@bridge_gpt/mcp-server 0.2.71 → 0.2.73
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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -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/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- 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-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 +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- 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.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -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/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -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-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- 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 +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -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/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -1054,8 +1054,12 @@ export async function promoteBootstrapPendingCredential(params, deps) {
|
|
|
1054
1054
|
error: `No pending bootstrap-invite credential for ${getBootstrapPendingTarget(repoName)} in ${primaryPath}.`,
|
|
1055
1055
|
};
|
|
1056
1056
|
}
|
|
1057
|
+
if (Object.prototype.hasOwnProperty.call(params, "observedKey") &&
|
|
1058
|
+
(typeof base[target]?.BAPI_API_KEY === "string" ? base[target].BAPI_API_KEY : null) !== params.observedKey) {
|
|
1059
|
+
return { ok: false, path: primaryPath, target, kind: "credential-conflict", error: "Credential changed since the replacement decision; replay proof preserved." };
|
|
1060
|
+
}
|
|
1057
1061
|
const hadKey = hasExistingBapiKey(base, repoName);
|
|
1058
|
-
if (hadKey && !params.allowOverwriteExistingCredential) {
|
|
1062
|
+
if (hadKey && base[target]?.BAPI_API_KEY !== pending.keySecret && !params.allowOverwriteExistingCredential) {
|
|
1059
1063
|
return {
|
|
1060
1064
|
ok: false,
|
|
1061
1065
|
path: primaryPath,
|
|
@@ -1068,6 +1072,8 @@ export async function promoteBootstrapPendingCredential(params, deps) {
|
|
|
1068
1072
|
delete next[getBootstrapPendingTarget(repoName)];
|
|
1069
1073
|
// Preserve sibling secret names under bapi:<repo>; replace ONLY BAPI_API_KEY.
|
|
1070
1074
|
next[target] = { ...(base[target] ?? {}), BAPI_API_KEY: pending.keySecret };
|
|
1075
|
+
if (base[target]?.BAPI_API_KEY !== pending.keySecret)
|
|
1076
|
+
delete next[target].BAPI_EPIC_LAUNCH_BOUND_BASE_URL;
|
|
1071
1077
|
const written = await durablyReplaceCredentialStoreJson(primaryPath, next, deps);
|
|
1072
1078
|
if (!written.ok) {
|
|
1073
1079
|
return { ok: false, path: primaryPath, target, kind: written.kind, error: written.error };
|
|
@@ -1308,22 +1314,10 @@ export async function discardBootstrapPendingCredential(params, deps) {
|
|
|
1308
1314
|
return { ok: true, path: primaryPath, target };
|
|
1309
1315
|
}, (error) => ({ ok: false, path: primaryPath, target, kind: "lock-error", error }));
|
|
1310
1316
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
* - Always targets {@link getPrimaryCredentialStorePath}; never writes the
|
|
1316
|
-
* fallback path and never touches project/worktree config.
|
|
1317
|
-
* - Preserves every existing top-level entry and every sibling secret under
|
|
1318
|
-
* `bapi:<repoName>`; replaces only `BAPI_API_KEY`.
|
|
1319
|
-
* - On a first primary write, seeds from the legacy fallback store so its
|
|
1320
|
-
* entries are not shadowed (`migratedFallback: true`).
|
|
1321
|
-
* - POSIX: writes mode `0600` and `chmod`s the temp file before rename.
|
|
1322
|
-
* `win32`: skips chmod and relies on user-profile ACLs.
|
|
1323
|
-
* - Returns a structured, secret-free result. The `apiKey` value never appears
|
|
1324
|
-
* in any returned error, even if an underlying I/O error message contains it.
|
|
1325
|
-
*/
|
|
1326
|
-
export async function upsertBapiCredential(repoName, apiKey, deps) {
|
|
1317
|
+
function observationChanged(options, actual) {
|
|
1318
|
+
return Object.prototype.hasOwnProperty.call(options, "observedKey") && options.observedKey !== (actual ?? null);
|
|
1319
|
+
}
|
|
1320
|
+
export async function upsertBapiCredential(repoName, apiKey, deps, options = {}) {
|
|
1327
1321
|
const primaryPath = getPrimaryCredentialStorePath(deps);
|
|
1328
1322
|
const trimmedRepo = (repoName ?? "").trim();
|
|
1329
1323
|
const trimmedKey = (apiKey ?? "").trim();
|
|
@@ -1369,6 +1363,12 @@ export async function upsertBapiCredential(repoName, apiKey, deps) {
|
|
|
1369
1363
|
migratedFallback = seeded.migratedFallback;
|
|
1370
1364
|
}
|
|
1371
1365
|
const existingEntry = base[target];
|
|
1366
|
+
const actualKey = existingEntry?.BAPI_API_KEY?.trim() || undefined;
|
|
1367
|
+
if (observationChanged(options, actualKey))
|
|
1368
|
+
return { ok: false, path: primaryPath, target,
|
|
1369
|
+
kind: "changed-since-decision", error: "Saved credential changed since the decision. Re-evaluate before writing." };
|
|
1370
|
+
if (actualKey === trimmedKey)
|
|
1371
|
+
return { ok: true, path: primaryPath, target, action: "unchanged", migratedFallback: false };
|
|
1372
1372
|
const hadKey = !!existingEntry &&
|
|
1373
1373
|
typeof existingEntry.BAPI_API_KEY === "string" &&
|
|
1374
1374
|
existingEntry.BAPI_API_KEY.length > 0;
|
|
@@ -1419,6 +1419,76 @@ export async function upsertBapiCredential(repoName, apiKey, deps) {
|
|
|
1419
1419
|
return { ok: true, path: primaryPath, target, action, migratedFallback };
|
|
1420
1420
|
}, (error) => ({ ok: false, path: primaryPath, target, kind: "lock-error", error }), false);
|
|
1421
1421
|
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Generic bundle upsert (BAPI-1545): store `values` as the WHOLE entry for
|
|
1424
|
+
* `target` in the primary credential store. Used by the MCP grant setup item to
|
|
1425
|
+
* move an imported host server's env values out of any config file and into the
|
|
1426
|
+
* store, under a grant-specific target the grant then references by name.
|
|
1427
|
+
*
|
|
1428
|
+
* Same contract as {@link upsertBapiCredential}: the shared lock (when a lock
|
|
1429
|
+
* primitive is available), fallback seeding on the first primary write, temp
|
|
1430
|
+
* write with mode `0600`, atomic rename, and fixed errors that never echo a
|
|
1431
|
+
* value. `createOnly` refuses to touch an existing target, so a bundle the
|
|
1432
|
+
* current grant already references is never overwritten.
|
|
1433
|
+
*/
|
|
1434
|
+
export async function upsertCredentialBundle(target, values, deps, options = {}) {
|
|
1435
|
+
const primaryPath = getPrimaryCredentialStorePath(deps);
|
|
1436
|
+
const trimmedTarget = (target ?? "").trim();
|
|
1437
|
+
if (trimmedTarget.length === 0 || trimmedTarget !== target) {
|
|
1438
|
+
return { ok: false, path: primaryPath, target: "", kind: "invalid-target", error: "Cannot store a credential bundle: the target is empty or padded." };
|
|
1439
|
+
}
|
|
1440
|
+
const keys = Object.keys(values);
|
|
1441
|
+
if (keys.length === 0 || keys.some((k) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) || typeof values[k] !== "string")) {
|
|
1442
|
+
return { ok: false, path: primaryPath, target, kind: "invalid-values", error: `Cannot store the credential bundle ${target}: its key names or values are not usable.` };
|
|
1443
|
+
}
|
|
1444
|
+
return withCredentialStoreLock(deps, async () => {
|
|
1445
|
+
const primary = await readCredentialStoreJsonIfPresent(primaryPath, deps);
|
|
1446
|
+
if (primary.state === "error")
|
|
1447
|
+
return { ok: false, path: primaryPath, target, kind: primary.kind, error: primary.error };
|
|
1448
|
+
const base = primary.state === "present" ? { ...primary.value } : (await mergeFallbackCredentialStoreOnFirstPrimaryWrite(deps)).base;
|
|
1449
|
+
const existing = base[target];
|
|
1450
|
+
if (existing !== undefined && options.createOnly === true) {
|
|
1451
|
+
return { ok: false, path: primaryPath, target, kind: "exists", error: `The credential bundle ${target} already exists; it was left unchanged.` };
|
|
1452
|
+
}
|
|
1453
|
+
const nextEntry = {};
|
|
1454
|
+
for (const key of keys)
|
|
1455
|
+
nextEntry[key] = values[key];
|
|
1456
|
+
if (existing !== undefined && JSON.stringify(existing) === JSON.stringify(nextEntry)) {
|
|
1457
|
+
return { ok: true, path: primaryPath, target, action: "unchanged" };
|
|
1458
|
+
}
|
|
1459
|
+
const next = { ...base, [target]: nextEntry };
|
|
1460
|
+
if (deps.open) {
|
|
1461
|
+
const durable = await durablyReplaceCredentialStoreJson(primaryPath, next, deps);
|
|
1462
|
+
if (!durable.ok && durable.kind !== "post-rename-uncertain") {
|
|
1463
|
+
return { ok: false, path: primaryPath, target, kind: durable.kind, error: `Failed to write credentials file at ${primaryPath}.` };
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
else {
|
|
1467
|
+
const dir = path.dirname(primaryPath);
|
|
1468
|
+
const tempPath = path.join(dir, `${path.basename(primaryPath)}.${(deps.tempSuffix ?? defaultTempSuffix)()}.tmp`);
|
|
1469
|
+
const isPosix = deps.platform !== "win32";
|
|
1470
|
+
try {
|
|
1471
|
+
await deps.mkdir(dir, { recursive: true });
|
|
1472
|
+
await deps.writeFile(tempPath, formatCredentialStoreJson(next), isPosix ? { encoding: "utf-8", mode: 0o600 } : { encoding: "utf-8" });
|
|
1473
|
+
if (isPosix)
|
|
1474
|
+
await deps.chmod(tempPath, 0o600);
|
|
1475
|
+
await deps.rename(tempPath, primaryPath);
|
|
1476
|
+
}
|
|
1477
|
+
catch {
|
|
1478
|
+
if (deps.unlink) {
|
|
1479
|
+
try {
|
|
1480
|
+
await deps.unlink(tempPath);
|
|
1481
|
+
}
|
|
1482
|
+
catch {
|
|
1483
|
+
/* cleanup failure must not mask the write error */
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return { ok: false, path: primaryPath, target, kind: "write-error", error: `Failed to write credentials file at ${primaryPath}.` };
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return { ok: true, path: primaryPath, target, action: existing === undefined ? "created" : "updated" };
|
|
1490
|
+
}, (error) => ({ ok: false, path: primaryPath, target, kind: "lock-error", error }), false);
|
|
1491
|
+
}
|
|
1422
1492
|
// ---------------------------------------------------------------------------
|
|
1423
1493
|
// Epic-launch credential binding (BAPI-1260)
|
|
1424
1494
|
// ---------------------------------------------------------------------------
|
|
@@ -1432,7 +1502,7 @@ export async function upsertBapiCredential(repoName, apiKey, deps) {
|
|
|
1432
1502
|
*/
|
|
1433
1503
|
export const BAPI_EPIC_LAUNCH_BOUND_BASE_URL_FIELD = "BAPI_EPIC_LAUNCH_BOUND_BASE_URL";
|
|
1434
1504
|
/** Trim and drop trailing slashes — the executor's own base-URL normalization. */
|
|
1435
|
-
function normalizeBoundBaseUrl(raw) {
|
|
1505
|
+
export function normalizeBoundBaseUrl(raw) {
|
|
1436
1506
|
if (typeof raw !== "string")
|
|
1437
1507
|
return null;
|
|
1438
1508
|
const normalized = raw.trim().replace(/\/+$/, "");
|
|
@@ -1504,7 +1574,7 @@ export async function resolveEpicLaunchCredential(repoName, targetBaseUrl, deps,
|
|
|
1504
1574
|
kind: "binding-unbound",
|
|
1505
1575
|
error: `The stored credential "${diagnosticComponent(bundleKey)}" has not been approved for this Bridge API endpoint ` +
|
|
1506
1576
|
`(${diagnosticComponent(primaryPath)}). Production needs no approval; any other endpoint does. Run guided setup ` +
|
|
1507
|
-
`once to bind it: install
|
|
1577
|
+
`once to bind it: install epic-implementer --launch-profile <name> --base-url ${diagnosticComponent(target)}.`,
|
|
1508
1578
|
};
|
|
1509
1579
|
}
|
|
1510
1580
|
// An unreadable read-back is refused like a mismatch: the key was read a
|
|
@@ -1516,7 +1586,7 @@ export async function resolveEpicLaunchCredential(repoName, targetBaseUrl, deps,
|
|
|
1516
1586
|
error: `The stored credential "${diagnosticComponent(bundleKey)}" is approved for a different Bridge API endpoint than the ` +
|
|
1517
1587
|
"selected target. It was not sent. A key approved for a local server is never sent to " +
|
|
1518
1588
|
"production: pass that server's --launch-profile <name> or --base-url <url>, or bind the key " +
|
|
1519
|
-
"once with install
|
|
1589
|
+
"once with install epic-implementer --launch-profile <name> --base-url <url>.",
|
|
1520
1590
|
};
|
|
1521
1591
|
}
|
|
1522
1592
|
return { ok: true, apiKey: stored.values.BAPI_API_KEY, source: "file", binding: "store-bound" };
|
|
@@ -1573,7 +1643,7 @@ export async function readStoredBinding(bundleKey, deps) {
|
|
|
1573
1643
|
* durable replacement; every other entry and sibling field is preserved. A store
|
|
1574
1644
|
* with no key for the repository is refused rather than creating one.
|
|
1575
1645
|
*/
|
|
1576
|
-
export async function bindEpicLaunchCredential(repoName, targetBaseUrl, deps) {
|
|
1646
|
+
export async function bindEpicLaunchCredential(repoName, targetBaseUrl, deps, options = {}) {
|
|
1577
1647
|
const target = `bapi:${repoName.trim()}`;
|
|
1578
1648
|
const baseUrl = normalizeBoundBaseUrl(targetBaseUrl);
|
|
1579
1649
|
if (repoName.trim().length === 0 || baseUrl === null) {
|
|
@@ -1594,6 +1664,9 @@ export async function bindEpicLaunchCredential(repoName, targetBaseUrl, deps) {
|
|
|
1594
1664
|
error: `No stored BAPI_API_KEY under "${target}" in ${primaryPath} to bind.`,
|
|
1595
1665
|
};
|
|
1596
1666
|
}
|
|
1667
|
+
if (observationChanged(options, entry.BAPI_API_KEY.trim()))
|
|
1668
|
+
return { ok: false, target,
|
|
1669
|
+
kind: "changed-since-decision", error: "Saved credential changed since endpoint authorization. Re-evaluate before binding." };
|
|
1597
1670
|
const previous = normalizeBoundBaseUrl(entry[BAPI_EPIC_LAUNCH_BOUND_BASE_URL_FIELD]);
|
|
1598
1671
|
if (previous === baseUrl)
|
|
1599
1672
|
return { ok: true, target, action: "unchanged", path: primaryPath };
|
|
@@ -1913,6 +1986,8 @@ export async function promoteModernBootstrapCredential(scope, proof, deps, allow
|
|
|
1913
1986
|
return { ok: true, path: getPrimaryCredentialStorePath(deps) };
|
|
1914
1987
|
if (!record || record.keySecret !== proof.keySecret || record.canonical !== proof.canonical || record.fingerprint !== proof.fingerprint || record.folder !== scope.folder || record.baseUrl !== scope.baseUrl || reference?.LOCATOR !== scope.locator || reference.FOLDER !== scope.folder || reference.BASE_URL !== scope.baseUrl)
|
|
1915
1988
|
throw new Error(modernRecoveryError);
|
|
1989
|
+
if (consentedKey !== undefined && (existingKey ?? null) !== consentedKey)
|
|
1990
|
+
return { ok: false, error: "Destination credential changed after the decision. Replay proof preserved." };
|
|
1916
1991
|
if (existingKey && existingKey !== proof.keySecret) {
|
|
1917
1992
|
if (!allowOverwrite)
|
|
1918
1993
|
return { ok: false, error: "The canonical credential already exists; overwrite consent is required.", needsConsent: true, observedKey: existingKey };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1551 — the TypeScript copy of the `dependency_install` and `ci_database`
|
|
3
|
+
* gate-profile declaration rules.
|
|
4
|
+
*
|
|
5
|
+
* `api/library/epic_implementer/gate_profile.py` (`validate_dependency_install`,
|
|
6
|
+
* `validate_ci_database`) is the authority; this module mirrors its bounds so the
|
|
7
|
+
* Bridge API client can parse a stored profile fail-closed and the executor can
|
|
8
|
+
* re-check a job payload without trusting it.
|
|
9
|
+
*
|
|
10
|
+
* Two consumers, two postures:
|
|
11
|
+
*
|
|
12
|
+
* - {@link parseDependencyInstallStrict} — the client. Any invalid entry makes the
|
|
13
|
+
* whole list unreadable (`null`), like any other malformed profile member.
|
|
14
|
+
* - {@link admitDependencyInstallDeclarations} — the executor. Never throws: a bad
|
|
15
|
+
* entry is skipped with a closed reason and the rest still apply.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here logs, and nothing returned for a refusal carries an argv item. A
|
|
18
|
+
* `cwd` is returned beside a refusal only after it passed the path rules, so it
|
|
19
|
+
* is safe to print.
|
|
20
|
+
*
|
|
21
|
+
* Identity: two entries are duplicates when they share the canonical
|
|
22
|
+
* `(cwd, sorted lockfiles)` pair. A JavaScript and a Python toolchain at the same
|
|
23
|
+
* root are two distinct entries.
|
|
24
|
+
*/
|
|
25
|
+
export const MAX_DEPENDENCY_INSTALL_ENTRIES = 8;
|
|
26
|
+
export const MAX_DEPENDENCY_INSTALL_ARGV_ITEMS = 32;
|
|
27
|
+
export const MAX_DEPENDENCY_INSTALL_ARG_CHARS = 1024;
|
|
28
|
+
export const MAX_DEPENDENCY_INSTALL_LOCKFILES = 8;
|
|
29
|
+
/** The longest repository-relative path a declaration may name. */
|
|
30
|
+
export const MAX_DEPENDENCY_INSTALL_PATH_CHARS = 512;
|
|
31
|
+
export const CI_DATABASE_VALUES = ["none", "provided", "unknown"];
|
|
32
|
+
export const CI_DATABASE_DEFAULT = "unknown";
|
|
33
|
+
const ENTRY_KEYS = new Set(["cwd", "argv", "lockfiles"]);
|
|
34
|
+
/** Absolute-looking, backslash, colon, and every control or line-separator character. */
|
|
35
|
+
const FORBIDDEN_PATH_CHARS = /[:\\\x00-\x1f\x7f-\x9f\u2028\u2029]/;
|
|
36
|
+
const FORBIDDEN_ARG_CHARS = /[\u0000\r\n]/;
|
|
37
|
+
/**
|
|
38
|
+
* True when `value` is a safe repository-relative path: not absolute, no `..`,
|
|
39
|
+
* no `.` segment, no empty segment, no backslash, colon, or control character.
|
|
40
|
+
* `allowRoot` admits the lone `"."` (the repository root) for a `cwd`.
|
|
41
|
+
*/
|
|
42
|
+
export function isSafeRepoRelativePath(value, options = {}) {
|
|
43
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_DEPENDENCY_INSTALL_PATH_CHARS) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (value === ".")
|
|
47
|
+
return options.allowRoot === true;
|
|
48
|
+
if (value.startsWith("/") || FORBIDDEN_PATH_CHARS.test(value))
|
|
49
|
+
return false;
|
|
50
|
+
return value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
51
|
+
}
|
|
52
|
+
/** The canonical identity of an entry: its `cwd` and its lockfiles, sorted. */
|
|
53
|
+
export function dependencyInstallEntryIdentity(entry) {
|
|
54
|
+
return JSON.stringify([entry.cwd, [...entry.lockfiles].sort()]);
|
|
55
|
+
}
|
|
56
|
+
/** Check one raw entry against every rule except list bounds and duplicates. */
|
|
57
|
+
export function checkDependencyInstallEntry(raw) {
|
|
58
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
59
|
+
return { ok: false, reason: "dependency_install_invalid_entry" };
|
|
60
|
+
}
|
|
61
|
+
const item = raw;
|
|
62
|
+
for (const key of Object.keys(item)) {
|
|
63
|
+
if (!ENTRY_KEYS.has(key))
|
|
64
|
+
return { ok: false, reason: "dependency_install_invalid_entry" };
|
|
65
|
+
}
|
|
66
|
+
const { cwd, argv, lockfiles } = item;
|
|
67
|
+
if (typeof cwd !== "string")
|
|
68
|
+
return { ok: false, reason: "dependency_install_invalid_entry" };
|
|
69
|
+
if (!isSafeRepoRelativePath(cwd, { allowRoot: true })) {
|
|
70
|
+
return { ok: false, reason: "dependency_install_invalid_path" };
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(argv) || !Array.isArray(lockfiles)) {
|
|
73
|
+
return { ok: false, reason: "dependency_install_invalid_entry", cwd };
|
|
74
|
+
}
|
|
75
|
+
if (argv.length === 0 || lockfiles.length === 0) {
|
|
76
|
+
return { ok: false, reason: "dependency_install_invalid_entry", cwd };
|
|
77
|
+
}
|
|
78
|
+
if (argv.length > MAX_DEPENDENCY_INSTALL_ARGV_ITEMS || lockfiles.length > MAX_DEPENDENCY_INSTALL_LOCKFILES) {
|
|
79
|
+
return { ok: false, reason: "dependency_install_over_bound", cwd };
|
|
80
|
+
}
|
|
81
|
+
for (const arg of argv) {
|
|
82
|
+
if (typeof arg !== "string" || arg.length === 0 || FORBIDDEN_ARG_CHARS.test(arg)) {
|
|
83
|
+
return { ok: false, reason: "dependency_install_invalid_entry", cwd };
|
|
84
|
+
}
|
|
85
|
+
if (arg.length > MAX_DEPENDENCY_INSTALL_ARG_CHARS) {
|
|
86
|
+
return { ok: false, reason: "dependency_install_over_bound", cwd };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const seenLockfiles = new Set();
|
|
90
|
+
for (const file of lockfiles) {
|
|
91
|
+
if (!isSafeRepoRelativePath(file))
|
|
92
|
+
return { ok: false, reason: "dependency_install_invalid_path", cwd };
|
|
93
|
+
if (seenLockfiles.has(file))
|
|
94
|
+
return { ok: false, reason: "dependency_install_duplicate", cwd };
|
|
95
|
+
seenLockfiles.add(file);
|
|
96
|
+
}
|
|
97
|
+
return { ok: true, entry: { cwd, argv: [...argv], lockfiles: [...lockfiles] } };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The executor's never-throwing admission: re-check every server bound and skip
|
|
101
|
+
* a bad entry with a closed reason. The first occurrence of an identity wins.
|
|
102
|
+
*/
|
|
103
|
+
export function admitDependencyInstallDeclarations(raw) {
|
|
104
|
+
if (!Array.isArray(raw))
|
|
105
|
+
return { entries: [], skipped: [], notAList: true };
|
|
106
|
+
const entries = [];
|
|
107
|
+
const skipped = [];
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
for (let index = 0; index < raw.length; index++) {
|
|
110
|
+
if (index >= MAX_DEPENDENCY_INSTALL_ENTRIES) {
|
|
111
|
+
skipped.push({ reason: "dependency_install_over_bound" });
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
const checked = checkDependencyInstallEntry(raw[index]);
|
|
115
|
+
if (!checked.ok) {
|
|
116
|
+
skipped.push({ reason: checked.reason, ...(checked.cwd !== undefined ? { cwd: checked.cwd } : {}) });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const identity = dependencyInstallEntryIdentity(checked.entry);
|
|
120
|
+
if (seen.has(identity)) {
|
|
121
|
+
skipped.push({ reason: "dependency_install_duplicate", cwd: checked.entry.cwd });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
seen.add(identity);
|
|
125
|
+
entries.push(checked.entry);
|
|
126
|
+
}
|
|
127
|
+
return { entries, skipped, notAList: false };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The client's fail-closed parse: the whole list or `null`. `undefined` (an
|
|
131
|
+
* absent field) reads as no declarations.
|
|
132
|
+
*/
|
|
133
|
+
export function parseDependencyInstallStrict(raw) {
|
|
134
|
+
if (raw === undefined)
|
|
135
|
+
return [];
|
|
136
|
+
if (!Array.isArray(raw) || raw.length > MAX_DEPENDENCY_INSTALL_ENTRIES)
|
|
137
|
+
return null;
|
|
138
|
+
const admitted = admitDependencyInstallDeclarations(raw);
|
|
139
|
+
if (admitted.notAList || admitted.skipped.length > 0)
|
|
140
|
+
return null;
|
|
141
|
+
return admitted.entries;
|
|
142
|
+
}
|
|
143
|
+
/** True when `value` is one of the three `ci_database` values. */
|
|
144
|
+
export function isCiDatabase(value) {
|
|
145
|
+
return typeof value === "string" && CI_DATABASE_VALUES.includes(value);
|
|
146
|
+
}
|
|
147
|
+
/** Any value other than the three reads as `unknown`. */
|
|
148
|
+
export function normalizeCiDatabase(value) {
|
|
149
|
+
return isCiDatabase(value) ? value : CI_DATABASE_DEFAULT;
|
|
150
|
+
}
|
|
151
|
+
/** True when two declaration lists are the same, entry for entry and in order. */
|
|
152
|
+
export function sameDependencyInstall(a, b) {
|
|
153
|
+
return JSON.stringify(a.map(canonicalEntry)) === JSON.stringify(b.map(canonicalEntry));
|
|
154
|
+
}
|
|
155
|
+
function canonicalEntry(entry) {
|
|
156
|
+
return { cwd: entry.cwd, argv: [...entry.argv], lockfiles: [...entry.lockfiles] };
|
|
157
|
+
}
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
// BAPI-1580 — must-order paths
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
/** The most entries a `must_order_paths` declaration may hold (mirrors `MAX_MUST_ORDER_PATHS`). */
|
|
162
|
+
export const MAX_MUST_ORDER_PATHS = 32;
|
|
163
|
+
const MUST_ORDER_GLOB_CHARS = /[*?[\]]/;
|
|
164
|
+
/**
|
|
165
|
+
* True when `value` is one acceptable must-order entry, exactly as
|
|
166
|
+
* `validate_must_order_paths` checks it: no glob character, and after removing
|
|
167
|
+
* one trailing `/` (a directory prefix) a safe repository-relative path.
|
|
168
|
+
*/
|
|
169
|
+
export function isValidMustOrderPath(value) {
|
|
170
|
+
if (typeof value !== "string" || MUST_ORDER_GLOB_CHARS.test(value))
|
|
171
|
+
return false;
|
|
172
|
+
return isSafeRepoRelativePath(value.endsWith("/") ? value.slice(0, -1) : value);
|
|
173
|
+
}
|
|
174
|
+
/** Code-point order, the order Python's `sorted` gives the server's list. */
|
|
175
|
+
export function compareCodePoints(a, b) {
|
|
176
|
+
const left = Array.from(a);
|
|
177
|
+
const right = Array.from(b);
|
|
178
|
+
for (let i = 0; i < Math.min(left.length, right.length); i++) {
|
|
179
|
+
const diff = (left[i].codePointAt(0) ?? 0) - (right[i].codePointAt(0) ?? 0);
|
|
180
|
+
if (diff !== 0)
|
|
181
|
+
return diff;
|
|
182
|
+
}
|
|
183
|
+
return left.length - right.length;
|
|
184
|
+
}
|
|
185
|
+
/** The canonical (sorted, distinct) form of a must-order list. */
|
|
186
|
+
export function canonicalMustOrderPaths(paths) {
|
|
187
|
+
return [...new Set(paths)].sort(compareCodePoints);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The client's fail-closed parse of `must_order_paths`: the canonical sorted
|
|
191
|
+
* list, or `null` when any entry is invalid, duplicated, or the list is over
|
|
192
|
+
* the bound. `undefined` (an absent field) reads as no declarations.
|
|
193
|
+
*/
|
|
194
|
+
export function parseMustOrderPathsStrict(raw) {
|
|
195
|
+
if (raw === undefined)
|
|
196
|
+
return [];
|
|
197
|
+
if (!Array.isArray(raw) || raw.length > MAX_MUST_ORDER_PATHS)
|
|
198
|
+
return null;
|
|
199
|
+
const seen = new Set();
|
|
200
|
+
for (const entry of raw) {
|
|
201
|
+
if (!isValidMustOrderPath(entry) || seen.has(entry))
|
|
202
|
+
return null;
|
|
203
|
+
seen.add(entry);
|
|
204
|
+
}
|
|
205
|
+
return canonicalMustOrderPaths([...seen]);
|
|
206
|
+
}
|
|
207
|
+
/** True when two must-order lists hold the same entries (order never matters). */
|
|
208
|
+
export function sameMustOrderPaths(a, b) {
|
|
209
|
+
const left = canonicalMustOrderPaths(a);
|
|
210
|
+
const right = canonicalMustOrderPaths(b);
|
|
211
|
+
return left.length === right.length && left.every((p, i) => p === right[i]);
|
|
212
|
+
}
|