@temmo/cli 0.0.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (445) hide show
  1. package/.claude-plugin/marketplace.json +14 -0
  2. package/.claude-plugin/plugin.json +16 -0
  3. package/.codex-plugin/plugin.json +30 -0
  4. package/.cursor-plugin/plugin.json +22 -0
  5. package/.mcp.json +18 -0
  6. package/LICENSE +202 -0
  7. package/README.md +82 -2
  8. package/THIRD_PARTY_NOTICES +32 -0
  9. package/commands/afk.md +17 -0
  10. package/deploy/build-ui.mjs +65 -0
  11. package/deploy/claude/README.md +16 -0
  12. package/deploy/claude/auto-mode.json +31 -0
  13. package/deploy/postgres/compose.yaml +26 -0
  14. package/deploy/temmo-runner.service +24 -0
  15. package/deploy/verify-ui.mjs +15 -0
  16. package/harness-core/README.md +27 -0
  17. package/harness-core/bin/harness.mjs +17 -0
  18. package/harness-core/package.json +10 -0
  19. package/harness-core/stage.mjs +108 -0
  20. package/harness-core/stages/commit.md +7 -0
  21. package/harness-core/stages/pr.md +7 -0
  22. package/harness-core/stages/push.md +7 -0
  23. package/hooks/codex-hooks.json +14 -0
  24. package/hooks/cursor-hooks.json +17 -0
  25. package/hooks/hooks.json +27 -0
  26. package/lib/acp/permission.js +72 -0
  27. package/lib/acp/sessionConfig.js +109 -0
  28. package/lib/activity.js +244 -0
  29. package/lib/agent-guard.js +72 -0
  30. package/lib/agents-route.js +55 -0
  31. package/lib/agents.js +213 -0
  32. package/lib/agui.js +255 -0
  33. package/lib/alerts.js +36 -0
  34. package/lib/analyze-otlp.js +46 -0
  35. package/lib/analyze-run-code.js +397 -0
  36. package/lib/analyze-sources.js +372 -0
  37. package/lib/approval-card.js +54 -0
  38. package/lib/approval-cli.js +53 -0
  39. package/lib/approval-request.js +81 -0
  40. package/lib/approval-signer.js +48 -0
  41. package/lib/approvals.js +295 -0
  42. package/lib/attachment-cache.js +236 -0
  43. package/lib/attachment.js +63 -0
  44. package/lib/blocked.js +20 -0
  45. package/lib/build-review.js +90 -0
  46. package/lib/builder/cli.js +90 -0
  47. package/lib/builder/policy.js +176 -0
  48. package/lib/builder/recover.js +189 -0
  49. package/lib/builder/run.js +240 -0
  50. package/lib/builder/settle.js +198 -0
  51. package/lib/builder/stage.js +240 -0
  52. package/lib/builder/state.js +73 -0
  53. package/lib/builder/supervisor.js +289 -0
  54. package/lib/builder-clean.js +223 -0
  55. package/lib/builder-code.cjs +67 -0
  56. package/lib/builder.js +9 -0
  57. package/lib/bus-postgres.js +281 -0
  58. package/lib/bus.js +349 -0
  59. package/lib/catalog/author.js +278 -0
  60. package/lib/catalog/dot.js +426 -0
  61. package/lib/catalog/pattern-model.js +193 -0
  62. package/lib/catalog/patterns.js +324 -0
  63. package/lib/catalog/projects.js +83 -0
  64. package/lib/catalog/records.js +2 -0
  65. package/lib/catalog/roster.js +70 -0
  66. package/lib/catalog/team-files.js +49 -0
  67. package/lib/catalog/teams.js +109 -0
  68. package/lib/claude-socket.js +333 -0
  69. package/lib/cli.js +741 -0
  70. package/lib/code-mode.js +45 -0
  71. package/lib/code-read-policy.yaml +9 -0
  72. package/lib/code-run.js +461 -0
  73. package/lib/codex-compact.js +141 -0
  74. package/lib/compaction.js +21 -0
  75. package/lib/config.js +424 -0
  76. package/lib/cursor-trace.js +248 -0
  77. package/lib/deep-link.js +20 -0
  78. package/lib/deliver-push.js +120 -0
  79. package/lib/delivery.js +28 -0
  80. package/lib/deploy-tree.js +227 -0
  81. package/lib/durable.js +404 -0
  82. package/lib/factory-tick.js +32 -0
  83. package/lib/family.js +63 -0
  84. package/lib/fetch-origin.js +53 -0
  85. package/lib/format.js +133 -0
  86. package/lib/harness-surface-cli.js +153 -0
  87. package/lib/harness-surface.js +486 -0
  88. package/lib/harness.js +271 -0
  89. package/lib/hook.mjs +291 -0
  90. package/lib/idle.js +40 -0
  91. package/lib/install-cursor.js +115 -0
  92. package/lib/install-opencode.js +105 -0
  93. package/lib/job.js +82 -0
  94. package/lib/land-cli.js +319 -0
  95. package/lib/land-member.js +64 -0
  96. package/lib/land.js +320 -0
  97. package/lib/lessons.js +223 -0
  98. package/lib/limit-alert.js +423 -0
  99. package/lib/limits.js +284 -0
  100. package/lib/machine-prompt.js +19 -0
  101. package/lib/merge-sweep.js +149 -0
  102. package/lib/messaging.js +1002 -0
  103. package/lib/mission-cli.js +103 -0
  104. package/lib/mission.js +241 -0
  105. package/lib/mode.js +215 -0
  106. package/lib/models.js +114 -0
  107. package/lib/names.js +86 -0
  108. package/lib/opencode-api.js +57 -0
  109. package/lib/opencode-plugin.mjs +313 -0
  110. package/lib/operator-token.js +78 -0
  111. package/lib/operator.js +187 -0
  112. package/lib/pad-activity.js +143 -0
  113. package/lib/pad-fresh.js +44 -0
  114. package/lib/pad.js +198 -0
  115. package/lib/pattern-cli.js +120 -0
  116. package/lib/pattern-compiler.js +68 -0
  117. package/lib/pattern-runs.js +795 -0
  118. package/lib/pattern-stall.js +58 -0
  119. package/lib/pattern-tick.js +45 -0
  120. package/lib/pattern-workflow.js +69 -0
  121. package/lib/pi-extension.mjs +98 -0
  122. package/lib/pi.js +57 -0
  123. package/lib/plugin-copy.js +76 -0
  124. package/lib/pm-review.js +32 -0
  125. package/lib/pm-workspace.js +87 -0
  126. package/lib/postgres.js +115 -0
  127. package/lib/pr-card.js +34 -0
  128. package/lib/probe.js +295 -0
  129. package/lib/process.js +67 -0
  130. package/lib/project-pause.js +23 -0
  131. package/lib/prune.js +793 -0
  132. package/lib/questions.js +250 -0
  133. package/lib/receipts.js +63 -0
  134. package/lib/reflect.js +962 -0
  135. package/lib/rename-migration.js +118 -0
  136. package/lib/run-terminal.js +437 -0
  137. package/lib/runner-request.js +33 -0
  138. package/lib/sandbox-app.js +120 -0
  139. package/lib/sandbox-claims.js +258 -0
  140. package/lib/sandbox-cli.js +188 -0
  141. package/lib/sandbox-hosts-cli.js +68 -0
  142. package/lib/sandbox-hosts.js +94 -0
  143. package/lib/sandbox-pr.js +102 -0
  144. package/lib/sandbox-proposal.js +367 -0
  145. package/lib/sandbox-tools.js +143 -0
  146. package/lib/sandbox.js +501 -0
  147. package/lib/schedule-session.js +68 -0
  148. package/lib/session-activity.js +67 -0
  149. package/lib/session-events.js +94 -0
  150. package/lib/sessions/control.js +244 -0
  151. package/lib/sessions/git-refs.js +265 -0
  152. package/lib/sessions/launch.js +359 -0
  153. package/lib/sessions/registry.js +450 -0
  154. package/lib/sessions/scope.js +111 -0
  155. package/lib/setup.js +377 -0
  156. package/lib/signed-approval.js +225 -0
  157. package/lib/slash.js +167 -0
  158. package/lib/spawn-cli.js +45 -0
  159. package/lib/spawn.js +107 -0
  160. package/lib/start-limit.js +58 -0
  161. package/lib/state.js +24 -0
  162. package/lib/stop.js +308 -0
  163. package/lib/store-read.js +62 -0
  164. package/lib/store.js +252 -0
  165. package/lib/subagent-guard.js +240 -0
  166. package/lib/surfaces/channel-post.js +43 -0
  167. package/lib/surfaces/instructions.js +15 -0
  168. package/lib/surfaces/mcp-reload.js +144 -0
  169. package/lib/surfaces/ops.js +629 -0
  170. package/lib/surfaces/render-mcp.js +33 -0
  171. package/lib/surfaces/run-terminal-ops.js +40 -0
  172. package/lib/surfaces/sandbox-ops.js +36 -0
  173. package/lib/surfaces/schema.js +7 -0
  174. package/lib/surfaces/task-view.js +90 -0
  175. package/lib/surfaces/types.js +4 -0
  176. package/lib/task-cli.js +274 -0
  177. package/lib/task-order.js +34 -0
  178. package/lib/task-order.mjs +2 -0
  179. package/lib/task-route.js +125 -0
  180. package/lib/tasks.js +631 -0
  181. package/lib/team-permission.js +34 -0
  182. package/lib/team-templates/blitz/team.dot +9 -0
  183. package/lib/team-templates/factory/team.dot +26 -0
  184. package/lib/team-templates/feature/team.dot +14 -0
  185. package/lib/team-templates/fix-and-review/team.dot +12 -0
  186. package/lib/team-templates/product/team.dot +16 -0
  187. package/lib/team-templates/release/team.dot +7 -0
  188. package/lib/team-templates/review/team.dot +6 -0
  189. package/lib/terminal-draft.js +42 -0
  190. package/lib/thread-branch.js +82 -0
  191. package/lib/thread-channel-store.js +181 -0
  192. package/lib/thread-channels.js +116 -0
  193. package/lib/thread-listening.js +20 -0
  194. package/lib/thread-routes.js +91 -0
  195. package/lib/threads.js +441 -0
  196. package/lib/tool-api.js +33 -0
  197. package/lib/transcript.js +98 -0
  198. package/lib/ui-build-output.js +19 -0
  199. package/lib/ui-capabilities.js +90 -0
  200. package/lib/usage.js +182 -0
  201. package/lib/vendor/mcp-sdk.d.mts +4 -0
  202. package/lib/vendor/mcp-sdk.mjs +17046 -0
  203. package/lib/waiter.js +127 -0
  204. package/lib/workflows.js +546 -0
  205. package/lib/worktree-setup.js +86 -0
  206. package/package.json +112 -1
  207. package/runner/adapters/claude.js +465 -0
  208. package/runner/adapters/cli-sandbox.js +277 -0
  209. package/runner/adapters/codex.js +675 -0
  210. package/runner/adapters/cursor.mjs +937 -0
  211. package/runner/adapters/fake.js +119 -0
  212. package/runner/adapters/opencode-sandbox.js +370 -0
  213. package/runner/adapters/opencode.js +486 -0
  214. package/runner/adapters/pi-sandbox.js +134 -0
  215. package/runner/adapters/pi.js +364 -0
  216. package/runner/client.js +40 -0
  217. package/runner/contract.js +129 -0
  218. package/runner/control.js +178 -0
  219. package/runner/delivery.js +184 -0
  220. package/runner/factory-tick.mjs +10 -0
  221. package/runner/lock.js +41 -0
  222. package/runner/main.mjs +118 -0
  223. package/runner/pattern-tick.mjs +16 -0
  224. package/runner/publish.js +113 -0
  225. package/runner/runner.js +2612 -0
  226. package/runner/sandbox-run.mjs +239 -0
  227. package/runner/schedules.js +294 -0
  228. package/runner/task-wake.js +59 -0
  229. package/scripts/ai-collab +3 -0
  230. package/scripts/ai-collab-bus.mjs +4 -0
  231. package/scripts/ai-collab-code-mcp.mjs +3 -0
  232. package/scripts/ai-collab-hook +3 -0
  233. package/scripts/ai-collab-hook.mjs +3 -0
  234. package/scripts/ai-collab-mcp-tools.mjs +2 -0
  235. package/scripts/ai-collab-mcp.mjs +3 -0
  236. package/scripts/ai-collab.mjs +3 -0
  237. package/scripts/install-cursor.mjs +11 -0
  238. package/scripts/install-opencode.mjs +10 -0
  239. package/scripts/temmo +3 -0
  240. package/scripts/temmo-bus.mjs +151 -0
  241. package/scripts/temmo-code-mcp.mjs +63 -0
  242. package/scripts/temmo-hook +3 -0
  243. package/scripts/temmo-hook.mjs +201 -0
  244. package/scripts/temmo-mcp-tools.mjs +22 -0
  245. package/scripts/temmo-mcp.mjs +27 -0
  246. package/scripts/temmo.mjs +4 -0
  247. package/skills/antislop/SKILL.md +701 -0
  248. package/skills/antislop/VERSION +1 -0
  249. package/skills/antislop-code/SKILL.md +128 -0
  250. package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
  251. package/skills/antislop-human/SKILL.md +204 -0
  252. package/skills/antislop-human/contrast-check.py +168 -0
  253. package/skills/antislop-human/contrast-mcp.py +125 -0
  254. package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
  255. package/skills/antislop-human/references/WCAG.md +127 -0
  256. package/skills/antislop-layoutmobile/SKILL.md +170 -0
  257. package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
  258. package/skills/antislop-ui/SKILL.md +351 -0
  259. package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
  260. package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
  261. package/skills/harness-surface/SKILL.md +42 -0
  262. package/skills/land/SKILL.md +32 -0
  263. package/skills/memory-file/SKILL.md +39 -0
  264. package/skills/temmo/SKILL.md +101 -0
  265. package/skills/temmo/references/role-programs.md +47 -0
  266. package/skills/ui-sdk/SKILL.md +56 -0
  267. package/skills/ui-sdk/references/agent-ready.md +136 -0
  268. package/skills/ui-sdk/references/build-interface.md +187 -0
  269. package/skills/ui-sdk/references/create-component.md +88 -0
  270. package/skills/ui-sdk/references/patterns.md +246 -0
  271. package/skills/ui-sdk/references/styles.md +66 -0
  272. package/skills/ui-sdk/references/testing.md +172 -0
  273. package/skills/ui-sdk/references/web-components.md +78 -0
  274. package/tools/screen-state.mjs +119 -0
  275. package/tools/smoke-ui.mjs +540 -0
  276. package/web/app/activity.jsx +251 -0
  277. package/web/app/agent-mark.tsx +43 -0
  278. package/web/app/alert-level.jsx +16 -0
  279. package/web/app/api/[action]/route.js +8 -0
  280. package/web/app/api/auth/[step]/route.js +12 -0
  281. package/web/app/api/events/route.js +8 -0
  282. package/web/app/api/file/[name]/route.js +8 -0
  283. package/web/app/api/land/route.js +12 -0
  284. package/web/app/api/lessons/route.js +8 -0
  285. package/web/app/api/push/key/route.js +8 -0
  286. package/web/app/api/push/subscribe/route.js +12 -0
  287. package/web/app/api/push/test/route.js +8 -0
  288. package/web/app/api/refs/route.js +8 -0
  289. package/web/app/api/review-diff/route.js +8 -0
  290. package/web/app/api/schedules/route.js +8 -0
  291. package/web/app/api/thread-diff/route.js +8 -0
  292. package/web/app/api/version/route.js +6 -0
  293. package/web/app/cards.jsx +189 -0
  294. package/web/app/chat-api.js +82 -0
  295. package/web/app/chat-composer.jsx +313 -0
  296. package/web/app/chat-console.jsx +691 -0
  297. package/web/app/chat-image.tsx +61 -0
  298. package/web/app/chat-message.jsx +122 -0
  299. package/web/app/chat-shared.jsx +59 -0
  300. package/web/app/chat-sidebar.jsx +25 -0
  301. package/web/app/chat-stream.js +127 -0
  302. package/web/app/chat.jsx +31 -0
  303. package/web/app/compactions.jsx +57 -0
  304. package/web/app/composer-actions.tsx +87 -0
  305. package/web/app/decisions.jsx +53 -0
  306. package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
  307. package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
  308. package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
  309. package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  310. package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  311. package/web/app/globals.css +199 -0
  312. package/web/app/home.jsx +246 -0
  313. package/web/app/icon.svg +1 -0
  314. package/web/app/land-panel.jsx +63 -0
  315. package/web/app/land-reviews.jsx +20 -0
  316. package/web/app/layout.jsx +17 -0
  317. package/web/app/lessons.tsx +76 -0
  318. package/web/app/logo.tsx +13 -0
  319. package/web/app/logos.jsx +16 -0
  320. package/web/app/manifest.js +8 -0
  321. package/web/app/mode-menu.tsx +46 -0
  322. package/web/app/new-session.jsx +275 -0
  323. package/web/app/notify.jsx +180 -0
  324. package/web/app/outcomes.tsx +94 -0
  325. package/web/app/page.jsx +9 -0
  326. package/web/app/pattern-graph.jsx +75 -0
  327. package/web/app/patterns-page.jsx +293 -0
  328. package/web/app/phone-nav.tsx +36 -0
  329. package/web/app/progress-feed.tsx +33 -0
  330. package/web/app/providers.tsx +27 -0
  331. package/web/app/quote.jsx +15 -0
  332. package/web/app/run-card.tsx +200 -0
  333. package/web/app/run-requests.tsx +148 -0
  334. package/web/app/scheduled.jsx +105 -0
  335. package/web/app/session-panel.tsx +174 -0
  336. package/web/app/session-toolbar.tsx +180 -0
  337. package/web/app/shadcn.css +638 -0
  338. package/web/app/shipped.jsx +49 -0
  339. package/web/app/subagent-runs.jsx +31 -0
  340. package/web/app/task-graph.jsx +67 -0
  341. package/web/app/tasks-strip.tsx +36 -0
  342. package/web/app/tasks.jsx +375 -0
  343. package/web/app/team-author.jsx +145 -0
  344. package/web/app/team-editor.jsx +88 -0
  345. package/web/app/thread-agents.tsx +32 -0
  346. package/web/app/thread-place.tsx +9 -0
  347. package/web/app/thread-sessions.tsx +149 -0
  348. package/web/app/thread-sidebar.tsx +418 -0
  349. package/web/app/thread-switcher.tsx +27 -0
  350. package/web/app/tool-diff.jsx +94 -0
  351. package/web/components/a2ui/controls.jsx +36 -0
  352. package/web/components/a2ui/option-picker.jsx +23 -0
  353. package/web/components/a2ui/script.tsx +121 -0
  354. package/web/components/a2ui/surface.jsx +81 -0
  355. package/web/components/chat/thread.jsx +50 -0
  356. package/web/components/script-text.tsx +42 -0
  357. package/web/components/ui/avatar.jsx +115 -0
  358. package/web/components/ui/badge.jsx +47 -0
  359. package/web/components/ui/button.jsx +63 -0
  360. package/web/components/ui/chat-container.jsx +52 -0
  361. package/web/components/ui/choice-list.tsx +72 -0
  362. package/web/components/ui/code-block.jsx +60 -0
  363. package/web/components/ui/copy-button.tsx +41 -0
  364. package/web/components/ui/dropdown-menu.jsx +257 -0
  365. package/web/components/ui/markdown.jsx +84 -0
  366. package/web/components/ui/message.jsx +28 -0
  367. package/web/components/ui/popover.jsx +33 -0
  368. package/web/components/ui/scroll-button.jsx +34 -0
  369. package/web/components/ui/select.jsx +189 -0
  370. package/web/components/ui/sheet.jsx +152 -0
  371. package/web/components/ui/sonner.jsx +10 -0
  372. package/web/components/ui/tabs.jsx +88 -0
  373. package/web/components/ui/textarea.jsx +20 -0
  374. package/web/components/ui/tooltip.jsx +56 -0
  375. package/web/components.json +24 -0
  376. package/web/instrumentation.js +8 -0
  377. package/web/lib/a2ui-catalog.js +34 -0
  378. package/web/lib/a2ui-pr.js +76 -0
  379. package/web/lib/a2ui-run-catalog.js +18 -0
  380. package/web/lib/a2ui-run.js +93 -0
  381. package/web/lib/a2ui.js +262 -0
  382. package/web/lib/activity-rows.js +275 -0
  383. package/web/lib/agent-detail.js +5 -0
  384. package/web/lib/alert-level.js +44 -0
  385. package/web/lib/approval-mode.js +22 -0
  386. package/web/lib/chat-turns.js +174 -0
  387. package/web/lib/child-subagents.js +16 -0
  388. package/web/lib/compaction-view.js +48 -0
  389. package/web/lib/composer-actions.js +40 -0
  390. package/web/lib/context-view.js +57 -0
  391. package/web/lib/fuzzy.js +26 -0
  392. package/web/lib/highlight.js +44 -0
  393. package/web/lib/lessons-view.js +23 -0
  394. package/web/lib/mentions.js +16 -0
  395. package/web/lib/message-routing.js +105 -0
  396. package/web/lib/new-session.js +85 -0
  397. package/web/lib/operator-messages.js +28 -0
  398. package/web/lib/pattern-graph.js +165 -0
  399. package/web/lib/pattern-view.js +33 -0
  400. package/web/lib/pending-summary.js +18 -0
  401. package/web/lib/permission-modes.js +30 -0
  402. package/web/lib/project-feed.js +107 -0
  403. package/web/lib/quote.js +7 -0
  404. package/web/lib/reply-quote.js +31 -0
  405. package/web/lib/scheduled.js +79 -0
  406. package/web/lib/selection.js +110 -0
  407. package/web/lib/send-confirmation.js +22 -0
  408. package/web/lib/session-dead.js +10 -0
  409. package/web/lib/session-state.js +132 -0
  410. package/web/lib/sidebar.js +15 -0
  411. package/web/lib/slash-commands.js +164 -0
  412. package/web/lib/start-default.js +35 -0
  413. package/web/lib/start-mode.js +35 -0
  414. package/web/lib/stream-views.js +49 -0
  415. package/web/lib/subagent-state.js +20 -0
  416. package/web/lib/task-board.js +54 -0
  417. package/web/lib/task-graph.js +183 -0
  418. package/web/lib/task-tags.js +41 -0
  419. package/web/lib/team-editor.js +10 -0
  420. package/web/lib/thread-groups.js +86 -0
  421. package/web/lib/threads.js +28 -0
  422. package/web/lib/tool-diff.js +273 -0
  423. package/web/lib/ui-events.js +58 -0
  424. package/web/lib/utils.js +5 -0
  425. package/web/lib/view-memory.js +25 -0
  426. package/web/next.config.mjs +37 -0
  427. package/web/postcss.config.mjs +1 -0
  428. package/web/proxy.js +25 -0
  429. package/web/public/sw.js +39 -0
  430. package/web/server/auth.js +178 -0
  431. package/web/server/dispatch.js +293 -0
  432. package/web/server/history.js +56 -0
  433. package/web/server/hosted.js +58 -0
  434. package/web/server/hub.js +126 -0
  435. package/web/server/instance.js +5 -0
  436. package/web/server/land-reviews.js +64 -0
  437. package/web/server/push.js +148 -0
  438. package/web/server/run-terminal.js +79 -0
  439. package/web/server/schedules.js +38 -0
  440. package/web/server/shipped.js +51 -0
  441. package/web/server/task-board.js +71 -0
  442. package/web/server/threads.js +209 -0
  443. package/web/server/ui.js +2937 -0
  444. package/web/tsconfig.base.json +16 -0
  445. package/web/tsconfig.json +9 -0
@@ -0,0 +1,275 @@
1
+ "use client";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { ArrowUp, Check, ChevronDown, X } from "lucide-react";
4
+ import { Button } from "@/components/ui/button";
5
+ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
6
+ import { Textarea } from "@/components/ui/textarea";
7
+ import { HarnessLogo } from "./logos";
8
+ import { cn } from "@/lib/utils";
9
+ import { activeModel, codeModeField, flatModels, modeChoice, modeOptions, modelGroups, modelLabel, moveActive, harnessPlaces } from "@/lib/new-session";
10
+ import { EMPTY_PICK, envChoice, envOptions, envPayload } from "@/lib/branch-picker";
11
+ import { SessionToolbar } from "./session-toolbar";
12
+ import { initialChoice } from "@/lib/start-default";
13
+
14
+ export const PROMPT_PLACEHOLDER = "Plan, search, build anything";
15
+ const MODE_HINTS = { agent: "Build and edit", ask: "Answers, read-only", plan: "Plans, read-only" };
16
+
17
+ /** True on a touch-only screen (a phone), where Return types a newline and the round button sends. */
18
+ function useCoarsePointer() {
19
+ const [coarse, setCoarse] = useState(false);
20
+ useEffect(() => {
21
+ const query = window.matchMedia("(pointer: coarse)");
22
+ const sync = () => setCoarse(query.matches);
23
+ sync();
24
+ query.addEventListener("change", sync);
25
+ return () => query.removeEventListener("change", sync);
26
+ }, []);
27
+ return coarse;
28
+ }
29
+
30
+ /** The round button at a pill row's start; the popover it opens carries the choices. */
31
+ function Pill({ open, label, className, children, ...props }) {
32
+ return <PopoverTrigger asChild>
33
+ <button type="button" aria-label={label} title={label} {...props}
34
+ className={cn("flex h-7 min-w-0 shrink-0 items-center gap-1 rounded-md px-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground disabled:pointer-events-none disabled:opacity-50",
35
+ open && "bg-muted text-foreground", className)}>
36
+ {children}
37
+ <ChevronDown className="size-3 shrink-0 opacity-60"/>
38
+ </button>
39
+ </PopoverTrigger>;
40
+ }
41
+
42
+ /** A harness logo in a small disc, so a model row reads as its harness at a glance. */
43
+ function Mark({ harness }) {
44
+ return <span aria-hidden className="grid size-4 shrink-0 place-items-center rounded-md bg-muted">
45
+ <HarnessLogo peer={harness} className="size-2.5 text-foreground/70"/>
46
+ </span>;
47
+ }
48
+
49
+ /** A menu heading above a run of rows. */
50
+ function MenuLabel({ children }) {
51
+ return <p className="px-2 pb-0.5 pt-1.5 text-xs font-medium text-muted-foreground">{children}</p>;
52
+ }
53
+
54
+ function ModePill({ mode, harness, set }) {
55
+ const [open, setOpen] = useState(false);
56
+ const options = modeOptions(harness);
57
+ const current = options.find(option => option.id === mode) || options[0];
58
+ if (!current) return null;
59
+ return <Popover open={open} onOpenChange={setOpen}>
60
+ <Pill open={open} label={"Mode: " + current.label}>
61
+ <span className="truncate font-medium text-foreground">{current.label}</span>
62
+ </Pill>
63
+ <PopoverContent className="w-56">
64
+ <MenuLabel>Mode</MenuLabel>
65
+ <div role="listbox" aria-label="Mode">
66
+ {options.map(option => <button type="button" role="option" aria-selected={option.id === current.id} key={option.id}
67
+ onClick={() => { set(option.id); setOpen(false); }}
68
+ className="flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-sm outline-hidden hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent">
69
+ <span className="flex min-w-0 flex-1 flex-col">
70
+ <span className="truncate">{option.label}</span>
71
+ <span className="truncate text-xs text-muted-foreground">{MODE_HINTS[option.id] || option.id}</span>
72
+ </span>
73
+ {option.id === current.id && <Check className="size-3.5 shrink-0 text-primary"/>}
74
+ </button>)}
75
+ </div>
76
+ </PopoverContent>
77
+ </Popover>;
78
+ }
79
+
80
+ /** Where the start goes: a new thread, or one of the project's threads (the agent joins its worktree). */
81
+ function ThreadPill({ threads, thread, set }) {
82
+ const [open, setOpen] = useState(false);
83
+ const current = threads.find(item => item.id === thread);
84
+ const label = current ? current.title || "Untitled" : "New thread";
85
+ const options = [{ id: "", title: "New thread" }, ...threads];
86
+ return <Popover open={open} onOpenChange={setOpen}>
87
+ <Pill open={open} label={"Thread: " + label} className="min-w-0 shrink">
88
+ <span className="min-w-0 max-w-48 truncate font-medium text-foreground sm:max-w-72">{label}</span>
89
+ </Pill>
90
+ <PopoverContent className="max-h-80 w-72 overflow-y-auto">
91
+ <MenuLabel>Start in</MenuLabel>
92
+ <div role="listbox" aria-label="Thread">
93
+ {options.map(option => <button type="button" role="option" aria-selected={option.id === thread} key={option.id || "new"}
94
+ onClick={() => { set(option.id); setOpen(false); }}
95
+ className="flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-sm outline-hidden hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent">
96
+ <span className={cn("min-w-0 flex-1 truncate", !option.id && "font-medium")}>{option.id ? option.title || "Untitled" : "New thread"}</span>
97
+ {option.id === thread && <Check className="size-3.5 shrink-0 text-primary"/>}
98
+ </button>)}
99
+ </div>
100
+ </PopoverContent>
101
+ </Popover>;
102
+ }
103
+
104
+ function ModelPill({ choice, startable, models, set }) {
105
+ const [open, setOpen] = useState(false);
106
+ const [query, setQuery] = useState("");
107
+ const [active, setActive] = useState(0);
108
+ // A fresh open starts from the whole list, like Cursor's model menu.
109
+ useEffect(() => { if (!open) { setQuery(""); setActive(0); } }, [open]);
110
+ useEffect(() => { setActive(0); }, [query]);
111
+ const groups = useMemo(() => modelGroups({ startable, models, query }), [startable, models, query]);
112
+ const listed = useMemo(() => flatModels(groups), [groups]);
113
+ // Where each harness's run starts in the flat list, so a row knows its keyboard index without a search.
114
+ const offsets = useMemo(() => groups.map((_, i) => groups.slice(0, i).reduce((at, group) => at + group.models.length, 0)), [groups]);
115
+ const pick = item => { set(item); setOpen(false); };
116
+ const loading = Object.keys(models || {}).length === 0;
117
+ // The keyboard position is clamped to the list, so a shorter result set never hides the highlight.
118
+ const cursor = Math.min(active, Math.max(listed.length - 1, 0));
119
+ return <Popover open={open} onOpenChange={setOpen}>
120
+ <Pill open={open} label={"Model: " + modelLabel(choice)} className="min-w-0 flex-1 shrink sm:flex-none">
121
+ <Mark harness={choice.harness}/>
122
+ <span className="min-w-0 max-w-40 truncate font-medium text-foreground sm:max-w-56">{modelLabel(choice)}</span>
123
+ </Pill>
124
+ <PopoverContent className="w-[min(22rem,calc(100vw-1.5rem))] p-0">
125
+ <div className="border-b p-2">
126
+ <input autoFocus value={query} onChange={event => setQuery(event.target.value)}
127
+ onKeyDown={event => {
128
+ if (event.key === "ArrowDown") { setActive(moveActive(cursor, 1, listed.length)); event.preventDefault(); }
129
+ else if (event.key === "ArrowUp") { setActive(moveActive(cursor, -1, listed.length)); event.preventDefault(); }
130
+ else if (event.key === "Enter") {
131
+ const item = activeModel(listed, cursor);
132
+ if (item) { pick(item); event.preventDefault(); }
133
+ }
134
+ }}
135
+ aria-label="Search models" placeholder="Search models" role="combobox" aria-expanded="true" aria-controls="model-list"
136
+ className="h-8 w-full rounded-lg bg-transparent px-2 text-sm outline-none placeholder:text-muted-foreground"/>
137
+ </div>
138
+ <div id="model-list" role="listbox" aria-label="Models" className="max-h-72 overflow-y-auto p-1">
139
+ {listed.length === 0 ? <p className="px-2 py-6 text-center text-xs text-muted-foreground">
140
+ {loading ? "Models are still loading." : "No model matches."}</p>
141
+ : groups.map((group, groupIndex) => <div key={group.harness} role="group" aria-label={group.label}>
142
+ <MenuLabel>{group.label}</MenuLabel>
143
+ {group.models.map((model, indexInGroup) => {
144
+ const selected = group.harness === choice.harness && model === choice.model;
145
+ const index = offsets[groupIndex] + indexInGroup;
146
+ return <button type="button" role="option" aria-selected={selected} key={group.harness + ":" + model}
147
+ onMouseEnter={() => setActive(index)} onClick={() => pick({ harness: group.harness, model })}
148
+ className={cn("flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-sm",
149
+ index === cursor && "bg-accent text-accent-foreground")}>
150
+ <span className={cn("min-w-0 flex-1 truncate font-mono text-xs", selected && "font-semibold")}>{model}</span>
151
+ {selected && <Check className="size-3.5 shrink-0 text-primary"/>}
152
+ </button>;
153
+ })}
154
+ </div>)}
155
+ </div>
156
+ </PopoverContent>
157
+ </Popover>;
158
+ }
159
+
160
+ /** Native code mode on or off for this start; shown only for a harness whose start can use it. */
161
+ function CodeModePill({ harness, mode, place, on, set }) {
162
+ if (codeModeField(harness, on, mode, place).codeMode === undefined) return null;
163
+ const label = "Code mode: " + (on ? "on" : "off");
164
+ return <button type="button" aria-label={label} title={label} aria-pressed={on} onClick={() => set(!on)}
165
+ className={cn("flex h-7 shrink-0 items-center gap-1 rounded-md px-1.5 font-mono text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
166
+ on && "text-foreground")}>
167
+ {"{}"}<span className="truncate">{on ? "Code" : "Code off"}</span>
168
+ </button>;
169
+ }
170
+
171
+ /**
172
+ * The new-agent dialogue, shaped like Cursor's composer: the prompt first, then one pill row (mode, model, place) with
173
+ * a round send button at its end. The harness comes from the chosen model, never from text typed into the prompt.
174
+ */
175
+ export function NewAgentComposer({ project, agents = [], startable = [], places: offered = ["folder"], startPlace = "folder", sandboxHarnesses = [], models = {}, startDefault, codeModeDefault = true, disabled, start, close, open, threads = [], thread = "", setThread = () => {} }) {
176
+ const [choice, setChoice] = useState(() => initialChoice({ startable, models, setting: startDefault }));
177
+ const [codeMode, setCodeMode] = useState(codeModeDefault !== false);
178
+ const [mode, setMode] = useState(() => modeChoice("agent", choice.harness));
179
+ const places = harnessPlaces(offered, choice.harness, sandboxHarnesses);
180
+ const [env, setEnv] = useState(() => envChoice("", envOptions(places), startPlace));
181
+ // An env picked on the toolbar outranks the configured place while the harness can still use it.
182
+ const envPicked = useRef(false);
183
+ const [pick, setPick] = useState(EMPTY_PICK);
184
+ const [current, setCurrent] = useState("");
185
+ const place = env === "existing" ? "worktree" : env;
186
+ const [result, setResult] = useState(null);
187
+ const [posting, setPosting] = useState(false);
188
+ const [draft, setDraft] = useState("");
189
+ // A picked model or harness outranks the configured default when the model lists arrive later.
190
+ const picked = useRef(false);
191
+ const busy = disabled || posting;
192
+ const coarse = useCoarsePointer();
193
+ // The session's chat opens once its status arrives, as the old panel did; a failed start keeps the panel.
194
+ const joined = result?.session && agents.some(agent => agent.id === result.session) ? result.session : "";
195
+
196
+ useEffect(() => {
197
+ if (!joined) return;
198
+ close();
199
+ open(joined);
200
+ }, [joined]);
201
+ useEffect(() => {
202
+ // A pick outranks the default, but only while the project can still start it (a peer removed, a CLI gone).
203
+ if (picked.current && startable.includes(choice.harness)) return;
204
+ picked.current = false;
205
+ const next = initialChoice({ startable, models, setting: startDefault });
206
+ setChoice(current => (current.harness === next.harness && current.model === next.model ? current : next));
207
+ }, [startable, models, startDefault, choice.harness]);
208
+ // A harness change keeps the mode when it still supports it, else takes its first.
209
+ useEffect(() => { setMode(current => modeChoice(current, choice.harness)); }, [choice.harness]);
210
+ // A place can vanish when the project's snapshot changes (a sandbox stopped, a worktree no longer possible).
211
+ useEffect(() => { setEnv(current => envChoice(envPicked.current ? current : "", envOptions(places), startPlace)); }, [places.join(","), startPlace]);
212
+ useEffect(() => { setPick(EMPTY_PICK); }, [env]);
213
+
214
+ // A start in a thread runs in that thread's worktree, so place and code mode drop out (web/server/ui.ts start).
215
+ const inThread = Boolean(thread) && threads.some(item => item.id === thread);
216
+ const canSend = !busy && Boolean(draft.trim()) && Boolean(choice.harness) && (inThread || env !== "existing" || Boolean(pick.worktreePath));
217
+ const failure = result && result.status !== "started" ? [result.status, result.detail].filter(Boolean).join(" · ") : "";
218
+
219
+ async function submit() {
220
+ const prompt = draft.trim();
221
+ if (!canSend || !prompt) return;
222
+ setPosting(true);
223
+ setResult(null);
224
+ try {
225
+ // A new worktree always names its base, so the toolbar's "from main" is what git uses.
226
+ const where = envPayload(env, env === "worktree" ? { ...pick, base: pick.base || current || "HEAD" } : pick);
227
+ const payload = { harness: choice.harness, prompt, startMode: mode, ...(inThread ? { thread } : where), ...(choice.model ? { model: choice.model } : {}), ...(inThread ? {} : codeModeField(choice.harness, codeMode, mode, place)) };
228
+ const next = await start(payload);
229
+ setResult(next);
230
+ if (next?.status === "started") setDraft("");
231
+ } catch (error) {
232
+ setResult({ status: "failed", detail: error.message });
233
+ } finally {
234
+ setPosting(false);
235
+ }
236
+ }
237
+ // Enter sends from a keyboard; Shift+Enter keeps the newline; Escape closes. A phone's return key types a newline,
238
+ // because there the send button is the way to submit.
239
+ function onKeyDown(event) {
240
+ if (event.key === "Escape") { event.preventDefault(); close(); return; }
241
+ if (coarse || event.key !== "Enter" || event.shiftKey || event.isComposing) return;
242
+ event.preventDefault();
243
+ submit();
244
+ }
245
+
246
+ return <section aria-label="New session" className="mx-auto mt-2 w-full max-w-3xl">
247
+ <div className="rounded-2xl bg-card p-2 shadow-surface focus-within:ring-2 focus-within:ring-ring">
248
+ <div className="flex items-center justify-between gap-2 px-1 pb-1">
249
+ <h2 className="flex min-w-0 items-center gap-1 text-xs text-muted-foreground">
250
+ <span className="shrink-0">Start in <span className="font-medium text-foreground">{project}</span> →</span>
251
+ <ThreadPill threads={threads} thread={inThread ? thread : ""} set={setThread}/>
252
+ </h2>
253
+ <Button type="button" variant="ghost" size="icon-xs" aria-label="Close new session" disabled={posting} onClick={close}><X/></Button>
254
+ </div>
255
+ {startable.length === 0 ? <p className="px-2 pb-2 pt-1 text-sm text-muted-foreground">No harness is installed and configured for this project.</p>
256
+ : <>
257
+ <Textarea id="new-agent-prompt" aria-label="Prompt" value={draft} onChange={event => setDraft(event.target.value)} onKeyDown={onKeyDown}
258
+ placeholder={PROMPT_PLACEHOLDER} disabled={busy} rows={3} autoFocus
259
+ className="min-h-24 resize-none border-0 bg-transparent px-2 py-1 text-base shadow-none field-sizing-content focus-visible:ring-0 md:text-base dark:bg-transparent"/>
260
+ <div className="flex items-center gap-1 px-0.5 pt-1">
261
+ <ModePill mode={mode} harness={choice.harness} set={setMode}/>
262
+ <ModelPill choice={choice} startable={startable} models={models} set={item => { picked.current = true; setChoice(item); }}/>
263
+ {!inThread && <CodeModePill place={place} mode={mode} harness={choice.harness} on={codeMode} set={setCodeMode}/>}
264
+ <Button type="button" size="icon" aria-label="Start session" disabled={!canSend} onClick={submit}
265
+ className="ml-auto size-8 shrink-0 rounded-md"><ArrowUp/></Button>
266
+ </div>
267
+ </>}
268
+ </div>
269
+ {startable.length > 0 && !inThread && <SessionToolbar project={project} places={places} env={env} setEnv={next => { envPicked.current = true; setEnv(next); }}
270
+ pick={pick} setPick={setPick} setCurrent={setCurrent} disabled={busy}/>}
271
+ {failure && <p role="status" data-new-session-status="failed" className="px-2 pt-1.5 text-xs text-destructive">{failure}</p>}
272
+ {result?.status === "started" && <p role="status" data-new-session-status="started" className="px-2 pt-1.5 text-xs text-muted-foreground">
273
+ {[result.detail, result.warning].filter(Boolean).join(" · ")}{result.session && !joined ? " · waiting for " + result.session.split("#")[1] + " to report" : ""}</p>}
274
+ </section>;
275
+ }
@@ -0,0 +1,180 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ import { Bell, BellOff, BellRing } from "lucide-react";
4
+ import { toast } from "sonner";
5
+ import { Button } from "@/components/ui/button";
6
+ import { cn } from "@/lib/utils";
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
8
+ import { ALERT_LEVELS, AlertLevelItems } from "./alert-level";
9
+ import { isAlertLevel, readRememberedAlertLevel, rememberAlertLevel, shownAlertLevel, subscriptionUsesKey } from "@/lib/alert-level";
10
+
11
+ const STATES = {
12
+ loading: ["checking", Bell], off: ["off", Bell], on: ["on", BellRing],
13
+ blocked: ["blocked by browser", BellOff], unsupported: ["unsupported", BellOff], install: ["needs Home Screen app", BellOff],
14
+ };
15
+ const HINTS = {
16
+ blocked: "Allow notifications for this site in the browser's site settings, then reload.",
17
+ unsupported: "This browser cannot receive push notifications here. Use Chrome or Firefox over the HTTPS address.",
18
+ install: "On iPhone or iPad, add Temmo to the Home Screen and open it from there.",
19
+ };
20
+
21
+ // Decisions the bell lists before pointing at the inbox.
22
+ const BELL_ITEMS = 5;
23
+
24
+ const supported = () => typeof window !== "undefined" && window.isSecureContext && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
25
+ const apple = () => /iPad|iPhone|iPod/.test(navigator.userAgent) && !navigator.standalone;
26
+
27
+ function keyBytes(base64url) {
28
+ const raw = atob(base64url.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(base64url.length / 4) * 4, "="));
29
+ return Uint8Array.from(raw, c => c.charCodeAt(0));
30
+ }
31
+
32
+ const sameKey = subscriptionUsesKey;
33
+
34
+ async function call(method, path, body) {
35
+ const res = await fetch("/api/push/" + path, body ? { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) } : { method });
36
+ const result = await res.json().catch(() => ({}));
37
+ if (!res.ok) throw new Error(result.error || "Request failed");
38
+ return result;
39
+ }
40
+
41
+ // Header bell: one Notifications menu with the browser push state, its actions, and the phone alert level.
42
+ // level is the server's stored level; undefined before the first state frame, so the last choice shows instead.
43
+ /** One line for a pending decision: the approval's summary, the suspension's title, or the question itself. */
44
+ function decisionText(item) {
45
+ if (item.approval) return item.approval.summary || item.approval.tool || "Approval";
46
+ if (item.suspension) return item.suspension.title || item.suspension.prompt || "Run waits to resume";
47
+ const lines = String(item.body || "").split("\n").map(line => line.trim()).filter(line => line && !/^(Question from|Reply in this topic)/.test(line));
48
+ return (lines[0] || "Question").replace(/^IMPORTANT, the agent waits for this answer:\s*/, "");
49
+ }
50
+
51
+ /** The one bell: pending decisions from every project with their count, then this browser's push and alert controls. */
52
+ export function NotifyToggle({ level, levelDisabled = false, setLevel, decisions = [], now = 0, openInbox }) {
53
+ const [state, setState] = useState("loading");
54
+ const [busy, setBusy] = useState(false);
55
+
56
+ useEffect(() => {
57
+ if (!supported()) { setState(apple() ? "install" : "unsupported"); return; }
58
+ let live = true;
59
+ // A tapped notification asks an open tab to show the item's thread.
60
+ const onMessage = event => {
61
+ const hash = event.data?.type === "temmo-open" && event.data.hash;
62
+ if (typeof hash === "string" && hash.startsWith("#")) location.hash = hash;
63
+ };
64
+ navigator.serviceWorker.addEventListener("message", onMessage);
65
+ navigator.serviceWorker.register("/sw.js", { scope: "/" })
66
+ .then(reg => reg.pushManager.getSubscription())
67
+ .then(async sub => {
68
+ if (!live) return;
69
+ if (Notification.permission === "denied") return setState("blocked");
70
+ if (!sub || Notification.permission !== "granted") return setState("off");
71
+ // A subscription made with an older VAPID key can never be delivered to; replace it before claiming "on".
72
+ const { publicKey } = await call("GET", "key").catch(() => ({}));
73
+ const key = publicKey ? keyBytes(publicKey) : null;
74
+ if (key && !sameKey(sub, key)) {
75
+ await sub.unsubscribe().catch(() => {});
76
+ sub = await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key }).catch(() => null);
77
+ if (!live) return;
78
+ if (!sub) return setState("off");
79
+ }
80
+ setState("on");
81
+ // The server drops subscriptions the push service reports gone; resend so it holds this one.
82
+ await call("POST", "subscribe", { subscription: sub.toJSON() }).catch(() => {});
83
+ })
84
+ .catch(() => live && setState("unsupported"));
85
+ return () => { live = false; navigator.serviceWorker.removeEventListener("message", onMessage); };
86
+ }, []);
87
+
88
+ async function enable() {
89
+ // Firefox shows the prompt only from a user gesture, so requestPermission runs before any other await.
90
+ const permission = Notification.permission === "granted" ? "granted" : await Notification.requestPermission();
91
+ if (permission !== "granted") { setState(permission === "denied" ? "blocked" : "off"); return; }
92
+ setBusy(true);
93
+ try {
94
+ const [reg, { publicKey }] = await Promise.all([navigator.serviceWorker.ready, call("GET", "key")]);
95
+ const key = keyBytes(publicKey);
96
+ let sub = await reg.pushManager.getSubscription();
97
+ if (sub && !sameKey(sub, key)) { await sub.unsubscribe(); sub = null; }
98
+ sub ||= await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: key });
99
+ await call("POST", "subscribe", { subscription: sub.toJSON() });
100
+ setState("on");
101
+ toast.success("Notifications on");
102
+ } catch (err) {
103
+ toast.error("Notifications failed: " + err.message);
104
+ } finally {
105
+ setBusy(false);
106
+ }
107
+ }
108
+
109
+ async function disable() {
110
+ setBusy(true);
111
+ try {
112
+ const sub = await (await navigator.serviceWorker.ready).pushManager.getSubscription();
113
+ if (sub) {
114
+ await call("DELETE", "subscribe", { endpoint: sub.endpoint }).catch(() => {});
115
+ await sub.unsubscribe();
116
+ }
117
+ setState("off");
118
+ toast.success("Notifications off");
119
+ } catch (err) {
120
+ toast.error("Could not turn notifications off: " + err.message);
121
+ } finally {
122
+ setBusy(false);
123
+ }
124
+ }
125
+
126
+ async function test() {
127
+ setBusy(true);
128
+ try {
129
+ const sub = await (await navigator.serviceWorker.ready).pushManager.getSubscription();
130
+ if (!sub) throw new Error("this browser is not subscribed");
131
+ await call("POST", "test", { endpoint: sub.endpoint });
132
+ toast.success("Test sent");
133
+ } catch (err) {
134
+ toast.error("Test failed: " + err.message);
135
+ } finally {
136
+ setBusy(false);
137
+ }
138
+ }
139
+
140
+ // The server's level wins; before the first state frame (and after a deploy reload) this browser's last choice shows.
141
+ const shown = shownAlertLevel(level, readRememberedAlertLevel(globalThis.localStorage));
142
+ const choose = next => {
143
+ if (!isAlertLevel(next)) return;
144
+ rememberAlertLevel(globalThis.localStorage, next);
145
+ setLevel?.(next);
146
+ };
147
+ const [label, Icon] = STATES[state];
148
+ const alerts = ALERT_LEVELS.find(([id]) => id === shown)?.[1] || "All";
149
+ const pending = decisions.filter(item => !(item.expiresAt && item.expiresAt < now));
150
+ const count = pending.length;
151
+ const summary = (count ? count + (count === 1 ? " decision waits" : " decisions wait") + " on you · " : "") + "Notifications: " + label + " · phone alerts " + alerts;
152
+ return <DropdownMenu>
153
+ <DropdownMenuTrigger asChild>
154
+ <Button variant="ghost" size={count ? "default" : "icon"} aria-label={summary} title={summary} data-state-push={state} data-decisions={count} disabled={levelDisabled}
155
+ className={cn(count > 0 && "gap-1 px-2 text-primary")}>
156
+ <Icon/>{count > 0 && <span className="text-xs font-semibold tabular-nums">{count}</span>}
157
+ </Button>
158
+ </DropdownMenuTrigger>
159
+ <DropdownMenuContent align="end" side="top" className="w-80 max-w-[calc(100vw-1rem)]">
160
+ <DropdownMenuLabel>{count ? "Waiting on you · " + count : "No decisions waiting"}</DropdownMenuLabel>
161
+ {pending.slice(0, BELL_ITEMS).map(item => <DropdownMenuItem key={item.project + ":" + item.key} onSelect={() => openInbox?.()} className="flex-col items-start gap-0.5">
162
+ <span className="line-clamp-2 w-full text-sm [overflow-wrap:anywhere]">{decisionText(item)}</span>
163
+ <span className="text-xs text-muted-foreground">{item.project} · {item.agentName || item.from}</span>
164
+ </DropdownMenuItem>)}
165
+ {openInbox && <DropdownMenuItem onSelect={openInbox} className="font-medium text-primary">
166
+ {count > BELL_ITEMS ? "All " + count + " in the decision inbox" : "Open decision inbox"}
167
+ </DropdownMenuItem>}
168
+ <DropdownMenuSeparator/>
169
+ <DropdownMenuLabel>Browser push · {label}</DropdownMenuLabel>
170
+ <DropdownMenuSeparator/>
171
+ {state === "off" && <DropdownMenuItem disabled={busy} onSelect={enable}>Turn on</DropdownMenuItem>}
172
+ {state === "on" && <>
173
+ <DropdownMenuItem disabled={busy} onSelect={test}>Send test</DropdownMenuItem>
174
+ <DropdownMenuItem disabled={busy} onSelect={disable}>Turn off</DropdownMenuItem>
175
+ </>}
176
+ {HINTS[state] && <p className="px-2 py-1.5 text-xs text-muted-foreground">{HINTS[state]}</p>}
177
+ <AlertLevelItems level={shown} set={choose}/>
178
+ </DropdownMenuContent>
179
+ </DropdownMenu>;
180
+ }
@@ -0,0 +1,94 @@
1
+ import { Input } from "@ui-sdk/react/input";
2
+ import { Button } from "@/components/ui/button";
3
+ import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet";
4
+
5
+ type OutcomeRequestProps = {
6
+ project: string;
7
+ close: () => void;
8
+ submit: (fields: { outcome: string; check: string }) => void;
9
+ disabled: boolean;
10
+ error: string;
11
+ };
12
+
13
+ type OutcomeCardsProps = {
14
+ outcomes?: Array<{
15
+ id: string;
16
+ outcome: string;
17
+ check: string;
18
+ state: "requested" | "proposed" | "approved" | "closed";
19
+ taskIds?: string[];
20
+ titles?: string[];
21
+ result?: { passed: boolean; text: string; revision: string };
22
+ }>;
23
+ tasks: Array<{ id: string; title: string; status: string }>;
24
+ inspect: (id: string) => void;
25
+ controls: {
26
+ disabled: boolean;
27
+ paused: boolean;
28
+ act: (action: "approve-outcome" | "accept-outcome", fields: { id: string; revision?: string }, message: string) => void;
29
+ };
30
+ };
31
+
32
+ const INPUT_CLASS = "min-h-11 rounded-md border bg-background px-3 text-base";
33
+
34
+ export function OutcomeRequest({ project, close, submit, disabled, error }: OutcomeRequestProps) {
35
+ return <Sheet open={Boolean(project)} onOpenChange={(open: boolean) => { if (!open) close(); }}>
36
+ <SheetContent side="bottom" className="max-h-dvh overflow-y-auto p-4 sm:px-8">
37
+ <SheetTitle>Request an outcome</SheetTitle>
38
+ <SheetDescription>The PM will propose tasks for {project}.</SheetDescription>
39
+ <form key={project} className="flex flex-col gap-4" onSubmit={event => {
40
+ event.preventDefault();
41
+ const fields = new FormData(event.currentTarget);
42
+ const outcome = fields.get("outcome");
43
+ const check = fields.get("check");
44
+ if (typeof outcome === "string" && typeof check === "string") submit({ outcome, check });
45
+ }}>
46
+ <label className="grid gap-1">Requested outcome
47
+ <Input name="outcome" required maxLength={500} className={INPUT_CLASS}/>
48
+ </label>
49
+ <label className="grid gap-1">Acceptance check
50
+ <Input name="check" required maxLength={500} className={INPUT_CLASS}/>
51
+ </label>
52
+ {error && <p role="alert" className="text-destructive">{error}</p>}
53
+ <Button disabled={disabled} className="min-h-11 self-start">Send to PM</Button>
54
+ </form>
55
+ </SheetContent>
56
+ </Sheet>;
57
+ }
58
+
59
+ export function OutcomeCards({ outcomes, tasks, inspect, controls }: OutcomeCardsProps) {
60
+ if (!outcomes?.length) return null;
61
+ const byId = new Map(tasks.map(task => [task.id, task]));
62
+ return <section aria-label="Project outcomes" className="grid gap-2">
63
+ {outcomes.map(entry => {
64
+ const result = entry.result;
65
+ const linked = entry.taskIds?.map(id => byId.get(id));
66
+ const done = linked?.every(task => task?.status === "done");
67
+ const status = {
68
+ requested: "Open · Waiting for PM proposal",
69
+ proposed: "Open · Waiting for approval",
70
+ approved: done ? "Open · Acceptance check" : "Open · Tasks in progress",
71
+ closed: "Closed",
72
+ }[entry.state];
73
+ return <article key={entry.id} className="grid gap-2 rounded-xl bg-card shadow-surface p-3 text-sm [overflow-wrap:anywhere]">
74
+ <h2 className="font-semibold">{entry.outcome}</h2>
75
+ <p className="text-muted-foreground">{status}</p>
76
+ <p><strong>Acceptance check</strong> · {entry.check}</p>
77
+ {entry.titles && <ul className="grid gap-1">
78
+ {entry.titles.map((title, index) => {
79
+ const task = linked?.[index];
80
+ return <li key={title}>{task ? <button type="button" className="min-h-9 text-left underline" onClick={() => inspect(task.id)}>
81
+ {task.title}{task.status === "done" ? " · Done" : ""}
82
+ </button> : title}</li>;
83
+ })}
84
+ </ul>}
85
+ {entry.state === "approved" && done && !result && <p>Waiting for the PM to report the result.</p>}
86
+ {result && <p><strong>{result.passed ? "Passed" : "Failed"}</strong> · {result.text}</p>}
87
+ {entry.state === "proposed" && <Button className="min-h-11 justify-self-start" disabled={controls.disabled || controls.paused}
88
+ onClick={() => controls.act("approve-outcome", { id: entry.id }, "Plan approved")}>Approve plan</Button>}
89
+ {entry.state === "approved" && done && result?.passed && <Button className="min-h-11 justify-self-start" disabled={controls.disabled}
90
+ onClick={() => controls.act("accept-outcome", { id: entry.id, revision: result.revision }, "Outcome closed")}>Accept result and close</Button>}
91
+ </article>;
92
+ })}
93
+ </section>;
94
+ }
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import dynamic from "next/dynamic";
3
+
4
+ // The chat reads location.hash and the DOM, so it renders only in the browser.
5
+ const Chat = dynamic(() => import("./chat.jsx"), { ssr: false });
6
+
7
+ export default function Page() {
8
+ return <Chat/>;
9
+ }
@@ -0,0 +1,75 @@
1
+ import { useId, useState } from "react";
2
+ import { Button } from "@/components/ui/button";
3
+ import { cn } from "@/lib/utils";
4
+ import { NODE_H, NODE_W, edgeLines, layoutGraph, nodeTitle } from "@/lib/pattern-graph";
5
+ import { firedCounts } from "@/lib/pattern-view";
6
+
7
+ // Nodes are roles, arrows are handoffs: solid when required, dashed for guidance. `used` is a run; `active` names the node it is on.
8
+ export function RoleGraph({ graph, active = "", used = null, label = "Pattern graph" }) {
9
+ const markerId = "arrow" + useId().replace(/[^a-zA-Z0-9]/g, "");
10
+ const geo = layoutGraph(graph);
11
+ const fired = used ? firedCounts(used) : null;
12
+ return <svg viewBox={`0 0 ${geo.width} ${geo.height}`} role="img" aria-label={label} className="h-auto w-full text-muted-foreground">
13
+ <defs>
14
+ <marker id={markerId} viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
15
+ <path d="M0,0 L10,5 L0,10 z" className="fill-current"/>
16
+ </marker>
17
+ </defs>
18
+ {geo.edges.map(edge => {
19
+ const [first, second] = edgeLines(edge, fired ? fired(edge) : null);
20
+ const width = Math.max(first.length, second.length) * 6.6 + 14;
21
+ const left = edge.anchor === "end" ? edge.lx - width + 4 : edge.anchor === "middle" ? edge.lx - width / 2 : edge.lx - 4;
22
+ const x = edge.anchor === "start" ? edge.lx + 4 : edge.lx;
23
+ return <g key={edge.index}>
24
+ <path d={edge.path} fill="none" className="stroke-current" strokeWidth="1.5" strokeDasharray={edge.required ? undefined : "5 4"} markerEnd={`url(#${markerId})`}>
25
+ <title>{`${edge.from} → ${edge.to}: "${edge.on}" (${edge.required ? "required" : "guidance"}, ${edge.kind})`}</title>
26
+ </path>
27
+ <rect x={left} y={edge.ly - 15} width={width} height={30} rx={8} className="fill-background stroke-border" strokeWidth="1"/>
28
+ <text x={x} y={edge.ly - 2} textAnchor={edge.anchor} fontSize="11" className="fill-foreground font-mono">{first}</text>
29
+ <text x={x} y={edge.ly + 11} textAnchor={edge.anchor} fontSize="10" className="fill-muted-foreground font-mono">{second}</text>
30
+ </g>;
31
+ })}
32
+ {geo.nodes.map(node => {
33
+ const isActive = node.id === active;
34
+ const detail = [node.agent, node.skill].filter(Boolean).join(" · ");
35
+ return <g key={node.id}>
36
+ <rect x={node.x} y={node.y} width={NODE_W} height={NODE_H} rx={10} strokeWidth="1.5"
37
+ className={cn(isActive ? "fill-primary stroke-primary" : node.done ? "fill-muted stroke-border" : "fill-card stroke-border")}>
38
+ <title>{node.id}</title>
39
+ </rect>
40
+ <text x={node.x + NODE_W / 2} y={node.y + 19} textAnchor="middle" fontSize="13" fontWeight="600" className={cn("font-mono", isActive ? "fill-primary-foreground" : "fill-foreground")}>{nodeTitle(node)}</text>
41
+ {detail && <text x={node.x + NODE_W / 2} y={node.y + 36} textAnchor="middle" fontSize="10" className={cn(isActive ? "fill-primary-foreground" : "fill-muted-foreground")}>
42
+ {detail.length > 22 ? `${detail.slice(0, 21)}…` : detail}</text>}
43
+ {node.fallback && <text x={node.x + NODE_W / 2} y={node.y + 52} textAnchor="middle" fontSize="9" className={cn("font-mono", isActive ? "fill-primary-foreground" : "fill-muted-foreground")}>
44
+ <title>{`Fallback when the subscription runs out: ${node.fallback}`}</title>
45
+ {`fallback ${node.fallback.length > 14 ? `${node.fallback.slice(0, 13)}…` : node.fallback}`}</text>}
46
+ </g>;
47
+ })}
48
+ </svg>;
49
+ }
50
+
51
+ // One line per handoff: from -> to, the event that triggers it, and whether the run enforces it.
52
+ export function HandoffDiagram({ handoffs }) {
53
+ return <ol className="flex flex-col gap-1 font-mono text-xs">
54
+ {handoffs.map((handoff, index) => <li key={index} className="flex flex-wrap items-center gap-1">
55
+ <span className="rounded border px-1">{handoff.from}</span>
56
+ <span>→</span>
57
+ <span className="rounded border px-1">{handoff.to}</span>
58
+ <span className="text-muted-foreground">&quot;{handoff.on}&quot;</span>
59
+ <span className={handoff.required ? "text-foreground" : "text-muted-foreground"}>
60
+ {handoff.required ? "required" : "guidance"}{handoff.cap !== undefined ? ` · max ${handoff.cap}` : ""}
61
+ </span>
62
+ </li>)}
63
+ </ol>;
64
+ }
65
+
66
+ // Two clicks: the first asks, the second runs the action.
67
+ export function ConfirmButton({ label, question, confirmLabel, onConfirm, disabled, variant = "outline" }) {
68
+ const [asking, setAsking] = useState(false);
69
+ if (!asking) return <Button type="button" size="sm" variant={variant} disabled={disabled} onClick={() => setAsking(true)}>{label}</Button>;
70
+ return <span className="flex flex-wrap items-center gap-2 text-xs">
71
+ <span>{question}</span>
72
+ <Button type="button" size="sm" variant="destructive" disabled={disabled} onClick={() => { setAsking(false); onConfirm(); }}>{confirmLabel}</Button>
73
+ <Button type="button" size="sm" variant="ghost" onClick={() => setAsking(false)}>Keep</Button>
74
+ </span>;
75
+ }