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
@@ -101,20 +101,36 @@ export async function listObjects(c: SpaceConfig): Promise<{ rows: Listed[]; cal
101
101
  export async function listVersions(c: SpaceConfig): Promise<{ versions: Split & { markers: number }; calls: number }> {
102
102
  const old: { key: string; size: number }[] = []
103
103
  let markers = 0
104
+ const calls = await eachVersion(c, {}, (v) => {
105
+ if (v.marker) markers++
106
+ else if (!v.latest) old.push({ key: v.key, size: v.size })
107
+ })
108
+ return { versions: { ...splitOf(old), markers }, calls }
109
+ }
110
+
111
+ /** one version or delete marker of a key, as ListObjectVersions answers it */
112
+ export type VersionRow = { key: string; versionId: string; latest: boolean; marker: boolean; modified: number | null; size: number }
113
+
114
+ /** every version and delete marker (under `prefix`), a page of 1,000 at a time, in the bucket's order: a key's
115
+ * versions together, newest first. The calls it took */
116
+ export async function eachVersion(c: SpaceConfig, o: { prefix?: string }, fn: (v: VersionRow) => void): Promise<number> {
104
117
  let calls = 0
105
118
  let key: string | null = null
106
119
  let vid: string | null = null
107
120
  do {
108
- const text = await listCall(c, { versions: '', 'max-keys': '1000', ...(key != null ? { 'key-marker': key } : {}), ...(vid != null ? { 'version-id-marker': vid } : {}) })
121
+ const text = await listCall(c, { versions: '', 'max-keys': '1000', ...(o.prefix ? { prefix: o.prefix } : {}), ...(key != null ? { 'key-marker': key } : {}), ...(vid != null ? { 'version-id-marker': vid } : {}) })
109
122
  calls++
110
- for (const m of text.matchAll(/<Version>([\s\S]*?)<\/Version>/g)) if (tagOf(m[1]!, 'IsLatest') === 'false') old.push({ key: tagOf(m[1]!, 'Key') ?? '', size: Number(tagOf(m[1]!, 'Size') ?? 0) })
111
- markers += [...text.matchAll(/<DeleteMarker>/g)].length
123
+ for (const m of text.matchAll(/<(Version|DeleteMarker)>([\s\S]*?)<\/\1>/g)) {
124
+ const b = m[2]!
125
+ const at = tagOf(b, 'LastModified')
126
+ fn({ key: tagOf(b, 'Key') ?? '', versionId: tagOf(b, 'VersionId') ?? '', latest: tagOf(b, 'IsLatest') === 'true', marker: m[1] === 'DeleteMarker', modified: at ? Date.parse(at) || null : null, size: Number(tagOf(b, 'Size') ?? 0) })
127
+ }
112
128
  const more = /<IsTruncated>true<\/IsTruncated>/.test(text)
113
129
  key = more ? tagOf(text, 'NextKeyMarker') : null
114
130
  vid = more ? tagOf(text, 'NextVersionIdMarker') : null
115
131
  if (more && key == null) throw new Error(`the versions of ${c.bucket} say more and name no next page`)
116
132
  } while (key != null)
117
- return { versions: { ...splitOf(old), markers }, calls }
133
+ return calls
118
134
  }
119
135
 
120
136
  /** the uploads never completed, a page of 1,000 at a time; a part's size is not in this answer */
@@ -1,8 +1,8 @@
1
1
  // the private S3 bucket that keeps every media file of the machine's store (wiki tools/shipkit/media-store.md), named by
2
2
  // the house config's `serve.mediaSpace`. Every object is PRIVATE but those under `public/`, and the key alone decides
3
3
  // (`aclOf`); never a bucket policy, never a public listing. A page reads a private one through a URL signed for one hour,
4
- // on the CDN edge. The key pair (`KEY:SECRET`) is read through the house's
5
- // `credsReadCommand`, held in memory only: never written to a file, never printed
4
+ // on the CDN edge. The key pair (`KEY:SECRET`) is read through the house
5
+ // store, held in memory only: never written to a file, never printed
6
6
  import { S3Client } from 'bun'
7
7
  import { mkdirSync, renameSync, rmSync } from 'node:fs'
8
8
  import { dirname } from 'node:path'
@@ -15,7 +15,7 @@ export interface MediaSpace {
15
15
  region: string
16
16
  /** the CDN edge a signed URL is handed out on */
17
17
  cdn?: string
18
- /** the secret whose value is `KEY:SECRET`, read through `credsReadCommand` */
18
+ /** the secret whose value is `KEY:SECRET`, read through the house store */
19
19
  secret: string
20
20
  }
21
21
 
@@ -221,9 +221,11 @@ let config: { at: number; config: SpaceConfig | null; why: string } | null = nul
221
221
 
222
222
  /** the house's Space as a config, the key pair read: what a hand signed call needs (forget.ts) */
223
223
  export async function houseSpaceConfig(secret?: string): Promise<{ config: SpaceConfig | null; why: string }> {
224
+ // SHIPKIT_SPACES=off beats a house config read before; a test's own config (useSpaceConfig) stays its own
225
+ const injected = config?.at === Infinity
226
+ if (process.env.SHIPKIT_SPACES === 'off' && !injected) return { config: null, why: 'SHIPKIT_SPACES=off' }
224
227
  if (secret === undefined && config && Date.now() - config.at <= SPACE_KEY_HELD_MS) return { config: config.config, why: config.why }
225
228
  const out = await (async (): Promise<{ config: SpaceConfig | null; why: string }> => {
226
- if (process.env.SHIPKIT_SPACES === 'off') return { config: null, why: 'SHIPKIT_SPACES=off' }
227
229
  const { houseRootOf } = await import('../home/home-start.ts')
228
230
  const { loadRepoConfig } = await import('../repo-config.ts')
229
231
  const house = houseRootOf(process.cwd())
@@ -231,7 +233,6 @@ export async function houseSpaceConfig(secret?: string): Promise<{ config: Space
231
233
  const c = await loadRepoConfig(house)
232
234
  const r = c.serve?.mediaSpace
233
235
  if (!r) return { config: null, why: `the house config (${house}) names no serve.mediaSpace` }
234
- if (!c.credsReadCommand) return { config: null, why: `the house config (${house}) declares no credsReadCommand to read ${r.secret}` }
235
236
  const name = secret ?? r.secret
236
237
  let v = ''
237
238
  try {
@@ -0,0 +1,49 @@
1
+ // an agent's new persona or value proposition written by hand into the store (wiki tools/shipkit/messages.md, Objects in
2
+ // threads): refused by the PreToolUse guard (hooks/one-way-in-guard.ts) with the verb to type instead, since the owner
3
+ // decides those in a thread. A field filled, a candidate phrasing, a fix of words, anything in surfaces.md, and a store
4
+ // written whole for the first time pass. Pure and tiny: the guard runs before every edit and every Bash call
5
+ export const STORE_FILE = /(?:^|\/)\.shipkit\/messages\/(personas|messages)\.md$/
6
+
7
+ /** the section ids of a store file's text, comments left out, each as many times as it heads a section */
8
+ export function sectionIds(md: string): string[] {
9
+ return [...md.replace(/<!--[\s\S]*?-->/g, '').matchAll(/^## ([\w-]+)[ :]/gm)].map((m) => m[1]!.toLowerCase())
10
+ }
11
+
12
+ const refusal = (what: 'personas' | 'messages', heads: string[]): string => {
13
+ const persona = what === 'personas'
14
+ return `${heads.map((id) => `## ${id}`).join(', ')}: a new ${persona ? 'persona' : 'value proposition'} is the owner's decision, so it goes to the owner in a thread: sk messages propose ${persona ? 'persona' : 'message'} <id> … "<why>"; the owner's approval writes it into ${what}.md. A field, a candidate phrasing or a fix of words stays a plain edit. Even when the owner asked for this one by hand, propose it: approving it is one click`
15
+ }
16
+
17
+ /** why this edit of a store file is refused, or null: it adds a section the file did not have, a case twin included.
18
+ * `before` the file as it is on the disk ('' when it does not exist yet), `after` the file as the edit leaves it */
19
+ export function handWriteRefusal(path: string, before: string, after: string): string | null {
20
+ const m = STORE_FILE.exec(path.replace(/\\/g, '/'))
21
+ if (m == null || before.trim() === '') return null
22
+ const had = sectionIds(before)
23
+ const left = [...had]
24
+ const added = sectionIds(after).filter((id) => {
25
+ const i = left.indexOf(id)
26
+ if (i === -1) return true
27
+ left.splice(i, 1)
28
+ return false
29
+ })
30
+ return added.length === 0 ? null : refusal(m[1] as 'personas' | 'messages', added)
31
+ }
32
+
33
+ /** why this Bash call is refused, or null: it appends or writes a section head into a store file (`>>`, `>`, `tee`) */
34
+ export function bashHandWriteRefusal(command: string): string | null {
35
+ const into = /(?:>>?|\btee\b(?:\s+-a)?)\s*["']?([^\s"'|;&]*\.shipkit\/messages\/(personas|messages)\.md)/.exec(command)
36
+ if (into == null || !/(^|\\n|\n|["'])\s*## [\w-]+[ :(]/.test(command)) return null
37
+ const heads = [...command.matchAll(/(?:^|\\n|\n|["'])\s*## ([\w-]+)[ :(]/g)].map((x) => x[1]!.toLowerCase())
38
+ return refusal(into[2] as 'personas' | 'messages', heads)
39
+ }
40
+
41
+ /** the file an Edit, a MultiEdit or a Write leaves, from the text on the disk; null when it is no such tool */
42
+ export function afterEdit(tool: string, input: Record<string, unknown>, before: string): string | null {
43
+ const str = (v: unknown): string => (typeof v === 'string' ? v : '')
44
+ if (tool === 'Write') return str(input.content)
45
+ const one = (text: string, e: Record<string, unknown>): string => (e.replace_all === true ? text.split(str(e.old_string)).join(str(e.new_string)) : text.replace(str(e.old_string), () => str(e.new_string)))
46
+ if (tool === 'Edit') return one(before, input)
47
+ if (tool === 'MultiEdit' && Array.isArray(input.edits)) return (input.edits as Record<string, unknown>[]).reduce(one, before)
48
+ return null
49
+ }
@@ -135,7 +135,7 @@ export function lintSurfaces(surfaces: Surface[], guard: Guard): string[] {
135
135
  }
136
136
 
137
137
  /** the store's files read whole; a store with no personas.md or surfaces.md reads as none */
138
- /** `hash`: messages.md as read, so a write from the page refuses a file that changed under it (suggest.ts) */
138
+ /** `hash`: messages.md as read, so a write from the page refuses a file that changed under it (write.ts) */
139
139
  export type Store = { dir: string; hash: string; messages: Message[]; personas: Persona[]; surfaces: Surface[]; brief: Brief }
140
140
 
141
141
  export const hashOf = (text: string): string => Bun.hash(text).toString(36)
@@ -0,0 +1,201 @@
1
+ // the messages store's objects (wiki tools/shipkit/messages.md, Objects in threads): a persona, a value proposition and
2
+ // its phrasings, a page top and its options, each by its address (`persona:<id>`, `messages:<message>[/<phrasing>]`,
3
+ // `surface:<surface>[/<option>]`), read from the md as the one truth: its json (what an apply writes back) and its card
4
+ // (what the hub draws), with the scores of the newest run that scored it. The one constraint a reader breaks first: a
5
+ // repo's worktrees share one thread store, so every read is the main checkout's, never the caller's tree
6
+ import { existsSync, readFileSync } from 'node:fs'
7
+ import { basename, dirname, join } from 'node:path'
8
+ import { gitRoot } from '../core/git-root.ts'
9
+ import type { CardLine, CardScore, CardState, ObjectCard } from '../review/object-card.ts'
10
+ import { MESSAGES_DIR, parseBrief, parseMessages, parsePersonas, parseSurfaces, runsOf, type Message, type Persona, type Surface } from './model.ts'
11
+ import { PASS, runView, VETO, type RunView } from './score.ts'
12
+
13
+ export const OBJECT_KINDS = ['persona', 'messages', 'surface'] as const
14
+ export type ObjectKind = (typeof OBJECT_KINDS)[number]
15
+ export const isObjectKind = (w: string): w is ObjectKind => (OBJECT_KINDS as readonly string[]).includes(w)
16
+
17
+ /** the file of the store each kind lives in */
18
+ export const FILE_OF: Record<ObjectKind, string> = { persona: 'personas.md', messages: 'messages.md', surface: 'surfaces.md' }
19
+
20
+ export type PersonaJson = { id: string; role: 'reader' | 'gatekeeper'; who: string }
21
+ export type PhrasingJson = { id: string; text: string; source: string }
22
+ /** a value proposition: its fields as written, `toFill` those written with no value */
23
+ export type MessageJson = { id: string; title: string; fields: Record<string, string>; toFill: string[]; phrasings: PhrasingJson[] }
24
+ export type OneJson = PhrasingJson & { message: string }
25
+ export type OptionJson = { id: string; headline: string; second: string }
26
+ export type SurfaceJson = { id: string; title: string; budget?: number; shot?: string; options: OptionJson[] }
27
+ export type OneOptionJson = OptionJson & { surface: string }
28
+ export type ObjectJson = PersonaJson | MessageJson | OneJson | SurfaceJson | OneOptionJson
29
+
30
+ /** the repo's main checkout: a worktree's own copy of the store is its branch's, the threads are the repo's */
31
+ export function mainRoot(root: string): string {
32
+ const g = gitRoot(root)
33
+ if (g == null || basename(g.commonDir) !== '.git') return root
34
+ return dirname(g.commonDir)
35
+ }
36
+
37
+ /** a file of the store, at a git ref of the main checkout or in its working tree; '' when it has none */
38
+ export function storeText(root: string, file: string, at?: string): string {
39
+ const main = mainRoot(root)
40
+ if (at === undefined) {
41
+ const f = join(main, MESSAGES_DIR, file)
42
+ return existsSync(f) ? readFileSync(f, 'utf8') : ''
43
+ }
44
+ const p = Bun.spawnSync(['git', '-C', main, 'show', `${at}:${MESSAGES_DIR}/${file}`], { stdout: 'pipe', stderr: 'ignore' })
45
+ return p.exitCode === 0 ? p.stdout.toString() : ''
46
+ }
47
+
48
+ /** an address's key in its parts; an object kind's key is lowercased by the store, so ids match whatever their case */
49
+ export function keyParts(key: string): { id: string; part?: string } {
50
+ const at = key.indexOf('/')
51
+ return at === -1 ? { id: key } : { id: key.slice(0, at), part: key.slice(at + 1) }
52
+ }
53
+
54
+ const same = (a: string, b: string): boolean => a.toLowerCase() === b.toLowerCase()
55
+
56
+ export const personaJson = (p: Persona): PersonaJson => ({ id: p.id, role: p.kind, who: p.who })
57
+ export const messageJson = (m: Message): MessageJson => ({ id: m.id, title: m.title, fields: { ...m.fields }, toFill: [...m.toFill], phrasings: m.candidates.map((c) => ({ id: c.id, text: c.text, source: c.source })) })
58
+ export const surfaceJson = (s: Surface): SurfaceJson => ({ id: s.id, title: s.title, ...(s.budget !== undefined ? { budget: s.budget } : {}), ...(s.shot !== undefined ? { shot: s.shot } : {}), options: s.options.map((o) => ({ ...o })) })
59
+
60
+ /** one object's json as the md holds it now (or at `at`), null when the md has none by that key */
61
+ export function objectJson(root: string, kind: ObjectKind, key: string, at?: string): ObjectJson | null {
62
+ const text = storeText(root, FILE_OF[kind], at)
63
+ const { id, part } = keyParts(key)
64
+ if (kind === 'persona') {
65
+ const p = parsePersonas(text).find((x) => same(x.id, id))
66
+ return p == null || part !== undefined ? null : personaJson(p)
67
+ }
68
+ if (kind === 'messages') {
69
+ const m = parseMessages(text).find((x) => same(x.id, id))
70
+ if (m == null) return null
71
+ if (part === undefined) return messageJson(m)
72
+ const c = m.candidates.find((x) => same(x.id, part))
73
+ return c == null ? null : { message: m.id, id: c.id, text: c.text, source: c.source }
74
+ }
75
+ const s = parseSurfaces(text).find((x) => same(x.id, id))
76
+ if (s == null) return null
77
+ if (part === undefined) return surfaceJson(s)
78
+ const o = s.options.find((x) => same(x.id, part))
79
+ return o == null ? null : { surface: s.id, ...o }
80
+ }
81
+
82
+ // ---- scores
83
+
84
+ /** the newest run of a kind that scored one of `ids`, read only that far back: a run is a folder of the sub-agents' json */
85
+ function newestRunOf(root: string, kind: RunView['kind'], ids: readonly string[]): RunView | null {
86
+ const dir = join(mainRoot(root), MESSAGES_DIR)
87
+ const takeaways = parseBrief(storeText(root, 'brief.md')).takeaways
88
+ for (const r of runsOf(dir)) {
89
+ const v = runView(join(dir, 'runs', r), r, takeaways)
90
+ if (v.kind !== kind) continue
91
+ if (kind === 'messages' ? ids.some((i) => v.cells[i] != null) : v.surface.some((s) => ids.includes(s.option))) return v
92
+ }
93
+ return null
94
+ }
95
+
96
+ const mean = (xs: number[]): number | null => (xs.length ? Math.round(xs.reduce((a, b) => a + b, 0) / xs.length) : null)
97
+
98
+ /** a phrasing's scores in a messages run: each reader's cell, each gatekeeper's refusal */
99
+ function phrasingScores(v: RunView, id: string): { scores: CardScore[]; best: number | null } {
100
+ const cells = v.cells[id] ?? {}
101
+ const scores: CardScore[] = v.readers.map((p) => (cells[p] ? { who: p, score: cells[p]!.score, said: cells[p]!.said } : { who: p, score: null }))
102
+ for (const [g, x] of Object.entries(v.verdicts[id] ?? {})) if (VETO.test(x.verdict)) scores.push({ who: g, score: null, said: `${x.verdict}${x.words ? `: ${x.words}` : ''}`, veto: true })
103
+ return { scores, best: mean(Object.values(cells).map((c) => c.score)) }
104
+ }
105
+
106
+ // ---- cards
107
+
108
+ const FIELD_ORDER = ['meaning', 'value', 'truth', 'never', 'held']
109
+
110
+ function messageCard(m: MessageJson, v: RunView | null, only?: string): ObjectCard {
111
+ const chips = [m.fields.family, m.fields.held ? 'held' : undefined].filter((x): x is string => !!x)
112
+ const fields: NonNullable<ObjectCard['fields']> = []
113
+ for (const k of FIELD_ORDER) {
114
+ if (m.fields[k]) fields.push({ label: k, text: m.fields[k]! })
115
+ else if (m.toFill.includes(k)) fields.push({ label: k, text: 'to fill', fill: true })
116
+ }
117
+ const lines: CardLine[] = m.phrasings
118
+ .filter((p) => only === undefined || p.id === only)
119
+ .map((p) => ({ id: p.id, text: p.text, note: p.source, ...(v && v.cells[p.id] ? { ...phrasingScores(v, p.id), run: v.id } : {}) }))
120
+ return { kind: only === undefined ? 'value proposition' : 'phrasing', title: m.title, ...(chips.length ? { chips } : {}), fields, lines }
121
+ }
122
+
123
+ function personaCard(p: PersonaJson, v: RunView | null): ObjectCard {
124
+ const card: ObjectCard = { kind: 'persona', title: p.id, chips: [p.role], fields: [{ label: 'who', text: p.who }] }
125
+ if (v == null) return card
126
+ if (p.role === 'reader') {
127
+ const mine = Object.entries(v.cells)
128
+ .flatMap(([id, c]) => (c[p.id] ? [{ id, score: c[p.id]!.score, said: c[p.id]!.said }] : []))
129
+ .sort((a, b) => b.score - a.score)
130
+ const pick = mine.length > 6 ? [...mine.slice(0, 3), ...mine.slice(-3)] : mine
131
+ card.lines = pick.map((x) => ({ id: x.id, text: x.said, best: x.score, run: v.id }))
132
+ } else {
133
+ card.lines = Object.entries(v.verdicts)
134
+ .flatMap(([id, by]) => (by[p.id] && !PASS.test(by[p.id]!.verdict) ? [{ id, text: `${by[p.id]!.verdict}${by[p.id]!.words ? `: ${by[p.id]!.words}` : ''}`, run: v.id }] : []))
135
+ .slice(0, 8)
136
+ }
137
+ return card
138
+ }
139
+
140
+ function surfaceCard(s: SurfaceJson, v: RunView | null, only?: string): ObjectCard {
141
+ const fields: NonNullable<ObjectCard['fields']> = []
142
+ if (s.budget !== undefined) fields.push({ label: 'budget', text: `${s.budget} characters` })
143
+ if (s.shot !== undefined) fields.push({ label: 'shot', text: s.shot })
144
+ const lines: CardLine[] = s.options
145
+ .filter((o) => only === undefined || o.id === only)
146
+ .map((o) => {
147
+ const n = (o.second ? `${o.headline} ${o.second}` : o.headline).length
148
+ const row = v?.surface.find((r) => r.option === o.id)
149
+ return {
150
+ id: o.id,
151
+ text: o.headline,
152
+ ...(o.second ? { second: o.second } : {}),
153
+ note: `${n}${s.budget !== undefined ? `/${s.budget}` : ''} characters`,
154
+ ...(row && v ? { best: row.veto ? null : row.score, run: v.id, scores: row.gatekeepers.map((g) => ({ who: g.split(' ')[0]!, score: null, said: g, veto: true as const })) } : {}),
155
+ }
156
+ })
157
+ return { kind: only === undefined ? 'page top' : 'page top option', title: s.title, fields, lines }
158
+ }
159
+
160
+ /** an object's card from its json: with the scores of the newest run that scored it when `scores` */
161
+ export function cardOfJson(root: string, kind: ObjectKind, json: ObjectJson, scores = true): ObjectCard {
162
+ if (kind === 'persona') {
163
+ const p = json as PersonaJson
164
+ return personaCard(p, scores ? newestAnyMessagesRun(root, p.id) : null)
165
+ }
166
+ if (kind === 'messages') {
167
+ if ('phrasings' in json) {
168
+ const m = json as MessageJson
169
+ return messageCard(m, scores ? newestRunOf(root, 'messages', m.phrasings.map((p) => p.id)) : null)
170
+ }
171
+ const one = json as OneJson
172
+ const m = parseMessages(storeText(root, 'messages.md')).find((x) => x.id === one.message)
173
+ const base: MessageJson = m ? messageJson(m) : { id: one.message, title: one.message, fields: {}, toFill: [], phrasings: [] }
174
+ const rest = base.phrasings.filter((p) => p.id !== one.id)
175
+ return messageCard({ ...base, phrasings: [...rest, { id: one.id, text: one.text, source: one.source }] }, scores ? newestRunOf(root, 'messages', [one.id]) : null, one.id)
176
+ }
177
+ if ('options' in json) {
178
+ const s = json as SurfaceJson
179
+ return surfaceCard(s, scores ? newestRunOf(root, 'surface', s.options.map((o) => o.id)) : null)
180
+ }
181
+ const one = json as OneOptionJson
182
+ const s = parseSurfaces(storeText(root, 'surfaces.md')).find((x) => x.id === one.surface)
183
+ const base: SurfaceJson = s ? surfaceJson(s) : { id: one.surface, title: one.surface, options: [] }
184
+ return surfaceCard({ ...base, options: [...base.options.filter((o) => o.id !== one.id), { id: one.id, headline: one.headline, second: one.second }] }, scores ? newestRunOf(root, 'surface', [one.id]) : null, one.id)
185
+ }
186
+
187
+ /** the newest messages run a persona read in, or judged as a gatekeeper */
188
+ function newestAnyMessagesRun(root: string, persona: string): RunView | null {
189
+ const dir = join(mainRoot(root), MESSAGES_DIR)
190
+ for (const r of runsOf(dir)) {
191
+ const v = runView(join(dir, 'runs', r), r, [])
192
+ if (v.kind === 'messages' && (v.readers.includes(persona) || v.gatekeepers.includes(persona))) return v
193
+ }
194
+ return null
195
+ }
196
+
197
+ /** the object as a kind's `read` returns it: its json and its card, null when the md has none by that key */
198
+ export function readObject(root: string, kind: ObjectKind, key: string, at?: string): CardState | null {
199
+ const json = objectJson(root, kind, key, at)
200
+ return json == null ? null : { json, card: cardOfJson(root, kind, json, at === undefined) }
201
+ }
@@ -1,8 +1,8 @@
1
1
  // the messages page's routes (wiki tools/shipkit/messages.md, The page): the whole store read fresh on each load, and
2
- // the owner's suggestions appended to messages.md (suggest.ts). Every other edit of the store is made as text
2
+ // the owner's suggestions appended to messages.md (write.ts). An agent's new object lands through the owner's verdict (write.ts applyObject)
3
3
  import { bad, NO_STORE } from '../review/http.ts'
4
4
  import { storeView } from './score.ts'
5
- import { Changed, suggest, type Suggestion } from './suggest.ts'
5
+ import { Changed, suggest, type Suggestion } from './write.ts'
6
6
 
7
7
  /** the messages routes of the repo at `root`; null for any other path */
8
8
  export async function messagesRoutes(root: string, req: Request, path: string): Promise<Response | null> {
@@ -155,7 +155,7 @@ export type RunView = {
155
155
 
156
156
  export type StoreView = Pick<Store, 'hash' | 'messages' | 'personas' | 'surfaces'> & { takeaways: Takeaway[]; runs: RunView[] }
157
157
 
158
- function runView(dir: string, id: string, takeaways: readonly Takeaway[]): RunView {
158
+ export function runView(dir: string, id: string, takeaways: readonly Takeaway[]): RunView {
159
159
  const readings = jsonsIn(join(dir, 'readings')).map((f) => [f.slice(0, -5), readJson<unknown[]>(join(dir, 'readings', f))] as const)
160
160
  const surface = readings.some(([, rs]) => rs.some((r) => typeof r === 'object' && r !== null && 'option' in r))
161
161
  const verdicts: RunView['verdicts'] = {}