@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,61 @@
1
+ "use client";
2
+
3
+ import { FileInput, FileInputDropzone, FileInputTrigger } from "@ui-sdk/react/file-input";
4
+ import { useEffect, useState, type ReactNode } from "react";
5
+ import { Paperclip, X } from "lucide-react";
6
+ import { Button } from "@/components/ui/button";
7
+ import { cn } from "@/lib/utils";
8
+
9
+ const MAX_IMAGE_BYTES = 15 * 1024 * 1024;
10
+ const IMAGE_TYPES = [".png", ".jpg", ".jpeg", ".gif", ".webp"];
11
+
12
+ export function ImagePicker({ files, onChange, onError, disabled, children }: {
13
+ files: File[];
14
+ onChange: (files: File[]) => void;
15
+ onError: (message: string) => void;
16
+ disabled: boolean;
17
+ children: ReactNode;
18
+ }) {
19
+ return <FileInput name="image" value={files} onValueChange={onChange} disabled={disabled}
20
+ accept={IMAGE_TYPES} maxSize={MAX_IMAGE_BYTES} minSize={1}
21
+ onReject={([file]) => onError(file?.reasons.includes("file-too-large") ? "Choose an image up to 15 MB." : "Choose a PNG, JPEG, GIF, or WebP image.")}>
22
+ <FileInputDropzone pasteTarget="#composer" className="rounded-3xl data-drag-accept:outline-2 data-drag-accept:outline-ring">
23
+ {children}
24
+ </FileInputDropzone>
25
+ </FileInput>;
26
+ }
27
+
28
+ export function AttachImageButton({ replacing }: { replacing: boolean }) {
29
+ const label = replacing ? "Replace image" : "Attach image";
30
+ return <FileInputTrigger aria-label={label} title={label}
31
+ render={<Button variant="ghost" size="icon" className="size-11 rounded-md sm:size-8"/>}>
32
+ <Paperclip aria-hidden="true"/>
33
+ </FileInputTrigger>;
34
+ }
35
+
36
+ export function ChatImage({ attachment, compact = false }: { attachment: { file: string; name: string }; compact?: boolean }) {
37
+ const src = "/api/file/" + encodeURIComponent(attachment.file);
38
+ const [unavailable, setUnavailable] = useState(false);
39
+ return <a href={src} target="_blank" rel="noreferrer"
40
+ className="block w-fit max-w-full overflow-hidden rounded-xl bg-card shadow-surface focus-visible:outline-2 focus-visible:outline-ring">
41
+ {!unavailable && <img src={src} alt="" loading="lazy" onError={() => setUnavailable(true)}
42
+ className={cn("w-auto max-w-full object-contain", compact ? "max-h-20" : "max-h-96")}/>}
43
+ <span className="block break-all px-3 py-1.5 text-sm underline">{attachment.name}</span>
44
+ {unavailable && <span className="block px-3 pb-1.5 text-xs text-muted-foreground">Image unavailable</span>}
45
+ </a>;
46
+ }
47
+
48
+ export function ImageDraft({ file, disabled, remove }: { file: File; disabled: boolean; remove: () => void }) {
49
+ const [src, setSrc] = useState("");
50
+ useEffect(() => {
51
+ const url = URL.createObjectURL(file);
52
+ setSrc(url);
53
+ return () => URL.revokeObjectURL(url);
54
+ }, [file]);
55
+ return <div className="mx-1 mb-1 flex min-w-0 items-center gap-2 rounded-xl border px-2">
56
+ {src && <img src={src} alt="" className="size-10 shrink-0 rounded-md object-contain"/>}
57
+ <span className="min-w-0 flex-1 truncate text-sm" title={file.name}>{file.name}</span>
58
+ <Button type="button" variant="ghost" size="icon" className="size-11 sm:size-8" disabled={disabled}
59
+ aria-label="Remove image" onClick={remove}><X aria-hidden="true"/></Button>
60
+ </div>;
61
+ }
@@ -0,0 +1,122 @@
1
+ "use client";
2
+ // One chat message bubble and its header row (receipts, reply, badges), plus the project chat's
3
+ // completion and live rows that ride the same thread.
4
+ import { useMemo, useState } from "react";
5
+ import { MessagePrimitive } from "@assistant-ui/react";
6
+ import { Check, CheckCheck, CircleCheck, LoaderCircle, Reply, Zap } from "lucide-react";
7
+ import { Badge } from "@/components/ui/badge";
8
+ import { BubbleContext, BubbleText } from "@/components/chat/thread";
9
+ import { Button } from "@/components/ui/button";
10
+ import { remarkPluginsFor } from "@/components/ui/markdown";
11
+ import { cn } from "@/lib/utils";
12
+ import { withMentions } from "@/lib/mentions";
13
+ import { ChatImage } from "./chat-image";
14
+ import { ApprovalCard, PrCard, QuestionCard } from "./cards";
15
+ import { Quote } from "./quote";
16
+ import { Avatar, ago, clock, short } from "./chat-shared";
17
+
18
+ const RECEIPTS = { sent: ["Sent", Check], delivered: ["Read by some sessions", CheckCheck], read: ["Read", CheckCheck] };
19
+
20
+ // WhatsApp-style ticks on the operator's own messages: ✓ sent, ✓✓ read by some (broadcast), primary ✓✓ read.
21
+ function Ticks({ state }) {
22
+ const [label, Icon] = RECEIPTS[state] || [];
23
+ if (!Icon) return null;
24
+ return <span role="img" aria-label={label} title={label} data-receipt={state}
25
+ className={cn("inline-flex", state === "read" ? "text-primary" : "text-muted-foreground")}><Icon className="size-3.5"/></span>;
26
+ }
27
+
28
+ export function QueueRow({ message, disabled, change }) {
29
+ const [draft, setDraft] = useState(null);
30
+ return <li className="flex flex-wrap items-center gap-2 border-t px-3 py-2 text-sm">
31
+ {draft === null ? <>
32
+ <div className="min-w-0 flex-1">
33
+ {message.body && <p className="truncate" title={message.body}>{message.body}</p>}
34
+ {message.attachment && <ChatImage attachment={message.attachment} compact/>}
35
+ </div>
36
+ <Button type="button" variant="ghost" size="sm" disabled={disabled} onClick={() => setDraft(message.body)}>Edit</Button>
37
+ <Button type="button" variant="ghost" size="sm" disabled={disabled} onClick={() => change(message, "cancel")}>Cancel</Button>
38
+ <Button type="button" variant="ghost" size="sm" disabled={disabled} onClick={() => change(message, "steer")}>Retry delivery</Button>
39
+ </> : <form className="flex w-full flex-wrap items-center gap-2" onSubmit={async event => {
40
+ event.preventDefault();
41
+ if (await change(message, "edit", draft)) setDraft(null);
42
+ }}>
43
+ <textarea aria-label="Edit queued message" className="w-full rounded border bg-background p-2" autoFocus value={draft} maxLength={16000} onChange={event => setDraft(event.target.value)}/>
44
+ <Button type="submit" size="sm" disabled={disabled || !draft.trim()}>Save</Button>
45
+ <Button type="button" variant="ghost" size="sm" onClick={() => setDraft(null)}>Discard edit</Button>
46
+ </form>}
47
+ </li>;
48
+ }
49
+
50
+ export function ChatMessage({ message, operator, me, now, replyFrom, open, act, setMode, answer, skip, disabled, detail, name, taskLinks }) {
51
+ const bubble = useMemo(() => ({ plugins: remarkPluginsFor(taskLinks) }), [taskLinks]);
52
+ const sender = message.from || message.sender || "ntfy";
53
+ const outgoing = sender === operator;
54
+ // Channel posts (operator broadcasts, phone replies) travel as "ntfy" on the wire; readers see them as the operator's.
55
+ const shown = sender === "ntfy" ? "operator" : sender;
56
+ // A signed-in family member's message names them; the viewer's own stays "You".
57
+ const other = message.by && message.by !== me ? message.by : "";
58
+ const who = message.by || name || short(shown);
59
+ const label = message.system ? "System" : ["Question", "Reply", "Approval"].includes(message.kind) ? message.kind + " · " + who : who;
60
+ const at = message.time ? message.time * 1000 : 0;
61
+ // An agent's avatar and name open its session (or harness) view; the operator's own, system and channel posts stay plain.
62
+ const openable = !outgoing && sender !== "ntfy" && sender !== "operator" && sender !== "system";
63
+ const go = () => open(sender);
64
+ // A reply to an agent prefills its address so the mention routes the reply to that session.
65
+ const prefill = openable ? "@" + sender + " " : "";
66
+ // The asking agent's avatar and name, the header row of an approval card; a question card leaves them to the message header.
67
+ const cardHead = <><Avatar address={sender} by={other} className="size-6 text-xs"/><span className="truncate" title={sender}>{name || short(sender)}</span></>;
68
+ // Cards take the whole row on a phone, so long option descriptions wrap less.
69
+ const card = message.kind === "Approval" || message.kind === "CreatePr" || (message.kind === "Question" && Boolean(message.question));
70
+ return <MessagePrimitive.Root data-message-id={message.id} data-reply-id={message.replyId} className={cn("flex max-w-full gap-3", outgoing && "flex-row-reverse")}
71
+ onClick={event => { const tag = event.target.closest?.("[data-mention]"); if (tag) open(tag.textContent.replace(/^@/, "").split(/[:/]/)[0]); }}>
72
+ {openable ? <button type="button" aria-label={"Open avatar " + sender} tabIndex={-1} className="shrink-0 self-start rounded-md" onClick={go}><Avatar address={sender}/></button> : <Avatar address={shown} by={other}/>}
73
+ <div className={cn("flex min-w-0 flex-col gap-1", card ? "flex-1 sm:max-w-[82%]" : "max-w-[82%]", outgoing ? "items-end" : "items-start")}>
74
+ <div className="flex max-w-full flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground">
75
+ {openable ? <button type="button" aria-label={"Open " + sender} title={sender} onClick={go}
76
+ className="font-medium text-foreground underline-offset-2 hover:underline">{label}</button>
77
+ : <span className="font-medium text-foreground" title={message.by ? shown + " · " + message.by : shown}>{outgoing ? other || "You" : label}</span>}
78
+ {detail && <span data-agent-detail className="text-xs text-muted-foreground">{"· " + detail}</span>}
79
+ {message.to && message.to !== "all" && (message.to.includes("#") && message.to !== operator
80
+ ? <button type="button" title={message.to} aria-label={"Open " + message.to} onClick={() => open(message.to)} className="underline-offset-2 hover:underline">→ {short(message.to)}</button>
81
+ : <span title={message.to}>→ {short(message.to)}</span>)}
82
+ {message.terminal && <Badge variant="outline" data-terminal title="Typed in the agent's terminal" className="h-4 px-1.5 text-xs">terminal</Badge>}
83
+ {message.replyTo && <Badge variant="outline" data-answer title={"Answers question " + message.replyTo} className="h-4 px-1.5 text-xs">answer</Badge>}
84
+ {at > 0 && <time dateTime={new Date(at).toISOString()} title={clock.format(at)}>{ago(at, now)}</time>}
85
+ {replyFrom && message.kind !== "Approval" && message.kind !== "Question" && <button type="button" data-tap aria-label={"Reply to " + sender} title="Reply" onClick={() => replyFrom({ id: message.replyId || message.id, sender, prefill, body: message.body })}
86
+ className="rounded-md p-0.5 hover:bg-muted hover:text-foreground"><Reply className="size-3.5"/></button>}
87
+ {message.scope === "all" && <Badge variant="secondary" className="h-4 px-1.5 text-xs">to all</Badge>}
88
+ {message.urgent && !message.cancelled && <span role="img" aria-label="Sent now" title="Sent now: delivered at the agent's next tool call" data-urgent className="text-primary"><Zap className="size-3.5"/></span>}
89
+ {outgoing && (message.queueStatus ? <span>{message.queueStatus}</span> : <Ticks state={message.receipt}/>)}
90
+ </div>
91
+ {message.quote && <Quote quote={message.quote} label={short(message.quote.sender)}/>}
92
+ {message.kind === "Approval" ? <ApprovalCard approval={message.approval} now={now} disabled={disabled} act={act} skip={skip} setMode={setMode} head={cardHead}/>
93
+ : message.kind === "CreatePr" && message.createPr ? <PrCard createPr={message.createPr}/>
94
+ : message.kind === "Question" && message.question ? <QuestionCard question={message.question} body={withMentions(message.body)} taskLinks={taskLinks} answer={message.answer} by={message.answeredBy} skipped={message.skipped} disabled={disabled} onAnswer={body => answer(message.question, body)} skip={skip}/>
95
+ : (message.body || !message.attachment) && <BubbleContext.Provider value={bubble}>
96
+ <div className={cn("bubble max-w-full rounded-2xl px-3.5 py-2 text-base leading-relaxed shadow-xs [overflow-wrap:anywhere]",
97
+ outgoing ? "rounded-tr-md border border-primary/25 bg-primary/10 text-foreground" : "rounded-tl-md bg-card shadow-surface text-card-foreground",
98
+ message.kind === "Question" && "border-primary/50")}><MessagePrimitive.Content components={{ Text: BubbleText }}/></div>
99
+ </BubbleContext.Provider>}
100
+ {message.attachment && <ChatImage attachment={message.attachment}/>}
101
+ </div>
102
+ </MessagePrimitive.Root>;
103
+ }
104
+
105
+ // A session's finished turn(s) in the project chat: the first line of the final reply; tap opens the session.
106
+ export function CompletionRow({ row, when, open }) {
107
+ return <button type="button" data-type="completion" onClick={() => open(row.agent)} title={row.agent}
108
+ className="flex min-w-0 items-center gap-2 rounded-xl px-2.5 py-1.5 text-left text-sm text-muted-foreground hover:bg-accent">
109
+ <CircleCheck className="size-4 shrink-0 text-emerald-700 dark:text-emerald-400"/>
110
+ <span className="min-w-0 flex-1 truncate"><span className="font-mono text-foreground">{short(row.agent)}</span>{row.seat && " · " + row.seat} finished{row.turns > 1 ? " " + row.turns + " turns" : ""}{row.text && " · " + row.text}</span>
111
+ {row.time > 0 && <time className="shrink-0 text-xs" dateTime={new Date(row.time * 1000).toISOString()}>{when(row.time * 1000)}</time>}
112
+ </button>;
113
+ }
114
+
115
+ // A busy session in the project chat: its current turn's summary; tap opens the session.
116
+ export function LiveRow({ row, open }) {
117
+ return <button type="button" data-type="live" onClick={() => open(row.agent)} title={row.agent}
118
+ className="flex min-w-0 items-center gap-2 rounded-xl border border-dashed bg-card px-2.5 py-1.5 text-left text-sm">
119
+ <LoaderCircle className="size-4 shrink-0 animate-spin text-muted-foreground"/>
120
+ <span className="min-w-0 flex-1 truncate"><span className="font-mono">{short(row.agent)}</span>{row.seat && " · " + row.seat} · working{row.summary && " on " + row.summary}</span>
121
+ </button>;
122
+ }
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ // Small pieces every chat view shares: relative time, address helpers, the sender avatar and its online dot.
3
+ import { HarnessLogo, hasLogo } from "./logos";
4
+ import { Avatar as BaseAvatar, AvatarFallback } from "@/components/ui/avatar";
5
+ import { cn } from "@/lib/utils";
6
+ import { isLive } from "@/lib/session-state";
7
+
8
+ export const HARNESS_NAMES = { claude: "Claude Code", codex: "Codex", cursor: "Cursor", opencode: "OpenCode" };
9
+ export const clock = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" });
10
+
11
+ export function ago(ms, now) {
12
+ if (!ms) return "never";
13
+ const seconds = Math.max(0, Math.round((now - ms) / 1000));
14
+ if (seconds < 15) return "just now";
15
+ if (seconds < 60) return seconds + "s ago";
16
+ if (seconds < 3600) return Math.max(1, Math.round(seconds / 60)) + "m ago";
17
+ if (seconds < 86400) return Math.round(seconds / 3600) + "h ago";
18
+ return Math.round(seconds / 86400) + "d ago";
19
+ }
20
+
21
+ export const peerOf = address => String(address || "").split("#")[0];
22
+ export const short = address => address?.includes("#") ? address.slice(0, address.indexOf("#") + 9) : address;
23
+
24
+ // Literal classes so Tailwind emits them; any other agent peer takes the generic agent tint.
25
+ export const HARNESS_TINT = { claude: "text-claude", codex: "text-codex", cursor: "text-cursor", opencode: "text-opencode" };
26
+
27
+ /** The harness tint class for a peer: its own, the generic agent tint for another agent, none for the operator or system. */
28
+ export function harnessTint(peer) {
29
+ return HARNESS_TINT[peer] || (peer && peer !== "operator" && peer !== "system" ? "text-agent" : "");
30
+ }
31
+
32
+ export function Avatar({ address, className, by }) {
33
+ const peer = peerOf(address);
34
+ const tint = by ? "" : harnessTint(peer);
35
+ const label = by ? by.slice(0, 2).toUpperCase() : peer === "operator" ? "You" : peer === "system" ? "Sys" : peer.slice(0, 2).toUpperCase();
36
+ const fallback = !by && hasLogo(peer) ? <HarnessLogo peer={peer} className="size-[55%]"/> : label;
37
+ return <BaseAvatar title={address} className={cn("size-8 shrink-0 rounded-md text-xs font-medium [&_[data-slot=avatar-fallback]]:rounded-md [&_[data-slot=avatar-fallback]]:bg-muted", !tint && "[&_[data-slot=avatar-fallback]]:text-muted-foreground", className)}><AvatarFallback data-harness={tint ? peer : undefined} className={tint}>{fallback}</AvatarFallback></BaseAvatar>;
38
+ }
39
+
40
+ export function Dot({ online }) {
41
+ return <span aria-hidden className={cn("inline-block size-2 shrink-0 rounded-full", online ? "bg-live" : "bg-muted-foreground/40")}/>;
42
+ }
43
+
44
+ /** Team and role for a session address, from the agent list. Empty when the session holds no live role. */
45
+ export function seatOf(agents, address) {
46
+ const agent = (agents || []).find(item => item.id === address);
47
+ return agent?.team ? agent.team + " · " + agent.role : "";
48
+ }
49
+
50
+ /** "msg 3m ago · active just now" only while the session is waiting, held, or working. Hook seenAt is not a turn. */
51
+ export function seen(item, now) {
52
+ const live = item.live === true || (item.live === undefined && isLive(item, now));
53
+ return live && item.activeAt ? `msg ${ago(item.lastMessageAt, now)} · active ${ago(item.activeAt, now)}` : `msg ${ago(item.lastMessageAt, now)}`;
54
+ }
55
+
56
+ // The session's human name after its address, when the harness or its first prompt gives one.
57
+ export function SessionName({ agent }) {
58
+ return agent?.name ? <span className="block min-w-0 truncate text-xs text-muted-foreground" title={agent.name}>{agent.name}</span> : null;
59
+ }
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ // The AFK switch in the thread sidebar's footer; the sidebar itself is thread-sidebar.tsx.
3
+ import { Coffee, Monitor, VolumeX } from "lucide-react";
4
+ import { Button } from "@/components/ui/button";
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
6
+
7
+ const AFK_MODES = [["off", "Off", Monitor], ["on", "On", Coffee], ["quiet", "Quiet", VolumeX]];
8
+
9
+ // Operator away mode, broadcast to every project's agents.
10
+ export function AfkToggle({ mode, disabled, set }) {
11
+ const Icon = AFK_MODES.find(([id]) => id === mode)?.[2] || Monitor;
12
+ return <DropdownMenu>
13
+ <DropdownMenuTrigger asChild>
14
+ <Button variant={mode === "off" ? "ghost" : "secondary"} size="sm" aria-label={"AFK mode: " + mode} title={"AFK mode: " + mode} disabled={disabled}>
15
+ <Icon/><span className="text-xs">{mode === "off" ? "AFK" : "AFK " + mode}</span>
16
+ </Button>
17
+ </DropdownMenuTrigger>
18
+ <DropdownMenuContent align="end" className="w-56">
19
+ <DropdownMenuLabel>AFK mode · all projects</DropdownMenuLabel>
20
+ <DropdownMenuRadioGroup value={mode} onValueChange={next => next !== mode && set(next)}>
21
+ {AFK_MODES.map(([id, label, ItemIcon]) => <DropdownMenuRadioItem key={id} value={id}><ItemIcon/>{label}</DropdownMenuRadioItem>)}
22
+ </DropdownMenuRadioGroup>
23
+ </DropdownMenuContent>
24
+ </DropdownMenu>;
25
+ }
@@ -0,0 +1,127 @@
1
+ // The console's live stream: one /api/events subscription per view, its reconnect ladder, and the view cache
2
+ // that lets a screen switch render from the last frame while the new stream revalidates it.
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { toast } from "sonner";
5
+ import { subscribeUiEvents } from "@/lib/ui-events";
6
+ import { streamViews } from "@/lib/stream-views";
7
+ import { AUTH_CHECK, checkBuild, CONNECTION_TOAST, initial } from "./chat-api";
8
+
9
+ const QUIET_RETRY_MS = 500;
10
+ const RECONNECT_GRACE_MS = 3_000;
11
+ const STALE_AFTER_MS = 20_000;
12
+
13
+ /**
14
+ * Owns the streamed screen for one `requested` stream key.
15
+ * `route` is the console's live route ref: frames for a stream the console has left are dropped.
16
+ * `onReady` runs on the first state frame (the console refreshes its clock there).
17
+ */
18
+ export function useStream({ requested, route, account, onReady }) {
19
+ const [cached] = useState(() => streamViews.restore(requested));
20
+ const [data, setData] = useState(cached?.data || initial);
21
+ const [activity, setActivity] = useState(cached?.activity || []);
22
+ // A2UI surfaces by id, from the stream's ACTIVITY_SNAPSHOT frames.
23
+ const [surfaces, setSurfaces] = useState(cached?.surfaces || {});
24
+ // A restored view is already complete, so its screen renders at once instead of waiting for the new state frame.
25
+ const [ready, setReady] = useState(Boolean(cached));
26
+ const [loadError, setLoadError] = useState("");
27
+ const [revision, setRevision] = useState(0);
28
+ const retrying = useRef(false);
29
+ const shown = useRef(false);
30
+ const autoRetry = useRef(true);
31
+ const hiddenAt = useRef(0);
32
+
33
+ // A switch to a screen already in the cache shows its last frame at once; the new stream revalidates it.
34
+ function restore(nextStream) {
35
+ const view = streamViews.restore(nextStream);
36
+ if (view) { setData(view.data); setActivity(view.activity); setSurfaces(view.surfaces); }
37
+ else setActivity([]);
38
+ setReady(Boolean(view));
39
+ setLoadError("");
40
+ return view;
41
+ }
42
+
43
+ // Pull to refresh and the error banner's Retry: reconnect now, and say so if it fails.
44
+ function retry() {
45
+ retrying.current = true;
46
+ setRevision(n => n + 1);
47
+ }
48
+
49
+ useEffect(() => {
50
+ let controller;
51
+ let subscription;
52
+ let closed = false;
53
+ let bannerTimer = 0;
54
+ let retryTimer = 0;
55
+ // Error banners wait for one quiet reconnect; a manual Retry or a visible error ends in one toast.
56
+ const show = error => { clearTimeout(bannerTimer); shown.current = true; setLoadError(error); };
57
+ // A failure that heals within RECONNECT_GRACE_MS (a phone waking up) shows nothing, so no "Reconnected" follows.
58
+ const fail = error => {
59
+ if (!retrying.current) { clearTimeout(bannerTimer); bannerTimer = setTimeout(() => show(error), RECONNECT_GRACE_MS); return; }
60
+ show(error);
61
+ retrying.current = false; toast.error("Reconnect failed", { id: CONNECTION_TOAST, description: error });
62
+ };
63
+ const reconnect = () => { autoRetry.current = true; setRevision(n => n + 1); };
64
+ const disconnected = error => {
65
+ if (controller.signal.aborted || requested !== route.current) return;
66
+ controller.abort();
67
+ if (error?.status) {
68
+ closed = true;
69
+ if (account.enabled) window.dispatchEvent(new Event(AUTH_CHECK));
70
+ if (autoRetry.current && !retrying.current) { autoRetry.current = false; retryTimer = setTimeout(() => setRevision(n => n + 1), QUIET_RETRY_MS); return; }
71
+ return fail("Connection closed");
72
+ }
73
+ if (retrying.current) fail("Server unreachable. Still retrying automatically.");
74
+ else if (!bannerTimer) bannerTimer = setTimeout(() => show("Reconnecting…"), RECONNECT_GRACE_MS);
75
+ retryTimer = setTimeout(open, RECONNECT_GRACE_MS);
76
+ };
77
+ function open() {
78
+ controller = new AbortController();
79
+ let checked = false;
80
+ // Every frame of this stream also builds the cached view, so a switch back shows the newest one.
81
+ const view = streamViews.connect(requested);
82
+ subscription = subscribeUiEvents(() => fetch("/api/events?" + requested, {
83
+ headers: { Accept: "text/event-stream" }, signal: controller.signal,
84
+ }), {
85
+ next({ event, data }) {
86
+ if (requested !== route.current) return;
87
+ if (event === "problem") {
88
+ closed = true;
89
+ controller.abort();
90
+ subscription.unsubscribe();
91
+ return fail(data.error);
92
+ }
93
+ const next = view(event, data);
94
+ if (!next) return;
95
+ if (event === "state") {
96
+ if (!checked) { checked = true; checkBuild(); }
97
+ clearTimeout(bannerTimer); bannerTimer = 0;
98
+ setReady(true); setLoadError(""); onReady();
99
+ toast.dismiss(CONNECTION_TOAST);
100
+ retrying.current = false; shown.current = false; autoRetry.current = true;
101
+ }
102
+ // The cached view is the one source for all three, so a reconnect keeps a surface that did not change.
103
+ setData(next.data); setActivity(next.activity); setSurfaces(next.surfaces);
104
+ },
105
+ error: disconnected,
106
+ complete: disconnected,
107
+ });
108
+ }
109
+ open();
110
+ // Phones suspend background pages and can leave a dead stream open; reconnect quietly on return.
111
+ const resume = () => {
112
+ if (document.visibilityState === "hidden") { hiddenAt.current = Date.now(); return; }
113
+ const away = hiddenAt.current && Date.now() - hiddenAt.current > STALE_AFTER_MS;
114
+ hiddenAt.current = 0;
115
+ if (closed || away) reconnect();
116
+ };
117
+ document.addEventListener("visibilitychange", resume);
118
+ window.addEventListener("online", reconnect);
119
+ return () => {
120
+ clearTimeout(bannerTimer); clearTimeout(retryTimer); controller.abort(); subscription.unsubscribe();
121
+ document.removeEventListener("visibilitychange", resume);
122
+ window.removeEventListener("online", reconnect);
123
+ };
124
+ }, [requested, revision]);
125
+
126
+ return { cached, data, activity, surfaces, ready, loadError, setLoadError, setReady, restore, retry };
127
+ }
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ // Entry point: the sign-in gate over the console. The console itself lives in chat-console.jsx;
3
+ // its parts in chat-sidebar/-message/-composer/-stream/-shared, and the network layer in chat-api.js.
4
+ import { useEffect, useState } from "react";
5
+ import { Button } from "@/components/ui/button";
6
+ import { AUTH_CHECK } from "./chat-api";
7
+ import { Console } from "./chat-console";
8
+
9
+ // With GitHub sign-in on, a signed-out visitor sees only the sign-in button; a 401 or closed stream checks again.
10
+ export default function Chat() {
11
+ const [account, setAccount] = useState(null);
12
+ useEffect(() => {
13
+ let live = true;
14
+ const check = () => fetch("/api/auth/me", { cache: "no-store" }).then(response => response.json())
15
+ .then(result => { if (live) setAccount(result); }, () => { if (live) setAccount(current => current || { enabled: false, user: null }); });
16
+ check();
17
+ window.addEventListener(AUTH_CHECK, check);
18
+ return () => { live = false; window.removeEventListener(AUTH_CHECK, check); };
19
+ }, []);
20
+ if (!account) return null;
21
+ if (account.enabled && !account.user) return <SignIn/>;
22
+ return <Console account={account}/>;
23
+ }
24
+
25
+ function SignIn() {
26
+ return <main className="flex h-dvh flex-col items-center justify-center gap-4 px-6 text-center">
27
+ <h1 className="text-xl font-semibold">Temmo</h1>
28
+ <p className="text-sm text-muted-foreground">Sign in to message your agents.</p>
29
+ <Button asChild className="rounded-md"><a href="/api/auth/login">Sign in with GitHub</a></Button>
30
+ </main>;
31
+ }
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { Badge } from "@/components/ui/badge";
3
+ import { axisPercent, clearText, compactionText, headroom, mapAxis, modelText, tokenCount } from "@/lib/compaction-view";
4
+ import { Avatar, ago } from "./chat-shared";
5
+
6
+ const MARK = { auto: "bg-primary", manual: "bg-primary", failed: "bg-destructive", clear: "bg-sky-500", model: "bg-emerald-500" };
7
+
8
+ // The sentence for one history entry: a compaction, a clear or a model switch.
9
+ const textOf = entry => entry.kind === "clear" ? clearText(entry) : entry.kind === "model" ? modelText(entry) : compactionText(entry);
10
+ const markOf = entry => entry.kind === "compaction" ? (entry.phase === "failed" ? MARK.failed : MARK[entry.trigger] || "bg-muted-foreground") : MARK[entry.kind];
11
+ const RECENT = 3;
12
+ const short = address => address?.includes("#") ? address.slice(0, address.indexOf("#") + 9) : address;
13
+
14
+ // Context against the window the harness reported; a harness that reports none shows the tokens only.
15
+ function contextLine({ context }) {
16
+ if (!Number.isSafeInteger(context?.tokens)) return "No context reading yet";
17
+ const left = headroom(context);
18
+ if (!left) return `${tokenCount(context.tokens)} tokens · window not reported`;
19
+ return `${tokenCount(context.tokens)} of ${tokenCount(left.window)} · ${tokenCount(left.left)} to window`;
20
+ }
21
+
22
+ /** Every agent's compactions on one time axis, with its context against the reported window. */
23
+ export function CompactionMap({ agents, now }) {
24
+ const rows = agents.map(agent => ({
25
+ agent,
26
+ entries: agent.history || [],
27
+ }));
28
+ const axis = mapAxis(rows.map(row => row.entries), now);
29
+ return <section aria-label="History" className="flex w-full flex-col gap-3">
30
+ <p className="text-xs text-muted-foreground">Headroom counts to the harness window. No harness reports its auto-compact point, so none is shown. Markers: amber auto, blue manual, red failed, sky clear, green model switch.</p>
31
+ {rows.length === 0 && <p className="py-16 text-center text-sm text-muted-foreground">No agents in this project yet.</p>}
32
+ {rows.map(({ agent, entries }) => <article key={agent.id} data-compaction-agent={agent.id} className="flex min-w-0 flex-col gap-2.5 rounded-2xl bg-card shadow-surface p-3 text-sm">
33
+ <header className="flex min-w-0 flex-wrap items-center gap-2">
34
+ <Avatar address={agent.id} className="size-6 text-xs"/>
35
+ <span className="min-w-0 truncate font-mono text-xs">{short(agent.id)}</span>
36
+ <Badge variant="outline">{agent.peer}</Badge>
37
+ {agent.model && <span className="min-w-0 truncate text-xs text-muted-foreground">{agent.model}</span>}
38
+ </header>
39
+ <p className="text-xs text-muted-foreground">{contextLine(agent)}</p>
40
+ <div role="list" aria-label={`Compactions of ${short(agent.id)}`} className="relative h-6 rounded-md bg-muted">
41
+ {entries.map(entry => <span key={entry.id} role="listitem" className="contents">
42
+ <span role="img" aria-label={`${ago(entry.at, now)}: ${textOf(entry)}`} title={textOf(entry)}
43
+ style={{ left: `${axisPercent(entry.at, axis.start, axis.end)}%` }}
44
+ className={`absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2 ring-card ${markOf(entry)}`}/>
45
+ </span>)}
46
+ </div>
47
+ <div className="flex justify-between text-xs text-muted-foreground"><span>{ago(axis.start, now)}</span><span>now</span></div>
48
+ {entries.length === 0 && <p className="text-xs text-muted-foreground">No compactions, clears or model switches in the activity kept in memory.</p>}
49
+ {entries.length > 0 && <ul className="flex flex-col gap-1 text-xs">
50
+ {entries.slice(-RECENT).reverse().map(entry => <li key={entry.id} className="flex min-w-0 flex-wrap gap-x-2">
51
+ <span className="shrink-0 text-muted-foreground">{ago(entry.at, now)}</span>
52
+ <span className="min-w-0 break-words">{textOf(entry)}</span>
53
+ </li>)}
54
+ </ul>}
55
+ </article>)}
56
+ </section>;
57
+ }
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ // The composer's Actions button: the session's slash commands in a menu (a sheet on phones), argument values as items.
3
+ import { Check, ChevronRight, SquareSlash } from "lucide-react";
4
+ import { Menu, MenuContent, MenuGroup, MenuGroupLabel, MenuItem, MenuSeparator, MenuSub, MenuSubContent, MenuSubTrigger, MenuTrigger } from "@ui-sdk/react/menu";
5
+ import { composerActions } from "@/lib/composer-actions";
6
+ import { cn } from "@/lib/utils";
7
+
8
+ const TRIGGER = "inline-flex h-11 shrink-0 cursor-pointer items-center gap-1.5 rounded-md px-2.5 text-sm font-medium outline-none hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-open:bg-muted sm:h-7 [&_svg]:size-4 sm:[&_svg]:size-3.5";
9
+ const MENU = "z-50 max-h-(--available-height) w-80 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-xl bg-popover p-1 text-sm text-popover-foreground shadow-raised outline-none";
10
+ const ITEM = "flex min-h-11 w-full min-w-0 cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-left outline-none focus-visible:-outline-offset-2 data-disabled:cursor-not-allowed data-highlighted:bg-accent";
11
+
12
+ type Value = { value: string; summary: string; command?: string; values?: Value[]; current?: boolean };
13
+ type Entry = { name: string; summary: string; args?: string; status: string; reason: string; command?: string; values?: Value[]; current?: string };
14
+ type Data = { teams?: { name: string; description?: string }[]; models?: string[] };
15
+
16
+ // Name and summary of an entry or value; the summary wraps so a 360-pixel sheet never scrolls sideways.
17
+ function Label({ name, summary, mono = true }: { name: string; summary?: string; mono?: boolean }) {
18
+ return <span className="flex min-w-0 flex-1 flex-col">
19
+ <span className={cn("wrap-anywhere", mono ? "font-mono text-xs" : "font-medium")}>{name}</span>
20
+ {summary && <span className="text-xs text-muted-foreground wrap-anywhere">{summary}</span>}
21
+ </span>;
22
+ }
23
+
24
+ // A status tag beside a command the harness supports only in part, or has not been checked against.
25
+ function Status({ status }: { status: string }) {
26
+ if (status !== "partial" && status !== "unverified") return null;
27
+ return <span className="shrink-0 rounded-md border px-1.5 text-xs text-primary">{status}</span>;
28
+ }
29
+
30
+ // One level of argument values: an item that runs its command, or a submenu for the next argument.
31
+ // When one value is tagged current (the /mode submenu), a check column marks it and picking it is a no-op, as on the card's menu.
32
+ function Values({ values, run, empty }: { values: Value[]; run: (text: string) => void; empty: string }) {
33
+ if (!values.length) return <MenuItem className={ITEM} disabled><Label name={empty} mono={false}/></MenuItem>;
34
+ const marks = values.some(value => value.current);
35
+ return <>{values.map(value => value.values
36
+ ? <MenuSub key={value.value}>
37
+ <MenuSubTrigger className={ITEM}><Label name={value.value} summary={value.summary}/><ChevronRight aria-hidden className="size-4 shrink-0"/></MenuSubTrigger>
38
+ <MenuSubContent className={MENU}><Values values={value.values} run={run} empty="No values"/></MenuSubContent>
39
+ </MenuSub>
40
+ : <MenuItem key={value.value} className={ITEM} disabled={value.current || undefined} aria-current={value.current || undefined} onSelect={() => run(value.command as string)}>
41
+ {marks && <Check aria-hidden className={cn("size-4 shrink-0", !value.current && "invisible")}/>}
42
+ <Label name={value.value} summary={value.summary}/>
43
+ </MenuItem>)}</>;
44
+ }
45
+
46
+ /** The Actions menu for a session: run picks a command's full text. target names the session, so a current-mode badge says whose mode it is. */
47
+ export function ComposerActions({ harness, data, target, disabled, run }: {
48
+ harness: string; data: Data; target?: string; disabled?: boolean; run: (text: string) => void;
49
+ }) {
50
+ const entries: Entry[] = composerActions(harness, data);
51
+ const usable = entries.filter(entry => entry.status !== "unsupported");
52
+ const unsupported = entries.filter(entry => entry.status === "unsupported");
53
+ return <Menu presentation="auto">
54
+ <MenuTrigger className={TRIGGER} disabled={disabled} aria-label="Actions: slash commands for this session" title="Slash commands for this session">
55
+ <SquareSlash aria-hidden/>Actions
56
+ </MenuTrigger>
57
+ <MenuContent align="start" className={MENU}>
58
+ <MenuGroup>
59
+ <MenuGroupLabel className="px-2 py-1.5 text-xs font-medium text-muted-foreground">Commands for this session</MenuGroupLabel>
60
+ {usable.map(entry => entry.values
61
+ ? <MenuSub key={entry.name}>
62
+ <MenuSubTrigger className={ITEM}><Label name={"/" + entry.name} summary={entry.summary}/>
63
+ {entry.current && <span className="shrink-0 rounded-md bg-muted px-1.5 font-mono text-xs text-muted-foreground"
64
+ title={"Current mode for " + (target || "this session")}>{entry.current}</span>}
65
+ <Status status={entry.status}/><ChevronRight aria-hidden className="size-4 shrink-0"/></MenuSubTrigger>
66
+ <MenuSubContent className={MENU}>
67
+ <MenuGroupLabel className="px-2 py-1.5 text-xs font-medium text-muted-foreground">{"/" + entry.name + " " + entry.args}</MenuGroupLabel>
68
+ <Values values={entry.values} run={run} empty={entry.name === "team-permission" ? "No team.dot teams in this project" : "No values listed"}/>
69
+ </MenuSubContent>
70
+ </MenuSub>
71
+ : <MenuItem key={entry.name} className={ITEM} title={entry.reason} onSelect={() => run(entry.command as string)}>
72
+ <Label name={"/" + entry.name} summary={entry.summary}/><Status status={entry.status}/>
73
+ </MenuItem>)}
74
+ </MenuGroup>
75
+ {unsupported.length > 0 && <>
76
+ <MenuSeparator className="my-1 h-px bg-border"/>
77
+ <MenuGroup>
78
+ <MenuGroupLabel className="px-2 py-1.5 text-xs font-medium text-muted-foreground">Not available for {harness}</MenuGroupLabel>
79
+ {unsupported.map(entry => <MenuItem key={entry.name} className={cn(ITEM, "items-start")} disabled>
80
+ <span className="flex min-w-0 flex-1 flex-col opacity-70"><span className="font-mono text-xs">/{entry.name}</span>
81
+ <span className="text-xs text-muted-foreground wrap-anywhere">{entry.reason}</span></span>
82
+ </MenuItem>)}
83
+ </MenuGroup>
84
+ </>}
85
+ </MenuContent>
86
+ </Menu>;
87
+ }