@mainwave/cli 0.10.0 → 0.12.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 (46) hide show
  1. package/README.md +176 -13
  2. package/dist/adapters/claude-code.js +5 -4
  3. package/dist/adapters/claude-desktop.js +35 -1
  4. package/dist/adapters/copilot-chat.js +7 -13
  5. package/dist/adapters/copilot-cli.js +9 -12
  6. package/dist/adapters/cursor.js +7 -2
  7. package/dist/adapters/kiro.js +13 -8
  8. package/dist/commands.js +217 -0
  9. package/dist/core/apply.js +13 -5
  10. package/dist/core/auth-commands.js +2 -1
  11. package/dist/core/codecs/kiro-hooks-json.js +1 -1
  12. package/dist/core/doctor.js +71 -8
  13. package/dist/core/entry-script.js +9 -4
  14. package/dist/core/format.js +0 -1
  15. package/dist/core/hook-copies.js +157 -0
  16. package/dist/core/install-hooks.js +148 -10
  17. package/dist/core/interview.js +8 -2
  18. package/dist/core/markers.js +90 -24
  19. package/dist/core/post-setup.js +5 -22
  20. package/dist/core/redaction.js +179 -0
  21. package/dist/core/skills.js +6 -14
  22. package/dist/core/status.js +21 -1
  23. package/dist/core/store.js +255 -5
  24. package/dist/core/url.js +1 -0
  25. package/dist/core/wizard.js +101 -7
  26. package/dist/main.js +163 -162
  27. package/hooks/git-commit-marker.mjs +406 -0
  28. package/hooks/kiro-otlp.mjs +10 -1
  29. package/hooks/mainwave-hook.mjs +17 -5
  30. package/hooks/marker-core.mjs +56 -2
  31. package/hooks/matchers.json +20 -3
  32. package/hooks/redaction-data.mjs +201 -0
  33. package/hooks/redaction-json.mjs +215 -0
  34. package/hooks/redaction-pattern.mjs +503 -0
  35. package/hooks/redaction.d.mts +84 -0
  36. package/hooks/redaction.mjs +701 -0
  37. package/hooks/vocabulary.d.mts +13 -0
  38. package/hooks/vocabulary.mjs +42 -1
  39. package/package.json +9 -7
  40. package/skills/mainwave-instrument/SKILL.md +24 -6
  41. package/skills/mainwave-instrument/reference/frameworks.md +4 -2
  42. package/skills/mainwave-instrument/reference/troubleshooting.md +4 -0
  43. package/skills/mainwave-instrument-node/SKILL.md +81 -30
  44. package/skills/mainwave-instrument-node/reference/api.md +3 -3
  45. package/skills/mainwave-instrument-node/reference/frameworks.md +42 -25
  46. package/skills/mainwave-instrument-node/reference/troubleshooting.md +11 -7
@@ -2,11 +2,24 @@ import { basename, dirname, isAbsolute, resolve } from 'node:path';
2
2
  import { claudeConfigDir } from '../adapters/claude-code.js';
3
3
  import { hasPath } from './detect.js';
4
4
  import { activeHierarchy } from './effective-settings.js';
5
+ import { refreshFlatCopiesForOrgPacks } from './hook-copies.js';
5
6
  import { isManagedLayer } from './layer-policy.js';
6
- import { bootstrapGroup, buildHookGroups, DEFAULT_MARKER_TOOL, groupEvent, isBootstrapCommand, isDelivered, managedDeliversEntry, managedHooksDir, managedMarkerDeliveries, matchersForTool, packagedHooksDir, prepareMarkersFile, readPackagedMatchers, scanForMarkers, syncManagedHooks, syncOrgDelivered, userHookGroups, } from './markers.js';
7
+ import { BOOTSTRAP_KEY, bootstrapGroup, buildHookGroups, DEFAULT_MARKER_TOOL, groupEvent, isBootstrapCommand, installedHooksDir, isDelivered, managedDeliversEntry, managedHooksDir, managedMarkerDeliveries, managedRedactionPacks, managedRunsBootstrap, matchersForTool, packagedHooksDir, prepareMarkersFile, readEntryVersion, readPackagedMatchers, routeKeyOf, scanForMarkers, syncManagedHooks, syncOrgDelivered, userHookGroups, } from './markers.js';
8
+ import { REDACTION_PACKS } from '../../hooks/redaction.mjs';
7
9
  import { applyUpdate } from './settings.js';
8
- import { readSettings } from './store.js';
10
+ import { KEEP_ORG_PACKS, hasOrgEntry, readSettings, settingsPath, syncOrgRedaction, } from './store.js';
9
11
  import { VERSION } from './version.js';
12
+ const ROUTES_BEFORE_RECORD = [
13
+ BOOTSTRAP_KEY,
14
+ 'UserPromptSubmit',
15
+ 'PostToolUse:gh',
16
+ 'PostToolUse:glab',
17
+ 'PostToolUse:bash',
18
+ 'PostToolUse:git',
19
+ 'PostToolUse:linear',
20
+ 'PostToolUse:jira',
21
+ 'StopFailure',
22
+ ];
10
23
  export const PAYLOAD_EVENTS = [
11
24
  'SessionStart',
12
25
  'UserPromptSubmit',
@@ -14,8 +27,11 @@ export const PAYLOAD_EVENTS = [
14
27
  'StopFailure',
15
28
  ];
16
29
  const payloadGroup = ({ event: _event, ...group }) => group;
17
- export const managedPayloadHooks = (matchers) => {
18
- const groups = [bootstrapGroup(), ...buildHookGroups(matchersForTool(matchers), 'claude-code')];
30
+ export const managedPayloadHooks = (matchers, redactionPacks = []) => {
31
+ const groups = [
32
+ bootstrapGroup(redactionPacks),
33
+ ...buildHookGroups(matchersForTool(matchers), 'claude-code'),
34
+ ];
19
35
  const under = (event) => groups.filter((g) => groupEvent(g) === event).map(payloadGroup);
20
36
  return Object.fromEntries(PAYLOAD_EVENTS.map((e) => [e, under(e)]));
21
37
  };
@@ -23,10 +39,15 @@ const defaultPaths = () => ({
23
39
  srcDir: packagedHooksDir(),
24
40
  destDir: managedHooksDir(),
25
41
  });
26
- export const installHooks = async (adapter, paths = defaultPaths()) => {
42
+ export const installHooks = async (adapter, paths = defaultPaths(), { redactionPacks } = {}) => {
27
43
  const all = await readPackagedMatchers(paths.srcDir);
28
- const updated = await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
29
44
  if (adapter === undefined) {
45
+ const held = redactionPacks !== undefined && (await readEntryVersion(paths.destDir)) === undefined
46
+ ? 'config-dir'
47
+ : undefined;
48
+ const updated = held !== undefined
49
+ ? []
50
+ : await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
30
51
  return {
31
52
  updated,
32
53
  destDir: paths.destDir,
@@ -34,21 +55,71 @@ export const installHooks = async (adapter, paths = defaultPaths()) => {
34
55
  removedFromUser: 0,
35
56
  addedToUser: 0,
36
57
  userSettings: undefined,
58
+ ...(held === undefined ? {} : { held }),
37
59
  };
38
60
  }
39
61
  const scans = await scanForMarkers((await activeHierarchy(adapter)).filter(isManagedLayer));
62
+ const configDir = dirname(adapter.paths.global);
63
+ const orgPacks = managedRedactionPacks(scans);
64
+ const recorded = orgPacks !== undefined && orgPacks.length > 0 ? orgPacks : undefined;
65
+ const keep = recorded === undefined && !managedRunsBootstrap(scans);
66
+ const hasEntry = (await readEntryVersion(paths.destDir)) !== undefined;
67
+ if (redactionPacks !== undefined && recorded === undefined && !hasEntry) {
68
+ return {
69
+ updated: [],
70
+ destDir: paths.destDir,
71
+ managedDelivers: false,
72
+ removedFromUser: 0,
73
+ addedToUser: 0,
74
+ userSettings: undefined,
75
+ held: 'unreadable',
76
+ };
77
+ }
78
+ const settingsFile = paths.settingsFile ?? settingsPath();
79
+ let sync = 'unchanged';
80
+ let recordProblem;
81
+ const hadRecord = keep && (await hasOrgEntry(configDir, settingsFile).catch(() => false));
82
+ try {
83
+ sync = await syncOrgRedaction(configDir, keep ? KEEP_ORG_PACKS : recorded, settingsFile);
84
+ }
85
+ catch (err) {
86
+ if (!hasEntry)
87
+ throw err;
88
+ recordProblem = err instanceof Error ? err.message : String(err);
89
+ }
90
+ const flat = recorded === undefined || recordProblem !== undefined
91
+ ? { flat: [] }
92
+ : await refreshFlatCopiesForOrgPacks(paths.flatDir ?? installedHooksDir(), paths.srcDir);
93
+ const orgRedaction = {
94
+ packs: recorded,
95
+ sync,
96
+ flat: flat.flat,
97
+ ...(keep ? { kept: { hadRecord } } : {}),
98
+ ...(recordProblem === undefined ? {} : { recordProblem }),
99
+ ...(flat.failed !== undefined
100
+ ? { flatProblem: flat.failed }
101
+ : flat.skipped !== undefined
102
+ ? { flatProblem: flat.skipped.map((b) => `${b.script} ${b.reason}`).join('; ') }
103
+ : {}),
104
+ };
105
+ const updated = await syncManagedHooks(all, paths.srcDir, paths.destDir, paths.version ?? VERSION, paths.nodePath);
40
106
  const delivered = managedMarkerDeliveries(scans);
41
- await syncOrgDelivered(managedDeliversEntry(scans), dirname(adapter.paths.global), paths.destDir);
107
+ await syncOrgDelivered(managedDeliversEntry(scans), configDir, paths.destDir);
42
108
  const managedDelivers = delivered.size > 0;
43
109
  const stored = paths.stored ?? (await readSettings().catch(() => ({}))).hooks ?? {};
44
110
  const userSettings = adapter.paths.global;
45
111
  const disclosed = stored.events?.[adapter.name]?.[userSettings];
112
+ const disclosedRoutes = stored.routes?.[adapter.name]?.[userSettings] ?? ROUTES_BEFORE_RECORD;
46
113
  let removedFromUser = 0;
47
114
  let addedToUser = 0;
48
115
  if ((managedDelivers || disclosed !== undefined) && hasPath(userSettings)) {
49
116
  const groups = disclosed === undefined
50
117
  ? []
51
- : userHookGroups(matchersForTool(all, DEFAULT_MARKER_TOOL), { markers: stored.markers?.[adapter.name] ?? true }, delivered, DEFAULT_MARKER_TOOL).filter((g) => disclosed.includes(groupEvent(g)));
118
+ : userHookGroups(matchersForTool(all, DEFAULT_MARKER_TOOL), { markers: stored.markers?.[adapter.name] ?? true }, delivered, DEFAULT_MARKER_TOOL).filter((g) => disclosed.includes(groupEvent(g)) &&
119
+ g.hooks.every((h) => {
120
+ const key = routeKeyOf(h.command);
121
+ return key === undefined || disclosedRoutes.includes(key);
122
+ }));
52
123
  const { update, plan } = await prepareMarkersFile(userSettings, adapter.codec, groups, 0o600, (ownership, group) => ownership === 'cli' &&
53
124
  ((!isBootstrapCommand(group.command) &&
54
125
  isDelivered(delivered, group.event, group.command)) ||
@@ -66,27 +137,44 @@ export const installHooks = async (adapter, paths = defaultPaths()) => {
66
137
  removedFromUser,
67
138
  addedToUser,
68
139
  userSettings,
140
+ orgRedaction,
69
141
  };
70
142
  };
71
143
  export const runInstallHooks = async (adapter, options = {}, paths) => {
72
144
  let result;
73
145
  try {
74
- result = await installHooks(adapter, paths);
146
+ result = await installHooks(adapter, paths, { redactionPacks: options.redactionPacks });
75
147
  }
76
148
  catch (err) {
77
149
  const reason = err instanceof Error ? err.message : String(err);
78
150
  process.stderr.write(`mainwave-cli install-hooks: ${reason}\n`);
79
151
  return 1;
80
152
  }
153
+ if (result.orgRedaction?.recordProblem !== undefined) {
154
+ process.stderr.write(`mainwave-cli install-hooks: ${result.orgRedaction.recordProblem}\n`);
155
+ }
81
156
  if (options.quiet)
82
157
  return 0;
83
158
  const dest = result.destDir;
159
+ if (result.held === 'config-dir') {
160
+ console.log("CLAUDE_CODE_SUBPROCESS_ENV_SCRUB hid this session's CLAUDE_CONFIG_DIR and the hook input " +
161
+ "didn't name it, so your organization's redaction packs couldn't be recorded. No hooks were " +
162
+ 'installed; the next session start that names its config dir installs them.');
163
+ return 0;
164
+ }
165
+ if (result.held === 'unreadable') {
166
+ console.log('--redaction-packs names packs, but no managed settings source this command reads names ' +
167
+ 'them (it reads neither an OS-level policy nor a server-managed cache that has not been ' +
168
+ 'written yet), so nothing was installed.');
169
+ return 0;
170
+ }
84
171
  console.log(result.updated.length > 0
85
172
  ? `Installed Mainwave hook scripts in ${dest}: ${result.updated.join(', ')}`
86
173
  : `Mainwave hook scripts in ${dest} are already current.`);
87
174
  if (result.userSettings === undefined) {
88
175
  console.log("CLAUDE_CODE_SUBPROCESS_ENV_SCRUB hid this session's CLAUDE_CONFIG_DIR and the hook input " +
89
- "didn't name it, so no Claude config dir's settings were changed.");
176
+ "didn't name it, so no Claude config dir's settings were changed" +
177
+ (options.redactionPacks === undefined ? '.' : ', and no redaction packs were recorded.'));
90
178
  }
91
179
  else if (result.removedFromUser > 0 || result.addedToUser > 0) {
92
180
  console.log(`Updated the Mainwave hooks in ${result.userSettings}` +
@@ -97,8 +185,58 @@ export const runInstallHooks = async (adapter, options = {}, paths) => {
97
185
  else if (!result.managedDelivers) {
98
186
  console.log('No managed settings deliver the Mainwave hooks, so your user settings were left as they are.');
99
187
  }
188
+ if (result.orgRedaction !== undefined) {
189
+ for (const line of orgRedactionLines(result.orgRedaction, options.redactionPacks)) {
190
+ console.log(line);
191
+ }
192
+ }
100
193
  return 0;
101
194
  };
195
+ const orgRedactionLines = (org, asked) => {
196
+ const out = [];
197
+ const known = REDACTION_PACKS;
198
+ if (org.packs === undefined) {
199
+ if (org.kept !== undefined) {
200
+ const tail = org.kept.hadRecord
201
+ ? 'so the recorded packs were kept.'
202
+ : 'so no packs are recorded, so none apply.';
203
+ if (asked !== undefined) {
204
+ out.push('--redaction-packs names packs, but no managed settings source this command reads names ' +
205
+ `them, ${tail}`);
206
+ }
207
+ else if (org.kept.hadRecord) {
208
+ out.push(`No managed settings source this command reads runs the Mainwave bootstrap, ${tail}`);
209
+ }
210
+ }
211
+ else if (asked !== undefined) {
212
+ out.push("--redaction-packs is read from your organization's managed settings, which name none, " +
213
+ 'so no redaction packs were recorded.');
214
+ }
215
+ if (org.sync === 'cleared') {
216
+ out.push("Your organization's managed settings no longer set redaction packs; cleared them.");
217
+ }
218
+ return out;
219
+ }
220
+ if (org.sync === 'set') {
221
+ out.push(`Recorded your organization's redaction packs: ${org.packs.join(', ')}.`);
222
+ }
223
+ if (asked !== undefined && asked.join(',') !== org.packs.join(',')) {
224
+ out.push(`Your organization's managed settings name ${org.packs.join(', ')}; those apply, not --redaction-packs.`);
225
+ }
226
+ const unknown = org.packs.filter((name) => !known.includes(name));
227
+ if (unknown.length > 0) {
228
+ out.push(`This release has no redaction pack ${unknown.join(', ')}, so the Mainwave hooks send nothing ` +
229
+ 'until one that has them is installed.');
230
+ }
231
+ if (org.flat.length > 0) {
232
+ out.push('Refreshed the Cursor and Kiro hook copies so they apply the packs.');
233
+ }
234
+ if (org.flatProblem !== undefined) {
235
+ out.push(`The Cursor and Kiro hook copies predate redaction packs and were not refreshed (${org.flatProblem}); ` +
236
+ 'they send spans without the packs until setup is re-run.');
237
+ }
238
+ return out;
239
+ };
102
240
  const HOOK_INPUT_CAP = 1024 * 1024;
103
241
  const HOOK_INPUT_WAIT_MS = 2000;
104
242
  const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
@@ -8,7 +8,7 @@ import { promptApiKey, promptCollectorUrl, promptUserEmail } from './prompts.js'
8
8
  import { storedKeyFor } from './store.js';
9
9
  import { say } from './ui.js';
10
10
  import { resolveUseCase } from './use-case.js';
11
- export const DEFAULT_COLLECTOR_URL = 'https://collector.mainwave.com';
11
+ const DEFAULT_COLLECTOR_URL = 'https://collector.mainwave.com';
12
12
  const missing = (what, flag) => new WizardAbort(`${what} is required in a non-interactive run — pass ${flag}`);
13
13
  const resolveApiKey = async (input) => {
14
14
  if (input.overrides.apiKey)
@@ -92,7 +92,7 @@ const resolveAdapterEmails = async (input, identityAdapters, general, toolEmail)
92
92
  }
93
93
  return Object.fromEntries(tools.map((a) => [a.name, chosen]));
94
94
  };
95
- export const noIdentityWarning = (headerTools, nonOauth) => {
95
+ const noIdentityWarning = (headerTools, nonOauth) => {
96
96
  const names = [
97
97
  ...headerTools.map((a) => a.displayName),
98
98
  ...nonOauth.map(({ adapter, reason }) => `${adapter.displayName} (${reason})`),
@@ -166,6 +166,12 @@ const sayCaptureNotice = (optIns, adapters, explicit) => {
166
166
  : undefined,
167
167
  optIns.toolDetails ? 'shell commands and file paths' : undefined,
168
168
  optIns.toolContent ? 'tool result bodies' : undefined,
169
+ optIns.userPrompts &&
170
+ optIns.toolDetails &&
171
+ optIns.toolContent &&
172
+ adapters.some((a) => a.name === 'claude-desktop')
173
+ ? 'raw model request and response bodies, system prompts included (Claude Desktop)'
174
+ : undefined,
169
175
  optIns.repository && adapters.some((a) => a.name === 'claude-code')
170
176
  ? 'repository names (Claude Code)'
171
177
  : undefined,
@@ -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,13 +30,13 @@ 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',
37
38
  ];
38
- export const MARKER_HOOK_EVENTS = INSTALLED_HOOK_EVENTS;
39
+ const MARKER_HOOK_EVENTS = INSTALLED_HOOK_EVENTS;
39
40
  const ENTRY_EVENTS = [
40
41
  'UserPromptSubmit',
41
42
  'PostToolUse',
@@ -63,15 +64,31 @@ export const shellHome = (plat = process.platform, env = process.env, dirExists
63
64
  return drivePath;
64
65
  return env.USERPROFILE || homedir();
65
66
  };
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`;
67
+ export const installHooksCommand = (version, { quiet = true, redactionPacks = [], } = {}) => `cd "$HOME" && npx -y --registry=https://registry.npmjs.org ` +
68
+ `@mainwave/cli@${version} install-hooks${quiet ? ' --quiet' : ''}` +
69
+ (redactionPacks.length > 0
70
+ ? ` ${REDACTION_PACKS_FLAG} ${canonicalPacks(redactionPacks).join(',')}`
71
+ : '');
72
+ export const bootstrapCommand = (version, redactionPacks = []) => `{ ${installHooksCommand(version, { redactionPacks })}; } >/dev/null 2>&1; exit 0`;
73
+ const REDACTION_PACKS_FLAG = '--redaction-packs';
74
+ export const redactionPacksIn = (command) => {
75
+ const args = /\binstall-hooks\b([^;}]*)/.exec(command)?.[1];
76
+ if (args === undefined)
77
+ return undefined;
78
+ const found = /(?:^|\s)--redaction-packs(?:=|\s+)('[^']*'|"[^"]*"|[^\s'"]+)/.exec(args);
79
+ if (found === null)
80
+ return undefined;
81
+ const value = found[1].replace(/^(['"])(.*)\1$/, '$2');
82
+ return [...new Set(value.split(',').map((n) => n.trim()))].filter((n) => n !== '');
83
+ };
69
84
  export const BOOTSTRAP_MATCHER = 'startup|resume|fork';
70
85
  export const BOOTSTRAP_KEY = 'SessionStart:bootstrap';
71
- export const bootstrapGroup = () => ({
86
+ export const bootstrapGroup = (redactionPacks = []) => ({
72
87
  event: 'SessionStart',
73
88
  matcher: BOOTSTRAP_MATCHER,
74
- hooks: [{ type: 'command', command: bootstrapCommand(PAYLOAD_CLI_SPEC), async: true }],
89
+ hooks: [
90
+ { type: 'command', command: bootstrapCommand(PAYLOAD_CLI_SPEC, redactionPacks), async: true },
91
+ ],
75
92
  });
76
93
  const SAFE_ROUTE = /^[a-z][a-z0-9-]*$/;
77
94
  export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
@@ -138,8 +155,20 @@ export const readPackagedMatchers = async (dir = packagedHooksDir()) => {
138
155
  };
139
156
  });
140
157
  };
141
- const SHARED_HOOK_MODULES = ['marker-core.mjs', 'vocabulary.mjs', HOOK_DISPATCHER_SCRIPT];
142
- export const featureModule = (feature) => `${feature}.mjs`;
158
+ export const REDACTION_HOOK_MODULES = [
159
+ 'redaction.mjs',
160
+ 'redaction-pattern.mjs',
161
+ 'redaction-json.mjs',
162
+ 'redaction-data.mjs',
163
+ ];
164
+ export const lacksRedactionModules = (dir) => REDACTION_HOOK_MODULES.every((f) => !existsSync(join(dir, f)));
165
+ const SHARED_HOOK_MODULES = [
166
+ 'marker-core.mjs',
167
+ 'vocabulary.mjs',
168
+ ...REDACTION_HOOK_MODULES,
169
+ HOOK_DISPATCHER_SCRIPT,
170
+ ];
171
+ const featureModule = (feature) => `${feature}.mjs`;
143
172
  export const hookScriptFiles = (matchers) => [
144
173
  ...SHARED_HOOK_MODULES,
145
174
  ...new Set(matchers.flatMap((m) => m.features.map(featureModule))),
@@ -154,8 +183,8 @@ export const copyHookScripts = async (files, srcDir = packagedHooksDir(), destDi
154
183
  }
155
184
  return destDir;
156
185
  };
157
- export const MANAGED_POINTER = 'current.json';
158
- export const MANAGED_VERSIONS_DIR = 'versions';
186
+ const MANAGED_POINTER = 'current.json';
187
+ const MANAGED_VERSIONS_DIR = 'versions';
159
188
  export const MANAGED_ENTRY_SCRIPT = 'managed-entry.mjs';
160
189
  const MANAGED_ENTRY_MARK = 'mainwave managed hook entry';
161
190
  const RETIRED_GRACE_MS = 10 * 60 * 1000;
@@ -172,7 +201,7 @@ const LEGACY_SCRIPT_ROUTES = {
172
201
  'glab-mr-marker.mjs': { event: 'PostToolUse', route: 'glab' },
173
202
  'claude-plan-snapshot.mjs': { event: 'UserPromptSubmit' },
174
203
  };
175
- export const legacyScriptReleased = (name) => LEGACY_ENTRY_NAMES.includes(name);
204
+ const legacyScriptReleased = (name) => LEGACY_ENTRY_NAMES.includes(name);
176
205
  const VERSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
177
206
  const versionDirName = (version, files, bodies) => {
178
207
  const hash = createHash('sha256');
@@ -206,6 +235,15 @@ export const readEntryVersion = async (destDir) => {
206
235
  const text = await fs.readFile(join(destDir, HOOK_ENTRY_SCRIPT), 'utf8').catch(() => null);
207
236
  return text === null ? undefined : entryVersionId(text);
208
237
  };
238
+ export const releaseBeforeRedaction = async (destDir) => {
239
+ const id = await readEntryVersion(destDir);
240
+ if (id === undefined)
241
+ return undefined;
242
+ const dir = join(destDir, MANAGED_VERSIONS_DIR, id);
243
+ if (!existsSync(join(dir, HOOK_DISPATCHER_SCRIPT)))
244
+ return undefined;
245
+ return lacksRedactionModules(dir) ? { id, dir } : undefined;
246
+ };
209
247
  export const stageManagedVersion = async (files, srcDir, destDir, version) => {
210
248
  const bodies = await Promise.all(files.map((f) => fs.readFile(join(srcDir, f))));
211
249
  const id = versionDirName(version, files, bodies);
@@ -288,7 +326,7 @@ export const writeHookEntry = async (staged, destDir, routes, nodePath = process
288
326
  await retire(destDir, previous, staged.id);
289
327
  return true;
290
328
  };
291
- export const writeNodeEntry = async (srcDir, destDir) => {
329
+ const writeNodeEntry = async (srcDir, destDir) => {
292
330
  const body = await fs.readFile(join(srcDir, HOOK_NODE_ENTRY_SCRIPT));
293
331
  const path = join(destDir, HOOK_NODE_ENTRY_SCRIPT);
294
332
  const current = await fs.readFile(path).catch(() => null);
@@ -381,7 +419,7 @@ export const resolveManagedScript = async (script) => {
381
419
  const target = join(dirname(script), MANAGED_VERSIONS_DIR, dir, basename(script));
382
420
  return existsSync(target) ? target : undefined;
383
421
  };
384
- export const hooksRootDir = (managedDir = managedHooksDir()) => dirname(managedDir);
422
+ const hooksRootDir = (managedDir = managedHooksDir()) => dirname(managedDir);
385
423
  export const optOutFlagPath = (host, optOut, root = hooksRootDir()) => join(root, 'off', host, optOut);
386
424
  export const writeOptOutFlags = async (host, on, root = hooksRootDir()) => {
387
425
  for (const [optOut, enabled] of Object.entries(on)) {
@@ -508,7 +546,7 @@ export const ownedGroupsInDoc = (doc) => {
508
546
  }
509
547
  return out;
510
548
  };
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. ` +
549
+ 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
550
  'Fix or remove that value, then re-run setup.';
513
551
  const effectiveMatcher = (matcher) => matcher === undefined || matcher === '' || matcher === '*' ? NO_MATCHER : matcher;
514
552
  const sameGroup = (before, after) => before.event === groupEvent(after) &&
@@ -643,6 +681,7 @@ export const markerLogFiles = (home = homedir()) => [
643
681
  logFile(home, 'Jira tickets', 'jira-ticket-marker.log', '.mainwave-jira-ticket-marker.log'),
644
682
  logFile(home, 'PRs', 'pr-marker.log', '.mainwave-pr-marker.log'),
645
683
  logFile(home, 'GitLab MRs', 'glab-mr-marker.log', '.mainwave-glab-mr-marker.log'),
684
+ logFile(home, 'Git commits', 'git-commit-marker.log', '.mainwave-git-commit-marker.log'),
646
685
  {
647
686
  ...logFile(home, 'Claude plan snapshots', 'plan-snapshot.log', '.mainwave-plan-snapshot.log.ok'),
648
687
  activityPath: join(hookLogDir(home), 'plan-snapshot.log.ok'),
@@ -773,6 +812,17 @@ export const managedMarkerDeliveries = (scans) => new Set(activeManagedScans(sca
773
812
  const key = routeKeyOf(g.command);
774
813
  return key === undefined ? [] : [key];
775
814
  })));
815
+ const managedBootstraps = (scans) => activeManagedScans(scans)
816
+ .filter((s) => s.managed)
817
+ .flatMap((s) => s.groups)
818
+ .filter((g) => g.ownership === 'cli' && g.event === 'SessionStart' && isBootstrapCommand(g.command));
819
+ export const managedRedactionPacks = (scans) => {
820
+ const named = managedBootstraps(scans)
821
+ .map((g) => redactionPacksIn(g.command))
822
+ .filter((packs) => packs !== undefined);
823
+ return named.length === 0 ? undefined : packOrder(named.flat());
824
+ };
825
+ export const managedRunsBootstrap = (scans) => managedBootstraps(scans).length > 0;
776
826
  export const scanRoutes = (scan, host = DEFAULT_MARKER_TOOL) => [
777
827
  ...new Set(scan.groups
778
828
  .filter((g) => g.ownership === 'cli')
@@ -791,7 +841,8 @@ export const routeLabel = (key) => {
791
841
  UserPromptSubmit: 'the Claude plan snapshot',
792
842
  'PostToolUse:gh': 'the GitHub PR marker',
793
843
  'PostToolUse:glab': 'the GitLab MR marker',
794
- 'PostToolUse:bash': 'the PR and MR markers',
844
+ 'PostToolUse:git': 'the git commit marker',
845
+ 'PostToolUse:bash': 'the PR, MR and commit markers',
795
846
  'PostToolUse:linear': 'the Linear ticket marker',
796
847
  'PostToolUse:jira': 'the Jira ticket marker',
797
848
  StopFailure: 'the Claude turn-error span',
@@ -1074,7 +1125,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
1074
1125
  if (!entryChecked) {
1075
1126
  entryChecked = true;
1076
1127
  const nodeEntry = cli.some((c) => c.command.includes(HOOK_NODE_ENTRY_SCRIPT));
1077
- issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry)));
1128
+ issues.push(...(await entryIssues(layout.managedDir, matchers, g.managed, nodeEntry, layout.redaction ?? 'off')));
1078
1129
  }
1079
1130
  }
1080
1131
  const anyCurrent = cli.some((g) => commandGeneration(g.command) === 'entry');
@@ -1109,7 +1160,7 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
1109
1160
  }
1110
1161
  return issues;
1111
1162
  };
1112
- export const entryIssues = async (managedDir, matchers, managed, nodeEntry = false) => {
1163
+ const entryIssues = async (managedDir, matchers, managed, nodeEntry = false, redaction = 'off') => {
1113
1164
  const entry = join(managedDir, HOOK_ENTRY_SCRIPT);
1114
1165
  const fix = managed
1115
1166
  ? 'Start a new Claude Code session (the managed settings install it at startup), or ' +
@@ -1137,12 +1188,27 @@ export const entryIssues = async (managedDir, matchers, managed, nodeEntry = fal
1137
1188
  }
1138
1189
  const missing = hookScriptFiles(matchers).filter((f) => !existsSync(join(release, f)));
1139
1190
  if (missing.length > 0) {
1140
- return [
1141
- {
1142
- level: 'error',
1143
- message: `Release ${id} of the Mainwave hooks lacks ${missing.join(', ')}, so the hooks that need ${missing.length === 1 ? 'it' : 'them'} send nothing. ${fix}`,
1144
- },
1145
- ];
1191
+ const predates = lacksRedactionModules(release);
1192
+ const redactionModules = REDACTION_HOOK_MODULES;
1193
+ const rest = predates ? missing.filter((f) => !redactionModules.includes(f)) : missing;
1194
+ const found = [];
1195
+ if (predates && redaction !== 'off') {
1196
+ found.push({
1197
+ level: redaction === 'file' ? 'error' : 'warn',
1198
+ message: `Release ${id} of the Mainwave hooks predates redaction (it lacks ${REDACTION_HOOK_MODULES.join(', ')}), so its hooks send spans without applying redaction rules` +
1199
+ (redaction === 'file'
1200
+ ? ', although redaction is on'
1201
+ : ', although credential redaction is on by default') +
1202
+ `. ${fix}`,
1203
+ });
1204
+ }
1205
+ if (rest.length > 0) {
1206
+ found.push({
1207
+ level: 'warn',
1208
+ 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}`,
1209
+ });
1210
+ }
1211
+ return found;
1146
1212
  }
1147
1213
  const node = join(managedDir, HOOK_NODE_ENTRY_SCRIPT);
1148
1214
  if (nodeEntry && !existsSync(node)) {
@@ -1,5 +1,5 @@
1
1
  import { homedir, platform as osPlatform } from 'node:os';
2
- import { basename, isAbsolute, join } from 'node:path';
2
+ import { basename, join } from 'node:path';
3
3
  import { color } from './format.js';
4
4
  const detectShellKind = () => {
5
5
  const shellEnv = process.env.SHELL;
@@ -41,31 +41,14 @@ const profile = (kind) => {
41
41
  return { kind, rcFile: '~/.profile', oneShot: posixOneShot, rcLine: posixRcLine };
42
42
  };
43
43
  const indent = (line) => ` ${line}`;
44
- export const renderEnvFileBlock = (envFile, scope) => {
44
+ export const renderEnvFileBlock = (envFile) => {
45
45
  const sh = profile(detectShellKind());
46
46
  const shellLabel = sh.kind === 'unknown' ? 'your shell' : sh.kind;
47
- if (scope === 'global') {
48
- return [
49
- color.bold(`Persist for every ${shellLabel} session — add to ${sh.rcFile}:`),
50
- '',
51
- indent(color.cyan(sh.rcLine(envFile))),
52
- '',
53
- color.dim(` (or one-shot for the current terminal: ${color.reset(sh.oneShot(envFile))})`),
54
- ].join('\n');
55
- }
56
- const absoluteEnvFile = isAbsolute(envFile) ? envFile : join(process.cwd(), envFile);
57
47
  return [
58
- color.bold('Per-project setup — two options below. Pick the one(s) you want:'),
59
- '',
60
- color.bold('1. Current terminal (one-shot):'),
61
- indent(color.cyan(sh.oneShot(envFile))),
48
+ color.bold(`Persist for every ${shellLabel} session — add to ${sh.rcFile}:`),
62
49
  '',
63
- color.bold(`2. GUI launches (Spotlight/Dock) — add to ${sh.rcFile}:`),
64
- indent(color.cyan(sh.rcLine(absoluteEnvFile))),
65
- color.dim(' The rc line points at this project by absolute path, so VS Code picks'),
66
- color.dim(' it up on GUI launch. Comment out / swap the line when changing projects.'),
50
+ indent(color.cyan(sh.rcLine(envFile))),
67
51
  '',
68
- color.dim(`Or, to auto-load per directory, install direnv and add to ./.envrc:`),
69
- indent(color.cyan(`source_env ${envFile}`)),
52
+ color.dim(` (or one-shot for the current terminal: ${color.reset(sh.oneShot(envFile))})`),
70
53
  ].join('\n');
71
54
  };