rvlib-shipkit 2.27.0 → 2.29.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 (855) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/package.json +10 -2
  3. package/src/advisors/acts.ts +277 -0
  4. package/src/advisors/advice.ts +384 -0
  5. package/src/advisors/advisor-view.ts +417 -0
  6. package/src/advisors/app-graph.ts +112 -0
  7. package/src/advisors/app.ts +75 -0
  8. package/src/advisors/door.ts +59 -0
  9. package/src/advisors/edge/api.ts +292 -0
  10. package/src/advisors/edge/bucket.ts +43 -0
  11. package/src/advisors/edge/certs.ts +20 -0
  12. package/src/advisors/edge/form.ts +45 -0
  13. package/src/advisors/edge/handler.ts +156 -0
  14. package/src/advisors/edge/jwt.ts +76 -0
  15. package/src/advisors/edge/shell.ts +27 -0
  16. package/src/advisors/edge/status.ts +12 -0
  17. package/src/advisors/edge/types.ts +137 -0
  18. package/src/advisors/edge/worker.ts +52 -0
  19. package/src/advisors/expose.ts +150 -0
  20. package/src/advisors/job.ts +35 -0
  21. package/src/advisors/owner-store.ts +226 -0
  22. package/src/advisors/photos.ts +182 -0
  23. package/src/advisors/project.ts +311 -0
  24. package/src/advisors/r2.ts +48 -0
  25. package/src/advisors/routes.ts +469 -0
  26. package/src/advisors/scan.ts +194 -0
  27. package/src/advisors/sync.ts +363 -0
  28. package/src/agent-time/accounts-usage-disk.ts +29 -0
  29. package/src/agent-time/accounts-usage.ts +97 -0
  30. package/src/agent-time/hooks.ts +73 -29
  31. package/src/agent-time/lane-name.ts +7 -0
  32. package/src/agent-time/leads.ts +95 -0
  33. package/src/agent-time/live.ts +11 -5
  34. package/src/agent-time/registry.ts +354 -0
  35. package/src/agent-time/render.ts +35 -4
  36. package/src/agent-time/report-cache.ts +4 -8
  37. package/src/agent-time/report.ts +19 -1
  38. package/src/agent-time/store.ts +10 -16
  39. package/src/annex/born.ts +2 -2
  40. package/src/annex/offload.ts +12 -11
  41. package/src/annex/snapshots.ts +3 -3
  42. package/src/annex/tidy.ts +10 -23
  43. package/src/asks/ask-after.ts +8 -3
  44. package/src/asks/ask-bar-fold.ts +57 -0
  45. package/src/asks/ask-carry.ts +190 -0
  46. package/src/asks/ask-close.ts +72 -0
  47. package/src/asks/ask-doc.ts +42 -0
  48. package/src/asks/ask-migrate.ts +280 -0
  49. package/src/asks/ask-steps-fold.ts +123 -0
  50. package/src/asks/ask-store.ts +703 -0
  51. package/src/asks/ask-words-fold.ts +208 -0
  52. package/src/assets/kits/identity-kit.ts +106 -38
  53. package/src/assets/kits/poster-thumbnail.ts +282 -0
  54. package/src/checks/SK001-package-json-shape.check.ts +5 -7
  55. package/src/checks/SK003-claude-md-shape.check.ts +92 -25
  56. package/src/checks/SK004-gitignore-policy.check.ts +21 -17
  57. package/src/checks/SK010-undeclared-unit.check.ts +77 -64
  58. package/src/checks/SK013-one-way-in-policy.check.ts +27 -5
  59. package/src/checks/SK026-asks-autoclose.check.ts +9 -23
  60. package/src/checks/SK027-agent-wiki-links.check.ts +46 -6
  61. package/src/checks/SK033-global-contribution.check.ts +1 -1
  62. package/src/checks/SK036-draft-media-size.check.ts +5 -4
  63. package/src/checks/SK038-speaks-as.check.ts +3 -3
  64. package/src/checks/SK039-vscode-watch-generated.check.ts +1 -1
  65. package/src/checks/SK040-release-words.check.ts +39 -10
  66. package/src/checks/SK042-post-kinds.check.ts +26 -24
  67. package/src/checks/SK045-slow-hooks.check.ts +5 -2
  68. package/src/checks/SK049-thread-answers-hook.check.ts +83 -0
  69. package/src/checks/SK050-retired-commands.check.ts +127 -0
  70. package/src/checks/SK051-no-formatter.check.ts +485 -0
  71. package/src/cli/cmd_Advisors.ts +336 -0
  72. package/src/cli/cmd_Annex.ts +10 -10
  73. package/src/cli/cmd_Asks.ts +303 -51
  74. package/src/cli/cmd_Backup.ts +157 -14
  75. package/src/cli/cmd_CacheAudit.ts +1 -1
  76. package/src/cli/cmd_Calls.ts +1 -0
  77. package/src/cli/cmd_Check.ts +3 -3
  78. package/src/cli/cmd_Checks.ts +1 -1
  79. package/src/cli/cmd_Ci.ts +15 -16
  80. package/src/cli/cmd_Commands.ts +140 -34
  81. package/src/cli/cmd_Contracts.ts +1 -0
  82. package/src/cli/cmd_Db.ts +9 -9
  83. package/src/cli/cmd_FleetPush.ts +1 -1
  84. package/src/cli/cmd_History.ts +2 -2
  85. package/src/cli/cmd_Home.ts +5 -6
  86. package/src/cli/cmd_Hooks.ts +13 -3
  87. package/src/cli/cmd_Hq.ts +30 -19
  88. package/src/cli/cmd_Keys.ts +2 -1
  89. package/src/cli/cmd_Lanes.ts +21 -4
  90. package/src/cli/cmd_Media.ts +59 -13
  91. package/src/cli/cmd_Messages.ts +152 -1
  92. package/src/cli/cmd_Needs.ts +1 -0
  93. package/src/cli/cmd_Orchestrator.ts +138 -0
  94. package/src/cli/cmd_Rec.ts +5 -2
  95. package/src/cli/cmd_Reflect.ts +17 -3
  96. package/src/cli/cmd_Releases.ts +38 -38
  97. package/src/cli/cmd_Review.ts +1500 -424
  98. package/src/cli/cmd_Secret.ts +255 -34
  99. package/src/cli/cmd_Shot.ts +14 -6
  100. package/src/cli/cmd_Social.ts +41 -37
  101. package/src/cli/cmd_SocialDrafts.ts +248 -0
  102. package/src/cli/cmd_Sound.ts +22 -1
  103. package/src/cli/cmd_Space.ts +1 -1
  104. package/src/cli/cmd_Start.ts +3 -2
  105. package/src/cli/cmd_ThreadHolds.ts +34 -0
  106. package/src/cli/cmd_ThreadKinds.ts +153 -0
  107. package/src/cli/cmd_ThreadReflect.ts +91 -0
  108. package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
  109. package/src/cli/cmd_Time.ts +2 -1
  110. package/src/cli/cmd_Tmp.ts +9 -8
  111. package/src/cli/cmd_TraceAudit.ts +1 -1
  112. package/src/cli/cmd_Trailer.ts +5 -5
  113. package/src/cli/cmd_Urls.ts +3 -3
  114. package/src/cli/cmd_Vault.ts +5 -5
  115. package/src/cli/cmd_When.ts +2 -1
  116. package/src/cli/cmd_Worktrees.ts +109 -0
  117. package/src/cli/family-help.ts +2 -2
  118. package/src/cli/family-pages.ts +1 -1
  119. package/src/cli/kit/builtins.ts +1 -0
  120. package/src/cli/kit/verb.ts +6 -2
  121. package/src/cli/registry.ts +35 -5
  122. package/src/cli.ts +26 -15
  123. package/src/collections/actions.ts +27 -75
  124. package/src/collections/checks.ts +1 -1
  125. package/src/collections/collection-types.ts +23 -8
  126. package/src/collections/md-body.ts +5 -3
  127. package/src/collections/pings.ts +16 -6
  128. package/src/collections/providers.ts +63 -71
  129. package/src/collections/reflections.ts +9 -4
  130. package/src/collections/review.ts +25 -23
  131. package/src/collections/state-rules.ts +8 -7
  132. package/src/comfy/comfy-panel.ts +2 -2
  133. package/src/commands/model.ts +1 -1
  134. package/src/commands/routes.ts +1 -1
  135. package/src/commands/runs.ts +1 -1
  136. package/src/core/app-icon.ts +3 -9
  137. package/src/core/atomic-write.ts +36 -0
  138. package/src/core/budget.ts +16 -1
  139. package/src/core/bun-builtins.ts +7 -7
  140. package/src/core/canonical-scripts.ts +4 -6
  141. package/src/core/check-ctx.ts +17 -3
  142. package/src/core/day-stamp.ts +20 -0
  143. package/src/core/git-bin.ts +10 -0
  144. package/src/core/git.ts +75 -0
  145. package/src/core/hard-reset.ts +1 -2
  146. package/src/core/history-files.ts +4 -8
  147. package/src/core/house-layout.ts +20 -0
  148. package/src/core/hub-theme.ts +16 -0
  149. package/src/core/identity.ts +1 -1
  150. package/src/core/in-base.ts +19 -0
  151. package/src/core/instance.ts +15 -5
  152. package/src/core/last-good.ts +42 -133
  153. package/src/core/layout.ts +11 -6
  154. package/src/core/load-probe.ts +4 -8
  155. package/src/core/locked-write.ts +116 -43
  156. package/src/core/loop-watch.ts +24 -3
  157. package/src/core/machine-db.ts +58 -14
  158. package/src/core/machine-link.ts +1 -1
  159. package/src/core/memory-watch.ts +3 -2
  160. package/src/core/migrate-layout.ts +8 -10
  161. package/src/core/motherhome.ts +2 -1
  162. package/src/core/nearest.ts +23 -0
  163. package/src/core/on-loop.ts +57 -0
  164. package/src/core/one-way-in-policy.ts +26 -13
  165. package/src/core/raw-access.ts +9 -2
  166. package/src/core/reexec.ts +3 -5
  167. package/src/core/repo-walk.ts +104 -0
  168. package/src/core/retention.ts +10 -12
  169. package/src/core/run-dirs.ts +45 -0
  170. package/src/core/runs-matrix.ts +1 -1
  171. package/src/core/slots.ts +2 -2
  172. package/src/core/slug.ts +33 -0
  173. package/src/core/spawn-timeout.ts +3 -1
  174. package/src/core/squircle.ts +0 -8
  175. package/src/core/throwaway-worktree.ts +21 -2
  176. package/src/core/unit-files.ts +4 -4
  177. package/src/core/when-block.ts +4 -5
  178. package/src/core/when.ts +1 -3
  179. package/src/core/words.ts +33 -0
  180. package/src/fleet/push-fleet.ts +4 -11
  181. package/src/{core → gate}/cache-audit.ts +1 -1
  182. package/src/{core → gate}/check-runner.ts +24 -54
  183. package/src/{core → gate}/discover-checks.ts +19 -101
  184. package/src/{core → gate}/discover-legacy-checks.ts +3 -3
  185. package/src/{ledger → gate}/gate-checks.ts +5 -5
  186. package/src/gate/head-gate.ts +151 -0
  187. package/src/{core → gate}/job-follow.ts +1 -1
  188. package/src/{core → gate}/job-run.ts +3 -3
  189. package/src/{core → gate}/pre-commit-discovery.ts +2 -2
  190. package/src/{core → gate}/run-check.ts +7 -7
  191. package/src/{core → gate}/run-ci.ts +9 -9
  192. package/src/gate/run-fix.ts +173 -0
  193. package/src/{core → gate}/run-fixers.ts +14 -14
  194. package/src/{core → gate}/trace-audit.ts +8 -8
  195. package/src/home/activity-shape.ts +1 -1
  196. package/src/home/activity.ts +21 -26
  197. package/src/home/app-sign.ts +17 -9
  198. package/src/home/daemon-guard.ts +6 -0
  199. package/src/home/daemon-jobs.ts +64 -10
  200. package/src/home/database-words.ts +21 -27
  201. package/src/home/databases.ts +3 -3
  202. package/src/home/global-context.ts +2 -2
  203. package/src/home/global-units.ts +1 -1
  204. package/src/home/gui-app/ShipkitGui.swift +129 -55
  205. package/src/home/gui-app.ts +1 -1
  206. package/src/home/handover.ts +126 -0
  207. package/src/home/home-move.ts +29 -16
  208. package/src/home/home-paths.ts +33 -8
  209. package/src/home/home-routes.ts +83 -5
  210. package/src/home/home-start.ts +1 -1
  211. package/src/home/home-state.ts +12 -6
  212. package/src/home/hubs.ts +28 -5
  213. package/src/home/inbox-shape.ts +250 -94
  214. package/src/home/inbox.ts +27 -71
  215. package/src/home/lib-watch.ts +93 -74
  216. package/src/home/machine-fold.ts +54 -56
  217. package/src/home/machine-host.ts +19 -1
  218. package/src/home/machine-repair.ts +5 -6
  219. package/src/home/machine-stores.ts +3 -3
  220. package/src/home/machine-temp.ts +58 -67
  221. package/src/home/other-macs.ts +2 -2
  222. package/src/home/page-build.ts +330 -0
  223. package/src/home/page-held.ts +338 -0
  224. package/src/home/pm-config.ts +10 -2
  225. package/src/home/pm.ts +35 -1
  226. package/src/home/process-apps.ts +3 -3
  227. package/src/home/push-sources.ts +132 -0
  228. package/src/home/run-daemon.ts +54 -4
  229. package/src/home/run-pm.ts +2 -1
  230. package/src/home/run-web.ts +11 -6
  231. package/src/home/search-shape.ts +54 -0
  232. package/src/home/search.ts +114 -0
  233. package/src/home/serve-daemon.ts +40 -18
  234. package/src/home/serve-web.ts +90 -148
  235. package/src/home/space-page.ts +8 -8
  236. package/src/home/space-words.ts +11 -10
  237. package/src/home/supervise.ts +24 -0
  238. package/src/home/time-page-shape.ts +0 -13
  239. package/src/home/vault-page.ts +64 -30
  240. package/src/home/vault-reveal.ts +29 -0
  241. package/src/home/vault-words.ts +5 -5
  242. package/src/home/via-hub.ts +3 -4
  243. package/src/home/worktree-tidy.ts +236 -0
  244. package/src/hooks/edit-guard.ts +12 -0
  245. package/src/hooks/hook-gates.ts +2 -0
  246. package/src/hooks/leak-guard.ts +9 -3
  247. package/src/hooks/one-way-in-guard.ts +32 -2
  248. package/src/hooks/run-hooks.ts +58 -5
  249. package/src/hooks/shared-file.ts +174 -0
  250. package/src/{serve → house}/project-gutter.ts +11 -54
  251. package/src/hq/door-route.ts +2 -2
  252. package/src/hq/door.ts +3 -3
  253. package/src/hq/files-send.ts +32 -33
  254. package/src/hq/forgotten-log.ts +1 -1
  255. package/src/hq/history-check.ts +7 -6
  256. package/src/hq/history-send.ts +12 -14
  257. package/src/hq/hq-db.ts +5 -2
  258. package/src/hq/hq-local.ts +48 -13
  259. package/src/hq/hq-routes.ts +10 -2
  260. package/src/hq/hq-store.ts +10 -6
  261. package/src/hq/kinds/ask.ts +9 -8
  262. package/src/hq/kinds/index.ts +4 -4
  263. package/src/hq/kinds/{card-gone.ts → item-gone.ts} +24 -25
  264. package/src/hq/kinds/{card-msg.ts → item-msg.ts} +25 -27
  265. package/src/hq/kinds/{card.ts → item.ts} +31 -29
  266. package/src/hq/kinds/kind.ts +3 -0
  267. package/src/hq/kinds/media.ts +2 -3
  268. package/src/hq/kinds/prompt.ts +2 -1
  269. package/src/hq/kinds/time-day.ts +5 -4
  270. package/src/hq/ledger.ts +22 -22
  271. package/src/hq/machine-notes.ts +14 -15
  272. package/src/hq/outbox.ts +35 -24
  273. package/src/hq/replica.ts +1 -2
  274. package/src/hq/report.ts +10 -12
  275. package/src/hq/switch.ts +20 -23
  276. package/src/hq/{cards.ts → thread-sync.ts} +127 -99
  277. package/src/hq/vault-route.ts +112 -0
  278. package/src/{serve → http}/door-forward.ts +11 -4
  279. package/src/http/loopback-serve.ts +84 -0
  280. package/src/{serve → http}/same-origin.ts +6 -2
  281. package/src/http/tailnet-caller.ts +118 -0
  282. package/src/identities/collection.ts +2 -2
  283. package/src/identities/identities.ts +9 -8
  284. package/src/identities/machine-route.ts +8 -3
  285. package/src/identities/shown.ts +2 -6
  286. package/src/ledger/check-table.ts +1 -1
  287. package/src/ledger/db.ts +9 -1
  288. package/src/ledger/git-key.ts +9 -3
  289. package/src/ledger/git-scan.ts +2 -2
  290. package/src/ledger/ledger.ts +6 -16
  291. package/src/media-kinds.ts +4 -1
  292. package/src/media-store/backup/daemon.ts +51 -10
  293. package/src/media-store/backup/keys.ts +1 -4
  294. package/src/media-store/backup/manifest.ts +21 -3
  295. package/src/media-store/backup/prune.ts +362 -0
  296. package/src/media-store/backup/retention.ts +122 -0
  297. package/src/media-store/backup/run.ts +22 -35
  298. package/src/media-store/backup/sources.ts +27 -27
  299. package/src/media-store/backup/thread-copy.ts +339 -0
  300. package/src/media-store/backup/watch.ts +10 -6
  301. package/src/media-store/content.ts +3 -0
  302. package/src/media-store/copy/config.ts +3 -4
  303. package/src/media-store/copy/night.ts +4 -4
  304. package/src/media-store/copy/store.ts +2 -2
  305. package/src/media-store/daemon.ts +5 -4
  306. package/src/media-store/db.ts +10 -20
  307. package/src/media-store/forget-one.ts +247 -0
  308. package/src/media-store/forget.ts +141 -4
  309. package/src/media-store/hq-send.ts +5 -4
  310. package/src/media-store/purge.ts +5 -4
  311. package/src/media-store/remote.ts +2 -2
  312. package/src/media-store/space-listing.ts +20 -9
  313. package/src/media-store/space.ts +7 -5
  314. package/src/media-store/tidy.ts +3 -3
  315. package/src/media-store/upload.ts +2 -2
  316. package/src/media-store/webp.ts +3 -3
  317. package/src/messages/guard.ts +49 -0
  318. package/src/messages/model.ts +1 -1
  319. package/src/messages/objects.ts +203 -0
  320. package/src/messages/routes.ts +2 -2
  321. package/src/messages/score.ts +2 -4
  322. package/src/messages/store-doc.ts +114 -0
  323. package/src/messages/verdicts.ts +6 -0
  324. package/src/messages/write.ts +285 -0
  325. package/src/mv/mv-md.ts +43 -12
  326. package/src/orchestrator/brief.md +29 -0
  327. package/src/orchestrator/deliver.ts +81 -0
  328. package/src/orchestrator/drill.ts +129 -0
  329. package/src/orchestrator/guards.ts +63 -0
  330. package/src/orchestrator/keeper.ts +332 -0
  331. package/src/orchestrator/phone.ts +98 -0
  332. package/src/orchestrator/pm.ts +20 -0
  333. package/src/orchestrator/presence-shape.ts +17 -0
  334. package/src/orchestrator/presence.ts +68 -0
  335. package/src/orchestrator/push.ts +102 -0
  336. package/src/orchestrator/routes.ts +113 -0
  337. package/src/orchestrator/state.ts +92 -0
  338. package/src/orchestrator/switch.ts +86 -0
  339. package/src/orchestrator/tmux.ts +82 -0
  340. package/src/orchestrator/unheard.ts +68 -0
  341. package/src/pages/frame-client.ts +181 -4
  342. package/src/pages/unit.ts +1 -1
  343. package/src/plan/repo-source.ts +1 -1
  344. package/src/recordings/load.ts +1 -1
  345. package/src/recordings/model.ts +18 -10
  346. package/src/recordings/place.ts +3 -3
  347. package/src/recordings/recorder-app/Capture.swift +69 -21
  348. package/src/recordings/recorder-app/Editor.swift +214 -11
  349. package/src/recordings/recorder-app/main.swift +229 -47
  350. package/src/recordings/recorder-app.ts +1 -1
  351. package/src/recordings/routes.ts +11 -1
  352. package/src/recordings/take.ts +7 -5
  353. package/src/recordings/view.ts +6 -0
  354. package/src/reflect/prompt-corpus.ts +5 -3
  355. package/src/reflect/thread-words.ts +51 -0
  356. package/src/reflections/reflection-close.ts +123 -0
  357. package/src/reflections/reflection-doc.ts +59 -0
  358. package/src/reflections/reflection-place.ts +60 -0
  359. package/src/reflections/reflections-queue.ts +1 -1
  360. package/src/release/gate-checkout.ts +124 -21
  361. package/src/release/git-facts.ts +11 -9
  362. package/src/release/machine-words.ts +21 -3
  363. package/src/release/public-clean.ts +81 -21
  364. package/src/release/run-bump.ts +3 -5
  365. package/src/release/run-release.ts +42 -38
  366. package/src/releases/add.ts +33 -87
  367. package/src/releases/{from-card.ts → from-thread.ts} +47 -46
  368. package/src/releases/model.ts +207 -36
  369. package/src/releases/routes.ts +2 -2
  370. package/src/releases/shape.ts +184 -0
  371. package/src/releases/store.ts +10 -10
  372. package/src/repo-config.ts +53 -21
  373. package/src/review/anim.ts +8 -8
  374. package/src/review/answer-kinds.ts +160 -0
  375. package/src/review/auto.ts +3 -3
  376. package/src/review/band.ts +145 -0
  377. package/src/review/branch-hold.ts +91 -0
  378. package/src/review/cells.ts +451 -96
  379. package/src/review/close.ts +92 -0
  380. package/src/review/doc-card.ts +41 -0
  381. package/src/review/doc-model.ts +100 -0
  382. package/src/review/doc-routes.ts +66 -0
  383. package/src/review/doc-save.ts +152 -0
  384. package/src/review/draft-item.ts +36 -0
  385. package/src/review/draft-model.ts +125 -17
  386. package/src/review/events.ts +164 -0
  387. package/src/review/file-tags.ts +52 -0
  388. package/src/review/format.ts +195 -38
  389. package/src/review/glyphs.ts +63 -0
  390. package/src/review/gone.ts +21 -21
  391. package/src/review/hand-over.ts +58 -0
  392. package/src/review/heard.ts +29 -0
  393. package/src/review/holds-sync.ts +62 -0
  394. package/src/review/holds.ts +85 -0
  395. package/src/review/house-kind-defs.ts +71 -0
  396. package/src/review/http.ts +1 -1
  397. package/src/review/inbox-hook.ts +69 -10
  398. package/src/review/inbox-read.ts +226 -0
  399. package/src/review/instructions.ts +241 -0
  400. package/src/review/{card-db.ts → item-db.ts} +48 -36
  401. package/src/review/{card-rows.ts → item-rows.ts} +79 -51
  402. package/src/review/kind-apply.ts +61 -0
  403. package/src/review/kind-catalog.ts +96 -0
  404. package/src/review/kind-still.ts +125 -0
  405. package/src/review/kinds.ts +314 -0
  406. package/src/review/lane-ask.ts +113 -0
  407. package/src/review/live-post.ts +107 -0
  408. package/src/review/live-view.ts +137 -0
  409. package/src/review/media-kind.ts +4 -4
  410. package/src/review/media-read.ts +4 -4
  411. package/src/review/media.ts +3 -5
  412. package/src/review/mentions.ts +100 -0
  413. package/src/review/model-moved.ts +76 -0
  414. package/src/review/model.ts +846 -214
  415. package/src/review/move.ts +62 -61
  416. package/src/review/need-address.ts +15 -0
  417. package/src/review/need-threads.ts +51 -0
  418. package/src/review/notes.ts +2 -1
  419. package/src/review/object-card.ts +48 -0
  420. package/src/review/object-read.ts +31 -0
  421. package/src/review/one-block.ts +64 -0
  422. package/src/review/owner-read.ts +41 -0
  423. package/src/review/owner-verdict.ts +36 -0
  424. package/src/review/parties.ts +274 -0
  425. package/src/review/paste.ts +4 -4
  426. package/src/review/phone-push.ts +137 -0
  427. package/src/review/previews.ts +19 -17
  428. package/src/review/project.ts +1 -1
  429. package/src/review/projections.ts +235 -0
  430. package/src/review/push.ts +269 -0
  431. package/src/review/referring.ts +76 -0
  432. package/src/review/reflection-object.ts +190 -0
  433. package/src/review/rev.ts +1 -1
  434. package/src/review/role.ts +3 -3
  435. package/src/review/routes.ts +227 -83
  436. package/src/review/search-index.ts +218 -0
  437. package/src/review/search-job.ts +40 -0
  438. package/src/review/search-ocr.ts +138 -0
  439. package/src/review/search-text.ts +129 -0
  440. package/src/review/secret-route.ts +110 -0
  441. package/src/review/settle.ts +67 -0
  442. package/src/review/snooze.ts +38 -0
  443. package/src/review/stage-routes.ts +15 -13
  444. package/src/review/{stage-card.ts → stage-thread.ts} +22 -21
  445. package/src/review/store-index.ts +49 -0
  446. package/src/review/store-parties.ts +20 -0
  447. package/src/review/store.ts +721 -260
  448. package/src/review/supersede.ts +132 -0
  449. package/src/review/take-back.ts +65 -0
  450. package/src/review/thread-fold.ts +20 -7
  451. package/src/review/threads.ts +397 -79
  452. package/src/review/traces.ts +206 -0
  453. package/src/review/trailer-desk.ts +7 -7
  454. package/src/review/{trailer-card.ts → trailer-item.ts} +12 -12
  455. package/src/review/trailer-model.ts +4 -4
  456. package/src/review/trailer-notes.ts +2 -2
  457. package/src/review/trailer-routes.ts +5 -4
  458. package/src/review/trailer-shots.ts +3 -3
  459. package/src/review/unit.ts +140 -13
  460. package/src/review/uploads.ts +103 -0
  461. package/src/review/verdict-items.ts +73 -0
  462. package/src/review/verdict-write.ts +15 -0
  463. package/src/review/view-layout.ts +69 -0
  464. package/src/review/wait.ts +91 -0
  465. package/src/review/wakes.ts +115 -0
  466. package/src/review/watch-feed.ts +183 -0
  467. package/src/review/watchers.ts +44 -10
  468. package/src/rules/untrack-generated.ts +40 -39
  469. package/src/scaffold/files/bunfig.toml +1 -9
  470. package/src/scaffold/files/claude-settings-local.json +2 -0
  471. package/src/scaffold/files/vscode-settings.json +1 -1
  472. package/src/scaffold/project-scaffold.ts +14 -10
  473. package/src/secrets/archive-mark.ts +52 -0
  474. package/src/secrets/archive.ts +84 -0
  475. package/src/secrets/copy.ts +14 -14
  476. package/src/secrets/keychain-write.ts +56 -0
  477. package/src/secrets/keychain.ts +8 -5
  478. package/src/secrets/lapse-mark.ts +38 -0
  479. package/src/secrets/lapse.ts +71 -0
  480. package/src/secrets/list.ts +16 -22
  481. package/src/secrets/manager.ts +31 -16
  482. package/src/secrets/read.ts +161 -33
  483. package/src/secrets/security-line.ts +19 -0
  484. package/src/secrets/tail.ts +31 -0
  485. package/src/serve/embed.ts +1 -1
  486. package/src/serve/house-runs.ts +1 -1
  487. package/src/serve/hub-app/accounts-line.tsx +67 -0
  488. package/src/serve/hub-app/activity-st.ts +46 -50
  489. package/src/serve/hub-app/advice-box.tsx +66 -0
  490. package/src/serve/hub-app/advisor-app.tsx +46 -0
  491. package/src/serve/hub-app/advisor-face.tsx +29 -0
  492. package/src/serve/hub-app/advisor-host.ts +142 -0
  493. package/src/serve/hub-app/advisor.html +22 -0
  494. package/src/serve/hub-app/advisors-st.ts +261 -0
  495. package/src/serve/hub-app/advisors-view.tsx +269 -0
  496. package/src/serve/hub-app/advisors.css +57 -0
  497. package/src/serve/hub-app/app-bridge.ts +27 -24
  498. package/src/serve/hub-app/ask-steps-st.ts +60 -0
  499. package/src/serve/hub-app/ask-steps.tsx +23 -0
  500. package/src/serve/hub-app/asks-page.tsx +9 -5
  501. package/src/serve/hub-app/asks-st.ts +1 -4
  502. package/src/serve/hub-app/auto-text.tsx +118 -18
  503. package/src/serve/hub-app/benign-errors.ts +15 -1
  504. package/src/serve/hub-app/card-head.tsx +49 -0
  505. package/src/serve/hub-app/check-view.tsx +3 -2
  506. package/src/serve/hub-app/checks-svc.ts +1 -1
  507. package/src/serve/hub-app/clock-svc.ts +21 -5
  508. package/src/serve/hub-app/code-copy.ts +196 -0
  509. package/src/serve/hub-app/col-card.tsx +24 -40
  510. package/src/serve/hub-app/col-list-page.tsx +7 -4
  511. package/src/serve/hub-app/col-list-st.ts +6 -1
  512. package/src/serve/hub-app/col-tables-view.tsx +7 -4
  513. package/src/serve/hub-app/col-tables.ts +19 -13
  514. package/src/serve/hub-app/cols-svc.ts +15 -80
  515. package/src/serve/hub-app/comfy-svc.ts +3 -2
  516. package/src/serve/hub-app/commands/commands-page.tsx +2 -1
  517. package/src/serve/hub-app/commands/commands-st.ts +36 -26
  518. package/src/serve/hub-app/controls.css +99 -0
  519. package/src/serve/hub-app/cursor-spot.ts +81 -0
  520. package/src/serve/hub-app/database-st.ts +31 -26
  521. package/src/serve/hub-app/database-view.tsx +12 -12
  522. package/src/serve/hub-app/dock-st.ts +51 -10
  523. package/src/serve/hub-app/dock-view.tsx +14 -1
  524. package/src/serve/hub-app/editor/doc-editor-st.ts +223 -0
  525. package/src/serve/hub-app/editor/doc-editor.tsx +116 -0
  526. package/src/serve/hub-app/editor/doc-saved.tsx +26 -0
  527. package/src/serve/hub-app/editor/doc-slot.ts +66 -0
  528. package/src/serve/hub-app/editor.css +36 -0
  529. package/src/serve/hub-app/emoji-names.ts +1915 -0
  530. package/src/serve/hub-app/emoji.ts +133 -0
  531. package/src/serve/hub-app/floating.tsx +162 -6
  532. package/src/serve/hub-app/frames-st.ts +17 -1
  533. package/src/serve/hub-app/git-st.ts +25 -19
  534. package/src/serve/hub-app/git-view.tsx +3 -2
  535. package/src/serve/hub-app/hash-route.ts +1 -1
  536. package/src/serve/hub-app/header-bar.tsx +4 -3
  537. package/src/serve/hub-app/held-keys.ts +25 -0
  538. package/src/serve/hub-app/home-st.ts +167 -18
  539. package/src/serve/hub-app/home-strip.css +4 -8
  540. package/src/serve/hub-app/home-strip.tsx +7 -3
  541. package/src/serve/hub-app/home.html +10 -0
  542. package/src/serve/hub-app/house-wiki-view.tsx +20 -0
  543. package/src/serve/hub-app/hub-app.tsx +102 -36
  544. package/src/serve/hub-app/hub-types.ts +2 -0
  545. package/src/serve/hub-app/hub.css +117 -92
  546. package/src/serve/hub-app/icons.tsx +24 -4
  547. package/src/serve/hub-app/identities-st.ts +35 -25
  548. package/src/serve/hub-app/identities-view.tsx +11 -7
  549. package/src/serve/hub-app/inbox-st.ts +241 -52
  550. package/src/serve/hub-app/inbox-view.tsx +198 -105
  551. package/src/serve/hub-app/inbox.css +53 -47
  552. package/src/serve/hub-app/index.html +10 -0
  553. package/src/serve/hub-app/insights-st.ts +27 -19
  554. package/src/serve/hub-app/instructions.css +33 -0
  555. package/src/serve/hub-app/kept-folds.ts +43 -0
  556. package/src/serve/hub-app/keys.ts +13 -5
  557. package/src/serve/hub-app/later.tsx +1 -1
  558. package/src/serve/hub-app/layout-st.ts +37 -6
  559. package/src/serve/hub-app/list-filter.tsx +1 -1
  560. package/src/serve/hub-app/live-bar.css +12 -0
  561. package/src/serve/hub-app/live-svc.ts +12 -2
  562. package/src/serve/hub-app/machine-st.ts +38 -12
  563. package/src/serve/hub-app/machines-st.ts +40 -34
  564. package/src/serve/hub-app/machines-view.tsx +9 -16
  565. package/src/serve/hub-app/machines.css +0 -9
  566. package/src/serve/hub-app/markdown.css +128 -0
  567. package/src/serve/hub-app/md-copy.tsx +18 -40
  568. package/src/serve/hub-app/md.ts +176 -14
  569. package/src/serve/hub-app/media-svc.ts +44 -11
  570. package/src/serve/hub-app/media-view.tsx +2 -2
  571. package/src/serve/hub-app/messages/messages-page.tsx +57 -12
  572. package/src/serve/hub-app/messages/messages-st.ts +27 -23
  573. package/src/serve/hub-app/messages.css +0 -1
  574. package/src/serve/hub-app/new-thread.tsx +121 -0
  575. package/src/serve/hub-app/objects.css +52 -0
  576. package/src/serve/hub-app/orchestrator-line.tsx +104 -0
  577. package/src/serve/hub-app/orchestrator.css +37 -0
  578. package/src/serve/hub-app/page-keys.ts +8 -5
  579. package/src/serve/hub-app/page-reload.ts +111 -0
  580. package/src/serve/hub-app/pages-frames.tsx +12 -1
  581. package/src/serve/hub-app/pages-svc.ts +8 -3
  582. package/src/serve/hub-app/palette-st.ts +11 -6
  583. package/src/serve/hub-app/pane-boundary.tsx +85 -0
  584. package/src/serve/hub-app/pane-errors.ts +55 -0
  585. package/src/serve/hub-app/pano.css +20 -0
  586. package/src/serve/hub-app/plan-view.tsx +4 -3
  587. package/src/serve/hub-app/planned-st.ts +30 -26
  588. package/src/serve/hub-app/planned-view.tsx +17 -10
  589. package/src/serve/hub-app/planned.css +0 -4
  590. package/src/serve/hub-app/polled.ts +201 -0
  591. package/src/serve/hub-app/presence-st.ts +110 -0
  592. package/src/serve/hub-app/processes-view.tsx +3 -2
  593. package/src/serve/hub-app/project-list.css +101 -66
  594. package/src/serve/hub-app/project-list.tsx +139 -155
  595. package/src/serve/hub-app/projects-svc.ts +113 -57
  596. package/src/serve/hub-app/push-sign.tsx +15 -0
  597. package/src/serve/hub-app/push-svc.ts +273 -0
  598. package/src/serve/hub-app/quiet-st.ts +59 -0
  599. package/src/serve/hub-app/rail-fly.tsx +95 -0
  600. package/src/serve/hub-app/reach.ts +16 -0
  601. package/src/serve/hub-app/readme.css +9 -15
  602. package/src/serve/hub-app/recordings-st.ts +169 -9
  603. package/src/serve/hub-app/recordings-take.ts +58 -0
  604. package/src/serve/hub-app/recordings-view.tsx +42 -35
  605. package/src/serve/hub-app/recordings.css +1 -1
  606. package/src/serve/hub-app/reflections-page.tsx +70 -5
  607. package/src/serve/hub-app/releases/releases-page.tsx +54 -20
  608. package/src/serve/hub-app/releases/releases-st.ts +39 -26
  609. package/src/serve/hub-app/releases.css +4 -1
  610. package/src/serve/hub-app/repo-sections.ts +21 -10
  611. package/src/serve/hub-app/repo-st.ts +36 -9
  612. package/src/serve/hub-app/review/advisor-bar.tsx +40 -0
  613. package/src/serve/hub-app/review/attach-st.ts +195 -0
  614. package/src/serve/hub-app/review/attach-view.tsx +260 -0
  615. package/src/serve/hub-app/review/clip-st.ts +1 -1
  616. package/src/serve/hub-app/review/code-colors.ts +30 -0
  617. package/src/serve/hub-app/review/cta.tsx +11 -0
  618. package/src/serve/hub-app/review/diff-view.tsx +77 -0
  619. package/src/serve/hub-app/review/doc-body.tsx +109 -0
  620. package/src/serve/hub-app/review/dock.tsx +118 -0
  621. package/src/serve/hub-app/review/draft-body.tsx +235 -0
  622. package/src/serve/hub-app/review/faces.tsx +26 -0
  623. package/src/serve/hub-app/review/group-block.tsx +239 -0
  624. package/src/serve/hub-app/review/heard-line.tsx +31 -0
  625. package/src/serve/hub-app/review/instructions-view.tsx +141 -0
  626. package/src/serve/hub-app/review/item-verdict.tsx +111 -0
  627. package/src/serve/hub-app/review/kind-states.tsx +265 -0
  628. package/src/serve/hub-app/review/kind-view.tsx +23 -44
  629. package/src/serve/hub-app/review/kit.tsx +54 -75
  630. package/src/serve/hub-app/review/lane-bar.tsx +64 -0
  631. package/src/serve/hub-app/review/lightbox.tsx +16 -0
  632. package/src/serve/hub-app/review/line-window.ts +149 -0
  633. package/src/serve/hub-app/review/live-bar-st.ts +145 -0
  634. package/src/serve/hub-app/review/live-bar.tsx +126 -0
  635. package/src/serve/hub-app/review/live-view.tsx +104 -0
  636. package/src/serve/hub-app/review/mention-st.ts +85 -0
  637. package/src/serve/hub-app/review/mesh-view.tsx +9 -0
  638. package/src/serve/hub-app/review/object-card.tsx +62 -0
  639. package/src/serve/hub-app/review/object-panel.tsx +197 -0
  640. package/src/serve/hub-app/review/pano-gl.ts +145 -0
  641. package/src/serve/hub-app/review/pano-view.tsx +192 -0
  642. package/src/serve/hub-app/review/phone-top.tsx +16 -0
  643. package/src/serve/hub-app/review/pictures-st.ts +38 -0
  644. package/src/serve/hub-app/review/question-views.tsx +387 -0
  645. package/src/serve/hub-app/review/review-board.tsx +1 -1
  646. package/src/serve/hub-app/review/review-cells.tsx +223 -184
  647. package/src/serve/hub-app/review/review-host.ts +69 -0
  648. package/src/serve/hub-app/review/review-kit.ts +34 -19
  649. package/src/serve/hub-app/review/review-list.tsx +211 -51
  650. package/src/serve/hub-app/review/review-page.tsx +10 -20
  651. package/src/serve/hub-app/review/review-st.ts +294 -151
  652. package/src/serve/hub-app/review/review-thread.tsx +605 -161
  653. package/src/serve/hub-app/review/review-views.tsx +547 -452
  654. package/src/serve/hub-app/review/scene-view.tsx +26 -0
  655. package/src/serve/hub-app/review/secret-facts.ts +26 -0
  656. package/src/serve/hub-app/review/space3d.tsx +114 -0
  657. package/src/serve/hub-app/review/splat-view.tsx +9 -0
  658. package/src/serve/hub-app/review/superseded-runs.ts +76 -0
  659. package/src/serve/hub-app/review/thread-close.tsx +134 -0
  660. package/src/serve/hub-app/review/thread-control-st.ts +2 -1
  661. package/src/serve/hub-app/review/thread-control.tsx +4 -4
  662. package/src/serve/hub-app/review/thread-st.ts +710 -140
  663. package/src/serve/hub-app/review/thread-views.ts +71 -0
  664. package/src/serve/hub-app/review/{trailer-card.tsx → trailer-body.tsx} +35 -35
  665. package/src/serve/hub-app/review/trailer-page.tsx +23 -25
  666. package/src/serve/hub-app/review/trailer-st.ts +38 -38
  667. package/src/serve/hub-app/review/trailer-timeline.tsx +24 -20
  668. package/src/serve/hub-app/review/trailer-voices.tsx +3 -2
  669. package/src/serve/hub-app/review.css +459 -188
  670. package/src/serve/hub-app/search-st.ts +138 -0
  671. package/src/serve/hub-app/search-view.tsx +92 -0
  672. package/src/serve/hub-app/section-head.tsx +52 -0
  673. package/src/serve/hub-app/shell-rows.ts +126 -0
  674. package/src/serve/hub-app/site/site-st.ts +18 -23
  675. package/src/serve/hub-app/social/calendar.tsx +5 -11
  676. package/src/serve/hub-app/social/comms-page.tsx +36 -20
  677. package/src/serve/hub-app/social/group-editor.tsx +44 -0
  678. package/src/serve/hub-app/social/kit.tsx +15 -61
  679. package/src/serve/hub-app/social/next-release.tsx +5 -7
  680. package/src/serve/hub-app/social/post-card.tsx +19 -52
  681. package/src/serve/hub-app/social/post-page.tsx +80 -0
  682. package/src/serve/hub-app/social/problems.tsx +9 -12
  683. package/src/serve/hub-app/social/social-model.ts +13 -5
  684. package/src/serve/hub-app/social/social-page.tsx +4 -4
  685. package/src/serve/hub-app/social/social-st.ts +67 -83
  686. package/src/serve/hub-app/social/stage-popup.tsx +6 -6
  687. package/src/serve/hub-app/social/stage-st.ts +9 -9
  688. package/src/serve/hub-app/social.css +7 -25
  689. package/src/serve/hub-app/space-st.ts +38 -48
  690. package/src/serve/hub-app/space-view.tsx +6 -6
  691. package/src/serve/hub-app/space.css +1 -1
  692. package/src/serve/hub-app/stores/stores-page.tsx +10 -6
  693. package/src/serve/hub-app/stores/stores-st.ts +19 -23
  694. package/src/serve/hub-app/terminal-input.ts +12 -0
  695. package/src/serve/hub-app/terminal-panel.tsx +40 -0
  696. package/src/serve/hub-app/terminal-st.ts +416 -0
  697. package/src/serve/hub-app/terminal.css +15 -0
  698. package/src/serve/hub-app/tests-svc.ts +3 -2
  699. package/src/serve/hub-app/theme-st.ts +1 -9
  700. package/src/serve/hub-app/thread-row.tsx +136 -0
  701. package/src/serve/hub-app/time-ago.tsx +40 -16
  702. package/src/serve/hub-app/time-st.ts +43 -27
  703. package/src/serve/hub-app/time-view.tsx +4 -3
  704. package/src/serve/hub-app/time.css +2 -5
  705. package/src/serve/hub-app/tree-build.ts +2 -2
  706. package/src/serve/hub-app/tree-row.tsx +44 -27
  707. package/src/serve/hub-app/tree-svc.ts +1 -1
  708. package/src/serve/hub-app/urls-svc.ts +6 -5
  709. package/src/serve/hub-app/vault-st.ts +32 -27
  710. package/src/serve/hub-app/vault-view.tsx +57 -6
  711. package/src/serve/hub-app/vault.css +2 -0
  712. package/src/serve/hub-app/veille/veille-page.tsx +5 -14
  713. package/src/serve/hub-app/veille/veille-st.ts +56 -49
  714. package/src/serve/hub-app/veille.css +0 -1
  715. package/src/serve/hub-app/view-layout.css +90 -0
  716. package/src/serve/hub-app/waiting-svc.ts +5 -4
  717. package/src/serve/hub-app/when-view.tsx +6 -3
  718. package/src/serve/hub-app/wiki-st.ts +33 -6
  719. package/src/serve/hub-app/wikis-view.tsx +22 -18
  720. package/src/serve/hub-app/words.tsx +15 -0
  721. package/src/serve/hub-collections.ts +105 -0
  722. package/src/serve/hub-runtime.ts +83 -91
  723. package/src/serve/live-hop.ts +102 -0
  724. package/src/serve/other-repos.ts +1 -1
  725. package/src/serve/project-gutter-route.ts +69 -46
  726. package/src/serve/read-thread.ts +76 -0
  727. package/src/serve/read-worker.ts +53 -0
  728. package/src/serve/run-serve.ts +11 -7
  729. package/src/serve/secret-gate.ts +21 -0
  730. package/src/serve/serve-hub.ts +129 -51
  731. package/src/serve/terminal-guard.ts +50 -0
  732. package/src/serve/terminal-route.ts +176 -0
  733. package/src/shipkit.ts +10 -10
  734. package/src/shot/client.ts +32 -16
  735. package/src/shot/dom-clip.ts +30 -5
  736. package/src/shot/film-box.ts +23 -8
  737. package/src/shot/serve-shot.ts +16 -5
  738. package/src/shot/shooter.ts +72 -24
  739. package/src/shot/shot-ask.ts +17 -6
  740. package/src/shot/shot-guard.ts +53 -0
  741. package/src/shot/shot-theme.ts +70 -0
  742. package/src/shot/still-file.ts +60 -0
  743. package/src/site/desk.ts +6 -5
  744. package/src/smoke/run-smoke.ts +3 -4
  745. package/src/social/brands.ts +4 -0
  746. package/src/social/compose.ts +13 -7
  747. package/src/social/cover.ts +4 -3
  748. package/src/social/desk-index.ts +34 -13
  749. package/src/social/draft-doc.ts +88 -0
  750. package/src/social/draft-versions.ts +80 -0
  751. package/src/social/drafts.ts +26 -8
  752. package/src/social/fit.ts +4 -3
  753. package/src/social/house.ts +1 -1
  754. package/src/social/import-drafts.ts +244 -0
  755. package/src/social/kind-pages.ts +3 -3
  756. package/src/social/kinds.ts +2 -2
  757. package/src/social/load.ts +106 -73
  758. package/src/social/media-facts.ts +1 -19
  759. package/src/social/media-kind.ts +68 -161
  760. package/src/social/media-limit.ts +3 -18
  761. package/src/social/media-of.ts +5 -4
  762. package/src/social/no-account.ts +38 -0
  763. package/src/social/open.ts +3 -2
  764. package/src/social/post-object.ts +120 -0
  765. package/src/social/post-sources.ts +136 -0
  766. package/src/social/post-text.ts +123 -0
  767. package/src/social/posts.ts +433 -0
  768. package/src/social/presence.ts +17 -13
  769. package/src/social/publish/index.ts +17 -5
  770. package/src/social/publish/secret.ts +2 -2
  771. package/src/social/release-stage.ts +76 -75
  772. package/src/social/routes.ts +72 -50
  773. package/src/social/stage.ts +45 -60
  774. package/src/social/stats.ts +3 -4
  775. package/src/social/strip.ts +4 -6
  776. package/src/social/text.ts +6 -4
  777. package/src/social/thread-drafts.ts +16 -0
  778. package/src/social/thumbnail.ts +135 -43
  779. package/src/social/tracker.ts +1 -1
  780. package/src/social/unit.ts +12 -3
  781. package/src/social/writes.ts +8 -31
  782. package/src/start-repo.ts +33 -13
  783. package/src/stores/desk.ts +17 -12
  784. package/src/stores/unit.ts +2 -2
  785. package/src/suite/core-counters.ts +31 -3
  786. package/src/suite/judge-suites.ts +69 -47
  787. package/src/suite/select.ts +1 -27
  788. package/src/suite/suite-cli.ts +18 -8
  789. package/src/suite/suite-cpu-preload.ts +10 -6
  790. package/src/trace/tracer.ts +4 -5
  791. package/src/trailer/build.ts +30 -15
  792. package/src/trailer/ffmpeg.ts +90 -31
  793. package/src/trailer/fonts.ts +5 -6
  794. package/src/trailer/footage.ts +9 -3
  795. package/src/trailer/grammar.ts +2 -1
  796. package/src/trailer/graph.ts +12 -10
  797. package/src/trailer/load-unit.ts +1 -1
  798. package/src/trailer/passage.ts +4 -3
  799. package/src/trailer/prune.ts +4 -4
  800. package/src/trailer/score/sound.ts +3 -3
  801. package/src/trailer/shot-plan.ts +5 -5
  802. package/src/trailer/shot-state.ts +25 -31
  803. package/src/trailer/sound/eleven.ts +34 -3
  804. package/src/trailer/sound/gen.ts +3 -3
  805. package/src/trailer/sound/run.ts +76 -64
  806. package/src/trailer/sound/takes.ts +0 -3
  807. package/src/trailer/take-fault.ts +41 -0
  808. package/src/trailer/titles.ts +17 -13
  809. package/src/trailer/url.ts +1 -1
  810. package/src/trailer/vertical-draw.ts +7 -7
  811. package/src/trailer/vertical.ts +3 -3
  812. package/src/trailer/vocab.ts +3 -4
  813. package/src/ts/config.ts +60 -24
  814. package/src/ts/cycles.ts +3 -1
  815. package/src/ts/imports.ts +17 -3
  816. package/src/ts/rename.ts +6 -7
  817. package/src/ts/source-graph.ts +15 -9
  818. package/src/ts/workspaces.ts +26 -0
  819. package/src/tui/build-steps-panel.ts +3 -3
  820. package/src/tui/checks-panel.ts +2 -2
  821. package/src/urls/frame.ts +3 -3
  822. package/src/urls/routes.ts +1 -1
  823. package/src/urls/rows.ts +2 -2
  824. package/src/vault/house-keys.ts +1 -1
  825. package/src/vault/vault-audit.ts +2 -3
  826. package/src/vault/vault-config.ts +6 -2
  827. package/src/vault/vault-http.ts +11 -3
  828. package/src/vault/vault-import.ts +6 -1
  829. package/src/vault/vault-restore.ts +3 -9
  830. package/src/vault/vault-serve.ts +47 -11
  831. package/src/vault/vault-snapshot.ts +5 -14
  832. package/src/veille/desk.ts +2 -2
  833. package/src/veille/identity.ts +2 -2
  834. package/src/veille/routes.ts +1 -1
  835. package/src/view3d/cam.ts +101 -0
  836. package/src/view3d/lib.ts +69 -0
  837. package/src/view3d/loop.ts +39 -0
  838. package/src/view3d/scene-cache.ts +62 -0
  839. package/src/view3d/viewer.ts +480 -0
  840. package/src/wiki/agent-paths.ts +55 -0
  841. package/src/wiki/graph-pages.ts +13 -1
  842. package/src/wiki/run-wiki.ts +4 -1
  843. package/src/wiki/scan-md.ts +1 -1
  844. package/src/wiki/serve-graph.ts +2 -3
  845. package/src/asks/asks-queue.ts +0 -424
  846. package/src/core/run-fix.ts +0 -120
  847. package/src/home/hmr-keep.ts +0 -134
  848. package/src/messages/suggest.ts +0 -96
  849. package/src/review/draft-card.ts +0 -41
  850. package/src/serve/hub-app/review/draft-card.tsx +0 -163
  851. package/src/serve/hub-app/review/note-place.ts +0 -31
  852. package/src/social/card-drafts.ts +0 -24
  853. package/src/social/migrate.ts +0 -123
  854. /package/src/{serve → http}/door-names.ts +0 -0
  855. /package/src/{serve → http}/hub-port.ts +0 -0
@@ -1,9 +1,13 @@
1
- // sk thread: an agent shows the owner something as one card of the one store and reads his answer; a dispatcher routes
1
+ // sk thread: an agent shows the owner something as a version in its thread and reads his answer; a dispatcher routes
2
2
  // what he, a player or a rule raised, a worker claims and closes it (review/store.ts, wiki tools/shipkit/threads.md).
3
3
  // Every module loads inside execute: the cli registers this file on every `sk` call
4
4
  import { Command, Option } from 'clipanion'
5
+ import type { AnswerKind } from '../review/model.ts'
6
+ import { holdsThread, laneOfCaller, maySee } from '../review/parties.ts'
7
+ import { realGit } from '../core/git.ts'
8
+ import { ageWords } from '../core/words.ts'
5
9
 
6
- const DETAILS = `threads, the one exchange with the owner: one thread per subject for its whole life (wiki tools/shipkit/threads.md). The store: .shipkit/review/<id>/ of each repo, or with the machine switch cards-in-db the rows of the daemon's database and their media in its spool (sk thread move). One subject is one card (other angles are views of it, a follow up --supersedes it), he answers it in the hub's review entry (approved, ok with a fix, rejected, archived, rectangles, reactions per view), you read his answer with inbox or watch. What he, a player or a rule raises is an item of the same store: a dispatcher routes it to a topic, a worker claims it and closes it. The repo's review unit names its kinds, topics, sources and rules. SK_AGENT names your lane. Page: wiki tools/shipkit/threads.md`
10
+ const DETAILS = `threads, the one exchange with the owner (wiki tools/shipkit/threads.md): one thread per subject, found by its address <kind>:<key>, for its whole life. sk thread post <address> sends a version into it, linked by the tool; ask, propose, reply and update write in it, and start it when no thread owns the address. He answers in the hub's threads page; you read his answer with watch, inbox or the inbox hook, then mark it seen. What he, a player or a rule raises is an item of the same store with its own state, closed with sk thread fixed. The store: .shipkit/review/ of each repo, or the daemon's rows (sk thread move). SK_AGENT names your lane.`
7
11
 
8
12
  type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
9
13
  type Unit = import('../review/unit.ts').ReviewUnit
@@ -18,7 +22,7 @@ interface Here {
18
22
  err: (l: string) => void
19
23
  }
20
24
 
21
- /** the shipkit repo the cwd stands in: only its store reaches a hub, so anywhere else a card is refused before a
25
+ /** the shipkit repo the cwd stands in: only its store reaches a hub, so anywhere else an item is refused before a
22
26
  * stray .shipkit/review/ is made where nobody looks */
23
27
  async function reviewRoot(cwd: string): Promise<string | null> {
24
28
  const { findRepoRoot } = await import('../ts/config.ts')
@@ -37,7 +41,13 @@ async function run(context: Ctx, body: (h: Here) => Promise<number> | number, o:
37
41
  const argv = process.argv.slice(2)
38
42
  if (argv[0] === 'review' && !argv.includes('--hook') && !argv.includes('--json')) err(`sk review is now sk thread: sk thread ${argv.slice(1).map((a) => (/^[\w./=,@:+#-]+$/.test(a) ? a : JSON.stringify(a))).join(' ')}`)
39
43
  const root = await reviewRoot(process.cwd())
40
- if (root == null) throw new Error(`${process.cwd()} is in no shipkit repo (no repo.config.ts at its git root), so no hub would ever show what is stored here: run it from inside the repo the card is for`)
44
+ if (root == null) throw new Error(`${process.cwd()} is in no shipkit repo (no repo.config.ts at its git root), so no hub would ever show what is stored here: run it from inside the repo the thread is for`)
45
+ // a repo where an agent writes in a thread needs a next session that hears it; the gate's repair wires the hook
46
+ if (WRITING_VERBS.has(argv[1] ?? '')) {
47
+ const { inboxHookLacks } = await import('../review/inbox-read.ts')
48
+ const lacks = inboxHookLacks(root)
49
+ if (lacks.length > 0) err(`review: no inbox hook runs here on ${lacks.join(' and ')}, so the next session may not hear his answer: sk ci --only SK049 wires it (wiki tools/shipkit/threads-how-it-fits.md)`)
50
+ }
41
51
  if (o.unit === false) {
42
52
  const { storeDir } = await import('../review/store.ts')
43
53
  return await body({ dir: storeDir(root), unit: null, say: { spec: (await import('../review/model.ts')).NO_SPEC, more: () => [] }, out, err })
@@ -48,7 +58,7 @@ async function run(context: Ctx, body: (h: Here) => Promise<number> | number, o:
48
58
  return await body({ dir, unit, say: { spec: specOf(dir), more: (x) => factLines(unit, x) }, out, err })
49
59
  } catch (e) {
50
60
  err(`FAIL: review: ${e instanceof Error ? e.message : String(e)}`)
51
- // a walk of the cards' database runs: run it again once it ends
61
+ // a walk of the items' database runs: run it again once it ends
52
62
  const { isStoreRefused, WAIT_EXIT } = await import('../core/machine-db.ts')
53
63
  return isStoreRefused(e) && e.wait ? WAIT_EXIT : 1
54
64
  }
@@ -56,9 +66,12 @@ async function run(context: Ctx, body: (h: Here) => Promise<number> | number, o:
56
66
 
57
67
  const isHelp = (a: string): boolean => a === '--help' || a === '-h'
58
68
 
59
- /** the agent that acts: --as, else SK_AGENT; `need` refuses an unnamed one */
69
+ /** the verbs that write an agent's act in a thread */
70
+ const WRITING_VERBS = new Set(['post', 'add', 'add-view', 'ask', 'propose', 'reply', 'update', 'take', 'assign', 'working', 'fixed', 'done', 'attach', 'ready'])
71
+
72
+ /** the agent that acts (review/parties.ts laneOfCaller); `need` refuses an unnamed one */
60
73
  function actor(as: string | undefined, need: boolean, verb: string): string {
61
- const n = as?.trim() || process.env.SK_AGENT?.trim()
74
+ const n = callerLane(as)
62
75
  if (n === 'owner') throw new Error('the owner acts from the hub, not from here')
63
76
  if (n) return n
64
77
  if (need) throw new Error(`${verb} needs --as <name> (or SK_AGENT)`)
@@ -67,32 +80,83 @@ function actor(as: string | undefined, need: boolean, verb: string): string {
67
80
 
68
81
  /** an item id, a player report's ref (`live#3`), or an address (`trailer:comfy-ts/main`, the newest version of the
69
82
  * thread that owns it, or the one above it) to its item id */
70
- async function idOf(dir: string, ref: string): Promise<string> {
83
+ async function idOf(dir: string, ref: string, one?: { verb: string; objects?: boolean }): Promise<string> {
71
84
  const { itemOfRef, readAll, specOf } = await import('../review/store.ts')
72
- const { ADDRESS_RE, ID_RE } = await import('../review/model.ts')
73
- if (!ID_RE.test(ref) && ADDRESS_RE.test(ref)) {
74
- const { threadOfAddress } = await import('../review/threads.ts')
75
- const t = threadOfAddress(ref, readAll(dir).items, specOf(dir), { up: true })
76
- if (!t) throw new Error(`no thread owns ${ref}: sk thread post ${ref} --title "…" --what "…" <media> starts it`)
77
- return t.head.item.id
85
+ const { addressOrThrow, ID_RE } = await import('../review/model.ts')
86
+ const { THREAD_ID_RE, threadIdOf, threadOfAddress, threadsOf, threadsOfId } = await import('../review/threads.ts')
87
+ // a thread named where one item is needed: refused with the ids it could mean, never its newest version guessed
88
+ const itemOf = async (t: import('../review/threads.ts').Thread): Promise<string> => {
89
+ if (!one) return t.head.item.id
90
+ const { itemIdsOf } = await import('../review/format.ts')
91
+ throw new Error(`${ref === threadIdOf(t) ? `${ref} is a thread` : `${ref} is the thread ${threadIdOf(t)}`}: ${one.verb} takes one item of it, by its id: ${itemIdsOf(t, one.objects).join('; ')}`)
92
+ }
93
+ if (THREAD_ID_RE.test(ref)) {
94
+ const ts = threadsOfId(ref, threadsOf(readAll(dir).items, specOf(dir)))
95
+ if (ts.length === 0) throw new Error(`no thread ${ref} (sk thread --all lists them)`)
96
+ if (ts.length > 1) throw new Error(`${ref} is the first version of ${ts.length} threads (two versions superseded it): name one by its newest version, ${ts.map((t) => t.head.item.id).join(' or ')}`)
97
+ return itemOf(ts[0]!)
98
+ }
99
+ if (!ID_RE.test(ref) && ref.includes(':') && !/^\w+#\d+$/.test(ref)) {
100
+ const a = addressOrThrow(ref)
101
+ const t = threadOfAddress(a, readAll(dir).items, specOf(dir), { up: true })
102
+ if (!t) throw new Error(`no thread owns ${a}: sk thread post ${a} --title "…" --what "…" starts it`)
103
+ return itemOf(t)
78
104
  }
79
105
  const x = itemOfRef(dir, ref)
80
106
  if (!x) throw new Error(`no item ${ref}`)
81
107
  return x.item.id
82
108
  }
83
109
 
84
- /** the sources pulled before a read: a line per source down, said once a process */
85
- const downSaid = new Set<string>()
110
+ /** an address an agent starts a thread on or links: its kind word must be one a kind declares (the repo's or the
111
+ * house's, `sk thread kinds`), so one subject never becomes two threads under two words */
112
+ async function declaredOrThrow(h: Here, a: string): Promise<void> {
113
+ const { readAll } = await import('../review/store.ts')
114
+ const { addressRefusal } = await import('../review/threads.ts')
115
+ const why = addressRefusal(a, readAll(h.dir).items, h.say.spec)
116
+ if (why !== null) throw new Error(why)
117
+ }
118
+
119
+ /** the item an act on `ref` goes on: an id's, or the newest version of the thread its address has; an address no
120
+ * thread owns gets its thread opened with words first, `title` its title, so a question needs no picture */
121
+
122
+ /** an urgent word of an agent: it brings back a thread he set aside (wiki tools/shipkit/threads-asks.md, Snooze) */
123
+ async function urgentOn(dir: string, id: string, who: string): Promise<void> {
124
+ const { appendMessage } = await import('../review/store.ts')
125
+ appendMessage(dir, id, { who, urgent: true })
126
+ }
127
+
128
+ async function idOrOpen(h: Here, ref: string, title: string, as: string | undefined): Promise<string> {
129
+ const { addressOrThrow, ID_RE } = await import('../review/model.ts')
130
+ if (ID_RE.test(ref) || !ref.includes(':') || /^\w+#\d+$/.test(ref)) return idOf(h.dir, ref)
131
+ const a = addressOrThrow(ref)
132
+ const { openThread, readAll, specOf } = await import('../review/store.ts')
133
+ const { threadOfAddress } = await import('../review/threads.ts')
134
+ const t = threadOfAddress(a, readAll(h.dir).items, specOf(h.dir), { up: true })
135
+ if (t) return t.head.item.id
136
+ await declaredOrThrow(h, a)
137
+ const lane = callerLane(as)
138
+ const x = await openThread(h.dir, a, { title, ...(lane ? { lane } : {}) })
139
+ h.err(`${a}: no thread owned it, this one starts it: ${x.id}`)
140
+ return x.id
141
+ }
142
+
143
+ /** why a version that names no subject is refused: a thread is found by its address, so a version without one would
144
+ * start a thread nobody finds again */
145
+ const NO_ADDRESS =
146
+ 'a version names the subject he judges, so it goes into that subject\'s one thread: sk thread post <kind>:<key> --title "…" --what "…" <media> (screen:<screen>, asset:<asset>, page:<page>, or a kind this repo\'s review unit declares; --trailer and --draft name their own). Page: wiki tools/shipkit/threads.md, The model'
147
+
148
+ /** the sources pulled before a read: a line per source down, said once a process and a store */
149
+ const downSaid = new Map<string, Set<string>>()
86
150
  async function pull(h: Here): Promise<void> {
87
151
  if (!h.unit?.sources?.length) return
88
152
  const { pullSources } = await import('../review/project.ts')
89
153
  const now = new Set<string>()
154
+ const said = downSaid.get(h.dir)
90
155
  const got = await pullSources(h.dir, h.unit, (l) => {
91
156
  now.add(l)
92
- if (!downSaid.has(l)) h.err(l)
157
+ if (!said?.has(l)) h.err(l)
93
158
  })
94
- downSaid.clear()
95
- for (const l of now) downSaid.add(l)
159
+ downSaid.set(h.dir, now)
96
160
  if (got.length > 0) h.err(`review: ${got.length} new items pulled`)
97
161
  }
98
162
 
@@ -148,10 +212,45 @@ export function takeViews(args: readonly string[]): { views: ViewInput[]; rest:
148
212
  return { views, rest }
149
213
  }
150
214
 
151
- const ADD_VIEW_USAGE = 'add-view <id> "<label>" <a.png> [<b.png>] | --image <a.png> | --before <a.png> --after <b.png> | --video <clip> | --audio <sound> | --gallery <a.png> … [--label "<label>"] [--note "<text>"] [--keep]'
215
+ const ADD_VIEW_USAGE = 'add-view <id> "<label>" <a.png> [<b.png>] | --image <a.png> | --before <a.png> --after <b.png> | --video <clip> | --audio <sound> | --pano <360.png> | --splat <a.ply> [--image <poster.png>] | --mesh <a.glb> [--image <poster.png>] | --gallery <a.png> … [--label "<label>"] [--note "<text>"] [--keep]'
152
216
  const MEDIA_FILE = /\.(png|jpe?g|webp|gif|mp4|webm|mov|wav|mp3|flac|ogg|opus|m4a)$/i
217
+
218
+ /** one `--option` of a question: words, a media file, `<label>=<file>` or `<label>=<before>,<after>` (a gallery tile's
219
+ * form); the part after the last `=` is media only when each of its files is one */
220
+ export function askOption(a: string): { label: string; files?: string[] } {
221
+ const eq = a.lastIndexOf('=')
222
+ const tail = eq >= 0 ? a.slice(eq + 1).split(',').map((f) => f.trim()) : [a.trim()]
223
+ const media = tail.length <= 2 && tail.every((f) => MEDIA_FILE.test(f))
224
+ if (!media) return { label: a }
225
+ return { label: eq >= 0 ? a.slice(0, eq).trim() : '', files: tail }
226
+ }
153
227
  const quoted = (a: string): string => (/^[\w./=,@:+-]+$/.test(a) ? a : `"${a.replace(/"/g, '\\"')}"`)
154
228
 
229
+ /** a splat's or a mesh's view with its poster: the one given (--image), else the 3D file shot at rest now through the
230
+ * warm browser (view3d/lib.ts); `drop` deletes a shot once the store copied it. Any other view as it is */
231
+ async function withPoster(view: ViewInput): Promise<{ view: ViewInput; drop: () => void }> {
232
+ const space = view.splat ?? view.mesh
233
+ if (space === undefined || view.image !== undefined) return { view, drop: () => {} }
234
+ const { mkdtempSync, rmSync } = await import('node:fs')
235
+ const { tmpdir } = await import('node:os')
236
+ const { join } = await import('node:path')
237
+ const { existsSync } = await import('node:fs')
238
+ const kind = view.splat !== undefined ? 'splat' : 'mesh'
239
+ if (!existsSync(space)) throw new Error(`--${kind} ${space}: no such file`)
240
+ const { SPACE_EXT } = await import('../review/model.ts')
241
+ if (!SPACE_EXT[kind].test(space)) throw new Error(`--${kind} ${space}: ${kind === 'splat' ? 'a Gaussian splat, .ply or .spz' : 'a .glb mesh'}`)
242
+ const tmp = mkdtempSync(join(tmpdir(), 'view3d-poster-'))
243
+ const drop = (): void => rmSync(tmp, { recursive: true, force: true })
244
+ try {
245
+ const out = join(tmp, 'poster.png')
246
+ await (await import('../view3d/lib.ts')).shootPoster(kind, space, out)
247
+ return { view: { ...view, image: out }, drop }
248
+ } catch (e) {
249
+ drop()
250
+ throw new Error(`--${kind} ${space}: its poster could not be shot (${(e as Error).message}); give one with --image <poster.png>`)
251
+ }
252
+ }
253
+
155
254
  /** add-view's args: the positional form, or the view flags of add; a flag is never a label, `own` are the repo unit's flags */
156
255
  export async function addViewArgs(args: readonly string[], own: readonly string[]): Promise<{ id: string; view: ViewInput; repoFlags: Record<string, string[]> }> {
157
256
  const one: Record<string, string> = {}
@@ -170,7 +269,7 @@ export async function addViewArgs(args: readonly string[], own: readonly string[
170
269
  continue
171
270
  }
172
271
  if (name === 'what') throw new Error(`--what: a view takes no --what, a line on it is --note "<text>"; ${ADD_VIEW_USAGE}`)
173
- if (!['label', 'note', 'image', 'video', 'audio', 'before', 'after', ...own].includes(name)) throw new Error(`${a}: add-view takes no such flag; ${ADD_VIEW_USAGE}`)
272
+ if (!['label', 'note', 'image', 'video', 'audio', 'pano', 'splat', 'mesh', 'before', 'after', ...own].includes(name)) throw new Error(`${a}: add-view takes no such flag; ${ADD_VIEW_USAGE}`)
174
273
  const v = args[i + 1]
175
274
  if (v === undefined || v.startsWith('--')) throw new Error(`${a} needs its value; ${ADD_VIEW_USAGE}`)
176
275
  i++
@@ -183,18 +282,23 @@ export async function addViewArgs(args: readonly string[], own: readonly string[
183
282
  let files = rest
184
283
  if (label === undefined && rest[0] !== undefined && !MEDIA_FILE.test(rest[0])) [label, ...files] = rest
185
284
  if (label === undefined && gallery?.[0] !== undefined && !MEDIA_FILE.test(gallery[0]) && !gallery[0].includes('=')) label = gallery.shift()
186
- const given = [files.length > 0 ? 'files' : '', one.image ? '--image' : '', one.video ? '--video' : '', one.audio ? '--audio' : '', one.before || one.after ? '--before --after' : '', gallery ? '--gallery' : ''].filter((x) => x !== '')
285
+ const space = one.splat ?? one.mesh
286
+ const given = [files.length > 0 ? 'files' : '', one.image && space === undefined ? '--image' : '', one.splat ? '--splat' : '', one.mesh ? '--mesh' : '', one.video ? '--video' : '', one.audio ? '--audio' : '', one.pano ? '--pano' : '', one.before || one.after ? '--before --after' : '', gallery ? '--gallery' : ''].filter((x) => x !== '')
187
287
  if (given.length !== 1) throw new Error(`${given.length === 0 ? 'no media' : `one media a view, not ${given.join(' and ')}`}; ${ADD_VIEW_USAGE}`)
188
288
  if (!label?.trim()) throw new Error(`the view needs its label: sk thread ${['add-view', id, '"<label>"', ...args.filter((a) => a !== id).map(quoted)].join(' ')}`)
189
289
  if ((one.before === undefined) !== (one.after === undefined)) throw new Error(`--before and --after go together; ${ADD_VIEW_USAGE}`)
190
290
  if (gallery?.length === 0) throw new Error(`--gallery needs its images; ${ADD_VIEW_USAGE}`)
191
- const view: ViewInput = one.image
291
+ const view: ViewInput = space !== undefined
292
+ ? { label, ...(one.splat ? { splat: one.splat } : { mesh: space }), ...(one.image ? { image: one.image } : {}) }
293
+ : one.image
192
294
  ? { label, image: one.image }
193
295
  : one.video
194
296
  ? { label, video: one.video }
195
297
  : one.audio
196
298
  ? { label, audio: one.audio }
197
- : one.before && one.after
299
+ : one.pano
300
+ ? { label, pano: one.pano }
301
+ : one.before && one.after
198
302
  ? { label, before: one.before, after: one.after }
199
303
  : gallery
200
304
  ? { label, gallery: gallery.map(tileOf) }
@@ -220,7 +324,7 @@ function flagsOf(args: readonly string[], values: readonly string[], repeat: rea
220
324
  on.add(name)
221
325
  continue
222
326
  }
223
- if (!values.includes(name) && !repeat.includes(name)) throw new Error(`${a}: no such flag (sk thread add --help)`)
327
+ if (!values.includes(name) && !repeat.includes(name)) throw new Error(`${a}: no such flag (sk thread post --help)`)
224
328
  const v = args[i + 1]
225
329
  if (v === undefined) throw new Error(`${a}: needs a value`)
226
330
  i++
@@ -231,37 +335,44 @@ function flagsOf(args: readonly string[], values: readonly string[], repeat: rea
231
335
  }
232
336
 
233
337
  const ADD_FLAGS = `flags:
234
- --title "<title>" one short line: what he looks at (a lone "<title>" after add is the same)
235
- --what "<what>" what changed and why, short markdown: one line, then - bullets
338
+ --title "<title>" one short line: what he looks at (a lone "<title>" after the address is the same)
339
+ --what "<what>" what he sees now, one or two short lines: never the mechanics (why no before, an internal rename, how a count is computed)
236
340
  --post "<line>" the public line for a post of it, what a user gets (the repo's guard reads it)
237
- --changelog "<category>: <line>" its change in the release being filled: on his approval it lands in .shipkit/releases/next.md with the card's after picture (the repo's guard reads it)
341
+ --changelog "<category>: <line>" its change in the release being filled: on his approval it lands in .shipkit/releases/next.md with the version's after picture (the repo's guard reads it)
238
342
  --rating <safe|mild|explicit> with --changelog: what its media shows at full size, the rating its picture lands with; unset, unrated (reads explicit: no SFW venue shows it)
343
+ --verdict words with no media wait for the owner's verdict like a version (a version asks it always)
344
+ --md <file.md | -> a markdown document as the subject (a table, a list, numbers; light html: <sub> <kbd> <mark>, <span class="green|amber|red|blue|dim">): words and tables go this way, never as a picture of text; the next version shows a text diff
345
+ --html <file.html | -> an html card as the subject, in a sandboxed frame (its own scripts and styles, no network but the hub's media), for when markdown is not enough
239
346
  --image <a.png> the subject; a clip (webm, mp4) goes anywhere an image goes
240
347
  --video <clip.mp4> a clip
241
348
  --audio <sound.wav> a sound: a waveform and a player (wav, mp3, flac, ogg, opus, m4a)
349
+ --pano <360.png> an equirectangular panorama (2:1): he drags to look around, wheel or pinch to zoom
350
+ --splat <a.ply | a.spz> a Gaussian splat he orbits and flies through, in the lightbox only; --image <poster.png> its still in the thread, else one shot now
351
+ --mesh <a.glb> a mesh he walks through, in the lightbox only; --image <poster.png> its still in the thread, else one shot now
242
352
  --before <a.png> --after <b.png> a before and after: two images, two clips of one size, or two sounds
353
+ on an object of a kind: its states (a json file, or a git ref its kind reads, . the working tree); a kind whose page draws it gets a still of that page shot now, or --image <a.png> as that still; a state that names its "views" gets one still a view, --image <view>=<a.png> for one (repeat it)
354
+ --live [<label>] <url> a running page framed in the thread (repeat it), its shot taken now: what an advisor sees, and what shows while it loads or when it stops answering; a loopback, tailnet or https url, never the hub's own
243
355
  --label "<label>" the first view's label
244
356
  --view "<label>" <a.png> [<b.png>] another view of the same subject (repeat it); --note "<text>" right after it: a line on that view
245
- --choice every view is an option he scores and picks one of (two --view or more)
246
- --pick <view> with --choice: the option you suggest, by its letter (B) or its label; the hub pills it « my pick » (later: sk thread pick <id> <view>)
357
+ --choice the older form of a question: posts sk thread ask with each --view an option, and prints that form
358
+ --pick <n> with --choice: the option you suggest, by its number from 1 (a letter or a label works too); the « my pick » pill
247
359
  --gallery "<label>" <a.png> … a grid he rates tile by tile (stars, OK, fix or no, a word), alone or beside other views; a tile is "[<row>/]<label>=[<before>,]<after>": a redraw carries its before, a row holds one asset's variants
248
- --trailer <cut.trailer> a trailer cut, played in the card by the trailer entry's player, never a compiled clip; his notes land on its shots
360
+ --trailer <cut.trailer> a trailer cut, played in the thread by the trailer entry's player, never a compiled clip; his notes land on its shots
249
361
  --version v<n> with --trailer: a kept version of that cut, else the cut's own render
250
362
  --before v<m> | <cut> with --trailer: the render he switches to on the same shot
251
363
  --shots <a,b> with --trailer: the shots the change touched (else, with --before, the shots whose block differs)
252
- --draft <slug> a post draft of .shipkit/social/drafts/ (its folder, its topic or its path), shown itself in the card, read live: a block a place, each with its own OK, fix or no and his word; no image is made
364
+ --draft <slug> a post draft of the repo's social store (its slug or its topic), shown itself in the thread, read live: a block a place, each with its own OK, fix or no and his word; no image is made
253
365
  --topic <topic> what part of the project it is about (sk thread topics)
254
366
  --subject <kind> what is judged (default shot; the repo's unit names its kinds)
255
367
  --commit <sha> the commit it shows
256
368
  --lane <id> the lane that made it; else SK_AGENT
257
- --wip "<what is still wrong>" a card sent in work: « in progress », no verdict asked; each step after: sk thread update <id> <broken|better|fixed> "<line>" <file>
369
+ --wip "<what is still wrong>" a version sent in work: « in progress », no verdict asked; each step after: sk thread update <id> <broken|better|fixed> "<line>" <file>
258
370
  --on <address> the version's own address (page:review/lightbox, trailer:<name>/<cut>): it goes into the thread that owns it, one thread per address; a trailer or a draft names its own
259
371
  --about <address> another object it is about, a link that finds it (repeat it); never its thread
260
- --supersedes <id> the version it follows; with an address the tool links it, only a wrong link is refused
261
372
  --answers <id | live#3> the item it answers (a note he raised, a player's report), one thread (repeat it)
262
- --keeps "<what stays>" with --supersedes on an approved look: what of it stays
263
- --new --why "<reason>" a new card beside an active one of the same subject
264
- --keep every picture as given; otherwise a png lands as a lossless webp, its pixels checked exact, and the card keeps that webp alone (a jpeg always lands as given)`
373
+ --keeps "<what stays>" on a new version of an approved look: what of it stays
374
+ --new --why "<reason>" a version with no address of its own whose title reads like an active thread's: why it is another subject
375
+ --keep every picture as given; otherwise a png lands as a lossless webp, its pixels checked exact, and the version keeps that webp alone (a jpeg always lands as given)`
265
376
 
266
377
  /** the help of add or add-view, then the flags this repo's review unit adds (any kind's, then each kind's under
267
378
  * `--subject <kind>`); a repo with no unit, or one that does not load, says so on one line */
@@ -280,26 +391,26 @@ async function helpWithUnit(context: Ctx, usage: string, kinds: boolean): Promis
280
391
  return 0
281
392
  }
282
393
 
283
- /** --trailer and its flags as a card: its cut, pinned renders and shots, the image it keeps (a still cut into a temp
394
+ /** --trailer and its flags as a version: its cut, pinned renders and shots, the image it keeps (a still cut into a temp
284
395
  * folder `drop` removes); null without --trailer, which then refuses its own flags */
285
- export async function trailerOfFlags(o: Record<string, string>, others: boolean): Promise<{ card: import('../review/model.ts').TrailerCard; image: string; drop: () => void } | null> {
396
+ export async function trailerOfFlags(o: Record<string, string>, others: boolean): Promise<{ item: import('../review/model.ts').ItemTrailer; image: string; drop: () => void } | null> {
286
397
  if (o.trailer === undefined) {
287
398
  for (const k of ['version', 'shots']) if (o[k] !== undefined) throw new Error(`--${k}: only with --trailer <cut.trailer>`)
288
399
  return null
289
400
  }
290
401
  const clash = ['image', 'video', 'audio', 'after', 'live'].filter((k) => o[k] !== undefined)
291
- if (clash.length > 0 || others) throw new Error(`--trailer: the card plays the cut; no ${clash.length > 0 ? clash.map((k) => `--${k}`).join(', ') : '--view, --gallery, --choice or --wip'} beside it`)
402
+ if (clash.length > 0 || others) throw new Error(`--trailer: the version plays the cut; no ${clash.length > 0 ? clash.map((k) => `--${k}`).join(', ') : '--view, --gallery, --choice or --wip'} beside it`)
292
403
  const { mkdtempSync, rmSync } = await import('node:fs')
293
404
  const { tmpdir } = await import('node:os')
294
405
  const { join } = await import('node:path')
295
406
  const { findRepoRoot } = await import('../ts/config.ts')
296
- const { trailerCardOf } = await import('../review/trailer-card.ts')
297
- const tmp = mkdtempSync(join(tmpdir(), 'trailer-card-'))
407
+ const { trailerItemOf } = await import('../review/trailer-item.ts')
408
+ const tmp = mkdtempSync(join(tmpdir(), 'trailer-version-'))
298
409
  const drop = (): void => rmSync(tmp, { recursive: true, force: true })
299
410
  try {
300
411
  const shots = o.shots?.split(',').map((s) => s.trim()).filter((s) => s !== '')
301
412
  const input = { file: o.trailer, ...(o.version ? { version: o.version } : {}), ...(o.before ? { before: o.before } : {}), ...(shots ? { shots } : {}) }
302
- const r = await trailerCardOf(findRepoRoot(process.cwd()), process.cwd(), input, join(tmp, 'still.png'))
413
+ const r = await trailerItemOf(findRepoRoot(process.cwd()), process.cwd(), input, join(tmp, 'still.png'))
303
414
  return { ...r, drop }
304
415
  } catch (e) {
305
416
  drop()
@@ -307,31 +418,64 @@ export async function trailerOfFlags(o: Record<string, string>, others: boolean)
307
418
  }
308
419
  }
309
420
 
310
- /** --draft as a card: the post draft its slug names, pinned by the hashes of its head and of each message; null without
421
+ /** --draft as a version: the post draft its slug names, pinned by the hashes of its head and of each message; null without
311
422
  * --draft. A draft that does not load clean is refused in the loader's words */
312
- export async function draftOfFlags(o: Record<string, string>, others: boolean, cwd: string = process.cwd()): Promise<import('../review/model.ts').DraftCard | null> {
423
+ export async function draftOfFlags(o: Record<string, string>, others: boolean, cwd: string = process.cwd()): Promise<import('../review/model.ts').ItemDraft | null> {
313
424
  if (o.draft === undefined) return null
314
425
  const clash = ['image', 'video', 'audio', 'before', 'after', 'label', 'live', 'trailer'].filter((k) => o[k] !== undefined)
315
- if (clash.length > 0 || others) throw new Error(`--draft: the card shows the draft itself; no ${clash.length > 0 ? clash.map((k) => `--${k}`).join(', ') : '--view, --gallery or --choice'} beside it`)
316
- const [{ findRepoRoot }, { openDesk }, { draftCardOf }] = await Promise.all([import('../ts/config.ts'), import('../social/open.ts'), import('../review/draft-card.ts')])
317
- return draftCardOf((await openDesk(findRepoRoot(cwd))).desk, o.draft, cwd).card
426
+ if (clash.length > 0 || others) throw new Error(`--draft: the version shows the draft itself; no ${clash.length > 0 ? clash.map((k) => `--${k}`).join(', ') : '--view, --gallery or --choice'} beside it`)
427
+ const [{ findRepoRoot }, { openDesk }, { draftItemOf }] = await Promise.all([import('../ts/config.ts'), import('../social/open.ts'), import('../review/draft-item.ts')])
428
+ return draftItemOf((await openDesk(findRepoRoot(cwd))).desk, o.draft, cwd).item
429
+ }
430
+
431
+ /** --md <file | -> or --html <file | ->: the version's subject is that document, its text read now (`-` stdin); null
432
+ * without either. Words, numbers and tables go this way, never as a picture of text */
433
+ export async function docOfFlags(o: Record<string, string>, beside: { trailer: unknown; draft: unknown; states: unknown; choice: boolean; wip: boolean }, stdin: () => Promise<string> = () => new Response(Bun.stdin.stream()).text()): Promise<import('../review/model.ts').ItemDoc | null> {
434
+ if (o.md !== undefined && o.html !== undefined) throw new Error('--md and --html: one document a version; markdown first, --html when markdown is not enough')
435
+ const kind = o.md !== undefined ? 'md' : o.html !== undefined ? 'html' : null
436
+ if (kind === null) return null
437
+ const other = beside.trailer ? '--trailer' : beside.draft ? '--draft' : beside.states ? "an object's --before and --after states" : beside.choice ? '--choice' : beside.wip ? '--wip --live' : null
438
+ if (other !== null) throw new Error(`--${kind}: a document is the version's subject, never with ${other}`)
439
+ const path = o[kind]!
440
+ const ext = kind === 'md' ? /\.(md|markdown|txt)$/i : /\.html?$/i
441
+ if (path !== '-' && !ext.test(path)) throw new Error(`--${kind} ${path}: ${kind === 'md' ? 'a .md file' : 'an .html file'}, or - to read it from stdin`)
442
+ let text: string
443
+ if (path === '-') text = await stdin()
444
+ else {
445
+ const { existsSync, readFileSync } = await import('node:fs')
446
+ if (!existsSync(path)) throw new Error(`--${kind} ${path}: no such file`)
447
+ text = readFileSync(path, 'utf8')
448
+ }
449
+ if (text.includes('\0')) throw new Error(`--${kind} ${path}: not text`)
450
+ const { docProblem } = await import('../review/model.ts')
451
+ const doc = { kind, text } as const
452
+ const why = docProblem(doc)
453
+ if (why !== null) throw new Error(why)
454
+ return doc
318
455
  }
319
456
 
320
457
  export class ReviewAddCommand extends Command {
321
- static override paths = [['review', 'add']]
458
+ static override paths = [['thread', 'post'], ['review', 'add']]
322
459
  static essential = {}
460
+ /** the flags its proxy reads, as its help lists them: what a doc may name (RV019) */
461
+ static proxyFlags = [...new Set(ADD_FLAGS.match(/--[a-z][a-z0-9-]*/g) ?? [])]
323
462
  static override usage = Command.Usage({
324
463
  category: 'Review',
325
- description: 'a version he answers in the hub: an image, a clip, a pair, views; into the thread of its subject',
326
- details: `${DETAILS}\n\n${ADD_FLAGS}`,
464
+ description: "a version in the thread of its subject, by its address; it starts the thread; no media: words",
465
+ details: `${DETAILS}\n\nsk thread post [<address> | <id>] <flags>. The address is the version's own (screen:<screen>, asset:<asset>, page:<page>, a kind of the repo's unit); --trailer and --draft name theirs, so it may be left out. An id names its thread. With no media, --title and --what are words: they start the thread, or are a reply in it. sk thread add is its older name.\n\n${ADD_FLAGS}`,
327
466
  examples: [
328
- ['one image', 'sk thread add --title "the new menu" --what "the menu, bigger" --image shots/menu.png'],
329
- ['a before and after', 'sk thread add --title "lamps lit" --what "..." --before a.png --after b.png'],
330
- ['a second version after his answer', 'sk thread add --title "lamps lit" --what "..." --image c.png --supersedes <id>'],
331
- ['a pick among three voices, yours on the second', 'sk thread add --choice --pick B --title "the narrator" --what "..." --view "voice 0" a.flac --note "low, breathy" --view "voice 1" b.flac --view "voice 2" c.flac'],
332
- ['icons he rates one by one', 'sk thread add --title "buff icons" --what "..." --gallery "icons" vitality=a.png haste=b.png greed=c.png'],
333
- ['a trailer cut against its last kept version', 'sk thread add --trailer trailer/demo/main.trailer --version v4 --before v3 --title "the drop, recut" --what "..."'],
334
- ['a post draft, each place answered on its own', 'sk thread add --draft 20261119-174922-trailer --title "the trailer post" --what "..."'],
467
+ ['one image', 'sk thread post screen:menu --title "the new menu" --what "the menu, bigger" --image shots/menu.png'],
468
+ ['a report with a table: markdown, never a picture of text', 'sk thread post page:hub/speed --title "the hub, before and after" --what "every click under 50 ms" --md report.md'],
469
+ ['a before and after', 'sk thread post asset:lamps --title "lamps lit" --what "..." --before a.png --after b.png'],
470
+ ['the next version: the same address, the tool links it', 'sk thread post asset:lamps --title "lamps lit, warmer" --what "..." --image c.png'],
471
+ ['a pick among three voices, yours on the second', 'sk thread post asset:narrator --choice --pick 2 --title "the narrator" --what "..." --view "voice 0" a.flac --note "low, breathy" --view "voice 1" b.flac --view "voice 2" c.flac'],
472
+ ['a 360° panorama he looks around in', 'sk thread post screen:hall --title "the hall in 360" --what "..." --pano hall-360.png'],
473
+ ['a Gaussian splat he orbits, its poster shot now', 'sk thread post asset:hall --title "the hall as a splat" --what "..." --splat hall.ply'],
474
+ ['icons he rates one by one', 'sk thread post asset:buff-icons --title "buff icons" --what "..." --gallery "icons" vitality=a.png haste=b.png greed=c.png'],
475
+ ['a trailer cut against its last kept version', 'sk thread post --trailer trailer/demo/main.trailer --version v4 --before v3 --title "the drop, recut" --what "..."'],
476
+ ['a post draft, each place answered on its own', 'sk thread post --draft 20261119-174922-trailer --title "the trailer post" --what "..."'],
477
+ ['a running page, framed in the thread', 'sk thread post page:settings --title "the settings page" --what "..." --live "settings" http://localhost:5173/settings'],
478
+ ['words, no picture', 'sk thread post messages:tui/u1 --title "the hook line" --what "the hook line, shorter: it names the gain first"'],
335
479
  ],
336
480
  })
337
481
  args = Option.Proxy()
@@ -342,47 +486,89 @@ export class ReviewAddCommand extends Command {
342
486
  }
343
487
  return run(this.context, async (h) => {
344
488
  const { addItem, postUpdate, agentName } = await import('../review/store.ts')
345
- // `--wip "<what is still wrong>"`: a card sent in work, its first update still broken; a bare --wip goes with --live
489
+ if (this.path[1] === 'add') h.err('sk thread add is now sk thread post [<address>]: the same flags')
490
+ // `--wip "<what is still wrong>"`: a version sent in work, its first update still broken; a bare --wip goes with --live
346
491
  const w = this.args.indexOf('--wip')
347
492
  const wipLine = w >= 0 && this.args[w + 1] !== undefined && !this.args[w + 1]!.startsWith('--') ? this.args[w + 1] : undefined
348
- const { views, rest } = takeViews(wipLine === undefined ? this.args : [...this.args.slice(0, w + 1), ...this.args.slice(w + 2)])
493
+ const { takeLives } = await import('../review/live-post.ts')
494
+ const { lives, rest: unlived } = takeLives(wipLine === undefined ? this.args : [...this.args.slice(0, w + 1), ...this.args.slice(w + 2)])
495
+ const { views, rest } = takeViews(unlived)
349
496
  // the repo's own flags: the subject kind's (--where), and the unit's for any kind (--mark), each repeatable
350
497
  const kindName = rest[rest.indexOf('--subject') + 1]
351
498
  const kind = rest.includes('--subject') && kindName ? h.unit?.kinds?.[kindName] : undefined
352
499
  const own = [...Object.keys(kind?.flags ?? {}), ...Object.keys(h.unit?.flags ?? {})]
353
- const f = flagsOf(rest, ['title', 'what', 'post', 'changelog', 'rating', 'image', 'video', 'audio', 'before', 'after', 'label', 'topic', 'subject', 'commit', 'lane', 'supersedes', 'keeps', 'why', 'live', 'trailer', 'version', 'shots', 'pick', 'draft', 'on'], ['answers', 'about', ...own], ['new', 'wip', 'choice', 'keep'])
500
+ const f = flagsOf(rest, ['title', 'what', 'post', 'changelog', 'rating', 'video', 'audio', 'pano', 'splat', 'mesh', 'before', 'after', 'label', 'topic', 'subject', 'commit', 'lane', 'supersedes', 'keeps', 'why', 'live', 'trailer', 'version', 'shots', 'pick', 'draft', 'on', 'md', 'html'], ['image', 'answers', 'about', ...own], ['new', 'wip', 'choice', 'keep', 'verdict'])
354
501
  const o = f.one
502
+ // --image repeats only as the stills of a kind's page, one a view (<view>=<a.png>)
503
+ const images = f.many.image ?? []
504
+ if (images.length === 1) o.image = images[0]!
505
+ if (images.length > 1 && f.on.has('choice')) throw new Error('--choice: one --image, the first option; the others are --view')
506
+ // the first word names the thread: an address (the version's own), or an id (its thread)
507
+ const { addressOrThrow, canonicalAddress, ID_RE } = await import('../review/model.ts')
508
+ const first = f.positionals[0]
509
+ // post names its thread first; add's lone word is a title, unless it reads as an address
510
+ const named = first !== undefined && (ID_RE.test(first) || canonicalAddress(first) !== null || (this.path[1] === 'post' && !MEDIA_FILE.test(first)))
511
+ const target = named ? f.positionals.shift() : undefined
512
+ if (target !== undefined && ID_RE.test(target)) {
513
+ const { readAll } = await import('../review/store.ts')
514
+ const { threadOfItem, threadsOf } = await import('../review/threads.ts')
515
+ const { ownAddressOf } = await import('../review/model.ts')
516
+ const t = threadOfItem((await idOf(h.dir, target)), threadsOf(readAll(h.dir).items, h.say.spec))
517
+ if (!t) throw new Error(`no thread holds ${target}`)
518
+ const head = t.head.item
519
+ const own = ownAddressOf(head, h.say.spec)
520
+ if (head.origin.by === 'agent') o.supersedes ??= head.id
521
+ else if (own !== null) o.on ??= own
522
+ else f.many.answers = [...(f.many.answers ?? []), head.id]
523
+ } else if (target !== undefined) {
524
+ const a = addressOrThrow(target)
525
+ if (o.on !== undefined && addressOrThrow(o.on) !== a) throw new Error(`${a} and --on ${o.on}: one address a version`)
526
+ o.on = a
527
+ }
528
+ if (o.on !== undefined) await declaredOrThrow(h, addressOrThrow(o.on))
529
+ for (const a of f.many.about ?? []) await declaredOrThrow(h, addressOrThrow(a))
355
530
  // a lone word is the title, as `sk ask <title>` takes it; a media file never is
356
531
  const [lone, ...more] = f.positionals
357
532
  if (lone !== undefined && more.length === 0 && o.title === undefined && !MEDIA_FILE.test(lone)) o.title = lone
358
- else if (lone !== undefined) throw new Error(`unexpected ${f.positionals.map(quoted).join(' ')}: the title is --title "<title>", the subject --image <a.png> (sk thread add --help)`)
533
+ else if (lone !== undefined) throw new Error(`unexpected ${f.positionals.map(quoted).join(' ')}: the title is --title "<title>", the subject --image <a.png> (sk thread post --help)`)
534
+ if (f.on.has('choice') && f.on.has('verdict')) throw new Error("--choice --verdict: a choice is a question, its pick is the owner's answer; post it without --verdict")
535
+ if (lives.length > 0 && (f.on.has('choice') || o.trailer !== undefined || o.draft !== undefined || o.live !== undefined))
536
+ throw new Error(`--live <url>: a view of a running page; never with ${f.on.has('choice') ? '--choice (ask, then post)' : o.trailer !== undefined ? '--trailer' : o.draft !== undefined ? '--draft' : '--wip --live <name>'}`)
537
+ if (f.on.has('choice')) return choiceAsQuestion(h, o, views, f.many)
538
+ const states = await statesOfFlags(h, o, views.length > 0)
539
+ if (images.length > 1 && !states) throw new Error('--image: one picture a version; it repeats as <view>=<a.png> only beside --after on a kind whose page draws views')
540
+ // a version a kind's page draws shows its stills: the picture given wins over a shot of the page
541
+ const still = states ? await stillOfFlags(h, o, states, images) : null
359
542
  const trailer = await trailerOfFlags(o, views.length > 0 || f.on.has('wip') || f.on.has('choice'))
543
+ // a draft's own address with no media draws the draft itself, as --draft does: never a version of words
544
+ const ownDraft = o.on !== undefined ? /^draft:([^/]+)$/.exec(o.on) : null
545
+ if (ownDraft && o.draft === undefined && views.length === 0 && [o.image, o.video, o.audio, o.pano, o.before, o.after, o.live, o.trailer].every((v) => v === undefined)) o.draft = ownDraft[1]!
360
546
  const draft = await draftOfFlags(o, views.length > 0 || f.on.has('choice'))
361
547
  const repoFlags = Object.fromEntries(own.flatMap((k) => (f.many[k] ? [[k, f.many[k]]] : [])))
362
548
  const parsed = kind?.parse ? kind.parse(Object.fromEntries(Object.keys(kind.flags ?? {}).map((k) => [k, f.many[k] ?? []]))) : null
363
- if (wipLine !== undefined && o.live !== undefined) throw new Error('--wip "<line>" sends a card in work; --wip --live <name> a draft on a live shot: one of the two')
549
+ if (wipLine !== undefined && o.live !== undefined) throw new Error('--wip "<line>" sends a version in work; --wip --live <name> a draft on a live shot: one of the two')
364
550
  if (wipLine === undefined && f.on.has('wip') !== (o.live !== undefined))
365
- throw new Error('--wip "<what is still wrong>" sends a card in work (sk thread update as it moves); --wip --live <name> a draft on a live shot')
551
+ throw new Error('--wip "<what is still wrong>" sends a version in work (sk thread update as it moves); --wip --live <name> a draft on a live shot')
366
552
  let wipViews: ViewInput[] = []
367
553
  if (o.live !== undefined) {
368
554
  if (!h.unit?.live) throw new Error("--live: the repo's review unit declares no live shots (live: { frames })")
369
- if (o.image || o.video || o.audio || o.before || o.after || views.length > 0) throw new Error('--wip: the card shows the live shot alone, no --image, --video, pair or --view beside it')
555
+ if (o.image || o.video || o.audio || o.pano || o.splat || o.mesh || o.before || o.after || views.length > 0) throw new Error('--wip: the version shows the live shot alone, no --image, --video, pair or --view beside it')
370
556
  const fr = h.unit.live.frames(o.live)
371
557
  wipViews = [{ label: '', image: fr.image }, ...(fr.history.length > 0 ? [{ label: 'history', gallery: fr.history }] : [])]
372
558
  }
373
559
  const answers = await Promise.all((f.many.answers ?? []).map((a) => idOf(h.dir, a)))
374
560
  if (o.post !== undefined) {
375
- // a public line: the repo's guard reads it before the card holds it
561
+ // a public line: the repo's guard reads it before the version holds it
376
562
  const { dirname } = await import('node:path')
377
563
  const { loadSocialUnit } = await import('../social/unit.ts')
378
564
  const unit = await loadSocialUnit(dirname(dirname(h.dir)))
379
565
  const problems = unit?.guard ? [...unit.guard({ title: '', alt: '', texts: [o.post], files: [] })] : []
380
566
  if (problems.length > 0) throw new Error(`--post: the repo's guard refuses it: ${problems.join('; ')}`)
381
567
  }
382
- let changelog: import('../review/model.ts').CardChangelog | undefined
568
+ let changelog: import('../review/model.ts').ItemChangelog | undefined
383
569
  if (o.rating !== undefined && o.changelog === undefined) throw new Error('--rating rates the picture its --changelog line lands with: give --changelog too')
384
570
  if (o.changelog !== undefined) {
385
- // its category and line are public words: the repo's guard reads them before the card holds them
571
+ // its category and line are public words: the repo's guard reads them before the item holds them
386
572
  const { dirname } = await import('node:path')
387
573
  const { changelogOfFlag } = await import('../review/model.ts')
388
574
  const { publicProblems } = await import('../social/unit.ts')
@@ -399,18 +585,24 @@ export class ReviewAddCommand extends Command {
399
585
  if (problems.length > 0) throw new Error(`--changelog: the repo's guard refuses it: ${problems.join('; ')}`)
400
586
  }
401
587
  const topic = o.topic ?? parsed?.topic
588
+ const doc = await docOfFlags(o, { trailer, draft, states, choice: f.on.has('choice'), wip: o.live !== undefined })
402
589
  let input: import('../review/store.ts').AddInput = {
403
590
  title: o.title ?? '',
404
591
  what: o.what ?? '',
405
592
  ...(o.post ? { post: o.post } : {}),
406
593
  ...(changelog ? { changelog } : {}),
407
- ...(parsed ? { subject: parsed.subject } : o.subject ? { subject: { kind: o.subject } } : trailer ? { subject: { kind: 'trailer' } } : draft ? { subject: { kind: 'draft', slug: draft.slug } } : {}),
594
+ ...(parsed ? { subject: parsed.subject } : o.subject ? { subject: { kind: o.subject } } : trailer ? { subject: { kind: 'trailer' } } : draft ? { subject: { kind: 'draft', slug: draft.slug } } : doc ? { subject: { kind: 'doc' } } : {}),
595
+ ...(doc ? { doc } : {}),
408
596
  ...(topic ? { topic } : {}),
409
- ...(trailer ? { image: trailer.image, trailer: trailer.card } : {}),
597
+ ...(trailer ? { image: trailer.image, trailer: trailer.item } : {}),
410
598
  ...(draft ? { draft } : {}),
599
+ ...(states ? { states } : {}),
411
600
  ...(o.image ? { image: o.image } : {}),
412
601
  ...(o.video ? { video: o.video } : {}),
413
602
  ...(o.audio ? { audio: o.audio } : {}),
603
+ ...(o.pano ? { pano: o.pano } : {}),
604
+ ...(o.splat ? { splat: o.splat } : {}),
605
+ ...(o.mesh ? { mesh: o.mesh } : {}),
414
606
  ...(o.before && !trailer ? { before: o.before } : {}),
415
607
  ...(o.after ? { after: o.after } : {}),
416
608
  ...(o.label ? { label: o.label } : {}),
@@ -428,12 +620,34 @@ export class ReviewAddCommand extends Command {
428
620
  ...(o.pick !== undefined ? { agentPick: o.pick } : {}),
429
621
  ...(o.live !== undefined ? { image: wipViews[0]?.image ?? '', views: wipViews.slice(1), wip: { live: o.live } } : { views }),
430
622
  }
623
+ const media = [o.image, o.video, o.audio, o.pano, o.splat, o.mesh, o.before, o.after, o.live, o.trailer, o.draft].some((v) => v !== undefined) || views.length > 0 || lives.length > 0 || states !== null || doc !== null
624
+ if (!media && input.on !== undefined) return postWords(h, input.on, input.title, input.what, input.lane, f.on.has('verdict'))
625
+ // a version asks the owner's verdict always: the field says it, the flag changes nothing else
626
+ if (f.on.has('verdict')) input = { ...input, asksVerdict: true }
627
+ // each live page asked and shot now: its shot is the view everyone but the owner's hub sees
628
+ const shots = lives.length > 0 ? await (await import('../review/live-post.ts')).liveViews(lives) : null
629
+ if (shots) input = { ...input, views: [...(input.views ?? []), ...shots.views] }
630
+ // a splat or a mesh with no --image: its poster shot now, the viewer at rest
631
+ const poster = await withPoster({ label: '', ...(input.splat ? { splat: input.splat } : {}), ...(input.mesh ? { mesh: input.mesh } : {}), ...(input.image ? { image: input.image } : {}) })
632
+ if (poster.view.image !== undefined) input = { ...input, image: poster.view.image }
431
633
  if (h.unit?.add) input = await h.unit.add(input, repoFlags)
432
- const item = await addItem(h.dir, input).finally(() => trailer?.drop())
634
+ const { ownAddressOf } = await import('../review/model.ts')
635
+ const address = ownAddressOf({ subject: input.subject ?? { kind: 'shot' }, ...(input.on ? { on: input.on } : {}), ...(input.trailer ? { trailer: input.trailer } : {}), origin: { by: 'agent' }, views: [] } as unknown as import('../review/model.ts').Item, h.say.spec)
636
+ if (address === null && input.supersedes === undefined && (input.answers ?? []).length === 0) {
637
+ trailer?.drop()
638
+ shots?.drop()
639
+ poster.drop()
640
+ throw new Error(NO_ADDRESS)
641
+ }
642
+ const item = await addItem(h.dir, input).finally(() => {
643
+ trailer?.drop()
644
+ shots?.drop()
645
+ poster.drop()
646
+ })
647
+ if (still) await keepStill(h, item, still)
433
648
  h.out(item.id)
434
649
  // on stderr: a script reads the id alone on stdout
435
- if (item.supersedes !== undefined && o.supersedes === undefined) h.err(`into its thread: the next version after ${item.supersedes}, its own address one thread`)
436
- else if ((item.answers ?? []).some((a) => !answers.includes(a))) h.err(`into its thread: it answers the notes ${(item.answers ?? []).join(', ')}`)
650
+ await saidIntoThread(h, item, o.supersedes !== undefined)
437
651
  if (wipLine !== undefined) {
438
652
  const who = item.origin.by === 'agent' ? (item.origin.lane ?? agentName()) : agentName()
439
653
  await postUpdate(h.dir, item.id, { who, state: 'broken', text: wipLine })
@@ -441,14 +655,14 @@ export class ReviewAddCommand extends Command {
441
655
  }
442
656
  // on stderr: a script reads the id alone on stdout
443
657
  for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, item)) h.err(line)
444
- if (item.trailer) h.out(`trailer card: ${item.trailer.trailer}/${item.trailer.after.cut}${item.trailer.before ? ` against ${item.trailer.before.cut}` : ''}${item.trailer.shots.length > 0 ? `, shots ${item.trailer.shots.join(', ')}` : ''}`)
445
- // a cut shown on a card is a version from then on: the next edit of its file makes the one after it
658
+ if (item.trailer) h.out(`trailer version: ${item.trailer.trailer}/${item.trailer.after.cut}${item.trailer.before ? ` against ${item.trailer.before.cut}` : ''}${item.trailer.shots.length > 0 ? `, shots ${item.trailer.shots.join(', ')}` : ''}`)
659
+ // a cut shown in a thread is a version from then on: the next edit of its file makes the one after it
446
660
  if (item.trailer && o.trailer !== undefined && o.version === undefined) {
447
661
  try {
448
662
  const [b, { keepShown, thumbnailKept, versionVideo }, { findRepoRoot }] = await Promise.all([import('../trailer/build.ts'), import('../trailer/passage.ts'), import('../ts/config.ts')])
449
663
  const root = findRepoRoot(process.cwd())
450
664
  const l = await b.load(b.trailerFile(o.trailer, root, process.cwd()), root)
451
- if ((await import('node:fs')).existsSync(b.mockMark(l))) h.err('the cut this card shows is a MOCK (sk trailer --mock built it last): its --what must say so; for the filmed cut, sk trailer first')
665
+ if ((await import('node:fs')).existsSync(b.mockMark(l))) h.err('the cut this version shows is a MOCK (sk trailer --mock built it last): its --what must say so; for the filmed cut, sk trailer first')
452
666
  // a version is a video a post may use: a cut that may not render (no thumbnail word) keeps none
453
667
  if (l.errors.length > 0) throw new Error(`${l.errors[0]!.message} (line ${l.errors[0]!.line})`)
454
668
  const lines: string[] = []
@@ -462,12 +676,12 @@ export class ReviewAddCommand extends Command {
462
676
  h.err(`WARN ${v} is kept, its thumbnail is not: ${(e as Error).message}`),
463
677
  )
464
678
  } catch (e) {
465
- h.err(`WARN the card is sent, the cut was not kept as a version: ${(e as Error).message}`)
679
+ h.err(`WARN the version is sent, the cut was not kept as a version: ${(e as Error).message}`)
466
680
  }
467
681
  }
468
- if (item.draft) h.out(`draft card: ${item.draft.slug}, ${item.draft.posts.length} place${item.draft.posts.length > 1 ? 's' : ''}: ${item.draft.posts.map((p) => p.name).join(', ')}`)
469
- if (item.origin.by === 'agent' && !item.origin.lane) h.err('no lane on the card: pass --lane <id> (or SK_AGENT), so the hub colours it')
470
- if (item.choice && item.agentPick === undefined) h.err(`a choice with no pick of yours: every question carries one, sk thread pick ${item.id} <view> (or --pick on add)`)
682
+ if (item.draft) h.out(`draft version: ${item.draft.slug}, ${item.draft.posts.length} place${item.draft.posts.length > 1 ? 's' : ''}: ${item.draft.posts.map((p) => p.name).join(', ')}`)
683
+ if (item.origin.by === 'agent' && !item.origin.lane) h.err(`posted ${item.id} with no lane: on the next post pass --lane <id> (or SK_AGENT), so the hub colours it; never post this one again`)
684
+ if (item.choice && item.agentPick === undefined) h.err(`a choice with no pick of yours: every question carries one, sk thread pick ${item.id} <view> (or --pick on post)`)
471
685
  const { unheardLine } = await import('../review/model.ts')
472
686
  const { liveWatchers } = await import('../review/watchers.ts')
473
687
  const unheard = unheardLine(item, liveWatchers(h.dir))
@@ -477,6 +691,179 @@ export class ReviewAddCommand extends Command {
477
691
  }
478
692
  }
479
693
 
694
+ /** what a version that went into a thread says on stderr: the version it follows (and that one's verdict, which only the
695
+ * newest version takes), the way out for a subject of its own, and his notes it leaves open */
696
+ /** `post <address> --before <state> --after <state>` on an object of a kind (threads-how-it-fits.md, Kinds): each side
697
+ * a json file (`{ json, files? }` or bare json), or a git ref (`.` the working tree) the kind's `read` turns into one;
698
+ * null when the flags are a picture's before and after. The flags it takes are cleared, so no media reads them */
699
+ async function statesOfFlags(h: Here, o: Record<string, string>, views: boolean): Promise<{ before?: import('../review/model.ts').StoredState; after: import('../review/model.ts').StoredState } | null> {
700
+ if (o.on === undefined || o.after === undefined) return null
701
+ const word = o.on.slice(0, o.on.indexOf(':'))
702
+ const key = o.on.slice(o.on.indexOf(':') + 1)
703
+ const { findRepoRoot } = await import('../ts/config.ts')
704
+ const root = findRepoRoot(process.cwd())
705
+ const kind = (await import('../review/house-kind-defs.ts')).serverKindOf(root, h.unit, word)
706
+ const json = (v: string): boolean => /\.json$/i.test(v)
707
+ if (!kind?.read && !json(o.after)) return null
708
+ if (views || o.video || o.audio || o.pano || o.splat || o.mesh) throw new Error(`${o.on}: a version of an object shows its two states and their still (--image) alone, no other picture beside them`)
709
+ const { existsSync, readFileSync } = await import('node:fs')
710
+ const side = async (flag: string, v: string): Promise<import('../review/model.ts').StoredState> => {
711
+ if (json(v)) {
712
+ if (!existsSync(v)) throw new Error(`--${flag} ${v}: no such file`)
713
+ const parsed = JSON.parse(readFileSync(v, 'utf8')) as unknown
714
+ return typeof parsed === 'object' && parsed !== null && 'json' in parsed ? (parsed as import('../review/model.ts').StoredState) : { json: parsed }
715
+ }
716
+ if (!kind?.read) throw new Error(`--${flag} ${v}: a json file, or a git ref the kind reads; the kind ${word} declares no read`)
717
+ let at: string | undefined
718
+ if (v !== '.') {
719
+ const p = realGit.runSync(root, ['rev-parse', '--verify', '--quiet', `${v}^{commit}`])
720
+ at = p.out.trim()
721
+ if (p.code !== 0 || at === '') throw new Error(`--${flag} ${v}: no commit of this repo by that name (a json file, a git ref, or . for the working tree)`)
722
+ }
723
+ const st = await kind.read(key, at)
724
+ if (st === null) throw new Error(`--${flag} ${v}: the kind ${word} reads no ${key} there`)
725
+ return { ...st, ...(at ? { at } : {}) }
726
+ }
727
+ const after = await side('after', o.after)
728
+ const before = o.before !== undefined ? await side('before', o.before) : undefined
729
+ delete o.before
730
+ delete o.after
731
+ return { ...(before ? { before } : {}), after }
732
+ }
733
+
734
+ /** where the stills of a version of an object come from (review/kind-still.ts): `--image`, taken out of the flags so
735
+ * no view reads it, else a shot of the kind's page once the version exists, one a view its state names; null when its
736
+ * kind draws no page */
737
+ async function stillOfFlags(h: Here, o: Record<string, string>, states: { before?: import('../review/model.ts').StoredState; after: import('../review/model.ts').StoredState }, images: readonly string[]) {
738
+ const word = o.on!.slice(0, o.on!.indexOf(':'))
739
+ const { findRepoRoot } = await import('../ts/config.ts')
740
+ const kind = (await import('../review/house-kind-defs.ts')).serverKindOf(findRepoRoot(process.cwd()), h.unit, word)
741
+ const plan = (await import('../review/kind-still.ts')).stillPlan(kind, states, images)
742
+ delete o.image
743
+ return plan ? { plan, kind } : null
744
+ }
745
+
746
+ /** the version's stills kept beside its states: each picture given, else a shot of the kind's page through the hub
747
+ * (`mode=thumb`, the view's `view`), as a live view's shot is taken. A state that names views gets one gallery tile a
748
+ * view, else the one still. A still that cannot be shot never holds the version back: the thread then shows a
749
+ * placeholder that opens the page, and the line says why */
750
+ async function keepStill(h: Here, item: import('../review/model.ts').Item, still: NonNullable<Awaited<ReturnType<typeof stillOfFlags>>>): Promise<void> {
751
+ const { setStill, setKindStills } = await import('../review/store.ts')
752
+ const { kindFrames } = await import('../review/kind-still.ts')
753
+ const lone = still.plan.length === 1 && still.plan[0]!.view === null ? still.plan[0]! : null
754
+ if (lone?.image !== undefined) return void (await setStill(h.dir, item.id, { image: lone.image }))
755
+ const { pasteHosts } = await import('../review/paste.ts')
756
+ const { findRepoRoot } = await import('../ts/config.ts')
757
+ const hub = (await pasteHosts(findRepoRoot(process.cwd()))).open.replace(/\/$/, '')
758
+ const drops: (() => void)[] = []
759
+ try {
760
+ const shotOf = async (view: string | undefined) => {
761
+ const plan = kindFrames(still.kind, item, (side) => `${hub}/api/review/${item.id}/state?side=${side}`, { view, mode: 'thumb' })
762
+ if (plan === null) return null
763
+ const shots = await (await import('../review/live-post.ts')).kindStill(hub, plan.page, plan.frames)
764
+ drops.push(shots.drop)
765
+ return shots.files
766
+ }
767
+ if (lone) {
768
+ const files = await shotOf(undefined)
769
+ if (files) await setStill(h.dir, item.id, files)
770
+ return
771
+ }
772
+ const tiles: { view: string; label: string; file: string; before?: string }[] = []
773
+ for (const s of still.plan) {
774
+ const v = s.view!
775
+ if (s.image !== undefined) {
776
+ tiles.push({ view: v.id, label: v.label, file: s.image })
777
+ continue
778
+ }
779
+ const files = await shotOf(v.id)
780
+ if (files === null) return
781
+ tiles.push({ view: v.id, label: v.label, ...('image' in files ? { file: files.image } : { file: files.after, before: files.before }) })
782
+ }
783
+ await setKindStills(h.dir, item.id, tiles)
784
+ } catch (e) {
785
+ h.err(`WARN the version is sent with no still: ${(e as Error).message}. The thread shows a placeholder that opens the page; --image <a.png> gives one${lone ? '' : ', --image <view>=<a.png> one a view'}`)
786
+ } finally {
787
+ for (const d of drops) d()
788
+ }
789
+ }
790
+
791
+ /** `post --choice`, the older form of a question with media options: each view an option (its note after its label),
792
+ * the title and what its words, posted as the question into the address's thread; it prints the `ask` form */
793
+ async function choiceAsQuestion(h: Here, o: Record<string, string>, views: readonly ViewInput[], many: Record<string, string[]>): Promise<number> {
794
+ const versionOnly = ['changelog', 'rating', 'post', 'keeps', 'supersedes', 'trailer', 'draft', 'live', 'why'].filter((k) => o[k] !== undefined)
795
+ if (many.answers?.length) versionOnly.push('answers')
796
+ if (versionOnly.length > 0) throw new Error(`--choice is a question now, and a question takes no ${versionOnly.map((k) => `--${k}`).join(', ')}: ask, then post the version once he picked`)
797
+ if (views.some((v) => v.gallery)) throw new Error('--choice: a gallery is no option; a set he rates one by one stays a gallery version, a row per asset')
798
+ if (o.on === undefined) throw new Error(NO_ADDRESS)
799
+ const first = o.image ?? o.video ?? o.audio
800
+ const all: ViewInput[] = [...(first !== undefined ? [{ label: o.label ?? 'option 1', image: first }] : o.before !== undefined && o.after !== undefined ? [{ label: o.label ?? 'option 1', before: o.before, after: o.after }] : []), ...views]
801
+ const options = all.map((v) => ({ label: v.note?.trim() ? `${v.label}: ${v.note.trim()}` : v.label, files: v.before !== undefined && v.after !== undefined ? [v.before, v.after] : [v.image ?? v.video ?? v.audio ?? ''] }))
802
+ const { viewIndexOf } = await import('../review/model.ts')
803
+ const pick = o.pick === undefined ? undefined : /^\d+$/.test(o.pick) ? Number(o.pick) - 1 : viewIndexOf(all, o.pick)
804
+ const text = [o.title, o.what].filter((x) => x?.trim()).join('\n') || 'which one ?'
805
+ const form = `sk thread ask ${o.on} ${quoted(text.split('\n')[0]!)} ${options.map((x) => `--option ${quoted(`${x.label}=${x.files.join(',')}`)}`).join(' ')}${pick !== undefined ? ` --pick ${pick + 1}` : ''}`
806
+ h.err(`post --choice is now a question: ${form}`)
807
+ if (pick === undefined) h.err('no --pick: the house rule wants your pick on every question')
808
+ const { postAsk } = await import('../review/store.ts')
809
+ const as = o.lane
810
+ const id = await idOrOpen(h, o.on, o.title ?? text, as)
811
+ const m = await postAsk(h.dir, id, { who: actor(as, false, 'ask'), text, options, ...(pick !== undefined ? { pick } : {}) })
812
+ h.out(`${id} asked: ${m.ask?.options.map((x, i) => `${i + 1} ${x}${m.ask?.pick === i ? ' (your pick)' : ''}`).join(' · ')}`)
813
+ return 0
814
+ }
815
+
816
+ async function saidIntoThread(h: Here, item: import('../review/model.ts').Item, typed: boolean): Promise<void> {
817
+ const { readAll } = await import('../review/store.ts')
818
+ const { ownAddressOf, stateOf, verdictOf } = await import('../review/model.ts')
819
+ const { threadOfItem, threadsOf } = await import('../review/threads.ts')
820
+ const items = readAll(h.dir).items
821
+ const t = threadOfItem(item.id, threadsOf(items, h.say.spec))
822
+ const own = ownAddressOf(item, h.say.spec)
823
+ const before = item.supersedes === undefined ? undefined : items.find((x) => x.item.id === item.supersedes)
824
+ if (before && !typed) {
825
+ const waited = verdictOf(before) === null && before.item.views.length > 0
826
+ h.err(`into its thread ${own ?? ''}: the next version after ${before.item.id} "${before.item.title}"${waited ? ', which waited on his answer: only this one takes his marks now' : ''}. A subject he judges on its own takes its own address: --on ${own ?? '<kind>:<key>'}/<part>`)
827
+ }
828
+ const notes = t ? [...(t.head.item.origin.by === 'agent' ? [] : [t.head]), ...t.answers.filter((x) => t.joined.has(x.item.id))] : []
829
+ const open = notes.filter((x) => stateOf(x, false).state !== 'closed' && !(item.answers ?? []).includes(x.item.id))
830
+ if (open.length > 0) h.err(`his notes in the thread stay open: ${open.map((x) => `${x.item.id} "${x.item.title}"`).join('; ')}. Close one once done: sk thread fixed <id> "<what was done>"; or name it on the version: --answers <id>`)
831
+ }
832
+
833
+ /** `post <address>` with no media: words that start the address's thread, or a reply in the thread it has. The thread
834
+ * is the one its own address names, as a version's: a part address (`<kind>:<key>/<part>`) is its own thread, never
835
+ * its parent's */
836
+ async function postWords(h: Here, address: string, title: string, what: string, lane: string | undefined, verdict = false): Promise<number> {
837
+ const { agentName, openThread, readAll, specOf } = await import('../review/store.ts')
838
+ const { threadIdOf, threadOfAddress } = await import('../review/threads.ts')
839
+ if (!title.trim() && !what.trim()) throw new Error('--title "<words>" (and --what): with no media, a post is words')
840
+ const t = threadOfAddress(address, readAll(h.dir).items, specOf(h.dir))
841
+ if (t) {
842
+ const m = await wordsIn(h.dir, t.head.item.id, lane?.trim() || agentName(), [title.trim(), what.trim()].filter(Boolean).join('\n'), verdict)
843
+ h.out(`${t.head.item.id}: ${m.id}`)
844
+ h.err(`a word in the thread ${threadIdOf(t)} of ${address}${verdict ? ", waiting for the owner's verdict" : ''}`)
845
+ return 0
846
+ }
847
+ const x = await openThread(h.dir, address, { title: title.trim() || what.trim(), ...(what.trim() ? { what } : {}), ...(lane?.trim() ? { lane: lane.trim() } : {}), ...(verdict ? { asksVerdict: true as const } : {}) })
848
+ h.out(x.id)
849
+ h.err(`${address}: the thread starts with these words`)
850
+ return 0
851
+ }
852
+
853
+ /** an agent's words in a thread, its image beside them; `verdict`: they wait for the owner's verdict (review/verdict-items.ts) */
854
+ async function wordsIn(dir: string, id: string, who: string, text: string, verdict: boolean, image?: string): Promise<import('../review/model.ts').Message> {
855
+ const { addMessage, appendMessage, readItem } = await import('../review/store.ts')
856
+ if (!verdict) return addMessage(dir, id, who, text, image)
857
+ const { textOf } = await import('../review/model.ts')
858
+ if (!readItem(dir, id)) throw new Error(`no item ${id}`)
859
+ const t = textOf(text)
860
+ if ('error' in t) throw new Error(t.error)
861
+ return appendMessage(dir, id, { who, text: t.text, asksVerdict: true }, image !== undefined ? { image } : {})
862
+ }
863
+
864
+ /** `--verdict` on a posting verb: it waits for the owner's verdict (wiki tools/shipkit/threads-how-it-fits.md, The model) */
865
+ const VERDICT_FLAG = "it waits for the owner's verdict (approve, fix, reject on it in the hub, « judge » in the inbox): a thing made that the owner approves before it ships or lands; a choice of what to do is a question, a visible change a version, never on a progress line"
866
+
480
867
  export class ReviewAddViewCommand extends Command {
481
868
  static override paths = [['review', 'add-view']]
482
869
  static essential = {}
@@ -487,6 +874,7 @@ export class ReviewAddViewCommand extends Command {
487
874
  examples: [
488
875
  ['a view from above', 'sk thread add-view <id> "from above" top.png'],
489
876
  ['a before and after', 'sk thread add-view <id> --label "on a phone" --before a.png --after b.png'],
877
+ ['a 360° panorama', 'sk thread add-view <id> --label "inside" --pano hall-360.png'],
490
878
  ],
491
879
  })
492
880
  args = Option.Proxy()
@@ -496,16 +884,20 @@ export class ReviewAddViewCommand extends Command {
496
884
  return helpWithUnit(this.context, this.cli.usage(ReviewAddViewCommand, { detailed: true }), false)
497
885
  }
498
886
  return run(this.context, async (h) => {
499
- const { addView } = await import('../review/store.ts')
887
+ const { addViewAlso } = await import('../review/store.ts')
500
888
  const keep = this.args.includes('--keep')
501
889
  const a = await addViewArgs(this.args.filter((x) => x !== '--keep'), Object.keys(h.unit?.flags ?? {}))
502
- const v = a.view
503
890
  const id = await idOf(h.dir, a.id)
891
+ const posted = await withPoster(a.view)
892
+ const v = posted.view
504
893
  const extra = h.unit?.addView ? await h.unit.addView(v, a.repoFlags) : {}
505
- const item = await addView(h.dir, id, v, { ...extra, ...(keep ? { keep: true } : {}) })
894
+ const { item, added } = await addViewAlso(h.dir, id, v, { ...extra, ...(keep ? { keep: true } : {}) }).finally(posted.drop)
506
895
  const { viewNo } = await import('../review/model.ts')
507
- h.out(`${id}: view ${viewNo(item.views.length - 1)} "${v.label}" added`)
508
- for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, item, item.views.length - 1)) h.err(line)
896
+ const { playCopies } = await import('../review/previews.ts')
897
+ for (const n of added) {
898
+ h.out(`${id}: view ${viewNo(n)} "${item.views[n]!.label}" added`)
899
+ for (const line of await playCopies(h.dir, item, n)) h.err(line)
900
+ }
509
901
  return 0
510
902
  })
511
903
  }
@@ -515,7 +907,7 @@ export class ReviewLsCommand extends Command {
515
907
  static override paths = [['review'], ['review', 'ls']]
516
908
  static override usage = Command.Usage({
517
909
  category: 'Review',
518
- description: "the store's active threads, one line each: status, id, title; `sk thread <verb>` runs a unit's verb",
910
+ description: "the active threads: status, thread id, title, address; `sk thread <verb>` runs a unit's verb",
519
911
  details: `${DETAILS}\n\nsk thread [--all] lists; sk thread <verb> … runs a verb the repo's review unit declares (verbs: {...}).`,
520
912
  examples: [['what is open', 'sk thread ls'], ['every thread', 'sk thread ls --all']],
521
913
  })
@@ -556,7 +948,12 @@ export class ReviewLsCommand extends Command {
556
948
  for (const b of all.broken) h.err(`review: FAIL ${b.id}: ${b.error}`)
557
949
  const threads = orderedThreads(all.items).filter((t) => every || isActive(t))
558
950
  if (threads.length === 0) h.out(every ? 'review: the store is empty' : 'review: nothing active (--all shows every thread)')
559
- for (const t of threads) h.out(`${statusOf(t.head, all.items).padEnd(17)} ${t.head.item.id} ${t.head.item.title}${t.versions.length > 1 ? ` (v${t.versions.length})` : ''}`)
951
+ const { ownAddressesOf, threadIdOf, threadTitle } = await import('../review/threads.ts')
952
+ // the thread's own id, never an item's: the items' ids are `sk thread show <thread>`'s
953
+ for (const t of threads) {
954
+ const at = ownAddressesOf(t)[0]
955
+ h.out(`${statusOf(t.head, all.items).padEnd(17)} ${threadIdOf(t)} ${threadTitle(t)}${t.versions.length > 1 ? ` (v${t.versions.length})` : ''}${at ? ` ${at}` : ''}`)
956
+ }
560
957
  return all.broken.length > 0 ? 1 : 0
561
958
  },
562
959
  { unit: false },
@@ -566,19 +963,19 @@ export class ReviewLsCommand extends Command {
566
963
 
567
964
  export class ReviewShowCommand extends Command {
568
965
  static override paths = [['review', 'show']]
569
- static essential = { args: '<id>' }
966
+ static essential = { args: '<address | id>' }
570
967
  static override usage = Command.Usage({
571
968
  category: 'Review',
572
969
  description: 'one item and its thread: the verdict, rectangles, reactions, the whole conversation',
573
- details: `${DETAILS}\n\nTakes an item id or a player report's ref (live#3). --paste prints the short block that hands the card to another agent session (the hub's copy button gives the same).`,
574
- examples: [['hand a card to another session', 'sk thread show <id> --paste']],
970
+ details: `${DETAILS}\n\nTakes an item id or a player report's ref (live#3). --paste prints the short block that hands the thread to another agent session (the hub's copy button gives the same).`,
971
+ examples: [['hand a thread to another session', 'sk thread show <id> --paste']],
575
972
  })
576
- id = Option.String()
973
+ id = Option.String({ name: 'address | id' })
577
974
  paste = Option.Boolean('--paste', false, { description: 'the block another agent session acts on: title, repo, this command, the links' })
578
975
 
579
976
  async execute(): Promise<number> {
580
977
  return run(this.context, async (h) => {
581
- const { readAllCached } = await import('../review/store.ts')
978
+ const { mediaDir, readAllCached } = await import('../review/store.ts')
582
979
  const { threadDetail, detail } = await import('../review/format.ts')
583
980
  const { threadOfItem, threadsOf } = await import('../review/threads.ts')
584
981
  const id = await idOf(h.dir, this.id)
@@ -587,25 +984,25 @@ export class ReviewShowCommand extends Command {
587
984
  if (!x) throw new Error(`no item ${this.id}`)
588
985
  if (this.paste) {
589
986
  const { dirname } = await import('node:path')
590
- const { pasteHosts, cardUrl } = await import('../review/paste.ts')
987
+ const { pasteHosts, threadUrl } = await import('../review/paste.ts')
591
988
  const { pasteBlock, STATUS_LABEL } = await import('../review/model.ts')
592
989
  const { statusOf } = await import('../review/threads.ts')
593
990
  const w = await pasteHosts(dirname(dirname(h.dir)))
594
- h.out(pasteBlock(x.item, STATUS_LABEL[statusOf(x, all.items)], { root: w.root, open: cardUrl(w.open, x.item.id), phone: w.phone ? cardUrl(w.phone, x.item.id) : null }))
991
+ h.out(pasteBlock(x.item, STATUS_LABEL[statusOf(x, all.items)], { root: w.root, open: threadUrl(w.open, x.item.id), phone: w.phone ? threadUrl(w.phone, x.item.id) : null }))
595
992
  return 0
596
993
  }
597
994
  const t = threadOfItem(x.item.id, threadsOf(all.items))
598
- // the image paths it prints are on the disk: a message image the purge let go comes back first
995
+ // the paths it prints are on the disk: a message's image or file the purge let go comes back first
599
996
  const { ensureLocal } = await import('../review/media-read.ts')
600
997
  const { membersOf } = await import('../review/threads.ts')
601
- await Promise.all((t ? membersOf(t) : [x]).flatMap((y) => y.thread.flatMap((m) => (m.image ? [ensureLocal(h.dir, y.item.id, `thread/${m.image}`).catch((e: Error) => h.err(`review: WARN thread/${m.image}: ${e.message}`))] : []))))
602
- h.out(t && (t.head.item.id === x.item.id || t.answers.length > 0) ? threadDetail(t, h.dir, true, h.say) : detail(x, h.dir, true, false, h.say))
998
+ await Promise.all((t ? membersOf(t) : [x]).flatMap((y) => y.thread.flatMap((m) => [...(m.image ? [m.image] : []), ...(m.files ?? []).map((g) => g.file)].map((n) => ensureLocal(h.dir, y.item.id, `thread/${n}`).catch((e: Error) => h.err(`review: WARN thread/${n}: ${e.message}`))))))
999
+ h.out(t && (t.head.item.id === x.item.id || t.answers.length > 0) ? threadDetail(t, mediaDir(h.dir), true, h.say) : detail(x, mediaDir(h.dir), true, false, h.say))
603
1000
  return 0
604
1001
  })
605
1002
  }
606
1003
  }
607
1004
 
608
- /** --mine or --session <id>: only the cards that session opened; null keeps every item */
1005
+ /** --mine or --session <id>: only the items that session opened; null keeps every item */
609
1006
  async function sessionOf(mine: boolean, session: string | undefined): Promise<string | null> {
610
1007
  if (session !== undefined) return session
611
1008
  if (!mine) return null
@@ -622,119 +1019,259 @@ export class ReviewInboxCommand extends Command {
622
1019
  category: 'Review',
623
1020
  description: 'every answer not marked seen and every open item he raised, frame notes included',
624
1021
  details: DETAILS,
625
- examples: [['what waits on you', 'sk thread inbox'], ['his notes on trailer frames', 'sk thread inbox --subject frame'], ['the cards this session sent', 'sk thread inbox --mine'], ['as a Claude Code hook, on UserPromptSubmit and on Stop', 'sk thread inbox --hook']],
1022
+ examples: [['what waits on you', 'sk thread inbox'], ['his notes on trailer frames', 'sk thread inbox --subject frame'], ['the threads this session holds', 'sk thread inbox --mine'], ['as a Claude Code hook, on UserPromptSubmit and on Stop', 'sk thread inbox --hook']],
626
1023
  })
627
1024
  mine = Option.Boolean('--mine', false, { description: "only the threads this Claude Code session holds" })
628
1025
  session = Option.String('--session', { description: "only the threads that session holds" })
629
1026
  subject = Option.String('--subject', { description: 'only items of this subject kind (frame, shot…)' })
630
1027
  all = Option.Boolean('--all', false, { description: 'a plain approval too, not only the counted line' })
631
- hook = Option.Boolean('--hook', false, { description: 'run as a Claude Code hook (UserPromptSubmit, Stop): the hook input on stdin, its json answer on stdout. The unseen answers join a prompt as context, and a turn does not end while one is unseen' })
1028
+ hook = Option.Boolean('--hook', false, { description: 'run as a Claude Code hook (UserPromptSubmit, Stop, SubagentStop): the hook input on stdin, its json answer on stdout. A thread whose holder is gone passes on first (a lane that ended → its session); the unseen answers join a prompt as context, and a turn does not end while one is unseen, or while a thread of his turn has no watch to hear it' })
632
1029
 
633
1030
  async execute(): Promise<number> {
634
- const { hookAnswer, hookPasses, parseHookInput } = await import('../review/inbox-hook.ts')
1031
+ const { endedAgentOf, hookPasses, hookSession, parseHookInput } = await import('../review/inbox-hook.ts')
635
1032
  // the hook input is one small json on stdin; a terminal has none
636
1033
  const input = this.hook ? parseHookInput(process.stdin.isTTY === true ? '' : await new Response(Bun.stdin.stream()).text().catch(() => '')) : null
637
1034
  if (input != null && hookPasses(input)) return 0
638
- return run(this.context, async (hh) => {
639
- // as a hook, the lines of the inbox are the answer's text, never the output
640
- const unseenLines: string[] = []
641
- const h = input == null ? hh : { ...hh, out: (l: string) => void unseenLines.push(l) }
642
- const { liveWatchers } = await import('../review/watchers.ts')
643
- const { readAll } = await import('../review/store.ts')
644
- const { BUILTIN_KINDS, moveOf, stateOf, unreadBy, untakenOf, verdictOf } = await import('../review/model.ts')
645
- const { followedIds, threadOfItem, threadsOf, unseen } = await import('../review/threads.ts')
646
- const { detail, threadDetail, untakenLine } = await import('../review/format.ts')
1035
+ return run(this.context, async (h) => {
1036
+ const { BUILTIN_KINDS, untakenOf } = await import('../review/model.ts')
647
1037
  const kinds = [...Object.keys(h.say.spec.kinds), ...Object.keys(BUILTIN_KINDS)]
648
1038
  if (this.subject !== undefined && Object.keys(h.say.spec.kinds).length > 0 && !kinds.includes(this.subject)) throw new Error(`--subject: one of ${kinds.join(', ')}`)
649
- const session = await sessionOf(this.mine, this.session)
1039
+ const { selectInbox, selectedText, hookReply } = await import('../review/inbox-read.ts')
1040
+ const { followedIds, hears, listenersOf, sinceHeLeft, threadByItem, threadsOf } = await import('../review/threads.ts')
1041
+ const { untakenLine } = await import('../review/format.ts')
1042
+ const { liveWatchers } = await import('../review/watchers.ts')
650
1043
  await pull(h)
651
- const all = readAll(h.dir)
652
- for (const b of all.broken) h.err(`review: FAIL ${b.id}: ${b.error}`)
653
- const { hears, threadByItem } = await import('../review/threads.ts')
654
- const byItem = threadByItem(threadsOf(all.items, h.say.spec))
655
- const of = (x: (typeof all.items)[number]): boolean => hears({ session, lane: null }, x, byItem) && (this.subject === undefined || x.item.subject.kind === this.subject)
656
- const news = unseen(all.items).filter(of)
657
- const followed = followedIds(all.items)
658
- // what he or a player raised and nobody closed is the agents' move, read or not
659
- const open = all.items.filter((x) => of(x) && x.item.origin.by !== 'agent' && moveOf(stateOf(x, followed.has(x.item.id)).state) === 'agents' && !news.includes(x))
660
- // a plain approval (no comment, no rectangle, no reaction, no pick, no reply) asks for no work: counted on one
661
- // line unless --all
662
- const plain = (x: (typeof news)[number]): boolean => {
663
- const v = verdictOf(x)
664
- return v?.status === 'approved' && !v.seen && !v.comment && v.rects.length === 0 && !v.reactions && v.pick === undefined && unreadBy(x, 'agent').length === 0
665
- }
666
- // as a hook: a raised item a lane claimed is in that lane's hands until it closes it, so it never blocks a turn
667
- const inHand = (x: (typeof news)[number]): boolean => input != null && x.item.origin.by !== 'agent' && stateOf(x, followed.has(x.item.id)).state === 'claimed'
668
- const shown = [...(this.all ? news : news.filter((x) => !plain(x))), ...open].filter((x) => !inHand(x))
669
- if (shown.length === 0 && news.length === 0) h.out('review: no unseen feedback or reply')
670
- const threads = threadsOf(all.items)
671
- const printed = new Set<string>()
672
- for (const x of shown) {
673
- const t = threadOfItem(x.item.id, threads)
674
- if (t && printed.has(t.head.item.id)) continue
675
- if (t) printed.add(t.head.item.id)
676
- h.out(`${t ? threadDetail(t, h.dir, false, h.say) : detail(x, h.dir, false, false, h.say)}\n`)
1044
+ const here = await hereStore(h)
1045
+ for (const b of here.broken) h.err(`review: FAIL ${b.id}: ${b.error}`)
1046
+ if (input != null) {
1047
+ // as a hook: what this session hears, in its own repo and in every store it or its lanes wrote in
1048
+ const session = hookSession(input)
1049
+ const { noteHanded, noteSession } = await import('../agent-time/registry.ts')
1050
+ if (session !== null) noteSession(h.dir)
1051
+ let stores = [here, ...(session === null ? [] : await storesOf(session, h.dir))]
1052
+ // a SubagentStop fires at every turn a lane ends, one that waits on its background work too: the
1053
+ // registry reads which (agent-time/registry.ts readParties, stopped)
1054
+ const parties = await partiesFor(stores, session, endedAgentOf(input))
1055
+ // rule 2 as a write: a thread whose holder is gone passes on now (review/hand-over.ts)
1056
+ const { handOver, handedLines } = await import('../review/hand-over.ts')
1057
+ const handed = session === null ? [] : stores.flatMap((s) => handOver(s.dir, s.say.spec, parties, s.repo, { onHanded: noteHanded }))
1058
+ if (input.hook_event_name === 'SubagentStop') return 0
1059
+ if (handed.length > 0) stores = [await hereStore(h), ...(session === null ? [] : await storesOf(session, h.dir))]
1060
+ const me = { lane: null, session }
1061
+ // the session's own watch in a store, or its one house watch for all of them
1062
+ const { laneWatchesOf, watchedBy } = await import('../review/watchers.ts')
1063
+ const watchedIn = watchedBy(session, stores.map((s) => s.dir))
1064
+ const laneWatches = session === null ? [] : laneWatchesOf(session, stores.map((s) => s.dir))
1065
+ const answer = hookReply({ input, me, stores, parties, onHanded: noteHanded, handed: handedLines(handed.filter((x) => x.to === session)), watchedIn, laneWatches })
1066
+ if (answer != null) h.out(answer)
1067
+ return 0
677
1068
  }
678
- // a « fix » or a « no » an agent read and has not done: owed, never an unseen answer again
679
- const owed = threads.filter((t) => of(t.head) && !printed.has(t.head.item.id) && t.head.item.origin.by === 'agent' && verdictOf(t.head)?.seen === true && stateOf(t.head, false).state === 'claimed')
680
- const owedLine = (x: (typeof all.items)[number]): string => {
1069
+ const session = await sessionOf(this.mine, this.session)
1070
+ const lane = this.mine ? callerLane(undefined) : null
1071
+ const parties = session === null && lane === null ? null : await partiesFor([here], session)
1072
+ const since = sinceHeLeft(here.items)
1073
+ if (since && since.moved > 0) h.out(`since you left (${since.at}): ${since.moved} moved, ${since.yours} yours\n`)
1074
+ // his requests for a lane first: the orchestrator's (review/lane-ask.ts)
1075
+ const { laneAsksFor } = await import('../review/inbox-read.ts')
1076
+ for (const l of laneAsksFor(here, { session, lane }, parties ?? { sessions: [], lanes: [] })) h.out(`${l}\n`)
1077
+ // the owner's words that name another agent are that agent's (wiki tools/shipkit/threads-how-it-fits.md, Mentions)
1078
+ const { wordReaches } = await import('../review/threads.ts')
1079
+ const named = threadByItem(threadsOf(here.items, h.say.spec))
1080
+ const mine = { ...here, say: { ...here.say, to: (x: import('../review/model.ts').ReviewItem, m: import('../review/model.ts').Message) => wordReaches({ session, lane }, x, m, named, parties) } }
1081
+ const sel = selectInbox(mine, (x, byItem) => hears({ session, lane }, x, byItem, parties), { all: this.all, subject: this.subject })
1082
+ if (sel.threads.length === 0 && sel.news.length === 0) h.out('review: no unseen feedback or reply')
1083
+ for (const g of sel.threads) h.out(`${selectedText(mine, g)}\n`)
1084
+ const { ownAddressOf, verdictOf } = await import('../review/model.ts')
1085
+ const owedLine = (t: (typeof sel.owed)[number]): string => {
1086
+ const x = t.head
681
1087
  const fix = verdictOf(x)?.status === 'approved-with-fix'
682
- const close = fix ? `sk thread done ${x.item.id} "<what changed>"` : `--supersedes ${x.item.id} on its new version`
1088
+ const close = fix ? `sk thread fixed ${x.item.id} "<what changed>"` : `its next version, sk thread post ${ownAddressOf(x.item, h.say.spec) ?? x.item.id} …`
683
1089
  return ` ${x.item.id} ${fix ? 'ok with a fix' : 'rejected'} "${x.item.title}": ${close}, or sk thread wontfix ${x.item.id} --note "<why>"`
684
1090
  }
685
- if (input != null) {
686
- const approvals = news.filter(plain)
687
- if (approvals.length > 0) h.out(`${approvals.length} plain approval(s), nothing to do: sk thread seen ${approvals.map((x) => x.item.id).join(' ')}`)
688
- const said = unseenLines.filter((l) => l !== 'review: no unseen feedback or reply').join('\n').trim()
689
- const answer = hookAnswer(input, said, owed.map((t) => t.head.item.id))
690
- if (answer != null) hh.out(answer)
691
- return 0
692
- }
693
- if (owed.length > 0) h.out(`owed, read and not done:\n${owed.map((t) => owedLine(t.head)).join('\n')}\n`)
1091
+ if (sel.owed.length > 0) h.out(`owed, read and not done:\n${sel.owed.map(owedLine).join('\n')}\n`)
694
1092
  const watchers = liveWatchers(h.dir)
695
- const untaken = all.items.flatMap((x) => {
696
- const why = untakenOf(x, followed.has(x.item.id), watchers, new Date(), h.say.spec.dispatcher)
1093
+ const byItem = threadByItem(threadsOf(here.items, h.say.spec))
1094
+ const followed = followedIds(here.items)
1095
+ const untaken = here.items.flatMap((x) => {
1096
+ const why = untakenOf(x, followed.has(x.item.id), listenersOf(watchers, x, byItem).length > 0, new Date(), h.say.spec.dispatcher)
697
1097
  return why === null ? [] : [untakenLine(x, why, null)]
698
1098
  })
699
1099
  if (untaken.length > 0) h.out(`not taken:\n${untaken.join('\n')}\n`)
700
- const approvals = this.all ? [] : news.filter(plain)
701
- if (approvals.length > 0) h.out(`review: ${approvals.length} plain approval(s), nothing to do: sk thread seen ${approvals.map((x) => x.item.id).join(' ')}`)
702
- if (shown.length > 0) h.out('mark each handled: sk thread seen <id>; close a raised one: sk thread fixed <id> --note "<what was done>"')
703
- return all.broken.length > 0 ? 1 : 0
1100
+ if (sel.plain.length > 0) h.out(`review: ${sel.plain.length} plain approval(s), nothing to do: sk thread seen ${sel.plain.map((x) => x.item.id).join(' ')}`)
1101
+ if (sel.threads.length > 0) h.out('mark each handled: sk thread seen <id>; close a raised one: sk thread fixed <id> --note "<what was done>"')
1102
+ return here.broken.length > 0 ? 1 : 0
704
1103
  })
705
1104
  }
706
1105
  }
707
1106
 
708
- /** the lane that acts on a reply or a seen: --as, else SK_AGENT, else none */
709
- const laneOfCaller = (as: string | undefined): string | null => as?.trim() || process.env.SK_AGENT?.trim() || null
1107
+ /** the store the verb stands in, read for the inbox */
1108
+ async function hereStore(h: Here): Promise<import('../review/inbox-read.ts').StoreRead> {
1109
+ const { readAll } = await import('../review/store.ts')
1110
+ const { repoNameOf } = await import('../agent-time/registry.ts')
1111
+ const { dirname } = await import('node:path')
1112
+ const root = dirname(dirname(h.dir))
1113
+ return { repo: repoNameOf(root), root, dir: h.dir, here: true, ...readAll(h.dir), say: h.say }
1114
+ }
1115
+
1116
+ /** every other store this session or its lanes wrote in (agent-time/registry.ts), each with its repo's unit bound */
1117
+ async function storesOf(session: string, hereDir: string): Promise<import('../review/inbox-read.ts').StoreRead[]> {
1118
+ const { repoNameOf } = await import('../agent-time/registry.ts')
1119
+ const { readAll } = await import('../review/store.ts')
1120
+ const { dirname, resolve } = await import('node:path')
1121
+ const out: import('../review/inbox-read.ts').StoreRead[] = []
1122
+ for (const dir of await recordedStores(session, (d) => resolve(d) === resolve(hereDir))) {
1123
+ const root = dirname(dirname(dir))
1124
+ try {
1125
+ const { say } = await hereAt(dir, () => {}, () => {})
1126
+ out.push({ repo: repoNameOf(root), root, dir, here: false, ...readAll(dir), say })
1127
+ } catch {
1128
+ // a store that does not read now: its own repo's hook and inbox say why
1129
+ }
1130
+ }
1131
+ return out
1132
+ }
1133
+
1134
+ /** the stores the session's record names, but those `skip` keeps out; only a store its commands run in (`sk thread
1135
+ * seen` there refuses a folder that is no shipkit repo), the others leave its record */
1136
+ async function recordedStores(session: string, skip: (dir: string) => boolean): Promise<string[]> {
1137
+ const { forgetStores, readSessionRecord, scratchStore } = await import('../agent-time/registry.ts')
1138
+ const { existsSync } = await import('node:fs')
1139
+ const { dirname } = await import('node:path')
1140
+ const dirs: string[] = []
1141
+ const gone: string[] = []
1142
+ for (const d of (readSessionRecord(session)?.stores ?? []).filter((x) => !skip(x))) (!scratchStore(d) && existsSync(d) && (await reviewRoot(dirname(dirname(d)))) !== null ? dirs : gone).push(d)
1143
+ forgetStores(session, gone)
1144
+ return dirs
1145
+ }
1146
+
1147
+ /** the store at `dir` of another repo as a verb works on it, its repo's unit bound */
1148
+ async function hereAt(dir: string, out: (l: string) => void, err: (l: string) => void): Promise<Here> {
1149
+ const { openReview, factLines } = await import('../review/project.ts')
1150
+ const { specOf } = await import('../review/store.ts')
1151
+ const { dirname } = await import('node:path')
1152
+ const { unit } = await openReview(dirname(dirname(dir)))
1153
+ return { dir, unit, say: { spec: specOf(dir), more: (x) => factLines(unit, x) }, out, err }
1154
+ }
1155
+
1156
+ /** the parties these stores' threads name: their holders' sessions and the caller's, with each store's live watches */
1157
+ async function partiesFor(stores: readonly import('../review/inbox-read.ts').StoreRead[], self: string | null, stopped: string | null = null): Promise<import('../review/parties.ts').Parties> {
1158
+ const { readParties } = await import('../agent-time/registry.ts')
1159
+ const { holderOf, threadsOf } = await import('../review/threads.ts')
1160
+ const { liveWatchers } = await import('../review/watchers.ts')
1161
+ const ids = new Set<string>()
1162
+ for (const s of stores) for (const t of threadsOf(s.items, s.say.spec)) {
1163
+ const hs = holderOf(t)?.session
1164
+ if (hs) ids.add(hs)
1165
+ }
1166
+ return readParties({ sessions: [...ids], watchers: stores.flatMap((s) => liveWatchers(s.dir)), self, stopped })
1167
+ }
1168
+
1169
+ /** the lane that acts on a reply or a seen, by this process's SK_AGENT (review/parties.ts laneOfCaller) */
1170
+ const callerLane = (as: string | undefined): string | null => laneOfCaller(as, process.env.SK_AGENT)
1171
+
1172
+ /** why the caller may not mark his answer on this item seen (review/threads.ts seenRefusal, rule 4: the holder or its
1173
+ * session), null when it may */
1174
+ async function seenRefused(dir: string, id: string, as: string | undefined): Promise<{ refused: string | null; only?: string[] }> {
1175
+ const { readAll } = await import('../review/store.ts')
1176
+ const { seenOnly, seenRefusal, threadOfItem, threadsOf } = await import('../review/threads.ts')
1177
+ const items = readAll(dir).items
1178
+ const x = items.find((y) => y.item.id === id)
1179
+ if (x === undefined) return { refused: null }
1180
+ const t = threadOfItem(id, threadsOf(items))
1181
+ const { me, parties } = await callerParties(dir, t, as)
1182
+ // a lane the owner's words name reads those words only, on a thread another agent holds
1183
+ const { repoNameOf } = await import('../agent-time/registry.ts')
1184
+ const { dirname } = await import('node:path')
1185
+ const only = seenOnly(x, t, me, parties, repoNameOf(dirname(dirname(dir))))
1186
+ return { refused: seenRefusal(x, t, me, parties), ...(only !== undefined ? { only } : {}) }
1187
+ }
710
1188
 
711
- /** why the caller may not reply to or mark seen this card (review/model.ts notAnswererOf), null when it may */
712
- async function answererRefusal(dir: string, id: string, as: string | undefined, op: 'reply' | 'seen'): Promise<string | null> {
713
- const { readItem, sessionId } = await import('../review/store.ts')
714
- const { notAnswererOf } = await import('../review/model.ts')
1189
+ /** the caller and the parties its thread's holder names */
1190
+ async function callerParties(dir: string, t: import('../review/threads.ts').Thread | null, as: string | undefined): Promise<{ me: import('../review/parties.ts').Me; parties: import('../review/parties.ts').Parties }> {
1191
+ const { sessionId } = await import('../review/store.ts')
1192
+ const { holderOf } = await import('../review/threads.ts')
1193
+ const { readParties } = await import('../agent-time/registry.ts')
715
1194
  const { liveWatchers } = await import('../review/watchers.ts')
716
- const x = readItem(dir, id)
717
- return x === null ? null : notAnswererOf(x, { lane: laneOfCaller(as), session: sessionId() }, op, op === 'seen' ? liveWatchers(dir) : undefined)
1195
+ const me = { lane: callerLane(as), session: sessionId() }
1196
+ const hs = t ? holderOf(t)?.session : undefined
1197
+ return { me, parties: await readParties({ sessions: hs ? [hs] : [], watchers: liveWatchers(dir), self: me.session }) }
1198
+ }
1199
+
1200
+ /** the caller holds the item's thread (review/parties.ts holdsThread): it may close what that thread's lane claimed */
1201
+ async function callerHolds(dir: string, id: string, as: string | undefined): Promise<boolean> {
1202
+ const { readAll } = await import('../review/store.ts')
1203
+ const { holderOf, threadOfItem, threadsOf } = await import('../review/threads.ts')
1204
+ const t = threadOfItem(id, threadsOf(readAll(dir).items))
1205
+ if (t === null || holderOf(t) === null) return false
1206
+ const { me, parties } = await callerParties(dir, t, as)
1207
+ return holdsThread(me, holderOf(t), parties)
1208
+ }
1209
+
1210
+ /** `--replaces <object>`: the thread item `id` is in, and the message id the new object supersedes, once the caller may
1211
+ * (review/supersede.ts replaceRefusal: the holder or its session, an agent's object not superseded yet); thrown
1212
+ * before anything is written. A cell id the hub copies (`<item>/<message>`) names its message */
1213
+ async function replacing(dir: string, ref: string, target: string, as: string | undefined): Promise<{ id: string; replaces: string }> {
1214
+ const id = await idOf(dir, ref)
1215
+ const { readAll } = await import('../review/store.ts')
1216
+ const { membersOf, threadOfItem, threadsOf } = await import('../review/threads.ts')
1217
+ const { replaceRefusal } = await import('../review/supersede.ts')
1218
+ const t = threadOfItem(id, threadsOf(readAll(dir).items))
1219
+ if (t === null) throw new Error(`--replaces ${target}: ${id} reads in no thread`)
1220
+ const replaces = target.includes('/') ? target.slice(target.lastIndexOf('/') + 1) : target
1221
+ const no = replaceRefusal(membersOf(t), replaces, { holds: await mayHold(dir, t, as) })
1222
+ if (no !== null) throw new Error(no)
1223
+ return { id, replaces }
1224
+ }
1225
+
1226
+ /** the caller may act as the thread's holder (review/parties.ts maySee): it holds it, or nobody does */
1227
+ async function mayHold(dir: string, t: import('../review/threads.ts').Thread, as: string | undefined): Promise<boolean> {
1228
+ const { holderOf } = await import('../review/threads.ts')
1229
+ const { me, parties } = await callerParties(dir, t, as)
1230
+ return maySee(me, holderOf(t), parties)
1231
+ }
1232
+
1233
+ /** mayHold for the thread item `id` is in, false when it reads in none */
1234
+ export async function mayHoldItem(dir: string, id: string, as?: string): Promise<boolean> {
1235
+ const { readAll } = await import('../review/store.ts')
1236
+ const { threadOfItem, threadsOf } = await import('../review/threads.ts')
1237
+ const t = threadOfItem(id, threadsOf(readAll(dir).items))
1238
+ return t !== null && mayHold(dir, t, as)
718
1239
  }
719
1240
 
720
1241
  export class ReviewSeenCommand extends Command {
721
1242
  static override paths = [['review', 'seen']]
722
- static essential = { args: '<ids>' }
723
- static override usage = Command.Usage({ category: 'Review', description: 'mark his answers and replies on these items read, once you acted on them', details: DETAILS })
724
- ids = Option.Rest({ required: 1 })
1243
+ static essential = { args: '<address | ids>' }
1244
+ static override usage = Command.Usage({ category: 'Review', description: 'mark his new words read as you read them: by id, or a whole thread by its address', details: DETAILS })
1245
+ ids = Option.Rest({ required: 1, name: 'address | id' })
725
1246
  as = Option.String('--as', { description: 'the lane that read it (else SK_AGENT)' })
726
1247
 
727
1248
  async execute(): Promise<number> {
728
1249
  return run(this.context, async (h) => {
729
1250
  const { markSeen } = await import('../review/store.ts')
730
- // every id checked before any is marked: his answer on another lane's card stays unread for that lane
1251
+ // every id checked before any is marked: his answer on another lane's version stays unread for that lane
731
1252
  const ids: [string, string][] = []
732
- for (const ref of this.ids) ids.push([ref, await idOf(h.dir, ref).catch(() => ref)])
733
- const refused = (await Promise.all(ids.map(([, id]) => answererRefusal(h.dir, id, this.as, 'seen')))).filter((w) => w !== null)
1253
+ const { ID_RE } = await import('../review/model.ts')
1254
+ for (const ref of this.ids) {
1255
+ // an address: every item of its thread with an answer not marked seen
1256
+ if (!ID_RE.test(ref) && ref.includes(':')) {
1257
+ const { readAll } = await import('../review/store.ts')
1258
+ const { membersOf, threadOfItem, threadsOf, unseen } = await import('../review/threads.ts')
1259
+ const items = readAll(h.dir).items
1260
+ const t = threadOfItem(await idOf(h.dir, ref), threadsOf(items, h.say.spec))
1261
+ const members = new Set(t ? membersOf(t).map((x) => x.item.id) : [])
1262
+ const open = unseen(items).filter((x) => members.has(x.item.id))
1263
+ if (open.length === 0) h.out(`${ref}: nothing of his unseen`)
1264
+ for (const x of open) ids.push([x.item.id, x.item.id])
1265
+ continue
1266
+ }
1267
+ ids.push([ref, await idOf(h.dir, ref).catch(() => ref)])
1268
+ }
1269
+ const scopes = await Promise.all(ids.map(([, id]) => seenRefused(h.dir, id, this.as)))
1270
+ const refused = scopes.map((s) => s.refused).filter((w) => w !== null)
734
1271
  if (refused.length > 0) throw new Error(`nothing marked: ${refused.join('; ')}`)
735
1272
  let bad = 0
736
- for (const [ref, id] of ids) {
737
- if (markSeen(h.dir, id)) h.out(`${ref}: seen`)
1273
+ for (const [i, [ref, id]] of ids.entries()) {
1274
+ if (markSeen(h.dir, id, new Date(), scopes[i]!.only)) h.out(`${ref}: seen`)
738
1275
  else {
739
1276
  h.err(`FAIL: review: ${ref}: no such item, or nothing of his to read on it`)
740
1277
  bad++
@@ -745,22 +1282,145 @@ export class ReviewSeenCommand extends Command {
745
1282
  }
746
1283
  }
747
1284
 
1285
+ /** the longest « what I do now » line: a glance in his thread, never a report */
1286
+ const WORKING_MAX = 200
1287
+
1288
+ export class ThreadWorkingCommand extends Command {
1289
+ static override paths = [['thread', 'working']]
1290
+ static essential = { args: '<address | id> "<what I do now>"' }
1291
+ static override usage = Command.Usage({
1292
+ category: 'Review',
1293
+ description: 'say you are on his new words in a thread, one line of what you do now; your next act there ends it',
1294
+ details: `${DETAILS}\n\nMark his new words seen as you read them (sk thread seen), then, for work longer than your next call, say what you do with them here: he sees « L29 is on it: <line> » in the thread, its head and its row. It ends with the next act in the thread, yours or another agent's (a version, an update, a reply, a question, a change, a close, a take, a newer working), or once nothing moved for 2 h. A read with no act after it keeps his word owed: a turn's end holds on it. Never written for you: no watch, beat or hook says it (wiki tools/shipkit/threads-how-it-fits.md, Read and on it).`,
1295
+ examples: [['on it', 'SK_AGENT=L29 sk thread working page:backup "backing up the key in OpenBao"']],
1296
+ })
1297
+ ref = Option.String({ name: 'address | id' })
1298
+ line = Option.String()
1299
+ as = Option.String('--as', { description: 'the lane on it (else SK_AGENT)' })
1300
+
1301
+ async execute(): Promise<number> {
1302
+ return run(this.context, async (h) => {
1303
+ const line = this.line.trim()
1304
+ if (line === '') throw new Error('say what you do now: sk thread working <address> "<line>"')
1305
+ if (line.length > WORKING_MAX) throw new Error(`one short line: at most ${WORKING_MAX} characters, ${line.length} given`)
1306
+ const { appendMessage, readAll } = await import('../review/store.ts')
1307
+ const { threadOfItem, threadsOf } = await import('../review/threads.ts')
1308
+ const id = await idOf(h.dir, this.ref)
1309
+ const t = threadOfItem(id, threadsOf(readAll(h.dir).items, h.say.spec))
1310
+ const who = callerLane(this.as) ?? 'agent'
1311
+ appendMessage(h.dir, t?.head.item.id ?? id, { who, op: 'working', note: line })
1312
+ h.out(`${this.ref}: ${who} is on it: ${line} (your next act in this thread ends it)`)
1313
+ return 0
1314
+ })
1315
+ }
1316
+ }
1317
+
1318
+ export class ThreadTakeCommand extends Command {
1319
+ static override paths = [['thread', 'take']]
1320
+ static essential = { args: '<address | id>' }
1321
+ static override usage = Command.Usage({
1322
+ category: 'Review',
1323
+ description: 'hold a thread from now on: his answers on it reach you, and you mark them seen',
1324
+ details: `${DETAILS}\n\nWho holds a thread is the agent of its newest act in it; a take is that act with no words, its state left as it is. A thread whose agent ended, or one nobody hears (the inbox hook lists those at a session's prompt), becomes yours. Writing in a thread (reply, update, post) takes it too. A session takes its own ended lane's thread only to keep it when it cannot resume that lane: a resumed lane takes back what it held, and a session marks its lane's thread seen with no take (wiki tools/shipkit/threads-how-it-fits.md, The parties).`,
1325
+ examples: [['a thread its ended session left', 'sk thread take asset:start'], ['as a lane', 'SK_AGENT=L4 sk thread take screen:orders/list']],
1326
+ })
1327
+ ref = Option.String({ name: 'address | id' })
1328
+ as = Option.String('--as', { description: 'the lane that takes it (else SK_AGENT)' })
1329
+
1330
+ async execute(): Promise<number> {
1331
+ return run(this.context, async (h) => {
1332
+ const { appendMessage, readAll } = await import('../review/store.ts')
1333
+ const { holderOf, hearingOfThread, threadOfItem, threadsOf } = await import('../review/threads.ts')
1334
+ const { sessionLabel } = await import('../review/parties.ts')
1335
+ const id = await idOf(h.dir, this.ref)
1336
+ const before = threadOfItem(id, threadsOf(readAll(h.dir).items, h.say.spec))
1337
+ const head = before?.head.item.id ?? id
1338
+ const was = before ? holderOf(before) : null
1339
+ const { dropHanded, readParties, repoNameOf } = await import('../agent-time/registry.ts')
1340
+ const { liveWatchers } = await import('../review/watchers.ts')
1341
+ const { sessionId } = await import('../review/store.ts')
1342
+ const lane = callerLane(this.as)
1343
+ appendMessage(h.dir, head, { who: lane ?? 'agent', op: 'take' })
1344
+ // taken here: the ended lane, resumed later, leaves it to its taker
1345
+ const self = sessionId()
1346
+ if (self) dropHanded(self, h.dir, head, lane)
1347
+ const after = threadOfItem(head, threadsOf(readAll(h.dir).items, h.say.spec))
1348
+ const now = after ? holderOf(after) : null
1349
+ // a house watch of the caller hears this store too, within 2 s of the take
1350
+ const { houseWatchesOf } = await import('../review/watchers.ts')
1351
+ const { readSessionRecord } = await import('../agent-time/registry.ts')
1352
+ const house = self ? houseWatchesOf(self, readSessionRecord(self)?.stores ?? []) : []
1353
+ const parties = await readParties({ sessions: [...new Set([was?.session, now?.session].filter((x): x is string => !!x))], watchers: [...liveWatchers(h.dir), ...house], self })
1354
+ const { dirname } = await import('node:path')
1355
+ const hearing = after ? hearingOfThread(after, parties, repoNameOf(dirname(dirname(h.dir)))) : null
1356
+ const wasText = was === null ? 'nobody held it' : `it was held by ${was.lane ?? sessionLabel(was.session, parties)}`
1357
+ h.out(`${this.ref}: yours now (${hearing?.chip ?? lane ?? 'this session'}), ${wasText}; ${hearing?.words ?? ''}`)
1358
+ if (hearing && hearing.light !== 'hears') h.err(`review: no watch of yours hears it now: sk thread watch --mine --house under a monitor, one watch for every repo where you hold threads`)
1359
+ return 0
1360
+ })
1361
+ }
1362
+ }
1363
+
1364
+ export class ThreadAssignCommand extends Command {
1365
+ static override paths = [['thread', 'assign']]
1366
+ static override usage = Command.Usage({
1367
+ category: 'Review',
1368
+ description: 'give a thread to a lane: it holds it, a trace line names who gave it',
1369
+ details: `${DETAILS}\n\nThe orchestrator's answer to the owner's « start a lane »: on a thread nobody holds, sk thread take it first; then SendMessage to a live lane, or start a sub-agent with the thread as its brief (nothing starts a process for you); then assign the thread to that lane. The lane holds it (a take under its name, the state left as it is), and its trace line reads « L65 took the thread: assigned by app main ». The request clears at the lane's first act there: tell it to say \`sk thread working <address> "…"\` first (wiki tools/shipkit/threads-how-it-fits.md, A lane he asks for).`,
1370
+ examples: [['a lane for the thread he asked one on', 'sk thread assign screen:orders/list L65']],
1371
+ })
1372
+ ref = Option.String({ name: 'address | id' })
1373
+ lane = Option.String()
1374
+
1375
+ async execute(): Promise<number> {
1376
+ return run(this.context, async (h) => {
1377
+ const { AGENT_RE } = await import('../review/model.ts')
1378
+ const lane = this.lane.trim()
1379
+ if (!AGENT_RE.test(lane) || lane === 'agent' || lane === 'owner' || lane === 'player') throw new Error(`« ${lane} » is no lane name: sk thread assign <address> L<n>`)
1380
+ const { appendMessage, readAll, sessionId } = await import('../review/store.ts')
1381
+ const { threadOfItem, threadsOf } = await import('../review/threads.ts')
1382
+ const { sessionLabel } = await import('../review/parties.ts')
1383
+ const { dropHanded, readParties } = await import('../agent-time/registry.ts')
1384
+ const id = await idOf(h.dir, this.ref)
1385
+ const head = threadOfItem(id, threadsOf(readAll(h.dir).items, h.say.spec))?.head.item.id ?? id
1386
+ const self = sessionId()
1387
+ const by = callerLane(undefined) ?? (self ? sessionLabel(self, await readParties({ sessions: [], self })) : 'a terminal')
1388
+ appendMessage(h.dir, head, { who: lane, op: 'take', note: `assigned by ${by}` })
1389
+ if (self) dropHanded(self, h.dir, head, lane)
1390
+ h.out(`${this.ref}: given to ${lane} (assigned by ${by}): its first act there (sk thread working ${this.ref} "…") clears his request`)
1391
+ return 0
1392
+ })
1393
+ }
1394
+ }
1395
+
748
1396
  export class ReviewReplyCommand extends Command {
749
1397
  static override paths = [['review', 'reply']]
750
- static essential = { args: '<id> <text>' }
1398
+ static essential = { args: '<address | id> <text>' }
751
1399
  static override usage = Command.Usage({ category: 'Review', description: "your message in a thread: what you changed, the answer to his question", details: DETAILS })
752
- id = Option.String()
1400
+ id = Option.String({ name: 'address | id' })
753
1401
  text = Option.String()
754
1402
  image = Option.String('--image', { description: 'an image beside the words' })
755
1403
  as = Option.String('--as', { description: 'the lane that answers (else SK_AGENT)' })
1404
+ urgent = Option.Boolean('--urgent', false, { description: 'brings back a thread he set aside, at once: only under the bar of a ping (an incident, a hard block, a deadline before it comes back)' })
1405
+ replaces = Option.String('--replaces', { description: 'the id of your earlier words (or question, or change) these supersede: it folds to one line « superseded by … » and leaves the dock, its answers kept' })
1406
+ verdict = Option.Boolean('--verdict', false, { description: VERDICT_FLAG })
756
1407
 
757
1408
  async execute(): Promise<number> {
758
1409
  return run(this.context, async (h) => {
759
- const { addMessage, agentName } = await import('../review/store.ts')
760
- const id = await idOf(h.dir, this.id)
761
- const refused = await answererRefusal(h.dir, id, this.as, 'reply')
762
- if (refused !== null) throw new Error(refused)
763
- const m = addMessage(h.dir, id, laneOfCaller(this.as) ?? agentName(), this.text, this.image)
1410
+ const { agentName, appendMessage } = await import('../review/store.ts')
1411
+ if (this.replaces !== undefined) {
1412
+ if (this.image !== undefined) throw new Error('--replaces with --image: post the image as its own reply')
1413
+ const { textOf } = await import('../review/model.ts')
1414
+ const r = await replacing(h.dir, this.id, this.replaces, this.as)
1415
+ const t = textOf(this.text)
1416
+ if ('error' in t) throw new Error(t.error)
1417
+ const m = appendMessage(h.dir, r.id, { who: callerLane(this.as) ?? agentName(), text: t.text, replaces: r.replaces, ...(this.verdict ? { asksVerdict: true as const } : {}) })
1418
+ h.out(`${r.id}: ${m.id} supersedes ${r.replaces}`)
1419
+ return 0
1420
+ }
1421
+ const id = await idOrOpen(h, this.id, this.text, this.as)
1422
+ const m = await wordsIn(h.dir, id, callerLane(this.as) ?? agentName(), this.text, this.verdict, this.image)
1423
+ if (this.urgent) await urgentOn(h.dir, id, callerLane(this.as) ?? agentName())
764
1424
  h.out(`${id}: ${m.id}`)
765
1425
  return 0
766
1426
  })
@@ -769,11 +1429,11 @@ export class ReviewReplyCommand extends Command {
769
1429
 
770
1430
  export class ReviewUpdateCommand extends Command {
771
1431
  static override paths = [['review', 'update']]
772
- static essential = { args: '<id> <state> <text>' }
1432
+ static essential = { args: '<address | id> [state] <text>' }
773
1433
  static override usage = Command.Usage({
774
1434
  category: 'Review',
775
- description: "where a thread's work stands, no answer needed: broken, better or fixed, a line, a file or a pair",
776
- details: `${DETAILS}\n\nsk thread update <id> <broken|better|fixed> "<one line>" [<file> | <before> <after>]: the file (an image, a clip or a sound, as it is: no special file) becomes the card's next view, the line and the state go on its thread in time order. Two files make that view a before and after pair, as add --before --after does: two images of one size, two clips of one size and length, or two sounds, never one of each; the owner picks how he compares them (side by side, wipe, fade). broken or better holds the card « in progress » (not waiting on the owner's verdict, still new in the list), fixed asks the owner's verdict again on the same thread, even after an answer. The owner's hint on an update reaches watch and inbox as a reply « on update <k> ». Posted on the thread's newest version.`,
1435
+ description: "where a thread's work stands, no answer needed: broken, better, fixed or a plain line; a file",
1436
+ details: `${DETAILS}\n\nsk thread update <id> <broken|better|fixed> "<one line>" [<file> | <before> <after>]: the file (an image, a clip or a sound, as it is: no special file) becomes the version's next view, the line and the state go on its thread in time order. Two files make that view a before and after pair, as add --before --after does: two images of one size, two clips of one size and length, or two sounds, never one of each; the owner picks how he compares them (side by side, wipe, fade). broken or better holds the version « in progress » (not waiting on the owner's verdict, still new in the list), fixed asks the owner's verdict again on the same thread, even after an answer. The owner's hint on an update reaches watch and inbox as a reply « on update <k> ». Posted on the thread's newest version.`,
777
1437
  examples: [
778
1438
  ['still broken, the take as it is', 'SK_AGENT=L2 sk thread update <id> broken "her arm still crosses her leg at 2 s" take.mp4'],
779
1439
  ['better, not done', 'SK_AGENT=L2 sk thread update <id> better "the crossing is gone, the landing still snaps" take.mp4'],
@@ -781,29 +1441,46 @@ export class ReviewUpdateCommand extends Command {
781
1441
  ['better, as a before and after he compares his way', 'SK_AGENT=L2 sk thread update <id> better "the snap is half as deep" before.mp4 after.mp4'],
782
1442
  ],
783
1443
  })
784
- id = Option.String()
1444
+ id = Option.String({ name: 'address | id' })
785
1445
  state = Option.String()
786
- text = Option.String()
787
- files = Option.Rest()
1446
+ // the line and the files are one rest: clipanion never fills an optional positional that a rest follows
1447
+ rest = Option.Rest()
1448
+ get text(): string | undefined {
1449
+ return this.rest[0]
1450
+ }
1451
+ get files(): string[] {
1452
+ return this.rest.slice(1)
1453
+ }
788
1454
  as = Option.String('--as', { description: 'the lane that posts (else SK_AGENT)' })
789
- keep = Option.Boolean('--keep', false, { description: 'its pictures as given: a png lands as a lossless webp otherwise, its pixels checked exact, and the card keeps only the webp' })
1455
+ keep = Option.Boolean('--keep', false, { description: 'its pictures as given: a png lands as a lossless webp otherwise, its pixels checked exact, and the version keeps only the webp' })
1456
+ verdict = Option.Boolean('--verdict', false, { description: `on a plain line only: ${VERDICT_FLAG}` })
790
1457
 
791
1458
  async execute(): Promise<number> {
792
1459
  return run(this.context, async (h) => {
793
1460
  const { postUpdate, agentName, readAll } = await import('../review/store.ts')
794
1461
  const { threadsOf } = await import('../review/threads.ts')
795
1462
  const { threadOfId } = await import('../review/cells.ts')
796
- const asked = await idOf(h.dir, this.id)
1463
+ const { UPDATE_STATES } = await import('../review/model.ts')
1464
+ // fixed asks the version's verdict again, broken and better hold it in work: a verdict of their own would be two answers on one cell
1465
+ if (this.verdict && this.text !== undefined) throw new Error(`update ${this.state} --verdict: ${this.state === 'fixed' ? "fixed already asks the owner's verdict on the version" : `${this.state} holds the version in work, its hint box is the owner's answer`}; --verdict goes on a plain line`)
1466
+ // no state: a plain progress line, a reply on the newest version
1467
+ if (this.text === undefined) {
1468
+ if ((UPDATE_STATES as readonly string[]).includes(this.state)) throw new Error(`update <address | id> ${this.state} "<one line>": the line is missing`)
1469
+ const at = await idOrOpen(h, this.id, this.state, this.as)
1470
+ const on = threadOfId(at, threadsOf(readAll(h.dir).items))?.head.item.id ?? at
1471
+ const m = await wordsIn(h.dir, on, callerLane(this.as) ?? agentName(), this.state, this.verdict)
1472
+ h.out(`${on}: ${m.id}, a line, no state`)
1473
+ return 0
1474
+ }
1475
+ const asked = await idOrOpen(h, this.id, this.text, this.as)
797
1476
  // an update goes where he reads: the thread's newest version
798
1477
  const id = threadOfId(asked, threadsOf(readAll(h.dir).items))?.head.item.id ?? asked
799
- const refused = await answererRefusal(h.dir, id, this.as, 'reply')
800
- if (refused !== null) throw new Error(refused)
801
- const r = await postUpdate(h.dir, id, { who: laneOfCaller(this.as) ?? agentName(), state: this.state, text: this.text, files: this.files, ...(this.keep ? { keep: true } : {}) })
1478
+ const r = await postUpdate(h.dir, id, { who: callerLane(this.as) ?? agentName(), state: this.state, text: this.text, files: this.files, ...(this.keep ? { keep: true } : {}) })
802
1479
  const { viewNo, stateOf } = await import('../review/model.ts')
803
1480
  const { readItem } = await import('../review/store.ts')
804
1481
  const x = readItem(h.dir, id)
805
1482
  const now = x && stateOf(x, false).state === 'asks' ? "waits for the owner's verdict" : x && stateOf(x, false).state === 'draft' ? 'in progress, no verdict asked' : 'in work'
806
- h.out(`${id}: ${r.tag}${r.view !== null ? `, view ${viewNo(r.view)}` : ''}${id !== asked ? ` (on the newest version, ${asked} is older)` : ''}; the card ${now}`)
1483
+ h.out(`${id}: ${r.tag}${r.view !== null ? `, view ${viewNo(r.view)}` : ''}${id !== asked ? ` (on the newest version, ${asked} is older)` : ''}; the version ${now}`)
807
1484
  if (r.view !== null) for (const line of await (await import('../review/previews.ts')).playCopies(h.dir, r.item, r.view)) h.err(line)
808
1485
  const { unheardLine } = await import('../review/model.ts')
809
1486
  const { liveWatchers } = await import('../review/watchers.ts')
@@ -816,18 +1493,37 @@ export class ReviewUpdateCommand extends Command {
816
1493
 
817
1494
  export class ReviewWithdrawCommand extends Command {
818
1495
  static override paths = [['review', 'withdraw']]
819
- static override usage = Command.Usage({ category: 'Review', description: 'take an unanswered version back, with the reason', details: DETAILS })
1496
+ static override usage = Command.Usage({
1497
+ category: 'Review',
1498
+ description: 'take back what an agent posted, with the reason: a version by its id, or one message by its id',
1499
+ details: `${DETAILS}\n\nA version (or any other item of a thread) withdrawn asks nothing more: its open questions, changes and words asking the owner's verdict wait on nobody with it. A message id (sk thread show prints them) takes back that one question, change or words alone, a reply posted by mistake included. A thread (its address, or its own id t-…) is refused with the ids of its items: name the one you mean. What the owner wrote or raised is never withdrawn by an agent. --chat "<the owner's words>": the owner answered it in chat; the words are the reason, quoted, so it never stays open in the hub.`,
1500
+ examples: [
1501
+ ['a version taken back', 'sk thread withdraw 20261120-101500-the-logo --why "a newer one follows"'],
1502
+ ['he answered the question in chat', 'sk thread withdraw 20261120-223154-747-agent-vg49 --chat "B only, keep both kill matrices"'],
1503
+ ],
1504
+ })
820
1505
  ids = Option.Rest({ required: 1 })
821
- why = Option.String('--why,--note', { required: true, description: 'why it goes (--note says the same, as on fixed, wontfix, blocked and drop)' })
1506
+ why = Option.String('--why,--note', { required: false, description: 'why it goes (--note says the same, as on fixed, wontfix, blocked and drop)' })
1507
+ chat = Option.String('--chat', { required: false, description: 'the owner answered it in chat: the words become the reason, quoted' })
822
1508
 
823
1509
  async execute(): Promise<number> {
824
1510
  return run(this.context, async (h) => {
825
- const { withdraw } = await import('../review/store.ts')
826
- const ids = await Promise.all(this.ids.map((ref) => idOf(h.dir, ref)))
827
- for (const id of ids) {
828
- const r = withdraw(h.dir, id, this.why)
1511
+ const { answeredInChat, withdraw, withdrawObject } = await import('../review/store.ts')
1512
+ const { MESSAGE_RE } = await import('../review/model.ts')
1513
+ const why = this.chat?.trim() ? answeredInChat(this.chat) : this.why?.trim()
1514
+ if (!why) throw new Error('--why "<why it goes>", or --chat "<the owner\'s words>" when the owner answered it in chat')
1515
+ for (const ref of this.ids) {
1516
+ const msg = ref.includes('/') ? ref.slice(ref.indexOf('/') + 1) : ref
1517
+ if (MESSAGE_RE.test(msg)) {
1518
+ const r = withdrawObject(h.dir, msg, why)
1519
+ if ('refused' in r) throw new Error(r.refused)
1520
+ h.out(`${msg}: withdrawn (${why}); it waits on nobody now`)
1521
+ continue
1522
+ }
1523
+ const id = await idOf(h.dir, ref, { verb: 'withdraw', objects: true })
1524
+ const r = withdraw(h.dir, id, why)
829
1525
  if ('refused' in r) throw new Error(r.refused)
830
- h.out(r.already ? `${id}: withdrawn already (${r.already}), nothing to do` : `${id}: withdrawn`)
1526
+ h.out(r.already ? `${id}: withdrawn already (${r.already}), nothing to do` : `${id}: withdrawn, its open questions and changes with it`)
831
1527
  }
832
1528
  return 0
833
1529
  })
@@ -842,12 +1538,12 @@ export class ReviewReopenCommand extends Command {
842
1538
  async execute(): Promise<number> {
843
1539
  return run(this.context, async (h) => {
844
1540
  const { reopen } = await import('../review/store.ts')
845
- const { followAnswer } = await import('../releases/from-card.ts')
1541
+ const { followAnswer } = await import('../releases/from-thread.ts')
846
1542
  const { dirname } = await import('node:path')
847
1543
  for (const ref of this.ids) {
848
- const id = await idOf(h.dir, ref)
1544
+ const id = await idOf(h.dir, ref, { verb: 'reopen' })
849
1545
  const v = reopen(h.dir, id)
850
- if (!v) throw new Error(`${id}: no such card, or no answer to reopen`)
1546
+ if (!v) throw new Error(`${id}: no such version, or no answer to reopen`)
851
1547
  await followAnswer(dirname(dirname(h.dir)), id, v.status)
852
1548
  }
853
1549
  h.out(`review: ${this.ids.length} reopened`)
@@ -858,10 +1554,12 @@ export class ReviewReopenCommand extends Command {
858
1554
 
859
1555
  export class ReviewPickCommand extends Command {
860
1556
  static override paths = [['review', 'pick']]
1557
+ /** for an older choice version: a question's pick is fixed when it is asked */
1558
+ static older = true
861
1559
  static override usage = Command.Usage({
862
1560
  category: 'Review',
863
1561
  description: "the option you suggest on a choice he has not answered: the hub's « my pick » pill on it",
864
- details: `${DETAILS}\n\nsk thread pick <id> <view>: the view by its letter (B) or its label; one pick a card, a new one replaces it. On add: --choice … --pick <view>.`,
1562
+ details: `${DETAILS}\n\nsk thread pick <id> <view>: the view by its letter (B) or its label; one pick a version, a new one replaces it; for an older choice version (a question's pick is fixed at ask).`,
865
1563
  examples: [['suggest the second option', 'sk thread pick <id> B'], ['by its label', 'sk thread pick <id> "Zen Garden"']],
866
1564
  })
867
1565
  id = Option.String({ required: true })
@@ -886,27 +1584,118 @@ type ActOp = 'fixed' | 'wontfix' | 'claim' | 'release' | 'blocked' | 'done' | 'd
886
1584
  function actCommand(op: ActOp, description: string, o: { note?: 'required' | 'optional'; text?: string; topic?: 'required' | 'optional'; named: boolean; examples: [string, string][] }) {
887
1585
  return class extends Command {
888
1586
  static override paths = [['review', op]]
889
- static essential = op === 'done' ? { args: '<id> [what changed]' } : op === 'fixed' ? { args: '<id> --note <what was done>' } : undefined
1587
+ static essential = op === 'ask' ? { args: '<address | id> "<question>" --option … --pick <n>' } : undefined
1588
+ static gloss = op === 'done' ? 'the old name of fixed' : undefined
1589
+ static older = op === 'done' ? true : undefined
890
1590
  static override usage = Command.Usage({ category: 'Review', description, details: `${DETAILS}\n\nTakes an item id or a player report's ref (live#3). ${o.named ? 'Who acts: --as <name>, else SK_AGENT.' : 'Who acts: --as, else SK_AGENT, else agent.'}`, examples: o.examples })
891
- id = Option.String()
1591
+ id = Option.String({ name: 'address | id' })
892
1592
  words = o.text !== undefined || o.topic !== undefined ? Option.String({ required: false, name: o.text ?? 'topic' }) : undefined
893
1593
  note = o.note === 'required' ? Option.String('--note', { required: true, description: 'what was done, why not, or what is needed' }) : Option.String('--note', { description: 'what was done, or the reason' })
894
1594
  commit = Option.String('--commit', { description: 'the commit that holds the fix' })
895
1595
  as = Option.String('--as', { description: 'who acts (else SK_AGENT)' })
896
- options = op === 'ask' ? Option.Array('--option', { description: 'a question he answers in one click: each option (two or more); any agent asks this way, the dispatcher asks without' }) : undefined
1596
+ options = op === 'ask' ? Option.Array('--option', { description: 'a question he answers in one click: each option (two or more), words, a file (a picture, a clip, a sound: its name the label), "<label>=<file>" or "<label>=<before>,<after>"; any agent asks this way, the dispatcher asks without' }) : undefined
897
1597
  pick = op === 'ask' ? Option.String('--pick', { description: 'with --option: the option you pick, by its number from 1 (the house rule: a pick on every question)' }) : undefined
1598
+ checklist = op === 'ask' ? Option.Array('--checklist', { description: 'a checklist he ticks, line by line, over days: each line a step, words on one line (markdown: bold, a link, code)' }) : undefined
1599
+ confirm = op === 'ask' ? Option.Boolean('--confirm', false, { description: 'one step he does in the real world: he answers « done »' }) : undefined
1600
+ text = op === 'ask' ? Option.Boolean('--text', false, { description: 'a value he types: a line or a paragraph' }) : undefined
1601
+ url = op === 'ask' ? Option.Boolean('--url', false, { description: 'a link he pastes (a proof, a listing): the hub opens it once and says its status' }) : undefined
1602
+ secret = op === 'ask' ? Option.String('--secret', { description: 'a key he types into the vault under this name: the thread keeps « stored as <name> », you use it as $(sk secret get <name>) inside the command that needs it; typed in the hub on the Mac that runs it or on his phone over the tailnet' }) : undefined
1603
+ after = op === 'ask' ? Option.String('--after', { description: 'set the thread aside until then (2h, tomorrow, next-week, YYYY-MM-DD[THH:MM]): your question waits for that day; only when you post it' }) : undefined
1604
+ urgent = op === 'ask' ? Option.Boolean('--urgent', false, { description: 'brings back a thread he set aside, at once: only under the bar of a ping (an incident, a hard block, a deadline before it comes back)' }) : undefined
1605
+ login = op === 'ask' ? Option.Boolean('--login', false, { description: 'with --secret: a login, its account (the email or user name) typed and stored beside it' }) : undefined
1606
+ replaces = op === 'ask' ? Option.String('--replaces', { description: 'the id of your earlier question (or words) this one supersedes: it folds to one line « superseded by … » and leaves the dock, his answers on it kept' }) : undefined
1607
+ keep = op === 'ask' ? Option.Boolean('--keep', false, { description: 'keep his older open questions of the same kind on this thread open beside this one; by default this one supersedes them' }) : undefined
1608
+ verdict = op === 'ask' ? Option.Boolean('--verdict', false, { description: "refused: a question waits for the owner's answer already, his answer is its verdict" }) : undefined
1609
+
1610
+ /** the thread item the question goes on and what it supersedes: never a new thread when it supersedes. Named
1611
+ * none, it supersedes the older open questions of its kind on the thread (review/supersede.ts olderQuestions):
1612
+ * the newest by `replaces`, each other withdrawn by `withdrawOlder` once this one has its id; `--keep` none */
1613
+ async target(h: Here, q: { kind: AnswerKind; secret?: string }): Promise<{ id: string; replaces?: string; others: string[] }> {
1614
+ if (this.replaces !== undefined) return { ...(await replacing(h.dir, this.id, this.replaces, this.as)), others: [] }
1615
+ const id = await idOrOpen(h, this.id, this.words ?? '', this.as)
1616
+ if (this.keep) return { id, others: [] }
1617
+ const { readAll } = await import('../review/store.ts')
1618
+ const { membersOf, threadOfItem, threadsOf } = await import('../review/threads.ts')
1619
+ const { olderQuestions } = await import('../review/supersede.ts')
1620
+ const t = threadOfItem(id, threadsOf(readAll(h.dir).items))
1621
+ const older = t === null ? [] : olderQuestions(membersOf(t), q)
1622
+ if (older.length === 0) return { id, others: [] }
1623
+ if (!(await mayHold(h.dir, t!, this.as))) {
1624
+ h.err(` ${older.length} older open question${older.length > 1 ? 's' : ''} of this kind stay open (${older.map((m) => m.id).join(', ')}): another agent holds the thread; sk thread take <address>, then --replaces <id>`)
1625
+ return { id, others: [] }
1626
+ }
1627
+ return { id, replaces: older.at(-1)!.id, others: older.slice(0, -1).map((m) => m.id) }
1628
+ }
1629
+
1630
+ /** the older questions `target` named beside the one it superseded: each withdrawn, « replaced by » the new one */
1631
+ async withdrawOlder(h: Here, t: { replaces?: string; others: string[] }, by: string): Promise<void> {
1632
+ if (t.replaces !== undefined && this.replaces === undefined) h.out(` supersedes ${t.replaces}${t.others.length > 0 ? ` and ${t.others.join(', ')}` : ''}: older open question${t.others.length > 0 ? 's' : ''} of this kind (--keep keeps them)`)
1633
+ const { withdrawObject } = await import('../review/store.ts')
1634
+ for (const re of t.others) {
1635
+ const r = withdrawObject(h.dir, re, `replaced by ${by}`)
1636
+ if ('refused' in r) h.err(` ${re} stays open: ${r.refused}`)
1637
+ }
1638
+ }
1639
+
1640
+ /** after a question: set aside until --after, or brought back by --urgent */
1641
+ async later(h: Here, id: string): Promise<void> {
1642
+ if (this.urgent) await urgentOn(h.dir, id, actor(this.as, false, op))
1643
+ if (this.after === undefined) return
1644
+ const { asideAt, snoozeThread } = await import('../review/snooze.ts')
1645
+ const until = asideAt(this.after)
1646
+ if (until === null) throw new Error(`--after ${this.after}: 2h, tomorrow, next-week, or YYYY-MM-DD[THH:MM]`)
1647
+ snoozeThread(h.dir, id, { until, who: actor(this.as, false, op) })
1648
+ h.out(` set aside until ${until.toLocaleString()}: out of his turn until then`)
1649
+ }
1650
+
1651
+ /** the answer kind the flags name, null for none (a choice through --option, or the dispatcher's question) */
1652
+ kindFlags(): { kind: AnswerKind; label: string } | null {
1653
+ const named = [
1654
+ ...((this.checklist?.length ?? 0) > 0 ? [{ kind: 'checklist' as const, label: '--checklist' }] : []),
1655
+ ...(this.confirm ? [{ kind: 'confirm' as const, label: '--confirm' }] : []),
1656
+ ...(this.text ? [{ kind: 'text' as const, label: '--text' }] : []),
1657
+ ...(this.url ? [{ kind: 'url' as const, label: '--url' }] : []),
1658
+ ...(this.secret !== undefined ? [{ kind: 'secret' as const, label: '--secret' }] : []),
1659
+ ]
1660
+ if (named.length > 1 || (named.length === 1 && this.options !== undefined)) throw new Error(`one answer kind a question: ${[...named.map((k) => k.label), ...(this.options !== undefined ? ['--option'] : [])].join(' and ')} together; ask twice`)
1661
+ if (this.login && this.secret === undefined) throw new Error('--login goes with --secret <name>')
1662
+ return named[0] ?? null
1663
+ }
898
1664
 
899
1665
  async execute(): Promise<number> {
900
1666
  return run(this.context, async (h) => {
901
- const { act, readItem } = await import('../review/store.ts')
1667
+ const { act, mediaDir, readItem } = await import('../review/store.ts')
1668
+ if (op === 'done') h.err(`sk thread done is now sk thread fixed ${this.id} "<what changed>"`)
1669
+ if (this.verdict) throw new Error("ask --verdict: a question waits for the owner's answer already, his answer is its verdict; a thing made he approves goes in a reply --verdict")
1670
+ const k = op === 'ask' ? this.kindFlags() : null
1671
+ if (k !== null) {
1672
+ const { postAsk } = await import('../review/store.ts')
1673
+ const { askStateText } = await import('../review/answer-kinds.ts')
1674
+ if (!this.words?.trim()) throw new Error(`ask <address | id> "<what you ask>" ${k.label}`)
1675
+ if (k.kind === 'secret' && this.secret) {
1676
+ const who = await (await import('../secrets/who-reads.ts')).whoReads([this.secret], process.cwd())
1677
+ if (who[this.secret]?.registered !== true) throw new Error(`--secret ${this.secret}: no row in the secret registry, so the vault would refuse the value he types. Add its row first (the name, what it is for, its scope: wiki identities/_common/secrets-registry.md), then ask again`)
1678
+ }
1679
+ const at = await this.target(h, { kind: k.kind, ...(k.kind === 'secret' && this.secret ? { secret: this.secret } : {}) })
1680
+ const { id, replaces } = at
1681
+ const m = await postAsk(h.dir, id, { who: actor(this.as, false, op), text: this.words, kind: k.kind, ...(k.kind === 'checklist' ? { options: this.checklist ?? [] } : {}), ...(k.kind === 'secret' ? { secret: { name: this.secret ?? '', login: this.login === true } } : {}), ...(replaces ? { replaces } : {}) })
1682
+ h.out(`${id} asked: ${askStateText(readItem(h.dir, id)?.thread ?? [m], m)}`)
1683
+ await this.withdrawOlder(h, at, m.id)
1684
+ await this.later(h, id)
1685
+ if (k.kind === 'secret') h.out(` his answer reads « stored as ${m.ask?.secret?.name} »; then: sk secret get ${m.ask?.secret?.name}`)
1686
+ return 0
1687
+ }
902
1688
  if (op === 'ask' && this.options !== undefined) {
903
1689
  const { postAsk } = await import('../review/store.ts')
904
1690
  if (!this.words?.trim()) throw new Error('ask <address | id> "<question>" --option "<a>" --option "<b>" --pick <n>')
905
- const id = await idOf(h.dir, this.id)
1691
+ const at = await this.target(h, { kind: 'choice' })
1692
+ const { id, replaces } = at
906
1693
  const pick = this.pick === undefined ? undefined : Number(this.pick) - 1
907
1694
  if (pick === undefined) h.err('no --pick: the house rule wants your pick on every question')
908
- const m = postAsk(h.dir, id, { who: actor(this.as, false, op), text: this.words, options: this.options, ...(pick !== undefined ? { pick } : {}) })
909
- h.out(`${id} asked: ${m.ask?.options.map((o, i) => `${i + 1} ${o}${m.ask?.pick === i ? ' (your pick)' : ''}`).join(' · ')}`)
1695
+ const m = await postAsk(h.dir, id, { who: actor(this.as, false, op), text: this.words, options: this.options.map(askOption), ...(pick !== undefined ? { pick } : {}), ...(replaces ? { replaces } : {}) })
1696
+ h.out(`${id} asked: ${m.ask?.options.map((o, i) => `${i + 1} ${o}${m.ask?.views?.[i] != null ? ' [media]' : ''}${m.ask?.pick === i ? ' (your pick)' : ''}`).join(' · ')}`)
1697
+ await this.withdrawOlder(h, at, m.id)
1698
+ await this.later(h, id)
910
1699
  return 0
911
1700
  }
912
1701
  const { stateOf } = await import('../review/model.ts')
@@ -916,22 +1705,37 @@ function actCommand(op: ActOp, description: string, o: { note?: 'required' | 'op
916
1705
  if (o.topic === 'required' && !this.words) throw new Error(`${op} <id> <topic> (sk thread topics)`)
917
1706
  const id = await idOf(h.dir, this.id)
918
1707
  const who = actor(this.as, o.named, op)
1708
+ if (op === 'wontfix') {
1709
+ // an ask's thread closes by its ask (wiki tools/shipkit/threads-page.md, Close and reopen), as the hub's close does
1710
+ const { isAskItem } = await import('../review/model.ts')
1711
+ const was = readItem(h.dir, id)
1712
+ if (was && isAskItem(was.item)) {
1713
+ const { moveAsk, rootOfStore } = await import('../review/close.ts')
1714
+ const { findAsk } = await import('../asks/ask-store.ts')
1715
+ const moved = moveAsk(h.dir, was.item.on!, 'wontfix', this.note ?? '')
1716
+ const a = findAsk(rootOfStore(h.dir), was.item.on!)
1717
+ h.out(`${a.address} ${moved ? 'declined' : `${a.status} already`}${a.why ? `: ${a.why}` : ''}`)
1718
+ return 0
1719
+ }
1720
+ }
919
1721
  if (op === 'done') {
920
- // done is asked of a card he answered « fix »: closed already is the goal reached, unanswered is withdraw's
1722
+ // done is asked of an item he answered « fix »: closed already is the goal reached, unanswered is withdraw's
921
1723
  const { readAll } = await import('../review/store.ts')
922
1724
  const { followedIds } = await import('../review/threads.ts')
923
1725
  const was = readItem(h.dir, id)
924
1726
  const followed = followedIds(readAll(h.dir).items).has(id)
925
1727
  const st = was ? stateOf(was, followed) : null
926
1728
  if (st?.state === 'closed') {
927
- h.out(`${id}: closed already (${st.why ?? 'closed'}${followed ? ', a newer card follows it' : ''}), nothing to close`)
1729
+ h.out(`${id}: closed already (${st.why ?? 'closed'}${followed ? ', a newer version follows it' : ''}), nothing to close`)
928
1730
  if (this.words || this.note) h.err(`your words are not posted: sk thread reply ${id} "<text>"`)
929
1731
  return 0
930
1732
  }
931
1733
  if (st?.state === 'asks' || st?.state === 'draft')
932
- throw new Error(`${id}: done closes a card the owner answered « fix »; this one ${st.state === 'asks' ? "waits on the owner's verdict" : 'is in progress'}: sk thread withdraw ${id} --why "<why>" takes it back`)
1734
+ throw new Error(`${id}: done closes a version the owner answered « fix »; this one ${st.state === 'asks' ? "waits on the owner's verdict" : 'is in progress'}: sk thread withdraw ${id} --why "<why>" takes it back`)
933
1735
  }
1736
+ const holds = op === 'done' || op === 'wontfix' || op === 'release' || op === 'blocked' || op === 'fixed' ? await callerHolds(h.dir, id, this.as) : false
934
1737
  act(h.dir, id, op, who, {
1738
+ holds,
935
1739
  ...(this.note ? { note: this.note } : {}),
936
1740
  ...(op === 'ask' && this.words ? { text: this.words } : {}),
937
1741
  ...(op === 'done' && this.words ? { note: this.words } : {}),
@@ -941,21 +1745,70 @@ function actCommand(op: ActOp, description: string, o: { note?: 'required' | 'op
941
1745
  const x = readItem(h.dir, id)
942
1746
  const st = x ? stateOf(x, false) : null
943
1747
  h.out(`${id} ${op}: ${st ? `${st.state}${st.why ? ` (${st.why})` : ''}${st.topic ? ` ${st.topic}` : ''}${st.worker ? ` ${st.worker}` : ''}` : 'gone'}`)
944
- if (op === 'claim' && x) h.out(detail(x, h.dir, false, false, h.say))
1748
+ if (op === 'claim' && x) h.out(detail(x, mediaDir(h.dir), false, false, h.say))
945
1749
  return 0
946
1750
  })
947
1751
  }
948
1752
  }
949
1753
  }
950
1754
 
951
- export const ReviewFixedCommand = actCommand('fixed', 'close an item he raised as done: the note says what was done (and --commit where)', { note: 'optional', named: false, examples: [['done, with its commit', 'sk thread fixed <id> --note "the lamp lit" --commit abc1234']] })
952
1755
  export const ReviewWontfixCommand = actCommand('wontfix', 'close an item he raised as not done, with the reason', { note: 'required', named: false, examples: [['not done', 'sk thread wontfix <id> --note "the room is gone"']] })
953
1756
  export const ReviewClaimCommand = actCommand('claim', 'take an item to work on it: the hub shows the thread in work by your lane', { named: true, examples: [['take it', 'sk thread claim <id> --as L12']] })
954
1757
  export const ReviewReleaseCommand = actCommand('release', 'give back an item you claimed', { note: 'optional', named: true, examples: [['give it back', 'sk thread release <id> --as L12']] })
955
1758
  export const ReviewBlockedCommand = actCommand('blocked', 'an item you claimed goes back to the owner with what is needed', { note: 'required', named: true, examples: [['his decision is needed', 'sk thread blocked <id> --note "which of the two doors?" --as L12']] })
956
- export const ReviewDoneCommand = actCommand('done', 'an « ok with a fix » version made with no new version: closed, the words say what changed', { text: 'what changed', named: false, examples: [['the fix made', 'sk thread done <id> "the sign moved one tile up"']] })
1759
+ export const ReviewDoneCommand = actCommand('done', 'the older name of sk thread fixed on a version he answered « ok with a fix »', { text: 'what changed', named: false, examples: [['the fix made', 'sk thread fixed <id> "the sign moved one tile up"']] })
1760
+
1761
+ /** `fixed <address | id> ["<what was done>"]`: the one way to say it is fixed (review/threads.ts fixedPlan) */
1762
+ export class ReviewFixedCommand extends Command {
1763
+ static override paths = [['review', 'fixed']]
1764
+ static essential = { args: '<address | id> [what was done]' }
1765
+ static override usage = Command.Usage({
1766
+ category: 'Review',
1767
+ description: 'it is fixed: closes an open note of the owner, an « ok with a fix », or asks the verdict again',
1768
+ details: `${DETAILS}\n\nOn a note of the owner (its id): closes it. On a thread (its address or a version's id): the owner's one open note in it closes (two or more are named: give the note's id); else its version he answered « ok with a fix » closes; else a version he rejected or in work asks the owner's verdict again, as sk thread update <id> fixed "<line>" does (with a file, use that).`,
1769
+ examples: [
1770
+ ["the owner's note, with its commit", 'sk thread fixed page:threads/lightbox "the bar is half as tall" --commit abc1234'],
1771
+ ['an « ok with a fix » made with no new version', 'sk thread fixed <id> "the sign moved one tile up"'],
1772
+ ],
1773
+ })
1774
+ id = Option.String({ name: 'address | id' })
1775
+ words = Option.String({ required: false, name: 'what was done' })
1776
+ note = Option.String('--note', { description: 'what was done (the same as the words)' })
1777
+ commit = Option.String('--commit', { description: 'the commit that holds the fix' })
1778
+ as = Option.String('--as', { description: 'who acts (else SK_AGENT)' })
1779
+
1780
+ async execute(): Promise<number> {
1781
+ return run(this.context, async (h) => {
1782
+ const { act, postUpdate, readAll } = await import('../review/store.ts')
1783
+ const { stateOf } = await import('../review/model.ts')
1784
+ const { fixedPlan, threadOfItem, threadsOf } = await import('../review/threads.ts')
1785
+ const id = await idOf(h.dir, this.id)
1786
+ const items = readAll(h.dir).items
1787
+ const x = items.find((y) => y.item.id === id)
1788
+ const t = threadOfItem(id, threadsOf(items, h.say.spec))
1789
+ if (!x || !t) throw new Error(`no item ${this.id}`)
1790
+ const { ID_RE } = await import('../review/model.ts')
1791
+ const plan = fixedPlan(t, x, { byAddress: !ID_RE.test(this.id) && this.id.includes(':') && !/^\w+#\d+$/.test(this.id) })
1792
+ if ('error' in plan) throw new Error(plan.error)
1793
+ const said = (this.words ?? this.note)?.trim()
1794
+ const who = actor(this.as, false, 'fixed')
1795
+ if (plan.op === 'update') {
1796
+ const r = await postUpdate(h.dir, plan.id, { who, state: 'fixed', text: said || 'fixed' })
1797
+ const { isOpening } = await import('../review/model.ts')
1798
+ h.out(`${plan.id}: ${r.tag}; ${isOpening(r.item) ? 'its work is done, nothing waits on the owner' : "the owner's verdict is asked again"}`)
1799
+ return 0
1800
+ }
1801
+ const holds = await callerHolds(h.dir, plan.id, this.as)
1802
+ act(h.dir, plan.id, plan.op, who, { ...(said ? { note: said } : {}), ...(this.commit ? { commit: this.commit } : {}), holds })
1803
+ const after = readAll(h.dir).items.find((y) => y.item.id === plan.id)
1804
+ const st = after ? stateOf(after, false) : null
1805
+ h.out(`${plan.id} ${plan.op === 'done' ? 'closed, « ok with a fix » done' : 'fixed'}: ${st ? `${st.state}${st.why ? ` (${st.why})` : ''}` : 'gone'}`)
1806
+ return 0
1807
+ })
1808
+ }
1809
+ }
957
1810
  export const ReviewDispatchCommand = actCommand('dispatch', 'the dispatcher sends a raised item to a topic', { note: 'optional', topic: 'required', named: true, examples: [['to a topic', 'sk thread dispatch <id> lieux --as orchestrator']] })
958
- export const ReviewAskCommand = actCommand('ask', 'the dispatcher asks the owner a question on a raised item; his reply answers it', { text: 'question', named: true, examples: [['a question', 'sk thread ask <id> "which tower?" --as orchestrator']] })
1811
+ export const ReviewAskCommand = actCommand('ask', 'a question he answers in one click, with your pick; it starts the thread when none owns the address', { text: 'question', named: true, examples: [['one click, your pick on the second', 'sk thread ask messages:tui/u1 "which hook line ?" --option "Run any workflow" --option "Your workflow, one command" --pick 2'], ["the dispatcher's question on a raised item (no --option)", 'sk thread ask <id> "which tower?" --as orchestrator']] })
959
1812
  export const ReviewDropCommand = actCommand('drop', 'the dispatcher closes a raised item with the reason (a duplicate, already fixed)', { note: 'required', named: true, examples: [['a duplicate', 'sk thread drop <id> --note "same as <other id>" --as orchestrator']] })
960
1813
  export const ReviewReassignCommand = actCommand('reassign', 'the dispatcher takes a claim back, or sends the item to another topic', { note: 'optional', topic: 'optional', named: true, examples: [['a stale claim', 'sk thread reassign <id> --as orchestrator']] })
961
1814
 
@@ -997,7 +1850,7 @@ export class ReviewNextCommand extends Command {
997
1850
 
998
1851
  async execute(): Promise<number> {
999
1852
  return run(this.context, async (h) => {
1000
- const { claimNext } = await import('../review/store.ts')
1853
+ const { claimNext, mediaDir } = await import('../review/store.ts')
1001
1854
  const { stateOf } = await import('../review/model.ts')
1002
1855
  const { detail } = await import('../review/format.ts')
1003
1856
  const lane = this.lane?.trim()
@@ -1011,7 +1864,7 @@ export class ReviewNextCommand extends Command {
1011
1864
  }
1012
1865
  const topic = stateOf(got, false).topic
1013
1866
  const read = topic ? h.say.spec.topics[topic]?.read : undefined
1014
- h.out(`${detail(got, h.dir, false, false, h.say)}${read?.length ? `\nread first: ${read.join(', ')}` : ''}`)
1867
+ h.out(`${detail(got, mediaDir(h.dir), false, false, h.say)}${read?.length ? `\nread first: ${read.join(', ')}` : ''}`)
1015
1868
  return 0
1016
1869
  })
1017
1870
  }
@@ -1174,7 +2027,7 @@ export class ReviewAnimCommand extends Command {
1174
2027
  mode = Option.String('--mode', 'fade', { description: 'cut, fade or wipe' })
1175
2028
  format = Option.String('--format', 'mp4', { description: 'mp4 or gif' })
1176
2029
  labels = Option.String('--labels', 'en', { description: 'the corner labels: en, fr or none' })
1177
- before = Option.String('--before', { description: 'an image, with --after: no card' })
2030
+ before = Option.String('--before', { description: 'an image, with --after: no thread' })
1178
2031
  after = Option.String('--after', { description: 'an image, with --before' })
1179
2032
  out = Option.String('--out', { description: 'where it goes' })
1180
2033
 
@@ -1207,8 +2060,8 @@ export class ReviewStageCommand extends Command {
1207
2060
  static override paths = [['review', 'stage']]
1208
2061
  static override usage = Command.Usage({
1209
2062
  category: 'Review',
1210
- description: "one media of a version staged as a post: a draft in .shipkit/social/drafts/, never posted",
1211
- details: `${DETAILS}\n\nThe media copied in with its metadata left out, the repo's guard run first, the draft committed by its paths. Without --view, the newest version's first media. Without --kind, iteration: feature, a change users can use now, is picked by hand. --dry prints the draft as it would be written, then each account, its place, its count, what it skips. It never publishes: Publish stays his, in Communications. Page: wiki tools/shipkit/threads-raised-notes.md, A post staged from a card`,
2063
+ description: "one media of a version staged as a post: a draft group of the repo's social store, never posted",
2064
+ details: `${DETAILS}\n\nThe media copied in with its metadata left out, the repo's guard run first, the draft committed by its paths. Without --view, the newest version's first media. Without --kind, iteration: feature, a change users can use now, is picked by hand. --dry prints the draft as it would be written, then each account, its place, its count, what it skips. It never publishes: Publish stays his, in Communications. Page: wiki tools/shipkit/threads-raised-notes.md, A post staged from a version`,
1212
2065
  examples: [
1213
2066
  ['the first media, a safe post', 'sk thread stage <id> --text "Hands now pinch and lift." --rating safe'],
1214
2067
  ["the second view's wipe, polished by an agent", 'sk thread stage <id> --view B --side wipe --text "…" --rating mild --polish'],
@@ -1238,13 +2091,13 @@ export class ReviewStageCommand extends Command {
1238
2091
  const { isPostRating, POST_RATINGS } = await import('../identities/rating.ts')
1239
2092
  const missing = [this.text === undefined ? '--text "<the post>"' : null, this.rating === undefined ? `--rating <${POST_RATINGS.join('|')}>` : null].filter((x) => x !== null)
1240
2093
  if (this.text === undefined || this.rating === undefined) throw new Error(`sk thread stage ${this.id} needs ${missing.join(' and ')}`)
1241
- const { stageInputOf, stageOfCard } = await import('../review/stage-card.ts')
2094
+ const { stageInputOf, stageOfThread } = await import('../review/stage-thread.ts')
1242
2095
  const { askPolish, fitStage, stagedKind, stageDraft, stageDry } = await import('../social/stage.ts')
1243
2096
  const { loadSocialUnit } = await import('../social/unit.ts')
1244
2097
  if (!isPostRating(this.rating)) throw new Error(`--rating ${this.rating}: one of ${POST_RATINGS.join(', ')}`)
1245
2098
  const root = dirname(dirname(h.dir))
1246
2099
  const id = await idOf(h.dir, this.id)
1247
- const s = stageOfCard(h.dir, id)
2100
+ const s = stageOfThread(h.dir, id)
1248
2101
  let pick: string | undefined
1249
2102
  if (this.view) {
1250
2103
  // a view's number, or the letter it had before; either alone or after its version's number
@@ -1298,13 +2151,12 @@ export class ReviewAutoCommand extends Command {
1298
2151
  if (this.verb === undefined) {
1299
2152
  if (rules.length === 0) h.out("no auto rule: the repo's review unit declares none (auto: [...]), and no Veille names this repo")
1300
2153
  const now = Date.now()
1301
- const ago = (t: number): string => `${Math.round(Math.abs(now - t) / 60_000)} min`
1302
2154
  for (const r of rules) {
1303
2155
  const log = readAutoLog(h.dir, r.id)
1304
2156
  const next = nextRun(r, log, now)
1305
2157
  h.out(
1306
- `${r.id} every ${r.every} ${log ? `ran ${ago(Date.parse(log.at))} ago (${log.ms.toFixed(1)} ms): ${log.answer}${log.error ? `: ${log.error}` : ''}` : 'never ran'}` +
1307
- `${log?.lastRaised ? ` last item ${log.lastRaised.id}` : ''} next ${next <= now ? 'due now' : `in ${ago(next)}`}`,
2158
+ `${r.id} every ${r.every} ${log ? `ran ${ageWords(Date.parse(log.at), now)} (${log.ms.toFixed(1)} ms): ${log.answer}${log.error ? `: ${log.error}` : ''}` : 'never ran'}` +
2159
+ `${log?.lastRaised ? ` last item ${log.lastRaised.id}` : ''} next ${next <= now ? 'due now' : `in ${ageWords(now, next, { short: true })}`}`,
1308
2160
  )
1309
2161
  }
1310
2162
  if (rules.length > 0) h.out(`logs: ${autoLogDir(h.dir)}; the hub's daemon runs them`)
@@ -1334,152 +2186,322 @@ export class ReviewWatchCommand extends Command {
1334
2186
  static override usage = Command.Usage({
1335
2187
  category: 'Review',
1336
2188
  description: 'one line per verdict, reply or raised note as it lands; every unseen one first; ends with its owner',
1337
- details: `${DETAILS}\n\nRun it under a monitor, unfiltered (a grep holds a burst's last line). It registers itself, so the hub shows who listens. It exits within 2 s once a process above it at start is gone or nothing reads its output. An item nobody takes prints 2 minutes after its last message, then every 2 hours.`,
1338
- examples: [['the cards this session sent', 'sk thread watch --mine'], ["one lane's items", 'sk thread watch --lane interaction']],
2189
+ details: `${DETAILS}\n\nRun it under a monitor, unfiltered (a grep holds a burst's last line). It registers itself, so the hub shows who listens. It exits within 2 s once a process above it at start is gone or nothing reads its output. An item nobody takes prints 2 minutes after its last message, then every 2 hours.\n\n--house: one watch for every repo where the session holds threads, each line headed [<repo>]; it reads the session's record every 2 s, so a repo where it takes a thread later joins with no restart, and the inbox hook counts it as the session's watch in every repo.`,
2190
+ examples: [
2191
+ ['the threads this session holds', 'sk thread watch --mine'],
2192
+ ['the threads this session holds, in every repo', 'sk thread watch --mine --house'],
2193
+ ["one lane's items", 'sk thread watch --lane interaction'],
2194
+ ],
1339
2195
  })
1340
2196
  mine = Option.Boolean('--mine', false, { description: "only the threads this Claude Code session holds" })
1341
2197
  session = Option.String('--session', { description: "only the threads that session holds" })
1342
2198
  lane = Option.String('--lane', { description: "only that lane's items" })
2199
+ house = Option.Boolean('--house', false, { description: 'with --mine or --session: every repo where the session holds threads, one joined later too, each line headed [<repo>]' })
1343
2200
 
1344
2201
  async execute(): Promise<number> {
1345
2202
  return run(this.context, async (h) => {
1346
- const { existsSync, mkdirSync, watch } = await import('node:fs')
1347
- const { readAll, scanStamp } = await import('../review/store.ts')
1348
- const { cardsInDb } = await import('../hq/switch.ts')
1349
- const { AGENT_RE, coversCard, laneOf, UNTAKEN_AGAIN_MS, untakenOf } = await import('../review/model.ts')
1350
- const { followedIds, unseen } = await import('../review/threads.ts')
1351
- const { raisedLine, untakenLine, watchLines } = await import('../review/format.ts')
1352
- const { exitWithOwner, liveWatchers, registerWatch } = await import('../review/watchers.ts')
2203
+ const { AGENT_RE } = await import('../review/model.ts')
2204
+ const { exitWithOwner, liveWatchers } = await import('../review/watchers.ts')
2205
+ const { sessionId } = await import('../review/store.ts')
1353
2206
  const session = await sessionOf(this.mine, this.session)
1354
- const lane = this.lane?.trim() || null
2207
+ // --mine under SK_AGENT is that lane's watch: a lane shares its session's id, its name tells them apart
2208
+ const lane = this.lane?.trim() || (this.mine ? callerLane(undefined) : null)
1355
2209
  if (lane !== null && !AGENT_RE.test(lane)) throw new Error(`--lane: « ${lane} » is no lane id (${AGENT_RE.source})`)
1356
- const { hears, threadByItem, threadsOf } = await import('../review/threads.ts')
1357
- let byItem = new Map<string, import('../review/threads.ts').Thread>()
1358
- const mine = (x: Parameters<typeof coversCard>[1]): boolean => hears({ session, lane }, x, byItem)
2210
+ // a house watch follows one session's record: an unfiltered one would hear every thread of every repo
2211
+ if (this.house && session === null) throw new Error('--house hears the threads of one session in every repo it holds them in: with --mine, or --session <id>')
1359
2212
  if (session === null && lane === null) {
1360
2213
  const { bareWatchTaken } = await import('../review/model.ts')
1361
2214
  const taken = bareWatchTaken(liveWatchers(h.dir), process.pid)
1362
2215
  if (taken !== null) throw new Error(taken)
1363
2216
  }
1364
- registerWatch(h.dir, { session, lane })
1365
- // before any await: a pull that hangs never keeps a watch alive past its owner
2217
+ const by = sessionId()
2218
+ // before any await of a store: a pull that hangs never keeps a watch alive past its owner
1366
2219
  exitWithOwner()
1367
- const shown = new Set<string>()
1368
- // a store refused for a while (a fold or a way back of the daemon file walks): one line, and the next poll
1369
- // reads again; never a watch that dies and hears nothing more
1370
- let refused: string | null = null
1371
- const safely = (fn: () => void): void => {
1372
- try {
1373
- fn()
1374
- if (refused !== null) h.err(`review: ok, the store reads again: this watch goes on`)
1375
- refused = null
1376
- } catch (e) {
1377
- const why = (e as Error).message.split('\n')[0] ?? ''
1378
- if (refused === null) h.err(`review: WARN the store does not read now (${why}): this watch reads again at its next poll`)
1379
- refused = why
1380
- }
2220
+ await restartWatchOnModelMove(h)
2221
+ // the one stream for every store this watch hears, its own lines untagged
2222
+ await watchFeed(h.err)
2223
+ const f = { session, lane, by, house: this.house }
2224
+ if (!this.house || session === null) {
2225
+ await hearStore(h, f)
2226
+ return new Promise<number>(() => {})
1381
2227
  }
1382
- const tick = (): void => safely(read)
1383
- const read = (): void => {
1384
- const all = readAll(h.dir)
1385
- byItem = threadByItem(threadsOf(all.items, h.say.spec))
1386
- for (const b of all.broken) {
1387
- const key = `broken ${b.id} ${b.error}`
1388
- if (!shown.has(key)) h.err(`review: FAIL ${b.id}: ${b.error}`)
1389
- shown.add(key)
1390
- }
1391
- for (const x of unseen(all.items).filter(mine))
1392
- for (const l of watchLines(x, all.items)) {
1393
- if (shown.has(l.key)) continue
1394
- shown.add(l.key)
1395
- h.out(l.text)
2228
+ // one process, one loop a store: the store it starts in, then each one the session's record names
2229
+ const { noteSession, repoNameOf } = await import('../agent-time/registry.ts')
2230
+ const { dirname, resolve } = await import('node:path')
2231
+ noteSession(h.dir)
2232
+ const heard = new Set<string>()
2233
+ const retry = new Map<string, number>()
2234
+ const hear = async (x: Here): Promise<string> => {
2235
+ heard.add(resolve(x.dir))
2236
+ const repo = repoNameOf(dirname(dirname(x.dir)))
2237
+ const tagged = (print: (l: string) => void) => (l: string) => print(l.split('\n').map((y) => `[${repo}] ${y}`).join('\n'))
2238
+ await hearStore({ ...x, out: tagged(h.out), err: tagged(h.err) }, f)
2239
+ return repo
2240
+ }
2241
+ let busy = false
2242
+ const more = async (): Promise<string[]> => {
2243
+ if (busy) return []
2244
+ busy = true
2245
+ const joined: string[] = []
2246
+ try {
2247
+ for (const dir of await recordedStores(session, (d) => heard.has(resolve(d)) || (retry.get(resolve(d)) ?? 0) > Date.now())) {
2248
+ try {
2249
+ joined.push(await hear(await hereAt(dir, h.out, h.err)))
2250
+ } catch (e) {
2251
+ // a store that does not open now: said once a minute, read again then
2252
+ retry.set(resolve(dir), Date.now() + 60_000)
2253
+ h.err(`review watch: WARN ${dir} does not open now (${(e as Error).message.split('\n')[0]}): tried again in a minute`)
2254
+ }
1396
2255
  }
1397
- for (const x of all.items.filter(mine)) {
1398
- const l = raisedLine(x)
1399
- if (l === null || shown.has(l.key)) continue
1400
- shown.add(l.key)
1401
- h.out(l.text)
1402
- }
1403
- // an item nobody takes: a --lane watch hears its own lane's, an unfiltered or --mine watch every one
1404
- const now = new Date()
1405
- const followed = followedIds(all.items)
1406
- const watchers = liveWatchers(h.dir)
1407
- for (const x of all.items) {
1408
- if (lane !== null && laneOf(x) !== lane) continue
1409
- const why = untakenOf(x, followed.has(x.item.id), watchers, now, h.say.spec.dispatcher)
1410
- if (why === null) continue
1411
- const round = Math.floor((now.getTime() - Date.parse(x.thread.at(-1)?.at ?? x.item.created)) / UNTAKEN_AGAIN_MS)
1412
- const key = `untaken ${x.item.id} ${why} ${round}`
1413
- if (shown.has(key)) continue
1414
- shown.add(key)
1415
- h.out(untakenLine(x, why, lane))
2256
+ } finally {
2257
+ busy = false
1416
2258
  }
2259
+ return joined
1417
2260
  }
1418
- tick()
1419
- // the grace and the reminder pass with time alone: one read a minute
1420
- setInterval(tick, 60_000)
1421
- // the store the switch names, read again at each poll (a process reads the switch at most once a second), so a
1422
- // watch follows a move while it runs. The rows: their stamp is a query of a few µs, asked every 50 ms, read at
1423
- // once. The files: a watch of the folder asks again (debounced), and a stat stamp every 5 s catches a missed event
1424
- let soon: ReturnType<typeof setTimeout> | null = null
1425
- const again = (): void => {
1426
- if (soon) clearTimeout(soon)
1427
- soon = setTimeout(() => {
1428
- soon = null
1429
- tick()
1430
- }, cardsInDb() ? 0 : 150)
2261
+ const first = [await hear(h), ...(await more())]
2262
+ h.err(`review watch: hears ${first.join(', ')}; a repo where this session takes a thread joins within 2 s`)
2263
+ setInterval(
2264
+ () =>
2265
+ void more()
2266
+ .then((js) => js.forEach((r) => h.err(`review watch: hears ${r} too`)))
2267
+ .catch(() => {}),
2268
+ 2000,
2269
+ )
2270
+ return new Promise<number>(() => {})
2271
+ })
2272
+ }
2273
+ }
2274
+
2275
+ /** a watch outlives a change of the thread model: once a read fails on an item the new model wrote, it runs again with
2276
+ * its args, same pid, onto code that loads (review/model-moved.ts) */
2277
+ async function restartWatchOnModelMove(h: Here): Promise<void> {
2278
+ const { modelWatch, MODEL_FILE } = await import('../review/model-moved.ts')
2279
+ modelWatch.onMove(async (why) => {
2280
+ const { bootEntries, probeLoad } = await import('../core/load-probe.ts')
2281
+ const { OWN_LIB } = await import('../core/last-good.ts')
2282
+ const { join } = await import('node:path')
2283
+ const a = await probeLoad(OWN_LIB, [...bootEntries(OWN_LIB), MODEL_FILE, join(OWN_LIB, 'src/review/store.ts')])
2284
+ if (!a.ok) {
2285
+ h.err(`review watch: WARN ${why}, and ${a.file} fails to load (${a.error}): this watch keeps its model until it loads`)
2286
+ return false
2287
+ }
2288
+ h.err(`review watch: ${why}: it runs again with its args`)
2289
+ const { reexecSelf } = await import('../core/reexec.ts')
2290
+ return reexecSelf()
2291
+ })
2292
+ }
2293
+
2294
+ /** one store heard by a watch of filter `f`, until the process ends: registered beside it, its lines printed through `h` */
2295
+ async function hearStore(h: Here, f: { session: string | null; lane: string | null; by: string | null; house: boolean }): Promise<void> {
2296
+ const { session, lane, by } = f
2297
+ const { existsSync, mkdirSync, watch } = await import('node:fs')
2298
+ const { mediaDir, readAll, scanStamp } = await import('../review/store.ts')
2299
+ const { modelWatch } = await import('../review/model-moved.ts')
2300
+ const { threadsInDb } = await import('../hq/switch.ts')
2301
+ const { coversItem, laneOf, UNTAKEN_AGAIN_MS, untakenOf } = await import('../review/model.ts')
2302
+ const { followedIds, unseen } = await import('../review/threads.ts')
2303
+ const { raisedLine, untakenLine, watchLines } = await import('../review/format.ts')
2304
+ const { liveWatchers, registerWatch } = await import('../review/watchers.ts')
2305
+ const { hears, holderOf, listenersOf, threadByItem, threadsOf, wordReaches } = await import('../review/threads.ts')
2306
+ let byItem = new Map<string, import('../review/threads.ts').Thread>()
2307
+ // who hears what: the registry, read again every 30 s, so a lane's threads reach its session's watch once it ends
2308
+ const { noteHanded, readParties, repoNameOf } = await import('../agent-time/registry.ts')
2309
+ const { laneAsksFor, resumeOf } = await import('../review/inbox-read.ts')
2310
+ const { dirname } = await import('node:path')
2311
+ let parties: import('../review/parties.ts').Parties | null = null
2312
+ const mine = (x: Parameters<typeof coversItem>[1]): boolean => hears({ session, lane }, x, byItem, parties)
2313
+ // the owner's words that name another agent are that agent's (wiki tools/shipkit/threads-how-it-fits.md, Mentions)
2314
+ const to = (x: Parameters<typeof coversItem>[1], m: import('../review/model.ts').Message): boolean => wordReaches({ session, lane }, x, m, byItem, parties)
2315
+ const beat = registerWatch(h.dir, { session, lane }, new Date(), by, f.house)
2316
+ setInterval(() => beat(), 10_000)
2317
+ const known = async (): Promise<void> => {
2318
+ if (session === null && lane === null) return
2319
+ const all = readAll(h.dir)
2320
+ const ids = new Set(threadsOf(all.items, h.say.spec).flatMap((t) => [...(t.head.item.origin.by === 'agent' && t.head.item.origin.session ? [t.head.item.origin.session] : []), ...(holderOf(t)?.session ?? [])]))
2321
+ parties = await readParties({ sessions: [...ids, ...(session ? [session] : [])], watchers: liveWatchers(h.dir), self: by })
2322
+ // a lane's watch ends with its lane: its threads pass to its session, whose hook or watch hears them
2323
+ const me = lane !== null && by !== null ? parties.lanes.filter((l) => l.name === lane && l.session === by) : []
2324
+ if (me.length > 0 && !me.some((l) => l.live)) {
2325
+ h.err(`review watch: exits, its lane ${lane} ended: its threads pass to its session`)
2326
+ process.exit(0)
2327
+ }
2328
+ }
2329
+ await known().catch(() => {})
2330
+ setInterval(() => void known().catch(() => {}), 30_000)
2331
+ const shown = new Set<string>()
2332
+ // a store refused for a while (a fold or a way back of the daemon file walks): one line, and the next poll
2333
+ // reads again; never a watch that dies and hears nothing more
2334
+ let refused: string | null = null
2335
+ const safely = (fn: () => void): void => {
2336
+ try {
2337
+ fn()
2338
+ if (refused !== null) h.err(`review: ok, the store reads again: this watch goes on`)
2339
+ refused = null
2340
+ } catch (e) {
2341
+ const why = (e as Error).message.split('\n')[0] ?? ''
2342
+ if (refused === null) h.err(`review: WARN the store does not read now (${why}): this watch reads again at its next poll`)
2343
+ refused = why
2344
+ }
2345
+ }
2346
+ const tick = (): void => safely(read)
2347
+ const read = (): void => {
2348
+ const all = readAll(h.dir)
2349
+ // the model moved under this watch: it runs again, and its broken lines are the old model's
2350
+ if (all.broken.length > 0 && modelWatch.readFailed()) return
2351
+ byItem = threadByItem(threadsOf(all.items, h.say.spec))
2352
+ for (const b of all.broken) {
2353
+ const key = `broken ${b.id} ${b.error}`
2354
+ if (!shown.has(key)) h.err(`review: FAIL ${b.id}: ${b.error}`)
2355
+ shown.add(key)
2356
+ }
2357
+ // his request for a lane, first: a session's watch (or a bare one) is the orchestrator's ear
2358
+ if (lane === null && (parties !== null || session === null)) {
2359
+ for (const l of laneAsksFor({ repo: repoNameOf(dirname(dirname(h.dir))), root: dirname(dirname(h.dir)), dir: h.dir, here: true, ...all, say: h.say }, { session, lane: null }, parties ?? { sessions: [], lanes: [] })) {
2360
+ if (shown.has(l)) continue
2361
+ shown.add(l)
2362
+ h.out(l)
1431
2363
  }
1432
- let folderWatched = false
1433
- const watchFolder = (): void => {
1434
- if (folderWatched) return
1435
- folderWatched = true
1436
- if (!existsSync(h.dir)) mkdirSync(h.dir, { recursive: true })
1437
- watch(h.dir, { recursive: true }, () => {
1438
- if (!cardsInDb()) again()
1439
- })
2364
+ }
2365
+ for (const x of unseen(all.items, to).filter(mine)) {
2366
+ const fresh = watchLines(x, all.items, mediaDir(h.dir), to).filter((l) => !shown.has(l.key))
2367
+ for (const l of fresh) {
2368
+ shown.add(l.key)
2369
+ h.out(l.text)
1440
2370
  }
1441
- if (!cardsInDb()) watchFolder()
1442
- // the sources: pulled now and every 30 s, a new item lands and the tick prints it
1443
- await pull(h)
1444
- if (h.unit?.sources?.length) setInterval(() => void pull(h), 30_000)
1445
- let stamp = ''
1446
- let scanned = Date.now()
1447
- setInterval(() => {
1448
- const rows = cardsInDb()
1449
- // the files' stamp walks every card: once every 5 s, never at the rows' pace
1450
- if (!rows) {
1451
- watchFolder()
1452
- if (Date.now() - scanned < 5000) return
1453
- }
1454
- scanned = Date.now()
1455
- // a refused stamp, or one read again after a refusal: the read says it, once
1456
- try {
1457
- const now = scanStamp(h.dir)
1458
- if (now !== stamp || refused !== null) again()
1459
- stamp = now
1460
- } catch {
1461
- again()
1462
- }
1463
- }, 50)
1464
- return new Promise<number>(() => {})
2371
+ // a session's watch, his message on its ended lane's thread: the way back to that lane
2372
+ const t = byItem.get(x.item.id)
2373
+ const r = fresh.length > 0 && lane === null && t && parties ? resumeOf(h, t, parties) : null
2374
+ if (r) {
2375
+ h.out(` ${r.line}`)
2376
+ noteHanded(r.lane, r.session, r.thread)
2377
+ }
2378
+ }
2379
+ for (const x of all.items.filter(mine)) {
2380
+ const l = raisedLine(x)
2381
+ if (l === null || shown.has(l.key)) continue
2382
+ shown.add(l.key)
2383
+ h.out(l.text)
2384
+ }
2385
+ // an item nobody takes: a --lane watch hears its own lane's, an unfiltered or --mine watch every one
2386
+ const now = new Date()
2387
+ const followed = followedIds(all.items)
2388
+ const watchers = liveWatchers(h.dir)
2389
+ for (const x of all.items) {
2390
+ if (lane !== null && laneOf(x) !== lane) continue
2391
+ const why = untakenOf(x, followed.has(x.item.id), listenersOf(watchers, x, byItem).length > 0, now, h.say.spec.dispatcher)
2392
+ if (why === null) continue
2393
+ const round = Math.floor((now.getTime() - Date.parse(x.thread.at(-1)?.at ?? x.item.created)) / UNTAKEN_AGAIN_MS)
2394
+ const key = `untaken ${x.item.id} ${why} ${round}`
2395
+ if (shown.has(key)) continue
2396
+ shown.add(key)
2397
+ h.out(untakenLine(x, why, lane))
2398
+ }
2399
+ }
2400
+ tick()
2401
+ // the grace and the reminder pass with time alone: one read a minute
2402
+ setInterval(tick, 60_000)
2403
+ // the store the switch names, read again at each poll (a process reads the switch at most once a second), so a
2404
+ // watch follows a move while it runs. The rows: their stamp is a query of a few µs, asked every 50 ms, read at
2405
+ // once. The files: a watch of the folder asks again (debounced), and a stat stamp every 5 s catches a missed event
2406
+ let soon: ReturnType<typeof setTimeout> | null = null
2407
+ const again = (): void => {
2408
+ if (soon) clearTimeout(soon)
2409
+ soon = setTimeout(() => {
2410
+ soon = null
2411
+ tick()
2412
+ }, threadsInDb() ? 0 : 150)
2413
+ }
2414
+ // the store's own poll, for a watch the daemon's stream does not feed: no home, a store it serves no hub for, a
2415
+ // daemon that does not answer (review/watch-feed.ts)
2416
+ let polling = false
2417
+ let folderWatched = false
2418
+ const watchFolder = (): void => {
2419
+ if (folderWatched) return
2420
+ folderWatched = true
2421
+ if (!existsSync(h.dir)) mkdirSync(h.dir, { recursive: true })
2422
+ watch(h.dir, { recursive: true }, () => {
2423
+ if (polling && !threadsInDb()) again()
1465
2424
  })
1466
2425
  }
2426
+ let stamp = ''
2427
+ let scanned = Date.now()
2428
+ let loop: ReturnType<typeof setInterval> | null = null
2429
+ const poll = (on: boolean): void => {
2430
+ polling = on
2431
+ if (!on) {
2432
+ if (loop) clearInterval(loop)
2433
+ loop = null
2434
+ return
2435
+ }
2436
+ if (loop) return
2437
+ if (!threadsInDb()) watchFolder()
2438
+ stamp = ''
2439
+ loop = setInterval(() => {
2440
+ const rows = threadsInDb()
2441
+ // the files' stamp walks every item: once every 5 s, never at the rows' pace
2442
+ if (!rows) {
2443
+ watchFolder()
2444
+ if (Date.now() - scanned < 5000) return
2445
+ }
2446
+ scanned = Date.now()
2447
+ // a refused stamp, or one read again after a refusal: the read says it, once
2448
+ try {
2449
+ const now = scanStamp(h.dir)
2450
+ if (now !== stamp || refused !== null) again()
2451
+ stamp = now
2452
+ } catch {
2453
+ again()
2454
+ }
2455
+ }, 50)
2456
+ }
2457
+ // the sources: pulled now and every 30 s, a new item lands and the tick prints it
2458
+ await pull(h)
2459
+ if (h.unit?.sources?.length) setInterval(() => void pull(h), 30_000)
2460
+ const feed = await watchFeed(h.err)
2461
+ if (feed === null) return poll(true)
2462
+ // a daemon down is said once for the whole watch by the feed; a store it serves no hub for, once here
2463
+ let saidAlone = false
2464
+ feed.hear(h.dir, {
2465
+ moved: again,
2466
+ push: () => {
2467
+ poll(false)
2468
+ again()
2469
+ },
2470
+ poll: (why) => {
2471
+ if (why !== null && !saidAlone) h.err(`review watch: ${why}: this watch reads the store itself`)
2472
+ if (why !== null) saidAlone = true
2473
+ poll(true)
2474
+ },
2475
+ })
2476
+ }
2477
+
2478
+ /** the one stream of the daemon's store moves this process hears, null where no home runs (SHIPKIT_NO_HOME, CI, a
2479
+ * machine with none): a watch then polls its store */
2480
+ let feedHeld: import('../review/watch-feed.ts').WatchFeed | null | undefined
2481
+ /** `say`: the watch's own line, untagged: the first caller's, the command's before any store */
2482
+ async function watchFeed(say: (l: string) => void): Promise<import('../review/watch-feed.ts').WatchFeed | null> {
2483
+ if (feedHeld !== undefined) return feedHeld
2484
+ const set = (v: string | undefined): boolean => v != null && v !== ''
2485
+ const { homeWanted } = await import('../home/home-start.ts')
2486
+ if (set(process.env.SHIPKIT_NO_HOME) || set(process.env.CI) || !homeWanted()) return (feedHeld = null)
2487
+ const { daemonUrl } = await import('../home/home-paths.ts')
2488
+ const { WatchFeed } = await import('../review/watch-feed.ts')
2489
+ return (feedHeld = new WatchFeed(daemonUrl(), { say }))
1467
2490
  }
1468
2491
 
1469
2492
  /** the review folders of this machine's house, its archived repos included: what a move carries */
1470
2493
  async function houseStores(): Promise<string[]> {
1471
2494
  const { findRepoRoot } = await import('../ts/config.ts')
1472
- const { houseRepos } = await import('../serve/project-gutter.ts')
2495
+ const { houseRepos } = await import('../house/project-gutter.ts')
1473
2496
  const { homedir } = await import('node:os')
1474
2497
  const { storeDir } = await import('../review/store.ts')
1475
2498
  const house = houseRepos(findRepoRoot(process.cwd()), homedir())
1476
2499
  if (house.index == null) throw new Error(`${process.cwd()} is in no house repo: run it from the house checkout, whose repos it moves`)
1477
2500
  const { existsSync } = await import('node:fs')
1478
2501
  const repos = [...house.repos, ...house.archived].map((r) => r.path)
1479
- // a lane's worktree holds the cards it sent there: they join their repo's rows
2502
+ // a lane's worktree holds the items it sent there: they join their repo's rows
1480
2503
  const trees = repos.flatMap((r) => {
1481
- const p = Bun.spawnSync(['git', '-C', r, 'worktree', 'list', '--porcelain'], { stdout: 'pipe', stderr: 'ignore' })
1482
- return (p.stdout?.toString() ?? '').split('\n').flatMap((l) => (l.startsWith('worktree ') && l.slice(9) !== r ? [l.slice(9)] : []))
2504
+ return realGit.runSync(r, ['worktree', 'list', '--porcelain']).out.split('\n').flatMap((l) => (l.startsWith('worktree ') && l.slice(9) !== r ? [l.slice(9)] : []))
1483
2505
  })
1484
2506
  return [...repos, ...trees.filter((t) => existsSync(storeDir(t)))].map((r) => storeDir(r))
1485
2507
  }
@@ -1488,14 +2510,14 @@ export class ReviewMoveCommand extends Command {
1488
2510
  static override paths = [['review', 'move']]
1489
2511
  static override usage = Command.Usage({
1490
2512
  category: 'Review',
1491
- description: "this machine's cards into the daemon's database, or back into files",
2513
+ description: "this machine's threads into the daemon's database, or back into files",
1492
2514
  details:
1493
- "The machine db switch cards-in-db picks where every review card of this machine is read and written: its repo's files (`.shipkit/review/<id>/`, off, the default), or the rows of the daemon's database (on). `--go` imports every card file of every house repo the rows lack (by id and rev), proves each is in the rows, turns the switch on, then reads the files once more after a second for a writer that had not seen it. With the switch hq-cards on, it first asks the hq: the hq and the files must hold the same cards, else nothing moves. The files stay where they are, untouched: the way back. `--back` is a look of the way back, `--back --go` first fetches from the Space any media file the spool let go (or refuses, naming how many it would lack), then writes every card of the rows into the files (the cards made since included), turns the switch off, and writes them out again after a second. During a move's lag (7 s) a reader in another process can miss a card a writer made on the side the move left; the second pass carries it, and none stays missed. Both keep the later of two heads and every message by its id, so a move stopped half way runs again. A card's media files stay in its folder. `--tidy` (a look, `--tidy --go` acts) removes a card's files from its repo only while the switch is on and once its rows hold all of them, the hq holds them (hq-cards on) and the Space each of its media files; a card whose rows differ stays, named; after it, `--back --go` writes the files again from the rows. It moves every house repo of the home it runs in, worktrees resolved to their checkout: a test names a scratch HOME. Page: wiki tools/shipkit/threads-store.md",
2515
+ "The machine db switch cards-in-db picks where every thread of this machine is read and written: its repo's files (`.shipkit/review/<id>/`, off, the default), or the rows of the daemon's database (on). `--go` imports every version file of every house repo the rows lack (by id and rev), proves each is in the rows, turns the switch on, then reads the files once more after a second for a writer that had not seen it. With the switch hq-cards on, it first asks the hq: the hq and the files must hold the same cards, else nothing moves. The files stay where they are, untouched: the way back. `--back` is a look of the way back, `--back --go` first fetches from the Space any media file the spool let go (or refuses, naming how many it would lack), then writes every version of the rows into the files (the versions made since included), turns the switch off, and writes them out again after a second. During a move's lag (7 s) a reader in another process can miss a version a writer made on the side the move left; the second pass carries it, and none stays missed. Both keep the later of two heads and every message by its id, so a move stopped half way runs again. A version's media files stay in its folder. `--tidy` (a look, `--tidy --go` acts) removes a version's files from its repo only while the switch is on and once its rows hold all of them, the hq holds them (hq-cards on) and the Space each of its media files; a version whose rows differ stays, named; after it, `--back --go` writes the files again from the rows. It moves every house repo of the home it runs in, worktrees resolved to their checkout: a test names a scratch HOME. Page: wiki tools/shipkit/threads-store.md",
1494
2516
  examples: [['what the tidy would remove', 'sk thread move --tidy'], ['what a move would do', 'sk thread move'], ['move this machine', 'sk thread move --go'], ['what the way back would do', 'sk thread move --back'], ['go back to the files', 'sk thread move --back --go']],
1495
2517
  })
1496
2518
  go = Option.Boolean('--go', false, { description: 'do it: the move, or with --back the way back' })
1497
2519
  back = Option.Boolean('--back', false, { description: 'the way back: the rows into the files, the switch off' })
1498
- tidy = Option.Boolean('--tidy', false, { description: 'remove the card files the rows, the hq and the Space all hold' })
2520
+ tidy = Option.Boolean('--tidy', false, { description: 'remove the thread files the rows, the hq and the Space all hold' })
1499
2521
 
1500
2522
  async execute(): Promise<number> {
1501
2523
  const out = (l: string): void => void this.context.stdout.write(`${l}\n`)
@@ -1505,17 +2527,16 @@ export class ReviewMoveCommand extends Command {
1505
2527
  const stores = await houseStores()
1506
2528
  const { moveBack, moveGo, tidyFiles } = await import('../review/move.ts')
1507
2529
  const dry = !this.go
1508
- // one move or look of the cards job at a time: the job would send what the move is writing
1509
- const { cardsLease } = await import('../hq/cards.ts')
1510
- const { leaseHolder, tryLease } = await import('../core/locked-write.ts')
1511
- const lease = dry ? null : tryLease(cardsLease(), 'review move')
1512
- if (!dry && lease == null) throw new Error(`a look of the cards job or another move runs (pid ${leaseHolder(cardsLease())?.pid ?? '?'}): run it again once it ended`)
2530
+ // one move or look of the threads job at a time: the job would send what the move is writing
2531
+ const { threadsLeaseHolder, tryThreadsLease } = await import('../hq/thread-sync.ts')
2532
+ const lease = dry ? null : tryThreadsLease('review move')
2533
+ if (!dry && lease == null) throw new Error(`a look of the hq threads job or another move runs (pid ${threadsLeaseHolder()?.pid ?? '?'}): run it again once it ended`)
1513
2534
  try {
1514
2535
  const r = this.tidy ? await tidyFiles(stores, { dry, proof: await tidyProof(stores) }) : this.back ? await moveBack(stores, { dry }) : await moveGo(stores, { dry, hqDiff: hqDiffOf(stores) })
1515
2536
  for (const l of r.lines) (l.startsWith('WARN') ? err : out)(l)
1516
- const { cardsInDb } = await import('../hq/switch.ts')
2537
+ const { threadsInDb } = await import('../hq/switch.ts')
1517
2538
  const { BACK_FIRST } = await import('../review/move.ts')
1518
- if (cardsInDb()) out(BACK_FIRST)
2539
+ if (threadsInDb()) out(BACK_FIRST)
1519
2540
  if (dry) out(`a look: nothing ${this.tidy ? 'removed' : 'moved'}. sk thread move ${this.tidy ? '--tidy --go removes' : this.back ? '--back --go moves' : '--go moves'}`)
1520
2541
  return r.ok ? 0 : 1
1521
2542
  } finally {
@@ -1531,24 +2552,24 @@ export class ReviewMoveCommand extends Command {
1531
2552
  /** what the tidy proves outside the store: the names of each repo's rows the hq lacks or holds at another rev (the
1532
2553
  * check hq-cards, the hq asked once), and the Space's word on each file */
1533
2554
  async function tidyProof(stores: readonly string[]): Promise<import('../review/move.ts').TidyProof> {
1534
- const { cardsDiff, cardsOn, heldRepos } = await import('../hq/cards.ts')
2555
+ const { threadsDiff, threadsOn, heldRepos } = await import('../hq/thread-sync.ts')
1535
2556
  const { confirmedUp } = await import('../media-store/remote.ts')
1536
2557
  const up = (key: string, size: number): Promise<boolean> => confirmedUp(key, size)
1537
- if (!cardsOn()) return { hqLacks: async () => ({ refused: 'the switch hq-cards is off: no hq holds them' }), up }
2558
+ if (!threadsOn()) return { hqLacks: async () => ({ refused: 'the switch hq-cards is off: no hq holds them' }), up }
1538
2559
  const { myHq } = await import('../hq/hq-local.ts')
1539
2560
  const hq = myHq()
1540
2561
  if ('refused' in hq) return { hqLacks: async () => ({ refused: `the hq is not reached (${hq.refused})` }), up }
1541
2562
  const { dirname } = await import('node:path')
1542
2563
  const { held, left } = await heldRepos(stores.map((d) => ({ name: d, path: dirname(dirname(d)) })))
1543
- const diff = await cardsDiff(hq, held)
2564
+ const diff = await threadsDiff(hq, held)
1544
2565
  if ('refused' in diff) return { hqLacks: async () => ({ refused: `the hq refused the check: ${diff.refused}` }), up }
1545
- const { repoIdOf } = await import('../review/card-db.ts')
2566
+ const { repoIdOf } = await import('../review/item-db.ts')
1546
2567
  const byRepo = new Map(diff.map((d) => [d.repo, new Set([...d.onlyHere, ...d.differ])]))
1547
2568
  return {
1548
2569
  hqLacks: async (dir) => {
1549
2570
  const set = byRepo.get(repoIdOf(dir))
1550
2571
  if (set != null) return set
1551
- return { refused: left.some((l) => dir.startsWith(l)) ? 'a repo with no remote: the hq carries none of its cards' : 'the hq holds no cards of this repo' }
2572
+ return { refused: left.some((l) => dir.startsWith(l)) ? 'a repo with no remote: the hq carries none of its threads' : 'the hq holds no threads of this repo' }
1552
2573
  },
1553
2574
  up,
1554
2575
  }
@@ -1558,14 +2579,14 @@ async function tidyProof(stores: readonly string[]): Promise<import('../review/m
1558
2579
  * proof that nothing it leaves behind is missing elsewhere. Null with the switch off */
1559
2580
  function hqDiffOf(stores: readonly string[]): () => Promise<string[] | null> {
1560
2581
  return async () => {
1561
- const { cardsDiff, cardsOn, heldRepos } = await import('../hq/cards.ts')
1562
- if (!cardsOn()) return null
2582
+ const { threadsDiff, threadsOn, heldRepos } = await import('../hq/thread-sync.ts')
2583
+ if (!threadsOn()) return null
1563
2584
  const { myHq } = await import('../hq/hq-local.ts')
1564
2585
  const hq = myHq()
1565
2586
  if ('refused' in hq) return [`the hq is not reached (${hq.refused}): the check hq-cards cannot prove both sides equal`]
1566
2587
  const { dirname } = await import('node:path')
1567
2588
  const { held } = await heldRepos(stores.map((d) => ({ name: d, path: dirname(dirname(d)) })))
1568
- const diff = await cardsDiff(hq, held)
2589
+ const diff = await threadsDiff(hq, held)
1569
2590
  if ('refused' in diff) return [`the hq refused the check: ${diff.refused}`]
1570
2591
  return diff.flatMap((d) => (d.onlyHere.length + d.onlyHq.length + d.differ.length === 0 ? [] : [`${d.repo}: ${d.onlyHere.length} only here, ${d.onlyHq.length} only in the hq, ${d.differ.length} at two revs (${[...d.onlyHere, ...d.onlyHq, ...d.differ].slice(0, 3).join(', ')})`]))
1571
2592
  }
@@ -1575,34 +2596,34 @@ export class ReviewExportCommand extends Command {
1575
2596
  static override paths = [['review', 'export']]
1576
2597
  static override usage = Command.Usage({
1577
2598
  category: 'Review',
1578
- description: 'cards of this repo written as the files of a card, into a folder',
1579
- details: `${DETAILS}\n\nWith the switch cards-in-db on, a card is rows of the daemon's database; export writes it as the folder the files backend keeps (\`<to>/<id>/item.json\`, \`thread/<message>.json\`, and each media file this machine still holds; a file the disk let go is named, its key in the head's media). Nothing in the store changes.`,
1580
- examples: [['one card', 'sk thread export 20261118-210000-the-gate --to /tmp/cards'], ['every card of the repo', 'sk thread export --all --to /tmp/cards']],
2599
+ description: 'threads of this repo written as their files, one folder an item, into a folder',
2600
+ details: `${DETAILS}\n\nWith the switch cards-in-db on, an item is rows of the daemon's database; export writes it as the folder the files backend keeps (\`<to>/<id>/item.json\`, \`thread/<message>.json\`, and each media file this machine still holds; a file the disk let go is named, its key in the head's media). Nothing in the store changes.`,
2601
+ examples: [['one item', 'sk thread export 20261118-210000-the-gate --to /tmp/threads'], ['every item of the repo', 'sk thread export --all --to /tmp/threads']],
1581
2602
  })
1582
- all = Option.Boolean('--all', false, { description: 'every card of the repo' })
1583
- to = Option.String('--to', { required: true, description: 'the folder the cards are written into' })
2603
+ all = Option.Boolean('--all', false, { description: 'every item of the repo' })
2604
+ to = Option.String('--to', { required: true, description: 'the folder the items are written into' })
1584
2605
  ids = Option.Rest()
1585
2606
 
1586
2607
  async execute(): Promise<number> {
1587
2608
  return run(this.context, async (h) => {
1588
- const { cardsInDb } = await import('../hq/switch.ts')
2609
+ const { threadsInDb } = await import('../hq/switch.ts')
1589
2610
  const { resolve } = await import('node:path')
1590
- if (this.all === this.ids.length > 0) throw new Error('give card ids or --all')
2611
+ if (this.all === this.ids.length > 0) throw new Error('give item ids or --all')
1591
2612
  const to = resolve(this.to)
1592
2613
  if (to === resolve(h.dir)) throw new Error(`--to ${this.to}: the store itself; sk thread move --back --go writes the rows into the store`)
1593
2614
  const ids = this.all ? undefined : await Promise.all(this.ids.map((r) => idOf(h.dir, r)))
1594
2615
  let r: import('../review/move.ts').Moved
1595
- if (cardsInDb()) r = (await import('../review/move.ts')).exportRows(h.dir, { to, ...(ids ? { ids } : {}) })
2616
+ if (threadsInDb()) r = (await import('../review/move.ts')).exportRows(h.dir, { to, ...(ids ? { ids } : {}) })
1596
2617
  else {
1597
2618
  // the files are the store: a copy of each folder is the export
1598
2619
  const { cpSync, existsSync } = await import('node:fs')
1599
- const { cardIds } = await import('../review/store.ts')
2620
+ const { itemIds } = await import('../review/store.ts')
1600
2621
  const { join } = await import('node:path')
1601
- const want = ids ?? cardIds(h.dir)
2622
+ const want = ids ?? itemIds(h.dir)
1602
2623
  for (const id of want) if (!existsSync(join(to, id))) cpSync(join(h.dir, id), join(to, id), { recursive: true })
1603
- r = { dir: h.dir, cards: want.length, heads: want.length, msgs: 0, gone: 0, same: 0, files: 0, kept: [], broken: [], read: [] }
2624
+ r = { dir: h.dir, items: want.length, heads: want.length, msgs: 0, gone: 0, same: 0, files: 0, kept: [], broken: [], read: [] }
1604
2625
  }
1605
- h.out(`review: ${r.cards} cards written into ${to} (${r.heads} heads, ${r.msgs} messages${r.media ? `, ${r.media.copied} media files` : ''})`)
2626
+ h.out(`review: ${r.items} items written into ${to} (${r.heads} heads, ${r.msgs} messages${r.media ? `, ${r.media.copied} media files` : ''})`)
1606
2627
  for (const k of r.kept) h.out(` kept: ${k}`)
1607
2628
  for (const b of r.broken) h.err(` does not read: ${b}`)
1608
2629
  if (r.media && r.media.missing.length > 0) h.out(` ${r.media.missing.length} media files this machine no longer holds (the Space has them by their key in the head): ${r.media.missing.slice(0, 5).join(', ')}`)
@@ -1611,71 +2632,110 @@ export class ReviewExportCommand extends Command {
1611
2632
  }
1612
2633
  }
1613
2634
 
1614
- /** `post <address | id>`: a version in the thread that owns the address (or holds the id), started when none does;
1615
- * every flag of add after it */
1616
- export class ThreadPostCommand extends Command {
1617
- static override paths = [['thread', 'post']]
1618
- static essential = {}
1619
- static override usage = Command.Usage({
1620
- category: 'Review',
1621
- description: 'a version in the thread of an object, by its address; the thread starts when none owns it',
1622
- details: `${DETAILS}\n\nThe address is the version's own (page:review/lightbox, draft:<slug>, trailer:<name>/<cut>); an item id names its thread instead. Every other flag is add's (sk thread add --help): --title, --what, the media, --keeps. The tool links it into the thread: you never type a --supersedes. Page: wiki tools/shipkit/threads.md`,
1623
- examples: [['a version of a hub page', 'SK_AGENT=L12 sk thread post page:review/lightbox --title "…" --what "…" --before a.png --after b.png'], ['the next version of a thread', 'sk thread post 20261119-233610-trailer-v15 --title "…" --what "…" --image c.png']],
1624
- })
1625
- target = Option.String()
1626
- rest = Option.Proxy()
1627
-
1628
- async execute(): Promise<number> {
1629
- const { ADDRESS_RE, ID_RE } = await import('../review/model.ts')
1630
- const t = this.target.trim()
1631
- let link: string[]
1632
- if (ADDRESS_RE.test(t) && !ID_RE.test(t)) link = ['--on', t]
1633
- else {
1634
- const { storeDir, readAll } = await import('../review/store.ts')
1635
- const root = await reviewRoot(process.cwd())
1636
- if (root == null) throw new Error(`${process.cwd()} is in no shipkit repo`)
1637
- const { openReview } = await import('../review/project.ts')
1638
- const { dir } = await openReview(root)
1639
- const id = await idOf(dir ?? storeDir(root), t)
1640
- const { threadOfId } = await import('../review/cells.ts')
1641
- const { threadsOf } = await import('../review/threads.ts')
1642
- const head = threadOfId(id, threadsOf(readAll(dir).items))?.head.item
1643
- if (!head) throw new Error(`no thread holds ${t}`)
1644
- link = head.origin.by === 'agent' ? ['--supersedes', head.id] : ['--answers', head.id]
2635
+ /** what `propose` was typed with: its positionals, the thread it goes in, who acts, and its fields in the order typed:
2636
+ * `--field <key>` opens a field, the value flags after it are that field's; with no `--field`, one field */
2637
+ export function proposeArgs(args: readonly string[], read: (file: string) => string): { positionals: string[]; into?: string; as?: string; replaces?: string; fields: import('../review/store.ts').ProposeInput[] } {
2638
+ const positionals: string[] = []
2639
+ const fields: { key?: string; before?: string; after?: string; type?: string }[] = []
2640
+ let into: string | undefined
2641
+ let as: string | undefined
2642
+ let replaces: string | undefined
2643
+ const cur = (flag: string): (typeof fields)[number] => {
2644
+ if (fields.length === 0) fields.push({})
2645
+ const f = fields.at(-1)!
2646
+ const name = flag.replace(/-file$/, '') as 'before' | 'after' | 'type'
2647
+ if (f[name] !== undefined) throw new Error(`--${flag} twice on ${f.key ? `--field ${f.key}` : 'one field'}: a change of several names each with --field <key>`)
2648
+ return f
2649
+ }
2650
+ for (let i = 0; i < args.length; i++) {
2651
+ const a = args[i]!
2652
+ if (!a.startsWith('--')) {
2653
+ positionals.push(a)
2654
+ continue
1645
2655
  }
1646
- return this.cli.run(['thread', 'add', ...link, ...this.rest])
2656
+ if (a === '--verdict') throw new Error("--verdict: a proposed change waits for the owner's answer already, the owner's apply or the owner's words are its verdict")
2657
+ const v = args[++i]
2658
+ if (v === undefined) throw new Error(`${a}: needs a value`)
2659
+ const flag = a.slice(2)
2660
+ if (flag === 'field') fields.push({ key: v })
2661
+ else if (flag === 'in') into = v
2662
+ else if (flag === 'as') as = v
2663
+ else if (flag === 'replaces') replaces = v
2664
+ else if (flag === 'before' || flag === 'after' || flag === 'type') cur(flag)[flag] = v
2665
+ else if (flag === 'before-file' || flag === 'after-file') cur(flag)[flag === 'before-file' ? 'before' : 'after'] = read(v)
2666
+ else throw new Error(`${a}: no such flag (sk thread propose --help)`)
2667
+ }
2668
+ return {
2669
+ positionals,
2670
+ ...(into !== undefined ? { into } : {}),
2671
+ ...(as !== undefined ? { as } : {}),
2672
+ ...(replaces !== undefined ? { replaces } : {}),
2673
+ fields: fields.map((f) => {
2674
+ const at = f.key ? `--field ${f.key}: ` : ''
2675
+ if (f.after === undefined) throw new Error(`${at}--after "<value>" (or --after-file): the value you propose`)
2676
+ const [type, lang] = f.type === undefined ? [] : f.type.split(':', 2)
2677
+ if (lang !== undefined && type !== 'code') throw new Error(`${at}--type ${f.type}: a language goes with code alone, code:<lang>`)
2678
+ return { after: f.after, ...(f.key !== undefined ? { key: f.key } : {}), ...(f.before !== undefined ? { before: f.before } : {}), ...(type !== undefined ? { type: type as import('../review/model.ts').DiffType } : {}), ...(lang ? { lang } : {}) }
2679
+ }),
1647
2680
  }
1648
2681
  }
1649
2682
 
1650
- /** `propose <address> --after "<text>"`: a change of an object's text he applies in one click, or edits first */
2683
+ const PROPOSE_USAGE = `sk thread propose <address> ["<why>"] --before "<value>" --after "<value>"
2684
+ sk thread propose <address> ["<why>"] --field <key> --before … --after … [--field <key> …]
2685
+
2686
+ --before, --after the value as it is and as you propose it (--before-file, --after-file read a file)
2687
+ --field <key> opens one field of a change of several: the value flags after it are its own; he applies each alone
2688
+ --type <text|color|sound|code[:<lang>]> how the field draws (code:ts, code:glsl: its syntax colours, none for a language it does not know); else the repo's unit declares it for that kind, else its values say
2689
+ --in <id | address> the thread to post it in, when it is not the address's own
2690
+ --as <name> who acts (else SK_AGENT)
2691
+ --replaces <id> your earlier change (or question) this one supersedes: it folds, its answers kept`
2692
+
2693
+ /** `propose <address> --after "<value>"`: a change of an object, one field or several, he applies in one click a field */
1651
2694
  export class ThreadProposeCommand extends Command {
1652
2695
  static override paths = [['thread', 'propose']]
2696
+ static essential = { args: '<address> ["<why>"] --before … --after …' }
1653
2697
  static override usage = Command.Usage({
1654
2698
  category: 'Review',
1655
- description: "a change of an object's text he applies in one click, or edits first; you land what he applied",
1656
- details: `${DETAILS}\n\nIt goes into the thread that owns the address, or the one above it (--in <id> names another). --before and --after are the text (--before-file, --after-file read a file). His « apply » reaches your watch as \`<id> applied your change of <address>: land this text: …\`: you write it where the object lives and say so in the thread. Page: wiki tools/shipkit/threads.md`,
1657
- examples: [['a phrasing', 'SK_AGENT=L12 sk thread propose messages:tui/u1 --before "Run any workflow" --after "Run your workflow from the terminal" "shorter, and says where"']],
2699
+ description: 'a change he applies a field at a click: words, a colour, code, a sound; you land it',
2700
+ details: `${DETAILS}\n\n${PROPOSE_USAGE}\n\nIt goes into the thread that owns the address, or the one above it. Each field draws by its type: words as a word diff, a colour (#rrggbb) as its swatch beside the old one, code as a hunk in syntax colours, a sound (two files) as an A/B player; several fields as one table. His « apply » reaches your watch as one line a field, \`<id> applied <field> of <address>: land <value>\`: you write it where the object lives and say so in the thread. Page: wiki tools/shipkit/threads.md, A proposed change`,
2701
+ examples: [
2702
+ ['a phrasing', 'SK_AGENT=L12 sk thread propose messages:tui/u1 --before "Run any workflow" --after "Run your workflow from the terminal" "shorter, and says where"'],
2703
+ ['a colour and a label, each applied alone', 'SK_AGENT=L12 sk thread propose screen:home/button "warmer, and says what it does" --field accent --before "#3a7bd5" --after "#e0569b" --field label --before "Run" --after "Run it now"'],
2704
+ ['a snippet of code', 'SK_AGENT=L12 sk thread propose asset:shader/water --type code:glsl --before-file old.glsl --after-file new.glsl "calmer waves"'],
2705
+ ['a sound, A/B', 'SK_AGENT=L12 sk thread propose asset:sfx/clash --before sfx/clash.flac --after sfx/clash-v2.flac "less harsh"'],
2706
+ ],
1658
2707
  })
1659
2708
  address = Option.String()
1660
2709
  words = Option.String({ required: false })
1661
- before = Option.String('--before', { description: 'the text as it is' })
1662
- after = Option.String('--after', { description: 'the text you propose' })
1663
- beforeFile = Option.String('--before-file', { description: 'the text as it is, from a file' })
1664
- afterFile = Option.String('--after-file', { description: 'the text you propose, from a file' })
2710
+ field = Option.Array('--field', { description: 'opens one field of a change of several: the value flags after it are its own; he applies each alone' })
2711
+ before = Option.Array('--before', { description: 'the value as it is' })
2712
+ after = Option.Array('--after', { description: 'the value you propose' })
2713
+ beforeFile = Option.Array('--before-file', { description: 'the value as it is, from a file' })
2714
+ afterFile = Option.Array('--after-file', { description: 'the value you propose, from a file' })
2715
+ type = Option.Array('--type', { description: 'how the field draws: text, color, code[:<lang>], sound, image, clip (else the unit or its values say)' })
1665
2716
  into = Option.String('--in', { description: 'the thread to post it in, by an id or an address, when it is not the address own' })
1666
2717
  as = Option.String('--as', { description: 'who acts (else SK_AGENT)' })
2718
+ replaces = Option.String('--replaces', { description: 'the id of your earlier change (or question) this one supersedes: it folds to one line « superseded by … » and leaves the dock' })
1667
2719
 
1668
2720
  async execute(): Promise<number> {
2721
+ // the flags are declared for the help; the fields are read in the order typed, since --field opens each
2722
+ const raw = process.argv.slice(2)
2723
+ const at = raw.indexOf('propose')
2724
+ const args = at >= 0 ? raw.slice(at + 1) : [this.address, ...(this.words !== undefined ? [this.words] : [])]
1669
2725
  return run(this.context, async (h) => {
1670
2726
  const { readFileSync } = await import('node:fs')
1671
2727
  const { postPropose } = await import('../review/store.ts')
1672
- const read = (v: string | undefined, f: string | undefined): string | undefined => (f !== undefined ? readFileSync(f, 'utf8') : v)
1673
- const after = read(this.after, this.afterFile)
1674
- if (after === undefined) throw new Error('--after "<text>" (or --after-file): the text you propose')
1675
- const before = read(this.before, this.beforeFile)
1676
- const id = await idOf(h.dir, this.into ?? this.address)
1677
- const m = postPropose(h.dir, id, { who: actor(this.as, false, 'propose'), text: this.words ?? `a change of ${this.address}`, on: this.address, ...(before !== undefined ? { before } : {}), after })
1678
- h.out(`${id} proposed ${m.propose?.on}: he applies it in the hub`)
2728
+ const p = proposeArgs(args, (f) => readFileSync(f, 'utf8'))
2729
+ const [address, words, ...more] = p.positionals
2730
+ if (address === undefined) throw new Error(`the address of the object first:\n${PROPOSE_USAGE}`)
2731
+ if (more.length > 0) throw new Error(`unexpected ${more.map(quoted).join(' ')}: one address, then the words in quotes`)
2732
+ const { addressOrThrow } = await import('../review/model.ts')
2733
+ await declaredOrThrow(h, addressOrThrow(address))
2734
+ const r = p.replaces !== undefined ? await replacing(h.dir, p.into ?? address, p.replaces, p.as) : null
2735
+ const id = r !== null ? r.id : p.into !== undefined ? await idOf(h.dir, p.into) : await idOrOpen(h, address, words ?? `a change of ${address}`, p.as)
2736
+ const m = await postPropose(h.dir, id, { who: actor(p.as, false, 'propose'), text: words ?? `a change of ${address}`, on: address, fields: p.fields, ...(r !== null ? { replaces: r.replaces } : {}) })
2737
+ const fields = m.propose?.fields ?? [{ key: '', type: m.propose?.type }]
2738
+ h.out(`${id} proposed ${m.propose?.on}${fields.length > 1 ? ` (${fields.map((f) => `${f.key}${f.type ? ` ${f.type}` : ''}`).join(', ')})` : m.propose?.type ? ` (${m.propose.type})` : ''}: he applies it in the hub, a field at a time`)
1679
2739
  return 0
1680
2740
  })
1681
2741
  }
@@ -1686,20 +2746,34 @@ export class ThreadAttachCommand extends Command {
1686
2746
  static override paths = [['thread', 'attach']]
1687
2747
  static override usage = Command.Usage({
1688
2748
  category: 'Review',
1689
- description: 'a thread links one more object: its thread control finds the thread; never its own address',
1690
- details: `${DETAILS}\n\nA link: many threads may link one object. Page: wiki tools/shipkit/threads.md`,
2749
+ description: 'link one more object to a thread, never its own address: that object then finds the thread',
2750
+ details: `${DETAILS}\n\nThe thread is its address or an id. The object's thread control then finds the thread. A link: many threads may link one object. Page: wiki tools/shipkit/threads.md`,
1691
2751
  examples: [['link a media', 'sk thread attach 20261119-233610-trailer-v15 media:thumbnail-v3']],
1692
2752
  })
1693
2753
  thread = Option.String()
1694
2754
  address = Option.String()
1695
2755
  as = Option.String('--as', { description: 'who acts (else SK_AGENT)' })
2756
+ verdict = Option.Boolean('--verdict', false, { description: `the linked object waits for the owner's verdict (a draft, a text, a diff): ${VERDICT_FLAG}` })
1696
2757
 
1697
2758
  async execute(): Promise<number> {
1698
2759
  return run(this.context, async (h) => {
1699
- const { attachTo } = await import('../review/store.ts')
2760
+ const { attachTo, specOf } = await import('../review/store.ts')
1700
2761
  const id = await idOf(h.dir, this.thread)
1701
- attachTo(h.dir, id, actor(this.as, false, 'attach'), this.address)
1702
- h.out(`${id} links ${this.address}`)
2762
+ const { addressOrThrow } = await import('../review/model.ts')
2763
+ const a = addressOrThrow(this.address)
2764
+ await declaredOrThrow(h, a)
2765
+ if (this.verdict) {
2766
+ // a kind with actions of its own (a reflection: accept, rework, discard): they are the owner's answer on the link
2767
+ const { HOUSE_KINDS } = await import('../review/kinds.ts')
2768
+ const k = a.slice(0, a.indexOf(':'))
2769
+ const kind = specOf(h.dir).kinds[k] ?? HOUSE_KINDS[k]
2770
+ if (Object.keys(kind?.actions ?? {}).length > 0) throw new Error(`attach ${a} --verdict: the kind ${k} declares its own actions, which are the owner's answer on the link; attach it without --verdict`)
2771
+ // a draft is settled by what he does with it (publish, drop), never approved
2772
+ // only the house kinds' acts are read (review/settle.ts): a repo's own kind keeps the verdict
2773
+ if (!(k in specOf(h.dir).kinds) && Object.keys(kind?.acts ?? {}).length > 0) throw new Error(`attach ${a} --verdict: the kind ${k} is answered by its own acts (${Object.values(kind!.acts!).map((x) => x.label).join(', ')}), never a verdict${k === 'draft' ? '; show it here with sk social draft save <slug> <file|-> --thread <this thread>' : ''}`)
2774
+ }
2775
+ attachTo(h.dir, id, actor(this.as, false, 'attach'), this.address, new Date(), this.verdict ? { asksVerdict: true } : {})
2776
+ h.out(`${id} links ${this.address}${this.verdict ? ", waiting for the owner's verdict" : ''}`)
1703
2777
  return 0
1704
2778
  })
1705
2779
  }
@@ -1724,16 +2798,16 @@ export class ReviewMigrateCommand extends Command {
1724
2798
  const { dirname } = await import('node:path')
1725
2799
  const { openReview } = await import('../review/project.ts')
1726
2800
  const { foldStore } = await import('../review/thread-fold.ts')
1727
- const { repoIdOf } = await import('../review/card-db.ts')
1728
- const { cardsInDb } = await import('../hq/switch.ts')
2801
+ const { repoIdOf } = await import('../review/item-db.ts')
2802
+ const { threadsInDb } = await import('../hq/switch.ts')
1729
2803
  const { existsSync } = await import('node:fs')
1730
2804
  const dirs = this.all ? await houseStores() : [h.dir]
1731
2805
  const seen = new Set<string>()
1732
2806
  const stores = dirs.filter((d) => {
1733
- const key = cardsInDb() ? repoIdOf(d) : d
2807
+ const key = threadsInDb() ? repoIdOf(d) : d
1734
2808
  if (seen.has(key)) return false
1735
2809
  seen.add(key)
1736
- return cardsInDb() || existsSync(d)
2810
+ return threadsInDb() || existsSync(d)
1737
2811
  })
1738
2812
  const plans = []
1739
2813
  for (const d of stores) {
@@ -1801,9 +2875,11 @@ export const REVIEW_COMMANDS = [
1801
2875
  ReviewMoveCommand,
1802
2876
  ReviewExportCommand,
1803
2877
  ReviewMigrateCommand,
1804
- ThreadPostCommand,
1805
2878
  ThreadProposeCommand,
1806
2879
  ThreadAttachCommand,
2880
+ ThreadTakeCommand,
2881
+ ThreadAssignCommand,
2882
+ ThreadWorkingCommand,
1807
2883
  ]
1808
2884
 
1809
2885
  // every verb is `sk thread <verb>`, and `sk review <verb>` its older name (run() says the new form on stderr)