rvlib-shipkit 2.21.0 → 2.22.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 +19 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +8 -7
- package/src/assets/kits/identity-kit.ts +158 -2
- package/src/cli/cmd_Bump.ts +3 -3
- package/src/cli/cmd_Rec.ts +349 -0
- package/src/cli/cmd_Releases.ts +4 -1
- package/src/cli/cmd_Secret.ts +10 -3
- package/src/cli/cmd_Sign.ts +24 -0
- package/src/cli/cmd_Social.ts +44 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +4 -0
- package/src/core/agent-spawn.ts +4 -17
- package/src/core/code-lines.ts +49 -0
- package/src/core/discover-checks.ts +27 -3
- package/src/core/hard-reset.ts +34 -0
- package/src/core/raw-access.ts +3 -13
- package/src/core/throwaway-worktree.ts +72 -0
- package/src/home/app-sign.ts +98 -0
- package/src/home/gui-app.ts +31 -12
- package/src/home/home-routes.ts +6 -0
- package/src/home/serve-web.ts +1 -1
- package/src/identities/identities.ts +6 -0
- package/src/media-kinds.ts +5 -3
- package/src/media-store/forget.ts +54 -0
- package/src/media-store/put.ts +4 -3
- package/src/media-store/space.ts +63 -24
- package/src/recordings/delete.ts +19 -0
- package/src/recordings/edit.ts +231 -0
- package/src/recordings/load.ts +37 -0
- package/src/recordings/marks-draw.ts +111 -0
- package/src/recordings/marks-png.ts +25 -0
- package/src/recordings/marks.ts +138 -0
- package/src/recordings/media-kind.ts +67 -0
- package/src/recordings/model.ts +170 -0
- package/src/recordings/open.ts +33 -0
- package/src/recordings/place.ts +89 -0
- package/src/recordings/presets.ts +99 -0
- package/src/recordings/recorder-app/Capture.swift +510 -0
- package/src/recordings/recorder-app/Clip.swift +107 -0
- package/src/recordings/recorder-app/Editor.swift +39 -0
- package/src/recordings/recorder-app/Tray.swift +298 -0
- package/src/recordings/recorder-app/main.swift +859 -0
- package/src/recordings/recorder-app.ts +46 -0
- package/src/recordings/recorder.shipkit.ts +11 -0
- package/src/recordings/routes.ts +140 -0
- package/src/recordings/run-recorder.ts +40 -0
- package/src/recordings/share.ts +107 -0
- package/src/recordings/take.ts +146 -0
- package/src/recordings/view.ts +40 -0
- package/src/release/gate-checkout.ts +74 -0
- package/src/release/release-scope.ts +35 -26
- package/src/release/run-bump.ts +79 -37
- package/src/release/run-release.ts +67 -53
- package/src/releases/add.ts +7 -2
- package/src/releases/from-card.ts +3 -3
- package/src/releases/model.ts +29 -7
- package/src/repo-config.ts +7 -3
- package/src/review/trailer-desk.ts +1 -0
- package/src/review/trailer-model.ts +2 -0
- package/src/secrets/manager.ts +18 -1
- package/src/serve/hub-app/home-st.ts +15 -5
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +6 -1
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/palette-st.ts +1 -0
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/recordings-st.ts +641 -0
- package/src/serve/hub-app/recordings-view.tsx +504 -0
- package/src/serve/hub-app/recordings.css +82 -0
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/trailer-page.tsx +1 -0
- package/src/serve/hub-app/review/trailer-st.ts +16 -0
- package/src/serve/hub-app/review/trailer-timeline.tsx +3 -0
- package/src/serve/hub-app/review.css +2 -0
- package/src/serve/hub-app/social/post-card.tsx +31 -3
- package/src/serve/hub-app/social/social-model.ts +4 -0
- package/src/serve/hub-app/social/social-st.ts +12 -0
- package/src/serve/hub-app/social.css +4 -0
- package/src/shipkit.ts +2 -2
- package/src/shot/box.ts +23 -17
- package/src/shot/browser-slot.ts +13 -3
- package/src/shot/film-box.ts +193 -117
- package/src/shot/shooter.ts +5 -3
- package/src/smoke/run-smoke.ts +8 -6
- package/src/social/compose.ts +14 -0
- package/src/social/drafts.ts +1 -1
- package/src/social/load.ts +16 -2
- package/src/social/publish/index.ts +3 -1
- package/src/social/publish/secret.ts +12 -4
- package/src/social/release-card.ts +69 -0
- package/src/social/release-stage.ts +49 -10
- package/src/social/routes.ts +5 -0
- package/src/social/stage.ts +9 -5
- package/src/trailer/build.ts +24 -0
- package/src/trailer/ffmpeg.ts +8 -0
- package/src/trailer/grammar.ts +9 -2
- package/src/trailer/look.ts +7 -0
- package/src/veille/chrome.ts +6 -3
package/src/shot/film-box.ts
CHANGED
|
@@ -1,34 +1,81 @@
|
|
|
1
1
|
// the box half of the box route (box.ts): run by bun on the box that films for a repo (repo.config.ts browsers.box),
|
|
2
|
-
// uploaded there by its content hash, node builtins only. One warm chromium
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// the
|
|
11
|
-
//
|
|
2
|
+
// uploaded there by its content hash, node builtins only. One warm chromium PER BROWSER SLOT of a repo (`<repo>-<slot>`,
|
|
3
|
+
// the Mac's slot index, browser-slot.ts), each on the box's discrete GPU with its own devtools port (the Mac reaches it
|
|
4
|
+
// through ssh) and its own profile, kept, so its HTTP cache outlives each film. A browser per slot because chromium
|
|
5
|
+
// runs every page of a browser through ONE GPU process: measured on wm (2026-11-10), a page booting there tripled
|
|
6
|
+
// another page's play (6.1 s alone, 20.9 s beside it; 6.1 s beside a boot in a browser of its own), and a look sheet's
|
|
7
|
+
// five tabs held that process at 100 % of a core while the 4090 idled. It is chromium's headless shell: the full
|
|
8
|
+
// chromium's headless mode composites a WebGPU canvas black in the box's session 0 (no display). The shell ships
|
|
9
|
+
// without the DirectX shader compiler Dawn's D3D12 loads, so it gets the full chromium's copy; the full chromium also
|
|
10
|
+
// reads the discrete GPU's LUID off chrome://gpu, which the shell lacks.
|
|
11
|
+
// up <playwright version> <slot key> the slot's browser answering, any page left in it closed (started when down
|
|
12
|
+
// or of another version: installed when missing, its GPU's LUID found)
|
|
13
|
+
// watch <slot key> <pid> <port> closes a page whose film died, ends the browser once nothing used it for
|
|
14
|
+
// IDLE_MS or its devtools went deaf (started by up, outside the ssh session)
|
|
15
|
+
// the constraint a reader breaks first: a slot is held by one film at a time on the Mac, so its browser is that film's
|
|
16
|
+
// alone: up may close its pages and replace it, and never touches another slot's browser. Windows OpenSSH ends every
|
|
17
|
+
// process of its session when it closes, so the browser and the watcher are created through WMI, outside it
|
|
12
18
|
import { createHash } from 'node:crypto'
|
|
13
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
19
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
14
20
|
import { homedir, uptime } from 'node:os'
|
|
15
21
|
import { dirname, join } from 'node:path'
|
|
16
22
|
|
|
23
|
+
/** the base the Mac maps a box port onto its own (box.ts localCdp); older versions ran their one browser on it */
|
|
17
24
|
export const CDP_PORT = 9333
|
|
25
|
+
/** the ports a slot's browser takes: past the 9333 and 9336 of older versions */
|
|
26
|
+
export const FIRST_PORT = 9340
|
|
27
|
+
const LAST_PORT = 9439
|
|
18
28
|
const PROBE_PORT = 9334
|
|
19
|
-
/** the browser ends once no film touched
|
|
29
|
+
/** the browser ends once no film touched its slot for this long and it shows no page */
|
|
20
30
|
const IDLE_MS = 10 * 60_000
|
|
21
|
-
/**
|
|
22
|
-
const
|
|
31
|
+
/** how long a devtools answer may take before the browser counts as not answering (a busy one answers in under 0.1 s) */
|
|
32
|
+
const ANSWER_MS = 5000
|
|
33
|
+
/** every SWEEP_MS the watcher looks; a page no client drives two sweeps in a row is closed, a browser whose devtools
|
|
34
|
+
* did not answer DEAF_SWEEPS sweeps in a row is ended */
|
|
35
|
+
const SWEEP_MS = 5000
|
|
36
|
+
const DEAF_SWEEPS = 6
|
|
23
37
|
|
|
24
38
|
const DIR = join(homedir(), 'dev', 'shipkit-film')
|
|
25
|
-
const
|
|
26
|
-
const
|
|
39
|
+
const SLOTS = join(DIR, 'slots')
|
|
40
|
+
const LOG = join(DIR, 'film-box.log')
|
|
41
|
+
/** the one browser of older versions, ended once it drives no page */
|
|
42
|
+
const LEGACY_PID = join(DIR, 'browser.pid')
|
|
43
|
+
const LEGACY_USED = join(DIR, 'used')
|
|
44
|
+
const LEGACY_QUIET_MS = 2 * 60_000
|
|
27
45
|
const say = (s: string) => console.error(`box: ${s}`)
|
|
28
46
|
|
|
29
|
-
/** this script's version: a browser another version started is replaced */
|
|
47
|
+
/** this script's version: a slot's browser another version started is replaced */
|
|
30
48
|
const VERSION = createHash('sha1').update(readFileSync(import.meta.path)).digest('hex').slice(0, 12)
|
|
31
49
|
|
|
50
|
+
/** a slot key as the Mac sends it: a file name */
|
|
51
|
+
export const slotKeyOk = (key: string): boolean => /^[\w.-]{1,80}$/.test(key)
|
|
52
|
+
|
|
53
|
+
/** the first port of FIRST_PORT..LAST_PORT that no slot's live browser holds and nothing answers on */
|
|
54
|
+
export async function freePort(taken: Set<number>, answering: (port: number) => Promise<boolean>): Promise<number> {
|
|
55
|
+
for (let p = FIRST_PORT; p <= LAST_PORT; p++) if (!taken.has(p) && !(await answering(p))) return p
|
|
56
|
+
throw new Error(`no free devtools port in ${FIRST_PORT}..${LAST_PORT}`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** what a slot's file holds: its browser's pid, the script version that started it, its devtools port */
|
|
60
|
+
export type SlotBrowser = { pid: number; version: string; port: number }
|
|
61
|
+
export const slotLine = (b: SlotBrowser): string => `${b.pid} ${b.version} ${b.port}`
|
|
62
|
+
export function parseSlotLine(s: string): SlotBrowser | null {
|
|
63
|
+
const [pid, version, port] = s.trim().split(' ')
|
|
64
|
+
return Number(pid) > 0 && Number(port) > 0 ? { pid: Number(pid), version: version ?? '', port: Number(port) } : null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const pidFile = (key: string) => join(SLOTS, `${key}.pid`)
|
|
68
|
+
const usedFile = (key: string) => join(SLOTS, `${key}.used`)
|
|
69
|
+
const readSlot = (key: string): SlotBrowser | null => (existsSync(pidFile(key)) ? parseSlotLine(readFileSync(pidFile(key), 'utf8')) : null)
|
|
70
|
+
|
|
71
|
+
/** one line of what the box did to its browsers (started, ended and why, pages closed), kept under 1 MB */
|
|
72
|
+
function log(line: string): void {
|
|
73
|
+
try {
|
|
74
|
+
if ((statSync(LOG, { throwIfNoEntry: false })?.size ?? 0) > 1 << 20) rmSync(LOG, { force: true })
|
|
75
|
+
appendFileSync(LOG, `${new Date().toISOString()} ${line}\n`)
|
|
76
|
+
} catch {}
|
|
77
|
+
}
|
|
78
|
+
|
|
32
79
|
/** playwright's own switches for a launched chromium (chromiumSwitches, headless), so a page films here as it would
|
|
33
80
|
* under a launch: --disable-ipc-flooding-protection above all, without which chromium drops a page's history updates
|
|
34
81
|
* past 200 in 10 s and a take's clock (its hash's stop=) froze at frame 201 */
|
|
@@ -70,9 +117,9 @@ const BROWSER_ARGS = [
|
|
|
70
117
|
'--lang=en-US',
|
|
71
118
|
]
|
|
72
119
|
|
|
73
|
-
async function answers(port: number): Promise<boolean> {
|
|
120
|
+
async function answers(port: number, ms = ANSWER_MS): Promise<boolean> {
|
|
74
121
|
try {
|
|
75
|
-
return (await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(
|
|
122
|
+
return (await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(ms) })).ok
|
|
76
123
|
} catch {
|
|
77
124
|
return false
|
|
78
125
|
}
|
|
@@ -112,7 +159,7 @@ function detached(line: string): number {
|
|
|
112
159
|
return pid
|
|
113
160
|
}
|
|
114
161
|
|
|
115
|
-
const
|
|
162
|
+
const killTree = (pid: number) => Bun.spawnSync(['taskkill', '/T', '/F', '/PID', String(pid)], { stdout: 'ignore', stderr: 'ignore' })
|
|
116
163
|
|
|
117
164
|
const alive = (pid: number) => {
|
|
118
165
|
try {
|
|
@@ -123,6 +170,20 @@ const alive = (pid: number) => {
|
|
|
123
170
|
}
|
|
124
171
|
}
|
|
125
172
|
|
|
173
|
+
/** the pid still names a headless shell: Windows hands a dead process's pid to the next one */
|
|
174
|
+
function isShell(pid: number): boolean {
|
|
175
|
+
const p = Bun.spawnSync(['tasklist', '/FI', `PID eq ${pid}`, '/FO', 'CSV', '/NH'], { stdout: 'pipe', stderr: 'ignore' })
|
|
176
|
+
return p.stdout.toString().toLowerCase().includes('chrome-headless-shell')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** a browser ended, said in the log, once its pid is still a headless shell; waits until it is gone (its profile freed) */
|
|
180
|
+
async function end(pid: number, why: string): Promise<void> {
|
|
181
|
+
if (!isShell(pid)) return
|
|
182
|
+
log(`end ${pid}: ${why}`)
|
|
183
|
+
killTree(pid)
|
|
184
|
+
for (let i = 0; i < 50 && alive(pid); i++) await Bun.sleep(100)
|
|
185
|
+
}
|
|
186
|
+
|
|
126
187
|
const quote = (s: string) => `"${s}"`
|
|
127
188
|
|
|
128
189
|
/** the LUID of the box's discrete GPU as chromium names it (`high,low`): chromium on Windows draws on the adapter the
|
|
@@ -135,16 +196,18 @@ async function discreteLuid(exe: string): Promise<string | null> {
|
|
|
135
196
|
const profile = join(DIR, 'probe-profile')
|
|
136
197
|
const pid = detached([exe, '--headless=new', `--remote-debugging-port=${PROBE_PORT}`, `--user-data-dir=${profile}`, '--no-first-run', 'about:blank'].map(quote).join(' '))
|
|
137
198
|
try {
|
|
138
|
-
for (let i = 0; i < 100 && !(await answers(PROBE_PORT)); i++) await Bun.sleep(100)
|
|
139
|
-
const target = (await (await fetch(`http://127.0.0.1:${PROBE_PORT}/json/new?chrome://gpu`, { method: 'PUT' })).json()) as { webSocketDebuggerUrl: string }
|
|
199
|
+
for (let i = 0; i < 100 && !(await answers(PROBE_PORT, 1000)); i++) await Bun.sleep(100)
|
|
200
|
+
const target = (await (await fetch(`http://127.0.0.1:${PROBE_PORT}/json/new?chrome://gpu`, { method: 'PUT', signal: AbortSignal.timeout(ANSWER_MS) })).json()) as { webSocketDebuggerUrl: string }
|
|
140
201
|
const text = await new Promise<string>((done, fail) => {
|
|
141
202
|
const ws = new WebSocket(target.webSocketDebuggerUrl)
|
|
203
|
+
const t = setTimeout(() => (ws.close(), fail(new Error('chrome://gpu: no answer in 10 s'))), 10_000)
|
|
142
204
|
let n = 0
|
|
143
205
|
const ask = () => ws.send(JSON.stringify({ id: ++n, method: 'Runtime.evaluate', params: { expression: "document.querySelector('info-view')?.shadowRoot?.textContent ?? ''", returnByValue: true } }))
|
|
144
206
|
ws.onopen = ask
|
|
145
207
|
ws.onmessage = (e) => {
|
|
146
208
|
const v = (JSON.parse(String(e.data)) as { result?: { result?: { value?: string } } }).result?.result?.value ?? ''
|
|
147
209
|
if (/GPU0/.test(v)) {
|
|
210
|
+
clearTimeout(t)
|
|
148
211
|
ws.close()
|
|
149
212
|
done(v)
|
|
150
213
|
} else if (n > 50) fail(new Error('chrome://gpu named no GPU in 5 s'))
|
|
@@ -158,135 +221,148 @@ async function discreteLuid(exe: string): Promise<string | null> {
|
|
|
158
221
|
return got
|
|
159
222
|
} finally {
|
|
160
223
|
// its profile stays for the next boot's probe: chromium holds its files a while after the kill
|
|
161
|
-
|
|
224
|
+
killTree(pid)
|
|
162
225
|
}
|
|
163
226
|
}
|
|
164
227
|
|
|
165
|
-
/**
|
|
166
|
-
function
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
228
|
+
/** one devtools call on the browser's own socket, ANSWER_MS at most */
|
|
229
|
+
async function browserCall<T>(port: number, method: string, params: Record<string, unknown> = {}): Promise<T> {
|
|
230
|
+
const { webSocketDebuggerUrl } = (await (await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(ANSWER_MS) })).json()) as { webSocketDebuggerUrl: string }
|
|
231
|
+
return await new Promise<T>((done, fail) => {
|
|
232
|
+
const ws = new WebSocket(webSocketDebuggerUrl)
|
|
233
|
+
const t = setTimeout(() => (ws.close(), fail(new Error(`${method}: no answer in ${ANSWER_MS / 1000} s`))), ANSWER_MS)
|
|
234
|
+
ws.onopen = () => ws.send(JSON.stringify({ id: 1, method, params }))
|
|
235
|
+
ws.onmessage = (e) => {
|
|
236
|
+
clearTimeout(t)
|
|
237
|
+
ws.close()
|
|
238
|
+
done((JSON.parse(String(e.data)) as { result: T }).result)
|
|
239
|
+
}
|
|
240
|
+
ws.onerror = () => fail(new Error(`${method}: the browser's socket failed`))
|
|
241
|
+
})
|
|
170
242
|
}
|
|
171
243
|
|
|
172
|
-
|
|
244
|
+
type Target = { targetId: string; type: string; url: string; attached: boolean }
|
|
245
|
+
|
|
246
|
+
/** the pages that show something (about:blank aside) */
|
|
247
|
+
async function pages(port: number): Promise<Target[]> {
|
|
248
|
+
const { targetInfos } = await browserCall<{ targetInfos: Target[] }>(port, 'Target.getTargets')
|
|
249
|
+
return targetInfos.filter((p) => p.type === 'page' && p.url !== 'about:blank')
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** the slot's browser answering for the film that holds the slot now: warm, or started (a lock serializes the starts:
|
|
253
|
+
* the ports they pick, the LUID probe) */
|
|
254
|
+
async function up(version: string, key: string): Promise<void> {
|
|
255
|
+
if (!slotKeyOk(key)) throw new Error(`up: '${key}' is not a slot key`)
|
|
173
256
|
const t = performance.now()
|
|
174
|
-
mkdirSync(
|
|
175
|
-
writeFileSync(
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
console.log(`up warm ${Math.round(performance.now() - t)} port ${
|
|
257
|
+
mkdirSync(SLOTS, { recursive: true })
|
|
258
|
+
writeFileSync(usedFile(key), String(Date.now()))
|
|
259
|
+
const c = readSlot(key)
|
|
260
|
+
if (c != null && c.version === VERSION && alive(c.pid) && (await answers(c.port))) {
|
|
261
|
+
// the slot is this film's: a page still open in its browser is a film's that died or never closed it
|
|
262
|
+
const left = await pages(c.port).catch(() => [])
|
|
263
|
+
for (const p of left) await browserCall(c.port, 'Target.closeTarget', { targetId: p.targetId }).catch(() => undefined)
|
|
264
|
+
if (left.length) log(`${key}: ${left.length} page(s) left by an earlier film closed`)
|
|
265
|
+
console.log(`up warm ${Math.round(performance.now() - t)} port ${c.port}${left.length ? `, ${left.length} page(s) an earlier film left closed` : ''}`)
|
|
183
266
|
return
|
|
184
267
|
}
|
|
185
|
-
|
|
186
|
-
|
|
268
|
+
if (c != null) await end(c.pid, `${key}: ${c.version !== VERSION ? 'another film-box version' : 'its devtools did not answer'}`)
|
|
269
|
+
await start(version, key, t)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function start(version: string, key: string, t: number): Promise<void> {
|
|
273
|
+
const lock = join(DIR, 'start.lock')
|
|
187
274
|
for (;;) {
|
|
188
275
|
try {
|
|
189
276
|
mkdirSync(lock)
|
|
190
277
|
break
|
|
191
278
|
} catch {
|
|
192
279
|
if (Date.now() - (statSync(lock, { throwIfNoEntry: false })?.mtimeMs ?? Date.now()) > 60_000) rmSync(lock, { recursive: true, force: true })
|
|
193
|
-
await Bun.sleep(
|
|
280
|
+
await Bun.sleep(100)
|
|
194
281
|
}
|
|
195
282
|
}
|
|
283
|
+
let b: SlotBrowser
|
|
284
|
+
let luid: string | null
|
|
196
285
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
286
|
+
await endLegacy()
|
|
287
|
+
const exe = chromium(version)
|
|
288
|
+
luid = await discreteLuid(exe.full)
|
|
289
|
+
if (luid == null) say('no discrete GPU named in chrome://gpu: the browser draws on the default adapter')
|
|
290
|
+
const taken = new Set<number>()
|
|
291
|
+
for (const f of readdirSync(SLOTS).filter((f) => f.endsWith('.pid'))) {
|
|
292
|
+
const s = parseSlotLine(readFileSync(join(SLOTS, f), 'utf8'))
|
|
293
|
+
if (s != null && alive(s.pid)) taken.add(s.port)
|
|
294
|
+
}
|
|
295
|
+
const port = await freePort(taken, (p) => answers(p, 300))
|
|
296
|
+
const args = [`--remote-debugging-port=${port}`, `--user-data-dir=${join(DIR, `profile-${key}`)}`, ...BROWSER_ARGS, ...(luid ? [`--use-adapter-luid=${luid}`] : []), 'about:blank']
|
|
297
|
+
b = { pid: detached([exe.shell, ...args].map(quote).join(' ')), version: VERSION, port }
|
|
298
|
+
writeFileSync(pidFile(key), slotLine(b))
|
|
200
299
|
} finally {
|
|
201
300
|
rmSync(lock, { recursive: true, force: true })
|
|
202
301
|
}
|
|
302
|
+
for (let i = 0; i < 150 && !(await answers(b.port, 1000)); i++) await Bun.sleep(100)
|
|
303
|
+
if (!(await answers(b.port))) throw new Error(`the browser of ${key} (pid ${b.pid}) did not answer on 127.0.0.1:${b.port} in 15 s`)
|
|
304
|
+
detached([process.execPath, import.meta.path, 'watch', key, String(b.pid), String(b.port)].map(quote).join(' '))
|
|
305
|
+
log(`${key}: started ${b.pid} on ${b.port}`)
|
|
306
|
+
console.log(`up started ${Math.round(performance.now() - t)} port ${b.port} pid ${b.pid}${luid ? ` luid ${luid}` : ''}`)
|
|
203
307
|
}
|
|
204
308
|
|
|
205
|
-
/**
|
|
206
|
-
*
|
|
207
|
-
async function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const port =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (luid == null) say('no discrete GPU named in chrome://gpu: the browser draws on the default adapter')
|
|
219
|
-
const args = [`--remote-debugging-port=${port}`, `--user-data-dir=${join(DIR, `profile-${port}`)}`, ...BROWSER_ARGS, ...(luid ? [`--use-adapter-luid=${luid}`] : []), 'about:blank']
|
|
220
|
-
const pid = detached([exe.shell, ...args].map(quote).join(' '))
|
|
221
|
-
writeFileSync(PID, `${pid} ${VERSION} ${port}`)
|
|
222
|
-
for (let i = 0; i < 150 && !(await answers(port)); i++) await Bun.sleep(100)
|
|
223
|
-
if (!(await answers(port))) throw new Error(`the browser (pid ${pid}) did not answer on 127.0.0.1:${port} in 15 s`)
|
|
224
|
-
detached([process.execPath, import.meta.path, 'watch', String(pid), String(port)].map(quote).join(' '))
|
|
225
|
-
console.log(`up started ${Math.round(performance.now() - t)} port ${port} pid ${pid}${luid ? ` luid ${luid}` : ''}${oldUp ? `, the old one on ${old.port} draining` : ''}`)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** one devtools call on the browser's own socket */
|
|
229
|
-
async function browserCall<T>(port: number, method: string, params: Record<string, unknown> = {}): Promise<T> {
|
|
230
|
-
const { webSocketDebuggerUrl } = (await (await fetch(`http://127.0.0.1:${port}/json/version`)).json()) as { webSocketDebuggerUrl: string }
|
|
231
|
-
return await new Promise<T>((done, fail) => {
|
|
232
|
-
const ws = new WebSocket(webSocketDebuggerUrl)
|
|
233
|
-
const t = setTimeout(() => (ws.close(), fail(new Error(`${method}: no answer in 5 s`))), 5000)
|
|
234
|
-
ws.onopen = () => ws.send(JSON.stringify({ id: 1, method, params }))
|
|
235
|
-
ws.onmessage = (e) => {
|
|
236
|
-
clearTimeout(t)
|
|
237
|
-
ws.close()
|
|
238
|
-
done((JSON.parse(String(e.data)) as { result: T }).result)
|
|
239
|
-
}
|
|
240
|
-
ws.onerror = () => fail(new Error(`${method}: the browser's socket failed`))
|
|
241
|
-
})
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
type Target = { targetId: string; type: string; url: string; attached: boolean }
|
|
245
|
-
|
|
246
|
-
/** the pages a film drives now */
|
|
247
|
-
async function filming(port: number): Promise<number> {
|
|
248
|
-
const { targetInfos } = await browserCall<{ targetInfos: Target[] }>(port, 'Target.getTargets')
|
|
249
|
-
return targetInfos.filter((p) => p.type === 'page' && p.url !== 'about:blank' && p.attached).length
|
|
309
|
+
/** the one browser older versions shared between every film, ended once no film drives a page in it and none asked
|
|
310
|
+
* for it in LEGACY_QUIET_MS (a process still running older code connects between its up and its first page) */
|
|
311
|
+
async function endLegacy(): Promise<void> {
|
|
312
|
+
if (!existsSync(LEGACY_PID)) return
|
|
313
|
+
if (Date.now() - (statSync(LEGACY_USED, { throwIfNoEntry: false })?.mtimeMs ?? 0) < LEGACY_QUIET_MS) return
|
|
314
|
+
const [pid, , port] = readFileSync(LEGACY_PID, 'utf8').trim().split(' ')
|
|
315
|
+
const busy = await pages(Number(port) || CDP_PORT).then(
|
|
316
|
+
(p) => p.some((t) => t.attached),
|
|
317
|
+
() => false,
|
|
318
|
+
)
|
|
319
|
+
if (busy) return
|
|
320
|
+
await end(Number(pid), 'the shared browser of an older film-box version')
|
|
321
|
+
rmSync(LEGACY_PID, { force: true })
|
|
250
322
|
}
|
|
251
323
|
|
|
252
|
-
|
|
253
|
-
* on the GPU); every IDLE_CHECK_MS the idle rule. `drain`: a replaced browser, ended once no film drives a page */
|
|
254
|
-
const SWEEP_MS = 5000
|
|
255
|
-
const IDLE_CHECK_MS = 30_000
|
|
256
|
-
|
|
257
|
-
async function watch(pid: number, port: number, drain: boolean): Promise<void> {
|
|
324
|
+
async function watch(key: string, pid: number, port: number): Promise<void> {
|
|
258
325
|
let orphans = new Set<string>()
|
|
259
|
-
|
|
326
|
+
let deaf = 0
|
|
327
|
+
for (;;) {
|
|
260
328
|
await Bun.sleep(SWEEP_MS)
|
|
261
329
|
if (!alive(pid)) return
|
|
262
|
-
|
|
263
|
-
|
|
330
|
+
// replaced: the slot's next up started another browser
|
|
331
|
+
if (readSlot(key)?.pid !== pid) return void (await end(pid, `${key}: replaced`))
|
|
332
|
+
let shown: Target[]
|
|
264
333
|
try {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
334
|
+
shown = await pages(port)
|
|
335
|
+
deaf = 0
|
|
336
|
+
} catch {
|
|
337
|
+
if (++deaf < DEAF_SWEEPS) continue
|
|
338
|
+
await end(pid, `${key}: its devtools did not answer for ${(DEAF_SWEEPS * SWEEP_MS) / 1000} s`)
|
|
339
|
+
return forget(key, pid)
|
|
340
|
+
}
|
|
341
|
+
const now = new Set(shown.filter((t) => !t.attached).map((t) => t.targetId))
|
|
342
|
+
for (const id of now)
|
|
343
|
+
if (orphans.has(id)) {
|
|
344
|
+
await browserCall(port, 'Target.closeTarget', { targetId: id }).catch(() => undefined)
|
|
345
|
+
log(`${key}: a page no film drives closed`)
|
|
346
|
+
}
|
|
347
|
+
orphans = now
|
|
348
|
+
const idle = Date.now() - (statSync(usedFile(key), { throwIfNoEntry: false })?.mtimeMs ?? 0)
|
|
349
|
+
if (idle > IDLE_MS && shown.length === 0) {
|
|
350
|
+
await end(pid, `${key}: idle`)
|
|
351
|
+
return forget(key, pid)
|
|
280
352
|
}
|
|
281
353
|
}
|
|
282
354
|
}
|
|
283
355
|
|
|
356
|
+
function forget(key: string, pid: number): void {
|
|
357
|
+
if (readSlot(key)?.pid === pid) rmSync(pidFile(key), { force: true })
|
|
358
|
+
}
|
|
359
|
+
|
|
284
360
|
if (import.meta.main) {
|
|
285
|
-
const [cmd,
|
|
286
|
-
if (cmd === 'up' &&
|
|
287
|
-
else if (cmd === 'watch' && Number(
|
|
361
|
+
const [cmd, a, b, c] = process.argv.slice(2)
|
|
362
|
+
if (cmd === 'up' && a && b) await up(a, b)
|
|
363
|
+
else if (cmd === 'watch' && b && Number(b) > 0 && Number(c) > 0) await watch(a!, Number(b), Number(c))
|
|
288
364
|
else {
|
|
289
|
-
console.error('usage: film-box.ts up <playwright version> | watch <browser pid>
|
|
365
|
+
console.error('usage: film-box.ts up <playwright version> <slot key> | watch <slot key> <browser pid> <port>')
|
|
290
366
|
process.exit(2)
|
|
291
367
|
}
|
|
292
368
|
}
|
package/src/shot/shooter.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { loadPlaywright } from '../smoke/run-smoke.ts'
|
|
|
27
27
|
import { CLIP_INIT, CLIP_QUANTIZER, clipDone, installClip, KEY_EVERY, muxArgs, type PageClipAsk, type PageClipDone, TAKE, takeClip } from './clip-encoder.ts'
|
|
28
28
|
import { type ClipPath, clipPathOf, domEncodeArgs, FrameTimeline, largestCanvas, screencastParams } from './dom-clip.ts'
|
|
29
29
|
import { CLOSE_MS, openBrowser, type PwBrowser, slotFor } from './box.ts'
|
|
30
|
+
import type { BrowserLease } from './browser-slot.ts'
|
|
30
31
|
import { capMsOf, type ClipAsk, pageMove, readMark, type ShotAsk, slotKey, stillFormat, Turns, waitReady } from './shot-ask.ts'
|
|
31
32
|
|
|
32
33
|
/** the slice of playwright the shots touch, so the lib types nothing it does not ship */
|
|
@@ -118,7 +119,7 @@ export class Shooter {
|
|
|
118
119
|
#launching: Promise<Browser> | null = null
|
|
119
120
|
#held: (() => void) | null = null
|
|
120
121
|
/** a slot taken in the queue and not yet handed to its browser's open */
|
|
121
|
-
#queued:
|
|
122
|
+
#queued: BrowserLease | null = null
|
|
122
123
|
/** before a page goes to a url: the box route forwards this machine's localhost port to the box */
|
|
123
124
|
#reach: (url: string) => Promise<void> = async () => undefined
|
|
124
125
|
#slot: Slot | null = null
|
|
@@ -177,9 +178,10 @@ export class Shooter {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
#free(): void {
|
|
180
|
-
const held = [this.#held, this.#queued]
|
|
181
|
+
const [held, queued] = [this.#held, this.#queued]
|
|
181
182
|
this.#held = this.#queued = null
|
|
182
|
-
|
|
183
|
+
held?.()
|
|
184
|
+
queued?.release()
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
#touch(): void {
|
package/src/smoke/run-smoke.ts
CHANGED
|
@@ -227,16 +227,18 @@ export function secretArgv(template: string, name: string, field: 'get' | 'accou
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
/** a secret read through the repo's declared command, never argv and never
|
|
230
|
-
* env
|
|
231
|
-
* password. */
|
|
232
|
-
export function readSecret(template: string, name: string, field: 'get' | 'account' = 'get'): string {
|
|
230
|
+
* env, as the repo at `cwd` (a scoped name is refused out of its scope). The
|
|
231
|
+
* ACCOUNT field of a secret carries the identity, the value the password. */
|
|
232
|
+
export function readSecret(template: string, name: string, field: 'get' | 'account' = 'get', cwd?: string): string {
|
|
233
233
|
const argv = secretArgv(template, name, field)
|
|
234
234
|
const bin = argv[0] ?? ''
|
|
235
235
|
if (bin === '' || Bun.which(bin) == null) throw new Error(`FAIL credsReadCommand names '${bin}', which is not on PATH`)
|
|
236
|
-
const r = Bun.spawnSync(argv)
|
|
236
|
+
const r = Bun.spawnSync(argv, { ...(cwd != null ? { cwd } : {}), stderr: 'pipe' })
|
|
237
237
|
const v = r.stdout.toString().trim()
|
|
238
|
-
if (r.exitCode
|
|
239
|
-
|
|
238
|
+
if (r.exitCode === 0 && v !== '') return v
|
|
239
|
+
// a refusal is no missing secret: storing it again would not help
|
|
240
|
+
const why = r.stderr.toString().trim().split('\n').at(-1) ?? ''
|
|
241
|
+
throw new Error(why.startsWith('REFUSED') ? `FAIL ${why}` : `FAIL \`${argv.join(' ')}\` answered nothing — store the secret under that name first${why !== '' ? ` (${why})` : ''}`)
|
|
240
242
|
}
|
|
241
243
|
|
|
242
244
|
/** the smallest slice of playwright this module touches, so the package
|
package/src/social/compose.ts
CHANGED
|
@@ -39,6 +39,19 @@ export const TAG = /^#[\p{L}\p{N}_]+$/u
|
|
|
39
39
|
const SATURDAY = '#ScreenshotSaturday'
|
|
40
40
|
/** what each platform takes of a message's tags (wiki tools/shipkit/social.md, The tags); an account with no rule takes none */
|
|
41
41
|
const TAGS: Readonly<Record<string, 'all' | 'one' | 'vertical'>> = { x: 'all', bluesky: 'all', mastodon: 'all', threads: 'one', tiktok: 'vertical', instagram: 'vertical', youtube: 'vertical' }
|
|
42
|
+
/** platforms whose markdown starts a list only after a blank line: a list glued to the line above reads as text */
|
|
43
|
+
const LIST_AFTER_BLANK = new Set(['subscribestar'])
|
|
44
|
+
const LIST_ITEM = /^\s*(?:[-*+]|\d+\.)\s/
|
|
45
|
+
|
|
46
|
+
function blankBeforeLists(text: string): string {
|
|
47
|
+
const out: string[] = []
|
|
48
|
+
for (const line of text.split('\n')) {
|
|
49
|
+
const prev = out.at(-1)
|
|
50
|
+
if (LIST_ITEM.test(line) && prev !== undefined && prev.trim() !== '' && !LIST_ITEM.test(prev)) out.push('')
|
|
51
|
+
out.push(line)
|
|
52
|
+
}
|
|
53
|
+
return out.join('\n')
|
|
54
|
+
}
|
|
42
55
|
|
|
43
56
|
/** a message as one platform posts it: its text with the tags that platform takes (within its `max`), the footer of a
|
|
44
57
|
* vertical; X's links go to `reply`, the first reply under the post */
|
|
@@ -48,6 +61,7 @@ export function compose(
|
|
|
48
61
|
o: { max: number | null; saturday: boolean },
|
|
49
62
|
): { text: string; reply: string } {
|
|
50
63
|
let text = m.text.trim()
|
|
64
|
+
if (LIST_AFTER_BLANK.has(platform)) text = blankBeforeLists(text)
|
|
51
65
|
let reply = ''
|
|
52
66
|
if (platform === 'x') {
|
|
53
67
|
const links = text.match(URL_RE) ?? []
|
package/src/social/drafts.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { parseFrontmatter } from './md.ts'
|
|
|
8
8
|
|
|
9
9
|
/** the headings a draft holds besides its platforms */
|
|
10
10
|
const OWN = ['Angle', 'Posted'] as const
|
|
11
|
-
const OPTIONS = ['name', 'place', 'title', 'media', 'rating', 'pin', 'outro', 'mark', 'tags'] as const
|
|
11
|
+
const OPTIONS = ['name', 'place', 'title', 'media', 'rating', 'pin', 'outro', 'mark', 'tags', 'tier'] as const
|
|
12
12
|
type Option = (typeof OPTIONS)[number]
|
|
13
13
|
/** the options whose value is one of a few words: a vertical's end and its watermark's corner, words a project reads */
|
|
14
14
|
const WORDS: Partial<Record<Option, readonly string[]>> = { outro: ['montage', 'short', 'none'], mark: ['left', 'right'] }
|
package/src/social/load.ts
CHANGED
|
@@ -97,6 +97,10 @@ export type SocialPost = {
|
|
|
97
97
|
/** the heading's own text, as he writes it; `text` is it composed for the account */
|
|
98
98
|
body: string
|
|
99
99
|
tags: string[]
|
|
100
|
+
/** the tier it is posted at, its heading's `tier` else its account's open tier; empty on an account with no tiers */
|
|
101
|
+
tier: string
|
|
102
|
+
/** the heading names its tier; false, `tier` is the account's suggestion */
|
|
103
|
+
tierSet: boolean
|
|
100
104
|
/** X's links, out of its text: the first reply under the post; empty elsewhere */
|
|
101
105
|
reply: string
|
|
102
106
|
/** its write page takes the text (`{text}`); else « Open » copies it first */
|
|
@@ -175,10 +179,18 @@ const FORMATS = ['short', VERTICAL] as const
|
|
|
175
179
|
/** the name of a compiled vertical video */
|
|
176
180
|
export const VERTICAL_FILE = /-vertical\.mp4$/
|
|
177
181
|
|
|
178
|
-
/** what one message breaks on its account: a text past the account's max,
|
|
179
|
-
|
|
182
|
+
/** what one message breaks on its account: a text past the account's max, more tags than its `max tags`, a tier its
|
|
183
|
+
* account has not, a `## vertical` message without its video */
|
|
184
|
+
export function messageErrors(
|
|
185
|
+
post: Pick<SocialPost, 'file' | 'from' | 'length' | 'media' | 'tags' | 'tier'>,
|
|
186
|
+
a: Pick<Account, 'name' | 'max' | 'maxTags' | 'tiers'>,
|
|
187
|
+
): string[] {
|
|
180
188
|
const out: string[] = []
|
|
181
189
|
if (a.max !== null && post.length > a.max) out.push(`${post.file}: ## ${post.from} is ${post.length} on ${a.name}, over its ${a.max}`)
|
|
190
|
+
if (a.maxTags !== null && post.tags.length > a.maxTags)
|
|
191
|
+
out.push(`${post.file}: ## ${post.from} has ${post.tags.length} tags on ${a.name}, over its ${a.maxTags}`)
|
|
192
|
+
if (post.tier !== '' && !a.tiers.includes(post.tier))
|
|
193
|
+
out.push(`${post.file}: ## ${post.from} tier "${post.tier}" is none of ${a.name}'s: ${a.tiers.join(', ') || 'it has no tiers'}`)
|
|
182
194
|
if (post.from.split('/')[0] === VERTICAL && !VERTICAL_FILE.test(post.media?.name ?? ''))
|
|
183
195
|
out.push(`${post.file}: ## ${post.from} goes to ${a.name} without its vertical video (media: media/<name>-vertical.mp4)`)
|
|
184
196
|
return out
|
|
@@ -367,6 +379,8 @@ export function loadDesk(root: string, ids: Identities, o: { speaksAs?: string |
|
|
|
367
379
|
text: made.text,
|
|
368
380
|
body: s.text,
|
|
369
381
|
tags,
|
|
382
|
+
tier: s.options.tier ?? a.tiers[0] ?? '',
|
|
383
|
+
tierSet: s.options.tier !== undefined,
|
|
370
384
|
reply: made.reply,
|
|
371
385
|
length: messageLength(a.id, made.text),
|
|
372
386
|
media: (s.options.media == null ? ownMedia : pick(s.options.media))[0] ?? null,
|
|
@@ -5,6 +5,7 @@ import { accountOf, draftPost, type Desk } from '../load.ts'
|
|
|
5
5
|
import { setPosted } from '../writes.ts'
|
|
6
6
|
import { postBluesky } from './bluesky.ts'
|
|
7
7
|
import { postDiscord } from './discord.ts'
|
|
8
|
+
import { secretsAs } from './secret.ts'
|
|
8
9
|
import type { Account } from '../../identities/identities.ts'
|
|
9
10
|
import type { SocialPost } from '../load.ts'
|
|
10
11
|
|
|
@@ -35,7 +36,8 @@ export async function publish(desk: Desk, slug: string, key: string, publishers:
|
|
|
35
36
|
if (run == null) throw new Error(`${post.platform}: nothing posts there by itself`)
|
|
36
37
|
if (a.automation !== 'live') throw new Error(`${a.file}: its automation is not live`)
|
|
37
38
|
if (post.posted !== '' && !EDITS_IN_PLACE.has(post.platform)) throw new Error(`${slug} is already posted on ${a.name}: ${post.posted}`)
|
|
38
|
-
|
|
39
|
+
// the hub runs in the house's folder: the token is read as the draft's repo
|
|
40
|
+
const url = await secretsAs(desk.root, () => run(a, post))
|
|
39
41
|
return { url, files: url === post.posted ? [] : setPosted(desk, slug, key, url) }
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
// an account's token, read through the house config's `credsReadCommand`: a missing one fails loud with where it is named
|
|
1
|
+
// an account's token, read through the house config's `credsReadCommand`: a missing one fails loud with where it is named.
|
|
2
|
+
// It reads as the repo that posts: the hub runs in the house's folder, so `secretsAs` names the draft's repo
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
4
|
import { readSecret } from '../../smoke/run-smoke.ts'
|
|
3
5
|
|
|
6
|
+
const postingRepo = new AsyncLocalStorage<string>()
|
|
7
|
+
|
|
8
|
+
/** `run`, its token reads made as the repo at `root` */
|
|
9
|
+
export const secretsAs = <T>(root: string, run: () => Promise<T>): Promise<T> => postingRepo.run(root, run)
|
|
10
|
+
|
|
4
11
|
export async function secret(name: string, where: string): Promise<string> {
|
|
5
12
|
if (name === '') throw new Error(`no token named: ${where} names no secret`)
|
|
13
|
+
const cwd = postingRepo.getStore() ?? process.cwd()
|
|
6
14
|
const { houseRootOf } = await import('../../home/home-start.ts')
|
|
7
15
|
const { loadRepoConfig } = await import('../../repo-config.ts')
|
|
8
|
-
const house = houseRootOf(
|
|
9
|
-
if (!house) throw new Error(`no house repo seen from ${
|
|
16
|
+
const house = houseRootOf(cwd)
|
|
17
|
+
if (!house) throw new Error(`no house repo seen from ${cwd} to read the token ${name} (${where})`)
|
|
10
18
|
const c = await loadRepoConfig(house)
|
|
11
19
|
if (!c.credsReadCommand) throw new Error(`the house config (${house}) declares no credsReadCommand to read ${name} (${where})`)
|
|
12
|
-
return readSecret(c.credsReadCommand, name)
|
|
20
|
+
return readSecret(c.credsReadCommand, name, 'get', cwd)
|
|
13
21
|
}
|