@bastani/atomic 0.9.83-alpha.1 → 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 +30 -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
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.84-alpha.1] - 2026-11-13
6
+
7
+ Sessions now move between machines alongside workflow runs.
8
+
9
+ - **Export and import sessions with your runs.** `atomic storage export <dir>` writes sessions next to workflow runs, `atomic storage import <dir>` restores both, and `--sessions`, `--workflows`, `--limit`, and `--since` pick what moves ([#4720](https://github.com/bastani-inc/atomic/issues/4720), [#4721](https://github.com/bastani-inc/atomic/pull/4721)).
10
+ - **Safer storage transfers.** Import checks everything under the journal's write locks before writing and reports exactly what a partial import wrote, and export no longer drops runs that `atomic storage consolidate` moves while it reads ([#4720](https://github.com/bastani-inc/atomic/issues/4720), [#4721](https://github.com/bastani-inc/atomic/pull/4721)).
11
+ - **`/reload` keeps unsaved sessions intact.** A `--no-session` session keeps its transcript, `/session` counts, and context usage across `/reload` ([#4703](https://github.com/bastani-inc/atomic/issues/4703), [#4723](https://github.com/bastani-inc/atomic/pull/4723)).
12
+ - **Patched dependency advisories.** The bundled `hono` and `@hono/node-server` are updated to clear reported moderate and low advisories ([#4722](https://github.com/bastani-inc/atomic/pull/4722)).
13
+
14
+ ### Changed
15
+
16
+ - `atomic storage export <dir>` now also exports sessions, and writes them to `<dir>/sessions/<sessionId>.jsonl` and workflow runs to `<dir>/workflows/<runId>.jsonl`. Session files are format-4 session files, the format `atomic --import` reads, with their tool outputs and snapshot contents carried inline. `--sessions` and `--workflows` limit export and import to one kind, `--limit` also keeps the most recently modified sessions, and `--since <time>` keeps sessions modified since a date. `atomic storage import <dir>` restores both kinds from those subdirectories, checks every file of both kinds before writing, appends the entries a session lacks, and refuses a session that continued differently with its file and line ([#4720](https://github.com/bastani-inc/atomic/issues/4720))
17
+
18
+ ### Fixed
19
+
20
+ - Fixed `atomic storage import` leaving earlier runs imported when another process changed a later run during the import. Import now takes the write lock of every journal file it writes to and checks every run again under those locks, so a concurrent change fails the import before anything is written. An import that fails after writing part of its files lists exactly what it imported and what it did not, and running it again finishes it without duplicates ([#4720](https://github.com/bastani-inc/atomic/issues/4720))
21
+ - Fixed `atomic storage export` leaving out a workflow run that `atomic storage consolidate` moved to another shard while the export read it, and reporting it as a run in the old journal format. Export now reads the catalog again and rereads the shard the run moved to, including a shard created during the export, and reports any run it still cannot export with the real reason ([#4720](https://github.com/bastani-inc/atomic/issues/4720))
22
+ - Updated the bundled `hono` (4.13.13 → 4.13.16) and `@hono/node-server` (2.1.5 → 2.1.8), which the MCP SDK pulls in, to clear five moderate and low `hono` advisories and two moderate `@hono/node-server` advisories reported against the installed versions
23
+ - Fixed `/reload` emptying the transcript of a `--no-session` session in interactive mode, and `/session` and the context indicator reading 0 until the next turn. The transcript, `/session` counts, and context usage now stay as they were before the reload, for unsaved and saved sessions alike ([#4703](https://github.com/bastani-inc/atomic/issues/4703) by [@grghub](https://github.com/grghub))
24
+
25
+ ## [0.9.83] - 2026-11-13
26
+
27
+ Workflow runs that travel between machines.
28
+
29
+ - **Carry workflow runs as plain files.** `atomic storage export <dir>` writes runs from the local journal to versioned JSONL files, and `atomic storage import <dir>` loads them back, so hosts that persist only files keep their runs and an interrupted run resumes on the new machine ([#4716](https://github.com/bastani-inc/atomic/issues/4716), [#4717](https://github.com/bastani-inc/atomic/pull/4717)).
30
+
31
+ ### Added
32
+
33
+ - Added `atomic storage export <dir>` and `atomic storage import <dir>`, which move workflow runs between the local workflow journal and versioned JSONL files (one `<runId>.jsonl` per run), so hosts that persist only files can keep runs between machines. Export selects runs with `--run`, `--unfinished` and `--limit`, reads a consistent snapshot, writes each file atomically, and gives byte-identical output for an unchanged run. Import checks every file before writing, is idempotent, accepts files whose string values were redacted, and leaves imported runs unowned so an interrupted run resumes on the new machine ([#4716](https://github.com/bastani-inc/atomic/issues/4716), [#4717](https://github.com/bastani-inc/atomic/pull/4717))
34
+
5
35
  ## [0.9.83-alpha.1] - 2026-11-13
6
36
 
7
37
  Workflow runs that travel between machines.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/intercom",
3
- "version": "0.9.83-alpha.1",
3
+ "version": "0.9.84-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension providing a private coordination channel between parent and child agent sessions. Fork of: https://github.com/nicobailon/pi-intercom",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/mcp",
3
- "version": "0.9.83-alpha.1",
3
+ "version": "0.9.84-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic's pi-compatible MCP integration for server connections, OAuth, tools, resources, and terminal management.",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/subagents",
3
- "version": "0.9.83-alpha.1",
3
+ "version": "0.9.84-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for delegating tasks to subagents with parallel execution. Fork of: https://github.com/nicobailon/pi-subagents",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/web-access",
3
- "version": "0.9.83-alpha.1",
3
+ "version": "0.9.84-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for web search, URL fetching, GitHub repo cloning, PDF/video extraction. Fork of: https://github.com/nicobailon/pi-web-access",
6
6
  "contributors": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/workflows",
3
- "version": "0.9.83-alpha.1",
3
+ "version": "0.9.84-alpha.1",
4
4
  "private": true,
5
5
  "description": "Atomic extension for multi-stage workflow authoring and execution.",
6
6
  "contributors": [
@@ -4,7 +4,7 @@
4
4
  * uses. `atomic storage join` points this machine's global `storage` setting at a shared libSQL / Turso database.
5
5
  * `atomic storage adopt` registers existing journal files in the journal store in place, and `atomic storage
6
6
  * consolidate` moves their finished runs into the store's own shards. `atomic storage export` and `atomic storage
7
- * import` move workflow runs between the local workflow journal and versioned JSONL files (#4716).
7
+ * import` move sessions and workflow runs between their storage and JSONL files (#4716, #4720).
8
8
  */
9
9
  import type { IntercomBrokerControl } from "../core/intercom-broker-control.js";
10
10
  import { LIBSQL_ADAPTER_PACKAGE, STORAGE_TOKEN_FILE } from "../core/storage/selection.js";
@@ -29,13 +29,24 @@ export type StorageCommand = {
29
29
  } | {
30
30
  readonly kind: "export";
31
31
  readonly directory: string;
32
+ /** The kinds to export; both when neither `--sessions` nor `--workflows` is given. */
33
+ readonly kinds: TransferKinds;
32
34
  readonly runs?: readonly string[];
33
35
  readonly unfinished: boolean;
34
36
  readonly limit?: number;
37
+ /** `--since`, in milliseconds since the epoch. */
38
+ readonly since?: number;
35
39
  } | {
36
40
  readonly kind: "import";
37
41
  readonly directory: string;
42
+ readonly kinds: TransferKinds;
38
43
  };
44
+ /** Which kinds an export or import covers, and whether `--sessions` or `--workflows` named them. */
45
+ export interface TransferKinds {
46
+ readonly sessions: boolean;
47
+ readonly workflows: boolean;
48
+ readonly explicit: boolean;
49
+ }
39
50
  export declare class StorageCommandError extends Error {
40
51
  }
41
52
  /** Parse the arguments after `storage`. */
@@ -1 +1 @@
1
- {"version":3,"file":"storage-command.d.ts","sourceRoot":"","sources":["../../src/cli/storage-command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAchF,OAAO,EAGN,sBAAsB,EAEtB,kBAAkB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEN,KAAK,YAAY,EAIjB,KAAK,aAAa,EAClB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,CAAC;AAiDtD,MAAM,MAAM,cAAc,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC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AAM,CAAC;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,iEAAiE;IACjE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC5D;AAID,+EAA+E;AAC/E,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAChD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC5D,GAAG,OAAO,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAQzC;AAED,wGAAwG;AACxG,wBAAgB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAOpD;AAQD,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAkEnE;AAwED,4DAA4D;AAC5D,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiChH"}
@@ -4,24 +4,32 @@
4
4
  * uses. `atomic storage join` points this machine's global `storage` setting at a shared libSQL / Turso database.
5
5
  * `atomic storage adopt` registers existing journal files in the journal store in place, and `atomic storage
6
6
  * consolidate` moves their finished runs into the store's own shards. `atomic storage export` and `atomic storage
7
- * import` move workflow runs between the local workflow journal and versioned JSONL files (#4716).
7
+ * import` move sessions and workflow runs between their storage and JSONL files (#4716, #4720).
8
8
  */
9
+ import { existsSync } from "node:fs";
9
10
  import { join, resolve } from "node:path";
10
11
  import { APP_NAME } from "../config.js";
12
+ import { resolveSessionStore, selectSessionStorage } from "../core/session-storage.js";
13
+ import { exportSessions } from "../core/session-transfer.js";
14
+ import { SettingsManager } from "../core/settings-manager.js";
11
15
  import { isJournalStoreError, isTeamProfileConfigError, isTeamProfileError } from "../core/storage/errors.js";
12
16
  import { adoptJournals, consolidateJournalStore, defaultJournalStoreDirectory, } from "../core/storage/journal-adoption.js";
13
- import { exportWorkflowRuns, importWorkflowRuns, isWorkflowRunTransferError, WORKFLOW_RUN_EXPORT_VERSION, } from "../core/storage/journal-transfer.js";
17
+ import { exportWorkflowRuns, WORKFLOW_RUN_EXPORT_VERSION, } from "../core/storage/journal-transfer.js";
14
18
  import { checkTeamUrl, isFileUrl, LIBSQL_ADAPTER_PACKAGE, missingTeamToken, STORAGE_TOKEN_FILE, } from "../core/storage/selection.js";
15
- import { collectStorageStatus, describeStorageError, describeStorageSelection, effectiveJournalSelection, } from "../core/storage/storage-status.js";
19
+ import { SESSION_FORMAT_VERSION } from "../core/storage/session/types.js";
20
+ import { collectStorageStatus, describeStorageError, describeStorageSelection, effectiveJournalSelection, projectTrust, } from "../core/storage/storage-status.js";
16
21
  import { joinSharedDatabase } from "../core/storage/team.js";
22
+ import { isStorageImportIncompleteError, isStorageTransferError, } from "../core/storage/transfer-files.js";
23
+ import { importStorage, sessionsTransferDirectory, workflowsTransferDirectory } from "../core/storage-transfer.js";
17
24
  export { LIBSQL_ADAPTER_PACKAGE, STORAGE_TOKEN_FILE };
18
25
  const HELP = `Usage:
19
26
  ${APP_NAME} storage status [--json]
20
27
  ${APP_NAME} storage join <url> [--token-file <path>] [--prefix <prefix>]
21
28
  ${APP_NAME} storage adopt <path>... [--no-discover]
22
29
  ${APP_NAME} storage consolidate
23
- ${APP_NAME} storage export <dir> [--run <id>]... [--unfinished] [--limit <n>]
24
- ${APP_NAME} storage import <dir>
30
+ ${APP_NAME} storage export <dir> [--sessions] [--workflows] [--run <id>]... [--unfinished]
31
+ [--limit <n>] [--since <time>]
32
+ ${APP_NAME} storage import <dir> [--sessions] [--workflows]
25
33
 
26
34
  Commands:
27
35
  status Show, for sessions, workflow runs, and Intercom, the selected storage and where the
@@ -42,13 +50,19 @@ Commands:
42
50
  Move finished runs (completed, failed or cancelled, not leased, without local workers)
43
51
  from adopted journals into the journal store's own shards. Other runs stay where they
44
52
  are. An interrupted consolidation leaves every run readable; run it again to finish.
45
- export Write workflow runs to <dir>/<runId>.jsonl, one file per run (format version
46
- ${WORKFLOW_RUN_EXPORT_VERSION}): a header line, then one line per journal event. Every run by default;
47
- a file is replaced whole, and one that already holds the same run is not rewritten.
48
- import Restore every *.jsonl export in <dir> into this directory's workflow journal. All files
49
- are checked first, so a malformed or unsupported file changes nothing. Importing again
50
- adds nothing; a newer export of a run adds its later events. Imported runs are not
51
- owned by any process: an interrupted one can be resumed here.
53
+ export Write sessions to <dir>/sessions/<sessionId>.jsonl (session format version
54
+ ${SESSION_FORMAT_VERSION}, the format \`${APP_NAME} --import\` reads) and workflow runs to
55
+ <dir>/workflows/<runId>.jsonl (workflow run export version ${WORKFLOW_RUN_EXPORT_VERSION}), one file per
56
+ session or run. Both kinds by default; --sessions or --workflows limits it to one. Each
57
+ file is replaced whole, one that already holds the same bytes is not rewritten, and no
58
+ file is deleted. A kind kept in a shared libSQL / Turso database is skipped (an error
59
+ when --sessions or --workflows asks for it): every machine joined to it reads it already.
60
+ import Restore the sessions in <dir>/sessions and the workflow runs in <dir>/workflows into
61
+ this directory's storage; other files are ignored. Every file of both kinds is checked
62
+ first, so a malformed or unsupported file changes nothing. Importing again adds
63
+ nothing; a newer export of a session or run adds its later entries. Imported runs are
64
+ not owned by any process: an interrupted one can be resumed here. If the import fails
65
+ after writing part of it, it names what was and was not written; run it again to finish.
52
66
 
53
67
  Options:
54
68
  --json Print the status as JSON
@@ -56,9 +70,14 @@ Options:
56
70
  surrounding whitespace is removed. Required except for file: URLs
57
71
  --prefix <prefix> Table prefix, to share one database between projects or teams
58
72
  --no-discover adopt: register only the given paths
59
- --run <id> export: only this run; repeat for more
60
- --unfinished export: only runs that are not completed, failed or cancelled
61
- --limit <n> export: at most n runs, newest first`;
73
+ --sessions export, import: sessions only (with --workflows too: both)
74
+ --workflows export, import: workflow runs only (with --sessions too: both)
75
+ --run <id> export: only this workflow run; repeat for more
76
+ --unfinished export: only workflow runs that are not completed, failed or cancelled
77
+ --limit <n> export: at most n workflow runs, newest first, and at most n sessions,
78
+ most recently modified first
79
+ --since <time> export: only sessions modified at or after <time>, a date such as
80
+ 2026-11-01 or a date and time such as 2026-11-01T09:30:00Z`;
62
81
  const HELP_HINT = `Use "${APP_NAME} storage --help" for usage.`;
63
82
  export class StorageCommandError extends Error {
64
83
  }
@@ -73,6 +92,8 @@ export function parseStorageCommand(args) {
73
92
  let json = false;
74
93
  let discover = true;
75
94
  let unfinished = false;
95
+ let sessions = false;
96
+ let workflows = false;
76
97
  const runs = [];
77
98
  for (let index = 0; index < rest.length; index++) {
78
99
  const arg = rest[index];
@@ -84,6 +105,13 @@ export function parseStorageCommand(args) {
84
105
  discover = false;
85
106
  continue;
86
107
  }
108
+ if ((command === "export" || command === "import") && (arg === "--sessions" || arg === "--workflows")) {
109
+ if (arg === "--sessions")
110
+ sessions = true;
111
+ else
112
+ workflows = true;
113
+ continue;
114
+ }
87
115
  if (command === "export" && arg === "--unfinished") {
88
116
  unfinished = true;
89
117
  continue;
@@ -96,7 +124,7 @@ export function parseStorageCommand(args) {
96
124
  continue;
97
125
  }
98
126
  if ((command === "join" && (arg === "--token-file" || arg === "--prefix")) ||
99
- (command === "export" && arg === "--limit")) {
127
+ (command === "export" && (arg === "--limit" || arg === "--since"))) {
100
128
  const value = rest[++index];
101
129
  if (value === undefined)
102
130
  throw new StorageCommandError(`${arg} needs a value.`);
@@ -139,27 +167,40 @@ export function parseStorageCommand(args) {
139
167
  throw new StorageCommandError(`Usage: ${APP_NAME} storage consolidate`);
140
168
  return { kind: "consolidate" };
141
169
  }
170
+ const kinds = sessions || workflows
171
+ ? { sessions, workflows, explicit: true }
172
+ : { sessions: true, workflows: true, explicit: false };
142
173
  if (command === "export") {
143
174
  const [directory, ...extra] = positional;
144
175
  if (directory === undefined || extra.length > 0)
145
- throw new StorageCommandError(`Usage: ${APP_NAME} storage export <dir> [--run <id>]... [--unfinished] [--limit <n>]`);
176
+ throw new StorageCommandError(`Usage: ${APP_NAME} storage export <dir> [--sessions] [--workflows] [--run <id>]... [--unfinished] [--limit <n>] [--since <time>]`);
146
177
  const limitText = values.get("--limit");
147
178
  const limit = limitText === undefined ? undefined : Number(limitText);
148
179
  if (limit !== undefined && (!/^[0-9]+$/.test(limitText) || !Number.isSafeInteger(limit) || limit < 1))
149
180
  throw new StorageCommandError(`--limit needs a positive whole number, not "${limitText}".`);
181
+ const sinceText = values.get("--since");
182
+ const since = sinceText === undefined ? undefined : Date.parse(sinceText);
183
+ if (since !== undefined && Number.isNaN(since))
184
+ throw new StorageCommandError(`--since needs a date such as 2026-11-01 or a date and time such as 2026-11-01T09:30:00Z, not "${sinceText}".`);
185
+ if (!kinds.workflows && (runs.length > 0 || unfinished))
186
+ throw new StorageCommandError(`${runs.length > 0 ? "--run" : "--unfinished"} selects workflow runs, which --sessions alone does not export.`);
187
+ if (!kinds.sessions && since !== undefined)
188
+ throw new StorageCommandError("--since selects sessions, which --workflows alone does not export.");
150
189
  return {
151
190
  kind: "export",
152
191
  directory,
192
+ kinds,
153
193
  unfinished,
154
194
  ...(runs.length === 0 ? {} : { runs }),
155
195
  ...(limit === undefined ? {} : { limit }),
196
+ ...(since === undefined ? {} : { since }),
156
197
  };
157
198
  }
158
199
  if (command === "import") {
159
200
  const [directory, ...extra] = positional;
160
201
  if (directory === undefined || extra.length > 0)
161
- throw new StorageCommandError(`Usage: ${APP_NAME} storage import <dir>`);
162
- return { kind: "import", directory };
202
+ throw new StorageCommandError(`Usage: ${APP_NAME} storage import <dir> [--sessions] [--workflows]`);
203
+ return { kind: "import", directory, kinds };
163
204
  }
164
205
  throw new StorageCommandError(`Unknown storage command "${command}".\n${HELP_HINT}`);
165
206
  }
@@ -331,7 +372,7 @@ export async function runStorageCommand(args, options) {
331
372
  if (command.kind === "export")
332
373
  return await exportRuns(command, options, log, error);
333
374
  if (command.kind === "import")
334
- return await importRuns(command, options, log);
375
+ return await importRuns(command, options, log, error);
335
376
  return await joinStorage(command, options, (...lines) => {
336
377
  for (const line of lines)
337
378
  log(line);
@@ -345,7 +386,7 @@ export async function runStorageCommand(args, options) {
345
386
  return 1;
346
387
  }
347
388
  error(caught instanceof StorageCommandError ||
348
- isWorkflowRunTransferError(caught) ||
389
+ isStorageTransferError(caught) ||
349
390
  isTeamProfileError(caught) ||
350
391
  isTeamProfileConfigError(caught)
351
392
  ? caught.message
@@ -403,41 +444,163 @@ async function consolidate(options, log) {
403
444
  * The local workflow journal this directory's runs use, which `export` and `import` read and write. A shared database
404
445
  * is refused: every machine joined to it already reads its runs, so there is nothing to carry between them.
405
446
  */
406
- function transferStorage(options, command) {
447
+ function workflowTransfer(options, command) {
407
448
  const selection = effectiveJournalSelection(options.cwd, options.agentDir);
408
449
  if (selection.kind === "sharded")
409
- return { kind: "store", directory: selection.dir };
450
+ return { target: { kind: "store", directory: selection.dir } };
410
451
  if (selection.kind === "sqlite" && selection.path !== ":memory:")
411
452
  return {
412
- kind: "sqlite",
413
- path: resolve(options.cwd, selection.path),
414
- ...(selection.prefix === undefined ? {} : { prefix: selection.prefix }),
453
+ target: {
454
+ kind: "sqlite",
455
+ path: resolve(options.cwd, selection.path),
456
+ ...(selection.prefix === undefined ? {} : { prefix: selection.prefix }),
457
+ },
415
458
  };
416
- throw new StorageCommandError(`${APP_NAME} storage ${command} works with a local workflow journal (the journal store or a SQLite file), but workflow runs here use ${describeStorageSelection(selection)}.` +
417
- (selection.kind === "adapter"
418
- ? " A shared database already holds the runs of every machine joined to it, so there is nothing to export or import; use its own backups instead."
419
- : ""));
459
+ return {
460
+ refused: `${APP_NAME} storage ${command} works with a local workflow journal (the journal store or a SQLite file), but workflow runs here use ${describeStorageSelection(selection)}.` +
461
+ (selection.kind === "adapter"
462
+ ? " A shared database already holds the runs of every machine joined to it, so there is nothing to export or import; use its own backups instead."
463
+ : ""),
464
+ };
465
+ }
466
+ /**
467
+ * The session storage this directory selects, as a session started here would open it: the default database, a JSONL
468
+ * directory, a SQLite file or an adapter. A shared libSQL / Turso database is refused as it is for workflow runs, and so
469
+ * is in-memory storage, which keeps nothing. Undefined target for an export when nothing has been stored yet, so an
470
+ * export creates no database.
471
+ */
472
+ async function sessionTransfer(options, command) {
473
+ const settings = SettingsManager.create(options.cwd, options.agentDir, {
474
+ projectTrusted: projectTrust(options.cwd, options.agentDir),
475
+ }).getSettings();
476
+ const storageOptions = { agentDir: options.agentDir, settings };
477
+ const selection = selectSessionStorage(options.cwd, storageOptions);
478
+ if (!("load" in selection)) {
479
+ if (selection.kind === "memory" || (selection.kind === "sqlite" && selection.path === ":memory:"))
480
+ return {
481
+ refused: `${APP_NAME} storage ${command} needs stored sessions, but sessions here use ${describeStorageSelection(selection)}, which keeps nothing.`,
482
+ };
483
+ if (selection.kind === "adapter" && selection.module === LIBSQL_ADAPTER_PACKAGE)
484
+ return {
485
+ refused: `${APP_NAME} storage ${command} works with local session storage, but sessions here use ${describeStorageSelection(selection)}. A shared database already holds the sessions of every machine joined to it, so there is nothing to export or import; use its own backups instead.`,
486
+ };
487
+ if (command === "export") {
488
+ const stored = selection.kind === "jsonl"
489
+ ? existsSync(selection.dir)
490
+ : selection.kind !== "sqlite" ||
491
+ existsSync(resolve(options.cwd, selection.path)) ||
492
+ existsSync(join(options.agentDir, "sessions"));
493
+ if (!stored)
494
+ return { target: undefined };
495
+ }
496
+ }
497
+ return { target: await resolveSessionStore(options.cwd, storageOptions) };
420
498
  }
499
+ const plural = (count, noun) => `${count} ${noun}${count === 1 ? "" : "s"}`;
421
500
  async function exportRuns(command, options, log, error) {
422
- const storage = transferStorage(options, "export");
423
501
  const directory = resolve(options.cwd, command.directory);
424
- const report = await exportWorkflowRuns(storage, directory, {
425
- unfinished: command.unfinished,
426
- ...(command.runs === undefined ? {} : { runs: command.runs }),
427
- ...(command.limit === undefined ? {} : { limit: command.limit }),
428
- });
429
- const total = report.written.length + report.unchanged.length;
430
- log(`Exported ${total} workflow run${total === 1 ? "" : "s"} to ${directory} (${report.written.length} written, ${report.unchanged.length} unchanged).`);
431
- for (const skipped of report.skipped)
432
- error(`Skipped ${skipped.runId === undefined ? skipped.path : `run ${skipped.runId}`}: ${skipped.reason}.`);
433
- return 0;
502
+ const workflows = command.kinds.workflows ? workflowTransfer(options, "export") : undefined;
503
+ const sessions = command.kinds.sessions ? await sessionTransfer(options, "export") : undefined;
504
+ try {
505
+ const refusals = [workflows, sessions].flatMap((transfer) => transfer !== undefined && "refused" in transfer ? [transfer.refused] : []);
506
+ const kinds = Number(command.kinds.sessions) + Number(command.kinds.workflows);
507
+ if (refusals.length > 0 && (command.kinds.explicit || refusals.length === kinds))
508
+ throw new StorageCommandError(refusals.join("\n"));
509
+ for (const refused of refusals)
510
+ error(`Skipped: ${refused}`);
511
+ // Workflow runs first: an unknown --run fails the export before any file of either kind is written.
512
+ if (workflows !== undefined && "target" in workflows) {
513
+ const target = workflowsTransferDirectory(directory);
514
+ const report = await exportWorkflowRuns(workflows.target, target, {
515
+ unfinished: command.unfinished,
516
+ ...(command.runs === undefined ? {} : { runs: command.runs }),
517
+ ...(command.limit === undefined ? {} : { limit: command.limit }),
518
+ });
519
+ const total = report.written.length + report.unchanged.length;
520
+ log(`Exported ${plural(total, "workflow run")} to ${target} (${report.written.length} written, ${report.unchanged.length} unchanged).`);
521
+ for (const skipped of report.skipped)
522
+ error(`Skipped ${skipped.runId === undefined ? skipped.path : `run ${skipped.runId} (${skipped.path})`}: ${skipped.reason}.`);
523
+ }
524
+ if (sessions !== undefined && "target" in sessions) {
525
+ const target = sessionsTransferDirectory(directory);
526
+ const report = sessions.target === undefined
527
+ ? { written: [], unchanged: [] }
528
+ : await exportSessions(sessions.target, target, {
529
+ ...(command.limit === undefined ? {} : { limit: command.limit }),
530
+ ...(command.since === undefined ? {} : { since: command.since }),
531
+ });
532
+ const total = report.written.length + report.unchanged.length;
533
+ log(`Exported ${plural(total, "session")} to ${target} (${report.written.length} written, ${report.unchanged.length} unchanged).`);
534
+ }
535
+ return 0;
536
+ }
537
+ finally {
538
+ await sessionStore(sessions)?.close();
539
+ }
540
+ }
541
+ function describeIds(ids) {
542
+ const parts = [
543
+ ids.sessions.length === 0
544
+ ? undefined
545
+ : `${ids.sessions.length === 1 ? "session" : "sessions"} ${ids.sessions.join(", ")}`,
546
+ ids.workflows.length === 0
547
+ ? undefined
548
+ : `${ids.workflows.length === 1 ? "workflow run" : "workflow runs"} ${ids.workflows.join(", ")}`,
549
+ ].filter((part) => part !== undefined);
550
+ return parts.length === 0 ? "nothing" : parts.join("; ");
434
551
  }
435
- async function importRuns(command, options, log) {
436
- const storage = transferStorage(options, "import");
552
+ async function importRuns(command, options, log, error) {
437
553
  const directory = resolve(options.cwd, command.directory);
438
- const report = await importWorkflowRuns(storage, directory);
439
- const total = report.added.length + report.updated.length + report.unchanged.length;
440
- log(`Imported ${total} workflow run${total === 1 ? "" : "s"} from ${directory} (${report.added.length} added, ${report.updated.length} updated, ${report.unchanged.length} already up to date).`);
441
- return 0;
554
+ if (!existsSync(directory))
555
+ throw new StorageCommandError(`${directory}: no such directory.`);
556
+ const workflows = command.kinds.workflows ? workflowTransfer(options, "import") : undefined;
557
+ const sessions = command.kinds.sessions ? await sessionTransfer(options, "import") : undefined;
558
+ try {
559
+ const refusals = [workflows, sessions].flatMap((transfer) => transfer !== undefined && "refused" in transfer ? [transfer.refused] : []);
560
+ const kinds = Number(command.kinds.sessions) + Number(command.kinds.workflows);
561
+ if (refusals.length > 0 && (command.kinds.explicit || refusals.length === kinds))
562
+ throw new StorageCommandError(refusals.join("\n"));
563
+ for (const refused of refusals)
564
+ error(`Skipped: ${refused}`);
565
+ const sessionTarget = sessionStore(sessions);
566
+ const workflowStorage = workflows !== undefined && "target" in workflows ? workflows.target : undefined;
567
+ let report;
568
+ try {
569
+ report = await importStorage(directory, {
570
+ ...(sessionTarget === undefined ? {} : { sessions: sessionTarget }),
571
+ ...(workflowStorage === undefined ? {} : { workflows: workflowStorage }),
572
+ });
573
+ }
574
+ catch (caught) {
575
+ if (isStorageImportIncompleteError(caught)) {
576
+ error(caught.message);
577
+ error(`Imported before the failure: ${describeIds(caught.written)}.`);
578
+ error(`Not imported: ${describeIds(caught.notWritten)}.`);
579
+ error("Run the same import again to finish: it imports only what is missing.");
580
+ return 1;
581
+ }
582
+ if (isStorageTransferError(caught)) {
583
+ error(caught.message);
584
+ error("Nothing was imported.");
585
+ return 1;
586
+ }
587
+ throw caught;
588
+ }
589
+ if (report.sessions !== undefined) {
590
+ const { added, updated, unchanged } = report.sessions;
591
+ log(`Imported ${plural(added.length + updated.length + unchanged.length, "session")} from ${sessionsTransferDirectory(directory)} (${added.length} added, ${updated.length} updated, ${unchanged.length} already up to date).`);
592
+ }
593
+ if (report.workflows !== undefined) {
594
+ const { added, updated, unchanged } = report.workflows;
595
+ log(`Imported ${plural(added.length + updated.length + unchanged.length, "workflow run")} from ${workflowsTransferDirectory(directory)} (${added.length} added, ${updated.length} updated, ${unchanged.length} already up to date).`);
596
+ }
597
+ return 0;
598
+ }
599
+ finally {
600
+ await sessionStore(sessions)?.close();
601
+ }
602
+ }
603
+ function sessionStore(transfer) {
604
+ return transfer !== undefined && "target" in transfer ? transfer.target : undefined;
442
605
  }
443
606
  //# sourceMappingURL=storage-command.js.map