@bastani/atomic 0.9.83 → 0.9.84
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 +40 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/cli/storage-command.d.ts +12 -1
- package/dist/cli/storage-command.d.ts.map +1 -1
- package/dist/cli/storage-command.js +210 -47
- package/dist/cli/storage-command.js.map +1 -1
- package/dist/core/session-transfer.d.ts +84 -0
- package/dist/core/session-transfer.d.ts.map +1 -0
- package/dist/core/session-transfer.js +270 -0
- package/dist/core/session-transfer.js.map +1 -0
- package/dist/core/storage/journal-transfer.d.ts +74 -35
- package/dist/core/storage/journal-transfer.d.ts.map +1 -1
- package/dist/core/storage/journal-transfer.js +384 -278
- package/dist/core/storage/journal-transfer.js.map +1 -1
- package/dist/core/storage/transfer-files.d.ts +75 -0
- package/dist/core/storage/transfer-files.d.ts.map +1 -0
- package/dist/core/storage/transfer-files.js +170 -0
- package/dist/core/storage/transfer-files.js.map +1 -0
- package/dist/core/storage-transfer.d.ts +30 -0
- package/dist/core/storage-transfer.d.ts.map +1 -0
- package/dist/core/storage-transfer.js +49 -0
- package/dist/core/storage-transfer.js.map +1 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +21 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +1 -0
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/docs/reference/cli.md +31 -3
- package/docs/storage.md +81 -17
- package/npm-shrinkwrap.json +38 -38
- package/package.json +3 -3
|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A0B,KAAe,CAAC,OAAO,EAAE;gBAC3D,KAAK,EAAE,KAA4B;aACnC,CAAC,CAAC;QACJ,CAAC;QACD,IAAI,IAAY,CAAC;QACjB,IAAI,CAAC;YACJ,IAAI,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,oBAAoB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;YAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["/**\n * The files `atomic storage export` writes and `atomic storage import` reads (#4716, #4720): one JSONL file per session\n * or workflow run, in its own subdirectory of the export directory. Each file is written whole through a temporary\n * file, and one that already holds the same bytes is left untouched.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { open, readdir, readFile, rename, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { withCleanup } from \"./cleanup.js\";\nimport { StorageError, type StorageFailureCause } from \"./errors.js\";\n\n/** The file name extension of an exported session or run; import reads every file with it and ignores the rest. */\nexport const TRANSFER_FILE_EXTENSION = \".jsonl\";\n/** The subdirectory of an export directory that holds sessions. */\nexport const SESSIONS_TRANSFER_DIRECTORY = \"sessions\";\n/** The subdirectory of an export directory that holds workflow runs. */\nexport const WORKFLOWS_TRANSFER_DIRECTORY = \"workflows\";\n\nexport interface StorageTransferErrorInit {\n\t/** The file or storage location the error is about. */\n\treadonly path: string;\n\t/** The 1-based line of `path`. */\n\treadonly line?: number;\n\t/** The session or run the error is about. */\n\treadonly id?: string;\n\treadonly reason: string;\n\treadonly cause?: StorageFailureCause;\n}\n\n/** An export or import that could not be done; an import that fails this way wrote nothing. */\nexport class StorageTransferError extends StorageError {\n\toverride readonly name = \"StorageTransferError\" as const;\n\treadonly path: string;\n\treadonly line: number | undefined;\n\treadonly id: string | undefined;\n\treadonly reason: string;\n\n\tconstructor(init: StorageTransferErrorInit) {\n\t\tsuper(`${init.path}${init.line === undefined ? \"\" : `:${init.line}`}: ${init.reason}`, { cause: init.cause });\n\t\tthis.path = init.path;\n\t\tthis.line = init.line;\n\t\tthis.id = init.id;\n\t\tthis.reason = init.reason;\n\t}\n}\n\n/** The sessions and workflow runs an import wrote, or did not write. */\nexport interface TransferredIds {\n\treadonly sessions: readonly string[];\n\treadonly workflows: readonly string[];\n}\n\n/**\n * An import that failed after it wrote some sessions or runs: `written` names exactly what it wrote, and `notWritten`\n * what it did not. Importing the same files again writes only what is missing.\n */\nexport class StorageImportIncompleteError extends StorageError {\n\toverride readonly name = \"StorageImportIncompleteError\" as const;\n\treadonly written: TransferredIds;\n\treadonly notWritten: TransferredIds;\n\n\tconstructor(cause: Error, outcome: { readonly written: TransferredIds; readonly notWritten: TransferredIds }) {\n\t\tsuper(cause.message, { cause });\n\t\tthis.written = outcome.written;\n\t\tthis.notWritten = outcome.notWritten;\n\t}\n}\n\nexport function isStorageImportIncompleteError(value: unknown): value is StorageImportIncompleteError {\n\tif (value instanceof StorageImportIncompleteError) return true;\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t(value as { name?: unknown }).name === \"StorageImportIncompleteError\"\n\t);\n}\n\nexport function isStorageTransferError(value: unknown): value is StorageTransferError {\n\tif (value instanceof StorageTransferError) return true;\n\treturn typeof value === \"object\" && value !== null && (value as { name?: unknown }).name === \"StorageTransferError\";\n}\n\n/** The file a session or run with `id` is exported to in `directory`. */\nexport function transferFile(directory: string, id: string): string {\n\treturn join(directory, `${encodeURIComponent(id)}${TRANSFER_FILE_EXTENSION}`);\n}\n\nasync function sameBytes(left: string, right: string): Promise<boolean> {\n\tconst [a, b] = await Promise.all([open(left, \"r\"), open(right, \"r\").catch(() => undefined)]);\n\tif (b === undefined) {\n\t\tawait a.close();\n\t\treturn false;\n\t}\n\treturn withCleanup(\n\t\tasync () => {\n\t\t\tconst [sizeA, sizeB] = await Promise.all([a.stat(), b.stat()]);\n\t\t\tif (sizeA.size !== sizeB.size) return false;\n\t\t\tconst chunkA = Buffer.alloc(64 * 1024);\n\t\t\tconst chunkB = Buffer.alloc(64 * 1024);\n\t\t\tfor (let offset = 0; offset < sizeA.size; ) {\n\t\t\t\tconst [readA, readB] = await Promise.all([\n\t\t\t\t\ta.read(chunkA, 0, chunkA.length, offset),\n\t\t\t\t\tb.read(chunkB, 0, chunkB.length, offset),\n\t\t\t\t]);\n\t\t\t\tif (readA.bytesRead === 0 || readA.bytesRead !== readB.bytesRead) return false;\n\t\t\t\tif (!chunkA.subarray(0, readA.bytesRead).equals(chunkB.subarray(0, readB.bytesRead))) return false;\n\t\t\t\toffset += readA.bytesRead;\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t\tasync () => {\n\t\t\tawait Promise.allSettled([a.close(), b.close()]);\n\t\t},\n\t);\n}\n\n/**\n * Writes `lines`, each followed by a newline, to `file` through an owner-only temporary file in the same directory\n * that is flushed and then renamed over it, so `file` holds either its earlier content or all of the new content. The\n * lines are written as they come, so a large session is never held as one string. A file that already holds exactly\n * these bytes is left alone.\n */\nexport async function writeLinesAtomically(\n\tfile: string,\n\tlines: Iterable<string> | AsyncIterable<string>,\n): Promise<\"written\" | \"unchanged\"> {\n\tconst temporary = join(file, \"..\", `.${randomUUID()}.tmp`);\n\ttry {\n\t\tconst handle = await open(temporary, \"wx\", 0o600);\n\t\tawait withCleanup(\n\t\t\tasync () => {\n\t\t\t\tfor await (const line of lines) await handle.write(`${line}\\n`, null, \"utf8\");\n\t\t\t\tawait handle.sync();\n\t\t\t},\n\t\t\t() => handle.close(),\n\t\t);\n\t\tif (await sameBytes(temporary, file)) {\n\t\t\tawait rm(temporary, { force: true });\n\t\t\treturn \"unchanged\";\n\t\t}\n\t\tawait rename(temporary, file);\n\t} catch (error) {\n\t\tawait rm(temporary, { force: true }).catch(() => undefined);\n\t\tif (isStorageTransferError(error)) throw error;\n\t\tthrow new StorageTransferError({\n\t\t\tpath: file,\n\t\t\treason: `cannot write the export file: ${(error as Error).message}`,\n\t\t\tcause: error as StorageFailureCause,\n\t\t});\n\t}\n\treturn \"written\";\n}\n\n/** One export file as import reads it: its path and its lines, each with its 1-based line number. */\nexport interface TransferFileLines {\n\treadonly file: string;\n\treadonly lines: readonly { readonly line: number; readonly text: string }[];\n}\n\n/**\n * The `*.jsonl` files of `directory`, in name order, each decoded as UTF-8 and split into lines; a final newline does\n * not start another line. A directory that does not exist holds no files. Throws `StorageTransferError` naming the\n * file when one cannot be read or is not UTF-8.\n */\nexport async function readTransferDirectory(directory: string): Promise<TransferFileLines[]> {\n\tlet names: string[];\n\ttry {\n\t\tnames = await readdir(directory);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow new StorageTransferError({\n\t\t\tpath: directory,\n\t\t\treason: `cannot read the directory: ${(error as Error).message}`,\n\t\t\tcause: error as StorageFailureCause,\n\t\t});\n\t}\n\tconst files: TransferFileLines[] = [];\n\tfor (const name of names.filter((entry) => entry.endsWith(TRANSFER_FILE_EXTENSION)).sort()) {\n\t\tconst file = join(directory, name);\n\t\tlet bytes: Buffer;\n\t\ttry {\n\t\t\tbytes = await readFile(file);\n\t\t} catch (error) {\n\t\t\tthrow new StorageTransferError({\n\t\t\t\tpath: file,\n\t\t\t\treason: `cannot read the file: ${(error as Error).message}`,\n\t\t\t\tcause: error as StorageFailureCause,\n\t\t\t});\n\t\t}\n\t\tlet text: string;\n\t\ttry {\n\t\t\ttext = new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n\t\t} catch {\n\t\t\tthrow new StorageTransferError({ path: file, reason: \"is not valid UTF-8 text\" });\n\t\t}\n\t\tconst lines = text.split(\"\\n\");\n\t\tif (lines.at(-1) === \"\") lines.pop();\n\t\tfiles.push({ file, lines: lines.map((line, index) => ({ line: index + 1, text: line })) });\n\t}\n\treturn files;\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atomic storage export` and `import` (#4716, #4720): sessions and workflow runs as JSONL files, one per session in
|
|
3
|
+
* `<dir>/sessions` and one per run in `<dir>/workflows`. Import reads only those two subdirectories.
|
|
4
|
+
*/
|
|
5
|
+
import { type SessionImportReport } from "./session-transfer.ts";
|
|
6
|
+
import { type WorkflowRunImportReport, type WorkflowRunTransferStorage } from "./storage/journal-transfer.js";
|
|
7
|
+
import type { SessionStore } from "./storage/session/types.js";
|
|
8
|
+
/** The directory of an export directory that holds its sessions. */
|
|
9
|
+
export declare function sessionsTransferDirectory(directory: string): string;
|
|
10
|
+
/** The directory of an export directory that holds its workflow runs. */
|
|
11
|
+
export declare function workflowsTransferDirectory(directory: string): string;
|
|
12
|
+
/** Where an import writes each kind it imports; a kind without a target is not read. */
|
|
13
|
+
export interface StorageImportTargets {
|
|
14
|
+
readonly sessions?: SessionStore;
|
|
15
|
+
readonly workflows?: WorkflowRunTransferStorage;
|
|
16
|
+
}
|
|
17
|
+
export interface StorageImportReport {
|
|
18
|
+
readonly sessions?: SessionImportReport;
|
|
19
|
+
readonly workflows?: WorkflowRunImportReport;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Imports the sessions and workflow runs exported to `directory`. Every file of both kinds is read and checked, and
|
|
23
|
+
* every session and run compared with the storage's copy, before anything is written: a malformed file, an unsupported
|
|
24
|
+
* version, or a session or run that continued differently here fails the import with the file and line, and nothing
|
|
25
|
+
* is written. Workflow runs are then written under the write locks of every journal file they go to, and sessions
|
|
26
|
+
* after them. A failure after something was written throws `StorageImportIncompleteError`, which names exactly what was
|
|
27
|
+
* written and what was not; importing again writes only what is missing.
|
|
28
|
+
*/
|
|
29
|
+
export declare function importStorage(directory: string, targets: StorageImportTargets): Promise<StorageImportReport>;
|
|
30
|
+
//# sourceMappingURL=storage-transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-transfer.d.ts","sourceRoot":"","sources":["../../src/core/storage-transfer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAKN,KAAK,mBAAmB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIN,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAQ/D,oEAAoE;AACpE,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,yEAAyE;AACzE,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wFAAwF;AACxF,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,0BAA0B,CAAC;CAChD;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,SAAS,CAAC,EAAE,uBAAuB,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA6BlH"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `atomic storage export` and `import` (#4716, #4720): sessions and workflow runs as JSONL files, one per session in
|
|
3
|
+
* `<dir>/sessions` and one per run in `<dir>/workflows`. Import reads only those two subdirectories.
|
|
4
|
+
*/
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { applySessionImport, pendingSessions, planSessionImport, readSessionExports, } from "./session-transfer.js";
|
|
7
|
+
import { applyWorkflowRunImport, planWorkflowRunImport, readWorkflowRunExports, } from "./storage/journal-transfer.js";
|
|
8
|
+
import { isStorageImportIncompleteError, SESSIONS_TRANSFER_DIRECTORY, StorageImportIncompleteError, WORKFLOWS_TRANSFER_DIRECTORY, } from "./storage/transfer-files.js";
|
|
9
|
+
/** The directory of an export directory that holds its sessions. */
|
|
10
|
+
export function sessionsTransferDirectory(directory) {
|
|
11
|
+
return join(directory, SESSIONS_TRANSFER_DIRECTORY);
|
|
12
|
+
}
|
|
13
|
+
/** The directory of an export directory that holds its workflow runs. */
|
|
14
|
+
export function workflowsTransferDirectory(directory) {
|
|
15
|
+
return join(directory, WORKFLOWS_TRANSFER_DIRECTORY);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Imports the sessions and workflow runs exported to `directory`. Every file of both kinds is read and checked, and
|
|
19
|
+
* every session and run compared with the storage's copy, before anything is written: a malformed file, an unsupported
|
|
20
|
+
* version, or a session or run that continued differently here fails the import with the file and line, and nothing
|
|
21
|
+
* is written. Workflow runs are then written under the write locks of every journal file they go to, and sessions
|
|
22
|
+
* after them. A failure after something was written throws `StorageImportIncompleteError`, which names exactly what was
|
|
23
|
+
* written and what was not; importing again writes only what is missing.
|
|
24
|
+
*/
|
|
25
|
+
export async function importStorage(directory, targets) {
|
|
26
|
+
const sessionFiles = targets.sessions === undefined ? undefined : await readSessionExports(sessionsTransferDirectory(directory));
|
|
27
|
+
const runFiles = targets.workflows === undefined ? undefined : await readWorkflowRunExports(workflowsTransferDirectory(directory));
|
|
28
|
+
const sessionPlan = targets.sessions === undefined ? undefined : await planSessionImport(targets.sessions, sessionFiles);
|
|
29
|
+
const runPlan = targets.workflows === undefined ? undefined : await planWorkflowRunImport(targets.workflows, runFiles);
|
|
30
|
+
let workflows;
|
|
31
|
+
if (runPlan !== undefined) {
|
|
32
|
+
try {
|
|
33
|
+
workflows = await applyWorkflowRunImport(runPlan);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!isStorageImportIncompleteError(error) || sessionPlan === undefined)
|
|
37
|
+
throw error;
|
|
38
|
+
throw new StorageImportIncompleteError(error.cause, {
|
|
39
|
+
written: error.written,
|
|
40
|
+
notWritten: { ...error.notWritten, sessions: pendingSessions(sessionPlan) },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const sessions = sessionPlan === undefined
|
|
45
|
+
? undefined
|
|
46
|
+
: await applySessionImport(sessionPlan, workflows === undefined ? [] : [...workflows.added, ...workflows.updated]);
|
|
47
|
+
return { ...(sessions === undefined ? {} : { sessions }), ...(workflows === undefined ? {} : { workflows }) };
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=storage-transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-transfer.js","sourceRoot":"","sources":["../../src/core/storage-transfer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GAElB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GAGtB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,8BAA8B,EAC9B,2BAA2B,EAC3B,4BAA4B,EAC5B,4BAA4B,GAC5B,MAAM,6BAA6B,CAAC;AAErC,oEAAoE;A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AM,IAAI,4BAA4B,CAAC,KAAK,CAAC,KAAc,EAAE;gBAC5D,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,UAAU,EAAE,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC,WAAW,CAAC,EAAE;aAC3E,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IACD,MAAM,QAAQ,GACb,WAAW,KAAK,SAAS;QACxB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,MAAM,kBAAkB,CACxB,WAAW,EACX,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,CACzE,CAAC;IACL,OAAO,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;AAC/G,CAAC","sourcesContent":["/**\n * `atomic storage export` and `import` (#4716, #4720): sessions and workflow runs as JSONL files, one per session in\n * `<dir>/sessions` and one per run in `<dir>/workflows`. Import reads only those two subdirectories.\n */\n\nimport { join } from \"node:path\";\nimport {\n\tapplySessionImport,\n\tpendingSessions,\n\tplanSessionImport,\n\treadSessionExports,\n\ttype SessionImportReport,\n} from \"./session-transfer.ts\";\nimport {\n\tapplyWorkflowRunImport,\n\tplanWorkflowRunImport,\n\treadWorkflowRunExports,\n\ttype WorkflowRunImportReport,\n\ttype WorkflowRunTransferStorage,\n} from \"./storage/journal-transfer.js\";\nimport type { SessionStore } from \"./storage/session/types.js\";\nimport {\n\tisStorageImportIncompleteError,\n\tSESSIONS_TRANSFER_DIRECTORY,\n\tStorageImportIncompleteError,\n\tWORKFLOWS_TRANSFER_DIRECTORY,\n} from \"./storage/transfer-files.js\";\n\n/** The directory of an export directory that holds its sessions. */\nexport function sessionsTransferDirectory(directory: string): string {\n\treturn join(directory, SESSIONS_TRANSFER_DIRECTORY);\n}\n\n/** The directory of an export directory that holds its workflow runs. */\nexport function workflowsTransferDirectory(directory: string): string {\n\treturn join(directory, WORKFLOWS_TRANSFER_DIRECTORY);\n}\n\n/** Where an import writes each kind it imports; a kind without a target is not read. */\nexport interface StorageImportTargets {\n\treadonly sessions?: SessionStore;\n\treadonly workflows?: WorkflowRunTransferStorage;\n}\n\nexport interface StorageImportReport {\n\treadonly sessions?: SessionImportReport;\n\treadonly workflows?: WorkflowRunImportReport;\n}\n\n/**\n * Imports the sessions and workflow runs exported to `directory`. Every file of both kinds is read and checked, and\n * every session and run compared with the storage's copy, before anything is written: a malformed file, an unsupported\n * version, or a session or run that continued differently here fails the import with the file and line, and nothing\n * is written. Workflow runs are then written under the write locks of every journal file they go to, and sessions\n * after them. A failure after something was written throws `StorageImportIncompleteError`, which names exactly what was\n * written and what was not; importing again writes only what is missing.\n */\nexport async function importStorage(directory: string, targets: StorageImportTargets): Promise<StorageImportReport> {\n\tconst sessionFiles =\n\t\ttargets.sessions === undefined ? undefined : await readSessionExports(sessionsTransferDirectory(directory));\n\tconst runFiles =\n\t\ttargets.workflows === undefined ? undefined : await readWorkflowRunExports(workflowsTransferDirectory(directory));\n\tconst sessionPlan =\n\t\ttargets.sessions === undefined ? undefined : await planSessionImport(targets.sessions, sessionFiles!);\n\tconst runPlan =\n\t\ttargets.workflows === undefined ? undefined : await planWorkflowRunImport(targets.workflows, runFiles!);\n\tlet workflows: WorkflowRunImportReport | undefined;\n\tif (runPlan !== undefined) {\n\t\ttry {\n\t\t\tworkflows = await applyWorkflowRunImport(runPlan);\n\t\t} catch (error) {\n\t\t\tif (!isStorageImportIncompleteError(error) || sessionPlan === undefined) throw error;\n\t\t\tthrow new StorageImportIncompleteError(error.cause as Error, {\n\t\t\t\twritten: error.written,\n\t\t\t\tnotWritten: { ...error.notWritten, sessions: pendingSessions(sessionPlan) },\n\t\t\t});\n\t\t}\n\t}\n\tconst sessions =\n\t\tsessionPlan === undefined\n\t\t\t? undefined\n\t\t\t: await applySessionImport(\n\t\t\t\t\tsessionPlan,\n\t\t\t\t\tworkflows === undefined ? [] : [...workflows.added, ...workflows.updated],\n\t\t\t\t);\n\treturn { ...(sessions === undefined ? {} : { sessions }), ...(workflows === undefined ? {} : { workflows }) };\n}\n"]}
|
|
@@ -52,6 +52,7 @@ export declare class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
52
52
|
private readonly reportedReadyCompactions;
|
|
53
53
|
private autoRetryEnabled;
|
|
54
54
|
private remoteSessionName;
|
|
55
|
+
private remoteSessionId;
|
|
55
56
|
private remoteSessionFile;
|
|
56
57
|
private readonly health;
|
|
57
58
|
private readonly remoteCommands;
|
|
@@ -196,6 +197,12 @@ export declare class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
196
197
|
private patchSessionManager;
|
|
197
198
|
private syncPersistedModelCatalog;
|
|
198
199
|
private refreshSessionView;
|
|
200
|
+
/**
|
|
201
|
+
* A saved session's entries reach the host through the store it shares with the engine. An unsaved one exists only
|
|
202
|
+
* in the engine's memory, so its view is rebuilt from the engine's entries and leaf, under the engine's session id
|
|
203
|
+
* (#4703).
|
|
204
|
+
*/
|
|
205
|
+
private openUnpersistedSessionView;
|
|
199
206
|
private observeEvent;
|
|
200
207
|
}
|
|
201
208
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isolated-runtime.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/isolated-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,mBAAmB,EAAE,KAAK,gCAAgC,EAAE,MAAM,q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,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC,CAGxC;IAED,gHAAgH;IAChH,OAAO,CAAC,eAAe;IA8BvB,OAAO,CAAC,gBAAgB;YAcV,2BAA2B;IAWzC,OAAO,CAAC,mBAAmB;YAiBb,yBAAyB;YAazB,kBAAkB;IAehC;;;;OAIG;YACW,0BAA0B;IAaxC,OAAO,CAAC,YAAY;CA6DpB"}
|
|
@@ -83,6 +83,7 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
83
83
|
reportedReadyCompactions = new WeakMap();
|
|
84
84
|
autoRetryEnabled = true;
|
|
85
85
|
remoteSessionName;
|
|
86
|
+
remoteSessionId;
|
|
86
87
|
remoteSessionFile;
|
|
87
88
|
health;
|
|
88
89
|
remoteCommands;
|
|
@@ -245,6 +246,7 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
245
246
|
this.resourceOverlaps = state.resourceOverlaps ?? [];
|
|
246
247
|
this.updateResourceExtensions(state.resourceExtensions ?? []);
|
|
247
248
|
this.remoteSessionName = state.sessionName;
|
|
249
|
+
this.remoteSessionId = state.sessionId;
|
|
248
250
|
this.remoteSessionFile = state.sessionLocation;
|
|
249
251
|
this.streaming = state.isStreaming;
|
|
250
252
|
this.compacting = state.isCompacting;
|
|
@@ -252,6 +254,7 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
252
254
|
this.queuePause.synchronize(state.queuedMessagesPaused === true);
|
|
253
255
|
this.replaceModelFallback(state.modelFallbackMessage, state.modelFallbackReason);
|
|
254
256
|
await this.refreshSessionView();
|
|
257
|
+
this.sessionStats.refresh();
|
|
255
258
|
this.engineCallbackActive = false;
|
|
256
259
|
this.health.clearUnresponsive();
|
|
257
260
|
this.health.markCooperativeAbortSettled();
|
|
@@ -1063,11 +1066,28 @@ export class IsolatedInteractiveRuntime extends AgentSessionRuntime {
|
|
|
1063
1066
|
async refreshSessionView() {
|
|
1064
1067
|
const session = super.session;
|
|
1065
1068
|
const currentManager = session.sessionManager;
|
|
1066
|
-
const refreshed =
|
|
1069
|
+
const refreshed = currentManager.isPersisted()
|
|
1070
|
+
? await SessionManager.open(currentManager.getSessionStore(), currentManager.getSessionId(), currentManager.getCwd())
|
|
1071
|
+
: await this.openUnpersistedSessionView(currentManager);
|
|
1067
1072
|
Object.defineProperty(session, "sessionManager", { configurable: true, value: refreshed });
|
|
1068
1073
|
this.patchSessionManager(refreshed);
|
|
1069
1074
|
session.agent.state.messages = refreshed.buildSessionContext().messages;
|
|
1070
1075
|
}
|
|
1076
|
+
/**
|
|
1077
|
+
* A saved session's entries reach the host through the store it shares with the engine. An unsaved one exists only
|
|
1078
|
+
* in the engine's memory, so its view is rebuilt from the engine's entries and leaf, under the engine's session id
|
|
1079
|
+
* (#4703).
|
|
1080
|
+
*/
|
|
1081
|
+
async openUnpersistedSessionView(current) {
|
|
1082
|
+
const { entries, leafId } = await this.client.getEntries();
|
|
1083
|
+
const header = current.getHeader();
|
|
1084
|
+
const view = SessionManager.inMemory(current.getCwd(), undefined, header ? [{ ...header, id: this.remoteSessionId ?? header.id }, ...entries] : entries);
|
|
1085
|
+
if (leafId === null)
|
|
1086
|
+
await view.resetLeaf();
|
|
1087
|
+
else if (leafId !== view.getLeafId())
|
|
1088
|
+
await view.branch(leafId);
|
|
1089
|
+
return view;
|
|
1090
|
+
}
|
|
1071
1091
|
observeEvent(event) {
|
|
1072
1092
|
const session = super.session;
|
|
1073
1093
|
// The engine reports its session's extension errors on this stream. They are this host session's errors, and
|