@temmo/cli 0.0.0 → 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 +112 -1
  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,93 @@
1
+ // A2UI operations for a run-in-terminal card (lib/run-terminal.mjs), and the mapping of its Run or Reject action back.
2
+ import { A2UI_CATALOG_ID, A2UI_VERSION } from "./a2ui.js";
3
+ const RUN_ID = /^[a-f0-9]{24}$/;
4
+ const HEX64 = /^[a-f0-9]{64}$/;
5
+ export const runSurfaceId = id => "run-" + id;
6
+ const op = (kind, body) => ({ version: A2UI_VERSION, [kind]: body });
7
+ const text = (id, value, variant) => ({ id, component: "Text", text: value, ...(variant ? { variant } : {}) });
8
+ const button = (id, label, variant, name, context, checks) => [
9
+ { id, component: "Button", child: id + "-label", variant, action: { event: { name, context } }, ...(checks ? { checks } : {}) },
10
+ text(id + "-label", label),
11
+ ];
12
+ const seconds = ms => (ms / 1000).toFixed(ms < 10_000 ? 1 : 0) + " s";
13
+ /** The status line of a request that is no longer waiting for a click. */
14
+ export function runOutcome(request) {
15
+ const by = request.by ? " · " + request.by : "";
16
+ if (request.status === "rejected")
17
+ return "Rejected" + by;
18
+ if (request.status === "expired")
19
+ return "Expired before anyone ran it";
20
+ if (request.status === "refused")
21
+ return "Refused: " + (request.why || "closed") + by;
22
+ if (request.status === "running")
23
+ return "Running" + by;
24
+ if (request.status === "lost")
25
+ return "Lost: the UI server restarted while it ran" + by;
26
+ if (request.status !== "done")
27
+ return "";
28
+ if (request.error)
29
+ return "Could not start bash: " + request.error;
30
+ if (request.timedOut)
31
+ return `Killed at the ${request.timeoutS} s timeout · ${seconds(request.durationMs)}` + by;
32
+ const end = request.signal ? "Ended by " + request.signal : "Exit " + request.exitCode;
33
+ return `${end} · ${seconds(request.durationMs)}` + by;
34
+ }
35
+ /** createSurface, components and data model for one request; Run sends the hash the browser computed from the shown bytes. */
36
+ export function runOperations(request, now = Date.now()) {
37
+ const surfaceId = runSurfaceId(request.id);
38
+ const pending = request.status === "pending" && request.expiresAt > now;
39
+ // The same word as the summary row (web/lib/run-row.ts): a run that ended without exit 0 failed.
40
+ const failed = request.status === "done" && Boolean(request.error || request.timedOut || request.signal || request.exitCode !== 0);
41
+ const status = pending ? "" : request.status === "pending" ? "Expired before anyone ran it" : runOutcome(request);
42
+ const components = [
43
+ { id: "root", component: "Column", children: [] },
44
+ text("title", "Run in terminal"),
45
+ { id: "badge", component: "Chip", text: pending ? "waiting" : request.status === "pending" ? "expired" : failed ? "failed" : request.status, tone: pending ? "default" : failed ? "danger" : "muted" },
46
+ { id: "heading", component: "Row", children: ["title", "badge"], justify: "spaceBetween", align: "center" },
47
+ text("reason", request.reason),
48
+ text("from", "From " + request.session, "caption"),
49
+ { id: "cwd", component: "Script", label: "cwd", text: request.cwd, inline: true },
50
+ // A decided card folds its script, so its outcome and output fit a phone screen.
51
+ { id: "script", component: "Script", label: "Script", text: { path: "/script" }, sha256: request.sha256, shown: { path: "/shown" }, ...(pending ? {} : { collapsed: true }) },
52
+ ];
53
+ const children = ["heading", "reason", "from", "cwd", "script"];
54
+ if (pending) {
55
+ const checks = [{ condition: { call: "required", args: { value: { path: "/shown" } } }, message: "Checking the script hash" }];
56
+ components.push(...button("run", "Run", "primary", "run", { id: request.id, sha256: { path: "/shown" } }, checks));
57
+ components.push(...button("reject", "Reject", "default", "reject", { id: request.id }));
58
+ components.push({ id: "actions", component: "Row", children: ["reject", "run"], justify: "end" });
59
+ components.push(text("expires", `Expires ${new Date(request.expiresAt).toISOString().slice(11, 16)} UTC · times out after ${request.timeoutS} s`, "caption"));
60
+ children.push("actions", "expires");
61
+ }
62
+ else {
63
+ components.push(text("status", status));
64
+ children.push("status");
65
+ if (request.stdoutTail) {
66
+ components.push({ id: "stdout", component: "Script", label: "stdout", text: { path: "/stdout" }, follow: true });
67
+ children.push("stdout");
68
+ }
69
+ if (request.stderrTail) {
70
+ components.push({ id: "stderr", component: "Script", label: "stderr", text: { path: "/stderr" }, follow: true });
71
+ children.push("stderr");
72
+ }
73
+ }
74
+ components[0].children = children;
75
+ return [
76
+ op("createSurface", { surfaceId, catalogId: A2UI_CATALOG_ID }),
77
+ op("updateComponents", { surfaceId, components }),
78
+ op("updateDataModel", { surfaceId, path: "/", value: { script: request.script, shown: "", stdout: request.stdoutTail || "", stderr: request.stderrTail || "" } }),
79
+ ];
80
+ }
81
+ /** {id, decision, sha256} from a run card's action, or null when the action is not one. */
82
+ export function runAnswer(userAction) {
83
+ const context = userAction?.context;
84
+ if (!context || typeof context !== "object" || typeof context.id !== "string" || !RUN_ID.test(context.id))
85
+ return null;
86
+ if (userAction.surfaceId !== runSurfaceId(context.id))
87
+ return null;
88
+ if (userAction.name === "reject")
89
+ return { id: context.id, decision: "reject" };
90
+ if (userAction.name === "run" && typeof context.sha256 === "string" && HEX64.test(context.sha256))
91
+ return { id: context.id, decision: "run", sha256: context.sha256 };
92
+ return null;
93
+ }
@@ -0,0 +1,262 @@
1
+ // A2UI operations for approval and question cards, and the mapping of a surface action back to an answer.
2
+ // Protocol v0.9.1: @a2ui/react 0.15.0 accepts v0.9 and v0.9.1 only; no v1.0 renderer exists yet.
3
+ export const A2UI_ACTIVITY = "a2ui-surface";
4
+ export const A2UI_VERSION = "v0.9.1";
5
+ export const A2UI_CATALOG_ID = "urn:temmo:a2ui:catalog:1";
6
+ const ENDED = {
7
+ allowed: "Allowed from the phone", denied: "Denied from the phone", answered: "Answered from the phone",
8
+ timeout: "Timed out: the terminal prompt took over", "afk-off": "AFK turned off: the terminal prompt took over",
9
+ cancelled: "Closed: answered in the terminal or the agent stopped", terminal: "Answered in the terminal",
10
+ skipped: "Skipped",
11
+ };
12
+ export const SKIPPED = ENDED.skipped;
13
+ export const IN_TERMINAL = "Answer in the terminal";
14
+ // Why a view-only card has no buttons, and how to get them next time.
15
+ export const IN_TERMINAL_HINT = "AFK is off, so the terminal holds this prompt. Turn AFK on to answer approvals here.";
16
+ // The same card once AFK is back on: the showing prompt stays in the terminal, and the card must not claim AFK is off.
17
+ export const IN_TERMINAL_STALE = "AFK is on again, so the next approval comes to the phone. This prompt is already in the terminal.";
18
+ // The hook could not read the mode, so the card may not claim the operator is at the terminal either way.
19
+ export const IN_TERMINAL_UNKNOWN = "This prompt is already in the terminal, so answer it there. New approvals follow the current AFK mode.";
20
+ // The wire prefix of a blocking question; the server reads it, the card hides it.
21
+ const BLOCKING_PREFIX = /^IMPORTANT, the agent waits for this answer: /;
22
+ // Why a view-only card has no buttons, from the live mode: the hook saw AFK off, and the card must not outlive that
23
+ // reading to claim the operator is present while AFK is on, or the reverse when the hook's own read failed.
24
+ export function terminalHint(mode) {
25
+ if (mode === "off")
26
+ return IN_TERMINAL_HINT;
27
+ if (mode === "on" || mode === "quiet")
28
+ return IN_TERMINAL_STALE;
29
+ return IN_TERMINAL_UNKNOWN;
30
+ }
31
+ const HEX12 = /^[a-f0-9]{12}$/;
32
+ /** Outcome line for an approval: its end reason, "sent", or expiry; "" while it waits for an answer. */
33
+ export function approvalOutcome(approval, now) {
34
+ if (ENDED[approval.state])
35
+ return ENDED[approval.state];
36
+ if (approval.expiresAt && approval.expiresAt < now)
37
+ return approval.decision ? "Expired before the agent read the answer" : "Expired: answered in the terminal or timed out";
38
+ if (approval.state === "sent")
39
+ return approval.decision === "deny" ? "Deny sent, waiting for the agent" : "Answer sent, waiting for the agent";
40
+ return "";
41
+ }
42
+ export const ALWAYS_LABEL = "Always for this session";
43
+ // Only the runner's Cursor adapter remembers a session grant (decision "always"); other cards keep Allow and Deny.
44
+ export const offersSessionGrant = approval => approval.owned === true && approval.harness === "cursor" && !approval.questions;
45
+ // A terminal Claude session's saved /permission mode rides on the next Allow (hook setMode), so the button names it.
46
+ export const allowLabel = approval => approval.switchTo ? "Allow · switch to " + approval.switchTo : "Allow";
47
+ export const approvalSurfaceId = id => "approval-" + id;
48
+ export const questionSurfaceId = question => "question-" + question;
49
+ const op = (kind, body) => ({ version: A2UI_VERSION, [kind]: body });
50
+ const text = (id, value) => ({ id, component: "Text", text: value });
51
+ const column = (id, children) => ({ id, component: "Column", children });
52
+ const button = (id, label, variant, name, context, checks) => [
53
+ { id, component: "Button", child: id + "-label", variant, action: { event: { name, context } }, ...(checks ? { checks } : {}) },
54
+ text(id + "-label", label),
55
+ ];
56
+ // A question is answered when its picks or its Other text is non-empty; Submit stays disabled until all are.
57
+ const answered = i => ({ call: "or", args: { values: [
58
+ { call: "required", args: { value: { path: `/picks/${i}` } } },
59
+ { call: "required", args: { value: { path: `/other/${i}` } } },
60
+ ] }, returnType: "boolean" });
61
+ const withBy = (outcome, by) => outcome + (by ? " · " + by : "");
62
+ // createSurface, then the components, then the data model the components bind to.
63
+ function surfaceOps(surfaceId, components, model) {
64
+ return [
65
+ op("createSurface", { surfaceId, catalogId: A2UI_CATALOG_ID }),
66
+ op("updateComponents", { surfaceId, components }),
67
+ op("updateDataModel", { surfaceId, path: "/", value: model }),
68
+ ];
69
+ }
70
+ // A closed request shows a muted badge: "answered" when someone answered it, else "closed"; none while open.
71
+ const ANSWERED = ["allowed", "denied", "answered", "sent"];
72
+ const badgeOf = (approval, open) => open ? "" : ANSWERED.includes(approval.state) ? "answered" : "closed";
73
+ // The title line, with the badge beside it when closed; pushes its components and returns the child ids.
74
+ function titleRow(components, title, badge) {
75
+ components.push(text("title", title));
76
+ if (!badge)
77
+ return ["title"];
78
+ components.push({ id: "badge", component: "Chip", text: badge, tone: "muted" });
79
+ components.push({ id: "heading", component: "Row", children: ["title", "badge"], justify: "spaceBetween", align: "center" });
80
+ return ["heading"];
81
+ }
82
+ // Permission request: tool line and summary, then Allow and Deny while open, else the terminal note or the outcome.
83
+ function permissionOps(approval, open, outcome, terminal) {
84
+ const components = [column("root", [])];
85
+ const children = titleRow(components, "Permission · " + approval.tool, badgeOf(approval, open));
86
+ if (approval.summary) {
87
+ components.push(text("summary", approval.summary));
88
+ children.push("summary");
89
+ }
90
+ if (open && !terminal) {
91
+ const always = offersSessionGrant(approval);
92
+ components.push({ id: "actions", component: "Row", children: always ? ["allow", "always", "deny"] : ["allow", "deny"], justify: "end" });
93
+ components.push(...button("allow", allowLabel(approval), "primary", "decide", { id: approval.id, decision: "allow" }));
94
+ if (always)
95
+ components.push(...button("always", ALWAYS_LABEL, "default", "decide", { id: approval.id, decision: "always" }));
96
+ components.push(...button("deny", "Deny", "default", "decide", { id: approval.id, decision: "deny" }));
97
+ children.push("actions");
98
+ }
99
+ else {
100
+ components.push(text("status", open ? IN_TERMINAL : withBy(outcome, approval.by)));
101
+ children.push("status");
102
+ if (open) {
103
+ components.push({ id: "hint", component: "Text", variant: "caption", text: terminalHint(approval.mode) });
104
+ children.push("hint");
105
+ }
106
+ }
107
+ components[0].children = children;
108
+ return surfaceOps(approvalSurfaceId(approval.id), components, {});
109
+ }
110
+ // AskUserQuestion: per question a header chip and step, then the OptionPicker that shows the question, with the Other field as its
111
+ // last row; read-only once closed. The card header names the kind, so the body opens on the question itself.
112
+ function choiceOps(approval, open, outcome, terminal) {
113
+ const interactive = open && !terminal;
114
+ const count = approval.questions.length;
115
+ const components = [column("root", [])];
116
+ const rootChildren = [];
117
+ approval.questions.forEach((q, i) => {
118
+ const group = "q" + i;
119
+ const children = [];
120
+ if (i > 0) {
121
+ components.push({ id: group + "-rule", component: "Divider" });
122
+ rootChildren.push(group + "-rule");
123
+ }
124
+ const top = [];
125
+ if (q.header) {
126
+ components.push({ id: group + "-chip", component: "Chip", text: q.header });
127
+ top.push(group + "-chip");
128
+ }
129
+ if (count > 1) {
130
+ components.push({ id: group + "-step", component: "Text", variant: "caption", text: `${i + 1} of ${count}` });
131
+ top.push(group + "-step");
132
+ }
133
+ if (top.length) {
134
+ components.push({ id: group + "-top", component: "Row", children: top, justify: "spaceBetween", align: "center" });
135
+ children.push(group + "-top");
136
+ }
137
+ const options = q.options.map(o => ({
138
+ label: o.label, value: o.label,
139
+ ...(o.description ? { description: o.description } : {}), ...(o.preview ? { preview: o.preview } : {}),
140
+ }));
141
+ const multiSelect = q.multiSelect === true;
142
+ if (interactive) {
143
+ components.push({ id: group + "-pick", component: "OptionPicker", label: q.question, options, multiSelect, value: { path: `/picks/${i}` }, other: { path: `/other/${i}` }, otherChild: group + "-other" });
144
+ components.push({ id: group + "-other", component: "TextField", label: "Other answer", value: { path: `/other/${i}` } });
145
+ children.push(group + "-pick");
146
+ }
147
+ else {
148
+ const answer = String(approval.answers?.[q.question] ?? "");
149
+ const chosen = answer ? answer.split(", ") : [];
150
+ components.push({ id: group + "-pick", component: "OptionPicker", label: q.question, options, multiSelect, readOnly: true, value: chosen });
151
+ children.push(group + "-pick");
152
+ if (chosen.some(label => !q.options.some(o => o.label === label))) {
153
+ components.push(text(group + "-answer", "Answer: " + answer));
154
+ children.push(group + "-answer");
155
+ }
156
+ }
157
+ components.push(column(group, children));
158
+ rootChildren.push(group);
159
+ });
160
+ if (interactive) {
161
+ const every = approval.questions.map((_, i) => answered(i));
162
+ const condition = every.length === 1 ? every[0] : { call: "and", args: { values: every }, returnType: "boolean" };
163
+ const checks = [{ condition, message: "Answer every question" }];
164
+ components.push(...button("submit", "Submit", "primary", "answer", { id: approval.id, picks: { path: "/picks" }, other: { path: "/other" } }, checks));
165
+ components.push({ id: "footer", component: "Row", children: ["submit"], justify: "end" });
166
+ rootChildren.push("footer");
167
+ }
168
+ else {
169
+ // Closed, the outcome is a caption under the answer; open in the terminal, it stays body text with the hint below.
170
+ components.push({ id: "status", component: "Text", ...(open ? {} : { variant: "caption" }), text: open ? IN_TERMINAL : withBy(outcome, approval.by) });
171
+ rootChildren.push("status");
172
+ if (open) {
173
+ components.push({ id: "hint", component: "Text", variant: "caption", text: terminalHint(approval.mode) });
174
+ rootChildren.push("hint");
175
+ }
176
+ }
177
+ components[0].children = rootChildren;
178
+ const model = { picks: approval.questions.map(() => []), other: approval.questions.map(() => "") };
179
+ return surfaceOps(approvalSurfaceId(approval.id), components, model);
180
+ }
181
+ /** Operations for an approval (permission request or AskUserQuestion choice), with the outcome the chat card shows. */
182
+ export function approvalOperations(approval, now) {
183
+ const outcome = approvalOutcome(approval, now);
184
+ const open = !outcome;
185
+ const terminal = approval.terminal === true;
186
+ return approval.questions ? choiceOps(approval, open, outcome, terminal) : permissionOps(approval, open, outcome, terminal);
187
+ }
188
+ /** A question's text without the wire prefix that marks it blocking; the card shows BLOCKING_LABEL instead. */
189
+ export const questionText = body => String(body ?? "").replace(BLOCKING_PREFIX, "");
190
+ /** Whether the agent waits for this question's answer (ask_question important=true). */
191
+ export const isBlocking = body => BLOCKING_PREFIX.test(String(body ?? ""));
192
+ export const BLOCKING_LABEL = "Agent waits for this answer";
193
+ /** Operations for an ask_question post: a blocking tag while open, its body, then an answer field, or the answer once given, or Skipped. */
194
+ export function questionOperations(question, body, answer, by, skipped = false) {
195
+ const components = [column("root", []), text("body", questionText(body))];
196
+ const children = ["body"];
197
+ if (!answer && !skipped && isBlocking(body)) {
198
+ components.push({ id: "blocking", component: "Chip", text: BLOCKING_LABEL, tone: "accent" });
199
+ children.unshift("blocking");
200
+ }
201
+ if (skipped && !answer) {
202
+ components.push(text("status", SKIPPED));
203
+ children.push("status");
204
+ }
205
+ else if (answer) {
206
+ components.push(text("status", "Answered: " + answer + (by ? " · " + by : "")));
207
+ children.push("status");
208
+ }
209
+ else {
210
+ components.push({ id: "answer", component: "TextField", label: "Your answer…", value: { path: "/answer" } });
211
+ components.push(...button("submit", "Submit", "primary", "reply", { question, answer: { path: "/answer" } }));
212
+ components.push({ id: "footer", component: "Row", children: ["submit"], justify: "end" });
213
+ children.push("answer", "footer");
214
+ }
215
+ components[0].children = children;
216
+ return surfaceOps(questionSurfaceId(question), components, { answer: "" });
217
+ }
218
+ /** Surface id and operations for a chat entry shown as a card, or null for any other entry. */
219
+ export function surfaceOf(entry, now = Date.now()) {
220
+ if (entry?.kind === "Approval" && entry.approval && HEX12.test(entry.approval.id)) {
221
+ return { id: approvalSurfaceId(entry.approval.id), operations: approvalOperations(entry.approval, now) };
222
+ }
223
+ if (entry?.kind === "Question" && HEX12.test(entry.question || "")) {
224
+ return { id: questionSurfaceId(entry.question), operations: questionOperations(entry.question, String(entry.body ?? ""), entry.answer, entry.answeredBy, entry.skipped === true) };
225
+ }
226
+ return null;
227
+ }
228
+ const strings = value => Array.isArray(value) && value.every(item => typeof item === "string");
229
+ /**
230
+ * The answer a surface action carries: a permission decision, picks and Other text for a choice, or a question reply.
231
+ * Null when the action matches no surface this module builds.
232
+ */
233
+ export function surfaceAnswer(userAction) {
234
+ const context = userAction?.context;
235
+ if (!context || typeof context !== "object" || Array.isArray(context) || typeof userAction.surfaceId !== "string")
236
+ return null;
237
+ if (typeof context.id === "string" && HEX12.test(context.id) && userAction.surfaceId === approvalSurfaceId(context.id)) {
238
+ if (userAction.name === "decide" && ["allow", "always", "deny"].includes(context.decision))
239
+ return { kind: "approval", id: context.id, decision: context.decision };
240
+ if (userAction.name === "answer" && Array.isArray(context.picks) && context.picks.every(strings) && strings(context.other)) {
241
+ return { kind: "approval", id: context.id, picks: context.picks, other: context.other };
242
+ }
243
+ return null;
244
+ }
245
+ if (userAction.name === "reply" && typeof context.question === "string" && HEX12.test(context.question)
246
+ && userAction.surfaceId === questionSurfaceId(context.question) && typeof context.answer === "string") {
247
+ return { kind: "question", question: context.question, body: context.answer };
248
+ }
249
+ return null;
250
+ }
251
+ /**
252
+ * The answers object a choice reply sends, keyed by question text as AskUserQuestion expects.
253
+ * A typed Other answer replaces the picks of a single-select question, as the chat card does.
254
+ */
255
+ export function choiceAnswers(questions, picks, other) {
256
+ return Object.fromEntries(questions.map((q, i) => {
257
+ const typed = typeof other[i] === "string" ? other[i].trim() : "";
258
+ const chosen = Array.isArray(picks[i]) ? picks[i] : [];
259
+ const values = q.multiSelect ? [...chosen, ...(typed ? [typed] : [])] : typed ? [typed] : chosen;
260
+ return [q.question, values.join(", ")];
261
+ }));
262
+ }
@@ -0,0 +1,275 @@
1
+ // Pure activity-row helpers shared by the Activity view and its tests.
2
+ const SUMMARY_KEYS = ["command", "cmd", "pattern", "file_path", "filePath", "url", "query", "path", "description", "prompt", "skill"];
3
+ const SUMMARY_FIELD = /"(command|cmd|pattern|file_path|filePath|url|query|path|description)"\s*:\s*"((?:[^"\\]|\\.)*)/;
4
+ const WORKING_MS = 15 * 60_000;
5
+ const SHELL_TOOL = /^(bash|shell|exec_command|run_terminal_cmd|terminal)/i;
6
+ const READ_TOOL = /^(read|view|cat|read_file)/i;
7
+ const RUN_ACTIVE_MS = 2 * 60_000;
8
+ const AGENT_TOOL = /^(Agent|Task)$/;
9
+ const AGENT_ID = /"agentId"\s*:\s*"([\w-]{1,128})"/;
10
+ const TASK_DONE = /<task-id>([\w-]{1,128})<\/task-id>[\s\S]*?<status>(?:completed|failed|killed|stopped)<\/status>/;
11
+ // The temmo spawn_agent tool under any MCP prefix (mcp__…__spawn_agent, temmo.spawn_agent).
12
+ const SPAWN_TOOL = /(^|[_.:/])spawn_agent$/;
13
+ // The child address in spawn_agent's result (lib/spawn.ts SpawnResult), its quotes escaped or not.
14
+ const SPAWNED = /\\*"session\\*"\s*:\s*\\*"((?:claude|codex|cursor|opencode)#[a-f0-9]{16})/;
15
+ const DIFF = /^(diff --git |--- \S|\+\+\+ \S|@@ -\d)/m;
16
+ /** One-line summary of a tool input: the command, path, pattern or URL when the input is JSON (even truncated JSON). */
17
+ export function summarize(input) {
18
+ if (!input)
19
+ return "";
20
+ let value;
21
+ try {
22
+ value = JSON.parse(input);
23
+ }
24
+ catch { }
25
+ if (typeof value === "string")
26
+ return value.split("\n")[0];
27
+ if (value && typeof value === "object") {
28
+ const key = SUMMARY_KEYS.find(name => typeof value[name] === "string");
29
+ const text = key ? value[key] : Object.values(value).find(item => typeof item === "string") || "";
30
+ return text.split("\n")[0];
31
+ }
32
+ const field = SUMMARY_FIELD.exec(input);
33
+ if (field)
34
+ return field[2].replace(/\\n/g, " ").replace(/\\(.)/g, "$1");
35
+ return input.split("\n")[0];
36
+ }
37
+ /** The child session address a spawn_agent call or result row started, or "". */
38
+ export function spawnedSession(row) {
39
+ if (!SPAWN_TOOL.test(row?.tool || ""))
40
+ return "";
41
+ const output = row.type === "tool_call" ? row.result?.output : row.output;
42
+ return typeof output === "string" ? SPAWNED.exec(output)?.[1] || "" : "";
43
+ }
44
+ /** Blocks to show for a tool input: a shell command as bash plus any other fields as JSON; other input as JSON when it is JSON. */
45
+ export function inputBlocks(tool, input) {
46
+ if (!input)
47
+ return [];
48
+ let value;
49
+ try {
50
+ value = JSON.parse(input);
51
+ }
52
+ catch { }
53
+ const command = value && typeof value === "object" && !Array.isArray(value) ? value.command ?? value.cmd : undefined;
54
+ if (SHELL_TOOL.test(tool || "") && (typeof command === "string" || Array.isArray(command))) {
55
+ const { command: _, cmd: __, ...rest } = value;
56
+ const blocks = [{ code: Array.isArray(command) ? command.join(" ") : command, language: "bash" }];
57
+ return Object.keys(rest).length ? [...blocks, { code: JSON.stringify(rest, null, 2), language: "json" }] : blocks;
58
+ }
59
+ return [{ code: input, language: /^\s*[[{]/.test(input) ? "json" : "" }];
60
+ }
61
+ /** Language name of a tool result: a diff, shell output as bash, a read file by its extension, JSON; else "". */
62
+ export function resultLanguage(tool, input, output) {
63
+ if (!output)
64
+ return "";
65
+ if (DIFF.test(output) && /^[-+@]/m.test(output))
66
+ return "diff";
67
+ if (SHELL_TOOL.test(tool || ""))
68
+ return "bash";
69
+ if (READ_TOOL.test(tool || "")) {
70
+ const path = /"(?:file_path|filePath|path)"\s*:\s*"((?:[^"\\]|\\.)*)"/.exec(input || "")?.[1] || "";
71
+ const ext = /\.([A-Za-z0-9]+)$/.exec(path)?.[1];
72
+ if (ext)
73
+ return ext.toLowerCase();
74
+ }
75
+ return /^\s*[[{]/.test(output) ? "json" : "";
76
+ }
77
+ /** Joins Claude's streamed text batches and pairs each tool call with its result or error by callId, in arrival order. */
78
+ export function activityRows(items) {
79
+ const results = new Map();
80
+ for (const item of items) {
81
+ if ((item.type === "tool_result" || item.type === "error") && item.callId)
82
+ results.set(item.agent + "|" + item.callId, item);
83
+ }
84
+ const used = new Set();
85
+ const texts = new Map();
86
+ const rows = [];
87
+ for (const item of items) {
88
+ const batch = item.type === "text" && item.callId ? /^(.+)#(\d+)$/.exec(item.callId) : null;
89
+ if (batch) {
90
+ const key = item.agent + "|" + batch[1];
91
+ let row = texts.get(key);
92
+ if (!row) {
93
+ row = { ...item, parts: [] };
94
+ texts.set(key, row);
95
+ rows.push(row);
96
+ }
97
+ row.parts.push([Number(batch[2]), item.output || ""]);
98
+ row.parts.sort((a, b) => a[0] - b[0]);
99
+ row.output = row.parts.map(part => part[1]).join("");
100
+ continue;
101
+ }
102
+ if (item.type === "tool_call" && item.callId) {
103
+ const result = results.get(item.agent + "|" + item.callId);
104
+ if (result)
105
+ used.add(result);
106
+ rows.push({ ...item, result });
107
+ continue;
108
+ }
109
+ if (!used.has(item))
110
+ rows.push(item);
111
+ }
112
+ return rows.filter(row => !used.has(row));
113
+ }
114
+ /** When each session's running turn began (ms): its first prompt row after its newest stop row; a stopped session has none. */
115
+ export function turnStarts(rows) {
116
+ const stops = new Map();
117
+ for (const row of rows)
118
+ if (row.type === "stop" && !row.subagent?.id)
119
+ stops.set(row.agent, Math.max(stops.get(row.agent) ?? -Infinity, row.time));
120
+ const starts = new Map();
121
+ for (const row of rows) {
122
+ if (row.type !== "prompt" || row.subagent?.id || row.time <= (stops.get(row.agent) ?? -Infinity))
123
+ continue;
124
+ starts.set(row.agent, Math.min(starts.get(row.agent) ?? Infinity, row.time * 1000));
125
+ }
126
+ return starts;
127
+ }
128
+ /** Folds each subagent run's rows into one "subagent" row at its first row's place; done on its stop row or the parent's completion notice. */
129
+ export function groupSubagents(rows) {
130
+ const runs = new Map();
131
+ const out = [];
132
+ const launches = new Map();
133
+ const finished = new Map();
134
+ for (const row of rows) {
135
+ if (row.subagent?.id)
136
+ continue;
137
+ // The parent's Agent tool result names the run (agentId) and its description; a foreground run's result means it ended.
138
+ const launch = AGENT_TOOL.test(row.tool || "") ? agentLaunch(row.type === "tool_call" ? row.result?.output : row.type === "tool_result" ? row.output : "", row.input) : null;
139
+ if (launch) {
140
+ launches.set(row.agent + "|" + launch.id, launch);
141
+ if (launch.done)
142
+ finished.set(row.agent + "|" + launch.id, row.result?.time ?? row.time);
143
+ }
144
+ // Claude tells the parent with a <task-notification> prompt when a background run ends.
145
+ const notice = row.type === "prompt" || row.type === "text" ? TASK_DONE.exec(row.input || row.output || "") : null;
146
+ if (notice)
147
+ finished.set(row.agent + "|" + notice[1], row.time);
148
+ }
149
+ for (const row of rows) {
150
+ if (!row.subagent?.id) {
151
+ out.push(row);
152
+ continue;
153
+ }
154
+ const key = row.agent + "|" + row.subagent.id;
155
+ let run = runs.get(key);
156
+ if (!run) {
157
+ run = { id: "subagent:" + key, type: "subagent", agent: row.agent, time: row.time, run: row.subagent.id, kind: "", rows: [] };
158
+ runs.set(key, run);
159
+ out.push(run);
160
+ }
161
+ run.rows.push(row);
162
+ run.kind ||= row.subagent.type;
163
+ }
164
+ for (const [key, run] of runs) {
165
+ run.lastTime = Math.max(...run.rows.map(row => row.time || 0));
166
+ // A resumed run (follow-up message, no new start) reopens: done only when a stop ends the rows or a finish marker is newest.
167
+ // Hooks arrive out of order, so the newest end marker (stop or finish) decides, not the last array row.
168
+ const stopAt = Math.max(-Infinity, ...run.rows.filter(row => row.type === "stop").map(row => row.time || 0));
169
+ const endAt = Math.max(stopAt, finished.get(key) ?? -Infinity);
170
+ run.done = endAt !== -Infinity && endAt >= run.lastTime;
171
+ // A step is one tool use: its call row, or its result alone when the call row never arrived.
172
+ run.steps = run.rows.filter(row => row.type === "tool_call" || ((row.type === "tool_result" || row.type === "error") && row.tool)).length;
173
+ run.description = launches.get(key)?.description || "";
174
+ run.model = launches.get(key)?.model || run.rows.find(row => row.subagent.model)?.subagent.model || "";
175
+ const last = run.rows.findLast(row => row.tool);
176
+ run.last = last ? { tool: last.tool, summary: summarize(last.input), time: last.time } : null;
177
+ const end = run.rows.at(-1);
178
+ run.open = end?.type === "tool_call" && !end.result;
179
+ }
180
+ return out;
181
+ }
182
+ /** done (stopped or reported finished), running (a row in the last 2 min), else idle; without now, every unfinished run is running. */
183
+ export function runState(run, now) {
184
+ if (run.done)
185
+ return "done";
186
+ // A long tool call (a build, a test run) keeps the run running for up to 15 min without new rows.
187
+ if (run.open && now !== undefined && now - (run.lastTime ?? run.time) * 1000 < WORKING_MS)
188
+ return "running";
189
+ return now === undefined || now - (run.lastTime ?? run.time) * 1000 < RUN_ACTIVE_MS ? "running" : "idle";
190
+ }
191
+ /** "Explore · in claude#28d7fa48 · running · 12 steps" for a subagent row. */
192
+ export function subagentLabel(run, now) {
193
+ const address = run.agent || "";
194
+ const short = address.includes("#") ? address.slice(0, address.indexOf("#") + 9) : address;
195
+ return [run.kind || "agent", short && "in " + short, runState(run, now), run.steps + (run.steps === 1 ? " step" : " steps")].filter(Boolean).join(" · ");
196
+ }
197
+ // {id, description, done} from an Agent tool result's JSON text, or null.
198
+ function agentLaunch(output, input) {
199
+ const id = typeof output === "string" ? AGENT_ID.exec(output)?.[1] : "";
200
+ if (!id)
201
+ return null;
202
+ const description = /"description"\s*:\s*"((?:[^"\\]|\\.)*)"/.exec(output)?.[1] || "";
203
+ const model = /"model"\s*:\s*"([\w.:-]{1,64})"/.exec(typeof input === "string" ? input : JSON.stringify(input ?? ""))?.[1] || "";
204
+ return { id, description, model, done: /"status"\s*:\s*"completed"/.test(output) };
205
+ }
206
+ /** A subagent's model: its own, else on Claude the parent's marked inherited; empty when neither is known. */
207
+ export function subagentModel(run, parent) {
208
+ if (run.model || run.child)
209
+ return run.model || "";
210
+ const peer = String(parent?.peer || (run.agent || "").split("#")[0]);
211
+ return peer === "claude" && parent?.model ? parent.model + " · inherited" : "";
212
+ }
213
+ /** Sessions with a running subagent run: session → count. */
214
+ export function runningSubagents(rows, now) {
215
+ const count = new Map();
216
+ for (const row of rows)
217
+ if (row.type === "subagent" && runState(row, now) === "running")
218
+ count.set(row.agent, (count.get(row.agent) || 0) + 1);
219
+ return count;
220
+ }
221
+ /** Chat messages and activity rows in one thread by time (seconds); on a tie the activity row comes first. */
222
+ export function interleave(messages, rows) {
223
+ const out = [];
224
+ let i = 0;
225
+ let j = 0;
226
+ while (i < messages.length || j < rows.length) {
227
+ const takeRow = j < rows.length && (i >= messages.length || (rows[j].time || 0) <= (messages[i].time || 0));
228
+ out.push(takeRow ? { activity: rows[j++] } : { message: messages[i++] });
229
+ }
230
+ return out;
231
+ }
232
+ // Agents whose latest row is a recent tool call with no result yet.
233
+ export function working(rows, now) {
234
+ const latest = new Map();
235
+ for (const row of rows)
236
+ latest.set(row.agent, row);
237
+ return [...latest.values()].filter(row => row.type === "tool_call" && !row.result && now - row.time * 1000 < WORKING_MS).map(row => row.agent);
238
+ }
239
+ // Harness wrappers that arrive as prompt text: Claude Code's background-task notices and subagent hand-backs, pasted blocks.
240
+ const TASK_NOTICE = /^<task-notification>([\s\S]*?)(?:<\/task-notification>)?\s*$/;
241
+ const AGENT_MESSAGE = /^<agent-message from="([^"]*)">([\s\S]*?)(?:<\/agent-message>)?\s*$/;
242
+ const REPORT_START = /The report follows:\s*\n/;
243
+ const PASTED = /<pasted_content[^>]*>\n?([\s\S]*?)\n?<\/pasted_content[^>]*>/g;
244
+ const WRAPPED = /^<([a-z][\w-]*)(?:\s[^>]*)?>\n?([\s\S]*?)\n?<\/\1>\s*$/i;
245
+ // Removes the indent every non-empty line shares.
246
+ function dedent(text) {
247
+ const lines = text.split("\n");
248
+ const indent = Math.min(...lines.filter(line => line.trim()).map(line => /^ */.exec(line)[0].length));
249
+ return Number.isFinite(indent) && indent > 0 ? lines.map(line => line.slice(indent)).join("\n") : text;
250
+ }
251
+ /** Prompt or agent text made readable: harness XML wrappers become a label and plain markdown; other text is unchanged. */
252
+ export function readableText(raw) {
253
+ const text = String(raw || "").trim();
254
+ const notice = TASK_NOTICE.exec(text);
255
+ if (notice) {
256
+ const pick = name => new RegExp(`<${name}>([\\s\\S]*?)</${name}>`).exec(notice[1])?.[1]?.trim() || "";
257
+ return { label: "Task notification", text: [pick("summary") || "A background task changed state", pick("result")].filter(Boolean).join("\n\n") };
258
+ }
259
+ const message = AGENT_MESSAGE.exec(text);
260
+ if (message) {
261
+ const body = message[2];
262
+ const start = REPORT_START.exec(body);
263
+ return { label: "Subagent report", text: dedent(start ? body.slice(start.index + start[0].length) : body).trim() };
264
+ }
265
+ if (text.includes("<pasted_content"))
266
+ return { label: "", text: text.replace(PASTED, (_, inner) => "```text\n" + inner.replace(/```/g, "ˋˋˋ") + "\n```") };
267
+ const wrapped = WRAPPED.exec(text);
268
+ return wrapped ? { label: "", text: wrapped[2].trim() } : { label: "", text: String(raw || "") };
269
+ }
270
+ /** Agents working now: sessions with an open tool call and running subagent runs, as {key, agent, kind}. */
271
+ export function activeAgents(rows, now) {
272
+ const sessions = working(rows.filter(row => row.type !== "subagent"), now).map(agent => ({ key: agent, agent, kind: "" }));
273
+ const runs = rows.filter(row => row.type === "subagent" && runState(row, now) === "running").map(run => ({ key: run.id, agent: run.agent, kind: run.kind || "agent" }));
274
+ return [...sessions, ...runs];
275
+ }
@@ -0,0 +1,5 @@
1
+ // Pure helper: the muted detail shown after an agent's address in chat.
2
+ /** The model then the place, joined by a middle dot: "composer-2.5 · cursor-teams"; "" when neither is known. */
3
+ export function agentDetail(agent) {
4
+ return [agent?.model, agent?.where].filter(Boolean).join(" · ");
5
+ }