oc-harness-setup 0.6.0 → 1.0.1

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/bin/cli.js CHANGED
@@ -49,7 +49,11 @@ const FILE_ALIASES = { 'gitignore.template': '.gitignore' };
49
49
  const DIR_ALIASES = { 'state-seed': 'state' };
50
50
  // Ownership table for the opencode.jsonc merge. Every top-level key falls into
51
51
  // exactly one bucket; there is no "known merge key" list to drift out of date.
52
- // INSTALL_OWNED — the distro's value wins outright (runtime policy).
52
+ // INSTALL_OWNED — the distro supplies a default; on a collision the adopter's
53
+ // value wins and the collided key is reported by name.
54
+ // DENY_OWNED — the hard tool.use deny block. Unioned with the adopter's
55
+ // entries, distro denies last, so a user rule can be added but
56
+ // can never shadow a shipped deny.
53
57
  // UNION_KEYS — arrays unioned + deduped (distro entries first).
54
58
  // 'references' — object union: distro keys + user-only keys.
55
59
  // 'permissions' — ordered union: harness allow/ask rules first, then the
@@ -60,7 +64,8 @@ const DIR_ALIASES = { 'state-seed': 'state' };
60
64
  // allowlist is deny-then-allows; see mergeJsonc).
61
65
  // everything else (known or unknown) — the adopter's value wins; the distro
62
66
  // value stays when the adopter does not define the key.
63
- const INSTALL_OWNED = ['$schema', 'default_agent', 'formatter', 'compaction', 'tool_output', 'media', 'watcher', 'policies'];
67
+ const INSTALL_OWNED = ['$schema', 'default_agent', 'formatter', 'compaction', 'tool_output', 'media', 'watcher'];
68
+ const DENY_OWNED = ['policies'];
64
69
  const UNION_KEYS = ['plugins'];
65
70
  const DISTRO_PLUGIN_IDS = ['oc-flight-deck'];
66
71
 
@@ -111,16 +116,11 @@ function normalizePluginEntries(entries) {
111
116
  return out;
112
117
  }
113
118
 
114
- // Adopter-owned files: a shipped skeleton that the adopter genuinely edited
115
- // MUST survive an upgrade — overwriting it destroys their data. Genuineness
116
- // is proven against the prior manifest (see stageFiles): a destination that
117
- // still matches the prior installed hash is unmodified pack content and IS
118
- // updated, so a stock 0.3.3 AGENTS.md is replaced by the V9 contract while a
119
- // genuinely adopter-edited one is kept. The template is a controlled copy
120
- // graded by the doctor, so adopter edits are archived then overwritten.
121
- const PRESERVE_IF_EXISTS = new Set(['reference/models.md', 'AGENTS.md', '.gitignore', 'state/lessons.md']);
122
- // Keyed on forward slashes; matched through norm() because rel is platform-native
123
- // (path.join yields backslashes on Windows).
119
+ // Every shipped file follows one decision table (classifyDest): new bytes land
120
+ // in place only where the destination still matches what we installed. A
121
+ // destination that cannot be proven package-owned is the adopter's file, so it
122
+ // is never overwritten — the new version lands beside it as `<name>.new`.
123
+ //
124
124
  // Leak markers — generic shapes, never a concrete machine. They catch the
125
125
  // maintainer's workstation leaking into the shipped tree (an absolute
126
126
  // user-profile path, a session id). They are linted against the package
@@ -179,6 +179,15 @@ function atomicInstall(tmp, dest) {
179
179
  rmSync(aside, { force: true });
180
180
  }
181
181
 
182
+ // Write bytes through the atomic replace, so a crash never leaves the
183
+ // destination deleted with the new copy orphaned as tmp.
184
+ function installBytes(dest, buf) {
185
+ mkdirSync(path.dirname(dest), { recursive: true });
186
+ const tmp = `${dest}.oc-harness-setup-tmp-${process.pid}`;
187
+ writeFileSync(tmp, buf);
188
+ atomicInstall(tmp, dest);
189
+ }
190
+
182
191
  function usage() {
183
192
  console.log(`oc-harness-setup — install the OpenCode harness into your config dir.
184
193
 
@@ -197,7 +206,7 @@ function bail(msg) {
197
206
  }
198
207
 
199
208
  // Windows 10/11 only. This installer writes the Windows config home, runs
200
- // PowerShell doctors, and registers Windows shell policy — there is no
209
+ // the Node doctor, and registers Windows shell policy — there is no
201
210
  // macOS/Linux path. --help and --version return from parseArgs before any
202
211
  // dispatch, so they keep working everywhere.
203
212
  function assertWindows() {
@@ -427,7 +436,7 @@ function nextBackupPath(configDir) {
427
436
 
428
437
  /* ------------------------------ staged copy -------------------------------- */
429
438
 
430
- function stageFiles(files, manifest, prior, configDir) {
439
+ function stageFiles(files, manifest, prior) {
431
440
  // Prior manifests spell paths with either separator; incoming rels use the
432
441
  // platform join. Compare on normalized slashes so a prior entry still
433
442
  // matches its incoming path (journaling keeps each entry's own spelling).
@@ -435,85 +444,81 @@ function stageFiles(files, manifest, prior, configDir) {
435
444
  const priorByPath = new Map(
436
445
  (prior && Array.isArray(prior.files) ? prior.files : []).map((f) => [norm(f.path), f])
437
446
  );
438
- let written = 0;
447
+ const counts = { added: 0, updated: 0, kept: 0, skipped: 0 };
439
448
  for (const f of files) {
440
449
  const srcHash = sha256File(f.src);
441
- let action = 'written';
442
- let prevHash = null;
443
- let archivedTo = null;
444
- if (existsSync(f.dest)) {
445
- const destHash = sha256File(f.dest);
446
- if (destHash === srcHash) {
447
- action = 'skip';
448
- log('staging', `skip ${f.rel} (already identical — rerun-safe)`);
449
- } else if (PRESERVE_IF_EXISTS.has(norm(f.rel))) {
450
- // Upgrade rule: preserve only a GENUINELY adopter-edited file, i.e.
451
- // one that differs from the prior manifest hash. A destination that
452
- // still matches the prior installed hash is unmodified pack content —
453
- // update it, so a stock 0.3.3 AGENTS.md is replaced by the V9 contract
454
- // while an adopter-edited AGENTS.md is kept. No prior record means we
455
- // cannot prove it is stock, so preserve (never destroy unknown data).
456
- const p = priorByPath.get(norm(f.rel));
457
- if (p && p.hash && destHash === p.hash) {
458
- action = 'overwritten';
459
- prevHash = destHash;
460
- log('staging', `update ${f.rel} (matches the prior installed hash — unmodified pack content, overwriting; backup + manifest protect you)`);
461
- } else {
462
- action = 'preserved';
463
- log('staging', `preserve ${f.rel} (exists and differs from the prior install — kept; harness will not overwrite adopter-owned files)`);
464
- }
465
- } else {
466
- // Safe-upgrade rule: a destination the user edited since install
467
- // (its bytes differ from the prior manifest hash) is archived before
468
- // the overwrite, so a user-modified 0.3.x file that the new distro
469
- // still ships — e.g. agents/orchestrator.md — is never silently
470
- // destroyed. Unmodified pack content (or no prior record) overwrites
471
- // normally; the pre-install backup still protects it. Files in
472
- // PRESERVE_IF_EXISTS never reach this branch (kept above, never
473
- // archived). Same archive root and nextFreePath as retireStale.
474
- const p = priorByPath.get(norm(f.rel));
475
- // state/template.md is pack-owned but graded: an existing copy that
476
- // differs from the shipped bytes is ALWAYS archived before the
477
- // overwrite, with or without a prior manifest entry.
478
- const isTemplate = norm(f.rel) === 'state/template.md';
479
- if ((p && p.hash && destHash !== p.hash) || (isTemplate && destHash !== srcHash)) {
480
- const dest2 = nextFreePath(path.join(configDir, 'state', 'archive', 'legacy-0.3.x', f.rel));
481
- mkdirSync(path.dirname(dest2), { recursive: true });
482
- renameSync(f.dest, dest2);
483
- archivedTo = path.relative(configDir, dest2);
484
- action = 'overwritten';
485
- prevHash = destHash;
486
- log('staging', `archive ${f.rel} → ${archivedTo} (you edited the old file — pre-upgrade bytes moved aside; writing the new file)`);
487
- } else {
488
- // A genuine overwrite: journal it so --uninstall can put the original
489
- // back from the pre-install backup instead of deleting the harness copy.
490
- action = 'overwritten';
491
- prevHash = destHash;
492
- log('staging', `update ${f.rel} (destination differs — overwriting; backup + manifest protect you)`);
493
- }
494
- }
495
- } else {
496
- log('staging', `copy ${f.rel}`);
450
+ const verdict = classifyDest(f, srcHash, priorByPath, norm);
451
+ if (verdict.action === 'skip') {
452
+ counts.skipped += 1;
453
+ log('staging', `skip ${f.rel} (already identical — rerun-safe)`);
454
+ manifest.files.push({ path: f.rel, hash: srcHash, action: 'skip' });
455
+ continue;
497
456
  }
498
- if (action === 'written' || action === 'overwritten') {
499
- mkdirSync(path.dirname(f.dest), { recursive: true });
500
- const tmp = `${f.dest}.oc-harness-setup-tmp-${process.pid}`;
501
- writeFileSync(tmp, readFileSync(f.src));
502
- atomicInstall(tmp, f.dest);
503
- written += 1;
457
+ if (verdict.action === 'written') {
458
+ installBytes(f.dest, readFileSync(f.src));
459
+ counts.added += 1;
460
+ log('staging', `copy ${f.rel}`);
461
+ manifest.files.push({ path: f.rel, hash: srcHash, action: 'written' });
462
+ continue;
504
463
  }
505
- // Preserved entries journal the SRC hash on purpose: --uninstall deletes
506
- // only on an exact match, so a preserved destination (bytes differ from
507
- // src) reads as modified → kept, not deleted.
508
- if (archivedTo) {
509
- manifest.files.push({ path: f.rel, hash: srcHash, prevHash, action, archivedTo });
510
- } else if (prevHash) {
511
- manifest.files.push({ path: f.rel, hash: srcHash, prevHash, action });
512
- } else {
513
- manifest.files.push({ path: f.rel, hash: srcHash, action });
464
+ if (verdict.action === 'kept') {
465
+ // The destination is the adopter's file: leave it byte-identical and put
466
+ // the new pack bytes beside it. `newPath` is journaled so --uninstall can
467
+ // sweep the `.new` and so a later run can see the adopter's adoption.
468
+ const newRel = `${norm(f.rel)}.new`;
469
+ const newPath = `${f.dest}.new`;
470
+ if (!(existsSync(newPath) && sha256File(newPath) === srcHash)) {
471
+ installBytes(newPath, readFileSync(f.src));
472
+ }
473
+ counts.kept += 1;
474
+ log('staging', `kept user file ${norm(f.rel)}, wrote ${newRel} (differs from what we installed — your bytes are untouched)`);
475
+ manifest.files.push({ path: f.rel, hash: srcHash, prevHash: verdict.prevHash, action: 'kept', newPath: newRel });
476
+ continue;
514
477
  }
478
+ // `overwritten`: the destination still matches the prior installed hash, so
479
+ // it is package-owned content and replacing it IS the upgrade.
480
+ installBytes(f.dest, readFileSync(f.src));
481
+ counts.updated += 1;
482
+ log('staging', `update ${f.rel} (unmodified package content — updated in place; backup + manifest protect you)`);
483
+ manifest.files.push({ path: f.rel, hash: srcHash, prevHash: verdict.prevHash, action: 'overwritten' });
515
484
  }
516
- return written;
485
+ return counts;
486
+ }
487
+
488
+ // The whole install policy in one place: a destination is only replaced when it
489
+ // still carries the bytes we installed. Silence about a path (no prior record)
490
+ // proves no ownership, so the adopter keeps it.
491
+ // absent → written (nothing to respect)
492
+ // identical to the pack → skip (rerun-safe)
493
+ // identical to the prior install → overwritten (package-owned; this is the upgrade)
494
+ // anything else → kept (adopter-owned; `.new` lands beside it)
495
+ function classifyDest(f, srcHash, priorByPath, norm) {
496
+ if (!existsSync(f.dest)) return { action: 'written' };
497
+ const destHash = sha256File(f.dest);
498
+ if (destHash === srcHash) return { action: 'skip' };
499
+ const prior = priorByPath.get(norm(f.rel));
500
+ if (prior && prior.hash && destHash === prior.hash) {
501
+ return { action: 'overwritten', prevHash: destHash };
502
+ }
503
+ return { action: 'kept', prevHash: destHash };
504
+ }
505
+
506
+ // Read-only twin of stageFiles for the pre-gate manifest: the same decision
507
+ // table, counted and never written.
508
+ function planCounts(files, prior) {
509
+ const norm = (p) => String(p).replace(/\\/g, '/');
510
+ const priorByPath = new Map(
511
+ (prior && Array.isArray(prior.files) ? prior.files : []).map((f) => [norm(f.path), f])
512
+ );
513
+ const counts = { added: 0, updated: 0, kept: 0, skipped: 0 };
514
+ for (const f of files) {
515
+ const v = classifyDest(f, sha256File(f.src), priorByPath, norm);
516
+ if (v.action === 'written') counts.added += 1;
517
+ else if (v.action === 'overwritten') counts.updated += 1;
518
+ else if (v.action === 'kept') counts.kept += 1;
519
+ else counts.skipped += 1;
520
+ }
521
+ return counts;
517
522
  }
518
523
 
519
524
  // A prior `skills/<id>/...` path belongs to skill <id>; anything else is not
@@ -582,6 +587,26 @@ function retireStale(configDir, prior, files, manifest) {
582
587
  if (settled) retiredSkills.add(settled);
583
588
  continue;
584
589
  }
590
+ if (entry.action === 'kept') {
591
+ // The live path holds the adopter's bytes, not ours — an upgrade must not
592
+ // move it anywhere. Only our own `.new` beside it is retired.
593
+ log('retire', `keep ${rel} (your file from an earlier install — left in place)`);
594
+ const newRel = entry.newPath ? String(entry.newPath) : `${norm(rel)}.new`;
595
+ const newResolved = path.resolve(base, newRel);
596
+ if (newResolved.startsWith(base + path.sep) && existsSync(newResolved)) {
597
+ try {
598
+ if (entry.hash && sha256File(newResolved) === entry.hash) {
599
+ rmSync(newResolved, { force: true });
600
+ log('retire', `removed ${newRel} (our copy beside your file — this version no longer ships it)`);
601
+ } else {
602
+ log('retire', `keep ${newRel} (you edited it — left in place)`);
603
+ }
604
+ } catch {
605
+ log('retire', `keep ${newRel} (unreadable — refusing)`);
606
+ }
607
+ }
608
+ continue;
609
+ }
585
610
  const resolved = path.resolve(base, rel);
586
611
  if (resolved !== base && !resolved.startsWith(base + path.sep)) {
587
612
  log('retire', `skip ${rel} (escapes the config dir — refusing)`);
@@ -700,6 +725,33 @@ function parseJsonc(text, what) {
700
725
  }
701
726
  }
702
727
 
728
+ const isPlainObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
729
+
730
+ // Additive merge for an install-owned key: the distro value is a default the
731
+ // adopter may adopt, never a replacement for their own. Plain objects merge, so
732
+ // a subkey the adopter never set still arrives; every collided leaf keeps the
733
+ // adopter's value and is named in `collisions` so the report can cite it.
734
+ function adoptInstallOwned(distro, user, key, pathParts, collisions) {
735
+ const d = distro[key];
736
+ const u = user[key];
737
+ if (isPlainObject(d) && isPlainObject(u)) {
738
+ for (const sub of Object.keys(u)) adoptInstallOwned(d, u, sub, [...pathParts, sub], collisions);
739
+ return;
740
+ }
741
+ if (JSON.stringify(d) !== JSON.stringify(u)) collisions.push(pathParts.join('.'));
742
+ distro[key] = u;
743
+ }
744
+
745
+ // Deny-owning blocks are additive without being softenable: the adopter's own
746
+ // entries ride along, every shipped entry stays, and the shipped entries land
747
+ // last so a user allow can never shadow a shipped deny under last-match-wins.
748
+ function unionDenyLast(distro, user) {
749
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
750
+ const d = Array.isArray(distro) ? distro : [];
751
+ const u = Array.isArray(user) ? user : [];
752
+ return [...u.filter((r) => !d.some((x) => same(x, r))), ...d];
753
+ }
754
+
703
755
  function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set(), prior = null) {
704
756
  const distroPath = path.join(PKG_ROOT, 'opencode.jsonc');
705
757
  if (!existsSync(distroPath)) {
@@ -734,8 +786,22 @@ function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set(),
734
786
  if (user.permissions !== undefined && !userPerms) {
735
787
  console.warn('[warn] merge: your "permissions" is not an array (v2 expects an array of {action,resource,effect}) — harness denies kept; fix your rules manually.');
736
788
  }
789
+ const ownedCollisions = [];
737
790
  for (const k of Object.keys(user)) {
738
- if (INSTALL_OWNED.includes(k)) continue; // distro value wins outright
791
+ if (DENY_OWNED.includes(k)) {
792
+ if (!Array.isArray(user[k])) {
793
+ console.warn(`[warn] merge: your "${k}" is not an array — the shipped deny entries are kept and yours cannot be merged; fix your rules manually.`);
794
+ } else {
795
+ merged[k] = unionDenyLast(merged[k], user[k]);
796
+ }
797
+ preserved.push(k);
798
+ continue;
799
+ }
800
+ if (INSTALL_OWNED.includes(k)) {
801
+ adoptInstallOwned(merged, user, k, [k], ownedCollisions);
802
+ preserved.push(k);
803
+ continue;
804
+ }
739
805
  if (k === 'permissions') {
740
806
  if (!userPerms) continue;
741
807
  // Ordered union, deny-last. Under last-match-wins an adopter's rule must
@@ -803,6 +869,9 @@ function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set(),
803
869
  }
804
870
  preserved.push(k);
805
871
  }
872
+ if (ownedCollisions.length) {
873
+ log('merge', `kept your value(s) for install-owned key(s): ${ownedCollisions.join(', ')} — the shipped default is not applied to them (delete the key to adopt it)`);
874
+ }
806
875
  } else {
807
876
  log('merge', 'no existing opencode.jsonc/opencode.json — writing the harness base');
808
877
  }
@@ -844,7 +913,7 @@ function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set(),
844
913
  manifest.files.push({ path: 'opencode.jsonc', hash: sha256Text(out), action: 'merged' });
845
914
  log(
846
915
  'merge',
847
- `ownership — install-owned (distro wins): ${INSTALL_OWNED.join(', ')} · union: ${[...UNION_KEYS, 'references'].join(', ')} · your keys preserved: ${preserved.length}${preserved.length ? ` (${preserved.join(', ')})` : ''}`
916
+ `ownership — your value wins on a collision for: ${INSTALL_OWNED.join(', ')} · deny block unioned, shipped denies last: ${DENY_OWNED.join(', ')} · union: ${[...UNION_KEYS, 'references'].join(', ')} · your keys preserved: ${preserved.length}${preserved.length ? ` (${preserved.join(', ')})` : ''}`
848
917
  );
849
918
  log('merge', `rewrote ${targetPath} (distro base + your keys; permissions = harness allows, yours, harness denies last)`);
850
919
  }
@@ -871,32 +940,18 @@ function lintPackagedSource(files) {
871
940
 
872
941
  /* --------------------------------- doctor ---------------------------------- */
873
942
 
874
- function pwshProbe() {
875
- const probe = exec('pwsh', ['-NoProfile', '-Command', 'exit 0'], true);
876
- return { usable: !(probe.error || probe.status !== 0) };
877
- }
878
-
879
943
  function doctorPlan() {
880
- return pwshProbe().usable
881
- ? 'run scripts/harness-doctor.ps1 via pwsh'
882
- : 'pwsh missing — doctor SKIPPED, 18 laws UNVERIFIED (warned + journaled)';
944
+ return 'run scripts/harness-doctor.mjs via node';
883
945
  }
884
946
 
885
- function runDoctor(configDir, probe) {
886
- if (!probe.usable) {
887
- console.warn('[doctor] WARNING: pwsh (PowerShell 7) was not found — harness-doctor did NOT run, so the 18 laws are UNVERIFIED.');
888
- console.warn('[doctor] Your config still landed, and the skip is recorded in the manifest. To verify later:');
889
- console.log(' winget install --id Microsoft.PowerShell --source winget (Windows)');
890
- console.log(' then re-run: npx oc-harness-setup setup');
891
- return { code: 0, skipped: true };
892
- }
893
- const script = path.join(configDir, 'scripts', 'harness-doctor.ps1');
947
+ function runDoctor(configDir) {
948
+ const script = path.join(configDir, 'scripts', 'harness-doctor.mjs');
894
949
  if (!existsSync(script)) {
895
950
  console.warn(`[doctor] WARNING: ${script} not found — harness-doctor did NOT run, so the 18 laws are UNVERIFIED.`);
896
951
  return { code: 0, skipped: true };
897
952
  }
898
953
  log('doctor', `running ${script}`);
899
- const res = exec('pwsh', ['-NoProfile', '-File', script, '-ConfigDir', configDir], false);
954
+ const res = exec(process.execPath, [script, '-ConfigDir', configDir], false);
900
955
  if (res.error || res.status !== 0) {
901
956
  log(
902
957
  'doctor',
@@ -910,18 +965,19 @@ function runDoctor(configDir, probe) {
910
965
 
911
966
  /* --------------------------- manifest print (gate) ------------------------- */
912
967
 
913
- function printManifest(configDir, files, backupPath, doctor) {
968
+ function printManifest(configDir, files, backupPath, doctor, prior = null) {
914
969
  const newCount = files.filter((f) => !existsSync(f.dest)).length;
915
970
  const sameCount = files.length - newCount;
971
+ const plan = planCounts(files, prior);
916
972
  console.log('----------------------------- install manifest -----------------------------');
917
973
  console.log(` destination config dir : ${configDir}`);
918
974
  console.log(` incoming files : ${files.length} (${newCount} new, ${sameCount} already identical — rerun-safe)`);
975
+ console.log(` policy : ${plan.updated} updated in place (unmodified package files) · ${plan.kept} kept + .new written (your files) · ${plan.added} added · ${plan.skipped} skipped (identical)`);
919
976
  console.log(` backup path : ${backupPath}`);
920
977
  console.log(' opencode.jsonc merge : distro base (permissions/deny block, policies block, skill allowlist,');
921
978
  console.log(' default_agent: "orchestrator", references registry)');
922
- console.log(' + your keys kept · permissions: harness allows, yours, harness denies last');
923
- console.log(' state-seed/ -> state/ : shipped seed maps to live state/ (state/lessons.md is preserved;');
924
- console.log(' state/template.md is pack-owned, and an edited copy is archived under state/archive/ then replaced)');
979
+ console.log(' + your keys kept, your value wins on a collision · permissions: harness allows, yours, harness denies last');
980
+ console.log(' state-seed/ -> state/ : shipped seed maps to live state/ (an edited state file is kept, the seeded copy lands as <name>.new)');
925
981
  console.log(` doctor plan : harness-doctor, 18 laws — ${doctor}`);
926
982
  console.log('----------------------------------------------------------------------------');
927
983
  }
@@ -1030,6 +1086,32 @@ function uninstall(configDir, opts = {}) {
1030
1086
  }
1031
1087
  continue;
1032
1088
  }
1089
+ if (entry.action === 'kept') {
1090
+ // The live path is the adopter's file — uninstall never removes it. The
1091
+ // `.new` beside it is our bytes, so that one goes when it is unmodified.
1092
+ kept += 1;
1093
+ const newRel = entry.newPath ? String(entry.newPath) : null;
1094
+ const newResolved = newRel ? path.resolve(base, newRel) : null;
1095
+ const insideBase = newResolved && newResolved.startsWith(base + path.sep);
1096
+ if (!insideBase || !existsSync(newResolved)) {
1097
+ log('uninstall', `kept ${rel} (your file — never removed)`);
1098
+ continue;
1099
+ }
1100
+ if (entry.hash && sha256File(newResolved) === entry.hash) {
1101
+ if (preview) {
1102
+ removed += 1;
1103
+ log('uninstall', `would remove ${newRel} (our copy beside your kept file)`);
1104
+ } else {
1105
+ rmSync(newResolved, { force: true });
1106
+ removed += 1;
1107
+ log('uninstall', `removed ${newRel} (our copy beside your kept file)`);
1108
+ }
1109
+ } else {
1110
+ kept += 1;
1111
+ log('uninstall', `kept ${newRel} (you edited the new version — keeping it)`);
1112
+ }
1113
+ continue;
1114
+ }
1033
1115
  if (!existsSync(resolved)) {
1034
1116
  missing += 1;
1035
1117
  continue;
@@ -1142,17 +1224,26 @@ function carryForwardJournal(manifest, prior) {
1142
1224
  if (p.action === 'overwritten') {
1143
1225
  e.action = 'overwritten';
1144
1226
  e.prevHash = p.prevHash || e.prevHash;
1145
- } else if (p.action === 'preserved' && e.action !== 'overwritten') {
1227
+ } else if (p.action === 'kept' && e.action !== 'overwritten') {
1228
+ // The adopter's file was never ours; an identical destination (they may
1229
+ // have adopted the old `.new`) must not be downgraded to `skip`, or
1230
+ // --uninstall would delete a file the harness never wrote.
1231
+ e.action = 'kept';
1232
+ e.prevHash = p.prevHash || e.prevHash;
1233
+ e.newPath = p.newPath || e.newPath;
1234
+ } else if (p.action === 'preserved' && e.action !== 'overwritten' && e.action !== 'kept') {
1146
1235
  e.action = 'preserved';
1147
1236
  }
1148
1237
  }
1149
1238
  // A re-run must not forget what an earlier run settled: those paths are
1150
1239
  // already deleted or archived and absent from this run's staging, but
1151
1240
  // --uninstall still needs them to restore the pre-install originals from
1152
- // the backup chain.
1241
+ // the backup chain. A kept adopter path the pack no longer ships is carried
1242
+ // for the same reason: its `.new` may still be beside it.
1153
1243
  const now = new Set(manifest.files.map((f) => norm(f.path)));
1154
1244
  for (const p of prior.files) {
1155
- if ((p.action === 'retired' || p.action === 'archived') && !now.has(norm(p.path))) {
1245
+ const settled = p.action === 'retired' || p.action === 'archived' || p.action === 'kept';
1246
+ if (settled && !now.has(norm(p.path))) {
1156
1247
  manifest.files.push(p);
1157
1248
  now.add(norm(p.path));
1158
1249
  }
@@ -1265,7 +1356,7 @@ async function setup(opts) {
1265
1356
  const prior = readManifest(configDir); // read-only
1266
1357
  const newBackupPath = nextBackupPath(configDir);
1267
1358
  const backupPath = prior && prior.backupPath ? prior.backupPath : newBackupPath;
1268
- printManifest(configDir, files, backupPath, doctorPlan());
1359
+ printManifest(configDir, files, backupPath, doctorPlan(), prior);
1269
1360
  if (opts.dryRun) {
1270
1361
  console.log('[dry-run] manifest only — nothing was touched.');
1271
1362
  return 0;
@@ -1298,8 +1389,7 @@ async function setup(opts) {
1298
1389
  // already been mutated by the previous install, so restoring from it would be
1299
1390
  // a lie. Keep the original pointer; chain the new snapshot as priorBackup.
1300
1391
  const backupPath = prior && prior.backupPath ? prior.backupPath : newBackupPath;
1301
- const doctorProbe = pwshProbe(); // read-only probe
1302
- printManifest(configDir, files, backupPath, doctorPlan());
1392
+ printManifest(configDir, files, backupPath, doctorPlan(), prior);
1303
1393
 
1304
1394
  // (F2: --dry-run / --ci already returned print-only before preflight.)
1305
1395
  if (!(await confirmProceed())) {
@@ -1329,26 +1419,30 @@ async function setup(opts) {
1329
1419
 
1330
1420
  const retiredSkills = retireStale(configDir, prior, files, manifest);
1331
1421
  if (retiredSkills.size) log('retire', `${retiredSkills.size} stale skill id(s) retired — their allowlist entries are pruned from the merge (${[...retiredSkills].join(', ')})`);
1332
- stageFiles(files, manifest, prior, configDir);
1422
+ const staged = stageFiles(files, manifest, prior);
1333
1423
  carryForwardJournal(manifest, prior);
1334
1424
  // An adopter's own plugins[] entries survive the merge via UNION_KEYS; the
1335
1425
  // distro ships no plugins of its own, so there is nothing to register here.
1336
1426
  mergeJsonc(configDir, backup, manifest, retiredSkills, prior);
1337
1427
 
1338
1428
  // R6: record the skip in the journal so "all 18 laws unrun" is never silent.
1339
- manifest.doctorSkipped = !doctorProbe.usable || !existsSync(path.join(configDir, 'scripts', 'harness-doctor.ps1'));
1429
+ manifest.doctorSkipped = !existsSync(path.join(configDir, 'scripts', 'harness-doctor.mjs'));
1340
1430
  writeManifest(configDir, manifest);
1341
1431
  log('manifest', `journal written: ${path.join(configDir, MANIFEST_FILE)}`);
1342
1432
 
1343
- const doctorResult = runDoctor(configDir, doctorProbe);
1433
+ const doctorResult = runDoctor(configDir);
1344
1434
  if (doctorResult.code !== 0) return 1;
1345
1435
 
1346
1436
  console.log();
1347
1437
  console.log('-------------------------------- summary ---------------------------------');
1348
1438
  console.log(' installed: agents/, commands/, skills/, reference/, scripts/, .docs/, state/ (from state-seed/), AGENTS.md, GLOSSARY.md + merged opencode.jsonc');
1439
+ console.log(` policy : ${staged.updated} updated in place (unmodified package files) · ${staged.kept} kept + .new written (your files) · ${staged.added} added · ${staged.skipped} skipped (identical)`);
1440
+ if (staged.kept > 0) {
1441
+ console.log(' adopt : the new version of each kept file sits beside it as <name>.new — diff it and move it over when you want it');
1442
+ }
1349
1443
  console.log(` backup : ${manifest.backupPath}${manifest.priorBackup ? `\n snapshot : ${manifest.priorBackup} (chained — backup() pointer above is the original)` : ''}`);
1350
1444
  if (manifest.doctorSkipped) {
1351
- console.log(' doctor : ⚠ SKIPPED — the 18 laws were NOT verified (journaled as doctorSkipped; install PowerShell 7 and re-run to verify)');
1445
+ console.log(' doctor : ⚠ SKIPPED — the 18 laws were NOT verified (journaled as doctorSkipped; re-run setup to verify)');
1352
1446
  }
1353
1447
  console.log(' undo : npx oc-harness-setup setup --uninstall');
1354
1448
  console.log(' restart : restart your OpenCode session so the new agents/commands/skills load.');