agency-lang 0.2.0 → 0.3.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 (431) hide show
  1. package/dist/lib/agents/agency-agent/agent.agency +3 -2
  2. package/dist/lib/agents/judge.js +67 -70
  3. package/dist/lib/agents/policy/agent.agency +153 -53
  4. package/dist/lib/agents/policy/prompts/system.md +7 -0
  5. package/dist/lib/agents/review/agent.agency +2 -1
  6. package/dist/lib/agents/review/agent.js +394 -446
  7. package/dist/lib/backends/agencyGenerator.d.ts +45 -2
  8. package/dist/lib/backends/agencyGenerator.js +249 -62
  9. package/dist/lib/backends/agencyGenerator.test.js +106 -76
  10. package/dist/lib/backends/docstringInterpolationRuntime.test.js +59 -0
  11. package/dist/lib/backends/typescriptBuilder/assignmentEmitter.d.ts +64 -0
  12. package/dist/lib/backends/typescriptBuilder/assignmentEmitter.js +104 -0
  13. package/dist/lib/backends/typescriptBuilder/nameClassifier.d.ts +51 -0
  14. package/dist/lib/backends/typescriptBuilder/nameClassifier.js +130 -0
  15. package/dist/lib/backends/typescriptBuilder/namedArgsResolver.d.ts +28 -0
  16. package/dist/lib/backends/typescriptBuilder/namedArgsResolver.js +92 -0
  17. package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.d.ts +1 -0
  18. package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.js +75 -0
  19. package/dist/lib/backends/typescriptBuilder/pipeChainEmitter.d.ts +94 -0
  20. package/dist/lib/backends/typescriptBuilder/pipeChainEmitter.js +227 -0
  21. package/dist/lib/backends/typescriptBuilder/pipeReceiverCodegen.test.d.ts +1 -0
  22. package/dist/lib/backends/typescriptBuilder/pipeReceiverCodegen.test.js +58 -0
  23. package/dist/lib/backends/typescriptBuilder/scopeManager.d.ts +62 -0
  24. package/dist/lib/backends/typescriptBuilder/scopeManager.js +131 -0
  25. package/dist/lib/backends/typescriptBuilder/sectionAssembler.d.ts +108 -0
  26. package/dist/lib/backends/typescriptBuilder/sectionAssembler.js +249 -0
  27. package/dist/lib/backends/typescriptBuilder/stepPathTracker.d.ts +45 -0
  28. package/dist/lib/backends/typescriptBuilder/stepPathTracker.js +76 -0
  29. package/dist/lib/backends/typescriptBuilder.d.ts +37 -114
  30. package/dist/lib/backends/typescriptBuilder.integration.test.js +0 -26
  31. package/dist/lib/backends/typescriptBuilder.js +603 -974
  32. package/dist/lib/backends/typescriptGenerator/jsonSchemaAnnotation.test.d.ts +1 -0
  33. package/dist/lib/backends/typescriptGenerator/jsonSchemaAnnotation.test.js +104 -0
  34. package/dist/lib/backends/typescriptGenerator/tagArgToTs.d.ts +19 -0
  35. package/dist/lib/backends/typescriptGenerator/tagArgToTs.js +171 -0
  36. package/dist/lib/backends/typescriptGenerator/tagArgToTs.test.d.ts +1 -0
  37. package/dist/lib/backends/typescriptGenerator/tagArgToTs.test.js +44 -0
  38. package/dist/lib/backends/typescriptGenerator/typeToString.js +96 -1
  39. package/dist/lib/backends/typescriptGenerator/typeToString.test.d.ts +1 -0
  40. package/dist/lib/backends/typescriptGenerator/typeToString.test.js +52 -0
  41. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.d.ts +12 -3
  42. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +105 -9
  43. package/dist/lib/backends/typescriptGenerator/typeToZodSchema.test.js +122 -1
  44. package/dist/lib/backends/typescriptGenerator/validationDescriptor.d.ts +31 -0
  45. package/dist/lib/backends/typescriptGenerator/validationDescriptor.js +257 -0
  46. package/dist/lib/cli/commands.js +9 -4
  47. package/dist/lib/cli/debug.js +2 -0
  48. package/dist/lib/cli/doc.js +74 -3
  49. package/dist/lib/cli/doc.test.js +39 -0
  50. package/dist/lib/cli/evaluate.js +3 -3
  51. package/dist/lib/cli/optimize.js +23 -2
  52. package/dist/lib/cli/optimize.test.js +6 -1
  53. package/dist/lib/cli/schedule/index.js +1 -0
  54. package/dist/lib/cli/serve.js +1 -0
  55. package/dist/lib/cli/test.js +19 -6
  56. package/dist/lib/cli/util.d.ts +2 -1
  57. package/dist/lib/cli/util.js +14 -6
  58. package/dist/lib/compilationUnit.d.ts +6 -7
  59. package/dist/lib/compilationUnit.js +35 -16
  60. package/dist/lib/compilationUnit.test.js +3 -35
  61. package/dist/lib/compiler/compile.d.ts +9 -6
  62. package/dist/lib/compiler/compile.js +36 -42
  63. package/dist/lib/compiler/compile.test.js +71 -21
  64. package/dist/lib/compiler/typecheck.d.ts +18 -0
  65. package/dist/lib/compiler/typecheck.js +79 -0
  66. package/dist/lib/config.js +1 -1
  67. package/dist/lib/debugger/debuggerState.js +0 -3
  68. package/dist/lib/debugger/driver.js +12 -3
  69. package/dist/lib/debugger/testHelpers.js +1 -0
  70. package/dist/lib/debugger/uiState.js +1 -0
  71. package/dist/lib/formatter.test.js +8 -0
  72. package/dist/lib/importPaths.d.ts +33 -0
  73. package/dist/lib/importPaths.js +37 -0
  74. package/dist/lib/importPaths.test.js +70 -0
  75. package/dist/lib/ir/builders.d.ts +115 -15
  76. package/dist/lib/ir/builders.js +166 -54
  77. package/dist/lib/ir/prettyPrint.js +43 -5
  78. package/dist/lib/ir/prettyPrint.test.js +35 -1
  79. package/dist/lib/ir/tsIR.d.ts +25 -1
  80. package/dist/lib/logsViewer/render.d.ts +2 -1
  81. package/dist/lib/logsViewer/render.js +57 -13
  82. package/dist/lib/logsViewer/render.test.js +63 -1
  83. package/dist/lib/logsViewer/run.js +5 -1
  84. package/dist/lib/logsViewer/search.d.ts +1 -1
  85. package/dist/lib/logsViewer/search.js +9 -5
  86. package/dist/lib/logsViewer/search.test.js +1 -1
  87. package/dist/lib/logsViewer/summary.js +1 -1
  88. package/dist/lib/logsViewer/types.d.ts +1 -0
  89. package/dist/lib/lowering/patternLowering.js +27 -1
  90. package/dist/lib/lowering/patternLowering.test.js +165 -0
  91. package/dist/lib/lsp/builtinHover.d.ts +5 -1
  92. package/dist/lib/lsp/builtinHover.js +41 -2
  93. package/dist/lib/lsp/completion.js +10 -6
  94. package/dist/lib/lsp/diagnostics.js +2 -2
  95. package/dist/lib/lsp/documentSymbol.js +0 -8
  96. package/dist/lib/lsp/foldingRange.js +0 -1
  97. package/dist/lib/lsp/semantics.js +1 -14
  98. package/dist/lib/lsp/server.js +1 -0
  99. package/dist/lib/lsp/workspaceSymbol.js +0 -1
  100. package/dist/lib/parser.js +2 -2
  101. package/dist/lib/parsers/function.test.js +175 -140
  102. package/dist/lib/parsers/objectTypeTags.test.d.ts +1 -0
  103. package/dist/lib/parsers/objectTypeTags.test.js +69 -0
  104. package/dist/lib/parsers/parsers.d.ts +50 -7
  105. package/dist/lib/parsers/parsers.js +302 -121
  106. package/dist/lib/parsers/pattern.test.js +146 -0
  107. package/dist/lib/parsers/tag.test.js +141 -13
  108. package/dist/lib/parsers/tagIntegration.test.js +11 -8
  109. package/dist/lib/parsers/typeHints.test.js +330 -1
  110. package/dist/lib/preprocessors/importResolver.js +10 -2
  111. package/dist/lib/preprocessors/injectSchemaArgs.d.ts +36 -0
  112. package/dist/lib/preprocessors/injectSchemaArgs.js +209 -0
  113. package/dist/lib/preprocessors/injectSchemaArgs.test.d.ts +1 -0
  114. package/dist/lib/preprocessors/injectSchemaArgs.test.js +383 -0
  115. package/dist/lib/preprocessors/liftCallbacks.d.ts +2 -0
  116. package/dist/lib/preprocessors/liftCallbacks.js +242 -0
  117. package/dist/lib/preprocessors/liftCallbacks.test.d.ts +1 -0
  118. package/dist/lib/preprocessors/liftCallbacks.test.js +146 -0
  119. package/dist/lib/preprocessors/parallelDesugar.js +4 -5
  120. package/dist/lib/preprocessors/resolveReExports.js +1 -3
  121. package/dist/lib/preprocessors/typeAliasTags.test.d.ts +1 -0
  122. package/dist/lib/preprocessors/typeAliasTags.test.js +57 -0
  123. package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +3 -3
  124. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +9 -1
  125. package/dist/lib/preprocessors/typescriptPreprocessor.js +66 -30
  126. package/dist/lib/runtime/__tests__/node.test.js +8 -3
  127. package/dist/lib/runtime/__tests__/testHelpers.js +31 -0
  128. package/dist/lib/runtime/agency.d.ts +49 -0
  129. package/dist/lib/runtime/agency.js +204 -0
  130. package/dist/lib/runtime/agency.test.d.ts +1 -0
  131. package/dist/lib/runtime/agency.test.js +277 -0
  132. package/dist/lib/runtime/agencyFunction.d.ts +15 -3
  133. package/dist/lib/runtime/agencyFunction.js +37 -24
  134. package/dist/lib/runtime/agencyFunction.test.js +76 -12
  135. package/dist/lib/runtime/agencyInterrupt.d.ts +18 -0
  136. package/dist/lib/runtime/agencyInterrupt.js +159 -0
  137. package/dist/lib/runtime/agencyInterrupt.test.d.ts +1 -0
  138. package/dist/lib/runtime/agencyInterrupt.test.js +231 -0
  139. package/dist/lib/runtime/agencyLlm.checkpointInfo.test.d.ts +1 -0
  140. package/dist/lib/runtime/agencyLlm.checkpointInfo.test.js +63 -0
  141. package/dist/lib/runtime/agencyLlm.d.ts +59 -0
  142. package/dist/lib/runtime/agencyLlm.js +20 -0
  143. package/dist/lib/runtime/agencyLlm.test.d.ts +1 -0
  144. package/dist/lib/runtime/agencyLlm.test.js +199 -0
  145. package/dist/lib/runtime/asyncContext.d.ts +208 -0
  146. package/dist/lib/runtime/asyncContext.js +196 -0
  147. package/dist/lib/runtime/asyncContext.test.d.ts +1 -0
  148. package/dist/lib/runtime/asyncContext.test.js +221 -0
  149. package/dist/lib/runtime/call.d.ts +15 -2
  150. package/dist/lib/runtime/call.js +17 -4
  151. package/dist/lib/runtime/call.test.js +20 -7
  152. package/dist/lib/runtime/checkpoint.d.ts +11 -4
  153. package/dist/lib/runtime/checkpoint.js +19 -11
  154. package/dist/lib/runtime/checkpoint.test.js +54 -39
  155. package/dist/lib/runtime/debugger.d.ts +1 -2
  156. package/dist/lib/runtime/debugger.js +1 -1
  157. package/dist/lib/runtime/debugger.test.js +13 -16
  158. package/dist/lib/runtime/deterministicClient.d.ts +9 -1
  159. package/dist/lib/runtime/deterministicClient.js +19 -5
  160. package/dist/lib/runtime/deterministicClient.test.js +10 -2
  161. package/dist/lib/runtime/guard.d.ts +243 -0
  162. package/dist/lib/runtime/guard.js +314 -0
  163. package/dist/lib/runtime/guard.test.d.ts +1 -0
  164. package/dist/lib/runtime/guard.test.js +289 -0
  165. package/dist/lib/runtime/haltSignal.d.ts +21 -0
  166. package/dist/lib/runtime/haltSignal.js +24 -0
  167. package/dist/lib/runtime/hooks.d.ts +49 -4
  168. package/dist/lib/runtime/hooks.js +148 -35
  169. package/dist/lib/runtime/hooks.test.d.ts +1 -0
  170. package/dist/lib/runtime/hooks.test.js +143 -0
  171. package/dist/lib/runtime/index.d.ts +18 -1
  172. package/dist/lib/runtime/index.js +12 -0
  173. package/dist/lib/runtime/interrupts.d.ts +2 -1
  174. package/dist/lib/runtime/interrupts.js +34 -6
  175. package/dist/lib/runtime/ipc.d.ts +1 -2
  176. package/dist/lib/runtime/ipc.js +6 -3
  177. package/dist/lib/runtime/memory/manager.js +51 -0
  178. package/dist/lib/runtime/memory/manager.test.js +173 -0
  179. package/dist/lib/runtime/node.d.ts +5 -5
  180. package/dist/lib/runtime/node.js +92 -36
  181. package/dist/lib/runtime/policy.d.ts +19 -5
  182. package/dist/lib/runtime/policy.js +9 -12
  183. package/dist/lib/runtime/prompt.d.ts +8 -5
  184. package/dist/lib/runtime/prompt.js +436 -309
  185. package/dist/lib/runtime/promptRunner.d.ts +128 -0
  186. package/dist/lib/runtime/promptRunner.js +222 -0
  187. package/dist/lib/runtime/promptRunner.test.d.ts +1 -0
  188. package/dist/lib/runtime/promptRunner.test.js +398 -0
  189. package/dist/lib/runtime/result.js +36 -0
  190. package/dist/lib/runtime/resumableScope.d.ts +45 -0
  191. package/dist/lib/runtime/resumableScope.js +124 -0
  192. package/dist/lib/runtime/resumableScope.test.d.ts +1 -0
  193. package/dist/lib/runtime/resumableScope.test.js +239 -0
  194. package/dist/lib/runtime/rewind.d.ts +2 -0
  195. package/dist/lib/runtime/rewind.js +21 -3
  196. package/dist/lib/runtime/runBatch.d.ts +93 -0
  197. package/dist/lib/runtime/runBatch.js +443 -0
  198. package/dist/lib/runtime/runBatch.test.d.ts +1 -0
  199. package/dist/lib/runtime/runBatch.test.js +574 -0
  200. package/dist/lib/runtime/runner.d.ts +106 -21
  201. package/dist/lib/runtime/runner.js +361 -304
  202. package/dist/lib/runtime/runner.test.js +120 -5
  203. package/dist/lib/runtime/schema.d.ts +8 -0
  204. package/dist/lib/runtime/schema.js +11 -0
  205. package/dist/lib/runtime/state/bootstrapThreadStore.d.ts +38 -0
  206. package/dist/lib/runtime/state/bootstrapThreadStore.js +72 -0
  207. package/dist/lib/runtime/state/bootstrapThreadStore.test.d.ts +1 -0
  208. package/dist/lib/runtime/state/bootstrapThreadStore.test.js +34 -0
  209. package/dist/lib/runtime/state/context.d.ts +7 -10
  210. package/dist/lib/runtime/state/context.js +16 -36
  211. package/dist/lib/runtime/state/stateStack.d.ts +93 -0
  212. package/dist/lib/runtime/state/stateStack.js +219 -0
  213. package/dist/lib/runtime/state/stateStack.test.js +386 -0
  214. package/dist/lib/runtime/subprocess-bootstrap.js +8 -0
  215. package/dist/lib/runtime/types.d.ts +1 -9
  216. package/dist/lib/runtime/validateChain.d.ts +71 -0
  217. package/dist/lib/runtime/validateChain.js +138 -0
  218. package/dist/lib/runtime/validateChain.test.d.ts +1 -0
  219. package/dist/lib/runtime/validateChain.test.js +131 -0
  220. package/dist/lib/simplemachine/graph.js +1 -1
  221. package/dist/lib/simplemachine/util.d.ts +1 -1
  222. package/dist/lib/stdlib/abortable.d.ts +58 -0
  223. package/dist/lib/stdlib/abortable.js +175 -0
  224. package/dist/lib/stdlib/agency.d.ts +44 -0
  225. package/dist/lib/stdlib/agency.js +218 -12
  226. package/dist/lib/stdlib/assertContained.d.ts +24 -0
  227. package/dist/lib/stdlib/assertContained.js +110 -0
  228. package/dist/lib/stdlib/browserUse.d.ts +7 -0
  229. package/dist/lib/stdlib/browserUse.js +58 -27
  230. package/dist/lib/stdlib/builtins.d.ts +16 -2
  231. package/dist/lib/stdlib/builtins.js +75 -8
  232. package/dist/lib/stdlib/fs.d.ts +2 -2
  233. package/dist/lib/stdlib/fs.js +14 -26
  234. package/dist/lib/stdlib/http.d.ts +32 -1
  235. package/dist/lib/stdlib/http.js +105 -23
  236. package/dist/lib/stdlib/memory.d.ts +27 -13
  237. package/dist/lib/stdlib/memory.js +71 -13
  238. package/dist/lib/stdlib/oauth.d.ts +37 -0
  239. package/dist/lib/stdlib/oauth.js +113 -34
  240. package/dist/lib/stdlib/policy.d.ts +2 -1
  241. package/dist/lib/stdlib/policy.js +7 -2
  242. package/dist/lib/stdlib/resolvePath.d.ts +11 -0
  243. package/dist/lib/stdlib/resolvePath.js +13 -2
  244. package/dist/lib/stdlib/shell.d.ts +47 -16
  245. package/dist/lib/stdlib/shell.js +62 -58
  246. package/dist/lib/stdlib/skills.d.ts +9 -0
  247. package/dist/lib/stdlib/skills.js +16 -0
  248. package/dist/lib/stdlib/speech.d.ts +18 -3
  249. package/dist/lib/stdlib/speech.js +102 -22
  250. package/dist/lib/stdlib/system.d.ts +19 -5
  251. package/dist/lib/stdlib/system.js +51 -12
  252. package/dist/lib/stdlib/thread.d.ts +45 -0
  253. package/dist/lib/stdlib/thread.js +120 -0
  254. package/dist/lib/stdlib/ui.d.ts +7 -0
  255. package/dist/lib/stdlib/ui.js +45 -6
  256. package/dist/lib/stdlib/validators.d.ts +12 -0
  257. package/dist/lib/stdlib/validators.js +77 -0
  258. package/dist/lib/symbolTable.d.ts +24 -8
  259. package/dist/lib/symbolTable.js +43 -25
  260. package/dist/lib/symbolTable.test.js +53 -0
  261. package/dist/lib/templates/backends/agency/template.d.ts +1 -1
  262. package/dist/lib/templates/backends/agency/template.js +1 -1
  263. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +1 -1
  264. package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +1 -1
  265. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/system.d.ts +1 -1
  266. package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/system.js +4 -2
  267. package/dist/lib/templates/backends/typescriptGenerator/debugger.d.ts +1 -1
  268. package/dist/lib/templates/backends/typescriptGenerator/debugger.js +2 -2
  269. package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.d.ts +1 -1
  270. package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.js +10 -2
  271. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.d.ts +1 -1
  272. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.js +9 -1
  273. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -2
  274. package/dist/lib/templates/backends/typescriptGenerator/imports.js +6 -14
  275. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +1 -1
  276. package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +9 -9
  277. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +1 -1
  278. package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +9 -9
  279. package/dist/lib/templates/backends/typescriptGenerator/resultCheckpointSetup.d.ts +1 -1
  280. package/dist/lib/templates/backends/typescriptGenerator/resultCheckpointSetup.js +1 -1
  281. package/dist/lib/tui/styleParser.js +1 -0
  282. package/dist/lib/typeChecker/assignability.d.ts +46 -3
  283. package/dist/lib/typeChecker/assignability.js +313 -8
  284. package/dist/lib/typeChecker/builtins.js +83 -26
  285. package/dist/lib/typeChecker/callbackBodyInterrupts.test.d.ts +1 -0
  286. package/dist/lib/typeChecker/callbackBodyInterrupts.test.js +168 -0
  287. package/dist/lib/typeChecker/checker.js +25 -18
  288. package/dist/lib/typeChecker/docstringParamInterpolation.test.d.ts +1 -0
  289. package/dist/lib/typeChecker/docstringParamInterpolation.test.js +70 -0
  290. package/dist/lib/typeChecker/genericAliasDeclaration.test.d.ts +1 -0
  291. package/dist/lib/typeChecker/genericAliasDeclaration.test.js +71 -0
  292. package/dist/lib/typeChecker/genericValidation.test.d.ts +1 -0
  293. package/dist/lib/typeChecker/genericValidation.test.js +212 -0
  294. package/dist/lib/typeChecker/index.js +58 -4
  295. package/dist/lib/typeChecker/interruptAnalysis.d.ts +14 -0
  296. package/dist/lib/typeChecker/interruptAnalysis.js +74 -0
  297. package/dist/lib/typeChecker/jsGlobalsSig.test.js +0 -4
  298. package/dist/lib/typeChecker/jsonSchemaArgValidator.d.ts +60 -0
  299. package/dist/lib/typeChecker/jsonSchemaArgValidator.js +266 -0
  300. package/dist/lib/typeChecker/jsonSchemaArgValidator.test.d.ts +1 -0
  301. package/dist/lib/typeChecker/jsonSchemaArgValidator.test.js +179 -0
  302. package/dist/lib/typeChecker/mergeTags.d.ts +28 -0
  303. package/dist/lib/typeChecker/mergeTags.js +182 -0
  304. package/dist/lib/typeChecker/mergeTags.test.d.ts +1 -0
  305. package/dist/lib/typeChecker/mergeTags.test.js +144 -0
  306. package/dist/lib/typeChecker/namedArgStructure.test.d.ts +1 -0
  307. package/dist/lib/typeChecker/namedArgStructure.test.js +66 -0
  308. package/dist/lib/typeChecker/recordAssignability.test.d.ts +1 -0
  309. package/dist/lib/typeChecker/recordAssignability.test.js +72 -0
  310. package/dist/lib/typeChecker/recordSynth.test.d.ts +1 -0
  311. package/dist/lib/typeChecker/recordSynth.test.js +80 -0
  312. package/dist/lib/typeChecker/reservedNameDeclaration.test.js +15 -0
  313. package/dist/lib/typeChecker/resolveCall.d.ts +4 -5
  314. package/dist/lib/typeChecker/resolveCall.js +7 -3
  315. package/dist/lib/typeChecker/resolveType.test.d.ts +1 -0
  316. package/dist/lib/typeChecker/resolveType.test.js +478 -0
  317. package/dist/lib/typeChecker/resolveTypeTags.test.d.ts +1 -0
  318. package/dist/lib/typeChecker/resolveTypeTags.test.js +154 -0
  319. package/dist/lib/typeChecker/resolveVariable.d.ts +5 -15
  320. package/dist/lib/typeChecker/resolveVariable.js +3 -7
  321. package/dist/lib/typeChecker/scopes.js +53 -2
  322. package/dist/lib/typeChecker/shadowing.d.ts +0 -1
  323. package/dist/lib/typeChecker/shadowing.js +1 -5
  324. package/dist/lib/typeChecker/substitute.d.ts +25 -0
  325. package/dist/lib/typeChecker/substitute.js +33 -0
  326. package/dist/lib/typeChecker/substitute.test.d.ts +1 -0
  327. package/dist/lib/typeChecker/substitute.test.js +165 -0
  328. package/dist/lib/typeChecker/synthesizer.js +46 -18
  329. package/dist/lib/typeChecker/typeWalker.d.ts +14 -0
  330. package/dist/lib/typeChecker/typeWalker.js +62 -0
  331. package/dist/lib/typeChecker/typeWalker.test.d.ts +1 -0
  332. package/dist/lib/typeChecker/typeWalker.test.js +212 -0
  333. package/dist/lib/typeChecker/types.d.ts +7 -2
  334. package/dist/lib/typeChecker/undefinedFunctionDiagnostic.js +1 -4
  335. package/dist/lib/typeChecker/undefinedVariableDiagnostic.js +3 -4
  336. package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.js +33 -6
  337. package/dist/lib/typeChecker/utils.js +4 -2
  338. package/dist/lib/typeChecker/validate.d.ts +2 -2
  339. package/dist/lib/typeChecker/validate.js +123 -5
  340. package/dist/lib/typeChecker/valueParamSubstitution.d.ts +92 -0
  341. package/dist/lib/typeChecker/valueParamSubstitution.js +645 -0
  342. package/dist/lib/typeChecker/valueParamSubstitution.test.d.ts +1 -0
  343. package/dist/lib/typeChecker/valueParamSubstitution.test.js +214 -0
  344. package/dist/lib/types/dataStructures.d.ts +6 -0
  345. package/dist/lib/types/function.d.ts +2 -6
  346. package/dist/lib/types/graphNode.d.ts +3 -3
  347. package/dist/lib/types/literals.d.ts +1 -1
  348. package/dist/lib/types/newExpression.d.ts +14 -0
  349. package/dist/lib/types/newExpression.js +1 -0
  350. package/dist/lib/types/pattern.d.ts +8 -3
  351. package/dist/lib/types/tag.d.ts +2 -1
  352. package/dist/lib/types/typeHints.d.ts +108 -1
  353. package/dist/lib/types.d.ts +4 -4
  354. package/dist/lib/types.js +1 -1
  355. package/dist/lib/utils/docStringText.d.ts +22 -0
  356. package/dist/lib/utils/docStringText.js +47 -0
  357. package/dist/lib/utils/formatType.js +2 -0
  358. package/dist/lib/utils/node.js +19 -14
  359. package/dist/lib/utils/schemaParam.d.ts +34 -0
  360. package/dist/lib/utils/schemaParam.js +48 -0
  361. package/dist/lib/utils/schemaParam.test.d.ts +1 -0
  362. package/dist/lib/utils/schemaParam.test.js +69 -0
  363. package/dist/lib/utils.d.ts +13 -0
  364. package/dist/lib/utils.js +97 -0
  365. package/dist/lib/utils.test.d.ts +1 -0
  366. package/dist/lib/utils.test.js +101 -0
  367. package/dist/scripts/agency.js +1 -0
  368. package/package.json +1 -1
  369. package/stdlib/agency.agency +217 -3
  370. package/stdlib/agency.js +1864 -222
  371. package/stdlib/agent.js +147 -146
  372. package/stdlib/array.js +737 -784
  373. package/stdlib/browser.agency +2 -2
  374. package/stdlib/browser.js +92 -103
  375. package/stdlib/calendar.js +425 -436
  376. package/stdlib/clipboard.js +132 -143
  377. package/stdlib/date.js +580 -591
  378. package/stdlib/email.js +289 -300
  379. package/stdlib/fs.agency +12 -6
  380. package/stdlib/fs.js +525 -508
  381. package/stdlib/http.agency +61 -4
  382. package/stdlib/http.js +451 -98
  383. package/stdlib/imessage.js +84 -95
  384. package/stdlib/index.agency +66 -40
  385. package/stdlib/index.js +944 -1119
  386. package/stdlib/keyring.js +252 -263
  387. package/stdlib/math.js +167 -162
  388. package/stdlib/memory.agency +21 -13
  389. package/stdlib/memory.js +267 -216
  390. package/stdlib/oauth.agency +4 -1
  391. package/stdlib/oauth.js +270 -277
  392. package/stdlib/object.js +276 -307
  393. package/stdlib/path.js +273 -284
  394. package/stdlib/policy.agency +30 -6
  395. package/stdlib/policy.js +160 -141
  396. package/stdlib/schemas.agency +37 -0
  397. package/stdlib/schemas.js +202 -0
  398. package/stdlib/shell.agency +39 -22
  399. package/stdlib/shell.js +597 -518
  400. package/stdlib/skills.agency +18 -0
  401. package/stdlib/skills.js +276 -0
  402. package/stdlib/sms.js +90 -101
  403. package/stdlib/speech.agency +31 -9
  404. package/stdlib/speech.js +256 -223
  405. package/stdlib/strategy.js +336 -369
  406. package/stdlib/syntax.agency +20 -0
  407. package/stdlib/syntax.js +296 -0
  408. package/stdlib/system.agency +27 -4
  409. package/stdlib/system.js +512 -398
  410. package/stdlib/thread.agency +148 -0
  411. package/stdlib/thread.js +937 -0
  412. package/stdlib/types.agency +58 -0
  413. package/stdlib/types.js +180 -0
  414. package/stdlib/ui.agency +3 -1
  415. package/stdlib/ui.js +541 -558
  416. package/stdlib/validators.agency +150 -0
  417. package/stdlib/validators.js +1471 -0
  418. package/stdlib/weather.js +127 -130
  419. package/stdlib/wikipedia.js +124 -135
  420. package/dist/lib/codegenBuiltins/contextInjected.d.ts +0 -56
  421. package/dist/lib/codegenBuiltins/contextInjected.js +0 -78
  422. package/dist/lib/codegenBuiltins/contextInjected.test.js +0 -57
  423. package/dist/lib/runtime/classReviver.d.ts +0 -15
  424. package/dist/lib/runtime/classReviver.js +0 -32
  425. package/dist/lib/templates/backends/typescriptGenerator/classDefinition.d.ts +0 -19
  426. package/dist/lib/templates/backends/typescriptGenerator/classDefinition.js +0 -48
  427. package/dist/lib/templates/backends/typescriptGenerator/classMethod.d.ts +0 -14
  428. package/dist/lib/templates/backends/typescriptGenerator/classMethod.js +0 -37
  429. package/dist/lib/types/classDefinition.d.ts +0 -30
  430. package/dist/lib/types/classDefinition.js +0 -4
  431. /package/dist/lib/{codegenBuiltins/contextInjected.test.d.ts → backends/docstringInterpolationRuntime.test.d.ts} +0 -0
@@ -2,6 +2,7 @@ import { addTask, listTasks, markTaskDone } from "./subagents/task.agency"
2
2
  import { writeToPlan, readPlan } from "./subagents/plan.agency"
3
3
  import { writeCode, appendCode, readCode } from "./subagents/code.agency"
4
4
  import { syntaxHighlight } from "../../utils/agentUtils.js"
5
+ import { systemMessage } from "std::thread"
5
6
  // todo allow this
6
7
  // import { Plan } from "./subagents/plan.agency"
7
8
 
@@ -124,7 +125,7 @@ node plan(mode, existingCode, existingFilename: string | null) {
124
125
  """
125
126
  }
126
127
  thread {
127
- system("${systemPrompt}\n\n${planPrompt}${modeContext}")
128
+ systemMessage("${systemPrompt}\n\n${planPrompt}${modeContext}")
128
129
  userMsg = input("What would you like to accomplish today? ")
129
130
  nextAction: NextAction = {
130
131
  type: "start"
@@ -176,7 +177,7 @@ node design(plan, mode, existingCode, existingFilename: string | null) {
176
177
  """
177
178
  }
178
179
  thread {
179
- system(designPrompt)
180
+ systemMessage(designPrompt)
180
181
  userMsg = prompt
181
182
  nextAction: DesignAction = {
182
183
  type: "start"
@@ -1,4 +1,4 @@
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";
1
+ import { print, printJSON, parseJSON, input, sleep, round, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit, callback } 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";
@@ -22,11 +22,12 @@ import {
22
22
  respondToInterrupts as _respondToInterrupts,
23
23
  rewindFrom as _rewindFrom,
24
24
  RestoreSignal,
25
+ GuardExceededError,
25
26
  failure,
26
- readSkill as _readSkillRaw,
27
- readSkillTool as __readSkillTool,
28
- readSkillToolParams as __readSkillToolParams,
29
27
  AgencyFunction as __AgencyFunction,
28
+ __threads,
29
+ getRuntimeContext,
30
+ agencyStore,
30
31
  functionRefReviver as __functionRefReviver,
31
32
  DeterministicClient as __DeterministicClient
32
33
  } from "agency-lang/runtime";
@@ -60,15 +61,9 @@ const __globalCtx = new RuntimeContext({
60
61
  traceConfig: {
61
62
  program: "dist/lib/agents/judge.agency",
62
63
  traceDir: "traces"
63
- },
64
- memory: {
65
- dir: ".agency-memory"
66
64
  }
67
65
  });
68
66
  const graph = __globalCtx.graph;
69
- function readSkill({ filepath }) {
70
- return _readSkillRaw({ filepath, dirname: __dirname });
71
- }
72
67
  function approve(value) {
73
68
  return { type: "approve", value };
74
69
  }
@@ -78,8 +73,8 @@ function reject(value) {
78
73
  function propagate() {
79
74
  return { type: "propagate" };
80
75
  }
81
- const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata });
82
- const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata });
76
+ const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
77
+ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
83
78
  const __setDebugger = (dbg) => {
84
79
  __globalCtx.debuggerState = dbg;
85
80
  };
@@ -121,8 +116,6 @@ __registerTool(parseJSON);
121
116
  __registerTool(input);
122
117
  __registerTool(sleep);
123
118
  __registerTool(round);
124
- __registerTool(fetch);
125
- __registerTool(fetchJSON);
126
119
  __registerTool(read);
127
120
  __registerTool(write);
128
121
  __registerTool(readImage);
@@ -133,51 +126,50 @@ __registerTool(keys);
133
126
  __registerTool(values);
134
127
  __registerTool(entries);
135
128
  __registerTool(emit);
129
+ __registerTool(callback);
136
130
  async function __initializeGlobals(__ctx) {
137
131
  __ctx.globals.markInitialized("dist/lib/agents/judge.agency");
138
132
  }
139
- __toolRegistry["readSkill"] = __AgencyFunction.create({
140
- name: "readSkill",
141
- module: "dist/lib/agents/judge.agency",
142
- fn: readSkill,
143
- params: __readSkillToolParams.map((p) => ({ name: p, hasDefault: false, defaultValue: void 0, variadic: false })),
144
- toolDefinition: __readSkillTool
145
- }, __toolRegistry);
133
+ async function __registerTopLevelCallbacks(__ctx) {
134
+ __ctx.topLevelCallbacks = [];
135
+ }
146
136
  __functionRefReviver.registry = __toolRegistry;
147
137
  const JudgeResult = z.object({ "score": z.number().describe("a score from 0 to 100 where 100 means perfect match"), "reasoning": z.string().describe("brief explanation for the score") });
148
138
  graph.node("judge", async (__state) => {
149
139
  const __setupData = setupNode({
150
140
  state: __state
151
141
  });
152
- const __stateStack = __state.ctx.stateStack;
153
142
  const __stack = __setupData.stack;
154
143
  const __step = __setupData.step;
155
144
  const __self = __setupData.self;
156
- const __threads = __setupData.threads;
157
- const __ctx = __state.ctx;
158
- const statelogClient = __ctx.statelogClient;
159
- const __graph = __ctx.graph;
145
+ const __ctx = getRuntimeContext().ctx;
160
146
  let __forked;
161
147
  let __functionCompleted = false;
162
- await callHook({
163
- callbacks: __ctx.callbacks,
164
- name: "onNodeStart",
165
- data: {
166
- nodeName: "judge"
167
- }
168
- });
169
- const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/judge.agency", scopeName: "judge" });
148
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/judge.agency", scopeName: "judge", threads: __setupData.threads });
170
149
  if (!__state.isResume) {
171
150
  __stack.args["actualOutput"] = __state.data.actualOutput;
172
151
  __stack.args["expectedOutput"] = __state.data.expectedOutput;
173
152
  __stack.args["judgePrompt"] = __state.data.judgePrompt;
174
153
  }
175
154
  try {
176
- await runner.step(0, async (runner2) => {
177
- __self.__removedTools = __self.__removedTools || [];
178
- __stack.locals.result = await runPrompt({
179
- ctx: __ctx,
180
- prompt: `You are an evaluation judge. Score how well the actual output matches what was expected.
155
+ await agencyStore.run({
156
+ ...getRuntimeContext(),
157
+ ctx: __ctx,
158
+ stack: __ctx.stateStack,
159
+ threads: __setupData.threads
160
+ }, async () => {
161
+ await runner.hook(0, async () => {
162
+ await callHook({
163
+ name: "onNodeStart",
164
+ data: {
165
+ nodeName: "judge"
166
+ }
167
+ });
168
+ });
169
+ await runner.step(1, async (runner2) => {
170
+ __self.__removedTools = __self.__removedTools || [];
171
+ __stack.locals.result = await runPrompt({
172
+ prompt: `You are an evaluation judge. Score how well the actual output matches what was expected.
181
173
 
182
174
  Judge prompt (evaluation criteria): ${__stack.args.judgePrompt}
183
175
 
@@ -186,54 +178,58 @@ Expected output: ${__stack.args.expectedOutput}
186
178
  Actual output: ${__stack.args.actualOutput}
187
179
 
188
180
  Provide a score from 0 to 100 where 100 means perfect match and 0 means completely wrong. Also provide brief reasoning.`,
189
- messages: __threads.getOrCreateActive(),
190
- responseFormat: z.object({
191
- response: JudgeResult
192
- }),
193
- clientConfig: {},
194
- maxToolCallRounds: 10,
195
- stateStack: __stateStack,
196
- removedTools: __self.__removedTools,
197
- checkpointInfo: runner2.getCheckpointInfo()
181
+ messages: __threads().getOrCreateActive(),
182
+ responseFormat: z.object({
183
+ response: JudgeResult
184
+ }),
185
+ clientConfig: {},
186
+ maxToolCallRounds: 10,
187
+ removedTools: __self.__removedTools,
188
+ checkpointInfo: runner2.getCheckpointInfo()
189
+ });
190
+ if (hasInterrupts(__stack.locals.result)) {
191
+ await getRuntimeContext().ctx.pendingPromises.awaitAll();
192
+ runner2.halt({
193
+ messages: __threads(),
194
+ data: __stack.locals.result
195
+ });
196
+ return;
197
+ }
198
198
  });
199
- if (hasInterrupts(__stack.locals.result)) {
200
- await __ctx.pendingPromises.awaitAll();
199
+ await runner.step(2, async (runner2) => {
201
200
  runner2.halt({
202
- messages: __threads,
201
+ messages: __threads(),
203
202
  data: __stack.locals.result
204
203
  });
205
204
  return;
206
- }
207
- });
208
- await runner.step(1, async (runner2) => {
209
- runner2.halt({
210
- messages: __threads,
211
- data: __stack.locals.result
212
205
  });
213
- return;
214
206
  });
215
207
  if (runner.halted) return runner.haltResult;
216
- await callHook({
217
- callbacks: __ctx.callbacks,
218
- name: "onNodeEnd",
219
- data: {
220
- nodeName: "judge",
221
- data: void 0
222
- }
208
+ await runner.hook(3, async () => {
209
+ await callHook({
210
+ name: "onNodeEnd",
211
+ data: {
212
+ nodeName: "judge",
213
+ data: void 0
214
+ }
215
+ });
223
216
  });
224
217
  return {
225
- messages: __threads,
218
+ messages: __threads(),
226
219
  data: void 0
227
220
  };
228
221
  } catch (__error) {
229
222
  if (__error instanceof RestoreSignal) {
230
223
  throw __error;
231
224
  }
225
+ if (__error instanceof GuardExceededError) {
226
+ throw __error;
227
+ }
232
228
  console.error(`
233
229
  Agent crashed: ${__error.message}`);
234
230
  console.error(__error.stack);
235
231
  return {
236
- messages: __threads,
232
+ messages: __threads(),
237
233
  data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "judge" })
238
234
  };
239
235
  }
@@ -249,12 +245,14 @@ async function judge(actualOutput, expectedOutput, judgePrompt, { messages, call
249
245
  },
250
246
  messages,
251
247
  callbacks,
252
- initializeGlobals: __initializeGlobals
248
+ initializeGlobals: __initializeGlobals,
249
+ registerTopLevelCallbacks: __registerTopLevelCallbacks,
250
+ moduleDir: __dirname
253
251
  });
254
252
  }
255
253
  const __judgeNodeParams = ["actualOutput", "expectedOutput", "judgePrompt"];
256
254
  var stdin_default = graph;
257
- const __sourceMap = { "dist/lib/agents/judge.agency:judge": { "0": { "line": 6, "col": 2 }, "1": { "line": 16, "col": 2 } } };
255
+ const __sourceMap = { "dist/lib/agents/judge.agency:judge": { "1": { "line": 6, "col": 2 }, "2": { "line": 16, "col": 2 } } };
258
256
  export {
259
257
  __getCheckpoints,
260
258
  __judgeNodeParams,
@@ -270,7 +268,6 @@ export {
270
268
  isDebugger,
271
269
  isInterrupt,
272
270
  judge,
273
- readSkill,
274
271
  reject,
275
272
  respondToInterrupts,
276
273
  rewindFrom
@@ -1,13 +1,102 @@
1
1
  import { map } from "std::array"
2
- import { writePolicyFile } from "std::policy"
2
+ import {
3
+ writePolicyFile,
4
+ Policy,
5
+ InterruptKind,
6
+ InterruptDataKey,
7
+ InterruptDataVal,
8
+ } from "std::policy"
9
+ import { highlight } from "std::syntax"
3
10
  import { args } from "std::system"
11
+ import { systemMessage, userMessage, assistantMessage } from "std::thread"
4
12
 
5
- systemPrompt = read("./prompts/system.md")
13
+ callback("onToolCallStart") as data {
14
+ print("Calling ${data.toolName}...")
15
+ }
16
+
17
+ callback("onToolCallEnd") as data {
18
+ print("Finished calling ${data.toolName}.")
19
+ }
20
+
21
+ systemPrompt = read("system.md", "./prompts") with approve
22
+
23
+ type Question = {
24
+ type: "askQuestion";
25
+ question: string
26
+ }
27
+
28
+ type Done = {
29
+ type: "done"
30
+ }
31
+
32
+ type Action = Question | Done
33
+
34
+ type PolicyAction = "approve" | "reject" | "propagate"
6
35
 
7
- type NextStep =
8
- | { type: "showPolicy"; policy: object }
9
- | { type: "writePolicy"; policy: object }
10
- | { type: "askQuestion"; question: string }
36
+ let currentPolicy: Policy = {}
37
+
38
+ def addToPolicy(
39
+ interruptKind: InterruptKind,
40
+ matchArgName: InterruptDataKey,
41
+ matchArgValue: InterruptDataVal,
42
+ action: PolicyAction!,
43
+ ): Result<Policy> {
44
+ """
45
+ Add a rule to the current policy for the given interrupt kind, matching on the specified argument and value, with the specified action.
46
+ Use only "approve", "reject", or "propagate" as the action. DO NOT use "allow" or "deny".
47
+ Returns the current policy after adding the rule.
48
+ """
49
+ const match = {
50
+ [matchArgName]: matchArgValue
51
+ }
52
+ if (!currentPolicy[interruptKind]) {
53
+ currentPolicy[interruptKind] = []
54
+ }
55
+ currentPolicy[interruptKind].push({
56
+ match: match,
57
+ action: action
58
+ })
59
+
60
+ return success(currentPolicy)
61
+ }
62
+
63
+ def getPolicy(): Policy {
64
+ """
65
+ Get the current policy object.
66
+ """
67
+ return currentPolicy
68
+ }
69
+
70
+ def setPolicy(newPolicy: Policy): Policy {
71
+ """
72
+ Replace the current policy with a new policy object. Returns the new policy.
73
+
74
+ @param newPolicy - The new policy object to set as the current policy.
75
+ """
76
+ currentPolicy = newPolicy
77
+ return currentPolicy
78
+ }
79
+
80
+ def deleteFromPolicy(interruptKind: InterruptKind, index: number): boolean {
81
+ """
82
+ Delete the rule at the specified index for the given interrupt kind from the current policy.
83
+ Returns true if the rule was successfully deleted, or false if the index was out of bounds.
84
+ """
85
+ if (currentPolicy[interruptKind] && index < currentPolicy[interruptKind].length) {
86
+ currentPolicy[interruptKind].splice(index, 1)
87
+ return true
88
+ }
89
+ return false
90
+ }
91
+
92
+ def savePolicy(path: string) {
93
+ """
94
+ Validate and save the current policy to a JSON file.
95
+
96
+ @param path - The file path where the policy should be saved.
97
+ """
98
+ return writePolicyFile(path, currentPolicy)
99
+ }
11
100
 
12
101
  def get(array: any[], index: number) {
13
102
  if (index < array.length) {
@@ -16,70 +105,81 @@ def get(array: any[], index: number) {
16
105
  return failure("Index out of bounds: ${index} >= ${array.length}")
17
106
  }
18
107
 
108
+ def highlightJSON(obj: Record<string, any>): string {
109
+ return highlight(JSON.stringify(obj, null, 2), "json")
110
+ }
111
+
19
112
  node main() {
20
113
  const cliArgs = args()
21
114
  if (cliArgs.length < 2) {
22
115
  print("Usage: agency policy gen <file>")
23
- return end()
116
+ return
24
117
  }
25
- print(cliArgs)
26
118
 
27
119
  const interruptKinds = cliArgs[0] |> parseJSON
28
120
  const outputPath = cliArgs[1]
29
- const existingPolicy = get(cliArgs, 3) |> parseJSON
121
+ const existingPolicy = get(cliArgs, 2) |> parseJSON
30
122
 
31
- if (isFailure(interruptKinds)) {
32
- print("Failed to parse interrupt kinds: ${interruptKinds.error}")
33
- return null
123
+ if (interruptKinds is failure(error)) {
124
+ print("Failed to parse interrupt kinds: ${error}")
125
+ return
34
126
  }
35
127
 
36
- let contextMessage = "This agent can produce the following interrupts:\n" + map(interruptKinds, kind -> `- ${kind}\n`).join("")
128
+ let contextMessage = "This agent can produce the following interrupts:\n${map(interruptKinds.value, \kind -> "- ${kind}\n").join("")}"
129
+
130
+ if (existingPolicy is success(thePolicy)) {
131
+ currentPolicy = thePolicy
132
+ contextMessage = """
133
+ ${contextMessage}
134
+
135
+ Current policy:
136
+ ```json
137
+ ${highlightJSON(currentPolicy)}
138
+ ```
37
139
 
38
- if (existingPolicy != null) {
39
- contextMessage = contextMessage + """
40
- Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
41
- """
140
+ What would you like to change?
141
+ """
42
142
  } else {
43
- contextMessage = contextMessage + "\nWhat actions would you like to allow?"
143
+ contextMessage = """
144
+ ${contextMessage}
145
+
146
+ What actions would you like to allow?
147
+ """
44
148
  }
45
149
 
46
150
  print(contextMessage)
47
151
 
48
- let done = false
49
- let policy = {}
50
- let conversationHistory = contextMessage
51
- while (!done) {
52
- let userInput = input("> ")
53
- conversationHistory = conversationHistory + "\nUser: ${userInput}"
54
-
55
- thread {
56
- system(systemPrompt)
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
- )
62
- }
63
-
64
- if (step.type == "showPolicy") {
65
- policy = step.policy
66
- let policyStr = printJSON(policy)
67
- print("\nProposed policy:\n```json\n${policyStr}\n```\n")
68
- print("Does this look right? (say 'yes' to save, or describe changes)")
69
- conversationHistory = conversationHistory + "\nAssistant: Here is the proposed policy:\n${policyStr}\nDoes this look right?"
70
- } else if (step.type == "writePolicy") {
71
- policy = step.policy
72
- writePolicyFile(outputPath, policy)
73
- print("\nPolicy written to ${outputPath}")
74
- done = true
75
- } else if (step.type == "askQuestion") {
76
- print(step.question)
77
- conversationHistory = conversationHistory + "\nAssistant: ${step.question}"
78
- }
79
- }
80
- return end()
81
- }
152
+ let userInput = input("> ")
153
+ // didn't catch `policy` var is undefined??
154
+ // doesn't typecheck in string segments??
155
+ const prompt = """
156
+ Current policy: ${JSON.stringify(currentPolicy, null, 2)}
157
+
158
+ Decide the next step. If the user is describing what they want, build or update the policy and use addToPolicy, setPolicy, or deleteFromPolicy. Show the user the policy and get confirmation that it looks good. When you are done, return { type: "done" }. Otherwise, ask the user a question to clarify what they want, and return { type: "askQuestion", question: "..." }.
159
+ """
82
160
 
83
- node end() {
161
+ systemMessage(systemPrompt)
162
+ assistantMessage(contextMessage)
163
+ userMessage(userInput)
84
164
 
165
+ const tools = [addToPolicy, getPolicy, setPolicy, deleteFromPolicy]
166
+
167
+ let action: Action = llm(prompt, {
168
+ tools: tools
169
+ })
170
+ while (action.type != "done") {
171
+ print(action.question)
172
+ let userInput = input("> ")
173
+ action: Action = llm(userInput, {
174
+ tools: tools
175
+ })
176
+ }
177
+ print("Done. Final policy:")
178
+ printJSON(currentPolicy)
179
+ const result = savePolicy(outputPath)
180
+ if (result is failure(error)) {
181
+ print("Failed to save policy: ${error}")
182
+ return
183
+ }
184
+ print("Saved policy to ${outputPath}.")
85
185
  }
@@ -37,3 +37,10 @@ Each rule has:
37
37
  7. If the user wants changes, refine and show again
38
38
 
39
39
  Be concise. Don't over-explain the policy format unless the user asks. Focus on understanding what they want to allow or deny, then build the policy for them.
40
+
41
+
42
+ ## Tools you can use
43
+ - addToPolicy: adds a new rule to the policy for a given interrupt kind
44
+ - getPolicy: retrieves the current policy
45
+ - setPolicy: replaces the entire policy with a new JSON object
46
+ - deleteFromPolicy: deletes rules from the policy for a given interrupt kind
@@ -1,5 +1,6 @@
1
1
  import { exec } from "std::shell"
2
2
  import { args } from "std::system"
3
+ import { systemMessage } from "std::thread"
3
4
  systemPrompt = read("./prompts/system.md")
4
5
 
5
6
  type Severity = "critical" | "warning" | "suggestion"
@@ -38,7 +39,7 @@ node main() {
38
39
  }
39
40
  // Have the LLM review the code
40
41
  thread {
41
- system(systemPrompt)
42
+ systemMessage(systemPrompt)
42
43
  let typeErrorMessage = "The type checker found no errors."
43
44
  if (typeErrors != "") {
44
45
  typeErrorMessage = "The type checker reported the following errors:\n${typeErrors}"