oc-harness-setup 0.1.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.
Files changed (67) hide show
  1. package/AGENTS.md +106 -0
  2. package/LICENSE +21 -0
  3. package/README.md +67 -0
  4. package/agents/build.md +22 -0
  5. package/agents/coder.md +19 -0
  6. package/agents/documenter.md +28 -0
  7. package/agents/explore.md +20 -0
  8. package/agents/general.md +21 -0
  9. package/agents/keeper.md +22 -0
  10. package/agents/master.md +68 -0
  11. package/agents/plan.md +32 -0
  12. package/agents/researcher.md +21 -0
  13. package/agents/reviewer.md +27 -0
  14. package/agents/security-auditor.md +20 -0
  15. package/agents/test-engineer.md +20 -0
  16. package/agents/vault.md +64 -0
  17. package/agents/web-performance-auditor.md +19 -0
  18. package/bin/cli.js +641 -0
  19. package/commands/build.md +13 -0
  20. package/commands/checkpoint.md +5 -0
  21. package/commands/code-simplify.md +13 -0
  22. package/commands/council.md +24 -0
  23. package/commands/doctor.md +18 -0
  24. package/commands/handoff.md +5 -0
  25. package/commands/keeper.md +7 -0
  26. package/commands/plan.md +18 -0
  27. package/commands/ponytail-audit.md +7 -0
  28. package/commands/ponytail-debt.md +14 -0
  29. package/commands/review.md +7 -0
  30. package/commands/ship.md +31 -0
  31. package/commands/spec.md +15 -0
  32. package/commands/test.md +14 -0
  33. package/opencode.jsonc +427 -0
  34. package/package.json +45 -0
  35. package/reference/README.md +18 -0
  36. package/reference/model-keeper.md +26 -0
  37. package/reference/model-test.md +171 -0
  38. package/reference/models.md.example +21 -0
  39. package/scripts/harness-doctor.ps1 +964 -0
  40. package/scripts/panic/panic.ts +240 -0
  41. package/skills/_shared/SOURCES.md +26 -0
  42. package/skills/_shared/references/accessibility-checklist.md +160 -0
  43. package/skills/_shared/references/definition-of-done.md +67 -0
  44. package/skills/_shared/references/observability-checklist.md +92 -0
  45. package/skills/_shared/references/orchestration-patterns.md +156 -0
  46. package/skills/_shared/references/performance-checklist.md +236 -0
  47. package/skills/_shared/references/security-checklist.md +245 -0
  48. package/skills/_shared/references/testing-patterns.md +235 -0
  49. package/skills/api-and-interface-design/SKILL.md +367 -0
  50. package/skills/code-review-and-quality/SKILL.md +396 -0
  51. package/skills/code-simplification/SKILL.md +371 -0
  52. package/skills/creative-writing/SKILL.md +96 -0
  53. package/skills/debugging-and-error-recovery/SKILL.md +316 -0
  54. package/skills/frontend-ui-engineering/SKILL.md +328 -0
  55. package/skills/git-ceremony/SKILL.md +329 -0
  56. package/skills/grilling/SKILL.md +38 -0
  57. package/skills/incremental-implementation/SKILL.md +249 -0
  58. package/skills/observability-and-instrumentation/SKILL.md +238 -0
  59. package/skills/performance-optimization/SKILL.md +496 -0
  60. package/skills/planning-and-task-breakdown/SKILL.md +257 -0
  61. package/skills/security-and-hardening/SKILL.md +499 -0
  62. package/skills/source-driven-development/SKILL.md +216 -0
  63. package/skills/spec-driven-development/SKILL.md +245 -0
  64. package/skills/swarm-orchestration/SKILL.md +54 -0
  65. package/skills/test-driven-development/SKILL.md +398 -0
  66. package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  67. package/skills/writing-for-agents/SKILL.md +83 -0
package/bin/cli.js ADDED
@@ -0,0 +1,641 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * oc-harness-setup — installer engine. Pure Node ESM, stdlib only, ZERO dependencies.
4
+ *
5
+ * Subcommands / flags:
6
+ * setup full install (default when no args)
7
+ * --dry-run print the install manifest, touch nothing
8
+ * --ci refuse to mutate: print the manifest, exit 0
9
+ * setup --uninstall delete exactly the manifest-listed files, keep
10
+ * user-modified ones, print the backup restore path
11
+ * --fleet also register the oc-freedom-fleet plugin
12
+ *
13
+ * Exit codes are strictly 0 (ok / clean abort) or 1 (failure).
14
+ */
15
+ import { spawnSync } from 'node:child_process';
16
+ import { createHash } from 'node:crypto';
17
+ import {
18
+ cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync,
19
+ rmSync, statSync, writeFileSync,
20
+ } from 'node:fs';
21
+ import { homedir } from 'node:os';
22
+ import path from 'node:path';
23
+ import { createInterface } from 'node:readline/promises';
24
+
25
+ const PKG_NAME = 'oc-harness-setup';
26
+ const PKG_ROOT = path.resolve(import.meta.dirname, '..');
27
+ const MANIFEST_FILE = 'oc-harness-setup.manifest.json';
28
+ const COPY_DIRS = ['agents', 'commands', 'skills', 'reference', 'scripts'];
29
+ const COPY_FILES = ['AGENTS.md'];
30
+ const MERGE_KEYS = ['model', 'providers', 'mcp', 'plugins'];
31
+ const LINT_PATTERNS = ['c:\\users', 'q:\\', 'nathan', 'ses_', '.secrets'];
32
+
33
+ /* ------------------------------ tiny helpers ------------------------------ */
34
+
35
+ function log(label, msg) {
36
+ console.log(`[${label}] ${msg}`);
37
+ }
38
+
39
+ function usage() {
40
+ console.log(`oc-harness-setup — install the OpenCode harness into your config dir.
41
+
42
+ usage:
43
+ oc-harness-setup setup full install (default: no args needed)
44
+ oc-harness-setup --dry-run print the manifest only; touch nothing
45
+ oc-harness-setup --ci print-only, refuse to mutate, exit 0
46
+ oc-harness-setup setup --uninstall remove exactly the manifest-listed files
47
+ oc-harness-setup setup --fleet also register plugin oc-freedom-fleet`);
48
+ }
49
+
50
+ class Bail extends Error {}
51
+ function bail(msg) {
52
+ console.error(`[error] ${msg}`);
53
+ throw new Bail(msg);
54
+ }
55
+
56
+ function sha256(buf) {
57
+ return createHash('sha256').update(buf).digest('hex');
58
+ }
59
+ const sha256File = (p) => sha256(readFileSync(p));
60
+ const sha256Text = (s) => sha256(Buffer.from(s, 'utf8'));
61
+
62
+ function tsStamp() {
63
+ const d = new Date();
64
+ const p = (n) => String(n).padStart(2, '0');
65
+ return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
66
+ }
67
+
68
+ function pkgVersion() {
69
+ try {
70
+ return JSON.parse(readFileSync(path.join(PKG_ROOT, 'package.json'), 'utf8')).version || '0.0.0';
71
+ } catch {
72
+ return '0.0.0';
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Run a CLI. On Windows, npm-installed commands are .cmd shims that
78
+ * CreateProcess cannot launch directly — retry through cmd.exe on ENOENT.
79
+ */
80
+ function exec(name, args = [], capture = false) {
81
+ const opts = {
82
+ encoding: 'utf8',
83
+ stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit',
84
+ windowsHide: true,
85
+ };
86
+ try {
87
+ const res1 = spawnSync(name, args, opts);
88
+ if (!res1.error) return res1;
89
+ if (res1.error.code !== 'ENOENT') return res1;
90
+ if (process.platform === 'win32') {
91
+ const comspec = process.env.ComSpec || 'cmd.exe';
92
+ const res2 = spawnSync(comspec, ['/d', '/s', '/c', name, ...args], opts);
93
+ if (!res2.error) return res2;
94
+ }
95
+ return res1;
96
+ } catch (err) {
97
+ return { error: err, status: null, stdout: '', stderr: '' };
98
+ }
99
+ }
100
+
101
+ /* ------------------------- preflight / config discovery -------------------- */
102
+
103
+ function preflight() {
104
+ const res = exec('opencode', ['--version'], true);
105
+ if (res.error || res.status !== 0) {
106
+ bail(
107
+ 'OpenCode CLI is required but not runnable (' +
108
+ (res.error ? 'not found on PATH' : `exited ${res.status}`) +
109
+ '). Install/upgrade OpenCode first, then re-run setup.'
110
+ );
111
+ }
112
+ const first = (res.stdout || '').trim().split(/\r?\n/)[0] || 'unknown version';
113
+ log('preflight', `opencode ${first} — OK`);
114
+ }
115
+
116
+ function findConfigDir() {
117
+ const res = exec('opencode', ['debug', 'paths'], true);
118
+ if (!res.error && res.status === 0) {
119
+ const m = (res.stdout || '').match(/^config\s*[=:]?\s*(.+)$/m);
120
+ if (m) {
121
+ let dir = m[1].trim().replace(/^["']|["']$/g, '');
122
+ if (dir.startsWith('~') && (dir[1] === '/' || dir[1] === '\\')) {
123
+ dir = path.join(homedir(), dir.slice(2));
124
+ }
125
+ if (dir) {
126
+ log('config', `resolved via 'opencode debug paths': ${dir}`);
127
+ return dir;
128
+ }
129
+ }
130
+ } else {
131
+ log('config', 'opencode debug paths unavailable — falling back to the environment chain');
132
+ }
133
+ const env = process.env;
134
+ if (env.OPENCODE_CONFIG_DIR) {
135
+ log('config', `env OPENCODE_CONFIG_DIR: ${env.OPENCODE_CONFIG_DIR}`);
136
+ return env.OPENCODE_CONFIG_DIR;
137
+ }
138
+ if (env.XDG_CONFIG_HOME) {
139
+ const p = path.join(env.XDG_CONFIG_HOME, 'opencode');
140
+ log('config', `XDG_CONFIG_HOME fallback: ${p}`);
141
+ return p;
142
+ }
143
+ if (process.platform === 'win32' && env.USERPROFILE) {
144
+ const p = path.join(env.USERPROFILE, '.config', 'opencode');
145
+ log('config', `%USERPROFILE% fallback: ${p}`);
146
+ return p;
147
+ }
148
+ if (env.HOME) {
149
+ const p = path.join(env.HOME, '.config', 'opencode');
150
+ log('config', `$HOME fallback: ${p}`);
151
+ return p;
152
+ }
153
+ const home = homedir();
154
+ if (home) {
155
+ const p = path.join(home, '.config', 'opencode');
156
+ log('config', `os.homedir() fallback: ${p}`);
157
+ return p;
158
+ }
159
+ bail('could not determine the OpenCode config dir. Set OPENCODE_CONFIG_DIR and re-run.');
160
+ }
161
+
162
+ /* --------------------------- package tree collection ----------------------- */
163
+
164
+ function walkDir(dir, onFile) {
165
+ for (const ent of readdirSync(dir, { withFileTypes: true })) {
166
+ const p = path.join(dir, ent.name);
167
+ if (ent.isDirectory()) walkDir(p, onFile);
168
+ else onFile(p);
169
+ }
170
+ }
171
+
172
+ function collectIncoming(configDir) {
173
+ const files = [];
174
+ for (const dirName of COPY_DIRS) {
175
+ const srcDir = path.join(PKG_ROOT, dirName);
176
+ if (!existsSync(srcDir) || !statSync(srcDir).isDirectory()) {
177
+ log('staging', `note: ${dirName}/ not present in this package — nothing to copy from it`);
178
+ continue;
179
+ }
180
+ walkDir(srcDir, (p) =>
181
+ files.push({
182
+ rel: path.relative(PKG_ROOT, p),
183
+ src: p,
184
+ dest: path.join(configDir, path.relative(PKG_ROOT, p)),
185
+ })
186
+ );
187
+ }
188
+ for (const f of COPY_FILES) {
189
+ const src = path.join(PKG_ROOT, f);
190
+ if (!existsSync(src)) {
191
+ log('staging', `note: ${f} not present in this package — nothing to copy`);
192
+ continue;
193
+ }
194
+ files.push({ rel: f, src, dest: path.join(configDir, f) });
195
+ }
196
+ return files;
197
+ }
198
+
199
+ /* -------------------------------- backup ----------------------------------- */
200
+
201
+ function makeBackup(configDir) {
202
+ const backupPath = `${configDir}.bak-oc-harness-setup-${tsStamp()}`;
203
+ if (existsSync(configDir)) {
204
+ if (!statSync(configDir).isDirectory()) {
205
+ bail(`${configDir} exists but is not a directory — refusing to install over it`);
206
+ }
207
+ cpSync(configDir, backupPath, { recursive: true });
208
+ log('backup', `copied ${configDir} → ${backupPath}`);
209
+ } else {
210
+ log('backup', `no config dir at ${configDir} yet — will create it (nothing to back up)`);
211
+ }
212
+ return backupPath;
213
+ }
214
+
215
+ /* ------------------------------ staged copy -------------------------------- */
216
+
217
+ function stageFiles(files, manifest) {
218
+ let written = 0;
219
+ for (const f of files) {
220
+ const srcHash = sha256File(f.src);
221
+ let action = 'written';
222
+ if (existsSync(f.dest)) {
223
+ if (sha256File(f.dest) === srcHash) {
224
+ action = 'skip';
225
+ log('staging', `skip ${f.rel} (already identical — rerun-safe)`);
226
+ } else {
227
+ log('staging', `update ${f.rel} (destination differs — overwriting; backup + manifest protect you)`);
228
+ }
229
+ } else {
230
+ log('staging', `copy ${f.rel}`);
231
+ }
232
+ if (action === 'written') {
233
+ mkdirSync(path.dirname(f.dest), { recursive: true });
234
+ const tmp = `${f.dest}.oc-harness-setup-tmp-${process.pid}`;
235
+ writeFileSync(tmp, readFileSync(f.src));
236
+ rmSync(f.dest, { force: true }); // Windows rename() cannot overwrite
237
+ renameSync(tmp, f.dest);
238
+ written += 1;
239
+ }
240
+ manifest.files.push({ path: f.rel, hash: srcHash, action });
241
+ }
242
+ return written;
243
+ }
244
+
245
+ /* ---------------------------- opencode.jsonc merge ------------------------- */
246
+
247
+ function stripJsonc(text) {
248
+ let out = '';
249
+ let inStr = false;
250
+ let esc = false;
251
+ for (let i = 0; i < text.length; i++) {
252
+ const c = text[i];
253
+ if (inStr) {
254
+ out += c;
255
+ if (esc) esc = false;
256
+ else if (c === '\\') esc = true;
257
+ else if (c === '"') inStr = false;
258
+ continue;
259
+ }
260
+ if (c === '"') {
261
+ inStr = true;
262
+ out += c;
263
+ continue;
264
+ }
265
+ if (c === '/' && text[i + 1] === '/') {
266
+ while (i < text.length && text[i] !== '\n') i++;
267
+ out += '\n';
268
+ continue;
269
+ }
270
+ if (c === '/' && text[i + 1] === '*') {
271
+ i += 2;
272
+ while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++;
273
+ i++;
274
+ continue;
275
+ }
276
+ out += c;
277
+ }
278
+ return out;
279
+ }
280
+
281
+ function dropTrailingCommas(text) {
282
+ let out = '';
283
+ let inStr = false;
284
+ let esc = false;
285
+ for (let i = 0; i < text.length; i++) {
286
+ const c = text[i];
287
+ if (inStr) {
288
+ out += c;
289
+ if (esc) esc = false;
290
+ else if (c === '\\') esc = true;
291
+ else if (c === '"') inStr = false;
292
+ continue;
293
+ }
294
+ if (c === '"') {
295
+ inStr = true;
296
+ out += c;
297
+ continue;
298
+ }
299
+ if (c === ',') {
300
+ let j = i + 1;
301
+ while (j < text.length && /\s/.test(text[j])) j++;
302
+ if (text[j] === '}' || text[j] === ']') continue; // trailing comma
303
+ }
304
+ out += c;
305
+ }
306
+ return out;
307
+ }
308
+
309
+ function parseJsonc(text, what) {
310
+ try {
311
+ return JSON.parse(dropTrailingCommas(stripJsonc(text)));
312
+ } catch (err) {
313
+ bail(`${what} is not valid JSONC: ${err.message}`);
314
+ }
315
+ }
316
+
317
+ function describeKey(k, v) {
318
+ if (k === 'model') return `model "${v}"`;
319
+ if (Array.isArray(v)) return `${k} (${v.length} entr${v.length === 1 ? 'y' : 'ies'})`;
320
+ if (v && typeof v === 'object') {
321
+ const n = Object.keys(v).length;
322
+ return `${k} (${n} entr${n === 1 ? 'y' : 'ies'})`;
323
+ }
324
+ return `${k} (${JSON.stringify(v)})`;
325
+ }
326
+
327
+ function mergeJsonc(configDir, backupPath, manifest) {
328
+ const distroPath = path.join(PKG_ROOT, 'opencode.jsonc');
329
+ const userPath = path.join(configDir, 'opencode.jsonc');
330
+ if (!existsSync(distroPath)) {
331
+ log('merge', 'note: this package ships no opencode.jsonc — no merge to do');
332
+ return;
333
+ }
334
+ const merged = parseJsonc(
335
+ readFileSync(distroPath, 'utf8'),
336
+ `the shipped opencode.jsonc (this package build looks broken)`
337
+ );
338
+ const kept = [];
339
+ if (existsSync(userPath)) {
340
+ const user = parseJsonc(
341
+ readFileSync(userPath, 'utf8'),
342
+ `your existing opencode.jsonc — aborting before any write; your config is untouched (backup: ${backupPath})`
343
+ );
344
+ for (const k of MERGE_KEYS) {
345
+ if (user[k] !== undefined) {
346
+ merged[k] = user[k];
347
+ kept.push(describeKey(k, user[k]));
348
+ } else {
349
+ log('merge', `opencode.jsonc: no ${k} in your config — harness default stays`);
350
+ }
351
+ }
352
+ log('merge', `kept your ${kept.join(', ') || '(nothing — harness defaults only)'}`);
353
+ } else {
354
+ log('merge', 'no existing opencode.jsonc — writing the harness base');
355
+ }
356
+ const out = `${JSON.stringify(merged, null, 2)}\n`;
357
+ mkdirSync(configDir, { recursive: true });
358
+ const tmp = `${userPath}.oc-harness-setup-tmp-${process.pid}`;
359
+ writeFileSync(tmp, out);
360
+ rmSync(userPath, { force: true });
361
+ renameSync(tmp, userPath);
362
+ manifest.files.push({ path: 'opencode.jsonc', hash: sha256Text(out), action: 'merged' });
363
+ log('merge', `rewrote ${userPath} (distro base with permissions/deny, skill allowlist, default_agent "master", references; your model/providers/mcp/plugins re-injected)`);
364
+ }
365
+
366
+ /* ------------------------------ placeholder lint --------------------------- */
367
+
368
+ function lintCopiedFiles(files) {
369
+ const hits = [];
370
+ for (const f of files) {
371
+ if (!existsSync(f.dest)) continue;
372
+ const low = readFileSync(f.dest, 'utf8').toLowerCase();
373
+ for (const pat of LINT_PATTERNS) {
374
+ if (low.includes(pat)) {
375
+ hits.push({ file: f.rel, pattern: pat });
376
+ break;
377
+ }
378
+ }
379
+ }
380
+ return hits;
381
+ }
382
+
383
+ /* ------------------------------- plugin gate ------------------------------- */
384
+
385
+ function registerPlugins(fleet) {
386
+ const list = ['oc-flight-deck', ...(fleet ? ['oc-freedom-fleet'] : [])];
387
+ for (const p of list) {
388
+ log('plugin', `opencode plugin add ${p}`);
389
+ const res = exec('opencode', ['plugin', 'add', p], false);
390
+ if (res.error || res.status !== 0) {
391
+ log(
392
+ 'plugin',
393
+ `'opencode plugin add ${p}' failed (${res.error ? 'not found' : `exit ${res.status}`}) — add it manually later; the config is already installed`
394
+ );
395
+ } else {
396
+ log('plugin', `${p} registered`);
397
+ }
398
+ }
399
+ return list;
400
+ }
401
+
402
+ /* --------------------------------- doctor ---------------------------------- */
403
+
404
+ function doctorPlan() {
405
+ const probe = exec('pwsh', ['-NoProfile', '-Command', 'exit 0'], true);
406
+ return probe.error || probe.status !== 0
407
+ ? 'pwsh missing — doctor skipped, install note printed'
408
+ : 'run scripts/harness-doctor.ps1 via pwsh';
409
+ }
410
+
411
+ function runDoctor(configDir) {
412
+ const probe = exec('pwsh', ['-NoProfile', '-Command', 'exit 0'], true);
413
+ if (probe.error || probe.status !== 0) {
414
+ log('doctor', 'pwsh is not on PATH — /doctor cannot run here. Config still lands.');
415
+ console.log(' PowerShell 7 is optional here but powers /doctor — install:');
416
+ console.log(' winget install --id Microsoft.PowerShell --source winget (Windows)');
417
+ console.log(' brew install --cask powershell (macOS)');
418
+ return 0;
419
+ }
420
+ const script = path.join(configDir, 'scripts', 'harness-doctor.ps1');
421
+ if (!existsSync(script)) {
422
+ log('doctor', `note: ${script} not found — doctor skipped`);
423
+ return 0;
424
+ }
425
+ log('doctor', `running ${script}`);
426
+ const res = exec('pwsh', ['-NoProfile', '-File', script], false);
427
+ if (res.error || res.status !== 0) {
428
+ log(
429
+ 'doctor',
430
+ `harness-doctor exited ${res.error ? 'with an error' : `${res.status}`} — fix the issue, then re-run setup (idempotent)`
431
+ );
432
+ return 1;
433
+ }
434
+ log('doctor', 'harness-doctor passed');
435
+ return 0;
436
+ }
437
+
438
+ /* --------------------------- manifest print (gate) ------------------------- */
439
+
440
+ function printManifest(configDir, files, backupPath, fleet, doctor) {
441
+ const newCount = files.filter((f) => !existsSync(f.dest)).length;
442
+ const sameCount = files.length - newCount;
443
+ console.log('----------------------------- install manifest -----------------------------');
444
+ console.log(` destination config dir : ${configDir}`);
445
+ console.log(` incoming files : ${files.length} (${newCount} new, ${sameCount} already identical — rerun-safe)`);
446
+ console.log(` backup path : ${backupPath}`);
447
+ console.log(' opencode.jsonc merge : distro base (permissions/deny block, skill allowlist,');
448
+ console.log(' default_agent: "master", references registry)');
449
+ console.log(` + your keys re-injected: ${MERGE_KEYS.join(', ')}`);
450
+ console.log(` plugin registration : oc-flight-deck${fleet ? ' + oc-freedom-fleet' : ''} (via 'opencode plugin add')`);
451
+ console.log(` doctor plan : ${doctor}`);
452
+ console.log('----------------------------------------------------------------------------');
453
+ }
454
+
455
+ async function confirmProceed() {
456
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
457
+ let answer = '';
458
+ try {
459
+ answer = (await rl.question('Type y to continue (anything else aborts; nothing is touched): ')).trim().toLowerCase();
460
+ } catch {
461
+ answer = ''; // stdin closed (EOF) — treat as abort
462
+ } finally {
463
+ rl.close();
464
+ }
465
+ return answer === 'y' || answer === 'yes';
466
+ }
467
+
468
+ /* -------------------------------- uninstall -------------------------------- */
469
+
470
+ function uninstall(configDir) {
471
+ const manifestPath = path.join(configDir, MANIFEST_FILE);
472
+ if (!existsSync(manifestPath)) {
473
+ bail(
474
+ `no ${MANIFEST_FILE} found in ${configDir} — nothing to uninstall (an install may already have been removed, or the config dir moved).`
475
+ );
476
+ }
477
+ let manifest;
478
+ try {
479
+ manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
480
+ } catch (err) {
481
+ bail(`could not read ${manifestPath}: ${err.message} — inspect it manually before touching anything.`);
482
+ }
483
+ const base = path.resolve(configDir);
484
+ const files = Array.isArray(manifest.files) ? manifest.files : [];
485
+ if (!files.length) bail(`manifest at ${manifestPath} lists no files — refusing a blind cleanup.`);
486
+ let removed = 0;
487
+ let kept = 0;
488
+ let missing = 0;
489
+ for (const entry of files) {
490
+ const rel = String(entry.path || '');
491
+ const resolved = path.resolve(base, rel);
492
+ if (resolved !== base && !resolved.startsWith(base + path.sep)) {
493
+ log('uninstall', `skip ${rel} (escapes the config dir — refusing)`);
494
+ continue;
495
+ }
496
+ if (!existsSync(resolved)) {
497
+ missing += 1;
498
+ continue;
499
+ }
500
+ if (entry.hash && sha256File(resolved) === entry.hash) {
501
+ rmSync(resolved, { force: true });
502
+ removed += 1;
503
+ log('uninstall', `removed ${rel}`);
504
+ } else {
505
+ kept += 1;
506
+ log('uninstall', `kept ${rel} (you modified it — hash differs)`);
507
+ }
508
+ }
509
+ rmSync(manifestPath, { force: true });
510
+ log('uninstall', `removed ${removed}, kept ${kept} modified, already-missing ${missing}`);
511
+ console.log(` backup (pre-install config dir): ${manifest.backupPath || '(none recorded)'}`);
512
+ console.log(' to restore it fully, replace the current config dir with that backup.');
513
+ if (Array.isArray(manifest.plugins) && manifest.plugins.length) {
514
+ console.log(
515
+ ` plugins left registered: ${manifest.plugins.join(', ')} — remove with 'opencode plugin remove <name>' if unwanted.`
516
+ );
517
+ }
518
+ }
519
+
520
+ /* ---------------------------------- setup ---------------------------------- */
521
+
522
+ function writeManifest(configDir, manifest) {
523
+ mkdirSync(configDir, { recursive: true });
524
+ writeFileSync(path.join(configDir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
525
+ }
526
+
527
+ async function setup(opts) {
528
+ preflight();
529
+ const configDir = findConfigDir();
530
+ const files = collectIncoming(configDir);
531
+ const backupPath = `${configDir}.bak-oc-harness-setup-${tsStamp()}`;
532
+ const doctor = doctorPlan(); // read-only probe
533
+ printManifest(configDir, files, backupPath, opts.fleet, doctor);
534
+
535
+ if (opts.dryRun) {
536
+ console.log('[dry-run] manifest only — nothing was touched.');
537
+ return 0;
538
+ }
539
+ if (opts.ci) {
540
+ console.log('[ci] refusing to mutate — print-only. Run setup interactively to install.');
541
+ return 0;
542
+ }
543
+ if (!(await confirmProceed())) {
544
+ console.log('[gate] aborted — nothing was modified.');
545
+ return 0;
546
+ }
547
+
548
+ /* ---------------- mutations begin (all journaled) ---------------- */
549
+ const backup = makeBackup(configDir);
550
+ const manifest = {
551
+ package: PKG_NAME,
552
+ version: pkgVersion(),
553
+ created: new Date().toISOString(),
554
+ configDir,
555
+ backupPath: backup,
556
+ plugins: ['oc-flight-deck', ...(opts.fleet ? ['oc-freedom-fleet'] : [])],
557
+ files: [],
558
+ };
559
+
560
+ stageFiles(files, manifest);
561
+ mergeJsonc(configDir, backup, manifest);
562
+
563
+ const hits = lintCopiedFiles(files);
564
+ if (hits.length) {
565
+ // Journal first — uninstall must know exactly what landed.
566
+ writeManifest(configDir, manifest);
567
+ for (const h of hits) console.error(`[lint] placeholder pattern "${h.pattern}" found in ${h.file}`);
568
+ bail(
569
+ `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}`
570
+ );
571
+ }
572
+
573
+ writeManifest(configDir, manifest);
574
+ log('manifest', `journal written: ${path.join(configDir, MANIFEST_FILE)}`);
575
+
576
+ registerPlugins(opts.fleet);
577
+ const doctorOk = runDoctor(configDir);
578
+ if (doctorOk !== 0) return 1;
579
+
580
+ console.log();
581
+ console.log('-------------------------------- summary ---------------------------------');
582
+ console.log(' installed: agents/, commands/, skills/, reference/, scripts/, AGENTS.md + merged opencode.jsonc');
583
+ console.log(` plugins : oc-flight-deck${opts.fleet ? ', oc-freedom-fleet' : ''}`);
584
+ console.log(` backup : ${backup}`);
585
+ console.log(' undo : npx oc-harness-setup setup --uninstall');
586
+ console.log(' restart : restart your OpenCode session so the new agents/commands/skills load.');
587
+ console.log('----------------------------------------------------------------------------');
588
+ return 0;
589
+ }
590
+
591
+ /* --------------------------------- entry ---------------------------------- */
592
+
593
+ function parseArgs(argv) {
594
+ const opts = { command: 'setup', dryRun: false, ci: false, uninstall: false, fleet: false };
595
+ for (const a of argv) {
596
+ switch (a) {
597
+ case 'setup':
598
+ opts.command = 'setup';
599
+ break;
600
+ case '--dry-run':
601
+ opts.dryRun = true;
602
+ break;
603
+ case '--ci':
604
+ opts.ci = true;
605
+ break;
606
+ case '--uninstall':
607
+ opts.uninstall = true;
608
+ break;
609
+ case '--fleet':
610
+ opts.fleet = true;
611
+ break;
612
+ case '--help':
613
+ case '-h':
614
+ usage();
615
+ process.exitCode = 0;
616
+ return null;
617
+ default:
618
+ usage();
619
+ bail(`unknown argument: ${a}`);
620
+ return null;
621
+ }
622
+ }
623
+ return opts;
624
+ }
625
+
626
+ async function main() {
627
+ const opts = parseArgs(process.argv.slice(2));
628
+ if (!opts) return;
629
+ if (opts.uninstall) {
630
+ const configDir = findConfigDir();
631
+ uninstall(configDir);
632
+ return;
633
+ }
634
+ const code = await setup(opts);
635
+ if (code !== 0) process.exitCode = code;
636
+ }
637
+
638
+ main().catch((err) => {
639
+ if (!(err instanceof Bail)) console.error(`[fatal] ${err && err.stack ? err.stack : err}`);
640
+ process.exitCode = 1;
641
+ });
@@ -0,0 +1,13 @@
1
+ ---
2
+ description: Implement the request with the smallest working change
3
+ agent: build
4
+ ---
5
+
6
+ Build `$ARGUMENTS`. Define "done" first, then implement with the smallest correct diff.
7
+
8
+ - Pick the local skill that fits: `spec-driven-development` for a new or specified feature, `incremental-implementation` for the build loop, `test-driven-development` when tests should come first, and `debugging-and-error-recovery` for hard bugs. For UI, consult `frontend-ui-engineering`; for API boundaries, use `api-and-interface-design`.
9
+ - Inspect before editing; understand the real flow, then stop at the first rung that holds.
10
+ - Preserve safety, validation, security, accessibility, reversibility, and anything the user explicitly asked for — never lean these away.
11
+ - Run the narrow check that proves the change and report: files changed, what you ran, what it proved, and residual risk.
12
+ - Mark deliberate shortcuts with `lean: <ceiling>; revisit when <trigger>` so `/ponytail-debt` can collect them.
13
+ - For work that splits at natural seams, spawn helpers in parallel with one writer per artifact; follow the `swarm-orchestration` skill.
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: Write or refresh this session's checkpoint
3
+ ---
4
+
5
+ Update `checkpoint.md` in this session's state directory (`~/.opencode/state/sessions/<session-id>/`): goal, status (done / now / next), key files, blockers. `$ARGUMENTS` is optional scope. Keep it short; append a timestamped entry if the file exists.
@@ -0,0 +1,13 @@
1
+ ---
2
+ description: Simplify current changes by cutting unnecessary complexity
3
+ agent: coder
4
+ ---
5
+
6
+ Simplify `$ARGUMENTS` (default: the current changes) by applying the Ponytail ladder in `AGENTS.md` and the local `code-simplification` skill: the laziest change that actually works.
7
+
8
+ 1. First **review** the target for what can be cut — tags `delete` (dead code, unused flags), `stdlib` (reinvented standard library), `native` (platform features replaced by custom code), `yagni` (speculative flexibility), `shrink` (over-abstraction). Or run `/ponytail-audit --diff` first if the diff is large.
9
+ 2. Then **apply** the safe cuts: one writer per artifact, smallest diff, no behavior change unless removing the behavior is the point.
10
+ 3. Preserve the lean safety floor: validation, security, accessibility, reversibility, and explicit user requirements are never cut.
11
+ 4. Run the check that proves behavior is unchanged (or correctly simpler) and report: what was cut, lines/dependencies removed, what you ran, and what it proved.
12
+
13
+ Mark anything you deliberately deferred with `lean: <ceiling>; revisit when <trigger>`. Route correctness, security, and performance findings to `/review` — this command cuts complexity only.