codeep 1.3.41 → 2.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/README.md +208 -0
- package/dist/acp/commands.js +770 -7
- package/dist/acp/protocol.d.ts +11 -2
- package/dist/acp/server.js +179 -11
- package/dist/acp/session.d.ts +3 -0
- package/dist/acp/session.js +5 -0
- package/dist/api/index.js +39 -6
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.js +46 -1
- package/dist/config/providers.js +76 -1
- package/dist/renderer/App.d.ts +12 -0
- package/dist/renderer/App.js +96 -4
- package/dist/renderer/agentExecution.js +5 -0
- package/dist/renderer/commands.js +348 -2
- package/dist/renderer/components/Login.d.ts +1 -0
- package/dist/renderer/components/Login.js +24 -9
- package/dist/renderer/handlers.d.ts +11 -1
- package/dist/renderer/handlers.js +30 -0
- package/dist/renderer/main.js +73 -0
- package/dist/utils/agent.d.ts +17 -0
- package/dist/utils/agent.js +91 -7
- package/dist/utils/agentChat.d.ts +10 -2
- package/dist/utils/agentChat.js +48 -9
- package/dist/utils/agentStream.js +6 -2
- package/dist/utils/checkpoints.d.ts +93 -0
- package/dist/utils/checkpoints.js +205 -0
- package/dist/utils/context.d.ts +24 -0
- package/dist/utils/context.js +57 -0
- package/dist/utils/customCommands.d.ts +62 -0
- package/dist/utils/customCommands.js +201 -0
- package/dist/utils/hooks.d.ts +97 -0
- package/dist/utils/hooks.js +223 -0
- package/dist/utils/mcpClient.d.ts +229 -0
- package/dist/utils/mcpClient.js +497 -0
- package/dist/utils/mcpConfig.d.ts +55 -0
- package/dist/utils/mcpConfig.js +177 -0
- package/dist/utils/mcpMarketplace.d.ts +49 -0
- package/dist/utils/mcpMarketplace.js +175 -0
- package/dist/utils/mcpRegistry.d.ts +129 -0
- package/dist/utils/mcpRegistry.js +427 -0
- package/dist/utils/mcpSamplingBridge.d.ts +32 -0
- package/dist/utils/mcpSamplingBridge.js +88 -0
- package/dist/utils/mcpStreamableHttp.d.ts +65 -0
- package/dist/utils/mcpStreamableHttp.js +207 -0
- package/dist/utils/openrouterPrefs.d.ts +36 -0
- package/dist/utils/openrouterPrefs.js +83 -0
- package/dist/utils/skillBundles.d.ts +84 -0
- package/dist/utils/skillBundles.js +257 -0
- package/dist/utils/skillBundlesCloud.d.ts +66 -0
- package/dist/utils/skillBundlesCloud.js +196 -0
- package/dist/utils/tokenTracker.d.ts +14 -2
- package/dist/utils/tokenTracker.js +59 -45
- package/dist/utils/toolExecution.d.ts +17 -1
- package/dist/utils/toolExecution.js +184 -6
- package/dist/utils/tools.d.ts +22 -6
- package/dist/utils/tools.js +83 -8
- package/package.json +3 -2
- package/bin/codeep-macos-arm64 +0 -0
- package/bin/codeep-macos-x64 +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MCP (Model Context Protocol) stdio client.
|
|
3
|
+
*
|
|
4
|
+
* Each `McpClient` instance owns one child process running an MCP server
|
|
5
|
+
* (e.g. `npx @modelcontextprotocol/server-filesystem /some/path`). It speaks
|
|
6
|
+
* JSON-RPC 2.0 over stdio per the MCP spec, performs the
|
|
7
|
+
* initialize → tools/list handshake, and exposes a `callTool` method that
|
|
8
|
+
* agent tool dispatch routes through.
|
|
9
|
+
*
|
|
10
|
+
* Scope of this MVP:
|
|
11
|
+
* - initialize + tools/list discovery
|
|
12
|
+
* - tools/call forwarding
|
|
13
|
+
* - stop() kills the process and rejects in-flight requests
|
|
14
|
+
*
|
|
15
|
+
* NOT covered yet (defer to a future iteration):
|
|
16
|
+
* - resources / prompts / sampling MCP primitives
|
|
17
|
+
* - capability negotiation beyond "we want tools"
|
|
18
|
+
* - server-initiated requests (we ignore them)
|
|
19
|
+
* - reconnect on crash (process exit is fatal for that client)
|
|
20
|
+
*/
|
|
21
|
+
import type { McpServer } from '../acp/protocol.js';
|
|
22
|
+
export interface McpTool {
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
inputSchema?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface McpResource {
|
|
28
|
+
uri: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
mimeType?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface McpResourceContent {
|
|
34
|
+
uri: string;
|
|
35
|
+
mimeType?: string;
|
|
36
|
+
/** Text payload — set when the server returns a text resource. */
|
|
37
|
+
text?: string;
|
|
38
|
+
/** Base64 blob payload — set when the server returns binary. */
|
|
39
|
+
blob?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface McpPrompt {
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Argument metadata if the prompt is parameterised. */
|
|
45
|
+
arguments?: {
|
|
46
|
+
name: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
}[];
|
|
50
|
+
}
|
|
51
|
+
export interface McpPromptMessage {
|
|
52
|
+
role: 'user' | 'assistant' | 'system';
|
|
53
|
+
content: {
|
|
54
|
+
type: string;
|
|
55
|
+
text?: string;
|
|
56
|
+
[k: string]: unknown;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Server-initiated `sampling/createMessage` request payload. MCP servers
|
|
61
|
+
* that opt into the `sampling` capability send this to ask the host LLM
|
|
62
|
+
* (Codeep, in our case) to generate a completion on their behalf.
|
|
63
|
+
*/
|
|
64
|
+
export interface SamplingCreateMessageParams {
|
|
65
|
+
messages: {
|
|
66
|
+
role: 'user' | 'assistant';
|
|
67
|
+
content: {
|
|
68
|
+
type: 'text';
|
|
69
|
+
text: string;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'image';
|
|
72
|
+
data: string;
|
|
73
|
+
mimeType: string;
|
|
74
|
+
};
|
|
75
|
+
}[];
|
|
76
|
+
modelPreferences?: {
|
|
77
|
+
hints?: {
|
|
78
|
+
name?: string;
|
|
79
|
+
}[];
|
|
80
|
+
costPriority?: number;
|
|
81
|
+
speedPriority?: number;
|
|
82
|
+
intelligencePriority?: number;
|
|
83
|
+
};
|
|
84
|
+
systemPrompt?: string;
|
|
85
|
+
includeContext?: 'none' | 'thisServer' | 'allServers';
|
|
86
|
+
temperature?: number;
|
|
87
|
+
maxTokens?: number;
|
|
88
|
+
stopSequences?: string[];
|
|
89
|
+
metadata?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
export interface SamplingCreateMessageResult {
|
|
92
|
+
role: 'assistant';
|
|
93
|
+
content: {
|
|
94
|
+
type: 'text';
|
|
95
|
+
text: string;
|
|
96
|
+
};
|
|
97
|
+
model: string;
|
|
98
|
+
stopReason?: 'endTurn' | 'stopSequence' | 'maxTokens';
|
|
99
|
+
}
|
|
100
|
+
export declare class McpClient {
|
|
101
|
+
readonly server: McpServer;
|
|
102
|
+
readonly clientOpts: {
|
|
103
|
+
workspaceRoot?: string;
|
|
104
|
+
onSamplingRequest?: (params: SamplingCreateMessageParams) => Promise<SamplingCreateMessageResult>;
|
|
105
|
+
};
|
|
106
|
+
/** Stdio transport state. Null when running over HTTP (or before start). */
|
|
107
|
+
private child;
|
|
108
|
+
/** HTTP transport state. Null when running over stdio. */
|
|
109
|
+
private http;
|
|
110
|
+
private pending;
|
|
111
|
+
private buffer;
|
|
112
|
+
private stopped;
|
|
113
|
+
private toolsCache;
|
|
114
|
+
/** True when this client is configured for the Streamable HTTP transport. */
|
|
115
|
+
private get isHttp();
|
|
116
|
+
/**
|
|
117
|
+
* Rolling-window record of recent crash times (ms epoch). Used by the
|
|
118
|
+
* auto-reconnect logic: too many crashes in a short window → give up
|
|
119
|
+
* instead of spinning indefinitely on a broken server.
|
|
120
|
+
*/
|
|
121
|
+
private crashTimestamps;
|
|
122
|
+
/** Reconnect tuning — generous defaults, configurable via env if needed. */
|
|
123
|
+
private readonly MAX_RESTARTS;
|
|
124
|
+
private readonly RESTART_WINDOW_MS;
|
|
125
|
+
/** Has the agent loop been notified that this server is fully gone? */
|
|
126
|
+
private gaveUp;
|
|
127
|
+
/**
|
|
128
|
+
* Optional callback fired after a successful auto-restart. The registry
|
|
129
|
+
* uses this to drop its tools cache so the next `listTools()` re-queries
|
|
130
|
+
* (the server may expose a different tool set after restart).
|
|
131
|
+
*/
|
|
132
|
+
onRestart?: () => void;
|
|
133
|
+
/**
|
|
134
|
+
* Optional callback fired when the client gives up after exceeding the
|
|
135
|
+
* restart budget. The registry uses this to surface a visible "MCP
|
|
136
|
+
* server died" error in /mcp.
|
|
137
|
+
*/
|
|
138
|
+
onGaveUp?: (reason: string) => void;
|
|
139
|
+
/**
|
|
140
|
+
* Optional callback fired when the server sends a `notifications/*`
|
|
141
|
+
* indicating its catalog changed (tools, resources, prompts). The
|
|
142
|
+
* registry forwards this up so the agent loop can re-fetch on the next
|
|
143
|
+
* iteration.
|
|
144
|
+
*/
|
|
145
|
+
onCatalogChanged?: (kind: 'tools' | 'resources' | 'prompts') => void;
|
|
146
|
+
/**
|
|
147
|
+
* @param server MCP server config (command, args, env, name).
|
|
148
|
+
* @param opts Optional client metadata.
|
|
149
|
+
* - `workspaceRoot` exposed to the server as a root via
|
|
150
|
+
* the `roots` capability so filesystem-style servers
|
|
151
|
+
* can scope their reads.
|
|
152
|
+
* - `onSamplingRequest` makes the client advertise the
|
|
153
|
+
* `sampling` capability and routes server-initiated
|
|
154
|
+
* `sampling/createMessage` to the host LLM.
|
|
155
|
+
*/
|
|
156
|
+
constructor(server: McpServer, clientOpts?: {
|
|
157
|
+
workspaceRoot?: string;
|
|
158
|
+
onSamplingRequest?: (params: SamplingCreateMessageParams) => Promise<SamplingCreateMessageResult>;
|
|
159
|
+
});
|
|
160
|
+
/** Open the transport and perform the MCP handshake. */
|
|
161
|
+
start(opts?: {
|
|
162
|
+
initTimeoutMs?: number;
|
|
163
|
+
}): Promise<void>;
|
|
164
|
+
/** Discover tools the server exposes. Cached on first call. */
|
|
165
|
+
listTools(): Promise<McpTool[]>;
|
|
166
|
+
/**
|
|
167
|
+
* Discover resources the server exposes. Not all servers implement
|
|
168
|
+
* resources/list — those return a `-32601 Method not found`, which we
|
|
169
|
+
* surface as an empty array (callers can treat absence and emptiness
|
|
170
|
+
* the same way).
|
|
171
|
+
*/
|
|
172
|
+
listResources(): Promise<McpResource[]>;
|
|
173
|
+
/** Read one resource by URI. */
|
|
174
|
+
readResource(uri: string): Promise<McpResourceContent[]>;
|
|
175
|
+
/** Discover prompt templates the server exposes (optional capability). */
|
|
176
|
+
listPrompts(): Promise<McpPrompt[]>;
|
|
177
|
+
/** Materialise a prompt template into its message sequence. */
|
|
178
|
+
getPrompt(name: string, args?: Record<string, unknown>): Promise<{
|
|
179
|
+
description?: string;
|
|
180
|
+
messages: McpPromptMessage[];
|
|
181
|
+
}>;
|
|
182
|
+
/** Invoke a tool on this server. */
|
|
183
|
+
callTool(name: string, args: Record<string, unknown>, opts?: {
|
|
184
|
+
timeoutMs?: number;
|
|
185
|
+
}): Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Attempt to spawn a fresh child process after a crash. Tries up to
|
|
188
|
+
* MAX_RESTARTS times within RESTART_WINDOW_MS, then gives up. After a
|
|
189
|
+
* successful restart, `toolsCache` is cleared so the next listTools()
|
|
190
|
+
* re-queries — the server may legitimately expose different tools after
|
|
191
|
+
* a code reload.
|
|
192
|
+
*/
|
|
193
|
+
private attemptRestart;
|
|
194
|
+
/** Wire up data/exit/error listeners on the current child. Used by start() and attemptRestart(). */
|
|
195
|
+
private attachChildHandlers;
|
|
196
|
+
/** Tear down the transport (stdio child or HTTP stream) and reject pending requests. */
|
|
197
|
+
stop(): Promise<void>;
|
|
198
|
+
private handleStdout;
|
|
199
|
+
/**
|
|
200
|
+
* Handle a request from the MCP server (server-initiated JSON-RPC).
|
|
201
|
+
* Currently handled methods:
|
|
202
|
+
* - `roots/list` — return the workspace folder if provided
|
|
203
|
+
* - `sampling/createMessage` — delegate to the host LLM callback if
|
|
204
|
+
* one was wired into the constructor; otherwise -32601 (so a
|
|
205
|
+
* server that asks without us advertising the capability gets a
|
|
206
|
+
* clear "no" instead of a hang).
|
|
207
|
+
*
|
|
208
|
+
* Anything else replies with `-32601 Method not found` per JSON-RPC spec.
|
|
209
|
+
*/
|
|
210
|
+
private handleServerRequest;
|
|
211
|
+
/** Serialise and send a JSON-RPC response over whichever transport is active. */
|
|
212
|
+
private writeResponse;
|
|
213
|
+
/**
|
|
214
|
+
* Single send path used by request/notify/writeResponse. Stdio just
|
|
215
|
+
* pipes the serialised frame + newline. HTTP POSTs the JSON body; the
|
|
216
|
+
* response (or any later SSE event) re-enters via `dispatchFrame`.
|
|
217
|
+
* Errors on the HTTP path reject pending request promises so the
|
|
218
|
+
* agent doesn't hang waiting on a frame that'll never come.
|
|
219
|
+
*/
|
|
220
|
+
private writeFrame;
|
|
221
|
+
/**
|
|
222
|
+
* Common entry point for every incoming JSON-RPC frame, regardless of
|
|
223
|
+
* transport. Stdio's `handleStdout` parses lines and forwards each
|
|
224
|
+
* here; the HTTP transport calls this directly from its `onFrame`.
|
|
225
|
+
*/
|
|
226
|
+
private dispatchFrame;
|
|
227
|
+
private request;
|
|
228
|
+
private notify;
|
|
229
|
+
}
|