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,62 @@
1
+ // the pass that checks each standing hold (wiki tools/shipkit/threads-how-it-fits.md, The model): every object that
2
+ // holds a thread open, its kind's check run server side, a `hold` message written only when it flips (its first check
3
+ // included), so a minute's pass on unmoved objects writes nothing. The hub runs it with its ping; `sk thread holds` now.
4
+ //
5
+ // the one constraint a reader breaks first: a check that throws holds, its words the error, never a clear: one broken
6
+ // read must never close a thread
7
+ import { existsSync } from 'node:fs'
8
+ import { branchHold } from './branch-hold.ts'
9
+ import { heldOpen, holdsOpenOf, type Hold, type HoldState, type HoldsOpen } from './holds.ts'
10
+ import type { ReviewItem, Spec } from './model.ts'
11
+ import { appendMessage, readAll, specOf, storeDir } from './store.ts'
12
+ import { membersOf, threadsOf } from './threads.ts'
13
+
14
+ /** the house kinds' checks: server side, beside a declaration the hub bundles (review/kinds.ts) */
15
+ const HOUSE_CHECKS: Record<string, NonNullable<HoldsOpen['check']>> = { branch: branchHold }
16
+
17
+ export interface HoldSync {
18
+ checked: number
19
+ flipped: number
20
+ }
21
+
22
+ /** one hold checked now, null when its kind declares no check; a check that throws holds */
23
+ async function checkHold(root: string, h: Hold, spec: Spec): Promise<HoldState | null> {
24
+ const word = h.address.slice(0, h.address.indexOf(':'))
25
+ const check = holdsOpenOf(word, spec)?.check ?? HOUSE_CHECKS[word]
26
+ if (check === undefined) return null
27
+ try {
28
+ return await check(h.address.slice(word.length + 1), { root, ...(h.sha !== undefined ? { sha: h.sha } : {}), ...(h.ahead !== undefined ? { ahead: h.ahead } : {}) })
29
+ } catch (e) {
30
+ return { held: true, words: `held open by ${h.address}: its check broke: ${(e as Error).message.split('\n')[0]}` }
31
+ }
32
+ }
33
+
34
+ /** the thread's standing holds as they stand this instant, for the page: each one's words and facts read now, nothing
35
+ * written (the pass writes the flips) */
36
+ export async function liveHolds(root: string, members: readonly ReviewItem[], spec: Spec): Promise<(Hold & { facts?: Record<string, unknown> })[]> {
37
+ return Promise.all(
38
+ heldOpen(members, spec).map(async (h) => {
39
+ const s = await checkHold(root, h, spec)
40
+ return s === null ? h : { ...h, words: s.words, ...(s.facts ? { facts: s.facts } : {}) }
41
+ }),
42
+ )
43
+ }
44
+
45
+ /** each standing hold of the store of `root` checked; a flip written as the machine's message on its thread */
46
+ export async function syncHolds(root: string, now = new Date()): Promise<HoldSync> {
47
+ const out: HoldSync = { checked: 0, flipped: 0 }
48
+ const dir = storeDir(root)
49
+ if (!existsSync(dir)) return out
50
+ const spec = specOf(dir)
51
+ for (const t of threadsOf(readAll(dir).items, spec))
52
+ for (const h of heldOpen(membersOf(t), spec)) {
53
+ const s = await checkHold(root, h, spec)
54
+ if (s === null) continue
55
+ out.checked++
56
+ if (h.checked && s.held) continue
57
+ const ahead = s.facts?.ahead
58
+ appendMessage(dir, t.head.item.id, { who: 'agent', text: s.words, hold: { address: h.address, held: s.held, ...(s.sha !== undefined ? { sha: s.sha } : {}), ...(typeof ahead === 'number' ? { ahead } : {}) } }, { machine: true, now })
59
+ out.flipped++
60
+ }
61
+ return out
62
+ }
@@ -0,0 +1,85 @@
1
+ // an attached object that holds its thread open (wiki tools/shipkit/threads-how-it-fits.md, The model): its kind
2
+ // declares `holdsOpen`, an attach (`about`) starts the hold, the machine writes a `hold` message each time one flips,
3
+ // his close (`unhold`) releases the standing ones. Pure and browser safe: the checks run server side
4
+ // (review/holds-sync.ts)
5
+ //
6
+ // the one constraint a reader breaks first: only the messages after an object's newest attach count, so an object
7
+ // attached again after a release or a clear holds again until its next check
8
+ import { HOUSE_KINDS } from './kinds.ts'
9
+ import { canonicalAddress, NO_SPEC, partyOf, type ReviewItem, type Spec } from './model.ts'
10
+
11
+ /** what a kind's check says of one object now: held while its condition is not met; `sha` the object's version the
12
+ * next check may need (a branch deleted after its merge) */
13
+ export interface HoldState {
14
+ held: boolean
15
+ words: string
16
+ sha?: string
17
+ /** what the box draws beside the words: ahead, behind, the last commit, the diff */
18
+ facts?: Record<string, unknown>
19
+ }
20
+
21
+ /** a kind's hold: its condition in words, whose move it is while it holds, and server side, its check on one object by
22
+ * its key */
23
+ export interface HoldsOpen {
24
+ until: string
25
+ /** who meets the condition: the owner (a merge into main is his gate), else an agent */
26
+ move?: 'owner' | 'agents'
27
+ check?(key: string, ctx: { root: string; sha?: string; ahead?: number }): HoldState | Promise<HoldState>
28
+ }
29
+
30
+ /** one object that holds or held a thread since its newest attach */
31
+ export interface Hold {
32
+ address: string
33
+ held: boolean
34
+ words: string
35
+ /** the newest flip's time, else the attach's */
36
+ at: string
37
+ /** false until the machine checked it once: it holds meanwhile */
38
+ checked: boolean
39
+ sha?: string
40
+ ahead?: number
41
+ /** his close released it */
42
+ released: boolean
43
+ }
44
+
45
+ const wordOf = (address: string): string => address.slice(0, address.indexOf(':'))
46
+
47
+ /** the hold a kind word declares, the repo's kind first */
48
+ export const holdsOpenOf = (word: string, spec: Spec = NO_SPEC): HoldsOpen | undefined => (spec.kinds[word] ?? HOUSE_KINDS[word])?.holdsOpen
49
+
50
+ /** every object attached to the thread whose kind holds, or that a hold message names, as it stands since its newest
51
+ * attach, oldest attach first */
52
+ export function holdsOf(members: readonly ReviewItem[], spec: Spec = NO_SPEC): Hold[] {
53
+ const msgs = members.flatMap((x) => x.thread).sort((a, b) => a.at.localeCompare(b.at) || a.id.localeCompare(b.id))
54
+ const named = new Set(msgs.flatMap((m) => (m.hold ? [m.hold.address] : [])))
55
+ const attached = new Map<string, string>()
56
+ for (const m of msgs)
57
+ for (const raw of m.about ?? []) {
58
+ const a = canonicalAddress(raw) ?? raw
59
+ if (holdsOpenOf(wordOf(a), spec) !== undefined || named.has(a)) attached.set(a, m.at)
60
+ }
61
+ const out: Hold[] = []
62
+ for (const [address, since] of [...attached].sort((a, b) => a[1].localeCompare(b[1]))) {
63
+ const after = msgs.filter((m) => m.at >= since)
64
+ const flip = after.filter((m) => m.hold?.address === address && partyOf(m.who) === 'agent').at(-1)
65
+ const released = after.some((m) => partyOf(m.who) === 'owner' && m.unhold?.includes(address))
66
+ const until = holdsOpenOf(wordOf(address), spec)?.until ?? 'its condition is met'
67
+ out.push({
68
+ address,
69
+ held: !released && (flip?.hold?.held ?? true),
70
+ words: flip?.text ?? `held open by ${address} until ${until}: not checked yet`,
71
+ at: flip?.at ?? since,
72
+ checked: flip !== undefined,
73
+ ...(flip?.hold?.sha ? { sha: flip.hold.sha } : {}),
74
+ ...(flip?.hold?.ahead !== undefined ? { ahead: flip.hold.ahead } : {}),
75
+ released,
76
+ })
77
+ }
78
+ return out
79
+ }
80
+
81
+ /** the objects that hold the thread open now */
82
+ export const heldOpen = (members: readonly ReviewItem[], spec: Spec = NO_SPEC): Hold[] => holdsOf(members, spec).filter((h) => h.held)
83
+
84
+ /** whose move a standing hold is: its kind's `move`, an agent's when the kind says none */
85
+ export const holdMoveOf = (h: Pick<Hold, 'address'>, spec: Spec = NO_SPEC): 'owner' | 'agents' => holdsOpenOf(wordOf(h.address), spec)?.move ?? 'agents'
@@ -0,0 +1,41 @@
1
+ // the server part of the house kinds that read and apply an object (wiki tools/shipkit/threads-how-it-fits.md, Kinds):
2
+ // the messages store's `persona`, `messages` and `surface`, their read and apply bound to the repo root. One lookup for
3
+ // every server caller (`sk thread post`'s states, the apply on the owner's verdict): the repo unit's kind of that word first,
4
+ // as a repo's word wins, else the house's. The one constraint a reader breaks first: this module reads the disk, so
5
+ // nothing the hub bundles imports it (the pure declarations stay in kinds.ts)
6
+ import { isObjectKind, readObject, type MessageJson } from '../messages/objects.ts'
7
+ import { applyObject } from '../messages/write.ts'
8
+ import { HOUSE_KINDS } from './kinds.ts'
9
+ import type { KindDef, ObjectState, ReviewUnit } from './unit.ts'
10
+
11
+ /** one field of a proposed change set on a store object's json: a message's own fields sit under `fields`, a field the owner
12
+ * filled leaves `toFill`; a phrasing's or an option's words are its `text` or `headline` (an empty field name) */
13
+ export function withField(state: ObjectState, field: string, value: string): ObjectState {
14
+ const j = { ...(state.json as Record<string, unknown>) }
15
+ if ('phrasings' in j && field !== 'title') {
16
+ const m = j as unknown as MessageJson
17
+ const fields = { ...m.fields, [field]: value }
18
+ // an empty value is the field with no words: to fill when it was written so, else absent
19
+ if (value.trim() === '') delete fields[field]
20
+ const toFill = value.trim() === '' ? m.toFill : m.toFill.filter((k) => k !== field)
21
+ return { json: { ...m, fields, toFill } }
22
+ }
23
+ const k = field !== '' ? field : 'text' in j ? 'text' : 'headline' in j ? 'headline' : field
24
+ if (k === '') throw new Error('name the field the change sets (--field <key>)')
25
+ return { json: { ...j, [k]: value } }
26
+ }
27
+
28
+ /** the house kind of `word` with its server part, bound to `root`; undefined for a kind with none */
29
+ function houseDef(root: string, word: string): KindDef | undefined {
30
+ const spec = HOUSE_KINDS[word]
31
+ if (spec == null || !isObjectKind(word)) return undefined
32
+ return {
33
+ ...spec,
34
+ read: (key, at) => readObject(root, word, key, at),
35
+ apply: (key, after, before) => void applyObject(root, word, key, after.json, before?.json),
36
+ field: withField,
37
+ }
38
+ }
39
+
40
+ /** the kind that reads and applies objects of `word` in this repo: the unit's own, else the house's */
41
+ export const serverKindOf = (root: string, unit: Pick<ReviewUnit, 'kinds'> | null | undefined, word: string): KindDef | undefined => unit?.kinds?.[word] ?? houseDef(root, word)
@@ -1,11 +1,12 @@
1
1
  // `sk thread inbox --hook`: the inbox as a Claude Code hook, so the owner's answers reach a session that holds no
2
2
  // watch. On a prompt (UserPromptSubmit) the unseen answers join the turn as context; at a turn's end (Stop) the turn
3
- // is refused while one is unseen. An answer is seen once `sk thread seen <id>` ran, after the session acted on it.
3
+ // is refused while one is unseen, or read with no act in its thread since (review/traces.ts readNoAct). The agent
4
+ // marks it seen as it reads it, then says what it does (`sk thread working`).
4
5
  // the one constraint a reader breaks first: a Stop the hook already refused once (`stop_hook_active`) passes, else
5
6
  // a session that cannot mark an answer seen never ends its turn
6
7
 
7
- /** what Claude Code hands a hook on stdin, the two fields read here */
8
- export type HookInput = { hook_event_name?: string; stop_hook_active?: boolean }
8
+ /** what Claude Code hands a hook on stdin, the fields read here */
9
+ export type HookInput = { hook_event_name?: string; stop_hook_active?: boolean; session_id?: string }
9
10
 
10
11
  export function parseHookInput(text: string): HookInput {
11
12
  try {
@@ -16,20 +17,32 @@ export function parseHookInput(text: string): HookInput {
16
17
  }
17
18
  }
18
19
 
20
+ /** the session whose threads the hook hears: the id its acts carry, CLAUDE_CODE_SESSION_ID, which a hook gets in its
21
+ * env; else the one the input names. The two differ once a session is resumed inside a running process: its acts keep
22
+ * the id the process started with, the input names the transcript's. Null (every thread) on a run with neither */
23
+ export const hookSession = (input: HookInput, env: Record<string, string | undefined> = process.env): string | null =>
24
+ env.CLAUDE_CODE_SESSION_ID?.trim() || (typeof input.session_id === 'string' && input.session_id !== '' ? input.session_id : null)
25
+
19
26
  /** true when the hook answers nothing and the inbox need not be read at all */
20
27
  export const hookPasses = (input: HookInput): boolean => input.hook_event_name === 'Stop' && input.stop_hook_active === true
21
28
 
22
- /** the one json line the hook prints, or null for none. `unseen`: the answers not marked seen, as the inbox prints
23
- * them; `owed`: the ids of the answers read and not closed */
24
- export function hookAnswer(input: HookInput, unseen: string, owed: readonly string[], bin = 'sk'): string | null {
29
+ /** the one json line the hook prints, or null for none. `unseen`: the answers not marked seen that this session hears,
30
+ * as the inbox prints them; `owed`: the ids of the answers read and not closed; `nobody`: the threads of the repo no
31
+ * live party hears, on a prompt only (a stop is never held for another session's thread); `lanes`: his requests for a
32
+ * lane this session is the orchestrator of (review/lane-ask.ts), first, a stop held on them too */
33
+ export function hookAnswer(input: HookInput, unseen: string, owed: readonly string[], bin = 'sk', nobody = '', lanes = ''): string | null {
25
34
  if (hookPasses(input)) return null
35
+ const laneText = lanes === '' ? '' : `The owner asks for a lane on a thread. You are the orchestrator: nothing starts a process for you, so give it one now:\n${lanes}`
26
36
  if (input.hook_event_name === 'Stop') {
27
- if (unseen === '') return null
28
- return JSON.stringify({ decision: 'block', reason: `The owner's answers in threads are not marked seen. Read each, act on it (relay it to its lane, answer it), then \`${bin} thread seen <id>\`:\n${unseen}` })
37
+ if (unseen === '' && lanes === '') return null
38
+ const answers = unseen === '' ? '' : `The owner's answers in threads are unseen, or read with nothing done since. Mark each seen as you read it (\`${bin} thread seen <id>\`), then act on it (relay it to its live lane, or act as yourself: a session acts on its own lane's thread) and answer in its thread, or say what you do (\`${bin} thread working <id> "…"\`):\n${unseen}`
39
+ return JSON.stringify({ decision: 'block', reason: [laneText, answers].filter((p) => p !== '').join('\n\n') })
29
40
  }
30
41
  const parts = [
31
- unseen === '' ? '' : `Unseen answers of the owner in threads (act on each, then \`${bin} thread seen <id>\`):\n${unseen}`,
42
+ laneText,
43
+ unseen === '' ? '' : `Answers of the owner in threads, unseen or read with nothing done since (mark each seen as you read it: \`${bin} thread seen <id>\`, then \`${bin} thread working <id> "<what you do now>"\`, then act):\n${unseen}`,
32
44
  owed.length === 0 ? '' : `Answers read but not closed (done or wontfix): ${owed.join(', ')}`,
45
+ nobody === '' ? '' : `Threads of this repo nobody hears now (no agent holds it, or the session that held it ended): take one when your task allows, else name it in your report. To act on one, \`${bin} thread take <address>\` makes it yours, then act and \`${bin} thread seen <id>\`:\n${nobody}`,
33
46
  ].filter((p) => p !== '')
34
47
  return parts.length === 0 ? null : JSON.stringify({ hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: parts.join('\n\n') } })
35
48
  }
@@ -0,0 +1,201 @@
1
+ // what the inbox reads out (wiki tools/shipkit/threads-how-it-fits.md, The rules): per store, his answers not marked
2
+ // seen and the notes he raised that an agent owes, each thread printed by the item he answered; as a hook, what the
3
+ // asking session hears (rule 3) in every store it or its lanes wrote in, and what nobody hears in its own repo
4
+ import { existsSync, readFileSync } from 'node:fs'
5
+ import { join } from 'node:path'
6
+ import { detail, markIt, newsDetail, type Say } from './format.ts'
7
+ import { hookAnswer, type HookInput } from './inbox-hook.ts'
8
+ import { moveOf, stateOf, unreadBy, verdictOf, type ReviewItem } from './model.ts'
9
+ import { resumableOf, resumeLine, type Me, type Parties } from './parties.ts'
10
+ import { followedIds, holderOf, hookHears, membersOf, ownAddressesOf, threadByItem, threadOfItem, threadsOf, unseen, type Thread } from './threads.ts'
11
+ import type { Handed } from '../agent-time/registry.ts'
12
+ import { readNoAct } from './traces.ts'
13
+ import { laneAskForMe, laneAskLine, laneAskOf, laneAskOwed, orchestratorOf } from './lane-ask.ts'
14
+
15
+ /** one store as the inbox reads it: its repo by name, its root, whether the caller stands in it */
16
+ export interface StoreRead {
17
+ repo: string
18
+ root: string
19
+ dir: string
20
+ here: boolean
21
+ items: ReviewItem[]
22
+ broken: { id: string; error: string }[]
23
+ say: Say
24
+ }
25
+
26
+ /** a plain approval: no word, no rectangle, no reaction, no pick, no reply; it asks for no work */
27
+ export const plainApproval = (x: ReviewItem): boolean => {
28
+ const v = verdictOf(x)
29
+ return v?.status === 'approved' && !v.seen && !v.comment && v.rects.length === 0 && !v.reactions && v.pick === undefined && unreadBy(x, 'agent').length === 0
30
+ }
31
+
32
+ /** what one store holds for the agent that `keep` says hears it: the threads with news, each with the items of it to
33
+ * read; the plain approvals; the « fix » and « no » read and not done */
34
+ export interface Selected {
35
+ threads: { t: Thread | null; items: ReviewItem[] }[]
36
+ plain: ReviewItem[]
37
+ owed: Thread[]
38
+ news: ReviewItem[]
39
+ /** his newest word an agent read with no act since (review/traces.ts readNoAct): still owed */
40
+ read: Thread[]
41
+ }
42
+
43
+ export function selectInbox(s: StoreRead, keep: (x: ReviewItem, byItem: ReadonlyMap<string, Thread>) => boolean, o: { all?: boolean; hook?: boolean; subject?: string } = {}): Selected {
44
+ const threads = threadsOf(s.items, s.say.spec)
45
+ const byItem = threadByItem(threads)
46
+ const of = (x: ReviewItem): boolean => keep(x, byItem) && (o.subject === undefined || x.item.subject.kind === o.subject)
47
+ const news = unseen(s.items).filter(of)
48
+ const followed = followedIds(s.items)
49
+ // what he or a player raised and nobody closed is the agents' move, read or not
50
+ const open = s.items.filter((x) => of(x) && x.item.origin.by !== 'agent' && moveOf(stateOf(x, followed.has(x.item.id)).state) === 'agents' && !news.includes(x))
51
+ // 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
52
+ const inHand = (x: ReviewItem): boolean => o.hook === true && x.item.origin.by !== 'agent' && stateOf(x, followed.has(x.item.id)).state === 'claimed'
53
+ const shown = [...(o.all ? news : news.filter((x) => !plainApproval(x))), ...open].filter((x) => !inHand(x))
54
+ const out: Selected['threads'] = []
55
+ const at = new Map<string, Selected['threads'][number]>()
56
+ for (const x of shown) {
57
+ const t = threadOfItem(x.item.id, threads)
58
+ const key = t ? t.head.item.id : x.item.id
59
+ const g = at.get(key)
60
+ if (g) g.items.push(x)
61
+ else {
62
+ const n = { t, items: [x] }
63
+ at.set(key, n)
64
+ out.push(n)
65
+ }
66
+ }
67
+ const owed = threads.filter((t) => of(t.head) && !at.has(t.head.item.id) && t.head.item.origin.by === 'agent' && verdictOf(t.head)?.seen === true && stateOf(t.head, false).state === 'claimed')
68
+ const read = threads.filter((t) => of(t.head) && !at.has(t.head.item.id) && readNoAct(t) !== null)
69
+ return { threads: out, plain: o.all ? [] : news.filter(plainApproval), owed, news, read }
70
+ }
71
+
72
+ /** one thread of a selection in words: by the item he answered (format.ts newsDetail) */
73
+ export const selectedText = (s: StoreRead, g: Selected['threads'][number]): string => (g.t ? newsDetail(g.t, g.items, s.dir, s.say) : g.items.map((x) => detail(x, s.dir, false, false, s.say)).join('\n'))
74
+
75
+ /** a thread whose holder lane ended, its session alive: the line that offers the resume, and what the lane takes back */
76
+ export function resumeOf(s: Pick<StoreRead, 'dir' | 'say'>, t: Thread, p: Parties, bin = 'sk'): { line: string; lane: string; session: string; thread: Handed['threads'][number] } | null {
77
+ const r = resumableOf(holderOf(t), p)
78
+ if (r === null) return null
79
+ const address = ownAddressesOf(t, s.say.spec)[0] ?? t.head.item.id
80
+ return { line: resumeLine(r, address, bin), lane: r.lane, session: r.session, thread: { dir: s.dir, head: t.head.item.id, address } }
81
+ }
82
+
83
+ /** a store the caller does not stand in: its commands run there */
84
+ const elsewhere = (s: StoreRead, bin: string): string => `in ${s.repo} (${s.root}): run its commands there, cd ${s.root} && ${bin} thread seen <id>`
85
+
86
+ /** a thread whose newest word of his an agent read and nobody acted on since: owed like an unseen one */
87
+ function readLine(s: StoreRead, t: Thread, bin: string): string {
88
+ const address = ownAddressesOf(t, s.say.spec)[0] ?? t.head.item.id
89
+ const r = readNoAct(t)!
90
+ return `thread ${address}: ${r.who} read his newest word (${r.at}) and nothing was done in the thread since: answer it there, or say what you do: ${bin} thread working ${address} "…"`
91
+ }
92
+
93
+ /** his requests for a lane in a store that `me` is the orchestrator of (review/lane-ask.ts), each as its line; a run
94
+ * that names no session reads them all */
95
+ export function laneAsksFor(s: StoreRead, me: Me, p: Parties, bin = 'sk'): string[] {
96
+ const anyone = me.session === null && me.lane === null
97
+ if (me.lane !== null) return []
98
+ const out: string[] = []
99
+ for (const t of threadsOf(s.items, s.say.spec)) {
100
+ const a = laneAskOf(membersOf(t))
101
+ if (a === null || !laneAskOwed(a, p)) continue
102
+ const h = holderOf(t)
103
+ if (!anyone && !laneAskForMe(me, orchestratorOf(h, p, s.repo), s.here)) continue
104
+ out.push(laneAskLine(a, ownAddressesOf(t, s.say.spec)[0] ?? t.head.item.id, t.head.item.title, bin))
105
+ }
106
+ return out
107
+ }
108
+
109
+ /** the threads nobody hears shown in full on a prompt; the rest counted */
110
+ const NOBODY_SHOWN = 5
111
+
112
+ export interface HookIn {
113
+ input: HookInput
114
+ me: Me
115
+ stores: readonly StoreRead[]
116
+ parties: Parties
117
+ bin?: string
118
+ /** his message on an ended lane's thread was shown: the lane takes it back at its next `sk` call (registry noteHanded) */
119
+ onHanded?: (lane: string, session: string, thread: Handed['threads'][number]) => void
120
+ }
121
+
122
+ /** the hook's json line, or null for none: what `me` hears in every store (a prompt's context; a stop refused while
123
+ * one is unseen), and on a prompt what nobody hears in the repo it stands in, with the way to take it */
124
+ export function hookReply(o: HookIn): string | null {
125
+ const bin = o.bin ?? 'sk'
126
+ const mine: string[] = []
127
+ const owed: string[] = []
128
+ const plain: string[] = []
129
+ const nobody: string[] = []
130
+ let nobodyMore = 0
131
+ const lanes: string[] = []
132
+ // a run that names no session (a terminal's) reads every thread, as the bare inbox does
133
+ const anyone = o.me.session === null && o.me.lane === null
134
+ for (const s of o.stores) {
135
+ const asked = laneAsksFor(s, o.me, o.parties, bin)
136
+ if (asked.length > 0 && !s.here) lanes.push(elsewhere(s, bin))
137
+ lanes.push(...asked)
138
+ const heard = selectInbox(s, (x, byItem) => anyone || hookHears(o.me, x, byItem, o.parties, s.repo) === 'mine', { hook: true })
139
+ if (heard.threads.length > 0) {
140
+ if (!s.here) mine.push(elsewhere(s, bin))
141
+ for (const g of heard.threads) {
142
+ const r = g.t ? resumeOf(s, g.t, o.parties, bin) : null
143
+ if (r !== null) o.onHanded?.(r.lane, r.session, r.thread)
144
+ const address = g.t ? (ownAddressesOf(g.t, s.say.spec)[0] ?? g.t.head.item.id) : (g.items[0]?.item.id ?? '')
145
+ mine.push(`${selectedText(s, g)}\n ${markIt(address, bin).slice(3)}${r === null ? '' : `\n ${r.line}`}\n`)
146
+ }
147
+ }
148
+ for (const t of heard.read) mine.push(readLine(s, t, bin))
149
+ owed.push(...heard.owed.map((t) => (s.here ? t.head.item.id : `${t.head.item.id} (in ${s.repo})`)))
150
+ plain.push(...heard.plain.map((x) => x.item.id))
151
+ if (anyone || !s.here || o.input.hook_event_name === 'Stop') continue
152
+ const orphan = selectInbox(s, (x, byItem) => hookHears(o.me, x, byItem, o.parties, s.repo) === 'nobody', { hook: true })
153
+ for (const g of orphan.threads) {
154
+ if (nobody.length >= NOBODY_SHOWN) {
155
+ nobodyMore++
156
+ continue
157
+ }
158
+ const address = g.t ? (ownAddressesOf(g.t, s.say.spec)[0] ?? g.t.head.item.id) : (g.items[0]?.item.id ?? '')
159
+ nobody.push(`${selectedText(s, g)}\n take it: ${bin} thread take ${address}\n`)
160
+ }
161
+ for (const t of orphan.read) if (nobody.length < NOBODY_SHOWN) nobody.push(`${readLine(s, t, bin)}\n take it: ${bin} thread take ${ownAddressesOf(t, s.say.spec)[0] ?? t.head.item.id}\n`)
162
+ }
163
+ if (plain.length > 0) mine.push(`${plain.length} plain approval(s), nothing to do: ${bin} thread seen ${plain.join(' ')}`)
164
+ const nobodyText = [...nobody, ...(nobodyMore > 0 ? [`${nobodyMore} more: ${bin} thread inbox lists them`] : [])].join('\n').trim()
165
+ return hookAnswer(o.input, mine.join('\n').trim(), owed, bin, nobodyText, lanes.join('\n').trim())
166
+ }
167
+
168
+ const EVENTS = ['UserPromptSubmit', 'Stop'] as const
169
+ type Settings = { hooks?: Record<string, unknown> } & Record<string, unknown>
170
+
171
+ const readSettings = (file: string): Settings | null | 'broken' => {
172
+ if (!existsSync(file)) return null
173
+ try {
174
+ const v = JSON.parse(readFileSync(file, 'utf8')) as unknown
175
+ return typeof v === 'object' && v !== null && !Array.isArray(v) ? (v as Settings) : 'broken'
176
+ } catch {
177
+ return 'broken'
178
+ }
179
+ }
180
+
181
+ /** the events a settings object runs an inbox hook on (a command naming the inbox and a hook, shipkit's or the repo's) */
182
+ export function inboxHookEvents(s: Settings | null): Set<string> {
183
+ const on = new Set<string>()
184
+ for (const e of EVENTS) {
185
+ const entries = s?.hooks?.[e]
186
+ if (!Array.isArray(entries)) continue
187
+ const cmds = entries.flatMap((m: { hooks?: { command?: unknown }[] }) => (Array.isArray(m?.hooks) ? m.hooks : []).map((h) => h?.command))
188
+ if (cmds.some((c) => typeof c === 'string' && /inbox/.test(c) && /hook/.test(c))) on.add(e)
189
+ }
190
+ return on
191
+ }
192
+
193
+ /** the events on which neither of `root`'s settings files runs the inbox hook; read only: SK049's repair alone writes a
194
+ * Claude settings file, a posting verb never does */
195
+ export function inboxHookLacks(root: string): string[] {
196
+ const dir = join(root, '.claude')
197
+ const tracked = readSettings(join(dir, 'settings.json'))
198
+ const local = readSettings(join(dir, 'settings.local.json'))
199
+ const on = new Set([...inboxHookEvents(tracked === 'broken' ? null : tracked), ...inboxHookEvents(local === 'broken' ? null : local)])
200
+ return EVENTS.filter((e) => !on.has(e))
201
+ }
@@ -0,0 +1,199 @@
1
+ // an ask's instructions read as steps (wiki tools/shipkit/threads-instructions.md): the why above the first `##`, a step
2
+ // each `##` heading with its body up to the next one, a choice step's options; the one reading for `sk ask`, the store,
3
+ // the migration and the hub. A `##` inside a fenced block is code, never a step. Pure and browser safe
4
+
5
+ /** a numbered option of a choice step: `1. **<name>**: <words>`, its name in bold first */
6
+ const OPTION_RE = /^\s{0,3}\d+[.)]\s+(\*\*(.+?)\*\*.*)$/
7
+ const RECOMMENDED_RE = /\s*\((recommended|my pick)\)/i
8
+ const NUMBER_RE = /^\d+[.)]\s+/
9
+ const DONE_MARK = /✅/g
10
+
11
+ /** a choice step: its options as markdown lines, the agent's pick */
12
+ export type StepChoice = { options: string[]; pick?: number }
13
+
14
+ /** a field he fills inside a step, written as a fenced block whose info string names its widget: ```secret <name>
15
+ * [login]```, ```url```, ```text```; its body the one line hint. A secret goes to the vault through the secret field */
16
+ export type StepField = { kind: 'secret'; name: string; login?: true; hint: string } | { kind: 'url' | 'text'; hint: string }
17
+ export const FIELD_KINDS = ['secret', 'url', 'text'] as const
18
+ const FIELD_FENCE = /^\s{0,3}(`{3,}|~{3,})\s*(secret|url|text)(?:\s+(.*?))?\s*$/
19
+
20
+ /** a step's fields and its markdown split around them */
21
+ function fieldsOf(md: string): { fields: StepField[]; segments: InstructionStep['segments']; broken: string | null } {
22
+ const fields: StepField[] = []
23
+ const segments: InstructionStep['segments'] = []
24
+ let buf: string[] = []
25
+ let open: { kind: string; arg: string; fence: string; hint: string[] } | null = null
26
+ let broken: string | null = null
27
+ const flush = (): void => {
28
+ const md = buf.join('\n').trim()
29
+ if (md !== '') segments.push({ kind: 'md', md })
30
+ buf = []
31
+ }
32
+ for (const line of md.split('\n')) {
33
+ if (open) {
34
+ if (line.trim() === open.fence) {
35
+ const hint = open.hint.join(' ').replace(/\s+/g, ' ').trim()
36
+ if (open.kind === 'secret') {
37
+ const [name, flag] = open.arg.split(/\s+/)
38
+ if (!name) broken ??= 'a ```secret field names its secret: ```secret <name>'
39
+ else fields.push({ kind: 'secret', name, ...(flag === 'login' ? { login: true as const } : {}), hint })
40
+ } else fields.push({ kind: open.kind as 'url' | 'text', hint })
41
+ segments.push({ kind: 'field', k: fields.length - 1 })
42
+ open = null
43
+ } else open.hint.push(line)
44
+ continue
45
+ }
46
+ const f = FIELD_FENCE.exec(line)
47
+ if (f) {
48
+ flush()
49
+ open = { kind: f[2]!, arg: f[3] ?? '', fence: f[1]!, hint: [] }
50
+ } else buf.push(line)
51
+ }
52
+ flush()
53
+ return { fields, segments, broken }
54
+ }
55
+
56
+ export type InstructionStep = {
57
+ /** its heading's words, the number and ✅ gone */
58
+ title: string
59
+ /** its markdown up to the next `##`, the heading left out */
60
+ body: string
61
+ /** its body without a choice's option list, which the hub draws as buttons */
62
+ rest: string
63
+ /** the fields he fills inside it, in order: each a fenced block named for its widget */
64
+ fields: StepField[]
65
+ /** `rest` as the hub draws it: markdown, and each field at its place */
66
+ segments: ({ kind: 'md'; md: string } | { kind: 'field'; k: number })[]
67
+ /** ✅ in its heading: done before he looked */
68
+ done: boolean
69
+ choice: StepChoice | null
70
+ }
71
+
72
+ /** a part of the instructions as it draws: the why, a step, or a `##` section that is no step (an old « tell the agent ») */
73
+ export type InstructionSection = { kind: 'why'; md: string } | ({ kind: 'step'; n: number; heading: string } & InstructionStep) | { kind: 'text'; md: string }
74
+
75
+ export type ParsedInstructions = { why: string; steps: InstructionStep[]; sections: InstructionSection[] }
76
+
77
+ /** a step title that is a word to the agent, no act of his: the ask bar's « done ✓ » and the thread say it. Only the
78
+ * agent as the one told: « Tell the estate agent the date » is his act */
79
+ export function tellsTheAgent(title: string): boolean {
80
+ const t = title.replace(/[*_`"«»“”]/g, '').trim()
81
+ if (/^(tell|let|notify|ping|message|inform|update)\s+(the\s+)?agent\b/i.test(t)) return true
82
+ if (/^report\s+(back\s+)?to\s+(the\s+)?agent\b/i.test(t)) return true
83
+ // « Tell <a name> "done" »: whoever is told, a bare « done » is the ask bar's
84
+ if (/^(tell|notify|ping|message)\s+\S+\s+done\W*$/i.test(t)) return true
85
+ return /^(say|reply|answer|type|write)\s+(back\s+)?done\b/i.test(t)
86
+ }
87
+
88
+ /** a body's lines, each marked inside a fenced block or not */
89
+ function linesOf(md: string): { line: string; fenced: boolean }[] {
90
+ let fence: string | null = null
91
+ return md.split('\n').map((line) => {
92
+ const f = /^\s{0,3}(`{3,}|~{3,})/.exec(line)
93
+ if (f) {
94
+ const mark = f[1]!
95
+ if (fence === null) {
96
+ fence = mark
97
+ return { line, fenced: true }
98
+ }
99
+ if (mark[0] === fence[0] && mark.length >= fence.length && line.trim() === mark) {
100
+ fence = null
101
+ return { line, fenced: true }
102
+ }
103
+ }
104
+ return { line, fenced: fence !== null }
105
+ })
106
+ }
107
+
108
+ /** the numbered list that opens a step's body, its every item opening with a bold name, two items or more. Only as its
109
+ * first block: a list of sub acts further down (« 1. **Tiers**: click it ») is no choice */
110
+ function choiceOf(body: string): { choice: StepChoice; rest: string } | null {
111
+ const lines = linesOf(body)
112
+ let i = lines.findIndex((l) => l.line.trim() !== '')
113
+ if (i < 0 || lines[i]!.fenced || !OPTION_RE.test(lines[i]!.line)) return null
114
+ const options: string[] = []
115
+ let pick: number | undefined
116
+ for (; i < lines.length; i++) {
117
+ const l = lines[i]!
118
+ if (l.line.trim() === '') continue
119
+ const m = l.fenced ? null : OPTION_RE.exec(l.line)
120
+ if (!m) {
121
+ if (/^\s{0,3}\d+[.)]\s/.test(l.line)) return null
122
+ break
123
+ }
124
+ if (RECOMMENDED_RE.test(m[1]!) && pick === undefined) pick = options.length
125
+ options.push(m[1]!.replace(RECOMMENDED_RE, '').trim())
126
+ }
127
+ const rest = lines.slice(i).map((l) => l.line).join('\n').trim()
128
+ return options.length >= 2 ? { choice: { options, ...(pick !== undefined ? { pick } : {}) }, rest } : null
129
+ }
130
+
131
+ /** an option's name, its bold words: what the holder hears he picked */
132
+ export const choiceName = (option: string): string => /\*\*(.+?)\*\*/.exec(option)?.[1]?.trim() ?? option
133
+
134
+ /** the instructions as steps; a `##` whose title tells the agent is plain text, never a step. `numbered`: the grammar of
135
+ * the asks made before 2026-11-20, where only a `## N.` heading was a step and any other `##` text */
136
+ export function parseInstructions(md: string, o: { numbered?: boolean } = {}): ParsedInstructions {
137
+ const sections: InstructionSection[] = []
138
+ let title: string | null = null
139
+ let buf: string[] = []
140
+ const flush = (): void => {
141
+ const text = buf.join('\n').trim()
142
+ if (title === null) {
143
+ if (text !== '') sections.push({ kind: 'why', md: text })
144
+ } else if (tellsTheAgent(title.replace(NUMBER_RE, '')) || (o.numbered === true && !NUMBER_RE.test(title))) sections.push({ kind: 'text', md: `## ${title}\n\n${text}`.trim() })
145
+ else {
146
+ const n = sections.filter((s) => s.kind === 'step').length + 1
147
+ const c = choiceOf(text)
148
+ const rest = c?.rest ?? text
149
+ const f = fieldsOf(rest)
150
+ sections.push({ kind: 'step', n, heading: title, title: title.replace(NUMBER_RE, '').replace(DONE_MARK, '').replace(/\s+/g, ' ').trim(), body: text, rest, done: title.includes('✅'), choice: c?.choice ?? null, fields: f.fields, segments: f.segments })
151
+ }
152
+ buf = []
153
+ }
154
+ for (const { line, fenced } of linesOf(md)) {
155
+ const h = fenced ? null : /^##\s+(.+?)\s*#*\s*$/.exec(line)
156
+ if (h) {
157
+ flush()
158
+ title = h[1]!.trim()
159
+ } else buf.push(line)
160
+ }
161
+ flush()
162
+ const steps = sections.flatMap((s) => (s.kind === 'step' ? [{ title: s.title, body: s.body, rest: s.rest, done: s.done, choice: s.choice, fields: s.fields, segments: s.segments }] : []))
163
+ return { why: sections.find((s) => s.kind === 'why')?.md ?? '', steps, sections }
164
+ }
165
+
166
+ const key = (s: string): string => s.replace(/\s+/g, ' ').trim().toLowerCase()
167
+
168
+ /** the instructions as the hub draws them against the steps stored on them (their `ask.options`): a `##` section is
169
+ * step `i` when its title is the next stored step's, else text, so words read by an older grammar draw as they were
170
+ * ticked */
171
+ export function stepSections(md: string, options: readonly string[]): ({ kind: 'text'; md: string } | { kind: 'step'; i: number; step: InstructionStep })[] {
172
+ let i = 0
173
+ return parseInstructions(md).sections.map((s) => {
174
+ if (s.kind === 'step' && i < options.length && key(s.title) === key(options[i]!)) return { kind: 'step' as const, i: i++, step: s }
175
+ return { kind: 'text' as const, md: s.kind === 'step' ? `## ${s.heading}\n\n${s.body}`.trim() : s.md }
176
+ })
177
+ }
178
+
179
+ const PAGE = 'wiki tools/shipkit/threads-instructions.md'
180
+
181
+ /** why `sk ask` refuses these instructions, null when it takes them */
182
+ export function instructionsRefusal(md: string): string | null {
183
+ // a copy block may hold `${{ secrets.X }}` (a workflow): only the words outside one are a scaffold's leftovers
184
+ if (linesOf(md).some((l) => !l.fenced && l.line.includes('{{'))) return `a {{placeholder}} is left in it: fill it first (${PAGE})`
185
+ for (const s of parseInstructions(md).steps) {
186
+ const broken = fieldsOf(s.rest).broken
187
+ if (broken !== null) return `${broken} (${PAGE}, How to write a step)`
188
+ }
189
+ const titles = parseInstructions(md).steps.map((s) => s.title.toLowerCase())
190
+ const twice = titles.find((t, i) => titles.indexOf(t) !== i)
191
+ if (twice !== undefined) return `two steps are titled « ${twice} »: a tick is kept by its step's title, so each title is one step (${PAGE}, The shape)`
192
+ for (const { line, fenced } of linesOf(md)) {
193
+ const h = fenced ? null : /^##\s+(.+?)\s*$/.exec(line)
194
+ if (h && tellsTheAgent(h[1]!.replace(NUMBER_RE, ''))) return `the step « ${h[1]!.replace(NUMBER_RE, '').trim()} » is no act of his: the ask bar's « done ✓ » is that act, and what the agent does next goes in the why (${PAGE}, How to write a step)`
195
+ if (!fenced && /^\s*\*\*Answer\*\*\s*:/i.test(line)) return `an **Answer** line asks him to type in words: a value he gives is a field in its step (\`\`\`text, \`\`\`url, \`\`\`secret <name>), his « done » the ask bar (${PAGE}, How to write a step)`
196
+ if (!fenced && /^\s*\*\*Done when\*\*/i.test(line)) return `a **Done when** line is the agent's check, never the owner's reading: give it as --check '<command>' (${PAGE}, How to write a step)`
197
+ }
198
+ return null
199
+ }