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
@@ -1,26 +1,48 @@
1
- // SK003 — the CLAUDE.md two-line contract (meta/agent-folder/index.md): CLAUDE.md
2
- // is an include index, never a doc; `@./<agent dir>/index.md` comes LAST (include
3
- // order is SEMANTIC — base context first, repo docs after so they
4
- // override); a
5
- // public repo's `@./CLAUDE.local.md` line-1 indirection must be gitignored.
6
- // The rule asserts no base include path of its own: `shipkit start` owns
7
- // which one lands (its house template, or `--include`). A repo with neither
8
- // CLAUDE.md nor agent/ is not a two-line-contract repo and passes.
1
+ // SK003 — the CLAUDE.md contract (meta/agent-folder/index.md): CLAUDE.md is an include index, never a doc. In order:
2
+ // the base context, the identity the repo speaks as (when its `speaksAs` names one whose index exists beside the
3
+ // base wiki), then `@./<agent dir>/index.md` LAST (order is SEMANTIC: repo docs come after so they override). A
4
+ // public repo's `@./CLAUDE.local.md` stands for the private lines and must be gitignored. The rule asserts no base
5
+ // include path of its own: `shipkit start` owns which one lands. A repo with neither CLAUDE.md nor agent/ passes.
6
+ import { homedir } from 'os'
7
+ import { dirname, join, resolve } from 'path'
9
8
  import { check, type FixResult } from '../check.ts'
10
9
  import { DEFAULT_AGENT_DIR, agentDirOf } from '../core/agent-dir.ts'
10
+ import { HOUSE_LAYOUT } from '../core/house-layout.ts'
11
11
 
12
12
  /** the repo router line, always LAST: start writes it whenever agent/index.md exists */
13
13
  export const AGENT_LINE = `@./${DEFAULT_AGENT_DIR}/index.md`
14
14
  const LOCAL_LINE = '@./CLAUDE.local.md'
15
+ /** an identity's include, beside a base wiki: `@<wiki>/identities/<id>/index.md` */
16
+ const IDENTITY_RE = /^@\S*\/identities\/([a-z0-9][a-z0-9-]*)\/index\.md$/
17
+
18
+ const nonBlank = (text: string | null): string[] => (text ?? '').split('\n').filter((l) => l.trim() !== '')
19
+ /** an include path on disk: `~/` from the home, a relative one from the repo root (never the process cwd) */
20
+ const expand = (p: string, root: string): string => (p.startsWith('~/') ? join(homedir(), p.slice(2)) : resolve(root, p))
21
+
22
+ /** the identity line this repo owes: beside the base wiki's index, for its `speaksAs`, when that index exists on this
23
+ * disk (read through `has`, which the check records, so its cache knows the file). Null when it owes none (no base,
24
+ * no speaksAs, a stranger's house with no identities) */
25
+ export function identityLineFor(base: string | undefined, speaksAs: string | undefined, root: string, has: (abs: string) => boolean): string | null {
26
+ if (base == null || speaksAs == null || !base.startsWith('@') || !base.endsWith('/index.md')) return null
27
+ const sub = HOUSE_LAYOUT.identities.slice(HOUSE_LAYOUT.wiki.length + 1)
28
+ const line = `@${dirname(base.slice(1))}/${sub}/${speaksAs}/index.md`
29
+ return has(expand(line.slice(1), root)) ? line : null
30
+ }
31
+
32
+ /** the lines in load order: CLAUDE.md with its local include replaced by the local file's lines */
33
+ const loadOrder = (claude: string[], local: string | null): string[] => claude.flatMap((l) => (l === LOCAL_LINE ? nonBlank(local) : [l]))
34
+
35
+ /** the base context: the first include that is neither an identity nor the agent route */
36
+ const baseOf = (order: string[], agentLine: string): string | undefined => order.find((l) => l.startsWith('@') && l !== agentLine && !IDENTITY_RE.test(l))
15
37
 
16
38
  export const claudeMdShape = check({
17
39
  id: 'SK003',
18
40
  blocking: true,
19
41
  title: 'CLAUDE.md',
20
- description: 'CLAUDE.md loads the house wiki into every session',
42
+ description: 'CLAUDE.md loads the house wiki and the repo\'s identity into every session',
21
43
  owner: 'meta/agent-folder/index.md',
22
- // keyed on what it reads: CLAUDE.md, whether agent/index.md exists, and
23
- // the ignore files git read for the gitignore probe (c.exec runs traced)
44
+ // keyed on what it reads: CLAUDE.md and its local file, whether agent/index.md exists, the identity index beside
45
+ // the house wiki (an absolute read, recorded like any), the config, and the ignore files git read
24
46
  runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
25
47
  cache: { by: 'reads' },
26
48
  fix: 'ci',
@@ -33,23 +55,34 @@ export const claudeMdShape = check({
33
55
  const agentLine = `@./${agentIndex}`
34
56
  const hasAgent = c.exists(agentIndex)
35
57
  if (claude == null) {
36
- if (hasAgent) c.fail(`${agentIndex} exists but there is no CLAUDE.md routing it — the two-line contract wants ${agentLine}`)
37
- else c.ok('no CLAUDE.md / agent — not a two-line-contract repo')
58
+ if (hasAgent) c.fail(`${agentIndex} exists but there is no CLAUDE.md routing it — the contract wants ${agentLine}`)
59
+ else c.ok('no CLAUDE.md / agent — not a CLAUDE.md contract repo')
38
60
  return
39
61
  }
40
- const lines = claude.split('\n').filter((l) => l.trim() !== '')
62
+ const lines = nonBlank(claude)
41
63
  const includes = lines.filter((l) => l.startsWith('@'))
42
64
  const prose = lines.length - includes.length
43
65
  if (prose > 0)
44
66
  c.fail(`CLAUDE.md carries ${prose} non-include line(s) — it is a tiny include index, content belongs in agent/index.md`)
45
- if (includes.length > 2)
46
- c.fail(`CLAUDE.md has ${includes.length} include lines — the contract is 2: base context, then ${agentLine}`)
67
+ const base = baseOf(includes, agentLine)
68
+ const others = includes.filter((l) => l !== base && l !== agentLine && l !== LOCAL_LINE && !IDENTITY_RE.test(l))
69
+ if (others.length > 0)
70
+ c.fail(`CLAUDE.md includes ${others.join(', ')} — the contract is the base context, the identity the repo speaks as, then ${agentLine}`)
47
71
  if (hasAgent && !lines.includes(agentLine))
48
72
  c.fail(`${agentIndex} exists but CLAUDE.md does not import it — add ${agentLine} as the LAST line`)
49
73
  if (lines.includes(agentLine) && lines.at(-1) !== agentLine)
50
74
  c.fail(`include order inverted — base context first, ${agentLine} LAST (order is semantic: repo docs override the base)`)
51
75
  if (dir !== DEFAULT_AGENT_DIR && !hasAgent)
52
76
  c.fail(`CLAUDE.md's last include names ${agentIndex}, which does not exist: the agent folder it declares is missing`)
77
+ const local = lines.includes(LOCAL_LINE) ? c.read('CLAUDE.local.md') : null
78
+ const order = loadOrder(lines, local)
79
+ const owed = identityLineFor(baseOf(order, agentLine), c.config.speaksAs, c.root, (abs) => c.read(abs) != null)
80
+ const loaded = order.filter((l) => IDENTITY_RE.test(l))
81
+ if (owed != null && !order.includes(owed))
82
+ c.fail(`CLAUDE.md does not load the identity this repo speaks as: ${owed}, after the base context${lines.includes(LOCAL_LINE) ? ', in CLAUDE.local.md' : ''}`)
83
+ else if (owed != null && order.indexOf(owed) !== 1)
84
+ c.fail(`${owed} loads at place ${order.indexOf(owed) + 1}: it comes second, after the base context and before ${agentLine}`)
85
+ for (const l of loaded) if (l !== owed) c.fail(`CLAUDE.md loads ${l}, an identity this repo does not speak as (speaksAs: ${c.config.speaksAs ?? 'none'})`)
53
86
  if (lines.includes(LOCAL_LINE)) {
54
87
  const r = await c.exec(['git', 'check-ignore', '-q', 'CLAUDE.local.md'], { cwd: c.root, timeoutMs: 5_000 })
55
88
  if (r.code === 1)
@@ -59,18 +92,52 @@ export const claudeMdShape = check({
59
92
  }
60
93
  if (!c.failed) c.ok(`CLAUDE.md include-index ok (${lines.length} line(s))`)
61
94
  },
62
- // the one mechanical repair: the missing agent/index.md route, appended
63
- // to an EXISTING CLAUDE.md. Never creates the file — a created one-line
64
- // CLAUDE.md would lint green with the base include forever missing,
65
- // trading a loud FAIL for a permanent silent gap. Creation and prose
66
- // relocation stay human/machine-local (`shipkit start --include`).
95
+ // the mechanical repairs, on an EXISTING CLAUDE.md only: the missing agent route, appended last, and the missing
96
+ // identity line, put second (in CLAUDE.local.md when the repo routes its private lines there). Never creates
97
+ // CLAUDE.md: a created one would lint green with the base include forever missing. Creation and prose relocation
98
+ // stay with `shipkit start --include`
67
99
  repair: (c): FixResult => {
68
- if (!c.exists(`${DEFAULT_AGENT_DIR}/index.md`)) return { changed: false, summary: 'no agent/index.md — nothing mechanical to fix' }
69
100
  const cur = c.read('CLAUDE.md')
70
101
  if (cur == null) return { changed: false, summary: 'CLAUDE.md missing — creation needs the base include (shipkit start <name> writes it), not autofixable' }
71
- if (cur.split('\n').includes(AGENT_LINE)) return { changed: false, summary: `${AGENT_LINE} already routed — remaining findings need a human` }
72
- c.write('CLAUDE.md', `${cur.endsWith('\n') || cur === '' ? cur : `${cur}\n`}${AGENT_LINE}\n`)
73
- return { changed: true, summary: `${AGENT_LINE} appended as the last line` }
102
+ const done: string[] = []
103
+ let lines = nonBlank(cur)
104
+ let claudeChanged = false
105
+ if (c.exists(`${DEFAULT_AGENT_DIR}/index.md`) && !lines.includes(AGENT_LINE)) {
106
+ lines = [...lines, AGENT_LINE]
107
+ claudeChanged = true
108
+ done.push(`${AGENT_LINE} appended as the last line`)
109
+ }
110
+ const viaLocal = lines.includes(LOCAL_LINE)
111
+ let local = viaLocal ? c.read('CLAUDE.local.md') : null
112
+ let localChanged = false
113
+ const owed = identityLineFor(baseOf(loadOrder(lines, local), AGENT_LINE), c.config.speaksAs, c.root, (abs) => c.read(abs) != null)
114
+ // an identity line the repo does not speak as (its speaksAs changed, or it has none): as mechanical to drop
115
+ const stale = (l: string): boolean => IDENTITY_RE.test(l) && l !== owed
116
+ if (lines.some(stale)) {
117
+ done.push(`${lines.filter(stale).join(', ')} removed`)
118
+ lines = lines.filter((l) => !stale(l))
119
+ claudeChanged = true
120
+ }
121
+ if (local != null && nonBlank(local).some(stale)) {
122
+ done.push(`${nonBlank(local).filter(stale).join(', ')} removed from CLAUDE.local.md`)
123
+ local = `${nonBlank(local).filter((l) => !stale(l)).join('\n')}\n`
124
+ localChanged = true
125
+ }
126
+ if (owed != null && !loadOrder(lines, local).includes(owed)) {
127
+ if (viaLocal && local != null) {
128
+ const l = nonBlank(local)
129
+ local = `${[l[0]!, owed, ...l.slice(1)].join('\n')}\n`
130
+ localChanged = true
131
+ } else {
132
+ lines = [lines[0]!, owed, ...lines.slice(1)]
133
+ claudeChanged = true
134
+ }
135
+ done.push(`${owed} added second${viaLocal ? ' in CLAUDE.local.md' : ''}`)
136
+ }
137
+ if (done.length === 0) return { changed: false, summary: 'nothing mechanical to fix — remaining findings need a human' }
138
+ if (claudeChanged) c.write('CLAUDE.md', `${lines.join('\n')}\n`)
139
+ if (localChanged && local != null) c.write('CLAUDE.local.md', local)
140
+ return { changed: true, summary: done.join('; ') }
74
141
  },
75
142
  })
76
143
 
@@ -146,12 +146,16 @@ export async function notIgnored(d: Disk, paths: string[]): Promise<string[] | n
146
146
  // exit 1 means "none of them are ignored", which is an ANSWER, and git
147
147
  // still wrote the rows we parse. Anything else (no repo, no git) is not
148
148
  if (r.code !== 0 && r.code !== 1) return null
149
- // a row is `source:line:pattern<TAB>path`, and an unignored path has all
150
- // three empty: `::<TAB>path`
149
+ // a row is `source:line:pattern<TAB>path`. A path no line matches has all
150
+ // three empty (`::<TAB>path`), and a path whose last match is a `!` line
151
+ // is printed with that line, yet git keeps it: both are misses
151
152
  const miss: string[] = []
152
153
  for (const row of r.out.split('\n')) {
153
154
  const tab = row.indexOf('\t')
154
- if (tab > 0 && row.slice(0, tab) === '::') miss.push(row.slice(tab + 1))
155
+ if (tab <= 0) continue
156
+ const head = row.slice(0, tab)
157
+ const pattern = head.slice(head.indexOf(':', head.indexOf(':') + 1) + 1)
158
+ if (head === '::' || pattern.startsWith('!')) miss.push(row.slice(tab + 1))
155
159
  }
156
160
  return miss
157
161
  }
@@ -268,7 +272,7 @@ export const gitignorePolicy = check({
268
272
  c.lines.push({ kind: 'fix-fail', text: 'shipkit ci (or check --fix SK004) untracks it in one commit, the file stays on disk' })
269
273
  }
270
274
  // the old root layout is a move a machine makes, so it is red until made
271
- const left = legacyLayoutLeft(c.root, c.config)
275
+ const left = legacyLayoutLeft(c.root)
272
276
  if (left.length > 0) {
273
277
  c.fail(`old layout: ${left.join(' ')} still at the repo root, shipkit keeps them under ${SHIPKIT_DIR}/`)
274
278
  c.lines.push({ kind: 'fix-fail', text: 'shipkit ci (or check --fix SK004) moves them and lands one commit' })
@@ -83,6 +83,10 @@ const guardHookCommand = (s: Settings): string | null => {
83
83
 
84
84
  const hasGuardHook = (s: Settings): boolean => guardHookCommand(s) != null
85
85
 
86
+ /** the matcher the guard sees edits under: an agent's new persona or value proposition by hand (messages/guard.ts) */
87
+ export const EDIT_MATCHER = 'Edit|Write|MultiEdit'
88
+ const hasEditGuard = (s: Settings): boolean => (s.hooks?.['PreToolUse'] ?? []).some((m) => m.matcher === EDIT_MATCHER && (m.hooks ?? []).some((h) => h.command?.includes('one-way-in-guard') === true))
89
+
86
90
  /** the guard file the hook command points at, resolved against the repo root
87
91
  * when it hangs off `$CLAUDE_PROJECT_DIR`, as written when it is absolute.
88
92
  * A hook whose script does not exist errors on EVERY Bash call and refuses
@@ -174,6 +178,7 @@ export const oneWayInPolicy = check({
174
178
  `point it at this repo's own copy of hooks/one-way-in-guard.ts, or delete the hook and let the deny list stand alone`,
175
179
  )
176
180
  }
181
+ if (guard != null && !hasEditGuard(s)) c.fail(`${SETTINGS_PATH}: the guard does not see edits (no PreToolUse ${EDIT_MATCHER} entry), so an agent writes a new persona or value proposition by hand instead of proposing it in a thread`)
177
182
  // the summary states only what the file actually delivers: claiming the
178
183
  // replacement is named while the guard cannot run is the green that
179
184
  // measured nothing, one line under the WARN that says otherwise
@@ -220,6 +225,11 @@ export const oneWayInPolicy = check({
220
225
  h.command = wantGuard
221
226
  }
222
227
  }
228
+ if (!hasEditGuard(s)) {
229
+ const command = guardHookCommand(s) ?? wantGuard
230
+ s.hooks = { ...s.hooks, PreToolUse: [...(s.hooks?.['PreToolUse'] ?? []), { matcher: EDIT_MATCHER, hooks: [{ type: 'command', command }] }] }
231
+ changes.push(`the guard sees edits too (${EDIT_MATCHER})`)
232
+ }
223
233
  if (changes.length === 0) return { changed: false, summary: `${SETTINGS_PATH} already closes every raw runner` }
224
234
  c.write(SETTINGS_PATH, JSON.stringify(s, null, 2) + '\n')
225
235
  return { changed: true, summary: `${SETTINGS_PATH}: ${changes.join(', ')}` }
@@ -1,12 +1,8 @@
1
- // SK026 asks auto close (tools/shipkit/built-in-checks.md): probe every open
2
- // ask's own `check:` and archive the ones that pass, so an act done in the
3
- // world leaves the queue without anyone editing a file. An open queue is no
4
- // warning: the hub and `shipkit needs` show it. A repo with no queue skips.
5
- import { existsSync } from 'fs'
6
- import { join } from 'path'
7
- import { checkAsks, isClosed, listAsks } from '../asks/asks-queue.ts'
1
+ // SK026 asks auto close (tools/shipkit/built-in-checks.md): probe every open ask's own check, and a credential ask's
2
+ // values, and close the ones that pass in their threads, so an act done in the world leaves the queue without anyone
3
+ // answering it. An open queue is no warning: the hub and `shipkit needs` show it. A repo with no such ask skips
4
+ import { asksOfRepo, checkAsks } from '../asks/ask-store.ts'
8
5
  import { check } from '../check.ts'
9
- import { LAYOUT } from '../core/layout.ts'
10
6
 
11
7
  export const asksAutoclose = check({
12
8
  id: 'SK026',
@@ -17,24 +13,14 @@ export const asksAutoclose = check({
17
13
  runs: { onPreCommit: false, onCi: false, onFull: false, onRelease: false, onHealth: true, onSave: false, onClock: { every: ['20h', '28h'], inactive: 'wait' } },
18
14
  cache: { by: 'never', why: "runs each open ask's own probe, a shell command that reads the world" },
19
15
  fix: 'none',
20
- // it only probes an ask that carries one, archives one marked done or declined, and reopens a declined one set open
21
- applies: (env) => {
22
- const dir = join(env.root, env.config.asks?.dir ?? LAYOUT.asks)
23
- if (!existsSync(dir)) return 'no asks queue'
24
- return listAsks(dir).some((a) => a.check != null || isClosed(a.status)) || existsSync(join(dir, 'declined')) ? null : 'no open ask carries a probe'
25
- },
16
+ applies: (env) => (asksOfRepo(env.root).some((a) => a.status === 'open' && (a.check != null || (a.kind === 'credential' && a.secrets.length > 0))) ? null : 'no open ask carries a probe'),
17
+ // a close writes the ask's thread in the store, never a tracked file: a frozen run closes like any other
26
18
  run: async (c) => {
27
- const dir = join(c.root, c.config.asks?.dir ?? LAYOUT.asks)
28
- if (!existsSync(dir)) return void c.lines.push({ kind: 'skip', text: 'no asks queue in this repo' })
29
- // archiving RENAMES files, and the release path runs the checks between
30
- // its clean tree guard and `npm publish`: frozen means report only
31
- if (c.frozen) return void c.lines.push({ kind: 'skip', text: 'asks not probed: a frozen run archives nothing' })
32
19
  const events: string[] = []
33
- await checkAsks(c.root, dir, (l) => events.push(l))
34
- // `closed + archived <file>` / `archived <file>` / `reopened <file>` are the queue's frozen stdout contract
20
+ await checkAsks(c.root, (l) => events.push(l))
35
21
  for (const l of events) {
36
- if (l.startsWith('closed') || l.startsWith('archived') || l.startsWith('reopened')) c.ok(`ask ${l}`)
37
- // the queue could not run (another agent holds the write lease)
22
+ if (l.startsWith('closed')) c.ok(`ask ${l}`)
23
+ // the check could not run: another agent holds the asks lease
38
24
  else if (l.startsWith('WARN')) c.warn(l.replace(/^WARN\s*/, ''))
39
25
  }
40
26
  if (!c.lines.some((l) => l.kind === 'ok')) c.ok('no open ask has a probe that passes')
@@ -7,7 +7,7 @@ import { existsSync, readdirSync } from 'fs'
7
7
  import { join } from 'path'
8
8
  import { check } from '../check.ts'
9
9
  import { CONFIG_FILE } from '../core/identity.ts'
10
- import { LAYOUT } from '../core/layout.ts'
10
+ import { HOUSE_LAYOUT } from '../core/house-layout.ts'
11
11
  import { houseRootOf } from '../home/home-start.ts'
12
12
  import { speaksAsOfText } from '../social/house.ts'
13
13
 
@@ -21,10 +21,10 @@ export function machineIdentityIds(root: string): MachineIds {
21
21
  if (env != null && env !== '' && !existsSync(env)) return { broken: `SHIPKIT_IDENTITIES_DIR names ${env}, which does not exist` }
22
22
  const house = env ? null : houseRootOf(root)
23
23
  if (!env && house == null) return { none: 'not a house repo: no identities to name' }
24
- const dir = env || join(house!, LAYOUT.identities)
24
+ const dir = env || join(house!, HOUSE_LAYOUT.identities)
25
25
  const ids = existsSync(dir)
26
26
  ? readdirSync(dir, { withFileTypes: true })
27
- .filter((e) => e.isDirectory() && existsSync(join(dir, e.name, 'identity.md')))
27
+ .filter((e) => e.isDirectory() && !e.name.startsWith('_') && existsSync(join(dir, e.name, 'identity.md')))
28
28
  .map((e) => e.name)
29
29
  .sort()
30
30
  : []
@@ -1,18 +1,23 @@
1
- // SK042 post kinds (tools/shipkit/built-in-checks-contracts-and-visibility.md): every draft of `.shipkit/social/drafts/`
2
- // names what it is for, a kind of the closed set or of the social unit's own `kinds` (wiki guides/post-kinds/index.md),
3
- // through the load's one check, kinds.ts kindProblem. A word of the old words table only warns: each repo moves its own
4
- // drafts. Keyed on the social folder, the unit file's text and whether each page its text names is a file: kinds a
5
- // module the unit imports declares keep a stale green until one of those moves
6
- import { existsSync, readdirSync, readFileSync } from 'node:fs'
1
+ // SK042 post kinds (tools/shipkit/built-in-checks-contracts-and-visibility.md): every post group of the repo (its events
2
+ // in the thread store) names what it is for, a kind of the closed set or of the social unit's own `kinds` (wiki
3
+ // guides/post-kinds/index.md), through the load's one check, kinds.ts kindProblem. A word of the old words table only
4
+ // warns: each repo moves its own groups. Keyed on the repo's newest group write, the unit file's text and whether each
5
+ // page its text names is a file: kinds a module the unit imports declares keep a stale green until one of those moves
6
+ import { existsSync, readFileSync } from 'node:fs'
7
7
  import { join } from 'node:path'
8
8
  import { check } from '../check.ts'
9
- import { LAYOUT } from '../core/layout.ts'
10
9
  import { unitFilesDeclaring } from '../core/unit-files.ts'
10
+ import { cardsDb } from '../review/card-db.ts'
11
+ import { eventsRepo } from '../review/events.ts'
12
+ import { storeDir } from '../review/store.ts'
11
13
  import { ownPageMissing } from '../social/kind-pages.ts'
12
14
  import { kindOfMeta, kindProblem } from '../social/kinds.ts'
13
- import { parseFrontmatter } from '../social/md.ts'
15
+ import { groupsNow } from '../social/post-sources.ts'
14
16
  import { loadSocialUnit, type SocialUnit } from '../social/unit.ts'
15
17
 
18
+ /** the newest write of the repo's groups: the check's fact */
19
+ const groupsStamp = (root: string): string => String((cardsDb().query('select max(last_seq) as s from thread_post_groups where repo = ?').get(eventsRepo(storeDir(root))) as { s: number | null } | null)?.s ?? 0)
20
+
16
21
  /** a unit file's text, and whether each `.md` path it names is a file: a kind's page deleted asks the question again */
17
22
  export function unitKey(root: string, file: string): string {
18
23
  const text = readFileSync(file, 'utf8')
@@ -20,24 +25,24 @@ export function unitKey(root: string, file: string): string {
20
25
  return `${file}:${Bun.hash(text)}:${pages.join(',')}`
21
26
  }
22
27
 
23
- const FIX ='set the kind to one of wiki guides/post-kinds/index.md (a custom one with its kindWhy), or declare the project kind in its social unit, then sk ci --only SK042'
24
- const FIX_OLD = "move each draft to the kind its intent reads as (wiki guides/post-kinds/index.md, The old words): the repo's own step, never a blind replace"
28
+ const FIX ='set the kind to one of wiki guides/post-kinds/index.md (a custom one with its kindWhy) with sk social draft save, or declare the project kind in its social unit, then sk ci --only SK042'
29
+ const FIX_OLD = "move each draft to the kind its intent reads as (wiki guides/post-kinds/old-words.md): the repo's own step, never a blind replace"
25
30
 
26
31
  export const postKinds = check({
27
32
  id: 'SK042',
28
33
  blocking: true,
29
34
  title: 'post kinds',
30
- description: 'every social draft names its kind: one of the closed set or of the social unit',
35
+ description: 'every post group names its kind: one of the closed set or of the social unit',
31
36
  owner: 'tools/shipkit/built-in-checks-contracts-and-visibility.md',
32
- runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
33
- // the social folder, the text of the social unit files that declare its own kinds, and each page they name
34
- cache: { by: 'files', inputs: [LAYOUT.social], optional: [LAYOUT.social], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => unitKey(env.root, f)).join('\n') },
37
+ // the database, never the tree: a save refuses a bad kind, the health surface reads what is there
38
+ runs: { onPreCommit: false, onCi: false, onFull: false, onRelease: false, onHealth: true, onSave: false, onClock: 'once' },
39
+ // the repo's newest group write, the text of the social unit files that declare its own kinds, and each page they name
40
+ cache: { by: 'fact', key: (env) => [groupsStamp(env.root), ...unitFilesDeclaring(env.root, 'social').map((f) => unitKey(env.root, f))].join('\n') },
35
41
  fix: 'none',
36
42
  applies: 'always',
37
43
  run: async (c) => {
38
- const dir = join(c.root, LAYOUT.social, 'drafts')
39
- const slugs = existsSync(dir) ? readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => e.name).sort() : []
40
- if (slugs.length === 0) return c.ok(`no draft in ${LAYOUT.social}/drafts/: no kind to read`)
44
+ const groups = groupsNow(eventsRepo(storeDir(c.root)))
45
+ if (groups.length === 0) return c.ok('no post group in the database: no kind to read')
41
46
  let unit: SocialUnit | null
42
47
  try {
43
48
  unit = await loadSocialUnit(c.root)
@@ -48,12 +53,9 @@ export const postKinds = check({
48
53
  for (const k of own) if (!existsSync(join(c.root, k.page))) c.fail(ownPageMissing(k), `write its rules page, in the shape of a page of wiki guides/post-kinds/`)
49
54
  let bad = 0
50
55
  let old = 0
51
- for (const slug of slugs) {
52
- const rel = `${LAYOUT.social}/drafts/${slug}/draft.md`
53
- const raw = c.read(rel)
54
- if (raw == null) continue
55
- const { meta } = parseFrontmatter(raw)
56
- const { kind, why } = kindOfMeta(meta)
56
+ for (const g of groups) {
57
+ const rel = `draft:${g.group.slug}`
58
+ const { kind, why } = kindOfMeta(g.group.meta)
57
59
  const p = kindProblem(kind, why, own)
58
60
  if (p == null) continue
59
61
  if (p.old) {
@@ -66,7 +68,7 @@ export const postKinds = check({
66
68
  }
67
69
  if (bad > 0) c.fail(`${bad} draft${bad === 1 ? '' : 's'} with no kind of the set`, FIX)
68
70
  if (old > 0) c.warn(`${old} draft${old === 1 ? '' : 's'} on an old kind word`, FIX_OLD)
69
- if (bad === 0 && old === 0 && !c.failed) c.ok(`${slugs.length} draft${slugs.length === 1 ? '' : 's'}, each names its kind`)
71
+ if (bad === 0 && old === 0 && !c.failed) c.ok(`${groups.length} draft${groups.length === 1 ? '' : 's'}, each names its kind`)
70
72
  },
71
73
  })
72
74
 
@@ -0,0 +1,81 @@
1
+ // SK049 thread answers hook (tools/shipkit/built-in-checks-repo-wiring.md): the repo's agent settings run
2
+ // `sk thread inbox --hook` on each prompt and at each turn's end, so a session hears the owner's answers on the threads
3
+ // it holds, and the threads nobody hears reach the repo's next session. The tracked .claude/settings.json, or this
4
+ // machine's .claude/settings.local.json (the one a root that publishes to npm gets: its tracked file belongs to every
5
+ // contributor). The repair MERGES, as SK013's does. A repo that runs its own inbox hook (a command naming the inbox and
6
+ // a hook) passes
7
+ import { rootPublishesNpm } from '../core/repo-facts.ts'
8
+ import { check, type FixResult } from '../check.ts'
9
+
10
+ const SETTINGS = '.claude/settings.json'
11
+ const LOCAL = '.claude/settings.local.json'
12
+ export const INBOX_HOOK = 'sk thread inbox --hook'
13
+ const EVENTS = ['UserPromptSubmit', 'Stop'] as const
14
+
15
+ type Entry = { matcher?: string; hooks?: { type?: string; command?: string; timeout?: number }[] }
16
+ type Settings = { hooks?: Record<string, Entry[]> } & Record<string, unknown>
17
+
18
+ /** a command that reads the thread inbox as a hook: shipkit's, or a repo's own script for it */
19
+ const isInboxHook = (command: string | undefined): boolean => command !== undefined && /inbox/.test(command) && /hook/.test(command)
20
+
21
+ /** a hooks event as a list of entries: one that is no list holds none Claude Code runs */
22
+ const entries = (s: Settings, e: string): Entry[] => {
23
+ const v = s.hooks?.[e]
24
+ return Array.isArray(v) ? v : []
25
+ }
26
+
27
+ const missing = (s: Settings): string[] => EVENTS.filter((e) => !entries(s, e).some((m) => (Array.isArray(m.hooks) ? m.hooks : []).some((h) => isInboxHook(h.command))))
28
+
29
+ const read = (text: string | null): Settings | null | 'broken' => {
30
+ if (text === null) return null
31
+ try {
32
+ const v = JSON.parse(text) as unknown
33
+ return typeof v === 'object' && v !== null && !Array.isArray(v) ? (v as Settings) : 'broken'
34
+ } catch {
35
+ return 'broken'
36
+ }
37
+ }
38
+
39
+ /** the events neither file runs the hook on */
40
+ const lackOf = (tracked: Settings | null, local: Settings | null): string[] => {
41
+ const a = new Set(missing(tracked ?? {}))
42
+ return missing(local ?? {}).filter((e) => a.has(e))
43
+ }
44
+
45
+ export const threadAnswersHook = check({
46
+ id: 'SK049',
47
+ blocking: false,
48
+ title: 'thread answers hook',
49
+ description: 'the agent settings run sk thread inbox --hook on each prompt and turn end',
50
+ owner: 'tools/shipkit/built-in-checks-repo-wiring.md',
51
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: false, onHealth: true, onSave: 'moved', onClock: false },
52
+ cache: { by: 'reads' },
53
+ fix: 'ci',
54
+ applies: 'always',
55
+ run: async (c) => {
56
+ const s = read(c.read(SETTINGS))
57
+ const l = read(c.read(LOCAL))
58
+ if (s === 'broken') return void c.warn(`${SETTINGS} is not a JSON object: Claude Code loads none of its hooks`, `fix the JSON of ${SETTINGS}`)
59
+ if (l === 'broken') return void c.warn(`${LOCAL} is not a JSON object: Claude Code loads none of its hooks`, `fix the JSON of ${LOCAL}`)
60
+ const lack = lackOf(s, l)
61
+ if (lack.length === 0) return void c.ok(`the agent settings read the thread inbox on each prompt and turn end`)
62
+ const into = rootPublishesNpm(c.config) ? LOCAL : SETTINGS
63
+ c.warn(`no agent settings run the thread inbox hook on ${lack.join(', ')}: a session with no live sk thread watch never hears his answers, and nobody hears a thread whose session ended`, `sk ci repairs it: \`${INBOX_HOOK}\` on each, in ${into}, as tools/shipkit/threads.md says`)
64
+ },
65
+ repair: async (c): Promise<FixResult> => {
66
+ const s = read(c.read(SETTINGS))
67
+ const l = read(c.read(LOCAL))
68
+ if (s === 'broken' || l === 'broken') return { changed: false, summary: `${s === 'broken' ? SETTINGS : LOCAL} is not a JSON object: repair it by hand first, a merge would destroy it` }
69
+ const lack = lackOf(s, l)
70
+ if (lack.length === 0) return { changed: false, summary: 'the agent settings already read the thread inbox' }
71
+ // a root that publishes to npm: its tracked file belongs to every contributor, the hook is this machine's
72
+ const file = rootPublishesNpm(c.config) ? LOCAL : SETTINGS
73
+ const into: Settings = (file === LOCAL ? l : s) ?? {}
74
+ const hooks = { ...into.hooks }
75
+ for (const e of lack) hooks[e] = [...entries(into, e), { hooks: [{ type: 'command', command: INBOX_HOOK, timeout: 10 }] }]
76
+ c.write(file, `${JSON.stringify({ ...into, hooks }, null, 2)}\n`)
77
+ return { changed: true, summary: `${file}: ${INBOX_HOOK} on ${lack.join(', ')}` }
78
+ },
79
+ })
80
+
81
+ export default threadAnswersHook
@@ -0,0 +1,127 @@
1
+ // SK050 retired commands (tools/shipkit/built-in-checks-repo-wiring.md): a command the house retired (its config's
2
+ // `retired`) is mentioned nowhere live in a house repo. History keeps its words: the plans, repros, reviews,
3
+ // reflections, brainstorms, journal and release files, and every changelog. It warns, never fails: each repo fixes its
4
+ // own house at its next gate. `sk check --fix SK050` rewrites the plain forms only, the declared verbs, a text and an
5
+ // argv alike, and drops a manager template that names the command (the house store answers then). A mention in prose,
6
+ // a path to the old tool, a guard that greps for its name stays a warn, fixed by hand. Never applied by the gate: a
7
+ // rewrite in a public repo is read before it is committed
8
+ import { check, type CheckCtx, type FixResult } from '../check.ts'
9
+ import { parseDirectives, reaches } from '../core/waivers.ts'
10
+ import { readFileSync } from 'node:fs'
11
+ import { join } from 'node:path'
12
+
13
+ export type Retired = { command: string; use: string; verbs: string[] }
14
+
15
+ /** where history lives: a mention there is a record, never a use */
16
+ export const HISTORY = ['.shipkit/plans', '.shipkit/repros', '.shipkit/brainstorms', '.shipkit/reflections', '.shipkit/reviews', '.shipkit/journal', '.shipkit/releases']
17
+ const isHistory = (file: string): boolean => HISTORY.some((h) => file.startsWith(`${h}/`)) || /(^|\/)changelog(\/|\.md$)|(^|\/)CHANGELOG\.md$/i.test(file)
18
+
19
+ const esc = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
20
+
21
+ /** the command as a word, a path to it included (`src/old-tool`): never inside a longer name (`old-tool-test`) */
22
+ const word = (r: Retired): RegExp => new RegExp(`(?<![\\w-])${esc(r.command)}(?![\\w-])`)
23
+
24
+ /** every line of a text that mentions the command, 1-based */
25
+ export function mentions(text: string, r: Retired): number[] {
26
+ const w = word(r)
27
+ return text.split('\n').flatMap((l, i) => (w.test(l) ? [i + 1] : []))
28
+ }
29
+
30
+ /** the plain forms rewritten: `<command> <verb>` in a text, `'<command>', '<verb>'` in an argv, and a manager template
31
+ * line that names the command dropped. Everything else left as it is */
32
+ export function rewrite(text: string, r: Retired): string {
33
+ const verbs = r.verbs.map(esc).join('|')
34
+ const head = `(?<![\\w/.-])${esc(r.command)}`
35
+ const use = r.use.split(/\s+/)
36
+ return text
37
+ .replace(new RegExp(`^[ \\t]*creds(?:Read)?Command:[ \\t]*(['"\`])${esc(r.command)} [^'"\`\\n]*\\1,?[ \\t]*\\n`, 'gm'), '')
38
+ .replace(new RegExp(`(['"])${esc(r.command)}\\1(\\s*,\\s*)(['"])(${verbs})\\3`, 'g'), (_m, q: string, sep: string, q2: string, verb: string) => `${use.map((u) => `${q}${u}${q}`).join(sep)}${sep}${q2}${verb}${q2}`)
39
+ .replace(new RegExp(`${head} (${verbs})(?![\\w-])`, 'g'), `${r.use} $1`)
40
+ }
41
+
42
+ /** a file rewritten line by line, a line its own waiver reaches left as it is */
43
+ export function rewriteFile(file: string, text: string, r: Retired, id = 'SK050'): string {
44
+ const waivers = parseDirectives(file, text).filter((d) => d.reason != null && d.ids.includes(id))
45
+ const lines = text.split('\n')
46
+ return lines
47
+ .map((l, i) => {
48
+ if (waivers.some((d) => reaches(d, i + 1))) return i === lines.length - 1 ? l : `${l}\n`
49
+ const out = rewrite(`${l}\n`, r)
50
+ return i === lines.length - 1 ? out.replace(/\n$/, '') : out
51
+ })
52
+ .join('')
53
+ }
54
+
55
+ /** the house config's text, hashed: a change of the retired list asks the question again */
56
+ function houseConfigKey(root: string): string {
57
+ const { houseRootOf } = require('../home/home-start.ts') as typeof import('../home/home-start.ts')
58
+ const house = houseRootOf(root)
59
+ if (house == null) return 'no house'
60
+ try {
61
+ return String(Bun.hash(readFileSync(join(house, 'repo.config.ts'), 'utf8')))
62
+ } catch {
63
+ return 'no house config'
64
+ }
65
+ }
66
+
67
+ async function retiredOf(root: string): Promise<Retired[]> {
68
+ const { houseRootOf } = await import('../home/home-start.ts')
69
+ const { loadRepoConfig } = await import('../repo-config.ts')
70
+ const house = houseRootOf(root)
71
+ if (house == null) return []
72
+ return (await loadRepoConfig(house).catch(() => null))?.retired ?? []
73
+ }
74
+
75
+ /** the live tracked files that name a command, one git grep */
76
+ async function filesNaming(c: CheckCtx, command: string): Promise<string[]> {
77
+ const r = await c.exec(['git', 'grep', '-l', '-I', '-F', '-e', command], { cwd: c.root, timeoutMs: 10_000 })
78
+ return r.out.split('\n').filter((f) => f !== '' && !isHistory(f))
79
+ }
80
+
81
+ export const retiredCommands = check({
82
+ id: 'SK050',
83
+ blocking: false,
84
+ title: 'retired commands',
85
+ description: 'no live mention of a command the house retired; the plain forms rewrite with --fix',
86
+ owner: 'tools/shipkit/built-in-checks-repo-wiring.md',
87
+ runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: false, onHealth: true, onSave: false, onClock: false },
88
+ // the whole tree, and the house config's text: the retired list lives there
89
+ cache: { by: 'files', inputs: ['.'], key: (env) => houseConfigKey(env.root) },
90
+ fix: 'manual',
91
+ applies: 'always',
92
+ run: async (c) => {
93
+ const retired = await retiredOf(c.root)
94
+ if (retired.length === 0) return c.ok('the house retires no command')
95
+ let sites = 0
96
+ for (const r of retired) {
97
+ for (const file of await filesNaming(c, r.command)) {
98
+ const text = c.read(file)
99
+ if (text == null) continue
100
+ const lines = text.split('\n')
101
+ for (const line of mentions(text, r)) {
102
+ sites++
103
+ const fixable = rewrite(`${lines[line - 1]}\n`, r) !== `${lines[line - 1]}\n`
104
+ c.warn(`${r.command} is retired: use ${r.use}`, { fix: fixable ? `sk check --fix SK050 rewrites it` : `rewrite it by hand to ${r.use} (wiki services/secrets)`, at: { file, line } })
105
+ }
106
+ }
107
+ }
108
+ if (sites === 0) c.ok(`no live mention of ${retired.map((r) => r.command).join(', ')}`)
109
+ },
110
+ repair: async (c): Promise<FixResult> => {
111
+ const retired = await retiredOf(c.root)
112
+ const changed: string[] = []
113
+ for (const r of retired)
114
+ for (const file of await filesNaming(c, r.command)) {
115
+ const text = c.read(file)
116
+ if (text == null) continue
117
+ const next = rewriteFile(file, text, r)
118
+ if (next !== text) {
119
+ c.write(file, next)
120
+ changed.push(file)
121
+ }
122
+ }
123
+ return { changed: changed.length > 0, summary: changed.length === 0 ? 'no plain form to rewrite' : `rewrote ${changed.length} file${changed.length === 1 ? '' : 's'}: ${changed.join(', ')}; read the diff before committing` }
124
+ },
125
+ })
126
+
127
+ export default retiredCommands