@agent-watch-ai/edge 0.5.0 → 0.7.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 +238 -7
- package/README.md +308 -8
- package/dist/billing/billing-mode.d.ts +37 -5
- package/dist/billing/billing-mode.js +28 -19
- package/dist/billing/constants/billing.constants.d.ts +0 -2
- package/dist/billing/constants/billing.constants.js +0 -2
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.js +1 -1
- package/dist/billing/session-billing.d.ts +3 -2
- package/dist/billing/session-billing.js +8 -8
- package/dist/billing/types/billing.types.d.ts +7 -0
- package/dist/capture/capture-env.d.ts +147 -0
- package/dist/capture/capture-env.js +301 -0
- package/dist/capture/captured-step.d.ts +88 -0
- package/dist/capture/captured-step.js +479 -0
- package/dist/capture/constants/capture.constants.d.ts +70 -0
- package/dist/capture/constants/capture.constants.js +72 -0
- package/dist/capture/launched-runs.d.ts +16 -0
- package/dist/capture/launched-runs.js +151 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +823 -0
- package/dist/capture/schemas/capture.schema.d.ts +35 -0
- package/dist/capture/schemas/capture.schema.js +31 -0
- package/dist/capture/types/capture.types.d.ts +20 -0
- package/dist/cli/constants/cli.constants.d.ts +2 -6
- package/dist/cli/constants/cli.constants.js +3 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +13 -0
- package/dist/cli/doctor-run-capture.js +19 -0
- package/dist/cli/doctor.js +16 -67
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +40 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/misc.js +10 -2
- package/dist/cli/replay.d.ts +33 -0
- package/dist/cli/replay.js +193 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +154 -26
- package/dist/cli/status.js +45 -5
- package/dist/cli/toggle.js +10 -0
- package/dist/cli/types/cli.types.d.ts +15 -1
- package/dist/cli/uninstall.js +8 -22
- package/dist/cli.js +104 -17
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.js +2 -0
- package/dist/config/events-transport.d.ts +15 -0
- package/dist/config/events-transport.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/root-config.d.ts +12 -0
- package/dist/config/root-config.js +24 -0
- package/dist/config/schemas/config.schema.d.ts +13 -0
- package/dist/config/schemas/config.schema.js +42 -6
- package/dist/config/types/config.types.d.ts +7 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/version.d.ts +9 -0
- package/dist/core/version.js +14 -0
- package/dist/core/which.d.ts +11 -0
- package/dist/core/which.js +18 -0
- package/dist/credentials/cloud-claim.d.ts +32 -0
- package/dist/credentials/cloud-claim.js +42 -0
- package/dist/credentials/constants/credentials.constants.d.ts +8 -1
- package/dist/credentials/constants/credentials.constants.js +9 -2
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/sign-in.d.ts +27 -0
- package/dist/credentials/sign-in.js +31 -1
- package/dist/credentials/token-refresher.d.ts +5 -1
- package/dist/credentials/token-refresher.js +10 -2
- package/dist/events/constants/events.constants.d.ts +8 -2
- package/dist/events/constants/events.constants.js +7 -1
- package/dist/events/index.d.ts +2 -0
- package/dist/events/product-event.d.ts +10 -4
- package/dist/events/types/events.types.d.ts +6 -0
- package/dist/events/types/replay-progress.types.d.ts +26 -0
- package/dist/events/types/replay-progress.types.js +1 -0
- package/dist/events/types/repo-snapshot.types.d.ts +1 -4
- package/dist/events/types/repo-tree.types.d.ts +25 -0
- package/dist/events/types/repo-tree.types.js +1 -0
- package/dist/feature/ticket-candidates.d.ts +1 -1
- package/dist/git/checkout-root.d.ts +15 -0
- package/dist/git/checkout-root.js +18 -0
- package/dist/git/code-state.d.ts +2 -16
- package/dist/git/code-state.js +11 -12
- package/dist/git/constants/git.constants.d.ts +31 -11
- package/dist/git/constants/git.constants.js +36 -12
- package/dist/git/constants/tree.constants.d.ts +71 -0
- package/dist/git/constants/tree.constants.js +92 -0
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.d.ts +1 -0
- package/dist/git/git-context.js +8 -3
- package/dist/git/index.d.ts +1 -2
- package/dist/git/index.js +1 -1
- package/dist/git/repo-snapshot.d.ts +13 -4
- package/dist/git/repo-snapshot.js +47 -9
- package/dist/git/repo-tree.d.ts +69 -0
- package/dist/git/repo-tree.js +130 -0
- package/dist/git/types/git.types.d.ts +5 -2
- package/dist/git/types/snapshot.types.d.ts +14 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +112 -72
- package/dist/privacy/product-capture.js +36 -5
- package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.capture.js +5 -0
- package/dist/providers/antigravity/antigravity.detect.js +8 -22
- package/dist/providers/antigravity/antigravity.provider.js +10 -3
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
- package/dist/providers/claude/claude.adapter.js +9 -6
- package/dist/providers/claude/claude.detect.js +2 -17
- package/dist/providers/claude/claude.otel.d.ts +21 -3
- package/dist/providers/claude/claude.otel.js +216 -61
- package/dist/providers/claude/claude.provider.js +17 -1
- package/dist/providers/claude/claude.version.d.ts +9 -0
- package/dist/providers/claude/claude.version.js +28 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.constants.js +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
- package/dist/providers/claude/types/claude.types.d.ts +13 -0
- package/dist/providers/codex/codex.capture.d.ts +76 -0
- package/dist/providers/codex/codex.capture.js +454 -0
- package/dist/providers/codex/codex.detect.js +2 -4
- package/dist/providers/codex/codex.otel.d.ts +38 -2
- package/dist/providers/codex/codex.otel.js +50 -6
- package/dist/providers/codex/codex.provider.js +8 -0
- package/dist/providers/codex/codex.surface.d.ts +9 -0
- package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
- package/dist/providers/codex/codex.titles.d.ts +14 -0
- package/dist/providers/codex/codex.titles.js +35 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
- package/dist/providers/codex/constants/codex.constants.js +4 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
- package/dist/providers/cursor/constants/cursor.constants.js +25 -5
- package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
- package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
- package/dist/providers/cursor/cursor.adapter.js +20 -82
- package/dist/providers/cursor/cursor.capture.d.ts +1 -0
- package/dist/providers/cursor/cursor.capture.js +4 -0
- package/dist/providers/cursor/cursor.detect.d.ts +5 -1
- package/dist/providers/cursor/cursor.detect.js +11 -26
- package/dist/providers/cursor/cursor.hooks.js +2 -2
- package/dist/providers/cursor/cursor.provider.js +16 -7
- package/dist/providers/cursor/cursor.titles.d.ts +14 -0
- package/dist/providers/cursor/cursor.titles.js +20 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
- package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
- package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
- package/dist/providers/gemini/constants/gemini.constants.js +17 -0
- package/dist/providers/gemini/gemini.capture.d.ts +81 -0
- package/dist/providers/gemini/gemini.capture.js +210 -0
- package/dist/providers/gemini/gemini.detect.js +57 -24
- package/dist/providers/gemini/gemini.otel.d.ts +38 -2
- package/dist/providers/gemini/gemini.otel.js +56 -125
- package/dist/providers/gemini/gemini.provider.js +5 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/provider.d.ts +8 -0
- package/dist/providers/provider.js +9 -0
- package/dist/providers/registry.d.ts +14 -0
- package/dist/providers/registry.js +14 -0
- package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
- package/dist/providers/shared/constants/hook-config.constants.js +2 -0
- package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
- package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
- package/dist/providers/shared/editor-paths.d.ts +8 -0
- package/dist/providers/shared/editor-paths.js +18 -0
- package/dist/providers/shared/hook-config.d.ts +5 -0
- package/dist/providers/shared/hook-config.js +39 -1
- package/dist/providers/shared/hooks-marker.d.ts +14 -0
- package/dist/providers/shared/hooks-marker.js +23 -0
- package/dist/providers/shared/install-record.d.ts +29 -0
- package/dist/providers/shared/install-record.js +52 -0
- package/dist/providers/shared/session-title-store.d.ts +23 -0
- package/dist/providers/shared/session-title-store.js +50 -0
- package/dist/providers/shared/terminal-capture.d.ts +41 -0
- package/dist/providers/shared/terminal-capture.js +109 -0
- package/dist/providers/shared/tooling.d.ts +21 -0
- package/dist/providers/shared/tooling.js +36 -1
- package/dist/providers/types/provider.types.d.ts +57 -4
- package/dist/replay/checkout-resolver.d.ts +29 -0
- package/dist/replay/checkout-resolver.js +69 -0
- package/dist/replay/codex-turns.d.ts +24 -0
- package/dist/replay/codex-turns.js +221 -0
- package/dist/replay/constants/replay.constants.d.ts +99 -0
- package/dist/replay/constants/replay.constants.js +102 -0
- package/dist/replay/describe.d.ts +10 -0
- package/dist/replay/describe.js +31 -0
- package/dist/replay/gemini-turns.d.ts +36 -0
- package/dist/replay/gemini-turns.js +192 -0
- package/dist/replay/machine.d.ts +34 -0
- package/dist/replay/machine.js +68 -0
- package/dist/replay/progress-event.d.ts +21 -0
- package/dist/replay/progress-event.js +45 -0
- package/dist/replay/replay-runner.d.ts +58 -0
- package/dist/replay/replay-runner.js +529 -0
- package/dist/replay/replay-scan.d.ts +83 -0
- package/dist/replay/replay-scan.js +170 -0
- package/dist/replay/replay-state.d.ts +108 -0
- package/dist/replay/replay-state.js +199 -0
- package/dist/replay/resume.d.ts +18 -0
- package/dist/replay/resume.js +34 -0
- package/dist/replay/start.d.ts +23 -0
- package/dist/replay/start.js +39 -0
- package/dist/replay/throttle.d.ts +35 -0
- package/dist/replay/throttle.js +41 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +215 -0
- package/dist/replay/turn-event.d.ts +38 -0
- package/dist/replay/turn-event.js +116 -0
- package/dist/replay/types/replay.types.d.ts +162 -0
- package/dist/replay/types/replay.types.js +1 -0
- package/dist/replay/window.d.ts +28 -0
- package/dist/replay/window.js +41 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +74 -42
- package/dist/snapshot/budget.js +2 -2
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +10 -0
- package/dist/snapshot/constants/snapshot-stages.constants.js +10 -0
- package/dist/snapshot/constants/snapshot.constants.d.ts +37 -4
- package/dist/snapshot/constants/snapshot.constants.js +37 -4
- package/dist/snapshot/index.d.ts +6 -1
- package/dist/snapshot/index.js +3 -1
- package/dist/snapshot/snapshot-event.d.ts +7 -0
- package/dist/snapshot/snapshot-event.js +8 -5
- package/dist/snapshot/snapshot-pipeline.js +89 -26
- package/dist/snapshot/snapshot-state.js +24 -2
- package/dist/snapshot/tree-event.d.ts +14 -0
- package/dist/snapshot/tree-event.js +91 -0
- package/dist/snapshot/tree-pipeline.d.ts +12 -0
- package/dist/snapshot/tree-pipeline.js +172 -0
- package/dist/snapshot/types/snapshot.types.d.ts +62 -2
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/transport/constants/transport.constants.d.ts +5 -0
- package/dist/transport/constants/transport.constants.js +5 -0
- package/dist/transport/delivery-stats.d.ts +13 -1
- package/dist/transport/delivery-stats.js +18 -2
- package/dist/transport/delivery.d.ts +4 -3
- package/dist/transport/delivery.js +21 -7
- package/dist/transport/identity-delivery.d.ts +20 -0
- package/dist/transport/identity-delivery.js +41 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/queue.js +40 -6
- package/dist/transport/types/delivery-flow.types.d.ts +7 -0
- package/dist/turns/claude-transcript.js +4 -12
- package/dist/turns/codex-transcript.d.ts +9 -0
- package/dist/turns/codex-transcript.js +27 -19
- package/dist/turns/constants/turns.constants.d.ts +13 -12
- package/dist/turns/constants/turns.constants.js +15 -19
- package/dist/turns/gemini-transcript.d.ts +19 -1
- package/dist/turns/gemini-transcript.js +29 -18
- package/dist/turns/index.d.ts +3 -4
- package/dist/turns/index.js +2 -3
- package/dist/turns/run-state.d.ts +71 -0
- package/dist/turns/run-state.js +114 -0
- package/dist/turns/tool-events.d.ts +11 -1
- package/dist/turns/tool-events.js +32 -9
- package/dist/turns/transcript.d.ts +15 -14
- package/dist/turns/transcript.js +23 -4
- package/dist/turns/turn-state.d.ts +49 -7
- package/dist/turns/turn-state.js +78 -10
- package/dist/turns/turn-summary.js +10 -6
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +162 -86
- package/dist/turns/types/transcript.types.d.ts +11 -1
- package/dist/turns/types/turn-provider.types.d.ts +33 -0
- package/dist/turns/types/turn-provider.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +9 -0
- package/dist/turns/types/turn-summary.types.d.ts +20 -6
- package/dist/turns/types/turn-tracker.types.d.ts +3 -1
- package/dist/turns/work-checkout.js +1 -2
- package/docs/AUDIT_PROMPT.md +10 -0
- package/docs/DATA_HANDLING.md +269 -32
- package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
- package/docs/PERFORMANCE.md +27 -0
- package/package.json +3 -2
- package/dist/events/canonical-event.d.ts +0 -10
- package/dist/events/canonical-event.js +0 -9
- package/dist/git/repository-root.d.ts +0 -39
- package/dist/git/repository-root.js +0 -131
- package/dist/git/types/repository-root.types.d.ts +0 -11
- package/dist/transport/transport.d.ts +0 -6
- package/dist/turns/codex-originator.d.ts +0 -11
- package/dist/turns/cursor-transcript.d.ts +0 -21
- package/dist/turns/cursor-transcript.js +0 -66
- package/dist/turns/native-session-titles.d.ts +0 -26
- package/dist/turns/native-session-titles.js +0 -102
- /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
- /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
|
@@ -2,7 +2,15 @@ import path from 'node:path';
|
|
|
2
2
|
import { asRecord, firstString } from '../../core/object.js';
|
|
3
3
|
import { sanitizeText } from '../../privacy/sanitizer.js';
|
|
4
4
|
import { sha256Hex } from '../../events/event-id.js';
|
|
5
|
-
import { COMMAND_KEYS, FILE_EDIT_TOOLS, FILE_PATH_KEYS, FILE_READ_TOOLS, COMMAND_HEAD, MAX_TOOL_KEY_LENGTH, MCP_FOLDED_KEY, MCP_TOOL_PREFIX, MCP_TOOL_SEPARATOR, SHELL_TOOLS } from './constants/tooling.constants.js';
|
|
5
|
+
import { COMMAND_KEYS, FILE_EDIT_TOOLS, FILE_PATH_KEYS, FILE_READ_TOOLS, COMMAND_HEAD, MAX_TOOL_KEY_LENGTH, MCP_FOLDED_KEY, MCP_TOOL_PREFIX, MCP_TOOL_SEPARATOR, RE_HARNESS_BLOCK, SHELL_TOOLS } from './constants/tooling.constants.js';
|
|
6
|
+
/** Core's name rule (AWT-710); a value that fails it is never sent. */
|
|
7
|
+
const RE_NAME = /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,79}$/;
|
|
8
|
+
/**
|
|
9
|
+
* A prompt's leading `/token`. No `/` inside it: `/Users/me/a.ts fix this` is a path, not a command.
|
|
10
|
+
* ponytail: a one-segment path (`/tmp is full`) still reads as command `tmp`, one name-shaped word;
|
|
11
|
+
* upgrade path is checking the token against the agent's own command list.
|
|
12
|
+
*/
|
|
13
|
+
const RE_SLASH_COMMAND = /^\/([A-Za-z0-9][A-Za-z0-9_.:-]{0,79})(?:\s|$)/;
|
|
6
14
|
/**
|
|
7
15
|
* What kind of thing a tool call is, whatever the agent calls it.
|
|
8
16
|
*
|
|
@@ -162,6 +170,33 @@ export function extractCommand(toolInput) {
|
|
|
162
170
|
return undefined;
|
|
163
171
|
return firstString(record, COMMAND_KEYS);
|
|
164
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* The skill a skill call invoked, its name and nothing else.
|
|
175
|
+
*
|
|
176
|
+
* Read in memory from the call's input; its arguments are never looked at.
|
|
177
|
+
* A name core would refuse is dropped here, never the call it rides on.
|
|
178
|
+
*
|
|
179
|
+
* @param input - The skill tool's input as the agent passed it.
|
|
180
|
+
* @param key - The input field naming the skill.
|
|
181
|
+
* @returns The trimmed name, or undefined when there is no valid one.
|
|
182
|
+
*/
|
|
183
|
+
export function skillName(input, key) {
|
|
184
|
+
const name = asRecord(input)?.[key];
|
|
185
|
+
return typeof name === 'string' && RE_NAME.test(name.trim()) ? name.trim() : undefined;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The slash command a prompt starts with, without its slash or arguments.
|
|
189
|
+
*
|
|
190
|
+
* Only the matched token survives: nothing after it, and nothing at all from
|
|
191
|
+
* a prompt that does not open with one.
|
|
192
|
+
*
|
|
193
|
+
* @param prompt - The prompt as the agent reported it.
|
|
194
|
+
* @returns The command name, or undefined.
|
|
195
|
+
*/
|
|
196
|
+
export function slashCommandName(prompt) {
|
|
197
|
+
// Harness blocks first, as `promptPatch` drops them: they are not what the person typed.
|
|
198
|
+
return prompt === undefined ? undefined : RE_SLASH_COMMAND.exec(prompt.replace(RE_HARNESS_BLOCK, '').trimStart())?.[1];
|
|
199
|
+
}
|
|
165
200
|
/**
|
|
166
201
|
* A shell call out of untrusted payload fields, type-checked.
|
|
167
202
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentWatchConfig, OtelSignalName } from '../../config/types/config.types.js';
|
|
2
2
|
import type { Env } from '../../core/types/core.types.js';
|
|
3
3
|
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
4
|
+
import type { TurnProvider } from '../../turns/types/turn-provider.types.js';
|
|
4
5
|
import type { AgentWatchPaths, InstallState } from '../../storage/types/storage.types.js';
|
|
5
6
|
/** What detection found out about one agent on this machine. */
|
|
6
7
|
export interface DetectionResult {
|
|
@@ -43,6 +44,11 @@ export interface SetupOutcome {
|
|
|
43
44
|
readonly changed: boolean;
|
|
44
45
|
/** User-facing notes: required manual steps, skip reasons, errors. */
|
|
45
46
|
readonly messages: readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* Refused because the developer's own telemetry config is in the way. A
|
|
49
|
+
* skipped step, not a failure: nothing AgentWatch can or should repair.
|
|
50
|
+
*/
|
|
51
|
+
readonly conflict?: boolean;
|
|
46
52
|
/**
|
|
47
53
|
* Install state after this operation, when it recorded anything.
|
|
48
54
|
*
|
|
@@ -69,7 +75,23 @@ export interface NativeTelemetryStatus {
|
|
|
69
75
|
readonly conflict?: string;
|
|
70
76
|
readonly detail?: string;
|
|
71
77
|
}
|
|
78
|
+
/** Whether what this agent's shell tool starts loads the capture shims. */
|
|
79
|
+
export interface RunCaptureStatus {
|
|
80
|
+
readonly on: boolean;
|
|
81
|
+
/** Why it is off, in words a developer can act on. */
|
|
82
|
+
readonly reason?: string;
|
|
83
|
+
/** It is on, but something should be done about it. */
|
|
84
|
+
readonly warning?: string;
|
|
85
|
+
}
|
|
86
|
+
/** How one agent's launched processes get the capture shims in their environment. */
|
|
87
|
+
export interface RunCaptureRoute {
|
|
88
|
+
inspect(context: SetupContext): Promise<RunCaptureStatus>;
|
|
89
|
+
/** The file this route writes the shims into; the shared copy stays while any of them names it. */
|
|
90
|
+
configPath(env: Env): string;
|
|
91
|
+
}
|
|
72
92
|
export interface NativeTelemetryConfigurator {
|
|
93
|
+
/** The run-capture route, for an agent whose telemetry config also carries it. */
|
|
94
|
+
readonly runCapture?: RunCaptureRoute;
|
|
73
95
|
supported(env: Env): Promise<boolean>;
|
|
74
96
|
inspect(context: SetupContext): Promise<NativeTelemetryStatus>;
|
|
75
97
|
configure(context: SetupContext): Promise<SetupOutcome>;
|
|
@@ -99,8 +121,8 @@ export interface NativeTelemetryConfigurator {
|
|
|
99
121
|
*/
|
|
100
122
|
rewriteBearer?(context: BearerRewriteContext): Promise<boolean>;
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
/** One coding agent; the turn tracker reads the `TurnProvider` part. */
|
|
125
|
+
export interface AgentProvider extends TurnProvider {
|
|
104
126
|
readonly displayName: string;
|
|
105
127
|
detect(env: Env): Promise<DetectionResult>;
|
|
106
128
|
installHooks(context: SetupContext): Promise<SetupOutcome>;
|
|
@@ -125,6 +147,13 @@ export interface AgentProvider {
|
|
|
125
147
|
* channel, and the line is not shown.
|
|
126
148
|
*/
|
|
127
149
|
getNoticeResponse?(payload: unknown, message: string): ProviderHookResponse | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Whether this payload is processed by a detached `agentwatch hook`, so the
|
|
152
|
+
* agent is answered at once instead of waiting on the send. Only for a hook
|
|
153
|
+
* that answers nothing, and only where nothing that follows at once (a
|
|
154
|
+
* session end clearing its state) would race the detached process.
|
|
155
|
+
*/
|
|
156
|
+
runsDetached?(payload: unknown, env: Env): boolean;
|
|
128
157
|
/**
|
|
129
158
|
* Working directory this payload was produced in, when the provider does not
|
|
130
159
|
* report it as a top-level `cwd`. Git context, repository config and ticket
|
|
@@ -136,8 +165,9 @@ export interface AgentProvider {
|
|
|
136
165
|
* The shell command a tool-start payload is about to run, and the directory
|
|
137
166
|
* it runs in when the agent reports one apart from `cwd`.
|
|
138
167
|
*
|
|
139
|
-
* Read
|
|
140
|
-
*
|
|
168
|
+
* Read in memory, for the directory names in it and for what it runs; the text
|
|
169
|
+
* is dropped there and never reaches an event, a record or a log. The one thing
|
|
170
|
+
* kept is a captured run's scrubbed entry file (`src/capture/launched-runs.ts`).
|
|
141
171
|
* Undefined for any payload that is not a shell call.
|
|
142
172
|
*/
|
|
143
173
|
shellCall?(payload: unknown): ShellCall | undefined;
|
|
@@ -148,6 +178,29 @@ export interface AgentProvider {
|
|
|
148
178
|
*/
|
|
149
179
|
workspaceRoots?(payload: unknown): readonly string[] | undefined;
|
|
150
180
|
readonly nativeTelemetry?: NativeTelemetryConfigurator;
|
|
181
|
+
/** Run capture, for an agent with no telemetry config to carry it. */
|
|
182
|
+
readonly runCapture?: RunCaptureRoute;
|
|
183
|
+
/**
|
|
184
|
+
* What this agent cannot report, which no setting fixes. Setup, status and
|
|
185
|
+
* doctor show them, so an absent number reads as a known gap rather than a
|
|
186
|
+
* bug in the edge.
|
|
187
|
+
*/
|
|
188
|
+
readonly caveats?: readonly ProviderCaveat[];
|
|
189
|
+
/** What doctor should check about the agent itself, such as its version. */
|
|
190
|
+
readonly checks?: (env: Env) => Promise<readonly ProviderCheck[]>;
|
|
191
|
+
}
|
|
192
|
+
/** One doctor check an agent runs on itself; see `AgentProvider.checks`. */
|
|
193
|
+
export interface ProviderCheck {
|
|
194
|
+
readonly name: string;
|
|
195
|
+
readonly level: 'ok' | 'warn';
|
|
196
|
+
readonly detail: string;
|
|
197
|
+
}
|
|
198
|
+
/** One known limitation of an agent; see `AgentProvider.caveats`. */
|
|
199
|
+
export interface ProviderCaveat {
|
|
200
|
+
/** Short label, e.g. "Cursor token usage". */
|
|
201
|
+
readonly name: string;
|
|
202
|
+
/** One line saying what is missing and why. */
|
|
203
|
+
readonly detail: string;
|
|
151
204
|
}
|
|
152
205
|
/** A shell call as the agent is about to run it. Memory only; see `AgentProvider.shellCall`. */
|
|
153
206
|
export interface ShellCall {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReplayCheckout, ReplayTurn } from './types/replay.types.js';
|
|
2
|
+
/** Answers "which repository is this folder in?" for a transcript's folders, asking git once per folder. */
|
|
3
|
+
export type CheckoutResolver = (cwd: string) => Promise<ReplayCheckout | undefined>;
|
|
4
|
+
/**
|
|
5
|
+
* A resolver that remembers its answers for the run.
|
|
6
|
+
*
|
|
7
|
+
* Two git processes per distinct folder, however many turns ran there; a
|
|
8
|
+
* folder that no longer exists answers nothing, and so do the turns that ran
|
|
9
|
+
* in it (their tokens still count, with no repository). Not the whole git
|
|
10
|
+
* context the hooks take: no branch, commit or status, because the branch is
|
|
11
|
+
* the transcript's and the commit is not known.
|
|
12
|
+
*
|
|
13
|
+
* @returns The resolver.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCheckoutResolver(): CheckoutResolver;
|
|
16
|
+
/**
|
|
17
|
+
* The checkout a turn ran in: its folder's, or else the first one its tool files lie in.
|
|
18
|
+
*
|
|
19
|
+
* Mirrors the live hook's `changed → carried → referenced → cwd` ladder as far as a
|
|
20
|
+
* transcript allows: a folder that is no checkout (an umbrella folder) or is gone
|
|
21
|
+
* still leaves tool calls naming absolute files inside real repositories.
|
|
22
|
+
* A file the turn edited says it `changed` that checkout; reads alone name none.
|
|
23
|
+
*
|
|
24
|
+
* @param turn - The turn.
|
|
25
|
+
* @param resolve - The run's resolver.
|
|
26
|
+
* @param accept - Whether a tool file's checkout may be used (it may belong to another root's identity); a refused one is passed over.
|
|
27
|
+
* @returns The checkout and whether its `root` still makes the tool paths relative; undefined when none resolves.
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkoutOfTurn(turn: Pick<ReplayTurn, 'cwd' | 'tools'>, resolve: CheckoutResolver, accept?: (checkout: ReplayCheckout) => boolean): Promise<ReplayCheckout | undefined>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { GIT_REMOTE_ARGS, GIT_REPO_ROOT_ARGS, GIT_TIMEOUT_MS } from '../git/constants/git.constants.js';
|
|
3
|
+
import { repositoryIdentity, runGit } from '../git/git-context.js';
|
|
4
|
+
/**
|
|
5
|
+
* A resolver that remembers its answers for the run.
|
|
6
|
+
*
|
|
7
|
+
* Two git processes per distinct folder, however many turns ran there; a
|
|
8
|
+
* folder that no longer exists answers nothing, and so do the turns that ran
|
|
9
|
+
* in it (their tokens still count, with no repository). Not the whole git
|
|
10
|
+
* context the hooks take: no branch, commit or status, because the branch is
|
|
11
|
+
* the transcript's and the commit is not known.
|
|
12
|
+
*
|
|
13
|
+
* @returns The resolver.
|
|
14
|
+
*/
|
|
15
|
+
export function createCheckoutResolver() {
|
|
16
|
+
const answers = new Map();
|
|
17
|
+
return (cwd) => {
|
|
18
|
+
const known = answers.get(cwd);
|
|
19
|
+
if (known)
|
|
20
|
+
return known;
|
|
21
|
+
const asked = resolveCheckout(cwd);
|
|
22
|
+
answers.set(cwd, asked);
|
|
23
|
+
return asked;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function resolveCheckout(cwd) {
|
|
27
|
+
const root = await runGit(GIT_REPO_ROOT_ARGS, cwd, GIT_TIMEOUT_MS);
|
|
28
|
+
if (!root)
|
|
29
|
+
return undefined;
|
|
30
|
+
const { repository } = repositoryIdentity(root, await runGit(GIT_REMOTE_ARGS, root, GIT_TIMEOUT_MS));
|
|
31
|
+
return repository ? { root, repository } : undefined;
|
|
32
|
+
}
|
|
33
|
+
/** How many distinct folders of a turn's tool files are asked about before giving up. */
|
|
34
|
+
const MAX_TOOL_FOLDERS = 10;
|
|
35
|
+
/**
|
|
36
|
+
* The checkout a turn ran in: its folder's, or else the first one its tool files lie in.
|
|
37
|
+
*
|
|
38
|
+
* Mirrors the live hook's `changed → carried → referenced → cwd` ladder as far as a
|
|
39
|
+
* transcript allows: a folder that is no checkout (an umbrella folder) or is gone
|
|
40
|
+
* still leaves tool calls naming absolute files inside real repositories.
|
|
41
|
+
* A file the turn edited says it `changed` that checkout; reads alone name none.
|
|
42
|
+
*
|
|
43
|
+
* @param turn - The turn.
|
|
44
|
+
* @param resolve - The run's resolver.
|
|
45
|
+
* @param accept - Whether a tool file's checkout may be used (it may belong to another root's identity); a refused one is passed over.
|
|
46
|
+
* @returns The checkout and whether its `root` still makes the tool paths relative; undefined when none resolves.
|
|
47
|
+
*/
|
|
48
|
+
export async function checkoutOfTurn(turn, resolve, accept = () => true) {
|
|
49
|
+
const byFolder = turn.cwd ? await resolve(turn.cwd) : undefined;
|
|
50
|
+
if (byFolder)
|
|
51
|
+
return byFolder;
|
|
52
|
+
const asked = new Set();
|
|
53
|
+
// Edits only: a file the turn merely read says too little to name its repository (the live ladder's
|
|
54
|
+
// `referenced` rung is weaker than `changed`), and would send that repository's snapshot.
|
|
55
|
+
for (const tool of turn.tools) {
|
|
56
|
+
if (tool.access !== 'edit' || !tool.path || !path.isAbsolute(tool.path))
|
|
57
|
+
continue;
|
|
58
|
+
const folder = path.dirname(tool.path);
|
|
59
|
+
if (asked.has(folder))
|
|
60
|
+
continue;
|
|
61
|
+
if (asked.size >= MAX_TOOL_FOLDERS)
|
|
62
|
+
break;
|
|
63
|
+
asked.add(folder);
|
|
64
|
+
const found = await resolve(folder);
|
|
65
|
+
if (found && accept(found))
|
|
66
|
+
return { ...found, evidence: 'changed' };
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReplaySource, ReplayTurn } from './types/replay.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Codex's rollouts as a replay source.
|
|
4
|
+
*
|
|
5
|
+
* @param home - `CODEX_HOME`, as the provider resolves it.
|
|
6
|
+
* @returns The source.
|
|
7
|
+
*/
|
|
8
|
+
export declare function codexSource(home: string): ReplaySource;
|
|
9
|
+
/**
|
|
10
|
+
* Stream a Codex rollout as the turns the live hook closed.
|
|
11
|
+
*
|
|
12
|
+
* A turn runs from `task_started` to its `task_complete` (or the next
|
|
13
|
+
* `task_started`, or the end of the file) and carries the rollout's `turn_id`,
|
|
14
|
+
* which is the id the live Codex hook sends. Only the rows named in
|
|
15
|
+
* {@link RE_CODEX_REPLAY_ROW} are parsed, plus the prompt rows when prompt text
|
|
16
|
+
* is allowed: messages, reasoning and tool output are never decoded. A turn
|
|
17
|
+
* with no token row did nothing billable and is not yielded. The branch and
|
|
18
|
+
* remote are `session_meta.git`, recorded once at session start, not per turn: still better than none.
|
|
19
|
+
*
|
|
20
|
+
* @param file - A `rollout-*.jsonl` file.
|
|
21
|
+
* @param promptText - Whether to keep the prompt's text; off unless the config allows it.
|
|
22
|
+
* @yields Turns, oldest first.
|
|
23
|
+
*/
|
|
24
|
+
export declare function readCodexTurns(file: string, promptText: boolean): AsyncGenerator<ReplayTurn>;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import fsp from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import readline from 'node:readline';
|
|
5
|
+
import { asRecord, firstStringOf } from '../core/object.js';
|
|
6
|
+
import { sha256Hex } from '../events/event-id.js';
|
|
7
|
+
import { CODEX_EXEC_ORIGINATOR, CODEX_PROVIDER_ID } from '../providers/codex/constants/codex.constants.js';
|
|
8
|
+
import { codexRowUsage } from '../turns/codex-transcript.js';
|
|
9
|
+
import { DEFAULT_SURFACE, EXEC_SURFACE } from '../turns/constants/turns.constants.js';
|
|
10
|
+
import { accumulateUsage, messageIdFor, parseJsonLine } from '../turns/transcript.js';
|
|
11
|
+
import { CODEX_ROLLOUT_PREFIX, CODEX_SESSIONS_DIR, DETACHED_BRANCH, RE_CODEX_PROMPT_ROW, RE_CODEX_REPLAY_ROW, RE_CODEX_TURN_START, REPLAY_FALLBACK_TURN_PREFIX } from './constants/replay.constants.js';
|
|
12
|
+
import { estimateTurns, recentFiles } from './replay-scan.js';
|
|
13
|
+
/**
|
|
14
|
+
* Codex's rollouts as a replay source.
|
|
15
|
+
*
|
|
16
|
+
* @param home - `CODEX_HOME`, as the provider resolves it.
|
|
17
|
+
* @returns The source.
|
|
18
|
+
*/
|
|
19
|
+
export function codexSource(home) {
|
|
20
|
+
const sessions = path.join(home, CODEX_SESSIONS_DIR);
|
|
21
|
+
return {
|
|
22
|
+
agent: CODEX_PROVIDER_ID,
|
|
23
|
+
list: (sinceMs) => listRollouts(sessions, sinceMs),
|
|
24
|
+
estimate: (file, sinceMs) => estimateTurns(file, sinceMs, RE_CODEX_TURN_START),
|
|
25
|
+
identity: codexIdentity,
|
|
26
|
+
read: readCodexTurns
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The rollouts written inside the window, from `sessions/YYYY/MM/DD`.
|
|
31
|
+
*
|
|
32
|
+
* ponytail: every file is stat'ed; no day folder is skipped by its name, because a resumed
|
|
33
|
+
* session appends to the rollout in the folder of the day it began. About a second for ten
|
|
34
|
+
* thousand rollouts.
|
|
35
|
+
*
|
|
36
|
+
* @param sessions - `CODEX_HOME/sessions`.
|
|
37
|
+
* @param sinceMs - The window's start.
|
|
38
|
+
* @returns The files; empty when Codex has left none.
|
|
39
|
+
*/
|
|
40
|
+
async function listRollouts(sessions, sinceMs) {
|
|
41
|
+
const found = [];
|
|
42
|
+
for (const day of await subfolders(sessions, 3))
|
|
43
|
+
found.push(...(await recentFiles(day, sinceMs, CODEX_ROLLOUT_PREFIX)));
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The folders `depth` levels below a folder.
|
|
48
|
+
*
|
|
49
|
+
* @param dir - Where to start.
|
|
50
|
+
* @param depth - How many levels down.
|
|
51
|
+
* @returns Their paths; empty when the folder is missing.
|
|
52
|
+
*/
|
|
53
|
+
async function subfolders(dir, depth) {
|
|
54
|
+
if (depth === 0)
|
|
55
|
+
return [dir];
|
|
56
|
+
const entries = await fsp.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
57
|
+
const found = [];
|
|
58
|
+
for (const entry of entries)
|
|
59
|
+
if (entry.isDirectory())
|
|
60
|
+
found.push(...(await subfolders(path.join(dir, entry.name), depth - 1)));
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A rollout's folder, remote, commit and branch: its first row, `session_meta`.
|
|
65
|
+
*
|
|
66
|
+
* @param file - A `rollout-*.jsonl` file.
|
|
67
|
+
* @returns What it says, or undefined when it has no folder.
|
|
68
|
+
*/
|
|
69
|
+
async function codexIdentity(file) {
|
|
70
|
+
const input = fs.createReadStream(file, { encoding: 'utf8' });
|
|
71
|
+
const lines = readline.createInterface({ input, crlfDelay: Infinity });
|
|
72
|
+
try {
|
|
73
|
+
for await (const line of lines) {
|
|
74
|
+
const row = parseJsonLine(line);
|
|
75
|
+
const payload = asRecord(row?.['payload']);
|
|
76
|
+
if (row?.['type'] !== 'session_meta' || !payload)
|
|
77
|
+
return undefined;
|
|
78
|
+
const { cwd, remote, commit, branch } = metaOf(payload);
|
|
79
|
+
return cwd ? { cwd, remote, commit, branch } : undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
lines.close();
|
|
84
|
+
// Closing the reader leaves the file open; one descriptor per rollout adds up.
|
|
85
|
+
input.destroy();
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Stream a Codex rollout as the turns the live hook closed.
|
|
91
|
+
*
|
|
92
|
+
* A turn runs from `task_started` to its `task_complete` (or the next
|
|
93
|
+
* `task_started`, or the end of the file) and carries the rollout's `turn_id`,
|
|
94
|
+
* which is the id the live Codex hook sends. Only the rows named in
|
|
95
|
+
* {@link RE_CODEX_REPLAY_ROW} are parsed, plus the prompt rows when prompt text
|
|
96
|
+
* is allowed: messages, reasoning and tool output are never decoded. A turn
|
|
97
|
+
* with no token row did nothing billable and is not yielded. The branch and
|
|
98
|
+
* remote are `session_meta.git`, recorded once at session start, not per turn: still better than none.
|
|
99
|
+
*
|
|
100
|
+
* @param file - A `rollout-*.jsonl` file.
|
|
101
|
+
* @param promptText - Whether to keep the prompt's text; off unless the config allows it.
|
|
102
|
+
* @yields Turns, oldest first.
|
|
103
|
+
*/
|
|
104
|
+
export async function* readCodexTurns(file, promptText) {
|
|
105
|
+
const lines = readline.createInterface({ input: fs.createReadStream(file, { encoding: 'utf8' }), crlfDelay: Infinity });
|
|
106
|
+
let state = { meta: { surface: DEFAULT_SURFACE } };
|
|
107
|
+
try {
|
|
108
|
+
for await (const line of lines) {
|
|
109
|
+
if (!RE_CODEX_REPLAY_ROW.test(line) && !(promptText && RE_CODEX_PROMPT_ROW.test(line)))
|
|
110
|
+
continue;
|
|
111
|
+
const row = parseJsonLine(line);
|
|
112
|
+
const payload = asRecord(row?.['payload']);
|
|
113
|
+
if (!row || !payload)
|
|
114
|
+
continue;
|
|
115
|
+
const step = stepRow(state, row, payload, line);
|
|
116
|
+
state = step.state;
|
|
117
|
+
if (step.closed)
|
|
118
|
+
yield step.closed;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
lines.close();
|
|
123
|
+
}
|
|
124
|
+
const last = state.open && closeTurn(state.open, state.meta);
|
|
125
|
+
if (last)
|
|
126
|
+
yield last;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* One row read: the state it leaves, and the turn it closed, if any.
|
|
130
|
+
*
|
|
131
|
+
* @param state - What the rollout said so far.
|
|
132
|
+
* @param row - The parsed row.
|
|
133
|
+
* @param payload - Its payload.
|
|
134
|
+
* @param line - The verbatim line.
|
|
135
|
+
* @returns The next state and a closed turn.
|
|
136
|
+
*/
|
|
137
|
+
function stepRow(state, row, payload, line) {
|
|
138
|
+
if (row['type'] === 'session_meta')
|
|
139
|
+
return { state: { ...state, meta: metaOf(payload) } };
|
|
140
|
+
const model = row['type'] === 'turn_context' ? (firstStringOf(payload['model']) ?? state.model) : state.model;
|
|
141
|
+
if (payload['type'] === 'task_started') {
|
|
142
|
+
const at = firstStringOf(row['timestamp']);
|
|
143
|
+
const open = at ? { turnId: firstStringOf(payload['turn_id']), startedAt: at, endedAt: at, model, usage: new Map() } : undefined;
|
|
144
|
+
return { state: { ...state, model, open }, closed: state.open && closeTurn(state.open, state.meta) };
|
|
145
|
+
}
|
|
146
|
+
if (!state.open)
|
|
147
|
+
return { state: { ...state, model } };
|
|
148
|
+
const open = foldRow(state.open, row, payload, line);
|
|
149
|
+
if (payload['type'] !== 'task_complete')
|
|
150
|
+
return { state: { ...state, model, open } };
|
|
151
|
+
return { state: { ...state, model, open: undefined }, closed: closeTurn(open, state.meta) };
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The session's id, folder and surface, from `session_meta`.
|
|
155
|
+
*
|
|
156
|
+
* @param payload - The row's payload.
|
|
157
|
+
* @returns What it says.
|
|
158
|
+
*/
|
|
159
|
+
function metaOf(payload) {
|
|
160
|
+
const git = asRecord(payload['git']);
|
|
161
|
+
const branch = firstStringOf(git?.['branch']);
|
|
162
|
+
return {
|
|
163
|
+
sessionId: firstStringOf(payload['id']),
|
|
164
|
+
cwd: firstStringOf(payload['cwd']),
|
|
165
|
+
branch: branch === DETACHED_BRANCH ? undefined : branch,
|
|
166
|
+
remote: firstStringOf(git?.['repository_url']),
|
|
167
|
+
commit: firstStringOf(git?.['commit_hash']),
|
|
168
|
+
// As the live hook resolves it (`codexSurface`): a headless `codex exec` run.
|
|
169
|
+
surface: payload['originator'] === CODEX_EXEC_ORIGINATOR ? EXEC_SURFACE : DEFAULT_SURFACE
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Fold one row into the open turn.
|
|
174
|
+
*
|
|
175
|
+
* @param open - The turn read so far.
|
|
176
|
+
* @param row - The parsed row.
|
|
177
|
+
* @param payload - Its payload.
|
|
178
|
+
* @param line - The verbatim line, whose hash keys a token row as the live reader keys it.
|
|
179
|
+
* @returns The turn with the row in it.
|
|
180
|
+
*/
|
|
181
|
+
function foldRow(open, row, payload, line) {
|
|
182
|
+
const at = firstStringOf(row['timestamp']);
|
|
183
|
+
const timed = at && at > open.endedAt ? { ...open, endedAt: at } : open;
|
|
184
|
+
if (row['type'] === 'turn_context') {
|
|
185
|
+
return { ...timed, turnId: timed.turnId ?? firstStringOf(payload['turn_id']), cwd: firstStringOf(payload['cwd']) ?? timed.cwd, model: firstStringOf(payload['model']) ?? timed.model };
|
|
186
|
+
}
|
|
187
|
+
if (payload['type'] === 'user_message')
|
|
188
|
+
return timed.promptText === undefined ? { ...timed, promptText: firstStringOf(payload['message']) } : timed;
|
|
189
|
+
const usage = codexRowUsage(payload);
|
|
190
|
+
return usage ? { ...timed, usage: new Map(timed.usage).set(messageIdFor(undefined, line), { model: timed.model, usage }) } : timed;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The turn a run of rows has become.
|
|
194
|
+
*
|
|
195
|
+
* @param open - The turn read so far.
|
|
196
|
+
* @param meta - The session's `session_meta`.
|
|
197
|
+
* @returns The turn, or undefined when it has no session id, no folder or no token row.
|
|
198
|
+
*/
|
|
199
|
+
function closeTurn(open, meta) {
|
|
200
|
+
const usage = accumulateUsage(open.usage);
|
|
201
|
+
const cwd = open.cwd ?? meta.cwd;
|
|
202
|
+
// No folder: no way to tell whether it ran under `ignoredRoots` or another root's identity.
|
|
203
|
+
if (!usage || !meta.sessionId || !cwd)
|
|
204
|
+
return undefined;
|
|
205
|
+
return {
|
|
206
|
+
provider: CODEX_PROVIDER_ID,
|
|
207
|
+
sessionId: meta.sessionId,
|
|
208
|
+
// A rollout from before turn ids: stable per session and start, so a second replay agrees with the first.
|
|
209
|
+
turnId: open.turnId ?? REPLAY_FALLBACK_TURN_PREFIX + sha256Hex(`${meta.sessionId}${open.startedAt}`).slice(0, 32),
|
|
210
|
+
startedAt: open.startedAt,
|
|
211
|
+
endedAt: open.endedAt,
|
|
212
|
+
cwd,
|
|
213
|
+
branch: meta.branch,
|
|
214
|
+
remote: meta.remote,
|
|
215
|
+
commit: meta.commit,
|
|
216
|
+
surface: meta.surface,
|
|
217
|
+
usage,
|
|
218
|
+
tools: [],
|
|
219
|
+
promptText: open.promptText?.trim() || undefined
|
|
220
|
+
};
|
|
221
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Days of history a replay reaches back when `--replay-days` names none. */
|
|
2
|
+
export declare const REPLAY_DEFAULT_DAYS = 30;
|
|
3
|
+
/** The most `--replay-days` accepts; a transcript older than the open charge period is never sent anyway. */
|
|
4
|
+
export declare const REPLAY_MAX_DAYS = 366;
|
|
5
|
+
/**
|
|
6
|
+
* Days into a month before the previous month's charges settle. A copy of core's
|
|
7
|
+
* `PLACEMENT_FINALIZATION_GRACE_DAYS` (packages/types/src/period-month.ts): the edge
|
|
8
|
+
* cannot import core, and the two must move together.
|
|
9
|
+
*/
|
|
10
|
+
export declare const REPLAY_FINALIZATION_GRACE_DAYS = 5;
|
|
11
|
+
/** Turns in one request. Small on purpose: the gateway budgets a batch at 8 s and the machine is someone's laptop. */
|
|
12
|
+
export declare const REPLAY_BATCH_TURNS = 20;
|
|
13
|
+
/** Between two requests, so a 1,000 turn history costs the backend under one request per five seconds. */
|
|
14
|
+
export declare const REPLAY_BATCH_INTERVAL_MS = 5000;
|
|
15
|
+
/** Between two transcript files, so the disk reads come up for air. */
|
|
16
|
+
export declare const REPLAY_FILE_PAUSE_MS = 200;
|
|
17
|
+
/** How long a busy machine (load, battery) is left alone before the next look. */
|
|
18
|
+
export declare const REPLAY_BUSY_PAUSE_MS = 30000;
|
|
19
|
+
/** The first wait after a failed request; it doubles up to {@link REPLAY_MAX_BACKOFF_MS}. */
|
|
20
|
+
export declare const REPLAY_BASE_BACKOFF_MS = 10000;
|
|
21
|
+
/** The longest wait after repeated failures. */
|
|
22
|
+
export declare const REPLAY_MAX_BACKOFF_MS = 300000;
|
|
23
|
+
/** Active time one run spends before it stops and waits to be resumed. */
|
|
24
|
+
export declare const REPLAY_RUN_BUDGET_MS: number;
|
|
25
|
+
/** A hook closed a turn this recently: an agent is working and replay waits. */
|
|
26
|
+
export declare const REPLAY_HOOK_QUIET_MS = 60000;
|
|
27
|
+
/** A progress record goes out every this many batches, besides its start, pauses and end. */
|
|
28
|
+
export declare const REPLAY_PROGRESS_EVERY_BATCHES = 5;
|
|
29
|
+
/**
|
|
30
|
+
* A turn that ended this recently may still be running; the live hook owns it.
|
|
31
|
+
* Replaying half a turn would hand the backend a smaller one than the hook's.
|
|
32
|
+
*/
|
|
33
|
+
export declare const REPLAY_LIVE_TURN_GRACE_MS: number;
|
|
34
|
+
/** A run whose state file has not been touched for this long is gone, whatever its pid says. */
|
|
35
|
+
export declare const REPLAY_HEARTBEAT_STALE_MS: number;
|
|
36
|
+
/** How often the battery is asked; `pmset` is a process start. */
|
|
37
|
+
export declare const REPLAY_BATTERY_CHECK_MS: number;
|
|
38
|
+
/** `nice` 19: the lowest priority the operating system offers. */
|
|
39
|
+
export declare const REPLAY_NICE = 19;
|
|
40
|
+
/** The 1-minute load average, per core, above which the machine counts as busy. */
|
|
41
|
+
export declare const REPLAY_BUSY_LOAD_PER_CORE = 0.5;
|
|
42
|
+
/** Where Claude Code keeps its transcripts, under HOME. */
|
|
43
|
+
export declare const CLAUDE_PROJECTS_SEGMENTS: readonly [".claude", "projects"];
|
|
44
|
+
/** The agents replay reads, by provider id: setup starts a replay when any of them is detected. */
|
|
45
|
+
export declare const REPLAY_AGENTS: ReadonlySet<string>;
|
|
46
|
+
/** Where Codex keeps its rollouts, under `CODEX_HOME`: `sessions/YYYY/MM/DD/rollout-*.jsonl`. */
|
|
47
|
+
export declare const CODEX_SESSIONS_DIR = "sessions";
|
|
48
|
+
export declare const CODEX_ROLLOUT_PREFIX = "rollout-";
|
|
49
|
+
/** The rollout rows replay reads; every other row (messages, reasoning, tool output) is skipped unparsed. */
|
|
50
|
+
export declare const RE_CODEX_REPLAY_ROW: RegExp;
|
|
51
|
+
/** A prompt row, read only when prompt text is allowed. */
|
|
52
|
+
export declare const RE_CODEX_PROMPT_ROW: RegExp;
|
|
53
|
+
/** The row that opens a Codex turn, for the cheap count. */
|
|
54
|
+
export declare const RE_CODEX_TURN_START: RegExp;
|
|
55
|
+
/** Gemini CLI's chat files, under its home: `tmp/<project>/chats/session-*.jsonl`, and the map of project folders. */
|
|
56
|
+
export declare const GEMINI_TMP_DIR = "tmp";
|
|
57
|
+
export declare const GEMINI_CHATS_DIR = "chats";
|
|
58
|
+
export declare const GEMINI_SESSION_PREFIX = "session-";
|
|
59
|
+
export declare const GEMINI_PROJECTS_FILE = "projects.json";
|
|
60
|
+
/** A user message, for the cheap count. */
|
|
61
|
+
export declare const RE_GEMINI_TURN_START: RegExp;
|
|
62
|
+
/** Directory under the identity state dir holding replay state. */
|
|
63
|
+
export declare const REPLAY_STATE_FILE_NAME = "replay.json";
|
|
64
|
+
/** Machine-wide claim that setup has already started or inherited an automatic replay attempt. */
|
|
65
|
+
export declare const REPLAY_ATTEMPTED_FILE_NAME = "replay-attempted";
|
|
66
|
+
/** The provider label replay progress reports; each turn carries its own agent's. */
|
|
67
|
+
export declare const REPLAY_PROVIDER = "claude";
|
|
68
|
+
/** What a real prompt never starts with: Claude Code's own slash-command and interrupt records. */
|
|
69
|
+
export declare const RE_NOT_A_PROMPT: RegExp;
|
|
70
|
+
/** Claude Code names a detached HEAD "HEAD" in `gitBranch`; the hook path reports no branch for it. */
|
|
71
|
+
export declare const DETACHED_BRANCH = "HEAD";
|
|
72
|
+
/** The fields a transcript line is cheaply recognised by before it is parsed. */
|
|
73
|
+
export declare const RE_USER_OR_ASSISTANT_LINE: RegExp;
|
|
74
|
+
/** Prompt id fallback namespace, so a hash never reads as a Claude id. */
|
|
75
|
+
export declare const REPLAY_FALLBACK_TURN_PREFIX = "replay-";
|
|
76
|
+
/** One send's network budget: a batch of twenty turns, to a gateway that budgets eight seconds. */
|
|
77
|
+
export declare const REPLAY_SEND_TIMEOUT_MS = 15000;
|
|
78
|
+
/** A repository's snapshot and tree flows share this; the hooks' own is one second. */
|
|
79
|
+
export declare const REPLAY_SNAPSHOT_BUDGET_MS = 5000;
|
|
80
|
+
/** Failed requests in a row (10 s doubling to 5 min is about ten minutes) before a run gives up until it is resumed. */
|
|
81
|
+
export declare const REPLAY_GIVE_UP_FAILURES = 6;
|
|
82
|
+
/** The sibling file that exists only while a replay is unfinished: the hook's one `stat` to know whether to resume it. */
|
|
83
|
+
export declare const REPLAY_PENDING_FILE_NAME = "replay-pending";
|
|
84
|
+
/** The provider label progress and snapshot records carry; Claude Code's public name. */
|
|
85
|
+
export declare const REPLAY_PROVIDER_LABEL = "claude-code";
|
|
86
|
+
/** A hook starts a stalled replay again at most this often. */
|
|
87
|
+
export declare const REPLAY_RESUME_INTERVAL_MS: number;
|
|
88
|
+
/** A nap is cut into pieces this long, each followed by a heartbeat, so a long wait is not mistaken for a dead run. */
|
|
89
|
+
export declare const REPLAY_HEARTBEAT_MS = 30000;
|
|
90
|
+
/**
|
|
91
|
+
* Node flags a replay runs under. A replay reads megabytes of JSON per second of
|
|
92
|
+
* wall time and keeps almost none of it, so left alone V8 lets the young
|
|
93
|
+
* generation and the heap grow into hundreds of megabytes of garbage (measured:
|
|
94
|
+
* 460 MB peak over 5,400 transcripts, against about 100 MB with these). They
|
|
95
|
+
* cost nothing in speed.
|
|
96
|
+
*/
|
|
97
|
+
export declare const REPLAY_NODE_FLAGS: readonly ["--max-semi-space-size=1", "--max-old-space-size=256"];
|
|
98
|
+
/** Files the identity pre-pass reads between two heartbeats (and looks for a `--stop`). */
|
|
99
|
+
export declare const PREPASS_PERSIST_EVERY = 25;
|