oc-harness-setup 0.4.5 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ ## [0.5.0] - 2026-10-28
6
+
7
+ ### Fixed
8
+
9
+ - `plugins[]` entries are emitted in the OpenCode 2.2.0 shape: a specifier
10
+ string. A 1.x `[specifier, options]` tuple is reduced to its specifier and
11
+ reported (2.2.0 drops a tuple entry outright, so the plugin silently stopped
12
+ loading), a non-string entry is reported instead of written, and the union
13
+ dedupes on strings so a re-run is byte-identical. The retired distro-plugin
14
+ match no longer assumes an unscoped `name@version` specifier.
15
+ - Config shapes are proven against the installed host rather than assumed:
16
+ new `test/host-schema.test.js` round-trips the shipped config and a real
17
+ merged config through `opencode debug config` and fails if the host drops any
18
+ key, while the hermetic suite pins `plugins` strings, `permissions[]` rules,
19
+ `policies[]` with `tool.use`, and the absence of 1.x singular keys.
20
+ - Preflight reads the `opencode v2.2.0` banner instead of echoing it (the log
21
+ line printed the product name twice), refuses a 1.x host before writing
22
+ anything (different config dialect), warns on a 2.0/2.1 host that the
23
+ `permissions[]`/`policies[]` deny gate is unproven there, and records the
24
+ host version in the install manifest. Compatibility truth: 2.2.0 tested;
25
+ 2.x warned; 1.x refused.
26
+
3
27
  ## [0.4.5] - 2026-10-23
4
28
 
5
29
  - npm front door split into a short `README.md`; full documentation moved to `docs/GUIDE.md`; no functional change.
package/README.md CHANGED
@@ -20,7 +20,7 @@ First run prints a manifest of everything it will touch and waits for you to typ
20
20
 
21
21
  ## Requirements
22
22
 
23
- Windows 10/11 only, with Node.js 22 or newer plus the OpenCode CLI installed and runnable.
23
+ Windows 10/11 only, with Node.js 22 or newer and OpenCode 2.2.0 or newer (the tested floor). A 2.0/2.1 host warns before installing — its `permissions[]`/`policies[]` deny gate is not proven there — and a 1.x host is refused before anything is written.
24
24
 
25
25
  ## Full documentation
26
26
 
package/bin/cli.js CHANGED
@@ -63,6 +63,54 @@ const DIR_ALIASES = { 'state-seed': 'state' };
63
63
  const INSTALL_OWNED = ['$schema', 'default_agent', 'formatter', 'compaction', 'tool_output', 'media', 'watcher', 'policies'];
64
64
  const UNION_KEYS = ['plugins'];
65
65
  const DISTRO_PLUGIN_IDS = ['oc-flight-deck'];
66
+
67
+ // `plugins` element truth for OpenCode 2.2.0, measured against the installed
68
+ // host (`opencode v2.2.0`, `opencode debug config`): an entry must be a
69
+ // specifier STRING — an npm name, `name@version`, `github:owner/repo#ref
70
+ // ::path:pkg`, or a local `.ts` path. The 1.x `[specifier, options]` tuple is
71
+ // DROPPED by the 2.2.0 schema (so the plugin silently stops loading), and a
72
+ // non-string is dropped too. A tuple is therefore reduced to its specifier —
73
+ // 2.2.0 has nowhere to express the options — and every entry that cannot be
74
+ // expressed is reported, never written into a config the host would ignore.
75
+ function pluginSpecifier(entry) {
76
+ if (typeof entry === 'string') {
77
+ const s = entry.trim();
78
+ return s ? s : null;
79
+ }
80
+ if (Array.isArray(entry) && typeof entry[0] === 'string' && entry[0].trim()) {
81
+ return entry[0].trim();
82
+ }
83
+ return null;
84
+ }
85
+
86
+ // Bare id of a specifier without mangling a scoped name: strip only a version
87
+ // suffix after the first character (`pkg@1.2.3` → `pkg`, `@scope/pkg@1.2.3`
88
+ // → `@scope/pkg`), and leave a `github:`/path specifier untouched.
89
+ function pluginIdOf(spec) {
90
+ const s = String(spec ?? '');
91
+ const at = s.indexOf('@', 1);
92
+ return at > 0 ? s.slice(0, at) : s;
93
+ }
94
+
95
+ // Reduce, dedupe (order preserved), and report 1.x plugin entries so a re-run
96
+ // produces byte-identical output and nothing the host would drop survives.
97
+ function normalizePluginEntries(entries) {
98
+ const out = [];
99
+ for (const entry of entries) {
100
+ const spec = pluginSpecifier(entry);
101
+ if (spec === null) {
102
+ log('merge', `dropped an unrepresentable plugins entry ${JSON.stringify(entry)} — OpenCode 2.2.0 accepts specifier strings only`);
103
+ continue;
104
+ }
105
+ if (Array.isArray(entry)) {
106
+ log('merge', `normalized the 1.x plugin tuple ${JSON.stringify(entry)} → "${spec}" (OpenCode 2.2.0 drops tuple entries; per-plugin options cannot be carried)`);
107
+ }
108
+ if (out.includes(spec)) continue;
109
+ out.push(spec);
110
+ }
111
+ return out;
112
+ }
113
+
66
114
  // Adopter-owned files: a shipped skeleton that the adopter genuinely edited
67
115
  // MUST survive an upgrade — overwriting it destroys their data. Genuineness
68
116
  // is proven against the prior manifest (see stageFiles): a destination that
@@ -234,8 +282,34 @@ function preflight() {
234
282
  '). Install/upgrade OpenCode first, then re-run setup.'
235
283
  );
236
284
  }
237
- const first = (res.stdout || '').trim().split(/\r?\n/)[0] || 'unknown version';
238
- log('preflight', `opencode ${first} — OK`);
285
+ // The 2.2.0 host prints exactly `opencode v2.2.0`; parse the version out of
286
+ // the banner instead of echoing the whole line (which logged the product name
287
+ // twice) and instead of accepting ANY version: the merged config uses the
288
+ // 2.2.0 dialect, so a 1.x host would silently drop `plugins[]` tuples,
289
+ // `permissions[]` and `policies[]` rather than honour them.
290
+ const banner = (res.stdout || '').trim().split(/\r?\n/)[0] || '';
291
+ const m = banner.match(/(\d+)\.(\d+)\.(\d+)/);
292
+ if (!m) {
293
+ bail(`could not read an OpenCode version from '${banner || 'no output'}' — expected 'opencode v2.2.0' or newer. Check 'opencode --version' by hand.`);
294
+ }
295
+ const host = { raw: `${m[1]}.${m[2]}.${m[3]}`, major: Number(m[1]), minor: Number(m[2]) };
296
+ if (host.major < 2) {
297
+ bail(
298
+ `OpenCode ${host.raw} speaks the 1.x config dialect (@opencode-ai/* plugins, an object \`permission\` block), not the 2.2.0 shape this package writes ` +
299
+ '(plugins[] of specifier strings, permissions[] of {action,resource,effect}, policies[] with tool.use). Nothing was written. ' +
300
+ 'Upgrade first (opencode upgrade), then re-run setup.'
301
+ );
302
+ }
303
+ if (host.minor < 2) {
304
+ console.warn(
305
+ `[warn] preflight: OpenCode ${host.raw} is below the 2.2.0 this package is tested on. The merge writes the 2.2-shaped config ` +
306
+ '(plugins[] as specifier strings, permissions[] of {action,resource,effect}, policies[] with tool.use); ' +
307
+ 'on 2.0/2.1 those blocks may be partly ignored, so the deny gate is not proven on this host. ' +
308
+ 'The install proceeds — upgrade to 2.2.0 or newer when you can.'
309
+ );
310
+ }
311
+ log('preflight', `opencode ${host.raw} — OK`);
312
+ return host;
239
313
  }
240
314
 
241
315
  function findConfigDir() {
@@ -699,24 +773,25 @@ function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set(),
699
773
  }
700
774
  merged.permissions = [...distroHead, ...userOnly, ...distroTail];
701
775
  } else if (UNION_KEYS.includes(k)) {
702
- let next;
703
- if (Array.isArray(user[k])) {
704
- next = [...new Set([...(Array.isArray(merged[k]) ? merged[k] : []), ...user[k]])];
776
+ if (!Array.isArray(user[k])) {
777
+ merged[k] = user[k]; // adopter's non-array value wins verbatim
705
778
  } else {
706
- next = user[k];
779
+ // `plugins` is the only union key, and it is the one whose element
780
+ // shape changed in 2.2.0: normalize before the union so dedupe works
781
+ // on strings (a tuple would never compare equal across runs and
782
+ // would accumulate).
783
+ merged[k] = normalizePluginEntries([
784
+ ...(Array.isArray(merged[k]) ? merged[k] : []),
785
+ ...user[k],
786
+ ]);
707
787
  }
708
- if (k === 'plugins' && priorIsOlder && Array.isArray(next)) {
709
- const isDistroPlugin = (e) => {
710
- const raw = Array.isArray(e) ? e[0] : e;
711
- return DISTRO_PLUGIN_IDS.includes(String(raw ?? '').split('@')[0]);
712
- };
713
- for (const d of next.filter(isDistroPlugin)) {
714
- const raw = Array.isArray(d) ? d[0] : d;
715
- log('merge', `dropped the retired distro plugin ${String(raw ?? '').split('@')[0]} (this version ships no plugin; your own plugin entries are kept)`);
788
+ if (k === 'plugins' && priorIsOlder && Array.isArray(merged[k])) {
789
+ const isDistroPlugin = (e) => DISTRO_PLUGIN_IDS.includes(pluginIdOf(e));
790
+ for (const d of merged[k].filter(isDistroPlugin)) {
791
+ log('merge', `dropped the retired distro plugin ${pluginIdOf(d)} (this version ships no plugin; your own plugin entries are kept)`);
716
792
  }
717
- next = next.filter((e) => !isDistroPlugin(e));
793
+ merged[k] = merged[k].filter((e) => !isDistroPlugin(e));
718
794
  }
719
- merged[k] = next;
720
795
  } else if (k === 'references') {
721
796
  // Object union: distro keys + user-only keys.
722
797
  merged.references = { ...(user.references ?? {}), ...(merged.references ?? {}) };
@@ -1195,7 +1270,7 @@ async function setup(opts) {
1195
1270
  console.log('[ci] refusing to mutate — print-only. Run setup interactively to install.');
1196
1271
  return 0;
1197
1272
  }
1198
- preflight();
1273
+ const host = preflight();
1199
1274
  const configDir = findConfigDir();
1200
1275
  warnConfigTargets(configDir);
1201
1276
  const files = collectIncoming(configDir);
@@ -1239,6 +1314,9 @@ async function setup(opts) {
1239
1314
  const manifest = {
1240
1315
  package: PKG_NAME,
1241
1316
  version: pkgVersion(),
1317
+ // The host whose dialect the merged config was written for: recorded so an
1318
+ // install's config shapes are auditable against the CLI that will read them.
1319
+ hostVersion: host.raw,
1242
1320
  created: new Date().toISOString(),
1243
1321
  configDir,
1244
1322
  backupPath: backupPath,
package/docs/GUIDE.md CHANGED
@@ -58,7 +58,7 @@ This starter grows through `evolve`: the smallest deliberate extension — one s
58
58
 
59
59
  - Windows 10/11 only; macOS and Linux are not supported.
60
60
  - Node.js 22 or newer, the only runtime requirement with zero runtime dependencies.
61
- - OpenCode CLI installed and runnable; setup refuses without it.
61
+ - OpenCode 2.2.0 or newer (the tested floor). A 2.0/2.1 host warns — the merged `permissions[]`/`policies[]` deny gate is unproven there — and a 1.x host is refused before anything is written (different config dialect).
62
62
  - PowerShell 7 for the doctor gate; without it the doctor reports skipped, never passed.
63
63
 
64
64
  ## Links
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-harness-setup",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "oc-harness-setup": "bin/cli.js"