agency-lang 0.6.2 → 0.6.3

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 (142) hide show
  1. package/dist/lib/agents/agency-agent/agent.agency +1 -1
  2. package/dist/lib/agents/agency-agent/agent.js +45 -112
  3. package/dist/lib/agents/agency-agent/code.js +532 -0
  4. package/dist/lib/agents/agency-agent/images/images.js +3 -0
  5. package/dist/lib/agents/agency-agent/lib/config.js +3 -0
  6. package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +5 -6
  7. package/dist/lib/agents/agency-agent/lib/models.agency +154 -0
  8. package/dist/lib/agents/agency-agent/lib/models.js +711 -0
  9. package/dist/lib/agents/agency-agent/lib/utils.js +9 -22
  10. package/dist/lib/agents/agency-agent/prompts/codeSample.js +9 -22
  11. package/dist/lib/agents/agency-agent/research.js +311 -0
  12. package/dist/lib/agents/agency-agent/shared.agency +19 -67
  13. package/dist/lib/agents/agency-agent/shared.js +52 -150
  14. package/dist/lib/agents/agency-agent/subagents/code.js +16 -20
  15. package/dist/lib/agents/agency-agent/subagents/explorer.js +9 -10
  16. package/dist/lib/agents/agency-agent/subagents/oracle.js +10 -11
  17. package/dist/lib/agents/agency-agent/subagents/research.js +12 -13
  18. package/dist/lib/agents/agency-agent/subagents/review.js +12 -34
  19. package/dist/lib/agents/agency-agent/tests/agentTurn.js +5 -6
  20. package/dist/lib/agents/agency-agent/tests/execPolicy.js +15 -31
  21. package/dist/lib/agents/agency-agent/tests/toolWiring.js +13 -26
  22. package/dist/lib/agents/agency-agent/toolWiring.js +696 -0
  23. package/dist/lib/agents/docs/cli/cli/optimize.md +4 -2
  24. package/dist/lib/agents/docs/cli/optimize.md +4 -2
  25. package/dist/lib/agents/eval/goalJudge.agency +4 -1
  26. package/dist/lib/agents/eval/goalJudge.js +14 -10
  27. package/dist/lib/agents/eval/judge.js +5 -6
  28. package/dist/lib/agents/eval/judgePairwise.js +5 -6
  29. package/dist/lib/agents/gepaReflect.js +316 -0
  30. package/dist/lib/agents/mutatePrompt.js +301 -0
  31. package/dist/lib/agents/optimize/gepaReflect.js +5 -6
  32. package/dist/lib/agents/optimize/mutatePrompt.js +5 -6
  33. package/dist/lib/agents/policy/agent.js +16 -44
  34. package/dist/lib/agents/review/agent.js +6 -10
  35. package/dist/lib/backends/typescriptBuilder.integration.test.js +80 -0
  36. package/dist/lib/backends/typescriptBuilder.js +67 -17
  37. package/dist/lib/backends/typescriptGenerator/validationDescriptor.d.ts +6 -0
  38. package/dist/lib/backends/typescriptGenerator/validationDescriptor.js +108 -31
  39. package/dist/lib/cli/eval/optimize.js +4 -2
  40. package/dist/lib/optimize/baseOptimizer.d.ts +27 -0
  41. package/dist/lib/optimize/baseOptimizer.js +56 -3
  42. package/dist/lib/optimize/grading/functionGrader.d.ts +5 -1
  43. package/dist/lib/optimize/grading/functionGrader.js +9 -1
  44. package/dist/lib/optimize/grading/functionGrader.test.js +22 -0
  45. package/dist/lib/optimize/grading/graders/llmJudge.d.ts +1 -0
  46. package/dist/lib/optimize/grading/graders/llmJudge.js +5 -1
  47. package/dist/lib/optimize/grading/graders/llmJudge.test.js +12 -2
  48. package/dist/lib/optimize/optimizers/example.d.ts +9 -10
  49. package/dist/lib/optimize/optimizers/example.js +33 -33
  50. package/dist/lib/optimize/optimizers/example.test.js +11 -0
  51. package/dist/lib/optimize/optimizers/gepa.d.ts +0 -2
  52. package/dist/lib/optimize/optimizers/gepa.js +3 -18
  53. package/dist/lib/optimize/optimizers/gepa.test.js +11 -0
  54. package/dist/lib/optimize/optimizers/greedyReflective.d.ts +0 -7
  55. package/dist/lib/optimize/optimizers/greedyReflective.js +2 -36
  56. package/dist/lib/runtime/errors.d.ts +21 -10
  57. package/dist/lib/runtime/errors.js +46 -22
  58. package/dist/lib/runtime/errors.test.js +56 -2
  59. package/dist/lib/runtime/guard.d.ts +22 -5
  60. package/dist/lib/runtime/guard.js +30 -7
  61. package/dist/lib/runtime/guard.test.js +30 -1
  62. package/dist/lib/runtime/hooks.js +5 -2
  63. package/dist/lib/runtime/index.d.ts +2 -2
  64. package/dist/lib/runtime/index.js +2 -2
  65. package/dist/lib/runtime/node.d.ts +43 -0
  66. package/dist/lib/runtime/node.js +129 -52
  67. package/dist/lib/runtime/prompt.js +16 -28
  68. package/dist/lib/runtime/result.d.ts +6 -0
  69. package/dist/lib/runtime/result.js +19 -15
  70. package/dist/lib/runtime/result.test.js +55 -4
  71. package/dist/lib/runtime/runBatch.js +3 -2
  72. package/dist/lib/runtime/runBatch.test.js +33 -0
  73. package/dist/lib/runtime/state/stateStack.test.js +6 -2
  74. package/dist/lib/runtime/threadRepair.d.ts +36 -0
  75. package/dist/lib/runtime/threadRepair.js +69 -0
  76. package/dist/lib/runtime/threadRepair.test.d.ts +1 -0
  77. package/dist/lib/runtime/threadRepair.test.js +89 -0
  78. package/dist/lib/serve/discovery.js +24 -2
  79. package/dist/lib/serve/http/adapter.js +1 -5
  80. package/dist/lib/serve/http/adapter.test.js +3 -0
  81. package/dist/lib/serve/http/functionFrame.integration.test.d.ts +1 -0
  82. package/dist/lib/serve/http/functionFrame.integration.test.js +83 -0
  83. package/dist/lib/serve/mcp/adapter.js +1 -1
  84. package/dist/lib/serve/mcp/adapter.test.js +4 -2
  85. package/dist/lib/serve/mcp/httpTransport.test.js +1 -0
  86. package/dist/lib/serve/types.d.ts +10 -0
  87. package/dist/lib/stdlib/http.js +19 -2
  88. package/dist/lib/stdlib/thread.d.ts +29 -4
  89. package/dist/lib/stdlib/thread.js +60 -15
  90. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.d.ts +1 -1
  91. package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.js +8 -15
  92. package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
  93. package/dist/lib/templates/backends/typescriptGenerator/imports.js +7 -2
  94. package/dist/lib/typeChecker/valueParamSubstitution.js +17 -3
  95. package/package.json +1 -1
  96. package/stdlib/agency/eval.js +9 -22
  97. package/stdlib/agency.js +20 -66
  98. package/stdlib/agent.js +13 -38
  99. package/stdlib/args.js +5 -6
  100. package/stdlib/array.js +17 -54
  101. package/stdlib/browser.js +5 -6
  102. package/stdlib/calendar.js +10 -26
  103. package/stdlib/chart.js +8 -18
  104. package/stdlib/cli.js +10 -26
  105. package/stdlib/clipboard.js +6 -10
  106. package/stdlib/concurrency.js +5 -6
  107. package/stdlib/date.js +19 -62
  108. package/stdlib/email.js +7 -14
  109. package/stdlib/fs.js +10 -26
  110. package/stdlib/http.js +7 -14
  111. package/stdlib/imessage.js +5 -6
  112. package/stdlib/index.js +24 -82
  113. package/stdlib/keyring.js +8 -18
  114. package/stdlib/layout.js +22 -74
  115. package/stdlib/llm.agency +9 -3
  116. package/stdlib/llm.js +17 -21
  117. package/stdlib/markdown.js +8 -18
  118. package/stdlib/math.js +8 -18
  119. package/stdlib/memory.js +13 -38
  120. package/stdlib/oauth.js +8 -18
  121. package/stdlib/object.js +9 -22
  122. package/stdlib/path.js +11 -30
  123. package/stdlib/policy.js +22 -74
  124. package/stdlib/schemas.js +3 -0
  125. package/stdlib/search.js +5 -6
  126. package/stdlib/shell.js +12 -34
  127. package/stdlib/skills.js +13 -38
  128. package/stdlib/sms.js +5 -6
  129. package/stdlib/speech.js +7 -14
  130. package/stdlib/statelog.js +10 -26
  131. package/stdlib/strategy.js +9 -22
  132. package/stdlib/syntax.js +8 -18
  133. package/stdlib/system.js +15 -46
  134. package/stdlib/table.js +11 -30
  135. package/stdlib/thread.agency +4 -3
  136. package/stdlib/thread.js +25 -43
  137. package/stdlib/threads.js +9 -22
  138. package/stdlib/types.js +27 -0
  139. package/stdlib/ui.js +60 -226
  140. package/stdlib/validators.js +15 -46
  141. package/stdlib/weather.js +7 -14
  142. package/stdlib/wikipedia.js +7 -14
@@ -0,0 +1,532 @@
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
+ import { todoWrite, todoList } from "agency-lang/stdlib/agent.js";
3
+ import { typecheck } from "agency-lang/stdlib/agency.js";
4
+ import { openDir, Workspace } from "agency-lang/stdlib/fs.js";
5
+ import { remember, recall } from "agency-lang/stdlib/memory.js";
6
+ import { skillsDir } from "agency-lang/stdlib/skills.js";
7
+ import { highlight } from "agency-lang/stdlib/syntax.js";
8
+ import { cwd } from "agency-lang/stdlib/system.js";
9
+ import { fileURLToPath } from "url";
10
+ import __process from "process";
11
+ import { z } from "agency-lang/zod";
12
+ import { nanoid } from "agency-lang";
13
+ import path from "path";
14
+ import {
15
+ RuntimeContext,
16
+ Runner,
17
+ setupFunction,
18
+ callHook,
19
+ checkpoint as __checkpoint_impl,
20
+ getCheckpoint as __getCheckpoint_impl,
21
+ restore as __restore_impl,
22
+ _run as __runtime_run_impl,
23
+ interrupt,
24
+ isInterrupt,
25
+ hasInterrupts,
26
+ isDebugger,
27
+ respondToInterrupts as _respondToInterrupts,
28
+ rewindFrom as _rewindFrom,
29
+ RestoreSignal,
30
+ GuardExceededError,
31
+ deepFreeze as __deepFreeze,
32
+ __UNINIT_STATIC,
33
+ __readStatic,
34
+ __registerStaticInit,
35
+ __registerGlobalsInit,
36
+ failure,
37
+ isFailure,
38
+ AgencyFunction as __AgencyFunction,
39
+ __call,
40
+ __callMethod,
41
+ __stateStack,
42
+ __globals,
43
+ getRuntimeContext,
44
+ agencyStore,
45
+ functionRefReviver as __functionRefReviver,
46
+ DeterministicClient as __DeterministicClient,
47
+ createLogger as __createLogger
48
+ } from "agency-lang/runtime";
49
+ const __filename = fileURLToPath(import.meta.url);
50
+ const __dirname = path.dirname(__filename);
51
+ const __cwd = __process.cwd();
52
+ const getDirname = () => __dirname;
53
+ const __globalCtx = new RuntimeContext({
54
+ statelogConfig: {
55
+ host: "https://statelog.adit.io",
56
+ apiKey: __process.env["STATELOG_API_KEY"] || "",
57
+ projectId: "agency-lang",
58
+ debugMode: false,
59
+ observability: true,
60
+ logFile: "statelog.log"
61
+ },
62
+ smoltalkDefaults: {
63
+ openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
64
+ googleApiKey: __process.env["GEMINI_API_KEY"] || "",
65
+ model: "gpt-4o-mini",
66
+ logLevel: "warn",
67
+ statelog: {
68
+ host: "https://statelog.adit.io",
69
+ projectId: "smoltalk",
70
+ apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
71
+ traceId: nanoid()
72
+ }
73
+ },
74
+ dirname: __dirname,
75
+ logLevel: "info",
76
+ traceConfig: {
77
+ program: "lib/agents/agency-agent/code.agency"
78
+ }
79
+ });
80
+ const graph = __globalCtx.graph;
81
+ function approve(value) {
82
+ return { type: "approve", value };
83
+ }
84
+ function reject(value) {
85
+ return { type: "reject", value };
86
+ }
87
+ function propagate() {
88
+ return { type: "propagate" };
89
+ }
90
+ const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
91
+ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
92
+ const __setDebugger = (dbg) => {
93
+ __globalCtx.debuggerState = dbg;
94
+ };
95
+ const __setTraceFile = (filePath) => {
96
+ __globalCtx.traceConfig.traceFile = filePath;
97
+ };
98
+ const __setLLMClient = (client) => {
99
+ __globalCtx.setLLMClient(client);
100
+ };
101
+ const __getCheckpoints = () => __globalCtx.checkpoints;
102
+ if (__process.env.AGENCY_LLM_MOCKS) {
103
+ __globalCtx.setLLMClient(
104
+ new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
105
+ );
106
+ }
107
+ const __toolRegistry = __functionRefReviver.registry ??= {};
108
+ function __registerTool(value, _aliasName) {
109
+ if (__AgencyFunction.isAgencyFunction(value)) {
110
+ __toolRegistry[`${value.module}:${value.name}`] = value;
111
+ }
112
+ }
113
+ const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
114
+ const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
115
+ 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);
116
+ 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);
117
+ function setLLMClient(client) {
118
+ __globalCtx.setLLMClient(client);
119
+ }
120
+ function registerTools(tools) {
121
+ for (const tool of tools) {
122
+ if (__AgencyFunction.isAgencyFunction(tool)) {
123
+ __toolRegistry[`${tool.module}:${tool.name}`] = tool;
124
+ }
125
+ }
126
+ }
127
+ __registerTool(print);
128
+ __registerTool(printJSON);
129
+ __registerTool(parseJSON);
130
+ __registerTool(input);
131
+ __registerTool(sleep);
132
+ __registerTool(round);
133
+ __registerTool(read);
134
+ __registerTool(write);
135
+ __registerTool(readImage);
136
+ __registerTool(notify);
137
+ __registerTool(range);
138
+ __registerTool(mostCommon);
139
+ __registerTool(keys);
140
+ __registerTool(values);
141
+ __registerTool(entries);
142
+ __registerTool(emit);
143
+ __registerTool(callback);
144
+ __registerTool(todoWrite);
145
+ __registerTool(todoList);
146
+ __registerTool(typecheck);
147
+ __registerTool(openDir);
148
+ __registerTool(Workspace);
149
+ __registerTool(remember);
150
+ __registerTool(recall);
151
+ __registerTool(skillsDir);
152
+ __registerTool(highlight);
153
+ __registerTool(cwd);
154
+ let __staticInitPromise = null;
155
+ let workspace = __UNINIT_STATIC;
156
+ let superpowersSkill = __UNINIT_STATIC;
157
+ let codeSysPrompt = __UNINIT_STATIC;
158
+ let codeTools = __UNINIT_STATIC;
159
+ async function __initializeStatic(__ctx) {
160
+ if (__staticInitPromise) {
161
+ return __staticInitPromise;
162
+ }
163
+ __staticInitPromise = (async () => {
164
+ workspace = __deepFreeze(await __call(openDir, {
165
+ type: "positional",
166
+ args: [await __call(cwd, {
167
+ type: "positional",
168
+ args: []
169
+ })]
170
+ }));
171
+ getRuntimeContext().ctx.pushHandler(async (__data) => approve());
172
+ try {
173
+ superpowersSkill = __deepFreeze(await __call(skillsDir, {
174
+ type: "positional",
175
+ args: [`./skills/superpowers`, `flat`]
176
+ }));
177
+ } finally {
178
+ getRuntimeContext().ctx.popHandler();
179
+ }
180
+ codeSysPrompt = __deepFreeze(`
181
+ You are the **code specialist** of a multi-thread Agency-language
182
+ assistant. You handle anything that touches code or the file system:
183
+ writing, editing, running, and typechecking Agency or shell code.
184
+
185
+ You do NOT have access to web search, documentation lookup, Wikipedia,
186
+ or URL fetching. If the user asks a question that needs research
187
+ (Agency syntax you're unsure of, an external API, a Wikipedia
188
+ summary, or a URL fetch), call \`handoff(reason)\` \u2014 the only valid
189
+ target for you is the research specialist, so just pass a brief
190
+ reason. The runtime will re-route the user's original message there.
191
+
192
+ **Bias toward staying in the code thread.** Most follow-up messages
193
+ ("can you make it faster?", "fix the error", "what about edge
194
+ cases?") are continuations of the current coding task, NOT new
195
+ categories. Only call \`handoff\` when the message clearly needs
196
+ research-specialist tools.
197
+
198
+ ## Hard rules
199
+
200
+ These are non-negotiable. They override anything else in this prompt
201
+ when in conflict.
202
+
203
+ 1. **NEVER assume a function, library, or type exists.** Before
204
+ importing or calling something, verify it with \`grep\` or \`read\`.
205
+ "I think there's a \`foo()\` in std::array" is not good enough \u2014 go
206
+ look. Hallucinated imports are the #1 cause of broken first drafts.
207
+ 2. **NEVER \`write\` or \`edit\` a file you have not \`read\` in this
208
+ session.** Even if you wrote it last turn. The file on disk may
209
+ have been changed by the user or another tool.
210
+ 3. **MUST call \`typecheck\` on every Agency source file you produce
211
+ or modify, before claiming the change is done.** If typecheck
212
+ reports errors, fix them and run it again. Don't silence errors \u2014
213
+ no \`as any\` cast, no \`// @ts-ignore\`, no deleting tests to make
214
+ them pass. Address the real issue or report the blocker.
215
+ 4. **Be concise. Minimize tokens.** Show code, not commentary. Don't
216
+ restate what just happened \u2014 the user can see the diff and the
217
+ tool output. End your turn when the work is done; don't pad with
218
+ summaries or next-step suggestions unless the user asked.
219
+ 5. **NEVER add code comments to explain your changes.** Explanations
220
+ belong in your reply, not in the source. Existing comments in the
221
+ codebase that document non-obvious behavior should be preserved.
222
+ 6. **Mimic the existing code style.** Before editing a file, look
223
+ at how nearby code is written and match it: brace style, naming,
224
+ import grouping, error handling pattern. The codebase has
225
+ conventions; respect them.
226
+ 7. **State your plan in one sentence before a multi-step task.**
227
+ "I'll grep for callers of X, then update the three sites." This
228
+ gives the user a chance to redirect before tool use burns time.
229
+ 8. **For any task with more than two steps, call \`todoWrite\` first
230
+ to plan, and mark each item completed the moment it's done.**
231
+ Use this VERY frequently \u2014 it gives the user visibility into your
232
+ progress and protects against forgetting a step. Mark items
233
+ completed one at a time, NEVER batch the completions at the end.
234
+ Skip the list for trivial single-step changes.
235
+
236
+ ## Agency syntax \u2014 common mistakes to never make
237
+
238
+ The Agency language has TypeScript-style braces and parens, not
239
+ Python-style colons. If your draft has any of these, it's wrong:
240
+
241
+ - \u274C \`function foo() -> ReturnType:\` \u2192 \u2705 \`def foo(): ReturnType { ... }\`
242
+ - \u274C \`node main -> end:\` \u2192 \u2705 \`node main() { ... }\`
243
+ - \u274C \`if condition:\` or \`if condition {\` (no parens) \u2192 \u2705 \`if (condition) { ... }\`
244
+ - \u274C \`for item in items:\` \u2192 \u2705 \`for (item in items) { ... }\`
245
+ - \u274C \`result = foo()\` without prior declaration \u2192 \u2705 \`let result = foo()\` or \`const result = foo()\`
246
+ - \u274C Python-style indentation for blocks \u2192 \u2705 always \`{ ... }\`
247
+
248
+ When unsure about syntax, read \`docs/site/guide/basic-syntax.md\` or
249
+ an existing fixture in \`tests/agency/\` before writing. Agency tests
250
+ live in \`.agency\` files you can \`read\` directly.
251
+
252
+ ## Workflow
253
+
254
+ 1. Call \`setCwd\` with the user's project directory first. After
255
+ that, every file-system tool resolves filenames against that
256
+ directory and its subtree.
257
+ 2. Read \`AGENTS.md\` and \`CLAUDE.md\` at the project root if either
258
+ exists and you haven't yet this session. They contain project
259
+ conventions you MUST follow.
260
+ 3. Use \`ls\` or \`glob\` to discover what files exist before guessing
261
+ filenames. \`glob("**/*.agency")\` is a good first move on a new
262
+ project. The returned paths (which may include subdirectories
263
+ like \`"sub/foo.agency"\`) are exactly what \`read\` / \`edit\` expect
264
+ as their \`filename\` argument.
265
+ 4. Use \`read\` to inspect existing code before modifying it (see
266
+ rule 2 above).
267
+ 5. Use \`write\` / \`edit\` to persist changes. \`edit\` takes an array
268
+ of \`{oldText, newText, replaceAll}\` entries \u2014 prefer one call
269
+ with multiple entries over several \`edit\` calls when you have
270
+ more than one change to make to the same file. The user will be
271
+ prompted to approve every write.
272
+ 6. After every change, run \`typecheck\` (rule 3 above) and any
273
+ relevant tests via \`bash\`.
274
+ 7. Use \`bash\` to run project-level commands (tests, git, formatters,
275
+ package managers). Prefer the dedicated file tools above for file
276
+ operations; use \`bash\` for everything else. The user is asked to
277
+ approve each command.
278
+ 8. You have a persistent knowledge graph scoped to coding work. Call
279
+ \`recall(query)\` to retrieve anything the user told you in a
280
+ previous session (project conventions, decisions made earlier).
281
+ Call \`remember(content)\` to persist a fact worth keeping across
282
+ sessions \u2014 user preferences ("prefers tabs"), project conventions
283
+ ("uses \`def\` not \`node\` for utilities"), or important decisions.
284
+ Don't \`remember\` transient details or things already in
285
+ AGENTS.md. Relevant facts are also auto-injected before each turn,
286
+ so often you don't need to call \`recall\` explicitly.
287
+ 9. For **larger coding tasks that benefit from up-front thinking**
288
+ \u2014 building a new feature, designing a non-trivial component,
289
+ refactoring across multiple files, debugging something the user
290
+ has already tried once \u2014 call \`superpowersSkill\` to read the
291
+ relevant Superpowers skill before jumping into code. Good
292
+ defaults:
293
+ * \`brainstorming.md\` first whenever the user describes a
294
+ *new* feature or behavior change, before writing any code.
295
+ * \`writing-plans.md\` once you have a spec, before touching
296
+ implementation.
297
+ * \`executing-plans.md\` while working through a written plan.
298
+ * \`test-driven-development.md\` for any feature or bugfix.
299
+ * \`systematic-debugging.md\` for bugs / unexpected failures.
300
+ * \`verification-before-completion.md\` before claiming work
301
+ is done.
302
+ Skip the skill for trivial one-line edits, single-file
303
+ tweaks, or quick questions \u2014 the skills are for tasks where
304
+ structure pays for itself.
305
+ 10. Whenever you want to show the user a multi-line code snippet,
306
+ call \`print(highlight(code))\` instead of including the raw
307
+ source in your reply. \`highlight\` returns a terminal-colored
308
+ string and \`print\` writes it directly to the user's console, so
309
+ the snippet appears with proper syntax highlighting. Skip this
310
+ for inline identifiers or one-token excerpts; use it for any
311
+ multi-line block. Your reply can then refer to the printed
312
+ snippet without repeating the source.
313
+
314
+ ## Output style
315
+
316
+ Respond in Markdown \u2014 use \`#\`/\`##\` headings, \`-\` bullets, **bold**,
317
+ _italic_, and fenced code blocks (\`\`\`ts, \`\`\`bash, \`\`\`json, \`\`\`diff)
318
+ for any code or command output. The REPL renders your reply through a
319
+ Markdown syntax highlighter, so well-marked-up replies appear with
320
+ colored headings, bold/italic styling, and properly highlighted code
321
+ fences. Code fences are especially important \u2014 they're how code in
322
+ your reply gets per-language coloring.
323
+
324
+ **Important:** put a blank line between a heading and any bullet list
325
+ or paragraph that follows it (\`## Heading\\n\\n- item\`, not
326
+ \`## Heading\\n- item\`). Without the blank line our Markdown renderer
327
+ silently truncates everything after the heading.
328
+ `);
329
+ codeTools = __deepFreeze([setCwd, __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").read, __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").write, await __callMethod(__readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").edit, "partial", {
330
+ type: "named",
331
+ positionalArgs: [],
332
+ namedArgs: {
333
+ printDiff: true
334
+ }
335
+ }), __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").ls, __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").glob, __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").grep, __readStatic(workspace, "workspace", "lib/agents/agency-agent/code.agency").bash, __readStatic(typecheck, "typecheck", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/agency.agency"), await __callMethod(__readStatic(highlight, "highlight", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/syntax.agency"), "partial", {
336
+ type: "named",
337
+ positionalArgs: [],
338
+ namedArgs: {
339
+ language: `ts`
340
+ }
341
+ }), __readStatic(print, "print", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/index.agency"), __readStatic(remember, "remember", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/memory.agency"), __readStatic(recall, "recall", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/memory.agency"), __readStatic(superpowersSkill, "superpowersSkill", "lib/agents/agency-agent/code.agency"), __readStatic(todoWrite, "todoWrite", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/agent.agency"), __readStatic(todoList, "todoList", "/Users/adityabhargava/agency-lang/packages/agency-lang/stdlib/agent.agency")]);
342
+ })();
343
+ return __staticInitPromise;
344
+ }
345
+ function __getStaticVars() {
346
+ return {
347
+ workspace,
348
+ superpowersSkill,
349
+ codeSysPrompt,
350
+ codeTools
351
+ };
352
+ }
353
+ __globalCtx.getStaticVars = __getStaticVars;
354
+ __registerStaticInit("lib/agents/agency-agent/code.agency", __initializeStatic);
355
+ async function __initializeGlobals(__ctx) {
356
+ if (__ctx.globals.isInitialized("lib/agents/agency-agent/code.agency")) {
357
+ return;
358
+ }
359
+ __ctx.globals.markInitialized("lib/agents/agency-agent/code.agency");
360
+ await __initializeStatic(__ctx);
361
+ await __ctx.writeStaticStateToTrace(__globalCtx.getStaticVars());
362
+ }
363
+ __registerGlobalsInit("lib/agents/agency-agent/code.agency", __initializeGlobals);
364
+ async function __registerTopLevelCallbacks(__ctx) {
365
+ __ctx.topLevelCallbacks = [];
366
+ }
367
+ __functionRefReviver.registry = __toolRegistry;
368
+ async function __setCwd_impl(dir) {
369
+ const __setupData = setupFunction();
370
+ const __stack = __setupData.stack;
371
+ const __step = __setupData.step;
372
+ const __self = __setupData.self;
373
+ const __ctx = getRuntimeContext().ctx;
374
+ let __forked;
375
+ let __functionCompleted = false;
376
+ if (!__globals().isInitialized("lib/agents/agency-agent/code.agency")) {
377
+ await __initializeGlobals(__ctx);
378
+ }
379
+ let __funcStartTime = performance.now();
380
+ __stack.args["dir"] = dir;
381
+ __self.__retryable = __self.__retryable ?? true;
382
+ const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "lib/agents/agency-agent/code.agency", scopeName: "setCwd", threads: __setupData.threads });
383
+ let __resultCheckpointId = -1;
384
+ if (__ctx._pendingArgOverrides) {
385
+ const __overrides = __ctx._pendingArgOverrides;
386
+ __ctx._pendingArgOverrides = void 0;
387
+ if ("dir" in __overrides) {
388
+ dir = __overrides["dir"];
389
+ __stack.args["dir"] = dir;
390
+ }
391
+ }
392
+ try {
393
+ await agencyStore.run({
394
+ ...getRuntimeContext(),
395
+ ctx: __ctx,
396
+ stack: __setupData.stateStack,
397
+ threads: __setupData.threads
398
+ }, async () => {
399
+ await runner.hook(0, async () => {
400
+ await callHook({
401
+ name: "onFunctionStart",
402
+ data: {
403
+ functionName: "setCwd",
404
+ args: {
405
+ dir
406
+ },
407
+ isBuiltin: false,
408
+ moduleId: "lib/agents/agency-agent/code.agency"
409
+ }
410
+ });
411
+ });
412
+ await runner.ifElse(1, [
413
+ {
414
+ condition: async () => __stack.args.dir === `cwd`,
415
+ body: async (runner2) => {
416
+ await runner2.step(0, async (runner3) => {
417
+ __stack.args.dir = await __call(cwd, {
418
+ type: "positional",
419
+ args: []
420
+ });
421
+ if (hasInterrupts(__stack.args.dir)) {
422
+ await getRuntimeContext().ctx.pendingPromises.awaitAll();
423
+ runner3.halt(__stack.args.dir);
424
+ return;
425
+ }
426
+ });
427
+ }
428
+ }
429
+ ]);
430
+ await runner.step(2, async (runner2) => {
431
+ });
432
+ await runner.step(3, async (runner2) => {
433
+ __functionCompleted = true;
434
+ runner2.halt(`Working directory set to: ${__stack.args.dir}`);
435
+ return;
436
+ });
437
+ });
438
+ if (runner.halted) {
439
+ if (isFailure(runner.haltResult)) {
440
+ runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
441
+ }
442
+ return runner.haltResult;
443
+ }
444
+ } catch (__error) {
445
+ if (__error instanceof RestoreSignal) {
446
+ throw __error;
447
+ }
448
+ if (__error instanceof GuardExceededError) {
449
+ throw __error;
450
+ }
451
+ {
452
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
453
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
454
+ const __log = __createLogger(__ctx.logLevel);
455
+ __log.error("Function setCwd threw an exception (converted to Failure): " + __errMsg);
456
+ if (__errStack) __log.error(__errStack);
457
+ __ctx.statelogClient?.error?.({
458
+ errorType: "runtimeError",
459
+ message: __errMsg,
460
+ functionName: "setCwd",
461
+ retryable: __self.__retryable
462
+ });
463
+ }
464
+ return failure(
465
+ __error instanceof Error ? __error.message : String(__error),
466
+ {
467
+ checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
468
+ retryable: __self.__retryable,
469
+ functionName: "setCwd",
470
+ args: __stack.args
471
+ }
472
+ );
473
+ } finally {
474
+ __stateStack()?.pop();
475
+ if (__functionCompleted) {
476
+ await callHook({
477
+ name: "onFunctionEnd",
478
+ data: {
479
+ functionName: "setCwd",
480
+ timeTaken: performance.now() - __funcStartTime
481
+ }
482
+ });
483
+ }
484
+ }
485
+ }
486
+ const setCwd = __AgencyFunction.create({
487
+ name: "setCwd",
488
+ module: "lib/agents/agency-agent/code.agency",
489
+ fn: __setCwd_impl,
490
+ params: [{
491
+ name: "dir",
492
+ hasDefault: false,
493
+ defaultValue: void 0,
494
+ variadic: false,
495
+ isFunctionTyped: false
496
+ }],
497
+ toolDefinition: {
498
+ name: "setCwd",
499
+ description: `Use this when the user tells you to change your current working
500
+ directory. After you call this, every file-system tool (read,
501
+ write, edit, ls, glob, grep, bash) will resolve filenames against
502
+ the given directory and its subtree. Pass \`"cwd"\` to anchor to the
503
+ user's current working directory.
504
+
505
+ @param dir - The directory to anchor file operations against`,
506
+ schema: z.object({ "dir": z.string() })
507
+ },
508
+ safe: false,
509
+ exported: true
510
+ }, __toolRegistry);
511
+ var stdin_default = graph;
512
+ const __sourceMap = { "lib/agents/agency-agent/code.agency:setCwd": { "1": { "line": 48, "col": 2 }, "3": { "line": 52, "col": 2 }, "1.0": { "line": 49, "col": 4 } } };
513
+ export {
514
+ __getCheckpoints,
515
+ __setDebugger,
516
+ __setLLMClient,
517
+ __setTraceFile,
518
+ __sourceMap,
519
+ __toolRegistry,
520
+ approve,
521
+ codeSysPrompt,
522
+ codeTools,
523
+ stdin_default as default,
524
+ hasInterrupts,
525
+ interrupt,
526
+ isDebugger,
527
+ isInterrupt,
528
+ reject,
529
+ respondToInterrupts,
530
+ rewindFrom,
531
+ setCwd
532
+ };
@@ -15,6 +15,7 @@ import {
15
15
  isDebugger,
16
16
  respondToInterrupts as _respondToInterrupts,
17
17
  rewindFrom as _rewindFrom,
18
+ runExportedFunction as _runExportedFunction,
18
19
  deepFreeze as __deepFreeze,
19
20
  __UNINIT_STATIC,
20
21
  __readStatic,
@@ -68,6 +69,7 @@ function propagate() {
68
69
  }
69
70
  const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
70
71
  const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
72
+ const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
71
73
  const __setDebugger = (dbg) => {
72
74
  __globalCtx.debuggerState = dbg;
73
75
  };
@@ -198,6 +200,7 @@ var stdin_default = graph;
198
200
  const __sourceMap = {};
199
201
  export {
200
202
  __getCheckpoints,
203
+ __invokeFunction,
201
204
  __setDebugger,
202
205
  __setLLMClient,
203
206
  __setTraceFile,
@@ -17,6 +17,7 @@ import {
17
17
  isDebugger,
18
18
  respondToInterrupts as _respondToInterrupts,
19
19
  rewindFrom as _rewindFrom,
20
+ runExportedFunction as _runExportedFunction,
20
21
  deepFreeze as __deepFreeze,
21
22
  __UNINIT_STATIC,
22
23
  __readStatic,
@@ -71,6 +72,7 @@ function propagate() {
71
72
  }
72
73
  const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
73
74
  const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
75
+ const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
74
76
  const __setDebugger = (dbg) => {
75
77
  __globalCtx.debuggerState = dbg;
76
78
  };
@@ -241,6 +243,7 @@ export {
241
243
  POLICY_FILE,
242
244
  POLICY_PATH,
243
245
  __getCheckpoints,
246
+ __invokeFunction,
244
247
  __setDebugger,
245
248
  __setLLMClient,
246
249
  __setTraceFile,
@@ -20,9 +20,9 @@ import {
20
20
  isDebugger,
21
21
  respondToInterrupts as _respondToInterrupts,
22
22
  rewindFrom as _rewindFrom,
23
+ runExportedFunction as _runExportedFunction,
23
24
  RestoreSignal,
24
- GuardExceededError,
25
- isAbortError as __isAbortError,
25
+ AgencyAbort,
26
26
  deepFreeze as __deepFreeze,
27
27
  __UNINIT_STATIC,
28
28
  __readStatic,
@@ -84,6 +84,7 @@ function propagate() {
84
84
  }
85
85
  const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
86
86
  const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
87
+ const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
87
88
  const __setDebugger = (dbg) => {
88
89
  __globalCtx.debuggerState = dbg;
89
90
  };
@@ -319,10 +320,7 @@ async function __agencyExecApproveRules_impl() {
319
320
  if (__error instanceof RestoreSignal) {
320
321
  throw __error;
321
322
  }
322
- if (__error instanceof GuardExceededError) {
323
- throw __error;
324
- }
325
- if (__isAbortError(__error)) {
323
+ if (__error instanceof AgencyAbort) {
326
324
  throw __error;
327
325
  }
328
326
  {
@@ -377,6 +375,7 @@ var stdin_default = graph;
377
375
  const __sourceMap = { "dist/lib/agents/agency-agent/lib/defaultPolicy.agency:agencyExecApproveRules": { "1": { "line": 20, "col": 2 } }, "dist/lib/agents/agency-agent/lib/defaultPolicy.agency:__block_0": { "1.0": { "line": 21, "col": 4 } } };
378
376
  export {
379
377
  __getCheckpoints,
378
+ __invokeFunction,
380
379
  __setDebugger,
381
380
  __setLLMClient,
382
381
  __setTraceFile,