@ionivetech/mugiwara 0.9.0 → 0.9.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.
Files changed (46) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.cursor-plugin/plugin.json +1 -1
  5. package/.kimi-plugin/plugin.json +1 -1
  6. package/.opencode/mugiwara-helpers.mjs +1 -1
  7. package/.opencode/plugins/mugiwara.mjs +173 -1
  8. package/README.md +4 -4
  9. package/content/agents/luffy-orchestrator.md +15 -1
  10. package/content/agents/zoro-execution.md +1 -1
  11. package/content/skills/mugiwara-checkpoint/SKILL.md +1 -0
  12. package/content/skills/mugiwara-execution/SKILL.md +5 -5
  13. package/content/skills/mugiwara-gates/SKILL.md +1 -0
  14. package/content/skills/mugiwara-healing/SKILL.md +1 -0
  15. package/content/skills/mugiwara-orchestration/SKILL.md +7 -3
  16. package/content/skills/mugiwara-orchestration/references/check-ins.md +4 -5
  17. package/content/skills/mugiwara-orchestration/references/output-contract.md +2 -2
  18. package/content/skills/mugiwara-planning/SKILL.md +1 -1
  19. package/content/skills/mugiwara-planning/references/sub-missions.md +2 -2
  20. package/content/skills/mugiwara-quality/SKILL.md +1 -0
  21. package/content/skills/mugiwara-review/SKILL.md +2 -0
  22. package/content/skills/mugiwara-security/SKILL.md +2 -2
  23. package/content/skills/mugiwara-ship/SKILL.md +12 -0
  24. package/content/skills/mugiwara-workflow/SKILL.md +2 -2
  25. package/dist/mugiwara.js +235 -82
  26. package/gemini-extension.json +1 -1
  27. package/hooks/engagement-marker.js +9 -1
  28. package/hooks/engagement-marker.ts +9 -1
  29. package/hooks/hooks.json +12 -0
  30. package/hooks/pipeline-guard.js +137 -3
  31. package/hooks/pipeline-guard.ts +161 -3
  32. package/hooks/pretool-guard.js +84 -0
  33. package/hooks/pretool-guard.ts +60 -0
  34. package/package.json +1 -1
  35. package/plugin.json +1 -1
  36. package/references/wave-banners.md +22 -27
  37. package/scripts/build-hooks.ts +1 -1
  38. package/scripts/gate-selftest.ts +342 -0
  39. package/scripts/savepoint.sh +16 -4
  40. package/scripts/validate-content.ts +190 -15
  41. package/scripts/write-metrics.ts +25 -1
  42. package/src/cli.ts +15 -0
  43. package/src/config.ts +1 -1
  44. package/src/guards.ts +40 -0
  45. package/src/initiative.ts +174 -0
  46. package/src/targets/claude.ts +1 -0
@@ -5,29 +5,28 @@ plugin and the opencode-target generator derive agent UI colors from the table
5
5
  below — change a color HERE, never in code. This file is machine-parsed:
6
6
  keep the table format exact (one row per agent, pipes, no extra columns).
7
7
 
8
- ## Banner format (one form)
8
+ ## The banner
9
9
 
10
- Every flow stage opens with the banner line in the owning agent's color, and closes
11
- with a handoff line:
10
+ Every flow stage opens with this line and closes with a handoff:
12
11
 
13
- ```
14
- ===== ⚔️ FLOW 3 ZORO (EXECUTION) =====
15
- → Flow 4 — Chopper (Checkpoint)
16
- ```
12
+ ## ⚔️ Flow 3 — Zoro (Execution)
13
+ Flow 4Chopper
17
14
 
18
- - Terminal: wrap the whole line in ANSI truecolor `\x1b[38;2;R;G;Bm` ... `\x1b[0m`.
19
- - Markdown UI: emit the plain equals line, no ANSI (UIs strip or garble escapes).
20
- - The crew emoji leads the line, before the `FLOW N` text.
21
- - RGB values come from the `hex` column below; R/G/B are the hex channels in
22
- decimal (truecolor `38;2;R;G;B`). If the terminal lacks truecolor, use the
23
- `ansi-256` index: `\x1b[38;5;Nm`.
24
- - Flow 9's handoff: `→ closure`.
25
- - The literal `FLOW N —` text must stay exact: the check-in protocol reads it.
26
- Heal cycles are counted from the DECISION LOG's `## Flow 8` sections
27
- (`mugiwara savepoint` greps `^## flow 8`), not from banners — a banner that
28
- drops the literal does not reset the heal loop.
29
- - Never convey the flow stage by color alone — the crew name always accompanies
30
- the color.
15
+ Rules, all unconditional:
16
+
17
+ - A markdown heading (`## `), the crew emoji, then `Flow N — Crew (Role)`.
18
+ - **Never emit ANSI escapes.** The model cannot tell a terminal from a markdown
19
+ UI, so it must not try. Colour is applied by the harness plugin, which knows
20
+ the surface — see "Colour" below.
21
+ - Keep `Flow N —` literal: the check-in protocol reads it.
22
+ - Handoff is the LAST line of the stage's final response. Flow 9 closes with
23
+ `→ closure`.
24
+
25
+ ## Colour (harness, not model)
26
+
27
+ The crew colour table below is consumed by the opencode plugin
28
+ (`readBannerColors()`) and by any harness that can style output. The model never
29
+ renders colour and never needs the hex values.
31
30
 
32
31
  ## Crew colors
33
32
 
@@ -53,12 +52,8 @@ their banners appear only when a wave or worker names them.
53
52
 
54
53
  ## Rules
55
54
 
56
- 1. Banner before EVERY flow stage; handoff after it. Main thread emits `===== FLOW N — CREW =====` FIRST line and `→ Flow N+1 — Crew` LAST line even when subagent does work — covers Flow 0 Luffy, 1 Usopp, 2 Nami, 3 Zoro, 4 Chopper, 5 Sanji, 6 Franky, 7 Robin/Jinbe, 8 Brook, 9 Luffy. No flow stage starts without its banner (orchestration red flag).
57
- 2. The color comes from this table only — never invent a hex mid-mission.
58
- 3. One form everywhere: equals line `===== <emoji> FLOW N — <CREW> (ROLE) =====` five `=` per side, the crew emoji from the table leading the line, ANSI-wrapped in terminals, plain in markdown-rendering UIs. When unsure, the plain form is safe everywhere.
59
- 4. Only the crew table's colors and the two SGR forms above (truecolor,
60
- 256-index) may appear in a banner — never other escape families (OSC,
61
- title, cursor, other SGR codes). The banner is a fixed template, not a
62
- formatting playground.
55
+ 1. Banner before EVERY flow stage; handoff after it. Main thread emits `## <emoji> Flow N — Crew (Role)` FIRST line and `→ Flow N+1 — Crew` LAST line even when subagent does work — covers Flow 0 Luffy, 1 Usopp, 2 Nami, 3 Zoro, 4 Chopper, 5 Sanji, 6 Franky, 7 Robin/Jinbe, 8 Brook, 9 Luffy. No flow stage starts without its banner (orchestration red flag).
56
+ 2. The color comes from this table only — never invent a hex mid-mission. The model never emits color itself; the harness styles the heading.
57
+ 3. One form everywhere: heading `## <emoji> Flow N — Crew (Role)`renders as a visual break in every markdown UI and stays readable as plain text in a terminal.
63
58
  5. Adding a crew member? Add the row here first; the plugin and target
64
59
  generator pick it up automatically.
@@ -12,7 +12,7 @@ import { dirname, join } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
 
14
14
  const root = join(dirname(fileURLToPath(import.meta.url)), '..');
15
- export const HOOK_ENTRIES = ['session-start', 'mugiwara-mode-tracker', 'auto-savepoint', 'engagement-marker', 'pipeline-guard'];
15
+ export const HOOK_ENTRIES = ['session-start', 'mugiwara-mode-tracker', 'auto-savepoint', 'engagement-marker', 'pipeline-guard', 'pretool-guard'];
16
16
 
17
17
  // --check verifies the committed .js files are present and current, without
18
18
  // rewriting them. hooks.json points at the .js builds, so a missing or stale
@@ -968,5 +968,347 @@ console.log('\nW12 — doc integrity stale path');
968
968
  }
969
969
  }
970
970
 
971
+ // --- E1: delete ## Before you start from luffy-orchestrator.md → validate-content fails ---
972
+ console.log('\nE1 — luffy entry protocol');
973
+ {
974
+ const lf = join(root, 'content', 'agents', 'luffy-orchestrator.md');
975
+ const original = readFileSync(lf, 'utf8');
976
+ try {
977
+ const broken = original.replace('## Before you start', '## Before you begin');
978
+ if (broken === original) {
979
+ console.error('✗ E1: mutation target not found');
980
+ failed++;
981
+ } else {
982
+ writeFileSync(lf, broken);
983
+ assert('luffy section renamed → validate-content fails', false, () => run('E1', 'bun scripts/validate-content.ts'));
984
+ }
985
+ } finally {
986
+ writeFileSync(lf, original);
987
+ assert('restored → content passes', true, () => run('E1-restore', 'bun scripts/validate-content.ts'));
988
+ }
989
+ }
990
+
991
+ // --- E2: restore the luffy exemption → the gate goes blind, selftest catches it ---
992
+ console.log('\nE2 — luffy exemption');
993
+ {
994
+ const vf = join(root, 'scripts', 'validate-content.ts');
995
+ const lf = join(root, 'content', 'agents', 'luffy-orchestrator.md');
996
+ const vOrig = readFileSync(vf, 'utf8');
997
+ const lOrig = readFileSync(lf, 'utf8');
998
+ try {
999
+ const vBroken = vOrig.replace(
1000
+ " const name = f.replace(/\\.md$/, '');\n const text = readFileSync(join(agentDir, f), 'utf8');",
1001
+ " const name = f.replace(/\\.md$/, '');\n if (name === 'luffy-orchestrator') continue;\n const text = readFileSync(join(agentDir, f), 'utf8');",
1002
+ );
1003
+ const lBroken = lOrig.replace('## Before you start', '## Before you begin');
1004
+ if (vBroken === vOrig || lBroken === lOrig) {
1005
+ console.error('✗ E2: mutation target not found');
1006
+ failed++;
1007
+ } else {
1008
+ writeFileSync(vf, vBroken);
1009
+ writeFileSync(lf, lBroken);
1010
+ // Blindness proof: with the exemption back, a captain with no checklist
1011
+ // passes the gate. Demonstrating that blindness IS the passing test —
1012
+ // it proves the gate can go blind, which is what this mutation guards.
1013
+ if (run('E2', 'bun scripts/validate-content.ts')) {
1014
+ passed++;
1015
+ console.log(' ✓ E2: exemption blinds the gate — regression caught');
1016
+ } else {
1017
+ console.error('✗ E2: gate still red — exemption no longer blinds');
1018
+ failed++;
1019
+ }
1020
+ }
1021
+ } finally {
1022
+ writeFileSync(vf, vOrig);
1023
+ writeFileSync(lf, lOrig);
1024
+ assert('restored → content passes', true, () => run('E2-restore', 'bun scripts/validate-content.ts'));
1025
+ }
1026
+ }
1027
+
1028
+ // --- E3: restore the source-only predicate → artifact case fails ---
1029
+ console.log('\nE3 — source-only predicate');
1030
+ {
1031
+ const gf = join(root, 'hooks', 'pipeline-guard.ts');
1032
+ const original = readFileSync(gf, 'utf8');
1033
+ try {
1034
+ const broken = original.replace('if (!sourceChangedNow && !artifactWorkNow()) return;', 'if (!sourceChangedNow) return;');
1035
+ if (broken === original) {
1036
+ console.error('✗ E3: mutation target not found');
1037
+ failed++;
1038
+ } else {
1039
+ writeFileSync(gf, broken);
1040
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1041
+ assert('source-only predicate → artifact case fails', false, () => run('E3', 'bunx vitest run test/hooks.test.ts -t "artifacts written"'));
1042
+ }
1043
+ } finally {
1044
+ writeFileSync(gf, original);
1045
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1046
+ assert('restored → artifact case passes', true, () => run('E3-restore', 'bunx vitest run test/hooks.test.ts -t "artifacts written"'));
1047
+ }
1048
+ }
1049
+
1050
+ // --- E4: remove gh pr create from the FORBIDDEN table → deny case fails ---
1051
+ console.log('\nE4 — forbidden table');
1052
+ {
1053
+ const gf = join(root, 'src', 'guards.ts');
1054
+ const original = readFileSync(gf, 'utf8');
1055
+ try {
1056
+ const broken = original.replace(" [/\\bgh\\s+pr\\s+(create|merge|ready)\\b/, 'opening or merging a PR'],\n", '');
1057
+ if (broken === original) {
1058
+ console.error('✗ E4: mutation target not found');
1059
+ failed++;
1060
+ } else {
1061
+ writeFileSync(gf, broken);
1062
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1063
+ assert('missing pr-create row → deny case fails', false, () => run('E4', 'bunx vitest run test/hooks.test.ts -t "gh pr create"'));
1064
+ }
1065
+ } finally {
1066
+ writeFileSync(gf, original);
1067
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1068
+ assert('restored → deny case passes', true, () => run('E4-restore', 'bunx vitest run test/hooks.test.ts -t "gh pr create"'));
1069
+ }
1070
+ }
1071
+
1072
+ // --- E5-overcorrection: block every git push → feature-push case fails ---
1073
+ console.log('\nE5 — over-broad push matcher');
1074
+ {
1075
+ const gf = join(root, 'src', 'guards.ts');
1076
+ const original = readFileSync(gf, 'utf8');
1077
+ try {
1078
+ const broken = original.replace(
1079
+ " [/\\bgit\\s+push\\b[^|;&]*\\b(main|master|production|release)\\b/, 'pushing to a protected branch'],",
1080
+ " [/\\bgit\\s+push\\b[^|;&]*\\b(main|master|production|release)\\b/, 'pushing to a protected branch'],\n [/\\bgit\\s+push\\b/, 'pushing anything'],",
1081
+ );
1082
+ if (broken === original) {
1083
+ console.error('✗ E5: mutation target not found');
1084
+ failed++;
1085
+ } else {
1086
+ writeFileSync(gf, broken);
1087
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1088
+ assert('push-all matcher → feature-push case fails', false, () => run('E5', 'bunx vitest run test/hooks.test.ts -t "feature-branch push"'));
1089
+ }
1090
+ } finally {
1091
+ writeFileSync(gf, original);
1092
+ execSync('bun scripts/build-hooks.ts', { cwd: root, stdio: 'pipe', timeout: 120000 });
1093
+ assert('restored → feature-push passes', true, () => run('E5-restore', 'bunx vitest run test/hooks.test.ts -t "feature-branch push"'));
1094
+ }
1095
+ }
1096
+
1097
+ // --- E6: remove the harness-matrix guard row → --check-invariants fails ---
1098
+ console.log('\nE6 — matrix guard row');
1099
+ {
1100
+ const mf = join(root, 'docs', 'reference', 'harness-matrix.md');
1101
+ const original = readFileSync(mf, 'utf8');
1102
+ try {
1103
+ const broken = original.replace(/Irreversible-command guard/g, 'Irreversible-command sentry');
1104
+ if (broken === original) {
1105
+ console.error('✗ E6: mutation target not found');
1106
+ failed++;
1107
+ } else {
1108
+ writeFileSync(mf, broken);
1109
+ assert('guard row renamed → --check-invariants fails', false, () => run('E6', 'bun scripts/validate-content.ts --check-invariants'));
1110
+ }
1111
+ } finally {
1112
+ writeFileSync(mf, original);
1113
+ assert('restored → invariants pass', true, () => run('E6-restore', 'bun scripts/validate-content.ts --check-invariants'));
1114
+ }
1115
+ }
1116
+
1117
+ // --- E7: point the mirror at a missing file → mirror test fails ---
1118
+ console.log('\nE7 — todos mirror');
1119
+ {
1120
+ const sf = join(root, 'scripts', 'savepoint.sh');
1121
+ const original = readFileSync(sf, 'utf8');
1122
+ try {
1123
+ const broken = original.replace('TODOS_FILE="$MISSION_DIR/flows/todos.md"', 'TODOS_FILE="$MISSION_DIR/flows/nope.md"');
1124
+ if (broken === original) {
1125
+ console.error('✗ E7: mutation target not found');
1126
+ failed++;
1127
+ } else {
1128
+ writeFileSync(sf, broken);
1129
+ assert('missing mirror → mirror test fails', false, () => run('E7', 'bunx vitest run test/savepoint.test.ts -t "todos mirror"'));
1130
+ }
1131
+ } finally {
1132
+ writeFileSync(sf, original);
1133
+ assert('restored → mirror test passes', true, () => run('E7-restore', 'bunx vitest run test/savepoint.test.ts -t "todos mirror"'));
1134
+ }
1135
+ }
1136
+
1137
+ // --- N1 mutation: remove `case 'initiative'` → --check-doc-integrity red ---
1138
+ console.log('\nN1 — initiative case mutation');
1139
+ {
1140
+ const f = join(root, 'src', 'cli.ts');
1141
+ const original = readFileSync(f, 'utf8');
1142
+ try {
1143
+ const broken = original.replace(" case 'initiative': return initiativeCmd(flags, _);\n", '');
1144
+ if (broken === original) {
1145
+ console.error('✗ N1: mutation target not found');
1146
+ failed++;
1147
+ } else {
1148
+ writeFileSync(f, broken);
1149
+ assert('missing initiative case → doc-integrity fails', false, () => run('N1', 'bun scripts/validate-content.ts --check-doc-integrity'));
1150
+ }
1151
+ } finally {
1152
+ writeFileSync(f, original);
1153
+ assert('restored → doc-integrity passes', true, () => run('N1-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1154
+ }
1155
+ }
1156
+
1157
+ // --- N2 mutation: ANSI escape back into wave-banners.md → banner-format red ---
1158
+ console.log('\nN2 — banner-format mutation');
1159
+ {
1160
+ const f = join(root, 'references', 'wave-banners.md');
1161
+ const original = readFileSync(f, 'utf8');
1162
+ try {
1163
+ const broken = `${original}\nTerminal: wrap in ANSI \`\\x1b[38;2;R;G;Bm\` ... \`\\x1b[0m\`.\n`;
1164
+ writeFileSync(f, broken);
1165
+ assert('ANSI escape in prose → doc-integrity fails', false, () => run('N2', 'bun scripts/validate-content.ts --check-doc-integrity'));
1166
+ } finally {
1167
+ writeFileSync(f, original);
1168
+ assert('restored → doc-integrity passes', true, () => run('N2-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1169
+ }
1170
+ }
1171
+
1172
+ // --- N3 mutation: depth allowlist back to lean → --check-config red ---
1173
+ console.log('\nN3 — depth allowlist mutation');
1174
+ {
1175
+ const f = join(root, 'scripts', 'savepoint.sh');
1176
+ const original = readFileSync(f, 'utf8');
1177
+ try {
1178
+ const broken = original.split('in full|standard|quick').join('in full|standard|lean');
1179
+ if (broken === original) {
1180
+ console.error('✗ N3: mutation target not found');
1181
+ failed++;
1182
+ } else {
1183
+ writeFileSync(f, broken);
1184
+ assert('lean-only allowlist → check-config fails', false, () => run('N3', 'bun scripts/validate-content.ts --check-config'));
1185
+ }
1186
+ } finally {
1187
+ writeFileSync(f, original);
1188
+ assert('restored → check-config passes', true, () => run('N3-restore', 'bun scripts/validate-content.ts --check-config'));
1189
+ }
1190
+ }
1191
+
1192
+ // --- N4 mutation: documented enum value the code rejects → --check-config red ---
1193
+ console.log('\nN4 — documented-enum mutation');
1194
+ {
1195
+ const f = join(root, 'docs', 'concepts', 'config.md');
1196
+ const original = readFileSync(f, 'utf8');
1197
+ try {
1198
+ const broken = original.replace('`review_depth` | full / standard / quick |', '`review_depth` | full / standard / turbo |');
1199
+ if (broken === original) {
1200
+ console.error('✗ N4: mutation target not found');
1201
+ failed++;
1202
+ } else {
1203
+ writeFileSync(f, broken);
1204
+ assert('turbo documented → check-config fails', false, () => run('N4', 'bun scripts/validate-content.ts --check-config'));
1205
+ }
1206
+ } finally {
1207
+ writeFileSync(f, original);
1208
+ assert('restored → check-config passes', true, () => run('N4-restore', 'bun scripts/validate-content.ts --check-config'));
1209
+ }
1210
+ }
1211
+
1212
+ // --- N5 mutation: flow-summary contract removed → content validation red ---
1213
+ console.log('\nN5 — flow-summary mutation');
1214
+ {
1215
+ const f = join(root, 'content', 'skills', 'mugiwara-orchestration', 'SKILL.md');
1216
+ const original = readFileSync(f, 'utf8');
1217
+ try {
1218
+ const broken = original.replace('## Flow summary line\n', '');
1219
+ if (broken === original) {
1220
+ console.error('✗ N5: mutation target not found');
1221
+ failed++;
1222
+ } else {
1223
+ writeFileSync(f, broken);
1224
+ assert('summary contract removed → validation fails', false, () => run('N5', 'bun scripts/validate-content.ts --check-doc-integrity'));
1225
+ }
1226
+ } finally {
1227
+ writeFileSync(f, original);
1228
+ assert('restored → validation passes', true, () => run('N5-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1229
+ }
1230
+ }
1231
+
1232
+ // --- N6 mutation: banner recording removed from marker → hooks banner test red ---
1233
+ console.log('\nN6 — banner-recording mutation');
1234
+ {
1235
+ const f = join(root, 'hooks', 'engagement-marker.ts');
1236
+ const original = readFileSync(f, 'utf8');
1237
+ try {
1238
+ const broken = original
1239
+ .replace(" if (sameSession && typeof prev.last_banner_flow === 'number') bannerFlow = prev.last_banner_flow;\n", '')
1240
+ .replace(" if (sameSession && typeof prev.last_banner_flow_at === 'string') bannerFlowAt = prev.last_banner_flow_at;\n", '');
1241
+ if (broken === original) {
1242
+ console.error('✗ N6: mutation target not found');
1243
+ failed++;
1244
+ } else {
1245
+ writeFileSync(f, broken);
1246
+ run('N6-build', 'bun run build-hooks');
1247
+ assert('recording removed → banner test fails', false, () => run('N6', 'bun test test/hooks.test.ts -t banner'));
1248
+ }
1249
+ } finally {
1250
+ writeFileSync(f, original);
1251
+ run('N6-rebuild', 'bun run build-hooks');
1252
+ assert('restored → banner test passes', true, () => run('N6-restore', 'bun test test/hooks.test.ts -t banner'));
1253
+ }
1254
+ }
1255
+
1256
+ // --- N7 mutation: `mugiwara lessons import` with no CLI case → doc-integrity red ---
1257
+ console.log('\nN7 — lessons-import mutation');
1258
+ {
1259
+ const f = join(root, 'docs', 'adoption.md');
1260
+ const original = readFileSync(f, 'utf8');
1261
+ try {
1262
+ writeFileSync(f, `${original}\nImport with \`mugiwara lessons import <file>\`.\n`);
1263
+ assert('dangling lessons verb → doc-integrity fails', false, () => run('N7', 'bun scripts/validate-content.ts --check-doc-integrity'));
1264
+ } finally {
1265
+ writeFileSync(f, original);
1266
+ assert('restored → doc-integrity passes', true, () => run('N7-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1267
+ }
1268
+ }
1269
+
1270
+ // --- N8 mutation: `/mugiwara mode` slash form → in-session phrase check red ---
1271
+ console.log('\nN8 — slash-mode mutation');
1272
+ {
1273
+ const f = join(root, 'content', 'skills', 'mugiwara-workflow', 'SKILL.md');
1274
+ const original = readFileSync(f, 'utf8');
1275
+ try {
1276
+ const broken = original.replace('Say `mugiwara mode <guided|semi|auto>` in session', '`/mugiwara mode <guided|semi|auto>` applies');
1277
+ if (broken === original) {
1278
+ console.error('✗ N8: mutation target not found');
1279
+ failed++;
1280
+ } else {
1281
+ writeFileSync(f, broken);
1282
+ assert('slash mode phrase → doc-integrity fails', false, () => run('N8', 'bun scripts/validate-content.ts --check-doc-integrity'));
1283
+ }
1284
+ } finally {
1285
+ writeFileSync(f, original);
1286
+ assert('restored → doc-integrity passes', true, () => run('N8-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1287
+ }
1288
+ }
1289
+
1290
+ // --- N9 mutation: unqualified "12 platforms" → README platform-count check red ---
1291
+ console.log('\nN9 — platform-count mutation');
1292
+ {
1293
+ const f = join(root, 'README.md');
1294
+ const original = readFileSync(f, 'utf8');
1295
+ try {
1296
+ const broken = original.replace(
1297
+ '9 via install (Claude, opencode, Copilot, Gemini, Codex, Windsurf, Cline, Kilo, Antigravity) + 3 via marketplace manifest (Cursor, Kimi, Pi)',
1298
+ 'Claude, opencode, Copilot, Gemini, Codex, Cursor, Kimi, Pi, and 5 more',
1299
+ );
1300
+ if (broken === original) {
1301
+ console.error('✗ N9: mutation target not found');
1302
+ failed++;
1303
+ } else {
1304
+ writeFileSync(f, broken);
1305
+ assert('unqualified count → doc-integrity fails', false, () => run('N9', 'bun scripts/validate-content.ts --check-doc-integrity'));
1306
+ }
1307
+ } finally {
1308
+ writeFileSync(f, original);
1309
+ assert('restored → doc-integrity passes', true, () => run('N9-restore', 'bun scripts/validate-content.ts --check-doc-integrity'));
1310
+ }
1311
+ }
1312
+
971
1313
  console.log(`\n${passed} passed, ${failed} failed`);
972
1314
  process.exit(failed > 0 ? 1 : 0);
@@ -365,11 +365,19 @@ if [ -n "$LANE_PREV" ] && [ "$LANE_PREV" != "$LANE" ]; then
365
365
  esac
366
366
  fi
367
367
 
368
- # task counts from plan doc bare name, one file per mission.
368
+ # task counts the execution mirror wins over the plan doc.
369
+ # Zoro tracks one box per task in flows/todos.md as work lands, while plan.md
370
+ # may carry no boxes at all (Steps: inline) or a different-granularity
371
+ # acceptance list. Counting plan-only left finished missions reading 0/N.
372
+ # Mirror wins when it has boxes; plan.md otherwise; sub-plan/ as before.
369
373
  PLAN_FILE="$MISSION_DIR/plan.md"
374
+ TODOS_FILE="$MISSION_DIR/flows/todos.md"
370
375
  TASKS_DONE=0
371
376
  TASKS_TOTAL=0
372
- if [ -n "$PLAN_FILE" ] && [ -f "$PLAN_FILE" ]; then
377
+ if [ -f "$TODOS_FILE" ] && [ "$(count_boxes "$TODOS_FILE" '[ xX]')" -gt 0 ] 2>/dev/null; then
378
+ TASKS_TOTAL=$(count_boxes "$TODOS_FILE" '[ xX]')
379
+ TASKS_DONE=$(count_boxes "$TODOS_FILE" '[xX]')
380
+ elif [ -n "$PLAN_FILE" ] && [ -f "$PLAN_FILE" ]; then
373
381
  # total counts ALL task lines (checked + unchecked); done counts checked only.
374
382
  # A fully-completed plan must read total=N done=N, never total=0 (the old
375
383
  # unchecked-only grep degenerated a done plan to tasks.total=0).
@@ -456,8 +464,12 @@ if [ -f "$MUGIWARA_DIR/config" ]; then
456
464
  _cfg_v=$(grep -E '^verify_merged=' "$MUGIWARA_DIR/config" 2>/dev/null | head -1 | cut -d= -f2- | cut -d'#' -f1 | tr -d '[:space:]')
457
465
  [ -n "$_cfg_v" ] && DEPTH_VERIFY="$_cfg_v"
458
466
  fi
459
- case "$DEPTH_REVIEW" in full|standard|lean) ;; *) DEPTH_REVIEW="full" ;; esac
460
- case "$DEPTH_QUALITY" in full|standard|lean) ;; *) DEPTH_QUALITY="full" ;; esac
467
+ # `quick` is the documented third level; `lean` was an undocumented synonym.
468
+ # Accept both, normalise to the documented name. (N3)
469
+ [ "$DEPTH_REVIEW" = "lean" ] && DEPTH_REVIEW="quick"
470
+ [ "$DEPTH_QUALITY" = "lean" ] && DEPTH_QUALITY="quick"
471
+ case "$DEPTH_REVIEW" in full|standard|quick) ;; *) DEPTH_REVIEW="full" ;; esac
472
+ case "$DEPTH_QUALITY" in full|standard|quick) ;; *) DEPTH_QUALITY="full" ;; esac
461
473
  case "$DEPTH_VERIFY" in on|off) ;; *) DEPTH_VERIFY="off" ;; esac
462
474
 
463
475
  # evidence paths — the mission's flow folder (quoted printf, no sed — mission