@temmo/cli 0.0.0-stage → 0.19.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 (445) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.claude-plugin/plugin.json +16 -0
  3. package/.codex-plugin/plugin.json +30 -0
  4. package/.cursor-plugin/plugin.json +22 -0
  5. package/.mcp.json +18 -0
  6. package/LICENSE +202 -0
  7. package/README.md +82 -2
  8. package/THIRD_PARTY_NOTICES +32 -0
  9. package/commands/afk.md +17 -0
  10. package/deploy/build-ui.mjs +65 -0
  11. package/deploy/claude/README.md +16 -0
  12. package/deploy/claude/auto-mode.json +31 -0
  13. package/deploy/postgres/compose.yaml +26 -0
  14. package/deploy/temmo-runner.service +24 -0
  15. package/deploy/verify-ui.mjs +15 -0
  16. package/harness-core/README.md +27 -0
  17. package/harness-core/bin/harness.mjs +17 -0
  18. package/harness-core/package.json +10 -0
  19. package/harness-core/stage.mjs +108 -0
  20. package/harness-core/stages/commit.md +7 -0
  21. package/harness-core/stages/pr.md +7 -0
  22. package/harness-core/stages/push.md +7 -0
  23. package/hooks/codex-hooks.json +14 -0
  24. package/hooks/cursor-hooks.json +17 -0
  25. package/hooks/hooks.json +27 -0
  26. package/lib/acp/permission.js +72 -0
  27. package/lib/acp/sessionConfig.js +109 -0
  28. package/lib/activity.js +244 -0
  29. package/lib/agent-guard.js +72 -0
  30. package/lib/agents-route.js +55 -0
  31. package/lib/agents.js +213 -0
  32. package/lib/agui.js +255 -0
  33. package/lib/alerts.js +36 -0
  34. package/lib/analyze-otlp.js +46 -0
  35. package/lib/analyze-run-code.js +397 -0
  36. package/lib/analyze-sources.js +372 -0
  37. package/lib/approval-card.js +54 -0
  38. package/lib/approval-cli.js +53 -0
  39. package/lib/approval-request.js +81 -0
  40. package/lib/approval-signer.js +48 -0
  41. package/lib/approvals.js +295 -0
  42. package/lib/attachment-cache.js +236 -0
  43. package/lib/attachment.js +63 -0
  44. package/lib/blocked.js +20 -0
  45. package/lib/build-review.js +90 -0
  46. package/lib/builder/cli.js +90 -0
  47. package/lib/builder/policy.js +176 -0
  48. package/lib/builder/recover.js +189 -0
  49. package/lib/builder/run.js +240 -0
  50. package/lib/builder/settle.js +198 -0
  51. package/lib/builder/stage.js +240 -0
  52. package/lib/builder/state.js +73 -0
  53. package/lib/builder/supervisor.js +289 -0
  54. package/lib/builder-clean.js +223 -0
  55. package/lib/builder-code.cjs +67 -0
  56. package/lib/builder.js +9 -0
  57. package/lib/bus-postgres.js +281 -0
  58. package/lib/bus.js +349 -0
  59. package/lib/catalog/author.js +278 -0
  60. package/lib/catalog/dot.js +426 -0
  61. package/lib/catalog/pattern-model.js +193 -0
  62. package/lib/catalog/patterns.js +324 -0
  63. package/lib/catalog/projects.js +83 -0
  64. package/lib/catalog/records.js +2 -0
  65. package/lib/catalog/roster.js +70 -0
  66. package/lib/catalog/team-files.js +49 -0
  67. package/lib/catalog/teams.js +109 -0
  68. package/lib/claude-socket.js +333 -0
  69. package/lib/cli.js +741 -0
  70. package/lib/code-mode.js +45 -0
  71. package/lib/code-read-policy.yaml +9 -0
  72. package/lib/code-run.js +461 -0
  73. package/lib/codex-compact.js +141 -0
  74. package/lib/compaction.js +21 -0
  75. package/lib/config.js +424 -0
  76. package/lib/cursor-trace.js +248 -0
  77. package/lib/deep-link.js +20 -0
  78. package/lib/deliver-push.js +120 -0
  79. package/lib/delivery.js +28 -0
  80. package/lib/deploy-tree.js +227 -0
  81. package/lib/durable.js +404 -0
  82. package/lib/factory-tick.js +32 -0
  83. package/lib/family.js +63 -0
  84. package/lib/fetch-origin.js +53 -0
  85. package/lib/format.js +133 -0
  86. package/lib/harness-surface-cli.js +153 -0
  87. package/lib/harness-surface.js +486 -0
  88. package/lib/harness.js +271 -0
  89. package/lib/hook.mjs +291 -0
  90. package/lib/idle.js +40 -0
  91. package/lib/install-cursor.js +115 -0
  92. package/lib/install-opencode.js +105 -0
  93. package/lib/job.js +82 -0
  94. package/lib/land-cli.js +319 -0
  95. package/lib/land-member.js +64 -0
  96. package/lib/land.js +320 -0
  97. package/lib/lessons.js +223 -0
  98. package/lib/limit-alert.js +423 -0
  99. package/lib/limits.js +284 -0
  100. package/lib/machine-prompt.js +19 -0
  101. package/lib/merge-sweep.js +149 -0
  102. package/lib/messaging.js +1002 -0
  103. package/lib/mission-cli.js +103 -0
  104. package/lib/mission.js +241 -0
  105. package/lib/mode.js +215 -0
  106. package/lib/models.js +114 -0
  107. package/lib/names.js +86 -0
  108. package/lib/opencode-api.js +57 -0
  109. package/lib/opencode-plugin.mjs +313 -0
  110. package/lib/operator-token.js +78 -0
  111. package/lib/operator.js +187 -0
  112. package/lib/pad-activity.js +143 -0
  113. package/lib/pad-fresh.js +44 -0
  114. package/lib/pad.js +198 -0
  115. package/lib/pattern-cli.js +120 -0
  116. package/lib/pattern-compiler.js +68 -0
  117. package/lib/pattern-runs.js +795 -0
  118. package/lib/pattern-stall.js +58 -0
  119. package/lib/pattern-tick.js +45 -0
  120. package/lib/pattern-workflow.js +69 -0
  121. package/lib/pi-extension.mjs +98 -0
  122. package/lib/pi.js +57 -0
  123. package/lib/plugin-copy.js +76 -0
  124. package/lib/pm-review.js +32 -0
  125. package/lib/pm-workspace.js +87 -0
  126. package/lib/postgres.js +115 -0
  127. package/lib/pr-card.js +34 -0
  128. package/lib/probe.js +295 -0
  129. package/lib/process.js +67 -0
  130. package/lib/project-pause.js +23 -0
  131. package/lib/prune.js +793 -0
  132. package/lib/questions.js +250 -0
  133. package/lib/receipts.js +63 -0
  134. package/lib/reflect.js +962 -0
  135. package/lib/rename-migration.js +118 -0
  136. package/lib/run-terminal.js +437 -0
  137. package/lib/runner-request.js +33 -0
  138. package/lib/sandbox-app.js +120 -0
  139. package/lib/sandbox-claims.js +258 -0
  140. package/lib/sandbox-cli.js +188 -0
  141. package/lib/sandbox-hosts-cli.js +68 -0
  142. package/lib/sandbox-hosts.js +94 -0
  143. package/lib/sandbox-pr.js +102 -0
  144. package/lib/sandbox-proposal.js +367 -0
  145. package/lib/sandbox-tools.js +143 -0
  146. package/lib/sandbox.js +501 -0
  147. package/lib/schedule-session.js +68 -0
  148. package/lib/session-activity.js +67 -0
  149. package/lib/session-events.js +94 -0
  150. package/lib/sessions/control.js +244 -0
  151. package/lib/sessions/git-refs.js +265 -0
  152. package/lib/sessions/launch.js +359 -0
  153. package/lib/sessions/registry.js +450 -0
  154. package/lib/sessions/scope.js +111 -0
  155. package/lib/setup.js +377 -0
  156. package/lib/signed-approval.js +225 -0
  157. package/lib/slash.js +167 -0
  158. package/lib/spawn-cli.js +45 -0
  159. package/lib/spawn.js +107 -0
  160. package/lib/start-limit.js +58 -0
  161. package/lib/state.js +24 -0
  162. package/lib/stop.js +308 -0
  163. package/lib/store-read.js +62 -0
  164. package/lib/store.js +252 -0
  165. package/lib/subagent-guard.js +240 -0
  166. package/lib/surfaces/channel-post.js +43 -0
  167. package/lib/surfaces/instructions.js +15 -0
  168. package/lib/surfaces/mcp-reload.js +144 -0
  169. package/lib/surfaces/ops.js +629 -0
  170. package/lib/surfaces/render-mcp.js +33 -0
  171. package/lib/surfaces/run-terminal-ops.js +40 -0
  172. package/lib/surfaces/sandbox-ops.js +36 -0
  173. package/lib/surfaces/schema.js +7 -0
  174. package/lib/surfaces/task-view.js +90 -0
  175. package/lib/surfaces/types.js +4 -0
  176. package/lib/task-cli.js +274 -0
  177. package/lib/task-order.js +34 -0
  178. package/lib/task-order.mjs +2 -0
  179. package/lib/task-route.js +125 -0
  180. package/lib/tasks.js +631 -0
  181. package/lib/team-permission.js +34 -0
  182. package/lib/team-templates/blitz/team.dot +9 -0
  183. package/lib/team-templates/factory/team.dot +26 -0
  184. package/lib/team-templates/feature/team.dot +14 -0
  185. package/lib/team-templates/fix-and-review/team.dot +12 -0
  186. package/lib/team-templates/product/team.dot +16 -0
  187. package/lib/team-templates/release/team.dot +7 -0
  188. package/lib/team-templates/review/team.dot +6 -0
  189. package/lib/terminal-draft.js +42 -0
  190. package/lib/thread-branch.js +82 -0
  191. package/lib/thread-channel-store.js +181 -0
  192. package/lib/thread-channels.js +116 -0
  193. package/lib/thread-listening.js +20 -0
  194. package/lib/thread-routes.js +91 -0
  195. package/lib/threads.js +441 -0
  196. package/lib/tool-api.js +33 -0
  197. package/lib/transcript.js +98 -0
  198. package/lib/ui-build-output.js +19 -0
  199. package/lib/ui-capabilities.js +90 -0
  200. package/lib/usage.js +182 -0
  201. package/lib/vendor/mcp-sdk.d.mts +4 -0
  202. package/lib/vendor/mcp-sdk.mjs +17046 -0
  203. package/lib/waiter.js +127 -0
  204. package/lib/workflows.js +546 -0
  205. package/lib/worktree-setup.js +86 -0
  206. package/package.json +110 -4
  207. package/runner/adapters/claude.js +465 -0
  208. package/runner/adapters/cli-sandbox.js +277 -0
  209. package/runner/adapters/codex.js +675 -0
  210. package/runner/adapters/cursor.mjs +937 -0
  211. package/runner/adapters/fake.js +119 -0
  212. package/runner/adapters/opencode-sandbox.js +370 -0
  213. package/runner/adapters/opencode.js +486 -0
  214. package/runner/adapters/pi-sandbox.js +134 -0
  215. package/runner/adapters/pi.js +364 -0
  216. package/runner/client.js +40 -0
  217. package/runner/contract.js +129 -0
  218. package/runner/control.js +178 -0
  219. package/runner/delivery.js +184 -0
  220. package/runner/factory-tick.mjs +10 -0
  221. package/runner/lock.js +41 -0
  222. package/runner/main.mjs +118 -0
  223. package/runner/pattern-tick.mjs +16 -0
  224. package/runner/publish.js +113 -0
  225. package/runner/runner.js +2612 -0
  226. package/runner/sandbox-run.mjs +239 -0
  227. package/runner/schedules.js +294 -0
  228. package/runner/task-wake.js +59 -0
  229. package/scripts/ai-collab +3 -0
  230. package/scripts/ai-collab-bus.mjs +4 -0
  231. package/scripts/ai-collab-code-mcp.mjs +3 -0
  232. package/scripts/ai-collab-hook +3 -0
  233. package/scripts/ai-collab-hook.mjs +3 -0
  234. package/scripts/ai-collab-mcp-tools.mjs +2 -0
  235. package/scripts/ai-collab-mcp.mjs +3 -0
  236. package/scripts/ai-collab.mjs +3 -0
  237. package/scripts/install-cursor.mjs +11 -0
  238. package/scripts/install-opencode.mjs +10 -0
  239. package/scripts/temmo +3 -0
  240. package/scripts/temmo-bus.mjs +151 -0
  241. package/scripts/temmo-code-mcp.mjs +63 -0
  242. package/scripts/temmo-hook +3 -0
  243. package/scripts/temmo-hook.mjs +201 -0
  244. package/scripts/temmo-mcp-tools.mjs +22 -0
  245. package/scripts/temmo-mcp.mjs +27 -0
  246. package/scripts/temmo.mjs +4 -0
  247. package/skills/antislop/SKILL.md +701 -0
  248. package/skills/antislop/VERSION +1 -0
  249. package/skills/antislop-code/SKILL.md +128 -0
  250. package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
  251. package/skills/antislop-human/SKILL.md +204 -0
  252. package/skills/antislop-human/contrast-check.py +168 -0
  253. package/skills/antislop-human/contrast-mcp.py +125 -0
  254. package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
  255. package/skills/antislop-human/references/WCAG.md +127 -0
  256. package/skills/antislop-layoutmobile/SKILL.md +170 -0
  257. package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
  258. package/skills/antislop-ui/SKILL.md +351 -0
  259. package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
  260. package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
  261. package/skills/harness-surface/SKILL.md +42 -0
  262. package/skills/land/SKILL.md +32 -0
  263. package/skills/memory-file/SKILL.md +39 -0
  264. package/skills/temmo/SKILL.md +101 -0
  265. package/skills/temmo/references/role-programs.md +47 -0
  266. package/skills/ui-sdk/SKILL.md +56 -0
  267. package/skills/ui-sdk/references/agent-ready.md +136 -0
  268. package/skills/ui-sdk/references/build-interface.md +187 -0
  269. package/skills/ui-sdk/references/create-component.md +88 -0
  270. package/skills/ui-sdk/references/patterns.md +246 -0
  271. package/skills/ui-sdk/references/styles.md +66 -0
  272. package/skills/ui-sdk/references/testing.md +172 -0
  273. package/skills/ui-sdk/references/web-components.md +78 -0
  274. package/tools/screen-state.mjs +119 -0
  275. package/tools/smoke-ui.mjs +540 -0
  276. package/web/app/activity.jsx +251 -0
  277. package/web/app/agent-mark.tsx +43 -0
  278. package/web/app/alert-level.jsx +16 -0
  279. package/web/app/api/[action]/route.js +8 -0
  280. package/web/app/api/auth/[step]/route.js +12 -0
  281. package/web/app/api/events/route.js +8 -0
  282. package/web/app/api/file/[name]/route.js +8 -0
  283. package/web/app/api/land/route.js +12 -0
  284. package/web/app/api/lessons/route.js +8 -0
  285. package/web/app/api/push/key/route.js +8 -0
  286. package/web/app/api/push/subscribe/route.js +12 -0
  287. package/web/app/api/push/test/route.js +8 -0
  288. package/web/app/api/refs/route.js +8 -0
  289. package/web/app/api/review-diff/route.js +8 -0
  290. package/web/app/api/schedules/route.js +8 -0
  291. package/web/app/api/thread-diff/route.js +8 -0
  292. package/web/app/api/version/route.js +6 -0
  293. package/web/app/cards.jsx +189 -0
  294. package/web/app/chat-api.js +82 -0
  295. package/web/app/chat-composer.jsx +313 -0
  296. package/web/app/chat-console.jsx +691 -0
  297. package/web/app/chat-image.tsx +61 -0
  298. package/web/app/chat-message.jsx +122 -0
  299. package/web/app/chat-shared.jsx +59 -0
  300. package/web/app/chat-sidebar.jsx +25 -0
  301. package/web/app/chat-stream.js +127 -0
  302. package/web/app/chat.jsx +31 -0
  303. package/web/app/compactions.jsx +57 -0
  304. package/web/app/composer-actions.tsx +87 -0
  305. package/web/app/decisions.jsx +53 -0
  306. package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
  307. package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
  308. package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
  309. package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  310. package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  311. package/web/app/globals.css +199 -0
  312. package/web/app/home.jsx +246 -0
  313. package/web/app/icon.svg +1 -0
  314. package/web/app/land-panel.jsx +63 -0
  315. package/web/app/land-reviews.jsx +20 -0
  316. package/web/app/layout.jsx +17 -0
  317. package/web/app/lessons.tsx +76 -0
  318. package/web/app/logo.tsx +13 -0
  319. package/web/app/logos.jsx +16 -0
  320. package/web/app/manifest.js +8 -0
  321. package/web/app/mode-menu.tsx +46 -0
  322. package/web/app/new-session.jsx +275 -0
  323. package/web/app/notify.jsx +180 -0
  324. package/web/app/outcomes.tsx +94 -0
  325. package/web/app/page.jsx +9 -0
  326. package/web/app/pattern-graph.jsx +75 -0
  327. package/web/app/patterns-page.jsx +293 -0
  328. package/web/app/phone-nav.tsx +36 -0
  329. package/web/app/progress-feed.tsx +33 -0
  330. package/web/app/providers.tsx +27 -0
  331. package/web/app/quote.jsx +15 -0
  332. package/web/app/run-card.tsx +200 -0
  333. package/web/app/run-requests.tsx +148 -0
  334. package/web/app/scheduled.jsx +105 -0
  335. package/web/app/session-panel.tsx +174 -0
  336. package/web/app/session-toolbar.tsx +180 -0
  337. package/web/app/shadcn.css +638 -0
  338. package/web/app/shipped.jsx +49 -0
  339. package/web/app/subagent-runs.jsx +31 -0
  340. package/web/app/task-graph.jsx +67 -0
  341. package/web/app/tasks-strip.tsx +36 -0
  342. package/web/app/tasks.jsx +375 -0
  343. package/web/app/team-author.jsx +145 -0
  344. package/web/app/team-editor.jsx +88 -0
  345. package/web/app/thread-agents.tsx +32 -0
  346. package/web/app/thread-place.tsx +9 -0
  347. package/web/app/thread-sessions.tsx +149 -0
  348. package/web/app/thread-sidebar.tsx +418 -0
  349. package/web/app/thread-switcher.tsx +27 -0
  350. package/web/app/tool-diff.jsx +94 -0
  351. package/web/components/a2ui/controls.jsx +36 -0
  352. package/web/components/a2ui/option-picker.jsx +23 -0
  353. package/web/components/a2ui/script.tsx +121 -0
  354. package/web/components/a2ui/surface.jsx +81 -0
  355. package/web/components/chat/thread.jsx +50 -0
  356. package/web/components/script-text.tsx +42 -0
  357. package/web/components/ui/avatar.jsx +115 -0
  358. package/web/components/ui/badge.jsx +47 -0
  359. package/web/components/ui/button.jsx +63 -0
  360. package/web/components/ui/chat-container.jsx +52 -0
  361. package/web/components/ui/choice-list.tsx +72 -0
  362. package/web/components/ui/code-block.jsx +60 -0
  363. package/web/components/ui/copy-button.tsx +41 -0
  364. package/web/components/ui/dropdown-menu.jsx +257 -0
  365. package/web/components/ui/markdown.jsx +84 -0
  366. package/web/components/ui/message.jsx +28 -0
  367. package/web/components/ui/popover.jsx +33 -0
  368. package/web/components/ui/scroll-button.jsx +34 -0
  369. package/web/components/ui/select.jsx +189 -0
  370. package/web/components/ui/sheet.jsx +152 -0
  371. package/web/components/ui/sonner.jsx +10 -0
  372. package/web/components/ui/tabs.jsx +88 -0
  373. package/web/components/ui/textarea.jsx +20 -0
  374. package/web/components/ui/tooltip.jsx +56 -0
  375. package/web/components.json +24 -0
  376. package/web/instrumentation.js +8 -0
  377. package/web/lib/a2ui-catalog.js +34 -0
  378. package/web/lib/a2ui-pr.js +76 -0
  379. package/web/lib/a2ui-run-catalog.js +18 -0
  380. package/web/lib/a2ui-run.js +93 -0
  381. package/web/lib/a2ui.js +262 -0
  382. package/web/lib/activity-rows.js +275 -0
  383. package/web/lib/agent-detail.js +5 -0
  384. package/web/lib/alert-level.js +44 -0
  385. package/web/lib/approval-mode.js +22 -0
  386. package/web/lib/chat-turns.js +174 -0
  387. package/web/lib/child-subagents.js +16 -0
  388. package/web/lib/compaction-view.js +48 -0
  389. package/web/lib/composer-actions.js +40 -0
  390. package/web/lib/context-view.js +57 -0
  391. package/web/lib/fuzzy.js +26 -0
  392. package/web/lib/highlight.js +44 -0
  393. package/web/lib/lessons-view.js +23 -0
  394. package/web/lib/mentions.js +16 -0
  395. package/web/lib/message-routing.js +105 -0
  396. package/web/lib/new-session.js +85 -0
  397. package/web/lib/operator-messages.js +28 -0
  398. package/web/lib/pattern-graph.js +165 -0
  399. package/web/lib/pattern-view.js +33 -0
  400. package/web/lib/pending-summary.js +18 -0
  401. package/web/lib/permission-modes.js +30 -0
  402. package/web/lib/project-feed.js +107 -0
  403. package/web/lib/quote.js +7 -0
  404. package/web/lib/reply-quote.js +31 -0
  405. package/web/lib/scheduled.js +79 -0
  406. package/web/lib/selection.js +110 -0
  407. package/web/lib/send-confirmation.js +22 -0
  408. package/web/lib/session-dead.js +10 -0
  409. package/web/lib/session-state.js +132 -0
  410. package/web/lib/sidebar.js +15 -0
  411. package/web/lib/slash-commands.js +164 -0
  412. package/web/lib/start-default.js +35 -0
  413. package/web/lib/start-mode.js +35 -0
  414. package/web/lib/stream-views.js +49 -0
  415. package/web/lib/subagent-state.js +20 -0
  416. package/web/lib/task-board.js +54 -0
  417. package/web/lib/task-graph.js +183 -0
  418. package/web/lib/task-tags.js +41 -0
  419. package/web/lib/team-editor.js +10 -0
  420. package/web/lib/thread-groups.js +86 -0
  421. package/web/lib/threads.js +28 -0
  422. package/web/lib/tool-diff.js +273 -0
  423. package/web/lib/ui-events.js +58 -0
  424. package/web/lib/utils.js +5 -0
  425. package/web/lib/view-memory.js +25 -0
  426. package/web/next.config.mjs +37 -0
  427. package/web/postcss.config.mjs +1 -0
  428. package/web/proxy.js +25 -0
  429. package/web/public/sw.js +39 -0
  430. package/web/server/auth.js +178 -0
  431. package/web/server/dispatch.js +293 -0
  432. package/web/server/history.js +56 -0
  433. package/web/server/hosted.js +58 -0
  434. package/web/server/hub.js +126 -0
  435. package/web/server/instance.js +5 -0
  436. package/web/server/land-reviews.js +64 -0
  437. package/web/server/push.js +148 -0
  438. package/web/server/run-terminal.js +79 -0
  439. package/web/server/schedules.js +38 -0
  440. package/web/server/shipped.js +51 -0
  441. package/web/server/task-board.js +71 -0
  442. package/web/server/threads.js +209 -0
  443. package/web/server/ui.js +2937 -0
  444. package/web/tsconfig.base.json +16 -0
  445. package/web/tsconfig.json +9 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * A build review packet: what a builder submitted, the host check's verdict, and the operator's decision on it.
3
+ * The packet names the submitted commit, so a re-run that moves the branch makes it stale and its decision worthless.
4
+ * Everything here is plain data plus one git read; the store (lib/tasks.ts) validates and persists it.
5
+ */
6
+ import { execFileSync } from "node:child_process";
7
+ /** A full Git object name: SHA-1 (40 hex) or SHA-256 (64 hex). */
8
+ export const COMMIT_ID = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
9
+ /** A branch name safe to hand to git without a shell or a leading option. */
10
+ export const BRANCH_NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
11
+ /** Per-file counts in a packet: at most this many, with the rest counted. The full diff is a link, not the packet. */
12
+ export const REVIEW_FILES_MAX = 12;
13
+ export const REVIEW_PATH_MAX = 200;
14
+ // The board asks about every review card on each push; tips are read at most once per this window per checkout.
15
+ const TIP_TTL_MS = 2000;
16
+ const tipCache = new Map();
17
+ /** Every local branch of `root` with its tip commit; {} when the checkout or git is unavailable. */
18
+ function branchTips(root, ttlMs) {
19
+ const hit = tipCache.get(root);
20
+ if (hit && Date.now() - hit.at < ttlMs)
21
+ return hit.value;
22
+ let value = {};
23
+ try {
24
+ const out = execFileSync("git", ["for-each-ref", "--format=%(refname:short) %(objectname)", "refs/heads"], {
25
+ cwd: root, encoding: "utf8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"],
26
+ });
27
+ for (const line of out.split("\n")) {
28
+ const at = line.lastIndexOf(" ");
29
+ if (at > 0)
30
+ value[line.slice(0, at).trim()] = line.slice(at + 1).trim();
31
+ }
32
+ }
33
+ catch { /* an unreadable checkout makes every packet stale */ }
34
+ if (tipCache.size > 32)
35
+ tipCache.clear();
36
+ tipCache.set(root, { at: Date.now(), value });
37
+ return value;
38
+ }
39
+ /** Forgets a checkout's cached tips, so a decision straight after a commit is judged against the live branch. */
40
+ export function forgetBranchTips(root) {
41
+ tipCache.delete(root);
42
+ }
43
+ /**
44
+ * Whether the branch in `root` still points at the submitted commit. A missing branch and an unavailable checkout
45
+ * read as stale too: the reviewer would otherwise judge a commit the build no longer is. `ttlMs` lets the board reuse
46
+ * a recent read; a decision passes 0 so it never acts on a cached tip.
47
+ */
48
+ export function reviewIsCurrent(root, review, { ttlMs = 0 } = {}) {
49
+ if (!root || typeof review?.branch !== "string" || !BRANCH_NAME.test(review.branch) || typeof review.commit !== "string")
50
+ return false;
51
+ return branchTips(root, ttlMs)[review.branch] === review.commit;
52
+ }
53
+ /**
54
+ * The phone-sized change summary of `git diff --numstat` output: totals plus up to REVIEW_FILES_MAX per-file counts.
55
+ * A binary file prints "-" for both counts, so it counts as a changed file with no lines.
56
+ */
57
+ export function changeSummary(numstat) {
58
+ const files = [];
59
+ let insertions = 0;
60
+ let deletions = 0;
61
+ let more = 0;
62
+ for (const line of String(numstat ?? "").split("\n")) {
63
+ if (!line.trim())
64
+ continue;
65
+ const [plus, minus, ...rest] = line.split("\t");
66
+ const path = rest.join("\t");
67
+ if (!path)
68
+ continue;
69
+ const added = plus === "-" ? 0 : Number(plus) || 0;
70
+ const removed = minus === "-" ? 0 : Number(minus) || 0;
71
+ insertions += added;
72
+ deletions += removed;
73
+ if (files.length < REVIEW_FILES_MAX)
74
+ files.push({ path: path.slice(0, REVIEW_PATH_MAX), insertions: added, deletions: removed });
75
+ else
76
+ more += 1;
77
+ }
78
+ return { files, insertions, deletions, more };
79
+ }
80
+ /** A packet's age in the largest whole unit, for the card line: "12s", "3m", "2h", "1d". */
81
+ export function reviewAge(at, now = Date.now()) {
82
+ const seconds = Math.max(0, Math.floor((now - (Number.isFinite(at) ? at : now)) / 1000));
83
+ if (seconds < 60)
84
+ return `${seconds}s`;
85
+ if (seconds < 3600)
86
+ return `${Math.floor(seconds / 60)}m`;
87
+ if (seconds < 86_400)
88
+ return `${Math.floor(seconds / 3600)}h`;
89
+ return `${Math.floor(seconds / 86_400)}d`;
90
+ }
@@ -0,0 +1,90 @@
1
+ // `temmo builder ...`: start, run, list, stop and clean.
2
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { stateDir } from "../config.js";
5
+ import { cleanBuilders } from "../builder-clean.js";
6
+ import { BUILDER_HARNESSES, FINAL_PHASES, LIVE_STATES, builderPaths, readState } from "./state.js";
7
+ import { startBuilder, runBuilder, stopBuilder, unitState } from "./supervisor.js";
8
+ const USAGE = {
9
+ start: "usage: builder start --task <id> [--harness cursor|codex|claude|opencode] [--model M] --brief <file> [--branch B] [--run ID]",
10
+ run: "usage: builder run <id>",
11
+ list: "usage: builder list [--all]",
12
+ stop: "usage: builder stop <id>",
13
+ clean: "usage: builder clean",
14
+ };
15
+ export async function builder([sub, ...rest], { env, cfg, out, err }) {
16
+ const fail = (key) => { err.write(`temmo: ${USAGE[key]}\n`); return 1; };
17
+ try {
18
+ if (sub === "start") {
19
+ const flags = parseStart(rest);
20
+ if (!flags?.task || !flags.brief || (flags.harness !== undefined && !BUILDER_HARNESSES.includes(flags.harness)))
21
+ return fail("start");
22
+ const result = await startBuilder(flags, { env, cfg, readBrief: () => readFileSync(flags.brief, "utf8") });
23
+ out.write([result.session ?? result.unit, result.task, result.sandbox, result.worktree, result.branch].join("\t") + "\n");
24
+ return 0;
25
+ }
26
+ if (sub === "run")
27
+ return rest.length === 1 ? await runBuilder(rest[0], { env, cfg, out, err }) : fail("run");
28
+ if (sub === "list")
29
+ return await listBuilders(rest, { env, out, fail });
30
+ if (sub === "stop")
31
+ return rest.length === 1 ? await stopBuilder(rest[0], { env, out, err }) : fail("stop");
32
+ if (sub === "clean") {
33
+ if (rest.length !== 0)
34
+ return fail("clean");
35
+ for (const id of await cleanBuilders(env))
36
+ out.write(`${id}\n`);
37
+ return 0;
38
+ }
39
+ }
40
+ catch (error) {
41
+ err.write(`temmo: builder ${sub}: ${error.message}\n`);
42
+ return 1;
43
+ }
44
+ err.write(`temmo: ${Object.values(USAGE).join("\n ")}\n`);
45
+ return 1;
46
+ }
47
+ function parseStart(argv) {
48
+ const spec = ["--task", "--harness", "--model", "--brief", "--branch", "--run"];
49
+ const flags = {};
50
+ for (let i = 0; i < argv.length; i += 1) {
51
+ const at = argv[i].indexOf("=");
52
+ const [key, value] = at > 0 ? [argv[i].slice(0, at), argv[i].slice(at + 1)] : [argv[i], argv[i + 1]];
53
+ if (!spec.includes(key) || value === undefined)
54
+ return null;
55
+ flags[key.slice(2)] = value;
56
+ if (at < 0)
57
+ i += 1;
58
+ }
59
+ return flags;
60
+ }
61
+ function listBuilders(argv, { env, out, fail }) {
62
+ if (argv.length > 1 || (argv.length === 1 && argv[0] !== "--all"))
63
+ return fail("list");
64
+ const all = argv[0] === "--all";
65
+ const root = join(stateDir(env), "builders");
66
+ const ids = existsSync(root) ? readdirSync(root).sort() : [];
67
+ return Promise.all(ids.map(async (id) => {
68
+ const paths = builderPaths(id, env);
69
+ let state;
70
+ try {
71
+ state = readState(paths);
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ if (state.owned) {
77
+ if (!all && FINAL_PHASES.includes(state.phase))
78
+ return null;
79
+ return [state.address || state.unit, state.task, state.sandbox, state.phase, state.phase].join("\t");
80
+ }
81
+ const active = await unitState(state.unit, env);
82
+ if (!all && !LIVE_STATES.includes(active) && FINAL_PHASES.includes(state.phase))
83
+ return null;
84
+ return `${state.unit}\t${state.task}\t${state.sandbox}\t${state.phase}\t${active}`;
85
+ })).then((rows) => {
86
+ for (const row of rows.filter(Boolean))
87
+ out.write(`${row}\n`);
88
+ return 0;
89
+ });
90
+ }
@@ -0,0 +1,176 @@
1
+ // Sandbox policy, harness argv and hook settings: what a builder sandbox may reach and run.
2
+ import * as S from "../sandbox.js";
3
+ import { readFileSync } from "node:fs";
4
+ import { argv } from "../harness.js";
5
+ import { TRACE_ENV } from "../cursor-trace.js";
6
+ import { SANDBOX, TOOLS } from "../sandbox.js";
7
+ import { normalizeHosts, readSandboxHosts } from "../sandbox-hosts.js";
8
+ export const APP_IN = "/sandbox/tools/temmo";
9
+ export const CLAUDE_SETTINGS_IN = "/sandbox/home/.claude/builder-settings.json";
10
+ export const CLAUDE_MCP_IN = "/sandbox/home/.claude/builder-mcp.json";
11
+ export const CURSOR_DIR = "/sandbox/agent";
12
+ export const CODEX_DIR = "/sandbox/codex";
13
+ export const OPENCODE_DIR = "/sandbox/opencode";
14
+ export const CLAUDE_DIR = "/sandbox/claude";
15
+ export const PI_DIR = "/sandbox/pi";
16
+ export const CODE_MCP = "scripts/temmo-code-mcp.mjs";
17
+ // Codex feature switches a sandbox home sets: `apps` adds the ChatGPT connectors server (codex_apps, 26 tools) and `plugins`
18
+ // the account's remote plugin skills, both on by default in codex 0.171 (measured with app-server mcpServerStatus/list and skills/list, 2026-12-04).
19
+ export const CODEX_SANDBOX_FEATURES = { apps: false, plugins: false };
20
+ // API hosts per harness; Cursor's and Claude's api host were measured on 2026-11-22, Codex's are UNVERIFIED; Claude's OAuth hosts come from the network-config docs.
21
+ const API_HOSTS = {
22
+ opencode: ["opencode.ai", "models.dev"],
23
+ cursor: ["api2.cursor.sh", "api3.cursor.sh", "api4.cursor.sh", "agentn.global.api5.cursor.sh", "cursor.com"],
24
+ codex: ["chatgpt.com", "api.openai.com", "auth.openai.com", "ab.chatgpt.com"],
25
+ claude: ["api.anthropic.com", "platform.claude.com", "claude.ai"],
26
+ // pi's providers come from its models.json; runner/adapters/pi-sandbox.ts adds their hosts and ports.
27
+ pi: [],
28
+ };
29
+ // Harnesses whose API traffic skips OpenShell's TLS termination and L7 inspection.
30
+ const TLS_PASSTHROUGH = ["cursor", "opencode"];
31
+ export const NTFY_HOST = "host.openshell.internal";
32
+ export const NTFY_PORT = 8794;
33
+ // The host bus as every sandbox reaches it.
34
+ export const BUS_URL = `http://${NTFY_HOST}:${NTFY_PORT}`;
35
+ // The peers every publishing sandbox lists: all four harnesses, whoever stages it.
36
+ const SANDBOX_PEERS = "claude,codex,cursor,opencode";
37
+ /** The bus entry a sandbox config gets: the host url, and tokenFile (the in-sandbox path) only when the host has a token. */
38
+ export function sandboxBus(tokenFile) {
39
+ return { url: BUS_URL, ...(tokenFile ? { tokenFile } : {}) };
40
+ }
41
+ /** The defaults.json a publishing sandbox gets: the host bus, its peers, and tokenFile (the in-sandbox path) when the host has a token. */
42
+ export function sandboxDefaults({ tokenFile }) {
43
+ return `${JSON.stringify({ ...sandboxBus(tokenFile), peers: SANDBOX_PEERS }, null, 2)}\n`;
44
+ }
45
+ // Host hook events that feed `oncebitten capture` when the host config names none.
46
+ const CAPTURE_EVENTS = { cursor: ["beforeSubmitPrompt", "postToolUse", "postToolUseFailure"], codex: ["UserPromptSubmit"], claude: ["UserPromptSubmit", "PostToolUse", "PostToolUseFailure"] };
47
+ // A lean headless Claude builder: the built-in tools a builder edits and tests with; Glob and Grep must be named on Linux.
48
+ const CLAUDE_TOOLS = "Bash,Read,Edit,Write,Glob,Grep";
49
+ // Documented in code.claude.com/docs/en/env-vars: each turns off a feature or network call a headless builder never needs.
50
+ export const CLAUDE_ENV = {
51
+ CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1", DISABLE_AUTOUPDATER: "1",
52
+ DISABLE_FEEDBACK_COMMAND: "1", DISABLE_COST_WARNINGS: "1", CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY: "1", CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1",
53
+ CLAUDE_CODE_DISABLE_TERMINAL_TITLE: "1", CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1", CLAUDE_CODE_DISABLE_AGENT_VIEW: "1",
54
+ CLAUDE_CODE_DISABLE_ARTIFACT: "1", ENABLE_CLAUDEAI_MCP_SERVERS: "false", CLAUDE_CODE_DISABLE_OFFICIAL_MARKETPLACE_AUTOINSTALL: "1",
55
+ CLAUDE_CODE_IDE_SKIP_AUTO_INSTALL: "1",
56
+ };
57
+ // The CLI marks itself non-dumpable unless this is set; OpenShell then cannot read its /proc/<pid>/exe and denies its DNS and sockets (measured 2026-11-22).
58
+ // The host traces a Cursor builder from its stream-json (lib/cursor-trace.ts), so its in-sandbox hooks record nothing.
59
+ export const CURSOR_ENV = { CURSOR_AGENT_ALLOW_PROCESS_INSPECTION: "1", [TRACE_ENV]: "launcher" };
60
+ // temmo MCP tools a builder never calls: sandbox task calls reach the host store (PR #160), but the supervisor owns a builder's task status.
61
+ const CLAUDE_MCP_DENY = ["task_list", "task_update", "team_start", "team_status", "pattern_start", "pattern_advance", "pattern_status", "pattern_list", "interrupt", "list_sessions"]
62
+ .map((tool) => `mcp__temmo__${tool}`);
63
+ // Tools no sandboxed Claude uses: remote triggers, schedules, artifacts, workflows, phone pushes and host worktrees.
64
+ export const CLAUDE_SESSION_TOOL_DENY = ["RemoteTrigger", "Artifact", "ArtifactData", "CronCreate", "CronDelete", "CronList", "ScheduleWakeup", "PushNotification", "SendUserFile", "Workflow", "DesignSync", "EnterWorktree", "ExitWorktree"];
65
+ // Tools a builder never uses, denied by bare name so they leave the context even if --tools changes.
66
+ const CLAUDE_TOOL_DENY = ["Agent", "Task", "WebFetch", "WebSearch", "Skill", "RemoteTrigger", "Artifact", "ArtifactData", "CronCreate", "CronDelete", "CronList", "ScheduleWakeup", "PushNotification", "SendUserFile", "SendMessage", "Monitor", "Workflow", "DesignSync", "NotebookEdit", "EnterWorktree", "ExitWorktree"];
67
+ // Settings keys every sandboxed Claude (builder or runner session) turns off; checked against the 2.1.330 CLI's settings schema.
68
+ export const CLAUDE_LEAN_SETTINGS = {
69
+ autoMemoryEnabled: false, disableBundledSkills: true, disableWorkflows: true, disableArtifact: true,
70
+ disableRemoteControl: true, remoteControlAtStartup: false, promptSuggestionEnabled: false, awaySummaryEnabled: false,
71
+ agentPushNotifEnabled: false, inputNeededNotifEnabled: false, feedbackSurveyRate: 0, spinnerTipsEnabled: false,
72
+ enabledPlugins: { "cc-plugin-telemetry@builtin": false, "cc-plugin-privacy@builtin": false, "cc-plugin-agents-md@builtin": false, "cc-plugin-plugin-authoring@builtin": false },
73
+ };
74
+ // A headless builder also compacts late and drops the git instructions; the names are the ones the host's own settings.json uses.
75
+ const CLAUDE_SETTINGS = { autoCompactEnabled: true, autoCompactWindow: 250000, includeGitInstructions: false, ...CLAUDE_LEAN_SETTINGS };
76
+ /** Harness argv in the sandbox, its own sandbox off; Codex gets hook trust (docs/builders.md). */
77
+ export function harnessCommand({ harness, model, brief, workdir, launcher, builderCode }) {
78
+ const sandbox = { tools: TOOLS, claudeTools: CLAUDE_TOOLS, mcpIn: CLAUDE_MCP_IN, settingsIn: CLAUDE_SETTINGS_IN };
79
+ const command = argv(harness, "builder", { model, brief, workdir, launcher, builderCode, sandbox });
80
+ if (!command)
81
+ throw new Error(`unknown harness ${harness}`);
82
+ return [command[0], ...command[1]];
83
+ }
84
+ // Package registries a runner sandbox pulls dependencies from, for most languages (npm, PyPI, crates, Go, RubyGems, Maven and
85
+ // Gradle, NuGet, Packagist, Hex, pub, CRAN, conda). Only HTTPS on 443; OS packages (apt) are not listed.
86
+ export const PACKAGE_HOSTS = [
87
+ "registry.npmjs.org", "registry.yarnpkg.com",
88
+ "pypi.org", "files.pythonhosted.org",
89
+ "index.crates.io", "static.crates.io", "crates.io",
90
+ "proxy.golang.org", "sum.golang.org",
91
+ "rubygems.org", "index.rubygems.org",
92
+ "repo.maven.apache.org", "repo1.maven.org", "plugins.gradle.org", "services.gradle.org",
93
+ "api.nuget.org", "globalcdn.nuget.org",
94
+ "repo.packagist.org",
95
+ "repo.hex.pm", "hex.pm",
96
+ "pub.dev",
97
+ "cran.r-project.org",
98
+ "conda.anaconda.org",
99
+ ];
100
+ // The OpenShell rest proxy refuses a `%2F` in the path (connect EACCES). npm sends one for every scoped package
101
+ // (`/@scope%2fname`, measured 2026-12-01). The same refusal applies to any host in this rule, so PyPI, crates, Go,
102
+ // RubyGems, Maven and Gradle, NuGet, Packagist, Hex, pub, CRAN and conda allow an encoded slash too.
103
+ // The executables a package install runs: the sandbox image's standard install prefixes (/usr is read-only there) and the
104
+ // uploaded tools tree, so an interpreter or package manager there reaches the registries. A glob matches real paths.
105
+ export const PACKAGE_BINARIES = ["/usr/bin/**", "/usr/local/bin/**", "/usr/lib/**", "/usr/local/lib/**", `${TOOLS}/**`];
106
+ /** The sandbox policy (JSON is YAML): the harness's API hosts and the host's bus port, for the named binaries only.
107
+ * `packages` adds the package-registry rule (PACKAGE_HOSTS, for PACKAGE_BINARIES); runner sandboxes set it, builders do not.
108
+ * Personal hosts from `~/.config/temmo/sandbox-hosts.json` (or `userHosts`) become a `personal` rule; regenerating
109
+ * policy never writes that file. Pass `userHosts: []` to omit them (tests). */
110
+ export function builderPolicy({ harness, binaries, ntfyBinaries = [], packages = false, userHosts }) {
111
+ // Cursor and OpenCode keep their own TLS: through the TLS-terminating proxy Zen refuses free models (measured 2026-11-22).
112
+ const apiEndpoint = (host) => TLS_PASSTHROUGH.includes(harness)
113
+ ? { host, port: 443, protocol: "tcp", tls: "skip" }
114
+ : endpoint(host, 443);
115
+ const endpoint = (host, port) => ({ host, port, protocol: "rest", access: "full" });
116
+ const hosts = API_HOSTS[harness];
117
+ const binary = (path) => ({ path });
118
+ const personal = normalizeHosts(userHosts ?? readSandboxHosts());
119
+ // Keyed by policy name: callers add entries (host providers) beside these. fromEntries keeps the inferred
120
+ // endpoint shapes while still typing the dictionary by name, so piPolicy and opencodePolicy can add their own.
121
+ const networkPolicies = Object.fromEntries([
122
+ ...(hosts.length ? [[harness, { name: harness, endpoints: hosts.map(apiEndpoint), binaries: binaries.map(binary) }]] : []),
123
+ // The policy entry keeps its pre-rename key and name, so a policy reapplied to a live sandbox is unchanged.
124
+ ["ai_collab", { name: "ai-collab", endpoints: [endpoint(NTFY_HOST, NTFY_PORT)], binaries: [...binaries, ...ntfyBinaries].map(binary) }],
125
+ ...(packages ? [["packages", { name: "packages", endpoints: PACKAGE_HOSTS.map((host) => ({ ...endpoint(host, 443), allow_encoded_slash: true })), binaries: PACKAGE_BINARIES.map(binary) }]] : []),
126
+ ...(personal.length ? [["personal", {
127
+ name: "personal",
128
+ endpoints: personal.map(({ host, port }) => ({ ...endpoint(host, port), allow_encoded_slash: true })),
129
+ binaries: [...binaries, ...ntfyBinaries, ...PACKAGE_BINARIES].map(binary),
130
+ }]] : []),
131
+ ]);
132
+ return {
133
+ version: 1,
134
+ filesystem_policy: {
135
+ include_workdir: true,
136
+ read_only: ["/usr", "/lib", "/bin", "/proc", "/dev/urandom", "/etc", "/var/log"],
137
+ read_write: [SANDBOX, "/tmp", "/dev/null"],
138
+ },
139
+ landlock: { compatibility: "best_effort" },
140
+ network_policies: networkPolicies,
141
+ };
142
+ }
143
+ /** The lean Claude settings file: feature switches, denied tools, and the capture hooks. */
144
+ export function claudeSettings(events) {
145
+ return { ...CLAUDE_SETTINGS, permissions: { deny: [...CLAUDE_TOOL_DENY, ...CLAUDE_MCP_DENY] }, ...captureHooks("claude", events) };
146
+ }
147
+ /** The only MCP servers a Claude builder gets: temmo, and code mode when its script exists; none without node. */
148
+ export function claudeMcpConfig({ node, project, codeMode }) {
149
+ if (!node)
150
+ return { mcpServers: {} };
151
+ const server = (script) => ({ command: `${TOOLS}/node/bin/node`, args: [`${APP_IN}/${script}`], env: { TEMMO_PROJECT: project, TEMMO_PEER: "claude" } });
152
+ return { mcpServers: { "temmo": server("scripts/temmo-mcp.mjs"), ...(codeMode ? { "temmo-code": server(CODE_MCP) } : {}) } };
153
+ }
154
+ /** Hook settings that save every capture payload in the sandbox: Cursor's hooks.json, Codex's, or Claude's settings hooks. */
155
+ export function captureHooks(harness, events) {
156
+ const command = `${TOOLS}/bin/ob-capture ${harness}`;
157
+ if (harness === "cursor")
158
+ return { version: 1, hooks: Object.fromEntries(events.map((e) => [e, [{ command }]])) };
159
+ return { hooks: Object.fromEntries(events.map((e) => [e, [{ hooks: [{ type: "command", command }] }]])) };
160
+ }
161
+ /** Hook events whose host commands run `oncebitten capture`, read from the host's hooks.json; defaults when none. */
162
+ export function hostCaptureEvents(harness, file) {
163
+ let hooks = {};
164
+ try {
165
+ hooks = JSON.parse(readFileSync(file, "utf8")).hooks ?? {};
166
+ }
167
+ catch {
168
+ return CAPTURE_EVENTS[harness];
169
+ }
170
+ const captures = (entry) => {
171
+ const e = entry;
172
+ return /oncebitten\S*'?\s+capture/.test(String(e?.command ?? "")) || (e?.hooks ?? []).some(captures);
173
+ };
174
+ const events = Object.entries(hooks).filter(([, list]) => Array.isArray(list) && list.some(captures)).map(([event]) => event);
175
+ return events.length ? events : CAPTURE_EVENTS[harness];
176
+ }
@@ -0,0 +1,189 @@
1
+ // Recovery after a restart, the task handoff, and the runner-owned builder hooks.
2
+ import * as S from "../sandbox.js";
3
+ import { isProjectPaused, PROJECT_PAUSED } from "../project-pause.js";
4
+ import { existsSync, readFileSync } from "node:fs";
5
+ import { basename, join } from "node:path";
6
+ import { stateDir } from "../config.js";
7
+ import { PROMPT_MAX_CHARS } from "../sessions/launch.js";
8
+ import { withLock } from "../state.js";
9
+ import { openTasks } from "../tasks.js";
10
+ import { BUILDER_HARNESSES, DEFAULT_MODEL, ID_RE, BUILDER_START_TIMEOUT_MS, SYNC_TIMEOUT_MS, FINAL_PHASES, LIVE_STATES, builderPaths, builderId, readState, updateState, builderExited, oneLine } from "./state.js";
11
+ import { builderSandboxGone, uploadBuilderSandbox, upload, stage } from "./stage.js";
12
+ import { cursorLimitDetail, retryLimitedBuilder, collect, downloadWorktree, cleanupBuilderSandbox } from "./run.js";
13
+ import { prepareSettlement, publishSettlement } from "./settle.js";
14
+ import { launchBuilder, unitState } from "./supervisor.js";
15
+ /** The stopped builder snapshot used by the task handoff. A task done or waiting for review is not handed off again. */
16
+ export function stoppedBuilder(project, task, env) {
17
+ const id = builderId(task.id);
18
+ if (!ID_RE.test(id) || task.status === "done" || task.status === "review")
19
+ return null;
20
+ const paths = builderPaths(id, env);
21
+ let state;
22
+ try {
23
+ state = readState(paths);
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ if (state.project !== project || state.task !== task.id || !FINAL_PHASES.includes(state.phase)
29
+ || state.sandboxCreated || state.sandboxDeleted === false || !existsSync(join(state.worktree, ".git")))
30
+ return null;
31
+ if (state.phase !== "finished" || state.commits > 0 && !state.landed) {
32
+ if (existsSync(join(paths.back, basename(state.worktree))))
33
+ return null;
34
+ }
35
+ return state;
36
+ }
37
+ export function builderAssignment(project, task, sessions, env) {
38
+ // A build waiting for review, and a finished one, have nothing to recover.
39
+ if (task.status === "done" || task.status === "review")
40
+ return null;
41
+ const paths = builderPaths(builderId(task.id), env);
42
+ if (!existsSync(paths.state))
43
+ return null;
44
+ let state;
45
+ try {
46
+ state = readState(paths);
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ if (state.project !== project || state.task !== task.id)
52
+ return null;
53
+ if (!builderExited(state)) {
54
+ return !state.owned && task.status === "building" && state.workspaceUploaded && !task.owner ? { builderUnit: state.unit } : null;
55
+ }
56
+ if (sessions.some(session => session.taskId === task.id && session.status !== "ended"))
57
+ return null;
58
+ if (task.owner && task.owner !== state.address && task.owner !== state.previousOwner)
59
+ return null;
60
+ const backup = join(paths.back, basename(state.worktree));
61
+ return { recovery: {
62
+ harness: state.harness, choices: BUILDER_HARNESSES.filter(harness => harness !== state.harness),
63
+ worktree: state.worktree, branch: state.branch, commits: state.commits ?? 0,
64
+ sandboxWorkspace: Boolean(state.sandboxCreated && state.workspaceUploaded && !state.collected),
65
+ ...(existsSync(join(backup, ".git")) ? { backup } : {}),
66
+ } };
67
+ }
68
+ export async function recoverBuilder(project, id, harness, sessions, env) {
69
+ if (isProjectPaused({ project, stateDir: stateDir(env) }))
70
+ throw new Error(PROJECT_PAUSED);
71
+ const paths = builderPaths(builderId(id), env);
72
+ const result = await withLock(join(paths.dir, "recovery"), async () => {
73
+ const task = openTasks(project, env).get(id);
74
+ const recovery = builderAssignment(project, task, sessions(), env)?.recovery;
75
+ if (!recovery)
76
+ throw new Error("This task has no recoverable builder");
77
+ const state = readState(paths);
78
+ const nextHarness = harness ?? state.harness;
79
+ if (!BUILDER_HARNESSES.includes(nextHarness))
80
+ throw new Error("Unknown builder harness");
81
+ const model = nextHarness === state.harness ? state.model : DEFAULT_MODEL[nextHarness];
82
+ const limited = cursorLimitDetail(nextHarness, model, env);
83
+ if (limited)
84
+ throw new Error(limited);
85
+ if (!state.owned && LIVE_STATES.includes(await unitState(state.unit, env)))
86
+ throw new Error("The previous builder is still stopping");
87
+ if (!existsSync(state.worktree))
88
+ throw new Error("The builder worktree is missing");
89
+ const openshell = env.TEMMO_OPENSHELL_BIN || "openshell";
90
+ if (state.sandboxCreated) {
91
+ if (recovery.sandboxWorkspace)
92
+ await downloadWorktree(state, paths, openshell, env);
93
+ const gone = await builderSandboxGone(state, { openshell, env });
94
+ if (!gone.ok)
95
+ throw new Error("Could not clear the previous sandbox: " + gone.detail);
96
+ updateState(paths, { sandboxCreated: false });
97
+ }
98
+ const brief = readFileSync(paths.brief, "utf8");
99
+ const last = task.progress.at(-1);
100
+ const context = ["Recover the unfinished assignment. Review the existing changes before continuing.",
101
+ last && "Last task update: " + last.text].filter(Boolean).join("\n\n").slice(0, 1000);
102
+ const prompt = brief.slice(0, PROMPT_MAX_CHARS - context.length - 2) + "\n\n" + context;
103
+ const { id: builder, branch, base, root, worktree, unit, sandbox, run } = state;
104
+ await launchBuilder(paths, {
105
+ id: builder, task: id, project, branch, base, root, worktree, unit, sandbox, run, prompt,
106
+ harness: nextHarness, model,
107
+ previousOwner: task.owner, commits: recovery.commits,
108
+ ...(existsSync(join(paths.back, basename(worktree), ".git")) ? { resume: join(paths.back, basename(worktree)) } : {}),
109
+ }, { env });
110
+ }, { staleMs: 2 * SYNC_TIMEOUT_MS + BUILDER_START_TIMEOUT_MS + 60_000 });
111
+ if (!result.locked)
112
+ throw new Error("Builder recovery is already in progress");
113
+ }
114
+ // Runner-owned builders reuse the standalone staging and landing paths.
115
+ export function ownedBuilder(project, id, env) {
116
+ if (typeof id !== "string" || !ID_RE.test(id))
117
+ throw new Error("Invalid builder id");
118
+ const state = readState(builderPaths(id, env));
119
+ if (!state.owned || state.id !== id || state.harness !== "codex" || state.project !== project)
120
+ throw new Error("Unknown owned builder");
121
+ return state;
122
+ }
123
+ export function markOwnedBuilderFailed(project, id, address, error, env) {
124
+ const paths = builderPaths(id, env);
125
+ if (!existsSync(paths.state))
126
+ return;
127
+ const current = ownedBuilder(project, id, env);
128
+ if (current.address !== address || FINAL_PHASES.includes(current.phase))
129
+ return;
130
+ updateState(paths, { phase: "failed", ended: Date.now(), error });
131
+ }
132
+ export async function stageOwnedBuilder(state, env, log) {
133
+ const paths = builderPaths(state.id, env);
134
+ const openshell = env.TEMMO_OPENSHELL_BIN || "openshell";
135
+ const current = readState(paths);
136
+ updateState(paths, { phase: "staging" });
137
+ const staged = await stage(state, paths, { env, log });
138
+ const context = { openshell, env, log };
139
+ // Only a sandbox recorded as ours can be reused after a partial upload.
140
+ if (!current.sandboxCreated)
141
+ await uploadBuilderSandbox(state, paths, staged, context);
142
+ else if (!current.workspaceUploaded)
143
+ await upload(state, paths, staged, context);
144
+ updateState(paths, { workspaceUploaded: true });
145
+ return {
146
+ workdir: staged.workdir,
147
+ layout: { auth: "" },
148
+ argv: S.execArgv({
149
+ openshell, sandbox: state.sandbox, workdir: staged.workdir,
150
+ env: { ...staged.execEnv, TEMMO_OWNED: "codex" },
151
+ command: [`${staged.layout.dir}/${basename(staged.layout.tree)}${staged.layout.launcher}`, "app-server", "-c", "thread_unload_delay_secs=0"],
152
+ }),
153
+ };
154
+ }
155
+ export async function claimOwnedBuilder(state, address, env) {
156
+ // A task already attached to a run retains that association.
157
+ await openTasks(state.project, env).update(state.task, { owner: address, status: "building", ...(state.run ? { run: state.run } : {}) });
158
+ updateState(builderPaths(state.id, env), { phase: "running", address });
159
+ }
160
+ export async function finishOwnedBuilder(state, staged, exitCode, env, log, failure, usageLimit = false, signal) {
161
+ const paths = builderPaths(state.id, env);
162
+ const openshell = env.TEMMO_OPENSHELL_BIN || "openshell";
163
+ const taskEnv = { ...env, TEMMO_PROJECT: state.project };
164
+ const current = readState(paths);
165
+ if (!FINAL_PHASES.includes(current.phase)) {
166
+ if (!current.settlement) {
167
+ try {
168
+ if (failure)
169
+ throw new Error(failure);
170
+ signal?.throwIfAborted();
171
+ if (!current.fallback && current.phase !== "collected") {
172
+ await collect(state, paths, staged, { openshell, env, log });
173
+ updateState(paths, { phase: "collected", exitCode });
174
+ }
175
+ if (usageLimit || current.fallback)
176
+ await retryLimitedBuilder(state, paths, { openshell, env: taskEnv, log, signal });
177
+ else
178
+ await prepareSettlement(state, paths, current.phase === "collected" ? current.exitCode : exitCode, { env: taskEnv, log });
179
+ }
180
+ catch (error) {
181
+ signal?.throwIfAborted();
182
+ const detail = "builder " + state.id + " failed: " + oneLine(error.message);
183
+ updateState(paths, { settlement: { status: "blocked", detail, at: Date.now(), error: error.message } });
184
+ }
185
+ }
186
+ await publishSettlement(state, paths, taskEnv);
187
+ }
188
+ await cleanupBuilderSandbox(state, paths, { openshell, env, log });
189
+ }