@bridge_gpt/mcp-server 0.2.72 → 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 +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -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/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -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 +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +106 -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-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 +166 -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.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 +150 -5
- package/build/conductor/gate-settings-review.js +224 -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-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- 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 +2101 -44
- package/build/epic-launch-context.js +607 -0
- 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/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- 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 +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- 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 +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- 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-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 +234 -109
- package/build/pipelines.generated.js +5 -5
- 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/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- 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 +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- 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/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
package/build/init.js
CHANGED
|
@@ -601,11 +601,11 @@ export async function runInit(cwd, options = {}) {
|
|
|
601
601
|
const detectedIDEs = Object.entries(ideDetection)
|
|
602
602
|
.filter(([, v]) => v)
|
|
603
603
|
.map(([k]) => k);
|
|
604
|
-
|
|
604
|
+
say(`Bridge API --init: detected IDEs: ${detectedIDEs.join(", ")}`);
|
|
605
605
|
// ---- Phase 2: Windsurf manual instructions ----
|
|
606
606
|
if (ideDetection.windsurf) {
|
|
607
607
|
const windsurfSnippet = JSON.stringify({ mcpServers: { [MCP_SERVER_NAME]: buildBridgeApiEntry(cwd) } }, null, 2);
|
|
608
|
-
|
|
608
|
+
say("\n⚠ Windsurf does not support project-local MCP configuration.\n" +
|
|
609
609
|
"Add the following to ~/.codeium/windsurf/mcp_config.json:\n\n" +
|
|
610
610
|
windsurfSnippet + "\n");
|
|
611
611
|
}
|
|
@@ -680,6 +680,21 @@ export async function runInit(cwd, options = {}) {
|
|
|
680
680
|
});
|
|
681
681
|
continue;
|
|
682
682
|
}
|
|
683
|
+
if (found.action === "skip-local-build") {
|
|
684
|
+
// BAPI-1636: a local build has no published-package pin to move. The
|
|
685
|
+
// file is never read for rewrite or re-serialized, so its bytes stay
|
|
686
|
+
// exactly as they were while the other assets below still refresh.
|
|
687
|
+
configActions.push({
|
|
688
|
+
path: target.path,
|
|
689
|
+
action: "skipped — local build preserved",
|
|
690
|
+
});
|
|
691
|
+
structuredActions.push({
|
|
692
|
+
relPath: target.path,
|
|
693
|
+
kind: "skipped-local-build",
|
|
694
|
+
registrationKey: found.registrationKey ?? undefined,
|
|
695
|
+
});
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
683
698
|
if (found.action === "ahead") {
|
|
684
699
|
// Never walk a project backwards. `upgrade` blocks on this before it
|
|
685
700
|
// ever calls init; a direct `--init` from an older CLI reaches here, and
|
|
@@ -877,10 +892,10 @@ export async function runInit(cwd, options = {}) {
|
|
|
877
892
|
scaffoldFailed ||= completed.length !== assets.length;
|
|
878
893
|
const destinationLabel = assets[0]?.hosts.includes("copilot") && (assets[0].kind === "prompt" || assets[0].kind === "skill")
|
|
879
894
|
? `into ${assets[0].destination.split("/").slice(0, 2).join("/")}/` : "assets";
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
895
|
+
say(`\n${label}: scaffolded ${completed.length} ${destinationLabel}`);
|
|
896
|
+
say(` Written: ${completed.filter(o => o !== "skipped").length}`);
|
|
897
|
+
say(` Overwritten (content changed): ${completed.filter(o => o === "overwritten").length}`);
|
|
898
|
+
say(` Skipped (unchanged): ${completed.filter(o => o === "skipped").length}`);
|
|
884
899
|
}
|
|
885
900
|
try {
|
|
886
901
|
await recordProvisionedAssets(cwd, successful, hosts);
|
|
@@ -1058,21 +1073,21 @@ says to serialize structured output.
|
|
|
1058
1073
|
}, null, 2) + "\n";
|
|
1059
1074
|
try {
|
|
1060
1075
|
await stat(readmePath);
|
|
1061
|
-
|
|
1076
|
+
say(` ${path.relative(cwd, readmePath)} (skipped — already exists)`);
|
|
1062
1077
|
}
|
|
1063
1078
|
catch {
|
|
1064
1079
|
await writeFile(readmePath, readmeContent, "utf-8");
|
|
1065
|
-
|
|
1080
|
+
say(` ${path.relative(cwd, readmePath)} (written)`);
|
|
1066
1081
|
}
|
|
1067
1082
|
try {
|
|
1068
1083
|
await stat(examplePath);
|
|
1069
|
-
|
|
1084
|
+
say(` ${path.relative(cwd, examplePath)} (skipped — already exists)`);
|
|
1070
1085
|
}
|
|
1071
1086
|
catch {
|
|
1072
1087
|
await writeFile(examplePath, exampleContent, "utf-8");
|
|
1073
|
-
|
|
1088
|
+
say(` ${path.relative(cwd, examplePath)} (written)`);
|
|
1074
1089
|
}
|
|
1075
|
-
|
|
1090
|
+
say(` ${path.relative(cwd, instrDir)}/ (ensured)`);
|
|
1076
1091
|
// ---- Phase 6b: Scaffold the committed secret-free `.bridge/config` ----
|
|
1077
1092
|
// This manifest is committed and inherited by every worktree; it is the
|
|
1078
1093
|
// input to start-tickets worktree MCP provisioning. It is intentionally
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1638 — answers for `install epic-implementer --answers <file>`.
|
|
3
|
+
*
|
|
4
|
+
* Reads a JSON answers object keyed by `answer_key`, validates the whole of it
|
|
5
|
+
* against the current assessment BEFORE any write, merges the existing per-choice
|
|
6
|
+
* flags into the same decisions, and builds the normalized proposal and its
|
|
7
|
+
* `proposal_digest`.
|
|
8
|
+
*
|
|
9
|
+
* Rules (the consent NFR):
|
|
10
|
+
* - every applicable consequential choice must be stated; a missing one refuses
|
|
11
|
+
* the whole apply and the refusal names every missing key;
|
|
12
|
+
* - a missing non-consequential key takes the recommended value the proposal
|
|
13
|
+
* shows, and that value is hashed like a stated one;
|
|
14
|
+
* - the merge token is accepted only as a reference, never as a value;
|
|
15
|
+
* - a flag that disagrees with an answer is refused;
|
|
16
|
+
* - no refusal ever echoes a submitted value.
|
|
17
|
+
*
|
|
18
|
+
* The digest catches a stale or mismatched answers file. It is NOT proof of human
|
|
19
|
+
* approval: anyone can run proposal mode and get a matching digest.
|
|
20
|
+
*/
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { CONDITIONAL_ANSWER_KEYS, INSTALL_ANSWER_KEYS, INSTALL_PROPOSAL_DIGEST_VERSION, isInstallAnswerKey, } from "./install-bridge-conductor-contracts.js";
|
|
23
|
+
import { REINDEX_BRANCH_EFFECTS, REINDEX_RETRY_EFFECTS, choiceFor, resolveEpicBranchCiRecommendation, } from "./install-bridge-conductor-assessment.js";
|
|
24
|
+
import { isValidCredentialReference, isValidSfccSandboxId, normalizeStorefrontOrigin } from "./epic-server-record.js";
|
|
25
|
+
/** The largest answers file read. A setup answers object is a few kilobytes. */
|
|
26
|
+
export const MAX_ANSWERS_BYTES = 256 * 1024;
|
|
27
|
+
const ENV_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
28
|
+
const STORE_TARGET_RE = /^[A-Za-z0-9][A-Za-z0-9._:/@_-]{0,255}$/;
|
|
29
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
30
|
+
/** An answers value is a short token; anything longer, or token-shaped, is treated as a possible literal secret. */
|
|
31
|
+
const TOKEN_SHAPED_RE = /^(gh[pousr]_|github_pat_)|[A-Za-z0-9_\-]{40,}/;
|
|
32
|
+
const RERUN_FIX = "Fix the answers file, or run --answers - --dry-run --json for a fresh proposal, then rerun.";
|
|
33
|
+
function refusal(reason, keys, detail, fix = RERUN_FIX) {
|
|
34
|
+
return { reasons: [{ reason, keys, detail }], fix };
|
|
35
|
+
}
|
|
36
|
+
/** Read the answers source once: a file path, or `-` for stdin. Errors are fixed text. */
|
|
37
|
+
export async function readAnswersSource(source, deps) {
|
|
38
|
+
let text;
|
|
39
|
+
try {
|
|
40
|
+
text = source === "-" ? await deps.readStdin() : await deps.readFile(source);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { ok: false, refusal: refusal("answers_unreadable", [], "The answers source could not be read.") };
|
|
44
|
+
}
|
|
45
|
+
if (typeof text !== "string" || Buffer.byteLength(text, "utf-8") > MAX_ANSWERS_BYTES) {
|
|
46
|
+
return { ok: false, refusal: refusal("answers_unreadable", [], "The answers source is too large to be an answers file.") };
|
|
47
|
+
}
|
|
48
|
+
return { ok: true, text };
|
|
49
|
+
}
|
|
50
|
+
/** Parse answers JSON. The value stays `unknown` until each key is validated. */
|
|
51
|
+
export function parseAnswersText(text) {
|
|
52
|
+
let parsed;
|
|
53
|
+
try {
|
|
54
|
+
parsed = JSON.parse(text);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return { ok: false, refusal: refusal("answers_malformed", [], "The answers are not valid JSON.") };
|
|
58
|
+
}
|
|
59
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
60
|
+
return { ok: false, refusal: refusal("answers_malformed", [], "The answers must be one JSON object keyed by answer_key.") };
|
|
61
|
+
}
|
|
62
|
+
return { ok: true, envelope: parsed };
|
|
63
|
+
}
|
|
64
|
+
const bad = (reason, detail) => ({ ok: false, reason, detail });
|
|
65
|
+
const option = (id) => ({ ok: true, decision: id === "decline" ? { kind: "decline" } : { kind: "option", option: id } });
|
|
66
|
+
/** The option ids a key accepts, independent of the current evidence. */
|
|
67
|
+
const OPTION_VOCABULARY = Object.freeze({
|
|
68
|
+
gate: ["approve", "decline", "keep"],
|
|
69
|
+
dependency_install: ["approve", "decline", "keep"],
|
|
70
|
+
ci_database: ["approve", "decline", "keep"],
|
|
71
|
+
must_order_paths: ["approve", "decline", "keep"],
|
|
72
|
+
worker_database: ["approve", "decline", "keep"],
|
|
73
|
+
test_command: ["learn", "skip", "keep"],
|
|
74
|
+
setup_pr: ["approve", "decline", "keep"],
|
|
75
|
+
merge_token: ["decline", "keep"],
|
|
76
|
+
reindex: ["approve", "skip", "keep"],
|
|
77
|
+
reindex_branch: ["correct", "keep"],
|
|
78
|
+
reindex_retry: ["retry", "no_retry"],
|
|
79
|
+
worker_mcp_grant: ["decline", "keep"],
|
|
80
|
+
epic_server: ["keep", "none", "local"],
|
|
81
|
+
epic_branch_ci: ["include", "decline"],
|
|
82
|
+
approval_exemption: ["approve", "decline", "keep"],
|
|
83
|
+
launch_profile: ["save", "skip"],
|
|
84
|
+
epic_ci_change: ["approve", "decline", "keep"],
|
|
85
|
+
});
|
|
86
|
+
function isPlainObject(value) {
|
|
87
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
88
|
+
}
|
|
89
|
+
function onlyKeys(value, allowed) {
|
|
90
|
+
return Object.keys(value).every((k) => allowed.includes(k));
|
|
91
|
+
}
|
|
92
|
+
function parseReference(raw) {
|
|
93
|
+
if (!isPlainObject(raw) || Object.keys(raw).length !== 1)
|
|
94
|
+
return null;
|
|
95
|
+
if (typeof raw.env === "string" && ENV_NAME_RE.test(raw.env) && !TOKEN_SHAPED_RE.test(raw.env))
|
|
96
|
+
return { kind: "env", name: raw.env };
|
|
97
|
+
if (typeof raw.credential_store === "string" && STORE_TARGET_RE.test(raw.credential_store) && !TOKEN_SHAPED_RE.test(raw.credential_store)) {
|
|
98
|
+
return { kind: "credential_store", target: raw.credential_store };
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/** Validate one raw value for its key. Never returns the raw value in a detail. */
|
|
103
|
+
export function parseAnswerValue(key, raw) {
|
|
104
|
+
if (key === "merge_token") {
|
|
105
|
+
if (raw === "decline" || raw === "keep")
|
|
106
|
+
return option(raw);
|
|
107
|
+
if (typeof raw === "string")
|
|
108
|
+
return bad("literal_credential", "The merge token is accepted only as a reference, never as a value.");
|
|
109
|
+
if (isPlainObject(raw) && onlyKeys(raw, ["reference"])) {
|
|
110
|
+
const reference = parseReference(raw.reference);
|
|
111
|
+
if (reference !== null)
|
|
112
|
+
return { ok: true, decision: { kind: "reference", reference } };
|
|
113
|
+
}
|
|
114
|
+
return bad("invalid_value", 'Use "decline", "keep", or {"reference": {"env": "NAME"}} or {"reference": {"credential_store": "target"}}.');
|
|
115
|
+
}
|
|
116
|
+
if (key === "worker_mcp_grant") {
|
|
117
|
+
if (raw === "decline" || raw === "keep")
|
|
118
|
+
return option(raw);
|
|
119
|
+
if (Array.isArray(raw) && raw.every((id) => typeof id === "string" && id.length > 0 && id.length <= 300)) {
|
|
120
|
+
return { ok: true, decision: { kind: "selection", ids: [...new Set(raw)].sort() } };
|
|
121
|
+
}
|
|
122
|
+
return bad("invalid_value", 'Use "decline", "keep", or a list of offered option ids ([] approves none).');
|
|
123
|
+
}
|
|
124
|
+
if (key === "test_command" && isPlainObject(raw)) {
|
|
125
|
+
if (onlyKeys(raw, ["command"]) && typeof raw.command === "string" && raw.command.trim().length > 0 && raw.command.length <= 500 && !/[\r\n]/.test(raw.command)) {
|
|
126
|
+
return { ok: true, decision: { kind: "command", command: raw.command.trim() } };
|
|
127
|
+
}
|
|
128
|
+
return bad("invalid_value", 'Use "learn", "skip", "keep", or {"command": "<one line>"}.');
|
|
129
|
+
}
|
|
130
|
+
if (key === "epic_server" && isPlainObject(raw)) {
|
|
131
|
+
if (!onlyKeys(raw, ["mode", "sandbox_id", "credential_ref", "storefront_origin"]) || raw.mode !== "sfcc_shared_active") {
|
|
132
|
+
return bad("invalid_value", 'Use "keep", "none", "local", or an sfcc_shared_active object.');
|
|
133
|
+
}
|
|
134
|
+
const origin = normalizeStorefrontOrigin(raw.storefront_origin);
|
|
135
|
+
if (!isValidSfccSandboxId(raw.sandbox_id) || !isValidCredentialReference(raw.credential_ref) || origin === null) {
|
|
136
|
+
return bad("invalid_value", "The sfcc_shared_active answer needs a valid sandbox_id, credential_ref, and storefront_origin.");
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
ok: true,
|
|
140
|
+
decision: {
|
|
141
|
+
kind: "epic_server_sfcc",
|
|
142
|
+
value: { mode: "sfcc_shared_active", sandbox_id: raw.sandbox_id, credential_ref: raw.credential_ref, storefront_origin: origin },
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (typeof raw !== "string")
|
|
147
|
+
return bad("invalid_value", "This answer must be one of the option ids the assessment lists.");
|
|
148
|
+
if (!OPTION_VOCABULARY[key].includes(raw))
|
|
149
|
+
return bad("invalid_value", "This answer is not an option id for this key.");
|
|
150
|
+
return option(raw);
|
|
151
|
+
}
|
|
152
|
+
/** Map existing per-choice flags onto the same decisions the answers make. */
|
|
153
|
+
export function flagDecisions(flags) {
|
|
154
|
+
const out = {};
|
|
155
|
+
if (flags.testCommand !== undefined)
|
|
156
|
+
out.test_command = { kind: "command", command: flags.testCommand.trim() };
|
|
157
|
+
if (flags.epicBranchCiDecision === "include")
|
|
158
|
+
out.epic_branch_ci = { kind: "option", option: "include" };
|
|
159
|
+
if (flags.epicBranchCiDecision === "decline")
|
|
160
|
+
out.epic_branch_ci = { kind: "decline" };
|
|
161
|
+
if (flags.launchProfile !== undefined)
|
|
162
|
+
out.launch_profile = { kind: "option", option: "save" };
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/** The option ids a choice will take right now. `keep`/`decline` are always acceptable on a settled choice. */
|
|
166
|
+
function acceptsOption(choice, id) {
|
|
167
|
+
if (choice.options.some((o) => o.id === id))
|
|
168
|
+
return true;
|
|
169
|
+
if (!choice.applicable)
|
|
170
|
+
return id === "keep" || id === "decline" || choice.effects?.[id] !== undefined;
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Recommended decision for an omitted non-consequential choice, or null when there is none.
|
|
175
|
+
*
|
|
176
|
+
* BAPI-1654 compatibility: a STATED `epic_branch_ci` answer (`include` or
|
|
177
|
+
* `decline`) keeps its effect and its hash. An OMITTED one takes the current
|
|
178
|
+
* recommendation, which is now `include` or `decline` wherever the inspection
|
|
179
|
+
* ran, so its digest can change on purpose. Only a run with no inspection
|
|
180
|
+
* evidence still records nothing (`no_decision`).
|
|
181
|
+
*/
|
|
182
|
+
function recommendedDecision(choice) {
|
|
183
|
+
const rec = choice.recommended;
|
|
184
|
+
if (Array.isArray(rec))
|
|
185
|
+
return { kind: "selection", ids: [...rec].sort() };
|
|
186
|
+
if (rec === null) {
|
|
187
|
+
// Epic-branch CI with uncertain coverage: record nothing (runs behave as include). Never decline.
|
|
188
|
+
return choice.answer_key === "epic_branch_ci" ? { kind: "option", option: "no_decision" } : null;
|
|
189
|
+
}
|
|
190
|
+
return rec === "decline" ? { kind: "decline" } : { kind: "option", option: rec };
|
|
191
|
+
}
|
|
192
|
+
function sameDecision(a, b) {
|
|
193
|
+
return canonicalJson(a) === canonicalJson(b);
|
|
194
|
+
}
|
|
195
|
+
/** The structured effect a decision has, from the choice's own effects. Never prose. */
|
|
196
|
+
function effectFor(key, choice, decision) {
|
|
197
|
+
if (decision.kind === "decline")
|
|
198
|
+
return null;
|
|
199
|
+
if (key === "reindex_branch" && decision.kind === "option")
|
|
200
|
+
return REINDEX_BRANCH_EFFECTS[decision.option] ?? null;
|
|
201
|
+
if (key === "reindex_retry" && decision.kind === "option")
|
|
202
|
+
return REINDEX_RETRY_EFFECTS[decision.option] ?? null;
|
|
203
|
+
const effects = choice?.effects ?? {};
|
|
204
|
+
switch (decision.kind) {
|
|
205
|
+
case "option":
|
|
206
|
+
return decision.option === "keep" || decision.option === "skip" || decision.option === "no_decision"
|
|
207
|
+
? null
|
|
208
|
+
: effects[decision.option] ?? null;
|
|
209
|
+
case "selection":
|
|
210
|
+
return effects.select !== undefined ? { ...effects.select, params: { ...(effects.select.params ?? {}), selected: decision.ids } } : null;
|
|
211
|
+
case "reference":
|
|
212
|
+
return effects.reference !== undefined ? { ...effects.reference, params: { reference: decision.reference } } : null;
|
|
213
|
+
case "command":
|
|
214
|
+
return { action: "qualify_owner_test_command", target: "repository_gate.local_commands", params: { command: decision.command }, condition: "only_if_check_passes" };
|
|
215
|
+
case "epic_server_sfcc":
|
|
216
|
+
return effects.sfcc_shared_active !== undefined
|
|
217
|
+
? { ...effects.sfcc_shared_active, params: { ...decision.value } }
|
|
218
|
+
: null;
|
|
219
|
+
case "profile":
|
|
220
|
+
return { action: "write_launch_profile", target: "launch_profile", params: { name: decision.name } };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function intentOf(decision, effect) {
|
|
224
|
+
if (decision.kind === "decline")
|
|
225
|
+
return "decline";
|
|
226
|
+
if (decision.kind === "selection" && decision.ids.length === 0)
|
|
227
|
+
return "write";
|
|
228
|
+
return effect === null ? "keep" : "write";
|
|
229
|
+
}
|
|
230
|
+
function consequenceOf(choice, decision) {
|
|
231
|
+
if (choice === undefined)
|
|
232
|
+
return "Applied only if fresh recovery evidence still shows this question.";
|
|
233
|
+
const id = decision.kind === "option" ? decision.option
|
|
234
|
+
: decision.kind === "decline" ? "decline"
|
|
235
|
+
: decision.kind === "reference" ? "reference"
|
|
236
|
+
: decision.kind === "epic_server_sfcc" ? "sfcc_shared_active"
|
|
237
|
+
: null;
|
|
238
|
+
if (decision.kind === "selection") {
|
|
239
|
+
return decision.ids.length === 0
|
|
240
|
+
? "Workers get Bridge only; an earlier grant is replaced by an empty one."
|
|
241
|
+
: `Workers also get the ${decision.ids.length} selected server${decision.ids.length === 1 ? "" : "s"}.`;
|
|
242
|
+
}
|
|
243
|
+
if (decision.kind === "command")
|
|
244
|
+
return "Bridge proves your command with one bounded check and stores it only if it passes.";
|
|
245
|
+
return choice.options.find((o) => o.id === id)?.consequence ?? "Nothing changes.";
|
|
246
|
+
}
|
|
247
|
+
const DEPENDS_ON = Object.freeze({
|
|
248
|
+
dependency_install: ["gate"],
|
|
249
|
+
ci_database: ["gate"],
|
|
250
|
+
must_order_paths: ["gate"],
|
|
251
|
+
worker_database: ["gate"],
|
|
252
|
+
test_command: ["gate"],
|
|
253
|
+
setup_pr: ["test_command"],
|
|
254
|
+
reindex_branch: ["reindex"],
|
|
255
|
+
reindex_retry: ["reindex"],
|
|
256
|
+
approval_exemption: ["epic_branch_ci"],
|
|
257
|
+
// BAPI-1659: `epic_ci_change` has no dependency. It opens its own pull request, so a declined
|
|
258
|
+
// setup pull request never blocks it, and the test-command dependency stays on `setup_pr` alone.
|
|
259
|
+
});
|
|
260
|
+
/**
|
|
261
|
+
* Validate the whole answers object against the assessment, merge the flags,
|
|
262
|
+
* and build the normalized proposal and its digest. Nothing here writes.
|
|
263
|
+
*/
|
|
264
|
+
export function normalizeInstallAnswers(input) {
|
|
265
|
+
const reasons = [];
|
|
266
|
+
const add = (reason, key, detail) => {
|
|
267
|
+
const existing = reasons.find((r) => r.reason === reason && r.detail === detail);
|
|
268
|
+
if (existing !== undefined)
|
|
269
|
+
existing.keys.push(key);
|
|
270
|
+
else
|
|
271
|
+
reasons.push({ reason, keys: [key], detail });
|
|
272
|
+
};
|
|
273
|
+
const envelope = input.envelope ?? {};
|
|
274
|
+
const stated = new Map();
|
|
275
|
+
for (const [rawKey, rawValue] of Object.entries(envelope)) {
|
|
276
|
+
if (rawKey === "proposal_digest")
|
|
277
|
+
continue;
|
|
278
|
+
if (!isInstallAnswerKey(rawKey)) {
|
|
279
|
+
// The key name is reported only when it is short and plain; never a value.
|
|
280
|
+
add("unknown_key", /^[a-z_]{1,40}$/.test(rawKey) ? rawKey : "(unnamed)", "This key is not an answer key.");
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const parsed = parseAnswerValue(rawKey, rawValue);
|
|
284
|
+
if (!parsed.ok) {
|
|
285
|
+
add(parsed.reason, rawKey, parsed.detail);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const choice = choiceFor(input.choices, rawKey);
|
|
289
|
+
const conditional = CONDITIONAL_ANSWER_KEYS.includes(rawKey);
|
|
290
|
+
if (choice === undefined && !conditional) {
|
|
291
|
+
add("option_not_offered", rawKey, "The assessment offers no choice for this key here.");
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (choice !== undefined) {
|
|
295
|
+
const d = parsed.decision;
|
|
296
|
+
const optionId = d.kind === "option" ? d.option : d.kind === "decline" ? "decline" : d.kind === "reference" ? "reference"
|
|
297
|
+
: d.kind === "epic_server_sfcc" ? "sfcc_shared_active" : null;
|
|
298
|
+
if (optionId !== null && !acceptsOption(choice, optionId)) {
|
|
299
|
+
add("option_not_offered", rawKey, "This option is not one the assessment offers for this key.");
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (d.kind === "selection") {
|
|
303
|
+
const offered = new Set(choice.options.map((o) => o.id).filter((id) => id !== "decline" && id !== "keep"));
|
|
304
|
+
if (!d.ids.every((id) => offered.has(id))) {
|
|
305
|
+
add("option_not_offered", rawKey, "The selection names a server that is not offered.");
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
stated.set(rawKey, parsed.decision);
|
|
311
|
+
}
|
|
312
|
+
const flags = flagDecisions(input.flags);
|
|
313
|
+
for (const [key, flagDecision] of Object.entries(flags)) {
|
|
314
|
+
const answer = stated.get(key);
|
|
315
|
+
if (answer !== undefined && !sameDecision(answer, flagDecision)) {
|
|
316
|
+
add("flag_conflict", key, "A flag and the answers file disagree for this key.");
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// BAPI-1659: the recommendation for an omitted, non-consequential choice is resolved from the
|
|
320
|
+
// answers and flags just settled. A received answer is never reinterpreted: only `recommended`
|
|
321
|
+
// and its reason change, and only for choices nobody answered.
|
|
322
|
+
const settledOption = (key) => {
|
|
323
|
+
const d = stated.get(key) ?? flags[key];
|
|
324
|
+
return d === undefined ? undefined : d.kind === "decline" ? "decline" : d.kind === "option" ? d.option : undefined;
|
|
325
|
+
};
|
|
326
|
+
const choices = resolveEpicBranchCiRecommendation(input.choices, settledOption, input.recommendationContext);
|
|
327
|
+
// Every applicable consequential choice must be stated (by answer or flag). Never defaulted.
|
|
328
|
+
const missing = [];
|
|
329
|
+
for (const choice of choices) {
|
|
330
|
+
if (!choice.consequential || !choice.applicable)
|
|
331
|
+
continue;
|
|
332
|
+
if (!stated.has(choice.answer_key) && flags[choice.answer_key] === undefined)
|
|
333
|
+
missing.push(choice.answer_key);
|
|
334
|
+
}
|
|
335
|
+
if (missing.length > 0) {
|
|
336
|
+
reasons.push({
|
|
337
|
+
reason: "missing_consequential",
|
|
338
|
+
keys: missing,
|
|
339
|
+
detail: "Each consequential choice must be stated as approve or decline (or an option id). Setup never defaults one.",
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
const decisions = [];
|
|
343
|
+
const actions = [];
|
|
344
|
+
for (const key of INSTALL_ANSWER_KEYS) {
|
|
345
|
+
const choice = choiceFor(choices, key);
|
|
346
|
+
let decision;
|
|
347
|
+
let source;
|
|
348
|
+
if (stated.has(key)) {
|
|
349
|
+
decision = stated.get(key);
|
|
350
|
+
source = "answer";
|
|
351
|
+
}
|
|
352
|
+
else if (flags[key] !== undefined) {
|
|
353
|
+
decision = flags[key];
|
|
354
|
+
source = "flag";
|
|
355
|
+
}
|
|
356
|
+
else if (choice !== undefined && !(choice.consequential && choice.applicable)) {
|
|
357
|
+
decision = recommendedDecision(choice) ?? undefined;
|
|
358
|
+
source = "recommended";
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (decision === undefined)
|
|
364
|
+
continue;
|
|
365
|
+
const consequential = choice?.consequential ?? CONDITIONAL_ANSWER_KEYS.includes(key);
|
|
366
|
+
decisions.push({ key, decision, source, consequential });
|
|
367
|
+
const effect = effectFor(key, choice, decision);
|
|
368
|
+
actions.push({
|
|
369
|
+
key,
|
|
370
|
+
intent: intentOf(decision, effect),
|
|
371
|
+
consequential,
|
|
372
|
+
effect,
|
|
373
|
+
consequence: consequenceOf(choice, decision),
|
|
374
|
+
depends_on: DEPENDS_ON[key] ?? [],
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
const proposal = {
|
|
378
|
+
version: INSTALL_PROPOSAL_DIGEST_VERSION,
|
|
379
|
+
identity: { ...input.identity },
|
|
380
|
+
decisions,
|
|
381
|
+
actions,
|
|
382
|
+
};
|
|
383
|
+
const digest = computeProposalDigest(proposal);
|
|
384
|
+
if (input.mode === "apply") {
|
|
385
|
+
const supplied = envelope.proposal_digest;
|
|
386
|
+
if (supplied === undefined) {
|
|
387
|
+
reasons.push({ reason: "digest_missing", keys: ["proposal_digest"], detail: "An answers apply needs the proposal_digest proposal mode returned." });
|
|
388
|
+
}
|
|
389
|
+
else if (typeof supplied !== "string" || !DIGEST_RE.test(supplied)) {
|
|
390
|
+
reasons.push({ reason: "invalid_value", keys: ["proposal_digest"], detail: "proposal_digest must be the 64-character hex digest proposal mode returned." });
|
|
391
|
+
}
|
|
392
|
+
else if (supplied !== digest && reasons.every((r) => r.reason === "missing_consequential" && r.keys.includes("epic_ci_change"))) {
|
|
393
|
+
// BAPI-1659: a saved envelope from before the CI change was independently offered cannot
|
|
394
|
+
// name it. It is stale, not incomplete: refuse it as a digest mismatch so nothing is
|
|
395
|
+
// prompted for, defaulted, or inferred from the setup answer.
|
|
396
|
+
reasons.length = 0;
|
|
397
|
+
reasons.push({
|
|
398
|
+
reason: "digest_mismatch",
|
|
399
|
+
keys: ["proposal_digest"],
|
|
400
|
+
detail: "The answers no longer match what setup would do now: the repository, destination, credential binding, " +
|
|
401
|
+
"an offered option, or a target changed since the proposal was shown.",
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
else if (supplied !== digest && reasons.length === 0) {
|
|
405
|
+
reasons.push({
|
|
406
|
+
reason: "digest_mismatch",
|
|
407
|
+
keys: ["proposal_digest"],
|
|
408
|
+
detail: "The answers no longer match what setup would do now: the repository, destination, credential binding, " +
|
|
409
|
+
"an offered option, or a target changed since the proposal was shown.",
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (reasons.length > 0) {
|
|
414
|
+
return {
|
|
415
|
+
ok: false,
|
|
416
|
+
refusal: { reasons, fix: RERUN_FIX },
|
|
417
|
+
...(input.mode === "proposal" ? { proposal, digest } : {}),
|
|
418
|
+
choices,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return { ok: true, proposal, digest, choices };
|
|
422
|
+
}
|
|
423
|
+
// ---------------------------------------------------------------------------
|
|
424
|
+
// The digest
|
|
425
|
+
// ---------------------------------------------------------------------------
|
|
426
|
+
/**
|
|
427
|
+
* Canonical JSON: object keys sorted, arrays kept in the order their owner
|
|
428
|
+
* gives (unordered collections are sorted where they are built), `undefined`
|
|
429
|
+
* dropped, `null` kept. Omission, `null`, and `[]` stay distinct.
|
|
430
|
+
*/
|
|
431
|
+
export function canonicalJson(value) {
|
|
432
|
+
if (value === null)
|
|
433
|
+
return "null";
|
|
434
|
+
if (Array.isArray(value))
|
|
435
|
+
return `[${value.map((v) => (v === undefined ? "null" : canonicalJson(v))).join(",")}]`;
|
|
436
|
+
if (typeof value === "object") {
|
|
437
|
+
const entries = Object.entries(value)
|
|
438
|
+
.filter(([, v]) => v !== undefined)
|
|
439
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
440
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
441
|
+
}
|
|
442
|
+
return JSON.stringify(value);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* The structure the digest covers: identity, every normalized decision, and each
|
|
446
|
+
* action's target and structured effect. It leaves out every shown sentence,
|
|
447
|
+
* the decision's source, timestamps, readiness, and current or completed state,
|
|
448
|
+
* so a replay after the work is done hashes the same.
|
|
449
|
+
*/
|
|
450
|
+
export function digestInput(proposal) {
|
|
451
|
+
return {
|
|
452
|
+
version: proposal.version,
|
|
453
|
+
identity: proposal.identity,
|
|
454
|
+
decisions: proposal.decisions.map((d) => ({ key: d.key, decision: d.decision, consequential: d.consequential })),
|
|
455
|
+
actions: proposal.actions.map((a) => ({ key: a.key, intent: a.intent, effect: a.effect, depends_on: a.depends_on })),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
/** SHA-256 hex of the canonical digest input. */
|
|
459
|
+
export function computeProposalDigest(proposal) {
|
|
460
|
+
return createHash("sha256").update(canonicalJson(digestInput(proposal)), "utf-8").digest("hex");
|
|
461
|
+
}
|
|
462
|
+
/** The decision for a key in a proposal, or undefined. */
|
|
463
|
+
export function decisionFor(proposal, key) {
|
|
464
|
+
return proposal?.decisions.find((d) => d.key === key)?.decision;
|
|
465
|
+
}
|