@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
package/lib/tasks.js ADDED
@@ -0,0 +1,631 @@
1
+ /**
2
+ * Project task list. The default backend is a file outside git: <XDG_DATA_HOME or ~/.local/share>/temmo/tasks/<project>.json
3
+ * ({"v": 1, "tasks": [...]}), shared by every checkout. docs/feature-requests.md is a committed snapshot rendered from it.
4
+ * A missing file reads as no tasks; an invalid file throws. Writes lock, validate, then rename a temp file over the store.
5
+ */
6
+ import { randomUUID } from "node:crypto";
7
+ import { existsSync, readFileSync, unwatchFile, watchFile } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { BRANCH_NAME, COMMIT_ID, REVIEW_FILES_MAX, REVIEW_PATH_MAX, changeSummary, reviewIsCurrent } from "./build-review.js";
10
+ import { isValidName, listProjects } from "./config.js";
11
+ import { RUN_ID } from "./pattern-runs.js";
12
+ import { withLock } from "./state.js";
13
+ import { appDir } from "./names.js";
14
+ import { writeJson } from "./store.js";
15
+ import { TASK_PRIORITY_DEFAULT, TASK_PRIORITIES, priorityOf, sortTasks } from "./task-order.js";
16
+ export { TASK_PRIORITIES, TASK_PRIORITY_DEFAULT, priorityOf, sortTasks };
17
+ export const STATUSES = ["open", "decided", "building", "review", "blocked", "done"];
18
+ /** The statuses a review decision moves a task to: accept finishes it, return queues it for another build. */
19
+ export const REVIEW_ACTIONS = ["accept", "return"];
20
+ // oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime review action
21
+ const REVIEW_RESULT = { accept: "done", return: "decided" };
22
+ export const BACKENDS = ["file"];
23
+ export const BACKEND_DEFAULT = "file";
24
+ export const TASKS_VERSION = 1;
25
+ export const ID_MAX = 40;
26
+ export const TITLE_MAX = 300;
27
+ export const DETAIL_MAX = 2000;
28
+ export const PROGRESS_MAX = 500;
29
+ export const QUESTION_MAX = 500;
30
+ export const OPTION_MAX = 80;
31
+ export const OPTIONS_MAX = 6;
32
+ export const TABLE_START = "<!-- tasks:start -->";
33
+ export const TABLE_END = "<!-- tasks:end -->";
34
+ const ID_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
35
+ const OWNER_RE = /^([a-z0-9-]{1,24})#([a-f0-9]{16})$/;
36
+ const LINE_BREAK = /[\r\n]/;
37
+ // A status word must end the cell or precede a separator; "building-ish" is no status.
38
+ // A status word, case-insensitive, then the end, a space or punctuation, or a dash set off by spaces; "open-ended" is no status.
39
+ const STATUS_CELL = /^(open|decided|building|review|blocked|done)(?=$|[\s;:,(—]|\s+-(?=\s|$))/i;
40
+ const DOC_PROSE = `# Feature requests
41
+
42
+ Operator requests from chat and the terminal, newest last. Status: ${STATUSES.join(", ")} (the UI shows decided as Ready). Priority: ${TASK_PRIORITIES.join(", ")}; a missing priority is ${TASK_PRIORITY_DEFAULT}. Rows are sorted by priority, then status, then most recently updated.
43
+
44
+ Generated from the task store by \`temmo task render\`. Change tasks with \`temmo task\`, not this file.
45
+
46
+ `;
47
+ const TABLE_HEAD = "| Request | Priority | Status |\n|---|---|---|\n";
48
+ export function taskStoreDir(env = process.env) {
49
+ return join(appDir("data", env), "tasks");
50
+ }
51
+ export function taskStoreFile(project, env = process.env) {
52
+ return join(taskStoreDir(env), `${project}.json`);
53
+ }
54
+ function taskError(id, message) {
55
+ return new Error(`task ${id}: ${message}`);
56
+ }
57
+ function codePoints(text) {
58
+ return [...text].length;
59
+ }
60
+ function checkTask(t) {
61
+ const id = typeof t?.id === "string" ? t.id : "?";
62
+ if (!t || typeof t !== "object" || Array.isArray(t))
63
+ throw taskError(id, "not an object");
64
+ if (typeof t.id !== "string" || !ID_RE.test(t.id) || t.id.length > ID_MAX)
65
+ throw taskError(id, "invalid id");
66
+ if (typeof t.title !== "string" || !t.title.trim() || t.title.length > TITLE_MAX || LINE_BREAK.test(t.title))
67
+ throw taskError(id, "invalid title");
68
+ if (!STATUSES.includes(t.status))
69
+ throw taskError(id, `invalid status ${JSON.stringify(t.status)}`);
70
+ if (t.priority !== undefined && !TASK_PRIORITIES.includes(t.priority))
71
+ throw taskError(id, `invalid priority ${JSON.stringify(t.priority)}`);
72
+ if (t.detail !== undefined && (typeof t.detail !== "string" || t.detail.length > DETAIL_MAX || LINE_BREAK.test(t.detail)))
73
+ throw taskError(id, "invalid detail");
74
+ if (!Array.isArray(t.blockers) || t.blockers.some((b) => typeof b !== "string") || new Set(t.blockers).size !== t.blockers.length) {
75
+ throw taskError(id, "blockers must be unique task ids");
76
+ }
77
+ if (t.owner !== undefined) {
78
+ const match = typeof t.owner === "string" ? OWNER_RE.exec(t.owner) : null;
79
+ if (!match || !isValidName(match[1]))
80
+ throw taskError(id, "owner must be a session address like claude#0123456789abcdef");
81
+ }
82
+ if (t.run !== undefined && (typeof t.run !== "string" || !RUN_ID.test(t.run)))
83
+ throw taskError(id, "invalid run id");
84
+ if (!Array.isArray(t.progress) || t.progress.some((p) => !p || typeof p !== "object"
85
+ || !Number.isFinite(p.at) || typeof p.by !== "string" || !p.by
86
+ || typeof p.text !== "string" || !p.text.trim() || codePoints(p.text) > PROGRESS_MAX)) {
87
+ throw taskError(id, "progress must be entries of {at, by, text}");
88
+ }
89
+ if (t.review !== undefined)
90
+ checkReview(id, t.review);
91
+ if (t.question !== undefined)
92
+ checkQuestion(id, t.question);
93
+ if (!Number.isFinite(t.created) || !Number.isFinite(t.updated))
94
+ throw taskError(id, "created and updated must be timestamps");
95
+ }
96
+ const oneLine = (text, max) => typeof text === "string" && Boolean(text.trim()) && codePoints(text) <= max && !LINE_BREAK.test(text);
97
+ // A build review packet: the submitted commit, what it was asked to do, the host check, and the decision once made.
98
+ function checkReview(id, r) {
99
+ const count = (value) => Number.isInteger(value) && value >= 0;
100
+ const files = Array.isArray(r?.files) && r.files.length <= REVIEW_FILES_MAX && r.files.every((file) => file && typeof file.path === "string" && file.path && codePoints(file.path) <= REVIEW_PATH_MAX && !LINE_BREAK.test(file.path)
101
+ && count(file.insertions) && count(file.deletions));
102
+ if (!r || typeof r !== "object" || Array.isArray(r)
103
+ || typeof r.commit !== "string" || !COMMIT_ID.test(r.commit)
104
+ || typeof r.base !== "string" || !COMMIT_ID.test(r.base)
105
+ || typeof r.branch !== "string" || !BRANCH_NAME.test(r.branch)
106
+ || typeof r.submission !== "string" || !r.submission || codePoints(r.submission) > 64 || LINE_BREAK.test(r.submission)
107
+ || typeof r.criteria !== "string" || codePoints(r.criteria) > DETAIL_MAX
108
+ || !r.check || !Number.isInteger(r.check.code) || typeof r.check.text !== "string" || codePoints(r.check.text) > PROGRESS_MAX
109
+ || !files || !count(r.insertions) || !count(r.deletions) || !count(r.more) || !Number.isFinite(r.at)) {
110
+ throw taskError(id, "invalid build review packet");
111
+ }
112
+ const d = r.decision;
113
+ if (d !== undefined && (!d || typeof d !== "object" || Array.isArray(d) || !REVIEW_ACTIONS.includes(d.action)
114
+ || !Number.isFinite(d.at) || !oneLine(d.by, PROGRESS_MAX)
115
+ || (d.action === "return" ? !oneLine(d.note, PROGRESS_MAX) : d.note !== undefined))) {
116
+ throw taskError(id, "invalid build review decision");
117
+ }
118
+ }
119
+ // A question for the operator: {text, by, at, options?}; once answered it also holds answer {text, by, at}.
120
+ function checkQuestion(id, q) {
121
+ if (!q || typeof q !== "object" || Array.isArray(q) || !oneLine(q.text, QUESTION_MAX) || typeof q.by !== "string" || !q.by || !Number.isFinite(q.at)) {
122
+ throw taskError(id, "question must be {text, by, at} with one line of text");
123
+ }
124
+ if (q.options !== undefined && (!Array.isArray(q.options) || q.options.length > OPTIONS_MAX || q.options.some((o) => !oneLine(o, OPTION_MAX)))) {
125
+ throw taskError(id, `question options must be at most ${OPTIONS_MAX} one-line choices`);
126
+ }
127
+ const a = q.answer;
128
+ if (a !== undefined && (!a || typeof a !== "object" || !oneLine(a.text, QUESTION_MAX) || typeof a.by !== "string" || !a.by || !Number.isFinite(a.at))) {
129
+ throw taskError(id, "answer must be {text, by, at} with one line of text");
130
+ }
131
+ }
132
+ // Depth-first search over blocker edges; a back edge is a cycle.
133
+ function assertAcyclic(tasks) {
134
+ const byId = new Map(tasks.map((t) => [t.id, t]));
135
+ const state = new Map();
136
+ const visit = (id) => {
137
+ if (state.get(id) === "done")
138
+ return;
139
+ if (state.get(id) === "active")
140
+ throw taskError(id, "blocker cycle");
141
+ state.set(id, "active");
142
+ for (const b of byId.get(id).blockers)
143
+ visit(b);
144
+ state.set(id, "done");
145
+ };
146
+ for (const t of tasks)
147
+ visit(t.id);
148
+ }
149
+ /** Checks a whole task document and returns it; throws on the first problem. */
150
+ export function validateTasks(doc) {
151
+ if (!doc || typeof doc !== "object" || Array.isArray(doc) || doc.v !== TASKS_VERSION || !Array.isArray(doc.tasks)) {
152
+ throw new Error(`expected {"v": ${TASKS_VERSION}, "tasks": []}`);
153
+ }
154
+ const ids = new Set();
155
+ for (const t of doc.tasks) {
156
+ checkTask(t);
157
+ if (ids.has(t.id))
158
+ throw taskError(t.id, "duplicate id");
159
+ ids.add(t.id);
160
+ }
161
+ for (const t of doc.tasks) {
162
+ for (const b of t.blockers) {
163
+ if (b === t.id)
164
+ throw taskError(t.id, "blocks itself");
165
+ if (!ids.has(b))
166
+ throw taskError(t.id, `blocker ${b} is not a task`);
167
+ }
168
+ }
169
+ assertAcyclic(doc.tasks);
170
+ return doc;
171
+ }
172
+ function outcomeStep(doc, action, { id, outcome, check, titles, result, passed, by, revision }) {
173
+ const outcomes = doc.outcomes ??= [];
174
+ if (action === "request") {
175
+ if (!oneLine(outcome, 500) || !oneLine(check, 500))
176
+ throw new Error("Give an outcome and one acceptance check (up to 500 characters each)");
177
+ const entry = { id: randomUUID(), outcome: outcome.trim(), check: check.trim(), state: "requested" };
178
+ outcomes.push(entry);
179
+ return entry;
180
+ }
181
+ const entry = outcomes.find(item => item.id === id);
182
+ if (!entry)
183
+ throw new Error("Unknown outcome");
184
+ if (action === "propose" && entry.state === "requested") {
185
+ if (!Array.isArray(titles) || titles.length < 1 || titles.length > 3
186
+ || titles.some(title => !oneLine(title, TITLE_MAX) || title.length > TITLE_MAX)
187
+ || new Set(titles.map(title => title.trim())).size !== titles.length) {
188
+ throw new Error("Propose one to three distinct task titles");
189
+ }
190
+ entry.titles = titles.map(title => title.trim());
191
+ entry.state = "proposed";
192
+ }
193
+ else if (action === "approve" && entry.state === "proposed") {
194
+ entry.taskIds = entry.titles.map((title) => addTask(doc, {
195
+ title, status: "decided", detail: "Outcome: " + entry.outcome + " | Acceptance check: " + entry.check,
196
+ }).id);
197
+ entry.state = "approved";
198
+ }
199
+ else if (["report", "accept"].includes(action) && entry.state === "approved") {
200
+ if (!entry.taskIds.every((taskId) => findTask(doc, taskId).status === "done"))
201
+ throw new Error("Finish every linked task first");
202
+ if (action === "report") {
203
+ if (!oneLine(result, 500) || typeof passed !== "boolean")
204
+ throw new Error("Give a pass or fail result and evidence (up to 500 characters)");
205
+ entry.result = { text: result.trim(), passed, by, revision: randomUUID() };
206
+ }
207
+ else {
208
+ if (!entry.result?.passed || entry.result.revision !== revision)
209
+ throw new Error("Review the current passing acceptance result first");
210
+ entry.state = "closed";
211
+ }
212
+ }
213
+ else {
214
+ throw new Error("This outcome action is unavailable in its current state");
215
+ }
216
+ return entry;
217
+ }
218
+ export function readStore(file) {
219
+ if (!existsSync(file))
220
+ return { v: TASKS_VERSION, tasks: [] };
221
+ let doc;
222
+ try {
223
+ doc = JSON.parse(readFileSync(file, "utf8"));
224
+ }
225
+ catch (err) {
226
+ throw new Error(`${file}: invalid JSON: ${err.message}`);
227
+ }
228
+ try {
229
+ return validateTasks(doc);
230
+ }
231
+ catch (err) {
232
+ throw new Error(`${file}: ${err.message}`);
233
+ }
234
+ }
235
+ /** Validates, then writes through a temp file and rename so readers never see a partial file. */
236
+ export function writeStore(file, doc) {
237
+ validateTasks(doc);
238
+ writeJson(file, doc, { indent: 2 });
239
+ return doc;
240
+ }
241
+ /** A lowercase slug of at most ID_MAX chars; "task" when the title has no letters or digits. */
242
+ export function slugify(title) {
243
+ const slug = String(title).toLowerCase().replace(/[`'"]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
244
+ return slug.slice(0, ID_MAX).replace(/-+$/, "") || "task";
245
+ }
246
+ function uniqueId(doc, base) {
247
+ const taken = new Set(doc.tasks.map((t) => t.id));
248
+ if (!taken.has(base))
249
+ return base;
250
+ for (let n = 2;; n++) {
251
+ const id = `${base.slice(0, ID_MAX - String(n).length - 1).replace(/-+$/, "")}-${n}`;
252
+ if (!taken.has(id))
253
+ return id;
254
+ }
255
+ }
256
+ export class TaskNotFoundError extends Error {
257
+ }
258
+ function findTask(doc, id) {
259
+ const task = doc.tasks.find((t) => t.id === id);
260
+ if (!task)
261
+ throw new TaskNotFoundError(`no task ${id}`);
262
+ return task;
263
+ }
264
+ /** Adds a task with status open unless given; the id defaults to a slug of the title. Returns the task. */
265
+ export function addTask(doc, { id, title, detail, status = "open", priority }, now = Date.now()) {
266
+ const text = String(title ?? "").trim();
267
+ const taskId = id ?? uniqueId(doc, slugify(text));
268
+ if (doc.tasks.some((t) => t.id === taskId))
269
+ throw new Error(`task ${taskId} exists`);
270
+ const task = { id: taskId, title: text, status, ...(priority ? { priority } : {}), ...(detail ? { detail } : {}), blockers: [], progress: [], created: now, updated: now };
271
+ doc.tasks.push(task);
272
+ validateTasks(doc);
273
+ return task;
274
+ }
275
+ export function setTaskField(doc, id, field, value, now = Date.now()) {
276
+ const task = findTask(doc, id);
277
+ if (!["status", "title", "detail", "run", "priority"].includes(field))
278
+ throw new Error(`cannot set ${field}`);
279
+ if (field === "status" && !STATUSES.includes(value))
280
+ throw new Error(`invalid status ${value}`);
281
+ if (field === "priority" && !TASK_PRIORITIES.includes(value))
282
+ throw new Error(`invalid priority ${value}`);
283
+ task[field] = value;
284
+ task.updated = now;
285
+ return task;
286
+ }
287
+ /** Records that task `id` is blocked on task `on`. */
288
+ export function blockTask(doc, id, on, now = Date.now()) {
289
+ const task = findTask(doc, id);
290
+ if (!task.blockers.includes(on))
291
+ task.blockers.push(on);
292
+ task.updated = now;
293
+ return task;
294
+ }
295
+ export function ownTask(doc, id, address, now = Date.now()) {
296
+ const task = findTask(doc, id);
297
+ task.owner = address;
298
+ task.updated = now;
299
+ return task;
300
+ }
301
+ /** Removes a task; refuses while another task still lists it as a blocker, naming those tasks. Returns the task. */
302
+ export function removeTask(doc, id) {
303
+ const task = findTask(doc, id);
304
+ if (doc.outcomes?.some(entry => entry.taskIds?.includes(id)))
305
+ throw taskError(id, "linked to a project outcome");
306
+ const dependents = doc.tasks.filter((t) => t.blockers.includes(id)).map((t) => t.id);
307
+ if (dependents.length)
308
+ throw taskError(id, `blocked on by ${dependents.join(", ")}; unblock them first`);
309
+ doc.tasks.splice(doc.tasks.indexOf(task), 1);
310
+ validateTasks(doc);
311
+ return task;
312
+ }
313
+ /** A progress text trimmed to PROGRESS_MAX code points; truncated says whether an ellipsis replaced the tail. */
314
+ export function clipProgress(text) {
315
+ const clean = String(text).trim();
316
+ const chars = [...clean];
317
+ if (chars.length <= PROGRESS_MAX)
318
+ return { text: clean, truncated: false };
319
+ return { text: `${chars.slice(0, PROGRESS_MAX - 1).join("")}…`, truncated: true };
320
+ }
321
+ export function addProgress(doc, id, { by, text }, now = Date.now()) {
322
+ const task = findTask(doc, id);
323
+ task.progress.push({ at: now, by, text: clipProgress(text).text });
324
+ task.updated = now;
325
+ return task;
326
+ }
327
+ /**
328
+ * A review packet from the pieces a builder has: the Git range, the task's criteria, the host check and the numstat.
329
+ * `submission` changes on every run, so a re-run's decision cannot land on the earlier packet.
330
+ */
331
+ export function reviewPacket({ commit, base, branch, criteria, check, numstat, submission, at = Date.now() }) {
332
+ return {
333
+ submission, commit, base, branch,
334
+ criteria: clipProgress(criteria ?? "").text,
335
+ check: { code: Number.isInteger(check?.code) ? check.code : 2, text: clipProgress(check?.text ?? "").text },
336
+ ...changeSummary(numstat),
337
+ at,
338
+ };
339
+ }
340
+ /** Records a completed build for review: the task moves to `review` with the packet beside it. */
341
+ export function submitReview(doc, id, packet, now = Date.now()) {
342
+ const next = { ...packet, at: Number.isFinite(packet?.at) ? packet.at : now };
343
+ checkReview(id, next);
344
+ const task = setTaskField(doc, id, "status", "review", now);
345
+ task.review = next;
346
+ return task;
347
+ }
348
+ /**
349
+ * Attaches a packet for a task the same write already moved to `review`. A settlement publishes status and packet in
350
+ * one patch, so the task needs a setter that takes both; the packet is validated exactly as submitReview does.
351
+ */
352
+ function setReview(doc, id, packet, now) {
353
+ const task = findTask(doc, id);
354
+ if (packet === null) {
355
+ delete task.review;
356
+ }
357
+ else {
358
+ const next = { ...packet, at: Number.isFinite(packet?.at) ? packet.at : now };
359
+ checkReview(id, next);
360
+ task.review = next;
361
+ }
362
+ task.updated = now;
363
+ return task;
364
+ }
365
+ /**
366
+ * Accept or return the pending packet. Throws for an unknown packet, one the branch has moved past, and a task that is
367
+ * no longer in review. Accept marks the task done for that commit; return queues it again with the operator's note.
368
+ */
369
+ export function decideReview(doc, id, { commit, submission, action, note, by, root, landedAnswer }, now = Date.now()) {
370
+ const task = findTask(doc, id);
371
+ const review = task.review;
372
+ if (!review || review.commit !== commit || review.submission !== submission)
373
+ throw taskError(id, "review packet is stale");
374
+ // The merge CLI has already verified this exact commit on origin for a landed review.
375
+ const landed = action === "accept" && landedAnswer;
376
+ if (!landed && !reviewIsCurrent(root, review))
377
+ throw taskError(id, "the build branch moved past the submitted commit");
378
+ if (task.status !== "review" || review.decision)
379
+ throw taskError(id, "review is no longer pending");
380
+ if (!REVIEW_ACTIONS.includes(action))
381
+ throw taskError(id, "unknown review action");
382
+ const text = String(note ?? "").trim();
383
+ if (action === "return" && !oneLine(text, PROGRESS_MAX))
384
+ throw taskError(id, "Give a one-line return note up to 500 characters");
385
+ review.decision = { action, at: now, by, ...(action === "return" ? { note: text } : {}) };
386
+ setTaskField(doc, id, "status", REVIEW_RESULT[action], now);
387
+ const answer = task.question?.answer;
388
+ if (landed && answer?.at === landedAnswer.at && answer?.by === landedAnswer.by && answer?.text === landedAnswer.text) {
389
+ delete task.question;
390
+ }
391
+ addProgress(doc, id, { by, text: action === "accept" ? `Build accepted at ${review.commit.slice(0, 12)}` : `Build returned: ${text}` }, now);
392
+ return task;
393
+ }
394
+ /** Puts a question for the operator on a task, replacing any earlier one and its answer; null removes it. */
395
+ export function askTask(doc, id, question, now = Date.now()) {
396
+ const task = findTask(doc, id);
397
+ if (question === null) {
398
+ delete task.question;
399
+ }
400
+ else {
401
+ const text = String(question?.text ?? "").trim();
402
+ const options = (question?.options ?? []).map((o) => String(o).trim()).filter(Boolean);
403
+ task.question = { text, by: question?.by, at: now, ...(options.length ? { options } : {}) };
404
+ }
405
+ task.updated = now;
406
+ return task;
407
+ }
408
+ /** Records the operator's answer to a task's open question, plus a progress line, so the next agent run reads it. */
409
+ export function answerTask(doc, id, { text, by }, now = Date.now()) {
410
+ const task = findTask(doc, id);
411
+ if (!task.question)
412
+ throw taskError(id, "has no question to answer");
413
+ const answer = String(text ?? "").trim();
414
+ task.question.answer = { text: answer, by, at: now };
415
+ task.progress.push({ at: now, by, text: clipProgress(`Decision: ${answer}`).text });
416
+ task.updated = now;
417
+ return task;
418
+ }
419
+ /** A task waits on the operator while it has a question with no answer. */
420
+ export const needsDecision = (task) => Boolean(task.question && !task.question.answer);
421
+ // Applies a patch of { status, title, detail, run, priority, owner, block, review, progress: {by, text}, ask, answer } to one task.
422
+ function applyPatch(doc, id, patch, now) {
423
+ // oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime patch key
424
+ const setters = {
425
+ status: (value) => setTaskField(doc, id, "status", value, now),
426
+ title: (value) => setTaskField(doc, id, "title", value, now),
427
+ detail: (value) => setTaskField(doc, id, "detail", value, now),
428
+ run: (value) => setTaskField(doc, id, "run", value, now),
429
+ priority: (value) => setTaskField(doc, id, "priority", value, now),
430
+ owner: (value) => ownTask(doc, id, value, now),
431
+ block: (value) => blockTask(doc, id, value, now),
432
+ review: (value) => setReview(doc, id, value, now),
433
+ progress: (value) => addProgress(doc, id, value, now),
434
+ ask: (value) => askTask(doc, id, value, now),
435
+ answer: (value) => answerTask(doc, id, value, now),
436
+ };
437
+ for (const [key, value] of Object.entries(patch)) {
438
+ if (!setters[key])
439
+ throw new Error(`cannot set ${key}`);
440
+ setters[key](value);
441
+ }
442
+ return findTask(doc, id);
443
+ }
444
+ /**
445
+ * The file backend: list and get read the store; add, update, addProgress, remove, submitReview and decideReview write
446
+ * under the store lock. A future backend (GitHub Issues, Linear) implements the same methods.
447
+ */
448
+ export function createFileBackend(file) {
449
+ const busy = () => new Error("task store is busy; retry");
450
+ const mutate = async (change, lockOptions) => {
451
+ const result = await withLock(file, async () => {
452
+ const doc = readStore(file);
453
+ const value = change(doc);
454
+ writeStore(file, doc);
455
+ return value;
456
+ }, lockOptions);
457
+ if (!result.locked)
458
+ throw busy();
459
+ return result.value;
460
+ };
461
+ return {
462
+ file,
463
+ /** Calls onChange when the store file changes, polled once a second; returns the function that stops it. */
464
+ watch(onChange) {
465
+ watchFile(file, { interval: 1000, persistent: false }, onChange);
466
+ return () => unwatchFile(file, onChange);
467
+ },
468
+ list: () => readStore(file).tasks,
469
+ projectBoard: () => readStore(file),
470
+ outcome: (action, fields) => mutate(doc => outcomeStep(doc, action, fields)),
471
+ get: (id) => findTask(readStore(file), id),
472
+ add: (fields, now = Date.now()) => mutate((doc) => addTask(doc, fields, now)),
473
+ update: (id, patch, now = Date.now(), lockOptions) => mutate((doc) => applyPatch(doc, id, patch, now), lockOptions),
474
+ addProgress: (id, entry, now = Date.now()) => mutate((doc) => addProgress(doc, id, entry, now)),
475
+ /** Records a completed build for review: the task moves to `review` with the packet beside it. */
476
+ submitReview: (id, packet, now = Date.now()) => mutate((doc) => submitReview(doc, id, packet, now)),
477
+ /**
478
+ * Accept or return the pending packet. Refuses a stale packet (the commit or submission is not the one on the task,
479
+ * or the branch has moved), a task that is no longer in review, and a return with no note.
480
+ */
481
+ decideReview: (id, decision, now = Date.now()) => mutate((doc) => decideReview(doc, id, decision, now)),
482
+ remove: (id) => mutate((doc) => removeTask(doc, id)),
483
+ /** Writes a whole document into an empty store; refuses when the store file exists. */
484
+ async replaceAll(next) {
485
+ const result = await withLock(file, async () => {
486
+ if (existsSync(file))
487
+ throw new Error(`${file} exists; import runs once`);
488
+ writeStore(file, validateTasks(next));
489
+ return next.tasks.length;
490
+ });
491
+ if (!result.locked)
492
+ throw busy();
493
+ return result.value;
494
+ },
495
+ };
496
+ }
497
+ /** The backend a project uses: projects.json "tasks" (default "file"). Throws on an unknown name. */
498
+ export function openTasks(project, env = process.env) {
499
+ if (!isValidName(project))
500
+ throw new Error(`invalid project name ${project}`);
501
+ const entry = listProjects(env).find((p) => p.project === project);
502
+ const name = entry?.tasks ?? BACKEND_DEFAULT;
503
+ if (!BACKENDS.includes(name))
504
+ throw new Error(`unknown tasks backend ${name}`);
505
+ return createFileBackend(taskStoreFile(project, env));
506
+ }
507
+ // Status cell: a status word, then detail. A cell with no status word is done with the whole cell as detail.
508
+ function parseStatusCell(cell) {
509
+ const text = cell.trim();
510
+ const match = STATUS_CELL.exec(text);
511
+ if (match)
512
+ return { status: match[1].toLowerCase(), detail: text.slice(match[0].length).replace(/^\s*[—-]\s*/, "").trim(), defaulted: false };
513
+ return { status: "done", detail: text, defaulted: true };
514
+ }
515
+ // Cells split on pipes that are not escaped; \\ and \| decode to \ and |.
516
+ function splitRow(line) {
517
+ const cells = [];
518
+ let current = "";
519
+ const body = line.trim().replace(/^\|/, "").replace(/\|$/, "");
520
+ for (let i = 0; i < body.length; i++) {
521
+ const ch = body[i];
522
+ if (ch === "\\" && i + 1 < body.length && (body[i + 1] === "\\" || body[i + 1] === "|")) {
523
+ current += body[++i];
524
+ }
525
+ else if (ch === "|") {
526
+ cells.push(current.trim());
527
+ current = "";
528
+ }
529
+ else {
530
+ current += ch;
531
+ }
532
+ }
533
+ cells.push(current.trim());
534
+ return cells;
535
+ }
536
+ // The table rows: those between the markers when the file has them, else the one table in the file.
537
+ function tableRows(markdown) {
538
+ const marks = markersOf(markdown);
539
+ if (marks)
540
+ return markdown.slice(marks.start + TABLE_START.length, marks.end).split("\n").filter(isTableLine);
541
+ if (markdown.includes(TABLE_START) || markdown.includes(TABLE_END))
542
+ throw new Error(`unbalanced ${TABLE_START} / ${TABLE_END} markers`);
543
+ const lines = markdown.split("\n");
544
+ const tables = lines.filter((line, i) => isTableLine(line) && !(i > 0 && isTableLine(lines[i - 1]))).length;
545
+ if (tables > 1)
546
+ throw new Error(`the file has ${tables} tables: wrap the one to import in ${TABLE_START} and ${TABLE_END}`);
547
+ return lines.filter(isTableLine);
548
+ }
549
+ function isTableLine(line) {
550
+ return line.trimStart().startsWith("|");
551
+ }
552
+ /** Positions of the one start and end marker when they appear once each, in order; null otherwise. */
553
+ function markersOf(text) {
554
+ const start = text.indexOf(TABLE_START);
555
+ const end = text.indexOf(TABLE_END);
556
+ const once = text.indexOf(TABLE_START, start + 1) < 0 && text.indexOf(TABLE_END, end + 1) < 0;
557
+ return start >= 0 && end > start && once ? { start, end } : null;
558
+ }
559
+ /**
560
+ * Converts the Request | Priority | Status table of feature-requests.md into a task document, sorted by priority.
561
+ * A two-cell row (the old table) is still read: title and status, with the default priority.
562
+ */
563
+ /** The task document of a table, and the titles of the rows whose status cell had no status word (imported as done). */
564
+ export function importReport(markdown, now = Date.now()) {
565
+ const doc = { v: TASKS_VERSION, tasks: [] };
566
+ const defaulted = [];
567
+ const rows = tableRows(markdown);
568
+ const priorityColumn = rows.length > 0 && splitRow(rows[0])[1] === "Priority";
569
+ for (const line of rows) {
570
+ const cells = splitRow(line);
571
+ const [title, ...rest] = cells;
572
+ const [priorityCell, statusCell, ...extra] = priorityColumn ? rest : [undefined, ...rest];
573
+ if (extra.length || statusCell === undefined)
574
+ throw new Error(`expected ${priorityColumn ? "three" : "two"} cells: ${line}`);
575
+ if (title === "Request" || /^:?-+:?$/.test(title))
576
+ continue;
577
+ const parsed = parseStatusCell(statusCell);
578
+ const priority = priorityCell !== undefined && TASK_PRIORITIES.includes(priorityCell) ? priorityCell : undefined;
579
+ addTask(doc, { title, status: parsed.status, priority, detail: parsed.detail || undefined }, now);
580
+ if (parsed.defaulted)
581
+ defaulted.push(title);
582
+ }
583
+ return { doc: validateTasks({ ...doc, tasks: sortTasks(doc.tasks) }), defaulted };
584
+ }
585
+ export function importFeatureRequests(markdown, now = Date.now()) {
586
+ return importReport(markdown, now).doc;
587
+ }
588
+ // Escapes the backslash first, so a text ending in \ keeps its meaning in the table.
589
+ const cell = (text) => String(text).replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
590
+ function statusCell(task) {
591
+ const detail = task.detail ?? "";
592
+ if (!detail)
593
+ return task.status;
594
+ return `${task.status}${/^[;:,]/.test(detail) ? "" : " "}${detail}`;
595
+ }
596
+ function priorityCell(task) {
597
+ return priorityOf(task);
598
+ }
599
+ /**
600
+ * The feature-requests.md text, sorted by priority. Only the table between the markers is replaced when `existing`
601
+ * has them, so prose outside the markers survives a render; otherwise a full document is written.
602
+ */
603
+ export function renderFeatureRequests(doc, existing = "") {
604
+ const rows = sortTasks(doc.tasks).map((t) => `| ${cell(t.title)} | ${priorityCell(t)} | ${cell(statusCell(t))} |\n`).join("");
605
+ const table = `${TABLE_START}\n${TABLE_HEAD}${rows}${TABLE_END}`;
606
+ if (!existing.trim())
607
+ return `${DOC_PROSE}${table}\n`;
608
+ // A file with content but no valid marker pair would lose its prose, so the render refuses it.
609
+ const marks = markersOf(existing);
610
+ if (!marks)
611
+ throw new Error(`the file needs one ${TABLE_START} ... ${TABLE_END} pair around its table; add it or delete the file`);
612
+ return `${existing.slice(0, marks.start)}${table}${existing.slice(marks.end + TABLE_END.length)}`;
613
+ }
614
+ /** The building tasks the session cfg owns, as tasks; [] without a session or a project. */
615
+ export function ownedBuilding(cfg, env = process.env) {
616
+ const address = cfg.session && cfg.peer ? `${cfg.peer}#${cfg.session}` : "";
617
+ if (!address || !cfg.project)
618
+ return [];
619
+ return openTasks(cfg.project, env).list().filter((t) => t.owner === address && t.status === "building");
620
+ }
621
+ /** Appends the text to every building task the session owns; returns how many. */
622
+ export async function recordOwnerProgress(cfg, text, env = process.env, now = Date.now()) {
623
+ const owned = ownedBuilding(cfg, env);
624
+ if (!owned.length)
625
+ return 0;
626
+ const backend = openTasks(cfg.project, env);
627
+ const by = `${cfg.peer}#${cfg.session}`;
628
+ for (const task of owned)
629
+ await backend.addProgress(task.id, { by, text }, now);
630
+ return owned.length;
631
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * /team-permission: asks the operator on a phone card (Apply or Cancel) and writes the team's team.dot permission
3
+ * attribute only on Apply. The answer is awaited in the background; the chat gets the pending state at once.
4
+ */
5
+ import { askQuestion } from "./questions.js";
6
+ import { getPattern, saveTeamText, teamTextOf } from "./catalog/patterns.js";
7
+ import { parseDot, serializeDot } from "./catalog/dot.js";
8
+ /**
9
+ * Starts the confirmation for one team. Returns {status, detail, done}: status "failed" when the team cannot take the
10
+ * attribute, else "pending"; done settles once the answer is handled, so tests and callers can await the write.
11
+ */
12
+ export function requestTeamPermission(cfg, name, mode, { env = process.env, ask = askQuestion, pattern = (team) => getPattern(cfg, team, env), save = (team, text) => saveTeamText(cfg, team, text, env), } = {}) {
13
+ let entry;
14
+ try {
15
+ entry = pattern(name);
16
+ }
17
+ catch (error) {
18
+ return { status: "failed", detail: error.message };
19
+ }
20
+ if (!entry.file)
21
+ return { status: "failed", detail: `"${name}" is not a team.dot team; only those take a permission attribute.` };
22
+ const question = `Set permission ${mode} on team "${name}"? Apply rewrites its team.dot for later runs.`;
23
+ const done = Promise.resolve()
24
+ .then(() => ask(cfg, question, { choices: ["Apply", "Cancel"], seconds: 600 }))
25
+ .then(async (answer) => {
26
+ if (answer?.answer !== "Apply")
27
+ return "cancelled";
28
+ const team = parseDot(teamTextOf(entry));
29
+ await save(name, serializeDot({ ...team, permission: mode }));
30
+ return "applied";
31
+ })
32
+ .catch(() => "failed");
33
+ return { status: "pending", detail: `Asked the operator to confirm ${mode} on "${name}".`, done };
34
+ }
@@ -0,0 +1,9 @@
1
+ // blitz: the cleanup pass the factory runs every 5 merged features while no new feature starts.
2
+ digraph "blitz" {
3
+ graph [description="Review oncebitten suggestions, fix violations, and choose an architecture review when due.", landing="pr", fallbacks="claude:claude-opus-5-5,claude:claude-haiku-5-5"];
4
+ sweeper [agent="claude:claude-opus-5-5", prompt="Add task blitz-<date> and set it building. Run oncebitten suggest (read-only) and oncebitten proposals list. Accept the rules that name a real repeated mistake with fixtures, reject the rest with a reason. Fix the violations the accepted rules report on this branch, test first, and land with LAND_FINISH. File larger fixes as tasks with blockers. Then send swept with what changed, or review due when the last architecture review is older than 20 merged features or the same area failed review twice."];
5
+ architect [agent="claude:claude-opus-5-5", prompt="Review the architecture of the area the sweeper named, the way .ai-collab/teams/architect does: objective, scope, constraints, tradeoffs, risks, acceptance criteria. File the outcome as decided tasks with blockers for the PM. Send reviewed."];
6
+ sweeper -> architect [on="review due", kind="pair", required=false];
7
+ sweeper -> done [on="swept", kind="pair", required=false];
8
+ architect -> done [on="reviewed", kind="pair", required=false];
9
+ }