opencode-agent-orchestration-kit 1.0.27 → 1.0.28

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.
@@ -0,0 +1,623 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ import { compareStableVersions, parseStableVersion } from "./version.mjs";
8
+
9
+ const SCRIPT_PATH = fileURLToPath(import.meta.url);
10
+ const REPOSITORY_ROOT = path.dirname(path.dirname(SCRIPT_PATH));
11
+ const EXACT_KEYS = {
12
+ root: ["schema_version", "node", "opencode", "sdk"],
13
+ node: ["engines", "blocking_majors", "canary_major"],
14
+ opencode: ["supported_range", "minimum_tested", "stable_tested", "canary"],
15
+ sdk: ["opencode_plugin", "opentui_core", "opentui_solid"],
16
+ };
17
+ const STATUS_TERMS = new Set(["tested", "supported", "experimental", "unsupported"]);
18
+ const STATIC_MATRIX_STATUSES = [
19
+ ["Node.js 20 and EOL/odd lines", "unsupported"],
20
+ ["Ubuntu GitHub runner", "tested"],
21
+ ["macOS GitHub runner", "tested"],
22
+ ["Other mainstream Linux/macOS environments", "supported"],
23
+ ["WSL2", "experimental"],
24
+ ["Native Windows", "unsupported"],
25
+ ["Token usage plugin", "experimental"],
26
+ ["Open Design Docker adapter", "experimental"],
27
+ ["Superpowers", "experimental"],
28
+ ["Impeccable", "experimental"],
29
+ ];
30
+
31
+ function invalid(message) {
32
+ const error = new Error(message);
33
+ error.code = "INVALID_COMPATIBILITY";
34
+ return error;
35
+ }
36
+
37
+ function assertExactKeys(value, expected, label) {
38
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
39
+ throw invalid(`${label} must be an object`);
40
+ }
41
+ const actual = Object.keys(value).sort();
42
+ const wanted = [...expected].sort();
43
+ if (JSON.stringify(actual) !== JSON.stringify(wanted)) {
44
+ throw invalid(`${label} keys must be exactly: ${wanted.join(", ")}`);
45
+ }
46
+ }
47
+
48
+ function parseNodeEngineMajors(value) {
49
+ if (typeof value !== "string") {
50
+ throw invalid("node.engines must list caret stable versions separated by ||");
51
+ }
52
+ const ranges = value.split(" || ");
53
+ if (ranges.length === 0 || ranges.some((range) => !range.startsWith("^"))) {
54
+ throw invalid("node.engines must list caret stable versions separated by ||");
55
+ }
56
+ try {
57
+ return ranges.map((range) => parseStableVersion(range.slice(1)).major);
58
+ } catch {
59
+ throw invalid("node.engines must list caret MAJOR.MINOR.PATCH versions separated by ||");
60
+ }
61
+ }
62
+
63
+ function expectedMatrixStatuses(data) {
64
+ const openTuiSurface = data.sdk.opentui_core === data.sdk.opentui_solid
65
+ ? `OpenTUI core/solid ${data.sdk.opentui_core}`
66
+ : `OpenTUI core ${data.sdk.opentui_core} / solid ${data.sdk.opentui_solid}`;
67
+ return new Map([
68
+ ...data.node.blocking_majors.map((major) => [`Node.js ${major}`, "supported"]),
69
+ [`Node.js ${data.node.canary_major}`, "experimental"],
70
+ [`OpenCode ${data.opencode.minimum_tested}`, "tested"],
71
+ [`OpenCode ${data.opencode.stable_tested}`, "tested"],
72
+ [`OpenCode ${data.opencode.supported_range}`, "supported"],
73
+ [`OpenCode <${data.opencode.minimum_tested} or >=2.0.0`, "unsupported"],
74
+ [`@opencode-ai/plugin ${data.sdk.opencode_plugin}`, "tested"],
75
+ [openTuiSurface, "tested"],
76
+ ...STATIC_MATRIX_STATUSES,
77
+ ]);
78
+ }
79
+
80
+ function readRegularText(root, relative, fsOps = fs) {
81
+ const full = path.join(root, relative);
82
+ const realRoot = fsOps.realpathSync(root);
83
+ const realFull = fsOps.realpathSync(full);
84
+ const resolvedRelative = path.relative(realRoot, realFull);
85
+ if (
86
+ resolvedRelative === ".." ||
87
+ resolvedRelative.startsWith(`..${path.sep}`) ||
88
+ path.isAbsolute(resolvedRelative)
89
+ ) {
90
+ throw invalid(`${relative} must be a safe regular file`);
91
+ }
92
+ const stat = fsOps.lstatSync(full);
93
+ if (stat.isSymbolicLink() || !stat.isFile()) {
94
+ throw invalid(`${relative} must be a safe regular file`);
95
+ }
96
+ return fsOps.readFileSync(full, "utf8");
97
+ }
98
+
99
+ function readJson(root, relative, fsOps = fs) {
100
+ try {
101
+ return JSON.parse(readRegularText(root, relative, fsOps));
102
+ } catch (error) {
103
+ if (error.code === "INVALID_COMPATIBILITY") throw error;
104
+ throw invalid(`${relative} is invalid JSON: ${error.message}`);
105
+ }
106
+ }
107
+
108
+ function validateCanonicalData(data) {
109
+ assertExactKeys(data, EXACT_KEYS.root, "compatibility");
110
+ assertExactKeys(data.node, EXACT_KEYS.node, "node");
111
+ assertExactKeys(data.opencode, EXACT_KEYS.opencode, "opencode");
112
+ assertExactKeys(data.sdk, EXACT_KEYS.sdk, "sdk");
113
+ if (data.schema_version !== 1) throw invalid("schema_version must be 1");
114
+ const engineMajors = parseNodeEngineMajors(data.node.engines);
115
+ if (
116
+ !Array.isArray(data.node.blocking_majors)
117
+ || data.node.blocking_majors.length === 0
118
+ || data.node.blocking_majors.some((major) => !Number.isSafeInteger(major) || major < 1)
119
+ || new Set(data.node.blocking_majors).size !== data.node.blocking_majors.length
120
+ ) {
121
+ throw invalid("node.blocking_majors must contain unique positive integers");
122
+ }
123
+ if (JSON.stringify(engineMajors) !== JSON.stringify(data.node.blocking_majors)) {
124
+ throw invalid("node.blocking_majors must match node.engines majors in order");
125
+ }
126
+ if (
127
+ !Number.isSafeInteger(data.node.canary_major)
128
+ || data.node.canary_major <= Math.max(...data.node.blocking_majors)
129
+ ) {
130
+ throw invalid("node.canary_major must be an integer greater than every blocking major");
131
+ }
132
+ for (const field of ["minimum_tested", "stable_tested"]) {
133
+ try {
134
+ parseStableVersion(data.opencode[field]);
135
+ } catch {
136
+ throw invalid(`${field} must use MAJOR.MINOR.PATCH`);
137
+ }
138
+ }
139
+ if (compareStableVersions(data.opencode.minimum_tested, data.opencode.stable_tested) >= 0) {
140
+ throw invalid("minimum_tested must be older than stable_tested");
141
+ }
142
+ if (data.opencode.supported_range !== `>=${data.opencode.minimum_tested} <2.0.0`) {
143
+ throw invalid("supported_range must begin at minimum_tested and end before 2.0.0");
144
+ }
145
+ if (data.opencode.canary !== "latest") throw invalid("opencode.canary must be latest");
146
+ for (const [field, value] of Object.entries(data.sdk)) {
147
+ try {
148
+ parseStableVersion(value);
149
+ } catch {
150
+ throw invalid(`sdk.${field} must use MAJOR.MINOR.PATCH`);
151
+ }
152
+ }
153
+ return data;
154
+ }
155
+
156
+ export function checkCompatibility(
157
+ repositoryRoot = REPOSITORY_ROOT,
158
+ { fsOps = fs, surfaces = true } = {},
159
+ ) {
160
+ const data = validateCanonicalData(readJson(repositoryRoot, "compatibility.json", fsOps));
161
+ if (surfaces) validateSurfaces(repositoryRoot, data, fsOps);
162
+ return data;
163
+ }
164
+
165
+ function validatePackages(root, data, fsOps) {
166
+ const rootPackage = readJson(root, "package.json", fsOps);
167
+ if (rootPackage.engines?.node !== data.node.engines) {
168
+ throw invalid("package.json engines.node must match compatibility.json node.engines");
169
+ }
170
+
171
+ const packagedPackage = readJson(root, "opencode/package.json", fsOps);
172
+ if (packagedPackage.engines?.node !== data.node.engines) {
173
+ throw invalid("opencode/package.json engines.node must match compatibility.json node.engines");
174
+ }
175
+
176
+ for (const [dependency, sdkField] of [
177
+ ["@opencode-ai/plugin", "opencode_plugin"],
178
+ ["@opentui/core", "opentui_core"],
179
+ ["@opentui/solid", "opentui_solid"],
180
+ ]) {
181
+ if (packagedPackage.dependencies?.[dependency] !== data.sdk[sdkField]) {
182
+ throw invalid(
183
+ `opencode/package.json dependency ${dependency} must match compatibility.json sdk.${sdkField}`,
184
+ );
185
+ }
186
+ }
187
+
188
+ const packagedLock = readJson(root, "opencode/package-lock.json", fsOps);
189
+ const lockRoot = packagedLock.packages?.[""];
190
+ if (!lockRoot || typeof lockRoot !== "object" || Array.isArray(lockRoot)) {
191
+ throw invalid("opencode/package-lock.json packages[''] must be an object");
192
+ }
193
+ if (lockRoot.engines?.node !== data.node.engines) {
194
+ throw invalid("opencode/package-lock.json engines.node must match compatibility.json node.engines");
195
+ }
196
+ for (const [dependency, sdkField] of [
197
+ ["@opencode-ai/plugin", "opencode_plugin"],
198
+ ["@opentui/core", "opentui_core"],
199
+ ["@opentui/solid", "opentui_solid"],
200
+ ]) {
201
+ if (lockRoot.dependencies?.[dependency] !== data.sdk[sdkField]) {
202
+ throw invalid(
203
+ `opencode/package-lock.json dependency ${dependency} must match compatibility.json sdk.${sdkField}`,
204
+ );
205
+ }
206
+ }
207
+ }
208
+
209
+ export function extractMarkedSection(text, start, end) {
210
+ const startCount = text.split(start).length - 1;
211
+ const endCount = text.split(end).length - 1;
212
+ const first = text.indexOf(start);
213
+ const last = text.indexOf(end);
214
+ if (startCount !== 1 || endCount !== 1) {
215
+ if (start.includes("compatibility-matrix")) {
216
+ throw invalid("docs/compatibility.md must contain exactly one start and one end marker");
217
+ }
218
+ if (start.includes("opencode-boundaries")) {
219
+ throw invalid("workflow must contain exactly one OpenCode boundary job marker pair");
220
+ }
221
+ if (start.includes("compatibility-canary")) {
222
+ throw invalid("compatibility canary must contain exactly one marker pair");
223
+ }
224
+ throw invalid("workflow must contain exactly one compatibility blocking marker pair");
225
+ }
226
+ if (last <= first) {
227
+ if (start.includes("compatibility-matrix")) {
228
+ throw invalid("docs/compatibility.md matrix markers must be in order");
229
+ }
230
+ if (start.includes("opencode-boundaries")) {
231
+ throw invalid("workflow OpenCode boundary job markers must be in order");
232
+ }
233
+ if (start.includes("compatibility-canary")) {
234
+ throw invalid("compatibility canary markers must be in order");
235
+ }
236
+ throw invalid("workflow compatibility blocking markers must be in order");
237
+ }
238
+ return text.slice(first + start.length, last);
239
+ }
240
+
241
+ function validateDocumentation(root, data, fsOps) {
242
+ const docs = readRegularText(root, "docs/compatibility.md", fsOps);
243
+ const readme = readRegularText(root, "README.md", fsOps);
244
+ const installation = readRegularText(root, "docs/installation.md", fsOps);
245
+ const matrix = extractMarkedSection(
246
+ docs,
247
+ "<!-- compatibility-matrix:start -->",
248
+ "<!-- compatibility-matrix:end -->",
249
+ );
250
+ const rows = new Map();
251
+
252
+ for (const line of matrix.split("\n")) {
253
+ if (!line.startsWith("|") || line.includes("---") || line.includes("Status")) continue;
254
+ const cells = line.split("|").map((cell) => cell.trim()).filter(Boolean);
255
+ if (cells.length >= 2 && !STATUS_TERMS.has(cells[1])) {
256
+ throw invalid(`unknown compatibility status: ${cells[1]}`);
257
+ }
258
+ if (cells.length >= 3) {
259
+ const surface = cells[0].replaceAll("`", "");
260
+ if (rows.has(surface)) {
261
+ throw invalid(`docs/compatibility.md must not duplicate surface ${surface}`);
262
+ }
263
+ rows.set(surface, cells[1]);
264
+ }
265
+ }
266
+
267
+ for (const [surface, expectedStatus] of expectedMatrixStatuses(data)) {
268
+ if (rows.get(surface) !== expectedStatus) {
269
+ throw invalid(`docs/compatibility.md must classify ${surface} as ${expectedStatus}`);
270
+ }
271
+ }
272
+
273
+ for (const token of [
274
+ data.node.engines,
275
+ data.opencode.supported_range,
276
+ data.opencode.minimum_tested,
277
+ data.opencode.stable_tested,
278
+ ...data.node.blocking_majors.map((major) => `Node.js ${major}`),
279
+ `Node.js ${data.node.canary_major}`,
280
+ "WSL2",
281
+ "Native Windows",
282
+ "Token usage plugin",
283
+ "Open Design Docker adapter",
284
+ "Superpowers",
285
+ "Impeccable",
286
+ ]) {
287
+ if (!matrix.includes(token) && !docs.includes(token)) {
288
+ throw invalid(`docs/compatibility.md must declare ${token}`);
289
+ }
290
+ }
291
+
292
+ if (!readme.includes("docs/compatibility.md")) {
293
+ throw invalid("README.md must link docs/compatibility.md");
294
+ }
295
+ if (!installation.includes(data.node.engines)) {
296
+ throw invalid("docs/installation.md must declare the canonical Node engine");
297
+ }
298
+ }
299
+
300
+ function extractWorkflowStep(workflow, name) {
301
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
302
+ const match = workflow.match(
303
+ new RegExp(`^ - name: ${escaped}\\n([\\s\\S]*?)(?=^ - name: |(?![\\s\\S]))`, "m"),
304
+ );
305
+ return match?.[0] ?? "";
306
+ }
307
+
308
+ function extractJobsBody(
309
+ workflow,
310
+ message = "workflow must contain exactly one unambiguous jobs.check body",
311
+ ) {
312
+ const jobsHeaders = [...workflow.matchAll(/^jobs:\s*$/gm)];
313
+ if (jobsHeaders.length !== 1) {
314
+ throw invalid(message);
315
+ }
316
+ const jobsStart = jobsHeaders[0].index + jobsHeaders[0][0].length;
317
+ const afterJobs = workflow.slice(jobsStart);
318
+ const nextTopLevel = afterJobs.match(/^\S[^\n]*:\s*$/m);
319
+ return afterJobs.slice(0, nextTopLevel?.index ?? afterJobs.length);
320
+ }
321
+
322
+ function extractUniqueJob(jobsBody, name, message) {
323
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
324
+ const headers = [...jobsBody.matchAll(new RegExp(`^ ${escaped}:\\s*$`, "gm"))];
325
+ if (headers.length !== 1) throw invalid(message);
326
+ const jobStart = headers[0].index;
327
+ const afterHeader = jobsBody.slice(jobStart + headers[0][0].length);
328
+ const nextJob = afterHeader.match(/^ [A-Za-z0-9_-]+:\s*$/m);
329
+ const jobEnd = jobStart + headers[0][0].length
330
+ + (nextJob?.index ?? afterHeader.length);
331
+ return { body: jobsBody.slice(jobStart, jobEnd), start: jobStart };
332
+ }
333
+
334
+ function extractBlockingJob(workflow) {
335
+ return extractUniqueJob(
336
+ extractJobsBody(workflow),
337
+ "check",
338
+ "workflow must contain exactly one unambiguous jobs.check body",
339
+ ).body;
340
+ }
341
+
342
+ function rejectJobLevelPermissions(job) {
343
+ if (/^ permissions\s*:/m.test(job)) {
344
+ throw invalid("workflow job-level permissions are forbidden; jobs must inherit top-level permissions");
345
+ }
346
+ }
347
+
348
+ function rejectOpenCodeBoundaryHazards(job) {
349
+ rejectJobLevelPermissions(job);
350
+ if (/^ continue-on-error\s*:/m.test(job)) {
351
+ throw invalid("OpenCode boundary job must remain blocking");
352
+ }
353
+ if (/\$\{\{\s*secrets\./.test(job)) {
354
+ throw invalid("OpenCode boundary job must not use secrets");
355
+ }
356
+ if (
357
+ /^\s*(?:run:\s*)?.*\b(?:npm|pnpm|yarn)\s+publish\b/m.test(job)
358
+ || /\bgh\s+release\s+create\b/.test(job)
359
+ ) {
360
+ throw invalid("OpenCode boundary job must not publish");
361
+ }
362
+ }
363
+
364
+ function validateOpenCodeBoundaryJob(workflow, data) {
365
+ const marked = extractMarkedSection(
366
+ workflow,
367
+ "# opencode-boundaries:start",
368
+ "# opencode-boundaries:end",
369
+ );
370
+ const versions = [data.opencode.minimum_tested, data.opencode.stable_tested]
371
+ .sort(compareStableVersions);
372
+ const expectedJob = [
373
+ " opencode-compatibility:",
374
+ " runs-on: ubuntu-latest",
375
+ " strategy:",
376
+ " fail-fast: false",
377
+ " matrix:",
378
+ " opencode:",
379
+ ...versions.map((version) => ` - "${version}"`),
380
+ " steps:",
381
+ " - name: Checkout",
382
+ " uses: actions/checkout@v4",
383
+ "",
384
+ " - name: Setup Node",
385
+ " uses: actions/setup-node@v4",
386
+ " with:",
387
+ " node-version: 24",
388
+ "",
389
+ " - name: Smoke OpenCode boundary",
390
+ ' run: bash scripts/opencode-compat-smoke.sh "${{ matrix.opencode }}"',
391
+ ].join("\n");
392
+ const actualJob = marked.replace(/^\n/, "").replace(/\n $/, "");
393
+ const jobsBody = extractJobsBody(workflow);
394
+ const completeJob = extractUniqueJob(
395
+ jobsBody,
396
+ "opencode-compatibility",
397
+ "OpenCode boundary job must be one separate exact job under jobs",
398
+ );
399
+ const expectedCompleteJob = `${expectedJob}\n # opencode-boundaries:end`;
400
+ const markerPrefix = " # opencode-boundaries:start\n";
401
+ rejectOpenCodeBoundaryHazards(completeJob.body);
402
+
403
+ if (
404
+ actualJob !== expectedJob
405
+ || !jobsBody.slice(0, completeJob.start).endsWith(markerPrefix)
406
+ || completeJob.body.trimEnd() !== expectedCompleteJob
407
+ ) {
408
+ throw invalid(
409
+ `OpenCode boundary job must exactly test ${versions.join(", ")} on Node 24 through the isolated matrix wrapper`,
410
+ );
411
+ }
412
+ }
413
+
414
+ function validateWorkflow(root, data, fsOps) {
415
+ const workflow = readRegularText(root, ".github/workflows/check.yml", fsOps);
416
+ const blockingJob = extractBlockingJob(workflow);
417
+ rejectJobLevelPermissions(blockingJob);
418
+ const marked = extractMarkedSection(
419
+ blockingJob,
420
+ "# compatibility-blocking:start",
421
+ "# compatibility-blocking:end",
422
+ );
423
+ const section = marked
424
+ .replace(/^\n/, "")
425
+ .replace(/\n $/, "")
426
+ .split("\n")
427
+ .map((line) => line.replace(/^ /, ""))
428
+ .join("\n");
429
+ const canonicalMajor = Math.max(...data.node.blocking_majors);
430
+ const expectedEntries = [
431
+ ...data.node.blocking_majors.map((node) => ({
432
+ os: "ubuntu-latest",
433
+ node,
434
+ canonical: node === canonicalMajor,
435
+ })),
436
+ { os: "macos-latest", node: canonicalMajor, canonical: false },
437
+ ];
438
+ const expectedSection = [
439
+ "strategy:",
440
+ " fail-fast: false",
441
+ " matrix:",
442
+ " include:",
443
+ ...expectedEntries.flatMap(({ os, node, canonical }) => [
444
+ ` - os: ${os}`,
445
+ ` node: ${node}`,
446
+ ` canonical: ${canonical}`,
447
+ ]),
448
+ ].join("\n");
449
+ const entries = [...section.matchAll(
450
+ /^ - os: (ubuntu-latest|macos-latest)\n node: (\d+)\n canonical: (true|false)$/gm,
451
+ )].map((match) => ({
452
+ os: match[1],
453
+ node: Number(match[2]),
454
+ canonical: match[3] === "true",
455
+ }));
456
+
457
+ if (!section.includes(" fail-fast: false")) {
458
+ throw invalid("workflow strategy must set fail-fast to false");
459
+ }
460
+ if (section !== expectedSection || JSON.stringify(entries) !== JSON.stringify(expectedEntries)) {
461
+ throw invalid(
462
+ `workflow blocking matrix must be exactly ${expectedEntries.map(({ os, node, canonical }) => `${os}/${node}/canonical=${canonical}`).join(", ")}`,
463
+ );
464
+ }
465
+ if (!/^ runs-on: \$\{\{ matrix\.os \}\}$/m.test(blockingJob)) {
466
+ throw invalid("workflow blocking job must run on matrix.os");
467
+ }
468
+ if (!/^ node-version: \$\{\{ matrix\.node \}\}$/m.test(blockingJob)) {
469
+ throw invalid("workflow setup-node must use matrix.node");
470
+ }
471
+
472
+ const tagStep = extractWorkflowStep(blockingJob, "Validate release tag");
473
+ if (JSON.stringify(tagStep.match(/^ if:.*$/gm)) !== JSON.stringify([
474
+ " if: matrix.canonical && startsWith(github.ref, 'refs/tags/')",
475
+ ])) {
476
+ throw invalid("workflow tag validation guard must be exact");
477
+ }
478
+ const auditStep = extractWorkflowStep(blockingJob, "Audit OpenCode tool dependencies");
479
+ if (JSON.stringify(auditStep.match(/^ if:.*$/gm)) !== JSON.stringify([
480
+ " if: matrix.canonical",
481
+ ])) {
482
+ throw invalid("workflow dependency audit guard must be exact");
483
+ }
484
+
485
+ for (const [snippet, label] of [
486
+ ["working-directory: opencode\n run: npm ci", "install OpenCode tool dependencies"],
487
+ ["run: npm run contract-check", "contract check"],
488
+ ["run: npm run unit-and-script-tests", "unit and script tests"],
489
+ ["run: npm run typecheck", "token plugin typecheck"],
490
+ ["run: npm run installation-smoke", "installation smoke"],
491
+ ]) {
492
+ if (!blockingJob.includes(snippet)) {
493
+ throw invalid(`workflow blocking job must retain ${label}`);
494
+ }
495
+ }
496
+
497
+ const evidenceStep = extractWorkflowStep(blockingJob, "Record runner evidence");
498
+ for (const token of [
499
+ "uname -a || true",
500
+ "node --version",
501
+ "npm --version",
502
+ "arch:process.arch",
503
+ "platform:process.platform",
504
+ 'p.dependencies["@opencode-ai/plugin"]',
505
+ 'p.dependencies["@opentui/core"]',
506
+ 'p.dependencies["@opentui/solid"]',
507
+ ]) {
508
+ if (!evidenceStep.includes(token)) {
509
+ throw invalid(`workflow runner evidence must include ${token}`);
510
+ }
511
+ }
512
+
513
+ validateOpenCodeBoundaryJob(workflow, data);
514
+
515
+ if (!/^permissions:\n contents: read$/m.test(workflow) || /^\s*[^#\n]+:\s*(?:write|write-all)\s*$/m.test(workflow)) {
516
+ throw invalid("workflow must use read-only permissions");
517
+ }
518
+ if (/^\s*(?:run:\s*)?.*\b(?:npm|pnpm|yarn)\s+publish\b/m.test(workflow) || /\bgh\s+release\s+create\b/.test(workflow)) {
519
+ throw invalid("workflow must not publish");
520
+ }
521
+ }
522
+
523
+ function validateCompatibilityCanary(root, data, fsOps) {
524
+ const workflow = readRegularText(
525
+ root,
526
+ ".github/workflows/compatibility-canary.yml",
527
+ fsOps,
528
+ );
529
+ const jobMessage = "compatibility canary must contain exactly one unambiguous jobs.latest body";
530
+ const marked = extractMarkedSection(
531
+ workflow,
532
+ "# compatibility-canary:start",
533
+ "# compatibility-canary:end",
534
+ );
535
+ const jobsBody = extractJobsBody(workflow, jobMessage);
536
+ const completeJob = extractUniqueJob(jobsBody, "latest", jobMessage);
537
+ const expectedJob = [
538
+ " latest:",
539
+ " runs-on: ubuntu-latest",
540
+ " steps:",
541
+ " - name: Checkout",
542
+ " uses: actions/checkout@v4",
543
+ " with:",
544
+ " persist-credentials: false",
545
+ "",
546
+ " - name: Setup Node",
547
+ " uses: actions/setup-node@v4",
548
+ " with:",
549
+ ` node-version: ${data.node.canary_major}`,
550
+ "",
551
+ " - name: Smoke latest OpenCode",
552
+ ` run: bash scripts/opencode-compat-smoke.sh ${data.opencode.canary}`,
553
+ ].join("\n");
554
+ const expectedWorkflow = [
555
+ "name: Compatibility Canary",
556
+ "",
557
+ "on:",
558
+ " workflow_dispatch:",
559
+ " schedule:",
560
+ ' - cron: "17 6 * * 1"',
561
+ "",
562
+ "permissions:",
563
+ " contents: read",
564
+ "",
565
+ "jobs:",
566
+ " # compatibility-canary:start",
567
+ expectedJob,
568
+ " # compatibility-canary:end",
569
+ "",
570
+ ].join("\n");
571
+ const actualJob = marked.replace(/^\n/, "").replace(/\n $/, "");
572
+ const markerPrefix = " # compatibility-canary:start\n";
573
+ const expectedCompleteJob = `${expectedJob}\n # compatibility-canary:end`;
574
+
575
+ if (/^ permissions\s*:/m.test(completeJob.body)) {
576
+ throw invalid("compatibility canary job-level permissions are forbidden");
577
+ }
578
+ if (/\bcontinue-on-error\s*:/.test(workflow)) {
579
+ throw invalid("compatibility canary failures must remain red");
580
+ }
581
+ if (/\$\{\{\s*secrets\./.test(workflow) || /\b(?:token|password|credential|api[_-]?key)\b/i.test(workflow)) {
582
+ throw invalid("compatibility canary must not use secrets or credentials");
583
+ }
584
+ if (
585
+ /\b(?:npm|pnpm|yarn)\s+publish\b/.test(workflow)
586
+ || /\bgh\s+(?:release|issue)\s+create\b/.test(workflow)
587
+ || /\bgit\s+(?:tag|push|commit)\b/.test(workflow)
588
+ || /\b(?:npm|pnpm)\s+(?:ci|install|update)\b/.test(workflow)
589
+ || /\byarn\s+(?:install|upgrade)\b/.test(workflow)
590
+ || /actions\/(?:cache|upload-artifact|download-artifact)@/.test(workflow)
591
+ ) {
592
+ throw invalid("compatibility canary must not publish, mutate, cache, or use artifacts");
593
+ }
594
+ if (
595
+ actualJob !== expectedJob
596
+ || !jobsBody.slice(0, completeJob.start).endsWith(markerPrefix)
597
+ || completeJob.body.trimEnd() !== expectedCompleteJob
598
+ || workflow !== expectedWorkflow
599
+ ) {
600
+ throw invalid(
601
+ `compatibility canary must exactly smoke ${data.opencode.canary} on Ubuntu Node ${data.node.canary_major} from schedule and workflow_dispatch only`,
602
+ );
603
+ }
604
+ }
605
+
606
+ function validateSurfaces(root, data, fsOps) {
607
+ validatePackages(root, data, fsOps);
608
+ validateDocumentation(root, data, fsOps);
609
+ validateWorkflow(root, data, fsOps);
610
+ validateCompatibilityCanary(root, data, fsOps);
611
+ }
612
+
613
+ if (path.resolve(process.argv[1] ?? "") === SCRIPT_PATH) {
614
+ try {
615
+ const data = checkCompatibility();
616
+ console.log(
617
+ `compatibility contract ok: Node ${data.node.blocking_majors.join("/")} OpenCode ${data.opencode.supported_range}`,
618
+ );
619
+ } catch (error) {
620
+ console.error(`compatibility contract invalid: ${error.message}`);
621
+ process.exitCode = 1;
622
+ }
623
+ }