@phuetz/code-buddy 0.1.18 → 0.1.20
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/agent/background-tasks.d.ts +49 -0
- package/dist/agent/background-tasks.js +153 -0
- package/dist/agent/background-tasks.js.map +1 -0
- package/dist/agent/definitions/agent-definition-loader.d.ts +21 -0
- package/dist/agent/definitions/agent-definition-loader.js +161 -0
- package/dist/agent/definitions/agent-definition-loader.js.map +1 -0
- package/dist/agent/definitions/index.d.ts +1 -0
- package/dist/agent/definitions/index.js +2 -0
- package/dist/agent/definitions/index.js.map +1 -0
- package/dist/agent/extended-thinking.d.ts +64 -0
- package/dist/agent/extended-thinking.js +103 -0
- package/dist/agent/extended-thinking.js.map +1 -0
- package/dist/agent/prompt-suggestions.d.ts +55 -0
- package/dist/agent/prompt-suggestions.js +125 -0
- package/dist/agent/prompt-suggestions.js.map +1 -0
- package/dist/agent/rewind-manager.d.ts +59 -0
- package/dist/agent/rewind-manager.js +124 -0
- package/dist/agent/rewind-manager.js.map +1 -0
- package/dist/agent/teams/agent-team.d.ts +54 -0
- package/dist/agent/teams/agent-team.js +114 -0
- package/dist/agent/teams/agent-team.js.map +1 -0
- package/dist/agent/teams/index.d.ts +1 -0
- package/dist/agent/teams/index.js +2 -0
- package/dist/agent/teams/index.js.map +1 -0
- package/dist/agent/teams/team-v2.d.ts +166 -0
- package/dist/agent/teams/team-v2.js +376 -0
- package/dist/agent/teams/team-v2.js.map +1 -0
- package/dist/analytics/dashboard.js +1 -1
- package/dist/analytics/dashboard.js.map +1 -1
- package/dist/channels/imessage/index.d.ts +40 -0
- package/dist/channels/imessage/index.js +69 -0
- package/dist/channels/imessage/index.js.map +1 -0
- package/dist/channels/line/index.d.ts +36 -0
- package/dist/channels/line/index.js +71 -0
- package/dist/channels/line/index.js.map +1 -0
- package/dist/channels/mattermost/index.d.ts +34 -0
- package/dist/channels/mattermost/index.js +56 -0
- package/dist/channels/mattermost/index.js.map +1 -0
- package/dist/channels/nextcloud-talk/index.d.ts +37 -0
- package/dist/channels/nextcloud-talk/index.js +67 -0
- package/dist/channels/nextcloud-talk/index.js.map +1 -0
- package/dist/channels/niche-channels.d.ts +61 -0
- package/dist/channels/niche-channels.js +131 -0
- package/dist/channels/niche-channels.js.map +1 -0
- package/dist/channels/nostr/index.d.ts +30 -0
- package/dist/channels/nostr/index.js +68 -0
- package/dist/channels/nostr/index.js.map +1 -0
- package/dist/channels/twilio-voice/index.d.ts +37 -0
- package/dist/channels/twilio-voice/index.js +76 -0
- package/dist/channels/twilio-voice/index.js.map +1 -0
- package/dist/channels/whatsapp/index.js +0 -1
- package/dist/channels/whatsapp/index.js.map +1 -1
- package/dist/channels/zalo/index.d.ts +28 -0
- package/dist/channels/zalo/index.js +53 -0
- package/dist/channels/zalo/index.js.map +1 -0
- package/dist/cloud/cloud-sessions.d.ts +56 -0
- package/dist/cloud/cloud-sessions.js +187 -0
- package/dist/cloud/cloud-sessions.js.map +1 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.d.ts +1 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.js +24 -0
- package/dist/codebuddy/tool-definitions/advanced-tools.js.map +1 -1
- package/dist/codebuddy/tool-definitions/index.d.ts +1 -1
- package/dist/codebuddy/tool-definitions/index.js +1 -1
- package/dist/codebuddy/tool-definitions/index.js.map +1 -1
- package/dist/commands/delegate.js +2 -2
- package/dist/commands/delegate.js.map +1 -1
- package/dist/commands/features.d.ts +1 -1
- package/dist/commands/features.js +1 -1
- package/dist/commands/handlers/auth-handler.d.ts +32 -0
- package/dist/commands/handlers/auth-handler.js +137 -0
- package/dist/commands/handlers/auth-handler.js.map +1 -0
- package/dist/commands/handlers/context-handler.d.ts +46 -0
- package/dist/commands/handlers/context-handler.js +102 -0
- package/dist/commands/handlers/context-handler.js.map +1 -0
- package/dist/commands/handlers/core-handlers.js +1 -1
- package/dist/commands/handlers/core-handlers.js.map +1 -1
- package/dist/commands/handlers/keybindings-handler.d.ts +30 -0
- package/dist/commands/handlers/keybindings-handler.js +124 -0
- package/dist/commands/handlers/keybindings-handler.js.map +1 -0
- package/dist/commands/handlers/missing-handlers.js +15 -14
- package/dist/commands/handlers/missing-handlers.js.map +1 -1
- package/dist/commands/handlers/session-commands.d.ts +17 -0
- package/dist/commands/handlers/session-commands.js +119 -0
- package/dist/commands/handlers/session-commands.js.map +1 -0
- package/dist/commands/handlers/worktree-handlers.d.ts +1 -1
- package/dist/commands/handlers/worktree-handlers.js +2 -2
- package/dist/commands/slash/builtin-commands.js +2 -2
- package/dist/commands/slash/builtin-commands.js.map +1 -1
- package/dist/config/admin-config.d.ts +54 -0
- package/dist/config/admin-config.js +144 -0
- package/dist/config/admin-config.js.map +1 -0
- package/dist/config/advanced-config.d.ts +118 -0
- package/dist/config/advanced-config.js +364 -0
- package/dist/config/advanced-config.js.map +1 -0
- package/dist/config/constants.d.ts +2 -2
- package/dist/config/constants.js +2 -2
- package/dist/config/constants.js.map +1 -1
- package/dist/config/managed-policies.d.ts +50 -0
- package/dist/config/managed-policies.js +120 -0
- package/dist/config/managed-policies.js.map +1 -0
- package/dist/config/settings-hierarchy.d.ts +59 -0
- package/dist/config/settings-hierarchy.js +188 -0
- package/dist/config/settings-hierarchy.js.map +1 -0
- package/dist/config/toml-config.js +1 -1
- package/dist/config/toml-config.js.map +1 -1
- package/dist/config/tool-profiles.d.ts +37 -0
- package/dist/config/tool-profiles.js +150 -0
- package/dist/config/tool-profiles.js.map +1 -0
- package/dist/config/user-settings.d.ts +31 -0
- package/dist/config/user-settings.js +66 -0
- package/dist/config/user-settings.js.map +1 -0
- package/dist/context/context-files.d.ts +1 -1
- package/dist/context/context-files.js +3 -3
- package/dist/context/context-files.js.map +1 -1
- package/dist/context/partial-summarizer.d.ts +32 -0
- package/dist/context/partial-summarizer.js +144 -0
- package/dist/context/partial-summarizer.js.map +1 -0
- package/dist/desktop/desktop-app.d.ts +44 -0
- package/dist/desktop/desktop-app.js +136 -0
- package/dist/desktop/desktop-app.js.map +1 -0
- package/dist/features/index.d.ts +1 -1
- package/dist/features/index.js +2 -2
- package/dist/features/index.js.map +1 -1
- package/dist/git/worktree-sessions.d.ts +24 -0
- package/dist/git/worktree-sessions.js +93 -0
- package/dist/git/worktree-sessions.js.map +1 -0
- package/dist/hooks/advanced-hooks.d.ts +110 -0
- package/dist/hooks/advanced-hooks.js +256 -0
- package/dist/hooks/advanced-hooks.js.map +1 -0
- package/dist/hooks/async-hooks.d.ts +73 -0
- package/dist/hooks/async-hooks.js +213 -0
- package/dist/hooks/async-hooks.js.map +1 -0
- package/dist/hooks/env-persistence.d.ts +58 -0
- package/dist/hooks/env-persistence.js +195 -0
- package/dist/hooks/env-persistence.js.map +1 -0
- package/dist/hooks/hook-events.d.ts +36 -0
- package/dist/hooks/hook-events.js +55 -0
- package/dist/hooks/hook-events.js.map +1 -0
- package/dist/hooks/hook-system.js +1 -1
- package/dist/hooks/hook-system.js.map +1 -1
- package/dist/hooks/smart-hooks.d.ts +85 -0
- package/dist/hooks/smart-hooks.js +199 -0
- package/dist/hooks/smart-hooks.js.map +1 -0
- package/dist/ide/jetbrains-plugin.d.ts +55 -0
- package/dist/ide/jetbrains-plugin.js +156 -0
- package/dist/ide/jetbrains-plugin.js.map +1 -0
- package/dist/ide/vscode-extension.d.ts +94 -0
- package/dist/ide/vscode-extension.js +229 -0
- package/dist/ide/vscode-extension.js.map +1 -0
- package/dist/index.js +77 -3
- package/dist/index.js.map +1 -1
- package/dist/input/file-autocomplete.d.ts +42 -0
- package/dist/input/file-autocomplete.js +154 -0
- package/dist/input/file-autocomplete.js.map +1 -0
- package/dist/integrations/chrome-bridge.d.ts +90 -0
- package/dist/integrations/chrome-bridge.js +151 -0
- package/dist/integrations/chrome-bridge.js.map +1 -0
- package/dist/integrations/github-action-runner.d.ts +40 -0
- package/dist/integrations/github-action-runner.js +163 -0
- package/dist/integrations/github-action-runner.js.map +1 -0
- package/dist/integrations/github-actions.js +1 -1
- package/dist/integrations/github-actions.js.map +1 -1
- package/dist/integrations/gitlab-ci-runner.d.ts +34 -0
- package/dist/integrations/gitlab-ci-runner.js +104 -0
- package/dist/integrations/gitlab-ci-runner.js.map +1 -0
- package/dist/integrations/pr-session-linker.d.ts +44 -0
- package/dist/integrations/pr-session-linker.js +103 -0
- package/dist/integrations/pr-session-linker.js.map +1 -0
- package/dist/integrations/tailscale.d.ts +36 -0
- package/dist/integrations/tailscale.js +101 -0
- package/dist/integrations/tailscale.js.map +1 -0
- package/dist/lsp/lsp-client.d.ts +68 -0
- package/dist/lsp/lsp-client.js +182 -0
- package/dist/lsp/lsp-client.js.map +1 -0
- package/dist/lsp/server.js +3 -3
- package/dist/lsp/server.js.map +1 -1
- package/dist/mcp/connectors.d.ts +28 -0
- package/dist/mcp/connectors.js +148 -0
- package/dist/mcp/connectors.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -4
- package/dist/mcp/index.js +7 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/mcp-auto-discovery.d.ts +49 -0
- package/dist/mcp/mcp-auto-discovery.js +104 -0
- package/dist/mcp/mcp-auto-discovery.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +70 -0
- package/dist/mcp/mcp-server.js +374 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/memory/auto-memory.d.ts +53 -0
- package/dist/memory/auto-memory.js +250 -0
- package/dist/memory/auto-memory.js.map +1 -0
- package/dist/memory/hybrid-search.d.ts +51 -0
- package/dist/memory/hybrid-search.js +199 -0
- package/dist/memory/hybrid-search.js.map +1 -0
- package/dist/memory/memory-flush.d.ts +51 -0
- package/dist/memory/memory-flush.js +102 -0
- package/dist/memory/memory-flush.js.map +1 -0
- package/dist/memory/subagent-memory.d.ts +73 -0
- package/dist/memory/subagent-memory.js +172 -0
- package/dist/memory/subagent-memory.js.map +1 -0
- package/dist/nodes/device-node.d.ts +40 -0
- package/dist/nodes/device-node.js +117 -0
- package/dist/nodes/device-node.js.map +1 -0
- package/dist/observability/dashboard.d.ts +1 -1
- package/dist/observability/dashboard.js +2 -2
- package/dist/observability/dashboard.js.map +1 -1
- package/dist/offline/offline-mode.d.ts +1 -1
- package/dist/offline/offline-mode.js +1 -1
- package/dist/output/json-schema-output.d.ts +67 -0
- package/dist/output/json-schema-output.js +273 -0
- package/dist/output/json-schema-output.js.map +1 -0
- package/dist/persistence/session-picker.d.ts +22 -0
- package/dist/persistence/session-picker.js +47 -0
- package/dist/persistence/session-picker.js.map +1 -0
- package/dist/persistence/session-store.d.ts +11 -0
- package/dist/persistence/session-store.js +17 -0
- package/dist/persistence/session-store.js.map +1 -1
- package/dist/plugins/git-pinned-marketplace.d.ts +39 -0
- package/dist/plugins/git-pinned-marketplace.js +152 -0
- package/dist/plugins/git-pinned-marketplace.js.map +1 -0
- package/dist/plugins/marketplace.d.ts +1 -1
- package/dist/plugins/marketplace.js +1 -1
- package/dist/plugins/plugin-manifest.d.ts +116 -0
- package/dist/plugins/plugin-manifest.js +283 -0
- package/dist/plugins/plugin-manifest.js.map +1 -0
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.js +1 -1
- package/dist/providers/local-llm-provider.d.ts +1 -1
- package/dist/providers/local-llm-provider.js +1 -1
- package/dist/sandbox/os-sandbox.d.ts +49 -1
- package/dist/sandbox/os-sandbox.js +347 -6
- package/dist/sandbox/os-sandbox.js.map +1 -1
- package/dist/scripting/codebuddy-bindings.js +1 -1
- package/dist/scripting/codebuddy-bindings.js.map +1 -1
- package/dist/sdk/agent-sdk.d.ts +61 -0
- package/dist/sdk/agent-sdk.js +90 -0
- package/dist/sdk/agent-sdk.js.map +1 -0
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/permission-modes.d.ts +76 -0
- package/dist/security/permission-modes.js +195 -0
- package/dist/security/permission-modes.js.map +1 -0
- package/dist/security/permission-patterns.d.ts +61 -0
- package/dist/security/permission-patterns.js +171 -0
- package/dist/security/permission-patterns.js.map +1 -0
- package/dist/security/safe-binaries.d.ts +23 -0
- package/dist/security/safe-binaries.js +96 -0
- package/dist/security/safe-binaries.js.map +1 -0
- package/dist/security/sender-policies.d.ts +46 -0
- package/dist/security/sender-policies.js +90 -0
- package/dist/security/sender-policies.js.map +1 -0
- package/dist/server/dashboard.d.ts +53 -0
- package/dist/server/dashboard.js +93 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/services/system-prompt-override.d.ts +34 -0
- package/dist/services/system-prompt-override.js +64 -0
- package/dist/services/system-prompt-override.js.map +1 -0
- package/dist/skills/skill-enhancements.d.ts +37 -0
- package/dist/skills/skill-enhancements.js +69 -0
- package/dist/skills/skill-enhancements.js.map +1 -0
- package/dist/telemetry/otel-tracer.d.ts +98 -0
- package/dist/telemetry/otel-tracer.js +245 -0
- package/dist/telemetry/otel-tracer.js.map +1 -0
- package/dist/templates/export/html.template.js +2 -2
- package/dist/templates/export/markdown.template.js +1 -1
- package/dist/templates/export/markdown.template.js.map +1 -1
- package/dist/themes/default-themes.d.ts +1 -1
- package/dist/themes/default-themes.js +1 -1
- package/dist/themes/index.d.ts +1 -1
- package/dist/themes/index.js +1 -1
- package/dist/themes/theme-manager.d.ts +1 -1
- package/dist/themes/theme-manager.js +1 -1
- package/dist/themes/theme.d.ts +1 -1
- package/dist/themes/theme.js +1 -1
- package/dist/tools/browser-stub.d.ts +61 -0
- package/dist/tools/browser-stub.js +184 -0
- package/dist/tools/browser-stub.js.map +1 -0
- package/dist/tools/gateway-tool.d.ts +43 -0
- package/dist/tools/gateway-tool.js +92 -0
- package/dist/tools/gateway-tool.js.map +1 -0
- package/dist/tools/image-stub.d.ts +32 -0
- package/dist/tools/image-stub.js +97 -0
- package/dist/tools/image-stub.js.map +1 -0
- package/dist/tools/js-repl.d.ts +78 -0
- package/dist/tools/js-repl.js +280 -0
- package/dist/tools/js-repl.js.map +1 -0
- package/dist/tools/message-tool.d.ts +42 -0
- package/dist/tools/message-tool.js +113 -0
- package/dist/tools/message-tool.js.map +1 -0
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.js +1 -1
- package/dist/ui/app.js +1 -1
- package/dist/ui/app.js.map +1 -1
- package/dist/ui/cli-enhancements.d.ts +178 -0
- package/dist/ui/cli-enhancements.js +430 -0
- package/dist/ui/cli-enhancements.js.map +1 -0
- package/dist/ui/components/HelpSystem.d.ts +1 -1
- package/dist/ui/components/HelpSystem.js +1 -1
- package/dist/ui/context/theme-context.d.ts +1 -1
- package/dist/ui/context/theme-context.js +1 -1
- package/dist/ui/dashboard/dashboard.js +1 -1
- package/dist/ui/dashboard/dashboard.js.map +1 -1
- package/dist/ui/status-line.d.ts +90 -0
- package/dist/ui/status-line.js +160 -0
- package/dist/ui/status-line.js.map +1 -0
- package/dist/ui/terminal-enhancements.d.ts +34 -0
- package/dist/ui/terminal-enhancements.js +97 -0
- package/dist/ui/terminal-enhancements.js.map +1 -0
- package/dist/ui/ui-enhancements.d.ts +38 -0
- package/dist/ui/ui-enhancements.js +116 -0
- package/dist/ui/ui-enhancements.js.map +1 -0
- package/dist/undo/checkpoint-manager.d.ts +1 -1
- package/dist/undo/checkpoint-manager.js +1 -1
- package/dist/utils/codebuddy-home.d.ts +1 -1
- package/dist/utils/codebuddy-home.js +1 -1
- package/dist/utils/conversation-export.js +3 -3
- package/dist/utils/conversation-export.js.map +1 -1
- package/dist/utils/custom-commands.js +1 -1
- package/dist/utils/custom-instructions.js +4 -1
- package/dist/utils/custom-instructions.js.map +1 -1
- package/dist/utils/debug-logger.d.ts +1 -1
- package/dist/utils/debug-logger.js +1 -1
- package/dist/utils/errors.d.ts +2 -2
- package/dist/utils/errors.js +2 -2
- package/dist/utils/export-manager.js +3 -3
- package/dist/utils/export-manager.js.map +1 -1
- package/dist/utils/headless-output.js +1 -1
- package/dist/utils/headless-output.js.map +1 -1
- package/dist/utils/init-project.d.ts +1 -1
- package/dist/utils/init-project.js +20 -20
- package/dist/utils/init-project.js.map +1 -1
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/utils/output-schema-validator.d.ts +40 -0
- package/dist/utils/output-schema-validator.js +137 -0
- package/dist/utils/output-schema-validator.js.map +1 -0
- package/dist/utils/safety-misc.d.ts +24 -0
- package/dist/utils/safety-misc.js +91 -0
- package/dist/utils/safety-misc.js.map +1 -0
- package/dist/utils/session-enhancements.d.ts +40 -0
- package/dist/utils/session-enhancements.js +118 -0
- package/dist/utils/session-enhancements.js.map +1 -0
- package/dist/utils/shell-completions.js +6 -6
- package/dist/utils/shell-snapshot.d.ts +38 -0
- package/dist/utils/shell-snapshot.js +323 -0
- package/dist/utils/shell-snapshot.js.map +1 -0
- package/dist/utils/stream-json-formatter.d.ts +77 -0
- package/dist/utils/stream-json-formatter.js +61 -0
- package/dist/utils/stream-json-formatter.js.map +1 -0
- package/dist/utils/terminal-notifications.js +1 -1
- package/dist/utils/terminal-notifications.js.map +1 -1
- package/dist/workflows/lobster-engine.d.ts +43 -0
- package/dist/workflows/lobster-engine.js +167 -0
- package/dist/workflows/lobster-engine.js.map +1 -0
- package/package.json +3 -6
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Auto-Discovery
|
|
3
|
+
*
|
|
4
|
+
* Defers loading of MCP tool descriptions when they would consume
|
|
5
|
+
* too much of the context window, using on-demand search instead.
|
|
6
|
+
*/
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// MCPAutoDiscovery
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export class MCPAutoDiscovery {
|
|
12
|
+
thresholdPercentage = 10;
|
|
13
|
+
loadedTools = [];
|
|
14
|
+
deferredTools = [];
|
|
15
|
+
/**
|
|
16
|
+
* Determine if tool descriptions should be deferred
|
|
17
|
+
* Returns true if total description length exceeds threshold % of context window
|
|
18
|
+
*/
|
|
19
|
+
shouldDeferLoading(toolDescriptions, contextWindowSize) {
|
|
20
|
+
const totalChars = toolDescriptions.reduce((sum, d) => sum + d.length, 0);
|
|
21
|
+
// Rough token estimate: ~4 chars per token
|
|
22
|
+
const estimatedTokens = totalChars / 4;
|
|
23
|
+
const threshold = (this.thresholdPercentage / 100) * contextWindowSize;
|
|
24
|
+
const shouldDefer = estimatedTokens > threshold;
|
|
25
|
+
logger.debug(`MCP auto-discovery: ${estimatedTokens} estimated tokens vs ${threshold} threshold → ${shouldDefer ? 'defer' : 'load'}`);
|
|
26
|
+
return shouldDefer;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Search deferred tools by relevance to a query
|
|
30
|
+
*/
|
|
31
|
+
searchTools(query, allTools) {
|
|
32
|
+
const queryLower = query.toLowerCase();
|
|
33
|
+
const queryWords = queryLower.split(/\s+/).filter(w => w.length > 2);
|
|
34
|
+
const scored = allTools.map(tool => {
|
|
35
|
+
let score = 0;
|
|
36
|
+
const nameLower = tool.name.toLowerCase();
|
|
37
|
+
const descLower = tool.description.toLowerCase();
|
|
38
|
+
// Exact name match
|
|
39
|
+
if (nameLower === queryLower)
|
|
40
|
+
score += 10;
|
|
41
|
+
// Name contains query
|
|
42
|
+
if (nameLower.includes(queryLower))
|
|
43
|
+
score += 5;
|
|
44
|
+
// Description contains query
|
|
45
|
+
if (descLower.includes(queryLower))
|
|
46
|
+
score += 3;
|
|
47
|
+
// Word-level matching
|
|
48
|
+
for (const word of queryWords) {
|
|
49
|
+
if (nameLower.includes(word))
|
|
50
|
+
score += 2;
|
|
51
|
+
if (descLower.includes(word))
|
|
52
|
+
score += 1;
|
|
53
|
+
}
|
|
54
|
+
return { tool, score };
|
|
55
|
+
});
|
|
56
|
+
return scored
|
|
57
|
+
.filter(s => s.score > 0)
|
|
58
|
+
.sort((a, b) => b.score - a.score)
|
|
59
|
+
.map(s => s.tool);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get currently loaded tool definitions
|
|
63
|
+
*/
|
|
64
|
+
getLoadedTools() {
|
|
65
|
+
return [...this.loadedTools];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get deferred tool names
|
|
69
|
+
*/
|
|
70
|
+
getDeferredTools() {
|
|
71
|
+
return this.deferredTools.map(t => t.name);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set the threshold percentage for deferring
|
|
75
|
+
*/
|
|
76
|
+
setThreshold(percentage) {
|
|
77
|
+
if (percentage < 0 || percentage > 100) {
|
|
78
|
+
throw new Error('Threshold must be between 0 and 100');
|
|
79
|
+
}
|
|
80
|
+
this.thresholdPercentage = percentage;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get current threshold
|
|
84
|
+
*/
|
|
85
|
+
getThreshold() {
|
|
86
|
+
return this.thresholdPercentage;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Partition tools into loaded and deferred sets
|
|
90
|
+
*/
|
|
91
|
+
partitionTools(tools, contextWindowSize) {
|
|
92
|
+
const descriptions = tools.map(t => t.description);
|
|
93
|
+
if (!this.shouldDeferLoading(descriptions, contextWindowSize)) {
|
|
94
|
+
this.loadedTools = [...tools];
|
|
95
|
+
this.deferredTools = [];
|
|
96
|
+
return { loaded: this.loadedTools, deferred: [] };
|
|
97
|
+
}
|
|
98
|
+
// When deferring, load no tools eagerly and defer all
|
|
99
|
+
this.loadedTools = [];
|
|
100
|
+
this.deferredTools = [...tools];
|
|
101
|
+
return { loaded: [], deferred: [...tools] };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=mcp-auto-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-auto-discovery.js","sourceRoot":"","sources":["../../src/mcp/mcp-auto-discovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAa5C,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,MAAM,OAAO,gBAAgB;IACnB,mBAAmB,GAAW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ED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,KAAoB,EAAE,iBAAyB;QAI5D,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,CAAC,EAAE,CAAC;YAC9D,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAC9B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;YACxB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;QAED,sDAAsD;QACtD,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QAChC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server - Expose Code Buddy tools via the Model Context Protocol
|
|
3
|
+
*
|
|
4
|
+
* Allows Code Buddy to act as a tool provider for other AI agents
|
|
5
|
+
* (VS Code, Cursor, Claude Desktop, etc.) over stdio transport.
|
|
6
|
+
*
|
|
7
|
+
* Exposed tools:
|
|
8
|
+
* - read_file: Read file contents
|
|
9
|
+
* - write_file: Write/create a file
|
|
10
|
+
* - edit_file: String replacement editing
|
|
11
|
+
* - bash: Execute shell commands
|
|
12
|
+
* - search_files: Search file contents (ripgrep-based)
|
|
13
|
+
* - list_files: List directory contents
|
|
14
|
+
* - git: Git operations (status, diff, log, add, commit, etc.)
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Tool definition metadata for listing purposes.
|
|
18
|
+
*/
|
|
19
|
+
export interface MCPToolDefinition {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* CodeBuddyMCPServer - MCP server that exposes Code Buddy tools.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* const server = new CodeBuddyMCPServer();
|
|
29
|
+
* await server.start(); // Blocks on stdio transport
|
|
30
|
+
* await server.stop(); // Clean shutdown
|
|
31
|
+
*/
|
|
32
|
+
export declare class CodeBuddyMCPServer {
|
|
33
|
+
private mcpServer;
|
|
34
|
+
private transport;
|
|
35
|
+
private running;
|
|
36
|
+
private textEditor;
|
|
37
|
+
private searchTool;
|
|
38
|
+
private gitTool;
|
|
39
|
+
private bashTool;
|
|
40
|
+
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Get the list of tools exposed by this MCP server.
|
|
43
|
+
*/
|
|
44
|
+
static getToolDefinitions(): MCPToolDefinition[];
|
|
45
|
+
/**
|
|
46
|
+
* Lazily initialize tool instances on first use.
|
|
47
|
+
*/
|
|
48
|
+
private ensureTools;
|
|
49
|
+
/**
|
|
50
|
+
* Convert a ToolResult to MCP CallToolResult format.
|
|
51
|
+
*/
|
|
52
|
+
private formatResult;
|
|
53
|
+
/**
|
|
54
|
+
* Register all Code Buddy tools with the MCP server.
|
|
55
|
+
*/
|
|
56
|
+
private registerTools;
|
|
57
|
+
/**
|
|
58
|
+
* Start the MCP server over stdio transport.
|
|
59
|
+
* This method blocks until the transport is closed.
|
|
60
|
+
*/
|
|
61
|
+
start(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Stop the MCP server and close the transport.
|
|
64
|
+
*/
|
|
65
|
+
stop(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the server is currently running.
|
|
68
|
+
*/
|
|
69
|
+
isRunning(): boolean;
|
|
70
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server - Expose Code Buddy tools via the Model Context Protocol
|
|
3
|
+
*
|
|
4
|
+
* Allows Code Buddy to act as a tool provider for other AI agents
|
|
5
|
+
* (VS Code, Cursor, Claude Desktop, etc.) over stdio transport.
|
|
6
|
+
*
|
|
7
|
+
* Exposed tools:
|
|
8
|
+
* - read_file: Read file contents
|
|
9
|
+
* - write_file: Write/create a file
|
|
10
|
+
* - edit_file: String replacement editing
|
|
11
|
+
* - bash: Execute shell commands
|
|
12
|
+
* - search_files: Search file contents (ripgrep-based)
|
|
13
|
+
* - list_files: List directory contents
|
|
14
|
+
* - git: Git operations (status, diff, log, add, commit, etc.)
|
|
15
|
+
*/
|
|
16
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
17
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import * as path from 'path';
|
|
20
|
+
import * as fs from 'fs';
|
|
21
|
+
// Read version from package.json (avoid import.meta.url for ts-jest compat)
|
|
22
|
+
let packageVersion = '0.1.0';
|
|
23
|
+
try {
|
|
24
|
+
const pkgPath = path.resolve(__dirname, '../../package.json');
|
|
25
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
26
|
+
packageVersion = pkgJson.version || packageVersion;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Ignore - use default version
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* CodeBuddyMCPServer - MCP server that exposes Code Buddy tools.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* const server = new CodeBuddyMCPServer();
|
|
36
|
+
* await server.start(); // Blocks on stdio transport
|
|
37
|
+
* await server.stop(); // Clean shutdown
|
|
38
|
+
*/
|
|
39
|
+
export class CodeBuddyMCPServer {
|
|
40
|
+
mcpServer;
|
|
41
|
+
transport = null;
|
|
42
|
+
running = false;
|
|
43
|
+
// Lazily initialized tool instances
|
|
44
|
+
textEditor = null;
|
|
45
|
+
searchTool = null;
|
|
46
|
+
gitTool = null;
|
|
47
|
+
bashTool = null;
|
|
48
|
+
constructor() {
|
|
49
|
+
this.mcpServer = new McpServer({
|
|
50
|
+
name: 'code-buddy',
|
|
51
|
+
version: packageVersion,
|
|
52
|
+
}, {
|
|
53
|
+
capabilities: {
|
|
54
|
+
tools: {},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
this.registerTools();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the list of tools exposed by this MCP server.
|
|
61
|
+
*/
|
|
62
|
+
static getToolDefinitions() {
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
name: 'read_file',
|
|
66
|
+
description: 'Read the contents of a file. Returns the file content with line numbers.',
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
path: { type: 'string', description: 'Absolute or relative path to the file to read' },
|
|
71
|
+
start_line: { type: 'number', description: 'Optional start line (1-indexed)' },
|
|
72
|
+
end_line: { type: 'number', description: 'Optional end line (1-indexed)' },
|
|
73
|
+
},
|
|
74
|
+
required: ['path'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'write_file',
|
|
79
|
+
description: 'Write content to a file. Creates the file if it does not exist, or overwrites it if it does.',
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
path: { type: 'string', description: 'Absolute or relative path to the file to write' },
|
|
84
|
+
content: { type: 'string', description: 'The content to write to the file' },
|
|
85
|
+
},
|
|
86
|
+
required: ['path', 'content'],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'edit_file',
|
|
91
|
+
description: 'Edit a file by replacing an exact string match with new content. The old_string must match exactly one location in the file.',
|
|
92
|
+
inputSchema: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
path: { type: 'string', description: 'Path to the file to edit' },
|
|
96
|
+
old_string: { type: 'string', description: 'The exact string to find and replace' },
|
|
97
|
+
new_string: { type: 'string', description: 'The replacement string' },
|
|
98
|
+
},
|
|
99
|
+
required: ['path', 'old_string', 'new_string'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'bash',
|
|
104
|
+
description: 'Execute a shell command and return its output. Use for running scripts, installing packages, or any terminal operation.',
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
command: { type: 'string', description: 'The shell command to execute' },
|
|
109
|
+
timeout: { type: 'number', description: 'Timeout in milliseconds (default: 30000)' },
|
|
110
|
+
},
|
|
111
|
+
required: ['command'],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'search_files',
|
|
116
|
+
description: 'Search for text patterns in files using ripgrep. Supports regex patterns and file type filtering.',
|
|
117
|
+
inputSchema: {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
query: { type: 'string', description: 'The search query (text or regex pattern)' },
|
|
121
|
+
path: { type: 'string', description: 'Directory to search in (defaults to cwd)' },
|
|
122
|
+
include_pattern: { type: 'string', description: 'Glob pattern for files to include (e.g., "*.ts")' },
|
|
123
|
+
case_sensitive: { type: 'boolean', description: 'Whether the search is case-sensitive (default: false)' },
|
|
124
|
+
max_results: { type: 'number', description: 'Maximum number of results to return (default: 50)' },
|
|
125
|
+
},
|
|
126
|
+
required: ['query'],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'list_files',
|
|
131
|
+
description: 'List files and directories at a given path. Returns names with type indicators (/ for directories).',
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {
|
|
135
|
+
path: { type: 'string', description: 'Directory path to list (defaults to cwd)' },
|
|
136
|
+
},
|
|
137
|
+
required: [],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'git',
|
|
142
|
+
description: 'Execute git operations: status, diff, log, add, commit, branch, checkout, etc.',
|
|
143
|
+
inputSchema: {
|
|
144
|
+
type: 'object',
|
|
145
|
+
properties: {
|
|
146
|
+
subcommand: {
|
|
147
|
+
type: 'string',
|
|
148
|
+
description: 'Git subcommand to run',
|
|
149
|
+
enum: ['status', 'diff', 'log', 'add', 'commit', 'branch', 'checkout'],
|
|
150
|
+
},
|
|
151
|
+
args: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
description: 'Arguments for the git subcommand',
|
|
154
|
+
properties: {
|
|
155
|
+
files: { type: 'array', items: { type: 'string' }, description: 'Files for add/diff' },
|
|
156
|
+
message: { type: 'string', description: 'Commit message' },
|
|
157
|
+
staged: { type: 'boolean', description: 'Show staged changes (for diff)' },
|
|
158
|
+
count: { type: 'number', description: 'Number of log entries' },
|
|
159
|
+
branch_name: { type: 'string', description: 'Branch name for branch/checkout' },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
required: ['subcommand'],
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Lazily initialize tool instances on first use.
|
|
170
|
+
*/
|
|
171
|
+
async ensureTools() {
|
|
172
|
+
if (this.textEditor)
|
|
173
|
+
return;
|
|
174
|
+
const [{ TextEditorTool }, { SearchTool }, { GitTool }, { BashTool },] = await Promise.all([
|
|
175
|
+
import('../tools/text-editor.js'),
|
|
176
|
+
import('../tools/search.js'),
|
|
177
|
+
import('../tools/git-tool.js'),
|
|
178
|
+
import('../tools/bash/index.js'),
|
|
179
|
+
]);
|
|
180
|
+
// Enable auto-approve for MCP server mode (no interactive confirmation)
|
|
181
|
+
const { ConfirmationService } = await import('../utils/confirmation-service.js');
|
|
182
|
+
const confirmService = ConfirmationService.getInstance();
|
|
183
|
+
confirmService.setSessionFlag('allOperations', true);
|
|
184
|
+
this.textEditor = new TextEditorTool();
|
|
185
|
+
this.searchTool = new SearchTool();
|
|
186
|
+
this.gitTool = new GitTool();
|
|
187
|
+
this.bashTool = new BashTool();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Convert a ToolResult to MCP CallToolResult format.
|
|
191
|
+
*/
|
|
192
|
+
formatResult(result) {
|
|
193
|
+
const text = result.success
|
|
194
|
+
? (result.output || result.content || 'Done')
|
|
195
|
+
: (result.error || 'Unknown error');
|
|
196
|
+
return {
|
|
197
|
+
content: [{ type: 'text', text }],
|
|
198
|
+
isError: !result.success,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Register all Code Buddy tools with the MCP server.
|
|
203
|
+
*/
|
|
204
|
+
registerTools() {
|
|
205
|
+
// read_file
|
|
206
|
+
this.mcpServer.tool('read_file', 'Read the contents of a file. Returns the file content with line numbers.', {
|
|
207
|
+
path: z.string().describe('Absolute or relative path to the file to read'),
|
|
208
|
+
start_line: z.number().optional().describe('Optional start line (1-indexed)'),
|
|
209
|
+
end_line: z.number().optional().describe('Optional end line (1-indexed)'),
|
|
210
|
+
}, async (args) => {
|
|
211
|
+
await this.ensureTools();
|
|
212
|
+
const viewRange = (args.start_line !== undefined && args.end_line !== undefined)
|
|
213
|
+
? [args.start_line, args.end_line]
|
|
214
|
+
: undefined;
|
|
215
|
+
const result = await this.textEditor.view(args.path, viewRange);
|
|
216
|
+
return this.formatResult(result);
|
|
217
|
+
});
|
|
218
|
+
// write_file
|
|
219
|
+
this.mcpServer.tool('write_file', 'Write content to a file. Creates the file if it does not exist, or overwrites it.', {
|
|
220
|
+
path: z.string().describe('Absolute or relative path to the file to write'),
|
|
221
|
+
content: z.string().describe('The content to write to the file'),
|
|
222
|
+
}, async (args) => {
|
|
223
|
+
await this.ensureTools();
|
|
224
|
+
const result = await this.textEditor.create(args.path, args.content);
|
|
225
|
+
return this.formatResult(result);
|
|
226
|
+
});
|
|
227
|
+
// edit_file
|
|
228
|
+
this.mcpServer.tool('edit_file', 'Edit a file by replacing an exact string match with new content.', {
|
|
229
|
+
path: z.string().describe('Path to the file to edit'),
|
|
230
|
+
old_string: z.string().describe('The exact string to find and replace'),
|
|
231
|
+
new_string: z.string().describe('The replacement string'),
|
|
232
|
+
}, async (args) => {
|
|
233
|
+
await this.ensureTools();
|
|
234
|
+
const result = await this.textEditor.strReplace(args.path, args.old_string, args.new_string);
|
|
235
|
+
return this.formatResult(result);
|
|
236
|
+
});
|
|
237
|
+
// bash
|
|
238
|
+
this.mcpServer.tool('bash', 'Execute a shell command and return its output.', {
|
|
239
|
+
command: z.string().describe('The shell command to execute'),
|
|
240
|
+
timeout: z.number().optional().describe('Timeout in milliseconds (default: 30000)'),
|
|
241
|
+
}, async (args) => {
|
|
242
|
+
await this.ensureTools();
|
|
243
|
+
const result = await this.bashTool.execute(args.command, args.timeout ?? 30000);
|
|
244
|
+
return this.formatResult(result);
|
|
245
|
+
});
|
|
246
|
+
// search_files
|
|
247
|
+
this.mcpServer.tool('search_files', 'Search for text patterns in files using ripgrep.', {
|
|
248
|
+
query: z.string().describe('The search query (text or regex pattern)'),
|
|
249
|
+
path: z.string().optional().describe('Directory to search in (defaults to cwd)'),
|
|
250
|
+
include_pattern: z.string().optional().describe('Glob pattern for files to include (e.g., "*.ts")'),
|
|
251
|
+
case_sensitive: z.boolean().optional().describe('Whether the search is case-sensitive (default: false)'),
|
|
252
|
+
max_results: z.number().optional().describe('Maximum number of results to return (default: 50)'),
|
|
253
|
+
}, async (args) => {
|
|
254
|
+
await this.ensureTools();
|
|
255
|
+
const result = await this.searchTool.search(args.query, {
|
|
256
|
+
searchType: 'text',
|
|
257
|
+
includePattern: args.include_pattern,
|
|
258
|
+
caseSensitive: args.case_sensitive ?? false,
|
|
259
|
+
maxResults: args.max_results ?? 50,
|
|
260
|
+
});
|
|
261
|
+
return this.formatResult(result);
|
|
262
|
+
});
|
|
263
|
+
// list_files
|
|
264
|
+
this.mcpServer.tool('list_files', 'List files and directories at a given path.', {
|
|
265
|
+
path: z.string().optional().describe('Directory path to list (defaults to cwd)'),
|
|
266
|
+
}, async (args) => {
|
|
267
|
+
await this.ensureTools();
|
|
268
|
+
const targetPath = args.path || process.cwd();
|
|
269
|
+
const result = await this.textEditor.view(targetPath);
|
|
270
|
+
return this.formatResult(result);
|
|
271
|
+
});
|
|
272
|
+
// git
|
|
273
|
+
this.mcpServer.tool('git', 'Execute git operations: status, diff, log, add, commit, branch, checkout.', {
|
|
274
|
+
subcommand: z.enum(['status', 'diff', 'log', 'add', 'commit', 'branch', 'checkout'])
|
|
275
|
+
.describe('Git subcommand to run'),
|
|
276
|
+
args: z.object({
|
|
277
|
+
files: z.array(z.string()).optional().describe('Files for add/diff'),
|
|
278
|
+
message: z.string().optional().describe('Commit message'),
|
|
279
|
+
staged: z.boolean().optional().describe('Show staged changes (for diff)'),
|
|
280
|
+
count: z.number().optional().describe('Number of log entries'),
|
|
281
|
+
branch_name: z.string().optional().describe('Branch name for branch/checkout'),
|
|
282
|
+
}).optional().describe('Arguments for the git subcommand'),
|
|
283
|
+
}, async (args) => {
|
|
284
|
+
await this.ensureTools();
|
|
285
|
+
const git = this.gitTool;
|
|
286
|
+
const subArgs = args.args || {};
|
|
287
|
+
try {
|
|
288
|
+
switch (args.subcommand) {
|
|
289
|
+
case 'status': {
|
|
290
|
+
const status = await git.getStatus();
|
|
291
|
+
const lines = [
|
|
292
|
+
`Branch: ${status.branch}`,
|
|
293
|
+
`Ahead: ${status.ahead}, Behind: ${status.behind}`,
|
|
294
|
+
];
|
|
295
|
+
if (status.staged.length > 0)
|
|
296
|
+
lines.push(`Staged:\n ${status.staged.join('\n ')}`);
|
|
297
|
+
if (status.unstaged.length > 0)
|
|
298
|
+
lines.push(`Unstaged:\n ${status.unstaged.join('\n ')}`);
|
|
299
|
+
if (status.untracked.length > 0)
|
|
300
|
+
lines.push(`Untracked:\n ${status.untracked.join('\n ')}`);
|
|
301
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
302
|
+
}
|
|
303
|
+
case 'diff': {
|
|
304
|
+
const diff = await git.getDiff(subArgs.staged ?? false);
|
|
305
|
+
return { content: [{ type: 'text', text: diff || 'No changes' }] };
|
|
306
|
+
}
|
|
307
|
+
case 'log': {
|
|
308
|
+
const log = await git.getLog(subArgs.count ?? 10);
|
|
309
|
+
return { content: [{ type: 'text', text: log || 'No commits' }] };
|
|
310
|
+
}
|
|
311
|
+
case 'add': {
|
|
312
|
+
const files = subArgs.files;
|
|
313
|
+
const result = await git.add(files && files.length > 0 ? files : 'all');
|
|
314
|
+
return this.formatResult(result);
|
|
315
|
+
}
|
|
316
|
+
case 'commit': {
|
|
317
|
+
if (!subArgs.message) {
|
|
318
|
+
return { content: [{ type: 'text', text: 'Error: commit message is required' }], isError: true };
|
|
319
|
+
}
|
|
320
|
+
const result = await git.commit(subArgs.message);
|
|
321
|
+
return this.formatResult(result);
|
|
322
|
+
}
|
|
323
|
+
case 'branch': {
|
|
324
|
+
// List branches or create one
|
|
325
|
+
const result = await git.branch(subArgs.branch_name);
|
|
326
|
+
return this.formatResult(result);
|
|
327
|
+
}
|
|
328
|
+
case 'checkout': {
|
|
329
|
+
if (!subArgs.branch_name) {
|
|
330
|
+
return { content: [{ type: 'text', text: 'Error: branch_name is required for checkout' }], isError: true };
|
|
331
|
+
}
|
|
332
|
+
const result = await git.checkout(subArgs.branch_name);
|
|
333
|
+
return this.formatResult(result);
|
|
334
|
+
}
|
|
335
|
+
default:
|
|
336
|
+
return { content: [{ type: 'text', text: `Unknown git subcommand: ${args.subcommand}` }], isError: true };
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
341
|
+
return { content: [{ type: 'text', text: `Git error: ${message}` }], isError: true };
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Start the MCP server over stdio transport.
|
|
347
|
+
* This method blocks until the transport is closed.
|
|
348
|
+
*/
|
|
349
|
+
async start() {
|
|
350
|
+
if (this.running) {
|
|
351
|
+
throw new Error('MCP server is already running');
|
|
352
|
+
}
|
|
353
|
+
this.transport = new StdioServerTransport();
|
|
354
|
+
await this.mcpServer.connect(this.transport);
|
|
355
|
+
this.running = true;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Stop the MCP server and close the transport.
|
|
359
|
+
*/
|
|
360
|
+
async stop() {
|
|
361
|
+
if (!this.running)
|
|
362
|
+
return;
|
|
363
|
+
await this.mcpServer.close();
|
|
364
|
+
this.transport = null;
|
|
365
|
+
this.running = false;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Whether the server is currently running.
|
|
369
|
+
*/
|
|
370
|
+
isRunning() {
|
|
371
|
+
return this.running;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/mcp/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,4EAA4E;AAC5E,IAAI,cAAc,GAAG,OAAO,CAAC;AAC7B,IAAI,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC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C,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC5C,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAE1B,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Memory System
|
|
3
|
+
*
|
|
4
|
+
* Automatically extracts and stores memories from agent interactions.
|
|
5
|
+
* Supports three scopes: user, project, and local.
|
|
6
|
+
* Memories are stored in MEMORY.md files at scope-appropriate paths.
|
|
7
|
+
*/
|
|
8
|
+
export type MemoryScope = 'user' | 'project' | 'local';
|
|
9
|
+
export interface MemoryEntry {
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
scope: MemoryScope;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
source: 'agent' | 'user';
|
|
15
|
+
}
|
|
16
|
+
export declare class AutoMemoryManager {
|
|
17
|
+
private projectDir;
|
|
18
|
+
private memories;
|
|
19
|
+
constructor(projectDir?: string);
|
|
20
|
+
/**
|
|
21
|
+
* Analyze context and response for potential memories to extract
|
|
22
|
+
*/
|
|
23
|
+
analyzeForMemories(context: string, response: string): MemoryEntry[];
|
|
24
|
+
/**
|
|
25
|
+
* Write a memory entry to the appropriate MEMORY.md file
|
|
26
|
+
*/
|
|
27
|
+
writeMemory(key: string, value: string, scope?: MemoryScope): void;
|
|
28
|
+
/**
|
|
29
|
+
* Search all scoped memory files for relevant entries
|
|
30
|
+
*/
|
|
31
|
+
recallMemories(context: string): MemoryEntry[];
|
|
32
|
+
/**
|
|
33
|
+
* Get the file path for a given memory scope
|
|
34
|
+
*/
|
|
35
|
+
getMemoryPath(scope: MemoryScope): string;
|
|
36
|
+
/**
|
|
37
|
+
* List all memories, optionally filtered by scope
|
|
38
|
+
*/
|
|
39
|
+
listMemories(scope?: MemoryScope): MemoryEntry[];
|
|
40
|
+
/**
|
|
41
|
+
* Delete a memory entry by key and optional scope
|
|
42
|
+
*/
|
|
43
|
+
deleteMemory(key: string, scope?: MemoryScope): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get a summary of recalled memories count
|
|
46
|
+
*/
|
|
47
|
+
getRecallSummary(): string;
|
|
48
|
+
private loadAllMemories;
|
|
49
|
+
private loadMemoryFile;
|
|
50
|
+
private saveMemoryFile;
|
|
51
|
+
}
|
|
52
|
+
export declare function getAutoMemoryManager(projectDir?: string): AutoMemoryManager;
|
|
53
|
+
export declare function resetAutoMemory(): void;
|