agency-lang 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/agents/agency-agent/agent.agency +3 -2
- package/dist/lib/agents/judge.js +67 -70
- package/dist/lib/agents/policy/agent.agency +153 -53
- 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 +394 -446
- package/dist/lib/backends/agencyGenerator.d.ts +45 -2
- package/dist/lib/backends/agencyGenerator.js +249 -62
- package/dist/lib/backends/agencyGenerator.test.js +106 -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 +51 -0
- package/dist/lib/backends/typescriptBuilder/nameClassifier.js +130 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.d.ts +28 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.js +92 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.d.ts +1 -0
- package/dist/lib/backends/typescriptBuilder/namedArgsResolver.test.js +75 -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 +108 -0
- package/dist/lib/backends/typescriptBuilder/sectionAssembler.js +249 -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.d.ts +37 -114
- package/dist/lib/backends/typescriptBuilder.integration.test.js +0 -26
- package/dist/lib/backends/typescriptBuilder.js +603 -974
- 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/cli/commands.js +9 -4
- 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/optimize.js +23 -2
- package/dist/lib/cli/optimize.test.js +6 -1
- 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 +36 -42
- package/dist/lib/compiler/compile.test.js +71 -21
- 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 +115 -15
- package/dist/lib/ir/builders.js +166 -54
- package/dist/lib/ir/prettyPrint.js +43 -5
- package/dist/lib/ir/prettyPrint.test.js +35 -1
- package/dist/lib/ir/tsIR.d.ts +25 -1
- 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/objectTypeTags.test.d.ts +1 -0
- package/dist/lib/parsers/objectTypeTags.test.js +69 -0
- package/dist/lib/parsers/parsers.d.ts +50 -7
- package/dist/lib/parsers/parsers.js +302 -121
- package/dist/lib/parsers/pattern.test.js +146 -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 +66 -30
- package/dist/lib/runtime/__tests__/node.test.js +8 -3
- package/dist/lib/runtime/__tests__/testHelpers.js +31 -0
- package/dist/lib/runtime/agency.d.ts +49 -0
- package/dist/lib/runtime/agency.js +204 -0
- package/dist/lib/runtime/agency.test.d.ts +1 -0
- package/dist/lib/runtime/agency.test.js +277 -0
- package/dist/lib/runtime/agencyFunction.d.ts +15 -3
- package/dist/lib/runtime/agencyFunction.js +37 -24
- package/dist/lib/runtime/agencyFunction.test.js +76 -12
- 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 +231 -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 +17 -4
- package/dist/lib/runtime/call.test.js +20 -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/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/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 +49 -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 +18 -1
- package/dist/lib/runtime/index.js +12 -0
- package/dist/lib/runtime/interrupts.d.ts +2 -1
- package/dist/lib/runtime/interrupts.js +34 -6
- package/dist/lib/runtime/ipc.d.ts +1 -2
- package/dist/lib/runtime/ipc.js +6 -3
- package/dist/lib/runtime/memory/manager.js +51 -0
- package/dist/lib/runtime/memory/manager.test.js +173 -0
- package/dist/lib/runtime/node.d.ts +5 -5
- package/dist/lib/runtime/node.js +92 -36
- package/dist/lib/runtime/policy.d.ts +19 -5
- package/dist/lib/runtime/policy.js +9 -12
- package/dist/lib/runtime/prompt.d.ts +8 -5
- package/dist/lib/runtime/prompt.js +436 -309
- 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 +45 -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 +239 -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 +106 -21
- package/dist/lib/runtime/runner.js +361 -304
- package/dist/lib/runtime/runner.test.js +120 -5
- 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 +7 -10
- package/dist/lib/runtime/state/context.js +16 -36
- package/dist/lib/runtime/state/stateStack.d.ts +93 -0
- package/dist/lib/runtime/state/stateStack.js +219 -0
- package/dist/lib/runtime/state/stateStack.test.js +386 -0
- package/dist/lib/runtime/subprocess-bootstrap.js +8 -0
- 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/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 +110 -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 +16 -2
- package/dist/lib/stdlib/builtins.js +75 -8
- package/dist/lib/stdlib/fs.d.ts +2 -2
- package/dist/lib/stdlib/fs.js +14 -26
- package/dist/lib/stdlib/http.d.ts +32 -1
- package/dist/lib/stdlib/http.js +105 -23
- package/dist/lib/stdlib/memory.d.ts +27 -13
- package/dist/lib/stdlib/memory.js +71 -13
- 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 +7 -2
- package/dist/lib/stdlib/resolvePath.d.ts +11 -0
- package/dist/lib/stdlib/resolvePath.js +13 -2
- package/dist/lib/stdlib/shell.d.ts +47 -16
- package/dist/lib/stdlib/shell.js +62 -58
- package/dist/lib/stdlib/skills.d.ts +9 -0
- package/dist/lib/stdlib/skills.js +16 -0
- package/dist/lib/stdlib/speech.d.ts +18 -3
- package/dist/lib/stdlib/speech.js +102 -22
- package/dist/lib/stdlib/system.d.ts +19 -5
- package/dist/lib/stdlib/system.js +51 -12
- package/dist/lib/stdlib/thread.d.ts +45 -0
- package/dist/lib/stdlib/thread.js +120 -0
- package/dist/lib/stdlib/ui.d.ts +7 -0
- package/dist/lib/stdlib/ui.js +45 -6
- package/dist/lib/stdlib/validators.d.ts +12 -0
- package/dist/lib/stdlib/validators.js +77 -0
- 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/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 +9 -1
- package/dist/lib/templates/backends/typescriptGenerator/imports.d.ts +1 -2
- package/dist/lib/templates/backends/typescriptGenerator/imports.js +6 -14
- 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 -1
- package/dist/lib/templates/backends/typescriptGenerator/resultCheckpointSetup.js +1 -1
- package/dist/lib/tui/styleParser.js +1 -0
- package/dist/lib/typeChecker/assignability.d.ts +46 -3
- package/dist/lib/typeChecker/assignability.js +313 -8
- 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 +25 -18
- package/dist/lib/typeChecker/docstringParamInterpolation.test.d.ts +1 -0
- package/dist/lib/typeChecker/docstringParamInterpolation.test.js +70 -0
- 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/index.js +58 -4
- package/dist/lib/typeChecker/interruptAnalysis.d.ts +14 -0
- package/dist/lib/typeChecker/interruptAnalysis.js +74 -0
- 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 +7 -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/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 +1 -4
- 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/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/types/dataStructures.d.ts +6 -0
- package/dist/lib/types/function.d.ts +2 -6
- package/dist/lib/types/graphNode.d.ts +3 -3
- package/dist/lib/types/literals.d.ts +1 -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/tag.d.ts +2 -1
- package/dist/lib/types/typeHints.d.ts +108 -1
- package/dist/lib/types.d.ts +4 -4
- package/dist/lib/types.js +1 -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/node.js +19 -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.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 +1 -0
- package/package.json +1 -1
- package/stdlib/agency.agency +217 -3
- package/stdlib/agency.js +1864 -222
- package/stdlib/agent.js +147 -146
- package/stdlib/array.js +737 -784
- package/stdlib/browser.agency +2 -2
- package/stdlib/browser.js +92 -103
- package/stdlib/calendar.js +425 -436
- package/stdlib/clipboard.js +132 -143
- package/stdlib/date.js +580 -591
- package/stdlib/email.js +289 -300
- package/stdlib/fs.agency +12 -6
- package/stdlib/fs.js +525 -508
- package/stdlib/http.agency +61 -4
- package/stdlib/http.js +451 -98
- package/stdlib/imessage.js +84 -95
- package/stdlib/index.agency +66 -40
- package/stdlib/index.js +944 -1119
- package/stdlib/keyring.js +252 -263
- package/stdlib/math.js +167 -162
- package/stdlib/memory.agency +21 -13
- package/stdlib/memory.js +267 -216
- package/stdlib/oauth.agency +4 -1
- package/stdlib/oauth.js +270 -277
- package/stdlib/object.js +276 -307
- package/stdlib/path.js +273 -284
- package/stdlib/policy.agency +30 -6
- package/stdlib/policy.js +160 -141
- package/stdlib/schemas.agency +37 -0
- package/stdlib/schemas.js +202 -0
- package/stdlib/shell.agency +39 -22
- package/stdlib/shell.js +597 -518
- package/stdlib/skills.agency +18 -0
- package/stdlib/skills.js +276 -0
- package/stdlib/sms.js +90 -101
- package/stdlib/speech.agency +31 -9
- package/stdlib/speech.js +256 -223
- package/stdlib/strategy.js +336 -369
- package/stdlib/syntax.agency +20 -0
- package/stdlib/syntax.js +296 -0
- package/stdlib/system.agency +27 -4
- package/stdlib/system.js +512 -398
- package/stdlib/thread.agency +148 -0
- package/stdlib/thread.js +937 -0
- package/stdlib/types.agency +58 -0
- package/stdlib/types.js +180 -0
- package/stdlib/ui.agency +3 -1
- package/stdlib/ui.js +541 -558
- package/stdlib/validators.agency +150 -0
- package/stdlib/validators.js +1471 -0
- package/stdlib/weather.js +127 -130
- package/stdlib/wikipedia.js +124 -135
- 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
|
@@ -2,6 +2,7 @@ import { addTask, listTasks, markTaskDone } from "./subagents/task.agency"
|
|
|
2
2
|
import { writeToPlan, readPlan } from "./subagents/plan.agency"
|
|
3
3
|
import { writeCode, appendCode, readCode } from "./subagents/code.agency"
|
|
4
4
|
import { syntaxHighlight } from "../../utils/agentUtils.js"
|
|
5
|
+
import { systemMessage } from "std::thread"
|
|
5
6
|
// todo allow this
|
|
6
7
|
// import { Plan } from "./subagents/plan.agency"
|
|
7
8
|
|
|
@@ -124,7 +125,7 @@ node plan(mode, existingCode, existingFilename: string | null) {
|
|
|
124
125
|
"""
|
|
125
126
|
}
|
|
126
127
|
thread {
|
|
127
|
-
|
|
128
|
+
systemMessage("${systemPrompt}\n\n${planPrompt}${modeContext}")
|
|
128
129
|
userMsg = input("What would you like to accomplish today? ")
|
|
129
130
|
nextAction: NextAction = {
|
|
130
131
|
type: "start"
|
|
@@ -176,7 +177,7 @@ node design(plan, mode, existingCode, existingFilename: string | null) {
|
|
|
176
177
|
"""
|
|
177
178
|
}
|
|
178
179
|
thread {
|
|
179
|
-
|
|
180
|
+
systemMessage(designPrompt)
|
|
180
181
|
userMsg = prompt
|
|
181
182
|
nextAction: DesignAction = {
|
|
182
183
|
type: "start"
|
package/dist/lib/agents/judge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { print, printJSON, parseJSON, input, sleep, round,
|
|
1
|
+
import { print, printJSON, parseJSON, input, sleep, round, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit, callback } 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";
|
|
@@ -22,11 +22,12 @@ import {
|
|
|
22
22
|
respondToInterrupts as _respondToInterrupts,
|
|
23
23
|
rewindFrom as _rewindFrom,
|
|
24
24
|
RestoreSignal,
|
|
25
|
+
GuardExceededError,
|
|
25
26
|
failure,
|
|
26
|
-
readSkill as _readSkillRaw,
|
|
27
|
-
readSkillTool as __readSkillTool,
|
|
28
|
-
readSkillToolParams as __readSkillToolParams,
|
|
29
27
|
AgencyFunction as __AgencyFunction,
|
|
28
|
+
__threads,
|
|
29
|
+
getRuntimeContext,
|
|
30
|
+
agencyStore,
|
|
30
31
|
functionRefReviver as __functionRefReviver,
|
|
31
32
|
DeterministicClient as __DeterministicClient
|
|
32
33
|
} from "agency-lang/runtime";
|
|
@@ -60,15 +61,9 @@ const __globalCtx = new RuntimeContext({
|
|
|
60
61
|
traceConfig: {
|
|
61
62
|
program: "dist/lib/agents/judge.agency",
|
|
62
63
|
traceDir: "traces"
|
|
63
|
-
},
|
|
64
|
-
memory: {
|
|
65
|
-
dir: ".agency-memory"
|
|
66
64
|
}
|
|
67
65
|
});
|
|
68
66
|
const graph = __globalCtx.graph;
|
|
69
|
-
function readSkill({ filepath }) {
|
|
70
|
-
return _readSkillRaw({ filepath, dirname: __dirname });
|
|
71
|
-
}
|
|
72
67
|
function approve(value) {
|
|
73
68
|
return { type: "approve", value };
|
|
74
69
|
}
|
|
@@ -78,8 +73,8 @@ function reject(value) {
|
|
|
78
73
|
function propagate() {
|
|
79
74
|
return { type: "propagate" };
|
|
80
75
|
}
|
|
81
|
-
const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata });
|
|
82
|
-
const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata });
|
|
76
|
+
const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
|
|
77
|
+
const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
|
|
83
78
|
const __setDebugger = (dbg) => {
|
|
84
79
|
__globalCtx.debuggerState = dbg;
|
|
85
80
|
};
|
|
@@ -121,8 +116,6 @@ __registerTool(parseJSON);
|
|
|
121
116
|
__registerTool(input);
|
|
122
117
|
__registerTool(sleep);
|
|
123
118
|
__registerTool(round);
|
|
124
|
-
__registerTool(fetch);
|
|
125
|
-
__registerTool(fetchJSON);
|
|
126
119
|
__registerTool(read);
|
|
127
120
|
__registerTool(write);
|
|
128
121
|
__registerTool(readImage);
|
|
@@ -133,51 +126,50 @@ __registerTool(keys);
|
|
|
133
126
|
__registerTool(values);
|
|
134
127
|
__registerTool(entries);
|
|
135
128
|
__registerTool(emit);
|
|
129
|
+
__registerTool(callback);
|
|
136
130
|
async function __initializeGlobals(__ctx) {
|
|
137
131
|
__ctx.globals.markInitialized("dist/lib/agents/judge.agency");
|
|
138
132
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
fn: readSkill,
|
|
143
|
-
params: __readSkillToolParams.map((p) => ({ name: p, hasDefault: false, defaultValue: void 0, variadic: false })),
|
|
144
|
-
toolDefinition: __readSkillTool
|
|
145
|
-
}, __toolRegistry);
|
|
133
|
+
async function __registerTopLevelCallbacks(__ctx) {
|
|
134
|
+
__ctx.topLevelCallbacks = [];
|
|
135
|
+
}
|
|
146
136
|
__functionRefReviver.registry = __toolRegistry;
|
|
147
137
|
const JudgeResult = z.object({ "score": z.number().describe("a score from 0 to 100 where 100 means perfect match"), "reasoning": z.string().describe("brief explanation for the score") });
|
|
148
138
|
graph.node("judge", async (__state) => {
|
|
149
139
|
const __setupData = setupNode({
|
|
150
140
|
state: __state
|
|
151
141
|
});
|
|
152
|
-
const __stateStack = __state.ctx.stateStack;
|
|
153
142
|
const __stack = __setupData.stack;
|
|
154
143
|
const __step = __setupData.step;
|
|
155
144
|
const __self = __setupData.self;
|
|
156
|
-
const
|
|
157
|
-
const __ctx = __state.ctx;
|
|
158
|
-
const statelogClient = __ctx.statelogClient;
|
|
159
|
-
const __graph = __ctx.graph;
|
|
145
|
+
const __ctx = getRuntimeContext().ctx;
|
|
160
146
|
let __forked;
|
|
161
147
|
let __functionCompleted = false;
|
|
162
|
-
|
|
163
|
-
callbacks: __ctx.callbacks,
|
|
164
|
-
name: "onNodeStart",
|
|
165
|
-
data: {
|
|
166
|
-
nodeName: "judge"
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/judge.agency", scopeName: "judge" });
|
|
148
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/judge.agency", scopeName: "judge", threads: __setupData.threads });
|
|
170
149
|
if (!__state.isResume) {
|
|
171
150
|
__stack.args["actualOutput"] = __state.data.actualOutput;
|
|
172
151
|
__stack.args["expectedOutput"] = __state.data.expectedOutput;
|
|
173
152
|
__stack.args["judgePrompt"] = __state.data.judgePrompt;
|
|
174
153
|
}
|
|
175
154
|
try {
|
|
176
|
-
await
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
155
|
+
await agencyStore.run({
|
|
156
|
+
...getRuntimeContext(),
|
|
157
|
+
ctx: __ctx,
|
|
158
|
+
stack: __ctx.stateStack,
|
|
159
|
+
threads: __setupData.threads
|
|
160
|
+
}, async () => {
|
|
161
|
+
await runner.hook(0, async () => {
|
|
162
|
+
await callHook({
|
|
163
|
+
name: "onNodeStart",
|
|
164
|
+
data: {
|
|
165
|
+
nodeName: "judge"
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
await runner.step(1, async (runner2) => {
|
|
170
|
+
__self.__removedTools = __self.__removedTools || [];
|
|
171
|
+
__stack.locals.result = await runPrompt({
|
|
172
|
+
prompt: `You are an evaluation judge. Score how well the actual output matches what was expected.
|
|
181
173
|
|
|
182
174
|
Judge prompt (evaluation criteria): ${__stack.args.judgePrompt}
|
|
183
175
|
|
|
@@ -186,54 +178,58 @@ Expected output: ${__stack.args.expectedOutput}
|
|
|
186
178
|
Actual output: ${__stack.args.actualOutput}
|
|
187
179
|
|
|
188
180
|
Provide a score from 0 to 100 where 100 means perfect match and 0 means completely wrong. Also provide brief reasoning.`,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
181
|
+
messages: __threads().getOrCreateActive(),
|
|
182
|
+
responseFormat: z.object({
|
|
183
|
+
response: JudgeResult
|
|
184
|
+
}),
|
|
185
|
+
clientConfig: {},
|
|
186
|
+
maxToolCallRounds: 10,
|
|
187
|
+
removedTools: __self.__removedTools,
|
|
188
|
+
checkpointInfo: runner2.getCheckpointInfo()
|
|
189
|
+
});
|
|
190
|
+
if (hasInterrupts(__stack.locals.result)) {
|
|
191
|
+
await getRuntimeContext().ctx.pendingPromises.awaitAll();
|
|
192
|
+
runner2.halt({
|
|
193
|
+
messages: __threads(),
|
|
194
|
+
data: __stack.locals.result
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
198
|
});
|
|
199
|
-
|
|
200
|
-
await __ctx.pendingPromises.awaitAll();
|
|
199
|
+
await runner.step(2, async (runner2) => {
|
|
201
200
|
runner2.halt({
|
|
202
|
-
messages: __threads,
|
|
201
|
+
messages: __threads(),
|
|
203
202
|
data: __stack.locals.result
|
|
204
203
|
});
|
|
205
204
|
return;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
await runner.step(1, async (runner2) => {
|
|
209
|
-
runner2.halt({
|
|
210
|
-
messages: __threads,
|
|
211
|
-
data: __stack.locals.result
|
|
212
205
|
});
|
|
213
|
-
return;
|
|
214
206
|
});
|
|
215
207
|
if (runner.halted) return runner.haltResult;
|
|
216
|
-
await
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
208
|
+
await runner.hook(3, async () => {
|
|
209
|
+
await callHook({
|
|
210
|
+
name: "onNodeEnd",
|
|
211
|
+
data: {
|
|
212
|
+
nodeName: "judge",
|
|
213
|
+
data: void 0
|
|
214
|
+
}
|
|
215
|
+
});
|
|
223
216
|
});
|
|
224
217
|
return {
|
|
225
|
-
messages: __threads,
|
|
218
|
+
messages: __threads(),
|
|
226
219
|
data: void 0
|
|
227
220
|
};
|
|
228
221
|
} catch (__error) {
|
|
229
222
|
if (__error instanceof RestoreSignal) {
|
|
230
223
|
throw __error;
|
|
231
224
|
}
|
|
225
|
+
if (__error instanceof GuardExceededError) {
|
|
226
|
+
throw __error;
|
|
227
|
+
}
|
|
232
228
|
console.error(`
|
|
233
229
|
Agent crashed: ${__error.message}`);
|
|
234
230
|
console.error(__error.stack);
|
|
235
231
|
return {
|
|
236
|
-
messages: __threads,
|
|
232
|
+
messages: __threads(),
|
|
237
233
|
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "judge" })
|
|
238
234
|
};
|
|
239
235
|
}
|
|
@@ -249,12 +245,14 @@ async function judge(actualOutput, expectedOutput, judgePrompt, { messages, call
|
|
|
249
245
|
},
|
|
250
246
|
messages,
|
|
251
247
|
callbacks,
|
|
252
|
-
initializeGlobals: __initializeGlobals
|
|
248
|
+
initializeGlobals: __initializeGlobals,
|
|
249
|
+
registerTopLevelCallbacks: __registerTopLevelCallbacks,
|
|
250
|
+
moduleDir: __dirname
|
|
253
251
|
});
|
|
254
252
|
}
|
|
255
253
|
const __judgeNodeParams = ["actualOutput", "expectedOutput", "judgePrompt"];
|
|
256
254
|
var stdin_default = graph;
|
|
257
|
-
const __sourceMap = { "dist/lib/agents/judge.agency:judge": { "
|
|
255
|
+
const __sourceMap = { "dist/lib/agents/judge.agency:judge": { "1": { "line": 6, "col": 2 }, "2": { "line": 16, "col": 2 } } };
|
|
258
256
|
export {
|
|
259
257
|
__getCheckpoints,
|
|
260
258
|
__judgeNodeParams,
|
|
@@ -270,7 +268,6 @@ export {
|
|
|
270
268
|
isDebugger,
|
|
271
269
|
isInterrupt,
|
|
272
270
|
judge,
|
|
273
|
-
readSkill,
|
|
274
271
|
reject,
|
|
275
272
|
respondToInterrupts,
|
|
276
273
|
rewindFrom
|
|
@@ -1,13 +1,102 @@
|
|
|
1
1
|
import { map } from "std::array"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
writePolicyFile,
|
|
4
|
+
Policy,
|
|
5
|
+
InterruptKind,
|
|
6
|
+
InterruptDataKey,
|
|
7
|
+
InterruptDataVal,
|
|
8
|
+
} from "std::policy"
|
|
9
|
+
import { highlight } from "std::syntax"
|
|
3
10
|
import { args } from "std::system"
|
|
11
|
+
import { systemMessage, userMessage, assistantMessage } from "std::thread"
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
callback("onToolCallStart") as data {
|
|
14
|
+
print("Calling ${data.toolName}...")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
callback("onToolCallEnd") as data {
|
|
18
|
+
print("Finished calling ${data.toolName}.")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
systemPrompt = read("system.md", "./prompts") with approve
|
|
22
|
+
|
|
23
|
+
type Question = {
|
|
24
|
+
type: "askQuestion";
|
|
25
|
+
question: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Done = {
|
|
29
|
+
type: "done"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Action = Question | Done
|
|
33
|
+
|
|
34
|
+
type PolicyAction = "approve" | "reject" | "propagate"
|
|
6
35
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
36
|
+
let currentPolicy: Policy = {}
|
|
37
|
+
|
|
38
|
+
def addToPolicy(
|
|
39
|
+
interruptKind: InterruptKind,
|
|
40
|
+
matchArgName: InterruptDataKey,
|
|
41
|
+
matchArgValue: InterruptDataVal,
|
|
42
|
+
action: PolicyAction!,
|
|
43
|
+
): Result<Policy> {
|
|
44
|
+
"""
|
|
45
|
+
Add a rule to the current policy for the given interrupt kind, matching on the specified argument and value, with the specified action.
|
|
46
|
+
Use only "approve", "reject", or "propagate" as the action. DO NOT use "allow" or "deny".
|
|
47
|
+
Returns the current policy after adding the rule.
|
|
48
|
+
"""
|
|
49
|
+
const match = {
|
|
50
|
+
[matchArgName]: matchArgValue
|
|
51
|
+
}
|
|
52
|
+
if (!currentPolicy[interruptKind]) {
|
|
53
|
+
currentPolicy[interruptKind] = []
|
|
54
|
+
}
|
|
55
|
+
currentPolicy[interruptKind].push({
|
|
56
|
+
match: match,
|
|
57
|
+
action: action
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
return success(currentPolicy)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
def getPolicy(): Policy {
|
|
64
|
+
"""
|
|
65
|
+
Get the current policy object.
|
|
66
|
+
"""
|
|
67
|
+
return currentPolicy
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
def setPolicy(newPolicy: Policy): Policy {
|
|
71
|
+
"""
|
|
72
|
+
Replace the current policy with a new policy object. Returns the new policy.
|
|
73
|
+
|
|
74
|
+
@param newPolicy - The new policy object to set as the current policy.
|
|
75
|
+
"""
|
|
76
|
+
currentPolicy = newPolicy
|
|
77
|
+
return currentPolicy
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
def deleteFromPolicy(interruptKind: InterruptKind, index: number): boolean {
|
|
81
|
+
"""
|
|
82
|
+
Delete the rule at the specified index for the given interrupt kind from the current policy.
|
|
83
|
+
Returns true if the rule was successfully deleted, or false if the index was out of bounds.
|
|
84
|
+
"""
|
|
85
|
+
if (currentPolicy[interruptKind] && index < currentPolicy[interruptKind].length) {
|
|
86
|
+
currentPolicy[interruptKind].splice(index, 1)
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def savePolicy(path: string) {
|
|
93
|
+
"""
|
|
94
|
+
Validate and save the current policy to a JSON file.
|
|
95
|
+
|
|
96
|
+
@param path - The file path where the policy should be saved.
|
|
97
|
+
"""
|
|
98
|
+
return writePolicyFile(path, currentPolicy)
|
|
99
|
+
}
|
|
11
100
|
|
|
12
101
|
def get(array: any[], index: number) {
|
|
13
102
|
if (index < array.length) {
|
|
@@ -16,70 +105,81 @@ def get(array: any[], index: number) {
|
|
|
16
105
|
return failure("Index out of bounds: ${index} >= ${array.length}")
|
|
17
106
|
}
|
|
18
107
|
|
|
108
|
+
def highlightJSON(obj: Record<string, any>): string {
|
|
109
|
+
return highlight(JSON.stringify(obj, null, 2), "json")
|
|
110
|
+
}
|
|
111
|
+
|
|
19
112
|
node main() {
|
|
20
113
|
const cliArgs = args()
|
|
21
114
|
if (cliArgs.length < 2) {
|
|
22
115
|
print("Usage: agency policy gen <file>")
|
|
23
|
-
return
|
|
116
|
+
return
|
|
24
117
|
}
|
|
25
|
-
print(cliArgs)
|
|
26
118
|
|
|
27
119
|
const interruptKinds = cliArgs[0] |> parseJSON
|
|
28
120
|
const outputPath = cliArgs[1]
|
|
29
|
-
const existingPolicy = get(cliArgs,
|
|
121
|
+
const existingPolicy = get(cliArgs, 2) |> parseJSON
|
|
30
122
|
|
|
31
|
-
if (
|
|
32
|
-
print("Failed to parse interrupt kinds: ${
|
|
33
|
-
return
|
|
123
|
+
if (interruptKinds is failure(error)) {
|
|
124
|
+
print("Failed to parse interrupt kinds: ${error}")
|
|
125
|
+
return
|
|
34
126
|
}
|
|
35
127
|
|
|
36
|
-
let contextMessage = "This agent can produce the following interrupts:\n
|
|
128
|
+
let contextMessage = "This agent can produce the following interrupts:\n${map(interruptKinds.value, \kind -> "- ${kind}\n").join("")}"
|
|
129
|
+
|
|
130
|
+
if (existingPolicy is success(thePolicy)) {
|
|
131
|
+
currentPolicy = thePolicy
|
|
132
|
+
contextMessage = """
|
|
133
|
+
${contextMessage}
|
|
134
|
+
|
|
135
|
+
Current policy:
|
|
136
|
+
```json
|
|
137
|
+
${highlightJSON(currentPolicy)}
|
|
138
|
+
```
|
|
37
139
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Current policy:\n```json\n${printJSON(existingPolicy)}\n```\n\nWhat would you like to change?
|
|
41
|
-
"""
|
|
140
|
+
What would you like to change?
|
|
141
|
+
"""
|
|
42
142
|
} else {
|
|
43
|
-
contextMessage =
|
|
143
|
+
contextMessage = """
|
|
144
|
+
${contextMessage}
|
|
145
|
+
|
|
146
|
+
What actions would you like to allow?
|
|
147
|
+
"""
|
|
44
148
|
}
|
|
45
149
|
|
|
46
150
|
print(contextMessage)
|
|
47
151
|
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
system(systemPrompt)
|
|
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
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (step.type == "showPolicy") {
|
|
65
|
-
policy = step.policy
|
|
66
|
-
let policyStr = printJSON(policy)
|
|
67
|
-
print("\nProposed policy:\n```json\n${policyStr}\n```\n")
|
|
68
|
-
print("Does this look right? (say 'yes' to save, or describe changes)")
|
|
69
|
-
conversationHistory = conversationHistory + "\nAssistant: Here is the proposed policy:\n${policyStr}\nDoes this look right?"
|
|
70
|
-
} else if (step.type == "writePolicy") {
|
|
71
|
-
policy = step.policy
|
|
72
|
-
writePolicyFile(outputPath, policy)
|
|
73
|
-
print("\nPolicy written to ${outputPath}")
|
|
74
|
-
done = true
|
|
75
|
-
} else if (step.type == "askQuestion") {
|
|
76
|
-
print(step.question)
|
|
77
|
-
conversationHistory = conversationHistory + "\nAssistant: ${step.question}"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return end()
|
|
81
|
-
}
|
|
152
|
+
let userInput = input("> ")
|
|
153
|
+
// didn't catch `policy` var is undefined??
|
|
154
|
+
// doesn't typecheck in string segments??
|
|
155
|
+
const prompt = """
|
|
156
|
+
Current policy: ${JSON.stringify(currentPolicy, null, 2)}
|
|
157
|
+
|
|
158
|
+
Decide the next step. If the user is describing what they want, build or update the policy and use addToPolicy, setPolicy, or deleteFromPolicy. Show the user the policy and get confirmation that it looks good. When you are done, return { type: "done" }. Otherwise, ask the user a question to clarify what they want, and return { type: "askQuestion", question: "..." }.
|
|
159
|
+
"""
|
|
82
160
|
|
|
83
|
-
|
|
161
|
+
systemMessage(systemPrompt)
|
|
162
|
+
assistantMessage(contextMessage)
|
|
163
|
+
userMessage(userInput)
|
|
84
164
|
|
|
165
|
+
const tools = [addToPolicy, getPolicy, setPolicy, deleteFromPolicy]
|
|
166
|
+
|
|
167
|
+
let action: Action = llm(prompt, {
|
|
168
|
+
tools: tools
|
|
169
|
+
})
|
|
170
|
+
while (action.type != "done") {
|
|
171
|
+
print(action.question)
|
|
172
|
+
let userInput = input("> ")
|
|
173
|
+
action: Action = llm(userInput, {
|
|
174
|
+
tools: tools
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
print("Done. Final policy:")
|
|
178
|
+
printJSON(currentPolicy)
|
|
179
|
+
const result = savePolicy(outputPath)
|
|
180
|
+
if (result is failure(error)) {
|
|
181
|
+
print("Failed to save policy: ${error}")
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
print("Saved policy to ${outputPath}.")
|
|
85
185
|
}
|
|
@@ -37,3 +37,10 @@ Each rule has:
|
|
|
37
37
|
7. If the user wants changes, refine and show again
|
|
38
38
|
|
|
39
39
|
Be concise. Don't over-explain the policy format unless the user asks. Focus on understanding what they want to allow or deny, then build the policy for them.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Tools you can use
|
|
43
|
+
- addToPolicy: adds a new rule to the policy for a given interrupt kind
|
|
44
|
+
- getPolicy: retrieves the current policy
|
|
45
|
+
- setPolicy: replaces the entire policy with a new JSON object
|
|
46
|
+
- deleteFromPolicy: deletes rules from the policy for a given interrupt kind
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { exec } from "std::shell"
|
|
2
2
|
import { args } from "std::system"
|
|
3
|
+
import { systemMessage } from "std::thread"
|
|
3
4
|
systemPrompt = read("./prompts/system.md")
|
|
4
5
|
|
|
5
6
|
type Severity = "critical" | "warning" | "suggestion"
|
|
@@ -38,7 +39,7 @@ node main() {
|
|
|
38
39
|
}
|
|
39
40
|
// Have the LLM review the code
|
|
40
41
|
thread {
|
|
41
|
-
|
|
42
|
+
systemMessage(systemPrompt)
|
|
42
43
|
let typeErrorMessage = "The type checker found no errors."
|
|
43
44
|
if (typeErrors != "") {
|
|
44
45
|
typeErrorMessage = "The type checker reported the following errors:\n${typeErrors}"
|