agency-lang 0.1.3 → 0.2.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 (376) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/lib/agents/judge.js +12 -5
  4. package/dist/lib/agents/policy/agent.agency +29 -21
  5. package/dist/lib/agents/review/agent.js +12 -5
  6. package/dist/lib/backends/agencyGenerator.d.ts +10 -0
  7. package/dist/lib/backends/agencyGenerator.js +68 -11
  8. package/dist/lib/backends/agencyGenerator.test.js +27 -0
  9. package/dist/lib/backends/typescriptBuilder.d.ts +28 -0
  10. package/dist/lib/backends/typescriptBuilder.integration.test.js +5 -46
  11. package/dist/lib/backends/typescriptBuilder.js +151 -4
  12. package/dist/lib/backends/typescriptGenerator.integration.test.js +6 -52
  13. package/dist/lib/cli/commands.d.ts +6 -1
  14. package/dist/lib/cli/commands.js +76 -7
  15. package/dist/lib/cli/installLocation.d.ts +3 -0
  16. package/dist/lib/cli/installLocation.js +40 -0
  17. package/dist/lib/cli/installLocation.test.js +32 -0
  18. package/dist/lib/cli/logsView.d.ts +3 -0
  19. package/dist/lib/cli/logsView.js +96 -0
  20. package/dist/lib/cli/pack.d.ts +10 -0
  21. package/dist/lib/cli/pack.js +205 -0
  22. package/dist/lib/cli/pack.test.d.ts +1 -0
  23. package/dist/lib/cli/pack.test.js +131 -0
  24. package/dist/lib/cli/policy.js +31 -7
  25. package/dist/lib/cli/run.spawn.test.d.ts +1 -0
  26. package/dist/lib/cli/run.spawn.test.js +53 -0
  27. package/dist/lib/cli/runBundledAgent.js +10 -4
  28. package/dist/lib/cli/runShim/register.mjs +5 -0
  29. package/dist/lib/cli/runShim/resolver.mjs +59 -0
  30. package/dist/lib/cli/runShim/resolver.test.d.ts +1 -0
  31. package/dist/lib/cli/runShim/resolver.test.js +69 -0
  32. package/dist/lib/cli/schedule/backends/github.js +3 -0
  33. package/dist/lib/cli/test.js +8 -0
  34. package/dist/lib/codegenBuiltins/contextInjected.d.ts +56 -0
  35. package/dist/lib/codegenBuiltins/contextInjected.js +78 -0
  36. package/dist/lib/codegenBuiltins/contextInjected.test.d.ts +1 -0
  37. package/dist/lib/codegenBuiltins/contextInjected.test.js +57 -0
  38. package/dist/lib/compilationUnit.d.ts +8 -0
  39. package/dist/lib/compilationUnit.js +14 -0
  40. package/dist/lib/compiler/compile.js +1 -1
  41. package/dist/lib/compiler/compile.test.js +1 -1
  42. package/dist/lib/config.d.ts +158 -14
  43. package/dist/lib/config.js +51 -3
  44. package/dist/lib/config.test.js +67 -0
  45. package/dist/lib/constants.d.ts +20 -0
  46. package/dist/lib/constants.js +20 -0
  47. package/dist/lib/debugger/driver.js +12 -15
  48. package/dist/lib/debugger/driver.test.js +31 -13
  49. package/dist/lib/debugger/thread.test.js +3 -3
  50. package/dist/lib/debugger/trace.test.js +24 -38
  51. package/dist/lib/formatter.js +3 -1
  52. package/dist/lib/importPaths.d.ts +7 -1
  53. package/dist/lib/importPaths.js +43 -12
  54. package/dist/lib/logsViewer/clipboard.d.ts +6 -0
  55. package/dist/lib/logsViewer/clipboard.js +61 -0
  56. package/dist/lib/logsViewer/clipboard.test.d.ts +1 -0
  57. package/dist/lib/logsViewer/clipboard.test.js +60 -0
  58. package/dist/lib/logsViewer/conversation.d.ts +20 -0
  59. package/dist/lib/logsViewer/conversation.js +91 -0
  60. package/dist/lib/logsViewer/conversation.test.d.ts +1 -0
  61. package/dist/lib/logsViewer/conversation.test.js +59 -0
  62. package/dist/lib/logsViewer/follow.d.ts +9 -0
  63. package/dist/lib/logsViewer/follow.js +53 -0
  64. package/dist/lib/logsViewer/follow.test.d.ts +1 -0
  65. package/dist/lib/logsViewer/follow.test.js +70 -0
  66. package/dist/lib/logsViewer/help.d.ts +9 -0
  67. package/dist/lib/logsViewer/help.js +60 -0
  68. package/dist/lib/logsViewer/input.d.ts +15 -0
  69. package/dist/lib/logsViewer/input.js +187 -0
  70. package/dist/lib/logsViewer/input.test.d.ts +1 -0
  71. package/dist/lib/logsViewer/input.test.js +163 -0
  72. package/dist/lib/logsViewer/jsonView/build.d.ts +3 -0
  73. package/dist/lib/logsViewer/jsonView/build.js +70 -0
  74. package/dist/lib/logsViewer/jsonView/build.test.d.ts +1 -0
  75. package/dist/lib/logsViewer/jsonView/build.test.js +113 -0
  76. package/dist/lib/logsViewer/jsonView/input.d.ts +12 -0
  77. package/dist/lib/logsViewer/jsonView/input.js +111 -0
  78. package/dist/lib/logsViewer/jsonView/input.test.d.ts +1 -0
  79. package/dist/lib/logsViewer/jsonView/input.test.js +76 -0
  80. package/dist/lib/logsViewer/jsonView/render.d.ts +18 -0
  81. package/dist/lib/logsViewer/jsonView/render.js +221 -0
  82. package/dist/lib/logsViewer/jsonView/render.test.d.ts +1 -0
  83. package/dist/lib/logsViewer/jsonView/render.test.js +93 -0
  84. package/dist/lib/logsViewer/jsonView/types.d.ts +22 -0
  85. package/dist/lib/logsViewer/jsonView/types.js +3 -0
  86. package/dist/lib/logsViewer/parse.d.ts +11 -0
  87. package/dist/lib/logsViewer/parse.js +61 -0
  88. package/dist/lib/logsViewer/parse.test.d.ts +1 -0
  89. package/dist/lib/logsViewer/parse.test.js +67 -0
  90. package/dist/lib/logsViewer/render.d.ts +20 -0
  91. package/dist/lib/logsViewer/render.js +243 -0
  92. package/dist/lib/logsViewer/render.test.d.ts +1 -0
  93. package/dist/lib/logsViewer/render.test.js +184 -0
  94. package/dist/lib/logsViewer/run.d.ts +16 -0
  95. package/dist/lib/logsViewer/run.js +293 -0
  96. package/dist/lib/logsViewer/run.test.d.ts +1 -0
  97. package/dist/lib/logsViewer/run.test.js +158 -0
  98. package/dist/lib/logsViewer/search.d.ts +8 -0
  99. package/dist/lib/logsViewer/search.js +119 -0
  100. package/dist/lib/logsViewer/search.test.d.ts +1 -0
  101. package/dist/lib/logsViewer/search.test.js +180 -0
  102. package/dist/lib/logsViewer/summary.d.ts +7 -0
  103. package/dist/lib/logsViewer/summary.js +153 -0
  104. package/dist/lib/logsViewer/summary.test.d.ts +1 -0
  105. package/dist/lib/logsViewer/summary.test.js +155 -0
  106. package/dist/lib/logsViewer/thresholds.d.ts +9 -0
  107. package/dist/lib/logsViewer/thresholds.js +22 -0
  108. package/dist/lib/logsViewer/thresholds.test.d.ts +1 -0
  109. package/dist/lib/logsViewer/thresholds.test.js +26 -0
  110. package/dist/lib/logsViewer/tree.d.ts +2 -0
  111. package/dist/lib/logsViewer/tree.js +247 -0
  112. package/dist/lib/logsViewer/tree.test.d.ts +1 -0
  113. package/dist/lib/logsViewer/tree.test.js +277 -0
  114. package/dist/lib/logsViewer/types.d.ts +40 -0
  115. package/dist/lib/logsViewer/types.js +1 -0
  116. package/dist/lib/lowering/patternLowering.d.ts +18 -0
  117. package/dist/lib/lowering/patternLowering.js +631 -0
  118. package/dist/lib/lowering/patternLowering.test.d.ts +8 -0
  119. package/dist/lib/lowering/patternLowering.test.js +383 -0
  120. package/dist/lib/lsp/builtinHover.d.ts +20 -0
  121. package/dist/lib/lsp/builtinHover.js +85 -0
  122. package/dist/lib/lsp/diagnostics.js +53 -0
  123. package/dist/lib/lsp/diagnostics.test.js +34 -0
  124. package/dist/lib/lsp/hover.js +41 -0
  125. package/dist/lib/lsp/hover.test.js +43 -0
  126. package/dist/lib/parser.d.ts +1 -1
  127. package/dist/lib/parser.js +27 -2
  128. package/dist/lib/parsers/parsers.d.ts +9 -0
  129. package/dist/lib/parsers/parsers.js +145 -8
  130. package/dist/lib/parsers/pattern.test.d.ts +1 -0
  131. package/dist/lib/parsers/pattern.test.js +672 -0
  132. package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +0 -551
  133. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -8
  134. package/dist/lib/preprocessors/typescriptPreprocessor.integration.test.js +6 -50
  135. package/dist/lib/preprocessors/typescriptPreprocessor.js +0 -192
  136. package/dist/lib/runtime/deterministicClient.d.ts +2 -1
  137. package/dist/lib/runtime/deterministicClient.js +12 -0
  138. package/dist/lib/runtime/interrupts.d.ts +1 -0
  139. package/dist/lib/runtime/interrupts.js +179 -76
  140. package/dist/lib/runtime/llmClient.d.ts +19 -0
  141. package/dist/lib/runtime/llmClient.js +9 -0
  142. package/dist/lib/runtime/memory/cacheEntry.d.ts +113 -0
  143. package/dist/lib/runtime/memory/cacheEntry.js +153 -0
  144. package/dist/lib/runtime/memory/cacheEntry.test.d.ts +1 -0
  145. package/dist/lib/runtime/memory/cacheEntry.test.js +136 -0
  146. package/dist/lib/runtime/memory/compaction.d.ts +21 -0
  147. package/dist/lib/runtime/memory/compaction.js +46 -0
  148. package/dist/lib/runtime/memory/compaction.test.d.ts +1 -0
  149. package/dist/lib/runtime/memory/compaction.test.js +87 -0
  150. package/dist/lib/runtime/memory/embeddings.d.ts +18 -0
  151. package/dist/lib/runtime/memory/embeddings.js +59 -0
  152. package/dist/lib/runtime/memory/embeddings.test.d.ts +1 -0
  153. package/dist/lib/runtime/memory/embeddings.test.js +65 -0
  154. package/dist/lib/runtime/memory/extraction.d.ts +43 -0
  155. package/dist/lib/runtime/memory/extraction.js +88 -0
  156. package/dist/lib/runtime/memory/extraction.test.d.ts +1 -0
  157. package/dist/lib/runtime/memory/extraction.test.js +85 -0
  158. package/dist/lib/runtime/memory/graph.d.ts +24 -0
  159. package/dist/lib/runtime/memory/graph.js +126 -0
  160. package/dist/lib/runtime/memory/graph.test.d.ts +1 -0
  161. package/dist/lib/runtime/memory/graph.test.js +106 -0
  162. package/dist/lib/runtime/memory/index.d.ts +9 -0
  163. package/dist/lib/runtime/memory/index.js +6 -0
  164. package/dist/lib/runtime/memory/manager.d.ts +217 -0
  165. package/dist/lib/runtime/memory/manager.js +1012 -0
  166. package/dist/lib/runtime/memory/manager.test.d.ts +1 -0
  167. package/dist/lib/runtime/memory/manager.test.js +446 -0
  168. package/dist/lib/runtime/memory/retrieval.d.ts +8 -0
  169. package/dist/lib/runtime/memory/retrieval.js +106 -0
  170. package/dist/lib/runtime/memory/retrieval.test.d.ts +1 -0
  171. package/dist/lib/runtime/memory/retrieval.test.js +118 -0
  172. package/dist/lib/runtime/memory/store.d.ts +21 -0
  173. package/dist/lib/runtime/memory/store.js +105 -0
  174. package/dist/lib/runtime/memory/store.test.d.ts +1 -0
  175. package/dist/lib/runtime/memory/store.test.js +111 -0
  176. package/dist/lib/runtime/memory/types.d.ts +129 -0
  177. package/dist/lib/runtime/memory/types.js +69 -0
  178. package/dist/lib/runtime/node.js +69 -4
  179. package/dist/lib/runtime/prompt.js +231 -97
  180. package/dist/lib/runtime/rewind.js +9 -1
  181. package/dist/lib/runtime/runner.d.ts +11 -0
  182. package/dist/lib/runtime/runner.js +183 -39
  183. package/dist/lib/runtime/simpleOpenAIClient.d.ts +2 -1
  184. package/dist/lib/runtime/simpleOpenAIClient.js +32 -0
  185. package/dist/lib/runtime/state/context.d.ts +21 -0
  186. package/dist/lib/runtime/state/context.js +63 -0
  187. package/dist/lib/runtime/state/threadStore.d.ts +4 -1
  188. package/dist/lib/runtime/state/threadStore.js +22 -1
  189. package/dist/lib/runtime/trace/contentAddressableStore.d.ts +10 -0
  190. package/dist/lib/runtime/trace/contentAddressableStore.js +13 -0
  191. package/dist/lib/runtime/trace/contentAddressableStore.test.js +19 -0
  192. package/dist/lib/runtime/trace/sinks.js +13 -1
  193. package/dist/lib/runtime/trace/traceWriter.d.ts +41 -1
  194. package/dist/lib/runtime/trace/traceWriter.js +96 -11
  195. package/dist/lib/runtime/trace/traceWriter.test.js +145 -1
  196. package/dist/lib/runtime/trace/types.d.ts +22 -0
  197. package/dist/lib/simplemachine/graph.d.ts +2 -0
  198. package/dist/lib/simplemachine/graph.js +28 -19
  199. package/dist/lib/simplemachine/types.d.ts +2 -0
  200. package/dist/lib/statelogClient.d.ts +224 -2
  201. package/dist/lib/statelogClient.js +390 -10
  202. package/dist/lib/statelogClient.test.d.ts +1 -0
  203. package/dist/lib/statelogClient.test.js +697 -0
  204. package/dist/lib/stdlib/agency.js +1 -1
  205. package/dist/lib/stdlib/builtins.d.ts +1 -0
  206. package/dist/lib/stdlib/builtins.js +3 -0
  207. package/dist/lib/stdlib/memory.d.ts +24 -0
  208. package/dist/lib/stdlib/memory.js +56 -0
  209. package/dist/lib/templates/backends/agency/template.d.ts +1 -1
  210. package/dist/lib/templates/backends/agency/template.js +1 -1
  211. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +2 -1
  212. package/dist/lib/templates/backends/typescriptGenerator/imports.js +11 -1
  213. package/dist/lib/templates/cli/schedule/githubWorkflow.d.ts +2 -1
  214. package/dist/lib/templates/cli/schedule/githubWorkflow.js +1 -1
  215. package/dist/lib/templates/prompts/memory/compaction.d.ts +6 -0
  216. package/dist/lib/templates/prompts/memory/compaction.js +15 -0
  217. package/dist/lib/templates/prompts/memory/extraction.d.ts +7 -0
  218. package/dist/lib/templates/prompts/memory/extraction.js +20 -0
  219. package/dist/lib/templates/prompts/memory/forget.d.ts +7 -0
  220. package/dist/lib/templates/prompts/memory/forget.js +21 -0
  221. package/dist/lib/templates/prompts/memory/mergeSummary.d.ts +7 -0
  222. package/dist/lib/templates/prompts/memory/mergeSummary.js +18 -0
  223. package/dist/lib/templates/prompts/memory/retrieval.d.ts +7 -0
  224. package/dist/lib/templates/prompts/memory/retrieval.js +25 -0
  225. package/dist/lib/tui/builders.d.ts +3 -1
  226. package/dist/lib/tui/builders.js +14 -0
  227. package/dist/lib/tui/builders.test.d.ts +1 -0
  228. package/dist/lib/tui/builders.test.js +38 -0
  229. package/dist/lib/tui/colors.d.ts +7 -0
  230. package/dist/lib/tui/colors.js +11 -0
  231. package/dist/lib/tui/elements.d.ts +12 -4
  232. package/dist/lib/tui/index.d.ts +3 -0
  233. package/dist/lib/tui/index.js +3 -0
  234. package/dist/lib/tui/input/format.d.ts +3 -0
  235. package/dist/lib/tui/input/format.js +37 -0
  236. package/dist/lib/tui/input/format.test.d.ts +1 -0
  237. package/dist/lib/tui/input/format.test.js +26 -0
  238. package/dist/lib/tui/input/scripted.d.ts +5 -0
  239. package/dist/lib/tui/input/scripted.js +11 -0
  240. package/dist/lib/tui/input/terminal.d.ts +5 -0
  241. package/dist/lib/tui/input/terminal.js +51 -0
  242. package/dist/lib/tui/output/recorder.d.ts +2 -0
  243. package/dist/lib/tui/output/recorder.js +12 -0
  244. package/dist/lib/tui/render/renderer.js +16 -3
  245. package/dist/lib/tui/screen.d.ts +7 -0
  246. package/dist/lib/tui/screen.js +10 -0
  247. package/dist/lib/tui/scroll.d.ts +2 -0
  248. package/dist/lib/tui/scroll.js +26 -0
  249. package/dist/lib/tui/scroll.test.d.ts +1 -0
  250. package/dist/lib/tui/scroll.test.js +30 -0
  251. package/dist/lib/tui/scrollList.d.ts +28 -0
  252. package/dist/lib/tui/scrollList.js +29 -0
  253. package/dist/lib/tui/scrollList.test.d.ts +1 -0
  254. package/dist/lib/tui/scrollList.test.js +78 -0
  255. package/dist/lib/typeChecker/assignability.js +12 -0
  256. package/dist/lib/typeChecker/blockBody.test.js +3 -1
  257. package/dist/lib/typeChecker/builtinSignatures.test.d.ts +1 -0
  258. package/dist/lib/typeChecker/builtinSignatures.test.js +51 -0
  259. package/dist/lib/typeChecker/builtins.d.ts +8 -5
  260. package/dist/lib/typeChecker/builtins.js +35 -25
  261. package/dist/lib/typeChecker/checker.js +94 -35
  262. package/dist/lib/typeChecker/constReassignment.test.d.ts +1 -0
  263. package/dist/lib/typeChecker/constReassignment.test.js +88 -0
  264. package/dist/lib/typeChecker/fixtureTypeCheck.integration.test.d.ts +1 -0
  265. package/dist/lib/typeChecker/fixtureTypeCheck.integration.test.js +72 -0
  266. package/dist/lib/typeChecker/index.d.ts +1 -0
  267. package/dist/lib/typeChecker/index.js +30 -22
  268. package/dist/lib/typeChecker/jsGlobalsSig.test.d.ts +1 -0
  269. package/dist/lib/typeChecker/jsGlobalsSig.test.js +100 -0
  270. package/dist/lib/typeChecker/primitiveMembers.d.ts +80 -0
  271. package/dist/lib/typeChecker/primitiveMembers.js +183 -0
  272. package/dist/lib/typeChecker/primitiveMembers.test.d.ts +1 -0
  273. package/dist/lib/typeChecker/primitiveMembers.test.js +56 -0
  274. package/dist/lib/typeChecker/primitiveMembersIntegration.test.d.ts +1 -0
  275. package/dist/lib/typeChecker/primitiveMembersIntegration.test.js +171 -0
  276. package/dist/lib/typeChecker/reservedNameDeclaration.test.d.ts +1 -0
  277. package/dist/lib/typeChecker/reservedNameDeclaration.test.js +57 -0
  278. package/dist/lib/typeChecker/resolveCall.d.ts +160 -0
  279. package/dist/lib/typeChecker/resolveCall.js +292 -0
  280. package/dist/lib/typeChecker/resolveCall.test.d.ts +1 -0
  281. package/dist/lib/typeChecker/resolveCall.test.js +115 -0
  282. package/dist/lib/typeChecker/resolveVariable.d.ts +77 -0
  283. package/dist/lib/typeChecker/resolveVariable.js +37 -0
  284. package/dist/lib/typeChecker/schemaType.test.d.ts +1 -0
  285. package/dist/lib/typeChecker/schemaType.test.js +79 -0
  286. package/dist/lib/typeChecker/scope.d.ts +14 -1
  287. package/dist/lib/typeChecker/scope.js +28 -2
  288. package/dist/lib/typeChecker/scope.test.js +16 -0
  289. package/dist/lib/typeChecker/scopes.js +121 -3
  290. package/dist/lib/typeChecker/shadowing.d.ts +11 -0
  291. package/dist/lib/typeChecker/shadowing.js +19 -0
  292. package/dist/lib/typeChecker/suppression.test.js +3 -1
  293. package/dist/lib/typeChecker/synthesizer.js +268 -4
  294. package/dist/lib/typeChecker/typeWalker.js +2 -0
  295. package/dist/lib/typeChecker/types.d.ts +2 -0
  296. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.d.ts +15 -0
  297. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.js +138 -0
  298. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.test.d.ts +1 -0
  299. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.test.js +273 -0
  300. package/dist/lib/typeChecker/undefinedVariableDiagnostic.d.ts +29 -0
  301. package/dist/lib/typeChecker/undefinedVariableDiagnostic.js +129 -0
  302. package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.d.ts +1 -0
  303. package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.js +80 -0
  304. package/dist/lib/typeChecker.test.js +38 -63
  305. package/dist/lib/types/forLoop.d.ts +2 -1
  306. package/dist/lib/types/matchBlock.d.ts +4 -2
  307. package/dist/lib/types/pattern.d.ts +35 -0
  308. package/dist/lib/types/pattern.js +1 -0
  309. package/dist/lib/types/typeHints.d.ts +12 -1
  310. package/dist/lib/types.d.ts +5 -2
  311. package/dist/lib/types.js +1 -0
  312. package/dist/lib/utils/formatType.js +2 -0
  313. package/dist/lib/utils/mapBodies.d.ts +20 -0
  314. package/dist/lib/utils/mapBodies.js +48 -0
  315. package/dist/scripts/agency.js +56 -3
  316. package/dist/tests/fixtureDiscovery.d.ts +25 -0
  317. package/dist/tests/fixtureDiscovery.js +60 -0
  318. package/package.json +4 -4
  319. package/stdlib/agency.js +12 -5
  320. package/stdlib/agent.js +12 -5
  321. package/stdlib/array.js +12 -5
  322. package/stdlib/browser.js +12 -5
  323. package/stdlib/calendar.js +12 -5
  324. package/stdlib/clipboard.js +12 -5
  325. package/stdlib/date.js +12 -5
  326. package/stdlib/email.js +12 -5
  327. package/stdlib/fs.js +12 -5
  328. package/stdlib/http.js +12 -5
  329. package/stdlib/imessage.js +12 -5
  330. package/stdlib/index.agency +8 -1
  331. package/stdlib/index.js +122 -6
  332. package/stdlib/keyring.js +12 -5
  333. package/stdlib/math.js +12 -5
  334. package/stdlib/memory.agency +92 -0
  335. package/stdlib/memory.js +690 -0
  336. package/stdlib/oauth.js +12 -5
  337. package/stdlib/object.js +12 -5
  338. package/stdlib/path.js +12 -5
  339. package/stdlib/policy.js +12 -5
  340. package/stdlib/shell.js +12 -5
  341. package/stdlib/sms.js +12 -5
  342. package/stdlib/speech.js +12 -5
  343. package/stdlib/strategy.js +12 -5
  344. package/stdlib/system.js +12 -5
  345. package/stdlib/ui.js +12 -5
  346. package/stdlib/weather.js +12 -5
  347. package/stdlib/wikipedia.js +12 -5
  348. package/dist/lib/agents/policy/agent.js +0 -736
  349. package/dist/lib/preprocessors/typescriptPreprocessor.test.js +0 -283
  350. package/stdlib/lib/allowBlockList.js +0 -37
  351. package/stdlib/lib/browserUse.js +0 -75
  352. package/stdlib/lib/builtins.js +0 -117
  353. package/stdlib/lib/calendar.js +0 -145
  354. package/stdlib/lib/clipboard.js +0 -41
  355. package/stdlib/lib/date.js +0 -196
  356. package/stdlib/lib/email.js +0 -145
  357. package/stdlib/lib/fs.js +0 -285
  358. package/stdlib/lib/http.js +0 -132
  359. package/stdlib/lib/imessage.js +0 -49
  360. package/stdlib/lib/keyring.js +0 -159
  361. package/stdlib/lib/messaging.js +0 -1
  362. package/stdlib/lib/oauth.js +0 -288
  363. package/stdlib/lib/oauthEncryption.js +0 -69
  364. package/stdlib/lib/path.js +0 -22
  365. package/stdlib/lib/policy.js +0 -1
  366. package/stdlib/lib/resolvePath.js +0 -43
  367. package/stdlib/lib/shell.js +0 -298
  368. package/stdlib/lib/sms.js +0 -47
  369. package/stdlib/lib/speech.js +0 -129
  370. package/stdlib/lib/syntax.js +0 -75
  371. package/stdlib/lib/system.js +0 -67
  372. package/stdlib/lib/ui.js +0 -393
  373. package/stdlib/lib/utils.js +0 -51
  374. package/stdlib/lib/weather.js +0 -94
  375. package/stdlib/lib/wikipedia.js +0 -47
  376. /package/dist/lib/{preprocessors/typescriptPreprocessor.test.d.ts → cli/installLocation.test.d.ts} +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aditya Bhargava
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -32,4 +32,4 @@ Now read [the docs](https://agency-lang.com) to learn more about the language an
32
32
  Weather data in the standard library (`std::weather`) is provided by [Open-Meteo](https://open-meteo.com/). Data is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The free API is for non-commercial use only; commercial use requires a [paid subscription](https://open-meteo.com/en/pricing).
33
33
 
34
34
  ## License
35
- [FSL](https://fsl.software).
35
+ MIT. See [LICENSE](./LICENSE).
@@ -1,4 +1,4 @@
1
- import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
1
+ import { print, printJSON, parseJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
2
2
  import { fileURLToPath } from "url";
3
3
  import __process from "process";
4
4
  import { z } from "agency-lang/zod";
@@ -39,7 +39,9 @@ const __globalCtx = new RuntimeContext({
39
39
  host: "https://statelog.adit.io",
40
40
  apiKey: __process.env["STATELOG_API_KEY"] || "",
41
41
  projectId: "agency-lang",
42
- debugMode: false
42
+ debugMode: false,
43
+ observability: true,
44
+ logFile: "statelog.log"
43
45
  },
44
46
  smoltalkDefaults: {
45
47
  openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
@@ -54,9 +56,13 @@ const __globalCtx = new RuntimeContext({
54
56
  }
55
57
  },
56
58
  dirname: __dirname,
59
+ logLevel: "info",
57
60
  traceConfig: {
58
61
  program: "dist/lib/agents/judge.agency",
59
62
  traceDir: "traces"
63
+ },
64
+ memory: {
65
+ dir: ".agency-memory"
60
66
  }
61
67
  });
62
68
  const graph = __globalCtx.graph;
@@ -77,8 +83,8 @@ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __global
77
83
  const __setDebugger = (dbg) => {
78
84
  __globalCtx.debuggerState = dbg;
79
85
  };
80
- const __setTraceWriter = (tw) => {
81
- __globalCtx.traceWriter = tw;
86
+ const __setTraceFile = (filePath) => {
87
+ __globalCtx.traceConfig.traceFile = filePath;
82
88
  };
83
89
  const __setLLMClient = (client) => {
84
90
  __globalCtx.setLLMClient(client);
@@ -111,6 +117,7 @@ function registerTools(tools) {
111
117
  }
112
118
  __registerTool(print);
113
119
  __registerTool(printJSON);
120
+ __registerTool(parseJSON);
114
121
  __registerTool(input);
115
122
  __registerTool(sleep);
116
123
  __registerTool(round);
@@ -253,7 +260,7 @@ export {
253
260
  __judgeNodeParams,
254
261
  __setDebugger,
255
262
  __setLLMClient,
256
- __setTraceWriter,
263
+ __setTraceFile,
257
264
  __sourceMap,
258
265
  __toolRegistry,
259
266
  approve,
@@ -1,38 +1,44 @@
1
+ import { map } from "std::array"
1
2
  import { writePolicyFile } from "std::policy"
2
3
  import { args } from "std::system"
3
4
 
4
5
  systemPrompt = read("./prompts/system.md")
5
6
 
6
- type NextStep = { type: "showPolicy"; policy: object } | { type: "writePolicy"; policy: object } | { type: "askQuestion"; question: string }
7
+ type NextStep =
8
+ | { type: "showPolicy"; policy: object }
9
+ | { type: "writePolicy"; policy: object }
10
+ | { type: "askQuestion"; question: string }
11
+
12
+ def get(array: any[], index: number) {
13
+ if (index < array.length) {
14
+ return success(array[index])
15
+ }
16
+ return failure("Index out of bounds: ${index} >= ${array.length}")
17
+ }
7
18
 
8
19
  node main() {
9
- let cliArgs = args()
20
+ const cliArgs = args()
10
21
  if (cliArgs.length < 2) {
11
22
  print("Usage: agency policy gen <file>")
12
23
  return end()
13
24
  }
14
- let interruptKindsJson = cliArgs[0]
15
- let outputPath = cliArgs[1]
16
- let existingPolicyJson = ""
17
- if (cliArgs.length >= 3) {
18
- existingPolicyJson = cliArgs[2]
19
- }
25
+ print(cliArgs)
20
26
 
21
- let interruptKinds = parseJSON(interruptKindsJson)
22
- let existingPolicy = null
23
- if (existingPolicyJson != "") {
24
- existingPolicy = parseJSON(existingPolicyJson)
25
- }
27
+ const interruptKinds = cliArgs[0] |> parseJSON
28
+ const outputPath = cliArgs[1]
29
+ const existingPolicy = get(cliArgs, 3) |> parseJSON
26
30
 
27
- let contextMessage = "This agent can produce the following interrupts:\n"
28
- for (kind in interruptKinds) {
29
- contextMessage = contextMessage + "- ${kind}\n"
31
+ if (isFailure(interruptKinds)) {
32
+ print("Failed to parse interrupt kinds: ${interruptKinds.error}")
33
+ return null
30
34
  }
31
35
 
36
+ let contextMessage = "This agent can produce the following interrupts:\n" + map(interruptKinds, kind -> `- ${kind}\n`).join("")
37
+
32
38
  if (existingPolicy != null) {
33
39
  contextMessage = contextMessage + """
34
- Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
35
- """
40
+ Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
41
+ """
36
42
  } else {
37
43
  contextMessage = contextMessage + "\nWhat actions would you like to allow?"
38
44
  }
@@ -48,9 +54,11 @@ node main() {
48
54
 
49
55
  thread {
50
56
  system(systemPrompt)
51
- let step: NextStep = llm("""
52
- ${conversationHistory}\n\nCurrent policy: ${printJSON(policy)}\n\nDecide the next step. If the user is describing what they want, build or update the policy and use showPolicy. If the user approves the shown policy, use writePolicy. If you need clarification, use askQuestion.
53
- """)
57
+ let step: NextStep = llm(
58
+ """
59
+ ${conversationHistory}\n\nCurrent policy: ${printJSON(policy)}\n\nDecide the next step. If the user is describing what they want, build or update the policy and use showPolicy. If the user approves the shown policy, use writePolicy. If you need clarification, use askQuestion.
60
+ """,
61
+ )
54
62
  }
55
63
 
56
64
  if (step.type == "showPolicy") {
@@ -1,4 +1,4 @@
1
- import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
1
+ import { print, printJSON, parseJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
2
2
  import { exec } from "agency-lang/stdlib/shell.js";
3
3
  import { args } from "agency-lang/stdlib/system.js";
4
4
  import { fileURLToPath } from "url";
@@ -44,7 +44,9 @@ const __globalCtx = new RuntimeContext({
44
44
  host: "https://statelog.adit.io",
45
45
  apiKey: __process.env["STATELOG_API_KEY"] || "",
46
46
  projectId: "agency-lang",
47
- debugMode: false
47
+ debugMode: false,
48
+ observability: true,
49
+ logFile: "statelog.log"
48
50
  },
49
51
  smoltalkDefaults: {
50
52
  openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
@@ -59,9 +61,13 @@ const __globalCtx = new RuntimeContext({
59
61
  }
60
62
  },
61
63
  dirname: __dirname,
64
+ logLevel: "info",
62
65
  traceConfig: {
63
66
  program: "dist/lib/agents/review/agent.agency",
64
67
  traceDir: "traces"
68
+ },
69
+ memory: {
70
+ dir: ".agency-memory"
65
71
  }
66
72
  });
67
73
  const graph = __globalCtx.graph;
@@ -82,8 +88,8 @@ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __global
82
88
  const __setDebugger = (dbg) => {
83
89
  __globalCtx.debuggerState = dbg;
84
90
  };
85
- const __setTraceWriter = (tw) => {
86
- __globalCtx.traceWriter = tw;
91
+ const __setTraceFile = (filePath) => {
92
+ __globalCtx.traceConfig.traceFile = filePath;
87
93
  };
88
94
  const __setLLMClient = (client) => {
89
95
  __globalCtx.setLLMClient(client);
@@ -116,6 +122,7 @@ function registerTools(tools) {
116
122
  }
117
123
  __registerTool(print);
118
124
  __registerTool(printJSON);
125
+ __registerTool(parseJSON);
119
126
  __registerTool(input);
120
127
  __registerTool(sleep);
121
128
  __registerTool(round);
@@ -752,7 +759,7 @@ export {
752
759
  __mainNodeParams,
753
760
  __setDebugger,
754
761
  __setLLMClient,
755
- __setTraceWriter,
762
+ __setTraceFile,
756
763
  __sourceMap,
757
764
  __toolRegistry,
758
765
  approve,
@@ -20,6 +20,7 @@ import { Keyword } from "../types/keyword.js";
20
20
  import { HandleBlock } from "../types/handleBlock.js";
21
21
  import { Tag } from "../types/tag.js";
22
22
  import { ClassDefinition, NewExpression } from "../types/classDefinition.js";
23
+ import { BindingPattern, MatchPattern } from "../types/pattern.js";
23
24
  export declare class AgencyGenerator {
24
25
  protected graphNodes: GraphNodeDefinition[];
25
26
  protected generatedStatements: string[];
@@ -70,6 +71,15 @@ export declare class AgencyGenerator {
70
71
  protected aliasedTypeToString(aliasedType: VariableType): string;
71
72
  protected processTypeAlias(node: TypeAlias): string;
72
73
  protected processAssignment(node: Assignment): string;
74
+ /**
75
+ * Format a pattern AST node back into Agency pattern syntax. Used by the
76
+ * formatter (it sees the un-lowered AST). Handles binding patterns and
77
+ * match patterns; for match patterns, literal sub-nodes are formatted via
78
+ * the existing literal/expression code paths.
79
+ */
80
+ protected formatPattern(pattern: BindingPattern | MatchPattern): string;
81
+ private formatObjectPattern;
82
+ private formatArrayPattern;
73
83
  protected generateLiteral(literal: Literal): string;
74
84
  private generateStringLiteral;
75
85
  private generateMultiLineStringLiteral;
@@ -3,7 +3,6 @@ import { formatUnitLiteral, } from "../types.js";
3
3
  import { variableTypeToString } from "./typescriptGenerator/typeToString.js";
4
4
  import { mergeDeep } from "../utils.js";
5
5
  import { PRECEDENCE, } from "../types/binop.js";
6
- import { expressionToString } from "../utils/node.js";
7
6
  export class AgencyGenerator {
8
7
  graphNodes = [];
9
8
  generatedStatements = [];
@@ -203,6 +202,13 @@ export class AgencyGenerator {
203
202
  return `re/${node.pattern}/${node.flags}`;
204
203
  case "interruptStatement":
205
204
  return this.processInterruptStatement(node);
205
+ case "objectPattern":
206
+ case "arrayPattern":
207
+ case "restPattern":
208
+ case "wildcardPattern":
209
+ return this.formatPattern(node);
210
+ case "isExpression":
211
+ return `${this.processNode(node.expression).trim()} is ${this.formatPattern(node.pattern)}`;
206
212
  case "parallelBlock":
207
213
  return this.processParallelBlock(node);
208
214
  case "seqBlock":
@@ -336,9 +342,12 @@ export class AgencyGenerator {
336
342
  ?.map((ce) => this.processAccessChainElement(ce))
337
343
  .join("") ?? "";
338
344
  const bangSuffix = node.validated ? "!" : "";
339
- const varName = node.typeHint
340
- ? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases, true)}${bangSuffix}`
341
- : `${node.variableName}${chainStr}`;
345
+ // Destructuring pattern takes precedence over the bare variableName.
346
+ const lhs = node.pattern
347
+ ? this.formatPattern(node.pattern)
348
+ : node.typeHint
349
+ ? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases, true)}${bangSuffix}`
350
+ : `${node.variableName}${chainStr}`;
342
351
  const exportPrefix = node.exported ? "export " : "";
343
352
  const staticPrefix = node.static ? "static " : "";
344
353
  const declPrefix = node.declKind ? `${node.declKind} ` : "";
@@ -346,7 +355,49 @@ export class AgencyGenerator {
346
355
  ? this.processBinOpExpression(node.value, true).trim()
347
356
  : this.processNode(node.value).trim();
348
357
  return (tags +
349
- this.indentStr(`${exportPrefix}${staticPrefix}${declPrefix}${varName} = ${valueCode}`));
358
+ this.indentStr(`${exportPrefix}${staticPrefix}${declPrefix}${lhs} = ${valueCode}`));
359
+ }
360
+ /**
361
+ * Format a pattern AST node back into Agency pattern syntax. Used by the
362
+ * formatter (it sees the un-lowered AST). Handles binding patterns and
363
+ * match patterns; for match patterns, literal sub-nodes are formatted via
364
+ * the existing literal/expression code paths.
365
+ */
366
+ formatPattern(pattern) {
367
+ switch (pattern.type) {
368
+ case "objectPattern":
369
+ return this.formatObjectPattern(pattern);
370
+ case "arrayPattern":
371
+ return this.formatArrayPattern(pattern);
372
+ case "restPattern":
373
+ return `...${pattern.identifier}`;
374
+ case "wildcardPattern":
375
+ return "_";
376
+ default:
377
+ // variableName / literals — defer to existing rendering
378
+ return this.processNode(pattern).trim();
379
+ }
380
+ }
381
+ formatObjectPattern(node) {
382
+ const parts = node.properties.map((p) => {
383
+ if (p.type === "objectPatternShorthand") {
384
+ return p.name;
385
+ }
386
+ if (p.type === "restPattern") {
387
+ return `...${p.identifier}`;
388
+ }
389
+ const prop = p;
390
+ // If the value is just `variableName` matching the key, emit shorthand.
391
+ if (prop.value.type === "variableName" && prop.value.value === prop.key) {
392
+ return prop.key;
393
+ }
394
+ return `${prop.key}: ${this.formatPattern(prop.value)}`;
395
+ });
396
+ return `{ ${parts.join(", ")} }`;
397
+ }
398
+ formatArrayPattern(node) {
399
+ const parts = node.elements.map((el) => this.formatPattern(el));
400
+ return `[${parts.join(", ")}]`;
350
401
  }
351
402
  generateLiteral(literal) {
352
403
  switch (literal.type) {
@@ -375,7 +426,9 @@ export class AgencyGenerator {
375
426
  result += segment.value;
376
427
  }
377
428
  else if (segment.type === "interpolation") {
378
- result += `\${${expressionToString(segment.expression)}}`;
429
+ // processNode (not expressionToString) so nested function calls with
430
+ // block arguments and quoted string literals round-trip correctly.
431
+ result += `\${${this.processNode(segment.expression).trim()}}`;
379
432
  }
380
433
  }
381
434
  result += '"';
@@ -388,7 +441,7 @@ export class AgencyGenerator {
388
441
  result += segment.value;
389
442
  }
390
443
  else if (segment.type === "interpolation") {
391
- result += `\${${expressionToString(segment.expression)}}`;
444
+ result += `\${${this.processNode(segment.expression).trim()}}`;
392
445
  }
393
446
  }
394
447
  result += '"""';
@@ -559,8 +612,11 @@ export class AgencyGenerator {
559
612
  const pattern = caseNode.caseValue === "_"
560
613
  ? "_"
561
614
  : this.processNode(caseNode.caseValue).trim();
615
+ const guardCode = caseNode.guard
616
+ ? ` if (${this.processNode(caseNode.guard).trim()})`
617
+ : "";
562
618
  const bodyCode = this.processNode(caseNode.body).trim();
563
- result += this.indentStr(`${pattern} => ${bodyCode}\n`);
619
+ result += this.indentStr(`${pattern}${guardCode} => ${bodyCode}\n`);
564
620
  }
565
621
  this.decreaseIndent();
566
622
  result += this.indentStr(`}`);
@@ -568,9 +624,10 @@ export class AgencyGenerator {
568
624
  }
569
625
  processForLoop(node) {
570
626
  const iterableCode = this.processNode(node.iterable).trim();
571
- const vars = node.indexVar
572
- ? `${node.itemVar}, ${node.indexVar}`
573
- : node.itemVar;
627
+ const itemVarStr = typeof node.itemVar === "string"
628
+ ? node.itemVar
629
+ : this.formatPattern(node.itemVar);
630
+ const vars = node.indexVar ? `${itemVarStr}, ${node.indexVar}` : itemVarStr;
574
631
  let result = this.indentStr(`for (${vars} in ${iterableCode}) {\n`);
575
632
  this.increaseIndent();
576
633
  result += this.renderBody(node.body);
@@ -428,3 +428,30 @@ describe("AgencyGenerator - schema(Type) expressions", () => {
428
428
  expect(output).toContain("schema(Result<number>)");
429
429
  });
430
430
  });
431
+ describe("AgencyGenerator - string interpolation with nested calls", () => {
432
+ function formatAgency(input) {
433
+ const parseResult = parseAgency(input, {}, false);
434
+ expect(parseResult.success).toBe(true);
435
+ if (!parseResult.success)
436
+ return "";
437
+ const generator = new AgencyGenerator();
438
+ return generator.generate(parseResult.result).output.trim();
439
+ }
440
+ it("preserves inline block arguments inside a string interpolation", () => {
441
+ // The interpolation expression is a function call whose second argument
442
+ // is an inline block (`\k -> ...`). Previously the generator routed
443
+ // through expressionToString, which knows nothing about block args,
444
+ // so the block silently disappeared from the output.
445
+ const input = `node main() {\n let s = "x: " + map(arr, \\k -> k).join(",")\n}`;
446
+ const output = formatAgency(input);
447
+ expect(output).toContain("\\k -> k");
448
+ expect(output).toContain('.join(",")');
449
+ });
450
+ it("preserves quoted string arguments inside a string interpolation", () => {
451
+ // expressionToString rendered string literals without their quotes,
452
+ // so `.join("")` collapsed to `.join()`.
453
+ const input = `node main() {\n let s = "x: " + arr.join("")\n}`;
454
+ const output = formatAgency(input);
455
+ expect(output).toContain('.join("")');
456
+ });
457
+ });
@@ -233,6 +233,12 @@ export declare class TypeScriptBuilder {
233
233
  private processFunctionCall;
234
234
  private generateFunctionCallExpression;
235
235
  private emitRuntimeDispatchCall;
236
+ /**
237
+ * Emit a plain direct function call: `f(arg1, arg2, blockArg?)`.
238
+ * Context-injected builtins reuse this with `prependArgs =
239
+ * [__ctx]`; the registry lookup at the call site is what marks the
240
+ * intent, no separate method needed.
241
+ */
236
242
  private emitDirectFunctionCall;
237
243
  /**
238
244
  * Build a CallType descriptor TsNode for an Agency function call.
@@ -259,6 +265,18 @@ export declare class TypeScriptBuilder {
259
265
  private processDebuggerStatement;
260
266
  private processMessageThread;
261
267
  private processBlockPlain;
268
+ /**
269
+ * Compile the synthetic `__objectRest(source, ["a", "b", ...])` call emitted
270
+ * by the pattern lowering pass for `let { a, b, ...rest } = obj` into a
271
+ * native-JS IIFE. No runtime helper required.
272
+ *
273
+ * __objectRest(source, ["a", "b"])
274
+ * → (({ a: __k0, b: __k1, ...__r }) => __r)(<resolved source>)
275
+ *
276
+ * For `let { ...rest } = obj` (no excluded keys), emits
277
+ * (({ ...__r }) => __r)(<resolved source>)
278
+ */
279
+ private buildObjectRestIIFE;
262
280
  private processNodeInGlobalInit;
263
281
  private buildHandlerArrow;
264
282
  private processHandleBlockWithSteps;
@@ -294,6 +312,16 @@ export declare class TypeScriptBuilder {
294
312
  private processBodyAsParts;
295
313
  private generateBuiltins;
296
314
  private generateImports;
315
+ /**
316
+ * Emit the import statements that bring every context-injected
317
+ * builtin into scope in the generated TS. The set is fixed by
318
+ * `CONTEXT_INJECTED_BUILTINS` at codegen time, so we always import
319
+ * the full list — esbuild tree-shakes anything the call site
320
+ * didn't use. Imports are grouped by each entry's `from` field, so
321
+ * adding a builtin sourced from a different module is a registry
322
+ * change only.
323
+ */
324
+ private generateContextInjectedImports;
297
325
  private preprocess;
298
326
  private postprocess;
299
327
  }
@@ -4,49 +4,8 @@ import { TypeScriptBuilder } from "./typescriptBuilder.js";
4
4
  import { TypescriptPreprocessor } from "../preprocessors/typescriptPreprocessor.js";
5
5
  import { buildCompilationUnit } from "../compilationUnit.js";
6
6
  import { printTs } from "../ir/prettyPrint.js";
7
- import fs from "fs";
7
+ import { discoverFixturePairs } from "../../tests/fixtureDiscovery.js";
8
8
  import path from "path";
9
- function discoverFixtures(fixtureDir) {
10
- const fixtures = [];
11
- function scanDirectory(dir, relativePath = "") {
12
- const entries = fs.readdirSync(dir, { withFileTypes: true });
13
- for (const entry of entries) {
14
- const fullPath = path.join(dir, entry.name);
15
- const relPath = relativePath
16
- ? `${relativePath}/${entry.name}`
17
- : entry.name;
18
- if (entry.isDirectory()) {
19
- scanDirectory(fullPath, relPath);
20
- }
21
- else if (entry.isFile() && entry.name.endsWith(".agency")) {
22
- const baseName = entry.name.replace(".agency", "");
23
- const mtsPath = path.join(dir, `${baseName}.mjs`);
24
- if (fs.existsSync(mtsPath)) {
25
- const nameWithoutExt = relativePath
26
- ? `${relativePath}/${baseName}`
27
- : baseName;
28
- try {
29
- fixtures.push({
30
- name: nameWithoutExt,
31
- agencyPath: fullPath,
32
- mtsPath: mtsPath,
33
- agencyContent: fs.readFileSync(fullPath, "utf-8"),
34
- expectedTS: fs.readFileSync(mtsPath, "utf-8"),
35
- });
36
- }
37
- catch (error) {
38
- console.error(`Cannot read fixture ${fullPath}: ${error instanceof Error ? error.message : String(error)}`);
39
- }
40
- }
41
- else {
42
- console.warn(`Warning: No corresponding .mjs file for ${fullPath}`);
43
- }
44
- }
45
- }
46
- }
47
- scanDirectory(fixtureDir);
48
- return fixtures.sort((a, b) => a.name.localeCompare(b.name));
49
- }
50
9
  function normalizeWhitespace(code) {
51
10
  return (code
52
11
  .replace(/\r\n/g, "\n")
@@ -71,7 +30,7 @@ export function generateWithBuilder(agencySource, moduleId = "test.agency") {
71
30
  }
72
31
  const FIXTURES_DIR = path.resolve(__dirname, "../../tests/typescriptBuilder");
73
32
  describe("TypeScript Builder Integration Tests", () => {
74
- const fixtures = discoverFixtures(FIXTURES_DIR);
33
+ const fixtures = discoverFixturePairs(FIXTURES_DIR, ".mjs");
75
34
  if (fixtures.length === 0) {
76
35
  it("should find test fixtures (add .agency + .mjs pairs to tests/typescriptBuilder/)", () => {
77
36
  // No fixtures yet — this is expected initially.
@@ -80,16 +39,16 @@ describe("TypeScript Builder Integration Tests", () => {
80
39
  });
81
40
  return;
82
41
  }
83
- describe.each(fixtures)("Fixture: $name", ({ name, agencyPath, agencyContent, expectedTS }) => {
42
+ describe.each(fixtures)("Fixture: $name", ({ name, filePath, agencyContent, companionContent }) => {
84
43
  it("should generate correct TypeScript output", () => {
85
44
  let generatedTS;
86
45
  try {
87
46
  generatedTS = generateWithBuilder(agencyContent, name + ".agency");
88
47
  }
89
48
  catch (error) {
90
- throw new Error(`Failed to generate TypeScript for fixture: ${name}\nFile: ${agencyPath}\nError: ${error instanceof Error ? error.message : String(error)}`);
49
+ throw new Error(`Failed to generate TypeScript for fixture: ${name}\nFile: ${filePath}\nError: ${error instanceof Error ? error.message : String(error)}`);
91
50
  }
92
- expect(normalizeWhitespace(generatedTS)).toBe(normalizeWhitespace(expectedTS));
51
+ expect(normalizeWhitespace(generatedTS)).toBe(normalizeWhitespace(companionContent));
93
52
  });
94
53
  });
95
54
  });