@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,110 @@
1
+ import { isTaskId } from "./task-tags.js";
2
+ // Location hash → console selection: the level, project, session, view tab and subagent run a URL names.
3
+ export const LEVELS = [["project", "Project"], ["session", "Sessions"], ["tasks", "Tasks"], ["patterns", "Teams"], ["compactions", "History"]];
4
+ // A thread id in the hash (lib/threads.ts THREAD_ID); the thread level is named by it, like home and inbox are by their flags.
5
+ const THREAD_ID = /^th_[a-f0-9]{16}$/;
6
+ // A native subagent run id (Claude's agentId) whose transcript replaces a session's chat.
7
+ const RUN_ID = /^[\w-]{1,128}$/;
8
+ // Views each level accepts in the hash: a session's chat alone (activity), or beside its subagents, raw activity, diff or PR panel.
9
+ export const TABS = { project: [], session: ["activity", "subagents", "raw", "diff", "pr", "tasks"], tasks: [], patterns: [] };
10
+ /**
11
+ * The hash (without "#") for a selection; the inverse of parseSelection for the keys it keeps.
12
+ * The patterns level carries the pattern, raw flag, run, the team editor (edit) and the author composer (author).
13
+ */
14
+ export function selectionHash(next = {}) {
15
+ if (next.level === "home" || next.level === "inbox" || next.level === "progress")
16
+ return next.level;
17
+ const params = new URLSearchParams();
18
+ for (const key of ["project", "level", "harness", "session"])
19
+ if (next[key])
20
+ params.set(key, next[key]);
21
+ if (next.level === "thread" && THREAD_ID.test(next.thread || ""))
22
+ params.set("thread", next.thread);
23
+ if ((TABS[next.level || "project"] || []).includes(next.tab))
24
+ params.set("tab", next.tab);
25
+ if (next.tab === "subagents" && next.run)
26
+ params.set("run", next.run);
27
+ if (next.level === "session" && next.session && RUN_ID.test(next.subagent || ""))
28
+ params.set("subagent", next.subagent);
29
+ if (next.level === "patterns") {
30
+ for (const key of ["pattern", "run"])
31
+ if (next[key])
32
+ params.set(key, next[key]);
33
+ if (next.raw)
34
+ params.set("raw", "1");
35
+ if (next.edit)
36
+ params.set("edit", next.edit);
37
+ if (next.author)
38
+ params.set("author", "1");
39
+ if (next.edit && next.authorName)
40
+ params.set("authorName", next.authorName);
41
+ }
42
+ if (next.level === "tasks" && isTaskId(next.task))
43
+ params.set("task", next.task);
44
+ if (next.level === "project" && isTaskId(next.composeTask))
45
+ params.set("composeTask", next.composeTask);
46
+ return params.toString();
47
+ }
48
+ /**
49
+ * The badge counts a project's views show: every task and how many of them wait on the operator's decision, and the
50
+ * number of patterns and teams.
51
+ */
52
+ export function projectViewCounts(data = {}) {
53
+ const tasks = data.tasks?.tasks || [];
54
+ const waiting = tasks.filter(task => task.question && !task.question.answer).length;
55
+ return { tasks: tasks.length, waiting, patterns: (data.patterns || []).length };
56
+ }
57
+ /** The selection named by a hash without its "#"; an empty hash, home, or level=home is the Home overview. */
58
+ export function parseSelection(hash) {
59
+ const params = new URLSearchParams(hash);
60
+ const level = params.get("level");
61
+ if (!hash || params.has("home") || level === "home")
62
+ return { project: "", level: "home", harness: "", session: "", tab: "chat", run: "" };
63
+ if (params.has("inbox") || level === "inbox")
64
+ return { project: "", level: "inbox", harness: "", session: "", tab: "chat", run: "" };
65
+ if (params.has("progress") || level === "progress")
66
+ return { project: "", level: "progress", harness: "", session: "", tab: "chat", run: "" };
67
+ // The thread level names one thread of a project (docs/threads.md "Thread view"); without a valid id the hash falls through to the project chat.
68
+ if (level === "thread" && THREAD_ID.test(params.get("thread") || "")) {
69
+ return { project: params.get("project") || "", level: "thread", harness: "", session: "", tab: "chat", run: "", thread: params.get("thread") };
70
+ }
71
+ const tab = params.get("tab");
72
+ // An old link to the board (level=project&tab=tasks) opens the Tasks level.
73
+ const named = level === "project" && tab === "tasks" ? "tasks" : level;
74
+ const at = LEVELS.some(([id]) => id === named) ? named : "project";
75
+ // Old links with tab=chat or tab=activity open a session's timeline.
76
+ const sessionTab = TABS.session.includes(tab) ? tab : "activity";
77
+ const base = {
78
+ project: params.get("project") || "",
79
+ level: at,
80
+ harness: params.get("harness") || "",
81
+ session: params.get("session") || "",
82
+ tab: at === "session" ? sessionTab : "chat",
83
+ run: at === "session" && tab === "subagents" ? params.get("run") || "" : "",
84
+ };
85
+ // pattern names the one inspected, raw=1 shows its definition text; edit=1 opens its team editor, edit=new a new team;
86
+ // author=1 opens the describe-a-team composer; authorName carries the name typed there into a new editor; run names a run.
87
+ if (at === "patterns") {
88
+ const edit = params.get("edit") || "";
89
+ return {
90
+ ...base, pattern: params.get("pattern") || "", raw: params.get("raw") === "1", ...(edit ? { edit } : {}),
91
+ ...(params.get("author") === "1" ? { author: true } : {}), ...(edit && params.get("authorName") ? { authorName: params.get("authorName") } : {}),
92
+ run: params.get("run") || "",
93
+ };
94
+ }
95
+ if (at === "tasks" && isTaskId(params.get("task")))
96
+ return { ...base, task: params.get("task") };
97
+ if (at === "project" && isTaskId(params.get("composeTask")))
98
+ return { ...base, composeTask: params.get("composeTask") };
99
+ // from/to (epoch ms) cut a session's timeline to one schedule run; no other session tab reads them.
100
+ const window = at === "session" && base.tab === "activity" ? timeWindow(params) : null;
101
+ // subagent names a native run of the session whose transcript the chat pane shows (docs/phone-ui.md "Subagents").
102
+ const subagent = at === "session" && base.session && RUN_ID.test(params.get("subagent") || "") ? params.get("subagent") : "";
103
+ return { ...base, ...(window ? { window } : {}), ...(subagent ? { subagent } : {}) };
104
+ }
105
+ // The {from, to} range a hash names, or null when a bound is missing, out of order or not a positive epoch time.
106
+ function timeWindow(params) {
107
+ const from = Number(params.get("from"));
108
+ const to = Number(params.get("to"));
109
+ return Number.isSafeInteger(from) && Number.isSafeInteger(to) && from > 0 && to >= from ? { from, to } : null;
110
+ }
@@ -0,0 +1,22 @@
1
+ export const SEND_CONFIRMATION = "application/x-ndjson";
2
+ export async function readSendConfirmation(response) {
3
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
4
+ let buffer = "";
5
+ async function next() {
6
+ for (;;) {
7
+ const newline = buffer.indexOf("\n");
8
+ if (newline !== -1) {
9
+ const line = buffer.slice(0, newline);
10
+ buffer = buffer.slice(newline + 1);
11
+ return JSON.parse(line);
12
+ }
13
+ const { done, value } = await reader.read();
14
+ if (done)
15
+ throw new Error("Send confirmation ended unexpectedly");
16
+ buffer += value;
17
+ }
18
+ }
19
+ const confirmed = await next();
20
+ const followup = next().catch(() => null).finally(() => reader.cancel().catch(() => { }));
21
+ return { ...confirmed, followup };
22
+ }
@@ -0,0 +1,10 @@
1
+ // The session list's Dead fold: dead cards leave Offline into their own section, behind one tap.
2
+ // Pure, so Home and Sessions and their tests share exactly the grouping the cards render.
3
+ import { isDead } from "./session-state.js";
4
+ /** [offline cards that are not dead, dead cards], both in the tree's order; children were judged with their parent. */
5
+ export function deadSplit(tree, now) {
6
+ const offline = tree.filter(node => node.group === "offline");
7
+ const dead = offline.filter(node => isDead(node, now));
8
+ const deadIds = new Set(dead.map(node => node.project + node.id));
9
+ return [offline.filter(node => !deadIds.has(node.project + node.id)), dead];
10
+ }
@@ -0,0 +1,132 @@
1
+ // Pure session-state helpers shared by the UI server (ui.ts), the Home and Sessions views, and their tests.
2
+ import { runState } from "./activity-rows.js";
3
+ export const RECENT_MS = 60_000;
4
+ export const WORKING_MS = 15 * 60_000;
5
+ // An offline session silent this long is dead: the list keeps it folded behind a tap.
6
+ export const DEAD_MS = 24 * 60 * 60_000;
7
+ export const STATES = ["waiting", "afk", "working", "idle", "offline"];
8
+ export const STATE_LABELS = { waiting: "Waiting on you", afk: "AFK hold", working: "Working", idle: "Idle", offline: "Offline" };
9
+ const FIRST_WORDS = 6;
10
+ /** The card's online dot. A stopped OpenCode session is offline while the shared server process stays up. */
11
+ export function shownOnline(s) {
12
+ if (!s?.online)
13
+ return false;
14
+ if (s.harness === "opencode" && /^(stop|sessionend|ended)$/i.test(s.event || ""))
15
+ return false;
16
+ return true;
17
+ }
18
+ /** True when a pending item the operator can answer in the UI is open: blocking and not expired. */
19
+ export function waitingOn(pending, now) {
20
+ return (pending || []).some(p => p.blocking && !(p.expiresAt && p.expiresAt < now));
21
+ }
22
+ /**
23
+ * State of one session card from server facts:
24
+ * waiting (an open approval, choice or important question), afk (its Stop hook holds the turn in AFK mode),
25
+ * working (a running job, an open tool call under 15 min old, a running subagent, or activity in the last 60 s), idle (online), else offline.
26
+ */
27
+ export function sessionState(s, now) {
28
+ if (waitingOn(s.pending, now))
29
+ return "waiting";
30
+ if (s.runningJobs > 0)
31
+ return "working";
32
+ if (shownOnline(s) && s.afkHold)
33
+ return "afk";
34
+ if (s.openCallAt && now - s.openCallAt < WORKING_MS)
35
+ return "working";
36
+ if (s.lastActivityAt && now - s.lastActivityAt < RECENT_MS)
37
+ return "working";
38
+ if (s.subagents?.some(run => runState(run, now) === "running"))
39
+ return "working";
40
+ return shownOnline(s) ? "idle" : "offline";
41
+ }
42
+ /** The wake to show for a session, or null once it reported after the wake began or the wake is no longer running. */
43
+ const LIVE = new Set(["waiting", "afk", "working"]);
44
+ /** True when the chat would show this session as waiting, held, or working, not idle or offline. */
45
+ export function isLive(s, now) {
46
+ return LIVE.has(sessionState(s, now));
47
+ }
48
+ /** True when All sessions keeps this group open. Idle and offline stay in the collapsed inactive section. */
49
+ export function isOpenGroup(group) {
50
+ return LIVE.has(group);
51
+ }
52
+ /** Open-list cards by group, and idle roots that fold into the inactive section. Offline stays out of both. */
53
+ export function listedGroups(tree) {
54
+ const open = new Map(STATES.filter(isOpenGroup).map(group => [group, []]));
55
+ const idle = [];
56
+ for (const node of tree) {
57
+ if (isOpenGroup(node.group))
58
+ open.get(node.group).push(node);
59
+ else if (node.group === "idle")
60
+ idle.push(node);
61
+ }
62
+ return { open, idle };
63
+ }
64
+ /** A project's sessions as running (a live turn) and off (idle or offline) for its sidebar row. */
65
+ export function sessionCounts(agents, now = Date.now()) {
66
+ const running = agents.filter((agent) => isLive(agent, now)).length;
67
+ return { running, inactive: agents.length - running };
68
+ }
69
+ export function visibleWake(wake, agent) {
70
+ if (!wake?.status)
71
+ return null;
72
+ const reported = Math.max(agent?.seenAt || 0, agent?.statusAt || 0);
73
+ if (wake.at && reported > wake.at)
74
+ return null;
75
+ // A wake whose session is back online needs no banner, waking or finished; a failed one keeps its Retry.
76
+ if (agent?.online && wake.status !== "failed")
77
+ return null;
78
+ return wake;
79
+ }
80
+ /** "<folder>: first words of the first prompt", the folder alone, or "". */
81
+ export function fallbackName(folder, prompt) {
82
+ const words = typeof prompt === "string" ? prompt.replace(/\s+/g, " ").trim().split(" ").slice(0, FIRST_WORDS).join(" ") : "";
83
+ return [folder, words].filter(Boolean).join(": ").slice(0, 80);
84
+ }
85
+ /** When the card, or any session nested under it, was last active (ms). */
86
+ export function lastSeenAt(node) {
87
+ return Math.max(node.seenAt || 0, node.lastActivityAt || 0, ...(node.children || []).map(lastSeenAt));
88
+ }
89
+ /** A card offline for a day is dead: still listed, but behind one tap so live work stays on screen. */
90
+ export function isDead(node, now) {
91
+ return (node.group || node.state) === "offline" && now - lastSeenAt(node) >= DEAD_MS;
92
+ }
93
+ /** Cards ordered by state, then newest activity; children whose parent is listed nest under it and lift its group. */
94
+ export function sessionTree(sessions, now, { separateOffline = false } = {}) {
95
+ const byId = new Map(sessions.map(s => [s.id, { ...s, state: sessionState(s, now), children: [] }]));
96
+ const roots = [];
97
+ for (const node of byId.values()) {
98
+ const parent = node.parent && node.parent !== node.id ? byId.get(node.parent) : null;
99
+ if (parent && (!separateOffline || (node.state === "offline") === (parent.state === "offline")) && !isAncestor(byId, node.id, parent.id))
100
+ parent.children.push(node);
101
+ else
102
+ roots.push(node);
103
+ }
104
+ const rank = node => Math.min(STATES.indexOf(node.state), ...node.children.map(rank));
105
+ const recent = node => Math.max(node.seenAt || 0, node.lastActivityAt || 0, ...node.children.map(recent));
106
+ const order = list => list.sort((a, b) => rank(a) - rank(b) || recent(b) - recent(a) || a.id.localeCompare(b.id)).forEach(n => order(n.children));
107
+ order(roots);
108
+ for (const node of roots)
109
+ node.group = STATES[rank(node)];
110
+ return roots;
111
+ }
112
+ // True when id is parentId or one of its ancestors, which would make a cycle.
113
+ function isAncestor(byId, id, parentId) {
114
+ for (let at = parentId, seen = 0; at && seen < 50; seen++) {
115
+ if (at === id)
116
+ return true;
117
+ at = byId.get(at)?.parent;
118
+ }
119
+ return false;
120
+ }
121
+ /**
122
+ * Whether the Stop button shows: a turn the runner holds is running, or a working session can take an interrupt
123
+ * (any runner-held harness; outside the runner only Codex and OpenCode, lib/sessions/control.ts interruptSession).
124
+ */
125
+ export function canStop(s, now) {
126
+ if (s.runnerStatus === "running")
127
+ return true;
128
+ if (sessionState(s, now) !== "working")
129
+ return false;
130
+ const peer = String(s.id || "").split("#")[0];
131
+ return Boolean(s.runnerStatus) || (shownOnline(s) && ["codex", "opencode"].includes(peer));
132
+ }
@@ -0,0 +1,15 @@
1
+ // The sidebar's agent list: sessions that set an identity name, the PM first, then the rest alphabetically.
2
+ const PM = /^pm$/i;
3
+ /** The set_identity name of a session, or "" when it only has a harness title or a fallback name. */
4
+ export function agentName(agent) {
5
+ return typeof agent?.identityName === "string" ? agent.identityName.trim() : "";
6
+ }
7
+ /** Sessions with a set_identity name, PM first, then by name; each opens its own direct chat. */
8
+ export function namedAgents(agents = []) {
9
+ return agents.filter(agent => agentName(agent))
10
+ .sort((a, b) => Number(PM.test(agentName(b))) - Number(PM.test(agentName(a))) || agentName(a).localeCompare(agentName(b)) || a.id.localeCompare(b.id));
11
+ }
12
+ /** The rest of the project's sessions, in the order the server sent them. */
13
+ export function unnamedAgents(agents = []) {
14
+ return agents.filter(agent => !agentName(agent));
15
+ }
@@ -0,0 +1,164 @@
1
+ // Slash commands the phone sends to a session, and what each harness supports. Shared by the server and the composer.
2
+ // Statuses: "supported" (verified in the harness source, binary or schema), "partial" (works for some session states only),
3
+ // "unverified" (documented, effect not checked), "unsupported" (no channel, or refused).
4
+ import { CLAUDE_CLI_MODES, CLAUDE_PERMISSION_SUMMARIES, CLAUDE_PERMISSION_VALUES, RUNNER_MODE_SUMMARIES, RUNNER_PERMISSION_MODES } from "./permission-modes.js";
5
+ export const NAME = /^[a-z][a-z0-9-]{0,31}$/;
6
+ // "/name word word partial": the words already typed after a command name, then the one being typed.
7
+ const TYPING_ARGS = /^\/([a-z][a-z0-9-]{0,31})\s+((?:\S+\s+)*)(\S*)$/i;
8
+ export const COMMANDS = [
9
+ { name: "compact", summary: "Compact the context" },
10
+ { name: "model", summary: "Switch the model", args: "<model>" },
11
+ { name: "clear", summary: "Start a new context" },
12
+ { name: "permission", summary: "Permission mode for the next start or wake", args: "<mode>" },
13
+ { name: "mode", summary: "Change a live session's permission mode", args: "<mode>" },
14
+ { name: "team-permission", summary: "Permission mode for a team, after you confirm", args: "<team> <mode>" },
15
+ { name: "afk", summary: "AFK mode for every project", args: "<on|off|quiet>" },
16
+ ];
17
+ const supported = (reason) => ({ status: "supported", reason });
18
+ const partial = (reason) => ({ status: "partial", reason });
19
+ const unverified = (reason) => ({ status: "unverified", reason });
20
+ const unsupported = (reason) => ({ status: "unsupported", reason });
21
+ // "passthrough" applies to any typed /name that is not in COMMANDS.
22
+ export const SUPPORT = {
23
+ claude: {
24
+ compact: partial("A runner-owned session compacts in place: /compact on its live query. A terminal session compacts through the Agent SDK when saved, or gets a request to finish its step, then /compact in its terminal."),
25
+ model: partial("Runner-owned sessions only: the runner switches the live session's model (Claude's list; a bare name such as sonnet, or anthropic/<model>). A terminal session refuses: start it from temmo to switch models."),
26
+ permission: supported("Runner modes (supervised, accept-edits, auto, full-access) or auto-afk; Claude's default, acceptEdits and bypassPermissions map onto them. A runner-owned session changes now, as /mode does; a terminal session stores the mode for its next start or wake (--permission-mode). full-access runs only in OpenShell unless the host allows it."),
27
+ mode: partial("Runner-owned sessions only: the runner changes the live session's mode (supervised, accept-edits, auto, full-access; Claude names map)."),
28
+ "team-permission": supported("Asks the operator to Apply or Cancel on a phone card; Apply rewrites team.dot."),
29
+ clear: unsupported("No clear is documented for Claude's messaging socket."),
30
+ afk: supported("Sets AFK mode for every project, as the sidebar switch does; the session itself is not involved."),
31
+ passthrough: unsupported("The socket wraps each message in a cross-session envelope, so /name reaches Claude as text, not a command."),
32
+ },
33
+ codex: {
34
+ compact: partial("A runner-owned session compacts in place with thread/compact/start. A terminal session compacts the thread when it is loaded and idle in the app-server daemon, or a saved thread; otherwise it gets a request."),
35
+ model: unsupported("app-server sets the model per turn (turn/start), not on a thread, so it cannot change the model alone."),
36
+ clear: unsupported("thread/start creates a new thread id; this session keeps its id."),
37
+ permission: partial("Runner-owned sessions only: the mode changes now, as /mode does (supervised, accept-edits, auto, full-access, or auto-afk; Claude's names map). A terminal Codex session has no stored mode."),
38
+ mode: partial("Runner-owned sessions only: the runner changes the live session's mode (supervised, accept-edits, auto, full-access; Claude names map)."),
39
+ "team-permission": supported("Asks the operator to Apply or Cancel on a phone card; Apply rewrites team.dot."),
40
+ afk: supported("Sets AFK mode for every project, as the sidebar switch does; the session itself is not involved."),
41
+ passthrough: unsupported("No app-server method runs a slash command. Sending it as a turn is unverified."),
42
+ },
43
+ opencode: {
44
+ compact: supported("POST /api/session/{id}/compact (operation session.compact in the OpenCode binary)."),
45
+ model: unverified("POST /api/session/{id}/model (session.switchModel). The body {providerID, modelID} is not checked against a live service."),
46
+ clear: unsupported("POST /api/session creates another session; this one keeps its id."),
47
+ permission: partial("Runner-owned sessions only: the mode changes now, as /mode does (supervised, accept-edits, full-access, or auto-afk; Claude's names map). A terminal OpenCode session has no stored mode."),
48
+ mode: partial("Runner-owned sessions only: the runner changes the live session's mode (supervised, accept-edits, auto, full-access; Claude names map)."),
49
+ "team-permission": supported("Asks the operator to Apply or Cancel on a phone card; Apply rewrites team.dot."),
50
+ afk: supported("Sets AFK mode for every project, as the sidebar switch does; the session itself is not involved."),
51
+ passthrough: unverified("POST /api/session/{id}/command (session.command). The body {command, arguments} is not checked against a live service."),
52
+ },
53
+ pi: {
54
+ compact: partial("A runner-owned session compacts in place with the rpc compact command."),
55
+ model: partial("Runner-owned sessions only: the runner switches the model with the rpc set_model command (provider/model). A terminal pi session has no route to its model."),
56
+ clear: unsupported("rpc new_session gives the session a new id; this session keeps its id."),
57
+ permission: partial("Runner-owned sessions only: the mode changes now, as /mode does (supervised, accept-edits, full-access, or auto-afk; Claude's names map). A terminal pi session has no stored mode."),
58
+ mode: partial("Runner-owned sessions only: the runner changes which tools the temmo extension asks about (supervised, accept-edits, full-access)."),
59
+ "team-permission": supported("Asks the operator to Apply or Cancel on a phone card; Apply rewrites team.dot."),
60
+ passthrough: unsupported("Not wired: rpc prompt runs a /command, but the phone sends no command to a runner-owned pi session."),
61
+ },
62
+ cursor: {
63
+ compact: unsupported("No outside compaction trigger. The Compact button sends the session a request instead."),
64
+ model: partial("Runner-owned sessions only: the runner switches the model over ACP (session/set_config_option, else session/set_model); not yet checked against a live cursor-agent. A terminal session has no control channel."),
65
+ clear: unsupported("cursor-agent exposes no control channel for a running session (--resume and --print only)."),
66
+ permission: unsupported("cursor-agent cannot change its permission mode while open, and a terminal Cursor session has no stored mode."),
67
+ mode: unsupported("cursor-agent cannot change its permission mode while open."),
68
+ "team-permission": supported("Asks the operator to Apply or Cancel on a phone card; Apply rewrites team.dot."),
69
+ afk: supported("Sets AFK mode for every project, as the sidebar switch does; the session itself is not involved."),
70
+ passthrough: unsupported("cursor-agent exposes no control channel for a running session (--resume and --print only)."),
71
+ },
72
+ };
73
+ /** {name, args} for a message that starts with /name, else null. */
74
+ export function parseCommand(text) {
75
+ const found = /^\/([a-z][a-z0-9-]{0,31})(?:\s+([\s\S]*))?$/i.exec(String(text).trim());
76
+ return found ? { name: found[1].toLowerCase(), args: (found[2] || "").trim() } : null;
77
+ }
78
+ /**
79
+ * The parsed command for a composer message, or null when the message is chat. Only a first word that names a known
80
+ * command, or one the picker inserted (picked: a Set of names), makes it a command: "/home/x is broken" stays chat.
81
+ */
82
+ export function commandFor(text, picked = new Set()) {
83
+ const parsed = parseCommand(text);
84
+ if (!parsed)
85
+ return null;
86
+ const known = COMMANDS.some(command => command.name === parsed.name);
87
+ return known || picked.has(parsed.name) ? parsed : null;
88
+ }
89
+ /** The support entry {status, reason} for a harness and command name; unknown names use passthrough. */
90
+ export function commandSupport(harness, name) {
91
+ const table = SUPPORT[harness];
92
+ if (!table)
93
+ return unsupported("Unknown harness.");
94
+ return table[name] ?? table.passthrough;
95
+ }
96
+ /**
97
+ * Entries for the composer picker: known commands whose name starts with prefix, each with its support for the harness.
98
+ * When no known command matches a valid name, the typed name itself is offered as a passthrough command.
99
+ */
100
+ export function matchCommands(harness, prefix) {
101
+ const typed = prefix.toLowerCase();
102
+ const known = COMMANDS.filter(command => command.name.startsWith(typed))
103
+ .map(command => ({ ...command, ...commandSupport(harness, command.name) }));
104
+ if (known.length || !NAME.test(typed))
105
+ return known;
106
+ return [{ name: typed, summary: "Send /" + typed + " to the session", ...commandSupport(harness, typed) }];
107
+ }
108
+ const claudeValues = () => CLAUDE_PERMISSION_VALUES.map(value => ({ value, summary: CLAUDE_PERMISSION_SUMMARIES[value] }));
109
+ // The values /mode accepts for a harness: its runner modes, and for Claude the Claude names the runner maps onto them.
110
+ function modeValues(harness) {
111
+ const modes = RUNNER_PERMISSION_MODES[harness] ?? [];
112
+ const aliases = harness === "claude" ? Object.entries(CLAUDE_CLI_MODES).filter(([name, mode]) => name !== mode && modes.includes(mode)) : [];
113
+ return [...modes.map(value => ({ value, summary: RUNNER_MODE_SUMMARIES[value] })),
114
+ ...aliases.map(([value, mode]) => ({ value, summary: "Claude's name for " + mode }))];
115
+ }
116
+ // The values /permission accepts for a harness: its runner modes, auto-afk, and the Claude names that map onto them.
117
+ function permissionValues(harness) {
118
+ const modes = RUNNER_PERMISSION_MODES[harness] ?? [];
119
+ const aliases = Object.entries(CLAUDE_CLI_MODES).filter(([name, mode]) => name !== mode && modes.includes(mode));
120
+ return [...modes.map(value => ({ value, summary: RUNNER_MODE_SUMMARIES[value] })),
121
+ { value: "auto-afk", summary: "supervised while AFK is on; a terminal session's own Claude settings otherwise" },
122
+ ...aliases.map(([value, mode]) => ({ value, summary: "Claude's name for " + mode }))];
123
+ }
124
+ // Tags the option equal to the session's live mode, so a picker can mark the current level; no tag when the mode is unknown.
125
+ function markCurrent(options, current) {
126
+ return current ? options.map(option => (option.value === current ? { ...option, current: true } : option)) : options;
127
+ }
128
+ // The values for argument index of a command: teams [{name, description?}] and models [id] come from the composer's data.
129
+ function argValues(name, index, harness, { teams = [], models = [], mode = {} } = {}) {
130
+ switch (name + ":" + index) {
131
+ case "permission:0": return markCurrent(permissionValues(harness), mode.current);
132
+ case "mode:0": return markCurrent(modeValues(harness), mode.current);
133
+ case "team-permission:0": return teams.map(team => ({ value: team.name, summary: team.description || "" }));
134
+ case "team-permission:1": return claudeValues();
135
+ case "model:0": return models.map(value => ({ value, summary: "" }));
136
+ default: return [];
137
+ }
138
+ }
139
+ /**
140
+ * Suggestions for the argument being typed after a known command, or null when text is not "/command " plus arguments.
141
+ * {command, options}: command is the entry with its support for the harness; options are {value, summary, text}, where
142
+ * text is the draft with the value inserted. An unsupported command, or one with every argument typed, has no options.
143
+ */
144
+ export function matchArgs(harness, text, data = {}) {
145
+ const found = TYPING_ARGS.exec(text);
146
+ const known = found && COMMANDS.find(command => command.name === found[1].toLowerCase());
147
+ if (!known?.args)
148
+ return null;
149
+ const command = { ...known, ...commandSupport(harness, known.name) };
150
+ const done = found[2].trim() ? found[2].trim().split(/\s+/) : [];
151
+ const slots = known.args.split(" ").length;
152
+ if (command.status === "unsupported" || done.length >= slots)
153
+ return { command, options: [] };
154
+ const typed = found[3];
155
+ const head = text.slice(0, text.length - typed.length);
156
+ const tail = done.length < slots - 1 ? " " : "";
157
+ const options = argValues(known.name, done.length, harness, data)
158
+ .filter(option => option.value.toLowerCase().startsWith(typed.toLowerCase()))
159
+ .map(option => ({ ...option, text: head + option.value + tail }));
160
+ // A value typed in full needs no suggestion.
161
+ if (options.length === 1 && options[0].value === typed)
162
+ return { command, options: [] };
163
+ return { command, options };
164
+ }
@@ -0,0 +1,35 @@
1
+ // New-session defaults from the configured startDefault: the old @harness:model prefill, and the picker's opening choice.
2
+ /** The models one harness lists, dropping anything that is not a name. */
3
+ export const modelsOf = (models, harness) => (Array.isArray(models?.[harness]) ? models[harness].filter(id => typeof id === "string" && id) : []);
4
+ /** "@harness:model " for the configured default, "@harness " for the first available harness, or "" when none can start. */
5
+ export function startDefaultDraft({ startable = [], models = {}, setting = {} }) {
6
+ const { harness, model } = setting;
7
+ if (startable.includes(harness)) {
8
+ // Models not loaded yet: keep the configured default; once loaded, it must list the model.
9
+ const known = Array.isArray(models[harness]) ? models[harness] : null;
10
+ if (!known || known.includes(model))
11
+ return `@${harness}:${model} `;
12
+ }
13
+ return startable.length ? `@${startable[0]} ` : "";
14
+ }
15
+ /**
16
+ * What the new-agent dialogue opens on: the configured harness and model when that harness can start here and lists
17
+ * the model (or has not loaded yet), else the first startable harness with its first listed model. The harness is
18
+ * carried by this choice, so the picker needs no @tag typed into the prompt.
19
+ */
20
+ export function initialChoice({ startable = [], models = {}, setting = {} }) {
21
+ const first = harness => modelsOf(models, harness)[0] || "";
22
+ const harness = typeof setting?.harness === "string" ? setting.harness : "";
23
+ const model = typeof setting?.model === "string" ? setting.model : "";
24
+ if (startable.includes(harness)) {
25
+ // Models not loaded yet: keep the configured model; once loaded, the harness must list it.
26
+ const known = Array.isArray(models?.[harness]);
27
+ if (!model)
28
+ return { harness, model: first(harness) };
29
+ if (!known || models[harness].includes(model))
30
+ return { harness, model };
31
+ return { harness, model: first(harness) };
32
+ }
33
+ const fallback = startable[0] || "";
34
+ return { harness: fallback, model: fallback ? first(fallback) : "" };
35
+ }
@@ -0,0 +1,35 @@
1
+ // The new-agent dialogue's mode pill: Agent / Ask / Plan, and the argv each harness gets for it.
2
+ // Only modes a harness documents are offered; a harness without a plan or ask mode lists neither.
3
+ // Verified read-only from the installed CLIs (`--help` and their bundles), never by running an agent:
4
+ // claude --permission-mode <mode>, with "plan" among the accepted modes
5
+ // codex -s, --sandbox read-only (a read-only sandbox: analysis and plans, no edits)
6
+ // cursor --mode <mode>, choices "plan" and "ask" (both read-only)
7
+ // opencode --agent <name>; its built-in "plan" primary agent plans before implementing
8
+ /** Pill labels, in the order the menu lists them. `agent` is the normal, editing mode. */
9
+ export const MODE_LABELS = { agent: "Agent", ask: "Ask", plan: "Plan" };
10
+ /** The modes each harness starts in; "agent" needs no flag. */
11
+ export const START_MODES = {
12
+ claude: ["agent", "plan"],
13
+ codex: ["agent", "plan"],
14
+ cursor: ["agent", "ask", "plan"],
15
+ opencode: ["agent", "plan"],
16
+ pi: ["agent"],
17
+ };
18
+ /** Modes the harness can start in, in pill order; none for an unknown harness. */
19
+ export function startModes(harness) {
20
+ return START_MODES[harness] || [];
21
+ }
22
+ /** Extra argv for a mode, [] for the normal mode, null when the harness has no such mode. */
23
+ export function modeFlags(harness, mode = "agent") {
24
+ if (!mode || mode === "agent")
25
+ return startModes(harness).includes("agent") ? [] : null;
26
+ if (!startModes(harness).includes(mode))
27
+ return null;
28
+ switch (harness) {
29
+ case "claude": return ["--permission-mode", "plan"];
30
+ case "codex": return ["-s", "read-only"];
31
+ case "cursor": return ["--mode", mode];
32
+ case "opencode": return ["--agent", "plan"];
33
+ default: return null;
34
+ }
35
+ }
@@ -0,0 +1,49 @@
1
+ import { createMemory } from "./view-memory.js";
2
+ // Screens kept warm, newest use first: switching back and forth between them never waits for the server.
3
+ const RECENT_STREAMS = 6;
4
+ export const ACTIVITY_MAX = 500;
5
+ /** One ACTIVITY_BATCH: a reset replaces the rows, an append follows them, and the newest ACTIVITY_MAX stay. */
6
+ export function mergeActivity(activity, { reset, items }) {
7
+ return (reset ? items : [...activity, ...items]).slice(-ACTIVITY_MAX);
8
+ }
9
+ /**
10
+ * The last view of each recent /api/events stream: its state snapshot, activity rows and A2UI surfaces. A screen
11
+ * switched back to renders this at once, then its reconnected stream replaces it with the current state.
12
+ */
13
+ export function createStreamViews(limit = RECENT_STREAMS) {
14
+ const memory = createMemory(limit);
15
+ // Reading a view makes it the most recent, so a screen the operator keeps returning to is never the one dropped.
16
+ const remember = key => {
17
+ const view = memory.get(key);
18
+ if (view !== undefined)
19
+ memory.set(key, view);
20
+ return view;
21
+ };
22
+ return {
23
+ restore: remember,
24
+ /**
25
+ * The reducer for one stream's frames, returning the view to render. Frames update the cached view in place, so
26
+ * surfaces go before each state frame, a full activity reset follows it, and a reconnect never blanks a screen.
27
+ * A frame that arrives before this screen's first state snapshot has no view to render, so it only caches.
28
+ */
29
+ connect(key) {
30
+ let view = remember(key);
31
+ return (event, data) => {
32
+ if (event === "state")
33
+ view = { ...view, data };
34
+ else if (event === "surface")
35
+ view = { ...view, surfaces: { ...view?.surfaces, [data.id]: data.operations } };
36
+ else if (event === "activity")
37
+ view = { ...view, activity: mergeActivity(view?.activity ?? [], data) };
38
+ else
39
+ return undefined;
40
+ if (!view?.data)
41
+ return undefined;
42
+ const stored = { data: view.data, activity: view.activity ?? [], surfaces: view.surfaces ?? {} };
43
+ memory.set(key, stored);
44
+ return stored;
45
+ };
46
+ },
47
+ };
48
+ }
49
+ export const streamViews = createStreamViews();
@@ -0,0 +1,20 @@
1
+ // Pure subagent-run state for the Subagents view: running, finished or stale.
2
+ import { runState } from "./activity-rows.js";
3
+ export const STALE_MS = 10 * 60_000;
4
+ export const IDLE_HIDE_MS = 30 * 60_000;
5
+ export const SUBAGENT_LABELS = { running: "Running", finished: "Finished", stale: "Stale" };
6
+ /** finished when a stop was seen (run.done); else running with activity in the last 10 min, else stale. */
7
+ export function subagentState(run, now) {
8
+ if (run.done)
9
+ return "finished";
10
+ return now - (run.lastTime ?? run.time) * 1000 < STALE_MS ? "running" : "stale";
11
+ }
12
+ /** Count of runs the browser counts as running (runState). */
13
+ export function runningCount(runs, now) {
14
+ return runs.filter(run => runState(run, now) === "running").length;
15
+ }
16
+ /** Runs to show, and the idle ones older than IDLE_HIDE_MS that the "Show N idle" toggle hides. */
17
+ export function splitIdleRuns(runs, now) {
18
+ const hidden = run => runState(run, now) !== "running" && now - (run.lastTime ?? run.time) * 1000 > IDLE_HIDE_MS;
19
+ return { shown: runs.filter(run => !hidden(run)), idle: runs.filter(hidden) };
20
+ }