Skip to content

feat(core): M3b — wire mode/permission/hooks into agent loop#4

Merged
oratis merged 1 commit into
mainfrom
feat/m3b-agent-integration-mcp
May 27, 2026
Merged

feat(core): M3b — wire mode/permission/hooks into agent loop#4
oratis merged 1 commit into
mainfrom
feat/m3b-agent-integration-mcp

Conversation

@oratis

@oratis oratis commented May 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implements docs/design/sandbox-plan-worktree.md §5.1 decision flow.
  • New harness/tool-dispatcher.ts combines mode + permission + PreToolUse hook into a single verdict.
  • Agent loop now consults the dispatcher; plan-blocked short-circuits, hook JSON output can override, PostToolUse fires after execution.
  • 9 new tests covering every decision path.
  • 206 tests passing / 0 failed.

Deferred

MCP client / compaction / statusLine / /init multi-phase / auto-classifier / additional hook handler types — these are independent subsystems for M3c.

Release notes

  • release-notes:feature

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

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>
@oratis oratis merged commit b18441a into main May 27, 2026
@oratis oratis deleted the feat/m3b-agent-integration-mcp branch May 27, 2026 16:32
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