@giljae/pi-pstack 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +67 -2
- package/agents/comment-sicko.md +35 -0
- package/agents/poteto-agent.md +12 -0
- package/harness/pi.md +87 -0
- package/package.json +37 -4
- package/skills/architect/SKILL.md +14 -0
- package/skills/arena/SKILL.md +51 -0
- package/skills/automate-me/SKILL.md +107 -0
- package/skills/benchmark-checklist/SKILL.md +42 -0
- package/skills/blast-radius/SKILL.md +53 -0
- package/skills/bro/SKILL.md +10 -0
- package/skills/correct/SKILL.md +35 -0
- package/skills/create-formal-verification-skill/SKILL.md +46 -0
- package/skills/create-verification-skill/SKILL.md +47 -0
- package/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/skills/figure-it-out/SKILL.md +55 -0
- package/skills/how/SKILL.md +24 -0
- package/skills/in-your-own-words/SKILL.md +10 -0
- package/skills/interrogate/SKILL.md +34 -0
- package/skills/ketchup/SKILL.md +46 -0
- package/skills/ketchup-video/SKILL.md +32 -0
- package/skills/maintain-formal-verification-skill/SKILL.md +61 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/make-bot-ui/SKILL.md +118 -0
- package/skills/no-comments/SKILL.md +27 -0
- package/skills/poteto-help/SKILL.md +165 -0
- package/skills/poteto-help/references/prompting.md +51 -0
- package/skills/poteto-help/references/recipes.md +51 -0
- package/skills/poteto-mode/SKILL.md +111 -0
- package/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
- package/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
- package/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
- package/skills/poteto-mode/playbooks/autopilot-stack.md +8 -0
- package/skills/poteto-mode/playbooks/babysit.md +10 -0
- package/skills/poteto-mode/playbooks/bug-fix.md +15 -0
- package/skills/poteto-mode/playbooks/eval.md +25 -0
- package/skills/poteto-mode/playbooks/feature.md +21 -0
- package/skills/poteto-mode/playbooks/hillclimb.md +21 -0
- package/skills/poteto-mode/playbooks/investigation.md +14 -0
- package/skills/poteto-mode/playbooks/multi-phase-plan.md +11 -0
- package/skills/poteto-mode/playbooks/opening-a-pr.md +9 -0
- package/skills/poteto-mode/playbooks/pause-safely.md +10 -0
- package/skills/poteto-mode/playbooks/perf-issue.md +25 -0
- package/skills/poteto-mode/playbooks/prototype.md +14 -0
- package/skills/poteto-mode/playbooks/refactoring.md +16 -0
- package/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
- package/skills/poteto-mode/playbooks/session-pickup.md +11 -0
- package/skills/poteto-mode/playbooks/shipping.md +12 -0
- package/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
- package/skills/poteto-mode/playbooks/visual-parity.md +11 -0
- package/skills/poteto-mode/playbooks/worktree-cleanup.md +12 -0
- package/skills/poteto-mode/references/bugbot-triage.md +142 -0
- package/skills/poteto-mode/scripts/bootstrap.ts +62 -0
- package/skills/poteto-mode/scripts/bun.lock +67 -0
- package/skills/poteto-mode/scripts/package.json +16 -0
- package/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
- package/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
- package/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +129 -0
- package/skills/poteto-mode/scripts/watch-pr/github.test.ts +498 -0
- package/skills/poteto-mode/scripts/watch-pr/github.ts +726 -0
- package/skills/poteto-mode/scripts/watch-pr/policy.test.ts +482 -0
- package/skills/poteto-mode/scripts/watch-pr/policy.ts +842 -0
- package/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
- package/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
- package/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
- package/skills/poteto-mode/scripts/watch-pr/types.ts +414 -0
- package/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
- package/skills/poteto-mode/scripts/worktree-audit.sh +134 -0
- package/skills/poteto-mode/worker.md +11 -0
- package/skills/principle-attack-the-premise/SKILL.md +18 -0
- package/skills/principle-boundary-discipline/SKILL.md +14 -0
- package/skills/principle-build-the-lever/SKILL.md +17 -0
- package/skills/principle-encode-lessons-in-structure/SKILL.md +14 -0
- package/skills/principle-exhaust-the-design-space/SKILL.md +12 -0
- package/skills/principle-experience-first/SKILL.md +22 -0
- package/skills/principle-explain-the-number/SKILL.md +17 -0
- package/skills/principle-fix-root-causes/SKILL.md +17 -0
- package/skills/principle-foundational-thinking/SKILL.md +16 -0
- package/skills/principle-guard-the-context-window/SKILL.md +15 -0
- package/skills/principle-laziness-protocol/SKILL.md +13 -0
- package/skills/principle-make-operations-idempotent/SKILL.md +18 -0
- package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +17 -0
- package/skills/principle-minimize-reader-load/SKILL.md +18 -0
- package/skills/principle-model-the-domain/SKILL.md +18 -0
- package/skills/principle-never-block-on-the-human/SKILL.md +18 -0
- package/skills/principle-outcome-oriented-execution/SKILL.md +24 -0
- package/skills/principle-prove-it-works/SKILL.md +14 -0
- package/skills/principle-redesign-from-first-principles/SKILL.md +19 -0
- package/skills/principle-separate-before-serializing-shared-state/SKILL.md +14 -0
- package/skills/principle-sequence-verifiable-units/SKILL.md +16 -0
- package/skills/principle-subtract-before-you-add/SKILL.md +21 -0
- package/skills/principle-test-behavior-not-implementation/SKILL.md +19 -0
- package/skills/principle-type-system-discipline/SKILL.md +18 -0
- package/skills/recall/SKILL.md +38 -0
- package/skills/reflect/SKILL.md +20 -0
- package/skills/setup-pstack/SKILL.md +81 -0
- package/skills/sharpen/SKILL.md +19 -0
- package/skills/show-me-your-work/SKILL.md +85 -0
- package/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/skills/show-me-your-work/scripts/log.sh +42 -0
- package/skills/statechart/SKILL.md +85 -0
- package/skills/statechart/references/render.md +93 -0
- package/skills/statechart/scripts/backends/cfg.ts +33 -0
- package/skills/statechart/scripts/backends/mermaid.ts +249 -0
- package/skills/statechart/scripts/backends/plain-text.ts +72 -0
- package/skills/statechart/scripts/backends/report.ts +177 -0
- package/skills/statechart/scripts/frontends/config.ts +276 -0
- package/skills/statechart/scripts/frontends/dot.ts +74 -0
- package/skills/statechart/scripts/frontends/marks.ts +93 -0
- package/skills/statechart/scripts/frontends/messages.ts +52 -0
- package/skills/statechart/scripts/frontends/spec.ts +114 -0
- package/skills/statechart/scripts/frontends/trace.ts +24 -0
- package/skills/statechart/scripts/frontends/value.ts +166 -0
- package/skills/statechart/scripts/frontends/verdict.ts +40 -0
- package/skills/statechart/scripts/frontends/view.ts +119 -0
- package/skills/statechart/scripts/ir.ts +547 -0
- package/skills/statechart/scripts/package.json +11 -0
- package/skills/statechart/scripts/passes/annotate.ts +128 -0
- package/skills/statechart/scripts/passes/label.ts +269 -0
- package/skills/statechart/scripts/passes/lift.ts +85 -0
- package/skills/statechart/scripts/passes/loop-check.ts +68 -0
- package/skills/statechart/scripts/passes/paths.ts +60 -0
- package/skills/statechart/scripts/passes/reach.ts +135 -0
- package/skills/statechart/scripts/passes/region-check.ts +97 -0
- package/skills/statechart/scripts/passes/regions.ts +295 -0
- package/skills/statechart/scripts/pipeline.ts +76 -0
- package/skills/statechart/scripts/run.ts +506 -0
- package/skills/statechart/scripts/statechart +29 -0
- package/skills/statechart/scripts/statechart.ts +164 -0
- package/skills/statechart/scripts/tsconfig.json +11 -0
- package/skills/statechart/scripts/worker.ts +35 -0
- package/skills/swarm/SKILL.md +44 -0
- package/skills/tdd/SKILL.md +45 -0
- package/skills/teach/SKILL.md +24 -0
- package/skills/technical-writing/SKILL.md +73 -0
- package/skills/typescript-best-practices/SKILL.md +33 -0
- package/skills/typescript-best-practices/references/patterns.md +328 -0
- package/skills/unslop/SKILL.md +43 -0
- package/skills/why/SKILL.md +12 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { type ChildProcess, execFile, type ExecFileException, spawn } from "node:child_process";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { inspect } from "node:util";
|
|
8
|
+
import { boundRun, chartRun, configText } from "./backends/cfg.ts";
|
|
9
|
+
import { plainText } from "./backends/plain-text.ts";
|
|
10
|
+
import { readConfig } from "./frontends/config.ts";
|
|
11
|
+
import { parseDot } from "./frontends/dot.ts";
|
|
12
|
+
import { readCounterexample, readMarks } from "./frontends/marks.ts";
|
|
13
|
+
import { readMessages } from "./frontends/messages.ts";
|
|
14
|
+
import { initialOnlyProperties, readChecks, readSany, readSpec } from "./frontends/spec.ts";
|
|
15
|
+
import { readTrace } from "./frontends/trace.ts";
|
|
16
|
+
import { type Break, readVerdict } from "./frontends/verdict.ts";
|
|
17
|
+
import {
|
|
18
|
+
type Bug,
|
|
19
|
+
CHART_STATES,
|
|
20
|
+
type CheckResult,
|
|
21
|
+
type ConfigSection,
|
|
22
|
+
hasSection,
|
|
23
|
+
type Lasso,
|
|
24
|
+
LEVEL,
|
|
25
|
+
type Mark,
|
|
26
|
+
must,
|
|
27
|
+
type Outcome,
|
|
28
|
+
type Output,
|
|
29
|
+
PART,
|
|
30
|
+
type Part,
|
|
31
|
+
type Property,
|
|
32
|
+
RERUN_STATES,
|
|
33
|
+
type Rule,
|
|
34
|
+
ruleKey,
|
|
35
|
+
type Stop,
|
|
36
|
+
stateRules,
|
|
37
|
+
type Trace,
|
|
38
|
+
type Verdict,
|
|
39
|
+
} from "./ir.ts";
|
|
40
|
+
import { addPast, deadEnds, finder, lasso, mark } from "./passes/annotate.ts";
|
|
41
|
+
import { pathGraph } from "./passes/paths.ts";
|
|
42
|
+
|
|
43
|
+
export function* fileLines(file: string) {
|
|
44
|
+
const fd = fs.openSync(file, "r");
|
|
45
|
+
try {
|
|
46
|
+
let buf = Buffer.allocUnsafe(PART);
|
|
47
|
+
let kept = 0;
|
|
48
|
+
for (;;) {
|
|
49
|
+
if (kept === buf.length) buf = Buffer.concat([buf], buf.length * 2);
|
|
50
|
+
const n = fs.readSync(fd, buf, kept, buf.length - kept, null);
|
|
51
|
+
if (!n) break;
|
|
52
|
+
const end = kept + n;
|
|
53
|
+
const cut = buf.lastIndexOf(10, end - 1);
|
|
54
|
+
if (cut === -1) {
|
|
55
|
+
kept = end;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
yield* buf.toString("utf8", 0, cut).split("\n");
|
|
59
|
+
kept = buf.copy(buf, 0, cut + 1, end);
|
|
60
|
+
}
|
|
61
|
+
yield buf.toString("utf8", 0, kept);
|
|
62
|
+
} finally {
|
|
63
|
+
fs.closeSync(fd);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const TLC_TOOL =
|
|
68
|
+
"http:tla2tools[url=https://github.com/tlaplus/tlaplus/releases/download/v1.7.4/tla2tools.jar,checksum=sha256:936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88]@1.7.4";
|
|
69
|
+
const JAVA_TOOL = "java@temurin-25";
|
|
70
|
+
export const PINNED_FLAGS = ["-workers", "1", "-fp", "0", "-lncheck", "final"];
|
|
71
|
+
const SANY_ERRORS = /^\*\*\* ?(?:Errors|Abort messages|Parse Error)/m;
|
|
72
|
+
|
|
73
|
+
type ChildResult = {
|
|
74
|
+
status: number | null;
|
|
75
|
+
stdout: string;
|
|
76
|
+
stderr: string;
|
|
77
|
+
error: ExecFileException | undefined;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const runChild = (file: string, args: string[], options: { cwd: string; env: NodeJS.ProcessEnv }) =>
|
|
81
|
+
new Promise<ChildResult>((resolve) => {
|
|
82
|
+
execFile(
|
|
83
|
+
file,
|
|
84
|
+
args,
|
|
85
|
+
{ encoding: "utf8", maxBuffer: 1 << 30, ...options },
|
|
86
|
+
(error, stdout, stderr) =>
|
|
87
|
+
resolve({
|
|
88
|
+
status: error ? (typeof error.code === "number" ? error.code : null) : 0,
|
|
89
|
+
stdout,
|
|
90
|
+
stderr,
|
|
91
|
+
error: typeof error?.code === "string" ? error : undefined,
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const killGroup = (pid: number) =>
|
|
97
|
+
new Promise((resolve) =>
|
|
98
|
+
spawn("/bin/sh", ["-c", 'kill -s KILL -- "-$1"', "sh", String(pid)], { stdio: "ignore" }).on(
|
|
99
|
+
"exit",
|
|
100
|
+
resolve,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
export const messageOf = (error: unknown) =>
|
|
105
|
+
typeof error === "object" &&
|
|
106
|
+
error !== null &&
|
|
107
|
+
"message" in error &&
|
|
108
|
+
typeof error.message === "string"
|
|
109
|
+
? error.message
|
|
110
|
+
: inspect(error);
|
|
111
|
+
|
|
112
|
+
const joined = (files: string[]): Output => {
|
|
113
|
+
const fds: number[] = [];
|
|
114
|
+
const sizes: number[] = [];
|
|
115
|
+
for (const f of files) {
|
|
116
|
+
const fd = fs.openSync(f, "r");
|
|
117
|
+
fds.push(fd);
|
|
118
|
+
sizes.push(fs.fstatSync(fd).size);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
*[Symbol.iterator]() {
|
|
122
|
+
for (let f = 0; f < fds.length; f++)
|
|
123
|
+
for (let pos = 0; pos < sizes[f];) {
|
|
124
|
+
const buf = Buffer.allocUnsafe(Math.min(PART, sizes[f] - pos));
|
|
125
|
+
const n = fs.readSync(fds[f], buf, 0, buf.length, pos);
|
|
126
|
+
if (!n) break;
|
|
127
|
+
pos += n;
|
|
128
|
+
yield buf.subarray(0, n);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const utf8 = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
135
|
+
|
|
136
|
+
function* outputLines(output: Output) {
|
|
137
|
+
let rest: Uint8Array = new Uint8Array(0);
|
|
138
|
+
for (const part of output) {
|
|
139
|
+
const buf = rest.length ? Buffer.concat([rest, part]) : part;
|
|
140
|
+
const cut = buf.lastIndexOf(10);
|
|
141
|
+
if (cut === -1) {
|
|
142
|
+
rest = buf;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
yield* utf8.decode(buf.subarray(0, cut)).split("\n");
|
|
146
|
+
rest = buf.subarray(cut + 1);
|
|
147
|
+
}
|
|
148
|
+
yield utf8.decode(rest);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const messagesOf = (output: Output): Iterable<Part> => ({
|
|
152
|
+
[Symbol.iterator]: () => readMessages(outputLines(output)),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
type FileResult = {
|
|
156
|
+
status: number | null;
|
|
157
|
+
stdout: string;
|
|
158
|
+
output: Output;
|
|
159
|
+
error: Error | undefined;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const runToFiles = (
|
|
163
|
+
file: string,
|
|
164
|
+
args: string[],
|
|
165
|
+
{ out, ...options }: { out: string; cwd: string; env: NodeJS.ProcessEnv },
|
|
166
|
+
) =>
|
|
167
|
+
new Promise<FileResult>((resolve) => {
|
|
168
|
+
const files = [`${out}.stdout`, `${out}.stderr`];
|
|
169
|
+
const fds: number[] = [];
|
|
170
|
+
for (const f of files) fds.push(fs.openSync(f, "w"));
|
|
171
|
+
let child: ChildProcess;
|
|
172
|
+
try {
|
|
173
|
+
child = spawn(file, args, { ...options, stdio: ["ignore", ...fds] });
|
|
174
|
+
} finally {
|
|
175
|
+
for (const fd of fds) fs.closeSync(fd);
|
|
176
|
+
}
|
|
177
|
+
let error: Error | undefined;
|
|
178
|
+
const settle = (code: number | null) =>
|
|
179
|
+
resolve({
|
|
180
|
+
status: error ? null : code,
|
|
181
|
+
stdout: files[0],
|
|
182
|
+
output: joined(files),
|
|
183
|
+
error,
|
|
184
|
+
});
|
|
185
|
+
child.on("error", (e) => {
|
|
186
|
+
error = e;
|
|
187
|
+
if (child.pid === undefined) settle(null);
|
|
188
|
+
});
|
|
189
|
+
child.on("close", (code) => {
|
|
190
|
+
if (child.pid !== undefined) settle(code);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
async function findTlc(cwd: string) {
|
|
195
|
+
const { TLA2TOOLS, JAVA } = process.env;
|
|
196
|
+
if (TLA2TOOLS) return { jar: TLA2TOOLS, java: JAVA || "java" };
|
|
197
|
+
const mise = (...args: string[]) =>
|
|
198
|
+
runChild("mise", args, { cwd, env: { ...process.env, MISE_CEILING_PATHS: cwd } });
|
|
199
|
+
const where = () =>
|
|
200
|
+
Promise.all([mise("where", TLC_TOOL), mise("which", "java", "--tool", JAVA_TOOL)]);
|
|
201
|
+
let found = await where();
|
|
202
|
+
if (found.some((r) => r.status !== 0)) {
|
|
203
|
+
const r = await mise("install", JAVA_TOOL, TLC_TOOL);
|
|
204
|
+
if (r.status !== 0)
|
|
205
|
+
throw new Error(
|
|
206
|
+
`Cannot find TLC: mise install failed: ${r.error?.message ?? r.stderr.trim()}\nOr set TLA2TOOLS to the path of tla2tools.jar, and JAVA to a java binary (Java 11 or later).`,
|
|
207
|
+
);
|
|
208
|
+
found = await where();
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
jar: path.join(found[0].stdout.trim(), "tla2tools.jar"),
|
|
212
|
+
java: JAVA || found[1].stdout.trim(),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const exitClass = (status: number | null) =>
|
|
217
|
+
status === 0 ? 0 : status === 11 || status === 12 || status === 13 ? 1 : 2;
|
|
218
|
+
|
|
219
|
+
const tail = (r: FileResult) => {
|
|
220
|
+
if (r.error) return r.error.message;
|
|
221
|
+
const kept: string[] = [];
|
|
222
|
+
let size = 0;
|
|
223
|
+
for (const chunk of plainText(messagesOf(r.output))) {
|
|
224
|
+
kept.push(chunk);
|
|
225
|
+
size += chunk.length;
|
|
226
|
+
while (size - kept[0].length >= 1 << 28) size -= kept.shift()!.length;
|
|
227
|
+
}
|
|
228
|
+
return kept.join("").trim().split("\n").slice(-30).join("\n");
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const firstLines = (text: string) => {
|
|
232
|
+
const lines = text.trim().split("\n");
|
|
233
|
+
if (lines.length > 40) lines.splice(40, Infinity, `... ${lines.length - 40} more lines`);
|
|
234
|
+
return lines.join("\n");
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const stopOf = (r: FileResult): Stop => {
|
|
238
|
+
const errors: Part[] = [];
|
|
239
|
+
for (const m of r.error ? [] : messagesOf(r.output))
|
|
240
|
+
if (
|
|
241
|
+
typeof m !== "string" &&
|
|
242
|
+
(m.level === LEVEL.ERROR ||
|
|
243
|
+
m.level === LEVEL.TLCBUG ||
|
|
244
|
+
(errors.length && m.level === LEVEL.STATE))
|
|
245
|
+
)
|
|
246
|
+
errors.push(m);
|
|
247
|
+
if (!errors.length) return { status: r.status, message: tail(r) };
|
|
248
|
+
return { status: r.status, message: firstLines([...plainText(errors)].join("")) };
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const sanyErrors = (r: FileResult) => {
|
|
252
|
+
if (r.error) return undefined;
|
|
253
|
+
const text = [...plainText(messagesOf(r.output))].join("");
|
|
254
|
+
const at = text.search(SANY_ERRORS);
|
|
255
|
+
return at === -1 ? undefined : firstLines(text.slice(at));
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const names = (rules: Rule[], kind: Rule["kind"]) => {
|
|
259
|
+
const found: string[] = [];
|
|
260
|
+
for (const rule of rules) if (rule.kind === kind) found.push(rule.name);
|
|
261
|
+
return found;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const brokenRule = (rules: Rule[], broke: Break) => {
|
|
265
|
+
if (broke.kind === "temporal") return undefined;
|
|
266
|
+
for (const rule of rules)
|
|
267
|
+
if (rule.kind === broke.kind && (broke.kind === "deadlock" || rule.name === broke.name))
|
|
268
|
+
return rule;
|
|
269
|
+
if (broke.kind === "invariant")
|
|
270
|
+
for (const rule of rules) if (rule.kind === "property" && rule.name === broke.name) return rule;
|
|
271
|
+
return undefined;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
function* only(marks: Iterable<Mark>, rules: Set<string>) {
|
|
275
|
+
for (const { values, broken } of marks) {
|
|
276
|
+
const kept: string[] = [];
|
|
277
|
+
for (const name of broken) if (rules.has(name)) kept.push(name);
|
|
278
|
+
if (kept.length) yield { values, broken: kept };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export async function check(specFile: string, configFile: string): Promise<CheckResult> {
|
|
283
|
+
const cfg = readConfig({ file: configFile, text: fs.readFileSync(configFile, "utf8") });
|
|
284
|
+
const checks = readChecks({ configFile, config: cfg });
|
|
285
|
+
const folder = path.dirname(path.resolve(specFile));
|
|
286
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-"));
|
|
287
|
+
try {
|
|
288
|
+
const tlc = await findTlc(dir);
|
|
289
|
+
const config = (name: string, sections: ConfigSection[], extra: string[]) => {
|
|
290
|
+
fs.writeFileSync(path.join(dir, `${name}.cfg`), configText(sections, extra));
|
|
291
|
+
return [`-metadir`, path.join(dir, `meta-${name}`), "-config", path.join(dir, `${name}.cfg`)];
|
|
292
|
+
};
|
|
293
|
+
const runJava = (name: string, main: string, args: string[], jvm: string[] = []) => {
|
|
294
|
+
const tmp = path.join(dir, `tmp-${name}`);
|
|
295
|
+
fs.mkdirSync(tmp);
|
|
296
|
+
return runToFiles(
|
|
297
|
+
tlc.java,
|
|
298
|
+
[
|
|
299
|
+
`-Djava.io.tmpdir=${tmp}`,
|
|
300
|
+
`-DTLA-Library=${folder}`,
|
|
301
|
+
...jvm,
|
|
302
|
+
"-cp",
|
|
303
|
+
tlc.jar,
|
|
304
|
+
main,
|
|
305
|
+
...args,
|
|
306
|
+
],
|
|
307
|
+
{
|
|
308
|
+
cwd: dir,
|
|
309
|
+
out: path.join(dir, name),
|
|
310
|
+
env: process.platform === "darwin" ? process.env : { ...process.env, LC_ALL: "C.UTF-8" },
|
|
311
|
+
},
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
const xml = await runJava(
|
|
315
|
+
"sany",
|
|
316
|
+
"tla2sany.xml.XMLExporter",
|
|
317
|
+
["-o", "-I", folder, path.resolve(specFile)],
|
|
318
|
+
["-XX:TieredStopAtLevel=1"],
|
|
319
|
+
);
|
|
320
|
+
if (xml.status !== 0) {
|
|
321
|
+
const errors = xml.error
|
|
322
|
+
? undefined
|
|
323
|
+
: sanyErrors(
|
|
324
|
+
await runJava(
|
|
325
|
+
"sany-errors",
|
|
326
|
+
"tla2sany.SANY",
|
|
327
|
+
[path.resolve(specFile)],
|
|
328
|
+
["-XX:TieredStopAtLevel=1"],
|
|
329
|
+
),
|
|
330
|
+
);
|
|
331
|
+
throw new Error(
|
|
332
|
+
`SANY could not read ${specFile} (exit ${xml.status}):\n${errors ?? tail(xml)}`,
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const sany = readSany(fs.readFileSync(xml.stdout, "utf8"));
|
|
336
|
+
const module = path.basename(specFile, ".tla");
|
|
337
|
+
const spec = { ...readSpec({ module, sany, checks }), folder };
|
|
338
|
+
const rules = stateRules(spec);
|
|
339
|
+
const all = [...rules];
|
|
340
|
+
for (const name of spec.properties) all.push({ kind: "property", name });
|
|
341
|
+
const verdicts = new Map<string, Verdict>();
|
|
342
|
+
const decide = (rule: Rule, outcome: Outcome, r?: FileResult) =>
|
|
343
|
+
verdicts.set(ruleKey(rule), { rule, outcome, messages: r && messagesOf(r.output) });
|
|
344
|
+
const judge = async () => {
|
|
345
|
+
const groups = [all];
|
|
346
|
+
let first: FileResult | undefined;
|
|
347
|
+
let stop: Stop | undefined;
|
|
348
|
+
const states = { distinct: 0, initial: 0, complete: false, cut: false };
|
|
349
|
+
for (let k = 1; groups.length;) {
|
|
350
|
+
const group: Rule[] = [];
|
|
351
|
+
for (const rule of groups[0]) if (!verdicts.has(ruleKey(rule))) group.push(rule);
|
|
352
|
+
if (first && !group.length) {
|
|
353
|
+
groups.shift();
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const name = `verdict-${k++}`;
|
|
357
|
+
const extra: string[] = [];
|
|
358
|
+
const invariants = names(group, "invariant");
|
|
359
|
+
const properties = names(group, "property");
|
|
360
|
+
if (invariants.length) extra.push(`INVARIANT ${invariants.join(" ")}`);
|
|
361
|
+
if (properties.length) extra.push(`PROPERTY ${properties.join(" ")}`);
|
|
362
|
+
const bounded = first !== undefined && !states.complete;
|
|
363
|
+
if (bounded) extra.push("CONSTRAINT ChartBound");
|
|
364
|
+
const r = await runJava(name, "tlc2.TLC", [
|
|
365
|
+
"-tool",
|
|
366
|
+
...PINNED_FLAGS,
|
|
367
|
+
...(names(group, "deadlock").length ? [] : ["-deadlock"]),
|
|
368
|
+
...config(name, spec.written, extra),
|
|
369
|
+
bounded ? "ChartBound" : spec.module,
|
|
370
|
+
]);
|
|
371
|
+
first ??= r;
|
|
372
|
+
const { broke, distinct, initial } = readVerdict(messagesOf(r.output));
|
|
373
|
+
states.distinct = Math.max(states.distinct, distinct);
|
|
374
|
+
states.initial = Math.max(states.initial, initial);
|
|
375
|
+
const rule = broke && brokenRule(group, broke);
|
|
376
|
+
const cut = bounded && distinct >= RERUN_STATES;
|
|
377
|
+
if (exitClass(r.status) === 2) {
|
|
378
|
+
stop = stopOf(r);
|
|
379
|
+
break;
|
|
380
|
+
} else if (rule) decide(rule, "broken", r);
|
|
381
|
+
else if (cut && (r.status === 0 || broke?.kind === "temporal")) {
|
|
382
|
+
states.cut = true;
|
|
383
|
+
for (const rule of group) decide(rule, "not checked");
|
|
384
|
+
} else if (r.status === 0) {
|
|
385
|
+
states.complete = true;
|
|
386
|
+
for (const rule of group) decide(rule, "holds");
|
|
387
|
+
} else if (broke && properties.length) {
|
|
388
|
+
if (broke.kind === "temporal") {
|
|
389
|
+
states.complete = true;
|
|
390
|
+
for (const rule of group) if (rule.kind !== "property") decide(rule, "holds");
|
|
391
|
+
}
|
|
392
|
+
const pending: Rule[][] = [];
|
|
393
|
+
const rest: Rule[] = [];
|
|
394
|
+
for (const rule of group)
|
|
395
|
+
if (rule.kind === "property") pending.push([rule]);
|
|
396
|
+
else if (!verdicts.has(ruleKey(rule))) rest.push(rule);
|
|
397
|
+
if (pending.length === 1) decide(pending[0][0], "broken", r);
|
|
398
|
+
else groups.splice(0, 1, rest, ...pending);
|
|
399
|
+
} else
|
|
400
|
+
throw new Error(
|
|
401
|
+
`TLC exited ${r.status} on ${specFile}, but its output names no rule that broke:\n${tail(r)}`,
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
for (const rule of all) if (!verdicts.has(ruleKey(rule))) decide(rule, "not checked");
|
|
405
|
+
return { first: first!, stop, states };
|
|
406
|
+
};
|
|
407
|
+
fs.writeFileSync(path.join(dir, "ChartBound.tla"), boundRun(spec.module));
|
|
408
|
+
const judged = await judge();
|
|
409
|
+
const exit = exitClass(judged.first.status);
|
|
410
|
+
const failed = (r: FileResult) =>
|
|
411
|
+
new Error(`TLC could not check ${specFile} (exit ${r.status}):\n${stopOf(r).message}`);
|
|
412
|
+
const initialOnly = initialOnlyProperties(sany, spec);
|
|
413
|
+
const propertiesWith = (bugOf: (trace: Trace) => Lasso | undefined) => {
|
|
414
|
+
const properties: Property[] = [];
|
|
415
|
+
for (const rule of all) {
|
|
416
|
+
if (rule.kind !== "property") continue;
|
|
417
|
+
const v = must(verdicts, ruleKey(rule));
|
|
418
|
+
properties.push({
|
|
419
|
+
...v,
|
|
420
|
+
bug: v.outcome === "broken" && v.messages ? bugOf(readTrace(v.messages)) : undefined,
|
|
421
|
+
initialOnly: initialOnly.has(rule.name),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
return properties;
|
|
425
|
+
};
|
|
426
|
+
if (exit === 2) throw failed(judged.first);
|
|
427
|
+
const checked: Verdict[] = [];
|
|
428
|
+
for (const rule of rules) checked.push(must(verdicts, ruleKey(rule)));
|
|
429
|
+
const common = {
|
|
430
|
+
spec,
|
|
431
|
+
exit,
|
|
432
|
+
stop: judged.stop,
|
|
433
|
+
states: judged.states,
|
|
434
|
+
messages: messagesOf(judged.first.output),
|
|
435
|
+
rules: checked,
|
|
436
|
+
};
|
|
437
|
+
if (judged.states.distinct <= CHART_STATES) {
|
|
438
|
+
const tag = `chart-${randomBytes(16).toString("hex")}`;
|
|
439
|
+
fs.writeFileSync(path.join(dir, "ChartRun.tla"), chartRun(spec, tag));
|
|
440
|
+
const drawn = await runJava("ChartRun", "tlc2.TLC", [
|
|
441
|
+
"-tool",
|
|
442
|
+
...PINNED_FLAGS,
|
|
443
|
+
"-deadlock",
|
|
444
|
+
...config("ChartRun", spec.written, ["INVARIANT ChartMark", "CONSTRAINT ChartBudget"]),
|
|
445
|
+
"-dump",
|
|
446
|
+
"dot,actionlabels",
|
|
447
|
+
path.join(dir, "graph"),
|
|
448
|
+
"ChartRun",
|
|
449
|
+
]);
|
|
450
|
+
const file = path.join(dir, "graph.dot");
|
|
451
|
+
if (!fs.existsSync(file)) throw failed(drawn);
|
|
452
|
+
if (readVerdict(messagesOf(drawn.output)).distinct <= CHART_STATES) {
|
|
453
|
+
const graph = parseDot(fileLines(file));
|
|
454
|
+
const find = finder(graph, spec.variables);
|
|
455
|
+
const drawing = drawn.status === 0 ? undefined : { status: drawn.status };
|
|
456
|
+
const broken = new Set<string>();
|
|
457
|
+
for (const { rule, outcome } of verdicts.values())
|
|
458
|
+
if (rule.kind === "invariant" && outcome === "broken") broken.add(rule.name);
|
|
459
|
+
const marks = only(readMarks(readMessages(fileLines(drawn.stdout)), tag), broken);
|
|
460
|
+
const past = mark(graph, marks, spec.variables, rules, find);
|
|
461
|
+
const excludes = hasSection(spec, "ACTION_CONSTRAINT");
|
|
462
|
+
for (const rule of rules) {
|
|
463
|
+
const { outcome, messages } = must(verdicts, ruleKey(rule));
|
|
464
|
+
if (
|
|
465
|
+
rule.kind === "deadlock" &&
|
|
466
|
+
outcome === "broken" &&
|
|
467
|
+
!drawing &&
|
|
468
|
+
!hasSection(spec, "CONSTRAINT", "ACTION_CONSTRAINT")
|
|
469
|
+
)
|
|
470
|
+
deadEnds(graph, rule);
|
|
471
|
+
if (outcome !== "broken" || !messages) continue;
|
|
472
|
+
const counterexample = readCounterexample(messages);
|
|
473
|
+
if (
|
|
474
|
+
!drawing ||
|
|
475
|
+
lasso(graph, { seq: counterexample, loop: undefined }, spec.variables, find)
|
|
476
|
+
)
|
|
477
|
+
addPast(graph, counterexample, spec.variables, rule, past, excludes, find);
|
|
478
|
+
}
|
|
479
|
+
const properties = propertiesWith((trace) => lasso(graph, trace, spec.variables, find));
|
|
480
|
+
return {
|
|
481
|
+
...common,
|
|
482
|
+
graph,
|
|
483
|
+
paths: undefined,
|
|
484
|
+
properties,
|
|
485
|
+
drawing,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const drawn = pathGraph(spec.variables);
|
|
490
|
+
const paths: Bug[] = [];
|
|
491
|
+
for (const rule of rules) {
|
|
492
|
+
const { outcome, messages } = must(verdicts, ruleKey(rule));
|
|
493
|
+
if (outcome === "broken" && messages)
|
|
494
|
+
paths.push(drawn.bug(rule, readCounterexample(messages)));
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
...common,
|
|
498
|
+
graph: drawn.graph,
|
|
499
|
+
paths,
|
|
500
|
+
properties: propertiesWith(drawn.lasso),
|
|
501
|
+
drawing: undefined,
|
|
502
|
+
};
|
|
503
|
+
} finally {
|
|
504
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
505
|
+
}
|
|
506
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
self=$0
|
|
3
|
+
while [ -L "$self" ]; do
|
|
4
|
+
link=$(readlink "$self")
|
|
5
|
+
case $link in
|
|
6
|
+
/*) self=$link ;;
|
|
7
|
+
*) self=$(dirname "$self")/$link ;;
|
|
8
|
+
esac
|
|
9
|
+
done
|
|
10
|
+
entry=$(dirname "$self")/statechart.ts
|
|
11
|
+
version() {
|
|
12
|
+
command -v "$1" >/dev/null || { echo 0; return; }
|
|
13
|
+
"$1" --version 2>/dev/null | sed -n '1s/[^0-9]*\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3/p' | {
|
|
14
|
+
read -r major minor patch
|
|
15
|
+
echo $((${major:-0} * 1000000 + ${minor:-0} * 1000 + ${patch:-0}))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
node=$(version node)
|
|
19
|
+
if [ "$node" -ge 23006000 ] || { [ "$node" -ge 22018000 ] && [ "$node" -lt 23000000 ]; }; then
|
|
20
|
+
exec node --disable-warning=ExperimentalWarning "$entry" "$@"
|
|
21
|
+
fi
|
|
22
|
+
if [ "$(version bun)" -ge 1001005 ]; then
|
|
23
|
+
exec bun "$entry" "$@"
|
|
24
|
+
fi
|
|
25
|
+
if [ "$(version deno)" -ge 2000000 ]; then
|
|
26
|
+
exec deno run --quiet --no-prompt --allow-read --allow-write --allow-run --allow-env "$entry" "$@"
|
|
27
|
+
fi
|
|
28
|
+
echo "statechart needs Node 22.18 to 22.x, Node 23.6 or later, Bun 1.1.5 or later, or Deno 2.0 or later." >&2
|
|
29
|
+
exit 127
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { killGroup, messageOf } from "./run.ts";
|
|
8
|
+
|
|
9
|
+
const USAGE = `Usage: statechart SPEC.tla [--config FILE] [--view FILE] [--out DIR]
|
|
10
|
+
|
|
11
|
+
Checks SPEC.tla with TLC and draws its state graph as Mermaid. Above 500 states, the chart
|
|
12
|
+
draws only the paths to the rules that break, and with no rule broken there is no chart.mmd.
|
|
13
|
+
--config FILE TLC config. Default: SPEC.cfg beside the spec.
|
|
14
|
+
--view FILE A module that exports state(vars) and, if you want, step(action, from, to),
|
|
15
|
+
group(vars), colors, and title. state() returns a string for a flat chart, an
|
|
16
|
+
array for parent states, or an object for regions. Default: each state's values.
|
|
17
|
+
colors gives each group blue, orange, purple, yellow, teal, tan, or pink.
|
|
18
|
+
--out DIR Where to write report.md, chart.mmd, tlc.out, and tlc-RULE.out for each
|
|
19
|
+
property that breaks and each rule that breaks off the chart. The folder must
|
|
20
|
+
be new or empty. Default: SPEC-chart.
|
|
21
|
+
Exit code: TLC's own on the config as written: 0 when every rule holds, 1 when a rule breaks,
|
|
22
|
+
and 2 when TLC stops with an error, a signal kills the check, or the command cannot run. 130 or
|
|
23
|
+
143 when SIGINT or SIGTERM stops the check. Only exits 0 and 1 write output.`;
|
|
24
|
+
|
|
25
|
+
let stop: NodeJS.Signals | undefined;
|
|
26
|
+
const stopped = new Promise<void>((resolve) => {
|
|
27
|
+
for (const name of ["SIGINT", "SIGTERM"] as const)
|
|
28
|
+
process.on(name, () => {
|
|
29
|
+
stop ??= name;
|
|
30
|
+
resolve();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
let flags;
|
|
35
|
+
let specFile;
|
|
36
|
+
try {
|
|
37
|
+
const args = parseArgs({
|
|
38
|
+
allowPositionals: true,
|
|
39
|
+
options: { config: { type: "string" }, view: { type: "string" }, out: { type: "string" } },
|
|
40
|
+
});
|
|
41
|
+
flags = args.values;
|
|
42
|
+
[specFile] = args.positionals;
|
|
43
|
+
if (args.positionals.length !== 1) throw new Error("Give one SPEC.tla.");
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error(`${messageOf(error)}\n\n${USAGE}`);
|
|
46
|
+
process.exit(2);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const codeOf = (error: unknown) =>
|
|
50
|
+
error instanceof Error && "code" in error ? error.code : undefined;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const configFile = flags.config ?? specFile.replace(/\.tla$/, ".cfg");
|
|
54
|
+
if (!fs.existsSync(configFile))
|
|
55
|
+
throw new Error(`Cannot find the TLC config ${configFile}. Pass --config FILE.`);
|
|
56
|
+
const out = flags.out ?? specFile.replace(/\.tla$/, "-chart");
|
|
57
|
+
let entries: string[] = [];
|
|
58
|
+
let dest: string;
|
|
59
|
+
try {
|
|
60
|
+
entries = fs.readdirSync(out);
|
|
61
|
+
dest = fs.realpathSync(out);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (codeOf(error) !== "ENOENT")
|
|
64
|
+
throw new Error(
|
|
65
|
+
`${out} cannot be the output folder. ${messageOf(error)}. Pass --out with a new folder.`,
|
|
66
|
+
{ cause: error },
|
|
67
|
+
);
|
|
68
|
+
if (fs.lstatSync(out, { throwIfNoEntry: false }))
|
|
69
|
+
throw new Error(
|
|
70
|
+
`${out} cannot be the output folder. It is a broken link. Pass --out with a new folder.`,
|
|
71
|
+
{ cause: error },
|
|
72
|
+
);
|
|
73
|
+
dest = path.resolve(out);
|
|
74
|
+
}
|
|
75
|
+
if (entries.length)
|
|
76
|
+
throw new Error(
|
|
77
|
+
`${out} is not empty. It has ${entries.sort()[0]}. The command writes only to a new or empty folder. Pass --out with a new folder.`,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let base = path.dirname(dest);
|
|
81
|
+
while (!fs.existsSync(base)) base = path.dirname(base);
|
|
82
|
+
const stage = fs.mkdtempSync(path.join(base, `.${path.basename(dest)}.statechart-`));
|
|
83
|
+
const done = path.join(stage, "done");
|
|
84
|
+
let tmp: string | undefined;
|
|
85
|
+
let janitor: ChildProcess | undefined;
|
|
86
|
+
let exitCode: number;
|
|
87
|
+
try {
|
|
88
|
+
tmp = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-"));
|
|
89
|
+
const runtime = process.versions.deno
|
|
90
|
+
? [
|
|
91
|
+
"run",
|
|
92
|
+
"--quiet",
|
|
93
|
+
"--no-prompt",
|
|
94
|
+
"--allow-read",
|
|
95
|
+
"--allow-write",
|
|
96
|
+
"--allow-run",
|
|
97
|
+
"--allow-env",
|
|
98
|
+
]
|
|
99
|
+
: process.execArgv;
|
|
100
|
+
const worker = spawn(
|
|
101
|
+
process.execPath,
|
|
102
|
+
[
|
|
103
|
+
...runtime,
|
|
104
|
+
path.join(import.meta.dirname, "worker.ts"),
|
|
105
|
+
stage,
|
|
106
|
+
specFile,
|
|
107
|
+
configFile,
|
|
108
|
+
...(flags.view ? [flags.view] : []),
|
|
109
|
+
],
|
|
110
|
+
{
|
|
111
|
+
detached: true,
|
|
112
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
113
|
+
env: { ...process.env, TMPDIR: tmp },
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
janitor = spawn(
|
|
117
|
+
"/bin/sh",
|
|
118
|
+
[
|
|
119
|
+
"-c",
|
|
120
|
+
'while read -r line; do :; done; kill -s KILL -- "-$1"; rm -rf -- "$2" "$3"',
|
|
121
|
+
"sh",
|
|
122
|
+
String(worker.pid),
|
|
123
|
+
stage,
|
|
124
|
+
tmp,
|
|
125
|
+
],
|
|
126
|
+
{ detached: true, stdio: ["pipe", "ignore", "ignore"] },
|
|
127
|
+
);
|
|
128
|
+
const exited = new Promise<number>((resolve) =>
|
|
129
|
+
worker.on("exit", (code) => resolve(code ?? 2)),
|
|
130
|
+
);
|
|
131
|
+
await Promise.race([stopped, exited]);
|
|
132
|
+
await killGroup(worker.pid as number);
|
|
133
|
+
const verdict = await exited;
|
|
134
|
+
if (stop) {
|
|
135
|
+
console.error(`${stop} stopped the check, so the command wrote nothing.`);
|
|
136
|
+
exitCode = 128 + os.constants.signals[stop];
|
|
137
|
+
} else if (worker.signalCode) {
|
|
138
|
+
console.error(`${worker.signalCode} killed the check, so the command wrote nothing.`);
|
|
139
|
+
exitCode = 2;
|
|
140
|
+
} else if ((verdict === 0 || verdict === 1) && fs.existsSync(done)) {
|
|
141
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
142
|
+
try {
|
|
143
|
+
fs.renameSync(done, dest);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (codeOf(error) !== "ENOTEMPTY" && codeOf(error) !== "EEXIST") throw error;
|
|
146
|
+
throw new Error(
|
|
147
|
+
`${path.join(out, fs.readdirSync(dest).sort()[0])} appeared while the check ran, so the command wrote nothing. Pass --out with a new folder.`,
|
|
148
|
+
{ cause: error },
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
process.stdout.write(fs.readFileSync(path.join(dest, "report.md")));
|
|
152
|
+
console.log(`\nWrote ${out}`);
|
|
153
|
+
exitCode = verdict;
|
|
154
|
+
} else exitCode = 2;
|
|
155
|
+
} finally {
|
|
156
|
+
fs.rmSync(stage, { recursive: true, force: true });
|
|
157
|
+
if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
|
|
158
|
+
janitor?.kill("SIGKILL");
|
|
159
|
+
}
|
|
160
|
+
process.exit(exitCode);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error(messageOf(error));
|
|
163
|
+
process.exit(2);
|
|
164
|
+
}
|