@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
|
@@ -46,7 +46,7 @@ export const EPIC_LAUNCH_PROFILE_NAME_PATTERN = /^[a-z0-9][a-z0-9._-]{0,62}$/;
|
|
|
46
46
|
export const EPIC_LAUNCH_EXECUTION_MODES = ["local", "durable"];
|
|
47
47
|
/** One-time migration guidance for a profile this build cannot read. */
|
|
48
48
|
export function epicLaunchProfileSetupGuidance(name) {
|
|
49
|
-
return (`Re-run guided setup to (re)write it: npx -y ${MCP_PACKAGE_NAME} install
|
|
49
|
+
return (`Re-run guided setup to (re)write it: npx -y ${MCP_PACKAGE_NAME} install epic-implementer ` +
|
|
50
50
|
`--launch-profile ${EPIC_LAUNCH_PROFILE_NAME_PATTERN.test(name) ? diagnosticComponent(name) : "<name>"} --base-url <url> ...`);
|
|
51
51
|
}
|
|
52
52
|
// ---------------------------------------------------------------------------
|
package/build/executor/cli.js
CHANGED
|
@@ -96,6 +96,8 @@ export function getExecutorUsage() {
|
|
|
96
96
|
" -h, --help Show this help.",
|
|
97
97
|
"",
|
|
98
98
|
"Subcommands:",
|
|
99
|
+
" executor uninstall-service List units; use --executor-id <id> to remove with",
|
|
100
|
+
" interactive consent, or --dry-run to preview.",
|
|
99
101
|
" executor watch <job> Attach (read-only) to a running job's worker log.",
|
|
100
102
|
" executor install-service Generate a launchd/systemd user service unit for a",
|
|
101
103
|
" stable --executor-id so the executor survives reboot.",
|
|
@@ -279,6 +279,22 @@ export const COMPLETION_CAUSE_VALUES = [
|
|
|
279
279
|
"cleanup_unconfirmed",
|
|
280
280
|
"verification_runner_unavailable",
|
|
281
281
|
];
|
|
282
|
+
/**
|
|
283
|
+
* BAPI-1563 — the closed vocabulary of supplementary executor OBSERVATION causes,
|
|
284
|
+
* in this exact order. Mirrors `VERIFICATION_OBSERVATION_CAUSE_VALUES` in
|
|
285
|
+
* `src/python/llms/executor_completion_contract.py` (a parity test pins both).
|
|
286
|
+
* These are diagnostic facts the executor reports beside a terminal report; they
|
|
287
|
+
* are deliberately NOT completion causes, park causes or end causes, share no value
|
|
288
|
+
* with {@link COMPLETION_CAUSE_VALUES}, and never select an evidence version.
|
|
289
|
+
*/
|
|
290
|
+
export const VERIFICATION_OBSERVATION_CAUSE_VALUES = [
|
|
291
|
+
"no_database",
|
|
292
|
+
"no_live_server",
|
|
293
|
+
"check_timed_out",
|
|
294
|
+
"check_not_runnable",
|
|
295
|
+
];
|
|
296
|
+
/** BAPI-1563 — most observations one terminal report may carry (server bound). */
|
|
297
|
+
export const MAX_VERIFICATION_OBSERVATIONS = 64;
|
|
282
298
|
export const END_CAUSE_VALUES = [
|
|
283
299
|
"worker_exit", "completion_window", "job_timeout", "executor_abort",
|
|
284
300
|
"executor_shutdown", "server_stop", "lease_lost",
|
|
@@ -93,7 +93,7 @@ export async function resolveExecutorApiAccess(repoName, deps, explicitBaseUrl)
|
|
|
93
93
|
ok: false,
|
|
94
94
|
error: `the stored credential for repo '${trimmed}' is approved for a different Bridge API ` +
|
|
95
95
|
"endpoint than this executor's base URL; it was not sent. Re-run guided setup " +
|
|
96
|
-
"(install
|
|
96
|
+
"(install epic-implementer) to re-bind it, or correct --base-url.",
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1563 — executor-side memory of the facts a terminal report carries beside
|
|
3
|
+
* its outcome: the pull request the executor discovered and the bounded
|
|
4
|
+
* supplementary observation causes it accumulated.
|
|
5
|
+
*
|
|
6
|
+
* The executor REPORTS facts; the server decides. Nothing here grants permission
|
|
7
|
+
* and nothing here marks a check as passed. A failed, unavailable or unrun check
|
|
8
|
+
* yields an observation (or none), never a positive claim.
|
|
9
|
+
*
|
|
10
|
+
* Memory is held per claimed job and attached to every `/complete` and `/fail`
|
|
11
|
+
* by one client wrapper ({@link withDeliveryObservations}), so a failure emitted
|
|
12
|
+
* before finalization, from a catch block, a supervision stop, or cleanup carries
|
|
13
|
+
* the same discovered PR as the happy path. Whether the fields reach the wire is
|
|
14
|
+
* decided later, by the HTTP client, from the claim's advertised capability.
|
|
15
|
+
*
|
|
16
|
+
* Diagnostics go through the caller's error log (stderr), never stdout.
|
|
17
|
+
*/
|
|
18
|
+
import { MAX_VERIFICATION_OBSERVATIONS, VERIFICATION_OBSERVATION_CAUSE_VALUES, } from "./completion-contract.js";
|
|
19
|
+
import { observationsFromVerificationFacts } from "./required-verification.js";
|
|
20
|
+
const FULL_SHA_RE = /^[0-9a-f]{40}$/;
|
|
21
|
+
const memories = new WeakMap();
|
|
22
|
+
/** The memory for `job`, created empty on first use. */
|
|
23
|
+
export function deliveryObservationMemory(job) {
|
|
24
|
+
let memory = memories.get(job);
|
|
25
|
+
if (!memory) {
|
|
26
|
+
memory = { observedPr: null, observations: [] };
|
|
27
|
+
memories.set(job, memory);
|
|
28
|
+
}
|
|
29
|
+
return memory;
|
|
30
|
+
}
|
|
31
|
+
/** True when `value` is a usable discovered-PR fact: positive int, full SHA, non-blank base. */
|
|
32
|
+
export function isObservedPr(value) {
|
|
33
|
+
if (value === null || typeof value !== "object")
|
|
34
|
+
return false;
|
|
35
|
+
const v = value;
|
|
36
|
+
return (typeof v.number === "number" &&
|
|
37
|
+
Number.isInteger(v.number) &&
|
|
38
|
+
v.number > 0 &&
|
|
39
|
+
typeof v.head_sha === "string" &&
|
|
40
|
+
FULL_SHA_RE.test(v.head_sha) &&
|
|
41
|
+
typeof v.base_ref === "string" &&
|
|
42
|
+
v.base_ref.trim().length > 0);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Remember the discovered PR. A later usable observation replaces an earlier one;
|
|
46
|
+
* an unusable one (missing head or base, as a provider may report) is ignored, so
|
|
47
|
+
* the report never carries a half-formed PR.
|
|
48
|
+
*/
|
|
49
|
+
export function recordObservedPr(job, pr) {
|
|
50
|
+
const candidate = {
|
|
51
|
+
number: pr.number ?? undefined,
|
|
52
|
+
head_sha: typeof pr.headSha === "string" ? pr.headSha.trim().toLowerCase() : undefined,
|
|
53
|
+
base_ref: typeof pr.baseRef === "string" ? pr.baseRef.trim() : undefined,
|
|
54
|
+
};
|
|
55
|
+
if (isObservedPr(candidate))
|
|
56
|
+
deliveryObservationMemory(job).observedPr = candidate;
|
|
57
|
+
}
|
|
58
|
+
/** Remember one observation. Unknown causes, duplicates and overflow are dropped. */
|
|
59
|
+
export function recordVerificationObservation(job, observation) {
|
|
60
|
+
if (!VERIFICATION_OBSERVATION_CAUSE_VALUES.includes(observation.cause))
|
|
61
|
+
return;
|
|
62
|
+
const memory = deliveryObservationMemory(job);
|
|
63
|
+
const key = (o) => `${o.step_id ?? ""}|${o.check_identity ?? ""}|${o.cause}`;
|
|
64
|
+
if (memory.observations.some((o) => key(o) === key(observation)))
|
|
65
|
+
return;
|
|
66
|
+
if (memory.observations.length >= MAX_VERIFICATION_OBSERVATIONS)
|
|
67
|
+
return;
|
|
68
|
+
memory.observations.push({
|
|
69
|
+
...(typeof observation.step_id === "number" ? { step_id: observation.step_id } : {}),
|
|
70
|
+
...(typeof observation.check_identity === "string" && observation.check_identity !== ""
|
|
71
|
+
? { check_identity: observation.check_identity }
|
|
72
|
+
: {}),
|
|
73
|
+
cause: observation.cause,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Fold derived verification observations into a job's memory. */
|
|
77
|
+
export function recordVerificationFacts(job, facts) {
|
|
78
|
+
for (const observation of observationsFromVerificationFacts(facts)) {
|
|
79
|
+
recordVerificationObservation(job, observation);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** The fields to add to a terminal body, each only when the report does not set it. */
|
|
83
|
+
function withMemory(job, body) {
|
|
84
|
+
const memory = memories.get(job);
|
|
85
|
+
if (!memory)
|
|
86
|
+
return body;
|
|
87
|
+
const additions = {};
|
|
88
|
+
if (body.observed_pr === undefined && memory.observedPr !== null)
|
|
89
|
+
additions.observed_pr = memory.observedPr;
|
|
90
|
+
if (body.verification_observations === undefined && memory.observations.length > 0) {
|
|
91
|
+
additions.verification_observations = [...memory.observations];
|
|
92
|
+
}
|
|
93
|
+
return Object.keys(additions).length === 0 ? body : { ...body, ...additions };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wrap a client so every terminal report of `job` carries its observation memory.
|
|
97
|
+
* Only `complete` and `fail` are touched; every other method passes through. The
|
|
98
|
+
* wire gate (the claim's capability) is applied by the real HTTP client.
|
|
99
|
+
*/
|
|
100
|
+
export function withDeliveryObservations(httpClient) {
|
|
101
|
+
return new Proxy(httpClient, {
|
|
102
|
+
get(target, key) {
|
|
103
|
+
if (key === "complete") {
|
|
104
|
+
return (job, completion) => target.complete(job, withMemory(job, completion));
|
|
105
|
+
}
|
|
106
|
+
if (key === "fail") {
|
|
107
|
+
return (job, failure) => target.fail(job, withMemory(job, failure));
|
|
108
|
+
}
|
|
109
|
+
const value = Reflect.get(target, key);
|
|
110
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -95,6 +95,30 @@ export function summarizeDeliveryBlockers(value) {
|
|
|
95
95
|
}
|
|
96
96
|
return out;
|
|
97
97
|
}
|
|
98
|
+
/** Reduce the server's carried-gap list to closed tokens and integer step ids. */
|
|
99
|
+
export function summarizeCarriedGaps(value) {
|
|
100
|
+
if (!Array.isArray(value))
|
|
101
|
+
return [];
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const entry of value) {
|
|
104
|
+
if (out.length >= MAX_BLOCKERS * 4)
|
|
105
|
+
break;
|
|
106
|
+
const rec = asRecord(entry);
|
|
107
|
+
if (!rec)
|
|
108
|
+
continue;
|
|
109
|
+
const step = rec.step_id;
|
|
110
|
+
const refusal = rec.refusal_token;
|
|
111
|
+
out.push({
|
|
112
|
+
...(typeof step === "number" && Number.isInteger(step) && step >= 0 && step <= 1_000_000
|
|
113
|
+
? { step_id: step }
|
|
114
|
+
: {}),
|
|
115
|
+
gap_kind: typeof rec.gap_kind === "string" && TOKEN_RE.test(rec.gap_kind) ? rec.gap_kind : "unrecognized",
|
|
116
|
+
cause: typeof rec.cause === "string" && TOKEN_RE.test(rec.cause) ? rec.cause : "unrecognized",
|
|
117
|
+
...(typeof refusal === "string" && TOKEN_RE.test(refusal) ? { refusal_token: refusal } : {}),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
98
122
|
function isDeliveryOutcomeToken(value) {
|
|
99
123
|
return typeof value === "string" && DELIVERY_OUTCOMES.includes(value);
|
|
100
124
|
}
|
|
@@ -171,6 +195,12 @@ export async function fetchServerDeliveryOutcome(job, branch, deps) {
|
|
|
171
195
|
// so a response without them parses exactly as it did before.
|
|
172
196
|
...(FULL_SHA_RE.test(rawObserved) ? { observedHeadSha: rawObserved } : {}),
|
|
173
197
|
...(readiness.post_pr_remote_ci_only === true ? { postPrRemoteCiOnly: true } : {}),
|
|
198
|
+
// Additive (BAPI-1563): the evidence outcome and carried gaps, only when
|
|
199
|
+
// the server supplied usable values. No outcome token is added or reinterpreted.
|
|
200
|
+
...(isDeliveryOutcomeToken(readiness.evidence_outcome) ? { evidenceOutcome: readiness.evidence_outcome } : {}),
|
|
201
|
+
...(Array.isArray(readiness.carried_gaps) && readiness.carried_gaps.length > 0
|
|
202
|
+
? { carriedGaps: summarizeCarriedGaps(readiness.carried_gaps) }
|
|
203
|
+
: {}),
|
|
174
204
|
};
|
|
175
205
|
}
|
|
176
206
|
catch {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1551 — the stream-draining, abortable install runner for the executor's
|
|
3
|
+
* dependency refresh.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately NOT `deps.runCommand`: that is `execFile` with a 10 MiB
|
|
6
|
+
* `maxBuffer`, so a noisy `npm ci` would be killed for its output size and read
|
|
7
|
+
* as a failed install. This runner drains both streams continuously and keeps
|
|
8
|
+
* only a bounded tail.
|
|
9
|
+
*
|
|
10
|
+
* - The command is an argv array, spawned with `shell: false`. No shell ever
|
|
11
|
+
* parses it.
|
|
12
|
+
* - On POSIX the child leads its own process group (`detached: true`), so a
|
|
13
|
+
* timeout or a cancellation terminates the WHOLE install tree (lifecycle
|
|
14
|
+
* scripts, `node-gyp`, and so on): SIGTERM to the group, a short grace, then
|
|
15
|
+
* SIGKILL. The runner resolves only after the child has exited, so nothing it
|
|
16
|
+
* started is still writing when the worker is spawned.
|
|
17
|
+
* - The result is a closed outcome. Raw process errors are never propagated.
|
|
18
|
+
* - The retained tail is returned to the caller for an executor-local diagnostic
|
|
19
|
+
* only. It must never reach a log line, Sentry, a server request, a job result,
|
|
20
|
+
* or a worker prompt: install output can echo argv, paths, or tokens.
|
|
21
|
+
*/
|
|
22
|
+
import { spawn } from "node:child_process";
|
|
23
|
+
/** Bytes of combined stdout/stderr kept for an executor-local diagnostic. */
|
|
24
|
+
export const DEPENDENCY_INSTALL_OUTPUT_TAIL_BYTES = 8 * 1024;
|
|
25
|
+
/** Grace between SIGTERM and SIGKILL of the install process group. */
|
|
26
|
+
export const DEPENDENCY_INSTALL_KILL_GRACE_MS = 5_000;
|
|
27
|
+
/** Keep the last `limit` bytes of a growing buffer. */
|
|
28
|
+
class BoundedTail {
|
|
29
|
+
limit;
|
|
30
|
+
chunks = [];
|
|
31
|
+
size = 0;
|
|
32
|
+
constructor(limit) {
|
|
33
|
+
this.limit = limit;
|
|
34
|
+
}
|
|
35
|
+
push(chunk) {
|
|
36
|
+
this.chunks.push(chunk);
|
|
37
|
+
this.size += chunk.length;
|
|
38
|
+
while (this.size > this.limit && this.chunks.length > 0) {
|
|
39
|
+
const first = this.chunks[0];
|
|
40
|
+
const excess = this.size - this.limit;
|
|
41
|
+
if (first.length <= excess) {
|
|
42
|
+
this.chunks.shift();
|
|
43
|
+
this.size -= first.length;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.chunks[0] = first.subarray(excess);
|
|
47
|
+
this.size -= excess;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
text() {
|
|
52
|
+
return Buffer.concat(this.chunks).toString("utf8");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** The real runner. Never throws. */
|
|
56
|
+
export const runDependencyInstall = (request) => new Promise((resolve) => {
|
|
57
|
+
const tail = new BoundedTail(DEPENDENCY_INSTALL_OUTPUT_TAIL_BYTES);
|
|
58
|
+
const posix = process.platform !== "win32";
|
|
59
|
+
if (request.argv.length === 0 || request.signal?.aborted) {
|
|
60
|
+
resolve({ outcome: request.signal?.aborted ? "cancelled" : "spawn_failed", outputTail: "" });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let child;
|
|
64
|
+
try {
|
|
65
|
+
child = spawn(request.argv[0], request.argv.slice(1), {
|
|
66
|
+
cwd: request.cwd,
|
|
67
|
+
env: request.env,
|
|
68
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
69
|
+
shell: false,
|
|
70
|
+
detached: posix,
|
|
71
|
+
windowsHide: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
resolve({ outcome: "spawn_failed", outputTail: "" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let stopping = null;
|
|
79
|
+
let spawnFailed = false;
|
|
80
|
+
let settled = false;
|
|
81
|
+
let killTimer;
|
|
82
|
+
const signalGroup = (signal) => {
|
|
83
|
+
const pid = child.pid;
|
|
84
|
+
if (pid === undefined)
|
|
85
|
+
return;
|
|
86
|
+
try {
|
|
87
|
+
if (posix)
|
|
88
|
+
process.kill(-pid, signal);
|
|
89
|
+
else
|
|
90
|
+
child.kill(signal);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
try {
|
|
94
|
+
child.kill(signal);
|
|
95
|
+
}
|
|
96
|
+
catch { /* already exited */ }
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const stop = (reason) => {
|
|
100
|
+
if (stopping !== null || settled)
|
|
101
|
+
return;
|
|
102
|
+
stopping = reason;
|
|
103
|
+
signalGroup("SIGTERM");
|
|
104
|
+
killTimer = setTimeout(() => signalGroup("SIGKILL"), DEPENDENCY_INSTALL_KILL_GRACE_MS);
|
|
105
|
+
};
|
|
106
|
+
const timer = setTimeout(() => stop("timeout"), Math.max(1, request.timeoutMs));
|
|
107
|
+
const onAbort = () => stop("cancelled");
|
|
108
|
+
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
109
|
+
child.stdout?.on("data", (chunk) => tail.push(chunk));
|
|
110
|
+
child.stderr?.on("data", (chunk) => tail.push(chunk));
|
|
111
|
+
const finish = (code) => {
|
|
112
|
+
if (settled)
|
|
113
|
+
return;
|
|
114
|
+
settled = true;
|
|
115
|
+
clearTimeout(timer);
|
|
116
|
+
if (killTimer)
|
|
117
|
+
clearTimeout(killTimer);
|
|
118
|
+
request.signal?.removeEventListener("abort", onAbort);
|
|
119
|
+
// A group member that outlived the leader still gets the hard stop.
|
|
120
|
+
if (stopping !== null && posix)
|
|
121
|
+
signalGroup("SIGKILL");
|
|
122
|
+
const outcome = stopping ?? (spawnFailed ? "spawn_failed" : code === 0 ? "exit_zero" : "nonzero");
|
|
123
|
+
resolve({ outcome, outputTail: tail.text() });
|
|
124
|
+
};
|
|
125
|
+
child.on("error", () => {
|
|
126
|
+
spawnFailed = true;
|
|
127
|
+
// A child that never started emits no `close` on every Node version.
|
|
128
|
+
if (child.pid === undefined)
|
|
129
|
+
finish(null);
|
|
130
|
+
});
|
|
131
|
+
child.on("close", (code) => finish(code));
|
|
132
|
+
});
|