@bridge_gpt/mcp-server 0.2.73 → 0.2.74
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 +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +12 -0
- package/build/agents.generated.js +3 -3
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +3 -0
- package/build/command-provisioning.js +4 -3
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +26 -1
- package/build/conductor/command-drift.js +1 -1
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +2 -0
- package/build/conductor/driver-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -0
- package/build/conductor/epic-branch-ci-inspection.js +61 -16
- package/build/conductor/epic-implementer-cli.js +33 -0
- package/build/conductor/epic-server-sfcc-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +58 -80
- package/build/conductor/epic-server.js +57 -4
- package/build/conductor/gate-discovery.js +46 -6
- package/build/conductor/gate-settings-review.js +51 -14
- package/build/credential-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +50 -0
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +47 -1
- package/build/docs.generated.js +8 -1
- package/build/doctor.js +41 -0
- package/build/drive-epic.js +297 -37
- package/build/epic-branch-ci-summary.js +18 -1
- package/build/epic-capability-statement.js +71 -3
- package/build/epic-ci-workflow-drift.js +52 -13
- package/build/epic-ci-workflow-install.js +31 -6
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +128 -7
- package/build/epic-implementer-bin.js +161 -70
- package/build/epic-launch-context.js +102 -7
- package/build/epic-server-record.js +30 -15
- package/build/executor/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +39 -1
- package/build/executor/epic-server-context.js +23 -7
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/job-runner.js +159 -17
- package/build/executor/permissions.js +85 -3
- package/build/executor/prompt-spec.js +37 -3
- package/build/executor-launch.js +4 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +398 -269
- package/build/install-bridge-conductor-answers.js +84 -21
- package/build/install-bridge-conductor-apply.js +30 -1
- package/build/install-bridge-conductor-assessment.js +375 -48
- package/build/install-bridge-conductor-compact.js +27 -2
- package/build/install-bridge-conductor-contracts.js +10 -1
- package/build/install-bridge-conductor-gate.js +124 -11
- package/build/install-bridge-conductor-setup.js +46 -8
- package/build/install-bridge-conductor.js +625 -113
- package/build/install-bridge.js +88 -11
- package/build/install-doctor.js +38 -8
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/mcp-grant-candidates.js +108 -96
- package/build/mcp-invoke.js +168 -4
- package/build/mcp-provisioning.js +21 -4
- package/build/mcp-server-invocation.js +13 -0
- package/build/merge-workflow-install.js +9 -1
- package/build/pipelines.generated.js +2 -1
- package/build/plane/status.js +8 -2
- package/build/printed-remedy-commands.js +5 -0
- package/build/project-root.js +40 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +5 -2
- package/build/repository-toolchains.js +6 -3
- package/build/setup-epic.js +116 -15
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +35 -4
- package/build/version.generated.js +3 -3
- package/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- package/package.json +1 -1
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* credential-scan — the names-only scan behind `credentials references scan --json`
|
|
3
|
+
* (BAPI-1648).
|
|
4
|
+
*
|
|
5
|
+
* `/install-bridge` uses the scan to propose worker credential REFERENCES for the
|
|
6
|
+
* owner to approve. The scan reports names, locations, key mappings, and launch
|
|
7
|
+
* fingerprints. It never returns, hashes, or sizes a credential value.
|
|
8
|
+
*
|
|
9
|
+
* ONE ratified exception to "discovery never opens a candidate": an ignored or
|
|
10
|
+
* untracked ROOT `dw.json` whose convention row declares a `hostProbe` is opened
|
|
11
|
+
* once, so the owner can be offered a sandbox proposal. The probe returns only a
|
|
12
|
+
* closed host class (`sfcc_sandbox`, `not_sandbox`, `unknown`) and the names of
|
|
13
|
+
* the mapped selectors that are present. It never returns the hostname, a value,
|
|
14
|
+
* a size, or a failure reason, and it adds no diagnostic.
|
|
15
|
+
*
|
|
16
|
+
* TWO PHASES, with different read guarantees:
|
|
17
|
+
*
|
|
18
|
+
* 1. DISCOVERY inventories permitted names only. It lists files with
|
|
19
|
+
* list-based `git ls-files` calls and never opens an ignored or untracked
|
|
20
|
+
* credential candidate (`dw.json`, `.env`, `.env.*`, `*.pem`,
|
|
21
|
+
* `service-account*.json`, `credentials.json`, `.npmrc`) — except the single
|
|
22
|
+
* root `dw.json` probe above: those are reported by file name or relative
|
|
23
|
+
* location. It reads only Git-eligible tracked
|
|
24
|
+
* templates (such as `.env.example`), committed project MCP configs, the
|
|
25
|
+
* owner's host MCP configs, and `.bridge/config`, and it projects every one
|
|
26
|
+
* to key names before returning.
|
|
27
|
+
* 2. STATUS (`readCredentialReferenceRecord` + `statusOnly`, from the shared
|
|
28
|
+
* reference module) may resolve sources the owner ALREADY approved. That is
|
|
29
|
+
* the only place a previously approved source is opened, and it still
|
|
30
|
+
* returns names and states only.
|
|
31
|
+
*
|
|
32
|
+
* Every failure to read a source becomes a closed diagnostic category. A source
|
|
33
|
+
* that could not be read is never reported as a confirmed empty result, and raw
|
|
34
|
+
* configuration text, subprocess output, and exception text never appear.
|
|
35
|
+
*/
|
|
36
|
+
import path from "path";
|
|
37
|
+
import { CREDENTIAL_REFERENCES_MAX_SOURCE_BYTES, computeLaunchFingerprint } from "./credential-references.js";
|
|
38
|
+
import { canonicalizeSfccHostname, isApprovedSfccSandboxHost } from "./sfcc/hostname.js";
|
|
39
|
+
import { readBridgeConfig } from "./bridge-config.js";
|
|
40
|
+
import { resolveClaudeUserConfigPath } from "./claude-user-config-doctor.js";
|
|
41
|
+
import { launcherTargetFor } from "./launcher-config-inspection.js";
|
|
42
|
+
import { classifyMcpGrantEntry, normalizeBridgeConfigManifest, normalizeServersDocument, withPackageEvidence, } from "./mcp-grant-candidates.js";
|
|
43
|
+
import { resolveCursorUserConfigPath } from "./mcp-host-targets.js";
|
|
44
|
+
import { CREDENTIAL_CONVENTIONS, TEMPLATE_SUFFIXES, findConvention, } from "./credential-scan-conventions.js";
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Result types
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
export const CREDENTIAL_SCAN_VERSION = 1;
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Helpers
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
const MAX_TEMPLATE_BYTES = 64 * 1024;
|
|
53
|
+
const MAX_SELECTORS = 64;
|
|
54
|
+
const MAX_ENTRIES_PER_SOURCE = 256;
|
|
55
|
+
const CANDIDATE_NAME_RE = /^(dw\.json|\.env|\.env\..+|[^/]+\.pem|service-account[^/]*\.json|credentials\.json|\.npmrc)$/;
|
|
56
|
+
const PROJECT_CONFIGS = [
|
|
57
|
+
{ relPath: ".mcp.json", origin: "project-claude" },
|
|
58
|
+
{ relPath: ".cursor/mcp.json", origin: "project-cursor" },
|
|
59
|
+
];
|
|
60
|
+
function baseName(relPath) {
|
|
61
|
+
const i = relPath.lastIndexOf("/");
|
|
62
|
+
return i === -1 ? relPath : relPath.slice(i + 1);
|
|
63
|
+
}
|
|
64
|
+
function stripTemplateSuffix(name) {
|
|
65
|
+
for (const suffix of TEMPLATE_SUFFIXES) {
|
|
66
|
+
if (name.endsWith(suffix) && name.length > suffix.length)
|
|
67
|
+
return name.slice(0, -suffix.length);
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
function compare(a, b) {
|
|
72
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
73
|
+
}
|
|
74
|
+
function errorCode(err) {
|
|
75
|
+
return err && typeof err === "object" ? err.code : undefined;
|
|
76
|
+
}
|
|
77
|
+
const UNKNOWN_PROBE = { host_class: "unknown", present_selectors: [] };
|
|
78
|
+
/**
|
|
79
|
+
* Open one eligible root candidate and return only the closed probe result.
|
|
80
|
+
*
|
|
81
|
+
* Limits: the pre-read size check and the post-read byte check are NOT a strict
|
|
82
|
+
* read bound, and nothing protects against the file being replaced between the
|
|
83
|
+
* `lstat` and the read. Every failure collapses to `unknown` with no logging,
|
|
84
|
+
* diagnostic, or retained data.
|
|
85
|
+
*/
|
|
86
|
+
async function probeRootFile(filePath, row, deps) {
|
|
87
|
+
try {
|
|
88
|
+
const stat = await deps.lstat(filePath);
|
|
89
|
+
if (!stat.isFile())
|
|
90
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
91
|
+
if (stat.size > CREDENTIAL_REFERENCES_MAX_SOURCE_BYTES)
|
|
92
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
93
|
+
const text = await deps.readFile(filePath);
|
|
94
|
+
if (Buffer.byteLength(text, "utf8") > CREDENTIAL_REFERENCES_MAX_SOURCE_BYTES) {
|
|
95
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
96
|
+
}
|
|
97
|
+
const parsed = JSON.parse(text);
|
|
98
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
99
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
100
|
+
}
|
|
101
|
+
const doc = parsed;
|
|
102
|
+
if (Array.isArray(doc["configs"]))
|
|
103
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
104
|
+
const hostSelector = row.hostProbe?.selector;
|
|
105
|
+
if (hostSelector === undefined)
|
|
106
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
107
|
+
const rawHost = Object.prototype.hasOwnProperty.call(doc, hostSelector.slice(1)) ? doc[hostSelector.slice(1)] : undefined;
|
|
108
|
+
if (typeof rawHost !== "string")
|
|
109
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
110
|
+
const canonical = canonicalizeSfccHostname(rawHost);
|
|
111
|
+
if (canonical === null)
|
|
112
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
113
|
+
const present = [];
|
|
114
|
+
for (const mapping of row.mappings) {
|
|
115
|
+
const key = mapping.selector.slice(1);
|
|
116
|
+
if (!present.includes(mapping.selector) &&
|
|
117
|
+
Object.prototype.hasOwnProperty.call(doc, key) &&
|
|
118
|
+
typeof doc[key] === "string") {
|
|
119
|
+
present.push(mapping.selector);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
host_class: isApprovedSfccSandboxHost(canonical) ? "sfcc_sandbox" : "not_sandbox",
|
|
124
|
+
present_selectors: present,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return { ...UNKNOWN_PROBE, present_selectors: [] };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Turn a convention row into a candidate hint. Without a probe the output is the
|
|
133
|
+
* plain row. With a probe, mappings are filtered to the present selectors for a
|
|
134
|
+
* classified host (`unknown` keeps the whole mapping), and only a positively
|
|
135
|
+
* classified sandbox host raises the level and proposes a whole-file destination.
|
|
136
|
+
* A hint is a proposal, never approval.
|
|
137
|
+
*/
|
|
138
|
+
function hintFor(row, probe) {
|
|
139
|
+
const hint = {
|
|
140
|
+
id: row.id,
|
|
141
|
+
format: row.format,
|
|
142
|
+
mappings: row.mappings.map((m) => ({ ...m })),
|
|
143
|
+
default_level: row.defaultLevel,
|
|
144
|
+
consumer_choice_required: row.suggestedConsumers.length === 0,
|
|
145
|
+
};
|
|
146
|
+
if (probe === undefined)
|
|
147
|
+
return hint;
|
|
148
|
+
hint.host_probe = { host_class: probe.host_class, present_selectors: [...probe.present_selectors] };
|
|
149
|
+
if (probe.host_class !== "unknown") {
|
|
150
|
+
const present = new Set(probe.present_selectors);
|
|
151
|
+
hint.mappings = hint.mappings.filter((m) => present.has(m.selector));
|
|
152
|
+
}
|
|
153
|
+
if (probe.host_class === "sfcc_sandbox") {
|
|
154
|
+
hint.default_level = "sandbox";
|
|
155
|
+
if (row.sandboxWholeFileDest !== undefined)
|
|
156
|
+
hint.whole_file_dest = row.sandboxWholeFileDest;
|
|
157
|
+
}
|
|
158
|
+
return hint;
|
|
159
|
+
}
|
|
160
|
+
async function gitList(deps, args) {
|
|
161
|
+
try {
|
|
162
|
+
const result = await deps.runGit("git", args, { cwd: deps.checkout });
|
|
163
|
+
if (result.exitCode !== 0)
|
|
164
|
+
return { ok: false };
|
|
165
|
+
return { ok: true, paths: result.stdout.split("\0").filter((p) => p.length > 0) };
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return { ok: false };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** `git check-ignore -q`: exit 0 ignored, exit 1 not ignored, anything else is a failure. */
|
|
172
|
+
async function checkIgnored(deps, relPath) {
|
|
173
|
+
try {
|
|
174
|
+
const result = await deps.runGit("git", ["check-ignore", "-q", "--", relPath], { cwd: deps.checkout });
|
|
175
|
+
if (result.exitCode === 0)
|
|
176
|
+
return true;
|
|
177
|
+
if (result.exitCode === 1)
|
|
178
|
+
return false;
|
|
179
|
+
return "failed";
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return "failed";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function parseDotenvNames(text) {
|
|
186
|
+
const names = new Set();
|
|
187
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
188
|
+
const line = rawLine.trim();
|
|
189
|
+
if (line.length === 0 || line.startsWith("#"))
|
|
190
|
+
continue;
|
|
191
|
+
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]{0,127})\s*=/.exec(line);
|
|
192
|
+
if (match === null)
|
|
193
|
+
return null;
|
|
194
|
+
names.add(match[1]);
|
|
195
|
+
}
|
|
196
|
+
return [...names].sort(compare).slice(0, MAX_SELECTORS);
|
|
197
|
+
}
|
|
198
|
+
function escapePointer(segment) {
|
|
199
|
+
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
200
|
+
}
|
|
201
|
+
function collectPointers(value, prefix, depth, out) {
|
|
202
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
203
|
+
return;
|
|
204
|
+
for (const [key, child] of Object.entries(value)) {
|
|
205
|
+
const pointer = `${prefix}/${escapePointer(key)}`;
|
|
206
|
+
if (child !== null && typeof child === "object" && !Array.isArray(child)) {
|
|
207
|
+
if (depth < 2)
|
|
208
|
+
collectPointers(child, pointer, depth + 1, out);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
out.push(pointer);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function parseJsonSelectors(text) {
|
|
216
|
+
let parsed;
|
|
217
|
+
try {
|
|
218
|
+
parsed = JSON.parse(text);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
224
|
+
return null;
|
|
225
|
+
const out = [];
|
|
226
|
+
collectPointers(parsed, "", 0, out);
|
|
227
|
+
return out.sort(compare).slice(0, MAX_SELECTORS);
|
|
228
|
+
}
|
|
229
|
+
async function discoverFiles(deps, diagnostics) {
|
|
230
|
+
const conventions = deps.conventions ?? CREDENTIAL_CONVENTIONS;
|
|
231
|
+
const result = { filenames: [], templates: [], trackedOpenable: new Set() };
|
|
232
|
+
const tracked = await gitList(deps, ["ls-files", "-z"]);
|
|
233
|
+
const untracked = await gitList(deps, ["ls-files", "-z", "--others", "--exclude-standard"]);
|
|
234
|
+
const ignored = await gitList(deps, ["ls-files", "-z", "--others", "--ignored", "--exclude-standard"]);
|
|
235
|
+
if (!tracked.ok || !untracked.ok || !ignored.ok)
|
|
236
|
+
diagnostics.push({ category: "git_incomplete", source: "git" });
|
|
237
|
+
const located = new Map();
|
|
238
|
+
for (const [list, location] of [
|
|
239
|
+
[ignored, "ignored"],
|
|
240
|
+
[untracked, "untracked"],
|
|
241
|
+
[tracked, "tracked"],
|
|
242
|
+
]) {
|
|
243
|
+
if (!list.ok)
|
|
244
|
+
continue;
|
|
245
|
+
for (const p of list.paths)
|
|
246
|
+
located.set(p, location);
|
|
247
|
+
}
|
|
248
|
+
const paths = [...located.keys()].sort(compare);
|
|
249
|
+
for (const relPath of paths) {
|
|
250
|
+
const location = located.get(relPath);
|
|
251
|
+
const name = baseName(relPath);
|
|
252
|
+
const stripped = stripTemplateSuffix(name);
|
|
253
|
+
const isTemplate = location === "tracked" && stripped !== null && CANDIDATE_NAME_RE.test(stripped);
|
|
254
|
+
if (!isTemplate && CANDIDATE_NAME_RE.test(name)) {
|
|
255
|
+
const row = findConvention(name, conventions);
|
|
256
|
+
// The single ratified probe: only the root `dw.json`, only when ignored or
|
|
257
|
+
// untracked, only when its convention row declares a probe.
|
|
258
|
+
const probe = row?.hostProbe !== undefined && relPath === "dw.json" && (location === "ignored" || location === "untracked")
|
|
259
|
+
? await probeRootFile(path.join(deps.checkout, relPath), row, deps)
|
|
260
|
+
: undefined;
|
|
261
|
+
result.filenames.push({
|
|
262
|
+
path: relPath,
|
|
263
|
+
location,
|
|
264
|
+
...(row !== undefined ? { convention: hintFor(row, probe) } : {}),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// Project MCP configs and templates are opened only when tracked AND not ignored.
|
|
269
|
+
const openable = async (relPath) => {
|
|
270
|
+
if (located.get(relPath) !== "tracked")
|
|
271
|
+
return false;
|
|
272
|
+
const ignoredState = await checkIgnored(deps, relPath);
|
|
273
|
+
if (ignoredState === "failed") {
|
|
274
|
+
diagnostics.push({ category: "git_incomplete", source: "git" });
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
return !ignoredState;
|
|
278
|
+
};
|
|
279
|
+
for (const { relPath } of PROJECT_CONFIGS) {
|
|
280
|
+
if (await openable(relPath))
|
|
281
|
+
result.trackedOpenable.add(relPath);
|
|
282
|
+
}
|
|
283
|
+
for (const relPath of paths) {
|
|
284
|
+
const name = baseName(relPath);
|
|
285
|
+
const stripped = stripTemplateSuffix(name);
|
|
286
|
+
if (located.get(relPath) !== "tracked" || stripped === null || !CANDIDATE_NAME_RE.test(stripped))
|
|
287
|
+
continue;
|
|
288
|
+
const format = stripped.endsWith(".json") ? "json" : stripped.startsWith(".env") ? "dotenv" : null;
|
|
289
|
+
if (format === null) {
|
|
290
|
+
// A template whose format has no parser here is reported by name only.
|
|
291
|
+
result.filenames.push({ path: relPath, location: "tracked" });
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (!(await openable(relPath)))
|
|
295
|
+
continue;
|
|
296
|
+
let text;
|
|
297
|
+
try {
|
|
298
|
+
text = await deps.readFile(path.join(deps.checkout, ...relPath.split("/")));
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
diagnostics.push({ category: "source_unreadable", source: "template", path: relPath });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (text.length > MAX_TEMPLATE_BYTES) {
|
|
305
|
+
diagnostics.push({ category: "parse_failed", source: "template", path: relPath });
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const names = format === "json" ? parseJsonSelectors(text) : parseDotenvNames(text);
|
|
309
|
+
if (names === null) {
|
|
310
|
+
diagnostics.push({ category: "parse_failed", source: "template", path: relPath });
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const row = findConvention(stripped, conventions);
|
|
314
|
+
result.templates.push({ path: relPath, format, names, ...(row !== undefined ? { convention: hintFor(row) } : {}) });
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
// ---------------------------------------------------------------------------
|
|
319
|
+
// Discovery: MCP servers
|
|
320
|
+
// ---------------------------------------------------------------------------
|
|
321
|
+
async function projectServers(deps, entries, originPath) {
|
|
322
|
+
const out = [];
|
|
323
|
+
const classified = await withPackageEvidence(entries, deps.readFile);
|
|
324
|
+
for (const entry of classified) {
|
|
325
|
+
const result = classifyMcpGrantEntry(entry, {
|
|
326
|
+
repoName: deps.repoName,
|
|
327
|
+
isKnownBridgeUrl: deps.isKnownBridgeUrl,
|
|
328
|
+
allowReservedName: false,
|
|
329
|
+
});
|
|
330
|
+
if (result.state !== "offered")
|
|
331
|
+
continue;
|
|
332
|
+
out.push({
|
|
333
|
+
server: entry.name,
|
|
334
|
+
origin: entry.origin,
|
|
335
|
+
origin_path: originPath(entry),
|
|
336
|
+
env_keys: [...entry.envKeys].sort(compare),
|
|
337
|
+
launch_fingerprint: computeLaunchFingerprint(entry.command, entry.args),
|
|
338
|
+
...(entry.declaredBundle !== undefined ? { declared_bundle: entry.declaredBundle } : {}),
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
function sortServers(rows) {
|
|
344
|
+
const seen = new Set();
|
|
345
|
+
const unique = [];
|
|
346
|
+
for (const row of rows) {
|
|
347
|
+
const key = JSON.stringify([row.server, row.origin, row.origin_path, row.env_keys, row.launch_fingerprint, row.declared_bundle ?? null]);
|
|
348
|
+
if (seen.has(key))
|
|
349
|
+
continue;
|
|
350
|
+
seen.add(key);
|
|
351
|
+
unique.push(row);
|
|
352
|
+
}
|
|
353
|
+
return unique
|
|
354
|
+
.sort((a, b) => compare(a.server, b.server) ||
|
|
355
|
+
compare(a.origin, b.origin) ||
|
|
356
|
+
compare(a.origin_path, b.origin_path) ||
|
|
357
|
+
compare(a.launch_fingerprint, b.launch_fingerprint))
|
|
358
|
+
.slice(0, MAX_ENTRIES_PER_SOURCE);
|
|
359
|
+
}
|
|
360
|
+
async function discoverProjectMcp(deps, openable, diagnostics) {
|
|
361
|
+
const rows = [];
|
|
362
|
+
for (const { relPath, origin } of PROJECT_CONFIGS) {
|
|
363
|
+
if (!openable.has(relPath))
|
|
364
|
+
continue;
|
|
365
|
+
let doc;
|
|
366
|
+
try {
|
|
367
|
+
doc = JSON.parse(await deps.readFile(path.join(deps.checkout, ...relPath.split("/"))));
|
|
368
|
+
}
|
|
369
|
+
catch (err) {
|
|
370
|
+
diagnostics.push({
|
|
371
|
+
category: err instanceof SyntaxError ? "parse_failed" : "source_unreadable",
|
|
372
|
+
source: "project_mcp",
|
|
373
|
+
path: relPath,
|
|
374
|
+
});
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const rootKey = launcherTargetFor(relPath)?.topLevelKey ?? "mcpServers";
|
|
378
|
+
rows.push(...(await projectServers(deps, normalizeServersDocument(doc, origin, rootKey), () => relPath)));
|
|
379
|
+
}
|
|
380
|
+
return sortServers(rows);
|
|
381
|
+
}
|
|
382
|
+
async function discoverHostMcp(deps, diagnostics) {
|
|
383
|
+
const home = deps.homedir();
|
|
384
|
+
const hosts = [
|
|
385
|
+
{ origin: "claude", file: resolveClaudeUserConfigPath(home, deps.platform), label: "claude user config" },
|
|
386
|
+
{ origin: "cursor", file: resolveCursorUserConfigPath(home), label: "cursor user config" },
|
|
387
|
+
];
|
|
388
|
+
const rows = [];
|
|
389
|
+
for (const host of hosts) {
|
|
390
|
+
let doc;
|
|
391
|
+
try {
|
|
392
|
+
doc = JSON.parse(await deps.readFile(host.file));
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
if (errorCode(err) === "ENOENT")
|
|
396
|
+
continue;
|
|
397
|
+
diagnostics.push({
|
|
398
|
+
category: err instanceof SyntaxError ? "parse_failed" : "source_unreadable",
|
|
399
|
+
source: "host_mcp",
|
|
400
|
+
});
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
rows.push(...(await projectServers(deps, normalizeServersDocument(doc, host.origin, "mcpServers"), () => host.label)));
|
|
404
|
+
}
|
|
405
|
+
return sortServers(rows);
|
|
406
|
+
}
|
|
407
|
+
async function discoverBridgeRegistry(deps, diagnostics) {
|
|
408
|
+
const read = await readBridgeConfig(deps.checkout, { readFile: deps.readFile });
|
|
409
|
+
if (!read.ok) {
|
|
410
|
+
if (read.kind === "parse-error")
|
|
411
|
+
diagnostics.push({ category: "parse_failed", source: "bridge_config" });
|
|
412
|
+
else if (read.kind === "validation-error")
|
|
413
|
+
diagnostics.push({ category: "invalid_configuration", source: "bridge_config" });
|
|
414
|
+
return [];
|
|
415
|
+
}
|
|
416
|
+
return sortServers(await projectServers(deps, normalizeBridgeConfigManifest(read.manifest), () => ".bridge/config"));
|
|
417
|
+
}
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
// Status phase
|
|
420
|
+
// ---------------------------------------------------------------------------
|
|
421
|
+
const UNUSABLE_STATUS = {
|
|
422
|
+
state: "record_unusable",
|
|
423
|
+
record_digest: null,
|
|
424
|
+
record_path: null,
|
|
425
|
+
reason: "record_unreadable",
|
|
426
|
+
statuses: [],
|
|
427
|
+
};
|
|
428
|
+
async function readExistingReferences(deps, diagnostics) {
|
|
429
|
+
let read;
|
|
430
|
+
let status;
|
|
431
|
+
try {
|
|
432
|
+
read = await deps.readRecord(deps.repoName);
|
|
433
|
+
status = await deps.statusOnly(deps.repoName);
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
diagnostics.push({ category: "record_unusable", source: "reference_record" });
|
|
437
|
+
return { status: { ...UNUSABLE_STATUS }, entries: [], digest: null, replaceable: false, consistent: true };
|
|
438
|
+
}
|
|
439
|
+
const sameState = read.state === status.state;
|
|
440
|
+
const readDigest = read.state === "record_unusable" ? read.digest : read.digest;
|
|
441
|
+
const sameDigest = readDigest === status.record_digest;
|
|
442
|
+
if (!sameState || !sameDigest) {
|
|
443
|
+
diagnostics.push({ category: "record_inconsistent", source: "reference_record" });
|
|
444
|
+
return { status, entries: [], digest: null, replaceable: false, consistent: false };
|
|
445
|
+
}
|
|
446
|
+
if (read.state === "record_unusable") {
|
|
447
|
+
diagnostics.push({ category: "record_unusable", source: "reference_record" });
|
|
448
|
+
return { status, entries: [], digest: null, replaceable: false, consistent: true };
|
|
449
|
+
}
|
|
450
|
+
if (read.state === "absent") {
|
|
451
|
+
return { status, entries: [], digest: "absent", replaceable: true, consistent: true };
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
status,
|
|
455
|
+
entries: read.record.credentials.map((e) => structuredClone(e)),
|
|
456
|
+
digest: read.digest,
|
|
457
|
+
replaceable: true,
|
|
458
|
+
consistent: true,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
// ---------------------------------------------------------------------------
|
|
462
|
+
// Entry point
|
|
463
|
+
// ---------------------------------------------------------------------------
|
|
464
|
+
function uniqueDiagnostics(list) {
|
|
465
|
+
const seen = new Set();
|
|
466
|
+
const out = [];
|
|
467
|
+
for (const d of list) {
|
|
468
|
+
const key = `${d.category}|${d.source}|${d.path ?? ""}`;
|
|
469
|
+
if (seen.has(key))
|
|
470
|
+
continue;
|
|
471
|
+
seen.add(key);
|
|
472
|
+
out.push(d);
|
|
473
|
+
}
|
|
474
|
+
return out.sort((a, b) => compare(a.source, b.source) || compare(a.category, b.category) || compare(a.path ?? "", b.path ?? ""));
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Run the scan. Never throws for a source failure: each becomes a diagnostic and
|
|
478
|
+
* the rest of the result is still returned. The result holds names, locations,
|
|
479
|
+
* mappings, and fingerprints only.
|
|
480
|
+
*/
|
|
481
|
+
export async function scanCredentialReferences(deps) {
|
|
482
|
+
const diagnostics = [];
|
|
483
|
+
const files = await discoverFiles(deps, diagnostics);
|
|
484
|
+
const projectMcp = await discoverProjectMcp(deps, files.trackedOpenable, diagnostics);
|
|
485
|
+
const hostMcp = await discoverHostMcp(deps, diagnostics);
|
|
486
|
+
const registry = await discoverBridgeRegistry(deps, diagnostics);
|
|
487
|
+
let storeTargets = [];
|
|
488
|
+
try {
|
|
489
|
+
const store = await deps.listStoreTargets(deps.repoName);
|
|
490
|
+
if (store.state === "ok")
|
|
491
|
+
storeTargets = store.targets.map((t) => ({ target: t.target, keys: [...t.keys].sort(compare) }));
|
|
492
|
+
else if (store.state === "failed") {
|
|
493
|
+
diagnostics.push({
|
|
494
|
+
category: store.reason === "store_malformed" ? "parse_failed" : "source_unreadable",
|
|
495
|
+
source: "credential_store",
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
diagnostics.push({ category: "source_unreadable", source: "credential_store" });
|
|
501
|
+
}
|
|
502
|
+
const references = await readExistingReferences(deps, diagnostics);
|
|
503
|
+
const finalDiagnostics = uniqueDiagnostics(diagnostics);
|
|
504
|
+
return {
|
|
505
|
+
version: CREDENTIAL_SCAN_VERSION,
|
|
506
|
+
repo_name: deps.repoName,
|
|
507
|
+
filename_candidates: files.filenames.sort((a, b) => compare(a.path, b.path)),
|
|
508
|
+
template_candidates: files.templates.sort((a, b) => compare(a.path, b.path)),
|
|
509
|
+
project_mcp: projectMcp,
|
|
510
|
+
host_mcp: hostMcp,
|
|
511
|
+
bridge_registry: registry,
|
|
512
|
+
store_targets: storeTargets.sort((a, b) => compare(a.target, b.target)),
|
|
513
|
+
references,
|
|
514
|
+
diagnostics: finalDiagnostics,
|
|
515
|
+
complete: finalDiagnostics.length === 0,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
@@ -255,6 +255,56 @@ export async function resolveCredentialBundle(bundleKey, requiredKeys, deps) {
|
|
|
255
255
|
}
|
|
256
256
|
return { ok: true, values, source: "file" };
|
|
257
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* True when a store target belongs to `repoName` under the grant-bundle naming
|
|
260
|
+
* convention `mcp-grant:<repo>:<server>:<suffix>`. The repository segment must
|
|
261
|
+
* match exactly: a substring match is never ownership. The routing credential
|
|
262
|
+
* (`bapi:<repo>`) is deliberately not listed, because it is never a worker
|
|
263
|
+
* credential candidate.
|
|
264
|
+
*/
|
|
265
|
+
function isRepositoryOwnedTarget(target, repoName) {
|
|
266
|
+
const parts = target.split(":");
|
|
267
|
+
return parts.length >= 4 && parts[0] === "mcp-grant" && parts[1] === repoName;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Names-only, read-only inventory of the credential-store targets owned by one
|
|
271
|
+
* repository (BAPI-1648). It reads and parses the store, then projects every
|
|
272
|
+
* value away before returning: callers get target names and sorted key names.
|
|
273
|
+
* It never consults the ambient environment for credentials, never writes, and
|
|
274
|
+
* never migrates. Absent, unreadable, and malformed stores stay distinct.
|
|
275
|
+
*/
|
|
276
|
+
export async function listRepositoryCredentialTargetNames(repoName, deps) {
|
|
277
|
+
let resolution;
|
|
278
|
+
try {
|
|
279
|
+
resolution = await resolveCredentialStorePath(deps);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return { state: "failed", reason: "store_unreadable", targets: [] };
|
|
283
|
+
}
|
|
284
|
+
if (!resolution.found)
|
|
285
|
+
return { state: "absent", targets: [] };
|
|
286
|
+
let raw;
|
|
287
|
+
try {
|
|
288
|
+
raw = await deps.readFile(resolution.path);
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
const code = err && typeof err === "object" ? err.code : undefined;
|
|
292
|
+
if (code === "ENOENT")
|
|
293
|
+
return { state: "absent", targets: [] };
|
|
294
|
+
return { state: "failed", reason: "store_unreadable", targets: [] };
|
|
295
|
+
}
|
|
296
|
+
const parsed = parseCredentialStoreJson(raw);
|
|
297
|
+
if (!parsed.ok)
|
|
298
|
+
return { state: "failed", reason: "store_malformed", targets: [] };
|
|
299
|
+
const targets = [];
|
|
300
|
+
for (const [target, entry] of Object.entries(parsed.value)) {
|
|
301
|
+
if (!isRepositoryOwnedTarget(target, repoName))
|
|
302
|
+
continue;
|
|
303
|
+
targets.push({ target, keys: Object.keys(entry).sort() });
|
|
304
|
+
}
|
|
305
|
+
targets.sort((a, b) => (a.target < b.target ? -1 : a.target > b.target ? 1 : 0));
|
|
306
|
+
return { state: "ok", targets };
|
|
307
|
+
}
|
|
258
308
|
/**
|
|
259
309
|
* Resolve the `BAPI_API_KEY` for `bapi:<repoName>`. Delegates to the generic
|
|
260
310
|
* {@link resolveCredentialBundle} with bundle key `bapi:${repoName}` and the
|