@bridge_gpt/mcp-server 0.2.73 → 0.2.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +12 -0
  3. package/build/agents.generated.js +3 -3
  4. package/build/bridge-config.js +7 -1
  5. package/build/bridge-permissions.js +3 -0
  6. package/build/command-provisioning.js +4 -3
  7. package/build/commands.generated.js +5 -5
  8. package/build/conductor/bridge-api-client.js +26 -1
  9. package/build/conductor/command-drift.js +1 -1
  10. package/build/conductor/declared-extras.js +335 -0
  11. package/build/conductor/doctor.js +2 -0
  12. package/build/conductor/driver-pass-output.js +104 -0
  13. package/build/conductor/driver-pass.js +571 -0
  14. package/build/conductor/epic-branch-ci-inspection.js +61 -16
  15. package/build/conductor/epic-implementer-cli.js +33 -0
  16. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  17. package/build/conductor/epic-server-sfcc.js +58 -80
  18. package/build/conductor/epic-server.js +57 -4
  19. package/build/conductor/gate-discovery.js +46 -6
  20. package/build/conductor/gate-settings-review.js +51 -14
  21. package/build/credential-delivery.js +280 -0
  22. package/build/credential-launch-safety.js +142 -0
  23. package/build/credential-materialization.js +91 -16
  24. package/build/credential-references-node-deps.js +29 -0
  25. package/build/credential-references.js +1394 -0
  26. package/build/credential-references.test-fixtures.js +211 -0
  27. package/build/credential-scan-conventions.js +145 -0
  28. package/build/credential-scan.js +517 -0
  29. package/build/credential-store.js +50 -0
  30. package/build/credentials-cli.js +252 -3
  31. package/build/dependency-install-declarations.js +47 -1
  32. package/build/docs.generated.js +8 -1
  33. package/build/doctor.js +41 -0
  34. package/build/drive-epic.js +297 -37
  35. package/build/epic-branch-ci-summary.js +18 -1
  36. package/build/epic-capability-statement.js +71 -3
  37. package/build/epic-ci-workflow-drift.js +52 -13
  38. package/build/epic-ci-workflow-install.js +31 -6
  39. package/build/epic-ci-workflow-v3.js +273 -0
  40. package/build/epic-ci-workflow.js +128 -7
  41. package/build/epic-implementer-bin.js +161 -70
  42. package/build/epic-launch-context.js +102 -7
  43. package/build/epic-server-record.js +30 -15
  44. package/build/executor/credential-delivery-step.js +168 -0
  45. package/build/executor/deps.js +3 -1
  46. package/build/executor/env.js +39 -1
  47. package/build/executor/epic-server-context.js +23 -7
  48. package/build/executor/guarded-fast-forward-push.js +13 -8
  49. package/build/executor/job-runner.js +159 -17
  50. package/build/executor/permissions.js +85 -3
  51. package/build/executor/prompt-spec.js +37 -3
  52. package/build/executor-launch.js +4 -2
  53. package/build/git-exclude-lock.js +187 -0
  54. package/build/index.js +398 -269
  55. package/build/install-bridge-conductor-answers.js +84 -21
  56. package/build/install-bridge-conductor-apply.js +30 -1
  57. package/build/install-bridge-conductor-assessment.js +375 -48
  58. package/build/install-bridge-conductor-compact.js +27 -2
  59. package/build/install-bridge-conductor-contracts.js +10 -1
  60. package/build/install-bridge-conductor-gate.js +124 -11
  61. package/build/install-bridge-conductor-setup.js +46 -8
  62. package/build/install-bridge-conductor.js +625 -113
  63. package/build/install-bridge.js +88 -11
  64. package/build/install-doctor.js +38 -8
  65. package/build/install-sfcc-detection.js +120 -0
  66. package/build/install-sfcc-setup.js +185 -0
  67. package/build/mcp-grant-candidates.js +108 -96
  68. package/build/mcp-invoke.js +168 -4
  69. package/build/mcp-provisioning.js +21 -4
  70. package/build/mcp-server-invocation.js +13 -0
  71. package/build/merge-workflow-install.js +9 -1
  72. package/build/pipelines.generated.js +2 -1
  73. package/build/plane/status.js +8 -2
  74. package/build/printed-remedy-commands.js +5 -0
  75. package/build/project-root.js +40 -0
  76. package/build/readme.generated.js +1 -1
  77. package/build/repository-state-paths.js +5 -2
  78. package/build/repository-toolchains.js +6 -3
  79. package/build/setup-epic.js +116 -15
  80. package/build/sfcc/credentials.js +3 -2
  81. package/build/sfcc/hostname.js +98 -2
  82. package/build/sfcc/tool-wrapper.js +6 -95
  83. package/build/start-tickets.js +193 -29
  84. package/build/test-support/executor-source-files.js +200 -0
  85. package/build/testing-config-client.js +25 -2
  86. package/build/third-party-mcp-targets.js +35 -4
  87. package/build/version.generated.js +3 -3
  88. package/build/with-credentials.js +208 -0
  89. package/build/worktree-credential-delivery.js +340 -0
  90. package/package.json +1 -1
@@ -1,23 +1,26 @@
1
1
  /**
2
- * SFCC shared-active-version mode (BAPI-1546).
2
+ * SFCC shared-active-version policy (BAPI-1546, reworked by BAPI-1669).
3
3
  *
4
- * There is no local server and no turns. The run uses the ONE sandbox approved
5
- * at setup. The driver uploads the epic's code, branched from base, onto that
6
- * sandbox's active code version at run start; each worker uploads its own
7
- * branch's changes onto the same active version as it works. Briefly seeing
8
- * other workers' changes is accepted.
4
+ * There is no local server and no turns in `sfcc_shared_active` mode. The run
5
+ * uses the ONE sandbox approved at setup. The driver uploads the whole cartridge
6
+ * tree at the epic head at run start (`epic-server sfcc-upload --full`) and
7
+ * records a baseline. Each worker uploads only the cartridge files its branch
8
+ * changed (`epic-server sfcc-upload --ticket <KEY> --head <SHA>`) onto the same
9
+ * code version as it works. Briefly seeing other workers' changes is accepted.
9
10
  *
10
- * Uploads go through the granted SFCC MCP or CLI, which resolves the sandbox
11
- * account's credential reference outside every worktree. No credential value is
12
- * ever an argument here, and none reaches a prompt, the tally, or evidence.
11
+ * Upload is independent of the epic-server mode: it needs only an approved
12
+ * sandbox in the record. The mode only picks where browser checks run. A `head`
13
+ * in upload evidence names the source commit of THIS invocation's uploaded files.
14
+ * It is not proof that the whole shared version equals that commit.
13
15
  *
14
- * The testable rules live here, behind injected uploader and check seams, and
15
- * the worker prompt states them from these same constants:
16
+ * No credential value is ever an argument, and none reaches a prompt, the tally,
17
+ * or evidence. The testable rules live in `epic-server-sfcc-upload.ts`. The
18
+ * worker prompt states the same rules from the constants below:
16
19
  *
17
20
  * - every check runs after the worker's OWN upload;
18
21
  * - a failed check is retried exactly ONCE, after a FRESH upload;
19
22
  * - evidence is labeled `shared_active_version` and carries each upload's
20
- * start and end time;
23
+ * code version, source head, and start and end time;
21
24
  * - a failed upload is a missing server (`no_live_server`, hand-off eligible);
22
25
  * - a check that still fails after the retry is a real verification failure
23
26
  * and is never relabeled unrunnable because the sandbox is shared.
@@ -28,80 +31,55 @@ export const SFCC_EVIDENCE_LABEL = "shared_active_version";
28
31
  export const SFCC_CHECK_RETRIES = 1;
29
32
  /** The hand-off cause for a failed upload. */
30
33
  export const SFCC_UPLOAD_FAILURE_CAUSE = "no_live_server";
31
- const SHA_RE = /^[0-9a-f]{40}$/;
34
+ /** The pinned b2c CLI used when the repository has no local bin. */
35
+ export const SFCC_B2C_CLI_PINNED_PACKAGE = "@salesforce/b2c-cli@2.10.2";
36
+ /** The minimum Node version for the pinned npx fallback. */
37
+ export const SFCC_B2C_NPX_MIN_NODE = "22.16.0";
38
+ // Worker form: cumulative b2c budget, per-call cap, and whole-command ceiling.
39
+ export const SFCC_UPLOAD_WORKER_BUDGET_SECONDS = 300;
40
+ export const SFCC_UPLOAD_WORKER_CALL_SECONDS = 120;
41
+ /** The longest a worker upload command can run before it prints. The prompt and the spawn env both use it. */
42
+ export const SFCC_UPLOAD_WORKER_COMMAND_SECONDS = 660;
43
+ // Full (driver) form.
44
+ export const SFCC_UPLOAD_FULL_BUDGET_SECONDS = 900;
45
+ export const SFCC_UPLOAD_FULL_CALL_SECONDS = 600;
46
+ export const SFCC_UPLOAD_FULL_COMMAND_SECONDS = 1020;
47
+ // Lock.
48
+ export const SFCC_UPLOAD_LOCK_WAIT_SECONDS = 300;
49
+ export const SFCC_UPLOAD_FULL_LOCK_WAIT_SECONDS = 60;
50
+ export const SFCC_UPLOAD_LOCK_POLL_SECONDS = 2;
51
+ export const SFCC_UPLOAD_LOCK_MAX_HOLD_SECONDS = 960;
52
+ /** The largest one archive may be before any b2c mutation. */
53
+ export const SFCC_UPLOAD_MAX_ARCHIVE_BYTES = 64 * 1024 * 1024;
54
+ /** The most remote deletes one worker run sends. */
55
+ export const SFCC_UPLOAD_MAX_WORKER_DELETES = 50;
32
56
  /**
33
- * Run one SFCC check under the shared-active-version rules: upload, check, and
34
- * only if that check fails, one fresh upload and exactly one retry. The upload
35
- * always targets the APPROVED sandbox; a request for any other sandbox is refused.
57
+ * The shared upload sentences, for both the SFCC and the local-with-sandbox
58
+ * worker texts so they never drift. Single-line, and free of `;`, quotes, and
59
+ * apostrophes, like the other launch-prompt instructions.
36
60
  */
37
- export async function runSfccSharedActiveCheck(input) {
38
- if (input.sandboxId !== input.approved.sandbox_id)
39
- return { outcome: "refused", reason: "sandbox_mismatch" };
40
- if (!SHA_RE.test(input.head))
41
- return { outcome: "refused", reason: "invalid_head" };
42
- const evidence = {
43
- label: SFCC_EVIDENCE_LABEL,
44
- sandbox_id: input.approved.sandbox_id,
45
- worker_head: input.head,
46
- uploads: [],
47
- check_attempts: 0,
48
- first_check: "not_run",
49
- };
50
- const upload = async () => {
51
- const started = input.now().toISOString();
52
- let ok = false;
53
- try {
54
- ok = (await input.uploader.upload({
55
- sandbox_id: input.approved.sandbox_id,
56
- credential_ref: input.approved.credential_ref,
57
- head: input.head,
58
- })).ok;
59
- }
60
- catch {
61
- ok = false;
62
- }
63
- evidence.uploads.push({ started_at: started, ended_at: input.now().toISOString(), ok });
64
- return ok;
65
- };
66
- const check = async () => {
67
- evidence.check_attempts += 1;
68
- try {
69
- return (await input.check.run()).passed;
70
- }
71
- catch {
72
- return false;
73
- }
74
- };
75
- if (!(await upload()))
76
- return { outcome: "unavailable", cause: SFCC_UPLOAD_FAILURE_CAUSE, evidence };
77
- const first = await check();
78
- evidence.first_check = first ? "passed" : "failed";
79
- if (first)
80
- return { outcome: "passed", evidence };
81
- for (let retry = 0; retry < SFCC_CHECK_RETRIES; retry++) {
82
- // The retry follows a FRESH upload of the worker's own head.
83
- if (!(await upload()))
84
- return { outcome: "unavailable", cause: SFCC_UPLOAD_FAILURE_CAUSE, evidence };
85
- if (await check())
86
- return { outcome: "passed", evidence };
87
- }
88
- // Still failing after the retry: a real failure, never relabeled unrunnable.
89
- return { outcome: "failed", evidence };
61
+ export function buildSfccUploadWorkerText(ticketKey, commandSeconds) {
62
+ return ("Commit your work first. Before each e2e_tests or rendered_ui_review check, run " +
63
+ "epic-implementer epic-server sfcc-upload --ticket " + ticketKey + " --head <your full head SHA> through the " +
64
+ "epic-implementer launcher on your PATH, in the foreground, with a command timeout of at least " + commandSeconds +
65
+ " seconds. It uploads only the cartridge files your branch changed onto the shared sandbox code version. " +
66
+ "Outcome uploaded or nothing_to_upload means run the check. That is permission to run it and not proof that it passes. " +
67
+ "Never upload any other way and never put a credential value in a command. Other workers upload onto the same " +
68
+ "version, so if a check fails, rerun the upload once and retry that check exactly " + SFCC_CHECK_RETRIES +
69
+ " time, no more. Label the step evidence " + SFCC_EVIDENCE_LABEL + " and record each upload code_version, head, " +
70
+ "and start and end times. Any other upload outcome means rerun the same command once as the corrected invocation. " +
71
+ "If that also fails, record the step escalated with a hand-off whose cause is " + SFCC_UPLOAD_FAILURE_CAUSE +
72
+ ", quoting the command, its output, and your head SHA. Nothing parks for this. A check that still fails after " +
73
+ "the retry is a real verification failure. Record it as failed and never relabel it unrunnable because the " +
74
+ "sandbox is shared.");
90
75
  }
91
76
  /**
92
77
  * The SFCC worker paragraph, generated from the constants above so the prompt
93
78
  * and the rules cannot drift. Single-line, and free of `;`, quotes, and
94
- * apostrophes, like the other launch-prompt instructions.
79
+ * apostrophes.
95
80
  */
96
- export function buildSfccWorkerPolicyText(origin) {
81
+ export function buildSfccWorkerPolicyText(origin, ticketKey, commandSeconds) {
97
82
  return ("Epic server, SFCC shared active version: there is no local epic server and there are no turns. " +
98
- "Browser checks run against the approved sandbox storefront at " + origin + ". Before each e2e_tests " +
99
- "or rendered_ui_review check, upload your own branch changes onto the sandbox active code version through " +
100
- "the granted SFCC MCP or CLI, never with a credential value in a command. Other workers upload onto the " +
101
- "same version, so if a check fails, do one fresh upload of your own head and retry that check exactly " +
102
- SFCC_CHECK_RETRIES + " time, no more. Label the step evidence " + SFCC_EVIDENCE_LABEL + " and record each " +
103
- "upload start and end time and your head SHA. If an upload fails, that is an unavailable server: record the " +
104
- "step escalated with a hand-off whose cause is " + SFCC_UPLOAD_FAILURE_CAUSE + " under the hand-off rules " +
105
- "above. A check that still fails after the retry is a real verification failure. Record it as failed and " +
106
- "never relabel it unrunnable because the sandbox is shared.");
83
+ "Browser checks run against the approved sandbox storefront at " + origin + ". " +
84
+ buildSfccUploadWorkerText(ticketKey, commandSeconds));
107
85
  }
@@ -15,6 +15,12 @@
15
15
  *
16
16
  * epic-server turn acquire --ticket <KEY> --head <SHA> --wait <seconds>
17
17
  * epic-server turn release --lease <handle>
18
+ * epic-server sfcc-upload --ticket <KEY> --head <SHA>
19
+ *
20
+ * SFCC upload verbs (BAPI-1669; work in any epic-server mode):
21
+ *
22
+ * epic-server sfcc-upload --full --epic <KEY> --epic-run-id <id> --head <SHA> (driver)
23
+ * epic-server sfcc-upload --check (read-only)
18
24
  *
19
25
  * Intentional output is one JSON document on stdout; a failure is one sanitized
20
26
  * line on stderr. Exit codes are 0 and 1. Nothing printed ever carries a login,
@@ -42,7 +48,8 @@ import { fetchEpicRunState, resolveConductorBridgeApiAccess } from "./bridge-api
42
48
  import { readMcpGrant } from "../mcp-grant.js";
43
49
  import { PLAYWRIGHT_PRESET_NAME } from "../mcp-presets.js";
44
50
  export { readEpicServerRecord, writeEpicServerRecord, validateEpicServerRecord, } from "../epic-server-record.js";
45
- export { SFCC_CHECK_RETRIES, SFCC_EVIDENCE_LABEL, runSfccSharedActiveCheck, buildSfccWorkerPolicyText, } from "./epic-server-sfcc.js";
51
+ export { SFCC_CHECK_RETRIES, SFCC_EVIDENCE_LABEL, buildSfccUploadWorkerText, buildSfccWorkerPolicyText, } from "./epic-server-sfcc.js";
52
+ import { createDefaultSfccUploadDeps, runSfccUpload, } from "./epic-server-sfcc-upload.js";
46
53
  /** The private helper launch action. Absent from usage. */
47
54
  export const EPIC_SERVER_HELPER_ACTION = "__helper";
48
55
  /** Default and ceiling for a worker's bounded turn wait. */
@@ -63,6 +70,10 @@ export function getEpicServerUsage() {
63
70
  "Worker verbs (run id from BRIDGE_EPIC_SERVER_RUN_ID):",
64
71
  " turn acquire --ticket <KEY> --head <SHA> --wait <seconds>",
65
72
  " turn release --lease <handle>",
73
+ "SFCC verbs:",
74
+ " sfcc-upload --ticket <KEY> --head <SHA> Upload this branch's changed cartridge files (worker)",
75
+ " sfcc-upload --full --epic <KEY> --epic-run-id <id> --head <SHA> Upload the whole cartridge tree and record a baseline (driver)",
76
+ " sfcc-upload --check Say, with no network call, whether upload is possible",
66
77
  ].join("\n");
67
78
  }
68
79
  const TICKET_RE = /^[A-Z][A-Z0-9_]{0,19}-\d{1,9}$/;
@@ -154,6 +165,43 @@ export function parseEpicServerArgs(argv) {
154
165
  }
155
166
  return bad("turn takes acquire or release");
156
167
  }
168
+ case "sfcc-upload": {
169
+ const malformed = "sfcc-upload takes exactly one of: --ticket <KEY> --head <SHA> | --full --epic <KEY> --epic-run-id <id> --head <SHA> | --check";
170
+ if (rest.length === 0)
171
+ return bad(malformed);
172
+ if (rest.includes("--check")) {
173
+ // Status-style: `--json` is accepted and ignored. Nothing else may be mixed in.
174
+ const others = rest.filter((arg) => arg !== "--check" && arg !== "--json");
175
+ if (others.length !== 0 || rest.filter((a) => a === "--check").length !== 1 || rest.filter((a) => a === "--json").length > 1)
176
+ return bad(malformed);
177
+ return { verb: "sfcc-upload", upload: { form: "check" } };
178
+ }
179
+ if (rest[0] === "--full") {
180
+ const flags = readFlags(rest.slice(1), ["--epic", "--epic-run-id", "--head"]);
181
+ if (flags === null || flags.size !== 3)
182
+ return bad(malformed);
183
+ const epicKey = flags.get("--epic");
184
+ const epicRunId = flags.get("--epic-run-id");
185
+ const head = flags.get("--head");
186
+ if (!isValidEpicKey(epicKey))
187
+ return bad("--epic is not a usable epic key");
188
+ if (!isValidEpicRunId(epicRunId))
189
+ return bad("--epic-run-id is not a usable run id");
190
+ if (!isFullCommitSha(head))
191
+ return bad("--head must be a full 40-character commit SHA");
192
+ return { verb: "sfcc-upload", upload: { form: "full", epicKey, epicRunId, head } };
193
+ }
194
+ const flags = readFlags(rest, ["--ticket", "--head"]);
195
+ if (flags === null || flags.size !== 2)
196
+ return bad(malformed);
197
+ const ticket = flags.get("--ticket");
198
+ const head = flags.get("--head");
199
+ if (!TICKET_RE.test(ticket))
200
+ return bad("--ticket is not a usable ticket key");
201
+ if (!isFullCommitSha(head))
202
+ return bad("--head must be a full 40-character commit SHA");
203
+ return { verb: "sfcc-upload", upload: { form: "worker", ticket, head } };
204
+ }
157
205
  case EPIC_SERVER_HELPER_ACTION: {
158
206
  const flags = readFlags(rest, ["--epic", "--epic-run-id", "--head", "--repo-name", "--repo-root"]);
159
207
  if (flags === null || flags.size !== 5)
@@ -340,7 +388,8 @@ async function requireLocalMode(deps, verb) {
340
388
  return { ok: false, code: 1 };
341
389
  }
342
390
  if (record.record.mode === "sfcc_shared_active") {
343
- deps.stderr(`epic-server ${verb}: this repository uses the SFCC shared active version; there is no local helper or turn`);
391
+ deps.stderr(`epic-server ${verb}: this repository uses the SFCC shared active version; it has no local helper or turn. ` +
392
+ "Uploads use epic-server sfcc-upload, which works in any mode");
344
393
  return { ok: false, code: 1 };
345
394
  }
346
395
  return { ok: true, repoName };
@@ -398,7 +447,7 @@ async function runStart(deps, cmd) {
398
447
  async function runMode(deps) {
399
448
  const repoName = await deps.resolveRepoName();
400
449
  if (repoName === null) {
401
- emit(deps, { mode: "unknown", playwright_grant: "unknown" });
450
+ emit(deps, { mode: "unknown", playwright_grant: "unknown", sfcc_sandbox: "unknown" });
402
451
  return 0;
403
452
  }
404
453
  let record;
@@ -409,7 +458,9 @@ async function runMode(deps) {
409
458
  record = { state: "unusable" };
410
459
  }
411
460
  const mode = record.state === "ok" ? record.record.mode : record.state === "absent" ? "none" : "unknown";
412
- emit(deps, { mode, playwright_grant: await deps.readPlaywrightGrant(repoName) });
461
+ // Value-free: whether the record approves a sandbox, never a field of it.
462
+ const sfccSandbox = record.state === "ok" ? (record.record.sfcc !== undefined ? "approved" : "absent") : record.state === "absent" ? "absent" : "unknown";
463
+ emit(deps, { mode, playwright_grant: await deps.readPlaywrightGrant(repoName), sfcc_sandbox: sfccSandbox });
413
464
  return 0;
414
465
  }
415
466
  async function runStatus(deps, cmd) {
@@ -582,6 +633,8 @@ export async function runEpicServerCommand(argv, deps = createDefaultEpicServerC
582
633
  return await runAcquire(deps, cmd);
583
634
  case "release":
584
635
  return await runRelease(deps, cmd);
636
+ case "sfcc-upload":
637
+ return await runSfccUpload(cmd.upload, (deps.sfccUpload ?? createDefaultSfccUploadDeps)(deps));
585
638
  case "helper":
586
639
  return await runHelper(deps, cmd);
587
640
  }
@@ -57,6 +57,7 @@ import { describeCheckEvidence } from "../check-evidence.js";
57
57
  import fs from "node:fs/promises";
58
58
  import path from "node:path";
59
59
  import { LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV } from "../epic-implementer-env.js";
60
+ import { deriveDeclaredExtras } from "./declared-extras.js";
60
61
  import { MAX_MUST_ORDER_PATHS, canonicalMustOrderPaths, isValidMustOrderPath, } from "../dependency-install-declarations.js";
61
62
  import { TOOLCHAIN_CONTENT_FILES, installArgvForJavaScript, installArgvForPython, resolveRepositoryToolchains, } from "../repository-toolchains.js";
62
63
  // ---------------------------------------------------------------------------
@@ -1225,7 +1226,12 @@ export async function proposeWorkerDatabase(fsSeam) {
1225
1226
  return undefined;
1226
1227
  }
1227
1228
  /** BAPI-1551 — the root dependency-refresh proposals and the notes on what was left out. */
1228
- export async function proposeDependencyInstall(fsSeam) {
1229
+ export async function proposeDependencyInstall(fsSeam,
1230
+ /**
1231
+ * BAPI-1677 — the learned-text snapshot extras are worked out from. Absent means no
1232
+ * derivation was asked for. `null` means the text could not be read: a limitation.
1233
+ */
1234
+ options = {}) {
1229
1235
  let resolution;
1230
1236
  try {
1231
1237
  resolution = await resolveRepositoryToolchains(toolchainReader(fsSeam));
@@ -1248,13 +1254,33 @@ export async function proposeDependencyInstall(fsSeam) {
1248
1254
  });
1249
1255
  }
1250
1256
  const py = resolution.toolchains.python;
1257
+ let limitations = [];
1258
+ let unknown = false;
1251
1259
  if (py !== null) {
1252
1260
  if (py.manager === "pip")
1253
1261
  notes.push("dependency_install_pip_not_proposed");
1254
- else
1255
- candidates.push({ cwd: ".", argv: installArgvForPython(py), lockfiles: [py.dependencyFile], label: py.manager });
1262
+ else {
1263
+ // The install target is resolved first: its own file, never a union across projects.
1264
+ const derived = options.learned === undefined
1265
+ ? null
1266
+ : await deriveDeclaredExtras({ manager: py.manager, cwd: ".", baseArgvLength: installArgvForPython(py).length }, options.learned, (relPath) => readBounded(fsSeam, relPath));
1267
+ limitations = derived?.notes ?? [];
1268
+ unknown = derived !== null && !derived.complete;
1269
+ candidates.push({
1270
+ cwd: ".",
1271
+ argv: installArgvForPython(py, derived?.extras ?? []),
1272
+ lockfiles: [py.dependencyFile],
1273
+ label: py.manager,
1274
+ ...(derived !== null && derived.evidence.length > 0 ? { extraEvidence: derived.evidence } : {}),
1275
+ });
1276
+ }
1256
1277
  }
1257
- return { candidates, notes };
1278
+ return {
1279
+ candidates,
1280
+ notes,
1281
+ ...(limitations.length > 0 ? { limitations } : {}),
1282
+ ...(unknown ? { unknown: true } : {}),
1283
+ };
1258
1284
  }
1259
1285
  async function collectWorkflows(fsSeam, evidence, lookups, extras) {
1260
1286
  const entries = await fsSeam.listDir(WORKFLOWS_DIR);
@@ -1565,7 +1591,7 @@ export async function discoverGate(input) {
1565
1591
  const localCommandIds = providerChecks.length > 0 ? [] : validLocal.filter((c) => c.confidence === "high").map((c) => c.id);
1566
1592
  const workerEnv = resolveWorkerEnv(extras.envObservations);
1567
1593
  const hints = await proposeReproductionHints(fsSeam, providerChecks, extras.hintJobs);
1568
- const dependencyInstall = await proposeDependencyInstall(fsSeam);
1594
+ const dependencyInstall = await proposeDependencyInstall(fsSeam, input.learned !== undefined ? { learned: input.learned } : {});
1569
1595
  const mustOrder = await proposeMustOrderPaths(fsSeam);
1570
1596
  return {
1571
1597
  providerCandidates,
@@ -1594,7 +1620,7 @@ export async function discoverGate(input) {
1594
1620
  export async function discoverDeclarations(input) {
1595
1621
  const extras = { envObservations: [], hintJobs: new Map(), workflowFiles: [] };
1596
1622
  await collectWorkflows(input.fs, [], new LookupNames(), extras);
1597
- const dependencyInstall = await proposeDependencyInstall(input.fs);
1623
+ const dependencyInstall = await proposeDependencyInstall(input.fs, input.learned !== undefined ? { learned: input.learned } : {});
1598
1624
  const mustOrder = await proposeMustOrderPaths(input.fs);
1599
1625
  return declarationFields(dependencyInstall, proposeCiDatabase(input.providerChecks, extras.workflowFiles), mustOrder, await proposeWorkerDatabase(input.fs));
1600
1626
  }
@@ -1608,6 +1634,8 @@ function declarationFields(dependencyInstall, ciDatabase, mustOrder, workerDatab
1608
1634
  ...(workerDatabase !== undefined ? { workerDatabaseProposal: workerDatabase } : {}),
1609
1635
  ...(dependencyInstall.candidates.length > 0 ? { dependencyInstallCandidates: dependencyInstall.candidates } : {}),
1610
1636
  ...(dependencyInstall.notes.length > 0 ? { dependencyInstallNotes: dependencyInstall.notes } : {}),
1637
+ ...(dependencyInstall.limitations !== undefined ? { dependencyInstallLimitations: dependencyInstall.limitations } : {}),
1638
+ ...(dependencyInstall.unknown === true ? { dependencyInstallUnknown: true } : {}),
1611
1639
  ...(ciDatabase.value !== "unknown" ? { ciDatabaseProposal: ciDatabase } : {}),
1612
1640
  ...(mustOrder.candidates.length > 0 ? { mustOrderPathCandidates: mustOrder.candidates } : {}),
1613
1641
  ...(mustOrder.overflow > 0 ? { mustOrderPathOverflow: mustOrder.overflow } : {}),
@@ -1673,3 +1701,15 @@ async function proposeReproductionHints(fsSeam, reportedChecks, hintJobs) {
1673
1701
  }
1674
1702
  return { proposed, skipped };
1675
1703
  }
1704
+ /**
1705
+ * BAPI-1677 — the test commands the repository's own files name, without any provider
1706
+ * lookup. The same collectors, in the same order, as {@link discoverGate}.
1707
+ */
1708
+ export async function discoverLocalTestCandidates(fsSeam) {
1709
+ const evidence = [];
1710
+ const localCandidates = [];
1711
+ await collectPackageJson(fsSeam, evidence, localCandidates);
1712
+ await collectMakefile(fsSeam, evidence, localCandidates);
1713
+ await collectPython(fsSeam, evidence, localCandidates);
1714
+ return localCandidates.filter((c) => isGateCommandName(c.name));
1715
+ }
@@ -37,6 +37,7 @@
37
37
  * untouched setting is omitted from the write, so the server keeps what it has;
38
38
  * an empty `workerEnv` list is a deliberate removal of every stored variable.
39
39
  */
40
+ import { redactSecretString } from "./redaction.js";
40
41
  import { LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./gate-discovery.js";
41
42
  import { CI_DATABASE_DEFAULT, MAX_DEPENDENCY_INSTALL_ENTRIES, MAX_DEPENDENCY_INSTALL_LOCKFILES, MAX_MUST_ORDER_PATHS, admitDependencyInstallDeclarations, canonicalMustOrderPaths, dependencyInstallEntryIdentity, isCiDatabase, isSafeRepoRelativePath, sameDependencyInstall, sameMustOrderPaths, } from "../dependency-install-declarations.js";
42
43
  /** Limits that mirror `gate_profile.py` for hand-typed hints. */
@@ -53,6 +54,14 @@ const MAX_REVIEW_ATTEMPTS = 3;
53
54
  * formatting characters are written as `\u{hex}`. Nothing is truncated; callers
54
55
  * pass values already bounded by the validated input limits.
55
56
  */
57
+ /**
58
+ * BAPI-1677 — text a person reads as it is, unquoted: credential shapes redacted and
59
+ * every control or bidirectional character removed. For values already known not to
60
+ * need the visible quoting of {@link terminalSafe}.
61
+ */
62
+ export function plainDisplayText(text) {
63
+ return redactSecretString(text).replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e\u2066-\u2069\ufeff]/g, "");
64
+ }
56
65
  export function terminalSafe(text) {
57
66
  let out = "";
58
67
  for (const ch of text) {
@@ -295,6 +304,36 @@ function newDependencyProposals(proposal, stored) {
295
304
  const storedList = stored?.dependency_install ?? [];
296
305
  return (proposal.dependencyInstallCandidates ?? []).filter((c) => !storedList.some((e) => dependencyInstallEqual([entryOf(c)], [e])));
297
306
  }
307
+ /**
308
+ * BAPI-1677 — the one rule for a proposal against a stored list. A proposed entry
309
+ * with a stored identity replaces it in place, a new identity is added at the end,
310
+ * and a stored entry the proposal does not name stays. Nothing is sorted.
311
+ *
312
+ * `additive` means every stored entry survives in its place, with the same trigger
313
+ * files and with its command only extended. Anything else is `replacing`.
314
+ */
315
+ export function mergeDependencyProposal(stored, proposed) {
316
+ const merged = stored.map(entryOf);
317
+ for (const candidate of proposed) {
318
+ const entry = entryOf(candidate);
319
+ const identity = dependencyInstallEntryIdentity(entry);
320
+ const at = merged.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
321
+ if (at === -1)
322
+ merged.push(entry);
323
+ else
324
+ merged[at] = entry;
325
+ }
326
+ const withinBounds = merged.length <= MAX_DEPENDENCY_INSTALL_ENTRIES;
327
+ if (dependencyInstallEqual(merged, [...stored]))
328
+ return { merged, drift: "same", withinBounds };
329
+ const additive = stored.every((before, index) => {
330
+ const after = merged[index];
331
+ return (JSON.stringify(after.lockfiles) === JSON.stringify(before.lockfiles) &&
332
+ after.cwd === before.cwd &&
333
+ before.argv.every((arg, at) => after.argv[at] === arg));
334
+ });
335
+ return { merged, drift: additive ? "additive" : "replacing", withinBounds };
336
+ }
298
337
  function entryOf(candidate) {
299
338
  return { cwd: candidate.cwd, argv: [...candidate.argv], lockfiles: [...candidate.lockfiles] };
300
339
  }
@@ -425,6 +464,10 @@ function describeDependencyEntry(entry, label, showValues) {
425
464
  lines.push(showValues
426
465
  ? ` runs: ${entry.argv.map(terminalSafe).join(" ")}`
427
466
  : " (the install command is shown only in a terminal)");
467
+ // BAPI-1677: why each extra is there, as the smallest matched text and its field.
468
+ for (const evidence of entry.extraEvidence ?? []) {
469
+ lines.push(` because ${evidence.field} says: ${plainDisplayText(evidence.span)}`);
470
+ }
428
471
  return lines;
429
472
  }
430
473
  /** BAPI-1551 (extended by BAPI-1580) — every declaration group with something to show. */
@@ -471,6 +514,9 @@ function renderDependencyAndCiReview(io, proposal, stored, showValues) {
471
514
  });
472
515
  for (const note of proposal.dependencyInstallNotes ?? [])
473
516
  io.log(` ${DEPENDENCY_NOTE_TEXT[note] ?? note}`);
517
+ for (const line of proposal.dependencyInstallLimitations ?? [])
518
+ io.log(` Could not check: ${plainDisplayText(line)}`);
519
+ io.log(" Each command runs in every fresh worker worktree, and again only when a file it names changes.");
474
520
  io.log(" Discovery looks at the repository root only, so it can miss a subdirectory project. Stored entries stay " +
475
521
  "as they are unless you change them; you can add a subdirectory entry by hand below.");
476
522
  io.log("");
@@ -898,20 +944,11 @@ export function recommendedSettingsSelection(proposal, stored, providerChecks) {
898
944
  }
899
945
  if (reproduce.size > 0)
900
946
  edit.reproduce = reproduce;
901
- const storedDeps = (stored?.dependency_install ?? []).map(entryOf);
902
- const deps = storedDeps.map(entryOf);
903
- for (const candidate of newDependencyProposals(proposal, stored)) {
904
- const entry = entryOf(candidate);
905
- const identity = dependencyInstallEntryIdentity(entry);
906
- const at = deps.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
907
- if (at === -1)
908
- deps.push(entry);
909
- else
910
- deps[at] = entry;
911
- }
912
- if (deps.length <= MAX_DEPENDENCY_INSTALL_ENTRIES && !dependencyInstallEqual(deps, storedDeps)) {
913
- edit.dependencyInstall = deps;
914
- }
947
+ // BAPI-1677: a safe default takes only additive drift. A change that drops or
948
+ // rewrites what is stored is the owner's decision, so it stays as stored here.
949
+ const deps = mergeDependencyProposal(stored?.dependency_install ?? [], proposal.dependencyInstallCandidates ?? []);
950
+ if (deps.withinBounds && deps.drift === "additive")
951
+ edit.dependencyInstall = deps.merged;
915
952
  const current = storedCiDatabase(stored);
916
953
  const proposedDb = proposedCiDatabase(proposal);
917
954
  if (proposedDb !== CI_DATABASE_DEFAULT && proposedDb !== current)