@bridge_gpt/mcp-server 0.2.75 → 0.2.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/build/agents.generated.js +4 -4
- package/build/codex-auto-recovery.js +25 -7
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +141 -6
- package/build/conductor/declare-blocked.js +4 -0
- package/build/conductor/driver-pass.js +8 -0
- package/build/conductor/epic-implementer-cli.js +4 -3
- package/build/conductor/epic-server-journal.js +13 -0
- package/build/conductor/epic-server-recipe.js +15 -5
- package/build/conductor/epic-server-runtime.js +163 -45
- package/build/conductor/epic-server.js +13 -6
- package/build/conductor/install-doctor.js +30 -2
- package/build/conductor/local-merge.js +54 -12
- package/build/conductor/pr-ci-producer.js +12 -3
- package/build/conductor/readiness-sections.js +46 -13
- package/build/conductor/readiness.js +3 -40
- package/build/conductor/recovery-cli.js +12 -12
- package/build/conductor/repository-workflow-remedy.js +147 -7
- package/build/conductor/ui-readiness.js +224 -0
- package/build/conductor/wait-run-attention.js +9 -4
- package/build/conductor/wait-run-cli.js +9 -2
- package/build/docs.generated.js +2 -2
- package/build/drive-epic.js +402 -27
- package/build/epic-implementer-bin.js +62 -42
- package/build/epic-launch-context.js +8 -1
- package/build/epic-shared/cut-protocol.js +55 -3
- package/build/executor/failure-reason-codes.js +2 -0
- package/build/executor/integration-job.js +56 -2
- package/build/executor/job-runner.js +4 -1
- package/build/executor/merge-job.js +45 -1
- package/build/executor/permissions.js +187 -2
- package/build/executor/provider-checks.js +28 -5
- package/build/executor/reconcile-overlap-job.js +70 -17
- package/build/executor/required-work-ledger.js +7 -2
- package/build/executor/resume-pre-spawn.js +32 -8
- package/build/executor/runner.js +26 -4
- package/build/executor/worktree.js +12 -1
- package/build/index.js +376 -434
- package/build/init.js +16 -0
- package/build/install-bridge-conductor-answers.js +4 -0
- package/build/install-bridge-conductor-apply.js +10 -0
- package/build/install-bridge-conductor-assessment.js +71 -0
- package/build/install-bridge-conductor-contracts.js +9 -1
- package/build/install-bridge-conductor-setup.js +103 -3
- package/build/install-bridge-conductor.js +437 -93
- package/build/mcp-host-config.js +54 -37
- package/build/phase-context-git-probe.js +16 -0
- package/build/pipelines.generated.js +9 -9
- package/build/plan-execution-ledger.js +27 -0
- package/build/plane/plane-freshness.js +43 -26
- package/build/printed-remedy-commands.js +8 -0
- package/build/readme.generated.js +1 -1
- package/build/secret-redaction.js +3 -0
- package/build/setup-epic.js +41 -8
- package/build/test-support/create-preview-world.js +232 -0
- package/build/ticket-delivery.js +65 -0
- package/build/v2-readiness-requirements.js +8 -3
- package/build/version.generated.js +3 -3
- package/build/worktree-core.js +51 -7
- package/docs/EPIC-IMPLEMENTER.md +79 -0
- package/docs/epic-implementer/getting-started.md +1 -1
- package/package.json +1 -1
- package/pipelines/implement-ticket.json +2 -2
|
@@ -49,6 +49,7 @@ import path from "node:path";
|
|
|
49
49
|
import { BRIDGE_RUN_STATE_DIR } from "./bridge-permissions.js";
|
|
50
50
|
import { READINESS_FRESH_RECONCILER_COUNT_CAP, } from "./conductor/bridge-api-client.js";
|
|
51
51
|
import { EMAIL_TRANSPORT_LIVE_DIAGNOSTIC_ID } from "./escalation-reachability.js";
|
|
52
|
+
import { repositoryReadinessVerdict } from "./conductor/repository-workflow-remedy.js";
|
|
52
53
|
/** The schema this writer produces (BAPI-1595: the corrected projection). */
|
|
53
54
|
export const LAUNCH_CONTEXT_SCHEMA_VERSION = 2;
|
|
54
55
|
/** The earlier, lossy schema. Still readable; its bring-up values are read as unknown. */
|
|
@@ -151,6 +152,9 @@ export function projectMandatoryDiagnostics(diagnostics) {
|
|
|
151
152
|
}
|
|
152
153
|
return results;
|
|
153
154
|
}
|
|
155
|
+
function readinessVerdictFact(verdict) {
|
|
156
|
+
return verdict === "confirmed" ? true : verdict === "denied" ? false : null;
|
|
157
|
+
}
|
|
154
158
|
function readinessFacts(report) {
|
|
155
159
|
const provider = typeof report.provider_repository === "string" && PROVIDER_REPO_RE.test(report.provider_repository)
|
|
156
160
|
? report.provider_repository
|
|
@@ -166,7 +170,10 @@ function readinessFacts(report) {
|
|
|
166
170
|
bring_up: bringUpFacts(report.bring_up),
|
|
167
171
|
unattended_conductor_allowed: boolOrNull(report.unattended?.conductor_allowed),
|
|
168
172
|
escalation_email_available: boolOrNull(report.unattended?.escalation_email_available),
|
|
169
|
-
|
|
173
|
+
// BAPI-1714 — the same shared-verdict mapping setup-epic reads from a full
|
|
174
|
+
// report: confirmed -> true, denied -> false, unknown -> null. The document
|
|
175
|
+
// format, version, and field type are unchanged.
|
|
176
|
+
repository_readiness_confirmed: readinessVerdictFact(repositoryReadinessVerdict(report)),
|
|
170
177
|
merge_execution_probe_skipped_reason: report.merge_execution?.probe_skipped_reason === LAUNCH_CONTEXT_PROBE_SKIPPED_REASON
|
|
171
178
|
? LAUNCH_CONTEXT_PROBE_SKIPPED_REASON
|
|
172
179
|
: null,
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
*
|
|
19
19
|
* - **Never force-updates an existing branch.** The push refspec has no leading
|
|
20
20
|
* `+`, so it can only create. A branch that already exists at any commit other
|
|
21
|
-
* than the held cut commit is a refusal, never a repoint.
|
|
21
|
+
* than the held cut commit is a refusal, never a repoint. The push skips
|
|
22
|
+
* client-side pre-push hooks (`--no-verify`) because it sends no new code; the
|
|
23
|
+
* comment at the push says why.
|
|
22
24
|
* - **Takes an already validated branch and SHA.** Callers validate the branch
|
|
23
25
|
* name (`validateBranchName`) and normalize the candidate SHA before calling;
|
|
24
26
|
* this module re-proves the SHA shape it pushes, but it is not a parser.
|
|
@@ -27,10 +29,12 @@
|
|
|
27
29
|
* only inside the typed client's headers.
|
|
28
30
|
* - **Every failure is classified, never thrown.** Callers get a discriminated
|
|
29
31
|
* outcome with operator-ready sentences and the bounded facts (expected and
|
|
30
|
-
* observed SHAs) they need to report; there is nothing to `try/catch`.
|
|
32
|
+
* observed SHAs) they need to report; there is nothing to `try/catch`. A failed
|
|
33
|
+
* push also carries a short, redacted tail of git's own output.
|
|
31
34
|
*/
|
|
32
35
|
import { execFile } from "node:child_process";
|
|
33
36
|
import { abandonIndexScopeCut, beginIndexScopeCut, commitIndexScopeCut, getIndexScopeStatus, } from "./bridge-client.js";
|
|
37
|
+
import { redactSecrets } from "../secret-redaction.js";
|
|
34
38
|
/**
|
|
35
39
|
* Poll bound for a scope bootstrap, shared by `implement-epic init` and
|
|
36
40
|
* `setup-epic`. A seed copies a repository's whole parse cache and the
|
|
@@ -96,6 +100,40 @@ export function normalizeCommitSha(value) {
|
|
|
96
100
|
const normalized = value.trim().toLowerCase();
|
|
97
101
|
return /^[0-9a-f]{40}$/.test(normalized) ? normalized : null;
|
|
98
102
|
}
|
|
103
|
+
/** How many trailing non-empty lines of git's output a failure message keeps. */
|
|
104
|
+
export const GIT_FAILURE_TAIL_MAX_LINES = 5;
|
|
105
|
+
/** The most characters of git's output a failure message keeps. */
|
|
106
|
+
export const GIT_FAILURE_TAIL_MAX_CHARS = 600;
|
|
107
|
+
/**
|
|
108
|
+
* A short, safe tail of a failed git command's output, or `null` when it said nothing.
|
|
109
|
+
*
|
|
110
|
+
* Without git's own words, a failed push reads the same whether a hook failed, a
|
|
111
|
+
* ruleset refused it, or the credentials were wrong. This keeps the last few
|
|
112
|
+
* non-empty lines of stderr (stdout when stderr is empty), strips color codes and
|
|
113
|
+
* other control characters, and redacts credentials: the shared
|
|
114
|
+
* {@link redactSecrets} patterns, plus the exact Bridge API key when one is given.
|
|
115
|
+
*/
|
|
116
|
+
export function gitFailureTail(result, apiKey) {
|
|
117
|
+
const raw = result.stderr.trim().length > 0 ? result.stderr : result.stdout;
|
|
118
|
+
const lines = raw
|
|
119
|
+
// ANSI CSI sequences (colors, cursor moves) and OSC sequences (titles, links).
|
|
120
|
+
.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "")
|
|
121
|
+
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "")
|
|
122
|
+
// Progress output redraws with a bare carriage return; treat it as a line break.
|
|
123
|
+
.split(/\r\n|\r|\n/)
|
|
124
|
+
.map((line) => line.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, "").trim())
|
|
125
|
+
.filter((line) => line.length > 0);
|
|
126
|
+
if (lines.length === 0)
|
|
127
|
+
return null;
|
|
128
|
+
let text = lines.slice(-GIT_FAILURE_TAIL_MAX_LINES).join(" | ");
|
|
129
|
+
if (apiKey && apiKey.length >= 4)
|
|
130
|
+
text = text.split(apiKey).join("[REDACTED]");
|
|
131
|
+
text = redactSecrets(text);
|
|
132
|
+
if (text.length > GIT_FAILURE_TAIL_MAX_CHARS) {
|
|
133
|
+
text = `...${text.slice(text.length - (GIT_FAILURE_TAIL_MAX_CHARS - 3))}`;
|
|
134
|
+
}
|
|
135
|
+
return text;
|
|
136
|
+
}
|
|
99
137
|
/**
|
|
100
138
|
* Read the head of `origin/<branch>` WITHOUT mutating anything.
|
|
101
139
|
*
|
|
@@ -207,17 +245,31 @@ export async function performExactIndexScopeCut(deps, access, request) {
|
|
|
207
245
|
// local checkout, no branch, no worktree — and deliberately not the GitHub
|
|
208
246
|
// App, which is `contents: read` and cannot create refs. Not a force push:
|
|
209
247
|
// the refspec has no leading `+`, so it can only create.
|
|
248
|
+
//
|
|
249
|
+
// `--no-verify` skips the repository's own client-side pre-push hook (tests,
|
|
250
|
+
// Husky, pre-commit) for THIS push only. The push sends no new code: it only
|
|
251
|
+
// names a branch at a commit the server already indexed from origin. A hook
|
|
252
|
+
// here would run inside the launch, with the operator's inherited
|
|
253
|
+
// environment, while the server's cut hold is open, and a hook failure would
|
|
254
|
+
// block the cut for reasons unrelated to it. Server-side branch protection
|
|
255
|
+
// and rulesets still apply. Pushes that carry new code (worker and
|
|
256
|
+
// child-branch pushes) keep running their hooks.
|
|
210
257
|
const pushed = await runGit(deps, [
|
|
211
258
|
"push",
|
|
259
|
+
"--no-verify",
|
|
212
260
|
"origin",
|
|
213
261
|
`${cut.cut_commit_sha}:refs/heads/${featureBranch}`,
|
|
214
262
|
]);
|
|
215
263
|
if (pushed.exitCode !== 0) {
|
|
264
|
+
// Keep git's own words (redacted), so the cause is visible: a hook, a
|
|
265
|
+
// ruleset, a network error, or credentials.
|
|
266
|
+
const gitSaid = gitFailureTail(pushed, access.apiKey);
|
|
216
267
|
return {
|
|
217
268
|
ok: false,
|
|
218
269
|
kind: "push_failed",
|
|
219
270
|
failures: [
|
|
220
|
-
`Could not create origin/${featureBranch} at the canonical indexed commit ${cut.cut_commit_sha}
|
|
271
|
+
`Could not create origin/${featureBranch} at the canonical indexed commit ${cut.cut_commit_sha}.` +
|
|
272
|
+
(gitSaid === null ? "" : ` git said: ${gitSaid}`),
|
|
221
273
|
],
|
|
222
274
|
lease: cut,
|
|
223
275
|
expectedSha: cut.cut_commit_sha,
|
|
@@ -66,6 +66,7 @@ import { buildLocalMergeChildEnv, sanitizeLocalMergeOutput, } from "../conductor
|
|
|
66
66
|
import { resolveMergeCredentialAtAction } from "../conductor/stored-merge-credential.js";
|
|
67
67
|
import { EPIC_INTEGRATION_PR_READ_TIMEOUT_MS, createProductionEpicIntegrationGhRunner, ensureEpicIntegrationPullRequest, } from "../epic-integration-pr.js";
|
|
68
68
|
import { EPIC_WORKAROUNDS_DIR_PATH } from "../epic-workarounds-path.js";
|
|
69
|
+
import { captureExecutorMergeIndex, stageExecutorAllowedTree, unstageExecutorExcludedPaths, } from "./permissions.js";
|
|
69
70
|
import { HANDOFF_REPORT_DETAIL_CODES, HANDOFF_REPORT_PAYLOAD_VERSION, HANDOFF_REPORT_SHAPES, INTEGRATION_ACTION_OPERATIONS, INTEGRATION_ACTION_OUTCOMES, INTEGRATION_ACTION_PROTOCOL_VERSION, MAX_HANDOFF_REPORT_COMMENT_CHARS, } from "./types.js";
|
|
70
71
|
/** The route prefix, mirrored from `api/routes/__init__.py`. */
|
|
71
72
|
export const INTEGRATION_ACTION_ROUTE_PREFIX = "/epic-integration-actions";
|
|
@@ -918,6 +919,9 @@ export function createIntegrationCorrectionDriver(action, deps) {
|
|
|
918
919
|
const baseSha = action.expected_base_sha;
|
|
919
920
|
const remoteUrl = `https://github.com/${action.provider_repository}.git`;
|
|
920
921
|
const destination = `refs/heads/${action.epic_branch}`;
|
|
922
|
+
// BAPI-1732: the protected-path index state of THIS action's conflicted merge.
|
|
923
|
+
// `null` is "not captured", distinct from a captured empty snapshot.
|
|
924
|
+
let mergeSnapshot = null;
|
|
921
925
|
const git = async (ctx, args, timeoutMs = GIT_TIMEOUT_MS, env) => {
|
|
922
926
|
try {
|
|
923
927
|
const r = await deps.runCommand("git", args, {
|
|
@@ -1025,6 +1029,21 @@ export function createIntegrationCorrectionDriver(action, deps) {
|
|
|
1025
1029
|
await restore(ctx);
|
|
1026
1030
|
return finish(complete({ outcome: "failed", detailCode: "merge_start_failed" }));
|
|
1027
1031
|
}
|
|
1032
|
+
// The merge's own protected-path index entries, kept so the worker's
|
|
1033
|
+
// staging of host files can be undone without losing them.
|
|
1034
|
+
mergeSnapshot = null;
|
|
1035
|
+
let captured = null;
|
|
1036
|
+
try {
|
|
1037
|
+
captured = await captureExecutorMergeIndex((args) => git(ctx, args));
|
|
1038
|
+
}
|
|
1039
|
+
catch {
|
|
1040
|
+
captured = null;
|
|
1041
|
+
}
|
|
1042
|
+
if (captured === null) {
|
|
1043
|
+
await restore(ctx);
|
|
1044
|
+
return finish(complete({ outcome: "failed", detailCode: "merge_start_failed" }));
|
|
1045
|
+
}
|
|
1046
|
+
mergeSnapshot = captured;
|
|
1028
1047
|
}
|
|
1029
1048
|
return {
|
|
1030
1049
|
kind: "spawn_worker",
|
|
@@ -1043,11 +1062,44 @@ export function createIntegrationCorrectionDriver(action, deps) {
|
|
|
1043
1062
|
await restore(ctx);
|
|
1044
1063
|
return complete({ outcome: "failed", detailCode: "worker_rewrote_history" });
|
|
1045
1064
|
}
|
|
1046
|
-
|
|
1065
|
+
const commitFailed = async () => {
|
|
1066
|
+
await restore(ctx);
|
|
1067
|
+
return complete({ outcome: "failed", detailCode: "commit_failed" });
|
|
1068
|
+
};
|
|
1069
|
+
const snapshot = mergeSnapshot;
|
|
1070
|
+
if (isConflict && snapshot === null)
|
|
1071
|
+
return commitFailed();
|
|
1072
|
+
// Stage the allowed tree only; protected host paths never enter the commit.
|
|
1073
|
+
try {
|
|
1074
|
+
await stageExecutorAllowedTree((args) => git(ctx, args));
|
|
1075
|
+
}
|
|
1076
|
+
catch {
|
|
1077
|
+
return commitFailed();
|
|
1078
|
+
}
|
|
1079
|
+
// Conflicted protected paths belong to the worker's resolution: stage exactly
|
|
1080
|
+
// those, in a call of their own.
|
|
1081
|
+
if (snapshot !== null && snapshot.conflicted.size > 0) {
|
|
1082
|
+
const literal = Array.from(snapshot.conflicted, (p) => `:(top,literal)${p}`);
|
|
1083
|
+
// `-f`: these paths are tracked and unmerged, but `info/exclude` also names
|
|
1084
|
+
// them, and Git refuses an ignored path without it.
|
|
1085
|
+
const resolved = await git(ctx, ["add", "-f", "--", ...literal]);
|
|
1086
|
+
if (resolved.exitCode !== 0)
|
|
1087
|
+
return commitFailed();
|
|
1088
|
+
}
|
|
1089
|
+
try {
|
|
1090
|
+
await unstageExecutorExcludedPaths((args) => git(ctx, args), isConflict ? (snapshot ?? undefined) : undefined);
|
|
1091
|
+
}
|
|
1092
|
+
catch {
|
|
1093
|
+
return commitFailed();
|
|
1094
|
+
}
|
|
1047
1095
|
if (isConflict) {
|
|
1048
1096
|
const unmerged = await git(ctx, ["ls-files", "-u"]);
|
|
1097
|
+
if (unmerged.exitCode !== 0)
|
|
1098
|
+
return commitFailed();
|
|
1049
1099
|
const markers = await git(ctx, ["grep", "--cached", "-n", "-I", "-E", "^(<{7}|>{7})( |$)"]);
|
|
1050
|
-
if (
|
|
1100
|
+
if (markers.exitCode !== 0 && markers.exitCode !== 1)
|
|
1101
|
+
return commitFailed();
|
|
1102
|
+
if (unmerged.stdout.trim().length > 0 || markers.exitCode === 0) {
|
|
1051
1103
|
await restore(ctx);
|
|
1052
1104
|
return complete({ outcome: "failed", detailCode: "conflicts_unresolved" });
|
|
1053
1105
|
}
|
|
@@ -1058,6 +1110,8 @@ export function createIntegrationCorrectionDriver(action, deps) {
|
|
|
1058
1110
|
await restore(ctx);
|
|
1059
1111
|
return complete({ outcome: "failed", detailCode: "correction_no_change" });
|
|
1060
1112
|
}
|
|
1113
|
+
if (staged.exitCode !== 1)
|
|
1114
|
+
return commitFailed();
|
|
1061
1115
|
}
|
|
1062
1116
|
const message = isConflict
|
|
1063
1117
|
? `Merge ${action.base_branch} into ${action.epic_branch}`
|
|
@@ -1694,7 +1694,10 @@ async function superviseFocusedRebaseWait(params) {
|
|
|
1694
1694
|
platform: deps.platform,
|
|
1695
1695
|
readFile: deps.readFile,
|
|
1696
1696
|
stat: deps.stat,
|
|
1697
|
-
}
|
|
1697
|
+
},
|
|
1698
|
+
// BAPI-1527: the rebase's own required-check list, so a repository with no
|
|
1699
|
+
// CI check cache is still read from live provider evidence.
|
|
1700
|
+
params.context.requiredChecks);
|
|
1698
1701
|
const phase = await superviseDriverPhase({
|
|
1699
1702
|
job,
|
|
1700
1703
|
httpClient,
|
|
@@ -89,6 +89,7 @@ export function readMergeJobPayloadFields(job, repositoryBaseBranch) {
|
|
|
89
89
|
const requiredChecks = Array.isArray(payload.required_checks)
|
|
90
90
|
? payload.required_checks.filter((c) => typeof c === "string")
|
|
91
91
|
: [];
|
|
92
|
+
const noCiGateDeclared = payload.no_ci_gate === true && requiredChecks.length === 0;
|
|
92
93
|
const actionKey = asString(payload.action_key) ?? `merge:pr-${prNumber}:${expectedHeadSha}`;
|
|
93
94
|
const ciWaitTimeoutMs = nonNegativeIntOrUndefined(payload.ci_wait_timeout_ms);
|
|
94
95
|
const ciWaitPollIntervalMs = nonNegativeIntOrUndefined(payload.ci_wait_poll_interval_ms);
|
|
@@ -100,6 +101,7 @@ export function readMergeJobPayloadFields(job, repositoryBaseBranch) {
|
|
|
100
101
|
expectedHeadSha,
|
|
101
102
|
method,
|
|
102
103
|
requiredChecks,
|
|
104
|
+
noCiGateDeclared,
|
|
103
105
|
actionKey,
|
|
104
106
|
ciWaitTimeoutMs,
|
|
105
107
|
ciWaitPollIntervalMs,
|
|
@@ -159,6 +161,10 @@ export function buildMergeJobResult(response, fields) {
|
|
|
159
161
|
result.commit_sha = mergeCommitSha;
|
|
160
162
|
result.head_sha = mergeCommitSha;
|
|
161
163
|
}
|
|
164
|
+
if (fields.noCiGateDeclared) {
|
|
165
|
+
// BAPI-1724: a declaration-based skipped wait, never a CI pass.
|
|
166
|
+
result.ci_wait = "skipped_no_ci_gate_declared";
|
|
167
|
+
}
|
|
162
168
|
return result;
|
|
163
169
|
}
|
|
164
170
|
/**
|
|
@@ -190,6 +196,22 @@ export const MERGE_REF_MISMATCH = "MergeRefMismatch";
|
|
|
190
196
|
* `merge_credential_no_access`.
|
|
191
197
|
*/
|
|
192
198
|
export const MERGE_CREDENTIAL_NO_ACCESS = "MergeCredentialNoAccess";
|
|
199
|
+
/**
|
|
200
|
+
* BAPI-1527 — a DELIBERATE, fail-closed refusal to merge: through the whole CI
|
|
201
|
+
* wait budget, the latest poll said the required-check configuration or provider
|
|
202
|
+
* access could not be read. That is not red CI, and it is never green evidence,
|
|
203
|
+
* so no merge happens. It is not a crash, so it is reported as `clean_exit`, and
|
|
204
|
+
* it is never a rebase target. Emitted only with the `ci_checks_unavailable`
|
|
205
|
+
* reason. It has its own kind (not {@link MERGE_RETRYABLE}) only so the server can
|
|
206
|
+
* name it: the server re-fires and retries it through the same merge budget as
|
|
207
|
+
* `ci_not_green`, and parks it as `merge_ci_checks_unavailable` only once that
|
|
208
|
+
* budget is spent — never earlier than a `ci_not_green` merge would park.
|
|
209
|
+
*
|
|
210
|
+
* Its sibling reason `ci_no_checks_observed` (a fallback poll saw no check at all
|
|
211
|
+
* before the wait budget ended) is a different shape: bounded absence of
|
|
212
|
+
* evidence, classified {@link MERGE_RETRYABLE}, with its own reason preserved.
|
|
213
|
+
*/
|
|
214
|
+
export const MERGE_CI_CHECKS_UNAVAILABLE = "MergeCiChecksUnavailable";
|
|
193
215
|
/**
|
|
194
216
|
* BAPI-1234 — the server's migration-graph merge guard refused the merge. Two
|
|
195
217
|
* kinds, kept distinct because they call for different human responses:
|
|
@@ -212,9 +234,24 @@ const MIGRATION_GRAPH_ERROR_KINDS = new Map([
|
|
|
212
234
|
const DELIBERATE_REFUSAL_ERROR_KINDS = new Set([
|
|
213
235
|
MERGE_REF_MISMATCH,
|
|
214
236
|
MERGE_CREDENTIAL_NO_ACCESS,
|
|
237
|
+
MERGE_CI_CHECKS_UNAVAILABLE,
|
|
215
238
|
MERGE_MIGRATION_GRAPH_INVALID,
|
|
216
239
|
MERGE_MIGRATION_GRAPH_UNREADABLE,
|
|
217
240
|
]);
|
|
241
|
+
/** BAPI-1527 — the local merge reason for unreadable check configuration. */
|
|
242
|
+
const CI_CHECKS_UNAVAILABLE_REASON = "ci_checks_unavailable";
|
|
243
|
+
/**
|
|
244
|
+
* BAPI-1527 — plain-language operator wording for the two new CI reasons. Fixed
|
|
245
|
+
* text only: it carries no provider body, credential, or exception text, and the
|
|
246
|
+
* named technical reason stays in the message as secondary context.
|
|
247
|
+
*/
|
|
248
|
+
const CI_REASON_SUMMARIES = new Map([
|
|
249
|
+
[
|
|
250
|
+
CI_CHECKS_UNAVAILABLE_REASON,
|
|
251
|
+
"CI checks unavailable: required-check configuration or provider access could not be read",
|
|
252
|
+
],
|
|
253
|
+
["ci_no_checks_observed", "No provider checks observed for this commit yet"],
|
|
254
|
+
]);
|
|
218
255
|
/** Reasons whose failure is transient/infrastructure and safe to retry. */
|
|
219
256
|
const RETRYABLE_MERGE_REASONS = new Set([
|
|
220
257
|
"gh_pr_view_timeout",
|
|
@@ -222,6 +259,7 @@ const RETRYABLE_MERGE_REASONS = new Set([
|
|
|
222
259
|
"gh_pr_view_unparseable",
|
|
223
260
|
"ci_poll_failed",
|
|
224
261
|
"ci_not_green",
|
|
262
|
+
"ci_no_checks_observed",
|
|
225
263
|
"gh_merge_timeout",
|
|
226
264
|
"gh_merge_failed",
|
|
227
265
|
"merge_aborted",
|
|
@@ -259,6 +297,8 @@ export function classifyMergeFailureErrorKind(response) {
|
|
|
259
297
|
return MERGE_CREDENTIAL_NO_ACCESS;
|
|
260
298
|
if (reason === "ref_mismatch")
|
|
261
299
|
return MERGE_REF_MISMATCH;
|
|
300
|
+
if (reason === CI_CHECKS_UNAVAILABLE_REASON)
|
|
301
|
+
return MERGE_CI_CHECKS_UNAVAILABLE;
|
|
262
302
|
const migrationGraphKind = reason ? MIGRATION_GRAPH_ERROR_KINDS.get(reason) : undefined;
|
|
263
303
|
if (migrationGraphKind)
|
|
264
304
|
return migrationGraphKind;
|
|
@@ -293,7 +333,9 @@ export function buildMergeJobFailure(response) {
|
|
|
293
333
|
const errorKind = classifyMergeFailureErrorKind(response);
|
|
294
334
|
return {
|
|
295
335
|
error_kind: errorKind,
|
|
296
|
-
error_message: secretFreeErrorMessage(new Error(
|
|
336
|
+
error_message: secretFreeErrorMessage(new Error(CI_REASON_SUMMARIES.has(reason)
|
|
337
|
+
? `local merge ${response.status}: ${CI_REASON_SUMMARIES.get(reason)} (reason=${reason})`
|
|
338
|
+
: `local merge ${response.status}: ${reason}`)),
|
|
297
339
|
classification: DELIBERATE_REFUSAL_ERROR_KINDS.has(errorKind) ? "clean_exit" : "crashed",
|
|
298
340
|
telemetry: { failure_reason_code: mergeResponseReasonCode(response) },
|
|
299
341
|
};
|
|
@@ -366,6 +408,8 @@ export async function runExecutorMergeJob(job, seams) {
|
|
|
366
408
|
method: fields.method,
|
|
367
409
|
ciWaitTimeoutMs: fields.ciWaitTimeoutMs,
|
|
368
410
|
ciWaitPollIntervalMs: fields.ciWaitPollIntervalMs,
|
|
411
|
+
// BAPI-1724: separate from `skipCiWait`, which has its own meaning.
|
|
412
|
+
noCiGateDeclared: fields.noCiGateDeclared,
|
|
369
413
|
// BAPI-1021 (AC-11): pass the already-resolved expectations through
|
|
370
414
|
// unchanged so verification and the post-merge enrichment below use one
|
|
371
415
|
// authoritative value — neither re-resolves it independently.
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
import { randomUUID } from "node:crypto";
|
|
39
39
|
import path from "node:path";
|
|
40
40
|
import { acquireExcludeLock } from "../git-exclude-lock.js";
|
|
41
|
+
import { PHASE_RESULT_SUBDIR } from "../phase-result-artifacts.js";
|
|
41
42
|
import { mergeClaudeSettingsWithAutoMemoryDisabled, mergeClaudeSettingsWithCommandHook, provisionClaudeSettingsForWorktree, DEFAULT_PRE_TOOL_USE_MATCHER, } from "../claude-settings.js";
|
|
42
43
|
/**
|
|
43
44
|
* BAPI-1647: one exact `Read(<path>)` rule per distinct restricted source path,
|
|
@@ -323,11 +324,52 @@ export const EXECUTOR_CONDUCTOR_EXCLUDE_LINE = ".conductor/";
|
|
|
323
324
|
* Every line the executor provisions into a worktree's `.git/info/exclude`, in
|
|
324
325
|
* the order they are appended. Named once so the writer and its tests cannot
|
|
325
326
|
* disagree about the set.
|
|
327
|
+
*
|
|
328
|
+
* These lines are ADDITIONAL protection only: they keep untracked host files out
|
|
329
|
+
* of a plain `git add`. They do not protect a file that is already tracked or
|
|
330
|
+
* already staged. The executor's real boundary is the pathspec list built from
|
|
331
|
+
* {@link EXECUTOR_STAGE_EXCLUDES}, which every executor-owned `git add` and
|
|
332
|
+
* `git status` passes. The phase-result directory is a filesystem-only ledger
|
|
333
|
+
* (`../phase-result-artifacts.ts`): it never needs to be committed, so it is
|
|
334
|
+
* excluded at every depth, including a customer directory of the same name.
|
|
326
335
|
*/
|
|
327
336
|
export const EXECUTOR_EXCLUDE_LINES = [
|
|
328
337
|
EXECUTOR_SETTINGS_EXCLUDE_LINE,
|
|
329
338
|
EXECUTOR_CONDUCTOR_EXCLUDE_LINE,
|
|
339
|
+
".mcp.json",
|
|
340
|
+
".cursor/mcp.json",
|
|
341
|
+
`${PHASE_RESULT_SUBDIR}/`,
|
|
342
|
+
];
|
|
343
|
+
/** The phase-result staging pattern: any directory of that name, at any depth. */
|
|
344
|
+
const PHASE_RESULT_STAGE_PATTERN = `**/${PHASE_RESULT_SUBDIR}/**`;
|
|
345
|
+
/**
|
|
346
|
+
* Paths no executor-owned commit may stage (the shared staging policy).
|
|
347
|
+
*
|
|
348
|
+
* Host configuration (`.mcp.json`, `.cursor/mcp.json`) is excluded by its
|
|
349
|
+
* ROOT-RELATIVE path only: there is deliberately no any-depth MCP glob, so a
|
|
350
|
+
* customer's nested `packages/app/.mcp.json` stays committable. Phase results are
|
|
351
|
+
* the one any-depth entry, written as a glob. Executor-owned settings and
|
|
352
|
+
* conductor artifacts complete the list.
|
|
353
|
+
*/
|
|
354
|
+
export const EXECUTOR_STAGE_EXCLUDES = [
|
|
355
|
+
".mcp.json",
|
|
356
|
+
".cursor/mcp.json",
|
|
357
|
+
PHASE_RESULT_STAGE_PATTERN,
|
|
358
|
+
EXECUTOR_SETTINGS_EXCLUDE_LINE,
|
|
359
|
+
EXECUTOR_CONDUCTOR_EXCLUDE_LINE,
|
|
330
360
|
];
|
|
361
|
+
function stagePathspec(entry, exclude) {
|
|
362
|
+
const magic = ["top", ...(exclude ? ["exclude"] : []), ...(entry === PHASE_RESULT_STAGE_PATTERN ? ["glob"] : [])];
|
|
363
|
+
return `:(${magic.join(",")})${entry}`;
|
|
364
|
+
}
|
|
365
|
+
/** `:(top,exclude)<path>` pathspecs for `git add` / `git status` (root-relative). */
|
|
366
|
+
export function executorStageExcludePathspecs() {
|
|
367
|
+
return EXECUTOR_STAGE_EXCLUDES.map((entry) => stagePathspec(entry, true));
|
|
368
|
+
}
|
|
369
|
+
/** `:(top)<path>` pathspecs selecting the same entries, for index inspection and reset. */
|
|
370
|
+
export function executorStagePositivePathspecs() {
|
|
371
|
+
return EXECUTOR_STAGE_EXCLUDES.map((entry) => stagePathspec(entry, false));
|
|
372
|
+
}
|
|
331
373
|
/**
|
|
332
374
|
* Build the one bounded shape every exclude-provisioning warning takes: a
|
|
333
375
|
* failure CATEGORY plus the affected worktree path, and nothing else.
|
|
@@ -339,7 +381,7 @@ export const EXECUTOR_EXCLUDE_LINES = [
|
|
|
339
381
|
*/
|
|
340
382
|
function excludeWarning(worktreePath, category) {
|
|
341
383
|
return (`worktree git-exclude provisioning did not complete for ${worktreePath}: ${category}. ` +
|
|
342
|
-
`${EXECUTOR_EXCLUDE_LINES.join("
|
|
384
|
+
`${EXECUTOR_EXCLUDE_LINES.join(", ")} are not protected from worker commits on this ` +
|
|
343
385
|
"worktree; inspect it before trusting the worktree's staged changes; continuing fail-open.");
|
|
344
386
|
}
|
|
345
387
|
const EXCLUDE_UNRESOLVED_CATEGORY = {
|
|
@@ -491,7 +533,9 @@ export async function resolveWorktreeSettingsExclude(worktreePath, deps) {
|
|
|
491
533
|
}
|
|
492
534
|
/**
|
|
493
535
|
* Keep the executor-owned `.claude/settings.local.json` and the conductor's
|
|
494
|
-
* `.conductor/` artifacts
|
|
536
|
+
* `.conductor/` artifacts, plus host MCP files and phase-result directories, out
|
|
537
|
+
* of worker commits (BAPI-740/F2, BAPI-814/D2, BAPI-1732). This is untracked-file
|
|
538
|
+
* protection only; the staging pathspecs are the executor's boundary.
|
|
495
539
|
* Worker-config isolation redirects `XDG_CONFIG_HOME`, so the
|
|
496
540
|
* operator's global git excludes (`~/.config/git/ignore`) no longer apply inside
|
|
497
541
|
* a worker — empirically, a worker `git add -A` commits the deny-layer file this
|
|
@@ -590,6 +634,147 @@ export async function provisionWorktreeSettingsExclude(worktreePath, deps) {
|
|
|
590
634
|
await lock.release();
|
|
591
635
|
}
|
|
592
636
|
}
|
|
637
|
+
const INDEX_HEADER = /^([0-7]{6}) ([0-9a-f]{40}|[0-9a-f]{64}) ([0-3])$/;
|
|
638
|
+
// Bounded, fixed messages: never Git output, environment values, or file content.
|
|
639
|
+
function indexError(category) {
|
|
640
|
+
return new Error(`executor index protection failed: ${category}`);
|
|
641
|
+
}
|
|
642
|
+
function parseIndexRecords(stdout) {
|
|
643
|
+
const parts = stdout.split("\0");
|
|
644
|
+
if (parts.length > 0 && parts[parts.length - 1] === "")
|
|
645
|
+
parts.pop();
|
|
646
|
+
return parts.map((record) => {
|
|
647
|
+
const tab = record.indexOf("\t");
|
|
648
|
+
if (tab < 0)
|
|
649
|
+
throw indexError("malformed index listing");
|
|
650
|
+
const header = INDEX_HEADER.exec(record.slice(0, tab));
|
|
651
|
+
const entryPath = record.slice(tab + 1);
|
|
652
|
+
if (!header || entryPath.length === 0)
|
|
653
|
+
throw indexError("malformed index listing");
|
|
654
|
+
return { mode: header[1], sha: header[2], stage: Number(header[3]), path: entryPath };
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
async function listProtectedIndex(git) {
|
|
658
|
+
const listed = await git([
|
|
659
|
+
"ls-files", "--stage", "--full-name", "-z", "--", ...executorStagePositivePathspecs(),
|
|
660
|
+
]);
|
|
661
|
+
if (listed.exitCode !== 0)
|
|
662
|
+
throw indexError("index listing failed");
|
|
663
|
+
return parseIndexRecords(listed.stdout);
|
|
664
|
+
}
|
|
665
|
+
/** `:(top)` plus every protected exclusion: the whole repository minus protected paths. */
|
|
666
|
+
export function executorAllowedTreePathspecs() {
|
|
667
|
+
return [":(top)", ...executorStageExcludePathspecs()];
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Stage every allowed change (`git add -A`) without ever staging a protected path.
|
|
671
|
+
*
|
|
672
|
+
* Git exits 1 from `add` when a pathspec literally names a file that
|
|
673
|
+
* `info/exclude` also ignores, and the exclusion entries count as such a mention.
|
|
674
|
+
* In a provisioned worktree that is the normal case (`.conductor/` and the
|
|
675
|
+
* settings file always exist), so exit 1 alone is not a failure. It is accepted
|
|
676
|
+
* only when a status read then proves nothing allowed is left unstaged; any other
|
|
677
|
+
* exit, or a leftover allowed change, throws. This never depends on Git's
|
|
678
|
+
* localized message text.
|
|
679
|
+
*/
|
|
680
|
+
export async function stageExecutorAllowedTree(git) {
|
|
681
|
+
const scope = executorAllowedTreePathspecs();
|
|
682
|
+
const added = await git(["add", "-A", "--", ...scope]);
|
|
683
|
+
if (added.exitCode === 0)
|
|
684
|
+
return;
|
|
685
|
+
if (added.exitCode !== 1)
|
|
686
|
+
throw indexError("staging failed");
|
|
687
|
+
const status = await git(["status", "--porcelain", "--", ...scope]);
|
|
688
|
+
if (status.exitCode !== 0)
|
|
689
|
+
throw indexError("staging check failed");
|
|
690
|
+
const unmerged = /^(?:DD|AU|UD|UA|DU|AA|UU)$/;
|
|
691
|
+
for (const line of status.stdout.split("\n")) {
|
|
692
|
+
if (line.length < 3)
|
|
693
|
+
continue;
|
|
694
|
+
const xy = line.slice(0, 2);
|
|
695
|
+
// An unmerged entry is the caller's conflict check to judge, not a staging fault.
|
|
696
|
+
if (unmerged.test(xy))
|
|
697
|
+
continue;
|
|
698
|
+
if (xy[1] !== " ")
|
|
699
|
+
throw indexError("staging incomplete");
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Capture the protected-path index state of a freshly started merge. Fails closed:
|
|
704
|
+
* a failed or malformed listing rejects rather than returning an empty snapshot.
|
|
705
|
+
*/
|
|
706
|
+
export async function captureExecutorMergeIndex(git) {
|
|
707
|
+
const records = await listProtectedIndex(git);
|
|
708
|
+
const conflicted = new Set();
|
|
709
|
+
const restore = [];
|
|
710
|
+
for (const rec of records) {
|
|
711
|
+
if (rec.stage !== 0)
|
|
712
|
+
conflicted.add(rec.path);
|
|
713
|
+
}
|
|
714
|
+
for (const rec of records) {
|
|
715
|
+
if (rec.stage === 0 && !conflicted.has(rec.path)) {
|
|
716
|
+
restore.push({ mode: rec.mode, sha: rec.sha, path: rec.path });
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return { restore, conflicted };
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Undo executor-created index changes to protected paths, touching the index only.
|
|
723
|
+
* Working-tree files are never modified.
|
|
724
|
+
*
|
|
725
|
+
* - Without a snapshot (not a merge): `git reset -q HEAD -- <protected>` returns
|
|
726
|
+
* tracked entries to HEAD and drops newly staged protected files.
|
|
727
|
+
* - With a snapshot (a conflicted merge): protected entries the merge itself
|
|
728
|
+
* produced are restored, entries added since are removed, and paths that were
|
|
729
|
+
* conflicted at capture are left to the worker's resolution. HEAD is not used,
|
|
730
|
+
* because that would erase legitimate merge content.
|
|
731
|
+
*/
|
|
732
|
+
export async function unstageExecutorExcludedPaths(git, snapshot) {
|
|
733
|
+
if (snapshot === undefined) {
|
|
734
|
+
const reset = await git(["reset", "-q", "HEAD", "--", ...executorStagePositivePathspecs()]);
|
|
735
|
+
if (reset.exitCode !== 0)
|
|
736
|
+
throw indexError("reset failed");
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const current = await listProtectedIndex(git);
|
|
740
|
+
const currentStageZero = new Map();
|
|
741
|
+
for (const rec of current) {
|
|
742
|
+
if (rec.stage === 0)
|
|
743
|
+
currentStageZero.set(rec.path, { mode: rec.mode, sha: rec.sha, path: rec.path });
|
|
744
|
+
}
|
|
745
|
+
const wanted = new Map(snapshot.restore.map((rec) => [rec.path, rec]));
|
|
746
|
+
const removals = [];
|
|
747
|
+
for (const rec of current) {
|
|
748
|
+
if (snapshot.conflicted.has(rec.path) || wanted.has(rec.path))
|
|
749
|
+
continue;
|
|
750
|
+
if (!removals.includes(rec.path))
|
|
751
|
+
removals.push(rec.path);
|
|
752
|
+
}
|
|
753
|
+
const restores = snapshot.restore.filter((rec) => {
|
|
754
|
+
const now = currentStageZero.get(rec.path);
|
|
755
|
+
return !now || now.mode !== rec.mode || now.sha !== rec.sha;
|
|
756
|
+
});
|
|
757
|
+
if (removals.length === 0 && restores.length === 0)
|
|
758
|
+
return;
|
|
759
|
+
// `update-index` takes cwd-relative paths while the listing is root-relative, so
|
|
760
|
+
// pin these calls to the repository root through the same injected closure.
|
|
761
|
+
const top = await git(["rev-parse", "--show-toplevel"]);
|
|
762
|
+
const root = top.stdout.replace(/\r?\n$/, "");
|
|
763
|
+
if (top.exitCode !== 0 || root.length === 0)
|
|
764
|
+
throw indexError("repository root lookup failed");
|
|
765
|
+
for (const entryPath of removals) {
|
|
766
|
+
const removed = await git(["-C", root, "update-index", "--force-remove", "--", entryPath]);
|
|
767
|
+
if (removed.exitCode !== 0)
|
|
768
|
+
throw indexError("index removal failed");
|
|
769
|
+
}
|
|
770
|
+
for (const rec of restores) {
|
|
771
|
+
const restored = await git([
|
|
772
|
+
"-C", root, "update-index", "--add", "--cacheinfo", `${rec.mode},${rec.sha},${rec.path}`,
|
|
773
|
+
]);
|
|
774
|
+
if (restored.exitCode !== 0)
|
|
775
|
+
throw indexError("index restoration failed");
|
|
776
|
+
}
|
|
777
|
+
}
|
|
593
778
|
/**
|
|
594
779
|
* Provision the executor deny layer into `<worktree>/.claude/settings.local.json`,
|
|
595
780
|
* and shield that file from worker commits via `.git/info/exclude` (BAPI-740/F2).
|
|
@@ -10,28 +10,51 @@
|
|
|
10
10
|
* worktree, pushes nothing, and decides no gate — the server's completion
|
|
11
11
|
* verifier stays the authority for both lanes (R14 rule 3).
|
|
12
12
|
*/
|
|
13
|
-
import { pollCiChecksForCommit, resolveConductorBridgeApiAccess, } from "../conductor/bridge-api-client.js";
|
|
13
|
+
import { pollCiChecksForCommit, classifyCiPollAvailability, resolveConductorBridgeApiAccess, } from "../conductor/bridge-api-client.js";
|
|
14
14
|
import { allRequiredChecksGreen } from "../conductor/local-merge.js";
|
|
15
15
|
export { allRequiredChecksGreen };
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Thrown by a provider-check poller that cannot observe checks at all: it has no
|
|
18
|
+
* Bridge API access, or the server reported the check configuration unreadable.
|
|
19
|
+
* Waiting cannot fix either, so a caller ends its wait instead of reading the
|
|
20
|
+
* missing evidence as pending checks.
|
|
21
|
+
*/
|
|
17
22
|
export class ProviderChecksUnobservable extends Error {
|
|
23
|
+
reason;
|
|
24
|
+
constructor(message, reason = "access_unavailable") {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ProviderChecksUnobservable";
|
|
27
|
+
this.reason = reason;
|
|
28
|
+
}
|
|
18
29
|
}
|
|
19
30
|
/**
|
|
20
31
|
* A provider-check poller that resolves Bridge API access once, on first use —
|
|
21
32
|
* the same read-only CI poll the `merge` job waits on. Without access it throws
|
|
22
33
|
* {@link ProviderChecksUnobservable}, so a caller can end its wait immediately
|
|
23
34
|
* rather than sleeping out the job budget on evidence it can never read.
|
|
35
|
+
*
|
|
36
|
+
* BAPI-1527: `requiredChecks` is forwarded on every poll so a repository with no
|
|
37
|
+
* CI check cache is judged on live provider evidence. A caller that learns its
|
|
38
|
+
* list only per job may pass it as the second argument of the returned poller,
|
|
39
|
+
* which then overrides the constructed list. A response saying the check
|
|
40
|
+
* configuration or provider access could not be read throws
|
|
41
|
+
* {@link ProviderChecksUnobservable} with reason `checks_configuration_unavailable`
|
|
42
|
+
* rather than passing through as an unremarkable "not green yet".
|
|
24
43
|
*/
|
|
25
|
-
export function lazyProviderCheckPoller(accessDeps) {
|
|
44
|
+
export function lazyProviderCheckPoller(accessDeps, requiredChecks = []) {
|
|
26
45
|
let access;
|
|
27
|
-
return async (sha) => {
|
|
46
|
+
return async (sha, requiredChecksOverride) => {
|
|
28
47
|
if (access === undefined) {
|
|
29
48
|
const resolved = await resolveConductorBridgeApiAccess(accessDeps);
|
|
30
49
|
access = resolved.ok ? resolved.access : null;
|
|
31
50
|
}
|
|
32
51
|
if (access === null)
|
|
33
52
|
throw new ProviderChecksUnobservable("bridge api access unavailable");
|
|
34
|
-
|
|
53
|
+
const response = await pollCiChecksForCommit(access, sha, undefined, requiredChecksOverride ?? requiredChecks);
|
|
54
|
+
if (classifyCiPollAvailability(response) === "configuration_unavailable") {
|
|
55
|
+
throw new ProviderChecksUnobservable("required-check configuration or provider access could not be read", "checks_configuration_unavailable");
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
35
58
|
};
|
|
36
59
|
}
|
|
37
60
|
/** Conclusions that PROVE a check failed, as opposed to not having finished. */
|