eliscript 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. package/README.md +61 -0
  2. package/bootstrap/README.md +26 -0
  3. package/bootstrap/backends/README.md +515 -0
  4. package/bootstrap/backends/async.eli +230 -0
  5. package/bootstrap/backends/binary.eli +173 -0
  6. package/bootstrap/backends/capabilities.eli +74 -0
  7. package/bootstrap/backends/elf.eli +246 -0
  8. package/bootstrap/backends/managed.eli +5976 -0
  9. package/bootstrap/backends/memory.eli +100 -0
  10. package/bootstrap/backends/native.eli +2000 -0
  11. package/bootstrap/backends/numeric.eli +1362 -0
  12. package/bootstrap/backends/optimize.eli +79 -0
  13. package/bootstrap/backends/regexp.eli +2263 -0
  14. package/bootstrap/backends/sha256.eli +138 -0
  15. package/bootstrap/backends/wasm.eli +1161 -0
  16. package/bootstrap/compiler/analyzer.eli +165 -77
  17. package/bootstrap/compiler/compiler.eli +43 -19
  18. package/bootstrap/compiler/emitter.eli +780 -170
  19. package/bootstrap/compiler/expander.eli +136 -45
  20. package/bootstrap/compiler/formatter.eli +8 -1
  21. package/bootstrap/compiler/ir.eli +148 -45
  22. package/bootstrap/compiler/lower.eli +29 -2
  23. package/bootstrap/compiler/project.eli +51 -21
  24. package/bootstrap/compiler/reader.eli +128 -36
  25. package/bootstrap/compiler/source-map.eli +46 -4
  26. package/bootstrap/compiler/symbol.eli +2 -1
  27. package/bootstrap/compiler/syntax.eli +47 -12
  28. package/bootstrap/compiler/transient-analysis.eli +40 -4
  29. package/bootstrap/host/check-cli-legacy.mjs +163 -0
  30. package/bootstrap/host/check-cli.mjs +59 -158
  31. package/bootstrap/host/check-cli.mjs.map +1 -0
  32. package/bootstrap/host/compiler-session.eli +1579 -0
  33. package/bootstrap/host/compiler-tools.eli +513 -0
  34. package/bootstrap/host/eliscript-cli.mjs +53 -33
  35. package/bootstrap/host/eliscript-cli.mjs.map +1 -0
  36. package/bootstrap/host/project-cli-legacy.mjs +295 -0
  37. package/bootstrap/host/project-cli.mjs +74 -289
  38. package/bootstrap/host/project-cli.mjs.map +1 -0
  39. package/bootstrap/host/project-legacy.mjs +1080 -0
  40. package/bootstrap/host/project.mjs +210 -1060
  41. package/bootstrap/host/project.mjs.map +1 -0
  42. package/bootstrap/runtime/UNICODE-LICENSE.txt +39 -0
  43. package/bootstrap/runtime/memory.eli +30379 -0
  44. package/browser/host.mjs +732 -11
  45. package/browser/worker.mjs +6 -3
  46. package/compiler/eliscript-analyzer.el +371 -4
  47. package/compiler/eliscript-cli.el +84 -1
  48. package/compiler/eliscript-emitter.el +1189 -256
  49. package/compiler/eliscript-expander.el +147 -10
  50. package/compiler/eliscript-ir-emitter.el +725 -208
  51. package/compiler/eliscript-lower.el +127 -1
  52. package/compiler/eliscript-portable.el +177 -51
  53. package/compiler/eliscript-project.el +20 -2
  54. package/compiler/eliscript-reader.el +141 -57
  55. package/compiler/eliscript-source-map.el +26 -12
  56. package/compiler/eliscript-transient-analysis.el +382 -19
  57. package/dist/backends/async.mjs +561 -0
  58. package/dist/backends/async.mjs.macro-origins.json +1 -0
  59. package/dist/backends/async.mjs.map +1 -0
  60. package/dist/backends/binary.mjs +381 -0
  61. package/dist/backends/binary.mjs.macro-origins.json +1 -0
  62. package/dist/backends/binary.mjs.map +1 -0
  63. package/dist/backends/capabilities.mjs +237 -0
  64. package/dist/backends/capabilities.mjs.macro-origins.json +1 -0
  65. package/dist/backends/capabilities.mjs.map +1 -0
  66. package/dist/backends/elf.mjs +540 -0
  67. package/dist/backends/elf.mjs.macro-origins.json +1 -0
  68. package/dist/backends/elf.mjs.map +1 -0
  69. package/dist/backends/managed.mjs +10616 -0
  70. package/dist/backends/managed.mjs.macro-origins.json +1 -0
  71. package/dist/backends/managed.mjs.map +1 -0
  72. package/dist/backends/memory.mjs +278 -0
  73. package/dist/backends/memory.mjs.macro-origins.json +1 -0
  74. package/dist/backends/memory.mjs.map +1 -0
  75. package/dist/backends/native.mjs +4099 -0
  76. package/dist/backends/native.mjs.macro-origins.json +1 -0
  77. package/dist/backends/native.mjs.map +1 -0
  78. package/dist/backends/numeric.mjs +2458 -0
  79. package/dist/backends/numeric.mjs.macro-origins.json +1 -0
  80. package/dist/backends/numeric.mjs.map +1 -0
  81. package/dist/backends/optimize.mjs +204 -0
  82. package/dist/backends/optimize.mjs.macro-origins.json +1 -0
  83. package/dist/backends/optimize.mjs.map +1 -0
  84. package/dist/backends/regexp.mjs +2033 -0
  85. package/dist/backends/regexp.mjs.macro-origins.json +1 -0
  86. package/dist/backends/regexp.mjs.map +1 -0
  87. package/dist/backends/sha256.mjs +310 -0
  88. package/dist/backends/sha256.mjs.macro-origins.json +1 -0
  89. package/dist/backends/sha256.mjs.map +1 -0
  90. package/dist/backends/wasm.mjs +2258 -0
  91. package/dist/backends/wasm.mjs.macro-origins.json +1 -0
  92. package/dist/backends/wasm.mjs.map +1 -0
  93. package/dist/bootstrap/analyzer.mjs +1908 -776
  94. package/dist/bootstrap/analyzer.mjs.macro-origins.json +1 -0
  95. package/dist/bootstrap/analyzer.mjs.map +1 -1
  96. package/dist/bootstrap/compiler.mjs +450 -142
  97. package/dist/bootstrap/compiler.mjs.macro-origins.json +1 -0
  98. package/dist/bootstrap/compiler.mjs.map +1 -1
  99. package/dist/bootstrap/emitter.mjs +3083 -909
  100. package/dist/bootstrap/emitter.mjs.macro-origins.json +1 -0
  101. package/dist/bootstrap/emitter.mjs.map +1 -1
  102. package/dist/bootstrap/expander.mjs +2887 -1233
  103. package/dist/bootstrap/expander.mjs.macro-origins.json +1 -0
  104. package/dist/bootstrap/expander.mjs.map +1 -1
  105. package/dist/bootstrap/formatter.mjs +582 -218
  106. package/dist/bootstrap/formatter.mjs.macro-origins.json +1 -0
  107. package/dist/bootstrap/formatter.mjs.map +1 -1
  108. package/dist/bootstrap/ir.mjs +670 -116
  109. package/dist/bootstrap/ir.mjs.macro-origins.json +1 -0
  110. package/dist/bootstrap/ir.mjs.map +1 -1
  111. package/dist/bootstrap/lower.mjs +866 -257
  112. package/dist/bootstrap/lower.mjs.macro-origins.json +1 -0
  113. package/dist/bootstrap/lower.mjs.map +1 -1
  114. package/dist/bootstrap/package.json +1 -0
  115. package/dist/bootstrap/project.mjs +1168 -498
  116. package/dist/bootstrap/project.mjs.macro-origins.json +1 -0
  117. package/dist/bootstrap/project.mjs.map +1 -1
  118. package/dist/bootstrap/reader.mjs +674 -175
  119. package/dist/bootstrap/reader.mjs.macro-origins.json +1 -0
  120. package/dist/bootstrap/reader.mjs.map +1 -1
  121. package/dist/bootstrap/runtime/math.mjs +1117 -0
  122. package/dist/bootstrap/runtime/math.mjs.map +1 -0
  123. package/dist/bootstrap/runtime/unicode-case-data.mjs +10125 -0
  124. package/dist/bootstrap/runtime/unicode-case-data.mjs.map +1 -0
  125. package/dist/bootstrap/runtime/unicode-case.mjs +281 -0
  126. package/dist/bootstrap/runtime/unicode-case.mjs.map +1 -0
  127. package/dist/bootstrap/source-map.mjs +430 -119
  128. package/dist/bootstrap/source-map.mjs.macro-origins.json +1 -0
  129. package/dist/bootstrap/source-map.mjs.map +1 -1
  130. package/dist/bootstrap/symbol.mjs +229 -53
  131. package/dist/bootstrap/symbol.mjs.macro-origins.json +1 -0
  132. package/dist/bootstrap/symbol.mjs.map +1 -1
  133. package/dist/bootstrap/syntax.mjs +205 -7
  134. package/dist/bootstrap/syntax.mjs.macro-origins.json +1 -0
  135. package/dist/bootstrap/syntax.mjs.map +1 -1
  136. package/dist/bootstrap/transient-analysis.mjs +1185 -489
  137. package/dist/bootstrap/transient-analysis.mjs.macro-origins.json +1 -0
  138. package/dist/bootstrap/transient-analysis.mjs.map +1 -1
  139. package/dist/browser/compiler.js +199 -6478
  140. package/dist/browser/host.mjs +1078 -0
  141. package/dist/browser/loader.js +1 -0
  142. package/dist/browser/loader.mjs +231 -0
  143. package/dist/browser/worker.mjs +63 -0
  144. package/dist/compiler-artifact.json +1 -0
  145. package/dist/host/compiler-session.mjs +2980 -0
  146. package/dist/host/compiler-session.mjs.macro-origins.json +1 -0
  147. package/dist/host/compiler-session.mjs.map +1 -0
  148. package/dist/host/compiler-tools.mjs +1084 -0
  149. package/dist/host/compiler-tools.mjs.macro-origins.json +1 -0
  150. package/dist/host/compiler-tools.mjs.map +1 -0
  151. package/dist/literal-sources/runtime/core/collection-internals.eli +60 -0
  152. package/dist/literal-sources/runtime/core/collection.eli +639 -0
  153. package/dist/literal-sources/runtime/core/data-text.eli +290 -0
  154. package/dist/literal-sources/runtime/core/data.eli +22 -0
  155. package/dist/literal-sources/runtime/core/identifier.eli +44 -0
  156. package/dist/literal-sources/runtime/core/lazy-sequence.eli +131 -0
  157. package/dist/literal-sources/runtime/core/list.eli +19 -0
  158. package/dist/literal-sources/runtime/core/map.eli +9 -0
  159. package/dist/literal-sources/runtime/core/metadata-internals.eli +6 -0
  160. package/dist/literal-sources/runtime/core/metadata.eli +40 -0
  161. package/dist/literal-sources/runtime/core/object.eli +8 -0
  162. package/dist/literal-sources/runtime/core/order.eli +123 -0
  163. package/dist/literal-sources/runtime/core/persistent-kind.eli +28 -0
  164. package/dist/literal-sources/runtime/core/protocol-error.eli +32 -0
  165. package/dist/literal-sources/runtime/core/protocol.eli +28 -0
  166. package/dist/literal-sources/runtime/core/queue.eli +9 -0
  167. package/dist/literal-sources/runtime/core/record.eli +191 -0
  168. package/dist/literal-sources/runtime/core/regex.eli +158 -0
  169. package/dist/literal-sources/runtime/core/sequence.eli +305 -0
  170. package/dist/literal-sources/runtime/core/set-algebra.eli +28 -0
  171. package/dist/literal-sources/runtime/core/set.eli +9 -0
  172. package/dist/literal-sources/runtime/core/sorted.eli +408 -0
  173. package/dist/literal-sources/runtime/core/text.eli +14 -0
  174. package/dist/literal-sources/runtime/core/transducer.eli +268 -0
  175. package/dist/literal-sources/runtime/core/transient.eli +17 -0
  176. package/dist/literal-sources/runtime/core/truth.eli +4 -0
  177. package/dist/literal-sources/runtime/core/type.eli +232 -0
  178. package/dist/literal-sources/runtime/core/value-internals.eli +13 -0
  179. package/dist/literal-sources/runtime/core/value.eli +19 -0
  180. package/dist/literal-sources/runtime/core/vector.eli +25 -0
  181. package/dist/literal-sources/runtime/literals.eli +23 -0
  182. package/dist/literal-sources/runtime/testing/value.eli +6 -0
  183. package/dist/literal-sources/runtime/wire/http-rpc.eli +362 -0
  184. package/dist/literal-sources/runtime/wire/markdown.eli +275 -0
  185. package/dist/literal-sources/runtime/wire/schema.eli +193 -0
  186. package/dist/literal-sources/stdlib/bit.eli +36 -0
  187. package/dist/literal-sources/stdlib/core/data.eli +306 -0
  188. package/dist/literal-sources/stdlib/core/object.eli +89 -0
  189. package/dist/literal-sources/stdlib/core/protocol.eli +451 -0
  190. package/dist/literal-sources/stdlib/core/set.eli +312 -0
  191. package/dist/literal-sources/stdlib/core/text.eli +103 -0
  192. package/dist/literal-sources/stdlib/managed-literal-protocols.eli +494 -0
  193. package/dist/literal-sources/stdlib/managed-literals.eli +1469 -0
  194. package/dist/literal-sources/stdlib/managed-queue-state.eli +65 -0
  195. package/dist/literal-sources/stdlib/managed-sorted-state.eli +233 -0
  196. package/dist/literal-sources/stdlib/managed-transient-state.eli +348 -0
  197. package/dist/literal-sources/stdlib/managed-value-state.eli +153 -0
  198. package/dist/literal-sources/stdlib/managed-vector-view-state.eli +102 -0
  199. package/dist/literal-sources/stdlib/persistent-list.eli +145 -0
  200. package/dist/literal-sources/stdlib/persistent-map.eli +724 -0
  201. package/dist/literal-sources/stdlib/persistent-set.eli +236 -0
  202. package/dist/literal-sources/stdlib/persistent-vector.eli +359 -0
  203. package/dist/literal-sources/stdlib/value.eli +325 -0
  204. package/dist/package.json +10 -0
  205. package/dist/runtime/math.mjs +1116 -0
  206. package/dist/runtime/math.mjs.macro-origins.json +1 -0
  207. package/dist/runtime/math.mjs.map +1 -0
  208. package/dist/runtime/unicode-case-data.mjs +10124 -0
  209. package/dist/runtime/unicode-case-data.mjs.macro-origins.json +1 -0
  210. package/dist/runtime/unicode-case-data.mjs.map +1 -0
  211. package/dist/runtime/unicode-case.mjs +280 -0
  212. package/dist/runtime/unicode-case.mjs.macro-origins.json +1 -0
  213. package/dist/runtime/unicode-case.mjs.map +1 -0
  214. package/dist/runtime.eli +30379 -0
  215. package/dist/stage3-release.json +1 -0
  216. package/editor/README.md +1 -1
  217. package/editor/eliscript-mode.el +1 -1
  218. package/editor/eliscript-repl.el +1 -1
  219. package/package.json +106 -11
  220. package/platform/http.mjs +20 -0
  221. package/runtime/array-text.mjs +159 -0
  222. package/runtime/core/map-internals.mjs +27 -9
  223. package/runtime/core/object-impl.mjs +26 -17
  224. package/runtime/core/object-impl.mjs.map +1 -1
  225. package/runtime/core/protocol-impl.mjs +682 -255
  226. package/runtime/core/protocol-impl.mjs.map +1 -1
  227. package/runtime/core/protocol.mjs +4 -0
  228. package/runtime/core/record.mjs +23 -2
  229. package/runtime/core/regex.mjs +4 -0
  230. package/runtime/core/sorted.mjs +53 -0
  231. package/runtime/core/text-impl.mjs +167 -48
  232. package/runtime/core/text-impl.mjs.map +1 -1
  233. package/runtime/core/type.mjs +75 -3
  234. package/runtime/core/vector.mjs +6 -0
  235. package/runtime/math.eli +429 -0
  236. package/runtime/math.mjs +1116 -0
  237. package/runtime/math.mjs.map +1 -0
  238. package/runtime/number-radix.mjs +105 -0
  239. package/runtime/unicode-case-data.eli +29 -0
  240. package/runtime/unicode-case-data.mjs +10124 -0
  241. package/runtime/unicode-case-data.mjs.map +1 -0
  242. package/runtime/unicode-case.eli +100 -0
  243. package/runtime/unicode-case.mjs +280 -0
  244. package/runtime/unicode-case.mjs.map +1 -0
  245. package/runtime/wire/http-rpc.mjs +168 -0
  246. package/runtime/wire/markdown.mjs +196 -0
  247. package/runtime/wire/schema.mjs +109 -0
  248. package/stdlib/README.md +54 -0
  249. package/stdlib/core/protocol.eli +81 -17
  250. package/stdlib/core/seq.eli +1 -1
  251. package/stdlib/core/zipper.eli +172 -72
  252. package/stdlib/gepo.eli +12 -0
  253. package/stdlib/interop/js.eli +56 -15
  254. package/stdlib/managed-literal-protocols.eli +494 -0
  255. package/stdlib/managed-literals.eli +1469 -0
  256. package/stdlib/managed-protocol-error.eli +32 -0
  257. package/stdlib/managed-queue-state.eli +65 -0
  258. package/stdlib/managed-runtime-collection-internals.eli +60 -0
  259. package/stdlib/managed-runtime-collection.eli +639 -0
  260. package/stdlib/managed-runtime-data-text.eli +290 -0
  261. package/stdlib/managed-runtime-data.eli +22 -0
  262. package/stdlib/managed-runtime-identifier.eli +44 -0
  263. package/stdlib/managed-runtime-lazy-sequence.eli +131 -0
  264. package/stdlib/managed-runtime-list.eli +19 -0
  265. package/stdlib/managed-runtime-literals.eli +23 -0
  266. package/stdlib/managed-runtime-map.eli +9 -0
  267. package/stdlib/managed-runtime-metadata-internals.eli +6 -0
  268. package/stdlib/managed-runtime-metadata.eli +40 -0
  269. package/stdlib/managed-runtime-object.eli +8 -0
  270. package/stdlib/managed-runtime-order.eli +123 -0
  271. package/stdlib/managed-runtime-persistent-kind.eli +28 -0
  272. package/stdlib/managed-runtime-protocol.eli +28 -0
  273. package/stdlib/managed-runtime-queue.eli +9 -0
  274. package/stdlib/managed-runtime-record.eli +191 -0
  275. package/stdlib/managed-runtime-regex.eli +158 -0
  276. package/stdlib/managed-runtime-sequence.eli +305 -0
  277. package/stdlib/managed-runtime-set-algebra.eli +28 -0
  278. package/stdlib/managed-runtime-set.eli +9 -0
  279. package/stdlib/managed-runtime-sorted.eli +408 -0
  280. package/stdlib/managed-runtime-text.eli +14 -0
  281. package/stdlib/managed-runtime-transducer.eli +268 -0
  282. package/stdlib/managed-runtime-transient.eli +17 -0
  283. package/stdlib/managed-runtime-truth.eli +4 -0
  284. package/stdlib/managed-runtime-type.eli +232 -0
  285. package/stdlib/managed-runtime-value-internals.eli +13 -0
  286. package/stdlib/managed-runtime-value.eli +19 -0
  287. package/stdlib/managed-runtime-vector.eli +25 -0
  288. package/stdlib/managed-sorted-state.eli +233 -0
  289. package/stdlib/managed-testing-value.eli +6 -0
  290. package/stdlib/managed-transient-state.eli +348 -0
  291. package/stdlib/managed-value-state.eli +153 -0
  292. package/stdlib/managed-vector-view-state.eli +102 -0
  293. package/stdlib/managed-wire-http-rpc.eli +362 -0
  294. package/stdlib/managed-wire-markdown.eli +275 -0
  295. package/stdlib/managed-wire-schema.eli +193 -0
  296. package/stdlib/mdp.eli +7 -0
  297. package/stdlib/mds.eli +4 -0
  298. package/stdlib/persistent-vector.eli +23 -6
  299. package/tools/acceptance/check-legacy.mjs +687 -0
  300. package/tools/acceptance/check.eli +431 -0
  301. package/tools/acceptance/compile-evidence.el +49 -0
  302. package/tools/acceptance/finalize-legacy.mjs +498 -0
  303. package/tools/acceptance/finalize.eli +270 -0
  304. package/tools/backends/benchmark.mjs +175 -0
  305. package/tools/backends/build.mjs +135 -0
  306. package/tools/backends/compile.mjs +94 -0
  307. package/tools/backends/compiler-bootstrap.mjs +1001 -0
  308. package/tools/backends/compiler-browser.mjs +361 -0
  309. package/tools/backends/compiler-build.mjs +1628 -0
  310. package/tools/backends/compiler-cli-legacy.mjs +334 -0
  311. package/tools/backends/compiler-cli.mjs +29 -0
  312. package/tools/backends/compiler-corpus-bit.mjs +234 -0
  313. package/tools/backends/compiler-corpus-cli-adapters-legacy.mjs +362 -0
  314. package/tools/backends/compiler-corpus-cli-adapters.mjs +247 -0
  315. package/tools/backends/compiler-corpus-debugging.mjs +221 -0
  316. package/tools/backends/compiler-corpus-emitter.mjs +324 -0
  317. package/tools/backends/compiler-corpus-evaluation-adapters.mjs +65 -0
  318. package/tools/backends/compiler-corpus-execution-legacy.mjs +769 -0
  319. package/tools/backends/compiler-corpus-execution.mjs +3324 -0
  320. package/tools/backends/compiler-corpus-fuzz.mjs +229 -0
  321. package/tools/backends/compiler-corpus-generations.mjs +208 -0
  322. package/tools/backends/compiler-corpus-host-context-legacy.mjs +114 -0
  323. package/tools/backends/compiler-corpus-host-context.mjs +550 -0
  324. package/tools/backends/compiler-corpus-identity-host.mjs +553 -0
  325. package/tools/backends/compiler-corpus-identity-value-adapters-legacy.mjs +298 -0
  326. package/tools/backends/compiler-corpus-identity-value-adapters.mjs +69 -0
  327. package/tools/backends/compiler-corpus-isolated-exports.mjs +21 -0
  328. package/tools/backends/compiler-corpus-legacy.mjs +1155 -0
  329. package/tools/backends/compiler-corpus-literal-provider.mjs +282 -0
  330. package/tools/backends/compiler-corpus-managed-adapters-legacy.mjs +334 -0
  331. package/tools/backends/compiler-corpus-managed-adapters.mjs +937 -0
  332. package/tools/backends/compiler-corpus-managed-cases.mjs +179 -0
  333. package/tools/backends/compiler-corpus-managed-fixtures-legacy.mjs +879 -0
  334. package/tools/backends/compiler-corpus-managed-fixtures.mjs +1287 -0
  335. package/tools/backends/compiler-corpus-matchers.mjs +173 -0
  336. package/tools/backends/compiler-corpus-original-program.mjs +612 -0
  337. package/tools/backends/compiler-corpus-process.mjs +765 -0
  338. package/tools/backends/compiler-corpus-program-driver.mjs +306 -0
  339. package/tools/backends/compiler-corpus-project-adapters-legacy.mjs +497 -0
  340. package/tools/backends/compiler-corpus-project-adapters.mjs +340 -0
  341. package/tools/backends/compiler-corpus-project-entry-host.mjs +511 -0
  342. package/tools/backends/compiler-corpus-project-transport.mjs +151 -0
  343. package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1438 -0
  344. package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1456 -0
  345. package/tools/backends/compiler-corpus-raw-math-fixture.mjs +346 -0
  346. package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +523 -0
  347. package/tools/backends/compiler-corpus-reference-legacy.mjs +263 -0
  348. package/tools/backends/compiler-corpus-reference.mjs +241 -0
  349. package/tools/backends/compiler-corpus-runtime-adapters-legacy.mjs +843 -0
  350. package/tools/backends/compiler-corpus-runtime-adapters.mjs +663 -0
  351. package/tools/backends/compiler-corpus-source-archive.mjs +206 -0
  352. package/tools/backends/compiler-corpus-tools-artifact-adapters.mjs +410 -0
  353. package/tools/backends/compiler-corpus-tools-cli.mjs +363 -0
  354. package/tools/backends/compiler-corpus-tools-reference.mjs +264 -0
  355. package/tools/backends/compiler-corpus.mjs +2054 -0
  356. package/tools/backends/compiler-debug.mjs +142 -0
  357. package/tools/backends/compiler-matrix.mjs +1955 -0
  358. package/tools/backends/compiler-metadata.mjs +203 -0
  359. package/tools/backends/compiler-package-browser.mjs +120 -0
  360. package/tools/backends/compiler-package-legacy.mjs +654 -0
  361. package/tools/backends/compiler-package.mjs +464 -0
  362. package/tools/backends/compiler-project.mjs +126 -0
  363. package/tools/backends/compiler-session.mjs +843 -0
  364. package/tools/backends/compiler-sha256.mjs +152 -0
  365. package/tools/backends/compiler-unicode-profile-host.mjs +196 -0
  366. package/tools/backends/compiler-worker.mjs +573 -0
  367. package/tools/backends/dist/bootstrap-js-stages.mjs +919 -0
  368. package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -0
  369. package/tools/backends/dist/managed-ir-inventory.mjs +488 -0
  370. package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -0
  371. package/tools/backends/dist/record-grid.mjs +1256 -0
  372. package/tools/backends/dist/record-grid.mjs.map +1 -0
  373. package/tools/backends/dist/release-cli.mjs +462 -0
  374. package/tools/backends/dist/release-cli.mjs.map +1 -0
  375. package/tools/backends/dist/run-artifact.mjs +517 -0
  376. package/tools/backends/dist/run-artifact.mjs.map +1 -0
  377. package/tools/backends/eliscript/compiler-corpus-bit.eli +77 -0
  378. package/tools/backends/eliscript/compiler-corpus-debugging.eli +70 -0
  379. package/tools/backends/eliscript/compiler-corpus-project-entry-host.eli +256 -0
  380. package/tools/backends/managed-foreign-binding.mjs +497 -0
  381. package/tools/backends/managed-host-legacy.mjs +1181 -0
  382. package/tools/backends/managed-host-lifecycle.mjs +310 -0
  383. package/tools/backends/managed-host-object-provider.mjs +155 -0
  384. package/tools/backends/managed-host-object-realm.mjs +797 -0
  385. package/tools/backends/managed-host-proxy.mjs +71 -0
  386. package/tools/backends/managed-host-runtime.mjs +5868 -0
  387. package/tools/backends/managed-host.mjs +716 -0
  388. package/tools/backends/managed-module-graph-legacy.mjs +308 -0
  389. package/tools/backends/managed-module-graph.mjs +694 -0
  390. package/tools/backends/managed-runtime-host-legacy.mjs +195 -0
  391. package/tools/backends/managed-runtime.mjs +939 -0
  392. package/tools/backends/managed-source-view-legacy.mjs +332 -0
  393. package/tools/backends/managed-source-view.mjs +959 -0
  394. package/tools/backends/memory-runtime.mjs +100 -0
  395. package/tools/backends/native-benchmark.mjs +88 -0
  396. package/tools/backends/native-managed-runtime.mjs +677 -0
  397. package/tools/backends/native-memory.mjs +768 -0
  398. package/tools/backends/native-node-memory.mjs +142 -0
  399. package/tools/backends/native-node-runner.mjs +99 -0
  400. package/tools/backends/native-node-watchdog.mjs +19 -0
  401. package/tools/backends/native-node-worker.mjs +75 -0
  402. package/tools/backends/stage3-targets.mjs +493 -0
  403. package/tools/bootstrap-command.el +13 -0
  404. package/tools/bootstrap-runtime.el +101 -0
  405. package/tools/bootstrap-seed.el +55 -0
  406. package/tools/project/check-cli.eli +31 -0
  407. package/tools/project/project-cli.eli +42 -0
  408. package/tools/project/project.eli +122 -0
  409. package/tools/runtime/unicode-case-profiles.mjs +13 -0
  410. package/tools/runtime/unicode-case-runtime.el +57 -0
  411. package/tools/testing/source-debugging-corpus-host.eli +16 -0
  412. package/tools/testing/source-debugging.eli +139 -0
  413. package/tools/testing/stdlib-bit-corpus-host.eli +21 -0
  414. package/tools/testing/stdlib-bit-corpus-host.mjs +118 -0
  415. package/tools/testing/stdlib-bit.eli +104 -0
  416. package/tools/testing/stdlib-bit.mjs +255 -0
  417. package/bin/eliscript-bootstrap +0 -15
@@ -0,0 +1,687 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const TOOL_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
9
+ export const DEFAULT_ROOT = path.resolve(TOOL_DIRECTORY, "../..");
10
+ const CONTRACT_FILE = "contracts/core-acceptance-corpus.json";
11
+ const RUN_RESULTS = new Set(["pass", "incomplete", "fail"]);
12
+
13
+ export class AcceptanceCorpusError extends Error {
14
+ constructor(errors) {
15
+ super(`core acceptance corpus validation failed:\n- ${errors.join("\n- ")}`);
16
+ this.name = "AcceptanceCorpusError";
17
+ this.errors = errors;
18
+ }
19
+ }
20
+
21
+ function isPlainObject(value) {
22
+ return value !== null && typeof value === "object" && !Array.isArray(value);
23
+ }
24
+
25
+ function safeRelativePath(value) {
26
+ return typeof value === "string" && value.length > 0 &&
27
+ !path.isAbsolute(value) &&
28
+ !value.split("/").includes("..") &&
29
+ path.posix.normalize(value) === value;
30
+ }
31
+
32
+ function sortedUnique(values) {
33
+ return [...new Set(values)].sort();
34
+ }
35
+
36
+ function equal(left, right) {
37
+ return JSON.stringify(left) === JSON.stringify(right);
38
+ }
39
+
40
+ function sha256(value) {
41
+ return createHash("sha256").update(value).digest("hex");
42
+ }
43
+
44
+ async function readJson(filename) {
45
+ return JSON.parse(await readFile(filename, "utf8"));
46
+ }
47
+
48
+ function extractCriteria(source, expression) {
49
+ return [...source.matchAll(expression)].map((match) => ({
50
+ id: match[1],
51
+ title: match[2].trim(),
52
+ }));
53
+ }
54
+
55
+ async function trackedFiles(root) {
56
+ const result = await capture(["git", "ls-files", "-z"], root, 30_000);
57
+ if (result.exitCode !== 0 || result.timedOut) {
58
+ throw new AcceptanceCorpusError([
59
+ "git ls-files could not enumerate corpus evidence",
60
+ ]);
61
+ }
62
+ return new Set(result.stdout.split("\0").filter(Boolean));
63
+ }
64
+
65
+ async function capture(argv, root, timeoutMs, env = process.env) {
66
+ const child = Bun.spawn(argv, {
67
+ cwd: root,
68
+ env,
69
+ stdout: "pipe",
70
+ stderr: "pipe",
71
+ });
72
+ let timedOut = false;
73
+ let forceKillTimer;
74
+ const timer = setTimeout(() => {
75
+ timedOut = true;
76
+ child.kill("SIGTERM");
77
+ forceKillTimer = setTimeout(() => child.kill("SIGKILL"), 2_000);
78
+ }, timeoutMs);
79
+ try {
80
+ const [exitCode, stdout, stderr] = await Promise.all([
81
+ child.exited,
82
+ new Response(child.stdout).text(),
83
+ new Response(child.stderr).text(),
84
+ ]);
85
+ return { exitCode, stdout, stderr, timedOut };
86
+ } finally {
87
+ clearTimeout(timer);
88
+ clearTimeout(forceKillTimer);
89
+ }
90
+ }
91
+
92
+ function validateStringArray(values, label, errors) {
93
+ if (!Array.isArray(values) || values.length === 0 ||
94
+ values.some((value) => typeof value !== "string" || value.length === 0)) {
95
+ errors.push(`${label} must be a non-empty string array`);
96
+ return [];
97
+ }
98
+ if (!equal(values, sortedUnique(values))) {
99
+ errors.push(`${label} must be unique and lexicographically sorted`);
100
+ }
101
+ return values;
102
+ }
103
+
104
+ export async function validateAcceptanceCorpus(contract, options = {}) {
105
+ const root = path.resolve(options.root ?? DEFAULT_ROOT);
106
+ const errors = [];
107
+ if (!isPlainObject(contract) || contract.schemaVersion !== 1 ||
108
+ contract.format !== "eliscript-core-acceptance-corpus" ||
109
+ contract.version !== 1) {
110
+ throw new AcceptanceCorpusError([
111
+ "contract must use eliscript-core-acceptance-corpus version 1",
112
+ ]);
113
+ }
114
+
115
+ const expectedSources = {
116
+ acceptance: "specs/0040-maturity-roadmap.md",
117
+ persistentData: "specs/0041-host-symbiosis-and-persistent-data.md",
118
+ progress: "contracts/maturity-progress.json",
119
+ };
120
+ if (!equal(contract.sources, expectedSources)) {
121
+ errors.push("sources must identify the normative acceptance and progress files");
122
+ }
123
+
124
+ const commands = Array.isArray(contract.commands) ? contract.commands : [];
125
+ const commandIds = commands.map((command) => command?.id);
126
+ if (commands.length === 0 || !equal(commandIds, sortedUnique(commandIds))) {
127
+ errors.push("command ids must be non-empty, unique, and sorted");
128
+ }
129
+ for (const [index, command] of commands.entries()) {
130
+ const label = `command ${index}`;
131
+ if (!isPlainObject(command) || typeof command.id !== "string" ||
132
+ !Array.isArray(command.argv) || command.argv.length === 0 ||
133
+ command.argv.some((part) => typeof part !== "string" || part.length === 0) ||
134
+ !Number.isInteger(command.timeoutMs) || command.timeoutMs < 1_000) {
135
+ errors.push(`${label} must declare id, argv, and a bounded timeout`);
136
+ }
137
+ }
138
+
139
+ let acceptanceSource = "";
140
+ let persistentDataSource = "";
141
+ let progress = {};
142
+ try {
143
+ [acceptanceSource, persistentDataSource, progress] = await Promise.all([
144
+ readFile(path.join(root, expectedSources.acceptance), "utf8"),
145
+ readFile(path.join(root, expectedSources.persistentData), "utf8"),
146
+ readJson(path.join(root, expectedSources.progress)),
147
+ ]);
148
+ } catch (error) {
149
+ errors.push(`normative source could not be read: ${error.message}`);
150
+ }
151
+
152
+ const acceptanceCriteria = extractCriteria(
153
+ acceptanceSource,
154
+ /^\*\*(AC-\d{2}) MUST - ([^*]+)\*\*$/gmu,
155
+ );
156
+ const persistentCriteria = extractCriteria(
157
+ persistentDataSource,
158
+ /^### (PD-\d{2}): (.+)$/gmu,
159
+ );
160
+ const expectedCriteria = [...acceptanceCriteria, ...persistentCriteria];
161
+ const criteria = Array.isArray(contract.criteria) ? contract.criteria : [];
162
+ const actualCriteria = criteria.map(({ id, title }) => ({ id, title }));
163
+ if (acceptanceCriteria.length === 0 || persistentCriteria.length === 0 ||
164
+ !equal(actualCriteria, expectedCriteria)) {
165
+ errors.push(
166
+ "criteria must exactly match the ordered AC and PD headings in the normative specifications",
167
+ );
168
+ }
169
+
170
+ const progressCriteria = Array.isArray(progress?.verification?.criteria)
171
+ ? progress.verification.criteria
172
+ : [];
173
+ if (!equal(
174
+ criteria.map((criterion) => criterion?.id),
175
+ progressCriteria.map((criterion) => criterion?.id),
176
+ )) {
177
+ errors.push("corpus and maturity progress criteria must have identical ids and order");
178
+ }
179
+
180
+ let files = new Set();
181
+ try {
182
+ files = await trackedFiles(root);
183
+ } catch (error) {
184
+ errors.push(...error.errors);
185
+ }
186
+ const referencedCommands = new Set();
187
+ for (const [index, criterion] of criteria.entries()) {
188
+ const expected = expectedCriteria[index];
189
+ const label = expected?.id ?? `criterion ${index}`;
190
+ if (!isPlainObject(criterion)) {
191
+ errors.push(`${label} must be an object`);
192
+ continue;
193
+ }
194
+ const expectedSpec = criterion.id?.startsWith("AC-") ? "0040" : "0041";
195
+ if (criterion.sourceSpec !== expectedSpec) {
196
+ errors.push(`${label} sourceSpec must be ${expectedSpec}`);
197
+ }
198
+ const probes = validateStringArray(criterion.probes, `${label} probes`, errors);
199
+ for (const probe of probes) {
200
+ referencedCommands.add(probe);
201
+ if (!commandIds.includes(probe)) {
202
+ errors.push(`${label} references unknown command ${probe}`);
203
+ }
204
+ }
205
+ const evidence = validateStringArray(
206
+ criterion.evidence,
207
+ `${label} evidence`,
208
+ errors,
209
+ );
210
+ for (const filename of evidence) {
211
+ if (!safeRelativePath(filename)) {
212
+ errors.push(`${label} has unsafe evidence path ${JSON.stringify(filename)}`);
213
+ continue;
214
+ }
215
+ if (!files.has(filename)) {
216
+ errors.push(`${label} evidence is not tracked: ${filename}`);
217
+ continue;
218
+ }
219
+ try {
220
+ const details = await stat(path.join(root, filename));
221
+ if (!details.isFile()) errors.push(`${label} evidence is not a file: ${filename}`);
222
+ } catch {
223
+ errors.push(`${label} evidence is missing: ${filename}`);
224
+ }
225
+ }
226
+ }
227
+ for (const id of commandIds) {
228
+ if (!referencedCommands.has(id)) errors.push(`command ${id} is not used by any criterion`);
229
+ }
230
+
231
+ const applications = extractCriteria(
232
+ acceptanceSource,
233
+ /^\*\*(AV-\d{2}) - ([^*]+)\*\*$/gmu,
234
+ );
235
+ const actualApplications = Array.isArray(contract.applications)
236
+ ? contract.applications.map(({ id, title }) => ({ id, title }))
237
+ : [];
238
+ if (!equal(actualApplications, applications) ||
239
+ contract.applications?.some((entry) => entry.contributesToCore !== false)) {
240
+ errors.push("applications must match AV headings and contribute no core evidence");
241
+ }
242
+
243
+ if (errors.length > 0) throw new AcceptanceCorpusError(errors);
244
+ return {
245
+ contract,
246
+ progress,
247
+ criteria: expectedCriteria,
248
+ applications,
249
+ };
250
+ }
251
+
252
+ export async function checkAcceptanceCorpus(options = {}) {
253
+ const root = path.resolve(options.root ?? DEFAULT_ROOT);
254
+ const contract = options.contract ??
255
+ await readJson(path.join(root, CONTRACT_FILE));
256
+ return validateAcceptanceCorpus(contract, { root });
257
+ }
258
+
259
+ function outputSummary(stdout, stderr) {
260
+ const lines = `${stdout}\n${stderr}`.split(/\r?\n/u)
261
+ .map((line) => line.trim())
262
+ .filter(Boolean);
263
+ return lines.slice(-3).join(" | ").slice(0, 600);
264
+ }
265
+
266
+ async function runProbe(command, root) {
267
+ const started = performance.now();
268
+ const result = await capture(command.argv, root, command.timeoutMs, {
269
+ ...process.env,
270
+ ELISCRIPT_SKIP_RETAINED_ACCEPTANCE: "1",
271
+ });
272
+ const output = `${result.stdout}\n${result.stderr}`;
273
+ return {
274
+ id: command.id,
275
+ argv: command.argv,
276
+ timeoutMs: command.timeoutMs,
277
+ status: !result.timedOut && result.exitCode === 0 ? "pass" : "fail",
278
+ exitCode: result.exitCode,
279
+ timedOut: result.timedOut,
280
+ durationMs: Math.round((performance.now() - started) * 1_000) / 1_000,
281
+ outputSha256: sha256(output),
282
+ summary: outputSummary(result.stdout, result.stderr),
283
+ };
284
+ }
285
+
286
+ async function commandText(argv, root) {
287
+ const result = await capture(argv, root, 30_000);
288
+ if (result.exitCode !== 0 || result.timedOut) {
289
+ throw new AcceptanceCorpusError([`${argv.join(" ")} could not be recorded`]);
290
+ }
291
+ return result.stdout.trim();
292
+ }
293
+
294
+ async function repositoryStatus(root) {
295
+ return commandText(["git", "status", "--short", "--untracked-files=all"], root);
296
+ }
297
+
298
+ async function environmentRecord(root) {
299
+ const [operatingSystem, bunVersion, nodeVersion, emacsVersion] = await Promise.all([
300
+ commandText(["uname", "-sr"], root),
301
+ commandText(["bun", "--version"], root),
302
+ commandText(["node", "--version"], root),
303
+ commandText(["emacs", "--batch", "-Q", "--eval", "(princ emacs-version)"], root),
304
+ ]);
305
+ return {
306
+ platform: process.platform,
307
+ architecture: process.arch,
308
+ operatingSystem,
309
+ bunVersion,
310
+ nodeVersion,
311
+ emacsVersion,
312
+ cpu: os.cpus()[0]?.model ?? "unknown",
313
+ };
314
+ }
315
+
316
+ async function artifactRecords(root, contract) {
317
+ const filenames = sortedUnique([
318
+ CONTRACT_FILE,
319
+ ...Object.values(contract.sources),
320
+ ...contract.criteria.flatMap((criterion) => criterion.evidence),
321
+ ]);
322
+ return Promise.all(filenames.map(async (file) => ({
323
+ file,
324
+ sha256: sha256(await readFile(path.join(root, file))),
325
+ })));
326
+ }
327
+
328
+ function countResults(criteria) {
329
+ const counts = { pass: 0, incomplete: 0, fail: 0, total: criteria.length };
330
+ for (const criterion of criteria) counts[criterion.result] += 1;
331
+ return counts;
332
+ }
333
+
334
+ export async function runAcceptanceCorpus(options = {}) {
335
+ const root = path.resolve(options.root ?? DEFAULT_ROOT);
336
+ const checked = await checkAcceptanceCorpus({ root, contract: options.contract });
337
+ const before = await repositoryStatus(root);
338
+ if (before.length > 0) {
339
+ throw new AcceptanceCorpusError([
340
+ "acceptance runs require a clean tracked and untracked worktree",
341
+ ]);
342
+ }
343
+
344
+ const source = {
345
+ commit: await commandText(["git", "rev-parse", "HEAD"], root),
346
+ tree: await commandText(["git", "rev-parse", "HEAD^{tree}"], root),
347
+ cleanBefore: true,
348
+ cleanAfter: false,
349
+ };
350
+ const commands = [];
351
+ for (const command of checked.contract.commands) {
352
+ commands.push(await runProbe(command, root));
353
+ }
354
+ source.cleanAfter = (await repositoryStatus(root)).length === 0;
355
+
356
+ const artifacts = await artifactRecords(root, checked.contract);
357
+ const commandResults = new Map(commands.map((command) => [command.id, command]));
358
+ const progressResults = new Map(
359
+ checked.progress.verification.criteria.map((criterion) => [criterion.id, criterion]),
360
+ );
361
+ const criteria = checked.contract.criteria.map((criterion) => {
362
+ const progress = progressResults.get(criterion.id);
363
+ const probesPassed = criterion.probes.every(
364
+ (id) => commandResults.get(id)?.status === "pass",
365
+ );
366
+ const result = !probesPassed
367
+ ? "fail"
368
+ : progress.status === "complete" ? "pass" : "incomplete";
369
+ return {
370
+ id: criterion.id,
371
+ title: criterion.title,
372
+ sourceSpec: criterion.sourceSpec,
373
+ result,
374
+ declaredStatus: progress.status,
375
+ probes: criterion.probes,
376
+ evidence: criterion.evidence,
377
+ ...(progress.remaining ? { remaining: progress.remaining } : {}),
378
+ };
379
+ });
380
+ const counts = countResults(criteria);
381
+ const operationalSuccess = commands.every((command) => command.status === "pass") &&
382
+ source.cleanBefore && source.cleanAfter;
383
+ const report = {
384
+ schemaVersion: 1,
385
+ format: "eliscript-core-acceptance-run",
386
+ version: 1,
387
+ generatedAt: new Date().toISOString(),
388
+ source,
389
+ environment: await environmentRecord(root),
390
+ corpus: {
391
+ contract: CONTRACT_FILE,
392
+ contractSha256: sha256(
393
+ await readFile(path.join(root, CONTRACT_FILE)),
394
+ ),
395
+ criterionCount: checked.contract.criteria.length,
396
+ },
397
+ commands,
398
+ artifacts,
399
+ criteria,
400
+ applications: checked.contract.applications.map((application) => ({
401
+ ...application,
402
+ result: "not-run",
403
+ })),
404
+ summary: {
405
+ criteria: counts,
406
+ corpusComplete: criteria.length === checked.criteria.length,
407
+ operationalSuccess,
408
+ acceptancePass: operationalSuccess && counts.pass === counts.total,
409
+ },
410
+ };
411
+
412
+ if (options.jsonOutput) {
413
+ const filename = path.resolve(root, options.jsonOutput);
414
+ await mkdir(path.dirname(filename), { recursive: true });
415
+ await writeFile(filename, `${JSON.stringify(report, null, 2)}\n`);
416
+ }
417
+ if (options.markdownOutput) {
418
+ const filename = path.resolve(root, options.markdownOutput);
419
+ await mkdir(path.dirname(filename), { recursive: true });
420
+ await writeFile(filename, humanRunReport(report));
421
+ }
422
+ if (options.requirePass && !report.summary.acceptancePass) {
423
+ throw new AcceptanceCorpusError([
424
+ "the complete corpus ran, but the final acceptance gate did not pass",
425
+ ]);
426
+ }
427
+ if (!report.summary.operationalSuccess) {
428
+ throw new AcceptanceCorpusError([
429
+ "one or more corpus commands failed or changed the repository",
430
+ ]);
431
+ }
432
+ return report;
433
+ }
434
+
435
+ function markdownCell(value) {
436
+ return String(value).replaceAll("|", "\\|").replaceAll("\n", " ");
437
+ }
438
+
439
+ export function humanRunReport(report) {
440
+ const lines = [
441
+ "# Core Acceptance Corpus Run",
442
+ "",
443
+ `- Source commit: \`${report.source.commit}\``,
444
+ `- Source tree: \`${report.source.tree}\``,
445
+ `- Generated: ${report.generatedAt}`,
446
+ `- Environment: ${report.environment.operatingSystem}; ${report.environment.architecture}; Bun ${report.environment.bunVersion}; Node ${report.environment.nodeVersion}; Emacs ${report.environment.emacsVersion}`,
447
+ `- Corpus complete: ${report.summary.corpusComplete ? "yes" : "no"}`,
448
+ `- Operational success: ${report.summary.operationalSuccess ? "yes" : "no"}`,
449
+ `- Final acceptance: ${report.summary.acceptancePass ? "pass" : "not reached"}`,
450
+ "",
451
+ "This is a retained maturity audit, not a final 1.0 acceptance claim. A",
452
+ "criterion remains incomplete until its complete normative wording is proven.",
453
+ "Application validations are reported separately and contribute no core result.",
454
+ "",
455
+ "## Commands",
456
+ "",
457
+ "| Probe | Command | Result | Exit | Duration (ms) | Output SHA-256 |",
458
+ "| --- | --- | --- | ---: | ---: | --- |",
459
+ ...report.commands.map((command) =>
460
+ `| ${command.id} | \`${markdownCell(command.argv.join(" "))}\` | ${command.status} | ${command.exitCode} | ${command.durationMs} | \`${command.outputSha256}\` |`),
461
+ "",
462
+ "## Mandatory Criteria",
463
+ "",
464
+ `Results: ${report.summary.criteria.pass} pass, ${report.summary.criteria.incomplete} incomplete, ${report.summary.criteria.fail} fail, ${report.summary.criteria.total} total.`,
465
+ "",
466
+ "| Criterion | Result | Declared state | Evidence | Remaining work |",
467
+ "| --- | --- | --- | --- | --- |",
468
+ ...report.criteria.map((criterion) =>
469
+ `| ${criterion.id} ${markdownCell(criterion.title)} | ${criterion.result} | ${criterion.declaredStatus} | ${criterion.evidence.map((file) => `\`${file}\``).join("<br>")} | ${markdownCell(criterion.remaining ?? "-")} |`),
470
+ "",
471
+ "## Application Validation",
472
+ "",
473
+ "| Criterion | Result | Core contribution |",
474
+ "| --- | --- | --- |",
475
+ ...report.applications.map((application) =>
476
+ `| ${application.id} ${markdownCell(application.title)} | ${application.result} | no |`),
477
+ "",
478
+ "## Artifact Digests",
479
+ "",
480
+ "| File | SHA-256 |",
481
+ "| --- | --- |",
482
+ ...report.artifacts.map((artifact) =>
483
+ `| \`${artifact.file}\` | \`${artifact.sha256}\` |`),
484
+ ];
485
+ return `${lines.join("\n")}\n`;
486
+ }
487
+
488
+ function validateRunShape(report, checked, errors) {
489
+ if (!isPlainObject(report) || report.schemaVersion !== 1 ||
490
+ report.format !== "eliscript-core-acceptance-run" || report.version !== 1) {
491
+ errors.push("run must use eliscript-core-acceptance-run version 1");
492
+ return;
493
+ }
494
+ if (!/^\d{4}-\d{2}-\d{2}T/u.test(report.generatedAt ?? "") ||
495
+ !/^[0-9a-f]{40}$/u.test(report.source?.commit ?? "") ||
496
+ !/^[0-9a-f]{40}$/u.test(report.source?.tree ?? "") ||
497
+ report.source?.cleanBefore !== true || report.source?.cleanAfter !== true) {
498
+ errors.push("run source identity and clean-worktree evidence are invalid");
499
+ }
500
+ if (!isPlainObject(report.environment) ||
501
+ ["platform", "architecture", "operatingSystem", "bunVersion", "nodeVersion", "emacsVersion", "cpu"]
502
+ .some((field) => typeof report.environment[field] !== "string" ||
503
+ report.environment[field].length === 0)) {
504
+ errors.push("run environment metadata is incomplete");
505
+ }
506
+ if (report.corpus?.contract !== CONTRACT_FILE ||
507
+ !/^[0-9a-f]{64}$/u.test(report.corpus?.contractSha256 ?? "") ||
508
+ report.corpus?.criterionCount !== checked.contract.criteria.length) {
509
+ errors.push("run corpus identity is invalid");
510
+ }
511
+ const expectedCommands = checked.contract.commands.map(({ id, argv, timeoutMs }) => ({
512
+ id,
513
+ argv,
514
+ timeoutMs,
515
+ }));
516
+ const actualCommands = Array.isArray(report.commands)
517
+ ? report.commands.map(({ id, argv, timeoutMs }) => ({ id, argv, timeoutMs }))
518
+ : [];
519
+ if (!equal(actualCommands, expectedCommands) || report.commands?.some((command) =>
520
+ !["pass", "fail"].includes(command.status) ||
521
+ !Number.isInteger(command.exitCode) || typeof command.timedOut !== "boolean" ||
522
+ typeof command.durationMs !== "number" || command.durationMs < 0 ||
523
+ !/^[0-9a-f]{64}$/u.test(command.outputSha256 ?? ""))) {
524
+ errors.push("run command records do not match the corpus contract");
525
+ }
526
+ const expectedCriteria = checked.contract.criteria.map(({ id, title, sourceSpec, probes, evidence }) => ({
527
+ id,
528
+ title,
529
+ sourceSpec,
530
+ probes,
531
+ evidence,
532
+ }));
533
+ const actualCriteria = Array.isArray(report.criteria)
534
+ ? report.criteria.map(({ id, title, sourceSpec, probes, evidence }) => ({
535
+ id,
536
+ title,
537
+ sourceSpec,
538
+ probes,
539
+ evidence,
540
+ }))
541
+ : [];
542
+ if (!equal(actualCriteria, expectedCriteria) || report.criteria?.some((criterion) =>
543
+ !RUN_RESULTS.has(criterion.result) ||
544
+ !["complete", "partial", "open", "blocked"].includes(criterion.declaredStatus))) {
545
+ errors.push("run criteria do not match the complete corpus contract");
546
+ }
547
+ const expectedArtifacts = sortedUnique([
548
+ CONTRACT_FILE,
549
+ ...Object.values(checked.contract.sources),
550
+ ...checked.contract.criteria.flatMap((criterion) => criterion.evidence),
551
+ ]);
552
+ if (!Array.isArray(report.artifacts) ||
553
+ !equal(report.artifacts.map((artifact) => artifact.file), expectedArtifacts) ||
554
+ report.artifacts.some((artifact) => !/^[0-9a-f]{64}$/u.test(artifact.sha256 ?? ""))) {
555
+ errors.push("run artifact digest inventory is incomplete or invalid");
556
+ }
557
+ const expectedApplications = checked.contract.applications.map((application) => ({
558
+ ...application,
559
+ result: "not-run",
560
+ }));
561
+ if (!equal(report.applications, expectedApplications)) {
562
+ errors.push("run application results must remain separate and non-contributing");
563
+ }
564
+ const counts = Array.isArray(report.criteria)
565
+ ? countResults(report.criteria)
566
+ : { pass: 0, incomplete: 0, fail: 0, total: 0 };
567
+ const operationalSuccess = report.commands?.every((command) => command.status === "pass") &&
568
+ report.source?.cleanBefore === true && report.source?.cleanAfter === true;
569
+ const expectedSummary = {
570
+ criteria: counts,
571
+ corpusComplete: counts.total === checked.contract.criteria.length,
572
+ operationalSuccess,
573
+ acceptancePass: operationalSuccess && counts.pass === counts.total,
574
+ };
575
+ if (!equal(report.summary, expectedSummary)) {
576
+ errors.push("run summary is not derived from recorded results");
577
+ }
578
+ }
579
+
580
+ export async function verifyAcceptanceRun(runFile, options = {}) {
581
+ const root = path.resolve(options.root ?? DEFAULT_ROOT);
582
+ const checked = await checkAcceptanceCorpus({ root, contract: options.contract });
583
+ const report = options.report ?? await readJson(path.resolve(root, runFile));
584
+ const errors = [];
585
+ validateRunShape(report, checked, errors);
586
+ const currentContractDigest = sha256(
587
+ await readFile(path.join(root, CONTRACT_FILE)),
588
+ );
589
+ if (report.corpus?.contractSha256 !== currentContractDigest) {
590
+ errors.push("run was produced from a different acceptance corpus contract");
591
+ }
592
+ if (options.markdownFile) {
593
+ const markdown = await readFile(path.resolve(root, options.markdownFile), "utf8");
594
+ if (markdown !== humanRunReport(report)) {
595
+ errors.push("human report does not match its machine-readable run");
596
+ }
597
+ }
598
+ if (errors.length > 0) throw new AcceptanceCorpusError(errors);
599
+ return report;
600
+ }
601
+
602
+ export function humanCorpusReport(checked) {
603
+ return [
604
+ `Core acceptance corpus: ${checked.criteria.length} mandatory criteria`,
605
+ `Commands: ${checked.contract.commands.map((command) => command.id).join(", ")}`,
606
+ `Applications: ${checked.applications.length} separate non-contributing validations`,
607
+ ].join("\n");
608
+ }
609
+
610
+ export function humanVerifiedRunReport(report) {
611
+ return [
612
+ `Verified core acceptance run: ${report.source.commit}`,
613
+ `Criteria: ${report.summary.criteria.pass}/${report.summary.criteria.total} pass, ${report.summary.criteria.incomplete} incomplete, ${report.summary.criteria.fail} fail`,
614
+ `Corpus complete: ${report.summary.corpusComplete ? "yes" : "no"}`,
615
+ `Operational success: ${report.summary.operationalSuccess ? "yes" : "no"}`,
616
+ `Final acceptance: ${report.summary.acceptancePass ? "pass" : "not reached"}`,
617
+ ].join("\n");
618
+ }
619
+
620
+ function parseArguments(argv) {
621
+ const options = {};
622
+ for (let index = 0; index < argv.length; index += 1) {
623
+ const argument = argv[index];
624
+ if (argument === "--run") options.run = true;
625
+ else if (argument === "--require-pass") options.requirePass = true;
626
+ else if (argument === "--json") options.json = true;
627
+ else if (["--json-output", "--markdown-output", "--verify-run", "--verify-markdown"].includes(argument)) {
628
+ const value = argv[index + 1];
629
+ if (!value) throw new AcceptanceCorpusError([`${argument} requires a path`]);
630
+ const key = {
631
+ "--json-output": "jsonOutput",
632
+ "--markdown-output": "markdownOutput",
633
+ "--verify-run": "verifyRun",
634
+ "--verify-markdown": "verifyMarkdown",
635
+ }[argument];
636
+ options[key] = value;
637
+ index += 1;
638
+ } else {
639
+ throw new AcceptanceCorpusError([`unknown argument ${argument}`]);
640
+ }
641
+ }
642
+ return options;
643
+ }
644
+
645
+ async function main() {
646
+ const options = parseArguments(process.argv.slice(2));
647
+ if (options.run) {
648
+ if (!options.jsonOutput || !options.markdownOutput) {
649
+ throw new AcceptanceCorpusError([
650
+ "--run requires --json-output and --markdown-output",
651
+ ]);
652
+ }
653
+ const report = await runAcceptanceCorpus(options);
654
+ process.stdout.write(options.json
655
+ ? `${JSON.stringify(report, null, 2)}\n`
656
+ : humanRunReport(report));
657
+ return;
658
+ }
659
+ if (options.verifyRun) {
660
+ const report = await verifyAcceptanceRun(options.verifyRun, {
661
+ markdownFile: options.verifyMarkdown,
662
+ });
663
+ process.stdout.write(options.json
664
+ ? `${JSON.stringify(report, null, 2)}\n`
665
+ : `${humanVerifiedRunReport(report)}\n`);
666
+ return;
667
+ }
668
+ const checked = await checkAcceptanceCorpus();
669
+ process.stdout.write(options.json
670
+ ? `${JSON.stringify({
671
+ format: "eliscript-core-acceptance-corpus-report",
672
+ version: 1,
673
+ criteria: checked.criteria.length,
674
+ commands: checked.contract.commands.map((command) => command.id),
675
+ applications: checked.applications.length,
676
+ }, null, 2)}\n`
677
+ : `${humanCorpusReport(checked)}\n`);
678
+ }
679
+
680
+ if (import.meta.main) {
681
+ try {
682
+ await main();
683
+ } catch (error) {
684
+ process.stderr.write(`${error.stack ?? error}\n`);
685
+ process.exitCode = 1;
686
+ }
687
+ }