@mainwave/cli 0.11.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 (39) hide show
  1. package/README.md +168 -13
  2. package/dist/adapters/claude-code.js +3 -3
  3. package/dist/adapters/claude-desktop.js +35 -1
  4. package/dist/adapters/cursor.js +7 -2
  5. package/dist/adapters/kiro.js +13 -8
  6. package/dist/commands.js +217 -0
  7. package/dist/core/apply.js +3 -3
  8. package/dist/core/auth-commands.js +2 -1
  9. package/dist/core/codecs/kiro-hooks-json.js +1 -1
  10. package/dist/core/doctor.js +71 -8
  11. package/dist/core/entry-script.js +2 -3
  12. package/dist/core/format.js +0 -1
  13. package/dist/core/hook-copies.js +157 -0
  14. package/dist/core/install-hooks.js +144 -15
  15. package/dist/core/interview.js +8 -2
  16. package/dist/core/markers.js +86 -22
  17. package/dist/core/redaction.js +179 -0
  18. package/dist/core/skills.js +3 -11
  19. package/dist/core/status.js +21 -1
  20. package/dist/core/store.js +254 -4
  21. package/dist/core/wizard.js +91 -6
  22. package/dist/main.js +163 -162
  23. package/hooks/kiro-otlp.mjs +10 -1
  24. package/hooks/mainwave-hook.mjs +11 -1
  25. package/hooks/marker-core.mjs +56 -2
  26. package/hooks/matchers.json +1 -1
  27. package/hooks/redaction-data.mjs +201 -0
  28. package/hooks/redaction-json.mjs +215 -0
  29. package/hooks/redaction-pattern.mjs +503 -0
  30. package/hooks/redaction.d.mts +84 -0
  31. package/hooks/redaction.mjs +701 -0
  32. package/package.json +3 -1
  33. package/skills/mainwave-instrument/SKILL.md +24 -6
  34. package/skills/mainwave-instrument/reference/frameworks.md +4 -2
  35. package/skills/mainwave-instrument/reference/troubleshooting.md +4 -0
  36. package/skills/mainwave-instrument-node/SKILL.md +83 -38
  37. package/skills/mainwave-instrument-node/reference/api.md +16 -16
  38. package/skills/mainwave-instrument-node/reference/frameworks.md +42 -27
  39. package/skills/mainwave-instrument-node/reference/troubleshooting.md +11 -7
package/dist/main.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { claudeCodeFor } from './adapters/claude-code.js';
2
2
  import { adapterNames, adapters } from './adapters/index.js';
3
+ import { commandFlags, detailsBlock, isCommand, usageBlock } from './commands.js';
3
4
  import { runLogin, runLogout, runWhoami } from './core/auth-commands.js';
4
5
  import { runDoctor } from './core/doctor.js';
5
6
  import { runEdit } from './core/edit.js';
6
7
  import { runEnvCommand } from './core/env-command.js';
7
8
  import { PlatformError, WizardAbort } from './core/errors.js';
8
9
  import { runInstallHooks, sessionConfigDir } from './core/install-hooks.js';
9
- import { flagBool, flagValue, hasFlag, parseArgs } from './core/flags.js';
10
+ import { parseRedactionPacks } from './core/redaction.js';
11
+ import { parseArgs } from './core/flags.js';
10
12
  import { color } from './core/format.js';
11
13
  import { promptAdapters } from './core/prompts.js';
12
14
  import { runStatus } from './core/status.js';
@@ -15,7 +17,6 @@ import { VERSION } from './core/version.js';
15
17
  import { runVerify } from './core/verify.js';
16
18
  import { runRemove } from './core/remove.js';
17
19
  import { runSetup, runSkillsOnly } from './core/wizard.js';
18
- export { VERSION };
19
20
  const printHelp = () => {
20
21
  const list = adapterNames()
21
22
  .map((n) => ` ${n}`)
@@ -23,57 +24,10 @@ const printHelp = () => {
23
24
  console.log(`mainwave-cli — Mainwave AI setup wizard
24
25
 
25
26
  Usage:
26
- mainwave-cli login [--password] [--device] [--no-browser] [--api-url <u>] [--json]
27
- sign in to Mainwave: shows a code and opens the app to
28
- approve it. --password uses email + password instead
29
- (MAINWAVE_EMAIL / MAINWAVE_PASSWORD drive it
30
- non-interactively); --device forces the browser flow
31
- without a terminal (coding agents); --no-browser
32
- prints the URL
33
- mainwave-cli logout forget the stored session
34
- mainwave-cli whoami [--json] print the signed-in user, org, and endpoints
35
- mainwave-cli setup [<adapter>...] run the interactive setup wizard; with no adapter,
36
- every detected tool is configured and the rest are
37
- offered, and with several, configure them all in
38
- one pass. Always writes user-global config
39
- mainwave-cli verify [--ucid <id|url>] [--no-sample] [--timeout <s>] [--json]
40
- push a sample trace and wait for it to land, then
41
- print where your activity appears
42
- mainwave-cli status [<adapter>] [--json]
43
- show current on-disk config for all (or one) adapter
44
- mainwave-cli edit <adapter> [--local|--global]
45
- open a settings file in $EDITOR (interactive picker by default;
46
- flag is required in non-TTY)
47
- mainwave-cli doctor <adapter> [--validate] [--json]
48
- show settings hierarchy and run health checks
49
- mainwave-cli env <adapter> print export lines for shell-sourceable adapters
50
- (usage: \`eval "$(mainwave-cli env <adapter>)"\`)
51
- mainwave-cli install-hooks [--quiet] install or refresh the Mainwave hook entry and the
52
- latest release's hook scripts, with no prompts or
53
- sign-in (run at session start by an org's managed
54
- settings, and by setup's own session-start hook)
27
+ ${usageBlock()}
55
28
  mainwave-cli --help show this message
56
29
 
57
- Setup flags (every prompt has one, so scripts and coding agents can drive it):
58
- --api-key <k> --collector-url <u> --api-url <u>
59
- --ucid <id|url> --use-case <name> pin every tool to one use case (by default none
60
- is written: each tool's activity is attributed at ingest
61
- from your identity). A pin survives later default runs;
62
- --no-use-case removes it
63
- --email <e> --new-key
64
- --invite <token> redeem an account-less developer invite: no login, no key
65
- to paste — the token brings its own key, collector, and
66
- identity (mutually exclusive with --api-key/--ucid/--use-case)
67
- --opt-in prompts,tool-details,tool-content,repository|all|none content capture
68
- (default: all on — "--opt-in none" sends metadata only;
69
- repository = repository names on Claude Code telemetry)
70
- --no-markers skip the Mainwave hooks (installed by default): the ticket
71
- & PR markers and, for Claude Code, the plan snapshot
72
- --yes --json --no-verify --verify-timeout <seconds>
73
- --skills / --no-skills install the agent skills payload (default: ask, or on in scripts)
74
- --skills-only install only the skills, touching no telemetry config
75
- --remove take this CLI's config for the named tools back off this
76
- machine (Kiro: its hooks file entries and kiro.env)
30
+ ${detailsBlock()}
77
31
  mainwave-cli --version print version
78
32
 
79
33
  Available adapters:
@@ -128,38 +82,55 @@ const detectedAdapters = () => {
128
82
  return found;
129
83
  };
130
84
  const setupOptions = (parsed) => {
131
- if (hasFlag(parsed, 'scope')) {
85
+ const flags = commandFlags('setup', parsed);
86
+ if (flags.has('scope')) {
132
87
  throw new WizardAbort('--scope was removed: setup writes user-global config only. Drop the flag.');
133
88
  }
134
- const invite = flagValue(parsed, 'invite');
135
- if (hasFlag(parsed, 'invite') && invite === undefined) {
89
+ const invite = flags.value('invite');
90
+ if (flags.has('invite') && invite === undefined) {
136
91
  throw new WizardAbort('--invite requires a token, e.g. --invite <token>');
137
92
  }
138
93
  if (invite !== undefined) {
139
94
  for (const conflicting of ['api-key', 'ucid', 'use-case']) {
140
- if (hasFlag(parsed, conflicting)) {
95
+ if (flags.has(conflicting)) {
141
96
  throw new WizardAbort(`--invite cannot be combined with --${conflicting}`);
142
97
  }
143
98
  }
144
99
  }
100
+ const redactionFile = flags.value('redaction-file');
101
+ if (flags.has('redaction-file') && (redactionFile === undefined || redactionFile === '')) {
102
+ throw new WizardAbort('--redaction-file requires a path, e.g. --redaction-file ./redaction.json');
103
+ }
104
+ const noRedaction = flags.bool('redaction') === false;
105
+ if (redactionFile !== undefined && noRedaction) {
106
+ throw new WizardAbort('--redaction-file and --no-redaction cannot be combined');
107
+ }
108
+ const redactSecrets = flags.bool('redact-secrets');
109
+ if ((redactionFile !== undefined || noRedaction || redactSecrets !== undefined) &&
110
+ flags.bool('skills-only') === true) {
111
+ throw new WizardAbort('--skills-only touches no telemetry config, so redaction flags do not apply');
112
+ }
145
113
  return {
146
114
  invite,
147
- apiKey: flagValue(parsed, 'api-key'),
148
- collectorUrl: flagValue(parsed, 'collector-url'),
149
- apiUrl: flagValue(parsed, 'api-url'),
150
- ucid: flagValue(parsed, 'ucid'),
151
- useCaseName: flagValue(parsed, 'use-case'),
152
- skipUseCase: flagBool(parsed, 'use-case') === false,
153
- userEmail: flagValue(parsed, 'email'),
154
- optIns: parseOptIns(flagValue(parsed, 'opt-in')),
155
- markers: flagBool(parsed, 'markers'),
156
- skills: flagBool(parsed, 'skills'),
157
- skillsOnly: flagBool(parsed, 'skills-only') === true,
158
- newKey: flagBool(parsed, 'new-key') === true,
159
- yes: flagBool(parsed, 'yes') === true,
160
- json: flagBool(parsed, 'json') === true,
161
- skipVerify: flagBool(parsed, 'verify') === false,
162
- verifyTimeoutMs: seconds(flagValue(parsed, 'verify-timeout')),
115
+ redactionFile,
116
+ noRedaction,
117
+ redactSecrets,
118
+ apiKey: flags.value('api-key'),
119
+ collectorUrl: flags.value('collector-url'),
120
+ apiUrl: flags.value('api-url'),
121
+ ucid: flags.value('ucid'),
122
+ useCaseName: flags.value('use-case'),
123
+ skipUseCase: flags.bool('use-case') === false,
124
+ userEmail: flags.value('email'),
125
+ optIns: parseOptIns(flags.value('opt-in')),
126
+ markers: flags.bool('markers'),
127
+ skills: flags.bool('skills'),
128
+ skillsOnly: flags.bool('skills-only') === true,
129
+ newKey: flags.bool('new-key') === true,
130
+ yes: flags.bool('yes') === true,
131
+ json: flags.bool('json') === true,
132
+ skipVerify: flags.bool('verify') === false,
133
+ verifyTimeoutMs: seconds(flags.value('verify-timeout')),
163
134
  };
164
135
  };
165
136
  const reportCommandError = (err) => {
@@ -179,56 +150,56 @@ const reportCommandError = (err) => {
179
150
  printError(err instanceof Error ? err.message : String(err));
180
151
  return 1;
181
152
  };
182
- export const main = async (argv) => {
183
- const args = argv.slice(2);
184
- const cmd = args[0];
185
- if (cmd === undefined || cmd === '--help' || cmd === '-h' || cmd === 'help') {
186
- printHelp();
187
- return 0;
188
- }
189
- if (cmd === '--version' || cmd === '-v') {
190
- console.log(VERSION);
191
- return 0;
192
- }
193
- const AUTH_COMMANDS = ['login', 'logout', 'whoami'];
194
- if (cmd !== 'setup' &&
195
- cmd !== 'doctor' &&
196
- cmd !== 'env' &&
197
- cmd !== 'status' &&
198
- cmd !== 'edit' &&
199
- cmd !== 'verify' &&
200
- cmd !== 'install-hooks' &&
201
- !AUTH_COMMANDS.includes(cmd)) {
202
- printError(`unknown command: ${cmd}`);
203
- printHelp();
204
- return 1;
153
+ const resolveAdapters = (names) => {
154
+ const named = [];
155
+ for (const name of names) {
156
+ const resolved = resolveAdapter(name);
157
+ if (typeof resolved === 'number')
158
+ return resolved;
159
+ named.push(resolved);
205
160
  }
206
- if (AUTH_COMMANDS.includes(cmd)) {
207
- const parsed = parseArgs(args.slice(1));
208
- const json = flagBool(parsed, 'json') === true;
161
+ return named;
162
+ };
163
+ const HANDLERS = {
164
+ login: async (args) => {
165
+ const flags = commandFlags('login', parseArgs(args));
209
166
  try {
210
- if (cmd === 'login') {
211
- return await runLogin({
212
- email: flagValue(parsed, 'email'),
213
- usePassword: flagBool(parsed, 'password') === true,
214
- useDevice: flagBool(parsed, 'device') === true,
215
- noBrowser: flagBool(parsed, 'browser') === false,
216
- deviceTimeoutMs: seconds(flagValue(parsed, 'device-timeout')),
217
- apiUrl: flagValue(parsed, 'api-url'),
218
- force: flagBool(parsed, 'force') === true,
219
- json,
220
- });
221
- }
222
- if (cmd === 'logout')
223
- return await runLogout({ json });
224
- return await runWhoami({ apiUrl: flagValue(parsed, 'api-url'), json });
167
+ return await runLogin({
168
+ email: flags.value('email'),
169
+ usePassword: flags.bool('password') === true,
170
+ useDevice: flags.bool('device') === true,
171
+ noBrowser: flags.bool('browser') === false,
172
+ deviceTimeoutMs: seconds(flags.value('device-timeout')),
173
+ apiUrl: flags.value('api-url'),
174
+ force: flags.bool('force') === true,
175
+ json: flags.bool('json') === true,
176
+ });
225
177
  }
226
178
  catch (err) {
227
179
  return reportCommandError(err);
228
180
  }
229
- }
230
- if (cmd === 'status') {
231
- const parsed = parseArgs(args.slice(1));
181
+ },
182
+ logout: async (args) => {
183
+ const flags = commandFlags('logout', parseArgs(args));
184
+ try {
185
+ return await runLogout({ json: flags.bool('json') === true });
186
+ }
187
+ catch (err) {
188
+ return reportCommandError(err);
189
+ }
190
+ },
191
+ whoami: async (args) => {
192
+ const flags = commandFlags('whoami', parseArgs(args));
193
+ try {
194
+ return await runWhoami({ apiUrl: flags.value('api-url'), json: flags.bool('json') === true });
195
+ }
196
+ catch (err) {
197
+ return reportCommandError(err);
198
+ }
199
+ },
200
+ status: async (args) => {
201
+ const parsed = parseArgs(args);
202
+ const flags = commandFlags('status', parsed);
232
203
  const name = parsed.positionals[0];
233
204
  let target;
234
205
  if (name !== undefined) {
@@ -238,55 +209,62 @@ export const main = async (argv) => {
238
209
  target = resolved;
239
210
  }
240
211
  try {
241
- return await runStatus(target, { json: flagBool(parsed, 'json') === true });
212
+ return await runStatus(target, { json: flags.bool('json') === true });
242
213
  }
243
214
  catch (err) {
244
215
  printError(err instanceof Error ? err.message : String(err));
245
216
  return 1;
246
217
  }
247
- }
248
- if (cmd === 'verify') {
249
- const parsed = parseArgs(args.slice(1));
218
+ },
219
+ verify: async (args) => {
220
+ const flags = commandFlags('verify', parseArgs(args));
250
221
  try {
251
222
  return await runVerify({
252
- ucid: flagValue(parsed, 'ucid'),
253
- noSample: flagBool(parsed, 'sample') === false,
254
- timeoutMs: seconds(flagValue(parsed, 'timeout')),
255
- apiUrl: flagValue(parsed, 'api-url'),
256
- collectorUrl: flagValue(parsed, 'collector-url'),
257
- apiKey: flagValue(parsed, 'api-key'),
258
- json: flagBool(parsed, 'json') === true,
223
+ ucid: flags.value('ucid'),
224
+ noSample: flags.bool('sample') === false,
225
+ timeoutMs: seconds(flags.value('timeout')),
226
+ apiUrl: flags.value('api-url'),
227
+ collectorUrl: flags.value('collector-url'),
228
+ apiKey: flags.value('api-key'),
229
+ json: flags.bool('json') === true,
259
230
  });
260
231
  }
261
232
  catch (err) {
262
233
  return reportCommandError(err);
263
234
  }
264
- }
265
- if (cmd === 'install-hooks') {
266
- const parsed = parseArgs(args.slice(1));
235
+ },
236
+ 'install-hooks': async (args) => {
237
+ const flags = commandFlags('install-hooks', parseArgs(args));
238
+ let redactionPacks;
239
+ if (flags.has('redaction-packs')) {
240
+ try {
241
+ redactionPacks = parseRedactionPacks(flags.value('redaction-packs'));
242
+ }
243
+ catch (err) {
244
+ process.stderr.write(`mainwave-cli install-hooks: ${err instanceof Error ? err.message : String(err)}\n`);
245
+ return 1;
246
+ }
247
+ }
267
248
  const dir = await sessionConfigDir();
268
249
  return runInstallHooks(dir === undefined ? undefined : claudeCodeFor(dir), {
269
- quiet: flagBool(parsed, 'quiet') === true,
250
+ quiet: flags.bool('quiet') === true,
251
+ ...(redactionPacks === undefined ? {} : { redactionPacks }),
270
252
  });
271
- }
272
- if (cmd === 'setup') {
273
- const parsed = parseArgs(args.slice(1));
274
- const requested = parsed.positionals;
275
- const named = [];
276
- for (const name of requested) {
277
- const resolved = resolveAdapter(name);
278
- if (typeof resolved === 'number')
279
- return resolved;
280
- named.push(resolved);
281
- }
253
+ },
254
+ setup: async (args) => {
255
+ const parsed = parseArgs(args);
256
+ const flags = commandFlags('setup', parsed);
257
+ const named = resolveAdapters(parsed.positionals);
258
+ if (typeof named === 'number')
259
+ return named;
282
260
  try {
283
- if (flagBool(parsed, 'remove') === true) {
261
+ if (flags.bool('remove') === true) {
284
262
  if (named.length === 0) {
285
263
  throw new WizardAbort('--remove needs the tools to remove, e.g. `setup kiro-ide --remove`');
286
264
  }
287
265
  return await runRemove(named, {
288
- yes: flagBool(parsed, 'yes') === true,
289
- json: flagBool(parsed, 'json') === true,
266
+ yes: flags.bool('yes') === true,
267
+ json: flags.bool('json') === true,
290
268
  });
291
269
  }
292
270
  const opts = setupOptions(parsed);
@@ -304,16 +282,17 @@ export const main = async (argv) => {
304
282
  catch (err) {
305
283
  return reportCommandError(err);
306
284
  }
307
- }
308
- const adapter = resolveAdapter(args[1]);
309
- if (typeof adapter === 'number')
310
- return adapter;
311
- if (cmd === 'edit') {
312
- const flags = args.slice(2);
313
- const local = flags.includes('--local');
314
- const global = flags.includes('--global');
285
+ },
286
+ edit: async (args) => {
287
+ const adapter = resolveAdapter(args[0]);
288
+ if (typeof adapter === 'number')
289
+ return adapter;
290
+ const flags = commandFlags('edit', parseArgs(args.slice(1)));
315
291
  try {
316
- return await runEdit(adapter, { local, global });
292
+ return await runEdit(adapter, {
293
+ local: flags.bool('local') === true,
294
+ global: flags.bool('global') === true,
295
+ });
317
296
  }
318
297
  catch (err) {
319
298
  if (err instanceof WizardAbort) {
@@ -323,21 +302,27 @@ export const main = async (argv) => {
323
302
  printError(err instanceof Error ? err.message : String(err));
324
303
  return 1;
325
304
  }
326
- }
327
- if (cmd === 'doctor') {
328
- const parsed = parseArgs(args.slice(2));
305
+ },
306
+ doctor: async (args) => {
307
+ const adapter = resolveAdapter(args[0]);
308
+ if (typeof adapter === 'number')
309
+ return adapter;
310
+ const flags = commandFlags('doctor', parseArgs(args.slice(1)));
329
311
  try {
330
312
  return await runDoctor(adapter, {
331
- validate: flagBool(parsed, 'validate') === true,
332
- json: flagBool(parsed, 'json') === true,
313
+ validate: flags.bool('validate') === true,
314
+ json: flags.bool('json') === true,
333
315
  });
334
316
  }
335
317
  catch (err) {
336
318
  printError(err instanceof Error ? err.message : String(err));
337
319
  return 1;
338
320
  }
339
- }
340
- if (cmd === 'env') {
321
+ },
322
+ env: async (args) => {
323
+ const adapter = resolveAdapter(args[0]);
324
+ if (typeof adapter === 'number')
325
+ return adapter;
341
326
  try {
342
327
  return await runEnvCommand(adapter);
343
328
  }
@@ -345,7 +330,23 @@ export const main = async (argv) => {
345
330
  printError(err instanceof Error ? err.message : String(err));
346
331
  return 1;
347
332
  }
333
+ },
334
+ };
335
+ export const main = async (argv) => {
336
+ const args = argv.slice(2);
337
+ const cmd = args[0];
338
+ if (cmd === undefined || cmd === '--help' || cmd === '-h' || cmd === 'help') {
339
+ printHelp();
340
+ return 0;
348
341
  }
349
- printError(`unknown command: ${cmd}`);
350
- return 1;
342
+ if (cmd === '--version' || cmd === '-v') {
343
+ console.log(VERSION);
344
+ return 0;
345
+ }
346
+ if (!isCommand(cmd)) {
347
+ printError(`unknown command: ${cmd}`);
348
+ printHelp();
349
+ return 1;
350
+ }
351
+ return HANDLERS[cmd](args.slice(1));
351
352
  };
@@ -54,6 +54,7 @@ import {
54
54
  markerLogPath,
55
55
  parseEnvFile,
56
56
  parseKv,
57
+ redactForSend,
57
58
  } from './marker-core.mjs'
58
59
 
59
60
  const LOG_NAME = 'kiro.log'
@@ -484,6 +485,9 @@ export const handOff = (
484
485
  argv = process.argv,
485
486
  script = fileURLToPath(import.meta.url),
486
487
  ) => {
488
+ // Redact before anything is written: plaintext never lands in the spool.
489
+ const out = redactForSend(body, label, log)
490
+ if (out === undefined) return false
487
491
  const dir = ensureSpool()
488
492
  const full = join(dir, FULL_MARK)
489
493
  if (sweepSpool(dir) >= SPOOL_MAX_FILES) {
@@ -503,7 +507,10 @@ export const handOff = (
503
507
  // not full before
504
508
  }
505
509
  const file = join(dir, `kiro-${Date.now()}-${randomBytes(6).toString('hex')}.json`)
506
- writeFileSync(file, JSON.stringify({ label, body }), { mode: 0o600, flag: 'wx' })
510
+ writeFileSync(file, JSON.stringify({ label, body: out.body, redacted: out.applied }), {
511
+ mode: 0o600,
512
+ flag: 'wx',
513
+ })
507
514
  const logFile = hookFlag(argv, '--log-file')
508
515
  const child = spawn(
509
516
  process.execPath,
@@ -549,6 +556,8 @@ export const send = async (argv = process.argv) => {
549
556
  log,
550
557
  timeoutMs: POST_TIMEOUT_MS,
551
558
  logOk: false,
559
+ // Redacted when it was spooled; one spooled with no rules is checked now.
560
+ redacted: spooled.redacted === true,
552
561
  })
553
562
  if (isOkStatus(status)) markDelivered(argv)
554
563
  }
@@ -27,6 +27,7 @@ import { basename, dirname, join } from 'node:path'
27
27
  import { fileURLToPath, pathToFileURL } from 'node:url'
28
28
 
29
29
  import {
30
+ claudeConfigDir,
30
31
  emitMarker,
31
32
  markerLog,
32
33
  markerManagedDir,
@@ -240,6 +241,10 @@ export const dispatch = async (
240
241
  env: sessionEnv,
241
242
  managedDir: markerManagedDir(hookArgv),
242
243
  }
244
+ // A Claude Code hook applies its own config dir's organization packs. Codex
245
+ // can't tell which Claude config dir an org delivered to, so it applies
246
+ // every recorded dir's.
247
+ const redactionConfigDir = host === 'claude-code' ? claudeConfigDir(sessionEnv) : undefined
243
248
  return Promise.all(
244
249
  features.map(async (feature) => {
245
250
  const spec = FEATURES[feature]
@@ -251,7 +256,12 @@ export const dispatch = async (
251
256
  // Only what the feature is bound to is ever posted.
252
257
  const emit = (args) => {
253
258
  const body = allowlistPayload(args.body, feature)
254
- return hasSpan(body) ? emitMarker({ ...args, body }) : Promise.resolve(undefined)
259
+ // Never `redacted: true`: only Kiro's own sender posts a spooled,
260
+ // already-redacted body, so no feature can skip the rules. The
261
+ // organization packs are the session's config dir's (§ redactForSend).
262
+ return hasSpan(body)
263
+ ? emitMarker({ ...args, body, redacted: false, redactionConfigDir })
264
+ : Promise.resolve(undefined)
255
265
  }
256
266
  const run = Promise.resolve(mod.handle(payload, { argv: hookArgv, emit })).then(
257
267
  () => 'done',
@@ -25,6 +25,7 @@ import { homedir } from 'node:os'
25
25
  import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
26
26
  import { fileURLToPath } from 'node:url'
27
27
 
28
+ import { loadHookRedaction, redactOtlpTraces } from './redaction.mjs'
28
29
  import {
29
30
  ATTR_CALLER_SPAN_ID,
30
31
  ATTR_CALLER_TRACE_ID,
@@ -1142,13 +1143,57 @@ export const buildMarkerPayload = ({
1142
1143
  ],
1143
1144
  })
1144
1145
 
1146
+ // The redaction rules this process runs, loaded on first use, per Claude
1147
+ // config dir ('' for a hook that can't tell its own): a dispatcher run's
1148
+ // features (and the Kiro sender) share one read of the settings and the rules
1149
+ // file.
1150
+ const hookRedaction = new Map()
1151
+
1152
+ /** Forget the loaded rules so the next send reads them again.
1153
+ * @internal
1154
+ */
1155
+ export const resetHookRedaction = () => {
1156
+ hookRedaction.clear()
1157
+ }
1158
+
1159
+ /**
1160
+ * The body to send, or `undefined` when it must not leave the machine. The
1161
+ * one place redaction happens: every hook's POST goes through `emitMarker`,
1162
+ * and Kiro's spool write through here too, so a send path cannot skip it.
1163
+ * `configDir` is the Claude config dir the hook runs for, which picks the
1164
+ * organization packs it applies; a hook that can't tell (Cursor's, Kiro's,
1165
+ * Codex's) passes none and applies every recorded dir's. `applied` is whether
1166
+ * rules ran. The `secrets` pack runs unless the developer turned it off (and
1167
+ * recorded no rules file, and no organization packs are recorded), in which
1168
+ * case the body is returned as it is; with rules that cannot be loaded or
1169
+ * run, nothing is sent and one line naming the reason (never span content)
1170
+ * goes to `log`: redaction that was asked for does not silently turn off.
1171
+ */
1172
+ export const redactForSend = (body, label, log, { configDir } = {}) => {
1173
+ const key = configDir ?? ''
1174
+ if (!hookRedaction.has(key)) hookRedaction.set(key, loadHookRedaction({ configDir }))
1175
+ const loaded = hookRedaction.get(key)
1176
+ if (loaded.state === 'off') return { body, applied: false }
1177
+ if (loaded.state === 'error') {
1178
+ log(`redaction unavailable (${loaded.reason}); not sending ${label}`)
1179
+ return undefined
1180
+ }
1181
+ try {
1182
+ return { body: redactOtlpTraces(loaded.redactor, body), applied: true }
1183
+ } catch (e) {
1184
+ log(`redaction failed (${e?.name ?? 'Error'}); not sending ${label}`)
1185
+ return undefined
1186
+ }
1187
+ }
1188
+
1145
1189
  /** Whether an HTTP status is a 2xx. */
1146
1190
  export const isOkStatus = (status) => Number.isInteger(status) && status >= 200 && status < 300
1147
1191
 
1148
1192
  /**
1149
1193
  * POST the OTLP body to the collector, failing open (any error is swallowed).
1150
1194
  * Resolves the response's HTTP status, or `undefined` when no response came
1151
- * (network error, abort at `timeoutMs`). Every outcome is logged, except a
1195
+ * (network error, abort at `timeoutMs`), and also when § redactForSend holds
1196
+ * the body back. Every outcome is logged, except a
1152
1197
  * 2xx when `logOk` is false — a caller that sends on every prompt keeps its
1153
1198
  * log to what someone diagnoses and records success itself from the status.
1154
1199
  */
@@ -1160,14 +1205,23 @@ export const emitMarker = async ({
1160
1205
  log,
1161
1206
  timeoutMs = EMIT_TIMEOUT_MS,
1162
1207
  logOk = true,
1208
+ redacted = false,
1209
+ redactionConfigDir,
1163
1210
  }) => {
1211
+ // `redacted`: the body already went through § redactForSend (a spooled one).
1212
+ // `redactionConfigDir`: the session's Claude config dir, which the
1213
+ // dispatcher passes for a Claude Code hook.
1214
+ const out = redacted
1215
+ ? { body }
1216
+ : redactForSend(body, label, log, { configDir: redactionConfigDir })
1217
+ if (out === undefined) return undefined
1164
1218
  const controller = new AbortController()
1165
1219
  const timer = setTimeout(() => controller.abort(), timeoutMs)
1166
1220
  try {
1167
1221
  const res = await fetch(`${endpoint.replace(/\/$/, '')}/v1/traces`, {
1168
1222
  method: 'POST',
1169
1223
  headers: { 'content-type': 'application/json', authorization: bearer },
1170
- body: JSON.stringify(body),
1224
+ body: JSON.stringify(out.body),
1171
1225
  signal: controller.signal,
1172
1226
  })
1173
1227
  if (logOk || !isOkStatus(res.status)) log(`posted ${label}: status=${res.status}`)
@@ -56,7 +56,7 @@
56
56
  "changed-file, added-line and removed-line counts",
57
57
  "repository-relative file paths with per-file added and removed line counts and a binary flag"
58
58
  ],
59
- "why": "Built-in tool, exact name, narrowed by the handler's `if` to Bash commands that start with `git`. The feature still returns immediately unless the command ran 'git commit' at a command position, and sends nothing unless the tool output carries git's new-commit summary line, so a failed commit sends nothing. Each commit is then read with `git show --numstat` under a 5 s budget. A commit that isn't the command's first word (`cd x && git commit`) is matched by the feature but not by `git *`; that miss is accepted rather than widening the `if` to every Bash command."
59
+ "why": "Built-in tool, exact name, narrowed by the handler's `if` to Bash commands that start with `git` (compound commands included). The feature still returns immediately unless the command ran 'git commit' at a command position, and sends nothing unless the tool output carries git's new-commit summary line, so a failed commit sends nothing. Each commit is then read with `git show --numstat` under a 5 s budget."
60
60
  },
61
61
  {
62
62
  "event": "PostToolUse",