typeclaw 0.48.13 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/package.json +5 -5
  2. package/scripts/dump-system-prompt.ts +52 -110
  3. package/src/agent/index.ts +144 -72
  4. package/src/agent/live-sessions.ts +2 -2
  5. package/src/agent/live-subagents.ts +1 -0
  6. package/src/agent/plugin-tools.ts +53 -11
  7. package/src/agent/prompt-cache-key.ts +42 -0
  8. package/src/agent/provider-error.ts +179 -10
  9. package/src/agent/restart-handoff/index.ts +7 -14
  10. package/src/agent/reviewer-activity.ts +68 -0
  11. package/src/agent/session-origin.ts +33 -0
  12. package/src/agent/subagents.ts +13 -1
  13. package/src/agent/system-prompt.ts +68 -202
  14. package/src/agent/todo/continuation-policy.ts +12 -4
  15. package/src/agent/tool-file-safety.ts +113 -14
  16. package/src/agent/tool-not-found-nudge.ts +1 -1
  17. package/src/agent/tools/channel-history-render.ts +2 -1
  18. package/src/agent/tools/channel-reply.ts +23 -5
  19. package/src/agent/tools/channel-send.ts +49 -7
  20. package/src/agent/tools/curl-impersonate.ts +11 -2
  21. package/src/agent/tools/post-github-review.ts +77 -15
  22. package/src/agent/tools/skip-response.ts +2 -2
  23. package/src/agent/tools/spawn-subagent.ts +163 -12
  24. package/src/agent/tools/subagent-output.ts +8 -0
  25. package/src/bundled-plugins/backup/README.md +10 -9
  26. package/src/bundled-plugins/backup/runner.ts +140 -58
  27. package/src/bundled-plugins/backup/subagents.ts +58 -26
  28. package/src/bundled-plugins/github-cli-auth/gh-command.ts +34 -2
  29. package/src/bundled-plugins/github-cli-auth/granted-push.ts +135 -0
  30. package/src/bundled-plugins/github-cli-auth/index.ts +83 -11
  31. package/src/bundled-plugins/github-cli-auth/review-account.ts +23 -0
  32. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -2
  33. package/src/bundled-plugins/github-cli-auth/review-recorder.ts +45 -7
  34. package/src/bundled-plugins/operator/operator.ts +15 -4
  35. package/src/bundled-plugins/reviewer/skills/code-review.ts +1 -1
  36. package/src/bundled-plugins/security/index.ts +50 -2
  37. package/src/bundled-plugins/security/policies/git-exfil.ts +24 -12
  38. package/src/channels/adapters/discord-bot-reactions.ts +18 -0
  39. package/src/channels/adapters/discord-bot.ts +122 -67
  40. package/src/channels/adapters/discord-reactions.ts +18 -0
  41. package/src/channels/adapters/discord.ts +114 -8
  42. package/src/channels/adapters/github/inbound.ts +103 -8
  43. package/src/channels/adapters/github/index.ts +251 -19
  44. package/src/channels/adapters/github/last-alive.ts +27 -0
  45. package/src/channels/adapters/github/outbound.ts +54 -18
  46. package/src/channels/adapters/github/pending-review-store.ts +141 -0
  47. package/src/channels/adapters/github/permission-guidance.ts +1 -0
  48. package/src/channels/adapters/github/reactions.ts +100 -0
  49. package/src/channels/adapters/github/reconcile-cooldown-store.ts +197 -67
  50. package/src/channels/adapters/github/reconcile-open-prs.ts +418 -33
  51. package/src/channels/adapters/github/recovery.ts +106 -0
  52. package/src/channels/adapters/github/review-check.ts +510 -0
  53. package/src/channels/adapters/github/review-submitter.ts +34 -2
  54. package/src/channels/adapters/instagram.ts +32 -14
  55. package/src/channels/adapters/kakaotalk.ts +22 -7
  56. package/src/channels/adapters/line.ts +18 -3
  57. package/src/channels/adapters/outbound-account.ts +20 -0
  58. package/src/channels/adapters/own-reactions.ts +66 -0
  59. package/src/channels/adapters/recovery-correlation.ts +214 -0
  60. package/src/channels/adapters/slack-bot-classify.ts +18 -11
  61. package/src/channels/adapters/slack-bot-dedupe.ts +111 -28
  62. package/src/channels/adapters/slack-bot-reactions.ts +18 -0
  63. package/src/channels/adapters/slack-bot.ts +125 -57
  64. package/src/channels/adapters/slack-classify.ts +25 -4
  65. package/src/channels/adapters/slack-inbound-revision.ts +96 -0
  66. package/src/channels/adapters/slack-reactions.ts +18 -0
  67. package/src/channels/adapters/slack-thread-ts.ts +6 -0
  68. package/src/channels/adapters/slack.ts +48 -3
  69. package/src/channels/adapters/teams.ts +14 -4
  70. package/src/channels/adapters/telegram-bot.ts +56 -10
  71. package/src/channels/adapters/webex-bot.ts +12 -2
  72. package/src/channels/adapters/webex.ts +12 -2
  73. package/src/channels/background-handoff.ts +434 -0
  74. package/src/channels/background-obligations.ts +893 -0
  75. package/src/channels/continuity-types.ts +271 -0
  76. package/src/channels/github-review-check.ts +598 -0
  77. package/src/channels/github-review-turn-ledger.ts +102 -28
  78. package/src/channels/github-review-verdict-coordinator.ts +72 -12
  79. package/src/channels/github-token-bridge.ts +11 -5
  80. package/src/channels/inbound-journal.ts +1738 -0
  81. package/src/channels/index.ts +6 -1
  82. package/src/channels/manager.ts +17 -7
  83. package/src/channels/recovery-dispatcher.ts +264 -0
  84. package/src/channels/recovery-notice.ts +94 -0
  85. package/src/channels/recovery-outbox.ts +459 -0
  86. package/src/channels/router.ts +2539 -615
  87. package/src/channels/schema.ts +8 -1
  88. package/src/channels/subagent-completion-bridge.ts +17 -14
  89. package/src/channels/types.ts +121 -16
  90. package/src/channels/waiting-reactions.ts +664 -0
  91. package/src/cli/compose.ts +7 -4
  92. package/src/cli/hostd.ts +49 -3
  93. package/src/cli/inspect.ts +11 -14
  94. package/src/coding-agent/broker-body.ts +38 -0
  95. package/src/coding-agent/broker.ts +290 -0
  96. package/src/coding-agent/claude.ts +95 -0
  97. package/src/coding-agent/codex.ts +104 -0
  98. package/src/coding-agent/index.ts +506 -0
  99. package/src/coding-agent/omo-state.ts +69 -0
  100. package/src/coding-agent/omo-stream.ts +98 -0
  101. package/src/coding-agent/omo.ts +192 -0
  102. package/src/coding-agent/runner.ts +263 -0
  103. package/src/coding-agent/tool.ts +62 -0
  104. package/src/coding-agent/worktree.ts +355 -0
  105. package/src/compose/restart.ts +10 -3
  106. package/src/compose/start.ts +20 -3
  107. package/src/config/config.ts +10 -3
  108. package/src/config/providers.ts +12 -9
  109. package/src/container/exit-reason.ts +44 -0
  110. package/src/container/index.ts +5 -0
  111. package/src/container/log-archive.ts +51 -13
  112. package/src/container/memory-limit.ts +1 -1
  113. package/src/container/memory-oversubscription.ts +36 -6
  114. package/src/container/oom-events.ts +86 -0
  115. package/src/container/restart.ts +2 -0
  116. package/src/container/shared.ts +8 -1
  117. package/src/container/start.ts +25 -13
  118. package/src/container/stop.ts +6 -2
  119. package/src/container/tool-oom-priority.ts +32 -0
  120. package/src/cron/consumer.ts +10 -4
  121. package/src/cron/reloadable.ts +23 -2
  122. package/src/doctor/checks.ts +14 -2
  123. package/src/hostd/daemon.ts +20 -10
  124. package/src/hostd/spawn.ts +106 -5
  125. package/src/hostd/version.ts +20 -0
  126. package/src/hostd/watchdog.ts +241 -0
  127. package/src/init/dockerfile.ts +57 -592
  128. package/src/init/index.ts +2 -3
  129. package/src/mcp/client.ts +3 -1
  130. package/src/operations/classify-tool-outcome.ts +45 -1
  131. package/src/operations/incidents.ts +10 -5
  132. package/src/plugin/core-tool-names.ts +1 -1
  133. package/src/plugin/define.ts +1 -0
  134. package/src/plugin/index.ts +1 -0
  135. package/src/plugin/types.ts +6 -1
  136. package/src/run/background-handoff-boot.ts +86 -0
  137. package/src/run/index.ts +83 -83
  138. package/src/run/resource-sample.ts +19 -0
  139. package/src/sandbox/build.ts +4 -0
  140. package/src/sandbox/coding-agent.ts +214 -0
  141. package/src/sandbox/policy.ts +1 -0
  142. package/src/sandbox/runtime-private.ts +4 -1
  143. package/src/secrets/coding-agent-auth.ts +97 -0
  144. package/src/secrets/index.ts +0 -16
  145. package/src/server/command-runner.ts +6 -2
  146. package/src/server/index.ts +101 -40
  147. package/src/skills/typeclaw-channel-github/SKILL.md +7 -5
  148. package/src/skills/typeclaw-claude-code/SKILL.md +25 -260
  149. package/src/skills/typeclaw-claude-code/references/auth-flow.md +7 -23
  150. package/src/skills/typeclaw-claude-code/references/headless-sessions.md +11 -0
  151. package/src/skills/typeclaw-claude-code/references/results-and-worktrees.md +13 -0
  152. package/src/skills/typeclaw-codex-cli/SKILL.md +35 -270
  153. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +13 -20
  154. package/src/skills/typeclaw-codex-cli/references/headless-sessions.md +26 -0
  155. package/src/skills/typeclaw-codex-cli/references/results-and-worktrees.md +28 -0
  156. package/src/skills/typeclaw-config/SKILL.md +21 -21
  157. package/src/skills/typeclaw-config/references/dockerfile.md +14 -13
  158. package/src/skills/typeclaw-cron/SKILL.md +1 -1
  159. package/src/skills/typeclaw-github-contributing/SKILL.md +2 -2
  160. package/src/skills/typeclaw-memory/SKILL.md +3 -3
  161. package/src/skills/typeclaw-omo-cli/SKILL.md +52 -0
  162. package/src/skills/typeclaw-omo-cli/references/auth-flow.md +11 -0
  163. package/src/skills/typeclaw-omo-cli/references/headless-sessions.md +11 -0
  164. package/src/skills/typeclaw-omo-cli/references/results-and-worktrees.md +23 -0
  165. package/src/skills/typeclaw-plugins/SKILL.md +15 -15
  166. package/src/skills/typeclaw-skills/SKILL.md +19 -2
  167. package/src/skills/typeclaw-troubleshooting/SKILL.md +15 -2
  168. package/typeclaw.schema.json +12 -1
  169. package/src/secrets/claude-credentials-json.ts +0 -129
  170. package/src/secrets/codex-auth-json.ts +0 -102
  171. package/src/secrets/export-claude-credentials-file.ts +0 -270
  172. package/src/secrets/export-codex-auth-file.ts +0 -250
  173. package/src/skills/typeclaw-claude-code/references/stop-hook.md +0 -101
  174. package/src/skills/typeclaw-claude-code/references/tmux-driving.md +0 -243
  175. package/src/skills/typeclaw-codex-cli/references/stop-hook.md +0 -92
  176. package/src/skills/typeclaw-codex-cli/references/tmux-driving.md +0 -239
@@ -1,11 +1,11 @@
1
1
  import { CONTAINER_AGENT_MESSENGER_CONFIG_DIR } from '@/agent-messenger/config-dir'
2
2
  import { ASKPASS_SCRIPT, TYPECLAW_GIT_ASKPASS_PATH } from '@/bundled-plugins/github-cli-auth/git-askpass'
3
+ import { CLAUDE_CODE_VERSION } from '@/coding-agent/claude'
4
+ import { CODEX_CLI_VERSION } from '@/coding-agent/codex'
5
+ import { OMO_CLI_VERSION } from '@/coding-agent/omo'
3
6
  import { validateDockerfileAppendLine } from '@/config/config'
4
7
  import type { DockerfileConfig, DockerfileFeatureToggle } from '@/config/config'
5
- import {
6
- CLAUDE_CREDENTIALS_FILE_NAME,
7
- CLAUDE_CREDENTIALS_RELATIVE_PATH,
8
- } from '@/secrets/export-claude-credentials-file'
8
+ import { TESTED_BUN_VERSION } from '@/hostd/version'
9
9
 
10
10
  import { GHCR_BASE_IMAGE_REPO } from './cli-version'
11
11
 
@@ -423,89 +423,6 @@ link_configured_symlinks() {
423
423
  ' || true
424
424
  }
425
425
 
426
- # link_custom_claude_credentials keeps a custom CLAUDE_CONFIG_DIR credential file
427
- # out of model-visible reach. The Claude Code exporter writes the OAuth refresh
428
- # token to \$CLAUDE_CONFIG_DIR/.credentials.json when that env var is set. Under
429
- # the default (unset) it lands in the runtime HOME's .claude, which bwrap never
430
- # binds — invisible to sandboxed bash. But a custom dir under /agent (or any
431
- # jail-visible root) would put the real token where model bash can read it.
432
- #
433
- # Instead of masking every possible custom location, plant a symlink from the
434
- # custom path INTO the runtime HOME's .claude and let the exporter's
435
- # symlink-aware writeAtomic() follow it — so the real bytes always live in the
436
- # unbound, already-denied runtime HOME regardless of where CLAUDE_CONFIG_DIR
437
- # points. This restores the invariant the old persistence helper used to provide
438
- # (it linked into the masked persist root); the target moved to the ephemeral
439
- # HOME, but the "credential is only an alias in the custom dir" property is
440
- # preserved. Runs in the root phase before privilege drop so custom dirs under
441
- # root-owned roots (e.g. /etc) can still be created. No-op when the value is
442
- # unset/blank or already resolves to the runtime HOME's .claude (avoids a
443
- # self-referential link). Re-linking is idempotent (an existing symlink is
444
- # replaced); failures are non-fatal so a bad custom path never blocks boot.
445
- #
446
- # The from-path MUST match where the exporter actually writes. The exporter
447
- # (src/secrets/export-claude-credentials-file.ts resolveClaudeConfigDir) applies
448
- # JS String.trim() and treats an all-whitespace value as unset. Replicating that
449
- # in POSIX sed would diverge on Unicode whitespace (\u00A0, \u2003, …) that
450
- # .trim() strips but a byte-oriented sed class does not — a divergence is a
451
- # credential-isolation bypass (exporter writes the trimmed path, alias sits at
452
- # the padded path, token stays model-readable). So do the normalization in the
453
- # same \`bun -e\` runtime the exporter uses, guaranteeing byte-for-byte identical
454
- # trimming, and create the symlink there too.
455
- link_custom_claude_credentials() {
456
- CLAUDE_CONFIG_DIR="\${CLAUDE_CONFIG_DIR:-}" _CLAUDE_RUNTIME_HOME="$runtime_home" \\
457
- _CLAUDE_CRED_FILE="${CLAUDE_CREDENTIALS_FILE_NAME}" _CLAUDE_CRED_REL="${CLAUDE_CREDENTIALS_RELATIVE_PATH}" bun -e '
458
- import { mkdirSync, rmSync, symlinkSync } from "node:fs";
459
- import { dirname, join } from "node:path";
460
- const raw = process.env.CLAUDE_CONFIG_DIR;
461
- const trimmed = raw?.trim();
462
- if (trimmed === undefined || trimmed.length === 0) process.exit(0);
463
- const runtimeHome = process.env._CLAUDE_RUNTIME_HOME || "/home/agent";
464
- const from = join(trimmed, process.env._CLAUDE_CRED_FILE);
465
- const to = join(runtimeHome, process.env._CLAUDE_CRED_REL);
466
- if (from === to) process.exit(0);
467
- try {
468
- mkdirSync(trimmed, { recursive: true });
469
- mkdirSync(dirname(to), { recursive: true });
470
- // Unconditionally (re)point the alias, matching the old ln -sfn: a
471
- // pre-existing real file at the custom path would otherwise keep the token
472
- // model-readable, which is exactly the exposure this aliasing closes.
473
- try { rmSync(from); } catch { /* nothing to remove */ }
474
- symlinkSync(to, from);
475
- } catch (e) {
476
- console.error("typeclaw-entrypoint: failed to alias custom Claude credentials:", String(e));
477
- }
478
- ' || true
479
- }
480
-
481
- # seed_runtime_home copies the image-baked Claude Code / Codex CLI settings from
482
- # the build-time HOME (/root) into the ephemeral runtime HOME. The Dockerfile
483
- # writes ~/.claude.json, ~/.claude/settings.json, and ~/.codex/hooks.json against
484
- # /root during \`docker build\`; once the runtime runs under HOME=$runtime_home
485
- # those files would otherwise be invisible, silently disabling Claude onboarding
486
- # state and both CLIs' completion hooks for claudeCode/codexCli users.
487
- #
488
- # Runs in the root setup phase (HOME is still /root), BEFORE the optional chown
489
- # so copied files have the dynamic host ownership when the runtime drops
490
- # privileges. \`cp -n\` keeps repeated shim execution idempotent within one
491
- # container life; Docker removes this HOME with the container.
492
- seed_runtime_home() {
493
- _src="\${1:-/root}"
494
- _dst="$2"
495
- [ "$_src" = "$_dst" ] && return 0
496
- mkdir -p "$_dst"
497
- [ -f "$_src/.claude.json" ] && cp -n "$_src/.claude.json" "$_dst/.claude.json" 2>/dev/null || true
498
- if [ -f "$_src/.claude/settings.json" ]; then
499
- mkdir -p "$_dst/.claude"
500
- cp -n "$_src/.claude/settings.json" "$_dst/.claude/settings.json" 2>/dev/null || true
501
- fi
502
- if [ -f "$_src/.codex/hooks.json" ]; then
503
- mkdir -p "$_dst/.codex"
504
- cp -n "$_src/.codex/hooks.json" "$_dst/.codex/hooks.json" 2>/dev/null || true
505
- fi
506
- unset _src _dst
507
- }
508
-
509
426
  start_xvfb() {
510
427
  if ! command -v Xvfb >/dev/null 2>&1; then
511
428
  return 0
@@ -575,8 +492,6 @@ fi
575
492
 
576
493
  runtime_home="\${TYPECLAW_RUNTIME_HOME:-/home/agent}"
577
494
  mkdir -p "$runtime_home"
578
- seed_runtime_home "$HOME" "$runtime_home"
579
- link_custom_claude_credentials
580
495
  if [ -n "\${TYPECLAW_HOST_UID:-}" ] && [ -n "\${TYPECLAW_HOST_GID:-}" ]; then
581
496
  chown -R "$TYPECLAW_HOST_UID:$TYPECLAW_HOST_GID" "$runtime_home"
582
497
  fi
@@ -759,511 +674,26 @@ RUN SHARP_ARCH="$(case "$(uname -m)" in aarch64|arm64) echo arm64 ;; x86_64|amd6
759
674
  "@img/sharp-libvips-linux-\${SHARP_ARCH}@1.2.4"
760
675
  WORKDIR /agent`
761
676
 
762
- // Claude Code's official installer is `curl | bash`, not apt — can't live
763
- // in APT_FEATURES. Layer placed after the toggle apt install (so curl + ca-
764
- // certificates from the baseline are guaranteed present) and before the
765
- // entrypoint shim (which is always last). Omitted entirely when disabled.
766
- //
767
- // The Anthropic installer drops `claude` at `$HOME/.local/bin/claude` and
768
- // emits a "~/.local/bin is not in your PATH" warning on every install on
769
- // bun:1-slim (PATH out of the box is `/usr/local/sbin:/usr/local/bin:/usr/
770
- // sbin:/usr/bin:/sbin:/bin:/usr/local/bun-node-fallback-bin`, no
771
- // `~/.local/bin`). Without intervention, every `which claude` from the
772
- // agent (and from the typeclaw-claude-code skill's verification step)
773
- // returns empty. Symlink into `/usr/local/bin/` — already on PATH, matches
774
- // what `cloudflared` does, survives `/root/.local/bin` getting rewritten
775
- // by the installer's "update" path. The symlink resolves to the
776
- // `~/.local/bin/claude` shim, which itself dereferences to the versioned
777
- // binary under `~/.local/share/claude/versions/<ver>/`, so upgrades via
778
- // `claude update` keep working without re-running this layer.
779
- // `~/.claude.json` is Claude Code's internal state file (NOT
780
- // `~/.claude/settings.json`, which is user-facing). On first run with an
781
- // empty or missing file, `claude` enters a TTY-only theme picker:
782
- // "Welcome to Claude Code … Choose the text style that looks best with
783
- // your terminal" with 7 options. The picker is unskippable via CLI
784
- // flags or env vars (no `--skip-onboarding`, no `--theme=dark`;
785
- // `IS_DEMO=1` exists but has documented side effects). The single
786
- // official escape hatch is writing `{"hasCompletedOnboarding": true,
787
- // "theme": "dark"}` to `~/.claude.json` before the first launch —
788
- // confirmed by Anthropic in multiple GitHub issues
789
- // (anthropics/claude-code#4714, #8938, #13827) and the empirical
790
- // answer used by metabase/metabase's `bin/claude-dangerous`, the
791
- // `claudeCodeAlDevContainer` feature, and dozens of other Docker
792
- // integrations.
793
- //
794
- // Without the pre-seed, the very first agent-driven `tmux new-session …
795
- // claude` invocation hangs on the theme picker: the agent's
796
- // `send-keys "<prompt>" Enter` arrives at the picker, gets interpreted
797
- // as picker input, and never reaches claude's actual prompt. The
798
- // `typeclaw-claude-code` skill is structured around a `Stop`-hook
799
- // sentinel, which never fires while the picker is up, so the polling
800
- // loop only learns of the hang at the 10-minute wall-clock budget.
801
- // Pre-seeding here costs ~85 bytes on disk and zero runtime overhead.
802
- //
803
- // SCOPE: this seed is NECESSARY but not SUFFICIENT for a fully
804
- // no-questions-asked first launch. Claude Code also shows two
805
- // post-seed modal dialogs that this file deliberately does NOT
806
- // pre-clear:
807
- // 1. "Detected a custom API key from environment. Do you want to use
808
- // this API key?" — fires when ANTHROPIC_API_KEY is set. Options
809
- // `[No (recommended), Yes]`, focus on No, picker does NOT wrap.
810
- // 2. Workspace trust ("Do you trust the files in this folder?") —
811
- // fires on every new cwd. Options `[Yes, proceed, No, exit]`,
812
- // focus on Yes.
813
- // Both are kept as runtime decisions handled by the
814
- // `typeclaw-claude-code` skill (see its "Driving the session" section,
815
- // "Clear startup dialogs" step, which uses dialog-specific keystrokes
816
- // because the picker doesn't wrap). Pre-seeding
817
- // `hasTrustDialogAccepted` or `customApiKeyResponses.approved` here
818
- // would silently widen the trust surface in ways the operator hasn't
819
- // consented to — the seed's job is strictly cosmetic-wizard removal,
820
- // not trust/permission preemption.
821
- //
822
- // `theme: "dark"` matches typeclaw's default TUI theme so the visual
823
- // transition between the typeclaw TUI and a tmux-attached claude pane
824
- // is consistent. Users on light terminals can override by editing
825
- // `~/.claude.json` (which persists across container restarts only if
826
- // they mount it; in the default container-ephemeral state it resets
827
- // to this default on every rebuild, which is fine — `claude` reads
828
- // the file at startup and the theme has no behavioral impact).
829
- //
830
- // `lastOnboardingVersion` is INTENTIONALLY OMITTED. ii-agent and a
831
- // few other templates ship `lastOnboardingVersion: "1.0.30"`, but
832
- // that value is version-coupled and goes stale on every Claude Code
833
- // release. Empirically against Claude Code 2.1.146, the current
834
- // `hasCompletedOnboarding: true` alone is honored without a version
835
- // pin. If a future Claude version starts re-triggering the picker
836
- // when the field is missing, capture `claude --version` output at
837
- // build time and inject it then — don't hardcode a stale value.
838
- //
839
- // `installMethod: "native"` and `numStartups: 1` match the shape
840
- // Claude Code itself writes after a clean first launch; keeping them
841
- // makes our seed indistinguishable from a real post-onboarding state,
842
- // which minimizes the chance of a future "if the file looks like
843
- // agent-pre-seed, redo onboarding" detection heuristic landing on us.
844
- //
845
- // Built via `JSON.stringify` rather than a hand-written string
846
- // literal so quote/escape bugs surface as TS errors at compile time,
847
- // not as a corrupt `~/.claude.json` discovered only when the build
848
- // runs. The `printf '%s\\n' '<JSON>'` shell pattern relies on the
849
- // JSON containing no single quotes (true by construction — JSON.
850
- // stringify only emits double quotes); a regression test parses the
851
- // emitted JSON back to confirm.
852
- const CLAUDE_CODE_ONBOARDING_SEED = JSON.stringify({
853
- hasCompletedOnboarding: true,
854
- theme: 'dark',
855
- installMethod: 'native',
856
- numStartups: 1,
857
- })
858
-
859
- // The Stop hook is what powers the typeclaw-claude-code skill's done-signal:
860
- // the operator subagent spawns claude in a worktree, polls a sentinel file,
861
- // and decides "turn done" from the file's contents. The hook was originally
862
- // per-worktree (`<worktree>/.claude/settings.json` + `<worktree>/hook-on-
863
- // stop.sh`), which meant the operator subagent wrote both files itself at
864
- // delegation time. That worked when operator wrote the canonical shape —
865
- // and silently failed when it didn't. Claude Code's settings parser
866
- // ignores unknown keys, so wrong-shape configs (`{"hooks": {"onStop":
867
- // "./script.sh"}}`, `{"hooks": {"Stop": "./script.sh"}}`,
868
- // `{"hooks": {"Stop": [{"command": "./script.sh"}]}}` etc.) surface as
869
- // "polling timed out at the 10-minute wall-clock budget" rather than as a
870
- // parse error — the failure is invisible until you've already paid the
871
- // budget. The skill's "do not simplify this JSON" warning helps but doesn't
872
- // eliminate the slip: as long as an LLM has to write the JSON, an LLM can
873
- // invent a shape.
874
- //
875
- // Move both pieces to Dockerfile-build time, where the JSON is constructed
876
- // once via JSON.stringify and the shape can never drift from the operator's
877
- // reading of the skill:
878
- //
879
- // 1. `/usr/local/bin/typeclaw-cc-stop-hook` — the hook script. Stable
880
- // absolute path so the global settings.json can name it without
881
- // worrying about $PATH. Reads stdin (Claude Code's Stop event JSON)
882
- // and atomically writes `$PWD/sentinel.json` + touches `$PWD/.done`.
883
- // The temp-file-then-rename keeps the read side from ever seeing a
884
- // partial sentinel even if the polling loop races the write — same
885
- // atomicity contract as the previous per-worktree script.
886
- // 2. `~/.claude/settings.json` — the user-level (global) hook config.
887
- // User-level hooks fire for every `claude` invocation regardless of
888
- // cwd, so the operator's worktree no longer needs its own
889
- // `.claude/settings.json`. (Claude Code merges hooks additively
890
- // across scopes per docs.claude.com/en/docs/claude-code/settings —
891
- // if a future user mounts their own `~/.claude/settings.json` with a
892
- // different Stop hook, both fire in parallel rather than ours being
893
- // clobbered.)
894
- //
895
- // Both files are written via JSON.stringify + heredoc; the JSON shape is
896
- // validated by JSON.parse in dockerfile.test.ts, so a future edit that
897
- // corrupts the structure fails the test, not the docker build (let alone
898
- // the next delegation that runs against the broken hook). The previous
899
- // per-worktree path is fully removed from the skill body; the only place
900
- // the hook shape lives is here.
901
- //
902
- // IMPORTANT — \`$PWD\` vs \`$CLAUDE_PROJECT_DIR\`: an earlier version of this
903
- // layer used \`$CLAUDE_PROJECT_DIR\`. Self-review caught this as a critical
904
- // bug. \`CLAUDE_PROJECT_DIR\` is Claude Code's documented env var for "the
905
- // project root" — but empirically (see anthropics/claude-code#27343 and
906
- // #44450), inside a git worktree it resolves to the *main repo's* git
907
- // root, NOT the worktree's path. The operator's flow is:
908
- // git -C /agent worktree add /tmp/cc-<id> HEAD
909
- // tmux new-session -d -s cc-<id> -c /tmp/cc-<id> claude
910
- // So \`/tmp/cc-<id>\` is a registered worktree of \`/agent\`, and Claude
911
- // Code would resolve \`CLAUDE_PROJECT_DIR=/agent\` — landing the sentinel
912
- // in the live agent folder while the polling loop watches the worktree.
913
- //
914
- // The fix: write to \`$PWD\` instead. \`$PWD\` is set by every POSIX shell
915
- // on every invocation (POSIX-required since IEEE 1003.1-1988), and it's
916
- // the literal cwd Claude Code was invoked with — exactly the worktree
917
- // path \`tmux -c\` set. \`CLAUDE_PROJECT_DIR\` is Anthropic-specific and
918
- // has shifted semantics across versions per the cited bug reports; we
919
- // deliberately avoid depending on it.
920
- //
921
- // PER-SESSION FILENAMES — concurrent-claude race safety: the Stop hook
922
- // writes to \`sentinel-<session_id>.json\` and \`.done-<session_id>\`,
923
- // not a fixed filename. session_id comes from Claude Code's Stop event
924
- // JSON on stdin (\`BaseHookInputSchema.session_id\`, always present per
925
- // the upstream schema). The operator learns the UUID by reading a
926
- // \`.session-id\` file that a SessionStart hook (also baked here) writes
927
- // at session-start time; see TYPECLAW_CC_SESSION_START_HOOK_SCRIPT
928
- // below.
929
- //
930
- // The earlier shape used fixed \`sentinel.json\` + \`.done\` names, which
931
- // is safe when each worktree has at most one claude session (today's
932
- // only caller). But if two callers ever share a cwd — operator A and
933
- // operator B both delegating in \`/agent\`, a future plugin that runs
934
- // \`claude\` from a shared dir, or an out-of-band caller violating the
935
- // "one worktree per delegation" invariant — both write to the same
936
- // file and corrupt each other's state with no diagnostic. Per-session
937
- // filenames make the race structurally impossible.
938
- //
939
- // WHY NOT \`claude --session-id <pre-generated-uuid>\`: an earlier
940
- // iteration of this PR had the operator pre-generate a UUID and pass
941
- // it via \`--session-id\`. Self-review caught that as a critical bug:
942
- // per anthropics/claude-code#44607, the \`--session-id\` flag only
943
- // controls the persistence/transcript UUID in \`-p\` (print) mode. In
944
- // interactive mode (which the typeclaw-claude-code skill uses), the
945
- // flag sets a separate telemetry/API ID while the CLI generates its
946
- // own internal UUID for the transcript file and for the \`session_id\`
947
- // field that hooks see. The pre-generated UUID and the hook's UUID
948
- // don't match — the polling loop times out forever. The current
949
- // design sidesteps this entirely: the operator does NOT pass
950
- // \`--session-id\`; it lets claude generate its own UUID and learns it
951
- // back via the \`.session-id\` file the SessionStart hook writes.
952
- //
953
- // session_id extraction: \`bun -e\` against the JSON payload. We use bun,
954
- // NOT POSIX sed, because bun is guaranteed in the container (bun:1-slim
955
- // base) and is a real JSON parser. A previous iteration used
956
- // \`sed -n 's/.*"session_id":"\\([^"]*\\)".*/\\1/p'\` which is greedy and
957
- // picks the LAST \`"session_id":"..."\` occurrence in the JSON.
958
- // Claude Code's Stop event carries \`last_assistant_message\` which
959
- // contains the assistant's prose — that prose can include the literal
960
- // text \`"session_id":"<fake-uuid>"\` (the model might have been
961
- // discussing session IDs!), which sed would extract instead of the
962
- // top-level field. bun's JSON.parse picks the structural \`session_id\`
963
- // regardless of what appears in nested string values. UUID-shape
964
- // validation still applies downstream as defense-in-depth against
965
- // path-traversal session_id values; malformed JSON or missing field
966
- // falls back to "malformed" so the polling loop sees SOMETHING and
967
- // can surface the corruption.
968
- //
969
- // FALLBACK FILENAMES — \`sentinel-malformed.json\` / \`.done-malformed\`:
970
- // if session_id extraction fails or validation rejects the result, the
971
- // hook writes to these fixed names. The operator's polling loop watches
972
- // its own \`<sid>\` file (read from \`.session-id\`) and will time out —
973
- // but the \`-malformed\` file exists on disk so a post-mortem inspector
974
- // can tell "hook fired but session_id was bad" apart from "hook never
975
- // fired at all."
976
- //
977
- // SECURITY/SCOPE: both hook scripts only touch files inside \`$PWD\`,
978
- // with filenames validated to UUID shape or the fixed "malformed"
979
- // fallback. Even with an adversarial \`session_id\` in the stdin
980
- // payload, the worst case is "hook writes \`$PWD/sentinel-malformed.json\`"
981
- // or "hook writes \`$PWD/.session-id\` containing 'malformed'" — never
982
- // path traversal, never writes outside \`$PWD\`. The hooks run as root
983
- // inside the container like every other in-container process; there is
984
- // no privilege boundary to cross.
985
- const TYPECLAW_CC_STOP_HOOK_PATH = '/usr/local/bin/typeclaw-cc-stop-hook'
986
- const TYPECLAW_CC_SESSION_START_HOOK_PATH = '/usr/local/bin/typeclaw-cc-session-start-hook'
987
-
988
- // SessionStart hook script. Fires when a session begins via
989
- // startup/resume/clear/compact per the upstream lifecycle docs. Writes
990
- // \`$PWD/.session-id\` containing the validated UUID, atomically.
991
- //
992
- // IMPORTANT — \`.session-id\` is a FAST PATH, not a precondition. Per
993
- // anthropics/claude-code#11519, SessionStart can be SKIPPED entirely
994
- // when workspace trust hasn't been accepted yet: debug logs show
995
- // \`Skipping SessionStart:startup hook execution - workspace trust not
996
- // accepted\`. For the typeclaw-claude-code skill flow, EVERY first
997
- // invocation in a fresh worktree hits this — the trust dialog fires
998
- // before any prompt can be sent. So \`.session-id\` may never appear
999
- // pre-first-prompt. The skill instructs the operator to fall back to
1000
- // reading session_id from the FIRST Stop hook's sentinel instead.
1001
- // \`.session-id\` is still useful for sessions that were already
1002
- // trusted (re-attaching to a running worktree, etc.) — when it
1003
- // appears, the operator can skip the discovery step.
1004
- //
1005
- // IMPORTANT — \`compact\` can ROTATE the session_id. The upstream
1006
- // behavior is documented in anthropics/claude-code#29094: a SessionStart
1007
- // with \`source: "compact"\` is a NEW session linked via
1008
- // \`parent_session_id\`. So \`.session-id\` can change mid-delegation if
1009
- // a long claude session compacts itself. The operator's polling loop
1010
- // must handle session_id rotation: a new \`.done-<different-uuid>\`
1011
- // appearing means \`cc_session_id\` should update to the new value.
1012
- const TYPECLAW_CC_SESSION_START_HOOK_SCRIPT = `#!/bin/sh
1013
- # typeclaw SessionStart-hook for Claude Code. Stdin carries the
1014
- # SessionStart event JSON. Writes \$PWD/.session-id with the session
1015
- # UUID as a fast-path optimization (the operator falls back to
1016
- # discovering session_id from the first Stop sentinel if .session-id
1017
- # never appears — see anthropics/claude-code#11519). Rationale lives
1018
- # in src/init/dockerfile.ts.
1019
- #
1020
- # Both temp filenames are PID-scoped (PID = \$\$) so two SessionStart
1021
- # hooks firing concurrently in the same cwd don't race on the same
1022
- # temp file.
1023
- set -eu
1024
- tmp_out="\${PWD}/.session-id.\$\$.tmp"
1025
- trap 'rm -f "\$tmp_out"' EXIT
1026
- sid=\$(bun -e 'try { const j = await new Response(Bun.stdin.stream()).json(); process.stdout.write(String(j.session_id ?? "")) } catch { process.stdout.write("") }')
1027
- case "\$sid" in
1028
- [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ;;
1029
- *) sid=malformed ;;
1030
- esac
1031
- printf '%s\\n' "\$sid" > "\$tmp_out"
1032
- mv "\$tmp_out" "\${PWD}/.session-id"
1033
- trap - EXIT
1034
- `
1035
-
1036
- // Single-quoted heredoc so the body is delivered verbatim — no shell
1037
- // expansion at build time. Runtime expansion of \`$PWD\`, \`$sid\`, etc.
1038
- // is what we want, so the heredoc must NOT expand them during \`docker
1039
- // build\`. POSIX \`<<'EOF'\` (quoted delimiter) is the canonical way to
1040
- // get verbatim heredoc.
1041
- //
1042
- // Script flow:
1043
- // 1. Buffer stdin to a temp file (we need to read it twice: once for
1044
- // session_id extraction, once for the sentinel write).
1045
- // 2. Extract session_id via POSIX sed. Result is matched against the
1046
- // RFC-4122-style UUID regex (8-4-4-4-12 hex with dashes). Anything
1047
- // that doesn't match — empty extraction, embedded escapes, path
1048
- // traversal, missing field — falls through to "malformed".
1049
- // 3. Atomic write: \`mv\` is POSIX-atomic on the same filesystem (we
1050
- // stay inside \`$PWD\` so the temp and final paths share an fs).
1051
- // 4. \`touch .done-<sid>\` AFTER the mv so a polling reader never sees
1052
- // .done existing before sentinel.json — the polling loop watches
1053
- // .done as the readiness signal.
1054
- const TYPECLAW_CC_STOP_HOOK_SCRIPT = `#!/bin/sh
1055
- # typeclaw Stop-hook for Claude Code. Stdin carries the Stop event JSON.
1056
- # Writes per-session sentinel/.done files into \$PWD. Rationale (including
1057
- # the security model, \$PWD semantics, and why bun-not-sed for JSON
1058
- # extraction) lives in src/init/dockerfile.ts.
1059
- set -eu
1060
- tmp_in="\${PWD}/.cc-stop-hook-in.\$\$"
1061
- trap 'rm -f "\$tmp_in"' EXIT
1062
- cat > "\$tmp_in"
1063
- sid=\$(bun -e 'try { const j = await Bun.file(process.argv[1]).json(); process.stdout.write(String(j.session_id ?? "")) } catch { process.stdout.write("") }' "\$tmp_in")
1064
- case "\$sid" in
1065
- [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ;;
1066
- *) sid=malformed ;;
1067
- esac
1068
- mv "\$tmp_in" "\${PWD}/sentinel-\${sid}.json"
1069
- trap - EXIT
1070
- touch "\${PWD}/.done-\${sid}"
1071
- `
1072
-
1073
- // User-level Claude Code settings file; applies to every invocation
1074
- // regardless of cwd. Registers BOTH the SessionStart hook (so the
1075
- // operator can learn the session UUID) and the Stop hook (so the
1076
- // operator can poll for turn-completion). Built via JSON.stringify
1077
- // rather than a string literal so any future shape edit fails the
1078
- // JSON.parse regression test, not the docker build (or worse, the
1079
- // first failed delegation).
1080
- //
1081
- // SessionStart matcher \`startup|resume|clear|compact\`: covers all four
1082
- // session-origin types per the upstream matcher reference. Stop has no
1083
- // matcher support (always fires on every occurrence per the docs), so
1084
- // \`matcher: "*"\` is the canonical "fire on every Stop" form.
1085
- //
1086
- // \`args: []\` is the exec-form trigger per docs.claude.com/en/docs/
1087
- // claude-code/hooks: with \`args\` present, Claude Code runs the command
1088
- // directly via execvp (kernel-handled shebang, no shell tokenization).
1089
- // With \`args\` absent, Claude Code falls back to shell form (\`sh -c
1090
- // "<command>"\`), which works for our absolute-path-no-special-chars
1091
- // case but is fragile to any future path change. Exec form is the
1092
- // canonical robust shape.
1093
- const TYPECLAW_CC_GLOBAL_SETTINGS = JSON.stringify({
1094
- hooks: {
1095
- SessionStart: [
1096
- {
1097
- matcher: 'startup|resume|clear|compact',
1098
- hooks: [{ type: 'command', command: TYPECLAW_CC_SESSION_START_HOOK_PATH, args: [] }],
1099
- },
1100
- ],
1101
- Stop: [
1102
- {
1103
- matcher: '*',
1104
- hooks: [{ type: 'command', command: TYPECLAW_CC_STOP_HOOK_PATH, args: [] }],
1105
- },
1106
- ],
1107
- },
1108
- })
1109
-
677
+ // The pinned native executable must live entirely under /usr, which bwrap binds.
678
+ // Subscription compatibility is qualified by the live release gate, not --version.
1110
679
  function renderClaudeCodeInstallLayer(enabled: boolean): string {
1111
680
  if (!enabled) return ''
1112
- return `# Layer 5.6 (toggle): install Anthropic's Claude Code CLI. Opt-in via
1113
- # typeclaw.json#docker.file.claudeCode. The skill \`typeclaw-claude-code\`
1114
- # documents the auth + usage flow. Pre-seed ~/.claude.json so the first
1115
- # launch skips the TTY-only theme picker; see CLAUDE_CODE_ONBOARDING_SEED
1116
- # above for the rationale and what the seed deliberately does NOT cover.
1117
- # Also pre-write the canonical Stop-hook config and helper script at
1118
- # build time (see TYPECLAW_CC_STOP_HOOK_PATH above) so the operator
1119
- # subagent never has to construct that JSON itself — the historically
1120
- # failure-prone step where wrong-shape configs (\`onStop\`, bare-string
1121
- # values, etc.) would silently disable the done-signal and burn the
1122
- # polling loop's wall-clock budget. The seed write runs LAST in the
1123
- # chain so the final layer state is exactly the seeded config —
1124
- # independent of whether any earlier command (or a future Claude
1125
- # version's \`--version\` smoke test) writes a default \`~/.claude.json\`
1126
- # partway through the layer.
1127
- RUN curl -fsSL https://claude.ai/install.sh | bash \\
1128
- && ln -sf "$HOME/.local/bin/claude" /usr/local/bin/claude \\
1129
- && claude --version > /dev/null \\
1130
- && cat > ${TYPECLAW_CC_SESSION_START_HOOK_PATH} <<'TYPECLAW_CC_SESSION_START_HOOK_EOF'
1131
- ${TYPECLAW_CC_SESSION_START_HOOK_SCRIPT}TYPECLAW_CC_SESSION_START_HOOK_EOF
1132
- RUN cat > ${TYPECLAW_CC_STOP_HOOK_PATH} <<'TYPECLAW_CC_STOP_HOOK_EOF'
1133
- ${TYPECLAW_CC_STOP_HOOK_SCRIPT}TYPECLAW_CC_STOP_HOOK_EOF
1134
- RUN chmod +x ${TYPECLAW_CC_SESSION_START_HOOK_PATH} ${TYPECLAW_CC_STOP_HOOK_PATH} \\
1135
- && mkdir -p "$HOME/.claude" \\
1136
- && printf '%s\\n' '${TYPECLAW_CC_GLOBAL_SETTINGS}' > "$HOME/.claude/settings.json" \\
1137
- && printf '%s\\n' '${CLAUDE_CODE_ONBOARDING_SEED}' > "$HOME/.claude.json"`
681
+ return `# Layer 5.6 (toggle): brokered headless Claude Code.
682
+ RUN curl -fsSL https://claude.ai/install.sh | bash -s -- ${CLAUDE_CODE_VERSION} \\
683
+ && install -D -m 0755 "$(readlink -f "$HOME/.local/bin/claude")" /usr/local/lib/typeclaw-coding-agents/claude/${CLAUDE_CODE_VERSION}/claude \\
684
+ && ln -sf /usr/local/lib/typeclaw-coding-agents/claude/${CLAUDE_CODE_VERSION}/claude /usr/local/bin/claude \\
685
+ && claude --version > /dev/null`
1138
686
  }
1139
687
 
1140
- // Codex CLI's official distribution channel is the npm package
1141
- // \`@openai/codex\` (https://www.npmjs.com/package/@openai/codex). Unlike
1142
- // Claude Code's \`curl | bash\` install, Codex installs cleanly via the same
1143
- // bun-global path agent-browser uses, so we layer it under the existing
1144
- // \`bun install -g\` invariant: cache-mount keyed install, no \$HOME/.local/bin
1145
- // symlink dance, no installer scratch.
1146
- //
1147
- // Hook architecture: Codex CLI ships a hook system with the SAME event names
1148
- // as Claude Code (SessionStart, Stop, PreToolUse, PostToolUse, etc.) and the
1149
- // SAME JSON shape (\`{ session_id, transcript_path, cwd, hook_event_name }\` on
1150
- // stdin). The two CLIs are NOT interoperable — Codex's config file is
1151
- // \`~/.codex/hooks.json\` (or inline \`[hooks]\` in \`config.toml\`), and the trust
1152
- // model differs (Codex prompts for hook trust on first run, gated by
1153
- // \`--dangerously-bypass-hook-trust\`). But the hook script body, the
1154
- // per-session filenames (\`.done-<sid>\`, \`sentinel-<sid>.json\`), the
1155
- // \`.session-id\` fast path, and the \`malformed\` fallback are byte-for-byte
1156
- // reusable. We deliberately use distinct paths (\`typeclaw-cx-*\` instead of
1157
- // \`typeclaw-cc-*\`) and a distinct settings file (\`~/.codex/hooks.json\` vs
1158
- // \`~/.claude/settings.json\`) so an agent with BOTH toggles on doesn't have
1159
- // the two CLIs racing on the same sentinel files. The skill side
1160
- // (\`typeclaw-codex-cli\`) documents which UUID-bearing artifacts belong to
1161
- // which CLI.
1162
- //
1163
- // Onboarding: Codex has NO theme picker, NO telemetry consent dialog, NO
1164
- // terms-of-service prompt — verified against
1165
- // codex-rs/tui/src/onboarding/onboarding_screen.rs in the upstream repo.
1166
- // The TUI's onboarding state machine has exactly three steps: Welcome,
1167
- // Auth, TrustDirectory. We CAN'T pre-seed past Welcome (it's an animation,
1168
- // not a prompt), and we DELIBERATELY don't pre-seed past Auth (the user
1169
- // must paste their OPENAI_API_KEY or run \`codex login\` themselves) or past
1170
- // TrustDirectory (trusting an arbitrary worktree silently widens the trust
1171
- // surface in ways the operator hasn't consented to — exact same reasoning
1172
- // as Claude Code's "don't preseed hasTrustDialogAccepted"). The
1173
- // \`typeclaw-codex-cli\` skill handles all three at runtime via dialog
1174
- // polling, the same shape Claude Code's skill uses for its post-seed
1175
- // modals.
1176
- //
1177
- // Smoke test: \`codex --version\` is supported per codex-rs/cli/src/main.rs
1178
- // (clap \`version\` attribute), so we use it as the build-time install check.
1179
- const TYPECLAW_CX_STOP_HOOK_PATH = '/usr/local/bin/typeclaw-cx-stop-hook'
1180
- const TYPECLAW_CX_SESSION_START_HOOK_PATH = '/usr/local/bin/typeclaw-cx-session-start-hook'
1181
-
1182
- const TYPECLAW_CX_SESSION_START_HOOK_SCRIPT = `#!/bin/sh
1183
- # typeclaw SessionStart-hook for Codex CLI. Stdin carries the SessionStart
1184
- # event JSON. Writes \$PWD/.session-id with the session UUID as a fast-path
1185
- # optimization (the operator falls back to discovering session_id from the
1186
- # first Stop sentinel if .session-id never appears). Rationale lives in
1187
- # src/init/dockerfile.ts.
1188
- set -eu
1189
- tmp_out="\${PWD}/.session-id.\$\$.tmp"
1190
- trap 'rm -f "\$tmp_out"' EXIT
1191
- sid=\$(bun -e 'try { const j = await new Response(Bun.stdin.stream()).json(); process.stdout.write(String(j.session_id ?? "")) } catch { process.stdout.write("") }')
1192
- case "\$sid" in
1193
- [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ;;
1194
- *) sid=malformed ;;
1195
- esac
1196
- printf '%s\\n' "\$sid" > "\$tmp_out"
1197
- mv "\$tmp_out" "\${PWD}/.session-id"
1198
- trap - EXIT
1199
- `
1200
-
1201
- const TYPECLAW_CX_STOP_HOOK_SCRIPT = `#!/bin/sh
1202
- # typeclaw Stop-hook for Codex CLI. Stdin carries the Stop event JSON.
1203
- # Writes per-session sentinel/.done files into \$PWD. Rationale (the
1204
- # security model, \$PWD semantics, and why bun-not-sed for JSON
1205
- # extraction) lives in src/init/dockerfile.ts.
1206
- set -eu
1207
- tmp_in="\${PWD}/.cx-stop-hook-in.\$\$"
1208
- trap 'rm -f "\$tmp_in"' EXIT
1209
- cat > "\$tmp_in"
1210
- sid=\$(bun -e 'try { const j = await Bun.file(process.argv[1]).json(); process.stdout.write(String(j.session_id ?? "")) } catch { process.stdout.write("") }' "\$tmp_in")
1211
- case "\$sid" in
1212
- [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ;;
1213
- *) sid=malformed ;;
1214
- esac
1215
- mv "\$tmp_in" "\${PWD}/sentinel-\${sid}.json"
1216
- trap - EXIT
1217
- touch "\${PWD}/.done-\${sid}"
1218
- `
1219
-
1220
- // Codex CLI's hook config file lives at ~/.codex/hooks.json. The JSON shape
1221
- // mirrors Claude Code's settings.json hooks block exactly — same nesting,
1222
- // same matcher syntax, same exec-form via \`args: []\`. Built via
1223
- // JSON.stringify so a shape edit fails the JSON.parse regression test, not
1224
- // the docker build (or the first failed delegation).
1225
- //
1226
- // SessionStart matcher \`startup|resume\`: Codex documents \`startup\` and
1227
- // \`resume\` as the two SessionStart sources (vs Claude Code's
1228
- // \`startup|resume|clear|compact\` — Codex has no \`/clear\` command and no
1229
- // auto-compaction in the same shape). Claude's broader matcher would not
1230
- // be wrong but would match against events Codex never fires.
1231
- const TYPECLAW_CX_GLOBAL_HOOKS = JSON.stringify({
1232
- hooks: {
1233
- SessionStart: [
1234
- {
1235
- matcher: 'startup|resume',
1236
- hooks: [{ type: 'command', command: TYPECLAW_CX_SESSION_START_HOOK_PATH, args: [] }],
1237
- },
1238
- ],
1239
- Stop: [
1240
- {
1241
- matcher: '*',
1242
- hooks: [{ type: 'command', command: TYPECLAW_CX_STOP_HOOK_PATH, args: [] }],
1243
- },
1244
- ],
1245
- },
1246
- })
688
+ // Keep the JS launcher and native optional dependencies under the sandbox-visible /usr.
1247
689
 
1248
690
  function renderCodexCliInstallLayer(enabled: boolean, buildKit: boolean): string {
1249
691
  if (!enabled) return ''
1250
- return `# Layer 5.7 (toggle): install OpenAI's Codex CLI. Opt-in via
1251
- # typeclaw.json#docker.file.codexCli. The skill \`typeclaw-codex-cli\`
1252
- # documents the auth + usage flow. Codex ships as the npm package
1253
- # \`@openai/codex\`, so we install via \`bun install -g\` reusing the same
1254
- # cache mount agent-browser uses. Hook scripts and ~/.codex/hooks.json
1255
- # are pre-written at build time so the operator subagent never has to
1256
- # construct that JSON itself — same load-bearing reason as the Claude
1257
- # Code layer above.
1258
- RUN ${bunCacheMount(buildKit)}bun install -g @openai/codex \\
1259
- && codex --version > /dev/null \\
1260
- && cat > ${TYPECLAW_CX_SESSION_START_HOOK_PATH} <<'TYPECLAW_CX_SESSION_START_HOOK_EOF'
1261
- ${TYPECLAW_CX_SESSION_START_HOOK_SCRIPT}TYPECLAW_CX_SESSION_START_HOOK_EOF
1262
- RUN cat > ${TYPECLAW_CX_STOP_HOOK_PATH} <<'TYPECLAW_CX_STOP_HOOK_EOF'
1263
- ${TYPECLAW_CX_STOP_HOOK_SCRIPT}TYPECLAW_CX_STOP_HOOK_EOF
1264
- RUN chmod +x ${TYPECLAW_CX_SESSION_START_HOOK_PATH} ${TYPECLAW_CX_STOP_HOOK_PATH} \\
1265
- && mkdir -p "$HOME/.codex" \\
1266
- && printf '%s\\n' '${TYPECLAW_CX_GLOBAL_HOOKS}' > "$HOME/.codex/hooks.json"`
692
+ return `# Layer 5.7 (toggle): brokered headless Codex CLI.
693
+ RUN ${bunCacheMount(buildKit)}BUN_INSTALL=/usr/local/lib/typeclaw-coding-agents/codex BUN_INSTALL_BIN=/usr/local/lib/typeclaw-coding-agents/codex/bin bun install -g @openai/codex@${CODEX_CLI_VERSION} \\
694
+ && printf '%s\\n' '#!/bin/sh' 'exec /usr/local/bin/bun /usr/local/lib/typeclaw-coding-agents/codex/bin/codex "$@"' > /usr/local/bin/codex \\
695
+ && chmod 0755 /usr/local/bin/codex \\
696
+ && codex --version > /dev/null`
1267
697
  }
1268
698
 
1269
699
  // Shared-library runtime deps Chrome for Testing needs to launch on amd64
@@ -1353,6 +783,7 @@ export function buildDockerfile(
1353
783
 
1354
784
  const claudeCodeLayer = renderClaudeCodeInstallLayer(config.claudeCode)
1355
785
  const codexCliLayer = renderCodexCliInstallLayer(config.codexCli, buildKit)
786
+ const omoCliLayer = renderOmoCliInstallLayer(config.omoCli)
1356
787
  const fromAndHeavyLayers =
1357
788
  baseImageVersion !== null
1358
789
  ? renderVersionedHead(
@@ -1362,9 +793,18 @@ export function buildDockerfile(
1362
793
  cloudflaredLayer,
1363
794
  claudeCodeLayer,
1364
795
  codexCliLayer,
796
+ omoCliLayer,
797
+ buildKit,
798
+ )
799
+ : renderInlineHead(
800
+ ghKeyringLayer,
801
+ toggleAptArgs,
802
+ cloudflaredLayer,
803
+ claudeCodeLayer,
804
+ codexCliLayer,
805
+ omoCliLayer,
1365
806
  buildKit,
1366
807
  )
1367
- : renderInlineHead(ghKeyringLayer, toggleAptArgs, cloudflaredLayer, claudeCodeLayer, codexCliLayer, buildKit)
1368
808
 
1369
809
  const header = buildKit ? `${BUILDKIT_HEADER}\n` : ''
1370
810
  return `${header}# AUTOGENERATED by typeclaw — do not edit.
@@ -1416,19 +856,21 @@ function renderVersionedHead(
1416
856
  cloudflaredLayer: string,
1417
857
  claudeCodeLayer: string,
1418
858
  codexCliLayer: string,
859
+ omoCliLayer: string,
1419
860
  buildKit: boolean,
1420
861
  ): string {
1421
862
  const toggleAptLayer = toggleAptArgs.length === 0 ? '' : `${renderToggleAptInstallLayer(toggleAptArgs, buildKit)}\n\n`
1422
863
  const cloudflaredBlock = cloudflaredLayer === '' ? '' : `${cloudflaredLayer}\n\n`
1423
864
  const claudeCodeBlock = claudeCodeLayer === '' ? '' : `${claudeCodeLayer}\n\n`
1424
865
  const codexCliBlock = codexCliLayer === '' ? '' : `${codexCliLayer}\n\n`
866
+ const omoCliBlock = omoCliLayer === '' ? '' : `${omoCliLayer}\n\n`
1425
867
  return `FROM ${GHCR_BASE_IMAGE_REPO}:${baseImageVersion}
1426
868
 
1427
869
  WORKDIR /agent
1428
870
 
1429
871
  ARG TARGETARCH
1430
872
 
1431
- ${ghKeyringLayer}${toggleAptLayer}${cloudflaredBlock}${claudeCodeBlock}${codexCliBlock}${renderEntrypointShimLayer()}
873
+ ${ghKeyringLayer}${toggleAptLayer}${cloudflaredBlock}${claudeCodeBlock}${codexCliBlock}${omoCliBlock}${renderEntrypointShimLayer()}
1432
874
  ${renderGitAskPassLayer()}
1433
875
 
1434
876
  ${LAYER_TRANSFORMERS_INSTALL}
@@ -1446,12 +888,14 @@ function renderInlineHead(
1446
888
  cloudflaredLayer: string,
1447
889
  claudeCodeLayer: string,
1448
890
  codexCliLayer: string,
891
+ omoCliLayer: string,
1449
892
  buildKit: boolean,
1450
893
  ): string {
1451
894
  const baselineAndToggleArgs = [...BASELINE_APT_PACKAGES, ...toggleAptArgs]
1452
895
  const cloudflaredBlock = cloudflaredLayer === '' ? '' : `${cloudflaredLayer}\n\n`
1453
896
  const claudeCodeBlock = claudeCodeLayer === '' ? '' : `${claudeCodeLayer}\n\n`
1454
897
  const codexCliBlock = codexCliLayer === '' ? '' : `${codexCliLayer}\n\n`
898
+ const omoCliBlock = omoCliLayer === '' ? '' : `${omoCliLayer}\n\n`
1455
899
  return `${FROM_AND_WORKDIR}
1456
900
 
1457
901
  # Layers are ordered most-stable first to maximize Docker layer cache hits on
@@ -1492,7 +936,7 @@ ${LAYER_4_5_AGENT_BROWSER_HEADED_WRAPPER}
1492
936
 
1493
937
  ${renderChromeForTestingLayer()}
1494
938
 
1495
- ${cloudflaredBlock}${claudeCodeBlock}${codexCliBlock}${renderEntrypointShimLayer()}
939
+ ${cloudflaredBlock}${claudeCodeBlock}${codexCliBlock}${omoCliBlock}${renderEntrypointShimLayer()}
1496
940
  ${renderGitAskPassLayer()}
1497
941
 
1498
942
  ${LAYER_TRANSFORMERS_INSTALL}
@@ -1601,8 +1045,10 @@ const bunCacheMount = (buildKit: boolean): string => (buildKit ? BUN_CACHE_MOUNT
1601
1045
  // resolving to Bun 1.4.0 the day it shipped — that would put an unvalidated
1602
1046
  // runtime in every container while CI still tested 1.3.14. Bump this in the
1603
1047
  // same change as the `bun-version:` pins in .github/workflows/*.yml so the
1604
- // host-stage checks and the container-stage runtime never disagree.
1605
- export const BUN_BASE_IMAGE = 'oven/bun:1.4.0-slim'
1048
+ // host-stage checks and the container-stage runtime never disagree. The
1049
+ // version itself lives in `TESTED_BUN_VERSION`, which also drives the host-Bun
1050
+ // warning in `typeclaw doctor` and the host daemon log.
1051
+ export const BUN_BASE_IMAGE = `oven/bun:${TESTED_BUN_VERSION}-slim`
1606
1052
 
1607
1053
  const FROM_AND_WORKDIR = `FROM ${BUN_BASE_IMAGE}
1608
1054
 
@@ -1790,6 +1236,24 @@ RUN if [ "$TARGETARCH" != "arm64" ]; then \\
1790
1236
  agent-browser install; \\
1791
1237
  fi`
1792
1238
 
1239
+ function renderOmoCliInstallLayer(enabled: boolean): string {
1240
+ if (!enabled) return ''
1241
+ const root = `/usr/local/lib/typeclaw-coding-agents/omo/${OMO_CLI_VERSION}`
1242
+ return `# Pinned OmO Native: executable and symlink target stay inside /usr.
1243
+ RUN case "\${TARGETARCH:-$(uname -m)}" in \\
1244
+ arm64|aarch64) asset=omo-linux-arm64; sha=87dc0f001e5821599bda889d55b10655136623ba5b74a804bae0edcdc4ce50b2 ;; \\
1245
+ amd64|x86_64) asset=omo-linux-x64-baseline; sha=df4ca3223fe600d3b497f9fbbe759052a11ae9300a9cb965834a8942d5747fc7 ;; \\
1246
+ *) echo "Unsupported OmO architecture" >&2; exit 1 ;; \\
1247
+ esac \\
1248
+ && mkdir -p ${root} \\
1249
+ && curl -fsSL "https://github.com/code-yeongyu/oh-my-openagent/releases/download/v${OMO_CLI_VERSION}/\${asset}" -o ${root}/omo \\
1250
+ && echo "\${sha} ${root}/omo" | sha256sum -c - \\
1251
+ && chmod 0755 ${root}/omo \\
1252
+ && ln -sf ${root}/omo /usr/local/bin/omo \\
1253
+ && HOME=/tmp/typeclaw-omo-smoke PI_OFFLINE=1 PI_SKIP_VERSION_CHECK=1 PI_TELEMETRY=0 DO_NOT_TRACK=1 OMO_SEND_ANONYMOUS_TELEMETRY=0 omo --version \\
1254
+ && rm -rf /tmp/typeclaw-omo-smoke`
1255
+ }
1256
+
1793
1257
  function defaultConfig(): DockerfileConfig {
1794
1258
  return {
1795
1259
  ffmpeg: false,
@@ -1801,6 +1265,7 @@ function defaultConfig(): DockerfileConfig {
1801
1265
  xvfb: true,
1802
1266
  claudeCode: false,
1803
1267
  codexCli: false,
1268
+ omoCli: false,
1804
1269
  append: [],
1805
1270
  }
1806
1271
  }