@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.
Files changed (181) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +15 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +30 -0
  6. package/build/ci-system-detection.js +50 -0
  7. package/build/ci-trigger-adapters.js +631 -0
  8. package/build/ci-trigger-install.js +106 -0
  9. package/build/codex-launcher-pin.js +33 -2
  10. package/build/codex-skill-adapter.js +3 -1
  11. package/build/command-host.js +33 -0
  12. package/build/command-provisioning.js +4 -3
  13. package/build/commands.generated.js +7 -6
  14. package/build/conductor/bridge-api-client.js +867 -35
  15. package/build/conductor/bring-up-facts.js +18 -5
  16. package/build/conductor/command-drift-production.js +42 -17
  17. package/build/conductor/command-drift.js +48 -1
  18. package/build/conductor/declare-blocked.js +554 -0
  19. package/build/conductor/declared-extras.js +335 -0
  20. package/build/conductor/doctor.js +108 -21
  21. package/build/conductor/driver-commands.js +141 -0
  22. package/build/conductor/driver-guard.js +277 -0
  23. package/build/conductor/driver-lapse.js +321 -0
  24. package/build/conductor/driver-pass-output.js +104 -0
  25. package/build/conductor/driver-pass.js +571 -0
  26. package/build/conductor/driver-register.js +176 -0
  27. package/build/conductor/driver-release.js +174 -0
  28. package/build/conductor/driver-session-state.js +315 -0
  29. package/build/conductor/epic-branch-ci-inspection.js +281 -43
  30. package/build/conductor/epic-implementer-cli.js +199 -15
  31. package/build/conductor/epic-server-database.js +162 -0
  32. package/build/conductor/epic-server-guidance.js +278 -0
  33. package/build/conductor/epic-server-journal.js +239 -0
  34. package/build/conductor/epic-server-processes.js +324 -0
  35. package/build/conductor/epic-server-recipe.js +397 -0
  36. package/build/conductor/epic-server-runtime.js +1207 -0
  37. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  38. package/build/conductor/epic-server-sfcc.js +85 -0
  39. package/build/conductor/epic-server-state.js +427 -0
  40. package/build/conductor/epic-server.js +647 -0
  41. package/build/conductor/gate-discovery.js +196 -11
  42. package/build/conductor/gate-settings-review.js +261 -4
  43. package/build/conductor/launch-need-probes.js +6 -53
  44. package/build/conductor/launch-plan.js +313 -156
  45. package/build/conductor/prerequisite-inputs.js +879 -45
  46. package/build/conductor/readiness-assessment.js +16 -1
  47. package/build/conductor/readiness-cli.js +20 -9
  48. package/build/conductor/readiness-prerequisites.js +28 -9
  49. package/build/conductor/readiness-sections.js +133 -126
  50. package/build/conductor/readiness.js +1 -1
  51. package/build/conductor/recovery-cli.js +13 -2
  52. package/build/conductor/tools.js +6 -5
  53. package/build/conductor/wait-run-attention.js +2 -2
  54. package/build/conductor/wait-run-cli.js +208 -22
  55. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  56. package/build/conductor/worker-setup-tally.js +27 -0
  57. package/build/credential-delivery.js +280 -0
  58. package/build/credential-launch-safety.js +142 -0
  59. package/build/credential-materialization.js +91 -16
  60. package/build/credential-references-node-deps.js +29 -0
  61. package/build/credential-references.js +1394 -0
  62. package/build/credential-references.test-fixtures.js +211 -0
  63. package/build/credential-scan-conventions.js +145 -0
  64. package/build/credential-scan.js +517 -0
  65. package/build/credential-store.js +121 -1
  66. package/build/credentials-cli.js +252 -3
  67. package/build/dependency-install-declarations.js +102 -1
  68. package/build/docs.generated.js +10 -3
  69. package/build/doctor.js +95 -3
  70. package/build/drive-epic-help.js +21 -2
  71. package/build/drive-epic.js +2095 -375
  72. package/build/engine-paths.js +20 -0
  73. package/build/epic-branch-ci-summary.js +157 -0
  74. package/build/epic-capability-statement.js +175 -0
  75. package/build/epic-ci-workflow-drift.js +77 -23
  76. package/build/epic-ci-workflow-install.js +137 -44
  77. package/build/epic-ci-workflow-v2.js +274 -0
  78. package/build/epic-ci-workflow-v3.js +273 -0
  79. package/build/epic-ci-workflow.js +165 -18
  80. package/build/epic-implementer-bin.js +2204 -56
  81. package/build/epic-launch-context.js +702 -0
  82. package/build/epic-server-record.js +288 -0
  83. package/build/epic-shared/bridge-client.js +11 -3
  84. package/build/escalation-reachability.js +43 -0
  85. package/build/executor/ci-fix-test-runs.js +334 -0
  86. package/build/executor/completion-contract.js +8 -1
  87. package/build/executor/credential-delivery-step.js +168 -0
  88. package/build/executor/deps.js +3 -1
  89. package/build/executor/env.js +98 -23
  90. package/build/executor/epic-server-context.js +157 -0
  91. package/build/executor/gate-qualification-job.js +127 -26
  92. package/build/executor/guarded-fast-forward-push.js +13 -8
  93. package/build/executor/http-client.js +52 -5
  94. package/build/executor/job-runner.js +577 -81
  95. package/build/executor/observation.js +8 -0
  96. package/build/executor/permissions.js +85 -3
  97. package/build/executor/pre-pr-checks.js +363 -0
  98. package/build/executor/prompt-spec.js +149 -3
  99. package/build/executor/reconcile-overlap-job.js +5 -3
  100. package/build/executor/required-work-diagnostics.js +4 -2
  101. package/build/executor/required-work-ledger.js +936 -38
  102. package/build/executor/results.js +58 -0
  103. package/build/executor/terminal-mutation.js +8 -0
  104. package/build/executor/worker-command.js +72 -3
  105. package/build/executor/worker-database-config.js +281 -0
  106. package/build/executor/worker-database-target.js +16 -12
  107. package/build/executor/worker-database.js +320 -101
  108. package/build/executor/worker-finalization.js +7 -1
  109. package/build/executor/worker-resources.js +25 -3
  110. package/build/executor/worker-verification-guidance.js +18 -3
  111. package/build/executor/worktree.js +20 -1
  112. package/build/executor-launch.js +58 -4
  113. package/build/generated-assets-catalog.js +2 -2
  114. package/build/git-exclude-lock.js +187 -0
  115. package/build/index.js +824 -366
  116. package/build/init.js +26 -11
  117. package/build/install-bridge-conductor-answers.js +528 -0
  118. package/build/install-bridge-conductor-apply.js +288 -0
  119. package/build/install-bridge-conductor-assessment.js +1222 -0
  120. package/build/install-bridge-conductor-compact.js +186 -0
  121. package/build/install-bridge-conductor-contracts.js +72 -0
  122. package/build/install-bridge-conductor-gate.js +1312 -198
  123. package/build/install-bridge-conductor-setup.js +577 -83
  124. package/build/install-bridge-conductor.js +3381 -544
  125. package/build/install-bridge.js +280 -25
  126. package/build/install-doctor.js +38 -8
  127. package/build/install-maintenance.js +26 -3
  128. package/build/install-sfcc-detection.js +120 -0
  129. package/build/install-sfcc-setup.js +185 -0
  130. package/build/launcher-config-inspection.js +162 -1
  131. package/build/mcp-grant-candidates.js +779 -0
  132. package/build/mcp-grant-doctor.js +63 -0
  133. package/build/mcp-grant.js +288 -0
  134. package/build/mcp-host-targets.js +8 -0
  135. package/build/mcp-identity.js +23 -0
  136. package/build/mcp-invoke.js +292 -15
  137. package/build/mcp-presets.js +107 -0
  138. package/build/mcp-provisioning.js +155 -6
  139. package/build/mcp-registration-doctor.js +31 -2
  140. package/build/mcp-server-invocation.js +19 -1
  141. package/build/merge-workflow-install.js +243 -110
  142. package/build/pipelines.generated.js +7 -6
  143. package/build/plan-discovery.js +97 -4
  144. package/build/plan-execution-ledger.js +100 -7
  145. package/build/plan-generation-io.js +262 -0
  146. package/build/plan-generation.js +424 -0
  147. package/build/plane/build-freshness.js +6 -1
  148. package/build/plane/cli.js +75 -9
  149. package/build/plane/plane-freshness.js +17 -0
  150. package/build/plane/preflight.js +50 -10
  151. package/build/plane/shutdown.js +19 -0
  152. package/build/plane/status.js +8 -2
  153. package/build/plane/terminal-run-cleanup.js +18 -4
  154. package/build/printed-remedy-commands.js +211 -12
  155. package/build/project-root.js +40 -0
  156. package/build/readiness-check.js +77 -0
  157. package/build/readiness-prerequisites.generated.js +122 -14
  158. package/build/readme.generated.js +1 -1
  159. package/build/repository-state-paths.js +41 -0
  160. package/build/repository-toolchains.js +6 -3
  161. package/build/run-unit-tests-launcher.js +8 -1
  162. package/build/setup-epic.js +1305 -210
  163. package/build/setup-progress.js +44 -0
  164. package/build/setup-question.js +122 -4
  165. package/build/sfcc/credentials.js +3 -2
  166. package/build/sfcc/hostname.js +98 -2
  167. package/build/sfcc/tool-wrapper.js +6 -95
  168. package/build/start-tickets.js +193 -29
  169. package/build/test-support/executor-source-files.js +200 -0
  170. package/build/testing-config-client.js +25 -2
  171. package/build/third-party-mcp-targets.js +63 -2
  172. package/build/ticket-delivery-enrollment.js +9 -0
  173. package/build/upgrade-cli.js +85 -2
  174. package/build/v2-readiness-requirements.js +28 -1
  175. package/build/version.generated.js +3 -3
  176. package/build/with-credentials.js +208 -0
  177. package/build/worktree-credential-delivery.js +340 -0
  178. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  179. package/docs/epic-implementer/getting-started.md +3 -1
  180. package/docs/epic-implementer/self-hosting.md +14 -1
  181. package/package.json +2 -2
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Reassurance during long setup work (BAPI-1604). A notice is printed on stderr
3
+ * every few seconds while an operation runs, so a quiet terminal is not mistaken
4
+ * for a hang. It is never a timeout, a retry, or a readiness condition: the
5
+ * operation's value or exception passes through untouched, and the notice stops
6
+ * on every completion path.
7
+ */
8
+ export const SETUP_PROGRESS_INTERVAL_MS = 10_000;
9
+ /** The real timer. The interval is unreferenced so it never holds the process open. */
10
+ export function createSetupProgressTimer() {
11
+ return {
12
+ now: () => Number(process.hrtime.bigint() / 1000000n),
13
+ start: (tick, intervalMs) => {
14
+ const handle = setInterval(tick, intervalMs);
15
+ handle.unref();
16
+ return () => clearInterval(handle);
17
+ },
18
+ };
19
+ }
20
+ /** `activity` is a fixed label such as `checking readiness`; it is never user data. */
21
+ export async function withSetupProgress(activity, operation, deps) {
22
+ const timer = deps.timer ?? createSetupProgressTimer();
23
+ const startedAt = timer.now();
24
+ let cancel;
25
+ try {
26
+ cancel = timer.start(() => {
27
+ const seconds = Math.round((timer.now() - startedAt) / 1000);
28
+ deps.errorLog(`Still ${activity} (${seconds} s)…`);
29
+ }, timer.intervalMs ?? SETUP_PROGRESS_INTERVAL_MS);
30
+ }
31
+ catch {
32
+ // A timer that cannot start must not change the operation.
33
+ cancel = undefined;
34
+ }
35
+ try {
36
+ return await operation();
37
+ }
38
+ finally {
39
+ try {
40
+ cancel?.();
41
+ }
42
+ catch { /* cancellation failure never masks the outcome */ }
43
+ }
44
+ }
@@ -1,9 +1,13 @@
1
- export function renderSetupQuestion(spec) {
2
- return [spec.purpose, `Current evidence:\n${spec.evidence.join("\n")}`,
1
+ /** Everything except the leading question line, built structurally. */
2
+ function renderSetupQuestionBody(spec) {
3
+ return [`Current evidence:\n${spec.evidence.join("\n")}`,
3
4
  `Options:\n${spec.options.map(o => `${o.id}: ${o.label}`).join("\n")}`,
4
5
  `Consequences:\n${spec.consequences.join("\n")}`,
5
6
  `Defer: ${spec.deferred}\nRecovery: ${spec.recovery}`].join("\n\n");
6
7
  }
8
+ export function renderSetupQuestion(spec) {
9
+ return [spec.purpose, renderSetupQuestionBody(spec)].join("\n\n");
10
+ }
7
11
  export function parseSetupDecision(input, options = []) {
8
12
  const value = input?.trim().toLowerCase();
9
13
  if (!value)
@@ -16,11 +20,13 @@ export function parseSetupDecision(input, options = []) {
16
20
  return option ? { status: "selected", id: option.id } : { status: "invalid" };
17
21
  }
18
22
  export async function askSetupQuestion(spec, terminal) {
19
- terminal.write?.(renderSetupQuestion(spec));
23
+ const question = spec.prompt ?? spec.purpose;
24
+ // The reader shows the question; print it here only when no reader will.
25
+ terminal.write?.(terminal.read ? renderSetupQuestionBody(spec) : [question, renderSetupQuestionBody(spec)].join("\n\n"));
20
26
  if (!terminal.read)
21
27
  return { status: "defer" };
22
28
  try {
23
- return parseSetupDecision(await terminal.read(spec.prompt ?? spec.purpose), spec.options);
29
+ return parseSetupDecision(await terminal.read(question), spec.options);
24
30
  }
25
31
  catch {
26
32
  return { status: "defer" };
@@ -60,3 +66,115 @@ export function setupConsentQuestion(purpose) {
60
66
  consequences: [consequence], deferred: "Only this operation is deferred; completed independent work is retained.",
61
67
  recovery: "Rerun setup interactively after resolving the affected prerequisite." };
62
68
  }
69
+ export const PLAIN_SETUP_INSTRUCTION = "Press Enter for the recommended option. Type ? for details.";
70
+ /** Invalid answers allowed after the first before the recommendation is used. */
71
+ export const PLAIN_SETUP_MAX_REASKS = 2;
72
+ /** A line ending pasted right behind an answer arrives within this window. */
73
+ export const PLAIN_SETUP_PASTE_TAIL_MS = 150;
74
+ /** Numbered options and the instruction, without the question line. */
75
+ function renderPlainSetupBody(spec) {
76
+ const lines = spec.options.map((o, i) => ` ${i + 1}. ${o.label}${o.id === spec.recommended ? " (recommended)" : ""}`);
77
+ return [...lines, ...(spec.summary ?? []), PLAIN_SETUP_INSTRUCTION].join("\n");
78
+ }
79
+ export function renderPlainSetupQuestion(spec) {
80
+ return [spec.question, renderPlainSetupBody(spec)].join("\n");
81
+ }
82
+ export function renderPlainSetupDetails(spec) {
83
+ return [`Current evidence:\n${spec.evidence.join("\n")}`,
84
+ ...(spec.consequences.length > 0 ? [`Consequences:\n${spec.consequences.join("\n")}`] : []),
85
+ `Recovery: ${spec.recovery}`].join("\n\n");
86
+ }
87
+ export function parsePlainSetupDecision(input, options) {
88
+ if (input === undefined)
89
+ return { status: "unavailable" };
90
+ const value = input.trim().toLowerCase();
91
+ if (!value)
92
+ return { status: "empty" };
93
+ if (value === "?")
94
+ return { status: "details" };
95
+ if (/^\d+$/.test(value)) {
96
+ const byNumber = options[Number(value) - 1];
97
+ return byNumber ? { status: "selected", id: byNumber.id } : { status: "invalid" };
98
+ }
99
+ const option = options.find(o => o.id.toLowerCase() === value
100
+ || (o.aliases ?? []).some(a => a.toLowerCase() === value));
101
+ return option ? { status: "selected", id: option.id } : { status: "invalid" };
102
+ }
103
+ /**
104
+ * Ask one plain question. Enter selects the recommendation; `?` shows details;
105
+ * an unavailable terminal defers (nothing is chosen) and prints the recording flag.
106
+ */
107
+ export async function askPlainSetupQuestion(spec, terminal) {
108
+ const deferUnavailable = () => {
109
+ terminal.write?.(`${spec.question}\nNo terminal is available, so nothing was chosen. To record this choice: ${spec.recordingFlag}`);
110
+ return { status: "defer" };
111
+ };
112
+ if (terminal.isTTY !== true || !terminal.read)
113
+ return deferUnavailable();
114
+ let invalid = 0;
115
+ for (;;) {
116
+ // The read prompt carries the question, so only the body is written.
117
+ terminal.write?.(renderPlainSetupBody(spec));
118
+ let parsed;
119
+ try {
120
+ parsed = parsePlainSetupDecision(await terminal.read(`${spec.question} `), spec.options);
121
+ }
122
+ catch {
123
+ return deferUnavailable();
124
+ }
125
+ if (parsed.status === "unavailable")
126
+ return deferUnavailable();
127
+ if (parsed.status === "empty")
128
+ return { status: "selected", id: spec.recommended };
129
+ if (parsed.status === "selected")
130
+ return parsed;
131
+ if (parsed.status === "details") {
132
+ terminal.write?.(renderPlainSetupDetails(spec));
133
+ continue;
134
+ }
135
+ invalid += 1;
136
+ if (invalid > PLAIN_SETUP_MAX_REASKS) {
137
+ terminal.write?.("That answer was not recognized, so the recommended option was used.");
138
+ return { status: "selected", id: spec.recommended };
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * Wrap one reader for one setup run. A pasted answer's trailing line ending can
144
+ * arrive as an immediate empty answer to the NEXT question; that one empty answer
145
+ * is dropped and the reader is asked again once. Non-empty input is never dropped,
146
+ * and only the previous answer's time and non-empty status are remembered.
147
+ */
148
+ export function createPlainInputSession(read, deps = {}) {
149
+ const now = deps.now ?? (() => Number(process.hrtime.bigint() / 1000000n));
150
+ const windowMs = deps.pasteTailMs ?? PLAIN_SETUP_PASTE_TAIL_MS;
151
+ let lastDoneAt;
152
+ let lastNonEmpty = false;
153
+ const finish = (answer) => {
154
+ lastDoneAt = now();
155
+ lastNonEmpty = (answer ?? "").trim().length > 0;
156
+ return answer;
157
+ };
158
+ return async (prompt) => {
159
+ let answer = await read(prompt);
160
+ if (answer !== undefined && answer.trim().length === 0 && lastNonEmpty
161
+ && lastDoneAt !== undefined && now() - lastDoneAt <= windowMs) {
162
+ answer = await read(prompt);
163
+ }
164
+ return finish(answer);
165
+ };
166
+ }
167
+ /** Plain consent for one operation. The safe default is `no` unless the caller says otherwise. */
168
+ export function plainConsentQuestion(purpose, recordingFlag, recommended = "no") {
169
+ const legacy = setupConsentQuestion(purpose);
170
+ return {
171
+ question: legacy.purpose,
172
+ options: [{ id: "yes", label: "Yes, do this", aliases: ["y"] }, { id: "no", label: "No, skip this", aliases: ["n"] }],
173
+ recommended, recordingFlag,
174
+ evidence: legacy.evidence, consequences: legacy.consequences, recovery: legacy.recovery,
175
+ };
176
+ }
177
+ export async function askPlainConsent(purpose, recordingFlag, terminal, recommended = "no") {
178
+ const decision = await askPlainSetupQuestion(plainConsentQuestion(purpose, recordingFlag, recommended), terminal);
179
+ return decision.status === "selected" && decision.id === "yes";
180
+ }
@@ -7,7 +7,7 @@
7
7
  * first-pick. Secret values (client_secret, tokens) are never included in
8
8
  * any returned or thrown string — only source and target are reported.
9
9
  */
10
- import { ensureGitInfoExcluded } from "../git-ignore-utils.js";
10
+ import { ensureGitInfoExcludedSerialized } from "../git-exclude-lock.js";
11
11
  import { canonicalizeSfccHostname, formatSafeHost } from "./hostname.js";
12
12
  import { readFile, writeFile, mkdir } from "fs/promises";
13
13
  import path from "path";
@@ -57,7 +57,8 @@ async function loadDwJson(deps) {
57
57
  const mk = deps.mkdir ?? ((p, opts) => mkdir(p, opts));
58
58
  // Ensure dw.json is excluded from git tracking.
59
59
  try {
60
- await ensureGitInfoExcluded(cwd, DW_JSON, { readFile: rf, writeFile: wf, mkdir: mk });
60
+ // BAPI-1647: serialized with every other Bridge exclude writer.
61
+ await ensureGitInfoExcludedSerialized(cwd, DW_JSON, { readFile: rf, writeFile: wf, mkdir: mk });
61
62
  }
62
63
  catch {
63
64
  // Non-fatal — continue even if we can't update .git/info/exclude.
@@ -3,8 +3,10 @@
3
3
  *
4
4
  * `canonicalizeSfccHostname` lives here so the target boundary
5
5
  * (`tool-wrapper.ts`), the credential resolver, and `check_permissions` all
6
- * canonicalize and display hosts the same way. `tool-wrapper.ts` re-exports it
7
- * so its public import surface is unchanged.
6
+ * canonicalize and display hosts the same way. It also owns the approved
7
+ * sandbox-host policy so the credential scan can reuse it without importing
8
+ * tool configuration or credential resolution. `tool-wrapper.ts` re-exports
9
+ * these so its public import surface is unchanged.
8
10
  */
9
11
  /** Longest hostname echoed in a diagnostic. */
10
12
  export const MAX_DIAGNOSTIC_HOST_LENGTH = 120;
@@ -65,3 +67,97 @@ export function formatSafeHost(raw) {
65
67
  ? `${canonical.slice(0, MAX_DIAGNOSTIC_HOST_LENGTH)}…`
66
68
  : canonical;
67
69
  }
70
+ // ---------------------------------------------------------------------------
71
+ // Sandbox host policy
72
+ // ---------------------------------------------------------------------------
73
+ /**
74
+ * The DNS suffix every approved sandbox form shares.
75
+ *
76
+ * Every SFCC developer-sandbox hostname evidenced anywhere in this repository —
77
+ * `credentials.ts`'s JSDoc, the install guide's prerequisites, the BAPI-399
78
+ * live smoke-test record, and the existing test fixtures — lives under this
79
+ * suffix. Legacy `*.demandware.net` hosts are deliberately NOT accepted: that
80
+ * domain covers sandbox, staging, development, and production instances alike
81
+ * with no suffix that separates them, so admitting it would reintroduce exactly
82
+ * the unbounded target this boundary exists to close. It appears in this repo
83
+ * only as a test fixture, never in production code or the SFCC install docs.
84
+ */
85
+ const SFCC_DX_SUFFIX = ".dx.commercecloud.salesforce.com";
86
+ /**
87
+ * First labels that name a non-sandbox environment on the B2C platform.
88
+ *
89
+ * Checked against the leading label of every candidate, so a host like
90
+ * `production-zzrf.dx.commercecloud.salesforce.com` or
91
+ * `staging-zzrf.sandbox.us01.dx.commercecloud.salesforce.com` is refused even
92
+ * though it would otherwise satisfy a form below. This is belt-and-braces: form
93
+ * B alone would already admit `production-001`, and a named production instance
94
+ * is precisely the target the ticket was filed about.
95
+ */
96
+ const RESERVED_ENVIRONMENT_LABELS = [
97
+ "production",
98
+ "prod",
99
+ "staging",
100
+ "stg",
101
+ "development",
102
+ ];
103
+ /**
104
+ * Human-readable description of every accepted form, for the refusal envelope
105
+ * and the documentation contract test. Keep in sync with
106
+ * `isApprovedSfccSandboxHost` — the tests assert both directions.
107
+ */
108
+ export const APPROVED_SANDBOX_HOST_FORMS = [
109
+ "<realm>-<nnn>.sandbox.<region>.dx.commercecloud.salesforce.com",
110
+ "<realm>-<nnn>.sandbox.dx.commercecloud.salesforce.com",
111
+ "<realm>-<nnn>.dx.commercecloud.salesforce.com",
112
+ ];
113
+ /** Form B's leading label: an SFCC realm id followed by a numeric instance. */
114
+ const REALM_INSTANCE_LABEL = /^[a-z0-9]+-\d{3}$/;
115
+ /**
116
+ * Decide whether a canonical hostname is an approved developer sandbox.
117
+ *
118
+ * Matching is ANCHORED on both ends: the host must END with the platform suffix
119
+ * and the labels in front of it must form one of the shapes below. This is the
120
+ * property a substring test lacks — `.includes(".sandbox.")` matches
121
+ * `zzzz-001.sandbox.evil.example.com`, whose registrable domain is not
122
+ * Salesforce's at all.
123
+ *
124
+ * Form A — explicit sandbox label, with or without a region:
125
+ * `zzzz-001.sandbox.us01.dx.commercecloud.salesforce.com`
126
+ * `zzzz-001.sandbox.dx.commercecloud.salesforce.com`
127
+ * Form B — realm + numeric instance, the on-demand sandbox form this project
128
+ * actually smoke-tested against (`docs/BAPI-399-sfcc-mcp-smoke-test.md`
129
+ * records sandbox `zyis-001`):
130
+ * `zyis-001.dx.commercecloud.salesforce.com`
131
+ *
132
+ * Form B is required for correctness, not convenience: without it the boundary
133
+ * would refuse the very sandbox this repository documents itself using, and a
134
+ * safety check that blocks the intended workflow gets disabled rather than
135
+ * obeyed. It is kept safe by requiring the `<realm>-<nnn>` shape (named
136
+ * environments such as `production-zzrf` do not match) and by the reserved-label
137
+ * check.
138
+ *
139
+ * Anything not matching — including every `*.demandware.net` host and any other
140
+ * registrable domain — is refused. Widening this set is a deliberate decision,
141
+ * not a bug fix: the ticket's Decision 1(b), an explicit per-instance opt-in, is
142
+ * the sanctioned way to reach an instance this policy does not recognize.
143
+ */
144
+ export function isApprovedSfccSandboxHost(canonical) {
145
+ if (!canonical.endsWith(SFCC_DX_SUFFIX))
146
+ return false;
147
+ const prefix = canonical.slice(0, -SFCC_DX_SUFFIX.length);
148
+ if (prefix === "")
149
+ return false;
150
+ const labels = prefix.split(".");
151
+ const first = labels[0];
152
+ for (const reserved of RESERVED_ENVIRONMENT_LABELS) {
153
+ if (first === reserved || first.startsWith(`${reserved}-`))
154
+ return false;
155
+ }
156
+ // Form A: <label>.sandbox[.<region>]
157
+ if ((labels.length === 2 || labels.length === 3) && labels[1] === "sandbox")
158
+ return true;
159
+ // Form B: <realm>-<nnn>
160
+ if (labels.length === 1 && REALM_INSTANCE_LABEL.test(first))
161
+ return true;
162
+ return false;
163
+ }
@@ -65,104 +65,15 @@ import { SFCC_VERSIONS, getSfccVersionConfig } from "./config.js";
65
65
  import { publishSfccVersion } from "./tools-configured.js";
66
66
  import { resolveSfccCredentials } from "./credentials.js";
67
67
  import { formatSfccFailure } from "./sfcc-result.js";
68
- import { canonicalizeSfccHostname, formatSafeHost } from "./hostname.js";
69
- // `canonicalizeSfccHostname` moved to hostname.ts; re-exported so existing
70
- // importers of this module are unaffected.
71
- export { canonicalizeSfccHostname };
68
+ import { APPROVED_SANDBOX_HOST_FORMS, canonicalizeSfccHostname, formatSafeHost, isApprovedSfccSandboxHost, } from "./hostname.js";
69
+ // `canonicalizeSfccHostname` and the sandbox-host policy moved to hostname.ts;
70
+ // re-exported so existing importers of this module are unaffected.
71
+ export { APPROVED_SANDBOX_HOST_FORMS, canonicalizeSfccHostname, isApprovedSfccSandboxHost };
72
72
  // ---------------------------------------------------------------------------
73
73
  // Hostname policy
74
74
  // ---------------------------------------------------------------------------
75
- /**
76
- * The DNS suffix every approved sandbox form shares.
77
- *
78
- * Every SFCC developer-sandbox hostname evidenced anywhere in this repository —
79
- * `credentials.ts`'s JSDoc, the install guide's prerequisites, the BAPI-399
80
- * live smoke-test record, and the existing test fixtures — lives under this
81
- * suffix. Legacy `*.demandware.net` hosts are deliberately NOT accepted: that
82
- * domain covers sandbox, staging, development, and production instances alike
83
- * with no suffix that separates them, so admitting it would reintroduce exactly
84
- * the unbounded target this boundary exists to close. It appears in this repo
85
- * only as a test fixture, never in production code or the SFCC install docs.
86
- */
87
- const SFCC_DX_SUFFIX = ".dx.commercecloud.salesforce.com";
88
- /**
89
- * First labels that name a non-sandbox environment on the B2C platform.
90
- *
91
- * Checked against the leading label of every candidate, so a host like
92
- * `production-zzrf.dx.commercecloud.salesforce.com` or
93
- * `staging-zzrf.sandbox.us01.dx.commercecloud.salesforce.com` is refused even
94
- * though it would otherwise satisfy a form below. This is belt-and-braces: form
95
- * B alone would already admit `production-001`, and a named production instance
96
- * is precisely the target the ticket was filed about.
97
- */
98
- const RESERVED_ENVIRONMENT_LABELS = [
99
- "production",
100
- "prod",
101
- "staging",
102
- "stg",
103
- "development",
104
- ];
105
- /**
106
- * Human-readable description of every accepted form, for the refusal envelope
107
- * and the documentation contract test. Keep in sync with
108
- * `isApprovedSfccSandboxHost` — the tests assert both directions.
109
- */
110
- export const APPROVED_SANDBOX_HOST_FORMS = [
111
- "<realm>-<nnn>.sandbox.<region>.dx.commercecloud.salesforce.com",
112
- "<realm>-<nnn>.sandbox.dx.commercecloud.salesforce.com",
113
- "<realm>-<nnn>.dx.commercecloud.salesforce.com",
114
- ];
115
- /** Form B's leading label: an SFCC realm id followed by a numeric instance. */
116
- const REALM_INSTANCE_LABEL = /^[a-z0-9]+-\d{3}$/;
117
- /**
118
- * Decide whether a canonical hostname is an approved developer sandbox.
119
- *
120
- * Matching is ANCHORED on both ends: the host must END with the platform suffix
121
- * and the labels in front of it must form one of the shapes below. This is the
122
- * property a substring test lacks — `.includes(".sandbox.")` matches
123
- * `zzzz-001.sandbox.evil.example.com`, whose registrable domain is not
124
- * Salesforce's at all.
125
- *
126
- * Form A — explicit sandbox label, with or without a region:
127
- * `zzzz-001.sandbox.us01.dx.commercecloud.salesforce.com`
128
- * `zzzz-001.sandbox.dx.commercecloud.salesforce.com`
129
- * Form B — realm + numeric instance, the on-demand sandbox form this project
130
- * actually smoke-tested against (`docs/BAPI-399-sfcc-mcp-smoke-test.md`
131
- * records sandbox `zyis-001`):
132
- * `zyis-001.dx.commercecloud.salesforce.com`
133
- *
134
- * Form B is required for correctness, not convenience: without it the boundary
135
- * would refuse the very sandbox this repository documents itself using, and a
136
- * safety check that blocks the intended workflow gets disabled rather than
137
- * obeyed. It is kept safe by requiring the `<realm>-<nnn>` shape (named
138
- * environments such as `production-zzrf` do not match) and by the reserved-label
139
- * check.
140
- *
141
- * Anything not matching — including every `*.demandware.net` host and any other
142
- * registrable domain — is refused. Widening this set is a deliberate decision,
143
- * not a bug fix: the ticket's Decision 1(b), an explicit per-instance opt-in, is
144
- * the sanctioned way to reach an instance this policy does not recognize.
145
- */
146
- export function isApprovedSfccSandboxHost(canonical) {
147
- if (!canonical.endsWith(SFCC_DX_SUFFIX))
148
- return false;
149
- const prefix = canonical.slice(0, -SFCC_DX_SUFFIX.length);
150
- if (prefix === "")
151
- return false;
152
- const labels = prefix.split(".");
153
- const first = labels[0];
154
- for (const reserved of RESERVED_ENVIRONMENT_LABELS) {
155
- if (first === reserved || first.startsWith(`${reserved}-`))
156
- return false;
157
- }
158
- // Form A: <label>.sandbox[.<region>]
159
- if ((labels.length === 2 || labels.length === 3) && labels[1] === "sandbox")
160
- return true;
161
- // Form B: <realm>-<nnn>
162
- if (labels.length === 1 && REALM_INSTANCE_LABEL.test(first))
163
- return true;
164
- return false;
165
- }
75
+ // The sandbox-host policy (`isApprovedSfccSandboxHost`,
76
+ // `APPROVED_SANDBOX_HOST_FORMS`) lives in hostname.ts and is re-exported above.
166
77
  /**
167
78
  * The one refusal envelope every SFCC tool returns for an unapproved target.
168
79
  *