rvlib-shipkit 2.27.0 → 2.28.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 (338) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/src/agent-time/hooks.ts +10 -3
  4. package/src/agent-time/live.ts +11 -5
  5. package/src/agent-time/registry.ts +289 -0
  6. package/src/agent-time/store.ts +2 -2
  7. package/src/annex/born.ts +2 -2
  8. package/src/annex/offload.ts +12 -11
  9. package/src/asks/ask-after.ts +6 -2
  10. package/src/asks/ask-bar-fold.ts +57 -0
  11. package/src/asks/ask-migrate.ts +280 -0
  12. package/src/asks/ask-steps-fold.ts +166 -0
  13. package/src/asks/ask-store.ts +586 -0
  14. package/src/assets/kits/identity-kit.ts +106 -38
  15. package/src/assets/kits/poster-thumbnail.ts +282 -0
  16. package/src/checks/SK003-claude-md-shape.check.ts +92 -25
  17. package/src/checks/SK004-gitignore-policy.check.ts +8 -4
  18. package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
  19. package/src/checks/SK026-asks-autoclose.check.ts +9 -23
  20. package/src/checks/SK038-speaks-as.check.ts +3 -3
  21. package/src/checks/SK042-post-kinds.check.ts +26 -24
  22. package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
  23. package/src/checks/SK050-retired-commands.check.ts +127 -0
  24. package/src/cli/cmd_Asks.ts +204 -53
  25. package/src/cli/cmd_Backup.ts +151 -8
  26. package/src/cli/cmd_Calls.ts +1 -0
  27. package/src/cli/cmd_Commands.ts +140 -34
  28. package/src/cli/cmd_Contracts.ts +1 -0
  29. package/src/cli/cmd_Keys.ts +1 -0
  30. package/src/cli/cmd_Lanes.ts +15 -4
  31. package/src/cli/cmd_Messages.ts +152 -1
  32. package/src/cli/cmd_Needs.ts +1 -0
  33. package/src/cli/cmd_Review.ts +931 -229
  34. package/src/cli/cmd_Secret.ts +255 -34
  35. package/src/cli/cmd_Social.ts +36 -33
  36. package/src/cli/cmd_SocialDrafts.ts +235 -0
  37. package/src/cli/cmd_Sound.ts +22 -1
  38. package/src/cli/cmd_Start.ts +3 -2
  39. package/src/cli/cmd_ThreadHolds.ts +34 -0
  40. package/src/cli/cmd_ThreadKinds.ts +146 -0
  41. package/src/cli/cmd_ThreadReflect.ts +83 -0
  42. package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
  43. package/src/cli/cmd_Vault.ts +1 -1
  44. package/src/cli/cmd_When.ts +1 -0
  45. package/src/cli/family-help.ts +2 -2
  46. package/src/cli/family-pages.ts +1 -1
  47. package/src/cli/kit/builtins.ts +1 -0
  48. package/src/cli/kit/verb.ts +6 -2
  49. package/src/cli/registry.ts +21 -2
  50. package/src/cli.ts +5 -2
  51. package/src/collections/actions.ts +25 -74
  52. package/src/collections/collection-types.ts +9 -5
  53. package/src/collections/md-body.ts +5 -3
  54. package/src/collections/pings.ts +13 -6
  55. package/src/collections/providers.ts +53 -61
  56. package/src/collections/reflections.ts +9 -4
  57. package/src/core/discover-checks.ts +18 -3
  58. package/src/core/git.ts +31 -0
  59. package/src/core/house-layout.ts +17 -0
  60. package/src/core/layout.ts +10 -5
  61. package/src/core/locked-write.ts +4 -1
  62. package/src/core/machine-db.ts +5 -3
  63. package/src/core/migrate-layout.ts +8 -10
  64. package/src/home/activity.ts +8 -15
  65. package/src/home/daemon-jobs.ts +13 -1
  66. package/src/home/home-paths.ts +6 -3
  67. package/src/home/home-routes.ts +8 -0
  68. package/src/home/inbox-shape.ts +233 -100
  69. package/src/home/inbox.ts +26 -71
  70. package/src/home/machine-fold.ts +10 -15
  71. package/src/home/machine-host.ts +19 -1
  72. package/src/home/other-macs.ts +2 -2
  73. package/src/home/serve-web.ts +6 -5
  74. package/src/home/space-page.ts +1 -1
  75. package/src/home/vault-page.ts +51 -17
  76. package/src/home/vault-words.ts +2 -2
  77. package/src/hooks/one-way-in-guard.ts +24 -2
  78. package/src/hq/files-send.ts +27 -28
  79. package/src/hq/hq-db.ts +4 -1
  80. package/src/hq/hq-local.ts +37 -4
  81. package/src/hq/hq-routes.ts +10 -2
  82. package/src/hq/hq-store.ts +6 -2
  83. package/src/hq/kinds/ask.ts +6 -6
  84. package/src/hq/outbox.ts +5 -3
  85. package/src/hq/replica.ts +1 -2
  86. package/src/hq/vault-route.ts +112 -0
  87. package/src/identities/collection.ts +2 -2
  88. package/src/identities/identities.ts +9 -8
  89. package/src/identities/machine-route.ts +8 -3
  90. package/src/ledger/db.ts +8 -1
  91. package/src/media-store/backup/daemon.ts +48 -8
  92. package/src/media-store/backup/keys.ts +1 -1
  93. package/src/media-store/backup/manifest.ts +20 -2
  94. package/src/media-store/backup/prune.ts +365 -0
  95. package/src/media-store/backup/retention.ts +122 -0
  96. package/src/media-store/backup/run.ts +14 -8
  97. package/src/media-store/backup/sources.ts +18 -17
  98. package/src/media-store/backup/thread-copy.ts +340 -0
  99. package/src/media-store/copy/config.ts +3 -4
  100. package/src/media-store/copy/store.ts +2 -2
  101. package/src/media-store/db.ts +2 -2
  102. package/src/media-store/forget.ts +118 -0
  103. package/src/media-store/purge.ts +3 -2
  104. package/src/media-store/space-listing.ts +20 -4
  105. package/src/media-store/space.ts +6 -5
  106. package/src/messages/guard.ts +49 -0
  107. package/src/messages/model.ts +1 -1
  108. package/src/messages/objects.ts +201 -0
  109. package/src/messages/routes.ts +2 -2
  110. package/src/messages/score.ts +1 -1
  111. package/src/messages/write.ts +285 -0
  112. package/src/pages/frame-client.ts +181 -4
  113. package/src/reflections/reflections-queue.ts +1 -1
  114. package/src/release/gate-checkout.ts +2 -1
  115. package/src/release/git-facts.ts +3 -2
  116. package/src/release/public-clean.ts +3 -2
  117. package/src/repo-config.ts +40 -18
  118. package/src/review/anim.ts +1 -1
  119. package/src/review/answer-kinds.ts +131 -0
  120. package/src/review/band.ts +53 -0
  121. package/src/review/branch-hold.ts +84 -0
  122. package/src/review/card-db.ts +16 -6
  123. package/src/review/card-rows.ts +4 -3
  124. package/src/review/cells.ts +297 -65
  125. package/src/review/close.ts +92 -0
  126. package/src/review/draft-card.ts +8 -16
  127. package/src/review/draft-model.ts +2 -2
  128. package/src/review/events.ts +171 -0
  129. package/src/review/format.ts +128 -14
  130. package/src/review/glyphs.ts +63 -0
  131. package/src/review/gone.ts +1 -1
  132. package/src/review/holds-sync.ts +62 -0
  133. package/src/review/holds.ts +85 -0
  134. package/src/review/house-kind-defs.ts +41 -0
  135. package/src/review/inbox-hook.ts +22 -9
  136. package/src/review/inbox-read.ts +201 -0
  137. package/src/review/instructions.ts +199 -0
  138. package/src/review/kind-apply.ts +61 -0
  139. package/src/review/kind-catalog.ts +96 -0
  140. package/src/review/kinds.ts +278 -0
  141. package/src/review/lane-ask.ts +109 -0
  142. package/src/review/model.ts +396 -86
  143. package/src/review/move.ts +3 -3
  144. package/src/review/need-address.ts +15 -0
  145. package/src/review/need-threads.ts +93 -0
  146. package/src/review/object-card.ts +48 -0
  147. package/src/review/object-read.ts +31 -0
  148. package/src/review/owner-verdict.ts +36 -0
  149. package/src/review/parties.ts +182 -0
  150. package/src/review/previews.ts +3 -1
  151. package/src/review/projections.ts +235 -0
  152. package/src/review/referring.ts +54 -0
  153. package/src/review/reflection-object.ts +195 -0
  154. package/src/review/routes.ts +137 -32
  155. package/src/review/secret-route.ts +80 -0
  156. package/src/review/snooze.ts +38 -0
  157. package/src/review/stage-card.ts +4 -4
  158. package/src/review/store.ts +366 -85
  159. package/src/review/supersede.ts +116 -0
  160. package/src/review/take-back.ts +52 -0
  161. package/src/review/thread-fold.ts +20 -7
  162. package/src/review/threads.ts +236 -39
  163. package/src/review/traces.ts +218 -0
  164. package/src/review/trailer-card.ts +2 -2
  165. package/src/review/unit.ts +71 -5
  166. package/src/review/verdict-items.ts +73 -0
  167. package/src/review/verdict-write.ts +15 -0
  168. package/src/review/wait.ts +85 -0
  169. package/src/review/watchers.ts +22 -9
  170. package/src/scaffold/files/claude-settings-local.json +2 -0
  171. package/src/secrets/archive-mark.ts +52 -0
  172. package/src/secrets/archive.ts +83 -0
  173. package/src/secrets/copy.ts +14 -14
  174. package/src/secrets/keychain-write.ts +48 -0
  175. package/src/secrets/keychain.ts +8 -5
  176. package/src/secrets/lapse-mark.ts +33 -0
  177. package/src/secrets/lapse.ts +60 -0
  178. package/src/secrets/list.ts +16 -22
  179. package/src/secrets/manager.ts +31 -16
  180. package/src/secrets/read.ts +161 -33
  181. package/src/secrets/tail.ts +31 -0
  182. package/src/serve/hub-app/asks-page.tsx +2 -1
  183. package/src/serve/hub-app/auto-text.tsx +14 -6
  184. package/src/serve/hub-app/benign-errors.ts +15 -1
  185. package/src/serve/hub-app/card-head.tsx +49 -0
  186. package/src/serve/hub-app/check-view.tsx +3 -2
  187. package/src/serve/hub-app/code-copy.ts +35 -0
  188. package/src/serve/hub-app/col-card.tsx +31 -40
  189. package/src/serve/hub-app/col-list-page.tsx +5 -2
  190. package/src/serve/hub-app/col-tables-view.tsx +7 -4
  191. package/src/serve/hub-app/col-tables.ts +5 -5
  192. package/src/serve/hub-app/cols-svc.ts +4 -79
  193. package/src/serve/hub-app/commands/commands-page.tsx +2 -1
  194. package/src/serve/hub-app/controls.css +83 -0
  195. package/src/serve/hub-app/frames-st.ts +17 -1
  196. package/src/serve/hub-app/git-view.tsx +3 -2
  197. package/src/serve/hub-app/home-st.ts +57 -6
  198. package/src/serve/hub-app/home-strip.css +1 -6
  199. package/src/serve/hub-app/home-strip.tsx +2 -1
  200. package/src/serve/hub-app/home.html +3 -0
  201. package/src/serve/hub-app/house-wiki-view.tsx +20 -0
  202. package/src/serve/hub-app/hub-app.tsx +48 -32
  203. package/src/serve/hub-app/hub-types.ts +2 -0
  204. package/src/serve/hub-app/hub.css +50 -61
  205. package/src/serve/hub-app/icons.tsx +14 -4
  206. package/src/serve/hub-app/identities-view.tsx +4 -3
  207. package/src/serve/hub-app/inbox-st.ts +203 -42
  208. package/src/serve/hub-app/inbox-view.tsx +189 -101
  209. package/src/serve/hub-app/inbox.css +47 -44
  210. package/src/serve/hub-app/index.html +3 -0
  211. package/src/serve/hub-app/instructions.css +30 -0
  212. package/src/serve/hub-app/keys.ts +5 -3
  213. package/src/serve/hub-app/machine-st.ts +2 -2
  214. package/src/serve/hub-app/machines-view.tsx +4 -11
  215. package/src/serve/hub-app/machines.css +0 -9
  216. package/src/serve/hub-app/markdown.css +51 -0
  217. package/src/serve/hub-app/md-copy.tsx +18 -40
  218. package/src/serve/hub-app/md.ts +25 -9
  219. package/src/serve/hub-app/media-view.tsx +2 -2
  220. package/src/serve/hub-app/messages/messages-page.tsx +2 -1
  221. package/src/serve/hub-app/messages/messages-st.ts +1 -1
  222. package/src/serve/hub-app/messages.css +0 -1
  223. package/src/serve/hub-app/objects.css +51 -0
  224. package/src/serve/hub-app/page-keys.ts +1 -1
  225. package/src/serve/hub-app/pages-frames.tsx +11 -1
  226. package/src/serve/hub-app/palette-st.ts +4 -4
  227. package/src/serve/hub-app/pane-boundary.tsx +72 -0
  228. package/src/serve/hub-app/pane-errors.ts +54 -0
  229. package/src/serve/hub-app/plan-view.tsx +3 -2
  230. package/src/serve/hub-app/planned-view.tsx +3 -3
  231. package/src/serve/hub-app/planned.css +0 -4
  232. package/src/serve/hub-app/processes-view.tsx +3 -2
  233. package/src/serve/hub-app/project-list.css +5 -13
  234. package/src/serve/hub-app/project-list.tsx +3 -6
  235. package/src/serve/hub-app/projects-svc.ts +6 -2
  236. package/src/serve/hub-app/readme.css +9 -15
  237. package/src/serve/hub-app/reflections-page.tsx +54 -1
  238. package/src/serve/hub-app/releases/releases-page.tsx +3 -2
  239. package/src/serve/hub-app/releases.css +0 -1
  240. package/src/serve/hub-app/review/code-colors.ts +30 -0
  241. package/src/serve/hub-app/review/diff-view.tsx +75 -0
  242. package/src/serve/hub-app/review/dock.tsx +104 -0
  243. package/src/serve/hub-app/review/draft-card.tsx +2 -2
  244. package/src/serve/hub-app/review/group-block.tsx +209 -0
  245. package/src/serve/hub-app/review/instructions-view.tsx +116 -0
  246. package/src/serve/hub-app/review/item-verdict.tsx +38 -0
  247. package/src/serve/hub-app/review/kind-states.tsx +193 -0
  248. package/src/serve/hub-app/review/kind-view.tsx +1 -37
  249. package/src/serve/hub-app/review/kit.tsx +57 -54
  250. package/src/serve/hub-app/review/lane-bar.tsx +64 -0
  251. package/src/serve/hub-app/review/object-card.tsx +62 -0
  252. package/src/serve/hub-app/review/object-panel.tsx +179 -0
  253. package/src/serve/hub-app/review/question-views.tsx +385 -0
  254. package/src/serve/hub-app/review/review-cells.tsx +86 -105
  255. package/src/serve/hub-app/review/review-list.tsx +104 -47
  256. package/src/serve/hub-app/review/review-page.tsx +5 -4
  257. package/src/serve/hub-app/review/review-st.ts +68 -28
  258. package/src/serve/hub-app/review/review-thread.tsx +171 -40
  259. package/src/serve/hub-app/review/review-views.tsx +35 -31
  260. package/src/serve/hub-app/review/thread-close.tsx +124 -0
  261. package/src/serve/hub-app/review/thread-control.tsx +4 -4
  262. package/src/serve/hub-app/review/thread-st.ts +222 -22
  263. package/src/serve/hub-app/review/trailer-card.tsx +1 -1
  264. package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
  265. package/src/serve/hub-app/review.css +216 -57
  266. package/src/serve/hub-app/section-head.tsx +51 -0
  267. package/src/serve/hub-app/social/calendar.tsx +5 -11
  268. package/src/serve/hub-app/social/comms-page.tsx +23 -10
  269. package/src/serve/hub-app/social/kit.tsx +8 -15
  270. package/src/serve/hub-app/social/next-release.tsx +3 -5
  271. package/src/serve/hub-app/social/post-card.tsx +3 -0
  272. package/src/serve/hub-app/social/post-page.tsx +80 -0
  273. package/src/serve/hub-app/social/problems.tsx +5 -9
  274. package/src/serve/hub-app/social/social-model.ts +13 -5
  275. package/src/serve/hub-app/social/social-page.tsx +1 -1
  276. package/src/serve/hub-app/social/social-st.ts +42 -5
  277. package/src/serve/hub-app/social.css +7 -17
  278. package/src/serve/hub-app/space.css +1 -1
  279. package/src/serve/hub-app/stores/stores-page.tsx +6 -2
  280. package/src/serve/hub-app/thread-row.tsx +101 -0
  281. package/src/serve/hub-app/time-ago.tsx +3 -2
  282. package/src/serve/hub-app/time-view.tsx +2 -1
  283. package/src/serve/hub-app/time.css +2 -5
  284. package/src/serve/hub-app/tree-row.tsx +1 -9
  285. package/src/serve/hub-app/vault-view.tsx +4 -4
  286. package/src/serve/hub-app/veille/veille-page.tsx +2 -11
  287. package/src/serve/hub-app/veille.css +0 -1
  288. package/src/serve/hub-app/waiting-svc.ts +4 -4
  289. package/src/serve/hub-app/when-view.tsx +6 -3
  290. package/src/serve/hub-app/wiki-st.ts +30 -4
  291. package/src/serve/hub-app/wikis-view.tsx +4 -3
  292. package/src/serve/hub-runtime.ts +20 -6
  293. package/src/serve/project-gutter-route.ts +16 -6
  294. package/src/serve/project-gutter.ts +6 -53
  295. package/src/serve/same-origin.ts +3 -0
  296. package/src/serve/secret-gate.ts +21 -0
  297. package/src/serve/serve-hub.ts +29 -20
  298. package/src/serve/tailnet-caller.ts +117 -0
  299. package/src/shipkit.ts +2 -2
  300. package/src/site/desk.ts +2 -2
  301. package/src/smoke/run-smoke.ts +3 -4
  302. package/src/social/brands.ts +4 -0
  303. package/src/social/card-drafts.ts +11 -19
  304. package/src/social/desk-index.ts +34 -13
  305. package/src/social/drafts.ts +4 -4
  306. package/src/social/import-drafts.ts +244 -0
  307. package/src/social/kind-pages.ts +3 -3
  308. package/src/social/kinds.ts +1 -1
  309. package/src/social/load.ts +89 -64
  310. package/src/social/media-kind.ts +68 -161
  311. package/src/social/media-of.ts +5 -4
  312. package/src/social/open.ts +3 -2
  313. package/src/social/post-object.ts +120 -0
  314. package/src/social/post-sources.ts +136 -0
  315. package/src/social/post-text.ts +103 -0
  316. package/src/social/posts.ts +378 -0
  317. package/src/social/presence.ts +7 -5
  318. package/src/social/publish/index.ts +17 -5
  319. package/src/social/publish/secret.ts +2 -2
  320. package/src/social/release-stage.ts +58 -57
  321. package/src/social/routes.ts +64 -24
  322. package/src/social/stage.ts +42 -57
  323. package/src/social/text.ts +4 -3
  324. package/src/social/thumbnail.ts +135 -43
  325. package/src/social/tracker.ts +1 -1
  326. package/src/social/writes.ts +12 -29
  327. package/src/stores/desk.ts +16 -11
  328. package/src/stores/unit.ts +2 -2
  329. package/src/trailer/sound/eleven.ts +33 -3
  330. package/src/urls/rows.ts +1 -1
  331. package/src/vault/vault-http.ts +11 -3
  332. package/src/vault/vault-import.ts +6 -1
  333. package/src/veille/identity.ts +2 -2
  334. package/src/wiki/graph-pages.ts +13 -1
  335. package/src/wiki/scan-md.ts +1 -1
  336. package/src/asks/asks-queue.ts +0 -424
  337. package/src/messages/suggest.ts +0 -96
  338. package/src/social/migrate.ts +0 -123
@@ -0,0 +1,61 @@
1
+ // a kind's apply, run where the owner's answer is written (wiki tools/shipkit/threads-how-it-fits.md, Kinds): the owner's approve of a
2
+ // version that holds an object's states, and the owner's apply of one field of a proposed change on an object's address. The
3
+ // one landing path for both: the kind's `apply`, never a writer of its own. Its outcome is a line in the thread,
4
+ // « landed » or « not landed » with the reason, so a refusal is never silent and the owner's answer stands either way
5
+ import { serverKindOf } from './house-kind-defs.ts'
6
+ import { proposeFields, type Message } from './model.ts'
7
+ import { appendMessage, readItem } from './store.ts'
8
+ import { sameJson, type ObjectState, type ReviewUnit } from './unit.ts'
9
+
10
+ const MACHINE = 'machine'
11
+ const splitAddress = (on: string): { word: string; key: string } => ({ word: on.slice(0, on.indexOf(':')), key: on.slice(on.indexOf(':') + 1) })
12
+
13
+ /** the outcome said in the thread: what landed and where, or why not */
14
+ function say(dir: string, id: string, text: string): Message {
15
+ return appendMessage(dir, id, { who: MACHINE, text }, { machine: true })
16
+ }
17
+
18
+ /** after the owner's verdict on item `id`: when it approves a version of an object whose kind applies, the after state lands */
19
+ export async function applyOnVerdict(root: string, dir: string, unit: Pick<ReviewUnit, 'kinds'> | null, id: string, status: unknown): Promise<string | null> {
20
+ if (status !== 'approved') return null
21
+ const x = readItem(dir, id)
22
+ const on = x?.item.on
23
+ const states = x?.item.states
24
+ if (!x || !on || !states) return null
25
+ const { word, key } = splitAddress(on)
26
+ const kind = serverKindOf(root, unit, word)
27
+ if (!kind?.apply) return null
28
+ try {
29
+ await kind.apply(key, states.after as ObjectState, states.before as ObjectState | undefined)
30
+ return say(dir, id, `landed ${on}: written by its kind's apply; the agent that holds this thread commits the file`).text ?? null
31
+ } catch (e) {
32
+ return say(dir, id, `not landed ${on}: ${(e as Error).message}. The owner's approval stands: fix the cause and post it again from what the store says now`).text ?? null
33
+ }
34
+ }
35
+
36
+ /** after the owner's apply of a field of the proposed change `re` on item `id`: that field set on the object as it is now,
37
+ * refused when the field no longer says what the change read as its before */
38
+ export async function applyOnAnswer(root: string, dir: string, unit: Pick<ReviewUnit, 'kinds'> | null, id: string, answer: Message): Promise<string | null> {
39
+ if (answer.answer?.apply !== true || answer.re === undefined) return null
40
+ const x = readItem(dir, id)
41
+ const m = x?.thread.find((y) => y.id === answer.re)
42
+ if (!x || !m?.propose) return null
43
+ const on = m.propose.on
44
+ const { word, key } = splitAddress(on)
45
+ const kind = serverKindOf(root, unit, word)
46
+ if (!kind?.apply || !kind.read) return null
47
+ const fields = proposeFields(m.propose)
48
+ const f = answer.answer.field !== undefined ? fields.find((y) => y.key === answer.answer!.field) : fields.length === 1 ? fields[0] : undefined
49
+ if (!f) return null
50
+ const label = f.key || 'the value'
51
+ try {
52
+ const now = await kind.read(key)
53
+ if (now == null) throw new Error(`no ${on} to change`)
54
+ const set = kind.field ?? ((s: ObjectState, k: string, v: string): ObjectState => ({ ...s, json: { ...(s.json as object), [k]: v } }))
55
+ if (f.before !== undefined && !sameJson(set(now, f.key, f.before).json, now.json)) throw new Error(`${label} no longer says what the change read; propose it again from what it says now`)
56
+ await kind.apply(key, set(now, f.key, answer.answer.value ?? f.after), now)
57
+ return say(dir, id, `landed ${label} of ${on}: written by its kind's apply; the agent that holds this thread commits the file`).text ?? null
58
+ } catch (e) {
59
+ return say(dir, id, `not landed ${label} of ${on}: ${(e as Error).message}. The owner's apply stands: propose it again from what the store says now`).text ?? null
60
+ }
61
+ }
@@ -0,0 +1,96 @@
1
+ // the always loaded catalog of what can show up in a thread (wiki tools/shipkit/thread-kinds.md): the house kinds, the
2
+ // answer kinds of a question, the value kinds of a proposed change, each with the widget he sees, rendered from their
3
+ // registries by `sk thread kinds --out`; RV037 keeps the page equal to it. Pure: no store, no repo
4
+ import { glyphSvg, hueHex, KIND_HUES, MESSAGE_TYPES, type MessageType } from './glyphs.ts'
5
+ import { DIFF_TYPES, HOUSE_KINDS, kindOfValue, type HouseKind, type ValueKind } from './kinds.ts'
6
+ import { ANSWER_KINDS, type AnswerKind } from './model.ts'
7
+
8
+ export const BEGIN = '<!-- shipkit:thread-kinds -->'
9
+ export const END = '<!-- /shipkit:thread-kinds -->'
10
+
11
+ /** what each answer kind of a question draws for him and the `sk thread ask` flag that asks it, null while no flag does */
12
+ export const ANSWER_WIDGETS: Record<AnswerKind, { shows: string; flag: string | null }> = {
13
+ choice: { shows: 'the options side by side, each its media over one button, your pick a pill', flag: '--option "<label>=<file>" … --pick <n>' },
14
+ checklist: { shows: 'a line a step, he ticks each over days', flag: '--checklist "<step>" …' },
15
+ confirm: { shows: 'one step in the real world, he answers « done »', flag: '--confirm' },
16
+ text: { shows: 'a value he types', flag: '--text' },
17
+ url: { shows: 'a link he pastes, opened once to say its status', flag: '--url' },
18
+ secret: { shows: 'a field into the vault, the thread keeps « stored as <name> »', flag: '--secret <name> [--login]' },
19
+ file: { shows: 'a file he drops', flag: null },
20
+ }
21
+
22
+ /** what is wrong with a house kind's widget words: none, or one line each. A kind he cannot see is a defect */
23
+ export function kindWidgetProblems(word: string, k: Pick<HouseKind, 'address' | 'example'> & { shows?: string }): string[] {
24
+ const out: string[] = []
25
+ if ((k.shows ?? '').trim() === '') out.push(`${word}: no widget: say what he sees of it (shows)`)
26
+ if (k.address !== undefined && (k.example ?? '').trim() === '') out.push(`${word}: an object kind gives one command an agent types (example)`)
27
+ if (k.example !== undefined && !k.example.startsWith('sk ')) out.push(`${word}: its example is a command, starting with sk`)
28
+ return out
29
+ }
30
+
31
+ /** what is wrong with an answer kind's widget words */
32
+ export function answerWidgetProblems(word: string, w: { shows?: string; flag?: string | null } | undefined): string[] {
33
+ if (w === undefined || (w.shows ?? '').trim() === '') return [`${word}: an answer kind with no widget: say what he sees (ANSWER_WIDGETS)`]
34
+ return []
35
+ }
36
+
37
+ const DIFF_WORDS: Record<ValueKind['diff'], string> = { words: 'a word diff', swatches: 'two swatches', hunk: 'a hunk in syntax colours', media: 'the two files, A and B' }
38
+ const EDIT_WORDS: Record<NonNullable<ValueKind['edit']>, string> = { text: 'he edits the words', color: 'a colour picker', code: 'he edits the code' }
39
+
40
+ /** every problem of the registries the catalog renders */
41
+ export function catalogProblems(kinds: Record<string, HouseKind> = HOUSE_KINDS, answers: Partial<Record<AnswerKind, { shows: string; flag: string | null }>> = ANSWER_WIDGETS): string[] {
42
+ return [...Object.entries(kinds).flatMap(([w, k]) => kindWidgetProblems(w, k)), ...ANSWER_KINDS.flatMap((w) => answerWidgetProblems(w, answers[w]))]
43
+ }
44
+
45
+ /** the generated block: one line an object kind, an answer kind an agent can ask, a value kind's widget. A subject kind
46
+ * with no address is the machine's word, never typed, so it stays out */
47
+ export function renderCatalog(kinds: Record<string, HouseKind> = HOUSE_KINDS): string {
48
+ const out = ['### Objects: the subject of a thread, `<kind>:<key>`', '']
49
+ for (const [w, k] of Object.entries(kinds)) if (k.address !== undefined) out.push(`- \`${w}:${k.address}\` ${k.shows}. \`${k.example}\``)
50
+ out.push('', '### A question he answers: `sk thread ask <address> "<question>"` and one of', '')
51
+ for (const w of ANSWER_KINDS) {
52
+ const a = ANSWER_WIDGETS[w]
53
+ if (a.flag !== null) out.push(`- \`${w}\` \`${a.flag}\`: ${a.shows}`)
54
+ }
55
+ out.push('', '### A field of a proposed change: `sk thread propose <address> [--type <kind>]`, else read from the values', '')
56
+ const lines = new Map<string, string[]>()
57
+ for (const t of DIFF_TYPES) {
58
+ const v = kindOfValue(t)
59
+ const words = `${DIFF_WORDS[v.diff]}${v.edit === null ? '' : `, ${EDIT_WORDS[v.edit]}`}`
60
+ lines.set(words, [...(lines.get(words) ?? []), t === 'code' ? 'code[:<lang>]' : t])
61
+ }
62
+ for (const [words, ts] of lines) out.push(`- ${ts.map((t) => `\`${t}\``).join(', ')}: ${words}`)
63
+ return out.join('\n')
64
+ }
65
+
66
+ export const OBJECTS_BEGIN = '<!-- shipkit:thread-objects -->'
67
+ export const OBJECTS_END = '<!-- /shipkit:thread-objects -->'
68
+
69
+ /** a message type's icon colour in a file: the muted grey the hub draws it in */
70
+ const MESSAGE_GREY = '#8b8f98'
71
+
72
+ const cell = (s: string): string => s.replaceAll('|', '\\|')
73
+
74
+ /** the objects page (wiki tools/shipkit/thread-objects.md): every kind, value kind and message type of a thread with
75
+ * its icon in its colour, what he sees and one command, as one markdown table each; `icons` is the folder of the SVG
76
+ * files, from the page (a topic's `references/`), each drawn by an img tag: a picture, never a markdown link (RV022). `files`: each icon's file, by its name in that folder */
77
+ export function renderObjects(icons: string, kinds: Record<string, HouseKind> = HOUSE_KINDS): { md: string; files: Record<string, string> } {
78
+ const files: Record<string, string> = {}
79
+ const icon = (name: string, word: string, d: string, color: string): string => {
80
+ files[`${name}.svg`] = glyphSvg(d, color)
81
+ return `<img src="${icons}/${name}.svg" alt="${word}" width="20" height="20">`
82
+ }
83
+ const kindIcon = (w: string, k: HouseKind): string => icon(`kind-${w}`, w, k.icon, hueHex(KIND_HUES[k.color]))
84
+ const out = ['### Objects: the subject of a thread, `<kind>:<key>`', '', '| | kind | what he sees | one command |', '|---|---|---|---|']
85
+ for (const [w, k] of Object.entries(kinds)) if (k.address !== undefined) out.push(`| ${kindIcon(w, k)} | \`${w}:${cell(k.address)}\` ${k.label} | ${cell(k.shows)} | \`${cell(k.example ?? '')}\` |`)
86
+ out.push('', "### Subjects only: a version's subject, never an address", '', '| | kind | what he sees |', '|---|---|---|')
87
+ for (const [w, k] of Object.entries(kinds)) if (k.address === undefined) out.push(`| ${kindIcon(w, k)} | \`${w}\` ${k.label} | ${cell(k.shows)} |`)
88
+ out.push('', '### Values: what a field of a proposed change holds, `--type <kind>`', '', '| | kind | what he sees |', '|---|---|---|')
89
+ for (const t of DIFF_TYPES) {
90
+ const v = kindOfValue(t)
91
+ out.push(`| ${icon(`value-${t}`, t, v.icon, hueHex(KIND_HUES[v.color]))} | \`${t}\` ${v.label} | ${DIFF_WORDS[v.diff]}${v.edit === null ? '' : `, ${EDIT_WORDS[v.edit]}`} |`)
92
+ }
93
+ out.push('', '### Messages: what a thread holds, each with its icon at its head', '', '| | type | what it is |', '|---|---|---|')
94
+ for (const [t, m] of Object.entries(MESSAGE_TYPES) as [MessageType, (typeof MESSAGE_TYPES)[MessageType]][]) out.push(`| ${icon(`message-${t}`, t, m.icon, MESSAGE_GREY)} | ${m.label} | ${cell(m.shows)} |`)
95
+ return { md: out.join('\n'), files }
96
+ }
@@ -0,0 +1,278 @@
1
+ // the house kinds (wiki tools/shipkit/threads-how-it-fits.md, Kinds), the one registry: each declared with the SpecKind a
2
+ // repo's `review({ kinds })` uses for its own, never a case in the hub. An object kind names objects by its `address`
3
+ // (`screen:orders/list`, `file:README.md`); a subject kind with none only types a version's subject. The value kinds,
4
+ // what a field of a proposed change holds, are the house's alone: their own type below, never on a repo's declaration
5
+ import type { KindColor } from './glyphs.ts'
6
+ import type { Spec, SpecKind } from './model.ts'
7
+
8
+ /** a house kind: the one declaration, plus the words the always loaded catalog prints (wiki tools/shipkit/thread-kinds.md,
9
+ * `sk thread kinds --out`); the hub draws a house kind with its own cells, so `shows` names that widget */
10
+ export interface HouseKind extends SpecKind {
11
+ /** its icon's colour, one hue of review/glyphs.ts KIND_HUES, its own among the house kinds */
12
+ color: KindColor
13
+ /** its icon: SVG path data on the hub's 20 unit grid, one stroke in the text colour (review/glyphs.ts); a repo's
14
+ * kind may leave it out and draws the neutral default */
15
+ icon: string
16
+ /** what the owner sees of an object of this kind in a thread, and how he answers it */
17
+ shows: string
18
+ /** one command an agent types on it; every object kind (an `address`) gives one */
19
+ example?: string
20
+ }
21
+
22
+ /** every kind a repo has without declaring it; a repo's kind of the same word wins in that repo */
23
+ export const HOUSE_KINDS: Record<string, HouseKind> = {
24
+ shot: {
25
+ label: 'images',
26
+ icon: 'M2.5 6.5h3l1.5-2h6l1.5 2h3v9.5h-15zM10 8.5a3 3 0 1 0 0 6a3 3 0 1 0 0-6',
27
+ color: 'azure',
28
+ shows: "a version's media with no address of its own (the default subject)",
29
+ },
30
+ frame: {
31
+ label: 'trailer frames',
32
+ icon: 'M3 4.5h14v11H3zM6.5 4.5v11M13.5 4.5v11M3 8h3.5M3 12h3.5M13.5 8H17M13.5 12H17',
33
+ color: 'rose',
34
+ shows: 'a note on a frame of a cut, in the thread of its cut',
35
+ },
36
+ post: {
37
+ label: 'post requests',
38
+ icon: 'M3 8h3l8-4v12l-8-4H3zM6 12l1.5 4.5',
39
+ color: 'vermilion',
40
+ shows: 'a retired post request, kept for its old items',
41
+ },
42
+ object: {
43
+ label: 'objects',
44
+ icon: 'M3 7.5 10 4l7 3.5v5L10 16l-7-3.5zM3 7.5 10 11l7-3.5M10 11v5',
45
+ color: 'indigo',
46
+ shows: 'a thread opened with words on an address',
47
+ },
48
+ screen: {
49
+ label: 'screens',
50
+ icon: 'M3 4h14v9H3zM7 16.5h6M10 13v3.5',
51
+ color: 'blue',
52
+ address: '<screen>[/<part>]',
53
+ shows: 'pictures of a screen: one, a before and after, a gallery; a verdict, rectangles, words',
54
+ example: 'sk thread post screen:orders/list --title "…" --what "…" --before a.png --after b.png',
55
+ },
56
+ asset: {
57
+ label: 'assets',
58
+ icon: 'M6 3.5h8l3.5 4.5L10 16.5 2.5 8zM2.5 8h15M7.5 8 10 16.5 12.5 8',
59
+ color: 'teal',
60
+ address: '<asset>',
61
+ shows: 'a sprite, an icon, a logo: a version, or candidates side by side he picks one of',
62
+ example: 'sk thread ask asset:logo "which logo ?" --option "round=a.png" --option "square=b.png" --pick 2',
63
+ },
64
+ file: {
65
+ label: 'files',
66
+ icon: 'M5 2.5h7l3 3v12H5zM12 2.5v3h3M8.5 10l-1.75 1.75L8.5 13.5M11.5 10l1.75 1.75-1.75 1.75',
67
+ color: 'leaf',
68
+ address: '<repo relative path>',
69
+ shows: 'a change of a repo file as a word or code diff he applies, or edits first',
70
+ example: 'sk thread propose file:README.md --before "<old>" --after "<new>" "<why>"',
71
+ },
72
+ page: {
73
+ label: 'hub pages',
74
+ icon: 'M2.5 4h15v12h-15zM2.5 7.5h15M5 5.75h.01M7 5.75h.01',
75
+ color: 'sky',
76
+ address: '<page>[/<part>]',
77
+ shows: "a hub page: its shots as versions; a 💬 note from the page lands here",
78
+ example: 'sk thread post page:threads --title "…" --what "…" --image shot.webp',
79
+ },
80
+ trailer: {
81
+ label: 'trailers',
82
+ icon: 'M2.5 4.5h15v11h-15zM2.5 8.5h15M6 4.5 7.5 8.5M10 4.5l1.5 4M14 4.5l1.5 4',
83
+ color: 'red',
84
+ address: '<trailer>/<cut>[/<shot>]',
85
+ shows: "the cut's player: timeline, shots, its render against a before; rectangles on paused frames",
86
+ example: 'sk thread post --trailer trailer/<name>/<cut>.trailer --title "…" --what "…"',
87
+ },
88
+ draft: {
89
+ label: 'post drafts',
90
+ icon: 'M3.5 4.5h9M3.5 8h6M3.5 11.5H7M9.5 16.5V14l6-6 2.5 2.5-6 6z',
91
+ color: 'chartreuse',
92
+ address: '<slug>[/<place>]',
93
+ shows: 'each place of the post as the platform gets it; OK, fix or no a place',
94
+ example: 'sk thread post --draft <slug> --title "…" --what "…"',
95
+ },
96
+ store: {
97
+ label: 'store pages',
98
+ icon: 'M3 4h14l1 4H2zM2 8c0 1.4 1.3 2.5 2.7 2.5S7.3 9.4 7.3 8c0 1.4 1.3 2.5 2.7 2.5S12.7 9.4 12.7 8c0 1.4 1.3 2.5 2.7 2.5S18 9.4 18 8M4 10.5V17h12v-6.5M8 17v-4h4v4',
99
+ color: 'jade',
100
+ address: '<store>/<asset>',
101
+ shows: "a store page's picture or field: a version, or a change of its words",
102
+ example: 'sk thread post store:steam/capsule --title "…" --what "…" --before a.png --after b.png',
103
+ },
104
+ // the messages store's objects: read from its md, written back by their apply (review/house-kind-defs.ts)
105
+ messages: {
106
+ label: 'value propositions',
107
+ icon: 'M3 4.5h14v9H8l-4 3v-3H3zM6 8h8M6 10.5h5',
108
+ color: 'orange',
109
+ address: '<message>[/<phrasing>]',
110
+ shows: 'a value proposition (a message) or a phrasing as a card, scored; a new one he approves, reworks or rejects, and his approval writes it into messages.md; a rephrasing is `sk thread propose`',
111
+ example: 'sk messages propose message <id> --title "…" --meaning "…" --value "…" "<why>"',
112
+ },
113
+ persona: {
114
+ label: 'personas',
115
+ icon: 'M10 9a3 3 0 1 0 0-6a3 3 0 1 0 0 6M4 17c0-3.3 2.7-5.5 6-5.5s6 2.2 6 5.5',
116
+ color: 'lime',
117
+ address: '<persona>',
118
+ shows: 'a persona of the messages store as a card; a new one he approves, reworks or rejects, and his approval writes it into personas.md',
119
+ example: 'sk messages propose persona <id> --role reader --who "…" "<why>"',
120
+ },
121
+ surface: {
122
+ label: 'page tops',
123
+ icon: 'M2.5 3.5h15v13h-15zM5 6.5h10M5 9h6M5 12.5h4.5v2H5z',
124
+ color: 'cobalt',
125
+ address: '<surface>[/<option>]',
126
+ shows: 'a page top of the messages store or one option as a card, scored; a new option he approves, reworks or rejects, and his approval writes it into surfaces.md',
127
+ example: 'sk messages propose option <surface> --headline "…" --line "…" "<why>"',
128
+ },
129
+ media: {
130
+ label: 'media',
131
+ icon: 'M3 4h14v12H3zM8.5 7.5v5l4-2.5z',
132
+ color: 'cyan',
133
+ address: '<id>',
134
+ shows: 'a link line to its page; to show the file itself, post it as a version',
135
+ example: 'sk thread attach <thread> media:<id>',
136
+ },
137
+ release: {
138
+ label: 'releases',
139
+ icon: 'M3 3.5h7l7 7-6.5 6.5-7-7zM6.5 6.5h.01',
140
+ color: 'emerald',
141
+ address: '<version>',
142
+ shows: 'words on a release and the verdict on them; its changes stay on its page',
143
+ example: 'sk thread post release:<version> --title "…" --what "…" --verdict',
144
+ },
145
+ ask: {
146
+ label: 'asks',
147
+ icon: 'M6.5 3h7v2.5h-7zM6.5 4.25H4.5v13h11v-13h-2M7.5 10.5 9 12l3.5-3.5M7.5 15h5',
148
+ color: 'yellow',
149
+ address: '<id>',
150
+ shows: 'an act only he can do: its why, its steps he ticks, a secret field, its proof',
151
+ example: 'sk ask "<title>" --why "<line>" --body steps.md',
152
+ },
153
+ check: {
154
+ label: 'checks',
155
+ icon: 'M10 2.5 16 5v4.5c0 4-2.7 6.5-6 8c-3.3-1.5-6-4-6-8V5zM7.5 10l2 2 3.5-3.5',
156
+ color: 'green',
157
+ address: '<repo>/<id>',
158
+ shows: "opened by the machine on a red check: its lines, then broken and fixed; an agent's to fix",
159
+ example: 'sk thread take check:<repo>/<id>',
160
+ },
161
+ // attached to a thread, it holds it open until merged; its check runs server side (review/branch-hold.ts)
162
+ branch: {
163
+ label: 'branches',
164
+ icon: 'M6 5v10M6 3a2 2 0 1 0 0 .01M6 17a2 2 0 1 0 0 .01M14 5a2 2 0 1 0 0 .01M14 7c0 4.5-8 3.5-8 7',
165
+ color: 'violet',
166
+ address: '<repo>/<name>',
167
+ holdsOpen: { until: 'merged into its release branch', move: 'owner' },
168
+ shows: 'holds its thread open until merged: ahead and behind, its last commit, the diff',
169
+ example: 'sk thread attach <thread> branch:<repo>/<name>',
170
+ },
171
+ // an object read from its file (review/reflection-object.ts), linked into the thread where it was written: a card
172
+ // with these three (wiki tools/shipkit/threads-how-it-fits.md, The model)
173
+ reflection: {
174
+ label: 'reflections',
175
+ icon: 'M7.5 14h5M8 16.5h4M10 2.5a5 5 0 0 0-3 9c.5.4.5 1 .5 2.5h5c0-1.5 0-2.1.5-2.5a5 5 0 0 0-3-9z',
176
+ color: 'amber',
177
+ address: '<repo>/<file>',
178
+ shows: 'an object read from its file, a card where an agent linked it: its title and one line, its words whole in the object panel; accept, ask to rework, discard',
179
+ example: 'sk thread reflect "<title>" --body <file | ->',
180
+ actions: {
181
+ accept: { label: 'accept', icon: '✓', what: 'it goes to the owner of the rule it proposes: the agent that wrote it hands it over' },
182
+ rework: { label: 'ask to rework', icon: '↻', words: true, what: 'your words go to the agent that wrote it: it rewrites the reflection and says so here' },
183
+ discard: { label: 'discard', icon: '✕', what: 'the agent deletes its file: its card folds' },
184
+ },
185
+ },
186
+ }
187
+
188
+ /** a house value kind: what a field of a proposed change holds, how it is sniffed, drawn and edited */
189
+ export interface ValueKind {
190
+ label: string
191
+ /** its icon: path data on the hub's 20 unit grid (review/glyphs.ts) */
192
+ icon: string
193
+ /** its icon's colour, one of the kind hues */
194
+ color: KindColor
195
+ /** a value read as this kind when nothing names one; the first kind that takes both sides wins */
196
+ sniff?(v: string): boolean
197
+ /** the hub's view of two values: a word diff, two swatches, a hunk in syntax colours, the store's view of two files */
198
+ diff: 'words' | 'swatches' | 'hunk' | 'media'
199
+ /** how the owner changes the value before applying it; null: as it is */
200
+ edit: 'text' | 'color' | 'code' | null
201
+ /** its values are files: the store keeps them as one view the message holds, a pair when there is a before */
202
+ file?: true
203
+ }
204
+
205
+ const ext = (re: RegExp) => (v: string) => re.test(v.trim())
206
+
207
+ /** the house value kinds, in the order a value is sniffed */
208
+ const VALUES = {
209
+ color: { label: 'colour', icon: 'M10 2.5S4.5 8.5 4.5 12a5.5 5.5 0 0 0 11 0c0-3.5-5.5-9.5-5.5-9.5z', color: 'pink', sniff: ext(/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i), diff: 'swatches', edit: 'color' },
210
+ sound: { label: 'sound', icon: 'M3 8h3l4-3.5v11L6 12H3zM13 7.5a3.5 3.5 0 0 1 0 5M15.5 5a7 7 0 0 1 0 10', color: 'magenta', sniff: ext(/\.(wav|mp3|flac|ogg|opus|m4a)$/i), diff: 'media', edit: null, file: true },
211
+ image: { label: 'picture', icon: 'M3 4h14v12H3zM3 13l4-4 4 4 2-2 4 4M13 7.5h.01', color: 'plum', sniff: ext(/\.(png|jpe?g|webp|gif)$/i), diff: 'media', edit: null, file: true },
212
+ clip: { label: 'clip', icon: 'M2.5 6h10.5v8H2.5zM13 8.5l4.5-2.5v8L13 11.5', color: 'purple', sniff: ext(/\.(mp4|webm|mov)$/i), diff: 'media', edit: null, file: true },
213
+ code: { label: 'code', icon: 'M7 6 3 10l4 4M13 6l4 4-4 4M11 4.5 9 15.5', color: 'indigo', diff: 'hunk', edit: 'code' },
214
+ text: { label: 'words', icon: 'M4 4.5h12M10 4.5v11M7.5 15.5h5', color: 'cobalt', diff: 'words', edit: 'text' },
215
+ } as const satisfies Record<string, ValueKind>
216
+
217
+ /** a house value kind's name: what `--type` takes */
218
+ export type DiffType = keyof typeof VALUES
219
+ export const DIFF_TYPES = Object.keys(VALUES) as DiffType[]
220
+
221
+ export const kindOfValue = (t: DiffType | undefined): ValueKind => VALUES[t ?? 'text']
222
+
223
+ /** a field's declared kind, as `diff.fields` and `--type` write it: a house value kind, `code:<lang>` for code */
224
+ export function valueKindOf(word: string): { type: DiffType; lang?: string } | null {
225
+ const [t, lang] = word.split(':', 2)
226
+ if (!DIFF_TYPES.includes(t as DiffType)) return null
227
+ if (lang !== undefined && (t !== 'code' || lang === '')) return null
228
+ return { type: t as DiffType, ...(lang ? { lang } : {}) }
229
+ }
230
+
231
+ /** the kind of a field when nothing names it: the first house value kind that takes its values, words otherwise */
232
+ export function sniffKind(f: { before?: string; after: string }): DiffType {
233
+ const both = [f.after, ...(f.before !== undefined ? [f.before] : [])]
234
+ for (const t of DIFF_TYPES) {
235
+ const sniff = (VALUES[t] as ValueKind).sniff
236
+ if (sniff && both.every((v) => sniff(v))) return t
237
+ }
238
+ return 'text'
239
+ }
240
+
241
+ /** one kind by its word: the repo's own first, then the house's */
242
+ export const kindOf = (word: string, spec: Spec): SpecKind | undefined => spec.kinds[word] ?? HOUSE_KINDS[word]
243
+
244
+ /** the kinds a thread's address may name in this repo: the repo's own that name objects (an `address`, the house
245
+ * shape of their word, or a `key`), then the house's object kinds the repo does not replace */
246
+ export function addressKinds(spec: Spec): { word: string; label: string; address: string; own: boolean }[] {
247
+ const own = Object.entries(spec.kinds).flatMap(([word, k]) => {
248
+ const address = k.address ?? HOUSE_KINDS[word]?.address ?? (k.key ? '<key>' : undefined)
249
+ return address === undefined ? [] : [{ word, label: k.label, address, own: true }]
250
+ })
251
+ const house = Object.entries(HOUSE_KINDS).flatMap(([word, k]) => (k.address !== undefined && !(word in spec.kinds) ? [{ word, label: k.label, address: k.address, own: false }] : []))
252
+ return [...own, ...house]
253
+ }
254
+
255
+ /** how far two words are apart: the edits that turn one into the other */
256
+ function distance(a: string, b: string): number {
257
+ const row = Array.from({ length: b.length + 1 }, (_, j) => j)
258
+ for (let i = 1; i <= a.length; i++) {
259
+ let prev = row[0]!
260
+ row[0] = i
261
+ for (let j = 1; j <= b.length; j++) {
262
+ const here = row[j]!
263
+ row[j] = Math.min(row[j]! + 1, row[j - 1]! + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1))
264
+ prev = here
265
+ }
266
+ }
267
+ return row[b.length]!
268
+ }
269
+
270
+ /** why an agent may not start a thread or a link on an address whose kind word no kind declares, or null: two words
271
+ * for one subject would make two threads, so a word is a declared kind or none */
272
+ export function addressKindProblem(address: string, spec: Spec): string | null {
273
+ const word = address.slice(0, address.indexOf(':'))
274
+ const kinds = addressKinds(spec)
275
+ if (kinds.some((k) => k.word === word)) return null
276
+ const near = [...kinds].sort((a, b) => distance(word, a.word) - distance(word, b.word)).slice(0, 3)
277
+ return `${word}: no kind of this repo names objects by that word, so a thread on it would never be found again by another word: ${near.map((k) => `${k.word}:${k.address}`).join(', ')}, or another of sk thread kinds`
278
+ }
@@ -0,0 +1,109 @@
1
+ // a lane he asks for on a thread (wiki tools/shipkit/threads-how-it-fits.md, A lane he asks for): his request, where it
2
+ // stands, the orchestrator that must act on it, and the line it reads. Pure and browser safe
3
+ // the one constraint a reader breaks first: nothing here starts a process; a session reads the line and decides
4
+ import { partyOf, type Message, type ReviewItem } from './model.ts'
5
+ import { sessionLabel, type Holder, type Parties } from './parties.ts'
6
+
7
+ /** his request as it stands: `asked` while nobody took the thread since; `given` once a lane (or a session) took it and
8
+ * has not acted yet. It clears, null, at the first agent act after it that is no take and no read */
9
+ export interface LaneAsk {
10
+ /** its message, and the item it sits on */
11
+ id: string
12
+ on: string
13
+ at: string
14
+ /** what the lane should do, in the owner's words; empty for none */
15
+ words: string
16
+ state: 'asked' | 'given'
17
+ /** given: the lane it went to; absent, the session took it as itself */
18
+ to?: string
19
+ /** given: the session of the one it went to */
20
+ toSession?: string
21
+ }
22
+
23
+ /** an agent's act a request reads: its writer, its session, a take or not */
24
+ interface Act {
25
+ who: string
26
+ session?: string
27
+ at: string
28
+ take: boolean
29
+ }
30
+
31
+ function actsAfter(members: readonly ReviewItem[], at: string): Act[] {
32
+ const out: Act[] = []
33
+ for (const x of members) {
34
+ const o = x.item.origin
35
+ if (o.by === 'agent' && (o.lane || o.session) && x.item.created > at) out.push({ who: o.lane ?? 'agent', ...(o.session ? { session: o.session } : {}), at: x.item.created, take: false })
36
+ for (const m of x.thread) {
37
+ // the machine's unnamed lines (a hold checked) and a read mark are no act of anyone
38
+ if (partyOf(m.who) !== 'agent' || m.op === 'seen' || m.at <= at || (m.who === 'agent' && m.session === undefined)) continue
39
+ out.push({ who: m.who, ...(m.session ? { session: m.session } : {}), at: m.at, take: m.op === 'take' })
40
+ }
41
+ }
42
+ return out.sort((a, b) => a.at.localeCompare(b.at))
43
+ }
44
+
45
+ /** the newest request of his in the thread and where it stands, null when there is none or it cleared */
46
+ export function laneAskOf(members: readonly ReviewItem[]): LaneAsk | null {
47
+ let ask: { m: Message; on: string } | null = null
48
+ for (const x of members) for (const m of x.thread) if (m.laneAsk !== undefined && partyOf(m.who) === 'owner' && (ask === null || m.at >= ask.m.at)) ask = { m, on: x.item.id }
49
+ if (ask === null) return null
50
+ // it clears at the first act of one it reached: a session (the orchestrators), or a lane a take after it names; an
51
+ // act of a lane it never reached (the holder at work on its own task) clears nothing
52
+ const acts = actsAfter(members, ask.m.at)
53
+ const reached = new Set<string>()
54
+ let took: Act | undefined
55
+ for (const a of acts) {
56
+ if (a.take) {
57
+ took = a
58
+ reached.add(a.who)
59
+ } else if (a.who === 'agent' || reached.has(a.who)) return null
60
+ }
61
+ const base = { id: ask.m.id, on: ask.on, at: ask.m.at, words: ask.m.text?.trim() ?? '' }
62
+ if (took === undefined) return { ...base, state: 'asked' }
63
+ return { ...base, state: 'given', ...(took.who !== 'agent' ? { to: took.who } : {}), ...(took.session ? { toSession: took.session } : {}) }
64
+ }
65
+
66
+ /** the one it was given to still lives: a lane live or with a live watch, a session live */
67
+ const givenLives = (a: LaneAsk, p: Parties): boolean =>
68
+ a.to !== undefined ? p.lanes.some((l) => l.name === a.to && (a.toSession === undefined || l.session === a.toSession) && (l.live || l.watch)) : p.sessions.some((s) => s.id === a.toSession && s.live)
69
+
70
+ /** it waits on the orchestrator: nobody took it, or the one given it ended before it acted */
71
+ export const laneAskOwed = (a: LaneAsk, p: Parties): boolean => a.state === 'asked' || !givenLives(a, p)
72
+
73
+ /** who must act on it: the holder's session while it lives, else every live session of the repo, else none (the repo's
74
+ * next session, at its first prompt) */
75
+ export interface Orchestrator {
76
+ /** the holder's live session */
77
+ session: string | null
78
+ /** with no such session: every live session of the repo */
79
+ sessions: string[]
80
+ /** in words: « app main », « the next session in app » */
81
+ label: string
82
+ }
83
+
84
+ export function orchestratorOf(h: Holder | null, p: Parties, repo: string): Orchestrator {
85
+ const own = h?.session !== undefined && p.sessions.some((s) => s.id === h.session && s.live) ? h.session : null
86
+ if (own !== null) return { session: own, sessions: [own], label: sessionLabel(own, p) }
87
+ const live = p.sessions.filter((s) => s.live && s.repo === repo).map((s) => s.id)
88
+ const label = live.length === 1 ? sessionLabel(live[0], p) : live.length > 1 ? `${repo} main` : `the next session in ${repo}`
89
+ return { session: null, sessions: live, label }
90
+ }
91
+
92
+ /** the state the thread shows: « lane asked · waiting for app main », « lane asked · given to L65 » */
93
+ export function laneAskWords(a: LaneAsk, h: Holder | null, p: Parties, repo: string): string {
94
+ const who = orchestratorOf(h, p, repo).label
95
+ const to = a.to ?? (a.toSession ? sessionLabel(a.toSession, p) : 'a session')
96
+ if (a.state === 'asked') return `lane asked · waiting for ${who}`
97
+ return givenLives(a, p) ? `lane asked · given to ${to}` : `lane asked · ${to} ended before it acted, waiting for ${who}`
98
+ }
99
+
100
+ /** the orchestrator's line in its hook and its watch: what he asks, and what to do */
101
+ export function laneAskLine(a: LaneAsk, address: string, title: string, bin = 'sk'): string {
102
+ const ended = a.state === 'given' ? `${a.to ?? 'the session'} was given it and ended before it acted. ` : ''
103
+ const words = a.words === '' ? '' : `: « ${a.words.split('\n').join(' ')} »`
104
+ return `he asks for a lane on thread ${address} "${title}"${words}\n ${ended}Nothing starts by itself. Take it first (${bin} thread take ${address}: the other sessions' line goes), then SendMessage to a live lane, or start a sub-agent with this thread as its brief (${bin} thread show ${address}); then ${bin} thread assign ${address} <lane>.`
105
+ }
106
+
107
+ /** the orchestrator `me` is for a request in a store: the holder's live session alone, else any session standing in the
108
+ * thread's repo (`here`) */
109
+ export const laneAskForMe = (me: { session: string | null }, o: Orchestrator, here: boolean): boolean => (o.session !== null ? me.session === o.session : here && me.session !== null)