@intra-mart/accel 0.5.0 → 0.6.0-dev.202609241904
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 +22 -3
- package/assets/runtime/ensure.mjs +914 -0
- package/dist/asset/dependencies.d.ts +7 -0
- package/dist/asset/dependencies.js +23 -0
- package/dist/asset/deployer.d.ts +1 -0
- package/dist/asset/deployer.js +11 -3
- package/dist/asset/installer.js +3 -8
- package/dist/asset/updater.d.ts +2 -0
- package/dist/asset/updater.js +3 -0
- package/dist/asset/walker.d.ts +1 -0
- package/dist/asset/walker.js +65 -3
- package/dist/commands/attach.d.ts +4 -1
- package/dist/commands/attach.js +8 -1
- package/dist/commands/detach.d.ts +2 -0
- package/dist/commands/detach.js +4 -0
- package/dist/commands/init.d.ts +4 -1
- package/dist/commands/init.js +8 -1
- package/dist/commands/switch.d.ts +3 -0
- package/dist/commands/switch.js +12 -3
- package/dist/commands/update.d.ts +4 -0
- package/dist/commands/update.js +26 -5
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +22 -1
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +6 -0
- package/dist/core/gitignore-entries.d.ts +7 -0
- package/dist/core/gitignore-entries.js +16 -0
- package/dist/core/paths.d.ts +1 -0
- package/dist/core/paths.js +1 -0
- package/dist/core/types.d.ts +2 -1
- package/dist/core/variable-interpolator.js +4 -0
- package/dist/i18n/en.js +15 -0
- package/dist/i18n/ja.js +15 -0
- package/dist/i18n/zh_CN.js +15 -0
- package/dist/interactive/next-steps.d.ts +1 -0
- package/dist/interactive/next-steps.js +3 -0
- package/dist/utils/credentials.d.ts +2 -1
- package/dist/utils/credentials.js +3 -2
- package/dist/utils/gitignore.d.ts +1 -0
- package/dist/utils/gitignore.js +8 -6
- package/dist/utils/mcp-generate.d.ts +8 -1
- package/dist/utils/mcp-generate.js +261 -31
- package/dist/utils/runtime-ensure.d.ts +55 -0
- package/dist/utils/runtime-ensure.js +391 -0
- package/dist/utils/sanitize-text.d.ts +2 -0
- package/dist/utils/sanitize-text.js +7 -0
- package/dist/utils/settings-io.d.ts +2 -1
- package/dist/utils/settings-io.js +2 -1
- package/package.json +7 -2
|
@@ -6,13 +6,19 @@ import { interpolateVariables } from "../core/variable-interpolator.js";
|
|
|
6
6
|
import { getMessage } from "../i18n/index.js";
|
|
7
7
|
import { persistCredentials, readCredentials } from "./credentials.js";
|
|
8
8
|
import { ensureGitignoreEntry } from "./gitignore.js";
|
|
9
|
+
import { MCP_STATE_GITIGNORE_ENTRY } from "../core/gitignore-entries.js";
|
|
9
10
|
import { syncGitHooks } from "./githooks-sync.js";
|
|
10
11
|
import { detectLocale } from "./locale-detect.js";
|
|
11
12
|
import { sanitizeDisplayText } from "./sanitize-text.js";
|
|
12
13
|
import { ACCEL_DIR, ensureAccelDir, readSettingsSafe } from "./settings-io.js";
|
|
13
14
|
const MCP_DIR = "mcp";
|
|
14
15
|
const MCP_STATE_FILE = "mcp-state.json";
|
|
15
|
-
const
|
|
16
|
+
const SETTINGS_STATE_KEY = "$settings";
|
|
17
|
+
const UNSAFE_KEYS = new Set([
|
|
18
|
+
"__proto__",
|
|
19
|
+
"constructor",
|
|
20
|
+
"prototype",
|
|
21
|
+
]);
|
|
16
22
|
const OUTPUT_TARGETS = new Map([
|
|
17
23
|
[".mcp.json", { format: "json", containerKey: "mcpServers" }],
|
|
18
24
|
[".vscode/mcp.json", { format: "json", containerKey: "servers" }],
|
|
@@ -36,31 +42,206 @@ const serializeDoc = (format, doc) => {
|
|
|
36
42
|
return out.endsWith("\n") ? out : out + "\n";
|
|
37
43
|
};
|
|
38
44
|
const resolveOutputFile = (projectDir, outputPath) => join(projectDir, ...outputPath.split("/"));
|
|
45
|
+
const hasCredentialPlaceholder = (value) => {
|
|
46
|
+
const text = JSON.stringify(value) ?? "";
|
|
47
|
+
return CREDENTIAL_PLACEHOLDERS.some((p) => text.includes(p));
|
|
48
|
+
};
|
|
49
|
+
const isTable = (value) => {
|
|
50
|
+
if (!isPlainObject(value))
|
|
51
|
+
return false;
|
|
52
|
+
const proto = Object.getPrototypeOf(value);
|
|
53
|
+
return proto === Object.prototype || proto === null;
|
|
54
|
+
};
|
|
55
|
+
const mergeSettings = (target, source, skipKey) => {
|
|
56
|
+
for (const [key, value] of Object.entries(source)) {
|
|
57
|
+
if (key === skipKey || UNSAFE_KEYS.has(key))
|
|
58
|
+
continue;
|
|
59
|
+
if (!isTable(value)) {
|
|
60
|
+
target[key] = value;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const current = Object.hasOwn(target, key) ? target[key] : undefined;
|
|
64
|
+
const child = isTable(current) ? current : {};
|
|
65
|
+
mergeSettings(child, value);
|
|
66
|
+
target[key] = child;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const flattenSettings = (table, prefix = []) => Object.entries(table).flatMap(([key, value]) => isTable(value)
|
|
70
|
+
? flattenSettings(value, [...prefix, key])
|
|
71
|
+
: [{ path: [...prefix, key], value }]);
|
|
72
|
+
const settingKey = (path) => JSON.stringify(path);
|
|
73
|
+
const settingLabel = (path) => path.join(".");
|
|
74
|
+
const compareSettings = (a, b) => {
|
|
75
|
+
const ka = settingKey(a.path);
|
|
76
|
+
const kb = settingKey(b.path);
|
|
77
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
78
|
+
};
|
|
79
|
+
const canonicalJson = (value) => JSON.stringify(value, (_key, v) => isTable(v)
|
|
80
|
+
? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
81
|
+
: v) ?? "";
|
|
82
|
+
const sameValue = (a, b) => canonicalJson(a) === canonicalJson(b);
|
|
83
|
+
const lookupSetting = (doc, path) => {
|
|
84
|
+
let current = doc;
|
|
85
|
+
for (let i = 0; i < path.length; i++) {
|
|
86
|
+
if (!Object.hasOwn(current, path[i]))
|
|
87
|
+
return { kind: "absent" };
|
|
88
|
+
const value = current[path[i]];
|
|
89
|
+
if (i === path.length - 1)
|
|
90
|
+
return { kind: "value", value };
|
|
91
|
+
if (!isTable(value))
|
|
92
|
+
return { kind: "blocked" };
|
|
93
|
+
current = value;
|
|
94
|
+
}
|
|
95
|
+
return { kind: "absent" };
|
|
96
|
+
};
|
|
97
|
+
const setSetting = (doc, path, value) => {
|
|
98
|
+
let current = doc;
|
|
99
|
+
for (const key of path.slice(0, -1)) {
|
|
100
|
+
const next = Object.hasOwn(current, key) ? current[key] : undefined;
|
|
101
|
+
if (isTable(next)) {
|
|
102
|
+
current = next;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const created = {};
|
|
106
|
+
current[key] = created;
|
|
107
|
+
current = created;
|
|
108
|
+
}
|
|
109
|
+
current[path[path.length - 1]] = value;
|
|
110
|
+
};
|
|
111
|
+
const deleteSetting = (doc, path) => {
|
|
112
|
+
const tables = [doc];
|
|
113
|
+
for (const key of path.slice(0, -1)) {
|
|
114
|
+
const next = tables[tables.length - 1][key];
|
|
115
|
+
if (!isTable(next))
|
|
116
|
+
return;
|
|
117
|
+
tables.push(next);
|
|
118
|
+
}
|
|
119
|
+
delete tables[tables.length - 1][path[path.length - 1]];
|
|
120
|
+
for (let i = tables.length - 1; i > 0; i--) {
|
|
121
|
+
if (Object.keys(tables[i]).length > 0)
|
|
122
|
+
break;
|
|
123
|
+
delete tables[i - 1][path[i - 1]];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const reconcileSettings = (doc, desired, deferred, recorded) => {
|
|
127
|
+
const desiredByKey = new Map(desired.map((s) => [settingKey(s.path), s]));
|
|
128
|
+
const recordedByKey = new Map(recorded.map((s) => [settingKey(s.path), s]));
|
|
129
|
+
const result = {
|
|
130
|
+
changed: false,
|
|
131
|
+
managed: [],
|
|
132
|
+
blocked: [],
|
|
133
|
+
};
|
|
134
|
+
for (const key of new Set([...recordedByKey.keys(), ...desiredByKey.keys()])) {
|
|
135
|
+
const prev = recordedByKey.get(key);
|
|
136
|
+
if (deferred.has(key)) {
|
|
137
|
+
if (prev)
|
|
138
|
+
result.managed.push(prev);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const next = desiredByKey.get(key);
|
|
142
|
+
const path = (next ?? prev)?.path;
|
|
143
|
+
if (!path)
|
|
144
|
+
continue;
|
|
145
|
+
const current = lookupSetting(doc, path);
|
|
146
|
+
if (current.kind === "blocked") {
|
|
147
|
+
if (next)
|
|
148
|
+
result.blocked.push(next);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (prev) {
|
|
152
|
+
if (current.kind === "absent") {
|
|
153
|
+
if (next)
|
|
154
|
+
result.managed.push(prev);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!sameValue(current.value, prev.value))
|
|
158
|
+
continue;
|
|
159
|
+
if (next) {
|
|
160
|
+
if (!sameValue(current.value, next.value)) {
|
|
161
|
+
setSetting(doc, path, next.value);
|
|
162
|
+
result.changed = true;
|
|
163
|
+
}
|
|
164
|
+
result.managed.push(next);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
deleteSetting(doc, path);
|
|
168
|
+
result.changed = true;
|
|
169
|
+
}
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (!next)
|
|
173
|
+
continue;
|
|
174
|
+
if (current.kind === "absent") {
|
|
175
|
+
setSetting(doc, path, next.value);
|
|
176
|
+
result.changed = true;
|
|
177
|
+
result.managed.push(next);
|
|
178
|
+
}
|
|
179
|
+
else if (sameValue(current.value, next.value)) {
|
|
180
|
+
result.managed.push(next);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
result.managed.sort(compareSettings);
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
186
|
+
const recordedSettingsFor = (state, outputPath, containerKey) => (state.settings[outputPath] ?? []).filter((s) => s.path[0] !== containerKey);
|
|
187
|
+
const isSafeSettingPath = (path) => Array.isArray(path) &&
|
|
188
|
+
path.length > 0 &&
|
|
189
|
+
path.every((k) => typeof k === "string" && !UNSAFE_KEYS.has(k));
|
|
190
|
+
const readSettingsRecords = (raw) => {
|
|
191
|
+
const settings = {};
|
|
192
|
+
for (const [outputPath, records] of Object.entries(raw)) {
|
|
193
|
+
if (outputPath === "__proto__")
|
|
194
|
+
continue;
|
|
195
|
+
if (!Array.isArray(records))
|
|
196
|
+
continue;
|
|
197
|
+
const valid = [];
|
|
198
|
+
for (const record of records) {
|
|
199
|
+
if (!isPlainObject(record))
|
|
200
|
+
continue;
|
|
201
|
+
if (!isSafeSettingPath(record.path) || !Object.hasOwn(record, "value")) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
valid.push({ path: [...record.path], value: record.value });
|
|
205
|
+
}
|
|
206
|
+
if (valid.length > 0)
|
|
207
|
+
settings[outputPath] = valid;
|
|
208
|
+
}
|
|
209
|
+
return settings;
|
|
210
|
+
};
|
|
39
211
|
export const readMcpState = async (projectDir) => {
|
|
212
|
+
const state = { servers: {}, settings: {} };
|
|
40
213
|
try {
|
|
41
214
|
const raw = await readFile(join(projectDir, ACCEL_DIR, MCP_STATE_FILE), "utf-8");
|
|
42
215
|
const parsed = JSON.parse(raw);
|
|
43
216
|
if (!isPlainObject(parsed))
|
|
44
|
-
return
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
if (outputPath === "__proto__")
|
|
217
|
+
return state;
|
|
218
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
219
|
+
if (key === "__proto__")
|
|
48
220
|
continue;
|
|
49
|
-
if (
|
|
221
|
+
if (key === SETTINGS_STATE_KEY) {
|
|
222
|
+
if (isPlainObject(value))
|
|
223
|
+
state.settings = readSettingsRecords(value);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (!Array.isArray(value))
|
|
50
227
|
continue;
|
|
51
|
-
const valid =
|
|
228
|
+
const valid = value.filter((n) => typeof n === "string");
|
|
52
229
|
if (valid.length > 0)
|
|
53
|
-
state[
|
|
230
|
+
state.servers[key] = valid;
|
|
54
231
|
}
|
|
55
232
|
return state;
|
|
56
233
|
}
|
|
57
234
|
catch {
|
|
58
|
-
return
|
|
235
|
+
return state;
|
|
59
236
|
}
|
|
60
237
|
};
|
|
61
238
|
export const writeMcpState = async (projectDir, state) => {
|
|
62
239
|
const accelDir = await ensureAccelDir(projectDir);
|
|
63
|
-
|
|
240
|
+
const out = { ...state.servers };
|
|
241
|
+
if (Object.keys(state.settings).length > 0) {
|
|
242
|
+
out[SETTINGS_STATE_KEY] = state.settings;
|
|
243
|
+
}
|
|
244
|
+
await writeFile(join(accelDir, MCP_STATE_FILE), JSON.stringify(out, null, 2) + "\n", "utf-8");
|
|
64
245
|
await ensureGitignoreEntry(projectDir, MCP_STATE_GITIGNORE_ENTRY);
|
|
65
246
|
};
|
|
66
247
|
const listFragmentTargets = async (projectDir) => {
|
|
@@ -140,9 +321,13 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
140
321
|
const prevState = await readMcpState(projectDir);
|
|
141
322
|
const fragmentTargets = await listFragmentTargets(projectDir);
|
|
142
323
|
const targetPaths = [
|
|
143
|
-
...new Set([
|
|
324
|
+
...new Set([
|
|
325
|
+
...fragmentTargets.keys(),
|
|
326
|
+
...Object.keys(prevState.servers),
|
|
327
|
+
...Object.keys(prevState.settings),
|
|
328
|
+
]),
|
|
144
329
|
].sort();
|
|
145
|
-
const nextState = {};
|
|
330
|
+
const nextState = { servers: {}, settings: {} };
|
|
146
331
|
let deferredTotal = 0;
|
|
147
332
|
for (const outputPath of targetPaths) {
|
|
148
333
|
const target = OUTPUT_TARGETS.get(outputPath);
|
|
@@ -155,6 +340,7 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
155
340
|
continue;
|
|
156
341
|
}
|
|
157
342
|
const entries = new Map();
|
|
343
|
+
const fragmentSettings = {};
|
|
158
344
|
for (const name of fragmentTargets.get(outputPath) ?? []) {
|
|
159
345
|
const fragRel = `${ACCEL_DIR}/${MCP_DIR}/${outputPath}/${name}`;
|
|
160
346
|
let raw;
|
|
@@ -178,6 +364,7 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
178
364
|
}));
|
|
179
365
|
continue;
|
|
180
366
|
}
|
|
367
|
+
mergeSettings(fragmentSettings, doc, target.containerKey);
|
|
181
368
|
const container = doc[target.containerKey];
|
|
182
369
|
if (!isPlainObject(container))
|
|
183
370
|
continue;
|
|
@@ -187,40 +374,65 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
187
374
|
}
|
|
188
375
|
const deferred = [];
|
|
189
376
|
for (const [serverName, value] of [...entries]) {
|
|
190
|
-
|
|
191
|
-
if (CREDENTIAL_PLACEHOLDERS.some((p) => text.includes(p))) {
|
|
377
|
+
if (hasCredentialPlaceholder(value)) {
|
|
192
378
|
deferred.push(serverName);
|
|
193
379
|
entries.delete(serverName);
|
|
194
380
|
}
|
|
195
381
|
}
|
|
196
|
-
|
|
197
|
-
|
|
382
|
+
const desiredSettings = [];
|
|
383
|
+
const deferredSettings = [];
|
|
384
|
+
for (const setting of flattenSettings(fragmentSettings)) {
|
|
385
|
+
(hasCredentialPlaceholder(setting.value)
|
|
386
|
+
? deferredSettings
|
|
387
|
+
: desiredSettings).push(setting);
|
|
388
|
+
}
|
|
389
|
+
deferredTotal += deferred.length + deferredSettings.length;
|
|
390
|
+
if (opts.credentialsConfirmed &&
|
|
391
|
+
deferred.length + deferredSettings.length > 0) {
|
|
392
|
+
const names = [
|
|
393
|
+
...deferred,
|
|
394
|
+
...deferredSettings.map((s) => settingLabel(s.path)),
|
|
395
|
+
];
|
|
198
396
|
warn(getMessage("mcp.warning.credentialEntryExcluded", locale, {
|
|
199
397
|
path: sanitizeDisplayText(outputPath),
|
|
200
|
-
names: sanitizeDisplayText(
|
|
398
|
+
names: sanitizeDisplayText(names.join(", ")),
|
|
201
399
|
}));
|
|
202
400
|
}
|
|
401
|
+
const recordedSettings = recordedSettingsFor(prevState, outputPath, target.containerKey);
|
|
203
402
|
const existing = await readOutputDoc(projectDir, outputPath, target.format, locale, warn);
|
|
204
403
|
if (existing === null) {
|
|
205
|
-
const prev = prevState[outputPath];
|
|
404
|
+
const prev = prevState.servers[outputPath];
|
|
206
405
|
if (prev && prev.length > 0)
|
|
207
|
-
nextState[outputPath] = prev;
|
|
406
|
+
nextState.servers[outputPath] = prev;
|
|
407
|
+
if (recordedSettings.length > 0) {
|
|
408
|
+
nextState.settings[outputPath] = recordedSettings;
|
|
409
|
+
}
|
|
208
410
|
continue;
|
|
209
411
|
}
|
|
210
412
|
const { raw: existingRaw, doc } = existing;
|
|
211
413
|
const deferredSet = new Set(deferred);
|
|
212
414
|
const removeNames = [
|
|
213
|
-
...new Set([...(prevState[outputPath] ?? []), ...entries.keys()]),
|
|
415
|
+
...new Set([...(prevState.servers[outputPath] ?? []), ...entries.keys()]),
|
|
214
416
|
].filter((n) => !deferredSet.has(n));
|
|
215
417
|
const existingContainer = doc[target.containerKey];
|
|
216
418
|
const container = isPlainObject(existingContainer) ? existingContainer : {};
|
|
217
419
|
const removedCount = removeNames.filter((n) => Object.hasOwn(container, n)).length;
|
|
218
|
-
|
|
420
|
+
const serversChanged = entries.size > 0 || removedCount > 0;
|
|
421
|
+
if (serversChanged) {
|
|
219
422
|
for (const n of removeNames)
|
|
220
423
|
delete container[n];
|
|
221
424
|
for (const [n, v] of entries)
|
|
222
425
|
container[n] = v;
|
|
223
426
|
doc[target.containerKey] = container;
|
|
427
|
+
}
|
|
428
|
+
const settingsResult = reconcileSettings(doc, desiredSettings, new Set(deferredSettings.map((s) => settingKey(s.path))), recordedSettings);
|
|
429
|
+
if (settingsResult.blocked.length > 0) {
|
|
430
|
+
warn(getMessage("mcp.warning.settingBlocked", locale, {
|
|
431
|
+
path: sanitizeDisplayText(outputPath),
|
|
432
|
+
names: sanitizeDisplayText(settingsResult.blocked.map((s) => settingLabel(s.path)).join(", ")),
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
if (serversChanged || settingsResult.changed) {
|
|
224
436
|
const out = serializeDoc(target.format, doc);
|
|
225
437
|
if (out !== existingRaw) {
|
|
226
438
|
const outFile = resolveOutputFile(projectDir, outputPath);
|
|
@@ -233,13 +445,18 @@ export const generateMcpConfigs = async (projectDir, opts = {}) => {
|
|
|
233
445
|
}
|
|
234
446
|
const managed = [...new Set([...entries.keys(), ...deferred])].sort();
|
|
235
447
|
if (managed.length > 0)
|
|
236
|
-
nextState[outputPath] = managed;
|
|
448
|
+
nextState.servers[outputPath] = managed;
|
|
449
|
+
if (settingsResult.managed.length > 0) {
|
|
450
|
+
nextState.settings[outputPath] = settingsResult.managed;
|
|
451
|
+
}
|
|
237
452
|
}
|
|
238
453
|
if (deferredTotal > 0 && !opts.credentialsConfirmed) {
|
|
239
454
|
info(getMessage("mcp.hint.loginRequired", locale));
|
|
240
455
|
}
|
|
456
|
+
const hasRecords = Object.keys(nextState.servers).length > 0 ||
|
|
457
|
+
Object.keys(nextState.settings).length > 0;
|
|
241
458
|
const statePath = join(projectDir, ACCEL_DIR, MCP_STATE_FILE);
|
|
242
|
-
if (
|
|
459
|
+
if (hasRecords || (await fileExists(statePath))) {
|
|
243
460
|
await writeMcpState(projectDir, nextState);
|
|
244
461
|
}
|
|
245
462
|
};
|
|
@@ -248,7 +465,10 @@ export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
|
|
|
248
465
|
const warn = opts.warn ?? noop;
|
|
249
466
|
const { locale } = await resolveProjectLocale(projectDir);
|
|
250
467
|
const state = await readMcpState(projectDir);
|
|
251
|
-
|
|
468
|
+
const outputPaths = [
|
|
469
|
+
...new Set([...Object.keys(state.servers), ...Object.keys(state.settings)]),
|
|
470
|
+
].sort();
|
|
471
|
+
for (const outputPath of outputPaths) {
|
|
252
472
|
const target = OUTPUT_TARGETS.get(outputPath);
|
|
253
473
|
if (!target)
|
|
254
474
|
continue;
|
|
@@ -256,18 +476,28 @@ export const removeManagedMcpEntries = async (projectDir, opts = {}) => {
|
|
|
256
476
|
if (existing === null || existing.raw === null)
|
|
257
477
|
continue;
|
|
258
478
|
const { doc } = existing;
|
|
479
|
+
let removedCount = 0;
|
|
259
480
|
const container = doc[target.containerKey];
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
481
|
+
if (isPlainObject(container)) {
|
|
482
|
+
const removed = (state.servers[outputPath] ?? []).filter((n) => Object.hasOwn(container, n));
|
|
483
|
+
for (const n of removed)
|
|
484
|
+
delete container[n];
|
|
485
|
+
removedCount += removed.length;
|
|
486
|
+
}
|
|
487
|
+
for (const setting of recordedSettingsFor(state, outputPath, target.containerKey)) {
|
|
488
|
+
const current = lookupSetting(doc, setting.path);
|
|
489
|
+
if (current.kind !== "value" || !sameValue(current.value, setting.value)) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
deleteSetting(doc, setting.path);
|
|
493
|
+
removedCount++;
|
|
494
|
+
}
|
|
495
|
+
if (removedCount === 0)
|
|
264
496
|
continue;
|
|
265
|
-
for (const n of removed)
|
|
266
|
-
delete container[n];
|
|
267
497
|
await writeFile(resolveOutputFile(projectDir, outputPath), serializeDoc(target.format, doc), "utf-8");
|
|
268
498
|
info(getMessage("mcp.detach.removed", locale, {
|
|
269
499
|
path: sanitizeDisplayText(outputPath),
|
|
270
|
-
count: String(
|
|
500
|
+
count: String(removedCount),
|
|
271
501
|
}));
|
|
272
502
|
}
|
|
273
503
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const ENSURE_STRICT_ENV = "ACCEL_ENSURE_STRICT";
|
|
2
|
+
export declare const CLAUDE_SETTINGS_REL = ".claude/settings.json";
|
|
3
|
+
export declare const CODEX_HOOKS_REL = ".codex/hooks.json";
|
|
4
|
+
export declare const COPILOT_HOOK_FILE_REL = ".github/hooks/accel-dependencies.json";
|
|
5
|
+
type LogSink = {
|
|
6
|
+
info: (msg: string) => void;
|
|
7
|
+
warn: (msg: string) => void;
|
|
8
|
+
};
|
|
9
|
+
type SinkOpts = {
|
|
10
|
+
info?: (msg: string) => void;
|
|
11
|
+
warn?: (msg: string) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const isAllowedDependencyDir: (p: string) => boolean;
|
|
14
|
+
export declare const computeDependencyId: (packageJsonText: string, lockText: string) => string;
|
|
15
|
+
export declare const computeDependencyIds: (projectDir: string, dirs: readonly string[], packageManager: string) => Promise<Set<string>>;
|
|
16
|
+
export declare const placeEnsureScript: (projectDir: string, opts: {
|
|
17
|
+
locale: string;
|
|
18
|
+
warn?: (msg: string) => void;
|
|
19
|
+
}) => Promise<boolean>;
|
|
20
|
+
export declare const resolveEnsureRuntime: () => string;
|
|
21
|
+
export type RunEnsureResult = {
|
|
22
|
+
ran: boolean;
|
|
23
|
+
exitCode: number | null;
|
|
24
|
+
stdout: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const runEnsure: (projectDir: string, opts?: SinkOpts & {
|
|
27
|
+
runtime?: string;
|
|
28
|
+
}) => Promise<RunEnsureResult>;
|
|
29
|
+
export declare const mergeManagedSessionStart: (doc: Record<string, unknown>, shouldHave: boolean, command: string) => {
|
|
30
|
+
doc: Record<string, unknown>;
|
|
31
|
+
changed: boolean;
|
|
32
|
+
unsupported: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare const copilotHookFileContent: (command: string) => string;
|
|
35
|
+
export declare const syncDependencyHooks: (projectDir: string, opts: SinkOpts & {
|
|
36
|
+
locale: string;
|
|
37
|
+
packageManager: string;
|
|
38
|
+
}, agents: readonly string[], hasDeps: boolean) => Promise<void>;
|
|
39
|
+
export type SyncDependencyArtifactsResult = {
|
|
40
|
+
hasDeps: boolean;
|
|
41
|
+
ensureReady: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare const syncDependencyArtifacts: (projectDir: string, opts?: SinkOpts) => Promise<SyncDependencyArtifactsResult>;
|
|
44
|
+
export declare const removeDependencyArtifacts: (projectDir: string, opts?: SinkOpts) => Promise<void>;
|
|
45
|
+
export declare const pruneRuntimeIds: (projectDir: string, ids: Iterable<string>) => Promise<void>;
|
|
46
|
+
export declare const syncDependencyArtifactsBestEffort: (projectDir: string, logger: LogSink, impl?: typeof syncDependencyArtifacts) => Promise<SyncDependencyArtifactsResult>;
|
|
47
|
+
export declare const runEnsureBestEffort: (projectDir: string, logger: LogSink, impl?: typeof runEnsure) => Promise<void>;
|
|
48
|
+
export declare const removeDependencyArtifactsBestEffort: (projectDir: string, logger: LogSink, impl?: typeof removeDependencyArtifacts) => Promise<void>;
|
|
49
|
+
export declare const pruneRuntimeIdsBestEffort: (projectDir: string, ids: Iterable<string>, impl?: typeof pruneRuntimeIds) => Promise<void>;
|
|
50
|
+
export declare const syncDependencyArtifactsAndEnsureBestEffort: (projectDir: string, logger: LogSink, opts: {
|
|
51
|
+
skipInstall: boolean;
|
|
52
|
+
syncImpl?: typeof syncDependencyArtifacts;
|
|
53
|
+
runImpl?: typeof runEnsure;
|
|
54
|
+
}) => Promise<SyncDependencyArtifactsResult>;
|
|
55
|
+
export {};
|