@bridge_gpt/mcp-server 0.2.72 → 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 +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -21
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -15
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- 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 +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/completion-contract.js +8 -1
- package/build/executor/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-invoke.js +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- 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 +63 -2
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -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
|
|
@@ -1419,6 +1469,76 @@ export async function upsertBapiCredential(repoName, apiKey, deps, options = {})
|
|
|
1419
1469
|
return { ok: true, path: primaryPath, target, action, migratedFallback };
|
|
1420
1470
|
}, (error) => ({ ok: false, path: primaryPath, target, kind: "lock-error", error }), false);
|
|
1421
1471
|
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Generic bundle upsert (BAPI-1545): store `values` as the WHOLE entry for
|
|
1474
|
+
* `target` in the primary credential store. Used by the MCP grant setup item to
|
|
1475
|
+
* move an imported host server's env values out of any config file and into the
|
|
1476
|
+
* store, under a grant-specific target the grant then references by name.
|
|
1477
|
+
*
|
|
1478
|
+
* Same contract as {@link upsertBapiCredential}: the shared lock (when a lock
|
|
1479
|
+
* primitive is available), fallback seeding on the first primary write, temp
|
|
1480
|
+
* write with mode `0600`, atomic rename, and fixed errors that never echo a
|
|
1481
|
+
* value. `createOnly` refuses to touch an existing target, so a bundle the
|
|
1482
|
+
* current grant already references is never overwritten.
|
|
1483
|
+
*/
|
|
1484
|
+
export async function upsertCredentialBundle(target, values, deps, options = {}) {
|
|
1485
|
+
const primaryPath = getPrimaryCredentialStorePath(deps);
|
|
1486
|
+
const trimmedTarget = (target ?? "").trim();
|
|
1487
|
+
if (trimmedTarget.length === 0 || trimmedTarget !== target) {
|
|
1488
|
+
return { ok: false, path: primaryPath, target: "", kind: "invalid-target", error: "Cannot store a credential bundle: the target is empty or padded." };
|
|
1489
|
+
}
|
|
1490
|
+
const keys = Object.keys(values);
|
|
1491
|
+
if (keys.length === 0 || keys.some((k) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) || typeof values[k] !== "string")) {
|
|
1492
|
+
return { ok: false, path: primaryPath, target, kind: "invalid-values", error: `Cannot store the credential bundle ${target}: its key names or values are not usable.` };
|
|
1493
|
+
}
|
|
1494
|
+
return withCredentialStoreLock(deps, async () => {
|
|
1495
|
+
const primary = await readCredentialStoreJsonIfPresent(primaryPath, deps);
|
|
1496
|
+
if (primary.state === "error")
|
|
1497
|
+
return { ok: false, path: primaryPath, target, kind: primary.kind, error: primary.error };
|
|
1498
|
+
const base = primary.state === "present" ? { ...primary.value } : (await mergeFallbackCredentialStoreOnFirstPrimaryWrite(deps)).base;
|
|
1499
|
+
const existing = base[target];
|
|
1500
|
+
if (existing !== undefined && options.createOnly === true) {
|
|
1501
|
+
return { ok: false, path: primaryPath, target, kind: "exists", error: `The credential bundle ${target} already exists; it was left unchanged.` };
|
|
1502
|
+
}
|
|
1503
|
+
const nextEntry = {};
|
|
1504
|
+
for (const key of keys)
|
|
1505
|
+
nextEntry[key] = values[key];
|
|
1506
|
+
if (existing !== undefined && JSON.stringify(existing) === JSON.stringify(nextEntry)) {
|
|
1507
|
+
return { ok: true, path: primaryPath, target, action: "unchanged" };
|
|
1508
|
+
}
|
|
1509
|
+
const next = { ...base, [target]: nextEntry };
|
|
1510
|
+
if (deps.open) {
|
|
1511
|
+
const durable = await durablyReplaceCredentialStoreJson(primaryPath, next, deps);
|
|
1512
|
+
if (!durable.ok && durable.kind !== "post-rename-uncertain") {
|
|
1513
|
+
return { ok: false, path: primaryPath, target, kind: durable.kind, error: `Failed to write credentials file at ${primaryPath}.` };
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
else {
|
|
1517
|
+
const dir = path.dirname(primaryPath);
|
|
1518
|
+
const tempPath = path.join(dir, `${path.basename(primaryPath)}.${(deps.tempSuffix ?? defaultTempSuffix)()}.tmp`);
|
|
1519
|
+
const isPosix = deps.platform !== "win32";
|
|
1520
|
+
try {
|
|
1521
|
+
await deps.mkdir(dir, { recursive: true });
|
|
1522
|
+
await deps.writeFile(tempPath, formatCredentialStoreJson(next), isPosix ? { encoding: "utf-8", mode: 0o600 } : { encoding: "utf-8" });
|
|
1523
|
+
if (isPosix)
|
|
1524
|
+
await deps.chmod(tempPath, 0o600);
|
|
1525
|
+
await deps.rename(tempPath, primaryPath);
|
|
1526
|
+
}
|
|
1527
|
+
catch {
|
|
1528
|
+
if (deps.unlink) {
|
|
1529
|
+
try {
|
|
1530
|
+
await deps.unlink(tempPath);
|
|
1531
|
+
}
|
|
1532
|
+
catch {
|
|
1533
|
+
/* cleanup failure must not mask the write error */
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
return { ok: false, path: primaryPath, target, kind: "write-error", error: `Failed to write credentials file at ${primaryPath}.` };
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
return { ok: true, path: primaryPath, target, action: existing === undefined ? "created" : "updated" };
|
|
1540
|
+
}, (error) => ({ ok: false, path: primaryPath, target, kind: "lock-error", error }), false);
|
|
1541
|
+
}
|
|
1422
1542
|
// ---------------------------------------------------------------------------
|
|
1423
1543
|
// Epic-launch credential binding (BAPI-1260)
|
|
1424
1544
|
// ---------------------------------------------------------------------------
|
|
@@ -1432,7 +1552,7 @@ export async function upsertBapiCredential(repoName, apiKey, deps, options = {})
|
|
|
1432
1552
|
*/
|
|
1433
1553
|
export const BAPI_EPIC_LAUNCH_BOUND_BASE_URL_FIELD = "BAPI_EPIC_LAUNCH_BOUND_BASE_URL";
|
|
1434
1554
|
/** Trim and drop trailing slashes — the executor's own base-URL normalization. */
|
|
1435
|
-
function normalizeBoundBaseUrl(raw) {
|
|
1555
|
+
export function normalizeBoundBaseUrl(raw) {
|
|
1436
1556
|
if (typeof raw !== "string")
|
|
1437
1557
|
return null;
|
|
1438
1558
|
const normalized = raw.trim().replace(/\/+$/, "");
|