oc-harness-setup 0.3.3 → 0.4.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/.docs/unwired-routing.md +16 -15
- package/AGENTS.md +105 -68
- package/CHANGELOG.md +107 -0
- package/GLOSSARY.md +46 -0
- package/LICENSE +1 -1
- package/README.md +49 -60
- package/agents/cleaner.md +86 -0
- package/agents/critic.md +79 -0
- package/agents/historian.md +92 -0
- package/agents/maintainer.md +106 -0
- package/agents/ops.md +69 -0
- package/agents/orchestrator.md +48 -18
- package/agents/researcher.md +72 -0
- package/agents/verifier.md +84 -0
- package/agents/worker.md +87 -0
- package/bin/cli.js +360 -133
- package/commands/close.md +11 -0
- package/commands/evolve.md +11 -0
- package/commands/fast.md +11 -0
- package/commands/goal.md +11 -0
- package/commands/search.md +11 -0
- package/commands/swarm.md +11 -0
- package/opencode.jsonc +39 -79
- package/package.json +13 -6
- package/reference/README.md +12 -14
- package/reference/canon.md +71 -0
- package/reference/context.md +35 -0
- package/reference/enforcement.md +6 -0
- package/reference/flow.md +19 -0
- package/reference/gates.md +23 -0
- package/reference/harness.md +15 -0
- package/reference/hygiene.md +13 -0
- package/reference/memory.md +13 -0
- package/reference/models.md +19 -24
- package/reference/phases.md +23 -0
- package/reference/repos.md +49 -0
- package/reference/tools.md +35 -0
- package/scripts/harness-doctor.ps1 +83 -0
- package/skills/close/SKILL.md +36 -0
- package/skills/evolve/SKILL.md +76 -0
- package/skills/fast/SKILL.md +36 -0
- package/skills/goal/SKILL.md +65 -0
- package/skills/search/SKILL.md +68 -0
- package/skills/swarm/SKILL.md +69 -0
- package/state-seed/lessons.md +22 -0
- package/state-seed/template.md +12 -0
- package/agents/build.md +0 -20
- package/agents/explore.md +0 -26
- package/agents/general.md +0 -19
- package/agents/plan.md +0 -29
- package/agents/reviewer.md +0 -22
- package/agents/vault.md +0 -73
- package/commands/build.md +0 -7
- package/commands/checkpoint.md +0 -7
- package/commands/code-simplify.md +0 -7
- package/commands/gauntlet.md +0 -7
- package/commands/handoff.md +0 -7
- package/commands/keeper.md +0 -7
- package/commands/kill.md +0 -11
- package/commands/plan.md +0 -7
- package/commands/retro.md +0 -15
- package/commands/review.md +0 -7
- package/commands/ship.md +0 -7
- package/commands/spec.md +0 -7
- package/commands/test.md +0 -7
- package/commands/webperf.md +0 -7
- package/reference/auto-mandate.md +0 -11
- package/reference/backup-convention.md +0 -9
- package/reference/clean-mandate.md +0 -13
- package/reference/editor-parity.md +0 -7
- package/reference/gc-scripts.md +0 -8
- package/reference/intent-routing.md +0 -14
- package/reference/lifecycle.md +0 -15
- package/reference/model-keeper.md +0 -46
- package/reference/model-test.md +0 -176
- package/reference/oc-source-map.md +0 -162
- package/reference/owner-pin.md +0 -31
- package/reference/roster.md +0 -15
- package/reference/session-scope.md +0 -9
- package/reference/session-state.md +0 -13
- package/reference/swarm.md +0 -32
- package/scripts/backup-config.ps1 +0 -42
- package/scripts/gc-branch.ps1 +0 -196
- package/scripts/gc-bump.ps1 +0 -198
- package/scripts/gc-clean.ps1 +0 -648
- package/scripts/gc-commit.ps1 +0 -143
- package/scripts/gc-merge.ps1 +0 -272
- package/scripts/gc-pr.ps1 +0 -190
- package/scripts/gc-push.ps1 +0 -111
- package/scripts/gc-read.ps1 +0 -150
- package/scripts/gc-rebase.ps1 +0 -162
- package/scripts/gc-release.ps1 +0 -225
- package/scripts/gc-stage.ps1 +0 -103
- package/scripts/gc-status.ps1 +0 -127
- package/scripts/gc-sync.ps1 +0 -65
- package/scripts/gc.core.ps1 +0 -715
- package/scripts/gc.smoke.ps1 +0 -779
- package/scripts/interrupt-session.ps1 +0 -65
- package/scripts/logbook/README.md +0 -108
- package/scripts/logbook/logbook.test.ts +0 -440
- package/scripts/logbook/logbook.ts +0 -797
- package/scripts/pirep/README.md +0 -147
- package/scripts/pirep/pirep.test.ts +0 -735
- package/scripts/pirep/pirep.ts +0 -836
- package/scripts/testflight/README.md +0 -112
- package/scripts/testflight/testflight.test.ts +0 -512
- package/scripts/testflight/testflight.ts +0 -806
- package/skills/_shared/SOURCES.md +0 -26
- package/skills/_shared/references/accessibility-checklist.md +0 -160
- package/skills/_shared/references/definition-of-done.md +0 -67
- package/skills/_shared/references/observability-checklist.md +0 -92
- package/skills/_shared/references/orchestration-patterns.md +0 -155
- package/skills/_shared/references/performance-checklist.md +0 -236
- package/skills/_shared/references/security-checklist.md +0 -245
- package/skills/_shared/references/testing-patterns.md +0 -235
- package/skills/api-and-interface-design/SKILL.md +0 -14
- package/skills/browser-testing-with-devtools/SKILL.md +0 -303
- package/skills/code-simplification/SKILL.md +0 -14
- package/skills/creative-writing/SKILL.md +0 -96
- package/skills/debugging-and-error-recovery/SKILL.md +0 -15
- package/skills/flight-deck/SKILL.md +0 -17
- package/skills/frontend-ui-engineering/SKILL.md +0 -16
- package/skills/gauntlet/SKILL.md +0 -21
- package/skills/git-ceremony/SKILL.md +0 -27
- package/skills/grilling/SKILL.md +0 -18
- package/skills/observability-and-instrumentation/SKILL.md +0 -18
- package/skills/performance-optimization/SKILL.md +0 -16
- package/skills/pilot-report/SKILL.md +0 -18
- package/skills/planning-and-task-breakdown/SKILL.md +0 -16
- package/skills/security-and-hardening/SKILL.md +0 -18
- package/skills/source-driven-development/SKILL.md +0 -16
- package/skills/spec-driven-development/SKILL.md +0 -26
- package/skills/test-driven-development/SKILL.md +0 -18
- package/skills/test-flight/SKILL.md +0 -14
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -89
package/bin/cli.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* --ci refuse to mutate: print the manifest, exit 0
|
|
9
9
|
* setup --uninstall delete exactly the manifest-listed files, keep
|
|
10
10
|
* user-modified ones, print the backup restore path
|
|
11
|
+
* --version / -v print the package version, touch nothing
|
|
11
12
|
*
|
|
12
13
|
* Exit codes are strictly 0 (ok / clean abort) or 1 (failure).
|
|
13
14
|
*/
|
|
@@ -15,17 +16,33 @@ import { spawnSync } from 'node:child_process';
|
|
|
15
16
|
import { createHash } from 'node:crypto';
|
|
16
17
|
import {
|
|
17
18
|
cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync,
|
|
18
|
-
rmSync, statSync, writeFileSync,
|
|
19
|
+
rmdirSync, rmSync, statSync, writeFileSync,
|
|
19
20
|
} from 'node:fs';
|
|
20
21
|
import { homedir } from 'node:os';
|
|
21
22
|
import path from 'node:path';
|
|
22
23
|
import { createInterface } from 'node:readline/promises';
|
|
23
24
|
|
|
25
|
+
// Node floor: import.meta.dirname needs Node 20.11+; the supported floor is
|
|
26
|
+
// 22 (package.json engines + README + CI). Fail fast with a clear message
|
|
27
|
+
// instead of a cryptic TypeError on older runtimes.
|
|
28
|
+
const NODE_MAJOR = Number(String(process.versions?.node ?? '').split('.')[0]);
|
|
29
|
+
if (!Number.isInteger(NODE_MAJOR) || NODE_MAJOR < 22) {
|
|
30
|
+
console.error(
|
|
31
|
+
`oc-harness-setup requires Node.js 22 or newer (found ${process.versions?.node ?? 'unknown'}). Install Node 22+ and retry.`
|
|
32
|
+
);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
const PKG_NAME = 'oc-harness-setup';
|
|
25
37
|
const PKG_ROOT = path.resolve(import.meta.dirname, '..');
|
|
26
38
|
const MANIFEST_FILE = 'oc-harness-setup.manifest.json';
|
|
27
|
-
const COPY_DIRS = ['agents', 'commands', 'skills', 'reference', 'scripts', '.docs'];
|
|
28
|
-
const COPY_FILES = ['AGENTS.md', '.gitignore'];
|
|
39
|
+
const COPY_DIRS = ['agents', 'commands', 'skills', 'reference', 'scripts', '.docs', 'state-seed'];
|
|
40
|
+
const COPY_FILES = ['AGENTS.md', 'GLOSSARY.md', '.gitignore'];
|
|
41
|
+
// Source→destination aliases: the pack ships `state-seed/` (tracked) but the
|
|
42
|
+
// live tree owns `state/` (git-ignored runtime), so every incoming
|
|
43
|
+
// `state-seed/...` file lands at `state/...`. `rel` is ALWAYS the
|
|
44
|
+
// destination-relative path — manifest, journal, and logs use it.
|
|
45
|
+
const DIR_ALIASES = { 'state-seed': 'state' };
|
|
29
46
|
// Ownership table for the opencode.jsonc merge. Every top-level key falls into
|
|
30
47
|
// exactly one bucket; there is no "known merge key" list to drift out of date.
|
|
31
48
|
// INSTALL_OWNED — the distro's value wins outright (runtime policy).
|
|
@@ -39,28 +56,33 @@ const COPY_FILES = ['AGENTS.md', '.gitignore'];
|
|
|
39
56
|
// allowlist is deny-then-allows; see mergeJsonc).
|
|
40
57
|
// everything else (known or unknown) — the adopter's value wins; the distro
|
|
41
58
|
// value stays when the adopter does not define the key.
|
|
42
|
-
const INSTALL_OWNED = ['$schema', 'default_agent', 'formatter', 'compaction', 'tool_output', 'media', 'watcher'];
|
|
59
|
+
const INSTALL_OWNED = ['$schema', 'default_agent', 'formatter', 'compaction', 'tool_output', 'media', 'watcher', 'policies'];
|
|
43
60
|
const UNION_KEYS = ['plugins'];
|
|
44
|
-
// Adopter-owned files: shipped
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
61
|
+
// Adopter-owned files: a shipped skeleton that the adopter genuinely edited
|
|
62
|
+
// MUST survive an upgrade — overwriting it destroys their data. Genuineness
|
|
63
|
+
// is proven against the prior manifest (see stageFiles): a destination that
|
|
64
|
+
// still matches the prior installed hash is unmodified pack content and IS
|
|
65
|
+
// updated, so a stock 0.3.3 AGENTS.md is replaced by the V9 contract while a
|
|
66
|
+
// genuinely adopter-edited one is kept.
|
|
67
|
+
const PRESERVE_IF_EXISTS = new Set(['reference/models.md', 'AGENTS.md', '.gitignore', 'state/lessons.md', 'state/template.md']);
|
|
68
|
+
// Leak markers — generic shapes, never a concrete machine. They catch the
|
|
69
|
+
// maintainer's workstation leaking into the shipped tree (an absolute
|
|
70
|
+
// user-profile path, a session id). They are linted against the package
|
|
71
|
+
// source only, never the adopter's config, so a legitimate
|
|
50
72
|
// `{file:~/.secrets/…}` apiKey pointer can never abort an install.
|
|
51
73
|
//
|
|
52
|
-
// Every marker is
|
|
53
|
-
//
|
|
54
|
-
// harness's safety tooling legitimately ships
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
74
|
+
// Every marker is a SHAPE, not a value: a drive letter plus a user-profile
|
|
75
|
+
// path, a session-id token — never the product's own vocabulary. The
|
|
76
|
+
// harness's safety tooling legitimately ships illustrative path fragments
|
|
77
|
+
// and self-test probes, so a bare generic token would abort every correct
|
|
78
|
+
// install; the markers are drawn tight enough to miss them (verified by the
|
|
79
|
+
// packaging audit, which runs these same shapes over the shipped tree).
|
|
80
|
+
// A leak of a concrete workstation path into a secret store is caught by the
|
|
81
|
+
// profile-path marker; a bare `.secrets` cannot distinguish product from
|
|
82
|
+
// author and so is deliberately not a marker.
|
|
60
83
|
const LINT_PATTERNS = [
|
|
61
|
-
{ label: '
|
|
62
|
-
{ label: '
|
|
63
|
-
{ label: 'ses_<id>', test: /ses_[a-z0-9]{16,}/ },
|
|
84
|
+
{ label: 'absolute user path', test: /[a-z]:[\\/]users[\\/]/i },
|
|
85
|
+
{ label: 'session id', test: /ses_[a-z0-9]{16,}/ },
|
|
64
86
|
];
|
|
65
87
|
|
|
66
88
|
/* ------------------------------ tiny helpers ------------------------------ */
|
|
@@ -108,7 +130,8 @@ usage:
|
|
|
108
130
|
oc-harness-setup setup full install (default: no args needed)
|
|
109
131
|
oc-harness-setup --dry-run print the manifest only; touch nothing
|
|
110
132
|
oc-harness-setup --ci print-only, refuse to mutate, exit 0
|
|
111
|
-
oc-harness-setup setup --uninstall remove exactly the manifest-listed files
|
|
133
|
+
oc-harness-setup setup --uninstall remove exactly the manifest-listed files
|
|
134
|
+
oc-harness-setup --version print the package version`);
|
|
112
135
|
}
|
|
113
136
|
|
|
114
137
|
class Bail extends Error {}
|
|
@@ -117,6 +140,17 @@ function bail(msg) {
|
|
|
117
140
|
throw new Bail(msg);
|
|
118
141
|
}
|
|
119
142
|
|
|
143
|
+
// Windows 10/11 only. This installer writes the Windows config home, runs
|
|
144
|
+
// PowerShell doctors, and registers Windows shell policy — there is no
|
|
145
|
+
// macOS/Linux path. --help and --version return from parseArgs before any
|
|
146
|
+
// dispatch, so they keep working everywhere.
|
|
147
|
+
function assertWindows() {
|
|
148
|
+
if (process.platform !== 'win32') {
|
|
149
|
+
bail('Windows 10/11 only — macOS and Linux are not supported.');
|
|
150
|
+
}
|
|
151
|
+
log('platform', 'Windows detected — running the Windows installer path');
|
|
152
|
+
}
|
|
153
|
+
|
|
120
154
|
function sha256(buf) {
|
|
121
155
|
return createHash('sha256').update(buf).digest('hex');
|
|
122
156
|
}
|
|
@@ -211,28 +245,16 @@ function findConfigDir() {
|
|
|
211
245
|
log('config', `env OPENCODE_CONFIG_DIR: ${dir}`);
|
|
212
246
|
return dir;
|
|
213
247
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
log('config', `%USERPROFILE% fallback: ${p}`);
|
|
222
|
-
return p;
|
|
223
|
-
}
|
|
224
|
-
if (env.HOME) {
|
|
225
|
-
const p = path.join(env.HOME, '.config', 'opencode');
|
|
226
|
-
log('config', `$HOME fallback: ${p}`);
|
|
227
|
-
return p;
|
|
228
|
-
}
|
|
229
|
-
const home = homedir();
|
|
230
|
-
if (home) {
|
|
231
|
-
const p = path.join(home, '.config', 'opencode');
|
|
232
|
-
log('config', `os.homedir() fallback: ${p}`);
|
|
248
|
+
// Windows-only target: the live Windows profile owns the config home.
|
|
249
|
+
// There are no XDG/HOME fallbacks — macOS and Linux are not supported
|
|
250
|
+
// (assertWindows bails before any discovery on those platforms).
|
|
251
|
+
const profile = env.USERPROFILE || homedir();
|
|
252
|
+
if (profile) {
|
|
253
|
+
const p = path.resolve(path.join(profile, '.config', 'opencode'));
|
|
254
|
+
log('config', `profile fallback: ${p}`);
|
|
233
255
|
return p;
|
|
234
256
|
}
|
|
235
|
-
bail('could not determine the OpenCode config dir. Set OPENCODE_CONFIG_DIR and re-run.');
|
|
257
|
+
bail('could not determine the OpenCode config dir. Set OPENCODE_CONFIG_DIR and re-run (USERPROFILE is absent).');
|
|
236
258
|
}
|
|
237
259
|
|
|
238
260
|
/* --------------------------- package tree collection ----------------------- */
|
|
@@ -253,13 +275,17 @@ function collectIncoming(configDir) {
|
|
|
253
275
|
log('staging', `note: ${dirName}/ not present in this package — nothing to copy from it`);
|
|
254
276
|
continue;
|
|
255
277
|
}
|
|
256
|
-
walkDir(srcDir, (p) =>
|
|
278
|
+
walkDir(srcDir, (p) => {
|
|
279
|
+
const pkgRel = path.relative(PKG_ROOT, p);
|
|
280
|
+
// Alias the destination: state-seed/lessons.md -> state/lessons.md.
|
|
281
|
+
const top = pkgRel.split(path.sep)[0];
|
|
282
|
+
const rel = DIR_ALIASES[top] ? path.join(DIR_ALIASES[top], pkgRel.slice(top.length + 1)) : pkgRel;
|
|
257
283
|
files.push({
|
|
258
|
-
rel
|
|
284
|
+
rel,
|
|
259
285
|
src: p,
|
|
260
|
-
dest: path.join(configDir,
|
|
261
|
-
})
|
|
262
|
-
);
|
|
286
|
+
dest: path.join(configDir, rel),
|
|
287
|
+
});
|
|
288
|
+
});
|
|
263
289
|
}
|
|
264
290
|
for (const f of COPY_FILES) {
|
|
265
291
|
const src = path.join(PKG_ROOT, f);
|
|
@@ -299,26 +325,66 @@ function nextBackupPath(configDir) {
|
|
|
299
325
|
|
|
300
326
|
/* ------------------------------ staged copy -------------------------------- */
|
|
301
327
|
|
|
302
|
-
function stageFiles(files, manifest) {
|
|
328
|
+
function stageFiles(files, manifest, prior, configDir) {
|
|
329
|
+
// Prior manifests spell paths with either separator; incoming rels use the
|
|
330
|
+
// platform join. Compare on normalized slashes so a prior entry still
|
|
331
|
+
// matches its incoming path (journaling keeps each entry's own spelling).
|
|
332
|
+
const norm = (p) => String(p).replace(/\\/g, '/');
|
|
333
|
+
const priorByPath = new Map(
|
|
334
|
+
(prior && Array.isArray(prior.files) ? prior.files : []).map((f) => [norm(f.path), f])
|
|
335
|
+
);
|
|
303
336
|
let written = 0;
|
|
304
337
|
for (const f of files) {
|
|
305
338
|
const srcHash = sha256File(f.src);
|
|
306
339
|
let action = 'written';
|
|
307
340
|
let prevHash = null;
|
|
341
|
+
let archivedTo = null;
|
|
308
342
|
if (existsSync(f.dest)) {
|
|
309
343
|
const destHash = sha256File(f.dest);
|
|
310
344
|
if (destHash === srcHash) {
|
|
311
345
|
action = 'skip';
|
|
312
346
|
log('staging', `skip ${f.rel} (already identical — rerun-safe)`);
|
|
313
347
|
} else if (PRESERVE_IF_EXISTS.has(f.rel)) {
|
|
314
|
-
|
|
315
|
-
|
|
348
|
+
// Upgrade rule: preserve only a GENUINELY adopter-edited file, i.e.
|
|
349
|
+
// one that differs from the prior manifest hash. A destination that
|
|
350
|
+
// still matches the prior installed hash is unmodified pack content —
|
|
351
|
+
// update it, so a stock 0.3.3 AGENTS.md is replaced by the V9 contract
|
|
352
|
+
// while an adopter-edited AGENTS.md is kept. No prior record means we
|
|
353
|
+
// cannot prove it is stock, so preserve (never destroy unknown data).
|
|
354
|
+
const p = priorByPath.get(norm(f.rel));
|
|
355
|
+
if (p && p.hash && destHash === p.hash) {
|
|
356
|
+
action = 'overwritten';
|
|
357
|
+
prevHash = destHash;
|
|
358
|
+
log('staging', `update ${f.rel} (matches the prior installed hash — unmodified pack content, overwriting; backup + manifest protect you)`);
|
|
359
|
+
} else {
|
|
360
|
+
action = 'preserved';
|
|
361
|
+
log('staging', `preserve ${f.rel} (exists and differs from the prior install — kept; harness will not overwrite adopter-owned files)`);
|
|
362
|
+
}
|
|
316
363
|
} else {
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
364
|
+
// Safe-upgrade rule: a destination the user edited since install
|
|
365
|
+
// (its bytes differ from the prior manifest hash) is archived before
|
|
366
|
+
// the overwrite, so a user-modified 0.3.x file that the new distro
|
|
367
|
+
// still ships — e.g. agents/orchestrator.md — is never silently
|
|
368
|
+
// destroyed. Unmodified pack content (or no prior record) overwrites
|
|
369
|
+
// normally; the pre-install backup still protects it. Files in
|
|
370
|
+
// PRESERVE_IF_EXISTS never reach this branch (kept above, never
|
|
371
|
+
// archived). Same archive root and nextFreePath as retireStale.
|
|
372
|
+
const p = priorByPath.get(norm(f.rel));
|
|
373
|
+
if (p && p.hash && destHash !== p.hash) {
|
|
374
|
+
const dest2 = nextFreePath(path.join(configDir, 'state', 'archive', 'legacy-0.3.x', f.rel));
|
|
375
|
+
mkdirSync(path.dirname(dest2), { recursive: true });
|
|
376
|
+
renameSync(f.dest, dest2);
|
|
377
|
+
archivedTo = path.relative(configDir, dest2);
|
|
378
|
+
action = 'overwritten';
|
|
379
|
+
prevHash = destHash;
|
|
380
|
+
log('staging', `archive ${f.rel} → ${archivedTo} (you edited the old file — pre-upgrade bytes moved aside; writing the new file)`);
|
|
381
|
+
} else {
|
|
382
|
+
// A genuine overwrite: journal it so --uninstall can put the original
|
|
383
|
+
// back from the pre-install backup instead of deleting the harness copy.
|
|
384
|
+
action = 'overwritten';
|
|
385
|
+
prevHash = destHash;
|
|
386
|
+
log('staging', `update ${f.rel} (destination differs — overwriting; backup + manifest protect you)`);
|
|
387
|
+
}
|
|
322
388
|
}
|
|
323
389
|
} else {
|
|
324
390
|
log('staging', `copy ${f.rel}`);
|
|
@@ -333,11 +399,126 @@ function stageFiles(files, manifest) {
|
|
|
333
399
|
// Preserved entries journal the SRC hash on purpose: --uninstall deletes
|
|
334
400
|
// only on an exact match, so a preserved destination (bytes differ from
|
|
335
401
|
// src) reads as modified → kept, not deleted.
|
|
336
|
-
|
|
402
|
+
if (archivedTo) {
|
|
403
|
+
manifest.files.push({ path: f.rel, hash: srcHash, prevHash, action, archivedTo });
|
|
404
|
+
} else if (prevHash) {
|
|
405
|
+
manifest.files.push({ path: f.rel, hash: srcHash, prevHash, action });
|
|
406
|
+
} else {
|
|
407
|
+
manifest.files.push({ path: f.rel, hash: srcHash, action });
|
|
408
|
+
}
|
|
337
409
|
}
|
|
338
410
|
return written;
|
|
339
411
|
}
|
|
340
412
|
|
|
413
|
+
// A prior `skills/<id>/...` path belongs to skill <id>; anything else is not
|
|
414
|
+
// a skill path (null). Used to prune stale skill allowlist entries after an
|
|
415
|
+
// upgrade retires or archives the skill's files.
|
|
416
|
+
function skillIdOf(rel) {
|
|
417
|
+
const parts = String(rel).split(/[\\/]/);
|
|
418
|
+
return parts[0] === 'skills' && parts.length > 2 ? parts[1] : null;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Prune directories left empty, up to (not including) the config dir: a
|
|
422
|
+
// stale empty `skills/old/` would otherwise trip the doctor's skill laws (a
|
|
423
|
+
// directory with no SKILL.md). Non-empty parents (adopter files inside) stop
|
|
424
|
+
// the climb and are kept.
|
|
425
|
+
function pruneEmptyParents(base, dir) {
|
|
426
|
+
while (dir !== base && dir.startsWith(base + path.sep)) {
|
|
427
|
+
let ents;
|
|
428
|
+
try {
|
|
429
|
+
ents = readdirSync(dir);
|
|
430
|
+
} catch {
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
if (ents.length) break;
|
|
434
|
+
try {
|
|
435
|
+
rmdirSync(dir);
|
|
436
|
+
} catch {
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
log('retire', `pruned empty dir ${path.relative(base, dir)} (left empty)`);
|
|
440
|
+
dir = path.dirname(dir);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Upgrade sweep: retire pack files the new distro no longer ships (old agent
|
|
445
|
+
// roster, old skills/commands/references/scripts). Runs BEFORE staging, so a
|
|
446
|
+
// retired path can never collide with an incoming one. Returns the Set of
|
|
447
|
+
// retired skill IDs (missing, retired, or archived) so the merge can prune
|
|
448
|
+
// their stale allowlist entries. For every prior manifest entry NOT in the
|
|
449
|
+
// incoming destination set: `merged` entries (opencode.jsonc) are ignored;
|
|
450
|
+
// anything else is resolved inside the config dir. A destination that is
|
|
451
|
+
// already gone just contributes its skill ID. Unmodified pack content (bytes
|
|
452
|
+
// still equal the prior entry hash) is deleted and journaled as
|
|
453
|
+
// { path, hash, action: 'retired' }. Modified content (the adopter owns the
|
|
454
|
+
// bytes) is MOVED out of the active tree into the runtime-ignored
|
|
455
|
+
// `state/archive/legacy-0.3.x/<rel>` (nextFreePath on collision) and
|
|
456
|
+
// journaled as { path, hash, action: 'archived', archivedTo } — nothing is
|
|
457
|
+
// destroyed. Unreadable entries are kept and the reason is logged.
|
|
458
|
+
// --uninstall restores both kinds from the pre-install backup.
|
|
459
|
+
function retireStale(configDir, prior, files, manifest) {
|
|
460
|
+
const retiredSkills = new Set();
|
|
461
|
+
if (!prior || !Array.isArray(prior.files)) return retiredSkills;
|
|
462
|
+
// Incoming rels use the platform join while a prior manifest may spell the
|
|
463
|
+
// same path with the other separator — compare on normalized slashes so a
|
|
464
|
+
// prior entry that the distro still ships is not mistaken for stale.
|
|
465
|
+
// Journaling keeps each entry's own spelling.
|
|
466
|
+
const norm = (p) => String(p).replace(/\\/g, '/');
|
|
467
|
+
const incoming = new Set(files.map((f) => norm(f.rel)));
|
|
468
|
+
const base = path.resolve(configDir);
|
|
469
|
+
for (const entry of prior.files) {
|
|
470
|
+
const rel = String(entry.path || '');
|
|
471
|
+
if (!rel || incoming.has(norm(rel))) continue;
|
|
472
|
+
if (entry.action === 'merged') continue;
|
|
473
|
+
if (entry.action === 'retired' || entry.action === 'archived') {
|
|
474
|
+
// An earlier run already settled this path; its skill stays pruned.
|
|
475
|
+
const settled = skillIdOf(rel);
|
|
476
|
+
if (settled) retiredSkills.add(settled);
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const resolved = path.resolve(base, rel);
|
|
480
|
+
if (resolved !== base && !resolved.startsWith(base + path.sep)) {
|
|
481
|
+
log('retire', `skip ${rel} (escapes the config dir — refusing)`);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
const skillId = skillIdOf(rel);
|
|
485
|
+
if (!existsSync(resolved)) {
|
|
486
|
+
if (skillId) retiredSkills.add(skillId);
|
|
487
|
+
log('retire', `absent ${rel} (already gone — nothing to retire)`);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
if (!statSync(resolved).isFile()) {
|
|
492
|
+
log('retire', `keep ${rel} (not a file — refusing)`);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
} catch {
|
|
496
|
+
log('retire', `keep ${rel} (unreadable — refusing)`);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
if (entry.hash && sha256File(resolved) === entry.hash) {
|
|
500
|
+
rmSync(resolved, { force: true });
|
|
501
|
+
manifest.files.push({ path: rel, hash: entry.hash, action: 'retired' });
|
|
502
|
+
if (skillId) retiredSkills.add(skillId);
|
|
503
|
+
log('retire', `retired ${rel} (unmodified pack content from the prior install — journaled for uninstall restore)`);
|
|
504
|
+
pruneEmptyParents(base, path.dirname(resolved));
|
|
505
|
+
} else if (entry.hash) {
|
|
506
|
+
const archivedTo = path.join('state', 'archive', 'legacy-0.3.x', rel);
|
|
507
|
+
const dest = nextFreePath(path.join(base, archivedTo));
|
|
508
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
509
|
+
renameSync(resolved, dest);
|
|
510
|
+
const relArchivedTo = path.relative(base, dest);
|
|
511
|
+
manifest.files.push({ path: rel, hash: entry.hash, action: 'archived', archivedTo: relArchivedTo });
|
|
512
|
+
if (skillId) retiredSkills.add(skillId);
|
|
513
|
+
log('retire', `archived ${rel} → ${relArchivedTo} (modified since install — moved out of the active tree; journaled for uninstall restore)`);
|
|
514
|
+
pruneEmptyParents(base, path.dirname(resolved));
|
|
515
|
+
} else {
|
|
516
|
+
log('retire', `keep ${rel} (no prior hash to compare — adopter owns it now)`);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return retiredSkills;
|
|
520
|
+
}
|
|
521
|
+
|
|
341
522
|
/* ---------------------------- opencode.jsonc merge ------------------------- */
|
|
342
523
|
|
|
343
524
|
function stripJsonc(text) {
|
|
@@ -410,7 +591,7 @@ function parseJsonc(text, what) {
|
|
|
410
591
|
}
|
|
411
592
|
}
|
|
412
593
|
|
|
413
|
-
function mergeJsonc(configDir, backupPath, manifest) {
|
|
594
|
+
function mergeJsonc(configDir, backupPath, manifest, retiredSkills = new Set()) {
|
|
414
595
|
const distroPath = path.join(PKG_ROOT, 'opencode.jsonc');
|
|
415
596
|
if (!existsSync(distroPath)) {
|
|
416
597
|
log('merge', 'note: this package ships no opencode.jsonc — no merge to do');
|
|
@@ -463,7 +644,25 @@ function mergeJsonc(configDir, backupPath, manifest) {
|
|
|
463
644
|
const isHardDeny = (p) => !!p && p.effect === 'deny' && p.action !== 'skill';
|
|
464
645
|
const distroHead = distroPerms.filter((p) => !isHardDeny(p));
|
|
465
646
|
const distroTail = distroPerms.filter(isHardDeny);
|
|
466
|
-
|
|
647
|
+
// Stale skill allows die with their skills: an adopter allow for a
|
|
648
|
+
// retired/archived skill would otherwise dangle (Law 14 fails a
|
|
649
|
+
// dangling allow). Custom adopter allows for live skills pass through.
|
|
650
|
+
const droppedStaleAllows = [];
|
|
651
|
+
const userOnly = userPerms.filter((p) => {
|
|
652
|
+
if (distroPerms.some((d) => sameRule(d, p))) return false;
|
|
653
|
+
if (
|
|
654
|
+
p && p.action === 'skill' && p.effect === 'allow' &&
|
|
655
|
+
typeof p.resource === 'string' && p.resource !== '*' &&
|
|
656
|
+
retiredSkills.has(p.resource)
|
|
657
|
+
) {
|
|
658
|
+
droppedStaleAllows.push(p.resource);
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
return true;
|
|
662
|
+
});
|
|
663
|
+
if (droppedStaleAllows.length) {
|
|
664
|
+
log('merge', `dropped stale skill allows for retired skills: ${droppedStaleAllows.join(', ')}`);
|
|
665
|
+
}
|
|
467
666
|
merged.permissions = [...distroHead, ...userOnly, ...distroTail];
|
|
468
667
|
} else if (UNION_KEYS.includes(k)) {
|
|
469
668
|
merged[k] = Array.isArray(user[k])
|
|
@@ -523,50 +722,6 @@ function lintPackagedSource(files) {
|
|
|
523
722
|
return hits;
|
|
524
723
|
}
|
|
525
724
|
|
|
526
|
-
/* ------------------------------- plugin gate ------------------------------- */
|
|
527
|
-
|
|
528
|
-
function registerPlugins() {
|
|
529
|
-
const list = ['oc-flight-deck'];
|
|
530
|
-
for (const p of list) {
|
|
531
|
-
log('plugin', `opencode plugin add ${p}`);
|
|
532
|
-
const res = exec('opencode', ['plugin', 'add', p], false);
|
|
533
|
-
if (res.error || res.status !== 0) {
|
|
534
|
-
log(
|
|
535
|
-
'plugin',
|
|
536
|
-
`'opencode plugin add ${p}' failed (${res.error ? 'not found' : `exit ${res.status}`}) — add it manually later; the config is already installed`
|
|
537
|
-
);
|
|
538
|
-
} else {
|
|
539
|
-
log('plugin', `${p} registered`);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
return list;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// The doctor's Law 6 grades `opencode plugin list`, but right after `plugin
|
|
546
|
-
// add` on a fresh config the registry can lag the file write by minutes - the
|
|
547
|
-
// doctor would grade an empty list and fail. Poll the list (bounded: up to 10
|
|
548
|
-
// attempts, 6 s apart) until every requested name appears in a row, mirroring
|
|
549
|
-
// the doctor's own row-contains-name check. Warning-only on expiry - exit
|
|
550
|
-
// codes are unchanged (the doctor grades; a re-run is idempotent).
|
|
551
|
-
async function waitForPluginRegistration(plugins, configDir) {
|
|
552
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
553
|
-
for (let attempt = 1; attempt <= 10; attempt++) {
|
|
554
|
-
const res = exec('opencode', ['plugin', 'list'], true);
|
|
555
|
-
const rows = (res.stdout || '').split(/\r?\n/).filter((l) => l.trim() !== '');
|
|
556
|
-
const missing = plugins.filter((name) => !rows.some((row) => row.includes(name)));
|
|
557
|
-
const state = res.error || res.status !== 0
|
|
558
|
-
? `list failed (${res.error ? 'not found' : `exit ${res.status}`})`
|
|
559
|
-
: `${rows.length} row(s), missing: ${missing.length ? missing.join(', ') : 'none'}`;
|
|
560
|
-
log('plugin', `registration wait ${attempt}/10 (${configDir}) - ${state}`);
|
|
561
|
-
if (!missing.length) {
|
|
562
|
-
for (const name of plugins) log('plugin', `${name} appears in the registry`);
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
if (attempt < 10) await sleep(6000);
|
|
566
|
-
}
|
|
567
|
-
console.warn(`[plugin] WARNING: plugin registry did not confirm ${plugins.join(', ')} within 60s - the doctor will grade it; re-run setup (idempotent) if it fails`);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
725
|
/* --------------------------------- doctor ---------------------------------- */
|
|
571
726
|
|
|
572
727
|
function pwshProbe() {
|
|
@@ -577,12 +732,12 @@ function pwshProbe() {
|
|
|
577
732
|
function doctorPlan() {
|
|
578
733
|
return pwshProbe().usable
|
|
579
734
|
? 'run scripts/harness-doctor.ps1 via pwsh'
|
|
580
|
-
: 'pwsh missing — doctor SKIPPED,
|
|
735
|
+
: 'pwsh missing — doctor SKIPPED, 18 laws UNVERIFIED (warned + journaled)';
|
|
581
736
|
}
|
|
582
737
|
|
|
583
738
|
function runDoctor(configDir, probe) {
|
|
584
739
|
if (!probe.usable) {
|
|
585
|
-
console.warn('[doctor] WARNING: pwsh (PowerShell 7) was not found — harness-doctor did NOT run, so the
|
|
740
|
+
console.warn('[doctor] WARNING: pwsh (PowerShell 7) was not found — harness-doctor did NOT run, so the 18 laws are UNVERIFIED.');
|
|
586
741
|
console.warn('[doctor] Your config still landed, and the skip is recorded in the manifest. To verify later:');
|
|
587
742
|
console.log(' winget install --id Microsoft.PowerShell --source winget (Windows)');
|
|
588
743
|
console.log(' brew install --cask powershell (macOS)');
|
|
@@ -591,7 +746,7 @@ function runDoctor(configDir, probe) {
|
|
|
591
746
|
}
|
|
592
747
|
const script = path.join(configDir, 'scripts', 'harness-doctor.ps1');
|
|
593
748
|
if (!existsSync(script)) {
|
|
594
|
-
console.warn(`[doctor] WARNING: ${script} not found — harness-doctor did NOT run, so the
|
|
749
|
+
console.warn(`[doctor] WARNING: ${script} not found — harness-doctor did NOT run, so the 18 laws are UNVERIFIED.`);
|
|
595
750
|
return { code: 0, skipped: true };
|
|
596
751
|
}
|
|
597
752
|
log('doctor', `running ${script}`);
|
|
@@ -616,10 +771,12 @@ function printManifest(configDir, files, backupPath, doctor) {
|
|
|
616
771
|
console.log(` destination config dir : ${configDir}`);
|
|
617
772
|
console.log(` incoming files : ${files.length} (${newCount} new, ${sameCount} already identical — rerun-safe)`);
|
|
618
773
|
console.log(` backup path : ${backupPath}`);
|
|
619
|
-
console.log(' opencode.jsonc merge : distro base (permissions/deny block, skill allowlist,');
|
|
774
|
+
console.log(' opencode.jsonc merge : distro base (permissions/deny block, policies block, skill allowlist,');
|
|
620
775
|
console.log(' default_agent: "orchestrator", references registry)');
|
|
621
776
|
console.log(' + your keys kept · permissions: harness allows, yours, harness denies last');
|
|
622
|
-
console.log('
|
|
777
|
+
console.log(' state-seed/ -> state/ : shipped seed maps to live state/ (existing state/lessons.md,');
|
|
778
|
+
console.log(' state/template.md preserved when genuinely edited)');
|
|
779
|
+
console.log(' doctor plan : harness-doctor, 18 laws');
|
|
623
780
|
console.log(` doctor plan : ${doctor}`);
|
|
624
781
|
console.log('----------------------------------------------------------------------------');
|
|
625
782
|
}
|
|
@@ -642,6 +799,7 @@ async function confirmProceed() {
|
|
|
642
799
|
function uninstall(configDir, opts = {}) {
|
|
643
800
|
// F3: --dry-run / --ci preview what would be removed and return 0 without
|
|
644
801
|
// deleting (setup --uninstall --dry-run must touch nothing).
|
|
802
|
+
assertWindows();
|
|
645
803
|
const preview = !!(opts.preview || opts.dryRun || opts.ci);
|
|
646
804
|
const manifestPath = path.join(configDir, MANIFEST_FILE);
|
|
647
805
|
if (!existsSync(manifestPath)) {
|
|
@@ -671,6 +829,62 @@ function uninstall(configDir, opts = {}) {
|
|
|
671
829
|
log('uninstall', `skip ${rel} (escapes the config dir — refusing)`);
|
|
672
830
|
continue;
|
|
673
831
|
}
|
|
832
|
+
if (entry.action === 'retired') {
|
|
833
|
+
// An upgrade retired this path: it is gone from the new distro. If the
|
|
834
|
+
// adopter never recreated it, put the pre-install original back from
|
|
835
|
+
// the backup; if they recreated it, it is theirs now — keep it.
|
|
836
|
+
if (!existsSync(resolved)) {
|
|
837
|
+
const original = backupRoot ? path.join(backupRoot, rel) : null;
|
|
838
|
+
if (original && existsSync(original)) {
|
|
839
|
+
if (preview) {
|
|
840
|
+
restored += 1;
|
|
841
|
+
log('uninstall', `would restore ${rel} (retired by upgrade — your pre-install file, from ${manifest.backupPath})`);
|
|
842
|
+
} else {
|
|
843
|
+
mkdirSync(path.dirname(resolved), { recursive: true });
|
|
844
|
+
cpSync(original, resolved, { force: true });
|
|
845
|
+
restored += 1;
|
|
846
|
+
log('uninstall', `restored ${rel} (retired by upgrade — your pre-install file, from ${manifest.backupPath})`);
|
|
847
|
+
}
|
|
848
|
+
} else {
|
|
849
|
+
missing += 1;
|
|
850
|
+
log('uninstall', `missing ${rel} (retired by upgrade and no backup holds it — nothing to restore)`);
|
|
851
|
+
}
|
|
852
|
+
} else {
|
|
853
|
+
kept += 1;
|
|
854
|
+
log('uninstall', `kept ${rel} (you recreated it after the upgrade retired it — keeping)`);
|
|
855
|
+
}
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
if (entry.action === 'archived') {
|
|
859
|
+
// An upgrade archived this path (you had modified it): the live bytes
|
|
860
|
+
// moved to state/archive/ and the active path went away. If the active
|
|
861
|
+
// path is still absent, put the pre-install original back from the
|
|
862
|
+
// backup; if you recreated it, it is yours now — keep it. Either way
|
|
863
|
+
// the archive path is reported so your bytes stay findable.
|
|
864
|
+
const archivedTo = entry.archivedTo ? String(entry.archivedTo) : null;
|
|
865
|
+
const archiveNote = archivedTo ? ` (your modified bytes live at ${archivedTo})` : '';
|
|
866
|
+
if (!existsSync(resolved)) {
|
|
867
|
+
const original = backupRoot ? path.join(backupRoot, rel) : null;
|
|
868
|
+
if (original && existsSync(original)) {
|
|
869
|
+
if (preview) {
|
|
870
|
+
restored += 1;
|
|
871
|
+
log('uninstall', `would restore ${rel} (archived by upgrade — your pre-install file, from ${manifest.backupPath})${archiveNote}`);
|
|
872
|
+
} else {
|
|
873
|
+
mkdirSync(path.dirname(resolved), { recursive: true });
|
|
874
|
+
cpSync(original, resolved, { force: true });
|
|
875
|
+
restored += 1;
|
|
876
|
+
log('uninstall', `restored ${rel} (archived by upgrade — your pre-install file, from ${manifest.backupPath})${archiveNote}`);
|
|
877
|
+
}
|
|
878
|
+
} else {
|
|
879
|
+
missing += 1;
|
|
880
|
+
log('uninstall', `missing ${rel} (archived by upgrade and no backup holds it — nothing to restore)${archiveNote}`);
|
|
881
|
+
}
|
|
882
|
+
} else {
|
|
883
|
+
kept += 1;
|
|
884
|
+
log('uninstall', `kept ${rel} (you recreated it after the upgrade archived it — keeping)${archiveNote}`);
|
|
885
|
+
}
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
674
888
|
if (!existsSync(resolved)) {
|
|
675
889
|
missing += 1;
|
|
676
890
|
continue;
|
|
@@ -678,8 +892,11 @@ function uninstall(configDir, opts = {}) {
|
|
|
678
892
|
if (entry.action === 'overwritten' || entry.action === 'merged') {
|
|
679
893
|
// A genuine overwrite comes back from the pre-install backup; the merged
|
|
680
894
|
// opencode.jsonc is never deleted — restore the adopter's original, or
|
|
681
|
-
// leave the harness copy in place when no backup holds it.
|
|
895
|
+
// leave the harness copy in place when no backup holds it. An
|
|
896
|
+
// `archivedTo` entry additionally keeps the pre-upgrade bytes in the
|
|
897
|
+
// runtime archive and says so.
|
|
682
898
|
const original = backupRoot ? path.join(backupRoot, rel) : null;
|
|
899
|
+
const archiveNote = entry.archivedTo ? ` (pre-upgrade archive kept at ${entry.archivedTo})` : null;
|
|
683
900
|
if (original && existsSync(original)) {
|
|
684
901
|
// Restoring is only reversible if the bytes being replaced survive. When
|
|
685
902
|
// the current file is not the one the installer wrote (hash differs, or
|
|
@@ -699,11 +916,11 @@ function uninstall(configDir, opts = {}) {
|
|
|
699
916
|
}
|
|
700
917
|
if (preview) {
|
|
701
918
|
restored += 1;
|
|
702
|
-
log('uninstall', `would restore ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
919
|
+
log('uninstall', `would restore ${rel} (your pre-install file, from ${manifest.backupPath})${archiveNote || ''}`);
|
|
703
920
|
} else {
|
|
704
921
|
cpSync(original, resolved, { force: true });
|
|
705
922
|
restored += 1;
|
|
706
|
-
log('uninstall', `restored ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
923
|
+
log('uninstall', `restored ${rel} (your pre-install file, from ${manifest.backupPath})${archiveNote || ''}`);
|
|
707
924
|
}
|
|
708
925
|
} else if (entry.action === 'merged' && entry.hash && sha256File(resolved) === entry.hash) {
|
|
709
926
|
// F5: installer-created merge output (adopter had only opencode.json,
|
|
@@ -751,12 +968,7 @@ function uninstall(configDir, opts = {}) {
|
|
|
751
968
|
console.log(` ${preserved} post-install edit-copy(ies) written beside the restored file(s) as <name>.replaced-<ts> (listed above).`);
|
|
752
969
|
}
|
|
753
970
|
if (manifest.doctorSkipped) {
|
|
754
|
-
console.log(' note: this install skipped the doctor — the
|
|
755
|
-
}
|
|
756
|
-
if (Array.isArray(manifest.plugins) && manifest.plugins.length) {
|
|
757
|
-
console.log(
|
|
758
|
-
` plugins left registered: ${manifest.plugins.join(', ')} — remove with 'opencode plugin remove <name>' if unwanted.`
|
|
759
|
-
);
|
|
971
|
+
console.log(' note: this install skipped the doctor — the 18 laws were never verified.');
|
|
760
972
|
}
|
|
761
973
|
}
|
|
762
974
|
|
|
@@ -776,8 +988,10 @@ function carryForwardJournal(manifest, prior) {
|
|
|
776
988
|
if (!prior || !Array.isArray(prior.files)) return;
|
|
777
989
|
const before = new Map(prior.files.map((f) => [String(f.path), f]));
|
|
778
990
|
for (const e of manifest.files) {
|
|
991
|
+
if (e.action === 'retired' || e.action === 'archived') continue; // a retirement/archive is this run's truth, never downgraded
|
|
779
992
|
const p = before.get(String(e.path));
|
|
780
993
|
if (!p) continue;
|
|
994
|
+
if (p.action === 'retired' || p.action === 'archived') continue; // a path the prior run settled that this run re-ships is fresh staging, not a settlement
|
|
781
995
|
if (p.action === 'overwritten') {
|
|
782
996
|
e.action = 'overwritten';
|
|
783
997
|
e.prevHash = p.prevHash || e.prevHash;
|
|
@@ -785,6 +999,17 @@ function carryForwardJournal(manifest, prior) {
|
|
|
785
999
|
e.action = 'preserved';
|
|
786
1000
|
}
|
|
787
1001
|
}
|
|
1002
|
+
// A re-run must not forget what an earlier run settled: those paths are
|
|
1003
|
+
// already deleted or archived and absent from this run's staging, but
|
|
1004
|
+
// --uninstall still needs them to restore the pre-install originals from
|
|
1005
|
+
// the backup chain.
|
|
1006
|
+
const now = new Set(manifest.files.map((f) => String(f.path)));
|
|
1007
|
+
for (const p of prior.files) {
|
|
1008
|
+
if ((p.action === 'retired' || p.action === 'archived') && !now.has(String(p.path))) {
|
|
1009
|
+
manifest.files.push(p);
|
|
1010
|
+
now.add(String(p.path));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
788
1013
|
}
|
|
789
1014
|
|
|
790
1015
|
function readManifest(configDir) {
|
|
@@ -883,6 +1108,7 @@ function validateJsoncInputs(configDir, backupPath) {
|
|
|
883
1108
|
}
|
|
884
1109
|
|
|
885
1110
|
async function setup(opts) {
|
|
1111
|
+
assertWindows();
|
|
886
1112
|
// F2: --ci / --dry-run promise print-only exit 0 with no mutation — honour
|
|
887
1113
|
// them BEFORE preflight(), which bails without the opencode binary (exactly
|
|
888
1114
|
// the headless case --ci exists for). Read-only manifest path only.
|
|
@@ -917,6 +1143,9 @@ async function setup(opts) {
|
|
|
917
1143
|
}
|
|
918
1144
|
|
|
919
1145
|
const prior = readManifest(configDir); // read-only
|
|
1146
|
+
if (!prior) {
|
|
1147
|
+
console.warn('[warn] no prior install manifest — old 0.3.x files are not auto-retired; review them manually before relying on a clean tree.');
|
|
1148
|
+
}
|
|
920
1149
|
const newBackupPath = nextBackupPath(configDir);
|
|
921
1150
|
// R4(d): a re-run must never re-point the original backup — that snapshot has
|
|
922
1151
|
// already been mutated by the previous install, so restoring from it would be
|
|
@@ -945,24 +1174,18 @@ async function setup(opts) {
|
|
|
945
1174
|
configDir,
|
|
946
1175
|
backupPath: backupPath,
|
|
947
1176
|
...(prior && prior.backupPath ? { priorBackup: backup } : {}),
|
|
948
|
-
plugins: ['oc-flight-deck'],
|
|
949
1177
|
files: [],
|
|
950
1178
|
};
|
|
951
1179
|
|
|
952
|
-
|
|
1180
|
+
const retiredSkills = retireStale(configDir, prior, files, manifest);
|
|
1181
|
+
if (retiredSkills.size) log('retire', `${retiredSkills.size} stale skill id(s) retired — their allowlist entries are pruned from the merge (${[...retiredSkills].join(', ')})`);
|
|
1182
|
+
stageFiles(files, manifest, prior, configDir);
|
|
953
1183
|
carryForwardJournal(manifest, prior);
|
|
954
|
-
//
|
|
955
|
-
//
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
mergeJsonc(configDir, backup, manifest);
|
|
960
|
-
|
|
961
|
-
// Right after a fresh `plugin add` the registry can lag by minutes; wait
|
|
962
|
-
// (bounded) for it to settle so the doctor's Law 6 grades a settled list.
|
|
963
|
-
await waitForPluginRegistration(manifest.plugins, configDir);
|
|
964
|
-
|
|
965
|
-
// R6: record the skip in the journal so "all 16 laws unrun" is never silent.
|
|
1184
|
+
// An adopter's own plugins[] entries survive the merge via UNION_KEYS; the
|
|
1185
|
+
// distro ships no plugins of its own, so there is nothing to register here.
|
|
1186
|
+
mergeJsonc(configDir, backup, manifest, retiredSkills);
|
|
1187
|
+
|
|
1188
|
+
// R6: record the skip in the journal so "all 18 laws unrun" is never silent.
|
|
966
1189
|
manifest.doctorSkipped = !doctorProbe.usable || !existsSync(path.join(configDir, 'scripts', 'harness-doctor.ps1'));
|
|
967
1190
|
writeManifest(configDir, manifest);
|
|
968
1191
|
log('manifest', `journal written: ${path.join(configDir, MANIFEST_FILE)}`);
|
|
@@ -972,11 +1195,10 @@ async function setup(opts) {
|
|
|
972
1195
|
|
|
973
1196
|
console.log();
|
|
974
1197
|
console.log('-------------------------------- summary ---------------------------------');
|
|
975
|
-
console.log(' installed: agents/, commands/, skills/, reference/, scripts/, AGENTS.md + merged opencode.jsonc');
|
|
976
|
-
console.log(' plugins : oc-flight-deck');
|
|
1198
|
+
console.log(' installed: agents/, commands/, skills/, reference/, scripts/, .docs/, state/ (from state-seed/), AGENTS.md, GLOSSARY.md + merged opencode.jsonc');
|
|
977
1199
|
console.log(` backup : ${manifest.backupPath}${manifest.priorBackup ? `\n snapshot : ${manifest.priorBackup} (chained — backup() pointer above is the original)` : ''}`);
|
|
978
1200
|
if (manifest.doctorSkipped) {
|
|
979
|
-
console.log(' doctor : ⚠ SKIPPED — the
|
|
1201
|
+
console.log(' doctor : ⚠ SKIPPED — the 18 laws were NOT verified (journaled as doctorSkipped; install PowerShell 7 and re-run to verify)');
|
|
980
1202
|
}
|
|
981
1203
|
console.log(' undo : npx oc-harness-setup setup --uninstall');
|
|
982
1204
|
console.log(' restart : restart your OpenCode session so the new agents/commands/skills load.');
|
|
@@ -993,6 +1215,11 @@ function parseArgs(argv) {
|
|
|
993
1215
|
case 'setup':
|
|
994
1216
|
opts.command = 'setup';
|
|
995
1217
|
break;
|
|
1218
|
+
case '--version':
|
|
1219
|
+
case '-v':
|
|
1220
|
+
console.log(pkgVersion());
|
|
1221
|
+
process.exitCode = 0;
|
|
1222
|
+
return null;
|
|
996
1223
|
case '--dry-run':
|
|
997
1224
|
opts.dryRun = true;
|
|
998
1225
|
break;
|