rvlib-shipkit 2.17.1 → 2.19.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.
- package/CHANGELOG.md +27 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +63 -10
- package/src/checks/SK039-vscode-watch-generated.check.ts +119 -0
- package/src/cli/cmd_Asks.ts +3 -1
- package/src/cli/cmd_GlobalProcesses.ts +34 -11
- package/src/cli/cmd_Home.ts +38 -2
- package/src/cli/cmd_Secret.ts +4 -30
- package/src/cli/cmd_Social.ts +40 -1
- package/src/cli/cmd_Trailer.ts +15 -3
- package/src/cli/registry.ts +2 -1
- package/src/collections/actions.ts +29 -1
- package/src/collections/collection-types.ts +2 -0
- package/src/collections/providers.ts +1 -1
- package/src/home/home-paths.ts +5 -1
- package/src/home/home-start.ts +12 -12
- package/src/home/run-daemon.ts +11 -2
- package/src/home/run-pm.ts +9 -1
- package/src/home/supervise.ts +3 -1
- package/src/identities/identities.ts +22 -5
- package/src/review/http.ts +7 -2
- package/src/review/store.ts +81 -19
- package/src/scaffold/files/vscode-settings.json +9 -1
- package/src/secrets/manager.ts +59 -0
- package/src/secrets/name.ts +2 -0
- package/src/serve/hub-app/auto-text.tsx +6 -1
- package/src/serve/hub-app/col-card.tsx +10 -0
- package/src/serve/hub-app/cols-svc.ts +37 -6
- package/src/serve/hub-app/hub.css +1 -0
- package/src/serve/hub-app/review/review-st.ts +12 -2
- package/src/serve/hub-app/review/review-thread.tsx +1 -1
- package/src/serve/hub-app/review/thread-st.ts +17 -1
- package/src/serve/hub-app/social/identity-pictures.ts +74 -0
- package/src/serve/hub-app/social/kit.tsx +3 -3
- package/src/serve/hub-app/social/post-card.tsx +2 -1
- package/src/serve/hub-app/social/social-page.tsx +77 -37
- package/src/serve/hub-app/social.css +9 -4
- package/src/serve/hub-app/stores/stores-page.tsx +4 -3
- package/src/serve/hub-app/veille/veille-page.tsx +2 -1
- package/src/serve/serve-hub.ts +16 -6
- package/src/serve/warm-cell.ts +63 -1
- package/src/shot/box.ts +23 -8
- package/src/shot/browser-slot.ts +8 -1
- package/src/shot/client.ts +9 -4
- package/src/shot/clip-encoder.ts +5 -2
- package/src/shot/job-store.ts +167 -0
- package/src/shot/shooter.ts +8 -3
- package/src/social/discord-layout.ts +239 -0
- package/src/social/md.ts +14 -6
- package/src/social/publish/discord.ts +3 -2
- package/src/social/routes.ts +3 -3
- package/src/stores/routes.ts +2 -2
- package/src/suite/judge-suites.ts +1 -1
- package/src/suite/select.ts +32 -6
- package/src/suite/suite-cli.ts +5 -5
- package/src/trailer/build.ts +75 -50
- package/src/trailer/draft.ts +28 -0
- package/src/trailer/footage.ts +4 -2
- package/src/trailer/grammar.ts +11 -9
- package/src/trailer/graph.ts +41 -12
- package/src/trailer/profile.ts +35 -0
- package/src/trailer/prune.ts +15 -10
- package/src/trailer/stitch.ts +22 -10
- package/src/trailer/titles.ts +47 -2
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// repo's diff shows it; Feedback appends are append-only, never destructive).
|
|
4
4
|
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
5
5
|
import { join } from 'path'
|
|
6
|
-
import { archiveAsk, proofAsk } from '../asks/asks-queue.ts'
|
|
6
|
+
import { archiveAsk, checkAsk, openAsks, proofAsk, type OneCheck } from '../asks/asks-queue.ts'
|
|
7
|
+
import { redact, type SecretStore } from '../secrets/manager.ts'
|
|
8
|
+
import { SECRET_NAME } from '../secrets/name.ts'
|
|
7
9
|
|
|
8
10
|
const today = (): string => new Date().toISOString().slice(0, 10)
|
|
9
11
|
|
|
@@ -35,3 +37,29 @@ export function askProof(root: string, asksDir: string, file: string, url: strin
|
|
|
35
37
|
if (file.includes('/') || file.includes('..')) throw new Error('bad path')
|
|
36
38
|
proofAsk(join(root, asksDir), file, url)
|
|
37
39
|
}
|
|
40
|
+
|
|
41
|
+
export type SecretAnswer = { stored: string } & OneCheck
|
|
42
|
+
|
|
43
|
+
/** a value pasted under a credential ask: stored under a name that open ask
|
|
44
|
+
* declares, then that ask's check alone. Its truth is the keychain, never a
|
|
45
|
+
* file: the value is not written, logged or answered, and a failure line has
|
|
46
|
+
* it replaced by ‹value› */
|
|
47
|
+
export async function askSecret(o: { root: string; asksDir: string; file: string; name: string; value: string; store: SecretStore }): Promise<SecretAnswer> {
|
|
48
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.md$/.test(o.file)) throw new Error('bad path')
|
|
49
|
+
const dir = join(o.root, o.asksDir)
|
|
50
|
+
const ask = openAsks(dir).find((a) => a.file === o.file)
|
|
51
|
+
if (ask == null) throw new Error(`no open ask ${o.file}`)
|
|
52
|
+
if (ask.kind !== 'credential') throw new Error(`${o.file} is a ${ask.kind} ask: only a credential ask stores a secret`)
|
|
53
|
+
if (!SECRET_NAME.test(o.name) || !ask.secrets.includes(o.name)) throw new Error(`${o.file} declares no secret named ${o.name}`)
|
|
54
|
+
const value = o.value.trim()
|
|
55
|
+
if (value === '') throw new Error('empty value: nothing stored')
|
|
56
|
+
let c: OneCheck
|
|
57
|
+
try {
|
|
58
|
+
const r = await o.store(o.name, value)
|
|
59
|
+
if (!r.ok) throw new Error(`${o.name} not stored: ${r.why}`)
|
|
60
|
+
c = await checkAsk(o.root, dir, o.file)
|
|
61
|
+
} catch (e) {
|
|
62
|
+
throw new Error(redact((e as Error).message, value))
|
|
63
|
+
}
|
|
64
|
+
return c.check === 'failed' ? { stored: o.name, check: 'failed', why: redact(c.why, value) } : { stored: o.name, ...c }
|
|
65
|
+
}
|
|
@@ -187,6 +187,8 @@ export type AskFacts = {
|
|
|
187
187
|
blocks: string
|
|
188
188
|
/** the shell probe that closes it once it exits 0, null for a manual ask */
|
|
189
189
|
probe: string | null
|
|
190
|
+
/** the secret names a credential ask stores: its page takes each pasted value */
|
|
191
|
+
secrets: string[]
|
|
190
192
|
}
|
|
191
193
|
|
|
192
194
|
/** one test file, as its row and its page read it */
|
|
@@ -121,7 +121,7 @@ const slug = (t: string): string => t.toLowerCase().replace(/[^a-z0-9]+/g, '-').
|
|
|
121
121
|
/** wire lines re-rendered as a fenced block for an instance's md */
|
|
122
122
|
const wireMd = (lines: string[]): string => `\`\`\`\n${lines.join('\n')}\n\`\`\``
|
|
123
123
|
|
|
124
|
-
const askFacts = (a: Ask): AskFacts => ({ kind: a.kind, created: a.created, closed: a.closed, blocks: a.blocks, probe: a.check })
|
|
124
|
+
const askFacts = (a: Ask): AskFacts => ({ kind: a.kind, created: a.created, closed: a.closed, blocks: a.blocks, probe: a.check, secrets: a.kind === 'credential' ? a.secrets : [] })
|
|
125
125
|
|
|
126
126
|
export function asksCollection(root: string, c: RepoConfig): Collection {
|
|
127
127
|
return {
|
package/src/home/home-paths.ts
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// Nothing here lives in a repo: the home is per machine, and a repo that is
|
|
3
3
|
// cloned elsewhere carries none of it.
|
|
4
4
|
import { homedir } from 'os'
|
|
5
|
-
import { join } from 'path'
|
|
5
|
+
import { dirname, join } from 'path'
|
|
6
|
+
import { gitRoot } from '../core/git-root.ts'
|
|
7
|
+
|
|
8
|
+
/** the house repo: the checkout that holds the house wiki index, the one root pm and the daemon run from */
|
|
9
|
+
export const houseOfIndex = (index: string): string | null => gitRoot(dirname(index))?.top ?? null
|
|
6
10
|
|
|
7
11
|
/** just below the hashed hub range (4800-4979), so no repo hub can hash onto it */
|
|
8
12
|
export const DEFAULT_HOME_PORT = 4799
|
package/src/home/home-start.ts
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
// serve handoff both come through here.
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync } from 'fs'
|
|
5
5
|
import { homedir } from 'os'
|
|
6
|
-
import {
|
|
7
|
-
import { gitRoot } from '../core/git-root.ts'
|
|
6
|
+
import { join, resolve } from 'path'
|
|
8
7
|
import { homeRepo, houseIndex } from '../serve/project-gutter.ts'
|
|
9
8
|
import type { WrapperOf } from './gui-app.ts'
|
|
10
9
|
|
|
@@ -12,7 +11,7 @@ import type { WrapperOf } from './gui-app.ts'
|
|
|
12
11
|
// at the startup of every command that imports this module
|
|
13
12
|
const gui = (): Promise<typeof import('./gui-app.ts')> => import('./gui-app.ts')
|
|
14
13
|
import { installedHouseRoot, LABEL, plistPath } from './home-launchd.ts'
|
|
15
|
-
import { childLog, daemonPort, daemonUp, homeDir, homePort, homeUp, pmLog } from './home-paths.ts'
|
|
14
|
+
import { childLog, daemonPort, daemonUp, homeDir, homePort, homeUp, houseOfIndex, pmLog } from './home-paths.ts'
|
|
16
15
|
|
|
17
16
|
/** the pm LaunchAgent is installed: on this machine no hub runs outside the home */
|
|
18
17
|
export const homeInstalled = (): boolean => existsSync(plistPath())
|
|
@@ -62,16 +61,17 @@ export function houseCli(root: string, own: string): string {
|
|
|
62
61
|
return own
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
/** the repo that hosts the house wiki, seen from any house repo, or null */
|
|
66
|
-
export function houseRootOf(cwd: string): string | null {
|
|
67
|
-
const index = houseIndex(homeRepo(cwd),
|
|
68
|
-
|
|
69
|
-
return gitRoot(dirname(index))?.top ?? null
|
|
64
|
+
/** the repo that hosts the house wiki, seen from any folder of any house repo, or null */
|
|
65
|
+
export function houseRootOf(cwd: string, home = homedir()): string | null {
|
|
66
|
+
const index = houseIndex(homeRepo(cwd), home)
|
|
67
|
+
return index == null ? null : houseOfIndex(index)
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
/** the house
|
|
73
|
-
*
|
|
74
|
-
|
|
70
|
+
/** the house this machine runs: the one cwd sits in, else the one the
|
|
71
|
+
* installed pm runs from. Never cwd itself: a daemon run from a folder
|
|
72
|
+
* inside a repo finds no repo config there and never boots. The pm agent's
|
|
73
|
+
* root and the shipkit app's mark */
|
|
74
|
+
export const houseRoot = (cwd: string, o: { plist?: string; home?: string } = {}): string | null => houseRootOf(cwd, o.home) ?? installedHouseRoot(o.plist ?? plistPath())
|
|
75
75
|
|
|
76
76
|
export const CHROME =process.env.CHROME ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
|
77
77
|
/** the window's own Chrome profile: its own dock icon and cookies, apart from the everyday browser */
|
|
@@ -96,7 +96,7 @@ export async function openWindow(url: string, o: { root?: string | null; version
|
|
|
96
96
|
const { BUNDLE_ID, canBuildGui, ensureGuiApp, quitCmd } = await gui()
|
|
97
97
|
if (canBuildGui()) {
|
|
98
98
|
try {
|
|
99
|
-
const { app, rebuilt } = await ensureGuiApp({ root: o.root ??
|
|
99
|
+
const { app, rebuilt } = await ensureGuiApp({ root: o.root ?? houseRoot(process.cwd()), version: o.version ?? '0' })
|
|
100
100
|
// a running copy is the old build: it quits, and the new one opens the window
|
|
101
101
|
if (rebuilt) Bun.spawnSync(quitCmd(BUNDLE_ID), { stdout: 'ignore', stderr: 'ignore' })
|
|
102
102
|
const cmd = ['open', '-a', app, url]
|
package/src/home/run-daemon.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { ensureIdentity } from '../core/identity.ts'
|
|
|
20
20
|
import { homedir } from 'os'
|
|
21
21
|
import { join } from 'path'
|
|
22
22
|
import { startBeat } from './beat.ts'
|
|
23
|
-
import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
|
|
23
|
+
import { childBeat, childLog, daemonPort, homeDir, homePort, homeUp, houseOfIndex, hubBase, publicHome, WORKER_ENV } from './home-paths.ts'
|
|
24
24
|
import { inboxAddress } from './inbox-shape.ts'
|
|
25
25
|
import { HomeState } from './home-state.ts'
|
|
26
26
|
import { Hubs } from './hubs.ts'
|
|
@@ -44,7 +44,16 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
|
|
|
44
44
|
const own = o.port ?? daemonPort()
|
|
45
45
|
// the port a page reaches every hub on: the web's
|
|
46
46
|
const port = homePort()
|
|
47
|
-
const
|
|
47
|
+
const seen = houseRepos(root, homedir())
|
|
48
|
+
// started in another folder (a house repo, a folder inside one): the daemon runs from the house repo, whose config
|
|
49
|
+
// it loads, never from the folder it started in
|
|
50
|
+
const top = seen.index == null ? null : houseOfIndex(seen.index)
|
|
51
|
+
const moved = top != null && top !== root
|
|
52
|
+
if (moved) {
|
|
53
|
+
io.print(`note: the daemon started in ${root}, so it runs from the house repo ${top}`)
|
|
54
|
+
root = top
|
|
55
|
+
}
|
|
56
|
+
const house = moved ? houseRepos(root, homedir()) : seen
|
|
48
57
|
if (house.index == null) {
|
|
49
58
|
io.printErr(`FAIL: ${root} includes no house wiki index in its CLAUDE.md, so the daemon has no repos to load. Run it from the repo that hosts the house wiki`)
|
|
50
59
|
return 1
|
package/src/home/run-pm.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// against pm's own 20.
|
|
8
8
|
import { stampConsole } from '../core/log-stamp.ts'
|
|
9
9
|
import { fileURLToPath } from 'url'
|
|
10
|
-
import { daemonPort, homeDir, homePort, homeUp, homeUrl, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
|
|
10
|
+
import { daemonPort, homeDir, homePort, homeUp, homeUrl, houseOfIndex, pmPort, pmUp, WORKER_ENV } from './home-paths.ts'
|
|
11
11
|
import { reloadOnOwnCode } from './lib-watch.ts'
|
|
12
12
|
import { Pm, PM_TICK_MS, type Role } from './pm.ts'
|
|
13
13
|
import { Resources } from './resources.ts'
|
|
@@ -81,6 +81,14 @@ export async function runPm(root: string, io: HomeIo, o: { port?: number } = {})
|
|
|
81
81
|
let c: PmConfig
|
|
82
82
|
try {
|
|
83
83
|
c = await readPmConfig(root)
|
|
84
|
+
// started from another folder (a house repo, a folder inside one): pm and its children run from the house
|
|
85
|
+
// repo, never from the folder pm started in, where the daemon finds no repo config
|
|
86
|
+
const house = c.index == null ? null : houseOfIndex(c.index)
|
|
87
|
+
if (house != null && house !== root) {
|
|
88
|
+
io.print(`note: pm started in ${root}, so it runs from the house repo ${house}`)
|
|
89
|
+
root = house
|
|
90
|
+
c = await readPmConfig(root)
|
|
91
|
+
}
|
|
84
92
|
} catch (e) {
|
|
85
93
|
io.printErr(`FAIL: ${(e as Error).message}`)
|
|
86
94
|
return 1
|
package/src/home/supervise.ts
CHANGED
|
@@ -52,6 +52,8 @@ export type ProcView = {
|
|
|
52
52
|
note: string | null
|
|
53
53
|
/** up, and started by something else: not ours to stop */
|
|
54
54
|
external: boolean
|
|
55
|
+
/** what the owner last asked for */
|
|
56
|
+
want: 'up' | 'down'
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export type SuperviseDeps = {
|
|
@@ -361,7 +363,7 @@ export class Proc {
|
|
|
361
363
|
}
|
|
362
364
|
|
|
363
365
|
view(): ProcView {
|
|
364
|
-
return { id: this.spec.id, status: this.status, pid: this.pid, since: this.since, restarts: this.crashes.length, note: this.note, external: this.external }
|
|
366
|
+
return { id: this.spec.id, status: this.status, pid: this.pid, since: this.since, restarts: this.crashes.length, note: this.note, external: this.external, want: this.want }
|
|
365
367
|
}
|
|
366
368
|
}
|
|
367
369
|
|
|
@@ -71,7 +71,8 @@ export type Account = {
|
|
|
71
71
|
places: Place[]
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
/** one picture: the file shown, its size, and the same picture in its other formats (an svg beside its png) */
|
|
75
|
+
export type Picture = { file: string; w: number | null; h: number | null; also: string[] }
|
|
75
76
|
|
|
76
77
|
/** a company as the forms ask it: `legal.md`, and the private rows of the gitignored `legal.local.md` */
|
|
77
78
|
export type Legal = {
|
|
@@ -199,19 +200,35 @@ function imageSize(abs: string): { w: number | null; h: number | null } {
|
|
|
199
200
|
return { w: null, h: null }
|
|
200
201
|
}
|
|
201
202
|
|
|
202
|
-
/** the
|
|
203
|
-
|
|
203
|
+
/** the formats a picture is shown by, the first one its folder holds; the others are its `also` */
|
|
204
|
+
const SHOWN = ['jpg', 'png', 'webp', 'mp4', 'svg']
|
|
205
|
+
/** the identity's own folder of pictures, listed first whether `pictures` names it or not */
|
|
206
|
+
const OWN = 'pictures'
|
|
207
|
+
|
|
208
|
+
/** the pictures of its own folder then of each `pictures` folder, each folder the largest first, one picture per name
|
|
209
|
+
* with its other formats: a folder under `files`, or a `~/…` or absolute one elsewhere on the disk (a repo's own files
|
|
210
|
+
* the identity names), its pictures named by that path */
|
|
204
211
|
function pictures(files: string | null, dirs: string, file: string, errors: string[]): Picture[] {
|
|
205
212
|
if (files == null) return []
|
|
213
|
+
const named = dirs.split(',').map((d) => d.trim().replace(/\/+$/, '')).filter(Boolean)
|
|
206
214
|
const out: Picture[] = []
|
|
207
|
-
for (const dir of
|
|
215
|
+
for (const dir of [...(named.includes(OWN) || !existsSync(join(files, OWN)) ? [] : [OWN]), ...named]) {
|
|
208
216
|
const abs = dir.startsWith('~/') || isAbsolute(dir) ? home(dir) : join(files, dir)
|
|
209
217
|
if (!existsSync(abs)) {
|
|
210
218
|
errors.push(`${file}: pictures "${dir}" is no folder on this disk`)
|
|
211
219
|
continue
|
|
212
220
|
}
|
|
221
|
+
const byName = new Map<string, string[]>()
|
|
222
|
+
for (const f of readdirSync(abs).sort()) {
|
|
223
|
+
const m = /^(.+)\.(\w+)$/.exec(f)
|
|
224
|
+
if (m == null || !SHOWN.includes(m[2]!)) continue
|
|
225
|
+
byName.set(m[1]!, [...(byName.get(m[1]!) ?? []), m[2]!])
|
|
226
|
+
}
|
|
213
227
|
const here: Picture[] = []
|
|
214
|
-
for (const
|
|
228
|
+
for (const [name, exts] of byName) {
|
|
229
|
+
const [shown, ...rest] = [...exts].sort((x, y) => SHOWN.indexOf(x) - SHOWN.indexOf(y))
|
|
230
|
+
here.push({ file: `${dir}/${name}.${shown}`, ...imageSize(join(abs, `${name}.${shown}`)), also: rest.map((e) => `${dir}/${name}.${e}`) })
|
|
231
|
+
}
|
|
215
232
|
out.push(...here.sort((x, y) => (y.w ?? 0) * (y.h ?? 0) - (x.w ?? 0) * (x.h ?? 0)))
|
|
216
233
|
}
|
|
217
234
|
return out
|
package/src/review/http.ts
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
// answer under its ETag, a file with byte ranges
|
|
3
3
|
import { extname } from 'node:path'
|
|
4
4
|
|
|
5
|
-
export const TYPES: Record<string, string> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.webm': 'video/webm', '.mp4': 'video/mp4', '.ico': 'image/x-icon' }
|
|
5
|
+
export const TYPES: Record<string, string> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.svg': 'image/svg+xml', '.webm': 'video/webm', '.mp4': 'video/mp4', '.ico': 'image/x-icon' }
|
|
6
6
|
export const NO_STORE = { 'Cache-Control': 'no-store' }
|
|
7
7
|
/** an item's files never change once written, nor a kept render under its version: a phone keeps what it fetched */
|
|
8
8
|
export const KEEP = { 'Cache-Control': 'private, max-age=86400' }
|
|
9
|
+
/** a file rebuilt in place under its name (an identity's picture, a store's asset): the page asks each time, and a
|
|
10
|
+
* 304 answers while its size and mtime hold */
|
|
11
|
+
export const FRESH = { 'Cache-Control': 'no-cache' }
|
|
9
12
|
|
|
10
13
|
/** a json answer under its ETag: 304 when the page holds it, gzipped when the page takes it and it is worth it. A
|
|
11
14
|
* caller that keeps the answer passes `held`, the zip made once for every page that asks the same tag */
|
|
@@ -27,7 +30,9 @@ export async function ranged(req: Request, path: string, headers: Record<string,
|
|
|
27
30
|
const file = Bun.file(path)
|
|
28
31
|
if (!(await file.exists())) return bad(`no ${path.split('/').pop()}`, 404)
|
|
29
32
|
const size = file.size
|
|
30
|
-
const
|
|
33
|
+
const tag = headers === FRESH ? `"${size.toString(36)}-${Math.round(file.lastModified).toString(36)}"` : null
|
|
34
|
+
if (tag && req.headers.get('If-None-Match') === tag) return new Response(null, { status: 304, headers: { ...FRESH, ETag: tag } })
|
|
35
|
+
const head = { 'Content-Type': TYPES[extname(path).toLowerCase()] ?? 'application/octet-stream', 'Accept-Ranges': 'bytes', ...headers, ...(tag ? { ETag: tag } : {}) }
|
|
31
36
|
const range = /^bytes=(\d*)-(\d*)$/.exec(req.headers.get('range') ?? '')
|
|
32
37
|
if (!range) return new Response(file, { headers: { ...head, 'Content-Length': String(size) } })
|
|
33
38
|
const start = range[1] ? Number(range[1]) : Math.max(0, size - Number(range[2]))
|
package/src/review/store.ts
CHANGED
|
@@ -605,8 +605,8 @@ const CODE_KEEP_MS = 7 * 24 * 3600_000
|
|
|
605
605
|
const READ_STEP = 250
|
|
606
606
|
|
|
607
607
|
/** every item of the store, through the machine index (space/db.ts): an item whose stamp moved is read again */
|
|
608
|
-
function readRaws(dir: string): ReadAll {
|
|
609
|
-
const steps = readRawsSteps(dir)
|
|
608
|
+
function readRaws(dir: string, stamps?: Map<string, string>): ReadAll {
|
|
609
|
+
const steps = readRawsSteps(dir, stamps)
|
|
610
610
|
for (;;) {
|
|
611
611
|
const r = steps.next()
|
|
612
612
|
if (r.done) return r.value
|
|
@@ -615,8 +615,8 @@ function readRaws(dir: string): ReadAll {
|
|
|
615
615
|
|
|
616
616
|
/** the same read, the loop given back every READ_STEP items: a cold store of thousands of items is seconds of parsing
|
|
617
617
|
* (wiki tools/shipkit/home.md, Nothing heavy on the daemon's loop) */
|
|
618
|
-
async function readRawsAsync(dir: string): Promise<ReadAll> {
|
|
619
|
-
const steps = readRawsSteps(dir)
|
|
618
|
+
async function readRawsAsync(dir: string, stamps?: Map<string, string>): Promise<ReadAll> {
|
|
619
|
+
const steps = readRawsSteps(dir, stamps)
|
|
620
620
|
for (;;) {
|
|
621
621
|
const r = steps.next()
|
|
622
622
|
if (r.done) return r.value
|
|
@@ -624,8 +624,8 @@ async function readRawsAsync(dir: string): Promise<ReadAll> {
|
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
-
/** the one read, in steps: it yields between two of them, and returns the store */
|
|
628
|
-
function* readRawsSteps(dir: string): Generator<void, ReadAll, void> {
|
|
627
|
+
/** the one read, in steps: it yields between two of them, and returns the store. `stamps` hears each item's stamp */
|
|
628
|
+
function* readRawsSteps(dir: string, stamps?: Map<string, string>): Generator<void, ReadAll, void> {
|
|
629
629
|
const out: ReadAll = { items: [], broken: [] }
|
|
630
630
|
if (!existsSync(dir)) return out
|
|
631
631
|
const store = resolve(dir)
|
|
@@ -650,6 +650,7 @@ function* readRawsSteps(dir: string): Generator<void, ReadAll, void> {
|
|
|
650
650
|
if (++n % READ_STEP === 0) yield
|
|
651
651
|
seen.add(id)
|
|
652
652
|
const stamp = stampOf(join(dir, id))
|
|
653
|
+
stamps?.set(id, stamp)
|
|
653
654
|
const held = was.get(id)
|
|
654
655
|
let read: Read | null = null
|
|
655
656
|
if (held && held.stamp === stamp)
|
|
@@ -1005,12 +1006,59 @@ export async function readyItem(dir: string, id: string, o: { image?: string; no
|
|
|
1005
1006
|
}
|
|
1006
1007
|
|
|
1007
1008
|
/** a store watched by this process: `moved` counts the writes under it, by any process; `dirty` names the items they
|
|
1008
|
-
* touched since the last read, `held` every item as last read (null until a first whole read); null once the watch
|
|
1009
|
+
* touched since the last read, `held` every item as last read (null until a first whole read); null once the watch
|
|
1010
|
+
* failed. `folder`, `stamps`, `swept` and `rev` are the disk check under the watch (verify) */
|
|
1009
1011
|
interface Watched {
|
|
1010
1012
|
moved: number
|
|
1011
1013
|
dirty: Set<string>
|
|
1012
1014
|
held: Map<string, Read> | null
|
|
1013
1015
|
all: ReadAll | null
|
|
1016
|
+
folder: string
|
|
1017
|
+
stamps: Map<string, string>
|
|
1018
|
+
swept: number
|
|
1019
|
+
rev: number
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/** how often a read stats every item of a watched store, for a write inside an item its watch missed (17 ms on 3333) */
|
|
1023
|
+
export const SWEEP_MS = 10_000
|
|
1024
|
+
|
|
1025
|
+
const folderStamp = (key: string): string => {
|
|
1026
|
+
const s = statSync(key, { bigint: true, throwIfNoEntry: false })
|
|
1027
|
+
return s ? `${s.ctimeNs}.${s.ino}` : '-'
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/** the disk checked under the watch, which goes silent under load (FSEvents drops events) and must never freeze the
|
|
1031
|
+
* list: each call stats the store folder (1 µs), which a card's arrival or removal moves (a rename in it), and every
|
|
1032
|
+
* SWEEP_MS the stamp of each item. What moved unheard goes dirty and moves the ETag */
|
|
1033
|
+
function verify(key: string, w: Watched, now: number): void {
|
|
1034
|
+
if (!w.held) return
|
|
1035
|
+
let found = false
|
|
1036
|
+
const mark = (id: string): void => {
|
|
1037
|
+
if (w.dirty.has(id)) return
|
|
1038
|
+
w.dirty.add(id)
|
|
1039
|
+
found = true
|
|
1040
|
+
}
|
|
1041
|
+
const folder = folderStamp(key)
|
|
1042
|
+
if (folder !== w.folder) {
|
|
1043
|
+
w.folder = folder
|
|
1044
|
+
const ids = new Set(readdirSync(key).filter((n) => !n.startsWith('.')))
|
|
1045
|
+
for (const id of ids) if (!w.held.has(id)) mark(id)
|
|
1046
|
+
for (const id of w.held.keys()) if (!ids.has(id)) mark(id)
|
|
1047
|
+
}
|
|
1048
|
+
if (now - w.swept >= SWEEP_MS) {
|
|
1049
|
+
w.swept = now
|
|
1050
|
+
for (const [id, stamp] of w.stamps) if (stampOf(join(key, id)) !== stamp) mark(id)
|
|
1051
|
+
}
|
|
1052
|
+
if (found) w.rev++
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/** a whole read's result kept as the watch's view: its items, their stamps, the folder as it was before the read */
|
|
1056
|
+
function hold(w: Watched, all: ReadAll, folder: string, stamps: Map<string, string>, now: number): void {
|
|
1057
|
+
w.held = new Map<string, Read>([...all.items.map((x) => [x.item.id, { x }] as const), ...all.broken.map((b) => [b.id, { error: b.error }] as const)])
|
|
1058
|
+
w.all = all
|
|
1059
|
+
w.folder = folder
|
|
1060
|
+
w.stamps = stamps
|
|
1061
|
+
w.swept = now
|
|
1014
1062
|
}
|
|
1015
1063
|
const watched = new Map<string, Watched | null>()
|
|
1016
1064
|
const BOOT = Date.now().toString(36)
|
|
@@ -1025,7 +1073,7 @@ function touched(path: string): void {
|
|
|
1025
1073
|
function watchOf(dir: string): Watched | null {
|
|
1026
1074
|
const key = resolve(dir)
|
|
1027
1075
|
if (watched.has(key)) return watched.get(key) ?? null
|
|
1028
|
-
const w: Watched = { moved: 0, dirty: new Set(), held: null, all: null }
|
|
1076
|
+
const w: Watched = { moved: 0, dirty: new Set(), held: null, all: null, folder: '', stamps: new Map(), swept: 0, rev: 0 }
|
|
1029
1077
|
try {
|
|
1030
1078
|
// an item's lock is no change of the list
|
|
1031
1079
|
const watcher = watch(key, { recursive: true }, (_, name) => {
|
|
@@ -1052,17 +1100,21 @@ export async function warmStore(dir: string): Promise<void> {
|
|
|
1052
1100
|
if (!w || (w.held && w.all)) return
|
|
1053
1101
|
// what moved before the read is in it; what moves during it stays dirty, read again by the next reader
|
|
1054
1102
|
w.dirty.clear()
|
|
1055
|
-
const
|
|
1103
|
+
const folder = folderStamp(resolve(dir))
|
|
1104
|
+
const stamps = new Map<string, string>()
|
|
1105
|
+
const all = await readRawsAsync(dir, stamps)
|
|
1056
1106
|
if (w.held && w.all) return
|
|
1057
|
-
w
|
|
1058
|
-
w.all = all
|
|
1107
|
+
hold(w, all, folder, stamps, Date.now())
|
|
1059
1108
|
}
|
|
1060
1109
|
|
|
1061
|
-
/** changes when anything the list is built from changes: watched, a count of writes
|
|
1062
|
-
|
|
1110
|
+
/** changes when anything the list is built from changes: watched, a count of writes and what the disk check found;
|
|
1111
|
+
* else a scan. The list's ETag */
|
|
1112
|
+
export function storeStamp(dir: string, now = Date.now()): string {
|
|
1063
1113
|
if (!existsSync(dir)) return 'none'
|
|
1064
1114
|
const w = watchOf(dir)
|
|
1065
|
-
|
|
1115
|
+
if (!w) return scanStamp(dir)
|
|
1116
|
+
verify(resolve(dir), w, now)
|
|
1117
|
+
return `${BOOT}.${w.moved}.${w.rev}.${wrote}`
|
|
1066
1118
|
}
|
|
1067
1119
|
|
|
1068
1120
|
/** the store's stamp and who listens (the live watchers' pids), so a watch that starts or dies moves it too */
|
|
@@ -1097,18 +1149,28 @@ function readRawsCached(dir: string): ReadAll {
|
|
|
1097
1149
|
if (cached?.dir !== dir || cached.tag !== tag) cached = { dir, tag, all: readRaws(dir) }
|
|
1098
1150
|
return cached.all
|
|
1099
1151
|
}
|
|
1152
|
+
const key = resolve(dir)
|
|
1153
|
+
const now = Date.now()
|
|
1100
1154
|
if (!w.held || !w.all) {
|
|
1101
1155
|
w.dirty.clear()
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1104
|
-
|
|
1156
|
+
const folder = folderStamp(key)
|
|
1157
|
+
const stamps = new Map<string, string>()
|
|
1158
|
+
const all = readRaws(dir, stamps)
|
|
1159
|
+
hold(w, all, folder, stamps, now)
|
|
1105
1160
|
return all
|
|
1106
1161
|
}
|
|
1162
|
+
verify(key, w, now)
|
|
1107
1163
|
if (w.dirty.size === 0) return w.all
|
|
1108
1164
|
for (const id of w.dirty) {
|
|
1109
1165
|
if (id === '' || id.startsWith('.')) continue
|
|
1110
|
-
if (existsSync(join(dir, id)))
|
|
1111
|
-
|
|
1166
|
+
if (existsSync(join(dir, id))) {
|
|
1167
|
+
// stamped before the read: a write during it moves the stamp again
|
|
1168
|
+
w.stamps.set(id, stampOf(join(dir, id)))
|
|
1169
|
+
w.held.set(id, readOne(dir, id))
|
|
1170
|
+
} else {
|
|
1171
|
+
w.held.delete(id)
|
|
1172
|
+
w.stamps.delete(id)
|
|
1173
|
+
}
|
|
1112
1174
|
}
|
|
1113
1175
|
w.dirty.clear()
|
|
1114
1176
|
const out: ReadAll = { items: [], broken: [] }
|
|
@@ -35,5 +35,13 @@
|
|
|
35
35
|
|
|
36
36
|
// eslint off, and no formatter on save: formatting is a manual `bun fmt`
|
|
37
37
|
"eslint.enable": false,
|
|
38
|
-
"js/ts.format.enabled": false
|
|
38
|
+
"js/ts.format.enabled": false,
|
|
39
|
+
|
|
40
|
+
// shipkit's generated folders: never watched (SK039)
|
|
41
|
+
"files.watcherExclude": {
|
|
42
|
+
"**/.shipkit/cache/**": true,
|
|
43
|
+
"**/.shipkit/tmp/**": true,
|
|
44
|
+
"**/.shipkit/review/**": true,
|
|
45
|
+
"**/trailer/**/out/**": true
|
|
46
|
+
}
|
|
39
47
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// the house secret manager as a repo config spells it: `credsCommand` writes,
|
|
2
|
+
// `credsReadCommand` reads, the repo's own line before the house's. Every
|
|
3
|
+
// write goes through `storeArgv`: `sk secret set` with the terminal on stdin,
|
|
4
|
+
// the hub with the pasted value on stdin. A value never rides argv, a log or
|
|
5
|
+
// an answer: a failure line comes back with it replaced by ‹value›.
|
|
6
|
+
import { existsSync } from 'fs'
|
|
7
|
+
import { basename, join } from 'path'
|
|
8
|
+
import { gitRoot } from '../core/git-root.ts'
|
|
9
|
+
import { houseRootOf } from '../home/home-start.ts'
|
|
10
|
+
import { loadIdentities, speakerOf } from '../identities/identities.ts'
|
|
11
|
+
import { loadRepoConfig, type RepoConfig } from '../repo-config.ts'
|
|
12
|
+
|
|
13
|
+
export type SecretsWhere = { repos: string[]; identity: string | null; own: RepoConfig | null; house: RepoConfig | null }
|
|
14
|
+
|
|
15
|
+
export async function secretsWhere(cwd: string): Promise<SecretsWhere> {
|
|
16
|
+
const root = gitRoot(cwd)?.top ?? cwd
|
|
17
|
+
const own = existsSync(join(root, 'repo.config.ts')) ? await loadRepoConfig(root) : null
|
|
18
|
+
const houseRoot = houseRootOf(cwd)
|
|
19
|
+
const house = houseRoot == null ? null : houseRoot === root ? own : await loadRepoConfig(houseRoot).catch(() => null)
|
|
20
|
+
const identity = speakerOf(own?.speaksAs, await loadIdentities({ cwd }))?.id ?? null
|
|
21
|
+
return { repos: [...new Set([own?.name ?? basename(root), basename(root)])], identity, own, house }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** a refusal said as one line, never a stack */
|
|
25
|
+
export class NoManager extends Error {}
|
|
26
|
+
|
|
27
|
+
export function managerTemplate(w: SecretsWhere, key: 'credsReadCommand' | 'credsCommand'): string {
|
|
28
|
+
const t = w.own?.[key] ?? w.house?.[key]
|
|
29
|
+
if (w.own == null && w.house == null) throw new NoManager('FAIL not inside a house repo: run it from a repo that loads the house wiki')
|
|
30
|
+
if (t == null || t.trim() === '') throw new NoManager(`FAIL no ${key} in this repo's repo.config.ts nor the house's: nothing knows how to reach the secret manager`)
|
|
31
|
+
return t
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** the one argv every write runs; the value goes on its stdin */
|
|
35
|
+
export const storeArgv = (template: string, name: string, account?: string): string[] =>
|
|
36
|
+
[...template.trim().split(/\s+/).map((x) => x.replaceAll('{name}', name)), ...(account != null ? [account] : [])]
|
|
37
|
+
|
|
38
|
+
export type Stored = { ok: true } | { ok: false; why: string }
|
|
39
|
+
export type SecretStore = (name: string, value: string) => Promise<Stored>
|
|
40
|
+
|
|
41
|
+
/** every place the value shows in a line, replaced */
|
|
42
|
+
export const redact = (text: string, value: string): string => (value === '' ? text : text.replaceAll(value, '‹value›'))
|
|
43
|
+
|
|
44
|
+
/** a store through the repo's `credsCommand`, as `sk secret set` runs it, the value on stdin */
|
|
45
|
+
export function managerStore(cwd: string): SecretStore {
|
|
46
|
+
return async (name, value) => {
|
|
47
|
+
let template: string
|
|
48
|
+
try {
|
|
49
|
+
template = managerTemplate(await secretsWhere(cwd), 'credsCommand')
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return { ok: false, why: (e as Error).message }
|
|
52
|
+
}
|
|
53
|
+
const p = Bun.spawn(storeArgv(template, name), { cwd, env: process.env, stdin: new Blob([value]), stdout: 'ignore', stderr: 'pipe' })
|
|
54
|
+
const err = await new Response(p.stderr).text()
|
|
55
|
+
if ((await p.exited) === 0) return { ok: true }
|
|
56
|
+
const tail = err.trim().split('\n').slice(-2).join(' ')
|
|
57
|
+
return { ok: false, why: redact(`${template.trim().split(/\s+/)[0]} exited ${p.exitCode}${tail !== '' ? `: ${tail}` : ''}`, value) }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -19,7 +19,12 @@ export function AutoText({ value, onText, rows = 1, el, className, ...rest }: Pr
|
|
|
19
19
|
if (t == null) return
|
|
20
20
|
t.style.height = 'auto'
|
|
21
21
|
const edge = t.offsetHeight - t.clientHeight
|
|
22
|
-
|
|
22
|
+
// an empty box is as tall as its placeholder: the hint reads whole, never cut by a scrollbar
|
|
23
|
+
const hint = t.value === '' && t.placeholder !== ''
|
|
24
|
+
if (hint) t.value = t.placeholder
|
|
25
|
+
const h = t.scrollHeight
|
|
26
|
+
if (hint) t.value = ''
|
|
27
|
+
t.style.height = `${h + edge}px`
|
|
23
28
|
// a sheet's max-height stops it: only then may it scroll
|
|
24
29
|
t.style.overflowY = t.scrollHeight > t.clientHeight + 1 ? 'auto' : 'hidden'
|
|
25
30
|
}, [])
|
|
@@ -68,6 +68,16 @@ export const ColCard = observer(({ app, col, id }: { app: RepoSt; col: string; i
|
|
|
68
68
|
) : null}
|
|
69
69
|
{i.artifact?.url != null ? <div className="row"><a href={i.artifact.url} target="_blank" rel="noreferrer">mint ↗</a></div> : null}
|
|
70
70
|
{i.artifact?.steps != null ? <div className="row"><div>{i.artifact.steps.map((s, n) => <span key={n}>{n + 1}. {s}<br /></span>)}</div></div> : null}
|
|
71
|
+
{/* a credential ask takes its value here: a password field per secret it names, sent once, never shown */}
|
|
72
|
+
{askFile != null && i.severity != null ? (i.ask?.secrets ?? []).map((name) => (
|
|
73
|
+
<div className="row" key={name}>
|
|
74
|
+
<input type="password" autoComplete="off" spellCheck={false} placeholder={`paste the token for ${name}`} value={c.secretDrafts.get(name) ?? ''}
|
|
75
|
+
onChange={(e) => c.setSecretDraft(name, e.target.value)}
|
|
76
|
+
onKeyDown={(e) => { if (e.key === 'Enter') void c.storeSecret(askFile, name) }} />
|
|
77
|
+
<button onClick={() => void c.storeSecret(askFile, name)}>store</button>
|
|
78
|
+
</div>
|
|
79
|
+
)) : null}
|
|
80
|
+
{c.secretNote !== '' ? <div className="said">✓ {c.secretNote}</div> : null}
|
|
71
81
|
{askFile != null && i.severity != null ? (
|
|
72
82
|
<div className="row">
|
|
73
83
|
<input placeholder="proof URL (optional)" value={c.proofDraft} onChange={(e) => runInAction(() => { c.proofDraft = e.target.value })} />
|