agency-lang 0.5.0 → 0.6.1
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 +307 -111
- package/dist/lib/agents/agency-agent/agent.js +1864 -524
- package/dist/lib/agents/agency-agent/images/images.js +2 -1
- package/dist/lib/agents/agency-agent/lib/config.agency +3 -3
- package/dist/lib/agents/agency-agent/lib/config.js +2 -1
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.agency +33 -1
- package/dist/lib/agents/agency-agent/lib/defaultPolicy.js +164 -4
- package/dist/lib/agents/agency-agent/lib/utils.js +19 -1
- package/dist/lib/agents/agency-agent/prompts/codeSample.js +21 -2
- package/dist/lib/agents/agency-agent/shared.agency +101 -2
- package/dist/lib/agents/agency-agent/shared.js +541 -3
- package/dist/lib/agents/agency-agent/subagents/code.agency +77 -49
- package/dist/lib/agents/agency-agent/subagents/code.js +144 -96
- package/dist/lib/agents/agency-agent/subagents/explorer.agency +11 -13
- package/dist/lib/agents/agency-agent/subagents/explorer.js +49 -21
- package/dist/lib/agents/agency-agent/subagents/oracle.agency +11 -12
- package/dist/lib/agents/agency-agent/subagents/oracle.js +49 -19
- package/dist/lib/agents/agency-agent/subagents/research.agency +9 -3
- package/dist/lib/agents/agency-agent/subagents/research.js +21 -6
- package/dist/lib/agents/agency-agent/subagents/review.agency +6 -6
- package/dist/lib/agents/agency-agent/subagents/review.js +28 -61
- package/dist/lib/agents/agency-agent/tests/agentTurn.agency +15 -0
- package/dist/lib/agents/agency-agent/{subagents/oneShot.js → tests/agentTurn.js} +78 -76
- 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/docs/cli/cli/eval-judge.md +7 -7
- package/dist/lib/agents/docs/cli/cli/eval.md +26 -91
- package/dist/lib/agents/docs/cli/cli/optimize.md +181 -0
- package/dist/lib/agents/docs/cli/eval-judge.md +7 -7
- package/dist/lib/agents/docs/cli/eval.md +26 -91
- package/dist/lib/agents/docs/cli/optimize.md +181 -0
- package/dist/lib/agents/docs/guide/effects-and-raises.md +156 -0
- package/dist/lib/agents/docs/guide/guide/effects-and-raises.md +156 -0
- package/dist/lib/agents/docs/guide/guide/handlers.md +2 -2
- package/dist/lib/agents/docs/guide/guide/observability.md +6 -0
- package/dist/lib/agents/docs/guide/guide/partial-application.md +26 -0
- package/dist/lib/agents/docs/guide/guide/policies.md +3 -3
- package/dist/lib/agents/docs/guide/guide/serving.md +1 -1
- package/dist/lib/agents/docs/guide/guide/structured-interrupts.md +8 -8
- package/dist/lib/agents/docs/guide/guide/troubleshooting.md +56 -1
- package/dist/lib/agents/docs/guide/guide/ts-interop.md +1 -1
- package/dist/lib/agents/docs/guide/handlers.md +2 -2
- package/dist/lib/agents/docs/guide/observability.md +6 -0
- package/dist/lib/agents/docs/guide/partial-application.md +26 -0
- package/dist/lib/agents/docs/guide/policies.md +3 -3
- package/dist/lib/agents/docs/guide/serving.md +1 -1
- package/dist/lib/agents/docs/guide/structured-interrupts.md +8 -8
- package/dist/lib/agents/docs/guide/troubleshooting.md +56 -1
- package/dist/lib/agents/docs/guide/ts-interop.md +1 -1
- package/dist/lib/agents/eval/goalJudge.agency +24 -0
- package/dist/lib/agents/eval/goalJudge.js +313 -0
- package/dist/lib/agents/{judge.js → eval/judge.js} +12 -7
- package/dist/lib/agents/eval/judgePairwise.js +313 -0
- package/dist/lib/agents/optimize/gepaReflect.agency +58 -0
- package/dist/lib/agents/optimize/gepaReflect.js +325 -0
- package/dist/lib/agents/{mutatePrompt.agency → optimize/mutatePrompt.agency} +7 -1
- package/dist/lib/agents/{mutatePrompt.js → optimize/mutatePrompt.js} +22 -10
- package/dist/lib/agents/policy/agent.agency +14 -14
- package/dist/lib/agents/policy/agent.js +72 -37
- package/dist/lib/agents/review/agent.js +12 -2
- package/dist/lib/analysis/interrupts.d.ts +3 -3
- package/dist/lib/analysis/interrupts.js +1 -1
- package/dist/lib/analysis/interrupts.test.js +6 -6
- package/dist/lib/backends/agencyGenerator.d.ts +2 -0
- package/dist/lib/backends/agencyGenerator.js +32 -5
- package/dist/lib/backends/anthropicApiKey.codegen.test.js +34 -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/typescriptBuilder/assignmentEmitter.d.ts +5 -2
- package/dist/lib/backends/typescriptBuilder/assignmentEmitter.js +10 -7
- 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.js +53 -22
- package/dist/lib/backends/typescriptGenerator/typeToString.d.ts +0 -3
- package/dist/lib/backends/typescriptGenerator/typeToString.js +19 -0
- package/dist/lib/cli/commands.js +30 -2
- package/dist/lib/cli/doc.js +11 -11
- package/dist/lib/cli/doc.test.js +9 -9
- 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 +14 -10
- package/dist/lib/cli/eval/optimize.js +137 -68
- package/dist/lib/cli/eval/optimize.test.js +132 -129
- package/dist/lib/cli/eval/run.d.ts +22 -15
- package/dist/lib/cli/eval/run.js +38 -26
- package/dist/lib/cli/eval/run.test.js +22 -22
- package/dist/lib/cli/evalJudge.d.ts +1 -1
- package/dist/lib/cli/evalJudge.js +24 -24
- package/dist/lib/cli/evalJudge.test.js +17 -17
- package/dist/lib/cli/interrupts.js +2 -2
- package/dist/lib/cli/interrupts.test.js +9 -9
- package/dist/lib/cli/policy.js +11 -11
- package/dist/lib/cli/runAgencyAgent.js +5 -1
- package/dist/lib/cli/runAgencyAgent.test.js +6 -3
- package/dist/lib/cli/serve.js +24 -15
- package/dist/lib/cli/util.d.ts +45 -1
- package/dist/lib/cli/util.js +31 -20
- 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 +4 -4
- package/dist/lib/compilationUnit.js +13 -11
- package/dist/lib/compiler/compileClosure.d.ts +1 -1
- package/dist/lib/compiler/compileClosure.js +12 -5
- package/dist/lib/config.d.ts +30 -0
- package/dist/lib/config.js +11 -0
- package/dist/lib/eval/extract.d.ts +9 -0
- package/dist/lib/eval/extract.js +24 -7
- package/dist/lib/eval/extract.test.js +68 -28
- package/dist/lib/eval/ids.d.ts +1 -1
- package/dist/lib/eval/ids.js +2 -2
- package/dist/lib/eval/judge/pairwise.d.ts +3 -3
- package/dist/lib/eval/judge/pairwise.js +8 -8
- package/dist/lib/eval/judge/pairwise.test.js +6 -6
- package/dist/lib/eval/judge/suite.d.ts +8 -8
- package/dist/lib/eval/judge/suite.js +42 -41
- package/dist/lib/eval/judge/suite.test.js +37 -37
- package/dist/lib/eval/judge/types.d.ts +6 -5
- 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/readRun.d.ts +5 -5
- package/dist/lib/eval/readRun.js +12 -12
- package/dist/lib/eval/readRun.test.js +37 -37
- package/dist/lib/eval/runArtifacts.d.ts +18 -18
- package/dist/lib/eval/runArtifacts.js +40 -39
- package/dist/lib/eval/runArtifacts.test.js +29 -29
- package/dist/lib/eval/{runEvalTask.d.ts → runEvalInput.d.ts} +13 -13
- package/dist/lib/eval/{runEvalTask.js → runEvalInput.js} +15 -14
- package/dist/lib/eval/runTypes.d.ts +22 -8
- package/dist/lib/eval/statelogParser.d.ts +1 -1
- package/dist/lib/eval/statelogParser.js +2 -2
- package/dist/lib/eval/statelogParser.test.js +2 -2
- package/dist/lib/eval/types.d.ts +5 -5
- package/dist/lib/importPaths.d.ts +5 -0
- package/dist/lib/importPaths.js +7 -0
- package/dist/lib/ir/builders.d.ts +1 -1
- package/dist/lib/ir/builders.js +2 -2
- package/dist/lib/ir/prettyPrint.js +9 -0
- package/dist/lib/ir/prettyPrint.test.js +11 -0
- package/dist/lib/ir/tsIR.d.ts +5 -0
- package/dist/lib/logsViewer/conversation.js +4 -1
- package/dist/lib/logsViewer/conversation.test.js +18 -0
- package/dist/lib/logsViewer/follow.js +16 -2
- package/dist/lib/logsViewer/follow.test.js +31 -0
- package/dist/lib/logsViewer/help.js +2 -1
- package/dist/lib/logsViewer/input.js +42 -4
- package/dist/lib/logsViewer/input.test.js +51 -18
- package/dist/lib/logsViewer/render.d.ts +1 -0
- package/dist/lib/logsViewer/render.e2e.test.d.ts +1 -0
- package/dist/lib/logsViewer/render.e2e.test.js +156 -0
- package/dist/lib/logsViewer/render.flatten.test.d.ts +1 -0
- package/dist/lib/logsViewer/render.flatten.test.js +240 -0
- package/dist/lib/logsViewer/render.js +112 -33
- package/dist/lib/logsViewer/render.test.js +38 -0
- package/dist/lib/logsViewer/search.js +41 -12
- package/dist/lib/logsViewer/search.test.js +84 -0
- package/dist/lib/logsViewer/summary.js +146 -15
- package/dist/lib/logsViewer/summary.test.js +151 -0
- package/dist/lib/logsViewer/tree.js +31 -31
- package/dist/lib/logsViewer/tree.test.js +47 -17
- 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/optimize/artifacts.d.ts +1 -1
- package/dist/lib/optimize/artifacts.js +1 -1
- package/dist/lib/optimize/artifacts.test.js +3 -3
- 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/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 +2 -2
- package/dist/lib/optimize/loop.js +38 -35
- package/dist/lib/optimize/loop.test.js +11 -11
- package/dist/lib/optimize/mutator.d.ts +28 -4
- package/dist/lib/optimize/mutator.js +19 -13
- package/dist/lib/optimize/mutator.test.js +25 -12
- 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 +56 -6
- package/dist/lib/optimize/reporter.js +75 -3
- package/dist/lib/optimize/reporter.test.js +70 -11
- 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 +2 -0
- package/dist/lib/optimize/sourceMutator.js +16 -2
- package/dist/lib/optimize/sourceMutator.test.js +16 -2
- package/dist/lib/optimize/targets.d.ts +2 -0
- package/dist/lib/optimize/targets.js +4 -0
- package/dist/lib/optimize/types.d.ts +13 -3
- 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.js +2 -2
- package/dist/lib/parsers/effectSet.test.d.ts +1 -0
- package/dist/lib/parsers/effectSet.test.js +96 -0
- package/dist/lib/parsers/handleBlock.test.js +20 -1
- package/dist/lib/parsers/interruptStatement.test.js +29 -8
- package/dist/lib/parsers/parsers.d.ts +4 -0
- package/dist/lib/parsers/parsers.js +154 -14
- 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/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/agencyFunction.d.ts +14 -0
- package/dist/lib/runtime/agencyFunction.js +28 -0
- package/dist/lib/runtime/agencyFunction.test.js +49 -0
- 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/call.js +13 -0
- package/dist/lib/runtime/configOverrides.d.ts +1 -0
- package/dist/lib/runtime/deterministicClient.d.ts +1 -1
- package/dist/lib/runtime/deterministicClient.test.js +9 -9
- package/dist/lib/runtime/errors.d.ts +63 -4
- package/dist/lib/runtime/errors.js +58 -6
- package/dist/lib/runtime/errors.test.js +70 -1
- package/dist/lib/runtime/guard.d.ts +3 -0
- package/dist/lib/runtime/guard.js +39 -1
- package/dist/lib/runtime/guard.test.js +18 -0
- package/dist/lib/runtime/index.d.ts +1 -1
- package/dist/lib/runtime/index.js +1 -1
- package/dist/lib/runtime/interrupts.d.ts +18 -4
- package/dist/lib/runtime/interrupts.js +37 -12
- package/dist/lib/runtime/interrupts.test.js +58 -5
- package/dist/lib/runtime/ipc.configOverrides.test.js +4 -4
- package/dist/lib/runtime/ipc.d.ts +2 -2
- package/dist/lib/runtime/ipc.js +3 -3
- package/dist/lib/runtime/isDebugger.test.js +3 -3
- package/dist/lib/runtime/node.js +3 -0
- 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 +229 -63
- package/dist/lib/runtime/prompt.test.d.ts +1 -0
- package/dist/lib/runtime/prompt.test.js +79 -0
- package/dist/lib/runtime/promptRunner.d.ts +1 -1
- package/dist/lib/runtime/promptRunner.js +11 -0
- package/dist/lib/runtime/result.js +43 -17
- package/dist/lib/runtime/result.test.js +65 -1
- package/dist/lib/runtime/runBatch.d.ts +4 -2
- package/dist/lib/runtime/runBatch.js +20 -3
- package/dist/lib/runtime/runBatch.test.js +41 -1
- package/dist/lib/runtime/runner.d.ts +8 -0
- package/dist/lib/runtime/runner.js +50 -25
- package/dist/lib/runtime/runner.test.js +69 -2
- package/dist/lib/runtime/state/context.d.ts +25 -1
- package/dist/lib/runtime/state/context.js +73 -22
- package/dist/lib/runtime/state/globalStore.js +6 -0
- package/dist/lib/runtime/state/stateStack.d.ts +29 -0
- package/dist/lib/runtime/state/stateStack.js +63 -0
- package/dist/lib/runtime/types.d.ts +1 -1
- package/dist/lib/runtime/utils.d.ts +15 -0
- package/dist/lib/runtime/utils.js +37 -1
- package/dist/lib/runtime/utils.test.js +60 -1
- 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 +52 -2
- package/dist/lib/serve/http/adapter.test.js +41 -8
- package/dist/lib/serve/mcp/adapter.d.ts +7 -1
- package/dist/lib/serve/mcp/adapter.js +68 -22
- package/dist/lib/serve/mcp/adapter.test.js +51 -16
- package/dist/lib/serve/mcp/httpTransport.d.ts +5 -0
- package/dist/lib/serve/mcp/httpTransport.js +2 -0
- 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/statelogClient.d.ts +24 -6
- package/dist/lib/statelogClient.js +34 -11
- package/dist/lib/statelogClient.test.js +48 -0
- package/dist/lib/stdlib/abortable.js +20 -9
- package/dist/lib/stdlib/agencyEval.d.ts +18 -18
- package/dist/lib/stdlib/agencyEval.js +29 -29
- package/dist/lib/stdlib/cli.d.ts +63 -0
- package/dist/lib/stdlib/cli.js +320 -24
- package/dist/lib/stdlib/fs.d.ts +5 -8
- package/dist/lib/stdlib/fs.js +28 -18
- package/dist/lib/stdlib/layout/axis.d.ts +3 -0
- package/dist/lib/stdlib/layout/axis.js +25 -2
- package/dist/lib/stdlib/layout/barchart.d.ts +33 -0
- package/dist/lib/stdlib/layout/barchart.js +217 -0
- package/dist/lib/stdlib/layout/box.d.ts +2 -0
- package/dist/lib/stdlib/layout/box.js +12 -1
- package/dist/lib/stdlib/layout/nodes.d.ts +7 -1
- package/dist/lib/stdlib/layout/nodes.js +33 -2
- package/dist/lib/stdlib/layout/render.d.ts +4 -5
- package/dist/lib/stdlib/layout/render.js +60 -124
- 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 +2 -0
- package/dist/lib/stdlib/layout/table.js +7 -0
- package/dist/lib/stdlib/layout.d.ts +12 -1
- package/dist/lib/stdlib/layout.js +11 -7
- package/dist/lib/stdlib/llm.d.ts +29 -0
- package/dist/lib/stdlib/llm.js +29 -0
- 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 +2 -2
- package/dist/lib/stdlib/statelog.js +5 -5
- 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 +81 -69
- package/dist/lib/stdlib/thread.d.ts +12 -0
- package/dist/lib/stdlib/thread.js +15 -0
- package/dist/lib/stdlib/ui.d.ts +1 -1
- package/dist/lib/stdlib/ui.js +27 -2
- 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 +1 -0
- 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 +2 -1
- 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 +7 -6
- package/dist/lib/templates/cli/standaloneMcpHttp.d.ts +2 -2
- package/dist/lib/templates/cli/standaloneMcpHttp.js +7 -5
- package/dist/lib/typeChecker/agencyFunctionMethods.test.d.ts +1 -0
- package/dist/lib/typeChecker/agencyFunctionMethods.test.js +91 -0
- package/dist/lib/typeChecker/builtins.d.ts +17 -0
- package/dist/lib/typeChecker/builtins.js +36 -0
- 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 +1 -1
- package/dist/lib/typeChecker/index.js +12 -8
- package/dist/lib/typeChecker/interruptAnalysis.d.ts +6 -6
- package/dist/lib/typeChecker/interruptAnalysis.js +20 -20
- package/dist/lib/typeChecker/interruptAnalysis.test.js +16 -16
- package/dist/lib/typeChecker/interruptCallGraph.test.js +2 -2
- 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/synthesizer.js +8 -29
- package/dist/lib/typeChecker/testUtils.d.ts +13 -0
- package/dist/lib/typeChecker/testUtils.js +37 -0
- package/dist/lib/typeChecker/types.d.ts +3 -3
- 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 +3 -0
- package/dist/lib/types/typeHints.d.ts +13 -0
- package/dist/lib/types.d.ts +3 -0
- package/dist/lib/utils/diff.d.ts +37 -5
- package/dist/lib/utils/diff.js +288 -24
- package/dist/lib/utils/diff.test.js +157 -19
- package/dist/lib/utils/node.js +9 -1
- package/dist/lib/utils/termcolors.d.ts +13 -0
- package/dist/lib/utils/termcolors.js +22 -0
- package/dist/scripts/agency.js +67 -34
- package/dist/scripts/agency.test.js +15 -2
- package/package.json +9 -2
- package/stdlib/agency/eval.agency +57 -56
- package/stdlib/agency/eval.js +89 -71
- package/stdlib/agency.js +51 -1
- package/stdlib/agent.js +30 -1
- package/stdlib/args.js +6 -1
- package/stdlib/array.js +42 -1
- package/stdlib/browser.js +6 -1
- package/stdlib/calendar.js +21 -1
- package/stdlib/chart.agency +157 -0
- package/stdlib/chart.js +982 -0
- package/stdlib/cli.agency +6 -0
- package/stdlib/cli.js +31 -5
- package/stdlib/clipboard.js +9 -1
- package/stdlib/concurrency.js +6 -1
- package/stdlib/date.js +48 -1
- package/stdlib/email.js +12 -1
- package/stdlib/fs.agency +35 -107
- package/stdlib/fs.js +254 -450
- package/stdlib/http.js +12 -1
- package/stdlib/imessage.js +6 -1
- package/stdlib/index.agency +64 -2
- package/stdlib/index.js +563 -29
- package/stdlib/keyring.js +15 -1
- package/stdlib/layout.agency +2 -228
- package/stdlib/layout.js +58 -1227
- package/stdlib/llm.agency +91 -0
- package/stdlib/llm.js +787 -0
- package/stdlib/markdown.js +15 -1
- package/stdlib/math.js +15 -1
- package/stdlib/memory.agency +19 -2
- package/stdlib/memory.js +152 -5
- package/stdlib/oauth.js +15 -1
- package/stdlib/object.js +18 -1
- package/stdlib/path.js +24 -1
- package/stdlib/policy.agency +180 -73
- package/stdlib/policy.js +650 -78
- package/stdlib/schemas.js +2 -1
- package/stdlib/search.js +6 -1
- package/stdlib/shell.agency +44 -2
- package/stdlib/shell.js +331 -62
- package/stdlib/skills.agency +50 -6
- package/stdlib/skills.js +224 -29
- package/stdlib/sms.js +6 -1
- package/stdlib/speech.js +12 -1
- package/stdlib/statelog.agency +15 -15
- package/stdlib/statelog.js +58 -38
- package/stdlib/strategy.js +20 -1
- package/stdlib/syntax.agency +175 -2
- package/stdlib/syntax.js +667 -9
- package/stdlib/system.js +36 -1
- package/stdlib/table.agency +202 -0
- package/stdlib/table.js +1427 -0
- package/stdlib/thread.agency +24 -0
- package/stdlib/thread.js +145 -3
- package/stdlib/threads.js +18 -1
- package/stdlib/types.js +2 -1
- package/stdlib/ui.agency +20 -1
- package/stdlib/ui.js +244 -19
- package/stdlib/validators.js +36 -1
- package/stdlib/weather.js +12 -1
- package/stdlib/wikipedia.js +12 -1
- package/dist/lib/agents/agency-agent/code.js +0 -532
- package/dist/lib/agents/agency-agent/research.js +0 -311
- package/dist/lib/agents/agency-agent/subagents/oneShot.agency +0 -49
- package/dist/lib/eval/loadTasks.d.ts +0 -6
- package/dist/lib/eval/loadTasks.js +0 -81
- package/dist/lib/eval/loadTasks.test.js +0 -60
- package/dist/lib/optimize/tasks.d.ts +0 -2
- package/dist/lib/optimize/tasks.js +0 -9
- package/dist/lib/optimize/tasks.test.js +0 -17
- /package/dist/lib/agents/{judge.agency → eval/judge.agency} +0 -0
- /package/dist/lib/agents/{judgePairwise.agency → eval/judgePairwise.agency} +0 -0
- /package/dist/lib/{eval/loadTasks.test.d.ts → backends/anthropicApiKey.codegen.test.d.ts} +0 -0
- /package/dist/lib/{optimize/tasks.test.d.ts → backends/maxToolResultChars.codegen.test.d.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getVersion } from "std::agency"
|
|
2
|
-
import { route } from "std::agent"
|
|
3
2
|
import { parseArgs } from "std::args"
|
|
4
3
|
import { clearMessages, pushMessage, repl, clearScreen } from "std::cli"
|
|
5
4
|
import { today } from "std::date"
|
|
5
|
+
import { setAgentCwd } from "std::index"
|
|
6
6
|
import { box, render } from "std::layout"
|
|
7
7
|
import { setMemoryId } from "std::memory"
|
|
8
8
|
import {
|
|
@@ -15,7 +15,7 @@ import { exists } from "std::shell"
|
|
|
15
15
|
import { commandsDir, expandSlash } from "std::skills"
|
|
16
16
|
import { highlight } from "std::syntax"
|
|
17
17
|
import { cwd, env, isTTY, readStdin, setTitle } from "std::system"
|
|
18
|
-
import { getCost,
|
|
18
|
+
import { getCost, getModelCosts, systemMessage } from "std::thread"
|
|
19
19
|
import { chooseOption, ChoiceItem } from "std::ui"
|
|
20
20
|
|
|
21
21
|
import { figs, title } from "./images/images.agency"
|
|
@@ -25,15 +25,11 @@ import {
|
|
|
25
25
|
recommendedAutoApprovePolicy,
|
|
26
26
|
} from "./lib/defaultPolicy.agency"
|
|
27
27
|
import { truncate, formatArgs, formatToolResponse } from "./lib/utils.agency"
|
|
28
|
-
import {
|
|
28
|
+
import { configureModels } from "./shared.agency"
|
|
29
|
+
import { codeAgent } from "./subagents/code.agency"
|
|
29
30
|
import { explorerAgent } from "./subagents/explorer.agency"
|
|
30
|
-
import { oneShotAgent } from "./subagents/oneShot.agency"
|
|
31
31
|
import { oracleAgent } from "./subagents/oracle.agency"
|
|
32
|
-
import {
|
|
33
|
-
researchSysPrompt,
|
|
34
|
-
researchTools,
|
|
35
|
-
researchAgent,
|
|
36
|
-
} from "./subagents/research.agency"
|
|
32
|
+
import { researchAgent } from "./subagents/research.agency"
|
|
37
33
|
import { reviewAgent } from "./subagents/review.agency"
|
|
38
34
|
|
|
39
35
|
|
|
@@ -65,8 +61,8 @@ import { reviewAgent } from "./subagents/review.agency"
|
|
|
65
61
|
*
|
|
66
62
|
* This file's responsibilities collapse to:
|
|
67
63
|
* 1. Per-turn callback (`_runTurn`) wiring the user message into
|
|
68
|
-
*
|
|
69
|
-
* 2. Per-
|
|
64
|
+
* `mainAgent` and printing the reply into the scroll output.
|
|
65
|
+
* 2. Per-effect ALWAYS_FIELDS map for the policy handler's
|
|
70
66
|
* "approve-always-here" option.
|
|
71
67
|
* 3. Wire the two specialists into one `RouterConfig`.
|
|
72
68
|
*
|
|
@@ -91,17 +87,28 @@ let VERBOSE: boolean = false
|
|
|
91
87
|
// scroll-output writes when stdout is destined for a Unix pipe.
|
|
92
88
|
let _isInteractive: boolean = true
|
|
93
89
|
|
|
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
|
|
95
|
+
}
|
|
96
|
+
|
|
94
97
|
callback("onToolCallStart") as data {
|
|
95
|
-
|
|
98
|
+
if (_showTraces()) {
|
|
99
|
+
pushMessage(color.yellow("⏺ ${data.toolName}(${formatArgs(data.args)})"))
|
|
100
|
+
}
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
callback("onToolCallEnd") as data {
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
|
|
@@ -178,6 +185,7 @@ def builtinPalette(): Record<string, string> {
|
|
|
178
185
|
"/exit": "Exit the agent",
|
|
179
186
|
"/clear": "Clear the conversation transcript",
|
|
180
187
|
"/cost": "Show cumulative LLM cost and tokens",
|
|
188
|
+
"/paste": "Multi-line paste mode (Ctrl+D submits, Ctrl+C cancels)",
|
|
181
189
|
"/help": "Show available slash commands"
|
|
182
190
|
}
|
|
183
191
|
}
|
|
@@ -220,18 +228,38 @@ def _runTurn(msg: string): boolean {
|
|
|
220
228
|
return true
|
|
221
229
|
}
|
|
222
230
|
if (trimmed == "/help") {
|
|
223
|
-
pushMessage("Commands: /exit, /clear, /cost, /help")
|
|
231
|
+
pushMessage("Commands: /exit, /clear, /cost, /paste, /help")
|
|
224
232
|
return true
|
|
225
233
|
}
|
|
226
234
|
if (trimmed == "/cost") {
|
|
227
|
-
|
|
228
|
-
|
|
235
|
+
// Derive BOTH the header total and the per-model breakdown from the
|
|
236
|
+
// same process-wide accumulator (getModelCosts), so the `Cost:` /
|
|
237
|
+
// `Tokens:` lines and the rows below them can never visibly disagree.
|
|
238
|
+
// (getCost()/getTokens() read the per-branch accumulator, a different
|
|
239
|
+
// scope — adjacent in the output, they could in principle diverge.)
|
|
240
|
+
// Rows are sorted by cost descending by getModelCosts(); a subagent
|
|
241
|
+
// on a pricier model (e.g. the oracle on opus-4.8) shows up here.
|
|
242
|
+
const byModel = getModelCosts()
|
|
243
|
+
let totalCost = 0.0
|
|
244
|
+
let totalTokens = 0
|
|
245
|
+
for (m in byModel) {
|
|
246
|
+
totalCost = totalCost + m.cost
|
|
247
|
+
totalTokens = totalTokens + m.inputTokens + m.outputTokens
|
|
248
|
+
}
|
|
249
|
+
pushMessage("Cost: $${totalCost.toFixed(4)}")
|
|
250
|
+
pushMessage("Tokens: ${totalTokens}")
|
|
251
|
+
if (byModel.length > 0) {
|
|
252
|
+
pushMessage("")
|
|
253
|
+
pushMessage("By model:")
|
|
254
|
+
for (m in byModel) {
|
|
255
|
+
pushMessage(" ${m.model} ↑${m.inputTokens} ↓${m.outputTokens} $${m.cost.toFixed(4)}")
|
|
256
|
+
}
|
|
257
|
+
}
|
|
229
258
|
return true
|
|
230
259
|
}
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
const
|
|
234
|
-
const reply = mainAgent(prompt)
|
|
260
|
+
// Hand the message to the agent. `agentReply` does the slash-command
|
|
261
|
+
// expansion and the actual agent work; the REPL just renders the reply.
|
|
262
|
+
const reply = agentReply(msg)
|
|
235
263
|
if (reply != "" && reply != null && reply != undefined) {
|
|
236
264
|
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
237
265
|
} else {
|
|
@@ -241,6 +269,12 @@ def _runTurn(msg: string): boolean {
|
|
|
241
269
|
}
|
|
242
270
|
|
|
243
271
|
let first = true
|
|
272
|
+
|
|
273
|
+
// Valid `--agent` targets. Empty / "main" routes through the coordinator;
|
|
274
|
+
// the rest route the starting prompt's first turn directly to that
|
|
275
|
+
// subagent. Used to validate the flag and to dispatch in `agentReplyVia`.
|
|
276
|
+
static const START_AGENTS = ["main", "code", "research", "oracle", "explorer", "review"]
|
|
277
|
+
|
|
244
278
|
static const mainAgentSystemPrompt = """
|
|
245
279
|
You are the top-level coordinator of an Agency-language assistant. You
|
|
246
280
|
receive every user message and decide how to respond.
|
|
@@ -386,6 +420,15 @@ parse → SymbolTable.build → preprocess → TypeScriptBuilder → printTs
|
|
|
386
420
|
Keep diagrams small. Skip them where prose or code is clearer —
|
|
387
421
|
diagrams earn their space by showing **relationships** or **flow**.
|
|
388
422
|
|
|
423
|
+
## Be proactive
|
|
424
|
+
|
|
425
|
+
When the user asks you to look at, debug, or change a file or some code,
|
|
426
|
+
**delegate to `codeAgent` to do it** — don't ask the user to paste a file
|
|
427
|
+
or describe code a subagent could read. The code agent has `read`, `glob`,
|
|
428
|
+
and `ls` and resolves relative paths against the user's working directory
|
|
429
|
+
automatically, so a bare filename like `foo.agency` is enough. Only ask
|
|
430
|
+
the user for information you genuinely cannot obtain through a subagent.
|
|
431
|
+
|
|
389
432
|
## Answer before action
|
|
390
433
|
|
|
391
434
|
When the user asks a question, asks for an opinion, or asks how to
|
|
@@ -408,7 +451,10 @@ def mainAgent(prompt: string): string {
|
|
|
408
451
|
thread(label: "main", summarize: true, session: "main") {
|
|
409
452
|
setMemoryId("main")
|
|
410
453
|
if (first) {
|
|
411
|
-
|
|
454
|
+
// `_context` carries the per-run grounding (date, cwd, AGENTS.md),
|
|
455
|
+
// set by `setupSession`. Appending it to the system prompt is what
|
|
456
|
+
// actually gets that context to the LLM.
|
|
457
|
+
systemMessage(mainAgentSystemPrompt + _context)
|
|
412
458
|
first = false
|
|
413
459
|
}
|
|
414
460
|
const result = llm(prompt, {
|
|
@@ -419,28 +465,39 @@ def mainAgent(prompt: string): string {
|
|
|
419
465
|
return result
|
|
420
466
|
}
|
|
421
467
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
468
|
+
// Dispatch one turn. `target` empty (or "main") runs the coordinator
|
|
469
|
+
// `mainAgent`, which routes as usual; any subagent name routes the turn
|
|
470
|
+
// directly to that subagent. All subagents share `(userMsg, allowHandoff)`
|
|
471
|
+
// and the seed turn never hands off (allowHandoff: false). Used by both
|
|
472
|
+
// the one-shot path and the interactive seed turn.
|
|
473
|
+
export def agentReplyVia(target: string, userMsg: string): string {
|
|
474
|
+
const expanded = expandSlash(userMsg, projectCommands)
|
|
475
|
+
if (target == "code") {
|
|
476
|
+
return codeAgent(expanded, false)
|
|
477
|
+
}
|
|
478
|
+
if (target == "research") {
|
|
479
|
+
return researchAgent(expanded, false)
|
|
480
|
+
}
|
|
481
|
+
if (target == "oracle") {
|
|
482
|
+
return oracleAgent(expanded, false)
|
|
483
|
+
}
|
|
484
|
+
if (target == "explorer") {
|
|
485
|
+
return explorerAgent(expanded, false)
|
|
486
|
+
}
|
|
487
|
+
if (target == "review") {
|
|
488
|
+
return reviewAgent(expanded, false)
|
|
489
|
+
}
|
|
490
|
+
return mainAgent(expanded)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// The agent's core turn, decoupled from the terminal: expand any project
|
|
494
|
+
// slash command, then run the prompt through `mainAgent` and return the
|
|
495
|
+
// reply. The REPL (`main` / `_runTurn`) owns input, output, and built-in
|
|
496
|
+
// commands; everything the *agent* does for a user message lives here, so
|
|
497
|
+
// it can be driven and tested without a terminal or user input. See
|
|
498
|
+
// `tests/agentTurn.agency`.
|
|
499
|
+
export def agentReply(userMsg: string): string {
|
|
500
|
+
return agentReplyVia("", userMsg)
|
|
444
501
|
}
|
|
445
502
|
|
|
446
503
|
def roundedCost(): string {
|
|
@@ -461,9 +518,15 @@ def sample(arr: any[]): any {
|
|
|
461
518
|
|
|
462
519
|
def printHeader() {
|
|
463
520
|
const fig = sample(figs)
|
|
464
|
-
const data = box(
|
|
521
|
+
const data = box(
|
|
522
|
+
title: "Agency",
|
|
523
|
+
padding: 1,
|
|
524
|
+
borderColor: "cyan",
|
|
525
|
+
titleColor: "cyan",
|
|
526
|
+
width: "full",
|
|
527
|
+
) as b {
|
|
465
528
|
b.row(gap: 1) as r {
|
|
466
|
-
r.column() as left {
|
|
529
|
+
r.column(width: "66%") as left {
|
|
467
530
|
left.text("Welcome to the Agency Agent!", bold: true)
|
|
468
531
|
left.text("Ask me to write code, look up docs, or just chat.")
|
|
469
532
|
left.text("All costs are estimates. Actual costs may be higher.", dim: true)
|
|
@@ -472,8 +535,8 @@ def printHeader() {
|
|
|
472
535
|
left.text("/help for commands · /exit to quit", dim: true)
|
|
473
536
|
}
|
|
474
537
|
r.vline()
|
|
475
|
-
r.column() as right {
|
|
476
|
-
right.raw(fig)
|
|
538
|
+
r.column(width: "30%", align: "center") as right {
|
|
539
|
+
right.raw(fig, align: "center")
|
|
477
540
|
}
|
|
478
541
|
}
|
|
479
542
|
}
|
|
@@ -501,6 +564,103 @@ def givePolicyChoice() {
|
|
|
501
564
|
}
|
|
502
565
|
}
|
|
503
566
|
|
|
567
|
+
// Shared session setup for both interactive and one-shot modes. Builds
|
|
568
|
+
// the per-run grounding context, loads (or initializes) the policy, and
|
|
569
|
+
// returns the installed CLI policy handler. `interactive` gates the
|
|
570
|
+
// first-run policy-choice prompt: one-shot has no user to answer it, so
|
|
571
|
+
// it falls back to the recommended default (reads/web auto-approved;
|
|
572
|
+
// writes still require approval, which a non-interactive run can't
|
|
573
|
+
// grant — those tasks block, which is the safe behavior).
|
|
574
|
+
def setupSession(interactive: boolean): any {
|
|
575
|
+
// Point every path-taking tool at the user's working directory so the
|
|
576
|
+
// agent's relative file/shell commands resolve against where the user
|
|
577
|
+
// launched it. The user (via the agent) can change this later with
|
|
578
|
+
// setAgentCwd.
|
|
579
|
+
setAgentCwd(cwd())
|
|
580
|
+
|
|
581
|
+
// Grounding: the LLM shouldn't have to ask where it is or what day it
|
|
582
|
+
// is. Project context: inline an AGENTS.md from the workspace root if
|
|
583
|
+
// present so the LLM follows the project's conventions.
|
|
584
|
+
const projectContext = loadAgentsMd(cwd()) with approve
|
|
585
|
+
_context = "\n\nCurrent date: ${today()}\nCurrent working directory: ${cwd()}${projectContext}"
|
|
586
|
+
|
|
587
|
+
const policy = parsePolicyFile(POLICY_PATH)
|
|
588
|
+
if (policy is failure(f)) {
|
|
589
|
+
if (f.status == "doesnt-exist") {
|
|
590
|
+
if (interactive) {
|
|
591
|
+
print(color.yellow("No existing policy found at ${POLICY_PATH}."))
|
|
592
|
+
setPolicy(POLICY_PATH, givePolicyChoice())
|
|
593
|
+
} else {
|
|
594
|
+
setPolicy(POLICY_PATH, recommendedAutoApprovePolicy)
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
print(color.red("Failed to load policy: ${JSON.stringify(f.error)}"))
|
|
598
|
+
process.exit(1)
|
|
599
|
+
}
|
|
600
|
+
} else {
|
|
601
|
+
setPolicy(POLICY_PATH, policy.value)
|
|
602
|
+
}
|
|
603
|
+
// Bind the handler to a local var so `with handler` parses (the
|
|
604
|
+
// `with` clause only accepts an identifier, not a call expression).
|
|
605
|
+
return cliPolicyHandler(file: POLICY_PATH, fields: ALWAYS_FIELDS)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// One-shot entry: run a single turn through the same `mainAgent` the
|
|
609
|
+
// REPL uses, with the same session setup and policy handler, and return
|
|
610
|
+
// the reply. Used for `agency agent -p "..."`, a positional query, or
|
|
611
|
+
// piped stdin. Slash commands are expanded so `-p /foo bar` works like
|
|
612
|
+
// typing it in the REPL; the loop-only built-ins (`/exit` etc.) are
|
|
613
|
+
// meaningless here and aren't checked.
|
|
614
|
+
def oneShotAgent(target: string, prompt: string): string {
|
|
615
|
+
_isInteractive = false
|
|
616
|
+
const handler = setupSession(false)
|
|
617
|
+
let reply: string = ""
|
|
618
|
+
handle {
|
|
619
|
+
reply = agentReplyVia(target, prompt)
|
|
620
|
+
} with (data) {
|
|
621
|
+
return handler(data)
|
|
622
|
+
}
|
|
623
|
+
return reply
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Render one seeded turn into the REPL scroll area: echo the auto-run
|
|
627
|
+
// prompt so the user sees what was asked, then push the agent's reply.
|
|
628
|
+
// Mirrors the reply-rendering half of `_runTurn`.
|
|
629
|
+
def _runSeedTurn(target: string, msg: string) {
|
|
630
|
+
pushMessage(color.dim("> ${msg}"))
|
|
631
|
+
const reply = agentReplyVia(target, msg)
|
|
632
|
+
if (reply != "" && reply != null && reply != undefined) {
|
|
633
|
+
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
634
|
+
} else {
|
|
635
|
+
pushMessage(color.red("No reply generated."))
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Start the interactive REPL. When `seedPrompt` is non-empty it is run as
|
|
640
|
+
// the first turn (routed via `seedTarget`) *inside* the handle block so
|
|
641
|
+
// its interrupts reach the policy `handler`; the user is then left at the
|
|
642
|
+
// prompt. `seedPrompt == ""` is the plain REPL with no seed. Subsequent
|
|
643
|
+
// turns always go through `_runTurn` (the coordinator) regardless of
|
|
644
|
+
// `seedTarget` — the target only kicks off the first turn.
|
|
645
|
+
def startInteractive(handler: any, seedTarget: string, seedPrompt: string) {
|
|
646
|
+
handle {
|
|
647
|
+
if (seedPrompt != "") {
|
|
648
|
+
_runSeedTurn(seedTarget, seedPrompt)
|
|
649
|
+
}
|
|
650
|
+
repl(
|
|
651
|
+
status: _buildStatus,
|
|
652
|
+
onSubmit: _runTurn,
|
|
653
|
+
prompt: "> ",
|
|
654
|
+
historyFile: HISTORY_PATH,
|
|
655
|
+
historyMax: 1000,
|
|
656
|
+
paletteCommands: mergedPalette(),
|
|
657
|
+
)
|
|
658
|
+
} with (data) {
|
|
659
|
+
return handler(data)
|
|
660
|
+
}
|
|
661
|
+
print(color.cyan("\nGoodbye!"))
|
|
662
|
+
}
|
|
663
|
+
|
|
504
664
|
node main() {
|
|
505
665
|
// Parse CLI flags first — `parseArgs` exits on --help / --version /
|
|
506
666
|
// usage errors, before any handlers or the TUI are installed.
|
|
@@ -522,6 +682,31 @@ node main() {
|
|
|
522
682
|
verbose: {
|
|
523
683
|
type: "boolean",
|
|
524
684
|
description: "Echo tool-call starts to stdout in non-interactive mode"
|
|
685
|
+
},
|
|
686
|
+
model: {
|
|
687
|
+
type: "string",
|
|
688
|
+
description: "Model for all LLM calls (overrides provider auto-detection)"
|
|
689
|
+
},
|
|
690
|
+
fastmodel: {
|
|
691
|
+
type: "string",
|
|
692
|
+
description: "Model for ordinary work (default: per detected provider)"
|
|
693
|
+
},
|
|
694
|
+
slowmodel: {
|
|
695
|
+
type: "string",
|
|
696
|
+
description: "Model for deep reasoning, e.g. the oracle/explorer subagents"
|
|
697
|
+
},
|
|
698
|
+
provider: {
|
|
699
|
+
type: "string",
|
|
700
|
+
description: "Force the LLM provider (use when a model name doesn't imply one)"
|
|
701
|
+
},
|
|
702
|
+
interactive: {
|
|
703
|
+
type: "boolean",
|
|
704
|
+
short: "i",
|
|
705
|
+
description: "Run the given prompt as the first turn of an interactive session, then hand over the REPL (instead of one-shot)"
|
|
706
|
+
},
|
|
707
|
+
agent: {
|
|
708
|
+
type: "string",
|
|
709
|
+
description: "Route the starting prompt to a named subagent: code, research, oracle, explorer, review (default: coordinator)"
|
|
525
710
|
}
|
|
526
711
|
}
|
|
527
712
|
},
|
|
@@ -534,74 +719,85 @@ node main() {
|
|
|
534
719
|
VERBOSE = true
|
|
535
720
|
}
|
|
536
721
|
|
|
537
|
-
|
|
538
|
-
|
|
722
|
+
// Resolve which models to use. Explicit flags win; otherwise detect a
|
|
723
|
+
// provider from API-key env vars and use that provider's defaults. The
|
|
724
|
+
// fast model becomes the run-wide default via `setModel`; the slow
|
|
725
|
+
// model is read by the deep-reasoning subagents (oracle, explorer).
|
|
726
|
+
// Resolve + apply the fast/slow models. Absent string flags read as
|
|
727
|
+
// `undefined`, and agency's `== null` does not match `undefined`, so
|
|
728
|
+
// normalize via `??` (which does treat `undefined` as nullish) to "".
|
|
729
|
+
configureModels(
|
|
730
|
+
args.flags.model ?? "",
|
|
731
|
+
args.flags.fastmodel ?? "",
|
|
732
|
+
args.flags.slowmodel ?? "",
|
|
733
|
+
args.flags.provider ?? "",
|
|
734
|
+
)
|
|
735
|
+
|
|
539
736
|
// Positional args (everything after flags) are joined with spaces to
|
|
540
|
-
// form the
|
|
737
|
+
// form the starting prompt. `--` ends flag parsing if a positional
|
|
541
738
|
// would otherwise look like a flag.
|
|
542
739
|
const positionalQuery = args.positionals.join(" ")
|
|
543
740
|
const hasQuery = positionalQuery != ""
|
|
741
|
+
const startAgent = args.flags.agent ?? ""
|
|
742
|
+
const wantInteractive = args.flags.interactive
|
|
743
|
+
|
|
744
|
+
// Validate the target subagent name up front (empty = coordinator).
|
|
745
|
+
if (startAgent != "" && !START_AGENTS.includes(startAgent)) {
|
|
746
|
+
print(
|
|
747
|
+
color.red(
|
|
748
|
+
"Unknown --agent value: ${startAgent}. Valid: ${START_AGENTS.join(", ")}",
|
|
749
|
+
),
|
|
750
|
+
)
|
|
751
|
+
process.exit(1)
|
|
752
|
+
}
|
|
544
753
|
|
|
545
|
-
//
|
|
546
|
-
//
|
|
547
|
-
//
|
|
548
|
-
//
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
const
|
|
556
|
-
|
|
754
|
+
// Seeded interactive: run the given prompt as the first turn, then hand
|
|
755
|
+
// the REPL to the user. Requires a seed prompt and a TTY (the REPL reads
|
|
756
|
+
// stdin). `--print` wins if both are passed — its whole job is to print
|
|
757
|
+
// and exit with no REPL. Without a TTY (or with `--print`) we fall
|
|
758
|
+
// through to one-shot below; `--interactive` with no prompt falls through
|
|
759
|
+
// to the plain REPL.
|
|
760
|
+
if (wantInteractive && hasQuery && isTTY() && !args.flags.print) {
|
|
761
|
+
setTitle("Agency Agent")
|
|
762
|
+
clearScreen()
|
|
763
|
+
printHeader()
|
|
764
|
+
const seededHandler = setupSession(true)
|
|
765
|
+
startInteractive(seededHandler, startAgent, positionalQuery)
|
|
557
766
|
process.exit(0)
|
|
558
767
|
}
|
|
559
768
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
//
|
|
563
|
-
//
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
setPolicy(POLICY_PATH, choice)
|
|
580
|
-
} else {
|
|
581
|
-
print(color.red("Failed to load policy: ${JSON.stringify(error)}"))
|
|
582
|
-
process.exit(1)
|
|
769
|
+
// One-shot invocation: run one turn through the same agent the REPL uses
|
|
770
|
+
// and write the reply to stdout. No banner, no REPL. Entered when
|
|
771
|
+
// `--print` / `-p` is passed, a positional query is given, or stdin is
|
|
772
|
+
// piped (no TTY) — so the agent behaves like a Unix filter:
|
|
773
|
+
// `echo "..." | agency agent`. `--interactive` is NOT a one-shot trigger
|
|
774
|
+
// on its own: with a TTY and no prompt it falls through to the plain
|
|
775
|
+
// REPL; without a TTY the `!isTTY()` check below routes it here to
|
|
776
|
+
// degrade gracefully. The prompt comes from the positional when present,
|
|
777
|
+
// otherwise from stdin. (Title/clearScreen are skipped so piped output
|
|
778
|
+
// stays free of escape codes.)
|
|
779
|
+
const forceOneShot = args.flags.print || hasQuery
|
|
780
|
+
if (forceOneShot || !isTTY()) {
|
|
781
|
+
let prompt = positionalQuery
|
|
782
|
+
if (!hasQuery) {
|
|
783
|
+
const fromStdin = readStdin()
|
|
784
|
+
if (fromStdin == null || fromStdin == "") {
|
|
785
|
+
process.exit(0)
|
|
786
|
+
}
|
|
787
|
+
prompt = fromStdin
|
|
583
788
|
}
|
|
584
|
-
|
|
585
|
-
|
|
789
|
+
print(oneShotAgent(startAgent, prompt))
|
|
790
|
+
process.exit(0)
|
|
586
791
|
}
|
|
587
|
-
// Bind the handler to a local var so `with handler` parses (the
|
|
588
|
-
// `with` clause only accepts an identifier, not a call expression).
|
|
589
|
-
const handler = cliPolicyHandler(file: POLICY_PATH, fields: ALWAYS_FIELDS)
|
|
590
792
|
|
|
591
|
-
//
|
|
592
|
-
// `_runTurn` which calls `
|
|
593
|
-
//
|
|
594
|
-
// `handle` block via the AsyncLocalStorage
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
historyMax: 1000,
|
|
602
|
-
paletteCommands: mergedPalette(),
|
|
603
|
-
)
|
|
604
|
-
} with handler
|
|
605
|
-
|
|
606
|
-
print(color.cyan("\nGoodbye!"))
|
|
793
|
+
// Plain interactive REPL (no seed). `startInteractive` owns the runloop;
|
|
794
|
+
// every Enter dispatches into `_runTurn` which calls `mainAgent`.
|
|
795
|
+
// Interrupts raised during a turn propagate to the policy handler
|
|
796
|
+
// installed by the enclosing `handle` block via the AsyncLocalStorage
|
|
797
|
+
// handler stack.
|
|
798
|
+
setTitle("Agency Agent")
|
|
799
|
+
clearScreen()
|
|
800
|
+
printHeader()
|
|
801
|
+
const handler = setupSession(true)
|
|
802
|
+
startInteractive(handler, "", "")
|
|
607
803
|
}
|