agency-lang 0.7.0 → 0.7.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 (182) hide show
  1. package/dist/lib/agents/agency-agent/agent.agency +169 -28
  2. package/dist/lib/agents/agency-agent/agent.js +579 -152
  3. package/dist/lib/agents/agency-agent/lib/attachments.js +2 -2
  4. package/dist/lib/agents/agency-agent/lib/config.agency +5 -0
  5. package/dist/lib/agents/agency-agent/lib/config.js +11 -0
  6. package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +106 -0
  7. package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +764 -3
  8. package/dist/lib/agents/agency-agent/lib/modelFilters.js +1 -1
  9. package/dist/lib/agents/agency-agent/lib/resolution.js +4 -4
  10. package/dist/lib/agents/agency-agent/lib/search.js +3 -3
  11. package/dist/lib/agents/agency-agent/lib/settings.js +1 -1
  12. package/dist/lib/agents/agency-agent/lib/utils.js +1 -1
  13. package/dist/lib/agents/agency-agent/shared.agency +22 -0
  14. package/dist/lib/agents/agency-agent/shared.js +160 -3
  15. package/dist/lib/agents/agency-agent/subagents/code.js +1 -1
  16. package/dist/lib/agents/agency-agent/subagents/explorer.js +1 -1
  17. package/dist/lib/agents/agency-agent/subagents/oracle.js +1 -1
  18. package/dist/lib/agents/agency-agent/subagents/research.js +1 -1
  19. package/dist/lib/agents/agency-agent/subagents/review.js +4 -4
  20. package/dist/lib/agents/agency-agent/tests/agentTurn.js +1 -1
  21. package/dist/lib/agents/agency-agent/tests/attachments.js +1 -1
  22. package/dist/lib/agents/agency-agent/tests/attachmentsTurn.js +2 -2
  23. package/dist/lib/agents/agency-agent/tests/gitPolicy.js +3 -3
  24. package/dist/lib/agents/agency-agent/tests/oneShotRounds.agency +20 -0
  25. package/dist/lib/agents/agency-agent/tests/oneShotRounds.js +555 -0
  26. package/dist/lib/agents/agency-agent/tests/oneShotRounds.test.json +9 -0
  27. package/dist/lib/agents/review/agent.js +3 -3
  28. package/dist/lib/cli/doctor.d.ts +8 -0
  29. package/dist/lib/cli/doctor.js +21 -13
  30. package/dist/lib/cli/doctor.test.js +34 -0
  31. package/dist/lib/cli/help.js +1 -5
  32. package/dist/lib/cli/runBundledAgent.d.ts +17 -1
  33. package/dist/lib/cli/runBundledAgent.js +73 -2
  34. package/dist/lib/cli/runBundledAgent.test.d.ts +1 -0
  35. package/dist/lib/cli/runBundledAgent.test.js +96 -0
  36. package/dist/lib/config.d.ts +42 -33
  37. package/dist/lib/config.js +108 -6
  38. package/dist/lib/config.test.js +121 -2
  39. package/dist/lib/ir/prettyPrint.js +25 -4
  40. package/dist/lib/parseCache.js +8 -13
  41. package/dist/lib/parseCache.test.js +5 -8
  42. package/dist/lib/parser.js +5 -12
  43. package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -28
  44. package/dist/lib/preprocessors/typescriptPreprocessor.js +0 -245
  45. package/dist/lib/runtime/configOverrides.d.ts +17 -16
  46. package/dist/lib/runtime/configOverrides.js +27 -16
  47. package/dist/lib/runtime/configOverrides.test.js +116 -2
  48. package/dist/lib/runtime/prompt.js +7 -3
  49. package/dist/lib/runtime/runner.d.ts +2 -2
  50. package/dist/lib/runtime/runner.js +26 -7
  51. package/dist/lib/runtime/state/context.js +9 -2
  52. package/dist/lib/stdlib/llm.d.ts +1 -0
  53. package/dist/lib/stdlib/version.d.ts +1 -1
  54. package/dist/lib/stdlib/version.js +1 -1
  55. package/dist/scripts/agency.d.ts +2 -0
  56. package/dist/scripts/agency.js +55 -12
  57. package/dist/scripts/agency.test.js +73 -1
  58. package/package.json +1 -1
  59. package/stdlib/agency/eval.js +1 -1
  60. package/stdlib/agency.js +1 -1
  61. package/stdlib/agent.agency +9 -9
  62. package/stdlib/agent.js +5 -5
  63. package/stdlib/data/tech/hackernews.js +1 -1
  64. package/stdlib/index.js +15 -15
  65. package/stdlib/llm.agency +2 -1
  66. package/stdlib/llm.js +3 -3
  67. package/stdlib/markdown.js +1 -1
  68. package/stdlib/memory.js +2 -2
  69. package/stdlib/object.js +5 -5
  70. package/stdlib/policy.agency +21 -7
  71. package/stdlib/policy.js +45 -16
  72. package/stdlib/skills.js +1 -1
  73. package/stdlib/strategy.js +3 -3
  74. package/stdlib/thread.js +3 -3
  75. package/stdlib/ui/chart.js +2 -2
  76. package/stdlib/ui/cli.agency +1 -1
  77. package/stdlib/ui/cli.js +1 -1
  78. package/stdlib/ui/layout.js +3 -3
  79. package/stdlib/ui/table.js +2 -2
  80. package/stdlib/ui.js +3 -3
  81. package/dist/lib/agents/docs/cli/cli/agent.md +0 -16
  82. package/dist/lib/agents/docs/cli/cli/compile.md +0 -21
  83. package/dist/lib/agents/docs/cli/cli/coverage.md +0 -112
  84. package/dist/lib/agents/docs/cli/cli/debug.md +0 -41
  85. package/dist/lib/agents/docs/cli/cli/doc.md +0 -98
  86. package/dist/lib/agents/docs/cli/cli/editor-integration.md +0 -44
  87. package/dist/lib/agents/docs/cli/cli/eval-judge.md +0 -72
  88. package/dist/lib/agents/docs/cli/cli/eval.md +0 -194
  89. package/dist/lib/agents/docs/cli/cli/format.md +0 -23
  90. package/dist/lib/agents/docs/cli/cli/index.md +0 -7
  91. package/dist/lib/agents/docs/cli/cli/local.md +0 -92
  92. package/dist/lib/agents/docs/cli/cli/models.md +0 -63
  93. package/dist/lib/agents/docs/cli/cli/optimize.md +0 -338
  94. package/dist/lib/agents/docs/cli/cli/pack.md +0 -56
  95. package/dist/lib/agents/docs/cli/cli/policy.md +0 -23
  96. package/dist/lib/agents/docs/cli/cli/preprocess-and-ast.md +0 -21
  97. package/dist/lib/agents/docs/cli/cli/review.md +0 -16
  98. package/dist/lib/agents/docs/cli/cli/run.md +0 -79
  99. package/dist/lib/agents/docs/cli/cli/schedule.md +0 -89
  100. package/dist/lib/agents/docs/cli/cli/serve.md +0 -52
  101. package/dist/lib/agents/docs/cli/cli/test.md +0 -44
  102. package/dist/lib/agents/docs/cli/cli/trace-and-bundle.md +0 -75
  103. package/dist/lib/agents/docs/cli/cli/typecheck.md +0 -19
  104. package/dist/lib/agents/docs/guide/guide/advanced-types.md +0 -26
  105. package/dist/lib/agents/docs/guide/guide/agency-config-file.md +0 -212
  106. package/dist/lib/agents/docs/guide/guide/agency-packages.md +0 -54
  107. package/dist/lib/agents/docs/guide/guide/agency-stdlib.md +0 -14
  108. package/dist/lib/agents/docs/guide/guide/agency-vs-typescript.md +0 -33
  109. package/dist/lib/agents/docs/guide/guide/attachments.md +0 -56
  110. package/dist/lib/agents/docs/guide/guide/basic-syntax.md +0 -350
  111. package/dist/lib/agents/docs/guide/guide/blocks.md +0 -134
  112. package/dist/lib/agents/docs/guide/guide/build-integration.md +0 -99
  113. package/dist/lib/agents/docs/guide/guide/builtins.md +0 -84
  114. package/dist/lib/agents/docs/guide/guide/callbacks.md +0 -169
  115. package/dist/lib/agents/docs/guide/guide/checkpointing.md +0 -101
  116. package/dist/lib/agents/docs/guide/guide/cli-args.md +0 -190
  117. package/dist/lib/agents/docs/guide/guide/common-functions.md +0 -36
  118. package/dist/lib/agents/docs/guide/guide/compiling-and-running.md +0 -62
  119. package/dist/lib/agents/docs/guide/guide/concurrency.md +0 -108
  120. package/dist/lib/agents/docs/guide/guide/cross-thread-context.md +0 -226
  121. package/dist/lib/agents/docs/guide/guide/custom-providers.md +0 -195
  122. package/dist/lib/agents/docs/guide/guide/debugging.md +0 -67
  123. package/dist/lib/agents/docs/guide/guide/developer-tools.md +0 -90
  124. package/dist/lib/agents/docs/guide/guide/effects-and-raises.md +0 -137
  125. package/dist/lib/agents/docs/guide/guide/effects.md +0 -100
  126. package/dist/lib/agents/docs/guide/guide/error-handling.md +0 -161
  127. package/dist/lib/agents/docs/guide/guide/exercise-1.md +0 -32
  128. package/dist/lib/agents/docs/guide/guide/functions.md +0 -94
  129. package/dist/lib/agents/docs/guide/guide/getting-started.md +0 -35
  130. package/dist/lib/agents/docs/guide/guide/global-var-initialization.md +0 -70
  131. package/dist/lib/agents/docs/guide/guide/global-vs-static.md +0 -76
  132. package/dist/lib/agents/docs/guide/guide/guards.md +0 -134
  133. package/dist/lib/agents/docs/guide/guide/handlers.md +0 -196
  134. package/dist/lib/agents/docs/guide/guide/image-generation.md +0 -113
  135. package/dist/lib/agents/docs/guide/guide/imports-and-packages.md +0 -100
  136. package/dist/lib/agents/docs/guide/guide/interrupts-from-typescript.md +0 -84
  137. package/dist/lib/agents/docs/guide/guide/interrupts-part-2.md +0 -54
  138. package/dist/lib/agents/docs/guide/guide/interrupts.md +0 -139
  139. package/dist/lib/agents/docs/guide/guide/llm-part-2.md +0 -111
  140. package/dist/lib/agents/docs/guide/guide/llm.md +0 -109
  141. package/dist/lib/agents/docs/guide/guide/mcp.md +0 -295
  142. package/dist/lib/agents/docs/guide/guide/memory.md +0 -401
  143. package/dist/lib/agents/docs/guide/guide/message-threads.md +0 -111
  144. package/dist/lib/agents/docs/guide/guide/nodes.md +0 -50
  145. package/dist/lib/agents/docs/guide/guide/observability.md +0 -99
  146. package/dist/lib/agents/docs/guide/guide/partial-application.md +0 -96
  147. package/dist/lib/agents/docs/guide/guide/pattern-matching.md +0 -366
  148. package/dist/lib/agents/docs/guide/guide/policies.md +0 -67
  149. package/dist/lib/agents/docs/guide/guide/schema-parameter-injection.md +0 -101
  150. package/dist/lib/agents/docs/guide/guide/schemas.md +0 -99
  151. package/dist/lib/agents/docs/guide/guide/serving.md +0 -165
  152. package/dist/lib/agents/docs/guide/guide/state-isolation.md +0 -139
  153. package/dist/lib/agents/docs/guide/guide/streaming.md +0 -28
  154. package/dist/lib/agents/docs/guide/guide/tags.md +0 -72
  155. package/dist/lib/agents/docs/guide/guide/testing.md +0 -187
  156. package/dist/lib/agents/docs/guide/guide/troubleshooting.md +0 -86
  157. package/dist/lib/agents/docs/guide/guide/ts-helpers.md +0 -559
  158. package/dist/lib/agents/docs/guide/guide/ts-interop.md +0 -72
  159. package/dist/lib/agents/docs/guide/guide/type-validation.md +0 -187
  160. package/dist/lib/agents/docs/guide/guide/types.md +0 -181
  161. package/dist/lib/agents/docs/guide/guide/unused.md +0 -178
  162. package/dist/lib/agents/docs/guide/guide/unused2.md +0 -258
  163. package/dist/lib/agents/docs/guide/guide/value-parameterized-types.md +0 -186
  164. package/dist/lib/agents/docs/guide/guide/vscode-extension.md +0 -33
  165. package/dist/lib/agents/docs/guide/guide/why-agency.md +0 -323
  166. package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +0 -327
  167. package/stdlib/browser.js +0 -421
  168. package/stdlib/chart.js +0 -983
  169. package/stdlib/cli.js +0 -1116
  170. package/stdlib/email.js +0 -1104
  171. package/stdlib/imessage.js +0 -377
  172. package/stdlib/keyring.js +0 -803
  173. package/stdlib/layout.js +0 -3657
  174. package/stdlib/oauth.js +0 -862
  175. package/stdlib/schemas.js +0 -223
  176. package/stdlib/search.js +0 -629
  177. package/stdlib/sms.js +0 -419
  178. package/stdlib/table.js +0 -1419
  179. package/stdlib/threads.js +0 -1041
  180. package/stdlib/types.js +0 -222
  181. package/stdlib/validators.js +0 -1606
  182. /package/dist/lib/{preprocessors/typescriptPreprocessor.config.test.d.ts → cli/doctor.test.d.ts} +0 -0
@@ -0,0 +1,555 @@
1
+ import { print, printJSON, input, sleep, read, write, writeBinary, readBinary, range, callback, map, filter, exclude, find, findIndex, reduce, flatMap, every, some, count, sortBy, unique, groupBy } from "agency-lang/stdlib/index.js";
2
+ import { resolveMaxToolCallRounds } from "../shared.js";
3
+ import { fileURLToPath } from "url";
4
+ import __process from "process";
5
+ import { readFileSync } from "fs";
6
+ import { nanoid } from "agency-lang";
7
+ import path from "path";
8
+ import {
9
+ RuntimeContext,
10
+ Runner,
11
+ setupNode,
12
+ runNode,
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
+ runExportedFunction as _runExportedFunction,
25
+ RestoreSignal,
26
+ AgencyAbort,
27
+ __registerGlobalsInit,
28
+ failure,
29
+ __eq,
30
+ AgencyFunction as __AgencyFunction,
31
+ __call,
32
+ __threads,
33
+ getRuntimeContext,
34
+ agencyStore,
35
+ functionRefReviver as __functionRefReviver,
36
+ DeterministicClient as __DeterministicClient,
37
+ installFetchMock as __installFetchMock,
38
+ createLogger as __createLogger
39
+ } from "agency-lang/runtime";
40
+ const __filename = fileURLToPath(import.meta.url);
41
+ const __dirname = path.dirname(__filename);
42
+ const __cwd = __process.cwd();
43
+ const getDirname = () => __dirname;
44
+ const __globalCtx = new RuntimeContext({
45
+ statelogConfig: {
46
+ host: "https://statelog.adit.io",
47
+ apiKey: __process.env["STATELOG_API_KEY"] || "",
48
+ projectId: "agency-lang",
49
+ debugMode: false,
50
+ observability: true,
51
+ logFile: "log.jsonl"
52
+ },
53
+ smoltalkDefaults: {
54
+ apiKey: {
55
+ openAi: __process.env["OPENAI_API_KEY"] || "",
56
+ google: __process.env["GEMINI_API_KEY"] || "",
57
+ anthropic: __process.env["ANTHROPIC_API_KEY"] || "",
58
+ openRouter: __process.env["OPENROUTER_API_KEY"] || "",
59
+ deepInfra: __process.env["DEEPINFRA_API_KEY"] || "",
60
+ liteLlm: __process.env["LITELLM_API_KEY"] || "",
61
+ openAiCompat: __process.env["OPENAI_COMPAT_API_KEY"] || ""
62
+ },
63
+ baseUrl: {
64
+ liteLlm: __process.env["LITELLM_BASE_URL"] || "",
65
+ openAiCompat: __process.env["OPENAI_COMPAT_BASE_URL"] || ""
66
+ },
67
+ model: "gpt-4o-mini",
68
+ logLevel: "warn",
69
+ statelog: {
70
+ host: "https://statelog.adit.io",
71
+ projectId: "smoltalk",
72
+ apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
73
+ traceId: nanoid()
74
+ }
75
+ },
76
+ dirname: __dirname,
77
+ logLevel: "info",
78
+ traceConfig: {
79
+ program: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency"
80
+ }
81
+ });
82
+ const graph = __globalCtx.graph;
83
+ function approve(value) {
84
+ return { type: "approve", value };
85
+ }
86
+ function reject(value) {
87
+ return { type: "reject", value };
88
+ }
89
+ function propagate() {
90
+ return { type: "propagate" };
91
+ }
92
+ const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
93
+ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
94
+ const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
95
+ const __setDebugger = (dbg) => {
96
+ __globalCtx.debuggerState = dbg;
97
+ };
98
+ const __setTraceFile = (filePath) => {
99
+ __globalCtx.traceConfig.traceFile = filePath;
100
+ };
101
+ const __setLLMClient = (client) => {
102
+ __globalCtx.setLLMClient(client);
103
+ };
104
+ const __getCheckpoints = () => __globalCtx.checkpoints;
105
+ if (__process.env.AGENCY_LLM_MOCKS) {
106
+ __globalCtx.setLLMClient(
107
+ new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
108
+ );
109
+ }
110
+ if (__process.env.AGENCY_FETCH_MOCKS_FILE) {
111
+ __installFetchMock(JSON.parse(readFileSync(__process.env.AGENCY_FETCH_MOCKS_FILE, "utf-8")));
112
+ }
113
+ const __toolRegistry = __functionRefReviver.registry ??= {};
114
+ function __registerTool(value, _aliasName) {
115
+ if (__AgencyFunction.isAgencyFunction(value)) {
116
+ __toolRegistry[`${value.module}:${value.name}`] = value;
117
+ }
118
+ }
119
+ const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
120
+ const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
121
+ 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);
122
+ 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 }, { name: "configOverrides", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "cwd", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "maxDepth", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
123
+ function setLLMClient(client) {
124
+ __globalCtx.setLLMClient(client);
125
+ }
126
+ function registerTools(tools) {
127
+ for (const tool of tools) {
128
+ if (__AgencyFunction.isAgencyFunction(tool)) {
129
+ __toolRegistry[`${tool.module}:${tool.name}`] = tool;
130
+ }
131
+ }
132
+ }
133
+ __registerTool(print);
134
+ __registerTool(printJSON);
135
+ __registerTool(input);
136
+ __registerTool(sleep);
137
+ __registerTool(read);
138
+ __registerTool(write);
139
+ __registerTool(writeBinary);
140
+ __registerTool(readBinary);
141
+ __registerTool(range);
142
+ __registerTool(callback);
143
+ __registerTool(map);
144
+ __registerTool(filter);
145
+ __registerTool(exclude);
146
+ __registerTool(find);
147
+ __registerTool(findIndex);
148
+ __registerTool(reduce);
149
+ __registerTool(flatMap);
150
+ __registerTool(every);
151
+ __registerTool(some);
152
+ __registerTool(count);
153
+ __registerTool(sortBy);
154
+ __registerTool(unique);
155
+ __registerTool(groupBy);
156
+ __registerTool(resolveMaxToolCallRounds);
157
+ async function __initializeGlobals(__ctx) {
158
+ if (__ctx.globals.isInitialized("dist/lib/agents/agency-agent/tests/oneShotRounds.agency")) {
159
+ return;
160
+ }
161
+ __ctx.globals.markInitialized("dist/lib/agents/agency-agent/tests/oneShotRounds.agency");
162
+ }
163
+ __registerGlobalsInit("dist/lib/agents/agency-agent/tests/oneShotRounds.agency", __initializeGlobals);
164
+ async function __registerTopLevelCallbacks(__ctx) {
165
+ __ctx.topLevelCallbacks = [];
166
+ }
167
+ __functionRefReviver.registry = __toolRegistry;
168
+ graph.node("explicitWinsOverOneShot", async (__state) => {
169
+ const __setupData = setupNode({
170
+ state: __state
171
+ });
172
+ const __stack = __setupData.stack;
173
+ const __step = __setupData.step;
174
+ const __self = __setupData.self;
175
+ const __ctx = getRuntimeContext().ctx;
176
+ let __forked;
177
+ let __functionCompleted = false;
178
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "explicitWinsOverOneShot", threads: __setupData.threads });
179
+ try {
180
+ await agencyStore.run({
181
+ ...getRuntimeContext(),
182
+ ctx: __ctx,
183
+ stack: __ctx.stateStack,
184
+ threads: __setupData.threads
185
+ }, async () => {
186
+ await runner.hook(0, async () => {
187
+ await callHook({
188
+ name: "onNodeStart",
189
+ data: {
190
+ nodeName: "explicitWinsOverOneShot"
191
+ }
192
+ });
193
+ });
194
+ await runner.step(1, async (runner2) => {
195
+ __self.__retryable = false;
196
+ runner2.halt({
197
+ messages: __threads(),
198
+ data: __eq(await __call(resolveMaxToolCallRounds, {
199
+ type: "positional",
200
+ args: [7, true]
201
+ }), 7)
202
+ });
203
+ return;
204
+ });
205
+ });
206
+ if (runner.halted) return runner.haltResult;
207
+ await runner.hook(2, async () => {
208
+ await callHook({
209
+ name: "onNodeEnd",
210
+ data: {
211
+ nodeName: "explicitWinsOverOneShot",
212
+ data: void 0
213
+ }
214
+ });
215
+ });
216
+ return {
217
+ messages: __threads(),
218
+ data: void 0
219
+ };
220
+ } catch (__error) {
221
+ if (__error instanceof RestoreSignal) {
222
+ throw __error;
223
+ }
224
+ if (__error instanceof AgencyAbort) {
225
+ throw __error;
226
+ }
227
+ {
228
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
229
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
230
+ const __log = __createLogger(__ctx.logLevel);
231
+ __log.error(`Node explicitWinsOverOneShot crashed: ${__errMsg}`);
232
+ if (__errStack) __log.error(__errStack);
233
+ __ctx.statelogClient?.error?.({
234
+ errorType: "runtimeError",
235
+ message: __errMsg,
236
+ functionName: "explicitWinsOverOneShot"
237
+ });
238
+ }
239
+ return {
240
+ messages: __threads(),
241
+ data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "explicitWinsOverOneShot" })
242
+ };
243
+ }
244
+ });
245
+ graph.node("oneShotDefaults50", async (__state) => {
246
+ const __setupData = setupNode({
247
+ state: __state
248
+ });
249
+ const __stack = __setupData.stack;
250
+ const __step = __setupData.step;
251
+ const __self = __setupData.self;
252
+ const __ctx = getRuntimeContext().ctx;
253
+ let __forked;
254
+ let __functionCompleted = false;
255
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "oneShotDefaults50", threads: __setupData.threads });
256
+ try {
257
+ await agencyStore.run({
258
+ ...getRuntimeContext(),
259
+ ctx: __ctx,
260
+ stack: __ctx.stateStack,
261
+ threads: __setupData.threads
262
+ }, async () => {
263
+ await runner.hook(0, async () => {
264
+ await callHook({
265
+ name: "onNodeStart",
266
+ data: {
267
+ nodeName: "oneShotDefaults50"
268
+ }
269
+ });
270
+ });
271
+ await runner.step(1, async (runner2) => {
272
+ __self.__retryable = false;
273
+ runner2.halt({
274
+ messages: __threads(),
275
+ data: __eq(await __call(resolveMaxToolCallRounds, {
276
+ type: "positional",
277
+ args: [null, true]
278
+ }), 50)
279
+ });
280
+ return;
281
+ });
282
+ });
283
+ if (runner.halted) return runner.haltResult;
284
+ await runner.hook(2, async () => {
285
+ await callHook({
286
+ name: "onNodeEnd",
287
+ data: {
288
+ nodeName: "oneShotDefaults50",
289
+ data: void 0
290
+ }
291
+ });
292
+ });
293
+ return {
294
+ messages: __threads(),
295
+ data: void 0
296
+ };
297
+ } catch (__error) {
298
+ if (__error instanceof RestoreSignal) {
299
+ throw __error;
300
+ }
301
+ if (__error instanceof AgencyAbort) {
302
+ throw __error;
303
+ }
304
+ {
305
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
306
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
307
+ const __log = __createLogger(__ctx.logLevel);
308
+ __log.error(`Node oneShotDefaults50 crashed: ${__errMsg}`);
309
+ if (__errStack) __log.error(__errStack);
310
+ __ctx.statelogClient?.error?.({
311
+ errorType: "runtimeError",
312
+ message: __errMsg,
313
+ functionName: "oneShotDefaults50"
314
+ });
315
+ }
316
+ return {
317
+ messages: __threads(),
318
+ data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "oneShotDefaults50" })
319
+ };
320
+ }
321
+ });
322
+ graph.node("explicitWinsOverInteractive", async (__state) => {
323
+ const __setupData = setupNode({
324
+ state: __state
325
+ });
326
+ const __stack = __setupData.stack;
327
+ const __step = __setupData.step;
328
+ const __self = __setupData.self;
329
+ const __ctx = getRuntimeContext().ctx;
330
+ let __forked;
331
+ let __functionCompleted = false;
332
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "explicitWinsOverInteractive", threads: __setupData.threads });
333
+ try {
334
+ await agencyStore.run({
335
+ ...getRuntimeContext(),
336
+ ctx: __ctx,
337
+ stack: __ctx.stateStack,
338
+ threads: __setupData.threads
339
+ }, async () => {
340
+ await runner.hook(0, async () => {
341
+ await callHook({
342
+ name: "onNodeStart",
343
+ data: {
344
+ nodeName: "explicitWinsOverInteractive"
345
+ }
346
+ });
347
+ });
348
+ await runner.step(1, async (runner2) => {
349
+ __self.__retryable = false;
350
+ runner2.halt({
351
+ messages: __threads(),
352
+ data: __eq(await __call(resolveMaxToolCallRounds, {
353
+ type: "positional",
354
+ args: [3, false]
355
+ }), 3)
356
+ });
357
+ return;
358
+ });
359
+ });
360
+ if (runner.halted) return runner.haltResult;
361
+ await runner.hook(2, async () => {
362
+ await callHook({
363
+ name: "onNodeEnd",
364
+ data: {
365
+ nodeName: "explicitWinsOverInteractive",
366
+ data: void 0
367
+ }
368
+ });
369
+ });
370
+ return {
371
+ messages: __threads(),
372
+ data: void 0
373
+ };
374
+ } catch (__error) {
375
+ if (__error instanceof RestoreSignal) {
376
+ throw __error;
377
+ }
378
+ if (__error instanceof AgencyAbort) {
379
+ throw __error;
380
+ }
381
+ {
382
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
383
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
384
+ const __log = __createLogger(__ctx.logLevel);
385
+ __log.error(`Node explicitWinsOverInteractive crashed: ${__errMsg}`);
386
+ if (__errStack) __log.error(__errStack);
387
+ __ctx.statelogClient?.error?.({
388
+ errorType: "runtimeError",
389
+ message: __errMsg,
390
+ functionName: "explicitWinsOverInteractive"
391
+ });
392
+ }
393
+ return {
394
+ messages: __threads(),
395
+ data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "explicitWinsOverInteractive" })
396
+ };
397
+ }
398
+ });
399
+ graph.node("interactiveKeepsBaked", async (__state) => {
400
+ const __setupData = setupNode({
401
+ state: __state
402
+ });
403
+ const __stack = __setupData.stack;
404
+ const __step = __setupData.step;
405
+ const __self = __setupData.self;
406
+ const __ctx = getRuntimeContext().ctx;
407
+ let __forked;
408
+ let __functionCompleted = false;
409
+ const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "interactiveKeepsBaked", threads: __setupData.threads });
410
+ try {
411
+ await agencyStore.run({
412
+ ...getRuntimeContext(),
413
+ ctx: __ctx,
414
+ stack: __ctx.stateStack,
415
+ threads: __setupData.threads
416
+ }, async () => {
417
+ await runner.hook(0, async () => {
418
+ await callHook({
419
+ name: "onNodeStart",
420
+ data: {
421
+ nodeName: "interactiveKeepsBaked"
422
+ }
423
+ });
424
+ });
425
+ await runner.step(1, async (runner2) => {
426
+ __self.__retryable = false;
427
+ runner2.halt({
428
+ messages: __threads(),
429
+ data: __eq(await __call(resolveMaxToolCallRounds, {
430
+ type: "positional",
431
+ args: [null, false]
432
+ }), null)
433
+ });
434
+ return;
435
+ });
436
+ });
437
+ if (runner.halted) return runner.haltResult;
438
+ await runner.hook(2, async () => {
439
+ await callHook({
440
+ name: "onNodeEnd",
441
+ data: {
442
+ nodeName: "interactiveKeepsBaked",
443
+ data: void 0
444
+ }
445
+ });
446
+ });
447
+ return {
448
+ messages: __threads(),
449
+ data: void 0
450
+ };
451
+ } catch (__error) {
452
+ if (__error instanceof RestoreSignal) {
453
+ throw __error;
454
+ }
455
+ if (__error instanceof AgencyAbort) {
456
+ throw __error;
457
+ }
458
+ {
459
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
460
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
461
+ const __log = __createLogger(__ctx.logLevel);
462
+ __log.error(`Node interactiveKeepsBaked crashed: ${__errMsg}`);
463
+ if (__errStack) __log.error(__errStack);
464
+ __ctx.statelogClient?.error?.({
465
+ errorType: "runtimeError",
466
+ message: __errMsg,
467
+ functionName: "interactiveKeepsBaked"
468
+ });
469
+ }
470
+ return {
471
+ messages: __threads(),
472
+ data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "interactiveKeepsBaked" })
473
+ };
474
+ }
475
+ });
476
+ async function explicitWinsOverOneShot({ messages, callbacks } = {}) {
477
+ return runNode({
478
+ ctx: __globalCtx,
479
+ nodeName: "explicitWinsOverOneShot",
480
+ data: {},
481
+ messages,
482
+ callbacks,
483
+ initializeGlobals: __initializeGlobals,
484
+ registerTopLevelCallbacks: __registerTopLevelCallbacks,
485
+ moduleDir: __dirname
486
+ });
487
+ }
488
+ const __explicitWinsOverOneShotNodeParams = [];
489
+ async function oneShotDefaults50({ messages, callbacks } = {}) {
490
+ return runNode({
491
+ ctx: __globalCtx,
492
+ nodeName: "oneShotDefaults50",
493
+ data: {},
494
+ messages,
495
+ callbacks,
496
+ initializeGlobals: __initializeGlobals,
497
+ registerTopLevelCallbacks: __registerTopLevelCallbacks,
498
+ moduleDir: __dirname
499
+ });
500
+ }
501
+ const __oneShotDefaults50NodeParams = [];
502
+ async function explicitWinsOverInteractive({ messages, callbacks } = {}) {
503
+ return runNode({
504
+ ctx: __globalCtx,
505
+ nodeName: "explicitWinsOverInteractive",
506
+ data: {},
507
+ messages,
508
+ callbacks,
509
+ initializeGlobals: __initializeGlobals,
510
+ registerTopLevelCallbacks: __registerTopLevelCallbacks,
511
+ moduleDir: __dirname
512
+ });
513
+ }
514
+ const __explicitWinsOverInteractiveNodeParams = [];
515
+ async function interactiveKeepsBaked({ messages, callbacks } = {}) {
516
+ return runNode({
517
+ ctx: __globalCtx,
518
+ nodeName: "interactiveKeepsBaked",
519
+ data: {},
520
+ messages,
521
+ callbacks,
522
+ initializeGlobals: __initializeGlobals,
523
+ registerTopLevelCallbacks: __registerTopLevelCallbacks,
524
+ moduleDir: __dirname
525
+ });
526
+ }
527
+ const __interactiveKeepsBakedNodeParams = [];
528
+ var stdin_default = graph;
529
+ const __sourceMap = { "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:explicitWinsOverOneShot": { "1": { "line": 6, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:oneShotDefaults50": { "1": { "line": 10, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:explicitWinsOverInteractive": { "1": { "line": 14, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:interactiveKeepsBaked": { "1": { "line": 18, "col": 2 } } };
530
+ export {
531
+ __explicitWinsOverInteractiveNodeParams,
532
+ __explicitWinsOverOneShotNodeParams,
533
+ __getCheckpoints,
534
+ __interactiveKeepsBakedNodeParams,
535
+ __invokeFunction,
536
+ __oneShotDefaults50NodeParams,
537
+ __setDebugger,
538
+ __setLLMClient,
539
+ __setTraceFile,
540
+ __sourceMap,
541
+ __toolRegistry,
542
+ approve,
543
+ stdin_default as default,
544
+ explicitWinsOverInteractive,
545
+ explicitWinsOverOneShot,
546
+ hasInterrupts,
547
+ interactiveKeepsBaked,
548
+ interrupt,
549
+ isDebugger,
550
+ isInterrupt,
551
+ oneShotDefaults50,
552
+ reject,
553
+ respondToInterrupts,
554
+ rewindFrom
555
+ };
@@ -0,0 +1,9 @@
1
+ {
2
+ "sourceFile": "oneShotRounds.agency",
3
+ "tests": [
4
+ { "nodeName": "explicitWinsOverOneShot", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
5
+ { "nodeName": "oneShotDefaults50", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
6
+ { "nodeName": "explicitWinsOverInteractive", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
7
+ { "nodeName": "interactiveKeepsBaked", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] }
8
+ ]
9
+ }
@@ -364,7 +364,7 @@ ${__stack.locals.typeErrors}
364
364
  });
365
365
  await runner.step(11, async (runner2) => {
366
366
  });
367
- await runner.thread(12, "create", {}, async (runner2) => {
367
+ await runner.thread(12, "create", async () => ({}), async (runner2) => {
368
368
  await runner2.step(0, async (runner3) => {
369
369
  __self.__retryable = false;
370
370
  const __funcResult = await __call(systemMessage, {
@@ -483,7 +483,7 @@ ${__stack.locals.typeErrors}`;
483
483
  return;
484
484
  }
485
485
  });
486
- await runner2.loop(1, __stack.locals.review.strengths, async (strength, _, runner3) => {
486
+ await runner2.loop(1, async () => __stack.locals.review.strengths, async (strength, _, runner3) => {
487
487
  await runner3.step(0, async (runner4) => {
488
488
  const __funcResult = await __call(print, {
489
489
  type: "positional",
@@ -521,7 +521,7 @@ ${__stack.locals.typeErrors}`;
521
521
  return;
522
522
  }
523
523
  });
524
- await runner2.loop(1, __stack.locals.review.issues, async (issue, _, runner3) => {
524
+ await runner2.loop(1, async () => __stack.locals.review.issues, async (issue, _, runner3) => {
525
525
  await runner3.step(0, async (runner4) => {
526
526
  __stack.locals.prefix = `[${issue.severity}]`;
527
527
  });
@@ -1,5 +1,13 @@
1
1
  import { AgencyConfig } from "../config.js";
2
2
  export declare function buildDoctorPrompt(file: string, symptom?: string): string;
3
+ export declare function buildDoctorArgs(opts: {
4
+ file: string;
5
+ symptom?: string;
6
+ trace?: string | true;
7
+ logFile?: string;
8
+ }): string[];
3
9
  export declare function doctor(config: AgencyConfig, file: string, opts?: {
4
10
  symptom?: string;
11
+ trace?: string | true;
12
+ logFile?: string;
5
13
  }): void;
@@ -26,18 +26,26 @@ export function buildDoctorPrompt(file, symptom) {
26
26
  "re-run `typecheck` to confirm the file is clean.",
27
27
  ].join("\n");
28
28
  }
29
- // `agency doctor <file> [--symptom <text>]` — launch the agency agent in
30
- // interactive mode, seeded with a diagnosis prompt routed to the code
31
- // subagent. A thin wrapper over the generic --interactive/--agent flags.
29
+ // Build the argv forwarded to the bundled agent. Kept pure and exported so
30
+ // the flag assembly can be unit-tested without launching the agent. Debug
31
+ // flags go BEFORE the `--` terminator (tokens after `--` are positionals to
32
+ // the agent's std::args parser); the prompt is the sole positional after it.
33
+ export function buildDoctorArgs(opts) {
34
+ const prompt = buildDoctorPrompt(opts.file, opts.symptom);
35
+ const debug = [];
36
+ if (opts.trace !== undefined) {
37
+ debug.push("--trace");
38
+ if (typeof opts.trace === "string")
39
+ debug.push(opts.trace);
40
+ }
41
+ if (opts.logFile)
42
+ debug.push("--log-file", opts.logFile);
43
+ return ["--interactive", "--agent", "code", ...debug, "--", prompt];
44
+ }
45
+ // `agency doctor <file> [--symptom <text>] [--trace [file]] [--log-file <path>]`
46
+ // — launch the agency agent in interactive mode, seeded with a diagnosis prompt
47
+ // routed to the code subagent. A thin wrapper over the generic
48
+ // --interactive/--agent flags.
32
49
  export function doctor(config, file, opts = {}) {
33
- const prompt = buildDoctorPrompt(file, opts.symptom);
34
- // `--` ends flag parsing so the prompt (which may start with `-`) is
35
- // treated as a positional by the agent's std::args parser.
36
- runBundledAgent(config, "agency-agent", [
37
- "--interactive",
38
- "--agent",
39
- "code",
40
- "--",
41
- prompt,
42
- ]);
50
+ runBundledAgent(config, "agency-agent", buildDoctorArgs({ file, ...opts }));
43
51
  }
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { buildDoctorArgs } from "./doctor.js";
3
+ describe("buildDoctorArgs", () => {
4
+ it("appends --trace / --log-file before the -- terminator", () => {
5
+ const args = buildDoctorArgs({
6
+ file: "x.agency",
7
+ symptom: "boom",
8
+ trace: "t.trace",
9
+ logFile: "l.jsonl",
10
+ });
11
+ const dashDash = args.indexOf("--");
12
+ expect(dashDash).toBeGreaterThan(-1);
13
+ expect(args.indexOf("--trace")).toBeGreaterThan(-1);
14
+ expect(args.indexOf("--trace")).toBeLessThan(dashDash);
15
+ expect(args.indexOf("--log-file")).toBeLessThan(dashDash);
16
+ expect(args.slice(args.indexOf("--trace"), args.indexOf("--trace") + 2)).toEqual([
17
+ "--trace",
18
+ "t.trace",
19
+ ]);
20
+ });
21
+ it("bare --trace appends just the flag before --", () => {
22
+ const args = buildDoctorArgs({ file: "x.agency", trace: true });
23
+ expect(args.filter((a) => a === "--trace")).toHaveLength(1);
24
+ expect(args.indexOf("--trace")).toBeLessThan(args.indexOf("--"));
25
+ // No stray value token after a bare --trace.
26
+ expect(args[args.indexOf("--trace") + 1]).toBe("--");
27
+ });
28
+ it("omits the debug flags entirely when not requested", () => {
29
+ const args = buildDoctorArgs({ file: "x.agency", symptom: "boom" });
30
+ expect(args).not.toContain("--trace");
31
+ expect(args).not.toContain("--log-file");
32
+ expect(args[args.length - 2]).toBe("--");
33
+ });
34
+ });