agency-lang 0.0.85 → 0.0.87

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 (309) hide show
  1. package/dist/lib/backends/agencyGenerator.d.ts +3 -4
  2. package/dist/lib/backends/agencyGenerator.js +96 -47
  3. package/dist/lib/backends/agencyGenerator.test.js +8 -8
  4. package/dist/lib/backends/index.d.ts +1 -0
  5. package/dist/lib/backends/index.js +1 -0
  6. package/dist/lib/backends/sourceMap.d.ts +13 -0
  7. package/dist/lib/backends/sourceMap.js +18 -0
  8. package/dist/lib/backends/sourceMap.test.d.ts +1 -0
  9. package/dist/lib/backends/sourceMap.test.js +57 -0
  10. package/dist/lib/backends/typescriptBuilder.d.ts +27 -4
  11. package/dist/lib/backends/typescriptBuilder.integration.test.js +27 -1
  12. package/dist/lib/backends/typescriptBuilder.js +438 -235
  13. package/dist/lib/backends/typescriptGenerator/typeToString.js +10 -0
  14. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +2 -0
  15. package/dist/lib/backends/typescriptGenerator.integration.test.js +1 -1
  16. package/dist/lib/cli/bundle.d.ts +1 -0
  17. package/dist/lib/cli/bundle.js +58 -0
  18. package/dist/lib/cli/bundle.test.d.ts +1 -0
  19. package/dist/lib/cli/bundle.test.js +74 -0
  20. package/dist/lib/cli/commands.d.ts +1 -1
  21. package/dist/lib/cli/commands.js +11 -10
  22. package/dist/lib/cli/debug.d.ts +7 -0
  23. package/dist/lib/cli/debug.js +166 -0
  24. package/dist/lib/cli/definition.d.ts +22 -0
  25. package/dist/lib/cli/definition.js +66 -0
  26. package/dist/lib/cli/definition.test.d.ts +1 -0
  27. package/dist/lib/cli/definition.test.js +145 -0
  28. package/dist/lib/cli/doc.d.ts +2 -0
  29. package/dist/lib/cli/doc.js +117 -0
  30. package/dist/lib/cli/doc.test.d.ts +1 -0
  31. package/dist/lib/cli/doc.test.js +133 -0
  32. package/dist/lib/cli/test.d.ts +2 -2
  33. package/dist/lib/cli/test.js +268 -155
  34. package/dist/lib/cli/util.d.ts +28 -15
  35. package/dist/lib/cli/util.js +79 -16
  36. package/dist/lib/config.d.ts +12 -2
  37. package/dist/lib/config.js +1 -36
  38. package/dist/lib/debugger/debuggerState.d.ts +49 -0
  39. package/dist/lib/debugger/debuggerState.js +112 -0
  40. package/dist/lib/debugger/debuggerState.test.d.ts +1 -0
  41. package/dist/lib/debugger/debuggerState.test.js +115 -0
  42. package/dist/lib/debugger/driver.d.ts +60 -0
  43. package/dist/lib/debugger/driver.js +505 -0
  44. package/dist/lib/debugger/driver.test.d.ts +1 -0
  45. package/dist/lib/debugger/driver.test.js +762 -0
  46. package/dist/lib/debugger/testHelpers.d.ts +29 -0
  47. package/dist/lib/debugger/testHelpers.js +96 -0
  48. package/dist/lib/debugger/thread.test.d.ts +1 -0
  49. package/dist/lib/debugger/thread.test.js +84 -0
  50. package/dist/lib/debugger/trace.test.d.ts +1 -0
  51. package/dist/lib/debugger/trace.test.js +75 -0
  52. package/dist/lib/debugger/types.d.ts +61 -0
  53. package/dist/lib/debugger/types.js +1 -0
  54. package/dist/lib/debugger/ui.d.ts +54 -0
  55. package/dist/lib/debugger/ui.js +741 -0
  56. package/dist/lib/debugger/uiState.d.ts +86 -0
  57. package/dist/lib/debugger/uiState.js +244 -0
  58. package/dist/lib/debugger/uiState.test.d.ts +1 -0
  59. package/dist/lib/debugger/uiState.test.js +251 -0
  60. package/dist/lib/debugger/util.d.ts +6 -0
  61. package/dist/lib/debugger/util.js +133 -0
  62. package/dist/lib/debugger/util.test.d.ts +1 -0
  63. package/dist/lib/debugger/util.test.js +164 -0
  64. package/dist/lib/importPaths.d.ts +74 -0
  65. package/dist/lib/importPaths.js +239 -0
  66. package/dist/lib/importPaths.test.d.ts +1 -0
  67. package/dist/lib/importPaths.test.js +237 -0
  68. package/dist/lib/ir/audit.js +3 -23
  69. package/dist/lib/ir/audit.test.js +4 -9
  70. package/dist/lib/ir/builders.d.ts +48 -16
  71. package/dist/lib/ir/builders.js +44 -16
  72. package/dist/lib/ir/prettyPrint.js +47 -147
  73. package/dist/lib/ir/prettyPrint.test.js +0 -77
  74. package/dist/lib/ir/tsIR.d.ts +50 -74
  75. package/dist/lib/parser.d.ts +1 -1
  76. package/dist/lib/parser.js +18 -8
  77. package/dist/lib/parser.test.js +9 -94
  78. package/dist/lib/parsers/access.js +6 -4
  79. package/dist/lib/parsers/access.test.js +24 -24
  80. package/dist/lib/parsers/assignment.test.js +109 -8
  81. package/dist/lib/parsers/binop.js +14 -56
  82. package/dist/lib/parsers/binop.test.js +20 -20
  83. package/dist/lib/parsers/blockArgument.d.ts +3 -0
  84. package/dist/lib/parsers/blockArgument.js +28 -0
  85. package/dist/lib/parsers/blockArgument.test.d.ts +1 -0
  86. package/dist/lib/parsers/blockArgument.test.js +118 -0
  87. package/dist/lib/parsers/body.test.js +1 -1
  88. package/dist/lib/parsers/comment.js +2 -2
  89. package/dist/lib/parsers/comment.test.js +1 -1
  90. package/dist/lib/parsers/dataStructures.js +6 -7
  91. package/dist/lib/parsers/dataStructures.test.js +3 -3
  92. package/dist/lib/parsers/debuggerStatement.d.ts +3 -0
  93. package/dist/lib/parsers/debuggerStatement.js +12 -0
  94. package/dist/lib/parsers/debuggerStatement.test.d.ts +1 -0
  95. package/dist/lib/parsers/debuggerStatement.test.js +45 -0
  96. package/dist/lib/parsers/expression.d.ts +3 -0
  97. package/dist/lib/parsers/expression.js +121 -0
  98. package/dist/lib/parsers/expression.test.d.ts +1 -0
  99. package/dist/lib/parsers/expression.test.js +299 -0
  100. package/dist/lib/parsers/forLoop.test.js +1 -1
  101. package/dist/lib/parsers/function.d.ts +5 -2
  102. package/dist/lib/parsers/function.js +65 -30
  103. package/dist/lib/parsers/function.test.js +223 -154
  104. package/dist/lib/parsers/functionCall.js +8 -8
  105. package/dist/lib/parsers/functionCall.test.js +132 -7
  106. package/dist/lib/parsers/handleBlock.test.js +1 -1
  107. package/dist/lib/parsers/ifElse.test.js +1 -1
  108. package/dist/lib/parsers/importStatement.js +22 -8
  109. package/dist/lib/parsers/importStatement.test.js +27 -27
  110. package/dist/lib/parsers/keyword.test.js +1 -1
  111. package/dist/lib/parsers/literals.d.ts +4 -3
  112. package/dist/lib/parsers/literals.js +15 -19
  113. package/dist/lib/parsers/literals.test.js +63 -8
  114. package/dist/lib/parsers/loc.d.ts +9 -0
  115. package/dist/lib/parsers/loc.js +30 -0
  116. package/dist/lib/parsers/matchBlock.d.ts +1 -1
  117. package/dist/lib/parsers/matchBlock.js +4 -7
  118. package/dist/lib/parsers/matchBlock.test.js +3 -3
  119. package/dist/lib/parsers/multiLineComment.test.js +1 -1
  120. package/dist/lib/parsers/parserUtils.test.js +2 -2
  121. package/dist/lib/parsers/returnStatement.js +5 -7
  122. package/dist/lib/parsers/returnStatement.test.js +1 -1
  123. package/dist/lib/parsers/skill.test.js +1 -1
  124. package/dist/lib/parsers/specialVar.js +2 -4
  125. package/dist/lib/parsers/specialVar.test.js +1 -1
  126. package/dist/lib/parsers/tools.test.js +1 -1
  127. package/dist/lib/parsers/typeHints.d.ts +2 -2
  128. package/dist/lib/parsers/typeHints.js +23 -7
  129. package/dist/lib/parsers/typeHints.test.js +62 -378
  130. package/dist/lib/parsers/utils.d.ts +1 -1
  131. package/dist/lib/parsers/vitest.setup.d.ts +9 -0
  132. package/dist/lib/parsers/vitest.setup.js +53 -0
  133. package/dist/lib/parsers/whileLoop.test.js +1 -1
  134. package/dist/lib/preprocessors/importResolver.d.ts +0 -8
  135. package/dist/lib/preprocessors/importResolver.js +41 -7
  136. package/dist/lib/preprocessors/importResolver.test.js +23 -6
  137. package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +1 -2
  138. package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +0 -20
  139. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +1 -5
  140. package/dist/lib/preprocessors/typescriptPreprocessor.integration.test.js +1 -1
  141. package/dist/lib/preprocessors/typescriptPreprocessor.js +125 -34
  142. package/dist/lib/programInfo.d.ts +6 -6
  143. package/dist/lib/programInfo.js +23 -11
  144. package/dist/lib/programInfo.test.js +2 -114
  145. package/dist/lib/runtime/audit.d.ts +14 -3
  146. package/dist/lib/runtime/builtinTools.d.ts +0 -90
  147. package/dist/lib/runtime/builtinTools.js +0 -65
  148. package/dist/lib/runtime/builtins.d.ts +0 -15
  149. package/dist/lib/runtime/builtins.js +0 -55
  150. package/dist/lib/runtime/checkpoint.js +6 -2
  151. package/dist/lib/runtime/checkpoint.test.js +14 -4
  152. package/dist/lib/runtime/debugger.d.ts +9 -0
  153. package/dist/lib/runtime/debugger.js +86 -0
  154. package/dist/lib/runtime/debugger.test.d.ts +1 -0
  155. package/dist/lib/runtime/debugger.test.js +161 -0
  156. package/dist/lib/runtime/hooks.d.ts +2 -0
  157. package/dist/lib/runtime/index.d.ts +10 -3
  158. package/dist/lib/runtime/index.js +9 -3
  159. package/dist/lib/runtime/interrupts.d.ts +13 -5
  160. package/dist/lib/runtime/interrupts.js +100 -30
  161. package/dist/lib/runtime/isDebugger.test.d.ts +1 -0
  162. package/dist/lib/runtime/isDebugger.test.js +24 -0
  163. package/dist/lib/runtime/prompt.js +9 -3
  164. package/dist/lib/runtime/rewind.d.ts +20 -0
  165. package/dist/lib/runtime/rewind.js +73 -0
  166. package/dist/lib/runtime/runner.d.ts +73 -0
  167. package/dist/lib/runtime/runner.js +368 -0
  168. package/dist/lib/runtime/runner.test.d.ts +1 -0
  169. package/dist/lib/runtime/runner.test.js +423 -0
  170. package/dist/lib/runtime/state/checkpointStore.d.ts +81 -8
  171. package/dist/lib/runtime/state/checkpointStore.js +256 -17
  172. package/dist/lib/runtime/state/checkpointStore.test.js +504 -30
  173. package/dist/lib/runtime/state/context.d.ts +5 -0
  174. package/dist/lib/runtime/state/context.js +19 -2
  175. package/dist/lib/runtime/state/context.test.d.ts +1 -0
  176. package/dist/lib/runtime/state/context.test.js +20 -0
  177. package/dist/lib/runtime/state/globalStore.d.ts +4 -0
  178. package/dist/lib/runtime/state/globalStore.js +9 -0
  179. package/dist/lib/runtime/state/schemas.d.ts +86 -0
  180. package/dist/lib/runtime/state/schemas.js +50 -0
  181. package/dist/lib/runtime/state/sourceLocation.d.ts +6 -0
  182. package/dist/lib/runtime/state/sourceLocation.js +1 -0
  183. package/dist/lib/runtime/state/stateStack.d.ts +21 -0
  184. package/dist/lib/runtime/state/stateStack.js +55 -3
  185. package/dist/lib/runtime/state/stateStack.test.js +27 -0
  186. package/dist/lib/runtime/trace/canonicalize.d.ts +1 -0
  187. package/dist/lib/runtime/trace/canonicalize.js +17 -0
  188. package/dist/lib/runtime/trace/canonicalize.test.d.ts +1 -0
  189. package/dist/lib/runtime/trace/canonicalize.test.js +39 -0
  190. package/dist/lib/runtime/trace/contentAddressableStore.d.ts +23 -0
  191. package/dist/lib/runtime/trace/contentAddressableStore.js +94 -0
  192. package/dist/lib/runtime/trace/contentAddressableStore.test.d.ts +1 -0
  193. package/dist/lib/runtime/trace/contentAddressableStore.test.js +88 -0
  194. package/dist/lib/runtime/trace/traceReader.d.ts +10 -0
  195. package/dist/lib/runtime/trace/traceReader.js +67 -0
  196. package/dist/lib/runtime/trace/traceReader.test.d.ts +1 -0
  197. package/dist/lib/runtime/trace/traceReader.test.js +150 -0
  198. package/dist/lib/runtime/trace/traceWriter.d.ts +9 -0
  199. package/dist/lib/runtime/trace/traceWriter.js +34 -0
  200. package/dist/lib/runtime/trace/traceWriter.test.d.ts +1 -0
  201. package/dist/lib/runtime/trace/traceWriter.test.js +103 -0
  202. package/dist/lib/runtime/trace/types.d.ts +42 -0
  203. package/dist/lib/runtime/trace/types.js +4 -0
  204. package/dist/lib/runtime/types.d.ts +4 -1
  205. package/dist/lib/statelogClient.d.ts +2 -27
  206. package/dist/lib/statelogClient.js +8 -135
  207. package/dist/lib/symbolTable.d.ts +4 -1
  208. package/dist/lib/symbolTable.js +10 -6
  209. package/dist/lib/symbolTable.test.js +5 -4
  210. package/dist/lib/templates/backends/agency/template.d.ts +6 -0
  211. package/dist/lib/templates/backends/agency/template.js +11 -0
  212. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +12 -0
  213. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +21 -0
  214. package/dist/lib/templates/backends/typescriptGenerator/debugger.d.ts +11 -0
  215. package/dist/lib/templates/backends/typescriptGenerator/debugger.js +25 -0
  216. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
  217. package/dist/lib/templates/backends/typescriptGenerator/imports.js +18 -51
  218. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +5 -3
  219. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +14 -6
  220. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +4 -1
  221. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +11 -16
  222. package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.d.ts +11 -0
  223. package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.js +32 -0
  224. package/dist/lib/templates/backends/typescriptGenerator/traceSetup.d.ts +7 -0
  225. package/dist/lib/templates/backends/typescriptGenerator/traceSetup.js +12 -0
  226. package/dist/lib/templates/cli/evaluate.d.ts +2 -1
  227. package/dist/lib/templates/cli/evaluate.js +1 -1
  228. package/dist/lib/templates/cli/judgeEvaluate.d.ts +2 -1
  229. package/dist/lib/templates/cli/judgeEvaluate.js +1 -1
  230. package/dist/lib/typeChecker.js +17 -12
  231. package/dist/lib/typeChecker.test.js +20 -39
  232. package/dist/lib/types/access.d.ts +4 -3
  233. package/dist/lib/types/awaitPending.d.ts +2 -1
  234. package/dist/lib/types/base.d.ts +9 -0
  235. package/dist/lib/types/base.js +1 -0
  236. package/dist/lib/types/binop.d.ts +7 -9
  237. package/dist/lib/types/binop.js +1 -0
  238. package/dist/lib/types/blockArgument.d.ts +8 -0
  239. package/dist/lib/types/blockArgument.js +1 -0
  240. package/dist/lib/types/dataStructures.d.ts +12 -8
  241. package/dist/lib/types/debuggerStatement.d.ts +6 -0
  242. package/dist/lib/types/debuggerStatement.js +1 -0
  243. package/dist/lib/types/forLoop.d.ts +4 -4
  244. package/dist/lib/types/function.d.ts +11 -7
  245. package/dist/lib/types/graphNode.d.ts +2 -1
  246. package/dist/lib/types/handleBlock.d.ts +2 -1
  247. package/dist/lib/types/ifElse.d.ts +4 -5
  248. package/dist/lib/types/importStatement.d.ts +7 -4
  249. package/dist/lib/types/importStatement.js +6 -0
  250. package/dist/lib/types/keyword.d.ts +2 -1
  251. package/dist/lib/types/literals.d.ts +13 -10
  252. package/dist/lib/types/matchBlock.d.ts +6 -10
  253. package/dist/lib/types/messageThread.d.ts +2 -1
  254. package/dist/lib/types/returnStatement.d.ts +4 -6
  255. package/dist/lib/types/sentinel.d.ts +11 -0
  256. package/dist/lib/types/sentinel.js +1 -0
  257. package/dist/lib/types/skill.d.ts +2 -1
  258. package/dist/lib/types/specialVar.d.ts +4 -6
  259. package/dist/lib/types/tools.d.ts +2 -1
  260. package/dist/lib/types/typeHints.d.ts +10 -6
  261. package/dist/lib/types/whileLoop.d.ts +4 -5
  262. package/dist/lib/types.d.ts +25 -12
  263. package/dist/lib/types.js +5 -0
  264. package/dist/lib/utils/markdown.d.ts +6 -0
  265. package/dist/lib/utils/markdown.js +21 -0
  266. package/dist/lib/utils/markdown.test.d.ts +1 -0
  267. package/dist/lib/utils/markdown.test.js +39 -0
  268. package/dist/lib/utils/node.d.ts +7 -5
  269. package/dist/lib/utils/node.js +92 -32
  270. package/dist/lib/utils.d.ts +1 -0
  271. package/dist/lib/utils.js +4 -0
  272. package/dist/lib/version.d.ts +1 -0
  273. package/dist/lib/version.js +1 -0
  274. package/dist/scripts/agency.js +82 -44
  275. package/dist/scripts/regenerate-fixtures.js +18 -60
  276. package/package.json +12 -6
  277. package/stdlib/_builtins.js +101 -0
  278. package/stdlib/_math.js +9 -0
  279. package/stdlib/clipboard.agency +15 -0
  280. package/stdlib/index.agency +115 -0
  281. package/stdlib/index.js +1350 -0
  282. package/stdlib/lib/clipboard.js +29 -0
  283. package/stdlib/lib/process.js +29 -0
  284. package/stdlib/lib/speech.js +69 -0
  285. package/stdlib/lib/system.js +29 -0
  286. package/stdlib/lib/utils.js +51 -0
  287. package/stdlib/math.agency +13 -0
  288. package/stdlib/math.js +389 -0
  289. package/stdlib/process.agency +25 -0
  290. package/stdlib/speech.agency +15 -0
  291. package/stdlib/system.agency +8 -0
  292. package/dist/lib/cli/remoteRun.d.ts +0 -3
  293. package/dist/lib/cli/remoteRun.js +0 -35
  294. package/dist/lib/cli/upload.d.ts +0 -3
  295. package/dist/lib/cli/upload.js +0 -50
  296. package/dist/lib/templates/backends/typescriptGenerator/forSteps.d.ts +0 -20
  297. package/dist/lib/templates/backends/typescriptGenerator/forSteps.js +0 -32
  298. package/dist/lib/templates/backends/typescriptGenerator/handleSteps.d.ts +0 -16
  299. package/dist/lib/templates/backends/typescriptGenerator/handleSteps.js +0 -22
  300. package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.d.ts +0 -17
  301. package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.js +0 -18
  302. package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.d.ts +0 -17
  303. package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.js +0 -26
  304. package/dist/lib/templates/backends/typescriptGenerator/substepBlock.d.ts +0 -10
  305. package/dist/lib/templates/backends/typescriptGenerator/substepBlock.js +0 -12
  306. package/dist/lib/templates/backends/typescriptGenerator/threadSteps.d.ts +0 -16
  307. package/dist/lib/templates/backends/typescriptGenerator/threadSteps.js +0 -21
  308. package/dist/lib/templates/backends/typescriptGenerator/whileSteps.d.ts +0 -16
  309. package/dist/lib/templates/backends/typescriptGenerator/whileSteps.js +0 -29
@@ -1,5 +1,5 @@
1
1
  import { SpecialVar } from "../types/specialVar.js";
2
- import { AgencyComment, AgencyMultiLineComment, AgencyNode, AgencyProgram, Assignment, Literal, NewLine, Scope, TypeAlias, TypeHint, TypeHintMap, VariableType } from "../types.js";
2
+ import { AgencyComment, AgencyMultiLineComment, AgencyNode, AgencyProgram, Assignment, DebuggerStatement, Literal, NewLine, Scope, TypeAlias, VariableType } from "../types.js";
3
3
  import { AccessChainElement, ValueAccess } from "../types/access.js";
4
4
  import { AgencyArray, AgencyObject } from "../types/dataStructures.js";
5
5
  import { FunctionCall, FunctionDefinition } from "../types/function.js";
@@ -18,7 +18,6 @@ import { BinOpArgument, BinOpExpression, Operator } from "../types/binop.js";
18
18
  import { Keyword } from "../types/keyword.js";
19
19
  import { HandleBlock } from "../types/handleBlock.js";
20
20
  export declare class AgencyGenerator {
21
- protected typeHints: TypeHintMap;
22
21
  protected graphNodes: GraphNodeDefinition[];
23
22
  protected generatedStatements: string[];
24
23
  protected generatedTypeAliases: string[];
@@ -48,7 +47,7 @@ export declare class AgencyGenerator {
48
47
  protected postprocess(): string;
49
48
  protected collectFunctionSignature(node: FunctionDefinition): void;
50
49
  protected processGraphNodeName(node: GraphNodeDefinition): void;
51
- protected processNode(node: AgencyNode): string;
50
+ processNode(node: AgencyNode): string;
52
51
  protected needsParensLeft(child: BinOpArgument, parentOp: Operator): boolean;
53
52
  protected needsParensRight(child: BinOpArgument, parentOp: Operator): boolean;
54
53
  protected startScope(scope: Scope): void;
@@ -63,7 +62,6 @@ export declare class AgencyGenerator {
63
62
  private stringifyProp;
64
63
  protected aliasedTypeToString(aliasedType: VariableType): string;
65
64
  protected processTypeAlias(node: TypeAlias): string;
66
- protected processTypeHint(node: TypeHint): string;
67
65
  protected processAssignment(node: Assignment): string;
68
66
  protected generateLiteral(literal: Literal): string;
69
67
  private generateStringLiteral;
@@ -80,6 +78,7 @@ export declare class AgencyGenerator {
80
78
  protected processWhileLoop(node: WhileLoop): string;
81
79
  protected processIfElse(node: IfElse): string;
82
80
  protected processReturnStatement(node: ReturnStatement): string;
81
+ protected processDebuggerStatement(node: DebuggerStatement): string;
83
82
  protected processComment(node: AgencyComment): string;
84
83
  protected processMultiLineComment(node: AgencyMultiLineComment): string;
85
84
  protected processImportStatement(node: ImportStatement): string;
@@ -3,7 +3,6 @@ import { mergeDeep } from "../utils.js";
3
3
  import { PRECEDENCE, } from "../types/binop.js";
4
4
  import { expressionToString } from "../utils/node.js";
5
5
  export class AgencyGenerator {
6
- typeHints = {};
7
6
  graphNodes = [];
8
7
  generatedStatements = [];
9
8
  generatedTypeAliases = [];
@@ -35,19 +34,13 @@ export class AgencyGenerator {
35
34
  this.processTypeAlias(node);
36
35
  }
37
36
  }
38
- // Pass 2: Collect all type hints
39
- for (const node of program.nodes) {
40
- if (node.type === "typeHint") {
41
- this.processTypeHint(node);
42
- }
43
- }
44
- // Pass 3: Collect all node names
37
+ // Pass 2: Collect all node names
45
38
  for (const node of program.nodes) {
46
39
  if (node.type === "graphNode") {
47
40
  this.processGraphNodeName(node);
48
41
  }
49
42
  }
50
- // Pass 4: Collect all node and tool imports
43
+ // Pass 3: Collect all node and tool imports
51
44
  for (const node of program.nodes) {
52
45
  if (node.type === "importNodeStatement") {
53
46
  this.importedNodes.push(node);
@@ -56,7 +49,7 @@ export class AgencyGenerator {
56
49
  this.importedTools.push(node);
57
50
  }
58
51
  }
59
- // Pass 5: Generate code for tools
52
+ // Pass 4: Generate code for tools
60
53
  for (const node of program.nodes) {
61
54
  if (node.type === "function") {
62
55
  this.generatedStatements.push(this.processTool(node));
@@ -64,10 +57,33 @@ export class AgencyGenerator {
64
57
  }
65
58
  }
66
59
  this.preprocessAST();
67
- // Pass 7: Process all nodes and generate code
60
+ // Types that should have a blank line before/after them at the top level
61
+ const BLOCK_TYPES = new Set([
62
+ "graphNode", "function", "typeAlias",
63
+ ]);
64
+ const NO_SPACE_TYPES = new Set([
65
+ "comment", "multiLineComment"
66
+ ]);
67
+ // Pass 5: Process all nodes and generate code
68
+ const stmtPairs = [];
68
69
  for (const node of program.nodes) {
69
70
  const result = this.processNode(node);
70
- this.generatedStatements.push(result);
71
+ if (result !== "") {
72
+ stmtPairs.push({ type: node.type, code: result });
73
+ }
74
+ }
75
+ // Join top-level statements: blank line between block declarations,
76
+ // single newline between simple statements
77
+ const stmtLines = [];
78
+ for (let i = 0; i < stmtPairs.length; i++) {
79
+ if (i > 0) {
80
+ const prev = stmtPairs[i - 1];
81
+ const curr = stmtPairs[i];
82
+ if (BLOCK_TYPES.has(prev.type) || (BLOCK_TYPES.has(curr.type) && !NO_SPACE_TYPES.has(prev.type))) {
83
+ stmtLines.push(""); // blank line
84
+ }
85
+ }
86
+ stmtLines.push(stmtPairs[i].code);
71
87
  }
72
88
  const output = [];
73
89
  this.addIfNonEmpty(this.preprocess(), output);
@@ -75,7 +91,7 @@ export class AgencyGenerator {
75
91
  this.addIfNonEmpty(this.generateImports(), output);
76
92
  this.addIfNonEmpty(this.generateBuiltins(), output);
77
93
  output.push(...this.generatedTypeAliases);
78
- output.push(this.generatedStatements.join(""));
94
+ output.push(stmtLines.join("\n"));
79
95
  this.addIfNonEmpty(this.postprocess(), output);
80
96
  return {
81
97
  output: output.join("\n"),
@@ -105,8 +121,6 @@ export class AgencyGenerator {
105
121
  processGraphNodeName(node) { }
106
122
  processNode(node) {
107
123
  switch (node.type) {
108
- case "typeHint":
109
- return this.processTypeHint(node);
110
124
  case "typeAlias":
111
125
  return this.processTypeAlias(node);
112
126
  case "assignment":
@@ -128,9 +142,12 @@ export class AgencyGenerator {
128
142
  case "string":
129
143
  case "variableName":
130
144
  case "boolean":
145
+ case "null":
131
146
  return this.generateLiteral(node);
132
147
  case "returnStatement":
133
148
  return this.processReturnStatement(node);
149
+ case "debuggerStatement":
150
+ return this.processDebuggerStatement(node);
134
151
  case "agencyArray":
135
152
  return this.processAgencyArray(node);
136
153
  case "agencyObject":
@@ -195,8 +212,8 @@ export class AgencyGenerator {
195
212
  }
196
213
  isImportedTool(functionName) {
197
214
  return this.importedTools
198
- .map((node) => node.importedTools)
199
- .flat()
215
+ .flatMap((node) => node.importedTools)
216
+ .flatMap((n) => n.importedNames)
200
217
  .includes(functionName);
201
218
  }
202
219
  isAgencyFunction(functionName, context) {
@@ -261,11 +278,6 @@ export class AgencyGenerator {
261
278
  const aliasedTypeStr = this.aliasedTypeToString(node.aliasedType);
262
279
  return this.indentStr(`type ${node.aliasName} = ${aliasedTypeStr}`);
263
280
  }
264
- processTypeHint(node) {
265
- this.typeHints[node.variableName] = node.variableType;
266
- const typeStr = variableTypeToString(node.variableType, this.typeAliases);
267
- return this.indentStr(`${node.variableName} :: ${typeStr}`);
268
- }
269
281
  // Assignment and literals
270
282
  processAssignment(node) {
271
283
  const chainStr = node.accessChain
@@ -274,9 +286,10 @@ export class AgencyGenerator {
274
286
  const varName = node.typeHint
275
287
  ? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases)}`
276
288
  : `${node.variableName}${chainStr}`;
277
- const prefix = node.shared ? "shared " : "";
289
+ const sharedPrefix = node.shared ? "shared " : "";
290
+ const declPrefix = node.declKind ? `${node.declKind} ` : "";
278
291
  let valueCode = this.processNode(node.value).trim();
279
- return this.indentStr(`${prefix}${varName} = ${valueCode}`);
292
+ return this.indentStr(`${sharedPrefix}${declPrefix}${varName} = ${valueCode}`);
280
293
  }
281
294
  generateLiteral(literal) {
282
295
  switch (literal.type) {
@@ -290,6 +303,8 @@ export class AgencyGenerator {
290
303
  return this.generateMultiLineStringLiteral(literal);
291
304
  case "boolean":
292
305
  return literal.value ? "true" : "false";
306
+ case "null":
307
+ return "null";
293
308
  default:
294
309
  return "";
295
310
  }
@@ -328,12 +343,16 @@ export class AgencyGenerator {
328
343
  const { functionName, body, parameters } = node;
329
344
  const params = parameters
330
345
  .map((p) => {
346
+ const prefix = p.variadic ? "..." : "";
347
+ const defaultSuffix = p.defaultValue
348
+ ? ` = ${this.processNode(p.defaultValue).trim()}`
349
+ : "";
331
350
  if (p.typeHint) {
332
351
  const typeStr = variableTypeToString(p.typeHint, this.typeAliases);
333
- return `${p.name}: ${typeStr}`;
352
+ return `${prefix}${p.name}: ${typeStr}${defaultSuffix}`;
334
353
  }
335
354
  else {
336
- return p.name;
355
+ return `${prefix}${p.name}${defaultSuffix}`;
337
356
  }
338
357
  })
339
358
  .join(", ");
@@ -341,14 +360,8 @@ export class AgencyGenerator {
341
360
  ? ": " + variableTypeToString(node.returnType, this.typeAliases)
342
361
  : "";
343
362
  let safePrefix = node.safe ? "safe " : "";
344
- let asyncPrefix = "";
345
- if (node.async === true) {
346
- asyncPrefix = "async ";
347
- }
348
- else if (node.async === false) {
349
- asyncPrefix = "sync ";
350
- }
351
- let result = this.indentStr(`${safePrefix}${asyncPrefix}def ${functionName}(${params})${returnTypeStr} {\n`);
363
+ const exportPrefix = node.exported ? "export " : "";
364
+ let result = this.indentStr(`${exportPrefix}${safePrefix}def ${functionName}(${params})${returnTypeStr} {\n`);
352
365
  this.increaseIndent();
353
366
  if (node.docString) {
354
367
  const docLines = [`"""`, ...node.docString.value.split("\n"), `"""`];
@@ -359,7 +372,7 @@ export class AgencyGenerator {
359
372
  for (const stmt of body) {
360
373
  lines.push(this.processNode(stmt));
361
374
  }
362
- const bodyCode = lines.join("").trimEnd() + "\n";
375
+ const bodyCode = lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
363
376
  result += bodyCode;
364
377
  this.decreaseIndent();
365
378
  result += this.indentStr(`}`);
@@ -371,6 +384,12 @@ export class AgencyGenerator {
371
384
  }
372
385
  generateFunctionCallExpression(node, context) {
373
386
  const args = node.arguments.map((arg) => {
387
+ if (arg.type === "namedArgument") {
388
+ return `${arg.name}: ${this.processNode(arg.value).trim()}`;
389
+ }
390
+ if (arg.type === "splat") {
391
+ return `...${this.processNode(arg.value).trim()}`;
392
+ }
374
393
  return this.processNode(arg).trim();
375
394
  });
376
395
  let asyncPrefix = "";
@@ -380,7 +399,26 @@ export class AgencyGenerator {
380
399
  else if (node.async === false) {
381
400
  asyncPrefix = "await ";
382
401
  }
383
- return `${asyncPrefix}${node.functionName}(${args.join(", ")})`;
402
+ let result = `${asyncPrefix}${node.functionName}(${args.join(", ")})`;
403
+ if (node.block) {
404
+ const block = node.block;
405
+ let asClause = "as ";
406
+ if (block.params.length === 1) {
407
+ asClause = `as ${block.params[0].name} `;
408
+ }
409
+ else if (block.params.length > 1) {
410
+ asClause = `as (${block.params.map((p) => p.name).join(", ")}) `;
411
+ }
412
+ this.increaseIndent();
413
+ const bodyLines = [];
414
+ for (const stmt of block.body) {
415
+ bodyLines.push(this.processNode(stmt));
416
+ }
417
+ this.decreaseIndent();
418
+ const bodyStr = bodyLines.filter((s) => s !== "").join("\n").trimEnd() + "\n";
419
+ result += ` ${asClause}{\n${bodyStr}${this.indentStr("}")}`;
420
+ }
421
+ return result;
384
422
  }
385
423
  // Data structures
386
424
  processAgencyArray(node) {
@@ -459,9 +497,11 @@ export class AgencyGenerator {
459
497
  : node.itemVar;
460
498
  let result = this.indentStr(`for (${vars} in ${iterableCode}) {\n`);
461
499
  this.increaseIndent();
500
+ const lines = [];
462
501
  for (const stmt of node.body) {
463
- result += this.processNode(stmt);
502
+ lines.push(this.processNode(stmt));
464
503
  }
504
+ result += lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
465
505
  this.decreaseIndent();
466
506
  result += this.indentStr(`}`);
467
507
  return result;
@@ -470,9 +510,11 @@ export class AgencyGenerator {
470
510
  const conditionCode = this.processNode(node.condition).trim();
471
511
  let result = this.indentStr(`while (${conditionCode}) {\n`);
472
512
  this.increaseIndent();
513
+ const lines = [];
473
514
  for (const stmt of node.body) {
474
- result += this.processNode(stmt);
515
+ lines.push(this.processNode(stmt));
475
516
  }
517
+ result += lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
476
518
  this.decreaseIndent();
477
519
  result += this.indentStr(`}`);
478
520
  return result;
@@ -487,7 +529,7 @@ export class AgencyGenerator {
487
529
  bodyLines.push(this.processNode(stmt));
488
530
  }
489
531
  this.decreaseIndent();
490
- lines.push(bodyLines.join("").trimEnd() + "\n");
532
+ lines.push(bodyLines.filter(s => s !== "").join("\n").trimEnd() + "\n");
491
533
  if (node.elseBody && node.elseBody.length > 0) {
492
534
  if (node.elseBody.length === 1 && node.elseBody[0].type === "ifElse") {
493
535
  const elseIfCode = this.processIfElse(node.elseBody[0]);
@@ -502,7 +544,7 @@ export class AgencyGenerator {
502
544
  elseBodyLines.push(this.processNode(stmt));
503
545
  }
504
546
  this.decreaseIndent();
505
- lines.push(elseBodyLines.join("").trimEnd() + "\n");
547
+ lines.push(elseBodyLines.filter(s => s !== "").join("\n").trimEnd() + "\n");
506
548
  }
507
549
  }
508
550
  lines.push(this.indentStr(`}`));
@@ -512,6 +554,9 @@ export class AgencyGenerator {
512
554
  const valueCode = this.processNode(node.value).trim();
513
555
  return this.indentStr(`return ${valueCode}`);
514
556
  }
557
+ processDebuggerStatement(node) {
558
+ return this.indentStr(node.label ? `debugger(${JSON.stringify(node.label)})` : "debugger()");
559
+ }
515
560
  // Utility methods
516
561
  processComment(node) {
517
562
  return this.indentStr(`//${node.content}`);
@@ -521,7 +566,10 @@ export class AgencyGenerator {
521
566
  }
522
567
  processImportStatement(node) {
523
568
  const importedNames = node.importedNames.map((name) => this.processImportNameType(name));
524
- const str = this.indentStr(`import ${importedNames.join(", ")} from "${node.modulePath}"`);
569
+ const modulePath = node.modulePath.startsWith("std::")
570
+ ? node.modulePath.replace(/\.agency$/, "")
571
+ : node.modulePath;
572
+ const str = this.indentStr(`import ${importedNames.join(", ")} from "${modulePath}"`);
525
573
  return str;
526
574
  }
527
575
  processImportNameType(node) {
@@ -540,7 +588,8 @@ export class AgencyGenerator {
540
588
  return `import node { ${node.importedNodes.join(", ")} } from "${node.agencyFile}"`;
541
589
  }
542
590
  processImportToolStatement(node) {
543
- return `import tool { ${node.importedTools.join(", ")} } from "${node.agencyFile}"`;
591
+ const toolNames = node.importedTools.flatMap((n) => n.importedNames);
592
+ return `import tool { ${toolNames.join(", ")} } from "${node.agencyFile}"`;
544
593
  }
545
594
  visibilityToString(vis) {
546
595
  switch (vis) {
@@ -569,7 +618,7 @@ export class AgencyGenerator {
569
618
  for (const stmt of body) {
570
619
  lines.push(this.processNode(stmt));
571
620
  }
572
- const bodyCode = lines.join("").trimEnd() + "\n";
621
+ const bodyCode = lines.filter(s => s !== "").join("\n").trimEnd() + "\n";
573
622
  result += bodyCode;
574
623
  this.decreaseIndent();
575
624
  result += this.indentStr(`}`);
@@ -585,7 +634,7 @@ export class AgencyGenerator {
585
634
  return this.indentStr(`@${node.name} = ${this.processNode(node.value).trim()}`);
586
635
  }
587
636
  processNewLine(_node) {
588
- return "\n";
637
+ return "";
589
638
  }
590
639
  processMessageThread(node) {
591
640
  this.increaseIndent();
@@ -594,7 +643,7 @@ export class AgencyGenerator {
594
643
  bodyCodes.push(this.processNode(stmt));
595
644
  }
596
645
  this.decreaseIndent();
597
- const bodyCodeStr = bodyCodes.join("");
646
+ const bodyCodeStr = bodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
598
647
  const threadType = node.threadType;
599
648
  return this.indentStr(`${threadType} {\n${bodyCodeStr}${this.indentStr("}")}`);
600
649
  }
@@ -605,7 +654,7 @@ export class AgencyGenerator {
605
654
  bodyCodes.push(this.processNode(stmt));
606
655
  }
607
656
  this.decreaseIndent();
608
- const bodyCodeStr = bodyCodes.join("");
657
+ const bodyCodeStr = bodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
609
658
  let handlerStr;
610
659
  if (node.handler.kind === "inline") {
611
660
  const paramStr = node.handler.param.typeHint
@@ -617,7 +666,7 @@ export class AgencyGenerator {
617
666
  handlerBodyCodes.push(this.processNode(stmt));
618
667
  }
619
668
  this.decreaseIndent();
620
- const handlerBodyStr = handlerBodyCodes.join("");
669
+ const handlerBodyStr = handlerBodyCodes.filter(s => s !== "").join("\n").trimEnd() + "\n";
621
670
  handlerStr = `(${paramStr}) {\n${handlerBodyStr}${this.indentStr("}")}`;
622
671
  }
623
672
  else {
@@ -57,7 +57,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
57
57
  ];
58
58
  testCases.forEach(({ description, input, expectedOutput }) => {
59
59
  it(`should correctly generate ${description}`, () => {
60
- const parseResult = parseAgency(input);
60
+ const parseResult = parseAgency(input, {}, false);
61
61
  expect(parseResult.success).toBe(true);
62
62
  if (!parseResult.success)
63
63
  return;
@@ -73,7 +73,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
73
73
  describe("Type preservation", () => {
74
74
  it("should preserve primitive types", () => {
75
75
  const input = "def test(n: number, s: string, b: boolean) { n }";
76
- const parseResult = parseAgency(input);
76
+ const parseResult = parseAgency(input, {}, false);
77
77
  expect(parseResult.success).toBe(true);
78
78
  if (!parseResult.success)
79
79
  return;
@@ -85,7 +85,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
85
85
  });
86
86
  it("should preserve array types", () => {
87
87
  const input = "def test(nums: number[], strs: string[]) { nums }";
88
- const parseResult = parseAgency(input);
88
+ const parseResult = parseAgency(input, {}, false);
89
89
  expect(parseResult.success).toBe(true);
90
90
  if (!parseResult.success)
91
91
  return;
@@ -96,7 +96,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
96
96
  });
97
97
  it("should preserve union types", () => {
98
98
  const input = "def test(val: string | number | boolean) { val }";
99
- const parseResult = parseAgency(input);
99
+ const parseResult = parseAgency(input, {}, false);
100
100
  expect(parseResult.success).toBe(true);
101
101
  if (!parseResult.success)
102
102
  return;
@@ -106,7 +106,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
106
106
  });
107
107
  it("should preserve nested array types", () => {
108
108
  const input = "def test(matrix: number[][]) { matrix }";
109
- const parseResult = parseAgency(input);
109
+ const parseResult = parseAgency(input, {}, false);
110
110
  expect(parseResult.success).toBe(true);
111
111
  if (!parseResult.success)
112
112
  return;
@@ -118,7 +118,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
118
118
  describe("Mixed typed and untyped parameters", () => {
119
119
  it("should handle first parameter typed, second untyped", () => {
120
120
  const input = "def test(x: number, y) { x }";
121
- const parseResult = parseAgency(input);
121
+ const parseResult = parseAgency(input, {}, false);
122
122
  expect(parseResult.success).toBe(true);
123
123
  if (!parseResult.success)
124
124
  return;
@@ -130,7 +130,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
130
130
  });
131
131
  it("should handle first parameter untyped, second typed", () => {
132
132
  const input = "def test(x, y: string) { x }";
133
- const parseResult = parseAgency(input);
133
+ const parseResult = parseAgency(input, {}, false);
134
134
  expect(parseResult.success).toBe(true);
135
135
  if (!parseResult.success)
136
136
  return;
@@ -142,7 +142,7 @@ describe("AgencyGenerator - Function Parameter Type Hints", () => {
142
142
  });
143
143
  it("should handle alternating typed and untyped parameters", () => {
144
144
  const input = "def test(a, b: number, c, d: string) { a }";
145
- const parseResult = parseAgency(input);
145
+ const parseResult = parseAgency(input, {}, false);
146
146
  expect(parseResult.success).toBe(true);
147
147
  if (!parseResult.success)
148
148
  return;
@@ -1 +1,2 @@
1
1
  export * from "./typescriptGenerator.js";
2
+ export * from "./sourceMap.js";
@@ -1 +1,2 @@
1
1
  export * from "./typescriptGenerator.js";
2
+ export * from "./sourceMap.js";
@@ -0,0 +1,13 @@
1
+ import type { SourceLocation } from "../types/base.js";
2
+ export type SourceMapLocation = {
3
+ line: number;
4
+ col: number;
5
+ };
6
+ export type SourceMap = Record<string, Record<string, SourceMapLocation>>;
7
+ export declare class SourceMapBuilder {
8
+ private currentKey;
9
+ private map;
10
+ enterScope(moduleId: string, scopeName: string): void;
11
+ record(subStepPath: number[], loc: SourceLocation | undefined): void;
12
+ build(): SourceMap;
13
+ }
@@ -0,0 +1,18 @@
1
+ export class SourceMapBuilder {
2
+ currentKey = "";
3
+ map = {};
4
+ enterScope(moduleId, scopeName) {
5
+ this.currentKey = `${moduleId}:${scopeName}`;
6
+ if (!this.map[this.currentKey]) {
7
+ this.map[this.currentKey] = {};
8
+ }
9
+ }
10
+ record(subStepPath, loc) {
11
+ if (!loc || !this.currentKey)
12
+ return;
13
+ this.map[this.currentKey][subStepPath.join(".")] = { line: loc.line, col: loc.col };
14
+ }
15
+ build() {
16
+ return structuredClone(this.map);
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { SourceMapBuilder } from "./sourceMap.js";
3
+ describe("SourceMapBuilder", () => {
4
+ it("records entries and builds correct structure", () => {
5
+ const builder = new SourceMapBuilder();
6
+ builder.enterScope("foo.agency", "main");
7
+ builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
8
+ builder.record([1], { line: 3, col: 2, start: 20, end: 30 });
9
+ const result = builder.build();
10
+ expect(result).toEqual({
11
+ "foo.agency:main": {
12
+ "0": { line: 1, col: 2 },
13
+ "1": { line: 3, col: 2 },
14
+ },
15
+ });
16
+ });
17
+ it("handles multiple scopes", () => {
18
+ const builder = new SourceMapBuilder();
19
+ builder.enterScope("foo.agency", "main");
20
+ builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
21
+ builder.enterScope("foo.agency", "greet");
22
+ builder.record([0], { line: 5, col: 2, start: 50, end: 60 });
23
+ const result = builder.build();
24
+ expect(result).toHaveProperty("foo.agency:main");
25
+ expect(result).toHaveProperty("foo.agency:greet");
26
+ });
27
+ it("silently skips undefined loc", () => {
28
+ const builder = new SourceMapBuilder();
29
+ builder.enterScope("foo.agency", "main");
30
+ builder.record([0], undefined);
31
+ builder.record([1], { line: 3, col: 2, start: 20, end: 30 });
32
+ const result = builder.build();
33
+ expect(result["foo.agency:main"]).toEqual({
34
+ "1": { line: 3, col: 2 },
35
+ });
36
+ });
37
+ it("formats substep paths with dot separator", () => {
38
+ const builder = new SourceMapBuilder();
39
+ builder.enterScope("foo.agency", "main");
40
+ builder.record([2, 0, 1], { line: 10, col: 4, start: 100, end: 120 });
41
+ const result = builder.build();
42
+ expect(result["foo.agency:main"]).toHaveProperty("2.0.1");
43
+ });
44
+ it("returns empty object when nothing recorded", () => {
45
+ const builder = new SourceMapBuilder();
46
+ expect(builder.build()).toEqual({});
47
+ });
48
+ it("build returns a copy, not the internal reference", () => {
49
+ const builder = new SourceMapBuilder();
50
+ builder.enterScope("foo.agency", "main");
51
+ builder.record([0], { line: 1, col: 2, start: 0, end: 10 });
52
+ const result1 = builder.build();
53
+ result1["foo.agency:main"]["0"].line = 999;
54
+ const result2 = builder.build();
55
+ expect(result2["foo.agency:main"]["0"].line).toBe(1);
56
+ });
57
+ });
@@ -15,12 +15,17 @@ export declare class TypeScriptBuilder {
15
15
  private loopVars;
16
16
  private insideMessageThread;
17
17
  private insideHandlerBody;
18
+ private _blockCounter;
19
+ /** Stack of loop subKeys for generating break/continue cleanup code.
20
+ * Pushed when entering a stepped loop, popped when leaving. */
21
+ private _loopContextStack;
18
22
  private _asyncBranchCheckNeeded;
19
23
  /** Tracks the current substep nesting path. Empty when at the top level
20
24
  * of a stepped body. Non-empty when inside a block (if/else, etc.) that
21
25
  * has been broken into substeps. Used to generate unique variable names
22
26
  * like __substep_3_1 for nested blocks. */
23
27
  private _subStepPath;
28
+ private _sourceMapBuilder;
24
29
  private programInfo;
25
30
  private moduleId;
26
31
  /**
@@ -44,9 +49,11 @@ export declare class TypeScriptBuilder {
44
49
  */
45
50
  private scopedAssign;
46
51
  private currentScopeKey;
47
- private getTypeHint;
52
+ /** Returns the name of the current scope (function, node, or block name, or empty string for global). */
53
+ private currentScopeName;
54
+ /** Returns the template opts for checkpoint creation (moduleId, scopeName, stepPath as JSON-quoted strings). */
55
+ private checkpointOpts;
48
56
  private getVisibleTypeAliases;
49
- private getVisibleTypeHints;
50
57
  private forkBranchSetup;
51
58
  private isImportedTool;
52
59
  private static RUNTIME_STATEFUL_FUNCTIONS;
@@ -59,9 +66,19 @@ export declare class TypeScriptBuilder {
59
66
  private needsParensLeft;
60
67
  private needsParensRight;
61
68
  build(program: AgencyProgram): TsNode;
69
+ /** Named args are cosmetic/positional — validate name matches the param at that index. */
70
+ private validateNamedArgs;
71
+ /** Process a function call argument, unwrapping NamedArgument and SplatExpression. */
72
+ private processCallArg;
73
+ /**
74
+ * Adjust call-site arguments to match the function's parameter list:
75
+ * 1. Pad omitted optional args (those with defaults) with null
76
+ * 2. Wrap extra args into an array for variadic params
77
+ */
78
+ private adjustCallArgs;
62
79
  private processNode;
80
+ private processKeyword;
63
81
  private processTypeAlias;
64
- private processTypeHint;
65
82
  private processComment;
66
83
  private processAgencyObject;
67
84
  private processAgencyArray;
@@ -86,6 +103,7 @@ export declare class TypeScriptBuilder {
86
103
  private generateToolRegistry;
87
104
  private processFunctionDefinition;
88
105
  private processStatement;
106
+ private buildInterruptReturn;
89
107
  private processFunctionCallAsStatement;
90
108
  private processFunctionCall;
91
109
  private generateFunctionCallExpression;
@@ -101,11 +119,16 @@ export declare class TypeScriptBuilder {
101
119
  * response format from type hints, and tools from config object.
102
120
  */
103
121
  private processLlmCall;
104
- private buildPromptString;
122
+ private processSentinel;
123
+ private processDebuggerStatement;
105
124
  private processSpecialVar;
106
125
  private processMessageThread;
107
126
  private processBlockPlain;
108
127
  private processHandleBlockWithSteps;
128
+ /** In debugger mode, insert debuggerStatement nodes before each
129
+ * step-triggering statement so that debugStep() is called at every
130
+ * substep boundary, not just top-level steps. */
131
+ private insertDebugSteps;
109
132
  private processBodyAsParts;
110
133
  private generateBuiltins;
111
134
  private generateImports;