@mainwave/cli 0.11.0 → 0.13.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 (43) hide show
  1. package/README.md +203 -16
  2. package/dist/adapters/claude-code.js +3 -3
  3. package/dist/adapters/claude-desktop.js +35 -1
  4. package/dist/adapters/codex-cli.js +16 -16
  5. package/dist/adapters/cursor.js +7 -2
  6. package/dist/adapters/kiro.js +13 -8
  7. package/dist/commands.js +219 -0
  8. package/dist/core/apply.js +47 -8
  9. package/dist/core/auth-commands.js +2 -1
  10. package/dist/core/codecs/kiro-hooks-json.js +1 -1
  11. package/dist/core/codex-trust.js +178 -0
  12. package/dist/core/doctor.js +144 -12
  13. package/dist/core/entry-script.js +2 -3
  14. package/dist/core/format.js +0 -1
  15. package/dist/core/hook-copies.js +157 -0
  16. package/dist/core/install-hooks.js +198 -15
  17. package/dist/core/interview.js +36 -16
  18. package/dist/core/markers.js +209 -44
  19. package/dist/core/redaction.js +188 -0
  20. package/dist/core/skills.js +3 -11
  21. package/dist/core/status.js +21 -1
  22. package/dist/core/store.js +254 -4
  23. package/dist/core/wizard.js +91 -6
  24. package/dist/main.js +173 -163
  25. package/hooks/codex-turns.mjs +584 -0
  26. package/hooks/kiro-otlp.mjs +10 -1
  27. package/hooks/mainwave-hook.mjs +27 -3
  28. package/hooks/marker-core.mjs +66 -8
  29. package/hooks/matchers.json +98 -1
  30. package/hooks/redaction-data.mjs +209 -0
  31. package/hooks/redaction-json.mjs +215 -0
  32. package/hooks/redaction-pattern.mjs +503 -0
  33. package/hooks/redaction.d.mts +84 -0
  34. package/hooks/redaction.mjs +701 -0
  35. package/hooks/vocabulary.mjs +41 -2
  36. package/package.json +3 -1
  37. package/skills/mainwave-instrument/SKILL.md +24 -6
  38. package/skills/mainwave-instrument/reference/frameworks.md +4 -2
  39. package/skills/mainwave-instrument/reference/troubleshooting.md +4 -0
  40. package/skills/mainwave-instrument-node/SKILL.md +83 -38
  41. package/skills/mainwave-instrument-node/reference/api.md +16 -16
  42. package/skills/mainwave-instrument-node/reference/frameworks.md +42 -27
  43. package/skills/mainwave-instrument-node/reference/troubleshooting.md +11 -7
@@ -7,6 +7,7 @@ import { dropInNames } from './effective-settings.js';
7
7
  import { GIT_BASH_FIX, GIT_BASH_MISSING_REASON } from './git-bash.js';
8
8
  import { entryCommand, entryVersionId, HOOK_DISPATCHER_SCRIPT, HOOK_ENTRY_SCRIPT, HOOK_NODE_ENTRY_SCRIPT, nodeEntryCommand, ORG_DELIVERED_MARK, parseEntryCommand, renderHookEntry, } from './entry-script.js';
9
9
  import { isManagedLayer, isPolicyKey } from './layer-policy.js';
10
+ import { canonicalPacks, packOrder } from './redaction.js';
10
11
  export const MANAGED_BY = '--managed-by @mainwave/cli';
11
12
  export const PAYLOAD_CLI_SPEC = 'latest';
12
13
  const OWNED_CLI_MARKERS = [MANAGED_BY, '.mainwave/hooks', '.mainwave\\hooks'];
@@ -29,17 +30,30 @@ export const commandGeneration = (command) => command.includes(HOOK_ENTRY_SCRIPT
29
30
  : BOOTSTRAP_RE.test(command)
30
31
  ? 'bootstrap'
31
32
  : 'legacy';
32
- export const INSTALLED_HOOK_EVENTS = [
33
+ const INSTALLED_HOOK_EVENTS = [
33
34
  'SessionStart',
34
35
  'UserPromptSubmit',
35
36
  'PostToolUse',
36
37
  'StopFailure',
38
+ 'Stop',
39
+ 'Interrupt',
40
+ 'PermissionRequest',
41
+ 'PreModelRequest',
42
+ 'SubagentStart',
43
+ 'SubagentStop',
37
44
  ];
38
- export const MARKER_HOOK_EVENTS = INSTALLED_HOOK_EVENTS;
45
+ const MARKER_HOOK_EVENTS = INSTALLED_HOOK_EVENTS;
39
46
  const ENTRY_EVENTS = [
40
47
  'UserPromptSubmit',
41
48
  'PostToolUse',
42
49
  'StopFailure',
50
+ 'SessionStart',
51
+ 'Stop',
52
+ 'Interrupt',
53
+ 'PermissionRequest',
54
+ 'PreModelRequest',
55
+ 'SubagentStart',
56
+ 'SubagentStop',
43
57
  ];
44
58
  const MATCHER_EVENTS = new Set(['PostToolUse', 'SessionStart']);
45
59
  const TOOL_EVENTS = new Set(['PostToolUse']);
@@ -63,15 +77,42 @@ export const shellHome = (plat = process.platform, env = process.env, dirExists
63
77
  return drivePath;
64
78
  return env.USERPROFILE || homedir();
65
79
  };
66
- export const installHooksCommand = (version, { quiet = true } = {}) => `cd "$HOME" && npx -y --registry=https://registry.npmjs.org ` +
67
- `@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}`;
68
- export const bootstrapCommand = (version) => `{ ${installHooksCommand(version)}; } >/dev/null 2>&1; exit 0`;
80
+ export const installHooksCommand = (version, { quiet = true, redactionPacks = [], host = DEFAULT_MARKER_TOOL, } = {}) => `cd "$HOME" && npx -y --registry=https://registry.npmjs.org ` +
81
+ `@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}` +
82
+ (host === 'codex' ? ' --host codex' : '') +
83
+ (redactionPacks.length > 0
84
+ ? ` ${REDACTION_PACKS_FLAG} ${canonicalPacks(redactionPacks).join(',')}`
85
+ : '');
86
+ export const bootstrapCommand = (version, redactionPacks = []) => `{ ${installHooksCommand(version, { redactionPacks })}; } >/dev/null 2>&1; exit 0`;
87
+ export const codexBootstrapCommand = (version, plat = process.platform) => plat === 'win32'
88
+ ? `(cd /d "%USERPROFILE%" && npx -y --registry=https://registry.npmjs.org ` +
89
+ `@mainwave/cli@${version} install-hooks --quiet --host codex) >NUL 2>&1 & exit /b 0`
90
+ : `{ ${installHooksCommand(version, { host: 'codex' })}; } >/dev/null 2>&1; exit 0`;
91
+ const REDACTION_PACKS_FLAG = '--redaction-packs';
92
+ export const redactionPacksIn = (command) => {
93
+ const args = /\binstall-hooks\b([^;}]*)/.exec(command)?.[1];
94
+ if (args === undefined)
95
+ return undefined;
96
+ const found = /(?:^|\s)--redaction-packs(?:=|\s+)('[^']*'|"[^"]*"|[^\s'"]+)/.exec(args);
97
+ if (found === null)
98
+ return undefined;
99
+ const value = found[1].replace(/^(['"])(.*)\1$/, '$2');
100
+ return [...new Set(value.split(',').map((n) => n.trim()))].filter((n) => n !== '');
101
+ };
69
102
  export const BOOTSTRAP_MATCHER = 'startup|resume|fork';
70
103
  export const BOOTSTRAP_KEY = 'SessionStart:bootstrap';
71
- export const bootstrapGroup = () => ({
104
+ export const bootstrapGroup = (redactionPacks = [], host = DEFAULT_MARKER_TOOL) => ({
72
105
  event: 'SessionStart',
73
106
  matcher: BOOTSTRAP_MATCHER,
74
- hooks: [{ type: 'command', command: bootstrapCommand(PAYLOAD_CLI_SPEC), async: true }],
107
+ hooks: [
108
+ {
109
+ type: 'command',
110
+ command: host === 'codex'
111
+ ? codexBootstrapCommand(PAYLOAD_CLI_SPEC)
112
+ : bootstrapCommand(PAYLOAD_CLI_SPEC, redactionPacks),
113
+ async: true,
114
+ },
115
+ ],
75
116
  });
76
117
  const SAFE_ROUTE = /^[a-z][a-z0-9-]*$/;
77
118
  export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
@@ -138,8 +179,20 @@ export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
138
179
  };
139
180
  });
140
181
  };
141
- const SHARED_HOOK_MODULES = ['marker-core.mjs', 'vocabulary.mjs', HOOK_DISPATCHER_SCRIPT];
142
- export const featureModule = (feature) => `${feature}.mjs`;
182
+ export const REDACTION_HOOK_MODULES = [
183
+ 'redaction.mjs',
184
+ 'redaction-pattern.mjs',
185
+ 'redaction-json.mjs',
186
+ 'redaction-data.mjs',
187
+ ];
188
+ export const lacksRedactionModules = (dir) => REDACTION_HOOK_MODULES.every((f) => !existsSync(join(dir, f)));
189
+ const SHARED_HOOK_MODULES = [
190
+ 'marker-core.mjs',
191
+ 'vocabulary.mjs',
192
+ ...REDACTION_HOOK_MODULES,
193
+ HOOK_DISPATCHER_SCRIPT,
194
+ ];
195
+ const featureModule = (feature) => `${feature}.mjs`;
143
196
  export const hookScriptFiles = (matchers) => [
144
197
  ...SHARED_HOOK_MODULES,
145
198
  ...new Set(matchers.flatMap((m) => m.features.map(featureModule))),
@@ -154,8 +207,8 @@ export const copyHookScripts = async (files, srcDir = packagedHooksDir(), destDi
154
207
  }
155
208
  return destDir;
156
209
  };
157
- export const MANAGED_POINTER = 'current.json';
158
- export const MANAGED_VERSIONS_DIR = 'versions';
210
+ const MANAGED_POINTER = 'current.json';
211
+ const MANAGED_VERSIONS_DIR = 'versions';
159
212
  export const MANAGED_ENTRY_SCRIPT = 'managed-entry.mjs';
160
213
  const MANAGED_ENTRY_MARK = 'mainwave managed hook entry';
161
214
  const RETIRED_GRACE_MS = 10 * 60 * 1000;
@@ -172,7 +225,7 @@ const LEGACY_SCRIPT_ROUTES = {
172
225
  'glab-mr-marker.mjs': { event: 'PostToolUse', route: 'glab' },
173
226
  'claude-plan-snapshot.mjs': { event: 'UserPromptSubmit' },
174
227
  };
175
- export const legacyScriptReleased = (name) => LEGACY_ENTRY_NAMES.includes(name);
228
+ const legacyScriptReleased = (name) => LEGACY_ENTRY_NAMES.includes(name);
176
229
  const VERSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
177
230
  const versionDirName = (version, files, bodies) => {
178
231
  const hash = createHash('sha256');
@@ -206,6 +259,15 @@ export const readEntryVersion = async (destDir) => {
206
259
  const text = await fs.readFile(join(destDir, HOOK_ENTRY_SCRIPT), 'utf8').catch(() => null);
207
260
  return text === null ? undefined : entryVersionId(text);
208
261
  };
262
+ export const releaseBeforeRedaction = async (destDir) => {
263
+ const id = await readEntryVersion(destDir);
264
+ if (id === undefined)
265
+ return undefined;
266
+ const dir = join(destDir, MANAGED_VERSIONS_DIR, id);
267
+ if (!existsSync(join(dir, HOOK_DISPATCHER_SCRIPT)))
268
+ return undefined;
269
+ return lacksRedactionModules(dir) ? { id, dir } : undefined;
270
+ };
209
271
  export const stageManagedVersion = async (files, srcDir, destDir, version) => {
210
272
  const bodies = await Promise.all(files.map((f) => fs.readFile(join(srcDir, f))));
211
273
  const id = versionDirName(version, files, bodies);
@@ -288,7 +350,7 @@ export const writeHookEntry = async (staged, destDir, routes, nodePath = process
288
350
  await retire(destDir, previous, staged.id);
289
351
  return true;
290
352
  };
291
- export const writeNodeEntry = async (srcDir, destDir) => {
353
+ const writeNodeEntry = async (srcDir, destDir) => {
292
354
  const body = await fs.readFile(join(srcDir, HOOK_NODE_ENTRY_SCRIPT));
293
355
  const path = join(destDir, HOOK_NODE_ENTRY_SCRIPT);
294
356
  const current = await fs.readFile(path).catch(() => null);
@@ -381,7 +443,7 @@ export const resolveManagedScript = async (script) => {
381
443
  const target = join(dirname(script), MANAGED_VERSIONS_DIR, dir, basename(script));
382
444
  return existsSync(target) ? target : undefined;
383
445
  };
384
- export const hooksRootDir = (managedDir = managedHooksDir()) => dirname(managedDir);
446
+ const hooksRootDir = (managedDir = managedHooksDir()) => dirname(managedDir);
385
447
  export const optOutFlagPath = (host, optOut, root = hooksRootDir()) => join(root, 'off', host, optOut);
386
448
  export const writeOptOutFlags = async (host, on, root = hooksRootDir()) => {
387
449
  for (const [optOut, enabled] of Object.entries(on)) {
@@ -437,12 +499,20 @@ export const scriptPathFromCommand = (command) => {
437
499
  const m = /^(?:\$\{HOME\}|\$HOME)(?=\/)/.exec(raw);
438
500
  return m ? shellHome() + raw.slice(m[0].length) : raw;
439
501
  };
440
- export const hookShape = (host) => host === 'codex' ? { timeout: 5 } : { async: true };
502
+ export const hookShape = (event, host = DEFAULT_MARKER_TOOL) => {
503
+ if (host === 'codex' && event === 'Stop')
504
+ return { timeout: CODEX_STOP_TIMEOUT_SEC };
505
+ if (host === 'codex' && event === 'Interrupt')
506
+ return { timeout: CODEX_INTERRUPT_TIMEOUT_SEC };
507
+ return { async: true };
508
+ };
509
+ const CODEX_STOP_TIMEOUT_SEC = 5;
510
+ const CODEX_INTERRUPT_TIMEOUT_SEC = 2;
441
511
  const groupFor = (m, host) => {
442
512
  const hook = {
443
513
  type: 'command',
444
514
  command: buildHookCommand(host, m.event, m.route),
445
- ...hookShape(host),
515
+ ...hookShape(m.event, host),
446
516
  };
447
517
  if (m.if !== undefined && host !== 'codex')
448
518
  hook.if = m.if;
@@ -453,11 +523,11 @@ const groupFor = (m, host) => {
453
523
  };
454
524
  };
455
525
  export const buildHookGroups = (matchers, host = DEFAULT_MARKER_TOOL) => matchers.map((m) => groupFor(m, host));
456
- export const hostRunsBootstrap = (host) => host === DEFAULT_MARKER_TOOL;
526
+ export const hostRunsBootstrap = (host) => host === DEFAULT_MARKER_TOOL || host === 'codex';
457
527
  export const userHookGroups = (hosted, on, delivered, host = DEFAULT_MARKER_TOOL) => {
458
528
  const selected = selectHookMatchers(hosted, on);
459
529
  const groups = [
460
- ...(hostRunsBootstrap(host) && selected.length > 0 ? [bootstrapGroup()] : []),
530
+ ...(hostRunsBootstrap(host) && selected.length > 0 ? [bootstrapGroup([], host)] : []),
461
531
  ...buildHookGroups(selected, host),
462
532
  ];
463
533
  return groups.filter((g) => {
@@ -508,7 +578,7 @@ export const ownedGroupsInDoc = (doc) => {
508
578
  }
509
579
  return out;
510
580
  };
511
- export const malformedEventMessage = (event) => `\`hooks.${event}\` in the settings file is not an array, so Mainwave left it untouched and installed no ${event} hook there. ` +
581
+ const malformedEventMessage = (event) => `\`hooks.${event}\` in the settings file is not an array, so Mainwave left it untouched and installed no ${event} hook there. ` +
512
582
  'Fix or remove that value, then re-run setup.';
513
583
  const effectiveMatcher = (matcher) => matcher === undefined || matcher === '' || matcher === '*' ? NO_MATCHER : matcher;
514
584
  const sameGroup = (before, after) => before.event === groupEvent(after) &&
@@ -517,6 +587,14 @@ const sameGroup = (before, after) => before.event === groupEvent(after) &&
517
587
  before.timeout === after.hooks[0]?.timeout &&
518
588
  (before.async === true) === (after.hooks[0]?.async === true) &&
519
589
  before.if === after.hooks[0]?.if;
590
+ const sameRoute = (before, after) => {
591
+ const command = after.hooks[0]?.command;
592
+ if (command === undefined || before.event !== groupEvent(after))
593
+ return false;
594
+ const host = parseEntryCommand(command)?.host ?? DEFAULT_MARKER_TOOL;
595
+ const key = routeKeyOf(command, host);
596
+ return key !== undefined && key === routeKeyOf(before.command, host);
597
+ };
520
598
  export const planMarkers = (doc, groups, remove = () => true) => {
521
599
  if (!isPlainObject(doc))
522
600
  throw new Error('expected the settings document to be a JSON object');
@@ -536,25 +614,53 @@ export const planMarkers = (doc, groups, remove = () => true) => {
536
614
  skippedEvents.push({ event, message: malformedEventMessage(event) });
537
615
  }
538
616
  const writable = groups.filter((g) => !skipped.has(groupEvent(g)));
539
- const before = [];
617
+ const identical = new Set();
618
+ const placed = new Set();
540
619
  let pruned = false;
620
+ const removedInfo = [];
541
621
  for (const event of MARKER_HOOK_EVENTS) {
542
622
  if (skipped.has(event))
543
623
  continue;
544
- const current = hooks[event];
545
- let removedHere = 0;
546
- const kept = (current ?? []).filter((g) => {
624
+ const current = hooks[event] ?? [];
625
+ const owned = current.map((g) => {
547
626
  const o = groupOwnership(g);
548
627
  if (o === null || !isPlainObject(g))
549
- return true;
628
+ return null;
550
629
  const info = ownedGroupInfo(g, o, event);
551
- if (!remove(o, info))
552
- return true;
553
- before.push(info);
554
- removedHere++;
555
- return false;
630
+ return remove(o, info) ? info : null;
631
+ });
632
+ const keep = owned.map((info) => {
633
+ if (info === null)
634
+ return false;
635
+ const same = writable.find((a) => !identical.has(a) && sameGroup(info, a));
636
+ if (same === undefined)
637
+ return false;
638
+ identical.add(same);
639
+ return true;
640
+ });
641
+ let removedHere = 0;
642
+ const kept = [];
643
+ current.forEach((g, i) => {
644
+ const info = owned[i];
645
+ if (info === null || info === undefined || keep[i]) {
646
+ kept.push(g);
647
+ return;
648
+ }
649
+ removedInfo.push(info);
650
+ const slot = writable.find((a) => !identical.has(a) && !placed.has(a) && sameRoute(info, a));
651
+ if (slot === undefined) {
652
+ removedHere++;
653
+ return;
654
+ }
655
+ placed.add(slot);
656
+ kept.push(writtenGroup(slot));
556
657
  });
557
- const next = [...kept, ...writable.filter((g) => groupEvent(g) === event).map(writtenGroup)];
658
+ const next = [
659
+ ...kept,
660
+ ...writable
661
+ .filter((g) => groupEvent(g) === event && !identical.has(g) && !placed.has(g))
662
+ .map(writtenGroup),
663
+ ];
558
664
  if (next.length > 0)
559
665
  hooks[event] = next;
560
666
  else if (removedHere > 0) {
@@ -567,9 +673,9 @@ export const planMarkers = (doc, groups, remove = () => true) => {
567
673
  next.hooks = hooks;
568
674
  else
569
675
  delete next.hooks;
570
- const unchanged = before.filter((b) => writable.some((a) => sameGroup(b, a))).length;
571
- const removed = before.filter((b) => !writable.some((a) => sameGroup(b, a)));
572
- const added = writable.filter((a) => !before.some((b) => sameGroup(b, a)));
676
+ const unchanged = identical.size;
677
+ const removed = removedInfo;
678
+ const added = writable.filter((a) => !identical.has(a));
573
679
  return {
574
680
  next,
575
681
  removed,
@@ -774,6 +880,17 @@ export const managedMarkerDeliveries = (scans) => new Set(activeManagedScans(sca
774
880
  const key = routeKeyOf(g.command);
775
881
  return key === undefined ? [] : [key];
776
882
  })));
883
+ const managedBootstraps = (scans) => activeManagedScans(scans)
884
+ .filter((s) => s.managed)
885
+ .flatMap((s) => s.groups)
886
+ .filter((g) => g.ownership === 'cli' && g.event === 'SessionStart' && isBootstrapCommand(g.command));
887
+ export const managedRedactionPacks = (scans) => {
888
+ const named = managedBootstraps(scans)
889
+ .map((g) => redactionPacksIn(g.command))
890
+ .filter((packs) => packs !== undefined);
891
+ return named.length === 0 ? undefined : packOrder(named.flat());
892
+ };
893
+ export const managedRunsBootstrap = (scans) => managedBootstraps(scans).length > 0;
777
894
  export const scanRoutes = (scan, host = DEFAULT_MARKER_TOOL) => [
778
895
  ...new Set(scan.groups
779
896
  .filter((g) => g.ownership === 'cli')
@@ -797,6 +914,15 @@ export const routeLabel = (key) => {
797
914
  'PostToolUse:linear': 'the Linear ticket marker',
798
915
  'PostToolUse:jira': 'the Jira ticket marker',
799
916
  StopFailure: 'the Claude turn-error span',
917
+ 'UserPromptSubmit:turns': 'the Codex turn start',
918
+ 'Stop:turns': 'the Codex turn end',
919
+ 'Interrupt:turns': 'the Codex interrupt',
920
+ 'PermissionRequest:turns': 'the Codex permission wait',
921
+ 'PostToolUse:turns': 'the Codex tool-call tracker',
922
+ 'PreModelRequest:turns': 'the Codex model-request tracker',
923
+ 'SubagentStart:turns': 'the Codex subagent start',
924
+ 'SubagentStop:turns': 'the Codex subagent end',
925
+ 'SessionStart:turns': 'the Codex session-start turn cleanup',
800
926
  };
801
927
  return labels[key] ?? key;
802
928
  };
@@ -997,12 +1123,28 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
997
1123
  }
998
1124
  continue;
999
1125
  }
1000
- if (host !== 'codex' && g.async !== true) {
1126
+ const want = generation === 'bootstrap' ? { async: true } : hookShape(g.event, host);
1127
+ if (want.async !== true && (g.async === true || g.timeout !== want.timeout)) {
1001
1128
  issues.push({
1002
1129
  level: 'warn',
1003
- message: `The Mainwave hook ${shortCommand(g.command)} under ${g.event} in ${g.path} is not async, so ` +
1004
- `Claude Code waits for it on every ${g.event === 'PostToolUse' ? 'matching tool call' : g.event}. ` +
1005
- fixFor(g.managed, 'Re-run setup to rewrite it.'),
1130
+ message: `The Mainwave hook ${shortCommand(g.command)} under ${g.event} in ${g.path} should be synchronous with ` +
1131
+ `a ${want.timeout} s timeout` +
1132
+ (g.async === true
1133
+ ? ', but it runs in the background, so `codex exec` can exit before it sends the last turn. '
1134
+ : `, but it has ${g.timeout === undefined ? 'no timeout' : `a ${g.timeout} s timeout`}. `) +
1135
+ fixFor(g.managed, 'Re-run `mainwave-cli setup codex` to rewrite it, then approve the changed hooks in /hooks.'),
1136
+ });
1137
+ }
1138
+ else if (want.async === true && g.async !== true) {
1139
+ const tool = host === 'codex' ? 'Codex' : 'Claude Code';
1140
+ issues.push({
1141
+ level: 'warn',
1142
+ message: `The Mainwave hook ${shortCommand(g.command)} under ${g.event} in ${g.path} is not async` +
1143
+ (g.timeout === undefined ? '' : ` (it still has the ${g.timeout} s timeout form)`) +
1144
+ `, so ${tool} waits for it on every ${g.event === 'PostToolUse' ? 'matching tool call' : g.event}. ` +
1145
+ fixFor(g.managed, host === 'codex'
1146
+ ? 'Re-run `mainwave-cli setup codex` to rewrite it, then approve the changed hooks in /hooks.'
1147
+ : 'Re-run setup to rewrite it.'),
1006
1148
  });
1007
1149
  }
1008
1150
  if (generation === 'bootstrap') {
@@ -1076,7 +1218,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
1076
1218
  if (!entryChecked) {
1077
1219
  entryChecked = true;
1078
1220
  const nodeEntry = cli.some((c) => c.command.includes(HOOK_NODE_ENTRY_SCRIPT));
1079
- issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry)));
1221
+ issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry, layout.redaction ?? 'off')));
1080
1222
  }
1081
1223
  }
1082
1224
  const anyCurrent = cli.some((g) => commandGeneration(g.command) === 'entry');
@@ -1084,6 +1226,14 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
1084
1226
  const managedCurrent = cli.some((g) => g.managed && commandGeneration(g.command) === 'entry');
1085
1227
  const wanted = managedCurrent ? matchers : selected;
1086
1228
  const missing = wanted.filter((m) => !seenRoutes.has(deliveryKey(m.event, m.route)));
1229
+ if (host === 'codex' && selected.length > 0 && !seenRoutes.has(BOOTSTRAP_KEY)) {
1230
+ issues.push({
1231
+ level: 'warn',
1232
+ message: `The Mainwave session-start refresh (install-hooks) is missing from Codex's hooks file, so a new release's hook scripts ` +
1233
+ 'and routes reach this machine only when you re-run setup. ' +
1234
+ 'Re-run `mainwave-cli setup codex`, then approve the new hook in /hooks.',
1235
+ });
1236
+ }
1087
1237
  if (missing.length > 0) {
1088
1238
  issues.push({
1089
1239
  level: managedCurrent ? 'info' : 'warn',
@@ -1111,7 +1261,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
1111
1261
  }
1112
1262
  return issues;
1113
1263
  };
1114
- export const entryIssues = async (managedDir, matchers, managed, nodeEntry = false) => {
1264
+ const entryIssues = async (managedDir, matchers, managed, nodeEntry = false, redaction = 'off') => {
1115
1265
  const entry = join(managedDir, HOOK_ENTRY_SCRIPT);
1116
1266
  const fix = managed
1117
1267
  ? 'Start a new Claude Code session (the managed settings install it at startup), or ' +
@@ -1139,12 +1289,27 @@ export const entryIssues = async (managedDir, matchers, managed, nodeEntry = fal
1139
1289
  }
1140
1290
  const missing = hookScriptFiles(matchers).filter((f) => !existsSync(join(release, f)));
1141
1291
  if (missing.length > 0) {
1142
- return [
1143
- {
1292
+ const predates = lacksRedactionModules(release);
1293
+ const redactionModules = REDACTION_HOOK_MODULES;
1294
+ const rest = predates ? missing.filter((f) => !redactionModules.includes(f)) : missing;
1295
+ const found = [];
1296
+ if (predates && redaction !== 'off') {
1297
+ found.push({
1298
+ level: redaction === 'file' ? 'error' : 'warn',
1299
+ message: `Release ${id} of the Mainwave hooks predates redaction (it lacks ${REDACTION_HOOK_MODULES.join(', ')}), so its hooks send spans without applying redaction rules` +
1300
+ (redaction === 'file'
1301
+ ? ', although redaction is on'
1302
+ : ', although credential redaction is on by default') +
1303
+ `. ${fix}`,
1304
+ });
1305
+ }
1306
+ if (rest.length > 0) {
1307
+ found.push({
1144
1308
  level: 'warn',
1145
- message: `Release ${id} of the Mainwave hooks lacks ${missing.join(', ')}, so the hooks that need ${missing.length === 1 ? 'it' : 'them'} send nothing until a newer release is installed. ${fix}`,
1146
- },
1147
- ];
1309
+ message: `Release ${id} of the Mainwave hooks lacks ${rest.join(', ')}, so the hooks that need ${rest.length === 1 ? 'it' : 'them'} send nothing until a newer release is installed. ${fix}`,
1310
+ });
1311
+ }
1312
+ return found;
1148
1313
  }
1149
1314
  const node = join(managedDir, HOOK_NODE_ENTRY_SCRIPT);
1150
1315
  if (nodeEntry && !existsSync(node)) {
@@ -0,0 +1,188 @@
1
+ import { isAbsolute, resolve } from 'node:path';
2
+ import { loadHookRedaction, readRedactionFile, recordedOrgPacks, REDACTION_PACKS, } from '../../hooks/redaction.mjs';
3
+ import { tildify } from './post-setup.js';
4
+ export const canonicalPacks = (names) => {
5
+ if (names.length === 0)
6
+ throw new Error('no redaction pack named');
7
+ const known = REDACTION_PACKS;
8
+ const seen = new Set();
9
+ for (const name of names) {
10
+ if (!known.includes(name)) {
11
+ throw new Error(`unknown redaction pack ${JSON.stringify(name)} (known: ${REDACTION_PACKS.join(', ')})`);
12
+ }
13
+ if (seen.has(name))
14
+ throw new Error(`redaction pack ${JSON.stringify(name)} is named twice`);
15
+ seen.add(name);
16
+ }
17
+ return REDACTION_PACKS.filter((name) => seen.has(name));
18
+ };
19
+ export const packOrder = (names) => {
20
+ const known = REDACTION_PACKS;
21
+ return [
22
+ ...known.filter((name) => names.includes(name)),
23
+ ...new Set(names.filter((name) => !known.includes(name))),
24
+ ];
25
+ };
26
+ export const parseRedactionPacks = (value) => {
27
+ if (value === undefined || value.trim() === '') {
28
+ throw new Error(`--redaction-packs requires a comma-separated list of packs (${REDACTION_PACKS.join(', ')})`);
29
+ }
30
+ try {
31
+ return canonicalPacks(value.split(',').map((name) => name.trim()));
32
+ }
33
+ catch (err) {
34
+ throw new Error(`--redaction-packs: ${err instanceof Error ? err.message : String(err)}`);
35
+ }
36
+ };
37
+ export const redactionView = ({ configDir } = {}) => {
38
+ const loaded = loadHookRedaction({ configDir });
39
+ const configDirs = recordedOrgPacks();
40
+ const scoped = configDir === undefined
41
+ ? packOrder(Object.values(configDirs).flat())
42
+ : packOrder(Object.entries(configDirs)
43
+ .filter(([dir]) => isAbsolute(dir) && resolve(dir) === resolve(configDir))
44
+ .flatMap(([, packs]) => packs));
45
+ const org = Object.keys(configDirs).length === 0
46
+ ? {}
47
+ : {
48
+ org: {
49
+ setBy: 'managed-settings',
50
+ packs: scoped,
51
+ ...(configDir === undefined ? {} : { configDir }),
52
+ configDirs,
53
+ },
54
+ };
55
+ if (loaded.state === 'off')
56
+ return { state: 'off', reason: 'secrets-off', ...org };
57
+ if (loaded.state === 'error') {
58
+ return {
59
+ state: 'error',
60
+ ...(loaded.file === undefined ? {} : { file: loaded.file }),
61
+ ...(loaded.org === true ? { cause: 'org' } : {}),
62
+ reason: loaded.reason,
63
+ ...org,
64
+ };
65
+ }
66
+ return {
67
+ state: 'on',
68
+ source: loaded.source,
69
+ ...(loaded.source === 'file' ? { file: loaded.file } : {}),
70
+ packs: loaded.redactor.packs,
71
+ summary: loaded.redactor.summary,
72
+ ...org,
73
+ };
74
+ };
75
+ export const hasRulesFile = (view) => view.state === 'error' || (view.state === 'on' && view.source === 'file');
76
+ export const checkRedactionFile = (path) => {
77
+ const file = resolve(path);
78
+ readRedactionFile(file);
79
+ return file;
80
+ };
81
+ export const nextRedactionChoice = (current, change) => {
82
+ if (change.file === undefined && change.noRedaction !== true && change.secrets === undefined) {
83
+ return undefined;
84
+ }
85
+ const base = typeof current === 'object' && current !== null && !Array.isArray(current);
86
+ const next = base ? { ...current } : {};
87
+ if (change.file !== undefined)
88
+ next.file = change.file;
89
+ else if (change.noRedaction === true)
90
+ delete next.file;
91
+ if (change.secrets === false)
92
+ next.secrets = false;
93
+ else if (change.secrets === true)
94
+ delete next.secrets;
95
+ return Object.keys(next).length === 0 ? null : next;
96
+ };
97
+ const SET_BY_ORG = "set by your organization's managed settings";
98
+ const orgLines = (org, indent) => {
99
+ if (org === undefined)
100
+ return [];
101
+ if (org.configDir !== undefined) {
102
+ return org.packs.length === 0
103
+ ? []
104
+ : [`${indent} organization packs: ${org.packs.join(', ')} (${SET_BY_ORG})`];
105
+ }
106
+ const dirs = Object.entries(org.configDirs);
107
+ return [
108
+ `${indent} organization packs (${SET_BY_ORG}), by Claude config dir:`,
109
+ ...dirs.map(([dir, packs]) => `${indent} ${tildify(dir)}: ${packs.join(', ')}`),
110
+ ];
111
+ };
112
+ export const redactionLines = (view, indent = '') => {
113
+ if (view.state === 'off') {
114
+ return [
115
+ `${indent}off (secrets turned off)`,
116
+ `${indent} credentials are not stripped; run setup with --redact-secrets to turn the default back on`,
117
+ ...orgLines(view.org, indent),
118
+ ];
119
+ }
120
+ if (view.state === 'error') {
121
+ return [
122
+ `${indent}error — hooks send nothing until it is fixed`,
123
+ ...(view.file === undefined ? [] : [`${indent} rules file: ${tildify(view.file)}`]),
124
+ `${indent} ${view.reason}`,
125
+ ...orgLines(view.org, indent),
126
+ ];
127
+ }
128
+ return [
129
+ view.file === undefined && (view.org?.packs.length ?? 0) === 0
130
+ ? `${indent}on (default)`
131
+ : `${indent}on`,
132
+ ...(view.file === undefined ? [] : [`${indent} rules file: ${tildify(view.file)}`]),
133
+ `${indent} packs: ${view.packs.length > 0 ? view.packs.join(', ') : 'none'}`,
134
+ ...orgLines(view.org, indent),
135
+ `${indent} summary: ${view.summary}`,
136
+ ];
137
+ };
138
+ const PROBE = {
139
+ collectorUrl: 'https://collector.invalid',
140
+ apiKey: 'redaction-probe',
141
+ };
142
+ const carriesOptIns = (adapter) => {
143
+ const all = (on) => ({
144
+ userPrompts: on,
145
+ toolDetails: on,
146
+ toolContent: on,
147
+ repository: on,
148
+ });
149
+ const build = (on) => JSON.stringify(adapter.buildEnv({ ...PROBE, optIns: all(on) }));
150
+ return build(true) !== build(false);
151
+ };
152
+ const exportsNatively = (adapter) => adapter.bundledHookScripts === undefined;
153
+ export const sendsUnredactedContent = (adapter, optIns) => {
154
+ if (!exportsNatively(adapter))
155
+ return false;
156
+ if (!carriesOptIns(adapter))
157
+ return true;
158
+ if (optIns === undefined)
159
+ return false;
160
+ return (optIns.userPrompts || optIns.toolDetails || optIns.toolContent || optIns.repository === true);
161
+ };
162
+ const list = (names) => names.length <= 2 ? names.join(' and ') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
163
+ export const uncoveredNotice = (uncovered) => {
164
+ const names = uncovered.map((a) => a.displayName);
165
+ const partial = uncovered.filter((a) => carriesOptIns(a) && a.alwaysOnOptIns !== undefined);
166
+ const switchable = uncovered
167
+ .filter((a) => carriesOptIns(a) && a.alwaysOnOptIns === undefined)
168
+ .map((a) => a.displayName);
169
+ const fixed = uncovered.filter((a) => !carriesOptIns(a)).map((a) => a.displayName);
170
+ return [
171
+ `Redaction covers the spans mainwave-cli's hooks send. ${list(names)} ` +
172
+ `${names.length === 1 ? 'exports' : 'export'} content through ` +
173
+ `${names.length === 1 ? 'its' : 'their'} own OpenTelemetry exporter, which the CLI is not in the ` +
174
+ 'path of, so that content is not redacted.',
175
+ ...(switchable.length > 0
176
+ ? [`Run setup with --opt-in none to stop ${list(switchable)} sending content.`]
177
+ : []),
178
+ ...(partial.length > 0
179
+ ? [
180
+ `${list(partial.map((a) => a.displayName))}: --opt-in none stops only prompt text; ` +
181
+ 'its tool commands and results are exported whatever --opt-in says.',
182
+ ]
183
+ : []),
184
+ ...(fixed.length > 0
185
+ ? [`${list(fixed)}: what it exports is set where its export is configured, not by --opt-in.`]
186
+ : []),
187
+ ].join(' ');
188
+ };
@@ -11,7 +11,7 @@ export const SKILL_NAMES = [
11
11
  'mainwave-instrument-node',
12
12
  ];
13
13
  export const packagedSkillsDir = () => fileURLToPath(new URL('../../skills/', import.meta.url));
14
- export const installedSkillsDir = () => join(homedir(), '.mainwave', 'skills');
14
+ const installedSkillsDir = () => join(homedir(), '.mainwave', 'skills');
15
15
  export const copySkillBundle = async (name, srcRoot = packagedSkillsDir(), destRoot = installedSkillsDir()) => {
16
16
  const src = join(srcRoot, name);
17
17
  const dest = join(destRoot, name);
@@ -34,7 +34,7 @@ export const copySkillBundle = async (name, srcRoot = packagedSkillsDir(), destR
34
34
  }
35
35
  return dest;
36
36
  };
37
- export const copyAllSkills = async (names = SKILL_NAMES, srcRoot = packagedSkillsDir(), destRoot = installedSkillsDir()) => {
37
+ const copyAllSkills = async (names = SKILL_NAMES, srcRoot = packagedSkillsDir(), destRoot = installedSkillsDir()) => {
38
38
  const out = [];
39
39
  for (const name of names)
40
40
  out.push(await copySkillBundle(name, srcRoot, destRoot));
@@ -57,15 +57,7 @@ export const renderBlock = (version, skillsDir, names = SKILL_NAMES) => {
57
57
  ];
58
58
  return lines.join('\n');
59
59
  };
60
- export const isBlockOpen = (line) => line.startsWith(BLOCK_OPEN);
61
- export const installedBlockVersion = (body) => {
62
- for (const line of body.split('\n')) {
63
- if (!isBlockOpen(line))
64
- continue;
65
- return /@([^\s]+) -->/.exec(line.slice(BLOCK_OPEN.length))?.[1];
66
- }
67
- return undefined;
68
- };
60
+ const isBlockOpen = (line) => line.startsWith(BLOCK_OPEN);
69
61
  export const stripBlocks = (body) => {
70
62
  const out = [];
71
63
  let inside = false;