@bridge_gpt/mcp-server 0.2.75 → 0.2.77

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 (94) hide show
  1. package/README.md +8 -6
  2. package/build/agents.generated.js +5 -5
  3. package/build/cli-dispatch.js +333 -0
  4. package/build/codex-auto-recovery.js +25 -7
  5. package/build/commands.generated.js +8 -8
  6. package/build/conductor/bridge-api-client.js +193 -13
  7. package/build/conductor/declare-blocked.js +146 -7
  8. package/build/conductor/driver-pass.js +8 -0
  9. package/build/conductor/driver-register.js +8 -2
  10. package/build/conductor/epic-implementer-cli.js +15 -10
  11. package/build/conductor/epic-server-journal.js +52 -22
  12. package/build/conductor/epic-server-recipe.js +15 -5
  13. package/build/conductor/epic-server-runtime.js +163 -45
  14. package/build/conductor/epic-server.js +13 -6
  15. package/build/conductor/install-doctor.js +30 -2
  16. package/build/conductor/launch-plan.js +28 -7
  17. package/build/conductor/local-merge.js +55 -13
  18. package/build/conductor/pr-ci-producer.js +12 -3
  19. package/build/conductor/readiness-prerequisites.js +89 -2
  20. package/build/conductor/readiness-sections.js +46 -13
  21. package/build/conductor/readiness.js +3 -40
  22. package/build/conductor/recovery-cli.js +14 -12
  23. package/build/conductor/repository-workflow-remedy.js +147 -7
  24. package/build/conductor/ui-readiness.js +224 -0
  25. package/build/conductor/wait-run-attention.js +9 -4
  26. package/build/conductor/wait-run-cli.js +9 -2
  27. package/build/docs.generated.js +67 -4
  28. package/build/doctor.js +97 -1
  29. package/build/drive-epic.js +625 -33
  30. package/build/engine-paths.js +10 -0
  31. package/build/epic-coherence-input-cli.js +105 -10
  32. package/build/epic-coherence-input.js +877 -4
  33. package/build/epic-coherence-input.test-fixtures.js +117 -0
  34. package/build/epic-implementer-bin.js +947 -120
  35. package/build/epic-implementer-env.js +2 -2
  36. package/build/epic-launch-context.js +8 -1
  37. package/build/epic-shared/cut-protocol.js +55 -3
  38. package/build/executor/completion-contract.js +14 -1
  39. package/build/executor/failure-reason-codes.js +2 -0
  40. package/build/executor/guarded-fast-forward-push.js +25 -2
  41. package/build/executor/integration-job.js +56 -2
  42. package/build/executor/job-runner.js +87 -28
  43. package/build/executor/likely-tests.js +78 -6
  44. package/build/executor/merge-job.js +45 -1
  45. package/build/executor/permissions.js +187 -2
  46. package/build/executor/provider-checks.js +101 -5
  47. package/build/executor/rebase-finalization.js +29 -27
  48. package/build/executor/reconcile-overlap-job.js +70 -17
  49. package/build/executor/rename-aside.js +265 -0
  50. package/build/executor/required-work-ledger.js +89 -6
  51. package/build/executor/resume-pre-spawn.js +32 -8
  52. package/build/executor/runner.js +26 -4
  53. package/build/executor/types.js +121 -0
  54. package/build/executor/worktree.js +39 -2
  55. package/build/index.js +2500 -495
  56. package/build/init.js +16 -0
  57. package/build/install-bridge-conductor-answers.js +4 -0
  58. package/build/install-bridge-conductor-apply.js +10 -0
  59. package/build/install-bridge-conductor-assessment.js +84 -0
  60. package/build/install-bridge-conductor-contracts.js +9 -1
  61. package/build/install-bridge-conductor-setup.js +103 -3
  62. package/build/install-bridge-conductor.js +440 -812
  63. package/build/install-bridge.js +4 -11
  64. package/build/language-catalog.generated.js +2649 -0
  65. package/build/mcp-host-config.js +54 -37
  66. package/build/phase-context-git-probe.js +16 -0
  67. package/build/pipelines.generated.js +47 -19
  68. package/build/plan-execution-ledger.js +35 -0
  69. package/build/plan-generation.js +34 -0
  70. package/build/plane/build-freshness.js +6 -0
  71. package/build/plane/cli.js +12 -5
  72. package/build/plane/plane-freshness.js +43 -26
  73. package/build/printed-remedy-commands.js +17 -0
  74. package/build/readiness-prerequisites.generated.js +28 -0
  75. package/build/readme.generated.js +1 -1
  76. package/build/run-unit-tests-launcher.js +3 -1
  77. package/build/secret-redaction.js +3 -0
  78. package/build/server.js +7946 -0
  79. package/build/setup-epic.js +41 -8
  80. package/build/start-tickets-prereqs.js +3 -6
  81. package/build/test-support/console-guard.js +30 -0
  82. package/build/test-support/create-preview-world.js +232 -0
  83. package/build/test-support/module-imports.js +155 -0
  84. package/build/test-support/server-client.js +96 -0
  85. package/build/test-support/stdio-server.js +146 -0
  86. package/build/ticket-delivery.js +65 -0
  87. package/build/v2-readiness-requirements.js +39 -5
  88. package/build/version.generated.js +3 -3
  89. package/build/worktree-core.js +51 -7
  90. package/docs/EPIC-IMPLEMENTER.md +150 -2
  91. package/docs/epic-implementer/getting-started.md +5 -1
  92. package/package.json +3 -3
  93. package/pipelines/implement-ticket.json +2 -2
  94. package/pipelines/learn-repository.json +19 -1
@@ -1,4 +1,5 @@
1
- import { CONSUMER_GUIDE_POINTER } from "../printed-remedy-commands.js";
1
+ import { CONSUMER_GUIDE_POINTER, PRINTED_CONDUCTOR_INSTALL_COMMAND, PRINTED_QUALIFY_GATE_COMMAND, READINESS_PREREQUISITE_FIXES, } from "../printed-remedy-commands.js";
2
+ import { quotedSubject } from "./readiness-sections.js";
2
3
  /** The two fixed workflow files unattended auto-merge reads. Named once here. */
3
4
  export const REVIEW_WORKFLOW_PATH = ".github/workflows/claude-review.yml";
4
5
  export const CI_WORKFLOW_PATH = ".github/workflows/epic-implementer-ci.yml";
@@ -9,12 +10,23 @@ export const MIGRATION_GUARD_INVOCATION = `python ${MIGRATION_GUARD_CHECKER_PATH
9
10
  const RETRY = "Retry readiness, or use --attended.";
10
11
  /** Every workflow remedy ends with the guide a consumer can actually install. */
11
12
  const GUIDE_SENTENCE = `See ${CONSUMER_GUIDE_POINTER}.`;
13
+ /**
14
+ * BAPI-1714 — the ONE fix sentence for a missing review marker, appended once
15
+ * however many markers are missing. Switching the default is the supported fix
16
+ * for a repository that does not want to edit its workflow.
17
+ */
18
+ const REVIEW_MARKER_FIX = `Switch the default with ${PRINTED_CONDUCTOR_INSTALL_COMMAND} --review-policy repository_policy, ` +
19
+ `or add the markers to ${REVIEW_WORKFLOW_PATH}, or pass --attended.`;
20
+ const REVIEW_MARKER_TOKENS = new Set([
21
+ "review_run_id_marker",
22
+ "review_reviewed_sha_marker",
23
+ ]);
12
24
  const TEMPLATES = {
13
25
  review_workflow_file: `${REVIEW_WORKFLOW_PATH} is missing from the default branch. Add it, or pass --attended.`,
14
- review_run_id_marker: `${REVIEW_WORKFLOW_PATH} does not emit the run-id: marker in its verdict comment. ` +
15
- "Add it, or pass --attended.",
16
- review_reviewed_sha_marker: `${REVIEW_WORKFLOW_PATH} does not emit the Reviewed-SHA: marker in its verdict comment. ` +
17
- "Add it, or pass --attended.",
26
+ // BAPI-1714: each marker template names only the missing marker. The one fix
27
+ // sentence both share is appended once by `build` (REVIEW_MARKER_FIX).
28
+ review_run_id_marker: `${REVIEW_WORKFLOW_PATH} does not emit the run-id: marker in its verdict comment.`,
29
+ review_reviewed_sha_marker: `${REVIEW_WORKFLOW_PATH} does not emit the Reviewed-SHA: marker in its verdict comment.`,
18
30
  review_workflow_unverifiable: `Bridge could not read ${REVIEW_WORKFLOW_PATH} on the default branch. ${RETRY}`,
19
31
  ci_workflow_file: `${CI_WORKFLOW_PATH} is missing from the default branch. Add it, or pass --attended.`,
20
32
  migration_guard_job: `${CI_WORKFLOW_PATH} has no job with id ${MIGRATION_GUARD_JOB_ID} running ${MIGRATION_GUARD_INVOCATION}. ` +
@@ -30,6 +42,127 @@ const TEMPLATES = {
30
42
  migration_guard_job_legacy: `${CI_WORKFLOW_PATH} has no job with id ${MIGRATION_GUARD_JOB_ID} running ${MIGRATION_GUARD_INVOCATION}. ` +
31
43
  "Add that job, or pass --attended.",
32
44
  };
45
+ /**
46
+ * Read the server's repository-readiness decision as one of three answers.
47
+ *
48
+ * A PURE reader of server decisions: no workflow inspection, no policy
49
+ * inference, no network access. `confirmed` when the server's aggregate flag is
50
+ * `true`. `denied` only when that flag is literally `false` AND the
51
+ * `repository_readiness` admission record says `denied` (a proven deficiency).
52
+ * Everything else is `unknown` — a missing block, a missing record, an
53
+ * `unable_to_verify` record, or an older server — and unknown is never an
54
+ * accusation. Unknown must not block a launch; first approval re-checks.
55
+ */
56
+ export function repositoryReadinessVerdict(readiness) {
57
+ const flag = readiness?.unattended?.repository_readiness_confirmed;
58
+ if (flag === true)
59
+ return "confirmed";
60
+ if (flag !== false)
61
+ return "unknown";
62
+ const records = readiness?.admission_evidence?.records;
63
+ if (!Array.isArray(records))
64
+ return "unknown";
65
+ const record = records.find((r) => r?.predicate === "repository_readiness");
66
+ return record?.verdict === "denied" ? "denied" : "unknown";
67
+ }
68
+ /**
69
+ * BAPI-1526 — the stored-gate-profile denials first approval judges exactly as the
70
+ * launch report does. A stored profile is judged by its own proofs on both sides,
71
+ * so a denial here is a denial at approval.
72
+ */
73
+ const REFUSING_GATE_PROFILE_REASONS = new Set([
74
+ "local_command_unqualified",
75
+ "provider_check_unseen",
76
+ "migration_guard_unset",
77
+ ]);
78
+ /**
79
+ * Read the server's `required_checks` admission record as `denied` or `other`.
80
+ *
81
+ * `denied` only when the block is schema version 1 and its `required_checks`
82
+ * record is a `denied` STORED-GATE-PROFILE record (`source: "gate_profile"`) for
83
+ * one of the closed gate-profile reasons above. Everything else is `other`: a
84
+ * `null` report, a missing block or record, another schema version, `confirmed`,
85
+ * `unable_to_verify`, `not_applicable`, and a repository-level denial such as
86
+ * `required_checks_empty` or `required_check_unknown_name`. That last group stays
87
+ * advisory: with no stored profile, first approval can stamp `no_ci_gate` or
88
+ * confirm plan-node checks the launch report never sees, so it may accept what
89
+ * the report denies. An unavailable record is never a confirmed denial. Read it
90
+ * only on the policy-aware launch report, where the server judged the create policy.
91
+ */
92
+ export function requiredChecksAdmissionVerdict(readiness) {
93
+ return requiredChecksDeniedRecord(readiness) === null ? "other" : "denied";
94
+ }
95
+ /** The denied `required_checks` record itself, or `null` (see `requiredChecksAdmissionVerdict`). */
96
+ export function requiredChecksDeniedRecord(readiness) {
97
+ const block = readiness?.admission_evidence;
98
+ if (block?.schema_version !== 1 || !Array.isArray(block.records))
99
+ return null;
100
+ const record = block.records.find((r) => r?.predicate === "required_checks");
101
+ if (record?.verdict !== "denied" || record.source !== "gate_profile")
102
+ return null;
103
+ if (typeof record.reason !== "string" || !REFUSING_GATE_PROFILE_REASONS.has(record.reason))
104
+ return null;
105
+ return {
106
+ reason: typeof record.reason === "string" ? record.reason : null,
107
+ subject: typeof record.subject === "string" ? record.subject : null,
108
+ };
109
+ }
110
+ /** The provider-evidence window the server searches, spelled once for the remedies. */
111
+ const PROVIDER_EVIDENCE_WINDOW = "the last 12 default-branch commits or 8 merged pull-request heads from the last 90 days";
112
+ /**
113
+ * BAPI-1390 — fixed remedies for the four gate-profile reasons. Everything is a
114
+ * literal except the validated `subject`. `null` for any other reason, so an
115
+ * unknown reason falls back to the owner's generic remedy.
116
+ *
117
+ * BAPI-1526 — moved here from `readiness.ts`, text unchanged, so the readiness
118
+ * row, the `drive-epic` preview refusal, and the `setup-epic` refusal share one
119
+ * wording without importing the advisory report.
120
+ */
121
+ export function gateProfileReasonRemedy(reason, verdict, subject) {
122
+ switch (reason) {
123
+ case "provider_check_unseen":
124
+ return (`a repository administrator confirms that the check ${quotedSubject(subject, "named in the gate profile")} ` +
125
+ `reports on the default branch — it was not seen on ${PROVIDER_EVIDENCE_WINDOW} — or edits the gate ` +
126
+ "profile; setup never grants it.");
127
+ case "provider_evidence_unavailable":
128
+ return (`Bridge could not read the provider's check history for ${quotedSubject(subject, "a gate-profile check")} ` +
129
+ `(${PROVIDER_EVIDENCE_WINDOW}), so it is unknown, not absent. Re-run readiness; if it persists, ` +
130
+ "email info@bridgegpt.ai.");
131
+ case "local_command_unqualified":
132
+ return verdict === "unable_to_verify"
133
+ ? `the qualification of the local gate command ${quotedSubject(subject, "in the gate profile")} could not ` +
134
+ "be read, so it is unknown, not qualified. Re-run readiness; if it persists, email info@bridgegpt.ai."
135
+ : `the local gate command ${quotedSubject(subject, "in the gate profile")} is not qualified for the current ` +
136
+ "gate-profile revision (unqualified or stale). Qualify it with " +
137
+ `\`${PRINTED_QUALIFY_GATE_COMMAND}\`, or have a repository administrator ` +
138
+ "edit the gate profile.";
139
+ case "migration_guard_unset":
140
+ return verdict === "unable_to_verify"
141
+ ? "Bridge could not confirm whether this repository has alembic.ini on its default branch, so it could " +
142
+ "not decide whether the gate profile needs a migration guard. Re-run readiness, or have a repository " +
143
+ "administrator set a migration guard in the gate profile."
144
+ : "this repository has alembic.ini on its default branch, so its gate profile must name a migration " +
145
+ "guard (a provider check or a local command). A repository administrator sets it in the gate " +
146
+ "profile; setup never grants it.";
147
+ default:
148
+ return null;
149
+ }
150
+ }
151
+ /**
152
+ * BAPI-1526 — the one wording for a denied `required_checks` record, shared by the
153
+ * `drive-epic` preview refusal and the `setup-epic` pre-create refusal. Built from
154
+ * `gateProfileReasonRemedy()`; an unknown reason falls back to the existing
155
+ * `supervisor_gate` text. `null` when the record is not a proven denial.
156
+ */
157
+ export function requiredChecksAdmissionRemedy(readiness) {
158
+ const record = requiredChecksDeniedRecord(readiness);
159
+ if (record === null)
160
+ return null;
161
+ const specific = gateProfileReasonRemedy(record.reason, "denied", record.subject);
162
+ return specific === null
163
+ ? `First approval would refuse this unattended run's required checks. ${READINESS_PREREQUISITE_FIXES.supervisor_gate}`
164
+ : `First approval would refuse this unattended run's required checks: ${specific}`;
165
+ }
33
166
  /** Shown when the report is missing, incomplete, or not in a shape we can name. */
34
167
  const UNVERIFIABLE_FALLBACK = `Bridge could not verify the review and CI workflows on the default branch. ${RETRY} ${GUIDE_SENTENCE}`;
35
168
  function classifyReview(w) {
@@ -102,8 +235,15 @@ export function describeRepositoryWorkflowRemedy(readiness) {
102
235
  return build("conductor_ci_workflow", ci);
103
236
  return { section: null, missing: [], text: "" };
104
237
  }
238
+ /** Fixed templates in token order, the shared marker fix once, then the guide. */
239
+ function renderTokens(missing) {
240
+ const parts = missing.map((token) => TEMPLATES[token]);
241
+ if (missing.some((token) => REVIEW_MARKER_TOKENS.has(token)))
242
+ parts.push(REVIEW_MARKER_FIX);
243
+ return `${parts.join(" ")} ${GUIDE_SENTENCE}`;
244
+ }
105
245
  function build(section, missing) {
106
- return { section, missing, text: `${missing.map((token) => TEMPLATES[token]).join(" ")} ${GUIDE_SENTENCE}` };
246
+ return { section, missing, text: renderTokens(missing) };
107
247
  }
108
248
  /**
109
249
  * The remedy sentence for a repository whose workflows are not confirmed. Never
@@ -123,5 +263,5 @@ export function ciWorkflowRemedy(c) {
123
263
  const tokens = classifyCi(c);
124
264
  if (tokens === "malformed" || tokens.length === 0)
125
265
  return UNVERIFIABLE_FALLBACK;
126
- return `${tokens.map((token) => TEMPLATES[token]).join(" ")} ${GUIDE_SENTENCE}`;
266
+ return renderTokens(tokens);
127
267
  }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * BAPI-1718: the advisory UI readiness of an epic launch preview.
3
+ *
4
+ * Before an epic starts, the owner should know when the epic builds UI but the
5
+ * AI workers may have no way to look at the pages. This module is the ONE owner of
6
+ * that rule and of its wording. It is pure, like `plan-generation.ts`: every input
7
+ * is injected, and nothing here reads a file, runs a process, opens a socket, reads
8
+ * the environment, calls a model, or logs. `drive-epic.ts` collects the facts and
9
+ * passes them in.
10
+ *
11
+ * The advisory only warns. It never refuses a launch, asks a question, parks a
12
+ * ticket, or changes a decision. Evidence it cannot read is `unknown`, never
13
+ * `none` and never "no browser". The result carries ticket keys and fixed text
14
+ * only: no description, path, command, argument, environment value, credential
15
+ * reference, or error text ever reaches it.
16
+ *
17
+ * Two questions are answered independently:
18
+ *
19
+ * - Does the epic change the UI? (`classifyUiWork`) Positive evidence is a cited
20
+ * rendered-UI file, the literal step names `e2e_tests` or `rendered_ui_review`,
21
+ * or a running plan node's `touched_files`. Prose such as "homepage" is not
22
+ * evidence. Any positive evidence wins; otherwise a failed required read makes
23
+ * the answer `unknown`; only complete, readable, unmatched evidence is `none`.
24
+ * - Can a worker see the pages? (`classifyUiVerification`) A recognized browser
25
+ * MCP server is approved for workers AND an epic server mode gives it a site.
26
+ */
27
+ import { TICKET_KEY_PATTERN } from "../ticket-key-utils.js";
28
+ import { BRIDGE_RESERVED_SERVER_NAMES } from "../mcp-grant.js";
29
+ import { isPlaywrightPresetEntry, PLAYWRIGHT_PRESET_NAME } from "../mcp-presets.js";
30
+ import { buildTrackedInventory, compareTicketKeys, extractTouchedFiles } from "../plan-generation.js";
31
+ export const UI_VERIFICATION_REASONS = [
32
+ "browser_mcp",
33
+ "no_epic_server",
34
+ "no_browser_mcp_or_epic_server",
35
+ "no_browser_mcp",
36
+ "unrecognized_mcp",
37
+ "unreadable",
38
+ ];
39
+ /** At most this many tickets are named as the source of UI work. */
40
+ export const UI_SOURCES_CAP = 20;
41
+ // ---------------------------------------------------------------------------
42
+ // The rendered-UI file rule
43
+ // ---------------------------------------------------------------------------
44
+ /** A path with one of these segments is never rendered UI. Whole segments only. */
45
+ const EXCLUDED_SEGMENTS = new Set([
46
+ "test", "tests", "__tests__", "spec", "e2e", "node_modules", "docs", ".github",
47
+ ]);
48
+ /** Extensions that are rendered UI wherever they live (outside an excluded segment). */
49
+ const ALWAYS_UI_SUFFIXES = new Set([
50
+ ".html", ".htm", ".jinja", ".jinja2", ".j2", ".njk", ".hbs", ".handlebars", ".mustache", ".ejs", ".pug",
51
+ ".isml", ".vue", ".svelte", ".astro", ".jsx", ".tsx", ".css", ".scss", ".sass", ".less", ".styl",
52
+ ]);
53
+ /** Script extensions that are rendered UI only beneath a directory in {@link UI_SCRIPT_DIRECTORIES}. */
54
+ const CONDITIONAL_UI_SUFFIXES = new Set([".js", ".mjs", ".cjs", ".ts"]);
55
+ const UI_SCRIPT_DIRECTORIES = new Set([
56
+ "public", "static", "assets", "www", "client", "frontend", "components", "pages",
57
+ ]);
58
+ /**
59
+ * True when a repository-relative path is a rendered-UI file. Lexical only: path
60
+ * segments and suffixes, with no prose, framework, or general script heuristic.
61
+ */
62
+ export function isRenderedUiPath(filePath) {
63
+ const segments = filePath.toLowerCase().split("/").filter((segment) => segment !== "" && segment !== ".");
64
+ if (segments.length === 0)
65
+ return false;
66
+ if (segments.some((segment) => EXCLUDED_SEGMENTS.has(segment)))
67
+ return false;
68
+ const name = segments[segments.length - 1];
69
+ const dot = name.lastIndexOf(".");
70
+ if (dot <= 0)
71
+ return false;
72
+ const suffix = name.slice(dot);
73
+ if (ALWAYS_UI_SUFFIXES.has(suffix))
74
+ return true;
75
+ if (!CONDITIONAL_UI_SUFFIXES.has(suffix))
76
+ return false;
77
+ return segments.slice(0, -1).some((segment) => UI_SCRIPT_DIRECTORIES.has(segment));
78
+ }
79
+ /** The exact step names that prove a ticket expects UI checking. */
80
+ const UI_STEP_LITERALS = ["e2e_tests", "rendered_ui_review"];
81
+ export function classifyUiWork(input) {
82
+ const inventory = input.trackedFiles.state === "ok" ? buildTrackedInventory(input.trackedFiles.value) : null;
83
+ const proven = new Set();
84
+ // The inventory is required to read a description's cited paths. Without it the
85
+ // answer can still be `present` from other evidence, but never `none`.
86
+ let incomplete = inventory === null;
87
+ const examine = (key, read) => {
88
+ if (read.state !== "ok") {
89
+ incomplete = true;
90
+ return;
91
+ }
92
+ if (UI_STEP_LITERALS.some((literal) => read.value.includes(literal))) {
93
+ proven.add(key);
94
+ return;
95
+ }
96
+ if (inventory !== null && extractTouchedFiles(read.value, inventory).some(isRenderedUiPath))
97
+ proven.add(key);
98
+ };
99
+ examine(input.epicKey, input.epicDescription);
100
+ const runningKeys = new Set();
101
+ for (const child of input.runningChildren) {
102
+ runningKeys.add(child.key);
103
+ examine(child.key, child.description);
104
+ }
105
+ for (const node of input.nodes) {
106
+ if (!runningKeys.has(node.ticket_key))
107
+ continue;
108
+ if (node.touched_files?.some(isRenderedUiPath) === true)
109
+ proven.add(node.ticket_key);
110
+ }
111
+ if (proven.size > 0) {
112
+ const sources = [...proven].filter((key) => TICKET_KEY_PATTERN.test(key)).sort(compareTicketKeys);
113
+ return { ui_work: "present", ui_sources: sources.slice(0, UI_SOURCES_CAP) };
114
+ }
115
+ return { ui_work: incomplete ? "unknown" : "none", ui_sources: [] };
116
+ }
117
+ // ---------------------------------------------------------------------------
118
+ // Browser recognition and verification
119
+ // ---------------------------------------------------------------------------
120
+ /**
121
+ * The closed policy for "this approved server can drive a browser": the Playwright
122
+ * preset entry, or a server whose `command` or one `args` element is exactly one of
123
+ * these package names. Nothing else is recognized: no shell parsing, no path
124
+ * normalization, no substring or concatenated match, and a host entry merely named
125
+ * `playwright` does not qualify.
126
+ */
127
+ export const RECOGNIZED_BROWSER_MCP = {
128
+ preset: { source: "preset", name: PLAYWRIGHT_PRESET_NAME },
129
+ tokens: ["@playwright/mcp", "chrome-devtools-mcp", "@modelcontextprotocol/server-puppeteer"],
130
+ };
131
+ /** Remove at most one trailing non-empty `@<version>`, keeping a scoped name's leading `@`. */
132
+ function stripOneVersionSuffix(token) {
133
+ const at = token.lastIndexOf("@");
134
+ return at > 0 && at < token.length - 1 ? token.slice(0, at) : token;
135
+ }
136
+ function isRecognizedBrowserToken(token) {
137
+ return RECOGNIZED_BROWSER_MCP.tokens.includes(stripOneVersionSuffix(token));
138
+ }
139
+ function isRecognizedBrowserServer(entry) {
140
+ if (isPlaywrightPresetEntry(entry))
141
+ return true;
142
+ return isRecognizedBrowserToken(entry.command) || entry.args.some(isRecognizedBrowserToken);
143
+ }
144
+ export function classifyUiVerification(grant, mode) {
145
+ // An unreadable grant or mode is unknown evidence, before anything else.
146
+ if (grant.state === "unusable" || grant.state === "failed" || mode === "unknown") {
147
+ return { verification: "unknown", reason: "unreadable" };
148
+ }
149
+ // An absent grant is confirmed-empty evidence.
150
+ const approved = grant.state === "ok"
151
+ ? grant.grant.servers.filter((server) => !BRIDGE_RESERVED_SERVER_NAMES.includes(server.name))
152
+ : [];
153
+ const hasSite = mode === "local" || mode === "sfcc_shared_active";
154
+ if (hasSite && approved.some(isRecognizedBrowserServer))
155
+ return { verification: "available", reason: "browser_mcp" };
156
+ if (!hasSite) {
157
+ return approved.length > 0
158
+ ? { verification: "unavailable", reason: "no_epic_server" }
159
+ : { verification: "unavailable", reason: "no_browser_mcp_or_epic_server" };
160
+ }
161
+ return approved.length === 0
162
+ ? { verification: "unavailable", reason: "no_browser_mcp" }
163
+ : { verification: "unknown", reason: "unrecognized_mcp" };
164
+ }
165
+ /**
166
+ * The name-based Playwright fact the readiness line has always shown. It is kept
167
+ * apart from browser recognition: a recognized Chrome DevTools server can make
168
+ * verification `available` while this still says `absent`.
169
+ */
170
+ export function classifyPlaywrightGrant(grant) {
171
+ if (grant.state === "absent")
172
+ return "absent";
173
+ if (grant.state !== "ok")
174
+ return "unknown";
175
+ return grant.grant.servers.some((server) => server.name === PLAYWRIGHT_PRESET_NAME) ? "present" : "absent";
176
+ }
177
+ // ---------------------------------------------------------------------------
178
+ // The line and the notices: the only place this wording lives
179
+ // ---------------------------------------------------------------------------
180
+ const NOT_APPLICABLE_LINE = "UI readiness: not applicable (no UI changes in this epic)";
181
+ const OPENING = {
182
+ present: "This epic changes the UI",
183
+ unknown: "This epic may change the UI",
184
+ };
185
+ const NOTICE_SUFFIX = {
186
+ no_browser_mcp_or_epic_server: ", but the AI may have no way to see the pages it builds: no browser MCP is approved for workers, and no epic server is set. Without a check, AI-built UI is often wrong in layout, styling, and behavior, so expect to review the pages yourself. With one, results are usually good. We recommend the Playwright MCP and a local epic server: run /install-epic-implementer and approve both.",
187
+ no_browser_mcp: ", but the AI may have no way to see the pages it builds: no browser MCP is approved for workers. Without a check, AI-built UI is often wrong in layout, styling, and behavior, so expect to review the pages yourself. With one, results are usually good. We recommend the Playwright MCP: run /install-epic-implementer and approve the Playwright preset for workers.",
188
+ no_epic_server: ", but the AI may have no running site to open: no epic server is set. Without a check, AI-built UI is often wrong in layout, styling, and behavior. Run /install-epic-implementer and choose a local epic server.",
189
+ };
190
+ const UNRECOGNIZED_MCP_NOTICE = "If none of your approved MCP servers can drive a browser, the AI may have no way to see the pages this epic builds. Without a check, AI-built UI is often wrong in layout, styling, and behavior. We recommend the Playwright MCP: run /install-epic-implementer and approve the Playwright preset for workers.";
191
+ function handoffWord(handoff) {
192
+ return handoff === "proceed" ? "on" : handoff === "block" ? "off" : "unknown";
193
+ }
194
+ /** Combine the two classifications into the closed readiness object. Pure. */
195
+ export function buildUiReadiness(input) {
196
+ const { work, verification } = input;
197
+ const base = {
198
+ ui_work: work.ui_work,
199
+ ui_sources: [...work.ui_sources],
200
+ verification: verification.verification,
201
+ reason: verification.reason,
202
+ };
203
+ // No UI changes: nothing to warn about, whatever verification looks like.
204
+ if (work.ui_work === "none")
205
+ return { ...base, ui_sources: [], line: NOT_APPLICABLE_LINE };
206
+ const line = `UI readiness (advisory): epic server ${input.mode}; Playwright grant ${input.playwrightGrant}; ` +
207
+ `hand-off policy ${handoffWord(input.handoff)}`;
208
+ const opening = OPENING[work.ui_work];
209
+ let notice;
210
+ switch (verification.reason) {
211
+ case "no_browser_mcp_or_epic_server":
212
+ case "no_browser_mcp":
213
+ case "no_epic_server":
214
+ notice = `${opening}${NOTICE_SUFFIX[verification.reason]}`;
215
+ break;
216
+ case "unrecognized_mcp":
217
+ notice = UNRECOGNIZED_MCP_NOTICE;
218
+ break;
219
+ default:
220
+ // available (browser_mcp) and unreadable carry no advice and no stored verdict.
221
+ notice = undefined;
222
+ }
223
+ return notice === undefined ? { ...base, line } : { ...base, line, notice };
224
+ }
@@ -106,10 +106,15 @@ export function newIncidents(baseline, current) {
106
106
  /**
107
107
  * Whether an executor-job block's state lets the job incidents be read at all.
108
108
  * `available` carries a list, and `not_applicable` (or an absent block) means this
109
- * source does not describe the run. `unavailable` and `unknown` are missing
110
- * evidence, not an empty failure set: the caller treats them as a transient read
111
- * failure so a job baseline is never silently cleared.
109
+ * source does not describe the run. `unknown` is readable only when the server
110
+ * also sent the exact `"no_jobs"` empty reason (BAPI-1733: both sources read
111
+ * clean and the whole run has no jobs). Bare `unknown`, `unavailable`, and
112
+ * unfamiliar states remain missing evidence, not an empty failure set: the
113
+ * caller treats them as a transient read failure so a job baseline is never
114
+ * silently cleared.
112
115
  */
113
- export function executorJobEvidenceReadable(state) {
116
+ export function executorJobEvidenceReadable(state, emptyReason) {
117
+ if (state === "unknown")
118
+ return emptyReason === "no_jobs";
114
119
  return state === null || state === "available" || state === "not_applicable";
115
120
  }
@@ -442,12 +442,15 @@ export function buildWaitRunSnapshot(body, ticketKey) {
442
442
  throw new WaitRunSelectorError();
443
443
  }
444
444
  let executorJobsState = null;
445
+ let executorJobsEmptyReason;
445
446
  let jobs = [];
446
447
  const block = body.executor_jobs;
447
448
  if (block !== undefined && block !== null) {
448
449
  if (!isRecord(block) || typeof block.state !== "string")
449
450
  throw new WaitRunMalformedError();
450
451
  executorJobsState = block.state;
452
+ if (block.empty_reason === "no_jobs")
453
+ executorJobsEmptyReason = "no_jobs";
451
454
  const jobRows = orNull(block.jobs);
452
455
  if (jobRows !== null) {
453
456
  if (!Array.isArray(jobRows))
@@ -470,6 +473,7 @@ export function buildWaitRunSnapshot(body, ticketKey) {
470
473
  run_control: stripTimestampKeys(runControl),
471
474
  },
472
475
  executor_jobs_state: executorJobsState,
476
+ ...(executorJobsEmptyReason !== undefined ? { executor_jobs_empty_reason: executorJobsEmptyReason } : {}),
473
477
  tickets,
474
478
  jobs: selectedJobs,
475
479
  };
@@ -524,7 +528,10 @@ export function buildWaitRunCurrent(snapshot) {
524
528
  }
525
529
  /** `v1:` plus the first 16 hex characters of the canonical projection's SHA-256. */
526
530
  export function buildWaitRunToken(snapshot) {
527
- const digest = createHash("sha256").update(canonicalJson(snapshot)).digest("hex");
531
+ // BAPI-1733: the empty-jobs marker decides only whether attention mode may read the
532
+ // evidence. It is not part of what changed, so it never moves a change-mode token.
533
+ const { executor_jobs_empty_reason: _marker, ...tokenInput } = snapshot;
534
+ const digest = createHash("sha256").update(canonicalJson(tokenInput)).digest("hex");
528
535
  return `v1:${digest.slice(0, 16)}`;
529
536
  }
530
537
  /** Bound a string for display: control characters removed, length capped. */
@@ -850,7 +857,7 @@ export async function runWaitRunCommand(argv, deps = {}) {
850
857
  }
851
858
  // Missing job evidence is not an empty failure set. Report it to the
852
859
  // primitive as a transient failure so the baseline is never cleared by it.
853
- if (!executorJobEvidenceReadable(snapshot.executor_jobs_state)) {
860
+ if (!executorJobEvidenceReadable(snapshot.executor_jobs_state, snapshot.executor_jobs_empty_reason)) {
854
861
  failedSinceGood = true;
855
862
  throw new ConductorBridgeApiError("server", 503);
856
863
  }