@agent-deck/cli 2.4.0 → 2.5.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/dist/agent-harness.js +1 -1
- package/dist/codex-plugin.d.ts +30 -8
- package/dist/codex-plugin.d.ts.map +1 -1
- package/dist/codex-plugin.js +141 -22
- package/dist/codex-plugin.js.map +1 -1
- package/dist/cursor-mcp-inspect.d.ts +7 -6
- package/dist/cursor-mcp-inspect.d.ts.map +1 -1
- package/dist/cursor-mcp-inspect.js +59 -30
- package/dist/cursor-mcp-inspect.js.map +1 -1
- package/dist/debug-mcp.d.ts.map +1 -1
- package/dist/debug-mcp.js +50 -12
- package/dist/debug-mcp.js.map +1 -1
- package/dist/host-connection.d.ts +159 -0
- package/dist/host-connection.d.ts.map +1 -0
- package/dist/host-connection.js +568 -0
- package/dist/host-connection.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/launcher-migration.d.ts +65 -0
- package/dist/launcher-migration.d.ts.map +1 -0
- package/dist/launcher-migration.js +383 -0
- package/dist/launcher-migration.js.map +1 -0
- package/dist/mcp-bridge.d.ts.map +1 -1
- package/dist/mcp-bridge.js +5 -0
- package/dist/mcp-bridge.js.map +1 -1
- package/dist/mcp-config.d.ts +120 -52
- package/dist/mcp-config.d.ts.map +1 -1
- package/dist/mcp-config.js +562 -195
- package/dist/mcp-config.js.map +1 -1
- package/dist/mcp-launcher.d.ts.map +1 -1
- package/dist/mcp-launcher.js +7 -0
- package/dist/mcp-launcher.js.map +1 -1
- package/dist/menubar.d.ts +7 -0
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +11 -1
- package/dist/menubar.js.map +1 -1
- package/dist/muse-skills/agent-deck-session/SKILL.md +9 -6
- package/dist/muse-skills/agent-deck-setup/SKILL.md +21 -5
- package/dist/setup.d.ts +3 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +152 -42
- package/dist/setup.js.map +1 -1
- package/dist/start.d.ts +4 -1
- package/dist/start.d.ts.map +1 -1
- package/dist/start.js +25 -4
- package/dist/start.js.map +1 -1
- package/dist/upgrade-scan.d.ts +20 -0
- package/dist/upgrade-scan.d.ts.map +1 -0
- package/dist/upgrade-scan.js +113 -0
- package/dist/upgrade-scan.js.map +1 -0
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +89 -5
- package/dist/upgrade.js.map +1 -1
- package/dist/use.d.ts +1 -1
- package/dist/use.d.ts.map +1 -1
- package/dist/use.js +92 -48
- package/dist/use.js.map +1 -1
- package/package.json +3 -3
- package/dist/coordinator.d.ts +0 -2
- package/dist/coordinator.d.ts.map +0 -1
- package/dist/coordinator.js +0 -153
- package/dist/coordinator.js.map +0 -1
- package/dist/grant-issue.d.ts +0 -39
- package/dist/grant-issue.d.ts.map +0 -1
- package/dist/grant-issue.js +0 -133
- package/dist/grant-issue.js.map +0 -1
- package/dist/grant-store.d.ts +0 -35
- package/dist/grant-store.d.ts.map +0 -1
- package/dist/grant-store.js +0 -302
- package/dist/grant-store.js.map +0 -1
- package/dist/run-adapter.d.ts +0 -100
- package/dist/run-adapter.d.ts.map +0 -1
- package/dist/run-adapter.js +0 -73
- package/dist/run-adapter.js.map +0 -1
- package/dist/run-claude.d.ts +0 -41
- package/dist/run-claude.d.ts.map +0 -1
- package/dist/run-claude.js +0 -91
- package/dist/run-claude.js.map +0 -1
- package/dist/run-codex.d.ts +0 -75
- package/dist/run-codex.d.ts.map +0 -1
- package/dist/run-codex.js +0 -337
- package/dist/run-codex.js.map +0 -1
- package/dist/run-cursor.d.ts +0 -79
- package/dist/run-cursor.d.ts.map +0 -1
- package/dist/run-cursor.js +0 -455
- package/dist/run-cursor.js.map +0 -1
- package/dist/run-muse.d.ts +0 -127
- package/dist/run-muse.d.ts.map +0 -1
- package/dist/run-muse.js +0 -499
- package/dist/run-muse.js.map +0 -1
package/dist/mcp-config.js
CHANGED
|
@@ -7,22 +7,33 @@ exports.MUSE_SCHEMA_VERSION = exports.CURSOR_MCP_RECOVERY_HINT = void 0;
|
|
|
7
7
|
exports.buildMcpUrl = buildMcpUrl;
|
|
8
8
|
exports.resolveMuseGlobalConfigDir = resolveMuseGlobalConfigDir;
|
|
9
9
|
exports.resolveConfigPath = resolveConfigPath;
|
|
10
|
+
exports.buildCodexAgentDeckEntry = buildCodexAgentDeckEntry;
|
|
11
|
+
exports.buildGlobalFallbackHttpEntry = buildGlobalFallbackHttpEntry;
|
|
10
12
|
exports.buildAgentDeckEntry = buildAgentDeckEntry;
|
|
13
|
+
exports.isHttpAgentDeckEntry = isHttpAgentDeckEntry;
|
|
14
|
+
exports.readHttpWorkspaceHeader = readHttpWorkspaceHeader;
|
|
11
15
|
exports.isLegacyBareHttpAgentDeckEntry = isLegacyBareHttpAgentDeckEntry;
|
|
12
16
|
exports.isMcpLaunchEntry = isMcpLaunchEntry;
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.formatCursorGlobalMcpEnsureMessage = formatCursorGlobalMcpEnsureMessage;
|
|
17
|
+
exports.isLegacyClaudeLaunchEntry = isLegacyClaudeLaunchEntry;
|
|
18
|
+
exports.isLegacyMuseLaunchEntry = isLegacyMuseLaunchEntry;
|
|
16
19
|
exports.readJsonFile = readJsonFile;
|
|
17
20
|
exports.mergeMuseServerConfig = mergeMuseServerConfig;
|
|
18
21
|
exports.mergeMcpServerConfig = mergeMcpServerConfig;
|
|
19
22
|
exports.writeJsonFile = writeJsonFile;
|
|
23
|
+
exports.readTextFile = readTextFile;
|
|
24
|
+
exports.writeTextFile = writeTextFile;
|
|
25
|
+
exports.escapeTomlBasicString = escapeTomlBasicString;
|
|
26
|
+
exports.formatCodexMcpSection = formatCodexMcpSection;
|
|
27
|
+
exports.formatCodexGlobalFallbackSection = formatCodexGlobalFallbackSection;
|
|
28
|
+
exports.codexTomlHasAgentDeckEntry = codexTomlHasAgentDeckEntry;
|
|
29
|
+
exports.codexTomlHasLauncherEntry = codexTomlHasLauncherEntry;
|
|
30
|
+
exports.mergeCodexTomlConfig = mergeCodexTomlConfig;
|
|
20
31
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
21
32
|
const node_os_1 = __importDefault(require("node:os"));
|
|
22
33
|
const node_path_1 = __importDefault(require("node:path"));
|
|
23
34
|
const strip_ansi_1 = require("./strip-ansi");
|
|
24
|
-
/** Shared recovery sentence for Cursor MCP diagnostics and docs (NOT-50). */
|
|
25
|
-
exports.CURSOR_MCP_RECOVERY_HINT =
|
|
35
|
+
/** Shared recovery sentence for Cursor MCP diagnostics and docs (NOT-50, pure-MCP form NOT-567). */
|
|
36
|
+
exports.CURSOR_MCP_RECOVERY_HINT = 'If Agent Deck tools are missing in Cursor, run `agent-deck setup --client cursor`, approve the project agent-deck server, run `agent-deck use <deck>` in the folder, then reload MCP.';
|
|
26
37
|
/** Muse user settings require this exact schema version (NOT-387). */
|
|
27
38
|
exports.MUSE_SCHEMA_VERSION = 1;
|
|
28
39
|
function buildMcpUrl({ host, mcpPort }) {
|
|
@@ -57,74 +68,146 @@ function resolveConfigPath(client, scope, cwd = process.cwd()) {
|
|
|
57
68
|
return node_path_1.default.join(cwd, '.mcp.json');
|
|
58
69
|
}
|
|
59
70
|
return node_path_1.default.join(resolveMuseGlobalConfigDir(home), 'muse', 'settings.json');
|
|
71
|
+
case 'codex':
|
|
72
|
+
return scope === 'project'
|
|
73
|
+
? node_path_1.default.join(cwd, '.codex', 'config.toml')
|
|
74
|
+
: node_path_1.default.join(home, '.codex', 'config.toml');
|
|
60
75
|
default:
|
|
61
76
|
throw new Error(`Unsupported client: ${client}`);
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
80
|
+
* Pure-HTTP entry for a Codex project config (`<folder>/.codex/config.toml`).
|
|
81
|
+
* The daemon resolves the deck from `.agent-deck/use.json` — no deck id here.
|
|
82
|
+
*/
|
|
83
|
+
function buildCodexAgentDeckEntry(endpoint, options) {
|
|
84
|
+
return {
|
|
85
|
+
url: buildMcpUrl(endpoint),
|
|
86
|
+
http_headers: {
|
|
87
|
+
'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Global headerless HTTP fallback entry (NOT-565, design §4): folders with
|
|
93
|
+
* no assignment connect everywhere over pure MCP and land in the existing
|
|
94
|
+
* unassigned (explain-only) session. No headers, no executable lookup.
|
|
95
|
+
* Per-folder entries written by `agent-deck use` use the same server name,
|
|
96
|
+
* so they shadow this fallback where an assignment exists.
|
|
97
|
+
*/
|
|
98
|
+
function buildGlobalFallbackHttpEntry(endpoint) {
|
|
99
|
+
return {
|
|
100
|
+
type: 'http',
|
|
101
|
+
url: buildMcpUrl(endpoint),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* MCP client entry for the agent-deck server. Codex, Claude, Cursor, and
|
|
106
|
+
* Muse connect over pure HTTP (NOT-563/565/567/570/571): the workspace
|
|
107
|
+
* header names the folder and the daemon resolves the deck from
|
|
108
|
+
* `.agent-deck/use.json` — no deck id in tracked config, no executable
|
|
109
|
+
* lookup.
|
|
110
|
+
*
|
|
111
|
+
* A `workspaceRoot` selects the per-folder HTTP form; without one the
|
|
112
|
+
* client gets the global headerless HTTP fallback (NOT-565/567/570).
|
|
113
|
+
* Claude Desktop still uses the trusted local launcher, which reads the
|
|
114
|
+
* folder assignment at runtime. The retired Muse launcher shape (NOT-387:
|
|
115
|
+
* command/args/env only, no type or workspace pin) is never built —
|
|
116
|
+
* legacy entries are detected with {@link isLegacyMuseLaunchEntry} and
|
|
117
|
+
* converted by the upgrade path (NOT-572).
|
|
67
118
|
*/
|
|
68
119
|
function buildAgentDeckEntry(client, endpoint, options) {
|
|
120
|
+
if (client === 'codex') {
|
|
121
|
+
if (!options?.workspaceRoot) {
|
|
122
|
+
throw new Error('buildAgentDeckEntry(codex) requires options.workspaceRoot for the x-agent-deck-workspace header');
|
|
123
|
+
}
|
|
124
|
+
return buildCodexAgentDeckEntry(endpoint, { workspaceRoot: options.workspaceRoot });
|
|
125
|
+
}
|
|
69
126
|
if (client === 'claude-desktop') {
|
|
70
127
|
return {
|
|
71
128
|
command: 'agent-deck',
|
|
72
129
|
args: ['mcp-launch'],
|
|
73
130
|
};
|
|
74
131
|
}
|
|
75
|
-
if (client === 'muse') {
|
|
76
|
-
// Muse
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}
|
|
132
|
+
if (client === 'muse' || client === 'claude') {
|
|
133
|
+
// NOT-571: Muse writes the identical entry Claude writes (NOT-563) —
|
|
134
|
+
// the same <folder>/.mcp.json, the same shape — so the two clients no
|
|
135
|
+
// longer overwrite each other's agent-deck entry.
|
|
136
|
+
if (options?.workspaceRoot) {
|
|
137
|
+
// Per-folder pure-MCP entry: the daemon resolves the deck from
|
|
138
|
+
// `.agent-deck/use.json` — no deck id in the file.
|
|
139
|
+
return {
|
|
140
|
+
type: 'http',
|
|
141
|
+
url: buildMcpUrl(endpoint),
|
|
142
|
+
headers: {
|
|
143
|
+
'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Global setup fallback: headerless pure HTTP, no launcher and no
|
|
148
|
+
// executable lookup. (The per-folder form above already returned, so
|
|
149
|
+
// no workspaceRoot is in scope here.)
|
|
150
|
+
return buildGlobalFallbackHttpEntry(endpoint);
|
|
90
151
|
}
|
|
91
|
-
if (client === '
|
|
92
|
-
const env = {
|
|
93
|
-
AGENT_DECK_MCP_PORT: String(endpoint.mcpPort),
|
|
94
|
-
AGENT_DECK_HOST: endpoint.host,
|
|
95
|
-
};
|
|
152
|
+
if (client === 'cursor') {
|
|
96
153
|
if (options?.workspaceRoot) {
|
|
97
|
-
|
|
154
|
+
// NOT-567 per-folder pure-MCP entry: the daemon resolves the deck
|
|
155
|
+
// from `.agent-deck/use.json` — no deck id in the file. Cursor
|
|
156
|
+
// does not interpolate `${workspaceFolder}` in header values, so
|
|
157
|
+
// the absolute folder path is written out.
|
|
158
|
+
return {
|
|
159
|
+
url: buildMcpUrl(endpoint),
|
|
160
|
+
headers: {
|
|
161
|
+
'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
98
164
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
165
|
+
// NOT-567 global setup fallback: headerless pure HTTP, no launcher
|
|
166
|
+
// and no executable lookup. Unassigned folders connect through it
|
|
167
|
+
// and land in the explain-only session.
|
|
168
|
+
return {
|
|
169
|
+
url: buildMcpUrl(endpoint),
|
|
104
170
|
};
|
|
105
|
-
return entry;
|
|
106
171
|
}
|
|
107
|
-
|
|
108
|
-
AGENT_DECK_MCP_PORT: String(endpoint.mcpPort),
|
|
109
|
-
AGENT_DECK_HOST: endpoint.host,
|
|
110
|
-
};
|
|
111
|
-
if (options?.workspaceRoot) {
|
|
112
|
-
env.AGENT_DECK_WORKSPACE = node_path_1.default.resolve(options.workspaceRoot);
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
command: 'agent-deck',
|
|
116
|
-
args: ['mcp-launch'],
|
|
117
|
-
env,
|
|
118
|
-
};
|
|
172
|
+
throw new Error(`Unsupported client: ${client}`);
|
|
119
173
|
}
|
|
120
|
-
/**
|
|
121
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Pure-MCP HTTP entry (NOT-567): a `url` with no `command` — the
|
|
176
|
+
* per-folder entry carrying the workspace header, or the headerless
|
|
177
|
+
* global fallback. No executable lookup on the connection path.
|
|
178
|
+
*/
|
|
179
|
+
function isHttpAgentDeckEntry(entry) {
|
|
122
180
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
123
181
|
return false;
|
|
124
182
|
}
|
|
125
183
|
const record = entry;
|
|
126
184
|
return typeof record.url === 'string' && typeof record.command !== 'string';
|
|
127
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Raw `x-agent-deck-workspace` header value from a pure-MCP HTTP entry
|
|
188
|
+
* (NOT-567). Returned as-is: Cursor sends header values literally, so a
|
|
189
|
+
* value carrying `${...}` interpolation is for the caller to flag, never
|
|
190
|
+
* to resolve.
|
|
191
|
+
*/
|
|
192
|
+
function readHttpWorkspaceHeader(entry) {
|
|
193
|
+
if (!isHttpAgentDeckEntry(entry)) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
const headers = entry.headers;
|
|
197
|
+
if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
const workspaceRoot = headers['x-agent-deck-workspace'];
|
|
201
|
+
return typeof workspaceRoot === 'string' && workspaceRoot.length > 0 ? workspaceRoot : undefined;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Pre-1.7 Cursor/HTTP entries used bare `url` with no deck-assignment
|
|
205
|
+
* launcher. Same url-without-command shape as {@link isHttpAgentDeckEntry};
|
|
206
|
+
* kept under this name for the Claude legacy paths.
|
|
207
|
+
*/
|
|
208
|
+
function isLegacyBareHttpAgentDeckEntry(entry) {
|
|
209
|
+
return isHttpAgentDeckEntry(entry);
|
|
210
|
+
}
|
|
128
211
|
function isMcpLaunchEntry(entry) {
|
|
129
212
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
130
213
|
return false;
|
|
@@ -140,161 +223,46 @@ function isMcpLaunchEntry(entry) {
|
|
|
140
223
|
const args = record.args;
|
|
141
224
|
return Array.isArray(args) && args.length === 1 && args[0] === 'mcp-launch';
|
|
142
225
|
}
|
|
143
|
-
|
|
226
|
+
/**
|
|
227
|
+
* True when a JSON `agent-deck` entry is a legacy Claude Code launcher
|
|
228
|
+
* entry (NOT-566): an `agent-deck mcp-launch` entry carrying
|
|
229
|
+
* `type: 'stdio'` or an `AGENT_DECK_WORKSPACE` env pin. Every launcher
|
|
230
|
+
* entry `use`/`setup --client claude` ever wrote carries at least one of
|
|
231
|
+
* those markers — project entries carry both, global entries the type.
|
|
232
|
+
*
|
|
233
|
+
* Muse-shaped launcher entries carry the same command/args but never
|
|
234
|
+
* `type` or the workspace pin, so they never match here; they match
|
|
235
|
+
* {@link isLegacyMuseLaunchEntry} instead, and the upgrade rewrite
|
|
236
|
+
* handles each marker with its own conversion (NOT-572).
|
|
237
|
+
*/
|
|
238
|
+
function isLegacyClaudeLaunchEntry(entry) {
|
|
144
239
|
if (!isMcpLaunchEntry(entry)) {
|
|
145
|
-
return
|
|
240
|
+
return false;
|
|
146
241
|
}
|
|
147
|
-
const
|
|
242
|
+
const record = entry;
|
|
243
|
+
if (record.type === 'stdio') {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const env = record.env;
|
|
148
247
|
if (!env || typeof env !== 'object' || Array.isArray(env)) {
|
|
149
|
-
return
|
|
248
|
+
return false;
|
|
150
249
|
}
|
|
151
250
|
const workspaceRoot = env.AGENT_DECK_WORKSPACE;
|
|
152
|
-
return typeof workspaceRoot === 'string' && workspaceRoot.length > 0
|
|
153
|
-
? node_path_1.default.resolve(workspaceRoot)
|
|
154
|
-
: undefined;
|
|
251
|
+
return typeof workspaceRoot === 'string' && workspaceRoot.length > 0;
|
|
155
252
|
}
|
|
156
253
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
254
|
+
* True when a JSON `agent-deck` entry is a legacy Muse launcher entry
|
|
255
|
+
* (NOT-387 shape, retired NOT-572): an `agent-deck mcp-launch` entry
|
|
256
|
+
* with neither Claude marker — no `type: 'stdio'`, no
|
|
257
|
+
* `AGENT_DECK_WORKSPACE` env pin. Every launcher entry older
|
|
258
|
+
* `use --client muse` and `setup --client muse --scope project` wrote
|
|
259
|
+
* has exactly this shape (command/args/env only). Nothing builds it;
|
|
260
|
+
* the upgrade path converts it to the HTTP shape (or removes it when
|
|
261
|
+
* the folder has no assignment), and setup/use only detect it for
|
|
262
|
+
* legacy warnings.
|
|
164
263
|
*/
|
|
165
|
-
function
|
|
166
|
-
|
|
167
|
-
const existingConfig = readJsonFile(configPath);
|
|
168
|
-
const servers = existingConfig.mcpServers && typeof existingConfig.mcpServers === 'object'
|
|
169
|
-
? existingConfig.mcpServers
|
|
170
|
-
: {};
|
|
171
|
-
const existing = servers['agent-deck'];
|
|
172
|
-
const workspaceRoot = options?.workspaceRoot ? node_path_1.default.resolve(options.workspaceRoot) : undefined;
|
|
173
|
-
const desired = buildAgentDeckEntry('cursor', endpoint, { workspaceRoot });
|
|
174
|
-
if (existing === undefined) {
|
|
175
|
-
if (!workspaceRoot) {
|
|
176
|
-
return { action: 'diagnostic', path: configPath, reason: 'missing' };
|
|
177
|
-
}
|
|
178
|
-
writeJsonFile(configPath, mergeMcpServerConfig(existingConfig, desired));
|
|
179
|
-
return { action: 'created', path: configPath, reason: 'missing', workspaceRoot };
|
|
180
|
-
}
|
|
181
|
-
if (isLegacyBareHttpAgentDeckEntry(existing)) {
|
|
182
|
-
if (!workspaceRoot) {
|
|
183
|
-
return { action: 'diagnostic', path: configPath, reason: 'bare-url' };
|
|
184
|
-
}
|
|
185
|
-
writeJsonFile(configPath, mergeMcpServerConfig(existingConfig, desired));
|
|
186
|
-
return {
|
|
187
|
-
action: 'upgraded',
|
|
188
|
-
path: configPath,
|
|
189
|
-
reason: 'bare-url',
|
|
190
|
-
workspaceRoot,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
if (!isMcpLaunchEntry(existing)) {
|
|
194
|
-
return workspaceRoot
|
|
195
|
-
? { action: 'skipped', path: configPath, reason: 'custom-entry' }
|
|
196
|
-
: { action: 'diagnostic', path: configPath, reason: 'custom-entry' };
|
|
197
|
-
}
|
|
198
|
-
const currentWorkspace = readCursorWorkspaceRoot(existing);
|
|
199
|
-
const existingEnv = existing.env;
|
|
200
|
-
const env = existingEnv && typeof existingEnv === 'object' && !Array.isArray(existingEnv)
|
|
201
|
-
? existingEnv
|
|
202
|
-
: {};
|
|
203
|
-
const endpointChanged = env.AGENT_DECK_HOST !== endpoint.host ||
|
|
204
|
-
env.AGENT_DECK_MCP_PORT !== String(endpoint.mcpPort);
|
|
205
|
-
if (!workspaceRoot) {
|
|
206
|
-
if (!currentWorkspace) {
|
|
207
|
-
return { action: 'diagnostic', path: configPath, reason: 'missing-workspace' };
|
|
208
|
-
}
|
|
209
|
-
if (endpointChanged) {
|
|
210
|
-
return {
|
|
211
|
-
action: 'diagnostic',
|
|
212
|
-
path: configPath,
|
|
213
|
-
reason: 'endpoint-changed',
|
|
214
|
-
workspaceRoot: currentWorkspace,
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
return { action: 'ok', path: configPath, workspaceRoot: currentWorkspace };
|
|
218
|
-
}
|
|
219
|
-
if (currentWorkspace === workspaceRoot && !endpointChanged) {
|
|
220
|
-
return { action: 'ok', path: configPath, workspaceRoot };
|
|
221
|
-
}
|
|
222
|
-
const reason = !currentWorkspace
|
|
223
|
-
? 'missing-workspace'
|
|
224
|
-
: currentWorkspace !== workspaceRoot
|
|
225
|
-
? 'workspace-changed'
|
|
226
|
-
: 'endpoint-changed';
|
|
227
|
-
const currentRecord = existing;
|
|
228
|
-
const desiredEnv = desired.env;
|
|
229
|
-
const repaired = {
|
|
230
|
-
...currentRecord,
|
|
231
|
-
...desired,
|
|
232
|
-
env: {
|
|
233
|
-
...env,
|
|
234
|
-
...desiredEnv,
|
|
235
|
-
},
|
|
236
|
-
};
|
|
237
|
-
writeJsonFile(configPath, mergeMcpServerConfig(existingConfig, repaired));
|
|
238
|
-
return reason === 'workspace-changed'
|
|
239
|
-
? {
|
|
240
|
-
action: 'updated',
|
|
241
|
-
path: configPath,
|
|
242
|
-
reason,
|
|
243
|
-
workspaceRoot,
|
|
244
|
-
previousWorkspaceRoot: currentWorkspace,
|
|
245
|
-
}
|
|
246
|
-
: { action: 'updated', path: configPath, reason, workspaceRoot };
|
|
247
|
-
}
|
|
248
|
-
function formatCursorGlobalMcpEnsureMessage(result) {
|
|
249
|
-
if (result.action === 'ok') {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
if (result.action === 'skipped') {
|
|
253
|
-
return [
|
|
254
|
-
`Cursor MCP: left custom agent-deck entry unchanged in ${result.path}.`,
|
|
255
|
-
' Configure that wrapper to run `agent-deck mcp-launch` with AGENT_DECK_WORKSPACE set to this workspace.',
|
|
256
|
-
].join('\n');
|
|
257
|
-
}
|
|
258
|
-
if (result.action === 'diagnostic') {
|
|
259
|
-
const detail = result.reason === 'missing'
|
|
260
|
-
? 'no user-level agent-deck entry exists'
|
|
261
|
-
: result.reason === 'bare-url'
|
|
262
|
-
? 'legacy bare URL has no deck-assignment launcher'
|
|
263
|
-
: result.reason === 'missing-workspace'
|
|
264
|
-
? 'mcp-launch has no AGENT_DECK_WORKSPACE pin'
|
|
265
|
-
: result.reason === 'endpoint-changed'
|
|
266
|
-
? 'the configured Agent Deck endpoint is stale'
|
|
267
|
-
: 'a custom agent-deck wrapper cannot be validated automatically';
|
|
268
|
-
return [
|
|
269
|
-
`Cursor MCP diagnostic: ${detail} in ${result.path}. No changes made.`,
|
|
270
|
-
` ${exports.CURSOR_MCP_RECOVERY_HINT}`,
|
|
271
|
-
].join('\n');
|
|
272
|
-
}
|
|
273
|
-
if (result.action === 'created') {
|
|
274
|
-
return [
|
|
275
|
-
`Cursor MCP: created ${result.path} and pinned it to ${result.workspaceRoot}.`,
|
|
276
|
-
' Reload Cursor MCP (or restart Cursor). Cursor mcp_auth is not required.',
|
|
277
|
-
].join('\n');
|
|
278
|
-
}
|
|
279
|
-
if (result.action === 'upgraded') {
|
|
280
|
-
return [
|
|
281
|
-
`Cursor MCP: upgraded the legacy bare URL in ${result.path} to mcp-launch and pinned it to ${result.workspaceRoot}.`,
|
|
282
|
-
' Reload Cursor MCP (or restart Cursor). Cursor mcp_auth is not required.',
|
|
283
|
-
].join('\n');
|
|
284
|
-
}
|
|
285
|
-
if (result.reason === 'workspace-changed') {
|
|
286
|
-
return [
|
|
287
|
-
`Cursor MCP: moved the user-level workspace pin from ${result.previousWorkspaceRoot} to ${result.workspaceRoot} in ${result.path}.`,
|
|
288
|
-
' Cursor user-level Agent Deck is last explicit `agent-deck use` wins; reload Cursor MCP (or restart Cursor).',
|
|
289
|
-
].join('\n');
|
|
290
|
-
}
|
|
291
|
-
const detail = result.reason === 'missing-workspace'
|
|
292
|
-
? `added the missing workspace pin ${result.workspaceRoot}`
|
|
293
|
-
: `updated the endpoint while keeping workspace ${result.workspaceRoot}`;
|
|
294
|
-
return [
|
|
295
|
-
`Cursor MCP: repaired ${result.path}; ${detail}.`,
|
|
296
|
-
' Reload Cursor MCP (or restart Cursor). Cursor mcp_auth is not required.',
|
|
297
|
-
].join('\n');
|
|
264
|
+
function isLegacyMuseLaunchEntry(entry) {
|
|
265
|
+
return isMcpLaunchEntry(entry) && !isLegacyClaudeLaunchEntry(entry);
|
|
298
266
|
}
|
|
299
267
|
function readJsonFile(filePath) {
|
|
300
268
|
if (!node_fs_1.default.existsSync(filePath)) {
|
|
@@ -343,4 +311,403 @@ function writeJsonFile(filePath, data) {
|
|
|
343
311
|
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
|
|
344
312
|
node_fs_1.default.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
|
|
345
313
|
}
|
|
314
|
+
function readTextFile(filePath) {
|
|
315
|
+
if (!node_fs_1.default.existsSync(filePath)) {
|
|
316
|
+
return '';
|
|
317
|
+
}
|
|
318
|
+
return node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
319
|
+
}
|
|
320
|
+
function writeTextFile(filePath, text) {
|
|
321
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
|
|
322
|
+
node_fs_1.default.writeFileSync(filePath, text, 'utf8');
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Matches our managed Codex section headers: the `[mcp_servers.agent-deck]`
|
|
326
|
+
* parent plus any `[mcp_servers.agent-deck.<sub>]` sub-table (the layout
|
|
327
|
+
* `codex mcp add --env` writes). Bare or quoted key, whitespace-tolerant,
|
|
328
|
+
* with any trailing comment. Never matches a merely prefixed sibling such
|
|
329
|
+
* as `[mcp_servers.agent-deck-env]`.
|
|
330
|
+
*/
|
|
331
|
+
const CODEX_AGENT_DECK_SECTION_RE = /^\s*\[\s*mcp_servers\s*\.\s*("agent-deck"|'agent-deck'|agent-deck)\s*(\.\s*[^\]#]+)?\]\s*(?:#.*)?$/;
|
|
332
|
+
/** Matches a bare `[mcp_servers]` section header holding dotted/inline keys. */
|
|
333
|
+
const CODEX_MCP_SERVERS_SECTION_RE = /^\s*\[\s*("mcp_servers"|'mcp_servers'|mcp_servers)\s*\]\s*(?:#.*)?$/;
|
|
334
|
+
/** Matches an `agent-deck` key definition start inside `[mcp_servers]`. */
|
|
335
|
+
const CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE = /^\s*("agent-deck"|'agent-deck'|agent-deck)\s*(?=[.=])/;
|
|
336
|
+
function isTomlSectionHeader(line) {
|
|
337
|
+
return line.trimStart().startsWith('[');
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Net `{`/`[` minus `}`/`]` depth change of one TOML line, ignoring string
|
|
341
|
+
* literals and `#` comments so braces inside values never unbalance the
|
|
342
|
+
* scan. Used to skip multi-line inline tables when removing stale keys.
|
|
343
|
+
*/
|
|
344
|
+
function tomlBracketDelta(line) {
|
|
345
|
+
let code = '';
|
|
346
|
+
let i = 0;
|
|
347
|
+
while (i < line.length) {
|
|
348
|
+
const ch = line[i];
|
|
349
|
+
if (ch === '"') {
|
|
350
|
+
i += 1;
|
|
351
|
+
while (i < line.length && line[i] !== '"') {
|
|
352
|
+
i += line[i] === '\\' ? 2 : 1;
|
|
353
|
+
}
|
|
354
|
+
i += 1;
|
|
355
|
+
}
|
|
356
|
+
else if (ch === "'") {
|
|
357
|
+
i += 1;
|
|
358
|
+
while (i < line.length && line[i] !== "'") {
|
|
359
|
+
i += 1;
|
|
360
|
+
}
|
|
361
|
+
i += 1;
|
|
362
|
+
}
|
|
363
|
+
else if (ch === '#') {
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
code += ch;
|
|
368
|
+
i += 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
let delta = 0;
|
|
372
|
+
for (const c of code) {
|
|
373
|
+
if (c === '{' || c === '[') {
|
|
374
|
+
delta += 1;
|
|
375
|
+
}
|
|
376
|
+
else if (c === '}' || c === ']') {
|
|
377
|
+
delta -= 1;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return delta;
|
|
381
|
+
}
|
|
382
|
+
function escapeTomlBasicString(value) {
|
|
383
|
+
return value
|
|
384
|
+
.replaceAll('\\', '\\\\')
|
|
385
|
+
.replaceAll('"', '\\"')
|
|
386
|
+
.replaceAll('\n', '\\n')
|
|
387
|
+
.replaceAll('\r', '\\r')
|
|
388
|
+
.replaceAll('\t', '\\t');
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Canonical `[mcp_servers.agent-deck]` TOML block (NOT-563). No trailing
|
|
392
|
+
* newline — the merge helper owns file framing.
|
|
393
|
+
*/
|
|
394
|
+
function formatCodexMcpSection(entry) {
|
|
395
|
+
const headers = Object.entries(entry.http_headers)
|
|
396
|
+
.map(([name, value]) => `"${escapeTomlBasicString(name)}" = "${escapeTomlBasicString(value)}"`)
|
|
397
|
+
.join(', ');
|
|
398
|
+
return [
|
|
399
|
+
'[mcp_servers.agent-deck]',
|
|
400
|
+
`url = "${escapeTomlBasicString(entry.url)}"`,
|
|
401
|
+
`http_headers = { ${headers} }`,
|
|
402
|
+
].join('\n');
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Canonical headerless `[mcp_servers.agent-deck]` TOML block: the global
|
|
406
|
+
* unassigned-folder fallback (NOT-565, design §4). Same-name per-folder
|
|
407
|
+
* entries written by `agent-deck use` shadow it. No trailing newline —
|
|
408
|
+
* the merge helper owns file framing.
|
|
409
|
+
*/
|
|
410
|
+
function formatCodexGlobalFallbackSection(endpoint) {
|
|
411
|
+
return [
|
|
412
|
+
'[mcp_servers.agent-deck]',
|
|
413
|
+
`url = "${escapeTomlBasicString(buildMcpUrl(endpoint))}"`,
|
|
414
|
+
].join('\n');
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* True when Codex TOML defines any `agent-deck` server entry (NOT-574):
|
|
418
|
+
* a managed `[mcp_servers.agent-deck]` section (or sub-table) in any
|
|
419
|
+
* transport, or a dotted/inline `agent-deck` key under a bare
|
|
420
|
+
* `[mcp_servers]` section. Other servers never match; a merely prefixed
|
|
421
|
+
* sibling such as `[mcp_servers.agent-deck-env]` never matches.
|
|
422
|
+
*/
|
|
423
|
+
function codexTomlHasAgentDeckEntry(existingText) {
|
|
424
|
+
if (!existingText.includes('agent-deck')) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
const lines = existingText.split('\n');
|
|
428
|
+
const headerKind = new Map();
|
|
429
|
+
for (const [index, line] of lines.entries()) {
|
|
430
|
+
if (!isTomlSectionHeader(line)) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (CODEX_AGENT_DECK_SECTION_RE.test(line)) {
|
|
434
|
+
return true;
|
|
435
|
+
}
|
|
436
|
+
if (CODEX_MCP_SERVERS_SECTION_RE.test(line)) {
|
|
437
|
+
headerKind.set(index, 'servers');
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
headerKind.set(index, 'other');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const headerIdxs = [...headerKind.keys()];
|
|
444
|
+
const rangeEnd = (headerIdx) => {
|
|
445
|
+
for (const candidate of headerIdxs) {
|
|
446
|
+
if (candidate > headerIdx) {
|
|
447
|
+
return candidate;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return lines.length;
|
|
451
|
+
};
|
|
452
|
+
for (const [headerIdx, kind] of headerKind) {
|
|
453
|
+
if (kind !== 'servers') {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const end = rangeEnd(headerIdx);
|
|
457
|
+
let depth = 0;
|
|
458
|
+
let index = headerIdx + 1;
|
|
459
|
+
while (index < end) {
|
|
460
|
+
const line = lines[index];
|
|
461
|
+
if (depth === 0 && CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE.test(line)) {
|
|
462
|
+
return true;
|
|
463
|
+
}
|
|
464
|
+
depth += tomlBracketDelta(line);
|
|
465
|
+
if (depth < 0) {
|
|
466
|
+
depth = 0;
|
|
467
|
+
}
|
|
468
|
+
index += 1;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* True when Codex TOML defines the `agent-deck` server through the legacy
|
|
475
|
+
* stdio launcher (NOT-566): a managed `[mcp_servers.agent-deck]` section
|
|
476
|
+
* (or sub-table) whose body mentions `mcp-launch`, or a dotted/inline
|
|
477
|
+
* `agent-deck` key under a bare `[mcp_servers]` section mentioning it.
|
|
478
|
+
* Pure-HTTP sections, custom entries, and other servers never match —
|
|
479
|
+
* only what the legacy-upgrade rewrite owns.
|
|
480
|
+
*/
|
|
481
|
+
function codexTomlHasLauncherEntry(existingText) {
|
|
482
|
+
if (!existingText.includes('mcp-launch')) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
const lines = existingText.split('\n');
|
|
486
|
+
const headerKind = new Map();
|
|
487
|
+
for (const [index, line] of lines.entries()) {
|
|
488
|
+
if (!isTomlSectionHeader(line)) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (CODEX_AGENT_DECK_SECTION_RE.test(line)) {
|
|
492
|
+
headerKind.set(index, 'managed');
|
|
493
|
+
}
|
|
494
|
+
else if (CODEX_MCP_SERVERS_SECTION_RE.test(line)) {
|
|
495
|
+
headerKind.set(index, 'servers');
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
headerKind.set(index, 'other');
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const headerIdxs = [...headerKind.keys()];
|
|
502
|
+
const rangeEnd = (headerIdx) => {
|
|
503
|
+
for (const candidate of headerIdxs) {
|
|
504
|
+
if (candidate > headerIdx) {
|
|
505
|
+
return candidate;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return lines.length;
|
|
509
|
+
};
|
|
510
|
+
for (const [headerIdx, kind] of headerKind) {
|
|
511
|
+
const end = rangeEnd(headerIdx);
|
|
512
|
+
if (kind === 'managed') {
|
|
513
|
+
for (let index = headerIdx + 1; index < end; index += 1) {
|
|
514
|
+
if (lines[index].includes('mcp-launch')) {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (kind !== 'servers') {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
// Dotted/inline agent-deck definitions, same top-level-key rule as
|
|
524
|
+
// the merge: a nested `agent-deck` key inside another server's inline
|
|
525
|
+
// table belongs to that server, not to us.
|
|
526
|
+
let depth = 0;
|
|
527
|
+
let index = headerIdx + 1;
|
|
528
|
+
while (index < end) {
|
|
529
|
+
const line = lines[index];
|
|
530
|
+
if (depth === 0 && CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE.test(line)) {
|
|
531
|
+
let block = line;
|
|
532
|
+
depth += tomlBracketDelta(line);
|
|
533
|
+
index += 1;
|
|
534
|
+
while (depth > 0 && index < end) {
|
|
535
|
+
block += `\n${lines[index]}`;
|
|
536
|
+
depth += tomlBracketDelta(lines[index]);
|
|
537
|
+
index += 1;
|
|
538
|
+
}
|
|
539
|
+
depth = 0;
|
|
540
|
+
if (block.includes('mcp-launch')) {
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
depth += tomlBracketDelta(line);
|
|
546
|
+
if (depth < 0) {
|
|
547
|
+
depth = 0;
|
|
548
|
+
}
|
|
549
|
+
index += 1;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Merge our managed section into existing Codex TOML, preserving every
|
|
556
|
+
* unrelated byte. Stale agent-deck content in any form is removed first:
|
|
557
|
+
* the parent section, every `[mcp_servers.agent-deck.<sub>]` sub-table
|
|
558
|
+
* wherever it sits, and dotted/inline `agent-deck` keys under a bare
|
|
559
|
+
* `[mcp_servers]` section (multi-line inline tables included). The first
|
|
560
|
+
* managed section is replaced in place with its header normalized to the
|
|
561
|
+
* bare form; otherwise the section is appended after a blank separator.
|
|
562
|
+
* Idempotent: merging twice yields byte-identical text. The result ends
|
|
563
|
+
* with exactly one newline when the section is the last content.
|
|
564
|
+
*/
|
|
565
|
+
function mergeCodexTomlConfig(existingText, section) {
|
|
566
|
+
const lines = existingText.split('\n');
|
|
567
|
+
const headerKind = new Map();
|
|
568
|
+
for (const [index, line] of lines.entries()) {
|
|
569
|
+
if (!isTomlSectionHeader(line)) {
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
if (CODEX_AGENT_DECK_SECTION_RE.test(line)) {
|
|
573
|
+
headerKind.set(index, 'managed');
|
|
574
|
+
}
|
|
575
|
+
else if (CODEX_MCP_SERVERS_SECTION_RE.test(line)) {
|
|
576
|
+
headerKind.set(index, 'servers');
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
headerKind.set(index, 'other');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
const headerIdxs = [...headerKind.keys()];
|
|
583
|
+
const rangeEnd = (headerIdx) => {
|
|
584
|
+
for (const candidate of headerIdxs) {
|
|
585
|
+
if (candidate > headerIdx) {
|
|
586
|
+
return candidate;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return lines.length;
|
|
590
|
+
};
|
|
591
|
+
// Dotted/inline agent-deck definitions inside bare [mcp_servers] bodies.
|
|
592
|
+
// Only top-level keys count, so a nested `agent-deck` key inside another
|
|
593
|
+
// server's inline table is left alone.
|
|
594
|
+
const removed = new Set();
|
|
595
|
+
for (const [headerIdx, kind] of headerKind) {
|
|
596
|
+
if (kind !== 'servers') {
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
const end = rangeEnd(headerIdx);
|
|
600
|
+
let depth = 0;
|
|
601
|
+
let index = headerIdx + 1;
|
|
602
|
+
while (index < end) {
|
|
603
|
+
const line = lines[index];
|
|
604
|
+
if (depth === 0 && CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE.test(line)) {
|
|
605
|
+
depth += tomlBracketDelta(line);
|
|
606
|
+
removed.add(index);
|
|
607
|
+
index += 1;
|
|
608
|
+
while (depth > 0 && index < end) {
|
|
609
|
+
depth += tomlBracketDelta(lines[index]);
|
|
610
|
+
removed.add(index);
|
|
611
|
+
index += 1;
|
|
612
|
+
}
|
|
613
|
+
depth = 0;
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
depth += tomlBracketDelta(line);
|
|
617
|
+
if (depth < 0) {
|
|
618
|
+
depth = 0;
|
|
619
|
+
}
|
|
620
|
+
index += 1;
|
|
621
|
+
}
|
|
622
|
+
// A removed key block takes one following blank separator with it when
|
|
623
|
+
// it sits right after the header or between blank lines, so no doubled
|
|
624
|
+
// blank line is left behind.
|
|
625
|
+
for (let i = headerIdx + 1; i < end; i += 1) {
|
|
626
|
+
if (!removed.has(i) || (i > headerIdx + 1 && removed.has(i - 1))) {
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
let blockEnd = i;
|
|
630
|
+
while (blockEnd + 1 < end && removed.has(blockEnd + 1)) {
|
|
631
|
+
blockEnd += 1;
|
|
632
|
+
}
|
|
633
|
+
const after = blockEnd + 1;
|
|
634
|
+
const beforeIsSeparator = i === headerIdx + 1 || lines[i - 1].trim() === '';
|
|
635
|
+
if (after < end && !removed.has(after) && lines[after].trim() === '' && beforeIsSeparator) {
|
|
636
|
+
removed.add(after);
|
|
637
|
+
}
|
|
638
|
+
i = blockEnd;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const managedHeaders = headerIdxs.filter((index) => headerKind.get(index) === 'managed');
|
|
642
|
+
const appendSection = (text) => {
|
|
643
|
+
let framed = text;
|
|
644
|
+
if (framed !== '' && !framed.endsWith('\n')) {
|
|
645
|
+
framed += '\n';
|
|
646
|
+
}
|
|
647
|
+
if (framed !== '' && !framed.endsWith('\n\n')) {
|
|
648
|
+
framed += '\n';
|
|
649
|
+
}
|
|
650
|
+
return `${framed}${section}\n`;
|
|
651
|
+
};
|
|
652
|
+
if (managedHeaders.length === 0) {
|
|
653
|
+
if (removed.size === 0) {
|
|
654
|
+
return appendSection(existingText);
|
|
655
|
+
}
|
|
656
|
+
// Only dotted/inline definitions: drop them, then append. Inserting a
|
|
657
|
+
// section header mid-body would reparent the remaining [mcp_servers]
|
|
658
|
+
// keys under agent-deck.
|
|
659
|
+
return appendSection(lines.filter((_, index) => !removed.has(index)).join('\n'));
|
|
660
|
+
}
|
|
661
|
+
for (const headerIdx of managedHeaders) {
|
|
662
|
+
const end = rangeEnd(headerIdx);
|
|
663
|
+
for (let index = headerIdx; index < end; index += 1) {
|
|
664
|
+
removed.add(index);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const first = managedHeaders[0];
|
|
668
|
+
const firstEnd = rangeEnd(first);
|
|
669
|
+
let nextKept = firstEnd;
|
|
670
|
+
while (nextKept < lines.length && removed.has(nextKept)) {
|
|
671
|
+
nextKept += 1;
|
|
672
|
+
}
|
|
673
|
+
// Keep one blank separator before the next surviving content when the
|
|
674
|
+
// removed block had any: trailing blanks of the replaced range or blanks
|
|
675
|
+
// in the gap up to the next kept line.
|
|
676
|
+
let hadSeparator = false;
|
|
677
|
+
for (let index = firstEnd - 1; index > first; index -= 1) {
|
|
678
|
+
if (lines[index].trim() === '') {
|
|
679
|
+
hadSeparator = true;
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (!hadSeparator) {
|
|
686
|
+
for (let index = firstEnd; index < nextKept; index += 1) {
|
|
687
|
+
if (lines[index].trim() === '') {
|
|
688
|
+
hadSeparator = true;
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const out = [];
|
|
694
|
+
for (let index = 0; index < first; index += 1) {
|
|
695
|
+
if (!removed.has(index)) {
|
|
696
|
+
out.push(lines[index]);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
out.push(...section.split('\n'));
|
|
700
|
+
const rest = [];
|
|
701
|
+
for (let index = nextKept; index < lines.length; index += 1) {
|
|
702
|
+
if (!removed.has(index)) {
|
|
703
|
+
rest.push(lines[index]);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (hadSeparator && rest.some((line) => line.trim() !== '')) {
|
|
707
|
+
out.push('');
|
|
708
|
+
}
|
|
709
|
+
out.push(...rest);
|
|
710
|
+
const merged = out.join('\n');
|
|
711
|
+
return merged.endsWith('\n') ? merged : `${merged}\n`;
|
|
712
|
+
}
|
|
346
713
|
//# sourceMappingURL=mcp-config.js.map
|