rvlib-shipkit 2.32.0 → 2.34.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 +42 -0
- package/package.json +1 -1
- package/src/advisors/advisor-view.ts +29 -7
- package/src/advisors/edge/api.ts +1 -30
- package/src/advisors/project.ts +3 -3
- package/src/advisors/sync.ts +11 -4
- package/src/advisors/users-router.ts +13 -11
- package/src/cli/cmd_BackupTargets.ts +49 -8
- package/src/cli/cmd_Capacity.ts +6 -2
- package/src/cli/cmd_Ci.ts +2 -1
- package/src/cli/cmd_Media.ts +1 -1
- package/src/cli/cmd_Shot.ts +26 -4
- package/src/cli/cmd_Start.ts +3 -3
- 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/memory-watch.ts +1 -1
- 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/gate-checks.ts +7 -5
- 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/backup-status.ts +41 -13
- package/src/home/backup-verdict.ts +1 -0
- package/src/home/daemon-jobs.ts +5 -0
- package/src/home/home-routes.ts +3 -2
- package/src/home/house-bucket.ts +14 -0
- package/src/home/run-daemon.ts +3 -1
- package/src/home/this-house.ts +68 -0
- package/src/home/via-hub.ts +2 -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/hq/backup-targets.ts +58 -5
- package/src/hq/hq-local.ts +1 -1
- package/src/media-store/backup/bucket-target.ts +58 -0
- package/src/media-store/backup/target-send.ts +7 -4
- package/src/media-store/space.ts +2 -0
- 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 +40 -9
- 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 +11 -2
- package/src/review/thread-state.ts +9 -3
- package/src/scaffold/project-scaffold.ts +2 -2
- package/src/secrets/copy.ts +4 -4
- package/src/serve/hub-app/auto-text.tsx +3 -1
- 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-thread.tsx +2 -1
- package/src/serve/hub-app/review/review-views.tsx +10 -7
- package/src/serve/hub-app/review/thread-st.ts +25 -11
- package/src/serve/hub-app/review/tone-bar.tsx +29 -24
- package/src/serve/hub-app/review/tones.ts +18 -0
- package/src/serve/hub-app/review.css +11 -2
- package/src/setup-house.ts +1 -7
- package/src/shot/client.ts +2 -1
- package/src/shot/on-place.ts +141 -0
- package/src/start-repo.ts +27 -30
package/src/gate/job-run.ts
CHANGED
|
@@ -17,7 +17,8 @@ export async function runJob(root: string, id: string, kind: JobKind, job: JobOp
|
|
|
17
17
|
const onCheck = (e: CheckEvent): void => appendJobCheck(root, id, e)
|
|
18
18
|
if (kind === 'ci') {
|
|
19
19
|
const { runCi } = await import('./run-ci.ts')
|
|
20
|
-
|
|
20
|
+
// a detached gate someone asked for waits on a full machine like a foreground one; the plan's own never does
|
|
21
|
+
return await runCi(root, { ...job.opts, ...(job.turn === true ? {} : { admit: true }), print, onCheck })
|
|
21
22
|
}
|
|
22
23
|
const { runCheck } = await import('./run-check.ts')
|
|
23
24
|
return await runCheck(root, { ...job.opts, print, onCheck })
|
|
@@ -166,14 +166,17 @@ function answerOf(table: Table, files: readonly string[], stamp: (f: string) =>
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/** the files that run at commit, from the table and stats alone: null when only discovery can say (no walk yet, a
|
|
169
|
-
* file no row knows, a file whose stamp moved). A walk whose dirs moved is brought up to date and kept
|
|
170
|
-
|
|
169
|
+
* file no row knows, a file whose stamp moved). A walk whose dirs moved is brought up to date and kept. `staged`: the
|
|
170
|
+
* paths the commit stages; the dirs of the walk (hundreds of stats) are read only when one of them is a unit file,
|
|
171
|
+
* since a new unit file enters the gate with the commit that stages it. A known unit file is still stamped, and one
|
|
172
|
+
* gone answers null */
|
|
173
|
+
export async function preCommitFromTable(root: string, staged?: readonly string[]): Promise<string[] | null> {
|
|
171
174
|
const path = declarationsTable(root)
|
|
172
175
|
const table = readTable(path)
|
|
173
176
|
if (path == null || table.walk == null) return null
|
|
174
177
|
const builtins = builtinFiles(builtinsOf(root, BUILTIN_CHECK_DIR))
|
|
175
178
|
if (builtins == null) return null
|
|
176
|
-
const { walk, moved } = await freshWalk(root, table.walk)
|
|
179
|
+
const { walk, moved } = staged != null && !staged.some((p) => p.endsWith(UNIT_SUFFIX)) ? { walk: table.walk, moved: false } : await freshWalk(root, table.walk)
|
|
177
180
|
const run = answerOf(table, [...builtins, ...walk.units], stampOf)
|
|
178
181
|
if (run != null && moved) writeTable(path, { ...table, walk })
|
|
179
182
|
return run
|
package/src/gate/run-check.ts
CHANGED
|
@@ -29,6 +29,8 @@ import { CI_LOG_DIR } from '../core/layout.ts'
|
|
|
29
29
|
export type { CheckEvent } from './check-runner.ts'
|
|
30
30
|
|
|
31
31
|
export type CheckOpts = {
|
|
32
|
+
/** waits once, before the first heavy check that misses the cache (check-runner.ts) */
|
|
33
|
+
beforeHeavy?: (id: string) => Promise<void>
|
|
32
34
|
json?: boolean
|
|
33
35
|
fresh?: boolean
|
|
34
36
|
/** report-only for self-maintaining rules (SK005 never touches package.json) */
|
|
@@ -199,6 +201,7 @@ export async function runCheckPass(root: string, o: CheckOpts = {}): Promise<Che
|
|
|
199
201
|
childEnv: { [SHARE_ENV]: sharePath, ...(o.fresh === true ? { SHIPKIT_FRESH: '1' } : {}) },
|
|
200
202
|
bail: o.bail,
|
|
201
203
|
color: o.color,
|
|
204
|
+
...(o.beforeHeavy != null ? { beforeHeavy: o.beforeHeavy } : {}),
|
|
202
205
|
print: sink,
|
|
203
206
|
detail: o.detail,
|
|
204
207
|
onCheck: (e) => { collected.push(...e.lines); o.onCheck?.(e) },
|
package/src/gate/run-ci.ts
CHANGED
|
@@ -23,6 +23,9 @@ import { gateBinary } from '../ledger/toolchain-identity.ts'
|
|
|
23
23
|
import type { CheckResult } from './check-runner.ts'
|
|
24
24
|
|
|
25
25
|
export type CiOpts = {
|
|
26
|
+
/** a gate someone asked for (sk ci, --head): it waits on a full machine before its first heavy check that misses
|
|
27
|
+
* the cache (gate/admit-heavy.ts). Unset for a release and the plan's own gates, which never wait */
|
|
28
|
+
admit?: boolean
|
|
26
29
|
bail?: boolean
|
|
27
30
|
json?: boolean
|
|
28
31
|
skipGroups?: string[]
|
|
@@ -223,6 +226,7 @@ export async function runCi(root: string, o: CiOpts = {}): Promise<number> {
|
|
|
223
226
|
fresh: o.fresh,
|
|
224
227
|
color: o.color,
|
|
225
228
|
tier,
|
|
229
|
+
...(o.admit === true ? { beforeHeavy: async (id: string) => (await import('./admit-heavy.ts')).admitCheck(id, o.print ?? ((l) => console.log(l))) } : {}),
|
|
226
230
|
}
|
|
227
231
|
try {
|
|
228
232
|
ledger = Ledger.open(root, composed.map((g) => g.row.decl), {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// machine is red whatever else is green, and the headline is the cells': a cell not proven is never green
|
|
11
11
|
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
12
12
|
import { ageWords } from '../core/words.ts'
|
|
13
|
-
import type
|
|
13
|
+
import { configBucket, ownBucket, type BackupTarget } from '../hq/backup-targets.ts'
|
|
14
14
|
import { type Drill, healthWords, REPLICA_BEHIND_MS, replicaLag, type ReplicaHealth, type ReplicaPlace } from '../hq/replica.ts'
|
|
15
15
|
import type { TargetSent } from '../media-store/backup/target-send.ts'
|
|
16
16
|
import { timeMachineFacts, type TimeMachineFacts } from '../media-store/backup/facts.ts'
|
|
@@ -30,7 +30,7 @@ export type Place = { id: string; label: string; where: string; kind: 'mac' | 'd
|
|
|
30
30
|
export type StoreRow = { row: string; id: StoreId; machine: string; name: string; what: string; state: CellState; line: string; stale?: true }
|
|
31
31
|
/** `machine`: where the judgement was made (the hq's machine), `at` its time. `client`: set where a client drew it,
|
|
32
32
|
* read from the hq; `stale` says the hq did not answer and how old the table is: never green, never red then */
|
|
33
|
-
export type BackupStatus = { at: number; machine: string; places: Place[]; stores: StoreRow[]; cells: Cell[]; alarms: string[]; worst: CellState; client?: { machine: string; readAt: number }; stale?: string }
|
|
33
|
+
export type BackupStatus = { notSetUp?: true; at: number; machine: string; places: Place[]; stores: StoreRow[]; cells: Cell[]; alarms: string[]; worst: CellState; client?: { machine: string; readAt: number }; stale?: string }
|
|
34
34
|
|
|
35
35
|
/** the red cells that ring the band and the alarm: a store with no working copy rings too; another red cell (a copy
|
|
36
36
|
* behind while another works) is red in the matrix only */
|
|
@@ -59,6 +59,11 @@ export type BackupInputs = {
|
|
|
59
59
|
vaultNear: { count: number; newest: number | null }
|
|
60
60
|
timeMachine: TimeMachineFacts
|
|
61
61
|
secondPlaceKey: boolean | null
|
|
62
|
+
/** a vault runs on this machine, or ran: false is a keychain only machine, which has no vault to copy. Unsaid: true */
|
|
63
|
+
vault?: boolean
|
|
64
|
+
/** a target, a copy or a drill was ever kept here, or the config names a place: false is a machine where no backup
|
|
65
|
+
* was set up yet, which is said once and rings no band. Unsaid: true */
|
|
66
|
+
setUp?: boolean
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
const ago = (at: number, now: number): string => `${ageWords(at, now)}`
|
|
@@ -113,9 +118,9 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
113
118
|
const c = (state: CellState, short: string, text: string, proof: string | null = null, fix: string | null = null): Draft => ({ state, short, text, proof, fix })
|
|
114
119
|
const shortOf = (state: CellState, at: number): string => (state === 'danger' ? `${ago(at, now)}, stale` : ago(at, now))
|
|
115
120
|
const target = d.targets.find((x) => x.id === p.id)
|
|
116
|
-
const space = target
|
|
121
|
+
const space = target != null && configBucket(target.address) === 'mediaSpace'
|
|
117
122
|
// the Space is at its provider, on no disk of a machine: its one copy off it is the second place
|
|
118
|
-
if (store === 'space' && !(target
|
|
123
|
+
if (store === 'space' && !(target != null && configBucket(target.address) === 'spaceCopy')) return c('dim', space ? 'itself' : 'not here', space ? 'the Space itself, at its provider' : `the Space is not copied to ${p.label}: its copy off its provider is the second place`)
|
|
119
124
|
if (p.kind === 'mac') {
|
|
120
125
|
if (store === 'vault') return c('dim', 'live', `the live vault on ${machine}${d.vaultNear.count > 0 ? `, ${d.vaultNear.count} sealed snapshots beside it${d.vaultNear.newest == null ? '' : `, the newest ${ago(d.vaultNear.newest, now)}`}` : ''}`, 'the same disk: no help if it dies')
|
|
121
126
|
return c('dim', 'live', `the live hq.sqlite on ${machine}`, 'the same disk: no help if it dies')
|
|
@@ -142,8 +147,8 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
142
147
|
}
|
|
143
148
|
return stream === 'mediaSpace' ? streamCell(d) : notStreamed(stream)
|
|
144
149
|
}
|
|
145
|
-
const second = t.address
|
|
146
|
-
if (second && d.secondPlaceKey === false) return c('warn', 'no key yet', 'no key yet: nothing goes there', null, '
|
|
150
|
+
const second = configBucket(t.address) === 'spaceCopy'
|
|
151
|
+
if (second && d.secondPlaceKey === false) return c('warn', 'no key yet', 'no key yet: nothing goes there', null, 'store the two secrets that serve.spaceCopy.key names (sk secret set)')
|
|
147
152
|
if (second && store === 'hq' && stream === 'spaceCopy') return streamCell(d)
|
|
148
153
|
if (store === 'vault') return sentCell(d.get<TargetSent>(`target-sent:vault:${p.id}`), now, BOUNDS.vault, BOUNDS.vault + 2 * H, 'sk daemon job backup targets')
|
|
149
154
|
if (store === 'hq') return sentCell(d.get<TargetSent>(`target-sent:hq:${p.id}`), now, BOUNDS.hqCopy, BOUNDS.hqCopyDanger, 'sk daemon job backup targets')
|
|
@@ -152,7 +157,7 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
152
157
|
const proof = d.get<Proof>('space-copy-proof')
|
|
153
158
|
const copy = (x: Draft): Draft => ({ ...x, of: 'space copy' })
|
|
154
159
|
if (proof == null) return copy(d.get<boolean>('space-copy') === true ? c('warn', 'not yet', 'the first copy of the Space runs each night until it is whole: no proof yet', null, 'sk space') : c('warn', 'not yet', 'the Space is not copied there: the nightly copy is off', null, 'sk space copy --auto on'))
|
|
155
|
-
const first = d.targets.find((x) => x.address
|
|
160
|
+
const first = d.targets.find((x) => configBucket(x.address) === 'mediaSpace')?.label ?? 'the Space'
|
|
156
161
|
const of = `the nightly copy of ${first}`
|
|
157
162
|
if (!proof.ok) return copy(c('danger', 'proof FAILED', `${of} failed its proof ${ago(proof.at, now)}`, proof.why[0] ?? 'the proof failed', 'sk space proof'))
|
|
158
163
|
const age = now - proof.at
|
|
@@ -171,7 +176,11 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
171
176
|
return c('dim', 'not here', `nothing of ${store} goes to ${p.label}`)
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
const whereOf = (t: BackupTarget): string =>
|
|
179
|
+
const whereOf = (t: BackupTarget): string => {
|
|
180
|
+
const own = ownBucket(t.address)
|
|
181
|
+
if (own != null) return `the bucket ${own.bucket} at ${new URL(own.endpoint).host} (s3)`
|
|
182
|
+
return t.address.kind === 'ssh' ? `${t.address.host}:${t.address.folder}` : configBucket(t.address) === 'mediaSpace' ? 'the private Space (s3)' : 'the second place (s3)'
|
|
183
|
+
}
|
|
175
184
|
|
|
176
185
|
/** the table and its alarms: every cell, each row's verdict, every reason to be red */
|
|
177
186
|
export function backupStatus(d: BackupInputs): BackupStatus {
|
|
@@ -190,6 +199,7 @@ export function backupStatus(d: BackupInputs): BackupStatus {
|
|
|
190
199
|
const stores: StoreRow[] = []
|
|
191
200
|
const alarms: string[] = []
|
|
192
201
|
for (const s of STORES) {
|
|
202
|
+
if (s.id === 'vault' && d.vault === false) continue
|
|
193
203
|
const row = `${judge}/${s.id}`
|
|
194
204
|
const mine = places.map((p): Cell => {
|
|
195
205
|
// a record that does not read leaves its cell orange, never the whole table thrown
|
|
@@ -209,15 +219,30 @@ export function backupStatus(d: BackupInputs): BackupStatus {
|
|
|
209
219
|
// the Space is its provider's: its second copy missing is orange, a broken one red, never « no copy »
|
|
210
220
|
const none = good.length === 0 && s.id !== 'space'
|
|
211
221
|
// a copy there but not proven (never restored, behind) is said as such: the fix differs from a copy gone
|
|
212
|
-
if (none) alarms.unshift(off.some((c) => c.state === 'warn') ? `${label}: NO proven copy off ${judge}` : `${label}: NO working copy off ${judge}`)
|
|
222
|
+
if (none && d.setUp !== false) alarms.unshift(off.some((c) => c.state === 'warn') ? `${label}: NO proven copy off ${judge}` : `${label}: NO working copy off ${judge}`)
|
|
213
223
|
for (const c of off.filter((x) => x.state === 'danger' && BROKEN.has(x.short))) alarms.push(`${label} on ${places.find((p) => p.id === c.place)!.label}: ${c.text}`)
|
|
214
|
-
const state: CellState = none ? 'danger' : off.some((c) => c.state === 'danger') ? 'danger' : off.some((c) => c.state === 'warn') || good.length === 0 ? 'warn' : 'ok'
|
|
224
|
+
const state: CellState = none && d.setUp === false ? 'warn' : none ? 'danger' : off.some((c) => c.state === 'danger') ? 'danger' : off.some((c) => c.state === 'warn') || good.length === 0 ? 'warn' : 'ok'
|
|
215
225
|
stores.push({ row, id: s.id, machine: judge, name: s.name, what: s.what, state, line: `${good.length} of ${off.length} copies off ${judge} work` })
|
|
216
226
|
}
|
|
217
227
|
// the headline is the cells': a cell not proven (unknown, never drilled, behind) keeps it from green
|
|
218
228
|
const unproven = cells.some((c) => c.state === 'warn' || c.state === 'danger') || stores.some((r) => r.state !== 'ok')
|
|
219
229
|
const worst: CellState = alarms.length > 0 ? 'danger' : unproven ? 'warn' : 'ok'
|
|
220
|
-
return { at: d.now, machine: judge, places, stores, cells, alarms, worst }
|
|
230
|
+
return { ...(d.setUp === false ? { notSetUp: true as const } : {}), at: d.now, machine: judge, places, stores, cells, alarms, worst }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** whether the house config names a place for backups, or does not load: only a config read and empty says none was
|
|
234
|
+
* ever set up */
|
|
235
|
+
async function namesPlace(): Promise<boolean> {
|
|
236
|
+
try {
|
|
237
|
+
const { houseRootOf } = await import('./home-start.ts')
|
|
238
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
239
|
+
const house = houseRootOf(process.cwd())
|
|
240
|
+
if (house == null) return true
|
|
241
|
+
const s = (await loadRepoConfig(house)).serve
|
|
242
|
+
return s?.mediaSpace != null || s?.spaceCopy != null || s?.hqReplica != null
|
|
243
|
+
} catch {
|
|
244
|
+
return true
|
|
245
|
+
}
|
|
221
246
|
}
|
|
222
247
|
|
|
223
248
|
/** every input, read on the machine that carries the hq: the targets of its hq, the kept records, Litestream's files,
|
|
@@ -254,7 +279,8 @@ export async function readBackupInputs(now = Date.now()): Promise<BackupInputs>
|
|
|
254
279
|
} catch {
|
|
255
280
|
count = 0
|
|
256
281
|
}
|
|
257
|
-
const
|
|
282
|
+
const copyId = targets.find((t) => configBucket(t.address) === 'spaceCopy')?.id
|
|
283
|
+
const second = copyId == null ? null : machineGet<TargetSent>(`target-sent:vault:${copyId}`)
|
|
258
284
|
return {
|
|
259
285
|
now,
|
|
260
286
|
machine,
|
|
@@ -264,6 +290,8 @@ export async function readBackupInputs(now = Date.now()): Promise<BackupInputs>
|
|
|
264
290
|
vaultNear: { count, newest },
|
|
265
291
|
timeMachine: await timeMachineFacts(now),
|
|
266
292
|
secondPlaceKey: second == null ? null : !('failed' in second && second.failed.startsWith('no key yet')),
|
|
293
|
+
vault: (await import('../secrets/read.ts')).vaultHere() || count > 0 || machineGet('vault-snapshot-sent') != null,
|
|
294
|
+
setUp: targets.length > 0 || folder != null || machineGet('vault-snapshot-sent') != null || machineGet('hq-drill') != null || (await namesPlace()),
|
|
267
295
|
}
|
|
268
296
|
}
|
|
269
297
|
|
|
@@ -295,7 +323,7 @@ export const alarmKeys = (s: BackupStatus): string[] =>
|
|
|
295
323
|
s.stale != null
|
|
296
324
|
? []
|
|
297
325
|
: [
|
|
298
|
-
...s.stores.filter((r) => r.stale !== true && r.id !== 'space' && !s.cells.some((c) => c.row === r.row && c.state === 'ok' && c.off)).map((r) => `${r.row}:none`),
|
|
326
|
+
...s.stores.filter((r) => s.notSetUp !== true && r.stale !== true && r.id !== 'space' && !s.cells.some((c) => c.row === r.row && c.state === 'ok' && c.off)).map((r) => `${r.row}:none`),
|
|
299
327
|
...s.cells.filter((c) => c.state === 'danger' && BROKEN.has(c.short) && c.off && s.stores.find((r) => r.row === c.row)?.stale !== true).map((c) => `${c.row}@${c.place}`),
|
|
300
328
|
]
|
|
301
329
|
|
|
@@ -7,6 +7,7 @@ export const rowName = (r: Pick<StoreRow, 'name'>): string => r.name
|
|
|
7
7
|
|
|
8
8
|
export function verdictWords(s: BackupStatus): string {
|
|
9
9
|
if (s.stale != null) return `not read: ${s.stale}`
|
|
10
|
+
if (s.notSetUp === true) return 'no backup is set up yet: what this machine keeps is on its own disk alone'
|
|
10
11
|
if (s.worst === 'danger') return 'a backup is NOT working'
|
|
11
12
|
if (s.worst === 'warn') return 'not every copy is fresh and proven: the orange lines say what to fix'
|
|
12
13
|
return 'every copy is fresh and proven'
|
package/src/home/daemon-jobs.ts
CHANGED
|
@@ -67,6 +67,11 @@ async function targetsJob(now: number): Promise<string[]> {
|
|
|
67
67
|
if ('why' in ends) return { why: `no key yet: ${ends.why}` }
|
|
68
68
|
return { put: async (key, bytes) => void (await putStream(ends.to, key, new Blob([bytes.slice()]).stream(), { max: bytes.length })) }
|
|
69
69
|
},
|
|
70
|
+
bucket: async (a) => {
|
|
71
|
+
const [{ bucketPut }, { houseBucket }] = await Promise.all([import('../media-store/backup/bucket-target.ts'), import('./house-bucket.ts')])
|
|
72
|
+
const c = await houseBucket(a)
|
|
73
|
+
return 'why' in c ? c : { put: (key, bytes) => bucketPut(c, key, bytes) }
|
|
74
|
+
},
|
|
70
75
|
},
|
|
71
76
|
})
|
|
72
77
|
}
|
package/src/home/home-routes.ts
CHANGED
|
@@ -161,12 +161,13 @@ export const projectsOrder = (rows: readonly Pick<ProjectRow, 'name' | 'activity
|
|
|
161
161
|
[...rows].sort((x, y) => (y.activity ?? -Infinity) - (x.activity ?? -Infinity) || x.name.localeCompare(y.name)).map((p) => p.name).join(',')
|
|
162
162
|
|
|
163
163
|
/** the house's backup targets the first time: the buckets its config names */
|
|
164
|
-
async function targetSeed(): Promise<
|
|
164
|
+
async function targetSeed(): Promise<import('../hq/backup-targets.ts').SeedFrom> {
|
|
165
165
|
const { houseRootOf } = await import('./home-start.ts')
|
|
166
166
|
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
167
167
|
const house = houseRootOf(process.cwd())
|
|
168
168
|
const serve = house == null ? undefined : (await loadRepoConfig(house).catch(() => null))?.serve
|
|
169
|
-
|
|
169
|
+
const of = (b: { endpoint?: string; region: string } | undefined) => (b == null ? null : { region: b.region, ...(b.endpoint == null ? {} : { endpoint: b.endpoint }) })
|
|
170
|
+
return { mediaSpace: of(serve?.mediaSpace), spaceCopy: of(serve?.spaceCopy) }
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
export function homeRoutes(d: HomeDeps) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// a bucket added by hand (media-store/backup/bucket-target.ts) with its key read on this machine: through the house's
|
|
2
|
+
// own secret manager where it declares one, else the house store
|
|
3
|
+
import type { BucketAddress } from '../hq/backup-targets.ts'
|
|
4
|
+
import { bucketConfig } from '../media-store/backup/bucket-target.ts'
|
|
5
|
+
import type { SpaceConfig } from '../media-store/space.ts'
|
|
6
|
+
import { loadRepoConfig } from '../repo-config.ts'
|
|
7
|
+
import { readThrough } from '../secrets/read.ts'
|
|
8
|
+
import { houseRootOf } from './home-start.ts'
|
|
9
|
+
|
|
10
|
+
export async function houseBucket(a: BucketAddress): Promise<SpaceConfig | { why: string }> {
|
|
11
|
+
const house = houseRootOf(process.cwd())
|
|
12
|
+
const template = house == null ? undefined : (await loadRepoConfig(house).catch(() => null))?.credsReadCommand
|
|
13
|
+
return bucketConfig(a, (name) => readThrough(template, name))
|
|
14
|
+
}
|
package/src/home/run-daemon.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// it runs with no bun watch and an edit of its own code restarts it in place
|
|
7
7
|
// at once (lib-watch.ts): the new image follows the jobs still running. The
|
|
8
8
|
// machine resources are pm's.
|
|
9
|
+
import { topUserWatch } from '../core/admission.ts'
|
|
10
|
+
import { readWho } from '../gate/admit-heavy.ts'
|
|
9
11
|
import { loopWatch } from '../core/loop-watch.ts'
|
|
10
12
|
import { MemoryWatch } from '../core/memory-watch.ts'
|
|
11
13
|
import { fileURLToPath } from 'url'
|
|
@@ -120,7 +122,7 @@ export async function runDaemon(root: string, io: HomeIo, o: { port?: number } =
|
|
|
120
122
|
const dir = homeDir()
|
|
121
123
|
// the machine's one plan: every repo and check pair, ticked by the daemon.
|
|
122
124
|
// Its catch up window lives in the machine db, so a restart in place keeps it
|
|
123
|
-
const plan = new Planner({ catchUp: machineCatchUp, onError: (repo, e) => io.printErr(`WARN the plan of ${repo} broke: ${e.message}`) })
|
|
125
|
+
const plan = new Planner({ catchUp: machineCatchUp, who: topUserWatch(readWho), onError: (repo, e) => io.printErr(`WARN the plan of ${repo} broke: ${e.message}`) })
|
|
124
126
|
// a repo's colour counts only the checks its plan holds today
|
|
125
127
|
// a page asked of a repo's own app: said on the pages' stream, which exists once the daemon serves
|
|
126
128
|
let askedPage: (repo: string) => void = () => {}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// which house this machine runs, seen from any folder: what `sk start` writes as line 1 of a new repo's CLAUDE.md, and
|
|
2
|
+
// where the house's `start.skip` is read. No house is named in this file: it ships on npm
|
|
3
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'fs'
|
|
4
|
+
import { homedir } from 'os'
|
|
5
|
+
import { dirname, join, relative, resolve, sep } from 'path'
|
|
6
|
+
import { homeRepo } from '../house/project-gutter.ts'
|
|
7
|
+
import { HOUSE_WIKI_INDEX, STARTER_MARK } from '../scaffold/starter-house.ts'
|
|
8
|
+
import { installedHouseRoot, plistPath } from './home-launchd.ts'
|
|
9
|
+
|
|
10
|
+
const inside = (p: string, root: string): boolean => p === root || p.startsWith(`${root}${sep}`)
|
|
11
|
+
const hosts = (dir: string): boolean => existsSync(join(dir, HOUSE_WIKI_INDEX)) && existsSync(join(dir, 'repo.config.ts'))
|
|
12
|
+
|
|
13
|
+
/** a house that `sk setup` made, whose owner chose no policy for their agents yet */
|
|
14
|
+
export function isStarterHouse(dir: string): boolean {
|
|
15
|
+
try {
|
|
16
|
+
return readFileSync(join(dir, 'README.md'), 'utf8').includes(STARTER_MARK)
|
|
17
|
+
} catch {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** the one house that `sk setup` made among the folders of `root`, null with none or several: none is guessed */
|
|
23
|
+
function starterHouseIn(root: string): string | null {
|
|
24
|
+
let names: string[]
|
|
25
|
+
try {
|
|
26
|
+
names = readdirSync(root)
|
|
27
|
+
} catch {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
const made = names.map((n) => join(root, n)).filter((d) => hosts(d) && isStarterHouse(d))
|
|
31
|
+
return made.length === 1 ? made[0]! : null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type HouseLookup = {
|
|
35
|
+
home?: string
|
|
36
|
+
/** the folder the repos sit in, where a starter house is looked for */
|
|
37
|
+
root?: string
|
|
38
|
+
/** the checkout this lib runs from, a house when shipkit is developed in one. Injected by tests */
|
|
39
|
+
lib?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the house root of this machine: the one its pm runs from, else the checkout this lib runs from, else the one
|
|
43
|
+
* `sk setup` made beside the repos. The lib's checkout counts only under this home: a scratch home is another machine */
|
|
44
|
+
export function thisHouse(o: HouseLookup = {}): string | null {
|
|
45
|
+
const home = o.home ?? homedir()
|
|
46
|
+
const pm = installedHouseRoot(plistPath(home))
|
|
47
|
+
if (pm != null && hosts(pm)) return pm
|
|
48
|
+
const lib = homeRepo(resolve(o.lib ?? join(import.meta.dir, '../../../..')))
|
|
49
|
+
if (hosts(lib) && inside(lib, resolve(home))) return lib
|
|
50
|
+
return starterHouseIn(o.root ?? join(home, 'dev'))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** the folder a new repo goes in: the house's own, since a house finds its repos among its siblings, else ~/dev */
|
|
54
|
+
export const reposRoot = (house: string | null, home: string): string => (house != null ? dirname(house) : join(home, 'dev'))
|
|
55
|
+
|
|
56
|
+
/** the line 1 a wired repo's CLAUDE.md carries: the house index, `~/` relative when it sits under the home */
|
|
57
|
+
export function houseLine(house: string, home: string): string {
|
|
58
|
+
const index = join(house, HOUSE_WIKI_INDEX)
|
|
59
|
+
const real = (p: string): string => {
|
|
60
|
+
try {
|
|
61
|
+
return realpathSync(p)
|
|
62
|
+
} catch {
|
|
63
|
+
return resolve(p)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// a home behind a symlink (/var → /private/var) would expand `~/` to another spelling of the path
|
|
67
|
+
return inside(index, home) && real(home) === home ? `@~/${relative(home, index)}` : `@${index}`
|
|
68
|
+
}
|
package/src/home/via-hub.ts
CHANGED
|
@@ -20,10 +20,11 @@ import { TRACE_ENV } from '../trace/tracer.ts'
|
|
|
20
20
|
import { FRESH_ENV } from '../ledger/store.ts'
|
|
21
21
|
import { LEDGER_ENV } from '../ledger/ledger.ts'
|
|
22
22
|
import { PARALLEL_ENV } from '../core/parallel.ts'
|
|
23
|
+
import { SUITE_SELECT_ENV } from '../suite/reads-env.ts'
|
|
23
24
|
|
|
24
25
|
/** the env switches a gate reads, which a terminal may set for one run: the
|
|
25
26
|
* job the home starts runs with the daemon's env, so they travel with it */
|
|
26
|
-
export const FORWARDED_ENV = [TRACE_ENV, FRESH_ENV, LEDGER_ENV, PARALLEL_ENV] as const
|
|
27
|
+
export const FORWARDED_ENV = [TRACE_ENV, FRESH_ENV, LEDGER_ENV, PARALLEL_ENV, SUITE_SELECT_ENV] as const
|
|
27
28
|
|
|
28
29
|
/** the forwarded switches this env sets */
|
|
29
30
|
export const forwardedEnv = (env: Env = process.env): Record<string, string> =>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// the commit-msg gate: the shared message predicate, the leak guard on the message, the reflection trailers, then the
|
|
2
|
+
// repo's own. Apart from the pre-commit gates (hooks/commit-run.ts), so the commit-msg hook loads only these.
|
|
3
|
+
// the one constraint a reader breaks first: the hook has 20 ms from bun's start (hooks/hook-gates.ts)
|
|
4
|
+
import { readFileSync } from 'fs'
|
|
5
|
+
import { commitMessageOffenses, stripNonMessage } from './commit-message.ts'
|
|
6
|
+
import { runLeakGuard } from './leak-guard.ts'
|
|
7
|
+
import { hookGateOff } from './hook-gates.ts'
|
|
8
|
+
import { commandGate, hitLine, moduleGate, startTimes, timeRow, waivedLines, type GateOutcome, type Timed } from './gate-outcome.ts'
|
|
9
|
+
import type { HookConfig } from './hook-config.ts'
|
|
10
|
+
|
|
11
|
+
/** what a repo's commit-msg module gate is given */
|
|
12
|
+
export type CommitMsgCtx = { root: string; message: string; messageFile: string; config: HookConfig }
|
|
13
|
+
|
|
14
|
+
export async function runCommitMsgWith(root: string, config: HookConfig, messageFile: string, o: { since?: number; before?: Timed[] } = {}): Promise<GateOutcome[]> {
|
|
15
|
+
const since = o.since ?? performance.now()
|
|
16
|
+
const times = startTimes(since, o.before)
|
|
17
|
+
const h = config.hooks ?? {}
|
|
18
|
+
const out: GateOutcome[] = []
|
|
19
|
+
const message = readFileSync(messageFile, 'utf8')
|
|
20
|
+
if (hookGateOff(config, 'commit-message') == null) {
|
|
21
|
+
const languageOff = hookGateOff(config, 'commit-language') != null
|
|
22
|
+
const offenses = commitMessageOffenses(message, { languageAllow: h.languageAllow })
|
|
23
|
+
.filter((o) => o.kind !== 'language' || !languageOff)
|
|
24
|
+
out.push(offenses.length === 0
|
|
25
|
+
? { id: 'commit-message', ok: true, lines: [`ok: commit message clean (no dash punctuation${languageOff ? '' : ', English'})`] }
|
|
26
|
+
: {
|
|
27
|
+
id: 'commit-message',
|
|
28
|
+
ok: false,
|
|
29
|
+
lines: [
|
|
30
|
+
`FAIL: commit message has ${offenses.length} offense(s)`,
|
|
31
|
+
...offenses.map((o) => ` line ${o.line}: ${o.text.slice(0, 100)}\n ${o.why}`),
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
// the leak guard also reads the MESSAGE, a private name pasted into a
|
|
36
|
+
// commit body is as public as one pasted into a file
|
|
37
|
+
if (hookGateOff(config, 'leak-guard') == null) {
|
|
38
|
+
const r = runLeakGuard(root, { keywordFile: h.keywordFile, staged: false, allow: h.leakAllow, text: [{ label: 'commit message', content: message }] })
|
|
39
|
+
if (r.status === 'hit')
|
|
40
|
+
out.push({ id: 'leak-guard', ok: false, lines: [`FAIL: leak-guard matched in the commit message`, ...r.hits.map(hitLine), ...waivedLines(r.waived)] })
|
|
41
|
+
else if (r.status === 'clean' && r.waived.length > 0)
|
|
42
|
+
out.push({ id: 'leak-guard', ok: true, lines: [`ok: leak-guard clean in the commit message (${r.waived.length} waived)`, ...waivedLines(r.waived)] })
|
|
43
|
+
}
|
|
44
|
+
if (hookGateOff(config, 'reflection-trailer') == null && /^(Fixes|Declines)-reflection:/im.test(message)) {
|
|
45
|
+
const t = performance.now()
|
|
46
|
+
const { machinePlaces, trailerErrors } = await import('../reflections/reflection-close.ts')
|
|
47
|
+
const places = await machinePlaces(root)
|
|
48
|
+
const errors = places === null ? ['no house repo on this machine: a reflection closes where its house is'] : trailerErrors(stripNonMessage(message), places)
|
|
49
|
+
out.push(errors.length === 0
|
|
50
|
+
? { id: 'reflection-trailer', ok: true, lines: ['ok: reflection trailers name open reflections'] }
|
|
51
|
+
: { id: 'reflection-trailer', ok: false, lines: [`FAIL: reflection-trailer: ${errors.length} trailer(s) name no open reflection`, ...errors.map((e) => ` ${e}`)] })
|
|
52
|
+
times.push({ id: 'reflection-trailer', ms: performance.now() - t })
|
|
53
|
+
}
|
|
54
|
+
for (const g of h.commitMsg ?? []) {
|
|
55
|
+
const t = performance.now()
|
|
56
|
+
out.push('module' in g ? await moduleGate<CommitMsgCtx>(root, g, 'commitMsg', { root, message, messageFile, config }) : await commandGate(root, g, [messageFile], 60_000))
|
|
57
|
+
times.push({ id: g.id, ms: performance.now() - t, owner: 'repo' })
|
|
58
|
+
}
|
|
59
|
+
out.push(timeRow('commit-msg', performance.now() - since, times))
|
|
60
|
+
return out
|
|
61
|
+
}
|