rvlib-shipkit 2.19.0 → 2.21.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 +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +11 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +337 -5
- package/src/home/gui-app.ts +64 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm-switch.ts +112 -0
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +121 -14
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +182 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +102 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +93 -0
- package/src/social/load.ts +125 -10
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// a trailer card's notes in the order of the cut (wiki tools/shipkit/review.md, A trailer): the card's own rectangles,
|
|
2
|
+
// sent with its verdicts or still in the draft, as the lane, the rail, the frame and the verdict's rows show them.
|
|
3
|
+
// Pure: the hub and its tests share it
|
|
4
|
+
import { onFrame, type Rect, type Side } from './model.ts'
|
|
5
|
+
|
|
6
|
+
export interface LaneNote {
|
|
7
|
+
/** `s:<verdict>:<k>` for a sent rectangle, `d:<i>` for the draft's i-th */
|
|
8
|
+
key: string
|
|
9
|
+
/** its number in the order of the cut, over every note of the version */
|
|
10
|
+
n: number
|
|
11
|
+
/** seconds on the render it was drawn on */
|
|
12
|
+
t: number
|
|
13
|
+
side?: Side
|
|
14
|
+
shot?: { name: string; time: number }
|
|
15
|
+
rect: Rect
|
|
16
|
+
/** its index in the draft, null once sent */
|
|
17
|
+
draft: number | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** every rectangle on a trailer card's frame, sent or drafted, in the order of the cut (its time, then before ahead of
|
|
21
|
+
* after); a rectangle with no time is no trailer note */
|
|
22
|
+
export function laneNotes(sent: readonly { id: string; rects: readonly Rect[] }[], draft: readonly Rect[]): LaneNote[] {
|
|
23
|
+
const all = [
|
|
24
|
+
...sent.flatMap((v) => v.rects.flatMap((r, k) => ((r.view ?? 0) === 0 && r.t !== undefined ? [{ key: `s:${v.id}:${k}`, rect: r, t: r.t, draft: null }] : []))),
|
|
25
|
+
...draft.flatMap((r, i) => ((r.view ?? 0) === 0 && r.t !== undefined ? [{ key: `d:${i}`, rect: r, t: r.t, draft: i }] : [])),
|
|
26
|
+
]
|
|
27
|
+
const sideRank = (r: Rect): number => (r.side === 'before' ? 0 : 1)
|
|
28
|
+
return all
|
|
29
|
+
.sort((a, b) => a.t - b.t || sideRank(a.rect) - sideRank(b.rect))
|
|
30
|
+
.map((x, i) => ({ ...x, n: i + 1, ...(x.rect.side ? { side: x.rect.side } : {}), ...(x.rect.shot ? { shot: x.rect.shot } : {}) }))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** a playing note lights this long either side of its time */
|
|
34
|
+
export const LIT_S = 0.5
|
|
35
|
+
|
|
36
|
+
/** the notes the frame shows now: on the render on screen, on this very frame while paused, within LIT_S while it plays */
|
|
37
|
+
export function notesNow(notes: readonly LaneNote[], at: { time: number; fps: number; paused: boolean; side: Side | undefined }): LaneNote[] {
|
|
38
|
+
return notes.filter((n) => n.side === at.side && (at.paused ? onFrame(n.t, at.time, at.fps) : Math.abs(n.t - at.time) <= LIT_S))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** a draft in the order of the cut once a rectangle joins it: where that rectangle went */
|
|
42
|
+
export function sortedDraft(rects: readonly Rect[], added: Rect): { rects: Rect[]; at: number } {
|
|
43
|
+
const out = [...rects, added].sort((a, b) => (a.t ?? 0) - (b.t ?? 0))
|
|
44
|
+
return { rects: out, at: out.indexOf(added) }
|
|
45
|
+
}
|
|
@@ -7,15 +7,14 @@ import { join, relative } from 'node:path'
|
|
|
7
7
|
import { bad, NO_STORE, ranged } from './http.ts'
|
|
8
8
|
import { ID_RE, isFrame } from './model.ts'
|
|
9
9
|
import { act, appendMessage, deleteRaised, raiseItem, readAllCached, readItem } from './store.ts'
|
|
10
|
-
import { cutOf, frameNote, montagePage, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
|
|
11
|
-
import { CUT_RE, noteOf, TRAILER_ID_RE, type
|
|
10
|
+
import { cutOf, frameNote, frameStill, montagePage, pinnedRender, readView, trailerDir, trailerIds, trailerInfo, videoOf, viewMedia } from './trailer-desk.ts'
|
|
11
|
+
import { CUT_RE, noteMarkOf, noteOf, TRAILER_ID_RE, type NoteMark, type NoteState, type TrailerDesk } from './trailer-model.ts'
|
|
12
|
+
import { madeFile, voicesDesk, voicesWaiting } from './trailer-voices.ts'
|
|
13
|
+
import { dropTake, setTakeEdit, writeTake, type TakeExt } from '../trailer/sound/takes.ts'
|
|
14
|
+
import type { Take } from '../trailer/sound/presets.ts'
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const pinOf = (v: unknown): NotePin | undefined => {
|
|
16
|
-
const p = v as { x?: unknown; y?: unknown } | null | undefined
|
|
17
|
-
return p && typeof p.x === 'number' && typeof p.y === 'number' ? { x: p.x, y: p.y } : undefined
|
|
18
|
-
}
|
|
16
|
+
/** a note's mark as its message stores it: a review card's Rect */
|
|
17
|
+
const rectsOf = (m: NoteMark) => [{ ...m, comment: '' }]
|
|
19
18
|
|
|
20
19
|
const STATES: readonly NoteState[] = ['open', 'done', 'wontfix']
|
|
21
20
|
|
|
@@ -42,10 +41,104 @@ function noteAfter(dir: string, nid: string): Response {
|
|
|
42
41
|
return note ? Response.json(note, { headers: NO_STORE }) : bad(`no note ${nid}`, 404)
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
const TAKE_TYPES: Record<string, TakeExt> = { 'audio/webm': 'webm', 'audio/ogg': 'ogg', 'audio/mp4': 'm4a', 'audio/x-m4a': 'm4a', 'audio/wav': 'wav', 'audio/x-wav': 'wav', 'audio/mpeg': 'mp3', 'audio/flac': 'flac' }
|
|
45
|
+
const AUDIO_TYPE: Record<string, string> = { webm: 'audio/webm', ogg: 'audio/ogg', m4a: 'audio/mp4', mp4: 'audio/mp4', wav: 'audio/wav', mp3: 'audio/mpeg', flac: 'audio/flac' }
|
|
46
|
+
|
|
47
|
+
/** his take made as the cut will play it, the build's own run: its waveform and its sound on the page are the cut's */
|
|
48
|
+
async function makeTake(root: string, voice: string, text: string, take: Take): Promise<void> {
|
|
49
|
+
const [{ takeRun }, { soundRun }, { brandSound }, { voiceTweak }] = await Promise.all([import('../trailer/sound/presets.ts'), import('../trailer/sound/run.ts'), import('../trailer/sound/index.ts'), import('../trailer/sound/brand.ts')])
|
|
50
|
+
await soundRun(takeRun(text, take, voiceTweak(await brandSound(root), voice)), { root, dir: root }, () => undefined)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** the Voices routes: the lines of a trailer, the sound a cut plays now, his take of a text (kept, played, edited,
|
|
54
|
+
* dropped) */
|
|
55
|
+
async function voiceRoutes(req: Request, path: string, root: string): Promise<Response | null> {
|
|
56
|
+
if (path === '/api/trailer/voices' && req.method === 'GET') return Response.json(await voicesWaiting(root), { headers: NO_STORE })
|
|
57
|
+
const made = /^\/api\/trailer\/voices\/made\/([0-9a-f]{16})\.wav$/.exec(path)
|
|
58
|
+
if (made && req.method === 'GET') {
|
|
59
|
+
const f = madeFile(root, made[1] ?? '')
|
|
60
|
+
return f ? ranged(req, f) : bad('that line is not made: sk trailer makes it', 404)
|
|
61
|
+
}
|
|
62
|
+
const passage = /^\/api\/trailer\/voices\/passage\/([^/]+)\/([0-9a-f]{12})\/([^/]+)\/(\d+)\/(ref|take|none)\.mp4$/.exec(path)
|
|
63
|
+
if (passage && req.method === 'GET') {
|
|
64
|
+
// one line's passage, picture and bed and one version of the line, as one file (trailer/bed.ts voicePassage)
|
|
65
|
+
const [, id = '', key = '', cut = '', lineNo = '', hear = 'none'] = passage
|
|
66
|
+
const tdir = trailerDir(root, id)
|
|
67
|
+
const c = tdir ? cutOf(tdir, cut) : null
|
|
68
|
+
const line = (await voicesDesk(root, id))?.lines.find((l) => l.key === key)
|
|
69
|
+
const use = line?.uses.find((u) => u.cut === cut && u.line === Number(lineNo))
|
|
70
|
+
if (!tdir || !c?.trailer || !line || !use?.video) return bad(`no rendered use of line ${key} in ${id}/${cut}:${lineNo}`, 404)
|
|
71
|
+
const media = await viewMedia(root, id, cut, use.video.mtime, 'video')
|
|
72
|
+
if (!media || !('path' in media)) return bad(`the render of ${cut} is not on this disk`, 404)
|
|
73
|
+
const ref = madeFile(root, (use.standin ? use.standin.made : use.made) ?? '')
|
|
74
|
+
const take = madeFile(root, line.take?.made ?? '')
|
|
75
|
+
const voice = hear === 'ref' ? ref : hear === 'take' ? take : null
|
|
76
|
+
if (hear !== 'none' && !voice) return bad(`no ${hear === 'ref' ? 'reference' : 'take'} of this line is made yet`, 404)
|
|
77
|
+
const [{ voiceBed, voicePassage }, { durationOf }] = await Promise.all([import('../trailer/bed.ts'), import('../trailer/ffmpeg.ts')])
|
|
78
|
+
const seconds = Math.max(0, ...(await Promise.all([ref, take].flatMap((f) => (f ? [durationOf(f)] : [])))))
|
|
79
|
+
const p = await voicePassage(root, { video: media.path, videoMtime: use.video.mtime, bed: await voiceBed(root, c.trailer), at: use.at, seconds, total: await durationOf(media.path), voice, volume: use.volume })
|
|
80
|
+
return ranged(req, p.file)
|
|
81
|
+
}
|
|
82
|
+
const voicedMp4 = /^\/api\/trailer\/voiced\/([0-9a-f]{16})\.mp4$/.exec(path)
|
|
83
|
+
if (voicedMp4 && req.method === 'GET') {
|
|
84
|
+
const { voicedFile } = await import('../trailer/bed.ts')
|
|
85
|
+
const f = voicedFile(root, voicedMp4[1] ?? '')
|
|
86
|
+
return f ? ranged(req, f) : bad('that voice of the cut is not made: the player asks for it first', 404)
|
|
87
|
+
}
|
|
88
|
+
const voiced = /^\/api\/trailer\/voiced\/([^/]+)\/([^/]+)\/(\d+)\/(takes|standin)$/.exec(path)
|
|
89
|
+
if (voiced && req.method === 'GET') {
|
|
90
|
+
// the whole cut in his voice or its standin's, its picture the render on screen (trailer/bed.ts voicedCut)
|
|
91
|
+
const [, id = '', cut = '', version = '', side = ''] = voiced
|
|
92
|
+
const tdir = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? trailerDir(root, id) : null
|
|
93
|
+
const c = tdir ? cutOf(tdir, cut) : null
|
|
94
|
+
if (!c?.trailer || c.version) return bad(`${id}/${cut} is no working cut: only a working cut plays in either voice`, 404)
|
|
95
|
+
const media = await viewMedia(root, id, cut, Number(version), 'video')
|
|
96
|
+
if (!media || !('path' in media)) return bad(`the render of ${cut} at ${version} is not on this disk`, 404)
|
|
97
|
+
const { voicedCut } = await import('../trailer/bed.ts')
|
|
98
|
+
const v = await voicedCut(root, c.trailer, media.path, side === 'takes', readView(root, id, cut, Number(version))?.timeline ?? null)
|
|
99
|
+
return Response.json({ key: v.key }, { headers: NO_STORE })
|
|
100
|
+
}
|
|
101
|
+
const desk = /^\/api\/trailer\/voices\/([^/]+)$/.exec(path)
|
|
102
|
+
if (desk && req.method === 'GET') {
|
|
103
|
+
const d = await voicesDesk(root, desk[1] ?? '')
|
|
104
|
+
return d ? Response.json(d, { headers: NO_STORE }) : bad(`no trailer ${desk[1]}`, 404)
|
|
105
|
+
}
|
|
106
|
+
const take = /^\/api\/trailer\/voices\/([^/]+)\/take\/([0-9a-f]{12})(\/edit)?$/.exec(path)
|
|
107
|
+
if (!take) return null
|
|
108
|
+
const [, id = '', key = '', edit] = take
|
|
109
|
+
const d = await voicesDesk(root, id)
|
|
110
|
+
const line = d?.lines.find((l) => l.key === key)
|
|
111
|
+
if (!d || !line) return bad(`no line ${key} in trailer ${id}`, 404)
|
|
112
|
+
if (req.method === 'GET') {
|
|
113
|
+
if (!line.take) return bad('no take of that line yet', 404)
|
|
114
|
+
const ext = line.take.file.split('.').pop() ?? ''
|
|
115
|
+
return new Response(Bun.file(join(root, line.take.file)), { headers: { 'Content-Type': AUDIO_TYPE[ext] ?? 'application/octet-stream', ...NO_STORE } })
|
|
116
|
+
}
|
|
117
|
+
if (!line.voice) return bad("the brand has no voice of yours: add one to trailer.voices in .shipkit/identity/brand.ts, { record: '<your name>' }")
|
|
118
|
+
if (req.method === 'PUT') {
|
|
119
|
+
const type = (req.headers.get('content-type') ?? '').split(';')[0]?.trim() ?? ''
|
|
120
|
+
const ext = TAKE_TYPES[type]
|
|
121
|
+
if (!ext) return bad(`a take is audio (${Object.keys(TAKE_TYPES).join(', ')}), got ${type || 'no type'}`)
|
|
122
|
+
const file = writeTake(root, line.voice, line.text, new Uint8Array(await req.arrayBuffer()), ext)
|
|
123
|
+
await makeTake(root, line.voice, line.text, { path: relative(root, file), offset: null, mask: [] })
|
|
124
|
+
return Response.json({ ok: true, file: relative(root, file) }, { headers: NO_STORE })
|
|
125
|
+
}
|
|
126
|
+
if (req.method === 'POST' && edit) {
|
|
127
|
+
// his drag and his mask, kept beside the take, the line made again at once
|
|
128
|
+
const e = setTakeEdit(root, line.voice, line.text, await req.json())
|
|
129
|
+
await makeTake(root, line.voice, line.text, { path: line.take?.file ?? '', ...e })
|
|
130
|
+
return Response.json({ ok: true, ...e }, { headers: NO_STORE })
|
|
131
|
+
}
|
|
132
|
+
if (req.method === 'DELETE') return Response.json({ ok: dropTake(root, line.voice, line.text) }, { headers: NO_STORE })
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
|
|
45
136
|
export async function trailerRoutes(req: Request, path: string, root: string, dir: string): Promise<Response | null> {
|
|
46
137
|
const API = '/api/trailer'
|
|
47
138
|
if (path !== API && !path.startsWith(`${API}/`)) return null
|
|
48
139
|
try {
|
|
140
|
+
const voices = await voiceRoutes(req, path, root)
|
|
141
|
+
if (voices) return voices
|
|
49
142
|
if (path === API && req.method === 'GET') {
|
|
50
143
|
const desk: TrailerDesk = { trailers: trailerIds(root).flatMap((id) => trailerInfo(root, id) ?? []) }
|
|
51
144
|
return Response.json(desk, { headers: NO_STORE })
|
|
@@ -59,6 +152,19 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
|
|
|
59
152
|
// a render the disk let go plays from the Space: the signed URL lives an hour, the browser keeps half of it
|
|
60
153
|
return 'path' in at ? ranged(req, at.path) : new Response(null, { status: 302, headers: { Location: at.url, 'Cache-Control': 'private, max-age=1800' } })
|
|
61
154
|
}
|
|
155
|
+
const pinned = /^\/api\/trailer\/render\/([^/]+)\/([^/]+)\/(\d+)$/.exec(path)
|
|
156
|
+
if (pinned && req.method === 'GET') {
|
|
157
|
+
const [, id = '', cut = '', version = ''] = pinned
|
|
158
|
+
const r = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? pinnedRender(root, id, cut, Number(version)) : null
|
|
159
|
+
return r ? Response.json(r, { headers: NO_STORE }) : bad(`no render ${id}/${cut} at ${version}: neither the disk nor the media store holds it`, 404)
|
|
160
|
+
}
|
|
161
|
+
const still = /^\/api\/trailer\/still\/([^/]+)\/([^/]+)\/(\d+)\/(\d+)\.jpg$/.exec(path)
|
|
162
|
+
if (still && req.method === 'GET') {
|
|
163
|
+
// one frame of a render, small, cut once and kept: a note's row in the rail and the verdict
|
|
164
|
+
const [, id = '', cut = '', version = '', frame = ''] = still
|
|
165
|
+
const f = TRAILER_ID_RE.test(id) && CUT_RE.test(cut) ? await frameStill(root, id, cut, Number(version), Number(frame)) : null
|
|
166
|
+
return f ? new Response(Bun.file(f), { headers: { 'Content-Type': 'image/jpeg', 'Cache-Control': 'private, max-age=86400' } }) : bad(`no frame ${frame} of ${id}/${cut} at ${version}`, 404)
|
|
167
|
+
}
|
|
62
168
|
const mont = /^\/api\/trailer\/montage\/([^/]+)\/([^/]+)$/.exec(path)
|
|
63
169
|
if (mont && req.method === 'GET') {
|
|
64
170
|
const page = montagePage(root, mont[1] ?? '', mont[2] ?? '')
|
|
@@ -83,7 +189,7 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
|
|
|
83
189
|
if (!trailerDir(root, id)) return bad(`no trailer ${id}`)
|
|
84
190
|
const text = String(b.text ?? '')
|
|
85
191
|
if (text.trim() === '') return bad('a note says something')
|
|
86
|
-
const
|
|
192
|
+
const mark = noteMarkOf(b.mark)
|
|
87
193
|
const tmp = mkdtempSync(join(tmpdir(), 'trailer-note-'))
|
|
88
194
|
try {
|
|
89
195
|
const still = join(tmp, 'still.png')
|
|
@@ -95,7 +201,7 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
|
|
|
95
201
|
topic: 'film',
|
|
96
202
|
title: titleOf(text),
|
|
97
203
|
text,
|
|
98
|
-
...(
|
|
204
|
+
...(mark ? { rects: rectsOf(mark) } : {}),
|
|
99
205
|
image: still,
|
|
100
206
|
...(commit ? { commit } : {}),
|
|
101
207
|
})
|
|
@@ -118,12 +224,12 @@ export async function trailerRoutes(req: Request, path: string, root: string, di
|
|
|
118
224
|
if (typeof b.state === 'string' && !STATES.includes(b.state as NoteState)) return bad(`state ${b.state}?`)
|
|
119
225
|
const text = typeof b.text === 'string' ? b.text.trim() : undefined
|
|
120
226
|
if (text === '') return bad('a note says something')
|
|
121
|
-
const
|
|
122
|
-
if (text !== undefined ||
|
|
227
|
+
const mark = b.mark === null ? null : noteMarkOf(b.mark)
|
|
228
|
+
if (text !== undefined || mark !== undefined)
|
|
123
229
|
appendMessage(dir, nid, {
|
|
124
230
|
who: 'owner',
|
|
125
231
|
...(text !== undefined ? { text } : {}),
|
|
126
|
-
...(
|
|
232
|
+
...(mark !== undefined ? { rects: mark ? rectsOf(mark) : [] } : {}),
|
|
127
233
|
})
|
|
128
234
|
const reply = typeof b.reply === 'string' ? b.reply : undefined
|
|
129
235
|
if (b.state === 'open') act(dir, nid, 'reopen', 'owner')
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// the trailer page's Voices (wiki tools/trailer/trailer-sound.md, Your own voice): every `voice "<line>"` of a trailer's
|
|
2
|
+
// working cuts, one row a text, with the sound the cut plays now, his take, and where it sits in each cut. A line of a
|
|
3
|
+
// recorded voice he has not read yet is waiting: the count on the page, its trailer and the hub's trailer row
|
|
4
|
+
import { existsSync, statSync } from 'node:fs'
|
|
5
|
+
import { join, relative } from 'node:path'
|
|
6
|
+
import { recordVoices, type TrailerSoundInput, voiceTweak } from '../trailer/sound/brand.ts'
|
|
7
|
+
import { recordedLine, standinPreset, takeRun } from '../trailer/sound/presets.ts'
|
|
8
|
+
import { brandSound, repoTakes, runOf } from '../trailer/sound/index.ts'
|
|
9
|
+
import { runSpec, soundCache, soundRun } from '../trailer/sound/run.ts'
|
|
10
|
+
import { takeKey, takeOf, takeWords } from '../trailer/sound/takes.ts'
|
|
11
|
+
import { cutInfo, cutsOf, parseCut, timelineOf, trailerDir, trailerIds } from './trailer-desk.ts'
|
|
12
|
+
import type { VoiceLine, VoicesDesk, VoiceUse } from './trailer-model.ts'
|
|
13
|
+
|
|
14
|
+
/** a line's sound as the cut plays it now, or as its standin reads it: its cache key when it is made */
|
|
15
|
+
function madeKey(root: string, dir: string, text: string, by: string | undefined, seed: number | undefined, line: number, brand: TrailerSoundInput | undefined, standin = false): string | null {
|
|
16
|
+
try {
|
|
17
|
+
const req = { kind: 'voice' as const, text, ...(by ? { by } : {}), ...(seed !== undefined ? { seed } : {}), line, dir }
|
|
18
|
+
const run = standin ? standinPreset(req, brand) : runOf(root, req, brand)
|
|
19
|
+
if (!run) return null
|
|
20
|
+
const spec = runSpec(run, { root, dir })
|
|
21
|
+
return existsSync(spec.file) ? spec.key : null
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** the voices of one trailer folder; null when it is none */
|
|
28
|
+
export async function voicesDesk(root: string, id: string, brand?: TrailerSoundInput): Promise<VoicesDesk | null> {
|
|
29
|
+
const dir = trailerDir(root, id)
|
|
30
|
+
if (!dir) return null
|
|
31
|
+
const b = brand ?? (await brandSound(root).catch(() => undefined))
|
|
32
|
+
const recorders = recordVoices(b)
|
|
33
|
+
const errors: string[] = []
|
|
34
|
+
const byKey = new Map<string, VoiceLine>()
|
|
35
|
+
for (const c of cutsOf(dir)) {
|
|
36
|
+
if (c.version || !c.trailer) continue
|
|
37
|
+
let parsed
|
|
38
|
+
try {
|
|
39
|
+
parsed = parseCut(c.trailer).trailer
|
|
40
|
+
} catch (e) {
|
|
41
|
+
errors.push(`${c.cut}.trailer: ${(e as Error).message}`)
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
const info = cutInfo(root, dir, id, c)
|
|
45
|
+
const own = timelineOf(parsed)
|
|
46
|
+
const tl = info.timeline ?? own
|
|
47
|
+
const spanOf = (name: string) => tl.shots.find((x) => x.name === name) ?? own.shots.find((x) => x.name === name)
|
|
48
|
+
// every line's start on the cut: a line has the room until the next one starts, or the cut ends
|
|
49
|
+
const starts = parsed.shots.flatMap((s) => (s.offcut ? [] : s.voices.map((v) => (spanOf(s.name)?.start ?? 0) + v.at))).sort((a, z) => a - z)
|
|
50
|
+
for (const s of parsed.shots) {
|
|
51
|
+
if (s.offcut) continue
|
|
52
|
+
const span = spanOf(s.name)
|
|
53
|
+
if (!span) continue
|
|
54
|
+
for (const v of s.voices) {
|
|
55
|
+
if (v.text === undefined || v.run) continue
|
|
56
|
+
const by = v.gen?.by
|
|
57
|
+
let rec = null
|
|
58
|
+
let reader: string
|
|
59
|
+
try {
|
|
60
|
+
rec = recordedLine({ text: v.text, ...(by ? { by } : {}) }, b, repoTakes(root))
|
|
61
|
+
const standin = rec?.standin.name ?? "the brand's voice"
|
|
62
|
+
reader = !rec ? (by ?? "the brand's voice") : rec.take ? rec.who : rec.kept ? `${standin}: takes off, ${rec.who}'s take kept` : `${standin}, standing in for ${rec.who}`
|
|
63
|
+
} catch (e) {
|
|
64
|
+
errors.push(`${c.cut}.trailer:${v.line}: ${(e as Error).message}`)
|
|
65
|
+
continue
|
|
66
|
+
}
|
|
67
|
+
const key = takeKey(v.text)
|
|
68
|
+
const use: VoiceUse = {
|
|
69
|
+
cut: c.cut,
|
|
70
|
+
line: v.line,
|
|
71
|
+
file: relative(root, c.trailer),
|
|
72
|
+
shot: s.name,
|
|
73
|
+
shotStart: span.start,
|
|
74
|
+
shotEnd: span.end,
|
|
75
|
+
at: span.start + v.at,
|
|
76
|
+
room: (starts.find((x) => x > span.start + v.at + 1e-6) ?? tl.total) - (span.start + v.at),
|
|
77
|
+
volume: v.volume,
|
|
78
|
+
by: by ?? null,
|
|
79
|
+
mine: rec !== null,
|
|
80
|
+
reader,
|
|
81
|
+
made: madeKey(root, c.trailer.replace(/\/[^/]+$/, ''), v.text, by, v.gen?.seed, v.line, b),
|
|
82
|
+
standin: rec ? { name: rec.standin.name ?? "the brand's voice", made: madeKey(root, c.trailer.replace(/\/[^/]+$/, ''), v.text, by, v.gen?.seed, v.line, b, true) } : null,
|
|
83
|
+
video: info.video ? { mtime: info.video.mtime } : null,
|
|
84
|
+
}
|
|
85
|
+
const row = byKey.get(key)
|
|
86
|
+
if (row) {
|
|
87
|
+
row.uses.push(use)
|
|
88
|
+
if (rec && !row.mine) row.voice = rec.voice
|
|
89
|
+
row.mine ||= use.mine
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
byKey.set(key, { key, text: v.text, words: takeWords(v.text), voice: rec?.voice ?? recorders[0]?.name ?? null, mine: use.mine, take: null, uses: [use] })
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const lines = [...byKey.values()]
|
|
97
|
+
for (const l of lines) {
|
|
98
|
+
const t = l.voice ? takeOf(root, l.voice, l.text) : null
|
|
99
|
+
const tweak = l.voice ? voiceTweak(b, l.voice) : undefined
|
|
100
|
+
const made = t ? runSpec(takeRun(l.text, t, tweak), { root, dir: root }) : null
|
|
101
|
+
// a take not made with this leveller or tweak yet (a new one, a take from before it) is made in the background:
|
|
102
|
+
// the next read draws and plays it
|
|
103
|
+
if (t && made && !existsSync(made.file)) void soundRun(takeRun(l.text, t, tweak), { root, dir: root }, () => undefined).catch((e: Error) => console.error(`FAIL: take ${l.key}: ${e.message}`))
|
|
104
|
+
l.take = t ? { file: t.path, mtime: t.mtime, offset: t.offset ?? (await autoOffsetKept(root, t)), dragged: t.offset !== null, mask: t.mask, made: made && existsSync(made.file) ? made.key : null } : null
|
|
105
|
+
}
|
|
106
|
+
const first = recorders[0]
|
|
107
|
+
return {
|
|
108
|
+
trailer: id,
|
|
109
|
+
recorder: first ? { voice: first.name, who: first.voice.record, takes: first.voice.takes !== false } : null,
|
|
110
|
+
lines,
|
|
111
|
+
waiting: lines.filter((l) => l.mine && !l.take).length,
|
|
112
|
+
errors,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** each trailer folder's waiting lines, the brand read once; a repo with no trailer never loads its brand */
|
|
117
|
+
export async function voicesWaiting(root: string): Promise<Record<string, number>> {
|
|
118
|
+
if (trailerIds(root).length === 0) return {}
|
|
119
|
+
const b = await brandSound(root).catch(() => undefined)
|
|
120
|
+
if (recordVoices(b).length === 0) return {}
|
|
121
|
+
const out: Record<string, number> = {}
|
|
122
|
+
for (const id of trailerIds(root)) out[id] = (await voicesDesk(root, id, b))?.waiting ?? 0
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const autos = new Map<string, number>()
|
|
127
|
+
|
|
128
|
+
/** a take's offset when he never dragged it, as the build finds it (gen.ts autoOffset), read once a recording and mask */
|
|
129
|
+
async function autoOffsetKept(root: string, t: { path: string; mtime: number; mask: [number, number][] }): Promise<number> {
|
|
130
|
+
const key = `${t.path}\0${t.mtime}\0${JSON.stringify(t.mask)}`
|
|
131
|
+
const kept = autos.get(key)
|
|
132
|
+
if (kept !== undefined) return kept
|
|
133
|
+
const { autoOffset } = await import('../trailer/sound/gen.ts')
|
|
134
|
+
const o = await autoOffset(join(root, t.path), t.mask).catch(() => 0)
|
|
135
|
+
autos.set(key, o)
|
|
136
|
+
return o
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** a made line's file in the sound cache, by its key; null when absent */
|
|
140
|
+
export function madeFile(root: string, key: string): string | null {
|
|
141
|
+
if (!/^[0-9a-f]{16}$/.test(key)) return null
|
|
142
|
+
const f = join(soundCache(root), `${key}.wav`)
|
|
143
|
+
return existsSync(f) && statSync(f).isFile() ? f : null
|
|
144
|
+
}
|
package/src/review/watchers.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// who listens: each `sk review watch` registers one file per process beside the store (`.shipkit/review-watchers/`),
|
|
2
2
|
// out of its watch, so a registration never wakes the watchers. A file alone is never trusted: its pid is probed
|
|
3
|
-
import {
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, writeSync } from 'node:fs'
|
|
4
5
|
import { join } from 'node:path'
|
|
5
6
|
import type { WatchFilter, Watcher } from './model.ts'
|
|
6
7
|
|
|
@@ -33,6 +34,62 @@ export function registerWatch(dir: string, filter: WatchFilter, now = new Date()
|
|
|
33
34
|
})
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/** what a watch lives for: its parent at start, every process above it then, and the reader of its output */
|
|
38
|
+
export interface Owner {
|
|
39
|
+
parent: number
|
|
40
|
+
above: readonly number[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** the processes above `pid`, nearest first, launchd left out, from the lines of `ps -axo pid=,ppid=` */
|
|
44
|
+
export function ancestorsOf(pid: number, table: string): number[] {
|
|
45
|
+
const up = new Map<number, number>()
|
|
46
|
+
for (const line of table.split('\n')) {
|
|
47
|
+
const [p, pp] = line.trim().split(/\s+/).map(Number)
|
|
48
|
+
if (Number.isInteger(p) && Number.isInteger(pp)) up.set(p as number, pp as number)
|
|
49
|
+
}
|
|
50
|
+
const out: number[] = []
|
|
51
|
+
for (let p = up.get(pid); p !== undefined && p > 1 && !out.includes(p); p = up.get(p)) out.push(p)
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** why the watch has no owner any more, else null */
|
|
56
|
+
export function ownerGone(o: Owner, now: { ppid: number; alive: (pid: number) => boolean; readerGone: boolean }): string | null {
|
|
57
|
+
if (now.ppid !== o.parent) return `its parent ${o.parent} is gone`
|
|
58
|
+
const dead = o.above.find((p) => !now.alive(p))
|
|
59
|
+
if (dead !== undefined) return `process ${dead} above it is gone`
|
|
60
|
+
return now.readerGone ? 'nothing reads its output' : null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** a zero byte write to a pipe nobody reads fails with EPIPE on macOS (Linux answers 0: a real line's EPIPE ends it there) */
|
|
64
|
+
function readerGone(): boolean {
|
|
65
|
+
try {
|
|
66
|
+
writeSync(1, new Uint8Array(0))
|
|
67
|
+
return false
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return (e as NodeJS.ErrnoException).code === 'EPIPE'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** this process exits once its owner is gone, checked every `everyMs`: a killed agent's shell often lives on, waiting
|
|
74
|
+
* on a pipeline, so the parent alone is not enough */
|
|
75
|
+
export function exitWithOwner(everyMs = 2000): void {
|
|
76
|
+
const ps = spawnSync('ps', ['-axo', 'pid=,ppid='], { encoding: 'utf8' })
|
|
77
|
+
const owner: Owner = { parent: process.ppid, above: ancestorsOf(process.pid, ps.stdout ?? '') }
|
|
78
|
+
const end = (why: string): never => {
|
|
79
|
+
try {
|
|
80
|
+
process.stderr.write(`review watch: exits, ${why}\n`)
|
|
81
|
+
} catch {}
|
|
82
|
+
process.exit(0)
|
|
83
|
+
}
|
|
84
|
+
process.stdout.on('error', (e: NodeJS.ErrnoException) => {
|
|
85
|
+
if (e.code === 'EPIPE') end('nothing reads its output')
|
|
86
|
+
})
|
|
87
|
+
setInterval(() => {
|
|
88
|
+
const why = ownerGone(owner, { ppid: process.ppid, alive: pidAlive, readerGone: readerGone() })
|
|
89
|
+
if (why !== null) end(why)
|
|
90
|
+
}, everyMs)
|
|
91
|
+
}
|
|
92
|
+
|
|
36
93
|
/** every live watcher, by pid; a file whose process is gone is deleted */
|
|
37
94
|
export function liveWatchers(dir: string, alive: (pid: number) => boolean = pidAlive): Watcher[] {
|
|
38
95
|
const folder = watchersDir(dir)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// the shipkit macOS app's Dock badge and notifications, fed by the page (wiki tools/shipkit/home-pages.md, the
|
|
2
|
+
// shipkit app's Dock badge): the count the rail draws, posted when it changes, and each card that starts waiting.
|
|
3
|
+
// The app's WebKit message handler `shipkit` is the only listener: a browser tab has none, and nothing is posted.
|
|
4
|
+
//
|
|
5
|
+
// the one constraint a reader breaks first: the first answer of the daemon is the seed, so the backlog at app start
|
|
6
|
+
// never notifies; the list this browser kept from its last load is not that answer
|
|
7
|
+
import { reaction } from 'mobx'
|
|
8
|
+
import type { Project } from './projects-svc.ts'
|
|
9
|
+
|
|
10
|
+
/** a card that started waiting, as the app's notification names it; `url` opens it where no page answers */
|
|
11
|
+
export type AppCard = { id: string; title: string; repo: string; url: string }
|
|
12
|
+
/** `seed`: every card waiting at the page's first daemon answer; the app notifies those it never saw, unless it is
|
|
13
|
+
* the first seed of its life (the backlog at start) */
|
|
14
|
+
export type AppNote = { waiting: number; keys: string[] } | { seed: AppCard[] } | { card: AppCard }
|
|
15
|
+
export type Post = (note: AppNote) => void
|
|
16
|
+
/** the absolute address of a card's review page */
|
|
17
|
+
export type CardUrl = (repo: string, id: string) => string
|
|
18
|
+
|
|
19
|
+
/** the app's handler, or null in a browser tab */
|
|
20
|
+
export function appPost(w: unknown = globalThis): Post | null {
|
|
21
|
+
const h = (w as { webkit?: { messageHandlers?: { shipkit?: { postMessage(m: unknown): void } } } }).webkit?.messageHandlers?.shipkit
|
|
22
|
+
return h == null ? null : (note) => h.postMessage(note)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** the house wide count the badge shows: the rail's per repo numbers summed */
|
|
26
|
+
export const waitingOf = (list: Project[]): number => list.reduce((n, p) => n + p.cards.length, 0)
|
|
27
|
+
|
|
28
|
+
/** what one daemon answer posts: the count and the `repo/id` keys waiting when either moved (the app removes the
|
|
29
|
+
* banners of every other card), the seed at the first answer, then each card this page had not seen. The app owns
|
|
30
|
+
* the set of cards notified: this one only keeps a poll from posting them again */
|
|
31
|
+
export class AppBridge {
|
|
32
|
+
private seen: Set<string> | null = null
|
|
33
|
+
private last: string | null = null
|
|
34
|
+
|
|
35
|
+
constructor(private readonly post: Post, private readonly cardUrl: CardUrl) {}
|
|
36
|
+
|
|
37
|
+
update(list: Project[]): void {
|
|
38
|
+
const cards = list.flatMap((p) => p.cards.map((c) => ({ key: `${p.name}/${c.id}`, card: { id: c.id, title: c.title, repo: p.name, url: this.cardUrl(p.name, c.id) } })))
|
|
39
|
+
const keys = cards.map((c) => c.key)
|
|
40
|
+
const now = JSON.stringify(keys)
|
|
41
|
+
if (now !== this.last) {
|
|
42
|
+
this.last = now
|
|
43
|
+
this.post({ waiting: waitingOf(list), keys })
|
|
44
|
+
}
|
|
45
|
+
const seen = this.seen
|
|
46
|
+
if (seen == null) {
|
|
47
|
+
this.seen = new Set(cards.map((c) => c.key))
|
|
48
|
+
this.post({ seed: cards.map((c) => c.card) })
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
for (const c of cards) {
|
|
52
|
+
if (seen.has(c.key)) continue
|
|
53
|
+
seen.add(c.key)
|
|
54
|
+
this.post({ card: c.card })
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** what the app calls on a notification's click: that card in this window, in place, or the inbox */
|
|
60
|
+
export type AppHooks = { openCard(repo: string, id: string): void; openInbox(): void }
|
|
61
|
+
|
|
62
|
+
/** feeds the app from the project list once it is the daemon's, and hands the app the page's hooks; a no-op
|
|
63
|
+
* outside the app. Returns the stop */
|
|
64
|
+
export function startAppBridge(o: { projects: { fresh: boolean; list: Project[] }; hooks: AppHooks; cardUrl: CardUrl; post?: Post | null; w?: unknown }): () => void {
|
|
65
|
+
const w = o.w ?? globalThis
|
|
66
|
+
const post = o.post === undefined ? appPost(w) : o.post
|
|
67
|
+
if (post == null) return () => {}
|
|
68
|
+
const bridge = new AppBridge(post, o.cardUrl)
|
|
69
|
+
;(w as { shipkitApp?: AppHooks }).shipkitApp = o.hooks
|
|
70
|
+
return reaction(() => (o.projects.fresh ? o.projects.list : null), (list) => { if (list != null) bridge.update(list) }, { fireImmediately: true })
|
|
71
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// the browser reports a ResizeObserver loop as a window 'error' event, yet it
|
|
2
|
+
// is a notice, not a failure: the spec delivers the skipped notifications next
|
|
3
|
+
// frame. Bun's dev overlay listens for 'error' and paints it as a runtime
|
|
4
|
+
// error. A capture listener on the target runs before Bun's bubble one, so
|
|
5
|
+
// stopImmediatePropagation keeps the overlay for real errors only.
|
|
6
|
+
const BENIGN = [
|
|
7
|
+
'ResizeObserver loop completed with undelivered notifications.', // webkit, chromium
|
|
8
|
+
'ResizeObserver loop limit exceeded', // older chromium
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
export const isBenignError = (message: unknown): boolean =>
|
|
12
|
+
typeof message === 'string' && BENIGN.some(b => message.includes(b))
|
|
13
|
+
|
|
14
|
+
export const quietBenignErrors = (target: EventTarget): void => {
|
|
15
|
+
target.addEventListener(
|
|
16
|
+
'error',
|
|
17
|
+
e => {
|
|
18
|
+
if (isBenignError((e as ErrorEvent).message)) e.stopImmediatePropagation()
|
|
19
|
+
},
|
|
20
|
+
{ capture: true },
|
|
21
|
+
)
|
|
22
|
+
}
|