@agent-deck/cli 2.5.0 → 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 (90) hide show
  1. package/dist/agent-harness.js +4 -4
  2. package/dist/agent-harness.js.map +1 -1
  3. package/dist/bin.js +0 -0
  4. package/dist/codex-plugin.d.ts +23 -26
  5. package/dist/codex-plugin.d.ts.map +1 -1
  6. package/dist/codex-plugin.js +113 -58
  7. package/dist/codex-plugin.js.map +1 -1
  8. package/dist/coordinator.d.ts +2 -0
  9. package/dist/coordinator.d.ts.map +1 -0
  10. package/dist/coordinator.js +153 -0
  11. package/dist/coordinator.js.map +1 -0
  12. package/dist/cursor-mcp-inspect.d.ts.map +1 -1
  13. package/dist/cursor-mcp-inspect.js +32 -4
  14. package/dist/cursor-mcp-inspect.js.map +1 -1
  15. package/dist/default-deck.d.ts +38 -0
  16. package/dist/default-deck.d.ts.map +1 -0
  17. package/dist/default-deck.js +129 -0
  18. package/dist/default-deck.js.map +1 -0
  19. package/dist/grant-issue.d.ts +39 -0
  20. package/dist/grant-issue.d.ts.map +1 -0
  21. package/dist/grant-issue.js +133 -0
  22. package/dist/grant-issue.js.map +1 -0
  23. package/dist/grant-store.d.ts +35 -0
  24. package/dist/grant-store.d.ts.map +1 -0
  25. package/dist/grant-store.js +302 -0
  26. package/dist/grant-store.js.map +1 -0
  27. package/dist/host-connection.d.ts +199 -0
  28. package/dist/host-connection.d.ts.map +1 -0
  29. package/dist/host-connection.js +626 -0
  30. package/dist/host-connection.js.map +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +6 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/launcher-migration.d.ts +45 -2
  35. package/dist/launcher-migration.d.ts.map +1 -1
  36. package/dist/launcher-migration.js +134 -25
  37. package/dist/launcher-migration.js.map +1 -1
  38. package/dist/mcp-config.d.ts +4 -142
  39. package/dist/mcp-config.d.ts.map +1 -1
  40. package/dist/mcp-config.js +17 -649
  41. package/dist/mcp-config.js.map +1 -1
  42. package/dist/menubar.d.ts +13 -2
  43. package/dist/menubar.d.ts.map +1 -1
  44. package/dist/menubar.js +42 -4
  45. package/dist/menubar.js.map +1 -1
  46. package/dist/muse-skills/agent-deck-session/SKILL.md +12 -10
  47. package/dist/muse-skills/agent-deck-setup/SKILL.md +21 -21
  48. package/dist/run-adapter.d.ts +100 -0
  49. package/dist/run-adapter.d.ts.map +1 -0
  50. package/dist/run-adapter.js +73 -0
  51. package/dist/run-adapter.js.map +1 -0
  52. package/dist/run-claude.d.ts +41 -0
  53. package/dist/run-claude.d.ts.map +1 -0
  54. package/dist/run-claude.js +91 -0
  55. package/dist/run-claude.js.map +1 -0
  56. package/dist/run-codex.d.ts +75 -0
  57. package/dist/run-codex.d.ts.map +1 -0
  58. package/dist/run-codex.js +337 -0
  59. package/dist/run-codex.js.map +1 -0
  60. package/dist/run-cursor.d.ts +79 -0
  61. package/dist/run-cursor.d.ts.map +1 -0
  62. package/dist/run-cursor.js +455 -0
  63. package/dist/run-cursor.js.map +1 -0
  64. package/dist/run-muse.d.ts +127 -0
  65. package/dist/run-muse.d.ts.map +1 -0
  66. package/dist/run-muse.js +499 -0
  67. package/dist/run-muse.js.map +1 -0
  68. package/dist/start.d.ts +2 -2
  69. package/dist/start.d.ts.map +1 -1
  70. package/dist/start.js +28 -4
  71. package/dist/start.js.map +1 -1
  72. package/dist/stop.d.ts +40 -1
  73. package/dist/stop.d.ts.map +1 -1
  74. package/dist/stop.js +275 -28
  75. package/dist/stop.js.map +1 -1
  76. package/dist/strip-ansi.d.ts +5 -4
  77. package/dist/strip-ansi.d.ts.map +1 -1
  78. package/dist/strip-ansi.js +19 -21
  79. package/dist/strip-ansi.js.map +1 -1
  80. package/dist/upgrade-scan.d.ts +20 -0
  81. package/dist/upgrade-scan.d.ts.map +1 -0
  82. package/dist/upgrade-scan.js +113 -0
  83. package/dist/upgrade-scan.js.map +1 -0
  84. package/dist/upgrade.d.ts.map +1 -1
  85. package/dist/upgrade.js +76 -20
  86. package/dist/upgrade.js.map +1 -1
  87. package/dist/use.d.ts.map +1 -1
  88. package/dist/use.js +4 -20
  89. package/dist/use.js.map +1 -1
  90. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-config.d.ts","sourceRoot":"","sources":["../src/mcp-config.ts"],"names":[],"mappings":"AAMA,oGAAoG;AACpG,eAAO,MAAM,wBAAwB,0LACoJ,CAAC;AAE1L,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,WAAW,GAAG,MAAM,CAElE;AAED,8EAA8E;AAC9E,wBAAgB,0BAA0B,CAAC,IAAI,GAAE,MAAqB,GAAG,MAAM,CAG9E;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,UAAU,EACjB,GAAG,GAAE,MAAsB,GAC1B,MAAM,CAgCR;AAED,2EAA2E;AAC3E,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,GACjC,mBAAmB,CAOrB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAK3F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4DzB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAM5D;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU1E;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAcxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAcjE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE/D;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBtE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAazB;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAGnF;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAGlE;AAgED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAWxE;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,CAK9E;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAuEvE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAmJlF"}
1
+ {"version":3,"file":"mcp-config.d.ts","sourceRoot":"","sources":["../src/mcp-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,oBAAoB,CAAC"}
@@ -1,655 +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.codexTomlHasLauncherEntry = codexTomlHasLauncherEntry;
29
- exports.mergeCodexTomlConfig = mergeCodexTomlConfig;
30
- const node_fs_1 = __importDefault(require("node:fs"));
31
- const node_os_1 = __importDefault(require("node:os"));
32
- const node_path_1 = __importDefault(require("node:path"));
33
- const strip_ansi_1 = require("./strip-ansi");
34
- /** Shared recovery sentence for Cursor MCP diagnostics and docs (NOT-50, pure-MCP form NOT-567). */
35
- 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.';
36
- /** Muse user settings require this exact schema version (NOT-387). */
37
- exports.MUSE_SCHEMA_VERSION = 1;
38
- function buildMcpUrl({ host, mcpPort }) {
39
- return `http://${host}:${mcpPort}/mcp`;
40
- }
41
- /** Muse honors XDG_CONFIG_HOME for its user settings; otherwise ~/.config. */
42
- function resolveMuseGlobalConfigDir(home = node_os_1.default.homedir()) {
43
- const xdg = process.env.XDG_CONFIG_HOME?.trim();
44
- return xdg ? xdg : node_path_1.default.join(home, '.config');
45
- }
46
- function resolveConfigPath(client, scope, cwd = process.cwd()) {
47
- const home = node_os_1.default.homedir();
48
- switch (client) {
49
- case 'cursor':
50
- return scope === 'project'
51
- ? node_path_1.default.join(cwd, '.cursor', 'mcp.json')
52
- : node_path_1.default.join(home, '.cursor', 'mcp.json');
53
- case 'claude':
54
- return scope === 'project'
55
- ? node_path_1.default.join(cwd, '.mcp.json')
56
- : node_path_1.default.join(home, '.claude.json');
57
- case 'claude-desktop':
58
- if (process.platform === 'darwin') {
59
- return node_path_1.default.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
60
- }
61
- if (process.platform === 'win32') {
62
- return node_path_1.default.join(process.env.APPDATA ?? home, 'Claude', 'claude_desktop_config.json');
63
- }
64
- return node_path_1.default.join(home, '.config', 'Claude', 'claude_desktop_config.json');
65
- case 'muse':
66
- if (scope === 'project') {
67
- return node_path_1.default.join(cwd, '.mcp.json');
68
- }
69
- return node_path_1.default.join(resolveMuseGlobalConfigDir(home), 'muse', 'settings.json');
70
- case 'codex':
71
- return scope === 'project'
72
- ? node_path_1.default.join(cwd, '.codex', 'config.toml')
73
- : node_path_1.default.join(home, '.codex', 'config.toml');
74
- default:
75
- throw new Error(`Unsupported client: ${client}`);
76
- }
77
- }
78
- /**
79
- * Pure-HTTP entry for a Codex project config (`<folder>/.codex/config.toml`).
80
- * The daemon resolves the deck from `.agent-deck/use.json` — no deck id here.
81
- */
82
- function buildCodexAgentDeckEntry(endpoint, options) {
83
- return {
84
- url: buildMcpUrl(endpoint),
85
- http_headers: {
86
- 'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
87
- },
88
- };
89
- }
90
- /**
91
- * Global headerless HTTP fallback entry (NOT-565, design §4): folders with
92
- * no assignment connect everywhere over pure MCP and land in the existing
93
- * unassigned (explain-only) session. No headers, no executable lookup.
94
- * Per-folder entries written by `agent-deck use` use the same server name,
95
- * so they shadow this fallback where an assignment exists.
96
- */
97
- function buildGlobalFallbackHttpEntry(endpoint) {
98
- return {
99
- type: 'http',
100
- url: buildMcpUrl(endpoint),
101
- };
102
- }
103
- /**
104
- * MCP client entry for the agent-deck server. Codex, Claude, Cursor, and
105
- * Muse connect over pure HTTP (NOT-563/565/567/570/571): the workspace
106
- * header names the folder and the daemon resolves the deck from
107
- * `.agent-deck/use.json` — no deck id in tracked config, no executable
108
- * lookup.
109
- *
110
- * A `workspaceRoot` selects the per-folder HTTP form; without one the
111
- * client gets the global headerless HTTP fallback (NOT-565/567/570).
112
- * Claude Desktop still uses the trusted local launcher, which reads the
113
- * folder assignment at runtime. The retired Muse launcher shape (NOT-387:
114
- * command/args/env only, no type or workspace pin) is never built —
115
- * legacy entries are detected with {@link isLegacyMuseLaunchEntry} and
116
- * converted by the upgrade path (NOT-572).
117
- */
118
- function buildAgentDeckEntry(client, endpoint, options) {
119
- if (client === 'codex') {
120
- if (!options?.workspaceRoot) {
121
- throw new Error('buildAgentDeckEntry(codex) requires options.workspaceRoot for the x-agent-deck-workspace header');
122
- }
123
- return buildCodexAgentDeckEntry(endpoint, { workspaceRoot: options.workspaceRoot });
124
- }
125
- if (client === 'claude-desktop') {
126
- return {
127
- command: 'agent-deck',
128
- args: ['mcp-launch'],
129
- };
130
- }
131
- if (client === 'muse' || client === 'claude') {
132
- // NOT-571: Muse writes the identical entry Claude writes (NOT-563) —
133
- // the same <folder>/.mcp.json, the same shape — so the two clients no
134
- // longer overwrite each other's agent-deck entry.
135
- if (options?.workspaceRoot) {
136
- // Per-folder pure-MCP entry: the daemon resolves the deck from
137
- // `.agent-deck/use.json` — no deck id in the file.
138
- return {
139
- type: 'http',
140
- url: buildMcpUrl(endpoint),
141
- headers: {
142
- 'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
143
- },
144
- };
145
- }
146
- // Global setup fallback: headerless pure HTTP, no launcher and no
147
- // executable lookup. (The per-folder form above already returned, so
148
- // no workspaceRoot is in scope here.)
149
- return buildGlobalFallbackHttpEntry(endpoint);
150
- }
151
- if (client === 'cursor') {
152
- if (options?.workspaceRoot) {
153
- // NOT-567 per-folder pure-MCP entry: the daemon resolves the deck
154
- // from `.agent-deck/use.json` — no deck id in the file. Cursor
155
- // does not interpolate `${workspaceFolder}` in header values, so
156
- // the absolute folder path is written out.
157
- return {
158
- url: buildMcpUrl(endpoint),
159
- headers: {
160
- 'x-agent-deck-workspace': node_path_1.default.resolve(options.workspaceRoot),
161
- },
162
- };
163
- }
164
- // NOT-567 global setup fallback: headerless pure HTTP, no launcher
165
- // and no executable lookup. Unassigned folders connect through it
166
- // and land in the explain-only session.
167
- return {
168
- url: buildMcpUrl(endpoint),
169
- };
170
- }
171
- throw new Error(`Unsupported client: ${client}`);
172
- }
173
- /**
174
- * Pure-MCP HTTP entry (NOT-567): a `url` with no `command` — the
175
- * per-folder entry carrying the workspace header, or the headerless
176
- * global fallback. No executable lookup on the connection path.
177
- */
178
- function isHttpAgentDeckEntry(entry) {
179
- if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
180
- return false;
181
- }
182
- const record = entry;
183
- return typeof record.url === 'string' && typeof record.command !== 'string';
184
- }
185
- /**
186
- * Raw `x-agent-deck-workspace` header value from a pure-MCP HTTP entry
187
- * (NOT-567). Returned as-is: Cursor sends header values literally, so a
188
- * value carrying `${...}` interpolation is for the caller to flag, never
189
- * to resolve.
190
- */
191
- function readHttpWorkspaceHeader(entry) {
192
- if (!isHttpAgentDeckEntry(entry)) {
193
- return undefined;
194
- }
195
- const headers = entry.headers;
196
- if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
197
- return undefined;
198
- }
199
- const workspaceRoot = headers['x-agent-deck-workspace'];
200
- return typeof workspaceRoot === 'string' && workspaceRoot.length > 0 ? workspaceRoot : undefined;
201
- }
202
- /**
203
- * Pre-1.7 Cursor/HTTP entries used bare `url` with no deck-assignment
204
- * launcher. Same url-without-command shape as {@link isHttpAgentDeckEntry};
205
- * kept under this name for the Claude legacy paths.
206
- */
207
- function isLegacyBareHttpAgentDeckEntry(entry) {
208
- return isHttpAgentDeckEntry(entry);
209
- }
210
- function isMcpLaunchEntry(entry) {
211
- if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
212
- return false;
213
- }
214
- const record = entry;
215
- if (typeof record.command !== 'string') {
216
- return false;
217
- }
218
- const commandName = record.command.replaceAll('\\', '/').split('/').pop();
219
- if (commandName !== 'agent-deck' && commandName !== 'agent-deck.cmd') {
220
- return false;
221
- }
222
- const args = record.args;
223
- return Array.isArray(args) && args.length === 1 && args[0] === 'mcp-launch';
224
- }
225
- /**
226
- * True when a JSON `agent-deck` entry is a legacy Claude Code launcher
227
- * entry (NOT-566): an `agent-deck mcp-launch` entry carrying
228
- * `type: 'stdio'` or an `AGENT_DECK_WORKSPACE` env pin. Every launcher
229
- * entry `use`/`setup --client claude` ever wrote carries at least one of
230
- * those markers — project entries carry both, global entries the type.
231
- *
232
- * Muse-shaped launcher entries carry the same command/args but never
233
- * `type` or the workspace pin, so they never match here; they match
234
- * {@link isLegacyMuseLaunchEntry} instead, and the upgrade rewrite
235
- * handles each marker with its own conversion (NOT-572).
236
- */
237
- function isLegacyClaudeLaunchEntry(entry) {
238
- if (!isMcpLaunchEntry(entry)) {
239
- return false;
240
- }
241
- const record = entry;
242
- if (record.type === 'stdio') {
243
- return true;
244
- }
245
- const env = record.env;
246
- if (!env || typeof env !== 'object' || Array.isArray(env)) {
247
- return false;
248
- }
249
- const workspaceRoot = env.AGENT_DECK_WORKSPACE;
250
- return typeof workspaceRoot === 'string' && workspaceRoot.length > 0;
251
- }
252
- /**
253
- * True when a JSON `agent-deck` entry is a legacy Muse launcher entry
254
- * (NOT-387 shape, retired NOT-572): an `agent-deck mcp-launch` entry
255
- * with neither Claude marker — no `type: 'stdio'`, no
256
- * `AGENT_DECK_WORKSPACE` env pin. Every launcher entry older
257
- * `use --client muse` and `setup --client muse --scope project` wrote
258
- * has exactly this shape (command/args/env only). Nothing builds it;
259
- * the upgrade path converts it to the HTTP shape (or removes it when
260
- * the folder has no assignment), and setup/use only detect it for
261
- * legacy warnings.
262
- */
263
- function isLegacyMuseLaunchEntry(entry) {
264
- return isMcpLaunchEntry(entry) && !isLegacyClaudeLaunchEntry(entry);
265
- }
266
- function readJsonFile(filePath) {
267
- if (!node_fs_1.default.existsSync(filePath)) {
268
- return {};
269
- }
270
- const raw = (0, strip_ansi_1.sanitizeJsonText)(node_fs_1.default.readFileSync(filePath, 'utf8').trim());
271
- if (!raw) {
272
- return {};
273
- }
274
- const parsed = JSON.parse(raw);
275
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
276
- throw new Error(`Expected JSON object in ${filePath}`);
277
- }
278
- return parsed;
279
- }
280
- /**
281
- * Merge into Muse global settings: sets schema_version when absent, rejects
282
- * an incompatible existing schema version with an actionable error (caller
283
- * must leave the file untouched), and preserves every unrelated root key
284
- * and MCP server. Project .mcp.json uses the plain merge — it has no
285
- * schema_version and is shared with Claude Code.
286
- */
287
- function mergeMuseServerConfig(existing, entry, configPath) {
288
- const schemaVersion = existing.schema_version;
289
- if (schemaVersion !== undefined && schemaVersion !== exports.MUSE_SCHEMA_VERSION) {
290
- throw new Error(`Unsupported schema_version in ${configPath}: expected ${exports.MUSE_SCHEMA_VERSION}, found ${JSON.stringify(schemaVersion)}. ` +
291
- 'Update Muse or fix the file manually, then re-run setup.');
292
- }
293
- return {
294
- ...mergeMcpServerConfig(existing, entry),
295
- schema_version: exports.MUSE_SCHEMA_VERSION,
296
- };
297
- }
298
- function mergeMcpServerConfig(existing, entry) {
299
- const currentServers = existing.mcpServers;
300
- const mcpServers = currentServers && typeof currentServers === 'object' && !Array.isArray(currentServers)
301
- ? { ...currentServers }
302
- : {};
303
- mcpServers['agent-deck'] = entry;
304
- return {
305
- ...existing,
306
- mcpServers,
307
- };
308
- }
309
- function writeJsonFile(filePath, data) {
310
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
311
- node_fs_1.default.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
312
- }
313
- function readTextFile(filePath) {
314
- if (!node_fs_1.default.existsSync(filePath)) {
315
- return '';
316
- }
317
- return node_fs_1.default.readFileSync(filePath, 'utf8');
318
- }
319
- function writeTextFile(filePath, text) {
320
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true });
321
- node_fs_1.default.writeFileSync(filePath, text, 'utf8');
322
- }
323
- /**
324
- * Matches our managed Codex section headers: the `[mcp_servers.agent-deck]`
325
- * parent plus any `[mcp_servers.agent-deck.<sub>]` sub-table (the layout
326
- * `codex mcp add --env` writes). Bare or quoted key, whitespace-tolerant,
327
- * with any trailing comment. Never matches a merely prefixed sibling such
328
- * as `[mcp_servers.agent-deck-env]`.
329
- */
330
- const CODEX_AGENT_DECK_SECTION_RE = /^\s*\[\s*mcp_servers\s*\.\s*("agent-deck"|'agent-deck'|agent-deck)\s*(\.\s*[^\]#]+)?\]\s*(?:#.*)?$/;
331
- /** Matches a bare `[mcp_servers]` section header holding dotted/inline keys. */
332
- const CODEX_MCP_SERVERS_SECTION_RE = /^\s*\[\s*("mcp_servers"|'mcp_servers'|mcp_servers)\s*\]\s*(?:#.*)?$/;
333
- /** Matches an `agent-deck` key definition start inside `[mcp_servers]`. */
334
- const CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE = /^\s*("agent-deck"|'agent-deck'|agent-deck)\s*(?=[.=])/;
335
- function isTomlSectionHeader(line) {
336
- return line.trimStart().startsWith('[');
337
- }
338
- /**
339
- * Net `{`/`[` minus `}`/`]` depth change of one TOML line, ignoring string
340
- * literals and `#` comments so braces inside values never unbalance the
341
- * scan. Used to skip multi-line inline tables when removing stale keys.
342
- */
343
- function tomlBracketDelta(line) {
344
- let code = '';
345
- let i = 0;
346
- while (i < line.length) {
347
- const ch = line[i];
348
- if (ch === '"') {
349
- i += 1;
350
- while (i < line.length && line[i] !== '"') {
351
- i += line[i] === '\\' ? 2 : 1;
352
- }
353
- i += 1;
354
- }
355
- else if (ch === "'") {
356
- i += 1;
357
- while (i < line.length && line[i] !== "'") {
358
- i += 1;
359
- }
360
- i += 1;
361
- }
362
- else if (ch === '#') {
363
- break;
364
- }
365
- else {
366
- code += ch;
367
- i += 1;
368
- }
369
- }
370
- let delta = 0;
371
- for (const c of code) {
372
- if (c === '{' || c === '[') {
373
- delta += 1;
374
- }
375
- else if (c === '}' || c === ']') {
376
- delta -= 1;
377
- }
378
- }
379
- return delta;
380
- }
381
- function escapeTomlBasicString(value) {
382
- return value
383
- .replaceAll('\\', '\\\\')
384
- .replaceAll('"', '\\"')
385
- .replaceAll('\n', '\\n')
386
- .replaceAll('\r', '\\r')
387
- .replaceAll('\t', '\\t');
388
- }
389
- /**
390
- * Canonical `[mcp_servers.agent-deck]` TOML block (NOT-563). No trailing
391
- * newline — the merge helper owns file framing.
392
- */
393
- function formatCodexMcpSection(entry) {
394
- const headers = Object.entries(entry.http_headers)
395
- .map(([name, value]) => `"${escapeTomlBasicString(name)}" = "${escapeTomlBasicString(value)}"`)
396
- .join(', ');
397
- return [
398
- '[mcp_servers.agent-deck]',
399
- `url = "${escapeTomlBasicString(entry.url)}"`,
400
- `http_headers = { ${headers} }`,
401
- ].join('\n');
402
- }
403
- /**
404
- * Canonical headerless `[mcp_servers.agent-deck]` TOML block: the global
405
- * unassigned-folder fallback (NOT-565, design §4). Same-name per-folder
406
- * entries written by `agent-deck use` shadow it. No trailing newline —
407
- * the merge helper owns file framing.
408
- */
409
- function formatCodexGlobalFallbackSection(endpoint) {
410
- return [
411
- '[mcp_servers.agent-deck]',
412
- `url = "${escapeTomlBasicString(buildMcpUrl(endpoint))}"`,
413
- ].join('\n');
414
- }
415
17
  /**
416
- * True when Codex TOML defines the `agent-deck` server through the legacy
417
- * stdio launcher (NOT-566): a managed `[mcp_servers.agent-deck]` section
418
- * (or sub-table) whose body mentions `mcp-launch`, or a dotted/inline
419
- * `agent-deck` key under a bare `[mcp_servers]` section mentioning it.
420
- * Pure-HTTP sections, custom entries, and other servers never match —
421
- * only what the legacy-upgrade rewrite owns.
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`.
422
21
  */
423
- function codexTomlHasLauncherEntry(existingText) {
424
- if (!existingText.includes('mcp-launch')) {
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
- headerKind.set(index, 'managed');
435
- }
436
- else 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
- const end = rangeEnd(headerIdx);
454
- if (kind === 'managed') {
455
- for (let index = headerIdx + 1; index < end; index += 1) {
456
- if (lines[index].includes('mcp-launch')) {
457
- return true;
458
- }
459
- }
460
- continue;
461
- }
462
- if (kind !== 'servers') {
463
- continue;
464
- }
465
- // Dotted/inline agent-deck definitions, same top-level-key rule as
466
- // the merge: a nested `agent-deck` key inside another server's inline
467
- // table belongs to that server, not to us.
468
- let depth = 0;
469
- let index = headerIdx + 1;
470
- while (index < end) {
471
- const line = lines[index];
472
- if (depth === 0 && CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE.test(line)) {
473
- let block = line;
474
- depth += tomlBracketDelta(line);
475
- index += 1;
476
- while (depth > 0 && index < end) {
477
- block += `\n${lines[index]}`;
478
- depth += tomlBracketDelta(lines[index]);
479
- index += 1;
480
- }
481
- depth = 0;
482
- if (block.includes('mcp-launch')) {
483
- return true;
484
- }
485
- continue;
486
- }
487
- depth += tomlBracketDelta(line);
488
- if (depth < 0) {
489
- depth = 0;
490
- }
491
- index += 1;
492
- }
493
- }
494
- return false;
495
- }
496
- /**
497
- * Merge our managed section into existing Codex TOML, preserving every
498
- * unrelated byte. Stale agent-deck content in any form is removed first:
499
- * the parent section, every `[mcp_servers.agent-deck.<sub>]` sub-table
500
- * wherever it sits, and dotted/inline `agent-deck` keys under a bare
501
- * `[mcp_servers]` section (multi-line inline tables included). The first
502
- * managed section is replaced in place with its header normalized to the
503
- * bare form; otherwise the section is appended after a blank separator.
504
- * Idempotent: merging twice yields byte-identical text. The result ends
505
- * with exactly one newline when the section is the last content.
506
- */
507
- function mergeCodexTomlConfig(existingText, section) {
508
- const lines = existingText.split('\n');
509
- const headerKind = new Map();
510
- for (const [index, line] of lines.entries()) {
511
- if (!isTomlSectionHeader(line)) {
512
- continue;
513
- }
514
- if (CODEX_AGENT_DECK_SECTION_RE.test(line)) {
515
- headerKind.set(index, 'managed');
516
- }
517
- else if (CODEX_MCP_SERVERS_SECTION_RE.test(line)) {
518
- headerKind.set(index, 'servers');
519
- }
520
- else {
521
- headerKind.set(index, 'other');
522
- }
523
- }
524
- const headerIdxs = [...headerKind.keys()];
525
- const rangeEnd = (headerIdx) => {
526
- for (const candidate of headerIdxs) {
527
- if (candidate > headerIdx) {
528
- return candidate;
529
- }
530
- }
531
- return lines.length;
532
- };
533
- // Dotted/inline agent-deck definitions inside bare [mcp_servers] bodies.
534
- // Only top-level keys count, so a nested `agent-deck` key inside another
535
- // server's inline table is left alone.
536
- const removed = new Set();
537
- for (const [headerIdx, kind] of headerKind) {
538
- if (kind !== 'servers') {
539
- continue;
540
- }
541
- const end = rangeEnd(headerIdx);
542
- let depth = 0;
543
- let index = headerIdx + 1;
544
- while (index < end) {
545
- const line = lines[index];
546
- if (depth === 0 && CODEX_MCP_SERVERS_AGENT_DECK_KEY_RE.test(line)) {
547
- depth += tomlBracketDelta(line);
548
- removed.add(index);
549
- index += 1;
550
- while (depth > 0 && index < end) {
551
- depth += tomlBracketDelta(lines[index]);
552
- removed.add(index);
553
- index += 1;
554
- }
555
- depth = 0;
556
- continue;
557
- }
558
- depth += tomlBracketDelta(line);
559
- if (depth < 0) {
560
- depth = 0;
561
- }
562
- index += 1;
563
- }
564
- // A removed key block takes one following blank separator with it when
565
- // it sits right after the header or between blank lines, so no doubled
566
- // blank line is left behind.
567
- for (let i = headerIdx + 1; i < end; i += 1) {
568
- if (!removed.has(i) || (i > headerIdx + 1 && removed.has(i - 1))) {
569
- continue;
570
- }
571
- let blockEnd = i;
572
- while (blockEnd + 1 < end && removed.has(blockEnd + 1)) {
573
- blockEnd += 1;
574
- }
575
- const after = blockEnd + 1;
576
- const beforeIsSeparator = i === headerIdx + 1 || lines[i - 1].trim() === '';
577
- if (after < end && !removed.has(after) && lines[after].trim() === '' && beforeIsSeparator) {
578
- removed.add(after);
579
- }
580
- i = blockEnd;
581
- }
582
- }
583
- const managedHeaders = headerIdxs.filter((index) => headerKind.get(index) === 'managed');
584
- const appendSection = (text) => {
585
- let framed = text;
586
- if (framed !== '' && !framed.endsWith('\n')) {
587
- framed += '\n';
588
- }
589
- if (framed !== '' && !framed.endsWith('\n\n')) {
590
- framed += '\n';
591
- }
592
- return `${framed}${section}\n`;
593
- };
594
- if (managedHeaders.length === 0) {
595
- if (removed.size === 0) {
596
- return appendSection(existingText);
597
- }
598
- // Only dotted/inline definitions: drop them, then append. Inserting a
599
- // section header mid-body would reparent the remaining [mcp_servers]
600
- // keys under agent-deck.
601
- return appendSection(lines.filter((_, index) => !removed.has(index)).join('\n'));
602
- }
603
- for (const headerIdx of managedHeaders) {
604
- const end = rangeEnd(headerIdx);
605
- for (let index = headerIdx; index < end; index += 1) {
606
- removed.add(index);
607
- }
608
- }
609
- const first = managedHeaders[0];
610
- const firstEnd = rangeEnd(first);
611
- let nextKept = firstEnd;
612
- while (nextKept < lines.length && removed.has(nextKept)) {
613
- nextKept += 1;
614
- }
615
- // Keep one blank separator before the next surviving content when the
616
- // removed block had any: trailing blanks of the replaced range or blanks
617
- // in the gap up to the next kept line.
618
- let hadSeparator = false;
619
- for (let index = firstEnd - 1; index > first; index -= 1) {
620
- if (lines[index].trim() === '') {
621
- hadSeparator = true;
622
- }
623
- else {
624
- break;
625
- }
626
- }
627
- if (!hadSeparator) {
628
- for (let index = firstEnd; index < nextKept; index += 1) {
629
- if (lines[index].trim() === '') {
630
- hadSeparator = true;
631
- break;
632
- }
633
- }
634
- }
635
- const out = [];
636
- for (let index = 0; index < first; index += 1) {
637
- if (!removed.has(index)) {
638
- out.push(lines[index]);
639
- }
640
- }
641
- out.push(...section.split('\n'));
642
- const rest = [];
643
- for (let index = nextKept; index < lines.length; index += 1) {
644
- if (!removed.has(index)) {
645
- rest.push(lines[index]);
646
- }
647
- }
648
- if (hadSeparator && rest.some((line) => line.trim() !== '')) {
649
- out.push('');
650
- }
651
- out.push(...rest);
652
- const merged = out.join('\n');
653
- return merged.endsWith('\n') ? merged : `${merged}\n`;
654
- }
22
+ __exportStar(require("@agent-deck/shared"), exports);
655
23
  //# sourceMappingURL=mcp-config.js.map