agency-lang 0.2.0 → 0.4.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/README.md +3 -1
- package/dist/lib/agents/agency-agent/agent.agency +291 -170
- package/dist/lib/agents/agency-agent/agent.js +2388 -0
- package/dist/lib/agents/agency-agent/code.agency +223 -0
- package/dist/lib/agents/agency-agent/code.js +530 -0
- package/dist/lib/agents/agency-agent/images/images.agency +41 -0
- package/dist/lib/agents/agency-agent/images/images.js +218 -0
- package/dist/lib/agents/agency-agent/prompts/codeSample.js +744 -0
- package/dist/lib/agents/agency-agent/research.agency +131 -0
- package/dist/lib/agents/agency-agent/research.js +311 -0
- package/dist/lib/agents/agency-agent/shared.agency +53 -0
- package/dist/lib/agents/agency-agent/shared.js +335 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/ATTRIBUTION.txt +7 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/brainstorming.md +164 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/executing-plans.md +70 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/systematic-debugging.md +296 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/test-driven-development.md +371 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/verification-before-completion.md +139 -0
- package/dist/lib/agents/agency-agent/skills/superpowers/writing-plans.md +145 -0
- package/dist/lib/agents/agency-agent/subagents/code.js +535 -0
- package/dist/lib/agents/agency-agent/subagents/plan.js +405 -0
- package/dist/lib/agents/agency-agent/subagents/task.js +513 -0
- package/dist/lib/agents/docs/appendix/advanced-types.md +26 -0
- package/dist/lib/agents/docs/appendix/agency-stdlib.md +25 -0
- package/dist/lib/agents/docs/appendix/agency-vs-typescript.md +14 -0
- package/dist/lib/agents/docs/appendix/builtins.md +61 -0
- package/dist/lib/agents/docs/appendix/callbacks.md +147 -0
- package/dist/lib/agents/docs/appendix/schema-parameter-injection.md +101 -0
- package/dist/lib/agents/docs/appendix/ts-helpers.md +489 -0
- package/dist/lib/agents/docs/appendix/vscode-extension.md +11 -0
- package/dist/lib/agents/docs/cli/agent.md +16 -0
- package/dist/lib/agents/docs/cli/compile.md +21 -0
- package/dist/lib/agents/docs/cli/coverage.md +112 -0
- package/dist/lib/agents/docs/cli/debug.md +41 -0
- package/dist/lib/agents/docs/cli/doc.md +98 -0
- package/dist/lib/agents/docs/cli/editor-integration.md +44 -0
- package/dist/lib/agents/docs/cli/format.md +23 -0
- package/dist/lib/agents/docs/cli/index.md +7 -0
- package/dist/lib/agents/docs/cli/optimize.md +18 -0
- package/dist/lib/agents/docs/cli/pack.md +56 -0
- package/dist/lib/agents/docs/cli/policy.md +23 -0
- package/dist/lib/agents/docs/cli/preprocess-and-ast.md +21 -0
- package/dist/lib/agents/docs/cli/review.md +16 -0
- package/dist/lib/agents/docs/cli/run.md +108 -0
- package/dist/lib/agents/docs/cli/schedule.md +89 -0
- package/dist/lib/agents/docs/cli/serve.md +52 -0
- package/dist/lib/agents/docs/cli/test.md +53 -0
- package/dist/lib/agents/docs/cli/trace-and-bundle.md +75 -0
- package/dist/lib/agents/docs/cli/typecheck.md +19 -0
- package/dist/lib/agents/docs/guide/agency-config-file.md +10 -0
- package/dist/lib/agents/docs/guide/agents-101.md +212 -0
- package/dist/lib/agents/docs/guide/basic-syntax.md +178 -0
- package/dist/lib/agents/docs/guide/blocks.md +104 -0
- package/dist/lib/agents/docs/guide/checkpointing.md +72 -0
- package/dist/lib/agents/docs/guide/concurrency.md +92 -0
- package/dist/lib/agents/docs/guide/cross-thread-context.md +200 -0
- package/dist/lib/agents/docs/guide/error-handling.md +149 -0
- package/dist/lib/agents/docs/guide/execution-model.md +117 -0
- package/dist/lib/agents/docs/guide/functions.md +33 -0
- package/dist/lib/agents/docs/guide/getting-started.md +42 -0
- package/dist/lib/agents/docs/guide/global-vs-static.md +54 -0
- package/dist/lib/agents/docs/guide/guards.md +185 -0
- package/dist/lib/agents/docs/guide/handlers.md +292 -0
- package/dist/lib/agents/docs/guide/imports-and-packages.md +160 -0
- package/dist/lib/agents/docs/guide/interrupts.md +99 -0
- package/dist/lib/agents/docs/guide/llm.md +180 -0
- package/dist/lib/agents/docs/guide/mcp.md +295 -0
- package/dist/lib/agents/docs/guide/memory.md +388 -0
- package/dist/lib/agents/docs/guide/message-history-and-threads.md +88 -0
- package/dist/lib/agents/docs/guide/nodes.md +35 -0
- package/dist/lib/agents/docs/guide/observability.md +86 -0
- package/dist/lib/agents/docs/guide/odds-and-ends.md +41 -0
- package/dist/lib/agents/docs/guide/partial-application.md +162 -0
- package/dist/lib/agents/docs/guide/pattern-matching.md +193 -0
- package/dist/lib/agents/docs/guide/policies.md +60 -0
- package/dist/lib/agents/docs/guide/schemas.md +86 -0
- package/dist/lib/agents/docs/guide/serving.md +165 -0
- package/dist/lib/agents/docs/guide/structured-interrupts.md +49 -0
- package/dist/lib/agents/docs/guide/testing.md +27 -0
- package/dist/lib/agents/docs/guide/troubleshooting.md +82 -0
- package/dist/lib/agents/docs/guide/ts-interop.md +185 -0
- package/dist/lib/agents/docs/guide/type-validation.md +329 -0
- package/dist/lib/agents/docs/guide/types.md +196 -0
- package/dist/lib/agents/judge.js +91 -80
- package/dist/lib/agents/policy/agent.agency +153 -53
- package/dist/lib/agents/policy/agent.js +1890 -0
- package/dist/lib/agents/policy/prompts/system.md +7 -0
- package/dist/lib/agents/review/agent.agency +2 -1
- package/dist/lib/agents/review/agent.js +430 -459
- package/dist/lib/backends/agencyGenerator.d.ts +56 -3
- package/dist/lib/backends/agencyGenerator.js +278 -65
- package/dist/lib/backends/agencyGenerator.test.js +131 -76
- package/dist/lib/backends/docstringInterpolationRuntime.test.js +59 -0
- package/dist/lib/backends/typescriptBuilder/assignmentEmitter.d.ts +64 -0
- package/dist/lib/backends/typescriptBuilder/assignmentEmitter.js +104 -0
- package/dist/lib/backends/typescriptBuilder/nameClassifier.d.ts +61 -0
- package/dist/lib/backends/typescriptBuilder/nameClassifier.js +142 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.d.ts +28 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.js +95 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.d.ts +1 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.js +79 -0
- package/dist/lib/backends/typescriptBuilder/pipeChainEmitter.d.ts +94 -0
- package/dist/lib/backends/typescriptBuilder/pipeChainEmitter.js +227 -0
- package/dist/lib/backends/typescriptBuilder/pipeReceiverCodegen.test.d.ts +1 -0
- package/dist/lib/backends/typescriptBuilder/pipeReceiverCodegen.test.js +58 -0
- package/dist/lib/backends/typescriptBuilder/scopeManager.d.ts +62 -0
- package/dist/lib/backends/typescriptBuilder/scopeManager.js +131 -0
- package/dist/lib/backends/typescriptBuilder/sectionAssembler.d.ts +157 -0
- package/dist/lib/backends/typescriptBuilder/sectionAssembler.js +447 -0
- package/dist/lib/backends/typescriptBuilder/stepPathTracker.d.ts +45 -0
- package/dist/lib/backends/typescriptBuilder/stepPathTracker.js +76 -0
- package/dist/lib/backends/typescriptBuilder/topLevelWith.test.d.ts +1 -0
- package/dist/lib/backends/typescriptBuilder/topLevelWith.test.js +59 -0
- package/dist/lib/backends/typescriptBuilder.d.ts +58 -115
- package/dist/lib/backends/typescriptBuilder.integration.test.js +25 -26
- package/dist/lib/backends/typescriptBuilder.js +751 -991
- package/dist/lib/backends/typescriptGenerator/jsonSchemaAnnotation.test.d.ts +1 -0
- package/dist/lib/backends/typescriptGenerator/jsonSchemaAnnotation.test.js +104 -0
- package/dist/lib/backends/typescriptGenerator/tagArgToTs.d.ts +19 -0
- package/dist/lib/backends/typescriptGenerator/tagArgToTs.js +171 -0
- package/dist/lib/backends/typescriptGenerator/tagArgToTs.test.d.ts +1 -0
- package/dist/lib/backends/typescriptGenerator/tagArgToTs.test.js +44 -0
- package/dist/lib/backends/typescriptGenerator/typeToString.js +96 -1
- package/dist/lib/backends/typescriptGenerator/typeToString.test.d.ts +1 -0
- package/dist/lib/backends/typescriptGenerator/typeToString.test.js +52 -0
- package/dist/lib/backends/typescriptGenerator/typeToZodSchema.d.ts +12 -3
- package/dist/lib/backends/typescriptGenerator/typeToZodSchema.js +105 -9
- package/dist/lib/backends/typescriptGenerator/typeToZodSchema.test.js +122 -1
- package/dist/lib/backends/typescriptGenerator/validationDescriptor.d.ts +31 -0
- package/dist/lib/backends/typescriptGenerator/validationDescriptor.js +257 -0
- package/dist/lib/backends/typescriptGenerator.d.ts +37 -1
- package/dist/lib/backends/typescriptGenerator.js +29 -2
- package/dist/lib/cli/commands.js +63 -5
- package/dist/lib/cli/debug.js +2 -0
- package/dist/lib/cli/doc.js +74 -3
- package/dist/lib/cli/doc.test.js +39 -0
- package/dist/lib/cli/evaluate.js +3 -3
- package/dist/lib/cli/literate.d.ts +2 -0
- package/dist/lib/cli/literate.js +128 -0
- package/dist/lib/cli/literate.test.d.ts +1 -0
- package/dist/lib/cli/literate.test.js +229 -0
- package/dist/lib/cli/optimize.js +23 -2
- package/dist/lib/cli/optimize.test.js +6 -1
- package/dist/lib/cli/runBundledAgent.js +12 -4
- package/dist/lib/cli/schedule/index.js +1 -0
- package/dist/lib/cli/serve.js +1 -0
- package/dist/lib/cli/test.js +19 -6
- package/dist/lib/cli/util.d.ts +2 -1
- package/dist/lib/cli/util.js +14 -6
- package/dist/lib/compilationUnit.d.ts +6 -7
- package/dist/lib/compilationUnit.js +35 -16
- package/dist/lib/compilationUnit.test.js +3 -35
- package/dist/lib/compiler/compile.d.ts +9 -6
- package/dist/lib/compiler/compile.js +53 -42
- package/dist/lib/compiler/compile.test.js +71 -21
- package/dist/lib/compiler/compileClosure.d.ts +74 -0
- package/dist/lib/compiler/compileClosure.js +404 -0
- package/dist/lib/compiler/compileClosure.test.d.ts +1 -0
- package/dist/lib/compiler/compileClosure.test.js +125 -0
- package/dist/lib/compiler/initDepGraph.d.ts +275 -0
- package/dist/lib/compiler/initDepGraph.js +761 -0
- package/dist/lib/compiler/initDepGraph.test.d.ts +1 -0
- package/dist/lib/compiler/initDepGraph.test.js +649 -0
- package/dist/lib/compiler/topSortInitGraph.d.ts +31 -0
- package/dist/lib/compiler/topSortInitGraph.js +120 -0
- package/dist/lib/compiler/topSortInitGraph.test.d.ts +1 -0
- package/dist/lib/compiler/topSortInitGraph.test.js +279 -0
- package/dist/lib/compiler/typecheck.d.ts +18 -0
- package/dist/lib/compiler/typecheck.js +79 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/debugger/debuggerState.js +0 -3
- package/dist/lib/debugger/driver.js +12 -3
- package/dist/lib/debugger/testHelpers.js +1 -0
- package/dist/lib/debugger/uiState.js +1 -0
- package/dist/lib/formatter.test.js +8 -0
- package/dist/lib/importPaths.d.ts +33 -0
- package/dist/lib/importPaths.js +37 -0
- package/dist/lib/importPaths.test.js +70 -0
- package/dist/lib/ir/builders.d.ts +120 -15
- package/dist/lib/ir/builders.js +166 -54
- package/dist/lib/ir/prettyPrint.js +74 -5
- package/dist/lib/ir/prettyPrint.test.js +35 -1
- package/dist/lib/ir/tsIR.d.ts +35 -2
- package/dist/lib/logger.js +22 -1
- package/dist/lib/logger.test.js +42 -12
- package/dist/lib/logsViewer/render.d.ts +2 -1
- package/dist/lib/logsViewer/render.js +57 -13
- package/dist/lib/logsViewer/render.test.js +63 -1
- package/dist/lib/logsViewer/run.js +5 -1
- package/dist/lib/logsViewer/search.d.ts +1 -1
- package/dist/lib/logsViewer/search.js +9 -5
- package/dist/lib/logsViewer/search.test.js +1 -1
- package/dist/lib/logsViewer/summary.js +1 -1
- package/dist/lib/logsViewer/types.d.ts +1 -0
- package/dist/lib/lowering/patternLowering.js +27 -1
- package/dist/lib/lowering/patternLowering.test.js +165 -0
- package/dist/lib/lsp/builtinHover.d.ts +5 -1
- package/dist/lib/lsp/builtinHover.js +41 -2
- package/dist/lib/lsp/completion.js +10 -6
- package/dist/lib/lsp/diagnostics.js +2 -2
- package/dist/lib/lsp/documentSymbol.js +0 -8
- package/dist/lib/lsp/foldingRange.js +0 -1
- package/dist/lib/lsp/semantics.js +1 -14
- package/dist/lib/lsp/server.js +1 -0
- package/dist/lib/lsp/workspaceSymbol.js +0 -1
- package/dist/lib/parser.js +2 -2
- package/dist/lib/parsers/function.test.js +175 -140
- package/dist/lib/parsers/messageThread.test.d.ts +1 -0
- package/dist/lib/parsers/messageThread.test.js +102 -0
- package/dist/lib/parsers/objectTypeTags.test.d.ts +1 -0
- package/dist/lib/parsers/objectTypeTags.test.js +69 -0
- package/dist/lib/parsers/parsers.d.ts +52 -7
- package/dist/lib/parsers/parsers.js +435 -123
- package/dist/lib/parsers/pattern.test.js +146 -0
- package/dist/lib/parsers/staticStatement.test.d.ts +1 -0
- package/dist/lib/parsers/staticStatement.test.js +46 -0
- package/dist/lib/parsers/tag.test.js +141 -13
- package/dist/lib/parsers/tagIntegration.test.js +11 -8
- package/dist/lib/parsers/typeHints.test.js +330 -1
- package/dist/lib/preprocessors/importResolver.js +10 -2
- package/dist/lib/preprocessors/injectSchemaArgs.d.ts +36 -0
- package/dist/lib/preprocessors/injectSchemaArgs.js +209 -0
- package/dist/lib/preprocessors/injectSchemaArgs.test.d.ts +1 -0
- package/dist/lib/preprocessors/injectSchemaArgs.test.js +383 -0
- package/dist/lib/preprocessors/liftCallbacks.d.ts +2 -0
- package/dist/lib/preprocessors/liftCallbacks.js +242 -0
- package/dist/lib/preprocessors/liftCallbacks.test.d.ts +1 -0
- package/dist/lib/preprocessors/liftCallbacks.test.js +146 -0
- package/dist/lib/preprocessors/parallelDesugar.js +4 -5
- package/dist/lib/preprocessors/resolveReExports.js +1 -3
- package/dist/lib/preprocessors/typeAliasTags.test.d.ts +1 -0
- package/dist/lib/preprocessors/typeAliasTags.test.js +57 -0
- package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +3 -3
- package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +9 -1
- package/dist/lib/preprocessors/typescriptPreprocessor.js +90 -30
- package/dist/lib/runtime/__tests__/node.test.js +28 -3
- package/dist/lib/runtime/__tests__/testHelpers.js +36 -0
- package/dist/lib/runtime/agency.d.ts +117 -0
- package/dist/lib/runtime/agency.js +310 -0
- package/dist/lib/runtime/agency.test.d.ts +1 -0
- package/dist/lib/runtime/agency.test.js +422 -0
- package/dist/lib/runtime/agencyFunction.d.ts +15 -3
- package/dist/lib/runtime/agencyFunction.js +41 -25
- package/dist/lib/runtime/agencyFunction.test.js +77 -13
- package/dist/lib/runtime/agencyInterrupt.d.ts +18 -0
- package/dist/lib/runtime/agencyInterrupt.js +159 -0
- package/dist/lib/runtime/agencyInterrupt.test.d.ts +1 -0
- package/dist/lib/runtime/agencyInterrupt.test.js +321 -0
- package/dist/lib/runtime/agencyLlm.checkpointInfo.test.d.ts +1 -0
- package/dist/lib/runtime/agencyLlm.checkpointInfo.test.js +63 -0
- package/dist/lib/runtime/agencyLlm.d.ts +59 -0
- package/dist/lib/runtime/agencyLlm.js +20 -0
- package/dist/lib/runtime/agencyLlm.test.d.ts +1 -0
- package/dist/lib/runtime/agencyLlm.test.js +199 -0
- package/dist/lib/runtime/asyncContext.d.ts +208 -0
- package/dist/lib/runtime/asyncContext.js +196 -0
- package/dist/lib/runtime/asyncContext.test.d.ts +1 -0
- package/dist/lib/runtime/asyncContext.test.js +221 -0
- package/dist/lib/runtime/call.d.ts +15 -2
- package/dist/lib/runtime/call.js +34 -4
- package/dist/lib/runtime/call.test.js +48 -7
- package/dist/lib/runtime/checkpoint.d.ts +11 -4
- package/dist/lib/runtime/checkpoint.js +19 -11
- package/dist/lib/runtime/checkpoint.test.js +54 -39
- package/dist/lib/runtime/crossModuleInitRegistry.d.ts +101 -0
- package/dist/lib/runtime/crossModuleInitRegistry.js +128 -0
- package/dist/lib/runtime/debugger.d.ts +1 -2
- package/dist/lib/runtime/debugger.js +1 -1
- package/dist/lib/runtime/debugger.test.js +13 -16
- package/dist/lib/runtime/deterministicClient.d.ts +9 -1
- package/dist/lib/runtime/deterministicClient.js +19 -5
- package/dist/lib/runtime/deterministicClient.test.js +10 -2
- package/dist/lib/runtime/errors.d.ts +11 -0
- package/dist/lib/runtime/errors.js +22 -0
- package/dist/lib/runtime/guard.d.ts +243 -0
- package/dist/lib/runtime/guard.js +314 -0
- package/dist/lib/runtime/guard.test.d.ts +1 -0
- package/dist/lib/runtime/guard.test.js +289 -0
- package/dist/lib/runtime/haltSignal.d.ts +21 -0
- package/dist/lib/runtime/haltSignal.js +24 -0
- package/dist/lib/runtime/hooks.d.ts +62 -4
- package/dist/lib/runtime/hooks.js +148 -35
- package/dist/lib/runtime/hooks.test.d.ts +1 -0
- package/dist/lib/runtime/hooks.test.js +143 -0
- package/dist/lib/runtime/index.d.ts +23 -1
- package/dist/lib/runtime/index.js +15 -0
- package/dist/lib/runtime/initPlanWorkedExamples.test.d.ts +1 -0
- package/dist/lib/runtime/initPlanWorkedExamples.test.js +208 -0
- package/dist/lib/runtime/interrupts.d.ts +2 -1
- package/dist/lib/runtime/interrupts.js +58 -7
- package/dist/lib/runtime/ipc.d.ts +1 -2
- package/dist/lib/runtime/ipc.js +6 -3
- package/dist/lib/runtime/memory/frame.d.ts +11 -0
- package/dist/lib/runtime/memory/frame.js +61 -0
- package/dist/lib/runtime/memory/frame.test.d.ts +1 -0
- package/dist/lib/runtime/memory/frame.test.js +98 -0
- package/dist/lib/runtime/memory/index.d.ts +2 -0
- package/dist/lib/runtime/memory/index.js +2 -0
- package/dist/lib/runtime/memory/manager.js +61 -5
- package/dist/lib/runtime/memory/manager.test.js +176 -3
- package/dist/lib/runtime/memory/registry.d.ts +59 -0
- package/dist/lib/runtime/memory/registry.js +69 -0
- package/dist/lib/runtime/memory/registry.test.d.ts +1 -0
- package/dist/lib/runtime/memory/registry.test.js +42 -0
- package/dist/lib/runtime/node.d.ts +5 -5
- package/dist/lib/runtime/node.js +126 -39
- package/dist/lib/runtime/policy.d.ts +19 -5
- package/dist/lib/runtime/policy.js +18 -13
- package/dist/lib/runtime/policy.test.js +96 -0
- package/dist/lib/runtime/prompt.d.ts +8 -5
- package/dist/lib/runtime/prompt.js +441 -312
- package/dist/lib/runtime/promptRunner.d.ts +128 -0
- package/dist/lib/runtime/promptRunner.js +222 -0
- package/dist/lib/runtime/promptRunner.test.d.ts +1 -0
- package/dist/lib/runtime/promptRunner.test.js +398 -0
- package/dist/lib/runtime/result.js +36 -0
- package/dist/lib/runtime/resumableScope.d.ts +49 -0
- package/dist/lib/runtime/resumableScope.js +124 -0
- package/dist/lib/runtime/resumableScope.test.d.ts +1 -0
- package/dist/lib/runtime/resumableScope.test.js +245 -0
- package/dist/lib/runtime/revivers/functionRefReviver.js +19 -16
- package/dist/lib/runtime/revivers/functionRefReviver.test.js +42 -0
- package/dist/lib/runtime/rewind.d.ts +2 -0
- package/dist/lib/runtime/rewind.js +21 -3
- package/dist/lib/runtime/runBatch.d.ts +93 -0
- package/dist/lib/runtime/runBatch.js +443 -0
- package/dist/lib/runtime/runBatch.test.d.ts +1 -0
- package/dist/lib/runtime/runBatch.test.js +574 -0
- package/dist/lib/runtime/runner.d.ts +125 -21
- package/dist/lib/runtime/runner.js +494 -312
- package/dist/lib/runtime/runner.test.js +165 -6
- package/dist/lib/runtime/schema.d.ts +8 -0
- package/dist/lib/runtime/schema.js +11 -0
- package/dist/lib/runtime/state/bootstrapThreadStore.d.ts +38 -0
- package/dist/lib/runtime/state/bootstrapThreadStore.js +72 -0
- package/dist/lib/runtime/state/bootstrapThreadStore.test.d.ts +1 -0
- package/dist/lib/runtime/state/bootstrapThreadStore.test.js +34 -0
- package/dist/lib/runtime/state/context.d.ts +43 -11
- package/dist/lib/runtime/state/context.js +145 -82
- package/dist/lib/runtime/state/context.test.js +100 -1
- package/dist/lib/runtime/state/messageThread.d.ts +31 -0
- package/dist/lib/runtime/state/messageThread.js +51 -0
- package/dist/lib/runtime/state/messageThread.test.d.ts +1 -0
- package/dist/lib/runtime/state/messageThread.test.js +44 -0
- package/dist/lib/runtime/state/stateStack.d.ts +139 -0
- package/dist/lib/runtime/state/stateStack.js +286 -0
- package/dist/lib/runtime/state/stateStack.test.js +448 -0
- package/dist/lib/runtime/state/threadStore.d.ts +33 -0
- package/dist/lib/runtime/state/threadStore.js +66 -1
- package/dist/lib/runtime/state/threadStore.test.d.ts +1 -0
- package/dist/lib/runtime/state/threadStore.test.js +99 -0
- package/dist/lib/runtime/staticInit.crossModule.test.d.ts +1 -0
- package/dist/lib/runtime/staticInit.crossModule.test.js +100 -0
- package/dist/lib/runtime/staticInit.d.ts +49 -0
- package/dist/lib/runtime/staticInit.js +70 -0
- package/dist/lib/runtime/staticInit.test.d.ts +1 -0
- package/dist/lib/runtime/staticInit.test.js +49 -0
- package/dist/lib/runtime/subprocess-bootstrap.js +8 -0
- package/dist/lib/runtime/topsortCycleErrors.test.d.ts +1 -0
- package/dist/lib/runtime/topsortCycleErrors.test.js +250 -0
- package/dist/lib/runtime/trace/sinks.js +30 -6
- package/dist/lib/runtime/types.d.ts +1 -9
- package/dist/lib/runtime/validateChain.d.ts +71 -0
- package/dist/lib/runtime/validateChain.js +138 -0
- package/dist/lib/runtime/validateChain.test.d.ts +1 -0
- package/dist/lib/runtime/validateChain.test.js +131 -0
- package/dist/lib/simplemachine/graph.js +1 -1
- package/dist/lib/simplemachine/util.d.ts +1 -1
- package/dist/lib/statelogClient.d.ts +19 -0
- package/dist/lib/statelogClient.js +25 -0
- package/dist/lib/statelogClient.test.js +12 -0
- package/dist/lib/stdlib/abortable.d.ts +58 -0
- package/dist/lib/stdlib/abortable.js +175 -0
- package/dist/lib/stdlib/agency.d.ts +44 -0
- package/dist/lib/stdlib/agency.js +218 -12
- package/dist/lib/stdlib/assertContained.d.ts +24 -0
- package/dist/lib/stdlib/assertContained.js +123 -0
- package/dist/lib/stdlib/browserUse.d.ts +7 -0
- package/dist/lib/stdlib/browserUse.js +58 -27
- package/dist/lib/stdlib/builtins.d.ts +17 -3
- package/dist/lib/stdlib/builtins.js +93 -10
- package/dist/lib/stdlib/cli.d.ts +1 -0
- package/dist/lib/stdlib/cli.js +745 -0
- package/dist/lib/stdlib/expandPath.d.ts +34 -0
- package/dist/lib/stdlib/expandPath.js +57 -0
- package/dist/lib/stdlib/fs.d.ts +10 -8
- package/dist/lib/stdlib/fs.js +31 -62
- package/dist/lib/stdlib/http.d.ts +32 -1
- package/dist/lib/stdlib/http.js +105 -23
- package/dist/lib/stdlib/layout.d.ts +67 -0
- package/dist/lib/stdlib/layout.js +477 -0
- package/dist/lib/stdlib/markdown.d.ts +21 -0
- package/dist/lib/stdlib/markdown.js +322 -0
- package/dist/lib/stdlib/memory.d.ts +68 -15
- package/dist/lib/stdlib/memory.js +166 -32
- package/dist/lib/stdlib/oauth.d.ts +37 -0
- package/dist/lib/stdlib/oauth.js +113 -34
- package/dist/lib/stdlib/policy.d.ts +2 -1
- package/dist/lib/stdlib/policy.js +6 -2
- package/dist/lib/stdlib/resolveDir.d.ts +24 -0
- package/dist/lib/stdlib/resolveDir.js +35 -0
- package/dist/lib/stdlib/resolvePath.d.ts +15 -0
- package/dist/lib/stdlib/resolvePath.js +24 -4
- package/dist/lib/stdlib/search.d.ts +14 -0
- package/dist/lib/stdlib/search.js +36 -0
- package/dist/lib/stdlib/shell.d.ts +47 -16
- package/dist/lib/stdlib/shell.js +114 -68
- package/dist/lib/stdlib/skills.d.ts +18 -0
- package/dist/lib/stdlib/skills.js +26 -0
- package/dist/lib/stdlib/speech.d.ts +18 -3
- package/dist/lib/stdlib/speech.js +101 -24
- package/dist/lib/stdlib/syntax.js +52 -0
- package/dist/lib/stdlib/system.d.ts +19 -5
- package/dist/lib/stdlib/system.js +54 -14
- package/dist/lib/stdlib/thread.d.ts +45 -0
- package/dist/lib/stdlib/thread.js +120 -0
- package/dist/lib/stdlib/threads.d.ts +45 -0
- package/dist/lib/stdlib/threads.js +176 -0
- package/dist/lib/stdlib/ui-region.d.ts +43 -0
- package/dist/lib/stdlib/ui-region.js +150 -0
- package/dist/lib/stdlib/ui.d.ts +198 -12
- package/dist/lib/stdlib/ui.js +680 -349
- package/dist/lib/stdlib/validators.d.ts +12 -0
- package/dist/lib/stdlib/validators.js +77 -0
- package/dist/lib/stdlib/wikipedia.js +7 -3
- package/dist/lib/symbolTable.d.ts +24 -8
- package/dist/lib/symbolTable.js +43 -25
- package/dist/lib/symbolTable.test.js +53 -0
- package/dist/lib/templates/backends/agency/template.d.ts +1 -1
- package/dist/lib/templates/backends/agency/template.js +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/blockSetup.js +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/registerTools.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/registerTools.js +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/system.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/builtinFunctions/system.js +4 -2
- package/dist/lib/templates/backends/typescriptGenerator/debugger.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/debugger.js +2 -2
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.js +10 -2
- package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/functionCatchFailure.js +28 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -2
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +23 -17
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +9 -9
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +9 -9
- package/dist/lib/templates/backends/typescriptGenerator/resultCheckpointSetup.d.ts +1 -3
- package/dist/lib/templates/backends/typescriptGenerator/resultCheckpointSetup.js +13 -4
- package/dist/lib/templates/prompts/memory/retrieval.d.ts +1 -1
- package/dist/lib/templates/prompts/memory/retrieval.js +4 -4
- package/dist/lib/tui/elements.d.ts +1 -0
- package/dist/lib/tui/input/terminal.d.ts +68 -0
- package/dist/lib/tui/input/terminal.js +187 -18
- package/dist/lib/tui/input/terminal.test.d.ts +1 -0
- package/dist/lib/tui/input/terminal.test.js +112 -0
- package/dist/lib/tui/input/types.d.ts +6 -0
- package/dist/lib/tui/output/terminal.d.ts +7 -0
- package/dist/lib/tui/output/terminal.js +61 -3
- package/dist/lib/tui/render/ansi.d.ts +3 -0
- package/dist/lib/tui/render/ansi.js +30 -24
- package/dist/lib/tui/render/renderer.js +131 -30
- package/dist/lib/tui/screen.d.ts +19 -3
- package/dist/lib/tui/screen.js +31 -5
- package/dist/lib/tui/screen.test.d.ts +1 -0
- package/dist/lib/tui/screen.test.js +56 -0
- package/dist/lib/tui/styleParser.js +1 -0
- package/dist/lib/typeChecker/assignability.d.ts +46 -3
- package/dist/lib/typeChecker/assignability.js +357 -8
- package/dist/lib/typeChecker/assignability.test.js +49 -0
- package/dist/lib/typeChecker/builtins.js +83 -26
- package/dist/lib/typeChecker/callbackBodyInterrupts.test.d.ts +1 -0
- package/dist/lib/typeChecker/callbackBodyInterrupts.test.js +168 -0
- package/dist/lib/typeChecker/checker.js +39 -21
- package/dist/lib/typeChecker/docstringParamInterpolation.test.d.ts +1 -0
- package/dist/lib/typeChecker/docstringParamInterpolation.test.js +70 -0
- package/dist/lib/typeChecker/fixtureTypeCheck.integration.test.js +7 -1
- package/dist/lib/typeChecker/genericAliasDeclaration.test.d.ts +1 -0
- package/dist/lib/typeChecker/genericAliasDeclaration.test.js +71 -0
- package/dist/lib/typeChecker/genericValidation.test.d.ts +1 -0
- package/dist/lib/typeChecker/genericValidation.test.js +212 -0
- package/dist/lib/typeChecker/handlerBodyInterrupts.test.d.ts +1 -0
- package/dist/lib/typeChecker/handlerBodyInterrupts.test.js +171 -0
- package/dist/lib/typeChecker/index.js +70 -4
- package/dist/lib/typeChecker/interruptAnalysis.d.ts +43 -1
- package/dist/lib/typeChecker/interruptAnalysis.js +183 -16
- package/dist/lib/typeChecker/interruptWarnings.test.js +24 -8
- package/dist/lib/typeChecker/jsGlobalsSig.test.js +0 -4
- package/dist/lib/typeChecker/jsonSchemaArgValidator.d.ts +60 -0
- package/dist/lib/typeChecker/jsonSchemaArgValidator.js +266 -0
- package/dist/lib/typeChecker/jsonSchemaArgValidator.test.d.ts +1 -0
- package/dist/lib/typeChecker/jsonSchemaArgValidator.test.js +179 -0
- package/dist/lib/typeChecker/mergeTags.d.ts +28 -0
- package/dist/lib/typeChecker/mergeTags.js +182 -0
- package/dist/lib/typeChecker/mergeTags.test.d.ts +1 -0
- package/dist/lib/typeChecker/mergeTags.test.js +144 -0
- package/dist/lib/typeChecker/namedArgStructure.test.d.ts +1 -0
- package/dist/lib/typeChecker/namedArgStructure.test.js +66 -0
- package/dist/lib/typeChecker/recordAssignability.test.d.ts +1 -0
- package/dist/lib/typeChecker/recordAssignability.test.js +72 -0
- package/dist/lib/typeChecker/recordSynth.test.d.ts +1 -0
- package/dist/lib/typeChecker/recordSynth.test.js +80 -0
- package/dist/lib/typeChecker/reservedNameDeclaration.test.js +15 -0
- package/dist/lib/typeChecker/resolveCall.d.ts +4 -5
- package/dist/lib/typeChecker/resolveCall.js +9 -3
- package/dist/lib/typeChecker/resolveType.test.d.ts +1 -0
- package/dist/lib/typeChecker/resolveType.test.js +478 -0
- package/dist/lib/typeChecker/resolveTypeTags.test.d.ts +1 -0
- package/dist/lib/typeChecker/resolveTypeTags.test.js +154 -0
- package/dist/lib/typeChecker/resolveVariable.d.ts +5 -15
- package/dist/lib/typeChecker/resolveVariable.js +3 -7
- package/dist/lib/typeChecker/scopes.js +53 -2
- package/dist/lib/typeChecker/shadowing.d.ts +0 -1
- package/dist/lib/typeChecker/shadowing.js +1 -5
- package/dist/lib/typeChecker/staticInitRules.d.ts +74 -0
- package/dist/lib/typeChecker/staticInitRules.js +155 -0
- package/dist/lib/typeChecker/substitute.d.ts +25 -0
- package/dist/lib/typeChecker/substitute.js +33 -0
- package/dist/lib/typeChecker/substitute.test.d.ts +1 -0
- package/dist/lib/typeChecker/substitute.test.js +165 -0
- package/dist/lib/typeChecker/synthesizer.js +46 -18
- package/dist/lib/typeChecker/typeWalker.d.ts +14 -0
- package/dist/lib/typeChecker/typeWalker.js +62 -0
- package/dist/lib/typeChecker/typeWalker.test.d.ts +1 -0
- package/dist/lib/typeChecker/typeWalker.test.js +212 -0
- package/dist/lib/typeChecker/types.d.ts +7 -2
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.js +25 -5
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.test.js +35 -0
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.js +3 -4
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.js +33 -6
- package/dist/lib/typeChecker/utils.js +4 -2
- package/dist/lib/typeChecker/validate.d.ts +2 -2
- package/dist/lib/typeChecker/validate.js +123 -5
- package/dist/lib/typeChecker/validateStaticInit.d.ts +26 -0
- package/dist/lib/typeChecker/validateStaticInit.js +39 -0
- package/dist/lib/typeChecker/validateStaticInit.test.d.ts +1 -0
- package/dist/lib/typeChecker/validateStaticInit.test.js +103 -0
- package/dist/lib/typeChecker/valueParamSubstitution.d.ts +92 -0
- package/dist/lib/typeChecker/valueParamSubstitution.js +645 -0
- package/dist/lib/typeChecker/valueParamSubstitution.test.d.ts +1 -0
- package/dist/lib/typeChecker/valueParamSubstitution.test.js +214 -0
- package/dist/lib/typeChecker.test.js +13 -4
- package/dist/lib/types/dataStructures.d.ts +6 -0
- package/dist/lib/types/function.d.ts +3 -7
- package/dist/lib/types/function.js +2 -0
- package/dist/lib/types/graphNode.d.ts +3 -3
- package/dist/lib/types/handleBlock.d.ts +2 -1
- package/dist/lib/types/literals.d.ts +1 -1
- package/dist/lib/types/messageThread.d.ts +11 -1
- package/dist/lib/types/newExpression.d.ts +14 -0
- package/dist/lib/types/newExpression.js +1 -0
- package/dist/lib/types/pattern.d.ts +8 -3
- package/dist/lib/types/staticStatement.d.ts +31 -0
- package/dist/lib/types/staticStatement.js +1 -0
- package/dist/lib/types/tag.d.ts +2 -1
- package/dist/lib/types/typeHints.d.ts +108 -1
- package/dist/lib/types.d.ts +6 -4
- package/dist/lib/types.js +2 -1
- package/dist/lib/utils/docStringText.d.ts +22 -0
- package/dist/lib/utils/docStringText.js +47 -0
- package/dist/lib/utils/formatType.js +2 -0
- package/dist/lib/utils/markdown.js +4 -1
- package/dist/lib/utils/markdown.test.js +15 -1
- package/dist/lib/utils/node.js +37 -14
- package/dist/lib/utils/schemaParam.d.ts +34 -0
- package/dist/lib/utils/schemaParam.js +48 -0
- package/dist/lib/utils/schemaParam.test.d.ts +1 -0
- package/dist/lib/utils/schemaParam.test.js +69 -0
- package/dist/lib/utils/termcolors.d.ts +44 -1
- package/dist/lib/utils/termcolors.js +5 -5
- package/dist/lib/utils.d.ts +13 -0
- package/dist/lib/utils.js +97 -0
- package/dist/lib/utils.test.d.ts +1 -0
- package/dist/lib/utils.test.js +101 -0
- package/dist/scripts/agency.js +16 -0
- package/package.json +5 -2
- package/stdlib/agency.agency +217 -3
- package/stdlib/agency.js +2032 -235
- package/stdlib/agent.agency +297 -0
- package/stdlib/agent.js +988 -159
- package/stdlib/array.js +905 -817
- package/stdlib/browser.agency +2 -2
- package/stdlib/browser.js +116 -112
- package/stdlib/calendar.js +509 -455
- package/stdlib/cli.agency +114 -0
- package/stdlib/cli.js +718 -0
- package/stdlib/clipboard.js +168 -154
- package/stdlib/date.js +772 -628
- package/stdlib/email.js +337 -313
- package/stdlib/fs.agency +124 -40
- package/stdlib/fs.js +893 -593
- package/stdlib/http.agency +61 -4
- package/stdlib/http.js +495 -107
- package/stdlib/imessage.js +108 -104
- package/stdlib/index.agency +79 -43
- package/stdlib/index.js +1195 -1163
- package/stdlib/keyring.js +312 -278
- package/stdlib/layout.agency +497 -0
- package/stdlib/layout.js +3418 -0
- package/stdlib/markdown.agency +315 -0
- package/stdlib/markdown.js +788 -0
- package/stdlib/math.js +227 -177
- package/stdlib/memory.agency +137 -15
- package/stdlib/memory.js +914 -233
- package/stdlib/oauth.agency +4 -1
- package/stdlib/oauth.js +330 -292
- package/stdlib/object.js +348 -324
- package/stdlib/path.js +369 -305
- package/stdlib/policy.agency +728 -6
- package/stdlib/policy.js +2233 -165
- package/stdlib/schemas.agency +37 -0
- package/stdlib/schemas.js +209 -0
- package/stdlib/search.agency +46 -0
- package/stdlib/search.js +364 -0
- package/stdlib/shell.agency +71 -26
- package/stdlib/shell.js +763 -543
- package/stdlib/skills.agency +94 -0
- package/stdlib/skills.js +885 -0
- package/stdlib/sms.js +114 -110
- package/stdlib/speech.agency +31 -9
- package/stdlib/speech.js +304 -236
- package/stdlib/strategy.js +408 -386
- package/stdlib/syntax.agency +20 -0
- package/stdlib/syntax.js +311 -0
- package/stdlib/system.agency +27 -4
- package/stdlib/system.js +618 -419
- package/stdlib/thread.agency +148 -0
- package/stdlib/thread.js +1002 -0
- package/stdlib/threads.agency +198 -0
- package/stdlib/threads.js +1017 -0
- package/stdlib/types.agency +58 -0
- package/stdlib/types.js +184 -0
- package/stdlib/ui.agency +1706 -50
- package/stdlib/ui.js +9536 -825
- package/stdlib/validators.agency +150 -0
- package/stdlib/validators.js +1586 -0
- package/stdlib/weather.js +175 -143
- package/stdlib/wikipedia.js +172 -148
- package/dist/lib/codegenBuiltins/contextInjected.d.ts +0 -56
- package/dist/lib/codegenBuiltins/contextInjected.js +0 -78
- package/dist/lib/codegenBuiltins/contextInjected.test.js +0 -57
- package/dist/lib/runtime/classReviver.d.ts +0 -15
- package/dist/lib/runtime/classReviver.js +0 -32
- package/dist/lib/templates/backends/typescriptGenerator/classDefinition.d.ts +0 -19
- package/dist/lib/templates/backends/typescriptGenerator/classDefinition.js +0 -48
- package/dist/lib/templates/backends/typescriptGenerator/classMethod.d.ts +0 -14
- package/dist/lib/templates/backends/typescriptGenerator/classMethod.js +0 -37
- package/dist/lib/types/classDefinition.d.ts +0 -30
- package/dist/lib/types/classDefinition.js +0 -4
- /package/dist/lib/{codegenBuiltins/contextInjected.test.d.ts → backends/docstringInterpolationRuntime.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Agency is a language for building agents that compiles to TypeScript.
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
pnpm install agency-lang
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
@@ -31,5 +31,7 @@ Now read [the docs](https://agency-lang.com) to learn more about the language an
|
|
|
31
31
|
|
|
32
32
|
Weather data in the standard library (`std::weather`) is provided by [Open-Meteo](https://open-meteo.com/). Data is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). The free API is for non-commercial use only; commercial use requires a [paid subscription](https://open-meteo.com/en/pricing).
|
|
33
33
|
|
|
34
|
+
The bundled agent's coding workflow skills (brainstorming, writing-plans, executing-plans, TDD, systematic debugging, verification-before-completion) are vendored from the [Superpowers](https://github.com/obra/superpowers) plugin by Jesse Vincent, used under the MIT license. See `lib/agents/agency-agent/skills/superpowers/ATTRIBUTION.txt`.
|
|
35
|
+
|
|
34
36
|
## License
|
|
35
37
|
MIT. See [LICENSE](./LICENSE).
|
|
@@ -1,198 +1,319 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
import { route } from "std::agent"
|
|
2
|
+
import { clearMessages, pushMessage, repl } from "std::cli"
|
|
3
|
+
import { today } from "std::date"
|
|
4
|
+
import { box, render } from "std::layout"
|
|
5
|
+
import { ScopedRuleFields, cliPolicyHandler } from "std::policy"
|
|
6
|
+
import { exists } from "std::shell"
|
|
7
|
+
import { highlight } from "std::syntax"
|
|
8
|
+
import { cwd, env } from "std::system"
|
|
9
|
+
import { getCost } from "std::thread"
|
|
10
|
+
|
|
11
|
+
import { codeSysPrompt, codeTools } from "./code.agency"
|
|
12
|
+
import { figs, title } from "./images/images.agency"
|
|
13
|
+
import { researchSysPrompt, researchTools } from "./research.agency"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// UI mode select — one-line swap between the alt-screen TUI and the
|
|
17
|
+
// line-mode REPL. Both modules expose the same `repl` / `pushMessage`
|
|
18
|
+
// / `clearMessages` surface (line mode re-exports `pushMessage` and
|
|
19
|
+
// `clearMessages` from `std::ui`). Trial both and decide. See
|
|
20
|
+
// `docs/superpowers/ideas/2026-06-02-line-mode-agent.md`.
|
|
21
|
+
//
|
|
22
|
+
//import { clearMessages, pushMessage, repl } from "std::ui"
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Agency Agent — helps users create and modify Agency code.
|
|
26
|
+
*
|
|
27
|
+
* Multi-thread architecture: the agent splits work across two
|
|
28
|
+
* specialists, each with its own thread / system prompt / tool set:
|
|
29
|
+
* - `code.agency` — writes, edits, typechecks, runs code
|
|
30
|
+
* - `research.agency` — looks up docs, fetches URLs, browses web
|
|
31
|
+
*
|
|
32
|
+
* The standard library does the heavy lifting:
|
|
33
|
+
* - `std::agent.route` runs the per-turn hop loop, owns the
|
|
34
|
+
* handoff signal, and force-answers when the hop limit is hit.
|
|
35
|
+
* - `std::policy.cliPolicyHandler` provides the interactive
|
|
36
|
+
* approve/reject/always menu and persists "always" decisions to
|
|
37
|
+
* `~/.agency-agent/policy.json`.
|
|
38
|
+
* - `std::ui.repl` provides the terminal UI: a bordered scroll
|
|
39
|
+
* output area, status line (cost + label), command palette
|
|
40
|
+
* opened with `/`, and history-aware input bar.
|
|
41
|
+
*
|
|
42
|
+
* This file's responsibilities collapse to:
|
|
43
|
+
* 1. Per-turn callback (`_runTurn`) wiring the user message into
|
|
44
|
+
* route() and printing the reply into the scroll output.
|
|
45
|
+
* 2. Per-kind ALWAYS_FIELDS map for the policy handler's
|
|
46
|
+
* "approve-always-here" option.
|
|
47
|
+
* 3. Wire the two specialists into one `RouterConfig`.
|
|
48
|
+
*
|
|
49
|
+
* Other features:
|
|
50
|
+
* - Doc-as-skills: bundles `docs/site/guide` etc. (copied to
|
|
51
|
+
* `dist/lib/agents/docs/` at build time, see makefile) and
|
|
52
|
+
* exposes each Markdown file as a skill the research agent can
|
|
53
|
+
* read on demand.
|
|
54
|
+
* - Typechecking: the code agent can call `typecheck` on any
|
|
55
|
+
* source it generates to verify the code before showing it.
|
|
56
|
+
* - File I/O tools: `read`, `write`, `edit` for actually creating /
|
|
57
|
+
* editing `.agency` files.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
// Verbose tool-call tracing, opt-in via `AGENT_DEBUG=1`.
|
|
61
|
+
const AGENT_DEBUG = env("AGENT_DEBUG") == "1"
|
|
62
|
+
|
|
63
|
+
callback("onToolCallStart") as data {
|
|
64
|
+
//if (AGENT_DEBUG) {
|
|
65
|
+
pushMessage(color.yellow("⏺ ${data.toolName}(${formatArgs(data.args)})"))
|
|
66
|
+
//}
|
|
38
67
|
}
|
|
39
68
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
strict: true,
|
|
44
|
-
numRetries: 2,
|
|
45
|
-
allowExtraKeys: true
|
|
69
|
+
def truncate(str: string, maxLength: number): string {
|
|
70
|
+
if (str.length <= maxLength) {
|
|
71
|
+
return str
|
|
46
72
|
}
|
|
73
|
+
return str.slice(0, maxLength) + "..."
|
|
47
74
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
|
|
76
|
+
def formatArgs(args: Record<string, any>): string {
|
|
77
|
+
const parts = []
|
|
78
|
+
for (key in args) {
|
|
79
|
+
const value = args[key]
|
|
80
|
+
parts.push("${key}: ${truncate(JSON.stringify(value), 50)}")
|
|
81
|
+
}
|
|
82
|
+
return parts.join(", ")
|
|
54
83
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
84
|
+
|
|
85
|
+
callback("onToolCallEnd") as data {
|
|
86
|
+
if (AGENT_DEBUG) {
|
|
87
|
+
pushMessage(
|
|
88
|
+
color.yellow(
|
|
89
|
+
"tool return: ${data.toolName} -> ${JSON.stringify(data.result)} ${data.timeTaken}ms",
|
|
90
|
+
),
|
|
91
|
+
)
|
|
92
|
+
}
|
|
58
93
|
}
|
|
59
|
-
} */
|
|
60
94
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
95
|
+
// On-disk policy at `$HOME/.agency-agent/policy.json`. We duplicate the
|
|
96
|
+
// home-dir computation here instead of importing `AGENCY_AGENT_DIR` from
|
|
97
|
+
// `shared.agency` because Agency doesn't guarantee imported static-const
|
|
98
|
+
// init runs before the importer reads it (upstream #232).
|
|
99
|
+
const POLICY_FILE = "policy.json"
|
|
100
|
+
const HISTORY_FILE = "history"
|
|
101
|
+
|
|
102
|
+
def policyDir(): string {
|
|
103
|
+
const home = env("HOME")
|
|
104
|
+
if (home == null) {
|
|
105
|
+
return "./.agency-agent"
|
|
106
|
+
}
|
|
107
|
+
return "${home}/.agency-agent"
|
|
68
108
|
}
|
|
69
109
|
|
|
70
|
-
def
|
|
71
|
-
""
|
|
72
|
-
Use this tool to write code to a file to the filesystem. The filename should include the path and extension (e.g., 'lib/agents/myAgent.agency').
|
|
73
|
-
"""
|
|
74
|
-
print(color.yellow())
|
|
75
|
-
message = "\nYou're about to write to the file ${filename} with the following content\n\n"
|
|
76
|
-
return interrupt({
|
|
77
|
-
tool: "writeCodeWithConfirm",
|
|
78
|
-
message: message,
|
|
79
|
-
content: content
|
|
80
|
-
})
|
|
81
|
-
write(filename, content)
|
|
110
|
+
def policyPath(): string {
|
|
111
|
+
return "${policyDir()}/${POLICY_FILE}"
|
|
82
112
|
}
|
|
83
113
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
print(color.cyan("Would you like to create a new agent or modify an existing one?"))
|
|
87
|
-
userinput = input("(create/modify) ")
|
|
88
|
-
thread {
|
|
89
|
-
mode: Mode = llm("categorize this user response as 'create' or 'modify': ${userinput}", config)
|
|
90
|
-
}
|
|
91
|
-
print(color.cyan("Great! Let's ${mode} an agent."))
|
|
92
|
-
match(mode) {
|
|
93
|
-
"create" => return plan("create", "", null)
|
|
94
|
-
"modify" => return readExisting()
|
|
95
|
-
}
|
|
114
|
+
def historyPath(): string {
|
|
115
|
+
return "${policyDir()}/${HISTORY_FILE}"
|
|
96
116
|
}
|
|
97
117
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
118
|
+
// Per-kind config driving the "approve-always-here" option. For each
|
|
119
|
+
// kind we list the data fields the scoped rule should pin, plus a
|
|
120
|
+
// flag that turns a directory value into a brace-expanded glob so the
|
|
121
|
+
// rule matches `dir` AND `dir/**`. Kinds not present in this map
|
|
122
|
+
// don't offer the option — the user falls back to (a)/(r)/(aa)/(rr).
|
|
123
|
+
const ALWAYS_FIELDS: ScopedRuleFields = {
|
|
124
|
+
"std::read": [{
|
|
125
|
+
field: "dir",
|
|
126
|
+
matchSubpaths: true
|
|
127
|
+
}],
|
|
128
|
+
"std::write": [{
|
|
129
|
+
field: "dir",
|
|
130
|
+
matchSubpaths: true
|
|
131
|
+
}],
|
|
132
|
+
"std::edit": [{
|
|
133
|
+
field: "dir",
|
|
134
|
+
matchSubpaths: true
|
|
135
|
+
}],
|
|
136
|
+
"std::ls": [{
|
|
137
|
+
field: "dir",
|
|
138
|
+
matchSubpaths: true
|
|
139
|
+
}],
|
|
140
|
+
"std::glob": [{
|
|
141
|
+
field: "dir",
|
|
142
|
+
matchSubpaths: true
|
|
143
|
+
}],
|
|
144
|
+
"std::grep": [{
|
|
145
|
+
field: "dir",
|
|
146
|
+
matchSubpaths: true
|
|
147
|
+
}],
|
|
148
|
+
"std::copy": [
|
|
149
|
+
{
|
|
150
|
+
field: "src",
|
|
151
|
+
matchSubpaths: true
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
field: "dest",
|
|
155
|
+
matchSubpaths: true
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
"std::move": [
|
|
159
|
+
{
|
|
160
|
+
field: "src",
|
|
161
|
+
matchSubpaths: true
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
field: "dest",
|
|
165
|
+
matchSubpaths: true
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
"std::exec": [
|
|
169
|
+
{
|
|
170
|
+
field: "command",
|
|
171
|
+
matchSubpaths: false
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
field: "subcommand",
|
|
175
|
+
matchSubpaths: false
|
|
176
|
+
},
|
|
177
|
+
]
|
|
104
178
|
}
|
|
105
179
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
180
|
+
def loadAgentsMd(dir: string): string {
|
|
181
|
+
"""
|
|
182
|
+
Read `AGENTS.md` from `dir` if it exists and return it wrapped in a
|
|
183
|
+
<project_context> block ready to splice into a system prompt. Returns
|
|
184
|
+
an empty string if there is no AGENTS.md or it cannot be read. The
|
|
185
|
+
read is auto-approved — the user implicitly opted in to scanning the
|
|
186
|
+
project directory by running the agent there.
|
|
187
|
+
"""
|
|
188
|
+
if (!exists("AGENTS.md", dir)) {
|
|
189
|
+
return ""
|
|
190
|
+
}
|
|
191
|
+
const result = read("AGENTS.md", dir) with approve
|
|
192
|
+
if (isFailure(result)) {
|
|
193
|
+
return ""
|
|
194
|
+
}
|
|
195
|
+
return "\n\n<project_context>\n${result.value}\n</project_context>"
|
|
110
196
|
}
|
|
111
197
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Focus on understanding what changes the user wants to make to this existing agent.
|
|
124
|
-
"""
|
|
198
|
+
// Per-turn grounding context. Captured at startup and re-used so the
|
|
199
|
+
// LLM doesn't have to re-ground each turn. Initialized in `main()`.
|
|
200
|
+
let _context: string = ""
|
|
201
|
+
|
|
202
|
+
// Slash-command + user-message dispatcher invoked by `repl()` for
|
|
203
|
+
// every Enter keystroke. Return `false` to terminate the loop.
|
|
204
|
+
def _runTurn(msg: string): boolean {
|
|
205
|
+
if (msg == "") {
|
|
206
|
+
return true
|
|
125
207
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
208
|
+
if (msg == "/exit" || msg == "/quit") {
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
211
|
+
if (msg == "/clear") {
|
|
212
|
+
clearMessages()
|
|
213
|
+
return true
|
|
214
|
+
}
|
|
215
|
+
if (msg == "/help") {
|
|
216
|
+
pushMessage("Commands: /exit, /clear, /help")
|
|
217
|
+
return true
|
|
218
|
+
}
|
|
219
|
+
const reply = route(
|
|
220
|
+
{
|
|
221
|
+
start: "code",
|
|
222
|
+
agents: {
|
|
223
|
+
code: {
|
|
224
|
+
systemPrompt: codeSysPrompt,
|
|
225
|
+
tools: codeTools,
|
|
226
|
+
memory: true
|
|
227
|
+
},
|
|
228
|
+
research: {
|
|
229
|
+
systemPrompt: researchSysPrompt,
|
|
230
|
+
tools: researchTools,
|
|
231
|
+
memory: true
|
|
136
232
|
}
|
|
137
|
-
}
|
|
233
|
+
},
|
|
234
|
+
maxHops: 3,
|
|
235
|
+
context: _context
|
|
236
|
+
},
|
|
237
|
+
msg,
|
|
238
|
+
)
|
|
239
|
+
pushMessage(highlight("${reply}\n", language: "markdown"))
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
def roundedCost(): string {
|
|
244
|
+
return "$${getCost().toFixed(4)}"
|
|
245
|
+
}
|
|
138
246
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
247
|
+
def _buildStatus(): { left: string; right: string; context: string } {
|
|
248
|
+
return {
|
|
249
|
+
left: "",
|
|
250
|
+
right: roundedCost(),
|
|
251
|
+
context: ""
|
|
142
252
|
}
|
|
143
|
-
return design(plan, mode, existingCode, existingFilename)
|
|
144
253
|
}
|
|
145
254
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
desiredActions: string[] # array of descriptions of each action
|
|
255
|
+
def sample(arr: any[]): any {
|
|
256
|
+
return arr[Math.floor(Math.random() * arr.length)]
|
|
149
257
|
}
|
|
150
258
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
The user wants to make the following modifications:
|
|
166
|
-
Goal: ${plan.overallGoal}
|
|
167
|
-
Desired changes: ${plan.desiredActions}
|
|
168
|
-
|
|
169
|
-
Modify the existing code to accomplish these changes. Preserve the existing style and structure where possible.
|
|
170
|
-
"""
|
|
171
|
-
} else {
|
|
172
|
-
print(color.cyan("Now let's design an agent to accomplish that plan."))
|
|
173
|
-
prompt = """
|
|
174
|
-
Help the user design an agent that can accomplish the following goal: ${plan.overallGoal}
|
|
175
|
-
with the following actions: ${plan.desiredActions}.
|
|
176
|
-
"""
|
|
177
|
-
}
|
|
178
|
-
thread {
|
|
179
|
-
system(designPrompt)
|
|
180
|
-
userMsg = prompt
|
|
181
|
-
nextAction: DesignAction = {
|
|
182
|
-
type: "start"
|
|
183
|
-
}
|
|
184
|
-
i = 0
|
|
185
|
-
while (nextAction.type != "done") {
|
|
186
|
-
i += 1
|
|
187
|
-
print(color.blue("Design iteration ${i}"))
|
|
188
|
-
nextAction: DesignAction = llm("${userMsg}", config)
|
|
189
|
-
if (nextAction.type == "askUser") {
|
|
190
|
-
userMsg = input("\n${nextAction.question} ")
|
|
259
|
+
def printHeader() {
|
|
260
|
+
const fig = sample(figs)
|
|
261
|
+
const data = box(title: "Agency", padding: 1, borderColor: "cyan", titleColor: "cyan") as b {
|
|
262
|
+
b.row(gap: 1) as r {
|
|
263
|
+
r.column() as left {
|
|
264
|
+
left.text("Welcome to the Agency Agent!", bold: true)
|
|
265
|
+
left.text("Ask me to write code, look up docs, or just chat.")
|
|
266
|
+
left.hline()
|
|
267
|
+
left.text("Getting Started", bold: true, fgColor: "cyan")
|
|
268
|
+
left.text("/help for commands · /exit to quit", dim: true)
|
|
269
|
+
}
|
|
270
|
+
r.vline()
|
|
271
|
+
r.column() as right {
|
|
272
|
+
right.raw(fig)
|
|
191
273
|
}
|
|
192
274
|
}
|
|
193
275
|
}
|
|
194
|
-
print(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
276
|
+
print(render(data, color: true))
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
node main() {
|
|
280
|
+
printHeader()
|
|
281
|
+
|
|
282
|
+
// Grounding: the LLM should not have to ask the user where it is
|
|
283
|
+
// or what day it is. Both are appended once per run so they ride
|
|
284
|
+
// with the first system message in each specialist's thread.
|
|
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.
|
|
289
|
+
const projectContext = loadAgentsMd(cwd()) with approve
|
|
290
|
+
_context = "\n\nCurrent date: ${today()}\nCurrent working directory: ${cwd()}${projectContext}"
|
|
291
|
+
|
|
292
|
+
// Bind the handler to a local var so `with handler` parses (the
|
|
293
|
+
// `with` clause only accepts an identifier, not a call expression).
|
|
294
|
+
const handler = cliPolicyHandler({
|
|
295
|
+
file: policyPath(),
|
|
296
|
+
fields: ALWAYS_FIELDS
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
// The `repl()` widget owns the runloop; every Enter dispatches into
|
|
300
|
+
// `_runTurn` which calls `route()`. Interrupts raised inside
|
|
301
|
+
// route() propagate to the policy handler installed by the enclosing
|
|
302
|
+
// `handle` block via the AsyncLocalStorage handler stack.
|
|
303
|
+
handle {
|
|
304
|
+
repl(
|
|
305
|
+
status: _buildStatus,
|
|
306
|
+
onSubmit: _runTurn,
|
|
307
|
+
prompt: "> ",
|
|
308
|
+
historyFile: historyPath(),
|
|
309
|
+
historyMax: 1000,
|
|
310
|
+
paletteCommands: {
|
|
311
|
+
"/exit": "Exit the agent",
|
|
312
|
+
"/clear": "Clear the conversation transcript",
|
|
313
|
+
"/help": "Show available slash commands"
|
|
314
|
+
},
|
|
315
|
+
)
|
|
316
|
+
} with handler
|
|
317
|
+
|
|
318
|
+
print(color.cyan("\nGoodbye!"))
|
|
319
|
+
}
|