From e6dfc60f1526abcf11617f0c29d95112cbbe7cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20M=2E=20Wo=C5=BAniak?= Date: Fri, 20 Nov 2026 09:03:29 +0100 Subject: [PATCH] Sync upstream pstack 0.15.44 to 0.15.46 --- .claude-plugin/marketplace.json | 2 +- package.json | 2 +- pins.json | 4 +-- plugins/pstack/.claude-plugin/plugin.json | 2 +- plugins/pstack/.codex-plugin/plugin.json | 2 +- plugins/pstack/skills/arena/SKILL.md | 4 +-- plugins/pstack/skills/poteto-mode/SKILL.md | 4 +-- plugins/pstack/skills/setup-pstack/SKILL.md | 10 +++---- plugins/pstack/skills/statechart/SKILL.md | 2 +- .../statechart/scripts/frontends/dot.ts | 5 +++- .../skills/statechart/scripts/janitor.ts | 13 +++++++++ .../pstack/skills/statechart/scripts/kill.ts | 15 ++++++++++ .../pstack/skills/statechart/scripts/run.ts | 24 ++++++--------- .../skills/statechart/scripts/statechart.ts | 27 ++++++++--------- .../statechart/scripts/test/cli.test.ts | 29 +++++++++++++++++++ .../statechart/scripts/test/messages.test.ts | 14 +++++++++ upstream/pstack/.cursor-plugin/plugin.json | 2 +- upstream/pstack/skills/arena/SKILL.md | 4 +-- upstream/pstack/skills/poteto-mode/SKILL.md | 4 +-- upstream/pstack/skills/setup-pstack/SKILL.md | 10 +++---- upstream/pstack/skills/statechart/SKILL.md | 2 +- .../statechart/scripts/frontends/dot.ts | 5 +++- .../skills/statechart/scripts/janitor.ts | 13 +++++++++ .../pstack/skills/statechart/scripts/kill.ts | 15 ++++++++++ .../pstack/skills/statechart/scripts/run.ts | 24 ++++++--------- .../skills/statechart/scripts/statechart.ts | 27 ++++++++--------- .../statechart/scripts/test/cli.test.ts | 29 +++++++++++++++++++ .../statechart/scripts/test/messages.test.ts | 14 +++++++++ 28 files changed, 223 insertions(+), 85 deletions(-) create mode 100644 plugins/pstack/skills/statechart/scripts/janitor.ts create mode 100644 plugins/pstack/skills/statechart/scripts/kill.ts create mode 100644 upstream/pstack/skills/statechart/scripts/janitor.ts create mode 100644 upstream/pstack/skills/statechart/scripts/kill.ts diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 1d9b8d2..f8f080f 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -9,7 +9,7 @@ "name": "pstack", "source": "./plugins/pstack", "description": "Cursor pstack for T3 Code: poteto-mode, principles, and the verified agent workflows, adapted to T3 orchestration for Claude and Codex.", - "version": "0.16.0", + "version": "0.17.0", "author": { "name": "Lauren Tan (pstack), pmwoz (T3 Code port)" }, diff --git a/package.json b/package.json index 48a6c4c..05254a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "t3-pstack", - "version": "0.16.0", + "version": "0.17.0", "private": true, "type": "module", "scripts": { diff --git a/pins.json b/pins.json index f64931a..6a64be3 100644 --- a/pins.json +++ b/pins.json @@ -1,8 +1,8 @@ { "upstream": { "repo": "cursor/plugins", - "commit": "e58dd043600587dbaf58ba315e7f2b38373eeb43", - "version": "0.15.44", + "commit": "aaeb0ea3a0584995aa8f55ce44c6c5259414b896", + "version": "0.15.46", "map": { "pstack/skills": "skills", "pstack/agents": "agents", diff --git a/plugins/pstack/.claude-plugin/plugin.json b/plugins/pstack/.claude-plugin/plugin.json index 5c7456b..60b1dff 100644 --- a/plugins/pstack/.claude-plugin/plugin.json +++ b/plugins/pstack/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "pstack", "displayName": "pstack", - "version": "0.16.0", + "version": "0.17.0", "description": "Cursor pstack for T3 Code: poteto-mode, principles, and the verified agent workflows, adapted to T3 orchestration for Claude and Codex.", "author": { "name": "Lauren Tan (pstack), pmwoz (T3 Code port)" diff --git a/plugins/pstack/.codex-plugin/plugin.json b/plugins/pstack/.codex-plugin/plugin.json index 2ec31dc..1631e81 100644 --- a/plugins/pstack/.codex-plugin/plugin.json +++ b/plugins/pstack/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "pstack", - "version": "0.16.0", + "version": "0.17.0", "description": "Cursor pstack for T3 Code: poteto-mode, principles, and the verified agent workflows, adapted to T3 orchestration for Claude and Codex.", "author": { "name": "Lauren Tan (pstack), pmwoz (T3 Code port)" diff --git a/plugins/pstack/skills/arena/SKILL.md b/plugins/pstack/skills/arena/SKILL.md index 5957c9e..e908a7c 100644 --- a/plugins/pstack/skills/arena/SKILL.md +++ b/plugins/pstack/skills/arena/SKILL.md @@ -14,7 +14,7 @@ Every candidate gets the same prompt, so the prompt is the contract. 1. State the artifact each candidate is producing. 2. Derive the rubric, 3-6 concrete gradeable criteria for what success looks like on *this* task. It is the picker's tool in Phase D. Candidates only see the task. -3. Pick the runners from the `arena runners` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-high`. An `auto` or `inherit-parent` entry is the parent model, so omit `model` and spawn `generalPurpose`. If the Task tool rejects a slug, use the nearest valid slug of the same family or drop the seat, keep at least two runners, and say so. Families go by prefix, and the longest match wins: `claude-fable-*`, `claude-*`, and `gemini-*`, after dropping a leading `cursor-`. Any other slug's family is its text before the first hyphen. Spawn more for multiple design directions, and repeat one model when the work is generation-bound, not judgment-sensitive. Pick each subagent's reasoning level per the Subagents section of the **poteto-mode** skill. +3. Pick the runners from the `arena runners` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-xhigh`. An `auto` or `inherit-parent` entry is the parent model, so omit `model` and spawn `generalPurpose`. If the Task tool rejects a slug, use the nearest valid slug of the same family or drop the seat, keep at least two runners, and say so. Families go by prefix, and the longest match wins: `claude-fable-*`, `claude-*`, and `gemini-*`, after dropping a leading `cursor-`. Any other slug's family is its text before the first hyphen. Spawn more for multiple design directions, and repeat one model when the work is generation-bound, not judgment-sensitive. Pick each subagent's reasoning level per the Subagents section of the **poteto-mode** skill. 4. Give each candidate its own output location (a git worktree where possible, otherwise `/tmp/arena-/candidate-/`), per the **separate-before-serializing-shared-state** principle skill. ## Phase B: Fan out @@ -25,7 +25,7 @@ If a candidate produces no output, proceed with N-1 and note the dropout. ## Phase C: Cross-judge -After all Phase B candidates complete, spawn one readonly judge from the `arena cross-judge pool` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-opus-5-5-high-fast`, `gemini-4-neon-high`. The judge is never from the parent's vendor, and Fable counts as Claude for that check, so use the first entry from another vendor. An `auto` or `inherit-parent` entry is the parent model. If you do not know the parent's model, use the first real slug and say that the vendor check did not run. If the Task tool rejects a slug, use the nearest valid slug of the same family, then the next such entry, or skip the judge, and say so. While you read in Phase D, the judge scores each candidate, by path label, on each rubric criterion and recommends a base. +After all Phase B candidates complete, spawn one readonly judge from the `arena cross-judge pool` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-opus-5-5-high-fast`, `gemini-4-neon-xhigh`. The judge is never from the parent's vendor, and Fable counts as Claude for that check, so use the first entry from another vendor. An `auto` or `inherit-parent` entry is the parent model. If you do not know the parent's model, use the first real slug and say that the vendor check did not run. If the Task tool rejects a slug, use the nearest valid slug of the same family, then the next such entry, or skip the judge, and say so. While you read in Phase D, the judge scores each candidate, by path label, on each rubric criterion and recommends a base. ## Phase D: Pick a base diff --git a/plugins/pstack/skills/poteto-mode/SKILL.md b/plugins/pstack/skills/poteto-mode/SKILL.md index 77d6673..cac414d 100644 --- a/plugins/pstack/skills/poteto-mode/SKILL.md +++ b/plugins/pstack/skills/poteto-mode/SKILL.md @@ -91,11 +91,11 @@ Read the leaf skill in full for any principle you apply. Each entry names when i - Code, prose, and judgment: `claude-opus-5-5-xhigh-fast`. - Trivial mechanical edits: `claude-opus-5-5-high-fast`. -- Diverse review and design panels: one runner each on `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-high`. +- Diverse review and design panels: one runner each on `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-xhigh`. **Fable 5.2 is an exception.** It runs outside a panel only when the user named it for this task or two Opus 5.5 xhigh runs of the same brief failed its check. Say which. Difficulty alone never qualifies. -**Match the model to the job.** Start from the role's line or default, keep its family, and set the level the job needs. The `/setup-pstack` budget sets each role's starting level. Panel seats keep their listed level. Raise any other role one step, up to xhigh, for the hardest or subtlest work, lower it one step for judgment, and two or more steps for routine work. No role runs above xhigh. Opus 5.5 always runs its `-fast` slug. Verification always runs on the `swarm workers` model, `claude-opus-5-5-high-fast` by default. A Gemini seat never runs above `gemini-4-neon-high`. If the Task tool rejects a slug, never pass it again. Fall back to the role's line or default, then the calling skill's fallback, then the closest valid slug of the same family, then omit `model`. Say so. +**Match the model to the job.** Start from the role's line or default, keep its family, and set the level the job needs. The `/setup-pstack` budget sets each role's starting level. Panel seats keep their listed level. Raise any other role one step, up to xhigh, for the hardest or subtlest work, lower it one step for judgment, and two or more steps for routine work. No role runs above xhigh. Opus 5.5 always runs its `-fast` slug. Verification always runs on the `swarm workers` model, `claude-opus-5-5-high-fast` by default. A Gemini seat runs at `gemini-4-neon-xhigh` unless its line names another level. If the Task tool rejects a slug, never pass it again. Fall back to the role's line or default, then the calling skill's fallback, then the closest valid slug of the same family, then omit `model`. Say so. You own every subagent's work. Review the diff and write your own summary. A second opinion is the same prompt on another vendor's model. diff --git a/plugins/pstack/skills/setup-pstack/SKILL.md b/plugins/pstack/skills/setup-pstack/SKILL.md index 94ea221..9fb93d4 100644 --- a/plugins/pstack/skills/setup-pstack/SKILL.md +++ b/plugins/pstack/skills/setup-pstack/SKILL.md @@ -17,7 +17,7 @@ Call `orchestrator_capabilities`. Its providers with `canRunChildTask: true` and The default role-to-model mapping is the sheet shape shown in step 5 below. It is upstream's default mapping translated per the adapter's Model per role section for a catalog without Gemini. When the catalog has an `antigravity` instance that can run child tasks and lists a Gemini model, use its Gemini 4 Neon model, else its newest Gemini model, wherever step 5 shows `codex:gpt-6.1-sol`. If `~/.agents/pstack-models.md` already exists, read it and treat its `# budget` line and its role values as the current choices. If only `~/.claude/pstack-models.md` exists, from an earlier pstack port, read that one and resolve its short forms (`claude:opus@high`) to exact descriptors. Otherwise start from those defaults. A line whose role is not in step 5, such as `hardest tasks`, `architect runners`, `reflect tooling`, or `why investigators`, is from a retired role. Drop it. -Older Gemini models held the panel seat before Gemini 4 Neon. So in a panel role (`arena runners`, `arena cross-judge pool`, `interrogate reviewers`), an `antigravity` entry whose model is a `gemini-4-*` id other than a Gemini 4 Neon id is an old default. When the catalog lists a Gemini 4 Neon model on that instance, each one becomes that model at `high`. Tell the user which entries you replaced. +Older defaults put another Gemini model, then Gemini 4 Neon at `high`, in the panel seat, and a catalog without Gemini put `codex:gpt-6.1-sol@high` there. So in a panel role (`arena runners`, `arena cross-judge pool`, `interrogate reviewers`), an `antigravity` Gemini 4 Neon entry at `high` and a `codex:gpt-6.1-sol@high` entry are old defaults, and each becomes the same model at `xhigh`. An `antigravity` entry whose model is a `gemini-4-*` id other than a Gemini 4 Neon id is an old default too. When the catalog lists a Gemini 4 Neon model on that instance, it becomes that model at `xhigh`. A Gemini 4 Neon or `codex:gpt-6.1-sol` entry at any other level is the user's choice and stays. Tell the user which entries you replaced. A sheet without the `# defaults: 3` line comes from an older setup. That setup wrote a line for every role, so some of its values are old defaults, not choices. Before step 3, replace these values: @@ -35,7 +35,7 @@ Every other value is the user's choice and stays, including an old value in any - `medium — high reasoning` - `small — medium reasoning` -**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family, list, or alias (`inherit-parent`, `auto`). Families are the ones Phase A of the **arena** skill defines, so Fable is its own family. Each role has a target effort, which is its default's effort moved by the budget. `large` keeps it, `medium` lowers it one step, and `small` lowers it two steps, on the ladder `xhigh` > `high` > `medium` > `low`. No role runs above `xhigh`, and a target at the bottom of the ladder stays there. Most defaults are at `xhigh`, and each budget label names where those land. Set the effort of every real descriptor in the role, panel entries included, to the role's target. The effort is the part after `@`. Catalog efforts above `xhigh`, such as `max`, `ultra`, or `ultrathink`, are never picked. If the model does not offer the target effort, use its highest offered effort at or below the target, else mark the role as needing a choice. A descriptor with no effort stays as it is. `inherit-parent` and `auto` do not change. So `medium` turns `claudeAgent:claude-opus-5-5@xhigh` into `claudeAgent:claude-opus-5-5@high` and `claudeAgent:claude-opus-5-5@high` into `claudeAgent:claude-opus-5-5@medium`, and `small` turns them into `@medium` and `@low`. A Gemini entry stays at `high` when its role's target is `xhigh`, even where the catalog offers `xhigh`. A descriptor names no speed. The adapter's Model per role section sets it. +**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family, list, or alias (`inherit-parent`, `auto`). Families are the ones Phase A of the **arena** skill defines, so Fable is its own family. Each role has a target effort, which is its default's effort moved by the budget. `large` keeps it, `medium` lowers it one step, and `small` lowers it two steps, on the ladder `xhigh` > `high` > `medium` > `low`. No role runs above `xhigh`, and a target at the bottom of the ladder stays there. Most defaults are at `xhigh`, and each budget label names where those land. Set the effort of every real descriptor in the role, panel entries included, to the role's target. The effort is the part after `@`. Catalog efforts above `xhigh`, such as `max`, `ultra`, or `ultrathink`, are never picked. If the model does not offer the target effort, use its highest offered effort at or below the target, else mark the role as needing a choice. A descriptor with no effort stays as it is. `inherit-parent` and `auto` do not change. So `medium` turns `claudeAgent:claude-opus-5-5@xhigh` into `claudeAgent:claude-opus-5-5@high` and `claudeAgent:claude-opus-5-5@high` into `claudeAgent:claude-opus-5-5@medium`, and `small` turns them into `@medium` and `@low`. A Gemini 4 Neon entry in a panel role, or the `codex:gpt-6.1-sol` entry that holds the Gemini seat without Gemini, takes its own target, `xhigh` moved by the budget, so `large` keeps `@xhigh`, `medium` writes `@high`, and `small` writes `@medium`. A descriptor names no speed. The adapter's Model per role section sets it. **(c) Show the roles and confirm.** Show every role with its model, marking any real descriptor not in the detected set as needing a choice. Also list each line step 2 dropped. Ask whether to accept as-is or change specific roles, offering the detected models at `xhigh` or below plus `inherit-parent` and `auto` (both mean: this role runs on the parent chat model) as the options. Prefer a structured question over free text. For panel roles (arena runners, interrogate reviewers) the value is a list, and one subagent runs per entry, alias entries included, so the list length sets the count. `arena cross-judge pool` is also a list, but Arena runs one judge. It tries only values from a vendor other than the parent's, in list order, so order it by preference. Fable and the other Claude models are one vendor. An `inherit-parent` or `auto` value never judges. `swarm workers` is the default model for every worker unless a race or comparison assigns another model per arm. @@ -58,10 +58,10 @@ bug-fix: claudeAgent:claude-opus-5-5@xhigh perf-issue: claudeAgent:claude-opus-5-5@xhigh hillclimb: claudeAgent:claude-opus-5-5@xhigh judgment and prose: claudeAgent:claude-opus-5-5@xhigh -arena runners: claudeAgent:claude-fable-5-2@high, claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@high -arena cross-judge pool: claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@high +arena runners: claudeAgent:claude-fable-5-2@high, claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@xhigh +arena cross-judge pool: claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@xhigh swarm workers: claudeAgent:claude-opus-5-5@high -interrogate reviewers: claudeAgent:claude-fable-5-2@high, claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@high +interrogate reviewers: claudeAgent:claude-fable-5-2@high, claudeAgent:claude-opus-5-5@high, codex:gpt-6.1-sol@xhigh ``` Codex runs the plugin's session-start hook only after the user trusts it, so point Codex at the adapter once anyway. If `${CODEX_HOME:-$HOME/.codex}/AGENTS.md` has no line naming `t3-adapter.md`, append this line to it: "pstack under T3 Code: before a pstack skill starts a subagent or another skill, read `references/t3-adapter.md` in the installed pstack plugin's `poteto-mode` skill." Tell a Codex user to trust the pstack hook once, by running `codex` in a terminal and approving it at the startup prompt or with `/hooks`. Claude needs no edit, because the plugin's session-start hook names the adapter. diff --git a/plugins/pstack/skills/statechart/SKILL.md b/plugins/pstack/skills/statechart/SKILL.md index f5a64a8..18d653a 100644 --- a/plugins/pstack/skills/statechart/SKILL.md +++ b/plugins/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 --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/plugins/pstack/skills/statechart/scripts/frontends/dot.ts b/plugins/pstack/skills/statechart/scripts/frontends/dot.ts index 003dfc8..09d5481 100644 --- a/plugins/pstack/skills/statechart/scripts/frontends/dot.ts +++ b/plugins/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/plugins/pstack/skills/statechart/scripts/janitor.ts b/plugins/pstack/skills/statechart/scripts/janitor.ts new file mode 100644 index 0000000..5e69fb3 --- /dev/null +++ b/plugins/pstack/skills/statechart/scripts/janitor.ts @@ -0,0 +1,13 @@ +import fs from "node:fs"; +import { finished } from "node:stream/promises"; +import { killGroup } from "./kill.ts"; + +const [pid, ...dirs] = process.argv.slice(2); + +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/plugins/pstack/skills/statechart/scripts/kill.ts b/plugins/pstack/skills/statechart/scripts/kill.ts new file mode 100644 index 0000000..014d7c3 --- /dev/null +++ b/plugins/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/plugins/pstack/skills/statechart/scripts/run.ts b/plugins/pstack/skills/statechart/scripts/run.ts index 017684f..45e13dc 100644 --- a/plugins/pstack/skills/statechart/scripts/run.ts +++ b/plugins/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); } @@ -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, @@ -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 => ({ @@ -170,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); } @@ -298,6 +290,8 @@ export async function check(specFile: string, configFile: string): Promise {}); 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]); - 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/plugins/pstack/skills/statechart/scripts/test/cli.test.ts b/plugins/pstack/skills/statechart/scripts/test/cli.test.ts index 11f06a6..ee80722 100644 --- a/plugins/pstack/skills/statechart/scripts/test/cli.test.ts +++ b/plugins/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/plugins/pstack/skills/statechart/scripts/test/messages.test.ts b/plugins/pstack/skills/statechart/scripts/test/messages.test.ts index 61af006..4e0d3c3 100644 --- a/plugins/pstack/skills/statechart/scripts/test/messages.test.ts +++ b/plugins/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)"), diff --git a/upstream/pstack/.cursor-plugin/plugin.json b/upstream/pstack/.cursor-plugin/plugin.json index 2cf3f1f..b166870 100644 --- a/upstream/pstack/.cursor-plugin/plugin.json +++ b/upstream/pstack/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "pstack", "displayName": "pstack", - "version": "0.15.44", + "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/upstream/pstack/skills/arena/SKILL.md b/upstream/pstack/skills/arena/SKILL.md index 5957c9e..e908a7c 100644 --- a/upstream/pstack/skills/arena/SKILL.md +++ b/upstream/pstack/skills/arena/SKILL.md @@ -14,7 +14,7 @@ Every candidate gets the same prompt, so the prompt is the contract. 1. State the artifact each candidate is producing. 2. Derive the rubric, 3-6 concrete gradeable criteria for what success looks like on *this* task. It is the picker's tool in Phase D. Candidates only see the task. -3. Pick the runners from the `arena runners` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-high`. An `auto` or `inherit-parent` entry is the parent model, so omit `model` and spawn `generalPurpose`. If the Task tool rejects a slug, use the nearest valid slug of the same family or drop the seat, keep at least two runners, and say so. Families go by prefix, and the longest match wins: `claude-fable-*`, `claude-*`, and `gemini-*`, after dropping a leading `cursor-`. Any other slug's family is its text before the first hyphen. Spawn more for multiple design directions, and repeat one model when the work is generation-bound, not judgment-sensitive. Pick each subagent's reasoning level per the Subagents section of the **poteto-mode** skill. +3. Pick the runners from the `arena runners` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-xhigh`. An `auto` or `inherit-parent` entry is the parent model, so omit `model` and spawn `generalPurpose`. If the Task tool rejects a slug, use the nearest valid slug of the same family or drop the seat, keep at least two runners, and say so. Families go by prefix, and the longest match wins: `claude-fable-*`, `claude-*`, and `gemini-*`, after dropping a leading `cursor-`. Any other slug's family is its text before the first hyphen. Spawn more for multiple design directions, and repeat one model when the work is generation-bound, not judgment-sensitive. Pick each subagent's reasoning level per the Subagents section of the **poteto-mode** skill. 4. Give each candidate its own output location (a git worktree where possible, otherwise `/tmp/arena-/candidate-/`), per the **separate-before-serializing-shared-state** principle skill. ## Phase B: Fan out @@ -25,7 +25,7 @@ If a candidate produces no output, proceed with N-1 and note the dropout. ## Phase C: Cross-judge -After all Phase B candidates complete, spawn one readonly judge from the `arena cross-judge pool` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-opus-5-5-high-fast`, `gemini-4-neon-high`. The judge is never from the parent's vendor, and Fable counts as Claude for that check, so use the first entry from another vendor. An `auto` or `inherit-parent` entry is the parent model. If you do not know the parent's model, use the first real slug and say that the vendor check did not run. If the Task tool rejects a slug, use the nearest valid slug of the same family, then the next such entry, or skip the judge, and say so. While you read in Phase D, the judge scores each candidate, by path label, on each rubric criterion and recommends a base. +After all Phase B candidates complete, spawn one readonly judge from the `arena cross-judge pool` line in `~/.cursor/rules/pstack-models.mdc`, by default `claude-opus-5-5-high-fast`, `gemini-4-neon-xhigh`. The judge is never from the parent's vendor, and Fable counts as Claude for that check, so use the first entry from another vendor. An `auto` or `inherit-parent` entry is the parent model. If you do not know the parent's model, use the first real slug and say that the vendor check did not run. If the Task tool rejects a slug, use the nearest valid slug of the same family, then the next such entry, or skip the judge, and say so. While you read in Phase D, the judge scores each candidate, by path label, on each rubric criterion and recommends a base. ## Phase D: Pick a base diff --git a/upstream/pstack/skills/poteto-mode/SKILL.md b/upstream/pstack/skills/poteto-mode/SKILL.md index 2baadf5..82a1941 100644 --- a/upstream/pstack/skills/poteto-mode/SKILL.md +++ b/upstream/pstack/skills/poteto-mode/SKILL.md @@ -89,11 +89,11 @@ Read the leaf skill in full for any principle you apply. Each entry names when i - Code, prose, and judgment: `claude-opus-5-5-xhigh-fast`. - Trivial mechanical edits: `claude-opus-5-5-high-fast`. -- Diverse review and design panels: one runner each on `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-high`. +- Diverse review and design panels: one runner each on `claude-fable-5-2-high`, `claude-opus-5-5-high-fast`, and `gemini-4-neon-xhigh`. **Fable 5.2 is an exception.** It runs outside a panel only when the user named it for this task or two Opus 5.5 xhigh runs of the same brief failed its check. Say which. Difficulty alone never qualifies. -**Match the model to the job.** Start from the role's line or default, keep its family, and set the level the job needs. The `/setup-pstack` budget sets each role's starting level. Panel seats keep their listed level. Raise any other role one step, up to xhigh, for the hardest or subtlest work, lower it one step for judgment, and two or more steps for routine work. No role runs above xhigh. Opus 5.5 always runs its `-fast` slug. Verification always runs on the `swarm workers` model, `claude-opus-5-5-high-fast` by default. A Gemini seat never runs above `gemini-4-neon-high`. If the Task tool rejects a slug, never pass it again. Fall back to the role's line or default, then the calling skill's fallback, then the closest valid slug of the same family, then omit `model`. Say so. +**Match the model to the job.** Start from the role's line or default, keep its family, and set the level the job needs. The `/setup-pstack` budget sets each role's starting level. Panel seats keep their listed level. Raise any other role one step, up to xhigh, for the hardest or subtlest work, lower it one step for judgment, and two or more steps for routine work. No role runs above xhigh. Opus 5.5 always runs its `-fast` slug. Verification always runs on the `swarm workers` model, `claude-opus-5-5-high-fast` by default. A Gemini seat runs at `gemini-4-neon-xhigh` unless its line names another level. If the Task tool rejects a slug, never pass it again. Fall back to the role's line or default, then the calling skill's fallback, then the closest valid slug of the same family, then omit `model`. Say so. You own every subagent's work. Review the diff and write your own summary. A second opinion is the same prompt on another vendor's model. diff --git a/upstream/pstack/skills/setup-pstack/SKILL.md b/upstream/pstack/skills/setup-pstack/SKILL.md index c7bda42..7358536 100644 --- a/upstream/pstack/skills/setup-pstack/SKILL.md +++ b/upstream/pstack/skills/setup-pstack/SKILL.md @@ -17,7 +17,7 @@ Enumerate the model slugs you can pass to a `Task` subagent in this session. Tha The default role-to-model mapping is the rule shape shown in step 5 below. If `~/.cursor/rules/pstack-models.mdc` already exists, read it and treat its `# budget` line and its role values as the current choices. Otherwise start from those defaults. A line whose role is not in step 5, such as `hardest tasks`, `architect runners`, `reflect tooling`, or `why investigators`, is from a retired role. Drop it. -Older Gemini models held the panel seat before Gemini 4 Neon. So in any rule, a `gemini-4-*` entry other than `gemini-4-neon-*` in a panel role (`arena runners`, `arena cross-judge pool`, `interrogate reviewers`) is an old default. Each one becomes `gemini-4-neon-high`. Tell the user which entries you replaced. +Older defaults put another Gemini model, then `gemini-4-neon-high`, in the panel seat. So in any rule, a `gemini-4-neon-high` entry, or a `gemini-4-*` entry other than `gemini-4-neon-*`, in a panel role (`arena runners`, `arena cross-judge pool`, `interrogate reviewers`) is an old default. Each one becomes `gemini-4-neon-xhigh`. A Gemini 4 Neon entry at any other level is the user's choice and stays. Tell the user which entries you replaced. A rule without the `# defaults: 3` line comes from an older setup. That setup wrote a line for every role, so some of its values are old defaults, not choices. Before step 3, replace these values: @@ -35,7 +35,7 @@ Every other value is the user's choice and stays, including an old slug in any o - `medium — high reasoning` - `small — medium reasoning` -**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family, list, or alias (`inherit-parent`, `auto`). Families are the ones Phase A of the **arena** skill defines, so Fable is its own family. Each role has a target effort, which is its default's effort moved by the budget. `large` keeps it, `medium` lowers it one step, and `small` lowers it two steps, on the ladder `xhigh` > `high` > `medium` > `low`. No role runs above `xhigh`, and a target at the bottom of the ladder stays there. Most defaults are at `xhigh`, and each budget label names where those land. Set the effort token of every real slug in the role, panel entries included, to the role's target. The effort token is the last token, or the one before a trailing `fast`. If the result is not a detected slug, use the same family's detected slug with the highest effort at or below the target, else mark the role as needing a choice. `inherit-parent` and `auto` do not change. So `medium` turns `claude-opus-5-5-xhigh-fast` into `claude-opus-5-5-high-fast` and `claude-opus-5-5-high-fast` into `claude-opus-5-5-medium-fast`, and `small` turns them into `claude-opus-5-5-medium-fast` and `claude-opus-5-5-low-fast`. Opus 5.5 always runs its `-fast` slug, so every Opus 5.5 value ends in `-fast`. Fable 5.2 and Gemini have no fast slug, so never write one. Gemini 4 Neon has an `xhigh` slug, but a Gemini entry stays at `high` when its role's target is `xhigh`. +**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family, list, or alias (`inherit-parent`, `auto`). Families are the ones Phase A of the **arena** skill defines, so Fable is its own family. Each role has a target effort, which is its default's effort moved by the budget. `large` keeps it, `medium` lowers it one step, and `small` lowers it two steps, on the ladder `xhigh` > `high` > `medium` > `low`. No role runs above `xhigh`, and a target at the bottom of the ladder stays there. Most defaults are at `xhigh`, and each budget label names where those land. Set the effort token of every real slug in the role, panel entries included, to the role's target. The effort token is the last token, or the one before a trailing `fast`. If the result is not a detected slug, use the same family's detected slug with the highest effort at or below the target, else mark the role as needing a choice. `inherit-parent` and `auto` do not change. So `medium` turns `claude-opus-5-5-xhigh-fast` into `claude-opus-5-5-high-fast` and `claude-opus-5-5-high-fast` into `claude-opus-5-5-medium-fast`, and `small` turns them into `claude-opus-5-5-medium-fast` and `claude-opus-5-5-low-fast`. Opus 5.5 always runs its `-fast` slug, so every Opus 5.5 value ends in `-fast`. Fable 5.2 and Gemini have no fast slug, so never write one. Gemini 4 Neon slugs run from `low` to `xhigh` with no `max` or `fast` slug, so its seat runs at `gemini-4-neon-xhigh`, its top slug. A Gemini 4 Neon entry in a panel role takes its own target, `xhigh` moved by the budget, so `large` keeps `gemini-4-neon-xhigh`, `medium` writes `gemini-4-neon-high`, and `small` writes `gemini-4-neon-medium`. **(c) Show the roles and confirm.** Show every role with its model, marking any real slug not in the detected set as needing a choice. Also list each line step 2 dropped. Ask whether to accept as-is or change specific roles, offering the detected models at `xhigh` or below plus `inherit-parent` and `auto` (both mean: this role runs on the parent chat model, which is how Auto users stay on Auto) as the options. Prefer AskQuestion over free text. For panel roles (arena runners, interrogate reviewers) the value is a list, and one subagent runs per entry, alias entries included, so the list length sets the count. `arena cross-judge pool` is also a list, but Arena runs one judge. It tries only values from a vendor other than the parent's, in list order, so order it by preference. Fable and the other Claude models are one vendor. An `inherit-parent` or `auto` value never judges. `swarm workers` is the default model for every worker unless a race or comparison assigns another model per arm. @@ -61,10 +61,10 @@ bug-fix: claude-opus-5-5-xhigh-fast perf-issue: claude-opus-5-5-xhigh-fast hillclimb: claude-opus-5-5-xhigh-fast judgment and prose: claude-opus-5-5-xhigh-fast -arena runners: claude-fable-5-2-high, claude-opus-5-5-high-fast, gemini-4-neon-high -arena cross-judge pool: claude-opus-5-5-high-fast, gemini-4-neon-high +arena runners: claude-fable-5-2-high, claude-opus-5-5-high-fast, gemini-4-neon-xhigh +arena cross-judge pool: claude-opus-5-5-high-fast, gemini-4-neon-xhigh swarm workers: claude-opus-5-5-high-fast -interrogate reviewers: claude-fable-5-2-high, claude-opus-5-5-high-fast, gemini-4-neon-high +interrogate reviewers: claude-fable-5-2-high, claude-opus-5-5-high-fast, gemini-4-neon-xhigh ``` ### 6. Confirm diff --git a/upstream/pstack/skills/statechart/SKILL.md b/upstream/pstack/skills/statechart/SKILL.md index f5a64a8..18d653a 100644 --- a/upstream/pstack/skills/statechart/SKILL.md +++ b/upstream/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 --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/upstream/pstack/skills/statechart/scripts/frontends/dot.ts b/upstream/pstack/skills/statechart/scripts/frontends/dot.ts index 003dfc8..09d5481 100644 --- a/upstream/pstack/skills/statechart/scripts/frontends/dot.ts +++ b/upstream/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/upstream/pstack/skills/statechart/scripts/janitor.ts b/upstream/pstack/skills/statechart/scripts/janitor.ts new file mode 100644 index 0000000..5e69fb3 --- /dev/null +++ b/upstream/pstack/skills/statechart/scripts/janitor.ts @@ -0,0 +1,13 @@ +import fs from "node:fs"; +import { finished } from "node:stream/promises"; +import { killGroup } from "./kill.ts"; + +const [pid, ...dirs] = process.argv.slice(2); + +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/upstream/pstack/skills/statechart/scripts/kill.ts b/upstream/pstack/skills/statechart/scripts/kill.ts new file mode 100644 index 0000000..014d7c3 --- /dev/null +++ b/upstream/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/upstream/pstack/skills/statechart/scripts/run.ts b/upstream/pstack/skills/statechart/scripts/run.ts index 017684f..45e13dc 100644 --- a/upstream/pstack/skills/statechart/scripts/run.ts +++ b/upstream/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); } @@ -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, @@ -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 => ({ @@ -170,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); } @@ -298,6 +290,8 @@ export async function check(specFile: string, configFile: string): Promise {}); 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]); - 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/upstream/pstack/skills/statechart/scripts/test/cli.test.ts b/upstream/pstack/skills/statechart/scripts/test/cli.test.ts index 11f06a6..ee80722 100644 --- a/upstream/pstack/skills/statechart/scripts/test/cli.test.ts +++ b/upstream/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/upstream/pstack/skills/statechart/scripts/test/messages.test.ts b/upstream/pstack/skills/statechart/scripts/test/messages.test.ts index 61af006..4e0d3c3 100644 --- a/upstream/pstack/skills/statechart/scripts/test/messages.test.ts +++ b/upstream/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)"),