@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,70 @@
|
|
|
1
|
+
import type { Tool } from "../tools/index.js";
|
|
2
|
+
import type { McpResource, McpResourceContent } from "./types.js";
|
|
3
|
+
/** A parsed `@<server>:<uri>` mention from user input. */
|
|
4
|
+
export interface ResourceMention {
|
|
5
|
+
ref: string;
|
|
6
|
+
server: string;
|
|
7
|
+
uri: string;
|
|
8
|
+
}
|
|
9
|
+
/** A resource resolved (or attempted) for injection into a turn. */
|
|
10
|
+
export interface McpResolvedResource {
|
|
11
|
+
ref: string;
|
|
12
|
+
server: string;
|
|
13
|
+
uri: string;
|
|
14
|
+
/** Rendered, capped, redacted content. Present on success. */
|
|
15
|
+
text?: string;
|
|
16
|
+
/** Why it couldn't be read (server offline, read error). Mutually exclusive
|
|
17
|
+
* with `text`. Absent + absent text ⇒ caller skipped it (non-member). */
|
|
18
|
+
note?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* (5.4 D4) Extract `@<server>:<uri>` mentions. The `@` must start a token
|
|
22
|
+
* (`(^|\s)@`) so an email (`a@b.com`) never matches; the body must contain an
|
|
23
|
+
* internal colon so a bare `@channel` is ignored. We capture the whole
|
|
24
|
+
* non-whitespace run and then strip trailing PROSE punctuation
|
|
25
|
+
* (`. , ; : ! ? ) ]`) — NOT `/`, so a directory-style URI ending in `/` is kept
|
|
26
|
+
* (5.4 R2: the old trailing-`\b` silently truncated `…/tmp/` and `…/a.md.`,
|
|
27
|
+
* which then missed the exact-cached match). Split on the FIRST colon →
|
|
28
|
+
* `(server, uri)`. Deduped by `ref`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractResourceMentions(text: string): ResourceMention[];
|
|
31
|
+
/**
|
|
32
|
+
* (5.4 D9′) The narrow host surface the resource tools + mention resolver need.
|
|
33
|
+
* `readResource` returns the raw content plus the per-server redactor (the host
|
|
34
|
+
* owns the secret bag); rendering/persistence happens in the tool/resolver which
|
|
35
|
+
* have the workspace root. Throws `AppError` on unknown server / read failure /
|
|
36
|
+
* restart race so callers can surface a clean message.
|
|
37
|
+
*/
|
|
38
|
+
export interface McpResourceProvider {
|
|
39
|
+
/** Cached `resources/list` snapshot, optionally filtered to one server. */
|
|
40
|
+
resources(server?: string): McpResource[];
|
|
41
|
+
readResource(server: string, uri: string, signal: AbortSignal): Promise<{
|
|
42
|
+
contents: McpResourceContent[];
|
|
43
|
+
redact: (msg: string) => string;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface ResourceToolOptions {
|
|
47
|
+
/** UTF-8 byte cap for inline resource text (`config.mcp.resourceReadMaxBytes`). */
|
|
48
|
+
maxBytes: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* (5.4 D5/N2) The two GLOBAL resource tools. They are intentionally NOT named
|
|
52
|
+
* `mcp__<server>__<tool>` (that prefix is reserved for bridged server tools) —
|
|
53
|
+
* single underscore + an explicit "global; pass {server, uri}" description so
|
|
54
|
+
* the model doesn't infer a server named `read`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function makeResourceTools(provider: McpResourceProvider, opts: ResourceToolOptions): Tool[];
|
|
57
|
+
/**
|
|
58
|
+
* (5.4 D4′/M3/S2) Resolve `@<server>:<uri>` mentions in DIRECTLY-TYPED user
|
|
59
|
+
* input. Only resolves mentions whose `(server, uri)` EXACTLY match the cached
|
|
60
|
+
* `resources/list` (S2 — a known-server prefix + arbitrary URI must go through
|
|
61
|
+
* the gated `mcp_read_resource` tool, never an ungated pre-turn read). Non-
|
|
62
|
+
* members are skipped (left as plain text). Read failures become a `note` and
|
|
63
|
+
* never throw — a bad @-ref must not abort the turn. NOT called on prompt-command
|
|
64
|
+
* output (M3 — the engine passes `expandMentions:false` for that).
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveMcpMentions(provider: McpResourceProvider, prompt: string, signal: AbortSignal, opts: {
|
|
67
|
+
maxBytes: number;
|
|
68
|
+
artifactRoot: string;
|
|
69
|
+
}): Promise<McpResolvedResource[]>;
|
|
70
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/mcp/resources.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAqB,IAAI,EAA2B,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGlE,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oEAAoE;AACpE,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;8EAC0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,CAgBvE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,2EAA2E;IAC3E,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;IAC1C,YAAY,CACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC;QAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC;QAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,QAAQ,EAAE,MAAM,CAAC;CAClB;AAUD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,IAAI,EAAE,mBAAmB,GAAG,IAAI,EAAE,CAsFlG;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC/C,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAuBhC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { AppError, ErrorCode } from "@chances-ai/runtime";
|
|
2
|
+
import { formatResourceContents, persistResourceBlob } from "./content.js";
|
|
3
|
+
/**
|
|
4
|
+
* (5.4 D4) Extract `@<server>:<uri>` mentions. The `@` must start a token
|
|
5
|
+
* (`(^|\s)@`) so an email (`a@b.com`) never matches; the body must contain an
|
|
6
|
+
* internal colon so a bare `@channel` is ignored. We capture the whole
|
|
7
|
+
* non-whitespace run and then strip trailing PROSE punctuation
|
|
8
|
+
* (`. , ; : ! ? ) ]`) — NOT `/`, so a directory-style URI ending in `/` is kept
|
|
9
|
+
* (5.4 R2: the old trailing-`\b` silently truncated `…/tmp/` and `…/a.md.`,
|
|
10
|
+
* which then missed the exact-cached match). Split on the FIRST colon →
|
|
11
|
+
* `(server, uri)`. Deduped by `ref`.
|
|
12
|
+
*/
|
|
13
|
+
export function extractResourceMentions(text) {
|
|
14
|
+
const re = /(^|\s)@(\S+)/g;
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const out = [];
|
|
17
|
+
let m;
|
|
18
|
+
while ((m = re.exec(text)) !== null) {
|
|
19
|
+
const ref = m[2].replace(/[.,;:!?)\]]+$/, "");
|
|
20
|
+
if (seen.has(ref))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(ref);
|
|
23
|
+
const colon = ref.indexOf(":");
|
|
24
|
+
if (colon <= 0)
|
|
25
|
+
continue; // no internal colon (or leading colon) → not a mention
|
|
26
|
+
const server = ref.slice(0, colon);
|
|
27
|
+
const uri = ref.slice(colon + 1);
|
|
28
|
+
if (server && uri)
|
|
29
|
+
out.push({ ref, server, uri });
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
function str(args, key) {
|
|
34
|
+
if (args && typeof args === "object" && !Array.isArray(args)) {
|
|
35
|
+
const v = args[key];
|
|
36
|
+
if (typeof v === "string")
|
|
37
|
+
return v;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* (5.4 D5/N2) The two GLOBAL resource tools. They are intentionally NOT named
|
|
43
|
+
* `mcp__<server>__<tool>` (that prefix is reserved for bridged server tools) —
|
|
44
|
+
* single underscore + an explicit "global; pass {server, uri}" description so
|
|
45
|
+
* the model doesn't infer a server named `read`.
|
|
46
|
+
*/
|
|
47
|
+
export function makeResourceTools(provider, opts) {
|
|
48
|
+
const list = {
|
|
49
|
+
name: "mcp_list_resources",
|
|
50
|
+
description: "List resources exposed by connected MCP servers (global; optional {server} filter). " +
|
|
51
|
+
"Returns lines of '<server>:<uri> <name> (<mimeType>)'. Read one with mcp_read_resource.",
|
|
52
|
+
category: "search",
|
|
53
|
+
parameters: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: { server: { type: "string", description: "Optional server id filter" } },
|
|
56
|
+
},
|
|
57
|
+
summarize: (args) => {
|
|
58
|
+
const s = str(args, "server");
|
|
59
|
+
return s ? `list MCP resources (server '${s}')` : "list MCP resources";
|
|
60
|
+
},
|
|
61
|
+
async execute(args) {
|
|
62
|
+
const server = str(args, "server");
|
|
63
|
+
const resources = provider.resources(server);
|
|
64
|
+
if (resources.length === 0) {
|
|
65
|
+
return { ok: true, output: server ? `(no resources on server '${server}')` : "(no MCP resources available)" };
|
|
66
|
+
}
|
|
67
|
+
const lines = resources.map((r) => {
|
|
68
|
+
const name = r.name ? ` ${r.name}` : "";
|
|
69
|
+
const mime = r.mimeType ? ` (${r.mimeType})` : "";
|
|
70
|
+
return `${r.server}:${r.uri}${name}${mime}`;
|
|
71
|
+
});
|
|
72
|
+
return { ok: true, output: lines.join("\n") };
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const read = {
|
|
76
|
+
name: "mcp_read_resource",
|
|
77
|
+
description: "Read one MCP resource (global; pass {server, uri}). Text is returned inline (capped); " +
|
|
78
|
+
"binary blobs are saved to disk and referenced by path. Discover URIs with mcp_list_resources.",
|
|
79
|
+
category: "integration",
|
|
80
|
+
parameters: {
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {
|
|
83
|
+
server: { type: "string", description: "MCP server id" },
|
|
84
|
+
uri: { type: "string", description: "Resource URI" },
|
|
85
|
+
},
|
|
86
|
+
required: ["server", "uri"],
|
|
87
|
+
},
|
|
88
|
+
summarize: (args) => {
|
|
89
|
+
const server = str(args, "server") ?? "?";
|
|
90
|
+
const uri = str(args, "uri") ?? "?";
|
|
91
|
+
return `read resource '${uri}' from MCP server '${server}'`;
|
|
92
|
+
},
|
|
93
|
+
// (5.4 D5/M4) Per-server cache scope: approving reads from server A must
|
|
94
|
+
// not pre-approve server B. The slash lifecycle invalidates
|
|
95
|
+
// `mcp_read_resource/<server>` on restart/remove/logout.
|
|
96
|
+
permission(args, ctx) {
|
|
97
|
+
const server = str(args, "server") ?? "?";
|
|
98
|
+
return {
|
|
99
|
+
name: "mcp_read_resource",
|
|
100
|
+
category: "integration",
|
|
101
|
+
summary: this.summarize(args, ctx),
|
|
102
|
+
args,
|
|
103
|
+
cacheKey: `mcp_read_resource/${server}`,
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
async execute(args, ctx) {
|
|
107
|
+
const server = str(args, "server");
|
|
108
|
+
const uri = str(args, "uri");
|
|
109
|
+
if (!server || !uri) {
|
|
110
|
+
return { ok: false, output: "mcp_read_resource requires { server, uri }" };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const { contents, redact } = await provider.readResource(server, uri, ctx.signal);
|
|
114
|
+
const root = ctx.parentWorkspaceRoot ?? ctx.workspaceRoot;
|
|
115
|
+
const output = formatResourceContents(contents, {
|
|
116
|
+
redact,
|
|
117
|
+
maxBytes: opts.maxBytes,
|
|
118
|
+
persistBlob: (buf, mime) => persistResourceBlob(root, buf, mime),
|
|
119
|
+
});
|
|
120
|
+
return { ok: true, output: output || "(empty resource)" };
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
if (ctx.signal.aborted)
|
|
124
|
+
throw new AppError(ErrorCode.Cancelled, "Operation cancelled");
|
|
125
|
+
if (e instanceof AppError && e.code === ErrorCode.Cancelled)
|
|
126
|
+
throw e;
|
|
127
|
+
return { ok: false, output: e.message };
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
return [list, read];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* (5.4 D4′/M3/S2) Resolve `@<server>:<uri>` mentions in DIRECTLY-TYPED user
|
|
135
|
+
* input. Only resolves mentions whose `(server, uri)` EXACTLY match the cached
|
|
136
|
+
* `resources/list` (S2 — a known-server prefix + arbitrary URI must go through
|
|
137
|
+
* the gated `mcp_read_resource` tool, never an ungated pre-turn read). Non-
|
|
138
|
+
* members are skipped (left as plain text). Read failures become a `note` and
|
|
139
|
+
* never throw — a bad @-ref must not abort the turn. NOT called on prompt-command
|
|
140
|
+
* output (M3 — the engine passes `expandMentions:false` for that).
|
|
141
|
+
*/
|
|
142
|
+
export async function resolveMcpMentions(provider, prompt, signal, opts) {
|
|
143
|
+
const mentions = extractResourceMentions(prompt);
|
|
144
|
+
if (mentions.length === 0)
|
|
145
|
+
return [];
|
|
146
|
+
const out = [];
|
|
147
|
+
for (const mention of mentions) {
|
|
148
|
+
const member = provider
|
|
149
|
+
.resources(mention.server)
|
|
150
|
+
.some((r) => r.server === mention.server && r.uri === mention.uri);
|
|
151
|
+
if (!member)
|
|
152
|
+
continue; // S2: only exact cached members; else plain text.
|
|
153
|
+
try {
|
|
154
|
+
const { contents, redact } = await provider.readResource(mention.server, mention.uri, signal);
|
|
155
|
+
const text = formatResourceContents(contents, {
|
|
156
|
+
redact,
|
|
157
|
+
maxBytes: opts.maxBytes,
|
|
158
|
+
persistBlob: (buf, mime) => persistResourceBlob(opts.artifactRoot, buf, mime),
|
|
159
|
+
});
|
|
160
|
+
out.push({ ...mention, text: text || "(empty resource)" });
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
if (signal.aborted)
|
|
164
|
+
throw new AppError(ErrorCode.Cancelled, "Operation cancelled");
|
|
165
|
+
out.push({ ...mention, note: `could not read: ${e.message}` });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/mcp/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAqB3E;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,MAAM,EAAE,GAAG,eAAe,CAAC;IAC3B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACpC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAA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1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-server config entry. The two transport flavors we ship in 3.1:
|
|
3
|
+
* - `stdio`: spawn a subprocess and exchange JSON-RPC over stdin/stdout.
|
|
4
|
+
* Default for most filesystem / cli MCP servers.
|
|
5
|
+
* - `http`: hit a streamable-HTTP endpoint. The MCP spec replaces SSE with
|
|
6
|
+
* streamable HTTP, so we don't ship SSE separately.
|
|
7
|
+
*
|
|
8
|
+
* `enabled: false` keeps the entry in config but skips connection on boot —
|
|
9
|
+
* useful for temporarily silencing a flaky server without losing its config.
|
|
10
|
+
*/
|
|
11
|
+
export type McpServerConfig = StdioMcpConfig | HttpMcpConfig;
|
|
12
|
+
interface BaseMcpConfig {
|
|
13
|
+
/** Default true. Disabled servers are listed by `/mcp` but never connect. */
|
|
14
|
+
enabled?: boolean;
|
|
15
|
+
/** Per-request timeout in milliseconds; default 30 000. */
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface StdioMcpConfig extends BaseMcpConfig {
|
|
19
|
+
type: "stdio";
|
|
20
|
+
command: string;
|
|
21
|
+
args?: string[];
|
|
22
|
+
/** Extra env vars merged onto `process.env` when spawning the subprocess. */
|
|
23
|
+
env?: Record<string, string>;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface HttpMcpConfig extends BaseMcpConfig {
|
|
27
|
+
type: "http";
|
|
28
|
+
url: string;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
/** (3.7) Optional OAuth configuration. When present, the host wires
|
|
31
|
+
* the chances OAuth provider into the SDK's streamable-HTTP
|
|
32
|
+
* transport. See `oauth/types.ts` for the discriminated union. */
|
|
33
|
+
auth?: OAuthMcpAuth;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* (3.7) OAuth configuration for an HTTP-transport MCP server.
|
|
37
|
+
* Currently `oauth` is the only `kind`; reserved for future variants
|
|
38
|
+
* like `client_credentials` (M2M) without breaking config schema.
|
|
39
|
+
*/
|
|
40
|
+
export interface OAuthMcpAuth {
|
|
41
|
+
kind: "oauth";
|
|
42
|
+
/** Optional explicit auth-server metadata URL. When absent, the SDK
|
|
43
|
+
* probes RFC 9728 → RFC 8414 starting from `serverConfig.url`. */
|
|
44
|
+
authServerMetadataUrl?: string;
|
|
45
|
+
/** Pre-registered OAuth client ID. When absent, Dynamic Client
|
|
46
|
+
* Registration (RFC 7591) runs on first flow. */
|
|
47
|
+
clientId?: string;
|
|
48
|
+
/** Pre-registered client secret. Only meaningful with `clientId`. */
|
|
49
|
+
clientSecret?: string;
|
|
50
|
+
/** OAuth scopes requested at consent. Empty array = the IdP's default. */
|
|
51
|
+
scopes?: readonly string[];
|
|
52
|
+
/** Override loopback callback port. When set, port-fallback is
|
|
53
|
+
* DISABLED (oh-my-pi commit `c246d88db` lesson — silent fallback
|
|
54
|
+
* breaks exact-URI-match with registered redirect_uri). */
|
|
55
|
+
callbackPort?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Per-server lifecycle snapshot. Surfaced through `McpHost.status()` so the
|
|
59
|
+
* `/mcp` slash command can render a meaningful list — including failed
|
|
60
|
+
* servers, not just running ones (otherwise users can't tell why a tool
|
|
61
|
+
* disappeared).
|
|
62
|
+
*/
|
|
63
|
+
export interface McpServerStatus {
|
|
64
|
+
id: string;
|
|
65
|
+
state: "starting" | "ready" | "failed" | "disabled" | "disposed";
|
|
66
|
+
/** Populated when `state === "failed"`. */
|
|
67
|
+
error?: string;
|
|
68
|
+
/** Tools discovered after a successful `tools/list`. Undefined when not yet ready. */
|
|
69
|
+
toolCount?: number;
|
|
70
|
+
/** Names of tools registered into the engine's ToolRegistry. */
|
|
71
|
+
toolNames?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
/** Result of `/mcp test <name>` — a one-shot connect + list + dispose. */
|
|
74
|
+
export interface McpTestResult {
|
|
75
|
+
ok: boolean;
|
|
76
|
+
/** When ok: the discovered tool names. Otherwise: the error reason. */
|
|
77
|
+
output: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* (5.4) A resource a server advertises via `resources/list`. We keep the
|
|
81
|
+
* subset we surface; servers may carry more (annotations, size). `server` is
|
|
82
|
+
* stamped by the host so a flat resource list across servers stays attributable
|
|
83
|
+
* (the `@<server>:<uri>` mention + `mcp_read_resource({server, uri})` both need it).
|
|
84
|
+
*/
|
|
85
|
+
export interface McpResource {
|
|
86
|
+
/** Owning server id — stamped by the host, not the wire. */
|
|
87
|
+
server: string;
|
|
88
|
+
uri: string;
|
|
89
|
+
name?: string;
|
|
90
|
+
description?: string;
|
|
91
|
+
mimeType?: string;
|
|
92
|
+
}
|
|
93
|
+
/** One content item from `resources/read`. Text xor blob (base64). */
|
|
94
|
+
export interface McpResourceContent {
|
|
95
|
+
uri?: string;
|
|
96
|
+
mimeType?: string;
|
|
97
|
+
text?: string;
|
|
98
|
+
/** base64 — persisted to disk by the reader, never inlined into context. */
|
|
99
|
+
blob?: string;
|
|
100
|
+
}
|
|
101
|
+
/** A declared argument of a server prompt (`prompts/list`). */
|
|
102
|
+
export interface McpPromptArgument {
|
|
103
|
+
name: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
required?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* (5.4) A prompt a server advertises via `prompts/list`. `server` is stamped by
|
|
109
|
+
* the host. Surfaced as the slash command `/<server>:<name>`.
|
|
110
|
+
*/
|
|
111
|
+
export interface McpPrompt {
|
|
112
|
+
server: string;
|
|
113
|
+
name: string;
|
|
114
|
+
description?: string;
|
|
115
|
+
arguments?: McpPromptArgument[];
|
|
116
|
+
}
|
|
117
|
+
/** One message from `prompts/get` — role + MCP content part(s). */
|
|
118
|
+
export interface McpPromptMessage {
|
|
119
|
+
role: "user" | "assistant";
|
|
120
|
+
content: unknown;
|
|
121
|
+
}
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @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
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type MemoryType } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal YAML-frontmatter reader. We intentionally don't pull in a YAML lib —
|
|
4
|
+
* the schema is fixed (name / description / type, all single-line strings), so
|
|
5
|
+
* a line-by-line parser is both smaller and safer (no surprise type coercion).
|
|
6
|
+
*/
|
|
7
|
+
export interface ParsedFrontmatter {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
type: MemoryType;
|
|
11
|
+
}
|
|
12
|
+
export interface ParsedMemoryFile {
|
|
13
|
+
frontmatter: ParsedFrontmatter;
|
|
14
|
+
body: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseMemoryFile(raw: string): ParsedMemoryFile | null;
|
|
17
|
+
export declare function formatMemoryFile(fm: ParsedFrontmatter, body: string): string;
|
|
18
|
+
//# sourceMappingURL=frontmatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontmatter.d.ts","sourceRoot":"","sources":["../../src/memory/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,iBAAiB,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CA8BpE;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isMemoryType } from "./types.js";
|
|
2
|
+
const FRONTMATTER_DELIM = "---";
|
|
3
|
+
export function parseMemoryFile(raw) {
|
|
4
|
+
const lines = raw.split(/\r?\n/);
|
|
5
|
+
if (lines[0]?.trim() !== FRONTMATTER_DELIM)
|
|
6
|
+
return null;
|
|
7
|
+
let end = -1;
|
|
8
|
+
for (let i = 1; i < lines.length; i++) {
|
|
9
|
+
if (lines[i]?.trim() === FRONTMATTER_DELIM) {
|
|
10
|
+
end = i;
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (end < 0)
|
|
15
|
+
return null;
|
|
16
|
+
const fm = {};
|
|
17
|
+
for (let i = 1; i < end; i++) {
|
|
18
|
+
const line = lines[i] ?? "";
|
|
19
|
+
if (!line.trim() || line.trim().startsWith("#"))
|
|
20
|
+
continue;
|
|
21
|
+
const colon = line.indexOf(":");
|
|
22
|
+
if (colon < 0)
|
|
23
|
+
continue;
|
|
24
|
+
const key = line.slice(0, colon).trim();
|
|
25
|
+
const value = unquote(line.slice(colon + 1).trim());
|
|
26
|
+
if (key)
|
|
27
|
+
fm[key] = value;
|
|
28
|
+
}
|
|
29
|
+
const name = fm["name"];
|
|
30
|
+
const description = fm["description"] ?? "";
|
|
31
|
+
const type = fm["type"];
|
|
32
|
+
if (!name || !type || !isMemoryType(type))
|
|
33
|
+
return null;
|
|
34
|
+
// Strip the leading blank line that follows the closing `---`, and the
|
|
35
|
+
// trailing newline that POSIX-friendly file writers always append, so callers
|
|
36
|
+
// get the *content* without round-trip artifacts.
|
|
37
|
+
const body = lines.slice(end + 1).join("\n").replace(/^\n+/, "").replace(/\n+$/g, "");
|
|
38
|
+
return { frontmatter: { name, description, type }, body };
|
|
39
|
+
}
|
|
40
|
+
export function formatMemoryFile(fm, body) {
|
|
41
|
+
// Frontmatter values are single-line — collapse whitespace so a stray newline
|
|
42
|
+
// in name/description can't break the YAML scalar. Body keeps its newlines.
|
|
43
|
+
const safeName = singleLine(fm.name);
|
|
44
|
+
const safeDescription = singleLine(fm.description);
|
|
45
|
+
const trimmedBody = body.replace(/\r/g, "").replace(/\n+$/g, "");
|
|
46
|
+
return [
|
|
47
|
+
FRONTMATTER_DELIM,
|
|
48
|
+
`name: ${quoteIfNeeded(safeName)}`,
|
|
49
|
+
`description: ${quoteIfNeeded(safeDescription)}`,
|
|
50
|
+
`type: ${fm.type}`,
|
|
51
|
+
FRONTMATTER_DELIM,
|
|
52
|
+
"",
|
|
53
|
+
trimmedBody,
|
|
54
|
+
"",
|
|
55
|
+
].join("\n");
|
|
56
|
+
}
|
|
57
|
+
function singleLine(s) {
|
|
58
|
+
return s.replace(/\s+/g, " ").trim();
|
|
59
|
+
}
|
|
60
|
+
function unquote(s) {
|
|
61
|
+
if (s.length >= 2 && s.startsWith("'") && s.endsWith("'")) {
|
|
62
|
+
// YAML single-quoted scalar: `''` is an escaped single quote.
|
|
63
|
+
return s.slice(1, -1).replace(/''/g, "'");
|
|
64
|
+
}
|
|
65
|
+
if (s.length >= 2 && s.startsWith('"') && s.endsWith('"')) {
|
|
66
|
+
return s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
67
|
+
}
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
70
|
+
function quoteIfNeeded(s) {
|
|
71
|
+
// Quote when YAML would otherwise misread the value: a leading special char or
|
|
72
|
+
// an internal colon. We always emit single-quoted form (only `'` itself needs
|
|
73
|
+
// escaping) so the unquote path doesn't have to handle YAML's full escape set.
|
|
74
|
+
if (s === "")
|
|
75
|
+
return "''";
|
|
76
|
+
if (/^[\s\-?:,\[\]{}#&*!|>'"%@`]/.test(s) || s.includes(":")) {
|
|
77
|
+
return `'${s.replace(/'/g, "''")}'`;
|
|
78
|
+
}
|
|
79
|
+
return s;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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,CAAC;IACtC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MEMORY_TYPES, MEMORY_SCOPES, isMemoryType, isMemoryScope, type MemoryType, type MemoryScope, type MemoryEntry, } from "./types.js";
|
|
2
|
+
export { MemoryStore, slugify, type MemoryStoreOptions, type SaveInput } from "./store.js";
|
|
3
|
+
export { parseMemoryFile, formatMemoryFile, type ParsedFrontmatter, type ParsedMemoryFile } from "./frontmatter.js";
|
|
4
|
+
export { memoryTools } from "./tools.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MEMORY_TYPES, MEMORY_SCOPES, isMemoryType, isMemoryScope, } from "./types.js";
|
|
2
|
+
export { MemoryStore, slugify } from "./store.js";
|
|
3
|
+
export { parseMemoryFile, formatMemoryFile } from "./frontmatter.js";
|
|
4
|
+
export { memoryTools } from "./tools.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,GAId,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,OAAO,EAA2C,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAiD,MAAM,kBAAkB,CAAC;AACpH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type MemoryEntry, type MemoryScope, type MemoryType } from "./types.js";
|
|
2
|
+
export interface MemoryStoreOptions {
|
|
3
|
+
workspaceRoot: string;
|
|
4
|
+
homeDir: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SaveInput {
|
|
7
|
+
type: MemoryType;
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
body: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Concurrency note (v1): mutations are sync-per-process but not locked across
|
|
14
|
+
* parallel CLI processes. Two simultaneous saves can interleave such that the
|
|
15
|
+
* last MEMORY.md index rewrite reflects a stale `list()`. At v1 scale (single
|
|
16
|
+
* interactive CLI, occasional `-p` invocation) the worst case is a stale
|
|
17
|
+
* index until the next mutation — not data loss, since each entry file write
|
|
18
|
+
* is atomic and slugs collision-suffix. A per-scope lock file is queued for
|
|
19
|
+
* v2 alongside the relevance ranker (when memory becomes hot-path enough to
|
|
20
|
+
* race on).
|
|
21
|
+
*/
|
|
22
|
+
export declare class MemoryStore {
|
|
23
|
+
private readonly dirs;
|
|
24
|
+
constructor(opts: MemoryStoreOptions);
|
|
25
|
+
/** Resolved on-disk directory for the given scope. Public so tools can show paths. */
|
|
26
|
+
dirFor(scope: MemoryScope): string;
|
|
27
|
+
list(scope?: MemoryScope): MemoryEntry[];
|
|
28
|
+
save(input: SaveInput, scope: MemoryScope): MemoryEntry;
|
|
29
|
+
/** Returns true if the slug existed and was removed. */
|
|
30
|
+
delete(slug: string, scope: MemoryScope): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a slug collision by walking `base`, `base-2`, `base-3`, ... until
|
|
33
|
+
* we find a slot that's either (a) empty or (b) holds an entry with the same
|
|
34
|
+
* name+type (in which case overwrite is the intended behavior — same memory
|
|
35
|
+
* being updated). This prevents two distinct memories whose names normalize
|
|
36
|
+
* to the same slug from silently clobbering each other.
|
|
37
|
+
*/
|
|
38
|
+
private uniqueSlugFor;
|
|
39
|
+
/** System-prompt injection block. Empty string when nothing is saved. */
|
|
40
|
+
asSystemContext(): string;
|
|
41
|
+
private rewriteIndex;
|
|
42
|
+
}
|
|
43
|
+
export declare function slugify(s: string): string;
|
|
44
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/memory/store.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AASpB,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8B;gBAEvC,IAAI,EAAE,kBAAkB;IAOpC,sFAAsF;IACtF,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM;IAIlC,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE;IA2BxC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,GAAG,WAAW;IAcvD,wDAAwD;IACxD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO;IAUjD;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAmBrB,yEAAyE;IACzE,eAAe,IAAI,MAAM;IAUzB,OAAO,CAAC,YAAY;CA+BrB;AA8DD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQzC"}
|