Skip to content

Add context intelligence: symbol-aware packets, context diff and score#42

Merged
00PrabalK00 merged 1 commit into
mainfrom
feat/context-intelligence
May 30, 2026
Merged

Add context intelligence: symbol-aware packets, context diff and score#42
00PrabalK00 merged 1 commit into
mainfrom
feat/context-intelligence

Conversation

@00PrabalK00
Copy link
Copy Markdown
Owner

Why

Strategy §Gap3 / §Phase2: make the context an agent receives an inspectable
object
, not a hidden prompt. This adds three capabilities on top of the
existing MemoryStore and context build packet: smarter (symbol-aware)
packets, packet diffing, and packet scoring.

Constraints honored: stdlib + git subprocess only (no tree-sitter, no
ctags, no new deps). Symbol extraction is conservative regex over file text;
token estimate reuses the repo's chars // 4 heuristic (core.estimate_tokens,
tied to CONTEXT_BUDGETS).

What

New module continuum/context_intel.py (pure functions): extract_symbols,
relevant_tests, recent_commits, gather_context_intel, diff_intel,
score_intel plus renderers. Three CLI commands under continuum context:

  • continuum context enrich <task_ref> — relevant files (claimed + changed),
    extracted symbols, linked tests, recent commits touching those files, prior
    decisions (DECISIONS.md + decision events), current blockers. Human + --json.
    Accepts --file to analyze explicit paths instead of a task's claims.
  • continuum context diff <ref_a> <ref_b> — files/symbols/tests/decisions
    only-in-A vs only-in-B and token-size delta. Answers "who got stale context".
    Human + --json.
  • continuum context score <ref>estimated_tokens, source_count,
    staleness (hours/days), deterministic risk_level (low/med/high from
    out-of-scope files, missing tests, stale context, large size) and a
    missing_info checklist. Human + --json. Non-zero exit only on real error
    (unknown task).
  • continuum context build --intel/--symbols — appends a compact
    "Relevant Symbols / Tests / Recent Changes" section. Default packet behavior
    is unchanged.

Real smoke output

context enrich T0001 (task claiming auth.py):

# Context Intel: T0001 Auth work
Status: RUNNING  Agent: claude
## Relevant Symbols
- `auth.py`: def login, class AuthService, const MAX_RETRIES
## Linked Tests
- `tests/test_auth.py`
## Recent Changes
- 4c71ae5 add auth and test

context diff T0001 T0002:

## Symbols
Only in T0001:
  - auth.py::class AuthService
  - auth.py::const MAX_RETRIES
  - auth.py::def login
Only in T0002:
  - ui.js::const HANDLER
  - ui.js::function render
## Token Size
- T0001: 87 tokens
- T0002: 81 tokens
- Delta (A - B): 6 tokens

context score T0002 --json (task with no linked tests):

{
  "estimated_tokens": 81,
  "source_count": 3,
  "sources": ["files", "symbols", "recent_commits"],
  "staleness_hours": 0.01,
  "risk_level": "low",
  "risk_reasons": ["no linked tests"],
  "missing_info": ["no tests linked", "no recent decisions"]
}

Unknown task exits non-zero: context score T9999 -> Error: Unknown task: T9999, exit 1.

Tests

tests/test_context_intel.py adds 17 tests (symbol extraction for Python + JS
ignoring comments/strings; test<->module linking; recent_commits in a git repo
and [] in a non-git dir; enrich/diff/score CLI field + JSON shape + exit codes;
score flags missing_info when sections are empty). Git-based tests set repo
identity in setUp (CI has no global identity).

CI-mimic GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null python -m unittest discover -s tests: 246 tests pass (229 prior + 17 new).

🤖 Generated with Claude Code

Make context an inspectable object, not a hidden prompt (Strategy
Gap3 / Phase2). New stdlib-only module continuum/context_intel.py with
pure functions and three CLI commands under `continuum context`:

- enrich <task_ref>: symbol-aware intel (relevant files, extracted
  symbols, linked tests, recent commits, prior decisions, blockers).
- diff <ref_a> <ref_b>: what context each task received and what
  differs (files/symbols/tests/decisions only-in-A vs only-in-B,
  token-size delta) -- answers who got stale context.
- score <ref>: estimated_tokens (chars//4), source_count, staleness,
  deterministic risk_level and a missing_info checklist; non-zero exit
  only on a real error (unknown task).

`context build` gains an optional --intel/--symbols appendix; default
packet behavior is unchanged. Symbol extraction is conservative regex
across common languages; token estimate reuses core.estimate_tokens.

Tests: tests/test_context_intel.py (17 new); full suite 246 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@00PrabalK00 00PrabalK00 merged commit e5abc57 into main May 30, 2026
12 checks passed
@00PrabalK00 00PrabalK00 deleted the feat/context-intelligence branch May 30, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant