@bridge_gpt/mcp-server 0.2.71 → 0.2.72
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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +19 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +4 -4
- package/build/bridge-permissions.js +4 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +518 -23
- package/build/conductor/doctor.js +84 -10
- package/build/conductor/epic-implementer-cli.js +51 -2
- package/build/conductor/gate-discovery.js +136 -10
- package/build/conductor/gate-settings-review.js +305 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-plan.js +42 -2
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +21 -8
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +223 -13
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +52 -11
- package/build/epic-implementer-bin.js +118 -43
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +67 -2
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +246 -28
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/prompt-spec.js +13 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +54 -2
- package/build/executor/worker-database.js +271 -31
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-verification-guidance.js +37 -2
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +679 -278
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +236 -42
- package/build/install-bridge-conductor-setup.js +115 -26
- package/build/install-bridge-conductor.js +448 -350
- package/build/install-bridge.js +418 -123
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +2 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +5 -5
- package/build/plan-execution-ledger.js +148 -2
- package/build/plane/plane-freshness.js +6 -7
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +24 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +50 -8
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +2 -2
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-enrollment.js +21 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +40 -15
- package/package.json +1 -1
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The interactive review of discovered CI settings (BAPI-1520).
|
|
3
3
|
*
|
|
4
|
-
* `install-
|
|
4
|
+
* `install epic-implementer` can propose two optional settings beside the gate:
|
|
5
5
|
*
|
|
6
6
|
* - **worker variables** — literal environment values found in CI config; and
|
|
7
7
|
* - **local reproduction hints** — a structured command for a reported provider
|
|
8
8
|
* check, so a worker can reproduce a failing check locally.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* BAPI-1551 adds two more, reviewed in the same step:
|
|
11
|
+
*
|
|
12
|
+
* - **dependency refresh** — `{cwd, argv, lockfiles}` entries the executor runs
|
|
13
|
+
* before a worker starts, only when a declared lockfile changed; and
|
|
14
|
+
* - **CI database behavior** — whether the repository's CI runs with a database
|
|
15
|
+
* (`none`, `provided`, or `unknown`).
|
|
16
|
+
*
|
|
17
|
+
* All are high-trust: a value is confirmed by the repository owner, one decision
|
|
18
|
+
* at a time, and only in an interactive terminal. An install argv is shown and
|
|
19
|
+
* edited only here, as an argument array, never as a shell string.
|
|
13
20
|
*
|
|
14
21
|
* ## Why values stay in this module
|
|
15
22
|
*
|
|
@@ -26,6 +33,7 @@
|
|
|
26
33
|
* an empty `workerEnv` list is a deliberate removal of every stored variable.
|
|
27
34
|
*/
|
|
28
35
|
import { LOCAL_COMMAND_TIMEOUT_SECONDS, } from "./gate-discovery.js";
|
|
36
|
+
import { CI_DATABASE_DEFAULT, MAX_DEPENDENCY_INSTALL_ENTRIES, MAX_DEPENDENCY_INSTALL_LOCKFILES, admitDependencyInstallDeclarations, dependencyInstallEntryIdentity, isCiDatabase, isSafeRepoRelativePath, sameDependencyInstall, } from "../dependency-install-declarations.js";
|
|
29
37
|
/** Limits that mirror `gate_profile.py` for hand-typed hints. */
|
|
30
38
|
const MAX_HINT_WORDS = 32;
|
|
31
39
|
const MAX_HINT_WORD_CHARS = 1024;
|
|
@@ -88,6 +96,14 @@ export function workerEnvEqual(a, b) {
|
|
|
88
96
|
export function hintEqual(a, b) {
|
|
89
97
|
return (a.timeout_seconds === b.timeout_seconds && a.argv.length === b.argv.length && a.argv.every((w, i) => w === b.argv[i]));
|
|
90
98
|
}
|
|
99
|
+
/** BAPI-1551 — whether two dependency-refresh lists are the same (absent is empty; order matters). */
|
|
100
|
+
export function dependencyInstallEqual(a, b) {
|
|
101
|
+
return sameDependencyInstall(a ?? [], b ?? []);
|
|
102
|
+
}
|
|
103
|
+
/** BAPI-1551 — the stored `ci_database`; absent is `unknown`. */
|
|
104
|
+
export function storedCiDatabase(stored) {
|
|
105
|
+
return stored?.ci_database ?? CI_DATABASE_DEFAULT;
|
|
106
|
+
}
|
|
91
107
|
/**
|
|
92
108
|
* Whether `edit` leaves the stored settings exactly as they are. Omitted
|
|
93
109
|
* settings and per-check hints resolve against `stored` first, so a request
|
|
@@ -96,6 +112,11 @@ export function hintEqual(a, b) {
|
|
|
96
112
|
export function settingsMatchStored(edit, stored) {
|
|
97
113
|
if (edit.workerEnv !== undefined && !workerEnvEqual(edit.workerEnv, stored?.worker_env))
|
|
98
114
|
return false;
|
|
115
|
+
if (edit.dependencyInstall !== undefined && !dependencyInstallEqual(edit.dependencyInstall, stored?.dependency_install)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (edit.ciDatabase !== undefined && edit.ciDatabase !== storedCiDatabase(stored))
|
|
119
|
+
return false;
|
|
99
120
|
for (const [check, hint] of edit.reproduce ?? []) {
|
|
100
121
|
const current = stored?.reproduction_hints?.get(check) ?? null;
|
|
101
122
|
if (hint === null) {
|
|
@@ -182,7 +203,38 @@ export function hasSettingsToReview(proposal, stored, providerChecks) {
|
|
|
182
203
|
return (proposal.workerEnvCandidates.length > 0 ||
|
|
183
204
|
(stored?.worker_env?.length ?? 0) > 0 ||
|
|
184
205
|
proposal.workerEnvConflicts.length > 0 ||
|
|
185
|
-
hintRows(proposal, stored, providerChecks).some((r) => r.stored !== null || r.proposed !== null)
|
|
206
|
+
hintRows(proposal, stored, providerChecks).some((r) => r.stored !== null || r.proposed !== null) ||
|
|
207
|
+
hasDeclarationsToReview(proposal, stored));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* BAPI-1551 — whether the dependency-refresh or CI-database declarations have
|
|
211
|
+
* anything stored or newly proposed.
|
|
212
|
+
*/
|
|
213
|
+
export function hasDeclarationsToReview(proposal, stored) {
|
|
214
|
+
return ((stored?.dependency_install?.length ?? 0) > 0 ||
|
|
215
|
+
newDependencyProposals(proposal, stored).length > 0 ||
|
|
216
|
+
storedCiDatabase(stored) !== CI_DATABASE_DEFAULT ||
|
|
217
|
+
proposedCiDatabase(proposal) !== CI_DATABASE_DEFAULT);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* BAPI-1551 — whether discovery proposes a declaration the stored profile does
|
|
221
|
+
* not already hold. This is the advisory gate change setup offers; it is never a
|
|
222
|
+
* blocking item.
|
|
223
|
+
*/
|
|
224
|
+
export function hasUnstoredDeclarationProposal(proposal, stored) {
|
|
225
|
+
const ci = proposedCiDatabase(proposal);
|
|
226
|
+
return newDependencyProposals(proposal, stored).length > 0 || (ci !== CI_DATABASE_DEFAULT && ci !== storedCiDatabase(stored));
|
|
227
|
+
}
|
|
228
|
+
/** Proposed entries whose identity (cwd and lockfiles) is not stored with the same argv. */
|
|
229
|
+
function newDependencyProposals(proposal, stored) {
|
|
230
|
+
const storedList = stored?.dependency_install ?? [];
|
|
231
|
+
return (proposal.dependencyInstallCandidates ?? []).filter((c) => !storedList.some((e) => dependencyInstallEqual([entryOf(c)], [e])));
|
|
232
|
+
}
|
|
233
|
+
function entryOf(candidate) {
|
|
234
|
+
return { cwd: candidate.cwd, argv: [...candidate.argv], lockfiles: [...candidate.lockfiles] };
|
|
235
|
+
}
|
|
236
|
+
function proposedCiDatabase(proposal) {
|
|
237
|
+
return proposal.ciDatabaseProposal?.value ?? CI_DATABASE_DEFAULT;
|
|
186
238
|
}
|
|
187
239
|
/**
|
|
188
240
|
* Print the review surface. Values appear only when `showValues` is true (an
|
|
@@ -252,8 +304,64 @@ export function renderSettingsReview(io, proposal, stored, providerChecks, showV
|
|
|
252
304
|
if (proposal.reproductionHintsSkipped.length > 0) {
|
|
253
305
|
io.log(` Not proposed (no single plain command could be read for): ${safeList(proposal.reproductionHintsSkipped)}`);
|
|
254
306
|
}
|
|
307
|
+
// Shown only when there is something to say, so a review without either
|
|
308
|
+
// declaration renders exactly as it did before BAPI-1551.
|
|
309
|
+
if (hasDeclarationsToReview(proposal, stored) || (proposal.dependencyInstallNotes?.length ?? 0) > 0) {
|
|
310
|
+
renderDeclarationsReview(io, proposal, stored, showValues);
|
|
311
|
+
}
|
|
255
312
|
io.log("");
|
|
256
313
|
}
|
|
314
|
+
const CI_DATABASE_TEXT = Object.freeze({
|
|
315
|
+
none: "none — CI runs without a database",
|
|
316
|
+
provided: "provided — CI provides a database",
|
|
317
|
+
unknown: "unknown — not declared",
|
|
318
|
+
});
|
|
319
|
+
const DEPENDENCY_NOTE_TEXT = Object.freeze({
|
|
320
|
+
dependency_install_pip_not_proposed: "A pip requirements file was found. It is not proposed: a bare pip install would use whatever " +
|
|
321
|
+
"Python is first on the executor's PATH, not this worktree's environment. Add an entry by hand if you need one.",
|
|
322
|
+
dependency_install_toolchain_unresolved: "The repository's toolchains could not be read with certainty, so nothing is proposed.",
|
|
323
|
+
});
|
|
324
|
+
/** One entry as a person reads it: where it runs and what it watches first, then the command. */
|
|
325
|
+
function describeDependencyEntry(entry, label, showValues) {
|
|
326
|
+
const where = entry.cwd === "." ? "repository root" : terminalSafe(entry.cwd);
|
|
327
|
+
const lines = [`${where}, when ${safeList(entry.lockfiles)} change${entry.lockfiles.length === 1 ? "s" : ""}${label ? ` (${label})` : ""}`];
|
|
328
|
+
lines.push(showValues
|
|
329
|
+
? ` runs: ${entry.argv.map(terminalSafe).join(" ")}`
|
|
330
|
+
: " (the install command is shown only in a terminal)");
|
|
331
|
+
return lines;
|
|
332
|
+
}
|
|
333
|
+
/** BAPI-1551 — the Dependency refresh and CI database behavior groups. */
|
|
334
|
+
function renderDeclarationsReview(io, proposal, stored, showValues) {
|
|
335
|
+
io.log("");
|
|
336
|
+
io.log(" Dependency refresh — before a worker starts, reinstall dependencies when a lockfile changed.");
|
|
337
|
+
const storedList = stored?.dependency_install ?? [];
|
|
338
|
+
const proposals = newDependencyProposals(proposal, stored);
|
|
339
|
+
if (storedList.length === 0 && proposals.length === 0)
|
|
340
|
+
io.log(" None stored and none proposed.");
|
|
341
|
+
storedList.forEach((entry) => {
|
|
342
|
+
const [first, ...rest] = describeDependencyEntry(entry, null, showValues);
|
|
343
|
+
io.log(` ${first} — Stored`);
|
|
344
|
+
for (const line of rest)
|
|
345
|
+
io.log(line);
|
|
346
|
+
});
|
|
347
|
+
proposals.forEach((candidate, index) => {
|
|
348
|
+
const [first, ...rest] = describeDependencyEntry(candidate, candidate.label, showValues);
|
|
349
|
+
io.log(` [${index + 1}] ${first} — Proposed`);
|
|
350
|
+
for (const line of rest)
|
|
351
|
+
io.log(line);
|
|
352
|
+
});
|
|
353
|
+
for (const note of proposal.dependencyInstallNotes ?? [])
|
|
354
|
+
io.log(` ${DEPENDENCY_NOTE_TEXT[note] ?? note}`);
|
|
355
|
+
io.log(" Discovery looks at the repository root only, so it can miss a subdirectory project. Stored entries stay " +
|
|
356
|
+
"as they are unless you change them; you can add a subdirectory entry by hand below.");
|
|
357
|
+
io.log("");
|
|
358
|
+
io.log(" CI database behavior — tells workers whether CI runs with a database.");
|
|
359
|
+
io.log(` Stored: ${CI_DATABASE_TEXT[storedCiDatabase(stored)]}`);
|
|
360
|
+
const ci = proposal.ciDatabaseProposal;
|
|
361
|
+
if (ci !== undefined && ci.value !== CI_DATABASE_DEFAULT && ci.value !== storedCiDatabase(stored)) {
|
|
362
|
+
io.log(` Proposed: ${CI_DATABASE_TEXT[ci.value]}${ci.sources.length > 0 ? ` (from ${safeList(ci.sources)})` : ""}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
257
365
|
function hintFrom(candidate) {
|
|
258
366
|
return { argv: [...candidate.argv], timeout_seconds: candidate.timeoutSeconds };
|
|
259
367
|
}
|
|
@@ -410,6 +518,164 @@ async function reviewHints(io, proposal, stored, providerChecks) {
|
|
|
410
518
|
}
|
|
411
519
|
return edits.size > 0 ? edits : undefined;
|
|
412
520
|
}
|
|
521
|
+
/** Read hand-typed relative paths (comma separated); `null` when any is unsafe. */
|
|
522
|
+
function parsePathList(line) {
|
|
523
|
+
const items = line.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
524
|
+
if (items.length === 0 || items.length > MAX_DEPENDENCY_INSTALL_LOCKFILES)
|
|
525
|
+
return null;
|
|
526
|
+
if (items.some((p) => !isSafeRepoRelativePath(p)) || new Set(items).size !== items.length)
|
|
527
|
+
return null;
|
|
528
|
+
return items;
|
|
529
|
+
}
|
|
530
|
+
/** Ask for one entry by hand: directory, lockfiles, then the command as words. `null` cancels. */
|
|
531
|
+
async function typedDependencyEntry(prompt, io, initial) {
|
|
532
|
+
const cwdAnswer = (await prompt(`Directory to run in, relative to the repository root ("." is the root)${initial ? ` (Enter keeps ${terminalSafe(initial.cwd)})` : ""}: `)).trim();
|
|
533
|
+
const cwd = cwdAnswer === "" && initial ? initial.cwd : cwdAnswer;
|
|
534
|
+
if (!isSafeRepoRelativePath(cwd, { allowRoot: true })) {
|
|
535
|
+
io.log(" A directory must be repository-relative, with no .., backslash, colon, or leading /.");
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
const lockAnswer = (await prompt(`Lockfiles, relative to the repository root, comma separated${initial ? ` (Enter keeps ${safeList(initial.lockfiles)})` : ""}: `)).trim();
|
|
539
|
+
const lockfiles = lockAnswer === "" && initial ? [...initial.lockfiles] : parsePathList(lockAnswer);
|
|
540
|
+
if (lockfiles === null) {
|
|
541
|
+
io.log(` Give 1 to ${MAX_DEPENDENCY_INSTALL_LOCKFILES} distinct repository-relative file paths.`);
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
const argvAnswer = await prompt(`Install command words, space separated, no shell syntax${initial ? " (Enter keeps the current command)" : ""}: `);
|
|
545
|
+
const argv = argvAnswer.trim() === "" && initial ? [...initial.argv] : parseHintWords(argvAnswer);
|
|
546
|
+
if (argv === null) {
|
|
547
|
+
io.log(` A command needs 1 to ${MAX_HINT_WORDS} words of at most ${MAX_HINT_WORD_CHARS} characters.`);
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
const admitted = admitDependencyInstallDeclarations([{ cwd, argv, lockfiles }]);
|
|
551
|
+
if (admitted.entries.length !== 1) {
|
|
552
|
+
io.log(" That entry cannot be stored. Nothing was changed.");
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
return admitted.entries[0];
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* BAPI-1551 — ask about dependency refresh. Returns the complete new list, or
|
|
559
|
+
* `undefined` when the owner leaves the stored list untouched. Declining a
|
|
560
|
+
* proposal never clears a stored entry.
|
|
561
|
+
*/
|
|
562
|
+
async function reviewDependencyInstall(io, proposal, stored) {
|
|
563
|
+
const prompt = io.promptLine;
|
|
564
|
+
const storedList = (stored?.dependency_install ?? []).map(entryOf);
|
|
565
|
+
const proposals = newDependencyProposals(proposal, stored);
|
|
566
|
+
if (storedList.length === 0 && proposals.length === 0 && (proposal.dependencyInstallNotes?.length ?? 0) === 0) {
|
|
567
|
+
return undefined;
|
|
568
|
+
}
|
|
569
|
+
const letters = [
|
|
570
|
+
...(storedList.length > 0 ? ["[k]eep stored entries as they are"] : []),
|
|
571
|
+
...(proposals.length > 0 ? ["[a]pply every proposal", "[i]gnore the proposals (stored entries stay untouched)"] : []),
|
|
572
|
+
"[e]dit — decide each entry one at a time, or add one by hand",
|
|
573
|
+
...(storedList.length > 0 ? ["[r]emove every stored entry"] : []),
|
|
574
|
+
];
|
|
575
|
+
let choice = null;
|
|
576
|
+
for (let attempt = 0; attempt < MAX_REVIEW_ATTEMPTS && choice === null; attempt++) {
|
|
577
|
+
const a = (await prompt(`Dependency refresh — ${letters.join(", ")} (Enter leaves it untouched): `)).trim().toLowerCase();
|
|
578
|
+
if (a === "")
|
|
579
|
+
choice = "keep";
|
|
580
|
+
else if ((a === "k" || a === "keep") && storedList.length > 0)
|
|
581
|
+
choice = "keep";
|
|
582
|
+
else if ((a === "a" || a === "apply") && proposals.length > 0)
|
|
583
|
+
choice = "apply";
|
|
584
|
+
else if ((a === "i" || a === "ignore") && proposals.length > 0)
|
|
585
|
+
choice = "ignore";
|
|
586
|
+
else if (a === "e" || a === "edit")
|
|
587
|
+
choice = "edit";
|
|
588
|
+
else if ((a === "r" || a === "remove") && storedList.length > 0)
|
|
589
|
+
choice = "remove";
|
|
590
|
+
else
|
|
591
|
+
io.log(" Choose one of the listed letters, or press Enter.");
|
|
592
|
+
}
|
|
593
|
+
if (choice === "ignore") {
|
|
594
|
+
io.log(` Ignored ${proposals.length} proposal(s). Stored entries are untouched; nothing was removed.`);
|
|
595
|
+
}
|
|
596
|
+
if (choice === null || choice === "keep" || choice === "ignore")
|
|
597
|
+
return undefined;
|
|
598
|
+
if (choice === "remove") {
|
|
599
|
+
io.log(` Removal requested for ${storedList.length} stored dependency refresh entr${storedList.length === 1 ? "y" : "ies"}.`);
|
|
600
|
+
return (await yes(prompt, "Remove every stored dependency refresh entry? [y/N]: ")) ? [] : undefined;
|
|
601
|
+
}
|
|
602
|
+
let result = storedList.map(entryOf);
|
|
603
|
+
const place = (entry) => {
|
|
604
|
+
const identity = dependencyInstallEntryIdentity(entry);
|
|
605
|
+
const at = result.findIndex((e) => dependencyInstallEntryIdentity(e) === identity);
|
|
606
|
+
if (at === -1)
|
|
607
|
+
result.push(entry);
|
|
608
|
+
else
|
|
609
|
+
result[at] = entry;
|
|
610
|
+
};
|
|
611
|
+
if (choice === "apply") {
|
|
612
|
+
for (const candidate of proposals)
|
|
613
|
+
place(entryOf(candidate));
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
for (const candidate of proposals) {
|
|
617
|
+
const where = candidate.cwd === "." ? "the repository root" : terminalSafe(candidate.cwd);
|
|
618
|
+
const a = (await prompt(`Proposed for ${where} (${safeList(candidate.lockfiles)}): ${candidate.argv.map(terminalSafe).join(" ")} — ` +
|
|
619
|
+
"[a]pply, [e]dit, or Enter to ignore: ")).trim().toLowerCase();
|
|
620
|
+
if (a === "a" || a === "apply")
|
|
621
|
+
place(entryOf(candidate));
|
|
622
|
+
else if (a === "e" || a === "edit") {
|
|
623
|
+
const typed = await typedDependencyEntry(prompt, io, entryOf(candidate));
|
|
624
|
+
if (typed !== null)
|
|
625
|
+
place(typed);
|
|
626
|
+
}
|
|
627
|
+
else
|
|
628
|
+
io.log(" Ignored that proposal. Stored entries are untouched.");
|
|
629
|
+
}
|
|
630
|
+
for (const entry of storedList) {
|
|
631
|
+
const where = entry.cwd === "." ? "the repository root" : terminalSafe(entry.cwd);
|
|
632
|
+
const a = (await prompt(`Stored entry for ${where} — [e]dit, [r]emove, or Enter to keep: `)).trim().toLowerCase();
|
|
633
|
+
const identity = dependencyInstallEntryIdentity(entry);
|
|
634
|
+
if (a === "r" || a === "remove") {
|
|
635
|
+
io.log(` Removal requested: the stored entry for ${where}.`);
|
|
636
|
+
result = result.filter((e) => dependencyInstallEntryIdentity(e) !== identity);
|
|
637
|
+
}
|
|
638
|
+
else if (a === "e" || a === "edit") {
|
|
639
|
+
const typed = await typedDependencyEntry(prompt, io, entry);
|
|
640
|
+
if (typed !== null) {
|
|
641
|
+
result = result.filter((e) => dependencyInstallEntryIdentity(e) !== identity);
|
|
642
|
+
place(typed);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
while (result.length < MAX_DEPENDENCY_INSTALL_ENTRIES && (await yes(prompt, "Add a dependency refresh entry by hand? [y/N]: "))) {
|
|
647
|
+
const typed = await typedDependencyEntry(prompt, io);
|
|
648
|
+
if (typed !== null)
|
|
649
|
+
place(typed);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (result.length > MAX_DEPENDENCY_INSTALL_ENTRIES) {
|
|
653
|
+
io.log(` At most ${MAX_DEPENDENCY_INSTALL_ENTRIES} entries can be stored. Nothing was changed.`);
|
|
654
|
+
return undefined;
|
|
655
|
+
}
|
|
656
|
+
return dependencyInstallEqual(result, storedList) ? undefined : result;
|
|
657
|
+
}
|
|
658
|
+
/** BAPI-1551 — ask about CI database behavior. `undefined` leaves the stored value untouched. */
|
|
659
|
+
async function reviewCiDatabase(io, proposal, stored) {
|
|
660
|
+
const current = storedCiDatabase(stored);
|
|
661
|
+
const proposed = proposedCiDatabase(proposal);
|
|
662
|
+
const offer = proposed !== CI_DATABASE_DEFAULT && proposed !== current ? proposed : null;
|
|
663
|
+
if (current === CI_DATABASE_DEFAULT && offer === null)
|
|
664
|
+
return undefined;
|
|
665
|
+
const answer = (await io.promptLine(`CI database behavior — ${offer ? `[a]pply proposed (${offer}), ` : ""}or type none, provided, or unknown ` +
|
|
666
|
+
"(unknown clears it) (Enter leaves it untouched): ")).trim().toLowerCase();
|
|
667
|
+
if (answer === "") {
|
|
668
|
+
if (offer)
|
|
669
|
+
io.log(" Ignored the proposal. The stored value is untouched.");
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
const chosen = (answer === "a" || answer === "apply") && offer ? offer : answer;
|
|
673
|
+
if (!isCiDatabase(chosen)) {
|
|
674
|
+
io.log(" Not recognized; the CI database behavior is left untouched.");
|
|
675
|
+
return undefined;
|
|
676
|
+
}
|
|
677
|
+
return chosen === current ? undefined : chosen;
|
|
678
|
+
}
|
|
413
679
|
/**
|
|
414
680
|
* Show the review surface and collect the owner's decisions. Requires a
|
|
415
681
|
* terminal. Returns what changed; nothing is stored here.
|
|
@@ -423,8 +689,31 @@ export async function reviewDiscoveredSettings(io, proposal, stored, providerChe
|
|
|
423
689
|
const reproduce = await reviewHints(io, proposal, stored, providerChecks);
|
|
424
690
|
if (reproduce !== undefined)
|
|
425
691
|
edit.reproduce = reproduce;
|
|
692
|
+
Object.assign(edit, await reviewDeclarations(io, proposal, stored));
|
|
693
|
+
return edit;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* BAPI-1551 — collect only the dependency-refresh and CI-database decisions.
|
|
697
|
+
* Used beside the full review, and by setup when a confirmed gate is kept and
|
|
698
|
+
* discovery proposes a declaration that is not stored yet.
|
|
699
|
+
*/
|
|
700
|
+
export async function reviewDeclarations(io, proposal, stored) {
|
|
701
|
+
const edit = {};
|
|
702
|
+
if (!hasDeclarationsToReview(proposal, stored))
|
|
703
|
+
return edit;
|
|
704
|
+
const dependencyInstall = await reviewDependencyInstall(io, proposal, stored);
|
|
705
|
+
if (dependencyInstall !== undefined)
|
|
706
|
+
edit.dependencyInstall = dependencyInstall;
|
|
707
|
+
const ciDatabase = await reviewCiDatabase(io, proposal, stored);
|
|
708
|
+
if (ciDatabase !== undefined)
|
|
709
|
+
edit.ciDatabase = ciDatabase;
|
|
426
710
|
return edit;
|
|
427
711
|
}
|
|
712
|
+
/** BAPI-1551 — print only the declaration groups (setup's advisory offer). */
|
|
713
|
+
export function renderDeclarationsOnly(io, proposal, stored, showValues) {
|
|
714
|
+
renderDeclarationsReview(io, proposal, stored, showValues);
|
|
715
|
+
io.log("");
|
|
716
|
+
}
|
|
428
717
|
/** Name-only lines describing what an edit changes, for the gate comparison. */
|
|
429
718
|
export function describeSettingsEdit(edit, stored) {
|
|
430
719
|
const lines = [];
|
|
@@ -447,5 +736,16 @@ export function describeSettingsEdit(edit, stored) {
|
|
|
447
736
|
? ` reproduction hint for ${terminalSafe(check)}: removal requested`
|
|
448
737
|
: ` reproduction hint for ${terminalSafe(check)}: set (hint only — never changes gating)`);
|
|
449
738
|
}
|
|
739
|
+
if (edit.dependencyInstall !== undefined) {
|
|
740
|
+
const where = edit.dependencyInstall.map((e) => (e.cwd === "." ? "repository root" : e.cwd));
|
|
741
|
+
lines.push(edit.dependencyInstall.length === 0
|
|
742
|
+
? " dependency refresh: removal requested for every stored entry"
|
|
743
|
+
: ` dependency refresh: ${edit.dependencyInstall.length} entr${edit.dependencyInstall.length === 1 ? "y" : "ies"} (${safeList(where)})`);
|
|
744
|
+
}
|
|
745
|
+
if (edit.ciDatabase !== undefined) {
|
|
746
|
+
lines.push(edit.ciDatabase === CI_DATABASE_DEFAULT
|
|
747
|
+
? " CI database behavior: reset to unknown"
|
|
748
|
+
: ` CI database behavior: ${edit.ciDatabase}`);
|
|
749
|
+
}
|
|
450
750
|
return lines;
|
|
451
751
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Byte-preserving removal of managed hook spans, independent of hook runtime. */
|
|
2
|
+
import { lstat, readFile, open, rename, unlink } from "node:fs/promises";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { confirmLocalCleanup } from "../local-cleanup.js";
|
|
6
|
+
import { MANAGED_HOOK_NAMES, BRIDGE_CONDUCTOR_HOOK_START, BRIDGE_CONDUCTOR_HOOK_END, removeManagedHookSnippet, resolveGitHooksDirectory } from "./git-hooks.js";
|
|
7
|
+
export async function planConductorGitHooksUninstall(deps = {}) {
|
|
8
|
+
const directory = resolveGitHooksDirectory(deps);
|
|
9
|
+
if (!directory.hooks_dir)
|
|
10
|
+
throw new Error("hooks directory unavailable");
|
|
11
|
+
const io = deps.io ?? { lstat, readFile, open, rename, unlink };
|
|
12
|
+
const items = [];
|
|
13
|
+
for (const name of MANAGED_HOOK_NAMES) {
|
|
14
|
+
const target = join(directory.hooks_dir, name);
|
|
15
|
+
try {
|
|
16
|
+
const stat = await io.lstat(target);
|
|
17
|
+
if (stat.isSymbolicLink() || !stat.isFile() || stat.size > 1024 * 1024) {
|
|
18
|
+
items.push({ path: target, action: "retained", warning: "unsafe hook file" });
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const bytes = await io.readFile(target);
|
|
22
|
+
const content = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
23
|
+
const removal = removeManagedHookSnippet(content);
|
|
24
|
+
items.push({ path: target, ...removal, snapshot: { bytes, dev: stat.dev, ino: stat.ino, mode: stat.mode } });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
items.push({ path: target, action: error.code === "ENOENT" ? "unchanged" : "retained", warning: error.code === "ENOENT" ? undefined : "hook bytes unavailable" });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return items;
|
|
31
|
+
}
|
|
32
|
+
export async function uninstallConductorGitHooks(items, deps = {}) {
|
|
33
|
+
const io = deps.io ?? { lstat, readFile, open, rename, unlink };
|
|
34
|
+
const results = [];
|
|
35
|
+
let ok = true;
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
if (item.action === "unchanged") {
|
|
38
|
+
results.push({ path: item.path, outcome: "nothing to remove" });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (item.action === "retained" || !item.snapshot) {
|
|
42
|
+
ok = false;
|
|
43
|
+
results.push({ path: item.path, outcome: `retained: ${item.warning}; owner repair required between ${BRIDGE_CONDUCTOR_HOOK_START} and ${BRIDGE_CONDUCTOR_HOOK_END}` });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const temp = `${item.path}.${randomUUID()}.tmp`;
|
|
47
|
+
let owned = false;
|
|
48
|
+
try {
|
|
49
|
+
if (item.action === "rewrite") {
|
|
50
|
+
const handle = await io.open(temp, "wx", 0o600);
|
|
51
|
+
owned = true;
|
|
52
|
+
try {
|
|
53
|
+
await handle.writeFile(item.content, "utf8");
|
|
54
|
+
await handle.chmod(item.snapshot.mode & 0o7777);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await handle.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const now = await io.lstat(item.path);
|
|
61
|
+
if (!now.isFile() || now.isSymbolicLink() || now.dev !== item.snapshot.dev || now.ino !== item.snapshot.ino || now.mode !== item.snapshot.mode || !(await io.readFile(item.path)).equals(item.snapshot.bytes))
|
|
62
|
+
throw new Error("changed");
|
|
63
|
+
if (item.action === "delete")
|
|
64
|
+
await io.unlink(item.path);
|
|
65
|
+
else {
|
|
66
|
+
await io.rename(temp, item.path);
|
|
67
|
+
owned = false;
|
|
68
|
+
}
|
|
69
|
+
results.push({ path: item.path, outcome: item.action === "delete" ? "deleted" : "user content restored" });
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
ok = false;
|
|
73
|
+
results.push({ path: item.path, outcome: "retained: changed or unavailable; retry after owner review" });
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (owned)
|
|
77
|
+
await io.unlink(temp).catch(() => { });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { ok, results };
|
|
81
|
+
}
|
|
82
|
+
export async function runUninstallGitHooksCommand(argv) {
|
|
83
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
84
|
+
process.stderr.write("Usage: epic-implementer uninstall-git-hooks [--dry-run]\nRemove only Bridge-managed hook text with interactive consent.\n");
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
if (argv.some(arg => arg !== "--dry-run")) {
|
|
88
|
+
process.stderr.write("Unsupported uninstall-git-hooks argument.\n");
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const items = await planConductorGitHooksUninstall();
|
|
93
|
+
for (const item of items)
|
|
94
|
+
process.stderr.write(`${item.path}: ${item.action}${item.warning ? ` (${item.warning})` : ""}\n`);
|
|
95
|
+
if (argv.includes("--dry-run")) {
|
|
96
|
+
process.stderr.write("dry run — nothing was removed\n");
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
if (!await confirmLocalCleanup("Remove only Bridge-managed text from these shared Git hooks?")) {
|
|
100
|
+
process.stderr.write("declined — nothing was removed\n");
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
const result = await uninstallConductorGitHooks(items);
|
|
104
|
+
for (const item of result.results)
|
|
105
|
+
process.stderr.write(`${item.path}: ${item.outcome}\n`);
|
|
106
|
+
return result.ok ? 0 : 1;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
process.stderr.write("Git hook removal unavailable; files retained. Run from a Git worktree.\n");
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -296,6 +296,50 @@ export function buildReferenceTransactionHookSnippet(conductorBin) {
|
|
|
296
296
|
function looksBinary(content) {
|
|
297
297
|
return content.includes("\u0000");
|
|
298
298
|
}
|
|
299
|
+
/** Unique line-bounded managed span, rejecting ambiguous marker arrangements. */
|
|
300
|
+
export function managedHookSpan(content) {
|
|
301
|
+
const starts = [...content.matchAll(new RegExp(BRIDGE_CONDUCTOR_HOOK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"))];
|
|
302
|
+
const ends = [...content.matchAll(new RegExp(BRIDGE_CONDUCTOR_HOOK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"))];
|
|
303
|
+
if (!starts.length && !ends.length)
|
|
304
|
+
return null;
|
|
305
|
+
if (starts.length !== 1 || ends.length !== 1)
|
|
306
|
+
return "unsafe";
|
|
307
|
+
const start = starts[0].index, end = ends[0].index + BRIDGE_CONDUCTOR_HOOK_END.length;
|
|
308
|
+
if (end <= start || (start > 0 && content[start - 1] !== "\n") || (end < content.length && content[end] !== "\n" && content.slice(end, end + 2) !== "\r\n"))
|
|
309
|
+
return "unsafe";
|
|
310
|
+
return { start, end };
|
|
311
|
+
}
|
|
312
|
+
const SEPARATOR_METADATA = "# bridge-hook-separators-v1:";
|
|
313
|
+
function withSeparatorMetadata(block, prefix, suffix) {
|
|
314
|
+
return block.replace(BRIDGE_CONDUCTOR_HOOK_START, `${BRIDGE_CONDUCTOR_HOOK_START}\n${SEPARATOR_METADATA}${Buffer.from(prefix).toString("hex")}:${Buffer.from(suffix).toString("hex")}`);
|
|
315
|
+
}
|
|
316
|
+
export function removeManagedHookSnippet(existing) {
|
|
317
|
+
if (looksBinary(existing))
|
|
318
|
+
return { action: "retained", content: existing, warning: "unsafe hook bytes" };
|
|
319
|
+
const span = managedHookSpan(existing);
|
|
320
|
+
if (span === "unsafe")
|
|
321
|
+
return { action: "retained", content: existing, warning: "ambiguous managed markers" };
|
|
322
|
+
if (span === null)
|
|
323
|
+
return { action: "unchanged", content: existing };
|
|
324
|
+
let start = span.start, end = span.end;
|
|
325
|
+
const metadata = existing.slice(start, end).split(/\r?\n/)[1];
|
|
326
|
+
let warning;
|
|
327
|
+
if (metadata?.startsWith(SEPARATOR_METADATA)) {
|
|
328
|
+
const match = metadata.slice(SEPARATOR_METADATA.length).match(/^((?:0a)?):((?:0a)?)$/);
|
|
329
|
+
if (!match)
|
|
330
|
+
return { action: "retained", content: existing, warning: "invalid separator provenance" };
|
|
331
|
+
const prefix = Buffer.from(match[1], "hex").toString(), suffix = Buffer.from(match[2], "hex").toString();
|
|
332
|
+
if ((prefix && existing.slice(start - prefix.length, start) !== prefix) || (suffix && existing.slice(end, end + suffix.length) !== suffix))
|
|
333
|
+
return { action: "retained", content: existing, warning: "separator provenance changed" };
|
|
334
|
+
start -= prefix.length;
|
|
335
|
+
end += suffix.length;
|
|
336
|
+
}
|
|
337
|
+
else
|
|
338
|
+
warning = "legacy block: adjacent user newlines retained";
|
|
339
|
+
const content = existing.slice(0, start) + existing.slice(end);
|
|
340
|
+
const deletable = /^\s*$/.test(content) || /^\s*#![^\r\n]*(?:\r?\n)?\s*$/.test(content);
|
|
341
|
+
return { action: deletable ? "delete" : "rewrite", content, ...(warning ? { warning } : {}) };
|
|
342
|
+
}
|
|
299
343
|
/**
|
|
300
344
|
* Insert or replace ONLY the conductor-managed block within existing hook content,
|
|
301
345
|
* preserving all surrounding user content. A binary/unsafe existing hook is left
|
|
@@ -304,7 +348,7 @@ function looksBinary(content) {
|
|
|
304
348
|
*/
|
|
305
349
|
export function mergeManagedHookSnippet(existing, managedBlock) {
|
|
306
350
|
if (existing === null || existing.length === 0) {
|
|
307
|
-
const content = `#!/bin/sh\n${managedBlock}\n`;
|
|
351
|
+
const content = `#!/bin/sh\n${withSeparatorMetadata(managedBlock, "", "\n")}\n`;
|
|
308
352
|
return { ok: true, content, action: "created" };
|
|
309
353
|
}
|
|
310
354
|
if (looksBinary(existing)) {
|
|
@@ -315,17 +359,20 @@ export function mergeManagedHookSnippet(existing, managedBlock) {
|
|
|
315
359
|
warning: "existing hook appears binary/unsafe to merge; left untouched",
|
|
316
360
|
};
|
|
317
361
|
}
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
const
|
|
362
|
+
const span = managedHookSpan(existing);
|
|
363
|
+
if (span === "unsafe")
|
|
364
|
+
return { ok: false, content: existing, action: "skipped", warning: "ambiguous managed markers; left untouched" };
|
|
365
|
+
if (span) {
|
|
366
|
+
const before = existing.slice(0, span.start);
|
|
367
|
+
const after = existing.slice(span.end);
|
|
368
|
+
const metadata = existing.slice(span.start, span.end).split(/\r?\n/)[1];
|
|
369
|
+
const replacement = metadata?.startsWith(SEPARATOR_METADATA) ? managedBlock.replace(BRIDGE_CONDUCTOR_HOOK_START, `${BRIDGE_CONDUCTOR_HOOK_START}\n${metadata}`) : managedBlock;
|
|
370
|
+
const content = `${before}${replacement}${after}`;
|
|
324
371
|
return { ok: true, content, action: "replaced" };
|
|
325
372
|
}
|
|
326
373
|
// No managed block yet — append after the user's content, preserving it.
|
|
327
374
|
const separator = existing.endsWith("\n") ? "" : "\n";
|
|
328
|
-
const content = `${existing}${separator}${managedBlock}\n`;
|
|
375
|
+
const content = `${existing}${separator}${withSeparatorMetadata(managedBlock, separator, "\n")}\n`;
|
|
329
376
|
return { ok: true, content, action: "appended" };
|
|
330
377
|
}
|
|
331
378
|
/** Stable discriminator for an install that never touched the filesystem. */
|
|
@@ -377,7 +424,7 @@ const DEFAULT_PUBLICATION_FS = {
|
|
|
377
424
|
lstat: (filePath) => {
|
|
378
425
|
try {
|
|
379
426
|
const st = lstatSync(filePath);
|
|
380
|
-
return { isFile: st.isFile(), isSymlink: st.isSymbolicLink(), mode: st.mode & 0o7777 };
|
|
427
|
+
return { isFile: st.isFile(), isSymlink: st.isSymbolicLink(), mode: st.mode & 0o7777, dev: st.dev, ino: st.ino };
|
|
381
428
|
}
|
|
382
429
|
catch (err) {
|
|
383
430
|
if (err.code === "ENOENT")
|
|
@@ -385,7 +432,7 @@ const DEFAULT_PUBLICATION_FS = {
|
|
|
385
432
|
throw err;
|
|
386
433
|
}
|
|
387
434
|
},
|
|
388
|
-
readFile: (filePath) =>
|
|
435
|
+
readFile: (filePath) => new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readFileSync(filePath)),
|
|
389
436
|
};
|
|
390
437
|
/**
|
|
391
438
|
* The mode a published hook gets: the ORIGINAL mode with only the missing
|
|
@@ -489,7 +536,7 @@ export function installConductorGitHooks(deps = {}) {
|
|
|
489
536
|
refused.push({ name, path: hookPath, warning: "could not read existing hook; left untouched" });
|
|
490
537
|
continue;
|
|
491
538
|
}
|
|
492
|
-
snapshot = { content, mode: stat.mode };
|
|
539
|
+
snapshot = { content, mode: stat.mode, dev: stat.dev, ino: stat.ino };
|
|
493
540
|
}
|
|
494
541
|
const merge = mergeManagedHookSnippet(snapshot?.content ?? null, snippetForHook(name, conductorBin));
|
|
495
542
|
if (!merge.ok) {
|
|
@@ -585,6 +632,8 @@ function targetMatchesSnapshot(plan, fs) {
|
|
|
585
632
|
return false;
|
|
586
633
|
if (current.mode !== plan.snapshot.mode)
|
|
587
634
|
return false;
|
|
635
|
+
if (current.dev !== plan.snapshot.dev || current.ino !== plan.snapshot.ino)
|
|
636
|
+
return false;
|
|
588
637
|
return fs.readFile(plan.path) === plan.snapshot.content;
|
|
589
638
|
}
|
|
590
639
|
function publishPlannedHook(plan, hooksDir, fs, platform) {
|
|
@@ -771,12 +820,20 @@ export function inspectConductorGitHooks(deps = {}) {
|
|
|
771
820
|
const hooks = [];
|
|
772
821
|
for (const name of MANAGED_HOOK_NAMES) {
|
|
773
822
|
const hookPath = resolve(hooks_dir, name);
|
|
774
|
-
|
|
823
|
+
let exists = false;
|
|
824
|
+
let existenceUnknown = false;
|
|
825
|
+
try {
|
|
826
|
+
lstatSync(hookPath);
|
|
827
|
+
exists = true;
|
|
828
|
+
}
|
|
829
|
+
catch (error) {
|
|
830
|
+
existenceUnknown = error.code !== "ENOENT";
|
|
831
|
+
}
|
|
775
832
|
let executable = false;
|
|
776
833
|
let managedPresent = false;
|
|
777
834
|
let embeddedBinPath = null;
|
|
778
835
|
let embeddedBinIsFile = false;
|
|
779
|
-
let state = "not-installed";
|
|
836
|
+
let state = existenceUnknown ? "unknown" : "not-installed";
|
|
780
837
|
if (exists) {
|
|
781
838
|
try {
|
|
782
839
|
const mode = statSync(hookPath).mode;
|
|
@@ -787,7 +844,12 @@ export function inspectConductorGitHooks(deps = {}) {
|
|
|
787
844
|
}
|
|
788
845
|
state = "no-managed-block";
|
|
789
846
|
try {
|
|
790
|
-
const
|
|
847
|
+
const stat = lstatSync(hookPath);
|
|
848
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1024 * 1024)
|
|
849
|
+
throw new Error("unsafe");
|
|
850
|
+
const content = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(readFileSync(hookPath));
|
|
851
|
+
if (looksBinary(content) || managedHookSpan(content) === "unsafe")
|
|
852
|
+
throw new Error("unsafe");
|
|
791
853
|
managedPresent = content.includes(BRIDGE_CONDUCTOR_HOOK_START);
|
|
792
854
|
if (managedPresent) {
|
|
793
855
|
// BAPI-772: a managed block is not enough — the block written by an
|
|
@@ -801,7 +863,10 @@ export function inspectConductorGitHooks(deps = {}) {
|
|
|
801
863
|
embeddedBinPath !== null &&
|
|
802
864
|
basename(embeddedBinPath) === CONDUCTOR_BIN_FILENAME &&
|
|
803
865
|
defaultIsFile(embeddedBinPath);
|
|
804
|
-
if (
|
|
866
|
+
if (deps.presenceOnly) {
|
|
867
|
+
state = "unrecognized";
|
|
868
|
+
}
|
|
869
|
+
else if (embeddedBinPath === null) {
|
|
805
870
|
state = "unrecognized";
|
|
806
871
|
}
|
|
807
872
|
else {
|
|
@@ -825,6 +890,7 @@ export function inspectConductorGitHooks(deps = {}) {
|
|
|
825
890
|
exists,
|
|
826
891
|
executable,
|
|
827
892
|
managed_block_present: managedPresent,
|
|
893
|
+
managed_block_observation: state === "unknown" ? "unknown" : managedPresent ? "present" : "absent",
|
|
828
894
|
embedded_bin_path: embeddedBinPath,
|
|
829
895
|
embedded_bin_is_file: embeddedBinIsFile,
|
|
830
896
|
recognized_command: embeddedBinPath !== null,
|