feat(acms): implement context policy configuration with view-specific settings and budget enforcement #9296

Open
opened 2026-04-14 14:20:43 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Branch: feat/acms-context-policy-configuration
  • Commit Message: feat(acms): implement context policy configuration with view-specific settings and budget enforcement
  • Milestone: v3.4.0

Background and Context

The Advanced Context Management System (ACMS) v1 requires a robust policy configuration layer that allows users and actors to control how context is assembled, filtered, and budget-constrained on a per-project and per-view basis. Currently, context assembly uses hardcoded defaults with no user-facing configuration surface.

The v3.4.0 milestone explicitly requires:

  • Context policies configurable with view-specific settings
  • Budget enforcement working with max_file_size and max_total_size constraints

Without a configurable policy system, the ACMS pipeline cannot adapt to different project sizes, team workflows, or actor roles. Large projects (10,000+ files) especially need fine-grained include/exclude patterns and budget caps to avoid context bloat and LLM token overruns.

The agents context policy CLI subcommand group provides the user-facing interface for managing these policies, backed by a ContextPolicy domain model and database persistence layer.


Expected Behavior

Users can configure context policies per project via the CLI:

# Set a policy for the "execute" view with budget constraints
agents context policy set --view execute --max-file-size 102400 --max-total-size 5242880 --max-files 200

# Set include/exclude patterns
agents context policy set --view strategize --include "src/**/*.py" --exclude "tests/**" --exclude "*.lock"

# Display the current policy for a project
agents context policy show

# List all policies for a project (all views)
agents context policy list

The policy system:

  • Persists policies to the SQLite database under the active project
  • Resolves policies at context assembly time (plan > project > global precedence)
  • Enforces max_file_size by skipping files exceeding the byte limit
  • Enforces max_total_size by stopping context accumulation once the total budget is reached
  • Enforces max_files by capping the number of files included in context
  • Applies include/exclude glob patterns before budget enforcement
  • Supports named views (e.g., strategize, execute, default) with independent settings per view

Acceptance Criteria

  • agents context policy set accepts --view, --max-file-size, --max-total-size, --max-files, --include, --exclude flags and persists the policy to the database
  • agents context policy show displays the current policy for the active project (optionally filtered by --view)
  • agents context policy list lists all configured policies for the active project, grouped by view
  • ContextPolicy domain model defined with fields: project_name, view_name, max_file_size, max_total_size, max_files, include_patterns, exclude_patterns
  • context_policies database table created with Alembic migration
  • Budget enforcement: files exceeding max_file_size are skipped during context assembly
  • Budget enforcement: context assembly halts once max_total_size bytes are accumulated
  • Budget enforcement: context assembly halts once max_files files are included
  • Include/exclude glob patterns are applied before budget enforcement
  • Policy resolution follows precedence: plan-level > project-level > global defaults
  • View-specific policies (strategize, execute) are applied when the ACMS pipeline assembles context for the corresponding actor phase
  • agents context policy set with no --view sets the default view policy
  • Test coverage >= 97% (Behave unit + Robot integration)
  • nox passes with all default sessions

Subtasks

  • Define ContextPolicy dataclass/model in domain/models/acms/policy.py
  • Create context_policies SQLAlchemy ORM model in db/models.py
  • Write Alembic migration for context_policies table
  • Implement ContextPolicyService in application/services/context_policy_service.py with set_policy, get_policy, list_policies methods
  • Implement agents context policy set CLI command with all required flags
  • Implement agents context policy show CLI command
  • Implement agents context policy list CLI command
  • Wire ContextPolicyService into the ACMS context assembly pipeline for budget enforcement
  • Implement include/exclude glob pattern filtering in the context assembly pipeline
  • Implement policy resolution precedence (plan > project > global) in ContextPolicyResolver
  • Apply view-specific policy lookup when assembling context for strategize and execute phases
  • Write Behave scenarios for context policy set/show/list CLI commands
  • Write Behave scenarios for budget enforcement (max_file_size, max_total_size, max_files)
  • Write Behave scenarios for include/exclude pattern filtering
  • Write Robot Framework integration tests for end-to-end policy configuration flow
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • agents context policy set/show/list commands are functional and tested.
  • Budget enforcement (max_file_size, max_total_size, max_files) is active in the ACMS pipeline.
  • Include/exclude glob patterns filter context correctly.
  • View-specific policies (strategize, execute) are applied during context assembly.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • The v3.4.0 milestone acceptance criteria for "Context policies configurable with view-specific settings" and "Budget enforcement works (max_file_size, max_total_size constraints)" are satisfied.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Branch**: `feat/acms-context-policy-configuration` - **Commit Message**: `feat(acms): implement context policy configuration with view-specific settings and budget enforcement` - **Milestone**: v3.4.0 --- ## Background and Context The Advanced Context Management System (ACMS) v1 requires a robust policy configuration layer that allows users and actors to control how context is assembled, filtered, and budget-constrained on a per-project and per-view basis. Currently, context assembly uses hardcoded defaults with no user-facing configuration surface. The v3.4.0 milestone explicitly requires: - Context policies configurable with view-specific settings - Budget enforcement working with `max_file_size` and `max_total_size` constraints Without a configurable policy system, the ACMS pipeline cannot adapt to different project sizes, team workflows, or actor roles. Large projects (10,000+ files) especially need fine-grained include/exclude patterns and budget caps to avoid context bloat and LLM token overruns. The `agents context policy` CLI subcommand group provides the user-facing interface for managing these policies, backed by a `ContextPolicy` domain model and database persistence layer. --- ## Expected Behavior Users can configure context policies per project via the CLI: ``` # Set a policy for the "execute" view with budget constraints agents context policy set --view execute --max-file-size 102400 --max-total-size 5242880 --max-files 200 # Set include/exclude patterns agents context policy set --view strategize --include "src/**/*.py" --exclude "tests/**" --exclude "*.lock" # Display the current policy for a project agents context policy show # List all policies for a project (all views) agents context policy list ``` The policy system: - Persists policies to the SQLite database under the active project - Resolves policies at context assembly time (plan > project > global precedence) - Enforces `max_file_size` by skipping files exceeding the byte limit - Enforces `max_total_size` by stopping context accumulation once the total budget is reached - Enforces `max_files` by capping the number of files included in context - Applies include/exclude glob patterns before budget enforcement - Supports named views (e.g., `strategize`, `execute`, `default`) with independent settings per view --- ## Acceptance Criteria - [ ] `agents context policy set` accepts `--view`, `--max-file-size`, `--max-total-size`, `--max-files`, `--include`, `--exclude` flags and persists the policy to the database - [ ] `agents context policy show` displays the current policy for the active project (optionally filtered by `--view`) - [ ] `agents context policy list` lists all configured policies for the active project, grouped by view - [ ] `ContextPolicy` domain model defined with fields: `project_name`, `view_name`, `max_file_size`, `max_total_size`, `max_files`, `include_patterns`, `exclude_patterns` - [ ] `context_policies` database table created with Alembic migration - [ ] Budget enforcement: files exceeding `max_file_size` are skipped during context assembly - [ ] Budget enforcement: context assembly halts once `max_total_size` bytes are accumulated - [ ] Budget enforcement: context assembly halts once `max_files` files are included - [ ] Include/exclude glob patterns are applied before budget enforcement - [ ] Policy resolution follows precedence: plan-level > project-level > global defaults - [ ] View-specific policies (`strategize`, `execute`) are applied when the ACMS pipeline assembles context for the corresponding actor phase - [ ] `agents context policy set` with no `--view` sets the `default` view policy - [ ] Test coverage >= 97% (Behave unit + Robot integration) - [ ] `nox` passes with all default sessions --- ## Subtasks - [ ] Define `ContextPolicy` dataclass/model in `domain/models/acms/policy.py` - [ ] Create `context_policies` SQLAlchemy ORM model in `db/models.py` - [ ] Write Alembic migration for `context_policies` table - [ ] Implement `ContextPolicyService` in `application/services/context_policy_service.py` with `set_policy`, `get_policy`, `list_policies` methods - [ ] Implement `agents context policy set` CLI command with all required flags - [ ] Implement `agents context policy show` CLI command - [ ] Implement `agents context policy list` CLI command - [ ] Wire `ContextPolicyService` into the ACMS context assembly pipeline for budget enforcement - [ ] Implement include/exclude glob pattern filtering in the context assembly pipeline - [ ] Implement policy resolution precedence (plan > project > global) in `ContextPolicyResolver` - [ ] Apply view-specific policy lookup when assembling context for `strategize` and `execute` phases - [ ] Write Behave scenarios for `context policy set/show/list` CLI commands - [ ] Write Behave scenarios for budget enforcement (max_file_size, max_total_size, max_files) - [ ] Write Behave scenarios for include/exclude pattern filtering - [ ] Write Robot Framework integration tests for end-to-end policy configuration flow - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors --- ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - `agents context policy set/show/list` commands are functional and tested. - Budget enforcement (`max_file_size`, `max_total_size`, `max_files`) is active in the ACMS pipeline. - Include/exclude glob patterns filter context correctly. - View-specific policies (`strategize`, `execute`) are applied during context assembly. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - The v3.4.0 milestone acceptance criteria for "Context policies configurable with view-specific settings" and "Budget enforcement works (max_file_size, max_total_size constraints)" are satisfied. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.4.0 milestone 2026-04-14 14:22:24 +00:00
Author
Owner

Triage: Verified [AUTO-OWNR-1]

Valid feature: Context policy configuration is explicitly listed in the v3.4.0 milestone acceptance criteria: "Context policies configurable with view-specific settings" and "Budget enforcement works (max_file_size, max_total_size constraints)." This issue provides a comprehensive specification for the ContextPolicy domain model, ContextPolicyService, CLI commands, and ACMS pipeline integration.

The policy system (view-specific settings, budget enforcement, include/exclude patterns, precedence resolution) is a core ACMS v1 feature that enables the system to handle large projects (10,000+ files) without context bloat.

Assigning to v3.4.0 (ACMS v1 + Context Scaling) as this is explicitly required by the milestone. Priority High — this is a core M5 deliverable.

MoSCoW: Must Have — context policy configuration is explicitly required by the v3.4.0 milestone acceptance criteria.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Triage: Verified** [AUTO-OWNR-1] Valid feature: Context policy configuration is explicitly listed in the v3.4.0 milestone acceptance criteria: "Context policies configurable with view-specific settings" and "Budget enforcement works (max_file_size, max_total_size constraints)." This issue provides a comprehensive specification for the `ContextPolicy` domain model, `ContextPolicyService`, CLI commands, and ACMS pipeline integration. The policy system (view-specific settings, budget enforcement, include/exclude patterns, precedence resolution) is a core ACMS v1 feature that enables the system to handle large projects (10,000+ files) without context bloat. Assigning to **v3.4.0** (ACMS v1 + Context Scaling) as this is explicitly required by the milestone. Priority **High** — this is a core M5 deliverable. MoSCoW: **Must Have** — context policy configuration is explicitly required by the v3.4.0 milestone acceptance criteria. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9296
No description provided.