@myrialabs/clopen 0.4.43 → 0.4.45
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/backend/artifacts/project/bridge.ts +218 -0
- package/backend/artifacts/project/edit.ts +243 -0
- package/backend/artifacts/project/index.ts +38 -0
- package/backend/artifacts/project/project.test.ts +181 -0
- package/backend/artifacts/project/scan.ts +368 -0
- package/backend/artifacts/project/sources.ts +100 -0
- package/backend/artifacts/sync.ts +1 -1
- package/backend/auth/permissions.ts +15 -0
- package/backend/chat/stream-manager.ts +26 -8
- package/backend/database/migrations/083_create_project_mcp_trust.ts +32 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +2 -0
- package/backend/database/queries/project-mcp-trust-queries.ts +43 -0
- package/backend/engine/adapters/claude/message-converter.ts +6 -2
- package/backend/engine/adapters/claude/stream.ts +36 -8
- package/backend/engine/adapters/cline/mcp-tools.ts +26 -4
- package/backend/engine/adapters/cline/stream.ts +20 -6
- package/backend/engine/adapters/codex/stream.ts +21 -4
- package/backend/engine/adapters/copilot/stream.ts +6 -3
- package/backend/engine/adapters/cursor/stream.ts +19 -8
- package/backend/engine/adapters/opencode/server.ts +14 -4
- package/backend/engine/adapters/opencode/stream.ts +18 -3
- package/backend/engine/adapters/pi/mcp-tools.ts +26 -4
- package/backend/engine/adapters/pi/stream.ts +35 -3
- package/backend/engine/adapters/qwen/message-converter.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +8 -0
- package/backend/engine/artifact-sync.ts +12 -5
- package/backend/engine/docs/lessons-learned.md +118 -0
- package/backend/files/file-watcher.test.ts +77 -0
- package/backend/files/file-watcher.ts +92 -60
- package/backend/files/watch-ignore.test.ts +182 -0
- package/backend/files/watch-ignore.ts +244 -0
- package/backend/git/git-executor.ts +14 -4
- package/backend/index.ts +11 -1
- package/backend/instructions/service.ts +5 -3
- package/backend/instructions/sync.ts +10 -27
- package/backend/mcp/external/config.ts +65 -23
- package/backend/mcp/external/project.ts +124 -0
- package/backend/mcp/external/proxy.ts +65 -11
- package/backend/mcp/index.ts +14 -9
- package/backend/mcp/internal/remote-server.ts +11 -1
- package/backend/skills/marketplace.ts +1 -1
- package/backend/snapshot/blob-store.ts +9 -5
- package/backend/snapshot/git-attribution.test.ts +42 -0
- package/backend/snapshot/git-attribution.ts +306 -0
- package/backend/snapshot/gitignore.test.ts +62 -0
- package/backend/snapshot/gitignore.ts +158 -78
- package/backend/snapshot/snapshot-service.test.ts +270 -0
- package/backend/snapshot/snapshot-service.ts +412 -136
- package/backend/snapshot/turn-activity.test.ts +52 -0
- package/backend/snapshot/turn-activity.ts +83 -0
- package/backend/snapshot/turn-changes.test.ts +58 -1
- package/backend/snapshot/turn-changes.ts +66 -0
- package/backend/worktrees/tree.ts +1 -1
- package/backend/ws/chat/composer.ts +504 -0
- package/backend/ws/chat/index.ts +3 -1
- package/backend/ws/chat/stream.ts +252 -440
- package/backend/ws/index.ts +4 -0
- package/backend/ws/project-artifacts/index.ts +236 -0
- package/backend/ws/snapshot/changes.ts +66 -31
- package/dist/assets/{index-BeUKiRiY.js → index-Am-rJRxA.js} +1 -1
- package/dist/assets/{index-B6u8cait.js → index-D-Ad1N96.js} +1 -1
- package/dist/assets/main--PLCDxSy.css +1 -0
- package/dist/assets/main-DelPm2Xt.js +1239 -0
- package/dist/index.html +2 -2
- package/package.json +5 -5
- package/shared/types/stores/settings.ts +5 -0
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +2 -0
- package/shared/types/unified/stream.ts +38 -1
- package/dist/assets/main-CMRXlv2f.js +0 -1215
- package/dist/assets/main-DzCY0n-j.css +0 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project MCP — servers a repository declares in `.agents/mcp.json`.
|
|
3
|
+
*
|
|
4
|
+
* They ride the same proxy as installed servers (Clopen is the upstream client,
|
|
5
|
+
* engines only ever see a loopback bridge URL), on a project-addressed route:
|
|
6
|
+
* `/mcp/proj/<projectId>/<name>`. Two things differ from installed servers:
|
|
7
|
+
*
|
|
8
|
+
* - TRUST. The file lives in the repo, so anyone who can push to it could make
|
|
9
|
+
* the server run a command. A server is emitted — and the bridge will only
|
|
10
|
+
* connect it — while the file's current sha256 matches the hash an admin
|
|
11
|
+
* approved (`project_mcp_trust`). Any edit makes it inert until re-approved.
|
|
12
|
+
* The check runs at config-build time AND again when the bridge connects, so
|
|
13
|
+
* a file swapped between the two is still refused.
|
|
14
|
+
* - PLACE. stdio servers start with the repository as their working
|
|
15
|
+
* directory, which is what a repo-relative `command`/`args` expects.
|
|
16
|
+
*
|
|
17
|
+
* Namespace: `project-<name>`, so tools surface as `mcp__project-<name>__<tool>`
|
|
18
|
+
* and never collide with an installed server of the same name.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
22
|
+
import { join } from 'path';
|
|
23
|
+
import { projectQueries, projectMcpTrustQueries } from '$backend/database/queries';
|
|
24
|
+
import { parseProjectMcpJson, hashContent } from '$backend/artifacts/project/scan';
|
|
25
|
+
import { PROJECT_WRITE_PATHS } from '$backend/artifacts/project/sources';
|
|
26
|
+
import { slugify } from '$backend/artifacts/slug';
|
|
27
|
+
import { debug } from '$shared/utils/logger';
|
|
28
|
+
import type { ResolvedExternalServer } from './types';
|
|
29
|
+
|
|
30
|
+
export interface ResolvedProjectServer extends ResolvedExternalServer {
|
|
31
|
+
projectId: string;
|
|
32
|
+
/** Repository root — the working directory for stdio servers. */
|
|
33
|
+
cwd: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Largest `.agents/mcp.json` Clopen will read. */
|
|
37
|
+
const MAX_BYTES = 256 * 1024;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Namespaces of project servers emitted so far. Engines report MCP tools under
|
|
41
|
+
* `<namespace><sep><tool>` with an SDK-specific separator, and the resolver has
|
|
42
|
+
* no project context — so it matches against the namespaces actually handed out.
|
|
43
|
+
*/
|
|
44
|
+
const knownNamespaces = new Set<string>();
|
|
45
|
+
|
|
46
|
+
export function projectNamespace(name: string): string {
|
|
47
|
+
return `project-${slugify(name)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function knownProjectNamespaces(): string[] {
|
|
51
|
+
return [...knownNamespaces];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Expand `${VAR}` / `${VAR:-default}` from the server's environment, as `.mcp.json` does. */
|
|
55
|
+
function expand(value: string): string {
|
|
56
|
+
return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g, (_m, name: string, fallback?: string) =>
|
|
57
|
+
process.env[name] ?? fallback ?? ''
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function expandRecord(record: Record<string, string>): Record<string, string> {
|
|
62
|
+
return Object.fromEntries(Object.entries(record).map(([k, v]) => [k, expand(v)]));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The raw file for a project, or null when absent/oversized. */
|
|
66
|
+
export function readProjectMcpFile(projectPath: string): string | null {
|
|
67
|
+
const file = join(projectPath, PROJECT_WRITE_PATHS.mcp);
|
|
68
|
+
try {
|
|
69
|
+
const info = statSync(file);
|
|
70
|
+
if (!info.isFile() || info.size > MAX_BYTES) return null;
|
|
71
|
+
return readFileSync(file, 'utf8');
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Every server in the project's `.agents/mcp.json`, but only while the file is
|
|
79
|
+
* the approved version. Synchronous on purpose: the per-engine MCP builders it
|
|
80
|
+
* feeds are synchronous, and the file is small.
|
|
81
|
+
*/
|
|
82
|
+
export function getTrustedProjectServers(projectId: string | null | undefined): ResolvedProjectServer[] {
|
|
83
|
+
if (!projectId) return [];
|
|
84
|
+
const project = projectQueries.getById(projectId);
|
|
85
|
+
if (!project?.path) return [];
|
|
86
|
+
const raw = readProjectMcpFile(project.path);
|
|
87
|
+
if (raw == null) return [];
|
|
88
|
+
if (!projectMcpTrustQueries.isTrusted(projectId, hashContent(raw))) {
|
|
89
|
+
debug.log('mcp', `🔒 Project ${projectId}: .agents/mcp.json is not approved (or changed since) — not loading it`);
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
let parsed;
|
|
93
|
+
try {
|
|
94
|
+
parsed = parseProjectMcpJson(raw);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
debug.warn('mcp', `Project ${projectId}: .agents/mcp.json is invalid:`, error);
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
return parsed.map(s => {
|
|
100
|
+
const namespace = projectNamespace(s.name);
|
|
101
|
+
knownNamespaces.add(namespace);
|
|
102
|
+
return {
|
|
103
|
+
id: 0,
|
|
104
|
+
slug: s.name,
|
|
105
|
+
namespace,
|
|
106
|
+
name: s.name,
|
|
107
|
+
transport: s.transport,
|
|
108
|
+
command: s.command ? expand(s.command) : null,
|
|
109
|
+
args: s.args.map(expand),
|
|
110
|
+
env: expandRecord(s.env),
|
|
111
|
+
url: s.url ? expand(s.url) : null,
|
|
112
|
+
headers: expandRecord(s.headers),
|
|
113
|
+
projectId,
|
|
114
|
+
cwd: project.path
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One trusted project server by name, or a readable error. */
|
|
120
|
+
export function requireTrustedProjectServer(projectId: string, name: string): ResolvedProjectServer {
|
|
121
|
+
const server = getTrustedProjectServers(projectId).find(s => s.name === name);
|
|
122
|
+
if (!server) throw new Error(`Project MCP server "${name}" is not declared in an approved .agents/mcp.json`);
|
|
123
|
+
return server;
|
|
124
|
+
}
|
|
@@ -40,6 +40,7 @@ import { debug } from '$shared/utils/logger';
|
|
|
40
40
|
import { mcpServerQueries, permissionSetQueries, profileQueries } from '$backend/database/queries';
|
|
41
41
|
import type { EngineType } from '$shared/types/unified';
|
|
42
42
|
import { resolveServerRow } from './config';
|
|
43
|
+
import { requireTrustedProjectServer, type ResolvedProjectServer } from './project';
|
|
43
44
|
import { parseToolOverrides, isToolExposed } from './tools';
|
|
44
45
|
// Import the PURE resolver (no `$backend/mcp` dependency) to avoid an
|
|
45
46
|
// mcp → permissions/service → mcp import cycle.
|
|
@@ -54,7 +55,7 @@ const UPSTREAM_CONNECT_TIMEOUT_MS = 30_000;
|
|
|
54
55
|
* subprocess or remote HTTP/SSE). OAuth/API-key headers come from
|
|
55
56
|
* `resolveServerRow`, which injects the Clopen-managed bearer.
|
|
56
57
|
*/
|
|
57
|
-
async function connectUpstream(s: ResolvedExternalServer): Promise<Client> {
|
|
58
|
+
async function connectUpstream(s: ResolvedExternalServer & { cwd?: string }): Promise<Client> {
|
|
58
59
|
const client = new Client({ name: 'clopen-proxy', version: '1.0.0' }, { capabilities: {} });
|
|
59
60
|
|
|
60
61
|
if (s.transport === 'stdio') {
|
|
@@ -65,6 +66,8 @@ async function connectUpstream(s: ResolvedExternalServer): Promise<Client> {
|
|
|
65
66
|
command: s.command,
|
|
66
67
|
args: s.args,
|
|
67
68
|
env: { ...getDefaultEnvironment(), ...s.env },
|
|
69
|
+
// Project servers (`.agents/mcp.json`) start inside their repository.
|
|
70
|
+
...(s.cwd ? { cwd: s.cwd } : {}),
|
|
68
71
|
stderr: 'ignore'
|
|
69
72
|
});
|
|
70
73
|
await client.connect(transport, { timeout: UPSTREAM_CONNECT_TIMEOUT_MS });
|
|
@@ -185,20 +188,46 @@ export async function createExternalProxyServer(slug: string, engine?: EngineTyp
|
|
|
185
188
|
throw new Error(`External MCP server is disabled: ${slug}`);
|
|
186
189
|
}
|
|
187
190
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const client = await connectUpstream(resolved);
|
|
191
|
-
|
|
192
|
-
// Global tool-permission policy for this engine (Settings → Permissions).
|
|
193
|
-
// MCP tools carry no permission hook on some engines (e.g. OpenCode only gates
|
|
191
|
+
// Global tool-permission policy for this engine (Settings → Permissions). MCP
|
|
192
|
+
// tools carry no permission hook on some engines (e.g. OpenCode only gates
|
|
194
193
|
// edit/bash/webfetch), so the bridge is the single reliable enforcement point
|
|
195
|
-
// for MCP deny/allow across every engine
|
|
196
|
-
//
|
|
197
|
-
// name `mcp__<namespace>__<tool>` (the identity the Permissions UI uses).
|
|
198
|
-
// Global scope only: the bridge has no session/project context.
|
|
194
|
+
// for MCP deny/allow across every engine. Global scope only: this bridge has
|
|
195
|
+
// no session/project context.
|
|
199
196
|
const permissions = engine
|
|
200
197
|
? mergePermissions(pickEngineSet(permissionSetQueries.getGlobal(), engine), undefined)
|
|
201
198
|
: null;
|
|
199
|
+
return buildProxyServer(resolveServerRow(row), parseToolOverrides(row.tool_overrides), engine, permissions);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Proxy for one server of a project's approved `.agents/mcp.json` — the
|
|
204
|
+
* `/mcp/proj/<projectId>/<name>` bridge. Trust is re-checked here, at connect
|
|
205
|
+
* time: a file edited after the engine received its config is refused rather
|
|
206
|
+
* than run. Project-scoped permission rules apply on top of the global ones,
|
|
207
|
+
* because unlike the installed-server bridge this one knows its project.
|
|
208
|
+
*/
|
|
209
|
+
export async function createProjectProxyServer(projectId: string, name: string, engine?: EngineType): Promise<ExternalProxy> {
|
|
210
|
+
const resolved = requireTrustedProjectServer(projectId, name);
|
|
211
|
+
const permissions = engine
|
|
212
|
+
? mergePermissions(
|
|
213
|
+
pickEngineSet(permissionSetQueries.getGlobal(), engine),
|
|
214
|
+
pickEngineSet(permissionSetQueries.getForProject(projectId), engine)
|
|
215
|
+
)
|
|
216
|
+
: null;
|
|
217
|
+
return buildProxyServer(resolved, {}, engine, permissions);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function buildProxyServer(
|
|
221
|
+
resolved: ResolvedExternalServer | ResolvedProjectServer,
|
|
222
|
+
overrides: ReturnType<typeof parseToolOverrides>,
|
|
223
|
+
engine: EngineType | undefined,
|
|
224
|
+
permissions: ReturnType<typeof mergePermissions> | null
|
|
225
|
+
): Promise<ExternalProxy> {
|
|
226
|
+
const slug = resolved.slug;
|
|
227
|
+
const client = await connectUpstream(resolved);
|
|
228
|
+
|
|
229
|
+
// Rules match the canonical engine-facing name `mcp__<namespace>__<tool>`
|
|
230
|
+
// (the identity the Permissions UI uses).
|
|
202
231
|
const permitted = (toolName: string): boolean =>
|
|
203
232
|
!permissions || isToolAllowed(permissions, `mcp__${resolved.namespace}__${toolName}`);
|
|
204
233
|
|
|
@@ -266,6 +295,31 @@ async function withUpstreamClient<T>(slug: string, fn: (client: Client) => Promi
|
|
|
266
295
|
}
|
|
267
296
|
}
|
|
268
297
|
|
|
298
|
+
/** Same as {@link withUpstreamClient} for a project server (trust-checked). */
|
|
299
|
+
async function withProjectUpstreamClient<T>(projectId: string, name: string, fn: (client: Client) => Promise<T>): Promise<T> {
|
|
300
|
+
const client = await connectUpstream(requireTrustedProjectServer(projectId, name));
|
|
301
|
+
try {
|
|
302
|
+
return await fn(client);
|
|
303
|
+
} finally {
|
|
304
|
+
client.close().catch(error => debug.warn('mcp', `Project MCP ${name}: error closing client:`, error));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** Sanitized tools of a trusted project server — for the in-process engines (Pi, Cline). */
|
|
309
|
+
export async function listProjectServerTools(projectId: string, name: string): Promise<Tool[]> {
|
|
310
|
+
return withProjectUpstreamClient(projectId, name, async (client) => (await listAllToolsRaw(client)).map(sanitizeTool));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Call one tool of a trusted project server — for the in-process engines (Pi, Cline). */
|
|
314
|
+
export async function callProjectServerTool(projectId: string, name: string, toolName: string, args: unknown): Promise<unknown> {
|
|
315
|
+
return withProjectUpstreamClient(projectId, name, async (client) =>
|
|
316
|
+
client.request(
|
|
317
|
+
{ method: 'tools/call', params: { name: toolName, arguments: (args ?? {}) as Record<string, unknown> } },
|
|
318
|
+
CompatibilityCallToolResultSchema
|
|
319
|
+
)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
269
323
|
/** List a server's sanitized tools live (unfiltered) — for the Settings tool panel. */
|
|
270
324
|
export async function listExternalServerTools(slug: string): Promise<Tool[]> {
|
|
271
325
|
return withUpstreamClient(slug, async (client) => (await listAllToolsRaw(client)).map(sanitizeTool));
|
package/backend/mcp/index.ts
CHANGED
|
@@ -59,7 +59,7 @@ export {
|
|
|
59
59
|
export * from './internal/servers';
|
|
60
60
|
|
|
61
61
|
// Remote MCP HTTP bridge (serves internal tools + external proxies to non-Claude engines)
|
|
62
|
-
export { handleMcpRequest, handleExternalMcpRequest, closeMcpServer } from './internal/remote-server';
|
|
62
|
+
export { handleMcpRequest, handleExternalMcpRequest, handleProjectMcpRequest, closeMcpServer } from './internal/remote-server';
|
|
63
63
|
|
|
64
64
|
// Project context service for MCP tool handlers
|
|
65
65
|
export { projectContextService } from './internal/project-context';
|
|
@@ -75,8 +75,10 @@ export {
|
|
|
75
75
|
|
|
76
76
|
// External catalog + types (used by the WS layer and Settings → MCP)
|
|
77
77
|
export { listRegistryServers, mapRegistryServer } from './external/registry-client';
|
|
78
|
-
export { getEnabledExternalServers, resolveServerRow, remoteNeedsOAuth, getEngineConfigsForServer } from './external/config';
|
|
79
|
-
export { listExternalServerTools, callExternalServerTool } from './external/proxy';
|
|
78
|
+
export { getEnabledExternalServers, resolveServerRow, remoteNeedsOAuth, getEngineConfigsForServer, getOpenCodeProjectMcpConfig } from './external/config';
|
|
79
|
+
export { listExternalServerTools, callExternalServerTool, listProjectServerTools, callProjectServerTool } from './external/proxy';
|
|
80
|
+
export { getTrustedProjectServers, projectNamespace, readProjectMcpFile } from './external/project';
|
|
81
|
+
export type { ResolvedProjectServer } from './external/project';
|
|
80
82
|
export { parseToolOverrides, resolveToolExposure, pruneToolOverrides, MCP_ENGINES } from './external/tools';
|
|
81
83
|
export type { ToolExposure } from './external/tools';
|
|
82
84
|
export { probeServer } from './external/probe';
|
|
@@ -108,11 +110,14 @@ export type { ParsedMcpServer, ParsedField, ParseResult } from './external/parse
|
|
|
108
110
|
export async function getEnabledMcpServers(context?: McpExecutionContext, profileFilter?: Set<string>): Promise<Record<string, McpServerConfig>> {
|
|
109
111
|
return {
|
|
110
112
|
...(await internal.getEnabledMcpServers(context, profileFilter)),
|
|
111
|
-
...external.getClaudeExternalMcpConfig(profileFilter)
|
|
113
|
+
...external.getClaudeExternalMcpConfig(profileFilter, context?.projectId)
|
|
112
114
|
};
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Open Code MCP config: internal `clopen-mcp` remote bridge + external servers.
|
|
119
|
+
* Project servers are NOT included — see {@link getOpenCodeProjectMcpConfig}.
|
|
120
|
+
*/
|
|
116
121
|
export function getOpenCodeMcpConfig(profileFilter?: Set<string>) {
|
|
117
122
|
return {
|
|
118
123
|
...internal.getOpenCodeMcpConfig(profileFilter),
|
|
@@ -124,7 +129,7 @@ export function getOpenCodeMcpConfig(profileFilter?: Set<string>) {
|
|
|
124
129
|
export function getCodexMcpConfig(profileFilter?: Set<string>, context?: McpExecutionContext) {
|
|
125
130
|
return {
|
|
126
131
|
...internal.getCodexMcpConfig(profileFilter, context),
|
|
127
|
-
...external.getCodexExternalMcpConfig(profileFilter)
|
|
132
|
+
...external.getCodexExternalMcpConfig(profileFilter, context?.projectId)
|
|
128
133
|
};
|
|
129
134
|
}
|
|
130
135
|
|
|
@@ -132,7 +137,7 @@ export function getCodexMcpConfig(profileFilter?: Set<string>, context?: McpExec
|
|
|
132
137
|
export function getCopilotMcpConfig(profileFilter?: Set<string>, context?: McpExecutionContext) {
|
|
133
138
|
return {
|
|
134
139
|
...internal.getCopilotMcpConfig(profileFilter, context),
|
|
135
|
-
...external.getCopilotExternalMcpConfig(profileFilter)
|
|
140
|
+
...external.getCopilotExternalMcpConfig(profileFilter, context?.projectId)
|
|
136
141
|
};
|
|
137
142
|
}
|
|
138
143
|
|
|
@@ -140,7 +145,7 @@ export function getCopilotMcpConfig(profileFilter?: Set<string>, context?: McpEx
|
|
|
140
145
|
export function getCursorMcpConfig(profileFilter?: Set<string>, context?: McpExecutionContext) {
|
|
141
146
|
return {
|
|
142
147
|
...internal.getCursorMcpConfig(profileFilter, context),
|
|
143
|
-
...external.getCursorExternalMcpConfig(profileFilter)
|
|
148
|
+
...external.getCursorExternalMcpConfig(profileFilter, context?.projectId)
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
|
|
@@ -148,7 +153,7 @@ export function getCursorMcpConfig(profileFilter?: Set<string>, context?: McpExe
|
|
|
148
153
|
export function getQwenMcpConfig(profileFilter?: Set<string>, context?: McpExecutionContext) {
|
|
149
154
|
return {
|
|
150
155
|
...internal.getQwenMcpConfig(profileFilter, context),
|
|
151
|
-
...external.getQwenExternalMcpConfig(profileFilter)
|
|
156
|
+
...external.getQwenExternalMcpConfig(profileFilter, context?.projectId)
|
|
152
157
|
};
|
|
153
158
|
}
|
|
154
159
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
20
20
|
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
21
21
|
import { createRemoteMcpServer, type RemoteMcpCaller } from './servers/helper';
|
|
22
|
-
import { createExternalProxyServer } from '../external/proxy';
|
|
22
|
+
import { createExternalProxyServer, createProjectProxyServer } from '../external/proxy';
|
|
23
23
|
import { debug } from '$shared/utils/logger';
|
|
24
24
|
import { authQueries } from '$backend/database/queries';
|
|
25
25
|
import { hashToken } from '$backend/auth/tokens';
|
|
@@ -273,6 +273,16 @@ export async function handleExternalMcpRequest(request: Request, slug: string):
|
|
|
273
273
|
return handleStreamable(request, `External MCP (${slug}${engine ? `, ${engine}` : ''})`, () => createExternalProxyServer(slug, engine));
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Handle a request to the per-project proxy `/mcp/proj/<projectId>/<name>` — a
|
|
278
|
+
* server from the project's approved `.agents/mcp.json` (see
|
|
279
|
+
* `backend/mcp/external/project.ts`).
|
|
280
|
+
*/
|
|
281
|
+
export async function handleProjectMcpRequest(request: Request, projectId: string, name: string): Promise<Response> {
|
|
282
|
+
const engine = (new URL(request.url).searchParams.get('engine') as EngineType | null) ?? undefined;
|
|
283
|
+
return handleStreamable(request, `Project MCP (${projectId}/${name}${engine ? `, ${engine}` : ''})`, () => createProjectProxyServer(projectId, name, engine));
|
|
284
|
+
}
|
|
285
|
+
|
|
276
286
|
/**
|
|
277
287
|
* Close all active MCP sessions and transports.
|
|
278
288
|
* Called during graceful server shutdown.
|
|
@@ -39,7 +39,7 @@ export interface FetchedSkill {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const PAGE_SIZE = 30;
|
|
42
|
-
const COMMUNITY_INDEX_URL = 'https://majiayu000.github.io/claude-skill-registry
|
|
42
|
+
const COMMUNITY_INDEX_URL = 'https://majiayu000.github.io/claude-skill-registry/search-index-lite.json';
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* A lite-index entry. The index uses full keys (`name`/`description`/`install`/
|
|
@@ -32,7 +32,7 @@ class BlobStore {
|
|
|
32
32
|
private initialized = false;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Cache:
|
|
35
|
+
* Cache: absolute path -> { mtimeMs, size, hash }
|
|
36
36
|
* Avoids re-reading files that haven't changed (based on mtime + size).
|
|
37
37
|
*/
|
|
38
38
|
private fileHashCache = new Map<string, FileHashCacheEntry>();
|
|
@@ -115,22 +115,26 @@ class BlobStore {
|
|
|
115
115
|
* If the file has changed, reads content, hashes it, stores blob, and caches.
|
|
116
116
|
* Reads as Buffer to safely handle binary files (images, PDFs, etc.).
|
|
117
117
|
*
|
|
118
|
+
* Cached by absolute path. It used to be keyed by whatever the caller passed,
|
|
119
|
+
* which was the project-relative path — shared by every project and every
|
|
120
|
+
* worktree copy, where the same file often has the same size.
|
|
121
|
+
*
|
|
118
122
|
* @returns hash and content Buffer (content is null if cache hit and blob already exists)
|
|
119
123
|
*/
|
|
120
|
-
async hashFile(
|
|
124
|
+
async hashFile(fullPath: string): Promise<{ hash: string; content: Buffer | null; cached: boolean }> {
|
|
121
125
|
await this.init();
|
|
122
126
|
|
|
123
127
|
const stat = await fs.stat(fullPath);
|
|
124
128
|
|
|
125
129
|
// Check mtime cache
|
|
126
|
-
const cached = this.fileHashCache.get(
|
|
130
|
+
const cached = this.fileHashCache.get(fullPath);
|
|
127
131
|
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
128
132
|
// Verify blob still exists on disk (could have been cleaned up)
|
|
129
133
|
if (await this.hasBlob(cached.hash)) {
|
|
130
134
|
return { hash: cached.hash, content: null, cached: true };
|
|
131
135
|
}
|
|
132
136
|
// Blob was deleted — invalidate cache, fall through to re-read and re-store
|
|
133
|
-
this.fileHashCache.delete(
|
|
137
|
+
this.fileHashCache.delete(fullPath);
|
|
134
138
|
}
|
|
135
139
|
|
|
136
140
|
// File changed or cache miss - read as Buffer (binary-safe, no encoding conversion)
|
|
@@ -141,7 +145,7 @@ class BlobStore {
|
|
|
141
145
|
await this.storeBlob(content);
|
|
142
146
|
|
|
143
147
|
// Update cache
|
|
144
|
-
this.fileHashCache.set(
|
|
148
|
+
this.fileHashCache.set(fullPath, {
|
|
145
149
|
mtimeMs: stat.mtimeMs,
|
|
146
150
|
size: stat.size,
|
|
147
151
|
hash
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the reflog for HEAD moves that rewrote the working tree.
|
|
3
|
+
*
|
|
4
|
+
* The line that matters is between a commit and everything else: a commit
|
|
5
|
+
* records files somebody already wrote, so treating it as git's own change
|
|
6
|
+
* would erase an agent's work the moment it committed it.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from 'bun:test';
|
|
10
|
+
import { isAuthoredCommit, parseReflog, workingTreeTransitions } from './git-attribution';
|
|
11
|
+
|
|
12
|
+
describe('isAuthoredCommit', () => {
|
|
13
|
+
it('knows a commit from the working tree from one that ends a merge', () => {
|
|
14
|
+
expect(isAuthoredCommit('commit: fix things')).toBe(true);
|
|
15
|
+
expect(isAuthoredCommit('commit (amend): fix things')).toBe(true);
|
|
16
|
+
expect(isAuthoredCommit('commit (initial): init')).toBe(true);
|
|
17
|
+
expect(isAuthoredCommit('commit (merge): Merge branch x')).toBe(false);
|
|
18
|
+
expect(isAuthoredCommit('merge origin/main: Merge made by the \'ort\' strategy.')).toBe(false);
|
|
19
|
+
expect(isAuthoredCommit('pull: Fast-forward')).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('workingTreeTransitions', () => {
|
|
24
|
+
const reflog = parseReflog([
|
|
25
|
+
'c3\tHEAD@{1000}\tmerge origin/main: Fast-forward',
|
|
26
|
+
'c2\tHEAD@{990}\tcommit: agent work',
|
|
27
|
+
'c1\tHEAD@{500}\tcheckout: moving from a to main'
|
|
28
|
+
].join('\n'));
|
|
29
|
+
|
|
30
|
+
it('parses sha, time and subject, newest first', () => {
|
|
31
|
+
expect(reflog[0]).toEqual({ sha: 'c3', time: 1000, subject: 'merge origin/main: Fast-forward' });
|
|
32
|
+
expect(reflog).toHaveLength(3);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('keeps the moves inside the turn and skips commits', () => {
|
|
36
|
+
expect(workingTreeTransitions(reflog, 'c1', 980_000)).toEqual([{ from: 'c2', to: 'c3' }]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('finds nothing when the turn began after the last move', () => {
|
|
40
|
+
expect(workingTreeTransitions(reflog, 'c3', 2_000_000)).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
});
|