@moxxy/core 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sessions/persistence.d.ts +75 -0
- package/dist/sessions/persistence.d.ts.map +1 -1
- package/dist/sessions/persistence.js +126 -0
- package/dist/sessions/persistence.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/sessions/page.test.ts +217 -0
- package/src/sessions/persistence.ts +147 -0
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export { SynthesizerRegistry } from './registries/synthesizers.js';
|
|
|
27
27
|
export { EmbedderRegistry } from './registries/embedders.js';
|
|
28
28
|
export { IsolatorRegistry as ContributedIsolatorRegistry } from './registries/isolators.js';
|
|
29
29
|
export { RequirementRegistry, type RequirementRegistryOptions } from './requirements.js';
|
|
30
|
-
export { SessionPersistence, defaultSessionsDir, readIndex as readSessionIndex, restoreEvents as restoreSessionEvents, deleteSession, type SessionMeta, type SessionPersistenceOpts, } from './sessions/persistence.js';
|
|
30
|
+
export { SessionPersistence, defaultSessionsDir, readIndex as readSessionIndex, restoreEvents as restoreSessionEvents, readEventPage as readSessionEventPage, pageEvents, seedSessionLog, deleteSession, type SessionMeta, type SessionPersistenceOpts, type EventPage, } from './sessions/persistence.js';
|
|
31
31
|
export { PluginHost, PluginRequirementError, type PluginLoader, type PluginSkipReason, type PluginSkipRecord, type PluginSkipSource, type RegisterStaticOptions, } from './plugins/host.js';
|
|
32
32
|
export { HookDispatcherImpl } from './plugins/lifecycle.js';
|
|
33
33
|
export { discoverPlugins } from './plugins/discovery.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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AAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,gCAAgC,EAChC,KAAK,0BAA0B,EAC/B,KAAK,iCAAiC,EACtC,KAAK,uBAAuB,EAC5B,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ export { SynthesizerRegistry } from './registries/synthesizers.js';
|
|
|
28
28
|
export { EmbedderRegistry } from './registries/embedders.js';
|
|
29
29
|
export { IsolatorRegistry as ContributedIsolatorRegistry } from './registries/isolators.js';
|
|
30
30
|
export { RequirementRegistry } from './requirements.js';
|
|
31
|
-
export { SessionPersistence, defaultSessionsDir, readIndex as readSessionIndex, restoreEvents as restoreSessionEvents, deleteSession, } from './sessions/persistence.js';
|
|
31
|
+
export { SessionPersistence, defaultSessionsDir, readIndex as readSessionIndex, restoreEvents as restoreSessionEvents, readEventPage as readSessionEventPage, pageEvents, seedSessionLog, deleteSession, } from './sessions/persistence.js';
|
|
32
32
|
export { PluginHost, PluginRequirementError, } from './plugins/host.js';
|
|
33
33
|
export { HookDispatcherImpl } from './plugins/lifecycle.js';
|
|
34
34
|
export { discoverPlugins } from './plugins/discovery.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAuB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE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;AACnC,OAAO,EACL,UAAU,EACV,sBAAsB,GAMvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAA0B,MAAM,qBAAqB,CAAC;AACjF,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GAGvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,gCAAgC,EAIhC,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,YAAY,EAA8B,MAAM,aAAa,CAAC"}
|
|
@@ -175,6 +175,81 @@ export declare function readIndex(dir?: string): Promise<SessionMeta[]>;
|
|
|
175
175
|
* post-gap history.
|
|
176
176
|
*/
|
|
177
177
|
export declare function restoreEvents(sessionId: string, dir?: string, logger?: Logger): Promise<MoxxyEvent[]>;
|
|
178
|
+
/** One page of persisted events, newest-page-first paging (see
|
|
179
|
+
* {@link readEventPage}). */
|
|
180
|
+
export interface EventPage {
|
|
181
|
+
/** The events in this page, in ascending `seq` order. */
|
|
182
|
+
readonly events: MoxxyEvent[];
|
|
183
|
+
/**
|
|
184
|
+
* Cursor to pass as `before` for the NEXT (older) page — the `seq` of the
|
|
185
|
+
* OLDEST event in this page. `null` once the start of history (the first
|
|
186
|
+
* persisted event) is included, signalling there is no older page.
|
|
187
|
+
*/
|
|
188
|
+
readonly prevCursor: number | null;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Read ONE page of a persisted session's events without re-materializing the
|
|
192
|
+
* whole conversation into a live {@link EventLog}. Backs the runner's
|
|
193
|
+
* `session.loadHistory` so a thin client (the desktop) can page history from
|
|
194
|
+
* the runner's authoritative JSONL instead of its own NDJSON mirror.
|
|
195
|
+
*
|
|
196
|
+
* Paging is newest-first, walking backwards:
|
|
197
|
+
* - `before == null` — the NEWEST page: the last `limit` events on disk.
|
|
198
|
+
* - `before == N` — the page of (up to) `limit` events strictly OLDER than
|
|
199
|
+
* `seq === N` (the events immediately preceding the cursor). Pass the
|
|
200
|
+
* previous page's `prevCursor` here to step one page further back.
|
|
201
|
+
*
|
|
202
|
+
* The returned `events` are always in ascending `seq` order (oldest-first
|
|
203
|
+
* WITHIN the page) so a caller can prepend a page to an in-order transcript.
|
|
204
|
+
* `prevCursor` is the `seq` of the page's oldest event, or `null` once the
|
|
205
|
+
* first persisted event is included (no older page remains).
|
|
206
|
+
*
|
|
207
|
+
* Corrupt lines are skipped (matching {@link restoreEvents}); unlike
|
|
208
|
+
* `restoreEvents` this is a READ-ONLY reader — it never rewrites the file, so
|
|
209
|
+
* it preserves the JSONL exactly (no atomic-write / mutex needed: there is no
|
|
210
|
+
* mutation). Paging keys on each event's on-disk `seq`. Determinism holds for a
|
|
211
|
+
* MONOTONICALLY-INCREASING seq sequence — including a gapped-but-increasing one
|
|
212
|
+
* (the append path guarantees this; the next resume re-sequences to contiguous
|
|
213
|
+
* 0..n-1 anyway). DUPLICATE / non-strictly-increasing seqs are only reachable
|
|
214
|
+
* via external file corruption, and a backward `prevCursor` walk over them can
|
|
215
|
+
* drop events page-size-dependently until that next resume repairs the log.
|
|
216
|
+
*
|
|
217
|
+
* A missing log file is treated as an EMPTY history (`{ events: [], prevCursor:
|
|
218
|
+
* null }`), not an error — a freshly-created session whose JSONL hasn't been
|
|
219
|
+
* written yet must page as empty rather than throw.
|
|
220
|
+
*/
|
|
221
|
+
export declare function readEventPage(sessionId: string, opts: {
|
|
222
|
+
before: number | null;
|
|
223
|
+
limit: number;
|
|
224
|
+
}, dir?: string): Promise<EventPage>;
|
|
225
|
+
/**
|
|
226
|
+
* Slice one newest-first page out of an ascending-`seq` event array. Pure +
|
|
227
|
+
* exported so the runner can reuse the EXACT paging semantics when it serves a
|
|
228
|
+
* page out of its in-memory log instead of disk — the two paths must agree
|
|
229
|
+
* byte-for-byte or a client crossing between them (in-memory → disk fallback)
|
|
230
|
+
* would see a discontinuity. `events` MUST be ordered oldest-first (the on-disk
|
|
231
|
+
* / append order); `before`/`limit` follow {@link readEventPage}.
|
|
232
|
+
*/
|
|
233
|
+
export declare function pageEvents(events: ReadonlyArray<MoxxyEvent>, before: number | null, limit: number): EventPage;
|
|
234
|
+
/**
|
|
235
|
+
* Seed a session's event log from an external event list IFF the session has no
|
|
236
|
+
* log on disk yet. This is the migration that makes the runner's authoritative
|
|
237
|
+
* log the home of a chat whose history previously lived ONLY in a thin client's
|
|
238
|
+
* own mirror (the desktop's NDJSON chat store) — after it runs, `loadHistory`
|
|
239
|
+
* serves that chat from the runner like any other.
|
|
240
|
+
*
|
|
241
|
+
* Idempotent and NON-destructive: if `<sessionId>.jsonl` already exists AND is
|
|
242
|
+
* NON-EMPTY this is a no-op returning `false`, so a session the runner already
|
|
243
|
+
* owns is NEVER overwritten. A 0-byte log IS seeded: `persistence.attach`
|
|
244
|
+
* creates an empty `<id>.jsonl` on every spawn (even a session with zero
|
|
245
|
+
* events), so an existence-only guard would skip exactly the legacy chats this
|
|
246
|
+
* migration targets — and an empty file holds no history, so seeding over it
|
|
247
|
+
* loses nothing. Events are re-sequenced to contiguous `seq` 0..n-1 (order + ids
|
|
248
|
+
* preserved) so the seeded log satisfies {@link EventLog}'s seq invariants when
|
|
249
|
+
* it is later restored. Written temp+rename so a crash mid-seed can't leave a
|
|
250
|
+
* half-written log. Returns `true` iff it wrote the log.
|
|
251
|
+
*/
|
|
252
|
+
export declare function seedSessionLog(sessionId: string, events: ReadonlyArray<MoxxyEvent>, dir?: string): Promise<boolean>;
|
|
178
253
|
/**
|
|
179
254
|
* Remove a session's log file and its sidecar. A leftover legacy `index.json`
|
|
180
255
|
* row, if any, is harmless —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reEvents(sessionId, dir = defaultSessionsDir(), logge
|
|
|
413
413
|
}
|
|
414
414
|
return events;
|
|
415
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Read ONE page of a persisted session's events without re-materializing the
|
|
418
|
+
* whole conversation into a live {@link EventLog}. Backs the runner's
|
|
419
|
+
* `session.loadHistory` so a thin client (the desktop) can page history from
|
|
420
|
+
* the runner's authoritative JSONL instead of its own NDJSON mirror.
|
|
421
|
+
*
|
|
422
|
+
* Paging is newest-first, walking backwards:
|
|
423
|
+
* - `before == null` — the NEWEST page: the last `limit` events on disk.
|
|
424
|
+
* - `before == N` — the page of (up to) `limit` events strictly OLDER than
|
|
425
|
+
* `seq === N` (the events immediately preceding the cursor). Pass the
|
|
426
|
+
* previous page's `prevCursor` here to step one page further back.
|
|
427
|
+
*
|
|
428
|
+
* The returned `events` are always in ascending `seq` order (oldest-first
|
|
429
|
+
* WITHIN the page) so a caller can prepend a page to an in-order transcript.
|
|
430
|
+
* `prevCursor` is the `seq` of the page's oldest event, or `null` once the
|
|
431
|
+
* first persisted event is included (no older page remains).
|
|
432
|
+
*
|
|
433
|
+
* Corrupt lines are skipped (matching {@link restoreEvents}); unlike
|
|
434
|
+
* `restoreEvents` this is a READ-ONLY reader — it never rewrites the file, so
|
|
435
|
+
* it preserves the JSONL exactly (no atomic-write / mutex needed: there is no
|
|
436
|
+
* mutation). Paging keys on each event's on-disk `seq`. Determinism holds for a
|
|
437
|
+
* MONOTONICALLY-INCREASING seq sequence — including a gapped-but-increasing one
|
|
438
|
+
* (the append path guarantees this; the next resume re-sequences to contiguous
|
|
439
|
+
* 0..n-1 anyway). DUPLICATE / non-strictly-increasing seqs are only reachable
|
|
440
|
+
* via external file corruption, and a backward `prevCursor` walk over them can
|
|
441
|
+
* drop events page-size-dependently until that next resume repairs the log.
|
|
442
|
+
*
|
|
443
|
+
* A missing log file is treated as an EMPTY history (`{ events: [], prevCursor:
|
|
444
|
+
* null }`), not an error — a freshly-created session whose JSONL hasn't been
|
|
445
|
+
* written yet must page as empty rather than throw.
|
|
446
|
+
*/
|
|
447
|
+
export async function readEventPage(sessionId, opts, dir = defaultSessionsDir()) {
|
|
448
|
+
const logPath = path.join(dir, `${sessionId}.jsonl`);
|
|
449
|
+
let raw;
|
|
450
|
+
try {
|
|
451
|
+
raw = await fs.readFile(logPath, 'utf8');
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
// No log on disk yet → empty history, not an error.
|
|
455
|
+
return { events: [], prevCursor: null };
|
|
456
|
+
}
|
|
457
|
+
// Parse the JSONL, skipping corrupt lines (one bad append must not make the
|
|
458
|
+
// rest unreadable). Read-only: we never rewrite the file here.
|
|
459
|
+
const all = [];
|
|
460
|
+
for (const line of raw.split('\n')) {
|
|
461
|
+
if (!line.trim())
|
|
462
|
+
continue;
|
|
463
|
+
try {
|
|
464
|
+
all.push(JSON.parse(line));
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
// skip a malformed/half-written line, same as restoreEvents
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// Delegate ALL paging (including the limit/cursor clamping) to pageEvents so
|
|
471
|
+
// the disk and in-memory paths are identical by construction — no separate
|
|
472
|
+
// limit handling here that could diverge from the in-memory page.
|
|
473
|
+
return pageEvents(all, opts.before, opts.limit);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Slice one newest-first page out of an ascending-`seq` event array. Pure +
|
|
477
|
+
* exported so the runner can reuse the EXACT paging semantics when it serves a
|
|
478
|
+
* page out of its in-memory log instead of disk — the two paths must agree
|
|
479
|
+
* byte-for-byte or a client crossing between them (in-memory → disk fallback)
|
|
480
|
+
* would see a discontinuity. `events` MUST be ordered oldest-first (the on-disk
|
|
481
|
+
* / append order); `before`/`limit` follow {@link readEventPage}.
|
|
482
|
+
*/
|
|
483
|
+
export function pageEvents(events, before, limit) {
|
|
484
|
+
const cap = Math.max(0, Math.floor(limit));
|
|
485
|
+
if (cap === 0 || events.length === 0) {
|
|
486
|
+
return { events: [], prevCursor: events.length === 0 ? null : before };
|
|
487
|
+
}
|
|
488
|
+
// Exclusive upper bound by `seq`: the first index whose event is NOT older
|
|
489
|
+
// than `before`. `before == null` (newest page) keeps the whole array.
|
|
490
|
+
let end = events.length;
|
|
491
|
+
if (before !== null) {
|
|
492
|
+
end = 0;
|
|
493
|
+
for (let i = 0; i < events.length; i += 1) {
|
|
494
|
+
if (events[i].seq < before)
|
|
495
|
+
end = i + 1;
|
|
496
|
+
else
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const start = Math.max(0, end - cap);
|
|
501
|
+
const page = events.slice(start, end);
|
|
502
|
+
// `null` once this page reaches the very first event on disk — no older page.
|
|
503
|
+
const prevCursor = start <= 0 ? null : page[0].seq;
|
|
504
|
+
return { events: page, prevCursor };
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Seed a session's event log from an external event list IFF the session has no
|
|
508
|
+
* log on disk yet. This is the migration that makes the runner's authoritative
|
|
509
|
+
* log the home of a chat whose history previously lived ONLY in a thin client's
|
|
510
|
+
* own mirror (the desktop's NDJSON chat store) — after it runs, `loadHistory`
|
|
511
|
+
* serves that chat from the runner like any other.
|
|
512
|
+
*
|
|
513
|
+
* Idempotent and NON-destructive: if `<sessionId>.jsonl` already exists AND is
|
|
514
|
+
* NON-EMPTY this is a no-op returning `false`, so a session the runner already
|
|
515
|
+
* owns is NEVER overwritten. A 0-byte log IS seeded: `persistence.attach`
|
|
516
|
+
* creates an empty `<id>.jsonl` on every spawn (even a session with zero
|
|
517
|
+
* events), so an existence-only guard would skip exactly the legacy chats this
|
|
518
|
+
* migration targets — and an empty file holds no history, so seeding over it
|
|
519
|
+
* loses nothing. Events are re-sequenced to contiguous `seq` 0..n-1 (order + ids
|
|
520
|
+
* preserved) so the seeded log satisfies {@link EventLog}'s seq invariants when
|
|
521
|
+
* it is later restored. Written temp+rename so a crash mid-seed can't leave a
|
|
522
|
+
* half-written log. Returns `true` iff it wrote the log.
|
|
523
|
+
*/
|
|
524
|
+
export async function seedSessionLog(sessionId, events, dir = defaultSessionsDir()) {
|
|
525
|
+
if (events.length === 0)
|
|
526
|
+
return false;
|
|
527
|
+
const logPath = path.join(dir, `${sessionId}.jsonl`);
|
|
528
|
+
try {
|
|
529
|
+
// A non-empty log is a session the runner already owns → never overwrite.
|
|
530
|
+
// A 0-byte log is the empty file attach() left behind → seed over it.
|
|
531
|
+
if ((await fs.stat(logPath)).size > 0)
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
/* no log yet → seed below */
|
|
536
|
+
}
|
|
537
|
+
await fs.mkdir(dir, { recursive: true });
|
|
538
|
+
const reseq = events.map((e, i) => (e.seq === i ? e : { ...e, seq: i }));
|
|
539
|
+
await writeFileAtomic(logPath, reseq.map((e) => JSON.stringify(e) + '\n').join(''));
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
416
542
|
/**
|
|
417
543
|
* Remove a session's log file and its sidecar. A leftover legacy `index.json`
|
|
418
544
|
* row, if any, is harmless — `readIndex` filters out sessions whose `.jsonl` is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.js","sourceRoot":"","sources":["../../src/sessions/persistence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,WAAW,EAA+C,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAe,MAAM,cAAc,CAAC;AA+BzD,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,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AAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,MAAM,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC;AAED,yCAAyC;AACzC,SAAS,QAAQ,CAAC,GAAW,EAAE,EAAU;IACvC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;AAC3C,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,MAAc,EAAE,KAAc;IAC3D,MAAM,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9C,MAAM,CAAC,GAAG,CAA4B,CAAC;IACvC,OAAO,CACL,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ;QACxB,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ;QACzB,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ;QAC/B,OAAO,CAAC,CAAC,YAAY,KAAK,QAAQ;QAClC,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moxxy/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "The moxxy runtime as a programmatic library: the agentic Session + runTurn loop, the event log, the plugin host, every block registry (providers, tools, modes, compactors, cache strategies, channels, …), session persistence, and the permission engine. Pair with @moxxy/sdk to build and embed moxxy agents in your own code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"moxxy",
|
package/src/index.ts
CHANGED
|
@@ -65,9 +65,13 @@ export {
|
|
|
65
65
|
defaultSessionsDir,
|
|
66
66
|
readIndex as readSessionIndex,
|
|
67
67
|
restoreEvents as restoreSessionEvents,
|
|
68
|
+
readEventPage as readSessionEventPage,
|
|
69
|
+
pageEvents,
|
|
70
|
+
seedSessionLog,
|
|
68
71
|
deleteSession,
|
|
69
72
|
type SessionMeta,
|
|
70
73
|
type SessionPersistenceOpts,
|
|
74
|
+
type EventPage,
|
|
71
75
|
} from './sessions/persistence.js';
|
|
72
76
|
export {
|
|
73
77
|
PluginHost,
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import type { MoxxyEvent } from '@moxxy/sdk';
|
|
6
|
+
import { pageEvents, readEventPage, restoreEvents, seedSessionLog } from './persistence.js';
|
|
7
|
+
|
|
8
|
+
const tempDirs: string[] = [];
|
|
9
|
+
|
|
10
|
+
async function makeTempDir(): Promise<string> {
|
|
11
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'moxxy-page-'));
|
|
12
|
+
tempDirs.push(dir);
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/** A contiguous 0..n-1 log of user_prompt events with predictable text. */
|
|
21
|
+
function makeLog(n: number, sessionId = 'pagesession'): MoxxyEvent[] {
|
|
22
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
23
|
+
id: `e${i}`,
|
|
24
|
+
seq: i,
|
|
25
|
+
ts: i,
|
|
26
|
+
sessionId,
|
|
27
|
+
turnId: `t${i}`,
|
|
28
|
+
source: 'user',
|
|
29
|
+
type: 'user_prompt',
|
|
30
|
+
text: `m${i}`,
|
|
31
|
+
})) as unknown as MoxxyEvent[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function writeLog(dir: string, id: string, events: MoxxyEvent[]): Promise<void> {
|
|
35
|
+
const body = events.map((e) => JSON.stringify(e) + '\n').join('');
|
|
36
|
+
await fs.writeFile(path.join(dir, `${id}.jsonl`), body, 'utf8');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('pageEvents (pure newest-first paging)', () => {
|
|
40
|
+
it('newest page (before=null) returns the last `limit` events with a prevCursor', () => {
|
|
41
|
+
const log = makeLog(10);
|
|
42
|
+
const page = pageEvents(log, null, 3);
|
|
43
|
+
expect(page.events.map((e) => e.seq)).toEqual([7, 8, 9]);
|
|
44
|
+
// prevCursor is the seq of the oldest event in THIS page → pass it next.
|
|
45
|
+
expect(page.prevCursor).toBe(7);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('older page via prevCursor returns the events immediately preceding it', () => {
|
|
49
|
+
const log = makeLog(10);
|
|
50
|
+
const newest = pageEvents(log, null, 3); // [7,8,9], prevCursor 7
|
|
51
|
+
const older = pageEvents(log, newest.prevCursor, 3);
|
|
52
|
+
expect(older.events.map((e) => e.seq)).toEqual([4, 5, 6]);
|
|
53
|
+
expect(older.prevCursor).toBe(4);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('prevCursor is null once the page includes the start of history', () => {
|
|
57
|
+
const log = makeLog(5);
|
|
58
|
+
// Walk back from the newest until the start is reached.
|
|
59
|
+
const p1 = pageEvents(log, null, 2); // [3,4] cursor 3
|
|
60
|
+
expect(p1.prevCursor).toBe(3);
|
|
61
|
+
const p2 = pageEvents(log, p1.prevCursor, 2); // [1,2] cursor 1
|
|
62
|
+
expect(p2.events.map((e) => e.seq)).toEqual([1, 2]);
|
|
63
|
+
expect(p2.prevCursor).toBe(1);
|
|
64
|
+
const p3 = pageEvents(log, p2.prevCursor, 2); // [0] — start reached
|
|
65
|
+
expect(p3.events.map((e) => e.seq)).toEqual([0]);
|
|
66
|
+
expect(p3.prevCursor).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('limit larger than history returns the whole log and a null cursor', () => {
|
|
70
|
+
const log = makeLog(4);
|
|
71
|
+
const page = pageEvents(log, null, 100);
|
|
72
|
+
expect(page.events.map((e) => e.seq)).toEqual([0, 1, 2, 3]);
|
|
73
|
+
expect(page.prevCursor).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('empty log returns no events and a null cursor regardless of before', () => {
|
|
77
|
+
expect(pageEvents([], null, 5)).toEqual({ events: [], prevCursor: null });
|
|
78
|
+
expect(pageEvents([], 3, 5)).toEqual({ events: [], prevCursor: null });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('walking all pages reconstructs the full log exactly once, in order', () => {
|
|
82
|
+
const log = makeLog(23);
|
|
83
|
+
const collected: number[] = [];
|
|
84
|
+
let before: number | null = null;
|
|
85
|
+
// Guard the loop so a paging bug can't spin forever.
|
|
86
|
+
for (let guard = 0; guard < 100; guard += 1) {
|
|
87
|
+
const page: ReturnType<typeof pageEvents> = pageEvents(log, before, 5);
|
|
88
|
+
collected.unshift(...page.events.map((e) => e.seq));
|
|
89
|
+
if (page.prevCursor === null) break;
|
|
90
|
+
before = page.prevCursor;
|
|
91
|
+
}
|
|
92
|
+
expect(collected).toEqual(log.map((e) => e.seq));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('readEventPage (paged JSONL reader)', () => {
|
|
97
|
+
it('pages the newest events off disk without materializing the whole log', async () => {
|
|
98
|
+
const dir = await makeTempDir();
|
|
99
|
+
const id = 'disk1';
|
|
100
|
+
await writeLog(dir, id, makeLog(8, id));
|
|
101
|
+
const page = await readEventPage(id, { before: null, limit: 3 }, dir);
|
|
102
|
+
expect(page.events.map((e) => (e as { text?: string }).text)).toEqual(['m5', 'm6', 'm7']);
|
|
103
|
+
expect(page.prevCursor).toBe(5);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('steps to the older page via prevCursor', async () => {
|
|
107
|
+
const dir = await makeTempDir();
|
|
108
|
+
const id = 'disk2';
|
|
109
|
+
await writeLog(dir, id, makeLog(8, id));
|
|
110
|
+
const newest = await readEventPage(id, { before: null, limit: 3 }, dir);
|
|
111
|
+
const older = await readEventPage(id, { before: newest.prevCursor, limit: 3 }, dir);
|
|
112
|
+
expect(older.events.map((e) => e.seq)).toEqual([2, 3, 4]);
|
|
113
|
+
expect(older.prevCursor).toBe(2);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('returns prevCursor=null at the start of history', async () => {
|
|
117
|
+
const dir = await makeTempDir();
|
|
118
|
+
const id = 'disk3';
|
|
119
|
+
await writeLog(dir, id, makeLog(3, id));
|
|
120
|
+
const page = await readEventPage(id, { before: 1, limit: 10 }, dir);
|
|
121
|
+
expect(page.events.map((e) => e.seq)).toEqual([0]);
|
|
122
|
+
expect(page.prevCursor).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('treats a missing log file as empty history (no throw)', async () => {
|
|
126
|
+
const dir = await makeTempDir();
|
|
127
|
+
await expect(readEventPage('never-written', { before: null, limit: 5 }, dir)).resolves.toEqual({
|
|
128
|
+
events: [],
|
|
129
|
+
prevCursor: null,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('agrees with pageEvents on an empty/missing log for any before/limit (incl. limit 0)', async () => {
|
|
134
|
+
// The disk reader delegates clamping to pageEvents, so the two paths cannot
|
|
135
|
+
// diverge — pin it, including the limit===0 corner the wire schema forbids
|
|
136
|
+
// but a direct in-process caller could still hit.
|
|
137
|
+
const dir = await makeTempDir();
|
|
138
|
+
for (const before of [null, 5] as const) {
|
|
139
|
+
for (const limit of [0, 3]) {
|
|
140
|
+
await expect(readEventPage('missing', { before, limit }, dir)).resolves.toEqual(
|
|
141
|
+
pageEvents([], before, limit),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('skips a corrupt line and pages the survivors deterministically', async () => {
|
|
148
|
+
const dir = await makeTempDir();
|
|
149
|
+
const id = 'disk4';
|
|
150
|
+
const events = makeLog(5, id);
|
|
151
|
+
const body =
|
|
152
|
+
events
|
|
153
|
+
.slice(0, 2)
|
|
154
|
+
.map((e) => JSON.stringify(e) + '\n')
|
|
155
|
+
.join('') +
|
|
156
|
+
'{not json\n' +
|
|
157
|
+
events
|
|
158
|
+
.slice(2)
|
|
159
|
+
.map((e) => JSON.stringify(e) + '\n')
|
|
160
|
+
.join('');
|
|
161
|
+
await fs.writeFile(path.join(dir, `${id}.jsonl`), body, 'utf8');
|
|
162
|
+
const page = await readEventPage(id, { before: null, limit: 10 }, dir);
|
|
163
|
+
// The corrupt line is dropped; the four survivors page in seq order.
|
|
164
|
+
expect(page.events.map((e) => e.seq)).toEqual([0, 1, 2, 3, 4]);
|
|
165
|
+
expect(page.prevCursor).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('does NOT rewrite the file on disk (read-only reader)', async () => {
|
|
169
|
+
const dir = await makeTempDir();
|
|
170
|
+
const id = 'disk5';
|
|
171
|
+
// A gapped/corrupt log — restoreEvents would repair it, readEventPage must not.
|
|
172
|
+
const body = '{corrupt\n' + makeLog(2, id).map((e) => JSON.stringify(e) + '\n').join('');
|
|
173
|
+
await fs.writeFile(path.join(dir, `${id}.jsonl`), body, 'utf8');
|
|
174
|
+
const before = await fs.readFile(path.join(dir, `${id}.jsonl`), 'utf8');
|
|
175
|
+
await readEventPage(id, { before: null, limit: 10 }, dir);
|
|
176
|
+
const after = await fs.readFile(path.join(dir, `${id}.jsonl`), 'utf8');
|
|
177
|
+
expect(after).toBe(before);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('seedSessionLog (NDJSON → runner-log migration)', () => {
|
|
182
|
+
it('writes a fresh session log, re-sequenced to 0..n-1, ids + content preserved', async () => {
|
|
183
|
+
const dir = await makeTempDir();
|
|
184
|
+
// Gapped original seqs — as rendered events pulled from the desktop mirror
|
|
185
|
+
// (which dropped the interleaved chunk/bookend events) would have.
|
|
186
|
+
const events = [
|
|
187
|
+
{ id: 'a', seq: 3, ts: 0, sessionId: 'sess', turnId: 't0', source: 'user', type: 'user_prompt', text: 'q' },
|
|
188
|
+
{ id: 'b', seq: 7, ts: 1, sessionId: 'sess', turnId: 't0', source: 'model', type: 'assistant_message', content: 'reply' },
|
|
189
|
+
] as unknown as MoxxyEvent[];
|
|
190
|
+
expect(await seedSessionLog('sess', events, dir)).toBe(true);
|
|
191
|
+
// The runner restores it like any native log: contiguous seqs, ids preserved.
|
|
192
|
+
const restored = await restoreEvents('sess', dir);
|
|
193
|
+
expect(restored.map((e) => e.id)).toEqual(['a', 'b']);
|
|
194
|
+
expect(restored.map((e) => e.seq)).toEqual([0, 1]);
|
|
195
|
+
expect((restored[1] as { content?: string }).content).toBe('reply');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('never overwrites a NON-EMPTY session the runner already owns', async () => {
|
|
199
|
+
const dir = await makeTempDir();
|
|
200
|
+
await writeLog(dir, 'sess', makeLog(2, 'sess')); // the runner already owns it
|
|
201
|
+
expect(await seedSessionLog('sess', makeLog(5, 'sess'), dir)).toBe(false);
|
|
202
|
+
const restored = await restoreEvents('sess', dir);
|
|
203
|
+
expect(restored).toHaveLength(2); // untouched
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('seeds OVER a 0-byte session log (the empty file attach leaves on every spawn)', async () => {
|
|
207
|
+
const dir = await makeTempDir();
|
|
208
|
+
await writeLog(dir, 'sess', []); // 0-byte file, holds no history
|
|
209
|
+
expect(await seedSessionLog('sess', makeLog(3, 'sess'), dir)).toBe(true);
|
|
210
|
+
expect(await restoreEvents('sess', dir)).toHaveLength(3);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('is a no-op for an empty event list', async () => {
|
|
214
|
+
const dir = await makeTempDir();
|
|
215
|
+
expect(await seedSessionLog('sess', [], dir)).toBe(false);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -463,6 +463,153 @@ export async function restoreEvents(
|
|
|
463
463
|
return events;
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
/** One page of persisted events, newest-page-first paging (see
|
|
467
|
+
* {@link readEventPage}). */
|
|
468
|
+
export interface EventPage {
|
|
469
|
+
/** The events in this page, in ascending `seq` order. */
|
|
470
|
+
readonly events: MoxxyEvent[];
|
|
471
|
+
/**
|
|
472
|
+
* Cursor to pass as `before` for the NEXT (older) page — the `seq` of the
|
|
473
|
+
* OLDEST event in this page. `null` once the start of history (the first
|
|
474
|
+
* persisted event) is included, signalling there is no older page.
|
|
475
|
+
*/
|
|
476
|
+
readonly prevCursor: number | null;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Read ONE page of a persisted session's events without re-materializing the
|
|
481
|
+
* whole conversation into a live {@link EventLog}. Backs the runner's
|
|
482
|
+
* `session.loadHistory` so a thin client (the desktop) can page history from
|
|
483
|
+
* the runner's authoritative JSONL instead of its own NDJSON mirror.
|
|
484
|
+
*
|
|
485
|
+
* Paging is newest-first, walking backwards:
|
|
486
|
+
* - `before == null` — the NEWEST page: the last `limit` events on disk.
|
|
487
|
+
* - `before == N` — the page of (up to) `limit` events strictly OLDER than
|
|
488
|
+
* `seq === N` (the events immediately preceding the cursor). Pass the
|
|
489
|
+
* previous page's `prevCursor` here to step one page further back.
|
|
490
|
+
*
|
|
491
|
+
* The returned `events` are always in ascending `seq` order (oldest-first
|
|
492
|
+
* WITHIN the page) so a caller can prepend a page to an in-order transcript.
|
|
493
|
+
* `prevCursor` is the `seq` of the page's oldest event, or `null` once the
|
|
494
|
+
* first persisted event is included (no older page remains).
|
|
495
|
+
*
|
|
496
|
+
* Corrupt lines are skipped (matching {@link restoreEvents}); unlike
|
|
497
|
+
* `restoreEvents` this is a READ-ONLY reader — it never rewrites the file, so
|
|
498
|
+
* it preserves the JSONL exactly (no atomic-write / mutex needed: there is no
|
|
499
|
+
* mutation). Paging keys on each event's on-disk `seq`. Determinism holds for a
|
|
500
|
+
* MONOTONICALLY-INCREASING seq sequence — including a gapped-but-increasing one
|
|
501
|
+
* (the append path guarantees this; the next resume re-sequences to contiguous
|
|
502
|
+
* 0..n-1 anyway). DUPLICATE / non-strictly-increasing seqs are only reachable
|
|
503
|
+
* via external file corruption, and a backward `prevCursor` walk over them can
|
|
504
|
+
* drop events page-size-dependently until that next resume repairs the log.
|
|
505
|
+
*
|
|
506
|
+
* A missing log file is treated as an EMPTY history (`{ events: [], prevCursor:
|
|
507
|
+
* null }`), not an error — a freshly-created session whose JSONL hasn't been
|
|
508
|
+
* written yet must page as empty rather than throw.
|
|
509
|
+
*/
|
|
510
|
+
export async function readEventPage(
|
|
511
|
+
sessionId: string,
|
|
512
|
+
opts: { before: number | null; limit: number },
|
|
513
|
+
dir = defaultSessionsDir(),
|
|
514
|
+
): Promise<EventPage> {
|
|
515
|
+
const logPath = path.join(dir, `${sessionId}.jsonl`);
|
|
516
|
+
let raw: string;
|
|
517
|
+
try {
|
|
518
|
+
raw = await fs.readFile(logPath, 'utf8');
|
|
519
|
+
} catch {
|
|
520
|
+
// No log on disk yet → empty history, not an error.
|
|
521
|
+
return { events: [], prevCursor: null };
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Parse the JSONL, skipping corrupt lines (one bad append must not make the
|
|
525
|
+
// rest unreadable). Read-only: we never rewrite the file here.
|
|
526
|
+
const all: MoxxyEvent[] = [];
|
|
527
|
+
for (const line of raw.split('\n')) {
|
|
528
|
+
if (!line.trim()) continue;
|
|
529
|
+
try {
|
|
530
|
+
all.push(JSON.parse(line) as MoxxyEvent);
|
|
531
|
+
} catch {
|
|
532
|
+
// skip a malformed/half-written line, same as restoreEvents
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
// Delegate ALL paging (including the limit/cursor clamping) to pageEvents so
|
|
536
|
+
// the disk and in-memory paths are identical by construction — no separate
|
|
537
|
+
// limit handling here that could diverge from the in-memory page.
|
|
538
|
+
return pageEvents(all, opts.before, opts.limit);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Slice one newest-first page out of an ascending-`seq` event array. Pure +
|
|
543
|
+
* exported so the runner can reuse the EXACT paging semantics when it serves a
|
|
544
|
+
* page out of its in-memory log instead of disk — the two paths must agree
|
|
545
|
+
* byte-for-byte or a client crossing between them (in-memory → disk fallback)
|
|
546
|
+
* would see a discontinuity. `events` MUST be ordered oldest-first (the on-disk
|
|
547
|
+
* / append order); `before`/`limit` follow {@link readEventPage}.
|
|
548
|
+
*/
|
|
549
|
+
export function pageEvents(
|
|
550
|
+
events: ReadonlyArray<MoxxyEvent>,
|
|
551
|
+
before: number | null,
|
|
552
|
+
limit: number,
|
|
553
|
+
): EventPage {
|
|
554
|
+
const cap = Math.max(0, Math.floor(limit));
|
|
555
|
+
if (cap === 0 || events.length === 0) {
|
|
556
|
+
return { events: [], prevCursor: events.length === 0 ? null : before };
|
|
557
|
+
}
|
|
558
|
+
// Exclusive upper bound by `seq`: the first index whose event is NOT older
|
|
559
|
+
// than `before`. `before == null` (newest page) keeps the whole array.
|
|
560
|
+
let end = events.length;
|
|
561
|
+
if (before !== null) {
|
|
562
|
+
end = 0;
|
|
563
|
+
for (let i = 0; i < events.length; i += 1) {
|
|
564
|
+
if (events[i]!.seq < before) end = i + 1;
|
|
565
|
+
else break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const start = Math.max(0, end - cap);
|
|
569
|
+
const page = events.slice(start, end);
|
|
570
|
+
// `null` once this page reaches the very first event on disk — no older page.
|
|
571
|
+
const prevCursor = start <= 0 ? null : page[0]!.seq;
|
|
572
|
+
return { events: page, prevCursor };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Seed a session's event log from an external event list IFF the session has no
|
|
577
|
+
* log on disk yet. This is the migration that makes the runner's authoritative
|
|
578
|
+
* log the home of a chat whose history previously lived ONLY in a thin client's
|
|
579
|
+
* own mirror (the desktop's NDJSON chat store) — after it runs, `loadHistory`
|
|
580
|
+
* serves that chat from the runner like any other.
|
|
581
|
+
*
|
|
582
|
+
* Idempotent and NON-destructive: if `<sessionId>.jsonl` already exists AND is
|
|
583
|
+
* NON-EMPTY this is a no-op returning `false`, so a session the runner already
|
|
584
|
+
* owns is NEVER overwritten. A 0-byte log IS seeded: `persistence.attach`
|
|
585
|
+
* creates an empty `<id>.jsonl` on every spawn (even a session with zero
|
|
586
|
+
* events), so an existence-only guard would skip exactly the legacy chats this
|
|
587
|
+
* migration targets — and an empty file holds no history, so seeding over it
|
|
588
|
+
* loses nothing. Events are re-sequenced to contiguous `seq` 0..n-1 (order + ids
|
|
589
|
+
* preserved) so the seeded log satisfies {@link EventLog}'s seq invariants when
|
|
590
|
+
* it is later restored. Written temp+rename so a crash mid-seed can't leave a
|
|
591
|
+
* half-written log. Returns `true` iff it wrote the log.
|
|
592
|
+
*/
|
|
593
|
+
export async function seedSessionLog(
|
|
594
|
+
sessionId: string,
|
|
595
|
+
events: ReadonlyArray<MoxxyEvent>,
|
|
596
|
+
dir = defaultSessionsDir(),
|
|
597
|
+
): Promise<boolean> {
|
|
598
|
+
if (events.length === 0) return false;
|
|
599
|
+
const logPath = path.join(dir, `${sessionId}.jsonl`);
|
|
600
|
+
try {
|
|
601
|
+
// A non-empty log is a session the runner already owns → never overwrite.
|
|
602
|
+
// A 0-byte log is the empty file attach() left behind → seed over it.
|
|
603
|
+
if ((await fs.stat(logPath)).size > 0) return false;
|
|
604
|
+
} catch {
|
|
605
|
+
/* no log yet → seed below */
|
|
606
|
+
}
|
|
607
|
+
await fs.mkdir(dir, { recursive: true });
|
|
608
|
+
const reseq = events.map((e, i) => (e.seq === i ? e : ({ ...e, seq: i } as MoxxyEvent)));
|
|
609
|
+
await writeFileAtomic(logPath, reseq.map((e) => JSON.stringify(e) + '\n').join(''));
|
|
610
|
+
return true;
|
|
611
|
+
}
|
|
612
|
+
|
|
466
613
|
/**
|
|
467
614
|
* Remove a session's log file and its sidecar. A leftover legacy `index.json`
|
|
468
615
|
* row, if any, is harmless — `readIndex` filters out sessions whose `.jsonl` is
|