rvlib-shipkit 2.24.0 → 2.26.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 +33 -0
- package/package.json +2 -2
- package/src/agent-time/hooks.ts +329 -0
- package/src/agent-time/live.ts +153 -0
- package/src/agent-time/render.ts +14 -2
- package/src/agent-time/report.ts +56 -4
- package/src/agent-time/store.ts +59 -5
- package/src/annex/offload.ts +16 -7
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +32 -11
- package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +1 -1
- package/src/checks/SK045-slow-hooks.check.ts +47 -0
- package/src/checks/SK046-hook-records.check.ts +76 -0
- package/src/cli/cmd_Annex.ts +12 -7
- package/src/cli/cmd_Assets.ts +5 -5
- package/src/cli/cmd_Backup.ts +14 -6
- package/src/cli/cmd_Capacity.ts +10 -6
- package/src/cli/cmd_Checks.ts +12 -1
- package/src/cli/cmd_Ci.ts +2 -2
- package/src/cli/cmd_Commands.ts +11 -2
- package/src/cli/cmd_ConfigKeys.ts +17 -0
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Keys.ts +4 -1
- package/src/cli/cmd_Lanes.ts +35 -0
- package/src/cli/cmd_Mv.ts +6 -7
- package/src/cli/cmd_Rec.ts +22 -7
- package/src/cli/cmd_Releases.ts +30 -0
- package/src/cli/cmd_Review.ts +130 -43
- package/src/cli/cmd_Shot.ts +15 -4
- package/src/cli/cmd_Status.ts +6 -5
- package/src/cli/cmd_Time.ts +18 -6
- package/src/cli/cmd_Veille.ts +10 -6
- package/src/cli/family-help.ts +136 -0
- package/src/cli/family-pages.ts +0 -19
- package/src/cli/kit/calls.ts +35 -0
- package/src/cli/kit/project-cli.ts +2 -12
- package/src/cli/registry.ts +41 -7
- package/src/cli.ts +8 -4
- package/src/commands/runner.ts +5 -1
- package/src/core/capacity.ts +89 -33
- package/src/core/check-runner.ts +5 -1
- package/src/core/floor-resolve.ts +6 -2
- package/src/core/floor.ts +6 -2
- package/src/core/history-files.ts +22 -0
- package/src/core/jobs.ts +35 -16
- package/src/core/layout.ts +2 -2
- package/src/core/nearest.ts +16 -0
- package/src/core/remove-tree.ts +19 -0
- package/src/core/runs.ts +12 -3
- package/src/core/signal-name.ts +6 -0
- package/src/core/throwaway-worktree.ts +22 -4
- package/src/core/trace-audit.ts +22 -4
- package/src/core/transient.ts +6 -0
- package/src/drill/run.ts +1 -1
- package/src/home/daemon-jobs.ts +41 -4
- package/src/home/machine-temp.ts +2 -10
- package/src/ledger/gate-checks.ts +26 -4
- package/src/ledger/git-key.ts +25 -4
- package/src/ledger/git-scan.ts +59 -7
- package/src/media-store/backup/daemon.ts +103 -20
- package/src/media-store/backup/run.ts +21 -15
- package/src/media-store/backup/sources.ts +163 -21
- package/src/media-store/backup/watch.ts +106 -0
- package/src/media-store/daemon.ts +36 -8
- package/src/media-store/hand.ts +3 -1
- package/src/mv/mv-md.ts +50 -18
- package/src/pb/run-pb.ts +2 -10
- package/src/plan/repo-source.ts +25 -14
- package/src/recordings/model.ts +1 -1
- package/src/reflect/transcript.ts +21 -3
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +12 -4
- package/src/releases/model.ts +18 -0
- package/src/releases/store.ts +13 -1
- package/src/repo-config.ts +11 -1
- package/src/review/cells.ts +2 -1
- package/src/review/format.ts +1 -1
- package/src/review/inbox-hook.ts +35 -0
- package/src/review/model.ts +26 -7
- package/src/review/store.ts +15 -7
- package/src/review/trailer-model.ts +2 -2
- package/src/shot/client.ts +4 -2
- package/src/shot/serve-shot.ts +71 -2
- package/src/shot/shooter.ts +65 -11
- package/src/shot/shot-ask.ts +32 -9
- package/src/suite/judge-suites.ts +77 -10
- package/src/suite/select.ts +13 -2
- package/src/suite/suite-cli.ts +72 -31
- package/src/suite/test-units.ts +31 -12
- package/src/trailer/graph.ts +2 -1
- package/src/ts/config.ts +12 -35
- package/src/ts/rename.ts +31 -17
- package/src/ts/workspaces.ts +45 -0
- package/src/wiki/run-wiki.ts +8 -2
- package/src/wiki/scan-md.ts +42 -1
package/src/agent-time/report.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { type PromptEntry, dedupePrompts } from '../reflect/prompt-corpus.ts'
|
|
|
9
9
|
import type { Outcome } from '../reflect/transcript.ts'
|
|
10
10
|
import type { Masker } from './mask.ts'
|
|
11
11
|
import { type Signal, signalsOf } from './signals.ts'
|
|
12
|
-
import type { FileRow, Loaded } from './store.ts'
|
|
12
|
+
import type { FileRow, HookRun, Loaded } from './store.ts'
|
|
13
|
+
import { cadenceOf, matcherMatches } from './hooks.ts'
|
|
13
14
|
import { type ReadCost, type TurnStats, addTurns, emptyTurns, turnsOf } from './turns.ts'
|
|
14
15
|
import { type Breakdown, type Call, type Mark, type Stream, FAILED, IDLE_MS, addBreakdown, callMs, type Closed, closeCalls, emptyBreakdown, quantileSorted, ranBefore, retries, runMs, wallBreakdown } from './timeline.ts'
|
|
15
16
|
|
|
@@ -61,9 +62,57 @@ export type TimeReport = {
|
|
|
61
62
|
turns: TurnReport
|
|
62
63
|
/** the measured waste, biggest first: each with the number behind it */
|
|
63
64
|
insights: Insight[]
|
|
65
|
+
hooks: HookRow[]
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
/** one hook command on one event, from the runs the harness timed (only the
|
|
69
|
+
* runs that printed). `calls`: the tool calls it applies to between its
|
|
70
|
+
* first and its last recorded run, by its declared matcher, else by the tools it was recorded
|
|
71
|
+
* on (`byMatcher` false); null on a turn event */
|
|
72
|
+
export type HookRow = { event: string; command: string; tools: string[]; runs: number; mean: number; p50: number; p90: number; max: number; total: number; errors: number; first: number; calls: number | null; byMatcher: boolean; placed: boolean }
|
|
73
|
+
|
|
74
|
+
/** some harness versions name a hook by its place in the settings (`command
|
|
75
|
+
* hook 2`), never its command: the place shifts as entries are added or
|
|
76
|
+
* differ per account, so those runs cannot be tied to a command */
|
|
77
|
+
export const PLACED = /^command hook \d+$/
|
|
78
|
+
|
|
79
|
+
/** key of a declared hook's matcher, by its event and command */
|
|
80
|
+
export const hookMatcherKey = (event: string, command: string): string => `${event}\u0000${command}`
|
|
81
|
+
|
|
82
|
+
export function hookRowsOf(runs: HookRun[], calls: { tool: string; start: number; end: number | null }[], matchers: Map<string, string>, mask: Masker): HookRow[] {
|
|
83
|
+
const by = new Map<string, HookRun[]>()
|
|
84
|
+
for (const r of runs) pushTo(by, hookMatcherKey(r.event, r.command), r)
|
|
85
|
+
return [...by.values()].map((rs): HookRow => {
|
|
86
|
+
const first = rs[0] as HookRun
|
|
87
|
+
const ms = rs.map((r) => r.ms).sort((a, b) => a - b)
|
|
88
|
+
const tools = [...new Set(rs.map((r) => r.tool).filter((t) => t !== ''))].sort()
|
|
89
|
+
const matcher = matchers.get(hookMatcherKey(first.event, first.command)) ?? null
|
|
90
|
+
const start = Math.min(...rs.map((r) => r.at))
|
|
91
|
+
const last = Math.max(...rs.map((r) => r.at))
|
|
92
|
+
const applies = (tool: string): boolean => (matcher != null ? matcherMatches(matcher, tool) : tools.includes(tool))
|
|
93
|
+
const n = cadenceOf(first.event) === 'call' ? calls.filter((c) => (c.end ?? c.start) >= start && c.start <= last && applies(c.tool)).length : null
|
|
94
|
+
const total = ms.reduce((a, b) => a + b, 0)
|
|
95
|
+
return { event: first.event, command: mask(first.command), tools, runs: ms.length, mean: total / ms.length, p50: quantileSorted(ms, 0.5), p90: quantileSorted(ms, 0.9), max: ms[ms.length - 1] ?? 0, total, errors: rs.filter((r) => r.error).length, first: start, calls: n, byMatcher: matcher != null, placed: PLACED.test(first.command) }
|
|
96
|
+
}).sort((a, b) => hookCost(b) - hookCost(a))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** an estimate of what a hook cost: the mean of its timed runs times the
|
|
100
|
+
* calls it applies to. It errs high where the hook returns early on calls
|
|
101
|
+
* that left no record (a silent run is never timed), low where it is slow
|
|
102
|
+
* and silent; never less than what was recorded */
|
|
103
|
+
export const hookCost = (h: HookRow): number => Math.max(h.total, h.calls == null ? 0 : h.mean * h.calls)
|
|
104
|
+
|
|
105
|
+
/** hook time is material past a minute recorded or five estimated */
|
|
106
|
+
export function hookInsight(rows: HookRow[]): Insight | null {
|
|
107
|
+
const top = rows[0]
|
|
108
|
+
if (top == null) return null
|
|
109
|
+
const est = top.calls == null ? 0 : top.mean * top.calls
|
|
110
|
+
if (top.total < 60_000 && est < 300_000) return null
|
|
111
|
+
const on = top.calls == null ? '' : `; it applies to ${top.calls.toLocaleString('en-US')} calls${top.byMatcher ? '' : ' (by the tools it was recorded on)'}, ~${fmt(est)} at the mean of its timed runs (an estimate: high where it returns early without a record)`
|
|
112
|
+
return { id: 'hooks', ms: Math.max(top.total, est), estimate: est > top.total, text: `the hook ${top.command.slice(0, 60)} on ${top.event}: ${top.runs.toLocaleString('en-US')} timed runs recorded, median ${fmt(top.p50)}, ${fmt(top.total)} in all${on} (sk time hooks)` }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type Insight = { id: 'classifier' | 'bash-edits' | 'polling' | 'failed' | 'approval' | 'background' | 'hooks'; ms: number; estimate: boolean; text: string }
|
|
67
116
|
|
|
68
117
|
/** commands that cost nothing to run: their time is the harness around them */
|
|
69
118
|
const CHEAP = new Set(['grep', 'sed', 'cat', 'ls', 'head', 'tail', 'wc', 'git status', 'echo', 'pwd', 'rg'])
|
|
@@ -208,7 +257,7 @@ function rowsBy(calls: { c: Closed; key: string }[], retriesByKey: Map<string, {
|
|
|
208
257
|
}).sort((a, b) => b.ms - a.ms || b.calls - a.calls)
|
|
209
258
|
}
|
|
210
259
|
|
|
211
|
-
export function buildReport(loaded: Loaded, q: { repos: string[]; from: number | null; to: number; repoOf: (project: string) => string }, mask: Masker): TimeReport {
|
|
260
|
+
export function buildReport(loaded: Loaded, q: { repos: string[]; from: number | null; to: number; repoOf: (project: string) => string; hookMatchers?: Map<string, string> }, mask: Masker): TimeReport {
|
|
212
261
|
const from = q.from ?? -Infinity
|
|
213
262
|
const groups = mergeStreams(loaded)
|
|
214
263
|
const accounts = new Set<string>()
|
|
@@ -319,6 +368,8 @@ export function buildReport(loaded: Loaded, q: { repos: string[]; from: number |
|
|
|
319
368
|
const queued = kept.filter((p) => p.origin === 'queued').length
|
|
320
369
|
|
|
321
370
|
const mains = groups.filter((g) => g.agent === '')
|
|
371
|
+
const hooks = hookRowsOf(loaded.hooks, all.map(({ c }) => c), q.hookMatchers ?? new Map(), mask)
|
|
372
|
+
const hookLine = hookInsight(hooks)
|
|
322
373
|
return {
|
|
323
374
|
repos: q.repos,
|
|
324
375
|
from: q.from,
|
|
@@ -342,7 +393,8 @@ export function buildReport(loaded: Loaded, q: { repos: string[]; from: number |
|
|
|
342
393
|
rows: topBy(turnRows, 200, (r) => r.work),
|
|
343
394
|
reads: [...readCosts.values()].sort((a, b) => b.model - a.model),
|
|
344
395
|
},
|
|
345
|
-
insights: insightsOf(all.map(({ c }) => c), wall, shapes),
|
|
396
|
+
insights: [...insightsOf(all.map(({ c }) => c), wall, shapes), ...(hookLine == null ? [] : [hookLine])].sort((a, b) => b.ms - a.ms),
|
|
397
|
+
hooks,
|
|
346
398
|
}
|
|
347
399
|
}
|
|
348
400
|
|
package/src/agent-time/store.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type { Call, Mark } from './timeline.ts'
|
|
|
27
27
|
export const AGENT_TIME_DB_ENV = 'SHIPKIT_AGENT_TIME_DB'
|
|
28
28
|
|
|
29
29
|
/** bumped when what a row holds changes: every file is read again */
|
|
30
|
-
export const INDEX_VERSION =
|
|
30
|
+
export const INDEX_VERSION = 9
|
|
31
31
|
|
|
32
32
|
export function agentTimeDbPath(): string {
|
|
33
33
|
const env = process.env[AGENT_TIME_DB_ENV]
|
|
@@ -83,6 +83,19 @@ create table if not exists prompts (
|
|
|
83
83
|
);
|
|
84
84
|
create index if not exists prompts_file on prompts (file_id, at);
|
|
85
85
|
create table if not exists meta (key text primary key, value text not null);
|
|
86
|
+
create table if not exists hooks (
|
|
87
|
+
file_id integer not null,
|
|
88
|
+
id text not null,
|
|
89
|
+
at integer not null,
|
|
90
|
+
event text not null,
|
|
91
|
+
tool text not null,
|
|
92
|
+
command text not null,
|
|
93
|
+
ms integer not null,
|
|
94
|
+
code integer,
|
|
95
|
+
error integer not null default 0
|
|
96
|
+
);
|
|
97
|
+
create unique index if not exists hooks_run on hooks (id, event, command);
|
|
98
|
+
create index if not exists hooks_file on hooks (file_id, at);
|
|
86
99
|
create table if not exists bg_ends (
|
|
87
100
|
id text primary key,
|
|
88
101
|
at integer not null,
|
|
@@ -231,7 +244,7 @@ const statements = (db: Database) => ({
|
|
|
231
244
|
get: db.query('select id, size, mtime, offset, version from files where path = ?'),
|
|
232
245
|
insFile: db.query('insert into files (path, account, project, session, agent, size, mtime, offset, version, first_at, last_at) values (?, ?, ?, ?, ?, 0, 0, 0, 0, null, null) returning id'),
|
|
233
246
|
setFile: db.query('update files set size = ?, mtime = ?, offset = ?, version = ?, first_at = coalesce(first_at, ?), last_at = coalesce(?, last_at), gone = 0 where id = ?'),
|
|
234
|
-
clear: [db.query('delete from calls where file_id = ?'), db.query('delete from marks where file_id = ?'), db.query('delete from prompts where file_id = ?')],
|
|
247
|
+
clear: [db.query('delete from calls where file_id = ?'), db.query('delete from marks where file_id = ?'), db.query('delete from prompts where file_id = ?'), db.query('delete from hooks where file_id = ?')],
|
|
235
248
|
resetFile: db.query('update files set offset = 0, first_at = null, last_at = null where id = ?'),
|
|
236
249
|
insCall: db.query('insert or ignore into calls (file_id, id, start, end, tool, shape, cmd, outcome, code, approval, perm, read, bg) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'),
|
|
237
250
|
endCall: db.query('update calls set end = ?, outcome = ?, code = ?, approval = ?, perm = ?, bg = ? where id = ? and end is null'),
|
|
@@ -240,6 +253,8 @@ const statements = (db: Database) => ({
|
|
|
240
253
|
bgEnd: db.query('insert into bg_ends (id, at, outcome, code) values (?, ?, ?, ?) on conflict (id) do update set at = excluded.at, outcome = excluded.outcome, code = excluded.code where excluded.at < bg_ends.at'),
|
|
241
254
|
insMark: db.query('insert into marks (file_id, at, kind) values (?, ?, ?)'),
|
|
242
255
|
insPrompt: db.query('insert into prompts (file_id, at, uuid, origin, text) values (?, ?, ?, ?, ?)'),
|
|
256
|
+
// one run is one call and one command: a copy of the session in another account is the same run
|
|
257
|
+
insHook: db.query('insert or ignore into hooks (file_id, id, at, event, tool, command, ms, code, error) values (?, ?, ?, ?, ?, ?, ?, ?, ?)'),
|
|
243
258
|
})
|
|
244
259
|
|
|
245
260
|
/** write the events of a chunk of lines: a call is written once its result
|
|
@@ -266,7 +281,8 @@ function writeEvents(st: Stmts, fileId: number, events: TranscriptEvent[]): { fi
|
|
|
266
281
|
} else if (e.kind === 'prompt') {
|
|
267
282
|
if (!Number.isNaN(e.at)) st.insPrompt.run(fileId, e.at, e.uuid, e.origin, e.text)
|
|
268
283
|
if (e.origin === 'typed' && !Number.isNaN(e.at)) st.insMark.run(fileId, e.at, 'prompt')
|
|
269
|
-
} else st.
|
|
284
|
+
} else if (e.kind === 'hook') st.insHook.run(fileId, e.id === '' ? String(e.at) : e.id, e.at, e.event, e.tool, e.command, Math.round(e.ms), e.code, e.error ? 1 : 0)
|
|
285
|
+
else st.insMark.run(fileId, e.at, e.kind)
|
|
270
286
|
}
|
|
271
287
|
for (const p of pending.values()) {
|
|
272
288
|
const shape = toolShape(p.tool, p.detail)
|
|
@@ -330,6 +346,44 @@ export function indexTranscripts(db: Database, files: TranscriptFile[], onProgre
|
|
|
330
346
|
return { scanned: files.length, read: todo.length, bytes: readBytes, ms: Math.round(performance.now() - t0), gone: 0 }
|
|
331
347
|
}
|
|
332
348
|
|
|
349
|
+
/** the files to read now, newest first, while their unread bytes fit
|
|
350
|
+
* `maxBytes`, and the unread bytes left for a later run: a bounded catch up
|
|
351
|
+
* that a gate can afford, each file committing alone */
|
|
352
|
+
export function catchUpPlan(db: Database, files: TranscriptFile[], maxBytes: number): { take: TranscriptFile[]; behind: number } {
|
|
353
|
+
const get = db.query('select size, mtime, offset, version from files where path = ?')
|
|
354
|
+
const take: TranscriptFile[] = []
|
|
355
|
+
let room = maxBytes
|
|
356
|
+
let behind = 0
|
|
357
|
+
for (const f of [...files].sort((a, b) => b.mtime - a.mtime)) {
|
|
358
|
+
const prev = get.get(f.path) as IndexedFile | null
|
|
359
|
+
const how = freshness(prev, f)
|
|
360
|
+
if (how === 'skip') continue
|
|
361
|
+
const bytes = how === 'append' && prev != null ? f.size - prev.offset : f.size
|
|
362
|
+
if (bytes <= room) {
|
|
363
|
+
take.push(f)
|
|
364
|
+
room -= bytes
|
|
365
|
+
} else behind += bytes
|
|
366
|
+
}
|
|
367
|
+
return { take, behind }
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** one timed hook run as the index holds it */
|
|
371
|
+
export type HookRun = { file_id: number; project: string; at: number; event: string; tool: string; command: string; ms: number; code: number | null; error: boolean }
|
|
372
|
+
|
|
373
|
+
/** the timed hook runs of the matching projects since `from` */
|
|
374
|
+
export function hookRuns(db: Database, keep: ProjectFilter, from: number, to = Number.MAX_SAFE_INTEGER): HookRun[] {
|
|
375
|
+
const files = (db.query('select id, project from files').all() as { id: number; project: string }[]).filter((f) => keep(f.project))
|
|
376
|
+
const projectOf = new Map(files.map((f) => [f.id, f.project]))
|
|
377
|
+
const ids = files.map((f) => f.id)
|
|
378
|
+
const out: HookRun[] = []
|
|
379
|
+
for (let i = 0; i < ids.length; i += 500) {
|
|
380
|
+
const part = ids.slice(i, i + 500)
|
|
381
|
+
const rows = db.query(`select file_id, at, event, tool, command, ms, code, error = 1 as error from hooks where file_id in (${part.map(() => '?').join(',')}) and at between ? and ?`).all(...part, from, to) as Omit<HookRun, 'project'>[]
|
|
382
|
+
for (const r of rows) out.push({ ...r, error: Boolean(r.error), project: projectOf.get(r.file_id) ?? '' })
|
|
383
|
+
}
|
|
384
|
+
return out.sort((a, b) => a.at - b.at)
|
|
385
|
+
}
|
|
386
|
+
|
|
333
387
|
/** the files the index holds that are no longer on disk, marked so the
|
|
334
388
|
* report can say how much history outlived the harness */
|
|
335
389
|
export function markGone(db: Database, onDisk: TranscriptFile[], keep: ProjectFilter): number {
|
|
@@ -350,7 +404,7 @@ export function markGone(db: Database, onDisk: TranscriptFile[], keep: ProjectFi
|
|
|
350
404
|
|
|
351
405
|
export type FileRow = { id: number; path: string; account: string; project: string; session: string; agent: string; first_at: number | null; last_at: number | null; gone: number }
|
|
352
406
|
|
|
353
|
-
export type Loaded = { files: FileRow[]; calls: Map<number, Call[]>; marks: Map<number, Mark[]>; prompts: { file_id: number; at: number; origin: 'typed' | 'queued'; text: string }[] }
|
|
407
|
+
export type Loaded = { files: FileRow[]; calls: Map<number, Call[]>; marks: Map<number, Mark[]>; prompts: { file_id: number; at: number; origin: 'typed' | 'queued'; text: string }[]; hooks: HookRun[] }
|
|
354
408
|
|
|
355
409
|
/** every row of the matching projects with activity in [from, to] */
|
|
356
410
|
export function loadWindow(db: Database, keep: ProjectFilter, from: number, to: number): Loaded {
|
|
@@ -384,7 +438,7 @@ export function loadWindow(db: Database, keep: ProjectFilter, from: number, to:
|
|
|
384
438
|
}
|
|
385
439
|
prompts.push(...(db.query(`select file_id, at, origin, text from prompts where file_id in (${inList}) and at between ? and ?`).all(...part, from, to) as Loaded['prompts']))
|
|
386
440
|
}
|
|
387
|
-
return { files, calls, marks, prompts }
|
|
441
|
+
return { files, calls, marks, prompts, hooks: hookRuns(db, keep, from, to) }
|
|
388
442
|
}
|
|
389
443
|
|
|
390
444
|
/** the repo a project dir belongs to: its slug without the worktree suffix,
|
package/src/annex/offload.ts
CHANGED
|
@@ -397,16 +397,25 @@ export async function drift(root: string): Promise<Drift[]> {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
const targets = offloads().map((x) => x.target)
|
|
400
|
-
const reached = (p: string): boolean => targets.some((t) => p === t || p.startsWith(`${t}/`) || t.startsWith(`${p}/`))
|
|
401
400
|
for (const a of await presentAnnexes()) {
|
|
402
401
|
const dir = join(a.path, 'offload', basename(root))
|
|
403
402
|
if (!existsSync(dir)) continue
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (e.dir || reached(p) || /\.\d+\.part(\/|$)/.test(p)) continue
|
|
407
|
-
out.push({ kind: 'orphan', path: p, why: 'on the annex, and no recorded offload of any repo reaches it', fix: `nothing on the Mac reaches it: delete ${p}` })
|
|
408
|
-
break
|
|
409
|
-
}
|
|
403
|
+
const p = firstOrphan(dir, targets)
|
|
404
|
+
if (p !== undefined) out.push({ kind: 'orphan', path: p, why: 'on the annex, and no recorded offload of any repo reaches it', fix: `nothing on the Mac reaches it: delete ${p}` })
|
|
410
405
|
}
|
|
411
406
|
return out
|
|
412
407
|
}
|
|
408
|
+
|
|
409
|
+
/** the first file under `dir` no target reaches, depth first; a folder a target reaches, or a copy in flight
|
|
410
|
+
* (`<name>.<n>.part`), is never read: the drive holds hundreds of thousands of files under the targets */
|
|
411
|
+
function firstOrphan(dir: string, targets: readonly string[]): string | undefined {
|
|
412
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
413
|
+
if (/\.\d+\.part$/.test(e.name)) continue
|
|
414
|
+
const p = join(dir, e.name)
|
|
415
|
+
if (targets.some((t) => p === t || p.startsWith(`${t}/`))) continue
|
|
416
|
+
if (!e.isDirectory()) return p
|
|
417
|
+
const found = firstOrphan(p, targets)
|
|
418
|
+
if (found !== undefined) return found
|
|
419
|
+
}
|
|
420
|
+
return undefined
|
|
421
|
+
}
|
package/src/check.ts
CHANGED
|
@@ -90,7 +90,9 @@ export type CheckDef = {
|
|
|
90
90
|
* not own OFF with `off` in repo.config.ts, never elsewhere. */
|
|
91
91
|
runs: Runs
|
|
92
92
|
/** HOW ITS ANSWER IS KEPT, one variant, every parameter explicit:
|
|
93
|
-
* `files` (keyed on these paths
|
|
93
|
+
* `files` (keyed on these paths; `optional` names the ones a repo may
|
|
94
|
+
* lack, keyed as absent, and any other missing path refuses the key),
|
|
95
|
+
* `reads` (keyed on what the body read),
|
|
94
96
|
* `ttl` (a world answer that keeps a span), `fact` (a decided value, once
|
|
95
97
|
* per key), `never` (with the reason). The file's own path joins every
|
|
96
98
|
* key automatically, so nothing declares its own code. */
|
|
@@ -32,12 +32,11 @@ const CONTRIB = '# repo-contributed lines (repo.config.ts gitignore:)'
|
|
|
32
32
|
|
|
33
33
|
const DRAFTS_BACK = '!.comfy-ts/drafts/'
|
|
34
34
|
const SOCIAL_BACK = `!${LAYOUT.social}/`
|
|
35
|
-
const VOICE_BACK = `!${LAYOUT.voice}/`
|
|
36
35
|
|
|
37
36
|
/** re-includes a private repo carries and a declared public one drops: a
|
|
38
37
|
* draft names private loras, a plan or a board quotes the owner, a social
|
|
39
|
-
* draft carries his angles and notes
|
|
40
|
-
const PRIVATE_ONLY: ReadonlySet<string> = new Set([DRAFTS_BACK, `!${LAYOUT.plans}/`, SOCIAL_BACK
|
|
38
|
+
* draft carries his angles and notes */
|
|
39
|
+
const PRIVATE_ONLY: ReadonlySet<string> = new Set([DRAFTS_BACK, `!${LAYOUT.plans}/`, SOCIAL_BACK])
|
|
41
40
|
|
|
42
41
|
export const POLICY_LINES = [
|
|
43
42
|
// everything shipkit keeps lives under .shipkit/ (core/layout.ts). Local
|
|
@@ -51,9 +50,11 @@ export const POLICY_LINES = [
|
|
|
51
50
|
// desks date posts from. A rendered trailer is made again by its command
|
|
52
51
|
SOCIAL_BACK,
|
|
53
52
|
`${LAYOUT.social}/drafts/**/*-trailer.mp4`,
|
|
54
|
-
// his takes of a trailer's lines: a recording is never made again
|
|
55
|
-
VOICE_BACK,
|
|
56
53
|
`${LAYOUT.assets}/out/`,
|
|
54
|
+
// recordings of a person's own voice never go to git, in any repo: covered
|
|
55
|
+
// by `.shipkit/*` and spelled out so this check asks git about it (the
|
|
56
|
+
// backup keeps the files)
|
|
57
|
+
`${LAYOUT.voice}/takes/`,
|
|
57
58
|
// already covered by the line above, and spelled out anyway so this check
|
|
58
59
|
// asks git about it: a negation below the block that exposed the keyword
|
|
59
60
|
// list would otherwise pass as a venue override
|
|
@@ -165,12 +166,12 @@ async function trackedGenerated(d: Disk): Promise<string[]> {
|
|
|
165
166
|
return GENERATED_TRACKED_PATHS.filter((p) => listed.has(p))
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
/** a
|
|
169
|
-
* not hold yet, never a file tracked before
|
|
169
|
+
/** files git still tracks under a folder this repo keeps local: the private only folders of a declared public repo,
|
|
170
|
+
* and recorded voice in any repo. The block ignores what git does not hold yet, never a file tracked before */
|
|
170
171
|
async function trackedPrivate(d: Disk, config: RepoConfig): Promise<Map<string, number>> {
|
|
171
172
|
const out = new Map<string, number>()
|
|
172
|
-
if (!
|
|
173
|
-
const dirs = [LAYOUT.plans, LAYOUT.social, LAYOUT.voice]
|
|
173
|
+
if (!d.exists('.git')) return out
|
|
174
|
+
const dirs = [...(declaredPublic(config) ? [LAYOUT.plans, LAYOUT.social] : []), LAYOUT.voice]
|
|
174
175
|
const r = await d.exec([gitBin(), 'ls-files', '-z', '--', ...dirs], { cwd: d.root })
|
|
175
176
|
if (r.code !== 0) return out
|
|
176
177
|
for (const f of r.out.split('\0')) {
|
|
@@ -203,6 +204,17 @@ function blockState(d: Disk, config: RepoConfig, legacy: boolean): BlockState {
|
|
|
203
204
|
return f.lines.slice(f.b, f.e + 1).join('\n') === expectedBlock(config, legacy) ? 'current' : 'stale'
|
|
204
205
|
}
|
|
205
206
|
|
|
207
|
+
/** the lines of a well-formed block the current one no longer holds: a line a repo wrote inside it, or one the policy
|
|
208
|
+
* retired. Only the repair removes them, and it names each */
|
|
209
|
+
export function removedLines(text: string | null, config: RepoConfig, legacy = false): string[] {
|
|
210
|
+
const f = parseText(text)
|
|
211
|
+
if (f == null || f.b === -1 || f.e === -1 || f.e < f.b) return []
|
|
212
|
+
const kept = new Set([...expectedBlock(config, legacy).split('\n'), CONTRIB, LEGACY])
|
|
213
|
+
return f.lines.slice(f.b + 1, f.e).filter((l) => l.trim() !== '' && !kept.has(l))
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const REMOVED_FIX = 'a line of the repo goes below the block, or in repo.config.ts gitignore:'
|
|
217
|
+
|
|
206
218
|
function writeBlock(d: Disk, config: RepoConfig, legacy: boolean): void {
|
|
207
219
|
d.write('.gitignore', withBlock(d.read('.gitignore'), config, legacy))
|
|
208
220
|
}
|
|
@@ -263,6 +275,12 @@ export const gitignorePolicy = check({
|
|
|
263
275
|
// every run that may write renders it in place, so a policy change never
|
|
264
276
|
// turns the whole fleet red until each repo runs its gate
|
|
265
277
|
if (s === 'stale') {
|
|
278
|
+
const removed = removedLines(c.read('.gitignore'), c.config, legacy)
|
|
279
|
+
if (removed.length > 0) {
|
|
280
|
+
c.warn(`.gitignore policy block is stale, and its rewrite removes ${removed.join(', ')}: left for the repair, which names each line`)
|
|
281
|
+
c.lines.push({ kind: 'fix-warn', text: `${REMOVED_FIX}; sk ci (or check --fix SK004) rewrites it` })
|
|
282
|
+
return
|
|
283
|
+
}
|
|
266
284
|
if (c.frozen) {
|
|
267
285
|
c.warn('.gitignore policy block is stale: the policy moved, and a frozen run rewrites nothing')
|
|
268
286
|
c.lines.push({ kind: 'fix-warn', text: 'any run that is not frozen rewrites it in place (sk check, sk ci)' })
|
|
@@ -324,7 +342,8 @@ export const gitignorePolicy = check({
|
|
|
324
342
|
}
|
|
325
343
|
c.ok(`.gitignore policy block current, ${claimed.length + backProbes.size} patterns verified against git`)
|
|
326
344
|
for (const [dir, n] of await trackedPrivate(c, c.config)) {
|
|
327
|
-
|
|
345
|
+
const files = `${n} file${n === 1 ? '' : 's'} under ${dir}/`
|
|
346
|
+
c.warn(dir === LAYOUT.voice ? `this repo still tracks ${files}: recorded voice, and the block keeps only new ones local` : `a public repo still tracks ${files}: strangers read them, and the block keeps only new ones local`)
|
|
328
347
|
c.lines.push({ kind: 'fix-warn', text: `git rm -r --cached -q ${dir} && git commit -m "untrack ${dir}" -- ${dir} (the files stay on the disk)` })
|
|
329
348
|
}
|
|
330
349
|
},
|
|
@@ -344,12 +363,14 @@ export const gitignorePolicy = check({
|
|
|
344
363
|
c.write('.gitignore', `${c.read('.gitignore') ?? ''}\n`)
|
|
345
364
|
terminated = '.gitignore terminated with a newline (the next append would have fused onto its last line)'
|
|
346
365
|
}
|
|
366
|
+
const removed = before === 'stale' ? removedLines(c.read('.gitignore'), c.config, legacy) : []
|
|
347
367
|
const blockSummary = before === 'current'
|
|
348
368
|
? null
|
|
349
369
|
: before === 'missing-file' ? '.gitignore created with the policy block'
|
|
350
370
|
: before === 'missing-block' ? 'policy block appended (repo lines untouched)'
|
|
351
371
|
: before === 'corrupted' ? 'policy block rebuilt (stray markers dropped, repo lines kept visible)'
|
|
352
|
-
:
|
|
372
|
+
: removed.length > 0 ? `policy block rewritten in place, removed from it: ${removed.join(', ')} (${REMOVED_FIX})`
|
|
373
|
+
: 'policy block rewritten in place (repo lines outside it untouched)'
|
|
353
374
|
if (blockSummary != null) writeBlock(c, c.config, legacy)
|
|
354
375
|
// the block must be written FIRST: untracking a path the ignore list
|
|
355
376
|
// does not yet carry leaves it staged for re-add on the next `git add`.
|
|
@@ -23,7 +23,7 @@ export const agentWikiLinks = check({
|
|
|
23
23
|
owner: 'meta/agent-folder/index.md',
|
|
24
24
|
runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
|
|
25
25
|
// the md lint walks agent/ on disk rather than through `c`; the loaded context starts at CLAUDE.md
|
|
26
|
-
cache: { by: 'files', inputs: ['agent', 'CLAUDE.md', 'CLAUDE.local.md'], key: null },
|
|
26
|
+
cache: { by: 'files', inputs: ['agent', 'CLAUDE.md', 'CLAUDE.local.md'], optional: ['agent', 'CLAUDE.md', 'CLAUDE.local.md'], key: null },
|
|
27
27
|
fix: 'none',
|
|
28
28
|
applies: 'always',
|
|
29
29
|
run: (c) => {
|
|
@@ -31,7 +31,7 @@ export const globalContribution = check({
|
|
|
31
31
|
owner: 'meta/agent-folder/index.md',
|
|
32
32
|
runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
|
|
33
33
|
// the file sits in the agent folder CLAUDE.md names: agent/, or a folder of the repo's wiki/
|
|
34
|
-
cache: { by: 'files', inputs: ['CLAUDE.md', 'agent/global-contribution.md', 'wiki'], key: null },
|
|
34
|
+
cache: { by: 'files', inputs: ['CLAUDE.md', 'agent/global-contribution.md', 'wiki'], optional: ['CLAUDE.md', 'agent/global-contribution.md', 'wiki'], key: null },
|
|
35
35
|
fix: 'ci',
|
|
36
36
|
applies: (env) => notHouse(env.root),
|
|
37
37
|
run: (c) => {
|
|
@@ -13,7 +13,7 @@ export const draftMediaSize = check({
|
|
|
13
13
|
owner: 'tools/shipkit/social.md',
|
|
14
14
|
runs: { onPreCommit: { budgetMs: 60 }, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
|
|
15
15
|
// the folder's files; the hook runs it raw on the index, so a file staged since a cached green is still seen there
|
|
16
|
-
cache: { by: 'files', inputs: [LAYOUT.social], key: null },
|
|
16
|
+
cache: { by: 'files', inputs: [LAYOUT.social], optional: [LAYOUT.social], key: null },
|
|
17
17
|
fix: 'none',
|
|
18
18
|
applies: 'always',
|
|
19
19
|
run: (c) => {
|
|
@@ -20,7 +20,7 @@ export const releaseWords = check({
|
|
|
20
20
|
owner: 'tools/shipkit/units.md',
|
|
21
21
|
runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
|
|
22
22
|
// the release files and the messages store the guard reads, and the text of the social unit files that declare it
|
|
23
|
-
cache: { by: 'files', inputs: [LAYOUT.releases, '.shipkit/messages'], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => `${f}:${Bun.hash(readFileSync(f, 'utf8'))}`).join('\n') },
|
|
23
|
+
cache: { by: 'files', inputs: [LAYOUT.releases, '.shipkit/messages'], optional: [LAYOUT.releases, '.shipkit/messages'], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => `${f}:${Bun.hash(readFileSync(f, 'utf8'))}`).join('\n') },
|
|
24
24
|
fix: 'none',
|
|
25
25
|
applies: 'always',
|
|
26
26
|
run: async (c) => {
|
|
@@ -31,7 +31,7 @@ export const postKinds = check({
|
|
|
31
31
|
owner: 'tools/shipkit/built-in-checks-contracts-and-visibility.md',
|
|
32
32
|
runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: true, onHealth: true, onSave: 'moved', onClock: false },
|
|
33
33
|
// the social folder, the text of the social unit files that declare its own kinds, and each page they name
|
|
34
|
-
cache: { by: 'files', inputs: [LAYOUT.social], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => unitKey(env.root, f)).join('\n') },
|
|
34
|
+
cache: { by: 'files', inputs: [LAYOUT.social], optional: [LAYOUT.social], key: (env) => unitFilesDeclaring(env.root, 'social').map((f) => unitKey(env.root, f)).join('\n') },
|
|
35
35
|
fix: 'none',
|
|
36
36
|
applies: 'always',
|
|
37
37
|
run: async (c) => {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SK045 slow hooks (tools/shipkit/built-in-checks-repo-wiring.md): a hook the repo's .claude settings run on every
|
|
2
|
+
// tool call answers under its budget, judged on what the gate itself can tell. A hook that takes a Bash call is
|
|
3
|
+
// probed on a no-op Bash call; any other (a save hook) fails unless repo.config.ts declares it instant with the
|
|
4
|
+
// reason. The runs the harness recorded are the world, read by SK046 as a warning. A user level hook is the
|
|
5
|
+
// machine's: judged in the house repo only, as a warning. agent-time/hooks.ts owns the budget, the probe and the verdict.
|
|
6
|
+
import { check, type CheckCtx } from '../check.ts'
|
|
7
|
+
import { INSTANT_KEY, REPO_SETTINGS, hasHooks, hooksKey, isHouse, repoHooks, userHooks, userSettingsFiles } from '../agent-time/hooks.ts'
|
|
8
|
+
|
|
9
|
+
async function body(c: CheckCtx): Promise<void> {
|
|
10
|
+
const { cadenceOf, judgeGate, probeHook, probeable } = await import('../agent-time/hooks.ts')
|
|
11
|
+
const { hooks: own, broken } = repoHooks(c.root)
|
|
12
|
+
for (const b of broken) c.fail(`${b} is not JSON: Claude Code loads none of its hooks either`, `fix the JSON of ${b}`)
|
|
13
|
+
const machine = isHouse(c.root) ? userHooks() : []
|
|
14
|
+
const instant = c.config.instantHooks ?? {}
|
|
15
|
+
const perCall = [...own, ...machine].filter((h) => cadenceOf(h.event) === 'call')
|
|
16
|
+
for (const h of perCall) {
|
|
17
|
+
const v = judgeGate(h, probeable(h) ? await probeHook(h, c.root) : null, { instant: instant[h.command], machine: h.source === 'user' })
|
|
18
|
+
if (v.level === 'fail') c.fail(v.text, v.fix)
|
|
19
|
+
else if (v.level === 'warn') c.warn(v.text, v.fix)
|
|
20
|
+
else c.ok(v.text)
|
|
21
|
+
}
|
|
22
|
+
const named = new Set([...own, ...machine].map((h) => h.command))
|
|
23
|
+
for (const command of Object.keys(instant))
|
|
24
|
+
if (!named.has(command)) c.warn(`repo.config.ts ${INSTANT_KEY} names \`${command}\`, which no settings hook runs`, `drop the entry, or copy the command exactly as .claude/settings.json writes it`)
|
|
25
|
+
if (perCall.length === 0 && broken.length === 0) c.ok('no hook on a tool call')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const slowHooks = check({
|
|
29
|
+
id: 'SK045',
|
|
30
|
+
blocking: true,
|
|
31
|
+
title: 'slow hooks',
|
|
32
|
+
description: 'a hook on every tool call is probed under 150 ms, or declared instant in repo.config.ts',
|
|
33
|
+
owner: 'tools/shipkit/built-in-checks-repo-wiring.md',
|
|
34
|
+
runs: { onPreCommit: false, onCi: true, onFull: true, onRelease: false, onHealth: true, onSave: 'moved', onClock: false },
|
|
35
|
+
// the settings and the declaration are the inputs; the key adds the stamp of every script a hook runs
|
|
36
|
+
cache: {
|
|
37
|
+
by: 'files',
|
|
38
|
+
inputs: [...REPO_SETTINGS, 'repo.config.ts'],
|
|
39
|
+
optional: [...REPO_SETTINGS],
|
|
40
|
+
key: (env) => hooksKey(env.root, [...REPO_SETTINGS, ...(isHouse(env.root) ? userSettingsFiles() : [])]),
|
|
41
|
+
},
|
|
42
|
+
fix: 'none',
|
|
43
|
+
applies: (env) => (hasHooks(env.root) ? null : 'no hook in .claude/settings.json or .claude/settings.local.json'),
|
|
44
|
+
run: body,
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
export default slowHooks
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SK046 hook records (tools/shipkit/built-in-checks-repo-wiring.md): the runs the harness timed for each hook the
|
|
2
|
+
// repo's .claude settings declare, read from the agent time index over every work tree of the repo's git, warn past
|
|
3
|
+
// the budget of their cadence. The index is the machine's (other work trees, a loaded afternoon, a fix outside the
|
|
4
|
+
// named script), so this reports the world and never blocks; SK045 is the gate. Each run catches the index up by a
|
|
5
|
+
// bounded slice, newest files first.
|
|
6
|
+
import { check } from '../check.ts'
|
|
7
|
+
import { REPO_SETTINGS, hasHooks, hooksKey, isHouse, userSettingsFiles } from '../agent-time/hooks.ts'
|
|
8
|
+
|
|
9
|
+
/** the unread transcript bytes one run may index: about a third of a second */
|
|
10
|
+
export const CATCH_UP_BYTES = 256 * 1024 * 1024
|
|
11
|
+
|
|
12
|
+
/** the projects of every work tree of this repo's git: one script, one command, filed under each checkout's folder */
|
|
13
|
+
async function familyFilter(root: string): Promise<(project: string) => boolean> {
|
|
14
|
+
const { gitBin } = await import('../core/git-bin.ts')
|
|
15
|
+
const { projectSlug } = await import('../reflect/prompt-corpus.ts')
|
|
16
|
+
const out = Bun.spawnSync([gitBin(), 'worktree', 'list', '--porcelain'], { cwd: root, stdout: 'pipe', stderr: 'ignore' })
|
|
17
|
+
const paths = out.exitCode === 0 ? out.stdout.toString().split('\n').filter((l) => l.startsWith('worktree ')).map((l) => l.slice(9)) : []
|
|
18
|
+
const slugs = [...new Set([root, ...paths].map(projectSlug))]
|
|
19
|
+
return (p) => slugs.some((s) => p === s || p.startsWith(`${s}--claude-worktrees-`))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Run = import('../agent-time/store.ts').HookRun
|
|
23
|
+
type Recorded = { family: Run[]; all: Run[]; behind: number; error: string | null }
|
|
24
|
+
|
|
25
|
+
/** the timed hook runs of this repo's family (and of every repo for the machine's hooks), after a bounded catch up */
|
|
26
|
+
async function recorded(root: string, machine: boolean): Promise<Recorded> {
|
|
27
|
+
const { catchUpPlan, hookRuns, indexTranscripts, listTranscripts, openIndex } = await import('../agent-time/store.ts')
|
|
28
|
+
const { discoverConfigRoots } = await import('../reflect/prompt-corpus.ts')
|
|
29
|
+
const { RECORD_DAYS } = await import('../agent-time/hooks.ts')
|
|
30
|
+
const keep = await familyFilter(root)
|
|
31
|
+
const from = Date.now() - RECORD_DAYS * 86_400_000
|
|
32
|
+
let db: ReturnType<typeof openIndex> | null = null
|
|
33
|
+
try {
|
|
34
|
+
db = openIndex()
|
|
35
|
+
const plan = catchUpPlan(db, listTranscripts(discoverConfigRoots(), keep).filter((f) => f.mtime >= from), CATCH_UP_BYTES)
|
|
36
|
+
if (plan.take.length > 0) indexTranscripts(db, plan.take)
|
|
37
|
+
return { family: hookRuns(db, keep, from), all: machine ? hookRuns(db, () => true, from) : [], behind: plan.behind, error: null }
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return { family: [], all: [], behind: 0, error: e instanceof Error ? e.message : String(e) }
|
|
40
|
+
} finally {
|
|
41
|
+
db?.close()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const hookRecords = check({
|
|
46
|
+
id: 'SK046',
|
|
47
|
+
blocking: false,
|
|
48
|
+
title: 'hook records',
|
|
49
|
+
description: "the runs the harness timed for each declared hook stay under its cadence's budget",
|
|
50
|
+
owner: 'tools/shipkit/built-in-checks-repo-wiring.md',
|
|
51
|
+
runs: { onPreCommit: false, onCi: false, onFull: false, onRelease: false, onHealth: true, onSave: false, onClock: { every: '6h', inactive: 'wait' } },
|
|
52
|
+
cache: { by: 'ttl', span: '6h', key: (env) => hooksKey(env.root, [...REPO_SETTINGS, ...(isHouse(env.root) ? userSettingsFiles() : [])]) },
|
|
53
|
+
fix: 'none',
|
|
54
|
+
applies: (env) => (hasHooks(env.root) ? null : 'no hook in .claude/settings.json or .claude/settings.local.json'),
|
|
55
|
+
run: async (c) => {
|
|
56
|
+
const { RECORD_DAYS, cadenceOf, changedAt, judgeRecords, matcherMatches, repoHooks, userHooks } = await import('../agent-time/hooks.ts')
|
|
57
|
+
const machine = isHouse(c.root) ? userHooks() : []
|
|
58
|
+
const hooks = [...repoHooks(c.root).hooks, ...machine].filter((h) => cadenceOf(h.event) !== 'other' && h.command !== '')
|
|
59
|
+
if (hooks.length === 0) return void c.ok('no command hook on a tool call or a turn')
|
|
60
|
+
const rec = await recorded(c.root, machine.length > 0)
|
|
61
|
+
if (rec.error != null) {
|
|
62
|
+
c.unmeasured = true
|
|
63
|
+
return void c.warn(`the agent time index did not open: ${rec.error}`, 'sk time opens and builds it')
|
|
64
|
+
}
|
|
65
|
+
const behind = rec.behind > 0 ? `the agent time index is ${(rec.behind / 1e9).toFixed(1)} GB behind for this repo: sk time catches it up` : undefined
|
|
66
|
+
for (const h of hooks) {
|
|
67
|
+
const since = Math.max(Date.now() - RECORD_DAYS * 86_400_000, changedAt(h.command, c.root) ?? 0)
|
|
68
|
+
const runs = (h.source === 'user' ? rec.all : rec.family).filter((r) => r.event === h.event && r.command === h.command && r.at >= since && (cadenceOf(h.event) !== 'call' || r.tool === '' || matcherMatches(h.matcher, r.tool)))
|
|
69
|
+
const v = judgeRecords(h, runs.map((r) => r.ms), behind)
|
|
70
|
+
if (v.level === 'ok') c.ok(v.text)
|
|
71
|
+
else c.warn(v.text, v.fix)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
export default hookRecords
|
package/src/cli/cmd_Annex.ts
CHANGED
|
@@ -31,10 +31,11 @@ export class AnnexCommand extends Command {
|
|
|
31
31
|
static override paths = [['annex']]
|
|
32
32
|
static override usage = Command.Usage({
|
|
33
33
|
category: 'Annex',
|
|
34
|
-
description: 'each annex: present or not, free space, its media,
|
|
35
|
-
details: `${DETAILS}\n\nA folder with no marker where an annex should be is named: the drive is unplugged, or a phantom folder took its place.`,
|
|
36
|
-
examples: [['where the annexes stand', 'sk annex']],
|
|
34
|
+
description: 'each annex: present or not, free space, its media, the offloaded folders, each link that fails',
|
|
35
|
+
details: `${DETAILS}\n\nA folder with no marker where an annex should be is named: the drive is unplugged, or a phantom folder took its place. Each repo with offloaded folders takes one line; a folder whose link does not hold is named under it with the command that settles it. --all lists every folder.`,
|
|
36
|
+
examples: [['where the annexes stand', 'sk annex'], ['every offloaded folder', 'sk annex --all']],
|
|
37
37
|
})
|
|
38
|
+
all = Option.Boolean('--all', false, { description: 'list every offloaded folder, its links that hold included' })
|
|
38
39
|
async execute(): Promise<number> {
|
|
39
40
|
return run(this.context, async (out) => {
|
|
40
41
|
const { annexSpecs, driveFree, isPresent, mediaFiles } = await import('../annex/annex.ts')
|
|
@@ -66,12 +67,16 @@ export class AnnexCommand extends Command {
|
|
|
66
67
|
for (const l of waitingBorn()) out(` waits: ${l.replace(/^WARN annex: /, '')}`)
|
|
67
68
|
for (const repo of [...new Set(list.map((x) => x.repo))]) {
|
|
68
69
|
const bad = new Map((await drift(repo)).map((d) => [d.path, d] as const))
|
|
69
|
-
|
|
70
|
+
const mine = list.filter((y) => y.repo === repo)
|
|
71
|
+
const born = mine.filter((x) => x.born).length
|
|
72
|
+
const moved = mine.reduce((s, x) => s + (x.born ? 0 : x.bytes), 0)
|
|
73
|
+
out(` ${repo} ${mine.length} ${mine.length === 1 ? 'folder' : 'folders'} (${born} born, ${gb(moved)} moved) ${bad.size === 0 ? 'every link holds' : `${bad.size} ${bad.size === 1 ? 'needs' : 'need'} a hand`}`)
|
|
74
|
+
for (const x of mine) {
|
|
70
75
|
const d = bad.get(`${x.repo}/${x.rel}`)
|
|
71
|
-
out(`
|
|
76
|
+
if (d || this.all) out(` ${x.rel} ${x.born ? 'born' : `${gb(x.bytes)} moved`} ${d ? `${d.kind.toUpperCase()}: ${d.why}` : 'link holds'}`)
|
|
72
77
|
}
|
|
73
|
-
for (const d of bad.values()) if (d.kind === 'orphan' || !list.some((x) => `${x.repo}/${x.rel}` === d.path)) out(`
|
|
74
|
-
for (const d of bad.values()) out(`
|
|
78
|
+
for (const d of bad.values()) if (d.kind === 'orphan' || !list.some((x) => `${x.repo}/${x.rel}` === d.path)) out(` ${d.kind.toUpperCase()} ${d.path}: ${d.why}`)
|
|
79
|
+
for (const d of bad.values()) out(` → ${d.fix}`)
|
|
75
80
|
}
|
|
76
81
|
const { readdirSync } = await import('node:fs')
|
|
77
82
|
const { join } = await import('node:path')
|
package/src/cli/cmd_Assets.ts
CHANGED
|
@@ -21,10 +21,10 @@ export class AssetsFillCommand extends Command {
|
|
|
21
21
|
|
|
22
22
|
static override usage = Command.Usage({
|
|
23
23
|
category: 'Assets',
|
|
24
|
-
description: 'top rolls up to N per asset
|
|
24
|
+
description: 'top rolls up to N per asset, sparsest first; a comfy asset renders on the GPU box, a job a roll',
|
|
25
25
|
examples: [
|
|
26
|
-
['every asset up to 8 rolls', 'sk assets fill 8'],
|
|
27
26
|
['only two categories', 'sk assets fill 8 icons sprites'],
|
|
27
|
+
['every asset up to 8 rolls: one GPU job for each roll missing', 'sk assets fill 8'],
|
|
28
28
|
],
|
|
29
29
|
})
|
|
30
30
|
|
|
@@ -46,8 +46,8 @@ export class AssetsAddCommand extends Command {
|
|
|
46
46
|
|
|
47
47
|
static override usage = Command.Usage({
|
|
48
48
|
category: 'Assets',
|
|
49
|
-
description: 'N more rolls per asset
|
|
50
|
-
examples: [['3 fresh rolls everywhere', 'sk assets add 3']],
|
|
49
|
+
description: 'N more rolls per asset, whatever it has; a comfy asset renders on the GPU box, a job a roll',
|
|
50
|
+
examples: [['3 fresh rolls for one category', 'sk assets add 3 icons'], ['3 fresh rolls everywhere: 3 GPU jobs for each comfy asset', 'sk assets add 3']],
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
n = Option.String({ required: true })
|
|
@@ -68,7 +68,7 @@ export class AssetsGenCommand extends Command {
|
|
|
68
68
|
|
|
69
69
|
static override usage = Command.Usage({
|
|
70
70
|
category: 'Assets',
|
|
71
|
-
description: '
|
|
71
|
+
description: 'rolls for one asset now; a comfy asset renders on the GPU box, a job a roll',
|
|
72
72
|
examples: [
|
|
73
73
|
['one roll', 'sk assets gen hero'],
|
|
74
74
|
['five rolls', 'sk assets gen hero --n 5'],
|