@bastani/atomic 0.9.83 → 0.9.84-alpha.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/package.json +1 -1
  5. package/dist/builtin/web-access/package.json +1 -1
  6. package/dist/builtin/workflows/package.json +1 -1
  7. package/dist/cli/storage-command.d.ts +12 -1
  8. package/dist/cli/storage-command.d.ts.map +1 -1
  9. package/dist/cli/storage-command.js +210 -47
  10. package/dist/cli/storage-command.js.map +1 -1
  11. package/dist/core/session-transfer.d.ts +84 -0
  12. package/dist/core/session-transfer.d.ts.map +1 -0
  13. package/dist/core/session-transfer.js +270 -0
  14. package/dist/core/session-transfer.js.map +1 -0
  15. package/dist/core/storage/journal-transfer.d.ts +74 -35
  16. package/dist/core/storage/journal-transfer.d.ts.map +1 -1
  17. package/dist/core/storage/journal-transfer.js +384 -278
  18. package/dist/core/storage/journal-transfer.js.map +1 -1
  19. package/dist/core/storage/transfer-files.d.ts +75 -0
  20. package/dist/core/storage/transfer-files.d.ts.map +1 -0
  21. package/dist/core/storage/transfer-files.js +170 -0
  22. package/dist/core/storage/transfer-files.js.map +1 -0
  23. package/dist/core/storage-transfer.d.ts +30 -0
  24. package/dist/core/storage-transfer.d.ts.map +1 -0
  25. package/dist/core/storage-transfer.js +49 -0
  26. package/dist/core/storage-transfer.js.map +1 -0
  27. package/dist/modes/interactive-engine/isolated-runtime.d.ts +7 -0
  28. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  29. package/dist/modes/interactive-engine/isolated-runtime.js +21 -1
  30. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  31. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  32. package/dist/modes/rpc/rpc-command-handler.js +1 -0
  33. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  34. package/docs/reference/cli.md +31 -3
  35. package/docs/storage.md +81 -17
  36. package/npm-shrinkwrap.json +38 -38
  37. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-transfer.js","sourceRoot":"","sources":["../../src/core/session-transfer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EACN,sBAAsB,EACtB,gBAAgB,EAEhB,iBAAiB,EACjB,oBAAoB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEtH,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAA4B,MAAM,oCAAoC,CAAC;AACtG,OAAO,EACN,sBAAsB,GAKtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,qBAAqB,EACrB,4BAA4B,EAC5B,oBAAoB,EAEpB,YAAY,EACZ,oBAAoB,GACpB,MAAM,6BAA6B,CAAC;AA0BrC,SAAS,aAAa,CAAC,KAAmB;IACzC,OAAO,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC;AAClC,CAAC;AAED,SAAS,WAAW,CAAC,IAAoB,EAAE,KAAqB;IAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5E,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACpC,OAAO,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,E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AC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBACvE,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YACvG,CAAC;QACF,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YACjB,MAAM,KAAK,GACV,MAAM,YAAY,oBAAoB,IAAI,MAAM,YAAY,kBAAkB;gBAC7E,CAAC,CAAC,IAAI,oBAAoB,CAAC;oBACzB,IAAI,EAAE,IAAI;oBACV,IAAI,EAAE,CAAC;oBACP,EAAE,EAAE,MAAM,CAAC,EAAE;oBACb,MAAM,EAAE,WAAW,MAAM,CAAC,EAAE,eAAe,aAAa,CAAC,KAAK,CAAC,kFAAkF;oBACjJ,KAAK,EAAE,MAAM;iBACb,CAAC;gBACH,CAAC,CAAE,MAAgB,CAAC;YACtB,MAAM,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * Sessions as format-4 JSONL files for `atomic storage export` and `import` (#4720): each session is written to\n * `<dir>/<sessionId>.jsonl` in the format JSONL session storage keeps and `atomic --import` reads, with the tool outputs\n * and worktree snapshot content it references carried inline as `/export <file>.jsonl` carries them, and read back with\n * the same parser.\n */\n\nimport { mkdir } from \"node:fs/promises\";\nimport type { SessionEntry } from \"./session-manager-types.ts\";\nimport {\n\tassertSessionBlobStore,\n\tinlineToolOutput,\n\ttype SessionBlobCopy,\n\tstoreSessionBlobs,\n\ttakeInlineToolOutput,\n} from \"./session-tool-output.ts\";\nimport { adoptInlineSnapshotBlobs, inlineSnapshotBlobs, sessionSnapshotBlobs } from \"./session-worktree-snapshots.ts\";\nimport type { StorageFailureCause } from \"./storage/errors.js\";\nimport { SessionConflictError, SessionExistsError } from \"./storage/session/errors.js\";\nimport { JsonlSessionStore } from \"./storage/session/jsonl-session-store.js\";\nimport { isCurrentSessionHeader, type StoredSessionHeader } from \"./storage/session/legacy-format.js\";\nimport {\n\tSESSION_FORMAT_VERSION,\n\ttype SessionRecordHeader,\n\ttype SessionSnapshot,\n\ttype SessionStore,\n\ttype SessionSummary,\n} from \"./storage/session/types.js\";\nimport {\n\treadTransferDirectory,\n\tStorageImportIncompleteError,\n\tStorageTransferError,\n\ttype TransferFileLines,\n\ttransferFile,\n\twriteLinesAtomically,\n} from \"./storage/transfer-files.js\";\nimport type { WorktreeSnapshot } from \"./worktree-snapshot/types.ts\";\n\nexport interface SessionExportOptions {\n\t/** At most this many sessions, most recently modified first. */\n\treadonly limit?: number;\n\t/** Only sessions modified at or after this time, in milliseconds since the epoch. */\n\treadonly since?: number;\n}\n\nexport interface SessionExportReport {\n\t/** Sessions whose file was written. */\n\treadonly written: readonly string[];\n\t/** Sessions whose file already held exactly this export, left untouched. */\n\treadonly unchanged: readonly string[];\n}\n\nexport interface SessionImportReport {\n\t/** Sessions the storage did not hold. */\n\treadonly added: readonly string[];\n\t/** Sessions the storage held an earlier part of, which now have the file's later entries. */\n\treadonly updated: readonly string[];\n\t/** Sessions the storage already held every entry of. */\n\treadonly unchanged: readonly string[];\n}\n\nfunction storeLocation(store: SessionStore): string {\n\treturn store.descriptor.location;\n}\n\nfunction newestFirst(left: SessionSummary, right: SessionSummary): number {\n\tconst modified = Date.parse(right.modifiedAt) - Date.parse(left.modifiedAt);\n\tif (modified !== 0) return modified;\n\treturn left.id < right.id ? -1 : left.id > right.id ? 1 : 0;\n}\n\n/**\n * A session's export file, line by line: the header, then every entry in append order, with the snapshot records,\n * snapshot content and tool outputs the store holds carried inline, each once. Tool outputs are read one at a time.\n */\nasync function* sessionExportLines(store: SessionStore, snapshot: SessionSnapshot): AsyncGenerator<string, void> {\n\tyield JSON.stringify({ type: \"session\", ...snapshot.header });\n\tconst records = new Map<string, WorktreeSnapshot>();\n\tfor (const entry of snapshot.entries)\n\t\tif (entry.type === \"worktree_snapshot\" && entry.snapshot !== undefined && !records.has(entry.snapshotId))\n\t\t\trecords.set(entry.snapshotId, entry.snapshot);\n\tconst entries = await inlineSnapshotBlobs(\n\t\tsnapshot.entries,\n\t\trecords,\n\t\tsessionSnapshotBlobs(store.snapshotBlobs, snapshot.entries),\n\t);\n\tfor await (const entry of inlineToolOutput(entries, store, snapshot.header.id)) yield JSON.stringify(entry);\n}\n\n/**\n * Exports the sessions of `store`, every project's and workflow stage sessions included, to\n * `<directory>/<sessionId>.jsonl`, one file per session. Each file is written whole or not at all; the same session\n * gives the same bytes, and a file that already holds them is not rewritten.\n */\nexport async function exportSessions(\n\tstore: SessionStore,\n\tdirectory: string,\n\toptions: SessionExportOptions = {},\n): Promise<SessionExportReport> {\n\tlet summaries: SessionSummary[] = [];\n\tfor await (const summary of store.list({ includeInternal: true })) summaries.push(summary);\n\tif (options.since !== undefined) {\n\t\tconst since = options.since;\n\t\tsummaries = summaries.filter((summary) => Date.parse(summary.modifiedAt) >= since);\n\t}\n\tsummaries.sort(newestFirst);\n\tif (options.limit !== undefined) summaries = summaries.slice(0, options.limit);\n\tawait mkdir(directory, { recursive: true });\n\tconst written: string[] = [];\n\tconst unchanged: string[] = [];\n\tfor (const summary of summaries) {\n\t\tconst snapshot = await store.load(summary.id);\n\t\tconst outcome = await writeLinesAtomically(\n\t\t\ttransferFile(directory, summary.id),\n\t\t\tsessionExportLines(store, snapshot),\n\t\t);\n\t\t(outcome === \"written\" ? written : unchanged).push(summary.id);\n\t}\n\treturn { written, unchanged };\n}\n\n/** A session read from an export file and checked: everything an import writes for it. */\nexport interface ParsedSession {\n\treadonly file: string;\n\treadonly header: SessionRecordHeader;\n\t/** The entries without the tool outputs they carried inline, which are in `blobs`. */\n\treadonly entries: readonly SessionEntry[];\n\treadonly blobs: readonly SessionBlobCopy[];\n}\n\ntype JsonLine = { readonly [key: string]: string | number | boolean | null | object };\n\n/** Checks one export file with the parser JSONL session storage and `atomic --import` use. */\nasync function parseSessionFile(source: JsonlSessionStore, { file, lines }: TransferFileLines): Promise<ParsedSession> {\n\tconst fail = (line: number | undefined, reason: string, cause?: StorageFailureCause): never => {\n\t\tthrow new StorageTransferError({ path: file, ...(line === undefined ? {} : { line }), reason, cause });\n\t};\n\tif (lines.length === 0) return fail(1, \"is empty; expected a session header\");\n\tconst parsed: JsonLine[] = [];\n\tfor (const { line, text } of lines) {\n\t\tif (text.trim() === \"\") fail(line, \"is empty\");\n\t\tlet value: JsonLine | string | number | boolean | null;\n\t\ttry {\n\t\t\tvalue = JSON.parse(text) as JsonLine;\n\t\t} catch (error) {\n\t\t\treturn fail(line, `is not valid JSON (${(error as Error).message})`);\n\t\t}\n\t\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) fail(line, \"is not a JSON object\");\n\t\tparsed.push(value);\n\t}\n\tconst first = parsed[0]!;\n\tif (first.type !== \"session\")\n\t\tfail(1, `is not an Atomic session export: its type is ${JSON.stringify(first.type ?? null)}, not \"session\"`);\n\tif (!isCurrentSessionHeader(first as StoredSessionHeader))\n\t\tfail(\n\t\t\t1,\n\t\t\t`has unsupported session format version ${JSON.stringify(first.version ?? null)}; this Atomic reads version ${SESSION_FORMAT_VERSION}`,\n\t\t);\n\tlet loaded: SessionSnapshot;\n\ttry {\n\t\tloaded = await source.loadFile(file);\n\t} catch (error) {\n\t\treturn fail(undefined, `is not a valid session: ${(error as Error).message}`, error as StorageFailureCause);\n\t}\n\ttry {\n\t\tconst { entries, blobs } = takeInlineToolOutput(loaded.entries, loaded.header.id);\n\t\t// Checks the snapshot content carried inline against its hashes, writing nothing.\n\t\tawait adoptInlineSnapshotBlobs(entries, undefined);\n\t\treturn { file, header: loaded.header, entries, blobs };\n\t} catch (error) {\n\t\treturn fail(undefined, `carries content that does not match its hash: ${(error as Error).message}`);\n\t}\n}\n\n/**\n * Reads and checks every `*.jsonl` session export file in `directory`; nothing is written. A directory that does not\n * exist holds no sessions. Throws `StorageTransferError` with the file, and the line where there is one, for the first\n * file that is not a valid format-4 session.\n */\nexport async function readSessionExports(directory: string): Promise<ParsedSession[]> {\n\tconst files = await readTransferDirectory(directory);\n\tif (files.length === 0) return [];\n\tconst source = await JsonlSessionStore.open(directory, { exactDirectory: true, scanExisting: false });\n\ttry {\n\t\tconst parsed: ParsedSession[] = [];\n\t\tconst seen = new Map<string, string>();\n\t\tfor (const lines of files) {\n\t\t\tconst session = await parseSessionFile(source, lines);\n\t\t\tconst earlier = seen.get(session.header.id);\n\t\t\tif (earlier !== undefined)\n\t\t\t\tthrow new StorageTransferError({\n\t\t\t\t\tpath: session.file,\n\t\t\t\t\tline: 1,\n\t\t\t\t\tid: session.header.id,\n\t\t\t\t\treason: `session ${session.header.id} is also in ${earlier}; keep one file per session`,\n\t\t\t\t});\n\t\t\tseen.set(session.header.id, session.file);\n\t\t\tparsed.push(session);\n\t\t}\n\t\treturn parsed;\n\t} finally {\n\t\tawait source.close();\n\t}\n}\n\n/** What an import does to one session. */\nexport type SessionImportAction = \"add\" | \"update\" | \"unchanged\";\n\ninterface PlannedSession {\n\treadonly session: ParsedSession;\n\treadonly action: SessionImportAction;\n\t/** How many entries the storage holds, and the sequence number a write must expect. */\n\treadonly storedEntries: number;\n\treadonly storedSeq: number;\n}\n\n/** What importing a set of session export files does to a session store, decided before anything is written. */\nexport interface SessionImportPlan {\n\treadonly store: SessionStore;\n\treadonly sessions: readonly PlannedSession[];\n}\n\nfunction pendingIds(sessions: readonly PlannedSession[]): string[] {\n\treturn sessions.map((planned) => planned.session.header.id);\n}\n\n/** The sessions of a plan an import writes. */\nexport function pendingSessions(plan: SessionImportPlan): string[] {\n\treturn plan.sessions.filter((session) => session.action !== \"unchanged\").map((session) => session.session.header.id);\n}\n\n/**\n * The fields import compares between an entry of a file and the stored entry at the same position: its ID, its\n * parent and its type, as `--import` and session storage identify entries. Everything else may differ, so a file a\n * tool redacted strings in imports as the session it came from.\n */\nfunction sameEntry(stored: SessionEntry, exported: SessionEntry): boolean {\n\treturn stored.id === exported.id && stored.parentId === exported.parentId && stored.type === exported.type;\n}\n\n/**\n * Compares every session of `sessions` with the store's copy, writing nothing. A session is identified by its header\n * ID, as `atomic --import` identifies it: one the store lacks is added; one whose entries the store holds the first\n * part of gets the rest; one the store holds every entry of is left alone. A session created at another time, or one\n * whose entries continued differently in the store, fails with the file and line.\n */\nexport async function planSessionImport(\n\tstore: SessionStore,\n\tsessions: readonly ParsedSession[],\n): Promise<SessionImportPlan> {\n\tconst planned: PlannedSession[] = [];\n\tconst location = storeLocation(store);\n\tfor (const session of sessions) {\n\t\tconst { header, entries, file } = session;\n\t\tconst fail = (line: number, reason: string): never => {\n\t\t\tthrow new StorageTransferError({ path: file, line, id: header.id, reason });\n\t\t};\n\t\tif ((await store.readHeader(header.id)) === undefined) {\n\t\t\tassertBlobs(store, session);\n\t\t\tplanned.push({ session, action: \"add\", storedEntries: 0, storedSeq: 0 });\n\t\t\tcontinue;\n\t\t}\n\t\tconst stored = await store.load(header.id);\n\t\tif (stored.header.createdAt !== header.createdAt)\n\t\t\tfail(\n\t\t\t\t1,\n\t\t\t\t`session ${header.id} in ${location} was created at another time; it is a different session with the same ID`,\n\t\t\t);\n\t\tconst shared = Math.min(stored.entries.length, entries.length);\n\t\tfor (let index = 0; index < shared; index++)\n\t\t\tif (!sameEntry(stored.entries[index]!, entries[index]!))\n\t\t\t\tfail(\n\t\t\t\t\tindex + 2,\n\t\t\t\t\t`entry ${index + 1} differs from entry ${index + 1} of session ${header.id} in ${location}: the session continued differently there`,\n\t\t\t\t);\n\t\tconst action = entries.length > stored.entries.length ? \"update\" : \"unchanged\";\n\t\tif (action === \"update\") assertBlobs(store, session);\n\t\tplanned.push({ session, action, storedEntries: stored.entries.length, storedSeq: stored.lastSeq });\n\t}\n\treturn { store, sessions: planned };\n}\n\nfunction assertBlobs(store: SessionStore, session: ParsedSession): void {\n\ttry {\n\t\tassertSessionBlobStore(store, session.header.id, session.blobs.length);\n\t} catch (error) {\n\t\tthrow new StorageTransferError({\n\t\t\tpath: session.file,\n\t\t\tid: session.header.id,\n\t\t\treason: (error as Error).message,\n\t\t\tcause: error as StorageFailureCause,\n\t\t});\n\t}\n}\n\n/**\n * Writes what `plan` decided, one session at a time. Each write expects the store to hold exactly what the plan\n * compared: a session another process created or added entries to since fails with the file, and nothing of it is\n * written. Session storage has no lock an import can hold across sessions, so when a write fails after earlier writes\n * (or after `workflowsWritten`, the runs the same import already wrote), `StorageImportIncompleteError` names what was\n * written and what was not; importing again writes only what is missing. A session the store already holds in full\n * gets the tool outputs of the file it lacks, so a rerun also finishes a session whose outputs an interrupted import\n * did not store.\n */\nexport async function applySessionImport(\n\tplan: SessionImportPlan,\n\tworkflowsWritten: readonly string[] = [],\n): Promise<SessionImportReport> {\n\tconst { store } = plan;\n\tconst report = { added: [] as string[], updated: [] as string[], unchanged: [] as string[] };\n\tconst pending = plan.sessions.filter((planned) => planned.action !== \"unchanged\");\n\t/** `error`, naming what this import wrote before it when it wrote anything, and the sessions it did not write. */\n\tconst failure = (error: Error, notWritten: readonly string[]): Error => {\n\t\tconst sessionsWritten = [...report.added, ...report.updated];\n\t\tif (sessionsWritten.length === 0 && workflowsWritten.length === 0) return error;\n\t\treturn new StorageImportIncompleteError(error, {\n\t\t\twritten: { sessions: sessionsWritten, workflows: workflowsWritten },\n\t\t\tnotWritten: { sessions: notWritten, workflows: [] },\n\t\t});\n\t};\n\tfor (const planned of plan.sessions) {\n\t\tif (planned.action !== \"unchanged\") continue;\n\t\t// An import stopped between writing a new session's entries and its tool outputs left the session complete but\n\t\t// its outputs missing: the rerun stores the ones the store lacks.\n\t\tconst { header, blobs } = planned.session;\n\t\ttry {\n\t\t\tfor (const blob of blobs)\n\t\t\t\tif ((await store.getBlob?.(header.id, blob.hash)) === undefined)\n\t\t\t\t\tawait store.putBlob?.(header.id, blob.read());\n\t\t} catch (caught) {\n\t\t\tthrow failure(caught as Error, [header.id, ...pendingIds(pending)]);\n\t\t}\n\t\treport.unchanged.push(header.id);\n\t}\n\tfor (const [index, planned] of pending.entries()) {\n\t\tconst { header, file, blobs } = planned.session;\n\t\ttry {\n\t\t\tconst entries = await adoptInlineSnapshotBlobs(planned.session.entries, store.snapshotBlobs);\n\t\t\tif (planned.action === \"add\") {\n\t\t\t\tawait store.create(header, entries);\n\t\t\t\tawait storeSessionBlobs(store, header.id, blobs);\n\t\t\t} else {\n\t\t\t\tfor (const blob of blobs) await store.putBlob!(header.id, blob.read());\n\t\t\t\tawait store.append(header.id, entries.slice(planned.storedEntries), { expectSeq: planned.storedSeq });\n\t\t\t}\n\t\t} catch (caught) {\n\t\t\tconst error =\n\t\t\t\tcaught instanceof SessionConflictError || caught instanceof SessionExistsError\n\t\t\t\t\t? new StorageTransferError({\n\t\t\t\t\t\t\tpath: file,\n\t\t\t\t\t\t\tline: 1,\n\t\t\t\t\t\t\tid: header.id,\n\t\t\t\t\t\t\treason: `session ${header.id} changed in ${storeLocation(store)} after the import compared it (another process wrote to it); it was not imported`,\n\t\t\t\t\t\t\tcause: caught,\n\t\t\t\t\t\t})\n\t\t\t\t\t: (caught as Error);\n\t\t\tthrow failure(error, pendingIds(pending.slice(index)));\n\t\t}\n\t\t(planned.action === \"add\" ? report.added : report.updated).push(header.id);\n\t}\n\treturn report;\n}\n"]}
@@ -1,25 +1,30 @@
1
1
  /**
2
- * Workflow runs as versioned JSONL files (#4716): `exportWorkflowRuns` writes each run of a local workflow journal to
3
- * `<dir>/<runId>.jsonl`, and `importWorkflowRuns` restores such files into one. The journal stays the working store;
4
- * the files are the form runs take at rest, so a host that persists only files can carry them between machines.
2
+ * Workflow runs as versioned JSONL files (#4716, #4720): `exportWorkflowRuns` writes each run of a local workflow
3
+ * journal to `<dir>/<runId>.jsonl`, and the import functions restore such files into one. The journal stays the
4
+ * working store; the files are the form runs take at rest, so a host that persists only files can carry them between
5
+ * machines. `atomic storage export` and `import` use `<exportDir>/workflows` as `<dir>`.
5
6
  *
6
7
  * Line 1 of a file is the run's header: the row of the journal's runs table. Every later line is one row of its
7
8
  * events table, in sequence order, with its payload as a JSON value instead of JSON text. Leases, local-worker pool
8
9
  * state and worktree snapshot blobs are not exported: they belong to the machine that wrote them.
9
10
  */
10
- import { StorageError, type StorageFailureCause } from "./errors.js";
11
+ import { type JournalEventTableRow, type JournalLeaseTableRow, type JournalRunTableRow } from "./journal-adoption.js";
12
+ import { type JournalShardRecord } from "./journal-catalog.js";
11
13
  /** The `type` of an export file's header line. */
12
14
  export declare const WORKFLOW_RUN_EXPORT_TYPE = "atomic.workflow-run";
13
15
  /** The export format version this Atomic writes and reads. */
14
16
  export declare const WORKFLOW_RUN_EXPORT_VERSION = 1;
15
- /** The file name extension of an exported run; import reads every file with it and ignores the rest. */
16
- export declare const WORKFLOW_RUN_EXPORT_EXTENSION = ".jsonl";
17
17
  /**
18
18
  * A lease renewed this recently belongs to a process that may still be running the run on this machine, so an import
19
19
  * does not add events to that run. It matches the window in which the workflows runtime treats a running run's owner
20
20
  * as live.
21
21
  */
22
22
  export declare const WORKFLOW_RUN_IMPORT_LIVE_LEASE_MS = 120000;
23
+ /**
24
+ * How many times an export reads the catalog again after reading the journal files, for runs a consolidation moved
25
+ * in between; a run still not found where the catalog names it after the last read is reported with its reason.
26
+ */
27
+ export declare const WORKFLOW_RUN_EXPORT_PLACEMENT_ATTEMPTS = 5;
23
28
  /** A JSON value as an export file holds it. */
24
29
  export type WorkflowRunExportValue = string | number | boolean | null | readonly WorkflowRunExportValue[] | {
25
30
  readonly [key: string]: WorkflowRunExportValue;
@@ -59,25 +64,6 @@ export type WorkflowRunTransferStorage = {
59
64
  readonly path: string;
60
65
  readonly prefix?: string;
61
66
  };
62
- export interface WorkflowRunTransferErrorInit {
63
- /** The file or storage location the error is about. */
64
- readonly path: string;
65
- /** The 1-based line of `path`. */
66
- readonly line?: number;
67
- readonly runId?: string;
68
- readonly reason: string;
69
- readonly cause?: StorageFailureCause;
70
- }
71
- /** An export or import that could not be done; an import that fails this way changed nothing. */
72
- export declare class WorkflowRunTransferError extends StorageError {
73
- readonly name: "WorkflowRunTransferError";
74
- readonly path: string;
75
- readonly line: number | undefined;
76
- readonly runId: string | undefined;
77
- readonly reason: string;
78
- constructor(init: WorkflowRunTransferErrorInit);
79
- }
80
- export declare function isWorkflowRunTransferError(value: unknown): value is WorkflowRunTransferError;
81
67
  export interface WorkflowRunExportOptions {
82
68
  /** Only these runs; a run the storage does not hold fails the export before any file is written. */
83
69
  readonly runs?: readonly string[];
@@ -91,7 +77,7 @@ export interface WorkflowRunExportReport {
91
77
  readonly written: readonly string[];
92
78
  /** Runs whose file already held exactly this export, left untouched. */
93
79
  readonly unchanged: readonly string[];
94
- /** Journal files that could not be read, and runs the catalog lists that no readable journal holds. */
80
+ /** Journal files that could not be read, and catalogued runs that could not be exported, with the reason. */
95
81
  readonly skipped: readonly {
96
82
  readonly path: string;
97
83
  readonly runId?: string;
@@ -106,21 +92,74 @@ export interface WorkflowRunImportReport {
106
92
  /** Runs the storage already held every event of. */
107
93
  readonly unchanged: readonly string[];
108
94
  }
109
- /** The file an exported run is written to in `directory`. */
110
- export declare function workflowRunExportFile(directory: string, runId: string): string;
111
95
  /**
112
96
  * Exports runs of a local workflow journal to `<directory>/<runId>.jsonl`, one file per run. Each journal file is read
113
97
  * in one read transaction, and each export file is written whole or not at all. The same journal state gives the same
114
- * bytes, and a file that already holds them is not rewritten.
98
+ * bytes, and a file that already holds them is not rewritten. A run the store's catalog lists is taken only from the
99
+ * shard the catalog names for it, read again when a consolidation moved it while the export ran; one that cannot be
100
+ * exported is reported with the reason.
115
101
  */
116
102
  export declare function exportWorkflowRuns(storage: WorkflowRunTransferStorage, directory: string, options?: WorkflowRunExportOptions): Promise<WorkflowRunExportReport>;
103
+ /** A run read from an export file and checked: everything an import writes for it. */
104
+ export interface ParsedWorkflowRun {
105
+ readonly file: string;
106
+ readonly header: WorkflowRunExportHeader;
107
+ readonly events: readonly WorkflowRunExportEvent[];
108
+ }
109
+ /**
110
+ * Reads and checks every `*.jsonl` export file in `directory`; nothing is written. A directory that does not exist
111
+ * holds no runs. Throws `StorageTransferError` with the file and line for the first file that is not a valid export.
112
+ */
113
+ export declare function readWorkflowRunExports(directory: string): Promise<ParsedWorkflowRun[]>;
114
+ interface StoredRun {
115
+ readonly run: JournalRunTableRow;
116
+ readonly events: readonly JournalEventTableRow[];
117
+ readonly lease?: JournalLeaseTableRow & {
118
+ readonly age_ms: number;
119
+ };
120
+ }
121
+ /** What an import does to one run. */
122
+ export type WorkflowRunImportAction = "add" | "update" | "unchanged";
123
+ /** One run of an import plan: what the import does to it, and the storage's copy the decision was made on. */
124
+ interface PlannedRun {
125
+ readonly run: ParsedWorkflowRun;
126
+ readonly action: WorkflowRunImportAction;
127
+ readonly stored: StoredRun | undefined;
128
+ /** The shard holding the run; for a store only. */
129
+ readonly shard?: JournalShardRecord;
130
+ /** Whether the store's catalog lists the run. */
131
+ readonly catalogued: boolean;
132
+ }
133
+ /** What importing a set of export files does to a local workflow journal, decided before anything is written. */
134
+ export interface WorkflowRunImportPlan {
135
+ readonly storage: WorkflowRunTransferStorage;
136
+ readonly runs: readonly PlannedRun[];
137
+ }
138
+ /** The runs of a plan an import writes. */
139
+ export declare function pendingWorkflowRuns(plan: WorkflowRunImportPlan): string[];
140
+ /**
141
+ * Compares every run of `runs` with the storage's copy, writing nothing: a run that continued differently here, or that
142
+ * a process here may still be running, fails with the file and line.
143
+ */
144
+ export declare function planWorkflowRunImport(storage: WorkflowRunTransferStorage, runs: readonly ParsedWorkflowRun[]): Promise<WorkflowRunImportPlan>;
145
+ /**
146
+ * Writes what `plan` decided. Every journal file the import writes to is opened and its write lock taken, in path
147
+ * order, before anything is written, and every run is compared again under those locks: a run another process changed
148
+ * since the plan was made (a resume took its lease, events were added, a consolidation moved it) fails the import with
149
+ * nothing written. The locks are held until the last run is written; each file then commits. Separate journal files
150
+ * cannot commit together, so when one fails to commit after another did, `StorageImportIncompleteError` names the runs
151
+ * written and the runs not written, and importing again writes only the rest. A store's catalog records added runs
152
+ * after their files commit; a run an interrupted import wrote before recording it is found and recorded by the next.
153
+ */
154
+ export declare function applyWorkflowRunImport(plan: WorkflowRunImportPlan): Promise<WorkflowRunImportReport>;
117
155
  /**
118
- * Imports every `<name>.jsonl` export file in `directory` into a local workflow journal. Every file is read and checked,
119
- * and every run compared with the storage's copy, before anything is written: a malformed file, an unsupported version,
120
- * a run that continued differently here, or a run a process here may still be running fails the import with the file
121
- * and line, and nothing changes. A run the storage does not hold is added; one whose earlier events it holds gets the
122
- * file's later ones; one it holds every event of is left as it is, so importing again changes nothing. String values
123
- * inside the records are not compared, so a file whose strings a tool redacted imports as the run it was exported from.
156
+ * Imports every `<name>.jsonl` export file in `directory` into a local workflow journal: `readWorkflowRunExports`,
157
+ * `planWorkflowRunImport` and `applyWorkflowRunImport` in turn. Every file is read and checked, and every run compared
158
+ * with the storage's copy, before anything is written. A run the storage does not hold is added; one whose earlier
159
+ * events it holds gets the file's later ones; one it holds every event of is left as it is, so importing again changes
160
+ * nothing. String values inside the records are not compared, so a file whose strings a tool redacted imports as the
161
+ * run it was exported from.
124
162
  */
125
163
  export declare function importWorkflowRuns(storage: WorkflowRunTransferStorage, directory: string): Promise<WorkflowRunImportReport>;
164
+ export {};
126
165
  //# sourceMappingURL=journal-transfer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"journal-transfer.d.ts","sourceRoot":"","sources":["../../../src/core/storage/journal-transfer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAoBr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