@chances-ai/engine 24.0.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/agents/discover.d.ts +30 -0
- package/dist/agents/discover.d.ts.map +1 -0
- package/dist/agents/discover.js +183 -0
- package/dist/agents/discover.js.map +1 -0
- package/dist/agents/index.d.ts +20 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +52 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/parse.d.ts +61 -0
- package/dist/agents/parse.d.ts.map +1 -0
- package/dist/agents/parse.js +527 -0
- package/dist/agents/parse.js.map +1 -0
- package/dist/agents/types.d.ts +52 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +8 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/ai/adapters/ai-sdk-stream.d.ts +19 -0
- package/dist/ai/adapters/ai-sdk-stream.d.ts.map +1 -0
- package/dist/ai/adapters/ai-sdk-stream.js +125 -0
- package/dist/ai/adapters/ai-sdk-stream.js.map +1 -0
- package/dist/ai/adapters/ai-sdk.d.ts +56 -0
- package/dist/ai/adapters/ai-sdk.d.ts.map +1 -0
- package/dist/ai/adapters/ai-sdk.js +112 -0
- package/dist/ai/adapters/ai-sdk.js.map +1 -0
- package/dist/ai/adapters/mock.d.ts +13 -0
- package/dist/ai/adapters/mock.d.ts.map +1 -0
- package/dist/ai/adapters/mock.js +54 -0
- package/dist/ai/adapters/mock.js.map +1 -0
- package/dist/ai/adapters/openai-compatible.d.ts +23 -0
- package/dist/ai/adapters/openai-compatible.d.ts.map +1 -0
- package/dist/ai/adapters/openai-compatible.js +45 -0
- package/dist/ai/adapters/openai-compatible.js.map +1 -0
- package/dist/ai/cost.d.ts +3 -0
- package/dist/ai/cost.d.ts.map +1 -0
- package/dist/ai/cost.js +5 -0
- package/dist/ai/cost.js.map +1 -0
- package/dist/ai/index.d.ts +12 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +11 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/known-models.d.ts +20 -0
- package/dist/ai/known-models.d.ts.map +1 -0
- package/dist/ai/known-models.js +129 -0
- package/dist/ai/known-models.js.map +1 -0
- package/dist/ai/registry.d.ts +12 -0
- package/dist/ai/registry.d.ts.map +1 -0
- package/dist/ai/registry.js +24 -0
- package/dist/ai/registry.js.map +1 -0
- package/dist/ai/retry.d.ts +11 -0
- package/dist/ai/retry.d.ts.map +1 -0
- package/dist/ai/retry.js +14 -0
- package/dist/ai/retry.js.map +1 -0
- package/dist/ai/router.d.ts +25 -0
- package/dist/ai/router.d.ts.map +1 -0
- package/dist/ai/router.js +36 -0
- package/dist/ai/router.js.map +1 -0
- package/dist/ai/setup.d.ts +23 -0
- package/dist/ai/setup.d.ts.map +1 -0
- package/dist/ai/setup.js +47 -0
- package/dist/ai/setup.js.map +1 -0
- package/dist/ai/summarizer.d.ts +24 -0
- package/dist/ai/summarizer.d.ts.map +1 -0
- package/dist/ai/summarizer.js +56 -0
- package/dist/ai/summarizer.js.map +1 -0
- package/dist/ai/types.d.ts +83 -0
- package/dist/ai/types.d.ts.map +1 -0
- package/dist/ai/types.js +2 -0
- package/dist/ai/types.js.map +1 -0
- package/dist/core/compaction/circuit-breaker.d.ts +32 -0
- package/dist/core/compaction/circuit-breaker.d.ts.map +1 -0
- package/dist/core/compaction/circuit-breaker.js +42 -0
- package/dist/core/compaction/circuit-breaker.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +75 -0
- package/dist/core/compaction/compactor.d.ts.map +1 -0
- package/dist/core/compaction/compactor.js +261 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/estimate.d.ts +39 -0
- package/dist/core/compaction/estimate.d.ts.map +1 -0
- package/dist/core/compaction/estimate.js +74 -0
- package/dist/core/compaction/estimate.js.map +1 -0
- package/dist/core/compaction/index.d.ts +5 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +5 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/prune.d.ts +43 -0
- package/dist/core/compaction/prune.d.ts.map +1 -0
- package/dist/core/compaction/prune.js +51 -0
- package/dist/core/compaction/prune.js.map +1 -0
- package/dist/core/engine.d.ts +268 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +767 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/task-tool.d.ts +175 -0
- package/dist/core/task-tool.d.ts.map +1 -0
- package/dist/core/task-tool.js +901 -0
- package/dist/core/task-tool.js.map +1 -0
- package/dist/core/workspace-query.d.ts +83 -0
- package/dist/core/workspace-query.d.ts.map +1 -0
- package/dist/core/workspace-query.js +217 -0
- package/dist/core/workspace-query.js.map +1 -0
- package/dist/core/worktree/active-marker.d.ts +31 -0
- package/dist/core/worktree/active-marker.d.ts.map +1 -0
- package/dist/core/worktree/active-marker.js +109 -0
- package/dist/core/worktree/active-marker.js.map +1 -0
- package/dist/core/worktree/create.d.ts +40 -0
- package/dist/core/worktree/create.d.ts.map +1 -0
- package/dist/core/worktree/create.js +121 -0
- package/dist/core/worktree/create.js.map +1 -0
- package/dist/core/worktree/errors.d.ts +7 -0
- package/dist/core/worktree/errors.d.ts.map +1 -0
- package/dist/core/worktree/errors.js +11 -0
- package/dist/core/worktree/errors.js.map +1 -0
- package/dist/core/worktree/gc.d.ts +39 -0
- package/dist/core/worktree/gc.d.ts.map +1 -0
- package/dist/core/worktree/gc.js +146 -0
- package/dist/core/worktree/gc.js.map +1 -0
- package/dist/core/worktree/git.d.ts +53 -0
- package/dist/core/worktree/git.d.ts.map +1 -0
- package/dist/core/worktree/git.js +166 -0
- package/dist/core/worktree/git.js.map +1 -0
- package/dist/core/worktree/index.d.ts +8 -0
- package/dist/core/worktree/index.d.ts.map +1 -0
- package/dist/core/worktree/index.js +8 -0
- package/dist/core/worktree/index.js.map +1 -0
- package/dist/core/worktree/paths.d.ts +26 -0
- package/dist/core/worktree/paths.d.ts.map +1 -0
- package/dist/core/worktree/paths.js +57 -0
- package/dist/core/worktree/paths.js.map +1 -0
- package/dist/core/worktree/slug.d.ts +6 -0
- package/dist/core/worktree/slug.d.ts.map +1 -0
- package/dist/core/worktree/slug.js +21 -0
- package/dist/core/worktree/slug.js.map +1 -0
- package/dist/local-vault/file-store.d.ts +64 -0
- package/dist/local-vault/file-store.d.ts.map +1 -0
- package/dist/local-vault/file-store.js +225 -0
- package/dist/local-vault/file-store.js.map +1 -0
- package/dist/local-vault/index.d.ts +57 -0
- package/dist/local-vault/index.d.ts.map +1 -0
- package/dist/local-vault/index.js +68 -0
- package/dist/local-vault/index.js.map +1 -0
- package/dist/local-vault/keychain.d.ts +58 -0
- package/dist/local-vault/keychain.d.ts.map +1 -0
- package/dist/local-vault/keychain.js +200 -0
- package/dist/local-vault/keychain.js.map +1 -0
- package/dist/local-vault/mutex.d.ts +20 -0
- package/dist/local-vault/mutex.d.ts.map +1 -0
- package/dist/local-vault/mutex.js +44 -0
- package/dist/local-vault/mutex.js.map +1 -0
- package/dist/local-vault/passphrase.d.ts +30 -0
- package/dist/local-vault/passphrase.d.ts.map +1 -0
- package/dist/local-vault/passphrase.js +72 -0
- package/dist/local-vault/passphrase.js.map +1 -0
- package/dist/lsp/config.d.ts +34 -0
- package/dist/lsp/config.d.ts.map +1 -0
- package/dist/lsp/config.js +68 -0
- package/dist/lsp/config.js.map +1 -0
- package/dist/lsp/detect.d.ts +7 -0
- package/dist/lsp/detect.d.ts.map +1 -0
- package/dist/lsp/detect.js +78 -0
- package/dist/lsp/detect.js.map +1 -0
- package/dist/lsp/errors.d.ts +11 -0
- package/dist/lsp/errors.d.ts.map +1 -0
- package/dist/lsp/errors.js +11 -0
- package/dist/lsp/errors.js.map +1 -0
- package/dist/lsp/formatters.d.ts +147 -0
- package/dist/lsp/formatters.d.ts.map +1 -0
- package/dist/lsp/formatters.js +259 -0
- package/dist/lsp/formatters.js.map +1 -0
- package/dist/lsp/index.d.ts +31 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +31 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/instance.d.ts +72 -0
- package/dist/lsp/instance.d.ts.map +1 -0
- package/dist/lsp/instance.js +489 -0
- package/dist/lsp/instance.js.map +1 -0
- package/dist/lsp/lazy-load.d.ts +27 -0
- package/dist/lsp/lazy-load.d.ts.map +1 -0
- package/dist/lsp/lazy-load.js +57 -0
- package/dist/lsp/lazy-load.js.map +1 -0
- package/dist/lsp/manager.d.ts +59 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +242 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/ops.d.ts +13 -0
- package/dist/lsp/ops.d.ts.map +1 -0
- package/dist/lsp/ops.js +225 -0
- package/dist/lsp/ops.js.map +1 -0
- package/dist/lsp/rpc.d.ts +47 -0
- package/dist/lsp/rpc.d.ts.map +1 -0
- package/dist/lsp/rpc.js +134 -0
- package/dist/lsp/rpc.js.map +1 -0
- package/dist/lsp/safe-uri.d.ts +18 -0
- package/dist/lsp/safe-uri.d.ts.map +1 -0
- package/dist/lsp/safe-uri.js +96 -0
- package/dist/lsp/safe-uri.js.map +1 -0
- package/dist/lsp/types.d.ts +70 -0
- package/dist/lsp/types.d.ts.map +1 -0
- package/dist/lsp/types.js +16 -0
- package/dist/lsp/types.js.map +1 -0
- package/dist/mcp/bridge.d.ts +57 -0
- package/dist/mcp/bridge.d.ts.map +1 -0
- package/dist/mcp/bridge.js +98 -0
- package/dist/mcp/bridge.js.map +1 -0
- package/dist/mcp/category.d.ts +22 -0
- package/dist/mcp/category.d.ts.map +1 -0
- package/dist/mcp/category.js +11 -0
- package/dist/mcp/category.js.map +1 -0
- package/dist/mcp/client.d.ts +228 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +352 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/content.d.ts +86 -0
- package/dist/mcp/content.d.ts.map +1 -0
- package/dist/mcp/content.js +147 -0
- package/dist/mcp/content.js.map +1 -0
- package/dist/mcp/env.d.ts +19 -0
- package/dist/mcp/env.d.ts.map +1 -0
- package/dist/mcp/env.js +50 -0
- package/dist/mcp/env.js.map +1 -0
- package/dist/mcp/host.d.ts +199 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +530 -0
- package/dist/mcp/host.js.map +1 -0
- package/dist/mcp/index.d.ts +18 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +17 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/load-mcp-host.d.ts +32 -0
- package/dist/mcp/load-mcp-host.d.ts.map +1 -0
- package/dist/mcp/load-mcp-host.js +49 -0
- package/dist/mcp/load-mcp-host.js.map +1 -0
- package/dist/mcp/oauth/callback-server.d.ts +73 -0
- package/dist/mcp/oauth/callback-server.d.ts.map +1 -0
- package/dist/mcp/oauth/callback-server.js +280 -0
- package/dist/mcp/oauth/callback-server.js.map +1 -0
- package/dist/mcp/oauth/config-hash.d.ts +24 -0
- package/dist/mcp/oauth/config-hash.d.ts.map +1 -0
- package/dist/mcp/oauth/config-hash.js +55 -0
- package/dist/mcp/oauth/config-hash.js.map +1 -0
- package/dist/mcp/oauth/error-normalize.d.ts +39 -0
- package/dist/mcp/oauth/error-normalize.d.ts.map +1 -0
- package/dist/mcp/oauth/error-normalize.js +91 -0
- package/dist/mcp/oauth/error-normalize.js.map +1 -0
- package/dist/mcp/oauth/provider.d.ts +190 -0
- package/dist/mcp/oauth/provider.d.ts.map +1 -0
- package/dist/mcp/oauth/provider.js +305 -0
- package/dist/mcp/oauth/provider.js.map +1 -0
- package/dist/mcp/oauth/refresh-coalescer.d.ts +46 -0
- package/dist/mcp/oauth/refresh-coalescer.d.ts.map +1 -0
- package/dist/mcp/oauth/refresh-coalescer.js +77 -0
- package/dist/mcp/oauth/refresh-coalescer.js.map +1 -0
- package/dist/mcp/oauth/sdk-shapes.d.ts +77 -0
- package/dist/mcp/oauth/sdk-shapes.d.ts.map +1 -0
- package/dist/mcp/oauth/sdk-shapes.js +21 -0
- package/dist/mcp/oauth/sdk-shapes.js.map +1 -0
- package/dist/mcp/parse.d.ts +28 -0
- package/dist/mcp/parse.d.ts.map +1 -0
- package/dist/mcp/parse.js +209 -0
- package/dist/mcp/parse.js.map +1 -0
- package/dist/mcp/prompts.d.ts +31 -0
- package/dist/mcp/prompts.d.ts.map +1 -0
- package/dist/mcp/prompts.js +71 -0
- package/dist/mcp/prompts.js.map +1 -0
- package/dist/mcp/redact.d.ts +62 -0
- package/dist/mcp/redact.d.ts.map +1 -0
- package/dist/mcp/redact.js +87 -0
- package/dist/mcp/redact.js.map +1 -0
- package/dist/mcp/resources.d.ts +70 -0
- package/dist/mcp/resources.d.ts.map +1 -0
- package/dist/mcp/resources.js +170 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/types.d.ts +123 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/memory/frontmatter.d.ts +18 -0
- package/dist/memory/frontmatter.d.ts.map +1 -0
- package/dist/memory/frontmatter.js +81 -0
- package/dist/memory/frontmatter.js.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/store.d.ts +44 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +237 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/memory/tools.d.ts +11 -0
- package/dist/memory/tools.d.ts.map +1 -0
- package/dist/memory/tools.js +159 -0
- package/dist/memory/tools.js.map +1 -0
- package/dist/memory/types.d.ts +32 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +20 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/plugin-api/index.d.ts +167 -0
- package/dist/plugin-api/index.d.ts.map +1 -0
- package/dist/plugin-api/index.js +151 -0
- package/dist/plugin-api/index.js.map +1 -0
- package/dist/plugin-logger/index.d.ts +21 -0
- package/dist/plugin-logger/index.d.ts.map +1 -0
- package/dist/plugin-logger/index.js +59 -0
- package/dist/plugin-logger/index.js.map +1 -0
- package/dist/session/index.d.ts +125 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +202 -0
- package/dist/session/index.js.map +1 -0
- package/dist/tools/approval.d.ts +33 -0
- package/dist/tools/approval.d.ts.map +1 -0
- package/dist/tools/approval.js +53 -0
- package/dist/tools/approval.js.map +1 -0
- package/dist/tools/builtins/_shared.d.ts +94 -0
- package/dist/tools/builtins/_shared.d.ts.map +1 -0
- package/dist/tools/builtins/_shared.js +246 -0
- package/dist/tools/builtins/_shared.js.map +1 -0
- package/dist/tools/builtins/ask-user-question.d.ts +27 -0
- package/dist/tools/builtins/ask-user-question.d.ts.map +1 -0
- package/dist/tools/builtins/ask-user-question.js +191 -0
- package/dist/tools/builtins/ask-user-question.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts +3 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -0
- package/dist/tools/builtins/bash.js +158 -0
- package/dist/tools/builtins/bash.js.map +1 -0
- package/dist/tools/builtins/diff.d.ts +3 -0
- package/dist/tools/builtins/diff.d.ts.map +1 -0
- package/dist/tools/builtins/diff.js +83 -0
- package/dist/tools/builtins/diff.js.map +1 -0
- package/dist/tools/builtins/edit.d.ts +3 -0
- package/dist/tools/builtins/edit.d.ts.map +1 -0
- package/dist/tools/builtins/edit.js +40 -0
- package/dist/tools/builtins/edit.js.map +1 -0
- package/dist/tools/builtins/glob.d.ts +3 -0
- package/dist/tools/builtins/glob.d.ts.map +1 -0
- package/dist/tools/builtins/glob.js +37 -0
- package/dist/tools/builtins/glob.js.map +1 -0
- package/dist/tools/builtins/grep.d.ts +3 -0
- package/dist/tools/builtins/grep.d.ts.map +1 -0
- package/dist/tools/builtins/grep.js +81 -0
- package/dist/tools/builtins/grep.js.map +1 -0
- package/dist/tools/builtins/lsp.d.ts +3 -0
- package/dist/tools/builtins/lsp.d.ts.map +1 -0
- package/dist/tools/builtins/lsp.js +102 -0
- package/dist/tools/builtins/lsp.js.map +1 -0
- package/dist/tools/builtins/pty.d.ts +64 -0
- package/dist/tools/builtins/pty.d.ts.map +1 -0
- package/dist/tools/builtins/pty.js +536 -0
- package/dist/tools/builtins/pty.js.map +1 -0
- package/dist/tools/builtins/read.d.ts +3 -0
- package/dist/tools/builtins/read.d.ts.map +1 -0
- package/dist/tools/builtins/read.js +18 -0
- package/dist/tools/builtins/read.js.map +1 -0
- package/dist/tools/builtins/web-fetch.d.ts +4 -0
- package/dist/tools/builtins/web-fetch.d.ts.map +1 -0
- package/dist/tools/builtins/web-fetch.js +353 -0
- package/dist/tools/builtins/web-fetch.js.map +1 -0
- package/dist/tools/builtins/write.d.ts +3 -0
- package/dist/tools/builtins/write.d.ts.map +1 -0
- package/dist/tools/builtins/write.js +48 -0
- package/dist/tools/builtins/write.js.map +1 -0
- package/dist/tools/builtins.d.ts +9 -0
- package/dist/tools/builtins.d.ts.map +1 -0
- package/dist/tools/builtins.js +29 -0
- package/dist/tools/builtins.js.map +1 -0
- package/dist/tools/diff.d.ts +18 -0
- package/dist/tools/diff.d.ts.map +1 -0
- package/dist/tools/diff.js +57 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +9 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/permission.d.ts +120 -0
- package/dist/tools/permission.d.ts.map +1 -0
- package/dist/tools/permission.js +208 -0
- package/dist/tools/permission.js.map +1 -0
- package/dist/tools/registry.d.ts +12 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +19 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/types.d.ts +244 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +15 -0
- package/dist/tools/types.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { type ApprovalMode, type AsyncTaskRegistry, type CancellationToken, type EventBus, type TaskNotification, ModelSelection } from "@chances-ai/runtime";
|
|
2
|
+
import { type ModelRouter, type RetryConfig } from "../ai/index.js";
|
|
3
|
+
import type { SessionManager } from "../session/index.js";
|
|
4
|
+
import type { MemoryStore } from "../memory/index.js";
|
|
5
|
+
import type { PermissionGate, ToolRegistry } from "../tools/index.js";
|
|
6
|
+
import type { PluginHost } from "../plugin-api/index.js";
|
|
7
|
+
export interface AgentEngineOptions {
|
|
8
|
+
bus: EventBus;
|
|
9
|
+
router: ModelRouter;
|
|
10
|
+
tools: ToolRegistry;
|
|
11
|
+
gate: PermissionGate;
|
|
12
|
+
session: SessionManager;
|
|
13
|
+
workspaceRoot: string;
|
|
14
|
+
memory?: MemoryStore;
|
|
15
|
+
plugins?: PluginHost;
|
|
16
|
+
/**
|
|
17
|
+
* (5.3) Session approval-mode getter. Read at the start of every turn (for
|
|
18
|
+
* the plan-mode system reminder) and per tool call (for the `blockByMode`
|
|
19
|
+
* pre-check). When omitted the engine behaves as `default` mode. The same
|
|
20
|
+
* getter is passed to the `PermissionGate`; child engines (`createTaskTool`)
|
|
21
|
+
* receive it too so a subagent in plan mode is told to stay read-only rather
|
|
22
|
+
* than discovering it via repeated denials (codex Round-1 SHOULD-FIX #2).
|
|
23
|
+
*/
|
|
24
|
+
getApprovalMode?: () => ApprovalMode;
|
|
25
|
+
/**
|
|
26
|
+
* Mutable model-preference holder. The engine reads it at the start of every
|
|
27
|
+
* turn, so `/model` switches land on the next request without an engine
|
|
28
|
+
* rebuild. When omitted, the engine seeds one from the deprecated scalar
|
|
29
|
+
* fields below for backwards compatibility with v2.x callers.
|
|
30
|
+
*/
|
|
31
|
+
selection?: ModelSelection;
|
|
32
|
+
/** @deprecated since v3.0 — pass `selection` instead. Still honored when
|
|
33
|
+
* `selection` is absent so existing tests / external callers don't break. */
|
|
34
|
+
preferredModel?: string;
|
|
35
|
+
/** @deprecated since v3.0 — pass `selection` instead. */
|
|
36
|
+
preferredProvider?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Safety valve against runaway tool loops. Matches claude-code's `maxTurns`
|
|
39
|
+
* (`src/QueryEngine.ts:154`) and pi's `MAX_TURNS` test convention. When the
|
|
40
|
+
* loop exhausts this budget without the model returning a final answer, the
|
|
41
|
+
* engine throws `AppError(Provider, "Reached maximum number of turns (N)")`
|
|
42
|
+
* — claude-code's terminal-error pattern. Defaults to 12 when omitted; the
|
|
43
|
+
* CLI threads `ChancesConfig.agent.maxTurns` in here.
|
|
44
|
+
*/
|
|
45
|
+
maxTurns?: number;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Renamed to `maxTurns` in 3.0.1 for parity with claude-code /
|
|
48
|
+
* pi. The old name still works for one minor cycle so any out-of-tree
|
|
49
|
+
* caller doesn't break silently; removal target is 4.x. New callers should
|
|
50
|
+
* use `maxTurns`. When both are set, `maxTurns` wins.
|
|
51
|
+
*/
|
|
52
|
+
maxIterations?: number;
|
|
53
|
+
/** Override default per-attempt backoff for provider stream retries. */
|
|
54
|
+
retry?: RetryConfig;
|
|
55
|
+
/**
|
|
56
|
+
* When true, the engine does NOT emit `error` events on the shared bus for
|
|
57
|
+
* its own terminal failures (provider exhaustion, max-turns). It still
|
|
58
|
+
* throws `AppError` so the caller can surface the failure on its own
|
|
59
|
+
* channel. Set this for child engines (e.g. the `task` subagent tool) that
|
|
60
|
+
* share a bus with a parent loop — without it the parent's `lastError`
|
|
61
|
+
* listener (see `apps/cli/src/commands/prompt.ts:26`) would record the
|
|
62
|
+
* child's failure as the *parent's* exit code, even when the parent's
|
|
63
|
+
* overall turn succeeded.
|
|
64
|
+
*
|
|
65
|
+
* Telemetry / TUI still see the child's per-call `usage`, `tool:call`, and
|
|
66
|
+
* `tool:result` frames — only the terminal `error` event is suppressed.
|
|
67
|
+
* The `tool:result` for the parent's `task` call carries the failure text
|
|
68
|
+
* (e.g. "Subagent failed: PROVIDER: ..."), which is the contextual story
|
|
69
|
+
* users actually need.
|
|
70
|
+
*/
|
|
71
|
+
suppressTerminalErrors?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Replaces the hardcoded base system prompt with caller-supplied text.
|
|
74
|
+
* Memory context (`MemoryStore.asSystemContext()`) is still appended after
|
|
75
|
+
* it. Set by the subagent `task` tool when spawning a catalog persona —
|
|
76
|
+
* the agent's body becomes the child's prompt INSTEAD of the generic
|
|
77
|
+
* "You are chances..." base, so a read-only `explore` agent doesn't carry
|
|
78
|
+
* the parent's "you may modify the workspace" framing into its turn.
|
|
79
|
+
* (3.3 design doc: codex Round-1 #3.) Undefined → engine keeps the v3.0
|
|
80
|
+
* baseline.
|
|
81
|
+
*/
|
|
82
|
+
systemBaseOverride?: string;
|
|
83
|
+
/**
|
|
84
|
+
* (3.4) Identity tag for events this engine emits. Child engines (the
|
|
85
|
+
* `task` subagent tool) set this so subscribers can demultiplex
|
|
86
|
+
* parent vs. child output on a shared bus. Parent engines leave undefined.
|
|
87
|
+
* Tagged event variants: `assistant:delta`, `assistant:message`,
|
|
88
|
+
* `tool:call`, `tool:permission`, `tool:result`, `usage`. Lifecycle
|
|
89
|
+
* events (`turn:start`, `turn:end`, `error`) are not tagged — child
|
|
90
|
+
* engines suppress those via `suppressLifecycleEvents`.
|
|
91
|
+
*
|
|
92
|
+
* `agentId` is optional (3.6 codex Round-1 MUST-FIX #3): sync subagents
|
|
93
|
+
* have no registry-issued id (they complete before the parent's
|
|
94
|
+
* `tool:call`/`tool:result` boundary closes — the parent already
|
|
95
|
+
* labels them at that level). Background subagents always set it.
|
|
96
|
+
*/
|
|
97
|
+
agentContext?: {
|
|
98
|
+
agentId?: string;
|
|
99
|
+
agentName: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* (3.4 — codex Round-1 MUST-FIX #2) When true, the engine does NOT emit
|
|
103
|
+
* `turn:start` / `turn:end` / `error` events on the shared bus. Set for
|
|
104
|
+
* child engines because the TUI flips its `busy` flag on every `turn:*`
|
|
105
|
+
* event (`packages/tui/src/view-model.ts:74-101`) — a child's turn
|
|
106
|
+
* lifecycle would otherwise end the parent's busy state and confuse the
|
|
107
|
+
* NDJSON / `-p` mode renderers that assume one bus = one conversation.
|
|
108
|
+
*
|
|
109
|
+
* `error` is suppressed too because the existing `suppressTerminalErrors`
|
|
110
|
+
* only gated the engine's *terminal* error emits (provider exhaustion,
|
|
111
|
+
* max-turns) — but with `agentContext` plumbing children can also emit
|
|
112
|
+
* mid-turn errors, and those should stay off the shared bus.
|
|
113
|
+
*/
|
|
114
|
+
suppressLifecycleEvents?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* (3.4) Optional registry of background subagent tasks. When provided:
|
|
117
|
+
* - At the top of every `runTurn`, the engine drains queued
|
|
118
|
+
* completion notifications and prepends an XML block to the turn's
|
|
119
|
+
* user-role message so the model sees them on the next request.
|
|
120
|
+
* - The `task` tool is expected to wire the launch path through the
|
|
121
|
+
* same registry (handled in `createTaskTool`, not here).
|
|
122
|
+
* When undefined: drain is a no-op (same as 3.3). The `task` tool's
|
|
123
|
+
* schema omits `run_in_background`. Used to scope the feature to
|
|
124
|
+
* interactive `chat` mode — `-p` one-shot mode passes undefined so
|
|
125
|
+
* backgrounds never accidentally orphan into a process exit.
|
|
126
|
+
*/
|
|
127
|
+
backgroundTasks?: AsyncTaskRegistry;
|
|
128
|
+
/**
|
|
129
|
+
* (3.5) Auto-compaction orchestrator. When provided:
|
|
130
|
+
* - After every appendTurn + before turn:end, the engine asks
|
|
131
|
+
* `compactor.shouldCompact(...)` with the last provider
|
|
132
|
+
* request's `inputTokens`, and `await`s
|
|
133
|
+
* `compactor.compact("threshold", token.signal)` when true.
|
|
134
|
+
* - On Anthropic overflow errors (`"prompt is too long"` /
|
|
135
|
+
* `"request_too_large"` / `"maximum.*context.*length"`),
|
|
136
|
+
* the engine triggers `compactor.compact("overflow", ...)`
|
|
137
|
+
* once per turn and retries the failed stream.
|
|
138
|
+
* - Engine emits `usage:turn` carrying `lastRequestInputTokens`
|
|
139
|
+
* BEFORE the compaction await; `turn:end` fires AFTER (codex
|
|
140
|
+
* Round-1 MUST-FIX #4 — TUI / slash should not see "turn
|
|
141
|
+
* over" while session is still mutating).
|
|
142
|
+
* When undefined (subagent engines, `-p` one-shot mode), the
|
|
143
|
+
* engine still emits `usage:turn` but never compacts.
|
|
144
|
+
*/
|
|
145
|
+
compactor?: import("./compaction/index.js").Compactor;
|
|
146
|
+
/**
|
|
147
|
+
* (4.1) Active worktree path for an isolated subagent. When set:
|
|
148
|
+
* - `ToolContext.workspaceRoot` and `ToolContext.cwd` BOTH flip to
|
|
149
|
+
* `worktreeCwd` for the duration of `runTurn`. `safePath`
|
|
150
|
+
* therefore resolves against the worktree tree, not the parent's.
|
|
151
|
+
* - The engine wraps `runTurn` body in `runWithCwd(worktreeCwd,
|
|
152
|
+
* …)` so descendant tool calls inherit the override transparently
|
|
153
|
+
* via AsyncLocalStorage (same pattern claude-code uses in
|
|
154
|
+
* `src/utils/cwd.ts`).
|
|
155
|
+
* - At every `runTurn` top, `refreshActiveMarker(worktreeCwd)`
|
|
156
|
+
* fires so cross-process GC can tell this worktree has a live
|
|
157
|
+
* owner.
|
|
158
|
+
* - The system prompt gains a paragraph informing the model that
|
|
159
|
+
* uncommitted parent changes are invisible here and the parent
|
|
160
|
+
* will see the final diff after the task completes.
|
|
161
|
+
* Set by `task-tool.ts` when `isolation: 'worktree'` is resolved for
|
|
162
|
+
* the spawning agent. Undefined → no isolation (the 3.x default).
|
|
163
|
+
*/
|
|
164
|
+
worktreeCwd?: string;
|
|
165
|
+
/**
|
|
166
|
+
* (4.2) Optional LSP host wired in at boot. Threaded through to
|
|
167
|
+
* `ToolContext.lsp` so the `lsp` built-in can reach it without a
|
|
168
|
+
* module-global. Undefined → tool returns `ok:false` "LSP not
|
|
169
|
+
* available". codex Round-1 MUST-FIX #1 — keeps the wrapper free
|
|
170
|
+
* of CLI-boot-state imports.
|
|
171
|
+
*/
|
|
172
|
+
lsp?: import("../tools/index.js").ToolLspHost;
|
|
173
|
+
/**
|
|
174
|
+
* (5.4) Optional MCP resource-mention resolver. When set, `runTurn`
|
|
175
|
+
* expands `@<server>:<uri>` mentions in DIRECTLY-TYPED user input into a
|
|
176
|
+
* synthetic resource message before the turn. Injected by boot (closed over
|
|
177
|
+
* the `McpHost`); typed structurally so `@chances-ai/core` stays decoupled
|
|
178
|
+
* from `@chances-ai/mcp` (no boundary edge). NOT applied to submitted/prompt
|
|
179
|
+
* text — see `runTurn`'s `expandMentions` (codex 5.4 R1 M3).
|
|
180
|
+
*/
|
|
181
|
+
resolveMcpMentions?: (prompt: string, signal: AbortSignal) => Promise<ResolvedMention[]>;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* (5.4) Structural shape of a resolved `@<server>:<uri>` mention — mirrors
|
|
185
|
+
* `@chances-ai/mcp#McpResolvedResource` without importing it (boundary).
|
|
186
|
+
*/
|
|
187
|
+
export interface ResolvedMention {
|
|
188
|
+
ref: string;
|
|
189
|
+
server: string;
|
|
190
|
+
uri: string;
|
|
191
|
+
/** Rendered resource content (present on success). */
|
|
192
|
+
text?: string;
|
|
193
|
+
/** Why it couldn't be read (mutually exclusive with `text`). */
|
|
194
|
+
note?: string;
|
|
195
|
+
}
|
|
196
|
+
/** Engine default when no caller-supplied or config-supplied value applies. */
|
|
197
|
+
export declare const DEFAULT_MAX_TURNS = 12;
|
|
198
|
+
/** Default base prompt the engine uses when no `systemBaseOverride` is set.
|
|
199
|
+
* Exported so tests can assert "is this the default or an agent override?" and
|
|
200
|
+
* so the doc + plugin authors can read the exact text. */
|
|
201
|
+
export declare const DEFAULT_BASE_PROMPT: string;
|
|
202
|
+
export interface AgentResult {
|
|
203
|
+
text: string;
|
|
204
|
+
inputTokens: number;
|
|
205
|
+
outputTokens: number;
|
|
206
|
+
costUsd: number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Mediator over ai/session/tools/memory. Depends only on interfaces (ports), so
|
|
210
|
+
* any ProviderAdapter or Tool plugs in unchanged. Communicates outward purely by
|
|
211
|
+
* emitting events on the bus — it never imports the TUI.
|
|
212
|
+
*/
|
|
213
|
+
export declare class AgentEngine {
|
|
214
|
+
private readonly opts;
|
|
215
|
+
private readonly selection;
|
|
216
|
+
constructor(opts: AgentEngineOptions);
|
|
217
|
+
/**
|
|
218
|
+
* Exposes the mutable selection so callers — typically slash commands like
|
|
219
|
+
* `/model` — can update it between turns. Returning the live instance (not a
|
|
220
|
+
* copy) is intentional: writes must propagate back.
|
|
221
|
+
*/
|
|
222
|
+
getSelection(): ModelSelection;
|
|
223
|
+
/** Bus-emit wrapper. Three responsibilities (3.4):
|
|
224
|
+
* 1. Suppress lifecycle frames (`turn:*`, `error`) when the engine is a
|
|
225
|
+
* child (`suppressLifecycleEvents=true`). Codex Round-1 MUST-FIX #2.
|
|
226
|
+
* 2. Stamp `agentId/agentName` on tagged event variants when an
|
|
227
|
+
* `agentContext` was supplied. Skipped silently when undefined.
|
|
228
|
+
* 3. Forward to `bus.emit` otherwise — fully transparent for parent engines.
|
|
229
|
+
*/
|
|
230
|
+
private emit;
|
|
231
|
+
runTurn(prompt: string, token: CancellationToken, opts?: {
|
|
232
|
+
expandMentions?: boolean;
|
|
233
|
+
}): Promise<AgentResult>;
|
|
234
|
+
private runTurnImpl;
|
|
235
|
+
private runTool;
|
|
236
|
+
private composeSystem;
|
|
237
|
+
}
|
|
238
|
+
/** (5.3) Inserted into the system prompt while the session approval mode is
|
|
239
|
+
* `plan`. Tells the model it is read-only and should produce a plan instead of
|
|
240
|
+
* editing — the same posture claude-code's plan mode enforces. */
|
|
241
|
+
export declare const PLAN_MODE_NOTICE: string;
|
|
242
|
+
/** (4.1) Inserted at the END of the child engine's system prompt when
|
|
243
|
+
* `worktreeCwd` is set. Tells the model two load-bearing facts: the
|
|
244
|
+
* worktree starts from HEAD (parent's uncommitted state is invisible),
|
|
245
|
+
* and writes are sandboxed (parent sees them as a diff after the task
|
|
246
|
+
* completes, not live). Round-1 SHOULD-FIX #2 wording. */
|
|
247
|
+
export declare const ISOLATED_WORKTREE_NOTICE: string;
|
|
248
|
+
/** Renders one `<task-notification>` XML block, fully entity-escaped so
|
|
249
|
+
* `result`/`summary` text containing `<`, `>`, `&`, `"`, `'` can't break
|
|
250
|
+
* the surrounding tag structure or impersonate a different role.
|
|
251
|
+
*
|
|
252
|
+
* This is the format the model receives at the top of its next turn
|
|
253
|
+
* after a background subagent completes. The shape matches the one we
|
|
254
|
+
* (chances-cli's own host) observe receiving from background research
|
|
255
|
+
* subagents — claude-code's `<task_notification>` convention, with our
|
|
256
|
+
* hyphen-separated tag style.
|
|
257
|
+
*/
|
|
258
|
+
export declare function renderTaskNotificationXml(n: TaskNotification): string;
|
|
259
|
+
/**
|
|
260
|
+
* (5.4) Build the synthetic resource message for `@<server>:<uri>` mentions.
|
|
261
|
+
* EVERY inserted field — server, uri, body, note — is XML-escaped (codex R1 M5:
|
|
262
|
+
* a malicious resource could otherwise close the tag and inject instructions),
|
|
263
|
+
* exactly like `renderTaskNotificationXml`. The resolver already stripped
|
|
264
|
+
* controls + redacted the body. Returns "" when nothing resolved (the caller
|
|
265
|
+
* skips the message entirely).
|
|
266
|
+
*/
|
|
267
|
+
export declare function renderMcpResourcesXml(resolved: ResolvedMention[]): string;
|
|
268
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/core/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,gBAAgB,EAGrB,cAAc,E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