feat(core): M3b — wire mode/permission/hooks into agent loop#4
Merged
Conversation
Implements docs/design/sandbox-plan-worktree.md §5.1 decision flow.
Shipped
-------
- harness/tool-dispatcher.ts (105 lines)
· dispatchToolCall() combines:
1. evaluatePermission (existing M2)
2. evaluateMode (existing M3a)
3. PreToolUse hook (existing M3a HookDispatcher)
· Returns DispatchVerdict { decision, source, reason, hook?, ... }
· plan-blocked short-circuits before hooks (matches invariant #1)
· Hook JSON output decision=deny/ask overrides mode allow
· Hook non-zero exit code → deny
- agent.ts integration:
· New RunAgentOptions fields: mode, permissions, hooks, approval
· Tool-call loop now consults dispatcher when mode is set
· 'ask' verdict invokes ApprovalCallback (caller-supplied)
· 'deny' / 'plan-blocked' produce tool_result with is_error=true,
fed back to LLM so it can recover
· PostToolUse hook fires after every tool execution
· Backwards compatible: when mode is unset, M1 behavior (allow all)
Tests
-----
- harness/tool-dispatcher.test.ts (9 tests)
All paths of the §5.1 decision tree, including plan short-circuit,
acceptEdits with permission-deny still winning, hook JSON override,
hook non-zero exit, dontAsk strict deny.
Total: 206 passed / 4 skipped / 0 failed (was 197).
Deferred to M3c
---------------
MCP client / compaction / statusLine / /init multi-phase / auto-classifier
mode / hook handler types beyond `command` / hook `if` field.
CLI REPL not yet plumbed with mode (M3c). Mode-aware gating only activates
when a caller passes `mode:` to `runAgent` — current REPL still uses M1
path.
Verified
--------
pnpm typecheck → green
pnpm test → 206 passed / 4 skipped
pnpm format:check → conformant
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
docs/design/sandbox-plan-worktree.md§5.1 decision flow.harness/tool-dispatcher.tscombines mode + permission + PreToolUse hook into a single verdict.Deferred
MCP client / compaction / statusLine / /init multi-phase / auto-classifier / additional hook handler types — these are independent subsystems for M3c.
Release notes
release-notes:featureCo-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com