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
package/stdlib/cli.js DELETED
@@ -1,1116 +0,0 @@
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 { _runLineRepl, _clearScreen, _termWidth, _clearHistory } from "agency-lang/stdlib-lib/cli.js";
3
- import { pushMessage as _reexport_pushMessage, clearMessages as _reexport_clearMessages } from "agency-lang/stdlib/ui.js";
4
- import { fileURLToPath } from "url";
5
- import __process from "process";
6
- import { z } from "agency-lang/zod";
7
- import { nanoid } from "agency-lang";
8
- import path from "path";
9
- import {
10
- RuntimeContext,
11
- Runner,
12
- setupFunction,
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
- isFailure,
30
- AgencyFunction as __AgencyFunction,
31
- UNSET as __UNSET,
32
- __call,
33
- __callMethod,
34
- __stateStack,
35
- __globals,
36
- getRuntimeContext,
37
- agencyStore,
38
- functionRefReviver as __functionRefReviver,
39
- DeterministicClient as __DeterministicClient,
40
- createLogger as __createLogger
41
- } from "agency-lang/runtime";
42
- const __filename = fileURLToPath(import.meta.url);
43
- const __dirname = path.dirname(__filename);
44
- const __cwd = __process.cwd();
45
- const getDirname = () => __dirname;
46
- const __globalCtx = new RuntimeContext({
47
- statelogConfig: {
48
- host: "https://statelog.adit.io",
49
- apiKey: __process.env["STATELOG_API_KEY"] || "",
50
- projectId: "agency-lang",
51
- debugMode: false,
52
- observability: true,
53
- logFile: "log.jsonl"
54
- },
55
- smoltalkDefaults: {
56
- apiKey: {
57
- openAi: __process.env["OPENAI_API_KEY"] || "",
58
- google: __process.env["GEMINI_API_KEY"] || "",
59
- anthropic: __process.env["ANTHROPIC_API_KEY"] || "",
60
- openRouter: __process.env["OPENROUTER_API_KEY"] || "",
61
- deepInfra: __process.env["DEEPINFRA_API_KEY"] || "",
62
- liteLlm: __process.env["LITELLM_API_KEY"] || "",
63
- openAiCompat: __process.env["OPENAI_COMPAT_API_KEY"] || ""
64
- },
65
- baseUrl: {
66
- liteLlm: __process.env["LITELLM_BASE_URL"] || "",
67
- openAiCompat: __process.env["OPENAI_COMPAT_BASE_URL"] || ""
68
- },
69
- model: "gpt-4o-mini",
70
- logLevel: "warn",
71
- statelog: {
72
- host: "https://statelog.adit.io",
73
- projectId: "smoltalk",
74
- apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
75
- traceId: nanoid()
76
- }
77
- },
78
- dirname: __dirname,
79
- logLevel: "info",
80
- traceConfig: {
81
- program: "stdlib/cli.agency"
82
- }
83
- });
84
- const graph = __globalCtx.graph;
85
- function approve(value) {
86
- return { type: "approve", value };
87
- }
88
- function reject(value) {
89
- return { type: "reject", value };
90
- }
91
- function propagate() {
92
- return { type: "propagate" };
93
- }
94
- const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
95
- const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
96
- const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
97
- const __setDebugger = (dbg) => {
98
- __globalCtx.debuggerState = dbg;
99
- };
100
- const __setTraceFile = (filePath) => {
101
- __globalCtx.traceConfig.traceFile = filePath;
102
- };
103
- const __setLLMClient = (client) => {
104
- __globalCtx.setLLMClient(client);
105
- };
106
- const __getCheckpoints = () => __globalCtx.checkpoints;
107
- if (__process.env.AGENCY_LLM_MOCKS) {
108
- __globalCtx.setLLMClient(
109
- new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
110
- );
111
- }
112
- const __toolRegistry = __functionRefReviver.registry ??= {};
113
- function __registerTool(value, _aliasName) {
114
- if (__AgencyFunction.isAgencyFunction(value)) {
115
- __toolRegistry[`${value.module}:${value.name}`] = value;
116
- }
117
- }
118
- const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
119
- const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
120
- 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);
121
- 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 }], toolDefinition: null }, __toolRegistry);
122
- function setLLMClient(client) {
123
- __globalCtx.setLLMClient(client);
124
- }
125
- function registerTools(tools) {
126
- for (const tool of tools) {
127
- if (__AgencyFunction.isAgencyFunction(tool)) {
128
- __toolRegistry[`${tool.module}:${tool.name}`] = tool;
129
- }
130
- }
131
- }
132
- __registerTool(print);
133
- __registerTool(printJSON);
134
- __registerTool(parseJSON);
135
- __registerTool(input);
136
- __registerTool(sleep);
137
- __registerTool(round);
138
- __registerTool(read);
139
- __registerTool(write);
140
- __registerTool(readImage);
141
- __registerTool(notify);
142
- __registerTool(range);
143
- __registerTool(mostCommon);
144
- __registerTool(keys);
145
- __registerTool(values);
146
- __registerTool(entries);
147
- __registerTool(emit);
148
- __registerTool(callback);
149
- __registerTool(_reexport_pushMessage);
150
- __registerTool(_reexport_clearMessages);
151
- async function __initializeGlobals(__ctx) {
152
- if (__ctx.globals.isInitialized("stdlib/cli.agency")) {
153
- return;
154
- }
155
- __ctx.globals.markInitialized("stdlib/cli.agency");
156
- __ctx.globals.set("stdlib/cli.agency", "_historyFile", ``);
157
- }
158
- __registerGlobalsInit("stdlib/cli.agency", __initializeGlobals);
159
- async function __registerTopLevelCallbacks(__ctx) {
160
- __ctx.topLevelCallbacks = [];
161
- }
162
- __functionRefReviver.registry = __toolRegistry;
163
- async function __pushMessage_impl(message) {
164
- const __setupData = setupFunction();
165
- const __stack = __setupData.stack;
166
- const __step = __setupData.step;
167
- const __self = __setupData.self;
168
- const __ctx = getRuntimeContext().ctx;
169
- let __forked;
170
- let __functionCompleted = false;
171
- if (!__globals().isInitialized("stdlib/cli.agency")) {
172
- await __initializeGlobals(__ctx);
173
- }
174
- let __funcStartTime = performance.now();
175
- __stack.args["message"] = message;
176
- __self.__retryable = __self.__retryable ?? true;
177
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "pushMessage", threads: __setupData.threads });
178
- let __resultCheckpointId = -1;
179
- if (__ctx._pendingArgOverrides) {
180
- const __overrides = __ctx._pendingArgOverrides;
181
- __ctx._pendingArgOverrides = void 0;
182
- if ("message" in __overrides) {
183
- message = __overrides["message"];
184
- __stack.args["message"] = message;
185
- }
186
- }
187
- try {
188
- await agencyStore.run({
189
- ...getRuntimeContext(),
190
- ctx: __ctx,
191
- stack: __setupData.stateStack,
192
- threads: __setupData.threads
193
- }, async () => {
194
- await runner.hook(0, async () => {
195
- await callHook({
196
- name: "onFunctionStart",
197
- data: {
198
- functionName: "pushMessage",
199
- args: {
200
- message
201
- },
202
- isBuiltin: false,
203
- moduleId: "stdlib/cli.agency"
204
- }
205
- });
206
- });
207
- await runner.step(1, async (runner2) => {
208
- __self.__retryable = false;
209
- __functionCompleted = true;
210
- runner2.halt(await __call(_reexport_pushMessage, {
211
- type: "positional",
212
- args: [__stack.args.message]
213
- }));
214
- return;
215
- });
216
- });
217
- if (runner.halted) {
218
- if (isFailure(runner.haltResult)) {
219
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
220
- }
221
- return runner.haltResult;
222
- }
223
- } catch (__error) {
224
- if (__error instanceof RestoreSignal) {
225
- throw __error;
226
- }
227
- if (__error instanceof AgencyAbort) {
228
- throw __error;
229
- }
230
- {
231
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
232
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
233
- const __log = __createLogger(__ctx.logLevel);
234
- __log.error("Function pushMessage threw an exception (converted to Failure): " + __errMsg);
235
- if (__errStack) __log.error(__errStack);
236
- __ctx.statelogClient?.error?.({
237
- errorType: "runtimeError",
238
- message: __errMsg,
239
- functionName: "pushMessage",
240
- retryable: __self.__retryable
241
- });
242
- }
243
- return failure(
244
- __error instanceof Error ? __error.message : String(__error),
245
- {
246
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
247
- retryable: __self.__retryable,
248
- functionName: "pushMessage",
249
- args: __stack.args
250
- }
251
- );
252
- } finally {
253
- __stateStack()?.pop();
254
- if (__functionCompleted) {
255
- await callHook({
256
- name: "onFunctionEnd",
257
- data: {
258
- functionName: "pushMessage",
259
- timeTaken: performance.now() - __funcStartTime
260
- }
261
- });
262
- }
263
- }
264
- }
265
- const pushMessage = __AgencyFunction.create({
266
- name: "pushMessage",
267
- module: "stdlib/cli.agency",
268
- fn: __pushMessage_impl,
269
- params: [{
270
- name: "message",
271
- hasDefault: false,
272
- defaultValue: void 0,
273
- variadic: false,
274
- isFunctionTyped: false
275
- }],
276
- toolDefinition: {
277
- name: "pushMessage",
278
- description: "No description provided.",
279
- schema: z.object({ "message": z.string() })
280
- },
281
- safe: false,
282
- exported: true
283
- }, __toolRegistry);
284
- async function __clearMessages_impl() {
285
- const __setupData = setupFunction();
286
- const __stack = __setupData.stack;
287
- const __step = __setupData.step;
288
- const __self = __setupData.self;
289
- const __ctx = getRuntimeContext().ctx;
290
- let __forked;
291
- let __functionCompleted = false;
292
- if (!__globals().isInitialized("stdlib/cli.agency")) {
293
- await __initializeGlobals(__ctx);
294
- }
295
- let __funcStartTime = performance.now();
296
- __self.__retryable = __self.__retryable ?? true;
297
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "clearMessages", threads: __setupData.threads });
298
- let __resultCheckpointId = -1;
299
- if (__ctx._pendingArgOverrides) {
300
- const __overrides = __ctx._pendingArgOverrides;
301
- __ctx._pendingArgOverrides = void 0;
302
- }
303
- try {
304
- await agencyStore.run({
305
- ...getRuntimeContext(),
306
- ctx: __ctx,
307
- stack: __setupData.stateStack,
308
- threads: __setupData.threads
309
- }, async () => {
310
- await runner.hook(0, async () => {
311
- await callHook({
312
- name: "onFunctionStart",
313
- data: {
314
- functionName: "clearMessages",
315
- args: {},
316
- isBuiltin: false,
317
- moduleId: "stdlib/cli.agency"
318
- }
319
- });
320
- });
321
- await runner.step(1, async (runner2) => {
322
- __self.__retryable = false;
323
- __functionCompleted = true;
324
- runner2.halt(await __call(_reexport_clearMessages, {
325
- type: "positional",
326
- args: []
327
- }));
328
- return;
329
- });
330
- });
331
- if (runner.halted) {
332
- if (isFailure(runner.haltResult)) {
333
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
334
- }
335
- return runner.haltResult;
336
- }
337
- } catch (__error) {
338
- if (__error instanceof RestoreSignal) {
339
- throw __error;
340
- }
341
- if (__error instanceof AgencyAbort) {
342
- throw __error;
343
- }
344
- {
345
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
346
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
347
- const __log = __createLogger(__ctx.logLevel);
348
- __log.error("Function clearMessages threw an exception (converted to Failure): " + __errMsg);
349
- if (__errStack) __log.error(__errStack);
350
- __ctx.statelogClient?.error?.({
351
- errorType: "runtimeError",
352
- message: __errMsg,
353
- functionName: "clearMessages",
354
- retryable: __self.__retryable
355
- });
356
- }
357
- return failure(
358
- __error instanceof Error ? __error.message : String(__error),
359
- {
360
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
361
- retryable: __self.__retryable,
362
- functionName: "clearMessages",
363
- args: __stack.args
364
- }
365
- );
366
- } finally {
367
- __stateStack()?.pop();
368
- if (__functionCompleted) {
369
- await callHook({
370
- name: "onFunctionEnd",
371
- data: {
372
- functionName: "clearMessages",
373
- timeTaken: performance.now() - __funcStartTime
374
- }
375
- });
376
- }
377
- }
378
- }
379
- const clearMessages = __AgencyFunction.create({
380
- name: "clearMessages",
381
- module: "stdlib/cli.agency",
382
- fn: __clearMessages_impl,
383
- params: [],
384
- toolDefinition: {
385
- name: "clearMessages",
386
- description: "No description provided.",
387
- schema: z.object({})
388
- },
389
- safe: false,
390
- exported: true
391
- }, __toolRegistry);
392
- async function __repl_impl(status, onSubmit, prompt = __UNSET, historyFile = __UNSET, historyMax = __UNSET, paletteCommands = __UNSET) {
393
- const __setupData = setupFunction();
394
- const __stack = __setupData.stack;
395
- const __step = __setupData.step;
396
- const __self = __setupData.self;
397
- const __ctx = getRuntimeContext().ctx;
398
- let __forked;
399
- let __functionCompleted = false;
400
- if (!__globals().isInitialized("stdlib/cli.agency")) {
401
- await __initializeGlobals(__ctx);
402
- }
403
- let __funcStartTime = performance.now();
404
- __stack.args["status"] = status;
405
- __stack.args["onSubmit"] = onSubmit;
406
- __stack.args["prompt"] = prompt === __UNSET ? `> ` : prompt;
407
- __stack.args["historyFile"] = historyFile === __UNSET ? `` : historyFile;
408
- __stack.args["historyMax"] = historyMax === __UNSET ? 1e3 : historyMax;
409
- __stack.args["paletteCommands"] = paletteCommands === __UNSET ? null : paletteCommands;
410
- __self.__retryable = __self.__retryable ?? true;
411
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "repl", threads: __setupData.threads });
412
- let __resultCheckpointId = -1;
413
- if (__ctx._pendingArgOverrides) {
414
- const __overrides = __ctx._pendingArgOverrides;
415
- __ctx._pendingArgOverrides = void 0;
416
- if ("status" in __overrides) {
417
- status = __overrides["status"];
418
- __stack.args["status"] = status;
419
- }
420
- if ("onSubmit" in __overrides) {
421
- onSubmit = __overrides["onSubmit"];
422
- __stack.args["onSubmit"] = onSubmit;
423
- }
424
- if ("prompt" in __overrides) {
425
- prompt = __overrides["prompt"];
426
- __stack.args["prompt"] = prompt;
427
- }
428
- if ("historyFile" in __overrides) {
429
- historyFile = __overrides["historyFile"];
430
- __stack.args["historyFile"] = historyFile;
431
- }
432
- if ("historyMax" in __overrides) {
433
- historyMax = __overrides["historyMax"];
434
- __stack.args["historyMax"] = historyMax;
435
- }
436
- if ("paletteCommands" in __overrides) {
437
- paletteCommands = __overrides["paletteCommands"];
438
- __stack.args["paletteCommands"] = paletteCommands;
439
- }
440
- }
441
- try {
442
- await agencyStore.run({
443
- ...getRuntimeContext(),
444
- ctx: __ctx,
445
- stack: __setupData.stateStack,
446
- threads: __setupData.threads
447
- }, async () => {
448
- await runner.hook(0, async () => {
449
- await callHook({
450
- name: "onFunctionStart",
451
- data: {
452
- functionName: "repl",
453
- args: {
454
- status,
455
- onSubmit,
456
- prompt,
457
- historyFile,
458
- historyMax,
459
- paletteCommands
460
- },
461
- isBuiltin: false,
462
- moduleId: "stdlib/cli.agency"
463
- }
464
- });
465
- });
466
- await runner.step(1, async (runner2) => {
467
- });
468
- await runner.step(2, async (runner2) => {
469
- __globals().set("stdlib/cli.agency", "_historyFile", __stack.args.historyFile);
470
- });
471
- await runner.step(3, async (runner2) => {
472
- __self.__retryable = false;
473
- const __funcResult = await __call(_runLineRepl, {
474
- type: "positional",
475
- args: [__stack.args.status, __stack.args.onSubmit, __stack.args.prompt, __stack.args.historyFile, __stack.args.historyMax, __stack.args.paletteCommands]
476
- });
477
- if (hasInterrupts(__funcResult)) {
478
- await getRuntimeContext().ctx.pendingPromises.awaitAll();
479
- runner2.halt(__funcResult);
480
- return;
481
- }
482
- });
483
- });
484
- if (runner.halted) {
485
- if (isFailure(runner.haltResult)) {
486
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
487
- }
488
- return runner.haltResult;
489
- }
490
- } catch (__error) {
491
- if (__error instanceof RestoreSignal) {
492
- throw __error;
493
- }
494
- if (__error instanceof AgencyAbort) {
495
- throw __error;
496
- }
497
- {
498
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
499
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
500
- const __log = __createLogger(__ctx.logLevel);
501
- __log.error("Function repl threw an exception (converted to Failure): " + __errMsg);
502
- if (__errStack) __log.error(__errStack);
503
- __ctx.statelogClient?.error?.({
504
- errorType: "runtimeError",
505
- message: __errMsg,
506
- functionName: "repl",
507
- retryable: __self.__retryable
508
- });
509
- }
510
- return failure(
511
- __error instanceof Error ? __error.message : String(__error),
512
- {
513
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
514
- retryable: __self.__retryable,
515
- functionName: "repl",
516
- args: __stack.args
517
- }
518
- );
519
- } finally {
520
- __stateStack()?.pop();
521
- if (__functionCompleted) {
522
- await callHook({
523
- name: "onFunctionEnd",
524
- data: {
525
- functionName: "repl",
526
- timeTaken: performance.now() - __funcStartTime
527
- }
528
- });
529
- }
530
- }
531
- }
532
- const repl = __AgencyFunction.create({
533
- name: "repl",
534
- module: "stdlib/cli.agency",
535
- fn: __repl_impl,
536
- params: [{
537
- name: "status",
538
- hasDefault: false,
539
- defaultValue: void 0,
540
- variadic: false,
541
- isFunctionTyped: false
542
- }, {
543
- name: "onSubmit",
544
- hasDefault: false,
545
- defaultValue: void 0,
546
- variadic: false,
547
- isFunctionTyped: false
548
- }, {
549
- name: "prompt",
550
- hasDefault: true,
551
- defaultValue: void 0,
552
- variadic: false,
553
- isFunctionTyped: false
554
- }, {
555
- name: "historyFile",
556
- hasDefault: true,
557
- defaultValue: void 0,
558
- variadic: false,
559
- isFunctionTyped: false
560
- }, {
561
- name: "historyMax",
562
- hasDefault: true,
563
- defaultValue: void 0,
564
- variadic: false,
565
- isFunctionTyped: false
566
- }, {
567
- name: "paletteCommands",
568
- hasDefault: true,
569
- defaultValue: void 0,
570
- variadic: false,
571
- isFunctionTyped: false
572
- }],
573
- toolDefinition: {
574
- name: "repl",
575
- description: `Line-mode REPL. Same call signature as \`std::ui.repl\` so swapping
576
- modes is a one-line import change in the calling agent.
577
-
578
- Per iteration: print \`prompt\`, await one line of input (via Node's
579
- \`readline\` \u2014 full line editing, history, bracketed paste), call
580
- \`onSubmit(line)\`. If \`onSubmit\` returns \`false\`, exit. If it
581
- returns a non-empty string, print the string to stdout. Anything
582
- else (e.g. the agent's \`_runTurn\` returning \`true\` after calling
583
- \`pushMessage\`) is silently ignored \u2014 the reply already reached
584
- stdout via the underlying \`print\` path.
585
-
586
- Exits on \`onSubmit\` returning \`false\`, on Ctrl+D (EOF) at the
587
- prompt, or on Ctrl+C at an idle prompt.
588
-
589
- Built-in \`/paste\` (TTY only): opens a multi-line editor (\xE0 la Node's
590
- REPL \`.editor\`). Enter inserts a newline, Ctrl+D submits the whole
591
- buffer as one message, and Ctrl+C / Esc cancels. Because Enter no
592
- longer submits while in this mode, pasting a multi-line block lands
593
- intact instead of firing one turn per line.
594
-
595
- Round-one limitations (intentional, see the spec):
596
- - \`status\` is accepted for signature parity but not yet rendered.
597
- WL2 will turn it into a per-turn footer.
598
- - \`paletteCommands\` is accepted but no tab completion yet (WL6).
599
- - No spinner during the busy window (WL3).
600
- - No Ctrl+C cancel of an in-flight turn (WL7).
601
-
602
- @param status - Callback returning {left, right, context}; reserved
603
- for the WL2 per-turn footer
604
- @param onSubmit - Called with the submitted line; return \`false\` to
605
- exit or a string to print
606
- @param prompt - String shown before the input buffer (default "> ")
607
- @param historyFile - Path to a JSON history file (array of entries);
608
- loaded at start and saved on exit. Empty string disables
609
- persistence.
610
- @param historyMax - Trim history to this many most-recent entries
611
- @param paletteCommands - Map of /cmd -> description; reserved for
612
- WL6 tab completion`,
613
- schema: z.object({ "status": z.any(), "onSubmit": z.any(), "prompt": z.string().nullable().describe("Default: > "), "historyFile": z.string().nullable().describe("Default: "), "historyMax": z.number().nullable().describe("Default: 1000"), "paletteCommands": z.any().nullable().describe("Default: null") })
614
- },
615
- safe: false,
616
- exported: true
617
- }, __toolRegistry);
618
- async function __clearScreen_impl() {
619
- const __setupData = setupFunction();
620
- const __stack = __setupData.stack;
621
- const __step = __setupData.step;
622
- const __self = __setupData.self;
623
- const __ctx = getRuntimeContext().ctx;
624
- let __forked;
625
- let __functionCompleted = false;
626
- if (!__globals().isInitialized("stdlib/cli.agency")) {
627
- await __initializeGlobals(__ctx);
628
- }
629
- let __funcStartTime = performance.now();
630
- __self.__retryable = __self.__retryable ?? true;
631
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "clearScreen", threads: __setupData.threads });
632
- let __resultCheckpointId = -1;
633
- if (__ctx._pendingArgOverrides) {
634
- const __overrides = __ctx._pendingArgOverrides;
635
- __ctx._pendingArgOverrides = void 0;
636
- }
637
- try {
638
- await agencyStore.run({
639
- ...getRuntimeContext(),
640
- ctx: __ctx,
641
- stack: __setupData.stateStack,
642
- threads: __setupData.threads
643
- }, async () => {
644
- await runner.hook(0, async () => {
645
- await callHook({
646
- name: "onFunctionStart",
647
- data: {
648
- functionName: "clearScreen",
649
- args: {},
650
- isBuiltin: false,
651
- moduleId: "stdlib/cli.agency"
652
- }
653
- });
654
- });
655
- await runner.step(1, async (runner2) => {
656
- __self.__retryable = false;
657
- const __funcResult = await __call(_clearScreen, {
658
- type: "positional",
659
- args: []
660
- });
661
- if (hasInterrupts(__funcResult)) {
662
- await getRuntimeContext().ctx.pendingPromises.awaitAll();
663
- runner2.halt(__funcResult);
664
- return;
665
- }
666
- });
667
- });
668
- if (runner.halted) {
669
- if (isFailure(runner.haltResult)) {
670
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
671
- }
672
- return runner.haltResult;
673
- }
674
- } catch (__error) {
675
- if (__error instanceof RestoreSignal) {
676
- throw __error;
677
- }
678
- if (__error instanceof AgencyAbort) {
679
- throw __error;
680
- }
681
- {
682
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
683
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
684
- const __log = __createLogger(__ctx.logLevel);
685
- __log.error("Function clearScreen threw an exception (converted to Failure): " + __errMsg);
686
- if (__errStack) __log.error(__errStack);
687
- __ctx.statelogClient?.error?.({
688
- errorType: "runtimeError",
689
- message: __errMsg,
690
- functionName: "clearScreen",
691
- retryable: __self.__retryable
692
- });
693
- }
694
- return failure(
695
- __error instanceof Error ? __error.message : String(__error),
696
- {
697
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
698
- retryable: __self.__retryable,
699
- functionName: "clearScreen",
700
- args: __stack.args
701
- }
702
- );
703
- } finally {
704
- __stateStack()?.pop();
705
- if (__functionCompleted) {
706
- await callHook({
707
- name: "onFunctionEnd",
708
- data: {
709
- functionName: "clearScreen",
710
- timeTaken: performance.now() - __funcStartTime
711
- }
712
- });
713
- }
714
- }
715
- }
716
- const clearScreen = __AgencyFunction.create({
717
- name: "clearScreen",
718
- module: "stdlib/cli.agency",
719
- fn: __clearScreen_impl,
720
- params: [],
721
- toolDefinition: {
722
- name: "clearScreen",
723
- description: "No description provided.",
724
- schema: z.object({})
725
- },
726
- safe: false,
727
- exported: true
728
- }, __toolRegistry);
729
- async function __clearHistory_impl() {
730
- const __setupData = setupFunction();
731
- const __stack = __setupData.stack;
732
- const __step = __setupData.step;
733
- const __self = __setupData.self;
734
- const __ctx = getRuntimeContext().ctx;
735
- let __forked;
736
- let __functionCompleted = false;
737
- if (!__globals().isInitialized("stdlib/cli.agency")) {
738
- await __initializeGlobals(__ctx);
739
- }
740
- let __funcStartTime = performance.now();
741
- __self.__retryable = __self.__retryable ?? true;
742
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "clearHistory", threads: __setupData.threads });
743
- let __resultCheckpointId = -1;
744
- if (__ctx._pendingArgOverrides) {
745
- const __overrides = __ctx._pendingArgOverrides;
746
- __ctx._pendingArgOverrides = void 0;
747
- }
748
- try {
749
- await agencyStore.run({
750
- ...getRuntimeContext(),
751
- ctx: __ctx,
752
- stack: __setupData.stateStack,
753
- threads: __setupData.threads
754
- }, async () => {
755
- await runner.hook(0, async () => {
756
- await callHook({
757
- name: "onFunctionStart",
758
- data: {
759
- functionName: "clearHistory",
760
- args: {},
761
- isBuiltin: false,
762
- moduleId: "stdlib/cli.agency"
763
- }
764
- });
765
- });
766
- await runner.step(1, async (runner2) => {
767
- __self.__retryable = false;
768
- const __funcResult = await __call(_clearHistory, {
769
- type: "positional",
770
- args: [__globals().get("stdlib/cli.agency", "_historyFile")]
771
- });
772
- if (hasInterrupts(__funcResult)) {
773
- await getRuntimeContext().ctx.pendingPromises.awaitAll();
774
- runner2.halt(__funcResult);
775
- return;
776
- }
777
- });
778
- });
779
- if (runner.halted) {
780
- if (isFailure(runner.haltResult)) {
781
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
782
- }
783
- return runner.haltResult;
784
- }
785
- } catch (__error) {
786
- if (__error instanceof RestoreSignal) {
787
- throw __error;
788
- }
789
- if (__error instanceof AgencyAbort) {
790
- throw __error;
791
- }
792
- {
793
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
794
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
795
- const __log = __createLogger(__ctx.logLevel);
796
- __log.error("Function clearHistory threw an exception (converted to Failure): " + __errMsg);
797
- if (__errStack) __log.error(__errStack);
798
- __ctx.statelogClient?.error?.({
799
- errorType: "runtimeError",
800
- message: __errMsg,
801
- functionName: "clearHistory",
802
- retryable: __self.__retryable
803
- });
804
- }
805
- return failure(
806
- __error instanceof Error ? __error.message : String(__error),
807
- {
808
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
809
- retryable: __self.__retryable,
810
- functionName: "clearHistory",
811
- args: __stack.args
812
- }
813
- );
814
- } finally {
815
- __stateStack()?.pop();
816
- if (__functionCompleted) {
817
- await callHook({
818
- name: "onFunctionEnd",
819
- data: {
820
- functionName: "clearHistory",
821
- timeTaken: performance.now() - __funcStartTime
822
- }
823
- });
824
- }
825
- }
826
- }
827
- const clearHistory = __AgencyFunction.create({
828
- name: "clearHistory",
829
- module: "stdlib/cli.agency",
830
- fn: __clearHistory_impl,
831
- params: [],
832
- toolDefinition: {
833
- name: "clearHistory",
834
- description: `Clear the input history of the **currently running** \`repl()\` session \u2014
835
- both its in-session up-arrow recall and the \`historyFile\` that session was
836
- started with. The file path comes from the \`_historyFile\` execution-model
837
- global (set by \`repl()\`), so the runtime remembers which file to clear; the
838
- live up-arrow recall is wiped via the active REPL. A no-op when called
839
- outside an interactive \`repl()\`.`,
840
- schema: z.object({})
841
- },
842
- safe: false,
843
- exported: true
844
- }, __toolRegistry);
845
- async function __termWidth_impl() {
846
- const __setupData = setupFunction();
847
- const __stack = __setupData.stack;
848
- const __step = __setupData.step;
849
- const __self = __setupData.self;
850
- const __ctx = getRuntimeContext().ctx;
851
- let __forked;
852
- let __functionCompleted = false;
853
- if (!__globals().isInitialized("stdlib/cli.agency")) {
854
- await __initializeGlobals(__ctx);
855
- }
856
- let __funcStartTime = performance.now();
857
- __self.__retryable = __self.__retryable ?? true;
858
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "termWidth", threads: __setupData.threads });
859
- let __resultCheckpointId = -1;
860
- if (__ctx._pendingArgOverrides) {
861
- const __overrides = __ctx._pendingArgOverrides;
862
- __ctx._pendingArgOverrides = void 0;
863
- }
864
- try {
865
- await agencyStore.run({
866
- ...getRuntimeContext(),
867
- ctx: __ctx,
868
- stack: __setupData.stateStack,
869
- threads: __setupData.threads
870
- }, async () => {
871
- await runner.hook(0, async () => {
872
- await callHook({
873
- name: "onFunctionStart",
874
- data: {
875
- functionName: "termWidth",
876
- args: {},
877
- isBuiltin: false,
878
- moduleId: "stdlib/cli.agency"
879
- }
880
- });
881
- });
882
- await runner.step(1, async (runner2) => {
883
- __functionCompleted = true;
884
- runner2.halt(await __call(_termWidth, {
885
- type: "positional",
886
- args: []
887
- }));
888
- return;
889
- });
890
- });
891
- if (runner.halted) {
892
- if (isFailure(runner.haltResult)) {
893
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
894
- }
895
- return runner.haltResult;
896
- }
897
- } catch (__error) {
898
- if (__error instanceof RestoreSignal) {
899
- throw __error;
900
- }
901
- if (__error instanceof AgencyAbort) {
902
- throw __error;
903
- }
904
- {
905
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
906
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
907
- const __log = __createLogger(__ctx.logLevel);
908
- __log.error("Function termWidth threw an exception (converted to Failure): " + __errMsg);
909
- if (__errStack) __log.error(__errStack);
910
- __ctx.statelogClient?.error?.({
911
- errorType: "runtimeError",
912
- message: __errMsg,
913
- functionName: "termWidth",
914
- retryable: __self.__retryable
915
- });
916
- }
917
- return failure(
918
- __error instanceof Error ? __error.message : String(__error),
919
- {
920
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
921
- retryable: __self.__retryable,
922
- functionName: "termWidth",
923
- args: __stack.args
924
- }
925
- );
926
- } finally {
927
- __stateStack()?.pop();
928
- if (__functionCompleted) {
929
- await callHook({
930
- name: "onFunctionEnd",
931
- data: {
932
- functionName: "termWidth",
933
- timeTaken: performance.now() - __funcStartTime
934
- }
935
- });
936
- }
937
- }
938
- }
939
- const termWidth = __AgencyFunction.create({
940
- name: "termWidth",
941
- module: "stdlib/cli.agency",
942
- fn: __termWidth_impl,
943
- params: [],
944
- toolDefinition: {
945
- name: "termWidth",
946
- description: "No description provided.",
947
- schema: z.object({})
948
- },
949
- safe: true,
950
- exported: true
951
- }, __toolRegistry);
952
- async function __hline_impl(char = __UNSET, width = __UNSET) {
953
- const __setupData = setupFunction();
954
- const __stack = __setupData.stack;
955
- const __step = __setupData.step;
956
- const __self = __setupData.self;
957
- const __ctx = getRuntimeContext().ctx;
958
- let __forked;
959
- let __functionCompleted = false;
960
- if (!__globals().isInitialized("stdlib/cli.agency")) {
961
- await __initializeGlobals(__ctx);
962
- }
963
- let __funcStartTime = performance.now();
964
- __stack.args["char"] = char === __UNSET ? `\u2500` : char;
965
- __stack.args["width"] = width === __UNSET ? null : width;
966
- __self.__retryable = __self.__retryable ?? true;
967
- const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "stdlib/cli.agency", scopeName: "hline", threads: __setupData.threads });
968
- let __resultCheckpointId = -1;
969
- if (__ctx._pendingArgOverrides) {
970
- const __overrides = __ctx._pendingArgOverrides;
971
- __ctx._pendingArgOverrides = void 0;
972
- if ("char" in __overrides) {
973
- char = __overrides["char"];
974
- __stack.args["char"] = char;
975
- }
976
- if ("width" in __overrides) {
977
- width = __overrides["width"];
978
- __stack.args["width"] = width;
979
- }
980
- }
981
- try {
982
- await agencyStore.run({
983
- ...getRuntimeContext(),
984
- ctx: __ctx,
985
- stack: __setupData.stateStack,
986
- threads: __setupData.threads
987
- }, async () => {
988
- await runner.hook(0, async () => {
989
- await callHook({
990
- name: "onFunctionStart",
991
- data: {
992
- functionName: "hline",
993
- args: {
994
- char,
995
- width
996
- },
997
- isBuiltin: false,
998
- moduleId: "stdlib/cli.agency"
999
- }
1000
- });
1001
- });
1002
- await runner.step(1, async (runner2) => {
1003
- __stack.locals._width = __stack.args.width || await __call(termWidth, {
1004
- type: "positional",
1005
- args: []
1006
- });
1007
- });
1008
- await runner.step(2, async (runner2) => {
1009
- __functionCompleted = true;
1010
- runner2.halt(await __callMethod(__stack.args.char, "repeat", {
1011
- type: "positional",
1012
- args: [__stack.locals._width]
1013
- }));
1014
- return;
1015
- });
1016
- });
1017
- if (runner.halted) {
1018
- if (isFailure(runner.haltResult)) {
1019
- runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
1020
- }
1021
- return runner.haltResult;
1022
- }
1023
- } catch (__error) {
1024
- if (__error instanceof RestoreSignal) {
1025
- throw __error;
1026
- }
1027
- if (__error instanceof AgencyAbort) {
1028
- throw __error;
1029
- }
1030
- {
1031
- const __errMsg = __error instanceof Error ? __error.message : String(__error);
1032
- const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
1033
- const __log = __createLogger(__ctx.logLevel);
1034
- __log.error("Function hline threw an exception (converted to Failure): " + __errMsg);
1035
- if (__errStack) __log.error(__errStack);
1036
- __ctx.statelogClient?.error?.({
1037
- errorType: "runtimeError",
1038
- message: __errMsg,
1039
- functionName: "hline",
1040
- retryable: __self.__retryable
1041
- });
1042
- }
1043
- return failure(
1044
- __error instanceof Error ? __error.message : String(__error),
1045
- {
1046
- checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
1047
- retryable: __self.__retryable,
1048
- functionName: "hline",
1049
- args: __stack.args
1050
- }
1051
- );
1052
- } finally {
1053
- __stateStack()?.pop();
1054
- if (__functionCompleted) {
1055
- await callHook({
1056
- name: "onFunctionEnd",
1057
- data: {
1058
- functionName: "hline",
1059
- timeTaken: performance.now() - __funcStartTime
1060
- }
1061
- });
1062
- }
1063
- }
1064
- }
1065
- const hline = __AgencyFunction.create({
1066
- name: "hline",
1067
- module: "stdlib/cli.agency",
1068
- fn: __hline_impl,
1069
- params: [{
1070
- name: "char",
1071
- hasDefault: true,
1072
- defaultValue: void 0,
1073
- variadic: false,
1074
- isFunctionTyped: false
1075
- }, {
1076
- name: "width",
1077
- hasDefault: true,
1078
- defaultValue: void 0,
1079
- variadic: false,
1080
- isFunctionTyped: false
1081
- }],
1082
- toolDefinition: {
1083
- name: "hline",
1084
- description: "No description provided.",
1085
- schema: z.object({ "char": z.string().nullable().describe("Default: \u2500"), "width": z.number().nullable().describe("Default: null") })
1086
- },
1087
- safe: true,
1088
- exported: true
1089
- }, __toolRegistry);
1090
- var stdin_default = graph;
1091
- const __sourceMap = { "stdlib/cli.agency:pushMessage": { "1": { "line": 61, "col": 0 } }, "stdlib/cli.agency:clearMessages": { "1": { "line": 61, "col": 0 } }, "stdlib/cli.agency:repl": { "2": { "line": 119, "col": 2 }, "3": { "line": 120, "col": 2 } }, "stdlib/cli.agency:clearScreen": { "1": { "line": 131, "col": 2 } }, "stdlib/cli.agency:clearHistory": { "1": { "line": 141, "col": 2 } }, "stdlib/cli.agency:termWidth": { "1": { "line": 145, "col": 2 } }, "stdlib/cli.agency:hline": { "1": { "line": 149, "col": 2 }, "2": { "line": 150, "col": 2 } } };
1092
- export {
1093
- __getCheckpoints,
1094
- __invokeFunction,
1095
- __setDebugger,
1096
- __setLLMClient,
1097
- __setTraceFile,
1098
- __sourceMap,
1099
- __toolRegistry,
1100
- approve,
1101
- clearHistory,
1102
- clearMessages,
1103
- clearScreen,
1104
- stdin_default as default,
1105
- hasInterrupts,
1106
- hline,
1107
- interrupt,
1108
- isDebugger,
1109
- isInterrupt,
1110
- pushMessage,
1111
- reject,
1112
- repl,
1113
- respondToInterrupts,
1114
- rewindFrom,
1115
- termWidth
1116
- };