oc-harness-setup 1.0.1 → 1.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.
@@ -41,6 +41,9 @@
41
41
  * an orphan either direction = FAIL)
42
42
  * - state/template.md exists and carries the fixed session key order
43
43
  * (id, title, status, goal, next, artifacts, decisions, open)
44
+ * - playbooks/*.md carry Entry criteria, a ### heading, two numbered steps
45
+ * and **Reply:** in order, and match skills/playbook/SKILL.md both ways
46
+ * (no playbooks shipped is a supported PASS; no router skips the cross-check)
44
47
  *
45
48
  * The small DECLARED block at the top is the honest form of the old hardcoded
46
49
  * state: each entry names its evidence. Everything else is read from
@@ -75,7 +78,6 @@ import { spawnSync } from 'node:child_process';
75
78
  import { readFileSync, readdirSync, statSync } from 'node:fs';
76
79
  import path from 'node:path';
77
80
 
78
- /* ------------------------------- arguments -------------------------------- */
79
81
 
80
82
  const argv = process.argv.slice(2);
81
83
  let fix = false;
@@ -102,7 +104,6 @@ if (!(process.env.USERPROFILE ?? '').trim()) {
102
104
 
103
105
  const root = configDirArg || path.join(process.env.USERPROFILE, '.config', 'opencode');
104
106
 
105
- /* ---------- declared values (each names its evidence) ---------- */
106
107
  // Required layout paths. Evidence: the harness shape itself (opencode.jsonc
107
108
  // header "Harness v4"); stable, changes only via a harness restructure.
108
109
  const requiredPaths = [
@@ -148,7 +149,6 @@ const denyGates = [
148
149
  // convention carried over from the deleted checker lineage.
149
150
  const secretNamePattern = /(apikey|api_key|secret|password|bearer|credential)/i;
150
151
 
151
- /* -------------------------------- helpers --------------------------------- */
152
152
 
153
153
  // PowerShell's -eq/-contains/-ne compare strings case-insensitively; the port
154
154
  // keeps that so a config that graded PASS before still grades PASS.
@@ -289,6 +289,17 @@ function getMcpServerNames(mcpNode) {
289
289
  return Object.keys(container);
290
290
  }
291
291
 
292
+ // A V2 `plugins[]` entry may be `{ package, options }`; its identity is
293
+ // `package`. A specifier string keeps its existing String() behavior, and a
294
+ // tuple or malformed object stays on that same path so it still fails closed.
295
+ function pluginIdentity(entry) {
296
+ if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
297
+ const id = entry.package;
298
+ if (typeof id === 'string' && id.trim() !== '') return id.trim();
299
+ }
300
+ return String(entry);
301
+ }
302
+
292
303
  // StrictMode-safe read of the permissions array. A config that omits the
293
304
  // key (or carries a non-array) grades as an empty set, so dependent laws
294
305
  // FAIL with their named reason instead of throwing a property error.
@@ -300,11 +311,14 @@ function getPermissionRules(config) {
300
311
  return Array.isArray(value) ? value : [];
301
312
  }
302
313
 
303
- // First token per line of `opencode mcp list`, minus status markers.
314
+ // First token per line of `opencode mcp list`, minus status markers. V2 marks
315
+ // a disabled server with a leading ○ (U+25CB): that glyph is a status, not an
316
+ // ID, so it is stripped like the older ✓/✗/×/• markers. A disabled server is
317
+ // still registered and keeps counting in both directions of Law 7.
304
318
  function getRegistryMcpNames(lines) {
305
319
  const names = [];
306
320
  for (const line of lines) {
307
- const text = String(line).replace(/^[\u2713\u2717\u00D7\u2022\-\s]+/, '').trim();
321
+ const text = String(line).replace(/^[\u2713\u2717\u00D7\u2022\u25CB\-\s]+/, '').trim();
308
322
  if (text === '') continue;
309
323
  const name = text.split(/\s+/).filter((tok) => tok !== '')[0];
310
324
  if (name && !/^(id|name|server|status|no)$/i.test(name)) names.push(String(name));
@@ -460,7 +474,6 @@ function getUnwiredRoutingDoc(docsRoot) {
460
474
  return null;
461
475
  }
462
476
 
463
- /* ---------------------------- law evaluation ------------------------------ */
464
477
 
465
478
  const laws = [];
466
479
 
@@ -673,7 +686,7 @@ if (!configOk) {
673
686
  const pluginRows = pluginRun.lines.filter((line) => String(line).trim() !== '').slice(1);
674
687
  const unresolved = [];
675
688
  for (const entry of configuredPlugins) {
676
- const text = String(entry);
689
+ const text = pluginIdentity(entry);
677
690
  let resolves = false;
678
691
  for (const row of pluginRows) {
679
692
  if (String(row).includes(text)) {
@@ -1329,7 +1342,87 @@ if (!isFile(templatePath)) {
1329
1342
  }
1330
1343
  }
1331
1344
 
1332
- /* -------------------------------- verdict --------------------------------- */
1345
+ // Law 19: playbooks carry the graded shape and match the router both ways.
1346
+ // The shape is a state machine over lines: Entry criteria -> ### heading ->
1347
+ // at least two numbered steps -> **Reply:**, in that order. This is a pure
1348
+ // read of the tree: no writes, no spawn, no network. A config with no
1349
+ // playbooks/ is a supported state (the install lane may not have run), so it
1350
+ // passes as 'no playbooks shipped' and ordering with that lane never matters.
1351
+ // The router cross-check is fail-closed in both directions; an absent router
1352
+ // skips it as PASS rather than FAIL.
1353
+ function getPlaybookMissingElements(text) {
1354
+ const missing = [];
1355
+ let stage = 0;
1356
+ let steps = 0;
1357
+ for (const line of text.split(/\r?\n/)) {
1358
+ if (stage === 0) {
1359
+ if (/^\s*Entry criteria\s*:/i.test(line)) stage = 1;
1360
+ } else if (stage === 1) {
1361
+ if (/^###\s+\S/.test(line)) stage = 2;
1362
+ } else if (stage === 2) {
1363
+ if (/^\s*\d+[.)]\s+\S/.test(line)) steps++;
1364
+ if (steps >= 2) stage = 3;
1365
+ } else if (stage === 3) {
1366
+ if (/^\s*\*\*Reply:\*\*/i.test(line)) stage = 4;
1367
+ } else {
1368
+ break;
1369
+ }
1370
+ }
1371
+ if (stage < 1) missing.push('Entry criteria: line');
1372
+ if (stage < 2) missing.push('### heading');
1373
+ if (stage < 3) missing.push('at least two numbered steps');
1374
+ if (stage < 4) missing.push('**Reply:** line');
1375
+ return missing;
1376
+ }
1377
+
1378
+ // Router rows are `| ... | playbooks/<name>.md |`. Only table rows count, so
1379
+ // prose mentions of a playbook never adopt a file the router does not route.
1380
+ function getRouterPlaybookNames(text) {
1381
+ const names = [];
1382
+ for (const line of text.split(/\r?\n/)) {
1383
+ if (!/^\s*\|/.test(line)) continue;
1384
+ for (const m of line.matchAll(/playbooks\/([^|\s]+\.md)/gi)) names.push(m[1]);
1385
+ }
1386
+ return sortUnique(names);
1387
+ }
1388
+
1389
+ const playbooksDir = path.join(root, 'playbooks');
1390
+ const routerPath = path.join(skillsRoot, 'playbook', 'SKILL.md');
1391
+ if (!isDir(playbooksDir)) {
1392
+ addLaw('playbooks carry the graded shape and match the router', 'PASS', 'no playbooks shipped');
1393
+ } else {
1394
+ const playbookFiles = listFiles(playbooksDir, /\.md$/i);
1395
+ const playbookProblems = [];
1396
+ for (const name of playbookFiles) {
1397
+ for (const element of getPlaybookMissingElements(safeText(path.join(playbooksDir, name)))) {
1398
+ playbookProblems.push(`${name}: missing ${element}`);
1399
+ }
1400
+ }
1401
+ const routerExists = isFile(routerPath);
1402
+ if (routerExists) {
1403
+ const routerNames = getRouterPlaybookNames(safeText(routerPath));
1404
+ const fileNames = sortUnique(playbookFiles);
1405
+ const orphans = fileNames.filter((name) => !hasCI(routerNames, name));
1406
+ const dangling = routerNames.filter((name) => !hasCI(fileNames, name));
1407
+ if (orphans.length > 0) playbookProblems.push(`orphan playbooks with no router row: ${orphans.join(', ')}`);
1408
+ if (dangling.length > 0) playbookProblems.push(`dangling router rows with no playbook: ${dangling.join(', ')}`);
1409
+ }
1410
+ if (playbookProblems.length > 0) {
1411
+ addLaw(
1412
+ 'playbooks carry the graded shape and match the router',
1413
+ 'FAIL',
1414
+ playbookProblems.join('; '),
1415
+ `repair each playbook and reconcile the router table in skills\\playbook\\SKILL.md: ${playbookProblems.join('; ')}`
1416
+ );
1417
+ } else {
1418
+ const routerDetail = routerExists ? 'router names agree both ways' : 'no router (cross-check skipped)';
1419
+ addLaw(
1420
+ 'playbooks carry the graded shape and match the router',
1421
+ 'PASS',
1422
+ `${playbookFiles.length} playbook file(s) carry Entry criteria, ### heading, two numbered steps, and **Reply:** in order; ${routerDetail}`
1423
+ );
1424
+ }
1425
+ }
1333
1426
 
1334
1427
  const failLaws = laws.filter((law) => law.result === 'FAIL');
1335
1428
  const driftLaws = laws.filter((law) => law.result === 'DRIFT');
@@ -1394,7 +1487,6 @@ if (json) {
1394
1487
  process.exit(exitCode);
1395
1488
  }
1396
1489
 
1397
- /* --------------------------------- report --------------------------------- */
1398
1490
 
1399
1491
  out(`=== harness-doctor ${root} ===`);
1400
1492
  for (const law of laws) {
@@ -5,72 +5,53 @@ description: "Use when the user asks to add a capability, write a skill, adopt a
5
5
 
6
6
  # evolve
7
7
 
8
- The harness grows by one deliberate extension at a time, never a burst.
8
+ Add one artifact at a time with the shipped CLI. The CLI fills a file from `templates/` and writes the result. Do not hand-write the artifact when the CLI can fill it.
9
9
 
10
10
  ## When to load
11
11
 
12
12
  - "add a skill for this"
13
13
  - "make the harness do X"
14
- - "adopt this feature/pattern from upstream"
15
- - "this should be built in"
16
- - A repeated manual workflow that should become a skill.
14
+ - "add a playbook for this task"
15
+ - "create a command or an agent for this"
17
16
 
18
- ## Decision order
17
+ ## Command
19
18
 
20
- 1. Existing reference or skill first — if one already covers the job, use it; done when the covering surface is named.
21
- 2. Repeatable procedure → skill + 1:1 command; done when the procedure clears the bar below.
22
- 3. New reach class → agent seat; a new craft alone never earns one; done when the reach gap is stated.
23
- 4. Configuration → `opencode.jsonc` + doctor, no agent; done when the config change and its check are named.
24
- 5. One-off → do it as a task, add no surface; done when the task ships with proof and nothing new is wired.
19
+ ```
20
+ oc-harness-setup evolve <skill|command|agent|playbook> <id> [--title ...] [--description ...] [--body <file|->] [--dry-run] [--force]
21
+ ```
25
22
 
26
- ## Write the skill
23
+ `<kind>` selects the matching template. `<id>` names the artifact. Use `--body -` to read the body from standard input, or pass a file path to read from that file.
27
24
 
28
- - One job, one trigger, one artifact, one proving check; done when all four are named in one line.
29
- - Frontmatter `name` matching the directory and a `description` stating when to load; done when both parse.
30
- - Body sections: When to load, Procedure (numbered, each step with its done condition), Done, Never, Examples (Good/Bad); done when every section exists.
31
- - ≤500 lines; detail behind a reference pointer; done when the line count holds.
32
- - Add `commands/<id>.md` with `agent: orchestrator`, `subagent: false`, body pointing at `skills/<id>/SKILL.md`; done when the command exists and points.
33
- - Wire the `AGENTS.md` pointer and the `opencode.jsonc` skill allowlist; done when both name the new skill.
34
- - Add a reference to `reference/README.md` if it adds one; done when the index matches the tree.
35
- - Update README/CHANGELOG if public; done when the public surface matches.
36
- - Do not add count edits: the doctor derives 1:1 dynamically.
25
+ ## Flags
37
26
 
38
- ## Adopt upstream
27
+ | Flag | Effect |
28
+ |---|---|
29
+ | `--title` | Fills `{{title}}`. Defaults to the id. |
30
+ | `--description` | Fills `{{description}}`. Quote values that hold a colon. |
31
+ | `--body` | Fills `{{body}}` from a file, or from `-` for standard input. |
32
+ | `--dry-run` | Prints the filled artifact and its side effects. Writes nothing. |
33
+ | `--force` | Overwrites an existing artifact. Read the old file first. |
39
34
 
40
- 1. Name source, version, license before reuse; done when all three are stated.
41
- 2. License verdict first (digest, quote-only, reject); done when the verdict is stated before any reuse.
42
- 3. Burden test: does this remove maintenance or add it; done when the one-line verdict holds.
43
- 4. Digest to house form; never paste unlicensed code; done when the digest is house-shaped and licensed.
44
- 5. Credit source + pinned revision; pin third-party packs; done when the pin is recorded.
45
- 6. Promote by ladder: cited note → proposal → reference or skill; done when no rung is skipped.
35
+ ## What gets written
46
36
 
47
- ## Adopt a user improvement request
37
+ - `skill` writes `skills/<id>/SKILL.md`, its paired `commands/<id>.md`, and the `opencode.jsonc` skill allow entry.
38
+ - `command` writes `commands/<id>.md`.
39
+ - `agent` writes `agents/<id>.md` with `description` and `steps`.
40
+ - `playbook` writes `playbooks/<id>.md` and appends one row to the playbook match table.
48
41
 
49
- 1. Treat it as a brief: outcome, scope, exclusions, proving check; done when all four are locked.
50
- 2. A doctrine change is proposed as rule/reason/surface, never applied inline; done when the proposal states all three and stops.
51
- 3. A local preference goes to the user's config or notes, not the shipped pack; done when the pack stays generic.
52
- 4. A niche request is rejected in one line and the general form that would earn a place is named; done when the rejection plus the general form are stated.
53
- 5. Implement through `worker` for code/docs, `maintainer` for harness content; done when the right seat owns the write.
54
- 6. Verify with a fresh seat; done when the verdict comes from a seat that did not write the work.
42
+ ## Rule
55
43
 
56
- ## Verify
57
-
58
- 1. Frontmatter parses; done when the loader accepts it.
59
- 2. Name matches directory; done when they are identical.
60
- 3. Command/skill 1:1; done when neither side is orphaned.
61
- 4. The skill loads in a fresh session and its trigger is discoverable; done when a fresh session fires it.
62
- 5. Run the doctor and package gate; cite command + output; done when both are green and cited.
63
- 6. Record CHANGELOG and state; version when shipped; done when the record exists.
44
+ 1. Pick the kind that matches the job. One extension at a time.
45
+ 2. Run the command with `--dry-run` and read the filled artifact.
46
+ 3. Check that no placeholder token survives and that each frontmatter scalar holding a colon is quoted.
47
+ 4. Run the command without `--dry-run` to write it.
48
+ 5. Run the doctor and the package gate. Quote command, exit, and key line.
49
+ 6. Report every file written and its SHA.
64
50
 
65
51
  ## Never
66
52
 
67
- - Never add a skill for a one-off.
68
- - Never a command without a skill or a skill without a command.
69
- - Never an agent for a new craft.
70
- - Never paste unlicensed upstream code.
71
- - Never apply a doctrine change without a proposal.
72
- - Never widen the pack with a niche skill — generalize or reject.
73
-
74
- ## Done
75
-
76
- - The smallest extension is wired, 1:1, loadable, doctor-clean, recorded, and versioned when public.
53
+ - Never hand-write an artifact when the CLI can fill it.
54
+ - Never add a skill for a one-off task.
55
+ - Never leave a placeholder token in a shipped file.
56
+ - Never use `--force` on a file you have not read.
57
+ - Never widen the pack with a niche artifact; generalize or reject.
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: playbook
3
+ description: "Use when a task needs a known route - pick one playbook from the match table, copy its steps into the todo, then do the work."
4
+ ---
5
+
6
+ # playbook
7
+
8
+ One task takes one playbook. Choose the row that matches the outcome you need, copy that playbook's numbered steps into the todo before work starts, and follow them in order.
9
+
10
+ ## Match table
11
+
12
+ | Task | Playbook |
13
+ |---|---|
14
+ | Answer a question without changing code | playbooks/investigate.md |
15
+ | Fix a failure you have reproduced | playbooks/bug-fix.md |
16
+ | Add new behavior with an agreed design | playbooks/feature.md |
17
+ | Change structure while behavior stays the same | playbooks/refactor.md |
18
+ | Land work that is already verified | playbooks/ship.md |
19
+
20
+ ## Rule
21
+
22
+ 1. Match one row. When two rows fit, choose the one that names the result, not the activity.
23
+ 2. Read the chosen playbook's entry criteria. When they do not hold, re-route and say why.
24
+ 3. Copy the playbook's numbered steps into the todo before any work starts.
25
+ 4. Work the steps in order. Never mix steps from two playbooks.
26
+ 5. Keep the reply and the SHA receipt in the shape the playbook asks for.
package/stages.yaml ADDED
@@ -0,0 +1,42 @@
1
+ # Shipped stage registry. Data only: code reads stage order and ids from here.
2
+ version: 1
3
+ stages:
4
+ - id: preflight
5
+ title: Preflight
6
+ steps:
7
+ - assertWindows
8
+ - preflight
9
+ - id: resolve
10
+ title: Resolve
11
+ steps:
12
+ - findConfigDir
13
+ - warnConfigTargets
14
+ - id: plan
15
+ title: Plan
16
+ steps:
17
+ - collectIncoming
18
+ - lintPackagedSource
19
+ - readManifest
20
+ - backupSelection
21
+ - printManifest
22
+ - confirmProceed
23
+ - validateJsoncInputs
24
+ - id: write
25
+ title: Write
26
+ steps:
27
+ - sweepTmpLitter
28
+ - makeBackup
29
+ - manifest
30
+ - retireStale
31
+ - stageFiles
32
+ - carryForwardJournal
33
+ - mergeJsonc
34
+ - writeManifest
35
+ - id: verify
36
+ title: Verify
37
+ checks:
38
+ - runDoctor
39
+ - id: report
40
+ title: Report
41
+ steps:
42
+ - summary
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: "{{description}}"
3
+ steps: 40
4
+ ---
5
+
6
+ # {{title}}
7
+
8
+ {{body}}
9
+
10
+ The `{{id}}` seat owns this file. Read the contract before you act on it.
@@ -0,0 +1,11 @@
1
+ ---
2
+ description: "{{description}}"
3
+ agent: orchestrator
4
+ subagent: false
5
+ ---
6
+
7
+ # {{title}}
8
+
9
+ Load the `{{id}}` skill; `skills/{{id}}/SKILL.md` owns the procedure. Apply it to `$ARGUMENTS`.
10
+
11
+ {{body}}
@@ -0,0 +1,13 @@
1
+ Entry criteria: {{description}}
2
+
3
+ ### {{title}}
4
+
5
+ **You own the {{id}} task. Follow the steps in order and verify the result.**
6
+
7
+ {{body}}
8
+
9
+ **Reply:** what you did, what you chose, and how you verified it.
10
+
11
+ ## Exit - SHA receipt
12
+
13
+ Land small ordered commits, one green per commit. Report the command, exit, and key line for each check. Push and publish stay gated.
@@ -0,0 +1,8 @@
1
+ ---
2
+ name: {{id}}
3
+ description: "{{description}}"
4
+ ---
5
+
6
+ # {{title}}
7
+
8
+ {{body}}
@@ -1,7 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
2
- <style>html,body{margin:0;padding:0}svg{display:block;width:100vw;height:100vh}</style>
3
- <!-- Direction A: "cursor-n" — rounded lowercase n + terminal block cursor, near-black ground -->
4
- <rect x="16" y="16" width="480" height="480" rx="112" fill="#0B0F14"/>
5
- <path d="M136 384 L136 264 C136 196 180 164 234 164 C288 164 328 198 328 264 L328 384 L264 384 L264 270 C264 242 250 230 234 230 C218 230 200 242 200 270 L200 384 Z" fill="#EEF3F6"/>
6
- <rect x="352" y="312" width="52" height="72" rx="8" fill="#4DD4E8"/>
7
- </svg>