MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / dump

Method dump

src/workspaces/scrollback-store.ts:35–54  ·  view source on GitHub ↗

* Truncate `bytes` to the tail (last `SCROLLBACK_CAP_BYTES`) and write to * ` / / .bin`. Returns the path relative to `dir` so * callers can stash it in the SessionRecord.

(wsId: string, sessionId: string, bytes: Buffer)

Source from the content-addressed store, hash-verified

33 * callers can stash it in the SessionRecord.
34 */
35 async dump(wsId: string, sessionId: string, bytes: Buffer): Promise<string> {
36 const rel = `${wsId}/${sessionId}.bin`;
37 const abs = join(this.dir, rel);
38 await mkdir(dirname(abs), { recursive: true });
39 const tail =
40 bytes.length > SCROLLBACK_CAP_BYTES ? bytes.subarray(bytes.length - SCROLLBACK_CAP_BYTES) : bytes;
41 // Atomic write: write to tmp, rename. Crash mid-write doesn't leave a
42 // half-flushed scrollback file (and prevents readers from racing).
43 const tmp = `${abs}.tmp`;
44 await writeFile(tmp, tail);
45 const { rename } = await import('node:fs/promises');
46 await rename(tmp, abs);
47 this.logger.info('scrollback.dumped', {
48 wsId,
49 sessionId,
50 original: bytes.length,
51 written: tail.length,
52 });
53 return rel;
54 }
55
56 async read(rel: string): Promise<Buffer | null> {
57 try {

Callers 1

createWorkspaceRoutesFunction · 0.80

Calls 1

infoMethod · 0.80

Tested by

no test coverage detected