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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
## 2.26.0
|
|
2
|
+
|
|
3
|
+
- **A slow hook is refused.** SK045 fails a repo whose hook on every tool call (`PreToolUse`, `PostToolUse`) takes over 150 ms on a no-op Bash call, and fails a hook on a save as soon as it is wired, unless `repo.config.ts` names it under `instantHooks` with the reason it is instant. SK046 warns on the runs the harness recorded. `sk time hooks` shows what each hook cost.
|
|
4
|
+
- **A suite that fails only in a loaded pool runs again alone** before the gate goes red: it passes alone, the gate warns and names the file and the load; it fails alone too, the machine was quiet, or more than three suites failed, the red stands.
|
|
5
|
+
- **The cache**: a submodule declared as an input keys by the commit it stands at while it is filled and holds no change of its own; an ignored file named as an input keeps its key after the first scan; a write in flight (`.dist.tmp-<pid>`) is never proposed as an ignored input.
|
|
6
|
+
- **A defect of a toolkit check never fails another repo's gate**: the check runs there with no cache and says whose defect it is; the repo that hosts the toolkit still fails on it.
|
|
7
|
+
- **Review**: once no watch of a card's lane or session lives, whoever reads the answer marks it seen; `sk review inbox --hook` runs the inbox as a Claude Code hook on a prompt and at a turn's end; the worker that blocked a raised item takes it back or closes it.
|
|
8
|
+
- **`sk releases remove <card id | title>`** takes one change out of the next release file.
|
|
9
|
+
- **`sk wiki lint`** checks that an anchor names a heading of its page; a changelog or a journal keeps a link as written.
|
|
10
|
+
- **`sk mv`** leaves archived repros and field notes as written too.
|
|
11
|
+
- **`sk backup --check`** reads the local files the daemon's looks keep, three times faster.
|
|
12
|
+
- **The bun types follow the machine's bun** (`@types/bun` ^1.4.4).
|
|
13
|
+
|
|
14
|
+
## 2.25.0
|
|
15
|
+
|
|
16
|
+
- **A repo adjusts its own lane count.** `sk capacity` answers how many lanes this repo runs now from the cores, the 1 minute load and the agents at work: never zero, `--max <n>` is the count the owner gave, and only a machine at twice its cores of load stops a lane. `sk lanes` shows each live session and lane, since when, and what it does.
|
|
17
|
+
- **A mistyped command answers in two lines** with the close command, the words after the slip kept (`did you mean sk review inbox ?`), where the parser printed every registered command. A family name (`sk gate --help`) lists its family, a word several commands start with lists them, and a known command on a line that does not fit answers with its usage.
|
|
18
|
+
- **`--help` typed after a command's arguments gives its help**, and help read through a pipe carries no colour codes.
|
|
19
|
+
- **`sk status <id> --wait`** holds until the detached gate has a verdict and prints it first: one call in place of a poll. With no id, status reads the latest run `--detach` started, never a job of the daemon. An unknown check id names the close ones.
|
|
20
|
+
- **`sk checks <word>` and `sk config-keys <word>`** keep the rows a word names.
|
|
21
|
+
- **The cache**: a stale lock a killed git left on the scan's index no longer costs a repo its whole cache. A check can mark an input `optional`, and a missing one keys as absent, so the built-in checks that read an optional file replay again. A workspace package a unit imports joins its keys, and another unit's run config no longer reruns every suite.
|
|
22
|
+
- **The daemon's plan** runs a check with no key when its reason changes or a tracked input moved, never at each save whatever moved: its own run wrote files, which was a loop.
|
|
23
|
+
- **The backup's look costs nothing while no source moves.** The daemon watches the sources; a look reads only what moved, a run reads only the files whose size or time moved, and a full walk runs every 30 min as a safety net. A review rule's log is no source.
|
|
24
|
+
- **The media store job** asks a stat before it starts a child: a pass that found nothing waits 5 min unless a store folder moves.
|
|
25
|
+
- **`sk shot`**: a page that navigates while it loads is shot where it lands, `--full` shoots the whole page, a file path is taken, a request the app refused prints its own line, and the warm shot service runs its new code once idle.
|
|
26
|
+
- **`sk mv`**: a longer path that only ends with the moved one is another file and stays; a page moved into a folder that already holds files no longer leaves the tree half moved; a plan, a changelog and a journal stay as written (`--history` rewrites them too), and `sk wiki lint` lets one name a path git once held.
|
|
27
|
+
- **`sk wiki lint`** sees a link with an anchor or a title.
|
|
28
|
+
- **Review**: `add-view` takes `add`'s view flags and never stores a flag as a label; a refusal names a step that works; `withdraw` and `done` on a card already closed say so and exit 0; a short id works in every verb; `withdraw` takes `--note` too; a media field reads on any `ReviewView`, and `'files' in view` still narrows.
|
|
29
|
+
- **`sk annex`** lists in well under a second with one line per repo (`--all` for every link); `sk backup runs` and `sk rec` answer with a count, then the newest.
|
|
30
|
+
- **`sk time`** finds its repo from a subfolder or a worktree, and its first line is the answer; `sk calls` names the command each run was.
|
|
31
|
+
- **The release gate's throwaway checkout** cleans a read only folder a check left in it.
|
|
32
|
+
- **`sk assets fill|add|gen`**: the help says a roll of a comfy asset is a job on the GPU box.
|
|
33
|
+
|
|
1
34
|
## 2.24.0
|
|
2
35
|
|
|
3
36
|
- **A slot of the machine pool is one core.** A suite run holds one slot per worker it starts, by its kept suite time (one worker per 4 s, at most half the cores), and gives the slots back when its parallel phase ends. One gate used to start 8 workers per suite whatever its size, and the load that followed closed the pool to one check for the whole machine.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rvlib-shipkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.0",
|
|
4
4
|
"funding": "https://github.com/sponsors/rvion",
|
|
5
5
|
"description": "All-in-one repo companion: ci gate (task DAG), auto-discovered health checks, release-contract fulfillness, asks queue, md-wiki tools, asset atelier, live tui",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"./src/*": "./src/*"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/bun": "^1.
|
|
26
|
+
"@types/bun": "^1.4.4",
|
|
27
27
|
"@types/react": "^19.2.17",
|
|
28
28
|
"@types/react-dom": "^19.2.3",
|
|
29
29
|
"@types/sanitize-html": "^2.16.1",
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// HOOKS ON THE AGENT'S PATH: what the settings wire to run on each tool call or
|
|
2
|
+
// each turn, the budget of each cadence, the probe a gate may run, and the
|
|
3
|
+
// verdicts of SK045 (the gate) and SK046 (the recorded runs, a warning).
|
|
4
|
+
// `sk time hooks` reads the same declarations.
|
|
5
|
+
//
|
|
6
|
+
// The constraint a reader breaks first: the harness records a hook's run only
|
|
7
|
+
// when the hook printed something, so a silent hook has no record, and a hook
|
|
8
|
+
// the probe may not run (one on a save may write) has no measure at all.
|
|
9
|
+
import { createHash } from 'crypto'
|
|
10
|
+
import { existsSync, readFileSync, realpathSync, statSync } from 'fs'
|
|
11
|
+
import { homedir } from 'os'
|
|
12
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'path'
|
|
13
|
+
import { gitBin } from '../core/git-bin.ts'
|
|
14
|
+
import { houseOfIndex } from '../home/home-paths.ts'
|
|
15
|
+
import { discoverConfigRoots } from '../reflect/prompt-corpus.ts'
|
|
16
|
+
import { homeRepo, houseIndex } from '../serve/project-gutter.ts'
|
|
17
|
+
|
|
18
|
+
/** how often a hook stands in the agent's way */
|
|
19
|
+
export type Cadence = 'call' | 'turn' | 'other'
|
|
20
|
+
|
|
21
|
+
const CADENCE: Record<string, Cadence> = { PreToolUse: 'call', PostToolUse: 'call', PostToolUseFailure: 'call', UserPromptSubmit: 'turn', Stop: 'turn', SubagentStop: 'turn' }
|
|
22
|
+
export const cadenceOf = (event: string): Cadence => CADENCE[event] ?? 'other'
|
|
23
|
+
|
|
24
|
+
/** a hook on every tool call: bun's own start is about 60 ms on a loaded Mac,
|
|
25
|
+
* so this leaves a guard room to read a file or two, and a whole tree
|
|
26
|
+
* typecheck (a median near a second) is far over */
|
|
27
|
+
export const CALL_BUDGET_MS = 150
|
|
28
|
+
/** a hook on each prompt or turn end runs once per many calls: ten times
|
|
29
|
+
* more, and over it warns, never fails */
|
|
30
|
+
export const TURN_BUDGET_MS = 1000
|
|
31
|
+
/** recorded runs a median needs before it judges */
|
|
32
|
+
export const MIN_RUNS = 5
|
|
33
|
+
/** records older than this describe another machine load and another tree */
|
|
34
|
+
export const RECORD_DAYS = 30
|
|
35
|
+
/** probe runs after one warm up: the fastest is a floor no load explains */
|
|
36
|
+
export const PROBE_RUNS = 5
|
|
37
|
+
|
|
38
|
+
export type HookSource = 'repo' | 'local' | 'user'
|
|
39
|
+
|
|
40
|
+
/** one hook as a settings file declares it; `command` is '' for a hook of
|
|
41
|
+
* another type, named by `type` */
|
|
42
|
+
export type DeclaredHook = { event: string; matcher: string; type: string; command: string; timeoutS: number | null; source: HookSource; file: string }
|
|
43
|
+
|
|
44
|
+
type RawSettings = { hooks?: Record<string, { matcher?: unknown; hooks?: { type?: unknown; command?: unknown; timeout?: unknown }[] }[]> }
|
|
45
|
+
|
|
46
|
+
/** the hooks of one settings text; throws on text that is not JSON */
|
|
47
|
+
export function parseHooks(text: string, source: HookSource, file: string): DeclaredHook[] {
|
|
48
|
+
const j = JSON.parse(text) as RawSettings
|
|
49
|
+
const out: DeclaredHook[] = []
|
|
50
|
+
for (const [event, entries] of Object.entries(j?.hooks ?? {})) {
|
|
51
|
+
if (!Array.isArray(entries)) continue
|
|
52
|
+
for (const e of entries) {
|
|
53
|
+
const matcher = typeof e?.matcher === 'string' ? e.matcher : ''
|
|
54
|
+
for (const h of Array.isArray(e?.hooks) ? e.hooks : []) {
|
|
55
|
+
const type = typeof h?.type === 'string' ? h.type : 'command'
|
|
56
|
+
const command = type === 'command' && typeof h?.command === 'string' ? h.command : ''
|
|
57
|
+
out.push({ event, matcher, type, command, timeoutS: typeof h?.timeout === 'number' ? h.timeout : null, source, file })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const REPO_SETTINGS = ['.claude/settings.json', '.claude/settings.local.json'] as const
|
|
65
|
+
|
|
66
|
+
/** the hooks a repo's own settings declare, and the files that did not parse */
|
|
67
|
+
export function repoHooks(root: string): { hooks: DeclaredHook[]; broken: string[] } {
|
|
68
|
+
const hooks: DeclaredHook[] = []
|
|
69
|
+
const broken: string[] = []
|
|
70
|
+
for (const rel of REPO_SETTINGS) {
|
|
71
|
+
const text = readOrNull(join(root, rel))
|
|
72
|
+
if (text == null) continue
|
|
73
|
+
try {
|
|
74
|
+
hooks.push(...parseHooks(text, rel.endsWith('.local.json') ? 'local' : 'repo', rel))
|
|
75
|
+
} catch {
|
|
76
|
+
broken.push(rel)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { hooks, broken }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** the settings file of every Claude Code account on the machine */
|
|
83
|
+
export function userSettingsFiles(home = homedir()): string[] {
|
|
84
|
+
return discoverConfigRoots(home).map((r) => join(dirname(r.projects), 'settings.json')).filter((f) => existsSync(f))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** the hooks every account declares for every repo; one entry per distinct
|
|
88
|
+
* hook, its file the first account that declares it */
|
|
89
|
+
export function userHooks(home = homedir()): DeclaredHook[] {
|
|
90
|
+
const seen = new Map<string, DeclaredHook>()
|
|
91
|
+
for (const f of userSettingsFiles(home)) {
|
|
92
|
+
const text = readOrNull(f)
|
|
93
|
+
if (text == null) continue
|
|
94
|
+
let hooks: DeclaredHook[]
|
|
95
|
+
try {
|
|
96
|
+
hooks = parseHooks(text, 'user', f.startsWith(`${home}/`) ? `~/${relative(home, f)}` : f)
|
|
97
|
+
} catch {
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
for (const h of hooks) if (!seen.has(hookKey(h))) seen.set(hookKey(h), h)
|
|
101
|
+
}
|
|
102
|
+
return [...seen.values()]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** this repo is the house, the one gate that judges the machine's own hooks */
|
|
106
|
+
export function isHouse(root: string): boolean {
|
|
107
|
+
const index = houseIndex(homeRepo(root), homedir())
|
|
108
|
+
return index != null && houseOfIndex(index) === root
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** a settings file that does not parse still applies: the check says so */
|
|
112
|
+
export function hasHooks(root: string): boolean {
|
|
113
|
+
const r = repoHooks(root)
|
|
114
|
+
return r.hooks.length > 0 || r.broken.length > 0 || (isHouse(root) && userHooks().length > 0)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const hookKey = (h: { event: string; matcher?: string; command: string }): string => `${h.event}\u0000${h.matcher ?? ''}\u0000${h.command}`
|
|
118
|
+
|
|
119
|
+
/** Claude Code's matcher: none, `*` or `.*` takes every tool, else a regex on the whole tool name */
|
|
120
|
+
export function matcherMatches(matcher: string, tool: string): boolean {
|
|
121
|
+
const m = matcher.trim()
|
|
122
|
+
if (m === '' || m === '*' || m === '.*') return true
|
|
123
|
+
try {
|
|
124
|
+
return new RegExp(`^(?:${m})$`).test(tool)
|
|
125
|
+
} catch {
|
|
126
|
+
return m === tool
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const matcherLabel = (matcher: string): string => (['', '*', '.*'].includes(matcher.trim()) ? 'every tool' : matcher)
|
|
131
|
+
|
|
132
|
+
// ── the probe ──────────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
const PROBE_ID = 'shipkit-hook-probe'
|
|
135
|
+
|
|
136
|
+
/** the probe runs a hook only on what the harness itself sends for a Bash
|
|
137
|
+
* `true`, a call that changes nothing, so it does no more than a real no-op
|
|
138
|
+
* call does. A hook whose matcher takes no Bash call is never run: on a
|
|
139
|
+
* made up save it may write, and its cost hangs on the file it is given */
|
|
140
|
+
export const probeable = (h: DeclaredHook): boolean => h.command !== '' && (h.event === 'PreToolUse' || h.event === 'PostToolUse') && matcherMatches(h.matcher, 'Bash')
|
|
141
|
+
|
|
142
|
+
export function probeInput(h: DeclaredHook, root: string): string {
|
|
143
|
+
const base = { session_id: PROBE_ID, transcript_path: '', cwd: root, permission_mode: 'default', hook_event_name: h.event, tool_name: 'Bash', tool_input: { command: 'true', description: 'a no-op' }, tool_use_id: PROBE_ID }
|
|
144
|
+
return JSON.stringify(h.event === 'PostToolUse' ? { ...base, tool_response: { stdout: '', stderr: '', interrupted: false, isImage: false } } : base)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type Probe = { ms: number[]; code: number | null; timedOut: boolean }
|
|
148
|
+
|
|
149
|
+
/** the env a probed hook gets: the caller's, minus the live session's own
|
|
150
|
+
* channel (its id, messaging socket and token, pid), plus the project dir */
|
|
151
|
+
export function probeEnv(from: Record<string, string | undefined>, root: string): Record<string, string | undefined> {
|
|
152
|
+
const env: Record<string, string | undefined> = {}
|
|
153
|
+
for (const [k, v] of Object.entries(from)) if (!k.startsWith('CLAUDE_CODE_') && k !== 'CLAUDE_PID') env[k] = v
|
|
154
|
+
env.CLAUDE_PROJECT_DIR = root
|
|
155
|
+
return env
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** the hook run as the harness runs it (a shell, the repo as its project dir,
|
|
159
|
+
* the input on stdin), once to warm up and PROBE_RUNS times measured */
|
|
160
|
+
export async function probeHook(h: DeclaredHook, root: string, runs = PROBE_RUNS): Promise<Probe> {
|
|
161
|
+
const env = probeEnv(process.env, root)
|
|
162
|
+
const input = Buffer.from(probeInput(h, root))
|
|
163
|
+
const capMs = Math.min(h.timeoutS ?? 60, 5) * 1000
|
|
164
|
+
const ms: number[] = []
|
|
165
|
+
let code: number | null = null
|
|
166
|
+
for (let i = 0; i <= runs; i++) {
|
|
167
|
+
const t0 = performance.now()
|
|
168
|
+
const p = Bun.spawn(['/bin/sh', '-c', h.command], { cwd: root, env, stdin: input, stdout: 'ignore', stderr: 'ignore' })
|
|
169
|
+
const timer = setTimeout(() => p.kill(9), capMs)
|
|
170
|
+
code = await p.exited
|
|
171
|
+
clearTimeout(timer)
|
|
172
|
+
const took = performance.now() - t0
|
|
173
|
+
if (took >= capMs) return { ms: [...ms, took], code, timedOut: true }
|
|
174
|
+
// exit 2 is a block, an answer like any other; anything else but 0 means it did not run as meant
|
|
175
|
+
if (code !== 0 && code !== 2) return { ms, code, timedOut: false }
|
|
176
|
+
if (i > 0) ms.push(took)
|
|
177
|
+
}
|
|
178
|
+
return { ms, code, timedOut: false }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── when the hook last changed ─────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
/** the files a command names: its quoted or bare paths, the project dir and ~ expanded */
|
|
184
|
+
export function scriptsOf(command: string, root: string, home = homedir()): string[] {
|
|
185
|
+
const out: string[] = []
|
|
186
|
+
for (const raw of command.replace(/["']/g, '').split(/\s+/)) {
|
|
187
|
+
const t = raw.replace(/\$\{?CLAUDE_PROJECT_DIR\}?/g, root).replace(/^~(?=\/)/, home)
|
|
188
|
+
if (!t.includes('/')) continue
|
|
189
|
+
const p = isAbsolute(t) ? t : resolve(root, t)
|
|
190
|
+
try {
|
|
191
|
+
if (statSync(p).isFile()) out.push(p)
|
|
192
|
+
} catch { /* not a file */ }
|
|
193
|
+
}
|
|
194
|
+
return out
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** when the files a hook runs last changed: a tracked file its last commit
|
|
198
|
+
* while it is clean, any other its mtime; null when it names none. A record
|
|
199
|
+
* older than this timed another version of the hook */
|
|
200
|
+
export function changedAt(command: string, root: string, home = homedir()): number | null {
|
|
201
|
+
let at: number | null = null
|
|
202
|
+
for (const f of scriptsOf(command, root, home)) {
|
|
203
|
+
const real = safeReal(f)
|
|
204
|
+
const rel = relative(root, real)
|
|
205
|
+
let t: number | null = null
|
|
206
|
+
if (!rel.startsWith('..') && !rel.split('/').includes('node_modules')) {
|
|
207
|
+
const dirty = Bun.spawnSync([gitBin(), 'status', '--porcelain', '--', rel], { cwd: root, stdout: 'pipe', stderr: 'ignore' })
|
|
208
|
+
if (dirty.exitCode === 0 && dirty.stdout.toString().trim() === '') {
|
|
209
|
+
const log = Bun.spawnSync([gitBin(), 'log', '-1', '--format=%ct', '--', rel], { cwd: root, stdout: 'pipe', stderr: 'ignore' })
|
|
210
|
+
const s = Number(log.stdout.toString().trim())
|
|
211
|
+
if (log.exitCode === 0 && s > 0) t = s * 1000
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (t == null) t = statSync(real).mtimeMs
|
|
215
|
+
if (at == null || t > at) at = t
|
|
216
|
+
}
|
|
217
|
+
return at
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** what a cached answer is keyed on: the settings texts and the stamp of each file their hooks run */
|
|
221
|
+
export function hooksKey(root: string, settings: string[], home = homedir()): string {
|
|
222
|
+
const h = createHash('sha1')
|
|
223
|
+
for (const f of settings) {
|
|
224
|
+
const text = readOrNull(isAbsolute(f) ? f : join(root, f))
|
|
225
|
+
h.update(`${f}\u0000${text ?? '-'}\u0000`)
|
|
226
|
+
if (text == null) continue
|
|
227
|
+
let hooks: DeclaredHook[] = []
|
|
228
|
+
try {
|
|
229
|
+
hooks = parseHooks(text, 'repo', f)
|
|
230
|
+
} catch { /* the body reports it */ }
|
|
231
|
+
for (const x of hooks)
|
|
232
|
+
for (const s of scriptsOf(x.command, root, home)) {
|
|
233
|
+
const st = statSync(safeReal(s))
|
|
234
|
+
h.update(`${s}:${st.size}:${Math.floor(st.mtimeMs)}\u0000`)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return h.digest('hex').slice(0, 16)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ── the verdict ────────────────────────────────────────────────────────────
|
|
241
|
+
|
|
242
|
+
export type Measure = { runs: number; p50: number; p90: number; max: number; total: number }
|
|
243
|
+
|
|
244
|
+
export function measureOf(ms: number[]): Measure | null {
|
|
245
|
+
if (ms.length === 0) return null
|
|
246
|
+
const s = [...ms].sort((a, b) => a - b)
|
|
247
|
+
const q = (p: number): number => s[Math.min(s.length - 1, Math.floor(p * s.length))] ?? 0
|
|
248
|
+
return { runs: s.length, p50: q(0.5), p90: q(0.9), max: s[s.length - 1] ?? 0, total: s.reduce((a, b) => a + b, 0) }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export type Verdict = { level: 'ok' | 'warn' | 'fail'; text: string; fix?: string }
|
|
252
|
+
|
|
253
|
+
/** 40 ms, 1.3 s */
|
|
254
|
+
export const fmtHookMs = (ms: number): string => (ms < 1000 ? `${Math.round(ms)} ms` : `${(ms / 1000).toFixed(1)} s`)
|
|
255
|
+
|
|
256
|
+
const recordedWords = (m: Measure): string => `median ${fmtHookMs(m.p50)} over ${m.runs} recorded run${m.runs === 1 ? '' : 's'} (p90 ${fmtHookMs(m.p90)}, worst ${fmtHookMs(m.max)})`
|
|
257
|
+
|
|
258
|
+
const probeWords = (p: Probe): string => {
|
|
259
|
+
const m = measureOf(p.ms)
|
|
260
|
+
return m == null ? 'no probe run' : `fastest ${fmtHookMs(Math.min(...p.ms))}, median ${fmtHookMs(m.p50)} of ${m.runs} probe runs on a no-op Bash call`
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export const hookLabel = (h: DeclaredHook): string =>
|
|
264
|
+
`${cadenceOf(h.event) === 'call' ? `${h.event} on ${matcherLabel(h.matcher)}` : h.event} (${h.file}): ${h.command === '' ? `a ${h.type} hook` : `\`${h.command}\``}`
|
|
265
|
+
|
|
266
|
+
/** the key of repo.config.ts that declares a hook the gate cannot time */
|
|
267
|
+
export const INSTANT_KEY = 'instantHooks'
|
|
268
|
+
|
|
269
|
+
const NOT_RECORDED = 'the harness records a hook run only when the hook prints something'
|
|
270
|
+
const AS_A_CHECK = 'work over the tree runs as a check when the step is done: sk ci --only <check>'
|
|
271
|
+
|
|
272
|
+
/** SK045's verdict on one per call hook, from what the gate itself can tell:
|
|
273
|
+
* its probe, or the repo's word that it answers at once. `instant` is the
|
|
274
|
+
* reason the repo declares, `machine` (a user level hook) turns a fail into a warn */
|
|
275
|
+
export function judgeGate(h: DeclaredHook, probe: Probe | null, opts: { instant?: string; machine?: boolean } = {}): Verdict {
|
|
276
|
+
const label = hookLabel(h)
|
|
277
|
+
const red = opts.machine ? 'warn' : 'fail'
|
|
278
|
+
const lift = h.source === 'user' ? `drop it from ${h.file}` : `remove its entry in ${h.file}`
|
|
279
|
+
if (probe == null) {
|
|
280
|
+
if (opts.instant != null) return { level: 'ok', text: `${label}: declared instant in repo.config.ts (${opts.instant}); its recorded runs: SK046` }
|
|
281
|
+
return {
|
|
282
|
+
level: red,
|
|
283
|
+
text: `${label}: a hook on every ${matcherLabel(h.matcher)} call that the gate cannot time (it runs only a hook that takes a Bash call: a made up save may write, and its cost hangs on the file), and repo.config.ts does not declare it instant`,
|
|
284
|
+
fix: `${lift}, or declare it in repo.config.ts ${INSTANT_KEY} with the reason it answers at once; ${AS_A_CHECK}`,
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (probe.timedOut || (probe.ms.length > 0 && Math.min(...probe.ms) > CALL_BUDGET_MS && (probe.code === 0 || probe.code === 2)))
|
|
288
|
+
return {
|
|
289
|
+
level: red,
|
|
290
|
+
text: `${label}: ${probe.timedOut ? `a probe run on a no-op Bash call took over ${fmtHookMs(probe.ms[probe.ms.length - 1] ?? 0)}` : probeWords(probe)}, over the ${CALL_BUDGET_MS} ms budget of a hook on every tool call${h.source === 'user' ? ' (a hook of every session on the machine)' : ''}`,
|
|
291
|
+
fix: `make it read its input and decide under ${CALL_BUDGET_MS} ms, or ${lift}; ${AS_A_CHECK}`,
|
|
292
|
+
}
|
|
293
|
+
if (probe.code !== 0 && probe.code !== 2)
|
|
294
|
+
return { level: 'warn', text: `${label}: its probe exited ${probe.code} on a no-op Bash call, so every call it applies to runs a broken hook`, fix: `run it by hand on a Bash call's input and fix its command, or ${lift}` }
|
|
295
|
+
return { level: 'ok', text: `${label}: ${probeWords(probe)}` }
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** SK046's verdict on one hook from the runs the harness recorded: a warning
|
|
299
|
+
* past the budget of its cadence, never a fail (the index is the world) */
|
|
300
|
+
export function judgeRecords(h: DeclaredHook, recorded: number[], behind?: string): Verdict {
|
|
301
|
+
const label = hookLabel(h)
|
|
302
|
+
const rec = measureOf(recorded)
|
|
303
|
+
const cadence = cadenceOf(h.event)
|
|
304
|
+
const budget = cadence === 'call' ? CALL_BUDGET_MS : TURN_BUDGET_MS
|
|
305
|
+
if (rec == null) return { level: 'ok', text: `${label}: no timed run recorded (${NOT_RECORDED})${behind == null ? '' : `; ${behind}`}` }
|
|
306
|
+
if (rec.runs >= MIN_RUNS && rec.p50 > budget)
|
|
307
|
+
return {
|
|
308
|
+
level: 'warn',
|
|
309
|
+
text: `${label}: ${recordedWords(rec)}, over the ${fmtHookMs(budget)} budget of a hook on every ${cadence === 'call' ? 'tool call' : 'prompt or turn end'}`,
|
|
310
|
+
fix: `make it read its input and decide under ${fmtHookMs(budget)}, or remove it; ${AS_A_CHECK}`,
|
|
311
|
+
}
|
|
312
|
+
return { level: 'ok', text: `${label}: ${recordedWords(rec)}${rec.runs < MIN_RUNS ? `, ${MIN_RUNS} needed to judge` : ''}` }
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function readOrNull(path: string): string | null {
|
|
316
|
+
try {
|
|
317
|
+
return readFileSync(path, 'utf8')
|
|
318
|
+
} catch {
|
|
319
|
+
return null
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function safeReal(p: string): string {
|
|
324
|
+
try {
|
|
325
|
+
return realpathSync(p)
|
|
326
|
+
} catch {
|
|
327
|
+
return p
|
|
328
|
+
}
|
|
329
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// WHO IS AT WORK ON THE MACHINE NOW, read from the transcripts every agent
|
|
2
|
+
// already writes: one row per live session and per live lane (a sub-agent),
|
|
3
|
+
// with what it does this second. No agent reports anything: the view costs
|
|
4
|
+
// no turn.
|
|
5
|
+
//
|
|
6
|
+
// The one constraint a reader breaks first: a transcript is read at its two
|
|
7
|
+
// ends only. A session's file reaches hundreds of megabytes, and this runs
|
|
8
|
+
// each time someone looks.
|
|
9
|
+
import { closeSync, openSync, readFileSync, readSync, statSync } from 'fs'
|
|
10
|
+
import type { TranscriptFile } from './store.ts'
|
|
11
|
+
|
|
12
|
+
const HEAD_BYTES = 64 * 1024
|
|
13
|
+
const TAIL_BYTES = 256 * 1024
|
|
14
|
+
/** a lane's file is read whole to count its calls up to this size; a larger one shows no count */
|
|
15
|
+
const COUNT_MAX_BYTES = 16 * 1024 * 1024
|
|
16
|
+
|
|
17
|
+
export type LiveState =
|
|
18
|
+
| { kind: 'tool'; what: string }
|
|
19
|
+
/** its request to the model is in flight */
|
|
20
|
+
| { kind: 'model' }
|
|
21
|
+
/** its turn ended: a lane is done, a session waits for its user */
|
|
22
|
+
| { kind: 'ended' }
|
|
23
|
+
| { kind: 'unknown' }
|
|
24
|
+
|
|
25
|
+
export type LiveRow = {
|
|
26
|
+
project: string
|
|
27
|
+
/** the folder it works in, as its first entry says: the repo's name comes from it */
|
|
28
|
+
cwd: string
|
|
29
|
+
session: string
|
|
30
|
+
/** '' for a session, the sub-agent's id for a lane */
|
|
31
|
+
agent: string
|
|
32
|
+
/** a lane's description as its orchestrator gave it, '' when none is kept */
|
|
33
|
+
name: string
|
|
34
|
+
model: string
|
|
35
|
+
startedAt: number | null
|
|
36
|
+
/** when its last entry was written, and what that entry says it does */
|
|
37
|
+
at: number
|
|
38
|
+
state: LiveState
|
|
39
|
+
/** tool calls so far, null when the file is too large to count */
|
|
40
|
+
calls: number | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type Entry = { type?: string; timestamp?: string; message?: { content?: unknown } }
|
|
44
|
+
type Part = { type?: string; name?: string; input?: Record<string, unknown> }
|
|
45
|
+
|
|
46
|
+
const parts = (e: Entry): Part[] => (Array.isArray(e.message?.content) ? (e.message.content as Part[]) : [])
|
|
47
|
+
|
|
48
|
+
/** a tool call in a few words: the command's head, the file's name, a sub-agent's description */
|
|
49
|
+
export function callWords(p: Part): string {
|
|
50
|
+
const i = p.input ?? {}
|
|
51
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v : '')
|
|
52
|
+
const head = text(i.command) || text(i.description) || (text(i.file_path).split('/').at(-1) ?? '') || text(i.pattern) || text(i.query) || text(i.skill)
|
|
53
|
+
const one = head.replace(/\s+/g, ' ').trim()
|
|
54
|
+
return `${p.name ?? 'tool'}${one === '' ? '' : `: ${one.length > 70 ? `${one.slice(0, 69)}…` : one}`}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** the call a sub-agent ends on: its report handed back to the session that started it */
|
|
58
|
+
const HAND_BACK = 'SubagentHandback'
|
|
59
|
+
|
|
60
|
+
/** what the last entries of a transcript say the agent does now. `lines` are its last lines, oldest first */
|
|
61
|
+
export function stateOf(lines: readonly string[]): { state: LiveState; at: number } {
|
|
62
|
+
// a result just came back, or a request is in flight: a model turn, unless the call before it was the hand back
|
|
63
|
+
let waiting: number | null = null
|
|
64
|
+
for (let n = lines.length - 1; n >= 0; n--) {
|
|
65
|
+
let e: Entry
|
|
66
|
+
try { e = JSON.parse(lines[n]!) as Entry } catch { continue }
|
|
67
|
+
const at = e.timestamp == null ? NaN : Date.parse(e.timestamp)
|
|
68
|
+
if (!Number.isFinite(at)) continue
|
|
69
|
+
if (e.type === 'api-request' || e.type === 'user') { waiting ??= at; continue }
|
|
70
|
+
if (e.type !== 'assistant') continue
|
|
71
|
+
const calls = parts(e).filter((p) => p.type === 'tool_use')
|
|
72
|
+
if (calls.some((p) => p.name === HAND_BACK)) return { state: { kind: 'ended' }, at: waiting ?? at }
|
|
73
|
+
if (waiting != null) return { state: { kind: 'model' }, at: waiting }
|
|
74
|
+
return calls.length > 0 ? { state: { kind: 'tool', what: calls.map(callWords).join(' + ') }, at } : { state: { kind: 'ended' }, at }
|
|
75
|
+
}
|
|
76
|
+
return waiting != null ? { state: { kind: 'model' }, at: waiting } : { state: { kind: 'unknown' }, at: 0 }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const slice = (path: string, from: number, bytes: number): string => {
|
|
80
|
+
const fd = openSync(path, 'r')
|
|
81
|
+
try {
|
|
82
|
+
const buf = Buffer.alloc(bytes)
|
|
83
|
+
return buf.subarray(0, readSync(fd, buf, 0, bytes, from)).toString('utf8')
|
|
84
|
+
} finally { closeSync(fd) }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** one live transcript read at its two ends. `calls: false` skips the count, the one read of the whole file */
|
|
88
|
+
export function liveRow(f: TranscriptFile, o: { calls?: boolean } = {}): LiveRow {
|
|
89
|
+
const size = statSync(f.path).size
|
|
90
|
+
const tail = slice(f.path, Math.max(0, size - TAIL_BYTES), Math.min(size, TAIL_BYTES)).split('\n').filter((l) => l !== '')
|
|
91
|
+
// the first line of a tail cut mid file is a fragment
|
|
92
|
+
const { state, at } = stateOf(size > TAIL_BYTES ? tail.slice(1) : tail)
|
|
93
|
+
const head = slice(f.path, 0, Math.min(size, HEAD_BYTES))
|
|
94
|
+
const stamp = /"timestamp":"([^"]+)"/.exec(head)
|
|
95
|
+
const startedAt = stamp == null ? null : Date.parse(stamp[1]!)
|
|
96
|
+
const cwd = /"cwd":"([^"]+)"/.exec(head)?.[1] ?? ''
|
|
97
|
+
let name = ''
|
|
98
|
+
let model = ''
|
|
99
|
+
if (f.agent !== '') {
|
|
100
|
+
try {
|
|
101
|
+
const meta = JSON.parse(readFileSync(f.path.replace(/\.jsonl$/, '.meta.json'), 'utf8')) as { description?: unknown; model?: unknown; agentType?: unknown }
|
|
102
|
+
name = typeof meta.description === 'string' ? meta.description : typeof meta.agentType === 'string' ? meta.agentType : ''
|
|
103
|
+
model = typeof meta.model === 'string' ? meta.model : ''
|
|
104
|
+
} catch { /* an agent with no meta file keeps its id as its name */ }
|
|
105
|
+
}
|
|
106
|
+
const calls = o.calls === false || size > COUNT_MAX_BYTES ? null : (readFileSync(f.path, 'utf8').match(/"type":"tool_use"/g) ?? []).length
|
|
107
|
+
return { project: f.project, cwd, session: f.session, agent: f.agent, name, model, startedAt: startedAt != null && Number.isFinite(startedAt) ? startedAt : null, at: at > 0 ? at : f.mtime, state, calls }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const span = (ms: number): string => {
|
|
111
|
+
const s = Math.max(0, Math.round(ms / 1000))
|
|
112
|
+
return s < 60 ? `${s}s` : s < 3600 ? `${Math.floor(s / 60)}m` : `${Math.floor(s / 3600)}h${String(Math.floor((s % 3600) / 60)).padStart(2, '0')}`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const doing = (r: LiveRow, now: number): string => {
|
|
116
|
+
const age = span(now - r.at)
|
|
117
|
+
return r.state.kind === 'tool' ? `${r.state.what} (${age})`
|
|
118
|
+
: r.state.kind === 'model' ? `model turn (${age})`
|
|
119
|
+
: r.state.kind === 'ended' ? `${r.agent === '' ? 'waits for its user' : 'ended'} (${age})`
|
|
120
|
+
: `last wrote ${age} ago`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** the repo a row belongs to: the name of the folder it works in, a linked worktree counted with its repo */
|
|
124
|
+
export const repoOf = (r: { cwd: string; project: string }): string =>
|
|
125
|
+
r.cwd === '' ? r.project : r.cwd.replace(/\/\.claude\/worktrees\/.*$/, '').split('/').filter((w) => w !== '').at(-1) ?? r.project
|
|
126
|
+
|
|
127
|
+
/** one row an agent: a session resumed from another folder writes the same transcript under both, the newest stands */
|
|
128
|
+
export function oneRowAnAgent<T extends { session: string; agent: string; mtime: number }>(files: readonly T[]): T[] {
|
|
129
|
+
const by = new Map<string, T>()
|
|
130
|
+
for (const f of files) {
|
|
131
|
+
const k = `${f.session}/${f.agent}`
|
|
132
|
+
const seen = by.get(k)
|
|
133
|
+
if (seen == null || f.mtime > seen.mtime) by.set(k, f)
|
|
134
|
+
}
|
|
135
|
+
return [...by.values()]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** the rows as a table, repos in name order, a session before its lanes */
|
|
139
|
+
export function liveTable(rows: readonly LiveRow[], now: number): string[] {
|
|
140
|
+
if (rows.length === 0) return ['no agent wrote in the window']
|
|
141
|
+
const sorted = [...rows].sort((a, b) => repoOf(a).localeCompare(repoOf(b)) || a.session.localeCompare(b.session) || (a.agent === '' ? -1 : b.agent === '' ? 1 : (a.startedAt ?? 0) - (b.startedAt ?? 0)))
|
|
142
|
+
const cells = sorted.map((r) => [
|
|
143
|
+
repoOf(r),
|
|
144
|
+
r.agent === '' ? `session ${r.session.slice(0, 8)}` : ` ${r.name === '' ? r.agent.slice(0, 12) : r.name}${r.model === '' ? '' : ` [${r.model}]`}`,
|
|
145
|
+
r.startedAt == null ? '?' : span(now - r.startedAt),
|
|
146
|
+
r.calls == null ? '-' : String(r.calls),
|
|
147
|
+
doing(r, now),
|
|
148
|
+
])
|
|
149
|
+
const head = ['repo', 'who', 'since', 'calls', 'now']
|
|
150
|
+
const w = head.map((h, i) => Math.max(h.length, ...cells.map((c) => c[i]!.length)))
|
|
151
|
+
const line = (c: string[]): string => c.map((x, i) => (i === c.length - 1 ? x : i === 3 ? x.padStart(w[i]!) : x.padEnd(w[i]!))).join(' ').trimEnd()
|
|
152
|
+
return [line(head), ...cells.map(line)]
|
|
153
|
+
}
|
package/src/agent-time/render.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Breakdown } from './timeline.ts'
|
|
|
5
5
|
import { running, type ShapeRow, type TimeReport, total } from './report.ts'
|
|
6
6
|
import type { TurnStats } from './turns.ts'
|
|
7
7
|
|
|
8
|
-
export const VIEWS = ['summary', 'commands', 'tools', 'slow', 'fails', 'feedback', 'sessions', 'turns'] as const
|
|
8
|
+
export const VIEWS = ['summary', 'commands', 'tools', 'slow', 'fails', 'feedback', 'sessions', 'turns', 'hooks'] as const
|
|
9
9
|
export type View = (typeof VIEWS)[number]
|
|
10
10
|
|
|
11
11
|
/** 0.4s, 12s, 4m10s, 3.2h */
|
|
@@ -123,7 +123,7 @@ function summary(r: TimeReport): string[] {
|
|
|
123
123
|
out.push('', ...feedbackHead(r))
|
|
124
124
|
const slow = r.feedback.hits.filter((h) => h.signals.some((s) => s.signal === 'slow')).slice(-3)
|
|
125
125
|
for (const h of slow) out.push(complaint(h))
|
|
126
|
-
out.push('', 'more: sk time commands | tools | slow | fails | feedback | sessions | turns, --json')
|
|
126
|
+
out.push('', 'more: sk time commands | tools | slow | fails | feedback | sessions | turns | hooks, --json')
|
|
127
127
|
return out
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -177,6 +177,18 @@ export function render(r: TimeReport, view: View, top: number): string {
|
|
|
177
177
|
case 'sessions':
|
|
178
178
|
out = [`${r.sessionRows.length} sessions, by wall (idle left out)`, ...table(['session', 'account', 'start', 'wall', 'model', 'tools', 'sub', 'bg', 'parked', 'unknown', 'you', 'calls', 'agents', 'first prompt'], r.sessionRows.slice(0, top).map((s) => [s.session.slice(0, 8), account(s.account), when(s.start), fmtMs(total(s.wall, false)), fmtMs(s.wall.model), fmtMs(s.wall.tools), fmtMs(s.wall.subagent), fmtMs(s.wall.background), fmtMs(s.wall.parked), fmtMs(s.wall.unknown), fmtMs(s.wall.human), `${s.calls}`, `${s.subagents}`, s.first.slice(0, 40)]))]
|
|
179
179
|
break
|
|
180
|
+
case 'hooks': {
|
|
181
|
+
const ms = (x: number): string => (x < 1000 ? `${Math.round(x)}ms` : fmtMs(x))
|
|
182
|
+
out = [
|
|
183
|
+
`${r.hooks.length} hook command${r.hooks.length === 1 ? '' : 's'}, by cost (~waited: the mean of its timed runs times the calls it applies to, an estimate: high where the hook returns early without a record, low where it is slow and silent)`,
|
|
184
|
+
' only runs the harness timed: it writes a record only when the hook printed something, so a silent hook is missing and the runs under count',
|
|
185
|
+
" a hook's time sits inside the call or the turn it ran on; calls: between its first and last recorded run, by its declared matcher, * by the tools it was recorded on",
|
|
186
|
+
...table(['hook', 'event', 'runs', 'median', 'mean', 'p90', 'worst', 'total', 'errors', 'calls', '~waited'], r.hooks.slice(0, top).map((h) => [h.command.slice(0, 56), h.event, n(h.runs), ms(h.p50), ms(h.mean), ms(h.p90), ms(h.max), fmtMs(h.total), h.errors === 0 ? '' : `${h.errors}`, h.calls == null ? '-' : `${n(h.calls)}${h.byMatcher ? '' : '*'}`, h.calls == null ? '-' : `~${fmtMs(h.mean * h.calls)}`])),
|
|
187
|
+
]
|
|
188
|
+
if (r.hooks.some((h) => h.placed))
|
|
189
|
+
out.push(' `command hook <n>`: some harness versions name a hook by its place in the settings, never its command, and the place is not stable across edits and accounts, so those runs cannot be tied to a command. Such a row and a named row on the same event and tools can be one hook over the same calls: never add their ~waited')
|
|
190
|
+
break
|
|
191
|
+
}
|
|
180
192
|
case 'turns': {
|
|
181
193
|
const t = r.turns
|
|
182
194
|
const reads = t.reads.reduce((a, x) => a + x.model, 0)
|