@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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  3. package/agents/comment-sicko.md +35 -0
  4. package/agents/poteto-agent.md +12 -0
  5. package/harness/pi.md +87 -0
  6. package/package.json +37 -4
  7. package/skills/architect/SKILL.md +14 -0
  8. package/skills/arena/SKILL.md +51 -0
  9. package/skills/automate-me/SKILL.md +107 -0
  10. package/skills/benchmark-checklist/SKILL.md +42 -0
  11. package/skills/blast-radius/SKILL.md +53 -0
  12. package/skills/bro/SKILL.md +10 -0
  13. package/skills/correct/SKILL.md +35 -0
  14. package/skills/create-formal-verification-skill/SKILL.md +46 -0
  15. package/skills/create-verification-skill/SKILL.md +47 -0
  16. package/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
  17. package/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
  18. package/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
  19. package/skills/figure-it-out/SKILL.md +55 -0
  20. package/skills/how/SKILL.md +24 -0
  21. package/skills/in-your-own-words/SKILL.md +10 -0
  22. package/skills/interrogate/SKILL.md +34 -0
  23. package/skills/ketchup/SKILL.md +46 -0
  24. package/skills/ketchup-video/SKILL.md +32 -0
  25. package/skills/maintain-formal-verification-skill/SKILL.md +61 -0
  26. package/skills/maintain-verification-skill/SKILL.md +42 -0
  27. package/skills/make-bot-ui/SKILL.md +118 -0
  28. package/skills/no-comments/SKILL.md +27 -0
  29. package/skills/poteto-help/SKILL.md +165 -0
  30. package/skills/poteto-help/references/prompting.md +51 -0
  31. package/skills/poteto-help/references/recipes.md +51 -0
  32. package/skills/poteto-mode/SKILL.md +111 -0
  33. package/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
  34. package/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
  35. package/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
  36. package/skills/poteto-mode/playbooks/autopilot-stack.md +8 -0
  37. package/skills/poteto-mode/playbooks/babysit.md +10 -0
  38. package/skills/poteto-mode/playbooks/bug-fix.md +15 -0
  39. package/skills/poteto-mode/playbooks/eval.md +25 -0
  40. package/skills/poteto-mode/playbooks/feature.md +21 -0
  41. package/skills/poteto-mode/playbooks/hillclimb.md +21 -0
  42. package/skills/poteto-mode/playbooks/investigation.md +14 -0
  43. package/skills/poteto-mode/playbooks/multi-phase-plan.md +11 -0
  44. package/skills/poteto-mode/playbooks/opening-a-pr.md +9 -0
  45. package/skills/poteto-mode/playbooks/pause-safely.md +10 -0
  46. package/skills/poteto-mode/playbooks/perf-issue.md +25 -0
  47. package/skills/poteto-mode/playbooks/prototype.md +14 -0
  48. package/skills/poteto-mode/playbooks/refactoring.md +16 -0
  49. package/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
  50. package/skills/poteto-mode/playbooks/session-pickup.md +11 -0
  51. package/skills/poteto-mode/playbooks/shipping.md +12 -0
  52. package/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
  53. package/skills/poteto-mode/playbooks/visual-parity.md +11 -0
  54. package/skills/poteto-mode/playbooks/worktree-cleanup.md +12 -0
  55. package/skills/poteto-mode/references/bugbot-triage.md +142 -0
  56. package/skills/poteto-mode/scripts/bootstrap.ts +62 -0
  57. package/skills/poteto-mode/scripts/bun.lock +67 -0
  58. package/skills/poteto-mode/scripts/package.json +16 -0
  59. package/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
  60. package/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
  61. package/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +129 -0
  62. package/skills/poteto-mode/scripts/watch-pr/github.test.ts +498 -0
  63. package/skills/poteto-mode/scripts/watch-pr/github.ts +726 -0
  64. package/skills/poteto-mode/scripts/watch-pr/policy.test.ts +482 -0
  65. package/skills/poteto-mode/scripts/watch-pr/policy.ts +842 -0
  66. package/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
  67. package/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
  68. package/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
  69. package/skills/poteto-mode/scripts/watch-pr/types.ts +414 -0
  70. package/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
  71. package/skills/poteto-mode/scripts/worktree-audit.sh +134 -0
  72. package/skills/poteto-mode/worker.md +11 -0
  73. package/skills/principle-attack-the-premise/SKILL.md +18 -0
  74. package/skills/principle-boundary-discipline/SKILL.md +14 -0
  75. package/skills/principle-build-the-lever/SKILL.md +17 -0
  76. package/skills/principle-encode-lessons-in-structure/SKILL.md +14 -0
  77. package/skills/principle-exhaust-the-design-space/SKILL.md +12 -0
  78. package/skills/principle-experience-first/SKILL.md +22 -0
  79. package/skills/principle-explain-the-number/SKILL.md +17 -0
  80. package/skills/principle-fix-root-causes/SKILL.md +17 -0
  81. package/skills/principle-foundational-thinking/SKILL.md +16 -0
  82. package/skills/principle-guard-the-context-window/SKILL.md +15 -0
  83. package/skills/principle-laziness-protocol/SKILL.md +13 -0
  84. package/skills/principle-make-operations-idempotent/SKILL.md +18 -0
  85. package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +17 -0
  86. package/skills/principle-minimize-reader-load/SKILL.md +18 -0
  87. package/skills/principle-model-the-domain/SKILL.md +18 -0
  88. package/skills/principle-never-block-on-the-human/SKILL.md +18 -0
  89. package/skills/principle-outcome-oriented-execution/SKILL.md +24 -0
  90. package/skills/principle-prove-it-works/SKILL.md +14 -0
  91. package/skills/principle-redesign-from-first-principles/SKILL.md +19 -0
  92. package/skills/principle-separate-before-serializing-shared-state/SKILL.md +14 -0
  93. package/skills/principle-sequence-verifiable-units/SKILL.md +16 -0
  94. package/skills/principle-subtract-before-you-add/SKILL.md +21 -0
  95. package/skills/principle-test-behavior-not-implementation/SKILL.md +19 -0
  96. package/skills/principle-type-system-discipline/SKILL.md +18 -0
  97. package/skills/recall/SKILL.md +38 -0
  98. package/skills/reflect/SKILL.md +20 -0
  99. package/skills/setup-pstack/SKILL.md +81 -0
  100. package/skills/sharpen/SKILL.md +19 -0
  101. package/skills/show-me-your-work/SKILL.md +85 -0
  102. package/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  103. package/skills/show-me-your-work/scripts/log.sh +42 -0
  104. package/skills/statechart/SKILL.md +85 -0
  105. package/skills/statechart/references/render.md +93 -0
  106. package/skills/statechart/scripts/backends/cfg.ts +33 -0
  107. package/skills/statechart/scripts/backends/mermaid.ts +249 -0
  108. package/skills/statechart/scripts/backends/plain-text.ts +72 -0
  109. package/skills/statechart/scripts/backends/report.ts +177 -0
  110. package/skills/statechart/scripts/frontends/config.ts +276 -0
  111. package/skills/statechart/scripts/frontends/dot.ts +74 -0
  112. package/skills/statechart/scripts/frontends/marks.ts +93 -0
  113. package/skills/statechart/scripts/frontends/messages.ts +52 -0
  114. package/skills/statechart/scripts/frontends/spec.ts +114 -0
  115. package/skills/statechart/scripts/frontends/trace.ts +24 -0
  116. package/skills/statechart/scripts/frontends/value.ts +166 -0
  117. package/skills/statechart/scripts/frontends/verdict.ts +40 -0
  118. package/skills/statechart/scripts/frontends/view.ts +119 -0
  119. package/skills/statechart/scripts/ir.ts +547 -0
  120. package/skills/statechart/scripts/package.json +11 -0
  121. package/skills/statechart/scripts/passes/annotate.ts +128 -0
  122. package/skills/statechart/scripts/passes/label.ts +269 -0
  123. package/skills/statechart/scripts/passes/lift.ts +85 -0
  124. package/skills/statechart/scripts/passes/loop-check.ts +68 -0
  125. package/skills/statechart/scripts/passes/paths.ts +60 -0
  126. package/skills/statechart/scripts/passes/reach.ts +135 -0
  127. package/skills/statechart/scripts/passes/region-check.ts +97 -0
  128. package/skills/statechart/scripts/passes/regions.ts +295 -0
  129. package/skills/statechart/scripts/pipeline.ts +76 -0
  130. package/skills/statechart/scripts/run.ts +506 -0
  131. package/skills/statechart/scripts/statechart +29 -0
  132. package/skills/statechart/scripts/statechart.ts +164 -0
  133. package/skills/statechart/scripts/tsconfig.json +11 -0
  134. package/skills/statechart/scripts/worker.ts +35 -0
  135. package/skills/swarm/SKILL.md +44 -0
  136. package/skills/tdd/SKILL.md +45 -0
  137. package/skills/teach/SKILL.md +24 -0
  138. package/skills/technical-writing/SKILL.md +73 -0
  139. package/skills/typescript-best-practices/SKILL.md +33 -0
  140. package/skills/typescript-best-practices/references/patterns.md +328 -0
  141. package/skills/unslop/SKILL.md +43 -0
  142. package/skills/why/SKILL.md +12 -0
@@ -0,0 +1,97 @@
1
+ import {
2
+ append,
3
+ type Arrow,
4
+ holds,
5
+ type Labels,
6
+ type Region,
7
+ tupleKey,
8
+ unkey,
9
+ type Walk,
10
+ } from "../ir.ts";
11
+
12
+ type Move = { from: string[]; text: string; to: string[] };
13
+ type Enabled = { i: number; a: Arrow };
14
+
15
+ export function regionsLie(
16
+ regions: Region[],
17
+ { names, keys, sorted, drawnLabels, together }: Labels,
18
+ { from, to, starts }: Walk,
19
+ order: Int32Array,
20
+ ) {
21
+ if (names.length < 2) return undefined;
22
+ const combo = (i: number) => {
23
+ const c: string[] = [];
24
+ for (let r = 0; r < names.length; r++) c.push(keys[r][i]);
25
+ return c;
26
+ };
27
+ const words = (c: string[]) => {
28
+ const parts: string[] = [];
29
+ for (let i = 0; i < names.length; i++) parts.push(`${names[i]} ${unkey(c[i]).join(" / ")}`);
30
+ return parts.join(", ");
31
+ };
32
+ const addMove = (moves: Map<string, Move>, m: Move) =>
33
+ moves.set(tupleKey([m.from, m.text, m.to]), m);
34
+ let product: string[][] = [[]];
35
+ for (const r of regions) {
36
+ const next: string[][] = [];
37
+ for (const c of product)
38
+ for (const s of r.states) if (s.start) next.push([...c, tupleKey(s.path)]);
39
+ product = next;
40
+ }
41
+ const realStarts = new Set<string>();
42
+ for (const i of starts) realStarts.add(tupleKey(combo(i)));
43
+ for (const c of product)
44
+ if (!realStarts.has(tupleKey(c)))
45
+ return `The regions chart starts at ${words(c)}, where the model never starts.`;
46
+ for (const [i, r] of regions.entries())
47
+ for (const a of r.arrows)
48
+ if (a.condition.kind === "tuples")
49
+ return `In ${names[i]}, ${a.label} from ${unkey(a.from).join(" / ")} depends on the other regions in a way that one "and" or "or" condition cannot say.`;
50
+ const real = new Map<string, Move>();
51
+ for (const j of sorted) {
52
+ const before = combo(from[j]);
53
+ const after = combo(to[j]);
54
+ if (tupleKey(before) !== tupleKey(after))
55
+ addMove(real, { from: before, text: drawnLabels[j], to: after });
56
+ }
57
+ const combos = new Map<string, string[]>();
58
+ for (const i of order) {
59
+ const c = combo(i);
60
+ combos.set(tupleKey(c), c);
61
+ }
62
+ const drawn = new Map<string, Move>();
63
+ for (const c of combos.values()) {
64
+ const enabled = new Map<string, Enabled[]>();
65
+ for (const [i, r] of regions.entries()) {
66
+ const rest: string[] = [];
67
+ for (let k = 0; k < c.length; k++) if (k !== i) rest.push(c[k]);
68
+ for (const a of r.arrows)
69
+ if (a.from === c[i] && holds(a.condition, rest)) append(enabled, a.label, { i, a });
70
+ }
71
+ for (const [text, list] of enabled) {
72
+ let groups: Enabled[][] = [];
73
+ if (together.has(text)) {
74
+ const byRegion = new Map<number, Enabled[]>();
75
+ for (const m of list) append(byRegion, m.i, m);
76
+ groups = [[]];
77
+ for (const opts of byRegion.values()) {
78
+ const next: Enabled[][] = [];
79
+ for (const g of groups) for (const m of opts) next.push([...g, m]);
80
+ groups = next;
81
+ }
82
+ } else for (const m of list) groups.push([m]);
83
+ for (const group of groups) {
84
+ const to = [...c];
85
+ for (const { i, a } of group) to[i] = a.to;
86
+ addMove(drawn, { from: c, text, to });
87
+ }
88
+ }
89
+ }
90
+ for (const [k, extra] of drawn)
91
+ if (!real.has(k))
92
+ return `The regions chart lets ${words(extra.from)} go to ${words(extra.to)} by ${extra.text}, which the model never does.`;
93
+ for (const [k, missing] of real)
94
+ if (!drawn.has(k))
95
+ return `The model goes from ${words(missing.from)} to ${words(missing.to)} by ${missing.text}, which the regions chart cannot show.`;
96
+ return undefined;
97
+ }
@@ -0,0 +1,295 @@
1
+ import {
2
+ append,
3
+ type Arrow,
4
+ type Bug,
5
+ byText,
6
+ type Chart,
7
+ type ChartState,
8
+ type ChartStep,
9
+ type Condition,
10
+ hasRule,
11
+ holds,
12
+ type Labels,
13
+ loopOf,
14
+ must,
15
+ type Region,
16
+ type Rule,
17
+ ruleKey,
18
+ seqOf,
19
+ tupleKey,
20
+ unkey,
21
+ type View,
22
+ type Walk,
23
+ } from "../ir.ts";
24
+
25
+ const anyRest: Condition = { kind: "and", otherKeys: [] };
26
+
27
+ type RegionMove = {
28
+ f: number;
29
+ t: number;
30
+ text: string;
31
+ group: number[];
32
+ other: RegionMove | undefined;
33
+ };
34
+
35
+ export function drawRegions(
36
+ { states: tla, index, from, to }: Walk,
37
+ { names, shapes, drawnLabels, group, keys, kinds, sizes, sorted, pathSteps, notes }: Labels,
38
+ order: Int32Array,
39
+ found: Bug[],
40
+ view: View,
41
+ ): Chart {
42
+ const n = shapes.length;
43
+ const m = drawnLabels.length;
44
+ const R = names.length;
45
+ const lead = new Uint8Array(n);
46
+ const looped = new Uint8Array(n);
47
+ for (const b of found) {
48
+ for (const i of seqOf(b, index).slice(0, b.loop)) lead[i] = 1;
49
+ for (const i of loopOf(b, index)) looped[i] = 1;
50
+ }
51
+ const loop = (j: number) => R === 1 && pathSteps[j] === 1;
52
+ const stays = (j: number) => {
53
+ for (let r = 0; r < R; r++) if (kinds[r][from[j]] !== kinds[r][to[j]]) return false;
54
+ return true;
55
+ };
56
+ let inside = 0;
57
+ for (const j of sorted) if (stays(j) && !loop(j)) inside++;
58
+ const comboOf =
59
+ R === 1
60
+ ? (i: number) => kinds[0][i]
61
+ : (i: number) => {
62
+ let c = "";
63
+ for (let r = 0; r < R; r++) c += (r ? "," : "") + kinds[r][i];
64
+ return c;
65
+ };
66
+ const dirty = new Map<number | string, number>();
67
+ for (const i of order)
68
+ if (tla[i].breaks.length) {
69
+ const c = comboOf(i);
70
+ if (!dirty.has(c)) dirty.set(c, i);
71
+ }
72
+ const clean = new Uint8Array(n);
73
+ if (dirty.size) for (let i = 0; i < n; i++) clean[i] = dirty.has(comboOf(i)) ? 0 : 1;
74
+ else clean.fill(1);
75
+ const regions: Region[] = [];
76
+ const objects: ChartState[][] = [];
77
+ for (const [r, name] of names.entries()) {
78
+ const key = keys[r];
79
+ const kind = kinds[r];
80
+ const states = new Map<string, ChartState>();
81
+ const objectOf = new Array<ChartState>(sizes[r]);
82
+ const keyOf = new Array<string>(sizes[r]);
83
+ const position = new Int32Array(sizes[r]);
84
+ for (const i of order) {
85
+ const s = tla[i];
86
+ let o = objectOf[kind[i]];
87
+ if (!o) {
88
+ o = {
89
+ path: shapes[i][name],
90
+ start: false,
91
+ members: [],
92
+ works: false,
93
+ lead: false,
94
+ repeats: false,
95
+ breaks: [],
96
+ group: undefined,
97
+ };
98
+ objectOf[kind[i]] = o;
99
+ keyOf[kind[i]] = key[i];
100
+ position[kind[i]] = states.size;
101
+ states.set(key[i], o);
102
+ }
103
+ o.start ||= s.start;
104
+ o.works ||= clean[i] === 1;
105
+ o.lead ||= lead[i] === 1;
106
+ o.repeats ||= looped[i] === 1;
107
+ o.members.push(i);
108
+ }
109
+ const parents = new Set<string>();
110
+ for (const s of states.values())
111
+ for (let i = 1; i < s.path.length; i++) parents.add(tupleKey(s.path.slice(0, i)));
112
+ for (const s of states.values()) {
113
+ if (parents.size && parents.has(tupleKey(s.path)))
114
+ throw new Error(
115
+ `The view's state() returned ${s.path.join(" / ")} both as a state and as a parent state${name ? ` in ${name}` : ""}. Give that state a child name of its own.`,
116
+ );
117
+ const rules = new Map<string, Rule>();
118
+ for (const i of s.members) for (const rule of tla[i].breaks) rules.set(ruleKey(rule), rule);
119
+ s.breaks = [];
120
+ for (const rule of [...rules.values()].sort(
121
+ (a, b) => byText(a.name, b.name) || byText(a.kind, b.kind),
122
+ )) {
123
+ let always = true;
124
+ for (const i of s.members) always &&= hasRule(tla[i].breaks, rule);
125
+ s.breaks.push({ rule, always });
126
+ }
127
+ const groups = new Set<unknown>();
128
+ for (const i of s.members) groups.add(group(i));
129
+ s.group = groups.size === 1 ? [...groups][0] : undefined;
130
+ }
131
+ const others: number[] = [];
132
+ for (let o = 0; o < R; o++) if (o !== r) others.push(o);
133
+ const tuple = (i: number) => {
134
+ const t: string[] = [];
135
+ for (const o of others) t.push(keys[o][i]);
136
+ return t;
137
+ };
138
+ const two = others.length === 1;
139
+ const words = (vs: Iterable<string>) => {
140
+ const texts: string[] = [];
141
+ for (const v of vs) texts.push(unkey(v).join(" / "));
142
+ return texts.sort(byText).join(two ? " or " : ", ");
143
+ };
144
+ const is = (o: number, vs: Set<string>) =>
145
+ two ? `when ${words(vs)}` : `${names[o]} is ${vs.size > 1 ? "one of " : ""}${words(vs)}`;
146
+ const isNot = (o: number, vs: string[]) =>
147
+ two
148
+ ? `unless ${words(vs)}`
149
+ : `${names[o]} is ${vs.length > 1 ? "none of" : "not"} ${words(vs)}`;
150
+ const moves: RegionMove[] = [];
151
+ const pairs = new Map<number, RegionMove>();
152
+ const size = sizes[r];
153
+ for (const j of sorted) {
154
+ const f = kind[from[j]];
155
+ const t = kind[to[j]];
156
+ if (f === t && !loop(j)) continue;
157
+ const text = drawnLabels[j];
158
+ const pair = position[f] * size + position[t];
159
+ let move = pairs.get(pair);
160
+ while (move && move.text !== text) move = move.other;
161
+ if (!move) {
162
+ move = { f, t, text, group: [], other: pairs.get(pair) };
163
+ pairs.set(pair, move);
164
+ moves.push(move);
165
+ }
166
+ if (R > 1) move.group.push(j);
167
+ }
168
+ const tuplesAt = new Map<number, number[]>();
169
+ const seenAt = new Map<number, string[][]>();
170
+ if (R > 1) for (const i of order) append(tuplesAt, kind[i], i);
171
+ const arrows: Arrow[] = [];
172
+ for (const move of moves) {
173
+ const fromKey = keyOf[move.f];
174
+ const toKey = keyOf[move.t];
175
+ if (R === 1) {
176
+ arrows.push({
177
+ from: fromKey,
178
+ to: toKey,
179
+ label: move.text,
180
+ condition: anyRest,
181
+ when: undefined,
182
+ });
183
+ continue;
184
+ }
185
+ const ok = new Set<string>();
186
+ for (const j of move.group) ok.add(tupleKey(tuple(from[j])));
187
+ const takes = (t: string[]) => ok.has(tupleKey(t));
188
+ let seen = seenAt.get(move.f);
189
+ if (!seen) {
190
+ seen = [];
191
+ const seenKeys = new Set<string>();
192
+ for (const i of must(tuplesAt, move.f)) {
193
+ const t = tuple(i);
194
+ const k = tupleKey(t);
195
+ if (seenKeys.has(k)) continue;
196
+ seenKeys.add(k);
197
+ seen.push(t);
198
+ }
199
+ seenAt.set(move.f, seen);
200
+ }
201
+ const all: Set<string>[] = [];
202
+ const and: Set<string>[] = [];
203
+ const or: Set<string>[] = [];
204
+ for (let j = 0; j < others.length; j++) {
205
+ const values = new Set<string>();
206
+ const taken = new Set<string>();
207
+ const untaken = new Set<string>();
208
+ for (const t of seen) {
209
+ values.add(t[j]);
210
+ if (takes(t)) taken.add(t[j]);
211
+ else untaken.add(t[j]);
212
+ }
213
+ const only = new Set<string>();
214
+ for (const v of values) if (!untaken.has(v)) only.add(v);
215
+ all.push(values);
216
+ and.push(taken);
217
+ or.push(only);
218
+ }
219
+ const fits = (condition: Condition) => {
220
+ for (const t of seen) if (holds(condition, t) !== takes(t)) return false;
221
+ return true;
222
+ };
223
+ const andHolds: Condition = { kind: "and", otherKeys: and };
224
+ const orHolds: Condition = { kind: "or", otherKeys: or };
225
+ const text = move.text;
226
+ if (fits(andHolds)) {
227
+ const parts: string[] = [];
228
+ for (let j = 0; j < others.length; j++) {
229
+ const no: string[] = [];
230
+ for (const v of all[j]) if (!and[j].has(v)) no.push(v);
231
+ if (no.length)
232
+ parts.push(and[j].size <= no.length ? is(others[j], and[j]) : isNot(others[j], no));
233
+ }
234
+ arrows.push({
235
+ from: fromKey,
236
+ to: toKey,
237
+ label: text,
238
+ condition: andHolds,
239
+ when: parts.length ? (two ? parts[0] : `when ${parts.join(" and ")}`) : undefined,
240
+ });
241
+ } else if (fits(orHolds)) {
242
+ const parts: string[] = [];
243
+ for (let j = 0; j < others.length; j++) if (or[j].size) parts.push(is(others[j], or[j]));
244
+ arrows.push({
245
+ from: fromKey,
246
+ to: toKey,
247
+ label: text,
248
+ condition: orHolds,
249
+ when: `when ${parts.join(" or ")}`,
250
+ });
251
+ } else
252
+ arrows.push({
253
+ from: fromKey,
254
+ to: toKey,
255
+ label: text,
256
+ condition: { kind: "tuples", otherTuples: ok },
257
+ });
258
+ }
259
+ const steps: ChartStep[] = [];
260
+ for (const [k, a] of arrows.entries())
261
+ steps.push({
262
+ from: objectOf[moves[k].f].path,
263
+ to: objectOf[moves[k].t].path,
264
+ label: a.label,
265
+ when: a.label.endsWith("]") ? undefined : a.when,
266
+ });
267
+ regions.push({ name, states: [...states.values()], steps, arrows });
268
+ objects.push(objectOf);
269
+ }
270
+ const hidden: ChartState[][] = [];
271
+ for (const i of dirty.values()) {
272
+ const ps: ChartState[] = [];
273
+ for (let r = 0; r < R; r++) ps.push(objects[r][kinds[r][i]]);
274
+ let works = true;
275
+ for (const s of ps) works &&= s.works;
276
+ if (works) hidden.push(ps);
277
+ }
278
+ for (const ps of hidden) for (const s of ps) s.works = false;
279
+ const paths: string[] = [];
280
+ const loops: string[] = [];
281
+ for (const b of found) {
282
+ if (b.loop !== 0) paths.push(b.rule.name);
283
+ if (b.loop !== undefined) loops.push(b.rule.name);
284
+ }
285
+ return {
286
+ title: view.title,
287
+ regions,
288
+ notes,
289
+ inside,
290
+ quiet: m - sorted.length,
291
+ colors: view.colors ?? {},
292
+ paths,
293
+ loops,
294
+ };
295
+ }
@@ -0,0 +1,76 @@
1
+ import { mermaidLines } from "./backends/mermaid.ts";
2
+ import { plainText } from "./backends/plain-text.ts";
3
+ import { report } from "./backends/report.ts";
4
+ import {
5
+ type Answers,
6
+ type Bug,
7
+ type Chart,
8
+ type CheckedView,
9
+ type CheckResult,
10
+ type Graph,
11
+ PART,
12
+ ruleKey,
13
+ type Story,
14
+ type View,
15
+ type Walk,
16
+ } from "./ir.ts";
17
+ import { asParents, ask, labelGraph, storiesOf } from "./passes/label.ts";
18
+ import { lift } from "./passes/lift.ts";
19
+ import { loopCheck } from "./passes/loop-check.ts";
20
+ import { bugs, drawOrder, walk } from "./passes/reach.ts";
21
+ import { regionsLie } from "./passes/region-check.ts";
22
+ import { drawRegions } from "./passes/regions.ts";
23
+
24
+ function* inParts(lines: string[]) {
25
+ let start = 0;
26
+ let size = 0;
27
+ for (let i = 0; i < lines.length; i++) {
28
+ size += lines[i].length + 1;
29
+ if (size > PART || i === lines.length - 1) {
30
+ yield (start ? "\n" : "") + lines.slice(start, i + 1).join("\n");
31
+ start = i + 1;
32
+ size = 0;
33
+ }
34
+ }
35
+ }
36
+
37
+ const shortestFirst = (a: { path: unknown[] }, b: { path: unknown[] }) =>
38
+ a.path.length - b.path.length;
39
+
40
+ export function project(graph: Graph, walked: Walk, view: View, found: Bug[]) {
41
+ const { order, rank } = drawOrder(walked);
42
+ const draw = (answers: Answers) => {
43
+ const labels = labelGraph(graph, walked, answers, rank, found);
44
+ return { labels, chart: drawRegions(walked, labels, order, found, view) };
45
+ };
46
+ const answers = ask(graph, walked, view);
47
+ const first = draw(answers);
48
+ const lie = regionsLie(first.chart.regions, first.labels, walked, order);
49
+ const { labels, chart } = lie ? draw(asParents(walked, answers)) : first;
50
+ loopCheck(chart, labels, walked, found);
51
+ return {
52
+ chart: lift(lie ? { ...chart, lie } : chart),
53
+ stories: storiesOf(graph, found, walked, first.labels),
54
+ };
55
+ }
56
+
57
+ export function compile(result: CheckResult, view: CheckedView) {
58
+ const walked = walk(result.graph);
59
+ const found = [...(result.paths ?? bugs(result.graph, walked))].sort(shortestFirst);
60
+ for (const p of result.properties) if (p.bug) found.push({ rule: p.rule, ...p.bug });
61
+ const { chart, stories } =
62
+ found.length || !result.paths
63
+ ? project(result.graph, walked, view, found)
64
+ : { chart: undefined, stories: new Map<Bug, Story>() };
65
+ const text = report(result, found, chart, stories);
66
+ const files = new Map<string, Iterable<string | Uint8Array>>();
67
+ if (chart) files.set("chart.mmd", inParts(mermaidLines(chart)));
68
+ files.set("report.md", [text]);
69
+ files.set("tlc.out", plainText(result.messages));
70
+ const drawn = new Set<string>();
71
+ for (const b of found) if (b.rule.kind !== "property") drawn.add(ruleKey(b.rule));
72
+ for (const { rule, outcome, messages } of [...result.rules, ...result.properties])
73
+ if (outcome === "broken" && messages && !drawn.has(ruleKey(rule)))
74
+ files.set(`tlc-${rule.name}.out`, plainText(messages));
75
+ return { report: text, files, exit: result.exit };
76
+ }