// A stand-in harness turn for the thread launch tests (row 121, #1615). It // keeps a history in $MOSAIC_SESSION_DIR, which for a thread run is the // thread's store, and a transcript per turn under $HOME/.claude/projects. // It answers with the message body and what both held before this turn, so // a test reads from the reply what a later run of the same thread kept. import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; const request = process.env.MOSAIC_REQUEST ?? ""; const body = request.match(/^Message [^\n]*:\n\n([\s\S]*)$/m)?.[1] ?? ""; const historyFile = join(process.env.MOSAIC_SESSION_DIR, "history"); const before = existsSync(historyFile) ? readFileSync(historyFile, "utf8").split("\n").filter(Boolean) : []; const projects = join(process.env.HOME, ".claude", "projects"); const transcripts = existsSync(projects) ? readdirSync(projects).sort() : null; // A turn longer than the test's idle time. if (body === "slow") Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 3000); appendFileSync(historyFile, `${body}\n`); if (transcripts) writeFileSync(join(projects, `turn-${before.length + 1}.jsonl`), `${JSON.stringify(body)}\n`); process.stdout.write(`THREAD ${JSON.stringify({ body, before, transcripts })}\n`); writeFileSync(process.env.MOSAIC_TURN_MARKER, "done\n");