Skip to content

Commit 19f348c

Browse files
committed
feat: co-refresh VS Code user MCP with global-adapters apply
Merge devcodex-memory and devcodex-profile into Code/User/mcp.json (and Insiders when present) on the same Copilot host transaction as the five-host apply, preserving existing inputs and servers. Paths are home-scoped for tests.
1 parent 8c901e9 commit 19f348c

5 files changed

Lines changed: 141 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ README / 用户使用文档当前补充四类专项 Skill:`user-manual-authori
592592
>
593593
> **能力差异**:🟢 Full = 已验证 Hook 事件 + MCP + 自动同步;🟡 Beta/Best-effort = 尚未达到 Full,具体能力以矩阵各列为准;🔴 Unsupported = 不在当前本地 adapter 发布范围。默认 `safety-only` 下,bootstrap / CP / auto 白名单等流程问题为提醒并继续,仅危险命令硬拦;设置 `DEVCODEX_HOOK_ENFORCEMENT=strict` 后,支持硬拦的事件才会停止流程。
594594
>
595-
> **MCP 边界**:Copilot CLI、Claude、Codex 与 Grok 的 MCP 配置指向各自用户级稳定 runtime;server 再从宿主 cwd 发现 workspace `.devcodex`。源码仓受版本控制的 `.mcp.json` 仅是包开发清单。Copilot IDE 与 Copilot CLI 是不同 surface,不能用 CLI 配置反推 IDE Hook/MCP 已生效。
595+
> **MCP 边界**:Copilot CLI、Claude、Codex 与 Grok 的 MCP 配置指向各自用户级稳定 runtime;server 再从宿主 cwd 发现 workspace `.devcodex`。源码仓受版本控制的 `.mcp.json` 仅是包开发清单。**VS Code 用户级** `mcp.json`(全局,`MCP: Open User Configuration`)在 `global-adapters apply` / 全局安装刷新 **与五宿主同一事务** 中合并写入 `devcodex-memory` / `devcodex-profile`(保留其它 servers/inputs);这与 Copilot CLI 的 `~/.copilot/mcp-config.json` 是不同文件。Copilot IDE 的 Hooks 能力仍可能弱于 CLI,不能用 CLI Hook 结论反推 IDE 已全量硬拦。
596596
597597
### 当前 MCP 清单与新增能力判断
598598

‎changelogs/unreleased.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
> **当前**: v1.15.3 已归档到 `changelogs/releases/v1.15.3.md`;本文件仅保留历史锚点索引与镜像供 validate 探针消费。发版后新实现再写入下方「当前未发布」。
55
66
## 当前未发布实现候选
7+
- **VS Code 全局 MCP 与五宿主同刷**:`global-adapters apply` / 全局安装在 Copilot host 事务中合并写入用户级 `Code/User/mcp.json`(及已存在的 Code - Insiders)的 `servers.devcodex-memory|profile`(stdio→copilot runtime mcp),保留既有 `inputs`/其它 server;测试与边界见 `global-host-target.resolveVscodeUserMcpPaths`。
78
- **SkillsDeployModeV1(隐蔽运行时 + PR-1 防假绿)**:默认 `skillsDeployMode=hidden` 将 active skills 部署到 `~/.agents/devcodex/skills`(G_RUNTIME),停写/目录 prune `~/.agents/skills`、`~/.claude/skills`、`~/.copilot/skills` 中的包 managed id;`resolveGlobalSkillsRoot` 随 mode 切换(ENV `DEVCODEX_GLOBAL_SKILLS_ROOT` 仍最高优先);`global-adapters apply --mode=hidden|legacy` 与 npm lifecycle 透传;receipt 记录 mode。强化 `pr1EvidenceOk`:有 `02` 须独立实质 `03` 复审(长度+blocker=0+实质章节),拒绝 thin open-blocker / sessions-only;改写 stop-gate 负向探针。需求:`全局Skill与插件隐蔽运行时`。
89
- **Runtime 白名单闭包防复发**:新增 `scripts/lib/runtime-dependency-closure.js` 作为统一 runtime require 闭包 Owner;`MCP_RUNTIME_DEPS` / `PROJECT_RUNTIME_SCRIPT_DEPS`(兼容 `CLAUDE_MCP_RUNTIME_SCRIPT_DEPS`)改为派生;Codex project hook 复制到 `.codex/scripts/lib`;`test:mcp-runtime-closure` 覆盖 allowlist-only layout/MCP smoke/负向/packlist;validation 节点 `mcp-runtime-closure` 接入 fast/full/profile-deploy/package-release。需求:`bugs/runtime白名单闭包防复发修复`。
910
- **P0-1 工作区意图 + DEVCODEX.md + ImplementStartGate + e2e(Batch1)**:入口 `.devcodex/workspace/DEVCODEX.md`;`workspace-skill-intent` catalog/意图/lifecycle;控制面 mutation 前 04+05+复审清单门闩(`IMPLEMENT_START_WITHOUT_PROCESS`);全局 skill `workspace-skill-author`;`npm run test:workspace-skill-intent` / `test:workspace-skill-intent-e2e`(E2E-A~J+K)并入 `test:skill-resolve`。**无 e2e 不算 Batch1 完成**。需求:`开源发布前用户面与文档边界收口`。

‎scripts/lib/global-host-config.js‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,40 @@ function buildCopilotMcpServers(runtimeRoot) {
231231
)
232232
}
233233

234+
/** VS Code user mcp.json "servers" entries (stdio). */
235+
function buildVscodeMcpServers (runtimeRoot) {
236+
return Object.fromEntries(
237+
Object.entries(buildMcpServers(runtimeRoot)).map(([name, server]) => [
238+
name,
239+
{
240+
type: 'stdio',
241+
command: server.command,
242+
args: server.args
243+
}
244+
])
245+
)
246+
}
247+
248+
/**
249+
* Merge DevCodex servers into VS Code User mcp.json without wiping inputs / other servers.
250+
*/
251+
function mergeVscodeUserMcpContent (existingText, runtimeRoot) {
252+
let doc = {}
253+
try {
254+
doc = parseJsonObject(existingText, 'VS Code user mcp.json')
255+
} catch {
256+
doc = {}
257+
}
258+
if (!doc.servers || typeof doc.servers !== 'object' || Array.isArray(doc.servers)) {
259+
doc.servers = {}
260+
}
261+
const managed = buildVscodeMcpServers(runtimeRoot)
262+
for (const [name, server] of Object.entries(managed)) {
263+
doc.servers[name] = server
264+
}
265+
return `${JSON.stringify(doc, null, 2)}\n`
266+
}
267+
234268
function codexTomlBlock(target) {
235269
const servers = buildMcpServers(target.runtimeRoot)
236270
return [
@@ -299,6 +333,30 @@ function addCopilotPlan(operations, target, packageRoot, fsImpl) {
299333
'json',
300334
`${JSON.stringify(mcp, null, 2)}\n`
301335
)
336+
// Co-refresh VS Code User mcp.json (global) on the same apply transaction as Copilot host
337+
const vscodePaths = []
338+
if (target.files && target.files.vscodeMcp) vscodePaths.push(target.files.vscodeMcp)
339+
if (Array.isArray(target.additionalFiles)) {
340+
for (const file of target.additionalFiles) {
341+
if (file && /mcp\.json$/i.test(file)) vscodePaths.push(file)
342+
}
343+
}
344+
const seenVscode = new Set()
345+
for (const vscodeMcpPath of vscodePaths) {
346+
const key = portable(vscodeMcpPath)
347+
if (seenVscode.has(key)) continue
348+
seenVscode.add(key)
349+
const existing = readText(vscodeMcpPath, fsImpl)
350+
const merged = mergeVscodeUserMcpContent(existing, target.runtimeRoot)
351+
addFileOperation(
352+
operations,
353+
target.host,
354+
vscodeMcpPath,
355+
merged,
356+
'json',
357+
merged
358+
)
359+
}
302360
}
303361

304362
function addClaudePlan(operations, target, packageRoot, fsImpl) {
@@ -1201,6 +1259,8 @@ module.exports = {
12011259
buildGlobalHostConfigPlan,
12021260
buildCopilotMcpServers,
12031261
buildMcpServers,
1262+
buildVscodeMcpServers,
1263+
mergeVscodeUserMcpContent,
12041264
copilotHookDocument,
12051265
digestPlan,
12061266
inspectGlobalHostConfig,

‎scripts/lib/global-host-target.js‎

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@ function hostRoot(host, home, env) {
2525
throw new Error(`GLOBAL_HOST_UNSUPPORTED: ${host}`)
2626
}
2727

28+
/**
29+
* VS Code user-profile MCP config (global, all workspaces).
30+
* Prefer paths under the resolved home so tests with a temp home never touch real APPDATA.
31+
* Override: DEVCODEX_VSCODE_MCP_PATH (single file) or DEVCODEX_VSCODE_USER_DIR.
32+
*/
33+
function resolveVscodeAppDataRoot (home, env = process.env) {
34+
const homeAbs = path.resolve(home)
35+
if (process.platform === 'win32') {
36+
const appData = env.APPDATA && isUnder(homeAbs, env.APPDATA)
37+
? path.resolve(env.APPDATA)
38+
: path.join(homeAbs, 'AppData', 'Roaming')
39+
return appData
40+
}
41+
if (process.platform === 'darwin') {
42+
return path.join(homeAbs, 'Library', 'Application Support')
43+
}
44+
const xdg = env.XDG_CONFIG_HOME && isUnder(homeAbs, env.XDG_CONFIG_HOME)
45+
? path.resolve(env.XDG_CONFIG_HOME)
46+
: path.join(homeAbs, '.config')
47+
return xdg
48+
}
49+
50+
function resolveVscodeUserMcpPaths (home, env = process.env, fsImpl = fs) {
51+
if (env.DEVCODEX_VSCODE_MCP_PATH) {
52+
return [path.resolve(env.DEVCODEX_VSCODE_MCP_PATH)]
53+
}
54+
if (env.DEVCODEX_VSCODE_USER_DIR) {
55+
return [path.join(path.resolve(env.DEVCODEX_VSCODE_USER_DIR), 'mcp.json')]
56+
}
57+
const appData = resolveVscodeAppDataRoot(home, env)
58+
const paths = [path.join(appData, 'Code', 'User', 'mcp.json')]
59+
// Also refresh Insiders when that product tree already exists (do not create product shell only for us)
60+
const insidersUser = path.join(appData, 'Code - Insiders', 'User')
61+
if (fsImpl.existsSync(path.join(appData, 'Code - Insiders')) || fsImpl.existsSync(insidersUser)) {
62+
paths.push(path.join(insidersUser, 'mcp.json'))
63+
}
64+
return paths
65+
}
66+
2867
function resolveGlobalSharedTarget(home, env = process.env) {
2968
const root = path.resolve(env.DEVCODEX_GLOBAL_SHARED_ROOT || path.join(home, '.agents'))
3069
// SCAN root (host L1). Optional DEVCODEX_GLOBAL_SKILLS_ROOT still overrides scan path for legacy tests.
@@ -126,16 +165,22 @@ function resolveGlobalHostTarget(host, options = {}) {
126165
}
127166

128167
if (normalized === 'copilot') {
168+
const vscodeMcpPaths = resolveVscodeUserMcpPaths(home, env)
169+
const vscodeUserDirs = [...new Set(vscodeMcpPaths.map(file => path.dirname(file)))]
129170
return assertTargetBoundary({
130171
...common,
131172
support: 'contract-fixture',
132-
evidenceCeiling: 'Copilot CLI user instructions, Hooks, MCP, and Skills; direct CLI execution is environment-dependent',
173+
evidenceCeiling: 'Copilot CLI user instructions, Hooks, MCP, and Skills; VS Code user mcp.json is co-refreshed with apply',
133174
files: {
134175
instructions: path.join(root, 'copilot-instructions.md'),
135176
hooks: path.join(root, 'hooks', 'devcodex.json'),
136177
mcp: path.join(root, 'mcp-config.json'),
137-
skills: path.join(root, 'skills')
138-
}
178+
skills: path.join(root, 'skills'),
179+
// Primary VS Code User MCP (first path); extras go via additionalFiles
180+
vscodeMcp: vscodeMcpPaths[0]
181+
},
182+
additionalRoots: [shared.root, ...vscodeUserDirs],
183+
additionalFiles: vscodeMcpPaths.slice(1)
139184
})
140185
}
141186
if (normalized === 'claude') {
@@ -205,6 +250,8 @@ module.exports = {
205250
resolveGlobalHostTarget,
206251
resolveGlobalHostTargets,
207252
resolveHome,
253+
resolveVscodeAppDataRoot,
254+
resolveVscodeUserMcpPaths,
208255
samePath,
209256
targetAcceptsPath
210257
}

‎scripts/test-global-host-config.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,35 @@ assert.strictEqual(copilotHooks.hooks.PreToolUse[0].matcher, '*')
274274
const copilotMcp = JSON.parse(fs.readFileSync(path.join(home, '.copilot', 'mcp-config.json'), 'utf8'))
275275
assert.strictEqual(copilotMcp.theme, 'user-owned')
276276
assert.ok(copilotMcp.mcpServers.custom)
277+
// VS Code User mcp.json co-refreshed with the same apply (global surface)
278+
const vscodeMcpPath = path.join(home, 'AppData', 'Roaming', 'Code', 'User', 'mcp.json')
279+
assert.strictEqual(fs.existsSync(vscodeMcpPath), true, 'apply must write VS Code User mcp.json')
280+
const vscodeMcp = JSON.parse(fs.readFileSync(vscodeMcpPath, 'utf8'))
281+
assert.ok(vscodeMcp.servers, 'VS Code mcp.json must have servers')
282+
for (const name of ['devcodex-memory', 'devcodex-profile']) {
283+
assert.ok(vscodeMcp.servers[name], `VS Code servers missing ${name}`)
284+
assert.strictEqual(vscodeMcp.servers[name].command, 'node')
285+
assert.ok(
286+
String(vscodeMcp.servers[name].args[0]).includes('memory-server.js') ||
287+
String(vscodeMcp.servers[name].args[0]).includes('profile-server.js') ||
288+
name === 'devcodex-memory' || name === 'devcodex-profile'
289+
)
290+
}
291+
assert.ok(String(vscodeMcp.servers['devcodex-memory'].args[0]).replace(/\\/g, '/').includes('/mcp/memory-server.js'))
292+
assert.ok(String(vscodeMcp.servers['devcodex-profile'].args[0]).replace(/\\/g, '/').includes('/mcp/profile-server.js'))
293+
// preserve non-DevCodex keys on re-apply
294+
fs.writeFileSync(vscodeMcpPath, JSON.stringify({
295+
inputs: [{ id: 'KEEP_ME', type: 'promptString' }],
296+
servers: {
297+
custom: { command: 'echo', args: ['hi'] },
298+
'devcodex-memory': { command: 'node', args: ['old'] }
299+
}
300+
}, null, 2))
301+
assert.strictEqual(applyGlobalHostConfig({ packageRoot, env, home }).transaction.status, 'committed')
302+
const vscodeMerged = JSON.parse(fs.readFileSync(vscodeMcpPath, 'utf8'))
303+
assert.strictEqual(vscodeMerged.inputs[0].id, 'KEEP_ME')
304+
assert.strictEqual(vscodeMerged.servers.custom.command, 'echo')
305+
assert.ok(String(vscodeMerged.servers['devcodex-memory'].args[0]).includes('memory-server.js'))
277306
for (const name of ['devcodex-memory', 'devcodex-profile']) {
278307
assert.strictEqual(copilotMcp.mcpServers[name].type, 'local')
279308
assert.deepStrictEqual(copilotMcp.mcpServers[name].tools, ['*'])

0 commit comments

Comments
 (0)