Skip to content

clauz3: native approval panel beside the agent pane (phase 1) - #3

Draft
cmungall wants to merge 7 commits into
mainfrom
cmungall/feat-native-clauz3-approval
Draft

cmungall wants to merge 7 commits into
mainfrom
cmungall/feat-native-clauz3-approval

Conversation

@cmungall

@cmungall cmungall commented Nov 29, 2026 •

Copy link
Copy Markdown

Phase 1 of weaving clauz3 into Orca. Restricted Claude sessions (agentSessionModes.claude = 'clauz3-restricted') are now approved inside Orca, beside the agent pane that asked, rather than in clauz3's web page.

Stacked on the spike (#2), now 8a00c03d168 on upstream stablyai/orca be4d21c0c94. #2 uses the agents/orca and agents/core libraries from clauz3-tools-agents main, with the policy at .clauz3/cz3tools/agents/orca/worker-approval-policy.json, and clauz3 main (8468da1+, with stablyai#61 and stablyai#62 merged). It also makes restricted agents refuse or fall back on every structured or chat launch path. This branch is #2's five commits plus the panel commit and a demo-docs commit. Design: #1 (docs/clauz3/DESIGN.md). Notes, key handoff, keyboard map and known gaps: docs/clauz3-approval-panel/README.md.

What it does

  • Key handoff over a pipe Orca owns (Never expose the approver sign-in key to terminal output clauz3#62, --approver-key-fd). Main makes a private FIFO (0600 in a 0700 temp dir), opens its read end, and launches clauz3 start claude --no-browser --approver-key-fd 3 … 3>'<fifo>'. clauz3 picks its own port, writes {origin, key, login_url} to fd 3 once ready, and closes it before the agent starts. Main reads the line, removes the FIFO, and only then registers the session. The key is never in env, argv, the pty, scrollback or on disk; clauz3 writes no link file. A one-line pipe write is atomic and reaches exactly one reader, so if main got it, nobody else did. If it never arrives (an old clauz3, a failed start), nothing is registered and nothing in Orca can approve (fail closed).
  • Needs clauz3 main (8468da1 or later, which has fix: use autoUpdater.quitAndInstall() on macOS to apply updates stablyai/orca#62): uv tool install git+https://github.com/normalform-ai/clauz3, or point spike: run an Orca worker as a restricted clauz3 session #2's clauz3Command setting at a venv built from main. An older clauz3 rejects the flag and the session is never registered.
  • Broker (src/main/clauz3/): polls each service's GET /api/requests with a fast-then-backoff timer that stops when no session is left. It sends the renderer display-only card views keyed by a one-time cardId, and keeps a frozen shown snapshot, including program_sha256. On decide it re-reads the record and refuses a stale card itself, then POST /decision with Bearer and shown. 404 maps to gone, 409 to decided or changed, 400 to refused. Approve is withheld when the program does not hash to program_sha256.
  • Only the person decides: clauz3Approvals:decide is accepted only from the Orca window's main frame. No runtime RPC, CLI verb, automation, plugin frame or paired client reaches it. Card ids are single-use. Card buttons and keys ignore script-dispatched (untrusted) events, and approve is inert for 750 ms after a card appears or changes.
  • Card parity with clauz3's _render_card and render_guarantees: resolved and unresolved guarantees with provenance, coverage with clauz3's labels and severity order (gaps also summarised above the buttons), simulated tools, profile problems, paused auto-approvals, proof results, and the syntax-highlighted program with its line count and hash. The actions are Approve once, Always allow… (only when profile_eligible, with a confirm step), Reject, Reject contract and Need more info, plus an optional note.
  • Where: a dock portalled into the asking agent's pane, collapsible to a "Waiting for approval (n)" strip; a badge on the workspace's sidebar card; an OS notification (summary only) when Orca isn't focused. Clicking the notification or the badge reveals and focuses the card. Keys on a focused card: ⌘↩ approve once, ⌘⇧↩ always allow, ⌘⌫ reject.

Demo (isolated dev build, scratch profile)

Combined worker run, everything from main (2026-11-29). clauz3 8468da1 (main) in a venv built from main, pinned with clauz3Command (the global clauz3 was left alone). The toy repo has agents/core and agents/orca from clauz3 install gh:normalform-ai/clauz3-tools-agents (main), plus stdlib git and filesystem. agentDefaultSurface set to chat (upstream's default is terminal, so it was set explicitly to exercise the chat fallback).

  • orca orchestration worker-start --agent claude returned mode: terminal: it fell back from chat to a restricted terminal worker.
  • The agent first bundled write, commit and worker_done into one program. That card was rejected from the panel with a note asking for two programs.
  • The write-and-commit card (clr_a128c7d693b1, only_writes_files([hello.txt]), only_subcommands([add, commit, log]), no_push(), protocol_messages_at_most(0)) was approved with ⌘↩ beside the worker's pane, with the key handed over --approver-key-fd. The worker's scrollback contains no login?key=.
  • The worker_done-only program was auto-approved by agents/orca's worker-approval-policy.json; no card appeared.
  • The coordinator received worker_done with outcome succeeded, and the task is completed, about 4 min after worker-start (one reject plus one approve). Commit 8bbbd20 add hello.txt.
  • Side effect worth knowing: while the worker was parked on the first card, Orca sent the coordinator a "Worker stopped without reporting" escalation, because a turn waiting on awaiting_approval looks finished (FINDINGS item 4).

worker demo

worker waiting
worker done

Earlier run (clauz3 stablyai#61 + stablyai#62 merged in a scratch venv, before they landed): one click, succeeded 72 s after worker-start.

worker waiting
worker done

Single-session runs:
With clauz3 stablyai#62's fd handoff. The terminal shows only "sign-in key handed to the host process". The clauz3 process env has no key, and no link file exists:
fd waiting

Approved from the panel with ⌘↩; hi.txt was written and the dock cleared:
fd approved

Earlier run, same panel, interim env route:
A request waiting beside the agent pane, with the sidebar badge:
waiting

After ⌘↩, clauz3 verified the receipt and ran the program. hello.txt was written, and the dock and badge cleared:
after

Component fixtures (pnpm fixtures:shot clauz3/Clauz3ApprovalCard --theme both):
pending gaps blocked

A forged decide call from the renderer with an unknown card id returned {ok:false, reason:"unknown-card"}.

Tests

  • src/main/clauz3/clauz3-approval-broker.test.ts: runs against a real loopback HTTP stand-in for the service. It covers: no token or origin in renderer data; token only on the POST; shown (with program_sha256) taken from main's snapshot; card ids spent and forged ids refused; a stale card refused without posting; 409 decided and 409 changed (C1-style service); 404; 400 with its detail; hash mismatch blocks approve; Always allow only when eligible; a dead service dropped.
  • src/shared/clauz3/clauz3-approval-view.test.ts: coverage and guarantee parity with clauz3's text and order; approve blockers.
  • src/renderer/src/components/clauz3/Clauz3ApprovalCard.test.tsx: the arm delay, untrusted clicks and keys ignored, no approve when blocked, Always allow only when eligible.
  • src/main/clauz3/clauz3-key-pipe.test.ts (real FIFO, Node pool): a process launched through sh with the exact 3>'<fifo>' redirect hands over the key, and the pipe dir is removed afterwards; a timeout rejects and cleans up; a non-loopback origin or malformed line is refused.
  • src/main/runtime/agent-session/launch/clauz3-launch-paths.test.ts (from spike: run an Orca worker as a restricted clauz3 session #2): its PTY rows now await the async seam with fake handoff deps, and the exact-command row includes the handoff and pipe arguments.
  • Spawn-seam tests: the launch line carries --approver-key-fd 3 and the redirect but no key, nothing is added to env, the session registers only after the key arrives, an undelivered key registers nothing, and a refused line registers nothing.
  • All six clauz3 test files: 65 pass. pnpm typecheck clean. pnpm check:changed: all 45 checks pass.

Known gaps

  1. shown re-check relies on main's pre-read until clauz3 C1 makes the HTTP endpoint re-check shown under the signing lock. The field is already sent.
  2. Polling: clauz3 has no push yet. Main polls fast while requests change, backs off while idle, and stops when no session is left. Terminal workers only: no native-chat sessions, Approvals page, coordinator feed, remote hosts or mobile yet.
  3. clauz3's own follow-up, from fix: use autoUpdater.quitAndInstall() on macOS to apply updates stablyai/orca#62's threat model: its service child still gets the decision and signing keys through its environment.
  4. For reviewer sign-off: clauz3-key-pipe.ts makes three sync fs calls once per restricted launch: two O_NONBLOCK opens of the just-made FIFO, which return at once, and one close. The raw fd must go to net.Socket, which an async FileHandle cannot hand over. They are added to main-sync-fs-baseline and main-blocking-helper-baseline with that reason. The FIFO test runs in the Node test pool, since Bun never reads a FIFO through net.Socket.
  5. Seen in the demo but not caused by this PR: proofs using stdlib:git hit clauz3's 30 s proof timeout.

🤖 Generated with Claude Code

Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​921 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​921
Prod 54 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3023 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3007

@cmungall
cmungall force-pushed the cmungall/feat-native-clauz3-approval branch 3 times, most recently from d8e53f4 to f4b8c0f Compare November 29, 2026 08:32
cmungall pushed a commit that referenced this pull request Nov 30, 2026
…e share a name (stablyai#52701)

Check runs were keyed by suite and name, so two same-named runs in one
suite shared one saved row. Every poll one of them carried a different run
id than the saved row and read as a rerun, posting a new "CI green" line
for the same head. Sort observed runs by run id and suffix repeated names
(#2, #3) so each run keeps its own row and an unchanged read compares equal.

Fixes stablyai#52700

Co-authored-by: Neil <[email protected]>
cmungall and others added 7 commits November 29, 2026 23:12
Add an optional per-agent `agentSessionModes` setting (default native). When
claude is set to `clauz3-restricted`, the pty spawn choke points rewrite the
launch, after `agent.launch.before`, from `claude … -- <prompt>` to
`clauz3 start claude [--model M] --prompt <prompt>`. It fails closed for
resumes, compound lines, unsupported agents and Windows.

docs/clauz3-restricted-worker/FINDINGS.md records the end-to-end dev-build
run (worker-start → proved programs approved in clauz3's web page →
worker_done) and what breaks: the approver key leaking into terminal output,
lost transcripts and status hooks, and the worker protocol needing a trusted
orca library (spike copy included).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restricted workers now start as
`clauz3 start claude --policy .clauz3/cz3tools/orca/worker-approval-policy.json …`,
so routine mail to the worker's own coordinator (worker_done, status,
questions) is auto-approved and everything else still goes to a person. A
new optional `clauz3Command` setting pins the clauz3 build that workers run
(here clauz3 PR stablyai#61's branch, until it merges) without touching the global
install.

Drop the spike's own cz3tools/orca copy in favour of stdlib:orca
(normalform-ai/clauz3#61). Update FINDINGS with the re-run: one approval, 68 s,
one worker_done, ORCA_TERMINAL_HANDLE kept through to the runner, and
ORCA_AGENT_SESSION_ID unset for terminal-mode workers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With agentDefaultSurface=chat, worker-start (and new tabs, bots, automations)
created a structured native-chat Claude session that never went through the
clauz3-restricted PTY wrapper. A restricted agent now fails closed on every
structured path:

- routing: nativeChatPreferenceFor never prefers chat for a restricted
  agent, so chat defaults fall back to the wrapped terminal agent (also
  when a paired client sends its own chat default);
- create: prepareStructuredAgentSessionCreateForWorktree, which every
  structured create goes through (tabs, agent launch, orchestration
  structured workers, bot chats, background chats), refuses with
  structured_agent_session_unsupported and a clear message, before any effect;
- spawn: composeStructuredLaunch, which resolves every structured start
  (resume, restore, queued start of an existing chat), refuses with a
  pre-spawn error;
- PTY: a spawn that names no agent but runs `claude` is wrapped too.

clauz3-launch-paths.test.ts enumerates the launch paths, one row each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stdlib:orca moved out of clauz3 into normalform-ai/clauz3-tools-agents
(PR #1, cmungall/orca-library) as cz3tools.agents.orca, with shared
delegation contracts in cz3tools.agents.core. Restricted workers now start
with --policy .clauz3/cz3tools/agents/orca/worker-approval-policy.json.
clauz3 core is pinned to stablyai#61's (now core-only) branch through clauz3Command.

FINDINGS: new setup (gh: install, then stdlib git/filesystem), item 2, and
the 2026-11-29 dev-build re-run (85 s, one approval, worker_done
auto-approved, default chat surface).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… --approver-key-fd

Restricted Claude sessions (agentSessionModes.claude = clauz3-restricted) are
approved inside Orca instead of clauz3's web page.

- Key handoff over a pipe Orca owns (normalform-ai/clauz3#62): main makes a private
  FIFO, opens its read end, and launches `clauz3 start claude ... --no-browser
  --approver-key-fd 3 ... 3>'<fifo>'`. clauz3 writes {origin, key, login_url} to
  fd 3 once ready; main reads it, removes the FIFO and only then registers the
  session. The key is never in env, argv, the pty or on disk; an undelivered key
  registers nothing.
- A main-process broker polls each approval service, mints one-time card ids,
  freezes the shown snapshot (incl. program_sha256), re-reads the record before
  deciding, and maps 404/409/400 to card outcomes.
- Decide IPC is accepted only from the Orca window's main frame; no CLI, runtime
  RPC, automation or agent path reaches it.
- Card with parity to clauz3's web card, Approve once / Reject / Always allow when
  eligible, keyboard shortcuts with a 750 ms arm delay, pane dock, sidebar badge
  and OS notification.

Normalform-Patch: fork-clauz3-approval-panel

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nts main

Re-ran the combined isolated dev-build demo with every dependency from main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmungall
cmungall force-pushed the cmungall/feat-native-clauz3-approval branch from f4b8c0f to f341cd5 Compare November 30, 2026 07:31
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