@agent-watch-ai/edge 0.7.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 +69 -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/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 +21 -0
- 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 +47 -6
- package/dist/cli/uninstall.js +34 -1
- package/dist/cli/update.js +3 -2
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +8 -1
- package/dist/config/schemas/config.schema.d.ts +2 -2
- package/dist/config/schemas/config.schema.js +10 -2
- 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 +2 -1
- package/dist/providers/claude/claude.provider.js +9 -5
- 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/constants/turns.constants.d.ts +16 -0
- package/dist/turns/constants/turns.constants.js +16 -0
- package/dist/turns/turn-state.d.ts +33 -0
- package/dist/turns/turn-state.js +80 -1
- package/dist/turns/turn-tracker.js +2 -2
- package/docs/DATA_HANDLING.md +8 -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 {
|
|
@@ -39,6 +39,22 @@ export declare const TRANSCRIPT_TAIL_BYTES: number;
|
|
|
39
39
|
export declare const TRANSCRIPT_PATH_KEY = "transcript_path";
|
|
40
40
|
/** Marker of a closed turn; no `.json`, so it is never read as a record (AWT-701). */
|
|
41
41
|
export declare const CLOSED_TURN_PREFIX = "closed-turn--";
|
|
42
|
+
/**
|
|
43
|
+
* Marker of a turn close handed to a detached process and not finished yet:
|
|
44
|
+
* `closing--<payload hash>`, no `.json`. Written by the hook that hands the
|
|
45
|
+
* close off, before the agent is answered, so a `SessionEnd` that follows at
|
|
46
|
+
* once (`/exit`, `/clear` in a terminal session) sees it and leaves the state to the close.
|
|
47
|
+
*/
|
|
48
|
+
export declare const CLOSING_TURN_PREFIX = "closing--";
|
|
49
|
+
/** Marker that `SessionEnd` came while a close was pending; the last close clears the session. No `.json`. */
|
|
50
|
+
export declare const SESSION_ENDED_FILE = "session-ended";
|
|
51
|
+
/**
|
|
52
|
+
* How long a pending-close or session-ended marker counts. A detached close
|
|
53
|
+
* does the work an in-place Stop did within Claude's 30 s hook timeout, about a
|
|
54
|
+
* second typically; a marker older than this belongs to a close that died, and
|
|
55
|
+
* must not keep the state from clearing.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DETACHED_CLOSE_MAX_AGE_MS = 60000;
|
|
42
58
|
/** Prefix distinguishing usage-claim files from turn records in a session dir. */
|
|
43
59
|
export declare const USAGE_CLAIM_PREFIX = "usage-claim--";
|
|
44
60
|
/**
|
|
@@ -45,6 +45,22 @@ export const TRANSCRIPT_TAIL_BYTES = 4 * 1024 * 1024;
|
|
|
45
45
|
export const TRANSCRIPT_PATH_KEY = 'transcript_path';
|
|
46
46
|
/** Marker of a closed turn; no `.json`, so it is never read as a record (AWT-701). */
|
|
47
47
|
export const CLOSED_TURN_PREFIX = 'closed-turn--';
|
|
48
|
+
/**
|
|
49
|
+
* Marker of a turn close handed to a detached process and not finished yet:
|
|
50
|
+
* `closing--<payload hash>`, no `.json`. Written by the hook that hands the
|
|
51
|
+
* close off, before the agent is answered, so a `SessionEnd` that follows at
|
|
52
|
+
* once (`/exit`, `/clear` in a terminal session) sees it and leaves the state to the close.
|
|
53
|
+
*/
|
|
54
|
+
export const CLOSING_TURN_PREFIX = 'closing--';
|
|
55
|
+
/** Marker that `SessionEnd` came while a close was pending; the last close clears the session. No `.json`. */
|
|
56
|
+
export const SESSION_ENDED_FILE = 'session-ended';
|
|
57
|
+
/**
|
|
58
|
+
* How long a pending-close or session-ended marker counts. A detached close
|
|
59
|
+
* does the work an in-place Stop did within Claude's 30 s hook timeout, about a
|
|
60
|
+
* second typically; a marker older than this belongs to a close that died, and
|
|
61
|
+
* must not keep the state from clearing.
|
|
62
|
+
*/
|
|
63
|
+
export const DETACHED_CLOSE_MAX_AGE_MS = 60_000;
|
|
48
64
|
/** Prefix distinguishing usage-claim files from turn records in a session dir. */
|
|
49
65
|
export const USAGE_CLAIM_PREFIX = 'usage-claim--';
|
|
50
66
|
/**
|
|
@@ -71,6 +71,38 @@ export declare class TurnStateStore {
|
|
|
71
71
|
* @returns A test for a turn id; false for every id when nothing has closed.
|
|
72
72
|
*/
|
|
73
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>;
|
|
74
106
|
/**
|
|
75
107
|
* Record which transcript messages a closed turn has counted.
|
|
76
108
|
*
|
|
@@ -344,6 +376,7 @@ export declare class TurnStateStore {
|
|
|
344
376
|
*/
|
|
345
377
|
private pruneAgentPids;
|
|
346
378
|
private pidFile;
|
|
379
|
+
private closingFile;
|
|
347
380
|
/**
|
|
348
381
|
* Directory holding one session's state.
|
|
349
382
|
*
|
package/dist/turns/turn-state.js
CHANGED
|
@@ -7,7 +7,7 @@ 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, CLOSED_TURN_PREFIX, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, 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';
|
|
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
11
|
/**
|
|
12
12
|
* The well-formed part of a session mode, from the start event's session or
|
|
13
13
|
* the memo read back: what is written and what is read pass the same check.
|
|
@@ -103,6 +103,60 @@ export class TurnStateStore {
|
|
|
103
103
|
const names = new Set(await readSessionDirSafely(this.sessionDir(sessionId)));
|
|
104
104
|
return (turnId) => names.has(`${CLOSED_TURN_PREFIX}${safeName(turnId)}`);
|
|
105
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
|
+
}
|
|
106
160
|
/**
|
|
107
161
|
* Record which transcript messages a closed turn has counted.
|
|
108
162
|
*
|
|
@@ -538,6 +592,9 @@ export class TurnStateStore {
|
|
|
538
592
|
pidFile(pid) {
|
|
539
593
|
return path.join(this.turnsDir, AGENT_PIDS_DIR, `${Math.trunc(pid)}.json`);
|
|
540
594
|
}
|
|
595
|
+
closingFile(sessionId, payload) {
|
|
596
|
+
return path.join(this.sessionDir(sessionId), `${CLOSING_TURN_PREFIX}${sha256Hex(payload).slice(0, SESSION_DIR_HASH_LENGTH)}`);
|
|
597
|
+
}
|
|
541
598
|
/**
|
|
542
599
|
* Directory holding one session's state.
|
|
543
600
|
*
|
|
@@ -714,6 +771,28 @@ async function newestMtime(dir, ignored = new Set()) {
|
|
|
714
771
|
}
|
|
715
772
|
return newest;
|
|
716
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
|
+
}
|
|
717
796
|
/**
|
|
718
797
|
* Filesystem-safe form of an untrusted record id.
|
|
719
798
|
*
|
|
@@ -81,7 +81,7 @@ async function processEvent(store, sessionId, event, options) {
|
|
|
81
81
|
// `generation.completed` would degrade the turn to a fallback summary, and one
|
|
82
82
|
// on `session.ended` would leave a session's raw prompt text undeleted.
|
|
83
83
|
if (type === 'session.started')
|
|
84
|
-
await Promise.all([rememberModelSafely(store, sessionId, event), rememberModeSafely(store, sessionId, event, options.provider)]);
|
|
84
|
+
await Promise.all([rememberModelSafely(store, sessionId, event), rememberModeSafely(store, sessionId, event, options.provider), store.forgetEnded(sessionId).catch(() => undefined)]);
|
|
85
85
|
// The first hook walks; a later one walks again only when the deadline cut
|
|
86
86
|
// the last walk, so a busy first hook does not cost the whole session. Not
|
|
87
87
|
// at the session's end, which clears the answer straight after.
|
|
@@ -102,7 +102,7 @@ async function processEvent(store, sessionId, event, options) {
|
|
|
102
102
|
return outcome;
|
|
103
103
|
}
|
|
104
104
|
if (type === 'session.ended') {
|
|
105
|
-
await store.
|
|
105
|
+
await store.endSession(sessionId);
|
|
106
106
|
await store.sweep(TURN_STATE_TTL_MS);
|
|
107
107
|
}
|
|
108
108
|
return undefined;
|