dsh-pstack 0.2.0-beta.1 → 0.2.0-beta.3

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 (261) hide show
  1. package/LICENSE +2 -3
  2. package/README.md +135 -84
  3. package/README.zh.md +185 -0
  4. package/cordis.patch.yml +97 -27
  5. package/dist/host-contract-CUPSpeNk.d.mts +22 -0
  6. package/dist/index.d.mts +49 -238
  7. package/dist/index.mjs +250 -123
  8. package/dist/models.d.mts +44 -0
  9. package/dist/models.mjs +201 -0
  10. package/dist/paths-BT77khwm.mjs +48 -0
  11. package/dist/pstack/LICENSE +21 -0
  12. package/dist/pstack/README.md +291 -0
  13. package/dist/pstack/agents/poteto-agent.md +9 -0
  14. package/{assets → dist/pstack}/docs/guide/01-setup.md +13 -11
  15. package/{assets → dist/pstack}/docs/guide/02-poteto-mode.md +4 -4
  16. package/{assets → dist/pstack}/docs/guide/04-design.md +4 -4
  17. package/{assets → dist/pstack}/docs/guide/05-build-and-clean.md +2 -2
  18. package/{assets → dist/pstack}/docs/guide/06-verify-and-ship.md +13 -3
  19. package/{assets → dist/pstack}/docs/guide/07-overnight.md +15 -13
  20. package/{assets → dist/pstack}/docs/guide/09-make-it-yours.md +6 -2
  21. package/{assets → dist/pstack}/docs/guide/10-recipes-and-pitfalls.md +7 -5
  22. package/{assets → dist/pstack}/docs/guide/README.md +1 -1
  23. package/dist/pstack/docs/harness/dsh.md +98 -0
  24. package/{assets → dist/pstack}/skills/architect/SKILL.md +12 -12
  25. package/dist/pstack/skills/arena/SKILL.md +50 -0
  26. package/{assets → dist/pstack}/skills/automate-me/SKILL.md +14 -14
  27. package/{assets → dist/pstack}/skills/benchmark-checklist/SKILL.md +1 -1
  28. package/{assets → dist/pstack}/skills/blast-radius/SKILL.md +4 -6
  29. package/{assets → dist/pstack}/skills/correct/SKILL.md +1 -1
  30. package/{assets → dist/pstack}/skills/create-formal-verification-skill/SKILL.md +4 -2
  31. package/{assets → dist/pstack}/skills/create-verification-skill/SKILL.md +5 -5
  32. package/dist/pstack/skills/figure-it-out/SKILL.md +54 -0
  33. package/dist/pstack/skills/how/SKILL.md +38 -0
  34. package/{assets → dist/pstack}/skills/in-your-own-words/SKILL.md +1 -1
  35. package/dist/pstack/skills/interrogate/SKILL.md +33 -0
  36. package/{assets → dist/pstack}/skills/ketchup/SKILL.md +3 -5
  37. package/dist/pstack/skills/ketchup-video/SKILL.md +29 -0
  38. package/{assets → dist/pstack}/skills/maintain-formal-verification-skill/SKILL.md +1 -1
  39. package/{assets → dist/pstack}/skills/maintain-verification-skill/SKILL.md +3 -3
  40. package/dist/pstack/skills/make-bot-ui/SKILL.md +117 -0
  41. package/dist/pstack/skills/no-comments/SKILL.md +26 -0
  42. package/{assets → dist/pstack}/skills/poteto-help/SKILL.md +34 -31
  43. package/{assets → dist/pstack}/skills/poteto-help/references/prompting.md +1 -1
  44. package/{assets → dist/pstack}/skills/poteto-help/references/recipes.md +3 -3
  45. package/{assets → dist/pstack}/skills/poteto-mode/SKILL.md +20 -19
  46. package/dist/pstack/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
  47. package/dist/pstack/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
  48. package/dist/pstack/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
  49. package/dist/pstack/skills/poteto-mode/playbooks/autopilot-stack.md +8 -0
  50. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/babysit.md +4 -4
  51. package/dist/pstack/skills/poteto-mode/playbooks/bug-fix.md +15 -0
  52. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/eval.md +3 -3
  53. package/dist/pstack/skills/poteto-mode/playbooks/feature.md +21 -0
  54. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/hillclimb.md +3 -3
  55. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/investigation.md +2 -2
  56. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/multi-phase-plan.md +23 -23
  57. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/opening-a-pr.md +6 -6
  58. package/dist/pstack/skills/poteto-mode/playbooks/orchestrate.md +25 -0
  59. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/pause-safely.md +2 -2
  60. package/dist/pstack/skills/poteto-mode/playbooks/perf-issue.md +25 -0
  61. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/prototype.md +4 -4
  62. package/dist/pstack/skills/poteto-mode/playbooks/refactoring.md +16 -0
  63. package/dist/pstack/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
  64. package/dist/pstack/skills/poteto-mode/playbooks/session-pickup.md +11 -0
  65. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/shipping.md +2 -2
  66. package/{assets → dist/pstack}/skills/poteto-mode/playbooks/trace-forensics.md +2 -2
  67. package/dist/pstack/skills/poteto-mode/playbooks/visual-parity.md +11 -0
  68. package/dist/pstack/skills/poteto-mode/playbooks/worktree-cleanup.md +12 -0
  69. package/{assets → dist/pstack}/skills/poteto-mode/scripts/check-plan.mjs +6 -8
  70. package/dist/pstack/skills/poteto-mode/scripts/check-plan.test.mjs +128 -0
  71. package/{assets/skills/poteto-mode/scripts/check-plan.test.mjs → dist/pstack/skills/poteto-mode/scripts/expect.mjs} +12 -101
  72. package/dist/pstack/skills/poteto-mode/scripts/support.mjs +93 -0
  73. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/cli.mjs +123 -0
  74. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/cli.test.mjs +217 -0
  75. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.mjs +119 -0
  76. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/github.mjs +626 -0
  77. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/github.test.mjs +521 -0
  78. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/policy.mjs +657 -0
  79. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/policy.test.mjs +523 -0
  80. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/render.mjs +106 -0
  81. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/types.mjs +9 -0
  82. package/dist/pstack/skills/poteto-mode/scripts/watch-pr/watch-pr.mjs +5 -0
  83. package/{assets → dist/pstack}/skills/poteto-mode/scripts/worktree-audit.mjs +15 -22
  84. package/dist/pstack/skills/poteto-mode/scripts/worktree-audit.test.mjs +134 -0
  85. package/{assets → dist/pstack}/skills/principle-attack-the-premise/SKILL.md +1 -1
  86. package/{assets → dist/pstack}/skills/principle-boundary-discipline/SKILL.md +1 -1
  87. package/{assets → dist/pstack}/skills/principle-encode-lessons-in-structure/SKILL.md +1 -1
  88. package/{assets → dist/pstack}/skills/principle-exhaust-the-design-space/SKILL.md +1 -1
  89. package/{assets → dist/pstack}/skills/principle-experience-first/SKILL.md +1 -1
  90. package/{assets → dist/pstack}/skills/principle-explain-the-number/SKILL.md +3 -2
  91. package/{assets → dist/pstack}/skills/principle-fix-root-causes/SKILL.md +1 -1
  92. package/{assets → dist/pstack}/skills/principle-laziness-protocol/SKILL.md +1 -1
  93. package/{assets → dist/pstack}/skills/principle-make-operations-idempotent/SKILL.md +1 -1
  94. package/{assets → dist/pstack}/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +1 -1
  95. package/{assets → dist/pstack}/skills/principle-minimize-reader-load/SKILL.md +1 -1
  96. package/{assets → dist/pstack}/skills/principle-model-the-domain/SKILL.md +1 -1
  97. package/{assets → dist/pstack}/skills/principle-never-block-on-the-human/SKILL.md +1 -1
  98. package/{assets → dist/pstack}/skills/principle-outcome-oriented-execution/SKILL.md +1 -1
  99. package/{assets → dist/pstack}/skills/principle-prove-it-works/SKILL.md +2 -2
  100. package/{assets → dist/pstack}/skills/principle-redesign-from-first-principles/SKILL.md +1 -1
  101. package/{assets → dist/pstack}/skills/principle-separate-before-serializing-shared-state/SKILL.md +1 -1
  102. package/{assets → dist/pstack}/skills/principle-sequence-verifiable-units/SKILL.md +1 -1
  103. package/{assets → dist/pstack}/skills/principle-subtract-before-you-add/SKILL.md +1 -1
  104. package/{assets → dist/pstack}/skills/principle-test-behavior-not-implementation/SKILL.md +1 -1
  105. package/{assets → dist/pstack}/skills/principle-type-system-discipline/SKILL.md +1 -1
  106. package/dist/pstack/skills/recall/SKILL.md +37 -0
  107. package/dist/pstack/skills/reflect/SKILL.md +71 -0
  108. package/{assets → dist/pstack}/skills/reflect/references/divergent-reviewer.md +4 -4
  109. package/{assets → dist/pstack}/skills/reflect/references/judgment-reviewer.md +2 -2
  110. package/{assets → dist/pstack}/skills/reflect/references/synthesizer.md +5 -5
  111. package/{assets → dist/pstack}/skills/reflect/references/tooling-reviewer.md +2 -2
  112. package/dist/pstack/skills/setup-pstack/SKILL.md +80 -0
  113. package/{assets → dist/pstack}/skills/sharpen/SKILL.md +1 -1
  114. package/{assets → dist/pstack}/skills/show-me-your-work/SKILL.md +8 -8
  115. package/{assets → dist/pstack}/skills/show-me-your-work/scripts/log.mjs +1 -3
  116. package/dist/pstack/skills/show-me-your-work/scripts/log.test.mjs +56 -0
  117. package/dist/pstack/skills/statechart/SKILL.md +82 -0
  118. package/dist/pstack/skills/statechart/references/render.md +93 -0
  119. package/dist/pstack/skills/statechart/scripts/backends/cfg.mjs +31 -0
  120. package/dist/pstack/skills/statechart/scripts/backends/mermaid.mjs +186 -0
  121. package/dist/pstack/skills/statechart/scripts/backends/plain-text.mjs +62 -0
  122. package/dist/pstack/skills/statechart/scripts/backends/report.mjs +84 -0
  123. package/dist/pstack/skills/statechart/scripts/frontends/config.mjs +268 -0
  124. package/dist/pstack/skills/statechart/scripts/frontends/dot.mjs +67 -0
  125. package/dist/pstack/skills/statechart/scripts/frontends/marks.mjs +94 -0
  126. package/dist/pstack/skills/statechart/scripts/frontends/messages.mjs +48 -0
  127. package/dist/pstack/skills/statechart/scripts/frontends/spec.mjs +101 -0
  128. package/dist/pstack/skills/statechart/scripts/frontends/trace.mjs +39 -0
  129. package/dist/pstack/skills/statechart/scripts/frontends/value.mjs +180 -0
  130. package/dist/pstack/skills/statechart/scripts/frontends/verdict.mjs +40 -0
  131. package/dist/pstack/skills/statechart/scripts/frontends/view.mjs +99 -0
  132. package/dist/pstack/skills/statechart/scripts/ir.mjs +277 -0
  133. package/dist/pstack/skills/statechart/scripts/passes/annotate.mjs +92 -0
  134. package/dist/pstack/skills/statechart/scripts/passes/label.mjs +210 -0
  135. package/dist/pstack/skills/statechart/scripts/passes/lift.mjs +84 -0
  136. package/dist/pstack/skills/statechart/scripts/passes/loop-check.mjs +47 -0
  137. package/dist/pstack/skills/statechart/scripts/passes/paths.mjs +72 -0
  138. package/dist/pstack/skills/statechart/scripts/passes/reach.mjs +135 -0
  139. package/dist/pstack/skills/statechart/scripts/passes/region-check.mjs +82 -0
  140. package/dist/pstack/skills/statechart/scripts/passes/regions.mjs +268 -0
  141. package/dist/pstack/skills/statechart/scripts/pipeline.mjs +72 -0
  142. package/dist/pstack/skills/statechart/scripts/run.mjs +440 -0
  143. package/dist/pstack/skills/statechart/scripts/statechart.mjs +155 -0
  144. package/dist/pstack/skills/statechart/scripts/statechart.test.mjs +198 -0
  145. package/dist/pstack/skills/statechart/scripts/worker.mjs +31 -0
  146. package/dist/pstack/skills/swarm/SKILL.md +43 -0
  147. package/{assets → dist/pstack}/skills/tdd/SKILL.md +1 -1
  148. package/{assets → dist/pstack}/skills/teach/SKILL.md +2 -2
  149. package/{assets → dist/pstack}/skills/technical-writing/SKILL.md +1 -1
  150. package/{assets → dist/pstack}/skills/typescript-best-practices/SKILL.md +3 -6
  151. package/{assets → dist/pstack}/skills/why/SKILL.md +8 -8
  152. package/dist/script.d.mts +9 -111
  153. package/dist/script.mjs +32 -329
  154. package/dist/skill.d.mts +38 -0
  155. package/dist/skill.mjs +183 -0
  156. package/dist/skills/authored/decision-audit/SKILL.md +99 -0
  157. package/dist/skills/authored/decision-audit/SKILL.zh.md +99 -0
  158. package/dist/skills/authored/decision-audit/references/recover-commit.md +17 -0
  159. package/dist/skills/authored/decision-audit/references/recover-commit.zh.md +17 -0
  160. package/dist/skills/authored/decision-write/SKILL.md +131 -0
  161. package/dist/skills/authored/decision-write/SKILL.zh.md +131 -0
  162. package/dist/skills/authored/decision-write/references/land.md +48 -0
  163. package/dist/skills/authored/decision-write/references/land.zh.md +48 -0
  164. package/dist/skills/authored/setup-project-docs/SKILL.md +58 -0
  165. package/dist/skills/authored/setup-project-docs/SKILL.zh.md +58 -0
  166. package/dist/skills/authored/setup-project-docs/references/decision-conventions.md +11 -0
  167. package/dist/skills/authored/setup-project-docs/references/decision-conventions.zh.md +11 -0
  168. package/dist/skills/vendored/retro/SKILL.md +44 -0
  169. package/dist/skills/vendored/retro/agents/openai.yaml +5 -0
  170. package/dist/skills/vendored/writing-for-agents/SKILL-MECHANICS.md +22 -0
  171. package/dist/skills/vendored/writing-for-agents/SKILL.md +81 -0
  172. package/dist/skills/vendored/writing-for-agents/agents/openai.yaml +3 -0
  173. package/dist/subagent.d.mts +56 -193
  174. package/dist/subagent.mjs +443 -741
  175. package/locale/en.json +3 -2
  176. package/locale/zh.json +3 -2
  177. package/package.json +63 -66
  178. package/assets/agents/poteto-agent.md +0 -8
  179. package/assets/docs/harness/dsh.md +0 -60
  180. package/assets/docs/pstack-models.example.md +0 -54
  181. package/assets/skills/arena/SKILL.md +0 -50
  182. package/assets/skills/figure-it-out/SKILL.md +0 -54
  183. package/assets/skills/how/SKILL.md +0 -38
  184. package/assets/skills/interrogate/SKILL.md +0 -71
  185. package/assets/skills/interrogate/references/code-quality-review.md +0 -47
  186. package/assets/skills/interrogate/references/lead-judgment.md +0 -39
  187. package/assets/skills/interrogate/references/reviewer-prompt.md +0 -62
  188. package/assets/skills/interrogate/references/rubric.md +0 -77
  189. package/assets/skills/no-comments/SKILL.md +0 -26
  190. package/assets/skills/poteto-mode/playbooks/authoring-a-skill.md +0 -12
  191. package/assets/skills/poteto-mode/playbooks/autonomous-run.md +0 -15
  192. package/assets/skills/poteto-mode/playbooks/autopilot-full.md +0 -25
  193. package/assets/skills/poteto-mode/playbooks/autopilot-stack.md +0 -12
  194. package/assets/skills/poteto-mode/playbooks/bug-fix.md +0 -15
  195. package/assets/skills/poteto-mode/playbooks/feature.md +0 -21
  196. package/assets/skills/poteto-mode/playbooks/orchestrate.md +0 -112
  197. package/assets/skills/poteto-mode/playbooks/perf-issue.md +0 -25
  198. package/assets/skills/poteto-mode/playbooks/refactoring.md +0 -16
  199. package/assets/skills/poteto-mode/playbooks/runtime-forensics.md +0 -11
  200. package/assets/skills/poteto-mode/playbooks/session-pickup.md +0 -11
  201. package/assets/skills/poteto-mode/playbooks/visual-parity.md +0 -11
  202. package/assets/skills/poteto-mode/playbooks/worktree-cleanup.md +0 -20
  203. package/assets/skills/poteto-mode/scripts/orch/orch.mjs +0 -4282
  204. package/assets/skills/poteto-mode/scripts/orch/orch.test.mjs +0 -2042
  205. package/assets/skills/poteto-mode/scripts/watch-pr/cli.test.mjs +0 -5101
  206. package/assets/skills/poteto-mode/scripts/watch-pr/github.test.mjs +0 -1177
  207. package/assets/skills/poteto-mode/scripts/watch-pr/policy.test.mjs +0 -1441
  208. package/assets/skills/poteto-mode/scripts/watch-pr/watch-pr.mjs +0 -4601
  209. package/assets/skills/recall/SKILL.md +0 -37
  210. package/assets/skills/reflect/SKILL.md +0 -69
  211. package/assets/skills/setup-pstack/SKILL.md +0 -67
  212. package/assets/skills/swarm/SKILL.md +0 -43
  213. package/dist/frontmatter-BQX3ekwP.mjs +0 -229
  214. package/dist/frontmatter-BQX3ekwP.mjs.map +0 -1
  215. package/dist/history.d.mts +0 -429
  216. package/dist/history.mjs +0 -1129
  217. package/dist/history.mjs.map +0 -1
  218. package/dist/host-contract-o47JH_r8.d.mts +0 -527
  219. package/dist/index.mjs.map +0 -1
  220. package/dist/paths-D_JlVmBk.mjs +0 -42
  221. package/dist/paths-D_JlVmBk.mjs.map +0 -1
  222. package/dist/script.mjs.map +0 -1
  223. package/dist/subagent.mjs.map +0 -1
  224. /package/{static/icon.png → assets/logo.png} +0 -0
  225. /package/{assets → dist/pstack}/agents/comment-sicko.md +0 -0
  226. /package/{assets → dist/pstack}/docs/guide/03-understand.md +0 -0
  227. /package/{assets → dist/pstack}/docs/guide/08-principles.md +0 -0
  228. /package/{assets → dist/pstack}/docs/guide/images/design.jpg +0 -0
  229. /package/{assets → dist/pstack}/docs/guide/images/overnight.jpg +0 -0
  230. /package/{assets → dist/pstack}/docs/guide/images/recipes.jpg +0 -0
  231. /package/{assets → dist/pstack}/docs/guide/images/router.jpg +0 -0
  232. /package/{assets → dist/pstack}/docs/guide/images/understanding.jpg +0 -0
  233. /package/{assets → dist/pstack}/docs/guide/images/verification.jpg +0 -0
  234. /package/{assets → dist/pstack}/skills/architect/references/design-red-flags.md +0 -0
  235. /package/{assets → dist/pstack}/skills/architect/references/rationale-template.md +0 -0
  236. /package/{assets → dist/pstack}/skills/architect/references/runner-prompt.md +0 -0
  237. /package/{assets → dist/pstack}/skills/bro/SKILL.md +0 -0
  238. /package/{assets → dist/pstack}/skills/create-verification-skill/references/feature-map-example/README.md +0 -0
  239. /package/{assets → dist/pstack}/skills/create-verification-skill/references/feature-map-example/create-note.md +0 -0
  240. /package/{assets → dist/pstack}/skills/create-verification-skill/references/feature-map-example/search.md +0 -0
  241. /package/{assets → dist/pstack}/skills/how/references/explainer-prompt.md +0 -0
  242. /package/{assets → dist/pstack}/skills/how/references/explorer-prompt.md +0 -0
  243. /package/{assets → dist/pstack}/skills/poteto-mode/references/bugbot-triage.md +0 -0
  244. /package/{assets → dist/pstack}/skills/principle-build-the-lever/SKILL.md +0 -0
  245. /package/{assets → dist/pstack}/skills/principle-foundational-thinking/SKILL.md +0 -0
  246. /package/{assets → dist/pstack}/skills/principle-guard-the-context-window/SKILL.md +0 -0
  247. /package/{assets → dist/pstack}/skills/show-me-your-work/references/decision-log-template.tsv +0 -0
  248. /package/{assets → dist/pstack}/skills/typescript-best-practices/references/patterns.md +0 -0
  249. /package/{assets → dist/pstack}/skills/unslop/SKILL.md +0 -0
  250. /package/{assets → dist/pstack}/skills/why/references/epistemics.md +0 -0
  251. /package/{assets → dist/pstack}/skills/why/references/investigator-prompt.md +0 -0
  252. /package/{assets → dist/pstack}/skills/why/references/source-playbook.md +0 -0
  253. /package/{assets → dist/pstack}/skills/why/references/sources/code-archaeology.md +0 -0
  254. /package/{assets → dist/pstack}/skills/why/references/sources/databricks.md +0 -0
  255. /package/{assets → dist/pstack}/skills/why/references/sources/datadog.md +0 -0
  256. /package/{assets → dist/pstack}/skills/why/references/sources/incident-postmortem.md +0 -0
  257. /package/{assets → dist/pstack}/skills/why/references/sources/linear.md +0 -0
  258. /package/{assets → dist/pstack}/skills/why/references/sources/notion.md +0 -0
  259. /package/{assets → dist/pstack}/skills/why/references/sources/sentry.md +0 -0
  260. /package/{assets → dist/pstack}/skills/why/references/sources/slack.md +0 -0
  261. /package/{assets → dist/pstack}/skills/why/references/synthesizer-prompt.md +0 -0
@@ -0,0 +1,277 @@
1
+ // runtime/skills/statechart/scripts/ir.ts
2
+ const EC = {
3
+ TLC_INVARIANT_VIOLATED_INITIAL: 2107,
4
+ TLC_PROPERTY_VIOLATED_INITIAL: 2108,
5
+ TLC_INVARIANT_VIOLATED_BEHAVIOR: 2110,
6
+ TLC_ACTION_PROPERTY_VIOLATED_BEHAVIOR: 2112,
7
+ TLC_DEADLOCK_REACHED: 2114,
8
+ TLC_TEMPORAL_PROPERTY_VIOLATED: 2116,
9
+ TLC_BACK_TO_STATE: 2122,
10
+ TLC_FINISHED: 2186,
11
+ TLC_INIT_GENERATED1: 2190,
12
+ TLC_INIT_GENERATED2: 2191,
13
+ TLC_STATS: 2199,
14
+ TLC_PROGRESS_STATS: 2200,
15
+ TLC_STATE_PRINT2: 2217,
16
+ TLC_STATE_PRINT3: 2218,
17
+ TLC_SANY_END: 2219,
18
+ TLC_SANY_START: 2220
19
+ };
20
+ const LEVEL = {
21
+ NONE: 0,
22
+ ERROR: 1,
23
+ TLCBUG: 2,
24
+ WARNING: 3,
25
+ STATE: 4
26
+ };
27
+ const RERUN_STATES = 1e5;
28
+ const CHART_STATES = 500;
29
+ const checked = Symbol("checked");
30
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
31
+ const isStrings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
32
+ const PART = 1 << 24;
33
+ const byText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
34
+ const list = (items, and = "and") => items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} ${and} ${items.at(-1)}`;
35
+ const ESCAPES = {
36
+ "\"": "\\\"",
37
+ "\\": "\\\\",
38
+ "\n": "\\n",
39
+ " ": "\\t",
40
+ "\r": "\\r",
41
+ "\f": "\\f"
42
+ };
43
+ const quote = (s) => `"${s.replace(/["\\\n\t\r\f]/g, (c) => ESCAPES[c])}"`;
44
+ const joined = (items, sep) => {
45
+ let s = "";
46
+ for (let i = 0; i < items.length; i++) s += (i ? sep : "") + show(items[i]);
47
+ return s;
48
+ };
49
+ const show = (v) => {
50
+ switch (typeof v) {
51
+ case "boolean": return v ? "TRUE" : "FALSE";
52
+ case "number": return String(v);
53
+ case "string": return quote(v);
54
+ }
55
+ switch (v.kind) {
56
+ case "model": return v.name;
57
+ case "interval": return `${v.lo}..${v.hi}`;
58
+ case "set": return `{${joined(v.members, ", ")}}`;
59
+ case "function": {
60
+ if (v.printedAs === "tuple") return `<<${joined(v.values, ", ")}>>`;
61
+ const record = v.printedAs === "record";
62
+ let s = record ? "[" : "(";
63
+ for (let i = 0; i < v.keys.length; i++) s += record ? `${i ? ", " : ""}${String(v.keys[i])} |-> ${show(v.values[i])}` : `${i ? " @@ " : ""}${show(v.keys[i])} :> ${show(v.values[i])}`;
64
+ return s + (record ? "]" : ")");
65
+ }
66
+ }
67
+ };
68
+ const must = (map, key) => {
69
+ const value = map.get(key);
70
+ if (value === void 0) throw new Error(`The chart lost track of ${JSON.stringify(key)}.`);
71
+ return value;
72
+ };
73
+ const append = (groups, key, item) => {
74
+ const group = groups.get(key);
75
+ if (group) group.push(item);
76
+ else groups.set(key, [item]);
77
+ };
78
+ const seqOf = (bug, index) => {
79
+ const seq = [must(index, bug.start)];
80
+ for (const p of bug.path) seq.push(must(index, p.state));
81
+ return seq;
82
+ };
83
+ const loopOf = (bug, index) => new Set(bug.loop === void 0 ? [] : seqOf(bug, index).slice(bug.loop));
84
+ const defaultState = (vars) => {
85
+ const entries = Object.entries(vars);
86
+ if (entries.length === 1) return show(entries[0][1]);
87
+ const parts = [];
88
+ for (const [k, v] of entries) parts.push(`${k}=${show(v)}`);
89
+ return parts.join(" ");
90
+ };
91
+ const stateText = (vars) => {
92
+ const parts = [];
93
+ for (const [k, v] of Object.entries(vars)) parts.push(`${k} = ${show(v)}`);
94
+ return parts.join(" /\\ ");
95
+ };
96
+ const count = (n) => {
97
+ const items = new Int32Array(n);
98
+ for (let i = 0; i < n; i++) items[i] = i;
99
+ return items;
100
+ };
101
+ const sortBy = (items, keys) => {
102
+ for (let k = keys.length - 1; k >= 0; k--) {
103
+ const key = keys[k];
104
+ let size = 0;
105
+ for (let p = 0; p < items.length; p++) if (key[items[p]] >= size) size = key[items[p]] + 1;
106
+ const start = new Int32Array(size + 1);
107
+ for (let p = 0; p < items.length; p++) start[key[items[p]] + 1]++;
108
+ for (let v = 0; v < size; v++) start[v + 1] += start[v];
109
+ const sorted = new Int32Array(items.length);
110
+ for (let p = 0; p < items.length; p++) sorted[start[key[items[p]]]++] = items[p];
111
+ items = sorted;
112
+ }
113
+ return items;
114
+ };
115
+ const tupleKey = (parts) => JSON.stringify(parts);
116
+ const unkey = (k) => {
117
+ const parts = JSON.parse(k);
118
+ if (!isStrings(parts)) throw new Error(`The chart cannot read the key ${k}.`);
119
+ return parts;
120
+ };
121
+ function holds(condition, others) {
122
+ switch (condition.kind) {
123
+ case "and":
124
+ for (let j = 0; j < others.length; j++) if (!condition.otherKeys[j].has(others[j])) return false;
125
+ return true;
126
+ case "or":
127
+ for (let j = 0; j < others.length; j++) if (condition.otherKeys[j].has(others[j])) return true;
128
+ return false;
129
+ case "tuples": return condition.otherTuples.has(tupleKey(others));
130
+ }
131
+ }
132
+ const ruleKey = (rule) => tupleKey([rule.kind, rule.name]);
133
+ const hasRule = (rules, rule) => {
134
+ for (const r of rules) if (r.kind === rule.kind && r.name === rule.name) return true;
135
+ return false;
136
+ };
137
+ const ascending = (keys) => {
138
+ for (let i = 1; i < keys.length; i++) if (keys[i - 1] > keys[i]) return false;
139
+ return true;
140
+ };
141
+ const span = (lo, hi) => hi > lo ? `${lo}..${hi}` : String(lo);
142
+ const setKey = (members) => {
143
+ const ints = [];
144
+ let others = [];
145
+ for (const m of members) if (typeof m === "number") ints.push(m);
146
+ else others.push(key(m));
147
+ for (let i = 1; i < ints.length; i++) if (ints[i - 1] >= ints[i]) {
148
+ ints.sort((a, b) => a - b);
149
+ break;
150
+ }
151
+ if (!ascending(others)) others = others.sort(byText);
152
+ let s = "{";
153
+ for (let i = 0; i < ints.length;) {
154
+ let j = i;
155
+ while (j + 1 < ints.length && ints[j + 1] - ints[j] <= 1) j++;
156
+ s += `${s.length > 1 ? "," : ""}${span(ints[i], ints[j])}`;
157
+ i = j + 1;
158
+ }
159
+ for (let i = 0; i < others.length; i++) if (!i || others[i] !== others[i - 1]) s += (s.length > 1 ? "," : "") + others[i];
160
+ return s + "}";
161
+ };
162
+ const functionKey = ({ keys, values }) => {
163
+ const order = [];
164
+ const keyTexts = [];
165
+ let ints = 0;
166
+ for (let i = 0; i < keys.length; i++) {
167
+ order.push(i);
168
+ keyTexts.push(key(keys[i]));
169
+ if (typeof keys[i] === "number") ints++;
170
+ }
171
+ const rank = (i) => typeof keys[i] === "number" ? keys[i] : Infinity;
172
+ order.sort((a, b) => rank(a) - rank(b) || byText(keyTexts[a], keyTexts[b]) || a - b);
173
+ let tuple = ints === keys.length;
174
+ for (let i = 0; tuple && i < order.length; i++) tuple = keys[order[i]] === i + 1;
175
+ let s = tuple ? "<<" : "(";
176
+ for (let i = 0, kept = 0; i < order.length; i++) {
177
+ const k = order[i];
178
+ if (i && keyTexts[k] === keyTexts[order[i - 1]]) continue;
179
+ const v = key(values[k]);
180
+ s += tuple ? `${kept++ ? "," : ""}${v}` : `${kept++ ? "@@" : ""}${keyTexts[k]}:>${v}`;
181
+ }
182
+ return s + (tuple ? ">>" : ")");
183
+ };
184
+ const keys = /* @__PURE__ */ new WeakMap();
185
+ const key = (v) => {
186
+ switch (typeof v) {
187
+ case "boolean": return v ? "TRUE" : "FALSE";
188
+ case "number": return String(v);
189
+ case "string": return JSON.stringify(v);
190
+ }
191
+ if (v.kind === "model") return v.name;
192
+ let k = keys.get(v);
193
+ if (k === void 0) {
194
+ k = v.kind === "interval" ? `{${v.lo > v.hi ? "" : span(v.lo, v.hi)}}` : v.kind === "set" ? setKey(v.members) : functionKey(v);
195
+ keys.set(v, k);
196
+ }
197
+ return k;
198
+ };
199
+ const stateKey = (values) => {
200
+ let k = "";
201
+ for (let i = 0; i < values.length; i++) k += (i ? "," : "") + key(values[i]);
202
+ return k;
203
+ };
204
+ const memo = (make, limit = 65536) => {
205
+ const cache = /* @__PURE__ */ new Map();
206
+ return (k) => {
207
+ let v = cache.get(k);
208
+ if (v === void 0) {
209
+ if (cache.size >= limit) cache.clear();
210
+ cache.set(k, v = make(k));
211
+ }
212
+ return v;
213
+ };
214
+ };
215
+ const valuesOf = (vars, names) => {
216
+ const values = [];
217
+ for (const n of names) values.push(vars[n]);
218
+ return values;
219
+ };
220
+ const findTrace = (counterexample, names, rule, find) => {
221
+ const trace = [];
222
+ for (const { action, vars } of counterexample) {
223
+ const values = valuesOf(vars, names);
224
+ trace.push({
225
+ action,
226
+ vars,
227
+ values,
228
+ id: find(values)
229
+ });
230
+ }
231
+ const end = trace.length - 1;
232
+ if (end < 0) throw new Error(`TLC's trace for ${rule.name} has no states.`);
233
+ for (let i = 0; i < end; i++) if (trace[i].id === void 0) throw new Error(`TLC's trace for ${rule.name} has a state before its last that the dump does not list.`);
234
+ return trace;
235
+ };
236
+ const findLoop = ({ seq, loop }, names, find) => {
237
+ const found = [];
238
+ for (const { action, vars } of seq) found.push({
239
+ action,
240
+ id: vars && find(valuesOf(vars, names))
241
+ });
242
+ return {
243
+ seq: found,
244
+ loop
245
+ };
246
+ };
247
+ const pastState = (vars, start, marked, excluded) => {
248
+ const breaks = [];
249
+ for (const r of marked) if (!hasRule(breaks, r)) breaks.push(r);
250
+ return {
251
+ vars,
252
+ start,
253
+ breaks,
254
+ ends: [],
255
+ past: true,
256
+ excluded
257
+ };
258
+ };
259
+ const CHECK_DEADLOCK = "CHECK_DEADLOCK";
260
+ const deadlockRule = ({ invariants, properties }) => ({
261
+ kind: "deadlock",
262
+ name: invariants.includes("NoDeadlock") || properties.includes("NoDeadlock") ? CHECK_DEADLOCK : "NoDeadlock"
263
+ });
264
+ const hasSection = ({ written }, ...keys) => {
265
+ for (const s of written) if (keys.includes(s.key)) return true;
266
+ return false;
267
+ };
268
+ const stateRules = (spec) => {
269
+ const rules = [];
270
+ for (const name of spec.invariants) rules.push({
271
+ kind: "invariant",
272
+ name
273
+ });
274
+ if (spec.deadlock) rules.push(deadlockRule(spec));
275
+ return rules;
276
+ };
277
+ export { CHART_STATES, CHECK_DEADLOCK, EC, LEVEL, PART, RERUN_STATES, append, byText, checked, count, defaultState, findLoop, findTrace, hasRule, hasSection, holds, isRecord, isStrings, key, list, loopOf, memo, must, pastState, ruleKey, seqOf, show, sortBy, stateKey, stateRules, stateText, tupleKey, unkey, valuesOf };
@@ -0,0 +1,92 @@
1
+ import { findLoop, findTrace, hasRule, must, pastState, stateKey, valuesOf } from "../ir.mjs";
2
+ // runtime/skills/statechart/scripts/passes/annotate.ts
3
+ const finder = (graph, names) => {
4
+ let ids;
5
+ const find = (values) => {
6
+ if (!ids) {
7
+ ids = /* @__PURE__ */ new Map();
8
+ for (const [id, s] of graph.states) if (!s.excluded) ids.set(stateKey(valuesOf(s.vars, names)), id);
9
+ }
10
+ return ids.get(stateKey(values));
11
+ };
12
+ find.add = (id, values) => ids?.set(stateKey(values), id);
13
+ return find;
14
+ };
15
+ function mark(graph, marks, names, rules, find = finder(graph, names)) {
16
+ const byName = /* @__PURE__ */ new Map();
17
+ for (const rule of rules) byName.set(rule.name, rule);
18
+ const past = /* @__PURE__ */ new Map();
19
+ for (const { values, broken } of marks) {
20
+ const id = find(values);
21
+ const state = id === void 0 ? void 0 : graph.states.get(id);
22
+ for (const name of broken) {
23
+ const rule = must(byName, name);
24
+ if (state) state.breaks.push(rule);
25
+ else past.set(stateKey(values), (past.get(stateKey(values)) ?? /* @__PURE__ */ new Set()).add(rule));
26
+ }
27
+ }
28
+ return past;
29
+ }
30
+ function deadEnds(graph, rule) {
31
+ const from = /* @__PURE__ */ new Set();
32
+ for (const t of graph.steps) from.add(t.from);
33
+ for (const [id, s] of graph.states) if (!s.past && !from.has(id)) s.breaks.push(rule);
34
+ }
35
+ function addPast(graph, counterexample, names, rule, past, excludes, find = finder(graph, names)) {
36
+ const trace = findTrace(counterexample, names, rule, find);
37
+ const end = trace.length - 1;
38
+ const from = trace[end - 1]?.id;
39
+ const action = trace[end].action;
40
+ const taken = (to) => {
41
+ for (const t of graph.steps) if (t.from === from && t.to === to && t.action === action) return true;
42
+ return false;
43
+ };
44
+ let to = trace[end].id;
45
+ const reached = to === void 0 ? void 0 : graph.states.get(to);
46
+ const excluded = excludes && reached !== void 0 && end > 0 && !reached.past && !taken(to);
47
+ if (excluded) to = `past ${to} ${action} ${from}`;
48
+ to ??= `past ${graph.states.size}`;
49
+ let last = graph.states.get(to);
50
+ if (!last) {
51
+ const marked = excluded ? reached.breaks : past.get(stateKey(trace[end].values)) ?? [];
52
+ last = pastState(trace[end].vars, end === 0, marked, excluded);
53
+ graph.states.set(to, last);
54
+ if (!excluded) find.add(to, trace[end].values);
55
+ }
56
+ if (!hasRule(last.breaks, rule)) last.breaks.push(rule);
57
+ (last.ends ??= []).push(rule);
58
+ if (from !== void 0 && last.past && !taken(to)) graph.steps.push({
59
+ from,
60
+ to,
61
+ action
62
+ });
63
+ }
64
+ function lasso(graph, trace, names, find = finder(graph, names)) {
65
+ const { seq, loop } = findLoop(trace, names, find);
66
+ const start = seq[0]?.id;
67
+ if (start === void 0) return void 0;
68
+ const out = /* @__PURE__ */ new Map();
69
+ for (const s of seq) out.set(s.id, []);
70
+ for (const t of graph.steps) out.get(t.from)?.push(t);
71
+ const route = [];
72
+ for (let i = 1; i < seq.length; i++) {
73
+ let step;
74
+ for (const t of out.get(seq[i - 1].id) ?? []) if (t.to === seq[i].id && t.action === seq[i].action) {
75
+ step = t;
76
+ break;
77
+ }
78
+ if (!step) return void 0;
79
+ route.push({
80
+ action: step.action,
81
+ state: step.to,
82
+ step
83
+ });
84
+ }
85
+ return {
86
+ start,
87
+ path: route,
88
+ loop,
89
+ stutters: loop === seq.length - 1
90
+ };
91
+ }
92
+ export { addPast, deadEnds, finder, lasso, mark };
@@ -0,0 +1,210 @@
1
+ import { isRecord, key, list, loopOf, must, sortBy, stateText, tupleKey } from "../ir.mjs";
2
+ // runtime/skills/statechart/scripts/passes/label.ts
3
+ const isLabel = (l) => typeof l === "string" && l !== "" && !/\bundefined\b|\bNaN\b|\[object Object\]/.test(l);
4
+ const shapeOf = (shape, vars) => {
5
+ function fail() {
6
+ throw new Error(`The view's state() returned ${JSON.stringify(shape) ?? "undefined"} for the state ${stateText(vars)}. Return a string, an array of strings, or an object of those.`);
7
+ }
8
+ const path = (p) => {
9
+ const labels = [];
10
+ for (const l of [p].flat()) {
11
+ if (!isLabel(l)) fail();
12
+ labels.push(l);
13
+ }
14
+ if (!labels.length) fail();
15
+ return labels;
16
+ };
17
+ const regions = isRecord(shape) ? Object.entries(shape) : [["", shape]];
18
+ const pairs = [];
19
+ for (const [k, v] of regions) pairs.push([k, path(v)]);
20
+ return pairs.length ? Object.fromEntries(pairs) : fail();
21
+ };
22
+ const stepOf = (view) => (action, from, to) => {
23
+ const label = (view.step ?? ((a) => a))(action, from, to);
24
+ if (label === null || isLabel(label)) return label;
25
+ throw new Error(`The view's step() returned ${JSON.stringify(label) ?? "undefined"} for the step ${action}.`);
26
+ };
27
+ function unlabeled(action, before, after, bug) {
28
+ const changed = [];
29
+ for (const k of Object.keys(after)) if (key(before[k]) !== key(after[k])) changed.push(k);
30
+ throw new Error(`The view's step() returned null for the step ${action} that changes ${changed.join(", ") || "nothing"}. It is on the path to the ${bug.rule.name} bug${bug.loop === void 0 ? "" : " or leaves its loop"}, so label it.`);
31
+ }
32
+ function ask(graph, { states: tla, nameOf, from, to }, view) {
33
+ const n = nameOf.length;
34
+ const m = from.length;
35
+ const state = view.state;
36
+ const shapes = new Array(n);
37
+ for (let i = 0; i < n; i++) shapes[i] = shapeOf(state ? state(tla[i].vars) : nameOf[i], tla[i].vars);
38
+ const names = Object.keys(shapes[0] ?? { "": [] });
39
+ const regionsKey = tupleKey(names);
40
+ for (let i = 0; i < n; i++) if (tupleKey(Object.keys(shapes[i])) !== regionsKey) throw new Error(`The view's state() returned the regions ${names.join(", ")} for one state and ${Object.keys(shapes[i]).join(", ")} for the state ${stateText(tla[i].vars)}. Return the same regions for every state.`);
41
+ const step = stepOf(view);
42
+ const labels = new Array(m);
43
+ for (let j = 0; j < m; j++) labels[j] = step(graph.steps[j].action, tla[from[j]].vars, tla[to[j]].vars);
44
+ const groups = new Array(n);
45
+ const asked = new Uint8Array(n);
46
+ const group = (i) => {
47
+ if (view.group && !asked[i]) {
48
+ groups[i] = view.group(tla[i].vars);
49
+ asked[i] = 1;
50
+ }
51
+ return groups[i];
52
+ };
53
+ return {
54
+ names,
55
+ shapes,
56
+ labels,
57
+ group
58
+ };
59
+ }
60
+ function asParents({ states: tla }, { names, shapes, labels, group }) {
61
+ const parents = new Array(shapes.length);
62
+ for (let i = 0; i < shapes.length; i++) {
63
+ const path = [];
64
+ for (const n of names) for (const p of shapes[i][n]) path.push(`${n} ${p}`);
65
+ parents[i] = shapeOf(path, tla[i].vars);
66
+ }
67
+ return {
68
+ names: [""],
69
+ shapes: parents,
70
+ labels,
71
+ group
72
+ };
73
+ }
74
+ function labelGraph(graph, { index, from, to, action }, answers, rank, found) {
75
+ const { names, shapes, labels: stepLabels } = answers;
76
+ const n = shapes.length;
77
+ const m = stepLabels.length;
78
+ const onPath = /* @__PURE__ */ new Set();
79
+ for (const b of found) for (const p of b.path) onPath.add(p.step);
80
+ const pathStepIndex = /* @__PURE__ */ new Map();
81
+ if (onPath.size) {
82
+ for (let j = 0; j < m; j++) if (onPath.has(graph.steps[j])) pathStepIndex.set(graph.steps[j], j);
83
+ }
84
+ const R = names.length;
85
+ const keys = [];
86
+ const kinds = [];
87
+ const sizes = [];
88
+ for (const name of names) {
89
+ const key = new Array(n);
90
+ const kind = new Int32Array(n);
91
+ const tops = /* @__PURE__ */ new Map();
92
+ const nested = /* @__PURE__ */ new Map();
93
+ const keyOf = [];
94
+ for (let i = 0; i < n; i++) {
95
+ const path = shapes[i][name];
96
+ const top = path.length === 1;
97
+ const seen = top ? tops : nested;
98
+ const k = top ? path[0] : tupleKey(path);
99
+ let c = seen.get(k);
100
+ if (c === void 0) {
101
+ seen.set(k, c = keyOf.length);
102
+ keyOf.push(top ? tupleKey(path) : k);
103
+ }
104
+ key[i] = keyOf[c];
105
+ kind[i] = c;
106
+ }
107
+ keys.push(key);
108
+ kinds.push(kind);
109
+ sizes.push(keyOf.length);
110
+ }
111
+ for (const b of found) {
112
+ let t;
113
+ for (const p of b.path) if (stepLabels[must(pathStepIndex, p.step)] === null) {
114
+ t = p.step;
115
+ break;
116
+ }
117
+ if (!t) {
118
+ const inLoop = loopOf(b, index);
119
+ if (inLoop.size) {
120
+ for (let j = 0; j < m; j++) if (inLoop.has(from[j]) && !inLoop.has(to[j]) && stepLabels[j] === null) {
121
+ t = graph.steps[j];
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ if (t) unlabeled(t.action, must(graph.states, t.from).vars, must(graph.states, t.to).vars, b);
127
+ }
128
+ const drawn = [];
129
+ const drawnLabels = new Array(m);
130
+ for (let j = 0; j < m; j++) {
131
+ const label = stepLabels[j];
132
+ if (label === null) continue;
133
+ drawn.push(j);
134
+ drawnLabels[j] = label;
135
+ }
136
+ const fromRank = new Int32Array(m);
137
+ const toRank = new Int32Array(m);
138
+ for (let j = 0; j < m; j++) {
139
+ fromRank[j] = rank[from[j]];
140
+ toRank[j] = rank[to[j]];
141
+ }
142
+ const sorted = sortBy(Int32Array.from(drawn), [
143
+ fromRank,
144
+ toRank,
145
+ action
146
+ ]);
147
+ const pathSteps = new Uint8Array(m);
148
+ for (const j of pathStepIndex.values()) pathSteps[j] = 1;
149
+ const byLabel = /* @__PURE__ */ new Map();
150
+ if (R > 1) for (const j of sorted) {
151
+ let entry = byLabel.get(drawnLabels[j]);
152
+ if (!entry) byLabel.set(drawnLabels[j], entry = {
153
+ changed: new Uint8Array(R),
154
+ sets: /* @__PURE__ */ new Set()
155
+ });
156
+ const changed = [];
157
+ for (let r = 0; r < R; r++) if (kinds[r][from[j]] !== kinds[r][to[j]]) {
158
+ changed.push(names[r]);
159
+ entry.changed[r] = 1;
160
+ }
161
+ if (changed.length > 1) entry.sets.add(list(changed));
162
+ }
163
+ const together = /* @__PURE__ */ new Set();
164
+ for (const [text, { sets }] of byLabel) if (sets.size) together.add(text);
165
+ const notes = [];
166
+ for (const [text, entry] of byLabel) {
167
+ const changed = [];
168
+ for (let r = 0; r < R; r++) if (entry.changed[r]) changed.push(names[r]);
169
+ if (changed.length < 2) continue;
170
+ if (!together.has(text)) {
171
+ notes.push(`The step ${text} changes only one of ${list(changed)} at a time.`);
172
+ continue;
173
+ }
174
+ const sets = [...entry.sets];
175
+ notes.push(`The step ${text} changes ${sets.length > 1 ? `${sets.join(", or ")},` : sets[0]} at the same time.`);
176
+ }
177
+ return {
178
+ ...answers,
179
+ drawnLabels,
180
+ keys,
181
+ kinds,
182
+ sizes,
183
+ sorted,
184
+ pathStepIndex,
185
+ pathSteps,
186
+ together,
187
+ notes
188
+ };
189
+ }
190
+ function tell(states, found, shapeAt, labelAt) {
191
+ const vars = (id) => must(states, id).vars;
192
+ const stories = /* @__PURE__ */ new Map();
193
+ for (const bug of found) {
194
+ const story = [{ state: shapeAt(bug.start) }];
195
+ let from = bug.start;
196
+ for (const [k, p] of bug.path.entries()) {
197
+ const step = labelAt(bug, k, from);
198
+ if (step === null) unlabeled(p.action, vars(from), vars(p.state), bug);
199
+ story.push({
200
+ step,
201
+ state: shapeAt(p.state)
202
+ });
203
+ from = p.state;
204
+ }
205
+ stories.set(bug, story);
206
+ }
207
+ return stories;
208
+ }
209
+ const storiesOf = (graph, found, { index }, { shapes, drawnLabels, pathStepIndex }) => tell(graph.states, found, (id) => shapes[must(index, id)], (bug, k) => drawnLabels[must(pathStepIndex, bug.path[k].step)]);
210
+ export { asParents, ask, labelGraph, storiesOf };
@@ -0,0 +1,84 @@
1
+ import { append, must, tupleKey, unkey } from "../ir.mjs";
2
+ // runtime/skills/statechart/scripts/passes/lift.ts
3
+ function liftToParents(states, steps) {
4
+ const depths = /* @__PURE__ */ new Map();
5
+ const leaves = /* @__PURE__ */ new Map();
6
+ for (const s of states.values()) for (let i = 1; i < s.path.length; i++) {
7
+ const prefix = tupleKey(s.path.slice(0, i));
8
+ depths.set(prefix, i);
9
+ leaves.set(prefix, (leaves.get(prefix) ?? 0) + 1);
10
+ }
11
+ if (!depths.size) return steps;
12
+ const leaving = /* @__PURE__ */ new Map();
13
+ for (const s of steps) {
14
+ let same = 0;
15
+ while (same < s.from.length && s.from[same] === s.to[same]) same++;
16
+ for (let i = 1; i < s.from.length; i++) {
17
+ if (i <= same && i < s.to.length) continue;
18
+ const prefix = tupleKey(s.from.slice(0, i));
19
+ if (depths.has(prefix)) append(leaving, prefix, s);
20
+ }
21
+ }
22
+ const removed = /* @__PURE__ */ new Set();
23
+ const lifted = [];
24
+ for (const [prefix] of [...depths].sort((a, b) => a[1] - b[1])) {
25
+ const groups = /* @__PURE__ */ new Map();
26
+ for (const s of leaving.get(prefix) ?? []) if (!removed.has(s)) append(groups, tupleKey([
27
+ s.label,
28
+ s.when,
29
+ s.to
30
+ ]), s);
31
+ const under = must(leaves, prefix);
32
+ for (const group of groups.values()) {
33
+ if (under < 2 || group.length < under) continue;
34
+ for (const s of group) removed.add(s);
35
+ lifted.push({
36
+ ...group[0],
37
+ from: unkey(prefix)
38
+ });
39
+ }
40
+ }
41
+ const kept = [];
42
+ for (const s of steps) if (!removed.has(s)) kept.push(s);
43
+ for (const s of lifted) kept.push(s);
44
+ return kept;
45
+ }
46
+ function lift(chart) {
47
+ const regions = [];
48
+ for (const r of chart.regions) {
49
+ const known = /* @__PURE__ */ new Map();
50
+ for (const s of r.states) known.set(s.path, known.size);
51
+ let numbers;
52
+ const pathIndex = (path) => {
53
+ let i = known.get(path);
54
+ if (i !== void 0) return i;
55
+ if (!numbers) {
56
+ numbers = /* @__PURE__ */ new Map();
57
+ for (const s of r.states) numbers.set(tupleKey(s.path), numbers.size);
58
+ }
59
+ const k = tupleKey(path);
60
+ i = numbers.get(k);
61
+ if (i === void 0) numbers.set(k, i = numbers.size);
62
+ known.set(path, i);
63
+ return i;
64
+ };
65
+ const merged = /* @__PURE__ */ new Map();
66
+ for (const s of liftToParents(r.states, r.steps)) {
67
+ const f = pathIndex(s.from);
68
+ const t = pathIndex(s.to);
69
+ const k = s.when === void 0 && f < 2 ** 26 && t < 2 ** 26 ? f * 2 ** 26 + t : `${f},${t}:${s.when}`;
70
+ const prior = merged.get(k);
71
+ if (prior) prior.label += ` or ${s.label}`;
72
+ else merged.set(k, { ...s });
73
+ }
74
+ regions.push({
75
+ ...r,
76
+ steps: [...merged.values()]
77
+ });
78
+ }
79
+ return {
80
+ ...chart,
81
+ regions
82
+ };
83
+ }
84
+ export { lift, liftToParents };