Repository navigation
Expand file tree
/
Copy pathfork-sync.ts
More file actions
1059 lines (985 loc) · 47 KB
/
Copy pathfork-sync.ts
File metadata and controls
1059 lines (985 loc) · 47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bun
/**
* fork-sync: hardened upstream tag-sync pipeline for the OpenFork branch-fork.
*
* Usage:
* bun run fork:sync preflight <tag> # fetch, refuse dirty tree, snapshot fork-only keys
* git merge <tag> # run by hand so the human sees the stop
* bun run fork:sync resolve # auto-resolve prune/lock/pkg/generated/fork-owned/meta
* # ... handle MANUAL items printed by resolve, re-run resolve until clean ...
* bun install # regenerate bun.lock from merged manifests
* git commit # union-listing message (see skill)
* bun run fork:sync verify --tag <tag>
*
* Why this exists: every tag merge resurrects pruned SaaS trees (~100
* conflict paths of noise), scatters package.json conflicts across 16+
* manifests, and silently drops fork-only keys (v1.18.29 lost the
* `@opencode-ai/core/memory` export because an ad-hoc union script only
* merged deps+scripts). This script makes the mechanical resolutions
* deterministic and turns the semantic checklist into failing checks.
*
* Rules source: keep-manifest.json (pruneFromMain) + FORK.md. If they
* disagree, believe the newer of the two and update the other.
*/
import { readdirSync, readFileSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { OPEN_CODE_HOSTED_COMPATIBILITY_FALLBACK } from "../packages/core/src/installation/upstream-compat"
type PkgJson = Record<string, any>
const DEP_SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"] as const
/** Scripts that only make sense with the pruned SaaS trees. Never resurrected. */
const DROP_SCRIPTS = new Set(["dev:console", "dev:stats", "dev:storybook", "sso"])
/** Script keys where the fork value wins on conflict. */
const OURS_WIN_SCRIPTS = new Set(["dev"])
/** Top-level package.json keys taken verbatim from upstream. */
const THEIRS_KEYS = new Set(["workspaces"])
/** Options for mergePackageJson. Pass workspace callbacks during a real
* resolve so `workspaces.packages` stays a curated, installable list
* instead of upstream globs that reference pruned trees (v1.18.29 broke
* `bun install` with `Workspace not found "packages/slack"`). */
export interface PkgMergeOptions {
workspaceExists?: (entry: string) => boolean
isDropWorkspace?: (entry: string) => boolean
}
/**
* Workspace package list policy: explicit entries only (bare `packages/*`
* globs re-include pruned trees), DROP entries removed, nonexistent
* entries removed, upstream additions kept when they exist on disk.
*/
export function mergeWorkspacePackages(
ours: unknown,
theirs: unknown,
opts: PkgMergeOptions = {},
): { packages: string[]; dropped: string[] } {
const list = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x) => typeof x === "string") : [])
const candidates = [...list(ours), ...list(theirs)]
const out: string[] = []
const dropped: string[] = []
for (const entry of candidates) {
if (out.includes(entry)) continue
if (entry.endsWith("/*")) {
dropped.push(entry)
continue
}
if (opts.isDropWorkspace?.(entry)) {
dropped.push(entry)
continue
}
if (opts.workspaceExists && !opts.workspaceExists(entry)) {
dropped.push(entry)
continue
}
out.push(entry)
}
return { packages: out.sort(), dropped }
}
const REPO_ROOT = join(import.meta.dir, "..")
// ---------------------------------------------------------------------------
// git helpers (argv-based: no shell, so `packages/console/.../[id]/...`
// paths never glob-expand the way they do under PowerShell)
// ---------------------------------------------------------------------------
function git(...args: string[]): { ok: boolean; out: string; errout: string } {
const out = Bun.spawnSync(["git", ...args], { stdout: "pipe", stderr: "pipe", cwd: REPO_ROOT })
return {
ok: out.exitCode === 0,
out: out.stdout.toString().trim(),
errout: out.stderr.toString().trim(),
}
}
function unmergedFiles(): string[] {
const r = git("diff", "--name-only", "--diff-filter=U")
if (!r.ok || !r.out) return []
return r.out.split("\n").map((s) => s.trim()).filter(Boolean)
}
function trackedFiles(...paths: string[]): string[] {
const r = git("ls-files", "--", ...paths)
if (!r.ok || !r.out) return []
return r.out.split("\n").map((s) => s.trim()).filter(Boolean)
}
function showFile(rev: string, path: string): string | undefined {
const r = git("show", `${rev}:${path}`)
return r.ok ? r.out : undefined
}
// ---------------------------------------------------------------------------
// keep-manifest
// ---------------------------------------------------------------------------
interface KeepManifest {
pruneFromMain: string[]
openCodeHostedCompatibility?: {
tag?: unknown
version?: unknown
}
}
export function validateOpenCodeHostedCompatibility(
value: KeepManifest["openCodeHostedCompatibility"],
verifyTag?: string,
): string | undefined {
if (!value || typeof value.tag !== "string" || typeof value.version !== "string") {
return "keep-manifest.json openCodeHostedCompatibility.tag/version missing"
}
if (!/^v\d+\.\d+\.\d+$/.test(value.tag)) {
return `invalid OpenCode hosted compatibility tag: ${JSON.stringify(value.tag)}`
}
const expectedVersion = value.tag.slice(1)
if (value.version !== expectedVersion) {
return `OpenCode hosted compatibility version ${JSON.stringify(value.version)} does not match tag ${value.tag}`
}
if (verifyTag && value.tag !== verifyTag) {
return `OpenCode hosted compatibility is ${value.tag}, but fork-sync verify targets ${verifyTag}`
}
}
function loadManifest(): KeepManifest {
const parsed = JSON.parse(readFileSync(join(REPO_ROOT, "keep-manifest.json"), "utf8")) as KeepManifest
if (!Array.isArray(parsed.pruneFromMain) || parsed.pruneFromMain.length === 0) {
throw new Error("keep-manifest.json pruneFromMain is empty or missing")
}
return parsed
}
function isDropPath(path: string, prune: string[]): boolean {
return prune.some((p) => path === p || path.startsWith(p + "/"))
}
// ---------------------------------------------------------------------------
// conflict classification (FORK.md § Conflict classes)
// ---------------------------------------------------------------------------
export type ConflictClass =
| "prune" // DROP tree re-added by upstream: always delete
| "lock" // bun.lock: take theirs, regenerate with bun install
| "pkg-union" // package.json: canonical union merger
| "generated" // SDK/client codegen: take theirs, regenerate
| "fork-ours" // fork-owned: keep ours, replay only clear bugfixes by hand
| "meta-ours" // FORK.md / AGENTS.md / workflows / updater / README: keep ours
| "union-manual" // registry / plugin / prompt unions: combine by hand
| "manual" // case-by-case or unknown: human decides, never guess
const GENERATED = [/^packages\/client\/src\/generated(-effect)?\//, /^packages\/sdk\/js\/src\/(v2\/)?gen\//]
const FORK_OWNED = [
/^packages\/app\/src\/components\/titlebar-/,
/^packages\/app\/src\/context\/tabs\.tsx$/,
/^packages\/app\/src\/components\/project-explorer/,
/^packages\/app\/src\/pages\/session\/v2\/project-explorer/,
/^packages\/app\/src\/pages\/session\/models-panel/,
/^packages\/app\/src\/components\/models\//,
/^packages\/app\/src\/context\/fork-usage\.tsx$/,
/^packages\/app\/src\/utils\/fork-client\.ts$/,
/^packages\/desktop\/src\/main\/browser\//,
/^packages\/app\/src\/pages\/session\/v2\/browser/,
/session-group/,
/^packages\/core\/src\/session\/(group-id|sql)\.ts$/,
/^packages\/opencode\/src\/session\/group\.ts$/,
/^packages\/opencode\/src\/quota\//,
/^packages\/opencode\/src\/fork\//,
/^packages\/opencode\/src\/tool\/(json|background|sqlite|git|typecheck|project|symbols|test|refactor|sympy|access|patch|archive|swarm|browser|reload|checkpoint|shell-safety)/,
/^packages\/core\/src\/search\//,
/^packages\/core\/src\/checkpoint\.ts$/,
/^packages\/opencode\/src\/session\/checkpoint\.ts$/,
/^packages\/opencode\/script\/install-jetbrains-acp\.ts$/,
/^packages\/core\/src\/special-agent-completion\.ts$/,
/^packages\/core\/src\/prompt-revisor(?:-prompt)?\.ts$/,
/^packages\/opencode\/src\/prompt-revisor\//,
/^packages\/opencode\/src\/special-agent\//,
/^packages\/core\/src\/session\/title\.ts$/,
/^packages\/opencode\/src\/session\/spad\//,
/^packages\/schema\/src\/goal(?:-id)?\.ts$/,
/^packages\/core\/src\/goal(?:\.ts|\/)/,
/^packages\/core\/test\/goal\//,
/^packages\/core\/src\/database\/migration\/.*goal/,
/^packages\/opencode\/src\/tool\/goal\.ts$/,
/^packages\/opencode\/src\/server\/routes\/instance\/httpapi\/(?:groups|handlers)\/goal\.ts$/,
/^packages\/app\/src\/components\/goal-composer-shelf/,
/^packages\/app\/src\/context\/goals\.ts$/,
]
const META = [/^FORK\.md$/, /\/AGENTS\.md$/, /^\.github\/workflows\//, /^README\.md$/, /^packages\/desktop\/src\/main\/updater\.ts$/]
const UNION_MANUAL = [
/^packages\/opencode\/src\/tool\/registry\.ts$/,
/^packages\/opencode\/src\/plugin\/index\.ts$/,
/^packages\/opencode\/src\/session\/prompt\.ts$/,
/^packages\/opencode\/src\/session\/message-v2\.ts$/,
/^packages\/opencode\/src\/provider\/provider\.ts$/,
/^packages\/opencode\/src\/server\/routes\/instance\/httpapi\/(api|server)\.ts$/,
/^packages\/opencode\/src\/agent\/agent\.ts$/,
/^packages\/opencode\/src\/tool\/shell\.ts$/,
/^packages\/core\/src\/config\.ts$/,
/^packages\/core\/src\/v1\/config\/(config|migrate)\.ts$/,
/^packages\/core\/src\/session\/runner\/llm\.ts$/,
/^packages\/core\/src\/location-services\.ts$/,
/^packages\/app\/src\/context\/settings\.tsx$/,
/^packages\/app\/src\/components\/settings-v2\/general\.tsx$/,
/^packages\/app\/src\/components\/prompt-input-v2\.tsx$/,
/^packages\/app\/src\/i18n\/en\.ts$/,
/^packages\/session-ui\/src\/v2\/components\/prompt-input\/index\.tsx$/,
]
export function classifyConflict(path: string, prune: string[]): ConflictClass {
if (isDropPath(path, prune)) return "prune"
if (path === "bun.lock") return "lock"
if (path === "package.json" || (path.endsWith("/package.json") && !path.includes("node_modules"))) return "pkg-union"
if (GENERATED.some((re) => re.test(path))) return "generated"
if (META.some((re) => re.test(path))) return "meta-ours"
if (FORK_OWNED.some((re) => re.test(path))) return "fork-ours"
if (UNION_MANUAL.some((re) => re.test(path))) return "union-manual"
return "manual"
}
// ---------------------------------------------------------------------------
// package.json canonical union (the v1.18.29 lesson: union EVERYTHING, and
// prove no fork-only key was lost — not just deps+scripts)
// ---------------------------------------------------------------------------
export interface PkgMergeReport {
file: string
versionTaken: string | undefined
forkOnlyKept: string[]
upstreamOnlyTaken: string[]
overlapUpstreamWins: string[]
overlapForkWins: string[]
}
function isPlainObject(v: unknown): v is Record<string, any> {
return typeof v === "object" && v !== null && !Array.isArray(v)
}
function unionArray(a: unknown, b: unknown): unknown[] {
const out: unknown[] = Array.isArray(a) ? [...a] : []
for (const item of Array.isArray(b) ? b : []) {
if (!out.some((x) => JSON.stringify(x) === JSON.stringify(item))) out.push(item)
}
return out
}
/**
* Merge policy:
* - version: upstream (theirs).
* - dep sections: union; upstream wins overlapping ranges.
* - scripts: union minus DROP_SCRIPTS; fork wins `dev` (+ OURS_WIN_SCRIPTS).
* - exports/imports: union; fork wins overlapping keys (fork keys are
* additive; an overlap with different values is reported for human review).
* - files/keywords arrays: union unique.
* - workspaces: upstream. Any other fork-only top-level key is preserved,
* never dropped (a dropped fork-only key is a failed sync, not a
* resolution).
*/
export function mergePackageJson(
file: string,
ours: PkgJson,
theirs: PkgJson,
opts: PkgMergeOptions = {},
): { merged: PkgJson; report: PkgMergeReport } {
const merged: PkgJson = JSON.parse(JSON.stringify(theirs))
const report: PkgMergeReport = {
file,
versionTaken: typeof theirs.version === "string" ? theirs.version : undefined,
forkOnlyKept: [],
upstreamOnlyTaken: [],
overlapUpstreamWins: [],
overlapForkWins: [],
}
const note = (list: string[], key: string) => {
if (!list.includes(key)) list.push(key)
}
for (const section of DEP_SECTIONS) {
const o = isPlainObject(ours[section]) ? ours[section] : {}
const t = isPlainObject(theirs[section]) ? theirs[section] : {}
const m = isPlainObject(merged[section]) ? { ...merged[section] } : {}
for (const [k, v] of Object.entries(o)) {
if (!(k in m)) {
m[k] = v
note(report.forkOnlyKept, `${section}.${k}`)
} else if (JSON.stringify(m[k]) !== JSON.stringify(v)) {
note(report.overlapUpstreamWins, `${section}.${k}`)
}
}
for (const k of Object.keys(t)) {
if (!(k in o)) note(report.upstreamOnlyTaken, `${section}.${k}`)
}
if (Object.keys(m).length > 0) merged[section] = m
else delete merged[section]
}
// scripts
{
const o = isPlainObject(ours.scripts) ? ours.scripts : {}
const t = isPlainObject(theirs.scripts) ? theirs.scripts : {}
const m: Record<string, any> = {}
for (const [k, v] of Object.entries(t)) {
if (DROP_SCRIPTS.has(k)) continue
m[k] = v
if (!(k in o)) note(report.upstreamOnlyTaken, `scripts.${k}`)
}
for (const [k, v] of Object.entries(o)) {
if (DROP_SCRIPTS.has(k)) continue
if (!(k in m)) {
m[k] = v
note(report.forkOnlyKept, `scripts.${k}`)
} else if (JSON.stringify(m[k]) !== JSON.stringify(v)) {
if (OURS_WIN_SCRIPTS.has(k)) {
m[k] = v
note(report.overlapForkWins, `scripts.${k}`)
} else {
note(report.overlapUpstreamWins, `scripts.${k}`)
}
}
}
merged.scripts = m
}
// exports / imports: union, fork wins overlaps (reported)
for (const section of ["exports", "imports"]) {
const o = isPlainObject(ours[section]) ? ours[section] : {}
const t = isPlainObject(theirs[section]) ? theirs[section] : {}
if (Object.keys(o).length === 0 && Object.keys(t).length === 0) continue
const m = { ...(isPlainObject(merged[section]) ? merged[section] : {}) }
for (const [k, v] of Object.entries(o)) {
if (!(k in m)) {
m[k] = v
note(report.forkOnlyKept, `${section}.${k}`)
} else if (JSON.stringify(m[k]) !== JSON.stringify(v)) {
m[k] = v
note(report.overlapForkWins, `${section}.${k}`)
}
}
for (const k of Object.keys(t)) {
if (!(k in o)) note(report.upstreamOnlyTaken, `${section}.${k}`)
}
merged[section] = m
}
// arrays: union unique
for (const section of ["files", "keywords"]) {
if (Array.isArray(ours[section]) || Array.isArray(theirs[section])) {
merged[section] = unionArray(theirs[section], ours[section])
}
}
// workspaces: curated explicit list (never upstream globs over DROP trees).
// Without fs callbacks there is nothing safe to compute, so keep upstream
// and let verify's `bun install` check catch it.
if (isPlainObject(ours.workspaces) || isPlainObject(theirs.workspaces)) {
const oPkgs = isPlainObject(ours.workspaces) ? ours.workspaces.packages : undefined
const tPkgs = isPlainObject(theirs.workspaces) ? theirs.workspaces.packages : undefined
if (opts.workspaceExists || opts.isDropWorkspace) {
const { packages, dropped } = mergeWorkspacePackages(oPkgs, tPkgs, opts)
merged.workspaces = { ...(isPlainObject(merged.workspaces) ? merged.workspaces : {}), packages }
for (const d of dropped) note(report.overlapUpstreamWins, `workspaces.packages!${d}`)
const oSet = new Set(Array.isArray(oPkgs) ? oPkgs : [])
for (const p of packages) if (!oSet.has(p)) note(report.upstreamOnlyTaken, `workspaces.packages.${p}`)
}
// workspaces.catalog: union pins, upstream wins overlaps (v1.18.29: identical, no loss)
const oCat = isPlainObject(ours.workspaces) && isPlainObject(ours.workspaces.catalog) ? ours.workspaces.catalog : {}
const tCat = isPlainObject(theirs.workspaces) && isPlainObject(theirs.workspaces.catalog) ? theirs.workspaces.catalog : {}
if (Object.keys(oCat).length > 0 || Object.keys(tCat).length > 0) {
const m = { ...tCat }
for (const [k, v] of Object.entries(oCat)) {
if (!(k in m)) {
m[k] = v
note(report.forkOnlyKept, `workspaces.catalog.${k}`)
} else if (JSON.stringify(m[k]) !== JSON.stringify(v)) {
note(report.overlapUpstreamWins, `workspaces.catalog.${k}`)
}
}
merged.workspaces = { ...(isPlainObject(merged.workspaces) ? merged.workspaces : {}), catalog: m }
}
}
// any other fork-only top-level key is preserved, never dropped
const handled = new Set([...DEP_SECTIONS, "scripts", "exports", "imports", "files", "keywords", "version"])
for (const [k, v] of Object.entries(ours)) {
if (handled.has(k) || THEIRS_KEYS.has(k)) continue
if (!(k in merged)) {
merged[k] = v
note(report.forkOnlyKept, k)
} else if (JSON.stringify(merged[k]) !== JSON.stringify(v)) {
note(report.overlapUpstreamWins, k)
}
}
return { merged, report }
}
// ---------------------------------------------------------------------------
// snapshot: fork-only package.json surface, taken at preflight, enforced
// by resolve + verify so a lost key fails loudly instead of at runtime
// ---------------------------------------------------------------------------
export interface PkgSnapshot {
file: string
forkOnlyTopKeys: string[]
forkOnlyExports: string[]
forkOnlyDeps: string[]
forkOnlyScripts: string[]
}
export function snapshotPackageJson(file: string, ours: PkgJson, theirs: PkgJson): PkgSnapshot {
const snap: PkgSnapshot = { file, forkOnlyTopKeys: [], forkOnlyExports: [], forkOnlyDeps: [], forkOnlyScripts: [] }
for (const k of Object.keys(ours)) {
if (!(k in theirs)) snap.forkOnlyTopKeys.push(k)
}
const oExp = isPlainObject(ours.exports) ? ours.exports : {}
const tExp = isPlainObject(theirs.exports) ? theirs.exports : {}
for (const k of Object.keys(oExp)) if (!(k in tExp)) snap.forkOnlyExports.push(k)
for (const section of DEP_SECTIONS) {
const o = isPlainObject(ours[section]) ? ours[section] : {}
const t = isPlainObject(theirs[section]) ? theirs[section] : {}
for (const k of Object.keys(o)) if (!(k in t)) snap.forkOnlyDeps.push(`${section}.${k}`)
}
const oS = isPlainObject(ours.scripts) ? ours.scripts : {}
const tS = isPlainObject(theirs.scripts) ? theirs.scripts : {}
for (const k of Object.keys(oS)) {
if (!(k in tS) && !DROP_SCRIPTS.has(k)) snap.forkOnlyScripts.push(k)
}
return snap
}
export function checkSnapshot(snap: PkgSnapshot, merged: PkgJson): string[] {
const missing: string[] = []
for (const k of snap.forkOnlyTopKeys) if (!(k in merged)) missing.push(k)
const exp = isPlainObject(merged.exports) ? merged.exports : {}
for (const k of snap.forkOnlyExports) if (!(k in exp)) missing.push(`exports.${k}`)
for (const dep of snap.forkOnlyDeps) {
const dot = dep.indexOf(".")
const section = dep.slice(0, dot)
const name = dep.slice(dot + 1)
const m = isPlainObject(merged[section]) ? merged[section] : {}
if (!(name in m)) missing.push(dep)
}
const scripts = isPlainObject(merged.scripts) ? merged.scripts : {}
for (const k of snap.forkOnlyScripts) if (!(k in scripts)) missing.push(`scripts.${k}`)
return missing
}
function snapshotPath(tag: string): string {
return join(REPO_ROOT, ".openfork", "cache", `fork-sync-${tag}.json`)
}
function snapshotDirectories(): string[] {
return [join(REPO_ROOT, ".openfork", "cache"), join(REPO_ROOT, ".opencode", "cache")]
}
function readJsonFile(path: string): any {
return JSON.parse(readFileSync(path, "utf8"))
}
// ---------------------------------------------------------------------------
// commands
// ---------------------------------------------------------------------------
function cmdPreflight(tag: string): number {
if (!/^v\d+\.\d+\.\d+$/.test(tag)) {
console.error(`preflight: expected a release tag like v1.18.29, got ${JSON.stringify(tag)}`)
return 1
}
const fetch = git("fetch", "upstream", "--tags", "--prune")
if (!fetch.ok) {
console.error(`preflight: git fetch upstream failed:\n${fetch.out}`)
return 1
}
if (!git("rev-parse", "--verify", tag).ok) {
console.error(`preflight: tag ${tag} not found after fetch`)
return 1
}
const dirty = git("status", "--porcelain")
if (dirty.ok && dirty.out) {
console.error("preflight: working tree is dirty — commit or stash first, then re-run. Refusing to start a sync on a dirty tree.")
return 1
}
// Snapshot fork-only package.json surface vs the tag, so resolve/verify
// can prove nothing fork-only was lost.
const manifests = trackedFiles("package.json", "packages/*/package.json").filter((f) => f.endsWith("package.json"))
const snaps: PkgSnapshot[] = []
for (const file of manifests) {
const oursRaw = showFile("HEAD", file)
const theirsRaw = showFile(tag, file)
if (!oursRaw || !theirsRaw) continue
try {
snaps.push(snapshotPackageJson(file, JSON.parse(oursRaw), JSON.parse(theirsRaw)))
} catch {
console.error(`preflight: could not parse ${file} on one side — will need manual review`)
}
}
writeFileSync(snapshotPath(tag), JSON.stringify({ tag, snaps }, null, 2))
console.log(`preflight: ${tag} verified, tree clean, snapshot of ${snaps.length} manifests -> .openfork/cache/fork-sync-${tag}.json`)
console.log(git("diff", "--stat", `main...${tag}`, "--", "packages/app", "packages/desktop", "packages/opencode", "packages/core",
"packages/schema", "packages/protocol", "packages/server", "packages/session-ui", "packages/ui").out || "(no KEEP-path changes)")
console.log(`next: git merge ${tag}`)
return 0
}
function loadSnapshots(): PkgSnapshot[] {
let best: PkgSnapshot[] = []
for (const dir of snapshotDirectories()) {
let cacheDir: string[] = []
try {
cacheDir = readdirSync(dir)
} catch {
continue
}
for (const entry of cacheDir) {
if (!entry.startsWith("fork-sync-") || !entry.endsWith(".json")) continue
try {
const data = readJsonFile(join(dir, entry))
if (Array.isArray(data.snaps) && data.snaps.length >= best.length) best = data.snaps
} catch {
/* ignore malformed snapshots */
}
}
}
return best
}
function cmdResolve(): number {
const manifest = loadManifest()
if (!git("rev-parse", "--verify", "MERGE_HEAD").ok) {
console.error("resolve: no merge in progress (MERGE_HEAD missing). Nothing to do.")
return 1
}
const files = unmergedFiles()
if (files.length === 0) {
console.log("resolve: no unmerged paths — nothing to do.")
return 0
}
let snapshots = loadSnapshots()
if (snapshots.length === 0) {
// No preflight snapshot: build ours-vs-theirs on the fly from the merge.
snapshots = []
for (const file of files.filter((f) => f.endsWith("package.json"))) {
const oursRaw = showFile("HEAD", file)
const theirsRaw = showFile("MERGE_HEAD", file)
if (oursRaw && theirsRaw) {
try {
snapshots.push(snapshotPackageJson(file, JSON.parse(oursRaw), JSON.parse(theirsRaw)))
} catch {
/* ignore */
}
}
}
}
const auto: string[] = []
const manual: { file: string; cls: ConflictClass }[] = []
const reports: PkgMergeReport[] = []
for (const file of files) {
const cls = classifyConflict(file, manifest.pruneFromMain)
switch (cls) {
case "prune": {
// Deleted-by-us or re-added under a DROP tree: always remove.
if (!git("rm", "--quiet", "-f", "--", file).ok) {
// Already absent from the worktree (index-only entry): unstage it.
git("rm", "--cached", "--quiet", "--", file)
}
auto.push(`prune ${file}`)
break
}
case "lock":
case "generated": {
git("checkout", "--theirs", "--", file)
git("add", "--", file)
auto.push(`${cls} ${file} (theirs${cls === "lock" ? "; run bun install after" : "; regenerate after"})`)
break
}
case "fork-ours":
case "meta-ours": {
git("checkout", "--ours", "--", file)
git("add", "--", file)
auto.push(`${cls} ${file} (ours)`)
break
}
case "pkg-union": {
const oursRaw = showFile("HEAD", file)
const theirsRaw = showFile("MERGE_HEAD", file)
if (!oursRaw || !theirsRaw) {
manual.push({ file, cls })
break
}
try {
const { merged, report } = mergePackageJson(file, JSON.parse(oursRaw), JSON.parse(theirsRaw), {
workspaceExists: (entry) => {
try {
return readdirSync(join(REPO_ROOT, entry), { withFileTypes: true }).some((e) => e.isDirectory() || e.isFile())
} catch {
return false
}
},
isDropWorkspace: (entry) => isDropPath(entry, manifest.pruneFromMain),
})
writeFileSync(join(REPO_ROOT, file), JSON.stringify(merged, null, 2) + "\n")
git("add", "--", file)
reports.push(report)
auto.push(`pkg-union ${file}`)
} catch (e) {
console.error(`resolve: ${file} failed to merge: ${e}`)
manual.push({ file, cls })
}
break
}
default:
manual.push({ file, cls })
}
}
// Loss detection: every snapshotted fork-only key must survive.
const losses: string[] = []
for (const s of snapshots) {
try {
const merged = readJsonFile(join(REPO_ROOT, s.file))
for (const m of checkSnapshot(s, merged)) losses.push(`${s.file}: ${m}`)
} catch {
/* file may be pruned; ignore */
}
}
console.log(`resolve: auto-resolved ${auto.length}/${files.length}`)
for (const line of auto) console.log(` auto ${line}`)
for (const r of reports) {
if (r.overlapForkWins.length > 0)
console.log(` note ${r.file} fork-wins (upstream changed the same key — review): ${r.overlapForkWins.join(", ")}`)
if (r.overlapUpstreamWins.length > 0) console.log(` note ${r.file} upstream-wins: ${r.overlapUpstreamWins.join(", ")}`)
}
if (losses.length > 0) {
console.error(`resolve: LOST fork-only keys (fix before committing):\n ${losses.join("\n ")}`)
}
if (manual.length > 0) {
console.log(`resolve: MANUAL (${manual.length}) — resolve by hand per FORK.md, then re-run resolve:`)
for (const m of manual) console.log(` manual [${m.cls}] ${m.file}`)
return 2
}
if (losses.length > 0) return 1
console.log("resolve: clean. Next: delete untracked DROP leftovers, bun install, commit with a union-listing message, then fork:sync verify.")
return 0
}
function fileContains(path: string, needle: string): boolean {
try {
return readFileSync(join(REPO_ROOT, path), "utf8").includes(needle)
} catch {
return false
}
}
function workspaceDirExists(entry: string): boolean {
try {
return readdirSync(join(REPO_ROOT, entry)).length >= 0
} catch {
return false
}
}
function cmdVerify(tag?: string): number {
const manifest = loadManifest()
const failures: string[] = []
const compatibilityFailure = validateOpenCodeHostedCompatibility(manifest.openCodeHostedCompatibility, tag)
if (compatibilityFailure) {
failures.push(compatibilityFailure)
} else {
const compat = manifest.openCodeHostedCompatibility!
const compatTag = compat.tag as string
const compatVersion = compat.version as string
if (compatVersion !== OPEN_CODE_HOSTED_COMPATIBILITY_FALLBACK) {
failures.push(
`OpenCode hosted compatibility fallback ${OPEN_CODE_HOSTED_COMPATIBILITY_FALLBACK} does not match manifest ${compatVersion}`,
)
}
if (!git("merge-base", "--is-ancestor", compatTag, "HEAD").ok) {
failures.push(`OpenCode hosted compatibility tag ${compatTag} is not merged into HEAD`)
}
}
const unmerged = unmergedFiles()
if (unmerged.length > 0) failures.push(`unmerged paths remain: ${unmerged.join(", ")}`)
const dropTracked = trackedFiles(...manifest.pruneFromMain)
if (dropTracked.length > 0)
failures.push(`DROP paths still tracked (${dropTracked.length}): ${dropTracked.slice(0, 8).join(", ")}${dropTracked.length > 8 ? " …" : ""}`)
// conflict markers anywhere outside DROP trees. The needle is built
// dynamically so this file does not itself contain the literal.
{
const needle = "<".repeat(7) + " HEAD"
const args = ["grep", "-l", needle, "--", ".", ...manifest.pruneFromMain.map((p) => `:(exclude)${p}`)]
const r = Bun.spawnSync(["git", ...args], { stdout: "pipe", stderr: "pipe", cwd: REPO_ROOT })
const hits = r.stdout.toString().trim()
if (hits) failures.push(`conflict markers remain in:\n${hits}`)
}
const checks: { name: string; run(): string | undefined }[] = [
{
name: "quota routes registered",
run: () =>
fileContains("packages/opencode/src/server/routes/instance/httpapi/api.ts", "QuotaApi")
? undefined
: "QuotaApi missing from httpapi/api.ts",
},
{
name: "fork tools present in registry",
run: () => {
const need = ["BackgroundTool", "SqliteTool", "SympyTool", "MemoryTool", "createToolAccessTool"]
const missing = need.filter((n) => !fileContains("packages/opencode/src/tool/registry.ts", n))
return missing.length > 0 ? `tool/registry.ts missing fork tools: ${missing.join(", ")}` : undefined
},
},
{
name: "pause/resume/regenerate-title handlers",
run: () =>
fileContains("packages/opencode/src/server/routes/instance/httpapi/groups/session.ts", "regenerate")
? undefined
: "regenerate-title handler missing from session group routes",
},
{
name: "session groups",
run: () => (trackedFiles("packages/schema/src/session-group*").length > 0 ? undefined : "packages/schema/src/session-group* missing"),
},
{
name: "goal mode native control plane",
run: () => {
const missing: string[] = []
if (!fileContains("packages/opencode/src/server/routes/instance/httpapi/api.ts", "GoalApi")) missing.push("GoalApi")
if (!fileContains("packages/opencode/src/tool/registry.ts", "GoalTool")) missing.push("V1 GoalTool")
if (!fileContains("packages/core/src/tool/builtins.ts", "GoalTool")) missing.push("V2 GoalTool")
if (!fileContains("packages/opencode/src/session/prompt.ts", "GoalAutomation")) missing.push("V1 automation seam")
if (!fileContains("packages/core/src/session/runner/llm.ts", "GoalAutomation")) missing.push("V2 automation seam")
if (!fileContains("packages/core/src/goal/automation.ts", "GoalAutomationTable")) missing.push("durable reservation service")
try {
const migrations = readdirSync(join(REPO_ROOT, "packages/core/src/database/migration"))
if (!migrations.some((name) => name.includes("goal") && name.endsWith(".ts"))) missing.push("Goal migrations")
} catch {
missing.push("Goal migrations")
}
return missing.length > 0 ? `Goal Mode missing: ${missing.join(", ")}` : undefined
},
},
{
name: "goal mode composer shelf",
run: () => {
const missing: string[] = []
if (!fileContains("packages/app/src/app.tsx", "GoalsProvider")) missing.push("GoalsProvider")
if (!fileContains("packages/app/src/components/prompt-input-v2.tsx", "GoalComposerShelf")) missing.push("GoalComposerShelf")
if (!fileContains("packages/session-ui/src/v2/components/prompt-input/index.tsx", "goalControl")) missing.push("goalControl slot")
return missing.length > 0 ? `Goal composer integration missing: ${missing.join(", ")}` : undefined
},
},
{
name: "goal auditor semantic gate",
run: () => {
const missing: string[] = []
if (!fileContains("packages/schema/src/goal.ts", "AuditorPolicy")) missing.push("per-Goal AuditorPolicy")
if (!fileContains("packages/core/src/config.ts", "auditor_prompt")) missing.push("global auditor_prompt")
if (!fileContains("packages/core/src/goal/auditor.ts", "audit_verdict")) missing.push("audit_verdict tool")
if (!fileContains("packages/core/src/goal/auditor-prompt.ts", "PROTOCOL_PROMPT")) missing.push("host-owned auditor protocol")
if (!fileContains("packages/schema/src/goal.ts", "continuationPrompt")) missing.push("auditor continuation artifact")
if (!fileContains("packages/core/src/goal/sql.ts", "continuation_prompt")) missing.push("durable continuation prompt")
if (!fileContains("packages/core/src/goal/automation.ts", "renderContinuationPrompt")) missing.push("auditor continuation wrapper")
for (const tool of ["read", "grep", "glob"]) {
if (!fileContains("packages/core/src/goal/auditor.ts", `${tool}: Tool.make`)) missing.push(`auditor ${tool} tool`)
}
if (!fileContains("packages/core/src/session/runner/llm.ts", "GoalAuditor")) missing.push("V2 auditor seam")
if (!fileContains("packages/opencode/src/session/prompt.ts", "GoalAuditor")) missing.push("V1 auditor seam")
if (!fileContains("packages/app/src/components/settings-v2/general.tsx", "AuditorPromptDialog")) missing.push("auditor prompt settings")
if (!fileContains("packages/app/src/components/goal-composer-shelf.tsx", "goal-auditor-model")) missing.push("per-Goal auditor model picker")
return missing.length > 0 ? `Goal auditor missing: ${missing.join(", ")}` : undefined
},
},
{
name: "goal agent creation provenance",
run: () => {
const missing: string[] = []
if (!fileContains("packages/core/src/goal/creation-policy.ts", "export function authorize")) missing.push("Core Goal creation authorization policy")
if (!fileContains("packages/core/src/goal/agent.ts", 'input.action === "create"')) missing.push("GoalAgent create action")
if (!fileContains("packages/core/src/goal/agent.ts", "sessions.get(sessionID)")) missing.push("Session-derived Goal ownership")
if (!fileContains("packages/core/src/goal/agent.ts", "GoalCreationPolicy.authorize")) missing.push("GoalAgent trusted authorization gate")
if (!fileContains("packages/core/src/tool/tool.ts", "userTurn")) missing.push("V2 trusted tool user-turn context")
if (!fileContains("packages/core/src/session/runner/llm.ts", "userTurn")) missing.push("V2 runner provenance seam")
if (!fileContains("packages/opencode/src/tool/goal.ts", "turnProvenance")) missing.push("V1 Goal provenance adapter")
if (!fileContains("packages/core/src/goal/index.ts", "sourceMessageID")) missing.push("Goal creation source-message audit attribution")
return missing.length > 0 ? `Goal agent creation provenance missing: ${missing.join(", ")}` : undefined
},
},
{
name: "shared special-agent completion protocol",
run: () => {
const missing: string[] = []
const shared = "packages/core/src/special-agent-completion.ts"
if (!fileContains(shared, "runAdaptiveToolChoice")) missing.push("shared tool-choice negotiation")
if (!fileContains(shared, "runTerminalCompletionWithTranscript")) missing.push("shared terminal protocol")
if (!fileContains(shared, "appendCompletionRepair")) missing.push("same-session repair transcript")
if (!fileContains("packages/core/src/prompt-revisor.ts", "runTerminalCompletion")) missing.push("Prompt Revisor shared completion seam")
if (!fileContains("packages/core/src/session/title.ts", "runTerminalCompletion")) missing.push("V2 title shared completion seam")
if (!fileContains("packages/core/src/goal/auditor.ts", "runTerminalCompletion")) missing.push("Goal Auditor shared completion seam")
if (!fileContains("packages/opencode/src/session/prompt.ts", "runTerminalCompletionWithTranscript")) missing.push("V1 title shared completion seam")
if (!fileContains("packages/opencode/src/prompt-revisor/runtime.ts", "generateAdaptive")) missing.push("Prompt Revisor host compatibility seam")
if (!fileContains("packages/opencode/src/special-agent/model-message-bridge.ts", "appendModelCompletionRepair")) missing.push("legacy transcript bridge")
return missing.length > 0 ? `Special-agent protocol missing: ${missing.join(", ")}` : undefined
},
},
{
name: "JetBrains ACP YOLO integration",
run: () => {
const missing: string[] = []
if (!fileContains("packages/opencode/src/agent/agent.ts", 'name: "yolo"')) missing.push("native yolo agent")
if (!fileContains("packages/opencode/src/tool/shell.ts", "catastrophicDeleteReason")) missing.push("catastrophic shell guard")
if (!fileContains("packages/opencode/script/install-jetbrains-acp.ts", 'AGENT_NAME = "OpenFork"')) missing.push("JetBrains installer")
if (!fileContains("packages/opencode/src/tool/registry.ts", "CheckpointTool")) missing.push("checkpoint tool")
return missing.length > 0 ? `JetBrains ACP integration missing: ${missing.join(", ")}` : undefined
},
},
{
name: "updater stays fork-pinned",
run: () => {
const missing: string[] = []
if (!fileContains("packages/desktop/src/main/constants.ts", "UPDATER_ENABLED = false")) missing.push("disabled gate")
if (!fileContains("packages/desktop/electron-builder.config.ts", 'owner: "thelabcorner"')) missing.push("OpenFork owner")
if (!fileContains("packages/desktop/electron-builder.config.ts", 'repo: "openfork"')) missing.push("OpenFork repo")
return missing.length > 0 ? `Desktop updater fork pin missing: ${missing.join(", ")}` : undefined
},
},
{
name: "OpenFork distribution boundary",
run: () => {
const failures: string[] = []
const read = (path: string) => {
try {
return readFileSync(join(REPO_ROOT, path), "utf8")
} catch {
failures.push(`unreadable ${path}`)
return ""
}
}
const installation = read("packages/opencode/src/installation/index.ts")
for (const forbidden of [
"https://opencode.ai/install",
"api.github.com/repos/anomalyco/opencode/releases",
"registry.npmjs.org/opencode-ai",
"anomalyco/tap/opencode",
"ScoopInstaller/Main/master/bucket/opencode.json",
"community.chocolatey.org/api/v2/Packages",
]) {
if (installation.includes(forbidden)) failures.push(`CLI updater contains upstream distribution marker: ${forbidden}`)
}
if (!installation.includes("PRODUCT_REPOSITORY_API_URL")) failures.push("CLI updater missing fork-owned release API")
if (!installation.includes('export type Method = "curl" | "unknown"'))
failures.push("CLI updater regained an unowned package-manager method")
const wsl = read("packages/desktop/src/main/wsl/runtime.ts")
if (!wsl.includes("github.com/thelabcorner/openfork/releases/download"))
failures.push("WSL installer is not pinned to OpenFork releases")
if (wsl.includes("opencode.ai/install")) failures.push("WSL installer regained upstream install script")
const releaseScript = read("script/release")
if (!releaseScript.includes("dev-pre-release.yml")) failures.push("release entry point missing OpenFork workflow")
if (releaseScript.includes("publish.yml")) failures.push("release entry point regained upstream publish workflow")
const versioning = read("packages/script/src/index.ts")
if (versioning.includes("registry.npmjs.org/opencode-ai/latest"))
failures.push("release versioning regained upstream npm source")
if (!versioning.includes('REPOSITORY = process.env.GH_REPO ?? "thelabcorner/openfork"'))
failures.push("release versioning missing OpenFork repository default")
const build = read("packages/opencode/script/build.ts")
if (!build.includes('PRODUCT_REPOSITORY } from "@opencode-ai/core/brand"'))
failures.push("CLI release upload missing canonical OpenFork repository owner")
if (build.includes("--repo ${process.env.GH_REPO}"))
failures.push("CLI release upload can resolve to an undefined repository")
const stablePublish = read("script/publish.ts")
if (!stablePublish.includes('OPENFORK_ENABLE_STABLE_PUBLISH !== "1"'))
failures.push("stable publish pipeline is not fail-closed")
if (stablePublish.includes("origin/dev")) failures.push("stable publish pipeline regained upstream dev-branch mutation")
for (const path of [
"packages/opencode/script/publish.ts",
"packages/plugin/script/publish.ts",
"packages/sdk/js/script/publish.ts",
"packages/ui/script/publish.ts",
]) {
const source = read(path)
if (source.includes("npm publish") && !source.includes("publishUpstreamNpmNamespace"))
failures.push(`${path} can publish an upstream npm namespace without an explicit fork gate`)
}
return failures.length > 0 ? `Distribution boundary broken: ${failures.join("; ")}` : undefined
},
},
{
name: "OpenFork product branding boundary",
run: () => {
const failures: string[] = []
const read = (path: string) => {
try {
return readFileSync(join(REPO_ROOT, path), "utf8")
} catch {
failures.push(`unreadable ${path}`)
return ""
}
}
const metainfo = read("packages/desktop/scripts/copy-metainfo.ts")
if (metainfo.includes("raw.githubusercontent.com/anomalyco/opencode"))
failures.push("Linux metainfo regained an upstream OpenCode promotional asset")
const appHelpers = read("packages/app/src/pages/layout/helpers.ts")
if (appHelpers.includes("https://opencode.ai/favicon.svg"))
failures.push("project avatars regained the upstream OpenCode product favicon")
const githubCommand = read("packages/opencode/src/cli/cmd/github.ts")
if (!githubCommand.includes("does not currently publish a first-party GitHub Action/GitHub App installer"))
failures.push("GitHub installer is no longer explicitly fail-closed")
const githubHandler = read("packages/opencode/src/cli/cmd/github.handler.ts")
if (githubHandler.includes("anomalyco/opencode/github@"))
failures.push("GitHub installer/runtime regained the upstream OpenCode Action")
if (githubHandler.includes("github.com/apps/opencode-agent"))
failures.push("GitHub installer regained the upstream OpenCode GitHub App")
for (const stale of ["[opencode session]", "Sending message to opencode", "opencode infrastructure"]) {
if (githubHandler.includes(stale)) failures.push(`GitHub runtime regained stale product copy: ${stale}`)
}
const v1Config = read("packages/core/src/v1/config/config.ts")
if (v1Config.includes("https://opencode.ai/docs/commands") || v1Config.includes("https://opencode.ai/docs/agents"))
failures.push("V1 config schema regained upstream OpenCode product documentation links")
const providerCli = read("packages/opencode/src/cli/cmd/providers.ts")
if (providerCli.includes("https://opencode.ai/docs/providers"))
failures.push("provider CLI regained upstream OpenCode product documentation links")
const protocolApi = read("packages/protocol/src/api.ts")
if (!protocolApi.includes('title: "OpenFork HttpApi"') || protocolApi.includes('title: "opencode HttpApi"'))
failures.push("local Protocol API metadata is not branded OpenFork")
const legacySdk = read("packages/sdk/js/src/gen/types.gen.ts")
if (legacySdk.includes("Automatically update to the latest version"))
failures.push("frozen V1 SDK regained stale upstream autoupdate documentation")
if (legacySdk.includes("https://opencode.ai/docs/commands") || legacySdk.includes("https://opencode.ai/docs/agent"))
failures.push("frozen V1 SDK regained upstream OpenCode product documentation links")
return failures.length > 0 ? `Branding boundary broken: ${failures.join("; ")}` : undefined
},
},
{
name: "core memory export resolvable",
run: () => {
try {
const pkg = readJsonFile(join(REPO_ROOT, "packages/core/package.json"))
return pkg.exports?.["./memory"] ? undefined : "packages/core/package.json exports./memory missing (v1.18.29 regression)"
} catch {
return "packages/core/package.json unreadable"
}
},
},
{
name: "workspaces installable (no globs, no DROP, all exist)",
run: () => {
try {
const pkg = readJsonFile(join(REPO_ROOT, "package.json"))
const entries = pkg.workspaces?.packages
if (!Array.isArray(entries)) return "root workspaces.packages is not a list"
const bad = entries.filter(
(e) =>
typeof e !== "string" ||
e.endsWith("/*") ||
isDropPath(e, manifest.pruneFromMain) ||
!workspaceDirExists(e),
)
return bad.length > 0
? `root workspaces.packages has uninstallable entries (v1.18.29 broke bun install this way): ${bad.join(", ")}`
: undefined