rvlib-shipkit 2.32.0 → 2.33.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 +20 -0
- package/package.json +1 -1
- package/src/advisors/advisor-view.ts +28 -7
- package/src/advisors/edge/api.ts +1 -30
- package/src/advisors/project.ts +3 -3
- package/src/advisors/sync.ts +7 -3
- package/src/advisors/users-router.ts +13 -11
- package/src/cli/cmd_Capacity.ts +6 -2
- package/src/cli/cmd_Ci.ts +2 -1
- package/src/cli/cmd_Shot.ts +26 -4
- package/src/cli.ts +13 -2
- package/src/core/admission.ts +268 -0
- package/src/core/code-lines.ts +36 -21
- package/src/core/machine-read.ts +5 -2
- package/src/core/peer-sk.ts +8 -0
- package/src/gate/admit-heavy.ts +150 -0
- package/src/gate/check-runner.ts +6 -0
- package/src/gate/head-gate.ts +1 -1
- package/src/gate/job-run.ts +2 -1
- package/src/gate/pre-commit-discovery.ts +6 -3
- package/src/gate/run-check.ts +3 -0
- package/src/gate/run-ci.ts +4 -0
- package/src/home/run-daemon.ts +3 -1
- package/src/hooks/commit-msg-run.ts +61 -0
- package/src/hooks/commit-run.ts +16 -166
- package/src/hooks/gate-outcome.ts +108 -0
- package/src/hooks/git-hook.ts +9 -9
- package/src/hooks/hook-config.ts +2 -1
- package/src/hooks/pre-commit-checks.ts +1 -1
- package/src/hooks/run-hooks.ts +2 -1
- package/src/hooks/shared-file.ts +3 -2
- package/src/plan/planner.ts +3 -2
- package/src/repo-config.ts +8 -1
- package/src/review/answer-kinds.ts +2 -0
- package/src/review/cells.ts +34 -7
- package/src/review/format.ts +1 -1
- package/src/review/model.ts +3 -3
- package/src/review/routes.ts +2 -28
- package/src/review/store-parties.ts +28 -0
- package/src/review/store.ts +9 -1
- package/src/review/thread-state.ts +9 -3
- package/src/secrets/copy.ts +4 -4
- package/src/serve/hub-app/dock-st.ts +1 -1
- package/src/serve/hub-app/review/question-views.tsx +28 -17
- package/src/serve/hub-app/review/review-host.ts +6 -2
- package/src/serve/hub-app/review/review-list.tsx +8 -5
- package/src/serve/hub-app/review/review-st.ts +2 -2
- package/src/serve/hub-app/review/review-views.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +17 -9
- package/src/serve/hub-app/review/tone-bar.tsx +27 -24
- package/src/serve/hub-app/review/tones.ts +18 -0
- package/src/serve/hub-app/review.css +11 -2
- package/src/shot/client.ts +2 -1
- package/src/shot/on-place.ts +141 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// the owner's answer bar (wiki tools/shipkit/threads-page.md, His answer): the five tones, or no answer, in one labelled bar at the foot
|
|
2
|
-
// of the item that asks it, a version
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// of the item that asks it, a version or a message that asks the owner's verdict; a question draws its own words in the
|
|
3
|
+
// same bar (tones.ts questionTones). A tone with no words acts in one click; one that takes words (a bubble corner marks
|
|
4
|
+
// it) opens a box over the tone, Enter sends its words with it, an empty box the bare tone, Escape closes. The send
|
|
5
5
|
// draws as given in that frame; only a refusal moves it back, the box open again with the words and why. While it waits
|
|
6
6
|
// it wears the orange frame (cta.tsx); given, the lit tone alone, the others on a hover. It sticks to the screen's foot
|
|
7
7
|
// while any part of its item shows, and never leaves its item (review.css .rv-tonebar)
|
|
@@ -15,7 +15,7 @@ import { tip } from '../tips.ts'
|
|
|
15
15
|
import { Cta } from './cta.tsx'
|
|
16
16
|
import { keepFocus, toneOf } from './kit.tsx'
|
|
17
17
|
import type { ThreadSt } from './thread-st.ts'
|
|
18
|
-
import { TONES, toneOfStatus, type Tone } from './tones.ts'
|
|
18
|
+
import { questionToneClass, questionTones, TONES, toneOfStatus, type Tone } from './tones.ts'
|
|
19
19
|
|
|
20
20
|
/** the act each tone is, for the page's role (review-host.ts): an advisor says ok or what they would fix, the rest is
|
|
21
21
|
* the owner's; on a question an advisor's ok and fix are picks */
|
|
@@ -37,10 +37,11 @@ export const ToneMark = ({ t }: { t: Tone }) => (
|
|
|
37
37
|
</span>
|
|
38
38
|
)
|
|
39
39
|
|
|
40
|
-
/** `on`: a version's id, or the cell id of a message that asks the owner's verdict or of a question.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
/** `on`: a version's id, or the cell id of a message that asks the owner's verdict or of a question. A question answers in
|
|
41
|
+
* question words (tones.ts questionTones), never in a verdict's: under its options the question's row alone, none of
|
|
42
|
+
* these (a choice), your call (`pick`, the agent's pick by its label, null when it named none), no answer. `option`: the
|
|
43
|
+
* bar of that one option (the lightbox's side panel): its pick and its pick with a remark, then the row, its pick lit
|
|
44
|
+
* only on the option he picked. A question's cell wears the frame of what waits already: its bar draws none of its own */
|
|
44
45
|
export const ToneBar = observer(({ thread, on, question, pick, option }: { thread: ThreadSt; on: string; question?: ReplyCell; pick?: string | null; option?: number }) => {
|
|
45
46
|
const buttons = useRef(new Map<ItemVerdict, HTMLButtonElement>())
|
|
46
47
|
const sent = thread.givenOn(on)
|
|
@@ -50,34 +51,34 @@ export const ToneBar = observer(({ thread, on, question, pick, option }: { threa
|
|
|
50
51
|
const failed = thread.failed?.on === on && note === null ? thread.failed.why : null
|
|
51
52
|
const sending = thread.sending?.on === on
|
|
52
53
|
const q = question !== undefined
|
|
53
|
-
const
|
|
54
|
+
const row = q && option === undefined
|
|
55
|
+
const list = q ? questionTones(row ? 'row' : 'option', pick ?? null, question.ask?.kind ?? 'choice') : TONES
|
|
56
|
+
const tones = list.filter((t) => thread.can(actOf(t.status, q)))
|
|
54
57
|
if (tones.length === 0) return null
|
|
55
|
-
const
|
|
58
|
+
const cls = (s: ItemVerdict): string => (q ? questionToneClass(s) : toneOf(s))
|
|
59
|
+
const noteTone = note ? (list.find((t) => t.status === note.status) ?? toneOfStatus(note.status)!) : null
|
|
56
60
|
return (
|
|
57
61
|
<Cta on={question === undefined && (!given || note !== null)} className="rv-tonecta">
|
|
58
62
|
{/* a click here never folds or unfolds the cell it sits on */}
|
|
59
|
-
<div className={`rv-tonebar${given ? ' given' : ''}${note ? ' noting' : ''}`} role="group" aria-label={q ? 'your answer to this question' : 'your verdict on this item'} data-check="tonebar" onClick={(e) => e.stopPropagation()}>
|
|
63
|
+
<div className={`rv-tonebar${row ? ' question' : ''}${given ? ' given' : ''}${note ? ' noting' : ''}`} role="group" aria-label={q ? 'your answer to this question' : 'your verdict on this item'} data-check="tonebar" onClick={(e) => e.stopPropagation()}>
|
|
60
64
|
{tones.map((t) => {
|
|
61
65
|
const lit = option === undefined ? sent === t.status : thread.litOn(on, t.status, option)
|
|
62
66
|
const open = note?.status === t.status
|
|
63
|
-
const no = blocked(t)
|
|
64
|
-
const takes = q && pick && (t.status === 'approved' || t.status === 'approved-with-fix') ? ` ${pick}` : ''
|
|
65
67
|
return (
|
|
66
68
|
<button key={t.status} type="button" ref={(b) => void (b ? buttons.current.set(t.status, b) : buttons.current.delete(t.status))} data-check="tone" data-status={t.status}
|
|
67
|
-
className={`rv-tone ${
|
|
68
|
-
|
|
69
|
-
{...tip(`${t.word}${takes} (${t.key} or ${t.letter}): ${no ?? (lit ? 'your answer; a note on it' + (version ? ', or take it back' : '') : t.says)}${t.words && !lit ? '\nopens a box for your words, Enter sends' : ''}`)}
|
|
69
|
+
className={`rv-tone ${cls(t.status)}${lit ? ' chosen' : ''}${open ? ' open' : ''}${t.words ? ' words' : ''}`} aria-pressed={lit} aria-haspopup={t.words ? 'dialog' : undefined} aria-expanded={t.words ? open : undefined}
|
|
70
|
+
{...tip(`${t.word} (${t.key} or ${t.letter}): ${lit ? 'your answer; a note on it' + (version ? ', or take it back' : '') : t.says}${t.words && !lit ? '\nopens a box for your words, Enter sends' : ''}`)}
|
|
70
71
|
onMouseDown={keepFocus} onClick={() => void thread.tone(on, t.status, option)}>
|
|
71
72
|
<ToneMark t={t} />
|
|
72
|
-
<span className="rv-toneword">{t.word}
|
|
73
|
+
<span className="rv-toneword">{t.word}</span>
|
|
73
74
|
</button>
|
|
74
75
|
)
|
|
75
76
|
})}
|
|
76
77
|
{sending ? <span className="rv-tonesending" role="status">sending…</span> : null}
|
|
77
|
-
{note ? (
|
|
78
|
-
<Popover open anchor={buttons.current.get(note.status) ?? null} onClose={() => thread.cancelNote()} outside={note.text.trim() === ''} className={`rv-vnote ${
|
|
79
|
-
label={`your ${
|
|
80
|
-
<NoteBox thread={thread} on={on}
|
|
78
|
+
{note && noteTone ? (
|
|
79
|
+
<Popover open anchor={buttons.current.get(note.status) ?? null} onClose={() => thread.cancelNote()} outside={note.text.trim() === ''} className={`rv-vnote ${cls(note.status)}${option !== undefined ? ' boxed' : ''}`}
|
|
80
|
+
label={`your ${noteTone.word}, with your words`} placement={option !== undefined ? 'bottom-start' : 'top-start'} fallbacks={option !== undefined ? ['top-start'] : ['bottom-start', 'top-end']}>
|
|
81
|
+
<NoteBox thread={thread} on={on} t={noteTone} question={q} text={note.text} why={note.why ?? null} takesBack={version && sent === note.status} />
|
|
81
82
|
</Popover>
|
|
82
83
|
) : null}
|
|
83
84
|
{failed !== null ? <span className="rv-vfail" role="alert">✗ not saved: {failed}</span> : null}
|
|
@@ -88,13 +89,15 @@ export const ToneBar = observer(({ thread, on, question, pick, option }: { threa
|
|
|
88
89
|
|
|
89
90
|
/** the box of a tone: its mark and word, the box focused as it opens; Enter sends both (an empty box the bare tone),
|
|
90
91
|
* ⇧Enter a new line, Escape closes with nothing sent. On the lit tone of a version, « take it back » */
|
|
91
|
-
const NoteBox = observer(({ thread, on,
|
|
92
|
+
const NoteBox = observer(({ thread, on, t, question, text, why, takesBack }: { thread: ThreadSt; on: string; t: Tone; question: boolean; text: string; why: string | null; takesBack: boolean }) => {
|
|
92
93
|
const box = useRef<HTMLTextAreaElement | null>(null)
|
|
94
|
+
const status = t.status
|
|
93
95
|
useLayoutEffect(() => {
|
|
94
96
|
box.current?.focus()
|
|
95
97
|
}, [on, status])
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
+
const hint = question
|
|
99
|
+
? status === 'approved-with-fix' ? 'your remark: what to change, what to keep' : status === 'rework' ? 'what you want instead' : `a note with your ${t.word}, if you like`
|
|
100
|
+
: status === 'approved-with-fix' ? 'what to fix, the rest stays' : status === 'rework' ? 'what is wrong, what to keep' : status === 'wrong-direction' ? 'why the direction is wrong, what you want instead' : `a note with your ${t.word}, if you like`
|
|
98
101
|
return (
|
|
99
102
|
<>
|
|
100
103
|
<div className="rv-vnotehead">
|
|
@@ -27,6 +27,24 @@ export const TONES: readonly Tone[] = [
|
|
|
27
27
|
|
|
28
28
|
export const toneOfStatus = (s: string): Tone | undefined => TONES.find((t) => t.status === s)
|
|
29
29
|
|
|
30
|
+
/** a question answers in question words, a version in verdict words: one option's pick and pick with a remark, then the
|
|
31
|
+
* question's own row, none of these, your call, no answer. Each is stored as the tone it names (store.ts answerAsk);
|
|
32
|
+
* ok, rework and wrong direction draw on no question. `pick`: the agent's pick by its label, null when it named none.
|
|
33
|
+
* `kind`: none of these on a choice alone; a confirm is a step only the owner does, so no your call either */
|
|
34
|
+
export function questionTones(where: 'option' | 'row', pick: string | null, kind = 'choice'): Tone[] {
|
|
35
|
+
const t = (s: ItemVerdict): Tone => toneOfStatus(s)!
|
|
36
|
+
const row: Tone[] = [
|
|
37
|
+
...(kind === 'choice' ? [{ ...t('rework'), word: 'none of these', glyph: '✕', says: 'none of these options: say what you want instead' }] : []),
|
|
38
|
+
...(kind === 'confirm' ? [] : [{ ...t('your-call'), says: pick !== null ? `go with the agent's pick, ${pick}: nothing to type` : 'the agent decides and says what it chose: nothing to type' }]),
|
|
39
|
+
t('no-answer'),
|
|
40
|
+
]
|
|
41
|
+
if (where === 'row') return row
|
|
42
|
+
return [{ ...t('approved'), word: 'pick', says: 'pick this option' }, { ...t('approved-with-fix'), word: 'pick with a remark', says: 'pick this option with your words: the agent reads both' }, ...row]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** the colour a question's answer draws in: « none of these » red, a pick with a remark orange, the rest their tone's */
|
|
46
|
+
export const questionToneClass = (s: ItemVerdict): string => (s === 'rework' || s === 'wrong-direction' ? 'st-none' : s === 'approved-with-fix' ? 'st-remark' : `st-${s}`)
|
|
47
|
+
|
|
30
48
|
/** a verdict's glyph as a disc draws it: a tone's, « not doing it » its own */
|
|
31
49
|
export const glyphOf = (s: string): string => toneOfStatus(s)?.glyph ?? (s === 'archived' ? '▤' : '•')
|
|
32
50
|
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
.st-approved-with-fix,.re-approved-with-fix{--tone:var(--yellow)}
|
|
9
9
|
.st-rework,.re-rework{--tone:var(--orange)}
|
|
10
10
|
.st-wrong-direction{--tone:var(--red)}
|
|
11
|
+
/* a question's « none of these » (tones.ts questionToneClass) */
|
|
12
|
+
.st-none{--tone:var(--red)}
|
|
13
|
+
/* a question's « pick with a remark » */
|
|
14
|
+
.st-remark{--tone:var(--orange)}
|
|
11
15
|
.st-your-call,.st-no-answer{--tone:var(--dim)}
|
|
12
16
|
.st-archived,.st-superseded,.st-withdrawn,.st-wontfix,.st-rated{--tone:var(--dim)}
|
|
13
17
|
.st-wip{--tone:var(--k2)}
|
|
@@ -442,7 +446,6 @@
|
|
|
442
446
|
.rv-siderow{color:var(--ink)}
|
|
443
447
|
.rv-boxside :is(.rv-tonecta,.rv-ctaoff.rv-tonecta){position:static;align-self:stretch;margin:0;padding:0}
|
|
444
448
|
.rv-boxside .rv-tonebar{flex-direction:column;align-items:stretch}
|
|
445
|
-
.rv-boxside .rv-tonetakes{display:none}
|
|
446
449
|
.rv-sidekeys{margin-top:auto;font-size:11.5px}
|
|
447
450
|
.rv-vnote.boxed{z-index:60}
|
|
448
451
|
@media (max-width:767px){.rv-boxbody{flex-direction:column}.rv-boxside{flex:0 0 auto;max-height:45%;border-left:0;border-top:1px solid var(--line)}.rv-sidekeys{display:none}}
|
|
@@ -1133,6 +1136,8 @@ button.tr-changed.on{background:var(--accent);color:var(--bg)}
|
|
|
1133
1136
|
.rv-askopt{display:inline-flex;align-items:center;gap:var(--s2);padding:var(--s1) var(--s3);border-radius:8px;border:1px solid var(--line);background:var(--bg);font-size:13px;cursor:pointer;text-align:left}
|
|
1134
1137
|
.rv-askoptlabel{flex:1 1 auto;min-width:min(7em,100%);overflow-wrap:break-word}
|
|
1135
1138
|
.rv-askopt:hover:not(:disabled){border-color:var(--accent)}
|
|
1139
|
+
/* an option of a question is its own pick: green under the pointer, as a pick draws once given */
|
|
1140
|
+
:is(.rv-askoption,.rv-askchoice) > .rv-askopt:hover:not(:disabled){border-color:var(--ok);background:color-mix(in srgb,var(--ok) 8%,var(--bg))}
|
|
1136
1141
|
.rv-askopt.pick{border-color:color-mix(in srgb,var(--accent) 60%,var(--line))}
|
|
1137
1142
|
/* his answer, green as what he settled; the agent's pick only a dashed suggestion beside it, never the same mark */
|
|
1138
1143
|
.rv-askopt.picked{background:color-mix(in srgb,var(--ok) 14%,var(--bg));border-color:var(--ok);outline:1px solid var(--ok);outline-offset:-2px;font-weight:600}
|
|
@@ -1366,7 +1371,11 @@ button.tr-changed.on{background:var(--accent);color:var(--bg)}
|
|
|
1366
1371
|
/* the speech bubble's corner: this tone opens a box for the owner's words */
|
|
1367
1372
|
.rv-tonebubble{position:absolute;right:-4px;top:-3px;width:9px;height:7px;border-radius:4px 4px 4px 0;background:var(--tone);box-shadow:0 0 0 1.5px var(--panel)}
|
|
1368
1373
|
.st-your-call .rv-tonemark{filter:grayscale(1)}
|
|
1369
|
-
.
|
|
1374
|
+
/* a question's own row under its options (tone-bar.tsx, tones.ts questionTones): quiet, the options are the answer */
|
|
1375
|
+
.rv-tonebar.question .rv-tone{min-height:26px;padding:2px var(--s2) 2px 2px;border-width:1px;font-size:12px;font-weight:500;background:none;box-shadow:none;color:var(--dim)}
|
|
1376
|
+
.rv-tonebar.question .rv-tone:hover:not(:disabled),.rv-tonebar.question .rv-tone:focus-visible{color:var(--ink);background:color-mix(in srgb,var(--tone) 16%,var(--panel))}
|
|
1377
|
+
.rv-tonebar.question .rv-tone.chosen,.rv-tonebar.question .rv-tone.open{color:var(--bg);background:var(--tone)}
|
|
1378
|
+
.rv-tonebar.question .rv-tonemark{width:18px;height:18px;font-size:11px}
|
|
1370
1379
|
.rv-tonesending{font-size:12px;color:var(--dim)}
|
|
1371
1380
|
.rv-phone .rv-tone,.rv-thread.slim .rv-tone{font-size:12px;padding-right:var(--s2)}
|
|
1372
1381
|
.rv-vdisc.st-your-call{filter:grayscale(1)}
|
package/src/shot/client.ts
CHANGED
|
@@ -16,7 +16,8 @@ export const SHOT_PROCESS = 'shot'
|
|
|
16
16
|
* (shot-theme.ts), and with none the browser's own */
|
|
17
17
|
export type ShotInput = { url: string; out: string; viewport?: Viewport; dpr?: number; reload?: boolean; waitMs?: number; step?: string; at?: number; full?: boolean; root?: string; theme?: Theme }
|
|
18
18
|
export type ClipInput = ShotInput & { seconds: number; fps?: number; dom?: boolean }
|
|
19
|
-
|
|
19
|
+
/** `on`: the place of the house it was shot on (on-place.ts), absent when here */
|
|
20
|
+
export type ShotResult = ShotDone & { via: 'warm' | 'started' | 'local' | 'box'; on?: string }
|
|
20
21
|
|
|
21
22
|
const shotAsk = async (i: ShotInput): Promise<ShotAsk> => {
|
|
22
23
|
const { houseShotLook } = await import('./shot-theme.ts')
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// sk shot --on <place>: a still or a clip shot on another place of the house, in that machine's own warm browser, the
|
|
2
|
+
// file brought back here. The place runs its own plain `sk shot` over ssh from its house checkout (core/peer-sk.ts,
|
|
3
|
+
// the reach `sk secret copy` uses), writing under its /tmp; each file comes back on ssh's stdout and leaves there.
|
|
4
|
+
// The one constraint a reader breaks first: the url is the place's own, so its localhost is that machine's, and a path
|
|
5
|
+
// of this machine is no url there
|
|
6
|
+
import { randomBytes } from 'crypto'
|
|
7
|
+
import { mkdirSync, writeFileSync } from 'fs'
|
|
8
|
+
import { dirname } from 'path'
|
|
9
|
+
import { peerSk, shq } from '../core/peer-sk.ts'
|
|
10
|
+
import { DEFAULT_FPS, DEFAULT_VIEWPORT, DEFAULT_WAIT_MS, MAX_CLIP_SECONDS, isClip, type ClipAsk, type ShotAsk } from './shot-ask.ts'
|
|
11
|
+
import type { ShotResult } from './client.ts'
|
|
12
|
+
import { assertStills, tileOut } from './still-file.ts'
|
|
13
|
+
|
|
14
|
+
/** a place as the hq last heard it: its name, its live daemon's user, tailnet name, shipkit, its global processes */
|
|
15
|
+
export type PlaceFacts = { name: string; nodes: { osUser: string; ended: number | null; seen: number; report: { at: number; body: { version: string; tailnet: { name: string | null }; processes?: { id: string; state: string }[] } } | null }[] }
|
|
16
|
+
|
|
17
|
+
/** where the shot runs: `host` is what ssh reaches, `seen` the time of its last report */
|
|
18
|
+
export type Place = { name: string; host: string; version: string; seen: number }
|
|
19
|
+
|
|
20
|
+
export type PlaceLook = { here: string; machines: readonly PlaceFacts[] | { refused: string }; sshAlias: (name: string) => boolean; now: number }
|
|
21
|
+
|
|
22
|
+
const ago = (ms: number): string => (ms < 90_000 ? `${Math.round(ms / 1000)} s` : ms < 5_400_000 ? `${Math.round(ms / 60_000)} min` : `${Math.round(ms / 3_600_000)} h`)
|
|
23
|
+
|
|
24
|
+
/** the place `name` names: 'here' for this machine, else the place or the one line that refuses it */
|
|
25
|
+
export function placeOf(name: string, l: PlaceLook): Place | 'here' | { refused: string } {
|
|
26
|
+
const same = (a: string): boolean => a.toLowerCase() === name.toLowerCase()
|
|
27
|
+
if (same(l.here)) return 'here'
|
|
28
|
+
if ('refused' in l.machines) return { refused: `FAIL shot --on ${name}: the hq does not answer (${l.machines.refused}), so no place is known: sk machines` }
|
|
29
|
+
const m = l.machines.find((x) => same(x.name))
|
|
30
|
+
if (m == null) {
|
|
31
|
+
if (l.sshAlias(name))
|
|
32
|
+
return { refused: `FAIL shot --on ${name}: ${name} is reached by ssh but is no place of the house (no shipkit daemon there reports to the hq), so no shot service runs on it. A repo whose repo.config.ts names it in browsers.box already films there with a plain sk shot` }
|
|
33
|
+
return { refused: `FAIL shot --on ${name}: no place of that name; the places the hq knows: ${l.machines.map((x) => x.name).join(', ') || 'none'} (sk machines)` }
|
|
34
|
+
}
|
|
35
|
+
const n = m.nodes.filter((x) => x.ended == null && x.report != null).sort((a, b) => b.seen - a.seen)[0]
|
|
36
|
+
if (n == null || n.report == null) return { refused: `FAIL shot --on ${m.name}: no daemon of ${m.name} reports to the hq any more: sk machines` }
|
|
37
|
+
const procs = n.report.body.processes
|
|
38
|
+
if (procs != null && !procs.some((p) => p.id === 'shot')) return { refused: `FAIL shot --on ${m.name}: pm on ${m.name} knows no shot service (shipkit ${n.report.body.version}): sk fleet update --place ${m.name}` }
|
|
39
|
+
const host = `${n.osUser}@${l.sshAlias(m.name) ? m.name : (n.report.body.tailnet.name ?? m.name)}`
|
|
40
|
+
return { name: m.name, host, version: n.report.body.version, seen: n.report.at }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** the place's own `sk shot` words for the ask, its file at `out` there; a default left out, so an older shipkit
|
|
44
|
+
* takes every ask it can */
|
|
45
|
+
export function placeArgs(a: ShotAsk | ClipAsk, out: string): string[] {
|
|
46
|
+
const w = ['shot', a.url]
|
|
47
|
+
if (a.viewport.width !== DEFAULT_VIEWPORT.width || a.viewport.height !== DEFAULT_VIEWPORT.height) w.push('--viewport', `${a.viewport.width},${a.viewport.height}`)
|
|
48
|
+
if (a.dpr !== 1) w.push('--dpr', String(a.dpr))
|
|
49
|
+
if (a.waitMs !== DEFAULT_WAIT_MS) w.push('--wait', String(a.waitMs))
|
|
50
|
+
if (a.reload) w.push('--reload')
|
|
51
|
+
if (a.theme != null) w.push('--theme', a.theme)
|
|
52
|
+
if (a.step != null) w.push('--step', a.step)
|
|
53
|
+
if (isClip(a)) {
|
|
54
|
+
w.push('--video', String(a.seconds))
|
|
55
|
+
if (a.seconds > MAX_CLIP_SECONDS) w.push('--long')
|
|
56
|
+
if (a.fps !== DEFAULT_FPS) w.push('--fps', String(a.fps))
|
|
57
|
+
if (a.dom) w.push('--dom')
|
|
58
|
+
} else {
|
|
59
|
+
if (a.at != null && a.step != null) w.push('--at', String(a.at))
|
|
60
|
+
if (a.full === true) w.push('--full')
|
|
61
|
+
}
|
|
62
|
+
w.push('--out', out, '--json')
|
|
63
|
+
return w
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type Ran = { code: number; out: Uint8Array; err: string }
|
|
67
|
+
/** one command on the place; a test passes a fake place */
|
|
68
|
+
export type Ssh = (host: string, command: string) => Promise<Ran>
|
|
69
|
+
|
|
70
|
+
const lastLine = (s: string): string => s.trim().split('\n').filter(Boolean).at(-1) ?? ''
|
|
71
|
+
|
|
72
|
+
/** the one line a failed run on the place says, with the fix */
|
|
73
|
+
export function placeRefusal(p: Place, r: { code: number; out: string; err: string }, houseRel: string, now: number): string {
|
|
74
|
+
const said = lastLine(r.err) || lastLine(r.out) || `exit ${r.code}`
|
|
75
|
+
const at = `FAIL shot --on ${p.name}`
|
|
76
|
+
if (r.code === 255) return `${at}: ${p.name} does not answer ssh at ${p.host} (${said}); its daemon last reported ${ago(now - p.seen)} ago: is it on and on the tailnet? sk machines`
|
|
77
|
+
if (r.code === 127 || /sk: (command )?not found/.test(r.err)) return `${at}: ${p.name} has no sk on the PATH of an ssh shell ($HOME/.local/bin, $HOME/.bun/bin): run bun run relink in its house checkout`
|
|
78
|
+
if (/cd: .*(No such file|not a directory|can't cd)/i.test(r.err)) return `${at}: ${p.name} has no house checkout at ~/${houseRel}, where this machine has its own`
|
|
79
|
+
if (/Unknown Syntax Error|Unsupported option|Command not found/i.test(`${r.err}\n${r.out}`))
|
|
80
|
+
return `${at}: ${p.name} runs shipkit ${p.version}, whose sk shot does not take this ask (${said}): sk fleet update --place ${p.name}`
|
|
81
|
+
return `${at}: ${said.replace(/^FAIL (shot: )?/, '')}`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** the ask shot on the place, each file it wrote brought back to `a.out` (its tiles beside it), and removed there */
|
|
85
|
+
export async function shotOnPlace(p: Place, a: ShotAsk | ClipAsk, o: { ssh: Ssh; houseRel: string; say?: (l: string) => void; now?: () => number }): Promise<ShotResult & { on: string }> {
|
|
86
|
+
const ext = /\.[^./]+$/.exec(a.out)?.[0] ?? (isClip(a) ? '.mp4' : '.webp')
|
|
87
|
+
const there = `/tmp/sk-shot-on-${randomBytes(6).toString('hex')}${ext}`
|
|
88
|
+
const text = (b: Uint8Array): string => new TextDecoder().decode(b)
|
|
89
|
+
const r = await o.ssh(p.host, peerSk(o.houseRel, placeArgs(a, there).map(shq).join(' ')))
|
|
90
|
+
const out = text(r.out)
|
|
91
|
+
if (r.code !== 0) throw new Error(placeRefusal(p, { code: r.code, out, err: r.err }, o.houseRel, (o.now ?? Date.now)()))
|
|
92
|
+
for (const l of r.err.split('\n').filter(Boolean)) o.say?.(`${p.name}: ${l}`)
|
|
93
|
+
let done: ShotResult
|
|
94
|
+
try {
|
|
95
|
+
done = JSON.parse(lastLine(out)) as ShotResult
|
|
96
|
+
} catch {
|
|
97
|
+
throw new Error(`FAIL shot --on ${p.name}: its sk shot answered no json (${lastLine(out) || 'nothing'}): shipkit ${p.version} there, sk fleet update --place ${p.name}`)
|
|
98
|
+
}
|
|
99
|
+
const files = done.tiles ?? [done.out]
|
|
100
|
+
const here = (f: string): string => {
|
|
101
|
+
if (f === there) return a.out
|
|
102
|
+
for (let n = 1; n <= files.length; n++) if (f === tileOut(there, n)) return tileOut(a.out, n)
|
|
103
|
+
throw new Error(`FAIL shot --on ${p.name}: it wrote ${f}, not the file it was asked for (${there})`)
|
|
104
|
+
}
|
|
105
|
+
const brought: string[] = []
|
|
106
|
+
for (const f of files) {
|
|
107
|
+
const to = here(f)
|
|
108
|
+
const got = await o.ssh(p.host, `cat ${shq(f)} && rm -f ${shq(f)}`)
|
|
109
|
+
if (got.code !== 0) throw new Error(`FAIL shot --on ${p.name}: its file ${f} did not come back (${lastLine(got.err) || `exit ${got.code}`})`)
|
|
110
|
+
mkdirSync(dirname(to), { recursive: true })
|
|
111
|
+
writeFileSync(to, got.out)
|
|
112
|
+
brought.push(to)
|
|
113
|
+
}
|
|
114
|
+
if (!isClip(a)) assertStills(brought)
|
|
115
|
+
return { ...done, out: brought[0] ?? a.out, ...(done.tiles != null ? { tiles: brought } : {}), on: p.name }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** the place this machine sees under `name`, from the hq's machines and ssh's own config; 'here' for this machine */
|
|
119
|
+
export async function lookPlace(name: string): Promise<Place | 'here' | { refused: string }> {
|
|
120
|
+
const { machineName } = await import('../core/machine-name.ts')
|
|
121
|
+
const { machinesPage } = await import('../hq/hq-local.ts')
|
|
122
|
+
const page = await machinesPage(1)
|
|
123
|
+
// a Host block names it when ssh's resolved config for it differs from a name no block matches (its own names apart)
|
|
124
|
+
const resolved = (n: string): string | null => {
|
|
125
|
+
const g = Bun.spawnSync(['ssh', '-G', n], { stdout: 'pipe', stderr: 'ignore' })
|
|
126
|
+
return g.exitCode !== 0 ? null : g.stdout.toString().split('\n').filter((l) => !/^host(name)? /.test(l)).join('\n')
|
|
127
|
+
}
|
|
128
|
+
const plain = resolved('sk-no-such-host.invalid')
|
|
129
|
+
const sshAlias = (n: string): boolean => {
|
|
130
|
+
const g = Bun.spawnSync(['ssh', '-G', n], { stdout: 'pipe', stderr: 'ignore' })
|
|
131
|
+
const host = /^hostname (.+)$/m.exec(g.stdout.toString())?.[1]?.trim()
|
|
132
|
+
return g.exitCode === 0 && ((host != null && host.toLowerCase() !== n.toLowerCase()) || (plain != null && resolved(n) !== plain))
|
|
133
|
+
}
|
|
134
|
+
return placeOf(name, { here: machineName(), machines: 'refused' in page ? page : page.machines, sshAlias, now: Date.now() })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** the ssh every place is reached by: one connection kept a while, so bringing the file back pays no second handshake */
|
|
138
|
+
export const placeSsh: Ssh = async (host, command) => {
|
|
139
|
+
const { houseSsh } = await import('../media-store/backup/ssh-target.ts')
|
|
140
|
+
return houseSsh(host, command)
|
|
141
|
+
}
|