@agent-deck/cli 2.5.1 → 2.5.2

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.
Files changed (73) hide show
  1. package/dist/agent-harness.js +4 -4
  2. package/dist/agent-harness.js.map +1 -1
  3. package/dist/coordinator.d.ts +2 -0
  4. package/dist/coordinator.d.ts.map +1 -0
  5. package/dist/coordinator.js +153 -0
  6. package/dist/coordinator.js.map +1 -0
  7. package/dist/cursor-mcp-inspect.d.ts.map +1 -1
  8. package/dist/cursor-mcp-inspect.js +32 -4
  9. package/dist/cursor-mcp-inspect.js.map +1 -1
  10. package/dist/default-deck.d.ts +38 -0
  11. package/dist/default-deck.d.ts.map +1 -0
  12. package/dist/default-deck.js +129 -0
  13. package/dist/default-deck.js.map +1 -0
  14. package/dist/grant-issue.d.ts +39 -0
  15. package/dist/grant-issue.d.ts.map +1 -0
  16. package/dist/grant-issue.js +133 -0
  17. package/dist/grant-issue.js.map +1 -0
  18. package/dist/grant-store.d.ts +35 -0
  19. package/dist/grant-store.d.ts.map +1 -0
  20. package/dist/grant-store.js +302 -0
  21. package/dist/grant-store.js.map +1 -0
  22. package/dist/host-connection.d.ts +40 -0
  23. package/dist/host-connection.d.ts.map +1 -1
  24. package/dist/host-connection.js +58 -0
  25. package/dist/host-connection.js.map +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp-config.d.ts +4 -150
  30. package/dist/mcp-config.d.ts.map +1 -1
  31. package/dist/mcp-config.js +17 -707
  32. package/dist/mcp-config.js.map +1 -1
  33. package/dist/menubar.d.ts +6 -2
  34. package/dist/menubar.d.ts.map +1 -1
  35. package/dist/menubar.js +31 -3
  36. package/dist/menubar.js.map +1 -1
  37. package/dist/muse-skills/agent-deck-session/SKILL.md +12 -10
  38. package/dist/muse-skills/agent-deck-setup/SKILL.md +21 -21
  39. package/dist/run-adapter.d.ts +100 -0
  40. package/dist/run-adapter.d.ts.map +1 -0
  41. package/dist/run-adapter.js +73 -0
  42. package/dist/run-adapter.js.map +1 -0
  43. package/dist/run-claude.d.ts +41 -0
  44. package/dist/run-claude.d.ts.map +1 -0
  45. package/dist/run-claude.js +91 -0
  46. package/dist/run-claude.js.map +1 -0
  47. package/dist/run-codex.d.ts +75 -0
  48. package/dist/run-codex.d.ts.map +1 -0
  49. package/dist/run-codex.js +337 -0
  50. package/dist/run-codex.js.map +1 -0
  51. package/dist/run-cursor.d.ts +79 -0
  52. package/dist/run-cursor.d.ts.map +1 -0
  53. package/dist/run-cursor.js +455 -0
  54. package/dist/run-cursor.js.map +1 -0
  55. package/dist/run-muse.d.ts +127 -0
  56. package/dist/run-muse.d.ts.map +1 -0
  57. package/dist/run-muse.js +499 -0
  58. package/dist/run-muse.js.map +1 -0
  59. package/dist/start.d.ts.map +1 -1
  60. package/dist/start.js +6 -0
  61. package/dist/start.js.map +1 -1
  62. package/dist/stop.d.ts +40 -1
  63. package/dist/stop.d.ts.map +1 -1
  64. package/dist/stop.js +275 -28
  65. package/dist/stop.js.map +1 -1
  66. package/dist/strip-ansi.d.ts +5 -4
  67. package/dist/strip-ansi.d.ts.map +1 -1
  68. package/dist/strip-ansi.js +19 -21
  69. package/dist/strip-ansi.js.map +1 -1
  70. package/dist/use.d.ts.map +1 -1
  71. package/dist/use.js +4 -20
  72. package/dist/use.js.map +1 -1
  73. package/package.json +3 -3
@@ -1,713 +1,23 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MUSE_SCHEMA_VERSION = exports.CURSOR_MCP_RECOVERY_HINT = void 0;
7
- exports.buildMcpUrl = buildMcpUrl;
8
- exports.resolveMuseGlobalConfigDir = resolveMuseGlobalConfigDir;
9
- exports.resolveConfigPath = resolveConfigPath;
10
- exports.buildCodexAgentDeckEntry = buildCodexAgentDeckEntry;
11
- exports.buildGlobalFallbackHttpEntry = buildGlobalFallbackHttpEntry;
12
- exports.buildAgentDeckEntry = buildAgentDeckEntry;
13
- exports.isHttpAgentDeckEntry = isHttpAgentDeckEntry;
14
- exports.readHttpWorkspaceHeader = readHttpWorkspaceHeader;
15
- exports.isLegacyBareHttpAgentDeckEntry = isLegacyBareHttpAgentDeckEntry;
16
- exports.isMcpLaunchEntry = isMcpLaunchEntry;
17
- exports.isLegacyClaudeLaunchEntry = isLegacyClaudeLaunchEntry;
18
- exports.isLegacyMuseLaunchEntry = isLegacyMuseLaunchEntry;
19
- exports.readJsonFile = readJsonFile;
20
- exports.mergeMuseServerConfig = mergeMuseServerConfig;
21
- exports.mergeMcpServerConfig = mergeMcpServerConfig;
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;
31
- const node_fs_1 = __importDefault(require("node:fs"));
32
- const node_os_1 = __importDefault(require("node:os"));
33
- const node_path_1 = __importDefault(require("node:path"));
34
- const strip_ansi_1 = require("./strip-ansi");
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.';
37
- /** Muse user settings require this exact schema version (NOT-387). */
38
- exports.MUSE_SCHEMA_VERSION = 1;
39
- function buildMcpUrl({ host, mcpPort }) {
40
- return `http://${host}:${mcpPort}/mcp`;
41
- }
42
- /** Muse honors XDG_CONFIG_HOME for its user settings; otherwise ~/.config. */
43
- function resolveMuseGlobalConfigDir(home = node_os_1.default.homedir()) {
44
- const xdg = process.env.XDG_CONFIG_HOME?.trim();
45
- return xdg ? xdg : node_path_1.default.join(home, '.config');
46
- }
47
- function resolveConfigPath(client, scope, cwd = process.cwd()) {
48
- const home = node_os_1.default.homedir();
49
- switch (client) {
50
- case 'cursor':
51
- return scope === 'project'
52
- ? node_path_1.default.join(cwd, '.cursor', 'mcp.json')
53
- : node_path_1.default.join(home, '.cursor', 'mcp.json');
54
- case 'claude':
55
- return scope === 'project'
56
- ? node_path_1.default.join(cwd, '.mcp.json')
57
- : node_path_1.default.join(home, '.claude.json');
58
- case 'claude-desktop':
59
- if (process.platform === 'darwin') {
60
- return node_path_1.default.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
61
- }
62
- if (process.platform === 'win32') {
63
- return node_path_1.default.join(process.env.APPDATA ?? home, 'Claude', 'claude_desktop_config.json');
64
- }
65
- return node_path_1.default.join(home, '.config', 'Claude', 'claude_desktop_config.json');
66
- case 'muse':
67
- if (scope === 'project') {
68
- return node_path_1.default.join(cwd, '.mcp.json');
69
- }
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');
75
- default:
76
- throw new Error(`Unsupported client: ${client}`);
77
- }
78
- }
79
- /**
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).
118
- */
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
- }
126
- if (client === 'claude-desktop') {
127
- return {
128
- command: 'agent-deck',
129
- args: ['mcp-launch'],
130
- };
131
- }
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);
151
- }
152
- if (client === 'cursor') {
153
- if (options?.workspaceRoot) {
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
- };
164
- }
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),
170
- };
171
- }
172
- throw new Error(`Unsupported client: ${client}`);
173
- }
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) {
180
- if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
181
- return false;
182
- }
183
- const record = entry;
184
- return typeof record.url === 'string' && typeof record.command !== 'string';
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
17
  /**
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.
18
+ * NOT-597: implementation moved to `@agent-deck/shared` so the daemon
19
+ * approval path shares one writer. This module re-exports for backwards
20
+ * compatibility; new code imports from `@agent-deck/shared`.
207
21
  */
208
- function isLegacyBareHttpAgentDeckEntry(entry) {
209
- return isHttpAgentDeckEntry(entry);
210
- }
211
- function isMcpLaunchEntry(entry) {
212
- if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
213
- return false;
214
- }
215
- const record = entry;
216
- if (typeof record.command !== 'string') {
217
- return false;
218
- }
219
- const commandName = record.command.replaceAll('\\', '/').split('/').pop();
220
- if (commandName !== 'agent-deck' && commandName !== 'agent-deck.cmd') {
221
- return false;
222
- }
223
- const args = record.args;
224
- return Array.isArray(args) && args.length === 1 && args[0] === 'mcp-launch';
225
- }
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) {
239
- if (!isMcpLaunchEntry(entry)) {
240
- return false;
241
- }
242
- const record = entry;
243
- if (record.type === 'stdio') {
244
- return true;
245
- }
246
- const env = record.env;
247
- if (!env || typeof env !== 'object' || Array.isArray(env)) {
248
- return false;
249
- }
250
- const workspaceRoot = env.AGENT_DECK_WORKSPACE;
251
- return typeof workspaceRoot === 'string' && workspaceRoot.length > 0;
252
- }
253
- /**
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.
263
- */
264
- function isLegacyMuseLaunchEntry(entry) {
265
- return isMcpLaunchEntry(entry) && !isLegacyClaudeLaunchEntry(entry);
266
- }
267
- function readJsonFile(filePath) {
268
- if (!node_fs_1.default.existsSync(filePath)) {
269
- return {};
270
- }
271
- const raw = (0, strip_ansi_1.sanitizeJsonText)(node_fs_1.default.readFileSync(filePath, 'utf8').trim());
272
- if (!raw) {
273
- return {};
274
- }
275
- const parsed = JSON.parse(raw);
276
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
277
- throw new Error(`Expected JSON object in ${filePath}`);
278
- }
279
- return parsed;
280
- }
281
- /**
282
- * Merge into Muse global settings: sets schema_version when absent, rejects
283
- * an incompatible existing schema version with an actionable error (caller
284
- * must leave the file untouched), and preserves every unrelated root key
285
- * and MCP server. Project .mcp.json uses the plain merge — it has no
286
- * schema_version and is shared with Claude Code.
287
- */
288
- function mergeMuseServerConfig(existing, entry, configPath) {
289
- const schemaVersion = existing.schema_version;
290
- if (schemaVersion !== undefined && schemaVersion !== exports.MUSE_SCHEMA_VERSION) {
291
- throw new Error(`Unsupported schema_version in ${configPath}: expected ${exports.MUSE_SCHEMA_VERSION}, found ${JSON.stringify(schemaVersion)}. ` +
292
- 'Update Muse or fix the file manually, then re-run setup.');
293
- }
294
- return {
295
- ...mergeMcpServerConfig(existing, entry),
296
- schema_version: exports.MUSE_SCHEMA_VERSION,
297
- };
298
- }
299
- function mergeMcpServerConfig(existing, entry) {
300
- const currentServers = existing.mcpServers;
301
- const mcpServers = currentServers && typeof currentServers === 'object' && !Array.isArray(currentServers)
302
- ? { ...currentServers }
303
- : {};
304
- mcpServers['agent-deck'] = entry;
305
- return {
306
- ...existing,
307
- mcpServers,
308
- };
309
- }
310
- function writeJsonFile(filePath, data) {
311
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
312
- node_fs_1.default.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
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
- }
22
+ __exportStar(require("@agent-deck/shared"), exports);
713
23
  //# sourceMappingURL=mcp-config.js.map