opencastle 1.0.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 +9 -4
- package/dist/cli/adapters/claude-code.d.ts +8 -4
- package/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +13 -7
- package/dist/cli/adapters/claude-code.js.map +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 +15 -1
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +46 -21
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/adapters/vscode.d.ts +11 -1
- package/dist/cli/adapters/vscode.d.ts.map +1 -1
- package/dist/cli/adapters/vscode.js +48 -8
- package/dist/cli/adapters/vscode.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/command-namespace.d.ts +91 -0
- package/dist/cli/command-namespace.d.ts.map +1 -0
- package/dist/cli/command-namespace.js +218 -0
- package/dist/cli/command-namespace.js.map +1 -0
- package/dist/cli/command-namespace.test.d.ts +2 -0
- package/dist/cli/command-namespace.test.d.ts.map +1 -0
- package/dist/cli/command-namespace.test.js +356 -0
- package/dist/cli/command-namespace.test.js.map +1 -0
- package/dist/cli/copy.d.ts +1 -1
- package/dist/cli/copy.d.ts.map +1 -1
- package/dist/cli/copy.js +3 -2
- package/dist/cli/copy.js.map +1 -1
- 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/doctor.test.js +2 -2
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js +13 -1
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/github-report.js +1 -1
- package/dist/cli/github-report.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +45 -10
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +31 -14
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/managed-paths.d.ts +18 -1
- package/dist/cli/managed-paths.d.ts.map +1 -1
- package/dist/cli/managed-paths.js +74 -2
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +2 -0
- package/dist/cli/manifest.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 +45 -8
- package/dist/cli/remove.js.map +1 -1
- package/dist/cli/sync-check.d.ts.map +1 -1
- package/dist/cli/sync-check.js +26 -7
- 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 +37 -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 +69 -5
- package/dist/cli/update.js.map +1 -1
- package/package.json +3 -2
- package/src/cli/adapters/claude-code.ts +13 -7
- package/src/cli/adapters/codex.ts +25 -7
- package/src/cli/adapters/single-file-base.ts +66 -26
- package/src/cli/adapters/vscode.ts +51 -10
- package/src/cli/codex-target.test.ts +178 -0
- package/src/cli/command-namespace.test.ts +417 -0
- package/src/cli/command-namespace.ts +222 -0
- package/src/cli/copy.ts +6 -2
- package/src/cli/doctor.test.ts +2 -2
- package/src/cli/doctor.ts +3 -2
- package/src/cli/explain.ts +13 -1
- package/src/cli/github-report.ts +1 -1
- package/src/cli/init.test.ts +31 -14
- package/src/cli/init.ts +48 -11
- package/src/cli/managed-paths.ts +75 -3
- package/src/cli/manifest.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 +40 -8
- package/src/cli/sync-check.test.ts +2 -2
- package/src/cli/sync-check.ts +23 -6
- package/src/cli/types.ts +37 -2
- package/src/cli/unreadable-report.ts +14 -0
- package/src/cli/update.ts +73 -5
- package/src/dashboard/node_modules/.vite/deps/_metadata.json +6 -6
- package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +4 -4
package/src/cli/doctor.test.ts
CHANGED
|
@@ -205,8 +205,8 @@ describe('claude-code adapter getDoctorChecks', () => {
|
|
|
205
205
|
expect(checks.find((c) => c.path === 'CLAUDE.md')?.type).toBe('file')
|
|
206
206
|
expect(checks.find((c) => c.path === '.claude/agents/')).toBeDefined()
|
|
207
207
|
expect(checks.find((c) => c.path === '.claude/skills/')).toBeDefined()
|
|
208
|
-
// claude-code: prompts and workflows share
|
|
209
|
-
expect(checks.find((c) => c.path === '.claude/commands/')).toBeDefined()
|
|
208
|
+
// claude-code: prompts and workflows share the namespaced commands dir
|
|
209
|
+
expect(checks.find((c) => c.path === '.claude/commands/oc/')).toBeDefined()
|
|
210
210
|
expect(checks.find((c) => c.label === 'Commands directory')).toBeDefined()
|
|
211
211
|
})
|
|
212
212
|
})
|
package/src/cli/doctor.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from './managed-block.js';
|
|
17
17
|
import { UnreadableConfigError } from './types.js';
|
|
18
18
|
import { checkMcpSupplyChain } from './mcp-audit.js';
|
|
19
|
+
import { parseMcpConfigText } from './mcp-file.js';
|
|
19
20
|
import {
|
|
20
21
|
teamStateFor,
|
|
21
22
|
teamAuditContext,
|
|
@@ -464,7 +465,7 @@ export function checkMcpFromPaths(projectRoot: string, mcpPaths: string[]): Chec
|
|
|
464
465
|
const abs = resolve(projectRoot, p);
|
|
465
466
|
if (!existsSync(abs)) continue;
|
|
466
467
|
try {
|
|
467
|
-
|
|
468
|
+
parseMcpConfigText(readFileSync(abs, 'utf8'), p);
|
|
468
469
|
} catch (err) {
|
|
469
470
|
return {
|
|
470
471
|
ok: false,
|
|
@@ -986,7 +987,7 @@ export default async function doctor({ pkgRoot, args }: CliContext): Promise<voi
|
|
|
986
987
|
|
|
987
988
|
let manifest: Manifest | null = null;
|
|
988
989
|
let manifestUnreadable: string | undefined;
|
|
989
|
-
let manifestReason: '
|
|
990
|
+
let manifestReason: UnreadableConfigError['reason'] = 'unparseable';
|
|
990
991
|
try {
|
|
991
992
|
manifest = await readManifest(projectRoot);
|
|
992
993
|
} catch (err) {
|
package/src/cli/explain.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { IDE_ADAPTERS } from './adapters/index.js'
|
|
|
8
8
|
import { PLUGINS } from '../orchestrator/plugins/index.js'
|
|
9
9
|
import { c } from './prompt.js'
|
|
10
10
|
import { IDE_LABELS, type CliContext, type IdeChoice } from './types.js'
|
|
11
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* `opencastle explain`: what a new teammate's assistant is given here, and
|
|
@@ -122,13 +123,24 @@ function render(report: ExplainReport, all: boolean): void {
|
|
|
122
123
|
if (lock.policy?.contextBudget) out(` ${c.dim(`budget: ${lock.policy.contextBudget} tokens`)}`)
|
|
123
124
|
out('')
|
|
124
125
|
|
|
126
|
+
// Where a prompt is a command someone types, and under which name.
|
|
127
|
+
const hasClaude = report.targets.some((t) => t.id === 'claude-code')
|
|
128
|
+
const typedIn = [
|
|
129
|
+
...(hasClaude ? ['Claude Code'] : []),
|
|
130
|
+
...(report.targets.some((t) => t.id === 'vscode') ? ['Copilot'] : []),
|
|
131
|
+
]
|
|
125
132
|
for (const kind of ['skills', 'agents', 'prompts', 'workflows'] as const) {
|
|
126
133
|
const items = ofKind(kind)
|
|
127
134
|
if (items.length === 0) continue
|
|
128
135
|
const team = items.filter(([, i]) => i.from !== 'opencastle' && !i.from.startsWith('plugin:'))
|
|
129
136
|
const integrations = items.filter(([, i]) => i.from.startsWith('plugin:'))
|
|
130
137
|
const core = items.filter(([, i]) => i.from === 'opencastle')
|
|
131
|
-
const title = {
|
|
138
|
+
const title = {
|
|
139
|
+
skills: 'Skills — loaded when a task matches the description',
|
|
140
|
+
agents: 'Agents — personas to delegate to',
|
|
141
|
+
prompts: typedIn.length > 0 ? `Commands — /${COMMAND_NAMESPACE}:<name> in ${typedIn.join(' and ')}` : 'Prompts',
|
|
142
|
+
workflows: hasClaude ? `Workflows — /${COMMAND_NAMESPACE}:workflow-<name> in Claude Code` : 'Workflows',
|
|
143
|
+
}[kind]
|
|
132
144
|
out(` ${c.bold(title)} ${c.dim(`(${items.length})`)}`)
|
|
133
145
|
for (const [ref, item] of [...team, ...integrations, ...(all ? core : [])]) {
|
|
134
146
|
const name = ref.slice(kind.length + 1)
|
package/src/cli/github-report.ts
CHANGED
|
@@ -54,7 +54,7 @@ function explain(d: Drift): string {
|
|
|
54
54
|
case 'missing':
|
|
55
55
|
return `${where} should exist but does not. Run \`opencastle sync\` and commit the result; generated config is committed like a lockfile.`
|
|
56
56
|
case 'extra':
|
|
57
|
-
return `${where} sits in generated output but no source produces it, so the next \`opencastle sync\` deletes it.`
|
|
57
|
+
return `${where} ${d.detail ? `was ${d.detail}` : 'sits in generated output but no source produces it'}, so the next \`opencastle sync\` deletes it.`
|
|
58
58
|
case 'outdated':
|
|
59
59
|
return `${where}: ${d.detail ?? 'an MCP server entry sync would change'}. Run \`opencastle sync\` and commit — it touches only entries OpenCastle wrote and nobody edited.`
|
|
60
60
|
case 'unreducible':
|
package/src/cli/init.test.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { mkdtemp, readFile, readdir, rm, unlink, writeFile } from 'node:fs/promi
|
|
|
19
19
|
import { join, resolve } from 'node:path'
|
|
20
20
|
import { tmpdir } from 'node:os'
|
|
21
21
|
import { existsSync } from 'node:fs'
|
|
22
|
+
import { parse as parseToml } from 'smol-toml'
|
|
22
23
|
import type { StackConfig, RepoInfo } from './types.js'
|
|
23
24
|
import { updateGitignore } from './gitignore.js'
|
|
24
25
|
import {
|
|
@@ -834,24 +835,28 @@ describe('Claude Code adapter install', () => {
|
|
|
834
835
|
expect(mcpConfig).not.toHaveProperty('servers')
|
|
835
836
|
})
|
|
836
837
|
|
|
837
|
-
it('creates prompts in .claude/commands/', async () => {
|
|
838
|
+
it('creates prompts in .claude/commands/oc/, the oc: namespace', async () => {
|
|
838
839
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
839
840
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
840
841
|
|
|
841
|
-
const commandsDir = join(tempDir, '.claude', 'commands')
|
|
842
|
+
const commandsDir = join(tempDir, '.claude', 'commands', 'oc')
|
|
842
843
|
expect(existsSync(commandsDir)).toBe(true)
|
|
843
844
|
const commands = await readdir(commandsDir)
|
|
844
845
|
// Should have prompt files
|
|
845
846
|
expect(commands.length).toBeGreaterThan(0)
|
|
847
|
+
expect(commands).toContain('bug-fix.md')
|
|
846
848
|
// All should be .md files
|
|
847
849
|
expect(commands.every((f) => f.endsWith('.md'))).toBe(true)
|
|
850
|
+
// Nothing outside the namespace: the rest of the directory is the user's.
|
|
851
|
+
const top = await readdir(join(tempDir, '.claude', 'commands'))
|
|
852
|
+
expect(top).toEqual(['oc'])
|
|
848
853
|
})
|
|
849
854
|
|
|
850
855
|
it('creates workflows as commands with workflow- prefix', async () => {
|
|
851
856
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
852
857
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
853
858
|
|
|
854
|
-
const commandsDir = join(tempDir, '.claude', 'commands')
|
|
859
|
+
const commandsDir = join(tempDir, '.claude', 'commands', 'oc')
|
|
855
860
|
const commands = await readdir(commandsDir)
|
|
856
861
|
// Workflow files should have the "workflow-" prefix
|
|
857
862
|
const workflows = commands.filter((f) => f.startsWith('workflow-'))
|
|
@@ -866,7 +871,8 @@ describe('Claude Code adapter install', () => {
|
|
|
866
871
|
expect(paths.framework).not.toContain('CLAUDE.md')
|
|
867
872
|
expect(paths.framework).toContain('.claude/agents/')
|
|
868
873
|
expect(paths.framework).toContain('.claude/skills/')
|
|
869
|
-
expect(paths.framework).toContain('.claude/commands/')
|
|
874
|
+
expect(paths.framework).toContain('.claude/commands/oc/')
|
|
875
|
+
expect(paths.framework).not.toContain('.claude/commands/')
|
|
870
876
|
|
|
871
877
|
expect(paths.customizable).toContain('.opencastle/')
|
|
872
878
|
expect(paths.customizable).toContain('.mcp.json')
|
|
@@ -1074,29 +1080,40 @@ describe('Codex adapter install', () => {
|
|
|
1074
1080
|
expect(content).toContain('.codex/')
|
|
1075
1081
|
})
|
|
1076
1082
|
|
|
1077
|
-
it('
|
|
1083
|
+
it('puts agents in .codex/ and skills where Codex reads them, .agents/skills/', async () => {
|
|
1078
1084
|
const adapter = await IDE_ADAPTERS['codex']()
|
|
1079
1085
|
await adapter.install(PKG_ROOT, tmpDir, STACK_SANITY_LINEAR)
|
|
1080
1086
|
expect(existsSync(join(tmpDir, '.codex', 'agents'))).toBe(true)
|
|
1081
|
-
expect(existsSync(join(tmpDir, '.
|
|
1087
|
+
expect(existsSync(join(tmpDir, '.agents', 'skills', 'testing-workflow', 'SKILL.md'))).toBe(true)
|
|
1088
|
+
// Codex has never read this; nothing should be written there.
|
|
1089
|
+
expect(existsSync(join(tmpDir, '.codex', 'skills'))).toBe(false)
|
|
1090
|
+
const root = await readFile(join(tmpDir, 'AGENTS.md'), 'utf8')
|
|
1091
|
+
expect(root).toContain('`.agents/skills/testing-workflow/SKILL.md`')
|
|
1082
1092
|
})
|
|
1083
1093
|
|
|
1084
|
-
it('
|
|
1094
|
+
it('writes MCP servers as [mcp_servers] tables in .codex/config.toml', async () => {
|
|
1085
1095
|
const adapter = await IDE_ADAPTERS['codex']()
|
|
1086
1096
|
await adapter.install(PKG_ROOT, tmpDir, STACK_SANITY_LINEAR)
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
const
|
|
1090
|
-
expect(
|
|
1097
|
+
expect(existsSync(join(tmpDir, '.codex', 'mcp.json'))).toBe(false)
|
|
1098
|
+
const text = await readFile(join(tmpDir, '.codex', 'config.toml'), 'utf8')
|
|
1099
|
+
const config = parseToml(text) as { mcp_servers: Record<string, Record<string, unknown>> }
|
|
1100
|
+
expect(Object.keys(config.mcp_servers).length).toBeGreaterThan(0)
|
|
1101
|
+
for (const entry of Object.values(config.mcp_servers)) {
|
|
1102
|
+
// Codex expands no variables, so none may be written as text.
|
|
1103
|
+
expect(JSON.stringify(entry)).not.toMatch(/\$\{[A-Z_]+\}/)
|
|
1104
|
+
expect('url' in entry || 'command' in entry).toBe(true)
|
|
1105
|
+
}
|
|
1091
1106
|
})
|
|
1092
1107
|
|
|
1093
|
-
it('getManagedPaths includes AGENTS.md
|
|
1108
|
+
it('getManagedPaths includes AGENTS.md, the .codex dirs and .agents/skills/', async () => {
|
|
1094
1109
|
const adapter = await IDE_ADAPTERS['codex']()
|
|
1095
1110
|
const paths = adapter.getManagedPaths()
|
|
1096
1111
|
expect(paths.merged).toContain('AGENTS.md')
|
|
1097
1112
|
expect(paths.framework).not.toContain('AGENTS.md')
|
|
1098
|
-
expect(paths.framework.
|
|
1099
|
-
expect(paths.
|
|
1113
|
+
expect(paths.framework).toContain('.codex/agents/')
|
|
1114
|
+
expect(paths.framework).toContain('.agents/skills/')
|
|
1115
|
+
expect(paths.framework).not.toContain('.codex/skills/')
|
|
1116
|
+
expect(paths.customizable).toContain('.codex/config.toml')
|
|
1100
1117
|
})
|
|
1101
1118
|
})
|
|
1102
1119
|
|
package/src/cli/init.ts
CHANGED
|
@@ -6,20 +6,21 @@ import { readManifest, writeManifest, createManifest } from './manifest.js'
|
|
|
6
6
|
import { removeDirIfExists, copyDir, getOrchestratorRoot } from './copy.js'
|
|
7
7
|
import { updateGitignore } from './gitignore.js'
|
|
8
8
|
import { getCustomizationsTransform } from './stack-config.js'
|
|
9
|
-
import { getMcpConfigRelPath, stripManagedMcpServers } from './mcp.js'
|
|
9
|
+
import { getMcpConfigRelPath, stripManagedMcpServers, retireLegacyMcpConfig } from './mcp.js'
|
|
10
10
|
import { getPluginsBySubCategory } from '../orchestrator/plugins/index.js'
|
|
11
11
|
import type { PluginConfig } from '../orchestrator/plugins/types.js'
|
|
12
12
|
import { detectRepoInfo, mergeStackIntoRepoInfo, formatRepoInfo, buildDetectedToolsSet, detectCurrentIde, detectAssistantConfigs } from './detect.js'
|
|
13
13
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
14
14
|
import { IDE_LABELS } from './types.js'
|
|
15
|
-
import type { CliContext, CopyResults, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
|
|
15
|
+
import type { CliContext, CopyResults, IdeAdapter, IdeChoice, TechTool, TeamTool, StackConfig } from './types.js'
|
|
16
16
|
import { bootstrapCustomizations } from './bootstrap.js'
|
|
17
17
|
import { stripManagedBlock, stripManagedBlockFromFile } from './managed-block.js'
|
|
18
|
-
import { resolveManagedPaths, declaredManagedPaths } from './managed-paths.js'
|
|
19
|
-
import { noteUnreadable } from './unreadable-report.js'
|
|
18
|
+
import { resolveManagedPaths, declaredManagedPaths, ownerOf, removeOwnedFiles } from './managed-paths.js'
|
|
19
|
+
import { noteUnreadable, whyLeftAlone } from './unreadable-report.js'
|
|
20
20
|
import { resolveSources, materialize, hasErrors, formatIssues, requiredEnvVars } from './layers.js'
|
|
21
21
|
import { buildLock, writeLock, priorTeam } from './lock.js'
|
|
22
22
|
import { parseVersion, compareVersions } from './version-range.js'
|
|
23
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js'
|
|
23
24
|
|
|
24
25
|
const INIT_HELP = `
|
|
25
26
|
opencastle init [options]
|
|
@@ -381,10 +382,21 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
381
382
|
const previous = await resolveManagedPaths({ ...existing, ide: dropped[0], ides: dropped })
|
|
382
383
|
const keeping = await declaredManagedPaths(ides as string[])
|
|
383
384
|
const kept = new Set([...keeping.framework, ...(keeping.merged ?? [])])
|
|
384
|
-
|
|
385
|
+
// And what a release before the `oc:` namespace left outside them.
|
|
386
|
+
const droppedAdapters: IdeAdapter[] = []
|
|
387
|
+
for (const id of dropped) {
|
|
388
|
+
const load = IDE_ADAPTERS[id]
|
|
389
|
+
if (load) droppedAdapters.push(await load())
|
|
390
|
+
}
|
|
391
|
+
const legacy = droppedAdapters.flatMap((a) => a.getLegacyOutputs?.(projectRoot) ?? [])
|
|
392
|
+
for (const p of [...previous.framework, ...legacy]) {
|
|
385
393
|
if (kept.has(p)) continue
|
|
386
394
|
const fullPath = resolve(projectRoot, p)
|
|
387
|
-
|
|
395
|
+
// A directory the target shares with the user loses only its own files.
|
|
396
|
+
const owns = ownerOf(droppedAdapters, p, projectRoot)
|
|
397
|
+
if (owns) {
|
|
398
|
+
removeOwnedFiles(projectRoot, p, owns)
|
|
399
|
+
} else if (p.endsWith('/')) {
|
|
388
400
|
await removeDirIfExists(fullPath)
|
|
389
401
|
} else if (existsSync(fullPath)) {
|
|
390
402
|
await unlink(fullPath)
|
|
@@ -397,6 +409,7 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
397
409
|
for (const id of dropped) {
|
|
398
410
|
if ((ides as string[]).includes(id)) continue
|
|
399
411
|
await stripManagedMcpServers(projectRoot, id as IdeChoice)
|
|
412
|
+
await retireLegacyMcpConfig(projectRoot, id as IdeChoice)
|
|
400
413
|
}
|
|
401
414
|
|
|
402
415
|
// Co-owned files are not ours to delete — take back only the block, and
|
|
@@ -480,9 +493,22 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
480
493
|
}
|
|
481
494
|
}
|
|
482
495
|
|
|
483
|
-
// If all files were skipped (orphaned install — no manifest but files exist)
|
|
484
|
-
|
|
485
|
-
|
|
496
|
+
// If all files were skipped (orphaned install — no manifest but files exist).
|
|
497
|
+
//
|
|
498
|
+
// Or if a release before the `oc:` namespace left its commands here. The
|
|
499
|
+
// namespaced files are new, so they count as created and "all skipped" no
|
|
500
|
+
// longer holds for any install that old — its stale `/bug-fix` stayed beside
|
|
501
|
+
// `/oc:bug-fix` and its agent bodies were never refreshed.
|
|
502
|
+
const previousOutput: string[] = []
|
|
503
|
+
if (!isReinit) {
|
|
504
|
+
for (const ide of ides) {
|
|
505
|
+
previousOutput.push(...((await IDE_ADAPTERS[ide]()).getLegacyOutputs?.(projectRoot) ?? []))
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (((totalCreated === 0 && totalSkipped > 0) || previousOutput.length > 0) && !isReinit) {
|
|
509
|
+
console.log(
|
|
510
|
+
` ${c.yellow('⚠')} Found ${totalSkipped + previousOutput.length} existing files from a previous installation.`,
|
|
511
|
+
)
|
|
486
512
|
// `--yes` is documented as "accept the detected setup without asking", and
|
|
487
513
|
// this was the one question it did not cover. On a TTY it still asked.
|
|
488
514
|
// `refuse`, because the default here overwrites. A piped run that ran out of
|
|
@@ -634,7 +660,7 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
634
660
|
const name = isAbsolute(abs) ? relative(projectRoot, abs) : abs
|
|
635
661
|
console.log(
|
|
636
662
|
` ${c.yellow('!')} Left ${name} alone — ` +
|
|
637
|
-
(why
|
|
663
|
+
whyLeftAlone(name, why),
|
|
638
664
|
)
|
|
639
665
|
// `--force` is not decoration. A plain `sync` short-circuits when nothing
|
|
640
666
|
// has drifted, and the MCP config is a customizable path the drift checker
|
|
@@ -645,7 +671,7 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
645
671
|
// servers" for every entry, and the list now also carries generated rule and
|
|
646
672
|
// skill files, so a skipped `.cursor/rules/x.mdc` was explained in terms of a
|
|
647
673
|
// feature that has nothing to do with it.
|
|
648
|
-
const isMcp = /(^|[/\\])(\.mcp\.json|mcp\.json|opencode\.json)$/.test(name)
|
|
674
|
+
const isMcp = /(^|[/\\])(\.mcp\.json|mcp\.json|mcp_config\.json|opencode\.json|config\.toml)$/.test(name)
|
|
649
675
|
console.log(
|
|
650
676
|
` ${c.dim(
|
|
651
677
|
isMcp
|
|
@@ -828,6 +854,17 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
828
854
|
` ${step}. Set the environment variable${envVars.length > 1 ? 's' : ''} listed above (in .env or your shell)`
|
|
829
855
|
)
|
|
830
856
|
}
|
|
857
|
+
// The commands are namespaced, and a name nobody tells you is a name nobody
|
|
858
|
+
// types. Only where `/oc:` is a slash command.
|
|
859
|
+
const withCommands = ides.filter((id) => id === 'claude-code' || id === 'vscode')
|
|
860
|
+
if (withCommands.length > 0) {
|
|
861
|
+
step++
|
|
862
|
+
const where = withCommands.map((id) => (id === 'vscode' ? 'Copilot Chat' : 'Claude Code')).join(' or ')
|
|
863
|
+
console.log(
|
|
864
|
+
` ${step}. Type ${c.cyan(`/${COMMAND_NAMESPACE}:`)} in ${where} for OpenCastle's commands — ` +
|
|
865
|
+
`${c.cyan(`/${COMMAND_NAMESPACE}:bootstrap-customizations`)} first on an existing codebase`,
|
|
866
|
+
)
|
|
867
|
+
}
|
|
831
868
|
step++
|
|
832
869
|
console.log(` ${step}. Commit the .opencastle/ folder to your repository`)
|
|
833
870
|
|
package/src/cli/managed-paths.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
1
|
+
import { existsSync, readdirSync, rmdirSync, rmSync, statSync } from 'node:fs'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
3
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
4
|
-
import type { ManagedPaths, Manifest } from './types.js'
|
|
4
|
+
import type { IdeAdapter, ManagedPaths, Manifest } from './types.js'
|
|
5
|
+
import { CLAUDE_COMMANDS_DIR } from './command-namespace.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* What the manifest *should* say, given what the adapters declare today.
|
|
@@ -36,6 +37,22 @@ export const ROOT_INSTRUCTION_FILES = [
|
|
|
36
37
|
'.github/copilot-instructions.md',
|
|
37
38
|
] as const
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Framework paths a release recorded that today's compiler has narrowed.
|
|
42
|
+
*
|
|
43
|
+
* Before the `oc:` namespace the whole of `.claude/commands/` was generated, and manifests
|
|
44
|
+
* recorded it. Commands now live under `.claude/commands/oc/`, and the rest of
|
|
45
|
+
* the directory is the user's — so a stored `.claude/commands/` must not stay
|
|
46
|
+
* in `framework`, where `remove` and a dropped target's cleanup would delete
|
|
47
|
+
* every command a person wrote there. What those releases left at the top is
|
|
48
|
+
* found by its banner instead (`getLegacyOutputs`).
|
|
49
|
+
*/
|
|
50
|
+
const SUPERSEDED_FRAMEWORK: Record<string, string> = {
|
|
51
|
+
'.claude/commands/': `.claude/${CLAUDE_COMMANDS_DIR}/`,
|
|
52
|
+
// Codex never read `.codex/skills/`; its skills moved to the shared location.
|
|
53
|
+
'.codex/skills/': '.agents/skills/',
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
function unique(values: string[]): string[] {
|
|
40
57
|
return [...new Set(values)]
|
|
41
58
|
}
|
|
@@ -78,7 +95,7 @@ export async function resolveManagedPaths(manifest: Manifest): Promise<Required<
|
|
|
78
95
|
|
|
79
96
|
return {
|
|
80
97
|
framework: unique([
|
|
81
|
-
...(stored?.framework ?? []),
|
|
98
|
+
...(stored?.framework ?? []).map((p) => SUPERSEDED_FRAMEWORK[p] ?? p),
|
|
82
99
|
...declared.framework,
|
|
83
100
|
]).filter((p) => !isMerged(p)),
|
|
84
101
|
customizable: unique([
|
|
@@ -95,6 +112,61 @@ export async function resolveManagedPaths(manifest: Manifest): Promise<Required<
|
|
|
95
112
|
}
|
|
96
113
|
}
|
|
97
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Which files in a framework directory the given targets wrote, when one of
|
|
117
|
+
* them shares that directory with the user — `undefined` when the directory is
|
|
118
|
+
* wholly generated and can be removed whole.
|
|
119
|
+
*/
|
|
120
|
+
export function ownerOf(
|
|
121
|
+
adapters: IdeAdapter[],
|
|
122
|
+
dir: string,
|
|
123
|
+
projectRoot: string,
|
|
124
|
+
): ((_rel: string) => boolean) | undefined {
|
|
125
|
+
const sharing = adapters.filter((a) => a.ownsFile && a.getSharedDirs?.().includes(dir))
|
|
126
|
+
if (sharing.length === 0) return undefined
|
|
127
|
+
return (rel) => sharing.every((a) => a.ownsFile!(rel, projectRoot))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Delete the files at the top of a shared directory that `owns` claims, and the
|
|
132
|
+
* directory itself if that empties it — never anything of the user's.
|
|
133
|
+
*
|
|
134
|
+
* Only the top level: the one shared directory, `.github/prompts/`, is read
|
|
135
|
+
* there and nowhere deeper, so nothing below it is ours, and walking into a
|
|
136
|
+
* person's subfolders could only delete their empty ones or stop at one it
|
|
137
|
+
* cannot read. A path that is not a readable directory is left for a person.
|
|
138
|
+
* Returns how many files went.
|
|
139
|
+
*/
|
|
140
|
+
export function removeOwnedFiles(projectRoot: string, dir: string, owns: (_rel: string) => boolean): number {
|
|
141
|
+
const root = resolve(projectRoot, dir)
|
|
142
|
+
const prefix = dir.endsWith('/') ? dir : `${dir}/`
|
|
143
|
+
let entries
|
|
144
|
+
try {
|
|
145
|
+
if (!statSync(root).isDirectory()) return 0
|
|
146
|
+
entries = readdirSync(root, { withFileTypes: true })
|
|
147
|
+
} catch {
|
|
148
|
+
return 0
|
|
149
|
+
}
|
|
150
|
+
let removed = 0
|
|
151
|
+
for (const entry of entries) {
|
|
152
|
+
if (entry.isDirectory() || !owns(`${prefix}${entry.name}`)) continue
|
|
153
|
+
try {
|
|
154
|
+
// `rmSync` rather than `unlinkSync`: on Windows it gets past a read-only
|
|
155
|
+
// file, which `unlink` fails on with EPERM.
|
|
156
|
+
rmSync(resolve(root, entry.name), { force: true })
|
|
157
|
+
removed++
|
|
158
|
+
} catch {
|
|
159
|
+
// Left for a person; one stubborn file must not stop the uninstall.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
if (readdirSync(root).length === 0) rmdirSync(root)
|
|
164
|
+
} catch {
|
|
165
|
+
// As above.
|
|
166
|
+
}
|
|
167
|
+
return removed
|
|
168
|
+
}
|
|
169
|
+
|
|
98
170
|
/**
|
|
99
171
|
* Files an install is not complete without.
|
|
100
172
|
*
|
package/src/cli/manifest.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { resolve, dirname, relative } from 'node:path';
|
|
|
3
3
|
import { existsSync, readdirSync } from 'node:fs';
|
|
4
4
|
import type { Manifest } from './types.js';
|
|
5
5
|
import { UnreadableConfigError } from './types.js';
|
|
6
|
+
import { COMMAND_NAMESPACE } from './command-namespace.js';
|
|
6
7
|
|
|
7
8
|
const MANIFEST_FILE = '.opencastle/manifest.json';
|
|
8
9
|
|
|
@@ -91,5 +92,6 @@ export function createManifest(version: string, ide: string, ides?: string[]): M
|
|
|
91
92
|
ides: ides ?? [ide],
|
|
92
93
|
installedAt: new Date().toISOString(),
|
|
93
94
|
updatedAt: new Date().toISOString(),
|
|
95
|
+
commandNamespace: COMMAND_NAMESPACE,
|
|
94
96
|
};
|
|
95
97
|
}
|
package/src/cli/mcp-audit.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { resolve } from 'node:path'
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs'
|
|
3
3
|
import { PLUGINS } from '../orchestrator/plugins/index.js'
|
|
4
4
|
import { getMcpConfigRelPath, upgradeGeneratedServers, canonicalJson } from './mcp.js'
|
|
5
|
+
import { parseMcpConfigText } from './mcp-file.js'
|
|
5
6
|
import type { IdeChoice } from './types.js'
|
|
6
7
|
import { disallowedBy, hostDisallowedBy, findInlineSecret, hostOfUrl, type EffectivePolicy } from './policy.js'
|
|
7
8
|
import { EDITOR_VARIABLES } from './team-config.js'
|
|
@@ -256,7 +257,7 @@ export function isPinned(launch: PackageLaunch): boolean {
|
|
|
256
257
|
function serverEntries(config: unknown): Array<[string, Record<string, unknown>]> {
|
|
257
258
|
if (!config || typeof config !== 'object') return []
|
|
258
259
|
const out: Array<[string, Record<string, unknown>]> = []
|
|
259
|
-
for (const key of ['servers', 'mcpServers', 'mcp']) {
|
|
260
|
+
for (const key of ['servers', 'mcpServers', 'mcp', 'mcp_servers']) {
|
|
260
261
|
const container = (config as Record<string, unknown>)[key]
|
|
261
262
|
if (!container || typeof container !== 'object' || Array.isArray(container)) continue
|
|
262
263
|
for (const [name, entry] of Object.entries(container as Record<string, unknown>)) {
|
|
@@ -437,6 +438,9 @@ const OWN_SPELLING: Partial<Record<IdeChoice, (name: string) => string>> = {
|
|
|
437
438
|
cursor: (n) => `\${env:${n}}`,
|
|
438
439
|
windsurf: (n) => `\${env:${n}}`,
|
|
439
440
|
opencode: (n) => `{env:${n}}`,
|
|
441
|
+
// Codex expands nothing: a variable reaches a server only by being named in
|
|
442
|
+
// a field that reads one.
|
|
443
|
+
codex: (n) => `env_vars, bearer_token_env_var or env_http_headers naming ${n}`,
|
|
440
444
|
}
|
|
441
445
|
|
|
442
446
|
/** The first `${NAME}` this target would pass through literally, as `NAME → spelling`, or null. */
|
|
@@ -444,7 +448,7 @@ function unexpandedVariable(entry: Record<string, unknown>, ide: IdeChoice): str
|
|
|
444
448
|
const spell = OWN_SPELLING[ide]
|
|
445
449
|
if (!spell) return null
|
|
446
450
|
const values: unknown[] = []
|
|
447
|
-
for (const field of ['env', 'environment', 'headers']) {
|
|
451
|
+
for (const field of ['env', 'environment', 'headers', 'http_headers']) {
|
|
448
452
|
const block = entry[field]
|
|
449
453
|
if (block && typeof block === 'object' && !Array.isArray(block)) values.push(...Object.values(block as Record<string, unknown>))
|
|
450
454
|
}
|
|
@@ -572,7 +576,7 @@ export function checkMcpSupplyChain(
|
|
|
572
576
|
if (!existsSync(abs)) return { ok: true, label: LABEL, detail: 'no MCP config' }
|
|
573
577
|
let parsed: unknown
|
|
574
578
|
try {
|
|
575
|
-
parsed =
|
|
579
|
+
parsed = parseMcpConfigText(readFileSync(abs, 'utf8'), rel)
|
|
576
580
|
} catch {
|
|
577
581
|
return { ok: true, label: LABEL, detail: `${rel} could not be read (reported above)` }
|
|
578
582
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { parse as parseToml } from 'smol-toml'
|
|
3
|
+
import { parseMcpConfigText, serialiseMcpConfig, TomlEditError } from './mcp-file.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `.codex/config.toml` holds a user's whole Codex setup — model, approvals,
|
|
7
|
+
* sandbox, profiles — beside the MCP servers OpenCastle writes. These pin the
|
|
8
|
+
* promise the JSON configs already keep: our servers change, nothing of theirs
|
|
9
|
+
* does, byte for byte.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const REL = '.codex/config.toml'
|
|
13
|
+
|
|
14
|
+
const USERS_OWN = `# My Codex setup
|
|
15
|
+
model = "gpt-5-codex"
|
|
16
|
+
approval_policy = "on-request"
|
|
17
|
+
|
|
18
|
+
[profiles.fast]
|
|
19
|
+
model = "gpt-5-codex-mini" # quick tasks
|
|
20
|
+
|
|
21
|
+
[mcp_servers.mine]
|
|
22
|
+
command = "my-server"
|
|
23
|
+
args = ["--port", "1234"]
|
|
24
|
+
|
|
25
|
+
[mcp_servers.mine.tools.dangerous]
|
|
26
|
+
approval_mode = "approve"
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
function serversOf(text: string): Record<string, unknown> {
|
|
30
|
+
return (parseToml(text) as { mcp_servers?: Record<string, unknown> }).mcp_servers ?? {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('Codex config.toml', () => {
|
|
34
|
+
it('parses to a plain object with mcp_servers as the container', () => {
|
|
35
|
+
const parsed = parseMcpConfigText(USERS_OWN, REL)
|
|
36
|
+
expect(Object.getPrototypeOf(parsed)).toBe(Object.prototype)
|
|
37
|
+
expect(Object.keys(parsed.mcp_servers as object)).toEqual(['mine'])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('adds a server after the user’s content and changes nothing of theirs', () => {
|
|
41
|
+
const value = parseMcpConfigText(USERS_OWN, REL)
|
|
42
|
+
;(value.mcp_servers as Record<string, unknown>).Linear = { url: 'https://mcp.linear.app/mcp' }
|
|
43
|
+
const text = serialiseMcpConfig(USERS_OWN, value, REL)
|
|
44
|
+
expect(text.startsWith(USERS_OWN)).toBe(true)
|
|
45
|
+
expect(text.slice(USERS_OWN.length)).toBe('\n[mcp_servers.Linear]\nurl = "https://mcp.linear.app/mcp"\n')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('removes only the server it was asked to, with its sub-tables', () => {
|
|
49
|
+
const withOurs = USERS_OWN + '\n[mcp_servers.Sanity]\ncommand = "npx"\nargs = ["-y", "@sanity/mcp-server@1.2.3"]\n'
|
|
50
|
+
const value = parseMcpConfigText(withOurs, REL)
|
|
51
|
+
delete (value.mcp_servers as Record<string, unknown>).Sanity
|
|
52
|
+
expect(serialiseMcpConfig(withOurs, value, REL)).toBe(USERS_OWN)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('gives the user their file back byte for byte after an add and a remove', () => {
|
|
56
|
+
const value = parseMcpConfigText(USERS_OWN, REL)
|
|
57
|
+
;(value.mcp_servers as Record<string, unknown>).Linear = { url: 'https://mcp.linear.app/mcp' }
|
|
58
|
+
const added = serialiseMcpConfig(USERS_OWN, value, REL)
|
|
59
|
+
const back = parseMcpConfigText(added, REL)
|
|
60
|
+
delete (back.mcp_servers as Record<string, unknown>).Linear
|
|
61
|
+
expect(serialiseMcpConfig(added, back, REL)).toBe(USERS_OWN)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('rewrites a changed server in place and keeps the tables around it', () => {
|
|
65
|
+
const before =
|
|
66
|
+
'model = "x"\n\n[mcp_servers.Sentry]\nurl = "https://old.example/mcp"\n\n[profiles.a]\nmodel = "y"\n'
|
|
67
|
+
const value = parseMcpConfigText(before, REL)
|
|
68
|
+
;(value.mcp_servers as Record<string, Record<string, unknown>>).Sentry = { url: 'https://mcp.sentry.dev/mcp' }
|
|
69
|
+
const text = serialiseMcpConfig(before, value, REL)
|
|
70
|
+
expect(text).toBe('model = "x"\n\n[mcp_servers.Sentry]\nurl = "https://mcp.sentry.dev/mcp"\n\n[profiles.a]\nmodel = "y"\n')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('quotes a server name that is not a bare key', () => {
|
|
74
|
+
const value = { mcp_servers: { 'Chrome DevTools': { command: 'npx', args: ['chrome-devtools-mcp@0.1.0'] } } }
|
|
75
|
+
const text = serialiseMcpConfig(null, value, REL)
|
|
76
|
+
expect(text).toContain('[mcp_servers."Chrome DevTools"]')
|
|
77
|
+
expect(serversOf(text)).toEqual(value.mcp_servers)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('writes env, env_vars and headers as values Codex reads back the same', () => {
|
|
81
|
+
const entry = {
|
|
82
|
+
url: 'https://api.example.com/mcp',
|
|
83
|
+
bearer_token_env_var: 'EXAMPLE_TOKEN',
|
|
84
|
+
http_headers: { 'X-Tenant': 'acme' },
|
|
85
|
+
env_http_headers: { 'X-Key': 'EXAMPLE_KEY' },
|
|
86
|
+
}
|
|
87
|
+
const stdio = { command: 'npx', args: ['-y', 'x@1.0.0'], env: { MODE: 'ci "quoted"\\path' }, env_vars: ['API_TOKEN'] }
|
|
88
|
+
const value = { mcp_servers: { remote: entry, local: stdio } }
|
|
89
|
+
const text = serialiseMcpConfig(null, value, REL)
|
|
90
|
+
expect(serversOf(text)).toEqual(value.mcp_servers)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('keeps CRLF line endings', () => {
|
|
94
|
+
const before = USERS_OWN.replace(/\n/g, '\r\n')
|
|
95
|
+
const value = parseMcpConfigText(before, REL)
|
|
96
|
+
;(value.mcp_servers as Record<string, unknown>).Linear = { url: 'https://mcp.linear.app/mcp' }
|
|
97
|
+
const text = serialiseMcpConfig(before, value, REL)
|
|
98
|
+
expect(text.startsWith(before)).toBe(true)
|
|
99
|
+
expect(text.replace(/\r\n/g, '')).not.toContain('\n')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('does not mistake a header-like line inside a multi-line string for a table', () => {
|
|
103
|
+
const before = 'instructions = """\n[mcp_servers.fake]\nnot a table\n"""\n\n[mcp_servers.real]\ncommand = "a"\n'
|
|
104
|
+
const value = parseMcpConfigText(before, REL)
|
|
105
|
+
;(value.mcp_servers as Record<string, Record<string, unknown>>).real = { command: 'b' }
|
|
106
|
+
const text = serialiseMcpConfig(before, value, REL)
|
|
107
|
+
expect(text).toContain('[mcp_servers.fake]\nnot a table')
|
|
108
|
+
expect(serversOf(text)).toEqual({ real: { command: 'b' } })
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('refuses rather than rewrites servers written as inline tables', () => {
|
|
112
|
+
const before = '[mcp_servers]\nmine = { command = "a" }\n'
|
|
113
|
+
const value = parseMcpConfigText(before, REL)
|
|
114
|
+
;(value.mcp_servers as Record<string, Record<string, unknown>>).mine = { command: 'b' }
|
|
115
|
+
expect(() => serialiseMcpConfig(before, value, REL)).toThrow(TomlEditError)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('refuses to change anything outside [mcp_servers]', () => {
|
|
119
|
+
const value = parseMcpConfigText(USERS_OWN, REL)
|
|
120
|
+
value.model = 'something-else'
|
|
121
|
+
expect(() => serialiseMcpConfig(USERS_OWN, value, REL)).toThrow(TomlEditError)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('leaves no [mcp_servers] residue when the last of ours goes', () => {
|
|
125
|
+
const before = 'model = "x"\n\n[mcp_servers.Linear]\nurl = "https://mcp.linear.app/mcp"\n'
|
|
126
|
+
const value = parseMcpConfigText(before, REL)
|
|
127
|
+
delete value.mcp_servers
|
|
128
|
+
expect(serialiseMcpConfig(before, value, REL)).toBe('model = "x"\n')
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('JSON configs are untouched by the TOML path', () => {
|
|
133
|
+
it('keeps the file’s indentation', () => {
|
|
134
|
+
const before = '{\n\t"mcpServers": {}\n}\n'
|
|
135
|
+
const text = serialiseMcpConfig(before, { mcpServers: { a: { command: 'x' } } }, '.mcp.json')
|
|
136
|
+
expect(text).toBe('{\n\t"mcpServers": {\n\t\t"a": {\n\t\t\t"command": "x"\n\t\t}\n\t}\n}\n')
|
|
137
|
+
})
|
|
138
|
+
})
|