Skip to content

Gate adapter directives on pack quality - #320

Merged
mohanagy merged 2 commits into
nextfrom
issue-312-confidence-gated-adapters
May 25, 2026
Merged

mohanagy merged 2 commits into
nextfrom
issue-312-confidence-gated-adapters

Conversation

@mohanagy

@mohanagy mohanagy commented May 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • gate claude/copilot directive wording on pack confidence and grounded first-read guidance
  • switch weaker packs to targeted verification language while keeping strong packs directive
  • add focused adapter gating regressions and update the existing adapter expectations

Closes #312

Summary by CodeRabbit

  • Refactor

    • Pack output now uses confidence-aware guidance that toggles messaging based on evidence and semantic coverage
    • Guidance text adapts per renderer (e.g., "do not start with a broad repo search" vs targeted verification / verify-before-editing)
  • Tests

    • Added unit tests covering confidence-gated guidance across output formats
    • Updated existing tests to expect the new, confidence-aware guidance wording

Review Change Stack

Closes #312

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

coderabbitai Bot commented May 25, 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: b3d54c65-5a2b-424d-b06e-5acced52ac2b

📥 Commits

Reviewing files that changed from the base of the PR and between 5fe8f78 and a35017a.

📒 Files selected for processing (2)
  • src/infrastructure/context-pack-command.ts
  • tests/unit/context-pack-adapter-gating.test.ts

📝 Walkthrough

Walkthrough

This PR implements confidence-gated directive-adapter guidance for context packs. It adds logic to decide when to emit strong behavioral instructions (like "do not search broadly") based on pack confidence and first-read grounding, updates Claude and Copilot renderers to branch wording accordingly, and adds tests validating gating across low/high/missing semantic coverage.

Changes

Directive-Adapter Confidence Gating

Layer / File(s) Summary
Confidence threshold and detection helpers
src/infrastructure/context-pack-command.ts
Adds a new internal ADAPTER_DIRECTIVE_CONFIDENCE_THRESHOLD plus helper functions: areWorkflowCentersGraphBacked(), isFirstReadGrounded(), useDirectiveAdapterGuidance(), and claudeSearchGuidanceLine() to decide directive-mode and produce Claude search guidance text.
Claude and Copilot adapter output updates
src/infrastructure/context-pack-command.ts
Replaces the prior hardcoded Claude search guidance with claudeSearchGuidanceLine(schema) and updates renderCopilotPlanSteps to compute directiveMode via useDirectiveAdapterGuidance() and branch the first plan step wording based on directiveMode and recommended_first_read[0].
Comprehensive adapter-gating test suite
tests/unit/context-pack-adapter-gating.test.ts
New Vitest suite that hoists/mocks buildImplementationPackGuidance, defines low/high/missing-coverage fixtures, builds synthetic RetrieveResult and compact-pack objects, wires mocked dependencies, and asserts expected guidance strings across claude and copilot formats.
Updated adapter test expectations
tests/unit/context-pack-command.test.ts
Renamed two tests to “confidence-aware” phrasing and adjusted expected guidance lines: Claude now expects targeted verification wording; Copilot now expects verification-before-editing wording.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • mohanagy/madar#304: Adds/scales workflow_centers data that this gating logic consumes to detect path-anchored recommendations.
  • mohanagy/madar#302: Restructures context-pack rendering/pack schema; overlaps in the output-generation code paths updated here.
  • mohanagy/madar#309: Introduced agent-specific adapter renderers for Claude/Copilot; this PR builds directive-gating on that adapter layer.

Poem

🐰 A rabbit checked the pack with care,
If confidence was low, it whispered "beware".
"Verify anchors first," the little hop said,
Then bounded off to read the files ahead.
When packs are strong, the rabbit leads the rest.

🚥 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 'Gate adapter directives on pack quality' directly describes the main change: making adapter directives conditional on pack confidence metrics.
Description check ✅ Passed PR description covers the main changes (confidence gating, directive wording, test coverage) and references the linked issue (#312), but lacks explicit testing verification steps from the template.
Linked Issues check ✅ Passed All acceptance criteria from issue #312 are met: confidence-gated directive behavior [main changes], distinction between high/low-confidence packs [test coverage], and low-confidence verification guidance [test expectations] without changing JSON output.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing issue #312: confidence gating logic in context-pack-command.ts and corresponding test coverage; no unrelated alterations detected.

✏️ 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-312-confidence-gated-adapters

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.

@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

🧹 Nitpick comments (1)
tests/unit/context-pack-adapter-gating.test.ts (1)

252-283: ⚡ Quick win

Add a high-confidence Copilot assertion to complete branch coverage.

This suite validates low-confidence Copilot behavior, but it doesn’t assert the high-confidence Copilot directive path. Adding one test that expects the strong “read first” guidance would close a likely regression gap in the new gating logic.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/context-pack-adapter-gating.test.ts` around lines 252 - 283, The
test suite covers low-confidence Copilot behavior but lacks a parallel
high-confidence Copilot case; add a new it(...) that mirrors the high-confidence
Claude test but sets format: 'copilot', uses highConfidenceCoverage() and
buildImplementationPackGuidanceMock.mockReturnValue(highConfidenceImplementation()),
calls runContextPackCommand(...) and asserts the output contains the strong
"Read `src/infrastructure/context-pack-command.ts` first to anchor the change:"
guidance (and does not contain the cautious verification message), so branch
coverage for Copilot high-confidence gating in
context-pack-adapter-gating.test.ts is complete.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/infrastructure/context-pack-command.ts`:
- Around line 728-733: The gating function useDirectiveAdapterGuidance currently
ignores schema.missing_semantic; update it to require no missing semantic
evidence before allowing directive-mode guidance by adding a check that
schema.missing_semantic.length === 0 alongside the existing checks (confidence
>= ADAPTER_DIRECTIVE_CONFIDENCE_THRESHOLD, schema.missing_context.length === 0,
hasGraphBackedWorkflowCenter(schema), hasGroundedFirstRead(schema)), so
directive guidance is suppressed when semantic coverage is incomplete.

---

Nitpick comments:
In `@tests/unit/context-pack-adapter-gating.test.ts`:
- Around line 252-283: The test suite covers low-confidence Copilot behavior but
lacks a parallel high-confidence Copilot case; add a new it(...) that mirrors
the high-confidence Claude test but sets format: 'copilot', uses
highConfidenceCoverage() and
buildImplementationPackGuidanceMock.mockReturnValue(highConfidenceImplementation()),
calls runContextPackCommand(...) and asserts the output contains the strong
"Read `src/infrastructure/context-pack-command.ts` first to anchor the change:"
guidance (and does not contain the cautious verification message), so branch
coverage for Copilot high-confidence gating in
context-pack-adapter-gating.test.ts is complete.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 10b08cfe-e59b-4c65-a325-47ddced7b9ce

📥 Commits

Reviewing files that changed from the base of the PR and between 22a1024 and 5fe8f78.

📒 Files selected for processing (3)
  • src/infrastructure/context-pack-command.ts
  • tests/unit/context-pack-adapter-gating.test.ts
  • tests/unit/context-pack-command.test.ts

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