import * as fs from "node:fs/promises"; import * as os from "node:os"; import * as path from "node:path"; // Offline fixture preparation only: this helper never launches OMP or imports its SDK. const marker = "return-desk-fictional-lab-v1"; const quote = (value: string) => `'${value.replaceAll("'", "'\\''")}'`; async function inspect(root: string) { const actual = await fs.realpath(root); const receipt = JSON.parse(await fs.readFile(path.join(actual, "lab.json"), "utf8")); if (receipt.marker !== marker || receipt.root !== actual) throw new Error("Not this helper's owned fictional lab"); const environment = Object.entries({ HOME: path.join(actual, "home"), PI_CODING_AGENT_DIR: path.join(actual, "agent"), TMPDIR: path.join(actual, "tmp"), XDG_CONFIG_HOME: path.join(actual, "config"), XDG_CACHE_HOME: path.join(actual, "cache"), XDG_STATE_HOME: path.join(actual, "state"), XDG_DATA_HOME: path.join(actual, "data"), TMUX_PANE: `%return-desk-${path.basename(actual)}`, TERM: "xterm-256color", }).map(([key, value]) => `${key}=${quote(value)}`).join(" "); const base = `env -i PATH="$PATH" ${environment} "$OMP_BIN" --cwd ${quote(receipt.cwd)} --session-dir ${quote(receipt.sessions)} --no-extensions --no-skills --no-rules --no-lsp --no-tools --no-title`; const yesterday = path.join(receipt.sessions, "2026-08-28T09-00-00-000Z_11111111-1111-4111-8111-111111111111.jsonl"); return { version: 1, ok: true, root: actual, cwd: receipt.cwd, sessions: receipt.sessions, yesterday, prerequisites: [ "Bun for this helper; a configured OMP executable for native interaction; an interactive terminal.", "Run resume and continue in the same actual terminal tab with the same generated environment. OMP prefers stdin's real TTY identity; this helper's TMUX_PANE value is only a synthetic fallback when no TTY path is available.", "Set OMP_BIN to the absolute path of the intended OMP executable. Native commands do not inherit API keys, HOME, session stores, or auth from the ordinary profile.", "If the clean lab profile stops at model/auth setup, stop this exercise there: do not log in, paste keys, or copy credentials. Use the prepared fixture inspection and private evidence instead, and record native interaction as not verified.", "OMP startup can discover providers or refresh metadata and may contact the network even with no prompt. The helper is offline; native OMP commands are not promised network-free.", "Do not submit model prompts in this exercise. Use /resume and exit only. Memory, autolearn, advisors, title generation, skills, rules, extensions, and tools are disabled in the supplied lab settings/flags.", ], commands: { setExecutable: "OMP_BIN=$(command -v omp)", resumeExplicitPath: `${base} --resume ${quote(yesterday)}`, forkExplicitPath: `${base} --fork ${quote(yesterday)}`, resumeExactId: `${base} --resume 11111111-1111-4111-8111-111111111111`, resumePicker: `${base} --resume`, continue: `${base} --continue`, unknownIdentity: `${base} --resume not-a-fictional-session`, inspectWorkspace: `cat ${quote(path.join(receipt.cwd, "today.txt"))}`, }, inSession: ["/resume", "/resume 11111111-1111-4111-8111-111111111111"], expected: [ "The picker begins in current-folder scope. Esc returns to the active session; Esc in the startup picker exits startup.", "Resume yesterday by explicit path, exit, then continue in the same actual terminal tab with the same generated environment: its terminal breadcrumb should prefer yesterday over the newer note.", "The fictional current workspace still says Packed and waiting; conversation history says Ready for pickup.", ], cleanup: "The receipt identifies one newly created temporary root. Remove only that root when finished; no automated deletion operation is provided.", }; } try { const request = JSON.parse(process.argv[2] ?? '{"version":1,"op":"discover"}'); if (request.version !== 1) throw new Error("Expected version: 1"); let result: unknown; if (request.op === "discover") result = { version: 1, ok: true, name: "return-desk-lab", operations: [ { op: "discover", mutates: false }, { op: "act", action: "create", mutates: true, effect: "Create one new temporary fictional lab; never overwrite existing files or launch OMP" }, { op: "inspect", root: "Absolute root from create receipt", mutates: false }, ], }; else if (request.op === "act" && request.action === "create") { const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), "return-desk-lab-"))); for (const dir of ["home", "agent", "tmp", "config", "cache", "state", "data", "project", "sessions"]) await fs.mkdir(path.join(root, dir)); const cwd = path.join(root, "project"); const sessions = path.join(root, "sessions"); const records = (await fs.readFile(path.join(import.meta.dir, "yesterday.jsonl"), "utf8")).trim().split("\n").map(line => JSON.parse(line)); records[0].cwd = cwd; const oldFile = path.join(sessions, "2026-08-28T09-00-00-000Z_11111111-1111-4111-8111-111111111111.jsonl"); await fs.writeFile(oldFile, `${records.map(record => JSON.stringify(record)).join("\n")}\n`); const newer = structuredClone(records); newer[0].id = "33333333-3333-4333-8333-333333333333"; newer[0].title = "Lantern Board: today's unrelated note"; newer[0].timestamp = "2026-08-29T09:00:00.000Z"; newer[1].message.content = "This is a different fictional conversation: today's packaging note."; const newFile = path.join(sessions, "2026-08-29T09-00-00-000Z_33333333-3333-4333-8333-333333333333.jsonl"); await fs.writeFile(newFile, `${newer.map(record => JSON.stringify(record)).join("\n")}\n`); await fs.utimes(oldFile, new Date("2026-08-28T09:00:00Z"), new Date("2026-08-28T09:00:00Z")); await fs.utimes(newFile, new Date("2026-08-29T09:00:00Z"), new Date("2026-08-29T09:00:00Z")); await fs.copyFile(path.join(import.meta.dir, "today.txt"), path.join(cwd, "today.txt")); await fs.writeFile(path.join(root, "agent", "config.yml"), "memory:\n backend: off\nautolearn:\n enabled: false\nadvisor:\n enabled: false\nskills:\n enabled: false\nsecrets:\n enabled: false\nmarketplace:\n autoUpdate: off\nautoResume: false\n"); await fs.writeFile(path.join(root, "lab.json"), `${JSON.stringify({ marker, root, cwd, sessions })}\n`); result = await inspect(root); } else if (request.op === "inspect" && typeof request.root === "string") result = await inspect(request.root); else throw new Error("Unsupported operation; use discover"); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.log(JSON.stringify({ version: 1, ok: false, error: error instanceof Error ? error.message : String(error) })); process.exitCode = 1; }