@bastani/atomic 0.9.38-alpha.7 → 0.9.38-alpha.8

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 (38) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/builtin/intercom/package.json +1 -1
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  5. package/dist/builtin/subagents/README.md +9 -4
  6. package/dist/builtin/subagents/package.json +1 -1
  7. package/dist/builtin/subagents/src/extension/index.bundle.mjs +23 -13
  8. package/dist/builtin/web-access/package.json +1 -1
  9. package/dist/builtin/workflows/CHANGELOG.md +6 -0
  10. package/dist/builtin/workflows/package.json +1 -1
  11. package/dist/builtin/workflows/src/durable/journal/legacy-journal-tables.d.ts +42 -0
  12. package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +3 -0
  13. package/dist/builtin/workflows/src/extension/index.bundle.mjs +204 -51
  14. package/dist/builtin/workflows/src/index.js +170 -17
  15. package/dist/core/session-manager-storage.d.ts +1 -1
  16. package/dist/core/session-manager-storage.d.ts.map +1 -1
  17. package/dist/core/session-manager-storage.js +2 -3
  18. package/dist/core/session-manager-storage.js.map +1 -1
  19. package/dist/core/session-storage.d.ts.map +1 -1
  20. package/dist/core/session-storage.js +20 -4
  21. package/dist/core/session-storage.js.map +1 -1
  22. package/dist/core/storage/session/jsonl-session-store.d.ts +7 -1
  23. package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -1
  24. package/dist/core/storage/session/jsonl-session-store.js +29 -20
  25. package/dist/core/storage/session/jsonl-session-store.js.map +1 -1
  26. package/dist/core/storage/session/legacy-format.d.ts +2 -0
  27. package/dist/core/storage/session/legacy-format.d.ts.map +1 -1
  28. package/dist/core/storage/session/legacy-format.js +55 -29
  29. package/dist/core/storage/session/legacy-format.js.map +1 -1
  30. package/dist/core/storage/session/legacy-session-store.d.ts +60 -0
  31. package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -0
  32. package/dist/core/storage/session/legacy-session-store.js +225 -0
  33. package/dist/core/storage/session/legacy-session-store.js.map +1 -0
  34. package/docs/session-format.md +1 -1
  35. package/docs/sessions.md +4 -2
  36. package/docs/subagents.md +19 -6
  37. package/npm-shrinkwrap.json +32 -32
  38. package/package.json +3 -3
@@ -0,0 +1,225 @@
1
+ import { existsSync } from "node:fs";
2
+ import { stat } from "node:fs/promises";
3
+ import { createSessionCwdMatcher } from "../../../utils/canonical-path.js";
4
+ import { openNodeSqliteDatabase } from "../node-sqlite.js";
5
+ import { SessionExistsError, SessionNotFoundError } from "./errors.js";
6
+ import { JsonlSessionStore } from "./jsonl-session-store.js";
7
+ import { summarizeSession } from "./session-summary.js";
8
+ const DELETED_TABLE = "session_legacy_deleted";
9
+ /**
10
+ * The default session store, plus the JSONL sessions saved before it existed.
11
+ *
12
+ * Sessions from before the SQLite default stay in `<agentDir>/sessions` and are
13
+ * listed from there, so `/resume` and `--continue` show them without any upfront
14
+ * work. A legacy session is converted into the database only when it is opened,
15
+ * following pi's migrate-on-load pattern; afterwards it is read from the database
16
+ * like any other session. The JSONL files are never modified. Deleting a session
17
+ * records its ID so a legacy copy of it is not listed again.
18
+ */
19
+ export class LegacySessionStore {
20
+ inner;
21
+ legacyDirectory;
22
+ databasePath;
23
+ legacy;
24
+ index;
25
+ summaries = new Map();
26
+ deletions;
27
+ constructor(inner, options) {
28
+ this.inner = inner;
29
+ this.legacyDirectory = options.legacyDirectory;
30
+ this.databasePath = options.databasePath;
31
+ }
32
+ get descriptor() {
33
+ return this.inner.descriptor;
34
+ }
35
+ create(header, entries) {
36
+ return this.inner.create(header, entries);
37
+ }
38
+ async append(sessionId, entries, options) {
39
+ await this.convert(sessionId);
40
+ return this.inner.append(sessionId, entries, options);
41
+ }
42
+ async replace(sessionId, header, entries, options) {
43
+ await this.convert(sessionId);
44
+ return this.inner.replace(sessionId, header, entries, options);
45
+ }
46
+ async load(sessionId) {
47
+ await this.convert(sessionId);
48
+ return this.inner.load(sessionId);
49
+ }
50
+ async readHeader(sessionId) {
51
+ const header = await this.inner.readHeader(sessionId);
52
+ if (header !== undefined)
53
+ return header;
54
+ return (await this.findLegacy(sessionId))?.header;
55
+ }
56
+ async delete(sessionId) {
57
+ const legacy = await this.findLegacy(sessionId);
58
+ if (legacy !== undefined)
59
+ await this.markDeleted(sessionId);
60
+ try {
61
+ await this.inner.delete(sessionId);
62
+ }
63
+ catch (error) {
64
+ if (!(error instanceof SessionNotFoundError) || legacy === undefined)
65
+ throw error;
66
+ }
67
+ }
68
+ async *list(query) {
69
+ const listed = new Set();
70
+ for await (const summary of this.inner.list(query)) {
71
+ listed.add(summary.id);
72
+ yield summary;
73
+ }
74
+ for await (const file of this.legacyFiles(query)) {
75
+ if (listed.has(file.header.id) || (await this.inner.readHeader(file.header.id)) !== undefined)
76
+ continue;
77
+ const summary = await this.summarize(file.header.id);
78
+ if (summary === undefined)
79
+ continue;
80
+ listed.add(summary.id);
81
+ yield summary;
82
+ }
83
+ }
84
+ async findMostRecent(query) {
85
+ let latest = await this.inner.findMostRecent(query);
86
+ for await (const file of this.legacyFiles(query)) {
87
+ if ((await this.inner.readHeader(file.header.id)) !== undefined)
88
+ continue;
89
+ const summary = await this.summarize(file.header.id);
90
+ if (summary !== undefined && (!latest || Date.parse(summary.modifiedAt) > Date.parse(latest.modifiedAt))) {
91
+ latest = summary;
92
+ }
93
+ }
94
+ return latest;
95
+ }
96
+ async close() {
97
+ const legacy = this.legacy;
98
+ const deletions = this.deletions;
99
+ this.legacy = undefined;
100
+ this.deletions = undefined;
101
+ this.index = undefined;
102
+ this.summaries.clear();
103
+ await Promise.all([
104
+ legacy?.then((store) => store?.close()).catch(() => { }),
105
+ deletions?.then((database) => database.close()).catch(() => { }),
106
+ ]);
107
+ await this.inner.close();
108
+ }
109
+ /** Convert one legacy session into the database the first time it is needed. */
110
+ async convert(sessionId) {
111
+ if ((await this.inner.readHeader(sessionId)) !== undefined)
112
+ return;
113
+ const snapshot = await this.readLegacy(sessionId);
114
+ if (snapshot === undefined)
115
+ return;
116
+ try {
117
+ await this.inner.create(snapshot.header, snapshot.entries);
118
+ }
119
+ catch (error) {
120
+ if (!(error instanceof SessionExistsError))
121
+ throw error;
122
+ }
123
+ if (await this.isDeleted(sessionId))
124
+ await this.inner.delete(sessionId).catch(() => { });
125
+ }
126
+ /** The first readable copy of a legacy session; a damaged duplicate does not hide a readable one. */
127
+ async readLegacy(sessionId) {
128
+ if (await this.isDeleted(sessionId))
129
+ return undefined;
130
+ for (const file of (await this.legacyIndex()).get(sessionId) ?? []) {
131
+ try {
132
+ const snapshot = await file.read();
133
+ summarizeSession(snapshot);
134
+ return snapshot;
135
+ }
136
+ catch {
137
+ // Try the next copy.
138
+ }
139
+ }
140
+ return undefined;
141
+ }
142
+ async findLegacy(sessionId) {
143
+ const file = (await this.legacyIndex()).get(sessionId)?.[0];
144
+ if (file === undefined || (await this.isDeleted(sessionId)))
145
+ return undefined;
146
+ return file;
147
+ }
148
+ async *legacyFiles(query) {
149
+ const matchesCwd = query.cwd === undefined ? undefined : createSessionCwdMatcher(query.cwd);
150
+ for (const [file] of (await this.legacyIndex()).values()) {
151
+ if (file === undefined)
152
+ continue;
153
+ if (matchesCwd && !matchesCwd(file.header.cwd))
154
+ continue;
155
+ if (!query.includeInternal && file.header.internal)
156
+ continue;
157
+ if (await this.isDeleted(file.header.id))
158
+ continue;
159
+ yield file;
160
+ }
161
+ }
162
+ /** Header-only index of the legacy directory, read once; nothing writes legacy sessions any more. */
163
+ legacyIndex() {
164
+ this.index ??= (async () => {
165
+ const files = new Map();
166
+ const legacy = await this.legacyStore();
167
+ if (legacy === undefined)
168
+ return files;
169
+ try {
170
+ for await (const file of legacy.scanFiles()) {
171
+ const copies = files.get(file.header.id);
172
+ if (copies)
173
+ copies.push(file);
174
+ else
175
+ files.set(file.header.id, [file]);
176
+ }
177
+ }
178
+ catch {
179
+ // An unreadable legacy directory leaves only the sessions already in the database.
180
+ }
181
+ return files;
182
+ })();
183
+ return this.index;
184
+ }
185
+ /** Summaries are cached per store until a copy of the session changes on disk. */
186
+ async summarize(sessionId) {
187
+ const stamp = await this.fileStamp(sessionId);
188
+ const cached = this.summaries.get(sessionId);
189
+ if (cached !== undefined && cached.stamp === stamp)
190
+ return cached.summary ?? undefined;
191
+ const snapshot = await this.readLegacy(sessionId);
192
+ const summary = snapshot === undefined ? null : summarizeSession(snapshot);
193
+ this.summaries.set(sessionId, { stamp, summary });
194
+ return summary ?? undefined;
195
+ }
196
+ async fileStamp(sessionId) {
197
+ const stamps = await Promise.all(((await this.legacyIndex()).get(sessionId) ?? []).map(async (file) => {
198
+ const stats = await stat(file.location).catch(() => undefined);
199
+ return stats === undefined ? "missing" : `${stats.size}:${stats.mtimeMs}`;
200
+ }));
201
+ return stamps.join("|");
202
+ }
203
+ legacyStore() {
204
+ this.legacy ??= existsSync(this.legacyDirectory)
205
+ ? JsonlSessionStore.open(this.legacyDirectory, { scanExisting: false }).catch(() => undefined)
206
+ : Promise.resolve(undefined);
207
+ return this.legacy;
208
+ }
209
+ deletionDatabase() {
210
+ this.deletions ??= openNodeSqliteDatabase(this.databasePath).then(async (database) => {
211
+ await database.exec(`CREATE TABLE IF NOT EXISTS ${DELETED_TABLE}(id TEXT PRIMARY KEY, deleted_at INTEGER NOT NULL)`);
212
+ return database;
213
+ });
214
+ return this.deletions;
215
+ }
216
+ async isDeleted(sessionId) {
217
+ const database = await this.deletionDatabase();
218
+ return (await database.get(`SELECT id FROM ${DELETED_TABLE} WHERE id = ?`, sessionId)) !== undefined;
219
+ }
220
+ async markDeleted(sessionId) {
221
+ const database = await this.deletionDatabase();
222
+ await database.run(`INSERT OR IGNORE INTO ${DELETED_TABLE} VALUES (?, ?)`, sessionId, Date.now());
223
+ }
224
+ }
225
+ //# sourceMappingURL=legacy-session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-session-store.js","sourceRoot":"","sources":["../../../../src/core/storage/session/legacy-session-store.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SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACnG,CAAC;CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { stat } from \"node:fs/promises\";\nimport { createSessionCwdMatcher } from \"../../../utils/canonical-path.ts\";\nimport type { SessionEntry } from \"../../session-manager-types.ts\";\nimport type { SqliteDatabase } from \"../database.js\";\nimport { openNodeSqliteDatabase } from \"../node-sqlite.js\";\nimport { SessionExistsError, SessionNotFoundError } from \"./errors.js\";\nimport { type JsonlSessionFile, JsonlSessionStore } from \"./jsonl-session-store.js\";\nimport { summarizeSession } from \"./session-summary.js\";\nimport type {\n\tSessionListQuery,\n\tSessionRecordHeader,\n\tSessionSnapshot,\n\tSessionStore,\n\tSessionSummary,\n\tSessionWriteOptions,\n\tStorageDescriptor,\n} from \"./types.js\";\n\nconst DELETED_TABLE = \"session_legacy_deleted\";\n\n/**\n * The default session store, plus the JSONL sessions saved before it existed.\n *\n * Sessions from before the SQLite default stay in `<agentDir>/sessions` and are\n * listed from there, so `/resume` and `--continue` show them without any upfront\n * work. A legacy session is converted into the database only when it is opened,\n * following pi's migrate-on-load pattern; afterwards it is read from the database\n * like any other session. The JSONL files are never modified. Deleting a session\n * records its ID so a legacy copy of it is not listed again.\n */\nexport class LegacySessionStore implements SessionStore {\n\tprivate readonly inner: SessionStore;\n\tprivate readonly legacyDirectory: string;\n\tprivate readonly databasePath: string;\n\tprivate legacy?: Promise<JsonlSessionStore | undefined>;\n\tprivate index?: Promise<ReadonlyMap<string, readonly JsonlSessionFile[]>>;\n\tprivate readonly summaries = new Map<string, { readonly stamp: string; readonly summary: SessionSummary | null }>();\n\tprivate deletions?: Promise<SqliteDatabase>;\n\n\tconstructor(inner: SessionStore, options: { readonly legacyDirectory: string; readonly databasePath: string }) {\n\t\tthis.inner = inner;\n\t\tthis.legacyDirectory = options.legacyDirectory;\n\t\tthis.databasePath = options.databasePath;\n\t}\n\n\tget descriptor(): StorageDescriptor {\n\t\treturn this.inner.descriptor;\n\t}\n\n\tcreate(header: SessionRecordHeader, entries: readonly SessionEntry[]): Promise<{ readonly lastSeq: number }> {\n\t\treturn this.inner.create(header, entries);\n\t}\n\n\tasync append(\n\t\tsessionId: string,\n\t\tentries: readonly SessionEntry[],\n\t\toptions: SessionWriteOptions,\n\t): Promise<{ readonly lastSeq: number }> {\n\t\tawait this.convert(sessionId);\n\t\treturn this.inner.append(sessionId, entries, options);\n\t}\n\n\tasync replace(\n\t\tsessionId: string,\n\t\theader: SessionRecordHeader,\n\t\tentries: readonly SessionEntry[],\n\t\toptions: SessionWriteOptions,\n\t): Promise<{ readonly lastSeq: number }> {\n\t\tawait this.convert(sessionId);\n\t\treturn this.inner.replace(sessionId, header, entries, options);\n\t}\n\n\tasync load(sessionId: string): Promise<SessionSnapshot> {\n\t\tawait this.convert(sessionId);\n\t\treturn this.inner.load(sessionId);\n\t}\n\n\tasync readHeader(sessionId: string): Promise<SessionRecordHeader | undefined> {\n\t\tconst header = await this.inner.readHeader(sessionId);\n\t\tif (header !== undefined) return header;\n\t\treturn (await this.findLegacy(sessionId))?.header;\n\t}\n\n\tasync delete(sessionId: string): Promise<void> {\n\t\tconst legacy = await this.findLegacy(sessionId);\n\t\tif (legacy !== undefined) await this.markDeleted(sessionId);\n\t\ttry {\n\t\t\tawait this.inner.delete(sessionId);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof SessionNotFoundError) || legacy === undefined) throw error;\n\t\t}\n\t}\n\n\tasync *list(query: SessionListQuery): AsyncIterable<SessionSummary> {\n\t\tconst listed = new Set<string>();\n\t\tfor await (const summary of this.inner.list(query)) {\n\t\t\tlisted.add(summary.id);\n\t\t\tyield summary;\n\t\t}\n\t\tfor await (const file of this.legacyFiles(query)) {\n\t\t\tif (listed.has(file.header.id) || (await this.inner.readHeader(file.header.id)) !== undefined) continue;\n\t\t\tconst summary = await this.summarize(file.header.id);\n\t\t\tif (summary === undefined) continue;\n\t\t\tlisted.add(summary.id);\n\t\t\tyield summary;\n\t\t}\n\t}\n\n\tasync findMostRecent(query: {\n\t\treadonly cwd: string;\n\t\treadonly includeInternal?: boolean;\n\t}): Promise<SessionSummary | undefined> {\n\t\tlet latest = await this.inner.findMostRecent(query);\n\t\tfor await (const file of this.legacyFiles(query)) {\n\t\t\tif ((await this.inner.readHeader(file.header.id)) !== undefined) continue;\n\t\t\tconst summary = await this.summarize(file.header.id);\n\t\t\tif (summary !== undefined && (!latest || Date.parse(summary.modifiedAt) > Date.parse(latest.modifiedAt))) {\n\t\t\t\tlatest = summary;\n\t\t\t}\n\t\t}\n\t\treturn latest;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tconst legacy = this.legacy;\n\t\tconst deletions = this.deletions;\n\t\tthis.legacy = undefined;\n\t\tthis.deletions = undefined;\n\t\tthis.index = undefined;\n\t\tthis.summaries.clear();\n\t\tawait Promise.all([\n\t\t\tlegacy?.then((store) => store?.close()).catch(() => {}),\n\t\t\tdeletions?.then((database) => database.close()).catch(() => {}),\n\t\t]);\n\t\tawait this.inner.close();\n\t}\n\n\t/** Convert one legacy session into the database the first time it is needed. */\n\tprivate async convert(sessionId: string): Promise<void> {\n\t\tif ((await this.inner.readHeader(sessionId)) !== undefined) return;\n\t\tconst snapshot = await this.readLegacy(sessionId);\n\t\tif (snapshot === undefined) return;\n\t\ttry {\n\t\t\tawait this.inner.create(snapshot.header, snapshot.entries);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof SessionExistsError)) throw error;\n\t\t}\n\t\tif (await this.isDeleted(sessionId)) await this.inner.delete(sessionId).catch(() => {});\n\t}\n\n\t/** The first readable copy of a legacy session; a damaged duplicate does not hide a readable one. */\n\tprivate async readLegacy(sessionId: string): Promise<SessionSnapshot | undefined> {\n\t\tif (await this.isDeleted(sessionId)) return undefined;\n\t\tfor (const file of (await this.legacyIndex()).get(sessionId) ?? []) {\n\t\t\ttry {\n\t\t\t\tconst snapshot = await file.read();\n\t\t\t\tsummarizeSession(snapshot);\n\t\t\t\treturn snapshot;\n\t\t\t} catch {\n\t\t\t\t// Try the next copy.\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async findLegacy(sessionId: string): Promise<JsonlSessionFile | undefined> {\n\t\tconst file = (await this.legacyIndex()).get(sessionId)?.[0];\n\t\tif (file === undefined || (await this.isDeleted(sessionId))) return undefined;\n\t\treturn file;\n\t}\n\n\tprivate async *legacyFiles(query: {\n\t\treadonly cwd?: string;\n\t\treadonly includeInternal?: boolean;\n\t}): AsyncIterable<JsonlSessionFile> {\n\t\tconst matchesCwd = query.cwd === undefined ? undefined : createSessionCwdMatcher(query.cwd);\n\t\tfor (const [file] of (await this.legacyIndex()).values()) {\n\t\t\tif (file === undefined) continue;\n\t\t\tif (matchesCwd && !matchesCwd(file.header.cwd)) continue;\n\t\t\tif (!query.includeInternal && file.header.internal) continue;\n\t\t\tif (await this.isDeleted(file.header.id)) continue;\n\t\t\tyield file;\n\t\t}\n\t}\n\n\t/** Header-only index of the legacy directory, read once; nothing writes legacy sessions any more. */\n\tprivate legacyIndex(): Promise<ReadonlyMap<string, readonly JsonlSessionFile[]>> {\n\t\tthis.index ??= (async () => {\n\t\t\tconst files = new Map<string, JsonlSessionFile[]>();\n\t\t\tconst legacy = await this.legacyStore();\n\t\t\tif (legacy === undefined) return files;\n\t\t\ttry {\n\t\t\t\tfor await (const file of legacy.scanFiles()) {\n\t\t\t\t\tconst copies = files.get(file.header.id);\n\t\t\t\t\tif (copies) copies.push(file);\n\t\t\t\t\telse files.set(file.header.id, [file]);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// An unreadable legacy directory leaves only the sessions already in the database.\n\t\t\t}\n\t\t\treturn files;\n\t\t})();\n\t\treturn this.index;\n\t}\n\n\t/** Summaries are cached per store until a copy of the session changes on disk. */\n\tprivate async summarize(sessionId: string): Promise<SessionSummary | undefined> {\n\t\tconst stamp = await this.fileStamp(sessionId);\n\t\tconst cached = this.summaries.get(sessionId);\n\t\tif (cached !== undefined && cached.stamp === stamp) return cached.summary ?? undefined;\n\t\tconst snapshot = await this.readLegacy(sessionId);\n\t\tconst summary = snapshot === undefined ? null : summarizeSession(snapshot);\n\t\tthis.summaries.set(sessionId, { stamp, summary });\n\t\treturn summary ?? undefined;\n\t}\n\n\tprivate async fileStamp(sessionId: string): Promise<string> {\n\t\tconst stamps = await Promise.all(\n\t\t\t((await this.legacyIndex()).get(sessionId) ?? []).map(async (file) => {\n\t\t\t\tconst stats = await stat(file.location).catch(() => undefined);\n\t\t\t\treturn stats === undefined ? \"missing\" : `${stats.size}:${stats.mtimeMs}`;\n\t\t\t}),\n\t\t);\n\t\treturn stamps.join(\"|\");\n\t}\n\n\tprivate legacyStore(): Promise<JsonlSessionStore | undefined> {\n\t\tthis.legacy ??= existsSync(this.legacyDirectory)\n\t\t\t? JsonlSessionStore.open(this.legacyDirectory, { scanExisting: false }).catch(() => undefined)\n\t\t\t: Promise.resolve(undefined);\n\t\treturn this.legacy;\n\t}\n\n\tprivate deletionDatabase(): Promise<SqliteDatabase> {\n\t\tthis.deletions ??= openNodeSqliteDatabase(this.databasePath).then(async (database) => {\n\t\t\tawait database.exec(\n\t\t\t\t`CREATE TABLE IF NOT EXISTS ${DELETED_TABLE}(id TEXT PRIMARY KEY, deleted_at INTEGER NOT NULL)`,\n\t\t\t);\n\t\t\treturn database;\n\t\t});\n\t\treturn this.deletions;\n\t}\n\n\tprivate async isDeleted(sessionId: string): Promise<boolean> {\n\t\tconst database = await this.deletionDatabase();\n\t\treturn (await database.get(`SELECT id FROM ${DELETED_TABLE} WHERE id = ?`, sessionId)) !== undefined;\n\t}\n\n\tprivate async markDeleted(sessionId: string): Promise<void> {\n\t\tconst database = await this.deletionDatabase();\n\t\tawait database.run(`INSERT OR IGNORE INTO ${DELETED_TABLE} VALUES (?, ?)`, sessionId, Date.now());\n\t}\n}\n"]}
@@ -18,7 +18,7 @@ Delete individual sessions from `/resume`: select a session, press `CTRL+D`, the
18
18
 
19
19
  ## Session Version
20
20
 
21
- SessionManager writes version 4 headers. Sessions in formats 1, 2, and 3 are upgraded automatically when opened, resumed, imported, or forked. Reading converts older records in memory; listing sessions and looking up headers leave files unchanged. Opening an older JSONL session persists its upgrade atomically under the file lock before new entries are saved. Future versions, unrecognized version values, and structurally invalid entries remain rejected; unloadable sessions are omitted from resume listings. A complete final record without a newline is accepted; a torn final record is rejected.
21
+ SessionManager writes version 4 headers with `createdAt` and `parentSessionId`. Sessions in formats 1, 2, and 3, and early version-4 files whose header has `timestamp` and `parentSession` instead, are upgraded automatically when opened, resumed, imported, or forked. Reading converts older records in memory; listing sessions and looking up headers leave files unchanged. Opening an older JSONL session persists its upgrade atomically under the file lock before new entries are saved. Future versions, unrecognized version values, and structurally invalid entries remain rejected; unloadable sessions are omitted from resume listings. A complete final record without a newline is accepted; a torn final record is rejected.
22
22
 
23
23
  ## Source Files
24
24
 
package/docs/sessions.md CHANGED
@@ -12,6 +12,8 @@ Sessions auto-save to the local SQLite database at `~/.atomic/workflows/journal.
12
12
 
13
13
  To choose another store, set `sessions.storage` in settings. Use shared `storage` to select one database for both sessions and workflow runs. JSONL is available only when explicitly selected. Memory is available through `--no-session`, `{ "memory": true }` in settings, or an explicit SDK option; it is never a fallback for a failed persistent store.
14
14
 
15
+ When the default SQLite store is selected, sessions saved before it became the default stay in `~/.atomic/agent/sessions` and appear in `/resume` and `--continue` next to newer ones. This includes sessions in formats 1, 2, and 3 and early 0.9.38 alpha sessions. A session is copied into the database the first time you open it, with `/resume`, `--continue`, `--session`, or `--fork`, and is read from the database afterwards. The original files are never modified or deleted, unreadable files are skipped, and workflow stage sessions stay hidden from `/resume` but remain openable by session ID. Deleting one of these sessions keeps it out of the list. Selecting a store yourself, as described below, shows only that store.
16
+
15
17
  Project-local storage settings apply after you approve project trust, including on the first launch. Atomic re-selects storage before saving a new conversation; resumed conversations stay in their original store. Generated resume commands for JSONL sessions include `--session-dir`; keep that option when reopening the conversation, even if the directory was previously the default.
16
18
 
17
19
  For SQLite, resume with `atomic --session-store "/data/project A/sessions.sqlite" --session-prefix project_ --session <id>`.
@@ -44,7 +46,7 @@ Imported IDs are kept verbatim, including an empty ID. Resume an imported empty
44
46
 
45
47
  This selects JSONL under `~/.atomic/sessions`. Use `{ "path": "sessions.sqlite" }` for another local SQLite file, `{ "memory": true }` for ephemeral sessions, or an adapter selection for a user-installed database driver. The `sessionDir` setting has been removed without an alias.
46
48
 
47
- Precedence is SDK `sessionStore`, `--no-session`, `--session-dir <dir>` or `--session-store <path>` (mutually exclusive CLI selections), non-empty `ATOMIC_CODING_AGENT_SESSION_DIR`, `sessions.storage`, shared `storage`, then the default SQLite file. Each selection wins as a whole; project selections replace global ones rather than merging fields. Relative settings paths resolve against Atomic home; CLI paths and environment directories resolve against the working directory. Changing stores selects a different history without migrating sessions; keep the original store to return to it.
49
+ Precedence is SDK `sessionStore`, `--no-session`, `--session-dir <dir>` or `--session-store <path>` (mutually exclusive CLI selections), non-empty `ATOMIC_CODING_AGENT_SESSION_DIR`, `sessions.storage`, shared `storage`, then the default SQLite file. Each selection wins as a whole; project selections replace global ones rather than merging fields. Relative settings paths resolve against Atomic home; CLI paths and environment directories resolve against the working directory. Changing stores selects a different history, and only the default store shows earlier JSONL sessions; keep the original store to return to it.
48
50
 
49
51
  `--session-store` cannot be combined with `--session-dir` or `--no-session`. `--session-prefix` requires `--session-store` and defaults to empty, giving `session_` table names. A non-empty prefix is prepended to those names, must match `[A-Za-z_][A-Za-z0-9_]*`, and must not start with `sqlite_` (case-insensitive). Invalid configuration or unavailable storage raises a typed error, never a fallback to another store.
50
52
 
@@ -85,7 +87,7 @@ For the JSONL file format and SessionManager API, see [Session Format](/session-
85
87
 
86
88
  `/resume` opens an interactive session picker for the current project. `atomic -r` opens the same picker at startup.
87
89
 
88
- Sessions written in formats 1, 2, and 3 appear in the picker and upgrade automatically to format 4 when opened, including with `--continue`, `--session`, or `--fork`. Browsing the picker does not change session files. Opening an older session rewrites only that file; no flag or confirmation is needed.
90
+ Sessions written in formats 1, 2, and 3, and early 0.9.38 alpha sessions whose header uses `timestamp`, appear in the picker and upgrade automatically to format 4. In the default store this happens when you first open one. In an explicit JSONL store it happens when you open them, including with `--continue`, `--session`, or `--fork`; browsing the picker does not change session files, and opening an older session rewrites only that file. No flag or confirmation is needed.
89
91
 
90
92
  Resuming restores saved verbatim compaction without another planning request. Older sessions with retired logical-deletion compaction can bring previously hidden content back into context.
91
93
 
package/docs/subagents.md CHANGED
@@ -245,16 +245,29 @@ Observation yields do not release these worktrees. Cancelling a queued child bef
245
245
 
246
246
  Fresh children inherit the invoking session's SDK configuration, resource-discovery inputs, model/auth runtime and host callbacks. Child tool selections can narrow the parent's permissions but cannot restore disabled packages or excluded tools. Intercom has no mandatory bypass; a child without access receives no supervisor grant. Model fallback keeps the same inherited restrictions. See [SDK child configuration](/sdk#workflow-and-subagent-children).
247
247
 
248
- Top-level parallel calls support up to 50 subagents after expanding each task's optional `count`. Two settings control the set:
249
-
250
- - `parallel.maxTasks` defaults to 50 and can enforce a lower task limit.
251
- - `parallel.concurrency` defaults to 3 and controls how many children run at once. Explicit configuration overrides the default; per-call `concurrency` takes precedence over configuration.
248
+ Top-level parallel calls apply these settings from `~/.atomic/agent/extensions/subagent/config.json` after expanding each task's optional `count`:
249
+
250
+ - `parallel.maxTasks` defaults to 50 and limits the number of tasks in a parallel set. There is no hard upper cap; raise or lower it as needed.
251
+ - `parallel.concurrency` defaults to 3 and limits how many children are dispatched at once. Per-call `concurrency` takes precedence.
252
+ - `parallel.runningCapacity` defaults to 4 and limits simultaneously running child turns per parent.
253
+
254
+ To run up to 100 children at once, raise both concurrency and running capacity as well as the task limit:
255
+
256
+ ```json
257
+ {
258
+ "parallel": {
259
+ "maxTasks": 100,
260
+ "concurrency": 100,
261
+ "runningCapacity": 100
262
+ }
263
+ }
264
+ ```
252
265
 
253
- At most four turns per parent can run at once, even when a higher subagent concurrency is configured.
266
+ Running capacity is selected when a parent's first child is created. Restart Atomic after changing this setting to apply the new capacity.
254
267
 
255
268
  When one assistant response emits several sibling execution-mode `subagent` tool calls, Atomic collects that synchronous burst before starting a child and runs it as one indexed parallel set. Each original tool call still receives one result containing only the children it requested, and its live result, progress, control, and artifact updates are projected to that same route without sibling data. The TUI redraws the shared run as one aggregate parallel widget rather than retaining one widget per original call. A single call keeps its original SINGLE or PARALLEL mode, calls awaited in sequence remain separate runs, and management actions bypass collection. An execution call that arrives after a child has started still receives the existing in-progress rejection. Prefer one explicit `{ tasks: [...] }` call when planning parallel work; burst collection handles sibling calls emitted by a model.
256
269
 
257
- For a collected burst, each call contributes its top-level `agent` task first and then its `tasks` entries in array order. Atomic preserves duplicates, expands `count` in place, and applies the configured task cap after flattening and expansion; the hard maximum remains 50. Each call-level `cwd` selects that call's agent-discovery scope and child base directory. A task-level `cwd` stays relative to that call base and changes only that child's execution directory, not agent discovery. This per-origin discovery rule applies only to collected sibling calls; an ordinary explicit `{ tasks: [...] }` call keeps one discovery scope from its top-level `cwd`. Per-call and per-task `group` values also stay with their originating children. Shared run options must match across every sibling call: `concurrency`, `worktree`, `context`, `share`, `control`, `sessionDir`, `maxOutput`, `artifacts`, `includeProgress`, and `agentScope`. A mismatch rejects the whole burst before any child launches and names the incompatible field.
270
+ For a collected burst, each call contributes its top-level `agent` task first and then its `tasks` entries in array order. Atomic preserves duplicates, expands `count` in place, and applies `parallel.maxTasks` after flattening and expansion. Each call-level `cwd` selects that call's agent-discovery scope and child base directory. A task-level `cwd` stays relative to that call base and changes only that child's execution directory, not agent discovery. This per-origin discovery rule applies only to collected sibling calls; an ordinary explicit `{ tasks: [...] }` call keeps one discovery scope from its top-level `cwd`. Per-call and per-task `group` values also stay with their originating children. Shared run options must match across every sibling call: `concurrency`, `worktree`, `context`, `share`, `control`, `sessionDir`, `maxOutput`, `artifacts`, `includeProgress`, and `agentScope`. A mismatch rejects the whole burst before any child launches and names the incompatible field.
258
271
 
259
272
  For a collected `worktree: true` burst, every call-level `cwd` must resolve to the same path. That common path becomes the shared worktree root; differing origins reject the burst before launch, and any task-level `cwd` must still resolve to that root. Each projected caller result keeps shared worktree diff text and terminal control guidance while its child results and standard child-output sections remain route-local.
260
273
 
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.9.38-alpha.7",
3
+ "version": "0.9.38-alpha.8",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@bastani/atomic",
9
- "version": "0.9.38-alpha.7",
9
+ "version": "0.9.38-alpha.8",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
- "@bastani/atomic-natives": "0.9.38-alpha.7",
13
- "@bastani/pi-ai": "0.9.38-alpha.7",
12
+ "@bastani/atomic-natives": "0.9.38-alpha.8",
13
+ "@bastani/pi-ai": "0.9.38-alpha.8",
14
14
  "@earendil-works/pi-agent-core": "1.3.0",
15
15
  "@earendil-works/pi-codemode": "1.3.0",
16
16
  "@earendil-works/pi-tui": "1.3.0",
@@ -427,18 +427,18 @@
427
427
  }
428
428
  },
429
429
  "node_modules/@bastani/atomic-natives": {
430
- "version": "0.9.38-alpha.7",
431
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives/-/atomic-natives-0.9.38-alpha.7.tgz",
430
+ "version": "0.9.38-alpha.8",
431
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives/-/atomic-natives-0.9.38-alpha.8.tgz",
432
432
  "license": "MIT",
433
433
  "optionalDependencies": {
434
- "@bastani/atomic-natives-darwin-arm64": "0.9.38-alpha.7",
435
- "@bastani/atomic-natives-darwin-x64": "0.9.38-alpha.7",
436
- "@bastani/atomic-natives-linux-arm64-gnu": "0.9.38-alpha.7",
437
- "@bastani/atomic-natives-linux-arm64-musl": "0.9.38-alpha.7",
438
- "@bastani/atomic-natives-linux-x64-gnu": "0.9.38-alpha.7",
439
- "@bastani/atomic-natives-linux-x64-musl": "0.9.38-alpha.7",
440
- "@bastani/atomic-natives-win32-arm64-msvc": "0.9.38-alpha.7",
441
- "@bastani/atomic-natives-win32-x64-msvc": "0.9.38-alpha.7"
434
+ "@bastani/atomic-natives-darwin-arm64": "0.9.38-alpha.8",
435
+ "@bastani/atomic-natives-darwin-x64": "0.9.38-alpha.8",
436
+ "@bastani/atomic-natives-linux-arm64-gnu": "0.9.38-alpha.8",
437
+ "@bastani/atomic-natives-linux-arm64-musl": "0.9.38-alpha.8",
438
+ "@bastani/atomic-natives-linux-x64-gnu": "0.9.38-alpha.8",
439
+ "@bastani/atomic-natives-linux-x64-musl": "0.9.38-alpha.8",
440
+ "@bastani/atomic-natives-win32-arm64-msvc": "0.9.38-alpha.8",
441
+ "@bastani/atomic-natives-win32-x64-msvc": "0.9.38-alpha.8"
442
442
  },
443
443
  "engines": {
444
444
  "bun": ">=1.4.2",
@@ -446,8 +446,8 @@
446
446
  }
447
447
  },
448
448
  "node_modules/@bastani/atomic-natives-darwin-arm64": {
449
- "version": "0.9.38-alpha.7",
450
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-arm64/-/atomic-natives-darwin-arm64-0.9.38-alpha.7.tgz",
449
+ "version": "0.9.38-alpha.8",
450
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-arm64/-/atomic-natives-darwin-arm64-0.9.38-alpha.8.tgz",
451
451
  "license": "MIT",
452
452
  "os": [
453
453
  "darwin"
@@ -458,8 +458,8 @@
458
458
  "optional": true
459
459
  },
460
460
  "node_modules/@bastani/atomic-natives-darwin-x64": {
461
- "version": "0.9.38-alpha.7",
462
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-x64/-/atomic-natives-darwin-x64-0.9.38-alpha.7.tgz",
461
+ "version": "0.9.38-alpha.8",
462
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-darwin-x64/-/atomic-natives-darwin-x64-0.9.38-alpha.8.tgz",
463
463
  "license": "MIT",
464
464
  "os": [
465
465
  "darwin"
@@ -470,8 +470,8 @@
470
470
  "optional": true
471
471
  },
472
472
  "node_modules/@bastani/atomic-natives-linux-arm64-gnu": {
473
- "version": "0.9.38-alpha.7",
474
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-gnu/-/atomic-natives-linux-arm64-gnu-0.9.38-alpha.7.tgz",
473
+ "version": "0.9.38-alpha.8",
474
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-gnu/-/atomic-natives-linux-arm64-gnu-0.9.38-alpha.8.tgz",
475
475
  "license": "MIT",
476
476
  "os": [
477
477
  "linux"
@@ -485,8 +485,8 @@
485
485
  "optional": true
486
486
  },
487
487
  "node_modules/@bastani/atomic-natives-linux-arm64-musl": {
488
- "version": "0.9.38-alpha.7",
489
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-musl/-/atomic-natives-linux-arm64-musl-0.9.38-alpha.7.tgz",
488
+ "version": "0.9.38-alpha.8",
489
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-arm64-musl/-/atomic-natives-linux-arm64-musl-0.9.38-alpha.8.tgz",
490
490
  "license": "MIT",
491
491
  "os": [
492
492
  "linux"
@@ -500,8 +500,8 @@
500
500
  "optional": true
501
501
  },
502
502
  "node_modules/@bastani/atomic-natives-linux-x64-gnu": {
503
- "version": "0.9.38-alpha.7",
504
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-gnu/-/atomic-natives-linux-x64-gnu-0.9.38-alpha.7.tgz",
503
+ "version": "0.9.38-alpha.8",
504
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-gnu/-/atomic-natives-linux-x64-gnu-0.9.38-alpha.8.tgz",
505
505
  "license": "MIT",
506
506
  "os": [
507
507
  "linux"
@@ -515,8 +515,8 @@
515
515
  "optional": true
516
516
  },
517
517
  "node_modules/@bastani/atomic-natives-linux-x64-musl": {
518
- "version": "0.9.38-alpha.7",
519
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-musl/-/atomic-natives-linux-x64-musl-0.9.38-alpha.7.tgz",
518
+ "version": "0.9.38-alpha.8",
519
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-linux-x64-musl/-/atomic-natives-linux-x64-musl-0.9.38-alpha.8.tgz",
520
520
  "license": "MIT",
521
521
  "os": [
522
522
  "linux"
@@ -530,8 +530,8 @@
530
530
  "optional": true
531
531
  },
532
532
  "node_modules/@bastani/atomic-natives-win32-arm64-msvc": {
533
- "version": "0.9.38-alpha.7",
534
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-arm64-msvc/-/atomic-natives-win32-arm64-msvc-0.9.38-alpha.7.tgz",
533
+ "version": "0.9.38-alpha.8",
534
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-arm64-msvc/-/atomic-natives-win32-arm64-msvc-0.9.38-alpha.8.tgz",
535
535
  "license": "MIT",
536
536
  "os": [
537
537
  "win32"
@@ -542,8 +542,8 @@
542
542
  "optional": true
543
543
  },
544
544
  "node_modules/@bastani/atomic-natives-win32-x64-msvc": {
545
- "version": "0.9.38-alpha.7",
546
- "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-x64-msvc/-/atomic-natives-win32-x64-msvc-0.9.38-alpha.7.tgz",
545
+ "version": "0.9.38-alpha.8",
546
+ "resolved": "https://registry.npmjs.org/@bastani/atomic-natives-win32-x64-msvc/-/atomic-natives-win32-x64-msvc-0.9.38-alpha.8.tgz",
547
547
  "license": "MIT",
548
548
  "os": [
549
549
  "win32"
@@ -554,8 +554,8 @@
554
554
  "optional": true
555
555
  },
556
556
  "node_modules/@bastani/pi-ai": {
557
- "version": "0.9.38-alpha.7",
558
- "resolved": "https://registry.npmjs.org/@bastani/pi-ai/-/pi-ai-0.9.38-alpha.7.tgz",
557
+ "version": "0.9.38-alpha.8",
558
+ "resolved": "https://registry.npmjs.org/@bastani/pi-ai/-/pi-ai-0.9.38-alpha.8.tgz",
559
559
  "license": "MIT",
560
560
  "dependencies": {
561
561
  "@anthropic-ai/sdk": "0.129.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/atomic",
3
- "version": "0.9.38-alpha.7",
3
+ "version": "0.9.38-alpha.8",
4
4
  "description": "Atomic coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "atomicConfig": {
@@ -89,8 +89,8 @@
89
89
  "prepublishOnly": "bun run clean && bun run build && bun run shrinkwrap"
90
90
  },
91
91
  "dependencies": {
92
- "@bastani/atomic-natives": "0.9.38-alpha.7",
93
- "@bastani/pi-ai": "0.9.38-alpha.7",
92
+ "@bastani/atomic-natives": "0.9.38-alpha.8",
93
+ "@bastani/pi-ai": "0.9.38-alpha.8",
94
94
  "@earendil-works/pi-agent-core": "1.3.0",
95
95
  "@earendil-works/pi-codemode": "1.3.0",
96
96
  "@earendil-works/pi-tui": "1.3.0",