@bridge_gpt/mcp-server 0.2.73 → 0.2.75

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 (123) hide show
  1. package/README.md +14 -7
  2. package/build/agent-launchers/claude-executor-adapter.js +12 -0
  3. package/build/agent-launchers/prompt.js +9 -21
  4. package/build/agents.generated.js +4 -4
  5. package/build/authored-plan.js +542 -0
  6. package/build/bridge-config.js +7 -1
  7. package/build/bridge-permissions.js +11 -0
  8. package/build/command-provisioning.js +4 -3
  9. package/build/commands.generated.js +6 -6
  10. package/build/conductor/bridge-api-client.js +692 -47
  11. package/build/conductor/command-drift.js +1 -1
  12. package/build/conductor/declared-extras.js +335 -0
  13. package/build/conductor/doctor.js +2 -0
  14. package/build/conductor/driver-pass-output.js +104 -0
  15. package/build/conductor/driver-pass.js +571 -0
  16. package/build/conductor/epic-branch-ci-inspection.js +61 -16
  17. package/build/conductor/epic-implementer-cli.js +370 -93
  18. package/build/conductor/epic-server-sfcc-upload.js +1567 -0
  19. package/build/conductor/epic-server-sfcc.js +58 -80
  20. package/build/conductor/epic-server.js +57 -4
  21. package/build/conductor/gate-discovery.js +253 -13
  22. package/build/conductor/gate-settings-review.js +58 -25
  23. package/build/conductor/launch-plan.js +58 -12
  24. package/build/conductor/open-decision-phrases.js +50 -0
  25. package/build/conductor/prerequisite-inputs.js +181 -14
  26. package/build/connect-github-api.js +18 -0
  27. package/build/connect-github.js +35 -18
  28. package/build/credential-delivery.js +280 -0
  29. package/build/credential-launch-safety.js +142 -0
  30. package/build/credential-materialization.js +91 -16
  31. package/build/credential-references-node-deps.js +29 -0
  32. package/build/credential-references.js +1394 -0
  33. package/build/credential-references.test-fixtures.js +211 -0
  34. package/build/credential-scan-conventions.js +145 -0
  35. package/build/credential-scan.js +517 -0
  36. package/build/credential-store.js +50 -0
  37. package/build/credentials-cli.js +252 -3
  38. package/build/dependency-install-declarations.js +47 -1
  39. package/build/docs.generated.js +8 -1
  40. package/build/doctor.js +41 -0
  41. package/build/drive-epic.js +684 -49
  42. package/build/epic-branch-ci-summary.js +18 -1
  43. package/build/epic-capability-statement.js +71 -3
  44. package/build/epic-ci-workflow-drift.js +52 -13
  45. package/build/epic-ci-workflow-install.js +31 -6
  46. package/build/epic-ci-workflow-v3.js +273 -0
  47. package/build/epic-ci-workflow.js +129 -7
  48. package/build/epic-implementer-bin.js +288 -83
  49. package/build/epic-implementer-bundle-cli.js +61 -0
  50. package/build/epic-implementer-claude-hook-bin.js +1 -1
  51. package/build/epic-implementer-env.js +3 -4
  52. package/build/epic-integration-pr.js +5 -2
  53. package/build/epic-launch-context.js +102 -7
  54. package/build/epic-server-record.js +30 -15
  55. package/build/executor/completion-contract.js +24 -1
  56. package/build/executor/credential-delivery-step.js +168 -0
  57. package/build/executor/deps.js +3 -1
  58. package/build/executor/env.js +39 -1
  59. package/build/executor/epic-server-context.js +23 -7
  60. package/build/executor/gate-qualification-job.js +193 -23
  61. package/build/executor/gate-qualification-tests-ran.js +232 -0
  62. package/build/executor/guarded-fast-forward-push.js +13 -8
  63. package/build/executor/job-runner.js +167 -738
  64. package/build/executor/job-type-wrappers.js +734 -0
  65. package/build/executor/permissions.js +85 -3
  66. package/build/executor/preflight.js +6 -2
  67. package/build/executor/process-containment.js +8 -1
  68. package/build/executor/prompt-spec.js +37 -3
  69. package/build/executor/required-verification.js +28 -2
  70. package/build/executor/runner.js +4 -1
  71. package/build/executor/types.js +9 -0
  72. package/build/executor/worker-database.js +6 -1
  73. package/build/executor/worker-guard-hook.js +24 -2
  74. package/build/executor-launch.js +4 -2
  75. package/build/generated/ticket-status.js +20 -0
  76. package/build/git-exclude-lock.js +187 -0
  77. package/build/index.js +589 -326
  78. package/build/install-bridge-conductor-answers.js +112 -22
  79. package/build/install-bridge-conductor-apply.js +38 -1
  80. package/build/install-bridge-conductor-assessment.js +482 -53
  81. package/build/install-bridge-conductor-compact.js +29 -2
  82. package/build/install-bridge-conductor-contracts.js +10 -1
  83. package/build/install-bridge-conductor-gate.js +379 -89
  84. package/build/install-bridge-conductor-setup.js +46 -8
  85. package/build/install-bridge-conductor-trial-report.js +170 -0
  86. package/build/install-bridge-conductor.js +925 -141
  87. package/build/install-bridge.js +88 -11
  88. package/build/install-doctor.js +38 -8
  89. package/build/install-sfcc-detection.js +120 -0
  90. package/build/install-sfcc-setup.js +185 -0
  91. package/build/mcp-grant-candidates.js +108 -96
  92. package/build/mcp-invoke.js +168 -4
  93. package/build/mcp-provisioning.js +21 -4
  94. package/build/mcp-server-invocation.js +13 -0
  95. package/build/merge-workflow-install.js +9 -1
  96. package/build/pipelines.generated.js +8 -7
  97. package/build/plan-generation.js +17 -0
  98. package/build/plane/status.js +8 -2
  99. package/build/printed-remedy-commands.js +59 -0
  100. package/build/project-root.js +40 -0
  101. package/build/readme.generated.js +1 -1
  102. package/build/repository-state-paths.js +5 -2
  103. package/build/repository-toolchains.js +16 -7
  104. package/build/scripts/saved-commands-config-field-driver.js +65 -0
  105. package/build/setup-epic.js +126 -16
  106. package/build/sfcc/credentials.js +3 -2
  107. package/build/sfcc/hostname.js +98 -2
  108. package/build/sfcc/tool-wrapper.js +6 -95
  109. package/build/start-tickets.js +193 -29
  110. package/build/test-support/executor-source-files.js +200 -0
  111. package/build/testing-config-client.js +25 -2
  112. package/build/third-party-mcp-targets.js +35 -4
  113. package/build/v2-readiness-requirements.js +5 -1
  114. package/build/version.generated.js +3 -3
  115. package/build/with-credentials.js +208 -0
  116. package/build/worker-guard-hook-bin.js +2 -2
  117. package/build/worktree-credential-delivery.js +340 -0
  118. package/docs/EPIC-IMPLEMENTER.md +4 -4
  119. package/docs/install/github-app.md +79 -92
  120. package/package.json +1 -1
  121. package/build/conductor/epic-reconcile.js +0 -603
  122. package/build/conductor/epic-runtime.js +0 -2020
  123. package/build/conductor/epic-state.js +0 -774
@@ -2,7 +2,7 @@
2
2
  export const COMMAND_DRIFT_ROW_ID = "command-drift";
3
3
  export const COMMAND_DRIFT_ROW_LABEL = "Committed command drift";
4
4
  /** Group-level remedy for divergent, non-customized commands. */
5
- export const COMMAND_DRIFT_DIVERGENT_REMEDIATION = "run `/upgrade-bridge` and commit the refreshed commands, or mark the command customized in the gate profile";
5
+ export const COMMAND_DRIFT_DIVERGENT_REMEDIATION = "commit the refreshed command files (run /upgrade-bridge first if they are not refreshed), or mark the command customized in the gate profile";
6
6
  /** Remedy when the check itself could not be completed. */
7
7
  export const COMMAND_DRIFT_UNASSESSABLE_REMEDIATION = "restore Bridge profile access and Git access for this repository, then rerun `epic-implementer doctor`";
8
8
  const SAFE_COMMAND_FILE = /^([a-z][a-z0-9-]*)\.md$/;
@@ -0,0 +1,335 @@
1
+ /**
2
+ * BAPI-1677 — work out which optional extras an install command may add.
3
+ *
4
+ * An extra is kept only when the install target DECLARES it and the repository's
5
+ * learned instructions NAME it in a positive example. Only a declared key ever
6
+ * reaches an argument list: no other repository or instruction text does.
7
+ *
8
+ * Pure apart from one injected bounded file reader: no network, prompt, or write.
9
+ * Extras are read from text with a small lexical scanner rather than a TOML
10
+ * dependency. Anything the scanner cannot read with certainty is `unknown`, never
11
+ * a confirmed empty list, and never a stop.
12
+ */
13
+ import { MAX_DEPENDENCY_INSTALL_ARGV_ITEMS, isUnsafeDependencyInstallArg, } from "../dependency-install-declarations.js";
14
+ import { LEARNED_INSTRUCTION_FIELDS } from "../testing-config-client.js";
15
+ /** The largest `pyproject.toml` the scanner reads. */
16
+ export const MAX_DECLARED_EXTRAS_FILE_BYTES = 256 * 1024;
17
+ /** The most learned text read from one field. A longer field is a limitation. */
18
+ export const MAX_LEARNED_TEXT_BYTES = 256 * 1024;
19
+ /** The most matches kept from one field. More is a limitation, not a guess. */
20
+ export const MAX_EXTRA_MATCHES = 64;
21
+ /** The longest evidence span shown for one extra. */
22
+ export const MAX_EXTRA_EVIDENCE_CHARS = 80;
23
+ /** The most notes one derivation returns. */
24
+ export const MAX_EXTRA_NOTES = 8;
25
+ /** The repository-relative path of a target's own `pyproject.toml`. */
26
+ export function pyprojectPathFor(cwd) {
27
+ return cwd === "." ? "pyproject.toml" : `${cwd}/pyproject.toml`;
28
+ }
29
+ const BARE_KEY_RE = /^[A-Za-z0-9_-]+$/;
30
+ /** What may stand as an extra name. A key outside this set never reaches a command. */
31
+ const EXTRA_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
32
+ /**
33
+ * Blank out comments and string bodies, keeping the line structure, so a header
34
+ * inside a multi-line string or a comment can never be read as a header. `null`
35
+ * means a string never closed: the file cannot be read with certainty.
36
+ *
37
+ * Each line reports its text with strings blanked to `S`, and its leading quoted
38
+ * key when it has one.
39
+ */
40
+ function lexicalLines(text) {
41
+ const lines = [];
42
+ let code = "";
43
+ let quotedKey = null;
44
+ let i = 0;
45
+ const flush = () => {
46
+ lines.push({ code, quotedKey });
47
+ code = "";
48
+ quotedKey = null;
49
+ };
50
+ while (i < text.length) {
51
+ const ch = text[i];
52
+ if (ch === "\n") {
53
+ flush();
54
+ i += 1;
55
+ continue;
56
+ }
57
+ if (ch === "#") {
58
+ while (i < text.length && text[i] !== "\n")
59
+ i += 1;
60
+ continue;
61
+ }
62
+ if (ch === '"' || ch === "'") {
63
+ const triple = ch.repeat(3);
64
+ if (text.startsWith(triple, i)) {
65
+ let end = i + 3;
66
+ for (;;) {
67
+ end = text.indexOf(triple, end);
68
+ if (end === -1)
69
+ return null;
70
+ // A basic string's `\"""` does not close it. A literal string has no escapes.
71
+ if (ch === '"' && isEscaped(text, end)) {
72
+ end += 1;
73
+ continue;
74
+ }
75
+ break;
76
+ }
77
+ // The string stands on its opening line. Its newlines stay lines, blank ones.
78
+ code += "S";
79
+ for (let at = i; at < end; at += 1)
80
+ if (text[at] === "\n")
81
+ flush();
82
+ i = end + 3;
83
+ // A closing delimiter may carry up to two more quotes that belong to the string.
84
+ while (text[i] === ch)
85
+ i += 1;
86
+ continue;
87
+ }
88
+ let end = i + 1;
89
+ while (end < text.length && text[end] !== "\n") {
90
+ if (text[end] === ch && !(ch === '"' && isEscaped(text, end)))
91
+ break;
92
+ end += 1;
93
+ }
94
+ if (text[end] !== ch)
95
+ return null;
96
+ if (code.trim().length === 0 && quotedKey === null) {
97
+ const inner = text.slice(i + 1, end);
98
+ // A quoted key with an escape is outside what this scanner can read exactly.
99
+ quotedKey = ch === '"' && inner.includes("\\") ? "\u0000" : inner;
100
+ }
101
+ code += "S";
102
+ i = end + 1;
103
+ continue;
104
+ }
105
+ code += ch;
106
+ i += 1;
107
+ }
108
+ flush();
109
+ return lines;
110
+ }
111
+ function isEscaped(text, at) {
112
+ let slashes = 0;
113
+ for (let j = at - 1; j >= 0 && text[j] === "\\"; j -= 1)
114
+ slashes += 1;
115
+ return slashes % 2 === 1;
116
+ }
117
+ const TABLE_FOR_MANAGER = Object.freeze({
118
+ uv: "[project.optional-dependencies]",
119
+ poetry: "[tool.poetry.extras]",
120
+ });
121
+ /**
122
+ * The manager's own table keys, in declaration order. A header counts only at the
123
+ * start of a line and outside any string or comment. Depth tracking skips a
124
+ * multi-line array's values, so a value never reads as a key.
125
+ */
126
+ export function scanDeclaredExtras(text, manager) {
127
+ if (Buffer.byteLength(text, "utf8") > MAX_DECLARED_EXTRAS_FILE_BYTES)
128
+ return { status: "unknown", reason: "too_large" };
129
+ const lines = lexicalLines(text.replace(/\r\n/g, "\n"));
130
+ if (lines === null)
131
+ return { status: "unknown", reason: "malformed" };
132
+ const wanted = TABLE_FOR_MANAGER[manager];
133
+ const extras = [];
134
+ let inTable = false;
135
+ let depth = 0;
136
+ for (const line of lines) {
137
+ const code = line.code;
138
+ const trimmed = code.trim();
139
+ if (depth > 0) {
140
+ depth += bracketDelta(code);
141
+ if (depth < 0)
142
+ return { status: "unknown", reason: "malformed" };
143
+ continue;
144
+ }
145
+ if (trimmed.length === 0)
146
+ continue;
147
+ if (trimmed.startsWith("[")) {
148
+ // A real table header starts at the first column.
149
+ if (code.startsWith("[") && /^\[\[?[^\]]*\]\]?$/.test(trimmed)) {
150
+ inTable = trimmed === wanted;
151
+ continue;
152
+ }
153
+ return { status: "unknown", reason: "malformed" };
154
+ }
155
+ const eq = code.indexOf("=");
156
+ if (eq === -1)
157
+ return { status: "unknown", reason: "malformed" };
158
+ depth = bracketDelta(code.slice(eq + 1));
159
+ if (depth < 0)
160
+ return { status: "unknown", reason: "malformed" };
161
+ if (!inTable)
162
+ continue;
163
+ const rawKey = code.slice(0, eq).trim();
164
+ const key = rawKey === "S" ? line.quotedKey : BARE_KEY_RE.test(rawKey) ? rawKey : null;
165
+ if (key === null || key === "\u0000")
166
+ return { status: "unknown", reason: "unsupported_key" };
167
+ if (!extras.includes(key))
168
+ extras.push(key);
169
+ }
170
+ if (depth !== 0)
171
+ return { status: "unknown", reason: "malformed" };
172
+ return { status: "known", extras };
173
+ }
174
+ function bracketDelta(code) {
175
+ let delta = 0;
176
+ for (const ch of code) {
177
+ if (ch === "[" || ch === "{")
178
+ delta += 1;
179
+ else if (ch === "]" || ch === "}")
180
+ delta -= 1;
181
+ }
182
+ return delta;
183
+ }
184
+ // A name ends in a letter or digit, so the full stop closing a sentence is never part of it.
185
+ const NAME = "[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?";
186
+ /** A sentence mentioning any of these is negated, even when another clause is positive. */
187
+ const NEGATION_RE = /\b(?:do not|don't|dont|never|avoid|without|must not|should not|shouldn't|cannot|can't|not)\b/i;
188
+ /** A word that makes a line refer to a command for something other than the install target. */
189
+ const OTHER_TARGET_RE = /\b(?:pip install|uv add|uv pip|poetry add|pipx)\b/i;
190
+ /** Sentence boundaries: a line break, or end punctuation before whitespace. */
191
+ function sentences(text) {
192
+ return text.split(/\n+|(?<=[.!?])\s+/).filter((s) => s.trim().length > 0);
193
+ }
194
+ function matchesInSentence(sentence, manager) {
195
+ const found = [];
196
+ if (/(?:^|[\s`'"])--all-extras(?=$|[\s`'".,;:)])/.test(sentence))
197
+ found.push({ names: "all", span: "--all-extras" });
198
+ if (manager === "uv") {
199
+ for (const m of sentence.matchAll(new RegExp(`(?:^|[\\s\`'"])--extra[ =](${NAME})`, "g"))) {
200
+ found.push({ names: [m[1]], span: `--extra ${m[1]}` });
201
+ }
202
+ }
203
+ else {
204
+ for (const m of sentence.matchAll(new RegExp(`(?:^|[\\s\`'"])-E[ =](${NAME})`, "g"))) {
205
+ found.push({ names: [m[1]], span: `-E ${m[1]}` });
206
+ }
207
+ for (const m of sentence.matchAll(/(?:^|[\s`'"])--extras[ =]"([^"]{1,200})"/g)) {
208
+ const names = m[1].trim().split(/\s+/).filter((n) => n.length > 0);
209
+ if (names.length > 0 && names.every((n) => EXTRA_NAME_RE.test(n))) {
210
+ found.push({ names, span: `--extras "${names.join(" ")}"` });
211
+ }
212
+ }
213
+ }
214
+ // `.[a,b]` is the resolved target itself. `other-pkg[seo]` has a name before the
215
+ // bracket, so it is another package's extra and never matches here.
216
+ for (const m of sentence.matchAll(/(?:^|[\s`'"])\.\[([A-Za-z0-9._,\s-]{1,200})\]/g)) {
217
+ const names = m[1].split(",").map((n) => n.trim()).filter((n) => n.length > 0);
218
+ if (names.length > 0 && names.every((n) => EXTRA_NAME_RE.test(n))) {
219
+ found.push({ names, span: `.[${names.join(",")}]` });
220
+ }
221
+ }
222
+ return found;
223
+ }
224
+ /** Whether a sentence holds an install-flag shape for extras at all. */
225
+ function mentionsExtraSyntax(sentence) {
226
+ return /(?:^|[\s`'"])(?:--extra|--extras|--all-extras|-E)(?=$|[\s=`'"])|(?:^|[\s`'"])\.\[/.test(sentence);
227
+ }
228
+ /** The learned fields in plain words, for what the owner reads. */
229
+ const LEARNED_FIELD_WORDS = Object.freeze({
230
+ architecture_instructions: "the architecture instructions Bridge learned",
231
+ unit_testing_instructions: "the unit testing instructions Bridge learned",
232
+ e2e_testing_instructions: "the end-to-end testing instructions Bridge learned",
233
+ });
234
+ function addNote(notes, note) {
235
+ if (notes.length < MAX_EXTRA_NOTES && !notes.includes(note))
236
+ notes.push(note);
237
+ }
238
+ /**
239
+ * Combine a target's declared keys with the learned text. Named ∩ declared, in
240
+ * declared order, within the argument bound. A failed field yields no extras from
241
+ * that field and marks the result incomplete; a blank field is only an absence.
242
+ */
243
+ export function deriveExtrasFromText(target, declared, learned) {
244
+ const notes = [];
245
+ let complete = true;
246
+ if (declared.status === "unknown") {
247
+ complete = false;
248
+ addNote(notes, `Bridge could not read the optional extras in ${pyprojectPathFor(target.cwd)}, so it adds none.`);
249
+ }
250
+ if (learned === null) {
251
+ complete = false;
252
+ addNote(notes, "Bridge could not read the repository's learned instructions, so it adds no extras from them.");
253
+ }
254
+ const declaredKeys = declared.status === "known" ? declared.extras : [];
255
+ const firstEvidence = new Map();
256
+ for (const field of LEARNED_INSTRUCTION_FIELDS) {
257
+ const read = learned?.[field];
258
+ if (read === undefined)
259
+ continue;
260
+ if (!read.ok) {
261
+ complete = false;
262
+ addNote(notes, `Bridge could not read ${LEARNED_FIELD_WORDS[field]} (${field}), so it adds no extras from them. Any extra your tests need can be added by correcting the commands.`);
263
+ continue;
264
+ }
265
+ const text = read.value;
266
+ if (text === null || text.trim().length === 0)
267
+ continue;
268
+ if (Buffer.byteLength(text, "utf8") > MAX_LEARNED_TEXT_BYTES) {
269
+ complete = false;
270
+ addNote(notes, `${LEARNED_FIELD_WORDS[field]} (${field}) are too long for Bridge to check for extras, so it adds none from them.`);
271
+ continue;
272
+ }
273
+ let matches = 0;
274
+ for (const sentence of sentences(text)) {
275
+ if (!mentionsExtraSyntax(sentence))
276
+ continue;
277
+ if (NEGATION_RE.test(sentence))
278
+ continue;
279
+ if (OTHER_TARGET_RE.test(sentence)) {
280
+ addNote(notes, `A line in ${LEARNED_FIELD_WORDS[field]} (${field}) names extras, but Bridge could not tell they belong to this project, so it left them out.`);
281
+ continue;
282
+ }
283
+ for (const match of matchesInSentence(sentence, target.manager)) {
284
+ matches += 1;
285
+ if (matches > MAX_EXTRA_MATCHES) {
286
+ complete = false;
287
+ addNote(notes, `${LEARNED_FIELD_WORDS[field]} (${field}) name too many extras for Bridge to read, so some may be left out.`);
288
+ break;
289
+ }
290
+ const names = match.names === "all" ? declaredKeys : match.names;
291
+ for (const name of names) {
292
+ if (declaredKeys.includes(name) && !firstEvidence.has(name)) {
293
+ firstEvidence.set(name, { extra: name, field, span: match.span.slice(0, MAX_EXTRA_EVIDENCE_CHARS) });
294
+ }
295
+ }
296
+ }
297
+ if (matches > MAX_EXTRA_MATCHES)
298
+ break;
299
+ }
300
+ }
301
+ const extras = [];
302
+ const evidence = [];
303
+ const room = Math.max(0, Math.floor((MAX_DEPENDENCY_INSTALL_ARGV_ITEMS - target.baseArgvLength) / 2));
304
+ let omittedForBound = false;
305
+ for (const key of declaredKeys) {
306
+ const kept = firstEvidence.get(key);
307
+ if (kept === undefined)
308
+ continue;
309
+ if (!EXTRA_NAME_RE.test(key) || isUnsafeDependencyInstallArg(key)) {
310
+ addNote(notes, "An extra was left out because its name is not safe to put in an install command.");
311
+ continue;
312
+ }
313
+ if (extras.length >= room) {
314
+ omittedForBound = true;
315
+ continue;
316
+ }
317
+ extras.push(key);
318
+ evidence.push(kept);
319
+ }
320
+ if (omittedForBound)
321
+ addNote(notes, "Some extras were left out because the install command would be too long.");
322
+ return { extras, evidence, notes, complete };
323
+ }
324
+ /** Read only the target's own `pyproject.toml`, then derive. Never throws. */
325
+ export async function deriveDeclaredExtras(target, learned, readFile) {
326
+ let text;
327
+ try {
328
+ text = await readFile(pyprojectPathFor(target.cwd));
329
+ }
330
+ catch {
331
+ text = null;
332
+ }
333
+ const declared = text === null ? { status: "unknown", reason: "unreadable" } : scanDeclaredExtras(text, target.manager);
334
+ return deriveExtrasFromText(target, declared, learned);
335
+ }
@@ -604,6 +604,8 @@ export const CREDENTIALED_RECOVERY_COMMANDS = [
604
604
  "driver-register",
605
605
  "driver-release",
606
606
  "declare-blocked",
607
+ // BAPI-1682: read-only driver clock report; same shared resolver and launch-profile selection.
608
+ "driver-pass",
607
609
  ];
608
610
  /** Remediation for recovery/repair verbs that cannot resolve Bridge credentials. */
609
611
  export const REPAIR_CREDENTIAL_REMEDIATION = "export BAPI_API_KEY in the shell that runs `conductor`, or store a credential for this " +
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Result types and terminal formatting for `epic-implementer driver-pass`.
3
+ *
4
+ * This module is deliberately dependency-light: it imports nothing, so the CLI
5
+ * can still print a full "unavailable" result when the command module itself
6
+ * (and the HTTP client behind it) fails to load.
7
+ *
8
+ * Every public field is present in every result, in every variant. A fact that
9
+ * could not be read is the literal `"unknown"`. A fact that this read-only
10
+ * command cannot compute at all, because it needs memory across calls, is the
11
+ * literal `"unavailable"`. The second kind is intentional and never lowers the
12
+ * result's completeness.
13
+ *
14
+ * Nothing here ever carries a recommendation, a command to run, a policy
15
+ * judgment, exception text, or a raw upstream string. Every string value comes
16
+ * from a closed vocabulary below, a validated identifier, or a normalized
17
+ * timestamp.
18
+ */
19
+ /** Closed failure and unknown-reason tokens. Never built from upstream text. */
20
+ export const DRIVER_PASS_REASONS = [
21
+ "credentials_unavailable",
22
+ "explain_unreadable",
23
+ "state_unreadable",
24
+ "readiness_unreadable",
25
+ "run_identity_mismatch",
26
+ "computation_failed",
27
+ "server_clock_unreadable",
28
+ "ticket_not_in_explain",
29
+ "ticket_not_in_state",
30
+ "jobs_unreadable",
31
+ "progress_basis_unreadable",
32
+ "progress_basis_in_future",
33
+ "queue_timestamp_unreadable",
34
+ "heartbeat_unreadable",
35
+ "heartbeat_in_future",
36
+ "park_unreadable",
37
+ "park_in_future",
38
+ ];
39
+ const REASON_SET = new Set(DRIVER_PASS_REASONS);
40
+ /** True when `value` is one of the closed reason tokens. */
41
+ export function isDriverPassReason(value) {
42
+ return typeof value === "string" && REASON_SET.has(value);
43
+ }
44
+ /** An all-unknown ticket record carrying one reason on every unreadable fact. */
45
+ export function buildUnknownDriverPassTicket(ticketKey, reason) {
46
+ return {
47
+ ticket_key: ticketKey,
48
+ no_progress: "unknown",
49
+ bound_reached: "unknown",
50
+ basis: "unknown",
51
+ bound_paused: "unknown",
52
+ evidence_unreliable: "unknown",
53
+ attach_window: "unknown",
54
+ stale_minutes: "unavailable",
55
+ transient_streak: "unavailable",
56
+ charged_interventions: "unavailable",
57
+ reasons: { progress: reason, pause: reason, attach_window: reason },
58
+ };
59
+ }
60
+ /**
61
+ * Build the full-schema result for a command that read nothing. Needs no
62
+ * credentials, no response payload and no HTTP module. When a ticket filter
63
+ * was supplied, the single requested ticket appears as an unknown record.
64
+ */
65
+ export function buildUnavailableDriverPassResult(epicRunId, reason, ticketKey) {
66
+ return {
67
+ epic_run_id: epicRunId,
68
+ status: "unavailable",
69
+ generated_at: "unknown",
70
+ reconciler: { stale: "unknown", last_tick_age_s: "unknown" },
71
+ overdue_claims: "unavailable",
72
+ checkpoint_due: "unavailable",
73
+ reasons: [reason],
74
+ tickets: ticketKey === undefined ? [] : [buildUnknownDriverPassTicket(ticketKey, reason)],
75
+ };
76
+ }
77
+ function token(value) {
78
+ return value === null ? "null" : String(value);
79
+ }
80
+ function compareKeys(a, b) {
81
+ return a < b ? -1 : a > b ? 1 : 0;
82
+ }
83
+ /**
84
+ * Render a result as plain key/value lines: run status first, reconciler facts
85
+ * second, grouped per-ticket facts last. Machine tokens are printed verbatim.
86
+ * The text never contains advice, a command, or any upstream string.
87
+ */
88
+ export function formatDriverPassResult(result) {
89
+ const lines = [
90
+ `status: ${result.status}`,
91
+ `epic_run_id: ${result.epic_run_id}`,
92
+ `generated_at: ${result.generated_at}`,
93
+ `reasons: ${result.reasons.length === 0 ? "none" : [...result.reasons].sort().join(",")}`,
94
+ `reconciler.stale: ${token(result.reconciler.stale)}`,
95
+ `reconciler.last_tick_age_s: ${token(result.reconciler.last_tick_age_s)}`,
96
+ `overdue_claims: ${result.overdue_claims}`,
97
+ `checkpoint_due: ${result.checkpoint_due}`,
98
+ ];
99
+ const tickets = [...result.tickets].sort((a, b) => compareKeys(a.ticket_key, b.ticket_key));
100
+ for (const ticket of tickets) {
101
+ lines.push("", `ticket: ${ticket.ticket_key}`, ` no_progress: ${token(ticket.no_progress)}`, ` bound_reached: ${token(ticket.bound_reached)}`, ` basis: ${ticket.basis}`, ` bound_paused: ${token(ticket.bound_paused)}`, ` evidence_unreliable: ${token(ticket.evidence_unreliable)}`, ` attach_window: ${ticket.attach_window}`, ` stale_minutes: ${ticket.stale_minutes}`, ` transient_streak: ${ticket.transient_streak}`, ` charged_interventions: ${ticket.charged_interventions}`, ` reason.progress: ${ticket.reasons.progress ?? "none"}`, ` reason.pause: ${ticket.reasons.pause ?? "none"}`, ` reason.attach_window: ${ticket.reasons.attach_window ?? "none"}`);
102
+ }
103
+ return lines.join("\n");
104
+ }