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,21 +1,25 @@
1
1
  // the one read of a secret on this machine, and its one write (wiki services/secrets): every reader of the lib and
2
- // the house's command line tool come here. On the machine that runs the vault, the vault is the store: a name is read
3
- // there first, and the keychain only when the vault does not hold it or does not answer, with one line on stderr
4
- // that says so. Elsewhere the house's secret manager (`credsReadCommand`) as before. An env override answers before
5
- // anything. A value never rides an argv, a log or an error
2
+ // the house's command line tool come here. One vault, the master on the Mac that carries the hq: there it is read on
3
+ // loopback, and on a Mac whose daemon joined that hq through the hq's vault route with the node's tokens. A name is
4
+ // read there first, and the keychain only when the vault does not hold it or does not answer, with one line on
5
+ // stderr that says so. Writes happen on the master's Mac alone. A Mac with neither reads its login keychain, or the
6
+ // manager a repo declares (`credsReadCommand`) for secrets kept elsewhere. An env override answers before anything.
7
+ // A value never rides a log or an error, nor an argv but the keychain write's one call to `security` (keychain-write.ts)
6
8
  import { existsSync } from 'fs'
7
9
  import { scopesAll, type Scope } from '../core/scope.ts'
8
10
  import { KV_MOUNT, pathOf } from '../vault/layout.ts'
9
11
  import { setInVault } from '../vault/vault-client.ts'
10
12
  import { markerFile, refuseRealVault, vaultPlace, vaultUrl } from '../vault/vault-config.ts'
11
13
  import { VaultApi, VaultError, vaultHealth } from '../vault/vault-http.ts'
14
+ import { archivedLine, type Archived } from './archive-mark.ts'
12
15
  import type { Held } from './held.ts'
13
- import { keychainReader } from './keychain.ts'
16
+ import { keychainReader, LOCKED_EXIT } from './keychain.ts'
14
17
  import type { Presence } from './list.ts'
15
18
  import { houseScopeOf, managerTemplate, readRefusal, secretsWhere, type SecretsWhere } from './manager.ts'
16
19
 
17
20
  export type Field = 'get' | 'account'
18
- export type Read = { value: string; from: 'env' | 'vault' | 'keychain' | 'manager' } | { refused: string } | { missing: string }
21
+ /** `locked`: the keychain holds it but is locked to this session (an ssh one), `security` exit 36 */
22
+ export type Read = { value: string; from: 'env' | 'vault' | 'keychain' | 'manager' } | { refused: string } | { missing: string; locked?: true }
19
23
 
20
24
  /** `rv/foo-bar/baz` → `RV_SECRET_FOO_BAR_BAZ`, `_ACCOUNT` after it for the account */
21
25
  export const envVarOf = (name: string, field: Field = 'get'): string => `RV_SECRET_${name.replace(/^rv\//, '').toUpperCase().replace(/[^A-Z0-9]/g, '_')}${field === 'account' ? '_ACCOUNT' : ''}`
@@ -43,18 +47,56 @@ export const STRIKES = 2
43
47
  let skipUntil = 0
44
48
  let strikes = 0
45
49
 
46
- let api: { token: string; vault: VaultApi } | null = null
50
+ /** where this machine reads the vault: `here` on the Mac that runs it, `master` through the vault route of the hq
51
+ * this daemon joined on another Mac (its host, the hq token the route wants), null for neither. The master is read
52
+ * only once this daemon holds a vault token its hq gave */
53
+ export type VaultReach = { at: 'here'; url: string; headers: Record<string, string> } | { at: 'master'; url: string; host: string; headers: Record<string, string> }
54
+
55
+ export async function vaultReach(): Promise<VaultReach | null> {
56
+ if (vaultHere()) return { at: 'here', url: vaultUrl(vaultPlace()), headers: {} }
57
+ const { carriesHq, hqUrl, readHqToken, readVaultToken } = await import('../hq/hq-local.ts')
58
+ if (carriesHq()) return null
59
+ const hq = readHqToken()
60
+ if (hq == null || readVaultToken() == null) return null
61
+ return { at: 'master', url: `${hqUrl().replace(/\/$/, '')}/hq/vault`, host: new URL(hqUrl()).hostname, headers: { authorization: `Bearer ${hq}` } }
62
+ }
63
+
64
+ /** the words of the vault a read reached: the master's host, for a Mac that reads it from afar */
65
+ const vaultWords = (r: VaultReach): string => (r.at === 'here' ? 'the vault' : `the master vault on ${r.host.split('.')[0]}`)
66
+
67
+ let api: { token: string; url: string; vault: VaultApi } | null = null
47
68
  /** the vault as this daemon's token reads it. The token is read from its file again when it changed (the vault job
48
69
  * renews it each 12 h and the hq revokes the old one), so a process that lives long never keeps a dead token */
49
70
  async function vaultApi(fresh = false): Promise<VaultApi | null> {
50
71
  const { readVaultToken } = await import('../hq/hq-local.ts')
51
- if (api != null && !fresh) return api.vault
72
+ const reach = await vaultReach()
73
+ if (api != null && !fresh && api.url === reach?.url) return api.vault
52
74
  const token = readVaultToken()
53
- if (token == null) return (api = null)
54
- if (api?.token !== token) api = { token, vault: new VaultApi(vaultUrl(vaultPlace()), token, READ_BUDGET_MS) }
75
+ if (token == null || reach == null) return (api = null)
76
+ if (api?.token !== token || api.url !== reach.url) api = { token, url: reach.url, vault: new VaultApi(reach.url, token, READ_BUDGET_MS, reach.headers) }
55
77
  return api.vault
56
78
  }
57
79
 
80
+ /** why the master did not answer, asked of tailscale only now: is its Mac online on the tailnet */
81
+ async function masterSilence(host: string): Promise<string> {
82
+ const short = host.split('.')[0]
83
+ // a tailnet name only: tailscale knows nothing of another host
84
+ if (!host.endsWith('.ts.net')) return `the master vault on ${short} does not answer`
85
+ try {
86
+ const { tailscaleJson } = await import('../home/machine-host.ts')
87
+ const st = (await tailscaleJson(['status', '--json'])) as { Peer?: Record<string, { DNSName?: string; Online?: boolean; LastSeen?: string }> } | null
88
+ const peer = Object.values(st?.Peer ?? {}).find((p) => (p.DNSName ?? '').replace(/\.$/, '').toLowerCase() === host.toLowerCase())
89
+ if (peer == null) return `the master vault on ${short} does not answer, and tailscale on this Mac does not list ${host}`
90
+ if (peer.Online === false) {
91
+ const seen = peer.LastSeen == null ? NaN : Date.parse(peer.LastSeen)
92
+ return `the master vault does not answer: ${short} is offline on the tailnet${Number.isNaN(seen) ? '' : `, last seen ${Math.round((Date.now() - seen) / 60_000)} min ago`} (it sleeps or is off)`
93
+ }
94
+ return `the master vault on ${short} does not answer though ${short} is online: its daemon may be restarting (sk pm there), or its hq port is closed (sk hq open there)`
95
+ } catch {
96
+ return `the master vault on ${short} does not answer`
97
+ }
98
+ }
99
+
58
100
  /** where a registry name lives in the vault for the asker: one scope only. A repo row names the repo by its id, and
59
101
  * the asker standing in that repo gives its key (the scope gate has let it in). Null with no place */
60
102
  export function vaultPathFor(w: SecretsWhere, name: string): string | null {
@@ -71,6 +113,9 @@ export function vaultPathFor(w: SecretsWhere, name: string): string | null {
71
113
  return pathOf(name, s)
72
114
  }
73
115
 
116
+ /** the house registry's archive mark of a name, or null */
117
+ export const archivedIn = (w: SecretsWhere, name: string): Archived | null => w.house?.creds?.find((c) => c.name === name)?.archived ?? null
118
+
74
119
  /** one name from the vault: a 403 reads the token file again and tries once more (a token renewed since); STRIKES
75
120
  * calls in a row that run out of their budget make the next reads of this process skip the vault for SKIP_MS */
76
121
  async function readVault(path: string, field: Field): Promise<{ value: string } | { why: string }> {
@@ -91,6 +136,12 @@ async function readVault(path: string, field: Field): Promise<{ value: string }
91
136
  skipUntil = Date.now() + SKIP_MS
92
137
  return { why: `the vault did not answer within ${READ_BUDGET_MS} ms, ${strikes} times in a row; this process reads the keychain for ${SKIP_MS / 1000} s` }
93
138
  }
139
+ const reach = await vaultReach()
140
+ if (reach?.at === 'master') {
141
+ if (e instanceof VaultError && e.status > 0) return { why: `the master vault on ${reach.host.split('.')[0]} refused the read: ${(e as Error).message.replace(/^[A-Z]+ \S+: /, '')}` }
142
+ const h = await vaultHealth(reach.url, 500, reach.headers)
143
+ return { why: h == null ? await masterSilence(reach.host) : h.sealed ? `the master vault on ${reach.host.split('.')[0]} is sealed` : `the master vault refused the read (${(e as Error).message})` }
144
+ }
94
145
  const h = await vaultHealth(vaultUrl(vaultPlace()), 500)
95
146
  return { why: h == null ? 'the vault does not answer' : h.sealed ? 'the vault is sealed' : `the vault refused the read (${(e as Error).message.replace(/^.*: (\d{3}).*$/, '$1')})` }
96
147
  }
@@ -110,25 +161,49 @@ function fromKeychain(name: string, field: Field): string | null {
110
161
  function fromManager(template: string, name: string, field: Field, cwd: string): Read {
111
162
  const argv = template.trim().split(/\s+/).map((x) => x.replaceAll('{name}', name).replaceAll('{field}', field))
112
163
  if (argv[0] == null || Bun.which(argv[0]) == null) return { missing: `credsReadCommand names '${argv[0] ?? ''}', which is not on PATH` }
113
- const r = Bun.spawnSync(argv, { cwd, stdin: 'ignore', stderr: 'pipe', env: { ...process.env, SHIPKIT_SECRET_KEYCHAIN_ONLY: 'lib' } })
164
+ const r = Bun.spawnSync(argv, { cwd, stdin: 'ignore', stderr: 'pipe' })
114
165
  const v = r.stdout.toString().trim()
115
166
  if (r.exitCode === 0 && v !== '') return { value: v, from: 'manager' }
116
167
  const why = r.stderr.toString().trim().split('\n').at(-1) ?? ''
117
168
  return why.startsWith('REFUSED') ? { refused: why } : { missing: `\`${argv.join(' ')}\` answered nothing — store the secret under that name first${why !== '' ? ` (${why})` : ''}` }
118
169
  }
119
170
 
120
- /** a name read for the repo at `cwd`. `say` gets the one line of a read that falls back to the keychain */
121
- export async function readSecretHere(o: { name: string; field?: Field; cwd: string; say?: (l: string) => void; w?: SecretsWhere; template?: string }): Promise<Read> {
171
+ /** the login keychain as the store of a Mac with no vault: no item, a locked keychain, a Mac with no `security`, each
172
+ * a missing name with its cause */
173
+ function fromHouseKeychain(name: string, field: Field): Read {
174
+ let r: ReturnType<ReturnType<typeof keychainReader>['read']>
175
+ try {
176
+ r = keychainReader().read(name)
177
+ } catch (e) {
178
+ return { missing: `${name}: this Mac's keychain is not read (${(e as Error).message}): set ${envVarOf(name, field)} instead` }
179
+ }
180
+ if (r == null) return { missing: `${name}: this Mac's keychain holds no copy: store it with sk secret set ${name}` }
181
+ if (!r.ok) return r.code === LOCKED_EXIT ? { missing: `${name}: the login keychain is locked to this session (an ssh one): security unlock-keychain in it, then read again`, locked: true } : { missing: `${name}: ${r.why}` }
182
+ const v = field === 'account' ? r.account : r.value
183
+ return v === '' ? { missing: `${name}: this Mac's keychain holds it with an empty ${field === 'account' ? 'account' : 'value'}` } : { value: v, from: 'keychain' }
184
+ }
185
+
186
+ /** a name read for the repo at `cwd`. `say` gets the one line of a read that falls back to the keychain. `store:
187
+ * 'keychain'` reads this Mac's keychain copy alone, past the env override, after the same gates (sk secret tail
188
+ * --keychain compares it with the vault's) */
189
+ export async function readSecretHere(o: { name: string; field?: Field; cwd: string; say?: (l: string) => void; w?: SecretsWhere; template?: string | null; store?: 'keychain' }): Promise<Read> {
122
190
  const field = o.field ?? 'get'
123
191
  const env = process.env[envVarOf(o.name, field)]
124
- if (env != null && env !== '') return { value: env, from: 'env' }
192
+ if (env != null && env !== '' && o.store == null) return { value: env, from: 'env' }
125
193
  const w = o.w ?? (await secretsWhere(o.cwd))
126
194
  const refused = readRefusal(o.name, houseScopeOf(w, o.name), w)
127
195
  if (refused != null) return { refused }
128
- const say = o.say ?? ((l: string) => void process.stderr.write(`${l}\n`))
196
+ const archived = archivedIn(w, o.name)
197
+ if (archived != null) return { refused: `REFUSED ${archivedLine(o.name, archived)}` }
198
+ if (o.store === 'keychain') {
199
+ const k = fromKeychain(o.name, field)
200
+ return k == null || k === '' ? { missing: `${o.name}: this Mac's keychain holds no copy` } : { value: k, from: 'keychain' }
201
+ }
202
+ const say = o.say ??((l: string) => void process.stderr.write(`${l}\n`))
129
203
  const only = process.env['SHIPKIT_SECRET_KEYCHAIN_ONLY']
130
204
  if (only === '1' && vaultHere()) say(`note: SHIPKIT_SECRET_KEYCHAIN_ONLY=1 sends ${o.name} past the vault to this Mac's keychain: the owner's undo switch, never an agent's. It may be stale`)
131
- if (only !== '1' && only !== 'lib' && vaultHere()) {
205
+ const reach = only !== '1' ? await vaultReach() : null
206
+ if (reach != null) {
132
207
  const path = vaultPathFor(w, o.name)
133
208
  let why = path == null ? 'the vault has no place for this name (no registry row of one scope)' : ''
134
209
  const skipping = path != null && Date.now() < skipUntil
@@ -138,18 +213,26 @@ export async function readSecretHere(o: { name: string; field?: Field; cwd: stri
138
213
  if ('value' in got) return { value: got.value, from: 'vault' }
139
214
  why = got.why
140
215
  }
141
- let k = fromKeychain(o.name, field)
216
+ // a keychain locked to this session (an ssh one) is said beside the vault's cause, never thrown over it
217
+ let k: string | null = null
218
+ let locked = ''
219
+ try {
220
+ k = fromKeychain(o.name, field)
221
+ } catch (e) {
222
+ locked = (e as Error).message.replace(`${o.name}: `, '')
223
+ }
142
224
  if ((k == null || k === '') && skipping && path != null) {
143
225
  const got = await readVault(path, field)
144
226
  if ('value' in got) return { value: got.value, from: 'vault' }
145
227
  why = got.why
146
228
  k = null
147
229
  }
148
- if (k == null || k === '') return { missing: `${o.name}: neither the vault nor the keychain holds it (${why}): store it with sk secret set ${o.name}` }
149
- say(`note: ${o.name} comes from this Mac's keychain, not the vault: ${why}. It may be stale`)
230
+ if (k == null || k === '') return { missing: `${o.name}: neither ${vaultWords(reach)} nor this Mac's keychain holds it (${why}${locked === '' ? '' : `; ${locked}`}): ${reach.at === 'here' ? `store it with sk secret set ${o.name}` : `store it on the Mac that carries the hq (sk secret set ${o.name} there)`}` }
231
+ say(`note: ${o.name} comes from this Mac's keychain, not ${vaultWords(reach)}: ${why}. It may be stale`)
150
232
  return { value: k, from: 'keychain' }
151
233
  }
152
- return fromManager(o.template ?? managerTemplate(w, 'credsReadCommand'), o.name, field, o.cwd)
234
+ const template = o.template !== undefined ? o.template : managerTemplate(w, 'credsReadCommand')
235
+ return template == null ? fromHouseKeychain(o.name, field) : fromManager(template, o.name, field, o.cwd)
153
236
  }
154
237
 
155
238
  /** whether the store holds each name, and since when: never a value. On the machine that runs the vault, the vault's
@@ -160,7 +243,7 @@ export async function heldHere(o: { names: readonly string[]; cwd: string; w?: S
160
243
  const w = o.w ?? (await secretsWhere(o.cwd))
161
244
  const out: Record<string, Held> = {}
162
245
  const rest: string[] = []
163
- const vault = o.vault !== undefined ? o.vault : vaultHere() ? await vaultApi() : null
246
+ const vault = o.vault !== undefined ? o.vault : (await vaultReach()) != null ? await vaultApi() : null
164
247
  await Promise.all(o.names.map(async (name) => {
165
248
  const refused = readRefusal(name, houseScopeOf(w, name), w)
166
249
  if (refused != null) return void (out[name] = { held: 'unknown', why: refused })
@@ -172,7 +255,7 @@ export async function heldHere(o: { names: readonly string[]; cwd: string; w?: S
172
255
  if (rest.length === 0) return out
173
256
  let present: Map<string, Presence>
174
257
  try {
175
- present = o.presence != null ? await o.presence(rest) : await (await import('./list.ts')).presence(managerTemplate(w, 'credsReadCommand'), rest, o.cwd)
258
+ present = o.presence != null ? await o.presence(rest) : await (await import('./list.ts')).presence(rest, o.cwd)
176
259
  } catch (e) {
177
260
  for (const n of rest) out[n] = { held: 'unknown', why: (e as Error).message }
178
261
  return out
@@ -191,6 +274,12 @@ export async function readSecretValue(name: string, field: Field = 'get', cwd: s
191
274
  throw new Error('refused' in r ? `FAIL ${r.refused}` : `FAIL ${r.missing}`)
192
275
  }
193
276
 
277
+ /** the refusal of a write on a Mac that reads the master from afar: one writer place, and no road named to it */
278
+ export async function masterOnly(): Promise<string | null> {
279
+ const r = await vaultReach()
280
+ return r?.at === 'master' ? `the vault is the master on the Mac that carries the hq (${r.host.split('.')[0]}): writes happen there, never on a Mac that reads it` : null
281
+ }
282
+
194
283
  /** a name removed on the machine that runs the vault: its newest version soft deleted in the vault (undone with
195
284
  * `bao kv undelete`), then checked gone. `older`: the versions before it, which stay readable by version: a node
196
285
  * token may never destroy (vault/policy.ts, nothing a node does is final), so the line says so. Elsewhere null.
@@ -211,20 +300,30 @@ export async function removeSecretHere(o: { name: string; cwd: string; w?: Secre
211
300
  return { removed: true, older }
212
301
  }
213
302
 
303
+ /** the vault as a write reaches it, with this daemon's token: a vault down, sealed or with no token is a refusal
304
+ * that says what to run */
305
+ export async function vaultToWrite(): Promise<{ vault: VaultApi; token: string } | { refused: string }> {
306
+ const h = await vaultHealth(vaultUrl(vaultPlace()))
307
+ if (h == null) return { refused: 'the vault does not answer: start it (sk gp start vault), then sk vault status' }
308
+ if (h.sealed) return { refused: 'the vault is sealed: restart it (sk gp restart vault), then sk vault status' }
309
+ const { readVaultToken } = await import('../hq/hq-local.ts')
310
+ const token = readVaultToken()
311
+ if (token == null) return { refused: 'this daemon holds no vault token yet: sk pm restart daemon, then sk vault status' }
312
+ return { vault: new VaultApi(vaultUrl(vaultPlace()), token, WRITE_BUDGET_MS), token }
313
+ }
314
+
214
315
  /** a name written on the machine that runs the vault: into the vault, read back. Elsewhere null: the caller writes
215
316
  * through the house's secret manager */
216
317
  export async function writeSecretHere(o: { name: string; account: string; value: string; cwd: string; w?: SecretsWhere }): Promise<{ version: number } | { refused: string } | null> {
217
318
  if (!vaultHere()) return null
218
319
  const w = o.w ?? (await secretsWhere(o.cwd))
320
+ const archived = archivedIn(w, o.name)
321
+ if (archived != null) return { refused: `${archivedLine(o.name, archived)}, then set it` }
219
322
  const path = vaultPathFor(w, o.name)
220
323
  if (path == null) return { refused: `${o.name} has no place in the vault: it needs a registry row of one scope, and for a repo row this command run inside that repo` }
221
- const h = await vaultHealth(vaultUrl(vaultPlace()))
222
- if (h == null) return { refused: 'the vault does not answer: start it (sk gp start vault), then sk vault status' }
223
- if (h.sealed) return { refused: 'the vault is sealed: restart it (sk gp restart vault), then sk vault status' }
224
- const { readVaultToken } = await import('../hq/hq-local.ts')
225
- const token = readVaultToken()
226
- if (token == null) return { refused: 'this daemon holds no vault token yet: sk pm restart daemon, then sk vault status' }
227
- const vault = new VaultApi(vaultUrl(vaultPlace()), token, WRITE_BUDGET_MS)
324
+ const opened = await vaultToWrite()
325
+ if ('refused' in opened) return opened
326
+ const { vault, token } = opened
228
327
  const before = await vault.currentVersion(KV_MOUNT, path).catch((e: Error) => e)
229
328
  const late = (e: Error): boolean => e.name === 'TimeoutError' || /timed out/i.test(e.message)
230
329
  if (before instanceof Error) {
@@ -248,10 +347,39 @@ export async function writeSecretHere(o: { name: string; account: string; value:
248
347
  }
249
348
  }
250
349
 
251
- /** the read every reader of the lib makes, `template` the manager it would have run: the value, or a FAIL line it
252
- * throws (a refusal kept as REFUSED, a missing name with how to store it) */
253
- export async function readThrough(template: string, name: string, field: Field = 'get', cwd: string = process.cwd()): Promise<string> {
254
- const r = await readSecretHere({ name, field, cwd, template })
350
+ /** a name stored in this Mac's store, with no manager declared: the vault where this Mac runs it (read back), a
351
+ * refusal on a Mac that reads the master from afar, else the login keychain (duplicates collapsed, read back). The
352
+ * lines say what happened; a refusal names what to do, the value never in it */
353
+ export async function storeSecretHere(o: { name: string; account: string; value: string; cwd: string; w?: SecretsWhere }): Promise<{ lines: string[] } | { refused: string }> {
354
+ if (o.value === '') return { refused: 'refusing to store empty value' }
355
+ const w = o.w ?? (await secretsWhere(o.cwd))
356
+ const archived = archivedIn(w, o.name)
357
+ if (archived != null) return { refused: `${archivedLine(o.name, archived)}, then set it` }
358
+ const master = await masterOnly()
359
+ if (master != null) return { refused: master }
360
+ if (vaultHere()) {
361
+ try {
362
+ const r = await writeSecretHere({ ...o, w })
363
+ if (r == null || 'refused' in r) return { refused: r == null ? 'no vault on this machine' : r.refused }
364
+ return { lines: [`stored ${o.name} in the vault (v${r.version}, read back, account: ${o.account}); the keychain is not written`] }
365
+ } catch (e) {
366
+ return { refused: `the vault did not take ${o.name}: ${(e as Error).message.replaceAll(o.value, '‹value›')}` }
367
+ }
368
+ }
369
+ const { keychainWriter } = await import('./keychain-write.ts')
370
+ let r: ReturnType<ReturnType<typeof keychainWriter>['set']>
371
+ try {
372
+ r = keychainWriter().set(o.name, o.account, o.value)
373
+ } catch (e) {
374
+ return { refused: `this Mac's keychain is not written (${(e as Error).message.replaceAll(o.value, '‹value›')})` }
375
+ }
376
+ return r.ok ? { lines: [...r.lines, `stored ${o.name} (account: ${o.account})`] } : { refused: r.why }
377
+ }
378
+
379
+ /** the read every reader of the lib makes, `template` a manager the repo declares (null or undefined: the house's own
380
+ * store): the value, or a FAIL line it throws (a refusal kept as REFUSED, a missing name with how to store it) */
381
+ export async function readThrough(template: string | null | undefined, name: string, field: Field = 'get', cwd: string = process.cwd()): Promise<string> {
382
+ const r = await readSecretHere({ name, field, cwd, ...(template != null ? { template } : {}) })
255
383
  if ('value' in r) return r.value
256
384
  throw new Error('refused' in r ? `FAIL ${r.refused}` : `FAIL ${r.missing}`)
257
385
  }
@@ -0,0 +1,31 @@
1
+ // the end of a secret a provider's dashboard shows (••••c23e), so an agent can say which key of a list a name holds
2
+ // (wiki services/secrets, Match a key with a dashboard). The value is read in this process and only its mask leaves:
3
+ // a value under TAIL_MIN characters gives its length alone, because 4 characters of a password are a share of it.
4
+ // No hash of the value: a hash lets a guess be checked offline from any transcript the line lands in
5
+ import type { Read } from './read.ts'
6
+
7
+ export const TAIL_MIN = 20
8
+ export const TAIL_CHARS = 4
9
+
10
+ export type Mask = { tail: string | null; length: number }
11
+
12
+ /** a control character in the tail is escaped, so a stray line break shows and still counts as one */
13
+ const shown = (s: string): string => s.replace(/[\x00-\x1f\x7f]/g, (c) => JSON.stringify(c).slice(1, -1))
14
+
15
+ export function maskOf(value: string): Mask {
16
+ const chars = [...value]
17
+ if (chars.length < TAIL_MIN) return { tail: null, length: chars.length }
18
+ return { tail: shown(chars.slice(-TAIL_CHARS).join('')), length: chars.length }
19
+ }
20
+
21
+ export const maskText = (m: Mask): string => (m.tail == null ? `short: ${m.length} chars, no tail` : `••••${m.tail} ${m.length} chars`)
22
+
23
+ /** one line a name: its mask and the store it came from, or why there is none. Exit 3 when a name was refused, 1
24
+ * when one is missing. `read` is the one read, or a test's vault */
25
+ export async function tailLines(o: { names: readonly string[]; read: (name: string) => Promise<Read> }): Promise<{ lines: string[]; code: number }> {
26
+ const got = await Promise.all(o.names.map(async (name) => ({ name, r: await o.read(name) })))
27
+ const lines = got.map(({ name, r }) =>
28
+ 'value' in r ? `${name} ${maskText(maskOf(r.value))} ${r.from}` : 'refused' in r ? `${name} ${r.refused}` : `${name} MISS ${r.missing}`)
29
+ const code = got.some(({ r }) => 'refused' in r) ? 3 : got.some(({ r }) => 'missing' in r) ? 1 : 0
30
+ return { lines, code }
31
+ }
@@ -2,6 +2,7 @@
2
2
  // file holds what is the asks' own: the row, the bands' names and the page's words
3
3
  import { observer } from 'mobx-react-lite'
4
4
  import { afterWords } from '../../asks/ask-after.ts'
5
+ import { BAND_WORDS } from '../../review/band.ts'
5
6
  import { askAt, askFactWords, isClosedAsk, isLaterAsk, type AskGroupKey } from './col-tables.ts'
6
7
  import { ColListPage, type ColListWords } from './col-list-page.tsx'
7
8
  import { openAsks } from './asks-st.ts'
@@ -33,7 +34,7 @@ const openWords = (n: number): string => (n === 0 ? 'asks · none open' : `asks
33
34
  const WORDS: ColListWords<AskGroupKey> = {
34
35
  search: 'search the asks',
35
36
  nav: 'the asks of this repo',
36
- band: { open: 'open', later: 'later', done: 'done', declined: 'declined by you' },
37
+ band: { open: 'open', later: BAND_WORDS.aside, done: 'done', declined: 'declined by you' },
37
38
  none: 'No ask yet.',
38
39
  noMatch: 'No ask matches.',
39
40
  reading: 'reading the asks…',
@@ -1,18 +1,19 @@
1
- // the hub's one text box that grows with its text: never an inner scrollbar, unless a sheet caps its height
2
- // (max-height), past which it scrolls. Every multi line field of the hub is this one
1
+ // the hub's one text box that grows with its text: two lines at rest, it wraps, never an inner scrollbar until its
2
+ // cap (hub.css textarea.autotext, or a sheet's lower max-height), past which it scrolls. Every multi line field of the
3
+ // hub is this one
3
4
  import { useCallback, useLayoutEffect, useRef, type TextareaHTMLAttributes } from 'react'
4
5
 
5
6
  type Props = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'onChange' | 'rows'> & {
6
7
  value: string
7
8
  onText: (text: string) => void
8
- /** the height it never shrinks under, in lines */
9
+ /** the height it never shrinks under, in lines: two unless the box says otherwise */
9
10
  rows?: number
10
11
  /** the element, for a caller that focuses it */
11
12
  el?: (t: HTMLTextAreaElement | null) => void
12
13
  }
13
14
 
14
15
  /** a textarea at the height of its text: its value, a new width, a font that loads all size it again */
15
- export function AutoText({ value, onText, rows = 1, el, className, ...rest }: Props) {
16
+ export function AutoText({ value, onText, rows = 2, el, className, ...rest }: Props) {
16
17
  const ref = useRef<HTMLTextAreaElement | null>(null)
17
18
  const size = useCallback((): void => {
18
19
  const t = ref.current
@@ -33,13 +34,20 @@ export function AutoText({ value, onText, rows = 1, el, className, ...rest }: Pr
33
34
  const t = ref.current
34
35
  if (t == null || typeof ResizeObserver === 'undefined') return
35
36
  let w = t.clientWidth
37
+ let raf = 0
38
+ // the new height lands on the next frame: sized inside the callback, its scrollbar moves its width and the
39
+ // observer fires again in the same frame (the loop notice Bun's dev overlay paints over the page)
36
40
  const ro = new ResizeObserver(() => {
37
41
  if (t.clientWidth === w) return
38
42
  w = t.clientWidth
39
- size()
43
+ cancelAnimationFrame(raf)
44
+ raf = requestAnimationFrame(size)
40
45
  })
41
46
  ro.observe(t)
42
- return () => ro.disconnect()
47
+ return () => {
48
+ cancelAnimationFrame(raf)
49
+ ro.disconnect()
50
+ }
43
51
  }, [size])
44
52
  return (
45
53
  <textarea
@@ -2,7 +2,10 @@
2
2
  // is a notice, not a failure: the spec delivers the skipped notifications next
3
3
  // frame. Bun's dev overlay listens for 'error' and paints it as a runtime
4
4
  // error. A capture listener on the target runs before Bun's bubble one, so
5
- // stopImmediatePropagation keeps the overlay for real errors only.
5
+ // stopImmediatePropagation keeps the overlay for real errors only. The overlay
6
+ // paints every 'unhandledrejection' too, and a request the page cancels on
7
+ // purpose rejects with an AbortError: that one is no failure either. Installed
8
+ // before the page's first await, so nothing early slips past it.
6
9
  const BENIGN = [
7
10
  'ResizeObserver loop completed with undelivered notifications.', // webkit, chromium
8
11
  'ResizeObserver loop limit exceeded', // older chromium
@@ -11,6 +14,10 @@ const BENIGN = [
11
14
  export const isBenignError = (message: unknown): boolean =>
12
15
  typeof message === 'string' && BENIGN.some(b => message.includes(b))
13
16
 
17
+ /** a rejection the page asked for: a request it cancelled */
18
+ export const isBenignRejection = (reason: unknown): boolean =>
19
+ typeof reason === 'object' && reason !== null && (reason as { name?: unknown }).name === 'AbortError'
20
+
14
21
  export const quietBenignErrors = (target: EventTarget): void => {
15
22
  target.addEventListener(
16
23
  'error',
@@ -19,4 +26,11 @@ export const quietBenignErrors = (target: EventTarget): void => {
19
26
  },
20
27
  { capture: true },
21
28
  )
29
+ target.addEventListener(
30
+ 'unhandledrejection',
31
+ e => {
32
+ if (isBenignRejection((e as PromiseRejectionEvent).reason)) e.stopImmediatePropagation()
33
+ },
34
+ { capture: true },
35
+ )
22
36
  }
@@ -0,0 +1,49 @@
1
+ // THE title of a card, on every page of the hub: its name in bold sentence case, its count dim beside it, a dim line
2
+ // of what it holds, what acts on it at its end. With `onFold` the name is a button that folds the card: the caret first,
3
+ // the accent on hover, Enter and Space by the button. The look lives in controls.css (.ch) and nowhere else:
4
+ // tests/hub-caret-card-head.test.ts fails a page that draws a card title of its own. A head over a group of rows in a
5
+ // list is the other control, section-head.tsx
6
+ import type { ReactNode } from 'react'
7
+ import { Caret } from './icons.tsx'
8
+
9
+ export type CardHeadProps = {
10
+ /** the card's name, bold, in the case it is written in */
11
+ title: ReactNode
12
+ /** how many things the card holds, dim beside the name */
13
+ n?: ReactNode
14
+ /** a dim line beside the name: what the card holds, or its summary while folded */
15
+ meta?: ReactNode
16
+ /** with `onFold`: the card shows its body */
17
+ open?: boolean
18
+ /** a click on the name (or Enter, Space) folds or shows the card */
19
+ onFold?: () => void
20
+ /** the words on hover; a fold head says what a click does when none is given */
21
+ tip?: string
22
+ /** a class that names the head for a check or a placement; it carries no look */
23
+ hook?: string
24
+ /** what acts on the card, at the head's end, outside the fold button */
25
+ children?: ReactNode
26
+ }
27
+
28
+ export const CardHead = (p: CardHeadProps) => {
29
+ const name = (
30
+ <>
31
+ {p.onFold != null ? <Caret open={p.open !== false} /> : null}
32
+ <span className="chl">{p.title}</span>
33
+ {p.n == null ? null : <span className="chn">{p.n}</span>}
34
+ {p.meta == null || p.meta === '' ? null : <span className="chm">{p.meta}</span>}
35
+ </>
36
+ )
37
+ const cls = `ch${p.hook != null ? ` ${p.hook}` : ''}`
38
+ if (p.onFold == null)
39
+ return <div className={cls} title={p.tip}>{name}{p.children}</div>
40
+ const open = p.open !== false
41
+ return (
42
+ <div className={cls}>
43
+ <button type="button" className="chf" aria-expanded={open} title={p.tip ?? `a click ${open ? 'folds' : 'shows'} it`} onClick={p.onFold}>
44
+ {name}
45
+ </button>
46
+ {p.children}
47
+ </div>
48
+ )
49
+ }
@@ -3,6 +3,7 @@
3
3
  // one grid of facts, each a dim label and a short value whose explanation is
4
4
  // the row's `(?)`, then where it runs: one line per context. No box holds a single field. Navigation is the tree on the
5
5
  // left, so there is no back link.
6
+ import { CardHead } from './card-head.tsx'
6
7
  import { observer } from 'mobx-react-lite'
7
8
  import { useEffect, useRef } from 'react'
8
9
  import { CACHED } from '../../core/outcome-words.ts'
@@ -70,7 +71,7 @@ export const PathCode = ({ p, href }: { p: ShortPath; href?: string | null }) =>
70
71
  /** the section title for what is not a fact: the output, the slow suites */
71
72
  export const Section = ({ title, help, children }: { title: string; help?: string; children: React.ReactNode }) => (
72
73
  <section className="csec">
73
- <div className="cstitle">{title}{help != null ? <Help text={help} /> : null}</div>
74
+ <CardHead title={title}>{help != null ? <Help text={help} /> : null}</CardHead>
74
75
  {children}
75
76
  </section>
76
77
  )
@@ -261,7 +262,7 @@ const Remembered = ({ u }: { u: CheckFacts }) => {
261
262
  * `fix:` pointer is made of backtick spans and urls, and a fence turns a
262
263
  * pointer a reader could click into text they have to retype */
263
264
  const LogLines = ({ lines }: { lines: string[] }) => (
264
- <>{lines.map((l, n) => <div key={`${n}-${l}`} className="wlogline" dangerouslySetInnerHTML={{ __html: renderMdInline(l) }} />)}</>
265
+ <>{lines.map((l, n) => <div key={`${n}-${l}`} className="wlogline mdi" dangerouslySetInnerHTML={{ __html: renderMdInline(l) }} />)}</>
265
266
  )
266
267
 
267
268
  /** the lines of the run in flight, then the lines of the last one. It
@@ -0,0 +1,35 @@
1
+ // the « copy » button of every code block the hub's markdown draws (md.ts puts it there): one listener on the page
2
+ // answers them all, wherever the markdown sits. Capture phase, so a card or a row under it never also takes the click
3
+ const FLASH_MS = 1600
4
+
5
+ /** the block's text as written between its fences: the renderer ends every block with one newline of its own */
6
+ export const blockText = (pre: Element): string => (pre.querySelector('code') ?? pre).textContent?.replace(/\n$/, '') ?? ''
7
+
8
+ const said = (b: HTMLButtonElement, word: string, cls: string): void => {
9
+ b.textContent = word
10
+ b.classList.add(cls)
11
+ b.closest('.mdpre')?.classList.add(cls)
12
+ setTimeout(() => {
13
+ b.textContent = 'copy'
14
+ b.classList.remove(cls)
15
+ b.closest('.mdpre')?.classList.remove(cls)
16
+ }, FLASH_MS)
17
+ }
18
+
19
+ export function installCodeCopy(doc: Document): void {
20
+ doc.addEventListener(
21
+ 'click',
22
+ (e) => {
23
+ const b = (e.target as Element | null)?.closest?.('button.mdcopy') as HTMLButtonElement | null
24
+ const pre = b?.parentElement?.querySelector(':scope > pre')
25
+ if (b == null || pre == null) return
26
+ e.preventDefault()
27
+ e.stopPropagation()
28
+ void navigator.clipboard.writeText(blockText(pre)).then(
29
+ () => said(b, 'copied', 'copied'),
30
+ () => said(b, 'select it by hand', 'refused'),
31
+ )
32
+ },
33
+ true,
34
+ )
35
+ }