rvlib-shipkit 2.16.0 → 2.17.1

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 (54) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +1 -1
  3. package/src/assets/kit-config.ts +19 -1
  4. package/src/assets/run-assets.ts +18 -0
  5. package/src/cli/cmd_Review.ts +26 -7
  6. package/src/cli/cmd_Secret.ts +127 -0
  7. package/src/cli/cmd_Wiki.ts +4 -4
  8. package/src/cli/family-pages.ts +1 -0
  9. package/src/cli/registry.ts +4 -0
  10. package/src/core/discover-checks.ts +18 -5
  11. package/src/core/scope.ts +42 -0
  12. package/src/home/beat.ts +30 -0
  13. package/src/home/home-paths.ts +1 -0
  14. package/src/home/pm.ts +3 -1
  15. package/src/home/run-daemon.ts +5 -2
  16. package/src/home/run-web.ts +4 -2
  17. package/src/home/supervise.ts +18 -1
  18. package/src/repo-config.ts +3 -0
  19. package/src/review/auto.ts +7 -2
  20. package/src/review/cells.ts +1 -1
  21. package/src/review/format.ts +2 -2
  22. package/src/review/model.ts +57 -13
  23. package/src/review/previews.ts +1 -1
  24. package/src/review/routes.ts +11 -0
  25. package/src/review/store.ts +18 -10
  26. package/src/secrets/list.ts +40 -0
  27. package/src/serve/hub-app/hub-app.tsx +28 -2
  28. package/src/serve/hub-app/icons.tsx +1 -0
  29. package/src/serve/hub-app/identities-view.tsx +1 -1
  30. package/src/serve/hub-app/kept-cols.tsx +47 -8
  31. package/src/serve/hub-app/layout-st.ts +37 -3
  32. package/src/serve/hub-app/review/review-kit.ts +12 -0
  33. package/src/serve/hub-app/review/review-page.tsx +1 -1
  34. package/src/serve/hub-app/review/review-st.ts +63 -4
  35. package/src/serve/hub-app/review/review-thread.tsx +1 -0
  36. package/src/serve/hub-app/review/review-views.tsx +215 -63
  37. package/src/serve/hub-app/review/thread-st.ts +82 -16
  38. package/src/serve/hub-app/review/trailer-page.tsx +1 -1
  39. package/src/serve/hub-app/review.css +41 -2
  40. package/src/serve/hub-app/social/comms-page.tsx +1 -1
  41. package/src/serve/hub-app/social/social-page.tsx +1 -1
  42. package/src/serve/hub-app/stores/stores-page.tsx +1 -1
  43. package/src/serve/hub-app/veille/veille-page.tsx +1 -1
  44. package/src/shipkit.ts +1 -1
  45. package/src/shot/box.ts +9 -1
  46. package/src/shot/shooter.ts +24 -2
  47. package/src/social/load.ts +3 -1
  48. package/src/trailer/grammar.ts +2 -0
  49. package/src/trailer/sound/presets.ts +3 -3
  50. package/src/trailer/sound/run.ts +22 -14
  51. package/src/trailer/titles.ts +1 -1
  52. package/src/wiki/lint-md.ts +4 -2
  53. package/src/wiki/run-wiki.ts +22 -6
  54. package/src/wiki/scan-md.ts +3 -1
@@ -33,7 +33,7 @@ export const TrailerPage = observer(({ app }: { app: RepoSt }) => {
33
33
  </div>
34
34
  )
35
35
  return (
36
- <KeptCols id="trailer">
36
+ <KeptCols id="trailer" folds={{ left: 'trailer-cuts', right: 'trailer-notes' }} layout={app.home.layout}>
37
37
  <Panel id="trailer-cuts" defaultSize="15%" minSize={190} className="rv-pane" style={PANEL}>
38
38
  <div className="rv-scroll"><CutList tr={tr} /></div>
39
39
  </Panel>
@@ -17,6 +17,17 @@
17
17
  /* ── the columns ── */
18
18
  .rv-cols{flex:1;min-height:0}
19
19
  .rv-pane{height:100%;min-width:0;display:flex;flex-direction:column}
20
+ .rv-widebody{display:flex}
21
+ .rv-widebody > .pmain{flex:1;min-width:0}
22
+ .rv-foldrow{flex:1;min-height:0;min-width:0;display:flex}
23
+ .rv-foldrow > .rv-cols{flex:1;min-width:0}
24
+ .rv-widebar.right{border-right:0;border-left:1px solid var(--line)}
25
+ .rv-widebar{flex:none;width:16px;height:100%;padding:0;border:0;border-right:1px solid var(--line);border-radius:0;background:var(--panel);cursor:pointer;display:flex;align-items:center;justify-content:center}
26
+ .rv-widebar:hover{background:color-mix(in srgb,var(--accent) 12%,var(--panel))}
27
+ .rv-wideknob{display:flex;align-items:center;justify-content:center;width:12px;height:56px;border-radius:6px;background:color-mix(in srgb,var(--accent) 35%,var(--line));color:var(--fg);font-size:13px;font-weight:700;line-height:1}
28
+ .rv-widebar:hover .rv-wideknob{background:var(--accent);color:var(--bg)}
29
+ .rv-iconbtn.on{background:color-mix(in srgb,var(--accent) 18%,transparent);border-color:var(--accent)}
30
+ .rv-iconbtn.on .hico{color:var(--accent)}
20
31
  .rv-scroll{flex:1;min-height:0;overflow-y:auto}
21
32
  .rv-dim,.tr-dim{color:var(--dim)}
22
33
  .rv-small,.tr-small{font-size:11px}
@@ -279,12 +290,40 @@ span.rv-react{display:inline-block;border:1px solid;border-radius:4px}
279
290
  .rv-noten.before{background:var(--warn)}
280
291
  /* the view's OK, Fix and No again, on their own row under the words */
281
292
  .rv-notereacts{flex:1 1 100%;display:flex;justify-content:flex-end}
282
- .rv-downloads{display:flex;gap:var(--s2);justify-content:flex-end;margin-top:var(--s1)}
283
- .rv-dl{font-size:11.5px;text-decoration:none}
293
+ .rv-downloads{display:flex;flex-wrap:wrap;align-items:center;gap:var(--s2);justify-content:flex-end;margin-top:var(--s1)}
294
+ .rv-dl{font-size:11.5px;text-decoration:none;white-space:nowrap}
284
295
  .rv-gallery{display:flex;flex-wrap:wrap;gap:var(--s2);align-items:flex-start}
296
+ .rv-gallerywrap{display:flex;flex-direction:column;gap:var(--s1)}
297
+ .rv-tilesize{display:flex;align-items:center;gap:var(--s1);align-self:flex-end}
298
+ .rv-tilesize input{width:140px}
299
+ .rv-galleryhead{display:flex;flex-wrap:wrap;align-items:center;gap:var(--s2)}
300
+ .rv-galleryrow{display:flex;flex-direction:column;gap:var(--s1);padding-top:var(--s1);border-top:1px solid var(--line)}
301
+ .rv-rowlabel{font-weight:600}
302
+ .rv-tile.picked{box-shadow:0 0 0 2px var(--ok)}
303
+ .rv-tileimg{position:relative;align-self:center}
304
+ .rv-tile .rv-over .rv-note{min-width:220px}
305
+ .rv-beforechip{position:absolute;top:4px;left:4px;font-size:10px;line-height:16px;padding:0 var(--s1);border-radius:4px;background:color-mix(in srgb,var(--bg) 80%,transparent);border:1px solid var(--line);cursor:default}
306
+ .rv-beforechip.on{background:var(--warn);color:var(--bg)}
307
+ .rv-galleryhead .rv-chip.on,.rv-keep.on{color:var(--bg);background:var(--accent);border-color:var(--accent)}
308
+ .rv-keep.on{background:var(--ok);border-color:var(--ok)}
309
+ .rv-tilesmall{display:flex;align-items:flex-end;gap:var(--s2);background:repeating-conic-gradient(var(--chk1) 0 25%,var(--chk2) 0 50%) 0 0/8px 8px;padding:var(--s1);border-radius:4px}
310
+ .rv-tilesmall img{object-fit:contain;image-rendering:auto}
285
311
  .rv-tile{display:flex;flex-direction:column;gap:var(--s1);padding:var(--s1);border-radius:6px;border:2px solid var(--line)}
286
312
  .rv-tile[class*=' re-']{border-color:var(--tone);background:color-mix(in srgb,var(--tone) 8%,transparent)}
287
313
  .rv-tile.big{width:100%}
314
+ .rv-tile.fill{width:100%}
315
+ .rv-tile.fill .rv-tileimg{cursor:default}
316
+ .rv-gallerylist{display:flex;flex-direction:column;gap:var(--s2)}
317
+ .rv-gtabs{display:grid;grid-template-columns:minmax(150px,220px) minmax(0,1fr);gap:var(--s2);align-items:start}
318
+ .rv-gtablist{position:sticky;top:0;display:flex;flex-direction:column;gap:2px;max-height:calc(100vh - 160px);overflow:auto;padding-right:2px}
319
+ .rv-gtab{display:grid;grid-template-columns:48px minmax(0,1fr);grid-template-rows:auto auto;column-gap:var(--s1);align-items:center;width:100%;text-align:left;padding:var(--s1);border:1px solid transparent;border-left:3px solid var(--line);border-radius:4px;background:none;cursor:pointer}
320
+ .rv-gtab:hover{background:color-mix(in srgb,var(--fg) 5%,transparent)}
321
+ .rv-gtab.on{background:color-mix(in srgb,var(--accent) 14%,transparent);border-color:var(--accent)}
322
+ .rv-gtab[class*=' re-']{border-left-color:var(--tone)}
323
+ .rv-gtab img{grid-row:span 2;width:48px;height:36px;object-fit:cover;object-position:top;border-radius:2px;background:repeating-conic-gradient(var(--chk1) 0 25%,var(--chk2) 0 50%) 0 0/8px 8px}
324
+ .rv-gtablabel{font-size:12px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
325
+ .rv-gtabmark{font-size:10px;color:var(--warn);min-height:12px}
326
+ .rv-gtabgroup{font-weight:600;font-size:11px;margin:var(--s1) 0 2px}
288
327
  .rv-tileimg{border-radius:4px;cursor:zoom-in;width:100%;background:repeating-conic-gradient(var(--chk1) 0 25%,var(--chk2) 0 50%) 0 0/12px 12px}
289
328
  .rv-tile.big .rv-tileimg{cursor:zoom-out}
290
329
  .rv-tileimg img{display:block;width:100%;height:100%;object-fit:contain}
@@ -49,7 +49,7 @@ export const CommsPage = observer(({ app }: { app: RepoSt }) => {
49
49
  return (
50
50
  <div className="so-page">
51
51
  <SocialCalendar so={so} />
52
- <KeptCols id="comms">
52
+ <KeptCols id="comms" folds={{ left: 'comms-list', right: 'comms-side' }} layout={app.home.layout}>
53
53
  <Panel id="comms-list" defaultSize="22%" minSize={240} className="rv-pane" style={PANEL}>
54
54
  <DraftsList so={so} />
55
55
  </Panel>
@@ -48,7 +48,7 @@ export const SocialPage = observer(({ app }: { app: RepoSt }) => {
48
48
  )
49
49
  return (
50
50
  <div className="so-page">
51
- <KeptCols id="social">
51
+ <KeptCols id="social" folds={{ left: 'social-list', right: 'social-right' }} layout={app.home.layout}>
52
52
  <Panel id="social-list" defaultSize="22%" minSize={240} className="rv-pane" style={PANEL}>
53
53
  <IdentityList so={so} />
54
54
  </Panel>
@@ -32,7 +32,7 @@ export const StoresPage = observer(({ app }: { app: RepoSt }) => {
32
32
  return (
33
33
  <>
34
34
  <Toast so={so} />
35
- <KeptCols id="stores">
35
+ <KeptCols id="stores" folds={{ left: 'stores-list', right: 'stores-pictures' }} layout={app.home.layout}>
36
36
  <Panel id="stores-list" defaultSize="20%" minSize={220} className="rv-pane" style={PANEL}>
37
37
  <div className="rv-scroll"><StoreList so={so} /></div>
38
38
  </Panel>
@@ -66,7 +66,7 @@ export const VeillePage = observer(({ app }: { app: RepoSt }) => {
66
66
  return (
67
67
  <>
68
68
  <Toast v={v} />
69
- <KeptCols id="veille">
69
+ <KeptCols id="veille" folds={{}} layout={app.home.layout}>
70
70
  <Panel id="veille-deck" defaultSize="72%" minSize={480} className="rv-pane" style={PANEL}>
71
71
  <Deck v={v} />
72
72
  </Panel>
package/src/shipkit.ts CHANGED
@@ -58,7 +58,7 @@ export type { Ask, CreateOpts } from './asks/asks-queue.ts'
58
58
  // assets surface (folded in from the standalone atelier lib; that npm
59
59
  // package is frozen). A repo's .shipkit/assets/kit.ts imports defineKit and
60
60
  // declares its kinds; `shipkit assets …` derives the rest.
61
- export { defineKit, defineKind, comfy, canvas, manual, gemini, mediaOf, MEDIA_EXTS, geometryPanel, gridPanel, customPanel, validateKit, missingPanelScripts, loadKit, findAsset, allAssets, categoriesOf } from './assets/kit-config.ts'
61
+ export { defineKit, defineKind, comfy, canvas, svg, manual, gemini, mediaOf, MEDIA_EXTS, geometryPanel, gridPanel, customPanel, validateKit, missingPanelScripts, loadKit, findAsset, allAssets, categoriesOf } from './assets/kit-config.ts'
62
62
  export type { KitConfig, ResolvedKit, Kind, KindMeta, Media, AssetSpec, GeneratorSpec, ComfyGen, CanvasGen, ManualGen, GeminiGen, PanelSpec, GeometryPanelSpec, GridPanelSpec, CustomPanelSpec, FoundAsset, ShipContext, ShipFn } from './assets/kit-config.ts'
63
63
  export { identityKinds, renderIdentity, renderIdentityFromMark, NO_PICK_FIX, FAVICON_SIZE, OG_W, OG_H, LOGO_SIZE } from './assets/kits/identity-kit.ts'
64
64
  export type { Brand } from './assets/kits/identity-kit.ts'
package/src/shot/box.ts CHANGED
@@ -15,7 +15,12 @@ import { CDP_PORT } from './film-box.ts'
15
15
 
16
16
  /** the slice of playwright the route drives: a browser to connect to, its default context, a page's viewport */
17
17
  type PwPage = { setViewportSize(v: { width: number; height: number }): Promise<void>; addInitScript(s: { content: string }): Promise<void>; close(): Promise<void> }
18
- type PwContext = { newPage(): Promise<PwPage>; newCDPSession(p: PwPage): Promise<{ send(m: string, p?: Record<string, unknown>): Promise<unknown> }> }
18
+ type PwContext = {
19
+ newPage(): Promise<PwPage>
20
+ newCDPSession(p: PwPage): Promise<{ send(m: string, p?: Record<string, unknown>): Promise<unknown> }>
21
+ cookies(): Promise<unknown[]>
22
+ addCookies(c: unknown[]): Promise<void>
23
+ }
19
24
  export type PwBrowser = { contexts(): PwContext[]; close(): Promise<void>; isConnected(): boolean; on(e: 'disconnected', cb: () => void): void }
20
25
  export type Pw = { chromium: { launch(o: { headless: boolean; args: string[] }): Promise<unknown>; connectOverCDP(url: string): Promise<PwBrowser> } }
21
26
 
@@ -98,6 +103,9 @@ function asLaunched(b: PwBrowser, all: PwPage[]) {
98
103
  return p
99
104
  },
100
105
  newCDPSession: (p: PwPage) => ctx.newCDPSession(p),
106
+ // the one default context holds every page's cookies already
107
+ cookies: () => ctx.cookies(),
108
+ addCookies: async () => undefined,
101
109
  async addInitScript(s: { content: string }) {
102
110
  scripts.push(s.content)
103
111
  for (const p of pages) await p.addInitScript(s)
@@ -55,7 +55,16 @@ export async function consoleWords(m: { args?(): { jsonValue(): Promise<unknown>
55
55
  return null
56
56
  }
57
57
  }
58
- type Context = { newPage(): Promise<Page>; newCDPSession(p: Page): Promise<Cdp>; addInitScript(s: { content: string }): Promise<void>; close(): Promise<void> }
58
+ /** a cookie as playwright reads and writes it */
59
+ type Cookie = { name: string; value: string; domain: string; path: string } & Record<string, unknown>
60
+ type Context = {
61
+ newPage(): Promise<Page>
62
+ newCDPSession(p: Page): Promise<Cdp>
63
+ addInitScript(s: { content: string }): Promise<void>
64
+ cookies(): Promise<Cookie[]>
65
+ addCookies(c: Cookie[]): Promise<void>
66
+ close(): Promise<void>
67
+ }
59
68
  export type Browser = {
60
69
  newContext(o: { viewport: { width: number; height: number }; deviceScaleFactor: number; locale?: string }): Promise<Context>
61
70
  close(): Promise<void>
@@ -111,6 +120,9 @@ export class Shooter {
111
120
  /** before a page goes to a url: the box route forwards this machine's localhost port to the box */
112
121
  #reach: (url: string) => Promise<void> = async () => undefined
113
122
  #slot: Slot | null = null
123
+ /** the cookies a closed context held, given to the next one: a sign in survives a shot at another viewport, a
124
+ * clip and the idle close. Memory only, never on disk */
125
+ #jar: Cookie[] = []
114
126
  #idle: ReturnType<typeof setTimeout> | null = null
115
127
  #live: ReturnType<typeof setTimeout> | null = null
116
128
 
@@ -138,13 +150,19 @@ export class Shooter {
138
150
  async close(): Promise<void> {
139
151
  if (this.#idle) clearTimeout(this.#idle)
140
152
  if (this.#live) clearTimeout(this.#live)
153
+ const s = this.#slot
141
154
  this.#slot = null
155
+ if (s) await this.#keep(s.ctx)
142
156
  const b = this.#browser
143
157
  this.#browser = null
144
158
  await b?.close().catch(() => undefined)
145
159
  this.#free()
146
160
  }
147
161
 
162
+ async #keep(ctx: Context): Promise<void> {
163
+ this.#jar = await ctx.cookies().catch(() => this.#jar)
164
+ }
165
+
148
166
  #free(): void {
149
167
  const held = this.#held
150
168
  this.#held = null
@@ -198,7 +216,9 @@ export class Shooter {
198
216
 
199
217
  async #context(a: ShotAsk): Promise<Context> {
200
218
  const b = await this.#ensureBrowser()
201
- return b.newContext({ viewport: a.viewport, deviceScaleFactor: a.dpr, locale: 'en-US' })
219
+ const ctx = await b.newContext({ viewport: a.viewport, deviceScaleFactor: a.dpr, locale: 'en-US' })
220
+ if (this.#jar.length > 0) await ctx.addCookies(this.#jar)
221
+ return ctx
202
222
  }
203
223
 
204
224
  static #listen(page: Page, errors: string[]): void {
@@ -224,6 +244,7 @@ export class Shooter {
224
244
  if (move === 'boot') {
225
245
  const old = this.#slot
226
246
  this.#slot = null
247
+ if (old) await this.#keep(old.ctx)
227
248
  await old?.ctx.close().catch(() => undefined)
228
249
  const t = performance.now()
229
250
  const ctx = await this.#context(a)
@@ -330,6 +351,7 @@ export class Shooter {
330
351
  const note = `${d.frames} frames ${d.width}x${d.height} at ${a.fps} fps ${how}, canvas ${d.canvasOfViewport}, ${mb} MB H.264 from the page's WebCodecs, muxed`
331
352
  return { out: a.out, ms: ms(t0), phases, errors, note, ...stepped }
332
353
  } finally {
354
+ await this.#keep(ctx)
333
355
  await ctx.close().catch(() => undefined)
334
356
  }
335
357
  }
@@ -121,6 +121,8 @@ const read = (abs: string): string => readFileSync(abs, 'utf8')
121
121
 
122
122
  /** the group whose messages need a compiled 9:16 video */
123
123
  export const VERTICAL = 'vertical'
124
+ /** the contract's two formats: always a heading a draft may use, even before the identity has an account in them */
125
+ const FORMATS = ['short', VERTICAL] as const
124
126
  /** the name of a compiled vertical video */
125
127
  export const VERTICAL_FILE = /-vertical\.mp4$/
126
128
 
@@ -208,7 +210,7 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
208
210
  }
209
211
  named.add(speaker.id)
210
212
  const accounts = identities.find((i) => i.id === speaker.id)!.accounts
211
- const groups = new Map([...new Set(accounts.map((a) => a.group).filter((g) => g !== ''))].map((g) => [g, accounts.filter((a) => a.group === g).map((a) => a.id)]))
213
+ const groups = new Map([...new Set([...FORMATS, ...accounts.map((a) => a.group).filter((g) => g !== '')])].map((g) => [g, accounts.filter((a) => a.group === g).map((a) => a.id)]))
212
214
  const d = parseDraft(raw, file, groups)
213
215
  errors.push(...d.errors)
214
216
  const media = new Map<string, Media>()
@@ -212,6 +212,8 @@ export interface SoundGen {
212
212
  export interface SoundRun {
213
213
  cmd: string
214
214
  reads?: string[]
215
+ /** the work runs on another machine (ElevenLabs, the comfy box): it never waits on this machine's load */
216
+ remote?: true
215
217
  }
216
218
 
217
219
  export interface Sfx {
@@ -53,14 +53,14 @@ export function presetOf(a: SoundAsk, brand: TrailerSoundInput | undefined): Sou
53
53
  if (a.kind === 'voice') {
54
54
  const voice = voiceOf(brand, a.by)
55
55
  const v = voiceFlags(voice)
56
- return { cmd: ['sk sound voice', q(a.text), ...v.flags, ...('eleven' in voice ? [] : comfy), ...seed, '--out {out}'].join(' '), ...(v.reads.length ? { reads: v.reads } : {}) }
56
+ return { cmd: ['sk sound voice', q(a.text), ...v.flags, ...('eleven' in voice ? [] : comfy), ...seed, '--out {out}'].join(' '), ...(v.reads.length ? { reads: v.reads } : {}), remote: true }
57
57
  }
58
- if (a.kind === 'sfx') return { cmd: ['sk sound sfx', q(a.text), '--seconds', num(a.for ?? SFX_SECONDS), ...seed, ...(a.hit ? ['--hit'] : []), ...comfy, '--out {out}'].join(' ') }
58
+ if (a.kind === 'sfx') return { cmd: ['sk sound sfx', q(a.text), '--seconds', num(a.for ?? SFX_SECONDS), ...seed, ...(a.hit ? ['--hit'] : []), ...comfy, '--out {out}'].join(' '), remote: true }
59
59
  // the soundfont and fluidsynth are in the words as a comment: another one renders the file again
60
60
  if (isMidi(a.text)) return { cmd: `sk sound midi ${q(a.text)} --out {out} # fluid ${new Bun.CryptoHasher('sha1').update(fluidIdentity()).digest('hex').slice(0, 12)}`, reads: [a.text] }
61
61
  const engine = a.by ?? 'stable-audio'
62
62
  if (!(MUSIC_ENGINES as readonly string[]).includes(engine)) throw new Error(`music by ${engine}: the engines are ${MUSIC_ENGINES.join(', ')}`)
63
- return { cmd: ['sk sound music', q(a.text), '--engine', engine, '--seconds', num(a.for ?? musicSeconds(a.seconds)), ...seed, ...comfy, '--out {out}'].join(' ') }
63
+ return { cmd: ['sk sound music', q(a.text), '--engine', engine, '--seconds', num(a.for ?? musicSeconds(a.seconds)), ...seed, ...comfy, '--out {out}'].join(' '), remote: true }
64
64
  }
65
65
 
66
66
  /** a paid run: the characters its line costs, else null */
@@ -1,8 +1,8 @@
1
1
  // THE one way a trailer makes a sound: a command that writes `{out}`, cached on its words and the content of each file
2
2
  // it reads. A voice, an sfx, a music bed and a MIDI file are presets of it (presets.ts). The cache is
3
3
  // `.shipkit/cache/sound/<key>.wav` with `<key>.json` (the command, its measures) and `<key>.png` (its waveform), out of
4
- // the trailer's cache so a trailer prune never deletes a paid line. One sound is made at a time, under nice, never
5
- // while the machine's load is over 16
4
+ // the trailer's cache so a trailer prune never deletes a paid line. One sound is made at a time, under nice, and one
5
+ // that loads this machine (not `remote`) never starts while its load is over 16
6
6
  import { closeSync, existsSync, mkdirSync, mkdtempSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs'
7
7
  import { loadavg } from 'node:os'
8
8
  import { join, relative, resolve } from 'node:path'
@@ -55,7 +55,7 @@ let queue: Promise<unknown> = Promise.resolve()
55
55
  export function soundRun(r: SoundRun, p: RunPlace, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
56
56
  const spec = runSpec(r, p)
57
57
  if (existsSync(spec.file)) return Promise.resolve({ file: spec.file, made: false })
58
- const job = queue.then(() => make(spec, p.root, say))
58
+ const job = queue.then(() => make(spec, p.root, r.remote === true, say))
59
59
  queue = job.catch(() => undefined)
60
60
  return job
61
61
  }
@@ -105,12 +105,12 @@ async function lockSound(spec: ReturnType<typeof runSpec>, say: (line: string) =
105
105
  }
106
106
  }
107
107
 
108
- async function make(spec: ReturnType<typeof runSpec>, root: string, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
108
+ async function make(spec: ReturnType<typeof runSpec>, root: string, remote: boolean, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
109
109
  mkdirSync(soundCache(root), { recursive: true })
110
110
  const unlock = await lockSound(spec, say)
111
111
  if (!unlock) return { file: spec.file, made: false }
112
112
  try {
113
- return await makeLocked(spec, root, say)
113
+ return await makeLocked(spec, root, remote, say)
114
114
  } finally {
115
115
  unlock()
116
116
  }
@@ -134,27 +134,35 @@ export function killGroup(pid: number): void {
134
134
  setTimeout(() => kill('SIGKILL'), 5000).unref()
135
135
  }
136
136
 
137
- const prepared = new Map<string, Promise<void>>()
137
+ const swept = new Set<string>()
138
+ let calm: Promise<void> | null = null
138
139
 
139
- /** once per process and repo, before the first sound it makes: the folders killed makes left swept, then a wait while
140
- * the machine's load is over 16 */
141
- async function prepare(root: string, say: (line: string) => void): Promise<void> {
140
+ /** once per process and repo, before the first sound it makes: the folders killed makes left swept */
141
+ function sweep(root: string): void {
142
+ if (swept.has(root)) return
143
+ swept.add(root)
142
144
  const cache = soundCache(root)
143
145
  for (const e of readdirSync(cache)) {
144
146
  const f = join(cache, e)
145
147
  if (e.startsWith('.make-') && Date.now() - statSync(f).mtimeMs > STALE_MAKE_MS) rmSync(f, { recursive: true, force: true })
146
148
  }
149
+ }
150
+
151
+ /** once per process, before the first sound that loads this machine: a wait while its load is over 16 */
152
+ async function waitCalm(say: (line: string) => void): Promise<void> {
147
153
  for (let waited = 0; loadavg()[0]! > 16; waited += 5) {
148
- if (waited === 0) say(`sound: the load is ${loadavg()[0]!.toFixed(1)}, over 16: waiting before the first sound`)
154
+ if (waited === 0) say(`sound: the load is ${loadavg()[0]!.toFixed(1)}, over 16: waiting before the first local sound`)
149
155
  if (waited > 600) throw new Error('sound: the load stayed over 16 for 10 minutes')
150
156
  await Bun.sleep(5000)
151
157
  }
152
158
  }
153
159
 
154
- async function makeLocked(spec: ReturnType<typeof runSpec>, root: string, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
155
- let ready = prepared.get(root)
156
- if (!ready) prepared.set(root, (ready = prepare(root, say)))
157
- await ready
160
+ async function makeLocked(spec: ReturnType<typeof runSpec>, root: string, remote: boolean, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
161
+ sweep(root)
162
+ if (!remote) {
163
+ calm ??= waitCalm(say)
164
+ await calm
165
+ }
158
166
  const dir = mkdtempSync(join(soundCache(root), '.make-'))
159
167
  try {
160
168
  const out = join(dir, 'out.wav')
@@ -401,7 +401,7 @@ function drawInto(g: SKRSContext2D, d: TitleDraw, [W, H]: readonly [number, numb
401
401
  // a strong display line in the upper third: light words in a thick edge outline, an accent stroke inside it
402
402
  const p = own({ ...base((d.fx?.size ?? 112) * k, 900), outline: { w: 22 * k, color: look.edge }, inner: { w: 8 * k, color: look.accent }, shadow: { blur: 26 * k, dy: 10 * k, color: alpha(look.edge, 0.55) } })
403
403
  setFace(g, p)
404
- const lines = wrap(g, [first, ...more].join(' '), W * 0.82)
404
+ const lines = wrap(g, text, W * 0.82)
405
405
  lines.forEach((l, i) => ink(cx, g, p, l, W / 2, H * 0.26 + (i - (lines.length - 1) / 2) * p.px * 1.12))
406
406
  } else if (style === 'line') {
407
407
  // a tagline: light words centred low on a soft dark band, no plate, the frame stays the picture
@@ -12,9 +12,11 @@ export type MdLintReport = {
12
12
  ok: boolean
13
13
  }
14
14
 
15
- export function lintMd(cfg: ScanMdConfig): MdLintReport {
15
+ /** `listedElsewhere`: pages another wiki's index lists (scan-root relative), never an orphan here */
16
+ export function lintMd(cfg: ScanMdConfig & { listedElsewhere?: string[] }): MdLintReport {
16
17
  const scan = scanMd(cfg)
17
- const orphans = scan.index == null ? [] : scan.graph.nodes.filter((n) => n.depth == null).map((n) => n.id)
18
+ const elsewhere = new Set(cfg.listedElsewhere ?? [])
19
+ const orphans = scan.index == null ? [] : scan.graph.nodes.filter((n) => n.depth == null && !elsewhere.has(n.id)).map((n) => n.id)
18
20
  return {
19
21
  index: scan.index,
20
22
  files: scan.graph.nodes.length,
@@ -1,13 +1,18 @@
1
1
  // md-wiki graph server + link lint (folded in from the standalone mdwiki
2
2
  // lib; that npm package is frozen). Plain modules behind cmd_Wiki —
3
3
  // clipanion owns the option parsing.
4
- import { basename, relative, resolve } from 'path'
4
+ import { existsSync } from 'fs'
5
+ import { basename, join, relative, resolve } from 'path'
6
+ import { agentDirAt, contributionFileAt } from '../core/agent-dir-at.ts'
5
7
  import { lintMd } from './lint-md.ts'
6
8
  import { scanMdGraph } from './scan-md.ts'
7
9
  import { serveMdGraph } from './serve-graph.ts'
8
10
 
9
11
  export type WikiScanOpts = {
10
- root: string
12
+ /** default: the repo's wiki, as the hub mounts it (`wiki/`, else the agent folder, else the cwd) */
13
+ root?: string
14
+ /** the repo the command runs in, default the process's cwd */
15
+ cwd?: string
11
16
  index?: string
12
17
  skip?: string
13
18
  /** where the verdict goes. The command passes its own stream, so the
@@ -16,8 +21,15 @@ export type WikiScanOpts = {
16
21
  print?: (line: string) => void
17
22
  }
18
23
 
24
+ // a `→ <path>` ref is relative to the wiki folder, so a lint rooted above it reports every ref as dangling
25
+ export function defaultWikiRoot(cwd: string): string {
26
+ if (existsSync(join(cwd, 'wiki'))) return 'wiki'
27
+ const agent = agentDirAt(cwd)
28
+ return existsSync(join(cwd, agent)) ? agent : '.'
29
+ }
30
+
19
31
  const scanConfig = (o: WikiScanOpts): { root: string; index?: string; skipDirs?: string[] } => ({
20
- root: resolve(process.cwd(), o.root),
32
+ root: resolve(o.cwd ?? process.cwd(), o.root ?? defaultWikiRoot(o.cwd ?? process.cwd())),
21
33
  index: o.index,
22
34
  skipDirs: o.skip?.split(',').filter(Boolean),
23
35
  })
@@ -25,8 +37,9 @@ const scanConfig = (o: WikiScanOpts): { root: string; index?: string; skipDirs?:
25
37
  export async function runWikiServe(o: WikiScanOpts & { port: number; title?: string }): Promise<number> {
26
38
  const say = o.print ?? console.log
27
39
  const cfg = scanConfig(o)
28
- const rel = relative(process.cwd(), cfg.root)
29
- const title = o.title ?? (rel === '' ? basename(cfg.root) : `${basename(process.cwd())} ${rel}`)
40
+ const cwd = o.cwd ?? process.cwd()
41
+ const rel = relative(cwd, cfg.root)
42
+ const title = o.title ?? (rel === '' ? basename(cfg.root) : `${basename(cwd)} ${rel}`)
30
43
  try {
31
44
  serveMdGraph({ port: o.port, title, root: cfg.root, load: () => scanMdGraph(cfg) })
32
45
  say(`wiki graph → http://localhost:${o.port} (open in browser, or VSCode "Simple Browser: Show")`)
@@ -45,7 +58,10 @@ export async function runWikiServe(o: WikiScanOpts & { port: number; title?: str
45
58
  export function runWikiLint(o: WikiScanOpts): number {
46
59
  const say = o.print ?? console.log
47
60
  const cfg = scanConfig(o)
48
- const r = lintMd(cfg)
61
+ // the global contribution is listed by the house index (SK033), never by agent/'s own
62
+ const cwd = o.cwd ?? process.cwd()
63
+ const contribution = relative(cfg.root, resolve(cwd, contributionFileAt(cwd)))
64
+ const r = lintMd({ ...cfg, listedElsewhere: contribution.startsWith('..') ? [] : [contribution] })
49
65
  if (r.index == null) {
50
66
  say(o.index != null
51
67
  ? `FAIL entrypoint '${o.index}' not found in ${cfg.root}`
@@ -61,7 +61,9 @@ function scanMdNow(cfg: ScanMdConfig): MdScan {
61
61
  const walk = (rel: string) => {
62
62
  for (const e of readdirSync(join(cfg.root, rel))) {
63
63
  const r = rel === '' ? e : `${rel}/${e}`
64
- if (statSync(join(cfg.root, r)).isDirectory()) {
64
+ const st = statSync(join(cfg.root, r), { throwIfNoEntry: false })
65
+ if (st == null) continue // a link to nothing (a deploy stage's gone target)
66
+ if (st.isDirectory()) {
65
67
  if (!skip.has(e) && !e.startsWith('.') && !vendored.has(join(cfg.root, r))) walk(r)
66
68
  } else if (e.endsWith('.md')) files.push(r)
67
69
  }