Repository navigation
Approval rules, part 1: gate, digest, and action plumbing (off by default) - #54
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Transport setup can exceed the configured gate timeout, and Codex path tracking lacks lifecycle cleanup.
Review effort: Balanced
Findings: 2
Open (4)
What changed in this PR
Adds opt-in approval-rule infrastructure, structured backend actions, privacy-preserving Jev digests, and automated gate decisions.
Changes:
- Adds approval-rule settings, receipts, normalization, and gate logic.
- Supplies structured approval actions from Claude, Codex, and mock backends.
- Adds unit coverage for decisions, redaction, persistence, and runner behavior.
| File | Description |
|---|---|
apps/desktop/test/store.test.ts |
Tests approval settings migration. |
apps/desktop/test/runner.test.ts |
Tests runner gate integration. |
apps/desktop/test/fakeproc.ts |
Captures structured approval requests. |
apps/desktop/test/codex-backend.test.ts |
Tests Codex approval actions. |
apps/desktop/test/claude-backend.test.ts |
Tests Claude approval actions. |
apps/desktop/test/approval-gate.test.ts |
Covers gate decisions and fallbacks. |
apps/desktop/test/approval-digest.test.ts |
Covers digest filtering and redaction. |
apps/desktop/src/shared/types.ts |
Defines rules, gate configuration, and receipts. |
apps/desktop/src/main/engine/store.ts |
Normalizes and persists approval settings. |
apps/desktop/src/main/engine/runner.ts |
Integrates gate decisions into approvals. |
apps/desktop/src/main/engine/routing/router.ts |
Exposes the resolved Jev transport. |
apps/desktop/src/main/engine/backends/types.ts |
Defines structured approval actions. |
apps/desktop/src/main/engine/backends/mock.ts |
Recovers actions from mock prompts. |
apps/desktop/src/main/engine/backends/codex.ts |
Builds Codex approval actions. |
apps/desktop/src/main/engine/backends/claude.ts |
Builds Claude approval actions. |
apps/desktop/src/main/engine/approvals/gate.ts |
Implements rule evaluation and safeguards. |
apps/desktop/src/main/engine/approvals/digest.ts |
Builds scrubbed Jev state. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+21
to
+22
| /** File paths of in-flight file changes, keyed `threadId:itemId`, so an approval can name them without the patch. */ | ||
| private readonly changePaths = new Map<string, string[]>(); |
| ): Promise<{ ask: true; decidedBy?: ApprovalReceipt } | { ask: false; answer: "yes" | "no"; decidedBy?: ApprovalReceipt }> { | ||
| if (!c.active() || c.signal?.aborted) return { ask: false, answer: "no" }; | ||
| try { | ||
| const jev = await this.router.jev().catch(() => ({ transport: null, model: "" })); |
| /** | ||
| * The approval gate: answers an approval from the user's plain-language rules before it reaches a | ||
| * human, or leaves it to the human. It never widens permissions (an allow is a one-off "yes") and | ||
| * fails closed: no rule, no key, an error, a timeout, or a malformed answer all mean "ask". |
|
|
||
| /** | ||
| * Runs the approval gate for one request. Resolves to a rule's answer ("yes" or "no", never | ||
| * "always"), or `ask` when a human must decide. Any failure is an ask; a stopped turn is a "no". |
…ault) Backends now attach a structured `action` to every approval request (Claude can_use_tool; Codex command, fileChange, and permissions, with grantRoot and permissions marked as escalations; the mock engine). A new approvals/ module decides approvals from plain-language rules: deterministic `<tool>: <glob>` matches first, then one Jev request (one noul per rule plus `destructive`, capped at 12 rules) through the Router's own transport. Precedence is never > ask > allow; destructive or escalating allows become asks; any Jev failure falls back to the exact matches, and everything else asks. Jev sees an allow-listed digest with scrubbed command text and file paths, never file contents. The runner consults the gate only when it is enabled and a rule applies to the project. A rule-answered approval lands already answered with a `decidedBy` receipt and never sets the thread to waiting; an allow is a one-off "yes", never "always". Settings gain `approval_rules` (default []) and `approval_gate` (default off). With the gate off, approvals follow the existing path unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BunsDev
force-pushed
the
approval-rules
branch
from
October 1, 2026 17:59
c309da9 to
9f97136
Compare
BunsDev
added a commit
that referenced
this pull request
Oct 1, 2026
* docs: bring status.md up to date with what is in flight In flight said "Nothing", but approval rules part 1 (#54) merged with part 2 pending, four contributor PRs are open, and three worktrees hold unlanded work. Record those, the #53 release-script change, the EPIPE failure on main CI for c9dcc7d, and #39 as an icon candidate for v0.0.5. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: record the second terminal-cleanup CI failure #63's push run failed "cleanup timeout retains ownership and a later close can retry" with kill ESRCH from its SIGCONT cleanup; the pull_request run of the same commit passed. Widen the rough edge to cover both intermittent failures in terminal-cleanup.test.ts. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 2, 2026
This was referenced Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part 1 of the Jev-gated approval rules spec (
2026-10-01-modex-jev-approval-rules-spec.md). This PR adds the plumbing, the gate, the digest, and unit tests. The gate is off by default and there is no UI, so nothing changes for users.What's in it
ApprovalActiononApprovalRequest(backends/types.ts), filled in by every backend:can_use_tool→{ tool, title, cwd, input }commandExecution→{ tool: "command", title: cmd, cwd, input: { command } };fileChange→{ tool: "fileChange", input: { paths, grantRoot? } }, withescalation: truewhengrantRootis set. The paths come from the item'sitem/started; the patch body is never put on the action.permissions→{ tool: "permissions", escalation: true }@modex/coreasks in (mockAction)approval_rules: ApprovalRule[](default[]) andapproval_gate(default{ enabled: false, threshold: 0.8, timeout_ms: 3000 }), with normalisation instore.ts. Malformed rules are dropped and out-of-range gate values fall back to the defaults. Approval items gain an optionaldecidedByreceipt.engine/approvals/digest.ts: the state Jev sees is built from an allow-list: tool, title, command (scrubbed, clipped to 500 characters), paths, project name and branch, and mode.old_string,new_string,content,patch,diff,edits[*], and any field not on the list are always dropped. The secret scrubber handles--token=…-style flags,Authorization:and similar headers,sk-,ghp_,github_pat_,xox*-,AKIAand JWT-shaped strings, URL credentials, andKEY=valueenv prefixes.engine/approvals/gate.ts: the decision procedure from the spec:<tool>: <glob>pass, then one Jev request with one noul per rule plusdestructive, capped at 12 rules (project-scoped first, then newest).jev-unavailable. Otherwise the result is ask."no".runner.tssinkapproval):"yes"(never"always") and adds an already-answered card withdecidedBy. The thread never goes towaiting."no"with a receipt.decidedByattached when a rule or a downgrade caused it.Router.jev()exposes the router's already-resolved transport and model. It returns null when Jev is off for the session, and an auth or billing rejection seen through it turns Jev off just as routing does. No second key path.Deviations from the spec (small; please check)
match. Under that wording, an exact-match allow such asBash: *would never get the destructive downgrade, even though the spec says that downgrade "cannot be overridden by any rule". So the gate also asks Jev when the deterministic result would be allow. Without a transport, deterministic allows still stand, as the spec says.$. Claude's Bash title is$ npm test. To make the spec's own example (Bash: npm test*) match, the glob is tried against the title both with and without a leading$.downgraded: "jev-unavailable"is set whenever Jev was consulted and failed. When a deterministic allow or never still stands, that is how the receipt "notes Jev unavailable".(rule: …). That needs the sink to return a reason alongside the answer, and it is only visible once rules are on.Deferred to PR 2
approvals:rules:get/set,approvals:try), receipt rows on the card, and e2e (e2e/approvals.spec.ts).approval_gate.enabled: true).AGENTS.md's "one network call outside the CLIs" sentence becomes "the optional Jev judge (Auto routing and approval rules)". Also the newdocs/approval-rules.md, a pointer indocs/auto-routing.md, a README bullet, anddocs/status.md. None of these change here because nothing user-visible ships until the gate turns on.Tests
npm run build && npm testin the worktree:npm run typecheckis clean. I did not run e2e locally because there is no UI change; CI runs it.approval-gate.test.ts(fakeJevTransport):matchwith a null transportbad_response"no"approval-digest.test.ts:runner.test.ts:"yes", lands an answered card withdecidedBy, and the statuses are onlyrunning → idledecidedBy"no"claude-backend.test.ts/codex-backend.test.ts:actionis filled in for each request kind. A rule's"yes"maps toallowwithoutupdatedPermissions(Claude) and toaccept, notacceptForSession(Codex).store.test.ts: defaults and normalisation.Open questions for Val (answer before PR 2 flips the default)
allowrules that have nomatchshow as inactive in Settings, or be hidden? The spec currently shows them, marked inactive.docs/status.mdNext yet.