oc-harness-setup 0.3.1 โ 0.3.3
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/LICENSE +2 -2
- package/README.md +60 -66
- package/bin/cli.js +175 -31
- package/opencode.jsonc +3 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026 nathwn12
|
|
3
|
+
Copyright (c) 2026 nathan <137482711+nathwn12@users.noreply.github.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,96 +1,90 @@
|
|
|
1
|
-
<
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/icon.svg" width="120" height="120" alt="oc-harness-setup icon" />
|
|
3
|
+
</p>
|
|
4
|
+
<h1 align="center">oc-harness-setup</h1>
|
|
5
|
+
<p align="center"><strong>Install and orchestrate the whole OpenCode harness in one command - PowerShell.</strong></p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="LICENSE"><img src="https://img.shields.io/github/license/nathwn12/oc-harness-setup" alt="License" /></a>
|
|
8
|
+
<img src="https://img.shields.io/github/languages/top/nathwn12/oc-harness-setup" alt="Language" />
|
|
9
|
+
<img src="https://img.shields.io/badge/platform-windows--linux-2b3137" alt="Platform" />
|
|
10
|
+
</p>
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
## What it is
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
*Orchestrator primary . 7 agents . 14 commands . 20 skills . a doctor that proves it.*
|
|
14
|
+
oc-harness-setup is a plug-and-play installer for the whole OpenCode harness. One explicit command lands an orchestrator primary with 7 agents, 14 commands, 20 skills, 18 PowerShell scripts, and a 16-law doctor gate that proves the install. It is a pure Node ESM package with zero runtime dependencies, shipped via npm.
|
|
7
15
|
|
|
8
|
-
|
|
16
|
+
## Why
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
Setting up the harness by hand means copying dozens of files and hoping they agree. This pack makes setup consent-first, idempotent, and verified: the full manifest prints before anything moves, re-runs skip identical files, and every install ends on the harness's own doctor. Installation never modifies config by itself; setup is always an explicit command, never a postinstall.
|
|
11
19
|
|
|
12
|
-
|
|
20
|
+
## Features
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
- One-command setup: `npx --yes oc-harness-setup setup`, then restart OpenCode
|
|
23
|
+
- Consent gate: the full manifest prints before anything moves; `--dry-run` changes nothing
|
|
24
|
+
- Idempotent: re-run anytime, identical files are skipped
|
|
25
|
+
- Verified: ends on the 16-law harness doctor; failures name the check, the detail, and a fix
|
|
26
|
+
- Config-preserving merge: your model, providers, MCP, and plugins survive; runtime policy is owned by the pack
|
|
27
|
+
- Fail-closed permissions: the deny set survives `--auto`, skills load from an exact allowlist
|
|
28
|
+
- Reversible: a SHA-256 journal records every touched file; `--uninstall` restores from backup
|
|
29
|
+
- Zero runtime dependencies: pure Node ESM, stdlib only
|
|
15
30
|
|
|
16
|
-
|
|
17
|
-
Install oc-harness-setup:
|
|
18
|
-
1. Run: npx --yes oc-harness-setup setup
|
|
19
|
-
2. Restart OpenCode.
|
|
20
|
-
3. Verify: pwsh -File ~/.config/opencode/scripts/harness-doctor.ps1
|
|
21
|
-
```
|
|
31
|
+
## Install
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
1. Run the installer: `npx --yes oc-harness-setup setup`
|
|
34
|
+
2. Restart OpenCode.
|
|
35
|
+
3. Verify: `pwsh -File ~/.config/opencode/scripts/harness-doctor.ps1`
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
Requires Node >= 22. The doctor gate needs PowerShell 7; where it is missing, laws are reported as skipped, not passed.
|
|
28
38
|
|
|
29
|
-
|
|
39
|
+
## Usage
|
|
30
40
|
|
|
31
|
-
|
|
41
|
+
Preview without touching a file:
|
|
32
42
|
|
|
33
|
-
```
|
|
34
|
-
|
|
43
|
+
```bash
|
|
44
|
+
npx --yes oc-harness-setup setup --dry-run
|
|
35
45
|
```
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
- **Idempotent** - re-run anytime; identical files are skipped
|
|
39
|
-
- **Verified** - ends on the harness's own 16-law doctor; red = nonzero exit, with every failing law naming the check, the detail, and a proposed fix. The doctor needs PowerShell 7: if it is missing, the laws are **skipped** and reported as skipped - not passed
|
|
40
|
-
|
|
41
|
-
> *Installation never modifies your config by itself - setup is always an explicit command you run. **No postinstall, ever.***
|
|
42
|
-
|
|
43
|
-
### ๐ฆ What you get
|
|
44
|
-
|
|
45
|
-
| Component | What it gives you |
|
|
46
|
-
|:---|:---|
|
|
47
|
-
| ๐ง **Orchestrator** | dispatch tiers, parallel waves, fan-in reduction, one question per close |
|
|
48
|
-
| ๐ค **7 agents** | orchestrator . plan . build . explore . general . reviewer . vault (secrets by pointer) |
|
|
49
|
-
| โจ๏ธ **14 commands** | build . checkpoint . code-simplify . gauntlet . handoff . keeper . kill . plan . retro . review . ship . spec . test . webperf |
|
|
50
|
-
| ๐งช **20 skills** | git ceremony . TDD . debugging . security . performance . test-flight . flight-deck . ... |
|
|
51
|
-
| ๐ฉบ **The doctor** | 16 self-derived laws; green = consistent, regressions != drift (runs as an installer-integrated gate, not a command) |
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## โ๏ธ Configure
|
|
47
|
+
Install for real:
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
|
|
62
|
-
## ๐ก๏ธ Safety
|
|
63
|
-
|
|
64
|
-
> Strict deny-set permissions that survive `--auto` . skills fail closed on unknown IDs . credentials stay by pointer . backup before any change.
|
|
65
|
-
|
|
66
|
-
### Policy
|
|
67
|
-
|
|
68
|
-
This package ships a **fail-closed permission set**: the disk-destroy and credential denies hold even under `--auto`, and skills load only from an exact allowlist - an unknown skill ID is denied, not loaded. The author's own live harness runs permission-free; the guardrails here are intentional, kept for adopters who want the safety net. Rogue-session and housekeeping machinery ships too: `/kill` (with `scripts/interrupt-session.ps1`) stops a runaway session, and `scripts/gc-clean.ps1` sweeps junk with a dry-run default. Adopters who prefer the author's freer setup can relax or remove the deny entries in the merged opencode.jsonc, with one caveat: the installer's merge re-applies the harness's deny entries on every install run - the deny tail is always placed after your rules, and under last-match-wins a re-added deny outranks any relaxation you added. To keep relaxed permissions, remove the deny entries from the merged opencode.jsonc and do not re-run setup afterwards.
|
|
69
|
-
|
|
70
|
-
---
|
|
49
|
+
```bash
|
|
50
|
+
npx --yes oc-harness-setup setup
|
|
51
|
+
```
|
|
71
52
|
|
|
72
|
-
|
|
53
|
+
Remove everything the installer created and restore overwritten files from backup:
|
|
73
54
|
|
|
74
55
|
```bash
|
|
75
56
|
npx --yes oc-harness-setup setup --uninstall
|
|
76
57
|
```
|
|
77
58
|
|
|
78
|
-
|
|
59
|
+
## Build from source
|
|
79
60
|
|
|
80
|
-
|
|
61
|
+
Prerequisites: Node >= 22 and Bun (for the test suite). No build step: pure Node ESM, stdlib only.
|
|
81
62
|
|
|
82
|
-
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/nathwn12/oc-harness-setup.git
|
|
65
|
+
cd oc-harness-setup
|
|
66
|
+
npm test
|
|
67
|
+
npm run check
|
|
68
|
+
```
|
|
83
69
|
|
|
84
|
-
|
|
70
|
+
## Docs
|
|
85
71
|
|
|
86
|
-
|
|
72
|
+
- [AGENTS.md](AGENTS.md) โ the harness contract the installer ships
|
|
73
|
+
- [reference/](reference/) โ harness references: dispatch, lifecycle, models, session state
|
|
74
|
+
- [.docs/unwired-routing.md](.docs/unwired-routing.md) โ unwired routing notes
|
|
87
75
|
|
|
88
|
-
##
|
|
76
|
+
## Status
|
|
89
77
|
|
|
90
|
-
|
|
78
|
+
**Unverified** โ as-is, use at your own risk.
|
|
91
79
|
|
|
92
|
-
|
|
80
|
+
## License
|
|
93
81
|
|
|
94
|
-
|
|
82
|
+
MIT โ see [LICENSE](LICENSE).
|
|
95
83
|
|
|
96
|
-
|
|
84
|
+
<!-- nathwn12 house footer: identical in every repo. Do not edit. -->
|
|
85
|
+
<p align="center">
|
|
86
|
+
<a href="https://github.com/nathwn12"><img src="assets/signature.svg" width="96" alt="nathwn12" /></a>
|
|
87
|
+
</p>
|
|
88
|
+
<p align="center">
|
|
89
|
+
<sub>Built by <a href="https://github.com/nathwn12">nathwn12</a> ยท <a href="https://github.com/nathwn12?tab=repositories">All projects</a></sub>
|
|
90
|
+
</p>
|
package/bin/cli.js
CHANGED
|
@@ -49,14 +49,14 @@ const PRESERVE_IF_EXISTS = new Set(['reference/models.md', 'reference/owner-pin.
|
|
|
49
49
|
// package source only, never the adopter's config, so a legitimate
|
|
50
50
|
// `{file:~/.secrets/โฆ}` apiKey pointer can never abort an install.
|
|
51
51
|
//
|
|
52
|
-
// Every marker is anchored to the
|
|
53
|
-
//
|
|
52
|
+
// Every marker is anchored to the author's concrete machine โ a drive
|
|
53
|
+
// letter, a username, a real session id โ never to the product's own vocabulary. The
|
|
54
54
|
// harness's safety tooling legitimately ships the generic forms
|
|
55
55
|
// (`C:\Users\<name>`, `ses_<id>`, `~/.secrets/โฆ` โ redactor regexes and their
|
|
56
56
|
// self-test probes), so a bare generic token would abort every correct install.
|
|
57
57
|
// A leak of an author path into a secret store is caught by the username/drive
|
|
58
58
|
// markers; a bare `.secrets` cannot distinguish product from author and so is
|
|
59
|
-
// deliberately not a marker.
|
|
59
|
+
// deliberately not a marker. The username marker also subsumes the full profile path.
|
|
60
60
|
const LINT_PATTERNS = [
|
|
61
61
|
{ label: 'q:\\', test: /q:\\/ },
|
|
62
62
|
{ label: 'nathan', test: /nathan/ },
|
|
@@ -79,6 +79,28 @@ function nextFreePath(base) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
// F4: atomic file replace โ rename dest aside, rename tmp into place, then
|
|
83
|
+
// delete the aside copy (restoring the aside copy if the middle step throws).
|
|
84
|
+
// Closes the rm-then-rename window where a crash left the user's file DELETED
|
|
85
|
+
// with the new copy orphaned as tmp.
|
|
86
|
+
function atomicInstall(tmp, dest) {
|
|
87
|
+
if (!existsSync(dest)) {
|
|
88
|
+
renameSync(tmp, dest);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const aside = nextFreePath(`${dest}.oc-harness-setup-aside-${process.pid}`);
|
|
92
|
+
renameSync(dest, aside);
|
|
93
|
+
try {
|
|
94
|
+
renameSync(tmp, dest);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
try {
|
|
97
|
+
renameSync(aside, dest);
|
|
98
|
+
} catch {}
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
rmSync(aside, { force: true });
|
|
102
|
+
}
|
|
103
|
+
|
|
82
104
|
function usage() {
|
|
83
105
|
console.log(`oc-harness-setup โ install the OpenCode harness into your config dir.
|
|
84
106
|
|
|
@@ -165,6 +187,10 @@ function findConfigDir() {
|
|
|
165
187
|
dir = path.join(homedir(), dir.slice(2));
|
|
166
188
|
}
|
|
167
189
|
if (dir) {
|
|
190
|
+
// F7: opencode echoes OPENCODE_CONFIG_DIR verbatim, so a relative
|
|
191
|
+
// value arrives here still relative โ resolve to absolute so the
|
|
192
|
+
// manifest records a cwd-independent destination.
|
|
193
|
+
dir = path.resolve(dir);
|
|
168
194
|
log('config', `resolved via 'opencode debug paths': ${dir}`);
|
|
169
195
|
return dir;
|
|
170
196
|
}
|
|
@@ -174,8 +200,16 @@ function findConfigDir() {
|
|
|
174
200
|
}
|
|
175
201
|
const env = process.env;
|
|
176
202
|
if (env.OPENCODE_CONFIG_DIR) {
|
|
177
|
-
|
|
178
|
-
|
|
203
|
+
// F7: resolve verbatim env (relative โ cwd-dependent) to absolute and
|
|
204
|
+
// expand a leading ~, mirroring the debug-paths branch.
|
|
205
|
+
let dir = String(env.OPENCODE_CONFIG_DIR).trim().replace(/^["']|["']$/g, '');
|
|
206
|
+
if (dir === '~' || (dir.startsWith('~') && (dir[1] === '/' || dir[1] === '\\'))) {
|
|
207
|
+
dir = path.join(homedir(), dir.length > 1 ? dir.slice(2) : '');
|
|
208
|
+
} else {
|
|
209
|
+
dir = path.resolve(dir);
|
|
210
|
+
}
|
|
211
|
+
log('config', `env OPENCODE_CONFIG_DIR: ${dir}`);
|
|
212
|
+
return dir;
|
|
179
213
|
}
|
|
180
214
|
if (env.XDG_CONFIG_HOME) {
|
|
181
215
|
const p = path.join(env.XDG_CONFIG_HOME, 'opencode');
|
|
@@ -293,8 +327,7 @@ function stageFiles(files, manifest) {
|
|
|
293
327
|
mkdirSync(path.dirname(f.dest), { recursive: true });
|
|
294
328
|
const tmp = `${f.dest}.oc-harness-setup-tmp-${process.pid}`;
|
|
295
329
|
writeFileSync(tmp, readFileSync(f.src));
|
|
296
|
-
|
|
297
|
-
renameSync(tmp, f.dest);
|
|
330
|
+
atomicInstall(tmp, f.dest);
|
|
298
331
|
written += 1;
|
|
299
332
|
}
|
|
300
333
|
// Preserved entries journal the SRC hash on purpose: --uninstall deletes
|
|
@@ -461,8 +494,7 @@ function mergeJsonc(configDir, backupPath, manifest) {
|
|
|
461
494
|
mkdirSync(configDir, { recursive: true });
|
|
462
495
|
const tmp = `${targetPath}.oc-harness-setup-tmp-${process.pid}`;
|
|
463
496
|
writeFileSync(tmp, out);
|
|
464
|
-
|
|
465
|
-
renameSync(tmp, targetPath);
|
|
497
|
+
atomicInstall(tmp, targetPath);
|
|
466
498
|
manifest.files.push({ path: 'opencode.jsonc', hash: sha256Text(out), action: 'merged' });
|
|
467
499
|
log(
|
|
468
500
|
'merge',
|
|
@@ -607,7 +639,10 @@ async function confirmProceed() {
|
|
|
607
639
|
|
|
608
640
|
/* -------------------------------- uninstall -------------------------------- */
|
|
609
641
|
|
|
610
|
-
function uninstall(configDir) {
|
|
642
|
+
function uninstall(configDir, opts = {}) {
|
|
643
|
+
// F3: --dry-run / --ci preview what would be removed and return 0 without
|
|
644
|
+
// deleting (setup --uninstall --dry-run must touch nothing).
|
|
645
|
+
const preview = !!(opts.preview || opts.dryRun || opts.ci);
|
|
611
646
|
const manifestPath = path.join(configDir, MANIFEST_FILE);
|
|
612
647
|
if (!existsSync(manifestPath)) {
|
|
613
648
|
bail(
|
|
@@ -652,31 +687,63 @@ function uninstall(configDir) {
|
|
|
652
687
|
// the restore overwrites it. Byte-identical installer output needs no
|
|
653
688
|
// copy.
|
|
654
689
|
if (!entry.hash || sha256File(resolved) !== entry.hash) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
690
|
+
if (preview) {
|
|
691
|
+
preserved += 1;
|
|
692
|
+
log('uninstall', `would keep ${path.relative(base, nextFreePath(`${resolved}.replaced-${tsStamp()}`))} (your post-install edits โ would copy before restore)`);
|
|
693
|
+
} else {
|
|
694
|
+
const keep = nextFreePath(`${resolved}.replaced-${tsStamp()}`);
|
|
695
|
+
cpSync(resolved, keep);
|
|
696
|
+
preserved += 1;
|
|
697
|
+
log('uninstall', `kept ${path.relative(base, keep)} (your post-install edits โ copied before restore)`);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (preview) {
|
|
701
|
+
restored += 1;
|
|
702
|
+
log('uninstall', `would restore ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
703
|
+
} else {
|
|
704
|
+
cpSync(original, resolved, { force: true });
|
|
705
|
+
restored += 1;
|
|
706
|
+
log('uninstall', `restored ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
707
|
+
}
|
|
708
|
+
} else if (entry.action === 'merged' && entry.hash && sha256File(resolved) === entry.hash) {
|
|
709
|
+
// F5: installer-created merge output (adopter had only opencode.json,
|
|
710
|
+
// so no backup holds opencode.jsonc) still hashes to what was written
|
|
711
|
+
// โ it is pure installer output, so delete it; keep only user-modified.
|
|
712
|
+
if (preview) {
|
|
713
|
+
removed += 1;
|
|
714
|
+
log('uninstall', `would remove ${rel} (installer-created merge output โ no pre-install file to restore)`);
|
|
715
|
+
} else {
|
|
716
|
+
rmSync(resolved, { force: true });
|
|
717
|
+
removed += 1;
|
|
718
|
+
log('uninstall', `removed ${rel} (installer-created merge output โ no pre-install file to restore)`);
|
|
659
719
|
}
|
|
660
|
-
cpSync(original, resolved, { force: true });
|
|
661
|
-
restored += 1;
|
|
662
|
-
log('uninstall', `restored ${rel} (your pre-install file, from ${manifest.backupPath})`);
|
|
663
720
|
} else {
|
|
664
721
|
kept += 1;
|
|
665
|
-
log('uninstall',
|
|
722
|
+
log('uninstall', `${preview ? 'would keep' : 'kept '} ${rel} (WARNING: no backup at ${original || '(no backupPath recorded)'} โ not deleted)`);
|
|
666
723
|
}
|
|
667
724
|
continue;
|
|
668
725
|
}
|
|
669
726
|
if (entry.hash && sha256File(resolved) === entry.hash) {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
727
|
+
if (preview) {
|
|
728
|
+
removed += 1;
|
|
729
|
+
log('uninstall', `would remove ${rel}`);
|
|
730
|
+
} else {
|
|
731
|
+
rmSync(resolved, { force: true });
|
|
732
|
+
removed += 1;
|
|
733
|
+
log('uninstall', `removed ${rel}`);
|
|
734
|
+
}
|
|
673
735
|
} else {
|
|
674
736
|
kept += 1;
|
|
675
737
|
log('uninstall', `kept ${rel} (you modified it โ hash differs)`);
|
|
676
738
|
}
|
|
677
739
|
}
|
|
678
|
-
|
|
679
|
-
|
|
740
|
+
if (preview) {
|
|
741
|
+
log('uninstall', `would remove ${removed}, would restore ${restored} overwritten, would keep ${kept} modified, preserved ${preserved} edit-copies, already-missing ${missing}`);
|
|
742
|
+
console.log('[dry-run] preview only โ nothing was touched.');
|
|
743
|
+
} else {
|
|
744
|
+
rmSync(manifestPath, { force: true });
|
|
745
|
+
log('uninstall', `removed ${removed}, restored ${restored} overwritten, kept ${kept} modified, preserved ${preserved} edit-copies, already-missing ${missing}`);
|
|
746
|
+
}
|
|
680
747
|
console.log(` backup (pre-install config dir): ${manifest.backupPath || '(none recorded)'}`);
|
|
681
748
|
if (manifest.priorBackup) console.log(` later snapshot (kept for the chain): ${manifest.priorBackup}`);
|
|
682
749
|
console.log(' to restore it fully, replace the current config dir with that backup.');
|
|
@@ -758,7 +825,81 @@ function warnConfigTargets(configDir) {
|
|
|
758
825
|
}
|
|
759
826
|
}
|
|
760
827
|
|
|
828
|
+
// F6: sweep installer crash litter (*.oc-harness-setup-tmp-*) left if killed
|
|
829
|
+
// between writeFileSync and renameSync. The infix `.oc-harness-setup-tmp-`
|
|
830
|
+
// never appears in real user files (opencode.jsonc, agents/*.md, โฆ), so the
|
|
831
|
+
// sweep is unambiguous installer junk. Runs only on the mutating path (never
|
|
832
|
+
// under --dry-run / --ci, which promise to touch nothing).
|
|
833
|
+
function sweepTmpLitter(configDir) {
|
|
834
|
+
if (!existsSync(configDir)) return 0;
|
|
835
|
+
try {
|
|
836
|
+
if (!statSync(configDir).isDirectory()) return 0;
|
|
837
|
+
} catch {
|
|
838
|
+
return 0;
|
|
839
|
+
}
|
|
840
|
+
let swept = 0;
|
|
841
|
+
const walk = (dir) => {
|
|
842
|
+
let ents;
|
|
843
|
+
try {
|
|
844
|
+
ents = readdirSync(dir, { withFileTypes: true });
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
for (const ent of ents) {
|
|
849
|
+
const p = path.join(dir, ent.name);
|
|
850
|
+
if (ent.isDirectory()) walk(p);
|
|
851
|
+
else if (ent.name.includes('.oc-harness-setup-tmp-')) {
|
|
852
|
+
try {
|
|
853
|
+
rmSync(p, { force: true });
|
|
854
|
+
swept += 1;
|
|
855
|
+
log('sweep', `removed crash litter ${path.relative(configDir, p)}`);
|
|
856
|
+
} catch {}
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
walk(configDir);
|
|
861
|
+
return swept;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// F1: validate every JSONC parse BEFORE any write, so a broken config bails
|
|
865
|
+
// before staging overwrites live files (no manifest => uninstall could not restore).
|
|
866
|
+
function validateJsoncInputs(configDir, backupPath) {
|
|
867
|
+
const distroPath = path.join(PKG_ROOT, 'opencode.jsonc');
|
|
868
|
+
if (existsSync(distroPath)) {
|
|
869
|
+
parseJsonc(
|
|
870
|
+
readFileSync(distroPath, 'utf8'),
|
|
871
|
+
'the shipped opencode.jsonc (this package build looks broken)'
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
const targetPath = path.join(configDir, 'opencode.jsonc');
|
|
875
|
+
const jsonPath = path.join(configDir, 'opencode.json');
|
|
876
|
+
const sourcePath = existsSync(targetPath) ? targetPath : existsSync(jsonPath) ? jsonPath : null;
|
|
877
|
+
if (sourcePath) {
|
|
878
|
+
parseJsonc(
|
|
879
|
+
readFileSync(sourcePath, 'utf8'),
|
|
880
|
+
`your existing ${path.basename(sourcePath)} โ aborting before any write; your config is untouched (backup: ${backupPath})`
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
761
885
|
async function setup(opts) {
|
|
886
|
+
// F2: --ci / --dry-run promise print-only exit 0 with no mutation โ honour
|
|
887
|
+
// them BEFORE preflight(), which bails without the opencode binary (exactly
|
|
888
|
+
// the headless case --ci exists for). Read-only manifest path only.
|
|
889
|
+
if (opts.ci || opts.dryRun) {
|
|
890
|
+
const configDir = findConfigDir();
|
|
891
|
+
const files = collectIncoming(configDir);
|
|
892
|
+
const prior = readManifest(configDir); // read-only
|
|
893
|
+
const newBackupPath = nextBackupPath(configDir);
|
|
894
|
+
const backupPath = prior && prior.backupPath ? prior.backupPath : newBackupPath;
|
|
895
|
+
printManifest(configDir, files, backupPath, doctorPlan());
|
|
896
|
+
if (opts.dryRun) {
|
|
897
|
+
console.log('[dry-run] manifest only โ nothing was touched.');
|
|
898
|
+
return 0;
|
|
899
|
+
}
|
|
900
|
+
console.log('[ci] refusing to mutate โ print-only. Run setup interactively to install.');
|
|
901
|
+
return 0;
|
|
902
|
+
}
|
|
762
903
|
preflight();
|
|
763
904
|
const configDir = findConfigDir();
|
|
764
905
|
warnConfigTargets(configDir);
|
|
@@ -784,20 +925,18 @@ async function setup(opts) {
|
|
|
784
925
|
const doctorProbe = pwshProbe(); // read-only probe
|
|
785
926
|
printManifest(configDir, files, backupPath, doctorPlan());
|
|
786
927
|
|
|
787
|
-
|
|
788
|
-
console.log('[dry-run] manifest only โ nothing was touched.');
|
|
789
|
-
return 0;
|
|
790
|
-
}
|
|
791
|
-
if (opts.ci) {
|
|
792
|
-
console.log('[ci] refusing to mutate โ print-only. Run setup interactively to install.');
|
|
793
|
-
return 0;
|
|
794
|
-
}
|
|
928
|
+
// (F2: --dry-run / --ci already returned print-only before preflight.)
|
|
795
929
|
if (!(await confirmProceed())) {
|
|
796
930
|
console.log('[gate] aborted โ nothing was modified.');
|
|
797
931
|
return 0;
|
|
798
932
|
}
|
|
799
933
|
|
|
800
934
|
/* ---------------- mutations begin (all journaled) ---------------- */
|
|
935
|
+
// F1: every parse validated BEFORE the first write โ a broken config bails
|
|
936
|
+
// here, before staging overwrites live files.
|
|
937
|
+
validateJsoncInputs(configDir, backupPath);
|
|
938
|
+
// F6: sweep unambiguous installer crash litter before the first write.
|
|
939
|
+
sweepTmpLitter(configDir);
|
|
801
940
|
const backup = makeBackup(configDir, newBackupPath);
|
|
802
941
|
const manifest = {
|
|
803
942
|
package: PKG_NAME,
|
|
@@ -882,6 +1021,11 @@ async function main() {
|
|
|
882
1021
|
if (!opts) return;
|
|
883
1022
|
if (opts.uninstall) {
|
|
884
1023
|
const configDir = findConfigDir();
|
|
1024
|
+
// F3: honour --dry-run / --ci in the uninstall branch โ preview only.
|
|
1025
|
+
if (opts.dryRun || opts.ci) {
|
|
1026
|
+
uninstall(configDir, { preview: true });
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
885
1029
|
uninstall(configDir);
|
|
886
1030
|
return;
|
|
887
1031
|
}
|
package/opencode.jsonc
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// model/providers/mcp/plugins.
|
|
8
8
|
"$schema": "https://opencode.ai/config.json",
|
|
9
9
|
"default_agent": "orchestrator",
|
|
10
|
-
|
|
10
|
+
// Formatting OFF (measured 2026-10-14): an object value ENABLES every built-in
|
|
11
|
+
// (off by default); a formatter silently rewrites bytes after write/edit/patch, so `cargo fmt` / `ruff format` stay manual.
|
|
12
|
+
"formatter": false,
|
|
11
13
|
"compaction": {
|
|
12
14
|
"auto": true,
|
|
13
15
|
"keep": {
|