agency-lang 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,24 @@ 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
+ - Leave the task COMPLETE on disk: write the required file(s), then verify
557
+ (compile, run, run any tests) and fix what fails before you stop.
558
+ - If you are running low on tool budget, spend the remaining calls
559
+ producing and saving the best COMPLETE artifact you can. A working file
560
+ on disk beats a perfect plan that was never written.`);
554
561
  })();
555
562
  return __staticInitPromise;
556
563
  }
@@ -560,7 +567,9 @@ function __getStaticVars() {
560
567
  docSkill,
561
568
  cliSkill,
562
569
  codeSysPrompt,
563
- codeTools
570
+ codeTools,
571
+ WEB_SEARCH_NOTE,
572
+ ONE_SHOT_NOTE
564
573
  };
565
574
  }
566
575
  __globalCtx.getStaticVars = __getStaticVars;
@@ -572,6 +581,7 @@ async function __initializeGlobals(__ctx) {
572
581
  __ctx.globals.markInitialized("dist/lib/agents/agency-agent/subagents/code.agency");
573
582
  await __initializeStatic(__ctx);
574
583
  await __ctx.writeStaticStateToTrace(__globalCtx.getStaticVars());
584
+ __ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", false);
575
585
  __ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", true);
576
586
  }
577
587
  __registerGlobalsInit("dist/lib/agents/agency-agent/subagents/code.agency", __initializeGlobals);
@@ -713,6 +723,120 @@ const agencyCli = __AgencyFunction.create({
713
723
  safe: false,
714
724
  exported: true
715
725
  }, __toolRegistry);
726
+ async function __setCodeOneShot_impl(oneShot) {
727
+ const __setupData = setupFunction();
728
+ const __stack = __setupData.stack;
729
+ const __step = __setupData.step;
730
+ const __self = __setupData.self;
731
+ const __ctx = getRuntimeContext().ctx;
732
+ let __forked;
733
+ let __functionCompleted = false;
734
+ if (!__globals().isInitialized("dist/lib/agents/agency-agent/subagents/code.agency")) {
735
+ await __initializeGlobals(__ctx);
736
+ }
737
+ let __funcStartTime = performance.now();
738
+ __stack.args["oneShot"] = oneShot;
739
+ __self.__retryable = __self.__retryable ?? true;
740
+ const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "dist/lib/agents/agency-agent/subagents/code.agency", scopeName: "setCodeOneShot", threads: __setupData.threads });
741
+ let __resultCheckpointId = -1;
742
+ if (__ctx._pendingArgOverrides) {
743
+ const __overrides = __ctx._pendingArgOverrides;
744
+ __ctx._pendingArgOverrides = void 0;
745
+ if ("oneShot" in __overrides) {
746
+ oneShot = __overrides["oneShot"];
747
+ __stack.args["oneShot"] = oneShot;
748
+ }
749
+ }
750
+ try {
751
+ await agencyStore.run({
752
+ ...getRuntimeContext(),
753
+ ctx: __ctx,
754
+ stack: __setupData.stateStack,
755
+ threads: __setupData.threads
756
+ }, async () => {
757
+ await runner.hook(0, async () => {
758
+ await callHook({
759
+ name: "onFunctionStart",
760
+ data: {
761
+ functionName: "setCodeOneShot",
762
+ args: {
763
+ oneShot
764
+ },
765
+ moduleId: "dist/lib/agents/agency-agent/subagents/code.agency"
766
+ }
767
+ });
768
+ });
769
+ await runner.step(1, async (runner2) => {
770
+ __globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", __stack.args.oneShot);
771
+ });
772
+ });
773
+ if (runner.halted) {
774
+ if (isFailure(runner.haltResult)) {
775
+ runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
776
+ }
777
+ return runner.haltResult;
778
+ }
779
+ } catch (__error) {
780
+ if (__error instanceof RestoreSignal) {
781
+ throw __error;
782
+ }
783
+ if (__error instanceof AgencyAbort) {
784
+ throw __error;
785
+ }
786
+ {
787
+ const __errMsg = __error instanceof Error ? __error.message : String(__error);
788
+ const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
789
+ const __log = __createLogger(__ctx.logLevel);
790
+ __log.error("Function setCodeOneShot threw an exception (converted to Failure): " + __errMsg);
791
+ if (__errStack) __log.error(__errStack);
792
+ __ctx.statelogClient?.error?.({
793
+ errorType: "runtimeError",
794
+ message: __errMsg,
795
+ functionName: "setCodeOneShot",
796
+ retryable: __self.__retryable
797
+ });
798
+ }
799
+ return failure(
800
+ __error instanceof Error ? __error.message : String(__error),
801
+ {
802
+ checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
803
+ retryable: __self.__retryable,
804
+ functionName: "setCodeOneShot",
805
+ args: __stack.args
806
+ }
807
+ );
808
+ } finally {
809
+ __stateStack()?.pop();
810
+ if (__functionCompleted) {
811
+ await callHook({
812
+ name: "onFunctionEnd",
813
+ data: {
814
+ functionName: "setCodeOneShot",
815
+ timeTaken: performance.now() - __funcStartTime
816
+ }
817
+ });
818
+ }
819
+ }
820
+ }
821
+ const setCodeOneShot = __AgencyFunction.create({
822
+ name: "setCodeOneShot",
823
+ module: "dist/lib/agents/agency-agent/subagents/code.agency",
824
+ fn: __setCodeOneShot_impl,
825
+ params: [{
826
+ name: "oneShot",
827
+ hasDefault: false,
828
+ defaultValue: void 0,
829
+ variadic: false,
830
+ isFunctionTyped: false
831
+ }],
832
+ toolDefinition: {
833
+ name: "setCodeOneShot",
834
+ description: "No description provided.",
835
+ schema: z.object({ "oneShot": z.boolean() })
836
+ },
837
+ safe: false,
838
+ exported: true
839
+ }, __toolRegistry);
716
840
  async function __codeAgent_impl(userMsg, allowHandoff) {
717
841
  const __setupData = setupFunction();
718
842
  const __stack = __setupData.stack;
@@ -854,10 +978,45 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
854
978
  condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_first"),
855
979
  body: async (runner4) => {
856
980
  await runner4.step(0, async (runner5) => {
981
+ });
982
+ await runner4.step(1, async (runner5) => {
983
+ __stack.locals.sys = __readStatic(codeSysPrompt, "codeSysPrompt", "dist/lib/agents/agency-agent/subagents/code.agency");
984
+ });
985
+ await runner4.ifElse(2, [
986
+ {
987
+ condition: async () => !__eq(await __call(getSearchBackend, {
988
+ type: "positional",
989
+ args: []
990
+ }), `off`),
991
+ body: async (runner5) => {
992
+ await runner5.step(0, async (runner6) => {
993
+ __stack.locals.sys = `${__stack.locals.sys}
994
+
995
+ ${__readStatic(WEB_SEARCH_NOTE, "WEB_SEARCH_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
996
+ });
997
+ }
998
+ }
999
+ ]);
1000
+ await runner4.step(3, async (runner5) => {
1001
+ __self.__retryable = false;
1002
+ });
1003
+ await runner4.ifElse(4, [
1004
+ {
1005
+ condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot"),
1006
+ body: async (runner5) => {
1007
+ await runner5.step(0, async (runner6) => {
1008
+ __stack.locals.sys = `${__stack.locals.sys}
1009
+
1010
+ ${__readStatic(ONE_SHOT_NOTE, "ONE_SHOT_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
1011
+ });
1012
+ }
1013
+ }
1014
+ ]);
1015
+ await runner4.step(5, async (runner5) => {
857
1016
  __self.__retryable = false;
858
1017
  const __funcResult = await __call(systemMessage, {
859
1018
  type: "positional",
860
- args: [__readStatic(codeSysPrompt, "codeSysPrompt", "dist/lib/agents/agency-agent/subagents/code.agency")]
1019
+ args: [__stack.locals.sys]
861
1020
  });
862
1021
  if (hasInterrupts(__funcResult)) {
863
1022
  await getRuntimeContext().ctx.pendingPromises.awaitAll();
@@ -865,7 +1024,7 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
865
1024
  return;
866
1025
  }
867
1026
  });
868
- await runner4.step(1, async (runner5) => {
1027
+ await runner4.step(6, async (runner5) => {
869
1028
  __globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", false);
870
1029
  });
871
1030
  }
@@ -1073,7 +1232,7 @@ const codeAgent = __AgencyFunction.create({
1073
1232
  exported: true
1074
1233
  }, __toolRegistry);
1075
1234
  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": {} };
1235
+ 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": 378, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:codeAgent": { "1": { "line": 394, "col": 2 }, "2": { "line": 395, "col": 2 }, "3": { "line": 396, "col": 2 }, "4": { "line": 397, "col": 2 }, "5": { "line": 401, "col": 2 }, "6": { "line": 402, "col": 2 }, "7": { "line": 405, "col": 2 }, "8": { "line": 412, "col": 2 }, "9": { "line": 413, "col": 2 }, "11": { "line": 465, "col": 2 }, "4.0": { "line": 398, "col": 4 }, "9.0": { "line": 414, "col": 4 }, "9.1.0": { "line": 416, "col": 6 }, "9.1.2.1": { "line": 421, "col": 8 }, "9.1.2.2.0": { "line": 423, "col": 10 }, "9.1.2.2": { "line": 422, "col": 8 }, "9.1.2.4.0": { "line": 426, "col": 10 }, "9.1.2.4": { "line": 425, "col": 8 }, "9.1.2.5": { "line": 428, "col": 8 }, "9.1.2.6": { "line": 429, "col": 8 }, "9.1.2": { "line": 418, "col": 6 }, "9.1.4": { "line": 431, "col": 6 }, "9.1.5": { "line": 439, "col": 6 }, "9.1.6.0": { "line": 441, "col": 8 }, "9.1.6.1": { "line": 442, "col": 8 }, "9.1.6.2": { "line": 443, "col": 8 }, "9.1.6.3": { "line": 445, "col": 8 }, "9.1.6": { "line": 440, "col": 6 }, "9.1": { "line": 415, "col": 4 }, "9.3": { "line": 449, "col": 4 }, "9.4": { "line": 463, "col": 4 } }, "dist/lib/agents/agency-agent/subagents/code.agency:__block_0": {} };
1077
1236
  export {
1078
1237
  __getCheckpoints,
1079
1238
  __invokeFunction,
@@ -1094,5 +1253,6 @@ export {
1094
1253
  isInterrupt,
1095
1254
  reject,
1096
1255
  respondToInterrupts,
1097
- rewindFrom
1256
+ rewindFrom,
1257
+ setCodeOneShot
1098
1258
  };
@@ -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;