Skip to content

spike: run an Orca worker as a restricted clauz3 session - #2

Draft
cmungall wants to merge 5 commits into
mainfrom
cmungall/clauz3-restricted-worker
Draft

cmungall wants to merge 5 commits into
mainfrom
cmungall/clauz3-restricted-worker

Conversation

@cmungall

@cmungall cmungall commented Nov 28, 2026 •

Copy link
Copy Markdown

Phase 0 spike. Off by default, and the patch is small.

This adds two optional settings:

  • agentSessionModes, per agent;
  • clauz3Command, which pins the clauz3 build that workers run.

With {claude: 'clauz3-restricted'}, every Claude launch that reaches the pty spawn choke points (runtime/spawn.ts, ipc/spawn-run.ts) is rewritten after agent.launch.before:

claude … -- <prompt> → clauz3 start claude --policy .clauz3/cz3tools/agents/orca/worker-approval-policy.json [--model M] --prompt <prompt>

It fails closed. Resumes, compound command lines, other agents, Windows, and repos without the policy file all refuse rather than launching natively.

Structured (native chat) sessions fail closed too. orca#3's demo found that with the default chat surface, worker-start started Claude as a structured chat, which skipped the wrapper. A restricted agent now:

  • falls back to the wrapped terminal agent when chat is only a default;
  • refuses explicit chat requests before any effect, saying why;
  • refuses every structured create (tabs, agent launch, structured workers, bot chats, background chats);
  • refuses every structured spawn (resume, restore, queued starts).

clauz3-launch-paths.test.ts has one test row per launch path. Restricted agents are terminal-only until clauz3 can drive native chat.

Dependencies, all from main (nothing pinned to a PR branch): clauz3 main (8468da1 or later: stablyai#61's Delegate event and domain-policy notices, stablyai#62's --approver-key-fd), and the agents/orca and agents/core libraries from normalform-ai/clauz3-tools-agents main (#1 and #2 merged), installed in the repo with clauz3 install gh:normalform-ai/clauz3-tools-agents. When the global clauz3 is older than main, point clauz3Command at a venv built from main:

uv venv c3main
VIRTUAL_ENV=$PWD/c3main uv pip install "clauz3 @ git+https://github.com/normalform-ai/clauz3@main"

Worker protocol: the worker reports with agents/orca's worker_done(task_id, dispatch_id, outcome, subject, summary) under only_to_coordinator(), only_task(T, D) and protocol_messages_at_most(n). agents/orca's worker approval policy auto-approves that routine mail.

Re-tested end to end in an isolated dev build (pnpm dev:fresh, scratch profile; the installed Orca app and the global clauz3 were not touched):

  1. worker-start started a restricted clauz3 worker.
  2. Its write-and-commit program was approved once in clauz3's web page.
  3. Its worker_done program was auto-approved by the policy.
  4. The coordinator saw succeeded 68 s after the start, with exactly one worker_done.

Re-run on 2026-11-29 with everything from main and agentDefaultSurface: chat (with orca#3's panel on top): worker-start fell back to a restricted terminal worker; write-and-commit was approved once, worker_done was auto-approved, and the coordinator saw succeeded. Details in orca#3 and FINDINGS.

ORCA_TERMINAL_HANDLE reaches the program runner. ORCA_AGENT_SESSION_ID is not set for terminal-mode workers.

Findings, the exact launch path and the minimal upstream hook set are in docs/clauz3-restricted-worker/FINDINGS.md. Open issues:

  • The approver login key was printed into the terminal stream. clauz3#62 (merged) adds --approver-key-fd, and orca#3 uses it so the key never reaches the pty.
  • Transcripts and status hooks are lost.
  • Resume and restore need a clauz3 resume mapping.
  • The policy only covers agents/core, agents/orca, git and filesystem; a repo that adds any other layer needs extra no_* clauses.

Rebased onto upstream stablyai/orca main be4d21c0c94. Tests: pnpm test src/shared/agent-launch/restricted/clauz3-restricted-launch.test.ts src/main/runtime/agent-session/launch/clauz3-launch-paths.test.ts, pnpm typecheck, and pnpm check:changed (run on the stacked orca#3 branch, which contains this one).

🤖 Generated with Claude Code

Files Added Deleted Net
Test 45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6640 $\color{#cf222e}{\Huge{\mathbf{−}}}$​36 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6604
Prod 334 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15304 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4267 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11037

@cmungall
cmungall force-pushed the cmungall/clauz3-restricted-worker branch 3 times, most recently from 64a01b4 to 2e23c9d Compare November 29, 2026 08:22
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 5 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]>
@cmungall
cmungall force-pushed the cmungall/clauz3-restricted-worker branch from 2e23c9d to 8a00c03 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