agency-lang 0.4.0 → 0.5.0
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.
- package/dist/lib/agents/agency-agent/agent.agency +416 -128
- package/dist/lib/agents/agency-agent/agent.js +1716 -521
- package/dist/lib/agents/agency-agent/code.js +17 -15
- package/dist/lib/agents/agency-agent/images/images.js +1 -1
- package/dist/lib/agents/agency-agent/lib/config.agency +72 -0
- package/dist/lib/agents/agency-agent/lib/config.js +258 -0
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +63 -0
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +236 -0
- package/dist/lib/agents/agency-agent/lib/utils.agency +57 -0
- package/dist/lib/agents/agency-agent/lib/utils.js +1017 -0
- package/dist/lib/agents/agency-agent/prompts/codeSample.js +1 -1
- package/dist/lib/agents/agency-agent/research.js +9 -9
- package/dist/lib/agents/agency-agent/shared.js +3 -2
- package/dist/lib/agents/agency-agent/subagents/code.agency +370 -26
- package/dist/lib/agents/agency-agent/subagents/code.js +663 -184
- package/dist/lib/agents/agency-agent/subagents/explorer.agency +166 -0
- package/dist/lib/agents/agency-agent/subagents/explorer.js +530 -0
- package/dist/lib/agents/agency-agent/subagents/oneShot.agency +49 -0
- package/dist/lib/agents/agency-agent/subagents/{plan.js → oneShot.js} +27 -165
- package/dist/lib/agents/agency-agent/subagents/oracle.agency +128 -0
- package/dist/lib/agents/agency-agent/subagents/oracle.js +503 -0
- package/dist/lib/agents/agency-agent/{research.agency → subagents/research.agency} +41 -5
- package/dist/lib/agents/agency-agent/subagents/research.js +581 -0
- package/dist/lib/agents/agency-agent/subagents/review.agency +171 -0
- package/dist/lib/agents/agency-agent/subagents/review.js +1548 -0
- package/dist/lib/agents/docs/appendix/advanced-types.md +1 -1
- package/dist/lib/agents/docs/appendix/agency-stdlib.md +1 -1
- package/dist/lib/agents/docs/appendix/agency-vs-typescript.md +1 -1
- package/dist/lib/agents/docs/appendix/appendix/advanced-types.md +26 -0
- package/dist/lib/agents/docs/appendix/appendix/agency-stdlib.md +25 -0
- package/dist/lib/agents/docs/appendix/appendix/agency-vs-typescript.md +14 -0
- package/dist/lib/agents/docs/appendix/appendix/builtins.md +61 -0
- package/dist/lib/agents/docs/appendix/appendix/callbacks.md +147 -0
- package/dist/lib/agents/docs/appendix/appendix/schema-parameter-injection.md +101 -0
- package/dist/lib/agents/docs/appendix/appendix/ts-helpers.md +511 -0
- package/dist/lib/agents/docs/appendix/appendix/vscode-extension.md +11 -0
- package/dist/lib/agents/docs/appendix/builtins.md +1 -1
- package/dist/lib/agents/docs/appendix/callbacks.md +1 -1
- package/dist/lib/agents/docs/appendix/schema-parameter-injection.md +1 -1
- package/dist/lib/agents/docs/appendix/ts-helpers.md +23 -1
- package/dist/lib/agents/docs/appendix/vscode-extension.md +1 -1
- package/dist/lib/agents/docs/cli/cli/agent.md +16 -0
- package/dist/lib/agents/docs/cli/cli/compile.md +21 -0
- package/dist/lib/agents/docs/cli/cli/coverage.md +112 -0
- package/dist/lib/agents/docs/cli/cli/debug.md +41 -0
- package/dist/lib/agents/docs/cli/cli/doc.md +98 -0
- package/dist/lib/agents/docs/cli/cli/editor-integration.md +44 -0
- package/dist/lib/agents/docs/cli/cli/eval-judge.md +72 -0
- package/dist/lib/agents/docs/cli/cli/eval.md +259 -0
- package/dist/lib/agents/docs/cli/cli/format.md +23 -0
- package/dist/lib/agents/docs/cli/cli/index.md +7 -0
- package/dist/lib/agents/docs/cli/cli/pack.md +56 -0
- package/dist/lib/agents/docs/cli/cli/policy.md +23 -0
- package/dist/lib/agents/docs/cli/cli/preprocess-and-ast.md +21 -0
- package/dist/lib/agents/docs/cli/cli/review.md +16 -0
- package/dist/lib/agents/docs/cli/cli/run.md +108 -0
- package/dist/lib/agents/docs/cli/cli/schedule.md +89 -0
- package/dist/lib/agents/docs/cli/cli/serve.md +52 -0
- package/dist/lib/agents/docs/cli/cli/test.md +44 -0
- package/dist/lib/agents/docs/cli/cli/trace-and-bundle.md +75 -0
- package/dist/lib/agents/docs/cli/cli/typecheck.md +19 -0
- package/dist/lib/agents/docs/cli/eval-judge.md +72 -0
- package/dist/lib/agents/docs/cli/eval.md +259 -0
- package/dist/lib/agents/docs/cli/test.md +0 -9
- package/dist/lib/agents/docs/guide/agency-config-file.md +1 -1
- package/dist/lib/agents/docs/guide/agents-101.md +1 -1
- package/dist/lib/agents/docs/guide/basic-syntax.md +41 -1
- package/dist/lib/agents/docs/guide/blocks.md +1 -1
- package/dist/lib/agents/docs/guide/checkpointing.md +1 -1
- package/dist/lib/agents/docs/guide/cli-args.md +190 -0
- package/dist/lib/agents/docs/guide/concurrency.md +60 -1
- package/dist/lib/agents/docs/guide/cross-thread-context.md +29 -1
- package/dist/lib/agents/docs/guide/error-handling.md +1 -1
- package/dist/lib/agents/docs/guide/execution-model.md +14 -1
- package/dist/lib/agents/docs/guide/functions.md +1 -1
- package/dist/lib/agents/docs/guide/getting-started.md +1 -1
- package/dist/lib/agents/docs/guide/global-vs-static.md +28 -1
- package/dist/lib/agents/docs/guide/guards.md +1 -1
- package/dist/lib/agents/docs/guide/guide/agency-config-file.md +10 -0
- package/dist/lib/agents/docs/guide/guide/agents-101.md +212 -0
- package/dist/lib/agents/docs/guide/guide/basic-syntax.md +218 -0
- package/dist/lib/agents/docs/guide/guide/blocks.md +104 -0
- package/dist/lib/agents/docs/guide/guide/checkpointing.md +72 -0
- package/dist/lib/agents/docs/guide/guide/cli-args.md +190 -0
- package/dist/lib/agents/docs/guide/guide/concurrency.md +151 -0
- package/dist/lib/agents/docs/guide/guide/cross-thread-context.md +228 -0
- package/dist/lib/agents/docs/guide/guide/error-handling.md +149 -0
- package/dist/lib/agents/docs/guide/guide/execution-model.md +130 -0
- package/dist/lib/agents/docs/guide/guide/functions.md +33 -0
- package/dist/lib/agents/docs/guide/guide/getting-started.md +42 -0
- package/dist/lib/agents/docs/guide/guide/global-vs-static.md +81 -0
- package/dist/lib/agents/docs/guide/guide/guards.md +185 -0
- package/dist/lib/agents/docs/guide/guide/handlers.md +292 -0
- package/dist/lib/agents/docs/guide/guide/imports-and-packages.md +160 -0
- package/dist/lib/agents/docs/guide/guide/interrupts.md +99 -0
- package/dist/lib/agents/docs/guide/guide/llm.md +180 -0
- package/dist/lib/agents/docs/guide/guide/mcp.md +295 -0
- package/dist/lib/agents/docs/guide/guide/memory.md +388 -0
- package/dist/lib/agents/docs/guide/guide/message-history-and-threads.md +88 -0
- package/dist/lib/agents/docs/guide/guide/nodes.md +35 -0
- package/dist/lib/agents/docs/guide/guide/observability.md +86 -0
- package/dist/lib/agents/docs/guide/guide/odds-and-ends.md +41 -0
- package/dist/lib/agents/docs/guide/guide/partial-application.md +162 -0
- package/dist/lib/agents/docs/guide/guide/pattern-matching.md +193 -0
- package/dist/lib/agents/docs/guide/guide/policies.md +60 -0
- package/dist/lib/agents/docs/guide/guide/schemas.md +86 -0
- package/dist/lib/agents/docs/guide/guide/serving.md +165 -0
- package/dist/lib/agents/docs/guide/guide/structured-interrupts.md +49 -0
- package/dist/lib/agents/docs/guide/guide/testing.md +27 -0
- package/dist/lib/agents/docs/guide/guide/troubleshooting.md +82 -0
- package/dist/lib/agents/docs/guide/guide/ts-interop.md +185 -0
- package/dist/lib/agents/docs/guide/guide/type-validation.md +329 -0
- package/dist/lib/agents/docs/guide/guide/types.md +196 -0
- package/dist/lib/agents/docs/guide/handlers.md +1 -1
- package/dist/lib/agents/docs/guide/imports-and-packages.md +1 -1
- package/dist/lib/agents/docs/guide/interrupts.md +1 -1
- package/dist/lib/agents/docs/guide/llm.md +1 -1
- package/dist/lib/agents/docs/guide/mcp.md +1 -1
- package/dist/lib/agents/docs/guide/memory.md +1 -1
- package/dist/lib/agents/docs/guide/message-history-and-threads.md +1 -1
- package/dist/lib/agents/docs/guide/nodes.md +1 -1
- package/dist/lib/agents/docs/guide/observability.md +1 -1
- package/dist/lib/agents/docs/guide/odds-and-ends.md +1 -1
- package/dist/lib/agents/docs/guide/partial-application.md +1 -1
- package/dist/lib/agents/docs/guide/pattern-matching.md +1 -1
- package/dist/lib/agents/docs/guide/policies.md +1 -1
- package/dist/lib/agents/docs/guide/schemas.md +1 -1
- package/dist/lib/agents/docs/guide/serving.md +1 -1
- package/dist/lib/agents/docs/guide/structured-interrupts.md +1 -1
- package/dist/lib/agents/docs/guide/testing.md +1 -1
- package/dist/lib/agents/docs/guide/troubleshooting.md +1 -1
- package/dist/lib/agents/docs/guide/ts-interop.md +1 -1
- package/dist/lib/agents/docs/guide/type-validation.md +1 -1
- package/dist/lib/agents/docs/guide/types.md +1 -1
- package/dist/lib/agents/judge.js +1 -1
- package/dist/lib/agents/judgePairwise.agency +41 -0
- package/dist/lib/agents/mutatePrompt.agency +38 -0
- package/dist/lib/agents/mutatePrompt.js +301 -0
- package/dist/lib/agents/policy/agent.js +53 -39
- package/dist/lib/agents/review/agent.js +3 -2
- package/dist/lib/analysis/interrupts.d.ts +36 -0
- package/dist/lib/analysis/interrupts.js +197 -0
- package/dist/lib/analysis/interrupts.test.js +392 -0
- package/dist/lib/backends/agencyGenerator.d.ts +9 -0
- package/dist/lib/backends/agencyGenerator.js +126 -33
- package/dist/lib/backends/agencyGenerator.test.js +141 -0
- package/dist/lib/backends/toolSchemaContribution.test.d.ts +1 -0
- package/dist/lib/backends/toolSchemaContribution.test.js +107 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.js +36 -7
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.js +19 -2
- package/dist/lib/backends/typescriptBuilder/sectionAssembler.js +8 -5
- package/dist/lib/backends/typescriptBuilder.d.ts +27 -0
- package/dist/lib/backends/typescriptBuilder.integration.test.js +18 -0
- package/dist/lib/backends/typescriptBuilder.js +132 -23
- package/dist/lib/backends/typescriptGenerator/typeToString.js +9 -2
- package/dist/lib/cli/agent.d.ts +1 -1
- package/dist/lib/cli/agent.js +2 -2
- package/dist/lib/cli/commands.d.ts +2 -0
- package/dist/lib/cli/commands.js +87 -51
- package/dist/lib/cli/doc.js +15 -4
- package/dist/lib/cli/doc.test.js +53 -7
- package/dist/lib/cli/eval/optimize.d.ts +27 -0
- package/dist/lib/cli/eval/optimize.js +96 -0
- package/dist/lib/cli/eval/optimize.test.d.ts +1 -0
- package/dist/lib/cli/eval/optimize.test.js +172 -0
- package/dist/lib/cli/eval/run.d.ts +51 -0
- package/dist/lib/cli/eval/run.js +192 -0
- package/dist/lib/cli/eval/run.test.d.ts +1 -0
- package/dist/lib/cli/eval/run.test.js +125 -0
- package/dist/lib/cli/evalExtract.d.ts +8 -0
- package/dist/lib/cli/evalExtract.js +28 -0
- package/dist/lib/cli/evalJudge.d.ts +10 -0
- package/dist/lib/cli/evalJudge.js +99 -0
- package/dist/lib/cli/evalJudge.test.d.ts +1 -0
- package/dist/lib/cli/evalJudge.test.js +161 -0
- package/dist/lib/cli/help.js +1 -0
- package/dist/lib/cli/interrupts.d.ts +9 -0
- package/dist/lib/cli/interrupts.js +48 -0
- package/dist/lib/cli/interrupts.test.d.ts +1 -0
- package/dist/lib/cli/interrupts.test.js +67 -0
- package/dist/lib/cli/runAgencyAgent.d.ts +33 -0
- package/dist/lib/cli/runAgencyAgent.js +112 -0
- package/dist/lib/cli/runAgencyAgent.test.d.ts +1 -0
- package/dist/lib/cli/runAgencyAgent.test.js +108 -0
- package/dist/lib/cli/runBundledAgent.js +1 -1
- package/dist/lib/cli/serve.js +1 -1
- package/dist/lib/cli/test.js +1 -0
- package/dist/lib/cli/util.d.ts +7 -3
- package/dist/lib/cli/util.js +44 -31
- package/dist/lib/compilationUnit.d.ts +17 -0
- package/dist/lib/compilationUnit.js +3 -0
- package/dist/lib/config.d.ts +9 -0
- package/dist/lib/config.js +6 -0
- package/dist/lib/config.test.js +9 -0
- package/dist/lib/eval/extract.d.ts +12 -0
- package/dist/lib/eval/extract.js +355 -0
- package/dist/lib/eval/extract.test.d.ts +1 -0
- package/dist/lib/eval/extract.test.js +366 -0
- package/dist/lib/eval/ids.d.ts +2 -0
- package/dist/lib/eval/ids.js +12 -0
- package/dist/lib/eval/judge/pairwise.d.ts +10 -0
- package/dist/lib/eval/judge/pairwise.js +113 -0
- package/dist/lib/eval/judge/pairwise.test.d.ts +1 -0
- package/dist/lib/eval/judge/pairwise.test.js +194 -0
- package/dist/lib/eval/judge/selectFinalResponse.d.ts +6 -0
- package/dist/lib/eval/judge/selectFinalResponse.js +20 -0
- package/dist/lib/eval/judge/selectFinalResponse.test.d.ts +1 -0
- package/dist/lib/eval/judge/selectFinalResponse.test.js +49 -0
- package/dist/lib/eval/judge/suite.d.ts +21 -0
- package/dist/lib/eval/judge/suite.js +154 -0
- package/dist/lib/eval/judge/suite.test.d.ts +1 -0
- package/dist/lib/eval/judge/suite.test.js +139 -0
- package/dist/lib/eval/judge/types.d.ts +65 -0
- package/dist/lib/eval/judge/types.js +1 -0
- package/dist/lib/eval/loadTasks.d.ts +6 -0
- package/dist/lib/eval/loadTasks.js +81 -0
- package/dist/lib/eval/loadTasks.test.d.ts +1 -0
- package/dist/lib/eval/loadTasks.test.js +60 -0
- package/dist/lib/eval/normalize.d.ts +40 -0
- package/dist/lib/eval/normalize.js +60 -0
- package/dist/lib/eval/normalize.test.d.ts +1 -0
- package/dist/lib/eval/normalize.test.js +125 -0
- package/dist/lib/eval/parseJsonl.d.ts +20 -0
- package/dist/lib/eval/parseJsonl.js +57 -0
- package/dist/lib/eval/parseJsonl.test.d.ts +1 -0
- package/dist/lib/eval/parseJsonl.test.js +72 -0
- package/dist/lib/eval/readRun.d.ts +13 -0
- package/dist/lib/eval/readRun.js +42 -0
- package/dist/lib/eval/readRun.test.d.ts +1 -0
- package/dist/lib/eval/readRun.test.js +82 -0
- package/dist/lib/eval/runArtifacts.d.ts +43 -0
- package/dist/lib/eval/runArtifacts.js +131 -0
- package/dist/lib/eval/runArtifacts.test.d.ts +1 -0
- package/dist/lib/eval/runArtifacts.test.js +131 -0
- package/dist/lib/eval/runEvalTask.d.ts +55 -0
- package/dist/lib/eval/runEvalTask.js +63 -0
- package/dist/lib/eval/runTypes.d.ts +36 -0
- package/dist/lib/eval/runTypes.js +1 -0
- package/dist/lib/eval/statelogParser.d.ts +26 -0
- package/dist/lib/eval/statelogParser.js +74 -0
- package/dist/lib/eval/statelogParser.test.d.ts +1 -0
- package/dist/lib/eval/statelogParser.test.js +78 -0
- package/dist/lib/eval/types.d.ts +193 -0
- package/dist/lib/eval/types.js +1 -0
- package/dist/lib/formatter.test.js +113 -0
- package/dist/lib/importPaths.d.ts +9 -0
- package/dist/lib/importPaths.js +31 -0
- package/dist/lib/importPaths.test.js +35 -1
- package/dist/lib/ir/builders.d.ts +24 -10
- package/dist/lib/ir/builders.js +33 -13
- package/dist/lib/ir/prettyPrint.js +15 -7
- package/dist/lib/ir/prettyPrint.test.js +1 -1
- package/dist/lib/logsViewer/conversation.js +3 -2
- package/dist/lib/logsViewer/conversation.test.js +14 -8
- package/dist/lib/logsViewer/render.js +13 -1
- package/dist/lib/logsViewer/render.test.js +2 -1
- package/dist/lib/logsViewer/summary.js +68 -8
- package/dist/lib/logsViewer/types.d.ts +2 -13
- package/dist/lib/mcp/server.js +1 -1
- package/dist/lib/mcp/server.test.js +1 -1
- package/dist/lib/optimize/artifacts.d.ts +46 -0
- package/dist/lib/optimize/artifacts.js +178 -0
- package/dist/lib/optimize/artifacts.test.d.ts +1 -0
- package/dist/lib/optimize/artifacts.test.js +174 -0
- package/dist/lib/optimize/history.d.ts +16 -0
- package/dist/lib/optimize/history.js +29 -0
- package/dist/lib/optimize/history.test.d.ts +1 -0
- package/dist/lib/optimize/history.test.js +37 -0
- package/dist/lib/optimize/loop.d.ts +24 -0
- package/dist/lib/optimize/loop.js +327 -0
- package/dist/lib/optimize/loop.test.d.ts +1 -0
- package/dist/lib/optimize/loop.test.js +377 -0
- package/dist/lib/optimize/mutator.d.ts +39 -0
- package/dist/lib/optimize/mutator.js +114 -0
- package/dist/lib/optimize/mutator.test.d.ts +1 -0
- package/dist/lib/optimize/mutator.test.js +129 -0
- package/dist/lib/optimize/reporter.d.ts +59 -0
- package/dist/lib/optimize/reporter.js +123 -0
- package/dist/lib/optimize/reporter.test.d.ts +1 -0
- package/dist/lib/optimize/reporter.test.js +207 -0
- package/dist/lib/optimize/sourceMutator.d.ts +127 -0
- package/dist/lib/optimize/sourceMutator.js +243 -0
- package/dist/lib/optimize/sourceMutator.test.d.ts +1 -0
- package/dist/lib/optimize/sourceMutator.test.js +524 -0
- package/dist/lib/optimize/targets.d.ts +56 -0
- package/dist/lib/optimize/targets.js +168 -0
- package/dist/lib/optimize/targets.test.d.ts +1 -0
- package/dist/lib/optimize/targets.test.js +255 -0
- package/dist/lib/optimize/tasks.d.ts +2 -0
- package/dist/lib/optimize/tasks.js +9 -0
- package/dist/lib/optimize/tasks.test.d.ts +1 -0
- package/dist/lib/optimize/tasks.test.js +17 -0
- package/dist/lib/optimize/types.d.ts +65 -0
- package/dist/lib/optimize/types.js +1 -0
- package/dist/lib/optimize/validation.d.ts +11 -0
- package/dist/lib/optimize/validation.js +64 -0
- package/dist/lib/optimize/validation.test.d.ts +1 -0
- package/dist/lib/optimize/validation.test.js +43 -0
- package/dist/lib/parser.d.ts +30 -1
- package/dist/lib/parser.js +102 -15
- package/dist/lib/parser.test.js +51 -0
- package/dist/lib/parsers/assignment.test.js +68 -0
- package/dist/lib/parsers/exportConst.test.js +11 -0
- package/dist/lib/parsers/forLoop.test.js +1 -0
- package/dist/lib/parsers/function.test.js +96 -1
- package/dist/lib/parsers/literals.test.js +161 -11
- package/dist/lib/parsers/objectTypeTrivia.test.d.ts +1 -0
- package/dist/lib/parsers/objectTypeTrivia.test.js +163 -0
- package/dist/lib/parsers/parsers.d.ts +1 -1
- package/dist/lib/parsers/parsers.js +322 -106
- package/dist/lib/parsers/typeHints.test.js +103 -0
- package/dist/lib/parsers/vitest.setup.js +11 -3
- package/dist/lib/preprocessors/parallelDesugar.js +14 -4
- package/dist/lib/runtime/__tests__/testHelpers.js +3 -0
- package/dist/lib/runtime/agency.d.ts +3 -1
- package/dist/lib/runtime/agency.js +40 -2
- package/dist/lib/runtime/agency.test.js +101 -1
- package/dist/lib/runtime/agencyFunction.d.ts +20 -0
- package/dist/lib/runtime/agencyFunction.js +61 -5
- package/dist/lib/runtime/agencyFunction.test.js +75 -2
- package/dist/lib/runtime/asyncContext.d.ts +30 -0
- package/dist/lib/runtime/asyncContext.js +27 -1
- package/dist/lib/runtime/asyncContext.test.js +5 -5
- package/dist/lib/runtime/configOverrides.d.ts +28 -0
- package/dist/lib/runtime/configOverrides.js +30 -0
- package/dist/lib/runtime/configOverrides.test.d.ts +1 -0
- package/dist/lib/runtime/configOverrides.test.js +26 -0
- package/dist/lib/runtime/deterministicClient.d.ts +21 -3
- package/dist/lib/runtime/deterministicClient.js +54 -9
- package/dist/lib/runtime/deterministicClient.test.js +76 -0
- package/dist/lib/runtime/index.d.ts +1 -1
- package/dist/lib/runtime/index.js +1 -1
- package/dist/lib/runtime/interrupts.js +20 -5
- package/dist/lib/runtime/ipc.configOverrides.test.d.ts +1 -0
- package/dist/lib/runtime/ipc.configOverrides.test.js +168 -0
- package/dist/lib/runtime/ipc.d.ts +54 -3
- package/dist/lib/runtime/ipc.js +203 -24
- package/dist/lib/runtime/lock.d.ts +11 -0
- package/dist/lib/runtime/lock.js +110 -0
- package/dist/lib/runtime/lock.test.d.ts +1 -0
- package/dist/lib/runtime/lock.test.js +85 -0
- package/dist/lib/runtime/node.js +14 -2
- package/dist/lib/runtime/prompt.js +37 -8
- package/dist/lib/runtime/promptRunner.js +10 -0
- package/dist/lib/runtime/resumableScope.js +7 -1
- package/dist/lib/runtime/runBatch.d.ts +25 -0
- package/dist/lib/runtime/runBatch.js +66 -18
- package/dist/lib/runtime/runner.d.ts +1 -1
- package/dist/lib/runtime/runner.js +47 -21
- package/dist/lib/runtime/state/context.d.ts +4 -0
- package/dist/lib/runtime/state/context.js +14 -0
- package/dist/lib/runtime/state/globalStore.d.ts +19 -0
- package/dist/lib/runtime/state/globalStore.js +21 -0
- package/dist/lib/runtime/state/messageThread.d.ts +6 -1
- package/dist/lib/runtime/state/messageThread.js +7 -1
- package/dist/lib/runtime/state/stateStack.d.ts +21 -1
- package/dist/lib/runtime/state/stateStack.js +21 -12
- package/dist/lib/runtime/state/threadStore.d.ts +88 -11
- package/dist/lib/runtime/state/threadStore.js +151 -24
- package/dist/lib/runtime/subprocess-bootstrap.js +8 -4
- package/dist/lib/runtime/toolBlockDiagnostics.d.ts +20 -0
- package/dist/lib/runtime/toolBlockDiagnostics.js +38 -0
- package/dist/lib/runtime/trace/traceWriter.js +1 -1
- package/dist/lib/runtime/validateToolForLLM.test.d.ts +1 -0
- package/dist/lib/runtime/validateToolForLLM.test.js +95 -0
- package/dist/lib/statelog/wireAccessors.d.ts +47 -0
- package/dist/lib/statelog/wireAccessors.js +113 -0
- package/dist/lib/statelog/wireAccessors.test.d.ts +1 -0
- package/dist/lib/statelog/wireAccessors.test.js +158 -0
- package/dist/lib/statelog/wireTypes.d.ts +13 -0
- package/dist/lib/statelog/wireTypes.js +1 -0
- package/dist/lib/statelogClient.d.ts +64 -5
- package/dist/lib/statelogClient.js +42 -5
- package/dist/lib/stdlib/agencyEval.d.ts +84 -0
- package/dist/lib/stdlib/agencyEval.js +154 -0
- package/dist/lib/stdlib/args.d.ts +115 -0
- package/dist/lib/stdlib/args.js +713 -0
- package/dist/lib/stdlib/cli.d.ts +2 -0
- package/dist/lib/stdlib/cli.js +94 -204
- package/dist/lib/stdlib/concurrency.d.ts +1 -0
- package/dist/lib/stdlib/concurrency.js +8 -0
- package/dist/lib/stdlib/layout/ansi.d.ts +15 -0
- package/dist/lib/stdlib/layout/ansi.js +167 -0
- package/dist/lib/stdlib/layout/axis.d.ts +4 -0
- package/dist/lib/stdlib/layout/axis.js +91 -0
- package/dist/lib/stdlib/layout/block.d.ts +16 -0
- package/dist/lib/stdlib/layout/block.js +103 -0
- package/dist/lib/stdlib/layout/border.d.ts +36 -0
- package/dist/lib/stdlib/layout/border.js +119 -0
- package/dist/lib/stdlib/layout/box.d.ts +3 -0
- package/dist/lib/stdlib/layout/box.js +25 -0
- package/dist/lib/stdlib/layout/nodes.d.ts +29 -0
- package/dist/lib/stdlib/layout/nodes.js +90 -0
- package/dist/lib/stdlib/layout/render.d.ts +18 -0
- package/dist/lib/stdlib/layout/render.js +174 -0
- package/dist/lib/stdlib/layout/table.d.ts +14 -0
- package/dist/lib/stdlib/layout/table.js +453 -0
- package/dist/lib/stdlib/layout.d.ts +21 -58
- package/dist/lib/stdlib/layout.js +27 -467
- package/dist/lib/stdlib/markdown.d.ts +2 -1
- package/dist/lib/stdlib/markdown.js +20 -10
- package/dist/lib/stdlib/statelog.d.ts +7 -0
- package/dist/lib/stdlib/statelog.js +62 -0
- package/dist/lib/stdlib/syntax.js +26 -10
- package/dist/lib/stdlib/system.d.ts +3 -0
- package/dist/lib/stdlib/system.js +13 -0
- package/dist/lib/stdlib/ui.d.ts +12 -10
- package/dist/lib/stdlib/ui.js +230 -62
- package/dist/lib/stdlib/version.d.ts +1 -0
- package/dist/lib/stdlib/version.js +1 -0
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +10 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +4 -2
- package/dist/lib/typeChecker/builtinNamedArgs.test.d.ts +1 -0
- package/dist/lib/typeChecker/builtinNamedArgs.test.js +61 -0
- package/dist/lib/typeChecker/builtins.js +14 -2
- package/dist/lib/typeChecker/checker.d.ts +36 -0
- package/dist/lib/typeChecker/checker.js +166 -40
- package/dist/lib/typeChecker/index.d.ts +2 -0
- package/dist/lib/typeChecker/index.js +20 -1
- package/dist/lib/typeChecker/interruptAnalysis.d.ts +58 -0
- package/dist/lib/typeChecker/interruptAnalysis.js +115 -0
- package/dist/lib/typeChecker/interruptCallGraph.test.d.ts +1 -0
- package/dist/lib/typeChecker/interruptCallGraph.test.js +171 -0
- package/dist/lib/typeChecker/resolveCall.d.ts +3 -0
- package/dist/lib/typeChecker/resolveCall.js +12 -3
- package/dist/lib/typeChecker/scopes.js +7 -0
- package/dist/lib/typeChecker/synthesizer.js +98 -10
- package/dist/lib/typeChecker/toolBlockBinding.d.ts +27 -0
- package/dist/lib/typeChecker/toolBlockBinding.js +168 -0
- package/dist/lib/typeChecker/toolBlockBinding.test.d.ts +1 -0
- package/dist/lib/typeChecker/toolBlockBinding.test.js +286 -0
- package/dist/lib/typeChecker/toolBlockBindingHelpers.test.d.ts +1 -0
- package/dist/lib/typeChecker/toolBlockBindingHelpers.test.js +54 -0
- package/dist/lib/typeChecker/types.d.ts +29 -1
- package/dist/lib/typeChecker/utils.d.ts +19 -0
- package/dist/lib/typeChecker/utils.js +39 -0
- package/dist/lib/typeChecker/variadicNamedBinding.test.d.ts +1 -0
- package/dist/lib/typeChecker/variadicNamedBinding.test.js +176 -0
- package/dist/lib/typeChecker.test.js +32 -6
- package/dist/lib/types/literals.d.ts +1 -0
- package/dist/lib/types/parallelBlock.d.ts +5 -1
- package/dist/lib/types/typeHints.d.ts +28 -1
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/utils/diff.d.ts +8 -5
- package/dist/lib/utils/diff.js +11 -8
- package/dist/lib/utils/diff.test.js +10 -0
- package/dist/lib/utils/formatType.d.ts +11 -1
- package/dist/lib/utils/formatType.js +21 -5
- package/dist/lib/utils/termcolors.d.ts +2 -0
- package/dist/lib/utils/termcolors.js +1 -0
- package/dist/scripts/agency.d.ts +1 -0
- package/dist/scripts/agency.js +142 -28
- package/dist/scripts/agency.test.js +11 -1
- package/dist/scripts/regenerate-fixtures.js +36 -0
- package/package.json +3 -3
- package/stdlib/agency/eval.agency +422 -0
- package/stdlib/agency/eval.js +1347 -0
- package/stdlib/agency.agency +77 -31
- package/stdlib/agency.js +268 -75
- package/stdlib/agent.agency +48 -5
- package/stdlib/agent.js +396 -38
- package/stdlib/args.agency +118 -0
- package/stdlib/args.js +288 -0
- package/stdlib/array.agency +14 -14
- package/stdlib/array.js +69 -41
- package/stdlib/browser.js +17 -9
- package/stdlib/calendar.js +52 -29
- package/stdlib/cli.agency +16 -4
- package/stdlib/cli.js +275 -19
- package/stdlib/clipboard.js +6 -4
- package/stdlib/concurrency.agency +38 -0
- package/stdlib/concurrency.js +342 -0
- package/stdlib/date.js +73 -44
- package/stdlib/email.js +75 -39
- package/stdlib/fs.js +50 -29
- package/stdlib/http.js +29 -16
- package/stdlib/imessage.js +11 -6
- package/stdlib/index.agency +2 -0
- package/stdlib/index.js +89 -49
- package/stdlib/keyring.js +20 -12
- package/stdlib/layout.agency +308 -26
- package/stdlib/layout.js +1583 -134
- package/stdlib/markdown.agency +11 -12
- package/stdlib/markdown.js +22 -16
- package/stdlib/math.js +22 -13
- package/stdlib/memory.agency +46 -29
- package/stdlib/memory.js +163 -24
- package/stdlib/oauth.js +28 -16
- package/stdlib/object.agency +6 -6
- package/stdlib/object.js +27 -16
- package/stdlib/path.js +27 -17
- package/stdlib/policy.agency +127 -52
- package/stdlib/policy.js +627 -174
- package/stdlib/schemas.js +1 -1
- package/stdlib/search.agency +14 -3
- package/stdlib/search.js +52 -10
- package/stdlib/shell.agency +15 -11
- package/stdlib/shell.js +77 -51
- package/stdlib/skills.agency +247 -49
- package/stdlib/skills.js +1149 -271
- package/stdlib/sms.js +17 -9
- package/stdlib/speech.js +27 -15
- package/stdlib/statelog.agency +131 -0
- package/stdlib/statelog.js +1010 -0
- package/stdlib/strategy.agency +14 -6
- package/stdlib/strategy.js +36 -22
- package/stdlib/syntax.js +9 -5
- package/stdlib/system.agency +49 -7
- package/stdlib/system.js +379 -27
- package/stdlib/thread.agency +32 -25
- package/stdlib/thread.js +42 -32
- package/stdlib/threads.js +23 -14
- package/stdlib/types.js +1 -1
- package/stdlib/ui.agency +261 -44
- package/stdlib/ui.js +1619 -453
- package/stdlib/validators.js +45 -28
- package/stdlib/weather.agency +5 -0
- package/stdlib/weather.js +44 -9
- package/stdlib/wikipedia.agency +13 -0
- package/stdlib/wikipedia.js +96 -9
- package/dist/lib/agents/agency-agent/code.agency +0 -223
- package/dist/lib/agents/agency-agent/subagents/plan.agency +0 -34
- package/dist/lib/agents/agency-agent/subagents/task.agency +0 -37
- package/dist/lib/agents/agency-agent/subagents/task.js +0 -513
- package/dist/lib/agents/docs/cli/optimize.md +0 -18
- package/dist/lib/cli/evaluate.d.ts +0 -2
- package/dist/lib/cli/evaluate.js +0 -213
- package/dist/lib/cli/optimize.d.ts +0 -30
- package/dist/lib/cli/optimize.js +0 -225
- package/dist/lib/cli/optimize.test.js +0 -251
- package/dist/lib/cli/optimizerIO.d.ts +0 -28
- package/dist/lib/cli/optimizerIO.js +0 -84
- package/dist/lib/cli/testOptimizerIO.d.ts +0 -29
- package/dist/lib/cli/testOptimizerIO.js +0 -31
- package/dist/lib/version.d.ts +0 -1
- package/dist/lib/version.js +0 -1
- /package/dist/lib/{cli/optimize.test.d.ts → analysis/interrupts.test.d.ts} +0 -0
|
@@ -1,16 +1,40 @@
|
|
|
1
|
+
import { getVersion } from "std::agency"
|
|
1
2
|
import { route } from "std::agent"
|
|
2
|
-
import {
|
|
3
|
+
import { parseArgs } from "std::args"
|
|
4
|
+
import { clearMessages, pushMessage, repl, clearScreen } from "std::cli"
|
|
3
5
|
import { today } from "std::date"
|
|
4
6
|
import { box, render } from "std::layout"
|
|
5
|
-
import {
|
|
7
|
+
import { setMemoryId } from "std::memory"
|
|
8
|
+
import {
|
|
9
|
+
ScopedRuleFields,
|
|
10
|
+
cliPolicyHandler,
|
|
11
|
+
parsePolicyFile,
|
|
12
|
+
setPolicy,
|
|
13
|
+
} from "std::policy"
|
|
6
14
|
import { exists } from "std::shell"
|
|
15
|
+
import { commandsDir, expandSlash } from "std::skills"
|
|
7
16
|
import { highlight } from "std::syntax"
|
|
8
|
-
import { cwd, env } from "std::system"
|
|
9
|
-
import { getCost } from "std::thread"
|
|
17
|
+
import { cwd, env, isTTY, readStdin, setTitle } from "std::system"
|
|
18
|
+
import { getCost, getTokens, systemMessage } from "std::thread"
|
|
19
|
+
import { chooseOption, ChoiceItem } from "std::ui"
|
|
10
20
|
|
|
11
|
-
import { codeSysPrompt, codeTools } from "./code.agency"
|
|
12
21
|
import { figs, title } from "./images/images.agency"
|
|
13
|
-
import {
|
|
22
|
+
import { POLICY_PATH, HISTORY_PATH, ALWAYS_FIELDS } from "./lib/config.agency"
|
|
23
|
+
import {
|
|
24
|
+
minimalAutoApprovePolicy,
|
|
25
|
+
recommendedAutoApprovePolicy,
|
|
26
|
+
} from "./lib/defaultPolicy.agency"
|
|
27
|
+
import { truncate, formatArgs, formatToolResponse } from "./lib/utils.agency"
|
|
28
|
+
import { codeSysPrompt, codeTools, codeAgent } from "./subagents/code.agency"
|
|
29
|
+
import { explorerAgent } from "./subagents/explorer.agency"
|
|
30
|
+
import { oneShotAgent } from "./subagents/oneShot.agency"
|
|
31
|
+
import { oracleAgent } from "./subagents/oracle.agency"
|
|
32
|
+
import {
|
|
33
|
+
researchSysPrompt,
|
|
34
|
+
researchTools,
|
|
35
|
+
researchAgent,
|
|
36
|
+
} from "./subagents/research.agency"
|
|
37
|
+
import { reviewAgent } from "./subagents/review.agency"
|
|
14
38
|
|
|
15
39
|
|
|
16
40
|
// UI mode select — one-line swap between the alt-screen TUI and the
|
|
@@ -57,124 +81,68 @@ import { researchSysPrompt, researchTools } from "./research.agency"
|
|
|
57
81
|
* editing `.agency` files.
|
|
58
82
|
*/
|
|
59
83
|
|
|
60
|
-
// Verbose tool-call tracing
|
|
61
|
-
|
|
84
|
+
// Verbose tool-call tracing. Enabled either by `AGENT_DEBUG=1` (legacy)
|
|
85
|
+
// or by passing `--debug` / `--verbose` on the command line (set in main()).
|
|
86
|
+
let AGENT_DEBUG: boolean = env("AGENT_DEBUG") == "1"
|
|
87
|
+
let VERBOSE: boolean = false
|
|
88
|
+
|
|
89
|
+
// Whether the agent is running in interactive (TTY) mode. Set in main()
|
|
90
|
+
// before any tool calls happen, so the callbacks below can suppress
|
|
91
|
+
// scroll-output writes when stdout is destined for a Unix pipe.
|
|
92
|
+
let _isInteractive: boolean = true
|
|
62
93
|
|
|
63
94
|
callback("onToolCallStart") as data {
|
|
64
|
-
//if (AGENT_DEBUG) {
|
|
65
95
|
pushMessage(color.yellow("⏺ ${data.toolName}(${formatArgs(data.args)})"))
|
|
66
|
-
//}
|
|
67
96
|
}
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
98
|
+
callback("onToolCallEnd") as data {
|
|
99
|
+
if (data.result is success(_result)) {
|
|
100
|
+
pushMessage(color.dim.green("${formatToolResponse(_result)}"))
|
|
101
|
+
} else if (data.result is failure(_error)) {
|
|
102
|
+
pushMessage(color.red(" ⎿ Error: ${_error}"))
|
|
103
|
+
} else {
|
|
104
|
+
pushMessage(color.dim("${formatToolResponse(data.result)}"))
|
|
72
105
|
}
|
|
73
|
-
return str.slice(0, maxLength) + "..."
|
|
74
106
|
}
|
|
75
107
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const value = args[key]
|
|
80
|
-
parts.push("${key}: ${truncate(JSON.stringify(value), 50)}")
|
|
108
|
+
callback("onLLMCallStart") as data {
|
|
109
|
+
if (AGENT_DEBUG || VERBOSE) {
|
|
110
|
+
pushMessage(color.green.dim("💬 [${data.model}] ${data.prompt}"))
|
|
81
111
|
}
|
|
82
|
-
return parts.join(", ")
|
|
83
112
|
}
|
|
84
113
|
|
|
85
|
-
callback("
|
|
86
|
-
if (AGENT_DEBUG) {
|
|
114
|
+
callback("onLLMCallEnd") as data {
|
|
115
|
+
if (AGENT_DEBUG || VERBOSE) {
|
|
87
116
|
pushMessage(
|
|
88
|
-
color.
|
|
89
|
-
"tool return: ${data.toolName} -> ${JSON.stringify(data.result)} ${data.timeTaken}ms",
|
|
90
|
-
),
|
|
117
|
+
color.green.dim("💬 [${data.model}] ${renderLLMCallResponse(data.result)}"),
|
|
91
118
|
)
|
|
92
119
|
}
|
|
93
120
|
}
|
|
94
121
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// init runs before the importer reads it (upstream #232).
|
|
99
|
-
const POLICY_FILE = "policy.json"
|
|
100
|
-
const HISTORY_FILE = "history"
|
|
101
|
-
|
|
102
|
-
def policyDir(): string {
|
|
103
|
-
const home = env("HOME")
|
|
104
|
-
if (home == null) {
|
|
105
|
-
return "./.agency-agent"
|
|
106
|
-
}
|
|
107
|
-
return "${home}/.agency-agent"
|
|
122
|
+
type ToolCallData = {
|
|
123
|
+
name: string;
|
|
124
|
+
arguments: any
|
|
108
125
|
}
|
|
109
126
|
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
type LLMResponse = {
|
|
128
|
+
output: string | null;
|
|
129
|
+
toolCalls: ToolCallData[];
|
|
130
|
+
usage: { inputTokens: number; outputTokens: number; totalTokens: number; cachedInputTokens: number };
|
|
131
|
+
cost: { inputCost: number; outputCost: number; cachedInputCost: number; totalCost: number; currency: string };
|
|
132
|
+
model: string
|
|
112
133
|
}
|
|
113
134
|
|
|
114
|
-
def
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
"
|
|
125
|
-
field: "dir",
|
|
126
|
-
matchSubpaths: true
|
|
127
|
-
}],
|
|
128
|
-
"std::write": [{
|
|
129
|
-
field: "dir",
|
|
130
|
-
matchSubpaths: true
|
|
131
|
-
}],
|
|
132
|
-
"std::edit": [{
|
|
133
|
-
field: "dir",
|
|
134
|
-
matchSubpaths: true
|
|
135
|
-
}],
|
|
136
|
-
"std::ls": [{
|
|
137
|
-
field: "dir",
|
|
138
|
-
matchSubpaths: true
|
|
139
|
-
}],
|
|
140
|
-
"std::glob": [{
|
|
141
|
-
field: "dir",
|
|
142
|
-
matchSubpaths: true
|
|
143
|
-
}],
|
|
144
|
-
"std::grep": [{
|
|
145
|
-
field: "dir",
|
|
146
|
-
matchSubpaths: true
|
|
147
|
-
}],
|
|
148
|
-
"std::copy": [
|
|
149
|
-
{
|
|
150
|
-
field: "src",
|
|
151
|
-
matchSubpaths: true
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
field: "dest",
|
|
155
|
-
matchSubpaths: true
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
"std::move": [
|
|
159
|
-
{
|
|
160
|
-
field: "src",
|
|
161
|
-
matchSubpaths: true
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
field: "dest",
|
|
165
|
-
matchSubpaths: true
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
"std::exec": [
|
|
169
|
-
{
|
|
170
|
-
field: "command",
|
|
171
|
-
matchSubpaths: false
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
field: "subcommand",
|
|
175
|
-
matchSubpaths: false
|
|
176
|
-
},
|
|
177
|
-
]
|
|
135
|
+
def renderLLMCallResponse(data: LLMResponse): string {
|
|
136
|
+
let response = []
|
|
137
|
+
if (data.output != "" && data.output != null && data.output != undefined) {
|
|
138
|
+
response.push(data.output)
|
|
139
|
+
}
|
|
140
|
+
if (data.toolCalls && data.toolCalls.length > 0) {
|
|
141
|
+
for (toolCall in data.toolCalls) {
|
|
142
|
+
response.push(`${toolCall.name}(${formatArgs(toolCall.arguments)})`)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return response.join("\n")
|
|
178
146
|
}
|
|
179
147
|
|
|
180
148
|
def loadAgentsMd(dir: string): string {
|
|
@@ -199,45 +167,280 @@ def loadAgentsMd(dir: string): string {
|
|
|
199
167
|
// LLM doesn't have to re-ground each turn. Initialized in `main()`.
|
|
200
168
|
let _context: string = ""
|
|
201
169
|
|
|
170
|
+
// Project-local slash commands. `cwd()` works at module-init time so
|
|
171
|
+
// we anchor at the user's project root (not the agent's source dir).
|
|
172
|
+
// `with approve` auto-approves the `glob`/`read` during init — the
|
|
173
|
+
// user implicitly opted in by running the agent in this directory.
|
|
174
|
+
static const projectCommands = commandsDir("${cwd()}/.claude/commands") with approve
|
|
175
|
+
|
|
176
|
+
def builtinPalette(): Record<string, string> {
|
|
177
|
+
return {
|
|
178
|
+
"/exit": "Exit the agent",
|
|
179
|
+
"/clear": "Clear the conversation transcript",
|
|
180
|
+
"/cost": "Show cumulative LLM cost and tokens",
|
|
181
|
+
"/help": "Show available slash commands"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Built-ins win over file commands so a user `/clear.md` can't shadow
|
|
186
|
+
// the built-in `/clear`. Build file entries first, then overlay builtins.
|
|
187
|
+
def mergedPalette(): Record<string, string> {
|
|
188
|
+
let out: Record<string, string> = {}
|
|
189
|
+
for (cmd in projectCommands) {
|
|
190
|
+
let label = cmd.description
|
|
191
|
+
if (cmd.argHint != "") {
|
|
192
|
+
label = "${cmd.description} ${cmd.argHint}"
|
|
193
|
+
}
|
|
194
|
+
out["/${cmd.name}"] = label
|
|
195
|
+
}
|
|
196
|
+
const builtins = builtinPalette()
|
|
197
|
+
for (key in builtins) {
|
|
198
|
+
out[key] = builtins[key]
|
|
199
|
+
}
|
|
200
|
+
return out
|
|
201
|
+
}
|
|
202
|
+
|
|
202
203
|
// Slash-command + user-message dispatcher invoked by `repl()` for
|
|
203
204
|
// every Enter keystroke. Return `false` to terminate the loop.
|
|
204
205
|
def _runTurn(msg: string): boolean {
|
|
205
|
-
|
|
206
|
+
// Trim once for built-in matching so `"/help\n"` (piped) or
|
|
207
|
+
// `" /clear"` behave the same as `"/clear"`. `expandSlash` is
|
|
208
|
+
// whitespace-tolerant in its own right, but it still receives the
|
|
209
|
+
// raw `msg` so the LLM sees the exact text the user typed when
|
|
210
|
+
// nothing matches.
|
|
211
|
+
const trimmed = msg.trim()
|
|
212
|
+
if (trimmed == "") {
|
|
206
213
|
return true
|
|
207
214
|
}
|
|
208
|
-
if (
|
|
215
|
+
if (trimmed == "/exit" || trimmed == "/quit") {
|
|
209
216
|
return false
|
|
210
217
|
}
|
|
211
|
-
if (
|
|
218
|
+
if (trimmed == "/clear") {
|
|
212
219
|
clearMessages()
|
|
213
220
|
return true
|
|
214
221
|
}
|
|
215
|
-
if (
|
|
216
|
-
pushMessage("Commands: /exit, /clear, /help")
|
|
222
|
+
if (trimmed == "/help") {
|
|
223
|
+
pushMessage("Commands: /exit, /clear, /cost, /help")
|
|
217
224
|
return true
|
|
218
225
|
}
|
|
226
|
+
if (trimmed == "/cost") {
|
|
227
|
+
pushMessage("Cost: $${getCost().toFixed(4)}")
|
|
228
|
+
pushMessage("Tokens: ${getTokens()}")
|
|
229
|
+
return true
|
|
230
|
+
}
|
|
231
|
+
// Expand `/foo args` to the rendered command body. Unknown `/foo`
|
|
232
|
+
// inputs fall through unchanged — matches Claude Code.
|
|
233
|
+
const prompt = expandSlash(msg, projectCommands)
|
|
234
|
+
const reply = mainAgent(prompt)
|
|
235
|
+
if (reply != "" && reply != null && reply != undefined) {
|
|
236
|
+
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
237
|
+
} else {
|
|
238
|
+
pushMessage(color.red("No reply generated."))
|
|
239
|
+
}
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
let first = true
|
|
244
|
+
static const mainAgentSystemPrompt = """
|
|
245
|
+
You are the top-level coordinator of an Agency-language assistant. You
|
|
246
|
+
receive every user message and decide how to respond.
|
|
247
|
+
|
|
248
|
+
You have five subagent tools, each running in its own isolated
|
|
249
|
+
context:
|
|
250
|
+
|
|
251
|
+
- `codeAgent(userMsg)` — anything that touches code or the filesystem:
|
|
252
|
+
reading, writing, editing, typechecking, running shell commands,
|
|
253
|
+
and answering Agency syntax / CLI questions. Use this for any task
|
|
254
|
+
that involves inspecting or modifying source code.
|
|
255
|
+
- `researchAgent(userMsg)` — web search, URL fetches, Wikipedia,
|
|
256
|
+
external API lookups, summarizing external content.
|
|
257
|
+
- `reviewAgent(userMsg)` — reviews Agency code for syntax and type
|
|
258
|
+
errors. Call this after `codeAgent` produces non-trivial new or
|
|
259
|
+
modified Agency code, passing the code to be reviewed.
|
|
260
|
+
- `oracleAgent(userMsg)` — a read-only senior reviewer on a stronger
|
|
261
|
+
reasoning model. Read the **Oracle** section below — you are
|
|
262
|
+
expected to use this tool **frequently**.
|
|
263
|
+
- `explorerAgent(userMsg)` — a read-only researcher that produces
|
|
264
|
+
broad, synthesizing answers about the codebase or bundled docs.
|
|
265
|
+
Read the **Explorer** section below.
|
|
266
|
+
|
|
267
|
+
**Answer directly (no tool call) when** the message is conversational,
|
|
268
|
+
a clarifying question, or something you can answer from context alone.
|
|
269
|
+
|
|
270
|
+
**Delegate when** the message clearly needs one of the subagents'
|
|
271
|
+
capabilities. Pick one based on what the message actually needs —
|
|
272
|
+
don't pre-emptively call multiple subagents.
|
|
273
|
+
|
|
274
|
+
## Picking between oracle, explorer, and code agent
|
|
275
|
+
|
|
276
|
+
These three overlap on "reads the codebase," but they're for
|
|
277
|
+
different jobs. Pick by **the shape of the answer the user wants**:
|
|
278
|
+
|
|
279
|
+
- **oracle** → sharp verdict on a specific plan, diff, or bug.
|
|
280
|
+
Output: short, decisive ("this plan won't work because X").
|
|
281
|
+
- **explorer** → broad synthesis from reading many files.
|
|
282
|
+
Output: structured overview ("Agency's five main features
|
|
283
|
+
are..."). Use for "summarize", "tour", "what are the main",
|
|
284
|
+
"how does X work across...".
|
|
285
|
+
- **codeAgent** → targeted action: edit, run, typecheck, or
|
|
286
|
+
answer a focused Agency-syntax question. Output: the edit
|
|
287
|
+
itself, or a concise factual reply.
|
|
288
|
+
|
|
289
|
+
Default: if the user asks a broad/synthesizing question,
|
|
290
|
+
`explorerAgent` beats `codeAgent` every time. The code agent is
|
|
291
|
+
optimized for terse action and will under-read on broad asks.
|
|
292
|
+
|
|
293
|
+
Subagents return summary text. Surface that result to the user (in
|
|
294
|
+
your own words if you're combining multiple results), formatted as
|
|
295
|
+
Markdown.
|
|
296
|
+
|
|
297
|
+
## Oracle
|
|
298
|
+
|
|
299
|
+
The oracle is the most powerful tool you have. Use it **FREQUENTLY**.
|
|
300
|
+
It is a read-only senior reviewer running on a stronger reasoning
|
|
301
|
+
model than you. It can read the codebase and the Agency docs but
|
|
302
|
+
cannot write, edit, or run anything. Its job is to **think hard so
|
|
303
|
+
you don't have to guess**.
|
|
304
|
+
|
|
305
|
+
Call the oracle:
|
|
306
|
+
|
|
307
|
+
- **Before** dispatching `codeAgent` for any non-trivial task — ask
|
|
308
|
+
the oracle to sanity-check the plan, find existing code that
|
|
309
|
+
already solves the problem, or suggest a simpler approach.
|
|
310
|
+
- **After** `codeAgent` produces a non-trivial diff — ask the oracle
|
|
311
|
+
to review the work for correctness, missed edge cases, and
|
|
312
|
+
better alternatives.
|
|
313
|
+
- When `codeAgent` reports it's stuck on a bug after one or two
|
|
314
|
+
attempts — ask the oracle what's actually going on.
|
|
315
|
+
- When the user proposes a plan or approach — ask the oracle
|
|
316
|
+
whether the plan is sound, **before** you act on it. If the
|
|
317
|
+
oracle finds a flaw, surface that to the user *before* taking
|
|
318
|
+
any action.
|
|
319
|
+
- Whenever you're tempted to guess about the codebase ("I think
|
|
320
|
+
there's probably already a helper for X") — ask the oracle to
|
|
321
|
+
look.
|
|
322
|
+
|
|
323
|
+
**Tell the user when you're consulting the oracle.** Say something
|
|
324
|
+
like "Let me ask the oracle to review this plan before we start"
|
|
325
|
+
or "I'll have the oracle look for an existing implementation." The
|
|
326
|
+
visibility is half the value — the user benefits from knowing a
|
|
327
|
+
second opinion is being sought.
|
|
328
|
+
|
|
329
|
+
Pass the oracle a self-contained question with full context. It
|
|
330
|
+
does not see your conversation. Include the user's request, the
|
|
331
|
+
plan or diff under review, relevant file paths, and the specific
|
|
332
|
+
question you want answered.
|
|
333
|
+
|
|
334
|
+
Default bias: when in doubt, **consult the oracle**. The cost of
|
|
335
|
+
asking is small; the cost of executing a flawed plan is large.
|
|
336
|
+
|
|
337
|
+
## Explorer
|
|
338
|
+
|
|
339
|
+
The explorer is your go-to for **broad, synthesizing questions**
|
|
340
|
+
about the codebase or the bundled Agency docs. It is read-only and
|
|
341
|
+
runs on a stronger reasoning model with extended thinking. Its job
|
|
342
|
+
is **coverage** — it reads widely and returns a structured synthesis.
|
|
343
|
+
|
|
344
|
+
Call the explorer when the user asks:
|
|
345
|
+
|
|
346
|
+
- "Summarize the Agency docs" / "What are the main features?"
|
|
347
|
+
- "Give me a tour of `lib/X/`" / "What's in this module?"
|
|
348
|
+
- "How does X work across the codebase?"
|
|
349
|
+
- "Walk me through the compilation pipeline"
|
|
350
|
+
- Anything where a good answer requires reading 5+ files and
|
|
351
|
+
organizing the findings by theme.
|
|
352
|
+
|
|
353
|
+
Do NOT use the explorer for:
|
|
354
|
+
- Specific factual lookups ("what does function X return?") — use
|
|
355
|
+
`codeAgent`.
|
|
356
|
+
- Plan critique or bug diagnosis — use `oracleAgent`.
|
|
357
|
+
- External / web research — use `researchAgent`.
|
|
358
|
+
|
|
359
|
+
**Tell the user when you're consulting the explorer.** "Let me have
|
|
360
|
+
the explorer go through the docs and put together an overview." Like
|
|
361
|
+
with the oracle, the visibility is part of the value — the user
|
|
362
|
+
benefits from knowing breadth is being applied.
|
|
363
|
+
|
|
364
|
+
Pass the explorer a self-contained question with explicit scope
|
|
365
|
+
("all of `docs/site/guide/`", "the `lib/parsers/` module"). It does
|
|
366
|
+
not see your conversation. Be clear about the level of detail
|
|
367
|
+
expected.
|
|
368
|
+
|
|
369
|
+
## Style
|
|
370
|
+
|
|
371
|
+
Never start a response by calling the user's question or idea good,
|
|
372
|
+
great, fascinating, profound, excellent, or perfect. Skip flattery
|
|
373
|
+
and respond directly. Don't pad replies with "happy to help",
|
|
374
|
+
"certainly", or trailing summaries the user can read in the diff.
|
|
375
|
+
|
|
376
|
+
**Use ASCII diagrams when they clarify.** For control flow, state
|
|
377
|
+
machines, pipelines, module relationships, or any "how do the parts
|
|
378
|
+
fit together" answer, draw a small ASCII diagram in a fenced
|
|
379
|
+
```text block. Boxes, arrows, and trees beat paragraphs for
|
|
380
|
+
structural explanations:
|
|
381
|
+
|
|
382
|
+
```text
|
|
383
|
+
parse → SymbolTable.build → preprocess → TypeScriptBuilder → printTs
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Keep diagrams small. Skip them where prose or code is clearer —
|
|
387
|
+
diagrams earn their space by showing **relationships** or **flow**.
|
|
388
|
+
|
|
389
|
+
## Answer before action
|
|
390
|
+
|
|
391
|
+
When the user asks a question, asks for an opinion, or asks how to
|
|
392
|
+
plan or approach something, **answer the question first**. Don't
|
|
393
|
+
jump straight into delegating to a subagent or making tool calls
|
|
394
|
+
unless the user has clearly asked for an action ("do X", "fix Y",
|
|
395
|
+
"build Z"). If the user is exploring or thinking out loud, think
|
|
396
|
+
with them — don't sprint to implementation.
|
|
397
|
+
"""
|
|
398
|
+
|
|
399
|
+
static const mainAgentTools = [
|
|
400
|
+
researchAgent.partial(allowHandoff: false),
|
|
401
|
+
codeAgent.partial(allowHandoff: false),
|
|
402
|
+
reviewAgent.partial(allowHandoff: false),
|
|
403
|
+
oracleAgent.partial(allowHandoff: false),
|
|
404
|
+
explorerAgent.partial(allowHandoff: false),
|
|
405
|
+
]
|
|
406
|
+
|
|
407
|
+
def mainAgent(prompt: string): string {
|
|
408
|
+
thread(label: "main", summarize: true, session: "main") {
|
|
409
|
+
setMemoryId("main")
|
|
410
|
+
if (first) {
|
|
411
|
+
systemMessage(mainAgentSystemPrompt)
|
|
412
|
+
first = false
|
|
413
|
+
}
|
|
414
|
+
const result = llm(prompt, {
|
|
415
|
+
memory: true,
|
|
416
|
+
tools: mainAgentTools
|
|
417
|
+
})
|
|
418
|
+
}
|
|
419
|
+
return result
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
def routeAgent(prompt: string): string {
|
|
219
423
|
const reply = route(
|
|
220
424
|
{
|
|
221
425
|
start: "code",
|
|
222
426
|
agents: {
|
|
223
427
|
code: {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
428
|
+
type: "agent",
|
|
429
|
+
name: "code",
|
|
430
|
+
agent: codeAgent
|
|
227
431
|
},
|
|
228
432
|
research: {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
433
|
+
type: "agent",
|
|
434
|
+
name: "research",
|
|
435
|
+
agent: researchAgent
|
|
232
436
|
}
|
|
233
437
|
},
|
|
234
438
|
maxHops: 3,
|
|
235
439
|
context: _context
|
|
236
440
|
},
|
|
237
|
-
|
|
441
|
+
prompt,
|
|
238
442
|
)
|
|
239
|
-
|
|
240
|
-
return true
|
|
443
|
+
return reply
|
|
241
444
|
}
|
|
242
445
|
|
|
243
446
|
def roundedCost(): string {
|
|
@@ -263,6 +466,7 @@ def printHeader() {
|
|
|
263
466
|
r.column() as left {
|
|
264
467
|
left.text("Welcome to the Agency Agent!", bold: true)
|
|
265
468
|
left.text("Ask me to write code, look up docs, or just chat.")
|
|
469
|
+
left.text("All costs are estimates. Actual costs may be higher.", dim: true)
|
|
266
470
|
left.hline()
|
|
267
471
|
left.text("Getting Started", bold: true, fgColor: "cyan")
|
|
268
472
|
left.text("/help for commands · /exit to quit", dim: true)
|
|
@@ -276,7 +480,83 @@ def printHeader() {
|
|
|
276
480
|
print(render(data, color: true))
|
|
277
481
|
}
|
|
278
482
|
|
|
483
|
+
def givePolicyChoice() {
|
|
484
|
+
const title = "Welcome to the agency agent. Please pick a policy to start."
|
|
485
|
+
const body = "Don't worry, you can change this later. The policy just controls how the agent asks for your approval when it wants to do something. You can also create your own custom policy file at ${POLICY_PATH} and the agent will use it automatically."
|
|
486
|
+
let items: ChoiceItem[] = [
|
|
487
|
+
{
|
|
488
|
+
key: "minimal",
|
|
489
|
+
label: "minimal default policy, you do most approvals manually"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
key: "recommended",
|
|
493
|
+
label: "recommended default policy, allow reading files and browsing the web, no writes"
|
|
494
|
+
},
|
|
495
|
+
]
|
|
496
|
+
|
|
497
|
+
const answer = chooseOption(title, body, items, allowFreeText: true)
|
|
498
|
+
match(answer) {
|
|
499
|
+
"minimal" => return minimalAutoApprovePolicy
|
|
500
|
+
"recommended" => return recommendedAutoApprovePolicy
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
279
504
|
node main() {
|
|
505
|
+
// Parse CLI flags first — `parseArgs` exits on --help / --version /
|
|
506
|
+
// usage errors, before any handlers or the TUI are installed.
|
|
507
|
+
const args = parseArgs(
|
|
508
|
+
{
|
|
509
|
+
programName: "agency agent",
|
|
510
|
+
description: "Agency language assistant — interactive REPL by default; one-shot when piped or passed a query / --print.",
|
|
511
|
+
version: getVersion(),
|
|
512
|
+
flags: {
|
|
513
|
+
print: {
|
|
514
|
+
type: "boolean",
|
|
515
|
+
short: "p",
|
|
516
|
+
description: "Run one-shot: print the reply to stdout and exit (no REPL)"
|
|
517
|
+
},
|
|
518
|
+
debug: {
|
|
519
|
+
type: "boolean",
|
|
520
|
+
description: "Log tool returns (toolName, result, timing). Same as AGENT_DEBUG=1"
|
|
521
|
+
},
|
|
522
|
+
verbose: {
|
|
523
|
+
type: "boolean",
|
|
524
|
+
description: "Echo tool-call starts to stdout in non-interactive mode"
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
if (args.flags.debug) {
|
|
531
|
+
AGENT_DEBUG = true
|
|
532
|
+
}
|
|
533
|
+
if (args.flags.verbose) {
|
|
534
|
+
VERBOSE = true
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
setTitle("Agency Agent")
|
|
538
|
+
clearScreen()
|
|
539
|
+
// Positional args (everything after flags) are joined with spaces to
|
|
540
|
+
// form the one-shot prompt. `--` ends flag parsing if a positional
|
|
541
|
+
// would otherwise look like a flag.
|
|
542
|
+
const positionalQuery = args.positionals.join(" ")
|
|
543
|
+
const hasQuery = positionalQuery != ""
|
|
544
|
+
|
|
545
|
+
// Non-interactive (piped) invocation: read the whole prompt from
|
|
546
|
+
// stdin, run one turn of `route()`, write the reply to stdout, and
|
|
547
|
+
// exit. No banner, no REPL, no slash commands. This lets the agent
|
|
548
|
+
// behave like a normal Unix filter: `echo "..." | pnpm run agency agent`.
|
|
549
|
+
//
|
|
550
|
+
// Also entered when `--print` / `-p` is passed, or when a positional
|
|
551
|
+
// query is given. In those cases stdin isn't read — the prompt comes
|
|
552
|
+
// from the positional.
|
|
553
|
+
const forceOneShot = args.flags.print || hasQuery
|
|
554
|
+
if (forceOneShot || !isTTY()) {
|
|
555
|
+
const result = oneShotAgent()
|
|
556
|
+
print(result)
|
|
557
|
+
process.exit(0)
|
|
558
|
+
}
|
|
559
|
+
|
|
280
560
|
printHeader()
|
|
281
561
|
|
|
282
562
|
// Grounding: the LLM should not have to ask the user where it is
|
|
@@ -289,12 +569,24 @@ node main() {
|
|
|
289
569
|
const projectContext = loadAgentsMd(cwd()) with approve
|
|
290
570
|
_context = "\n\nCurrent date: ${today()}\nCurrent working directory: ${cwd()}${projectContext}"
|
|
291
571
|
|
|
572
|
+
const policy = parsePolicyFile(POLICY_PATH)
|
|
573
|
+
if (policy is failure(f)) {
|
|
574
|
+
const { status, error } = f
|
|
575
|
+
print(f, status, error)
|
|
576
|
+
if (status == "doesnt-exist") {
|
|
577
|
+
print(color.yellow("No existing policy found at ${POLICY_PATH}."))
|
|
578
|
+
const choice = givePolicyChoice()
|
|
579
|
+
setPolicy(POLICY_PATH, choice)
|
|
580
|
+
} else {
|
|
581
|
+
print(color.red("Failed to load policy: ${JSON.stringify(error)}"))
|
|
582
|
+
process.exit(1)
|
|
583
|
+
}
|
|
584
|
+
} else {
|
|
585
|
+
setPolicy(POLICY_PATH, policy.value)
|
|
586
|
+
}
|
|
292
587
|
// Bind the handler to a local var so `with handler` parses (the
|
|
293
588
|
// `with` clause only accepts an identifier, not a call expression).
|
|
294
|
-
const handler = cliPolicyHandler(
|
|
295
|
-
file: policyPath(),
|
|
296
|
-
fields: ALWAYS_FIELDS
|
|
297
|
-
})
|
|
589
|
+
const handler = cliPolicyHandler(file: POLICY_PATH, fields: ALWAYS_FIELDS)
|
|
298
590
|
|
|
299
591
|
// The `repl()` widget owns the runloop; every Enter dispatches into
|
|
300
592
|
// `_runTurn` which calls `route()`. Interrupts raised inside
|
|
@@ -305,13 +597,9 @@ node main() {
|
|
|
305
597
|
status: _buildStatus,
|
|
306
598
|
onSubmit: _runTurn,
|
|
307
599
|
prompt: "> ",
|
|
308
|
-
historyFile:
|
|
600
|
+
historyFile: HISTORY_PATH,
|
|
309
601
|
historyMax: 1000,
|
|
310
|
-
paletteCommands:
|
|
311
|
-
"/exit": "Exit the agent",
|
|
312
|
-
"/clear": "Clear the conversation transcript",
|
|
313
|
-
"/help": "Show available slash commands"
|
|
314
|
-
},
|
|
602
|
+
paletteCommands: mergedPalette(),
|
|
315
603
|
)
|
|
316
604
|
} with handler
|
|
317
605
|
|