@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,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authoritative epic-server run recipe (BAPI-1546).
|
|
3
|
+
*
|
|
4
|
+
* The driver adapts the repository guidance (`epic-server-guidance.ts`) and the
|
|
5
|
+
* project docs into ONE versioned recipe, written to the private run-state
|
|
6
|
+
* directory outside every worktree. The helper replays only this recipe, exactly,
|
|
7
|
+
* and never improvises. A worker editing guidance on its branch cannot change it.
|
|
8
|
+
*
|
|
9
|
+
* Every command is an argv array. The helper never runs a shell of its own and
|
|
10
|
+
* never expands anything except the documented placeholder `@PORT@` (the run's
|
|
11
|
+
* fixed port). A recipe may still name an interpreter explicitly (for example
|
|
12
|
+
* `sh -c '<script>'`); that script is a literal argument the helper passes as is.
|
|
13
|
+
*
|
|
14
|
+
* Environment for recipe commands is REPLACING, never inherited: only the named
|
|
15
|
+
* literal inputs, approved credential REFERENCES (resolved inside the helper
|
|
16
|
+
* process, never written here), `PORT`, and the helper-owned per-turn database
|
|
17
|
+
* settings reach a recipe subprocess.
|
|
18
|
+
*
|
|
19
|
+
* Every wait is finite. Omitted timing values take the packaged defaults below,
|
|
20
|
+
* and each step must fit inside its enclosing deadline.
|
|
21
|
+
*/
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import { isValidCredentialReference } from "../epic-server-record.js";
|
|
24
|
+
import { isWorkerDatabaseIdentifier } from "../executor/worker-database-config.js";
|
|
25
|
+
export const EPIC_SERVER_RECIPE_VERSION = 1;
|
|
26
|
+
/** The only placeholder the helper substitutes inside an argv token. */
|
|
27
|
+
export const EPIC_SERVER_PORT_PLACEHOLDER = "@PORT@";
|
|
28
|
+
/**
|
|
29
|
+
* Packaged timing defaults, in seconds.
|
|
30
|
+
*
|
|
31
|
+
* A turn has two budgets. `acquire_wait_seconds` bounds the time a request waits
|
|
32
|
+
* in the queue to reach the front. Once it is at the front, the rebuild (fresh
|
|
33
|
+
* checkout, prepare, database, migrate, seed, start, ready) gets its own budget,
|
|
34
|
+
* `proof_seconds`, the same bound the recipe was proven under. So a recipe that
|
|
35
|
+
* proved can always rebuild a turn, however long it queued.
|
|
36
|
+
*/
|
|
37
|
+
export const EPIC_SERVER_DEFAULT_TIMING = Object.freeze({
|
|
38
|
+
proof_seconds: 600,
|
|
39
|
+
step_seconds: 600,
|
|
40
|
+
start_seconds: 120,
|
|
41
|
+
ready_seconds: 60,
|
|
42
|
+
acquire_wait_seconds: 900,
|
|
43
|
+
lease_seconds: 300,
|
|
44
|
+
terminal_poll_seconds: 30,
|
|
45
|
+
terminal_read_seconds: 10,
|
|
46
|
+
cleanup_seconds: 30,
|
|
47
|
+
max_lifetime_seconds: 12 * 60 * 60,
|
|
48
|
+
});
|
|
49
|
+
/** No single timing value may exceed this (two days). */
|
|
50
|
+
const MAX_TIMING_SECONDS = 2 * 24 * 60 * 60;
|
|
51
|
+
const MAX_ARGV_TOKENS = 64;
|
|
52
|
+
const MAX_TOKEN_CHARS = 4096;
|
|
53
|
+
const MAX_STEPS = 16;
|
|
54
|
+
const MAX_ENV_ENTRIES = 32;
|
|
55
|
+
const MAX_ENV_VALUE_CHARS = 1024;
|
|
56
|
+
const MAX_SEED_OUTPUTS = 8;
|
|
57
|
+
const ENV_NAME_RE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
58
|
+
const READY_PATH_RE = /^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]{0,255}$/;
|
|
59
|
+
/**
|
|
60
|
+
* Environment names a recipe may never set itself: the helper owns them, or they
|
|
61
|
+
* would re-open an ambient channel (dotenv loading, the owner's database, the
|
|
62
|
+
* executor's job identity).
|
|
63
|
+
*/
|
|
64
|
+
const RESERVED_ENV_NAMES = new Set([
|
|
65
|
+
"PORT",
|
|
66
|
+
"PATH",
|
|
67
|
+
"HOME",
|
|
68
|
+
"DATABASE_URL",
|
|
69
|
+
"BRIDGE_EXECUTOR_JOB_TAG",
|
|
70
|
+
"BRIDGE_EXECUTOR_JOB_ID",
|
|
71
|
+
"BRIDGE_EPIC_SERVER_INSTANCE_TAG",
|
|
72
|
+
"NODE_OPTIONS",
|
|
73
|
+
"LD_PRELOAD",
|
|
74
|
+
"DYLD_INSERT_LIBRARIES",
|
|
75
|
+
]);
|
|
76
|
+
const RESERVED_ENV_PREFIXES = ["PG", "POSTGRES_", "BAPI_", "BRIDGE_", "DOTENV"];
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Validation
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
function isPlainObject(value) {
|
|
81
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
82
|
+
}
|
|
83
|
+
function hasControlChars(value) {
|
|
84
|
+
for (let k = 0; k < value.length; k++) {
|
|
85
|
+
const code = value.charCodeAt(k);
|
|
86
|
+
if ((code <= 0x1f && code !== 0x09 && code !== 0x0a) || code === 0x7f)
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
/** True for a name a recipe may set in a command environment. */
|
|
92
|
+
export function isRecipeEnvName(name) {
|
|
93
|
+
if (!ENV_NAME_RE.test(name) || RESERVED_ENV_NAMES.has(name))
|
|
94
|
+
return false;
|
|
95
|
+
return !RESERVED_ENV_PREFIXES.some((p) => name.startsWith(p));
|
|
96
|
+
}
|
|
97
|
+
function validateArgv(raw, label) {
|
|
98
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > MAX_ARGV_TOKENS) {
|
|
99
|
+
return { ok: false, error: `${label}: argv must be a non-empty array of at most ${MAX_ARGV_TOKENS} strings` };
|
|
100
|
+
}
|
|
101
|
+
for (const token of raw) {
|
|
102
|
+
if (typeof token !== "string" || token.length > MAX_TOKEN_CHARS || token.includes("\0") || hasControlChars(token)) {
|
|
103
|
+
return { ok: false, error: `${label}: argv holds an unusable token` };
|
|
104
|
+
}
|
|
105
|
+
// `@NAME@` is the placeholder syntax; only the documented one is allowed.
|
|
106
|
+
const placeholders = token.match(/@[A-Z][A-Z0-9_]*@/g) ?? [];
|
|
107
|
+
if (placeholders.some((p) => p !== EPIC_SERVER_PORT_PLACEHOLDER)) {
|
|
108
|
+
return { ok: false, error: `${label}: argv uses an undocumented placeholder` };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const first = raw[0];
|
|
112
|
+
if (first.trim().length === 0)
|
|
113
|
+
return { ok: false, error: `${label}: argv[0] is empty` };
|
|
114
|
+
return { ok: true, argv: [...raw] };
|
|
115
|
+
}
|
|
116
|
+
function validateTimeout(raw, fallback, label) {
|
|
117
|
+
if (raw === undefined)
|
|
118
|
+
return fallback;
|
|
119
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || !Number.isInteger(raw) || raw <= 0 || raw > MAX_TIMING_SECONDS) {
|
|
120
|
+
return `${label}: timeout_seconds must be a positive whole number of seconds`;
|
|
121
|
+
}
|
|
122
|
+
return raw;
|
|
123
|
+
}
|
|
124
|
+
function validateCommand(raw, label, timing) {
|
|
125
|
+
if (!isPlainObject(raw))
|
|
126
|
+
return { ok: false, error: `${label}: must be an object with argv` };
|
|
127
|
+
const argv = validateArgv(raw.argv, label);
|
|
128
|
+
if (!argv.ok)
|
|
129
|
+
return argv;
|
|
130
|
+
const timeout = validateTimeout(raw.timeout_seconds, timing.step_seconds, label);
|
|
131
|
+
if (typeof timeout === "string")
|
|
132
|
+
return { ok: false, error: timeout };
|
|
133
|
+
if (timeout > timing.proof_seconds)
|
|
134
|
+
return { ok: false, error: `${label}: timeout exceeds the proof deadline` };
|
|
135
|
+
return { ok: true, command: { argv: argv.argv, timeout_seconds: timeout } };
|
|
136
|
+
}
|
|
137
|
+
function validateCommandList(raw, label, timing) {
|
|
138
|
+
if (raw === undefined)
|
|
139
|
+
return { ok: true, commands: [] };
|
|
140
|
+
if (!Array.isArray(raw) || raw.length > MAX_STEPS)
|
|
141
|
+
return { ok: false, error: `${label}: must be a list of commands` };
|
|
142
|
+
const commands = [];
|
|
143
|
+
for (let k = 0; k < raw.length; k++) {
|
|
144
|
+
const validated = validateCommand(raw[k], `${label}[${k}]`, timing);
|
|
145
|
+
if (!validated.ok)
|
|
146
|
+
return validated;
|
|
147
|
+
commands.push(validated.command);
|
|
148
|
+
}
|
|
149
|
+
return { ok: true, commands };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Resolve and validate timing. Every value is a finite positive whole number of
|
|
153
|
+
* seconds, and the relationships hold: each step fits the proof deadline, a
|
|
154
|
+
* terminal read fits its poll, and neither a lease nor a turn wait can outlive
|
|
155
|
+
* the helper's maximum lifetime (which renewal never extends). The turn wait
|
|
156
|
+
* must also cover one full turn ahead of it (a rebuild within `proof_seconds`
|
|
157
|
+
* plus a held lease of `lease_seconds`), so a worker queued behind one other
|
|
158
|
+
* worker reaches the front before its wait runs out.
|
|
159
|
+
*/
|
|
160
|
+
export function resolveEpicServerTiming(raw) {
|
|
161
|
+
const timing = { ...EPIC_SERVER_DEFAULT_TIMING };
|
|
162
|
+
if (raw !== undefined) {
|
|
163
|
+
if (!isPlainObject(raw))
|
|
164
|
+
return { ok: false, error: "timing must be an object" };
|
|
165
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
166
|
+
if (!(key in timing))
|
|
167
|
+
continue; // tolerated: unknown timing keys are ignored
|
|
168
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value <= 0 || value > MAX_TIMING_SECONDS) {
|
|
169
|
+
return { ok: false, error: `timing.${key} must be a positive whole number of seconds` };
|
|
170
|
+
}
|
|
171
|
+
timing[key] = value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (timing.step_seconds > timing.proof_seconds)
|
|
175
|
+
return { ok: false, error: "timing.step_seconds exceeds proof_seconds" };
|
|
176
|
+
if (timing.start_seconds > timing.proof_seconds)
|
|
177
|
+
return { ok: false, error: "timing.start_seconds exceeds proof_seconds" };
|
|
178
|
+
if (timing.ready_seconds > timing.proof_seconds)
|
|
179
|
+
return { ok: false, error: "timing.ready_seconds exceeds proof_seconds" };
|
|
180
|
+
if (timing.terminal_read_seconds >= timing.terminal_poll_seconds) {
|
|
181
|
+
return { ok: false, error: "timing.terminal_read_seconds must be shorter than terminal_poll_seconds" };
|
|
182
|
+
}
|
|
183
|
+
if (timing.lease_seconds > timing.max_lifetime_seconds)
|
|
184
|
+
return { ok: false, error: "timing.lease_seconds exceeds max_lifetime_seconds" };
|
|
185
|
+
if (timing.acquire_wait_seconds > timing.max_lifetime_seconds) {
|
|
186
|
+
return { ok: false, error: "timing.acquire_wait_seconds exceeds max_lifetime_seconds" };
|
|
187
|
+
}
|
|
188
|
+
if (timing.acquire_wait_seconds < timing.lease_seconds + timing.proof_seconds) {
|
|
189
|
+
return { ok: false, error: "timing.acquire_wait_seconds is shorter than lease_seconds plus proof_seconds" };
|
|
190
|
+
}
|
|
191
|
+
if (timing.proof_seconds > timing.max_lifetime_seconds)
|
|
192
|
+
return { ok: false, error: "timing.proof_seconds exceeds max_lifetime_seconds" };
|
|
193
|
+
if (timing.cleanup_seconds > timing.proof_seconds)
|
|
194
|
+
return { ok: false, error: "timing.cleanup_seconds exceeds proof_seconds" };
|
|
195
|
+
return { ok: true, timing };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Validate a recipe document. Unknown top-level keys are rejected: the recipe is
|
|
199
|
+
* authoritative input to a process runner, so a misspelled step must not be
|
|
200
|
+
* silently ignored. Error messages are fixed text naming only the field.
|
|
201
|
+
*/
|
|
202
|
+
export function validateEpicServerRecipe(raw) {
|
|
203
|
+
if (!isPlainObject(raw))
|
|
204
|
+
return { ok: false, error: "the recipe is not a JSON object" };
|
|
205
|
+
const allowed = new Set([
|
|
206
|
+
"version",
|
|
207
|
+
"revision",
|
|
208
|
+
"prepare",
|
|
209
|
+
"database",
|
|
210
|
+
"migrate",
|
|
211
|
+
"seed",
|
|
212
|
+
"start",
|
|
213
|
+
"ready",
|
|
214
|
+
"inputs",
|
|
215
|
+
"credential_refs",
|
|
216
|
+
"timing",
|
|
217
|
+
]);
|
|
218
|
+
for (const key of Object.keys(raw))
|
|
219
|
+
if (!allowed.has(key))
|
|
220
|
+
return { ok: false, error: "the recipe has an unknown field" };
|
|
221
|
+
if (raw.version !== EPIC_SERVER_RECIPE_VERSION)
|
|
222
|
+
return { ok: false, error: "the recipe has an unsupported version" };
|
|
223
|
+
if (typeof raw.revision !== "number" || !Number.isSafeInteger(raw.revision) || raw.revision < 1) {
|
|
224
|
+
return { ok: false, error: "the recipe revision must be a positive whole number" };
|
|
225
|
+
}
|
|
226
|
+
const timingResult = resolveEpicServerTiming(raw.timing);
|
|
227
|
+
if (!timingResult.ok)
|
|
228
|
+
return timingResult;
|
|
229
|
+
const timing = timingResult.timing;
|
|
230
|
+
const prepare = validateCommandList(raw.prepare, "prepare", timing);
|
|
231
|
+
if (!prepare.ok)
|
|
232
|
+
return prepare;
|
|
233
|
+
const migrate = validateCommandList(raw.migrate, "migrate", timing);
|
|
234
|
+
if (!migrate.ok)
|
|
235
|
+
return migrate;
|
|
236
|
+
let database = null;
|
|
237
|
+
if (raw.database !== undefined && raw.database !== null) {
|
|
238
|
+
if (!isPlainObject(raw.database) || raw.database.kind !== "disposable_postgres") {
|
|
239
|
+
return { ok: false, error: "database: only kind disposable_postgres is supported" };
|
|
240
|
+
}
|
|
241
|
+
if (!isWorkerDatabaseIdentifier(raw.database.role))
|
|
242
|
+
return { ok: false, error: "database: role is not a usable identifier" };
|
|
243
|
+
database = { kind: "disposable_postgres", role: raw.database.role };
|
|
244
|
+
}
|
|
245
|
+
let seed = null;
|
|
246
|
+
if (raw.seed !== undefined && raw.seed !== null) {
|
|
247
|
+
const command = validateCommand(raw.seed, "seed", timing);
|
|
248
|
+
if (!command.ok)
|
|
249
|
+
return command;
|
|
250
|
+
const outputs = isPlainObject(raw.seed) ? raw.seed.outputs : undefined;
|
|
251
|
+
if (!Array.isArray(outputs) ||
|
|
252
|
+
outputs.length === 0 ||
|
|
253
|
+
outputs.length > MAX_SEED_OUTPUTS ||
|
|
254
|
+
outputs.some((o) => typeof o !== "string" || !ENV_NAME_RE.test(o)) ||
|
|
255
|
+
new Set(outputs).size !== outputs.length) {
|
|
256
|
+
return { ok: false, error: "seed: outputs must list the KEY names the seed prints" };
|
|
257
|
+
}
|
|
258
|
+
seed = { ...command.command, outputs: [...outputs] };
|
|
259
|
+
}
|
|
260
|
+
if (!isPlainObject(raw.start))
|
|
261
|
+
return { ok: false, error: "start: must be an object with argv" };
|
|
262
|
+
const startArgv = validateArgv(raw.start.argv, "start");
|
|
263
|
+
if (!startArgv.ok)
|
|
264
|
+
return startArgv;
|
|
265
|
+
if (!isPlainObject(raw.ready))
|
|
266
|
+
return { ok: false, error: "ready: must be an object" };
|
|
267
|
+
const readyTimeout = validateTimeout(raw.ready.timeout_seconds, timing.ready_seconds, "ready");
|
|
268
|
+
if (typeof readyTimeout === "string")
|
|
269
|
+
return { ok: false, error: readyTimeout };
|
|
270
|
+
if (readyTimeout > timing.proof_seconds)
|
|
271
|
+
return { ok: false, error: "ready: timeout exceeds the proof deadline" };
|
|
272
|
+
let ready;
|
|
273
|
+
if (raw.ready.path !== undefined && raw.ready.argv === undefined) {
|
|
274
|
+
if (typeof raw.ready.path !== "string" || !READY_PATH_RE.test(raw.ready.path) || raw.ready.path.startsWith("//")) {
|
|
275
|
+
return { ok: false, error: "ready: path must be an absolute path on the run's own address" };
|
|
276
|
+
}
|
|
277
|
+
ready = { kind: "url", path: raw.ready.path, timeout_seconds: readyTimeout };
|
|
278
|
+
}
|
|
279
|
+
else if (raw.ready.argv !== undefined && raw.ready.path === undefined) {
|
|
280
|
+
const argv = validateArgv(raw.ready.argv, "ready");
|
|
281
|
+
if (!argv.ok)
|
|
282
|
+
return argv;
|
|
283
|
+
ready = { kind: "command", argv: argv.argv, timeout_seconds: readyTimeout };
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
return { ok: false, error: "ready: give exactly one of path or argv" };
|
|
287
|
+
}
|
|
288
|
+
const inputs = {};
|
|
289
|
+
if (raw.inputs !== undefined) {
|
|
290
|
+
if (!isPlainObject(raw.inputs) || Object.keys(raw.inputs).length > MAX_ENV_ENTRIES) {
|
|
291
|
+
return { ok: false, error: "inputs: must be an object of named values" };
|
|
292
|
+
}
|
|
293
|
+
for (const [name, value] of Object.entries(raw.inputs)) {
|
|
294
|
+
if (!isRecipeEnvName(name))
|
|
295
|
+
return { ok: false, error: "inputs: a name is reserved or unusable" };
|
|
296
|
+
if (typeof value !== "string" || value.length > MAX_ENV_VALUE_CHARS || value.includes("\0") || hasControlChars(value)) {
|
|
297
|
+
return { ok: false, error: "inputs: a value is unusable" };
|
|
298
|
+
}
|
|
299
|
+
inputs[name] = value;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const credentialRefs = {};
|
|
303
|
+
if (raw.credential_refs !== undefined) {
|
|
304
|
+
if (!isPlainObject(raw.credential_refs) || Object.keys(raw.credential_refs).length > MAX_ENV_ENTRIES) {
|
|
305
|
+
return { ok: false, error: "credential_refs: must be an object of named references" };
|
|
306
|
+
}
|
|
307
|
+
for (const [name, value] of Object.entries(raw.credential_refs)) {
|
|
308
|
+
if (!isRecipeEnvName(name) || name in inputs)
|
|
309
|
+
return { ok: false, error: "credential_refs: a name is reserved or unusable" };
|
|
310
|
+
if (!isPlainObject(value) || !isValidCredentialReference(value.ref) || typeof value.key !== "string" || !/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(value.key)) {
|
|
311
|
+
return { ok: false, error: "credential_refs: each entry needs a ref and a key name" };
|
|
312
|
+
}
|
|
313
|
+
if (Object.keys(value).some((k) => k !== "ref" && k !== "key")) {
|
|
314
|
+
// A raw secret value never belongs here.
|
|
315
|
+
return { ok: false, error: "credential_refs: an entry holds more than a reference" };
|
|
316
|
+
}
|
|
317
|
+
credentialRefs[name] = { ref: value.ref, key: value.key };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (seed && Object.keys(credentialRefs).some((name) => seed.outputs.includes(name))) {
|
|
321
|
+
return { ok: false, error: "seed: an output name collides with a credential reference" };
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
ok: true,
|
|
325
|
+
recipe: {
|
|
326
|
+
version: EPIC_SERVER_RECIPE_VERSION,
|
|
327
|
+
revision: raw.revision,
|
|
328
|
+
prepare: prepare.commands,
|
|
329
|
+
database,
|
|
330
|
+
migrate: migrate.commands,
|
|
331
|
+
seed,
|
|
332
|
+
start: { argv: startArgv.argv },
|
|
333
|
+
ready,
|
|
334
|
+
inputs,
|
|
335
|
+
credential_refs: credentialRefs,
|
|
336
|
+
timing,
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/** Canonical JSON (sorted keys) of a validated recipe. */
|
|
341
|
+
function canonicalJson(value) {
|
|
342
|
+
if (Array.isArray(value))
|
|
343
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
344
|
+
if (value !== null && typeof value === "object") {
|
|
345
|
+
const entries = Object.keys(value)
|
|
346
|
+
.sort()
|
|
347
|
+
.map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`);
|
|
348
|
+
return `{${entries.join(",")}}`;
|
|
349
|
+
}
|
|
350
|
+
return JSON.stringify(value);
|
|
351
|
+
}
|
|
352
|
+
/** The recipe's digest: sha256 of its canonical, validated form. */
|
|
353
|
+
export function epicServerRecipeDigest(recipe) {
|
|
354
|
+
return createHash("sha256").update(canonicalJson(recipe)).digest("hex");
|
|
355
|
+
}
|
|
356
|
+
/** Substitute `@PORT@` in one argv. Nothing else is ever expanded. */
|
|
357
|
+
export function substituteRecipeArgv(argv, port) {
|
|
358
|
+
return argv.map((token) => token.split(EPIC_SERVER_PORT_PLACEHOLDER).join(String(port)));
|
|
359
|
+
}
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
// Proof binding
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
export const EPIC_SERVER_PROOF_VERSION = 1;
|
|
364
|
+
const SHA_RE = /^[0-9a-f]{40}$/;
|
|
365
|
+
const DIGEST_RE = /^[0-9a-f]{64}$/;
|
|
366
|
+
/** True for a full 40-character lowercase commit SHA. */
|
|
367
|
+
export function isFullCommitSha(value) {
|
|
368
|
+
return typeof value === "string" && SHA_RE.test(value);
|
|
369
|
+
}
|
|
370
|
+
export function validateEpicServerProof(raw) {
|
|
371
|
+
if (!isPlainObject(raw))
|
|
372
|
+
return null;
|
|
373
|
+
if (raw.version !== EPIC_SERVER_PROOF_VERSION)
|
|
374
|
+
return null;
|
|
375
|
+
if (typeof raw.recipe_digest !== "string" || !DIGEST_RE.test(raw.recipe_digest))
|
|
376
|
+
return null;
|
|
377
|
+
if (typeof raw.recipe_revision !== "number" || !Number.isSafeInteger(raw.recipe_revision) || raw.recipe_revision < 1)
|
|
378
|
+
return null;
|
|
379
|
+
if (!isFullCommitSha(raw.epic_head))
|
|
380
|
+
return null;
|
|
381
|
+
if (typeof raw.proved_at !== "string" || Number.isNaN(Date.parse(raw.proved_at)))
|
|
382
|
+
return null;
|
|
383
|
+
return {
|
|
384
|
+
version: EPIC_SERVER_PROOF_VERSION,
|
|
385
|
+
recipe_digest: raw.recipe_digest,
|
|
386
|
+
recipe_revision: raw.recipe_revision,
|
|
387
|
+
epic_head: raw.epic_head,
|
|
388
|
+
proved_at: raw.proved_at,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* A start may serve `recipe` at `epicHead` only when a proof names exactly that
|
|
393
|
+
* recipe digest and that head. Changing the recipe needs another proof.
|
|
394
|
+
*/
|
|
395
|
+
export function proofCoversStart(proof, recipe, epicHead) {
|
|
396
|
+
return proof !== null && proof.recipe_digest === epicServerRecipeDigest(recipe) && proof.epic_head === epicHead;
|
|
397
|
+
}
|