@agent-watch-ai/edge 0.7.0 → 0.7.2
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 +92 -0
- package/README.md +4 -1
- package/dist/billing/session-billing.d.ts +5 -2
- package/dist/billing/session-billing.js +27 -6
- package/dist/capture/capture-env.d.ts +3 -3
- package/dist/capture/capture-env.js +5 -5
- package/dist/capture/captured-step.js +24 -0
- package/dist/capture/constants/capture.constants.d.ts +15 -0
- package/dist/capture/constants/capture.constants.js +15 -0
- package/dist/capture/launched-runs.d.ts +27 -0
- package/dist/capture/launched-runs.js +15 -9
- package/dist/capture/python/sitecustomize.py +11 -2
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +21 -0
- package/dist/cli/constants/cli.constants.js +22 -1
- package/dist/cli/doctor-run-capture.d.ts +8 -0
- package/dist/cli/doctor-run-capture.js +14 -0
- package/dist/cli/doctor.js +6 -2
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.js +44 -3
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.js +42 -7
- package/dist/cli/setup.js +71 -7
- package/dist/cli/types/cli.types.d.ts +2 -0
- package/dist/cli/uninstall.js +34 -1
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +4 -1
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +8 -0
- package/dist/config/config.js +10 -0
- package/dist/config/constants/config.constants.d.ts +13 -1
- package/dist/config/constants/config.constants.js +13 -1
- package/dist/config/repo-config.js +7 -2
- package/dist/config/schemas/config.schema.d.ts +6 -2
- package/dist/config/schemas/config.schema.js +17 -3
- package/dist/credentials/cloud-claim.d.ts +2 -0
- package/dist/credentials/cloud-claim.js +21 -2
- package/dist/credentials/constants/credentials.constants.d.ts +8 -0
- package/dist/credentials/constants/credentials.constants.js +8 -0
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/git/constants/git.constants.d.ts +2 -0
- package/dist/git/constants/git.constants.js +9 -0
- package/dist/git/repo-snapshot.js +8 -2
- package/dist/git/types/snapshot.types.d.ts +4 -0
- package/dist/pipeline/hook-pipeline.js +5 -2
- package/dist/providers/antigravity/antigravity.adapter.d.ts +14 -0
- package/dist/providers/antigravity/antigravity.adapter.js +86 -18
- package/dist/providers/antigravity/antigravity.provider.js +7 -4
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +10 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +10 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.js +7 -13
- package/dist/providers/claude/claude.otel.d.ts +33 -1
- package/dist/providers/claude/claude.otel.js +81 -12
- package/dist/providers/claude/claude.provider.js +12 -6
- package/dist/providers/codex/codex.capture.d.ts +1 -1
- package/dist/providers/codex/codex.capture.js +3 -3
- package/dist/providers/codex/codex.otel.js +2 -2
- package/dist/providers/codex/codex.provider.js +2 -1
- package/dist/providers/gemini/gemini.capture.js +2 -2
- package/dist/providers/gemini/gemini.otel.js +2 -2
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/shared/terminal-capture.js +3 -3
- package/dist/providers/types/provider.types.d.ts +5 -5
- package/dist/replay/checkout-resolver.d.ts +41 -14
- package/dist/replay/checkout-resolver.js +134 -30
- package/dist/replay/replay-runner.d.ts +3 -1
- package/dist/replay/replay-runner.js +74 -22
- package/dist/replay/replay-scan.d.ts +2 -1
- package/dist/replay/replay-scan.js +14 -2
- package/dist/replay/throttle.d.ts +2 -1
- package/dist/replay/throttle.js +4 -1
- package/dist/replay/transcript-turns.js +29 -3
- package/dist/replay/turn-event.d.ts +4 -2
- package/dist/replay/turn-event.js +22 -11
- package/dist/replay/types/replay.types.d.ts +39 -3
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/snapshot-pipeline.js +15 -4
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/turns/antigravity-transcript.d.ts +40 -0
- package/dist/turns/antigravity-transcript.js +102 -0
- package/dist/turns/claude-transcript.d.ts +35 -1
- package/dist/turns/claude-transcript.js +185 -2
- package/dist/turns/codex-transcript.d.ts +22 -1
- package/dist/turns/codex-transcript.js +161 -2
- package/dist/turns/constants/turns.constants.d.ts +67 -0
- package/dist/turns/constants/turns.constants.js +67 -0
- package/dist/turns/gemini-transcript.d.ts +17 -1
- package/dist/turns/gemini-transcript.js +36 -2
- package/dist/turns/transcript.d.ts +31 -1
- package/dist/turns/transcript.js +74 -0
- package/dist/turns/turn-state.d.ts +51 -1
- package/dist/turns/turn-state.js +124 -10
- package/dist/turns/turn-tracker.js +156 -18
- package/dist/turns/types/transcript.types.d.ts +25 -0
- package/dist/turns/types/turn-provider.types.d.ts +18 -1
- package/dist/turns/types/turn-state.types.d.ts +10 -0
- package/docs/DATA_HANDLING.md +11 -6
- package/docs/ENTERPRISE_DEPLOYMENT.md +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { compact } from '../core/object.js';
|
|
3
3
|
import { deriveEventId, sha256Hex } from '../events/event-id.js';
|
|
4
|
+
import { externalPath } from '../events/enrich.js';
|
|
4
5
|
import { repositoryIdentity } from '../git/git-context.js';
|
|
5
6
|
import { featureCandidatesFromBranch } from '../feature/ticket-candidates.js';
|
|
6
7
|
import { sanitizeText } from '../privacy/sanitizer.js';
|
|
@@ -9,8 +10,8 @@ import { buildTurnSummary } from '../turns/turn-summary.js';
|
|
|
9
10
|
/**
|
|
10
11
|
* The `turn.summary` a transcript turn becomes: the live hook's record, built by the live hook's builder.
|
|
11
12
|
*
|
|
12
|
-
* It differs from a live one only where a transcript knows less:
|
|
13
|
-
*
|
|
13
|
+
* It differs from a live one only where a transcript knows less: only a Codex
|
|
14
|
+
* rollout's session-start commit is known, no tool events, no
|
|
14
15
|
* session titles, and a repository and branch read from the turn's last
|
|
15
16
|
* folder and `gitBranch`, not from the checkout as it is now. The record's
|
|
16
17
|
* `turn_id` is the transcript's prompt id, which is the live hook's turn id,
|
|
@@ -26,7 +27,9 @@ import { buildTurnSummary } from '../turns/turn-summary.js';
|
|
|
26
27
|
export function buildReplayTurnEvent(turn, checkout, context) {
|
|
27
28
|
// No checkout (the folder is gone): the remote the rollout recorded still names the repository.
|
|
28
29
|
const repository = checkout?.repository ?? (turn.remote ? repositoryIdentity('', turn.remote).remote : undefined);
|
|
29
|
-
|
|
30
|
+
// A Codex session records its commit once, at start: it belongs to the repository it recorded, not to one the session moved to.
|
|
31
|
+
const ownCommit = !checkout?.evidence && !(checkout && turn.remote && repositoryIdentity('', turn.remote).remote !== checkout.repository);
|
|
32
|
+
const git = context.capture.git === false || !repository ? undefined : { repository, branch: checkout?.branch ?? (checkout?.evidence ? undefined : turn.branch), commit: ownCommit ? turn.commit : undefined };
|
|
30
33
|
const summary = buildTurnSummary({
|
|
31
34
|
provider: turn.provider,
|
|
32
35
|
surface: turn.surface ?? DEFAULT_SURFACE,
|
|
@@ -39,7 +42,7 @@ export function buildReplayTurnEvent(turn, checkout, context) {
|
|
|
39
42
|
featureCandidates: featureCandidatesFromBranch(git?.branch),
|
|
40
43
|
workEvidence: git ? (checkout?.evidence ?? 'cwd') : undefined,
|
|
41
44
|
prompts: [{ kind: 'prompt', at: turn.startedAt, turnId: turn.turnId, text: promptText(turn, context.capture) }],
|
|
42
|
-
tools: toolRecords(turn, context
|
|
45
|
+
tools: toolRecords(turn, checkout, context),
|
|
43
46
|
usage: turn.usage,
|
|
44
47
|
model: turn.usage?.model,
|
|
45
48
|
billingMode: context.billingMode,
|
|
@@ -79,26 +82,34 @@ function promptText(turn, capture) {
|
|
|
79
82
|
return sanitizeText(turn.promptText).slice(0, MAX_PROMPT_TEXT_LENGTH) || undefined;
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
|
-
* The turn's tool calls as the builder takes them: a name,
|
|
85
|
+
* The turn's tool calls as the builder takes them: a name, a path inside the checkout, and, for a file in no checkout, what the live hook sends.
|
|
83
86
|
*
|
|
84
|
-
* A file
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
+
* A file in no checkout is a bare basename in the file lists (core's session-files subject and charge rung read those),
|
|
88
|
+
* and its home-relative path in the external lists (the Security page reads those). A file in another checkout is left out.
|
|
89
|
+
* `capture.files: false` withholds every path, and `capture.git: false` the external ones, as live.
|
|
87
90
|
*
|
|
88
91
|
* @param turn - The turn.
|
|
89
|
-
* @param checkout - The checkout paths are made relative to; undefined drops paths.
|
|
92
|
+
* @param checkout - The checkout paths are made relative to; undefined drops paths inside one.
|
|
93
|
+
* @param context - The capture flags and the home.
|
|
90
94
|
* @returns One record per call.
|
|
91
95
|
*/
|
|
92
|
-
function toolRecords(turn, checkout) {
|
|
96
|
+
function toolRecords(turn, checkout, context) {
|
|
97
|
+
const files = context.capture.files !== false;
|
|
93
98
|
return turn.tools.map((tool) => ({
|
|
94
99
|
kind: 'tool',
|
|
95
100
|
at: turn.endedAt,
|
|
96
101
|
turnId: turn.turnId,
|
|
97
102
|
tool: tool.name,
|
|
98
103
|
access: tool.access,
|
|
99
|
-
filePath:
|
|
104
|
+
filePath: files ? filePathOf(tool, checkout) : undefined,
|
|
105
|
+
externalPath: files && tool.outside && context.capture.git !== false ? externalPath(tool.path, undefined, context.home) : undefined
|
|
100
106
|
}));
|
|
101
107
|
}
|
|
108
|
+
function filePathOf(tool, checkout) {
|
|
109
|
+
if (tool.outside)
|
|
110
|
+
return path.basename(tool.path);
|
|
111
|
+
return checkout && relativeTo(checkout.root, tool);
|
|
112
|
+
}
|
|
102
113
|
/**
|
|
103
114
|
* A tool's file as a slash-separated path inside a checkout.
|
|
104
115
|
*
|
|
@@ -20,6 +20,8 @@ export interface ReplayTool {
|
|
|
20
20
|
readonly access?: 'read' | 'edit';
|
|
21
21
|
/** Absolute, as the agent wrote it; made checkout-relative when the event is built. */
|
|
22
22
|
readonly path?: string;
|
|
23
|
+
/** The file lies in no checkout: sent as the live hook sends it, a basename and its home-relative place. */
|
|
24
|
+
readonly outside?: boolean;
|
|
23
25
|
}
|
|
24
26
|
/** What a transcript says about the folder a session ran in: its repository's remote, the commit and the branch, when it recorded them. */
|
|
25
27
|
export interface ReplayIdentity {
|
|
@@ -42,7 +44,7 @@ export interface ReplayTurn {
|
|
|
42
44
|
readonly branch?: string;
|
|
43
45
|
/** The remote the session started in, when the file records it (Codex `session_meta.git.repository_url`); used when the folder is gone. */
|
|
44
46
|
readonly remote?: string;
|
|
45
|
-
/** The full commit the session started at (Codex `session_meta.git.commit_hash`)
|
|
47
|
+
/** The full commit the session started at (Codex `session_meta.git.commit_hash`). */
|
|
46
48
|
readonly commit?: string;
|
|
47
49
|
readonly surface?: string;
|
|
48
50
|
readonly usage?: TurnUsage;
|
|
@@ -50,12 +52,28 @@ export interface ReplayTurn {
|
|
|
50
52
|
/** The prompt as typed; read only when the effective config allows prompt text. */
|
|
51
53
|
readonly promptText?: string;
|
|
52
54
|
}
|
|
55
|
+
/** One `git worktree add` a transcript recorded. */
|
|
56
|
+
export interface LearnedWorktree {
|
|
57
|
+
readonly root: string;
|
|
58
|
+
readonly branch?: string;
|
|
59
|
+
/** The folder the command ran from: a checkout of the repository, for a worktree since removed. */
|
|
60
|
+
readonly main: string;
|
|
61
|
+
readonly at: string;
|
|
62
|
+
}
|
|
53
63
|
/** The checkout a turn's `cwd` resolved to, cached per directory. */
|
|
54
64
|
export interface ReplayCheckout {
|
|
55
65
|
readonly root: string;
|
|
56
66
|
readonly repository: string;
|
|
57
|
-
/** How it was found when not by the turn's folder: `changed`, by a file a tool edited. Absent: the folder (`cwd`). */
|
|
58
|
-
readonly evidence?: 'changed';
|
|
67
|
+
/** How it was found when not by the turn's folder alone: `changed`, by a file a tool edited; `carried`, the session's last changed one. Absent: the folder (`cwd`). */
|
|
68
|
+
readonly evidence?: 'changed' | 'carried';
|
|
69
|
+
/** The branch the turn was on there, when known. Set by the ladder; a transcript's own branch only ever belongs to the turn's folder. */
|
|
70
|
+
readonly branch?: string;
|
|
71
|
+
/** The `git worktree add`s of this root the transcripts recorded, oldest first. */
|
|
72
|
+
readonly learned?: readonly LearnedWorktree[];
|
|
73
|
+
/** A linked worktree's branch today, or the main checkout's when it is a trunk: its branch today says nothing about history otherwise. */
|
|
74
|
+
readonly head?: string;
|
|
75
|
+
/** A checkout of the repository that can be asked, when this one is gone. */
|
|
76
|
+
readonly gitRoot?: string;
|
|
59
77
|
}
|
|
60
78
|
/** What one transcript file looked like when it was counted. */
|
|
61
79
|
export interface ReplayFileEntry {
|
|
@@ -88,9 +106,19 @@ export interface ReplaySource {
|
|
|
88
106
|
identity?(file: string): Promise<ReplayIdentity | undefined>;
|
|
89
107
|
/** The file's turns, oldest first. */
|
|
90
108
|
read(file: string, promptText: boolean): AsyncIterable<ReplayTurn>;
|
|
109
|
+
/** Every `git worktree add` in this agent's transcripts, whatever their date; stops between files once `stop` says so. */
|
|
110
|
+
worktreeAdds?(stop?: () => boolean): Promise<readonly LearnedWorktree[]>;
|
|
91
111
|
}
|
|
92
112
|
/** Why a running replay is waiting. */
|
|
93
113
|
export type ReplayPause = 'busy' | 'battery' | 'agent-active' | 'backend' | 'budget';
|
|
114
|
+
/** A repository the replay's turns placed, as the record keeps it between legs. */
|
|
115
|
+
export interface SeenRepositoryRecord {
|
|
116
|
+
readonly repository: string;
|
|
117
|
+
readonly sessionId: string;
|
|
118
|
+
readonly surface: string;
|
|
119
|
+
readonly provider: string;
|
|
120
|
+
readonly branches: readonly string[];
|
|
121
|
+
}
|
|
94
122
|
/** A replay's persisted state: the one file `status`, a resumed run and the progress record read. */
|
|
95
123
|
export interface ReplayRecord {
|
|
96
124
|
readonly replayId: string;
|
|
@@ -99,6 +127,8 @@ export interface ReplayRecord {
|
|
|
99
127
|
readonly state: ReplayProgressState;
|
|
100
128
|
readonly windowStart: string;
|
|
101
129
|
readonly windowEnd: string;
|
|
130
|
+
/** An operator chose this window; a resume keeps it and skips the local machine gates. */
|
|
131
|
+
readonly operator?: boolean;
|
|
102
132
|
readonly startedAt: string;
|
|
103
133
|
readonly updatedAt: string;
|
|
104
134
|
readonly pid?: number;
|
|
@@ -113,6 +143,8 @@ export interface ReplayRecord {
|
|
|
113
143
|
readonly refused: number;
|
|
114
144
|
/** Repositories whose snapshot has been queued. */
|
|
115
145
|
readonly snapshotted: readonly string[];
|
|
146
|
+
/** Every repository the run's sent turns placed, by snapshot root, with the branches they named: a resumed leg still snapshots them. */
|
|
147
|
+
readonly repositories?: Readonly<Record<string, SeenRepositoryRecord>>;
|
|
116
148
|
readonly files: Readonly<Record<string, ReplayFileEntry>>;
|
|
117
149
|
/** The sources a fresh run listed; absent in a record from before Codex and Gemini replay. */
|
|
118
150
|
readonly agents?: readonly string[];
|
|
@@ -152,6 +184,10 @@ export interface ReplayPorts {
|
|
|
152
184
|
/** Whether a turn that ran in this folder belongs to the identity the run sends as. */
|
|
153
185
|
inScope(cwd: string): boolean;
|
|
154
186
|
checkout: CheckoutResolver;
|
|
187
|
+
/** Teach `checkout` what the transcripts say about worktrees; run before anything is resolved. */
|
|
188
|
+
learnWorktrees?(learned: readonly LearnedWorktree[]): void;
|
|
189
|
+
/** Local checkouts under the selected root, used to recover repositories whose archived review checkout is gone. */
|
|
190
|
+
localCheckouts?(): Promise<readonly ReplayCheckout[]>;
|
|
155
191
|
/** The capture flags in force for a folder: the global ones, narrowed by the folder's `.agentwatch.json`, as a live hook there would read them. */
|
|
156
192
|
captureFor: (cwd: string) => Promise<CaptureConfig>;
|
|
157
193
|
machine(): Promise<MachineLoad>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LearnedWorktree } from './types/replay.types.js';
|
|
2
|
+
/** What a transcript taught about `git worktree add`: each path, what branch it got and when, the latest last. */
|
|
3
|
+
export type WorktreeMap = Map<string, LearnedWorktree[]>;
|
|
4
|
+
/**
|
|
5
|
+
* The folder's learned worktree: the nearest parent directory some `git worktree add` created.
|
|
6
|
+
*
|
|
7
|
+
* @param worktrees - The map.
|
|
8
|
+
* @param folder - A folder, likely gone.
|
|
9
|
+
* @returns The worktree's root, or undefined.
|
|
10
|
+
*/
|
|
11
|
+
export declare function learnedRootOf(worktrees: WorktreeMap, folder: string): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The worktrees one shell command creates.
|
|
14
|
+
*
|
|
15
|
+
* ponytail: a regex reader, as `shellDirectories` is. A worktree created by a script or a harness's own tool
|
|
16
|
+
* leaves no such line, and a variable in the path is skipped. Ceiling: such worktrees stay unknown; the upgrade
|
|
17
|
+
* path is the hooks' own per-session checkout memo, which a replay of an older history does not have.
|
|
18
|
+
*
|
|
19
|
+
* @param command - The command, in memory.
|
|
20
|
+
* @param cwd - The folder it ran in.
|
|
21
|
+
* @param home - Home, for `~/`.
|
|
22
|
+
* @param at - When it ran.
|
|
23
|
+
* @returns One entry per `git worktree add`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function worktreesCreatedBy(command: string, cwd: string, home: string | undefined, at: string): LearnedWorktree[];
|
|
26
|
+
/**
|
|
27
|
+
* The worktrees a transcript's Bash calls created.
|
|
28
|
+
*
|
|
29
|
+
* Only the top session and its sub-agents' lines in this file; Codex rollouts are not read.
|
|
30
|
+
*
|
|
31
|
+
* @param file - A Claude Code transcript.
|
|
32
|
+
* @param home - Home, for `~/`.
|
|
33
|
+
* @returns What it created.
|
|
34
|
+
*/
|
|
35
|
+
export declare function worktreesInTranscript(file: string, home: string | undefined): Promise<LearnedWorktree[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Put what was learned into the map, each path's entries oldest first.
|
|
38
|
+
*
|
|
39
|
+
* @param worktrees - The map.
|
|
40
|
+
* @param learned - The entries.
|
|
41
|
+
*/
|
|
42
|
+
export declare function learnWorktrees(worktrees: WorktreeMap, learned: readonly LearnedWorktree[]): void;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import readline from 'node:readline';
|
|
4
|
+
import { asRecord } from '../core/object.js';
|
|
5
|
+
import { RE_DIRECTORY_ARGUMENTS, RE_HEREDOC, RE_HOME_PREFIX, HEREDOC_PLACEHOLDER, RE_SHELL_SEPARATORS, RE_SURROUNDING_QUOTES, RE_UNEXPANDED } from '../providers/shared/constants/shell-directories.constants.js';
|
|
6
|
+
import { shellDirectories } from '../providers/shared/shell-directories.js';
|
|
7
|
+
import { parseJsonLine } from '../turns/transcript.js';
|
|
8
|
+
const WORKTREE_ADD = 'worktree add';
|
|
9
|
+
const SHELL_TOOL = 'Bash';
|
|
10
|
+
const RE_SHELL_WORD = /"[^"]*"|'[^']*'|(?:\\ |\S)+/g;
|
|
11
|
+
/** A `git worktree add` argument that names a commit rather than a branch: a sha, a relative ref, a tag, a remote's. */
|
|
12
|
+
const RE_NOT_A_BRANCH = /^(?:[0-9a-f]{7,40}$|HEAD|@|v?\d+\.\d|(?:origin|upstream|refs|pull|tags)\/)|[~^]/;
|
|
13
|
+
const RE_CHANGE_DIRECTORY_COMMAND = /^(?:cd|pushd)\s/;
|
|
14
|
+
/** Only git itself creates a worktree: `grep "git worktree add" docs` names one and creates nothing. */
|
|
15
|
+
const RE_GIT_COMMAND = /^(?:\w+=\S*\s+)*git\s/;
|
|
16
|
+
const RE_SUBSHELL_PARENS = /^\(\s*|\s*\)$/g;
|
|
17
|
+
/** Where the command's arguments end and the shell's plumbing begins: a pipe, a background `&`, a redirect. */
|
|
18
|
+
const RE_SHELL_PLUMBING = /^(?:\||&|\d*[<>])/;
|
|
19
|
+
const RE_LEADING_TILDE = /^~/;
|
|
20
|
+
const RE_GIT_DASH_C = RE_DIRECTORY_ARGUMENTS[0];
|
|
21
|
+
/**
|
|
22
|
+
* The folder's learned worktree: the nearest parent directory some `git worktree add` created.
|
|
23
|
+
*
|
|
24
|
+
* @param worktrees - The map.
|
|
25
|
+
* @param folder - A folder, likely gone.
|
|
26
|
+
* @returns The worktree's root, or undefined.
|
|
27
|
+
*/
|
|
28
|
+
export function learnedRootOf(worktrees, folder) {
|
|
29
|
+
for (let dir = folder; dir !== path.dirname(dir); dir = path.dirname(dir))
|
|
30
|
+
if (worktrees.has(dir))
|
|
31
|
+
return dir;
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The worktrees one shell command creates.
|
|
36
|
+
*
|
|
37
|
+
* ponytail: a regex reader, as `shellDirectories` is. A worktree created by a script or a harness's own tool
|
|
38
|
+
* leaves no such line, and a variable in the path is skipped. Ceiling: such worktrees stay unknown; the upgrade
|
|
39
|
+
* path is the hooks' own per-session checkout memo, which a replay of an older history does not have.
|
|
40
|
+
*
|
|
41
|
+
* @param command - The command, in memory.
|
|
42
|
+
* @param cwd - The folder it ran in.
|
|
43
|
+
* @param home - Home, for `~/`.
|
|
44
|
+
* @param at - When it ran.
|
|
45
|
+
* @returns One entry per `git worktree add`.
|
|
46
|
+
*/
|
|
47
|
+
export function worktreesCreatedBy(command, cwd, home, at) {
|
|
48
|
+
const added = [];
|
|
49
|
+
let base = cwd;
|
|
50
|
+
for (const piece of command.replace(RE_HEREDOC, HEREDOC_PLACEHOLDER).split(RE_SHELL_SEPARATORS)) {
|
|
51
|
+
const trimmed = piece.trim().replace(RE_SUBSHELL_PARENS, '');
|
|
52
|
+
if (RE_CHANGE_DIRECTORY_COMMAND.test(trimmed))
|
|
53
|
+
base = shellDirectories(trimmed, base, home)[0] ?? base;
|
|
54
|
+
const index = trimmed.indexOf(WORKTREE_ADD);
|
|
55
|
+
if (index < 0 || !RE_GIT_COMMAND.test(trimmed))
|
|
56
|
+
continue;
|
|
57
|
+
const { branch, target } = worktreeArguments(trimmed.slice(index + WORKTREE_ADD.length));
|
|
58
|
+
const dashC = [...trimmed.matchAll(RE_GIT_DASH_C)][0]?.[1];
|
|
59
|
+
const main = dashC ? (shellDirectories(`cd ${dashC}`, base, home)[0] ?? base) : base;
|
|
60
|
+
const expanded = target && home ? target.replace(RE_HOME_PREFIX, () => home) : target;
|
|
61
|
+
if (expanded && !RE_UNEXPANDED.test(expanded) && !RE_LEADING_TILDE.test(expanded))
|
|
62
|
+
added.push({ root: path.resolve(main, expanded), branch, main, at });
|
|
63
|
+
}
|
|
64
|
+
return added;
|
|
65
|
+
}
|
|
66
|
+
function worktreeArguments(text) {
|
|
67
|
+
const words = (text.match(RE_SHELL_WORD) ?? []).map((word) => word.replace(RE_SURROUNDING_QUOTES, '').replaceAll('\\ ', ' '));
|
|
68
|
+
const positional = [];
|
|
69
|
+
let branch;
|
|
70
|
+
let detached = false;
|
|
71
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
72
|
+
const word = words[i];
|
|
73
|
+
if (RE_SHELL_PLUMBING.test(word))
|
|
74
|
+
break;
|
|
75
|
+
detached ||= word === '--detach' || word === '-d';
|
|
76
|
+
if (word === '-b' || word === '-B' || word === '--reason') {
|
|
77
|
+
i += 1;
|
|
78
|
+
branch = word === '--reason' ? branch : words[i];
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (!word.startsWith('-'))
|
|
82
|
+
positional.push(word);
|
|
83
|
+
}
|
|
84
|
+
const commitish = positional[1];
|
|
85
|
+
return { branch: branch ?? (commitish && !detached && !RE_NOT_A_BRANCH.test(commitish) ? commitish : undefined), target: positional[0] };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The worktrees a transcript's Bash calls created.
|
|
89
|
+
*
|
|
90
|
+
* Only the top session and its sub-agents' lines in this file; Codex rollouts are not read.
|
|
91
|
+
*
|
|
92
|
+
* @param file - A Claude Code transcript.
|
|
93
|
+
* @param home - Home, for `~/`.
|
|
94
|
+
* @returns What it created.
|
|
95
|
+
*/
|
|
96
|
+
export async function worktreesInTranscript(file, home) {
|
|
97
|
+
const lines = readline.createInterface({ input: fs.createReadStream(file, { encoding: 'utf8' }), crlfDelay: Infinity });
|
|
98
|
+
const found = [];
|
|
99
|
+
try {
|
|
100
|
+
for await (const line of lines)
|
|
101
|
+
if (line.includes(WORKTREE_ADD))
|
|
102
|
+
found.push(...worktreesOfLine(line, home));
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return found;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
lines.close();
|
|
109
|
+
}
|
|
110
|
+
return found;
|
|
111
|
+
}
|
|
112
|
+
function worktreesOfLine(line, home) {
|
|
113
|
+
const entry = parseJsonLine(line);
|
|
114
|
+
const cwd = entry?.['cwd'];
|
|
115
|
+
const at = entry?.['timestamp'];
|
|
116
|
+
const content = asRecord(entry?.['message'])?.['content'];
|
|
117
|
+
if (typeof cwd !== 'string' || typeof at !== 'string' || !Array.isArray(content))
|
|
118
|
+
return [];
|
|
119
|
+
return content.flatMap((block) => {
|
|
120
|
+
const call = asRecord(block);
|
|
121
|
+
const command = asRecord(call?.['input'])?.['command'];
|
|
122
|
+
return call?.['type'] === 'tool_use' && call['name'] === SHELL_TOOL && typeof command === 'string' && command.includes(WORKTREE_ADD) ? worktreesCreatedBy(command, cwd, home, at) : [];
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Put what was learned into the map, each path's entries oldest first.
|
|
127
|
+
*
|
|
128
|
+
* @param worktrees - The map.
|
|
129
|
+
* @param learned - The entries.
|
|
130
|
+
*/
|
|
131
|
+
export function learnWorktrees(worktrees, learned) {
|
|
132
|
+
for (const entry of learned)
|
|
133
|
+
worktrees.set(entry.root, [...(worktrees.get(entry.root) ?? []), entry].sort((a, b) => a.at.localeCompare(b.at)));
|
|
134
|
+
}
|
|
@@ -61,7 +61,7 @@ export function runSnapshotPipeline(pipeline) {
|
|
|
61
61
|
*/
|
|
62
62
|
async function collectRefs(state) {
|
|
63
63
|
const { cwd } = state.input;
|
|
64
|
-
const refs = await collectBranchRefs({ cwd, branchCount: SNAPSHOT_SCAN_COUNT }, state.run);
|
|
64
|
+
const refs = await collectBranchRefs({ cwd, branchCount: SNAPSHOT_SCAN_COUNT, ...(state.input.requiredBranches ? { requiredBranches: state.input.requiredBranches } : {}) }, state.run);
|
|
65
65
|
if (refs.length === 0)
|
|
66
66
|
return stop(state, STOP_NOT_A_REPOSITORY);
|
|
67
67
|
const defaultBranch = await resolveDefaultBranch(cwd, state.run);
|
|
@@ -75,7 +75,12 @@ async function collectRefs(state) {
|
|
|
75
75
|
*/
|
|
76
76
|
async function selectChanged(state) {
|
|
77
77
|
const stored = await state.store.read(state.input.repository);
|
|
78
|
-
const
|
|
78
|
+
const selected = snapshotCandidates(selectionInput({ ...state, stored }));
|
|
79
|
+
const required = new Set(state.input.requiredBranches);
|
|
80
|
+
const candidates = [
|
|
81
|
+
...state.refs.filter((ref) => required.has(ref.name)).map((ref) => ({ ref, due: true })),
|
|
82
|
+
...selected.filter(({ ref }) => !required.has(ref.name))
|
|
83
|
+
];
|
|
79
84
|
if (!anyDue(candidates))
|
|
80
85
|
return stop({ ...state, stored }, STOP_NOTHING_CHANGED);
|
|
81
86
|
return next({ ...state, stored, candidates });
|
|
@@ -113,7 +118,7 @@ async function collectCommits(state) {
|
|
|
113
118
|
live += 1;
|
|
114
119
|
continue;
|
|
115
120
|
}
|
|
116
|
-
if (ref.upstreamGone && !state.stored?.branches[ref.name]) {
|
|
121
|
+
if (!state.input.requiredBranches?.includes(ref.name) && ref.upstreamGone && !state.stored?.branches[ref.name]) {
|
|
117
122
|
merged.push(ref);
|
|
118
123
|
continue;
|
|
119
124
|
}
|
|
@@ -146,7 +151,13 @@ async function collectCommits(state) {
|
|
|
146
151
|
* @returns What {@link collectBranchCommits} says.
|
|
147
152
|
*/
|
|
148
153
|
function checkBranch(ref, state, run) {
|
|
149
|
-
return collectBranchCommits(ref.name, {
|
|
154
|
+
return collectBranchCommits(ref.name, {
|
|
155
|
+
cwd: state.input.cwd,
|
|
156
|
+
defaultBranch: state.defaultBranch,
|
|
157
|
+
commitCount: SNAPSHOT_COMMITS_PER_BRANCH,
|
|
158
|
+
withFiles: state.input.files,
|
|
159
|
+
includeMerged: state.input.requiredBranches?.includes(ref.name)
|
|
160
|
+
}, run);
|
|
150
161
|
}
|
|
151
162
|
/**
|
|
152
163
|
* Build the event and put it through the same scrubber prompt text gets.
|
|
@@ -72,6 +72,8 @@ export interface SnapshotFlowInput extends SnapshotIdentity {
|
|
|
72
72
|
readonly identity?: string;
|
|
73
73
|
readonly deadline: number;
|
|
74
74
|
readonly run: GitRunner;
|
|
75
|
+
/** Historical replay branches that must be described even when old or squash/rebase-merged today. */
|
|
76
|
+
readonly requiredBranches?: readonly string[];
|
|
75
77
|
}
|
|
76
78
|
/** What the selection compares, and what the write-back records. */
|
|
77
79
|
export interface SelectionInput {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReadTurnUsageRetry, TranscriptUsageEntry, TurnUsage } from './types/transcript.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Per-turn token usage from an Antigravity transcript
|
|
4
|
+
* (`<app dir>/brain/<conversationId>/.system_generated/logs/transcript_full.jsonl`).
|
|
5
|
+
*
|
|
6
|
+
* Antigravity has no OTel export and no usage API, so this file is its only
|
|
7
|
+
* money source. One line per step; model steps (`source: "MODEL"`) carry
|
|
8
|
+
* `step_index`, `created_at`, `model`, `input_tokens`, `cache_read_tokens` and
|
|
9
|
+
* `output_tokens` (agy 1.5.0). Only those fields are read; content, thinking
|
|
10
|
+
* and tool calls are never looked at, so nothing a developer wrote leaves here.
|
|
11
|
+
*
|
|
12
|
+
* Older builds wrote the tokens without `model` (the summary then keeps the
|
|
13
|
+
* hook's model), and older still no tokens at all: a step without any count is
|
|
14
|
+
* skipped, so such a turn stays `pending` rather than reporting zero.
|
|
15
|
+
*
|
|
16
|
+
* Exactly once: each step is claimed by its `step_index`, unique within the
|
|
17
|
+
* conversation, through the tracker's claim ledger under the session usage lock.
|
|
18
|
+
*
|
|
19
|
+
* ponytail: `created_at` is whole seconds, so the lower bound is floored to the
|
|
20
|
+
* second, or a step written in the prompt's own second would be missed. An
|
|
21
|
+
* unclaimed step of the previous turn from that same second can join this one;
|
|
22
|
+
* claimed steps never do. The upper bound stays exact: a racing next prompt's
|
|
23
|
+
* step stamped in that prompt's own second goes to this turn (still once).
|
|
24
|
+
* Same 4 MiB tail ceiling as the other readers.
|
|
25
|
+
*
|
|
26
|
+
* @param transcriptPath - The transcript the hook named, or the brain-directory fallback.
|
|
27
|
+
* @param sinceIso - When the turn started.
|
|
28
|
+
* @param retry - How long to wait for the transcript flush to settle.
|
|
29
|
+
* @param untilIso - Upper bound, keeping a racing next prompt's steps out.
|
|
30
|
+
* @param excludeMessageIds - Steps another turn already claimed.
|
|
31
|
+
* @returns The turn's usage, or undefined when the transcript reports none.
|
|
32
|
+
*/
|
|
33
|
+
export declare function readAntigravityTurnUsage(transcriptPath: string, sinceIso: string, retry?: ReadTurnUsageRetry, untilIso?: string, excludeMessageIds?: ReadonlySet<string>): Promise<TurnUsage | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* The usage one transcript step carries, when it is a model step with counts.
|
|
36
|
+
*
|
|
37
|
+
* @param row - One parsed transcript line.
|
|
38
|
+
* @returns The step's model and counts under the transcript field names, or undefined.
|
|
39
|
+
*/
|
|
40
|
+
export declare function antigravityStepUsage(row: Readonly<Record<string, unknown>>): TranscriptUsageEntry | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { firstStringOf } from '../core/object.js';
|
|
2
|
+
import { accumulateUsage, messageIdFor, parseJsonLine, readUntilSettled, readWindowedTail } from './transcript.js';
|
|
3
|
+
import { ANTIGRAVITY_CACHE_READ_TOKENS, ANTIGRAVITY_COUNT_FIELDS, ANTIGRAVITY_INPUT_TOKENS, ANTIGRAVITY_MODEL_SOURCE, ANTIGRAVITY_OUTPUT_TOKENS, ANTIGRAVITY_STEP_ID_PREFIX, ANTIGRAVITY_TIMESTAMP_RESOLUTION_MS, TRANSCRIPT_CACHE_READ_TOKENS, TRANSCRIPT_INPUT_TOKENS, TRANSCRIPT_OUTPUT_TOKENS } from './constants/turns.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Per-turn token usage from an Antigravity transcript
|
|
6
|
+
* (`<app dir>/brain/<conversationId>/.system_generated/logs/transcript_full.jsonl`).
|
|
7
|
+
*
|
|
8
|
+
* Antigravity has no OTel export and no usage API, so this file is its only
|
|
9
|
+
* money source. One line per step; model steps (`source: "MODEL"`) carry
|
|
10
|
+
* `step_index`, `created_at`, `model`, `input_tokens`, `cache_read_tokens` and
|
|
11
|
+
* `output_tokens` (agy 1.5.0). Only those fields are read; content, thinking
|
|
12
|
+
* and tool calls are never looked at, so nothing a developer wrote leaves here.
|
|
13
|
+
*
|
|
14
|
+
* Older builds wrote the tokens without `model` (the summary then keeps the
|
|
15
|
+
* hook's model), and older still no tokens at all: a step without any count is
|
|
16
|
+
* skipped, so such a turn stays `pending` rather than reporting zero.
|
|
17
|
+
*
|
|
18
|
+
* Exactly once: each step is claimed by its `step_index`, unique within the
|
|
19
|
+
* conversation, through the tracker's claim ledger under the session usage lock.
|
|
20
|
+
*
|
|
21
|
+
* ponytail: `created_at` is whole seconds, so the lower bound is floored to the
|
|
22
|
+
* second, or a step written in the prompt's own second would be missed. An
|
|
23
|
+
* unclaimed step of the previous turn from that same second can join this one;
|
|
24
|
+
* claimed steps never do. The upper bound stays exact: a racing next prompt's
|
|
25
|
+
* step stamped in that prompt's own second goes to this turn (still once).
|
|
26
|
+
* Same 4 MiB tail ceiling as the other readers.
|
|
27
|
+
*
|
|
28
|
+
* @param transcriptPath - The transcript the hook named, or the brain-directory fallback.
|
|
29
|
+
* @param sinceIso - When the turn started.
|
|
30
|
+
* @param retry - How long to wait for the transcript flush to settle.
|
|
31
|
+
* @param untilIso - Upper bound, keeping a racing next prompt's steps out.
|
|
32
|
+
* @param excludeMessageIds - Steps another turn already claimed.
|
|
33
|
+
* @returns The turn's usage, or undefined when the transcript reports none.
|
|
34
|
+
*/
|
|
35
|
+
export async function readAntigravityTurnUsage(transcriptPath, sinceIso, retry, untilIso, excludeMessageIds) {
|
|
36
|
+
return readUntilSettled(() => readOnce(transcriptPath, sinceIso, untilIso, excludeMessageIds), retry);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One pass over the transcript tail.
|
|
40
|
+
*
|
|
41
|
+
* @param transcriptPath - Transcript file.
|
|
42
|
+
* @param sinceIso - Lower bound of the turn's window.
|
|
43
|
+
* @param untilIso - Upper bound, or undefined for "no upper bound".
|
|
44
|
+
* @param excludeMessageIds - Steps another turn already claimed.
|
|
45
|
+
* @returns The usage found in this pass.
|
|
46
|
+
*/
|
|
47
|
+
async function readOnce(transcriptPath, sinceIso, untilIso, excludeMessageIds) {
|
|
48
|
+
const tail = await readWindowedTail(transcriptPath, sinceIso, untilIso);
|
|
49
|
+
if (tail === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
const { raw, until } = tail;
|
|
52
|
+
const since = Math.floor(tail.since / ANTIGRAVITY_TIMESTAMP_RESOLUTION_MS) * ANTIGRAVITY_TIMESTAMP_RESOLUTION_MS;
|
|
53
|
+
const byStep = new Map();
|
|
54
|
+
for (const line of raw.split('\n')) {
|
|
55
|
+
// Cheap prefilter: user, tool and system steps carry no counts.
|
|
56
|
+
if (!ANTIGRAVITY_COUNT_FIELDS.some((field) => line.includes(`"${field}"`)))
|
|
57
|
+
continue;
|
|
58
|
+
const row = parseJsonLine(line);
|
|
59
|
+
const entry = row ? antigravityStepUsage(row) : undefined;
|
|
60
|
+
const timestamp = typeof row?.['created_at'] === 'string' ? Date.parse(row['created_at']) : NaN;
|
|
61
|
+
if (!row || !entry || Number.isNaN(timestamp) || timestamp < since || timestamp > until)
|
|
62
|
+
continue;
|
|
63
|
+
const step = row['step_index'];
|
|
64
|
+
const id = Number.isInteger(step) ? `${ANTIGRAVITY_STEP_ID_PREFIX}${String(step)}` : messageIdFor(undefined, line);
|
|
65
|
+
if (excludeMessageIds?.has(id))
|
|
66
|
+
continue;
|
|
67
|
+
byStep.set(id, entry);
|
|
68
|
+
}
|
|
69
|
+
return accumulateUsage(byStep);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The usage one transcript step carries, when it is a model step with counts.
|
|
73
|
+
*
|
|
74
|
+
* @param row - One parsed transcript line.
|
|
75
|
+
* @returns The step's model and counts under the transcript field names, or undefined.
|
|
76
|
+
*/
|
|
77
|
+
export function antigravityStepUsage(row) {
|
|
78
|
+
if (row['source'] !== ANTIGRAVITY_MODEL_SOURCE)
|
|
79
|
+
return undefined;
|
|
80
|
+
const input = finiteOrUndefined(row[ANTIGRAVITY_INPUT_TOKENS]);
|
|
81
|
+
const output = finiteOrUndefined(row[ANTIGRAVITY_OUTPUT_TOKENS]);
|
|
82
|
+
const cacheRead = finiteOrUndefined(row[ANTIGRAVITY_CACHE_READ_TOKENS]);
|
|
83
|
+
if (input === undefined && output === undefined && cacheRead === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
return {
|
|
86
|
+
model: firstStringOf(row['model']),
|
|
87
|
+
usage: {
|
|
88
|
+
[TRANSCRIPT_INPUT_TOKENS]: input,
|
|
89
|
+
[TRANSCRIPT_OUTPUT_TOKENS]: output,
|
|
90
|
+
[TRANSCRIPT_CACHE_READ_TOKENS]: cacheRead
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A count as a number, or undefined when it is missing or not a finite number.
|
|
96
|
+
*
|
|
97
|
+
* @param value - Candidate count.
|
|
98
|
+
* @returns The finite number, or undefined.
|
|
99
|
+
*/
|
|
100
|
+
function finiteOrUndefined(value) {
|
|
101
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
102
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReadTurnUsageRetry, SessionTitles, TurnUsage } from './types/transcript.types.js';
|
|
1
|
+
import type { ReadTurnUsageRetry, SessionTitles, SubagentTurn, TurnUsage } from './types/transcript.types.js';
|
|
2
2
|
export type { ReadTurnUsageRetry, TranscriptUsageEntry, TurnUsage } from './types/transcript.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Authoritative per-turn token usage from Claude Code's transcript JSONL.
|
|
@@ -16,6 +16,40 @@ export type { ReadTurnUsageRetry, TranscriptUsageEntry, TurnUsage } from './type
|
|
|
16
16
|
* @returns The turn's usage, or undefined when the transcript reports none.
|
|
17
17
|
*/
|
|
18
18
|
export declare function readTurnUsage(transcriptPath: string, sinceIso: string, retry?: ReadTurnUsageRetry, untilIso?: string, excludeMessageIds?: ReadonlySet<string>): Promise<TurnUsage | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* The usage a turn's subagents recorded, out of their own transcripts.
|
|
21
|
+
*
|
|
22
|
+
* Claude Code writes each subagent to `<session>/subagents/agent-<id>.jsonl`,
|
|
23
|
+
* never to the session's own transcript. A subagent's user lines name the
|
|
24
|
+
* parent's prompt id, the one that launched it or a later one that resumed it,
|
|
25
|
+
* so each assistant line belongs to the prompt id of the user line above it.
|
|
26
|
+
* Lines before the first such line (a fork's copy of the parent's last reply)
|
|
27
|
+
* are no one's here; the parent's own read counts that message. A file longer
|
|
28
|
+
* than the tail takes the last prompt id stated before the tail.
|
|
29
|
+
*
|
|
30
|
+
* A Stop reads every subagent file written since the turn began; a subagent's
|
|
31
|
+
* own stop reads only that subagent's file. One pass, no settle loop: a
|
|
32
|
+
* foreground subagent has stopped before its parent does, and a background one
|
|
33
|
+
* re-reads on its own stop. Never throws.
|
|
34
|
+
*
|
|
35
|
+
* @param payload - The raw hook payload.
|
|
36
|
+
* @param turn - The parent turn; its window is not used, the prompt id is exact.
|
|
37
|
+
* @param excludeMessageIds - Messages already claimed.
|
|
38
|
+
* @returns The subagents' usage in this turn, or undefined when there is none.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readClaudeSubagentUsage(payload: unknown, turn: SubagentTurn, excludeMessageIds: ReadonlySet<string>): Promise<TurnUsage | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* The turns a stopping subagent's lines name, oldest first: the prompt that
|
|
43
|
+
* launched it and any that resumed it.
|
|
44
|
+
*
|
|
45
|
+
* A `SubagentStop` names the session's current prompt (Claude Code 2.1.325),
|
|
46
|
+
* not the one that launched the subagent, so the turn a background subagent's
|
|
47
|
+
* late usage belongs to is read from its own lines.
|
|
48
|
+
*
|
|
49
|
+
* @param payload - The subagent's stop payload.
|
|
50
|
+
* @returns The prompt ids; empty when the payload names no subagent or its file cannot be read.
|
|
51
|
+
*/
|
|
52
|
+
export declare function readClaudeSubagentTurnIds(payload: unknown): Promise<string[]>;
|
|
19
53
|
/**
|
|
20
54
|
* The session's titles, from the tail of Claude Code's transcript.
|
|
21
55
|
*
|