@bridge_gpt/mcp-server 0.2.72 → 0.2.74
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/agent-launchers/claude-executor-adapter.js +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -21
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -15
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/completion-contract.js +8 -1
- package/build/executor/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-invoke.js +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +63 -2
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process ownership for the epic-server helper (BAPI-1546).
|
|
3
|
+
*
|
|
4
|
+
* The helper and every recipe descendant carry the helper's OWN instance tag
|
|
5
|
+
* (`BRIDGE_EPIC_SERVER_INSTANCE_TAG`), never the executor's job tag, so the
|
|
6
|
+
* executor's containment sweep never claims them and the helper never claims an
|
|
7
|
+
* executor job's process.
|
|
8
|
+
*
|
|
9
|
+
* A signal is sent only to a process whose pid, normalized `ps lstart` start
|
|
10
|
+
* time, AND instance tag all match what the helper recorded, re-checked
|
|
11
|
+
* immediately before each signal. A mismatch, or a check that cannot be read,
|
|
12
|
+
* refuses: nothing is ever signalled by port, by name, or by pid alone, and
|
|
13
|
+
* nothing listening on `:8000` is ever touched. A platform that cannot inspect a
|
|
14
|
+
* process's environment makes the epic server unavailable rather than weakening
|
|
15
|
+
* the check.
|
|
16
|
+
*
|
|
17
|
+
* Every recipe subprocess runs with a REPLACING environment built here: the
|
|
18
|
+
* minimal runtime inputs, the recipe's named literal inputs, its resolved
|
|
19
|
+
* credential references, `PORT`, the ownership tag, and the helper-owned
|
|
20
|
+
* per-turn database settings. Ambient `DATABASE_URL`, `PG*`, `POSTGRES_*`, the
|
|
21
|
+
* owner's dotenv values, and unrelated credentials never pass through.
|
|
22
|
+
*/
|
|
23
|
+
import { spawn as nodeSpawn, execFile } from "node:child_process";
|
|
24
|
+
import { readFile } from "node:fs/promises";
|
|
25
|
+
import { EPIC_SERVER_INSTANCE_TAG_ENV, isInstanceNonce } from "./epic-server-state.js";
|
|
26
|
+
const PS_TIMEOUT_MS = 5_000;
|
|
27
|
+
const LSTART_RE = /^[A-Z][a-z]{2}\s+[A-Z][a-z]{2}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4}$/;
|
|
28
|
+
const MAX_ENV_LISTING_CHARS = 1024 * 1024;
|
|
29
|
+
/** Captured stdout per recipe command (only the seed's is ever parsed). */
|
|
30
|
+
export const EPIC_SERVER_MAX_CAPTURED_OUTPUT = 64 * 1024;
|
|
31
|
+
/** The runtime keys copied from the helper's own environment, and nothing else. */
|
|
32
|
+
export const EPIC_SERVER_RUNTIME_ENV_KEYS = [
|
|
33
|
+
"PATH",
|
|
34
|
+
"HOME",
|
|
35
|
+
"USER",
|
|
36
|
+
"LOGNAME",
|
|
37
|
+
"TMPDIR",
|
|
38
|
+
"LANG",
|
|
39
|
+
"LC_ALL",
|
|
40
|
+
];
|
|
41
|
+
/** The production `ps` runner: bounded, shell-free. */
|
|
42
|
+
export const defaultCommandRunner = (file, args, options) => new Promise((resolve) => {
|
|
43
|
+
execFile(file, args, { timeout: options.timeoutMs, maxBuffer: MAX_ENV_LISTING_CHARS }, (err, stdout) => {
|
|
44
|
+
const code = err && typeof err.code === "number" ? (err.code) : err ? null : 0;
|
|
45
|
+
resolve({ exitCode: code, stdout: typeof stdout === "string" ? stdout : String(stdout ?? "") });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
export function createDefaultEpicServerProcessDeps() {
|
|
49
|
+
return {
|
|
50
|
+
platform: process.platform,
|
|
51
|
+
selfPid: process.pid,
|
|
52
|
+
runCommand: defaultCommandRunner,
|
|
53
|
+
readProcEnviron: (pid) => readFile(`/proc/${pid}/environ`, "latin1"),
|
|
54
|
+
killGroup: (pgid, sig) => {
|
|
55
|
+
if (!Number.isSafeInteger(pgid) || pgid <= 1)
|
|
56
|
+
return "denied";
|
|
57
|
+
try {
|
|
58
|
+
process.kill(-pgid, sig);
|
|
59
|
+
return "sent";
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
return err.code === "ESRCH" ? "gone" : "denied";
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** True when this platform can read both a start time and an environment tag. */
|
|
69
|
+
export function isOwnershipInspectionSupported(platform) {
|
|
70
|
+
return platform === "darwin" || platform === "linux";
|
|
71
|
+
}
|
|
72
|
+
function normalizeLstart(raw) {
|
|
73
|
+
return raw.trim().replace(/\s+/g, " ");
|
|
74
|
+
}
|
|
75
|
+
/** The live, normalized start time of `pid`, or null when gone or unreadable. */
|
|
76
|
+
export async function readProcessStartTime(pid, deps) {
|
|
77
|
+
if (!Number.isSafeInteger(pid) || pid <= 1)
|
|
78
|
+
return null;
|
|
79
|
+
if (!isOwnershipInspectionSupported(deps.platform))
|
|
80
|
+
return null;
|
|
81
|
+
try {
|
|
82
|
+
const res = await deps.runCommand("ps", ["-o", "lstart=", "-p", String(pid)], { timeoutMs: PS_TIMEOUT_MS });
|
|
83
|
+
if (res.exitCode !== 0)
|
|
84
|
+
return null;
|
|
85
|
+
const startedAt = normalizeLstart(res.stdout);
|
|
86
|
+
return LSTART_RE.test(startedAt) ? startedAt : null;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const TAG_RE = new RegExp(`(?:^|\\s|\\0)${EPIC_SERVER_INSTANCE_TAG_ENV}=([0-9a-f]{64})(?=\\s|\\0|$)`, "g");
|
|
93
|
+
/** The LAST well-formed instance tag in an environment listing, or null. */
|
|
94
|
+
export function extractInstanceTag(listing) {
|
|
95
|
+
let last = null;
|
|
96
|
+
TAG_RE.lastIndex = 0;
|
|
97
|
+
for (let m = TAG_RE.exec(listing); m !== null; m = TAG_RE.exec(listing))
|
|
98
|
+
last = m[1];
|
|
99
|
+
return last;
|
|
100
|
+
}
|
|
101
|
+
/** The instance tag `pid` carries, or null when it carries none or cannot be read. */
|
|
102
|
+
export async function readProcessInstanceTag(pid, deps) {
|
|
103
|
+
if (!Number.isSafeInteger(pid) || pid <= 1)
|
|
104
|
+
return null;
|
|
105
|
+
try {
|
|
106
|
+
if (deps.platform === "darwin") {
|
|
107
|
+
const res = await deps.runCommand("ps", ["-E", "-ww", "-o", "command=", "-p", String(pid)], { timeoutMs: PS_TIMEOUT_MS });
|
|
108
|
+
if (res.exitCode !== 0 || res.stdout.length > MAX_ENV_LISTING_CHARS)
|
|
109
|
+
return null;
|
|
110
|
+
return extractInstanceTag(res.stdout);
|
|
111
|
+
}
|
|
112
|
+
if (deps.platform === "linux") {
|
|
113
|
+
const environ = await deps.readProcEnviron(pid);
|
|
114
|
+
if (environ.length > MAX_ENV_LISTING_CHARS)
|
|
115
|
+
return null;
|
|
116
|
+
return extractInstanceTag(environ);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Verify that `expected` is still the process the helper started: same pid, same
|
|
126
|
+
* start time, and the instance tag equal to `nonce`. `gone` means the pid no
|
|
127
|
+
* longer exists. A pid reused by a process with another start time is
|
|
128
|
+
* `mismatch`: it is never signalled, and a caller that only needs to know the
|
|
129
|
+
* owned process is gone (recovery) treats it as gone itself.
|
|
130
|
+
*/
|
|
131
|
+
export async function verifyOwnedProcess(expected, nonce, deps) {
|
|
132
|
+
if (!isInstanceNonce(nonce))
|
|
133
|
+
return "unreadable";
|
|
134
|
+
if (!isOwnershipInspectionSupported(deps.platform))
|
|
135
|
+
return "unreadable";
|
|
136
|
+
if (expected.pid === deps.selfPid)
|
|
137
|
+
return "mismatch";
|
|
138
|
+
const startedAt = await readProcessStartTime(expected.pid, deps);
|
|
139
|
+
if (startedAt === null)
|
|
140
|
+
return "gone";
|
|
141
|
+
if (startedAt !== expected.started_at)
|
|
142
|
+
return "mismatch";
|
|
143
|
+
const tag = await readProcessInstanceTag(expected.pid, deps);
|
|
144
|
+
if (tag === null)
|
|
145
|
+
return "unreadable";
|
|
146
|
+
return tag === nonce ? "match" : "mismatch";
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Stop an owned process GROUP (the leader's pid is the pgid): verify, SIGTERM,
|
|
150
|
+
* wait up to `graceMs`, re-verify, SIGKILL. Every signal is preceded by a fresh
|
|
151
|
+
* ownership check; any mismatch or unreadable check refuses without signalling.
|
|
152
|
+
*/
|
|
153
|
+
export async function stopOwnedProcessGroup(expected, nonce, graceMs, deps) {
|
|
154
|
+
const first = await verifyOwnedProcess(expected, nonce, deps);
|
|
155
|
+
if (first === "gone")
|
|
156
|
+
return "already_gone";
|
|
157
|
+
if (first !== "match")
|
|
158
|
+
return "refused";
|
|
159
|
+
const sent = deps.killGroup(expected.pid, "SIGTERM");
|
|
160
|
+
if (sent === "gone")
|
|
161
|
+
return "already_gone";
|
|
162
|
+
if (sent === "denied")
|
|
163
|
+
return "refused";
|
|
164
|
+
const deadline = Date.now() + Math.max(0, graceMs);
|
|
165
|
+
while (Date.now() < deadline) {
|
|
166
|
+
await deps.sleep(Math.min(250, Math.max(1, deadline - Date.now())));
|
|
167
|
+
const now = await readProcessStartTime(expected.pid, deps);
|
|
168
|
+
if (now === null || now !== expected.started_at)
|
|
169
|
+
return "stopped";
|
|
170
|
+
}
|
|
171
|
+
const again = await verifyOwnedProcess(expected, nonce, deps);
|
|
172
|
+
if (again === "gone")
|
|
173
|
+
return "stopped";
|
|
174
|
+
if (again !== "match")
|
|
175
|
+
return "refused";
|
|
176
|
+
const killed = deps.killGroup(expected.pid, "SIGKILL");
|
|
177
|
+
return killed === "denied" ? "refused" : "stopped";
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Build the replacing environment for one recipe subprocess. Nothing from the
|
|
181
|
+
* helper's environment passes except the minimal runtime keys; the database
|
|
182
|
+
* settings, when present, name only the helper's current per-turn database.
|
|
183
|
+
*/
|
|
184
|
+
export function buildEpicServerCommandEnv(input) {
|
|
185
|
+
const env = {};
|
|
186
|
+
for (const key of EPIC_SERVER_RUNTIME_ENV_KEYS) {
|
|
187
|
+
const value = input.helperEnv[key];
|
|
188
|
+
if (typeof value === "string" && value.length > 0)
|
|
189
|
+
env[key] = value;
|
|
190
|
+
}
|
|
191
|
+
for (const [name, value] of Object.entries(input.inputs))
|
|
192
|
+
env[name] = value;
|
|
193
|
+
for (const [name, value] of Object.entries(input.credentials))
|
|
194
|
+
env[name] = value;
|
|
195
|
+
env.PORT = String(input.port);
|
|
196
|
+
env[EPIC_SERVER_INSTANCE_TAG_ENV] = input.nonce;
|
|
197
|
+
if (input.database !== null) {
|
|
198
|
+
const db = input.database;
|
|
199
|
+
env.DATABASE_URL = `postgresql://${encodeURIComponent(db.role)}@${db.host}:${db.port}/${encodeURIComponent(db.name)}`;
|
|
200
|
+
env.PGHOST = db.host;
|
|
201
|
+
env.PGPORT = db.port;
|
|
202
|
+
env.PGUSER = db.role;
|
|
203
|
+
env.PGDATABASE = db.name;
|
|
204
|
+
env.POSTGRES_HOST = db.host;
|
|
205
|
+
env.POSTGRES_PORT = db.port;
|
|
206
|
+
env.POSTGRES_USER = db.role;
|
|
207
|
+
env.POSTGRES_DB = db.name;
|
|
208
|
+
env.POSTGRES_DATABASE = db.name;
|
|
209
|
+
}
|
|
210
|
+
return env;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Run one bounded recipe command in its own process group, with the replacing
|
|
214
|
+
* environment. On timeout or cancellation the whole group is killed (the helper
|
|
215
|
+
* holds the live child handle, so this group is its own by construction).
|
|
216
|
+
* Stderr is discarded; stdout is captured only up to the bound.
|
|
217
|
+
*/
|
|
218
|
+
export function runRecipeCommand(argv, options, spawnFn = nodeSpawn) {
|
|
219
|
+
return new Promise((resolve) => {
|
|
220
|
+
// An already-aborted signal never fires `abort`: refuse before spawning.
|
|
221
|
+
if (options.signal?.aborted) {
|
|
222
|
+
resolve({ kind: "cancelled", exitCode: null, stdout: "" });
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let child;
|
|
226
|
+
try {
|
|
227
|
+
child = spawnFn(argv[0], argv.slice(1), {
|
|
228
|
+
cwd: options.cwd,
|
|
229
|
+
env: options.env,
|
|
230
|
+
detached: true,
|
|
231
|
+
stdio: ["ignore", options.captureStdout ? "pipe" : "ignore", "ignore"],
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
resolve({ kind: "spawn_failed", exitCode: null, stdout: "" });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
let stdout = "";
|
|
239
|
+
let settled = false;
|
|
240
|
+
let timedOut = false;
|
|
241
|
+
let cancelled = false;
|
|
242
|
+
const killGroup = () => {
|
|
243
|
+
if (typeof child.pid === "number" && child.pid > 1) {
|
|
244
|
+
try {
|
|
245
|
+
process.kill(-child.pid, "SIGKILL");
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
/* already gone */
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const timer = setTimeout(() => {
|
|
253
|
+
timedOut = true;
|
|
254
|
+
killGroup();
|
|
255
|
+
}, Math.max(1, options.timeoutMs));
|
|
256
|
+
const onAbort = () => {
|
|
257
|
+
cancelled = true;
|
|
258
|
+
killGroup();
|
|
259
|
+
};
|
|
260
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
261
|
+
child.stdout?.on("data", (chunk) => {
|
|
262
|
+
if (stdout.length < EPIC_SERVER_MAX_CAPTURED_OUTPUT)
|
|
263
|
+
stdout += chunk.toString("utf8").slice(0, EPIC_SERVER_MAX_CAPTURED_OUTPUT - stdout.length);
|
|
264
|
+
});
|
|
265
|
+
const finish = (outcome) => {
|
|
266
|
+
if (settled)
|
|
267
|
+
return;
|
|
268
|
+
settled = true;
|
|
269
|
+
clearTimeout(timer);
|
|
270
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
271
|
+
resolve(outcome);
|
|
272
|
+
};
|
|
273
|
+
child.on("error", () => finish({ kind: "spawn_failed", exitCode: null, stdout: "" }));
|
|
274
|
+
child.on("close", (code) => {
|
|
275
|
+
if (cancelled)
|
|
276
|
+
finish({ kind: "cancelled", exitCode: code, stdout: "" });
|
|
277
|
+
else if (timedOut)
|
|
278
|
+
finish({ kind: "timeout", exitCode: code, stdout: "" });
|
|
279
|
+
else
|
|
280
|
+
finish({ kind: code === 0 ? "ok" : "failed", exitCode: code, stdout });
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/** Start the app detached in its own process group. Output is discarded (it may carry secrets). */
|
|
285
|
+
export function startAppProcess(argv, options, spawnFn = nodeSpawn) {
|
|
286
|
+
let child;
|
|
287
|
+
try {
|
|
288
|
+
child = spawnFn(argv[0], argv.slice(1), { cwd: options.cwd, env: options.env, detached: true, stdio: ["ignore", "ignore", "ignore"] });
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
if (typeof child.pid !== "number" || child.pid <= 1)
|
|
294
|
+
return null;
|
|
295
|
+
child.on("error", () => undefined);
|
|
296
|
+
return { pid: child.pid, child };
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Parse bounded seed output into the declared `KEY=VALUE` pairs. Lines that are
|
|
300
|
+
* not a declared key are ignored; every declared key must appear exactly once
|
|
301
|
+
* with a non-empty single-line value. Null when the output does not satisfy that.
|
|
302
|
+
*/
|
|
303
|
+
export function parseSeedOutput(stdout, outputs) {
|
|
304
|
+
const found = {};
|
|
305
|
+
for (const raw of stdout.split(/\r?\n/)) {
|
|
306
|
+
const eq = raw.indexOf("=");
|
|
307
|
+
if (eq <= 0)
|
|
308
|
+
continue;
|
|
309
|
+
const key = raw.slice(0, eq).trim();
|
|
310
|
+
if (!outputs.includes(key))
|
|
311
|
+
continue;
|
|
312
|
+
const value = raw.slice(eq + 1);
|
|
313
|
+
if (value.length === 0 || value.length > 1024 || /[\0\r\n]/.test(value))
|
|
314
|
+
return null;
|
|
315
|
+
if (Object.prototype.hasOwnProperty.call(found, key))
|
|
316
|
+
return null;
|
|
317
|
+
found[key] = value;
|
|
318
|
+
}
|
|
319
|
+
return outputs.every((k) => Object.prototype.hasOwnProperty.call(found, k)) ? found : null;
|
|
320
|
+
}
|
|
321
|
+
/** Serialize a login file's content (`KEY=VALUE` lines, declared order). */
|
|
322
|
+
export function formatLoginFile(values, outputs) {
|
|
323
|
+
return `${outputs.map((k) => `${k}=${values[k]}`).join("\n")}\n`;
|
|
324
|
+
}
|