agency-lang 0.1.0 → 0.1.2

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 (338) hide show
  1. package/README.md +35 -0
  2. package/dist/lib/agents/judge.js +270 -0
  3. package/dist/lib/agents/policy/agent.agency +77 -0
  4. package/dist/lib/agents/policy/prompts/system.md +39 -0
  5. package/dist/lib/agents/review/agent.js +770 -0
  6. package/dist/lib/backends/agencyGenerator.d.ts +6 -2
  7. package/dist/lib/backends/agencyGenerator.js +29 -13
  8. package/dist/lib/backends/typescriptBuilder.js +16 -2
  9. package/dist/lib/cli/commands.js +4 -9
  10. package/dist/lib/cli/coverage.d.ts +6 -0
  11. package/dist/lib/cli/coverage.js +301 -0
  12. package/dist/lib/cli/debug.js +1 -1
  13. package/dist/lib/cli/policy.d.ts +5 -0
  14. package/dist/lib/cli/policy.js +51 -0
  15. package/dist/lib/cli/schedule/backends/launchd.js +2 -0
  16. package/dist/lib/cli/schedule/test.d.ts +14 -0
  17. package/dist/lib/cli/schedule/test.js +29 -0
  18. package/dist/lib/cli/serve.d.ts +18 -0
  19. package/dist/lib/cli/serve.js +341 -0
  20. package/dist/lib/cli/test.js +244 -39
  21. package/dist/lib/cli/util.d.ts +12 -13
  22. package/dist/lib/cli/util.js +36 -50
  23. package/dist/lib/compilationUnit.d.ts +3 -1
  24. package/dist/lib/compilationUnit.js +24 -0
  25. package/dist/lib/compiler/compile.d.ts +24 -0
  26. package/dist/lib/compiler/compile.js +140 -0
  27. package/dist/lib/compiler/compile.test.d.ts +1 -0
  28. package/dist/lib/compiler/compile.test.js +121 -0
  29. package/dist/lib/compiler/reExports.test.d.ts +1 -0
  30. package/dist/lib/compiler/reExports.test.js +87 -0
  31. package/dist/lib/config.d.ts +18 -9
  32. package/dist/lib/config.js +2 -1
  33. package/dist/lib/debugger/overlays.d.ts +1 -1
  34. package/dist/lib/debugger/overlays.js +1 -1
  35. package/dist/lib/debugger/testSession.d.ts +1 -1
  36. package/dist/lib/debugger/testSession.js +1 -1
  37. package/dist/lib/debugger/ui.d.ts +1 -1
  38. package/dist/lib/debugger/ui.js +2 -2
  39. package/dist/lib/formatter.test.js +13 -0
  40. package/dist/lib/logger.d.ts +8 -0
  41. package/dist/lib/logger.js +21 -0
  42. package/dist/lib/logger.test.d.ts +1 -0
  43. package/dist/lib/logger.test.js +44 -0
  44. package/dist/lib/lsp/completion.js +1 -1
  45. package/dist/lib/lsp/diagnostics.js +4 -2
  46. package/dist/lib/lsp/hover.js +1 -1
  47. package/dist/lib/lsp/hover.test.js +60 -0
  48. package/dist/lib/lsp/inlayHint.js +1 -1
  49. package/dist/lib/lsp/semantics.d.ts +3 -2
  50. package/dist/lib/lsp/semantics.js +48 -6
  51. package/dist/lib/lsp/signatureHelp.js +1 -1
  52. package/dist/lib/parser.js +2 -2
  53. package/dist/lib/parser.test.js +36 -0
  54. package/dist/lib/parsers/assignment.test.js +9 -9
  55. package/dist/lib/parsers/exportConst.test.d.ts +1 -0
  56. package/dist/lib/parsers/exportConst.test.js +41 -0
  57. package/dist/lib/parsers/exportFromStatement.test.d.ts +1 -0
  58. package/dist/lib/parsers/exportFromStatement.test.js +91 -0
  59. package/dist/lib/parsers/exportNode.test.d.ts +1 -0
  60. package/dist/lib/parsers/exportNode.test.js +37 -0
  61. package/dist/lib/parsers/parsers.d.ts +3 -1
  62. package/dist/lib/parsers/parsers.js +132 -24
  63. package/dist/lib/parsers/typeHints.test.js +7 -0
  64. package/dist/lib/parsers/unitLiteral.test.js +37 -0
  65. package/dist/lib/preprocessors/importResolver.js +4 -0
  66. package/dist/lib/preprocessors/importResolver.test.js +26 -0
  67. package/dist/lib/preprocessors/resolveReExports.d.ts +10 -0
  68. package/dist/lib/preprocessors/resolveReExports.js +191 -0
  69. package/dist/lib/preprocessors/resolveReExports.test.d.ts +1 -0
  70. package/dist/lib/preprocessors/resolveReExports.test.js +371 -0
  71. package/dist/lib/preprocessors/typescriptPreprocessor.js +15 -1
  72. package/dist/lib/runtime/agencyFunction.d.ts +4 -0
  73. package/dist/lib/runtime/agencyFunction.js +8 -0
  74. package/dist/lib/runtime/coverageCollector.d.ts +16 -0
  75. package/dist/lib/runtime/coverageCollector.js +37 -0
  76. package/dist/lib/runtime/coverageCollector.test.d.ts +1 -0
  77. package/dist/lib/runtime/coverageCollector.test.js +63 -0
  78. package/dist/lib/runtime/deterministicClient.d.ts +19 -0
  79. package/dist/lib/runtime/deterministicClient.js +82 -0
  80. package/dist/lib/runtime/deterministicClient.test.d.ts +1 -0
  81. package/dist/lib/runtime/deterministicClient.test.js +74 -0
  82. package/dist/lib/runtime/hooks.d.ts +3 -3
  83. package/dist/lib/runtime/index.d.ts +4 -0
  84. package/dist/lib/runtime/index.js +3 -0
  85. package/dist/lib/runtime/interrupts.js +11 -4
  86. package/dist/lib/runtime/ipc.d.ts +79 -0
  87. package/dist/lib/runtime/ipc.js +368 -0
  88. package/dist/lib/runtime/ipc.test.d.ts +1 -0
  89. package/dist/lib/runtime/ipc.test.js +54 -0
  90. package/dist/lib/runtime/llmClient.d.ts +1 -2
  91. package/dist/lib/runtime/policy.d.ts +2 -2
  92. package/dist/lib/runtime/prompt.d.ts +4 -4
  93. package/dist/lib/runtime/prompt.js +8 -8
  94. package/dist/lib/runtime/runner.d.ts +2 -2
  95. package/dist/lib/runtime/runner.js +9 -1
  96. package/dist/lib/runtime/state/context.d.ts +17 -15
  97. package/dist/lib/runtime/state/context.js +40 -7
  98. package/dist/lib/runtime/subprocess-bootstrap.d.ts +12 -0
  99. package/dist/lib/runtime/subprocess-bootstrap.js +126 -0
  100. package/dist/lib/serve/constants.d.ts +1 -0
  101. package/dist/lib/serve/constants.js +1 -0
  102. package/dist/lib/serve/discovery.d.ts +11 -0
  103. package/dist/lib/serve/discovery.js +37 -0
  104. package/dist/lib/serve/discovery.test.d.ts +1 -0
  105. package/dist/lib/serve/discovery.test.js +138 -0
  106. package/dist/lib/serve/http/adapter.d.ts +28 -0
  107. package/dist/lib/serve/http/adapter.js +140 -0
  108. package/dist/lib/serve/http/adapter.test.d.ts +1 -0
  109. package/dist/lib/serve/http/adapter.test.js +281 -0
  110. package/dist/lib/serve/http/auth.d.ts +1 -0
  111. package/dist/lib/serve/http/auth.js +25 -0
  112. package/dist/lib/serve/http/auth.test.d.ts +1 -0
  113. package/dist/lib/serve/http/auth.test.js +22 -0
  114. package/dist/lib/serve/http/security.d.ts +57 -0
  115. package/dist/lib/serve/http/security.js +116 -0
  116. package/dist/lib/serve/mcp/adapter.d.ts +27 -0
  117. package/dist/lib/serve/mcp/adapter.js +242 -0
  118. package/dist/lib/serve/mcp/adapter.test.d.ts +1 -0
  119. package/dist/lib/serve/mcp/adapter.test.js +384 -0
  120. package/dist/lib/serve/mcp/httpTransport.d.ts +37 -0
  121. package/dist/lib/serve/mcp/httpTransport.js +87 -0
  122. package/dist/lib/serve/mcp/httpTransport.test.d.ts +1 -0
  123. package/dist/lib/serve/mcp/httpTransport.test.js +274 -0
  124. package/dist/lib/serve/mcp/interruptLoop.d.ts +6 -0
  125. package/dist/lib/serve/mcp/interruptLoop.js +17 -0
  126. package/dist/lib/serve/mcp/interruptLoop.test.d.ts +1 -0
  127. package/dist/lib/serve/mcp/interruptLoop.test.js +125 -0
  128. package/dist/lib/serve/policyStore.d.ts +14 -0
  129. package/dist/lib/serve/policyStore.js +88 -0
  130. package/dist/lib/serve/policyStore.test.d.ts +1 -0
  131. package/dist/lib/serve/policyStore.test.js +129 -0
  132. package/dist/lib/serve/types.d.ts +19 -0
  133. package/dist/lib/serve/types.js +1 -0
  134. package/dist/lib/serve/util.d.ts +6 -0
  135. package/dist/lib/serve/util.js +36 -0
  136. package/dist/lib/stdlib/agency.d.ts +8 -0
  137. package/dist/lib/stdlib/agency.js +48 -0
  138. package/dist/lib/stdlib/allowBlockList.d.ts +11 -0
  139. package/dist/lib/stdlib/browserUse.d.ts +15 -0
  140. package/dist/lib/stdlib/builtins.d.ts +18 -0
  141. package/dist/lib/stdlib/calendar.d.ts +44 -0
  142. package/dist/lib/stdlib/clipboard.d.ts +2 -0
  143. package/dist/lib/stdlib/date.d.ts +15 -0
  144. package/dist/lib/stdlib/email.d.ts +34 -0
  145. package/dist/lib/stdlib/fs.d.ts +27 -0
  146. package/dist/lib/stdlib/http.d.ts +5 -0
  147. package/dist/lib/stdlib/imessage.d.ts +8 -0
  148. package/dist/lib/stdlib/keyring.d.ts +20 -0
  149. package/dist/lib/stdlib/messaging.js +1 -0
  150. package/dist/lib/stdlib/oauth.d.ts +17 -0
  151. package/{stdlib/lib → dist/lib/stdlib}/oauth.js +1 -2
  152. package/dist/lib/stdlib/oauthEncryption.d.ts +15 -0
  153. package/dist/lib/stdlib/path.d.ts +7 -0
  154. package/dist/lib/stdlib/policy.d.ts +2 -0
  155. package/dist/lib/stdlib/policy.js +9 -0
  156. package/dist/lib/stdlib/resolvePath.d.ts +5 -0
  157. package/dist/lib/stdlib/shell.d.ts +40 -0
  158. package/dist/lib/stdlib/sms.d.ts +12 -0
  159. package/dist/lib/stdlib/speech.d.ts +3 -0
  160. package/{stdlib/lib → dist/lib/stdlib}/speech.js +60 -1
  161. package/dist/lib/stdlib/syntax.d.ts +1 -0
  162. package/dist/lib/stdlib/system.d.ts +11 -0
  163. package/{stdlib/lib → dist/lib/stdlib}/system.js +3 -0
  164. package/dist/lib/stdlib/ui.d.ts +12 -0
  165. package/{stdlib/lib → dist/lib/stdlib}/ui.js +1 -1
  166. package/dist/lib/stdlib/utils.d.ts +21 -0
  167. package/dist/lib/stdlib/weather.d.ts +23 -0
  168. package/dist/lib/stdlib/wikipedia.d.ts +16 -0
  169. package/dist/lib/symbolTable.d.ts +29 -1
  170. package/dist/lib/symbolTable.js +185 -2
  171. package/dist/lib/symbolTable.test.js +396 -1
  172. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
  173. package/dist/lib/templates/backends/typescriptGenerator/imports.js +18 -4
  174. package/dist/lib/templates/cli/coverageReport.d.ts +10 -0
  175. package/dist/lib/templates/cli/coverageReport.js +43 -0
  176. package/dist/lib/templates/cli/schedule/plist.d.ts +3 -1
  177. package/dist/lib/templates/cli/schedule/plist.js +7 -0
  178. package/dist/lib/templates/cli/standaloneHttp.d.ts +15 -0
  179. package/dist/lib/templates/cli/standaloneHttp.js +48 -0
  180. package/dist/lib/templates/cli/standaloneMcp.d.ts +14 -0
  181. package/dist/lib/templates/cli/standaloneMcp.js +44 -0
  182. package/dist/lib/templates/cli/standaloneMcpHttp.d.ts +20 -0
  183. package/dist/lib/templates/cli/standaloneMcpHttp.js +68 -0
  184. package/dist/lib/tui/builders.d.ts +7 -0
  185. package/dist/lib/tui/builders.js +58 -0
  186. package/dist/lib/tui/colors.d.ts +3 -0
  187. package/dist/lib/tui/colors.js +24 -0
  188. package/dist/lib/tui/elements.d.ts +61 -0
  189. package/dist/lib/tui/elements.js +1 -0
  190. package/dist/lib/tui/frame.d.ts +27 -0
  191. package/dist/lib/tui/frame.js +42 -0
  192. package/dist/lib/tui/index.d.ts +18 -0
  193. package/dist/lib/tui/index.js +18 -0
  194. package/dist/lib/tui/input/scripted.d.ts +12 -0
  195. package/dist/lib/tui/input/scripted.js +46 -0
  196. package/dist/lib/tui/input/terminal.d.ts +14 -0
  197. package/dist/lib/tui/input/terminal.js +131 -0
  198. package/dist/lib/tui/input/types.d.ts +10 -0
  199. package/dist/lib/tui/input/types.js +1 -0
  200. package/dist/lib/tui/layout.d.ts +6 -0
  201. package/dist/lib/tui/layout.js +191 -0
  202. package/dist/lib/tui/output/recorder.d.ts +14 -0
  203. package/dist/lib/tui/output/recorder.js +64 -0
  204. package/dist/lib/tui/output/terminal.d.ts +16 -0
  205. package/dist/lib/tui/output/terminal.js +63 -0
  206. package/dist/lib/tui/output/types.d.ts +5 -0
  207. package/dist/lib/tui/output/types.js +1 -0
  208. package/dist/lib/tui/render/ansi.d.ts +2 -0
  209. package/dist/lib/tui/render/ansi.js +43 -0
  210. package/dist/lib/tui/render/flatten.d.ts +9 -0
  211. package/dist/lib/tui/render/flatten.js +32 -0
  212. package/dist/lib/tui/render/html.d.ts +2 -0
  213. package/dist/lib/tui/render/html.js +45 -0
  214. package/dist/lib/tui/render/plaintext.d.ts +2 -0
  215. package/dist/lib/tui/render/plaintext.js +7 -0
  216. package/dist/lib/tui/render/renderer.d.ts +3 -0
  217. package/dist/lib/tui/render/renderer.js +189 -0
  218. package/dist/lib/tui/screen.d.ts +24 -0
  219. package/dist/lib/tui/screen.js +34 -0
  220. package/dist/lib/tui/styleParser.d.ts +8 -0
  221. package/dist/lib/tui/styleParser.js +86 -0
  222. package/dist/lib/tui/utils.d.ts +15 -0
  223. package/dist/lib/tui/utils.js +18 -0
  224. package/dist/lib/typeChecker/assignability.js +30 -0
  225. package/dist/lib/typeChecker/assignability.test.d.ts +1 -0
  226. package/dist/lib/typeChecker/assignability.test.js +73 -0
  227. package/dist/lib/typeChecker/checker.d.ts +2 -0
  228. package/dist/lib/typeChecker/checker.js +12 -3
  229. package/dist/lib/typeChecker/dimensionMismatch.test.js +26 -0
  230. package/dist/lib/typeChecker/index.d.ts +1 -0
  231. package/dist/lib/typeChecker/index.js +15 -3
  232. package/dist/lib/typeChecker/interruptAnalysis.d.ts +8 -0
  233. package/dist/lib/typeChecker/interruptAnalysis.js +139 -0
  234. package/dist/lib/typeChecker/interruptAnalysis.test.d.ts +1 -0
  235. package/dist/lib/typeChecker/interruptAnalysis.test.js +169 -0
  236. package/dist/lib/typeChecker/interruptWarnings.test.d.ts +1 -0
  237. package/dist/lib/typeChecker/interruptWarnings.test.js +238 -0
  238. package/dist/lib/typeChecker/scopes.js +7 -1
  239. package/dist/lib/typeChecker/synthesizer.js +62 -31
  240. package/dist/lib/typeChecker/typeWalker.js +6 -0
  241. package/dist/lib/typeChecker/types.d.ts +3 -0
  242. package/dist/lib/typeChecker/utils.js +1 -1
  243. package/dist/lib/typeChecker.test.js +55 -2
  244. package/dist/lib/types/exportFromStatement.d.ts +21 -0
  245. package/dist/lib/types/exportFromStatement.js +4 -0
  246. package/dist/lib/types/graphNode.d.ts +1 -2
  247. package/dist/lib/types/importStatement.d.ts +7 -0
  248. package/dist/lib/types/literals.d.ts +8 -1
  249. package/dist/lib/types/typeHints.d.ts +9 -1
  250. package/dist/lib/types.d.ts +4 -1
  251. package/dist/lib/types.js +1 -0
  252. package/dist/lib/utils/formatType.d.ts +13 -0
  253. package/dist/lib/utils/formatType.js +56 -0
  254. package/dist/lib/utils/termcolors.d.ts +12 -0
  255. package/dist/lib/utils/termcolors.js +28 -0
  256. package/dist/lib/zod.d.ts +2 -0
  257. package/dist/lib/zod.js +6 -0
  258. package/dist/scripts/agency.js +129 -0
  259. package/package.json +41 -31
  260. package/stdlib/agency.agency +88 -0
  261. package/stdlib/agency.js +742 -0
  262. package/stdlib/agent.js +24 -5
  263. package/stdlib/array.js +54 -15
  264. package/stdlib/browser.agency +1 -1
  265. package/stdlib/browser.js +19 -4
  266. package/stdlib/calendar.agency +1 -1
  267. package/stdlib/calendar.js +34 -9
  268. package/stdlib/clipboard.agency +1 -1
  269. package/stdlib/clipboard.js +22 -5
  270. package/stdlib/date.agency +1 -1
  271. package/stdlib/date.js +61 -18
  272. package/stdlib/email.agency +1 -1
  273. package/stdlib/email.js +25 -6
  274. package/stdlib/fs.agency +1 -1
  275. package/stdlib/fs.js +37 -10
  276. package/stdlib/http.agency +1 -1
  277. package/stdlib/http.js +19 -4
  278. package/stdlib/imessage.agency +1 -1
  279. package/stdlib/imessage.js +19 -4
  280. package/stdlib/index.agency +1 -1
  281. package/stdlib/index.js +67 -20
  282. package/stdlib/keyring.agency +1 -1
  283. package/stdlib/keyring.js +28 -7
  284. package/stdlib/math.agency +4 -4
  285. package/stdlib/math.js +27 -6
  286. package/stdlib/oauth.agency +1 -1
  287. package/stdlib/oauth.js +28 -7
  288. package/stdlib/object.js +30 -7
  289. package/stdlib/path.agency +1 -1
  290. package/stdlib/path.js +37 -10
  291. package/stdlib/policy.agency +8 -1
  292. package/stdlib/policy.js +145 -6
  293. package/stdlib/shell.agency +64 -19
  294. package/stdlib/shell.js +43 -18
  295. package/stdlib/sms.agency +1 -1
  296. package/stdlib/sms.js +19 -4
  297. package/stdlib/speech.agency +19 -1
  298. package/stdlib/speech.js +177 -5
  299. package/stdlib/strategy.js +30 -7
  300. package/stdlib/system.agency +12 -1
  301. package/stdlib/system.js +175 -9
  302. package/stdlib/ui.agency +1 -1
  303. package/stdlib/ui.js +55 -16
  304. package/stdlib/weather.agency +1 -1
  305. package/stdlib/weather.js +25 -6
  306. package/stdlib/wikipedia.agency +1 -1
  307. package/stdlib/wikipedia.js +25 -6
  308. package/dist/lib/agents/agency-agent/run.js +0 -113
  309. package/dist/lib/agents/agency-agent/subagents/code.js +0 -628
  310. package/dist/lib/agents/agency-agent/subagents/plan.js +0 -445
  311. package/dist/lib/agents/agency-agent/subagents/task.js +0 -557
  312. package/scripts/hooks/postinstall.js +0 -13
  313. package/stdlib/_builtins.js +0 -134
  314. package/stdlib/_math.js +0 -9
  315. package/stdlib/lib/policy.js +0 -1
  316. package/stdlib/lib/process.js +0 -29
  317. package/stdlib/lib/test.js +0 -3
  318. /package/{stdlib/lib → dist/lib/stdlib}/allowBlockList.js +0 -0
  319. /package/{stdlib/lib → dist/lib/stdlib}/browserUse.js +0 -0
  320. /package/{stdlib/lib → dist/lib/stdlib}/builtins.js +0 -0
  321. /package/{stdlib/lib → dist/lib/stdlib}/calendar.js +0 -0
  322. /package/{stdlib/lib → dist/lib/stdlib}/clipboard.js +0 -0
  323. /package/{stdlib/lib → dist/lib/stdlib}/date.js +0 -0
  324. /package/{stdlib/lib → dist/lib/stdlib}/email.js +0 -0
  325. /package/{stdlib/lib → dist/lib/stdlib}/fs.js +0 -0
  326. /package/{stdlib/lib → dist/lib/stdlib}/http.js +0 -0
  327. /package/{stdlib/lib → dist/lib/stdlib}/imessage.js +0 -0
  328. /package/{stdlib/lib → dist/lib/stdlib}/keyring.js +0 -0
  329. /package/{stdlib/lib/messaging.js → dist/lib/stdlib/messaging.d.ts} +0 -0
  330. /package/{stdlib/lib → dist/lib/stdlib}/oauthEncryption.js +0 -0
  331. /package/{stdlib/lib → dist/lib/stdlib}/path.js +0 -0
  332. /package/{stdlib/lib → dist/lib/stdlib}/resolvePath.js +0 -0
  333. /package/{stdlib/lib → dist/lib/stdlib}/shell.js +0 -0
  334. /package/{stdlib/lib → dist/lib/stdlib}/sms.js +0 -0
  335. /package/{stdlib/lib → dist/lib/stdlib}/syntax.js +0 -0
  336. /package/{stdlib/lib → dist/lib/stdlib}/utils.js +0 -0
  337. /package/{stdlib/lib → dist/lib/stdlib}/weather.js +0 -0
  338. /package/{stdlib/lib → dist/lib/stdlib}/wikipedia.js +0 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Getting Started
2
+
3
+ Agency is a language for building agents that compiles to TypeScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install agency-lang zod
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ Create a file called `hello.agency`:
14
+
15
+ ```ts
16
+ node main() {
17
+ const greeting = llm("Say hello to the world!");
18
+ print(greeting);
19
+ }
20
+ ```
21
+
22
+ Compile and run it:
23
+
24
+ ```bash
25
+ pnpm run agency hello.agency
26
+ ```
27
+
28
+ Now read [the docs](https://agency-lang.com) to learn more about the language and how to use it!
29
+
30
+ ## Attributions
31
+
32
+ Weather data in the standard library (`std::weather`) is provided by [Open-Meteo](https://open-meteo.com/). Data is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The free API is for non-commercial use only; commercial use requires a [paid subscription](https://open-meteo.com/en/pricing).
33
+
34
+ ## License
35
+ [FSL](https://fsl.software).
@@ -0,0 +1,270 @@
1
+ import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
2
+ import { fileURLToPath } from "url";
3
+ import __process from "process";
4
+ import { z } from "agency-lang/zod";
5
+ import { nanoid } from "agency-lang";
6
+ import path from "path";
7
+ import {
8
+ RuntimeContext,
9
+ Runner,
10
+ setupNode,
11
+ runNode,
12
+ runPrompt,
13
+ callHook,
14
+ checkpoint as __checkpoint_impl,
15
+ getCheckpoint as __getCheckpoint_impl,
16
+ restore as __restore_impl,
17
+ _run as __runtime_run_impl,
18
+ interrupt,
19
+ isInterrupt,
20
+ hasInterrupts,
21
+ isDebugger,
22
+ respondToInterrupts as _respondToInterrupts,
23
+ rewindFrom as _rewindFrom,
24
+ RestoreSignal,
25
+ failure,
26
+ readSkill as _readSkillRaw,
27
+ readSkillTool as __readSkillTool,
28
+ readSkillToolParams as __readSkillToolParams,
29
+ AgencyFunction as __AgencyFunction,
30
+ functionRefReviver as __functionRefReviver,
31
+ DeterministicClient as __DeterministicClient
32
+ } from "agency-lang/runtime";
33
+ const __filename = fileURLToPath(import.meta.url);
34
+ const __dirname = path.dirname(__filename);
35
+ const __cwd = __process.cwd();
36
+ const getDirname = () => __dirname;
37
+ const __globalCtx = new RuntimeContext({
38
+ statelogConfig: {
39
+ host: "https://statelog.adit.io",
40
+ apiKey: __process.env["STATELOG_API_KEY"] || "",
41
+ projectId: "agency-lang",
42
+ debugMode: false
43
+ },
44
+ smoltalkDefaults: {
45
+ openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
46
+ googleApiKey: __process.env["GEMINI_API_KEY"] || "",
47
+ model: "gpt-4o-mini",
48
+ logLevel: "warn",
49
+ statelog: {
50
+ host: "https://statelog.adit.io",
51
+ projectId: "smoltalk",
52
+ apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
53
+ traceId: nanoid()
54
+ }
55
+ },
56
+ dirname: __dirname,
57
+ traceConfig: {
58
+ program: "dist/lib/agents/judge.agency",
59
+ traceDir: "traces"
60
+ }
61
+ });
62
+ const graph = __globalCtx.graph;
63
+ function readSkill({ filepath }) {
64
+ return _readSkillRaw({ filepath, dirname: __dirname });
65
+ }
66
+ function approve(value) {
67
+ return { type: "approve", value };
68
+ }
69
+ function reject(value) {
70
+ return { type: "reject", value };
71
+ }
72
+ function propagate() {
73
+ return { type: "propagate" };
74
+ }
75
+ const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata });
76
+ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata });
77
+ const __setDebugger = (dbg) => {
78
+ __globalCtx.debuggerState = dbg;
79
+ };
80
+ const __setTraceWriter = (tw) => {
81
+ __globalCtx.traceWriter = tw;
82
+ };
83
+ const __setLLMClient = (client) => {
84
+ __globalCtx.setLLMClient(client);
85
+ };
86
+ const __getCheckpoints = () => __globalCtx.checkpoints;
87
+ if (__process.env.AGENCY_LLM_MOCKS) {
88
+ __globalCtx.setLLMClient(
89
+ new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
90
+ );
91
+ }
92
+ const __toolRegistry = {};
93
+ function __registerTool(value, name) {
94
+ if (__AgencyFunction.isAgencyFunction(value)) {
95
+ __toolRegistry[name ?? value.name] = value;
96
+ }
97
+ }
98
+ const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
99
+ const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
100
+ const restore = __AgencyFunction.create({ name: "restore", module: "__runtime", fn: __restore_impl, params: [{ name: "checkpointIdOrCheckpoint", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "options", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
101
+ const _run = __AgencyFunction.create({ name: "_run", module: "__runtime", fn: __runtime_run_impl, params: [{ name: "compiled", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "node", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "args", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "wallClock", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "memory", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "ipcPayload", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "stdout", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
102
+ function setLLMClient(client) {
103
+ __globalCtx.setLLMClient(client);
104
+ }
105
+ function registerTools(tools) {
106
+ for (const tool of tools) {
107
+ if (__AgencyFunction.isAgencyFunction(tool)) {
108
+ __toolRegistry[tool.name] = tool;
109
+ }
110
+ }
111
+ }
112
+ __registerTool(print);
113
+ __registerTool(printJSON);
114
+ __registerTool(input);
115
+ __registerTool(sleep);
116
+ __registerTool(round);
117
+ __registerTool(fetch);
118
+ __registerTool(fetchJSON);
119
+ __registerTool(read);
120
+ __registerTool(write);
121
+ __registerTool(readImage);
122
+ __registerTool(notify);
123
+ __registerTool(range);
124
+ __registerTool(mostCommon);
125
+ __registerTool(keys);
126
+ __registerTool(values);
127
+ __registerTool(entries);
128
+ __registerTool(emit);
129
+ async function __initializeGlobals(__ctx) {
130
+ __ctx.globals.markInitialized("dist/lib/agents/judge.agency");
131
+ }
132
+ __toolRegistry["readSkill"] = __AgencyFunction.create({
133
+ name: "readSkill",
134
+ module: "dist/lib/agents/judge.agency",
135
+ fn: readSkill,
136
+ params: __readSkillToolParams.map((p) => ({ name: p, hasDefault: false, defaultValue: void 0, variadic: false })),
137
+ toolDefinition: __readSkillTool
138
+ }, __toolRegistry);
139
+ __functionRefReviver.registry = __toolRegistry;
140
+ 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") });
141
+ graph.node("judge", async (__state) => {
142
+ const __setupData = setupNode({
143
+ state: __state
144
+ });
145
+ const __stateStack = __state.ctx.stateStack;
146
+ const __stack = __setupData.stack;
147
+ const __step = __setupData.step;
148
+ const __self = __setupData.self;
149
+ const __threads = __setupData.threads;
150
+ const __ctx = __state.ctx;
151
+ const statelogClient = __ctx.statelogClient;
152
+ const __graph = __ctx.graph;
153
+ let __forked;
154
+ let __functionCompleted = false;
155
+ await callHook({
156
+ callbacks: __ctx.callbacks,
157
+ name: "onNodeStart",
158
+ data: {
159
+ nodeName: "judge"
160
+ }
161
+ });
162
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/judge.agency", scopeName: "judge" });
163
+ if (!__state.isResume) {
164
+ __stack.args["actualOutput"] = __state.data.actualOutput;
165
+ __stack.args["expectedOutput"] = __state.data.expectedOutput;
166
+ __stack.args["judgePrompt"] = __state.data.judgePrompt;
167
+ }
168
+ try {
169
+ await runner.step(0, async (runner2) => {
170
+ __self.__removedTools = __self.__removedTools || [];
171
+ __stack.locals.result = await runPrompt({
172
+ ctx: __ctx,
173
+ prompt: `You are an evaluation judge. Score how well the actual output matches what was expected.
174
+
175
+ Judge prompt (evaluation criteria): ${__stack.args.judgePrompt}
176
+
177
+ Expected output: ${__stack.args.expectedOutput}
178
+
179
+ Actual output: ${__stack.args.actualOutput}
180
+
181
+ Provide a score from 0 to 100 where 100 means perfect match and 0 means completely wrong. Also provide brief reasoning.`,
182
+ messages: __threads.getOrCreateActive(),
183
+ responseFormat: z.object({
184
+ response: JudgeResult
185
+ }),
186
+ clientConfig: {},
187
+ maxToolCallRounds: 10,
188
+ stateStack: __stateStack,
189
+ removedTools: __self.__removedTools,
190
+ checkpointInfo: runner2.getCheckpointInfo()
191
+ });
192
+ if (hasInterrupts(__stack.locals.result)) {
193
+ await __ctx.pendingPromises.awaitAll();
194
+ runner2.halt({
195
+ messages: __threads,
196
+ data: __stack.locals.result
197
+ });
198
+ return;
199
+ }
200
+ });
201
+ await runner.step(1, async (runner2) => {
202
+ runner2.halt({
203
+ messages: __threads,
204
+ data: __stack.locals.result
205
+ });
206
+ return;
207
+ });
208
+ if (runner.halted) return runner.haltResult;
209
+ await callHook({
210
+ callbacks: __ctx.callbacks,
211
+ name: "onNodeEnd",
212
+ data: {
213
+ nodeName: "judge",
214
+ data: void 0
215
+ }
216
+ });
217
+ return {
218
+ messages: __threads,
219
+ data: void 0
220
+ };
221
+ } catch (__error) {
222
+ if (__error instanceof RestoreSignal) {
223
+ throw __error;
224
+ }
225
+ console.error(`
226
+ Agent crashed: ${__error.message}`);
227
+ console.error(__error.stack);
228
+ return {
229
+ messages: __threads,
230
+ data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "judge" })
231
+ };
232
+ }
233
+ });
234
+ async function judge(actualOutput, expectedOutput, judgePrompt, { messages, callbacks } = {}) {
235
+ return runNode({
236
+ ctx: __globalCtx,
237
+ nodeName: "judge",
238
+ data: {
239
+ actualOutput,
240
+ expectedOutput,
241
+ judgePrompt
242
+ },
243
+ messages,
244
+ callbacks,
245
+ initializeGlobals: __initializeGlobals
246
+ });
247
+ }
248
+ const __judgeNodeParams = ["actualOutput", "expectedOutput", "judgePrompt"];
249
+ var stdin_default = graph;
250
+ const __sourceMap = { "dist/lib/agents/judge.agency:judge": { "0": { "line": 6, "col": 2 }, "1": { "line": 16, "col": 2 } } };
251
+ export {
252
+ __getCheckpoints,
253
+ __judgeNodeParams,
254
+ __setDebugger,
255
+ __setLLMClient,
256
+ __setTraceWriter,
257
+ __sourceMap,
258
+ __toolRegistry,
259
+ approve,
260
+ stdin_default as default,
261
+ hasInterrupts,
262
+ interrupt,
263
+ isDebugger,
264
+ isInterrupt,
265
+ judge,
266
+ readSkill,
267
+ reject,
268
+ respondToInterrupts,
269
+ rewindFrom
270
+ };
@@ -0,0 +1,77 @@
1
+ import { writePolicyFile } from "std::policy"
2
+ import { args } from "std::system"
3
+
4
+ systemPrompt = read("./prompts/system.md")
5
+
6
+ type NextStep = { type: "showPolicy"; policy: object } | { type: "writePolicy"; policy: object } | { type: "askQuestion"; question: string }
7
+
8
+ node main() {
9
+ let cliArgs = args()
10
+ if (cliArgs.length < 2) {
11
+ print("Usage: agency policy gen <file>")
12
+ return end()
13
+ }
14
+ let interruptKindsJson = cliArgs[0]
15
+ let outputPath = cliArgs[1]
16
+ let existingPolicyJson = ""
17
+ if (cliArgs.length >= 3) {
18
+ existingPolicyJson = cliArgs[2]
19
+ }
20
+
21
+ let interruptKinds = parseJSON(interruptKindsJson)
22
+ let existingPolicy = null
23
+ if (existingPolicyJson != "") {
24
+ existingPolicy = parseJSON(existingPolicyJson)
25
+ }
26
+
27
+ let contextMessage = "This agent can produce the following interrupts:\n"
28
+ for (kind in interruptKinds) {
29
+ contextMessage = contextMessage + "- ${kind}\n"
30
+ }
31
+
32
+ if (existingPolicy != null) {
33
+ contextMessage = contextMessage + """
34
+ Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
35
+ """
36
+ } else {
37
+ contextMessage = contextMessage + "\nWhat actions would you like to allow?"
38
+ }
39
+
40
+ print(contextMessage)
41
+
42
+ let done = false
43
+ let policy = {}
44
+ let conversationHistory = contextMessage
45
+ while (!done) {
46
+ let userInput = input("> ")
47
+ conversationHistory = conversationHistory + "\nUser: ${userInput}"
48
+
49
+ thread {
50
+ system(systemPrompt)
51
+ let step: NextStep = llm("""
52
+ ${conversationHistory}\n\nCurrent policy: ${printJSON(policy)}\n\nDecide the next step. If the user is describing what they want, build or update the policy and use showPolicy. If the user approves the shown policy, use writePolicy. If you need clarification, use askQuestion.
53
+ """)
54
+ }
55
+
56
+ if (step.type == "showPolicy") {
57
+ policy = step.policy
58
+ let policyStr = printJSON(policy)
59
+ print("\nProposed policy:\n```json\n${policyStr}\n```\n")
60
+ print("Does this look right? (say 'yes' to save, or describe changes)")
61
+ conversationHistory = conversationHistory + "\nAssistant: Here is the proposed policy:\n${policyStr}\nDoes this look right?"
62
+ } else if (step.type == "writePolicy") {
63
+ policy = step.policy
64
+ writePolicyFile(outputPath, policy)
65
+ print("\nPolicy written to ${outputPath}")
66
+ done = true
67
+ } else if (step.type == "askQuestion") {
68
+ print(step.question)
69
+ conversationHistory = conversationHistory + "\nAssistant: ${step.question}"
70
+ }
71
+ }
72
+ return end()
73
+ }
74
+
75
+ node end() {
76
+
77
+ }
@@ -0,0 +1,39 @@
1
+ You are a policy configuration assistant for Agency agents. Your job is to help users create interrupt policies that control what actions their agent can take autonomously.
2
+
3
+ ## What is a policy?
4
+
5
+ A policy is a JSON object that maps interrupt kinds to ordered arrays of rules. When an agent tries to perform an action that produces an interrupt, the policy is checked. The first matching rule determines whether the action is approved or rejected.
6
+
7
+ ## Policy format
8
+
9
+ ```json
10
+ {
11
+ "email::send": [
12
+ { "match": { "recipient": "*@company.com" }, "action": "approve" },
13
+ { "action": "reject" }
14
+ ]
15
+ }
16
+ ```
17
+
18
+ Each rule has:
19
+ - `action`: either `"approve"` or `"reject"`
20
+ - `match` (optional): an object where keys are interrupt data field names and values are glob patterns (using `*` for wildcards, `**` for path matching). If omitted, the rule is a catch-all.
21
+
22
+ ## Important rules
23
+
24
+ - Rules are evaluated **in order** — the first match wins
25
+ - Put specific rules **before** catch-all rules
26
+ - If no rule matches an interrupt kind, the interrupt is **rejected** by default
27
+ - Glob patterns use picomatch syntax: `*` matches anything except path separators, `**` matches anything including path separators
28
+
29
+ ## Your workflow
30
+
31
+ 1. You will be given a list of interrupt kinds that the agent can produce
32
+ 2. If an existing policy was provided, present it and ask what the user wants to change
33
+ 3. Otherwise, present the interrupt kinds and ask the user what they want to allow
34
+ 4. Build the policy based on the user's intent
35
+ 5. Show the complete policy JSON and ask for confirmation
36
+ 6. If the user approves, write the policy file using the writePolicyFile tool
37
+ 7. If the user wants changes, refine and show again
38
+
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.