agency-lang 0.1.2 → 0.2.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/LICENSE +21 -0
- package/README.md +1 -1
- package/dist/lib/agents/judge.js +12 -5
- package/dist/lib/agents/policy/agent.agency +29 -21
- package/dist/lib/agents/review/agent.js +12 -5
- package/dist/lib/backends/agencyGenerator.d.ts +10 -0
- package/dist/lib/backends/agencyGenerator.js +79 -22
- package/dist/lib/backends/agencyGenerator.test.js +85 -0
- package/dist/lib/backends/typescriptBuilder.d.ts +64 -0
- package/dist/lib/backends/typescriptBuilder.integration.test.js +5 -46
- package/dist/lib/backends/typescriptBuilder.js +294 -11
- package/dist/lib/backends/typescriptGenerator/typeToString.d.ts +1 -1
- package/dist/lib/backends/typescriptGenerator/typeToString.js +11 -8
- package/dist/lib/backends/typescriptGenerator.integration.test.js +6 -52
- package/dist/lib/cli/commands.d.ts +6 -1
- package/dist/lib/cli/commands.js +76 -7
- package/dist/lib/cli/coverage.d.ts +21 -2
- package/dist/lib/cli/coverage.js +51 -2
- package/dist/lib/cli/doc.js +29 -6
- package/dist/lib/cli/doc.test.js +38 -0
- package/dist/lib/cli/installLocation.d.ts +3 -0
- package/dist/lib/cli/installLocation.js +40 -0
- package/dist/lib/cli/installLocation.test.js +32 -0
- package/dist/lib/cli/logsView.d.ts +3 -0
- package/dist/lib/cli/logsView.js +96 -0
- package/dist/lib/cli/pack.d.ts +10 -0
- package/dist/lib/cli/pack.js +205 -0
- package/dist/lib/cli/pack.test.d.ts +1 -0
- package/dist/lib/cli/pack.test.js +131 -0
- package/dist/lib/cli/policy.js +31 -7
- package/dist/lib/cli/run.spawn.test.d.ts +1 -0
- package/dist/lib/cli/run.spawn.test.js +53 -0
- package/dist/lib/cli/runBundledAgent.js +10 -4
- package/dist/lib/cli/runShim/register.mjs +5 -0
- package/dist/lib/cli/runShim/resolver.mjs +59 -0
- package/dist/lib/cli/runShim/resolver.test.d.ts +1 -0
- package/dist/lib/cli/runShim/resolver.test.js +69 -0
- package/dist/lib/cli/schedule/backends/github.d.ts +18 -0
- package/dist/lib/cli/schedule/backends/github.js +113 -0
- package/dist/lib/cli/schedule/backends/github.snapshot.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/github.snapshot.test.js +50 -0
- package/dist/lib/cli/schedule/backends/github.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/github.test.js +165 -0
- package/dist/lib/cli/schedule/backends/index.d.ts +3 -1
- package/dist/lib/cli/schedule/backends/index.js +4 -0
- package/dist/lib/cli/schedule/backends/index.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/index.test.js +9 -0
- package/dist/lib/cli/schedule/backends/pinnedActions.d.ts +5 -0
- package/dist/lib/cli/schedule/backends/pinnedActions.js +16 -0
- package/dist/lib/cli/schedule/index.d.ts +11 -0
- package/dist/lib/cli/schedule/index.github.test.d.ts +1 -0
- package/dist/lib/cli/schedule/index.github.test.js +123 -0
- package/dist/lib/cli/schedule/index.js +56 -5
- package/dist/lib/cli/schedule/registry.d.ts +7 -0
- package/dist/lib/cli/test.js +8 -0
- package/dist/lib/codegenBuiltins/contextInjected.d.ts +56 -0
- package/dist/lib/codegenBuiltins/contextInjected.js +78 -0
- package/dist/lib/codegenBuiltins/contextInjected.test.d.ts +1 -0
- package/dist/lib/codegenBuiltins/contextInjected.test.js +57 -0
- package/dist/lib/compilationUnit.d.ts +8 -0
- package/dist/lib/compilationUnit.js +14 -0
- package/dist/lib/compiler/compile.js +1 -1
- package/dist/lib/compiler/compile.test.js +1 -1
- package/dist/lib/config.d.ts +180 -14
- package/dist/lib/config.js +59 -4
- package/dist/lib/config.test.js +67 -0
- package/dist/lib/constants.d.ts +20 -0
- package/dist/lib/constants.js +20 -0
- package/dist/lib/debugger/driver.js +12 -15
- package/dist/lib/debugger/driver.test.js +31 -13
- package/dist/lib/debugger/thread.test.js +3 -3
- package/dist/lib/debugger/trace.test.js +24 -38
- package/dist/lib/debugger/ui.js +33 -3
- package/dist/lib/formatter.js +3 -1
- package/dist/lib/importPaths.d.ts +7 -1
- package/dist/lib/importPaths.js +43 -12
- package/dist/lib/ir/prettyPrint.js +9 -1
- package/dist/lib/ir/prettyPrint.test.js +21 -0
- package/dist/lib/logsViewer/clipboard.d.ts +6 -0
- package/dist/lib/logsViewer/clipboard.js +61 -0
- package/dist/lib/logsViewer/clipboard.test.d.ts +1 -0
- package/dist/lib/logsViewer/clipboard.test.js +60 -0
- package/dist/lib/logsViewer/conversation.d.ts +20 -0
- package/dist/lib/logsViewer/conversation.js +91 -0
- package/dist/lib/logsViewer/conversation.test.d.ts +1 -0
- package/dist/lib/logsViewer/conversation.test.js +59 -0
- package/dist/lib/logsViewer/follow.d.ts +9 -0
- package/dist/lib/logsViewer/follow.js +53 -0
- package/dist/lib/logsViewer/follow.test.d.ts +1 -0
- package/dist/lib/logsViewer/follow.test.js +70 -0
- package/dist/lib/logsViewer/help.d.ts +9 -0
- package/dist/lib/logsViewer/help.js +60 -0
- package/dist/lib/logsViewer/input.d.ts +15 -0
- package/dist/lib/logsViewer/input.js +187 -0
- package/dist/lib/logsViewer/input.test.d.ts +1 -0
- package/dist/lib/logsViewer/input.test.js +163 -0
- package/dist/lib/logsViewer/jsonView/build.d.ts +3 -0
- package/dist/lib/logsViewer/jsonView/build.js +70 -0
- package/dist/lib/logsViewer/jsonView/build.test.d.ts +1 -0
- package/dist/lib/logsViewer/jsonView/build.test.js +113 -0
- package/dist/lib/logsViewer/jsonView/input.d.ts +12 -0
- package/dist/lib/logsViewer/jsonView/input.js +111 -0
- package/dist/lib/logsViewer/jsonView/input.test.d.ts +1 -0
- package/dist/lib/logsViewer/jsonView/input.test.js +76 -0
- package/dist/lib/logsViewer/jsonView/render.d.ts +18 -0
- package/dist/lib/logsViewer/jsonView/render.js +221 -0
- package/dist/lib/logsViewer/jsonView/render.test.d.ts +1 -0
- package/dist/lib/logsViewer/jsonView/render.test.js +93 -0
- package/dist/lib/logsViewer/jsonView/types.d.ts +22 -0
- package/dist/lib/logsViewer/jsonView/types.js +3 -0
- package/dist/lib/logsViewer/parse.d.ts +11 -0
- package/dist/lib/logsViewer/parse.js +61 -0
- package/dist/lib/logsViewer/parse.test.d.ts +1 -0
- package/dist/lib/logsViewer/parse.test.js +67 -0
- package/dist/lib/logsViewer/render.d.ts +20 -0
- package/dist/lib/logsViewer/render.js +243 -0
- package/dist/lib/logsViewer/render.test.d.ts +1 -0
- package/dist/lib/logsViewer/render.test.js +184 -0
- package/dist/lib/logsViewer/run.d.ts +16 -0
- package/dist/lib/logsViewer/run.js +293 -0
- package/dist/lib/logsViewer/run.test.d.ts +1 -0
- package/dist/lib/logsViewer/run.test.js +158 -0
- package/dist/lib/logsViewer/search.d.ts +8 -0
- package/dist/lib/logsViewer/search.js +119 -0
- package/dist/lib/logsViewer/search.test.d.ts +1 -0
- package/dist/lib/logsViewer/search.test.js +180 -0
- package/dist/lib/logsViewer/summary.d.ts +7 -0
- package/dist/lib/logsViewer/summary.js +153 -0
- package/dist/lib/logsViewer/summary.test.d.ts +1 -0
- package/dist/lib/logsViewer/summary.test.js +155 -0
- package/dist/lib/logsViewer/thresholds.d.ts +9 -0
- package/dist/lib/logsViewer/thresholds.js +22 -0
- package/dist/lib/logsViewer/thresholds.test.d.ts +1 -0
- package/dist/lib/logsViewer/thresholds.test.js +26 -0
- package/dist/lib/logsViewer/tree.d.ts +2 -0
- package/dist/lib/logsViewer/tree.js +247 -0
- package/dist/lib/logsViewer/tree.test.d.ts +1 -0
- package/dist/lib/logsViewer/tree.test.js +277 -0
- package/dist/lib/logsViewer/types.d.ts +40 -0
- package/dist/lib/logsViewer/types.js +1 -0
- package/dist/lib/lowering/patternLowering.d.ts +18 -0
- package/dist/lib/lowering/patternLowering.js +631 -0
- package/dist/lib/lowering/patternLowering.test.d.ts +8 -0
- package/dist/lib/lowering/patternLowering.test.js +383 -0
- package/dist/lib/lsp/builtinHover.d.ts +20 -0
- package/dist/lib/lsp/builtinHover.js +85 -0
- package/dist/lib/lsp/diagnostics.js +53 -0
- package/dist/lib/lsp/diagnostics.test.js +34 -0
- package/dist/lib/lsp/hover.js +41 -0
- package/dist/lib/lsp/hover.test.js +43 -0
- package/dist/lib/parser.d.ts +1 -1
- package/dist/lib/parser.js +27 -2
- package/dist/lib/parsers/blockArgument.test.js +7 -2
- package/dist/lib/parsers/expression.test.js +58 -0
- package/dist/lib/parsers/literals.test.js +33 -2
- package/dist/lib/parsers/parsers.d.ts +16 -0
- package/dist/lib/parsers/parsers.js +241 -17
- package/dist/lib/parsers/pattern.test.d.ts +1 -0
- package/dist/lib/parsers/pattern.test.js +672 -0
- package/dist/lib/parsers/typeHints.test.js +35 -0
- package/dist/lib/parsers/withModifier.test.js +10 -0
- package/dist/lib/preprocessors/typescriptPreprocessor.core.test.js +0 -551
- package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -8
- package/dist/lib/preprocessors/typescriptPreprocessor.integration.test.js +6 -50
- package/dist/lib/preprocessors/typescriptPreprocessor.js +0 -192
- package/dist/lib/runtime/agencyFunction.d.ts +5 -0
- package/dist/lib/runtime/agencyFunction.js +35 -0
- package/dist/lib/runtime/call.js +10 -0
- package/dist/lib/runtime/call.test.js +14 -0
- package/dist/lib/runtime/deterministicClient.d.ts +2 -1
- package/dist/lib/runtime/deterministicClient.js +12 -0
- package/dist/lib/runtime/interrupts.d.ts +1 -0
- package/dist/lib/runtime/interrupts.js +179 -76
- package/dist/lib/runtime/llmClient.d.ts +19 -0
- package/dist/lib/runtime/llmClient.js +9 -0
- package/dist/lib/runtime/memory/cacheEntry.d.ts +113 -0
- package/dist/lib/runtime/memory/cacheEntry.js +153 -0
- package/dist/lib/runtime/memory/cacheEntry.test.d.ts +1 -0
- package/dist/lib/runtime/memory/cacheEntry.test.js +136 -0
- package/dist/lib/runtime/memory/compaction.d.ts +21 -0
- package/dist/lib/runtime/memory/compaction.js +46 -0
- package/dist/lib/runtime/memory/compaction.test.d.ts +1 -0
- package/dist/lib/runtime/memory/compaction.test.js +87 -0
- package/dist/lib/runtime/memory/embeddings.d.ts +18 -0
- package/dist/lib/runtime/memory/embeddings.js +59 -0
- package/dist/lib/runtime/memory/embeddings.test.d.ts +1 -0
- package/dist/lib/runtime/memory/embeddings.test.js +65 -0
- package/dist/lib/runtime/memory/extraction.d.ts +43 -0
- package/dist/lib/runtime/memory/extraction.js +88 -0
- package/dist/lib/runtime/memory/extraction.test.d.ts +1 -0
- package/dist/lib/runtime/memory/extraction.test.js +85 -0
- package/dist/lib/runtime/memory/graph.d.ts +24 -0
- package/dist/lib/runtime/memory/graph.js +126 -0
- package/dist/lib/runtime/memory/graph.test.d.ts +1 -0
- package/dist/lib/runtime/memory/graph.test.js +106 -0
- package/dist/lib/runtime/memory/index.d.ts +9 -0
- package/dist/lib/runtime/memory/index.js +6 -0
- package/dist/lib/runtime/memory/manager.d.ts +217 -0
- package/dist/lib/runtime/memory/manager.js +1012 -0
- package/dist/lib/runtime/memory/manager.test.d.ts +1 -0
- package/dist/lib/runtime/memory/manager.test.js +446 -0
- package/dist/lib/runtime/memory/retrieval.d.ts +8 -0
- package/dist/lib/runtime/memory/retrieval.js +106 -0
- package/dist/lib/runtime/memory/retrieval.test.d.ts +1 -0
- package/dist/lib/runtime/memory/retrieval.test.js +118 -0
- package/dist/lib/runtime/memory/store.d.ts +21 -0
- package/dist/lib/runtime/memory/store.js +105 -0
- package/dist/lib/runtime/memory/store.test.d.ts +1 -0
- package/dist/lib/runtime/memory/store.test.js +111 -0
- package/dist/lib/runtime/memory/types.d.ts +129 -0
- package/dist/lib/runtime/memory/types.js +69 -0
- package/dist/lib/runtime/node.js +69 -4
- package/dist/lib/runtime/prompt.js +231 -97
- package/dist/lib/runtime/revivers/functionRefReviver.js +19 -9
- package/dist/lib/runtime/rewind.js +9 -1
- package/dist/lib/runtime/runner.d.ts +11 -0
- package/dist/lib/runtime/runner.js +183 -39
- package/dist/lib/runtime/simpleOpenAIClient.d.ts +2 -1
- package/dist/lib/runtime/simpleOpenAIClient.js +32 -0
- package/dist/lib/runtime/state/context.d.ts +21 -0
- package/dist/lib/runtime/state/context.js +63 -0
- package/dist/lib/runtime/state/threadStore.d.ts +4 -1
- package/dist/lib/runtime/state/threadStore.js +22 -1
- package/dist/lib/runtime/trace/contentAddressableStore.d.ts +10 -0
- package/dist/lib/runtime/trace/contentAddressableStore.js +13 -0
- package/dist/lib/runtime/trace/contentAddressableStore.test.js +19 -0
- package/dist/lib/runtime/trace/sinks.js +13 -1
- package/dist/lib/runtime/trace/traceWriter.d.ts +41 -1
- package/dist/lib/runtime/trace/traceWriter.js +96 -11
- package/dist/lib/runtime/trace/traceWriter.test.js +145 -1
- package/dist/lib/runtime/trace/types.d.ts +22 -0
- package/dist/lib/simplemachine/graph.d.ts +2 -0
- package/dist/lib/simplemachine/graph.js +28 -19
- package/dist/lib/simplemachine/types.d.ts +2 -0
- package/dist/lib/statelogClient.d.ts +224 -2
- package/dist/lib/statelogClient.js +390 -10
- package/dist/lib/statelogClient.test.d.ts +1 -0
- package/dist/lib/statelogClient.test.js +697 -0
- package/dist/lib/stdlib/agency.js +1 -1
- package/dist/lib/stdlib/builtins.d.ts +1 -0
- package/dist/lib/stdlib/builtins.js +3 -0
- package/dist/lib/stdlib/memory.d.ts +24 -0
- package/dist/lib/stdlib/memory.js +56 -0
- package/dist/lib/stdlib/syntax.js +19 -16
- package/dist/lib/symbolTable.js +5 -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/forkBlockSetup.d.ts +2 -1
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.js +14 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +2 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +11 -1
- package/dist/lib/templates/cli/schedule/githubWorkflow.d.ts +14 -0
- package/dist/lib/templates/cli/schedule/githubWorkflow.js +30 -0
- package/dist/lib/templates/prompts/memory/compaction.d.ts +6 -0
- package/dist/lib/templates/prompts/memory/compaction.js +15 -0
- package/dist/lib/templates/prompts/memory/extraction.d.ts +7 -0
- package/dist/lib/templates/prompts/memory/extraction.js +20 -0
- package/dist/lib/templates/prompts/memory/forget.d.ts +7 -0
- package/dist/lib/templates/prompts/memory/forget.js +21 -0
- package/dist/lib/templates/prompts/memory/mergeSummary.d.ts +7 -0
- package/dist/lib/templates/prompts/memory/mergeSummary.js +18 -0
- package/dist/lib/templates/prompts/memory/retrieval.d.ts +7 -0
- package/dist/lib/templates/prompts/memory/retrieval.js +25 -0
- package/dist/lib/tui/builders.d.ts +3 -1
- package/dist/lib/tui/builders.js +28 -28
- package/dist/lib/tui/builders.test.d.ts +1 -0
- package/dist/lib/tui/builders.test.js +38 -0
- package/dist/lib/tui/colors.d.ts +16 -0
- package/dist/lib/tui/colors.js +20 -0
- package/dist/lib/tui/elements.d.ts +12 -4
- package/dist/lib/tui/frame.d.ts +6 -0
- package/dist/lib/tui/frame.js +9 -1
- package/dist/lib/tui/index.d.ts +3 -0
- package/dist/lib/tui/index.js +3 -0
- package/dist/lib/tui/input/format.d.ts +3 -0
- package/dist/lib/tui/input/format.js +37 -0
- package/dist/lib/tui/input/format.test.d.ts +1 -0
- package/dist/lib/tui/input/format.test.js +26 -0
- package/dist/lib/tui/input/scripted.d.ts +5 -0
- package/dist/lib/tui/input/scripted.js +13 -2
- package/dist/lib/tui/input/terminal.d.ts +5 -0
- package/dist/lib/tui/input/terminal.js +72 -3
- package/dist/lib/tui/layout.js +16 -30
- package/dist/lib/tui/output/recorder.d.ts +3 -1
- package/dist/lib/tui/output/recorder.js +31 -1
- package/dist/lib/tui/output/terminal.d.ts +2 -1
- package/dist/lib/tui/output/terminal.js +19 -3
- package/dist/lib/tui/render/ansi.js +39 -10
- package/dist/lib/tui/render/html.js +28 -14
- package/dist/lib/tui/render/renderer.js +25 -10
- package/dist/lib/tui/screen.d.ts +7 -0
- package/dist/lib/tui/screen.js +10 -0
- package/dist/lib/tui/scroll.d.ts +2 -0
- package/dist/lib/tui/scroll.js +26 -0
- package/dist/lib/tui/scroll.test.d.ts +1 -0
- package/dist/lib/tui/scroll.test.js +30 -0
- package/dist/lib/tui/scrollList.d.ts +28 -0
- package/dist/lib/tui/scrollList.js +29 -0
- package/dist/lib/tui/scrollList.test.d.ts +1 -0
- package/dist/lib/tui/scrollList.test.js +78 -0
- package/dist/lib/tui/styleParser.js +172 -18
- package/dist/lib/tui/utils.d.ts +12 -1
- package/dist/lib/tui/utils.js +15 -0
- package/dist/lib/typeChecker/assignability.js +30 -0
- package/dist/lib/typeChecker/assignability.test.js +22 -0
- package/dist/lib/typeChecker/blockBody.test.js +3 -1
- package/dist/lib/typeChecker/builtinSignatures.test.d.ts +1 -0
- package/dist/lib/typeChecker/builtinSignatures.test.js +51 -0
- package/dist/lib/typeChecker/builtins.d.ts +8 -5
- package/dist/lib/typeChecker/builtins.js +35 -25
- package/dist/lib/typeChecker/checker.js +149 -38
- package/dist/lib/typeChecker/constReassignment.test.d.ts +1 -0
- package/dist/lib/typeChecker/constReassignment.test.js +88 -0
- package/dist/lib/typeChecker/fixtureTypeCheck.integration.test.d.ts +1 -0
- package/dist/lib/typeChecker/fixtureTypeCheck.integration.test.js +72 -0
- package/dist/lib/typeChecker/index.d.ts +1 -0
- package/dist/lib/typeChecker/index.js +30 -22
- package/dist/lib/typeChecker/interruptAnalysis.js +16 -12
- package/dist/lib/typeChecker/interruptWarnings.test.js +53 -0
- package/dist/lib/typeChecker/jsGlobalsSig.test.d.ts +1 -0
- package/dist/lib/typeChecker/jsGlobalsSig.test.js +100 -0
- package/dist/lib/typeChecker/primitiveMembers.d.ts +80 -0
- package/dist/lib/typeChecker/primitiveMembers.js +183 -0
- package/dist/lib/typeChecker/primitiveMembers.test.d.ts +1 -0
- package/dist/lib/typeChecker/primitiveMembers.test.js +56 -0
- package/dist/lib/typeChecker/primitiveMembersIntegration.test.d.ts +1 -0
- package/dist/lib/typeChecker/primitiveMembersIntegration.test.js +171 -0
- package/dist/lib/typeChecker/reservedNameDeclaration.test.d.ts +1 -0
- package/dist/lib/typeChecker/reservedNameDeclaration.test.js +57 -0
- package/dist/lib/typeChecker/resolveCall.d.ts +160 -0
- package/dist/lib/typeChecker/resolveCall.js +292 -0
- package/dist/lib/typeChecker/resolveCall.test.d.ts +1 -0
- package/dist/lib/typeChecker/resolveCall.test.js +115 -0
- package/dist/lib/typeChecker/resolveVariable.d.ts +77 -0
- package/dist/lib/typeChecker/resolveVariable.js +37 -0
- package/dist/lib/typeChecker/schemaType.test.d.ts +1 -0
- package/dist/lib/typeChecker/schemaType.test.js +79 -0
- package/dist/lib/typeChecker/scope.d.ts +14 -1
- package/dist/lib/typeChecker/scope.js +28 -2
- package/dist/lib/typeChecker/scope.test.js +16 -0
- package/dist/lib/typeChecker/scopes.js +121 -3
- package/dist/lib/typeChecker/shadowing.d.ts +11 -0
- package/dist/lib/typeChecker/shadowing.js +19 -0
- package/dist/lib/typeChecker/suppression.test.js +3 -1
- package/dist/lib/typeChecker/synthesizer.js +284 -7
- package/dist/lib/typeChecker/typeWalker.js +2 -0
- package/dist/lib/typeChecker/types.d.ts +2 -0
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.d.ts +15 -0
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.js +138 -0
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.test.d.ts +1 -0
- package/dist/lib/typeChecker/undefinedFunctionDiagnostic.test.js +273 -0
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.d.ts +29 -0
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.js +129 -0
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.d.ts +1 -0
- package/dist/lib/typeChecker/undefinedVariableDiagnostic.test.js +80 -0
- package/dist/lib/typeChecker.test.js +65 -63
- package/dist/lib/types/forLoop.d.ts +2 -1
- package/dist/lib/types/matchBlock.d.ts +4 -2
- package/dist/lib/types/pattern.d.ts +35 -0
- package/dist/lib/types/pattern.js +1 -0
- package/dist/lib/types/typeHints.d.ts +12 -1
- package/dist/lib/types.d.ts +5 -2
- package/dist/lib/types.js +1 -0
- package/dist/lib/utils/agentUtils.d.ts +1 -1
- package/dist/lib/utils/agentUtils.js +3 -75
- package/dist/lib/utils/formatType.js +2 -0
- package/dist/lib/utils/mapBodies.d.ts +20 -0
- package/dist/lib/utils/mapBodies.js +48 -0
- package/dist/lib/utils/termcolors.d.ts +7 -1
- package/dist/lib/utils/termcolors.js +44 -0
- package/dist/scripts/agency.js +83 -6
- package/dist/tests/fixtureDiscovery.d.ts +25 -0
- package/dist/tests/fixtureDiscovery.js +60 -0
- package/package.json +4 -5
- package/stdlib/agency.js +12 -5
- package/stdlib/agent.js +12 -5
- package/stdlib/array.js +12 -5
- package/stdlib/browser.js +12 -5
- package/stdlib/calendar.js +12 -5
- package/stdlib/clipboard.js +12 -5
- package/stdlib/date.js +12 -5
- package/stdlib/email.js +12 -5
- package/stdlib/fs.js +12 -5
- package/stdlib/http.js +12 -5
- package/stdlib/imessage.js +12 -5
- package/stdlib/index.agency +8 -1
- package/stdlib/index.js +122 -6
- package/stdlib/keyring.js +12 -5
- package/stdlib/math.js +12 -5
- package/stdlib/memory.agency +92 -0
- package/stdlib/memory.js +690 -0
- package/stdlib/oauth.js +12 -5
- package/stdlib/object.js +12 -5
- package/stdlib/path.js +12 -5
- package/stdlib/policy.js +12 -5
- package/stdlib/shell.js +12 -5
- package/stdlib/sms.js +12 -5
- package/stdlib/speech.js +12 -5
- package/stdlib/strategy.js +12 -5
- package/stdlib/system.js +12 -5
- package/stdlib/ui.js +12 -5
- package/stdlib/weather.js +12 -5
- package/stdlib/wikipedia.js +12 -5
- package/dist/lib/preprocessors/typescriptPreprocessor.test.js +0 -283
- /package/dist/lib/{preprocessors/typescriptPreprocessor.test.d.ts → cli/installLocation.test.d.ts} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aditya Bhargava
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -32,4 +32,4 @@ Now read [the docs](https://agency-lang.com) to learn more about the language an
|
|
|
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
34
|
## License
|
|
35
|
-
[
|
|
35
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/lib/agents/judge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
|
|
1
|
+
import { print, printJSON, parseJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import __process from "process";
|
|
4
4
|
import { z } from "agency-lang/zod";
|
|
@@ -39,7 +39,9 @@ const __globalCtx = new RuntimeContext({
|
|
|
39
39
|
host: "https://statelog.adit.io",
|
|
40
40
|
apiKey: __process.env["STATELOG_API_KEY"] || "",
|
|
41
41
|
projectId: "agency-lang",
|
|
42
|
-
debugMode: false
|
|
42
|
+
debugMode: false,
|
|
43
|
+
observability: true,
|
|
44
|
+
logFile: "statelog.log"
|
|
43
45
|
},
|
|
44
46
|
smoltalkDefaults: {
|
|
45
47
|
openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
|
|
@@ -54,9 +56,13 @@ const __globalCtx = new RuntimeContext({
|
|
|
54
56
|
}
|
|
55
57
|
},
|
|
56
58
|
dirname: __dirname,
|
|
59
|
+
logLevel: "info",
|
|
57
60
|
traceConfig: {
|
|
58
61
|
program: "dist/lib/agents/judge.agency",
|
|
59
62
|
traceDir: "traces"
|
|
63
|
+
},
|
|
64
|
+
memory: {
|
|
65
|
+
dir: ".agency-memory"
|
|
60
66
|
}
|
|
61
67
|
});
|
|
62
68
|
const graph = __globalCtx.graph;
|
|
@@ -77,8 +83,8 @@ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __global
|
|
|
77
83
|
const __setDebugger = (dbg) => {
|
|
78
84
|
__globalCtx.debuggerState = dbg;
|
|
79
85
|
};
|
|
80
|
-
const
|
|
81
|
-
__globalCtx.
|
|
86
|
+
const __setTraceFile = (filePath) => {
|
|
87
|
+
__globalCtx.traceConfig.traceFile = filePath;
|
|
82
88
|
};
|
|
83
89
|
const __setLLMClient = (client) => {
|
|
84
90
|
__globalCtx.setLLMClient(client);
|
|
@@ -111,6 +117,7 @@ function registerTools(tools) {
|
|
|
111
117
|
}
|
|
112
118
|
__registerTool(print);
|
|
113
119
|
__registerTool(printJSON);
|
|
120
|
+
__registerTool(parseJSON);
|
|
114
121
|
__registerTool(input);
|
|
115
122
|
__registerTool(sleep);
|
|
116
123
|
__registerTool(round);
|
|
@@ -253,7 +260,7 @@ export {
|
|
|
253
260
|
__judgeNodeParams,
|
|
254
261
|
__setDebugger,
|
|
255
262
|
__setLLMClient,
|
|
256
|
-
|
|
263
|
+
__setTraceFile,
|
|
257
264
|
__sourceMap,
|
|
258
265
|
__toolRegistry,
|
|
259
266
|
approve,
|
|
@@ -1,38 +1,44 @@
|
|
|
1
|
+
import { map } from "std::array"
|
|
1
2
|
import { writePolicyFile } from "std::policy"
|
|
2
3
|
import { args } from "std::system"
|
|
3
4
|
|
|
4
5
|
systemPrompt = read("./prompts/system.md")
|
|
5
6
|
|
|
6
|
-
type NextStep =
|
|
7
|
+
type NextStep =
|
|
8
|
+
| { type: "showPolicy"; policy: object }
|
|
9
|
+
| { type: "writePolicy"; policy: object }
|
|
10
|
+
| { type: "askQuestion"; question: string }
|
|
11
|
+
|
|
12
|
+
def get(array: any[], index: number) {
|
|
13
|
+
if (index < array.length) {
|
|
14
|
+
return success(array[index])
|
|
15
|
+
}
|
|
16
|
+
return failure("Index out of bounds: ${index} >= ${array.length}")
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
node main() {
|
|
9
|
-
|
|
20
|
+
const cliArgs = args()
|
|
10
21
|
if (cliArgs.length < 2) {
|
|
11
22
|
print("Usage: agency policy gen <file>")
|
|
12
23
|
return end()
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
let outputPath = cliArgs[1]
|
|
16
|
-
let existingPolicyJson = ""
|
|
17
|
-
if (cliArgs.length >= 3) {
|
|
18
|
-
existingPolicyJson = cliArgs[2]
|
|
19
|
-
}
|
|
25
|
+
print(cliArgs)
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
existingPolicy = parseJSON(existingPolicyJson)
|
|
25
|
-
}
|
|
27
|
+
const interruptKinds = cliArgs[0] |> parseJSON
|
|
28
|
+
const outputPath = cliArgs[1]
|
|
29
|
+
const existingPolicy = get(cliArgs, 3) |> parseJSON
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (isFailure(interruptKinds)) {
|
|
32
|
+
print("Failed to parse interrupt kinds: ${interruptKinds.error}")
|
|
33
|
+
return null
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
let contextMessage = "This agent can produce the following interrupts:\n" + map(interruptKinds, kind -> `- ${kind}\n`).join("")
|
|
37
|
+
|
|
32
38
|
if (existingPolicy != null) {
|
|
33
39
|
contextMessage = contextMessage + """
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
|
|
41
|
+
"""
|
|
36
42
|
} else {
|
|
37
43
|
contextMessage = contextMessage + "\nWhat actions would you like to allow?"
|
|
38
44
|
}
|
|
@@ -48,9 +54,11 @@ node main() {
|
|
|
48
54
|
|
|
49
55
|
thread {
|
|
50
56
|
system(systemPrompt)
|
|
51
|
-
let step: NextStep = llm(
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
let step: NextStep = llm(
|
|
58
|
+
"""
|
|
59
|
+
${conversationHistory}\n\nCurrent policy: ${printJSON(policy)}\n\nDecide the next step. If the user is describing what they want, build or update the policy and use showPolicy. If the user approves the shown policy, use writePolicy. If you need clarification, use askQuestion.
|
|
60
|
+
""",
|
|
61
|
+
)
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
if (step.type == "showPolicy") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
|
|
1
|
+
import { print, printJSON, parseJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
|
|
2
2
|
import { exec } from "agency-lang/stdlib/shell.js";
|
|
3
3
|
import { args } from "agency-lang/stdlib/system.js";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
@@ -44,7 +44,9 @@ const __globalCtx = new RuntimeContext({
|
|
|
44
44
|
host: "https://statelog.adit.io",
|
|
45
45
|
apiKey: __process.env["STATELOG_API_KEY"] || "",
|
|
46
46
|
projectId: "agency-lang",
|
|
47
|
-
debugMode: false
|
|
47
|
+
debugMode: false,
|
|
48
|
+
observability: true,
|
|
49
|
+
logFile: "statelog.log"
|
|
48
50
|
},
|
|
49
51
|
smoltalkDefaults: {
|
|
50
52
|
openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
|
|
@@ -59,9 +61,13 @@ const __globalCtx = new RuntimeContext({
|
|
|
59
61
|
}
|
|
60
62
|
},
|
|
61
63
|
dirname: __dirname,
|
|
64
|
+
logLevel: "info",
|
|
62
65
|
traceConfig: {
|
|
63
66
|
program: "dist/lib/agents/review/agent.agency",
|
|
64
67
|
traceDir: "traces"
|
|
68
|
+
},
|
|
69
|
+
memory: {
|
|
70
|
+
dir: ".agency-memory"
|
|
65
71
|
}
|
|
66
72
|
});
|
|
67
73
|
const graph = __globalCtx.graph;
|
|
@@ -82,8 +88,8 @@ const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __global
|
|
|
82
88
|
const __setDebugger = (dbg) => {
|
|
83
89
|
__globalCtx.debuggerState = dbg;
|
|
84
90
|
};
|
|
85
|
-
const
|
|
86
|
-
__globalCtx.
|
|
91
|
+
const __setTraceFile = (filePath) => {
|
|
92
|
+
__globalCtx.traceConfig.traceFile = filePath;
|
|
87
93
|
};
|
|
88
94
|
const __setLLMClient = (client) => {
|
|
89
95
|
__globalCtx.setLLMClient(client);
|
|
@@ -116,6 +122,7 @@ function registerTools(tools) {
|
|
|
116
122
|
}
|
|
117
123
|
__registerTool(print);
|
|
118
124
|
__registerTool(printJSON);
|
|
125
|
+
__registerTool(parseJSON);
|
|
119
126
|
__registerTool(input);
|
|
120
127
|
__registerTool(sleep);
|
|
121
128
|
__registerTool(round);
|
|
@@ -752,7 +759,7 @@ export {
|
|
|
752
759
|
__mainNodeParams,
|
|
753
760
|
__setDebugger,
|
|
754
761
|
__setLLMClient,
|
|
755
|
-
|
|
762
|
+
__setTraceFile,
|
|
756
763
|
__sourceMap,
|
|
757
764
|
__toolRegistry,
|
|
758
765
|
approve,
|
|
@@ -20,6 +20,7 @@ import { Keyword } from "../types/keyword.js";
|
|
|
20
20
|
import { HandleBlock } from "../types/handleBlock.js";
|
|
21
21
|
import { Tag } from "../types/tag.js";
|
|
22
22
|
import { ClassDefinition, NewExpression } from "../types/classDefinition.js";
|
|
23
|
+
import { BindingPattern, MatchPattern } from "../types/pattern.js";
|
|
23
24
|
export declare class AgencyGenerator {
|
|
24
25
|
protected graphNodes: GraphNodeDefinition[];
|
|
25
26
|
protected generatedStatements: string[];
|
|
@@ -70,6 +71,15 @@ export declare class AgencyGenerator {
|
|
|
70
71
|
protected aliasedTypeToString(aliasedType: VariableType): string;
|
|
71
72
|
protected processTypeAlias(node: TypeAlias): string;
|
|
72
73
|
protected processAssignment(node: Assignment): string;
|
|
74
|
+
/**
|
|
75
|
+
* Format a pattern AST node back into Agency pattern syntax. Used by the
|
|
76
|
+
* formatter (it sees the un-lowered AST). Handles binding patterns and
|
|
77
|
+
* match patterns; for match patterns, literal sub-nodes are formatted via
|
|
78
|
+
* the existing literal/expression code paths.
|
|
79
|
+
*/
|
|
80
|
+
protected formatPattern(pattern: BindingPattern | MatchPattern): string;
|
|
81
|
+
private formatObjectPattern;
|
|
82
|
+
private formatArrayPattern;
|
|
73
83
|
protected generateLiteral(literal: Literal): string;
|
|
74
84
|
private generateStringLiteral;
|
|
75
85
|
private generateMultiLineStringLiteral;
|
|
@@ -3,7 +3,6 @@ import { formatUnitLiteral, } from "../types.js";
|
|
|
3
3
|
import { variableTypeToString } from "./typescriptGenerator/typeToString.js";
|
|
4
4
|
import { mergeDeep } from "../utils.js";
|
|
5
5
|
import { PRECEDENCE, } from "../types/binop.js";
|
|
6
|
-
import { expressionToString } from "../utils/node.js";
|
|
7
6
|
export class AgencyGenerator {
|
|
8
7
|
graphNodes = [];
|
|
9
8
|
generatedStatements = [];
|
|
@@ -198,11 +197,18 @@ export class AgencyGenerator {
|
|
|
198
197
|
case "newExpression":
|
|
199
198
|
return this.processNewExpression(node);
|
|
200
199
|
case "schemaExpression":
|
|
201
|
-
return `schema(${variableTypeToString(node.typeArg, this.typeAliases)})`;
|
|
200
|
+
return `schema(${variableTypeToString(node.typeArg, this.typeAliases, true)})`;
|
|
202
201
|
case "regex":
|
|
203
202
|
return `re/${node.pattern}/${node.flags}`;
|
|
204
203
|
case "interruptStatement":
|
|
205
204
|
return this.processInterruptStatement(node);
|
|
205
|
+
case "objectPattern":
|
|
206
|
+
case "arrayPattern":
|
|
207
|
+
case "restPattern":
|
|
208
|
+
case "wildcardPattern":
|
|
209
|
+
return this.formatPattern(node);
|
|
210
|
+
case "isExpression":
|
|
211
|
+
return `${this.processNode(node.expression).trim()} is ${this.formatPattern(node.pattern)}`;
|
|
206
212
|
case "parallelBlock":
|
|
207
213
|
return this.processParallelBlock(node);
|
|
208
214
|
case "seqBlock":
|
|
@@ -276,7 +282,7 @@ export class AgencyGenerator {
|
|
|
276
282
|
? ` = ${this.processNode(p.defaultValue).trim()}`
|
|
277
283
|
: "";
|
|
278
284
|
if (p.typeHint) {
|
|
279
|
-
const typeStr = variableTypeToString(p.typeHint, this.typeAliases);
|
|
285
|
+
const typeStr = variableTypeToString(p.typeHint, this.typeAliases, true);
|
|
280
286
|
const bang = p.validated ? "!" : "";
|
|
281
287
|
return `${prefix}${p.name}: ${typeStr}${bang}${defaultSuffix}`;
|
|
282
288
|
}
|
|
@@ -294,13 +300,13 @@ export class AgencyGenerator {
|
|
|
294
300
|
const unionWithoutUndefined = nonUndefinedTypes.length === 1
|
|
295
301
|
? nonUndefinedTypes[0]
|
|
296
302
|
: { type: "unionType", types: nonUndefinedTypes };
|
|
297
|
-
let str = `${prop.key}?: ${variableTypeToString(unionWithoutUndefined, this.typeAliases)}`;
|
|
303
|
+
let str = `${prop.key}?: ${variableTypeToString(unionWithoutUndefined, this.typeAliases, true)}`;
|
|
298
304
|
if (prop.description) {
|
|
299
305
|
str += ` # ${prop.description}`;
|
|
300
306
|
}
|
|
301
307
|
return str;
|
|
302
308
|
}
|
|
303
|
-
let str = `${prop.key}: ${variableTypeToString(prop.value, this.typeAliases)}`;
|
|
309
|
+
let str = `${prop.key}: ${variableTypeToString(prop.value, this.typeAliases, true)}`;
|
|
304
310
|
if (prop.description) {
|
|
305
311
|
str += ` # ${prop.description}`;
|
|
306
312
|
}
|
|
@@ -320,7 +326,7 @@ export class AgencyGenerator {
|
|
|
320
326
|
result += this.indentStr("}");
|
|
321
327
|
return result;
|
|
322
328
|
}
|
|
323
|
-
return variableTypeToString(aliasedType, this.typeAliases);
|
|
329
|
+
return variableTypeToString(aliasedType, this.typeAliases, true);
|
|
324
330
|
}
|
|
325
331
|
processTypeAlias(node) {
|
|
326
332
|
this.typeAliases[node.aliasName] = node.aliasedType;
|
|
@@ -336,9 +342,12 @@ export class AgencyGenerator {
|
|
|
336
342
|
?.map((ce) => this.processAccessChainElement(ce))
|
|
337
343
|
.join("") ?? "";
|
|
338
344
|
const bangSuffix = node.validated ? "!" : "";
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
345
|
+
// Destructuring pattern takes precedence over the bare variableName.
|
|
346
|
+
const lhs = node.pattern
|
|
347
|
+
? this.formatPattern(node.pattern)
|
|
348
|
+
: node.typeHint
|
|
349
|
+
? `${node.variableName}${chainStr}: ${variableTypeToString(node.typeHint, this.typeAliases, true)}${bangSuffix}`
|
|
350
|
+
: `${node.variableName}${chainStr}`;
|
|
342
351
|
const exportPrefix = node.exported ? "export " : "";
|
|
343
352
|
const staticPrefix = node.static ? "static " : "";
|
|
344
353
|
const declPrefix = node.declKind ? `${node.declKind} ` : "";
|
|
@@ -346,7 +355,49 @@ export class AgencyGenerator {
|
|
|
346
355
|
? this.processBinOpExpression(node.value, true).trim()
|
|
347
356
|
: this.processNode(node.value).trim();
|
|
348
357
|
return (tags +
|
|
349
|
-
this.indentStr(`${exportPrefix}${staticPrefix}${declPrefix}${
|
|
358
|
+
this.indentStr(`${exportPrefix}${staticPrefix}${declPrefix}${lhs} = ${valueCode}`));
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Format a pattern AST node back into Agency pattern syntax. Used by the
|
|
362
|
+
* formatter (it sees the un-lowered AST). Handles binding patterns and
|
|
363
|
+
* match patterns; for match patterns, literal sub-nodes are formatted via
|
|
364
|
+
* the existing literal/expression code paths.
|
|
365
|
+
*/
|
|
366
|
+
formatPattern(pattern) {
|
|
367
|
+
switch (pattern.type) {
|
|
368
|
+
case "objectPattern":
|
|
369
|
+
return this.formatObjectPattern(pattern);
|
|
370
|
+
case "arrayPattern":
|
|
371
|
+
return this.formatArrayPattern(pattern);
|
|
372
|
+
case "restPattern":
|
|
373
|
+
return `...${pattern.identifier}`;
|
|
374
|
+
case "wildcardPattern":
|
|
375
|
+
return "_";
|
|
376
|
+
default:
|
|
377
|
+
// variableName / literals — defer to existing rendering
|
|
378
|
+
return this.processNode(pattern).trim();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
formatObjectPattern(node) {
|
|
382
|
+
const parts = node.properties.map((p) => {
|
|
383
|
+
if (p.type === "objectPatternShorthand") {
|
|
384
|
+
return p.name;
|
|
385
|
+
}
|
|
386
|
+
if (p.type === "restPattern") {
|
|
387
|
+
return `...${p.identifier}`;
|
|
388
|
+
}
|
|
389
|
+
const prop = p;
|
|
390
|
+
// If the value is just `variableName` matching the key, emit shorthand.
|
|
391
|
+
if (prop.value.type === "variableName" && prop.value.value === prop.key) {
|
|
392
|
+
return prop.key;
|
|
393
|
+
}
|
|
394
|
+
return `${prop.key}: ${this.formatPattern(prop.value)}`;
|
|
395
|
+
});
|
|
396
|
+
return `{ ${parts.join(", ")} }`;
|
|
397
|
+
}
|
|
398
|
+
formatArrayPattern(node) {
|
|
399
|
+
const parts = node.elements.map((el) => this.formatPattern(el));
|
|
400
|
+
return `[${parts.join(", ")}]`;
|
|
350
401
|
}
|
|
351
402
|
generateLiteral(literal) {
|
|
352
403
|
switch (literal.type) {
|
|
@@ -375,7 +426,9 @@ export class AgencyGenerator {
|
|
|
375
426
|
result += segment.value;
|
|
376
427
|
}
|
|
377
428
|
else if (segment.type === "interpolation") {
|
|
378
|
-
|
|
429
|
+
// processNode (not expressionToString) so nested function calls with
|
|
430
|
+
// block arguments and quoted string literals round-trip correctly.
|
|
431
|
+
result += `\${${this.processNode(segment.expression).trim()}}`;
|
|
379
432
|
}
|
|
380
433
|
}
|
|
381
434
|
result += '"';
|
|
@@ -388,7 +441,7 @@ export class AgencyGenerator {
|
|
|
388
441
|
result += segment.value;
|
|
389
442
|
}
|
|
390
443
|
else if (segment.type === "interpolation") {
|
|
391
|
-
result += `\${${
|
|
444
|
+
result += `\${${this.processNode(segment.expression).trim()}}`;
|
|
392
445
|
}
|
|
393
446
|
}
|
|
394
447
|
result += '"""';
|
|
@@ -403,7 +456,7 @@ export class AgencyGenerator {
|
|
|
403
456
|
const { functionName, body, parameters } = node;
|
|
404
457
|
const returnTypeBang = node.returnTypeValidated ? "!" : "";
|
|
405
458
|
const returnTypeStr = node.returnType
|
|
406
|
-
? ": " + variableTypeToString(node.returnType, this.typeAliases) + returnTypeBang
|
|
459
|
+
? ": " + variableTypeToString(node.returnType, this.typeAliases, true) + returnTypeBang
|
|
407
460
|
: "";
|
|
408
461
|
const prefixes = [];
|
|
409
462
|
if (node.exported)
|
|
@@ -559,8 +612,11 @@ export class AgencyGenerator {
|
|
|
559
612
|
const pattern = caseNode.caseValue === "_"
|
|
560
613
|
? "_"
|
|
561
614
|
: this.processNode(caseNode.caseValue).trim();
|
|
615
|
+
const guardCode = caseNode.guard
|
|
616
|
+
? ` if (${this.processNode(caseNode.guard).trim()})`
|
|
617
|
+
: "";
|
|
562
618
|
const bodyCode = this.processNode(caseNode.body).trim();
|
|
563
|
-
result += this.indentStr(`${pattern} => ${bodyCode}\n`);
|
|
619
|
+
result += this.indentStr(`${pattern}${guardCode} => ${bodyCode}\n`);
|
|
564
620
|
}
|
|
565
621
|
this.decreaseIndent();
|
|
566
622
|
result += this.indentStr(`}`);
|
|
@@ -568,9 +624,10 @@ export class AgencyGenerator {
|
|
|
568
624
|
}
|
|
569
625
|
processForLoop(node) {
|
|
570
626
|
const iterableCode = this.processNode(node.iterable).trim();
|
|
571
|
-
const
|
|
572
|
-
?
|
|
573
|
-
: node.itemVar;
|
|
627
|
+
const itemVarStr = typeof node.itemVar === "string"
|
|
628
|
+
? node.itemVar
|
|
629
|
+
: this.formatPattern(node.itemVar);
|
|
630
|
+
const vars = node.indexVar ? `${itemVarStr}, ${node.indexVar}` : itemVarStr;
|
|
574
631
|
let result = this.indentStr(`for (${vars} in ${iterableCode}) {\n`);
|
|
575
632
|
this.increaseIndent();
|
|
576
633
|
result += this.renderBody(node.body);
|
|
@@ -721,7 +778,7 @@ export class AgencyGenerator {
|
|
|
721
778
|
const { nodeName, body, parameters } = node;
|
|
722
779
|
const returnTypeBang = node.returnTypeValidated ? "!" : "";
|
|
723
780
|
const returnTypeStr = node.returnType
|
|
724
|
-
? ": " + variableTypeToString(node.returnType, this.typeAliases) + returnTypeBang
|
|
781
|
+
? ": " + variableTypeToString(node.returnType, this.typeAliases, true) + returnTypeBang
|
|
725
782
|
: "";
|
|
726
783
|
const exportPrefix = node.exported ? "export " : "";
|
|
727
784
|
const prefix = `${exportPrefix}node ${nodeName}`;
|
|
@@ -746,7 +803,7 @@ export class AgencyGenerator {
|
|
|
746
803
|
this.increaseIndent();
|
|
747
804
|
// Fields
|
|
748
805
|
for (const field of node.fields) {
|
|
749
|
-
result += this.indentStr(`${field.name}: ${variableTypeToString(field.typeHint, this.typeAliases)}\n`);
|
|
806
|
+
result += this.indentStr(`${field.name}: ${variableTypeToString(field.typeHint, this.typeAliases, true)}\n`);
|
|
750
807
|
}
|
|
751
808
|
// Methods (constructor is auto-generated, not formatted)
|
|
752
809
|
for (const method of node.methods) {
|
|
@@ -754,12 +811,12 @@ export class AgencyGenerator {
|
|
|
754
811
|
.map((p) => {
|
|
755
812
|
if (p.typeHint) {
|
|
756
813
|
const bang = p.validated ? "!" : "";
|
|
757
|
-
return `${p.name}: ${variableTypeToString(p.typeHint, this.typeAliases)}${bang}`;
|
|
814
|
+
return `${p.name}: ${variableTypeToString(p.typeHint, this.typeAliases, true)}${bang}`;
|
|
758
815
|
}
|
|
759
816
|
return p.name;
|
|
760
817
|
})
|
|
761
818
|
.join(", ");
|
|
762
|
-
const returnTypeStr = `: ${variableTypeToString(method.returnType, this.typeAliases)}`;
|
|
819
|
+
const returnTypeStr = `: ${variableTypeToString(method.returnType, this.typeAliases, true)}`;
|
|
763
820
|
result +=
|
|
764
821
|
"\n" + this.indentStr(`${method.name}(${params})${returnTypeStr} {\n`);
|
|
765
822
|
this.increaseIndent();
|
|
@@ -818,7 +875,7 @@ export class AgencyGenerator {
|
|
|
818
875
|
if (node.handler.kind === "inline") {
|
|
819
876
|
const handlerBang = node.handler.param.validated ? "!" : "";
|
|
820
877
|
const paramStr = node.handler.param.typeHint
|
|
821
|
-
? `${node.handler.param.name}: ${variableTypeToString(node.handler.param.typeHint, this.typeAliases)}${handlerBang}`
|
|
878
|
+
? `${node.handler.param.name}: ${variableTypeToString(node.handler.param.typeHint, this.typeAliases, true)}${handlerBang}`
|
|
822
879
|
: node.handler.param.name;
|
|
823
880
|
this.increaseIndent();
|
|
824
881
|
const handlerBodyStr = this.renderBody(node.handler.body);
|
|
@@ -350,6 +350,64 @@ describe("AgencyGenerator - Result type formatting", () => {
|
|
|
350
350
|
expect(output).not.toContain("Result<number, string>");
|
|
351
351
|
});
|
|
352
352
|
});
|
|
353
|
+
describe("AgencyGenerator - object type formatting", () => {
|
|
354
|
+
function formatAgency(input) {
|
|
355
|
+
const parseResult = parseAgency(input, {}, false);
|
|
356
|
+
expect(parseResult.success).toBe(true);
|
|
357
|
+
if (!parseResult.success)
|
|
358
|
+
return "";
|
|
359
|
+
const generator = new AgencyGenerator();
|
|
360
|
+
return generator.generate(parseResult.result).output.trim();
|
|
361
|
+
}
|
|
362
|
+
it("should format object type as 'object' not 'Record<string, any>'", () => {
|
|
363
|
+
const input = `def process(data: object) {\n print(data)\n}`;
|
|
364
|
+
const output = formatAgency(input);
|
|
365
|
+
expect(output).toContain("data: object");
|
|
366
|
+
expect(output).not.toContain("Record<string, any>");
|
|
367
|
+
});
|
|
368
|
+
it("should format object type in type aliases", () => {
|
|
369
|
+
const input = `type NextStep = { type: "showPolicy"; policy: object }`;
|
|
370
|
+
const output = formatAgency(input);
|
|
371
|
+
expect(output).toContain("policy: object");
|
|
372
|
+
expect(output).not.toContain("Record<string, any>");
|
|
373
|
+
});
|
|
374
|
+
it("should format object type in union type aliases", () => {
|
|
375
|
+
const input = `type NextStep =\n | { type: "showPolicy"; policy: object }\n | { type: "writePolicy"; policy: object }`;
|
|
376
|
+
const output = formatAgency(input);
|
|
377
|
+
expect(output).toContain("policy: object");
|
|
378
|
+
expect(output).not.toContain("Record<string, any>");
|
|
379
|
+
});
|
|
380
|
+
it("should format object type in variable declarations", () => {
|
|
381
|
+
const input = `node main() {\n const x: object = {}\n}`;
|
|
382
|
+
const output = formatAgency(input);
|
|
383
|
+
expect(output).toContain("const x: object");
|
|
384
|
+
expect(output).not.toContain("Record<string, any>");
|
|
385
|
+
});
|
|
386
|
+
it("should format object type in return types", () => {
|
|
387
|
+
const input = `def getData(): object {\n return {}\n}`;
|
|
388
|
+
const output = formatAgency(input);
|
|
389
|
+
expect(output).toContain("): object");
|
|
390
|
+
expect(output).not.toContain("Record<string, any>");
|
|
391
|
+
});
|
|
392
|
+
it("should format object type in node return types", () => {
|
|
393
|
+
const input = `node main(): object {\n return {}\n}`;
|
|
394
|
+
const output = formatAgency(input);
|
|
395
|
+
expect(output).toContain("(): object");
|
|
396
|
+
expect(output).not.toContain("Record<string, any>");
|
|
397
|
+
});
|
|
398
|
+
it("should format object[] array type", () => {
|
|
399
|
+
const input = `def process(items: object[]) {\n print(items)\n}`;
|
|
400
|
+
const output = formatAgency(input);
|
|
401
|
+
expect(output).toContain("items: object[]");
|
|
402
|
+
expect(output).not.toContain("Record<string, any>");
|
|
403
|
+
});
|
|
404
|
+
it("should format object type in schema expressions", () => {
|
|
405
|
+
const input = `node main() {\n const s = schema(object)\n}`;
|
|
406
|
+
const output = formatAgency(input);
|
|
407
|
+
expect(output).toContain("schema(object)");
|
|
408
|
+
expect(output).not.toContain("Record<string, any>");
|
|
409
|
+
});
|
|
410
|
+
});
|
|
353
411
|
describe("AgencyGenerator - schema(Type) expressions", () => {
|
|
354
412
|
function formatAgency(input) {
|
|
355
413
|
const parseResult = parseAgency(input, {}, false);
|
|
@@ -370,3 +428,30 @@ describe("AgencyGenerator - schema(Type) expressions", () => {
|
|
|
370
428
|
expect(output).toContain("schema(Result<number>)");
|
|
371
429
|
});
|
|
372
430
|
});
|
|
431
|
+
describe("AgencyGenerator - string interpolation with nested calls", () => {
|
|
432
|
+
function formatAgency(input) {
|
|
433
|
+
const parseResult = parseAgency(input, {}, false);
|
|
434
|
+
expect(parseResult.success).toBe(true);
|
|
435
|
+
if (!parseResult.success)
|
|
436
|
+
return "";
|
|
437
|
+
const generator = new AgencyGenerator();
|
|
438
|
+
return generator.generate(parseResult.result).output.trim();
|
|
439
|
+
}
|
|
440
|
+
it("preserves inline block arguments inside a string interpolation", () => {
|
|
441
|
+
// The interpolation expression is a function call whose second argument
|
|
442
|
+
// is an inline block (`\k -> ...`). Previously the generator routed
|
|
443
|
+
// through expressionToString, which knows nothing about block args,
|
|
444
|
+
// so the block silently disappeared from the output.
|
|
445
|
+
const input = `node main() {\n let s = "x: " + map(arr, \\k -> k).join(",")\n}`;
|
|
446
|
+
const output = formatAgency(input);
|
|
447
|
+
expect(output).toContain("\\k -> k");
|
|
448
|
+
expect(output).toContain('.join(",")');
|
|
449
|
+
});
|
|
450
|
+
it("preserves quoted string arguments inside a string interpolation", () => {
|
|
451
|
+
// expressionToString rendered string literals without their quotes,
|
|
452
|
+
// so `.join("")` collapsed to `.join()`.
|
|
453
|
+
const input = `node main() {\n let s = "x: " + arr.join("")\n}`;
|
|
454
|
+
const output = formatAgency(input);
|
|
455
|
+
expect(output).toContain('.join("")');
|
|
456
|
+
});
|
|
457
|
+
});
|
|
@@ -5,6 +5,13 @@ import type { CompilationUnit } from "../compilationUnit.js";
|
|
|
5
5
|
export declare class TypeScriptBuilder {
|
|
6
6
|
private generatedStatements;
|
|
7
7
|
private generatedTypeAliases;
|
|
8
|
+
/**
|
|
9
|
+
* TypeAlias AST nodes whose declaration has been hoisted to the
|
|
10
|
+
* containing function/node's outer scope (so it's visible to every
|
|
11
|
+
* runner.step closure). When processNode sees one of these inside a
|
|
12
|
+
* body, it returns ts.empty() to avoid a redeclaration.
|
|
13
|
+
*/
|
|
14
|
+
private hoistedTypeAliasNodes;
|
|
8
15
|
private importStatements;
|
|
9
16
|
private toolRegistrations;
|
|
10
17
|
private functionsUsed;
|
|
@@ -18,6 +25,11 @@ export declare class TypeScriptBuilder {
|
|
|
18
25
|
private insideGlobalInit;
|
|
19
26
|
private _isInSafeFunction;
|
|
20
27
|
private _blockCounter;
|
|
28
|
+
/** Nesting depth of fork/race block bodies currently being generated.
|
|
29
|
+
* Used to detect when a fork is nested inside another fork's block, so
|
|
30
|
+
* the inner block can carry forward the outer block's args (otherwise
|
|
31
|
+
* the inner __bstack only contains the inner iteration variable). */
|
|
32
|
+
private _forkBlockDepth;
|
|
21
33
|
/** Stack of loop subKeys for generating break/continue cleanup code.
|
|
22
34
|
* Pushed when entering a stepped loop, popped when leaving. */
|
|
23
35
|
private _loopContextStack;
|
|
@@ -113,6 +125,30 @@ export declare class TypeScriptBuilder {
|
|
|
113
125
|
*/
|
|
114
126
|
private processNode;
|
|
115
127
|
private processKeyword;
|
|
128
|
+
/**
|
|
129
|
+
* Walk a function/node body and collect every typeAlias declaration
|
|
130
|
+
* that belongs to this body's scope. Used to hoist body-local type
|
|
131
|
+
* aliases up to the enclosing function/node's outer scope so the
|
|
132
|
+
* generated zod schemas are visible to every runner.step closure.
|
|
133
|
+
*
|
|
134
|
+
* Delegates body recursion to `walkNodes` so any new body-bearing
|
|
135
|
+
* AST node (thread, parallelBlock, seqBlock, …) is automatically
|
|
136
|
+
* handled. Aliases nested inside a function/graphNode/class method
|
|
137
|
+
* are skipped — those defs hoist their own aliases when their bodies
|
|
138
|
+
* are built.
|
|
139
|
+
*/
|
|
140
|
+
private collectBodyTypeAliases;
|
|
141
|
+
/**
|
|
142
|
+
* Hoist body-local type aliases. Returns the generated TS declarations
|
|
143
|
+
* (to be inserted at the top of the enclosing function/node body) and
|
|
144
|
+
* marks each AST node so processNode skips its in-body emission.
|
|
145
|
+
*
|
|
146
|
+
* Coalesces duplicates by alias name: if the same name appears in
|
|
147
|
+
* multiple branches/blocks, only the first declaration is emitted to
|
|
148
|
+
* avoid redeclaration errors at the function scope. (The Agency
|
|
149
|
+
* typechecker is responsible for diagnosing genuine name collisions.)
|
|
150
|
+
*/
|
|
151
|
+
private hoistBodyTypeAliases;
|
|
116
152
|
private processTypeAlias;
|
|
117
153
|
private processComment;
|
|
118
154
|
private processAgencyObject;
|
|
@@ -197,6 +233,12 @@ export declare class TypeScriptBuilder {
|
|
|
197
233
|
private processFunctionCall;
|
|
198
234
|
private generateFunctionCallExpression;
|
|
199
235
|
private emitRuntimeDispatchCall;
|
|
236
|
+
/**
|
|
237
|
+
* Emit a plain direct function call: `f(arg1, arg2, blockArg?)`.
|
|
238
|
+
* Context-injected builtins reuse this with `prependArgs =
|
|
239
|
+
* [__ctx]`; the registry lookup at the call site is what marks the
|
|
240
|
+
* intent, no separate method needed.
|
|
241
|
+
*/
|
|
200
242
|
private emitDirectFunctionCall;
|
|
201
243
|
/**
|
|
202
244
|
* Build a CallType descriptor TsNode for an Agency function call.
|
|
@@ -223,6 +265,18 @@ export declare class TypeScriptBuilder {
|
|
|
223
265
|
private processDebuggerStatement;
|
|
224
266
|
private processMessageThread;
|
|
225
267
|
private processBlockPlain;
|
|
268
|
+
/**
|
|
269
|
+
* Compile the synthetic `__objectRest(source, ["a", "b", ...])` call emitted
|
|
270
|
+
* by the pattern lowering pass for `let { a, b, ...rest } = obj` into a
|
|
271
|
+
* native-JS IIFE. No runtime helper required.
|
|
272
|
+
*
|
|
273
|
+
* __objectRest(source, ["a", "b"])
|
|
274
|
+
* → (({ a: __k0, b: __k1, ...__r }) => __r)(<resolved source>)
|
|
275
|
+
*
|
|
276
|
+
* For `let { ...rest } = obj` (no excluded keys), emits
|
|
277
|
+
* (({ ...__r }) => __r)(<resolved source>)
|
|
278
|
+
*/
|
|
279
|
+
private buildObjectRestIIFE;
|
|
226
280
|
private processNodeInGlobalInit;
|
|
227
281
|
private buildHandlerArrow;
|
|
228
282
|
private processHandleBlockWithSteps;
|
|
@@ -258,6 +312,16 @@ export declare class TypeScriptBuilder {
|
|
|
258
312
|
private processBodyAsParts;
|
|
259
313
|
private generateBuiltins;
|
|
260
314
|
private generateImports;
|
|
315
|
+
/**
|
|
316
|
+
* Emit the import statements that bring every context-injected
|
|
317
|
+
* builtin into scope in the generated TS. The set is fixed by
|
|
318
|
+
* `CONTEXT_INJECTED_BUILTINS` at codegen time, so we always import
|
|
319
|
+
* the full list — esbuild tree-shakes anything the call site
|
|
320
|
+
* didn't use. Imports are grouped by each entry's `from` field, so
|
|
321
|
+
* adding a builtin sourced from a different module is a registry
|
|
322
|
+
* change only.
|
|
323
|
+
*/
|
|
324
|
+
private generateContextInjectedImports;
|
|
261
325
|
private preprocess;
|
|
262
326
|
private postprocess;
|
|
263
327
|
}
|