@myrialabs/clopen 0.3.21 → 0.4.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/backend/auth/permissions.ts +11 -1
- package/backend/chat/stream-manager.ts +14 -3
- package/backend/database/migrations/040_create_mcp_servers_table.ts +34 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/mcp-server-queries.ts +166 -0
- package/backend/engine/README.md +2 -2
- package/backend/engine/adapters/claude/environment.ts +0 -17
- package/backend/engine/adapters/claude/error-handler.ts +0 -4
- package/backend/engine/adapters/codex/message-converter.ts +1 -1
- package/backend/engine/adapters/codex/stream.ts +1 -1
- package/backend/engine/adapters/copilot/message-converter.ts +1 -1
- package/backend/engine/adapters/copilot/stream.ts +1 -1
- package/backend/engine/adapters/qwen/message-converter.ts +1 -1
- package/backend/engine/adapters/qwen/stream.ts +1 -1
- package/backend/engine/docs/adapter-contract.md +2 -2
- package/backend/engine/docs/lessons-learned.md +3 -3
- package/backend/engine/docs/quick-reference.md +1 -1
- package/backend/engine/install-recipes.ts +26 -95
- package/backend/files/file-operations.test.ts +75 -0
- package/backend/files/file-operations.ts +10 -56
- package/backend/files/image-processing.test.ts +52 -0
- package/backend/files/image-processing.ts +11 -1
- package/backend/files/path-browsing.ts +141 -139
- package/backend/git/git-service.ts +13 -2
- package/backend/http/files-upload.test.ts +174 -0
- package/backend/http/files-upload.ts +27 -7
- package/backend/http/upload-temp-cleanup.ts +53 -0
- package/backend/index.ts +9 -1
- package/backend/mcp/README.md +67 -32
- package/backend/mcp/external/config.ts +200 -0
- package/backend/mcp/external/registry-client.ts +214 -0
- package/backend/mcp/external/types.ts +69 -0
- package/backend/mcp/index.ts +104 -19
- package/backend/mcp/{config.ts → internal/config.ts} +82 -18
- package/backend/mcp/internal/remote-server.test.ts +150 -0
- package/backend/mcp/{remote-server.ts → internal/remote-server.ts} +68 -0
- package/backend/mcp/{servers → internal/servers}/browser-automation/actions.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/browser-automation/browser.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/browser-automation/index.ts +2 -0
- package/backend/mcp/{servers → internal/servers}/browser-automation/inspection.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/helper.ts +11 -0
- package/backend/mcp/{servers → internal/servers}/index.ts +0 -2
- package/backend/mcp/{types.ts → internal/types.ts} +3 -3
- package/backend/mcp/shared/constants.ts +66 -0
- package/backend/projects/project-cleanup.ts +1 -1
- package/backend/terminal/pty-session-manager.ts +18 -11
- package/backend/ws/engine/index.ts +3 -1
- package/backend/ws/engine/restart.ts +54 -0
- package/backend/ws/files/index.ts +5 -0
- package/backend/ws/files/reveal.ts +61 -0
- package/backend/ws/files/search.test.ts +115 -0
- package/backend/ws/files/search.ts +77 -26
- package/backend/ws/files/write.ts +3 -1
- package/backend/ws/git/branch-name.ts +170 -0
- package/backend/ws/git/branch.ts +15 -2
- package/backend/ws/git/commit-message.ts +8 -2
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/index.ts +5 -1
- package/backend/ws/mcp/catalog.ts +56 -0
- package/backend/ws/mcp/crud.ts +174 -0
- package/backend/ws/mcp/index.ts +18 -0
- package/backend/ws/user/crud.ts +8 -4
- package/dist/assets/main-B7f2Gzb3.css +1 -0
- package/dist/assets/main-DYt1fDrp.js +383 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/git.ts +5 -0
- package/shared/types/git.ts +5 -0
- package/shared/types/stores/settings.ts +19 -0
- package/backend/mcp/servers/weather/get-temperature.ts +0 -56
- package/backend/mcp/servers/weather/index.ts +0 -31
- package/dist/assets/main-BgOiIS43.js +0 -360
- package/dist/assets/main-CJdJeen6.css +0 -1
- /package/backend/mcp/{output-validator.test.ts → internal/output-validator.test.ts} +0 -0
- /package/backend/mcp/{output-validator.ts → internal/output-validator.ts} +0 -0
- /package/backend/mcp/{project-context.test.ts → internal/project-context.test.ts} +0 -0
- /package/backend/mcp/{project-context.ts → internal/project-context.ts} +0 -0
|
@@ -80,6 +80,7 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
80
80
|
'engine:opencode-account-rename',
|
|
81
81
|
'engine:opencode-server-restart',
|
|
82
82
|
'engine:opencode-models-dev-fetch',
|
|
83
|
+
'engine:restart-all',
|
|
83
84
|
// Tunnel — remote/local management mutates global Cloudflare credentials,
|
|
84
85
|
// cloudflared auth, and ingress rules. Quick Tunnel is ephemeral and stays
|
|
85
86
|
// open. Read-only routes (status, *-list, ingress, auth-status) stay open so
|
|
@@ -97,7 +98,16 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
97
98
|
'tunnel:local:ingress:add',
|
|
98
99
|
'tunnel:local:ingress:remove',
|
|
99
100
|
'tunnel:local:start',
|
|
100
|
-
'tunnel:local:stop'
|
|
101
|
+
'tunnel:local:stop',
|
|
102
|
+
// External MCP — installing/removing servers from the official registry is a
|
|
103
|
+
// global, system-wide operation (it applies to every engine and project), so
|
|
104
|
+
// the whole surface is admin-only, mirroring System Tools and Engines.
|
|
105
|
+
'mcp:catalog',
|
|
106
|
+
'mcp:list',
|
|
107
|
+
'mcp:install',
|
|
108
|
+
'mcp:toggle',
|
|
109
|
+
'mcp:update-config',
|
|
110
|
+
'mcp:uninstall'
|
|
101
111
|
]);
|
|
102
112
|
|
|
103
113
|
/**
|
|
@@ -35,7 +35,7 @@ import type { DatabaseMessage } from '$shared/types/database/schema';
|
|
|
35
35
|
import { getProjectEngine, initializeProjectEngine } from '../engine';
|
|
36
36
|
import { messageQueries, sessionQueries } from '../database/queries';
|
|
37
37
|
import { snapshotService } from '../snapshot/snapshot-service';
|
|
38
|
-
import { projectContextService } from '../mcp
|
|
38
|
+
import { projectContextService } from '../mcp';
|
|
39
39
|
import { browserMcpControl } from '../preview';
|
|
40
40
|
import { extractMessageText } from '../snapshot/helpers';
|
|
41
41
|
import { debug } from '$shared/utils/logger';
|
|
@@ -649,14 +649,25 @@ class StreamManager extends EventEmitter {
|
|
|
649
649
|
// ── System Init ────────────────────────────────────────
|
|
650
650
|
case 'system_init': {
|
|
651
651
|
const initEvent = output as SystemInitEvent;
|
|
652
|
-
|
|
652
|
+
// Suppress the toast for "soft" statuses: `pending` (still
|
|
653
|
+
// connecting) and `needs-auth` (server expects OAuth/credentials
|
|
654
|
+
// configured in Settings → MCP). These are not errors — a scary
|
|
655
|
+
// toast for them is confusing. (Status is the raw SDK string,
|
|
656
|
+
// wider than the EngineOutput union, hence the cast.)
|
|
657
|
+
const SOFT_STATUSES = new Set(['pending', 'needs-auth']);
|
|
658
|
+
const failedServers = initEvent.mcpServers.filter(
|
|
659
|
+
s => s.status !== 'connected' && !SOFT_STATUSES.has(s.status as string)
|
|
660
|
+
);
|
|
661
|
+
initEvent.mcpServers
|
|
662
|
+
.filter(s => SOFT_STATUSES.has(s.status as string))
|
|
663
|
+
.forEach(s => debug.log('mcp', `MCP server "${s.name}" not ready (${s.status}) — suppressing toast`));
|
|
653
664
|
failedServers.forEach(server => {
|
|
654
665
|
debug.warn('mcp', `MCP server connection failed: ${server.name} (${server.status})`);
|
|
655
666
|
this.emitStreamEvent(streamState, 'notification', {
|
|
656
667
|
notification: {
|
|
657
668
|
type: 'warning',
|
|
658
669
|
title: 'MCP Server Connection Failed',
|
|
659
|
-
message: `Failed to connect to
|
|
670
|
+
message: `Failed to connect to MCP server "${server.name}".`,
|
|
660
671
|
},
|
|
661
672
|
timestamp: new Date().toISOString()
|
|
662
673
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Create mcp_servers table for external (user-installed) MCP servers';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
debug.log('migration', 'Creating mcp_servers table...');
|
|
8
|
+
db.exec(`
|
|
9
|
+
CREATE TABLE IF NOT EXISTS mcp_servers (
|
|
10
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11
|
+
slug TEXT NOT NULL UNIQUE,
|
|
12
|
+
name TEXT NOT NULL,
|
|
13
|
+
description TEXT,
|
|
14
|
+
registry_name TEXT,
|
|
15
|
+
version TEXT,
|
|
16
|
+
transport TEXT NOT NULL,
|
|
17
|
+
command TEXT,
|
|
18
|
+
args TEXT NOT NULL DEFAULT '[]',
|
|
19
|
+
env TEXT NOT NULL DEFAULT '{}',
|
|
20
|
+
url TEXT,
|
|
21
|
+
headers TEXT NOT NULL DEFAULT '{}',
|
|
22
|
+
source TEXT NOT NULL DEFAULT 'registry',
|
|
23
|
+
is_enabled INTEGER NOT NULL DEFAULT 1,
|
|
24
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
25
|
+
)
|
|
26
|
+
`);
|
|
27
|
+
debug.log('migration', 'mcp_servers table created');
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const down = (db: DatabaseConnection): void => {
|
|
31
|
+
debug.log('migration', 'Dropping mcp_servers table...');
|
|
32
|
+
db.exec('DROP TABLE IF EXISTS mcp_servers');
|
|
33
|
+
debug.log('migration', 'mcp_servers table dropped');
|
|
34
|
+
};
|
|
@@ -38,6 +38,7 @@ import * as migration036 from './036_create_auth_audit_log';
|
|
|
38
38
|
import * as migration037 from './037_repair_auth_audit_log_schema';
|
|
39
39
|
import * as migration038 from './038_add_workspace_state_to_user_projects';
|
|
40
40
|
import * as migration039 from './039_create_file_audit_log';
|
|
41
|
+
import * as migration040 from './040_create_mcp_servers_table';
|
|
41
42
|
|
|
42
43
|
// Export all migrations in order
|
|
43
44
|
export const migrations = [
|
|
@@ -274,6 +275,12 @@ export const migrations = [
|
|
|
274
275
|
description: migration039.description,
|
|
275
276
|
up: migration039.up,
|
|
276
277
|
down: migration039.down
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: '040',
|
|
281
|
+
description: migration040.description,
|
|
282
|
+
up: migration040.up,
|
|
283
|
+
down: migration040.down
|
|
277
284
|
}
|
|
278
285
|
];
|
|
279
286
|
|
|
@@ -11,4 +11,6 @@ export { authQueries } from './auth-queries';
|
|
|
11
11
|
export { dbClientConnectionQueries } from './db-client-connection-queries';
|
|
12
12
|
export { dbClientQueryHistoryQueries } from './db-client-query-history-queries';
|
|
13
13
|
export { auditLogQueries } from './audit-log-queries';
|
|
14
|
-
export { fileAuditLogQueries } from './file-audit-log-queries';
|
|
14
|
+
export { fileAuditLogQueries } from './file-audit-log-queries';
|
|
15
|
+
export { mcpServerQueries } from './mcp-server-queries';
|
|
16
|
+
export type { McpServerRow, McpServerInput, McpTransport, McpSource } from './mcp-server-queries';
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External MCP Server Queries
|
|
3
|
+
*
|
|
4
|
+
* CRUD for user-installed (external) MCP servers — the servers managed from
|
|
5
|
+
* Settings → MCP, sourced from the official MCP registry. This is distinct
|
|
6
|
+
* from the INTERNAL custom-tool servers in `backend/mcp/internal/servers/`,
|
|
7
|
+
* which are defined in code and not stored in the DB.
|
|
8
|
+
*
|
|
9
|
+
* Conventions:
|
|
10
|
+
* - `slug` : unique machine id, used to derive the `<slug>` MCP
|
|
11
|
+
* namespace. Only `[a-z0-9-]`.
|
|
12
|
+
* - `transport`: 'stdio' | 'http' | 'sse'.
|
|
13
|
+
* - `args`/`env`/`headers` are stored as JSON strings.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { getDatabase } from '../index';
|
|
17
|
+
|
|
18
|
+
export type McpTransport = 'stdio' | 'http' | 'sse';
|
|
19
|
+
export type McpSource = 'registry' | 'custom' | 'internal';
|
|
20
|
+
|
|
21
|
+
/** Raw DB row. */
|
|
22
|
+
export interface McpServerRow {
|
|
23
|
+
id: number;
|
|
24
|
+
slug: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string | null;
|
|
27
|
+
registry_name: string | null;
|
|
28
|
+
version: string | null;
|
|
29
|
+
transport: McpTransport;
|
|
30
|
+
command: string | null;
|
|
31
|
+
args: string;
|
|
32
|
+
env: string;
|
|
33
|
+
url: string | null;
|
|
34
|
+
headers: string;
|
|
35
|
+
source: McpSource;
|
|
36
|
+
is_enabled: number;
|
|
37
|
+
created_at: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface McpServerInput {
|
|
41
|
+
slug: string;
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string | null;
|
|
44
|
+
registryName?: string | null;
|
|
45
|
+
version?: string | null;
|
|
46
|
+
transport: McpTransport;
|
|
47
|
+
command?: string | null;
|
|
48
|
+
args?: string[];
|
|
49
|
+
env?: Record<string, string>;
|
|
50
|
+
url?: string | null;
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
source?: McpSource;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const mcpServerQueries = {
|
|
56
|
+
getAll(): McpServerRow[] {
|
|
57
|
+
const db = getDatabase();
|
|
58
|
+
return db.prepare(`SELECT * FROM mcp_servers ORDER BY created_at ASC`).all() as McpServerRow[];
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
getEnabled(): McpServerRow[] {
|
|
62
|
+
const db = getDatabase();
|
|
63
|
+
return db.prepare(`SELECT * FROM mcp_servers WHERE is_enabled = 1 ORDER BY created_at ASC`).all() as McpServerRow[];
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
getById(id: number): McpServerRow | null {
|
|
67
|
+
const db = getDatabase();
|
|
68
|
+
return db.prepare(`SELECT * FROM mcp_servers WHERE id = ?`).get(id) as McpServerRow | null;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
getBySlug(slug: string): McpServerRow | null {
|
|
72
|
+
const db = getDatabase();
|
|
73
|
+
return db.prepare(`SELECT * FROM mcp_servers WHERE slug = ?`).get(slug) as McpServerRow | null;
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
getBySource(source: McpSource): McpServerRow[] {
|
|
77
|
+
const db = getDatabase();
|
|
78
|
+
return db.prepare(`SELECT * FROM mcp_servers WHERE source = ? ORDER BY created_at ASC`).all(source) as McpServerRow[];
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
insert(input: McpServerInput): McpServerRow {
|
|
82
|
+
const db = getDatabase();
|
|
83
|
+
const result = db.prepare(
|
|
84
|
+
`INSERT INTO mcp_servers
|
|
85
|
+
(slug, name, description, registry_name, version, transport, command, args, env, url, headers, source)
|
|
86
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
87
|
+
).run(
|
|
88
|
+
input.slug,
|
|
89
|
+
input.name,
|
|
90
|
+
input.description ?? null,
|
|
91
|
+
input.registryName ?? null,
|
|
92
|
+
input.version ?? null,
|
|
93
|
+
input.transport,
|
|
94
|
+
input.command ?? null,
|
|
95
|
+
JSON.stringify(input.args ?? []),
|
|
96
|
+
JSON.stringify(input.env ?? {}),
|
|
97
|
+
input.url ?? null,
|
|
98
|
+
JSON.stringify(input.headers ?? {}),
|
|
99
|
+
input.source ?? 'registry'
|
|
100
|
+
) as { lastInsertRowid: number | bigint };
|
|
101
|
+
const id = Number(result.lastInsertRowid);
|
|
102
|
+
return this.getById(id)!;
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
setEnabled(id: number, enabled: boolean): void {
|
|
106
|
+
const db = getDatabase();
|
|
107
|
+
db.prepare(`UPDATE mcp_servers SET is_enabled = ? WHERE id = ?`).run(enabled ? 1 : 0, id);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/** Update the stored env (e.g. user-provided API keys) for a server. */
|
|
111
|
+
updateEnv(id: number, env: Record<string, string>): void {
|
|
112
|
+
const db = getDatabase();
|
|
113
|
+
db.prepare(`UPDATE mcp_servers SET env = ? WHERE id = ?`).run(JSON.stringify(env), id);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/** Update both env (stdio) and headers (remote auth) for a server. */
|
|
117
|
+
updateConfig(id: number, env: Record<string, string>, headers: Record<string, string>): void {
|
|
118
|
+
const db = getDatabase();
|
|
119
|
+
db.prepare(`UPDATE mcp_servers SET env = ?, headers = ? WHERE id = ?`).run(
|
|
120
|
+
JSON.stringify(env),
|
|
121
|
+
JSON.stringify(headers),
|
|
122
|
+
id
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
remove(id: number): void {
|
|
127
|
+
const db = getDatabase();
|
|
128
|
+
db.prepare(`DELETE FROM mcp_servers WHERE id = ?`).run(id);
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Insert or refresh an INTERNAL (code-defined) server row.
|
|
133
|
+
*
|
|
134
|
+
* Internal servers are defined in `backend/mcp/internal/servers/` — the DB
|
|
135
|
+
* row is only a mirror used for listing + the enable/disable toggle. On
|
|
136
|
+
* update we refresh the display metadata (title/description/version) but
|
|
137
|
+
* PRESERVE `is_enabled` so the user's toggle survives restarts. New rows
|
|
138
|
+
* default to enabled and `stdio` transport (they run in-process / via the
|
|
139
|
+
* `/mcp` bridge, surfaced to the user as "local (stdio)").
|
|
140
|
+
*/
|
|
141
|
+
upsertInternal(input: { slug: string; name: string; description: string | null; version: string }): McpServerRow {
|
|
142
|
+
const db = getDatabase();
|
|
143
|
+
const existing = this.getBySlug(input.slug);
|
|
144
|
+
if (existing) {
|
|
145
|
+
db.prepare(
|
|
146
|
+
`UPDATE mcp_servers SET name = ?, description = ?, version = ?, transport = 'stdio', source = 'internal' WHERE slug = ?`
|
|
147
|
+
).run(input.name, input.description, input.version, input.slug);
|
|
148
|
+
return this.getBySlug(input.slug)!;
|
|
149
|
+
}
|
|
150
|
+
db.prepare(
|
|
151
|
+
`INSERT INTO mcp_servers (slug, name, description, version, transport, source, is_enabled)
|
|
152
|
+
VALUES (?, ?, ?, ?, 'stdio', 'internal', 1)`
|
|
153
|
+
).run(input.slug, input.name, input.description, input.version);
|
|
154
|
+
return this.getBySlug(input.slug)!;
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/** Remove internal rows whose code definition no longer exists (keeps the slugs in `keep`). */
|
|
158
|
+
pruneInternalExcept(keep: string[]): void {
|
|
159
|
+
const db = getDatabase();
|
|
160
|
+
const rows = this.getBySource('internal');
|
|
161
|
+
const keepSet = new Set(keep);
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
if (!keepSet.has(row.slug)) db.prepare(`DELETE FROM mcp_servers WHERE id = ?`).run(row.id);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
package/backend/engine/README.md
CHANGED
|
@@ -97,13 +97,13 @@ Three key rules that **every** layer upholds:
|
|
|
97
97
|
> Two design pitfalls have repeatedly tripped people adding new adapters.
|
|
98
98
|
> Before sketching architecture, double-check:
|
|
99
99
|
>
|
|
100
|
-
> 1. **MCP over HTTP already exists.** `backend/mcp/remote-server.ts` mounts
|
|
100
|
+
> 1. **MCP over HTTP already exists.** `backend/mcp/internal/remote-server.ts` mounts
|
|
101
101
|
> every `defineServer()`-registered MCP server as a Streamable HTTP
|
|
102
102
|
> endpoint at `http://localhost:<port>/mcp`. OpenCode consumes it via
|
|
103
103
|
> `getOpenCodeMcpConfig()`. Any engine whose CLI/SDK accepts a
|
|
104
104
|
> `streamable-http` MCP URL (Codex, future engines) reuses **the same
|
|
105
105
|
> URL** by adding a sibling `getXxxMcpConfig()` helper in
|
|
106
|
-
> `backend/mcp/config.ts`. Do **NOT** propose a "new MCP bridge",
|
|
106
|
+
> `backend/mcp/internal/config.ts`. Do **NOT** propose a "new MCP bridge",
|
|
107
107
|
> "per-engine MCP server", or "per-stream MCP path". See §9.12.
|
|
108
108
|
> 2. **Shared CLI dotfiles are swapped from DB, not isolated.** When a CLI
|
|
109
109
|
> stores its credentials in a known location (e.g. `~/.codex/auth.json`),
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { join } from 'path';
|
|
11
|
-
import { isWindows, findGitBash } from '../../../terminal/shell-utils.js';
|
|
12
11
|
import { engineQueries } from '../../../database/queries';
|
|
13
12
|
import { debug } from '$shared/utils/logger';
|
|
14
13
|
import { getCleanSpawnEnv, getClopenDir } from '../../../utils/index.js';
|
|
@@ -104,22 +103,6 @@ async function _doSetup(): Promise<void> {
|
|
|
104
103
|
debug.warn('engine', '⚠️ Claude Code: Could not read active account (DB may not be ready)');
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
// Setup Git Bash on Windows
|
|
108
|
-
if (isWindows) {
|
|
109
|
-
const existingPath = process.env.CLAUDE_CODE_GIT_BASH_PATH;
|
|
110
|
-
if (existingPath) {
|
|
111
|
-
overrides['CLAUDE_CODE_GIT_BASH_PATH'] = existingPath;
|
|
112
|
-
} else {
|
|
113
|
-
const gitBashPath = await findGitBash();
|
|
114
|
-
if (gitBashPath) {
|
|
115
|
-
overrides['CLAUDE_CODE_GIT_BASH_PATH'] = gitBashPath;
|
|
116
|
-
debug.log('engine', '✅ Claude Code: Git Bash configured at:', gitBashPath);
|
|
117
|
-
} else {
|
|
118
|
-
debug.warn('engine', '⚠️ Claude Code: Git Bash not found - may have limited functionality on Windows');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
106
|
// Terminal environment variables
|
|
124
107
|
overrides['FORCE_COLOR'] = '1';
|
|
125
108
|
overrides['COLORTERM'] = 'truecolor';
|
|
@@ -17,10 +17,6 @@ export function handleStreamError(error: unknown): void {
|
|
|
17
17
|
throw new Error('Unexpected conversation limit reached. This should not happen with unlimited turns enabled.');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
if (error.message.includes('git-bash') || error.message.includes('requires git-bash')) {
|
|
21
|
-
throw new Error('Claude Code requires git-bash on Windows. Please ensure Git is installed and accessible.');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
if (error.message.includes('ENOENT') || error.message.includes('spawn claude-code')) {
|
|
25
21
|
throw new Error('Claude Agent SDK not found. Please install it with: npm install @anthropic-ai/claude-agent-sdk');
|
|
26
22
|
}
|
|
@@ -75,7 +75,7 @@ import type {
|
|
|
75
75
|
ThreadStartedEvent,
|
|
76
76
|
TurnCompletedEvent,
|
|
77
77
|
} from '@openai/codex-sdk';
|
|
78
|
-
import { resolveOpenCodeToolName } from '../../../mcp
|
|
78
|
+
import { resolveOpenCodeToolName } from '../../../mcp';
|
|
79
79
|
import { readLastTokenUsageFromRollout } from './usage-rollout';
|
|
80
80
|
import { readApplyPatchesFromRollout, findMatchingPatch } from './patch-rollout';
|
|
81
81
|
|
|
@@ -26,7 +26,7 @@ import { extractJson } from '../../structured-helpers';
|
|
|
26
26
|
import { engineQueries } from '$backend/database/queries/engine-queries';
|
|
27
27
|
import { resolveOsPath } from '$backend/utils/paths';
|
|
28
28
|
import { resolveBinary } from '$backend/utils/cli';
|
|
29
|
-
import { getCodexMcpConfig } from '../../../mcp
|
|
29
|
+
import { getCodexMcpConfig } from '../../../mcp';
|
|
30
30
|
import { CODEX_MODELS } from './models';
|
|
31
31
|
import { debug } from '$shared/utils/logger';
|
|
32
32
|
import { handleStreamError, buildTurnError } from './error-handler';
|
|
@@ -49,7 +49,7 @@ import type {
|
|
|
49
49
|
} from '$shared/types/unified';
|
|
50
50
|
import { toCanonicalToolName } from '$shared/types/unified';
|
|
51
51
|
import type { SessionEvent } from '@github/copilot-sdk';
|
|
52
|
-
import { resolveOpenCodeToolName } from '../../../mcp
|
|
52
|
+
import { resolveOpenCodeToolName } from '../../../mcp';
|
|
53
53
|
|
|
54
54
|
// Derive data payload types from the SessionEvent discriminated union so we
|
|
55
55
|
// don't depend on internal type re-exports that aren't part of the SDK's
|
|
@@ -20,7 +20,7 @@ import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
|
20
20
|
import { engineQueries } from '$backend/database/queries/engine-queries';
|
|
21
21
|
import { resolveOsPath } from '$backend/utils/paths';
|
|
22
22
|
import { debug } from '$shared/utils/logger';
|
|
23
|
-
import { getCopilotMcpConfig } from '../../../mcp
|
|
23
|
+
import { getCopilotMcpConfig } from '../../../mcp';
|
|
24
24
|
import { handleStreamError, buildSessionError } from './error-handler';
|
|
25
25
|
import { fetchCopilotModels } from './models';
|
|
26
26
|
|
|
@@ -51,7 +51,7 @@ import type {
|
|
|
51
51
|
AskUserQuestion,
|
|
52
52
|
} from '$shared/types/unified';
|
|
53
53
|
import { toCanonicalToolName } from '$shared/types/unified';
|
|
54
|
-
import { resolveOpenCodeToolName } from '../../../mcp
|
|
54
|
+
import { resolveOpenCodeToolName } from '../../../mcp';
|
|
55
55
|
|
|
56
56
|
// ============================================================
|
|
57
57
|
// Qwen-specific tool-result content markers
|
|
@@ -45,7 +45,7 @@ import { getEngineEnv } from './environment';
|
|
|
45
45
|
import { handleStreamError } from './error-handler';
|
|
46
46
|
import { createSdkMessageConverter, toSdkUserMessage, type SdkMessageConverter } from './message-converter';
|
|
47
47
|
import { fetchQwenModels } from './models';
|
|
48
|
-
import { getQwenMcpConfig } from '../../../mcp
|
|
48
|
+
import { getQwenMcpConfig } from '../../../mcp';
|
|
49
49
|
import { forkQwenSessionState, sessionStateExists } from './session-fork';
|
|
50
50
|
|
|
51
51
|
interface PendingAskUserQuestion {
|
|
@@ -122,8 +122,8 @@ calling `getEnabledMcpServers(options.mcpContext)`.
|
|
|
122
122
|
- ❌ Use `console.*` — use `debug` from `$shared/utils/logger` with
|
|
123
123
|
category `'engine'`, `'chat'`, or `'mcp'`.
|
|
124
124
|
- ❌ **Build a new MCP HTTP server for the adapter.** Use the existing
|
|
125
|
-
`backend/mcp/remote-server.ts` and add a `getXxxMcpConfig()` helper in
|
|
126
|
-
`backend/mcp/config.ts` returning the URL in the engine's expected
|
|
125
|
+
`backend/mcp/internal/remote-server.ts` and add a `getXxxMcpConfig()` helper in
|
|
126
|
+
`backend/mcp/internal/config.ts` returning the URL in the engine's expected
|
|
127
127
|
shape. New MCP servers are added via `defineServer()` — never via a
|
|
128
128
|
parallel HTTP listener.
|
|
129
129
|
- ❌ **Create per-account isolated home directories** to multiplex two
|
|
@@ -352,7 +352,7 @@ async dispose(): Promise<void> {
|
|
|
352
352
|
|
|
353
353
|
### 9.12 Reuse the existing MCP HTTP infrastructure — never build a new bridge
|
|
354
354
|
|
|
355
|
-
`backend/mcp/remote-server.ts` already mounts every server registered via
|
|
355
|
+
`backend/mcp/internal/remote-server.ts` already mounts every server registered via
|
|
356
356
|
`defineServer()` as a **Streamable HTTP MCP** endpoint at
|
|
357
357
|
`http://localhost:<port>/mcp`. OpenCode consumes it via
|
|
358
358
|
`getOpenCodeMcpConfig()`. Tool handlers run **in-process** in the Clopen
|
|
@@ -383,9 +383,9 @@ When you add an engine whose CLI/SDK accepts a streamable-http MCP URL
|
|
|
383
383
|
- In the adapter, name the local variable holding the helper's return
|
|
384
384
|
value **`mcpConfig`**, not `mcpServers`. The latter shadows both the
|
|
385
385
|
SDK's config field name AND the registry exported from
|
|
386
|
-
`backend/mcp/config.ts`, and reads as a bug at the call site.
|
|
386
|
+
`backend/mcp/internal/config.ts`, and reads as a bug at the call site.
|
|
387
387
|
|
|
388
|
-
2. Use `resolveOpenCodeToolName()` (in `backend/mcp/config.ts`) on
|
|
388
|
+
2. Use `resolveOpenCodeToolName()` (in `backend/mcp/internal/config.ts`) on
|
|
389
389
|
incoming tool names; it strips the `clopen-mcp_` / `clopen-mcp-`
|
|
390
390
|
prefix and reverse-maps to `mcp__<server>__<tool>`. The same helper
|
|
391
391
|
works for any engine that uses the same naming convention.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
| Fork session (native vs. on-disk workaround) | `claude/stream.ts` (`forkSession: true`), `opencode/stream.ts` (`client.session.fork`), `copilot/stream.ts` (`client.rpc.sessions.fork`), `codex/session-fork.ts` + `qwen/session-fork.ts` (copy disk state) |
|
|
17
17
|
| Sub-agent (`Task`/`Agent`) routing | `claude/message-converter.ts` (`parent_tool_use_id`), `opencode/message-converter.ts::convertSubtaskToolUseOnly`, `copilot/message-converter.ts::resolveParentToolUseId` + `agentParentMap` (see §9.15) |
|
|
18
18
|
| AskUserQuestion event + HTTP fallback | `opencode/stream.ts::resolveUserAnswer`, `claude/stream.ts::canUseTool` |
|
|
19
|
-
| MCP servers exposed over HTTP (single source) | `backend/mcp/remote-server.ts`, `backend/mcp/config.ts::getOpenCodeMcpConfig` (and future `getXxxMcpConfig`) |
|
|
19
|
+
| MCP servers exposed over HTTP (single source) | `backend/mcp/internal/remote-server.ts`, `backend/mcp/internal/config.ts::getOpenCodeMcpConfig` (and future `getXxxMcpConfig`) |
|
|
20
20
|
| Auth-blob swap into shared CLI dotfile | Pattern only (no implementation yet); see §3.3 callout + §9.13 |
|
|
21
21
|
| Restart-Server pattern (long-lived engines) | `backend/ws/engine/opencode/providers.ts::engine:opencode-server-restart`, `frontend/components/chat/input/components/EngineModelPicker.svelte::restartOCServer`, `AIEnginesSettings.svelte::handleRestartServer`/`forceRestartServer` |
|
|
22
22
|
| `generateStructured` (no tools, JSON) | `claude/stream.ts::generateStructured` (native `outputFormat`), `codex/stream.ts::generateStructured` (native `outputSchema`), `opencode/stream.ts::generateStructured` + `copilot/stream.ts::generateStructured` + `qwen/stream.ts::generateStructured` (prompt-engineered via `backend/engine/structured-helpers.ts`). See §9.16 for the strict-schema + part-fallback gotchas. |
|
|
@@ -343,72 +343,33 @@ function attachCurlRequirement(base: Recipe, toolLabel: string): boolean {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
async function resolveClaudeRecipe(): Promise<Recipe> {
|
|
346
|
-
|
|
346
|
+
return {
|
|
347
347
|
tool: 'claude',
|
|
348
|
-
autoInstallable:
|
|
348
|
+
autoInstallable: true,
|
|
349
349
|
missingPrereqs: [],
|
|
350
|
-
manualInstructions: [
|
|
350
|
+
manualInstructions: [{
|
|
351
|
+
label: 'bun',
|
|
352
|
+
command: 'bun add -g @anthropic-ai/claude-code',
|
|
353
|
+
docs: 'https://code.claude.com/docs/en/setup'
|
|
354
|
+
}],
|
|
355
|
+
command: ['bun', 'add', '-g', '@anthropic-ai/claude-code'],
|
|
356
|
+
displayCommand: 'bun add -g @anthropic-ai/claude-code'
|
|
351
357
|
};
|
|
352
|
-
|
|
353
|
-
if (process.platform === 'win32') {
|
|
354
|
-
base.autoInstallable = true;
|
|
355
|
-
base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
|
|
356
|
-
base.command = ['irm https://claude.ai/install.ps1 | iex'];
|
|
357
|
-
base.displayCommand = 'irm https://claude.ai/install.ps1 | iex';
|
|
358
|
-
base.manualInstructions.push({
|
|
359
|
-
label: 'PowerShell',
|
|
360
|
-
command: 'irm https://claude.ai/install.ps1 | iex',
|
|
361
|
-
docs: 'https://docs.claude.com/en/docs/claude-code/overview'
|
|
362
|
-
});
|
|
363
|
-
return base;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// macOS / Linux
|
|
367
|
-
base.manualInstructions.push({
|
|
368
|
-
label: 'curl + bash',
|
|
369
|
-
command: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
370
|
-
docs: 'https://docs.claude.com/en/docs/claude-code/overview'
|
|
371
|
-
});
|
|
372
|
-
if (!attachCurlRequirement(base, 'Claude Code')) return base;
|
|
373
|
-
|
|
374
|
-
base.autoInstallable = true;
|
|
375
|
-
base.shell = { program: 'bash', args: ['-c'] };
|
|
376
|
-
base.command = ['curl -fsSL https://claude.ai/install.sh | bash'];
|
|
377
|
-
base.displayCommand = 'curl -fsSL https://claude.ai/install.sh | bash';
|
|
378
|
-
return base;
|
|
379
358
|
}
|
|
380
359
|
|
|
381
360
|
async function resolveOpenCodeRecipe(): Promise<Recipe> {
|
|
382
361
|
const base: Recipe = {
|
|
383
362
|
tool: 'opencode',
|
|
384
|
-
autoInstallable:
|
|
363
|
+
autoInstallable: true,
|
|
385
364
|
missingPrereqs: [],
|
|
386
365
|
manualInstructions: [{
|
|
387
|
-
label: '
|
|
388
|
-
command: '
|
|
389
|
-
docs: 'https://opencode.ai'
|
|
390
|
-
}]
|
|
366
|
+
label: 'bun',
|
|
367
|
+
command: 'bun add -g opencode-ai',
|
|
368
|
+
docs: 'https://opencode.ai/docs'
|
|
369
|
+
}],
|
|
370
|
+
command: ['bun', 'add', '-g', 'opencode-ai'],
|
|
371
|
+
displayCommand: 'bun add -g opencode-ai'
|
|
391
372
|
};
|
|
392
|
-
|
|
393
|
-
if (process.platform === 'win32') {
|
|
394
|
-
base.autoInstallable = true;
|
|
395
|
-
base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
|
|
396
|
-
base.command = ['irm https://opencode.ai/install.ps1 | iex'];
|
|
397
|
-
base.displayCommand = 'irm https://opencode.ai/install.ps1 | iex';
|
|
398
|
-
base.manualInstructions.push({
|
|
399
|
-
label: 'PowerShell',
|
|
400
|
-
command: 'irm https://opencode.ai/install.ps1 | iex',
|
|
401
|
-
docs: 'https://opencode.ai'
|
|
402
|
-
});
|
|
403
|
-
return base;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (!attachCurlRequirement(base, 'OpenCode')) return base;
|
|
407
|
-
|
|
408
|
-
base.autoInstallable = true;
|
|
409
|
-
base.shell = { program: 'bash', args: ['-c'] };
|
|
410
|
-
base.command = ['curl -fsSL https://opencode.ai/install | bash'];
|
|
411
|
-
base.displayCommand = 'curl -fsSL https://opencode.ai/install | bash';
|
|
412
373
|
return base;
|
|
413
374
|
}
|
|
414
375
|
|
|
@@ -429,60 +390,30 @@ async function resolveCopilotRecipe(): Promise<Recipe> {
|
|
|
429
390
|
}
|
|
430
391
|
|
|
431
392
|
async function resolveQwenRecipe(): Promise<Recipe> {
|
|
432
|
-
const manualInstructions: ManualInstruction[] = [{
|
|
433
|
-
label: 'bun',
|
|
434
|
-
command: 'bun add -g @qwen-code/qwen-code',
|
|
435
|
-
docs: 'https://github.com/QwenLM/qwen-code'
|
|
436
|
-
}];
|
|
437
|
-
|
|
438
|
-
// Qwen Code CLI ships bundled with `@qwen-code/sdk` from v0.1.1+ so the
|
|
439
|
-
// SDK path doesn't need a standalone install. We still expose this recipe
|
|
440
|
-
// for users who prefer the standalone CLI for `qwen-oauth` / shell use.
|
|
441
|
-
if (!resolveBinary('bun')) {
|
|
442
|
-
return {
|
|
443
|
-
tool: 'qwen',
|
|
444
|
-
autoInstallable: false,
|
|
445
|
-
unavailableReason: 'Bun is required to install the Qwen Code CLI. Install Bun first (https://bun.sh).',
|
|
446
|
-
missingPrereqs: [],
|
|
447
|
-
manualInstructions
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
|
|
451
393
|
return {
|
|
452
394
|
tool: 'qwen',
|
|
453
395
|
autoInstallable: true,
|
|
454
396
|
missingPrereqs: [],
|
|
455
|
-
manualInstructions
|
|
397
|
+
manualInstructions: [{
|
|
398
|
+
label: 'bun',
|
|
399
|
+
command: 'bun add -g @qwen-code/qwen-code',
|
|
400
|
+
docs: 'https://qwen.ai/qwencode'
|
|
401
|
+
}],
|
|
456
402
|
command: ['bun', 'add', '-g', '@qwen-code/qwen-code'],
|
|
457
403
|
displayCommand: 'bun add -g @qwen-code/qwen-code'
|
|
458
404
|
};
|
|
459
405
|
}
|
|
460
406
|
|
|
461
407
|
async function resolveCodexRecipe(): Promise<Recipe> {
|
|
462
|
-
const manualInstructions: ManualInstruction[] = [{
|
|
463
|
-
label: 'bun',
|
|
464
|
-
command: 'bun add -g @openai/codex',
|
|
465
|
-
docs: 'https://developers.openai.com/codex'
|
|
466
|
-
}];
|
|
467
|
-
|
|
468
|
-
// Codex CLI is installed via `bun add -g`. Bun must be on PATH for the
|
|
469
|
-
// auto-installer to work; otherwise we fall back to the manual instructions
|
|
470
|
-
// (the user installs Bun first via the existing Bun recipe / website).
|
|
471
|
-
if (!resolveBinary('bun')) {
|
|
472
|
-
return {
|
|
473
|
-
tool: 'codex',
|
|
474
|
-
autoInstallable: false,
|
|
475
|
-
unavailableReason: 'Bun is required to install the Codex CLI. Install Bun first (https://bun.sh).',
|
|
476
|
-
missingPrereqs: [],
|
|
477
|
-
manualInstructions
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
408
|
return {
|
|
482
409
|
tool: 'codex',
|
|
483
410
|
autoInstallable: true,
|
|
484
411
|
missingPrereqs: [],
|
|
485
|
-
manualInstructions
|
|
412
|
+
manualInstructions: [{
|
|
413
|
+
label: 'bun',
|
|
414
|
+
command: 'bun add -g @openai/codex',
|
|
415
|
+
docs: 'https://developers.openai.com/codex/quickstart'
|
|
416
|
+
}],
|
|
486
417
|
command: ['bun', 'add', '-g', '@openai/codex'],
|
|
487
418
|
displayCommand: 'bun add -g @openai/codex'
|
|
488
419
|
};
|