oc-harness-setup 0.1.1 → 0.2.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/AGENTS.md +3 -3
- package/README.md +13 -13
- package/agents/keeper.md +3 -3
- package/agents/master.md +5 -0
- package/bin/cli.js +294 -81
- package/commands/doctor.md +1 -0
- package/commands/keeper.md +1 -1
- package/commands/report.md +13 -0
- package/package.json +1 -1
- package/reference/README.md +1 -1
- package/reference/model-keeper.md +4 -4
- package/reference/model-test.md +3 -3
- package/scripts/harness-report.ps1 +695 -0
- package/reference/models.md.example +0 -21
package/bin/cli.js
CHANGED
|
@@ -26,8 +26,42 @@ const PKG_ROOT = path.resolve(import.meta.dirname, '..');
|
|
|
26
26
|
const MANIFEST_FILE = 'oc-harness-setup.manifest.json';
|
|
27
27
|
const COPY_DIRS = ['agents', 'commands', 'skills', 'reference', 'scripts', '.docs'];
|
|
28
28
|
const COPY_FILES = ['AGENTS.md', '.gitignore'];
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
// Ownership table for the opencode.jsonc merge. Every top-level key falls into
|
|
30
|
+
// exactly one bucket; there is no "known merge key" list to drift out of date.
|
|
31
|
+
// INSTALL_OWNED — the distro's value wins outright (runtime policy).
|
|
32
|
+
// UNION_KEYS — arrays unioned + deduped (distro entries first).
|
|
33
|
+
// 'references' — object union: distro keys + user-only keys.
|
|
34
|
+
// 'permissions' — ordered union: harness allow/ask rules first, then the
|
|
35
|
+
// adopter's rules, then the harness's hard DENIES last. Under
|
|
36
|
+
// last-match-wins this lets an adopter's deny beat a harness
|
|
37
|
+
// allow while nothing can shadow a harness deny. The `skill`
|
|
38
|
+
// wildcard deny is exempt from the move (its fail-closed
|
|
39
|
+
// allowlist is deny-then-allows; see mergeJsonc).
|
|
40
|
+
// everything else (known or unknown) — the adopter's value wins; the distro
|
|
41
|
+
// value stays when the adopter does not define the key.
|
|
42
|
+
const INSTALL_OWNED = ['$schema', 'default_agent', 'compaction', 'tool_output', 'media', 'watcher'];
|
|
43
|
+
const UNION_KEYS = ['plugins'];
|
|
44
|
+
// Adopter-owned files: shipped copies are skeletons, so an existing destination
|
|
45
|
+
// that differs MUST survive an upgrade — overwriting it destroys their data.
|
|
46
|
+
const PRESERVE_IF_EXISTS = new Set(['reference/models.md', 'AGENTS.md', '.gitignore']);
|
|
47
|
+
// Author-leak markers — they catch the MAINTAINER's machine leaking into the
|
|
48
|
+
// shipped tree (paths, username, session ids). They are linted against the
|
|
49
|
+
// package source only, never the adopter's config, so a legitimate
|
|
50
|
+
// `{file:~/.secrets/…}` apiKey pointer can never abort an install.
|
|
51
|
+
//
|
|
52
|
+
// Every marker is anchored to the AUTHOR's CONCRETE machine — drive `Q:`, user
|
|
53
|
+
// `nathan`, a real `ses_<id>` — never to the product's own vocabulary. The
|
|
54
|
+
// harness's safety tooling legitimately ships the generic forms
|
|
55
|
+
// (`C:\Users\<name>`, `ses_<id>`, `~/.secrets/…` — redactor regexes and their
|
|
56
|
+
// self-test probes), so a bare generic token would abort every correct install.
|
|
57
|
+
// A leak of an author path into a secret store is caught by the username/drive
|
|
58
|
+
// markers; a bare `.secrets` cannot distinguish product from author and so is
|
|
59
|
+
// deliberately not a marker. `nathan` also subsumes `C:\Users\nathan`.
|
|
60
|
+
const LINT_PATTERNS = [
|
|
61
|
+
{ label: 'q:\\', test: /q:\\/ },
|
|
62
|
+
{ label: 'nathan', test: /nathan/ },
|
|
63
|
+
{ label: 'ses_<id>', test: /ses_[a-z0-9]{16,}/ },
|
|
64
|
+
];
|
|
31
65
|
|
|
32
66
|
/* ------------------------------ tiny helpers ------------------------------ */
|
|
33
67
|
|
|
@@ -35,6 +69,16 @@ function log(label, msg) {
|
|
|
35
69
|
console.log(`[${label}] ${msg}`);
|
|
36
70
|
}
|
|
37
71
|
|
|
72
|
+
// Never reuse a taken path when preserving bytes: copying onto an existing file
|
|
73
|
+
// would destroy the very copy we are trying to keep.
|
|
74
|
+
function nextFreePath(base) {
|
|
75
|
+
if (!existsSync(base)) return base;
|
|
76
|
+
for (let i = 2; ; i++) {
|
|
77
|
+
const p = `${base}-${i}`;
|
|
78
|
+
if (!existsSync(p)) return p;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
38
82
|
function usage() {
|
|
39
83
|
console.log(`oc-harness-setup — install the OpenCode harness into your config dir.
|
|
40
84
|
|
|
@@ -196,8 +240,7 @@ function collectIncoming(configDir) {
|
|
|
196
240
|
|
|
197
241
|
/* -------------------------------- backup ----------------------------------- */
|
|
198
242
|
|
|
199
|
-
function makeBackup(configDir) {
|
|
200
|
-
const backupPath = `${configDir}.bak-oc-harness-setup-${tsStamp()}`;
|
|
243
|
+
function makeBackup(configDir, backupPath) {
|
|
201
244
|
if (existsSync(configDir)) {
|
|
202
245
|
if (!statSync(configDir).isDirectory()) {
|
|
203
246
|
bail(`${configDir} exists but is not a directory — refusing to install over it`);
|
|
@@ -210,6 +253,16 @@ function makeBackup(configDir) {
|
|
|
210
253
|
return backupPath;
|
|
211
254
|
}
|
|
212
255
|
|
|
256
|
+
// A second-resolution stamp can repeat on a fast re-run. If that path already
|
|
257
|
+
// exists it may be the PRESERVED ORIGINAL snapshot, and cpSync into an existing
|
|
258
|
+
// dir would overwrite pristine bytes — so never reuse a taken path.
|
|
259
|
+
function nextBackupPath(configDir) {
|
|
260
|
+
const stamp = tsStamp();
|
|
261
|
+
let p = `${configDir}.bak-oc-harness-setup-${stamp}`;
|
|
262
|
+
for (let i = 2; existsSync(p); i++) p = `${configDir}.bak-oc-harness-setup-${stamp}-${i}`;
|
|
263
|
+
return p;
|
|
264
|
+
}
|
|
265
|
+
|
|
213
266
|
/* ------------------------------ staged copy -------------------------------- */
|
|
214
267
|
|
|
215
268
|
function stageFiles(files, manifest) {
|
|
@@ -217,17 +270,26 @@ function stageFiles(files, manifest) {
|
|
|
217
270
|
for (const f of files) {
|
|
218
271
|
const srcHash = sha256File(f.src);
|
|
219
272
|
let action = 'written';
|
|
273
|
+
let prevHash = null;
|
|
220
274
|
if (existsSync(f.dest)) {
|
|
221
|
-
|
|
275
|
+
const destHash = sha256File(f.dest);
|
|
276
|
+
if (destHash === srcHash) {
|
|
222
277
|
action = 'skip';
|
|
223
278
|
log('staging', `skip ${f.rel} (already identical — rerun-safe)`);
|
|
279
|
+
} else if (PRESERVE_IF_EXISTS.has(f.rel)) {
|
|
280
|
+
action = 'preserved';
|
|
281
|
+
log('staging', `preserve ${f.rel} (exists and differs — kept; harness will not overwrite adopter-owned files)`);
|
|
224
282
|
} else {
|
|
283
|
+
// A genuine overwrite: journal it so --uninstall can put the original
|
|
284
|
+
// back from the pre-install backup instead of deleting the harness copy.
|
|
285
|
+
action = 'overwritten';
|
|
286
|
+
prevHash = destHash;
|
|
225
287
|
log('staging', `update ${f.rel} (destination differs — overwriting; backup + manifest protect you)`);
|
|
226
288
|
}
|
|
227
289
|
} else {
|
|
228
290
|
log('staging', `copy ${f.rel}`);
|
|
229
291
|
}
|
|
230
|
-
if (action === 'written') {
|
|
292
|
+
if (action === 'written' || action === 'overwritten') {
|
|
231
293
|
mkdirSync(path.dirname(f.dest), { recursive: true });
|
|
232
294
|
const tmp = `${f.dest}.oc-harness-setup-tmp-${process.pid}`;
|
|
233
295
|
writeFileSync(tmp, readFileSync(f.src));
|
|
@@ -235,7 +297,10 @@ function stageFiles(files, manifest) {
|
|
|
235
297
|
renameSync(tmp, f.dest);
|
|
236
298
|
written += 1;
|
|
237
299
|
}
|
|
238
|
-
|
|
300
|
+
// Preserved entries journal the SRC hash on purpose: --uninstall deletes
|
|
301
|
+
// only on an exact match, so a preserved destination (bytes differ from
|
|
302
|
+
// src) reads as modified → kept, not deleted.
|
|
303
|
+
manifest.files.push(prevHash ? { path: f.rel, hash: srcHash, prevHash, action } : { path: f.rel, hash: srcHash, action });
|
|
239
304
|
}
|
|
240
305
|
return written;
|
|
241
306
|
}
|
|
@@ -312,44 +377,75 @@ function parseJsonc(text, what) {
|
|
|
312
377
|
}
|
|
313
378
|
}
|
|
314
379
|
|
|
315
|
-
function describeKey(k, v) {
|
|
316
|
-
if (k === 'model') return `model "${v}"`;
|
|
317
|
-
if (Array.isArray(v)) return `${k} (${v.length} entr${v.length === 1 ? 'y' : 'ies'})`;
|
|
318
|
-
if (v && typeof v === 'object') {
|
|
319
|
-
const n = Object.keys(v).length;
|
|
320
|
-
return `${k} (${n} entr${n === 1 ? 'y' : 'ies'})`;
|
|
321
|
-
}
|
|
322
|
-
return `${k} (${JSON.stringify(v)})`;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
380
|
function mergeJsonc(configDir, backupPath, manifest) {
|
|
326
381
|
const distroPath = path.join(PKG_ROOT, 'opencode.jsonc');
|
|
327
|
-
const userPath = path.join(configDir, 'opencode.jsonc');
|
|
328
382
|
if (!existsSync(distroPath)) {
|
|
329
383
|
log('merge', 'note: this package ships no opencode.jsonc — no merge to do');
|
|
330
384
|
return;
|
|
331
385
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
386
|
+
// Output is always opencode.jsonc (the canonical file the doctor grades).
|
|
387
|
+
// Input prefers the adopter's opencode.jsonc; when only opencode.json exists
|
|
388
|
+
// we merge THAT, rather than ignoring the adopter's real config.
|
|
389
|
+
const targetPath = path.join(configDir, 'opencode.jsonc');
|
|
390
|
+
const jsonPath = path.join(configDir, 'opencode.json');
|
|
391
|
+
const sourcePath = existsSync(targetPath) ? targetPath : existsSync(jsonPath) ? jsonPath : null;
|
|
392
|
+
if (sourcePath === jsonPath) {
|
|
393
|
+
console.warn(
|
|
394
|
+
`[warn] merge: found ${jsonPath} but no opencode.jsonc — merging it into a freshly written opencode.jsonc. ` +
|
|
395
|
+
'Your opencode.json is left untouched; reconcile or remove it so the two cannot drift.'
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const merged = structuredClone(
|
|
400
|
+
parseJsonc(readFileSync(distroPath, 'utf8'), 'the shipped opencode.jsonc (this package build looks broken)')
|
|
335
401
|
);
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
402
|
+
const preserved = [];
|
|
403
|
+
if (sourcePath) {
|
|
338
404
|
const user = parseJsonc(
|
|
339
|
-
readFileSync(
|
|
340
|
-
`your existing
|
|
405
|
+
readFileSync(sourcePath, 'utf8'),
|
|
406
|
+
`your existing ${path.basename(sourcePath)} — aborting before any write; your config is untouched (backup: ${backupPath})`
|
|
341
407
|
);
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
408
|
+
const userPerms = Array.isArray(user.permissions) ? user.permissions : null;
|
|
409
|
+
if (user.permissions !== undefined && !userPerms) {
|
|
410
|
+
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.');
|
|
411
|
+
}
|
|
412
|
+
for (const k of Object.keys(user)) {
|
|
413
|
+
if (INSTALL_OWNED.includes(k)) continue; // distro value wins outright
|
|
414
|
+
if (k === 'permissions') {
|
|
415
|
+
if (!userPerms) continue;
|
|
416
|
+
// Ordered union, deny-last. Under last-match-wins an adopter's rule must
|
|
417
|
+
// sit AFTER the harness's allow/ask rules (whose leading `shell *` allow
|
|
418
|
+
// would otherwise neutralise an adopter `shell … deny`), and every
|
|
419
|
+
// harness HARD DENY must stay after both so nothing can shadow it
|
|
420
|
+
// (Law 12). The `skill` action is exempt from the move: its fail-closed
|
|
421
|
+
// allowlist is `skill * → deny` FOLLOWED by one allow per local skill
|
|
422
|
+
// (Law 9 requires the wildcard deny; Law 12 exempts the action), so
|
|
423
|
+
// moving that deny last would deny every known skill. Skill rules keep
|
|
424
|
+
// their shipped relative order in the head.
|
|
425
|
+
// Rules identical to a harness rule are dropped from the adopter's side
|
|
426
|
+
// and kept from the harness's, so a re-run reproduces the same array
|
|
427
|
+
// exactly (a plain concat would double it on every run).
|
|
428
|
+
const distroPerms = Array.isArray(merged.permissions) ? merged.permissions : [];
|
|
429
|
+
const sameRule = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
430
|
+
const isHardDeny = (p) => !!p && p.effect === 'deny' && p.action !== 'skill';
|
|
431
|
+
const distroHead = distroPerms.filter((p) => !isHardDeny(p));
|
|
432
|
+
const distroTail = distroPerms.filter(isHardDeny);
|
|
433
|
+
const userOnly = userPerms.filter((p) => !distroPerms.some((d) => sameRule(d, p)));
|
|
434
|
+
merged.permissions = [...distroHead, ...userOnly, ...distroTail];
|
|
435
|
+
} else if (UNION_KEYS.includes(k)) {
|
|
436
|
+
merged[k] = Array.isArray(user[k])
|
|
437
|
+
? [...new Set([...(Array.isArray(merged[k]) ? merged[k] : []), ...user[k]])]
|
|
438
|
+
: user[k];
|
|
439
|
+
} else if (k === 'references') {
|
|
440
|
+
// Object union: distro keys + user-only keys.
|
|
441
|
+
merged.references = { ...(user.references ?? {}), ...(merged.references ?? {}) };
|
|
346
442
|
} else {
|
|
347
|
-
|
|
443
|
+
merged[k] = user[k]; // adopter value wins
|
|
348
444
|
}
|
|
445
|
+
preserved.push(k);
|
|
349
446
|
}
|
|
350
|
-
log('merge', `kept your ${kept.join(', ') || '(nothing — harness defaults only)'}`);
|
|
351
447
|
} else {
|
|
352
|
-
log('merge', 'no existing opencode.jsonc — writing the harness base');
|
|
448
|
+
log('merge', 'no existing opencode.jsonc/opencode.json — writing the harness base');
|
|
353
449
|
}
|
|
354
450
|
// JSON.stringify strips comments, including the marker the doctor's Law 11
|
|
355
451
|
// cites as evidence — reinsert it so the merged file still documents the
|
|
@@ -363,26 +459,33 @@ function mergeJsonc(configDir, backupPath, manifest) {
|
|
|
363
459
|
);
|
|
364
460
|
const out = `${mergedText}\n`;
|
|
365
461
|
mkdirSync(configDir, { recursive: true });
|
|
366
|
-
const tmp = `${
|
|
462
|
+
const tmp = `${targetPath}.oc-harness-setup-tmp-${process.pid}`;
|
|
367
463
|
writeFileSync(tmp, out);
|
|
368
|
-
rmSync(
|
|
369
|
-
renameSync(tmp,
|
|
464
|
+
rmSync(targetPath, { force: true });
|
|
465
|
+
renameSync(tmp, targetPath);
|
|
370
466
|
manifest.files.push({ path: 'opencode.jsonc', hash: sha256Text(out), action: 'merged' });
|
|
371
|
-
log(
|
|
467
|
+
log(
|
|
468
|
+
'merge',
|
|
469
|
+
`ownership — install-owned (distro wins): ${INSTALL_OWNED.join(', ')} · union: ${[...UNION_KEYS, 'references'].join(', ')} · your keys preserved: ${preserved.length}${preserved.length ? ` (${preserved.join(', ')})` : ''}`
|
|
470
|
+
);
|
|
471
|
+
log('merge', `rewrote ${targetPath} (distro base + your keys; permissions = harness allows, yours, harness denies last)`);
|
|
372
472
|
}
|
|
373
473
|
|
|
374
|
-
/* ------------------------------
|
|
474
|
+
/* ------------------------------ author-leak lint --------------------------- */
|
|
375
475
|
|
|
376
|
-
|
|
476
|
+
// Lints the PACKAGE source (files[].src) and nothing else. The adopter's config
|
|
477
|
+
// is never a lint target, so a valid config — including a DOCS-SANCTIONED
|
|
478
|
+
// `{file:~/.secrets/…}` apiKey pointer — can never trip this abort. Called
|
|
479
|
+
// pre-write, so a hit aborts before anything lands.
|
|
480
|
+
function lintPackagedSource(files) {
|
|
377
481
|
const hits = [];
|
|
378
482
|
for (const f of files) {
|
|
379
|
-
if (!existsSync(f.
|
|
380
|
-
const low = readFileSync(f.
|
|
483
|
+
if (!f.src || !existsSync(f.src)) continue;
|
|
484
|
+
const low = readFileSync(f.src, 'utf8').toLowerCase();
|
|
485
|
+
// No `break`: a file can carry more than one marker, and reporting only the
|
|
486
|
+
// first hides the rest of the leak.
|
|
381
487
|
for (const pat of LINT_PATTERNS) {
|
|
382
|
-
if (
|
|
383
|
-
hits.push({ file: f.rel, pattern: pat });
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
488
|
+
if (pat.test.test(low)) hits.push({ file: f.rel, pattern: pat.label });
|
|
386
489
|
}
|
|
387
490
|
}
|
|
388
491
|
return hits;
|
|
@@ -409,26 +512,30 @@ function registerPlugins() {
|
|
|
409
512
|
|
|
410
513
|
/* --------------------------------- doctor ---------------------------------- */
|
|
411
514
|
|
|
412
|
-
function
|
|
515
|
+
function pwshProbe() {
|
|
413
516
|
const probe = exec('pwsh', ['-NoProfile', '-Command', 'exit 0'], true);
|
|
414
|
-
return probe.error || probe.status !== 0
|
|
415
|
-
? 'pwsh missing — doctor skipped, install note printed'
|
|
416
|
-
: 'run scripts/harness-doctor.ps1 via pwsh';
|
|
517
|
+
return { usable: !(probe.error || probe.status !== 0) };
|
|
417
518
|
}
|
|
418
519
|
|
|
419
|
-
function
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
520
|
+
function doctorPlan() {
|
|
521
|
+
return pwshProbe().usable
|
|
522
|
+
? 'run scripts/harness-doctor.ps1 via pwsh'
|
|
523
|
+
: 'pwsh missing — doctor SKIPPED, 16 laws UNVERIFIED (warned + journaled)';
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function runDoctor(configDir, probe) {
|
|
527
|
+
if (!probe.usable) {
|
|
528
|
+
console.warn('[doctor] WARNING: pwsh (PowerShell 7) was not found — harness-doctor did NOT run, so the 16 laws are UNVERIFIED.');
|
|
529
|
+
console.warn('[doctor] Your config still landed, and the skip is recorded in the manifest. To verify later:');
|
|
424
530
|
console.log(' winget install --id Microsoft.PowerShell --source winget (Windows)');
|
|
425
531
|
console.log(' brew install --cask powershell (macOS)');
|
|
426
|
-
|
|
532
|
+
console.log(' then re-run: npx oc-harness-setup setup');
|
|
533
|
+
return { code: 0, skipped: true };
|
|
427
534
|
}
|
|
428
535
|
const script = path.join(configDir, 'scripts', 'harness-doctor.ps1');
|
|
429
536
|
if (!existsSync(script)) {
|
|
430
|
-
|
|
431
|
-
return 0;
|
|
537
|
+
console.warn(`[doctor] WARNING: ${script} not found — harness-doctor did NOT run, so the 16 laws are UNVERIFIED.`);
|
|
538
|
+
return { code: 0, skipped: true };
|
|
432
539
|
}
|
|
433
540
|
log('doctor', `running ${script}`);
|
|
434
541
|
const res = exec('pwsh', ['-NoProfile', '-File', script, '-ConfigDir', configDir], false);
|
|
@@ -437,10 +544,10 @@ function runDoctor(configDir) {
|
|
|
437
544
|
'doctor',
|
|
438
545
|
`harness-doctor exited ${res.error ? 'with an error' : `${res.status}`} — fix the issue, then re-run setup (idempotent)`
|
|
439
546
|
);
|
|
440
|
-
return 1;
|
|
547
|
+
return { code: 1, skipped: false };
|
|
441
548
|
}
|
|
442
549
|
log('doctor', 'harness-doctor passed');
|
|
443
|
-
return 0;
|
|
550
|
+
return { code: 0, skipped: false };
|
|
444
551
|
}
|
|
445
552
|
|
|
446
553
|
/* --------------------------- manifest print (gate) ------------------------- */
|
|
@@ -454,7 +561,7 @@ function printManifest(configDir, files, backupPath, doctor) {
|
|
|
454
561
|
console.log(` backup path : ${backupPath}`);
|
|
455
562
|
console.log(' opencode.jsonc merge : distro base (permissions/deny block, skill allowlist,');
|
|
456
563
|
console.log(' default_agent: "master", references registry)');
|
|
457
|
-
console.log(
|
|
564
|
+
console.log(' + your keys kept · permissions: harness allows, yours, harness denies last');
|
|
458
565
|
console.log(' plugin registration : oc-flight-deck (via \'opencode plugin add\')');
|
|
459
566
|
console.log(` doctor plan : ${doctor}`);
|
|
460
567
|
console.log('----------------------------------------------------------------------------');
|
|
@@ -491,8 +598,11 @@ function uninstall(configDir) {
|
|
|
491
598
|
const base = path.resolve(configDir);
|
|
492
599
|
const files = Array.isArray(manifest.files) ? manifest.files : [];
|
|
493
600
|
if (!files.length) bail(`manifest at ${manifestPath} lists no files — refusing a blind cleanup.`);
|
|
601
|
+
const backupRoot = manifest.backupPath ? path.resolve(String(manifest.backupPath)) : null;
|
|
494
602
|
let removed = 0;
|
|
603
|
+
let restored = 0;
|
|
495
604
|
let kept = 0;
|
|
605
|
+
let preserved = 0;
|
|
496
606
|
let missing = 0;
|
|
497
607
|
for (const entry of files) {
|
|
498
608
|
const rel = String(entry.path || '');
|
|
@@ -505,6 +615,32 @@ function uninstall(configDir) {
|
|
|
505
615
|
missing += 1;
|
|
506
616
|
continue;
|
|
507
617
|
}
|
|
618
|
+
if (entry.action === 'overwritten' || entry.action === 'merged') {
|
|
619
|
+
// A genuine overwrite comes back from the pre-install backup; the merged
|
|
620
|
+
// opencode.jsonc is never deleted — restore the adopter's original, or
|
|
621
|
+
// leave the harness copy in place when no backup holds it.
|
|
622
|
+
const original = backupRoot ? path.join(backupRoot, rel) : null;
|
|
623
|
+
if (original && existsSync(original)) {
|
|
624
|
+
// Restoring is only reversible if the bytes being replaced survive. When
|
|
625
|
+
// the current file is not the one the installer wrote (hash differs, or
|
|
626
|
+
// none was journaled) it holds post-install edits — copy it aside before
|
|
627
|
+
// the restore overwrites it. Byte-identical installer output needs no
|
|
628
|
+
// copy.
|
|
629
|
+
if (!entry.hash || sha256File(resolved) !== entry.hash) {
|
|
630
|
+
const keep = nextFreePath(`${resolved}.replaced-${tsStamp()}`);
|
|
631
|
+
cpSync(resolved, keep);
|
|
632
|
+
preserved += 1;
|
|
633
|
+
log('uninstall', `kept ${path.relative(base, keep)} (your post-install edits — copied before restore)`);
|
|
634
|
+
}
|
|
635
|
+
cpSync(original, resolved, { force: true });
|
|
636
|
+
restored += 1;
|
|
637
|
+
log('uninstall', `restored ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
638
|
+
} else {
|
|
639
|
+
kept += 1;
|
|
640
|
+
log('uninstall', `kept ${rel} (WARNING: no backup at ${original || '(no backupPath recorded)'} — not deleted)`);
|
|
641
|
+
}
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
508
644
|
if (entry.hash && sha256File(resolved) === entry.hash) {
|
|
509
645
|
rmSync(resolved, { force: true });
|
|
510
646
|
removed += 1;
|
|
@@ -515,9 +651,16 @@ function uninstall(configDir) {
|
|
|
515
651
|
}
|
|
516
652
|
}
|
|
517
653
|
rmSync(manifestPath, { force: true });
|
|
518
|
-
log('uninstall', `removed ${removed}, kept ${kept} modified, already-missing ${missing}`);
|
|
654
|
+
log('uninstall', `removed ${removed}, restored ${restored} overwritten, kept ${kept} modified, preserved ${preserved} edit-copies, already-missing ${missing}`);
|
|
519
655
|
console.log(` backup (pre-install config dir): ${manifest.backupPath || '(none recorded)'}`);
|
|
656
|
+
if (manifest.priorBackup) console.log(` later snapshot (kept for the chain): ${manifest.priorBackup}`);
|
|
520
657
|
console.log(' to restore it fully, replace the current config dir with that backup.');
|
|
658
|
+
if (preserved > 0) {
|
|
659
|
+
console.log(` ${preserved} post-install edit-copy(ies) written beside the restored file(s) as <name>.replaced-<ts> (listed above).`);
|
|
660
|
+
}
|
|
661
|
+
if (manifest.doctorSkipped) {
|
|
662
|
+
console.log(' note: this install skipped the doctor — the 16 laws were never verified.');
|
|
663
|
+
}
|
|
521
664
|
if (Array.isArray(manifest.plugins) && manifest.plugins.length) {
|
|
522
665
|
console.log(
|
|
523
666
|
` plugins left registered: ${manifest.plugins.join(', ')} — remove with 'opencode plugin remove <name>' if unwanted.`
|
|
@@ -532,13 +675,89 @@ function writeManifest(configDir, manifest) {
|
|
|
532
675
|
writeFileSync(path.join(configDir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
533
676
|
}
|
|
534
677
|
|
|
678
|
+
// R4: a re-run must not erase what an earlier run knew. A file this run sees as
|
|
679
|
+
// "skip" may have been an overwrite two runs ago; downgrading it to "skip" would
|
|
680
|
+
// make --uninstall delete the adopter's original instead of restoring it. Keep
|
|
681
|
+
// the earliest truth: overwritten stays overwritten (with the ORIGINAL prevHash),
|
|
682
|
+
// preserved stays preserved.
|
|
683
|
+
function carryForwardJournal(manifest, prior) {
|
|
684
|
+
if (!prior || !Array.isArray(prior.files)) return;
|
|
685
|
+
const before = new Map(prior.files.map((f) => [String(f.path), f]));
|
|
686
|
+
for (const e of manifest.files) {
|
|
687
|
+
const p = before.get(String(e.path));
|
|
688
|
+
if (!p) continue;
|
|
689
|
+
if (p.action === 'overwritten') {
|
|
690
|
+
e.action = 'overwritten';
|
|
691
|
+
e.prevHash = p.prevHash || e.prevHash;
|
|
692
|
+
} else if (p.action === 'preserved' && e.action !== 'overwritten') {
|
|
693
|
+
e.action = 'preserved';
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function readManifest(configDir) {
|
|
699
|
+
const p = path.join(configDir, MANIFEST_FILE);
|
|
700
|
+
if (!existsSync(p)) return null;
|
|
701
|
+
try {
|
|
702
|
+
const m = JSON.parse(readFileSync(p, 'utf8'));
|
|
703
|
+
return m && typeof m === 'object' ? m : null;
|
|
704
|
+
} catch {
|
|
705
|
+
return null; // an unreadable manifest is not a reason to abort — a fresh one is written
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function warnConfigTargets(configDir) {
|
|
710
|
+
if (process.env.OPENCODE_CONFIG) {
|
|
711
|
+
console.warn(
|
|
712
|
+
`[warn] OPENCODE_CONFIG is set (${process.env.OPENCODE_CONFIG}) — it loads ABOVE the global config and may shadow this merge; check 'opencode debug config' after install.`
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
const own = new Set([
|
|
716
|
+
path.resolve(configDir, 'opencode.jsonc'),
|
|
717
|
+
path.resolve(configDir, 'opencode.json'),
|
|
718
|
+
]);
|
|
719
|
+
let dir = path.resolve(process.cwd());
|
|
720
|
+
for (;;) {
|
|
721
|
+
for (const name of ['opencode.jsonc', 'opencode.json']) {
|
|
722
|
+
const p = path.join(dir, name);
|
|
723
|
+
if (existsSync(p) && !own.has(path.resolve(p))) {
|
|
724
|
+
console.warn(
|
|
725
|
+
`[warn] project config ${p} outranks the global config — it may shadow this merge for sessions started in ${dir} or below (warn only; nothing changes).`
|
|
726
|
+
);
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const parent = path.dirname(dir);
|
|
731
|
+
if (parent === dir) return;
|
|
732
|
+
dir = parent;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
535
736
|
async function setup(opts) {
|
|
536
737
|
preflight();
|
|
537
738
|
const configDir = findConfigDir();
|
|
739
|
+
warnConfigTargets(configDir);
|
|
538
740
|
const files = collectIncoming(configDir);
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
741
|
+
|
|
742
|
+
// Author-leak lint runs PRE-write, over the PACKAGE source only. A hit aborts
|
|
743
|
+
// before the consent gate, so nothing lands and the adopter's config (which
|
|
744
|
+
// is never linted) can never trip it.
|
|
745
|
+
const hits = lintPackagedSource(files);
|
|
746
|
+
if (hits.length) {
|
|
747
|
+
for (const h of hits) console.error(`[lint] author-leak marker "${h.pattern}" found in ${h.file}`);
|
|
748
|
+
bail(
|
|
749
|
+
`author-leak markers found in the packaged source (${hits.length} file(s) listed above) — this package build is corrupted; NOTHING was written. Reinstall from npm.`
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const prior = readManifest(configDir); // read-only
|
|
754
|
+
const newBackupPath = nextBackupPath(configDir);
|
|
755
|
+
// R4(d): a re-run must never re-point the original backup — that snapshot has
|
|
756
|
+
// already been mutated by the previous install, so restoring from it would be
|
|
757
|
+
// a lie. Keep the original pointer; chain the new snapshot as priorBackup.
|
|
758
|
+
const backupPath = prior && prior.backupPath ? prior.backupPath : newBackupPath;
|
|
759
|
+
const doctorProbe = pwshProbe(); // read-only probe
|
|
760
|
+
printManifest(configDir, files, backupPath, doctorPlan());
|
|
542
761
|
|
|
543
762
|
if (opts.dryRun) {
|
|
544
763
|
console.log('[dry-run] manifest only — nothing was touched.');
|
|
@@ -554,18 +773,20 @@ async function setup(opts) {
|
|
|
554
773
|
}
|
|
555
774
|
|
|
556
775
|
/* ---------------- mutations begin (all journaled) ---------------- */
|
|
557
|
-
const backup = makeBackup(configDir);
|
|
776
|
+
const backup = makeBackup(configDir, newBackupPath);
|
|
558
777
|
const manifest = {
|
|
559
778
|
package: PKG_NAME,
|
|
560
779
|
version: pkgVersion(),
|
|
561
780
|
created: new Date().toISOString(),
|
|
562
781
|
configDir,
|
|
563
|
-
backupPath:
|
|
782
|
+
backupPath: backupPath,
|
|
783
|
+
...(prior && prior.backupPath ? { priorBackup: backup } : {}),
|
|
564
784
|
plugins: ['oc-flight-deck'],
|
|
565
785
|
files: [],
|
|
566
786
|
};
|
|
567
787
|
|
|
568
788
|
stageFiles(files, manifest);
|
|
789
|
+
carryForwardJournal(manifest, prior);
|
|
569
790
|
// Register plugins BEFORE the merge: on a fresh dir `opencode plugin add`
|
|
570
791
|
// installs the plugin, but once the merged opencode.jsonc lists it, add
|
|
571
792
|
// no-ops with "already configured" and nothing lands in `opencode plugin
|
|
@@ -573,30 +794,22 @@ async function setup(opts) {
|
|
|
573
794
|
registerPlugins();
|
|
574
795
|
mergeJsonc(configDir, backup, manifest);
|
|
575
796
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
{ rel: 'opencode.jsonc (merged)', dest: path.join(configDir, 'opencode.jsonc') },
|
|
579
|
-
]);
|
|
580
|
-
if (hits.length) {
|
|
581
|
-
// Journal first — uninstall must know exactly what landed.
|
|
582
|
-
writeManifest(configDir, manifest);
|
|
583
|
-
for (const h of hits) console.error(`[lint] placeholder pattern "${h.pattern}" found in ${h.file}`);
|
|
584
|
-
bail(
|
|
585
|
-
`placeholder data found in the shipped tree (${hits.length} file(s) listed above) — this package build is corrupted; stop and reinstall from npm. Restore your config from: ${backup}`
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
|
|
797
|
+
// R6: record the skip in the journal so "all 16 laws unrun" is never silent.
|
|
798
|
+
manifest.doctorSkipped = !doctorProbe.usable || !existsSync(path.join(configDir, 'scripts', 'harness-doctor.ps1'));
|
|
589
799
|
writeManifest(configDir, manifest);
|
|
590
800
|
log('manifest', `journal written: ${path.join(configDir, MANIFEST_FILE)}`);
|
|
591
801
|
|
|
592
|
-
const
|
|
593
|
-
if (
|
|
802
|
+
const doctorResult = runDoctor(configDir, doctorProbe);
|
|
803
|
+
if (doctorResult.code !== 0) return 1;
|
|
594
804
|
|
|
595
805
|
console.log();
|
|
596
806
|
console.log('-------------------------------- summary ---------------------------------');
|
|
597
807
|
console.log(' installed: agents/, commands/, skills/, reference/, scripts/, AGENTS.md + merged opencode.jsonc');
|
|
598
808
|
console.log(' plugins : oc-flight-deck');
|
|
599
|
-
console.log(` backup : ${backup}`);
|
|
809
|
+
console.log(` backup : ${manifest.backupPath}${manifest.priorBackup ? `\n snapshot : ${manifest.priorBackup} (chained — backup() pointer above is the original)` : ''}`);
|
|
810
|
+
if (manifest.doctorSkipped) {
|
|
811
|
+
console.log(' doctor : ⚠ SKIPPED — the 16 laws were NOT verified (journaled as doctorSkipped; install PowerShell 7 and re-run to verify)');
|
|
812
|
+
}
|
|
600
813
|
console.log(' undo : npx oc-harness-setup setup --uninstall');
|
|
601
814
|
console.log(' restart : restart your OpenCode session so the new agents/commands/skills load.');
|
|
602
815
|
console.log('----------------------------------------------------------------------------');
|
package/commands/doctor.md
CHANGED
|
@@ -14,5 +14,6 @@ From `~/.config/opencode`, run `pwsh -File scripts\harness-doctor.ps1` and repor
|
|
|
14
14
|
- Law 14 skill-allowlist set equality: allow entries and local skill IDs agree in both directions.
|
|
15
15
|
- Law 15 agent/command frontmatter: `agents/*.md` carry description+steps, `commands/*.md` carry description.
|
|
16
16
|
- Law 16 skill-loadable: every skill directory carries a `SKILL.md` with name+description and no YAML-breaking plain scalar.
|
|
17
|
+
- On a real regression or drift, recommend `/report` as the next action: it runs `scripts\harness-report.ps1` and returns a redacted, prefilled issue URL for the product repo. The doctor itself still writes nothing; `/report` also writes nothing by default - it prints the redacted body and the prefilled URL to the console, and only a run that passes `-OutFile <path>` writes that body to disk. Nothing is filed unless the human submits it.
|
|
17
18
|
|
|
18
19
|
Close with: verdict (clean / drift / real regression), the exact commands run, files changed (normally none), and the next action.
|
package/commands/keeper.md
CHANGED
|
@@ -4,4 +4,4 @@ agent: keeper
|
|
|
4
4
|
subagent: true
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Refresh the model picture: compare `reference/models.md
|
|
7
|
+
Refresh the model picture: compare `reference/models.md` and the model bindings in the file-based `agents\*.md` definitions against the live catalogs, pricing, and variants, following the canonical protocol in `reference/model-keeper.md`. Apply only evidence-backed changes; keep the catalog, bindings, and config parsing consistent. Report changes, sources, and uncertainty — or a clean no-change result.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Build a redacted harness report with a prefilled issue URL - offer to file it, never auto-file
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
From `~/.config/opencode`, run `pwsh -File scripts\harness-report.ps1` and report what it returns. `$ARGUMENTS` may be empty, `-Json`, `-OutFile <path>`, `-ConfigDir <path>`, or `-SelfTest`.
|
|
6
|
+
|
|
7
|
+
- Redaction is enforced in code, not promised in prose: every field that reaches the body passes one chokepoint in `scripts\harness-report.ps1`. Home and config paths collapse to `~`, the installer's backup path becomes `~/.opencode-backup/<ts>`, session ids become `<session>`, hostnames `<host>`, and usernames `<user>`. Secret-like **values** are redacted in place to `<redacted>` whenever the name keys the redactor (a diagnostic line survives; only the value becomes `<redacted>`). A line is dropped whole only when it cannot be kept safely: a `{file:...}` pointer target, a path into a secret store, or a bare credential literal. Show the exact post-redaction bytes the script printed - never re-render, summarise, or "improve" them, and never re-read the files behind them.
|
|
8
|
+
- TRIAGE every FAIL before offering anything, one line each: **HARNESS-BUG** (the product is wrong - a missing path, a broken law, a frontmatter check that ships broken) versus **LOCAL-DRIFT** (the user's own config or machine - a stale path, a plugin they removed, a CLI they never installed). Real regressions never auto-fix; say which bucket each one falls in and why. DRIFT is neither: it means the instrument could not derive an expectation, so repair the CLI or restore the file first.
|
|
9
|
+
- Print the prefilled URL verbatim, then OFFER to open the issue - the human gate holds EVERY time. Never file, never call `gh`, never open a browser to the URL, and never post to the product repo on your own initiative; the human submits it or it does not happen.
|
|
10
|
+
- PowerShell 7 (`pwsh`) is required for the doctor, so it is required for this report. If `pwsh` is absent, both are skipped: say so plainly, print the doctor-only findings you can see by other means, and do not pretend a report was generated.
|
|
11
|
+
- Never read or print the secret store or `.env`; the reporter's own guard refuses those paths and `-SelfTest` proves the redactor.
|
|
12
|
+
|
|
13
|
+
Close with: verdict (clean / real regression / drift), what the report found, the exact command run, whether anything was filed (normally nothing), and one question - file it, fix locally, or leave it.
|
package/package.json
CHANGED
package/reference/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Read these only when the task calls for them:
|
|
|
7
7
|
- `model-keeper.md` — how to refresh the model catalog and the agent model bindings (file-based under `agents\*.md`) from live evidence.
|
|
8
8
|
- `scripts\harness-doctor.ps1` — self-contained harness health check (run `pwsh -File scripts\harness-doctor.ps1` from `~/.config/opencode` after changing the harness).
|
|
9
9
|
|
|
10
|
-
## Gotchas (verified
|
|
10
|
+
## Gotchas (verified 2026-09-20)
|
|
11
11
|
|
|
12
12
|
Two traps were hit in one session and both cost real time. Check them before editing permission globs or running shell.
|
|
13
13
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Model Keeper
|
|
2
2
|
|
|
3
|
-
The `keeper` maintains the model picture: the catalog in `reference/models.md
|
|
3
|
+
The `keeper` maintains the model picture: the catalog in `reference/models.md` and the agent model bindings in the file-based agent definitions under `~/.config/opencode/agents/*.md` (the `model:` frontmatter). `opencode.jsonc` carries global defaults and may mirror bindings; for a given agent, its `agents\*.md` file is authoritative. `/keeper` is the explicit refresh point. The keeper works from live evidence and reports changes, sources, and uncertainty — or a clean no-change result.
|
|
4
4
|
|
|
5
5
|
## Keeper pass
|
|
6
6
|
|
|
7
|
-
1. Read `reference/models.md
|
|
7
|
+
1. Read `reference/models.md`, the agent files in `~/.config/opencode/agents/*.md`, `opencode.jsonc`, and the harness references that describe routing.
|
|
8
8
|
2. Query the live provider catalogs and list the models and variants each one offers.
|
|
9
9
|
3. Check official pricing, context sizes, capabilities, and available variants for the candidate models.
|
|
10
10
|
4. Diff the live picture against the configured bindings and the catalog: additions, removals, renames, price changes, capability changes, and variant changes.
|
|
11
|
-
5. Update `reference/models.md
|
|
11
|
+
5. Update `reference/models.md` and the `model:` bindings in `agents\*.md` together (touching `opencode.jsonc` only when defaults or mirrored bindings change), keeping every configured agent binding in agreement with the catalog. Only the `keeper` writes agent files; one writer per artifact.
|
|
12
12
|
6. Validate: every `model:` frontmatter value parses and resolves against the catalog, agent files still parse with their frontmatter, and `opencode.jsonc` (if touched) stays consistent.
|
|
13
13
|
|
|
14
14
|
## Evidence rules
|
|
@@ -17,7 +17,7 @@ The `keeper` maintains the model picture: the catalog in `reference/models.md.ex
|
|
|
17
17
|
- Official provider pricing is the price authority.
|
|
18
18
|
- Promotions, temporary discounts, free trials, and usage multipliers are not routing evidence.
|
|
19
19
|
- Record cache-read rates, context tiers, and per-model allocations when the source exposes them.
|
|
20
|
-
- Record source URLs and the verification date in `reference/models.md
|
|
20
|
+
- Record source URLs and the verification date in `reference/models.md`.
|
|
21
21
|
- Preserve uncertainty when sources disagree; never invent a model ID, price, or variant.
|
|
22
22
|
- Keep secrets by pointer only: never print, paste, log, or commit a key value.
|
|
23
23
|
|