agency-lang 0.7.2 → 0.7.4

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.
@@ -11,7 +11,7 @@ import { gitStatus, gitLog, gitDiff, gitShow, gitBranchList, gitRemoteList, gitB
11
11
  import { skillsDir } from "agency-lang/stdlib/skills.js";
12
12
  import { systemMessage } from "agency-lang/stdlib/thread.js";
13
13
  import { agentNames } from "../lib/config.js";
14
- import { withWebSearch } from "../lib/search.js";
14
+ import { withWebSearch, getSearchBackend } from "../lib/search.js";
15
15
  import { oracleAgent } from "./oracle.js";
16
16
  import { review, renderFeedback, feedbackHasErrors } from "./review.js";
17
17
  import { fileURLToPath } from "url";
@@ -214,6 +214,7 @@ __registerTool(skillsDir);
214
214
  __registerTool(systemMessage);
215
215
  __registerTool(agentNames);
216
216
  __registerTool(withWebSearch);
217
+ __registerTool(getSearchBackend);
217
218
  __registerTool(oracleAgent);
218
219
  __registerTool(review);
219
220
  __registerTool(renderFeedback);
@@ -224,6 +225,8 @@ let docSkill = __UNINIT_STATIC;
224
225
  let cliSkill = __UNINIT_STATIC;
225
226
  let codeSysPrompt = __UNINIT_STATIC;
226
227
  let codeTools = __UNINIT_STATIC;
228
+ let WEB_SEARCH_NOTE = __UNINIT_STATIC;
229
+ let ONE_SHOT_NOTE = __UNINIT_STATIC;
227
230
  async function __initializeStatic(__ctx) {
228
231
  if (__staticInitPromise) {
229
232
  return __staticInitPromise;
@@ -261,30 +264,16 @@ You are the **code specialist** of a multi-thread Agency-language
261
264
  assistant. You handle anything that touches code or the file system:
262
265
  writing, editing, running, and typechecking Agency or shell code.
263
266
 
264
- You do NOT have access to web search, Wikipedia,
265
- or URL fetching. If the user asks a question that needs research,
266
- do one of the following:
267
+ For Agency-language questions (syntax, control flow, types, the CLI),
268
+ call the bundled docs tools \u2014 they are authoritative for Agency:
269
+ * \`docSkill\` \u2014 the language guide (syntax, types, error handling,
270
+ built-ins, callbacks, advanced types)
271
+ * \`cliSkill\` \u2014 the CLI reference (\`agency run\`, \`agency test\`, ...)
272
+ Pick whichever matches the question rather than guessing.
267
273
 
268
- - If the research involves Agency features of syntax:
269
- - call the bundled docs tools first \u2014 they're authoritative:
270
- * \`docSkill\` \u2014 language guide (syntax, control flow,
271
- types, error handling, etc.),
272
- built-ins, callbacks, advanced types
273
- * \`cliSkill\` \u2014 CLI reference (\`agency run\`, \`agency test\`,
274
- \`agency compile\`, ...)
275
- Pick whichever matches the question rather than guessing.
276
-
277
- - If the research involves something else (a research question,
278
- an external API, a Wikipedia summary, or a URL fetch), call
279
- \`handoff(reason)\` \u2014 the only valid target for you is the research
280
- specialist, so just pass a brief reason. The runtime will re-route
281
- the user's original message there.
282
-
283
- **Bias toward staying in the code thread.** Most follow-up messages
284
- ("can you make it faster?", "fix the error", "what about edge
285
- cases?") are continuations of the current coding task, NOT new
286
- categories. Only call \`handoff\` when the message clearly needs
287
- research-specialist tools.
274
+ **Stay focused on the current task.** Most follow-ups ("can you make it
275
+ faster?", "fix the error", "what about edge cases?") are continuations
276
+ of the current work, not new categories.
288
277
 
289
278
  ## Style
290
279
 
@@ -551,6 +540,28 @@ diagram needs scrolling, prose is probably better.
551
540
  allowHandoff: false
552
541
  }
553
542
  })]);
543
+ WEB_SEARCH_NOTE = __deepFreeze(`
544
+ You have **web search**. Use it directly whenever a task needs current or
545
+ external information \u2014 a fact to verify, a library or API to check, a
546
+ dataset or leaderboard to consult. Do NOT ask the user to look things up,
547
+ and do NOT decline a task as "needs research / out of scope": search for
548
+ what you need and keep going.`);
549
+ ONE_SHOT_NOTE = __deepFreeze(`
550
+ You are running in **one-shot, autonomous mode**: no human will answer
551
+ questions and there is NO next turn. Therefore:
552
+ - NEVER end your turn by asking a clarifying question or waiting for input.
553
+ If something is ambiguous, state the most reasonable assumption and
554
+ proceed.
555
+ - NEVER defer work to "the next turn" or hand back a plan \u2014 do it now.
556
+ - NEVER end with an empty response or zero tool calls. If the task is hard,
557
+ underspecified, or outside your usual area, still take a concrete first
558
+ action toward it and write your best attempt to the required file \u2014 an
559
+ imperfect artifact on disk always beats producing nothing.
560
+ - Leave the task COMPLETE on disk: write the required file(s), then verify
561
+ (compile, run, run any tests) and fix what fails before you stop.
562
+ - If you are running low on tool budget, spend the remaining calls
563
+ producing and saving the best COMPLETE artifact you can. A working file
564
+ on disk beats a perfect plan that was never written.`);
554
565
  })();
555
566
  return __staticInitPromise;
556
567
  }
@@ -560,7 +571,9 @@ function __getStaticVars() {
560
571
  docSkill,
561
572
  cliSkill,
562
573
  codeSysPrompt,
563
- codeTools
574
+ codeTools,
575
+ WEB_SEARCH_NOTE,
576
+ ONE_SHOT_NOTE
564
577
  };
565
578
  }
566
579
  __globalCtx.getStaticVars = __getStaticVars;
@@ -572,6 +585,7 @@ async function __initializeGlobals(__ctx) {
572
585
  __ctx.globals.markInitialized("dist/lib/agents/agency-agent/subagents/code.agency");
573
586
  await __initializeStatic(__ctx);
574
587
  await __ctx.writeStaticStateToTrace(__globalCtx.getStaticVars());
588
+ __ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", false);
575
589
  __ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", true);
576
590
  }
577
591
  __registerGlobalsInit("dist/lib/agents/agency-agent/subagents/code.agency", __initializeGlobals);
@@ -713,6 +727,120 @@ const agencyCli = __AgencyFunction.create({
713
727
  safe: false,
714
728
  exported: true
715
729
  }, __toolRegistry);
730
+ async function __setCodeOneShot_impl(oneShot) {
731
+ const __setupData = setupFunction();
732
+ const __stack = __setupData.stack;
733
+ const __step = __setupData.step;
734
+ const __self = __setupData.self;
735
+ const __ctx = getRuntimeContext().ctx;
736
+ let __forked;
737
+ let __functionCompleted = false;
738
+ if (!__globals().isInitialized("dist/lib/agents/agency-agent/subagents/code.agency")) {
739
+ await __initializeGlobals(__ctx);
740
+ }
741
+ let __funcStartTime = performance.now();
742
+ __stack.args["oneShot"] = oneShot;
743
+ __self.__retryable = __self.__retryable ?? true;
744
+ const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "dist/lib/agents/agency-agent/subagents/code.agency", scopeName: "setCodeOneShot", threads: __setupData.threads });
745
+ let __resultCheckpointId = -1;
746
+ if (__ctx._pendingArgOverrides) {
747
+ const __overrides = __ctx._pendingArgOverrides;
748
+ __ctx._pendingArgOverrides = void 0;
749
+ if ("oneShot" in __overrides) {
750
+ oneShot = __overrides["oneShot"];
751
+ __stack.args["oneShot"] = oneShot;
752
+ }
753
+ }
754
+ try {
755
+ await agencyStore.run({
756
+ ...getRuntimeContext(),
757
+ ctx: __ctx,
758
+ stack: __setupData.stateStack,
759
+ threads: __setupData.threads
760
+ }, async () => {
761
+ await runner.hook(0, async () => {
762
+ await callHook({
763
+ name: "onFunctionStart",
764
+ data: {
765
+ functionName: "setCodeOneShot",
766
+ args: {
767
+ oneShot
768
+ },
769
+ moduleId: "dist/lib/agents/agency-agent/subagents/code.agency"
770
+ }
771
+ });
772
+ });
773
+ await runner.step(1, async (runner2) => {
774
+ __globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", __stack.args.oneShot);
775
+ });
776
+ });
777
+ if (runner.halted) {
778
+ if (isFailure(runner.haltResult)) {
779
+ runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
780
+ }
781
+ return runner.haltResult;
782
+ }
783
+ } catch (__error) {
784
+ if (__error instanceof RestoreSignal) {
785
+ throw __error;
786
+ }
787
+ if (__error instanceof AgencyAbort) {
788
+ throw __error;
789
+ }
790
+ {
791
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
792
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
793
+ const __log = __createLogger(__ctx.logLevel);
794
+ __log.error("Function setCodeOneShot threw an exception (converted to Failure): " + __errMsg);
795
+ if (__errStack) __log.error(__errStack);
796
+ __ctx.statelogClient?.error?.({
797
+ errorType: "runtimeError",
798
+ message: __errMsg,
799
+ functionName: "setCodeOneShot",
800
+ retryable: __self.__retryable
801
+ });
802
+ }
803
+ return failure(
804
+ __error instanceof Error ? __error.message : String(__error),
805
+ {
806
+ checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
807
+ retryable: __self.__retryable,
808
+ functionName: "setCodeOneShot",
809
+ args: __stack.args
810
+ }
811
+ );
812
+ } finally {
813
+ __stateStack()?.pop();
814
+ if (__functionCompleted) {
815
+ await callHook({
816
+ name: "onFunctionEnd",
817
+ data: {
818
+ functionName: "setCodeOneShot",
819
+ timeTaken: performance.now() - __funcStartTime
820
+ }
821
+ });
822
+ }
823
+ }
824
+ }
825
+ const setCodeOneShot = __AgencyFunction.create({
826
+ name: "setCodeOneShot",
827
+ module: "dist/lib/agents/agency-agent/subagents/code.agency",
828
+ fn: __setCodeOneShot_impl,
829
+ params: [{
830
+ name: "oneShot",
831
+ hasDefault: false,
832
+ defaultValue: void 0,
833
+ variadic: false,
834
+ isFunctionTyped: false
835
+ }],
836
+ toolDefinition: {
837
+ name: "setCodeOneShot",
838
+ description: "No description provided.",
839
+ schema: z.object({ "oneShot": z.boolean() })
840
+ },
841
+ safe: false,
842
+ exported: true
843
+ }, __toolRegistry);
716
844
  async function __codeAgent_impl(userMsg, allowHandoff) {
717
845
  const __setupData = setupFunction();
718
846
  const __stack = __setupData.stack;
@@ -854,10 +982,45 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
854
982
  condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_first"),
855
983
  body: async (runner4) => {
856
984
  await runner4.step(0, async (runner5) => {
985
+ });
986
+ await runner4.step(1, async (runner5) => {
987
+ __stack.locals.sys = __readStatic(codeSysPrompt, "codeSysPrompt", "dist/lib/agents/agency-agent/subagents/code.agency");
988
+ });
989
+ await runner4.ifElse(2, [
990
+ {
991
+ condition: async () => !__eq(await __call(getSearchBackend, {
992
+ type: "positional",
993
+ args: []
994
+ }), `off`),
995
+ body: async (runner5) => {
996
+ await runner5.step(0, async (runner6) => {
997
+ __stack.locals.sys = `${__stack.locals.sys}
998
+
999
+ ${__readStatic(WEB_SEARCH_NOTE, "WEB_SEARCH_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
1000
+ });
1001
+ }
1002
+ }
1003
+ ]);
1004
+ await runner4.step(3, async (runner5) => {
1005
+ __self.__retryable = false;
1006
+ });
1007
+ await runner4.ifElse(4, [
1008
+ {
1009
+ condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot"),
1010
+ body: async (runner5) => {
1011
+ await runner5.step(0, async (runner6) => {
1012
+ __stack.locals.sys = `${__stack.locals.sys}
1013
+
1014
+ ${__readStatic(ONE_SHOT_NOTE, "ONE_SHOT_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
1015
+ });
1016
+ }
1017
+ }
1018
+ ]);
1019
+ await runner4.step(5, async (runner5) => {
857
1020
  __self.__retryable = false;
858
1021
  const __funcResult = await __call(systemMessage, {
859
1022
  type: "positional",
860
- args: [__readStatic(codeSysPrompt, "codeSysPrompt", "dist/lib/agents/agency-agent/subagents/code.agency")]
1023
+ args: [__stack.locals.sys]
861
1024
  });
862
1025
  if (hasInterrupts(__funcResult)) {
863
1026
  await getRuntimeContext().ctx.pendingPromises.awaitAll();
@@ -865,7 +1028,7 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
865
1028
  return;
866
1029
  }
867
1030
  });
868
- await runner4.step(1, async (runner5) => {
1031
+ await runner4.step(6, async (runner5) => {
869
1032
  __globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", false);
870
1033
  });
871
1034
  }
@@ -1073,7 +1236,7 @@ const codeAgent = __AgencyFunction.create({
1073
1236
  exported: true
1074
1237
  }, __toolRegistry);
1075
1238
  var stdin_default = graph;
1076
- const __sourceMap = { "dist/lib/agents/agency-agent/subagents/code.agency:agencyCli": { "1": { "line": 66, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:codeAgent": { "1": { "line": 374, "col": 2 }, "2": { "line": 375, "col": 2 }, "3": { "line": 376, "col": 2 }, "4": { "line": 377, "col": 2 }, "5": { "line": 381, "col": 2 }, "6": { "line": 382, "col": 2 }, "7": { "line": 385, "col": 2 }, "8": { "line": 392, "col": 2 }, "9": { "line": 393, "col": 2 }, "11": { "line": 436, "col": 2 }, "4.0": { "line": 378, "col": 4 }, "9.0": { "line": 394, "col": 4 }, "9.1.0": { "line": 396, "col": 6 }, "9.1.2.0": { "line": 399, "col": 8 }, "9.1.2.1": { "line": 400, "col": 8 }, "9.1.2": { "line": 398, "col": 6 }, "9.1.4": { "line": 402, "col": 6 }, "9.1.5": { "line": 410, "col": 6 }, "9.1.6.0": { "line": 412, "col": 8 }, "9.1.6.1": { "line": 413, "col": 8 }, "9.1.6.2": { "line": 414, "col": 8 }, "9.1.6.3": { "line": 416, "col": 8 }, "9.1.6": { "line": 411, "col": 6 }, "9.1": { "line": 395, "col": 4 }, "9.3": { "line": 420, "col": 4 }, "9.4": { "line": 434, "col": 4 } }, "dist/lib/agents/agency-agent/subagents/code.agency:__block_0": {} };
1239
+ const __sourceMap = { "dist/lib/agents/agency-agent/subagents/code.agency:agencyCli": { "1": { "line": 66, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:setCodeOneShot": { "1": { "line": 382, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:codeAgent": { "1": { "line": 398, "col": 2 }, "2": { "line": 399, "col": 2 }, "3": { "line": 400, "col": 2 }, "4": { "line": 401, "col": 2 }, "5": { "line": 405, "col": 2 }, "6": { "line": 406, "col": 2 }, "7": { "line": 409, "col": 2 }, "8": { "line": 416, "col": 2 }, "9": { "line": 417, "col": 2 }, "11": { "line": 469, "col": 2 }, "4.0": { "line": 402, "col": 4 }, "9.0": { "line": 418, "col": 4 }, "9.1.0": { "line": 420, "col": 6 }, "9.1.2.1": { "line": 425, "col": 8 }, "9.1.2.2.0": { "line": 427, "col": 10 }, "9.1.2.2": { "line": 426, "col": 8 }, "9.1.2.4.0": { "line": 430, "col": 10 }, "9.1.2.4": { "line": 429, "col": 8 }, "9.1.2.5": { "line": 432, "col": 8 }, "9.1.2.6": { "line": 433, "col": 8 }, "9.1.2": { "line": 422, "col": 6 }, "9.1.4": { "line": 435, "col": 6 }, "9.1.5": { "line": 443, "col": 6 }, "9.1.6.0": { "line": 445, "col": 8 }, "9.1.6.1": { "line": 446, "col": 8 }, "9.1.6.2": { "line": 447, "col": 8 }, "9.1.6.3": { "line": 449, "col": 8 }, "9.1.6": { "line": 444, "col": 6 }, "9.1": { "line": 419, "col": 4 }, "9.3": { "line": 453, "col": 4 }, "9.4": { "line": 467, "col": 4 } }, "dist/lib/agents/agency-agent/subagents/code.agency:__block_0": {} };
1077
1240
  export {
1078
1241
  __getCheckpoints,
1079
1242
  __invokeFunction,
@@ -1094,5 +1257,6 @@ export {
1094
1257
  isInterrupt,
1095
1258
  reject,
1096
1259
  respondToInterrupts,
1097
- rewindFrom
1260
+ rewindFrom,
1261
+ setCodeOneShot
1098
1262
  };
@@ -1,9 +1,7 @@
1
1
  import { AgencyConfig } from "../config.js";
2
2
  import { AgencyProgram } from "../index.js";
3
- import { SymbolTable } from "../symbolTable.js";
4
- import { type CompiledClosure } from "../compiler/compileClosure.js";
5
- import { type ImportStrategy } from "../importStrategy.js";
6
3
  import { type InstallKind } from "./installLocation.js";
4
+ import { readFile, type CompileOptions } from "../compiler/buildSession.js";
7
5
  export declare function compiledOutputRegisterUrl(): string;
8
6
  export declare function compiledOutputNodeArgs(): string[];
9
7
  export declare function agencyLangResolvesFrom(dir: string): boolean;
@@ -11,42 +9,29 @@ export declare function compileWarning(kind: InstallKind, outputContext: string,
11
9
  export declare function loadConfig(configPath?: string, verbose?: boolean): AgencyConfig;
12
10
  export declare function readStdin(): Promise<string>;
13
11
  export declare function parse(contents: string, config: AgencyConfig, applyTemplate?: boolean, lower?: boolean): AgencyProgram;
14
- export declare function readFile(inputFile: string): string;
12
+ export { readFile };
15
13
  export declare function resetCompilationCache(): void;
16
14
  /**
17
15
  * Compile a set of entry files under ONE union closure, like the
18
16
  * directory branch of `compile()` does. Callers with many entry points
19
17
  * (the test runner's precompile pass) use this instead of per-file
20
- * `compile()` calls, which would rebuild the closure once per entry via
21
- * `ensureCompiledClosure`'s covers-check.
18
+ * `compile()` calls, which would rebuild the closure once per entry.
22
19
  *
23
20
  * Unlike the CLI directory branch, closure errors THROW
24
21
  * (`CompileClosureError`) instead of exiting, so programmatic callers
25
22
  * can attach context. Parse/typecheck failures inside per-file
26
23
  * `compile()` keep their existing exit behavior.
27
- *
28
- * `options.closure` lets a caller that already built the union closure
29
- * (e.g. to run analyses over `closure.programs`) hand it in rather than
30
- * paying for a rebuild. It MUST cover every file in `files`, otherwise
31
- * `ensureCompiledClosure` clears the session cache mid-loop and the
32
- * one-compile-per-module guarantee is lost.
33
24
  */
34
25
  export declare function compileMany(config: AgencyConfig, files: string[], options?: {
35
- closure?: CompiledClosure;
36
26
  quiet?: boolean;
37
27
  allowTestImports?: boolean;
38
28
  }): void;
39
- export declare function compile(config: AgencyConfig, inputFile: string, _outputFile?: string, options?: {
40
- ts?: boolean;
41
- symbolTable?: SymbolTable;
42
- importStrategy?: ImportStrategy;
43
- /** Suppress the per-file `input → output (in Nms)` progress line. */
44
- quiet?: boolean;
45
- /** Test-harness only. Honors `import test { … }`. Never set outside the
46
- * test runner / analysis paths — kept off AgencyConfig so agent source
47
- * cannot enable it. */
48
- allowTestImports?: boolean;
49
- }): string | null;
29
+ /**
30
+ * Compile an .agency file (or directory of them) to JavaScript. Thin
31
+ * delegate over the default BuildSession — all pipeline logic and caching
32
+ * state live in lib/compiler/buildSession.ts.
33
+ */
34
+ export declare function compile(config: AgencyConfig, inputFile: string, _outputFile?: string, options?: CompileOptions): string | null;
50
35
  export declare function format(contents: string, config?: AgencyConfig): Promise<string>;
51
36
  export declare function formatFile(inputFile: string, inPlace?: boolean, config?: AgencyConfig): Promise<void>;
52
37
  export declare function run(config: AgencyConfig, inputFile: string, outputFile?: string, resumeFile?: string): void;