@agent-watch-ai/edge 0.6.0 → 0.7.1
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 +288 -9
- package/README.md +307 -5
- 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 +7 -3
- package/dist/billing/session-billing.js +34 -13
- 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 +503 -0
- package/dist/capture/constants/capture.constants.d.ts +85 -0
- package/dist/capture/constants/capture.constants.js +87 -0
- package/dist/capture/launched-runs.d.ts +43 -0
- package/dist/capture/launched-runs.js +157 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +832 -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/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +23 -6
- package/dist/cli/constants/cli.constants.js +24 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +21 -0
- package/dist/cli/doctor-run-capture.js +33 -0
- package/dist/cli/doctor.js +21 -68
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +82 -1
- 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/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.d.ts +33 -0
- package/dist/cli/replay.js +228 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +200 -31
- 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 +42 -23
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +104 -17
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +10 -1
- 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 +15 -2
- package/dist/config/schemas/config.schema.js +52 -8
- 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 +34 -0
- package/dist/credentials/cloud-claim.js +61 -0
- package/dist/credentials/constants/credentials.constants.d.ts +16 -1
- package/dist/credentials/constants/credentials.constants.js +17 -2
- 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/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- 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/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/enforcement/enforcement.js +1 -1
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +6 -3
- 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-tree.types.d.ts +2 -1
- 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 +33 -11
- package/dist/git/constants/git.constants.js +45 -12
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.js +5 -1
- 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 +53 -9
- package/dist/git/types/snapshot.types.d.ts +6 -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 +82 -57
- package/dist/privacy/product-capture.js +2 -0
- 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 +21 -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 +56 -0
- package/dist/replay/checkout-resolver.js +173 -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 +60 -0
- package/dist/replay/replay-runner.js +581 -0
- package/dist/replay/replay-scan.d.ts +84 -0
- package/dist/replay/replay-scan.js +182 -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 +36 -0
- package/dist/replay/throttle.js +44 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +241 -0
- package/dist/replay/turn-event.d.ts +40 -0
- package/dist/replay/turn-event.js +127 -0
- package/dist/replay/types/replay.types.d.ts +198 -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/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +71 -41
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
- package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
- package/dist/snapshot/constants/snapshot.constants.js +34 -7
- package/dist/snapshot/index.d.ts +2 -2
- package/dist/snapshot/index.js +1 -1
- package/dist/snapshot/snapshot-pipeline.js +100 -26
- package/dist/snapshot/snapshot-state.js +6 -2
- package/dist/snapshot/tree-pipeline.d.ts +1 -1
- package/dist/snapshot/tree-pipeline.js +34 -15
- package/dist/snapshot/types/snapshot.types.d.ts +22 -3
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -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/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 +29 -12
- package/dist/turns/constants/turns.constants.js +31 -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 +82 -7
- package/dist/turns/turn-state.js +157 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +163 -87
- 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 +17 -1
- 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 +201 -13
- package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
- package/docs/PERFORMANCE.md +10 -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
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { SessionTitles } from './types/transcript.types.js';
|
|
2
|
-
import type { AgentProcessRecord, InheritedCheckoutMemo, SessionActivity, TurnRecord, TurnStateEntry, WorkCheckoutMemo } from './types/turn-state.types.js';
|
|
2
|
+
import type { AgentProcessRecord, InheritedCheckoutMemo, SessionActivity, SessionModeRecord, TurnRecord, TurnStateEntry, WorkCheckoutMemo } from './types/turn-state.types.js';
|
|
3
3
|
export type { CheckoutRecord, PromptRecord, ResponseRecord, SessionModelRecord, ToolRecord, TurnRecord, TurnStateEntry } from './types/turn-state.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The well-formed part of a session mode, from the start event's session or
|
|
6
|
+
* the memo read back: what is written and what is read pass the same check.
|
|
7
|
+
*
|
|
8
|
+
* @param value - Anything.
|
|
9
|
+
* @returns The mode, without the fields that are missing or malformed.
|
|
10
|
+
*/
|
|
11
|
+
export declare function toSessionMode(value: unknown): SessionModeRecord;
|
|
4
12
|
/**
|
|
5
13
|
* Per-session accumulator for turn summaries.
|
|
6
14
|
*
|
|
@@ -48,6 +56,53 @@ export declare class TurnStateStore {
|
|
|
48
56
|
* @param files - Paths returned by {@link collectEntries}.
|
|
49
57
|
*/
|
|
50
58
|
remove(files: readonly string[]): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Mark a turn closed, so a call of it that completes later (a background
|
|
61
|
+
* subagent keeps the prompt id that launched it) is known to be late.
|
|
62
|
+
*
|
|
63
|
+
* @param sessionId - Provider session id.
|
|
64
|
+
* @param turnId - The turn that closed.
|
|
65
|
+
*/
|
|
66
|
+
markTurnClosed(sessionId: string, turnId: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Which turns of a session have closed.
|
|
69
|
+
*
|
|
70
|
+
* @param sessionId - Provider session id.
|
|
71
|
+
* @returns A test for a turn id; false for every id when nothing has closed.
|
|
72
|
+
*/
|
|
73
|
+
closedTurns(sessionId: string): Promise<(turnId: string) => boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Note that a turn close was handed to a detached process and has not run yet.
|
|
76
|
+
*
|
|
77
|
+
* Written before the agent is answered: the `SessionEnd` that may follow at
|
|
78
|
+
* once must find it, or it clears the records the close still has to read.
|
|
79
|
+
*
|
|
80
|
+
* @param sessionId - Provider session id.
|
|
81
|
+
* @param payload - The handed-off payload as JSON text; its hash names the marker.
|
|
82
|
+
*/
|
|
83
|
+
markClosing(sessionId: string, payload: string): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Take a handed-off close's marker away, and clear the session when it ended
|
|
86
|
+
* meanwhile and no other close is pending.
|
|
87
|
+
*
|
|
88
|
+
* @param sessionId - Provider session id.
|
|
89
|
+
* @param payload - The payload the marker was written for.
|
|
90
|
+
*/
|
|
91
|
+
finishClosing(sessionId: string, payload: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Take back a `SessionEnd` that left its clear to a pending close: the same
|
|
94
|
+
* session id started again (`--resume`), and a close finishing now must not
|
|
95
|
+
* clear what the resumed session writes.
|
|
96
|
+
*
|
|
97
|
+
* @param sessionId - Provider session id.
|
|
98
|
+
*/
|
|
99
|
+
forgetEnded(sessionId: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* End a session: clear it now, or leave that to a detached close still pending.
|
|
102
|
+
*
|
|
103
|
+
* @param sessionId - Provider session id.
|
|
104
|
+
*/
|
|
105
|
+
endSession(sessionId: string): Promise<void>;
|
|
51
106
|
/**
|
|
52
107
|
* Record which transcript messages a closed turn has counted.
|
|
53
108
|
*
|
|
@@ -107,6 +162,23 @@ export declare class TurnStateStore {
|
|
|
107
162
|
* @returns The model, or undefined when none was usably remembered.
|
|
108
163
|
*/
|
|
109
164
|
readModel(sessionId: string): Promise<string | undefined>;
|
|
165
|
+
/**
|
|
166
|
+
* Remember the mode the session started in, or forget a stale one.
|
|
167
|
+
*
|
|
168
|
+
* Written on the session's start only, and forgotten there when the start
|
|
169
|
+
* names none, for the reason `forgetModel` gives: `--resume` reuses the id.
|
|
170
|
+
*
|
|
171
|
+
* @param sessionId - Provider session id.
|
|
172
|
+
* @param mode - What the start named.
|
|
173
|
+
*/
|
|
174
|
+
rememberMode(sessionId: string, mode: SessionModeRecord): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* The mode the session started in, keeping only well-formed fields.
|
|
177
|
+
*
|
|
178
|
+
* @param sessionId - Provider session id.
|
|
179
|
+
* @returns The mode; empty when none was usably remembered.
|
|
180
|
+
*/
|
|
181
|
+
readMode(sessionId: string): Promise<SessionModeRecord>;
|
|
110
182
|
/**
|
|
111
183
|
* The names of a session's files, and nothing read: how a tool hook learns
|
|
112
184
|
* which checkouts its turn already named, for the price of one `readdir`.
|
|
@@ -260,14 +332,16 @@ export declare class TurnStateStore {
|
|
|
260
332
|
*/
|
|
261
333
|
readPromptTickets(sessionId: string): Promise<readonly string[]>;
|
|
262
334
|
/**
|
|
263
|
-
* Drop a session's state at SessionEnd, all but
|
|
335
|
+
* Drop a session's state at SessionEnd, all but what a resume needs: the
|
|
336
|
+
* opening prompt's keys and the session mode (`SESSION_RESUME_FILES`).
|
|
264
337
|
*
|
|
265
338
|
* `--resume` reuses the session id, and without the memo the resumed
|
|
266
339
|
* session's first prompt ("continue") would become its opening prompt and
|
|
267
|
-
* claim it with no keys.
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
340
|
+
* claim it with no keys. Cursor names its mode on sessionStart only, so a
|
|
341
|
+
* conversation continued without a new start still needs it. Neither holds
|
|
342
|
+
* prompt text, and the expiry sweep removes them with the directory once they
|
|
343
|
+
* age out — counted from SessionEnd, not from the opening prompt, so a session
|
|
344
|
+
* that ran all day can still be resumed the next morning.
|
|
271
345
|
*
|
|
272
346
|
* @param sessionId - Provider session id.
|
|
273
347
|
*/
|
|
@@ -302,6 +376,7 @@ export declare class TurnStateStore {
|
|
|
302
376
|
*/
|
|
303
377
|
private pruneAgentPids;
|
|
304
378
|
private pidFile;
|
|
379
|
+
private closingFile;
|
|
305
380
|
/**
|
|
306
381
|
* Directory holding one session's state.
|
|
307
382
|
*
|
|
@@ -311,5 +386,5 @@ export declare class TurnStateStore {
|
|
|
311
386
|
* @param sessionId - Provider session id.
|
|
312
387
|
* @returns Absolute directory path.
|
|
313
388
|
*/
|
|
314
|
-
|
|
389
|
+
sessionDir(sessionId: string): string;
|
|
315
390
|
}
|
package/dist/turns/turn-state.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { asRecord, compact } from '../core/object.js';
|
|
3
|
+
import { asRecord, compact, firstStringOf } from '../core/object.js';
|
|
4
4
|
import { sha256Hex } from '../events/event-id.js';
|
|
5
5
|
import { MAX_TICKET_KEYS } from '../feature/constants/feature.constants.js';
|
|
6
6
|
import { writeFileAtomic } from '../storage/atomic-file.js';
|
|
7
7
|
import { readJsonFile } from '../storage/json-file.js';
|
|
8
8
|
import { SECRET_FILE_MODE, SWEEP_MARKER_FILE } from '../storage/constants/storage.constants.js';
|
|
9
9
|
import { claimSweep } from '../storage/sweep-marker.js';
|
|
10
|
-
import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_FILES, SESSION_MODEL_FILE, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_RECORD_KINDS, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
|
|
10
|
+
import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, CLOSED_TURN_PREFIX, CLOSING_TURN_PREFIX, DETACHED_CLOSE_MAX_AGE_MS, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_ENDED_FILE, SESSION_FILES, SESSION_MODEL_FILE, SESSION_MODE_FILE, SESSION_RESUME_FILES, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_RECORD_KINDS, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
|
|
11
|
+
/**
|
|
12
|
+
* The well-formed part of a session mode, from the start event's session or
|
|
13
|
+
* the memo read back: what is written and what is read pass the same check.
|
|
14
|
+
*
|
|
15
|
+
* @param value - Anything.
|
|
16
|
+
* @returns The mode, without the fields that are missing or malformed.
|
|
17
|
+
*/
|
|
18
|
+
export function toSessionMode(value) {
|
|
19
|
+
const record = asRecord(value);
|
|
20
|
+
const isCloudAgent = record?.['isCloudAgent'];
|
|
21
|
+
return compact({
|
|
22
|
+
mode: firstStringOf(record?.['mode']),
|
|
23
|
+
isCloudAgent: typeof isCloudAgent === 'boolean' ? isCloudAgent : undefined
|
|
24
|
+
});
|
|
25
|
+
}
|
|
11
26
|
/**
|
|
12
27
|
* Per-session accumulator for turn summaries.
|
|
13
28
|
*
|
|
@@ -68,6 +83,80 @@ export class TurnStateStore {
|
|
|
68
83
|
async remove(files) {
|
|
69
84
|
await Promise.all(files.map((file) => fs.rm(file, { force: true })));
|
|
70
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Mark a turn closed, so a call of it that completes later (a background
|
|
88
|
+
* subagent keeps the prompt id that launched it) is known to be late.
|
|
89
|
+
*
|
|
90
|
+
* @param sessionId - Provider session id.
|
|
91
|
+
* @param turnId - The turn that closed.
|
|
92
|
+
*/
|
|
93
|
+
async markTurnClosed(sessionId, turnId) {
|
|
94
|
+
await writeFileAtomic(path.join(this.sessionDir(sessionId), `${CLOSED_TURN_PREFIX}${safeName(turnId)}`), '', SECRET_FILE_MODE);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Which turns of a session have closed.
|
|
98
|
+
*
|
|
99
|
+
* @param sessionId - Provider session id.
|
|
100
|
+
* @returns A test for a turn id; false for every id when nothing has closed.
|
|
101
|
+
*/
|
|
102
|
+
async closedTurns(sessionId) {
|
|
103
|
+
const names = new Set(await readSessionDirSafely(this.sessionDir(sessionId)));
|
|
104
|
+
return (turnId) => names.has(`${CLOSED_TURN_PREFIX}${safeName(turnId)}`);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Note that a turn close was handed to a detached process and has not run yet.
|
|
108
|
+
*
|
|
109
|
+
* Written before the agent is answered: the `SessionEnd` that may follow at
|
|
110
|
+
* once must find it, or it clears the records the close still has to read.
|
|
111
|
+
*
|
|
112
|
+
* @param sessionId - Provider session id.
|
|
113
|
+
* @param payload - The handed-off payload as JSON text; its hash names the marker.
|
|
114
|
+
*/
|
|
115
|
+
async markClosing(sessionId, payload) {
|
|
116
|
+
// Empty, so it cannot be half written: no temp file and no fsync on the Stop the agent waits for.
|
|
117
|
+
await fs.mkdir(this.sessionDir(sessionId), { recursive: true });
|
|
118
|
+
await fs.writeFile(this.closingFile(sessionId, payload), '', { mode: SECRET_FILE_MODE });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Take a handed-off close's marker away, and clear the session when it ended
|
|
122
|
+
* meanwhile and no other close is pending.
|
|
123
|
+
*
|
|
124
|
+
* @param sessionId - Provider session id.
|
|
125
|
+
* @param payload - The payload the marker was written for.
|
|
126
|
+
*/
|
|
127
|
+
async finishClosing(sessionId, payload) {
|
|
128
|
+
await fs.rm(this.closingFile(sessionId, payload), { force: true });
|
|
129
|
+
const names = await freshMarkers(this.sessionDir(sessionId));
|
|
130
|
+
if (names.includes(SESSION_ENDED_FILE) && !names.some(isClosingMarker))
|
|
131
|
+
await this.clear(sessionId);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Take back a `SessionEnd` that left its clear to a pending close: the same
|
|
135
|
+
* session id started again (`--resume`), and a close finishing now must not
|
|
136
|
+
* clear what the resumed session writes.
|
|
137
|
+
*
|
|
138
|
+
* @param sessionId - Provider session id.
|
|
139
|
+
*/
|
|
140
|
+
async forgetEnded(sessionId) {
|
|
141
|
+
await fs.rm(path.join(this.sessionDir(sessionId), SESSION_ENDED_FILE), { force: true });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* End a session: clear it now, or leave that to a detached close still pending.
|
|
145
|
+
*
|
|
146
|
+
* @param sessionId - Provider session id.
|
|
147
|
+
*/
|
|
148
|
+
async endSession(sessionId) {
|
|
149
|
+
const dir = this.sessionDir(sessionId);
|
|
150
|
+
if ((await freshMarkers(dir)).some(isClosingMarker)) {
|
|
151
|
+
// A close that cleared the whole folder meanwhile leaves nothing to mark: clear below.
|
|
152
|
+
const marked = await fs.writeFile(path.join(dir, SESSION_ENDED_FILE), '', { mode: SECRET_FILE_MODE }).then(() => true, () => false);
|
|
153
|
+
// Looked at again after the mark: a close that finished in between did
|
|
154
|
+
// not see it, and would leave the session to the expiry sweep.
|
|
155
|
+
if (marked && (await freshMarkers(dir)).some(isClosingMarker))
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
await this.clear(sessionId);
|
|
159
|
+
}
|
|
71
160
|
/**
|
|
72
161
|
* Record which transcript messages a closed turn has counted.
|
|
73
162
|
*
|
|
@@ -164,6 +253,33 @@ export class TurnStateStore {
|
|
|
164
253
|
return undefined;
|
|
165
254
|
return model;
|
|
166
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Remember the mode the session started in, or forget a stale one.
|
|
258
|
+
*
|
|
259
|
+
* Written on the session's start only, and forgotten there when the start
|
|
260
|
+
* names none, for the reason `forgetModel` gives: `--resume` reuses the id.
|
|
261
|
+
*
|
|
262
|
+
* @param sessionId - Provider session id.
|
|
263
|
+
* @param mode - What the start named.
|
|
264
|
+
*/
|
|
265
|
+
async rememberMode(sessionId, mode) {
|
|
266
|
+
const file = path.join(this.sessionDir(sessionId), SESSION_MODE_FILE);
|
|
267
|
+
if (Object.keys(mode).length === 0) {
|
|
268
|
+
await fs.rm(file, { force: true });
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
await writeFileAtomic(file, JSON.stringify(mode), SECRET_FILE_MODE);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The mode the session started in, keeping only well-formed fields.
|
|
275
|
+
*
|
|
276
|
+
* @param sessionId - Provider session id.
|
|
277
|
+
* @returns The mode; empty when none was usably remembered.
|
|
278
|
+
*/
|
|
279
|
+
async readMode(sessionId) {
|
|
280
|
+
const read = await readJsonFile(path.join(this.sessionDir(sessionId), SESSION_MODE_FILE));
|
|
281
|
+
return read.state === 'ok' ? toSessionMode(read.value) : {};
|
|
282
|
+
}
|
|
167
283
|
/**
|
|
168
284
|
* The names of a session's files, and nothing read: how a tool hook learns
|
|
169
285
|
* which checkouts its turn already named, for the price of one `readdir`.
|
|
@@ -386,14 +502,16 @@ export class TurnStateStore {
|
|
|
386
502
|
return keys.filter((key) => typeof key === 'string').slice(0, MAX_TICKET_KEYS);
|
|
387
503
|
}
|
|
388
504
|
/**
|
|
389
|
-
* Drop a session's state at SessionEnd, all but
|
|
505
|
+
* Drop a session's state at SessionEnd, all but what a resume needs: the
|
|
506
|
+
* opening prompt's keys and the session mode (`SESSION_RESUME_FILES`).
|
|
390
507
|
*
|
|
391
508
|
* `--resume` reuses the session id, and without the memo the resumed
|
|
392
509
|
* session's first prompt ("continue") would become its opening prompt and
|
|
393
|
-
* claim it with no keys.
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
510
|
+
* claim it with no keys. Cursor names its mode on sessionStart only, so a
|
|
511
|
+
* conversation continued without a new start still needs it. Neither holds
|
|
512
|
+
* prompt text, and the expiry sweep removes them with the directory once they
|
|
513
|
+
* age out — counted from SessionEnd, not from the opening prompt, so a session
|
|
514
|
+
* that ran all day can still be resumed the next morning.
|
|
397
515
|
*
|
|
398
516
|
* @param sessionId - Provider session id.
|
|
399
517
|
*/
|
|
@@ -405,13 +523,17 @@ export class TurnStateStore {
|
|
|
405
523
|
await fs.rm(this.pidFile(pid), { force: true });
|
|
406
524
|
const dir = this.sessionDir(sessionId);
|
|
407
525
|
const names = await readSessionDir(dir);
|
|
408
|
-
|
|
526
|
+
const kept = [];
|
|
527
|
+
const dropped = [];
|
|
528
|
+
for (const name of names ?? [])
|
|
529
|
+
(SESSION_RESUME_FILES.has(name) ? kept : dropped).push(name);
|
|
530
|
+
if (kept.length === 0) {
|
|
409
531
|
await fs.rm(dir, { recursive: true, force: true });
|
|
410
532
|
return;
|
|
411
533
|
}
|
|
412
|
-
await Promise.all(
|
|
534
|
+
await Promise.all(dropped.map((name) => fs.rm(path.join(dir, name), { recursive: true, force: true })));
|
|
413
535
|
const now = new Date();
|
|
414
|
-
await fs.utimes(path.join(dir,
|
|
536
|
+
await Promise.all(kept.map((name) => fs.utimes(path.join(dir, name), now, now).catch(() => undefined)));
|
|
415
537
|
}
|
|
416
538
|
/**
|
|
417
539
|
* Remove sessions whose newest record is older than `maxAgeMs`.
|
|
@@ -470,6 +592,9 @@ export class TurnStateStore {
|
|
|
470
592
|
pidFile(pid) {
|
|
471
593
|
return path.join(this.turnsDir, AGENT_PIDS_DIR, `${Math.trunc(pid)}.json`);
|
|
472
594
|
}
|
|
595
|
+
closingFile(sessionId, payload) {
|
|
596
|
+
return path.join(this.sessionDir(sessionId), `${CLOSING_TURN_PREFIX}${sha256Hex(payload).slice(0, SESSION_DIR_HASH_LENGTH)}`);
|
|
597
|
+
}
|
|
473
598
|
/**
|
|
474
599
|
* Directory holding one session's state.
|
|
475
600
|
*
|
|
@@ -646,6 +771,28 @@ async function newestMtime(dir, ignored = new Set()) {
|
|
|
646
771
|
}
|
|
647
772
|
return newest;
|
|
648
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
* The pending-close and session-ended markers of a session written within
|
|
776
|
+
* {@link DETACHED_CLOSE_MAX_AGE_MS}: an older one belongs to a close that died.
|
|
777
|
+
*
|
|
778
|
+
* @param dir - Session directory.
|
|
779
|
+
* @returns The fresh markers' names.
|
|
780
|
+
*/
|
|
781
|
+
async function freshMarkers(dir) {
|
|
782
|
+
const cutoff = Date.now() - DETACHED_CLOSE_MAX_AGE_MS;
|
|
783
|
+
const fresh = [];
|
|
784
|
+
for (const name of await readSessionDirSafely(dir)) {
|
|
785
|
+
if (name !== SESSION_ENDED_FILE && !isClosingMarker(name))
|
|
786
|
+
continue;
|
|
787
|
+
const stat = await fs.stat(path.join(dir, name)).catch(() => undefined);
|
|
788
|
+
if (stat && stat.mtimeMs > cutoff)
|
|
789
|
+
fresh.push(name);
|
|
790
|
+
}
|
|
791
|
+
return fresh;
|
|
792
|
+
}
|
|
793
|
+
function isClosingMarker(name) {
|
|
794
|
+
return name.startsWith(CLOSING_TURN_PREFIX);
|
|
795
|
+
}
|
|
649
796
|
/**
|
|
650
797
|
* Filesystem-safe form of an untrusted record id.
|
|
651
798
|
*
|
|
@@ -3,7 +3,8 @@ import { FAIL_OPEN_REASONS } from '../enforcement/constants/enforcement.constant
|
|
|
3
3
|
import { deriveEventId, sha256Hex } from '../events/event-id.js';
|
|
4
4
|
import { EVENT_SCHEMA_VERSION } from '../events/constants/events.constants.js';
|
|
5
5
|
import { sanitizeText } from '../privacy/sanitizer.js';
|
|
6
|
-
import {
|
|
6
|
+
import { CANONICAL_PROVIDER_NAMES } from '../otlp/constants/otlp.constants.js';
|
|
7
|
+
import { MAX_SESSION_TITLE_LENGTH, MAX_TURN_FILES, MAX_TURN_TOOL_INPUTS, UNKNOWN_TOOL_NAME } from './constants/turns.constants.js';
|
|
7
8
|
/**
|
|
8
9
|
* Flatten one turn's accumulated state into the single product record the hook
|
|
9
10
|
* path emits.
|
|
@@ -20,7 +21,7 @@ export function buildTurnSummary(input) {
|
|
|
20
21
|
const startedAt = input.prompts[0]?.at;
|
|
21
22
|
const turnId = input.turnId ?? input.prompts.find((prompt) => prompt.turnId)?.turnId;
|
|
22
23
|
const jiraIds = ticketValues(input.featureCandidates);
|
|
23
|
-
const provider =
|
|
24
|
+
const provider = CANONICAL_PROVIDER_NAMES[input.provider] ?? input.provider;
|
|
24
25
|
return compact({
|
|
25
26
|
schemaVersion: EVENT_SCHEMA_VERSION,
|
|
26
27
|
id: deriveEventId({
|
|
@@ -42,6 +43,9 @@ export function buildTurnSummary(input) {
|
|
|
42
43
|
turn_id: turnId,
|
|
43
44
|
developer_id: input.developerId,
|
|
44
45
|
developer_name: input.developerName,
|
|
46
|
+
account_email: input.accountEmail,
|
|
47
|
+
session_mode: input.sessionMode?.mode,
|
|
48
|
+
is_cloud_agent: input.sessionMode?.isCloudAgent,
|
|
45
49
|
repository: input.git?.repository,
|
|
46
50
|
branch: input.git?.branch,
|
|
47
51
|
commit: input.git?.commit,
|
|
@@ -64,6 +68,7 @@ export function buildTurnSummary(input) {
|
|
|
64
68
|
tool_calls: input.tools.length,
|
|
65
69
|
tools_used: files.toolsUsed,
|
|
66
70
|
tool_events: input.toolEvents?.length ? input.toolEvents : undefined,
|
|
71
|
+
command: input.command,
|
|
67
72
|
model: input.usage?.model ?? input.model,
|
|
68
73
|
// 'unknown' is the absence of a verdict, not a billing mode.
|
|
69
74
|
billing_mode: input.billingMode && input.billingMode !== 'unknown' ? input.billingMode : undefined,
|
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import type { Env } from '../core/types/core.types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TurnProvider } from './types/turn-provider.types.js';
|
|
3
3
|
import type { TrackTurnOptions, TurnOutcome } from './types/turn-tracker.types.js';
|
|
4
4
|
export type { TrackTurnOptions, TurnOutcome } from './types/turn-tracker.types.js';
|
|
5
5
|
/**
|
|
6
6
|
* Accumulate turn state across hook invocations and close the turn on
|
|
7
|
-
* `generation.completed`, producing one flat summary
|
|
7
|
+
* `generation.completed`, producing one flat summary, with the local root of
|
|
8
|
+
* the checkout the summary reported beside it: the pipeline takes the
|
|
9
|
+
* repository snapshot there. The root never goes on the summary.
|
|
8
10
|
*
|
|
9
11
|
* Best-effort by design: hooks run inside the coding agent, so every failure
|
|
10
12
|
* path here ends in "no summary" or a degraded one, never in a thrown error.
|
|
11
13
|
*
|
|
12
14
|
* @param options - The payload's events, config, paths and clock.
|
|
13
|
-
* @returns The turn summary when this payload closed a turn.
|
|
14
|
-
*/
|
|
15
|
-
export declare function trackTurn(options: TrackTurnOptions): Promise<TurnSummaryEvent | undefined>;
|
|
16
|
-
/**
|
|
17
|
-
* {@link trackTurn}, with the local root of the checkout the summary reported
|
|
18
|
-
* beside it: the pipeline takes the repository snapshot there. The root never
|
|
19
|
-
* goes on the summary.
|
|
20
|
-
*
|
|
21
|
-
* @param options - The payload's events, config, paths and clock.
|
|
22
15
|
* @returns The summary when this payload closed a turn, and its checkout's root.
|
|
23
16
|
*/
|
|
24
17
|
export declare function trackTurnOutcome(options: TrackTurnOptions): Promise<TurnOutcome>;
|
|
25
18
|
/**
|
|
26
|
-
* Which surface the turn happened on.
|
|
19
|
+
* Which surface the turn happened on, as the agent says, else the default.
|
|
27
20
|
*
|
|
28
|
-
* @param provider -
|
|
29
|
-
* @param env -
|
|
30
|
-
* @param rawPayload - Hook payload
|
|
21
|
+
* @param provider - The agent the hook came from.
|
|
22
|
+
* @param env - The hook's environment.
|
|
23
|
+
* @param rawPayload - Hook payload.
|
|
31
24
|
* @returns The surface label.
|
|
32
25
|
*/
|
|
33
|
-
export declare function resolveSurface(provider:
|
|
26
|
+
export declare function resolveSurface(provider: TurnProvider, env: Env, rawPayload: unknown): Promise<string>;
|