From 1f5e1c0c1cc60eecce4f75890705539c1732b6a7 Mon Sep 17 00:00:00 2001 From: poteto <1390709+poteto@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:39:17 -0600 Subject: [PATCH 1/3] fix(pstack): run /statechart on native Windows and read TLC's \r\n line ends TLC on Windows ends lines with \r\n, including each @!@!@ENDMSG marker. The line readers split on \n only, so the marker regex failed, every later message nested inside the first, and a broken rule read as "TLC exited 12, but its output names no rule that broke". The command also spawned /bin/sh for its group kill and its janitor, which native Windows does not have. - One splitLines helper splits on \r?\n for linesOf, fileLines and outputLines. - killGroup moves to kill.ts: process.kill(-pid) on macOS and Linux, taskkill /t /f on Windows. The janitor is janitor.ts, run by the command's own runtime. On Windows the command kills the worker's tree only while the worker runs, because Windows reuses pids. - The worker gets TEMP and TMP beside TMPDIR. Java gets -Dstdout.encoding=UTF-8 and -Dstderr.encoding=UTF-8, because Windows ignores LC_ALL. - SKILL.md: on native Windows, run node scripts/statechart.ts, because the launcher is a POSIX shell script. - Tests: FirstRule's TLC output with \r\n names the rule that breaks, and each corpus case replays with line ends as TLC prints them on Windows. --- .../claude-code/skills/statechart/SKILL.md | 2 +- .../statechart/scripts/frontends/dot.ts | 5 +++- .../skills/statechart/scripts/janitor.ts | 9 ++++++ .../skills/statechart/scripts/kill.ts | 15 ++++++++++ .../skills/statechart/scripts/run.ts | 20 +++++-------- .../skills/statechart/scripts/statechart.ts | 20 +++++-------- .../statechart/scripts/test/cli.test.ts | 29 +++++++++++++++++++ .../statechart/scripts/test/messages.test.ts | 14 +++++++++ pstack/skills/statechart/SKILL.md | 2 +- .../statechart/scripts/frontends/dot.ts | 5 +++- pstack/skills/statechart/scripts/janitor.ts | 9 ++++++ pstack/skills/statechart/scripts/kill.ts | 15 ++++++++++ pstack/skills/statechart/scripts/run.ts | 20 +++++-------- .../skills/statechart/scripts/statechart.ts | 20 +++++-------- .../statechart/scripts/test/cli.test.ts | 29 +++++++++++++++++++ .../statechart/scripts/test/messages.test.ts | 14 +++++++++ 16 files changed, 174 insertions(+), 54 deletions(-) create mode 100644 harness/pstack/claude-code/skills/statechart/scripts/janitor.ts create mode 100644 harness/pstack/claude-code/skills/statechart/scripts/kill.ts create mode 100644 pstack/skills/statechart/scripts/janitor.ts create mode 100644 pstack/skills/statechart/scripts/kill.ts diff --git a/harness/pstack/claude-code/skills/statechart/SKILL.md b/harness/pstack/claude-code/skills/statechart/SKILL.md index f5a64a8db4..6793d8a931 100644 --- a/harness/pstack/claude-code/skills/statechart/SKILL.md +++ b/harness/pstack/claude-code/skills/statechart/SKILL.md @@ -16,7 +16,7 @@ Work in a scratch folder outside the repo. Write a TLA+ spec and its config. The /scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR] ``` -`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. +`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node /scripts/statechart.ts` with Node 22.18 or later. The first run installs TLC and Java with mise and needs the network. diff --git a/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts b/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts index 003dfc89d4..09d5481e70 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts @@ -35,7 +35,10 @@ export const parseState = (label: string, parsed = new Map; -export const linesOf = (input: Lines) => (typeof input === "string" ? input.split("\n") : input); +export const splitLines = (text: string) => + (text.endsWith("\r") ? text.slice(0, -1) : text).split(/\r?\n/); + +export const linesOf = (input: Lines) => (typeof input === "string" ? splitLines(input) : input); export function parseDot(input: Lines): Graph { const states = new Map(); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts b/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts new file mode 100644 index 0000000000..aeede96af1 --- /dev/null +++ b/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts @@ -0,0 +1,9 @@ +import fs from "node:fs"; +import { finished } from "node:stream/promises"; +import { killGroup } from "./kill.ts"; + +const [pid, ...dirs] = process.argv.slice(2); + +await finished(process.stdin.resume()).catch(() => {}); +await killGroup(Number(pid)); +for (const dir of dirs) fs.rmSync(dir, { recursive: true, force: true }); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/kill.ts b/harness/pstack/claude-code/skills/statechart/scripts/kill.ts new file mode 100644 index 0000000000..014d7c3504 --- /dev/null +++ b/harness/pstack/claude-code/skills/statechart/scripts/kill.ts @@ -0,0 +1,15 @@ +import { spawn } from "node:child_process"; + +export const killGroup = (pid: number) => + new Promise((resolve) => { + if (process.platform === "win32") { + spawn("taskkill", ["/pid", String(pid), "/t", "/f"], { stdio: "ignore" }) + .on("error", () => resolve()) + .on("exit", () => resolve()); + return; + } + try { + process.kill(-pid, "SIGKILL"); + } catch {} + resolve(); + }); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/run.ts b/harness/pstack/claude-code/skills/statechart/scripts/run.ts index 017684f82d..63ebe4734a 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/run.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/run.ts @@ -8,7 +8,7 @@ import { inspect } from "node:util"; import { boundRun, chartRun, configText } from "./backends/cfg.ts"; import { plainText } from "./backends/plain-text.ts"; import { readConfig } from "./frontends/config.ts"; -import { parseDot } from "./frontends/dot.ts"; +import { parseDot, splitLines } from "./frontends/dot.ts"; import { readCounterexample, readMarks } from "./frontends/marks.ts"; import { readMessages } from "./frontends/messages.ts"; import { initialOnlyProperties, readChecks, readSany, readSpec } from "./frontends/spec.ts"; @@ -55,10 +55,10 @@ export function* fileLines(file: string) { kept = end; continue; } - yield* buf.toString("utf8", 0, cut).split("\n"); + yield* splitLines(buf.toString("utf8", 0, cut)); kept = buf.copy(buf, 0, cut + 1, end); } - yield buf.toString("utf8", 0, kept); + yield* splitLines(buf.toString("utf8", 0, kept)); } finally { fs.closeSync(fd); } @@ -93,14 +93,6 @@ const runChild = (file: string, args: string[], options: { cwd: string; env: Nod ); }); -export const killGroup = (pid: number) => - new Promise((resolve) => - spawn("/bin/sh", ["-c", 'kill -s KILL -- "-$1"', "sh", String(pid)], { stdio: "ignore" }).on( - "exit", - resolve, - ), - ); - export const messageOf = (error: unknown) => typeof error === "object" && error !== null && @@ -142,10 +134,10 @@ function* outputLines(output: Output) { rest = buf; continue; } - yield* utf8.decode(buf.subarray(0, cut)).split("\n"); + yield* splitLines(utf8.decode(buf.subarray(0, cut))); rest = buf.subarray(cut + 1); } - yield utf8.decode(rest); + yield* splitLines(utf8.decode(rest)); } const messagesOf = (output: Output): Iterable => ({ @@ -298,6 +290,8 @@ export async function check(specFile: string, configFile: string): Promise((resolve) => worker.on("exit", (code) => resolve(code ?? 2)), ); await Promise.race([stopped, exited]); - await killGroup(worker.pid as number); + const running = worker.exitCode === null && worker.signalCode === null; + const groupOutlivesWorker = process.platform !== "win32"; + if (worker.pid !== undefined && (running || groupOutlivesWorker)) await killGroup(worker.pid); const verdict = await exited; if (stop) { console.error(`${stop} stopped the check, so the command wrote nothing.`); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts b/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts index 11f06a6fd7..ee80722d6f 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts @@ -102,6 +102,35 @@ for (const name of fs.readdirSync(corpus)) { }); } +function asTlcPrintsOnWindows(text: string) { + const lines = text.split("\n"); + let depth = 0; + for (let i = 0; i < lines.length - 1; i++) { + if (/@!@!@STARTMSG \d+:\d+ @!@!@$/.test(lines[i])) depth++; + else if (/^@!@!@ENDMSG \d+ @!@!@$/.test(lines[i])) depth--; + if (!depth) lines[i] += "\r"; + } + return lines.join("\n"); +} + +for (const name of fs.readdirSync(corpus)) { + test(`${name} writes the committed chart and report from TLC's output with Windows line ends`, () => { + const dir = copyCase(name, (d) => { + for (const f of fs.readdirSync(d)) + if (f.endsWith(".out")) + fs.writeFileSync(path.join(d, f), asTlcPrintsOnWindows(read(path.join(d, f)))); + }); + const r = run(dir); + assert.equal(r.stderr, ""); + const first = path.join(dir, "verdict-1.exit"); + const plain = fs.existsSync(first) ? Number(read(first)) : 0; + assert.equal(r.status, plain === 0 ? 0 : [11, 12, 13].includes(plain) ? 1 : 2); + assert.equal(r.report, read(path.join(corpus, name, "report.md"))); + assert.equal(read(path.join(r.out, "chart.mmd")), read(path.join(corpus, name, "chart.mmd"))); + for (const f of r.files) assert.doesNotMatch(read(path.join(r.out, f)), /\r|@!@!@/, f); + }); +} + const launcher = path.join(here, "../statechart"); const launcherTools = () => { diff --git a/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts b/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts index 61af006968..4e0d3c3588 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts @@ -1,13 +1,27 @@ import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; import { test } from "node:test"; +import { fileURLToPath } from "node:url"; import { plainText, runtime } from "../backends/plain-text.ts"; import { readMessages } from "../frontends/messages.ts"; +import { readVerdict } from "../frontends/verdict.ts"; + +const here = path.dirname(fileURLToPath(import.meta.url)); const tool = (code: number, level: number, ...lines: string[]) => [`@!@!@STARTMSG ${code}:${level} @!@!@`, ...lines, `@!@!@ENDMSG ${code} @!@!@`].join("\n"); const plain = (text: string) => [...plainText(readMessages(text))].join(""); +test("TLC output with Windows line ends names the rule that breaks and prints as with Unix ones", () => { + const unix = fs.readFileSync(path.join(here, "corpus", "FirstRule", "verdict-1.out"), "utf8"); + const windows = unix.replaceAll("\n", "\r\n"); + assert.deepEqual(readVerdict(readMessages(windows)).broke, { kind: "invariant", name: "NotOne" }); + assert.deepEqual(readVerdict(readMessages(windows)), readVerdict(readMessages(unix))); + assert.equal(plain(windows), plain(unix)); +}); + test("TLC's -tool output prints as plain TLC prints it", () => { const text = [ tool(2262, 0, "TLC2 Version 2.19 of 08 August 2024 (rev: 5a47802)"), diff --git a/pstack/skills/statechart/SKILL.md b/pstack/skills/statechart/SKILL.md index f5a64a8db4..6793d8a931 100644 --- a/pstack/skills/statechart/SKILL.md +++ b/pstack/skills/statechart/SKILL.md @@ -16,7 +16,7 @@ Work in a scratch folder outside the repo. Write a TLA+ spec and its config. The /scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR] ``` -`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. +`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node /scripts/statechart.ts` with Node 22.18 or later. The first run installs TLC and Java with mise and needs the network. diff --git a/pstack/skills/statechart/scripts/frontends/dot.ts b/pstack/skills/statechart/scripts/frontends/dot.ts index 003dfc89d4..09d5481e70 100644 --- a/pstack/skills/statechart/scripts/frontends/dot.ts +++ b/pstack/skills/statechart/scripts/frontends/dot.ts @@ -35,7 +35,10 @@ export const parseState = (label: string, parsed = new Map; -export const linesOf = (input: Lines) => (typeof input === "string" ? input.split("\n") : input); +export const splitLines = (text: string) => + (text.endsWith("\r") ? text.slice(0, -1) : text).split(/\r?\n/); + +export const linesOf = (input: Lines) => (typeof input === "string" ? splitLines(input) : input); export function parseDot(input: Lines): Graph { const states = new Map(); diff --git a/pstack/skills/statechart/scripts/janitor.ts b/pstack/skills/statechart/scripts/janitor.ts new file mode 100644 index 0000000000..aeede96af1 --- /dev/null +++ b/pstack/skills/statechart/scripts/janitor.ts @@ -0,0 +1,9 @@ +import fs from "node:fs"; +import { finished } from "node:stream/promises"; +import { killGroup } from "./kill.ts"; + +const [pid, ...dirs] = process.argv.slice(2); + +await finished(process.stdin.resume()).catch(() => {}); +await killGroup(Number(pid)); +for (const dir of dirs) fs.rmSync(dir, { recursive: true, force: true }); diff --git a/pstack/skills/statechart/scripts/kill.ts b/pstack/skills/statechart/scripts/kill.ts new file mode 100644 index 0000000000..014d7c3504 --- /dev/null +++ b/pstack/skills/statechart/scripts/kill.ts @@ -0,0 +1,15 @@ +import { spawn } from "node:child_process"; + +export const killGroup = (pid: number) => + new Promise((resolve) => { + if (process.platform === "win32") { + spawn("taskkill", ["/pid", String(pid), "/t", "/f"], { stdio: "ignore" }) + .on("error", () => resolve()) + .on("exit", () => resolve()); + return; + } + try { + process.kill(-pid, "SIGKILL"); + } catch {} + resolve(); + }); diff --git a/pstack/skills/statechart/scripts/run.ts b/pstack/skills/statechart/scripts/run.ts index 017684f82d..63ebe4734a 100644 --- a/pstack/skills/statechart/scripts/run.ts +++ b/pstack/skills/statechart/scripts/run.ts @@ -8,7 +8,7 @@ import { inspect } from "node:util"; import { boundRun, chartRun, configText } from "./backends/cfg.ts"; import { plainText } from "./backends/plain-text.ts"; import { readConfig } from "./frontends/config.ts"; -import { parseDot } from "./frontends/dot.ts"; +import { parseDot, splitLines } from "./frontends/dot.ts"; import { readCounterexample, readMarks } from "./frontends/marks.ts"; import { readMessages } from "./frontends/messages.ts"; import { initialOnlyProperties, readChecks, readSany, readSpec } from "./frontends/spec.ts"; @@ -55,10 +55,10 @@ export function* fileLines(file: string) { kept = end; continue; } - yield* buf.toString("utf8", 0, cut).split("\n"); + yield* splitLines(buf.toString("utf8", 0, cut)); kept = buf.copy(buf, 0, cut + 1, end); } - yield buf.toString("utf8", 0, kept); + yield* splitLines(buf.toString("utf8", 0, kept)); } finally { fs.closeSync(fd); } @@ -93,14 +93,6 @@ const runChild = (file: string, args: string[], options: { cwd: string; env: Nod ); }); -export const killGroup = (pid: number) => - new Promise((resolve) => - spawn("/bin/sh", ["-c", 'kill -s KILL -- "-$1"', "sh", String(pid)], { stdio: "ignore" }).on( - "exit", - resolve, - ), - ); - export const messageOf = (error: unknown) => typeof error === "object" && error !== null && @@ -142,10 +134,10 @@ function* outputLines(output: Output) { rest = buf; continue; } - yield* utf8.decode(buf.subarray(0, cut)).split("\n"); + yield* splitLines(utf8.decode(buf.subarray(0, cut))); rest = buf.subarray(cut + 1); } - yield utf8.decode(rest); + yield* splitLines(utf8.decode(rest)); } const messagesOf = (output: Output): Iterable => ({ @@ -298,6 +290,8 @@ export async function check(specFile: string, configFile: string): Promise((resolve) => worker.on("exit", (code) => resolve(code ?? 2)), ); await Promise.race([stopped, exited]); - await killGroup(worker.pid as number); + const running = worker.exitCode === null && worker.signalCode === null; + const groupOutlivesWorker = process.platform !== "win32"; + if (worker.pid !== undefined && (running || groupOutlivesWorker)) await killGroup(worker.pid); const verdict = await exited; if (stop) { console.error(`${stop} stopped the check, so the command wrote nothing.`); diff --git a/pstack/skills/statechart/scripts/test/cli.test.ts b/pstack/skills/statechart/scripts/test/cli.test.ts index 11f06a6fd7..ee80722d6f 100644 --- a/pstack/skills/statechart/scripts/test/cli.test.ts +++ b/pstack/skills/statechart/scripts/test/cli.test.ts @@ -102,6 +102,35 @@ for (const name of fs.readdirSync(corpus)) { }); } +function asTlcPrintsOnWindows(text: string) { + const lines = text.split("\n"); + let depth = 0; + for (let i = 0; i < lines.length - 1; i++) { + if (/@!@!@STARTMSG \d+:\d+ @!@!@$/.test(lines[i])) depth++; + else if (/^@!@!@ENDMSG \d+ @!@!@$/.test(lines[i])) depth--; + if (!depth) lines[i] += "\r"; + } + return lines.join("\n"); +} + +for (const name of fs.readdirSync(corpus)) { + test(`${name} writes the committed chart and report from TLC's output with Windows line ends`, () => { + const dir = copyCase(name, (d) => { + for (const f of fs.readdirSync(d)) + if (f.endsWith(".out")) + fs.writeFileSync(path.join(d, f), asTlcPrintsOnWindows(read(path.join(d, f)))); + }); + const r = run(dir); + assert.equal(r.stderr, ""); + const first = path.join(dir, "verdict-1.exit"); + const plain = fs.existsSync(first) ? Number(read(first)) : 0; + assert.equal(r.status, plain === 0 ? 0 : [11, 12, 13].includes(plain) ? 1 : 2); + assert.equal(r.report, read(path.join(corpus, name, "report.md"))); + assert.equal(read(path.join(r.out, "chart.mmd")), read(path.join(corpus, name, "chart.mmd"))); + for (const f of r.files) assert.doesNotMatch(read(path.join(r.out, f)), /\r|@!@!@/, f); + }); +} + const launcher = path.join(here, "../statechart"); const launcherTools = () => { diff --git a/pstack/skills/statechart/scripts/test/messages.test.ts b/pstack/skills/statechart/scripts/test/messages.test.ts index 61af006968..4e0d3c3588 100644 --- a/pstack/skills/statechart/scripts/test/messages.test.ts +++ b/pstack/skills/statechart/scripts/test/messages.test.ts @@ -1,13 +1,27 @@ import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; import { test } from "node:test"; +import { fileURLToPath } from "node:url"; import { plainText, runtime } from "../backends/plain-text.ts"; import { readMessages } from "../frontends/messages.ts"; +import { readVerdict } from "../frontends/verdict.ts"; + +const here = path.dirname(fileURLToPath(import.meta.url)); const tool = (code: number, level: number, ...lines: string[]) => [`@!@!@STARTMSG ${code}:${level} @!@!@`, ...lines, `@!@!@ENDMSG ${code} @!@!@`].join("\n"); const plain = (text: string) => [...plainText(readMessages(text))].join(""); +test("TLC output with Windows line ends names the rule that breaks and prints as with Unix ones", () => { + const unix = fs.readFileSync(path.join(here, "corpus", "FirstRule", "verdict-1.out"), "utf8"); + const windows = unix.replaceAll("\n", "\r\n"); + assert.deepEqual(readVerdict(readMessages(windows)).broke, { kind: "invariant", name: "NotOne" }); + assert.deepEqual(readVerdict(readMessages(windows)), readVerdict(readMessages(unix))); + assert.equal(plain(windows), plain(unix)); +}); + test("TLC's -tool output prints as plain TLC prints it", () => { const text = [ tool(2262, 0, "TLC2 Version 2.19 of 08 August 2024 (rev: 5a47802)"), From 975d662a0afa981b9a9622275f3bc2b3a3774d2b Mon Sep 17 00:00:00 2001 From: poteto <1390709+poteto@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:58:54 -0700 Subject: [PATCH 2/3] fix(pstack): spare a reused Windows pid and hide java and mise consoles - The command tells the janitor when the worker exits. On Windows the janitor then skips taskkill, since Windows can give that pid to another process, and still removes the folders. On macOS and Linux it kills the group as before. - java and mise start with windowsHide, so the console-less worker does not open a window for them. Node ignores it elsewhere. - SKILL.md gives the launcher's Node range, 22.18 to 22.x or 23.6 or later, and its --disable-warning=ExperimentalWarning flag. --- harness/pstack/claude-code/skills/statechart/SKILL.md | 2 +- .../claude-code/skills/statechart/scripts/janitor.ts | 8 ++++++-- .../pstack/claude-code/skills/statechart/scripts/run.ts | 4 ++-- .../claude-code/skills/statechart/scripts/statechart.ts | 7 ++++++- pstack/skills/statechart/SKILL.md | 2 +- pstack/skills/statechart/scripts/janitor.ts | 8 ++++++-- pstack/skills/statechart/scripts/run.ts | 4 ++-- pstack/skills/statechart/scripts/statechart.ts | 7 ++++++- 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/harness/pstack/claude-code/skills/statechart/SKILL.md b/harness/pstack/claude-code/skills/statechart/SKILL.md index 6793d8a931..18d653a810 100644 --- a/harness/pstack/claude-code/skills/statechart/SKILL.md +++ b/harness/pstack/claude-code/skills/statechart/SKILL.md @@ -16,7 +16,7 @@ Work in a scratch folder outside the repo. Write a TLA+ spec and its config. The /scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR] ``` -`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node /scripts/statechart.ts` with Node 22.18 or later. +`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node --disable-warning=ExperimentalWarning /scripts/statechart.ts` with Node 22.18 to 22.x, or Node 23.6 or later. The first run installs TLC and Java with mise and needs the network. diff --git a/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts b/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts index aeede96af1..5e69fb316c 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/janitor.ts @@ -4,6 +4,10 @@ import { killGroup } from "./kill.ts"; const [pid, ...dirs] = process.argv.slice(2); -await finished(process.stdin.resume()).catch(() => {}); -await killGroup(Number(pid)); +let input = ""; +process.stdin.setEncoding("utf8").on("data", (chunk: string) => (input += chunk)); +await finished(process.stdin).catch(() => {}); +const running = !input.includes("exited"); +const groupOutlivesWorker = process.platform !== "win32"; +if (running || groupOutlivesWorker) await killGroup(Number(pid)); for (const dir of dirs) fs.rmSync(dir, { recursive: true, force: true }); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/run.ts b/harness/pstack/claude-code/skills/statechart/scripts/run.ts index 63ebe4734a..45e13dcb4d 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/run.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/run.ts @@ -82,7 +82,7 @@ const runChild = (file: string, args: string[], options: { cwd: string; env: Nod execFile( file, args, - { encoding: "utf8", maxBuffer: 1 << 30, ...options }, + { encoding: "utf8", maxBuffer: 1 << 30, windowsHide: true, ...options }, (error, stdout, stderr) => resolve({ status: error ? (typeof error.code === "number" ? error.code : null) : 0, @@ -162,7 +162,7 @@ const runToFiles = ( for (const f of files) fds.push(fs.openSync(f, "w")); let child: ChildProcess; try { - child = spawn(file, args, { ...options, stdio: ["ignore", ...fds] }); + child = spawn(file, args, { ...options, stdio: ["ignore", ...fds], windowsHide: true }); } finally { for (const fd of fds) fs.closeSync(fd); } diff --git a/harness/pstack/claude-code/skills/statechart/scripts/statechart.ts b/harness/pstack/claude-code/skills/statechart/scripts/statechart.ts index 995fb32fbb..43ee983edf 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/statechart.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/statechart.ts @@ -119,8 +119,13 @@ try { [...runtime, path.join(import.meta.dirname, "janitor.ts"), String(worker.pid), stage, tmp], { detached: true, stdio: ["pipe", "ignore", "ignore"] }, ); + const toJanitor = janitor.stdin; + toJanitor?.on("error", () => {}); const exited = new Promise((resolve) => - worker.on("exit", (code) => resolve(code ?? 2)), + worker.on("exit", (code) => { + toJanitor?.write("exited\n"); + resolve(code ?? 2); + }), ); await Promise.race([stopped, exited]); const running = worker.exitCode === null && worker.signalCode === null; diff --git a/pstack/skills/statechart/SKILL.md b/pstack/skills/statechart/SKILL.md index 6793d8a931..18d653a810 100644 --- a/pstack/skills/statechart/SKILL.md +++ b/pstack/skills/statechart/SKILL.md @@ -16,7 +16,7 @@ Work in a scratch folder outside the repo. Write a TLA+ spec and its config. The /scripts/statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR] ``` -`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node /scripts/statechart.ts` with Node 22.18 or later. +`scripts/statechart.ts` is TypeScript, so run it with a runtime that can execute TypeScript. `scripts/statechart` is a POSIX shell script that picks one. On native Windows, run `node --disable-warning=ExperimentalWarning /scripts/statechart.ts` with Node 22.18 to 22.x, or Node 23.6 or later. The first run installs TLC and Java with mise and needs the network. diff --git a/pstack/skills/statechart/scripts/janitor.ts b/pstack/skills/statechart/scripts/janitor.ts index aeede96af1..5e69fb316c 100644 --- a/pstack/skills/statechart/scripts/janitor.ts +++ b/pstack/skills/statechart/scripts/janitor.ts @@ -4,6 +4,10 @@ import { killGroup } from "./kill.ts"; const [pid, ...dirs] = process.argv.slice(2); -await finished(process.stdin.resume()).catch(() => {}); -await killGroup(Number(pid)); +let input = ""; +process.stdin.setEncoding("utf8").on("data", (chunk: string) => (input += chunk)); +await finished(process.stdin).catch(() => {}); +const running = !input.includes("exited"); +const groupOutlivesWorker = process.platform !== "win32"; +if (running || groupOutlivesWorker) await killGroup(Number(pid)); for (const dir of dirs) fs.rmSync(dir, { recursive: true, force: true }); diff --git a/pstack/skills/statechart/scripts/run.ts b/pstack/skills/statechart/scripts/run.ts index 63ebe4734a..45e13dcb4d 100644 --- a/pstack/skills/statechart/scripts/run.ts +++ b/pstack/skills/statechart/scripts/run.ts @@ -82,7 +82,7 @@ const runChild = (file: string, args: string[], options: { cwd: string; env: Nod execFile( file, args, - { encoding: "utf8", maxBuffer: 1 << 30, ...options }, + { encoding: "utf8", maxBuffer: 1 << 30, windowsHide: true, ...options }, (error, stdout, stderr) => resolve({ status: error ? (typeof error.code === "number" ? error.code : null) : 0, @@ -162,7 +162,7 @@ const runToFiles = ( for (const f of files) fds.push(fs.openSync(f, "w")); let child: ChildProcess; try { - child = spawn(file, args, { ...options, stdio: ["ignore", ...fds] }); + child = spawn(file, args, { ...options, stdio: ["ignore", ...fds], windowsHide: true }); } finally { for (const fd of fds) fs.closeSync(fd); } diff --git a/pstack/skills/statechart/scripts/statechart.ts b/pstack/skills/statechart/scripts/statechart.ts index 995fb32fbb..43ee983edf 100644 --- a/pstack/skills/statechart/scripts/statechart.ts +++ b/pstack/skills/statechart/scripts/statechart.ts @@ -119,8 +119,13 @@ try { [...runtime, path.join(import.meta.dirname, "janitor.ts"), String(worker.pid), stage, tmp], { detached: true, stdio: ["pipe", "ignore", "ignore"] }, ); + const toJanitor = janitor.stdin; + toJanitor?.on("error", () => {}); const exited = new Promise((resolve) => - worker.on("exit", (code) => resolve(code ?? 2)), + worker.on("exit", (code) => { + toJanitor?.write("exited\n"); + resolve(code ?? 2); + }), ); await Promise.race([stopped, exited]); const running = worker.exitCode === null && worker.signalCode === null; From 14f6cf60077353f08c76d4c6904e7b1620199799 Mon Sep 17 00:00:00 2001 From: poteto <1390709+poteto@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:58:54 -0700 Subject: [PATCH 3/3] chore(pstack): 0.15.46 --- harness/pstack/claude-code/.claude-plugin/plugin.json | 2 +- harness/pstack/claude-code/plugin.json | 2 +- pstack/.cursor-plugin/plugin.json | 2 +- pstack/plugin.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/harness/pstack/claude-code/.claude-plugin/plugin.json b/harness/pstack/claude-code/.claude-plugin/plugin.json index 10b3bc27c2..fce40ca898 100644 --- a/harness/pstack/claude-code/.claude-plugin/plugin.json +++ b/harness/pstack/claude-code/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "pstack", - "version": "0.15.45", + "version": "0.15.46", "description": "if you want to go fast, go deep first. pstack helps you write less, but higher quality code. rigorous agent workflows you can parallelize with confidence.", "author": { "name": "Lauren Tan" diff --git a/harness/pstack/claude-code/plugin.json b/harness/pstack/claude-code/plugin.json index 10b3bc27c2..fce40ca898 100644 --- a/harness/pstack/claude-code/plugin.json +++ b/harness/pstack/claude-code/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "pstack", - "version": "0.15.45", + "version": "0.15.46", "description": "if you want to go fast, go deep first. pstack helps you write less, but higher quality code. rigorous agent workflows you can parallelize with confidence.", "author": { "name": "Lauren Tan" diff --git a/pstack/.cursor-plugin/plugin.json b/pstack/.cursor-plugin/plugin.json index 0e673b6434..b1668706ec 100644 --- a/pstack/.cursor-plugin/plugin.json +++ b/pstack/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "pstack", "displayName": "pstack", - "version": "0.15.45", + "version": "0.15.46", "description": "if you want to go fast, go deep first. pstack helps you write less, but higher quality code. rigorous agent workflows you can parallelize with confidence.", "author": { "name": "Lauren Tan" diff --git a/pstack/plugin.json b/pstack/plugin.json index 10b3bc27c2..fce40ca898 100644 --- a/pstack/plugin.json +++ b/pstack/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "pstack", - "version": "0.15.45", + "version": "0.15.46", "description": "if you want to go fast, go deep first. pstack helps you write less, but higher quality code. rigorous agent workflows you can parallelize with confidence.", "author": { "name": "Lauren Tan"