@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,249 @@
|
|
|
1
|
+
import { append, byText, type Chart, type ChartState, type Region, tupleKey } from "../ir.ts";
|
|
2
|
+
|
|
3
|
+
const BLANK = /\p{White_Space}/u;
|
|
4
|
+
const SAFE = /^[\p{L}\p{N} !'()+,\-./=?[\]"_|@{}:\\^%<>]$/u;
|
|
5
|
+
const HAZARD =
|
|
6
|
+
/:(?=:|$|\S*#)|\\(?=n)|%(?=%)|<(?=[\p{L}/!?])|_(?![\p{L}\p{N}])|(?<![\p{L}\p{N}])_/giu;
|
|
7
|
+
const DIRECTION = /(direction)\s+(?=LR|RL|TB|BT)/gi;
|
|
8
|
+
const DOUBLE_BRACKET = /\[(?=\[)/g;
|
|
9
|
+
const C4 = /C4(?=Container|Component|Dynamic|Deployment)/g;
|
|
10
|
+
const UNDRAWN = /[\0\x80-\x9f]/;
|
|
11
|
+
const REWRITTEN = ["fl°", "¶ß"];
|
|
12
|
+
const MARKER = /(?<=marker-end=)"/g;
|
|
13
|
+
const firstOf = new Map<number, number>();
|
|
14
|
+
for (const pair of REWRITTEN) {
|
|
15
|
+
const [first, second] = [...pair].map((c) => c.codePointAt(0) ?? 0);
|
|
16
|
+
firstOf.set(second, first);
|
|
17
|
+
}
|
|
18
|
+
const KEPT = 0;
|
|
19
|
+
const BLANKED = 1;
|
|
20
|
+
const DROPPED = 2;
|
|
21
|
+
const CODED = 3;
|
|
22
|
+
const JOINS = 4;
|
|
23
|
+
const kindOf = (n: number) => {
|
|
24
|
+
const c = String.fromCodePoint(n);
|
|
25
|
+
const kind =
|
|
26
|
+
c === " "
|
|
27
|
+
? KEPT
|
|
28
|
+
: BLANK.test(c)
|
|
29
|
+
? BLANKED
|
|
30
|
+
: UNDRAWN.test(c)
|
|
31
|
+
? DROPPED
|
|
32
|
+
: SAFE.test(c)
|
|
33
|
+
? KEPT
|
|
34
|
+
: CODED;
|
|
35
|
+
return firstOf.has(n) ? kind | JOINS : kind;
|
|
36
|
+
};
|
|
37
|
+
const ASCII = Uint8Array.from({ length: 128 }, (_, n) => kindOf(n));
|
|
38
|
+
const wide = new Map<number, number>();
|
|
39
|
+
const kindAt = (n: number) => {
|
|
40
|
+
if (n < 128) return ASCII[n];
|
|
41
|
+
let kind = wide.get(n);
|
|
42
|
+
if (kind === undefined) wide.set(n, (kind = kindOf(n)));
|
|
43
|
+
return kind;
|
|
44
|
+
};
|
|
45
|
+
const encode = (s: string, ref: (n: number) => string) => {
|
|
46
|
+
let out = "";
|
|
47
|
+
let run = 0;
|
|
48
|
+
let last = -1;
|
|
49
|
+
for (let i = 0; i < s.length;) {
|
|
50
|
+
let n = s.charCodeAt(i);
|
|
51
|
+
let width = 1;
|
|
52
|
+
if (n >= 0xd800 && n <= 0xdfff) {
|
|
53
|
+
const low = s.charCodeAt(i + 1);
|
|
54
|
+
if (n <= 0xdbff && low >= 0xdc00 && low <= 0xdfff) {
|
|
55
|
+
n = 0x10000 + ((n - 0xd800) << 10) + (low - 0xdc00);
|
|
56
|
+
width = 2;
|
|
57
|
+
} else n = 0xfffd;
|
|
58
|
+
}
|
|
59
|
+
let kind = kindAt(n);
|
|
60
|
+
if (kind === DROPPED) {
|
|
61
|
+
out += s.slice(run, i);
|
|
62
|
+
run = i + width;
|
|
63
|
+
} else {
|
|
64
|
+
const joined = kind >= JOINS && firstOf.get(n) === last;
|
|
65
|
+
kind &= ~JOINS;
|
|
66
|
+
if (joined || kind !== KEPT) {
|
|
67
|
+
out += s.slice(run, i);
|
|
68
|
+
if (joined) out += ref(0x2060);
|
|
69
|
+
if (kind === KEPT) run = i;
|
|
70
|
+
else {
|
|
71
|
+
out += kind === BLANKED ? " " : ref(n);
|
|
72
|
+
run = i + width;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
last = n;
|
|
76
|
+
}
|
|
77
|
+
i += width;
|
|
78
|
+
}
|
|
79
|
+
return out + s.slice(run);
|
|
80
|
+
};
|
|
81
|
+
const code = (s: string, ref: (n: number) => string) =>
|
|
82
|
+
encode(s, ref)
|
|
83
|
+
.replace(MARKER, `${ref(0x2060)}"`)
|
|
84
|
+
.replace(HAZARD, (c) => ref(c.charCodeAt(0)));
|
|
85
|
+
const esc = (s: string, quoted = false) => {
|
|
86
|
+
const plain = code(s, (n) => `#${n};`);
|
|
87
|
+
const out = quoted ? plain.replaceAll('"', "#34;") : plain;
|
|
88
|
+
if (!out.trim()) return "#32;";
|
|
89
|
+
const turned = out.replace(DIRECTION, "$1#32;");
|
|
90
|
+
const opened = turned.includes("[[") ? turned.replace(DOUBLE_BRACKET, "#91;") : turned;
|
|
91
|
+
return opened.includes("C4") ? opened.replace(C4, "C#52;") : opened;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const or = (names: Iterable<string>) => [...names].sort(byText).join(" or ");
|
|
95
|
+
|
|
96
|
+
type Edge = { from: string[]; start: boolean; to: string[]; label: string | undefined };
|
|
97
|
+
|
|
98
|
+
const within = (parent: string[], path: string[]) =>
|
|
99
|
+
path.length >= parent.length && parent.every((p, i) => path[i] === p);
|
|
100
|
+
const wayIn = (e: Edge) => tupleKey([e.start, e.from]);
|
|
101
|
+
|
|
102
|
+
export function drawnEdges(r: Region): Edge[] {
|
|
103
|
+
let out: Edge[] = [];
|
|
104
|
+
for (const s of r.states)
|
|
105
|
+
if (s.start) out.push({ from: [], start: true, to: s.path, label: undefined });
|
|
106
|
+
for (const s of r.steps)
|
|
107
|
+
out.push({
|
|
108
|
+
from: s.from,
|
|
109
|
+
start: false,
|
|
110
|
+
to: s.to,
|
|
111
|
+
label: s.label + (s.when ? ` [${s.when}]` : ""),
|
|
112
|
+
});
|
|
113
|
+
const parents = new Map<string, string[]>();
|
|
114
|
+
for (const s of r.states)
|
|
115
|
+
for (let i = 1; i < s.path.length; i++) {
|
|
116
|
+
const prefix = s.path.slice(0, i);
|
|
117
|
+
parents.set(tupleKey(prefix), prefix);
|
|
118
|
+
}
|
|
119
|
+
for (const parent of [...parents.values()].sort((a, b) => a.length - b.length)) {
|
|
120
|
+
const into = out.filter(
|
|
121
|
+
(e) => e.to.length > parent.length && within(parent, e.to) && !within(parent, e.from),
|
|
122
|
+
);
|
|
123
|
+
if (!into.length || into.some((e) => wayIn(e) !== wayIn(into[0]))) continue;
|
|
124
|
+
const one = into.length === 1;
|
|
125
|
+
const at = out.indexOf(into[0]);
|
|
126
|
+
out = out.filter((e) => !into.includes(e));
|
|
127
|
+
out.splice(
|
|
128
|
+
at,
|
|
129
|
+
0,
|
|
130
|
+
{ ...into[0], to: parent, label: one ? into[0].label : undefined },
|
|
131
|
+
...into.map((e) => ({
|
|
132
|
+
from: parent,
|
|
133
|
+
start: true,
|
|
134
|
+
to: e.to,
|
|
135
|
+
label: one ? undefined : e.label,
|
|
136
|
+
})),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const MARK_STYLES = {
|
|
143
|
+
breaks: "fill:#ffecee,stroke:#e72e3b,stroke-width:2.5px,color:#cd2834",
|
|
144
|
+
mayBreak: "fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06",
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export function mermaidLines(chart: Chart) {
|
|
148
|
+
let next = 0;
|
|
149
|
+
const marks: string[] = [];
|
|
150
|
+
const used = new Set<string>();
|
|
151
|
+
const rules = { breaks: new Set<string>(), mayBreak: new Set<string>() };
|
|
152
|
+
const region = (r: Region) => {
|
|
153
|
+
const out: string[] = [];
|
|
154
|
+
const topIds = new Map<string, string>();
|
|
155
|
+
const nestedIds = new Map<string, string>();
|
|
156
|
+
const id = (path: string[]) => {
|
|
157
|
+
const top = path.length === 1;
|
|
158
|
+
const named = top ? topIds : nestedIds;
|
|
159
|
+
const k = top ? path[0] : tupleKey(path);
|
|
160
|
+
let s = named.get(k);
|
|
161
|
+
if (s === undefined) named.set(k, (s = `s${next++}`));
|
|
162
|
+
return s;
|
|
163
|
+
};
|
|
164
|
+
const known = new Map<string[], string>();
|
|
165
|
+
const idOf = (path: string[]) => {
|
|
166
|
+
let s = known.get(path);
|
|
167
|
+
if (s === undefined) known.set(path, (s = id(path)));
|
|
168
|
+
return s;
|
|
169
|
+
};
|
|
170
|
+
const drawn = drawnEdges(r);
|
|
171
|
+
const line = (e: Edge, indent: string) =>
|
|
172
|
+
`${indent}${e.start ? "[*]" : idOf(e.from)} --> ${idOf(e.to)}${e.label === undefined ? "" : `: ${esc(e.label)}`}`;
|
|
173
|
+
const tree = (prefix: string[], indent: string, below: ChartState[]) => {
|
|
174
|
+
const heads = new Map<string, ChartState[]>();
|
|
175
|
+
for (const s of below) append(heads, s.path[prefix.length], s);
|
|
176
|
+
for (const [head, under] of heads) {
|
|
177
|
+
const path = [...prefix, head];
|
|
178
|
+
let leaf: ChartState | undefined;
|
|
179
|
+
const inner: ChartState[] = [];
|
|
180
|
+
for (const s of under)
|
|
181
|
+
if (s.path.length > path.length) inner.push(s);
|
|
182
|
+
else leaf = s;
|
|
183
|
+
if (inner.length) {
|
|
184
|
+
out.push(`${indent}state "${esc(head, true)}" as ${id(path)} {`);
|
|
185
|
+
tree(path, indent + " ", inner);
|
|
186
|
+
const key = tupleKey(path);
|
|
187
|
+
for (const e of drawn)
|
|
188
|
+
if (e.start && tupleKey(e.from) === key) out.push(line(e, `${indent} `));
|
|
189
|
+
out.push(`${indent}}`);
|
|
190
|
+
} else if (leaf) {
|
|
191
|
+
const sid = idOf(leaf.path);
|
|
192
|
+
out.push(`${indent}${sid}: ${esc(head)}`);
|
|
193
|
+
let mark: "breaks" | "mayBreak" | undefined =
|
|
194
|
+
leaf.breaks.length && !leaf.works ? "mayBreak" : undefined;
|
|
195
|
+
if (mark) for (const b of leaf.breaks) if (b.always) mark = "breaks";
|
|
196
|
+
if (mark) for (const b of leaf.breaks) rules[mark].add(b.rule.name);
|
|
197
|
+
const trail = [leaf.lead && "bugPath", leaf.repeats && "repeats"];
|
|
198
|
+
const color = leaf.group === undefined ? undefined : chart.colors[String(leaf.group)];
|
|
199
|
+
for (const cls of [color, mark, ...trail])
|
|
200
|
+
if (cls) {
|
|
201
|
+
used.add(cls);
|
|
202
|
+
marks.push(` class ${sid} ${cls}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
tree([], " ", r.states);
|
|
208
|
+
for (const e of drawn) if (!e.start || !e.from.length) out.push(line(e, " "));
|
|
209
|
+
return out;
|
|
210
|
+
};
|
|
211
|
+
let body: string[];
|
|
212
|
+
if (chart.regions.length > 1) {
|
|
213
|
+
body = [` state "At the same time" as all {`];
|
|
214
|
+
for (const [i, r] of chart.regions.entries()) {
|
|
215
|
+
if (i) body.push(" --");
|
|
216
|
+
body.push(` state "${esc(r.name, true)}" as r${i} {`);
|
|
217
|
+
for (const line of region(r)) body.push(` ${line}`);
|
|
218
|
+
body.push(" }");
|
|
219
|
+
}
|
|
220
|
+
body.push(" }");
|
|
221
|
+
} else body = region(chart.regions[0]);
|
|
222
|
+
const legend: string[][] = [];
|
|
223
|
+
for (const entry of [
|
|
224
|
+
...Object.entries(chart.colors),
|
|
225
|
+
[`Breaks ${or(rules.breaks)}`, "breaks"],
|
|
226
|
+
[`Breaks ${or(rules.mayBreak)} in some cases`, "mayBreak"],
|
|
227
|
+
[`Path to the ${or(chart.paths)} bug`, "bugPath"],
|
|
228
|
+
[`Repeats forever, so ${or(chart.loops)} breaks`, "repeats"],
|
|
229
|
+
])
|
|
230
|
+
if (used.has(entry[1])) legend.push(entry);
|
|
231
|
+
const lines: string[] = [];
|
|
232
|
+
const title = chart.title && code(chart.title, (n) => `fl°°${n}¶ß`).replaceAll("<", "fl°°60¶ß");
|
|
233
|
+
if (title) lines.push("---", `title: ${JSON.stringify(title)}`, "---");
|
|
234
|
+
lines.push("stateDiagram-v2");
|
|
235
|
+
if (chart.regions.length > 1) lines.push(" direction LR");
|
|
236
|
+
if (legend.length) {
|
|
237
|
+
lines.push(` state "Legend" as legend {`);
|
|
238
|
+
for (const [i, [text]] of legend.entries()) lines.push(` lg${i}: ${esc(text)}`);
|
|
239
|
+
lines.push(" }");
|
|
240
|
+
for (const [i, [, cls]] of legend.entries()) lines.push(` class lg${i} ${cls}`);
|
|
241
|
+
}
|
|
242
|
+
for (const line of body) lines.push(line);
|
|
243
|
+
for (const [cls, style] of Object.entries(MARK_STYLES))
|
|
244
|
+
if (used.has(cls)) lines.push(` classDef ${cls} ${style}`);
|
|
245
|
+
for (const line of marks) lines.push(line);
|
|
246
|
+
return lines;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const mermaid = (chart: Chart) => mermaidLines(chart).join("\n");
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { EC, LEVEL, type Message, PART, type Part } from "../ir.ts";
|
|
2
|
+
|
|
3
|
+
const PREFIX: { [level: number]: string } = {
|
|
4
|
+
[LEVEL.ERROR]: "Error: ",
|
|
5
|
+
[LEVEL.TLCBUG]: "TLC Bug: ",
|
|
6
|
+
[LEVEL.WARNING]: "Warning: ",
|
|
7
|
+
[LEVEL.STATE]: "State ",
|
|
8
|
+
};
|
|
9
|
+
const MINUTE = 60_000;
|
|
10
|
+
const HOUR = 3_600_000;
|
|
11
|
+
const DAY = 86_400_000;
|
|
12
|
+
|
|
13
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
14
|
+
|
|
15
|
+
export function runtime(ms: number) {
|
|
16
|
+
const t = new Date(ms > DAY ? ms - DAY : ms);
|
|
17
|
+
const [hh, mm, ss] = [t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds()].map(pad);
|
|
18
|
+
if (ms > DAY)
|
|
19
|
+
return `${Math.floor((t.getTime() - Date.UTC(t.getUTCFullYear(), 0, 1)) / DAY) + 1}d ${hh}h`;
|
|
20
|
+
if (ms > HOUR) return `${hh}h ${mm}min`;
|
|
21
|
+
if (ms > MINUTE) return `${mm}min ${ss}s`;
|
|
22
|
+
return `${ss}s`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const firstLine = ({ code, level }: Message, line: string) => {
|
|
26
|
+
if (code === EC.TLC_BACK_TO_STATE)
|
|
27
|
+
return line.replace(/^(\d+): Back to state: /, "Back to state $1: ");
|
|
28
|
+
if (code === EC.TLC_FINISHED)
|
|
29
|
+
return line.replace(
|
|
30
|
+
/^Finished in (\d+)ms/,
|
|
31
|
+
(_, ms: string) => `Finished in ${runtime(Number(ms))}`,
|
|
32
|
+
);
|
|
33
|
+
return (PREFIX[level] ?? "") + line;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const render = (m: Message): string =>
|
|
37
|
+
(m.beforeMarker ?? "") +
|
|
38
|
+
firstLine(m, m.body.map((part) => (typeof part === "string" ? part : render(part))).join("\n"));
|
|
39
|
+
|
|
40
|
+
function* printed(parts: Iterable<Part>): Generator<string> {
|
|
41
|
+
let warned = false;
|
|
42
|
+
let progress: Message | undefined;
|
|
43
|
+
for (const part of parts) {
|
|
44
|
+
if (progress?.body.length && (typeof part === "string" || part.code !== EC.TLC_STATS))
|
|
45
|
+
yield render(progress);
|
|
46
|
+
progress = undefined;
|
|
47
|
+
if (typeof part === "string") {
|
|
48
|
+
yield part;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (part.code === EC.TLC_SANY_START || part.code === EC.TLC_SANY_END) continue;
|
|
52
|
+
if (part.code === EC.TLC_PROGRESS_STATS) progress = part;
|
|
53
|
+
else if (part.body.length) yield render(part);
|
|
54
|
+
if (part.level === LEVEL.WARNING && !warned) {
|
|
55
|
+
yield "(Use the -nowarning option to disable this warning.)";
|
|
56
|
+
warned = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (progress?.body.length) yield render(progress);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function* plainText(parts: Iterable<Part>): Generator<string> {
|
|
63
|
+
let chunk = "";
|
|
64
|
+
for (const line of printed(parts)) {
|
|
65
|
+
chunk += `${line}\n`;
|
|
66
|
+
if (chunk.length >= PART) {
|
|
67
|
+
yield chunk;
|
|
68
|
+
chunk = "";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (chunk) yield chunk;
|
|
72
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Bug,
|
|
3
|
+
CHART_STATES,
|
|
4
|
+
type Chart,
|
|
5
|
+
type Graph,
|
|
6
|
+
hasSection,
|
|
7
|
+
list,
|
|
8
|
+
must,
|
|
9
|
+
type Property,
|
|
10
|
+
RERUN_STATES,
|
|
11
|
+
ruleKey,
|
|
12
|
+
type Spec,
|
|
13
|
+
type Stop,
|
|
14
|
+
type Story,
|
|
15
|
+
type Verdict,
|
|
16
|
+
} from "../ir.ts";
|
|
17
|
+
|
|
18
|
+
const stepsOf = (story: Story) => {
|
|
19
|
+
const path: { step?: string; state: string }[] = [];
|
|
20
|
+
for (const { step, state } of story) {
|
|
21
|
+
const parts: string[] = [];
|
|
22
|
+
for (const [name, names] of Object.entries(state))
|
|
23
|
+
parts.push((name ? `${name} ` : "") + names.join(" / "));
|
|
24
|
+
path.push({ step, state: parts.join(", ") });
|
|
25
|
+
}
|
|
26
|
+
return path;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const forever = (loop: { state: string }[], stutters: boolean | undefined) => {
|
|
30
|
+
const quoted = new Set<string>();
|
|
31
|
+
for (const p of loop) quoted.add(`"${p.state}"`);
|
|
32
|
+
const runs = [...quoted];
|
|
33
|
+
if (stutters) return `The run stops in ${runs[0]} forever.`;
|
|
34
|
+
return runs.length === 1
|
|
35
|
+
? `The run stays in ${runs[0]} forever.`
|
|
36
|
+
: `The run loops through ${list(runs)} forever.`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const fenced = (text: string) => ["```", text, "```"].join("\n");
|
|
40
|
+
|
|
41
|
+
export function report(
|
|
42
|
+
{
|
|
43
|
+
spec,
|
|
44
|
+
graph,
|
|
45
|
+
paths,
|
|
46
|
+
rules,
|
|
47
|
+
properties,
|
|
48
|
+
stop,
|
|
49
|
+
drawing,
|
|
50
|
+
states,
|
|
51
|
+
}: {
|
|
52
|
+
spec: Spec;
|
|
53
|
+
graph: Graph;
|
|
54
|
+
paths: Bug[] | undefined;
|
|
55
|
+
rules: Verdict[];
|
|
56
|
+
properties: Property[];
|
|
57
|
+
stop: Stop | undefined;
|
|
58
|
+
drawing: { status: number | null } | undefined;
|
|
59
|
+
states: { distinct: number; initial: number; complete: boolean; cut: boolean };
|
|
60
|
+
},
|
|
61
|
+
found: Bug[],
|
|
62
|
+
chart: Chart | undefined,
|
|
63
|
+
stories: Map<Bug, Story>,
|
|
64
|
+
) {
|
|
65
|
+
let size = 0;
|
|
66
|
+
let arrows = 0;
|
|
67
|
+
for (const r of chart?.regions ?? []) {
|
|
68
|
+
size += r.states.length;
|
|
69
|
+
arrows += r.steps.length;
|
|
70
|
+
}
|
|
71
|
+
let past = 0;
|
|
72
|
+
let pastSteps = 0;
|
|
73
|
+
let excluded = 0;
|
|
74
|
+
for (const s of graph.states.values()) {
|
|
75
|
+
if (s.excluded) excluded++;
|
|
76
|
+
else if (s.past) past++;
|
|
77
|
+
}
|
|
78
|
+
for (const t of graph.steps) if (must(graph.states, t.to).past) pastSteps++;
|
|
79
|
+
const includes = (n: number) =>
|
|
80
|
+
chart ? `, and the chart includes ${n === 1 ? "it" : "them"}` : "";
|
|
81
|
+
const out = [
|
|
82
|
+
`# ${spec.module}`,
|
|
83
|
+
"",
|
|
84
|
+
paths
|
|
85
|
+
? `TLC reached ${states.complete && !states.cut && states.distinct > CHART_STATES ? `${states.distinct.toLocaleString("en-US")} states, more than` : "more states than"} the chart budget of ${CHART_STATES}, so ${chart ? `the chart draws only the bug paths: ${size} states and ${arrows} arrows` : "the command wrote no chart.mmd"}.`
|
|
86
|
+
: `TLC reached ${graph.states.size - past - excluded} states and ${graph.steps.length - pastSteps} steps. The chart draws ${size} states and ${arrows} arrows.`,
|
|
87
|
+
];
|
|
88
|
+
if (drawing)
|
|
89
|
+
out.push(
|
|
90
|
+
`TLC stopped the drawing run with exit ${drawing.status}, so the chart draws only the states that it reached before it stopped.`,
|
|
91
|
+
);
|
|
92
|
+
if (!paths && !drawing && graph.states.size === past + excluded)
|
|
93
|
+
out.push(
|
|
94
|
+
states.initial
|
|
95
|
+
? "Every initial state is outside the constraints, so TLC explores none of them."
|
|
96
|
+
: "TLC found no state that satisfies Init, so no state can break a rule.",
|
|
97
|
+
);
|
|
98
|
+
if (past)
|
|
99
|
+
out.push(
|
|
100
|
+
`${past === 1 ? "1 state outside the constraints ends" : `${past} states outside the constraints each end`} a rule's path${includes(past)}. TLC checks the rules in a state outside the constraints, but it does not explore past it.`,
|
|
101
|
+
);
|
|
102
|
+
if (excluded)
|
|
103
|
+
out.push(
|
|
104
|
+
`${excluded === 1 ? "1 step that the constraints exclude ends" : `${excluded} steps that the constraints exclude each end`} a rule's path${includes(excluded)}. TLC checks the rules after such a step, but it does not take the step.`,
|
|
105
|
+
);
|
|
106
|
+
if (chart?.inside)
|
|
107
|
+
out.push(`The chart does not draw ${chart.inside} steps that stay in one chart state.`);
|
|
108
|
+
if (chart?.quiet)
|
|
109
|
+
out.push(`The view hides ${chart.quiet} steps, so the chart does not draw them.`);
|
|
110
|
+
for (const { rule, outcome } of rules)
|
|
111
|
+
if (
|
|
112
|
+
!paths &&
|
|
113
|
+
rule.kind === "deadlock" &&
|
|
114
|
+
outcome === "broken" &&
|
|
115
|
+
(drawing || hasSection(spec, "CONSTRAINT", "ACTION_CONSTRAINT"))
|
|
116
|
+
)
|
|
117
|
+
out.push(
|
|
118
|
+
drawing
|
|
119
|
+
? "The chart marks only the deadlock that TLC reports, because the drawing run stopped before it reached every state."
|
|
120
|
+
: "The chart marks only the deadlock that TLC reports. Under a CONSTRAINT or an ACTION_CONSTRAINT, a state with no step in the chart can still have steps that the constraints leave out, and TLC does not count it as a deadlock.",
|
|
121
|
+
);
|
|
122
|
+
if (chart?.lie) out.push(`${chart.lie} So the chart draws parent states in place of regions.`);
|
|
123
|
+
out.push(...(chart?.notes ?? []));
|
|
124
|
+
const merged: string[] = [];
|
|
125
|
+
for (const k of ["VIEW", "SYMMETRY"]) if (hasSection(spec, k)) merged.push(k);
|
|
126
|
+
if (chart && merged.length)
|
|
127
|
+
out.push(
|
|
128
|
+
`With ${list(merged)}, TLC keeps one representative for each group of states that it counts as the same. An arrow can lead to the representative rather than to the state that the step reaches.`,
|
|
129
|
+
);
|
|
130
|
+
for (const bug of found) {
|
|
131
|
+
const steps = `${bug.path.length} step${bug.path.length === 1 ? "" : "s"}`;
|
|
132
|
+
out.push("", `## ${bug.rule.name} breaks`);
|
|
133
|
+
out.push(
|
|
134
|
+
bug.rule.kind === "property"
|
|
135
|
+
? `TLC's counterexample is in tlc-${bug.rule.name}.out. It has ${steps}:`
|
|
136
|
+
: `The shortest path has ${steps}:`,
|
|
137
|
+
);
|
|
138
|
+
const path = stepsOf(must(stories, bug));
|
|
139
|
+
for (const [i, p] of path.entries()) out.push(`${i}. ${p.step ? `${p.step}: ` : ""}${p.state}`);
|
|
140
|
+
if (bug.loop !== undefined) out.push(forever(path.slice(bug.loop), bug.stutters));
|
|
141
|
+
}
|
|
142
|
+
const drawn = new Set<string>();
|
|
143
|
+
for (const b of found) drawn.add(ruleKey(b.rule));
|
|
144
|
+
const holds: string[] = [];
|
|
145
|
+
const unchecked: string[] = [];
|
|
146
|
+
for (const { rule, outcome, messages } of [...rules, ...properties]) {
|
|
147
|
+
if (outcome === "holds") holds.push(rule.name);
|
|
148
|
+
else if (outcome === "not checked") unchecked.push(rule.name);
|
|
149
|
+
else if (messages && !drawn.has(ruleKey(rule)))
|
|
150
|
+
out.push(
|
|
151
|
+
"",
|
|
152
|
+
`## ${rule.name} breaks`,
|
|
153
|
+
`TLC found a counterexample. It is in tlc-${rule.name}.out.`,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (holds.length) out.push("", "## Rules that hold", holds.join(", "));
|
|
157
|
+
if (unchecked.length) out.push("", "## Rules not checked", unchecked.join(", "));
|
|
158
|
+
if (unchecked.length && states.cut)
|
|
159
|
+
out.push(
|
|
160
|
+
`After the first break, each TLC run stops at ${RERUN_STATES.toLocaleString("en-US")} distinct states. A run reached that bound before it checked ${unchecked.length === 1 ? "this rule" : "these rules"} in every state.`,
|
|
161
|
+
);
|
|
162
|
+
if (stop)
|
|
163
|
+
out.push(
|
|
164
|
+
...(unchecked.length
|
|
165
|
+
? [
|
|
166
|
+
`TLC stopped with exit ${stop.status} before it checked ${unchecked.length === 1 ? "this rule" : "these rules"}:`,
|
|
167
|
+
]
|
|
168
|
+
: ["", "## TLC stopped", `TLC stopped with exit ${stop.status}:`]),
|
|
169
|
+
fenced(stop.message),
|
|
170
|
+
);
|
|
171
|
+
for (const p of properties)
|
|
172
|
+
if (p.outcome === "holds" && p.initialOnly)
|
|
173
|
+
out.push(
|
|
174
|
+
`TLC checked ${p.rule.name} only in the initial states, because it has no [], <>, or ~>. List it as an INVARIANT to check every state.`,
|
|
175
|
+
);
|
|
176
|
+
return out.join("\n");
|
|
177
|
+
}
|