rvlib-shipkit 2.25.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 +13 -0
- package/package.json +2 -2
- package/src/agent-time/hooks.ts +329 -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/checks/SK045-slow-hooks.check.ts +47 -0
- package/src/checks/SK046-hook-records.check.ts +76 -0
- package/src/cli/cmd_Backup.ts +3 -1
- package/src/cli/cmd_Mv.ts +1 -1
- package/src/cli/cmd_Releases.ts +30 -0
- package/src/cli/cmd_Review.ts +23 -4
- package/src/cli/cmd_Time.ts +8 -2
- package/src/cli/registry.ts +2 -1
- package/src/commands/runner.ts +5 -1
- package/src/core/history-files.ts +9 -5
- package/src/core/signal-name.ts +6 -0
- package/src/core/trace-audit.ts +6 -1
- package/src/core/transient.ts +6 -0
- package/src/drill/run.ts +1 -1
- package/src/ledger/gate-checks.ts +23 -2
- package/src/ledger/git-key.ts +3 -3
- package/src/ledger/git-scan.ts +49 -7
- package/src/media-store/backup/daemon.ts +11 -0
- package/src/media-store/backup/sources.ts +1 -4
- package/src/reflect/transcript.ts +21 -3
- package/src/releases/model.ts +18 -0
- package/src/releases/store.ts +13 -1
- package/src/repo-config.ts +11 -1
- package/src/review/inbox-hook.ts +35 -0
- package/src/review/model.ts +12 -6
- package/src/suite/judge-suites.ts +77 -10
- package/src/suite/suite-cli.ts +72 -31
- package/src/wiki/run-wiki.ts +2 -1
- package/src/wiki/scan-md.ts +42 -2
|
@@ -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_Backup.ts
CHANGED
|
@@ -54,7 +54,9 @@ export class BackupCommand extends Command {
|
|
|
54
54
|
for (const r of list) h.out(` refused ~/${r.path}: ${r.why}`)
|
|
55
55
|
}
|
|
56
56
|
if (this.check) {
|
|
57
|
-
|
|
57
|
+
// a look only: the local files as the daemon's looks keep them, never each repo's git walk again
|
|
58
|
+
const { keptLocals } = await import('../media-store/backup/daemon.ts')
|
|
59
|
+
const c = await backupCheck(h.space, { home: h.home, repos: h.repos, locals: keptLocals() })
|
|
58
60
|
h.out(`${c.files} files read; the last run: ${c.last ? `${c.last.at} (${c.last.key})` : 'none'}`)
|
|
59
61
|
h.out(`${c.waiting.length} not in the Space yet (${mb(c.waiting.reduce((n, w) => n + w.size, 0))}), ${c.changed.length} changed since the last run, ${c.refused.length} refused`)
|
|
60
62
|
for (const w of c.waiting.slice(0, 40)) h.out(` waiting ~/${w.path}`)
|
package/src/cli/cmd_Mv.ts
CHANGED
|
@@ -15,7 +15,7 @@ export class MvCommand extends Command {
|
|
|
15
15
|
static override usage = Command.Usage({
|
|
16
16
|
category: 'Refactor',
|
|
17
17
|
description: 'rename a file, folder or md page and rewrite every reference (dry run by default)',
|
|
18
|
-
details: 'rename anything and sweep every reference: an md page (plus its sibling dir and its check file) or a code file or folder. Dry run by default: it lists each file and its first rewritten line. A reference is the path written bare, from the repo root (absolute or ~), or relative to the file that holds it; a longer path that only ends with it (packages/p/agent/index.md for agent/index.md) names another file and stays. A page moved into its own folder (x.md to x/index.md or x/x.md) keeps that folder where it is. A map line sees what the lines before it moved, in a dry run too. A plan (.shipkit/plans/), a changelog and a journal record what was true when they were written: they stay as written, the run says how many name the path, and --history rewrites them too.',
|
|
18
|
+
details: 'rename anything and sweep every reference: an md page (plus its sibling dir and its check file) or a code file or folder. Dry run by default: it lists each file and its first rewritten line. A reference is the path written bare, from the repo root (absolute or ~), or relative to the file that holds it; a longer path that only ends with it (packages/p/agent/index.md for agent/index.md) names another file and stays. A page moved into its own folder (x.md to x/index.md or x/x.md) keeps that folder where it is. A map line sees what the lines before it moved, in a dry run too. A plan, an archived repro and a field note (.shipkit/plans/, repros/, reflections/), a changelog and a journal record what was true when they were written: they stay as written, the run says how many name the path, and --history rewrites them too.',
|
|
19
19
|
examples: [
|
|
20
20
|
['dry run, the default, shows what changes', 'sk mv docs/old-name.md docs/new-name.md'],
|
|
21
21
|
['apply it', 'sk mv docs/old-name.md docs/new-name.md --write'],
|
package/src/cli/cmd_Releases.ts
CHANGED
|
@@ -100,6 +100,36 @@ export class ReleasesAddCommand extends Command {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
export class ReleasesRemoveCommand extends Command {
|
|
104
|
+
static override paths = [['releases', 'remove']]
|
|
105
|
+
|
|
106
|
+
static override usage = Command.Usage({
|
|
107
|
+
category: 'Gate',
|
|
108
|
+
description: 'take one change out of .shipkit/releases/next.md, by its card id or its title',
|
|
109
|
+
details: 'the change the word names leaves .shipkit/releases/next.md, and the write is committed by pathspec, as `releases add` does. The word is the change\'s card id (whole, or the moment it starts with), else its title, whole or a part of it. Refused when it names no change or more than one. Its pictures stay where the store keeps them: they are kept by content, and another change may show the same one.',
|
|
110
|
+
examples: [
|
|
111
|
+
['by the card it came from', 'sk releases remove 20250101-120000-new-toolbar'],
|
|
112
|
+
['by its title', 'sk releases remove "A new toolbar"'],
|
|
113
|
+
],
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
ref = Option.String({ required: true, name: 'card id | title' })
|
|
117
|
+
|
|
118
|
+
async execute(): Promise<number> {
|
|
119
|
+
try {
|
|
120
|
+
const { dropChange } = await import('../releases/store.ts')
|
|
121
|
+
const { commitPaths } = await import('../social/writes.ts')
|
|
122
|
+
const { file, title } = dropChange(process.cwd(), this.ref)
|
|
123
|
+
commitPaths([file], `releases: next.md loses ${title}`)
|
|
124
|
+
this.context.stdout.write(`ok: « ${title} » is out of ${file}\n`)
|
|
125
|
+
return 0
|
|
126
|
+
} catch (e) {
|
|
127
|
+
this.context.stderr.write(`FAIL: ${e instanceof Error ? e.message : String(e)}\n`)
|
|
128
|
+
return 1
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
103
133
|
export class ReleasesRefreshCommand extends Command {
|
|
104
134
|
static override paths = [['releases', 'refresh']]
|
|
105
135
|
|
package/src/cli/cmd_Review.ts
CHANGED
|
@@ -561,15 +561,23 @@ export class ReviewInboxCommand extends Command {
|
|
|
561
561
|
category: 'Review',
|
|
562
562
|
description: 'every answer not marked seen and every open item he raised, frame notes included',
|
|
563
563
|
details: DETAILS,
|
|
564
|
-
examples: [['what waits on you', 'sk review inbox'], ['his notes on trailer frames', 'sk review inbox --subject frame'], ['the cards this session sent', 'sk review inbox --mine']],
|
|
564
|
+
examples: [['what waits on you', 'sk review inbox'], ['his notes on trailer frames', 'sk review inbox --subject frame'], ['the cards this session sent', 'sk review inbox --mine'], ['as a Claude Code hook, on UserPromptSubmit and on Stop', 'sk review inbox --hook']],
|
|
565
565
|
})
|
|
566
566
|
mine = Option.Boolean('--mine', false, { description: "only this Claude Code session's cards" })
|
|
567
567
|
session = Option.String('--session', { description: "only that session's cards" })
|
|
568
568
|
subject = Option.String('--subject', { description: 'only items of this subject kind (frame, shot…)' })
|
|
569
569
|
all = Option.Boolean('--all', false, { description: 'a plain approval too, not only the counted line' })
|
|
570
|
+
hook = Option.Boolean('--hook', false, { description: 'run as a Claude Code hook (UserPromptSubmit, Stop): the hook input on stdin, its json answer on stdout. The unseen answers join a prompt as context, and a turn does not end while one is unseen' })
|
|
570
571
|
|
|
571
572
|
async execute(): Promise<number> {
|
|
572
|
-
|
|
573
|
+
const { hookAnswer, hookPasses, parseHookInput } = await import('../review/inbox-hook.ts')
|
|
574
|
+
// the hook input is one small json on stdin; a terminal has none
|
|
575
|
+
const input = this.hook ? parseHookInput(process.stdin.isTTY === true ? '' : await new Response(Bun.stdin.stream()).text().catch(() => '')) : null
|
|
576
|
+
if (input != null && hookPasses(input)) return 0
|
|
577
|
+
return run(this.context, async (hh) => {
|
|
578
|
+
// as a hook, the lines of the inbox are the answer's text, never the output
|
|
579
|
+
const unseenLines: string[] = []
|
|
580
|
+
const h = input == null ? hh : { ...hh, out: (l: string) => void unseenLines.push(l) }
|
|
573
581
|
const { liveWatchers } = await import('../review/watchers.ts')
|
|
574
582
|
const { readAll } = await import('../review/store.ts')
|
|
575
583
|
const { BUILTIN_KINDS, coversCard, moveOf, stateOf, unreadBy, untakenOf, verdictOf } = await import('../review/model.ts')
|
|
@@ -592,7 +600,9 @@ export class ReviewInboxCommand extends Command {
|
|
|
592
600
|
const v = verdictOf(x)
|
|
593
601
|
return v?.status === 'approved' && !v.seen && !v.comment && v.rects.length === 0 && !v.reactions && v.pick === undefined && unreadBy(x, 'agent').length === 0
|
|
594
602
|
}
|
|
595
|
-
|
|
603
|
+
// as a hook: a raised item a lane claimed is in that lane's hands until it closes it, so it never blocks a turn
|
|
604
|
+
const inHand = (x: (typeof news)[number]): boolean => input != null && x.item.origin.by !== 'agent' && stateOf(x, followed.has(x.item.id)).state === 'claimed'
|
|
605
|
+
const shown = [...(this.all ? news : news.filter((x) => !plain(x))), ...open].filter((x) => !inHand(x))
|
|
596
606
|
if (shown.length === 0 && news.length === 0) h.out('review: no unseen feedback or reply')
|
|
597
607
|
const threads = threadsOf(all.items)
|
|
598
608
|
const printed = new Set<string>()
|
|
@@ -609,6 +619,14 @@ export class ReviewInboxCommand extends Command {
|
|
|
609
619
|
const close = fix ? `sk review done ${x.item.id} "<what changed>"` : `--supersedes ${x.item.id} on its new version`
|
|
610
620
|
return ` ${x.item.id} ${fix ? 'ok with a fix' : 'rejected'} "${x.item.title}": ${close}, or sk review wontfix ${x.item.id} --note "<why>"`
|
|
611
621
|
}
|
|
622
|
+
if (input != null) {
|
|
623
|
+
const approvals = news.filter(plain)
|
|
624
|
+
if (approvals.length > 0) h.out(`${approvals.length} plain approval(s), nothing to do: sk review seen ${approvals.map((x) => x.item.id).join(' ')}`)
|
|
625
|
+
const said = unseenLines.filter((l) => l !== 'review: no unseen feedback or reply').join('\n').trim()
|
|
626
|
+
const answer = hookAnswer(input, said, owed.map((t) => t.head.item.id))
|
|
627
|
+
if (answer != null) hh.out(answer)
|
|
628
|
+
return 0
|
|
629
|
+
}
|
|
612
630
|
if (owed.length > 0) h.out(`owed, read and not done:\n${owed.map((t) => owedLine(t.head)).join('\n')}\n`)
|
|
613
631
|
const watchers = liveWatchers(h.dir)
|
|
614
632
|
const untaken = all.items.flatMap((x) => {
|
|
@@ -631,8 +649,9 @@ const laneOfCaller = (as: string | undefined): string | null => as?.trim() || pr
|
|
|
631
649
|
async function answererRefusal(dir: string, id: string, as: string | undefined, op: 'reply' | 'seen'): Promise<string | null> {
|
|
632
650
|
const { readItem, sessionId } = await import('../review/store.ts')
|
|
633
651
|
const { notAnswererOf } = await import('../review/model.ts')
|
|
652
|
+
const { liveWatchers } = await import('../review/watchers.ts')
|
|
634
653
|
const x = readItem(dir, id)
|
|
635
|
-
return x === null ? null : notAnswererOf(x, { lane: laneOfCaller(as), session: sessionId() }, op)
|
|
654
|
+
return x === null ? null : notAnswererOf(x, { lane: laneOfCaller(as), session: sessionId() }, op, op === 'seen' ? liveWatchers(dir) : undefined)
|
|
636
655
|
}
|
|
637
656
|
|
|
638
657
|
export class ReviewSeenCommand extends Command {
|
package/src/cli/cmd_Time.ts
CHANGED
|
@@ -17,7 +17,8 @@ export class TimeCommand extends Command {
|
|
|
17
17
|
details: [
|
|
18
18
|
'Reads every Claude Code transcript under every config root (~/.claude, ~/.claude-<name>), sub-agent runs included, through an index at ~/.shipkit/agent-time.sqlite.',
|
|
19
19
|
'The first run builds the index (niced, resumable, progress on stderr); later runs read only what changed. The index keeps sessions Claude Code has pruned.',
|
|
20
|
-
'Views: summary (default), commands, tools, slow, fails, feedback, sessions, turns. A Bash command is grouped by its shape (`git commit`, `bun test <file>`, `sk ci --only lint`).',
|
|
20
|
+
'Views: summary (default), commands, tools, slow, fails, feedback, sessions, turns, hooks. A Bash command is grouped by its shape (`git commit`, `bun test <file>`, `sk ci --only lint`).',
|
|
21
|
+
'Hooks: each hook command with its event, the runs the harness timed (median, p90, worst, total) and the calls its matcher applies to. The harness records a hook run only when the hook printed something, so a silent hook is missing.',
|
|
21
22
|
'Turns: every call costs a model turn before it, so the summary gives the model time before each call, the share of single read calls and the share sent in parallel, for the main sessions and the sub-agents; `turns` lists the runs and the read shapes by the model time they cost.',
|
|
22
23
|
'Wall time is cut once per moment, and the buckets add up to the wall: tools in flight, a sub-agent in flight, waiting on you (an idle gap past 30 minutes is left out), stopped until a task notification woke it (background wait), stopped with nothing recorded that woke it (unknown), else the agent was in its turn (model).',
|
|
23
24
|
'A background command (run_in_background, or moved there at its timeout) is timed from its start to its task notification, its row marked (bg); a run with no notification is counted as having no end, never as zero.',
|
|
@@ -28,6 +29,7 @@ export class TimeCommand extends Command {
|
|
|
28
29
|
['every command shape, 30 days', 'sk time commands --since 30d'],
|
|
29
30
|
['what he said while it ran', 'sk time feedback --since all'],
|
|
30
31
|
['the runs by their turns, and what the reads cost', 'sk time turns --since 30d'],
|
|
32
|
+
['what the hooks cost, 30 days', 'sk time hooks --since 30d'],
|
|
31
33
|
['two repos, every recorded session', 'sk time ~/dev/game ~/dev/site --since all'],
|
|
32
34
|
['every repo on the machine', 'sk time --all'],
|
|
33
35
|
['for a script', 'sk time --json'],
|
|
@@ -108,7 +110,11 @@ export class TimeCommand extends Command {
|
|
|
108
110
|
err.write(` fix: widen it, --since all, or name a repo that ran Claude Code sessions\n`)
|
|
109
111
|
return 1
|
|
110
112
|
}
|
|
111
|
-
const
|
|
113
|
+
const { repoHooks, userHooks } = await import('../agent-time/hooks.ts')
|
|
114
|
+
const { hookMatcherKey } = await import('../agent-time/report.ts')
|
|
115
|
+
// the matcher each hook declares today: the calls it applies to
|
|
116
|
+
const hookMatchers = new Map([...userHooks(), ...repos.flatMap((r) => repoHooks(r).hooks)].map((h) => [hookMatcherKey(h.event, h.command), h.matcher]))
|
|
117
|
+
const report = buildReport(loaded, { repos: labels, from, to: now, repoOf: (p) => repoOfProject(p), hookMatchers }, loadMasker(repos[0] ?? null))
|
|
112
118
|
if (this.json) this.context.stdout.write(`${JSON.stringify(report)}\n`)
|
|
113
119
|
else this.context.stdout.write(render(report, view, top))
|
|
114
120
|
if (!tty) err.write(indexed)
|
package/src/cli/registry.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { NeedsCommand } from './cmd_Needs.ts'
|
|
|
35
35
|
import { PbCollectionCommand } from './cmd_Pb.ts'
|
|
36
36
|
import { ReflectCommand } from './cmd_Reflect.ts'
|
|
37
37
|
import { ReleaseCommand } from './cmd_Release.ts'
|
|
38
|
-
import { ReleasesAddCommand, ReleasesCommand, ReleasesRefreshCommand } from './cmd_Releases.ts'
|
|
38
|
+
import { ReleasesAddCommand, ReleasesCommand, ReleasesRefreshCommand, ReleasesRemoveCommand } from './cmd_Releases.ts'
|
|
39
39
|
import { ChecksCommand, UnitsAliasCommand } from './cmd_Checks.ts'
|
|
40
40
|
import { WhenCommand } from './cmd_When.ts'
|
|
41
41
|
import { CacheAuditCommand } from './cmd_CacheAudit.ts'
|
|
@@ -127,6 +127,7 @@ export function buildCli(): Cli {
|
|
|
127
127
|
cli.register(ReleasesCommand)
|
|
128
128
|
cli.register(ReleasesAddCommand)
|
|
129
129
|
cli.register(ReleasesRefreshCommand)
|
|
130
|
+
cli.register(ReleasesRemoveCommand)
|
|
130
131
|
cli.register(HooksInstallCommand)
|
|
131
132
|
cli.register(HooksPreCommitCommand)
|
|
132
133
|
cli.register(HooksCommitMsgCommand)
|
package/src/commands/runner.ts
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
// output into `out.log` and writes `exit.json` once it ends, so a daemon restart never loses a run or its verdict.
|
|
3
3
|
// Started detached (runs.ts), it leads its own process group: Stop signals the group
|
|
4
4
|
import { closeSync, openSync, writeSync } from 'node:fs'
|
|
5
|
+
import { signalName } from '../core/signal-name.ts'
|
|
5
6
|
import { constants } from 'node:os'
|
|
6
7
|
import { join } from 'node:path'
|
|
7
8
|
import { atomicWrite } from '../core/locked-write.ts'
|
|
8
9
|
import type { Exit } from '../core/jobs.ts'
|
|
9
10
|
|
|
10
11
|
/** the exit code of a run its signal ended: 128 plus the signal, as a shell says it */
|
|
11
|
-
export const signalCode = (signal: string | null): number =>
|
|
12
|
+
export const signalCode = (signal: string | number | null): number => {
|
|
13
|
+
const name = signalName(signal)
|
|
14
|
+
return 128 + ((name != null ? constants.signals[name as keyof typeof constants.signals] : undefined) ?? (typeof signal === 'number' ? signal : 0))
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
if (import.meta.main) {
|
|
14
18
|
const [dir, ...argv] = process.argv.slice(2)
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
// the files that record what was true when they were written: a plan,
|
|
2
|
-
// changelog, a journal. A rename leaves them as
|
|
3
|
-
// may name a path that is gone, as long as git once
|
|
1
|
+
// the files that record what was true when they were written: a plan, an
|
|
2
|
+
// archived repro, a field note, a changelog, a journal. A rename leaves them as
|
|
3
|
+
// written, and a link in one may name a path that is gone, as long as git once
|
|
4
|
+
// held it.
|
|
4
5
|
import { gitBin } from './git-bin.ts'
|
|
5
6
|
|
|
6
|
-
/**
|
|
7
|
+
/** the folders of `.shipkit/` that only hold records: plans, archived repros, field notes and their archive */
|
|
8
|
+
const RECORD_DIRS = ['plans', 'repros', 'reflections', 'harvested-reflections']
|
|
9
|
+
|
|
10
|
+
/** a repo relative path of a record: under one of those folders, or a file or a folder named changelog or journal */
|
|
7
11
|
export const isHistoryFile = (rel: string): boolean =>
|
|
8
|
-
rel.startsWith(
|
|
12
|
+
RECORD_DIRS.some((d) => rel.startsWith(`.shipkit/${d}/`)) || rel.split('/').some((s) => /^(?:changelog|journal)(?:$|[.\-_/])/i.test(s))
|
|
9
13
|
|
|
10
14
|
/** whether git ever held a file whose path is `token` or ends with `/token`, on any branch of the repo at `cwd` */
|
|
11
15
|
export function onceAPath(cwd: string, token: string): boolean {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// a signal as a process reports it: bun gives its name or its number
|
|
2
|
+
import { constants } from 'os'
|
|
3
|
+
|
|
4
|
+
/** the signal's name; null when the process ended by itself */
|
|
5
|
+
export const signalName = (signal: string | number | null | undefined): string | null =>
|
|
6
|
+
signal == null ? null : typeof signal === 'string' ? signal : (Object.entries(constants.signals).find(([, n]) => n === signal)?.[0] ?? `SIG${signal}`)
|
package/src/core/trace-audit.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// git common dir and reused while it is young: rule SK031 in
|
|
16
16
|
// the health pass pays for it, and the fix pass that applies it reads it.
|
|
17
17
|
import { mkdirSync, writeFileSync } from 'fs'
|
|
18
|
+
import { isTransient } from './transient.ts'
|
|
18
19
|
import { dirname, isAbsolute, posix, relative, resolve, sep } from 'path'
|
|
19
20
|
import type { RepoConfig } from '../repo-config.ts'
|
|
20
21
|
import { composeChecks } from '../ledger/gate-checks.ts'
|
|
@@ -94,7 +95,11 @@ function inTree(p: string, declared: string[], extras: string[]): boolean {
|
|
|
94
95
|
* An entry `leaks` refuses (the commit leak guard, which reads the config
|
|
95
96
|
* the fix pass writes) becomes its nearest parent it lets through, in the
|
|
96
97
|
* same form; one with no such parent below the root is left out */
|
|
97
|
-
export function proposeInputs(
|
|
98
|
+
export function proposeInputs(contentRead: string[], listedRead: string[], leaks: (entry: string) => boolean = () => false): string[] {
|
|
99
|
+
// a write in flight is no input: a build's `.dist.tmp-<pid>` names one run, and a line that pins it is stale at once
|
|
100
|
+
const kept = (p: string): boolean => !p.split('/').some(isTransient)
|
|
101
|
+
const content = contentRead.filter(kept)
|
|
102
|
+
const listed = listedRead.filter(kept)
|
|
98
103
|
const minimal = (xs: string[]): string[] => {
|
|
99
104
|
const sorted = [...new Set(xs)].sort()
|
|
100
105
|
return sorted.filter((x) => !sorted.some((y) => y !== x && under(x, y)))
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// a write in flight: an atomic write's temp file or folder (`x.tmp`, `x.tmp.<pid>.<hex>`, `.dist.tmp-<pid>`,
|
|
2
|
+
// `.STATUS.md.tmp-<n>`) or an editor's partial copy (`.!<pid>!x`). Its name is true for one run only, so nothing
|
|
3
|
+
// keeps it: no watch hears it, no key names it.
|
|
4
|
+
|
|
5
|
+
/** true for the name of a path segment that is a write in flight */
|
|
6
|
+
export const isTransient = (name: string): boolean => /\.tmp(?:$|[-.])|^\.!\d+!/.test(name)
|
package/src/drill/run.ts
CHANGED
|
@@ -212,7 +212,7 @@ export function drillRun(lines: readonly string[], o: { transcript: string; root
|
|
|
212
212
|
} else if (e.kind === 'bgend') {
|
|
213
213
|
const c = pending.get(e.id)
|
|
214
214
|
if (c != null && (c.bgEnd == null || e.at < c.bgEnd)) c.bgEnd = e.at
|
|
215
|
-
} else if (e.kind !== 'prompt') marks.push({ at: e.at, kind: e.kind })
|
|
215
|
+
} else if (e.kind !== 'prompt' && e.kind !== 'hook') marks.push({ at: e.at, kind: e.kind })
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
const start = Number.isFinite(first) ? first : 0
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// check script, a `*.check.ts` with no check object). The declaration always lives WITH the check, never in a table
|
|
12
12
|
// over here: a table beside the registry is a second source of truth that
|
|
13
13
|
// drifts the first time somebody adds one.
|
|
14
|
-
import { existsSync } from 'fs'
|
|
14
|
+
import { existsSync, realpathSync } from 'fs'
|
|
15
15
|
import { join, relative, resolve } from 'path'
|
|
16
16
|
import type { CheckCtx } from '../core/check-ctx.ts'
|
|
17
17
|
import { type RepoConfig } from '../repo-config.ts'
|
|
@@ -55,6 +55,27 @@ function rawAccessOf(root: string, u: DiscoveredCheck, configs: Map<string, RvtC
|
|
|
55
55
|
* asked for the quick tier and one that asked for the full tier are different
|
|
56
56
|
* questions, and a surface that renders keys without applying it renders a
|
|
57
57
|
* tier nobody ran. */
|
|
58
|
+
/** true when `file` is this repo's own source: under its root, and no install. By real paths, so a root or a file
|
|
59
|
+
* reached through a link is judged where it is */
|
|
60
|
+
export const hostsFile = (root: string, file: string): boolean => {
|
|
61
|
+
const real = (p: string): string => { try { return realpathSync(p) } catch { return p } }
|
|
62
|
+
const rel = relative(real(root), real(file))
|
|
63
|
+
return !rel.startsWith('..') && !rel.split(/[\\/]/).includes('node_modules')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** a check of the toolkit (it has no path of its own in the repo) whose source lives outside this repo */
|
|
67
|
+
export const toolkitCheckElsewhere = (root: string, u: { rel?: string | null; path: string }): boolean => u.rel == null && !hostsFile(root, u.path)
|
|
68
|
+
|
|
69
|
+
/** what a check that declares cache reads becomes when a module its body reaches touches the disk around `c`.
|
|
70
|
+
* In the repo that holds the check's source it is a refusal: the declaration is wrong, and the gate fails until it
|
|
71
|
+
* is right. A toolkit check seen from another repo is the toolkit's defect, never that repo's: it runs there with
|
|
72
|
+
* no cache and says why, so a red gate still means « this repo is broken » */
|
|
73
|
+
export function rawAccessDecl(raw: string, toolkitCheckElsewhere: boolean): Pick<CheckDecl, 'declError' | 'uncacheable'> {
|
|
74
|
+
return toolkitCheckElsewhere
|
|
75
|
+
? { uncacheable: `a defect of the toolkit, not of this repo: its check declares cache reads, but ${raw}. It runs here with no cache` }
|
|
76
|
+
: { declError: `declares cache reads, but ${raw}` }
|
|
77
|
+
}
|
|
78
|
+
|
|
58
79
|
export const FULL_TESTS_ENV = 'SHIPKIT_TEST_FULL'
|
|
59
80
|
|
|
60
81
|
export type TestTier = 'quick' | 'full'
|
|
@@ -423,7 +444,7 @@ export async function composeChecks(root: string, c: RepoConfig, o: ComposeOpts
|
|
|
423
444
|
extra: cache.reads === true ? `${extra ?? ''}|tier=${full ? 'full' : 'quick'}` : extra,
|
|
424
445
|
writes: u.def.writes,
|
|
425
446
|
...(cache.reads === true && raw == null ? { reads: true } : {}),
|
|
426
|
-
...(raw != null ?
|
|
447
|
+
...(raw != null ? rawAccessDecl(raw, toolkitCheckElsewhere(root, u)) : {}),
|
|
427
448
|
},
|
|
428
449
|
title: u.title,
|
|
429
450
|
description: u.description,
|
package/src/ledger/git-key.ts
CHANGED
|
@@ -367,14 +367,14 @@ export class KeyLayer {
|
|
|
367
367
|
} catch (e) {
|
|
368
368
|
return { ...base, reason: e instanceof Error ? e.message : String(e) }
|
|
369
369
|
}
|
|
370
|
-
// absent means not on disk at all: a path git cannot name while it
|
|
371
|
-
//
|
|
370
|
+
// absent means not on disk at all: a path git cannot name while it exists (a submodule
|
|
371
|
+
// with a change of its own, an empty folder) keys nothing, optional or not
|
|
372
372
|
const notOnDisk = (p: string): boolean => !existsSync(join(this.root, p))
|
|
373
373
|
const absent = new Set(inputs.filter((p) => optional.has(p) && scan.missing.includes(p) && notOnDisk(p)))
|
|
374
374
|
const stale = inputs.filter((p) => scan.missing.includes(p) && !absent.has(p))
|
|
375
375
|
const gone = stale.filter(notOnDisk)
|
|
376
376
|
if (gone.length > 0) return { ...base, reason: `declared input(s) not on disk: ${gone.join(', ')}` }
|
|
377
|
-
if (stale.length > 0) return { ...base, reason: `declared input(s) on disk that git could not name (a submodule, an empty folder): ${stale.join(', ')}` }
|
|
377
|
+
if (stale.length > 0) return { ...base, reason: `declared input(s) on disk that git could not name (a submodule with uncommitted changes, an empty folder): ${stale.join(', ')}` }
|
|
378
378
|
const hidden = inputs.flatMap((p) => scan.excluded.get(p) ?? [])
|
|
379
379
|
const inputOids: [string, string][] = inputs.map((p) => [p, absent.has(p) ? ABSENT : scan.oidByPath.get(p) ?? ''])
|
|
380
380
|
if (inputOids.some(([, oid]) => oid === '')) return { ...base, reason: 'git could not name one of the declared inputs' }
|
package/src/ledger/git-scan.ts
CHANGED
|
@@ -55,6 +55,10 @@ export type ScanResult = {
|
|
|
55
55
|
oidByPath: Map<string, string>
|
|
56
56
|
/** declared paths that are not on disk — the caller must not cache them */
|
|
57
57
|
missing: string[]
|
|
58
|
+
/** declared paths that are a submodule, keyed (by the commit it stands at) or not. Whether one holds a change
|
|
59
|
+
* is read from its own repo, not from this index, so a result that looked at one is never kept from one scan
|
|
60
|
+
* to the next, in either direction */
|
|
61
|
+
submodules?: string[]
|
|
58
62
|
/** repo-relative path → ignored content under it that is NOT in the key
|
|
59
63
|
* (node_modules only, by policy: toolchain-identity.ts owns installs) */
|
|
60
64
|
excluded: Map<string, string[]>
|
|
@@ -349,14 +353,17 @@ function stage(root: string, wanted: string[], prior: ScanResult | undefined, o:
|
|
|
349
353
|
// an earlier scan's object dir held and dropped: their ids are right, and
|
|
350
354
|
// `--missing-ok` lets the tree be written from the ids alone
|
|
351
355
|
const ignoredTreeOid = forceAdd.length > 0 ? gitOrThrow(root, ['write-tree', '--missing-ok'], on(ignoredIndex)).trim() : null
|
|
356
|
+
const submodules: string[] = []
|
|
357
|
+
/** the declared paths the tree holds as a submodule, with the commit each stands at */
|
|
358
|
+
const gitlinks = new Map<string, string>()
|
|
352
359
|
const done = (oidByPath: Map<string, string>, files?: readonly string[]): ScanResult => {
|
|
353
|
-
const r: ScanResult = { treeOid, oidByPath, missing: [...new Set(missing)].sort(), excluded, ignored, ignoredTreeOid, ...(files == null ? {} : { files }), ms: performance.now() - started }
|
|
354
|
-
if (memoKey != null) remember(memoKey, { ...r, oidByPath: new Map(oidByPath), missing: [...r.missing] })
|
|
360
|
+
const r: ScanResult = { treeOid, oidByPath, missing: [...new Set(missing)].sort(), excluded, ignored, ignoredTreeOid, ...(submodules.length > 0 ? { submodules: [...submodules] } : {}), ...(files == null ? {} : { files }), ms: performance.now() - started }
|
|
361
|
+
if (memoKey != null && submodules.length === 0) remember(memoKey, { ...r, oidByPath: new Map(oidByPath), missing: [...r.missing] })
|
|
355
362
|
return r
|
|
356
363
|
}
|
|
357
364
|
// both root trees unchanged and the same paths on disk: every path under
|
|
358
365
|
// them names the same object, so the per path answer is the prior one
|
|
359
|
-
if (prior != null && prior.treeOid === treeOid && prior.ignoredTreeOid === ignoredTreeOid && prior.missing.join('\n') === [...new Set(missing)].sort().join('\n') && (o.treeOnly !== true || prior.files != null))
|
|
366
|
+
if (prior != null && !(prior.submodules?.length) && prior.treeOid === treeOid && prior.ignoredTreeOid === ignoredTreeOid && prior.missing.join('\n') === [...new Set(missing)].sort().join('\n') && (o.treeOnly !== true || prior.files != null))
|
|
360
367
|
return done(new Map(prior.oidByPath), prior.files)
|
|
361
368
|
const oidByPath = new Map<string, string>()
|
|
362
369
|
// a declared path is relative to root, and `<tree>:<path>` reads from the
|
|
@@ -386,19 +393,54 @@ function stage(root: string, wanted: string[], prior: ScanResult | undefined, o:
|
|
|
386
393
|
throw new GitScanError(`git cat-file --batch-check answered ${lines.length} of ${paths.length} paths`)
|
|
387
394
|
paths.forEach((path, i) => {
|
|
388
395
|
const oid = lines[i]!.split(' ')[0] ?? ''
|
|
389
|
-
|
|
390
|
-
//
|
|
391
|
-
|
|
392
|
-
|
|
396
|
+
if (/^[0-9a-f]{40}$/.test(oid)) return void oidByPath.set(path, oid)
|
|
397
|
+
// `missing` is also git's word for an entry whose OBJECT is gone: the warm index keeps a file's entry
|
|
398
|
+
// from scan to scan, git writes no blob for an entry that did not move, and the objects of the scan
|
|
399
|
+
// that wrote it were dropped with that scan. The tree still names the file, and that id is its content
|
|
400
|
+
const entry = entryOf(root, root_, underRoot(path), on(index))
|
|
401
|
+
if (entry?.mode === GITLINK) gitlinks.set(path, entry.oid)
|
|
402
|
+
else if (entry != null) return void oidByPath.set(path, entry.oid)
|
|
403
|
+
// a path git cannot name is a path we cannot key on
|
|
404
|
+
if (!missing.includes(path)) missing.push(path)
|
|
393
405
|
})
|
|
394
406
|
}
|
|
395
407
|
|
|
408
|
+
// a submodule is a commit of another repo, so no object here names it. While it holds no change of its own, the
|
|
409
|
+
// commit it stands at is its content; with one, it stays a path git cannot name, and nothing is keyed on it
|
|
410
|
+
for (const path of [...missing]) {
|
|
411
|
+
if (path === WHOLE_TREE || !existsSync(join(root, path))) continue
|
|
412
|
+
const link = gitlinks.get(path)
|
|
413
|
+
if (link == null) continue
|
|
414
|
+
submodules.push(path)
|
|
415
|
+
if (!submoduleClean(join(root, path))) continue
|
|
416
|
+
oidByPath.set(path, link)
|
|
417
|
+
missing.splice(missing.indexOf(path), 1)
|
|
418
|
+
}
|
|
396
419
|
if (o.treeOnly !== true) return done(oidByPath)
|
|
397
420
|
const whole = oidByPath.get(WHOLE_TREE)
|
|
398
421
|
if (whole == null) throw new GitScanError('git could not name the work tree')
|
|
399
422
|
return done(oidByPath, filesOf(root, whole, on(indexFile)))
|
|
400
423
|
}
|
|
401
424
|
|
|
425
|
+
/** the mode of a tree entry that is a submodule: its id is a commit of another repo */
|
|
426
|
+
const GITLINK = '160000'
|
|
427
|
+
|
|
428
|
+
/** what a tree holds at `path`, read from the tree itself: its mode and its id, whether the object is at hand or not */
|
|
429
|
+
function entryOf(root: string, tree: string, path: string, env: Record<string, string>): { mode: string; oid: string } | null {
|
|
430
|
+
const p = Bun.spawnSync([gitBin(), 'ls-tree', tree, '--', path], { cwd: root, stdout: 'pipe', stderr: 'ignore', env: { ...process.env, ...env } })
|
|
431
|
+
const m = /^(\d{6}) \w+ ([0-9a-f]{40})\t/.exec(p.stdout.toString())
|
|
432
|
+
return p.exitCode === 0 && m ? { mode: m[1]!, oid: m[2]! } : null
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** a submodule's work tree is there and holds no change of its own: nothing modified, nothing untracked, in it or
|
|
436
|
+
* in a submodule of its own. A folder with no `.git` is a submodule nobody filled (a new worktree has them so): git
|
|
437
|
+
* would answer there for the repo around it, so it is never clean. The two flags hold whatever its config says */
|
|
438
|
+
function submoduleClean(dir: string): boolean {
|
|
439
|
+
if (!existsSync(join(dir, '.git'))) return false
|
|
440
|
+
const p = Bun.spawnSync([gitBin(), 'status', '--porcelain', '--untracked-files=all', '--ignore-submodules=none'], { cwd: dir, stdout: 'pipe', stderr: 'ignore' })
|
|
441
|
+
return p.exitCode === 0 && p.stdout.toString().trim() === ''
|
|
442
|
+
}
|
|
443
|
+
|
|
402
444
|
/** a tree id names its content, so its file list is a pure function of the
|
|
403
445
|
* id and one listing serves every scan of that tree. `--full-tree` keeps it
|
|
404
446
|
* so: without it git filters the listing by the cwd's path under the work
|
|
@@ -39,6 +39,17 @@ export type Stamps = { seen: string; ran: string; fullAt?: number; waitAt?: numb
|
|
|
39
39
|
export type Batch = { paths: string[]; all: boolean; done: boolean }
|
|
40
40
|
type Locals = Record<string, { at: number; files: string[] }>
|
|
41
41
|
|
|
42
|
+
/** each repo's `*.local.*` files as the daemon's looks keep them, for a reader that only looks (`sk backup --check`):
|
|
43
|
+
* the kept list while it is fresh, else the repo's own git walk, which takes seconds in a repo with a large ignored
|
|
44
|
+
* folder. Nothing is written */
|
|
45
|
+
export function keptLocals(now: () => number = Date.now): (repo: string) => Promise<string[]> {
|
|
46
|
+
const locals: Locals = machineGet<Locals>(LOCALS) ?? {}
|
|
47
|
+
return async (repo) => {
|
|
48
|
+
const held = locals[repo]
|
|
49
|
+
return held && now() - held.at < LOCALS_MS ? held.files : localFiles(repo)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
export interface BackupTick {
|
|
43
54
|
home: string
|
|
44
55
|
repos: string[]
|
|
@@ -277,10 +277,7 @@ const isLocalName = (rel: string): boolean => {
|
|
|
277
277
|
/** a moved path the repo's `*.local.*` git walk must read again */
|
|
278
278
|
export const movesLocals = (abs: string, repos: readonly string[]): string | null => (isLocalName(abs) ? (repos.find((r) => abs.startsWith(`${r}${sep}`)) ?? null) : null)
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
* partial copy (`.!<pid>!x`). Its rename into place is heard on its own, so the watch never hears the temp: the gate
|
|
282
|
-
* writes one at each run */
|
|
283
|
-
export const isTransient = (name: string): boolean => /\.tmp(?:$|[-.])|^\.!\d+!/.test(name)
|
|
280
|
+
export { isTransient } from '../../core/transient.ts'
|
|
284
281
|
|
|
285
282
|
const isFileName = (name: string): boolean => /\.[^.]+$/.test(name) && !name.startsWith('.')
|
|
286
283
|
|