feat(cli): wire project context CLI stubs to ACMS pipeline #534

Merged
CoreRasurae merged 1 commit from feature/m5-context-cli-wiring into master 2026-03-03 23:41:23 +00:00
Member

Summary

Wire all four project context CLI commands (inspect, simulate, set, show) to live ACMS pipeline services, replacing the previous NotImplementedError stubs with fully functional implementations backed by ContextTierService and CRP models. Also fixes two bugs found during review: context inspect incorrectly reported global tier fragment counts instead of project-scoped counts, and context simulate --focus silently ignored the focus URIs.

Closes #499

Changes

Source

src/cleveragents/cli/commands/project_context.py (+720/-11)

  • context inspect: Queries ContextTierService for project-scoped tier metrics (hot/warm/cold fragment counts, hit/miss rates) and per-project fragments. Supports optional filtering by --strategy, --focus, --breadth, and --depth. Displays tier budget utilisation, per-actor visibility (strategist/executor/reviewer), and fragment details (first 20). All output formats supported (rich/json/yaml/plain/table).
  • context simulate: Performs dry-run context assembly using CRP models (ContextRequest, ContextFragment, AssembledContext). Builds simulated fragments from tier data with budget enforcement. Configurable --budget (token limit override) and --strategy (repeatable hint). When --focus is provided, fragments are filtered by matching resource_id against the focus URIs. Outputs fragment provenance, total tokens, budget usage percentage, strategy list, and a context hash.
  • context set: Gains 12 new ACMS pipeline options: --hot-max-tokens, --warm-max-decisions, --cold-max-decisions, --summary-max-tokens, --temporal-scope, --auto-refresh/--no-auto-refresh, --summarize/--no-summarize, --strategy, --default-breadth, --default-depth, --skeleton-ratio, --query-limit. Persists ACMS config alongside the context policy via _write_policy() / _read_acms_config().
  • context show: Displays ACMS pipeline configuration (tier budgets, strategies, temporal scope, auto-refresh, skeleton ratio) alongside existing context policy in all output formats.
  • Helper functions: _get_context_tier_service(), _read_acms_config(), _default_acms_config(), _write_policy() (extended with acms_config parameter), _tier_metrics_to_dict(), _fragment_to_dict(), _assembled_to_dict(), _simulate_context_assembly().

src/cleveragents/application/services/context_tiers.py (+27)

  • Added get_scoped_metrics(project_names) method to ContextTierService. Returns TierMetrics with fragment counts (hot/warm/cold) filtered to the specified projects using ScopedBackendView, while keeping hit/miss counters as global service-level cache metrics. Raises ValueError if project_names is empty.

src/cleveragents/shared/redaction.py (+2)

  • Added hot_max_tokens and summary_max_tokens to _FALSE_POSITIVE_KEYS to prevent legitimate ACMS config keys from being redacted as sensitive data.

Bug Fixes

  • Scoped inspect metrics: context inspect displayed global tier fragment counts across all projects instead of counts for the target project only. Fixed by calling get_scoped_metrics([project]) instead of get_metrics().
  • Focus URI filtering: context simulate --focus accepted focus URIs and passed them to the ContextRequest model but never applied them to filter the fragment list, making --focus a no-op. Fixed by adding a filtering step in _simulate_context_assembly() that retains only fragments whose resource_id matches a supplied focus URI.

Tests

Behave BDD (unit-level)

  • New file: features/context_cli_wiring.feature — 30 scenarios covering all ACMS set options (12 scenarios), show with ACMS config (2), inspect with tier data (6, including scoped metrics verification and error cases), and simulate with budget/strategy/focus/fragments (8, including focus URI filtering and error cases).
  • New file: features/steps/context_cli_wiring_steps.py — 646 lines of step definitions using an in-memory SQLite database and a real ContextTierService instance with mocked DI container.
  • Updated: features/project_context_cli.feature — replaced NotImplementedError expectations for inspect/simulate with wired success assertions (2 scenarios updated).
  • Updated: features/steps/project_context_cli_steps.py — added ContextTierService to mock container, added width=500, soft_wrap=True to Rich Console to prevent JSON parse failures from line-wrapping, added inspect/simulate success step definitions.
  • Updated: features/m5_acms_smoke.feature — replaced NotImplementedError expectations with wired ACMS success assertions (2 scenarios updated).
  • Updated: features/steps/m5_acms_smoke_steps.py — rewired inspect/simulate steps to use mocked DI container with real ContextTierService, added success assertion steps.

Robot Framework (integration)

  • Updated: robot/project_context_cli.robot — 5 test cases: set-show round-trip, inspect-wired, simulate-wired, set-acms, show-acms (replaces 3 previous tests that tested stubs).
  • Updated: robot/helper_project_context_cli.py — added _make_mock_container(), _run_cli_func() helpers with mocked DI; added test_context_inspect_wired(), test_context_simulate_wired(), test_context_set_acms_options(), test_context_show_acms_config() (replaces stub tests).

Documentation

  • docs/reference/project_context_cli.md (+169/-12): Full reference documentation for all four commands. Added ACMS pipeline options table for set, output descriptions for show/inspect/simulate, usage examples for ACMS configuration, and replaced stub notices with complete command references.
  • CHANGELOG.md: Three entries under Unreleased — one for the feature wiring, one for the scoped inspect metrics fix, one for the focus URI filtering fix. All reference #499.

Verification

Check Result
ruff check (lint) Pass
ruff format --check (format) Pass
pyright (typecheck) Pass (0 errors on both modified source files)
BDD: context_cli_wiring.feature 30/30 scenarios pass
BDD: project_context_cli.feature 19/19 scenarios pass
BDD: m5_acms_smoke.feature 26/26 scenarios pass
Coverage: project_context.py 92% (new code paths exercised)
## Summary Wire all four project context CLI commands (`inspect`, `simulate`, `set`, `show`) to live ACMS pipeline services, replacing the previous `NotImplementedError` stubs with fully functional implementations backed by `ContextTierService` and CRP models. Also fixes two bugs found during review: `context inspect` incorrectly reported global tier fragment counts instead of project-scoped counts, and `context simulate --focus` silently ignored the focus URIs. Closes #499 ## Changes ### Source #### `src/cleveragents/cli/commands/project_context.py` (+720/-11) - **`context inspect`**: Queries `ContextTierService` for project-scoped tier metrics (hot/warm/cold fragment counts, hit/miss rates) and per-project fragments. Supports optional filtering by `--strategy`, `--focus`, `--breadth`, and `--depth`. Displays tier budget utilisation, per-actor visibility (strategist/executor/reviewer), and fragment details (first 20). All output formats supported (rich/json/yaml/plain/table). - **`context simulate`**: Performs dry-run context assembly using CRP models (`ContextRequest`, `ContextFragment`, `AssembledContext`). Builds simulated fragments from tier data with budget enforcement. Configurable `--budget` (token limit override) and `--strategy` (repeatable hint). When `--focus` is provided, fragments are filtered by matching `resource_id` against the focus URIs. Outputs fragment provenance, total tokens, budget usage percentage, strategy list, and a context hash. - **`context set`**: Gains 12 new ACMS pipeline options: `--hot-max-tokens`, `--warm-max-decisions`, `--cold-max-decisions`, `--summary-max-tokens`, `--temporal-scope`, `--auto-refresh/--no-auto-refresh`, `--summarize/--no-summarize`, `--strategy`, `--default-breadth`, `--default-depth`, `--skeleton-ratio`, `--query-limit`. Persists ACMS config alongside the context policy via `_write_policy()` / `_read_acms_config()`. - **`context show`**: Displays ACMS pipeline configuration (tier budgets, strategies, temporal scope, auto-refresh, skeleton ratio) alongside existing context policy in all output formats. - **Helper functions**: `_get_context_tier_service()`, `_read_acms_config()`, `_default_acms_config()`, `_write_policy()` (extended with `acms_config` parameter), `_tier_metrics_to_dict()`, `_fragment_to_dict()`, `_assembled_to_dict()`, `_simulate_context_assembly()`. #### `src/cleveragents/application/services/context_tiers.py` (+27) - Added `get_scoped_metrics(project_names)` method to `ContextTierService`. Returns `TierMetrics` with fragment counts (hot/warm/cold) filtered to the specified projects using `ScopedBackendView`, while keeping hit/miss counters as global service-level cache metrics. Raises `ValueError` if `project_names` is empty. #### `src/cleveragents/shared/redaction.py` (+2) - Added `hot_max_tokens` and `summary_max_tokens` to `_FALSE_POSITIVE_KEYS` to prevent legitimate ACMS config keys from being redacted as sensitive data. ### Bug Fixes - **Scoped inspect metrics**: `context inspect` displayed global tier fragment counts across all projects instead of counts for the target project only. Fixed by calling `get_scoped_metrics([project])` instead of `get_metrics()`. - **Focus URI filtering**: `context simulate --focus` accepted focus URIs and passed them to the `ContextRequest` model but never applied them to filter the fragment list, making `--focus` a no-op. Fixed by adding a filtering step in `_simulate_context_assembly()` that retains only fragments whose `resource_id` matches a supplied focus URI. ### Tests #### Behave BDD (unit-level) - **New file**: `features/context_cli_wiring.feature` — 30 scenarios covering all ACMS set options (12 scenarios), show with ACMS config (2), inspect with tier data (6, including scoped metrics verification and error cases), and simulate with budget/strategy/focus/fragments (8, including focus URI filtering and error cases). - **New file**: `features/steps/context_cli_wiring_steps.py` — 646 lines of step definitions using an in-memory SQLite database and a real `ContextTierService` instance with mocked DI container. - **Updated**: `features/project_context_cli.feature` — replaced `NotImplementedError` expectations for inspect/simulate with wired success assertions (2 scenarios updated). - **Updated**: `features/steps/project_context_cli_steps.py` — added `ContextTierService` to mock container, added `width=500, soft_wrap=True` to Rich Console to prevent JSON parse failures from line-wrapping, added inspect/simulate success step definitions. - **Updated**: `features/m5_acms_smoke.feature` — replaced `NotImplementedError` expectations with wired ACMS success assertions (2 scenarios updated). - **Updated**: `features/steps/m5_acms_smoke_steps.py` — rewired inspect/simulate steps to use mocked DI container with real `ContextTierService`, added success assertion steps. #### Robot Framework (integration) - **Updated**: `robot/project_context_cli.robot` — 5 test cases: set-show round-trip, inspect-wired, simulate-wired, set-acms, show-acms (replaces 3 previous tests that tested stubs). - **Updated**: `robot/helper_project_context_cli.py` — added `_make_mock_container()`, `_run_cli_func()` helpers with mocked DI; added `test_context_inspect_wired()`, `test_context_simulate_wired()`, `test_context_set_acms_options()`, `test_context_show_acms_config()` (replaces stub tests). ### Documentation - **`docs/reference/project_context_cli.md`** (+169/-12): Full reference documentation for all four commands. Added ACMS pipeline options table for `set`, output descriptions for `show`/`inspect`/`simulate`, usage examples for ACMS configuration, and replaced stub notices with complete command references. - **`CHANGELOG.md`**: Three entries under Unreleased — one for the feature wiring, one for the scoped inspect metrics fix, one for the focus URI filtering fix. All reference #499. ## Verification | Check | Result | |---|---| | `ruff check` (lint) | Pass | | `ruff format --check` (format) | Pass | | `pyright` (typecheck) | Pass (0 errors on both modified source files) | | BDD: `context_cli_wiring.feature` | 30/30 scenarios pass | | BDD: `project_context_cli.feature` | 19/19 scenarios pass | | BDD: `m5_acms_smoke.feature` | 26/26 scenarios pass | | Coverage: `project_context.py` | 92% (new code paths exercised) |
brent.edwards approved these changes 2026-03-03 22:24:11 +00:00
Dismissed
brent.edwards left a comment

Review — PR #534 feat(cli): wire project context CLI stubs to ACMS pipeline

Verdict: APPROVED with comments

Nice end-to-end wiring of project context commands with comprehensive Behave + Robot coverage and solid reference docs. The ACMS config persistence via shared policy JSON is consistent with existing patterns, and the new redaction allowlist keys close the false-positive leak for config output.

No P0 or P1 findings.


P2:should-fix

  1. Missing required PR label — Per CONTRIBUTING.md, every PR must carry exactly one Type/ label. This PR has no labels. The linked issue #499 is Type/Feature.

  2. Missing PR milestone — Per CONTRIBUTING.md, the PR milestone must match the linked issue. This PR has no milestone set. Issue #499 is assigned to milestone v3.4.0.

  3. context inspect tier metrics are global, not project-scoped — The command is per-project but ContextTierService.get_metrics() is global. In multi-project setups, the "Tier Metrics" panel and JSON tier_metrics will reflect all fragments, not just the target project. Please either compute metrics from get_scoped_view([project]) or add a scoped metrics helper so inspect reflects the project-specific tier state. (See src/cleveragents/cli/commands/project_context.py.)

  4. context simulate --focus is ignored in the simulated assemblyfocus_uris are only passed into ContextRequest, but the simulated fragment selection uses project_fragments without filtering. This makes --focus a no-op for the CLI output. Please filter the selected TieredFragment list by resource_id/fragment ID when --focus is provided so the simulation respects the option. (See _simulate_context_assembly in src/cleveragents/cli/commands/project_context.py.)


P2 items should be addressed in a follow-up within 3 business days.

## Review — PR #534 `feat(cli): wire project context CLI stubs to ACMS pipeline` **Verdict: APPROVED with comments** Nice end-to-end wiring of `project context` commands with comprehensive Behave + Robot coverage and solid reference docs. The ACMS config persistence via shared policy JSON is consistent with existing patterns, and the new redaction allowlist keys close the false-positive leak for config output. No P0 or P1 findings. --- ### P2:should-fix 1. **Missing required PR label** — Per `CONTRIBUTING.md`, every PR must carry exactly one `Type/` label. This PR has no labels. The linked issue #499 is `Type/Feature`. 2. **Missing PR milestone** — Per `CONTRIBUTING.md`, the PR milestone must match the linked issue. This PR has no milestone set. Issue #499 is assigned to milestone `v3.4.0`. 3. **`context inspect` tier metrics are global, not project-scoped** — The command is per-project but `ContextTierService.get_metrics()` is global. In multi-project setups, the "Tier Metrics" panel and JSON `tier_metrics` will reflect all fragments, not just the target project. Please either compute metrics from `get_scoped_view([project])` or add a scoped metrics helper so `inspect` reflects the project-specific tier state. (See `src/cleveragents/cli/commands/project_context.py`.) 4. **`context simulate --focus` is ignored in the simulated assembly** — `focus_uris` are only passed into `ContextRequest`, but the simulated fragment selection uses `project_fragments` without filtering. This makes `--focus` a no-op for the CLI output. Please filter the selected `TieredFragment` list by `resource_id`/fragment ID when `--focus` is provided so the simulation respects the option. (See `_simulate_context_assembly` in `src/cleveragents/cli/commands/project_context.py`.) --- P2 items should be addressed in a follow-up within 3 business days.
CoreRasurae added this to the v3.4.0 milestone 2026-03-03 23:10:35 +00:00
CoreRasurae force-pushed feature/m5-context-cli-wiring from cf514957a7
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 13s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 18s
CI / security (pull_request) Successful in 31s
CI / typecheck (pull_request) Successful in 33s
CI / unit_tests (pull_request) Successful in 2m23s
CI / integration_tests (pull_request) Successful in 3m1s
CI / docker (pull_request) Successful in 46s
CI / coverage (pull_request) Successful in 5m8s
CI / benchmark-regression (pull_request) Successful in 25m38s
to 70cd342e97
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / build (pull_request) Successful in 17s
CI / quality (pull_request) Successful in 19s
CI / security (pull_request) Successful in 32s
CI / typecheck (pull_request) Successful in 34s
CI / unit_tests (pull_request) Successful in 1m59s
CI / docker (pull_request) Successful in 39s
CI / integration_tests (pull_request) Successful in 2m53s
CI / coverage (pull_request) Successful in 4m35s
CI / benchmark-regression (pull_request) Has been cancelled
2026-03-03 23:15:15 +00:00
Compare
CoreRasurae dismissed brent.edwards's review 2026-03-03 23:15:15 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

brent.edwards approved these changes 2026-03-03 23:28:25 +00:00
Dismissed
brent.edwards left a comment

Review — PR #534 (updated)

Verdict: APPROVED

Verified all prior P2 findings are resolved:

  • PR now has required Type/Feature label and milestone v3.4.0.
  • context inspect now uses project-scoped tier metrics via get_scoped_metrics([project]).
  • context simulate --focus now filters fragments by focus URIs in _simulate_context_assembly().
  • New ContextTierService.get_scoped_metrics() added to support scoped counts (global hit/miss retained as intended).

No P0/P1 findings. No remaining P2/P3 items.

## Review — PR #534 (updated) **Verdict: APPROVED** Verified all prior P2 findings are resolved: - PR now has required `Type/Feature` label and milestone `v3.4.0`. - `context inspect` now uses project-scoped tier metrics via `get_scoped_metrics([project])`. - `context simulate --focus` now filters fragments by focus URIs in `_simulate_context_assembly()`. - New `ContextTierService.get_scoped_metrics()` added to support scoped counts (global hit/miss retained as intended). No P0/P1 findings. No remaining P2/P3 items.
CoreRasurae force-pushed feature/m5-context-cli-wiring from 70cd342e97
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / build (pull_request) Successful in 17s
CI / quality (pull_request) Successful in 19s
CI / security (pull_request) Successful in 32s
CI / typecheck (pull_request) Successful in 34s
CI / unit_tests (pull_request) Successful in 1m59s
CI / docker (pull_request) Successful in 39s
CI / integration_tests (pull_request) Successful in 2m53s
CI / coverage (pull_request) Successful in 4m35s
CI / benchmark-regression (pull_request) Has been cancelled
to ff42d59d6d
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 14s
CI / build (pull_request) Successful in 17s
CI / quality (pull_request) Successful in 19s
CI / security (pull_request) Successful in 32s
CI / typecheck (pull_request) Successful in 33s
CI / unit_tests (pull_request) Successful in 2m22s
CI / integration_tests (pull_request) Successful in 2m52s
CI / docker (pull_request) Successful in 39s
CI / coverage (pull_request) Successful in 4m13s
CI / lint (push) Successful in 13s
CI / build (push) Successful in 15s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 31s
CI / typecheck (push) Successful in 32s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m31s
CI / integration_tests (push) Successful in 3m0s
CI / docker (push) Successful in 39s
CI / coverage (push) Successful in 5m5s
CI / benchmark-publish (push) Successful in 14m43s
CI / benchmark-regression (pull_request) Successful in 25m44s
2026-03-03 23:36:31 +00:00
Compare
CoreRasurae dismissed brent.edwards's review 2026-03-03 23:36:31 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

CoreRasurae scheduled this pull request to auto merge when all checks succeed 2026-03-03 23:36:52 +00:00
CoreRasurae deleted branch feature/m5-context-cli-wiring 2026-03-03 23:41:23 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!534
No description provided.