agency-lang 0.4.0 → 0.6.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 +627 -164
- package/dist/lib/agents/agency-agent/agent.js +3287 -829
- package/dist/lib/agents/agency-agent/code.js +17 -15
- package/dist/lib/agents/agency-agent/images/images.js +2 -1
- package/dist/lib/agents/agency-agent/lib/config.agency +72 -0
- package/dist/lib/agents/agency-agent/lib/config.js +259 -0
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +95 -0
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +396 -0
- package/dist/lib/agents/agency-agent/lib/utils.agency +57 -0
- package/dist/lib/agents/agency-agent/lib/utils.js +1035 -0
- package/dist/lib/agents/agency-agent/prompts/codeSample.js +18 -1
- package/dist/lib/agents/agency-agent/research.js +9 -9
- package/dist/lib/agents/agency-agent/shared.agency +101 -2
- package/dist/lib/agents/agency-agent/shared.js +543 -4
- package/dist/lib/agents/agency-agent/subagents/code.agency +398 -26
- package/dist/lib/agents/agency-agent/subagents/code.js +713 -186
- package/dist/lib/agents/agency-agent/subagents/explorer.agency +164 -0
- package/dist/lib/agents/agency-agent/subagents/explorer.js +558 -0
- package/dist/lib/agents/agency-agent/subagents/oracle.agency +127 -0
- package/dist/lib/agents/agency-agent/subagents/oracle.js +533 -0
- package/dist/lib/agents/agency-agent/{research.agency → subagents/research.agency} +50 -8
- package/dist/lib/agents/agency-agent/subagents/research.js +596 -0
- package/dist/lib/agents/agency-agent/subagents/review.agency +171 -0
- package/dist/lib/agents/agency-agent/subagents/review.js +1515 -0
- package/dist/lib/agents/agency-agent/tests/agentTurn.agency +15 -0
- package/dist/lib/agents/agency-agent/tests/agentTurn.js +269 -0
- package/dist/lib/agents/agency-agent/tests/agentTurn.test.json +12 -0
- package/dist/lib/agents/agency-agent/tests/execPolicy.agency +46 -0
- package/dist/lib/agents/agency-agent/tests/execPolicy.js +795 -0
- package/dist/lib/agents/agency-agent/tests/execPolicy.test.json +34 -0
- package/dist/lib/agents/agency-agent/tests/toolWiring.agency +60 -0
- package/dist/lib/agents/agency-agent/tests/toolWiring.js +726 -0
- package/dist/lib/agents/agency-agent/tests/toolWiring.test.json +32 -0
- package/dist/lib/agents/agency-agent/toolWiring.js +696 -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 +194 -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/optimize.md +181 -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 +194 -0
- package/dist/lib/agents/docs/cli/optimize.md +170 -7
- 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/effects-and-raises.md +156 -0
- 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/effects-and-raises.md +156 -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 +188 -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 +137 -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 +3 -3
- 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 +27 -1
- package/dist/lib/agents/docs/guide/pattern-matching.md +1 -1
- package/dist/lib/agents/docs/guide/policies.md +4 -4
- package/dist/lib/agents/docs/guide/schemas.md +1 -1
- package/dist/lib/agents/docs/guide/serving.md +2 -2
- package/dist/lib/agents/docs/guide/structured-interrupts.md +9 -9
- package/dist/lib/agents/docs/guide/testing.md +1 -1
- package/dist/lib/agents/docs/guide/troubleshooting.md +57 -2
- package/dist/lib/agents/docs/guide/ts-interop.md +2 -2
- 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/eval/goalJudge.agency +24 -0
- package/dist/lib/agents/eval/goalJudge.js +311 -0
- package/dist/lib/agents/{judge.js → eval/judge.js} +12 -7
- package/dist/lib/agents/eval/judgePairwise.agency +41 -0
- package/dist/lib/agents/eval/judgePairwise.js +313 -0
- package/dist/lib/agents/gepaReflect.js +316 -0
- package/dist/lib/agents/mutatePrompt.js +301 -0
- package/dist/lib/agents/optimize/gepaReflect.agency +58 -0
- package/dist/lib/agents/optimize/gepaReflect.js +325 -0
- package/dist/lib/agents/optimize/mutatePrompt.agency +44 -0
- package/dist/lib/agents/optimize/mutatePrompt.js +313 -0
- package/dist/lib/agents/policy/agent.agency +14 -14
- package/dist/lib/agents/policy/agent.js +115 -68
- package/dist/lib/agents/review/agent.js +11 -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 +11 -0
- package/dist/lib/backends/agencyGenerator.js +158 -38
- package/dist/lib/backends/agencyGenerator.test.js +141 -0
- package/dist/lib/backends/anthropicApiKey.codegen.test.d.ts +1 -0
- package/dist/lib/backends/anthropicApiKey.codegen.test.js +34 -0
- package/dist/lib/backends/maxToolResultChars.codegen.test.d.ts +1 -0
- package/dist/lib/backends/maxToolResultChars.codegen.test.js +32 -0
- package/dist/lib/backends/raisesFormat.test.d.ts +1 -0
- package/dist/lib/backends/raisesFormat.test.js +59 -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/assignmentEmitter.d.ts +5 -2
- package/dist/lib/backends/typescriptBuilder/assignmentEmitter.js +10 -7
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.js +36 -7
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.js +19 -2
- package/dist/lib/backends/typescriptBuilder/scopeManager.d.ts +11 -0
- package/dist/lib/backends/typescriptBuilder/scopeManager.js +20 -0
- package/dist/lib/backends/typescriptBuilder/scopeManager.test.d.ts +1 -0
- package/dist/lib/backends/typescriptBuilder/scopeManager.test.js +29 -0
- 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 +179 -44
- package/dist/lib/backends/typescriptGenerator/typeToString.d.ts +0 -3
- package/dist/lib/backends/typescriptGenerator/typeToString.js +28 -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 +117 -53
- package/dist/lib/cli/doc.js +25 -14
- package/dist/lib/cli/doc.test.js +62 -16
- package/dist/lib/cli/doctor.d.ts +5 -0
- package/dist/lib/cli/doctor.js +43 -0
- package/dist/lib/cli/eval/optimize.d.ts +31 -0
- package/dist/lib/cli/eval/optimize.js +165 -0
- package/dist/lib/cli/eval/optimize.test.d.ts +1 -0
- package/dist/lib/cli/eval/optimize.test.js +175 -0
- package/dist/lib/cli/eval/run.d.ts +58 -0
- package/dist/lib/cli/eval/run.js +204 -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/policy.js +11 -11
- package/dist/lib/cli/runAgencyAgent.d.ts +33 -0
- package/dist/lib/cli/runAgencyAgent.js +116 -0
- package/dist/lib/cli/runAgencyAgent.test.d.ts +1 -0
- package/dist/lib/cli/runAgencyAgent.test.js +111 -0
- package/dist/lib/cli/runBundledAgent.js +1 -1
- package/dist/lib/cli/serve.js +9 -9
- package/dist/lib/cli/test.js +1 -0
- package/dist/lib/cli/util.d.ts +51 -3
- package/dist/lib/cli/util.js +73 -49
- package/dist/lib/cli/util.test.d.ts +1 -0
- package/dist/lib/cli/util.test.js +19 -0
- package/dist/lib/compilationUnit.d.ts +21 -4
- package/dist/lib/compilationUnit.js +16 -11
- package/dist/lib/compiler/compileClosure.d.ts +1 -1
- package/dist/lib/compiler/compileClosure.js +12 -5
- package/dist/lib/config.d.ts +39 -0
- package/dist/lib/config.js +17 -0
- package/dist/lib/config.test.js +9 -0
- package/dist/lib/eval/extract.d.ts +21 -0
- package/dist/lib/eval/extract.js +372 -0
- package/dist/lib/eval/extract.test.d.ts +1 -0
- package/dist/lib/eval/extract.test.js +406 -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 +155 -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 +66 -0
- package/dist/lib/eval/judge/types.js +1 -0
- package/dist/lib/eval/loadInputs.d.ts +11 -0
- package/dist/lib/eval/loadInputs.js +97 -0
- package/dist/lib/eval/loadInputs.test.d.ts +1 -0
- package/dist/lib/eval/loadInputs.test.js +79 -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 +132 -0
- package/dist/lib/eval/runArtifacts.test.d.ts +1 -0
- package/dist/lib/eval/runArtifacts.test.js +131 -0
- package/dist/lib/eval/runEvalInput.d.ts +55 -0
- package/dist/lib/eval/runEvalInput.js +64 -0
- package/dist/lib/eval/runTypes.d.ts +50 -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 +14 -0
- package/dist/lib/importPaths.js +38 -0
- package/dist/lib/importPaths.test.js +35 -1
- package/dist/lib/ir/builders.d.ts +25 -11
- package/dist/lib/ir/builders.js +35 -15
- package/dist/lib/ir/prettyPrint.js +24 -7
- package/dist/lib/ir/prettyPrint.test.js +12 -1
- package/dist/lib/ir/tsIR.d.ts +5 -0
- 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 +70 -8
- package/dist/lib/logsViewer/types.d.ts +2 -13
- package/dist/lib/lsp/builtinHover.js +2 -2
- package/dist/lib/lsp/diagnostics.js +2 -2
- package/dist/lib/lsp/semantics.d.ts +3 -3
- package/dist/lib/lsp/semantics.js +20 -20
- 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/baseOptimizer.d.ts +109 -0
- package/dist/lib/optimize/baseOptimizer.js +217 -0
- package/dist/lib/optimize/baseOptimizer.test.d.ts +1 -0
- package/dist/lib/optimize/baseOptimizer.test.js +180 -0
- package/dist/lib/optimize/candidatePool.d.ts +17 -0
- package/dist/lib/optimize/candidatePool.js +20 -0
- package/dist/lib/optimize/candidatePool.test.d.ts +1 -0
- package/dist/lib/optimize/candidatePool.test.js +25 -0
- package/dist/lib/optimize/evalCache.d.ts +11 -0
- package/dist/lib/optimize/evalCache.js +16 -0
- package/dist/lib/optimize/evalCache.test.d.ts +1 -0
- package/dist/lib/optimize/evalCache.test.js +28 -0
- package/dist/lib/optimize/gepaReflect.d.ts +9 -0
- package/dist/lib/optimize/gepaReflect.js +9 -0
- package/dist/lib/optimize/gepaReflect.test.d.ts +1 -0
- package/dist/lib/optimize/gepaReflect.test.js +20 -0
- package/dist/lib/optimize/goalJudgeFile.d.ts +12 -0
- package/dist/lib/optimize/goalJudgeFile.js +17 -0
- package/dist/lib/optimize/goalJudgeFile.test.d.ts +1 -0
- package/dist/lib/optimize/goalJudgeFile.test.js +18 -0
- package/dist/lib/optimize/gradeBreakdown.d.ts +22 -0
- package/dist/lib/optimize/gradeBreakdown.js +20 -0
- package/dist/lib/optimize/gradeBreakdown.test.d.ts +1 -0
- package/dist/lib/optimize/gradeBreakdown.test.js +31 -0
- package/dist/lib/optimize/grading/agencyRunner.d.ts +31 -0
- package/dist/lib/optimize/grading/agencyRunner.js +46 -0
- package/dist/lib/optimize/grading/agencyRunner.test.d.ts +1 -0
- package/dist/lib/optimize/grading/agencyRunner.test.js +19 -0
- package/dist/lib/optimize/grading/aggregate.d.ts +10 -0
- package/dist/lib/optimize/grading/aggregate.js +23 -0
- package/dist/lib/optimize/grading/aggregate.test.d.ts +1 -0
- package/dist/lib/optimize/grading/aggregate.test.js +33 -0
- package/dist/lib/optimize/grading/baseGrader.d.ts +26 -0
- package/dist/lib/optimize/grading/baseGrader.js +52 -0
- package/dist/lib/optimize/grading/baseGrader.test.d.ts +1 -0
- package/dist/lib/optimize/grading/baseGrader.test.js +63 -0
- package/dist/lib/optimize/grading/functionGrader.d.ts +32 -0
- package/dist/lib/optimize/grading/functionGrader.js +63 -0
- package/dist/lib/optimize/grading/functionGrader.test.d.ts +1 -0
- package/dist/lib/optimize/grading/functionGrader.test.js +49 -0
- package/dist/lib/optimize/grading/getPath.d.ts +8 -0
- package/dist/lib/optimize/grading/getPath.js +26 -0
- package/dist/lib/optimize/grading/getPath.test.d.ts +1 -0
- package/dist/lib/optimize/grading/getPath.test.js +29 -0
- package/dist/lib/optimize/grading/grade.d.ts +7 -0
- package/dist/lib/optimize/grading/grade.js +10 -0
- package/dist/lib/optimize/grading/grade.test.d.ts +1 -0
- package/dist/lib/optimize/grading/grade.test.js +15 -0
- package/dist/lib/optimize/grading/graders/builtinGraders.d.ts +34 -0
- package/dist/lib/optimize/grading/graders/builtinGraders.js +104 -0
- package/dist/lib/optimize/grading/graders/builtinGraders.test.d.ts +1 -0
- package/dist/lib/optimize/grading/graders/builtinGraders.test.js +77 -0
- package/dist/lib/optimize/grading/graders/humanGrader.d.ts +36 -0
- package/dist/lib/optimize/grading/graders/humanGrader.js +75 -0
- package/dist/lib/optimize/grading/graders/humanGrader.test.d.ts +1 -0
- package/dist/lib/optimize/grading/graders/humanGrader.test.js +70 -0
- package/dist/lib/optimize/grading/graders/llmJudge.d.ts +17 -0
- package/dist/lib/optimize/grading/graders/llmJudge.js +36 -0
- package/dist/lib/optimize/grading/graders/llmJudge.test.d.ts +1 -0
- package/dist/lib/optimize/grading/graders/llmJudge.test.js +47 -0
- package/dist/lib/optimize/grading/scorecard.d.ts +29 -0
- package/dist/lib/optimize/grading/scorecard.js +37 -0
- package/dist/lib/optimize/grading/scorecard.test.d.ts +1 -0
- package/dist/lib/optimize/grading/scorecard.test.js +105 -0
- package/dist/lib/optimize/grading/types.d.ts +51 -0
- package/dist/lib/optimize/grading/types.js +1 -0
- package/dist/lib/optimize/gradingModule.d.ts +10 -0
- package/dist/lib/optimize/gradingModule.js +47 -0
- package/dist/lib/optimize/gradingModule.test.d.ts +1 -0
- package/dist/lib/optimize/gradingModule.test.js +40 -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/inputs.d.ts +2 -0
- package/dist/lib/optimize/inputs.js +9 -0
- package/dist/lib/optimize/inputs.test.d.ts +1 -0
- package/dist/lib/optimize/inputs.test.js +17 -0
- package/dist/lib/optimize/loop.d.ts +24 -0
- package/dist/lib/optimize/loop.js +330 -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 +63 -0
- package/dist/lib/optimize/mutator.js +120 -0
- package/dist/lib/optimize/mutator.test.d.ts +1 -0
- package/dist/lib/optimize/mutator.test.js +142 -0
- package/dist/lib/optimize/optimizer.d.ts +30 -0
- package/dist/lib/optimize/optimizer.js +1 -0
- package/dist/lib/optimize/optimizerModule.d.ts +9 -0
- package/dist/lib/optimize/optimizerModule.js +47 -0
- package/dist/lib/optimize/optimizerModule.test.d.ts +1 -0
- package/dist/lib/optimize/optimizerModule.test.js +30 -0
- package/dist/lib/optimize/optimizers/example.d.ts +48 -0
- package/dist/lib/optimize/optimizers/example.js +82 -0
- package/dist/lib/optimize/optimizers/example.test.d.ts +1 -0
- package/dist/lib/optimize/optimizers/example.test.js +67 -0
- package/dist/lib/optimize/optimizers/gepa.d.ts +37 -0
- package/dist/lib/optimize/optimizers/gepa.js +139 -0
- package/dist/lib/optimize/optimizers/gepa.test.d.ts +1 -0
- package/dist/lib/optimize/optimizers/gepa.test.js +131 -0
- package/dist/lib/optimize/optimizers/greedyReflective.d.ts +35 -0
- package/dist/lib/optimize/optimizers/greedyReflective.js +132 -0
- package/dist/lib/optimize/optimizers/greedyReflective.test.d.ts +1 -0
- package/dist/lib/optimize/optimizers/greedyReflective.test.js +134 -0
- package/dist/lib/optimize/pareto.d.ts +13 -0
- package/dist/lib/optimize/pareto.js +17 -0
- package/dist/lib/optimize/pareto.test.d.ts +1 -0
- package/dist/lib/optimize/pareto.test.js +28 -0
- package/dist/lib/optimize/public.d.ts +24 -0
- package/dist/lib/optimize/public.js +18 -0
- package/dist/lib/optimize/public.test.d.ts +1 -0
- package/dist/lib/optimize/public.test.js +22 -0
- package/dist/lib/optimize/reflectionFeedback.d.ts +9 -0
- package/dist/lib/optimize/reflectionFeedback.js +71 -0
- package/dist/lib/optimize/reflectionFeedback.test.d.ts +1 -0
- package/dist/lib/optimize/reflectionFeedback.test.js +58 -0
- package/dist/lib/optimize/registry.d.ts +5 -0
- package/dist/lib/optimize/registry.js +24 -0
- package/dist/lib/optimize/registry.test.d.ts +1 -0
- package/dist/lib/optimize/registry.test.js +38 -0
- package/dist/lib/optimize/report.d.ts +14 -0
- package/dist/lib/optimize/report.js +58 -0
- package/dist/lib/optimize/report.test.d.ts +1 -0
- package/dist/lib/optimize/report.test.js +32 -0
- package/dist/lib/optimize/reporter.d.ts +109 -0
- package/dist/lib/optimize/reporter.js +195 -0
- package/dist/lib/optimize/reporter.test.d.ts +1 -0
- package/dist/lib/optimize/reporter.test.js +266 -0
- package/dist/lib/optimize/rng.d.ts +8 -0
- package/dist/lib/optimize/rng.js +34 -0
- package/dist/lib/optimize/rng.test.d.ts +1 -0
- package/dist/lib/optimize/rng.test.js +25 -0
- package/dist/lib/optimize/sourceMutator.d.ts +129 -0
- package/dist/lib/optimize/sourceMutator.js +257 -0
- package/dist/lib/optimize/sourceMutator.test.d.ts +1 -0
- package/dist/lib/optimize/sourceMutator.test.js +538 -0
- package/dist/lib/optimize/targets.d.ts +58 -0
- package/dist/lib/optimize/targets.js +172 -0
- package/dist/lib/optimize/targets.test.d.ts +1 -0
- package/dist/lib/optimize/targets.test.js +255 -0
- package/dist/lib/optimize/types.d.ts +75 -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/optimize/validationSplit.d.ts +8 -0
- package/dist/lib/optimize/validationSplit.js +14 -0
- package/dist/lib/optimize/validationSplit.test.d.ts +1 -0
- package/dist/lib/optimize/validationSplit.test.js +25 -0
- package/dist/lib/optimize/workspace.d.ts +42 -0
- package/dist/lib/optimize/workspace.js +100 -0
- package/dist/lib/optimize/workspace.test.d.ts +1 -0
- package/dist/lib/optimize/workspace.test.js +103 -0
- package/dist/lib/parser.d.ts +30 -1
- package/dist/lib/parser.js +104 -17
- package/dist/lib/parser.test.js +51 -0
- package/dist/lib/parsers/assignment.test.js +68 -0
- package/dist/lib/parsers/effectSet.test.d.ts +1 -0
- package/dist/lib/parsers/effectSet.test.js +96 -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/handleBlock.test.js +20 -1
- package/dist/lib/parsers/interruptStatement.test.js +29 -8
- 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 +5 -1
- package/dist/lib/parsers/parsers.js +470 -114
- package/dist/lib/parsers/raiseStatement.test.d.ts +1 -0
- package/dist/lib/parsers/raiseStatement.test.js +64 -0
- package/dist/lib/parsers/raisesClause.test.d.ts +1 -0
- package/dist/lib/parsers/raisesClause.test.js +87 -0
- 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/preprocessors/resolveReExports.js +39 -2
- package/dist/lib/preprocessors/resolveReExports.test.js +117 -0
- package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +16 -0
- package/dist/lib/preprocessors/typescriptPreprocessor.js +127 -52
- 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 +34 -0
- package/dist/lib/runtime/agencyFunction.js +89 -5
- package/dist/lib/runtime/agencyFunction.test.js +124 -2
- package/dist/lib/runtime/agencyInterrupt.d.ts +3 -3
- package/dist/lib/runtime/agencyInterrupt.js +2 -2
- package/dist/lib/runtime/agencyInterrupt.test.js +18 -18
- 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/call.js +13 -0
- package/dist/lib/runtime/configOverrides.d.ts +29 -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/errors.d.ts +3 -3
- package/dist/lib/runtime/errors.js +12 -5
- package/dist/lib/runtime/index.d.ts +1 -1
- package/dist/lib/runtime/index.js +1 -1
- package/dist/lib/runtime/interrupts.d.ts +3 -3
- package/dist/lib/runtime/interrupts.js +28 -13
- package/dist/lib/runtime/interrupts.test.js +3 -3
- 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 +56 -5
- package/dist/lib/runtime/ipc.js +206 -27
- package/dist/lib/runtime/isDebugger.test.js +3 -3
- 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 +17 -2
- package/dist/lib/runtime/policy.d.ts +1 -1
- package/dist/lib/runtime/policy.js +1 -1
- package/dist/lib/runtime/policy.test.js +22 -22
- package/dist/lib/runtime/prompt.d.ts +31 -0
- package/dist/lib/runtime/prompt.js +220 -23
- package/dist/lib/runtime/prompt.test.d.ts +1 -0
- package/dist/lib/runtime/prompt.test.js +79 -0
- 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 +83 -18
- package/dist/lib/runtime/runBatch.test.js +1 -1
- 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 +19 -0
- package/dist/lib/runtime/state/context.js +74 -18
- package/dist/lib/runtime/state/globalStore.d.ts +19 -0
- package/dist/lib/runtime/state/globalStore.js +24 -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 +34 -1
- package/dist/lib/runtime/state/stateStack.js +51 -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/types.d.ts +1 -1
- package/dist/lib/runtime/utils.d.ts +1 -0
- package/dist/lib/runtime/utils.js +6 -1
- package/dist/lib/runtime/validateToolForLLM.test.d.ts +1 -0
- package/dist/lib/runtime/validateToolForLLM.test.js +95 -0
- package/dist/lib/serve/discovery.d.ts +2 -2
- package/dist/lib/serve/discovery.js +7 -7
- package/dist/lib/serve/discovery.test.js +9 -9
- package/dist/lib/serve/http/adapter.js +2 -2
- package/dist/lib/serve/http/adapter.test.js +8 -8
- package/dist/lib/serve/mcp/adapter.js +16 -16
- package/dist/lib/serve/mcp/adapter.test.js +15 -15
- package/dist/lib/serve/mcp/httpTransport.test.js +1 -1
- package/dist/lib/serve/mcp/interruptLoop.test.js +2 -2
- package/dist/lib/serve/types.d.ts +3 -3
- 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 +79 -6
- package/dist/lib/statelogClient.js +72 -13
- package/dist/lib/statelogClient.test.js +48 -0
- 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 +48 -0
- package/dist/lib/stdlib/cli.js +361 -215
- package/dist/lib/stdlib/concurrency.d.ts +1 -0
- package/dist/lib/stdlib/concurrency.js +8 -0
- package/dist/lib/stdlib/fs.d.ts +5 -8
- package/dist/lib/stdlib/fs.js +28 -18
- 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 +7 -0
- package/dist/lib/stdlib/layout/axis.js +114 -0
- package/dist/lib/stdlib/layout/barchart.d.ts +33 -0
- package/dist/lib/stdlib/layout/barchart.js +217 -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 +5 -0
- package/dist/lib/stdlib/layout/box.js +36 -0
- package/dist/lib/stdlib/layout/nodes.d.ts +35 -0
- package/dist/lib/stdlib/layout/nodes.js +121 -0
- package/dist/lib/stdlib/layout/render.d.ts +17 -0
- package/dist/lib/stdlib/layout/render.js +110 -0
- package/dist/lib/stdlib/layout/sizing.d.ts +15 -0
- package/dist/lib/stdlib/layout/sizing.js +38 -0
- package/dist/lib/stdlib/layout/table.d.ts +16 -0
- package/dist/lib/stdlib/layout/table.js +460 -0
- package/dist/lib/stdlib/layout.d.ts +32 -58
- package/dist/lib/stdlib/layout.js +32 -468
- package/dist/lib/stdlib/llm.d.ts +29 -0
- package/dist/lib/stdlib/llm.js +29 -0
- package/dist/lib/stdlib/markdown.d.ts +2 -1
- package/dist/lib/stdlib/markdown.js +20 -10
- package/dist/lib/stdlib/memory.d.ts +1 -0
- package/dist/lib/stdlib/memory.js +5 -0
- package/dist/lib/stdlib/shell.d.ts +1 -1
- package/dist/lib/stdlib/shell.js +38 -5
- package/dist/lib/stdlib/statelog.d.ts +7 -0
- package/dist/lib/stdlib/statelog.js +62 -0
- package/dist/lib/stdlib/syntax-themes.d.ts +17 -0
- package/dist/lib/stdlib/syntax-themes.js +423 -0
- package/dist/lib/stdlib/syntax.d.ts +13 -1
- package/dist/lib/stdlib/syntax.js +106 -78
- 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 +254 -61
- package/dist/lib/stdlib/version.d.ts +1 -0
- package/dist/lib/stdlib/version.js +1 -0
- package/dist/lib/symbolTable.d.ts +8 -5
- package/dist/lib/symbolTable.js +12 -8
- package/dist/lib/symbolTable.test.js +6 -6
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +2 -1
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +11 -1
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.d.ts +2 -1
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.js +1 -0
- package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.js +9 -0
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +5 -2
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +2 -2
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +2 -2
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +1 -1
- package/dist/lib/templates/cli/optimizeReport.d.ts +9 -0
- package/dist/lib/templates/cli/optimizeReport.js +18 -0
- package/dist/lib/templates/cli/standaloneHttp.d.ts +2 -2
- package/dist/lib/templates/cli/standaloneHttp.js +2 -2
- package/dist/lib/templates/cli/standaloneMcp.d.ts +2 -2
- package/dist/lib/templates/cli/standaloneMcp.js +2 -2
- package/dist/lib/templates/cli/standaloneMcpHttp.d.ts +2 -2
- package/dist/lib/templates/cli/standaloneMcpHttp.js +2 -2
- package/dist/lib/typeChecker/agencyFunctionMethods.test.d.ts +1 -0
- package/dist/lib/typeChecker/agencyFunctionMethods.test.js +91 -0
- package/dist/lib/typeChecker/builtinNamedArgs.test.d.ts +1 -0
- package/dist/lib/typeChecker/builtinNamedArgs.test.js +61 -0
- package/dist/lib/typeChecker/builtins.d.ts +17 -0
- package/dist/lib/typeChecker/builtins.js +50 -2
- package/dist/lib/typeChecker/checker.d.ts +36 -0
- package/dist/lib/typeChecker/checker.js +166 -40
- package/dist/lib/typeChecker/effectSetImport.test.d.ts +1 -0
- package/dist/lib/typeChecker/effectSetImport.test.js +46 -0
- package/dist/lib/typeChecker/effectSets.d.ts +26 -0
- package/dist/lib/typeChecker/effectSets.js +64 -0
- package/dist/lib/typeChecker/effectSets.test.d.ts +1 -0
- package/dist/lib/typeChecker/effectSets.test.js +48 -0
- package/dist/lib/typeChecker/index.d.ts +3 -1
- package/dist/lib/typeChecker/index.js +32 -9
- package/dist/lib/typeChecker/interruptAnalysis.d.ts +64 -6
- package/dist/lib/typeChecker/interruptAnalysis.js +135 -20
- package/dist/lib/typeChecker/interruptAnalysis.test.js +16 -16
- package/dist/lib/typeChecker/interruptCallGraph.test.d.ts +1 -0
- package/dist/lib/typeChecker/interruptCallGraph.test.js +171 -0
- package/dist/lib/typeChecker/raisesDiagnostic.d.ts +18 -0
- package/dist/lib/typeChecker/raisesDiagnostic.js +58 -0
- package/dist/lib/typeChecker/raisesDiagnostic.test.d.ts +1 -0
- package/dist/lib/typeChecker/raisesDiagnostic.test.js +91 -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 +106 -39
- package/dist/lib/typeChecker/testUtils.d.ts +13 -0
- package/dist/lib/typeChecker/testUtils.js +37 -0
- 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 +31 -3
- 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/function.d.ts +6 -0
- package/dist/lib/types/graphNode.d.ts +3 -0
- package/dist/lib/types/handleBlock.d.ts +1 -0
- package/dist/lib/types/interruptStatement.d.ts +4 -1
- package/dist/lib/types/literals.d.ts +4 -0
- package/dist/lib/types/parallelBlock.d.ts +5 -1
- package/dist/lib/types/typeHints.d.ts +41 -1
- package/dist/lib/types.d.ts +4 -0
- package/dist/lib/utils/diff.d.ts +40 -5
- package/dist/lib/utils/diff.js +288 -21
- package/dist/lib/utils/diff.test.js +162 -14
- package/dist/lib/utils/formatType.d.ts +11 -1
- package/dist/lib/utils/formatType.js +21 -5
- package/dist/lib/utils/node.js +9 -1
- package/dist/lib/utils/termcolors.d.ts +15 -0
- package/dist/lib/utils/termcolors.js +23 -0
- package/dist/scripts/agency.d.ts +1 -0
- package/dist/scripts/agency.js +164 -29
- package/dist/scripts/agency.test.js +11 -1
- package/dist/scripts/regenerate-fixtures.js +36 -0
- package/package.json +10 -3
- package/stdlib/agency/eval.agency +423 -0
- package/stdlib/agency/eval.js +1365 -0
- package/stdlib/agency.agency +77 -31
- package/stdlib/agency.js +318 -75
- package/stdlib/agent.agency +48 -5
- package/stdlib/agent.js +425 -38
- package/stdlib/args.agency +118 -0
- package/stdlib/args.js +293 -0
- package/stdlib/array.agency +14 -14
- package/stdlib/array.js +110 -41
- package/stdlib/browser.js +22 -9
- package/stdlib/calendar.js +72 -29
- package/stdlib/chart.agency +157 -0
- package/stdlib/chart.js +982 -0
- package/stdlib/cli.agency +22 -4
- package/stdlib/cli.js +304 -22
- package/stdlib/clipboard.js +14 -4
- package/stdlib/concurrency.agency +38 -0
- package/{dist/lib/agents/agency-agent/subagents/plan.js → stdlib/concurrency.js} +101 -159
- package/stdlib/date.js +120 -44
- package/stdlib/email.js +86 -39
- package/stdlib/fs.agency +35 -107
- package/stdlib/fs.js +295 -470
- package/stdlib/http.js +40 -16
- package/stdlib/imessage.js +16 -6
- package/stdlib/index.agency +66 -2
- package/stdlib/index.js +650 -76
- package/stdlib/keyring.js +34 -12
- package/stdlib/layout.agency +82 -26
- package/stdlib/layout.js +414 -134
- package/stdlib/llm.agency +91 -0
- package/stdlib/llm.js +787 -0
- package/stdlib/markdown.agency +11 -12
- package/stdlib/markdown.js +36 -16
- package/stdlib/math.js +36 -13
- package/stdlib/memory.agency +65 -31
- package/stdlib/memory.js +313 -27
- package/stdlib/oauth.js +42 -16
- package/stdlib/object.agency +6 -6
- package/stdlib/object.js +44 -16
- package/stdlib/path.js +50 -17
- package/stdlib/policy.agency +293 -111
- package/stdlib/policy.js +1262 -237
- package/stdlib/schemas.js +2 -1
- package/stdlib/search.agency +14 -3
- package/stdlib/search.js +57 -10
- package/stdlib/shell.agency +58 -12
- package/stdlib/shell.js +405 -110
- package/stdlib/skills.agency +291 -49
- package/stdlib/skills.js +1369 -296
- package/stdlib/sms.js +22 -9
- package/stdlib/speech.js +38 -15
- package/stdlib/statelog.agency +131 -0
- package/stdlib/statelog.js +1030 -0
- package/stdlib/strategy.agency +14 -6
- package/stdlib/strategy.js +55 -22
- package/stdlib/syntax.agency +175 -2
- package/stdlib/syntax.js +675 -13
- package/stdlib/system.agency +49 -7
- package/stdlib/system.js +414 -27
- package/stdlib/table.agency +202 -0
- package/stdlib/table.js +1427 -0
- package/stdlib/thread.agency +32 -25
- package/stdlib/thread.js +62 -32
- package/stdlib/threads.js +40 -14
- package/stdlib/types.js +2 -1
- package/stdlib/ui.agency +280 -44
- package/stdlib/ui.js +1888 -497
- package/stdlib/validators.js +80 -28
- package/stdlib/weather.agency +5 -0
- package/stdlib/weather.js +55 -9
- package/stdlib/wikipedia.agency +13 -0
- package/stdlib/wikipedia.js +107 -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/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/agents/{judge.agency → eval/judge.agency} +0 -0
- /package/dist/lib/{cli/optimize.test.d.ts → analysis/interrupts.test.d.ts} +0 -0
|
@@ -1,16 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getVersion } from "std::agency"
|
|
2
|
+
import { parseArgs } from "std::args"
|
|
3
|
+
import { clearMessages, pushMessage, repl, clearScreen } from "std::cli"
|
|
3
4
|
import { today } from "std::date"
|
|
5
|
+
import { setAgentCwd } from "std::index"
|
|
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 { configureModels } from "./shared.agency"
|
|
29
|
+
import { codeAgent } from "./subagents/code.agency"
|
|
30
|
+
import { explorerAgent } from "./subagents/explorer.agency"
|
|
31
|
+
import { oracleAgent } from "./subagents/oracle.agency"
|
|
32
|
+
import { researchAgent } from "./subagents/research.agency"
|
|
33
|
+
import { reviewAgent } from "./subagents/review.agency"
|
|
14
34
|
|
|
15
35
|
|
|
16
36
|
// UI mode select — one-line swap between the alt-screen TUI and the
|
|
@@ -41,8 +61,8 @@ import { researchSysPrompt, researchTools } from "./research.agency"
|
|
|
41
61
|
*
|
|
42
62
|
* This file's responsibilities collapse to:
|
|
43
63
|
* 1. Per-turn callback (`_runTurn`) wiring the user message into
|
|
44
|
-
*
|
|
45
|
-
* 2. Per-
|
|
64
|
+
* `mainAgent` and printing the reply into the scroll output.
|
|
65
|
+
* 2. Per-effect ALWAYS_FIELDS map for the policy handler's
|
|
46
66
|
* "approve-always-here" option.
|
|
47
67
|
* 3. Wire the two specialists into one `RouterConfig`.
|
|
48
68
|
*
|
|
@@ -57,124 +77,79 @@ import { researchSysPrompt, researchTools } from "./research.agency"
|
|
|
57
77
|
* editing `.agency` files.
|
|
58
78
|
*/
|
|
59
79
|
|
|
60
|
-
// Verbose tool-call tracing
|
|
61
|
-
|
|
80
|
+
// Verbose tool-call tracing. Enabled either by `AGENT_DEBUG=1` (legacy)
|
|
81
|
+
// or by passing `--debug` / `--verbose` on the command line (set in main()).
|
|
82
|
+
let AGENT_DEBUG: boolean = env("AGENT_DEBUG") == "1"
|
|
83
|
+
let VERBOSE: boolean = false
|
|
62
84
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
85
|
+
// Whether the agent is running in interactive (TTY) mode. Set in main()
|
|
86
|
+
// before any tool calls happen, so the callbacks below can suppress
|
|
87
|
+
// scroll-output writes when stdout is destined for a Unix pipe.
|
|
88
|
+
let _isInteractive: boolean = true
|
|
68
89
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
90
|
+
// Live tool-call tracing. Always shown in the interactive REPL; in
|
|
91
|
+
// one-shot mode it's suppressed so piped output is just the reply,
|
|
92
|
+
// unless the user opts in with `--verbose` / `--debug` (AGENT_DEBUG).
|
|
93
|
+
def _showTraces(): boolean {
|
|
94
|
+
return _isInteractive || VERBOSE || AGENT_DEBUG
|
|
74
95
|
}
|
|
75
96
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const value = args[key]
|
|
80
|
-
parts.push("${key}: ${truncate(JSON.stringify(value), 50)}")
|
|
97
|
+
callback("onToolCallStart") as data {
|
|
98
|
+
if (_showTraces()) {
|
|
99
|
+
pushMessage(color.yellow("⏺ ${data.toolName}(${formatArgs(data.args)})"))
|
|
81
100
|
}
|
|
82
|
-
return parts.join(", ")
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
callback("onToolCallEnd") as data {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
color.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
if (_showTraces()) {
|
|
105
|
+
if (data.result is success(_result)) {
|
|
106
|
+
pushMessage(color.dim.green("${formatToolResponse(_result)}"))
|
|
107
|
+
} else if (data.result is failure(_error)) {
|
|
108
|
+
pushMessage(color.red(" ⎿ Error: ${_error}"))
|
|
109
|
+
} else {
|
|
110
|
+
pushMessage(color.dim("${formatToolResponse(data.result)}"))
|
|
111
|
+
}
|
|
92
112
|
}
|
|
93
113
|
}
|
|
94
114
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const HISTORY_FILE = "history"
|
|
115
|
+
callback("onLLMCallStart") as data {
|
|
116
|
+
if (AGENT_DEBUG || VERBOSE) {
|
|
117
|
+
pushMessage(color.green.dim("💬 [${data.model}] ${data.prompt}"))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
101
120
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
121
|
+
callback("onLLMCallEnd") as data {
|
|
122
|
+
if (AGENT_DEBUG || VERBOSE) {
|
|
123
|
+
pushMessage(
|
|
124
|
+
color.green.dim("💬 [${data.model}] ${renderLLMCallResponse(data.result)}"),
|
|
125
|
+
)
|
|
106
126
|
}
|
|
107
|
-
return "${home}/.agency-agent"
|
|
108
127
|
}
|
|
109
128
|
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
type ToolCallData = {
|
|
130
|
+
name: string;
|
|
131
|
+
arguments: any
|
|
112
132
|
}
|
|
113
133
|
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
type LLMResponse = {
|
|
135
|
+
output: string | null;
|
|
136
|
+
toolCalls: ToolCallData[];
|
|
137
|
+
usage: { inputTokens: number; outputTokens: number; totalTokens: number; cachedInputTokens: number };
|
|
138
|
+
cost: { inputCost: number; outputCost: number; cachedInputCost: number; totalCost: number; currency: string };
|
|
139
|
+
model: string
|
|
116
140
|
}
|
|
117
141
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
"
|
|
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
|
-
]
|
|
142
|
+
def renderLLMCallResponse(data: LLMResponse): string {
|
|
143
|
+
let response = []
|
|
144
|
+
if (data.output != "" && data.output != null && data.output != undefined) {
|
|
145
|
+
response.push(data.output)
|
|
146
|
+
}
|
|
147
|
+
if (data.toolCalls && data.toolCalls.length > 0) {
|
|
148
|
+
for (toolCall in data.toolCalls) {
|
|
149
|
+
response.push(`${toolCall.name}(${formatArgs(toolCall.arguments)})`)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return response.join("\n")
|
|
178
153
|
}
|
|
179
154
|
|
|
180
155
|
def loadAgentsMd(dir: string): string {
|
|
@@ -199,47 +174,311 @@ def loadAgentsMd(dir: string): string {
|
|
|
199
174
|
// LLM doesn't have to re-ground each turn. Initialized in `main()`.
|
|
200
175
|
let _context: string = ""
|
|
201
176
|
|
|
177
|
+
// Project-local slash commands. `cwd()` works at module-init time so
|
|
178
|
+
// we anchor at the user's project root (not the agent's source dir).
|
|
179
|
+
// `with approve` auto-approves the `glob`/`read` during init — the
|
|
180
|
+
// user implicitly opted in by running the agent in this directory.
|
|
181
|
+
static const projectCommands = commandsDir("${cwd()}/.claude/commands") with approve
|
|
182
|
+
|
|
183
|
+
def builtinPalette(): Record<string, string> {
|
|
184
|
+
return {
|
|
185
|
+
"/exit": "Exit the agent",
|
|
186
|
+
"/clear": "Clear the conversation transcript",
|
|
187
|
+
"/cost": "Show cumulative LLM cost and tokens",
|
|
188
|
+
"/paste": "Multi-line paste mode (Ctrl+D submits, Ctrl+C cancels)",
|
|
189
|
+
"/help": "Show available slash commands"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Built-ins win over file commands so a user `/clear.md` can't shadow
|
|
194
|
+
// the built-in `/clear`. Build file entries first, then overlay builtins.
|
|
195
|
+
def mergedPalette(): Record<string, string> {
|
|
196
|
+
let out: Record<string, string> = {}
|
|
197
|
+
for (cmd in projectCommands) {
|
|
198
|
+
let label = cmd.description
|
|
199
|
+
if (cmd.argHint != "") {
|
|
200
|
+
label = "${cmd.description} ${cmd.argHint}"
|
|
201
|
+
}
|
|
202
|
+
out["/${cmd.name}"] = label
|
|
203
|
+
}
|
|
204
|
+
const builtins = builtinPalette()
|
|
205
|
+
for (key in builtins) {
|
|
206
|
+
out[key] = builtins[key]
|
|
207
|
+
}
|
|
208
|
+
return out
|
|
209
|
+
}
|
|
210
|
+
|
|
202
211
|
// Slash-command + user-message dispatcher invoked by `repl()` for
|
|
203
212
|
// every Enter keystroke. Return `false` to terminate the loop.
|
|
204
213
|
def _runTurn(msg: string): boolean {
|
|
205
|
-
|
|
214
|
+
// Trim once for built-in matching so `"/help\n"` (piped) or
|
|
215
|
+
// `" /clear"` behave the same as `"/clear"`. `expandSlash` is
|
|
216
|
+
// whitespace-tolerant in its own right, but it still receives the
|
|
217
|
+
// raw `msg` so the LLM sees the exact text the user typed when
|
|
218
|
+
// nothing matches.
|
|
219
|
+
const trimmed = msg.trim()
|
|
220
|
+
if (trimmed == "") {
|
|
206
221
|
return true
|
|
207
222
|
}
|
|
208
|
-
if (
|
|
223
|
+
if (trimmed == "/exit" || trimmed == "/quit") {
|
|
209
224
|
return false
|
|
210
225
|
}
|
|
211
|
-
if (
|
|
226
|
+
if (trimmed == "/clear") {
|
|
212
227
|
clearMessages()
|
|
213
228
|
return true
|
|
214
229
|
}
|
|
215
|
-
if (
|
|
216
|
-
pushMessage("Commands: /exit, /clear, /help")
|
|
230
|
+
if (trimmed == "/help") {
|
|
231
|
+
pushMessage("Commands: /exit, /clear, /cost, /paste, /help")
|
|
217
232
|
return true
|
|
218
233
|
}
|
|
219
|
-
|
|
220
|
-
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
maxHops: 3,
|
|
235
|
-
context: _context
|
|
236
|
-
},
|
|
237
|
-
msg,
|
|
238
|
-
)
|
|
239
|
-
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
234
|
+
if (trimmed == "/cost") {
|
|
235
|
+
pushMessage("Cost: $${getCost().toFixed(4)}")
|
|
236
|
+
pushMessage("Tokens: ${getTokens()}")
|
|
237
|
+
return true
|
|
238
|
+
}
|
|
239
|
+
// Hand the message to the agent. `agentReply` does the slash-command
|
|
240
|
+
// expansion and the actual agent work; the REPL just renders the reply.
|
|
241
|
+
const reply = agentReply(msg)
|
|
242
|
+
if (reply != "" && reply != null && reply != undefined) {
|
|
243
|
+
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
244
|
+
} else {
|
|
245
|
+
pushMessage(color.red("No reply generated."))
|
|
246
|
+
}
|
|
240
247
|
return true
|
|
241
248
|
}
|
|
242
249
|
|
|
250
|
+
let first = true
|
|
251
|
+
|
|
252
|
+
// Valid `--agent` targets. Empty / "main" routes through the coordinator;
|
|
253
|
+
// the rest route the starting prompt's first turn directly to that
|
|
254
|
+
// subagent. Used to validate the flag and to dispatch in `agentReplyVia`.
|
|
255
|
+
static const START_AGENTS = ["main", "code", "research", "oracle", "explorer", "review"]
|
|
256
|
+
|
|
257
|
+
static const mainAgentSystemPrompt = """
|
|
258
|
+
You are the top-level coordinator of an Agency-language assistant. You
|
|
259
|
+
receive every user message and decide how to respond.
|
|
260
|
+
|
|
261
|
+
You have five subagent tools, each running in its own isolated
|
|
262
|
+
context:
|
|
263
|
+
|
|
264
|
+
- `codeAgent(userMsg)` — anything that touches code or the filesystem:
|
|
265
|
+
reading, writing, editing, typechecking, running shell commands,
|
|
266
|
+
and answering Agency syntax / CLI questions. Use this for any task
|
|
267
|
+
that involves inspecting or modifying source code.
|
|
268
|
+
- `researchAgent(userMsg)` — web search, URL fetches, Wikipedia,
|
|
269
|
+
external API lookups, summarizing external content.
|
|
270
|
+
- `reviewAgent(userMsg)` — reviews Agency code for syntax and type
|
|
271
|
+
errors. Call this after `codeAgent` produces non-trivial new or
|
|
272
|
+
modified Agency code, passing the code to be reviewed.
|
|
273
|
+
- `oracleAgent(userMsg)` — a read-only senior reviewer on a stronger
|
|
274
|
+
reasoning model. Read the **Oracle** section below — you are
|
|
275
|
+
expected to use this tool **frequently**.
|
|
276
|
+
- `explorerAgent(userMsg)` — a read-only researcher that produces
|
|
277
|
+
broad, synthesizing answers about the codebase or bundled docs.
|
|
278
|
+
Read the **Explorer** section below.
|
|
279
|
+
|
|
280
|
+
**Answer directly (no tool call) when** the message is conversational,
|
|
281
|
+
a clarifying question, or something you can answer from context alone.
|
|
282
|
+
|
|
283
|
+
**Delegate when** the message clearly needs one of the subagents'
|
|
284
|
+
capabilities. Pick one based on what the message actually needs —
|
|
285
|
+
don't pre-emptively call multiple subagents.
|
|
286
|
+
|
|
287
|
+
## Picking between oracle, explorer, and code agent
|
|
288
|
+
|
|
289
|
+
These three overlap on "reads the codebase," but they're for
|
|
290
|
+
different jobs. Pick by **the shape of the answer the user wants**:
|
|
291
|
+
|
|
292
|
+
- **oracle** → sharp verdict on a specific plan, diff, or bug.
|
|
293
|
+
Output: short, decisive ("this plan won't work because X").
|
|
294
|
+
- **explorer** → broad synthesis from reading many files.
|
|
295
|
+
Output: structured overview ("Agency's five main features
|
|
296
|
+
are..."). Use for "summarize", "tour", "what are the main",
|
|
297
|
+
"how does X work across...".
|
|
298
|
+
- **codeAgent** → targeted action: edit, run, typecheck, or
|
|
299
|
+
answer a focused Agency-syntax question. Output: the edit
|
|
300
|
+
itself, or a concise factual reply.
|
|
301
|
+
|
|
302
|
+
Default: if the user asks a broad/synthesizing question,
|
|
303
|
+
`explorerAgent` beats `codeAgent` every time. The code agent is
|
|
304
|
+
optimized for terse action and will under-read on broad asks.
|
|
305
|
+
|
|
306
|
+
Subagents return summary text. Surface that result to the user (in
|
|
307
|
+
your own words if you're combining multiple results), formatted as
|
|
308
|
+
Markdown.
|
|
309
|
+
|
|
310
|
+
## Oracle
|
|
311
|
+
|
|
312
|
+
The oracle is the most powerful tool you have. Use it **FREQUENTLY**.
|
|
313
|
+
It is a read-only senior reviewer running on a stronger reasoning
|
|
314
|
+
model than you. It can read the codebase and the Agency docs but
|
|
315
|
+
cannot write, edit, or run anything. Its job is to **think hard so
|
|
316
|
+
you don't have to guess**.
|
|
317
|
+
|
|
318
|
+
Call the oracle:
|
|
319
|
+
|
|
320
|
+
- **Before** dispatching `codeAgent` for any non-trivial task — ask
|
|
321
|
+
the oracle to sanity-check the plan, find existing code that
|
|
322
|
+
already solves the problem, or suggest a simpler approach.
|
|
323
|
+
- **After** `codeAgent` produces a non-trivial diff — ask the oracle
|
|
324
|
+
to review the work for correctness, missed edge cases, and
|
|
325
|
+
better alternatives.
|
|
326
|
+
- When `codeAgent` reports it's stuck on a bug after one or two
|
|
327
|
+
attempts — ask the oracle what's actually going on.
|
|
328
|
+
- When the user proposes a plan or approach — ask the oracle
|
|
329
|
+
whether the plan is sound, **before** you act on it. If the
|
|
330
|
+
oracle finds a flaw, surface that to the user *before* taking
|
|
331
|
+
any action.
|
|
332
|
+
- Whenever you're tempted to guess about the codebase ("I think
|
|
333
|
+
there's probably already a helper for X") — ask the oracle to
|
|
334
|
+
look.
|
|
335
|
+
|
|
336
|
+
**Tell the user when you're consulting the oracle.** Say something
|
|
337
|
+
like "Let me ask the oracle to review this plan before we start"
|
|
338
|
+
or "I'll have the oracle look for an existing implementation." The
|
|
339
|
+
visibility is half the value — the user benefits from knowing a
|
|
340
|
+
second opinion is being sought.
|
|
341
|
+
|
|
342
|
+
Pass the oracle a self-contained question with full context. It
|
|
343
|
+
does not see your conversation. Include the user's request, the
|
|
344
|
+
plan or diff under review, relevant file paths, and the specific
|
|
345
|
+
question you want answered.
|
|
346
|
+
|
|
347
|
+
Default bias: when in doubt, **consult the oracle**. The cost of
|
|
348
|
+
asking is small; the cost of executing a flawed plan is large.
|
|
349
|
+
|
|
350
|
+
## Explorer
|
|
351
|
+
|
|
352
|
+
The explorer is your go-to for **broad, synthesizing questions**
|
|
353
|
+
about the codebase or the bundled Agency docs. It is read-only and
|
|
354
|
+
runs on a stronger reasoning model with extended thinking. Its job
|
|
355
|
+
is **coverage** — it reads widely and returns a structured synthesis.
|
|
356
|
+
|
|
357
|
+
Call the explorer when the user asks:
|
|
358
|
+
|
|
359
|
+
- "Summarize the Agency docs" / "What are the main features?"
|
|
360
|
+
- "Give me a tour of `lib/X/`" / "What's in this module?"
|
|
361
|
+
- "How does X work across the codebase?"
|
|
362
|
+
- "Walk me through the compilation pipeline"
|
|
363
|
+
- Anything where a good answer requires reading 5+ files and
|
|
364
|
+
organizing the findings by theme.
|
|
365
|
+
|
|
366
|
+
Do NOT use the explorer for:
|
|
367
|
+
- Specific factual lookups ("what does function X return?") — use
|
|
368
|
+
`codeAgent`.
|
|
369
|
+
- Plan critique or bug diagnosis — use `oracleAgent`.
|
|
370
|
+
- External / web research — use `researchAgent`.
|
|
371
|
+
|
|
372
|
+
**Tell the user when you're consulting the explorer.** "Let me have
|
|
373
|
+
the explorer go through the docs and put together an overview." Like
|
|
374
|
+
with the oracle, the visibility is part of the value — the user
|
|
375
|
+
benefits from knowing breadth is being applied.
|
|
376
|
+
|
|
377
|
+
Pass the explorer a self-contained question with explicit scope
|
|
378
|
+
("all of `docs/site/guide/`", "the `lib/parsers/` module"). It does
|
|
379
|
+
not see your conversation. Be clear about the level of detail
|
|
380
|
+
expected.
|
|
381
|
+
|
|
382
|
+
## Style
|
|
383
|
+
|
|
384
|
+
Never start a response by calling the user's question or idea good,
|
|
385
|
+
great, fascinating, profound, excellent, or perfect. Skip flattery
|
|
386
|
+
and respond directly. Don't pad replies with "happy to help",
|
|
387
|
+
"certainly", or trailing summaries the user can read in the diff.
|
|
388
|
+
|
|
389
|
+
**Use ASCII diagrams when they clarify.** For control flow, state
|
|
390
|
+
machines, pipelines, module relationships, or any "how do the parts
|
|
391
|
+
fit together" answer, draw a small ASCII diagram in a fenced
|
|
392
|
+
```text block. Boxes, arrows, and trees beat paragraphs for
|
|
393
|
+
structural explanations:
|
|
394
|
+
|
|
395
|
+
```text
|
|
396
|
+
parse → SymbolTable.build → preprocess → TypeScriptBuilder → printTs
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Keep diagrams small. Skip them where prose or code is clearer —
|
|
400
|
+
diagrams earn their space by showing **relationships** or **flow**.
|
|
401
|
+
|
|
402
|
+
## Be proactive
|
|
403
|
+
|
|
404
|
+
When the user asks you to look at, debug, or change a file or some code,
|
|
405
|
+
**delegate to `codeAgent` to do it** — don't ask the user to paste a file
|
|
406
|
+
or describe code a subagent could read. The code agent has `read`, `glob`,
|
|
407
|
+
and `ls` and resolves relative paths against the user's working directory
|
|
408
|
+
automatically, so a bare filename like `foo.agency` is enough. Only ask
|
|
409
|
+
the user for information you genuinely cannot obtain through a subagent.
|
|
410
|
+
|
|
411
|
+
## Answer before action
|
|
412
|
+
|
|
413
|
+
When the user asks a question, asks for an opinion, or asks how to
|
|
414
|
+
plan or approach something, **answer the question first**. Don't
|
|
415
|
+
jump straight into delegating to a subagent or making tool calls
|
|
416
|
+
unless the user has clearly asked for an action ("do X", "fix Y",
|
|
417
|
+
"build Z"). If the user is exploring or thinking out loud, think
|
|
418
|
+
with them — don't sprint to implementation.
|
|
419
|
+
"""
|
|
420
|
+
|
|
421
|
+
static const mainAgentTools = [
|
|
422
|
+
researchAgent.partial(allowHandoff: false),
|
|
423
|
+
codeAgent.partial(allowHandoff: false),
|
|
424
|
+
reviewAgent.partial(allowHandoff: false),
|
|
425
|
+
oracleAgent.partial(allowHandoff: false),
|
|
426
|
+
explorerAgent.partial(allowHandoff: false),
|
|
427
|
+
]
|
|
428
|
+
|
|
429
|
+
def mainAgent(prompt: string): string {
|
|
430
|
+
thread(label: "main", summarize: true, session: "main") {
|
|
431
|
+
setMemoryId("main")
|
|
432
|
+
if (first) {
|
|
433
|
+
// `_context` carries the per-run grounding (date, cwd, AGENTS.md),
|
|
434
|
+
// set by `setupSession`. Appending it to the system prompt is what
|
|
435
|
+
// actually gets that context to the LLM.
|
|
436
|
+
systemMessage(mainAgentSystemPrompt + _context)
|
|
437
|
+
first = false
|
|
438
|
+
}
|
|
439
|
+
const result = llm(prompt, {
|
|
440
|
+
memory: true,
|
|
441
|
+
tools: mainAgentTools
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
return result
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Dispatch one turn. `target` empty (or "main") runs the coordinator
|
|
448
|
+
// `mainAgent`, which routes as usual; any subagent name routes the turn
|
|
449
|
+
// directly to that subagent. All subagents share `(userMsg, allowHandoff)`
|
|
450
|
+
// and the seed turn never hands off (allowHandoff: false). Used by both
|
|
451
|
+
// the one-shot path and the interactive seed turn.
|
|
452
|
+
export def agentReplyVia(target: string, userMsg: string): string {
|
|
453
|
+
const expanded = expandSlash(userMsg, projectCommands)
|
|
454
|
+
if (target == "code") {
|
|
455
|
+
return codeAgent(expanded, false)
|
|
456
|
+
}
|
|
457
|
+
if (target == "research") {
|
|
458
|
+
return researchAgent(expanded, false)
|
|
459
|
+
}
|
|
460
|
+
if (target == "oracle") {
|
|
461
|
+
return oracleAgent(expanded, false)
|
|
462
|
+
}
|
|
463
|
+
if (target == "explorer") {
|
|
464
|
+
return explorerAgent(expanded, false)
|
|
465
|
+
}
|
|
466
|
+
if (target == "review") {
|
|
467
|
+
return reviewAgent(expanded, false)
|
|
468
|
+
}
|
|
469
|
+
return mainAgent(expanded)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// The agent's core turn, decoupled from the terminal: expand any project
|
|
473
|
+
// slash command, then run the prompt through `mainAgent` and return the
|
|
474
|
+
// reply. The REPL (`main` / `_runTurn`) owns input, output, and built-in
|
|
475
|
+
// commands; everything the *agent* does for a user message lives here, so
|
|
476
|
+
// it can be driven and tested without a terminal or user input. See
|
|
477
|
+
// `tests/agentTurn.agency`.
|
|
478
|
+
export def agentReply(userMsg: string): string {
|
|
479
|
+
return agentReplyVia("", userMsg)
|
|
480
|
+
}
|
|
481
|
+
|
|
243
482
|
def roundedCost(): string {
|
|
244
483
|
return "$${getCost().toFixed(4)}"
|
|
245
484
|
}
|
|
@@ -258,62 +497,286 @@ def sample(arr: any[]): any {
|
|
|
258
497
|
|
|
259
498
|
def printHeader() {
|
|
260
499
|
const fig = sample(figs)
|
|
261
|
-
const data = box(
|
|
500
|
+
const data = box(
|
|
501
|
+
title: "Agency",
|
|
502
|
+
padding: 1,
|
|
503
|
+
borderColor: "cyan",
|
|
504
|
+
titleColor: "cyan",
|
|
505
|
+
width: "full",
|
|
506
|
+
) as b {
|
|
262
507
|
b.row(gap: 1) as r {
|
|
263
|
-
r.column() as left {
|
|
508
|
+
r.column(width: "66%") as left {
|
|
264
509
|
left.text("Welcome to the Agency Agent!", bold: true)
|
|
265
510
|
left.text("Ask me to write code, look up docs, or just chat.")
|
|
511
|
+
left.text("All costs are estimates. Actual costs may be higher.", dim: true)
|
|
266
512
|
left.hline()
|
|
267
513
|
left.text("Getting Started", bold: true, fgColor: "cyan")
|
|
268
514
|
left.text("/help for commands · /exit to quit", dim: true)
|
|
269
515
|
}
|
|
270
516
|
r.vline()
|
|
271
|
-
r.column() as right {
|
|
272
|
-
right.raw(fig)
|
|
517
|
+
r.column(width: "30%", align: "center") as right {
|
|
518
|
+
right.raw(fig, align: "center")
|
|
273
519
|
}
|
|
274
520
|
}
|
|
275
521
|
}
|
|
276
522
|
print(render(data, color: true))
|
|
277
523
|
}
|
|
278
524
|
|
|
279
|
-
|
|
280
|
-
|
|
525
|
+
def givePolicyChoice() {
|
|
526
|
+
const title = "Welcome to the agency agent. Please pick a policy to start."
|
|
527
|
+
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."
|
|
528
|
+
let items: ChoiceItem[] = [
|
|
529
|
+
{
|
|
530
|
+
key: "minimal",
|
|
531
|
+
label: "minimal default policy, you do most approvals manually"
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
key: "recommended",
|
|
535
|
+
label: "recommended default policy, allow reading files and browsing the web, no writes"
|
|
536
|
+
},
|
|
537
|
+
]
|
|
538
|
+
|
|
539
|
+
const answer = chooseOption(title, body, items, allowFreeText: true)
|
|
540
|
+
match(answer) {
|
|
541
|
+
"minimal" => return minimalAutoApprovePolicy
|
|
542
|
+
"recommended" => return recommendedAutoApprovePolicy
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Shared session setup for both interactive and one-shot modes. Builds
|
|
547
|
+
// the per-run grounding context, loads (or initializes) the policy, and
|
|
548
|
+
// returns the installed CLI policy handler. `interactive` gates the
|
|
549
|
+
// first-run policy-choice prompt: one-shot has no user to answer it, so
|
|
550
|
+
// it falls back to the recommended default (reads/web auto-approved;
|
|
551
|
+
// writes still require approval, which a non-interactive run can't
|
|
552
|
+
// grant — those tasks block, which is the safe behavior).
|
|
553
|
+
def setupSession(interactive: boolean): any {
|
|
554
|
+
// Point every path-taking tool at the user's working directory so the
|
|
555
|
+
// agent's relative file/shell commands resolve against where the user
|
|
556
|
+
// launched it. The user (via the agent) can change this later with
|
|
557
|
+
// setAgentCwd.
|
|
558
|
+
setAgentCwd(cwd())
|
|
281
559
|
|
|
282
|
-
// Grounding: the LLM
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
// Project context: if the user keeps an AGENTS.md at the workspace
|
|
287
|
-
// root (Anthropic / Pi / Aider all read it), inline it so the LLM
|
|
288
|
-
// automatically follows the project's conventions.
|
|
560
|
+
// Grounding: the LLM shouldn't have to ask where it is or what day it
|
|
561
|
+
// is. Project context: inline an AGENTS.md from the workspace root if
|
|
562
|
+
// present so the LLM follows the project's conventions.
|
|
289
563
|
const projectContext = loadAgentsMd(cwd()) with approve
|
|
290
564
|
_context = "\n\nCurrent date: ${today()}\nCurrent working directory: ${cwd()}${projectContext}"
|
|
291
565
|
|
|
566
|
+
const policy = parsePolicyFile(POLICY_PATH)
|
|
567
|
+
if (policy is failure(f)) {
|
|
568
|
+
if (f.status == "doesnt-exist") {
|
|
569
|
+
if (interactive) {
|
|
570
|
+
print(color.yellow("No existing policy found at ${POLICY_PATH}."))
|
|
571
|
+
setPolicy(POLICY_PATH, givePolicyChoice())
|
|
572
|
+
} else {
|
|
573
|
+
setPolicy(POLICY_PATH, recommendedAutoApprovePolicy)
|
|
574
|
+
}
|
|
575
|
+
} else {
|
|
576
|
+
print(color.red("Failed to load policy: ${JSON.stringify(f.error)}"))
|
|
577
|
+
process.exit(1)
|
|
578
|
+
}
|
|
579
|
+
} else {
|
|
580
|
+
setPolicy(POLICY_PATH, policy.value)
|
|
581
|
+
}
|
|
292
582
|
// Bind the handler to a local var so `with handler` parses (the
|
|
293
583
|
// `with` clause only accepts an identifier, not a call expression).
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
584
|
+
return cliPolicyHandler(file: POLICY_PATH, fields: ALWAYS_FIELDS)
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// One-shot entry: run a single turn through the same `mainAgent` the
|
|
588
|
+
// REPL uses, with the same session setup and policy handler, and return
|
|
589
|
+
// the reply. Used for `agency agent -p "..."`, a positional query, or
|
|
590
|
+
// piped stdin. Slash commands are expanded so `-p /foo bar` works like
|
|
591
|
+
// typing it in the REPL; the loop-only built-ins (`/exit` etc.) are
|
|
592
|
+
// meaningless here and aren't checked.
|
|
593
|
+
def oneShotAgent(target: string, prompt: string): string {
|
|
594
|
+
_isInteractive = false
|
|
595
|
+
const handler = setupSession(false)
|
|
596
|
+
let reply: string = ""
|
|
303
597
|
handle {
|
|
598
|
+
reply = agentReplyVia(target, prompt)
|
|
599
|
+
} with (data) {
|
|
600
|
+
return handler(data)
|
|
601
|
+
}
|
|
602
|
+
return reply
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// Render one seeded turn into the REPL scroll area: echo the auto-run
|
|
606
|
+
// prompt so the user sees what was asked, then push the agent's reply.
|
|
607
|
+
// Mirrors the reply-rendering half of `_runTurn`.
|
|
608
|
+
def _runSeedTurn(target: string, msg: string) {
|
|
609
|
+
pushMessage(color.dim("> ${msg}"))
|
|
610
|
+
const reply = agentReplyVia(target, msg)
|
|
611
|
+
if (reply != "" && reply != null && reply != undefined) {
|
|
612
|
+
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
613
|
+
} else {
|
|
614
|
+
pushMessage(color.red("No reply generated."))
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// Start the interactive REPL. When `seedPrompt` is non-empty it is run as
|
|
619
|
+
// the first turn (routed via `seedTarget`) *inside* the handle block so
|
|
620
|
+
// its interrupts reach the policy `handler`; the user is then left at the
|
|
621
|
+
// prompt. `seedPrompt == ""` is the plain REPL with no seed. Subsequent
|
|
622
|
+
// turns always go through `_runTurn` (the coordinator) regardless of
|
|
623
|
+
// `seedTarget` — the target only kicks off the first turn.
|
|
624
|
+
def startInteractive(handler: any, seedTarget: string, seedPrompt: string) {
|
|
625
|
+
handle {
|
|
626
|
+
if (seedPrompt != "") {
|
|
627
|
+
_runSeedTurn(seedTarget, seedPrompt)
|
|
628
|
+
}
|
|
304
629
|
repl(
|
|
305
630
|
status: _buildStatus,
|
|
306
631
|
onSubmit: _runTurn,
|
|
307
632
|
prompt: "> ",
|
|
308
|
-
historyFile:
|
|
633
|
+
historyFile: HISTORY_PATH,
|
|
309
634
|
historyMax: 1000,
|
|
310
|
-
paletteCommands:
|
|
311
|
-
"/exit": "Exit the agent",
|
|
312
|
-
"/clear": "Clear the conversation transcript",
|
|
313
|
-
"/help": "Show available slash commands"
|
|
314
|
-
},
|
|
635
|
+
paletteCommands: mergedPalette(),
|
|
315
636
|
)
|
|
316
|
-
} with
|
|
317
|
-
|
|
637
|
+
} with (data) {
|
|
638
|
+
return handler(data)
|
|
639
|
+
}
|
|
318
640
|
print(color.cyan("\nGoodbye!"))
|
|
319
641
|
}
|
|
642
|
+
|
|
643
|
+
node main() {
|
|
644
|
+
// Parse CLI flags first — `parseArgs` exits on --help / --version /
|
|
645
|
+
// usage errors, before any handlers or the TUI are installed.
|
|
646
|
+
const args = parseArgs(
|
|
647
|
+
{
|
|
648
|
+
programName: "agency agent",
|
|
649
|
+
description: "Agency language assistant — interactive REPL by default; one-shot when piped or passed a query / --print.",
|
|
650
|
+
version: getVersion(),
|
|
651
|
+
flags: {
|
|
652
|
+
print: {
|
|
653
|
+
type: "boolean",
|
|
654
|
+
short: "p",
|
|
655
|
+
description: "Run one-shot: print the reply to stdout and exit (no REPL)"
|
|
656
|
+
},
|
|
657
|
+
debug: {
|
|
658
|
+
type: "boolean",
|
|
659
|
+
description: "Log tool returns (toolName, result, timing). Same as AGENT_DEBUG=1"
|
|
660
|
+
},
|
|
661
|
+
verbose: {
|
|
662
|
+
type: "boolean",
|
|
663
|
+
description: "Echo tool-call starts to stdout in non-interactive mode"
|
|
664
|
+
},
|
|
665
|
+
model: {
|
|
666
|
+
type: "string",
|
|
667
|
+
description: "Model for all LLM calls (overrides provider auto-detection)"
|
|
668
|
+
},
|
|
669
|
+
fastmodel: {
|
|
670
|
+
type: "string",
|
|
671
|
+
description: "Model for ordinary work (default: per detected provider)"
|
|
672
|
+
},
|
|
673
|
+
slowmodel: {
|
|
674
|
+
type: "string",
|
|
675
|
+
description: "Model for deep reasoning, e.g. the oracle/explorer subagents"
|
|
676
|
+
},
|
|
677
|
+
provider: {
|
|
678
|
+
type: "string",
|
|
679
|
+
description: "Force the LLM provider (use when a model name doesn't imply one)"
|
|
680
|
+
},
|
|
681
|
+
interactive: {
|
|
682
|
+
type: "boolean",
|
|
683
|
+
short: "i",
|
|
684
|
+
description: "Run the given prompt as the first turn of an interactive session, then hand over the REPL (instead of one-shot)"
|
|
685
|
+
},
|
|
686
|
+
agent: {
|
|
687
|
+
type: "string",
|
|
688
|
+
description: "Route the starting prompt to a named subagent: code, research, oracle, explorer, review (default: coordinator)"
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
)
|
|
693
|
+
|
|
694
|
+
if (args.flags.debug) {
|
|
695
|
+
AGENT_DEBUG = true
|
|
696
|
+
}
|
|
697
|
+
if (args.flags.verbose) {
|
|
698
|
+
VERBOSE = true
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// Resolve which models to use. Explicit flags win; otherwise detect a
|
|
702
|
+
// provider from API-key env vars and use that provider's defaults. The
|
|
703
|
+
// fast model becomes the run-wide default via `setModel`; the slow
|
|
704
|
+
// model is read by the deep-reasoning subagents (oracle, explorer).
|
|
705
|
+
// Resolve + apply the fast/slow models. Absent string flags read as
|
|
706
|
+
// `undefined`, and agency's `== null` does not match `undefined`, so
|
|
707
|
+
// normalize via `??` (which does treat `undefined` as nullish) to "".
|
|
708
|
+
configureModels(
|
|
709
|
+
args.flags.model ?? "",
|
|
710
|
+
args.flags.fastmodel ?? "",
|
|
711
|
+
args.flags.slowmodel ?? "",
|
|
712
|
+
args.flags.provider ?? "",
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
// Positional args (everything after flags) are joined with spaces to
|
|
716
|
+
// form the starting prompt. `--` ends flag parsing if a positional
|
|
717
|
+
// would otherwise look like a flag.
|
|
718
|
+
const positionalQuery = args.positionals.join(" ")
|
|
719
|
+
const hasQuery = positionalQuery != ""
|
|
720
|
+
const startAgent = args.flags.agent ?? ""
|
|
721
|
+
const wantInteractive = args.flags.interactive
|
|
722
|
+
|
|
723
|
+
// Validate the target subagent name up front (empty = coordinator).
|
|
724
|
+
if (startAgent != "" && !START_AGENTS.includes(startAgent)) {
|
|
725
|
+
print(
|
|
726
|
+
color.red(
|
|
727
|
+
"Unknown --agent value: ${startAgent}. Valid: ${START_AGENTS.join(", ")}",
|
|
728
|
+
),
|
|
729
|
+
)
|
|
730
|
+
process.exit(1)
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// Seeded interactive: run the given prompt as the first turn, then hand
|
|
734
|
+
// the REPL to the user. Requires a seed prompt and a TTY (the REPL reads
|
|
735
|
+
// stdin). `--print` wins if both are passed — its whole job is to print
|
|
736
|
+
// and exit with no REPL. Without a TTY (or with `--print`) we fall
|
|
737
|
+
// through to one-shot below; `--interactive` with no prompt falls through
|
|
738
|
+
// to the plain REPL.
|
|
739
|
+
if (wantInteractive && hasQuery && isTTY() && !args.flags.print) {
|
|
740
|
+
setTitle("Agency Agent")
|
|
741
|
+
clearScreen()
|
|
742
|
+
printHeader()
|
|
743
|
+
const seededHandler = setupSession(true)
|
|
744
|
+
startInteractive(seededHandler, startAgent, positionalQuery)
|
|
745
|
+
process.exit(0)
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// One-shot invocation: run one turn through the same agent the REPL uses
|
|
749
|
+
// and write the reply to stdout. No banner, no REPL. Entered when
|
|
750
|
+
// `--print` / `-p` is passed, a positional query is given, or stdin is
|
|
751
|
+
// piped (no TTY) — so the agent behaves like a Unix filter:
|
|
752
|
+
// `echo "..." | agency agent`. `--interactive` is NOT a one-shot trigger
|
|
753
|
+
// on its own: with a TTY and no prompt it falls through to the plain
|
|
754
|
+
// REPL; without a TTY the `!isTTY()` check below routes it here to
|
|
755
|
+
// degrade gracefully. The prompt comes from the positional when present,
|
|
756
|
+
// otherwise from stdin. (Title/clearScreen are skipped so piped output
|
|
757
|
+
// stays free of escape codes.)
|
|
758
|
+
const forceOneShot = args.flags.print || hasQuery
|
|
759
|
+
if (forceOneShot || !isTTY()) {
|
|
760
|
+
let prompt = positionalQuery
|
|
761
|
+
if (!hasQuery) {
|
|
762
|
+
const fromStdin = readStdin()
|
|
763
|
+
if (fromStdin == null || fromStdin == "") {
|
|
764
|
+
process.exit(0)
|
|
765
|
+
}
|
|
766
|
+
prompt = fromStdin
|
|
767
|
+
}
|
|
768
|
+
print(oneShotAgent(startAgent, prompt))
|
|
769
|
+
process.exit(0)
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// Plain interactive REPL (no seed). `startInteractive` owns the runloop;
|
|
773
|
+
// every Enter dispatches into `_runTurn` which calls `mainAgent`.
|
|
774
|
+
// Interrupts raised during a turn propagate to the policy handler
|
|
775
|
+
// installed by the enclosing `handle` block via the AsyncLocalStorage
|
|
776
|
+
// handler stack.
|
|
777
|
+
setTitle("Agency Agent")
|
|
778
|
+
clearScreen()
|
|
779
|
+
printHeader()
|
|
780
|
+
const handler = setupSession(true)
|
|
781
|
+
startInteractive(handler, "", "")
|
|
782
|
+
}
|