Repository navigation
feat: add pack governance receipts - #448
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR implements source-safe governance receipts for context-pack JSON outputs, adding a versioned receipt (v1) with graph freshness, request/task metadata, directive/coverage summary, follow-up expansion summaries, and optional MCP call cache/delta metadata while excluding prompts, answers, source snippets, and file paths. ChangesGovernance Receipt Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/runtime/stdio/tools.ts (1)
242-252:⚠️ Potential issue | 🟠 Major | ⚡ Quick winCache validator allows governance-less payloads on cache hits
isCachedExplainContextPackPayloaddoes not validategovernance, so stale pre-governance cache entries can still be served (Line 1209 onward), bypassing the new receipt contract.Proposed fix
function isCachedExplainContextPackPayload(value: unknown): value is CachedExplainContextPackPayload { @@ const candidate = value as Record<string, unknown> + const governance = candidate.governance + const mcpCall = governance && typeof governance === 'object' && !Array.isArray(governance) + ? (governance as Record<string, unknown>).mcp_call + : null return candidate.task === 'explain' && typeof candidate.prompt === 'string' && typeof candidate.task_intent === 'string' && Array.isArray(candidate.expandable) && candidate.expandable.every((entry) => isContextPackExpandableRef(entry)) + && !!governance + && typeof governance === 'object' + && !Array.isArray(governance) + && !!mcpCall + && typeof mcpCall === 'object' + && !Array.isArray(mcpCall) }Also applies to: 1209-1222
🤖 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 `@src/runtime/stdio/tools.ts` around lines 242 - 252, The cache validator is missing governance validation: modify isCachedExplainContextPackPayload to require and validate candidate.governance (e.g., ensure candidate.governance is a non-null object and either pass it through an existing helper like isGovernanceReceipt/isValidGovernanceReceipt or explicitly check the governance receipt fields required by the new receipt contract), and return false if governance is absent/invalid; apply the same governance check to the other copy of this validator used elsewhere so stale pre-governance cache entries cannot be served.
🤖 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/contracts/context-pack.ts`:
- Line 520: The new required field `governance: ContextPackGovernanceReceipt`
breaks schema v1 compatibility; either make `governance` optional in the
ContextPack type (change to `governance?: ContextPackGovernanceReceipt`) so
existing v1 artifacts remain valid, or bump the schema version (increment
`schema_version` to 2 and update any migration/versioning docs/tests) to signal
a breaking wire-format change; update the declaration in
src/contracts/context-pack.ts (the ContextPack/interface where `governance` is
defined) and ensure tests/consumers reflect the chosen approach.
In `@src/infrastructure/context-pack-command.ts`:
- Around line 598-601: The code currently removes governance metadata for the
CLI-ready path by deleting governance.request when surface === 'cli_pack' and
later deleting payload.governance, which strips receipts; to fix, stop removing
governance.request in the 'cli_pack' branch and avoid deleting
payload.governance for CLI outputs (only remove truly sensitive fields if
needed). Locate the branch that checks surface === 'cli_pack' and the later code
that deletes payload.governance and remove or guard those deletions so
governance.request and payload.governance are preserved for CLI JSON output (use
trimmedFields only for fields you still want to hide, and keep receipts intact),
leaving the request.budget check logic unchanged.
- Around line 958-965: The buildAnswerReadyPackSchema flow never calls
enforceAnswerReadyBudget, so selection-based node-culling isn't applied; update
the return path in buildAnswerReadyPackSchema to invoke
enforceAnswerReadyBudget(payload, maxTokens, trimmedFields) (using the same
payload/maxTokens/trimmedFields symbols) before finalizing the payload and
attaching/returning the serialized budget; ensure you still call
attachSerializedBudget after enforcement and then return the payload so
_selectionDiagnostics and node-culling take effect.
---
Outside diff comments:
In `@src/runtime/stdio/tools.ts`:
- Around line 242-252: The cache validator is missing governance validation:
modify isCachedExplainContextPackPayload to require and validate
candidate.governance (e.g., ensure candidate.governance is a non-null object and
either pass it through an existing helper like
isGovernanceReceipt/isValidGovernanceReceipt or explicitly check the governance
receipt fields required by the new receipt contract), and return false if
governance is absent/invalid; apply the same governance check to the other copy
of this validator used elsewhere so stale pre-governance cache entries cannot be
served.
🪄 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: b6dc4b57-32a2-4242-9998-2299f1cfa994
📒 Files selected for processing (10)
docs/agent-governance.mdsrc/contracts/context-pack.tssrc/infrastructure/context-pack-command.tssrc/runtime/context-pack-governance.tssrc/runtime/stdio/tools.tstests/unit/agent-governance-doc.test.tstests/unit/answer-ready-explain-pack.test.tstests/unit/context-pack-command.test.tstests/unit/handoff-command.test.tstests/unit/stdio-slice-surface.test.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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 (1)
src/runtime/stdio/tools.ts (1)
251-261:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRedacted answer-ready packs will self-invalidates in cache.
buildAnswerReadyPackSchema(...)can remove top-levelpromptandtask_intentto stay source-safe, but this validator still requires both and the cache-hit path uses them to rebuild expandable handles. Any explain pack that crosses that trim threshold will be cached once, then treated as malformed and evicted on the next read.Cache an internal envelope that keeps the handle-restoration metadata out-of-band, or skip caching redacted answer-ready payloads entirely.
🤖 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 300-315: The current logic removes governance.request.task_intent
and governance.request.retrieval_strategy whenever surface === 'cli_pack',
stripping audit metadata; change the conditions so that request.task_intent and
request.retrieval_strategy are not deleted for the CLI governance receipt (i.e.,
only delete these fields for non-cli_pack surfaces), and likewise avoid removing
request.resolution/task_intent here if those are meant to be preserved for later
cleanup (reference variables: surface, request, trimmedFields and the blocks
that delete task_intent, retrieval_strategy, and resolution).
🪄 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: b5607ba8-e343-4dde-8454-4ac645635b21
📒 Files selected for processing (4)
src/contracts/context-pack.tssrc/infrastructure/context-pack-command.tssrc/runtime/stdio/tools.tstests/unit/stdio-slice-surface.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/contracts/context-pack.ts
- tests/unit/stdio-slice-surface.test.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Summary
Verification
Closes #434
Summary by CodeRabbit
New Features
Privacy
Documentation
Tests