@bridge_gpt/mcp-server 0.2.69 → 0.2.71
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 +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository-root toolchain resolution (BAPI-1536).
|
|
3
|
+
*
|
|
4
|
+
* One read-only answer to "what does this repository need installed before its
|
|
5
|
+
* stored test command can run?". Test-command detection uses it to pick the
|
|
6
|
+
* package manager, and the CI workflow renderer uses it to provision
|
|
7
|
+
* dependencies, so the two can never disagree.
|
|
8
|
+
*
|
|
9
|
+
* ## Contract
|
|
10
|
+
*
|
|
11
|
+
* - READ ONLY. The only effect is the injected {@link RepositoryFileReader}, and
|
|
12
|
+
* it is called only for a fixed allowlist of repository-root files. Nothing
|
|
13
|
+
* here runs a package manager, a subprocess, or a network call, and nothing
|
|
14
|
+
* consults the server's indexing metadata: the local working tree is the input.
|
|
15
|
+
* - Deterministic. The same files always give the same answer.
|
|
16
|
+
* - Fail closed. A relevant file that cannot be read, or metadata that is
|
|
17
|
+
* malformed, contradictory, or unsupported, makes the whole answer `unknown`.
|
|
18
|
+
* It never falls through to a lower-priority manager or to "no lockfile".
|
|
19
|
+
* - Sanitized. Failures carry a fixed repository-relative path from the
|
|
20
|
+
* allowlist and a closed reason, never exception text or file content.
|
|
21
|
+
*
|
|
22
|
+
* ## Priority
|
|
23
|
+
*
|
|
24
|
+
* - JavaScript: `pnpm-lock.yaml`, `yarn.lock`, `npm-shrinkwrap.json`,
|
|
25
|
+
* `package-lock.json`, `bun.lock`, then `bun.lockb`.
|
|
26
|
+
* - Python: `uv.lock`, `poetry.lock`, then `requirements.txt`.
|
|
27
|
+
* - Go (`go.mod`), unsupported Python manifests, and Rust (`Cargo.toml`) are
|
|
28
|
+
* detected independently of the two above and of any Makefile.
|
|
29
|
+
*
|
|
30
|
+
* ## Versions
|
|
31
|
+
*
|
|
32
|
+
* - Node: `.nvmrc`, then `.node-version`, then {@link NODE_FALLBACK_MAJOR}.
|
|
33
|
+
* - Python: `.python-version`, then {@link PYTHON_FALLBACK_MINOR}.
|
|
34
|
+
* - pnpm: a validated `package.json` `packageManager` version, else
|
|
35
|
+
* {@link PNPM_FALLBACK_MAJOR}.
|
|
36
|
+
* - Yarn: classic or Berry from `.yarnrc.yml`, `packageManager`, and the lockfile
|
|
37
|
+
* header. Corepack consumes a declared Berry version at CI runtime.
|
|
38
|
+
*
|
|
39
|
+
* The resolved set serializes to one canonical single line
|
|
40
|
+
* ({@link serializeRepositoryToolchains}) that the workflow header carries, and
|
|
41
|
+
* {@link parseRepositoryToolchains} reads it back strictly. A parsed set that
|
|
42
|
+
* re-serializes to different bytes is refused, so a marker can never claim more
|
|
43
|
+
* than the closed vocabulary below.
|
|
44
|
+
*/
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Fixed constants (documented; changing any of them is a renderer-version change)
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
/** Node major used when neither `.nvmrc` nor `.node-version` exists (the active LTS line). */
|
|
49
|
+
export const NODE_FALLBACK_MAJOR = "24";
|
|
50
|
+
/** Python minor used when `.python-version` does not exist. */
|
|
51
|
+
export const PYTHON_FALLBACK_MINOR = "3.12";
|
|
52
|
+
/** pnpm major used when `package.json` declares no `packageManager`. */
|
|
53
|
+
export const PNPM_FALLBACK_MAJOR = "10";
|
|
54
|
+
/** Yarn Berry major activated through Corepack when nothing declares a version. */
|
|
55
|
+
export const YARN_BERRY_FALLBACK_MAJOR = "4";
|
|
56
|
+
/** Bun version range installed for Bun projects. */
|
|
57
|
+
export const BUN_VERSION_RANGE = "1.x";
|
|
58
|
+
/** Poetry version installed for Poetry projects. */
|
|
59
|
+
export const POETRY_VERSION = "2.1.3";
|
|
60
|
+
const JAVASCRIPT_LOCKFILES = [
|
|
61
|
+
"pnpm-lock.yaml",
|
|
62
|
+
"yarn.lock",
|
|
63
|
+
"npm-shrinkwrap.json",
|
|
64
|
+
"package-lock.json",
|
|
65
|
+
"bun.lock",
|
|
66
|
+
"bun.lockb",
|
|
67
|
+
];
|
|
68
|
+
const PYTHON_LOCKFILES = ["uv.lock", "poetry.lock", "requirements.txt"];
|
|
69
|
+
/** Python manifests that name dependencies but that Bridge does not install. */
|
|
70
|
+
const UNSUPPORTED_PYTHON_MANIFESTS = ["pyproject.toml", "Pipfile", "setup.py", "environment.yml"];
|
|
71
|
+
/** Whether the set provisions nothing. */
|
|
72
|
+
export function hasNoProvisionedToolchain(toolchains) {
|
|
73
|
+
return toolchains.javascript === null && toolchains.python === null && toolchains.go === null;
|
|
74
|
+
}
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Optional reads (the one missing-versus-failed classifier)
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
/** A relevant repository file could not be read. Carries only the allowlisted path. */
|
|
79
|
+
export class RepositoryReadError extends Error {
|
|
80
|
+
file;
|
|
81
|
+
constructor(file) {
|
|
82
|
+
super("repository_read_failed");
|
|
83
|
+
this.file = file;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Whether `err` means the file or one of its parents does not exist. */
|
|
87
|
+
export function isMissingFileError(err) {
|
|
88
|
+
const code = typeof err === "object" && err !== null ? err.code : undefined;
|
|
89
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read a repository file that may be absent. Missing is `null`; any other
|
|
93
|
+
* failure throws {@link RepositoryReadError}, so an unreadable file is never
|
|
94
|
+
* mistaken for an absent one.
|
|
95
|
+
*/
|
|
96
|
+
export async function readOptionalRepositoryFile(readFile, relPath) {
|
|
97
|
+
try {
|
|
98
|
+
return await readFile(relPath);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (isMissingFileError(err))
|
|
102
|
+
return null;
|
|
103
|
+
throw new RepositoryReadError(relPath);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
// Resolution
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
class ToolchainFailureError extends Error {
|
|
110
|
+
failure;
|
|
111
|
+
constructor(failure) {
|
|
112
|
+
super(failure.reason);
|
|
113
|
+
this.failure = failure;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function failWith(file, reason) {
|
|
117
|
+
throw new ToolchainFailureError({ file, reason });
|
|
118
|
+
}
|
|
119
|
+
/** Read an optional file, turning a read failure into a recorded `unreadable` failure. */
|
|
120
|
+
async function read(readFile, relPath) {
|
|
121
|
+
try {
|
|
122
|
+
return await readOptionalRepositoryFile(readFile, relPath);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
if (err instanceof RepositoryReadError)
|
|
126
|
+
return failWith(relPath, "unreadable");
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async function exists(readFile, relPath) {
|
|
131
|
+
return (await read(readFile, relPath)) !== null;
|
|
132
|
+
}
|
|
133
|
+
const SEMVER_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
134
|
+
/**
|
|
135
|
+
* Parse `package.json`'s `packageManager` (`name@x.y.z`, optionally followed by
|
|
136
|
+
* a Corepack `+sha…` suffix). `null` when absent. A present but unusable value
|
|
137
|
+
* is a `malformed` failure for `package.json`.
|
|
138
|
+
*/
|
|
139
|
+
function parsePackageManagerField(packageJson) {
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = JSON.parse(packageJson);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return failWith("package.json", "malformed");
|
|
146
|
+
}
|
|
147
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
148
|
+
return failWith("package.json", "malformed");
|
|
149
|
+
}
|
|
150
|
+
const field = parsed.packageManager;
|
|
151
|
+
if (field === undefined)
|
|
152
|
+
return null;
|
|
153
|
+
if (typeof field !== "string")
|
|
154
|
+
return failWith("package.json", "malformed");
|
|
155
|
+
const match = /^([a-z]+)@([0-9A-Za-z.\-]+)(\+[0-9A-Za-z.\-]+)?$/.exec(field);
|
|
156
|
+
if (!match)
|
|
157
|
+
return failWith("package.json", "malformed");
|
|
158
|
+
return { name: match[1], version: match[2] };
|
|
159
|
+
}
|
|
160
|
+
async function resolveNodeSource(readFile) {
|
|
161
|
+
if (await exists(readFile, ".nvmrc"))
|
|
162
|
+
return ".nvmrc";
|
|
163
|
+
if (await exists(readFile, ".node-version"))
|
|
164
|
+
return ".node-version";
|
|
165
|
+
return "fixed";
|
|
166
|
+
}
|
|
167
|
+
async function resolvePythonSource(readFile) {
|
|
168
|
+
return (await exists(readFile, ".python-version")) ? ".python-version" : "fixed";
|
|
169
|
+
}
|
|
170
|
+
async function resolveJavaScript(readFile) {
|
|
171
|
+
let selected = null;
|
|
172
|
+
let lockfileText = null;
|
|
173
|
+
for (const name of JAVASCRIPT_LOCKFILES) {
|
|
174
|
+
const text = await read(readFile, name);
|
|
175
|
+
if (text !== null) {
|
|
176
|
+
selected = name;
|
|
177
|
+
lockfileText = text;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (selected === null) {
|
|
182
|
+
return { toolchain: null, sawPackageJson: await exists(readFile, "package.json") };
|
|
183
|
+
}
|
|
184
|
+
switch (selected) {
|
|
185
|
+
case "package-lock.json":
|
|
186
|
+
case "npm-shrinkwrap.json":
|
|
187
|
+
return {
|
|
188
|
+
toolchain: { manager: "npm", dependencyFile: selected, node: await resolveNodeSource(readFile) },
|
|
189
|
+
sawPackageJson: true,
|
|
190
|
+
};
|
|
191
|
+
case "bun.lock":
|
|
192
|
+
case "bun.lockb":
|
|
193
|
+
return { toolchain: { manager: "bun", dependencyFile: selected }, sawPackageJson: true };
|
|
194
|
+
case "pnpm-lock.yaml": {
|
|
195
|
+
const declared = await readPackageManager(readFile);
|
|
196
|
+
if (declared !== null && declared.name !== "pnpm")
|
|
197
|
+
return failWith("package.json", "contradictory");
|
|
198
|
+
let pnpm = { source: "default" };
|
|
199
|
+
if (declared !== null) {
|
|
200
|
+
if (!SEMVER_RE.test(declared.version))
|
|
201
|
+
return failWith("package.json", "unsupported");
|
|
202
|
+
pnpm = { source: "package_manager", version: declared.version };
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
toolchain: { manager: "pnpm", dependencyFile: "pnpm-lock.yaml", node: await resolveNodeSource(readFile), pnpm },
|
|
206
|
+
sawPackageJson: true,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
case "yarn.lock": {
|
|
210
|
+
const declared = await readPackageManager(readFile);
|
|
211
|
+
if (declared !== null && declared.name !== "yarn")
|
|
212
|
+
return failWith("package.json", "contradictory");
|
|
213
|
+
const hasYarnrc = await exists(readFile, ".yarnrc.yml");
|
|
214
|
+
const lockIsBerry = /^__metadata:/m.test(lockfileText ?? "");
|
|
215
|
+
let declaredMajor = null;
|
|
216
|
+
if (declared !== null) {
|
|
217
|
+
if (!SEMVER_RE.test(declared.version))
|
|
218
|
+
return failWith("package.json", "unsupported");
|
|
219
|
+
declaredMajor = Number(declared.version.split(".")[0]);
|
|
220
|
+
}
|
|
221
|
+
const node = await resolveNodeSource(readFile);
|
|
222
|
+
const berrySignals = hasYarnrc || lockIsBerry || (declaredMajor !== null && declaredMajor >= 2);
|
|
223
|
+
const classicSignals = declaredMajor === 1;
|
|
224
|
+
if (berrySignals && classicSignals)
|
|
225
|
+
return failWith("package.json", "contradictory");
|
|
226
|
+
if (berrySignals) {
|
|
227
|
+
return {
|
|
228
|
+
toolchain: {
|
|
229
|
+
manager: "yarn",
|
|
230
|
+
generation: "berry",
|
|
231
|
+
dependencyFile: "yarn.lock",
|
|
232
|
+
node,
|
|
233
|
+
yarn: declared !== null ? "package_manager" : "default",
|
|
234
|
+
},
|
|
235
|
+
sawPackageJson: true,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
toolchain: { manager: "yarn", generation: "classic", dependencyFile: "yarn.lock", node },
|
|
240
|
+
sawPackageJson: true,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function readPackageManager(readFile) {
|
|
246
|
+
const text = await read(readFile, "package.json");
|
|
247
|
+
if (text === null)
|
|
248
|
+
return null;
|
|
249
|
+
return parsePackageManagerField(text);
|
|
250
|
+
}
|
|
251
|
+
async function resolvePython(readFile) {
|
|
252
|
+
for (const name of PYTHON_LOCKFILES) {
|
|
253
|
+
if (!(await exists(readFile, name)))
|
|
254
|
+
continue;
|
|
255
|
+
const python = await resolvePythonSource(readFile);
|
|
256
|
+
if (name === "uv.lock")
|
|
257
|
+
return { manager: "uv", dependencyFile: "uv.lock", python };
|
|
258
|
+
if (name === "poetry.lock")
|
|
259
|
+
return { manager: "poetry", dependencyFile: "poetry.lock", python };
|
|
260
|
+
return { manager: "pip", dependencyFile: "requirements.txt", python };
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
async function hasUnsupportedPython(readFile) {
|
|
265
|
+
for (const name of UNSUPPORTED_PYTHON_MANIFESTS) {
|
|
266
|
+
if (await exists(readFile, name))
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Resolve the toolchains from the repository root. Never throws for an expected
|
|
273
|
+
* failure: an unreadable, malformed, contradictory, or unsupported relevant file
|
|
274
|
+
* is `status: "unknown"`.
|
|
275
|
+
*/
|
|
276
|
+
export async function resolveRepositoryToolchains(readFile) {
|
|
277
|
+
const failures = [];
|
|
278
|
+
const attempt = async (step) => {
|
|
279
|
+
try {
|
|
280
|
+
return await step();
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
if (err instanceof ToolchainFailureError) {
|
|
284
|
+
failures.push(err.failure);
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
const js = await attempt(() => resolveJavaScript(readFile));
|
|
291
|
+
const python = await attempt(() => resolvePython(readFile));
|
|
292
|
+
const goPresent = await attempt(() => exists(readFile, "go.mod"));
|
|
293
|
+
const rust = await attempt(() => exists(readFile, "Cargo.toml"));
|
|
294
|
+
const unsupportedPython = python === null ? await attempt(() => hasUnsupportedPython(readFile)) : python === undefined ? undefined : false;
|
|
295
|
+
if (failures.length > 0)
|
|
296
|
+
return { status: "unknown", failures };
|
|
297
|
+
return {
|
|
298
|
+
status: "resolved",
|
|
299
|
+
toolchains: {
|
|
300
|
+
javascript: js?.toolchain ?? null,
|
|
301
|
+
python: python ?? null,
|
|
302
|
+
go: goPresent === true ? { dependencyFile: "go.mod" } : null,
|
|
303
|
+
},
|
|
304
|
+
diagnostics: {
|
|
305
|
+
unsupportedPython: unsupportedPython === true,
|
|
306
|
+
rust: rust === true,
|
|
307
|
+
javascriptWithoutLockfile: js !== undefined && js.toolchain === null && js.sawPackageJson,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
// ---------------------------------------------------------------------------
|
|
312
|
+
// Canonical serialization
|
|
313
|
+
// ---------------------------------------------------------------------------
|
|
314
|
+
/** The version of the serialized shape. */
|
|
315
|
+
export const REPOSITORY_TOOLCHAINS_SERIAL_VERSION = 1;
|
|
316
|
+
function serializeManagerVersion(version) {
|
|
317
|
+
return version.source === "package_manager"
|
|
318
|
+
? { source: "package_manager", version: version.version }
|
|
319
|
+
: { source: "default" };
|
|
320
|
+
}
|
|
321
|
+
function serializeJavaScript(js) {
|
|
322
|
+
switch (js.manager) {
|
|
323
|
+
case "npm":
|
|
324
|
+
return { manager: "npm", file: js.dependencyFile, node: js.node };
|
|
325
|
+
case "pnpm":
|
|
326
|
+
return { manager: "pnpm", file: js.dependencyFile, node: js.node, pnpm: serializeManagerVersion(js.pnpm) };
|
|
327
|
+
case "yarn":
|
|
328
|
+
return js.generation === "classic"
|
|
329
|
+
? { manager: "yarn", generation: "classic", file: js.dependencyFile, node: js.node }
|
|
330
|
+
: { manager: "yarn", generation: "berry", file: js.dependencyFile, node: js.node, yarn: js.yarn };
|
|
331
|
+
case "bun":
|
|
332
|
+
return { manager: "bun", file: js.dependencyFile };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Serialize to one canonical line. Key order is fixed, so equal sets always
|
|
337
|
+
* give equal bytes.
|
|
338
|
+
*/
|
|
339
|
+
export function serializeRepositoryToolchains(toolchains) {
|
|
340
|
+
return JSON.stringify({
|
|
341
|
+
version: REPOSITORY_TOOLCHAINS_SERIAL_VERSION,
|
|
342
|
+
javascript: toolchains.javascript === null ? null : serializeJavaScript(toolchains.javascript),
|
|
343
|
+
python: toolchains.python === null
|
|
344
|
+
? null
|
|
345
|
+
: { manager: toolchains.python.manager, file: toolchains.python.dependencyFile, python: toolchains.python.python },
|
|
346
|
+
go: toolchains.go === null ? null : { file: toolchains.go.dependencyFile },
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function isObject(value) {
|
|
350
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
351
|
+
}
|
|
352
|
+
/** Whether `value` is an object with exactly the keys in `keys`. */
|
|
353
|
+
function hasExactKeys(value, keys) {
|
|
354
|
+
const actual = Object.keys(value);
|
|
355
|
+
return actual.length === keys.length && keys.every((key) => Object.prototype.hasOwnProperty.call(value, key));
|
|
356
|
+
}
|
|
357
|
+
function parseNodeSource(value) {
|
|
358
|
+
return value === ".nvmrc" || value === ".node-version" || value === "fixed" ? value : null;
|
|
359
|
+
}
|
|
360
|
+
function parsePythonSource(value) {
|
|
361
|
+
return value === ".python-version" || value === "fixed" ? value : null;
|
|
362
|
+
}
|
|
363
|
+
function parseManagerVersion(value) {
|
|
364
|
+
if (!isObject(value))
|
|
365
|
+
return null;
|
|
366
|
+
if (hasExactKeys(value, ["source"]) && value.source === "default")
|
|
367
|
+
return { source: "default" };
|
|
368
|
+
if (hasExactKeys(value, ["source", "version"]) &&
|
|
369
|
+
value.source === "package_manager" &&
|
|
370
|
+
typeof value.version === "string" &&
|
|
371
|
+
SEMVER_RE.test(value.version)) {
|
|
372
|
+
return { source: "package_manager", version: value.version };
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
function parseJavaScript(value) {
|
|
377
|
+
if (!isObject(value))
|
|
378
|
+
return null;
|
|
379
|
+
switch (value.manager) {
|
|
380
|
+
case "npm": {
|
|
381
|
+
const node = parseNodeSource(value.node);
|
|
382
|
+
if (!hasExactKeys(value, ["manager", "file", "node"]) || node === null)
|
|
383
|
+
return null;
|
|
384
|
+
if (value.file !== "package-lock.json" && value.file !== "npm-shrinkwrap.json")
|
|
385
|
+
return null;
|
|
386
|
+
return { manager: "npm", dependencyFile: value.file, node };
|
|
387
|
+
}
|
|
388
|
+
case "pnpm": {
|
|
389
|
+
const node = parseNodeSource(value.node);
|
|
390
|
+
const pnpm = parseManagerVersion(value.pnpm);
|
|
391
|
+
if (!hasExactKeys(value, ["manager", "file", "node", "pnpm"]) || node === null || pnpm === null)
|
|
392
|
+
return null;
|
|
393
|
+
if (value.file !== "pnpm-lock.yaml")
|
|
394
|
+
return null;
|
|
395
|
+
return { manager: "pnpm", dependencyFile: "pnpm-lock.yaml", node, pnpm };
|
|
396
|
+
}
|
|
397
|
+
case "yarn": {
|
|
398
|
+
const node = parseNodeSource(value.node);
|
|
399
|
+
if (node === null || value.file !== "yarn.lock")
|
|
400
|
+
return null;
|
|
401
|
+
if (value.generation === "classic") {
|
|
402
|
+
if (!hasExactKeys(value, ["manager", "generation", "file", "node"]))
|
|
403
|
+
return null;
|
|
404
|
+
return { manager: "yarn", generation: "classic", dependencyFile: "yarn.lock", node };
|
|
405
|
+
}
|
|
406
|
+
if (value.generation === "berry") {
|
|
407
|
+
if (!hasExactKeys(value, ["manager", "generation", "file", "node", "yarn"]))
|
|
408
|
+
return null;
|
|
409
|
+
if (value.yarn !== "package_manager" && value.yarn !== "default")
|
|
410
|
+
return null;
|
|
411
|
+
return { manager: "yarn", generation: "berry", dependencyFile: "yarn.lock", node, yarn: value.yarn };
|
|
412
|
+
}
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
case "bun": {
|
|
416
|
+
if (!hasExactKeys(value, ["manager", "file"]))
|
|
417
|
+
return null;
|
|
418
|
+
if (value.file !== "bun.lock" && value.file !== "bun.lockb")
|
|
419
|
+
return null;
|
|
420
|
+
return { manager: "bun", dependencyFile: value.file };
|
|
421
|
+
}
|
|
422
|
+
default:
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function parsePython(value) {
|
|
427
|
+
if (!isObject(value) || !hasExactKeys(value, ["manager", "file", "python"]))
|
|
428
|
+
return null;
|
|
429
|
+
const python = parsePythonSource(value.python);
|
|
430
|
+
if (python === null)
|
|
431
|
+
return null;
|
|
432
|
+
if (value.manager === "uv" && value.file === "uv.lock")
|
|
433
|
+
return { manager: "uv", dependencyFile: "uv.lock", python };
|
|
434
|
+
if (value.manager === "poetry" && value.file === "poetry.lock") {
|
|
435
|
+
return { manager: "poetry", dependencyFile: "poetry.lock", python };
|
|
436
|
+
}
|
|
437
|
+
if (value.manager === "pip" && value.file === "requirements.txt") {
|
|
438
|
+
return { manager: "pip", dependencyFile: "requirements.txt", python };
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Parse a serialized set strictly. Returns `null` for anything that is not
|
|
444
|
+
* exactly what {@link serializeRepositoryToolchains} produces: unknown fields,
|
|
445
|
+
* unsupported variants, invalid versions, a different serial version, or bytes
|
|
446
|
+
* that do not round-trip.
|
|
447
|
+
*/
|
|
448
|
+
export function parseRepositoryToolchains(text) {
|
|
449
|
+
let raw;
|
|
450
|
+
try {
|
|
451
|
+
raw = JSON.parse(text);
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
if (!isObject(raw) || !hasExactKeys(raw, ["version", "javascript", "python", "go"]))
|
|
457
|
+
return null;
|
|
458
|
+
if (raw.version !== REPOSITORY_TOOLCHAINS_SERIAL_VERSION)
|
|
459
|
+
return null;
|
|
460
|
+
const javascript = raw.javascript === null ? null : parseJavaScript(raw.javascript);
|
|
461
|
+
if (raw.javascript !== null && javascript === null)
|
|
462
|
+
return null;
|
|
463
|
+
const python = raw.python === null ? null : parsePython(raw.python);
|
|
464
|
+
if (raw.python !== null && python === null)
|
|
465
|
+
return null;
|
|
466
|
+
let go = null;
|
|
467
|
+
if (raw.go !== null) {
|
|
468
|
+
if (!isObject(raw.go) || !hasExactKeys(raw.go, ["file"]) || raw.go.file !== "go.mod")
|
|
469
|
+
return null;
|
|
470
|
+
go = { dependencyFile: "go.mod" };
|
|
471
|
+
}
|
|
472
|
+
const set = { javascript, python, go };
|
|
473
|
+
return serializeRepositoryToolchains(set) === text ? set : null;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Validate a set before it is rendered. Throws {@link RepositoryToolchainError}
|
|
477
|
+
* for anything the serializer would not round-trip, so a hand-built value with
|
|
478
|
+
* an unsupported variant or an invalid version can never reach the workflow.
|
|
479
|
+
*/
|
|
480
|
+
export class RepositoryToolchainError extends Error {
|
|
481
|
+
constructor() {
|
|
482
|
+
super("invalid_toolchain_set");
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
export function validateRepositoryToolchains(toolchains) {
|
|
486
|
+
let text;
|
|
487
|
+
try {
|
|
488
|
+
text = serializeRepositoryToolchains(toolchains);
|
|
489
|
+
}
|
|
490
|
+
catch {
|
|
491
|
+
throw new RepositoryToolchainError();
|
|
492
|
+
}
|
|
493
|
+
const parsed = parseRepositoryToolchains(text);
|
|
494
|
+
if (parsed === null)
|
|
495
|
+
throw new RepositoryToolchainError();
|
|
496
|
+
return parsed;
|
|
497
|
+
}
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
// Plain-language descriptions (operator output and pull request text)
|
|
500
|
+
// ---------------------------------------------------------------------------
|
|
501
|
+
function describeNode(node) {
|
|
502
|
+
return node === "fixed" ? `Node ${NODE_FALLBACK_MAJOR} (fixed fallback)` : `Node from ${node}`;
|
|
503
|
+
}
|
|
504
|
+
function describePython(python) {
|
|
505
|
+
return python === "fixed" ? `Python ${PYTHON_FALLBACK_MINOR} (fixed fallback)` : `Python from ${python}`;
|
|
506
|
+
}
|
|
507
|
+
function describeManagerVersion(name, version, fallback) {
|
|
508
|
+
return version.source === "package_manager"
|
|
509
|
+
? `${name} ${version.version} (from package.json)`
|
|
510
|
+
: `${name} ${fallback} (fixed fallback)`;
|
|
511
|
+
}
|
|
512
|
+
/** One plain line for the JavaScript selection. Never carries repository text beyond a validated version. */
|
|
513
|
+
export function describeJavaScriptToolchain(js) {
|
|
514
|
+
switch (js.manager) {
|
|
515
|
+
case "npm":
|
|
516
|
+
return `JavaScript: npm (${js.dependencyFile}); ${describeNode(js.node)}; installs with npm ci`;
|
|
517
|
+
case "pnpm":
|
|
518
|
+
return (`JavaScript: pnpm (${js.dependencyFile}); ${describeManagerVersion("pnpm", js.pnpm, PNPM_FALLBACK_MAJOR)}; ` +
|
|
519
|
+
`${describeNode(js.node)}; installs with pnpm install --frozen-lockfile`);
|
|
520
|
+
case "yarn":
|
|
521
|
+
return js.generation === "classic"
|
|
522
|
+
? `JavaScript: Yarn classic (${js.dependencyFile}); ${describeNode(js.node)}; installs with yarn install --frozen-lockfile`
|
|
523
|
+
: `JavaScript: Yarn Berry (${js.dependencyFile}); ` +
|
|
524
|
+
(js.yarn === "package_manager"
|
|
525
|
+
? "Yarn version from package.json through Corepack"
|
|
526
|
+
: `Yarn ${YARN_BERRY_FALLBACK_MAJOR} (fixed fallback) through Corepack`) +
|
|
527
|
+
`; ${describeNode(js.node)}; installs with yarn install --immutable`;
|
|
528
|
+
case "bun":
|
|
529
|
+
return `JavaScript: Bun (${js.dependencyFile}); Bun ${BUN_VERSION_RANGE}; installs with bun install --frozen-lockfile`;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/** One plain line for the Python selection. */
|
|
533
|
+
export function describePythonToolchain(py) {
|
|
534
|
+
switch (py.manager) {
|
|
535
|
+
case "uv":
|
|
536
|
+
return `Python: uv (${py.dependencyFile}); ${describePython(py.python)}; installs with uv sync --frozen`;
|
|
537
|
+
case "poetry":
|
|
538
|
+
return (`Python: Poetry (${py.dependencyFile}); Poetry ${POETRY_VERSION}; ${describePython(py.python)}; ` +
|
|
539
|
+
"installs with poetry install");
|
|
540
|
+
case "pip":
|
|
541
|
+
return `Python: pip (${py.dependencyFile}); ${describePython(py.python)}; installs with pip install -r requirements.txt`;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/** The selected ecosystems as plain lines, in JavaScript, Python, Go order. */
|
|
545
|
+
export function describeToolchainSet(toolchains) {
|
|
546
|
+
const lines = [];
|
|
547
|
+
if (toolchains.javascript !== null)
|
|
548
|
+
lines.push(describeJavaScriptToolchain(toolchains.javascript));
|
|
549
|
+
if (toolchains.python !== null)
|
|
550
|
+
lines.push(describePythonToolchain(toolchains.python));
|
|
551
|
+
if (toolchains.go !== null)
|
|
552
|
+
lines.push(`Go: ${toolchains.go.dependencyFile}; Go version from go.mod`);
|
|
553
|
+
return lines;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* The operator-facing summary of one inspection: every selected ecosystem, then
|
|
557
|
+
* the explicit limits. `none` is stated when nothing is provisioned, and an
|
|
558
|
+
* unreadable inspection is `unknown` rather than `none`.
|
|
559
|
+
*/
|
|
560
|
+
export function describeToolchainResolution(resolution) {
|
|
561
|
+
if (resolution.status === "unknown") {
|
|
562
|
+
return [
|
|
563
|
+
"Dependency setup: unknown. Bridge could not inspect " +
|
|
564
|
+
resolution.failures.map((f) => f.file).join(", ") +
|
|
565
|
+
", so it will not guess; fix the file or its permissions and re-run setup.",
|
|
566
|
+
];
|
|
567
|
+
}
|
|
568
|
+
const lines = describeToolchainSet(resolution.toolchains);
|
|
569
|
+
const { diagnostics } = resolution;
|
|
570
|
+
if (diagnostics.unsupportedPython) {
|
|
571
|
+
lines.push("Python: no automatic Python installation (no uv.lock, poetry.lock, or requirements.txt). " +
|
|
572
|
+
"Make the test command self-contained, or add a supported dependency file.");
|
|
573
|
+
}
|
|
574
|
+
if (diagnostics.rust) {
|
|
575
|
+
lines.push("Rust: relies on the toolchain the CI runner provides. If it is unsuitable, install what you need inside the test command.");
|
|
576
|
+
}
|
|
577
|
+
if (hasNoProvisionedToolchain(resolution.toolchains) && !diagnostics.unsupportedPython && !diagnostics.rust) {
|
|
578
|
+
lines.push("Dependency setup: none. Bridge provisions no dependencies for this repository, so the test command must be self-contained.");
|
|
579
|
+
}
|
|
580
|
+
return lines;
|
|
581
|
+
}
|