agency-lang 0.0.86 → 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 (239) hide show
  1. package/dist/lib/backends/agencyGenerator.d.ts +2 -4
  2. package/dist/lib/backends/agencyGenerator.js +44 -31
  3. package/dist/lib/backends/index.d.ts +1 -0
  4. package/dist/lib/backends/index.js +1 -0
  5. package/dist/lib/backends/sourceMap.d.ts +13 -0
  6. package/dist/lib/backends/sourceMap.js +18 -0
  7. package/dist/lib/backends/sourceMap.test.js +57 -0
  8. package/dist/lib/backends/typescriptBuilder.d.ts +21 -4
  9. package/dist/lib/backends/typescriptBuilder.integration.test.js +27 -1
  10. package/dist/lib/backends/typescriptBuilder.js +398 -264
  11. package/dist/lib/backends/typescriptGenerator/typeToString.js +10 -0
  12. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +2 -0
  13. package/dist/lib/backends/typescriptGenerator.integration.test.js +1 -1
  14. package/dist/lib/cli/bundle.d.ts +1 -0
  15. package/dist/lib/cli/bundle.js +58 -0
  16. package/dist/lib/cli/bundle.test.d.ts +1 -0
  17. package/dist/lib/cli/bundle.test.js +74 -0
  18. package/dist/lib/cli/commands.js +4 -4
  19. package/dist/lib/cli/debug.d.ts +7 -0
  20. package/dist/lib/cli/debug.js +166 -0
  21. package/dist/lib/cli/definition.d.ts +22 -0
  22. package/dist/lib/cli/definition.js +66 -0
  23. package/dist/lib/cli/definition.test.d.ts +1 -0
  24. package/dist/lib/cli/definition.test.js +145 -0
  25. package/dist/lib/cli/doc.d.ts +2 -0
  26. package/dist/lib/cli/doc.js +117 -0
  27. package/dist/lib/cli/doc.test.d.ts +1 -0
  28. package/dist/lib/cli/doc.test.js +133 -0
  29. package/dist/lib/cli/test.d.ts +2 -2
  30. package/dist/lib/cli/test.js +253 -153
  31. package/dist/lib/cli/util.d.ts +28 -15
  32. package/dist/lib/cli/util.js +75 -15
  33. package/dist/lib/config.d.ts +10 -1
  34. package/dist/lib/config.js +0 -1
  35. package/dist/lib/debugger/debuggerState.d.ts +49 -0
  36. package/dist/lib/debugger/debuggerState.js +112 -0
  37. package/dist/lib/debugger/debuggerState.test.d.ts +1 -0
  38. package/dist/lib/debugger/debuggerState.test.js +115 -0
  39. package/dist/lib/debugger/driver.d.ts +60 -0
  40. package/dist/lib/debugger/driver.js +505 -0
  41. package/dist/lib/debugger/driver.test.d.ts +1 -0
  42. package/dist/lib/debugger/driver.test.js +762 -0
  43. package/dist/lib/debugger/testHelpers.d.ts +29 -0
  44. package/dist/lib/debugger/testHelpers.js +96 -0
  45. package/dist/lib/debugger/thread.test.d.ts +1 -0
  46. package/dist/lib/debugger/thread.test.js +84 -0
  47. package/dist/lib/debugger/trace.test.d.ts +1 -0
  48. package/dist/lib/debugger/trace.test.js +75 -0
  49. package/dist/lib/debugger/types.d.ts +61 -0
  50. package/dist/lib/debugger/types.js +1 -0
  51. package/dist/lib/debugger/ui.d.ts +54 -0
  52. package/dist/lib/debugger/ui.js +741 -0
  53. package/dist/lib/debugger/uiState.d.ts +86 -0
  54. package/dist/lib/debugger/uiState.js +244 -0
  55. package/dist/lib/debugger/uiState.test.d.ts +1 -0
  56. package/dist/lib/debugger/uiState.test.js +251 -0
  57. package/dist/lib/debugger/util.d.ts +6 -0
  58. package/dist/lib/debugger/util.js +133 -0
  59. package/dist/lib/debugger/util.test.d.ts +1 -0
  60. package/dist/lib/debugger/util.test.js +164 -0
  61. package/dist/lib/importPaths.d.ts +40 -0
  62. package/dist/lib/importPaths.js +168 -0
  63. package/dist/lib/importPaths.test.js +161 -2
  64. package/dist/lib/ir/audit.js +3 -23
  65. package/dist/lib/ir/audit.test.js +4 -9
  66. package/dist/lib/ir/builders.d.ts +48 -16
  67. package/dist/lib/ir/builders.js +44 -16
  68. package/dist/lib/ir/prettyPrint.js +47 -147
  69. package/dist/lib/ir/prettyPrint.test.js +0 -77
  70. package/dist/lib/ir/tsIR.d.ts +50 -74
  71. package/dist/lib/parser.js +9 -3
  72. package/dist/lib/parser.test.js +6 -26
  73. package/dist/lib/parsers/access.js +2 -1
  74. package/dist/lib/parsers/assignment.test.js +107 -6
  75. package/dist/lib/parsers/blockArgument.d.ts +3 -0
  76. package/dist/lib/parsers/blockArgument.js +28 -0
  77. package/dist/lib/parsers/blockArgument.test.d.ts +1 -0
  78. package/dist/lib/parsers/blockArgument.test.js +118 -0
  79. package/dist/lib/parsers/dataStructures.js +3 -3
  80. package/dist/lib/parsers/debuggerStatement.js +2 -1
  81. package/dist/lib/parsers/debuggerStatement.test.js +2 -0
  82. package/dist/lib/parsers/expression.js +3 -3
  83. package/dist/lib/parsers/function.d.ts +5 -2
  84. package/dist/lib/parsers/function.js +55 -24
  85. package/dist/lib/parsers/function.test.js +218 -149
  86. package/dist/lib/parsers/functionCall.js +6 -3
  87. package/dist/lib/parsers/functionCall.test.js +90 -0
  88. package/dist/lib/parsers/literals.d.ts +4 -3
  89. package/dist/lib/parsers/literals.js +12 -11
  90. package/dist/lib/parsers/loc.js +6 -1
  91. package/dist/lib/parsers/matchBlock.js +2 -2
  92. package/dist/lib/parsers/returnStatement.js +2 -2
  93. package/dist/lib/parsers/typeHints.d.ts +2 -2
  94. package/dist/lib/parsers/typeHints.js +22 -6
  95. package/dist/lib/parsers/typeHints.test.js +48 -364
  96. package/dist/lib/preprocessors/importResolver.d.ts +0 -8
  97. package/dist/lib/preprocessors/importResolver.js +29 -4
  98. package/dist/lib/preprocessors/importResolver.test.js +20 -3
  99. package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +1 -2
  100. package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +0 -20
  101. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -5
  102. package/dist/lib/preprocessors/typescriptPreprocessor.integration.test.js +1 -1
  103. package/dist/lib/preprocessors/typescriptPreprocessor.js +56 -32
  104. package/dist/lib/programInfo.d.ts +6 -6
  105. package/dist/lib/programInfo.js +18 -11
  106. package/dist/lib/programInfo.test.js +1 -113
  107. package/dist/lib/runtime/audit.d.ts +2 -2
  108. package/dist/lib/runtime/checkpoint.js +6 -2
  109. package/dist/lib/runtime/checkpoint.test.js +14 -4
  110. package/dist/lib/runtime/debugger.d.ts +9 -0
  111. package/dist/lib/runtime/debugger.js +86 -0
  112. package/dist/lib/runtime/debugger.test.d.ts +1 -0
  113. package/dist/lib/runtime/debugger.test.js +161 -0
  114. package/dist/lib/runtime/index.d.ts +5 -0
  115. package/dist/lib/runtime/index.js +5 -0
  116. package/dist/lib/runtime/interrupts.d.ts +2 -1
  117. package/dist/lib/runtime/interrupts.js +81 -27
  118. package/dist/lib/runtime/prompt.js +9 -3
  119. package/dist/lib/runtime/rewind.js +6 -0
  120. package/dist/lib/runtime/runner.d.ts +73 -0
  121. package/dist/lib/runtime/runner.js +368 -0
  122. package/dist/lib/runtime/runner.test.d.ts +1 -0
  123. package/dist/lib/runtime/runner.test.js +423 -0
  124. package/dist/lib/runtime/state/checkpointStore.d.ts +81 -8
  125. package/dist/lib/runtime/state/checkpointStore.js +256 -17
  126. package/dist/lib/runtime/state/checkpointStore.test.js +504 -30
  127. package/dist/lib/runtime/state/context.d.ts +4 -0
  128. package/dist/lib/runtime/state/context.js +13 -2
  129. package/dist/lib/runtime/state/context.test.d.ts +1 -0
  130. package/dist/lib/runtime/state/context.test.js +20 -0
  131. package/dist/lib/runtime/state/globalStore.d.ts +4 -0
  132. package/dist/lib/runtime/state/globalStore.js +9 -0
  133. package/dist/lib/runtime/state/schemas.d.ts +86 -0
  134. package/dist/lib/runtime/state/schemas.js +50 -0
  135. package/dist/lib/runtime/state/sourceLocation.d.ts +6 -0
  136. package/dist/lib/runtime/state/sourceLocation.js +1 -0
  137. package/dist/lib/runtime/state/stateStack.d.ts +14 -0
  138. package/dist/lib/runtime/state/stateStack.js +39 -3
  139. package/dist/lib/runtime/state/stateStack.test.js +27 -0
  140. package/dist/lib/runtime/trace/canonicalize.d.ts +1 -0
  141. package/dist/lib/runtime/trace/canonicalize.js +17 -0
  142. package/dist/lib/runtime/trace/canonicalize.test.d.ts +1 -0
  143. package/dist/lib/runtime/trace/canonicalize.test.js +39 -0
  144. package/dist/lib/runtime/trace/contentAddressableStore.d.ts +23 -0
  145. package/dist/lib/runtime/trace/contentAddressableStore.js +94 -0
  146. package/dist/lib/runtime/trace/contentAddressableStore.test.d.ts +1 -0
  147. package/dist/lib/runtime/trace/contentAddressableStore.test.js +88 -0
  148. package/dist/lib/runtime/trace/traceReader.d.ts +10 -0
  149. package/dist/lib/runtime/trace/traceReader.js +67 -0
  150. package/dist/lib/runtime/trace/traceReader.test.d.ts +1 -0
  151. package/dist/lib/runtime/trace/traceReader.test.js +150 -0
  152. package/dist/lib/runtime/trace/traceWriter.d.ts +9 -0
  153. package/dist/lib/runtime/trace/traceWriter.js +34 -0
  154. package/dist/lib/runtime/trace/traceWriter.test.d.ts +1 -0
  155. package/dist/lib/runtime/trace/traceWriter.test.js +103 -0
  156. package/dist/lib/runtime/trace/types.d.ts +42 -0
  157. package/dist/lib/runtime/trace/types.js +4 -0
  158. package/dist/lib/runtime/types.d.ts +4 -1
  159. package/dist/lib/statelogClient.d.ts +2 -27
  160. package/dist/lib/statelogClient.js +8 -135
  161. package/dist/lib/symbolTable.d.ts +3 -1
  162. package/dist/lib/symbolTable.js +4 -2
  163. package/dist/lib/symbolTable.test.js +4 -3
  164. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +12 -0
  165. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +21 -0
  166. package/dist/lib/templates/backends/typescriptGenerator/debugger.d.ts +5 -1
  167. package/dist/lib/templates/backends/typescriptGenerator/debugger.js +13 -13
  168. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
  169. package/dist/lib/templates/backends/typescriptGenerator/imports.js +7 -3
  170. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +5 -3
  171. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +14 -6
  172. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +4 -1
  173. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +11 -16
  174. package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.d.ts +4 -1
  175. package/dist/lib/templates/backends/typescriptGenerator/rewindCheckpoint.js +1 -1
  176. package/dist/lib/templates/backends/typescriptGenerator/traceSetup.d.ts +7 -0
  177. package/dist/lib/templates/backends/typescriptGenerator/traceSetup.js +12 -0
  178. package/dist/lib/templates/cli/evaluate.d.ts +2 -1
  179. package/dist/lib/templates/cli/evaluate.js +1 -1
  180. package/dist/lib/templates/cli/judgeEvaluate.d.ts +2 -1
  181. package/dist/lib/templates/cli/judgeEvaluate.js +1 -1
  182. package/dist/lib/typeChecker.js +17 -12
  183. package/dist/lib/typeChecker.test.js +20 -39
  184. package/dist/lib/types/blockArgument.d.ts +8 -0
  185. package/dist/lib/types/blockArgument.js +1 -0
  186. package/dist/lib/types/dataStructures.d.ts +5 -0
  187. package/dist/lib/types/debuggerStatement.d.ts +1 -0
  188. package/dist/lib/types/function.d.ts +8 -2
  189. package/dist/lib/types/literals.d.ts +4 -1
  190. package/dist/lib/types/typeHints.d.ts +8 -5
  191. package/dist/lib/types.d.ts +12 -7
  192. package/dist/lib/types.js +1 -0
  193. package/dist/lib/utils/markdown.d.ts +6 -0
  194. package/dist/lib/utils/markdown.js +21 -0
  195. package/dist/lib/utils/markdown.test.d.ts +1 -0
  196. package/dist/lib/utils/markdown.test.js +39 -0
  197. package/dist/lib/utils/node.js +40 -5
  198. package/dist/lib/utils.d.ts +1 -0
  199. package/dist/lib/utils.js +4 -0
  200. package/dist/lib/version.d.ts +1 -0
  201. package/dist/lib/version.js +1 -0
  202. package/dist/scripts/agency.js +82 -44
  203. package/dist/scripts/regenerate-fixtures.js +18 -60
  204. package/package.json +10 -6
  205. package/stdlib/_builtins.js +7 -3
  206. package/stdlib/clipboard.agency +15 -0
  207. package/stdlib/index.agency +12 -12
  208. package/stdlib/index.js +1285 -1238
  209. package/stdlib/lib/clipboard.js +29 -0
  210. package/stdlib/lib/process.js +29 -0
  211. package/stdlib/lib/speech.js +69 -0
  212. package/stdlib/lib/system.js +29 -0
  213. package/stdlib/math.agency +3 -3
  214. package/stdlib/math.js +66 -60
  215. package/stdlib/process.agency +25 -0
  216. package/stdlib/speech.agency +15 -0
  217. package/stdlib/system.agency +8 -0
  218. package/dist/lib/cli/remoteRun.d.ts +0 -3
  219. package/dist/lib/cli/remoteRun.js +0 -35
  220. package/dist/lib/cli/upload.d.ts +0 -3
  221. package/dist/lib/cli/upload.js +0 -50
  222. package/dist/lib/runtime/rewind.test.js +0 -80
  223. package/dist/lib/templates/backends/typescriptGenerator/forSteps.d.ts +0 -20
  224. package/dist/lib/templates/backends/typescriptGenerator/forSteps.js +0 -29
  225. package/dist/lib/templates/backends/typescriptGenerator/handleSteps.d.ts +0 -16
  226. package/dist/lib/templates/backends/typescriptGenerator/handleSteps.js +0 -22
  227. package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.d.ts +0 -17
  228. package/dist/lib/templates/backends/typescriptGenerator/ifStepsBranchDispatch.js +0 -18
  229. package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.d.ts +0 -17
  230. package/dist/lib/templates/backends/typescriptGenerator/ifStepsCondbranch.js +0 -26
  231. package/dist/lib/templates/backends/typescriptGenerator/substepBlock.d.ts +0 -10
  232. package/dist/lib/templates/backends/typescriptGenerator/substepBlock.js +0 -12
  233. package/dist/lib/templates/backends/typescriptGenerator/threadSteps.d.ts +0 -16
  234. package/dist/lib/templates/backends/typescriptGenerator/threadSteps.js +0 -21
  235. package/dist/lib/templates/backends/typescriptGenerator/whileSteps.d.ts +0 -16
  236. package/dist/lib/templates/backends/typescriptGenerator/whileSteps.js +0 -26
  237. package/stdlib/lib/test.js +0 -3
  238. /package/dist/lib/{runtime/rewind.test.d.ts → backends/sourceMap.test.d.ts} +0 -0
  239. /package/stdlib/{_utils.js → lib/utils.js} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { SpecialVar } from "../types/specialVar.js";
2
- import { AgencyComment, AgencyMultiLineComment, AgencyNode, AgencyProgram, Assignment, DebuggerStatement, 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;
@@ -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));
@@ -71,7 +64,7 @@ export class AgencyGenerator {
71
64
  const NO_SPACE_TYPES = new Set([
72
65
  "comment", "multiLineComment"
73
66
  ]);
74
- // Pass 7: Process all nodes and generate code
67
+ // Pass 5: Process all nodes and generate code
75
68
  const stmtPairs = [];
76
69
  for (const node of program.nodes) {
77
70
  const result = this.processNode(node);
@@ -128,8 +121,6 @@ export class AgencyGenerator {
128
121
  processGraphNodeName(node) { }
129
122
  processNode(node) {
130
123
  switch (node.type) {
131
- case "typeHint":
132
- return this.processTypeHint(node);
133
124
  case "typeAlias":
134
125
  return this.processTypeAlias(node);
135
126
  case "assignment":
@@ -151,6 +142,7 @@ export class AgencyGenerator {
151
142
  case "string":
152
143
  case "variableName":
153
144
  case "boolean":
145
+ case "null":
154
146
  return this.generateLiteral(node);
155
147
  case "returnStatement":
156
148
  return this.processReturnStatement(node);
@@ -286,11 +278,6 @@ export class AgencyGenerator {
286
278
  const aliasedTypeStr = this.aliasedTypeToString(node.aliasedType);
287
279
  return this.indentStr(`type ${node.aliasName} = ${aliasedTypeStr}`);
288
280
  }
289
- processTypeHint(node) {
290
- this.typeHints[node.variableName] = node.variableType;
291
- const typeStr = variableTypeToString(node.variableType, this.typeAliases);
292
- return this.indentStr(`${node.variableName} :: ${typeStr}`);
293
- }
294
281
  // Assignment and literals
295
282
  processAssignment(node) {
296
283
  const chainStr = node.accessChain
@@ -299,9 +286,10 @@ export class AgencyGenerator {
299
286
  const varName = node.typeHint
300
287
  ? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases)}`
301
288
  : `${node.variableName}${chainStr}`;
302
- const prefix = node.shared ? "shared " : "";
289
+ const sharedPrefix = node.shared ? "shared " : "";
290
+ const declPrefix = node.declKind ? `${node.declKind} ` : "";
303
291
  let valueCode = this.processNode(node.value).trim();
304
- return this.indentStr(`${prefix}${varName} = ${valueCode}`);
292
+ return this.indentStr(`${sharedPrefix}${declPrefix}${varName} = ${valueCode}`);
305
293
  }
306
294
  generateLiteral(literal) {
307
295
  switch (literal.type) {
@@ -315,6 +303,8 @@ export class AgencyGenerator {
315
303
  return this.generateMultiLineStringLiteral(literal);
316
304
  case "boolean":
317
305
  return literal.value ? "true" : "false";
306
+ case "null":
307
+ return "null";
318
308
  default:
319
309
  return "";
320
310
  }
@@ -353,12 +343,16 @@ export class AgencyGenerator {
353
343
  const { functionName, body, parameters } = node;
354
344
  const params = parameters
355
345
  .map((p) => {
346
+ const prefix = p.variadic ? "..." : "";
347
+ const defaultSuffix = p.defaultValue
348
+ ? ` = ${this.processNode(p.defaultValue).trim()}`
349
+ : "";
356
350
  if (p.typeHint) {
357
351
  const typeStr = variableTypeToString(p.typeHint, this.typeAliases);
358
- return `${p.name}: ${typeStr}`;
352
+ return `${prefix}${p.name}: ${typeStr}${defaultSuffix}`;
359
353
  }
360
354
  else {
361
- return p.name;
355
+ return `${prefix}${p.name}${defaultSuffix}`;
362
356
  }
363
357
  })
364
358
  .join(", ");
@@ -366,14 +360,8 @@ export class AgencyGenerator {
366
360
  ? ": " + variableTypeToString(node.returnType, this.typeAliases)
367
361
  : "";
368
362
  let safePrefix = node.safe ? "safe " : "";
369
- let asyncPrefix = "";
370
- if (node.async === true) {
371
- asyncPrefix = "async ";
372
- }
373
- else if (node.async === false) {
374
- asyncPrefix = "sync ";
375
- }
376
- 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`);
377
365
  this.increaseIndent();
378
366
  if (node.docString) {
379
367
  const docLines = [`"""`, ...node.docString.value.split("\n"), `"""`];
@@ -396,6 +384,12 @@ export class AgencyGenerator {
396
384
  }
397
385
  generateFunctionCallExpression(node, context) {
398
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
+ }
399
393
  return this.processNode(arg).trim();
400
394
  });
401
395
  let asyncPrefix = "";
@@ -405,7 +399,26 @@ export class AgencyGenerator {
405
399
  else if (node.async === false) {
406
400
  asyncPrefix = "await ";
407
401
  }
408
- 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;
409
422
  }
410
423
  // Data structures
411
424
  processAgencyArray(node) {
@@ -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,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,6 +15,7 @@ export declare class TypeScriptBuilder {
15
15
  private loopVars;
16
16
  private insideMessageThread;
17
17
  private insideHandlerBody;
18
+ private _blockCounter;
18
19
  /** Stack of loop subKeys for generating break/continue cleanup code.
19
20
  * Pushed when entering a stepped loop, popped when leaving. */
20
21
  private _loopContextStack;
@@ -24,6 +25,7 @@ export declare class TypeScriptBuilder {
24
25
  * has been broken into substeps. Used to generate unique variable names
25
26
  * like __substep_3_1 for nested blocks. */
26
27
  private _subStepPath;
28
+ private _sourceMapBuilder;
27
29
  private programInfo;
28
30
  private moduleId;
29
31
  /**
@@ -47,9 +49,11 @@ export declare class TypeScriptBuilder {
47
49
  */
48
50
  private scopedAssign;
49
51
  private currentScopeKey;
50
- 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;
51
56
  private getVisibleTypeAliases;
52
- private getVisibleTypeHints;
53
57
  private forkBranchSetup;
54
58
  private isImportedTool;
55
59
  private static RUNTIME_STATEFUL_FUNCTIONS;
@@ -62,10 +66,19 @@ export declare class TypeScriptBuilder {
62
66
  private needsParensLeft;
63
67
  private needsParensRight;
64
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;
65
79
  private processNode;
66
80
  private processKeyword;
67
81
  private processTypeAlias;
68
- private processTypeHint;
69
82
  private processComment;
70
83
  private processAgencyObject;
71
84
  private processAgencyArray;
@@ -90,6 +103,7 @@ export declare class TypeScriptBuilder {
90
103
  private generateToolRegistry;
91
104
  private processFunctionDefinition;
92
105
  private processStatement;
106
+ private buildInterruptReturn;
93
107
  private processFunctionCallAsStatement;
94
108
  private processFunctionCall;
95
109
  private generateFunctionCallExpression;
@@ -107,11 +121,14 @@ export declare class TypeScriptBuilder {
107
121
  private processLlmCall;
108
122
  private processSentinel;
109
123
  private processDebuggerStatement;
110
- private buildPromptString;
111
124
  private processSpecialVar;
112
125
  private processMessageThread;
113
126
  private processBlockPlain;
114
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;
115
132
  private processBodyAsParts;
116
133
  private generateBuiltins;
117
134
  private generateImports;
@@ -58,7 +58,7 @@ function normalizeWhitespace(code) {
58
58
  .concat("\n"));
59
59
  }
60
60
  export function generateWithBuilder(agencySource, moduleId = "test.agency") {
61
- const parseResult = parseAgency(agencySource);
61
+ const parseResult = parseAgency(agencySource, {}, false);
62
62
  if (!parseResult.success) {
63
63
  throw new Error(`Failed to parse: ${parseResult.message}`);
64
64
  }
@@ -93,3 +93,29 @@ describe("TypeScript Builder Integration Tests", () => {
93
93
  });
94
94
  });
95
95
  });
96
+ describe("Named argument validation", () => {
97
+ it("should throw on mismatched named argument", () => {
98
+ expect(() => generateWithBuilder(`
99
+ def greet(name: string, greeting: string = "Hello") {
100
+ print(name)
101
+ }
102
+ greet(greeting: "Hi")
103
+ `)).toThrow("Named argument 'greeting' does not match parameter 'name' at position 1");
104
+ });
105
+ it("should throw on named argument beyond parameter list", () => {
106
+ expect(() => generateWithBuilder(`
107
+ def foo(a: string) {
108
+ print(a)
109
+ }
110
+ foo(a: "hi", extra: "oops")
111
+ `)).toThrow("Named argument 'extra' at position 2 is beyond the parameter list");
112
+ });
113
+ it("should accept correct named arguments", () => {
114
+ expect(() => generateWithBuilder(`
115
+ def greet(name: string, greeting: string = "Hello") {
116
+ print(name)
117
+ }
118
+ greet(name: "world", greeting: "Hi")
119
+ `)).not.toThrow();
120
+ });
121
+ });