sessionpipe 0.11.0 → 0.12.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/cli.js +127 -86
- package/dist/cli.js.map +3 -3
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +2 -2
- package/dist/hook.js.map +2 -2
- package/dist/index.js +67 -38
- package/dist/index.js.map +3 -3
- package/dist/worker.js +68 -39
- package/dist/worker.js.map +3 -3
- package/package.json +1 -1
package/dist/hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":";AAkBA,iFAAiF;AACjF,MAAM,WAAW,MAAM;IACrB,KAAK,IAAI,MAAM,CAAC;IAChB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;0FAE0F;AAC1F,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../src/hook.ts"],"names":[],"mappings":";AAkBA,iFAAiF;AACjF,MAAM,WAAW,MAAM;IACrB,KAAK,IAAI,MAAM,CAAC;IAChB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;0FAE0F;AAC1F,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6QhG"}
|
package/dist/hook.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// sessionpipe 0.
|
|
2
|
+
// sessionpipe 0.12.0 · Apache-2.0 · https://sessionpipe.org
|
|
3
3
|
|
|
4
4
|
// src/hook.ts
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
@@ -172,7 +172,7 @@ async function hookMain(argv, env, io) {
|
|
|
172
172
|
}
|
|
173
173
|
function controlAsk(stdin) {
|
|
174
174
|
if (harness !== "claude-code" || event !== "Stop" && event !== "PermissionRequest") return null;
|
|
175
|
-
if (env.SESSIONPIPE_CONTROL_JOB) return null;
|
|
175
|
+
if (env.SESSIONPIPE_CONTROL_JOB && event === "Stop") return null;
|
|
176
176
|
const sock = socketPath(state, env);
|
|
177
177
|
if (process.platform === "win32" ? !existsSync(path2.join(path2.dirname(configFile()), "control.json")) : !existsSync(sock))
|
|
178
178
|
return null;
|
package/dist/hook.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/hook.ts", "../src/control/local.ts"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n// SPDX-License-Identifier: Apache-2.0\n// The hook path. A harness runs `node hook.js <harness> <event>`; this reads stdin,\n// writes one job file, spawns the worker detached, prints what the harness needs\n// (Antigravity's answer) and exits 0 \u2014 in milliseconds, with nothing but node:\n// builtins imported (the build checks that). No network, no schema library, no\n// config parsing beyond one small file read for the throttle.\nimport { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { ask, socketPath } from \"./control/local.js\";\n\n/** A Claude Code session id (the same test as core's notClaudeCode). */\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/** The two streams the hook touches: stdin once, whole; stdout for an answer. */\nexport interface HookIO {\n stdin(): Buffer;\n stdout(text: string): void;\n}\n\n/** One hook run: `argv` is [harness, event, ...] as the harness invoked it, `env` the\n * process environment. Resolves once the job is on its way and any answer printed;\n * the process then exits 0, whatever happened (the hook is invisible to the harness). */\nexport async function hookMain(argv: string[], env: NodeJS.ProcessEnv, io: HookIO): Promise<void> {\n const t0 = process.hrtime.bigint();\n /** The hook's own work, when a control wait follows it (the wait is not the hook's cost). */\n let workMs: number | null = null;\n const [harness = \"\", event = \"\", ...rest] = argv;\n\n function stateDir(): string {\n if (env.SESSIONPIPE_STATE) return path.resolve(env.SESSIONPIPE_STATE);\n const home = os.homedir();\n if (process.platform === \"win32\")\n return path.join(env.LOCALAPPDATA || path.join(home, \"AppData\", \"Local\"), \"sessionpipe\");\n return path.join(env.XDG_STATE_HOME || path.join(home, \".local\", \"state\"), \"sessionpipe\");\n }\n function configFile(): string {\n if (env.SESSIONPIPE_CONFIG) return path.resolve(env.SESSIONPIPE_CONFIG);\n const home = os.homedir();\n if (process.platform === \"win32\")\n return path.join(env.APPDATA || path.join(home, \"AppData\", \"Roaming\"), \"sessionpipe\", \"config.json\");\n return path.join(env.XDG_CONFIG_HOME || path.join(home, \".config\"), \"sessionpipe\", \"config.json\");\n }\n\n // Antigravity parses stdout as the hook's answer; `{}` is \"carry on\" for every event we\n // register. PreToolUse is not one of them: `{}` there is a deny, so an entry an older\n // install left behind asks the person instead (core's AG_STALE_PRETOOL, same bytes).\n if (harness === \"antigravity\") {\n try {\n io.stdout(\n event === \"PreToolUse\"\n ? '{\"decision\":\"ask\",\"reason\":\"sessionpipe: an outdated PreToolUse hook is still loaded. Restart this conversation (or run sessionpipe install) to drop it.\"}\\n'\n : \"{}\\n\",\n );\n } catch {}\n }\n\n const state = stateDir();\n try {\n if (!harness || !event) throw new Error(\"usage: hook <harness> <event>\");\n let stdin = \"\";\n if (harness !== \"codex\" || event !== \"notify\") {\n try {\n const buf = io.stdin();\n stdin = buf.subarray(0, 1024 * 1024).toString(\"utf8\");\n } catch {}\n }\n // Claude Code's status line (install --status-line) runs on every refresh. It shows\n // the account's limits, and only a change becomes a job (limits.observed): at most\n // one a minute per config dir, and none when no sink takes tier 1.\n if (harness === \"claude-code\" && event === \"StatusLine\") {\n const limits = statusLimits(stdin);\n if (limits.line) {\n try {\n io.stdout(`${limits.line}\\n`);\n } catch {}\n }\n if (!limits.sig || !anySinkAbove(0) || !limitsDue(limits.sig)) return finish(false);\n }\n // Tool events are the bulk of what a harness fires. When no sink takes tier \u2265 1\n // they are only a \"still working\" signal: one heartbeat a minute per session.\n const TOOL = /^(PreToolUse|PostToolUse|PostToolUseFailure|BeforeTool|AfterTool|PostInvocation)$/;\n if (TOOL.test(event) && !anySinkAbove(0)) {\n const id = sessionIdOf(stdin);\n if (!id || !beatDue(id)) return finish(false);\n }\n // A Stop asks the daemon BEFORE its event goes to the worker: the worker reports the\n // Stop to the daemon too, and a message queued for this Stop must be taken here,\n // not rerouted because the event got there first.\n const stopAnswer = event === \"Stop\" ? await (controlAsk(stdin) ?? Promise.resolve(null)) : null;\n mkdirSync(path.join(state, \"jobs\"), { recursive: true, mode: 0o700 });\n const job = {\n harness,\n event,\n argv: [harness, event, ...rest],\n stdin,\n cwd: process.cwd(),\n env: pick([\n // Where a harness keeps its config and its sessions, so a job swept by a worker\n // some other harness's hook spawned still resolves this harness's own homes\n // (run.ts sweepJobs runs any stale job file, whatever spawned the worker).\n \"APPDATA\",\n \"CLAUDE_CODE_HOST_SESSION_ID\",\n // session.attended: Claude Code's own word, and SESSIONPIPE_CONTROL_JOB below, the\n // control daemon's mark on a turn it runs for a person's message.\n \"CLAUDE_CODE_SESSION_ATTENDED\",\n \"CLAUDE_CONFIG_DIR\",\n \"CLAUDE_PROJECT_DIR\",\n \"CODEX_HOME\",\n // Devin's payload names no folder at all; this is the only thing that does.\n \"DEVIN_PROJECT_DIR\",\n \"GEMINI_CLI_HOME\",\n \"SESSIONPIPE_CONTROL_JOB\",\n // The launcher a script named for a session it starts (PROTOCOL.md \u00A73 launched_by).\n \"SESSIONPIPE_LAUNCHED_BY\",\n // Devin's config file and session store are both resolved through these.\n \"XDG_CONFIG_HOME\",\n \"XDG_DATA_HOME\",\n ]),\n ppid: process.ppid,\n at: Date.now(),\n };\n const jobFile = path.join(\n state,\n \"jobs\",\n `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}.json`,\n );\n writeFileSync(jobFile, JSON.stringify(job), { mode: 0o600 });\n if (!env.SESSIONPIPE_NO_WORKER) {\n const worker = path.join(path.dirname(fileURLToPath(import.meta.url)), \"worker.js\");\n const p = spawn(process.execPath, [worker, jobFile], { detached: true, stdio: \"ignore\", windowsHide: true, env });\n p.unref();\n }\n if (stopAnswer) {\n try {\n io.stdout(`${stopAnswer}\\n`);\n } catch {}\n }\n // A PermissionRequest waits AFTER its event is on its way, so the receiver already\n // shows the Allow / Deny this answer is for.\n const ctl = event === \"PermissionRequest\" ? controlAsk(stdin) : null;\n if (ctl) {\n workMs = Number(process.hrtime.bigint() - t0) / 1e6;\n const out = await ctl;\n if (out) {\n try {\n io.stdout(`${out}\\n`);\n } catch {}\n }\n }\n return finish(true);\n } catch {\n return finish(false); // the hook must be invisible to the harness\n }\n\n /** Control (spec/CONTROL.md \u00A76, \u00A79): only on a machine with control paired, and only\n * for a message the daemon itself verified. A Stop hook asks for a queued message and\n * answers a block with it; a PermissionRequest hook waits for the person's signed\n * answer while the terminal shows its own prompt, first answer wins. Anything that\n * goes wrong (no daemon, a timeout) prints nothing: the harness carries on as usual. */\n function controlAsk(stdin: string): Promise<string | null> | null {\n if (harness !== \"claude-code\" || (event !== \"Stop\" && event !== \"PermissionRequest\")) return null;\n if (env.SESSIONPIPE_CONTROL_JOB) return null; // a headless turn the daemon itself runs\n const sock = socketPath(state, env);\n if (\n process.platform === \"win32\"\n ? !existsSync(path.join(path.dirname(configFile()), \"control.json\"))\n : !existsSync(sock)\n )\n return null;\n let s: Record<string, unknown>;\n try {\n s = JSON.parse(stdin) as Record<string, unknown>;\n } catch {\n return null;\n }\n const id = typeof s.session_id === \"string\" ? s.session_id : \"\";\n if (!id) return null;\n // Our entry in ~/.claude/settings.json is run by every harness that imports that file\n // \u2014 Devin's `claude` hooks provider is live, not a stub \u2014 and it arrives under the\n // claude-code name. Every Claude Code payload names a transcript and a UUID session;\n // a payload with neither is somebody else's, and must not be parked for up to 125 s\n // waiting on an answer that is not coming. Same test as core's notClaudeCode\n // (claude-code.ts), which the worker applies; repeated here because this file imports\n // nothing but node builtins.\n if (typeof s.transcript_path !== \"string\" && !UUID.test(id)) return null;\n const session = `claude-code:${id}`;\n if (event === \"Stop\")\n return ask(sock, { op: \"stop\", session, active: s.stop_hook_active === true }, 300).then((r) =>\n r?.op === \"block\" ? JSON.stringify({ decision: \"block\", reason: r.reason }) : null,\n );\n // The attention id the adapter puts on attention.needed (claude-code.ts), so the\n // receiver's Allow / Deny names this very prompt.\n const tool =\n typeof s.tool_name === \"string\" && /^[A-Za-z0-9_.:-]{1,120}$/.test(s.tool_name) ? s.tool_name : undefined;\n const turn = typeof s.prompt_id === \"string\" ? s.prompt_id : undefined;\n const attention = `perm-${createHash(\"sha256\")\n .update(`${turn ?? \"\"}|${tool ?? \"\"}|${JSON.stringify(s.tool_input ?? null)}`)\n .digest(\"hex\")\n .slice(0, 16)}`;\n return ask(sock, { op: \"permission\", session, attention, ...(tool ? { tool } : {}) }, 125_000).then((r) =>\n r?.op === \"decision\"\n ? JSON.stringify({\n hookSpecificOutput: {\n hookEventName: \"PermissionRequest\",\n decision:\n r.behavior === \"allow\"\n ? { behavior: \"allow\" }\n : { behavior: \"deny\", message: r.message || \"Denied by the owner (sessionpipe control).\" },\n },\n })\n : null,\n );\n }\n\n /** The timing line; the process exits 0 right after. */\n function finish(spawned: boolean): void {\n const total = Number(process.hrtime.bigint() - t0) / 1e6;\n const ms = workMs ?? total;\n try {\n mkdirSync(state, { recursive: true });\n appendFileSync(\n path.join(state, \"timing.jsonl\"),\n `${JSON.stringify({ at: Date.now(), harness, event, ms: Math.round(ms * 10) / 10, spawned, ...(workMs !== null ? { control_wait_ms: Math.round(total - workMs) } : {}) })}\\n`,\n );\n } catch {}\n }\n function pick(names: string[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const n of names) if (env[n] !== undefined) out[n] = env[n] as string;\n return out;\n }\n function anySinkAbove(tier: number): boolean {\n try {\n const c = JSON.parse(readFileSync(configFile(), \"utf8\")) as { sinks?: { tier?: number; paused?: string }[] };\n return (c.sinks ?? []).some((s) => Number(s.tier) > tier && !s.paused);\n } catch {\n return false;\n }\n }\n function sessionIdOf(stdin: string): string {\n const m = /\"(?:session_id|sessionId|conversationId)\"\\s*:\\s*\"([^\"]{1,128})\"/.exec(stdin);\n return m?.[1] ?? \"\";\n }\n /** The status line's `rate_limits` as one short line (`5h 23% \u00B7 week 41%`), and as\n * the text a change is told by. Empty when the account has none. */\n function statusLimits(stdin: string): { line: string; sig: string } {\n let rl: unknown;\n try {\n rl = (JSON.parse(stdin) as { rate_limits?: unknown }).rate_limits;\n } catch {}\n if (!rl || typeof rl !== \"object\") return { line: \"\", sig: \"\" };\n const label: Record<string, string> = { five_hour: \"5h\", seven_day: \"week\", spend_limit: \"spend\" };\n const parts = Object.entries(rl as Record<string, { used_percentage?: unknown }>)\n .filter(([, w]) => typeof w?.used_percentage === \"number\")\n .map(([id, w]) => `${label[id] ?? id} ${Math.round(w.used_percentage as number)}%`);\n return parts.length ? { line: parts.join(\" \u00B7 \"), sig: JSON.stringify(rl) } : { line: \"\", sig: \"\" };\n }\n /** A change of limits, at most one a minute per config dir (one account each): the\n * stamp holds the last limits sent, its mtime when. */\n function limitsDue(sig: string): boolean {\n const dir = createHash(\"sha256\")\n .update(env.CLAUDE_CONFIG_DIR ?? \"\")\n .digest(\"hex\")\n .slice(0, 12);\n const stamp = path.join(state, \"beats\", `${harness}-limits-${dir}`);\n try {\n if (readFileSync(stamp, \"utf8\") === sig || Date.now() - statSync(stamp).mtimeMs < 60_000) return false;\n } catch {}\n try {\n mkdirSync(path.dirname(stamp), { recursive: true, mode: 0o700 });\n writeFileSync(stamp, sig, { mode: 0o600 });\n } catch {}\n return true;\n }\n /** One heartbeat per minute per session: the stamp file's mtime is the clock. */\n function beatDue(id: string): boolean {\n const stamp = path.join(state, \"beats\", `${harness}-${id.replace(/[^A-Za-z0-9_-]/g, \"_\")}`);\n try {\n if (Date.now() - statSync(stamp).mtimeMs < 60_000) return false;\n } catch {}\n try {\n mkdirSync(path.dirname(stamp), { recursive: true, mode: 0o700 });\n writeFileSync(stamp, \"\", { mode: 0o600 });\n } catch {}\n return true;\n }\n}\n\n// Run as `node hook.js <harness> <event>`; importing this module runs nothing. The main\n// module is known by its real path: node resolves symlinks for import.meta.url, argv[1]\n// keeps the spelling it was given (/var \u2192 /private/var on macOS).\nif (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href)\n hookMain(process.argv.slice(2), process.env, {\n // fd 0 and 1 are the test runner's own (a read of 0 would block it); launcher.test.ts\n // and the bench run these two through the real binary.\n /* v8 ignore next -- see above */\n stdin: () => readFileSync(0),\n /* v8 ignore next -- see above */\n stdout: (text) => writeFileSync(1, text),\n }).then(() => process.exit(0));\n", "// SPDX-License-Identifier: Apache-2.0\n// The daemon's local socket (spec/CONTROL.md \u00A78): how the waiter, the Stop and\n// PermissionRequest hooks and the worker talk to the one daemon on this machine.\n// Line-delimited JSON, one request per connection. A Unix socket in the state\n// directory (0600, in a 0700 dir); a per-user named pipe on Windows. Only node:\n// builtins \u2014 the hook bundle imports this.\nimport net from \"node:net\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport type LocalRequest =\n /** A waiter parks until a message for its session arrives. */\n | { op: \"wait\"; session: string; pid?: number }\n /** A Stop hook asks for a queued message (turn mode). */\n | { op: \"stop\"; session: string; active: boolean }\n /** A PermissionRequest hook parks until a verified answer, or until it's released. */\n | { op: \"permission\"; session: string; attention: string; tool?: string }\n /** The worker reports a hook event: turn state and attention closure. */\n | { op: \"event\"; session: string; event: string; transcript?: string; cwd?: string }\n /** `sessionpipe control status`. */\n | { op: \"status\" }\n /** `sessionpipe update` installed a new copy: restart onto it once nothing is in hand. */\n | { op: \"restart\" }\n /** `sessionpipe pool \u2026` while the daemon runs: the daemon holds the pool's engine\n * (pins, credentials, the listener), so a change goes through it. `status` reads;\n * the rest are CONTROL.md \u00A76's actions, plus `import` (reads this machine's own\n * Claude Code logins, which no receiver may ask for). */\n | { op: \"pool\"; action: PoolOp; account?: string; order?: string[]; code?: string };\n\nexport type PoolOp =\n | \"status\"\n | \"on\"\n | \"off\"\n | \"enable\"\n | \"disable\"\n | \"remove\"\n | \"order\"\n | \"refresh\"\n | \"login.begin\"\n | \"login.complete\"\n | \"import\";\n\nexport type LocalReply =\n | { op: \"message\"; text: string; id: string }\n | { op: \"block\"; reason: string; id: string }\n | { op: \"decision\"; behavior: \"allow\" | \"deny\"; message?: string; id: string }\n | { op: \"none\" }\n /** A newer waiter for the same session took over; this one stops. */\n | { op: \"replaced\" }\n | { op: \"ok\" }\n | { op: \"status\"; status: unknown }\n /** A pool op's answer: the ack it would earn (CONTROL.md \u00A76) and the pool as it now\n * stands (`status`: the fa\u00E7ade's PoolStatus; `detail`: the summary line, or a\n * login.begin's \"<pending id> <URL>\"). */\n | {\n op: \"pool\";\n outcome: \"delivered\" | \"refused\" | \"failed\" | \"unsupported\";\n code?: string;\n detail: string;\n status?: unknown;\n /** `import`: what was added and what was left out (control/pool.ts Imported). */\n imported?: unknown;\n };\n\n/** Where the daemon listens. `SESSIONPIPE_SOCKET` overrides (tests). */\nexport function socketPath(state: string, env: NodeJS.ProcessEnv = process.env): string {\n if (env.SESSIONPIPE_SOCKET) return env.SESSIONPIPE_SOCKET;\n if (process.platform === \"win32\") return `\\\\\\\\.\\\\pipe\\\\sessionpipe-control-${os.userInfo().username}`;\n return path.join(state, \"control.sock\");\n}\n\n/** One request, one reply. `timeoutMs` bounds the whole exchange; null on any\n * failure (no daemon, a timeout, a garbled reply) \u2014 callers treat that as \"none\". */\nexport function ask(sock: string, req: LocalRequest, timeoutMs: number): Promise<LocalReply | null> {\n return new Promise((resolve) => {\n let buf = \"\";\n let done = false;\n const s = net.connect(sock);\n const finish = (r: LocalReply | null) => {\n if (done) return;\n done = true;\n clearTimeout(t);\n s.destroy();\n resolve(r);\n };\n const t = setTimeout(() => finish(null), timeoutMs);\n s.on(\"connect\", () => s.write(`${JSON.stringify(req)}\\n`));\n s.on(\"data\", (d) => {\n buf += d.toString(\"utf8\");\n const i = buf.indexOf(\"\\n\");\n if (i < 0) return;\n try {\n finish(JSON.parse(buf.slice(0, i)) as LocalReply);\n } catch {\n finish(null);\n }\n });\n s.on(\"error\", () => finish(null));\n s.on(\"close\", () => finish(null));\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;AAOA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB,YAAY,WAAW,cAAc,cAAc,UAAU,qBAAqB;AAC3G,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,SAAS,eAAe,qBAAqB;;;ACN7C,OAAO,SAAS;AAChB,OAAO,QAAQ;AACf,OAAO,UAAU;AAyDV,SAAS,WAAW,OAAe,MAAyB,QAAQ,KAAa;AACtF,MAAI,IAAI,mBAAoB,QAAO,IAAI;AACvC,MAAI,QAAQ,aAAa,QAAS,QAAO,oCAAoC,GAAG,SAAS,EAAE,QAAQ;AACnG,SAAO,KAAK,KAAK,OAAO,cAAc;AACxC;AAIO,SAAS,IAAI,MAAc,KAAmB,WAA+C;AAClG,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,MAAM;AACV,QAAI,OAAO;AACX,UAAM,IAAI,IAAI,QAAQ,IAAI;AAC1B,UAAM,SAAS,CAAC,MAAyB;AACvC,UAAI,KAAM;AACV,aAAO;AACP,mBAAa,CAAC;AACd,QAAE,QAAQ;AACV,cAAQ,CAAC;AAAA,IACX;AACA,UAAM,IAAI,WAAW,MAAM,OAAO,IAAI,GAAG,SAAS;AAClD,MAAE,GAAG,WAAW,MAAM,EAAE,MAAM,G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AAO,KAAK;AAAA,EACrB;AAOA,WAAS,WAAW,OAA8C;AAChE,QAAI,YAAY,iBAAkB,UAAU,UAAU,UAAU,oBAAsB,QAAO;
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n// SPDX-License-Identifier: Apache-2.0\n// The hook path. A harness runs `node hook.js <harness> <event>`; this reads stdin,\n// writes one job file, spawns the worker detached, prints what the harness needs\n// (Antigravity's answer) and exits 0 \u2014 in milliseconds, with nothing but node:\n// builtins imported (the build checks that). No network, no schema library, no\n// config parsing beyond one small file read for the throttle.\nimport { spawn } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { ask, socketPath } from \"./control/local.js\";\n\n/** A Claude Code session id (the same test as core's notClaudeCode). */\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/** The two streams the hook touches: stdin once, whole; stdout for an answer. */\nexport interface HookIO {\n stdin(): Buffer;\n stdout(text: string): void;\n}\n\n/** One hook run: `argv` is [harness, event, ...] as the harness invoked it, `env` the\n * process environment. Resolves once the job is on its way and any answer printed;\n * the process then exits 0, whatever happened (the hook is invisible to the harness). */\nexport async function hookMain(argv: string[], env: NodeJS.ProcessEnv, io: HookIO): Promise<void> {\n const t0 = process.hrtime.bigint();\n /** The hook's own work, when a control wait follows it (the wait is not the hook's cost). */\n let workMs: number | null = null;\n const [harness = \"\", event = \"\", ...rest] = argv;\n\n function stateDir(): string {\n if (env.SESSIONPIPE_STATE) return path.resolve(env.SESSIONPIPE_STATE);\n const home = os.homedir();\n if (process.platform === \"win32\")\n return path.join(env.LOCALAPPDATA || path.join(home, \"AppData\", \"Local\"), \"sessionpipe\");\n return path.join(env.XDG_STATE_HOME || path.join(home, \".local\", \"state\"), \"sessionpipe\");\n }\n function configFile(): string {\n if (env.SESSIONPIPE_CONFIG) return path.resolve(env.SESSIONPIPE_CONFIG);\n const home = os.homedir();\n if (process.platform === \"win32\")\n return path.join(env.APPDATA || path.join(home, \"AppData\", \"Roaming\"), \"sessionpipe\", \"config.json\");\n return path.join(env.XDG_CONFIG_HOME || path.join(home, \".config\"), \"sessionpipe\", \"config.json\");\n }\n\n // Antigravity parses stdout as the hook's answer; `{}` is \"carry on\" for every event we\n // register. PreToolUse is not one of them: `{}` there is a deny, so an entry an older\n // install left behind asks the person instead (core's AG_STALE_PRETOOL, same bytes).\n if (harness === \"antigravity\") {\n try {\n io.stdout(\n event === \"PreToolUse\"\n ? '{\"decision\":\"ask\",\"reason\":\"sessionpipe: an outdated PreToolUse hook is still loaded. Restart this conversation (or run sessionpipe install) to drop it.\"}\\n'\n : \"{}\\n\",\n );\n } catch {}\n }\n\n const state = stateDir();\n try {\n if (!harness || !event) throw new Error(\"usage: hook <harness> <event>\");\n let stdin = \"\";\n if (harness !== \"codex\" || event !== \"notify\") {\n try {\n const buf = io.stdin();\n stdin = buf.subarray(0, 1024 * 1024).toString(\"utf8\");\n } catch {}\n }\n // Claude Code's status line (install --status-line) runs on every refresh. It shows\n // the account's limits, and only a change becomes a job (limits.observed): at most\n // one a minute per config dir, and none when no sink takes tier 1.\n if (harness === \"claude-code\" && event === \"StatusLine\") {\n const limits = statusLimits(stdin);\n if (limits.line) {\n try {\n io.stdout(`${limits.line}\\n`);\n } catch {}\n }\n if (!limits.sig || !anySinkAbove(0) || !limitsDue(limits.sig)) return finish(false);\n }\n // Tool events are the bulk of what a harness fires. When no sink takes tier \u2265 1\n // they are only a \"still working\" signal: one heartbeat a minute per session.\n const TOOL = /^(PreToolUse|PostToolUse|PostToolUseFailure|BeforeTool|AfterTool|PostInvocation)$/;\n if (TOOL.test(event) && !anySinkAbove(0)) {\n const id = sessionIdOf(stdin);\n if (!id || !beatDue(id)) return finish(false);\n }\n // A Stop asks the daemon BEFORE its event goes to the worker: the worker reports the\n // Stop to the daemon too, and a message queued for this Stop must be taken here,\n // not rerouted because the event got there first.\n const stopAnswer = event === \"Stop\" ? await (controlAsk(stdin) ?? Promise.resolve(null)) : null;\n mkdirSync(path.join(state, \"jobs\"), { recursive: true, mode: 0o700 });\n const job = {\n harness,\n event,\n argv: [harness, event, ...rest],\n stdin,\n cwd: process.cwd(),\n env: pick([\n // Where a harness keeps its config and its sessions, so a job swept by a worker\n // some other harness's hook spawned still resolves this harness's own homes\n // (run.ts sweepJobs runs any stale job file, whatever spawned the worker).\n \"APPDATA\",\n \"CLAUDE_CODE_HOST_SESSION_ID\",\n // session.attended: Claude Code's own word, and SESSIONPIPE_CONTROL_JOB below, the\n // control daemon's mark on a turn it runs for a person's message.\n \"CLAUDE_CODE_SESSION_ATTENDED\",\n \"CLAUDE_CONFIG_DIR\",\n \"CLAUDE_PROJECT_DIR\",\n \"CODEX_HOME\",\n // Devin's payload names no folder at all; this is the only thing that does.\n \"DEVIN_PROJECT_DIR\",\n \"GEMINI_CLI_HOME\",\n \"SESSIONPIPE_CONTROL_JOB\",\n // The launcher a script named for a session it starts (PROTOCOL.md \u00A73 launched_by).\n \"SESSIONPIPE_LAUNCHED_BY\",\n // Devin's config file and session store are both resolved through these.\n \"XDG_CONFIG_HOME\",\n \"XDG_DATA_HOME\",\n ]),\n ppid: process.ppid,\n at: Date.now(),\n };\n const jobFile = path.join(\n state,\n \"jobs\",\n `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}.json`,\n );\n writeFileSync(jobFile, JSON.stringify(job), { mode: 0o600 });\n if (!env.SESSIONPIPE_NO_WORKER) {\n const worker = path.join(path.dirname(fileURLToPath(import.meta.url)), \"worker.js\");\n const p = spawn(process.execPath, [worker, jobFile], { detached: true, stdio: \"ignore\", windowsHide: true, env });\n p.unref();\n }\n if (stopAnswer) {\n try {\n io.stdout(`${stopAnswer}\\n`);\n } catch {}\n }\n // A PermissionRequest waits AFTER its event is on its way, so the receiver already\n // shows the Allow / Deny this answer is for.\n const ctl = event === \"PermissionRequest\" ? controlAsk(stdin) : null;\n if (ctl) {\n workMs = Number(process.hrtime.bigint() - t0) / 1e6;\n const out = await ctl;\n if (out) {\n try {\n io.stdout(`${out}\\n`);\n } catch {}\n }\n }\n return finish(true);\n } catch {\n return finish(false); // the hook must be invisible to the harness\n }\n\n /** Control (spec/CONTROL.md \u00A76, \u00A79): only on a machine with control paired, and only\n * for a message the daemon itself verified. A Stop hook asks for a queued message and\n * answers a block with it; a PermissionRequest hook waits for the person's signed\n * answer while the terminal shows its own prompt, first answer wins. Anything that\n * goes wrong (no daemon, a timeout) prints nothing: the harness carries on as usual. */\n function controlAsk(stdin: string): Promise<string | null> | null {\n if (harness !== \"claude-code\" || (event !== \"Stop\" && event !== \"PermissionRequest\")) return null;\n // A turn the daemon itself runs (a held Agent SDK session, a headless resume) never\n // asks at its Stop: the daemon hands that session its next message itself. Its\n // permission prompts do park: nobody is at a terminal there, so the owner's signed\n // answer is the only one it can get (a session started at edits, auto or inherit\n // asks before a Bash).\n if (env.SESSIONPIPE_CONTROL_JOB && event === \"Stop\") return null;\n const sock = socketPath(state, env);\n if (\n process.platform === \"win32\"\n ? !existsSync(path.join(path.dirname(configFile()), \"control.json\"))\n : !existsSync(sock)\n )\n return null;\n let s: Record<string, unknown>;\n try {\n s = JSON.parse(stdin) as Record<string, unknown>;\n } catch {\n return null;\n }\n const id = typeof s.session_id === \"string\" ? s.session_id : \"\";\n if (!id) return null;\n // Our entry in ~/.claude/settings.json is run by every harness that imports that file\n // \u2014 Devin's `claude` hooks provider is live, not a stub \u2014 and it arrives under the\n // claude-code name. Every Claude Code payload names a transcript and a UUID session;\n // a payload with neither is somebody else's, and must not be parked for up to 125 s\n // waiting on an answer that is not coming. Same test as core's notClaudeCode\n // (claude-code.ts), which the worker applies; repeated here because this file imports\n // nothing but node builtins.\n if (typeof s.transcript_path !== \"string\" && !UUID.test(id)) return null;\n const session = `claude-code:${id}`;\n if (event === \"Stop\")\n return ask(sock, { op: \"stop\", session, active: s.stop_hook_active === true }, 300).then((r) =>\n r?.op === \"block\" ? JSON.stringify({ decision: \"block\", reason: r.reason }) : null,\n );\n // The attention id the adapter puts on attention.needed (claude-code.ts), so the\n // receiver's Allow / Deny names this very prompt.\n const tool =\n typeof s.tool_name === \"string\" && /^[A-Za-z0-9_.:-]{1,120}$/.test(s.tool_name) ? s.tool_name : undefined;\n const turn = typeof s.prompt_id === \"string\" ? s.prompt_id : undefined;\n const attention = `perm-${createHash(\"sha256\")\n .update(`${turn ?? \"\"}|${tool ?? \"\"}|${JSON.stringify(s.tool_input ?? null)}`)\n .digest(\"hex\")\n .slice(0, 16)}`;\n return ask(sock, { op: \"permission\", session, attention, ...(tool ? { tool } : {}) }, 125_000).then((r) =>\n r?.op === \"decision\"\n ? JSON.stringify({\n hookSpecificOutput: {\n hookEventName: \"PermissionRequest\",\n decision:\n r.behavior === \"allow\"\n ? { behavior: \"allow\" }\n : { behavior: \"deny\", message: r.message || \"Denied by the owner (sessionpipe control).\" },\n },\n })\n : null,\n );\n }\n\n /** The timing line; the process exits 0 right after. */\n function finish(spawned: boolean): void {\n const total = Number(process.hrtime.bigint() - t0) / 1e6;\n const ms = workMs ?? total;\n try {\n mkdirSync(state, { recursive: true });\n appendFileSync(\n path.join(state, \"timing.jsonl\"),\n `${JSON.stringify({ at: Date.now(), harness, event, ms: Math.round(ms * 10) / 10, spawned, ...(workMs !== null ? { control_wait_ms: Math.round(total - workMs) } : {}) })}\\n`,\n );\n } catch {}\n }\n function pick(names: string[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const n of names) if (env[n] !== undefined) out[n] = env[n] as string;\n return out;\n }\n function anySinkAbove(tier: number): boolean {\n try {\n const c = JSON.parse(readFileSync(configFile(), \"utf8\")) as { sinks?: { tier?: number; paused?: string }[] };\n return (c.sinks ?? []).some((s) => Number(s.tier) > tier && !s.paused);\n } catch {\n return false;\n }\n }\n function sessionIdOf(stdin: string): string {\n const m = /\"(?:session_id|sessionId|conversationId)\"\\s*:\\s*\"([^\"]{1,128})\"/.exec(stdin);\n return m?.[1] ?? \"\";\n }\n /** The status line's `rate_limits` as one short line (`5h 23% \u00B7 week 41%`), and as\n * the text a change is told by. Empty when the account has none. */\n function statusLimits(stdin: string): { line: string; sig: string } {\n let rl: unknown;\n try {\n rl = (JSON.parse(stdin) as { rate_limits?: unknown }).rate_limits;\n } catch {}\n if (!rl || typeof rl !== \"object\") return { line: \"\", sig: \"\" };\n const label: Record<string, string> = { five_hour: \"5h\", seven_day: \"week\", spend_limit: \"spend\" };\n const parts = Object.entries(rl as Record<string, { used_percentage?: unknown }>)\n .filter(([, w]) => typeof w?.used_percentage === \"number\")\n .map(([id, w]) => `${label[id] ?? id} ${Math.round(w.used_percentage as number)}%`);\n return parts.length ? { line: parts.join(\" \u00B7 \"), sig: JSON.stringify(rl) } : { line: \"\", sig: \"\" };\n }\n /** A change of limits, at most one a minute per config dir (one account each): the\n * stamp holds the last limits sent, its mtime when. */\n function limitsDue(sig: string): boolean {\n const dir = createHash(\"sha256\")\n .update(env.CLAUDE_CONFIG_DIR ?? \"\")\n .digest(\"hex\")\n .slice(0, 12);\n const stamp = path.join(state, \"beats\", `${harness}-limits-${dir}`);\n try {\n if (readFileSync(stamp, \"utf8\") === sig || Date.now() - statSync(stamp).mtimeMs < 60_000) return false;\n } catch {}\n try {\n mkdirSync(path.dirname(stamp), { recursive: true, mode: 0o700 });\n writeFileSync(stamp, sig, { mode: 0o600 });\n } catch {}\n return true;\n }\n /** One heartbeat per minute per session: the stamp file's mtime is the clock. */\n function beatDue(id: string): boolean {\n const stamp = path.join(state, \"beats\", `${harness}-${id.replace(/[^A-Za-z0-9_-]/g, \"_\")}`);\n try {\n if (Date.now() - statSync(stamp).mtimeMs < 60_000) return false;\n } catch {}\n try {\n mkdirSync(path.dirname(stamp), { recursive: true, mode: 0o700 });\n writeFileSync(stamp, \"\", { mode: 0o600 });\n } catch {}\n return true;\n }\n}\n\n// Run as `node hook.js <harness> <event>`; importing this module runs nothing. The main\n// module is known by its real path: node resolves symlinks for import.meta.url, argv[1]\n// keeps the spelling it was given (/var \u2192 /private/var on macOS).\nif (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href)\n hookMain(process.argv.slice(2), process.env, {\n // fd 0 and 1 are the test runner's own (a read of 0 would block it); launcher.test.ts\n // and the bench run these two through the real binary.\n /* v8 ignore next -- see above */\n stdin: () => readFileSync(0),\n /* v8 ignore next -- see above */\n stdout: (text) => writeFileSync(1, text),\n }).then(() => process.exit(0));\n", "// SPDX-License-Identifier: Apache-2.0\n// The daemon's local socket (spec/CONTROL.md \u00A78): how the waiter, the Stop and\n// PermissionRequest hooks and the worker talk to the one daemon on this machine.\n// Line-delimited JSON, one request per connection. A Unix socket in the state\n// directory (0600, in a 0700 dir); a per-user named pipe on Windows. Only node:\n// builtins \u2014 the hook bundle imports this.\nimport net from \"node:net\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport type LocalRequest =\n /** A waiter parks until a message for its session arrives. */\n | { op: \"wait\"; session: string; pid?: number }\n /** A Stop hook asks for a queued message (turn mode). */\n | { op: \"stop\"; session: string; active: boolean }\n /** A PermissionRequest hook parks until a verified answer, or until it's released. */\n | { op: \"permission\"; session: string; attention: string; tool?: string }\n /** The worker reports a hook event: turn state and attention closure. */\n | { op: \"event\"; session: string; event: string; transcript?: string; cwd?: string }\n /** `sessionpipe control status`. */\n | { op: \"status\" }\n /** `sessionpipe update` installed a new copy: restart onto it once nothing is in hand. */\n | { op: \"restart\" }\n /** `sessionpipe pool \u2026` while the daemon runs: the daemon holds the pool's engine\n * (pins, credentials, the listener), so a change goes through it. `status` reads;\n * the rest are CONTROL.md \u00A76's actions, plus `import` (reads this machine's own\n * Claude Code logins, which no receiver may ask for). */\n | { op: \"pool\"; action: PoolOp; account?: string; order?: string[]; code?: string };\n\nexport type PoolOp =\n | \"status\"\n | \"on\"\n | \"off\"\n | \"enable\"\n | \"disable\"\n | \"remove\"\n | \"order\"\n | \"refresh\"\n | \"login.begin\"\n | \"login.complete\"\n | \"import\";\n\nexport type LocalReply =\n | { op: \"message\"; text: string; id: string }\n | { op: \"block\"; reason: string; id: string }\n | { op: \"decision\"; behavior: \"allow\" | \"deny\"; message?: string; id: string }\n | { op: \"none\" }\n /** A newer waiter for the same session took over; this one stops. */\n | { op: \"replaced\" }\n | { op: \"ok\" }\n | { op: \"status\"; status: unknown }\n /** A pool op's answer: the ack it would earn (CONTROL.md \u00A76) and the pool as it now\n * stands (`status`: the fa\u00E7ade's PoolStatus; `detail`: the summary line, or a\n * login.begin's \"<pending id> <URL>\"). */\n | {\n op: \"pool\";\n outcome: \"delivered\" | \"refused\" | \"failed\" | \"unsupported\";\n code?: string;\n detail: string;\n status?: unknown;\n /** `import`: what was added and what was left out (control/pool.ts Imported). */\n imported?: unknown;\n };\n\n/** Where the daemon listens. `SESSIONPIPE_SOCKET` overrides (tests). */\nexport function socketPath(state: string, env: NodeJS.ProcessEnv = process.env): string {\n if (env.SESSIONPIPE_SOCKET) return env.SESSIONPIPE_SOCKET;\n if (process.platform === \"win32\") return `\\\\\\\\.\\\\pipe\\\\sessionpipe-control-${os.userInfo().username}`;\n return path.join(state, \"control.sock\");\n}\n\n/** One request, one reply. `timeoutMs` bounds the whole exchange; null on any\n * failure (no daemon, a timeout, a garbled reply) \u2014 callers treat that as \"none\". */\nexport function ask(sock: string, req: LocalRequest, timeoutMs: number): Promise<LocalReply | null> {\n return new Promise((resolve) => {\n let buf = \"\";\n let done = false;\n const s = net.connect(sock);\n const finish = (r: LocalReply | null) => {\n if (done) return;\n done = true;\n clearTimeout(t);\n s.destroy();\n resolve(r);\n };\n const t = setTimeout(() => finish(null), timeoutMs);\n s.on(\"connect\", () => s.write(`${JSON.stringify(req)}\\n`));\n s.on(\"data\", (d) => {\n buf += d.toString(\"utf8\");\n const i = buf.indexOf(\"\\n\");\n if (i < 0) return;\n try {\n finish(JSON.parse(buf.slice(0, i)) as LocalReply);\n } catch {\n finish(null);\n }\n });\n s.on(\"error\", () => finish(null));\n s.on(\"close\", () => finish(null));\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAOA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB,YAAY,WAAW,cAAc,cAAc,UAAU,qBAAqB;AAC3G,OAAOA,SAAQ;AACf,OAAOC,WAAU;AACjB,SAAS,eAAe,qBAAqB;;;ACN7C,OAAO,SAAS;AAChB,OAAO,QAAQ;AACf,OAAO,UAAU;AAyDV,SAAS,WAAW,OAAe,MAAyB,QAAQ,KAAa;AACtF,MAAI,IAAI,mBAAoB,QAAO,IAAI;AACvC,MAAI,QAAQ,aAAa,QAAS,QAAO,oCAAoC,GAAG,SAAS,EAAE,QAAQ;AACnG,SAAO,KAAK,KAAK,OAAO,cAAc;AACxC;AAIO,SAAS,IAAI,MAAc,KAAmB,WAA+C;AAClG,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,QAAI,MAAM;AACV,QAAI,OAAO;AACX,UAAM,IAAI,IAAI,QAAQ,IAAI;AAC1B,UAAM,SAAS,CAAC,MAAyB;AACvC,UAAI,KAAM;AACV,aAAO;AACP,mBAAa,CAAC;AACd,QAAE,QAAQ;AACV,cAAQ,CAAC;AAAA,IACX;AACA,UAAM,IAAI,WAAW,MAAM,OAAO,IAAI,GAAG,SAAS;AAClD,MAAE,GAAG,WAAW,MAAM,EAAE,MAAM,GAAG,KAAK,UAAU,GAAG,CAAC;AAAA,CAAI,CAAC;AACzD,MAAE,GAAG,QAAQ,CAAC,MAAM;AAClB,aAAO,EAAE,SAAS,MAAM;AACxB,YAAM,IAAI,IAAI,QAAQ,IAAI;AAC1B,UAAI,IAAI,EAAG;AACX,UAAI;AACF,eAAO,KAAK,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC,CAAe;AAAA,MAClD,QAAQ;AACN,eAAO,IAAI;AAAA,MACb;AAAA,IACF,CAAC;AACD,MAAE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AC/D,oBAAc,OAAO,IAAI,EAAE,MAAM,IAAM,CAAC;AAAA,IAC1C,QAAQ;AAAA,IAAC;AACT,WAAO;AAAA,EACT;AACF;AAKA,IAAI,QAAQ,KAAK,CAAC,KAAK,YAAY,QAAQ,cAAc,aAAa,QAAQ,KAAK,CAAC,CAAC,CAAC,EAAE;AACtF,WAAS,QAAQ,KAAK,MAAM,CAAC,GAAG,QAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,IAI3C,OAAO,MAAM,aAAa,CAAC;AAAA;AAAA,IAE3B,QAAQ,CAAC,SAAS,cAAc,GAAG,IAAI;AAAA,EACzC,CAAC,EAAE,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC;",
|
|
6
6
|
"names": ["os", "path", "path", "os"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// sessionpipe 0.
|
|
1
|
+
// sessionpipe 0.12.0 · Apache-2.0 · https://sessionpipe.org
|
|
2
2
|
|
|
3
3
|
// src/http-sink.ts
|
|
4
4
|
import { createHash, createHmac } from "node:crypto";
|
|
@@ -101,7 +101,7 @@ import {
|
|
|
101
101
|
existsSync as existsSync10,
|
|
102
102
|
mkdirSync as mkdirSync8,
|
|
103
103
|
readdirSync as readdirSync6,
|
|
104
|
-
readFileSync as
|
|
104
|
+
readFileSync as readFileSync10,
|
|
105
105
|
renameSync as renameSync3,
|
|
106
106
|
statSync as statSync6,
|
|
107
107
|
unlinkSync as unlinkSync4,
|
|
@@ -722,13 +722,7 @@ var claudeCode = {
|
|
|
722
722
|
);
|
|
723
723
|
break;
|
|
724
724
|
case "Stop":
|
|
725
|
-
events.push(
|
|
726
|
-
ev("turn.ended", {
|
|
727
|
-
turn_id,
|
|
728
|
-
reason: "stop",
|
|
729
|
-
background: Array.isArray(s.background_tasks) ? s.background_tasks.length : void 0
|
|
730
|
-
})
|
|
731
|
-
);
|
|
725
|
+
events.push(ev("turn.ended", { turn_id, reason: "stop", background: backgroundCount(s.background_tasks) }));
|
|
732
726
|
break;
|
|
733
727
|
case "StopFailure":
|
|
734
728
|
events.push(
|
|
@@ -751,7 +745,8 @@ var claudeCode = {
|
|
|
751
745
|
events.push(
|
|
752
746
|
ev("subagent.ended", {
|
|
753
747
|
agent_id: String(s.agent_id ?? ""),
|
|
754
|
-
agent_type: typeof s.agent_type === "string" ? s.agent_type : void 0
|
|
748
|
+
agent_type: typeof s.agent_type === "string" ? s.agent_type : void 0,
|
|
749
|
+
background: backgroundCount(s.background_tasks, String(s.agent_id ?? ""))
|
|
755
750
|
})
|
|
756
751
|
);
|
|
757
752
|
break;
|
|
@@ -826,6 +821,15 @@ var claudeCode = {
|
|
|
826
821
|
return rows2;
|
|
827
822
|
}
|
|
828
823
|
};
|
|
824
|
+
var WAITER_RE = /(?:^|[\s"'`/\\])sessionpipe(?:\.\w+)?["']?\s+wait(?:\s|$)/;
|
|
825
|
+
function backgroundCount(tasks, ending) {
|
|
826
|
+
if (!Array.isArray(tasks)) return void 0;
|
|
827
|
+
return tasks.filter((t) => {
|
|
828
|
+
const task = t;
|
|
829
|
+
if (ending !== void 0 && task?.id === ending) return false;
|
|
830
|
+
return !(typeof task?.command === "string" && WAITER_RE.test(task.command));
|
|
831
|
+
}).length;
|
|
832
|
+
}
|
|
829
833
|
var LINE_REFRESH_S = 60;
|
|
830
834
|
function statusLine(file, want, cmd) {
|
|
831
835
|
const f = readJsonFile(file);
|
|
@@ -1254,7 +1258,7 @@ async function claudeAiTitle(bridge, token) {
|
|
|
1254
1258
|
}
|
|
1255
1259
|
|
|
1256
1260
|
// ../core/src/adapters/headless.ts
|
|
1257
|
-
import { accessSync, constants, statSync as statSync3 } from "node:fs";
|
|
1261
|
+
import { accessSync, constants, readFileSync as readFileSync3, statSync as statSync3 } from "node:fs";
|
|
1258
1262
|
import path5 from "node:path";
|
|
1259
1263
|
var JOB_TIMEOUT_MS = 30 * 6e4;
|
|
1260
1264
|
var OUT_CAP = 1024 * 1024;
|
|
@@ -1276,13 +1280,38 @@ function findBinary(o) {
|
|
|
1276
1280
|
for (const d of o.dirs) for (const n of o.names) if (isExe(path5.join(d, n))) return path5.join(d, n);
|
|
1277
1281
|
return null;
|
|
1278
1282
|
}
|
|
1283
|
+
function shimTarget(shim) {
|
|
1284
|
+
let text = "";
|
|
1285
|
+
try {
|
|
1286
|
+
text = readFileSync3(shim, "utf8");
|
|
1287
|
+
} catch {
|
|
1288
|
+
return null;
|
|
1289
|
+
}
|
|
1290
|
+
const m = /"%(?:~dp0|dp0%)\\([^"]+)"\s+%\*/.exec(text);
|
|
1291
|
+
if (!m) return null;
|
|
1292
|
+
const target = path5.resolve(path5.dirname(shim), m[1].split("\\").join(path5.sep));
|
|
1293
|
+
try {
|
|
1294
|
+
return statSync3(target).isFile() ? target : null;
|
|
1295
|
+
} catch {
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
function spawnable(bin, args) {
|
|
1300
|
+
if (!/\.(cmd|bat)$/i.test(bin)) return { file: bin, args };
|
|
1301
|
+
const target = shimTarget(bin);
|
|
1302
|
+
return target ? { file: process.execPath, args: [target, ...args] } : null;
|
|
1303
|
+
}
|
|
1304
|
+
function probe(bin, args) {
|
|
1305
|
+
const s = spawnable(bin, args);
|
|
1306
|
+
return s ? { ...s, shell: false } : { file: [`"${bin}"`, ...args].join(" "), args: [], shell: true };
|
|
1307
|
+
}
|
|
1279
1308
|
|
|
1280
1309
|
// ../core/src/adapters/antigravity.ts
|
|
1281
1310
|
import {
|
|
1282
1311
|
existsSync as existsSync3,
|
|
1283
1312
|
mkdirSync as mkdirSync2,
|
|
1284
1313
|
readdirSync as readdirSync3,
|
|
1285
|
-
readFileSync as
|
|
1314
|
+
readFileSync as readFileSync4,
|
|
1286
1315
|
realpathSync,
|
|
1287
1316
|
statSync as statSync4,
|
|
1288
1317
|
unlinkSync as unlinkSync2,
|
|
@@ -1411,7 +1440,7 @@ var antigravity = {
|
|
|
1411
1440
|
readTranscript(file, fromLine) {
|
|
1412
1441
|
let text = "";
|
|
1413
1442
|
try {
|
|
1414
|
-
text =
|
|
1443
|
+
text = readFileSync4(file, "utf8");
|
|
1415
1444
|
} catch {
|
|
1416
1445
|
return { turns: [], line: fromLine };
|
|
1417
1446
|
}
|
|
@@ -1490,7 +1519,7 @@ function agProjects(dir) {
|
|
|
1490
1519
|
if (!ID_RE.test(id)) continue;
|
|
1491
1520
|
let j;
|
|
1492
1521
|
try {
|
|
1493
|
-
j = JSON.parse(
|
|
1522
|
+
j = JSON.parse(readFileSync4(path6.join(dir, n), "utf8"));
|
|
1494
1523
|
} catch {
|
|
1495
1524
|
continue;
|
|
1496
1525
|
}
|
|
@@ -1527,7 +1556,7 @@ function antigravityRemoteUrl(transcript, opts) {
|
|
|
1527
1556
|
for (const d of dirs) {
|
|
1528
1557
|
try {
|
|
1529
1558
|
const m = /installation_uuid:\s*"([0-9a-f-]{36})"/i.exec(
|
|
1530
|
-
|
|
1559
|
+
readFileSync4(path6.join(d, "antigravity_state.pbtxt"), "utf8")
|
|
1531
1560
|
);
|
|
1532
1561
|
if (!m) continue;
|
|
1533
1562
|
const base = `https://antigravity.google.com/r/${m[1]}-v2`;
|
|
@@ -1587,7 +1616,7 @@ var enc = new TextEncoder();
|
|
|
1587
1616
|
var dec = new TextDecoder();
|
|
1588
1617
|
|
|
1589
1618
|
// ../core/src/adapters/codex.ts
|
|
1590
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync4, readFileSync as
|
|
1619
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync4, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1591
1620
|
import path7 from "node:path";
|
|
1592
1621
|
|
|
1593
1622
|
// ../core/src/adapters/codex-config.ts
|
|
@@ -1744,7 +1773,7 @@ function installNotify(cmd, env) {
|
|
|
1744
1773
|
const file = configFile2(env);
|
|
1745
1774
|
let text = "";
|
|
1746
1775
|
try {
|
|
1747
|
-
text =
|
|
1776
|
+
text = readFileSync5(file, "utf8");
|
|
1748
1777
|
} catch {
|
|
1749
1778
|
}
|
|
1750
1779
|
const argv = cmd([NAME3, "notify"]).argv;
|
|
@@ -1790,7 +1819,7 @@ function uninstallNotify(env) {
|
|
|
1790
1819
|
const file = configFile2(env);
|
|
1791
1820
|
let text;
|
|
1792
1821
|
try {
|
|
1793
|
-
text =
|
|
1822
|
+
text = readFileSync5(file, "utf8");
|
|
1794
1823
|
} catch {
|
|
1795
1824
|
return { file, changed: false };
|
|
1796
1825
|
}
|
|
@@ -1862,7 +1891,7 @@ var codex = {
|
|
|
1862
1891
|
];
|
|
1863
1892
|
let text = "";
|
|
1864
1893
|
try {
|
|
1865
|
-
text =
|
|
1894
|
+
text = readFileSync5(configFile2(env), "utf8");
|
|
1866
1895
|
} catch {
|
|
1867
1896
|
}
|
|
1868
1897
|
const n = readNotify(text);
|
|
@@ -1989,7 +2018,7 @@ var codex = {
|
|
|
1989
2018
|
readTranscript(file, fromLine) {
|
|
1990
2019
|
let text = "";
|
|
1991
2020
|
try {
|
|
1992
|
-
text =
|
|
2021
|
+
text = readFileSync5(file, "utf8");
|
|
1993
2022
|
} catch {
|
|
1994
2023
|
return { turns: [], line: fromLine };
|
|
1995
2024
|
}
|
|
@@ -2510,7 +2539,7 @@ function devinAccount(env = process.env) {
|
|
|
2510
2539
|
|
|
2511
2540
|
// ../core/src/adapters/gemini-cli.ts
|
|
2512
2541
|
import { execFileSync as execFileSync4 } from "node:child_process";
|
|
2513
|
-
import { existsSync as existsSync7, readFileSync as
|
|
2542
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6 } from "node:fs";
|
|
2514
2543
|
import path9 from "node:path";
|
|
2515
2544
|
var NAME5 = "gemini-cli";
|
|
2516
2545
|
var GEMINI_EVENTS = [
|
|
@@ -2532,14 +2561,14 @@ function geminiVersion(platform = process.platform, env = process.env) {
|
|
|
2532
2561
|
const win = platform === "win32";
|
|
2533
2562
|
const bin = win ? findBinary({ names: ["gemini.exe", "gemini.cmd"], dirs: [path9.dirname(process.execPath)], env }) : "gemini";
|
|
2534
2563
|
if (!bin) throw new Error("no gemini on PATH");
|
|
2535
|
-
const
|
|
2564
|
+
const c = probe(bin, ["--version"]);
|
|
2565
|
+
return execFileSync4(c.file, c.args, {
|
|
2536
2566
|
encoding: "utf8",
|
|
2537
2567
|
timeout: 4e3,
|
|
2538
2568
|
stdio: ["ignore", "pipe", "ignore"],
|
|
2539
|
-
env
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
return out.trim();
|
|
2569
|
+
env,
|
|
2570
|
+
shell: c.shell
|
|
2571
|
+
}).trim();
|
|
2543
2572
|
}
|
|
2544
2573
|
function geminiHooksActive(settingsFile) {
|
|
2545
2574
|
const tools = readJson(settingsFile).tools;
|
|
@@ -2664,7 +2693,7 @@ var geminiCli = {
|
|
|
2664
2693
|
readTranscript(file, fromLine) {
|
|
2665
2694
|
let text = "";
|
|
2666
2695
|
try {
|
|
2667
|
-
text =
|
|
2696
|
+
text = readFileSync6(file, "utf8");
|
|
2668
2697
|
} catch {
|
|
2669
2698
|
return { turns: [], line: fromLine };
|
|
2670
2699
|
}
|
|
@@ -2704,12 +2733,12 @@ var ADAPTERS = [claudeCode, codex, geminiCli, antigravity, devin];
|
|
|
2704
2733
|
var adapterByName = (name) => ADAPTERS.find((a) => a.name === name);
|
|
2705
2734
|
|
|
2706
2735
|
// ../core/src/config.ts
|
|
2707
|
-
import { chmodSync, existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as
|
|
2736
|
+
import { chmodSync, existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
2708
2737
|
import path10 from "node:path";
|
|
2709
2738
|
var DEFAULT_CONFIG = { sinks: [], harnesses: {}, update_check: true, keep_days: 30 };
|
|
2710
2739
|
function readConfig(file = configFile()) {
|
|
2711
2740
|
try {
|
|
2712
|
-
const j = JSON.parse(
|
|
2741
|
+
const j = JSON.parse(readFileSync7(file, "utf8"));
|
|
2713
2742
|
return {
|
|
2714
2743
|
...DEFAULT_CONFIG,
|
|
2715
2744
|
...j,
|
|
@@ -2809,7 +2838,7 @@ import {
|
|
|
2809
2838
|
mkdirSync as mkdirSync5,
|
|
2810
2839
|
openSync as openSync2,
|
|
2811
2840
|
readdirSync as readdirSync5,
|
|
2812
|
-
readFileSync as
|
|
2841
|
+
readFileSync as readFileSync8,
|
|
2813
2842
|
readSync as readSync2,
|
|
2814
2843
|
renameSync,
|
|
2815
2844
|
statSync as statSync5,
|
|
@@ -2839,7 +2868,7 @@ var Outbox = class {
|
|
|
2839
2868
|
const f = this.seqFile(ref);
|
|
2840
2869
|
let n = -1;
|
|
2841
2870
|
try {
|
|
2842
|
-
const t =
|
|
2871
|
+
const t = readFileSync8(f, "utf8").trim();
|
|
2843
2872
|
if (/^\d+$/.test(t)) n = Number(t);
|
|
2844
2873
|
} catch {
|
|
2845
2874
|
}
|
|
@@ -2851,7 +2880,7 @@ var Outbox = class {
|
|
|
2851
2880
|
lastSeqInFile(ref) {
|
|
2852
2881
|
const f = this.file(ref);
|
|
2853
2882
|
if (!existsSync9(f)) return -1;
|
|
2854
|
-
const lines =
|
|
2883
|
+
const lines = readFileSync8(f, "utf8").trim().split("\n");
|
|
2855
2884
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
2856
2885
|
try {
|
|
2857
2886
|
const j = JSON.parse(lines[i]);
|
|
@@ -2974,7 +3003,7 @@ var Cursors = class {
|
|
|
2974
3003
|
}
|
|
2975
3004
|
read() {
|
|
2976
3005
|
try {
|
|
2977
|
-
return JSON.parse(
|
|
3006
|
+
return JSON.parse(readFileSync8(this.file(), "utf8"));
|
|
2978
3007
|
} catch {
|
|
2979
3008
|
return {};
|
|
2980
3009
|
}
|
|
@@ -2998,7 +3027,7 @@ function takeNamedLock(root, name, staleMs = 5 * 6e4) {
|
|
|
2998
3027
|
mkdirSync5(dir, { recursive: true, mode: 448 });
|
|
2999
3028
|
const f = path11.join(dir, `${name}.lock`);
|
|
3000
3029
|
try {
|
|
3001
|
-
if (Date.now() - statSync5(f).mtimeMs > staleMs || !processAlive(Number(
|
|
3030
|
+
if (Date.now() - statSync5(f).mtimeMs > staleMs || !processAlive(Number(readFileSync8(f, "utf8")))) unlinkSync3(f);
|
|
3002
3031
|
else return null;
|
|
3003
3032
|
} catch {
|
|
3004
3033
|
}
|
|
@@ -3386,7 +3415,7 @@ var StdoutSink = class {
|
|
|
3386
3415
|
};
|
|
3387
3416
|
|
|
3388
3417
|
// src/control/aliases.ts
|
|
3389
|
-
import { chmodSync as chmodSync2, mkdirSync as mkdirSync7, readFileSync as
|
|
3418
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync7, readFileSync as readFileSync9, renameSync as renameSync2, writeFileSync as writeFileSync7 } from "node:fs";
|
|
3390
3419
|
import path13 from "node:path";
|
|
3391
3420
|
|
|
3392
3421
|
// src/secrets.ts
|
|
@@ -3434,7 +3463,7 @@ function startOptionsOf(v) {
|
|
|
3434
3463
|
var aliasFile = (controlDir) => path13.join(controlDir, "aliases.json");
|
|
3435
3464
|
function readAliases(file) {
|
|
3436
3465
|
try {
|
|
3437
|
-
const j = JSON.parse(
|
|
3466
|
+
const j = JSON.parse(readFileSync9(file, "utf8"));
|
|
3438
3467
|
if (!j || typeof j !== "object" || Array.isArray(j)) return {};
|
|
3439
3468
|
const out = {};
|
|
3440
3469
|
for (const [k, v] of Object.entries(j)) {
|
|
@@ -3540,7 +3569,7 @@ function factsState(state) {
|
|
|
3540
3569
|
return {
|
|
3541
3570
|
get(h, s) {
|
|
3542
3571
|
try {
|
|
3543
|
-
return JSON.parse(
|
|
3572
|
+
return JSON.parse(readFileSync10(file(h, s), "utf8"));
|
|
3544
3573
|
} catch {
|
|
3545
3574
|
return {};
|
|
3546
3575
|
}
|
|
@@ -3806,7 +3835,7 @@ var BACKOFF_MS = [2e3, 1e4, 6e4, 5 * 6e4, 30 * 6e4];
|
|
|
3806
3835
|
var backoffFile = (state, sink) => path15.join(state, "backoff", `${safeId(sink)}.json`);
|
|
3807
3836
|
function readBackoff(state, sink) {
|
|
3808
3837
|
try {
|
|
3809
|
-
const b = JSON.parse(
|
|
3838
|
+
const b = JSON.parse(readFileSync10(backoffFile(state, sink), "utf8"));
|
|
3810
3839
|
return typeof b.until === "number" ? b : null;
|
|
3811
3840
|
} catch {
|
|
3812
3841
|
return null;
|