@bubblebrain-ai/bubble 0.0.1
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 +70 -0
- package/dist/agent/evidence-tracker.d.ts +15 -0
- package/dist/agent/evidence-tracker.js +93 -0
- package/dist/agent/execution-governor.d.ts +30 -0
- package/dist/agent/execution-governor.js +169 -0
- package/dist/agent/subtask-policy.d.ts +14 -0
- package/dist/agent/subtask-policy.js +60 -0
- package/dist/agent/task-classifier.d.ts +3 -0
- package/dist/agent/task-classifier.js +36 -0
- package/dist/agent/tool-arbiter.d.ts +7 -0
- package/dist/agent/tool-arbiter.js +33 -0
- package/dist/agent/tool-intent.d.ts +20 -0
- package/dist/agent/tool-intent.js +176 -0
- package/dist/agent.d.ts +95 -0
- package/dist/agent.js +672 -0
- package/dist/approval/controller.d.ts +48 -0
- package/dist/approval/controller.js +78 -0
- package/dist/approval/danger.d.ts +13 -0
- package/dist/approval/danger.js +55 -0
- package/dist/approval/diff-hunks.d.ts +12 -0
- package/dist/approval/diff-hunks.js +32 -0
- package/dist/approval/session-cache.d.ts +35 -0
- package/dist/approval/session-cache.js +68 -0
- package/dist/approval/tool-helper.d.ts +14 -0
- package/dist/approval/tool-helper.js +32 -0
- package/dist/approval/types.d.ts +56 -0
- package/dist/approval/types.js +8 -0
- package/dist/bubble-home.d.ts +8 -0
- package/dist/bubble-home.js +19 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.js +82 -0
- package/dist/config.d.ts +41 -0
- package/dist/config.js +144 -0
- package/dist/context/budget.d.ts +21 -0
- package/dist/context/budget.js +72 -0
- package/dist/context/compact-llm.d.ts +16 -0
- package/dist/context/compact-llm.js +132 -0
- package/dist/context/compact.d.ts +15 -0
- package/dist/context/compact.js +251 -0
- package/dist/context/overflow.d.ts +9 -0
- package/dist/context/overflow.js +46 -0
- package/dist/context/projector.d.ts +26 -0
- package/dist/context/projector.js +150 -0
- package/dist/context/prune.d.ts +9 -0
- package/dist/context/prune.js +111 -0
- package/dist/lsp/config.d.ts +18 -0
- package/dist/lsp/config.js +58 -0
- package/dist/lsp/diagnostics.d.ts +24 -0
- package/dist/lsp/diagnostics.js +103 -0
- package/dist/lsp/index.d.ts +3 -0
- package/dist/lsp/index.js +3 -0
- package/dist/lsp/service.d.ts +85 -0
- package/dist/lsp/service.js +695 -0
- package/dist/main.d.ts +5 -0
- package/dist/main.js +352 -0
- package/dist/mcp/client.d.ts +68 -0
- package/dist/mcp/client.js +163 -0
- package/dist/mcp/config.d.ts +26 -0
- package/dist/mcp/config.js +127 -0
- package/dist/mcp/manager.d.ts +55 -0
- package/dist/mcp/manager.js +296 -0
- package/dist/mcp/name.d.ts +26 -0
- package/dist/mcp/name.js +40 -0
- package/dist/mcp/transports.d.ts +53 -0
- package/dist/mcp/transports.js +248 -0
- package/dist/mcp/types.d.ts +111 -0
- package/dist/mcp/types.js +14 -0
- package/dist/memory/db.d.ts +62 -0
- package/dist/memory/db.js +313 -0
- package/dist/memory/index.d.ts +9 -0
- package/dist/memory/index.js +9 -0
- package/dist/memory/paths.d.ts +18 -0
- package/dist/memory/paths.js +38 -0
- package/dist/memory/phase1.d.ts +23 -0
- package/dist/memory/phase1.js +172 -0
- package/dist/memory/phase2.d.ts +19 -0
- package/dist/memory/phase2.js +100 -0
- package/dist/memory/prompts.d.ts +19 -0
- package/dist/memory/prompts.js +99 -0
- package/dist/memory/reset.d.ts +1 -0
- package/dist/memory/reset.js +13 -0
- package/dist/memory/start.d.ts +24 -0
- package/dist/memory/start.js +50 -0
- package/dist/memory/storage.d.ts +10 -0
- package/dist/memory/storage.js +82 -0
- package/dist/memory/store.d.ts +43 -0
- package/dist/memory/store.js +193 -0
- package/dist/memory/usage.d.ts +1 -0
- package/dist/memory/usage.js +38 -0
- package/dist/model-catalog.d.ts +20 -0
- package/dist/model-catalog.js +99 -0
- package/dist/model-config.d.ts +32 -0
- package/dist/model-config.js +59 -0
- package/dist/model-pricing.d.ts +23 -0
- package/dist/model-pricing.js +46 -0
- package/dist/oauth/index.d.ts +3 -0
- package/dist/oauth/index.js +2 -0
- package/dist/oauth/openai-codex.d.ts +9 -0
- package/dist/oauth/openai-codex.js +173 -0
- package/dist/oauth/storage.d.ts +18 -0
- package/dist/oauth/storage.js +60 -0
- package/dist/oauth/types.d.ts +15 -0
- package/dist/oauth/types.js +1 -0
- package/dist/orchestrator/default-hooks.d.ts +2 -0
- package/dist/orchestrator/default-hooks.js +96 -0
- package/dist/orchestrator/hooks.d.ts +78 -0
- package/dist/orchestrator/hooks.js +52 -0
- package/dist/orchestrator/workflow.d.ts +10 -0
- package/dist/orchestrator/workflow.js +22 -0
- package/dist/permission/mode.d.ts +23 -0
- package/dist/permission/mode.js +20 -0
- package/dist/permissions/rule.d.ts +39 -0
- package/dist/permissions/rule.js +234 -0
- package/dist/permissions/settings.d.ts +71 -0
- package/dist/permissions/settings.js +202 -0
- package/dist/permissions/types.d.ts +61 -0
- package/dist/permissions/types.js +14 -0
- package/dist/prompt/compose.d.ts +12 -0
- package/dist/prompt/compose.js +67 -0
- package/dist/prompt/environment.d.ts +12 -0
- package/dist/prompt/environment.js +38 -0
- package/dist/prompt/provider-prompts/anthropic.d.ts +1 -0
- package/dist/prompt/provider-prompts/anthropic.js +5 -0
- package/dist/prompt/provider-prompts/codex.d.ts +1 -0
- package/dist/prompt/provider-prompts/codex.js +5 -0
- package/dist/prompt/provider-prompts/default.d.ts +1 -0
- package/dist/prompt/provider-prompts/default.js +6 -0
- package/dist/prompt/provider-prompts/gemini.d.ts +1 -0
- package/dist/prompt/provider-prompts/gemini.js +5 -0
- package/dist/prompt/provider-prompts/gpt.d.ts +1 -0
- package/dist/prompt/provider-prompts/gpt.js +5 -0
- package/dist/prompt/reminders.d.ts +30 -0
- package/dist/prompt/reminders.js +164 -0
- package/dist/prompt/runtime.d.ts +12 -0
- package/dist/prompt/runtime.js +31 -0
- package/dist/prompt/skills.d.ts +2 -0
- package/dist/prompt/skills.js +4 -0
- package/dist/provider-openai-codex.d.ts +14 -0
- package/dist/provider-openai-codex.js +409 -0
- package/dist/provider-registry.d.ts +56 -0
- package/dist/provider-registry.js +244 -0
- package/dist/provider-transform.d.ts +10 -0
- package/dist/provider-transform.js +69 -0
- package/dist/provider.d.ts +31 -0
- package/dist/provider.js +269 -0
- package/dist/question/controller.d.ts +22 -0
- package/dist/question/controller.js +97 -0
- package/dist/question/index.d.ts +2 -0
- package/dist/question/index.js +2 -0
- package/dist/question/types.d.ts +42 -0
- package/dist/question/types.js +6 -0
- package/dist/session-log.d.ts +16 -0
- package/dist/session-log.js +267 -0
- package/dist/session-types.d.ts +55 -0
- package/dist/session-types.js +1 -0
- package/dist/session.d.ts +32 -0
- package/dist/session.js +135 -0
- package/dist/skills/discovery.d.ts +12 -0
- package/dist/skills/discovery.js +148 -0
- package/dist/skills/format.d.ts +2 -0
- package/dist/skills/format.js +47 -0
- package/dist/skills/frontmatter.d.ts +5 -0
- package/dist/skills/frontmatter.js +60 -0
- package/dist/skills/invocation.d.ts +8 -0
- package/dist/skills/invocation.js +51 -0
- package/dist/skills/registry.d.ts +17 -0
- package/dist/skills/registry.js +42 -0
- package/dist/skills/types.d.ts +32 -0
- package/dist/skills/types.js +1 -0
- package/dist/slash-commands/commands.d.ts +7 -0
- package/dist/slash-commands/commands.js +779 -0
- package/dist/slash-commands/index.d.ts +4 -0
- package/dist/slash-commands/index.js +8 -0
- package/dist/slash-commands/registry.d.ts +31 -0
- package/dist/slash-commands/registry.js +70 -0
- package/dist/slash-commands/types.d.ts +44 -0
- package/dist/slash-commands/types.js +1 -0
- package/dist/slash-commands/unified.d.ts +38 -0
- package/dist/slash-commands/unified.js +38 -0
- package/dist/system-prompt.d.ts +34 -0
- package/dist/system-prompt.js +7 -0
- package/dist/tools/bash.d.ts +6 -0
- package/dist/tools/bash.js +135 -0
- package/dist/tools/edit.d.ts +16 -0
- package/dist/tools/edit.js +95 -0
- package/dist/tools/exa-mcp.d.ts +3 -0
- package/dist/tools/exa-mcp.js +74 -0
- package/dist/tools/exit-plan-mode.d.ts +17 -0
- package/dist/tools/exit-plan-mode.js +68 -0
- package/dist/tools/glob.d.ts +5 -0
- package/dist/tools/glob.js +129 -0
- package/dist/tools/grep.d.ts +5 -0
- package/dist/tools/grep.js +111 -0
- package/dist/tools/index.d.ts +36 -0
- package/dist/tools/index.js +59 -0
- package/dist/tools/lsp.d.ts +4 -0
- package/dist/tools/lsp.js +92 -0
- package/dist/tools/memory.d.ts +3 -0
- package/dist/tools/memory.js +90 -0
- package/dist/tools/question.d.ts +3 -0
- package/dist/tools/question.js +174 -0
- package/dist/tools/read.d.ts +7 -0
- package/dist/tools/read.js +83 -0
- package/dist/tools/sensitive-paths.d.ts +3 -0
- package/dist/tools/sensitive-paths.js +24 -0
- package/dist/tools/skill.d.ts +5 -0
- package/dist/tools/skill.js +51 -0
- package/dist/tools/task.d.ts +2 -0
- package/dist/tools/task.js +57 -0
- package/dist/tools/todo.d.ts +12 -0
- package/dist/tools/todo.js +151 -0
- package/dist/tools/tool-search.d.ts +23 -0
- package/dist/tools/tool-search.js +124 -0
- package/dist/tools/web-fetch.d.ts +6 -0
- package/dist/tools/web-fetch.js +75 -0
- package/dist/tools/web-search.d.ts +5 -0
- package/dist/tools/web-search.js +49 -0
- package/dist/tools/write.d.ts +11 -0
- package/dist/tools/write.js +77 -0
- package/dist/tui/display-history.d.ts +35 -0
- package/dist/tui/display-history.js +243 -0
- package/dist/tui/file-mentions.d.ts +29 -0
- package/dist/tui/file-mentions.js +174 -0
- package/dist/tui/image-paste.d.ts +54 -0
- package/dist/tui/image-paste.js +288 -0
- package/dist/tui/markdown-theme-rules.d.ts +23 -0
- package/dist/tui/markdown-theme-rules.js +164 -0
- package/dist/tui/markdown-theme.d.ts +5 -0
- package/dist/tui/markdown-theme.js +27 -0
- package/dist/tui/opencode-spinner.d.ts +21 -0
- package/dist/tui/opencode-spinner.js +216 -0
- package/dist/tui/prompt-keybindings.d.ts +41 -0
- package/dist/tui/prompt-keybindings.js +28 -0
- package/dist/tui/recent-activity.d.ts +8 -0
- package/dist/tui/recent-activity.js +71 -0
- package/dist/tui/run.d.ts +39 -0
- package/dist/tui/run.js +5696 -0
- package/dist/tui/sidebar-mcp.d.ts +31 -0
- package/dist/tui/sidebar-mcp.js +62 -0
- package/dist/tui/sidebar-state.d.ts +12 -0
- package/dist/tui/sidebar-state.js +69 -0
- package/dist/types.d.ts +219 -0
- package/dist/types.js +4 -0
- package/dist/variant/thinking-level.d.ts +5 -0
- package/dist/variant/thinking-level.js +25 -0
- package/dist/variant/variant-resolver.d.ts +4 -0
- package/dist/variant/variant-resolver.js +12 -0
- package/package.json +47 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP transports — minimal, dependency-free JSON-RPC clients.
|
|
3
|
+
*
|
|
4
|
+
* Two transports in v1:
|
|
5
|
+
* - StdioTransport: child process, line-delimited JSON on stdin/stdout
|
|
6
|
+
* - HttpTransport: POST JSON-RPC over HTTP (Streamable HTTP), handle both
|
|
7
|
+
* application/json and text/event-stream responses. Also used for `sse`
|
|
8
|
+
* servers — the spec lets a server respond with either content-type.
|
|
9
|
+
*
|
|
10
|
+
* These deliberately do NOT depend on @modelcontextprotocol/sdk. The SDK pulls
|
|
11
|
+
* in zod + schema machinery we don't need. Our surface area here is small:
|
|
12
|
+
* initialize + tools/list + tools/call. Adding more methods is just more
|
|
13
|
+
* JSON-RPC calls on the same pipe.
|
|
14
|
+
*/
|
|
15
|
+
import { spawn } from "node:child_process";
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Stdio
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
export class StdioTransport {
|
|
20
|
+
config;
|
|
21
|
+
child;
|
|
22
|
+
buffer = "";
|
|
23
|
+
stderrBuffer = "";
|
|
24
|
+
messageHandler;
|
|
25
|
+
errorHandler;
|
|
26
|
+
closeHandler;
|
|
27
|
+
closed = false;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.config = config;
|
|
30
|
+
}
|
|
31
|
+
async start() {
|
|
32
|
+
const env = { ...process.env, ...(this.config.env ?? {}) };
|
|
33
|
+
const child = spawn(this.config.command, this.config.args ?? [], {
|
|
34
|
+
env,
|
|
35
|
+
cwd: this.config.cwd,
|
|
36
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
37
|
+
});
|
|
38
|
+
this.child = child;
|
|
39
|
+
child.stdout.setEncoding("utf8");
|
|
40
|
+
child.stdout.on("data", (chunk) => this.onStdout(chunk));
|
|
41
|
+
child.stderr.setEncoding("utf8");
|
|
42
|
+
child.stderr.on("data", (chunk) => {
|
|
43
|
+
this.stderrBuffer += chunk;
|
|
44
|
+
if (this.stderrBuffer.length > 8192) {
|
|
45
|
+
this.stderrBuffer = this.stderrBuffer.slice(-4096);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
child.on("error", (err) => {
|
|
49
|
+
this.errorHandler?.(err);
|
|
50
|
+
});
|
|
51
|
+
child.on("exit", (code, signal) => {
|
|
52
|
+
if (this.closed)
|
|
53
|
+
return;
|
|
54
|
+
this.closed = true;
|
|
55
|
+
if (code && code !== 0) {
|
|
56
|
+
const msg = `stdio server exited with code ${code}${signal ? ` (signal ${signal})` : ""}${this.stderrBuffer ? `\nstderr:\n${this.stderrBuffer.trim()}` : ""}`;
|
|
57
|
+
this.errorHandler?.(new Error(msg));
|
|
58
|
+
}
|
|
59
|
+
this.closeHandler?.();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
onStdout(chunk) {
|
|
63
|
+
this.buffer += chunk;
|
|
64
|
+
let idx;
|
|
65
|
+
while ((idx = this.buffer.indexOf("\n")) !== -1) {
|
|
66
|
+
const line = this.buffer.slice(0, idx).trim();
|
|
67
|
+
this.buffer = this.buffer.slice(idx + 1);
|
|
68
|
+
if (!line)
|
|
69
|
+
continue;
|
|
70
|
+
try {
|
|
71
|
+
const parsed = JSON.parse(line);
|
|
72
|
+
this.messageHandler?.(parsed);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// Ignore non-JSON log lines from the server process.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async send(message) {
|
|
80
|
+
if (!this.child || this.closed)
|
|
81
|
+
throw new Error("Transport not started or already closed");
|
|
82
|
+
this.child.stdin.write(JSON.stringify(message) + "\n");
|
|
83
|
+
}
|
|
84
|
+
onMessage(handler) {
|
|
85
|
+
this.messageHandler = handler;
|
|
86
|
+
}
|
|
87
|
+
onError(handler) {
|
|
88
|
+
this.errorHandler = handler;
|
|
89
|
+
}
|
|
90
|
+
onClose(handler) {
|
|
91
|
+
this.closeHandler = handler;
|
|
92
|
+
}
|
|
93
|
+
async close() {
|
|
94
|
+
if (this.closed)
|
|
95
|
+
return;
|
|
96
|
+
this.closed = true;
|
|
97
|
+
const child = this.child;
|
|
98
|
+
if (!child)
|
|
99
|
+
return;
|
|
100
|
+
try {
|
|
101
|
+
child.stdin.end();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// ignore
|
|
105
|
+
}
|
|
106
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
107
|
+
child.kill("SIGTERM");
|
|
108
|
+
// Give it 500ms before SIGKILL.
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
111
|
+
try {
|
|
112
|
+
child.kill("SIGKILL");
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// ignore
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, 500).unref?.();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
getStderr() {
|
|
122
|
+
return this.stderrBuffer;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// HTTP (Streamable HTTP) — also handles `sse` servers since the spec overlaps.
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
export class HttpTransport {
|
|
129
|
+
messageHandler;
|
|
130
|
+
errorHandler;
|
|
131
|
+
closeHandler;
|
|
132
|
+
sessionId;
|
|
133
|
+
closed = false;
|
|
134
|
+
url;
|
|
135
|
+
baseHeaders;
|
|
136
|
+
constructor(config) {
|
|
137
|
+
this.url = config.url;
|
|
138
|
+
this.baseHeaders = { ...(config.headers ?? {}) };
|
|
139
|
+
}
|
|
140
|
+
async start() {
|
|
141
|
+
// HTTP transport is connectionless per message. Nothing to do here.
|
|
142
|
+
}
|
|
143
|
+
async send(message) {
|
|
144
|
+
if (this.closed)
|
|
145
|
+
throw new Error("Transport closed");
|
|
146
|
+
const headers = {
|
|
147
|
+
"Content-Type": "application/json",
|
|
148
|
+
Accept: "application/json, text/event-stream",
|
|
149
|
+
...this.baseHeaders,
|
|
150
|
+
};
|
|
151
|
+
if (this.sessionId) {
|
|
152
|
+
headers["Mcp-Session-Id"] = this.sessionId;
|
|
153
|
+
}
|
|
154
|
+
let response;
|
|
155
|
+
try {
|
|
156
|
+
response = await fetch(this.url, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers,
|
|
159
|
+
body: JSON.stringify(message),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
164
|
+
this.errorHandler?.(error);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
const newSessionId = response.headers.get("mcp-session-id");
|
|
168
|
+
if (newSessionId)
|
|
169
|
+
this.sessionId = newSessionId;
|
|
170
|
+
// Notifications or responses that return 202 Accepted with no body.
|
|
171
|
+
if (response.status === 202 || response.status === 204) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
const body = await response.text().catch(() => "");
|
|
176
|
+
const err = new Error(`HTTP ${response.status} from MCP server${body ? `: ${body.slice(0, 500)}` : ""}`);
|
|
177
|
+
this.errorHandler?.(err);
|
|
178
|
+
throw err;
|
|
179
|
+
}
|
|
180
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
181
|
+
const text = await response.text();
|
|
182
|
+
if (contentType.includes("text/event-stream")) {
|
|
183
|
+
this.parseSseBody(text);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// application/json — single JSON-RPC response, or a JSON array of them.
|
|
187
|
+
const trimmed = text.trim();
|
|
188
|
+
if (!trimmed)
|
|
189
|
+
return;
|
|
190
|
+
try {
|
|
191
|
+
const parsed = JSON.parse(trimmed);
|
|
192
|
+
if (Array.isArray(parsed)) {
|
|
193
|
+
for (const item of parsed)
|
|
194
|
+
this.messageHandler?.(item);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
this.messageHandler?.(parsed);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Fall back to SSE parsing — some servers send SSE without the content-type.
|
|
202
|
+
this.parseSseBody(text);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
parseSseBody(body) {
|
|
206
|
+
for (const line of body.split("\n")) {
|
|
207
|
+
if (!line.startsWith("data:"))
|
|
208
|
+
continue;
|
|
209
|
+
const data = line.slice(5).trim();
|
|
210
|
+
if (!data)
|
|
211
|
+
continue;
|
|
212
|
+
try {
|
|
213
|
+
const parsed = JSON.parse(data);
|
|
214
|
+
this.messageHandler?.(parsed);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
// skip malformed SSE data line
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
onMessage(handler) {
|
|
222
|
+
this.messageHandler = handler;
|
|
223
|
+
}
|
|
224
|
+
onError(handler) {
|
|
225
|
+
this.errorHandler = handler;
|
|
226
|
+
}
|
|
227
|
+
onClose(handler) {
|
|
228
|
+
this.closeHandler = handler;
|
|
229
|
+
}
|
|
230
|
+
async close() {
|
|
231
|
+
if (this.closed)
|
|
232
|
+
return;
|
|
233
|
+
this.closed = true;
|
|
234
|
+
// Best-effort session termination. Per spec, DELETE /mcp with the session id.
|
|
235
|
+
if (this.sessionId) {
|
|
236
|
+
try {
|
|
237
|
+
await fetch(this.url, {
|
|
238
|
+
method: "DELETE",
|
|
239
|
+
headers: { "Mcp-Session-Id": this.sessionId, ...this.baseHeaders },
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// ignore
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
this.closeHandler?.();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) core types.
|
|
3
|
+
*
|
|
4
|
+
* Server configurations loaded from settings.json:
|
|
5
|
+
*
|
|
6
|
+
* "mcpServers": {
|
|
7
|
+
* "github": { "type": "stdio", "command": "npx", "args": ["-y", "..."], "env": {...} },
|
|
8
|
+
* "exa": { "type": "http", "url": "https://mcp.exa.ai/mcp", "headers": {...} },
|
|
9
|
+
* "acme": { "type": "sse", "url": "https://acme.example/mcp/sse" }
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Shape mirrors Claude Desktop / Claude Code (minus OAuth, ws, sdk — not in v1).
|
|
13
|
+
*/
|
|
14
|
+
import type { ToolSchema } from "../types.js";
|
|
15
|
+
export type McpTransportType = "stdio" | "http" | "sse";
|
|
16
|
+
export interface StdioServerConfig {
|
|
17
|
+
type: "stdio";
|
|
18
|
+
command: string;
|
|
19
|
+
args?: string[];
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface HttpServerConfig {
|
|
24
|
+
type: "http";
|
|
25
|
+
url: string;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export interface SseServerConfig {
|
|
29
|
+
type: "sse";
|
|
30
|
+
url: string;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export type McpServerConfig = StdioServerConfig | HttpServerConfig | SseServerConfig;
|
|
34
|
+
/** A server config annotated with its source scope and original (unnormalized) name. */
|
|
35
|
+
export interface ScopedMcpServerConfig {
|
|
36
|
+
name: string;
|
|
37
|
+
scope: "user" | "project" | "local";
|
|
38
|
+
config: McpServerConfig;
|
|
39
|
+
}
|
|
40
|
+
/** One tool exposed by an MCP server, as returned by `tools/list`. */
|
|
41
|
+
export interface McpToolInfo {
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
inputSchema?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/** One prompt exposed by an MCP server, as returned by `prompts/list`. */
|
|
47
|
+
export interface McpPromptInfo {
|
|
48
|
+
name: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
arguments?: Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
required?: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
}
|
|
56
|
+
/** Status of a single server connection. */
|
|
57
|
+
export type McpServerStatus = {
|
|
58
|
+
kind: "connected";
|
|
59
|
+
tools: McpToolInfo[];
|
|
60
|
+
prompts: McpPromptInfo[];
|
|
61
|
+
serverInfo?: {
|
|
62
|
+
name: string;
|
|
63
|
+
version: string;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
kind: "failed";
|
|
67
|
+
error: string;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "disabled";
|
|
70
|
+
};
|
|
71
|
+
export interface McpServerState {
|
|
72
|
+
name: string;
|
|
73
|
+
scope: "user" | "project" | "local";
|
|
74
|
+
config: McpServerConfig;
|
|
75
|
+
status: McpServerStatus;
|
|
76
|
+
}
|
|
77
|
+
/** A JSON-RPC message. */
|
|
78
|
+
export interface JsonRpcRequest {
|
|
79
|
+
jsonrpc: "2.0";
|
|
80
|
+
id: number | string;
|
|
81
|
+
method: string;
|
|
82
|
+
params?: unknown;
|
|
83
|
+
}
|
|
84
|
+
export interface JsonRpcNotification {
|
|
85
|
+
jsonrpc: "2.0";
|
|
86
|
+
method: string;
|
|
87
|
+
params?: unknown;
|
|
88
|
+
}
|
|
89
|
+
export interface JsonRpcResponse {
|
|
90
|
+
jsonrpc: "2.0";
|
|
91
|
+
id: number | string;
|
|
92
|
+
result?: unknown;
|
|
93
|
+
error?: {
|
|
94
|
+
code: number;
|
|
95
|
+
message: string;
|
|
96
|
+
data?: unknown;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
100
|
+
/** Low-level transport interface. */
|
|
101
|
+
export interface McpTransport {
|
|
102
|
+
start(): Promise<void>;
|
|
103
|
+
send(message: JsonRpcRequest | JsonRpcNotification): Promise<void>;
|
|
104
|
+
/** Called once per incoming JSON-RPC message (response or server→client request/notification). */
|
|
105
|
+
onMessage(handler: (msg: JsonRpcResponse | JsonRpcNotification | JsonRpcRequest) => void): void;
|
|
106
|
+
onError(handler: (err: Error) => void): void;
|
|
107
|
+
onClose(handler: () => void): void;
|
|
108
|
+
close(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
/** Shape we convert MCP `inputSchema` into for the agent's ToolDefinition. */
|
|
111
|
+
export type McpToolParameters = ToolSchema;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) core types.
|
|
3
|
+
*
|
|
4
|
+
* Server configurations loaded from settings.json:
|
|
5
|
+
*
|
|
6
|
+
* "mcpServers": {
|
|
7
|
+
* "github": { "type": "stdio", "command": "npx", "args": ["-y", "..."], "env": {...} },
|
|
8
|
+
* "exa": { "type": "http", "url": "https://mcp.exa.ai/mcp", "headers": {...} },
|
|
9
|
+
* "acme": { "type": "sse", "url": "https://acme.example/mcp/sse" }
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Shape mirrors Claude Desktop / Claude Code (minus OAuth, ws, sdk — not in v1).
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type MemoryJobStatus = "pending" | "running" | "succeeded" | "failed";
|
|
2
|
+
export type MemoryMode = "enabled" | "disabled";
|
|
3
|
+
export interface Stage1Output {
|
|
4
|
+
sessionFile: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
entryCount: number;
|
|
7
|
+
sourceUpdatedAt: string;
|
|
8
|
+
generatedAt: string;
|
|
9
|
+
rawMemory: string;
|
|
10
|
+
rolloutSummary: string;
|
|
11
|
+
rolloutSlug?: string;
|
|
12
|
+
usageCount: number;
|
|
13
|
+
lastUsage?: string;
|
|
14
|
+
selectedForPhase2: boolean;
|
|
15
|
+
selectedForPhase2SourceUpdatedAt?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface MemoryJob {
|
|
18
|
+
kind: string;
|
|
19
|
+
jobKey: string;
|
|
20
|
+
status: MemoryJobStatus;
|
|
21
|
+
workerId?: string;
|
|
22
|
+
leaseUntil?: number;
|
|
23
|
+
retryAt?: number;
|
|
24
|
+
inputWatermark: number;
|
|
25
|
+
lastSuccessWatermark: number;
|
|
26
|
+
startedAt?: number;
|
|
27
|
+
finishedAt?: number;
|
|
28
|
+
lastError?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class MemoryDatabase {
|
|
31
|
+
private db;
|
|
32
|
+
constructor(cwd: string);
|
|
33
|
+
close(): void;
|
|
34
|
+
path(cwd: string): string;
|
|
35
|
+
upsertStage1Output(output: Omit<Stage1Output, "usageCount" | "selectedForPhase2" | "lastUsage" | "selectedForPhase2SourceUpdatedAt">): void;
|
|
36
|
+
getStage1Output(sessionFile: string): Stage1Output | undefined;
|
|
37
|
+
claimPhase1Job(sessionFile: string, workerId: string, leaseSeconds: number): {
|
|
38
|
+
claimed: boolean;
|
|
39
|
+
reason?: string;
|
|
40
|
+
};
|
|
41
|
+
finishPhase1Job(sessionFile: string, ok: boolean, error?: string): void;
|
|
42
|
+
listStage1Outputs(limit?: number): Stage1Output[];
|
|
43
|
+
listPreviouslySelectedNotIn(sessionFiles: string[]): Stage1Output[];
|
|
44
|
+
markSelectedForPhase2(outputs: Stage1Output[]): void;
|
|
45
|
+
recordUsage(sessionFiles: string[], now?: Date): number;
|
|
46
|
+
setThreadMemoryMode(sessionFile: string, mode: MemoryMode): void;
|
|
47
|
+
getThreadMemoryMode(sessionFile: string): MemoryMode;
|
|
48
|
+
claimGlobalPhase2Job(workerId: string, leaseSeconds: number): {
|
|
49
|
+
claimed: boolean;
|
|
50
|
+
job?: MemoryJob;
|
|
51
|
+
reason?: string;
|
|
52
|
+
};
|
|
53
|
+
finishGlobalPhase2Job(ok: boolean, watermark: number, error?: string): void;
|
|
54
|
+
getGlobalPhase2Job(): MemoryJob | undefined;
|
|
55
|
+
resetStageData(): void;
|
|
56
|
+
stats(): {
|
|
57
|
+
stage1Outputs: number;
|
|
58
|
+
disabledThreads: number;
|
|
59
|
+
jobs: MemoryJob[];
|
|
60
|
+
};
|
|
61
|
+
private migrate;
|
|
62
|
+
}
|