Skip to content

Strengthen active-context policy and explainable injection#278

Merged
xinhuagu merged 3 commits into
mainfrom
codex/issue-268-active-context-policy
Mar 16, 2026
Merged

Strengthen active-context policy and explainable injection#278
xinhuagu merged 3 commits into
mainfrom
codex/issue-268-active-context-policy

Conversation

@xinhuagu

@xinhuagu xinhuagu commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • add request-focus analysis and a dedicated task-focus prompt section
  • annotate context sections with scope, inclusion reason, and evidence
  • surface request focus and per-section explanations in /context

Testing

  • ./gradlew :aceclaw-daemon:test --tests dev.aceclaw.daemon.SystemPromptLoaderTest :aceclaw-cli:test --tests dev.aceclaw.cli.TerminalReplTest
  • ./gradlew :aceclaw-cli:test :aceclaw-daemon:test

Closes #268

Summary by CodeRabbit

  • New Features

    • Request Focus block added to context overviews, showing query summary, active files, symbols, and plan signals.
    • New "task-focus" context section type and richer scope metadata (scope type, inclusion reason, evidence) shown in lists and detail views.
  • Bug Fixes / UX

    • Context list rendering improved for readability (blank line after truncated sections and integrated focus block).
  • Tests

    • Expanded tests to cover request focus, new section metadata, and rendering changes.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds request-focused analysis and metadata to context assembly, inspection, RPC, and CLI rendering: introduces a RequestFocus record, enriches ContextSection with scopeType/inclusionReason/evidence, surfaces requestFocus in ContextInspection, and updates TerminalRepl to render a "Request Focus" block alongside enriched section details.

Changes

Cohort / File(s) Summary
CLI rendering & tests
aceclaw-cli/src/main/java/dev/aceclaw/cli/TerminalRepl.java, aceclaw-cli/src/test/java/dev/aceclaw/cli/TerminalReplTest.java
Added renderRequestFocus() and integrated it into context list rendering; context lines now show scopeType / sourceType; detail view includes Scope:, Why:, and Evidence:; tests updated to include requestFocus and validate new metadata.
System prompt / request-focus model & tests
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java, aceclaw-daemon/src/test/java/dev/aceclaw/daemon/SystemPromptLoaderTest.java
Introduced RequestFocus record and enriched ContextInspection/ContextSection with scopeType, inclusionReason, evidence; added analysis helpers (analyzeRequestFocus, extractActiveSymbols, inferPlanSignals, formatTaskFocusSection, etc.), ranking adjustments, and tests validating task-focus, evidence, and symbol-based boosts.
RPC/handler plumbing & tests
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/ContextRpcHelper.java, aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java, aceclaw-daemon/src/test/java/dev/aceclaw/daemon/StreamingAgentHandlerCandidateInjectionTest.java
Context inspection now includes a requestFocus node (querySummary, activeFilePaths, activeSymbols, planSignals); sections and details serialized with new fields via helper sectionToNode; StreamingAgentHandler computes/analyzes requestFocus when projectPath is null and returns it in ContextInspection; tests added to assert presence of focus data.

Sequence Diagram

sequenceDiagram
    participant Client as Client/CLI
    participant Handler as StreamingAgentHandler
    participant Loader as SystemPromptLoader
    participant Helper as ContextRpcHelper
    participant CLI as TerminalRepl

    Client->>Handler: inspectContext(sessionId, queryHint)
    Handler->>Loader: analyzeRequestFocus(queryHint, activeFilePaths)
    Loader->>Loader: extractActiveSymbols()<br/>inferPlanSignals()<br/>classifySectionScope()
    Loader-->>Handler: ContextInspection(requestFocus, sections, prompt)
    Handler->>Helper: buildContextResult(ContextInspection)
    Helper->>Helper: sectionToNode() — add scopeType, inclusionReason, evidence
    Helper-->>Handler: enriched JSON result
    Handler-->>Client: ContextInspection result
    Client->>CLI: render(contextInspection)
    CLI->>CLI: renderRequestFocus()<br/>renderContextList()/renderContextDetail()
    CLI-->>Client: formatted terminal output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Strengthen active-context policy and explainable injection' directly matches the main objectives: prioritizing active context and providing per-section explanations for injection decisions.
Linked Issues check ✅ Passed The code changes successfully implement all four objectives from #268: active file/plan/symbol prioritization via RequestFocus and section ranking, query-aware injection visibility through RequestFocus analysis, clear separation via scopeType field ('always-on' vs 'task-local'), and per-section explanations via inclusionReason and evidence fields.
Out of Scope Changes check ✅ Passed All changes directly support the linked issue objectives: SystemPromptLoader adds RequestFocus analysis and section metadata, ContextRpcHelper and StreamingAgentHandler integrate request focus data, TerminalRepl and tests validate the new rendering and behavior.
Block Major Correctness And Security Risks ✅ Passed No major security risks identified. PR does not introduce authentication, permission, data exposure, or unsafe error handling issues. Code uses immutable records with safe defaults.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/issue-268-active-context-policy
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java (1)

1739-1749: ⚠️ Potential issue | 🟡 Minor

Don't throw away request focus in the no-project fallback.

This path still has queryHint, but it returns RequestFocus.empty(). /context.inspect will therefore miss the new query-summary / symbol / plan metadata exactly when a session has no workspace. Extract the focus analysis into a reusable helper and populate it here too.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java`
around lines 1739 - 1749, The no-project fallback in StreamingAgentHandler
currently returns a ContextInspection with RequestFocus.empty(), discarding
queryHint-derived focus metadata; extract the focus-analysis logic (the code
that builds RequestFocus from queryHint / querySummary / symbol / plan) into a
reusable helper method (e.g., buildRequestFocus(session or queryHint) or
computeRequestFocusForSession(session)) and call that helper both in the normal
path and in the no-project fallback before constructing
SystemPromptLoader.ContextInspection; ensure the helper returns the same
RequestFocus type used elsewhere (not RequestFocus.empty()) and is invoked
alongside getSystemPrompt(sessionId) so the returned ContextInspection contains
populated focus metadata even when session.projectPath() == null.
aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java (1)

256-268: ⚠️ Potential issue | 🟠 Major

Request-focus metadata isn't wired into the actual selection policy.

requestFocus is created here, but the new activeSymbols and planSignals never feed any section selection or ranking call. Injection still runs off raw queryHint / activeFilePaths, so the active-symbol / active-plan prioritization goal is not implemented yet.

Also applies to: 270-272, 295-298

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java`
around lines 256 - 268, The requestFocus produced by
analyzeRequestFocus(queryHint, activeFilePaths) contains activeSymbols and
planSignals but is not used to influence which sections are included or their
priorities; update the tierSections loop and subsequent plan.addSection calls
(ContextAssemblyPlan.addSection usage) to consult requestFocus (e.g.,
requestFocus.activeSymbols and requestFocus.planSignals) and alter selection and
weights accordingly: when a section references an active symbol boost its
priority (or include it even if below threshold), and when planSignals indicate
a particular tier/section type boost or force inclusion (e.g., for base,
task-focus and other sections added later like the blocks at the later calls),
so that injection and ranking use the requestFocus metadata rather than only
queryHint/activeFilePaths.
🧹 Nitpick comments (1)
aceclaw-cli/src/test/java/dev/aceclaw/cli/TerminalReplTest.java (1)

305-309: Add an explicit assertion for request-focus file rendering.

Please also assert "Files:" here. Right now src/main/App.java can be satisfied by the separate “Active paths” block, so request-focus file coverage can be bypassed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@aceclaw-cli/src/test/java/dev/aceclaw/cli/TerminalReplTest.java` around lines
305 - 309, The test TerminalReplTest currently asserts output contains "Request
Focus", "Query:", "Symbols:", "Plan:", and "Last compact:" but misses asserting
the "Files:" header; update the test (in TerminalReplTest where the variable
plain is asserted) to include an explicit assertion that plain contains "Files:"
so the request-focus file rendering is verified (add an
assertThat(plain).contains("Files:") alongside the other contains checks).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java`:
- Around line 255-256: The system is marking "memory:Auto-Memory" as always-on
even though its inclusion-reason indicates it is query-aware; update the logic
that builds scope metadata so that when tierResult (or the memory tier
identifier) equals "memory:Auto-Memory" you do not set the scope to always-on
but instead mark it as query-aware (aligning with the inclusion-reason text).
Locate where tierResult is processed and scope/always-on flags are assigned
(near the call sites around analyzeRequestFocus and the requestFocus usage) and
change that branch so Auto-Memory uses the query-aware scope metadata; apply the
same fix to the other similar handling sites that produce the same
misclassification.

---

Outside diff comments:
In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java`:
- Around line 1739-1749: The no-project fallback in StreamingAgentHandler
currently returns a ContextInspection with RequestFocus.empty(), discarding
queryHint-derived focus metadata; extract the focus-analysis logic (the code
that builds RequestFocus from queryHint / querySummary / symbol / plan) into a
reusable helper method (e.g., buildRequestFocus(session or queryHint) or
computeRequestFocusForSession(session)) and call that helper both in the normal
path and in the no-project fallback before constructing
SystemPromptLoader.ContextInspection; ensure the helper returns the same
RequestFocus type used elsewhere (not RequestFocus.empty()) and is invoked
alongside getSystemPrompt(sessionId) so the returned ContextInspection contains
populated focus metadata even when session.projectPath() == null.

In `@aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java`:
- Around line 256-268: The requestFocus produced by
analyzeRequestFocus(queryHint, activeFilePaths) contains activeSymbols and
planSignals but is not used to influence which sections are included or their
priorities; update the tierSections loop and subsequent plan.addSection calls
(ContextAssemblyPlan.addSection usage) to consult requestFocus (e.g.,
requestFocus.activeSymbols and requestFocus.planSignals) and alter selection and
weights accordingly: when a section references an active symbol boost its
priority (or include it even if below threshold), and when planSignals indicate
a particular tier/section type boost or force inclusion (e.g., for base,
task-focus and other sections added later like the blocks at the later calls),
so that injection and ranking use the requestFocus metadata rather than only
queryHint/activeFilePaths.

---

Nitpick comments:
In `@aceclaw-cli/src/test/java/dev/aceclaw/cli/TerminalReplTest.java`:
- Around line 305-309: The test TerminalReplTest currently asserts output
contains "Request Focus", "Query:", "Symbols:", "Plan:", and "Last compact:" but
misses asserting the "Files:" header; update the test (in TerminalReplTest where
the variable plain is asserted) to include an explicit assertion that plain
contains "Files:" so the request-focus file rendering is verified (add an
assertThat(plain).contains("Files:") alongside the other contains checks).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ee4fccef-aa33-4bd4-99b3-8b01b1cd6b5a

📥 Commits

Reviewing files that changed from the base of the PR and between 5d2e5c7 and 06bb325.

📒 Files selected for processing (6)
  • aceclaw-cli/src/main/java/dev/aceclaw/cli/TerminalRepl.java
  • aceclaw-cli/src/test/java/dev/aceclaw/cli/TerminalReplTest.java
  • aceclaw-daemon/src/main/java/dev/aceclaw/daemon/ContextRpcHelper.java
  • aceclaw-daemon/src/main/java/dev/aceclaw/daemon/StreamingAgentHandler.java
  • aceclaw-daemon/src/main/java/dev/aceclaw/daemon/SystemPromptLoader.java
  • aceclaw-daemon/src/test/java/dev/aceclaw/daemon/SystemPromptLoaderTest.java

Xinhua Gu added 2 commits March 17, 2026 00:25
- Cache getSystemPrompt() in local var to avoid triple invocation
- Accept dotted qualified names in looksLikeSymbol (e.g. AppService.validate)
- Narrow inferPlanSignals "steps" match to "next steps" / "steps to"
- Cap request focus priority boost at 12 to prevent tier inversions
- Remove dead null checks in renderRequestFocus (JsonNode.path never null)
- Extract sectionToNode() helper in ContextRpcHelper to deduplicate fields
- Replace inline FQN java.util.LinkedHashSet with proper import
- Remove unnecessary distinct() in inferPlanSignals
@xinhuagu xinhuagu merged commit 9fc32ef into main Mar 16, 2026
2 of 3 checks passed
@xinhuagu xinhuagu deleted the codex/issue-268-active-context-policy branch March 16, 2026 23:38
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.

feat(context): strengthen active-context policy and explainable injection

1 participant