opencastle 1.1.0 → 1.1.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/README.md +1 -1
- package/dist/cli/adapters/codex.d.ts +19 -6
- package/dist/cli/adapters/codex.d.ts.map +1 -1
- package/dist/cli/adapters/codex.js +24 -7
- package/dist/cli/adapters/codex.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts +7 -0
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +35 -20
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/codex-target.test.d.ts +2 -0
- package/dist/cli/codex-target.test.d.ts.map +1 -0
- package/dist/cli/codex-target.test.js +154 -0
- package/dist/cli/codex-target.test.js.map +1 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -1
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +5 -4
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +22 -10
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/managed-paths.d.ts.map +1 -1
- package/dist/cli/managed-paths.js +2 -0
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/mcp-audit.d.ts.map +1 -1
- package/dist/cli/mcp-audit.js +7 -3
- package/dist/cli/mcp-audit.js.map +1 -1
- package/dist/cli/mcp-file.d.ts +37 -0
- package/dist/cli/mcp-file.d.ts.map +1 -0
- package/dist/cli/mcp-file.js +291 -0
- package/dist/cli/mcp-file.js.map +1 -0
- package/dist/cli/mcp-file.test.d.ts +2 -0
- package/dist/cli/mcp-file.test.d.ts.map +1 -0
- package/dist/cli/mcp-file.test.js +121 -0
- package/dist/cli/mcp-file.test.js.map +1 -0
- package/dist/cli/mcp.d.ts +15 -0
- package/dist/cli/mcp.d.ts.map +1 -1
- package/dist/cli/mcp.js +123 -56
- package/dist/cli/mcp.js.map +1 -1
- package/dist/cli/remove.d.ts.map +1 -1
- package/dist/cli/remove.js +23 -4
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +4 -3
- package/dist/cli/sync-check.js.map +1 -1
- package/dist/cli/sync-check.test.js +2 -2
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/cli/types.d.ts +5 -2
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js +3 -0
- package/dist/cli/types.js.map +1 -1
- package/dist/cli/unreadable-report.d.ts +7 -0
- package/dist/cli/unreadable-report.d.ts.map +1 -1
- package/dist/cli/unreadable-report.js +14 -0
- package/dist/cli/unreadable-report.js.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/update.js +55 -5
- package/dist/cli/update.js.map +1 -1
- package/package.json +2 -1
- package/src/cli/adapters/codex.ts +25 -7
- package/src/cli/adapters/single-file-base.ts +46 -24
- package/src/cli/codex-target.test.ts +178 -0
- package/src/cli/doctor.ts +3 -2
- package/src/cli/init.test.ts +22 -10
- package/src/cli/init.ts +5 -4
- package/src/cli/managed-paths.ts +2 -0
- package/src/cli/mcp-audit.ts +7 -3
- package/src/cli/mcp-file.test.ts +138 -0
- package/src/cli/mcp-file.ts +302 -0
- package/src/cli/mcp.ts +130 -60
- package/src/cli/remove.ts +20 -4
- package/src/cli/sync-check.test.ts +2 -2
- package/src/cli/sync-check.ts +4 -3
- package/src/cli/types.ts +5 -2
- package/src/cli/unreadable-report.ts +14 -0
- package/src/cli/update.ts +61 -5
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
package/src/cli/mcp.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { McpInput, McpServerConfig, EnvVarRequirement } from '../orchestrat
|
|
|
8
8
|
import type { ScaffoldResult, StackConfig, RepoInfo, IdeChoice, CopyResults } from './types.js';
|
|
9
9
|
import type { TeamMcpPlan } from './layers.js';
|
|
10
10
|
import { EDITOR_VARIABLES, type TeamMcpServer } from './team-config.js';
|
|
11
|
+
import { parseMcpConfigText, serialiseMcpConfig, TomlEditError } from './mcp-file.js';
|
|
11
12
|
|
|
12
13
|
// ── IDE-specific MCP format transformation ────────────────────
|
|
13
14
|
|
|
@@ -63,6 +64,12 @@ function editorVariableFor(ide: IdeChoice, name: string, original: string): stri
|
|
|
63
64
|
return original;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/** The variable a value is wholly a reference to — `${NAME}` and nothing else — or null. */
|
|
68
|
+
function wholeReference(value: string): string | null {
|
|
69
|
+
const m = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(value);
|
|
70
|
+
return m && !EDITOR_VARIABLES.has(m[1]) ? m[1] : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
/** Rewrite every `${NAME}` in a value into the target's own spelling. */
|
|
67
74
|
function rewriteRefs(value: string, ide: IdeChoice): string {
|
|
68
75
|
return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, name: string) =>
|
|
@@ -87,7 +94,6 @@ function transformMcpForIde(
|
|
|
87
94
|
case 'cursor':
|
|
88
95
|
case 'claude-code':
|
|
89
96
|
case 'windsurf':
|
|
90
|
-
case 'codex':
|
|
91
97
|
case 'antigravity': {
|
|
92
98
|
// mcpServers format — no 'type' field
|
|
93
99
|
const mcpServers: Record<string, unknown> = {};
|
|
@@ -115,6 +121,53 @@ function transformMcpForIde(
|
|
|
115
121
|
return { mcpServers };
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
case 'codex': {
|
|
125
|
+
// Codex CLI reads `[mcp_servers.<name>]` tables in `.codex/config.toml`
|
|
126
|
+
// and expands no variables anywhere in them. What it offers instead is
|
|
127
|
+
// structural: `env_vars` forwards a variable from the environment Codex
|
|
128
|
+
// was started in, `bearer_token_env_var` sends `Authorization: Bearer`
|
|
129
|
+
// with one, and `env_http_headers` sets a header to one. A reference that
|
|
130
|
+
// is exactly one of those shapes is written as it; anything else is left
|
|
131
|
+
// as written, and `doctor` says so.
|
|
132
|
+
const mcp_servers: Record<string, unknown> = {};
|
|
133
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
134
|
+
if (server.type === 'stdio') {
|
|
135
|
+
const env: Record<string, string> = {};
|
|
136
|
+
const envVars: string[] = [];
|
|
137
|
+
for (const [key, value] of Object.entries(server.env ?? {})) {
|
|
138
|
+
if (wholeReference(value) === key) envVars.push(key);
|
|
139
|
+
else env[key] = value;
|
|
140
|
+
}
|
|
141
|
+
mcp_servers[name] = {
|
|
142
|
+
command: server.command,
|
|
143
|
+
...(server.args && { args: server.args }),
|
|
144
|
+
...(Object.keys(env).length > 0 && { env }),
|
|
145
|
+
...(envVars.length > 0 && { env_vars: envVars }),
|
|
146
|
+
};
|
|
147
|
+
} else if (server.type === 'http') {
|
|
148
|
+
const url = (server.url ?? '').replace(/\$\{input:\w+\}/g, 'REPLACE_ME');
|
|
149
|
+
const literal: Record<string, string> = {};
|
|
150
|
+
const fromEnv: Record<string, string> = {};
|
|
151
|
+
let bearer: string | undefined;
|
|
152
|
+
for (const [header, value] of Object.entries(server.headers ?? {})) {
|
|
153
|
+
const token = /^Bearer\s+(\$\{[A-Za-z_][A-Za-z0-9_]*\})$/.exec(value);
|
|
154
|
+
const bearerVar = header.toLowerCase() === 'authorization' && token ? wholeReference(token[1]) : null;
|
|
155
|
+
const whole = wholeReference(value);
|
|
156
|
+
if (bearerVar) bearer = bearerVar;
|
|
157
|
+
else if (whole) fromEnv[header] = whole;
|
|
158
|
+
else literal[header] = value;
|
|
159
|
+
}
|
|
160
|
+
mcp_servers[name] = {
|
|
161
|
+
url,
|
|
162
|
+
...(bearer && { bearer_token_env_var: bearer }),
|
|
163
|
+
...(Object.keys(literal).length > 0 && { http_headers: literal }),
|
|
164
|
+
...(Object.keys(fromEnv).length > 0 && { env_http_headers: fromEnv }),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { mcp_servers };
|
|
169
|
+
}
|
|
170
|
+
|
|
118
171
|
case 'opencode': {
|
|
119
172
|
// OpenCode format — type: "local"/"remote", command as array
|
|
120
173
|
const mcp: Record<string, unknown> = {};
|
|
@@ -149,41 +202,6 @@ function transformMcpForIde(
|
|
|
149
202
|
}
|
|
150
203
|
}
|
|
151
204
|
|
|
152
|
-
/**
|
|
153
|
-
* The indentation a file already uses, so merging into it does not restyle it.
|
|
154
|
-
*
|
|
155
|
-
* `JSON.stringify(x, null, 2)` re-indented every co-owned config we touched. A
|
|
156
|
-
* hand-written tab-indented `opencode.json` — OpenCode's entire project config —
|
|
157
|
-
* came back two-space indented from a merge that added one key, and never came back
|
|
158
|
-
* from the uninstall at all: 111 bytes in, 114 out, for a strip that took nothing
|
|
159
|
-
* of theirs. Byte fidelity is a claim this tool makes about co-owned files, and a
|
|
160
|
-
* JSON config is one of those.
|
|
161
|
-
*
|
|
162
|
-
* Read from the first indented line, which is what every formatter agrees on.
|
|
163
|
-
* Falls back to two spaces for a file we are creating or one written on a single
|
|
164
|
-
* line, which is what this always did.
|
|
165
|
-
*/
|
|
166
|
-
function indentOf(text: string): string | number {
|
|
167
|
-
const m = /\n([ \t]+)\S/.exec(text);
|
|
168
|
-
if (m) return m[1].includes('\t') ? '\t' : m[1].length;
|
|
169
|
-
// A config written on one line has no indentation, and expanding it to three is
|
|
170
|
-
// as much a restyle as collapsing it would be. `0` is what `JSON.stringify` takes
|
|
171
|
-
// for "no whitespace".
|
|
172
|
-
return text.trim().includes('\n') ? 2 : 0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Re-serialise a config the way the file was already written.
|
|
177
|
-
*
|
|
178
|
-
* Indentation and line endings both, because `JSON.stringify` emits `\n` whatever
|
|
179
|
-
* it was handed and a CRLF config came back LF from a merge that added one key.
|
|
180
|
-
* The same rule `.gitignore` follows: a CRLF file stays CRLF.
|
|
181
|
-
*/
|
|
182
|
-
function serialiseLike(original: string, value: unknown): string {
|
|
183
|
-
const text = JSON.stringify(value, null, indentOf(original)) + '\n';
|
|
184
|
-
return /\r\n/.test(original) ? text.replace(/\n/g, '\r\n') : text;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
205
|
/**
|
|
188
206
|
* One plugin's server as the VS Code–format config, with the env vars other
|
|
189
207
|
* targets need spelled out — they have no `envFile`.
|
|
@@ -206,7 +224,8 @@ function serverFor(
|
|
|
206
224
|
return serverConfig;
|
|
207
225
|
}
|
|
208
226
|
|
|
209
|
-
function containerKeyFor(ide: IdeChoice): string {
|
|
227
|
+
export function containerKeyFor(ide: IdeChoice): string {
|
|
228
|
+
if (ide === 'codex') return 'mcp_servers';
|
|
210
229
|
return ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers';
|
|
211
230
|
}
|
|
212
231
|
|
|
@@ -418,6 +437,20 @@ export function upgradeGeneratedServers(
|
|
|
418
437
|
return upgraded;
|
|
419
438
|
}
|
|
420
439
|
|
|
440
|
+
/**
|
|
441
|
+
* The text to write, or the same refusal an unparseable config gets when a
|
|
442
|
+
* TOML config is laid out in a way that cannot be changed line by line —
|
|
443
|
+
* named and left alone, never rewritten wholesale.
|
|
444
|
+
*/
|
|
445
|
+
function serialiseOrRefuse(before: string | null, value: Record<string, unknown>, rel: string): string {
|
|
446
|
+
try {
|
|
447
|
+
return serialiseMcpConfig(before, value, rel);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
if (err instanceof TomlEditError) throw new UnreadableConfigError(rel, 'uneditable');
|
|
450
|
+
throw err;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
421
454
|
/**
|
|
422
455
|
* Scaffold or merge the MCP server config into the target project.
|
|
423
456
|
*
|
|
@@ -487,17 +520,12 @@ export async function scaffoldMcpConfig(
|
|
|
487
520
|
}
|
|
488
521
|
let existing: Record<string, unknown>;
|
|
489
522
|
try {
|
|
490
|
-
existing =
|
|
523
|
+
existing = parseMcpConfigText(existingContent, destRelPath);
|
|
491
524
|
} catch {
|
|
492
525
|
throw new UnreadableConfigError(destRelPath);
|
|
493
526
|
}
|
|
494
527
|
|
|
495
|
-
|
|
496
|
-
const containerKey = resolvedIde === 'opencode'
|
|
497
|
-
? 'mcp'
|
|
498
|
-
: resolvedIde === 'vscode'
|
|
499
|
-
? 'servers'
|
|
500
|
-
: 'mcpServers';
|
|
528
|
+
const containerKey = containerKeyFor(resolvedIde);
|
|
501
529
|
|
|
502
530
|
if (!existing[containerKey]) {
|
|
503
531
|
existing[containerKey] = {};
|
|
@@ -539,13 +567,13 @@ export async function scaffoldMcpConfig(
|
|
|
539
567
|
return { path: destPath, action: 'skipped', team: teamChanges };
|
|
540
568
|
}
|
|
541
569
|
|
|
542
|
-
await writeFile(destPath,
|
|
570
|
+
await writeFile(destPath, serialiseOrRefuse(existingContent, existing, destRelPath));
|
|
543
571
|
return { path: destPath, action: 'created', team: teamChanges };
|
|
544
572
|
}
|
|
545
573
|
|
|
546
574
|
const teamChanges = applyTeamPlan(output, resolvedIde, team);
|
|
547
575
|
await mkdir(dirname(destPath), { recursive: true });
|
|
548
|
-
await writeFile(destPath,
|
|
576
|
+
await writeFile(destPath, serialiseOrRefuse(null, output, destRelPath));
|
|
549
577
|
|
|
550
578
|
return { path: destPath, action: 'created', team: teamChanges };
|
|
551
579
|
}
|
|
@@ -568,7 +596,7 @@ export function getMcpConfigRelPath(ide: IdeChoice): string {
|
|
|
568
596
|
case 'windsurf':
|
|
569
597
|
return '.windsurf/mcp.json';
|
|
570
598
|
case 'codex':
|
|
571
|
-
return '.codex/
|
|
599
|
+
return '.codex/config.toml';
|
|
572
600
|
case 'antigravity':
|
|
573
601
|
return '.agents/mcp_config.json';
|
|
574
602
|
}
|
|
@@ -611,9 +639,7 @@ export async function scaffoldMcpConfigInto(
|
|
|
611
639
|
if (result.team?.removed.length) (results.mcpTeamRemoved ??= []).push(...result.team.removed);
|
|
612
640
|
} catch (err) {
|
|
613
641
|
if (!(err instanceof UnreadableConfigError)) throw err;
|
|
614
|
-
(results.unreadable ??= []).push(
|
|
615
|
-
err.reason === 'unreadable' ? `${err.file}\u0000unreadable` : err.file,
|
|
616
|
-
);
|
|
642
|
+
(results.unreadable ??= []).push(err.reason === 'unparseable' ? err.file : `${err.file}\u0000${err.reason}`);
|
|
617
643
|
}
|
|
618
644
|
}
|
|
619
645
|
|
|
@@ -641,8 +667,8 @@ export function willKeepSomethingAfterStrip(
|
|
|
641
667
|
teamInputs: string[] = [],
|
|
642
668
|
): boolean {
|
|
643
669
|
const containerKeys = ide
|
|
644
|
-
? [ide
|
|
645
|
-
: ['mcp', 'servers', 'mcpServers']
|
|
670
|
+
? [containerKeyFor(ide)]
|
|
671
|
+
: ['mcp', 'servers', 'mcpServers', 'mcp_servers']
|
|
646
672
|
|
|
647
673
|
const ourServerKeys = new Set([
|
|
648
674
|
...Object.values(PLUGINS)
|
|
@@ -680,7 +706,47 @@ export async function stripManagedMcpServers(
|
|
|
680
706
|
teamKeys: string[] = [],
|
|
681
707
|
teamInputs: string[] = [],
|
|
682
708
|
): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
|
|
683
|
-
|
|
709
|
+
return stripConfigAt(projectRoot, getMcpConfigRelPath(ide), ide, createdByUs, teamKeys, teamInputs);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* MCP configs a release before this one wrote where the assistant never looks.
|
|
714
|
+
*
|
|
715
|
+
* Codex CLI reads project servers only from `.codex/config.toml`; the
|
|
716
|
+
* `.codex/mcp.json` OpenCastle wrote for it was never loaded, so every server
|
|
717
|
+
* in it was one Codex did not have.
|
|
718
|
+
*/
|
|
719
|
+
export const LEGACY_MCP_CONFIGS: Partial<Record<IdeChoice, string>> = {
|
|
720
|
+
codex: '.codex/mcp.json',
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Take our servers back out of a target's legacy MCP config, and delete it if
|
|
725
|
+
* we created it and nothing of the user's is left. Anything they added stays —
|
|
726
|
+
* it never reached the assistant either, and `sync` says where it belongs.
|
|
727
|
+
*/
|
|
728
|
+
export async function retireLegacyMcpConfig(
|
|
729
|
+
projectRoot: string,
|
|
730
|
+
ide: IdeChoice,
|
|
731
|
+
createdByUs = false,
|
|
732
|
+
teamKeys: string[] = [],
|
|
733
|
+
teamInputs: string[] = [],
|
|
734
|
+
): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
|
|
735
|
+
const rel = LEGACY_MCP_CONFIGS[ide];
|
|
736
|
+
if (!rel) return 'absent';
|
|
737
|
+
// No `ide`: the legacy file is in the shape it was written in, not today's.
|
|
738
|
+
return stripConfigAt(projectRoot, rel, undefined, createdByUs, teamKeys, teamInputs);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
async function stripConfigAt(
|
|
742
|
+
projectRoot: string,
|
|
743
|
+
rel: string,
|
|
744
|
+
ide: IdeChoice | undefined,
|
|
745
|
+
createdByUs: boolean,
|
|
746
|
+
teamKeys: string[],
|
|
747
|
+
teamInputs: string[],
|
|
748
|
+
): Promise<'deleted' | 'stripped' | 'absent' | 'unreadable'> {
|
|
749
|
+
const destPath = resolve(projectRoot, rel);
|
|
684
750
|
if (!existsSync(destPath)) return 'absent';
|
|
685
751
|
|
|
686
752
|
let before: string;
|
|
@@ -691,7 +757,7 @@ export async function stripManagedMcpServers(
|
|
|
691
757
|
}
|
|
692
758
|
let parsed: Record<string, unknown>;
|
|
693
759
|
try {
|
|
694
|
-
parsed =
|
|
760
|
+
parsed = parseMcpConfigText(before, rel);
|
|
695
761
|
} catch {
|
|
696
762
|
// Not ours to repair. Leaving it alone beats deleting something unreadable,
|
|
697
763
|
// but 'stripped' would have removal report "kept your content in N file(s)"
|
|
@@ -734,7 +800,12 @@ export async function stripManagedMcpServers(
|
|
|
734
800
|
|
|
735
801
|
// The file's own indentation, not ours. Taking our servers out of a
|
|
736
802
|
// tab-indented config used to restyle every line of it.
|
|
737
|
-
|
|
803
|
+
try {
|
|
804
|
+
await writeFile(destPath, serialiseMcpConfig(before, parsed, rel));
|
|
805
|
+
} catch (err) {
|
|
806
|
+
if (err instanceof TomlEditError) return 'unreadable';
|
|
807
|
+
throw err;
|
|
808
|
+
}
|
|
738
809
|
return 'stripped';
|
|
739
810
|
}
|
|
740
811
|
|
|
@@ -778,12 +849,11 @@ export async function rebuildMcpConfig(
|
|
|
778
849
|
}
|
|
779
850
|
let existing: Record<string, unknown>;
|
|
780
851
|
try {
|
|
781
|
-
existing =
|
|
852
|
+
existing = parseMcpConfigText(before, destRelPath);
|
|
782
853
|
} catch {
|
|
783
854
|
throw new UnreadableConfigError(destRelPath);
|
|
784
855
|
}
|
|
785
|
-
const containerKey =
|
|
786
|
-
ide === 'opencode' ? 'mcp' : ide === 'vscode' ? 'servers' : 'mcpServers';
|
|
856
|
+
const containerKey = containerKeyFor(ide);
|
|
787
857
|
|
|
788
858
|
const existingServers = (existing[containerKey] ?? {}) as Record<string, unknown>;
|
|
789
859
|
|
|
@@ -868,11 +938,11 @@ export async function rebuildMcpConfig(
|
|
|
868
938
|
// policies, and the user's formatting lost to the stricter of them.
|
|
869
939
|
let unchanged = false;
|
|
870
940
|
try {
|
|
871
|
-
unchanged = JSON.stringify(
|
|
941
|
+
unchanged = JSON.stringify(parseMcpConfigText(before, destRelPath)) === JSON.stringify(existing);
|
|
872
942
|
} catch {
|
|
873
943
|
unchanged = false;
|
|
874
944
|
}
|
|
875
|
-
if (!unchanged) await writeFile(destPath,
|
|
945
|
+
if (!unchanged) await writeFile(destPath, serialiseOrRefuse(before, existing, destRelPath));
|
|
876
946
|
|
|
877
947
|
// Re-scaffold: merges new plugin servers into the cleaned config, and writes
|
|
878
948
|
// the team's servers exactly as its layers define them.
|
package/src/cli/remove.ts
CHANGED
|
@@ -7,10 +7,12 @@ import { removeGitignoreBlock, predictGitignoreStrip, LOCAL_DIRS } from './gitig
|
|
|
7
7
|
import { confirm, select, closePrompts, c } from './prompt.js'
|
|
8
8
|
import { stripManagedBlockFromFile, predictStripFile } from './managed-block.js'
|
|
9
9
|
import { resolveManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
10
|
-
import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip } from './mcp.js'
|
|
10
|
+
import { stripManagedMcpServers, getMcpConfigRelPath, willKeepSomethingAfterStrip, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
|
|
11
11
|
import { priorTeam } from './lock.js'
|
|
12
12
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
13
13
|
import type { CliContext, IdeChoice } from './types.js'
|
|
14
|
+
import { whyLeftAlone } from './unreadable-report.js'
|
|
15
|
+
import { parseMcpConfigText } from './mcp-file.js'
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Removal, with the destructive choice made explicit rather than encoded in the
|
|
@@ -104,7 +106,7 @@ async function previewCoOwned(
|
|
|
104
106
|
let keepsSomething = true
|
|
105
107
|
let tookAnything = false
|
|
106
108
|
try {
|
|
107
|
-
const parsed =
|
|
109
|
+
const parsed = parseMcpConfigText(await readFile(abs, 'utf8'), p)
|
|
108
110
|
// Captured before the predicate runs — it edits `parsed` in place.
|
|
109
111
|
const untouched = JSON.stringify(parsed)
|
|
110
112
|
keepsSomething = willKeepSomethingAfterStrip(parsed, ideFor.get(p), ...priorTeam(projectRoot))
|
|
@@ -212,7 +214,14 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
212
214
|
(id): id is IdeChoice => Boolean(id) && id in IDE_ADAPTERS,
|
|
213
215
|
)
|
|
214
216
|
const mcpOwner = new Map(ides.map((ide) => [getMcpConfigRelPath(ide), ide]))
|
|
215
|
-
|
|
217
|
+
// A config an earlier release wrote where its assistant never looked is ours
|
|
218
|
+
// to take back too. It has no owner in `mcpOwner` on purpose: it is in the
|
|
219
|
+
// shape it was written in, so the preview reads it as any config.
|
|
220
|
+
const legacyMcp = ides.flatMap((ide) => {
|
|
221
|
+
const rel = LEGACY_MCP_CONFIGS[ide]
|
|
222
|
+
return rel && existsSync(resolve(projectRoot, rel)) ? [rel] : []
|
|
223
|
+
})
|
|
224
|
+
const mcpPaths = new Set([...mcpOwner.keys(), ...legacyMcp])
|
|
216
225
|
// An install from before this field existed records nothing, and absence means
|
|
217
226
|
// "unknown" — which is treated as "not ours to delete".
|
|
218
227
|
const createdConfigs = new Set(manifest.createdConfigs ?? [])
|
|
@@ -379,6 +388,13 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
379
388
|
else if (outcome === 'unreadable') unreadable.push(getMcpConfigRelPath(ide))
|
|
380
389
|
const mcpParent = dirname(resolve(projectRoot, getMcpConfigRelPath(ide)))
|
|
381
390
|
if (mcpParent !== projectRoot) parents.add(mcpParent)
|
|
391
|
+
const legacyRel = LEGACY_MCP_CONFIGS[ide]
|
|
392
|
+
if (legacyRel) {
|
|
393
|
+
const legacy = await retireLegacyMcpConfig(projectRoot, ide, createdConfigs.has(legacyRel), ...priorTeam(projectRoot))
|
|
394
|
+
if (legacy === 'deleted') removed++
|
|
395
|
+
else if (legacy === 'stripped') stripped++
|
|
396
|
+
else if (legacy === 'unreadable') unreadable.push(legacyRel)
|
|
397
|
+
}
|
|
382
398
|
}
|
|
383
399
|
|
|
384
400
|
// The containers our own directories lived in. `.claude/agents/`, `skills/`
|
|
@@ -457,7 +473,7 @@ export default async function remove({ args }: CliContext): Promise<void> {
|
|
|
457
473
|
const [name, why] = entry.split('\u0000')
|
|
458
474
|
console.log(
|
|
459
475
|
` ${c.yellow('!')} Left ${name} alone — ` +
|
|
460
|
-
(why
|
|
476
|
+
whyLeftAlone(name, why),
|
|
461
477
|
)
|
|
462
478
|
}
|
|
463
479
|
if (keptDir) {
|
|
@@ -213,10 +213,10 @@ describe('two targets that share a root file', () => {
|
|
|
213
213
|
const text = readFileSync(join(projectRoot, 'AGENTS.md'), 'utf8')
|
|
214
214
|
expect(text).toContain('shared by more than one assistant')
|
|
215
215
|
expect(text).toContain('.opencode/skills/')
|
|
216
|
-
expect(text).
|
|
216
|
+
expect(text).toContain('`.codex/`, `.agents/skills/`')
|
|
217
217
|
// Both assistants still get their own files.
|
|
218
218
|
expect(existsSync(join(projectRoot, '.opencode', 'skills'))).toBe(true)
|
|
219
|
-
expect(existsSync(join(projectRoot, '.
|
|
219
|
+
expect(existsSync(join(projectRoot, '.agents', 'skills'))).toBe(true)
|
|
220
220
|
})
|
|
221
221
|
})
|
|
222
222
|
|
package/src/cli/sync-check.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { tmpdir } from 'node:os'
|
|
|
4
4
|
import { readManifest } from './manifest.js'
|
|
5
5
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
6
6
|
import { detectRepoInfo, mergeStackIntoRepoInfo } from './detect.js'
|
|
7
|
-
import { getMcpConfigRelPath, expectedTeamEntries } from './mcp.js'
|
|
7
|
+
import { getMcpConfigRelPath, expectedTeamEntries, containerKeyFor } from './mcp.js'
|
|
8
|
+
import { parseMcpConfigText } from './mcp-file.js'
|
|
8
9
|
import { resolveStack, getIncludedMcpServers } from './stack-config.js'
|
|
9
10
|
import { auditMcpConfig, describeFindingUnder, remedyFor, isFailure, type TeamAuditContext } from './mcp-audit.js'
|
|
10
11
|
import { resolveSources, materialize, hasErrors, cliVersionOf, type CompileSource } from './layers.js'
|
|
@@ -551,7 +552,7 @@ async function compareProject(
|
|
|
551
552
|
}
|
|
552
553
|
let parsed: unknown
|
|
553
554
|
try {
|
|
554
|
-
parsed =
|
|
555
|
+
parsed = parseMcpConfigText(readFileSync(abs, 'utf8'), rel)
|
|
555
556
|
} catch (err) {
|
|
556
557
|
drift.push({
|
|
557
558
|
ide,
|
|
@@ -572,7 +573,7 @@ async function compareProject(
|
|
|
572
573
|
// Leaving the second out let `doctor` say "sync removes it" while this
|
|
573
574
|
// passed and `sync` short-circuited — a remedy that did nothing.
|
|
574
575
|
const teamKeys = new Set(Object.keys(team.expected))
|
|
575
|
-
const container = (parsed as Record<string, unknown> | null)?.[ide
|
|
576
|
+
const container = (parsed as Record<string, unknown> | null)?.[containerKeyFor(ide as IdeChoice)]
|
|
576
577
|
const present = new Set(container && typeof container === 'object' ? Object.keys(container as object) : [])
|
|
577
578
|
const pluginOutdated = audit.outdated.filter((k) => !teamKeys.has(k))
|
|
578
579
|
const teamMissing = audit.outdated.filter((k) => teamKeys.has(k) && !present.has(k))
|
package/src/cli/types.ts
CHANGED
|
@@ -291,12 +291,15 @@ export class UnreadableConfigError extends Error {
|
|
|
291
291
|
* "It is not valid JSON" was printed for a path that was a *directory* — the
|
|
292
292
|
* remedy offered ("fix the file") did not match the fault, and the user had
|
|
293
293
|
* nothing to act on.
|
|
294
|
+
*
|
|
295
|
+
* `uneditable` is a TOML config that parses but holds its MCP servers in a
|
|
296
|
+
* form that cannot be changed without rewriting the user's text.
|
|
294
297
|
*/
|
|
295
|
-
readonly reason: 'unparseable' | 'unreadable';
|
|
298
|
+
readonly reason: 'unparseable' | 'unreadable' | 'uneditable';
|
|
296
299
|
|
|
297
300
|
constructor(
|
|
298
301
|
public readonly file: string,
|
|
299
|
-
reason: 'unparseable' | 'unreadable' = 'unparseable',
|
|
302
|
+
reason: 'unparseable' | 'unreadable' | 'uneditable' = 'unparseable',
|
|
300
303
|
) {
|
|
301
304
|
super(`Cannot read ${file}`);
|
|
302
305
|
this.name = 'UnreadableConfigError';
|
|
@@ -14,6 +14,20 @@
|
|
|
14
14
|
* printing the same report from separately maintained copies of the same logic is
|
|
15
15
|
* the shape that produced the disagreement in the first place.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Why a file was left alone, as the end of "Left <file> alone — …".
|
|
19
|
+
*
|
|
20
|
+
* Each caller used to spell this itself, as "it is not valid JSON" — true of
|
|
21
|
+
* every config until Codex's, which is TOML.
|
|
22
|
+
*/
|
|
23
|
+
export function whyLeftAlone(name: string, why: string | undefined): string {
|
|
24
|
+
if (why === 'unreadable') return 'it could not be read.'
|
|
25
|
+
if (why === 'uneditable') {
|
|
26
|
+
return 'its MCP servers are written in a form this cannot change without rewriting yours — give each one its own [mcp_servers.<name>] table.'
|
|
27
|
+
}
|
|
28
|
+
return `it is not valid ${name.endsWith('.toml') ? 'TOML' : 'JSON'}.`
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
export function noteUnreadable(into: string[], entry: string): void {
|
|
18
32
|
const SEP = '\u0000'
|
|
19
33
|
const [name, why] = entry.split(SEP)
|
package/src/cli/update.ts
CHANGED
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
getCustomizationsTransform,
|
|
14
14
|
isEnvVarSatisfied,
|
|
15
15
|
} from './stack-config.js'
|
|
16
|
-
import { rebuildMcpConfig, getMcpConfigRelPath } from './mcp.js'
|
|
16
|
+
import { rebuildMcpConfig, getMcpConfigRelPath, retireLegacyMcpConfig, LEGACY_MCP_CONFIGS } from './mcp.js'
|
|
17
17
|
import { updateGitignore, LOCAL_DIRS } from './gitignore.js'
|
|
18
18
|
import { resolveManagedPaths, REQUIRED_CUSTOMIZATIONS } from './managed-paths.js'
|
|
19
19
|
import { detectRepoInfo, mergeStackIntoRepoInfo, buildDetectedToolsSet } from './detect.js'
|
|
20
20
|
import type { CliContext, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
|
|
21
21
|
import { UnreadableConfigError } from './types.js'
|
|
22
|
-
import { noteUnreadable } from './unreadable-report.js'
|
|
22
|
+
import { noteUnreadable, whyLeftAlone } from './unreadable-report.js'
|
|
23
23
|
import {
|
|
24
24
|
resolveSources,
|
|
25
25
|
materialize,
|
|
@@ -32,6 +32,13 @@ import {
|
|
|
32
32
|
import { buildLock, writeLock, LOCK_REL, priorTeam } from './lock.js'
|
|
33
33
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
34
34
|
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
35
|
+
import { parseMcpConfigText } from './mcp-file.js'
|
|
36
|
+
|
|
37
|
+
/** The config that replaced a legacy one, for the sentence that reports it. */
|
|
38
|
+
function configBesideLegacy(rel: string, ides: string[]): string {
|
|
39
|
+
const ide = ides.find((i) => LEGACY_MCP_CONFIGS[i as IdeChoice] === rel)
|
|
40
|
+
return ide ? getMcpConfigRelPath(ide as IdeChoice) : 'the assistant\'s own config'
|
|
41
|
+
}
|
|
35
42
|
|
|
36
43
|
/** Print what is wrong with the team's sources, and that nothing was written. */
|
|
37
44
|
function reportTeamIssues(resolved: ResolvedSources): void {
|
|
@@ -247,7 +254,7 @@ export default async function update({
|
|
|
247
254
|
const abs = resolve(projectRoot, rel)
|
|
248
255
|
if (!existsSync(abs)) continue
|
|
249
256
|
try {
|
|
250
|
-
|
|
257
|
+
parseMcpConfigText(await readFile(abs, 'utf8'), rel)
|
|
251
258
|
} catch {
|
|
252
259
|
return true
|
|
253
260
|
}
|
|
@@ -557,6 +564,21 @@ export default async function update({
|
|
|
557
564
|
const teamWritten = new Set<string>()
|
|
558
565
|
const teamRemoved = new Set<string>()
|
|
559
566
|
const upgradedServers = new Set<string>()
|
|
567
|
+
// Which MCP configs exist before this sync writes any, so one it creates is
|
|
568
|
+
// recorded as ours — as `init` records the ones it creates. A target whose
|
|
569
|
+
// config moved (Codex, to `.codex/config.toml`) gets its new file here, and
|
|
570
|
+
// without the record `remove` would strip it and leave an empty file behind.
|
|
571
|
+
const mcpConfigsBefore = new Map(
|
|
572
|
+
ides.map((ide) => {
|
|
573
|
+
const rel = getMcpConfigRelPath(ide as IdeChoice)
|
|
574
|
+
return [rel, existsSync(resolve(projectRoot, rel))] as const
|
|
575
|
+
}),
|
|
576
|
+
)
|
|
577
|
+
const createdConfigs = new Set(manifest.createdConfigs ?? [])
|
|
578
|
+
// Legacy MCP configs this sync took our servers out of: deleted, or kept for
|
|
579
|
+
// what the user added to them.
|
|
580
|
+
const legacyDeleted: string[] = []
|
|
581
|
+
const legacyKept: string[] = []
|
|
560
582
|
const removedServers = new Set<string>()
|
|
561
583
|
let lockWritten = false
|
|
562
584
|
let lockHeld = false
|
|
@@ -609,12 +631,33 @@ export default async function update({
|
|
|
609
631
|
await step()
|
|
610
632
|
} catch (err) {
|
|
611
633
|
if (!(err instanceof UnreadableConfigError)) throw err
|
|
612
|
-
noteUnreadable(unreadable, err.file)
|
|
634
|
+
noteUnreadable(unreadable, err.reason === 'unparseable' ? err.file : `${err.file}\u0000${err.reason}`)
|
|
613
635
|
}
|
|
614
636
|
}
|
|
615
637
|
}
|
|
616
638
|
}
|
|
617
639
|
|
|
640
|
+
// Configs an earlier release wrote where the assistant never reads them.
|
|
641
|
+
// Taken back after the new config is written, so a failure there leaves
|
|
642
|
+
// the servers in at least one place.
|
|
643
|
+
const [priorKeys, priorInputs] = priorTeam(projectRoot)
|
|
644
|
+
for (const ide of ides) {
|
|
645
|
+
const rel = LEGACY_MCP_CONFIGS[ide as IdeChoice]
|
|
646
|
+
if (!rel) continue
|
|
647
|
+
const outcome = await retireLegacyMcpConfig(
|
|
648
|
+
projectRoot,
|
|
649
|
+
ide as IdeChoice,
|
|
650
|
+
createdConfigs.has(rel),
|
|
651
|
+
[...new Set([...Object.keys(source.mcp.servers), ...priorKeys])],
|
|
652
|
+
priorInputs,
|
|
653
|
+
)
|
|
654
|
+
if (outcome === 'deleted') {
|
|
655
|
+
legacyDeleted.push(rel)
|
|
656
|
+
createdConfigs.delete(rel)
|
|
657
|
+
} else if (outcome === 'stripped') legacyKept.push(rel)
|
|
658
|
+
else if (outcome === 'unreadable') noteUnreadable(unreadable, rel)
|
|
659
|
+
}
|
|
660
|
+
|
|
618
661
|
// What every assistant is now given, for review. Written last, from the
|
|
619
662
|
// same source the targets were compiled from — and not at all while an MCP
|
|
620
663
|
// config could not be read. The lock is how the next sync knows which team
|
|
@@ -665,6 +708,10 @@ export default async function update({
|
|
|
665
708
|
manifest.commandNamespace = COMMAND_NAMESPACE
|
|
666
709
|
manifest.stack = newStack
|
|
667
710
|
manifest.repoInfo = mergeStackIntoRepoInfo(repoInfo, newStack)
|
|
711
|
+
for (const [rel, existed] of mcpConfigsBefore) {
|
|
712
|
+
if (!existed && existsSync(resolve(projectRoot, rel))) createdConfigs.add(rel)
|
|
713
|
+
}
|
|
714
|
+
if (createdConfigs.size > 0 || manifest.createdConfigs) manifest.createdConfigs = [...createdConfigs]
|
|
668
715
|
if (manifestMeaning(manifest as unknown as Record<string, unknown>) !== before) {
|
|
669
716
|
manifest.updatedAt = new Date().toISOString()
|
|
670
717
|
await writeManifest(projectRoot, manifest)
|
|
@@ -702,6 +749,15 @@ export default async function update({
|
|
|
702
749
|
if (teamWritten.size > 0) {
|
|
703
750
|
console.log(` ${c.green('✓')} Wrote the team's MCP server(s) as defined: ${[...teamWritten].sort().join(', ')}`)
|
|
704
751
|
}
|
|
752
|
+
for (const rel of legacyDeleted) {
|
|
753
|
+
console.log(` ${c.yellow('-')} Removed ${rel}, which its assistant never read ${c.dim(`(its servers are now in ${configBesideLegacy(rel, ides)})`)}`)
|
|
754
|
+
}
|
|
755
|
+
for (const rel of legacyKept) {
|
|
756
|
+
console.log(
|
|
757
|
+
` ${c.yellow('!')} Took OpenCastle's servers out of ${rel}, which its assistant never read. ` +
|
|
758
|
+
`What is left there is yours — move it to ${configBesideLegacy(rel, ides)}.`,
|
|
759
|
+
)
|
|
760
|
+
}
|
|
705
761
|
if (teamRemoved.size > 0) {
|
|
706
762
|
console.log(
|
|
707
763
|
` ${c.yellow('-')} Removed ${teamRemoved.size} MCP server(s) the team's layers retired or its policy does not allow: ` +
|
|
@@ -743,7 +799,7 @@ export default async function update({
|
|
|
743
799
|
const name = isAbsolute(abs) ? relative(projectRoot, abs) : abs
|
|
744
800
|
console.log(
|
|
745
801
|
` ${c.yellow('!')} Left ${name} alone — ` +
|
|
746
|
-
(why
|
|
802
|
+
whyLeftAlone(name, why),
|
|
747
803
|
)
|
|
748
804
|
console.log(` ${c.dim('Merge conflict? Fix the file and run sync again.')}`)
|
|
749
805
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
"hash": "
|
|
2
|
+
"hash": "a4fd7106",
|
|
3
3
|
"configHash": "30f8ea04",
|
|
4
|
-
"lockfileHash": "
|
|
5
|
-
"browserHash": "
|
|
4
|
+
"lockfileHash": "68c77928",
|
|
5
|
+
"browserHash": "b3c82596",
|
|
6
6
|
"optimized": {
|
|
7
7
|
"astro > cssesc": {
|
|
8
8
|
"src": "../../../../../node_modules/cssesc/cssesc.js",
|
|
9
9
|
"file": "astro___cssesc.js",
|
|
10
|
-
"fileHash": "
|
|
10
|
+
"fileHash": "efb66864",
|
|
11
11
|
"needsInterop": true
|
|
12
12
|
},
|
|
13
13
|
"astro > aria-query": {
|
|
14
14
|
"src": "../../../../../node_modules/aria-query/lib/index.js",
|
|
15
15
|
"file": "astro___aria-query.js",
|
|
16
|
-
"fileHash": "
|
|
16
|
+
"fileHash": "372fa031",
|
|
17
17
|
"needsInterop": true
|
|
18
18
|
},
|
|
19
19
|
"astro > axobject-query": {
|
|
20
20
|
"src": "../../../../../node_modules/axobject-query/lib/index.js",
|
|
21
21
|
"file": "astro___axobject-query.js",
|
|
22
|
-
"fileHash": "
|
|
22
|
+
"fileHash": "7c9d31bc",
|
|
23
23
|
"needsInterop": true
|
|
24
24
|
}
|
|
25
25
|
},
|