@codyswann/lisa 5.4.0 → 5.6.0

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 (394) hide show
  1. package/README.md +60 -3
  2. package/all/copy-contents/gitignore +16 -0
  3. package/all/copy-contents/scripts/lisa-mutation.sh +4 -6
  4. package/all/copy-overwrite/scripts/fetch-test-access-map.d.mts +71 -0
  5. package/all/copy-overwrite/scripts/fetch-test-access-map.mjs +674 -0
  6. package/all/copy-overwrite/scripts/lib/affected-tests.mjs +818 -0
  7. package/all/copy-overwrite/scripts/lib/automation-provenance-local.mjs +48 -3
  8. package/all/copy-overwrite/scripts/lib/build-marker.mjs +410 -0
  9. package/all/copy-overwrite/scripts/lib/gate-pass-cache.mjs +537 -0
  10. package/all/copy-overwrite/scripts/lib/github-attestation-provider.mjs +68 -0
  11. package/all/copy-overwrite/scripts/lib/github-attestation-recovery.mjs +25 -10
  12. package/all/copy-overwrite/scripts/lib/github-attestation-verifier.mjs +4 -1
  13. package/all/copy-overwrite/scripts/lib/kill-marks.mjs +1 -2
  14. package/all/copy-overwrite/scripts/lib/lisa-cleanup-sweep-processes.mjs +3 -4
  15. package/all/copy-overwrite/scripts/lib/npm-update-allocate.mjs +1 -6
  16. package/all/copy-overwrite/scripts/lib/npm-update-authorization.mjs +25 -14
  17. package/all/copy-overwrite/scripts/lib/npm-update-cancel-origin.mjs +45 -11
  18. package/all/copy-overwrite/scripts/lib/npm-update-cancellation-proof.mjs +22 -11
  19. package/all/copy-overwrite/scripts/lib/npm-update-cancellation.mjs +29 -17
  20. package/all/copy-overwrite/scripts/lib/npm-update-controller-broker.mjs +1 -1
  21. package/all/copy-overwrite/scripts/lib/npm-update-controller-factory.mjs +19 -1
  22. package/all/copy-overwrite/scripts/lib/npm-update-gate-hooks.mjs +2 -1
  23. package/all/copy-overwrite/scripts/lib/npm-update-gate.mjs +5 -0
  24. package/all/copy-overwrite/scripts/lib/npm-update-gh-requests.mjs +57 -30
  25. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +9 -1
  26. package/all/copy-overwrite/scripts/lib/npm-update-hosted-hook.mjs +1 -1
  27. package/all/copy-overwrite/scripts/lib/npm-update-leaf.mjs +6 -1
  28. package/all/copy-overwrite/scripts/lib/npm-update-policy.mjs +38 -0
  29. package/all/copy-overwrite/scripts/lib/npm-update-publication.mjs +21 -3
  30. package/all/copy-overwrite/scripts/lib/npm-update-publish.mjs +13 -1
  31. package/all/copy-overwrite/scripts/lib/npm-update-recovery.mjs +29 -4
  32. package/all/copy-overwrite/scripts/lib/npm-update-supersession.mjs +21 -7
  33. package/all/copy-overwrite/scripts/lib/npm-update-tool-launcher.mjs +1 -1
  34. package/all/copy-overwrite/scripts/lib/npm-update-tracker-cancel.mjs +139 -0
  35. package/all/copy-overwrite/scripts/lib/npm-update-tracker-jira.mjs +149 -19
  36. package/all/copy-overwrite/scripts/lib/npm-update-tracker-linear.mjs +72 -17
  37. package/all/copy-overwrite/scripts/lib/npm-update-tracker-wire.mjs +102 -12
  38. package/all/copy-overwrite/scripts/lib/npm-update-tracker.mjs +91 -13
  39. package/all/copy-overwrite/scripts/lib/push-admission.mjs +158 -0
  40. package/all/copy-overwrite/scripts/lib/push-gate-defaults.d.mts +34 -0
  41. package/all/copy-overwrite/scripts/lib/push-gate-defaults.mjs +147 -0
  42. package/all/copy-overwrite/scripts/lib/push-timing.mjs +323 -0
  43. package/all/copy-overwrite/scripts/lib/rspec-selection.mjs +672 -0
  44. package/all/copy-overwrite/scripts/lisa-affected-tests.mjs +566 -0
  45. package/all/copy-overwrite/scripts/lisa-automation-provenance.mjs +35 -8
  46. package/all/copy-overwrite/scripts/lisa-gates.mjs +29 -0
  47. package/all/copy-overwrite/scripts/lisa-lint-staged-preflight.mjs +10 -1
  48. package/all/copy-overwrite/scripts/lisa-npm-updater.mjs +8 -5
  49. package/all/copy-overwrite/scripts/lisa-push-timing-report.mjs +153 -0
  50. package/all/copy-overwrite/scripts/lisa-rspec-select.mjs +982 -0
  51. package/all/copy-overwrite/scripts/lisa-run-gates.mjs +231 -6
  52. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +148 -41
  53. package/all/deletions.json +11 -2
  54. package/cdk/create-only/vitest.config.local.ts +1 -7
  55. package/cdk/package-lisa/package.lisa.json +4 -4
  56. package/dist/cli/admit-cmd.d.ts +21 -0
  57. package/dist/cli/admit-cmd.d.ts.map +1 -0
  58. package/dist/cli/admit-cmd.js +142 -0
  59. package/dist/cli/admit-cmd.js.map +1 -0
  60. package/dist/cli/check-cmd.d.ts +72 -0
  61. package/dist/cli/check-cmd.d.ts.map +1 -0
  62. package/dist/cli/check-cmd.js +316 -0
  63. package/dist/cli/check-cmd.js.map +1 -0
  64. package/dist/cli/index.d.ts.map +1 -1
  65. package/dist/cli/index.js +6 -4
  66. package/dist/cli/index.js.map +1 -1
  67. package/dist/cli/lisa-test-run-admission.d.ts +18 -0
  68. package/dist/cli/lisa-test-run-admission.d.ts.map +1 -0
  69. package/dist/cli/lisa-test-run-admission.js +62 -0
  70. package/dist/cli/lisa-test-run-admission.js.map +1 -0
  71. package/dist/cli/lisa-test-run-payload.d.ts +37 -0
  72. package/dist/cli/lisa-test-run-payload.d.ts.map +1 -0
  73. package/dist/cli/lisa-test-run-payload.js +55 -0
  74. package/dist/cli/lisa-test-run-payload.js.map +1 -0
  75. package/dist/cli/lisa-test-run-shard-files.d.ts +89 -0
  76. package/dist/cli/lisa-test-run-shard-files.d.ts.map +1 -0
  77. package/dist/cli/lisa-test-run-shard-files.js +239 -0
  78. package/dist/cli/lisa-test-run-shard-files.js.map +1 -0
  79. package/dist/cli/lisa-test-run-shard.d.ts +6 -2
  80. package/dist/cli/lisa-test-run-shard.d.ts.map +1 -1
  81. package/dist/cli/lisa-test-run-shard.js +25 -13
  82. package/dist/cli/lisa-test-run-shard.js.map +1 -1
  83. package/dist/cli/lisa-test-run.d.ts +1 -1
  84. package/dist/cli/lisa-test-run.d.ts.map +1 -1
  85. package/dist/cli/lisa-test-run.js +47 -10
  86. package/dist/cli/lisa-test-run.js.map +1 -1
  87. package/dist/cli/update-check-hook.d.ts.map +1 -1
  88. package/dist/cli/update-check-hook.js +3 -0
  89. package/dist/cli/update-check-hook.js.map +1 -1
  90. package/dist/configs/vitest/base.d.ts +58 -135
  91. package/dist/configs/vitest/base.d.ts.map +1 -1
  92. package/dist/configs/vitest/base.js +76 -228
  93. package/dist/configs/vitest/base.js.map +1 -1
  94. package/dist/configs/vitest/cdk.d.ts.map +1 -1
  95. package/dist/configs/vitest/cdk.js +3 -2
  96. package/dist/configs/vitest/cdk.js.map +1 -1
  97. package/dist/configs/vitest/coverage-include-global-setup.d.ts.map +1 -1
  98. package/dist/configs/vitest/coverage-include-global-setup.js +3 -4
  99. package/dist/configs/vitest/coverage-include-global-setup.js.map +1 -1
  100. package/dist/configs/vitest/coverage-reports-directory.d.ts +27 -5
  101. package/dist/configs/vitest/coverage-reports-directory.d.ts.map +1 -1
  102. package/dist/configs/vitest/coverage-reports-directory.js +47 -10
  103. package/dist/configs/vitest/coverage-reports-directory.js.map +1 -1
  104. package/dist/configs/vitest/harper-fabric.d.ts.map +1 -1
  105. package/dist/configs/vitest/harper-fabric.js +3 -2
  106. package/dist/configs/vitest/harper-fabric.js.map +1 -1
  107. package/dist/configs/vitest/nestjs.d.ts.map +1 -1
  108. package/dist/configs/vitest/nestjs.js +3 -2
  109. package/dist/configs/vitest/nestjs.js.map +1 -1
  110. package/dist/configs/vitest/phaser.d.ts.map +1 -1
  111. package/dist/configs/vitest/phaser.js +3 -2
  112. package/dist/configs/vitest/phaser.js.map +1 -1
  113. package/dist/configs/vitest/refusal-announcement.d.ts +51 -0
  114. package/dist/configs/vitest/refusal-announcement.d.ts.map +1 -0
  115. package/dist/configs/vitest/refusal-announcement.js +97 -0
  116. package/dist/configs/vitest/refusal-announcement.js.map +1 -0
  117. package/dist/configs/vitest/socket-safe-temp-base.d.ts +3 -4
  118. package/dist/configs/vitest/socket-safe-temp-base.d.ts.map +1 -1
  119. package/dist/configs/vitest/socket-safe-temp-base.js +7 -6
  120. package/dist/configs/vitest/socket-safe-temp-base.js.map +1 -1
  121. package/dist/configs/vitest/typescript.d.ts.map +1 -1
  122. package/dist/configs/vitest/typescript.js +3 -2
  123. package/dist/configs/vitest/typescript.js.map +1 -1
  124. package/dist/core/admission-decision.d.ts +110 -0
  125. package/dist/core/admission-decision.d.ts.map +1 -0
  126. package/dist/core/admission-decision.js +91 -0
  127. package/dist/core/admission-decision.js.map +1 -0
  128. package/dist/core/admission-lock.d.ts +69 -0
  129. package/dist/core/admission-lock.d.ts.map +1 -0
  130. package/dist/core/admission-lock.js +278 -0
  131. package/dist/core/admission-lock.js.map +1 -0
  132. package/dist/core/admission-settings.d.ts +69 -0
  133. package/dist/core/admission-settings.d.ts.map +1 -0
  134. package/dist/core/admission-settings.js +204 -0
  135. package/dist/core/admission-settings.js.map +1 -0
  136. package/dist/core/admission-state.d.ts +50 -0
  137. package/dist/core/admission-state.d.ts.map +1 -0
  138. package/dist/core/admission-state.js +168 -0
  139. package/dist/core/admission-state.js.map +1 -0
  140. package/dist/core/admission.d.ts +70 -0
  141. package/dist/core/admission.d.ts.map +1 -0
  142. package/dist/core/admission.js +205 -0
  143. package/dist/core/admission.js.map +1 -0
  144. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  145. package/dist/core/lisa-owned-hash-ledger.js +440 -0
  146. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  147. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  148. package/dist/core/project-config-push-gate.d.ts +66 -0
  149. package/dist/core/project-config-push-gate.d.ts.map +1 -0
  150. package/dist/core/project-config-push-gate.js +82 -0
  151. package/dist/core/project-config-push-gate.js.map +1 -0
  152. package/dist/core/project-config.d.ts +4 -0
  153. package/dist/core/project-config.d.ts.map +1 -1
  154. package/dist/core/project-config.js +14 -9
  155. package/dist/core/project-config.js.map +1 -1
  156. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  157. package/dist/core/upstream-evidence-manifest.js +234 -146
  158. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  159. package/expo/package-lisa/package.lisa.json +2 -2
  160. package/harper-fabric/package-lisa/package.lisa.json +4 -4
  161. package/nestjs/create-only/vitest.config.local.ts +1 -7
  162. package/nestjs/package-lisa/package.lisa.json +4 -4
  163. package/npm-package/package-lisa/package.lisa.json +4 -4
  164. package/package.json +12 -11
  165. package/phaser/package-lisa/package.lisa.json +4 -4
  166. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  167. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  168. package/plugins/lisa/.codex-plugin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  169. package/plugins/lisa/.codex-plugin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  170. package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +1 -1
  171. package/plugins/lisa/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  172. package/plugins/lisa/skills/lisa-git-submit-pr/SKILL.md +1 -1
  173. package/plugins/lisa/skills/lisa-implement/SKILL.md +1 -1
  174. package/plugins/lisa-agy/plugin.json +1 -1
  175. package/plugins/lisa-agy/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  176. package/plugins/lisa-agy/skills/lisa-git-submit-pr/SKILL.md +1 -1
  177. package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +1 -1
  178. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  179. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  180. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  181. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  182. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  183. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  184. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  185. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  186. package/plugins/lisa-copilot/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  187. package/plugins/lisa-copilot/skills/lisa-git-submit-pr/SKILL.md +1 -1
  188. package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +1 -1
  189. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  190. package/plugins/lisa-cursor/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  191. package/plugins/lisa-cursor/skills/lisa-git-submit-pr/SKILL.md +1 -1
  192. package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +1 -1
  193. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  194. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  195. package/plugins/lisa-devin/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  196. package/plugins/lisa-devin/skills/lisa-git-submit-pr/SKILL.md +1 -1
  197. package/plugins/lisa-devin/skills/lisa-implement/SKILL.md +1 -1
  198. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  199. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  200. package/plugins/lisa-expo-agy/plugin.json +1 -1
  201. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  202. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  203. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  204. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  205. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  206. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  207. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  208. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  209. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  210. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  211. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  212. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  213. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  214. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  215. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  216. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  217. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  218. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  219. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  220. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  221. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  222. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  223. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  224. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  225. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  226. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  227. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  228. package/plugins/lisa-rails-agy/plugin.json +1 -1
  229. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  230. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  231. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  232. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  233. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  234. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  235. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  236. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  237. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  238. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  239. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  240. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  241. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  242. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  243. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  244. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  245. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  246. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  247. package/plugins/src/base/skills/lisa-drive-pr-to-merge/SKILL.md +16 -3
  248. package/plugins/src/base/skills/lisa-git-submit-pr/SKILL.md +1 -1
  249. package/plugins/src/base/skills/lisa-implement/SKILL.md +1 -1
  250. package/rails/copy-overwrite/Gemfile.lisa +8 -0
  251. package/rails/copy-overwrite/lefthook.yml +25 -11
  252. package/rails/copy-overwrite/scripts/lisa-rails-gates.mjs +686 -0
  253. package/rails/copy-overwrite/scripts/lisa-rspec-shards.mjs +2 -2
  254. package/rails/copy-overwrite/scripts/lisa_crystalball_recorder.rb +239 -0
  255. package/rails/copy-overwrite/scripts/lisa_rspec_partial_coverage.rb +83 -0
  256. package/scripts/build-unless-marked.mjs +83 -0
  257. package/scripts/check-plugins-sync.sh +22 -5
  258. package/scripts/classify-markdown-assertions.mjs +141 -0
  259. package/scripts/integration-shard-build.mjs +143 -0
  260. package/scripts/lib/history-scanner-suites.mjs +19 -0
  261. package/scripts/lib/markdown-assertions/classify.mjs +289 -0
  262. package/scripts/lib/markdown-assertions/context.mjs +53 -0
  263. package/scripts/lib/markdown-assertions/corpus.mjs +222 -0
  264. package/scripts/lib/markdown-assertions/manifest-cull.mjs +86 -0
  265. package/scripts/lib/markdown-assertions/record-setup.mjs +265 -0
  266. package/scripts/lib/markdown-assertions/record.mjs +115 -0
  267. package/scripts/lib/markdown-assertions/record.vitest.config.mjs +24 -0
  268. package/scripts/lib/markdown-assertions/sites.mjs +273 -0
  269. package/scripts/lib/markdown-assertions/test-cull.mjs +768 -0
  270. package/scripts/lib/markdown-assertions/tokens.mjs +158 -0
  271. package/scripts/lib/shell-guard-trace.mjs +6 -0
  272. package/scripts/lib/test-access-map-setup.mjs +40 -0
  273. package/scripts/lib/test-access-map-tracer.mjs +205 -0
  274. package/scripts/lib/test-access-map.d.mts +72 -0
  275. package/scripts/lib/test-access-map.mjs +395 -0
  276. package/scripts/lib/test-timings-reporter.d.mts +17 -0
  277. package/scripts/lib/test-timings-reporter.mjs +99 -0
  278. package/scripts/plan-integration-shards.mjs +300 -0
  279. package/scripts/test-timing-report.d.mts +41 -0
  280. package/scripts/test-timing-report.mjs +361 -0
  281. package/scripts/two-channel-couplings.json +132 -36
  282. package/scripts/verify-npm-advisories-4333.mjs +3 -12
  283. package/typescript/copy-overwrite/.prettierignore +13 -0
  284. package/typescript/create-only/vitest.config.local.ts +1 -7
  285. package/typescript/package-lisa/package.lisa.json +4 -4
  286. package/all/copy-overwrite/scripts/lisa-scratch-run.sh +0 -1078
  287. package/dist/cli/lisa-test-run-bootstrap.d.ts +0 -3
  288. package/dist/cli/lisa-test-run-bootstrap.d.ts.map +0 -1
  289. package/dist/cli/lisa-test-run-bootstrap.js +0 -229
  290. package/dist/cli/lisa-test-run-bootstrap.js.map +0 -1
  291. package/dist/cli/lisa-test-run-ipc.d.ts +0 -49
  292. package/dist/cli/lisa-test-run-ipc.d.ts.map +0 -1
  293. package/dist/cli/lisa-test-run-ipc.js +0 -226
  294. package/dist/cli/lisa-test-run-ipc.js.map +0 -1
  295. package/dist/cli/lisa-test-run-process-group.d.ts +0 -30
  296. package/dist/cli/lisa-test-run-process-group.d.ts.map +0 -1
  297. package/dist/cli/lisa-test-run-process-group.js +0 -140
  298. package/dist/cli/lisa-test-run-process-group.js.map +0 -1
  299. package/dist/cli/lisa-test-run-reaper.d.ts +0 -3
  300. package/dist/cli/lisa-test-run-reaper.d.ts.map +0 -1
  301. package/dist/cli/lisa-test-run-reaper.js +0 -195
  302. package/dist/cli/lisa-test-run-reaper.js.map +0 -1
  303. package/dist/cli/lisa-test-run-runtime.d.ts +0 -46
  304. package/dist/cli/lisa-test-run-runtime.d.ts.map +0 -1
  305. package/dist/cli/lisa-test-run-runtime.js +0 -123
  306. package/dist/cli/lisa-test-run-runtime.js.map +0 -1
  307. package/dist/cli/lisa-test-run-supervisor.d.ts +0 -13
  308. package/dist/cli/lisa-test-run-supervisor.d.ts.map +0 -1
  309. package/dist/cli/lisa-test-run-supervisor.js +0 -265
  310. package/dist/cli/lisa-test-run-supervisor.js.map +0 -1
  311. package/dist/configs/vitest/fleet-admission-global-setup.d.ts +0 -34
  312. package/dist/configs/vitest/fleet-admission-global-setup.d.ts.map +0 -1
  313. package/dist/configs/vitest/fleet-admission-global-setup.js +0 -123
  314. package/dist/configs/vitest/fleet-admission-global-setup.js.map +0 -1
  315. package/dist/configs/vitest/fleet-admission.d.ts +0 -129
  316. package/dist/configs/vitest/fleet-admission.d.ts.map +0 -1
  317. package/dist/configs/vitest/fleet-admission.js +0 -239
  318. package/dist/configs/vitest/fleet-admission.js.map +0 -1
  319. package/dist/configs/vitest/scratch-authority.d.ts +0 -25
  320. package/dist/configs/vitest/scratch-authority.d.ts.map +0 -1
  321. package/dist/configs/vitest/scratch-authority.js +0 -107
  322. package/dist/configs/vitest/scratch-authority.js.map +0 -1
  323. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts +0 -5
  324. package/dist/configs/vitest/scratch-bound-cleanup-programs.d.ts.map +0 -1
  325. package/dist/configs/vitest/scratch-bound-cleanup-programs.js +0 -219
  326. package/dist/configs/vitest/scratch-bound-cleanup-programs.js.map +0 -1
  327. package/dist/configs/vitest/scratch-bound-cleanup.d.ts +0 -28
  328. package/dist/configs/vitest/scratch-bound-cleanup.d.ts.map +0 -1
  329. package/dist/configs/vitest/scratch-bound-cleanup.js +0 -155
  330. package/dist/configs/vitest/scratch-bound-cleanup.js.map +0 -1
  331. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts +0 -17
  332. package/dist/configs/vitest/scratch-bound-root-cleanup.d.ts.map +0 -1
  333. package/dist/configs/vitest/scratch-bound-root-cleanup.js +0 -149
  334. package/dist/configs/vitest/scratch-bound-root-cleanup.js.map +0 -1
  335. package/dist/configs/vitest/scratch-global-setup.d.ts +0 -258
  336. package/dist/configs/vitest/scratch-global-setup.d.ts.map +0 -1
  337. package/dist/configs/vitest/scratch-global-setup.js +0 -505
  338. package/dist/configs/vitest/scratch-global-setup.js.map +0 -1
  339. package/dist/configs/vitest/scratch-leak-setup.d.ts +0 -2
  340. package/dist/configs/vitest/scratch-leak-setup.d.ts.map +0 -1
  341. package/dist/configs/vitest/scratch-leak-setup.js +0 -108
  342. package/dist/configs/vitest/scratch-leak-setup.js.map +0 -1
  343. package/dist/configs/vitest/scratch-namespace-authority.d.ts +0 -80
  344. package/dist/configs/vitest/scratch-namespace-authority.d.ts.map +0 -1
  345. package/dist/configs/vitest/scratch-namespace-authority.js +0 -291
  346. package/dist/configs/vitest/scratch-namespace-authority.js.map +0 -1
  347. package/dist/configs/vitest/scratch-owner.d.ts +0 -131
  348. package/dist/configs/vitest/scratch-owner.d.ts.map +0 -1
  349. package/dist/configs/vitest/scratch-owner.js +0 -297
  350. package/dist/configs/vitest/scratch-owner.js.map +0 -1
  351. package/dist/configs/vitest/scratch-route-profile.d.ts +0 -46
  352. package/dist/configs/vitest/scratch-route-profile.d.ts.map +0 -1
  353. package/dist/configs/vitest/scratch-route-profile.js +0 -233
  354. package/dist/configs/vitest/scratch-route-profile.js.map +0 -1
  355. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts +0 -33
  356. package/dist/configs/vitest/scratch-run-root-compatibility.d.ts.map +0 -1
  357. package/dist/configs/vitest/scratch-run-root-compatibility.js +0 -137
  358. package/dist/configs/vitest/scratch-run-root-compatibility.js.map +0 -1
  359. package/dist/configs/vitest/scratch-run-root-intent.d.ts +0 -66
  360. package/dist/configs/vitest/scratch-run-root-intent.d.ts.map +0 -1
  361. package/dist/configs/vitest/scratch-run-root-intent.js +0 -183
  362. package/dist/configs/vitest/scratch-run-root-intent.js.map +0 -1
  363. package/dist/configs/vitest/scratch-setup.d.ts +0 -46
  364. package/dist/configs/vitest/scratch-setup.d.ts.map +0 -1
  365. package/dist/configs/vitest/scratch-setup.js +0 -226
  366. package/dist/configs/vitest/scratch-setup.js.map +0 -1
  367. package/dist/configs/vitest/scratch-supervision-intent.d.ts +0 -8
  368. package/dist/configs/vitest/scratch-supervision-intent.d.ts.map +0 -1
  369. package/dist/configs/vitest/scratch-supervision-intent.js +0 -125
  370. package/dist/configs/vitest/scratch-supervision-intent.js.map +0 -1
  371. package/dist/configs/vitest/scratch-supervision-protocol.d.ts +0 -12
  372. package/dist/configs/vitest/scratch-supervision-protocol.d.ts.map +0 -1
  373. package/dist/configs/vitest/scratch-supervision-protocol.js +0 -230
  374. package/dist/configs/vitest/scratch-supervision-protocol.js.map +0 -1
  375. package/dist/configs/vitest/scratch-supervision.d.ts +0 -69
  376. package/dist/configs/vitest/scratch-supervision.d.ts.map +0 -1
  377. package/dist/configs/vitest/scratch-supervision.js +0 -244
  378. package/dist/configs/vitest/scratch-supervision.js.map +0 -1
  379. package/dist/configs/vitest/scratch-sweep.d.ts +0 -66
  380. package/dist/configs/vitest/scratch-sweep.d.ts.map +0 -1
  381. package/dist/configs/vitest/scratch-sweep.js +0 -82
  382. package/dist/configs/vitest/scratch-sweep.js.map +0 -1
  383. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts +0 -48
  384. package/dist/configs/vitest/scratch-tmpdir-trust.d.ts.map +0 -1
  385. package/dist/configs/vitest/scratch-tmpdir-trust.js +0 -194
  386. package/dist/configs/vitest/scratch-tmpdir-trust.js.map +0 -1
  387. package/dist/configs/vitest/scratch.d.ts +0 -19
  388. package/dist/configs/vitest/scratch.d.ts.map +0 -1
  389. package/dist/configs/vitest/scratch.js +0 -34
  390. package/dist/configs/vitest/scratch.js.map +0 -1
  391. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts +0 -86
  392. package/dist/configs/vitest/synthesis-scratch-reclaim.d.ts.map +0 -1
  393. package/dist/configs/vitest/synthesis-scratch-reclaim.js +0 -226
  394. package/dist/configs/vitest/synthesis-scratch-reclaim.js.map +0 -1
@@ -0,0 +1,222 @@
1
+ /**
2
+ * The shipped-code corpus a machine token must appear in
3
+ * (CodySwannGT/lisa#4867).
4
+ *
5
+ * A pinned Markdown phrase is a MACHINE-TOKEN only when code that Lisa ships
6
+ * or runs reads it. "Code" here is every tracked script, source module, hook,
7
+ * workflow and config file, minus tests, generated plugin copies (they mirror
8
+ * `plugins/src`), and prose trees. For JavaScript and TypeScript only string,
9
+ * template and regular-expression literals count — a phrase quoted in a
10
+ * comment is not read by anything. For shell, Python and YAML, `#` comment
11
+ * lines are dropped.
12
+ * @module scripts/lib/markdown-assertions/corpus
13
+ */
14
+ import { execFileSync } from "node:child_process";
15
+ import { existsSync, readFileSync } from "node:fs";
16
+ import path from "node:path";
17
+
18
+ import ts from "typescript";
19
+
20
+ /** Extensions parsed as JavaScript or TypeScript. */
21
+ const SCRIPT_EXTENSIONS = new Set([
22
+ ".ts",
23
+ ".mts",
24
+ ".cts",
25
+ ".js",
26
+ ".mjs",
27
+ ".cjs",
28
+ ]);
29
+
30
+ /** Extensions read as text with `#` comments removed. */
31
+ const HASH_COMMENT_EXTENSIONS = new Set([
32
+ ".sh",
33
+ ".bash",
34
+ ".py",
35
+ ".yml",
36
+ ".yaml",
37
+ ]);
38
+
39
+ /** Extensions read as plain text. */
40
+ const PLAIN_EXTENSIONS = new Set([".json", ".jsonc"]);
41
+
42
+ /** Tracked paths that are not code a shipped parser lives in. */
43
+ const EXCLUDED = Object.freeze([
44
+ /^tests\//u,
45
+ /(^|\/)__tests__\//u,
46
+ /\.test\.[cm]?[jt]s$/u,
47
+ /\.spec\.[cm]?[jt]s$/u,
48
+ /^plugins\/lisa[^/]*\//u,
49
+ /^\.claude-pr\//u,
50
+ /^(wiki|docs|evidence|research|transcripts|dist|\.lisa)\//u,
51
+ /^scripts\/lib\/(phrase-tests|markdown-assertions)\//u,
52
+ /^scripts\/(classify-phrase-tests|generate-phrase-manifest|check-phrase-manifest-parity|classify-markdown-assertions)\.mjs$/u,
53
+ /(^|\/)(package-lock|bun\.lock|CHANGELOG)/u,
54
+ /(^|\/)node_modules\//u,
55
+ ]);
56
+
57
+ /**
58
+ * Whether a tracked path belongs in the code corpus.
59
+ * @param {string} file - Repository-relative path.
60
+ * @returns {boolean} True for shipped code.
61
+ */
62
+ export function isCodePath(file) {
63
+ const extension = path.posix.extname(file);
64
+ const known =
65
+ SCRIPT_EXTENSIONS.has(extension) ||
66
+ HASH_COMMENT_EXTENSIONS.has(extension) ||
67
+ PLAIN_EXTENSIONS.has(extension);
68
+ return known && !EXCLUDED.some(pattern => pattern.test(file));
69
+ }
70
+
71
+ /**
72
+ * The literal text of a JavaScript or TypeScript file: its string, template
73
+ * and regular-expression literals, one per line. Regular expressions are
74
+ * unescaped so `\[lisa-human-gate\]` reads as `[lisa-human-gate]`.
75
+ * @param {string} file - File name, for the parser.
76
+ * @param {string} text - Source text.
77
+ * @returns {string} Literal text.
78
+ */
79
+ export function scriptLiterals(file, text) {
80
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, false);
81
+ /** @type {string[]} */
82
+ const literals = [];
83
+ /** @param {ts.Node} node */
84
+ const visit = node => {
85
+ if (
86
+ ts.isStringLiteral(node) ||
87
+ ts.isNoSubstitutionTemplateLiteral(node) ||
88
+ ts.isTemplateHead(node) ||
89
+ ts.isTemplateMiddle(node) ||
90
+ ts.isTemplateTail(node)
91
+ ) {
92
+ literals.push(node.text);
93
+ } else if (ts.isRegularExpressionLiteral(node)) {
94
+ const body = node.text.slice(1, node.text.lastIndexOf("/"));
95
+ literals.push(body.replaceAll(/\\([^\w])/gu, "$1"));
96
+ }
97
+ ts.forEachChild(node, visit);
98
+ };
99
+ visit(source);
100
+ return literals.join("\n");
101
+ }
102
+
103
+ /**
104
+ * The names a JavaScript or TypeScript file declares: functions, classes,
105
+ * variables, parameters' object keys, properties and interface members.
106
+ * A document that tells an agent to call `parseLearningsFile` or set
107
+ * `mergeDriver` names one of these.
108
+ * @param {string} file - File name, for the parser.
109
+ * @param {string} text - Source text.
110
+ * @returns {Set<string>} Declared names.
111
+ */
112
+ export function declaredNames(file, text) {
113
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, false);
114
+ /** @type {Set<string>} */
115
+ const names = new Set();
116
+ /** @param {ts.Node} node */
117
+ const visit = node => {
118
+ const named =
119
+ ts.isFunctionDeclaration(node) ||
120
+ ts.isClassDeclaration(node) ||
121
+ ts.isVariableDeclaration(node) ||
122
+ ts.isMethodDeclaration(node) ||
123
+ ts.isPropertyDeclaration(node) ||
124
+ ts.isPropertySignature(node) ||
125
+ ts.isPropertyAssignment(node) ||
126
+ ts.isShorthandPropertyAssignment(node) ||
127
+ ts.isInterfaceDeclaration(node) ||
128
+ ts.isTypeAliasDeclaration(node) ||
129
+ ts.isExportSpecifier(node);
130
+ const name = named
131
+ ? /** @type {{ name?: ts.Node }} */ (node).name
132
+ : undefined;
133
+ if (name && (ts.isIdentifier(name) || ts.isStringLiteral(name))) {
134
+ names.add(name.text);
135
+ }
136
+ ts.forEachChild(node, visit);
137
+ };
138
+ visit(source);
139
+ return names;
140
+ }
141
+
142
+ /**
143
+ * The text of one code file that a token search should see.
144
+ * @param {string} file - Repository-relative path.
145
+ * @param {string} text - File contents.
146
+ * @returns {string} Searchable text.
147
+ */
148
+ export function searchableText(file, text) {
149
+ const extension = path.posix.extname(file);
150
+ if (SCRIPT_EXTENSIONS.has(extension)) return scriptLiterals(file, text);
151
+ if (HASH_COMMENT_EXTENSIONS.has(extension)) {
152
+ return text
153
+ .split("\n")
154
+ .filter(line => !/^\s*#/u.test(line))
155
+ .join("\n");
156
+ }
157
+ return text;
158
+ }
159
+
160
+ /**
161
+ * @typedef {object} Corpus
162
+ * @property {(needle: string) => string | undefined} find - The first code
163
+ * file whose searchable text contains `needle`, or undefined.
164
+ * @property {(needle: string) => number} count - How many code files contain it.
165
+ * @property {(name: string) => string | undefined} declares - The first code
166
+ * file that declares `name` (see declaredNames), or undefined.
167
+ * @property {number} files - Files in the corpus.
168
+ */
169
+
170
+ /**
171
+ * Build the code corpus for a repository checkout.
172
+ * @param {string} root - Repository root.
173
+ * @returns {Corpus} The corpus.
174
+ */
175
+ export function buildCorpus(root) {
176
+ const tracked = execFileSync("git", ["ls-files", "-z"], {
177
+ cwd: root,
178
+ encoding: "utf8",
179
+ maxBuffer: 64 * 1024 * 1024,
180
+ })
181
+ .split("\0")
182
+ .filter(Boolean)
183
+ .filter(isCodePath)
184
+ .sort();
185
+ /** @type {Map<string, string>} */
186
+ const declarations = new Map();
187
+ // A tracked file already deleted in the working tree is no longer code, so
188
+ // it is skipped; any other unreadable file throws rather than silently
189
+ // dropping its tokens (which would push phrases toward WORDING).
190
+ const entries = tracked
191
+ .filter(file => existsSync(path.join(root, file)))
192
+ .map(file => {
193
+ const text = readFileSync(path.join(root, file), "utf8");
194
+ if (SCRIPT_EXTENSIONS.has(path.posix.extname(file))) {
195
+ for (const name of declaredNames(file, text)) {
196
+ if (!declarations.has(name)) declarations.set(name, file);
197
+ }
198
+ }
199
+ return { file, text: searchableText(file, text) };
200
+ });
201
+ /** @type {Map<string, string[]>} */
202
+ const hits = new Map();
203
+ /**
204
+ * @param {string} needle - Text to find.
205
+ * @returns {string[]} Files containing it.
206
+ */
207
+ const filesWith = needle => {
208
+ const cached = hits.get(needle);
209
+ if (cached) return cached;
210
+ const found = entries
211
+ .filter(entry => entry.text.includes(needle))
212
+ .map(entry => entry.file);
213
+ hits.set(needle, found);
214
+ return found;
215
+ };
216
+ return {
217
+ find: needle => filesWith(needle)[0],
218
+ count: needle => filesWith(needle).length,
219
+ declares: name => declarations.get(name),
220
+ files: entries.length,
221
+ };
222
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Cull WORDING entries from the required-phrases manifest
3
+ * (CodySwannGT/lisa#4867).
4
+ * @module scripts/lib/markdown-assertions/manifest-cull
5
+ */
6
+ import { MANIFEST_COMMENT } from "../phrase-tests/manifest.mjs";
7
+
8
+ /** What the culled manifest tells whoever opens it next. */
9
+ export const CULLED_COMMENT = Object.freeze([
10
+ ...MANIFEST_COMMENT,
11
+ "Culled by scripts/classify-markdown-assertions.mjs (CodySwannGT/lisa#4867): only STRUCTURAL and MACHINE-TOKEN entries remain; the classification is in tests/phrase-manifest/classification/manifest.json.",
12
+ "Add a phrase here only when shipped code (a script, hook or parser) reads it; guidance prose needs review, not a pin. `manifest --check` fails on any WORDING entry.",
13
+ ]);
14
+
15
+ /** The manifest's four phrase arrays and the check each holds. */
16
+ const BUCKETS = Object.freeze([
17
+ ["required", "required", "string"],
18
+ ["forbidden", "forbidden", "string"],
19
+ ["requiredPatterns", "required", "pattern"],
20
+ ["forbiddenPatterns", "forbidden", "pattern"],
21
+ ]);
22
+
23
+ /**
24
+ * @typedef {import("./classify.mjs").Verdict} Verdict
25
+ * @typedef {import("./classify.mjs").Check} Check
26
+ * @typedef {import("../phrase-tests/manifest.mjs").Manifest} Manifest
27
+ */
28
+
29
+ /**
30
+ * Classify every manifest entry and drop the WORDING ones.
31
+ * @param {Manifest} manifest - The manifest as it stands.
32
+ * @param {(check: Check) => Verdict} classify - The classifier.
33
+ * @returns {{ evidence: object, culled: Manifest, counts: Record<string, number> }}
34
+ * The evidence (every entry with its class), the culled manifest, and counts.
35
+ */
36
+ export function cullManifest(manifest, classify) {
37
+ /** @type {Record<string, number>} */
38
+ const counts = { total: 0, STRUCTURAL: 0, "MACHINE-TOKEN": 0, WORDING: 0 };
39
+ /** @type {Record<string, object>} */
40
+ const evidenceFiles = {};
41
+ /** @type {Record<string, object>} */
42
+ const culledFiles = {};
43
+ for (const [file, entry] of Object.entries(manifest.files)) {
44
+ /** @type {Record<string, unknown[]>} */
45
+ const kept = {};
46
+ /** @type {{ kept: object[], wording: object[] }} */
47
+ const record = { kept: [], wording: [] };
48
+ for (const [key, polarity, kind] of BUCKETS) {
49
+ const values = /** @type {unknown[]} */ (
50
+ /** @type {Record<string, unknown>} */ (entry)[key] ?? []
51
+ );
52
+ kept[key] = values.filter(value => {
53
+ const verdict = classify(
54
+ /** @type {Check} */ ({ file, polarity, kind, value })
55
+ );
56
+ counts.total = (counts.total ?? 0) + 1;
57
+ counts[verdict.class] = (counts[verdict.class] ?? 0) + 1;
58
+ if (verdict.class === "WORDING") {
59
+ record.wording.push({ polarity, kind, value });
60
+ return false;
61
+ }
62
+ record.kept.push({ polarity, kind, value, ...verdict });
63
+ return true;
64
+ });
65
+ }
66
+ evidenceFiles[file] = record;
67
+ if (BUCKETS.some(([key]) => (kept[key]?.length ?? 0) > 0)) {
68
+ culledFiles[file] = { ...kept, source: entry.source };
69
+ }
70
+ }
71
+ counts.filesBefore = Object.keys(manifest.files).length;
72
+ counts.filesAfter = Object.keys(culledFiles).length;
73
+ return {
74
+ evidence: {
75
+ $comment: [
76
+ "Classification of tests/phrase-manifest/required-phrases.json as it stood before the CodySwannGT/lisa#4867 cull.",
77
+ "Produced by `node scripts/classify-markdown-assertions.mjs manifest --apply`; rules in scripts/lib/markdown-assertions/classify.mjs.",
78
+ "`kept` entries carry their class, reason and (for MACHINE-TOKEN) the code file that reads the token; `wording` entries were deleted.",
79
+ ],
80
+ counts,
81
+ files: evidenceFiles,
82
+ },
83
+ culled: { $comment: CULLED_COMMENT, files: culledFiles },
84
+ counts,
85
+ };
86
+ }
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Vitest setup file that records every phrase assertion and whether its
3
+ * subject is Markdown a test read (CodySwannGT/lisa#4867).
4
+ *
5
+ * Loaded only by `record.vitest.config.mjs`, never by the project's own
6
+ * config. It changes no behaviour: file reads return what they returned, and
7
+ * `toContain` / `toMatch` still assert. Alongside, it notes
8
+ *
9
+ * - every tracked Markdown file read from a test or a test helper (reads by
10
+ * the code under test do not count — a subject derived from them is the
11
+ * code's output, not the document);
12
+ * - for each `toContain` / `toMatch` call: its source location in the test
13
+ * file, the matcher, the negation, the expected value, and the Markdown
14
+ * file the subject came from — the whole text, a slice of it (compared
15
+ * whitespace- and case-insensitively), or a concatenation containing it.
16
+ *
17
+ * Rows go to `$LISA_MD_ASSERT_RECORD_DIR/<pid>-<n>.jsonl`, one per call.
18
+ * @module scripts/lib/markdown-assertions/record-setup
19
+ */
20
+ import fs from "node:fs";
21
+ import fsPromises from "node:fs/promises";
22
+ import { syncBuiltinESMExports } from "node:module";
23
+ import path from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ import { afterAll, chai } from "vitest";
27
+
28
+ const STATE_KEY = Symbol.for("lisa.markdown-assertions.record");
29
+ const OUT_DIR = process.env["LISA_MD_ASSERT_RECORD_DIR"] ?? "";
30
+ const ROOT = process.env["LISA_MD_ASSERT_ROOT"] ?? process.cwd();
31
+ const TESTS_DIR = `${path.join(ROOT, "tests")}${path.sep}`;
32
+ const THIS_FILE = fileURLToPath(import.meta.url);
33
+
34
+ /** Shortest normalised subject that counts as a slice of a document. */
35
+ const MIN_SLICE = 20;
36
+
37
+ /** Shortest document that counts when a subject concatenates several. */
38
+ const MIN_CONCAT_DOC = 200;
39
+
40
+ /**
41
+ * @typedef {{ tracked: Set<string>, reads: Map<string, { text: string, norm: string }>, rows: object[], files: number }} State
42
+ */
43
+
44
+ /**
45
+ * Collapse whitespace and case, so a re-wrapped or lower-cased slice still
46
+ * matches its document.
47
+ * @param {string} text - Text.
48
+ * @returns {string} Normalised text.
49
+ */
50
+ function normalise(text) {
51
+ return text.replaceAll(/\s+/gu, " ").toLowerCase();
52
+ }
53
+
54
+ /**
55
+ * The process-wide recorder state (builtins and the runner outlive a single
56
+ * test file's module graph, so the patches are installed once).
57
+ * @returns {State} The state.
58
+ */
59
+ function state() {
60
+ const holder = /** @type {Record<symbol, State>} */ (
61
+ /** @type {unknown} */ (globalThis)
62
+ );
63
+ holder[STATE_KEY] ??= {
64
+ tracked: new Set(
65
+ JSON.parse(
66
+ fs.readFileSync(process.env["LISA_MD_ASSERT_TRACKED"] ?? "", "utf8")
67
+ )
68
+ ),
69
+ reads: new Map(),
70
+ rows: [],
71
+ files: 0,
72
+ };
73
+ return holder[STATE_KEY];
74
+ }
75
+
76
+ /**
77
+ * Stack frames as absolute file paths with line and column.
78
+ * @returns {{ file: string, line: number, column: number }[]} Frames.
79
+ */
80
+ function frames() {
81
+ const stack = new Error("frames").stack ?? "";
82
+ return [
83
+ ...stack.matchAll(/(?:\(|at )(?:file:\/\/)?(\/[^():\s]+):(\d+):(\d+)/gu),
84
+ ]
85
+ .map(match => ({
86
+ file: match[1] ?? "",
87
+ line: Number(match[2]),
88
+ column: Number(match[3]),
89
+ }))
90
+ .filter(frame => frame.file !== THIS_FILE);
91
+ }
92
+
93
+ /**
94
+ * Note a file read when a test (not the code under test) made it.
95
+ * @param {unknown} target - The path argument.
96
+ * @param {unknown} result - What the read returned.
97
+ */
98
+ function noteRead(target, result) {
99
+ if (busy) return;
100
+ busy = true;
101
+ try {
102
+ noteReadOnce(target, result);
103
+ } finally {
104
+ busy = false;
105
+ }
106
+ }
107
+
108
+ /** Set while a read is being noted, so reads it causes are not. */
109
+ let busy = false;
110
+
111
+ /**
112
+ * Note one read (see noteRead).
113
+ * @param {unknown} target - The path argument.
114
+ * @param {unknown} result - What the read returned.
115
+ */
116
+ function noteReadOnce(target, result) {
117
+ const recorder = state();
118
+ const raw =
119
+ target instanceof URL
120
+ ? fileURLToPath(target)
121
+ : typeof target === "string"
122
+ ? target
123
+ : undefined;
124
+ if (raw === undefined) return;
125
+ const relative = path
126
+ .relative(ROOT, path.resolve(raw))
127
+ .split(path.sep)
128
+ .join("/");
129
+ if (!recorder.tracked.has(relative)) return;
130
+ const caller = frames().find(frame => !frame.file.includes("/node_modules/"));
131
+ if (!caller?.file.startsWith(TESTS_DIR)) return;
132
+ const text = typeof result === "string" ? result : String(result);
133
+ recorder.reads.set(relative, { text, norm: normalise(text) });
134
+ }
135
+
136
+ /**
137
+ * The tracked Markdown file a subject came from, or undefined.
138
+ * @param {unknown} subject - The `expect` subject.
139
+ * @returns {string | undefined} Repository-relative path.
140
+ */
141
+ function provenance(subject) {
142
+ if (typeof subject !== "string") return undefined;
143
+ const reads = [...state().reads.entries()];
144
+ const exact = reads.find(([, read]) => read.text === subject);
145
+ if (exact) return exact[0];
146
+ const norm = normalise(subject);
147
+ const slice = reads.find(
148
+ ([, read]) => norm.trim().length >= MIN_SLICE && read.norm.includes(norm)
149
+ );
150
+ if (slice) return slice[0];
151
+ const concat = reads.find(
152
+ ([, read]) => read.text.length >= MIN_CONCAT_DOC && norm.includes(read.norm)
153
+ );
154
+ return concat?.[0];
155
+ }
156
+
157
+ /**
158
+ * Serialise an expected value.
159
+ * @param {unknown} value - The matcher argument.
160
+ * @returns {unknown} JSON-safe value.
161
+ */
162
+ function serialise(value) {
163
+ if (value instanceof RegExp)
164
+ return { source: value.source, flags: value.flags };
165
+ return typeof value === "string" ? value : { unsupported: typeof value };
166
+ }
167
+
168
+ /** Install the read and matcher hooks once per process. */
169
+ function install() {
170
+ const holder = /** @type {Record<symbol, boolean>} */ (
171
+ /** @type {unknown} */ (globalThis)
172
+ );
173
+ const installed = Symbol.for("lisa.markdown-assertions.installed");
174
+ if (holder[installed]) return;
175
+ holder[installed] = true;
176
+ const readFileSync = fs.readFileSync;
177
+ fs.readFileSync = /** @type {typeof fs.readFileSync} */ (
178
+ function patchedReadFileSync(/** @type {unknown[]} */ ...args) {
179
+ const result = Reflect.apply(readFileSync, fs, args);
180
+ noteRead(args[0], result);
181
+ return result;
182
+ }
183
+ );
184
+ const readFile = fsPromises.readFile;
185
+ const patchedReadFile = /** @type {typeof fsPromises.readFile} */ (
186
+ async function patchedReadFile(/** @type {unknown[]} */ ...args) {
187
+ const result = await Reflect.apply(readFile, fsPromises, args);
188
+ noteRead(args[0], result);
189
+ return result;
190
+ }
191
+ );
192
+ fsPromises.readFile = patchedReadFile;
193
+ fs.promises.readFile = patchedReadFile;
194
+ syncBuiltinESMExports();
195
+ chai.use((api, utils) => {
196
+ for (const name of ["toContain", "toMatch"]) {
197
+ utils.overwriteMethod(api.Assertion.prototype, name, original =>
198
+ recordingMatcher(name, original, utils)
199
+ );
200
+ }
201
+ });
202
+ }
203
+
204
+ /**
205
+ * A matcher that records its call, then asserts exactly as `original` does.
206
+ * @param {string} name - The matcher name.
207
+ * @param {Function} original - The runner's matcher.
208
+ * @param {{ flag: (assertion: object, key: string) => unknown }} utils - Chai utilities.
209
+ * @returns {Function} The recording matcher.
210
+ */
211
+ function recordingMatcher(name, original, utils) {
212
+ return function recorded(/** @type {unknown[]} */ ...args) {
213
+ const subject = utils.flag(this, "object");
214
+ state().rows.push({
215
+ site: siteOf(frames()),
216
+ matcher: name,
217
+ negated: Boolean(utils.flag(this, "negate")),
218
+ value: serialise(args[0]),
219
+ markdown: provenance(subject) ?? null,
220
+ markdownExact: isWholeDocument(subject),
221
+ valueMarkdown: provenance(args[0]) ?? null,
222
+ });
223
+ return Reflect.apply(original, this, args);
224
+ };
225
+ }
226
+
227
+ /**
228
+ * The first test-tree frame as `<file>:<line>:<column>`, or null.
229
+ * @param {{ file: string, line: number, column: number }[]} stack - Frames.
230
+ * @returns {string | null} The site.
231
+ */
232
+ function siteOf(stack) {
233
+ const site = stack.find(frame => frame.file.startsWith(TESTS_DIR));
234
+ return site
235
+ ? `${path.relative(ROOT, site.file)}:${site.line}:${site.column}`
236
+ : null;
237
+ }
238
+
239
+ /**
240
+ * Whether a subject is the whole text of a document a test read.
241
+ * @param {unknown} subject - The `expect` subject.
242
+ * @returns {boolean} True for an exact document.
243
+ */
244
+ function isWholeDocument(subject) {
245
+ return (
246
+ typeof subject === "string" &&
247
+ [...state().reads.values()].some(read => read.text === subject)
248
+ );
249
+ }
250
+
251
+ state().reads.clear();
252
+ install();
253
+ afterAll(() => {
254
+ const recorder = state();
255
+ if (OUT_DIR && recorder.rows.length > 0) {
256
+ recorder.files++;
257
+ fs.mkdirSync(OUT_DIR, { recursive: true });
258
+ fs.writeFileSync(
259
+ path.join(OUT_DIR, `${process.pid}-${recorder.files}.jsonl`),
260
+ `${recorder.rows.map(row => JSON.stringify(row)).join("\n")}\n`
261
+ );
262
+ }
263
+ recorder.rows = [];
264
+ recorder.reads.clear();
265
+ });
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Run test files under the recording setup and collect their phrase
3
+ * assertions (CodySwannGT/lisa#4867). See `record-setup.mjs`.
4
+ * @module scripts/lib/markdown-assertions/record
5
+ */
6
+ import { execFileSync, spawnSync } from "node:child_process";
7
+ import {
8
+ mkdtempSync,
9
+ readdirSync,
10
+ readFileSync,
11
+ rmSync,
12
+ writeFileSync,
13
+ } from "node:fs";
14
+ import { tmpdir } from "node:os";
15
+ import path from "node:path";
16
+
17
+ import {
18
+ expectChains,
19
+ isPhraseChain,
20
+ parseSource,
21
+ } from "../phrase-tests/ast.mjs";
22
+
23
+ /** A test file worth recording: it makes phrase assertions and names documents. */
24
+ const DOCUMENT_HINT =
25
+ /\.mdc?\b|SKILL|AGENTS|CLAUDE|rules\/|skills|commands\/|agents\//u;
26
+
27
+ /**
28
+ * @typedef {object} Row
29
+ * @property {string | null} site - `<test file>:<line>:<column>` of the matcher call.
30
+ * @property {"toContain" | "toMatch"} matcher - The matcher.
31
+ * @property {boolean} negated - Whether `.not` preceded it.
32
+ * @property {string | { source: string, flags: string } | { unsupported: string }} value - The expected value.
33
+ * @property {string | null} markdown - The Markdown file the subject came from.
34
+ * @property {boolean} markdownExact - Whether the subject is a document's whole text.
35
+ * @property {string | null} valueMarkdown - The Markdown file the expected value came from.
36
+ */
37
+
38
+ /**
39
+ * Unit test files that make at least one phrase assertion and mention a
40
+ * document, in path order.
41
+ * @param {string} root - Repository root.
42
+ * @returns {string[]} Repository-relative test files.
43
+ */
44
+ export function candidateTestFiles(root) {
45
+ return execFileSync("git", ["ls-files", "tests/**/*.test.ts"], {
46
+ cwd: root,
47
+ encoding: "utf8",
48
+ })
49
+ .split("\n")
50
+ .filter(Boolean)
51
+ .filter(
52
+ file => !file.includes("/integration/") && !file.includes(".integration.")
53
+ )
54
+ .filter(file => {
55
+ const text = readFileSync(path.join(root, file), "utf8");
56
+ return (
57
+ DOCUMENT_HINT.test(text) &&
58
+ expectChains(parseSource(file, text)).some(isPhraseChain)
59
+ );
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Run the given test files under the recorder and return every row.
65
+ * @param {string} root - Repository root.
66
+ * @param {string[]} files - Test files.
67
+ * @returns {{ rows: Row[], status: number | null }} The rows and vitest's exit status.
68
+ */
69
+ export function recordAssertions(root, files) {
70
+ const scratch = mkdtempSync(path.join(tmpdir(), "lisa-md-assert-"));
71
+ const outDir = path.join(scratch, "rows");
72
+ const trackedFile = path.join(scratch, "tracked.json");
73
+ const tracked = execFileSync("git", ["ls-files", "*.md", "*.mdc", "*.mdx"], {
74
+ cwd: root,
75
+ encoding: "utf8",
76
+ maxBuffer: 64 * 1024 * 1024,
77
+ })
78
+ .split("\n")
79
+ .filter(Boolean);
80
+ writeFileSync(trackedFile, JSON.stringify(tracked));
81
+ const result = spawnSync(
82
+ "node_modules/.bin/vitest",
83
+ [
84
+ "run",
85
+ "--config",
86
+ "scripts/lib/markdown-assertions/record.vitest.config.mjs",
87
+ ...files,
88
+ ],
89
+ {
90
+ cwd: root,
91
+ stdio: ["ignore", "inherit", "inherit"],
92
+ env: {
93
+ ...process.env,
94
+ LISA_MD_ASSERT_RECORD_DIR: outDir,
95
+ LISA_MD_ASSERT_ROOT: root,
96
+ LISA_MD_ASSERT_TRACKED: trackedFile,
97
+ },
98
+ }
99
+ );
100
+ /** @type {string[]} */
101
+ let names = [];
102
+ try {
103
+ names = readdirSync(outDir);
104
+ } catch {
105
+ names = [];
106
+ }
107
+ const rows = names.flatMap(name =>
108
+ readFileSync(path.join(outDir, name), "utf8")
109
+ .split("\n")
110
+ .filter(Boolean)
111
+ .map(line => /** @type {Row} */ (JSON.parse(line)))
112
+ );
113
+ rmSync(scratch, { recursive: true, force: true });
114
+ return { rows, status: result.status };
115
+ }