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
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { generateLiterate } from "./literate.js";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
const tmpDir = path.join(process.env.TMPDIR || "/tmp", "agency-literate-test");
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
8
|
+
});
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
11
|
+
});
|
|
12
|
+
function writeInput(name, contents) {
|
|
13
|
+
const inputDir = path.join(tmpDir, "in");
|
|
14
|
+
fs.mkdirSync(inputDir, { recursive: true });
|
|
15
|
+
const inputPath = path.join(inputDir, name);
|
|
16
|
+
fs.writeFileSync(inputPath, contents);
|
|
17
|
+
return inputPath;
|
|
18
|
+
}
|
|
19
|
+
function weaveAndRead(name, contents, opts = {}) {
|
|
20
|
+
const inputPath = writeInput(name, contents);
|
|
21
|
+
const outputDir = path.join(tmpDir, "out");
|
|
22
|
+
generateLiterate({}, inputPath, outputDir, [], opts.lang ?? "agency");
|
|
23
|
+
const outName = name.replace(/\.agency$/, ".md");
|
|
24
|
+
return fs.readFileSync(path.join(outputDir, outName), "utf-8");
|
|
25
|
+
}
|
|
26
|
+
describe("generateLiterate (weave)", () => {
|
|
27
|
+
it("turns a block comment into prose and code into a fence", () => {
|
|
28
|
+
const md = weaveAndRead("test.agency", `/* hello */
|
|
29
|
+
|
|
30
|
+
def foo(): number {
|
|
31
|
+
return 1
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
// prose is plain text
|
|
35
|
+
expect(md).toContain("hello");
|
|
36
|
+
// code goes in an agency fence
|
|
37
|
+
expect(md).toContain("```agency");
|
|
38
|
+
expect(md).toContain("def foo");
|
|
39
|
+
// prose appears BEFORE the fence (positional check)
|
|
40
|
+
const proseIdx = md.indexOf("hello");
|
|
41
|
+
const fenceIdx = md.indexOf("```agency");
|
|
42
|
+
expect(proseIdx).toBeGreaterThanOrEqual(0);
|
|
43
|
+
expect(fenceIdx).toBeGreaterThan(proseIdx);
|
|
44
|
+
// and "hello" must not be inside the fence
|
|
45
|
+
const fenceEndIdx = md.indexOf("```", fenceIdx + 3);
|
|
46
|
+
expect(md.substring(fenceIdx, fenceEndIdx)).not.toContain("hello");
|
|
47
|
+
});
|
|
48
|
+
it("turns a doc comment (/** */) into prose, not into a fence", () => {
|
|
49
|
+
const md = weaveAndRead("test.agency", `/** docs */
|
|
50
|
+
|
|
51
|
+
def foo(): number {
|
|
52
|
+
return 1
|
|
53
|
+
}
|
|
54
|
+
`);
|
|
55
|
+
// The "docs" string must appear outside any fence.
|
|
56
|
+
const fenceIdx = md.indexOf("```agency");
|
|
57
|
+
expect(fenceIdx).toBeGreaterThan(0);
|
|
58
|
+
const fenceEndIdx = md.indexOf("```", fenceIdx + 3);
|
|
59
|
+
const fenceContent = md.substring(fenceIdx, fenceEndIdx + 3);
|
|
60
|
+
expect(fenceContent).not.toContain("docs");
|
|
61
|
+
// And it must appear before the fence as prose.
|
|
62
|
+
const docsIdx = md.indexOf("docs");
|
|
63
|
+
expect(docsIdx).toBeGreaterThanOrEqual(0);
|
|
64
|
+
expect(docsIdx).toBeLessThan(fenceIdx);
|
|
65
|
+
});
|
|
66
|
+
it("module-level doc comment appears once as the first prose paragraph", () => {
|
|
67
|
+
const md = weaveAndRead("test.agency", `/** module docs */
|
|
68
|
+
|
|
69
|
+
def foo(): number {
|
|
70
|
+
return 1
|
|
71
|
+
}
|
|
72
|
+
`);
|
|
73
|
+
// Exactly one occurrence (regression guard against double-emitting from
|
|
74
|
+
// program.docComment AND the multiLineComment node).
|
|
75
|
+
const occurrences = md.split("module docs").length - 1;
|
|
76
|
+
expect(occurrences).toBe(1);
|
|
77
|
+
// And it must be the first thing in the output (no fence before it).
|
|
78
|
+
const firstFenceIdx = md.indexOf("```");
|
|
79
|
+
const docsIdx = md.indexOf("module docs");
|
|
80
|
+
expect(docsIdx).toBeGreaterThanOrEqual(0);
|
|
81
|
+
expect(docsIdx).toBeLessThan(firstFenceIdx);
|
|
82
|
+
});
|
|
83
|
+
it("line comments stay inside the code fence", () => {
|
|
84
|
+
const md = weaveAndRead("test.agency", `def foo(): number {
|
|
85
|
+
// inline comment here
|
|
86
|
+
return 1
|
|
87
|
+
}
|
|
88
|
+
`);
|
|
89
|
+
const fenceIdx = md.indexOf("```agency");
|
|
90
|
+
const fenceEndIdx = md.indexOf("```", fenceIdx + 3);
|
|
91
|
+
const fenceContent = md.substring(fenceIdx, fenceEndIdx + 3);
|
|
92
|
+
expect(fenceContent).toContain("// inline comment here");
|
|
93
|
+
});
|
|
94
|
+
it("adjacent block comments merge with a paragraph break", () => {
|
|
95
|
+
const md = weaveAndRead("test.agency", `/* a */
|
|
96
|
+
|
|
97
|
+
/* b */
|
|
98
|
+
`);
|
|
99
|
+
// No fence at all — only prose.
|
|
100
|
+
expect(md).not.toContain("```");
|
|
101
|
+
// The two prose chunks are joined by "\n\n".
|
|
102
|
+
const aIdx = md.indexOf("a");
|
|
103
|
+
const bIdx = md.indexOf("b");
|
|
104
|
+
expect(aIdx).toBeGreaterThanOrEqual(0);
|
|
105
|
+
expect(bIdx).toBeGreaterThan(aIdx);
|
|
106
|
+
expect(md.substring(aIdx, bIdx + 1)).toContain("\n\n");
|
|
107
|
+
});
|
|
108
|
+
it("--lang flag flows through to the fence language tag", () => {
|
|
109
|
+
const md = weaveAndRead("test.agency", `def foo(): number { return 1 }
|
|
110
|
+
`, { lang: "typescript" });
|
|
111
|
+
expect(md).toContain("```typescript");
|
|
112
|
+
expect(md).not.toContain("```agency");
|
|
113
|
+
});
|
|
114
|
+
it("mirrors the tree for directory input", () => {
|
|
115
|
+
const inputDir = path.join(tmpDir, "src");
|
|
116
|
+
const nestedDir = path.join(inputDir, "nested");
|
|
117
|
+
fs.mkdirSync(nestedDir, { recursive: true });
|
|
118
|
+
fs.writeFileSync(path.join(inputDir, "a.agency"), `def a(): number { return 1 }\n`);
|
|
119
|
+
fs.writeFileSync(path.join(nestedDir, "b.agency"), `def b(): number { return 2 }\n`);
|
|
120
|
+
const outputDir = path.join(tmpDir, "out");
|
|
121
|
+
generateLiterate({}, inputDir, outputDir, [], "agency");
|
|
122
|
+
expect(fs.existsSync(path.join(outputDir, "a.md"))).toBe(true);
|
|
123
|
+
expect(fs.existsSync(path.join(outputDir, "nested", "b.md"))).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
it("produces an empty .md for an empty input file", () => {
|
|
126
|
+
const md = weaveAndRead("empty.agency", "");
|
|
127
|
+
expect(md).toBe("");
|
|
128
|
+
});
|
|
129
|
+
it("escalates the fence delimiter when the code contains triple backticks", () => {
|
|
130
|
+
// Block comment containing ``` ends up as prose, not code — so to
|
|
131
|
+
// exercise escalation through codeFence we need backticks inside a
|
|
132
|
+
// CODE node. A doc-string is the simplest way to get a string with
|
|
133
|
+
// backticks into the code segment.
|
|
134
|
+
const md = weaveAndRead("test.agency", "def foo(): string {\n" +
|
|
135
|
+
' """contains ``` triple backticks"""\n' +
|
|
136
|
+
' return "x"\n' +
|
|
137
|
+
"}\n");
|
|
138
|
+
// The surrounding fence must be at least 4 backticks so the inner
|
|
139
|
+
// ``` doesn't terminate it prematurely.
|
|
140
|
+
expect(md).toMatch(/^````+agency\n/m);
|
|
141
|
+
expect(md).toMatch(/\n````+\n?$/);
|
|
142
|
+
});
|
|
143
|
+
it("escalates the fence delimiter to 5 backticks when content has 4", () => {
|
|
144
|
+
const md = weaveAndRead("test.agency", "def foo(): string {\n" +
|
|
145
|
+
' """contains ```` four backticks"""\n' +
|
|
146
|
+
' return "x"\n' +
|
|
147
|
+
"}\n");
|
|
148
|
+
expect(md).toMatch(/^`````+agency\n/m);
|
|
149
|
+
});
|
|
150
|
+
it("strips JSDoc-style leading `*` from multi-line block comments", () => {
|
|
151
|
+
const md = weaveAndRead("test.agency", `/**
|
|
152
|
+
* Line one
|
|
153
|
+
*
|
|
154
|
+
* Line two
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
def foo(): number { return 1 }
|
|
158
|
+
`);
|
|
159
|
+
// The leading " * " on each line is gone; paragraphs are preserved.
|
|
160
|
+
expect(md).toContain("Line one");
|
|
161
|
+
expect(md).toContain("Line two");
|
|
162
|
+
expect(md).not.toMatch(/^\s*\*\s+Line/m);
|
|
163
|
+
// The two paragraphs are separated by a blank line.
|
|
164
|
+
const oneIdx = md.indexOf("Line one");
|
|
165
|
+
const twoIdx = md.indexOf("Line two");
|
|
166
|
+
expect(md.substring(oneIdx, twoIdx)).toContain("\n\n");
|
|
167
|
+
});
|
|
168
|
+
it("preserves markdown bullets (leading `*` after the JSDoc decoration)", () => {
|
|
169
|
+
const md = weaveAndRead("test.agency", `/**
|
|
170
|
+
* Items:
|
|
171
|
+
* * one
|
|
172
|
+
* * two
|
|
173
|
+
*/
|
|
174
|
+
`);
|
|
175
|
+
// After stripping the JSDoc decoration, the inner "* one" / "* two"
|
|
176
|
+
// markdown bullets remain.
|
|
177
|
+
expect(md).toContain("Items:");
|
|
178
|
+
expect(md).toContain("* one");
|
|
179
|
+
expect(md).toContain("* two");
|
|
180
|
+
});
|
|
181
|
+
it("leaves single-line block comments alone", () => {
|
|
182
|
+
const md = weaveAndRead("test.agency", `/* a * b */\n`);
|
|
183
|
+
// The internal "*" is untouched.
|
|
184
|
+
expect(md).toContain("a * b");
|
|
185
|
+
});
|
|
186
|
+
it("preserves source order of imports (no hoisting, no alphabetical sort)", () => {
|
|
187
|
+
const md = weaveAndRead("test.agency", `import { zebra } from "z"
|
|
188
|
+
import { apple } from "a"
|
|
189
|
+
|
|
190
|
+
def hello(): string {
|
|
191
|
+
return "world"
|
|
192
|
+
}
|
|
193
|
+
`);
|
|
194
|
+
// Without preserveOrder, AgencyGenerator would alphabetize these
|
|
195
|
+
// imports — "apple" would come before "zebra". Pin source order.
|
|
196
|
+
const zebraIdx = md.indexOf("zebra");
|
|
197
|
+
const appleIdx = md.indexOf("apple");
|
|
198
|
+
expect(zebraIdx).toBeGreaterThan(0);
|
|
199
|
+
expect(appleIdx).toBeGreaterThan(0);
|
|
200
|
+
expect(zebraIdx).toBeLessThan(appleIdx);
|
|
201
|
+
});
|
|
202
|
+
it("preserves imports placed mid-file (no hoisting)", () => {
|
|
203
|
+
const md = weaveAndRead("test.agency", `def first(): number { return 1 }
|
|
204
|
+
|
|
205
|
+
import { later } from "wherever"
|
|
206
|
+
|
|
207
|
+
def second(): number { return 2 }
|
|
208
|
+
`);
|
|
209
|
+
// The mid-file import must appear AFTER first() and BEFORE second().
|
|
210
|
+
const firstIdx = md.indexOf("def first");
|
|
211
|
+
const importIdx = md.indexOf("import { later }");
|
|
212
|
+
const secondIdx = md.indexOf("def second");
|
|
213
|
+
expect(firstIdx).toBeGreaterThanOrEqual(0);
|
|
214
|
+
expect(importIdx).toBeGreaterThan(firstIdx);
|
|
215
|
+
expect(secondIdx).toBeGreaterThan(importIdx);
|
|
216
|
+
});
|
|
217
|
+
it("smoke-tests against stdlib/markdown.agency (real-world AST)", () => {
|
|
218
|
+
const repoRoot = path.resolve(__dirname, "..", "..");
|
|
219
|
+
const input = path.join(repoRoot, "stdlib", "markdown.agency");
|
|
220
|
+
// Sanity: only run if the fixture exists in this checkout.
|
|
221
|
+
if (!fs.existsSync(input))
|
|
222
|
+
return;
|
|
223
|
+
const outputDir = path.join(tmpDir, "out");
|
|
224
|
+
generateLiterate({}, input, outputDir, [], "agency");
|
|
225
|
+
const md = fs.readFileSync(path.join(outputDir, "markdown.md"), "utf-8");
|
|
226
|
+
expect(md.length).toBeGreaterThan(0);
|
|
227
|
+
expect(md).toContain("```agency");
|
|
228
|
+
});
|
|
229
|
+
});
|
package/dist/lib/cli/optimize.js
CHANGED
|
@@ -87,7 +87,17 @@ export async function optimize(config, target, opts = {}, io) {
|
|
|
87
87
|
if (nonPromptKeys.length > 0) {
|
|
88
88
|
console.warn(`Warning: @optimize(${nonPromptKeys.join(", ")}) — only prompt optimization is supported in v1. Parameter tuning for ${nonPromptKeys.join(", ")} will be ignored.`);
|
|
89
89
|
}
|
|
90
|
-
const
|
|
90
|
+
const goalArg = goalTag.arguments[0];
|
|
91
|
+
if (!goalArg ||
|
|
92
|
+
goalArg.type !== "string" ||
|
|
93
|
+
goalArg.segments.length !== 1 ||
|
|
94
|
+
goalArg.segments[0].type !== "text") {
|
|
95
|
+
const where = goalArg?.loc
|
|
96
|
+
? ` (line ${goalArg.loc.line}, col ${goalArg.loc.col})`
|
|
97
|
+
: "";
|
|
98
|
+
throw new Error(`@goal(...) requires a single plain string-literal argument${where}; got ${goalArg ? goalArg.type : "no argument"}.`);
|
|
99
|
+
}
|
|
100
|
+
const goal = goalArg.segments[0].value;
|
|
91
101
|
console.log(`Goal: ${goal}`);
|
|
92
102
|
console.log(`Running up to ${options.iterations} iterations...\n`);
|
|
93
103
|
const targetNode = program.nodes.find((n) => n.type === "graphNode" && n.nodeName === nodeName);
|
|
@@ -197,7 +207,18 @@ function collectOptimizeTargets(body, targets) {
|
|
|
197
207
|
}
|
|
198
208
|
const target = { node, llmCall, tag: optimizeTag };
|
|
199
209
|
target.promptValue = getPromptValue(target);
|
|
200
|
-
|
|
210
|
+
if (optimizeTag.arguments.length === 0) {
|
|
211
|
+
target.configKeys = ["prompt"];
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
target.configKeys = optimizeTag.arguments.map((a) => {
|
|
215
|
+
if (a.type !== "variableName") {
|
|
216
|
+
const where = a.loc ? ` (line ${a.loc.line}, col ${a.loc.col})` : "";
|
|
217
|
+
throw new Error(`@optimize(...) arguments must be plain config-key identifiers${where}; got ${a.type}.`);
|
|
218
|
+
}
|
|
219
|
+
return a.value;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
201
222
|
targets.push(target);
|
|
202
223
|
}
|
|
203
224
|
}
|
|
@@ -81,7 +81,12 @@ node main(msg: string): string {
|
|
|
81
81
|
expect(tag).toMatchObject({
|
|
82
82
|
type: "tag",
|
|
83
83
|
name: "goal",
|
|
84
|
-
arguments: [
|
|
84
|
+
arguments: [
|
|
85
|
+
{
|
|
86
|
+
type: "string",
|
|
87
|
+
segments: [{ type: "text", value: "Classify messages accurately" }],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
85
90
|
});
|
|
86
91
|
});
|
|
87
92
|
it("returns null when no @goal tag exists on the node", () => {
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { compile, compiledOutputNodeArgs } from "./commands.js";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
|
+
import * as fs from "fs";
|
|
3
4
|
import * as path from "path";
|
|
4
5
|
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
|
5
6
|
export function runBundledAgent(config, agentName, args = []) {
|
|
6
7
|
const agentDir = path.resolve(currentDir, `../agents/${agentName}`);
|
|
7
8
|
const agencyFile = path.join(agentDir, "agent.agency");
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
9
|
+
const precompiledFile = path.join(agentDir, "agent.js");
|
|
10
|
+
// Prefer the precompiled agent.js produced by `make agents` so users
|
|
11
|
+
// don't pay the compile cost on every invocation. Falls back to a
|
|
12
|
+
// fresh compile if the bundle hasn't been built yet.
|
|
13
|
+
let runFile;
|
|
14
|
+
if (fs.existsSync(precompiledFile)) {
|
|
15
|
+
runFile = precompiledFile;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
runFile = compile(config, agencyFile);
|
|
19
|
+
}
|
|
12
20
|
if (runFile === null) {
|
|
13
21
|
console.error(`Failed to compile agent ${agentName}.`);
|
|
14
22
|
process.exit(1);
|
|
@@ -17,6 +17,7 @@ function cronIntervalMinutes(cron) {
|
|
|
17
17
|
return Number.POSITIVE_INFINITY;
|
|
18
18
|
}
|
|
19
19
|
export async function promptScheduleOverwrite(name) {
|
|
20
|
+
// eslint-disable-next-line no-restricted-syntax -- lazy load to avoid pulling in `prompts` for non-interactive flows
|
|
20
21
|
const prompts = (await import("prompts")).default;
|
|
21
22
|
const { overwrite } = await prompts({
|
|
22
23
|
type: "confirm",
|
package/dist/lib/cli/serve.js
CHANGED
|
@@ -53,6 +53,7 @@ function compileForServe(file) {
|
|
|
53
53
|
}
|
|
54
54
|
async function loadAndDiscover(compileResult) {
|
|
55
55
|
const moduleUrl = pathToFileURL(path.resolve(compileResult.outputPath)).href;
|
|
56
|
+
// eslint-disable-next-line no-restricted-syntax -- compiled module URL is only known at runtime
|
|
56
57
|
const mod = await import(moduleUrl);
|
|
57
58
|
const moduleExports = mod;
|
|
58
59
|
const toolRegistry = moduleExports.__toolRegistry ?? {};
|
package/dist/lib/cli/test.js
CHANGED
|
@@ -117,10 +117,11 @@ function exitIfSignal(e) {
|
|
|
117
117
|
process.exit(1);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
// eslint-disable-next-line max-lines-per-function -- legacy CLI entrypoint slated for incremental refactor
|
|
120
121
|
export async function fixtures(config, target) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const resolved = target ? parseTarget(target) : await promptForTarget();
|
|
123
|
+
const { filename } = resolved;
|
|
124
|
+
let { nodeName } = resolved;
|
|
124
125
|
const contents = readFile(filename);
|
|
125
126
|
const parsed = parseAgency(contents);
|
|
126
127
|
if (!parsed.success) {
|
|
@@ -139,7 +140,7 @@ export async function fixtures(config, target) {
|
|
|
139
140
|
}
|
|
140
141
|
// Find the selected node and prompt for args
|
|
141
142
|
const selectedNode = nodes.find((n) => n.nodeName === nodeName);
|
|
142
|
-
|
|
143
|
+
const { hasArgs, argsString } = await promptForArgs(selectedNode);
|
|
143
144
|
console.log("Running program from entrypoint", nodeName);
|
|
144
145
|
let json = executeNode({
|
|
145
146
|
config,
|
|
@@ -367,6 +368,7 @@ async function runSingleTest(config, testFile, testCase, timeoutMs, signal, log)
|
|
|
367
368
|
timeoutMs,
|
|
368
369
|
signal,
|
|
369
370
|
llmMocks: testCase.llmMocks,
|
|
371
|
+
useTestLLMProvider: testCase.useTestLLMProvider,
|
|
370
372
|
});
|
|
371
373
|
if (result.stdout)
|
|
372
374
|
log(result.stdout.trimEnd());
|
|
@@ -542,7 +544,8 @@ async function runTestFile(config, testFile, suite) {
|
|
|
542
544
|
// the judge itself is an LLM call without a mock. Skip these so CI
|
|
543
545
|
// gets a clear `skipped` rather than a confusing "no mock provided"
|
|
544
546
|
// failure.
|
|
545
|
-
if (process.env.AGENCY_USE_TEST_LLM_PROVIDER
|
|
547
|
+
if ((process.env.AGENCY_USE_TEST_LLM_PROVIDER ||
|
|
548
|
+
testCase.useTestLLMProvider) &&
|
|
546
549
|
testCase.evaluationCriteria.some((c) => c.type === "llmJudge")) {
|
|
547
550
|
log(color.yellow(` ⊘ Skipped (LLM-as-judge requires real client)`));
|
|
548
551
|
skipped++;
|
|
@@ -730,9 +733,19 @@ async function runTsTestDir(config, dir) {
|
|
|
730
733
|
// DeterministicClient. When the file is absent under deterministic
|
|
731
734
|
// mode we still set the env var to "[]" so any llm() call fails
|
|
732
735
|
// cleanly instead of falling through to the real OpenAI client.
|
|
736
|
+
//
|
|
737
|
+
// Activate the deterministic client whenever EITHER:
|
|
738
|
+
// - the suite-wide AGENCY_USE_TEST_LLM_PROVIDER env var is set
|
|
739
|
+
// (typical for PR CI), OR
|
|
740
|
+
// - a `useTestLLMProvider` marker file sits next to test.js
|
|
741
|
+
// (mirrors the per-test flag in .test.json — lets a single
|
|
742
|
+
// agency-js test pin itself to the deterministic provider even
|
|
743
|
+
// on push-to-main CI where the env var is unset).
|
|
733
744
|
const mocksFile = path.join(dir, "llmMocks.json");
|
|
745
|
+
const useDeterministic = !!process.env.AGENCY_USE_TEST_LLM_PROVIDER ||
|
|
746
|
+
fs.existsSync(path.join(dir, "useTestLLMProvider"));
|
|
734
747
|
let mocksEnv = {};
|
|
735
|
-
if (
|
|
748
|
+
if (useDeterministic) {
|
|
736
749
|
const mocks = fs.existsSync(mocksFile)
|
|
737
750
|
? fs.readFileSync(mocksFile, "utf-8")
|
|
738
751
|
: "[]";
|
package/dist/lib/cli/util.d.ts
CHANGED
|
@@ -37,8 +37,9 @@ type ExecuteNodeArgs = {
|
|
|
37
37
|
timeoutMs?: number;
|
|
38
38
|
signal?: AbortSignal;
|
|
39
39
|
llmMocks?: LLMMock[];
|
|
40
|
+
useTestLLMProvider?: boolean;
|
|
40
41
|
};
|
|
41
|
-
export declare function executeNodeAsync({ config, agencyFile, nodeName, hasArgs, argsString, interruptHandlers, timeoutMs, signal, llmMocks, }: ExecuteNodeArgs): Promise<{
|
|
42
|
+
export declare function executeNodeAsync({ config, agencyFile, nodeName, hasArgs, argsString, interruptHandlers, timeoutMs, signal, llmMocks, useTestLLMProvider, }: ExecuteNodeArgs): Promise<{
|
|
42
43
|
data: any;
|
|
43
44
|
stdout: string;
|
|
44
45
|
stderr: string;
|
package/dist/lib/cli/util.js
CHANGED
|
@@ -24,7 +24,7 @@ export function parseTarget(target) {
|
|
|
24
24
|
}
|
|
25
25
|
export async function promptForTarget() {
|
|
26
26
|
let filename = "";
|
|
27
|
-
|
|
27
|
+
const nodeName = "";
|
|
28
28
|
// Find all .agency files in the current directory
|
|
29
29
|
const agencyFiles = fs
|
|
30
30
|
.readdirSync(process.cwd())
|
|
@@ -117,7 +117,7 @@ export function resolveCompiledFile(distDir, agencyFile) {
|
|
|
117
117
|
}
|
|
118
118
|
return compiledPath;
|
|
119
119
|
}
|
|
120
|
-
export async function executeNodeAsync({ config, agencyFile, nodeName, hasArgs, argsString, interruptHandlers, timeoutMs, signal, llmMocks, }) {
|
|
120
|
+
export async function executeNodeAsync({ config, agencyFile, nodeName, hasArgs, argsString, interruptHandlers, timeoutMs, signal, llmMocks, useTestLLMProvider, }) {
|
|
121
121
|
let evaluateFile = "";
|
|
122
122
|
let resultsFile = "";
|
|
123
123
|
try {
|
|
@@ -163,10 +163,18 @@ export async function executeNodeAsync({ config, agencyFile, nodeName, hasArgs,
|
|
|
163
163
|
// Pass mocks to the subprocess as a JSON string in an env var. The
|
|
164
164
|
// compiled module's imports template auto-activates DeterministicClient
|
|
165
165
|
// when AGENCY_LLM_MOCKS is set. No temp file, no cleanup needed.
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
|
|
166
|
+
//
|
|
167
|
+
// Activate the deterministic client whenever EITHER:
|
|
168
|
+
// - the suite-wide AGENCY_USE_TEST_LLM_PROVIDER env var is set
|
|
169
|
+
// (typical for PR CI), OR
|
|
170
|
+
// - the per-test `useTestLLMProvider` flag is true (lets a single
|
|
171
|
+
// test pin itself to the deterministic provider even on
|
|
172
|
+
// push-to-main CI where the env var is unset).
|
|
173
|
+
// Setting the env var to "[]" when no mocks are provided still
|
|
174
|
+
// activates the deterministic client so any llm() call fails cleanly
|
|
175
|
+
// instead of falling through to the real OpenAI client.
|
|
176
|
+
const useDeterministic = !!process.env.AGENCY_USE_TEST_LLM_PROVIDER || !!useTestLLMProvider;
|
|
177
|
+
const mocksEnv = useDeterministic
|
|
170
178
|
? { AGENCY_LLM_MOCKS: JSON.stringify(llmMocks ?? []) }
|
|
171
179
|
: {};
|
|
172
180
|
const { stdout, stderr } = await execFileAsync("node", [evaluateFile], {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgencyProgram,
|
|
1
|
+
import type { AgencyProgram, FunctionDefinition, FunctionParameter, GraphNodeDefinition, Scope, Tag, TypeAliasEntry, TypeParam, ValueParam, VariableType } from "./types.js";
|
|
2
2
|
import type { ImportNodeStatement, ImportStatement } from "./types/importStatement.js";
|
|
3
3
|
import type { SymbolTable, InterruptKind } from "./symbolTable.js";
|
|
4
4
|
export declare const GLOBAL_SCOPE_KEY = "global";
|
|
@@ -9,13 +9,13 @@ export declare const GLOBAL_SCOPE_KEY = "global";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class ScopedTypeAliases {
|
|
11
11
|
private readonly byScope;
|
|
12
|
-
constructor(initial?: Record<string, Record<string,
|
|
13
|
-
add(scopeKey: string, name: string,
|
|
14
|
-
get(scopeKey: string): Record<string,
|
|
12
|
+
constructor(initial?: Record<string, Record<string, TypeAliasEntry>>);
|
|
13
|
+
add(scopeKey: string, name: string, body: VariableType, typeParams?: TypeParam[], tags?: Tag[], valueParams?: ValueParam[]): void;
|
|
14
|
+
get(scopeKey: string): Record<string, TypeAliasEntry> | undefined;
|
|
15
15
|
/** Flat map of every alias visible in `scopeKey`; scope-local wins. */
|
|
16
|
-
visibleIn(scopeKey: string): Record<string,
|
|
16
|
+
visibleIn(scopeKey: string): Record<string, TypeAliasEntry>;
|
|
17
17
|
/** Iterate over every (scopeKey, aliases-in-that-scope) pair. */
|
|
18
|
-
scopes(): [string, Record<string,
|
|
18
|
+
scopes(): [string, Record<string, TypeAliasEntry>][];
|
|
19
19
|
clone(): ScopedTypeAliases;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
@@ -54,7 +54,6 @@ export type CompilationUnit = {
|
|
|
54
54
|
* variable diagnostics quiet without pretending we know their types.
|
|
55
55
|
*/
|
|
56
56
|
jsImportedNames: Record<string, true>;
|
|
57
|
-
classDefinitions: Record<string, ClassDefinition>;
|
|
58
57
|
/** Original source text. Used by the typechecker to locate
|
|
59
58
|
* `// @tc-nocheck` / `// @tc-ignore` directives. Optional because
|
|
60
59
|
* many callers (including most tests) construct the AST directly. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getImportedNames } from "./types/importStatement.js";
|
|
2
|
+
import { collectTypeAliasTags } from "./symbolTable.js";
|
|
2
3
|
import { walkNodes } from "./utils/node.js";
|
|
3
4
|
import { resultTypeForValidation } from "./typeChecker/validation.js";
|
|
4
5
|
import { visitTypes } from "./typeChecker/typeWalker.js";
|
|
@@ -18,10 +19,17 @@ export class ScopedTypeAliases {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
|
-
add(scopeKey, name,
|
|
22
|
+
add(scopeKey, name, body, typeParams, tags, valueParams) {
|
|
22
23
|
if (!this.byScope[scopeKey])
|
|
23
24
|
this.byScope[scopeKey] = {};
|
|
24
|
-
|
|
25
|
+
const entry = { body };
|
|
26
|
+
if (typeParams)
|
|
27
|
+
entry.typeParams = typeParams;
|
|
28
|
+
if (valueParams)
|
|
29
|
+
entry.valueParams = valueParams;
|
|
30
|
+
if (tags && tags.length > 0)
|
|
31
|
+
entry.tags = tags;
|
|
32
|
+
this.byScope[scopeKey][name] = entry;
|
|
25
33
|
}
|
|
26
34
|
get(scopeKey) {
|
|
27
35
|
return this.byScope[scopeKey];
|
|
@@ -65,7 +73,6 @@ export function buildCompilationUnit(program, symbolTable, fromFile, sourceText)
|
|
|
65
73
|
importStatements: [],
|
|
66
74
|
importedFunctions: {},
|
|
67
75
|
jsImportedNames: {},
|
|
68
|
-
classDefinitions: {},
|
|
69
76
|
safeFunctions: {},
|
|
70
77
|
sourceText,
|
|
71
78
|
};
|
|
@@ -83,14 +90,6 @@ export function buildCompilationUnit(program, symbolTable, fromFile, sourceText)
|
|
|
83
90
|
case "importNodeStatement":
|
|
84
91
|
unit.importedNodes.push(node);
|
|
85
92
|
break;
|
|
86
|
-
case "classDefinition":
|
|
87
|
-
unit.classDefinitions[node.className] = node;
|
|
88
|
-
for (const method of node.methods) {
|
|
89
|
-
if (method.safe) {
|
|
90
|
-
unit.safeFunctions[`${node.className}.${method.name}`] = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
break;
|
|
94
93
|
case "importStatement":
|
|
95
94
|
unit.importStatements.push(node);
|
|
96
95
|
for (const nameType of node.importedNames) {
|
|
@@ -116,11 +115,18 @@ export function buildCompilationUnit(program, symbolTable, fromFile, sourceText)
|
|
|
116
115
|
break;
|
|
117
116
|
}
|
|
118
117
|
}
|
|
118
|
+
// Tags on local typeAlias nodes are only attached after the preprocessor
|
|
119
|
+
// runs (which happens AFTER buildCompilationUnit). Pre-collect them here
|
|
120
|
+
// so cross-module annotation propagation works in the first pass.
|
|
121
|
+
const localAliasTags = collectTypeAliasTags(program);
|
|
119
122
|
// Deep walk: collect every type alias keyed by its enclosing scope.
|
|
120
123
|
for (const { node, scopes } of walkNodes(program.nodes)) {
|
|
121
124
|
const key = scopeKey(scopes[scopes.length - 1]);
|
|
122
125
|
if (node.type === "typeAlias") {
|
|
123
|
-
|
|
126
|
+
const tags = node.tags && node.tags.length > 0
|
|
127
|
+
? node.tags
|
|
128
|
+
: localAliasTags[node.aliasName];
|
|
129
|
+
unit.typeAliases.add(key, node.aliasName, node.aliasedType, node.typeParams, tags, node.valueParams);
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
// Stitch in cross-file information from imports. Entries are only added
|
|
@@ -147,6 +153,7 @@ export function buildCompilationUnit(program, symbolTable, fromFile, sourceText)
|
|
|
147
153
|
originFile: r.file,
|
|
148
154
|
};
|
|
149
155
|
for (const p of r.symbol.parameters) {
|
|
156
|
+
// eslint-disable-next-line max-depth -- collecting alias seeds from imported function params
|
|
150
157
|
if (p.typeHint)
|
|
151
158
|
aliasSeeds.push({ type: p.typeHint, preferFile: r.file });
|
|
152
159
|
}
|
|
@@ -157,7 +164,7 @@ export function buildCompilationUnit(program, symbolTable, fromFile, sourceText)
|
|
|
157
164
|
unit.safeFunctions[r.localName] = true;
|
|
158
165
|
}
|
|
159
166
|
if (r.symbol.kind === "type") {
|
|
160
|
-
unit.typeAliases.add(GLOBAL_SCOPE_KEY, r.localName, r.symbol.aliasedType);
|
|
167
|
+
unit.typeAliases.add(GLOBAL_SCOPE_KEY, r.localName, r.symbol.aliasedType, r.symbol.typeParams, r.symbol.tags, r.symbol.valueParams);
|
|
161
168
|
// Imported type's body may reference other aliases from its
|
|
162
169
|
// module — pull those transitively too.
|
|
163
170
|
aliasSeeds.push({ type: r.symbol.aliasedType, preferFile: r.file });
|
|
@@ -224,7 +231,7 @@ function pullTransitiveAliases(unit, symbolTable, seeds) {
|
|
|
224
231
|
const found = resolveTypeFromFile(symbolTable, name, preferFile);
|
|
225
232
|
if (!found)
|
|
226
233
|
continue;
|
|
227
|
-
unit.typeAliases.add(GLOBAL_SCOPE_KEY, name, found.aliasedType);
|
|
234
|
+
unit.typeAliases.add(GLOBAL_SCOPE_KEY, name, found.aliasedType, found.typeParams, found.tags, found.valueParams);
|
|
228
235
|
// Nested aliases referenced by this type should resolve in the file
|
|
229
236
|
// the type was actually found in (not the original preferFile) — the
|
|
230
237
|
// body's references are scoped to that module.
|
|
@@ -245,13 +252,25 @@ function resolveTypeFromFile(symbolTable, name, preferFile) {
|
|
|
245
252
|
if (preferFile) {
|
|
246
253
|
const fileSym = symbolTable.getFile(preferFile)?.[name];
|
|
247
254
|
if (fileSym?.kind === "type") {
|
|
248
|
-
return {
|
|
255
|
+
return {
|
|
256
|
+
aliasedType: fileSym.aliasedType,
|
|
257
|
+
typeParams: fileSym.typeParams,
|
|
258
|
+
valueParams: fileSym.valueParams,
|
|
259
|
+
tags: fileSym.tags,
|
|
260
|
+
file: preferFile,
|
|
261
|
+
};
|
|
249
262
|
}
|
|
250
263
|
}
|
|
251
264
|
for (const file of symbolTable.filePaths()) {
|
|
252
265
|
const sym = symbolTable.getFile(file)?.[name];
|
|
253
266
|
if (sym?.kind === "type") {
|
|
254
|
-
return {
|
|
267
|
+
return {
|
|
268
|
+
aliasedType: sym.aliasedType,
|
|
269
|
+
typeParams: sym.typeParams,
|
|
270
|
+
valueParams: sym.valueParams,
|
|
271
|
+
tags: sym.tags,
|
|
272
|
+
file,
|
|
273
|
+
};
|
|
255
274
|
}
|
|
256
275
|
}
|
|
257
276
|
return undefined;
|
|
@@ -30,7 +30,7 @@ describe("buildCompilationUnit", () => {
|
|
|
30
30
|
};
|
|
31
31
|
const info = buildCompilationUnit(program);
|
|
32
32
|
expect(info.typeAliases.get(GLOBAL_SCOPE_KEY)).toEqual({
|
|
33
|
-
Name: { type: "primitiveType", value: "string" },
|
|
33
|
+
Name: { body: { type: "primitiveType", value: "string" } },
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
it("collects type aliases inside a graph node body", () => {
|
|
@@ -53,7 +53,7 @@ describe("buildCompilationUnit", () => {
|
|
|
53
53
|
};
|
|
54
54
|
const info = buildCompilationUnit(program);
|
|
55
55
|
expect(info.typeAliases.get("node:start")).toEqual({
|
|
56
|
-
LocalType: { type: "primitiveType", value: "number" },
|
|
56
|
+
LocalType: { body: { type: "primitiveType", value: "number" } },
|
|
57
57
|
});
|
|
58
58
|
expect(info.typeAliases.get(GLOBAL_SCOPE_KEY)?.["LocalType"]).toBeUndefined();
|
|
59
59
|
});
|
|
@@ -83,7 +83,7 @@ describe("buildCompilationUnit", () => {
|
|
|
83
83
|
const info = buildCompilationUnit(program);
|
|
84
84
|
const visible = info.typeAliases.visibleIn("function:fn");
|
|
85
85
|
// Function-scoped T overrides global T
|
|
86
|
-
expect(visible["T"]).toEqual({ type: "primitiveType", value: "number" });
|
|
86
|
+
expect(visible["T"]).toEqual({ body: { type: "primitiveType", value: "number" } });
|
|
87
87
|
});
|
|
88
88
|
it("collects graph nodes", () => {
|
|
89
89
|
const program = {
|
|
@@ -171,36 +171,4 @@ describe("buildCompilationUnit", () => {
|
|
|
171
171
|
const info = buildCompilationUnit(program);
|
|
172
172
|
expect(info.functionDefinitions["test"]).toBe(funcNode);
|
|
173
173
|
});
|
|
174
|
-
it("registers safe class methods in safeFunctions", () => {
|
|
175
|
-
const program = {
|
|
176
|
-
type: "agencyProgram",
|
|
177
|
-
nodes: [
|
|
178
|
-
{
|
|
179
|
-
type: "classDefinition",
|
|
180
|
-
className: "Math",
|
|
181
|
-
fields: [{ type: "classField", name: "x", typeHint: { type: "primitiveType", value: "number" } }],
|
|
182
|
-
methods: [
|
|
183
|
-
{
|
|
184
|
-
type: "classMethod",
|
|
185
|
-
name: "add",
|
|
186
|
-
parameters: [],
|
|
187
|
-
body: [],
|
|
188
|
-
returnType: { type: "primitiveType", value: "number" },
|
|
189
|
-
safe: true,
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
type: "classMethod",
|
|
193
|
-
name: "save",
|
|
194
|
-
parameters: [],
|
|
195
|
-
body: [],
|
|
196
|
-
returnType: { type: "primitiveType", value: "number" },
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
};
|
|
202
|
-
const info = buildCompilationUnit(program);
|
|
203
|
-
expect(info.safeFunctions["Math.add"]).toBe(true);
|
|
204
|
-
expect(info.safeFunctions["Math.save"]).toBeUndefined();
|
|
205
|
-
});
|
|
206
174
|
});
|