Skip to content

Tighten strict pack guidance and compare traces - #333

Merged
mohanagy merged 2 commits into
nextfrom
issue-328-agent-guidance-exploration
May 26, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-328-agent-guidance-exploration

Conversation

@mohanagy

@mohanagy mohanagy commented May 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • strengthen strict install guidance so high-confidence packs explicitly forbid broad Glob/grep/find exploration across installed agent surfaces
  • parse verbose native-agent compare output into provider-proof reductions and per-side tool-call counts, and print the tool-call delta in the terminal summary
  • align the README strict-profile wording with the new exploration contract and lock the behavior with regression tests

Testing

  • npm run test:run -- tests/unit/install.test.ts tests/unit/install-templates.test.ts tests/unit/compare-native-agent.test.ts
  • npm run test:run -- tests/unit/compare.test.ts tests/unit/compare-native-agent.test.ts tests/unit/why-madar-doc.test.ts
  • npm run typecheck
  • npm run build
  • CI=1 npm run test:run
  • npm pack --dry-run

Closes #328
Closes #329

Summary by CodeRabbit

  • Documentation

    • Clarified strict-mode guidance and when context-pack-first behavior counts as reducing exploration.
    • Expanded strict-profile wording to explicitly discourage broad repo discovery after high/medium-confidence context packs.
  • New Features / Improvements

    • Reports now surface per-tool call counts and show baseline → madar deltas when available.
    • Graph/prompt caching now also considers file size changes to ensure fresh reloads.
  • Tests

    • Added coverage for verbose runner outputs, tool-call counts, and cache reloads on size-only changes.

Review Change Stack

Strengthen the strict install guidance so strong packs explicitly forbid broad Glob/grep/find exploration, add verbose native-agent compare tool-call counts and result parsing, and align the README wording with the stricter contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b751ec1-4f37-4534-8193-993be37013dc

📥 Commits

Reviewing files that changed from the base of the PR and between 5b93a12 and b530293.

📒 Files selected for processing (3)
  • src/runtime/stdio-server.ts
  • src/runtime/stdio/prompts.ts
  • tests/unit/stdio-server.test.ts

📝 Walkthrough

Walkthrough

This PR parses verbose Anthropic-style JSON traces to extract per-tool call counts for native-agent comparisons, adds optional tool_call_counts to the native-agent report and summary, introduces a strict "no broad exploration" guidance helper, injects that rule into installed-agent templates, and updates stdio graph/prompt caches to also consider file size.

Changes

Exploration measurement and guidance

Layer / File(s) Summary
Trace record parsing foundation
src/infrastructure/compare.ts, tests/unit/compare-native-agent.test.ts
New parseAnthropicTraceRecords(stdout) parses JSON objects/arrays/line-delimited records. parseAnthropicResultEvent(stdout) refactored to use trace records, iterating in reverse to find the last usage-bearing event. Unit test validates extraction from verbose JSON-array outputs.
Tool-call counting extraction and integration
src/infrastructure/compare.ts
NativeAgentToolCallCountsEntry and NativeAgentToolCallCounts types introduced. extractToolCallCounts(stdout) aggregates per-tool counts (Read, Bash, Glob, Grep, ToolSearch, other) from trace records. extractMadarTrace(stdout) updated to consume trace records. NativeAgentCompareReport extended with optional tool_call_counts field. State variables added for baseline and madar counts; counts extracted, serialized conditionally to report, and summary updated to print "tool calls" delta when available.
Native-agent test coverage for verbose arrays and tool counts
tests/unit/compare-native-agent.test.ts
VERBOSE_BASELINE_PAYLOAD and VERBOSE_MADAR_PAYLOAD fixtures model multi-message tool-use traces with usage/result payloads. buildSummaryResult test helper extended with optional toolCallCounts override. Three new unit tests: parseAnthropicResultEvent extraction from verbose array, executeNativeAgentCompare with verbose payloads asserting reductions and tool-counts persist, and formatNativeAgentCompareSummary asserting tool-calls delta appears in output.
Strict "no broad exploration" rule implementation
src/infrastructure/install.ts, src/infrastructure/install-skill-templates.ts
strictContextPackNoBroadExplorationRule(markdown) helper generates guidance against Glob patterns, grep/find, and raw file sweeps after high/medium-confidence packs. Rule incorporated into STRICT_CONTEXT_PACK_MESSAGE and CODEX_CONTEXT_PACK_FIRST_MESSAGE. Injected as a new numbered step into CLAUDE, Aider, Codex, OpenCode, Gemini, and Cursor Markdown templates. Strict-profile user-facing text in geminiInstall, installCopilotMcp, cursorInstall, claudeInstall updated to reference the rule.
Test coverage for strict "no broad exploration" rule
tests/unit/install.test.ts, tests/unit/install-templates.test.ts
Test constants STRICT_NO_BROAD_EXPLORATION_RULE_MD and STRICT_NO_BROAD_EXPLORATION_RULE_PLAIN added. Seven strict-profile test assertions updated across Gemini, Claude, Cursor, Copilot, and Codex to verify rule strings appear in generated templates and decoded hook payloads. Assertion added to verify Codex template includes broad-Glob/grep/find guidance.
README documentation updates
README.md
Benchmark narrative refined to clarify strict context-pack guidance counts as a win only when reducing exploration. --profile strict section expanded to explicitly forbid broad Glob patterns, repo-wide grep/find, and raw file sweeps after strong context packs.
Stdio runtime cache validation
src/runtime/stdio-server.ts, src/runtime/stdio/prompts.ts, tests/unit/stdio-server.test.ts
Graph and prompt-context caches extended to include file size with mtimeMs for cache validation. loadGraphCached and loadPromptContext now stat files and reload when either mtimeMs or size changes; tests added to verify reload when size changes without mtime change.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • #328: Madar increases agent tool-call exploration even when context pack is correct — this PR adds both the strict "no broad exploration" install guidance and machine-readable per-side tool_call_counts to detect the regression.
  • #329: compare produces empty reductions when exec uses --output-format json --verbose — this PR adds trace-record parsing for verbose JSON arrays and extracts result events and tool-counts from those streams.

Possibly related PRs

  • mohanagy/madar#321: Related changes to install templates and trace reporting; overlaps in install guidance and compare trace processing.
  • mohanagy/madar#246: Overlaps on native-agent compare/report schema evolution and reporting behavior.
  • mohanagy/madar#325: Related native-agent compare extensions (token regression and reporting) touching the same compare/report paths.

Poem

🐰 A rabbit's ode to measured exploration:
No more wild Globs after the pack,
Trace records parse, bold and black—
Tool counts tallied, delta shown,
Strict guidance sown in every stone.
Less exploration, less astray, hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Tighten strict pack guidance and compare traces' directly summarizes the PR's dual focus: stricter guidance rules and improved trace parsing.
Description check ✅ Passed The PR description includes a clear summary of changes, comprehensive testing steps, and closes linked issues #328 and #329, meeting all template requirements.
Linked Issues check ✅ Passed All coding requirements from #328 and #329 are addressed: strict guidance rules added, verbose stream parsing implemented, tool_call_counts extraction added, tests covering both behaviors, and README aligned.
Out of Scope Changes check ✅ Passed All changes align with the stated objectives: strict guidance in install templates, verbose trace parsing, tool_call_counts reporting, cache invalidation on size changes, and supporting regression tests.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-328-agent-guidance-exploration

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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