@justjoshn/pi-pstack-v2 0.0.0-stage → 0.1.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 (576) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +66 -2
  3. package/agents/ci-watcher.md +26 -0
  4. package/agents/comment-sicko.md +32 -0
  5. package/agents/poteto-agent.md +8 -0
  6. package/agents/thermo-nuclear-code-quality-review.md +23 -0
  7. package/docs/guide/01-setup.md +81 -0
  8. package/docs/guide/02-poteto-mode.md +137 -0
  9. package/docs/guide/03-understand.md +79 -0
  10. package/docs/guide/04-design.md +133 -0
  11. package/docs/guide/05-build-and-clean.md +83 -0
  12. package/docs/guide/06-verify-and-ship.md +162 -0
  13. package/docs/guide/07-overnight.md +121 -0
  14. package/docs/guide/08-principles.md +72 -0
  15. package/docs/guide/09-make-it-yours.md +100 -0
  16. package/docs/guide/10-recipes-and-pitfalls.md +182 -0
  17. package/docs/guide/README.md +38 -0
  18. package/docs/guide/images/design.jpg +0 -0
  19. package/docs/guide/images/overnight.jpg +0 -0
  20. package/docs/guide/images/recipes.jpg +0 -0
  21. package/docs/guide/images/router.jpg +0 -0
  22. package/docs/guide/images/understanding.jpg +0 -0
  23. package/docs/guide/images/verification.jpg +0 -0
  24. package/docs/pi-mechanisms.md +101 -0
  25. package/package.json +49 -4
  26. package/rules/no-inline-imports.md +8 -0
  27. package/rules/typescript-exhaustive-switch.md +6 -0
  28. package/skills/architect/SKILL.md +81 -0
  29. package/skills/architect/references/design-red-flags.md +57 -0
  30. package/skills/architect/references/rationale-template.md +35 -0
  31. package/skills/architect/references/runner-prompt.md +20 -0
  32. package/skills/arena/SKILL.md +48 -0
  33. package/skills/automate-me/SKILL.md +104 -0
  34. package/skills/benchmark-checklist/SKILL.md +39 -0
  35. package/skills/blast-radius/SKILL.md +50 -0
  36. package/skills/bro/SKILL.md +7 -0
  37. package/skills/check-compiler-errors/SKILL.md +23 -0
  38. package/skills/control-cli/SKILL.md +110 -0
  39. package/skills/control-ui/SKILL.md +109 -0
  40. package/skills/correct/SKILL.md +32 -0
  41. package/skills/create-formal-verification-skill/SKILL.md +43 -0
  42. package/skills/create-verification-skill/SKILL.md +44 -0
  43. package/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
  44. package/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
  45. package/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
  46. package/skills/deslop/SKILL.md +22 -0
  47. package/skills/figure-it-out/SKILL.md +54 -0
  48. package/skills/fix-ci/SKILL.md +29 -0
  49. package/skills/fix-merge-conflicts/SKILL.md +32 -0
  50. package/skills/get-pr-comments/SKILL.md +23 -0
  51. package/skills/how/SKILL.md +21 -0
  52. package/skills/in-your-own-words/SKILL.md +7 -0
  53. package/skills/interrogate/SKILL.md +35 -0
  54. package/skills/ketchup/SKILL.md +43 -0
  55. package/skills/ketchup-video/SKILL.md +29 -0
  56. package/skills/loop-on-ci/SKILL.md +50 -0
  57. package/skills/maintain-formal-verification-skill/SKILL.md +58 -0
  58. package/skills/maintain-verification-skill/SKILL.md +39 -0
  59. package/skills/make-bot-ui/SKILL.md +98 -0
  60. package/skills/make-pr-easy-to-review/SKILL.md +59 -0
  61. package/skills/new-branch-and-pr/SKILL.md +29 -0
  62. package/skills/no-comments/SKILL.md +26 -0
  63. package/skills/poteto-help/SKILL.md +159 -0
  64. package/skills/poteto-help/references/prompting.md +51 -0
  65. package/skills/poteto-help/references/recipes.md +51 -0
  66. package/skills/poteto-mode/SKILL.md +151 -0
  67. package/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
  68. package/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
  69. package/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
  70. package/skills/poteto-mode/playbooks/autopilot-stack.md +8 -0
  71. package/skills/poteto-mode/playbooks/babysit.md +23 -0
  72. package/skills/poteto-mode/playbooks/bug-fix.md +15 -0
  73. package/skills/poteto-mode/playbooks/eval.md +25 -0
  74. package/skills/poteto-mode/playbooks/feature.md +21 -0
  75. package/skills/poteto-mode/playbooks/hillclimb.md +21 -0
  76. package/skills/poteto-mode/playbooks/investigation.md +14 -0
  77. package/skills/poteto-mode/playbooks/multi-phase-plan.md +155 -0
  78. package/skills/poteto-mode/playbooks/opening-a-pr.md +32 -0
  79. package/skills/poteto-mode/playbooks/orchestrate.md +25 -0
  80. package/skills/poteto-mode/playbooks/pause-safely.md +10 -0
  81. package/skills/poteto-mode/playbooks/perf-issue.md +25 -0
  82. package/skills/poteto-mode/playbooks/prototype.md +14 -0
  83. package/skills/poteto-mode/playbooks/refactoring.md +16 -0
  84. package/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
  85. package/skills/poteto-mode/playbooks/session-pickup.md +11 -0
  86. package/skills/poteto-mode/playbooks/shipping.md +12 -0
  87. package/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
  88. package/skills/poteto-mode/playbooks/visual-parity.md +11 -0
  89. package/skills/poteto-mode/playbooks/worktree-cleanup.md +12 -0
  90. package/skills/poteto-mode/references/bugbot-triage.md +142 -0
  91. package/skills/poteto-mode/scripts/bootstrap.ts +62 -0
  92. package/skills/poteto-mode/scripts/bun.lock +67 -0
  93. package/skills/poteto-mode/scripts/check-plan.mjs +205 -0
  94. package/skills/poteto-mode/scripts/check-plan.test.ts +110 -0
  95. package/skills/poteto-mode/scripts/package.json +16 -0
  96. package/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
  97. package/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
  98. package/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +129 -0
  99. package/skills/poteto-mode/scripts/watch-pr/github.test.ts +498 -0
  100. package/skills/poteto-mode/scripts/watch-pr/github.ts +726 -0
  101. package/skills/poteto-mode/scripts/watch-pr/policy.test.ts +482 -0
  102. package/skills/poteto-mode/scripts/watch-pr/policy.ts +842 -0
  103. package/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
  104. package/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
  105. package/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
  106. package/skills/poteto-mode/scripts/watch-pr/types.ts +414 -0
  107. package/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
  108. package/skills/poteto-mode/scripts/worktree-audit.sh +146 -0
  109. package/skills/pr-review-canvas/SKILL.md +170 -0
  110. package/skills/pr-review-canvas/renderer.js +170 -0
  111. package/skills/pr-review-canvas/styles.css +96 -0
  112. package/skills/pr-review-canvas/template.html +18 -0
  113. package/skills/principle-attack-the-premise/SKILL.md +21 -0
  114. package/skills/principle-boundary-discipline/SKILL.md +34 -0
  115. package/skills/principle-build-the-lever/SKILL.md +23 -0
  116. package/skills/principle-encode-lessons-in-structure/SKILL.md +11 -0
  117. package/skills/principle-exhaust-the-design-space/SKILL.md +9 -0
  118. package/skills/principle-experience-first/SKILL.md +19 -0
  119. package/skills/principle-explain-the-number/SKILL.md +18 -0
  120. package/skills/principle-fix-root-causes/SKILL.md +21 -0
  121. package/skills/principle-foundational-thinking/SKILL.md +21 -0
  122. package/skills/principle-guard-the-context-window/SKILL.md +12 -0
  123. package/skills/principle-laziness-protocol/SKILL.md +10 -0
  124. package/skills/principle-make-operations-idempotent/SKILL.md +22 -0
  125. package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +14 -0
  126. package/skills/principle-minimize-reader-load/SKILL.md +18 -0
  127. package/skills/principle-model-the-domain/SKILL.md +24 -0
  128. package/skills/principle-never-block-on-the-human/SKILL.md +15 -0
  129. package/skills/principle-outcome-oriented-execution/SKILL.md +21 -0
  130. package/skills/principle-prove-it-works/SKILL.md +22 -0
  131. package/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
  132. package/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
  133. package/skills/principle-sequence-verifiable-units/SKILL.md +17 -0
  134. package/skills/principle-subtract-before-you-add/SKILL.md +18 -0
  135. package/skills/principle-test-behavior-not-implementation/SKILL.md +20 -0
  136. package/skills/principle-type-system-discipline/SKILL.md +13 -0
  137. package/skills/recall/SKILL.md +37 -0
  138. package/skills/reflect/SKILL.md +69 -0
  139. package/skills/reflect/references/divergent-reviewer.md +38 -0
  140. package/skills/reflect/references/judgment-reviewer.md +37 -0
  141. package/skills/reflect/references/synthesizer.md +56 -0
  142. package/skills/reflect/references/tooling-reviewer.md +48 -0
  143. package/skills/review-and-ship/SKILL.md +41 -0
  144. package/skills/run-smoke-tests/SKILL.md +42 -0
  145. package/skills/setup-pstack/SKILL.md +79 -0
  146. package/skills/sharpen/SKILL.md +16 -0
  147. package/skills/show-me-your-work/SKILL.md +82 -0
  148. package/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
  149. package/skills/show-me-your-work/scripts/log.sh +42 -0
  150. package/skills/statechart/SKILL.md +82 -0
  151. package/skills/statechart/references/render.md +93 -0
  152. package/skills/statechart/scripts/backends/cfg.ts +33 -0
  153. package/skills/statechart/scripts/backends/mermaid.ts +249 -0
  154. package/skills/statechart/scripts/backends/plain-text.ts +72 -0
  155. package/skills/statechart/scripts/backends/report.ts +177 -0
  156. package/skills/statechart/scripts/frontends/config.ts +276 -0
  157. package/skills/statechart/scripts/frontends/dot.ts +74 -0
  158. package/skills/statechart/scripts/frontends/marks.ts +93 -0
  159. package/skills/statechart/scripts/frontends/messages.ts +52 -0
  160. package/skills/statechart/scripts/frontends/spec.ts +114 -0
  161. package/skills/statechart/scripts/frontends/trace.ts +24 -0
  162. package/skills/statechart/scripts/frontends/value.ts +166 -0
  163. package/skills/statechart/scripts/frontends/verdict.ts +40 -0
  164. package/skills/statechart/scripts/frontends/view.ts +119 -0
  165. package/skills/statechart/scripts/ir.ts +547 -0
  166. package/skills/statechart/scripts/package.json +11 -0
  167. package/skills/statechart/scripts/passes/annotate.ts +128 -0
  168. package/skills/statechart/scripts/passes/label.ts +269 -0
  169. package/skills/statechart/scripts/passes/lift.ts +85 -0
  170. package/skills/statechart/scripts/passes/loop-check.ts +68 -0
  171. package/skills/statechart/scripts/passes/paths.ts +60 -0
  172. package/skills/statechart/scripts/passes/reach.ts +135 -0
  173. package/skills/statechart/scripts/passes/region-check.ts +97 -0
  174. package/skills/statechart/scripts/passes/regions.ts +295 -0
  175. package/skills/statechart/scripts/pipeline.ts +76 -0
  176. package/skills/statechart/scripts/run.ts +506 -0
  177. package/skills/statechart/scripts/statechart +29 -0
  178. package/skills/statechart/scripts/statechart.ts +164 -0
  179. package/skills/statechart/scripts/test/ConfigOracle.java +63 -0
  180. package/skills/statechart/scripts/test/chart.test.ts +1253 -0
  181. package/skills/statechart/scripts/test/charts/Braces.mmd +7 -0
  182. package/skills/statechart/scripts/test/charts/Escapes.mmd +11 -0
  183. package/skills/statechart/scripts/test/charts/Phases.mmd +29 -0
  184. package/skills/statechart/scripts/test/cli.test.ts +1315 -0
  185. package/skills/statechart/scripts/test/config-fuzz.test.ts +263 -0
  186. package/skills/statechart/scripts/test/corpus/Counter/ChartRun.out +57 -0
  187. package/skills/statechart/scripts/test/corpus/Counter/Counter.cfg +3 -0
  188. package/skills/statechart/scripts/test/corpus/Counter/Counter.tla +10 -0
  189. package/skills/statechart/scripts/test/corpus/Counter/chart.mmd +9 -0
  190. package/skills/statechart/scripts/test/corpus/Counter/graph.dot +16 -0
  191. package/skills/statechart/scripts/test/corpus/Counter/report.md +7 -0
  192. package/skills/statechart/scripts/test/corpus/Counter/sany.out +2 -0
  193. package/skills/statechart/scripts/test/corpus/Counter/verdict-1.out +49 -0
  194. package/skills/statechart/scripts/test/corpus/CounterAction/ChartRun.out +60 -0
  195. package/skills/statechart/scripts/test/corpus/CounterAction/CounterAction.cfg +4 -0
  196. package/skills/statechart/scripts/test/corpus/CounterAction/CounterAction.tla +22 -0
  197. package/skills/statechart/scripts/test/corpus/CounterAction/chart.mmd +26 -0
  198. package/skills/statechart/scripts/test/corpus/CounterAction/graph.dot +19 -0
  199. package/skills/statechart/scripts/test/corpus/CounterAction/report.md +20 -0
  200. package/skills/statechart/scripts/test/corpus/CounterAction/sany.out +2 -0
  201. package/skills/statechart/scripts/test/corpus/CounterAction/verdict-1.exit +1 -0
  202. package/skills/statechart/scripts/test/corpus/CounterAction/verdict-1.out +56 -0
  203. package/skills/statechart/scripts/test/corpus/CounterAction/verdict-2.exit +1 -0
  204. package/skills/statechart/scripts/test/corpus/CounterAction/verdict-2.out +82 -0
  205. package/skills/statechart/scripts/test/corpus/CounterAction/verdict-3.out +57 -0
  206. package/skills/statechart/scripts/test/corpus/CounterDeadlock/ChartRun.out +59 -0
  207. package/skills/statechart/scripts/test/corpus/CounterDeadlock/CounterDeadlock.cfg +3 -0
  208. package/skills/statechart/scripts/test/corpus/CounterDeadlock/CounterDeadlock.tla +11 -0
  209. package/skills/statechart/scripts/test/corpus/CounterDeadlock/chart.mmd +22 -0
  210. package/skills/statechart/scripts/test/corpus/CounterDeadlock/graph.dot +16 -0
  211. package/skills/statechart/scripts/test/corpus/CounterDeadlock/report.md +17 -0
  212. package/skills/statechart/scripts/test/corpus/CounterDeadlock/sany.out +2 -0
  213. package/skills/statechart/scripts/test/corpus/CounterDeadlock/verdict-1.exit +1 -0
  214. package/skills/statechart/scripts/test/corpus/CounterDeadlock/verdict-1.out +56 -0
  215. package/skills/statechart/scripts/test/corpus/CounterDeadlock/verdict-2.exit +1 -0
  216. package/skills/statechart/scripts/test/corpus/CounterDeadlock/verdict-2.out +77 -0
  217. package/skills/statechart/scripts/test/corpus/CounterFan/ChartRun.out +69 -0
  218. package/skills/statechart/scripts/test/corpus/CounterFan/CounterFan.cfg +2 -0
  219. package/skills/statechart/scripts/test/corpus/CounterFan/CounterFan.tla +11 -0
  220. package/skills/statechart/scripts/test/corpus/CounterFan/chart.mmd +85 -0
  221. package/skills/statechart/scripts/test/corpus/CounterFan/graph.dot +70 -0
  222. package/skills/statechart/scripts/test/corpus/CounterFan/report.md +12 -0
  223. package/skills/statechart/scripts/test/corpus/CounterFan/sany.out +2 -0
  224. package/skills/statechart/scripts/test/corpus/CounterFan/verdict-1.exit +1 -0
  225. package/skills/statechart/scripts/test/corpus/CounterFan/verdict-1.out +67 -0
  226. package/skills/statechart/scripts/test/corpus/CounterFan/verdict-2.out +57 -0
  227. package/skills/statechart/scripts/test/corpus/CounterGuard/ChartRun.exit +1 -0
  228. package/skills/statechart/scripts/test/corpus/CounterGuard/ChartRun.out +85 -0
  229. package/skills/statechart/scripts/test/corpus/CounterGuard/CounterGuard.cfg +6 -0
  230. package/skills/statechart/scripts/test/corpus/CounterGuard/CounterGuard.tla +13 -0
  231. package/skills/statechart/scripts/test/corpus/CounterGuard/chart.mmd +5 -0
  232. package/skills/statechart/scripts/test/corpus/CounterGuard/graph.dot +10 -0
  233. package/skills/statechart/scripts/test/corpus/CounterGuard/report.md +31 -0
  234. package/skills/statechart/scripts/test/corpus/CounterGuard/sany.out +2 -0
  235. package/skills/statechart/scripts/test/corpus/CounterGuard/verdict-1.exit +1 -0
  236. package/skills/statechart/scripts/test/corpus/CounterGuard/verdict-1.out +64 -0
  237. package/skills/statechart/scripts/test/corpus/CounterGuard/verdict-2.exit +1 -0
  238. package/skills/statechart/scripts/test/corpus/CounterGuard/verdict-2.out +77 -0
  239. package/skills/statechart/scripts/test/corpus/CounterInitPast/ChartRun.out +55 -0
  240. package/skills/statechart/scripts/test/corpus/CounterInitPast/CounterInitPast.cfg +3 -0
  241. package/skills/statechart/scripts/test/corpus/CounterInitPast/CounterInitPast.tla +10 -0
  242. package/skills/statechart/scripts/test/corpus/CounterInitPast/chart.mmd +12 -0
  243. package/skills/statechart/scripts/test/corpus/CounterInitPast/graph.dot +6 -0
  244. package/skills/statechart/scripts/test/corpus/CounterInitPast/report.md +12 -0
  245. package/skills/statechart/scripts/test/corpus/CounterInitPast/sany.out +2 -0
  246. package/skills/statechart/scripts/test/corpus/CounterInitPast/verdict-1.exit +1 -0
  247. package/skills/statechart/scripts/test/corpus/CounterInitPast/verdict-1.out +33 -0
  248. package/skills/statechart/scripts/test/corpus/CounterInitPast/verdict-2.out +54 -0
  249. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/ChartRun.out +54 -0
  250. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/CounterInitPastHolds.cfg +3 -0
  251. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/CounterInitPastHolds.tla +10 -0
  252. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/chart.mmd +1 -0
  253. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/graph.dot +6 -0
  254. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/report.md +7 -0
  255. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/sany.out +2 -0
  256. package/skills/statechart/scripts/test/corpus/CounterInitPastHolds/verdict-1.out +46 -0
  257. package/skills/statechart/scripts/test/corpus/CounterInstance/ChartRun.out +59 -0
  258. package/skills/statechart/scripts/test/corpus/CounterInstance/CounterInstance.cfg +2 -0
  259. package/skills/statechart/scripts/test/corpus/CounterInstance/CounterInstance.tla +10 -0
  260. package/skills/statechart/scripts/test/corpus/CounterInstance/CounterSteps.tla +6 -0
  261. package/skills/statechart/scripts/test/corpus/CounterInstance/chart.mmd +17 -0
  262. package/skills/statechart/scripts/test/corpus/CounterInstance/graph.dot +15 -0
  263. package/skills/statechart/scripts/test/corpus/CounterInstance/report.md +14 -0
  264. package/skills/statechart/scripts/test/corpus/CounterInstance/sany.out +3 -0
  265. package/skills/statechart/scripts/test/corpus/CounterInstance/verdict-1.exit +1 -0
  266. package/skills/statechart/scripts/test/corpus/CounterInstance/verdict-1.out +78 -0
  267. package/skills/statechart/scripts/test/corpus/CounterJump/ChartRun.out +59 -0
  268. package/skills/statechart/scripts/test/corpus/CounterJump/CounterJump.cfg +3 -0
  269. package/skills/statechart/scripts/test/corpus/CounterJump/CounterJump.tla +19 -0
  270. package/skills/statechart/scripts/test/corpus/CounterJump/chart.mmd +26 -0
  271. package/skills/statechart/scripts/test/corpus/CounterJump/graph.dot +22 -0
  272. package/skills/statechart/scripts/test/corpus/CounterJump/report.md +12 -0
  273. package/skills/statechart/scripts/test/corpus/CounterJump/sany.out +2 -0
  274. package/skills/statechart/scripts/test/corpus/CounterJump/verdict-1.exit +1 -0
  275. package/skills/statechart/scripts/test/corpus/CounterJump/verdict-1.out +58 -0
  276. package/skills/statechart/scripts/test/corpus/CounterJump/verdict-2.out +57 -0
  277. package/skills/statechart/scripts/test/corpus/CounterLoop/ChartRun.out +57 -0
  278. package/skills/statechart/scripts/test/corpus/CounterLoop/CounterLoop.cfg +2 -0
  279. package/skills/statechart/scripts/test/corpus/CounterLoop/CounterLoop.tla +11 -0
  280. package/skills/statechart/scripts/test/corpus/CounterLoop/chart.mmd +17 -0
  281. package/skills/statechart/scripts/test/corpus/CounterLoop/graph.dot +15 -0
  282. package/skills/statechart/scripts/test/corpus/CounterLoop/report.md +14 -0
  283. package/skills/statechart/scripts/test/corpus/CounterLoop/sany.out +2 -0
  284. package/skills/statechart/scripts/test/corpus/CounterLoop/verdict-1.exit +1 -0
  285. package/skills/statechart/scripts/test/corpus/CounterLoop/verdict-1.out +76 -0
  286. package/skills/statechart/scripts/test/corpus/CounterOrder/ChartRun.out +59 -0
  287. package/skills/statechart/scripts/test/corpus/CounterOrder/CounterOrder.cfg +3 -0
  288. package/skills/statechart/scripts/test/corpus/CounterOrder/CounterOrder.tla +11 -0
  289. package/skills/statechart/scripts/test/corpus/CounterOrder/chart.mmd +19 -0
  290. package/skills/statechart/scripts/test/corpus/CounterOrder/graph.dot +10 -0
  291. package/skills/statechart/scripts/test/corpus/CounterOrder/report.md +15 -0
  292. package/skills/statechart/scripts/test/corpus/CounterOrder/sany.out +2 -0
  293. package/skills/statechart/scripts/test/corpus/CounterOrder/verdict-1.exit +1 -0
  294. package/skills/statechart/scripts/test/corpus/CounterOrder/verdict-1.out +56 -0
  295. package/skills/statechart/scripts/test/corpus/CounterOrder/verdict-2.exit +1 -0
  296. package/skills/statechart/scripts/test/corpus/CounterOrder/verdict-2.out +67 -0
  297. package/skills/statechart/scripts/test/corpus/CounterRules/ChartRun.out +62 -0
  298. package/skills/statechart/scripts/test/corpus/CounterRules/CounterRules.cfg +6 -0
  299. package/skills/statechart/scripts/test/corpus/CounterRules/CounterRules.tla +24 -0
  300. package/skills/statechart/scripts/test/corpus/CounterRules/Moves.tla +5 -0
  301. package/skills/statechart/scripts/test/corpus/CounterRules/chart.mmd +22 -0
  302. package/skills/statechart/scripts/test/corpus/CounterRules/graph.dot +10 -0
  303. package/skills/statechart/scripts/test/corpus/CounterRules/report.md +23 -0
  304. package/skills/statechart/scripts/test/corpus/CounterRules/sany.out +3 -0
  305. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-1.exit +1 -0
  306. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-1.out +58 -0
  307. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-2.exit +1 -0
  308. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-2.out +66 -0
  309. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-3.exit +1 -0
  310. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-3.out +74 -0
  311. package/skills/statechart/scripts/test/corpus/CounterRules/verdict-4.out +59 -0
  312. package/skills/statechart/scripts/test/corpus/CounterStart/ChartRun.out +58 -0
  313. package/skills/statechart/scripts/test/corpus/CounterStart/CounterStart.cfg +3 -0
  314. package/skills/statechart/scripts/test/corpus/CounterStart/CounterStart.tla +15 -0
  315. package/skills/statechart/scripts/test/corpus/CounterStart/chart.mmd +18 -0
  316. package/skills/statechart/scripts/test/corpus/CounterStart/graph.dot +13 -0
  317. package/skills/statechart/scripts/test/corpus/CounterStart/report.md +11 -0
  318. package/skills/statechart/scripts/test/corpus/CounterStart/sany.out +2 -0
  319. package/skills/statechart/scripts/test/corpus/CounterStart/verdict-1.exit +1 -0
  320. package/skills/statechart/scripts/test/corpus/CounterStart/verdict-1.out +33 -0
  321. package/skills/statechart/scripts/test/corpus/CounterStart/verdict-2.out +57 -0
  322. package/skills/statechart/scripts/test/corpus/CounterStop/ChartRun.out +57 -0
  323. package/skills/statechart/scripts/test/corpus/CounterStop/CounterStop.cfg +3 -0
  324. package/skills/statechart/scripts/test/corpus/CounterStop/CounterStop.tla +15 -0
  325. package/skills/statechart/scripts/test/corpus/CounterStop/chart.mmd +7 -0
  326. package/skills/statechart/scripts/test/corpus/CounterStop/graph.dot +13 -0
  327. package/skills/statechart/scripts/test/corpus/CounterStop/report.md +6 -0
  328. package/skills/statechart/scripts/test/corpus/CounterStop/sany.out +2 -0
  329. package/skills/statechart/scripts/test/corpus/CounterStop/verdict-1.out +49 -0
  330. package/skills/statechart/scripts/test/corpus/CounterTie/ChartRun.out +61 -0
  331. package/skills/statechart/scripts/test/corpus/CounterTie/CounterTie.cfg +4 -0
  332. package/skills/statechart/scripts/test/corpus/CounterTie/CounterTie.tla +14 -0
  333. package/skills/statechart/scripts/test/corpus/CounterTie/chart.mmd +30 -0
  334. package/skills/statechart/scripts/test/corpus/CounterTie/graph.dot +19 -0
  335. package/skills/statechart/scripts/test/corpus/CounterTie/report.md +27 -0
  336. package/skills/statechart/scripts/test/corpus/CounterTie/sany.out +2 -0
  337. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-1.exit +1 -0
  338. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-1.out +56 -0
  339. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-2.exit +1 -0
  340. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-2.out +64 -0
  341. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-3.exit +1 -0
  342. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-3.out +87 -0
  343. package/skills/statechart/scripts/test/corpus/CounterTie/verdict-4.out +57 -0
  344. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/ChartRun.out +60 -0
  345. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/CounterTieInGraph.cfg +3 -0
  346. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/CounterTieInGraph.tla +12 -0
  347. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/chart.mmd +23 -0
  348. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/graph.dot +19 -0
  349. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/report.md +11 -0
  350. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/sany.out +2 -0
  351. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/verdict-1.exit +1 -0
  352. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/verdict-1.out +56 -0
  353. package/skills/statechart/scripts/test/corpus/CounterTieInGraph/verdict-2.out +57 -0
  354. package/skills/statechart/scripts/test/corpus/CounterView/ChartRun.out +61 -0
  355. package/skills/statechart/scripts/test/corpus/CounterView/CounterView.cfg +4 -0
  356. package/skills/statechart/scripts/test/corpus/CounterView/CounterView.tla +14 -0
  357. package/skills/statechart/scripts/test/corpus/CounterView/chart.mmd +23 -0
  358. package/skills/statechart/scripts/test/corpus/CounterView/graph.dot +19 -0
  359. package/skills/statechart/scripts/test/corpus/CounterView/report.md +27 -0
  360. package/skills/statechart/scripts/test/corpus/CounterView/sany.out +2 -0
  361. package/skills/statechart/scripts/test/corpus/CounterView/verdict-1.exit +1 -0
  362. package/skills/statechart/scripts/test/corpus/CounterView/verdict-1.out +56 -0
  363. package/skills/statechart/scripts/test/corpus/CounterView/verdict-2.exit +1 -0
  364. package/skills/statechart/scripts/test/corpus/CounterView/verdict-2.out +64 -0
  365. package/skills/statechart/scripts/test/corpus/CounterView/verdict-3.exit +1 -0
  366. package/skills/statechart/scripts/test/corpus/CounterView/verdict-3.out +87 -0
  367. package/skills/statechart/scripts/test/corpus/CounterView/verdict-4.out +57 -0
  368. package/skills/statechart/scripts/test/corpus/CounterView/view.mjs +1 -0
  369. package/skills/statechart/scripts/test/corpus/DieHard/ChartRun.out +59 -0
  370. package/skills/statechart/scripts/test/corpus/DieHard/DieHard.cfg +4 -0
  371. package/skills/statechart/scripts/test/corpus/DieHard/DieHard.tla +38 -0
  372. package/skills/statechart/scripts/test/corpus/DieHard/chart.mmd +92 -0
  373. package/skills/statechart/scripts/test/corpus/DieHard/graph.dot +126 -0
  374. package/skills/statechart/scripts/test/corpus/DieHard/report.md +17 -0
  375. package/skills/statechart/scripts/test/corpus/DieHard/sany.out +2 -0
  376. package/skills/statechart/scripts/test/corpus/DieHard/verdict-1.exit +1 -0
  377. package/skills/statechart/scripts/test/corpus/DieHard/verdict-1.out +91 -0
  378. package/skills/statechart/scripts/test/corpus/DieHard/verdict-2.out +57 -0
  379. package/skills/statechart/scripts/test/corpus/FirstRule/ChartRun.out +61 -0
  380. package/skills/statechart/scripts/test/corpus/FirstRule/FirstRule.cfg +6 -0
  381. package/skills/statechart/scripts/test/corpus/FirstRule/FirstRule.tla +11 -0
  382. package/skills/statechart/scripts/test/corpus/FirstRule/chart.mmd +22 -0
  383. package/skills/statechart/scripts/test/corpus/FirstRule/graph.dot +16 -0
  384. package/skills/statechart/scripts/test/corpus/FirstRule/report.md +25 -0
  385. package/skills/statechart/scripts/test/corpus/FirstRule/sany.out +2 -0
  386. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-1.exit +1 -0
  387. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-1.out +56 -0
  388. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-2.exit +1 -0
  389. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-2.out +64 -0
  390. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-3.exit +1 -0
  391. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-3.out +64 -0
  392. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-4.exit +1 -0
  393. package/skills/statechart/scripts/test/corpus/FirstRule/verdict-4.out +77 -0
  394. package/skills/statechart/scripts/test/corpus/HiddenClock/ChartRun.out +57 -0
  395. package/skills/statechart/scripts/test/corpus/HiddenClock/HiddenClock.cfg +4 -0
  396. package/skills/statechart/scripts/test/corpus/HiddenClock/HiddenClock.tla +11 -0
  397. package/skills/statechart/scripts/test/corpus/HiddenClock/chart.mmd +13 -0
  398. package/skills/statechart/scripts/test/corpus/HiddenClock/graph.dot +12 -0
  399. package/skills/statechart/scripts/test/corpus/HiddenClock/report.md +11 -0
  400. package/skills/statechart/scripts/test/corpus/HiddenClock/sany.out +2 -0
  401. package/skills/statechart/scripts/test/corpus/HiddenClock/verdict-1.exit +1 -0
  402. package/skills/statechart/scripts/test/corpus/HiddenClock/verdict-1.out +72 -0
  403. package/skills/statechart/scripts/test/corpus/Login/ChartRun.out +57 -0
  404. package/skills/statechart/scripts/test/corpus/Login/Login.cfg +3 -0
  405. package/skills/statechart/scripts/test/corpus/Login/Login.tla +62 -0
  406. package/skills/statechart/scripts/test/corpus/Login/chart.mmd +28 -0
  407. package/skills/statechart/scripts/test/corpus/Login/graph.dot +40 -0
  408. package/skills/statechart/scripts/test/corpus/Login/report.md +7 -0
  409. package/skills/statechart/scripts/test/corpus/Login/sany.out +1 -0
  410. package/skills/statechart/scripts/test/corpus/Login/verdict-1.out +47 -0
  411. package/skills/statechart/scripts/test/corpus/Login/view.mjs +1 -0
  412. package/skills/statechart/scripts/test/corpus/LoginGuarded/ChartRun.out +57 -0
  413. package/skills/statechart/scripts/test/corpus/LoginGuarded/LoginGuarded.cfg +2 -0
  414. package/skills/statechart/scripts/test/corpus/LoginGuarded/LoginGuarded.tla +64 -0
  415. package/skills/statechart/scripts/test/corpus/LoginGuarded/chart.mmd +28 -0
  416. package/skills/statechart/scripts/test/corpus/LoginGuarded/graph.dot +37 -0
  417. package/skills/statechart/scripts/test/corpus/LoginGuarded/report.md +8 -0
  418. package/skills/statechart/scripts/test/corpus/LoginGuarded/sany.out +1 -0
  419. package/skills/statechart/scripts/test/corpus/LoginGuarded/verdict-1.out +47 -0
  420. package/skills/statechart/scripts/test/corpus/LoginGuarded/view.mjs +1 -0
  421. package/skills/statechart/scripts/test/corpus/LoginParallel/ChartRun.out +60 -0
  422. package/skills/statechart/scripts/test/corpus/LoginParallel/LoginParallel.cfg +3 -0
  423. package/skills/statechart/scripts/test/corpus/LoginParallel/LoginParallel.tla +64 -0
  424. package/skills/statechart/scripts/test/corpus/LoginParallel/chart.mmd +44 -0
  425. package/skills/statechart/scripts/test/corpus/LoginParallel/graph.dot +58 -0
  426. package/skills/statechart/scripts/test/corpus/LoginParallel/report.md +17 -0
  427. package/skills/statechart/scripts/test/corpus/LoginParallel/sany.out +1 -0
  428. package/skills/statechart/scripts/test/corpus/LoginParallel/verdict-1.exit +1 -0
  429. package/skills/statechart/scripts/test/corpus/LoginParallel/verdict-1.out +83 -0
  430. package/skills/statechart/scripts/test/corpus/LoginParallel/verdict-2.out +57 -0
  431. package/skills/statechart/scripts/test/corpus/LoginParallel/view.mjs +1 -0
  432. package/skills/statechart/scripts/test/corpus/MediaPlayer/ChartRun.out +60 -0
  433. package/skills/statechart/scripts/test/corpus/MediaPlayer/MediaPlayer.cfg +3 -0
  434. package/skills/statechart/scripts/test/corpus/MediaPlayer/MediaPlayer.tla +103 -0
  435. package/skills/statechart/scripts/test/corpus/MediaPlayer/chart.mmd +43 -0
  436. package/skills/statechart/scripts/test/corpus/MediaPlayer/graph.dot +93 -0
  437. package/skills/statechart/scripts/test/corpus/MediaPlayer/report.md +14 -0
  438. package/skills/statechart/scripts/test/corpus/MediaPlayer/sany.out +1 -0
  439. package/skills/statechart/scripts/test/corpus/MediaPlayer/verdict-1.exit +1 -0
  440. package/skills/statechart/scripts/test/corpus/MediaPlayer/verdict-1.out +59 -0
  441. package/skills/statechart/scripts/test/corpus/MediaPlayer/verdict-2.out +72 -0
  442. package/skills/statechart/scripts/test/corpus/MediaPlayer/view.mjs +3 -0
  443. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/ChartRun.out +57 -0
  444. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/MediaPlayerFixed.cfg +2 -0
  445. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/MediaPlayerFixed.tla +100 -0
  446. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/chart.mmd +31 -0
  447. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/graph.dot +85 -0
  448. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/report.md +9 -0
  449. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/sany.out +1 -0
  450. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/verdict-1.out +47 -0
  451. package/skills/statechart/scripts/test/corpus/MediaPlayerFixed/view.mjs +3 -0
  452. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/ChartRun.out +59 -0
  453. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/MediaPlayer.tla +103 -0
  454. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/MediaPlayerProps.cfg +3 -0
  455. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/MediaPlayerProps.tla +6 -0
  456. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/chart.mmd +42 -0
  457. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/graph.dot +93 -0
  458. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/report.md +19 -0
  459. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/sany.out +2 -0
  460. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-1.exit +1 -0
  461. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-1.out +61 -0
  462. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-2.out +59 -0
  463. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-3.out +61 -0
  464. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-4.exit +1 -0
  465. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-4.out +66 -0
  466. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-5.exit +1 -0
  467. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-5.out +58 -0
  468. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/verdict-6.out +49 -0
  469. package/skills/statechart/scripts/test/corpus/MediaPlayerProps/view.mjs +3 -0
  470. package/skills/statechart/scripts/test/corpus/PickWorker/ChartRun.out +57 -0
  471. package/skills/statechart/scripts/test/corpus/PickWorker/PickWorker.cfg +6 -0
  472. package/skills/statechart/scripts/test/corpus/PickWorker/PickWorker.tla +11 -0
  473. package/skills/statechart/scripts/test/corpus/PickWorker/chart.mmd +5 -0
  474. package/skills/statechart/scripts/test/corpus/PickWorker/graph.dot +11 -0
  475. package/skills/statechart/scripts/test/corpus/PickWorker/report.md +7 -0
  476. package/skills/statechart/scripts/test/corpus/PickWorker/sany.out +5 -0
  477. package/skills/statechart/scripts/test/corpus/PickWorker/verdict-1.out +70 -0
  478. package/skills/statechart/scripts/test/corpus/Shadow/ChartRun.out +61 -0
  479. package/skills/statechart/scripts/test/corpus/Shadow/Shadow.cfg +4 -0
  480. package/skills/statechart/scripts/test/corpus/Shadow/Shadow.tla +11 -0
  481. package/skills/statechart/scripts/test/corpus/Shadow/ShadowLib.tla +6 -0
  482. package/skills/statechart/scripts/test/corpus/Shadow/ShadowSub.tla +3 -0
  483. package/skills/statechart/scripts/test/corpus/Shadow/chart.mmd +9 -0
  484. package/skills/statechart/scripts/test/corpus/Shadow/graph.dot +16 -0
  485. package/skills/statechart/scripts/test/corpus/Shadow/report.md +8 -0
  486. package/skills/statechart/scripts/test/corpus/Shadow/sany.out +4 -0
  487. package/skills/statechart/scripts/test/corpus/Shadow/verdict-1.out +65 -0
  488. package/skills/statechart/scripts/test/corpus/SpacedNames/ChartRun.out +59 -0
  489. package/skills/statechart/scripts/test/corpus/SpacedNames/SpacedNames.cfg +2 -0
  490. package/skills/statechart/scripts/test/corpus/SpacedNames/SpacedNames.tla +9 -0
  491. package/skills/statechart/scripts/test/corpus/SpacedNames/chart.mmd +23 -0
  492. package/skills/statechart/scripts/test/corpus/SpacedNames/graph.dot +17 -0
  493. package/skills/statechart/scripts/test/corpus/SpacedNames/report.md +15 -0
  494. package/skills/statechart/scripts/test/corpus/SpacedNames/sany.out +1 -0
  495. package/skills/statechart/scripts/test/corpus/SpacedNames/verdict-1.exit +1 -0
  496. package/skills/statechart/scripts/test/corpus/SpacedNames/verdict-1.out +65 -0
  497. package/skills/statechart/scripts/test/corpus/SpacedNames/verdict-2.exit +1 -0
  498. package/skills/statechart/scripts/test/corpus/SpacedNames/verdict-2.out +75 -0
  499. package/skills/statechart/scripts/test/corpus/TwoPhase/ChartRun.out +69 -0
  500. package/skills/statechart/scripts/test/corpus/TwoPhase/TwoPhase.cfg +3 -0
  501. package/skills/statechart/scripts/test/corpus/TwoPhase/TwoPhase.tla +75 -0
  502. package/skills/statechart/scripts/test/corpus/TwoPhase/chart.mmd +60 -0
  503. package/skills/statechart/scripts/test/corpus/TwoPhase/graph.dot +297 -0
  504. package/skills/statechart/scripts/test/corpus/TwoPhase/report.md +20 -0
  505. package/skills/statechart/scripts/test/corpus/TwoPhase/sany.out +1 -0
  506. package/skills/statechart/scripts/test/corpus/TwoPhase/verdict-1.exit +1 -0
  507. package/skills/statechart/scripts/test/corpus/TwoPhase/verdict-1.out +95 -0
  508. package/skills/statechart/scripts/test/corpus/TwoPhase/verdict-2.out +57 -0
  509. package/skills/statechart/scripts/test/corpus/TwoPhase/view.mjs +1 -0
  510. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/ChartRun.out +57 -0
  511. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/TwoPhaseFixed.cfg +3 -0
  512. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/TwoPhaseFixed.tla +75 -0
  513. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/chart.mmd +37 -0
  514. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/graph.dot +223 -0
  515. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/report.md +11 -0
  516. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/sany.out +1 -0
  517. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/verdict-1.out +47 -0
  518. package/skills/statechart/scripts/test/corpus/TwoPhaseFixed/view.mjs +1 -0
  519. package/skills/statechart/scripts/test/corpus/TypeGuard/ChartRun.exit +1 -0
  520. package/skills/statechart/scripts/test/corpus/TypeGuard/ChartRun.out +75 -0
  521. package/skills/statechart/scripts/test/corpus/TypeGuard/TypeGuard.cfg +5 -0
  522. package/skills/statechart/scripts/test/corpus/TypeGuard/TypeGuard.tla +11 -0
  523. package/skills/statechart/scripts/test/corpus/TypeGuard/chart.mmd +18 -0
  524. package/skills/statechart/scripts/test/corpus/TypeGuard/graph.dot +14 -0
  525. package/skills/statechart/scripts/test/corpus/TypeGuard/report.md +29 -0
  526. package/skills/statechart/scripts/test/corpus/TypeGuard/sany.out +2 -0
  527. package/skills/statechart/scripts/test/corpus/TypeGuard/verdict-1.exit +1 -0
  528. package/skills/statechart/scripts/test/corpus/TypeGuard/verdict-1.out +64 -0
  529. package/skills/statechart/scripts/test/corpus/TypeGuard/verdict-2.exit +1 -0
  530. package/skills/statechart/scripts/test/corpus/TypeGuard/verdict-2.out +75 -0
  531. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/ChartRun.out +58 -0
  532. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/UserNoDeadlock.cfg +2 -0
  533. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/UserNoDeadlock.tla +8 -0
  534. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/chart.mmd +22 -0
  535. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/graph.dot +16 -0
  536. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/report.md +15 -0
  537. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/sany.out +2 -0
  538. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/verdict-1.exit +1 -0
  539. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/verdict-1.out +56 -0
  540. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/verdict-2.exit +1 -0
  541. package/skills/statechart/scripts/test/corpus/UserNoDeadlock/verdict-2.out +77 -0
  542. package/skills/statechart/scripts/test/corpus.test.ts +441 -0
  543. package/skills/statechart/scripts/test/differential.test.ts +565 -0
  544. package/skills/statechart/scripts/test/drawn.ts +20 -0
  545. package/skills/statechart/scripts/test/grid/Grid.cfg +2 -0
  546. package/skills/statechart/scripts/test/grid/Grid.tla +9 -0
  547. package/skills/statechart/scripts/test/grid/sany.out +2 -0
  548. package/skills/statechart/scripts/test/java.ts +63 -0
  549. package/skills/statechart/scripts/test/labels.ts +648 -0
  550. package/skills/statechart/scripts/test/messages.test.ts +212 -0
  551. package/skills/statechart/scripts/test/pipeline.test.ts +270 -0
  552. package/skills/statechart/scripts/test/plain-tlc.test.ts +255 -0
  553. package/skills/statechart/scripts/test/render.test.ts +145 -0
  554. package/skills/statechart/scripts/test/tlc-out.test.ts +90 -0
  555. package/skills/statechart/scripts/test/tlc.ts +158 -0
  556. package/skills/statechart/scripts/tsconfig.json +11 -0
  557. package/skills/statechart/scripts/worker.ts +35 -0
  558. package/skills/swarm/SKILL.md +41 -0
  559. package/skills/tdd/SKILL.md +42 -0
  560. package/skills/teach/SKILL.md +23 -0
  561. package/skills/technical-writing/SKILL.md +106 -0
  562. package/skills/thermo-nuclear-code-quality-review/SKILL.md +192 -0
  563. package/skills/typescript-best-practices/SKILL.md +32 -0
  564. package/skills/typescript-best-practices/references/patterns.md +328 -0
  565. package/skills/unslop/SKILL.md +62 -0
  566. package/skills/verify-this/SKILL.md +74 -0
  567. package/skills/weekly-review/SKILL.md +32 -0
  568. package/skills/what-did-i-get-done/SKILL.md +31 -0
  569. package/skills/why/SKILL.md +9 -0
  570. package/skills/workflow-from-chats/SKILL.md +50 -0
  571. package/src/credentials.ts +156 -0
  572. package/src/index.ts +663 -0
  573. package/src/jobs.ts +436 -0
  574. package/src/sandbox.ts +232 -0
  575. package/src/sweep.ts +132 -0
  576. package/src/transcript.ts +66 -0
package/src/jobs.ts ADDED
@@ -0,0 +1,436 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { createHash, randomBytes } from 'node:crypto';
3
+ import { closeSync, copyFileSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, statSync, writeFileSync } from 'node:fs';
4
+ import { basename, dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import { jobAgentDir } from './credentials.ts';
8
+ import { JOB_DIR_ENV, SANDBOX_ENV, type SandboxPolicy, TOP_DIR_ENV } from './sandbox.ts';
9
+ import { type Inventory, inventory, inventoryFile } from './sweep.ts';
10
+
11
+ const sweepSource = fileURLToPath(new URL('./sweep.ts', import.meta.url));
12
+
13
+ export type JobKind = 'pi' | 'command';
14
+
15
+ export interface JobSpec {
16
+ id: string;
17
+ name: string;
18
+ kind: JobKind;
19
+ cwd: string;
20
+ /** What tmux runs: the command wrapped in its sandbox. Empty for a brokered request until the root launches it. */
21
+ argv: string[];
22
+ /** The command before sandboxing, and the policy it asked for. A broker launches from these after clamping the policy. */
23
+ command: string[];
24
+ policy: SandboxPolicy;
25
+ /**
26
+ * Launched by the root Pi on a sandboxed worker's behalf, because macOS cannot nest Seatbelt profiles. The worker cannot
27
+ * reach the root's tmux server, so it reads the job's state from files only.
28
+ */
29
+ brokered: boolean;
30
+ /**
31
+ * Where the job's output, exit code, and launch markers live. It is the job directory itself, except for a brokered job,
32
+ * whose results the root writes under the top-level job, where no worker can plant a link for the root to write through.
33
+ */
34
+ out: string;
35
+ /** Session id of the Pi process that owns the job and receives its wake message. */
36
+ owner: string;
37
+ /** Message delivered to the owner when the job exits. Null means the owner is not woken. */
38
+ wake: string | null;
39
+ /** Relaunch the same job each time it exits cleanly, as a heartbeat. */
40
+ repeat: boolean;
41
+ /** Id of the first job in a repeat series. Stopping any job in the series stops the series. */
42
+ series: string;
43
+ /** Path of the tmux server socket the job runs under. Empty for a brokered request. */
44
+ socket: string;
45
+ /** Protected paths and checkout roots the wrapper sweeps after the job, for code that appeared while it ran. */
46
+ sweep: { roots: string[]; protect: string[] };
47
+ /** The $TMPDIR of the worker that started this job, shared so paths it hands the job exist. Unset for a top-level job. */
48
+ tmp?: string;
49
+ createdAt: string;
50
+ }
51
+
52
+ export type JobStatus = { state: 'running' } | { state: 'exited'; code: number } | { state: 'lost' };
53
+
54
+ export interface Job {
55
+ spec: JobSpec;
56
+ dir: string;
57
+ status: JobStatus;
58
+ }
59
+
60
+ export const STOPPED_EXIT_CODE = 143;
61
+
62
+ const shellQuote = (word: string): string => `'${word.replaceAll("'", "'\\''")}'`;
63
+ const hash = (text: string): string => createHash('sha256').update(text).digest('hex').slice(0, 16);
64
+
65
+ export const jobDir = (root: string, id: string): string => join(root, id);
66
+ export const outputPath = (out: string): string => join(out, 'output.log');
67
+ export const exitPath = (out: string): string => join(out, 'exit');
68
+ /** Where the root writes a brokered job's results: under the top-level job, which every descendant can read and none can write. */
69
+ export const resultsDir = (top: string, dir: string): string => join(top, 'brokered', hash(dir));
70
+ /** The tmux session a brokered job runs as on the root's server, named from its directory so a worker cannot pick another job's name. */
71
+ export const brokeredSession = (dir: string): string => `brokered-${hash(dir)}`;
72
+
73
+ export function newJobId(name: string): string {
74
+ const slug = name
75
+ .toLowerCase()
76
+ .replace(/[^a-z0-9]+/g, '-')
77
+ .replace(/^-|-$/g, '')
78
+ .slice(0, 24);
79
+ return `${slug || 'job'}-${randomBytes(3).toString('hex')}`;
80
+ }
81
+
82
+ /**
83
+ * One tmux server per owning session, started with that session's environment so jobs inherit PATH and credentials.
84
+ * Its socket sits where sandboxed jobs cannot connect, since the server runs whatever it is sent outside the sandbox.
85
+ */
86
+ export function tmuxSocket(owner: string): string {
87
+ const uid = process.getuid?.() ?? 0;
88
+ const dir = `/tmp/pstack-v2-${uid}`;
89
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
90
+ // Another local user could create this directory first and serve a socket of their own in it.
91
+ const stat = lstatSync(dir);
92
+ if (!stat.isDirectory() || stat.uid !== uid || (stat.mode & 0o077) !== 0) throw new Error(`${dir} must be a directory owned by you with mode 700.`);
93
+ return join(dir, `${hash(owner)}.sock`);
94
+ }
95
+
96
+ // tmux reaches the socket through a relative path from its directory, so a deeply nested socket stays under the
97
+ // 104 to 108 byte limit on Unix socket paths.
98
+ function tmux(socket: string, args: string[]): void {
99
+ const env = { ...process.env };
100
+ delete env['TMUX'];
101
+ delete env['TMUX_PANE'];
102
+ try {
103
+ execFileSync('tmux', ['-S', basename(socket), ...args], { stdio: 'ignore', env, cwd: dirname(socket) });
104
+ } catch (error) {
105
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') throw new Error('pstack needs tmux to run jobs and found none on PATH. Install tmux and try again.');
106
+ throw error;
107
+ }
108
+ }
109
+
110
+ function write(dir: string, spec: JobSpec, files: Record<string, string>): void {
111
+ mkdirSync(join(dir, 'tmp'), { recursive: true });
112
+ writeFileSync(join(dir, 'job.json'), `${JSON.stringify(spec, null, 2)}\n`);
113
+ for (const [name, content] of Object.entries(files)) writeFileSync(join(dir, name), content);
114
+ }
115
+
116
+ /** Package caches in a job's temp directory, deleted when it exits. One job's installs can fill hundreds of megabytes. */
117
+ const CACHES: Record<string, string> = {
118
+ XDG_CACHE_HOME: 'cache',
119
+ npm_config_cache: 'npm',
120
+ BUN_INSTALL_CACHE_DIR: 'bun',
121
+ PIP_CACHE_DIR: 'pip',
122
+ UV_CACHE_DIR: 'uv',
123
+ GOCACHE: 'go-build',
124
+ GOMODCACHE: 'go-mod',
125
+ YARN_CACHE_FOLDER: 'yarn',
126
+ DENO_DIR: 'deno',
127
+ GRADLE_USER_HOME: 'gradle',
128
+ npm_config_store_dir: 'pnpm',
129
+ };
130
+
131
+ // zsh writes here-documents under TMPPREFIX, which defaults to the shared /tmp.
132
+ const tempEnv = (tmp: string): Record<string, string> => ({ TMPDIR: tmp, TMP: tmp, TEMP: tmp, MAC_CHROMIUM_TMPDIR: tmp, TMPPREFIX: join(tmp, 'zsh') });
133
+
134
+ /** macOS mktemp prefers the per-user temp directory to $TMPDIR, and a job may not write there, so jobs find this one first on PATH. */
135
+ const MKTEMP = `#!/bin/sh
136
+ flags=
137
+ prefix=
138
+ while getopts :dqut:p: opt; do
139
+ case $opt in
140
+ d|q|u) flags="$flags -$opt" ;;
141
+ t) prefix=$OPTARG ;;
142
+ *) exec /usr/bin/mktemp "$@" ;;
143
+ esac
144
+ done
145
+ shift $((OPTIND - 1))
146
+ [ $# -gt 0 ] && [ -z "$prefix" ] && exec /usr/bin/mktemp $flags "$@"
147
+ exec /usr/bin/mktemp $flags "\${TMPDIR%/}/\${prefix:-tmp}.XXXXXXXXXX"
148
+ `;
149
+
150
+ /**
151
+ * A private temp directory and caches for the job. Shared temp directories and user caches hold code that unsandboxed
152
+ * programs later load, such as Pi's compiled-extension cache, so a job may write none of them.
153
+ */
154
+ export const privateEnv = (tmp: string): Record<string, string> => ({
155
+ ...tempEnv(tmp),
156
+ ...Object.fromEntries(Object.entries(CACHES).map(([name, dir]) => [name, join(tmp, dir)])),
157
+ });
158
+
159
+ /**
160
+ * Firefox and pnpm run their own sandbox or store-locking steps, which fail inside the job's sandbox. Firefox aborts when it
161
+ * cannot sandbox its child processes, and pnpm cannot lock the shared store it switches engines from.
162
+ */
163
+ const SANDBOX_COMPAT: Record<string, string> = {
164
+ ...Object.fromEntries(['CONTENT', 'GMP', 'RDD', 'SOCKET_PROCESS', 'GPU', 'UTILITY'].map((name) => [`MOZ_DISABLE_${name}_SANDBOX`, '1'])),
165
+ npm_config_manage_package_manager_versions: 'false',
166
+ };
167
+
168
+ interface Run {
169
+ kind: JobKind;
170
+ cwd: string;
171
+ argv: string[];
172
+ inventory: Inventory;
173
+ socket: string;
174
+ session: string;
175
+ /** The job's own directory, exported to it as its job directory. */
176
+ dir: string;
177
+ /** Where output and the exit code go. */
178
+ out: string;
179
+ top: string;
180
+ tmp: string | undefined;
181
+ }
182
+
183
+ /**
184
+ * Starts the wrapper that runs argv, captures its output, quarantines what it should not have created, and records its
185
+ * exit code. The job runs in its own process group while the wrapper waits on it, so when `tmux_jobs stop` hangs the
186
+ * session up, the trap fires at once. Bash would defer a trap until a foreground command finished. On every exit path the
187
+ * whole group is killed before cleanup, so no child the job left behind can act after it, and a job that ignores TERM
188
+ * gets KILL after a short grace period.
189
+ */
190
+ function run(job: Run): void {
191
+ // Pi's own variable points every job at its top-level job's agent directory, so no job's Pi writes your real credentials.
192
+ const env = Object.entries({
193
+ [SANDBOX_ENV]: '1',
194
+ [JOB_DIR_ENV]: job.dir,
195
+ [TOP_DIR_ENV]: job.top,
196
+ PI_CODING_AGENT_DIR: jobAgentDir(job.top),
197
+ ...SANDBOX_COMPAT,
198
+ ...privateEnv(join(job.dir, 'tmp')),
199
+ ...(job.tmp ? tempEnv(job.tmp) : {}),
200
+ })
201
+ .map(([name, value]) => `${name}=${shellQuote(value)}`)
202
+ .join(' ');
203
+ // The job cannot write its results directory, so it cannot replace what it finds there on PATH.
204
+ const bin = join(job.out, 'bin');
205
+ if (process.platform === 'darwin') {
206
+ mkdirSync(bin, { recursive: true });
207
+ writeFileSync(join(bin, 'mktemp'), MKTEMP, { mode: 0o755 });
208
+ }
209
+ const path = process.platform === 'darwin' ? `PATH=${shellQuote(bin)}:"$PATH" ` : '';
210
+ const command = `${path}${env} ${job.argv.map(shellQuote).join(' ')} < /dev/null`;
211
+ const out = shellQuote(outputPath(job.out));
212
+ const exit = shellQuote(exitPath(job.out));
213
+ // Output goes straight to its file, not through a pipe, so a child the job leaves running cannot hold the job open.
214
+ const body = job.kind === 'pi' ? `${command} > ${out} 2> ${shellQuote(join(job.out, 'stderr.log'))}` : `${command} > ${out} 2>&1`;
215
+ // Node refuses to strip types from a file under node_modules, where an npm install keeps this one. The copy sits in the
216
+ // job's results directory, which the job cannot write.
217
+ const sweepCopy = join(job.out, 'sweep.ts');
218
+ const caches = Object.values(CACHES)
219
+ .map((dir) => shellQuote(join(job.dir, 'tmp', dir)))
220
+ .join(' ');
221
+ const script = [
222
+ 'set -m',
223
+ `echo $$ > ${shellQuote(join(job.out, 'wrapper.pid'))}`,
224
+ 'finished=0',
225
+ 'finish() {',
226
+ ' [ "$finished" = 1 ] && return',
227
+ ' finished=1',
228
+ ' kill -KILL -- -$pid 2>/dev/null; wait $pid 2>/dev/null',
229
+ ' kill $mirror 2>/dev/null',
230
+ // Off the terminal: once tmux is gone, Node reopening the terminal to report an error blocks forever and holds a pty.
231
+ ` ${shellQuote(process.execPath)} ${shellQuote(sweepCopy)} ${shellQuote(inventoryFile(job.out))} < /dev/null >> ${out} 2>&1`,
232
+ // Go leaves its module cache read-only. find never follows a link the job planted, so only the job's own directories change.
233
+ ` find ${caches} -type d ! -perm -u+w -exec chmod u+w {} + 2>/dev/null; rm -rf ${caches}`,
234
+ ` echo "$1" > ${exit}.tmp && mv ${exit}.tmp ${exit}`,
235
+ '}',
236
+ `trap 'kill -TERM -- -$pid 2>/dev/null; for i in $(seq 30); do kill -0 -- -$pid 2>/dev/null || break; sleep 0.1; done; finish ${STOPPED_EXIT_CODE}; exit ${STOPPED_EXIT_CODE}' HUP TERM INT`,
237
+ `${body} &`,
238
+ 'pid=$!',
239
+ // The session's pane shows the output as it is written, so attaching to it is a live view of the job.
240
+ `tail -n +1 -f ${job.kind === 'pi' ? `${out} ${shellQuote(join(job.out, 'stderr.log'))}` : out} 2>/dev/null &`,
241
+ 'mirror=$!',
242
+ 'wait $pid',
243
+ 'finish "$?"',
244
+ ].join('\n');
245
+ // The script lives beside the job's results, where only the process that launched it can write, and runs from there,
246
+ // since a long list of protected paths would not fit on a tmux command line.
247
+ const file = join(job.out, 'wrapper.sh');
248
+ writeFileSync(inventoryFile(job.out), JSON.stringify(job.inventory));
249
+ copyFileSync(sweepSource, sweepCopy);
250
+ writeFileSync(file, `${script}\n`);
251
+ tmux(job.socket, ['new-session', '-d', '-s', job.session, '-c', job.cwd, 'bash', file]);
252
+ }
253
+
254
+ const takeInventory = (spec: JobSpec, out: string): Inventory => inventory(spec.sweep.roots, spec.sweep.protect, join(out, 'quarantine'), outputPath(out));
255
+
256
+ const inheritedTop = (dir: string): string => (process.env[SANDBOX_ENV] === '1' ? (process.env[TOP_DIR_ENV] ?? dir) : dir);
257
+
258
+ /** Creates the job directory, writes its spec, and starts it in a detached tmux session. */
259
+ export function launch(root: string, spec: JobSpec, files: Record<string, string> = {}): Job {
260
+ const dir = jobDir(root, spec.id);
261
+ const full = { ...spec, out: dir };
262
+ write(dir, full, files);
263
+ run({ kind: spec.kind, cwd: spec.cwd, argv: spec.argv, inventory: takeInventory(spec, dir), socket: spec.socket, session: spec.id, dir, out: dir, top: inheritedTop(dir), tmp: spec.tmp });
264
+ return { spec: full, dir, status: { state: 'running' } };
265
+ }
266
+
267
+ /** Writes a job for the root Pi to launch, from inside a macOS sandbox that cannot start a narrower one itself. */
268
+ export function request(root: string, spec: JobSpec, files: Record<string, string> = {}): Job {
269
+ const dir = jobDir(root, spec.id);
270
+ const top = process.env[TOP_DIR_ENV];
271
+ if (!top) throw new Error('A sandboxed worker needs its top-level job directory to request a job.');
272
+ const full = { ...spec, argv: [], socket: '', brokered: true, out: resultsDir(top, dir) };
273
+ write(dir, full, files);
274
+ return { spec: full, dir, status: { state: 'running' } };
275
+ }
276
+
277
+ /** Records a brokered job's result in its root-owned results directory, for a launch the root refused or could not start. */
278
+ export function settleBrokered(out: string, code: number, message: string): void {
279
+ mkdirSync(out, { recursive: true });
280
+ writeFileSync(outputPath(out), `${message}\n`);
281
+ writeFileSync(join(out, 'launched'), '');
282
+ writeFileSync(exitPath(out), `${code}\n`);
283
+ }
284
+
285
+ /** Launches a brokered request on the root's tmux server. The caller has already sandboxed argv under a policy it clamped. */
286
+ export function launchBrokered(top: string, dir: string, spec: JobSpec, sweepWhat: JobSpec['sweep'], argv: string[], socket: string): void {
287
+ const out = resultsDir(top, dir);
288
+ mkdirSync(out, { recursive: true });
289
+ try {
290
+ run({ kind: spec.kind, cwd: spec.cwd, argv, inventory: takeInventory({ ...spec, sweep: sweepWhat }, out), socket, session: brokeredSession(dir), dir, out, top, tmp: spec.tmp });
291
+ writeFileSync(join(out, 'launched'), '');
292
+ } catch (error) {
293
+ settleBrokered(out, 127, `pstack could not launch this job: ${error instanceof Error ? error.message : String(error)}`);
294
+ }
295
+ }
296
+
297
+ export function status(dir: string, spec: JobSpec): JobStatus {
298
+ const exit = exitPath(spec.out);
299
+ const exited = (): JobStatus | undefined => (existsSync(exit) ? { state: 'exited', code: Number(readFileSync(exit, 'utf8').trim()) } : undefined);
300
+ const before = exited();
301
+ if (before) return before;
302
+ if (spec.brokered) return existsSync(join(dir, 'stop')) ? { state: 'exited', code: STOPPED_EXIT_CODE } : { state: 'running' };
303
+ try {
304
+ tmux(spec.socket, ['has-session', '-t', `=${spec.id}`]);
305
+ return { state: 'running' };
306
+ } catch {
307
+ // The job may have written its exit code and closed its session between the two checks.
308
+ return exited() ?? { state: 'lost' };
309
+ }
310
+ }
311
+
312
+ export function readSpec(dir: string): JobSpec | undefined {
313
+ try {
314
+ return JSON.parse(readFileSync(join(dir, 'job.json'), 'utf8')) as JobSpec;
315
+ } catch {
316
+ return undefined;
317
+ }
318
+ }
319
+
320
+ /** Reads one of the owner's jobs. Another session's job reads as missing. */
321
+ export function read(root: string, id: string, owner: string): Job | undefined {
322
+ const dir = jobDir(root, id);
323
+ const spec = readSpec(dir);
324
+ return spec?.owner === owner ? { spec, dir, status: status(dir, spec) } : undefined;
325
+ }
326
+
327
+ export function list(root: string, owner: string): Job[] {
328
+ if (!existsSync(root)) return [];
329
+ return readdirSync(root)
330
+ .map((id) => read(root, id, owner))
331
+ .filter((job): job is Job => job !== undefined)
332
+ .sort((a, b) => a.spec.createdAt.localeCompare(b.spec.createdAt));
333
+ }
334
+
335
+ /**
336
+ * Ends a job. Hanging up its tmux session runs the wrapper's cleanup, and on Linux takes every process the job started
337
+ * with it. A brokered job is ended by the root, which sees the stop marker on its next tick.
338
+ */
339
+ export async function stop(job: Job): Promise<void> {
340
+ // Claimed first, since the session is gone before the wrapper records the exit, and the watcher would report the job lost.
341
+ claimWake(job);
342
+ if (job.spec.brokered) {
343
+ writeFileSync(join(job.dir, 'stop'), '');
344
+ } else {
345
+ try {
346
+ tmux(job.spec.socket, ['kill-session', '-t', `=${job.spec.id}`]);
347
+ } catch {
348
+ // Already gone.
349
+ }
350
+ // The wrapper records the exit once it has ended the job and cleaned up. Only a wrapper that is already gone, and so
351
+ // can never record it, leaves that to stop.
352
+ const exit = exitPath(job.spec.out);
353
+ const deadline = Date.now() + 6_000;
354
+ const wrapper = Number(readEnd(join(job.spec.out, 'wrapper.pid'), 32).trim());
355
+ const alive = (): boolean => {
356
+ try {
357
+ process.kill(wrapper, 0);
358
+ return wrapper > 0;
359
+ } catch {
360
+ return false;
361
+ }
362
+ };
363
+ // The wrapper keeps cleaning up after its session is gone, so waiting ends once it records the exit or is itself gone.
364
+ while (!existsSync(exit) && Date.now() < deadline && alive()) await new Promise((done) => setTimeout(done, 50));
365
+ if (!existsSync(exit)) {
366
+ writeFileSync(`${exit}.tmp`, `${STOPPED_EXIT_CODE}\n`);
367
+ renameSync(`${exit}.tmp`, exit);
368
+ }
369
+ }
370
+ }
371
+
372
+ /** Returns true exactly once per job, so a wake survives restarts without being delivered twice. */
373
+ export function claimWake(job: Job): boolean {
374
+ try {
375
+ writeFileSync(join(job.dir, 'woken'), '', { flag: 'wx' });
376
+ return true;
377
+ } catch {
378
+ return false;
379
+ }
380
+ }
381
+
382
+ function readRange(path: string, start: number, length: number): Buffer {
383
+ const buffer = Buffer.alloc(length);
384
+ const fd = openSync(path, 'r');
385
+ try {
386
+ readSync(fd, buffer, 0, length, start);
387
+ } finally {
388
+ closeSync(fd);
389
+ }
390
+ return buffer;
391
+ }
392
+
393
+ /** The end of a file, read without loading the whole of it, since a job's output can be very large. */
394
+ export function readEnd(path: string, bytes: number): string {
395
+ if (!existsSync(path)) return '';
396
+ const size = statSync(path).size;
397
+ const length = Math.min(size, bytes);
398
+ return readRange(path, size - length, length).toString('utf8');
399
+ }
400
+
401
+ const isContinuation = (byte: number | undefined): boolean => byte !== undefined && (byte & 0xc0) === 0x80;
402
+
403
+ /**
404
+ * The start and the end of a file with a note of how many bytes lie between, so a verdict on its first line survives a
405
+ * long output. Both cuts fall on character boundaries.
406
+ */
407
+ export function excerpt(path: string, head: number, tailBytes: number): string {
408
+ if (!existsSync(path)) return '';
409
+ const size = statSync(path).size;
410
+ if (size <= head + tailBytes) return readEnd(path, size);
411
+ return clipRanges(readRange(path, 0, head), readRange(path, size - tailBytes, tailBytes), size, path);
412
+ }
413
+
414
+ export function clip(text: string, head: number, tailBytes: number, source: string): string {
415
+ const buffer = Buffer.from(text);
416
+ if (buffer.length <= head + tailBytes) return text;
417
+ return clipRanges(buffer.subarray(0, head), buffer.subarray(buffer.length - tailBytes), buffer.length, source);
418
+ }
419
+
420
+ function clipRanges(first: Buffer, last: Buffer, size: number, path: string): string {
421
+ let lead = first.length - 1;
422
+ while (lead > 0 && isContinuation(first[lead])) lead--;
423
+ const byte = first[lead] ?? 0;
424
+ const end = lead + (byte >= 0xf0 ? 4 : byte >= 0xe0 ? 3 : byte >= 0xc0 ? 2 : 1) > first.length ? lead : first.length;
425
+ let from = 0;
426
+ while (isContinuation(last[from])) from++;
427
+ const omitted = size - end - (last.length - from);
428
+ return `${first.subarray(0, end).toString('utf8')}\n[... ${omitted} bytes omitted, full output at ${path} ...]\n${last.subarray(from).toString('utf8')}`;
429
+ }
430
+
431
+ export function tail(path: string, lines: number): string {
432
+ return readEnd(path, 256 * 1024)
433
+ .split('\n')
434
+ .slice(-lines)
435
+ .join('\n');
436
+ }
package/src/sandbox.ts ADDED
@@ -0,0 +1,232 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
3
+ import { basename, dirname, join } from 'node:path';
4
+
5
+ export const SANDBOX_ENV = 'PSTACK_V2_SANDBOXED';
6
+ /** The job directory of the sandboxed process. Jobs it asks the root to start are requested under its writable `nested/` directory. */
7
+ export const JOB_DIR_ENV = 'PSTACK_V2_JOB_DIR';
8
+ /** The directory of the top-level job a process descends from. Its `brokered/` directory holds what the root launched for descendants. */
9
+ export const TOP_DIR_ENV = 'PSTACK_V2_TOP_DIR';
10
+
11
+ export interface SandboxPolicy {
12
+ /** Paths the job may write. */
13
+ writable: string[];
14
+ /** Paths inside `writable` that stay read-only because an unsandboxed process would execute what they hold, such as git hooks. */
15
+ protect: string[];
16
+ /** Paths whose own entry may not be renamed, removed, or replaced, while writes inside them stay allowed, such as `.git`. */
17
+ lock: string[];
18
+ /** Git common directories the job may write. Every worktree and submodule redirection file under them stays read-only. */
19
+ gitDirs: string[];
20
+ /** Checkouts the job may write. No `.pi` code entry or `.git` entry anywhere in them may be written, even one that does not exist yet. */
21
+ checkouts: string[];
22
+ agentDir: string;
23
+ /**
24
+ * The job's own Pi agent directory, shared with every job its top-level job starts. Only the contents of its credentials
25
+ * copy and Pi's lock directories are writable, so no job can change what another job's Pi loads.
26
+ */
27
+ credentials: string;
28
+ /** The job's own directory. Jobs it asks the root to start are requested under its `nested/` directory. */
29
+ jobDir: string;
30
+ }
31
+
32
+ const real = (path: string): string => (existsSync(path) ? realpathSync(path) : path);
33
+ /** A path as the kernel sees it when the entry itself is the target: the real parent plus the entry's own name, links unresolved. */
34
+ const entry = (path: string): string => join(real(dirname(path)), basename(path));
35
+ const escapeRegex = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
36
+ const quote = (text: string): string => JSON.stringify(text);
37
+
38
+ // tmux servers outside the sandbox run commands unsandboxed, so a job may not connect to their sockets or replace them.
39
+ const TMUX_SOCKETS = '^/private/(tmp|var/folders/[^/]+/[^/]+/T)/(tmux|pstack-v2)-';
40
+ // Files through which git finds a worktree's or submodule's hooks and config.
41
+ const gitRedirects = (common: string): string => `^${escapeRegex(real(common))}/(config\\.worktree|worktrees/[^/]+/(commondir|gitdir|config\\.worktree)|modules/.+/(hooks|config|info|commondir|gitdir|config\\.worktree))(/|$)`;
42
+
43
+ /** The git directories of the linked worktrees the job works in, which it may write apart from their redirection files. */
44
+ const ownWorktrees = (policy: SandboxPolicy): string[] => policy.lock.filter((path) => policy.gitDirs.some((common) => dirname(path) === join(common, 'worktrees')));
45
+
46
+ /**
47
+ * bubblewrap can only make read-only what exists, so the git paths a job may not create are created first, empty. Git
48
+ * reads an empty `config.worktree` as no settings, and empty `hooks`, `info`, `worktrees`, and `modules` directories as none.
49
+ */
50
+ function placeholders(policy: SandboxPolicy): void {
51
+ for (const common of policy.gitDirs) {
52
+ if (!existsSync(common)) continue;
53
+ for (const name of ['hooks', 'info', 'worktrees', 'modules']) mkdirSync(join(common, name), { recursive: true });
54
+ for (const dir of [common, ...ownWorktrees(policy)]) if (existsSync(dir) && !existsSync(join(dir, 'config.worktree'))) writeFileSync(join(dir, 'config.worktree'), '');
55
+ }
56
+ }
57
+
58
+ export function seatbeltProfile(policy: SandboxPolicy): string {
59
+ const subpaths = (paths: string[]): string => paths.map((path) => `(subpath ${quote(real(path))})`).join(' ');
60
+ // A protected path that is itself a symlink is guarded at the link as well as at its target, so it cannot be swapped.
61
+ const guarded = [...policy.protect.map((path) => `(subpath ${quote(real(path))}) (literal ${quote(entry(path))})`), ...policy.lock.map((path) => `(literal ${quote(real(path))}) (literal ${quote(entry(path))})`)];
62
+ const inAgentDir = policy.writable.filter((path) => real(path) === real(policy.agentDir) || real(path).startsWith(`${real(policy.agentDir)}/`));
63
+ const lines = [
64
+ '(version 1)',
65
+ '(allow default)',
66
+ // Later rules win, so the order is the job's own paths, then Pi's agent directory closed even when a job path holds
67
+ // it, then the job's own paths inside it, then the paths an unsandboxed process would execute from. Shared temp
68
+ // directories are not writable: unsandboxed programs load code cached there, so each job gets its own.
69
+ '(deny file-write*)',
70
+ `(allow file-write* (literal "/dev/null") (literal "/dev/ptmx") (regex #"^/dev/tty") (regex #"^/dev/fd/") ${subpaths(policy.writable)})`,
71
+ `(deny file-write* (subpath ${quote(real(policy.agentDir))}))`,
72
+ // Inside Pi's agent directory only the job's own paths are writable, its session, nested jobs, temp, and its own agent
73
+ // directory with its credentials copy. Your real auth.json and settings are never writable.
74
+ ...(inAgentDir.length ? [`(allow file-write* ${subpaths(inAgentDir)})`] : []),
75
+ ...(policy.credentials ? [`(allow file-write-data (literal ${quote(join(real(policy.credentials), 'auth.json'))}))`, `(allow file-write* (regex #"^${escapeRegex(real(policy.credentials))}/[^/]+\\.lock(/|$)"))`] : []),
76
+ // A job may not add or change a worktree or submodule, apart from the metadata of the worktree it works in.
77
+ ...policy.gitDirs.map((common) => `(deny file-write* (subpath ${quote(real(join(common, 'worktrees')))}) (subpath ${quote(real(join(common, 'modules')))}))`),
78
+ ...(ownWorktrees(policy).length ? [`(allow file-write* ${subpaths(ownWorktrees(policy))})`] : []),
79
+ `(deny file-write* (regex #"${TMUX_SOCKETS}") ${guarded.join(' ')} ${policy.gitDirs.map((common) => `(regex #"${gitRedirects(common)}")`).join(' ')})`,
80
+ // Any .git a checkout gains is a repository git would run hooks from, apart from the checkout's own git directory.
81
+ ...policy.checkouts.map((root) => {
82
+ const git = existsSync(join(root, '.git')) && statSync(join(root, '.git')).isDirectory() ? '.+/\\.git' : '(.*/)?\\.git';
83
+ return `(deny file-write* (regex #"^${escapeRegex(real(root))}/(${git}|(.*/)?\\.pi/(extensions|settings\\.json|mcp\\.json|npm|git))(/|$)"))`;
84
+ }),
85
+ // Any local service socket could start a process outside the sandbox, such as Docker's, so only DNS is reachable.
86
+ '(deny network-outbound (remote unix-socket))',
87
+ '(allow network-outbound (remote unix-socket (path-literal "/private/var/run/mDNSResponder")))',
88
+ // Nor may it serve one, such as a tmux server of its own. Linux refuses the same through seccomp.
89
+ '(deny network-bind (local unix-socket))',
90
+ // Services that start processes on a caller's behalf would run them outside the sandbox: LaunchServices (`open`) and Apple Events.
91
+ // `open -a` on an app the job wrote launches it through launchd, so the lookup rules below cannot stop it, and lsopen does.
92
+ '(deny appleevent-send)',
93
+ '(deny lsopen)',
94
+ // A job may signal only processes in its own sandbox, never the wrapper that cleans up after it or the root Pi.
95
+ '(deny signal)',
96
+ '(allow signal (target same-sandbox))',
97
+ // launchservicesd stays reachable because Firefox checks in with it at startup and aborts without it. Opening goes through lsopen.
98
+ '(deny mach-lookup (global-name-regex #"^com\\.apple\\.lsd\\.") (global-name "com.apple.coreservices.appleevents"))',
99
+ // launchd would run a job it is handed outside the sandbox, and preference writes go through a daemon outside it.
100
+ '(deny mach-lookup (global-name-regex #"^com\\.apple\\.xpc\\.launchd\\."))',
101
+ '(deny user-preference-write)',
102
+ ];
103
+ return lines.join('\n');
104
+ }
105
+
106
+ /** Existing worktree and submodule redirection files under a git common directory, for bubblewrap, which can only bind what exists. */
107
+ function existingRedirects(common: string): string[] {
108
+ const found: string[] = [];
109
+ const worktrees = join(common, 'worktrees');
110
+ found.push(join(common, 'config.worktree'));
111
+ if (existsSync(worktrees)) for (const name of readdirSync(worktrees)) for (const file of ['commondir', 'gitdir', 'config.worktree']) found.push(join(worktrees, name, file));
112
+ const walk = (dir: string, depth: number): void => {
113
+ if (depth > 6 || !existsSync(dir)) return;
114
+ for (const name of readdirSync(dir)) {
115
+ const path = join(dir, name);
116
+ if (['hooks', 'config', 'info', 'commondir', 'gitdir', 'config.worktree'].includes(name)) found.push(path);
117
+ else if (statSync(path).isDirectory()) walk(path, depth + 1);
118
+ }
119
+ };
120
+ walk(join(common, 'modules'), 0);
121
+ return found.filter(existsSync);
122
+ }
123
+
124
+ export function bwrapArgs(policy: SandboxPolicy, env: NodeJS.ProcessEnv = process.env, uid: number = process.getuid?.() ?? 0): string[] {
125
+ // Its own PID namespace means every process a job starts dies with it, and none can signal the wrapper outside.
126
+ // A private /tmp, since unsandboxed programs load code they cached in the shared one. It also hides outside tmux sockets.
127
+ const args = ['--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--unshare-pid', '--tmpfs', '/tmp'];
128
+ // Pi's agent directory stays visible, read-only, even when it sits under the private /tmp.
129
+ if (existsSync(policy.agentDir)) args.push('--ro-bind', policy.agentDir, policy.agentDir);
130
+ const writable = policy.writable.filter(existsSync);
131
+ for (const path of writable) args.push('--bind', path, path);
132
+ // Later mounts win, so everything below lands on top of the writable paths, even one that contains these.
133
+ // Service sockets live under /run, such as Docker's and the system bus, so it is hidden, except the DNS resolver's files.
134
+ for (const hidden of new Set(['/run', '/var/run', `/run/user/${uid}`, env['XDG_RUNTIME_DIR']])) if (hidden && existsSync(hidden) && !lstatSync(hidden).isSymbolicLink()) args.push('--tmpfs', hidden);
135
+ for (const resolver of ['/run/systemd/resolve', '/run/resolvconf']) if (existsSync(resolver)) args.push('--ro-bind', resolver, resolver);
136
+ // The job's agent directory becomes a throwaway tmpfs holding its entries read-only, so Pi can create lock directories,
137
+ // and only its credentials copy is bound writable.
138
+ if (policy.credentials && existsSync(policy.credentials)) {
139
+ args.push('--tmpfs', policy.credentials);
140
+ for (const name of readdirSync(policy.credentials)) {
141
+ const path = join(policy.credentials, name);
142
+ args.push(name === 'auth.json' ? '--bind' : '--ro-bind', path, path);
143
+ }
144
+ }
145
+ // A mount point cannot be renamed, so a locked directory is bound onto itself, still writable inside, and a locked file read-only.
146
+ for (const path of policy.lock.filter(existsSync)) args.push(statSync(path).isDirectory() ? '--bind' : '--ro-bind', path, path);
147
+ for (const common of policy.gitDirs) for (const name of ['worktrees', 'modules']) if (existsSync(join(common, name))) args.push('--ro-bind', join(common, name), join(common, name));
148
+ for (const own of ownWorktrees(policy)) args.push('--bind', own, own);
149
+ for (const path of [...policy.protect, ...policy.gitDirs.flatMap(existingRedirects)].filter(existsSync)) args.push('--ro-bind', path, path);
150
+ // Shared /tmp is read-only, as on macOS, once everything under it is mounted.
151
+ return [...args, '--remount-ro', '/tmp', '--die-with-parent', '--'];
152
+ }
153
+
154
+ /** Linux syscall numbers and audit architecture for the seccomp filter, per Node architecture. */
155
+ const SYSCALLS: Partial<Record<NodeJS.Architecture, { audit: number; socket: number; ioUringSetup: number }>> = {
156
+ x64: { audit: 0xc000003e, socket: 41, ioUringSetup: 425 },
157
+ arm64: { audit: 0xc00000b7, socket: 198, ioUringSetup: 425 },
158
+ };
159
+
160
+ /**
161
+ * A classic BPF program for bubblewrap's `--seccomp`: a job may not open a Unix socket, the way macOS denies binding or
162
+ * connecting one, so it reaches no local service, abstract socket, or tmux server. Socket pairs, which child processes
163
+ * use for pipes, stay allowed. io_uring could open a socket around the filter, and another architecture's syscall
164
+ * numbers around its checks, so both are refused.
165
+ */
166
+ export function seccompFilter(arch: NodeJS.Architecture = process.arch): Buffer {
167
+ const nr = SYSCALLS[arch];
168
+ if (!nr) throw new Error(`pstack's Linux sandbox supports x64 and arm64, not ${arch}.`);
169
+ const LD = 0x20;
170
+ const JEQ = 0x15;
171
+ const JGE = 0x35;
172
+ const RET = 0x06;
173
+ const ALLOW = 0x7fff0000;
174
+ const DENY = 0x00050001;
175
+ const program: [number, number, number, number][] = [
176
+ [LD, 0, 0, 4],
177
+ [JEQ, 0, 7, nr.audit],
178
+ [LD, 0, 0, 0],
179
+ [JGE, 5, 0, 0x40000000],
180
+ [JEQ, 4, 0, nr.ioUringSetup],
181
+ [JEQ, 0, 2, nr.socket],
182
+ [LD, 0, 0, 16],
183
+ [JEQ, 1, 0, 1],
184
+ [RET, 0, 0, ALLOW],
185
+ [RET, 0, 0, DENY],
186
+ ];
187
+ const bytes = Buffer.alloc(program.length * 8);
188
+ program.forEach(([code, jt, jf, k], index) => {
189
+ bytes.writeUInt16LE(code, index * 8);
190
+ bytes.writeUInt8(jt, index * 8 + 2);
191
+ bytes.writeUInt8(jf, index * 8 + 3);
192
+ bytes.writeUInt32LE(k, index * 8 + 4);
193
+ });
194
+ return bytes;
195
+ }
196
+
197
+ /** The filter's file in Pi's agent directory, which no job may write, so none can loosen the filter before a launch. */
198
+ function seccompFile(agentDir: string): string {
199
+ const path = join(agentDir, 'pstack-v2', `seccomp-${process.arch}.bpf`);
200
+ const filter = seccompFilter();
201
+ if (!existsSync(path) || !readFileSync(path).equals(filter)) {
202
+ mkdirSync(dirname(path), { recursive: true });
203
+ writeFileSync(path, filter);
204
+ }
205
+ return path;
206
+ }
207
+
208
+ function available(command: string): boolean {
209
+ try {
210
+ execFileSync('/bin/sh', ['-c', command], { stdio: 'ignore' });
211
+ return true;
212
+ } catch {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Wraps argv so it runs with writes limited to the policy. bubblewrap nests, so a Linux job inside a sandbox gets its own
219
+ * narrower one. macOS refuses a second Seatbelt profile, so a sandboxed macOS worker asks the root Pi to launch instead.
220
+ */
221
+ export function sandboxed(argv: string[], policy: SandboxPolicy, platform: NodeJS.Platform = process.platform, env: NodeJS.ProcessEnv = process.env): string[] {
222
+ if (platform === 'darwin' && available('command -v sandbox-exec')) {
223
+ placeholders(policy);
224
+ return ['sandbox-exec', '-p', seatbeltProfile(policy), ...argv];
225
+ }
226
+ if (platform === 'linux' && available('command -v bwrap')) {
227
+ placeholders(policy);
228
+ // bubblewrap reads the filter from a file descriptor, which the shell opens just before it becomes bwrap.
229
+ return ['/bin/sh', '-c', 'exec 9<"$1"; shift; exec bwrap --seccomp 9 "$@"', 'sh', seccompFile(policy.agentDir), ...bwrapArgs(policy, env), ...argv];
230
+ }
231
+ throw new Error(`pstack runs every job in a sandbox and found none on ${platform}. Install bubblewrap (bwrap) on Linux or WSL2, or use macOS, where Seatbelt (sandbox-exec) is built in.`);
232
+ }