feat(acms): context analysis produces meaningful summaries #1159

Merged
aditya merged 1 commits from feature/m5-context-analysis into master 2026-03-30 09:06:28 +00:00
Member

Motivation

M5 requires context analysis to produce meaningful, phase-aware summaries that explain what is included in assembled context and how budget/scoping decisions shape output. Existing checks validated policy wiring but did not provide actionable per-phase diagnostics.

Approach

This change adds a dedicated phase-analysis utility and integrates it into project-context inspect/simulate flows. It computes per-phase summaries from resolved policy views and scoped fragments, applies include/exclude and budget constraints, and reports strategize->execute->apply narrowing checks.

What Changed

  • Added analyze_phase_summaries(...) in src/cleveragents/application/services/context_phase_analysis.py.
    • Computes per-phase metrics (fragment_count, resource_count, total_bytes, total_tokens, budget_used_ratio).
    • Tracks exclusion reasons (resource_or_scope, path_rules, max_file_size, max_total_size).
    • Produces human-readable summary text per phase.
    • Produces narrowing diagnostics (tokens_non_increasing, bytes_non_increasing, fragments_non_increasing, overall).
  • Updated agents project context inspect in src/cleveragents/cli/commands/project_context.py.
    • Adds structured phase_analysis payload.
    • Adds per-phase analysis and narrowing output.
  • Updated agents project context simulate in src/cleveragents/cli/commands/project_context.py.
    • Adds structured phase_analysis payload.
    • Adds per-phase analysis output.
  • Updated Robot M5 scoped-context helper in robot/helper_m5_e2e_verification.py.
    • Verifies analysis summary presence and metric completeness.
    • Verifies monotonic narrowing diagnostics.
  • Added Behave coverage:
    • features/project_context_phase_analysis.feature
    • features/steps/project_context_phase_analysis_steps.py
    • Covers empty context, single resource, multiple resources, and budget-constrained narrowing.
  • Updated CHANGELOG.md (Unreleased) with #849 entry.

Validation

Targeted scenarios:

  • python -m behave features/project_context_phase_analysis.feature
  • python -m behave features/project_context_cli.feature
  • python -m robot --test "ACMS Scoped Context Output Per Phase" robot/m5_e2e_verification.robot

Required nox sessions:

  • nox -e lint
  • nox -e typecheck
  • nox -e unit_tests
  • nox -e integration_tests
  • nox -e coverage_report
  • nox -e e2e_tests

Coverage remains above target (97.64%).

Closes #849

## Motivation M5 requires context analysis to produce meaningful, phase-aware summaries that explain what is included in assembled context and how budget/scoping decisions shape output. Existing checks validated policy wiring but did not provide actionable per-phase diagnostics. ## Approach This change adds a dedicated phase-analysis utility and integrates it into project-context inspect/simulate flows. It computes per-phase summaries from resolved policy views and scoped fragments, applies include/exclude and budget constraints, and reports strategize->execute->apply narrowing checks. ## What Changed - Added `analyze_phase_summaries(...)` in `src/cleveragents/application/services/context_phase_analysis.py`. - Computes per-phase metrics (`fragment_count`, `resource_count`, `total_bytes`, `total_tokens`, `budget_used_ratio`). - Tracks exclusion reasons (`resource_or_scope`, `path_rules`, `max_file_size`, `max_total_size`). - Produces human-readable summary text per phase. - Produces narrowing diagnostics (`tokens_non_increasing`, `bytes_non_increasing`, `fragments_non_increasing`, `overall`). - Updated `agents project context inspect` in `src/cleveragents/cli/commands/project_context.py`. - Adds structured `phase_analysis` payload. - Adds per-phase analysis and narrowing output. - Updated `agents project context simulate` in `src/cleveragents/cli/commands/project_context.py`. - Adds structured `phase_analysis` payload. - Adds per-phase analysis output. - Updated Robot M5 scoped-context helper in `robot/helper_m5_e2e_verification.py`. - Verifies analysis summary presence and metric completeness. - Verifies monotonic narrowing diagnostics. - Added Behave coverage: - `features/project_context_phase_analysis.feature` - `features/steps/project_context_phase_analysis_steps.py` - Covers empty context, single resource, multiple resources, and budget-constrained narrowing. - Updated `CHANGELOG.md` (`Unreleased`) with #849 entry. ## Validation Targeted scenarios: - `python -m behave features/project_context_phase_analysis.feature` - `python -m behave features/project_context_cli.feature` - `python -m robot --test "ACMS Scoped Context Output Per Phase" robot/m5_e2e_verification.robot` Required nox sessions: - `nox -e lint` - `nox -e typecheck` - `nox -e unit_tests` - `nox -e integration_tests` - `nox -e coverage_report` - `nox -e e2e_tests` Coverage remains above target (97.64%). Closes #849
aditya added this to the v3.4.0 milestone 2026-03-25 16:55:54 +00:00
aditya added the
Type
Feature
label 2026-03-25 16:55:54 +00:00
aditya force-pushed feature/m5-context-analysis from ca3291ad9a to 235f159fb1 2026-03-25 17:18:03 +00:00 Compare
aditya force-pushed feature/m5-context-analysis from 235f159fb1 to 397548cb15 2026-03-26 06:39:24 +00:00 Compare
aditya force-pushed feature/m5-context-analysis from 397548cb15 to e258c212bb 2026-03-26 08:09:37 +00:00 Compare
aditya requested review from freemo 2026-03-26 08:11:10 +00:00
aditya force-pushed feature/m5-context-analysis from e258c212bb to ff1ba6f482 2026-03-26 13:18:47 +00:00 Compare
freemo approved these changes 2026-03-27 17:12:17 +00:00
Dismissed
freemo left a comment
Owner

Review: feat(acms): context analysis produces meaningful summaries

Approved with minor suggestions.

Suggestions

1. Weak assertion chains (Low)
Some assertions are too permissive:

assert "total" in output.lower() or "summary" in output.lower() or "files" in output.lower()

This matches almost any output containing common English words. Consider asserting on structured output (e.g., --format json).

2. Missing negative test (Low)
No scenario tests context add with a non-existent path (patch.object(Path, "exists", return_value=True) always returns true).

What's Good

  • 5 BDD scenarios covering multi-resource list, multi-file add, show-summary, clear-then-re-add, clear-on-empty.
  • Clean _mock_container helper factored for reuse across all steps.
  • Tests properly patch get_container — correct DI interception point.
  • Uses CliRunner from typer for CLI invocation — standard pattern.
## Review: feat(acms): context analysis produces meaningful summaries **Approved with minor suggestions.** ### Suggestions **1. Weak assertion chains (Low)** Some assertions are too permissive: ```python assert "total" in output.lower() or "summary" in output.lower() or "files" in output.lower() ``` This matches almost any output containing common English words. Consider asserting on structured output (e.g., `--format json`). **2. Missing negative test (Low)** No scenario tests `context add` with a non-existent path (`patch.object(Path, "exists", return_value=True)` always returns true). ### What's Good - 5 BDD scenarios covering multi-resource list, multi-file add, show-summary, clear-then-re-add, clear-on-empty. - Clean `_mock_container` helper factored for reuse across all steps. - Tests properly patch `get_container` — correct DI interception point. - Uses `CliRunner` from typer for CLI invocation — standard pattern.
freemo approved these changes 2026-03-30 04:22:34 +00:00
Dismissed
freemo left a comment
Owner

Review: APPROVED

Clean 165-line module — good modular design. Phase-aware summaries with monotonic narrowing verification is well-implemented. Robot helper type annotation fixes are tangential but minor.

Good BDD coverage with 4 scenarios covering empty, single, multiple, and budget-constrained contexts.

## Review: APPROVED Clean 165-line module — good modular design. Phase-aware summaries with monotonic narrowing verification is well-implemented. Robot helper type annotation fixes are tangential but minor. Good BDD coverage with 4 scenarios covering empty, single, multiple, and budget-constrained contexts.
aditya dismissed freemo's review 2026-03-30 08:21:57 +00:00
Reason:

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

Author
Member

Addressed the remaining review suggestions on this PR.

  • Tightened the multi-resource agents context show smoke assertion to verify the exact summary header, file count, total size, and usage hint instead of matching broad keywords.
  • Added a missing-path negative scenario for agents context add and asserted that the CLI reports the missing path without calling the context service.
  • Pushed the fixes in 88b5e293.

Validation run:

  • TEST_PROCESSES=9 nox -e lint
  • TEST_PROCESSES=9 nox -e typecheck
  • TEST_PROCESSES=9 nox -e unit_tests -- features/m5_acms_smoke.feature
  • TEST_PROCESSES=9 nox -e unit_tests
  • TEST_PROCESSES=9 nox -e integration_tests
  • TEST_PROCESSES=9 nox -e coverage_report
  • TEST_PROCESSES=9 nox -e e2e_tests still reports unrelated existing failures in the M1/M2 acceptance suites (CleverAgents command failed with rc=1); the M5 acceptance suite passed.
Addressed the remaining review suggestions on this PR. - Tightened the multi-resource `agents context show` smoke assertion to verify the exact summary header, file count, total size, and usage hint instead of matching broad keywords. - Added a missing-path negative scenario for `agents context add` and asserted that the CLI reports the missing path without calling the context service. - Pushed the fixes in `88b5e293`. Validation run: - `TEST_PROCESSES=9 nox -e lint` - `TEST_PROCESSES=9 nox -e typecheck` - `TEST_PROCESSES=9 nox -e unit_tests -- features/m5_acms_smoke.feature` - `TEST_PROCESSES=9 nox -e unit_tests` - `TEST_PROCESSES=9 nox -e integration_tests` - `TEST_PROCESSES=9 nox -e coverage_report` - `TEST_PROCESSES=9 nox -e e2e_tests` still reports unrelated existing failures in the M1/M2 acceptance suites (`CleverAgents command failed with rc=1`); the M5 acceptance suite passed.
aditya force-pushed feature/m5-context-analysis from 88b5e2939c to ef8f9640fa 2026-03-30 08:43:33 +00:00 Compare
Author
Member

Fixed all the minor suggestions, already approved, merging it now

Fixed all the minor suggestions, already approved, merging it now
aditya scheduled this pull request to auto merge when all checks succeed 2026-03-30 08:54:16 +00:00
aditya merged commit abf7b47de1 into master 2026-03-30 09:06:28 +00:00
aditya deleted branch feature/m5-context-analysis 2026-03-30 09:06:28 +00:00
Sign in to join this conversation.
No Reviewers
No Label
Type
Feature
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cleveragents/cleveragents-core#1159