@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
@@ -1,5 +1,5 @@
1
1
  import { select } from '@inquirer/prompts';
2
- import { mergePrefills, planAdapter, planHasChanges, planSnapshotBlocked, printMarkerCoexistenceNotes, printPostSetup, readPrefill, renderPlan, userHooksPath, writePlan, } from './apply.js';
2
+ import { defaultHookDirs, mergePrefills, planAdapter, planHasChanges, planSnapshotBlocked, printMarkerCoexistenceNotes, printPostSetup, readPrefill, renderPlan, userHooksPath, writePlan, } from './apply.js';
3
3
  import { runLogin } from './auth-commands.js';
4
4
  import { computeEffective, isManagedUnitDrop, nativeIdentityReason } from './effective-settings.js';
5
5
  import { isManagedIdentityConfig, isManagedLayer } from './layer-policy.js';
@@ -8,10 +8,13 @@ import { color } from './format.js';
8
8
  import { runInterview } from './interview.js';
9
9
  import { redeemInvite } from './platform.js';
10
10
  import { promptApiKey, promptCollectorUrl, promptConfirmWrite, promptSkills } from './prompts.js';
11
+ import { checkRedactionFile, hasRulesFile, nextRedactionChoice, redactionLines, redactionView, sendsUnredactedContent, uncoveredNotice, } from './redaction.js';
12
+ import { describeBreaks, flatRefreshBreaks, refreshInstalledHooks } from './hook-copies.js';
11
13
  import { installSkillsPayload } from './skills.js';
12
14
  import { adapterEffective, attributionOf, primaryCarries } from './status.js';
13
- import { activeSession, readCredentials, readSettings, rememberKey, resolveEndpoints, updateSettings, } from './store.js';
15
+ import { activeSession, assertSettingsWritable, readCredentials, readSettings, rememberKey, resolveEndpoints, updateSettings, } from './store.js';
14
16
  import { isInteractive } from './tty.js';
17
+ import { trimSlash } from './url.js';
15
18
  import { VERSION } from './version.js';
16
19
  import { emitJson, say, setJsonMode } from './ui.js';
17
20
  import { validateCollector } from './validate.js';
@@ -109,7 +112,7 @@ export const ucidRemovalNotice = (plan, onDisk) => onDisk !== undefined && plan.
109
112
  ? `${plan.adapter.displayName}: removing UCID ${onDisk} an earlier setup wrote; activity will ` +
110
113
  `now be attributed from your identity. Pass --ucid ${onDisk} to keep it.`
111
114
  : null;
112
- export const ucidIgnoredNotice = (adapter, explicitUcid) => adapter.carriesNoUcid && explicitUcid !== undefined
115
+ const ucidIgnoredNotice = (adapter, explicitUcid) => adapter.carriesNoUcid && explicitUcid !== undefined
113
116
  ? `${adapter.displayName}: its hooks send no use-case id, so --ucid / --use-case don't apply; ` +
114
117
  'its activity is attributed from your email.'
115
118
  : null;
@@ -240,6 +243,10 @@ export const redeemInviteToOverrides = async (token, apiUrl, options) => {
240
243
  export const runSetup = async (adapters, rawOptions = {}) => {
241
244
  setJsonMode(rawOptions.json === true);
242
245
  const interactive = isInteractive();
246
+ const redactionFile = rawOptions.redactionFile === undefined
247
+ ? undefined
248
+ : checkRedactionFile(rawOptions.redactionFile);
249
+ await assertSettingsWritable();
243
250
  const settings = await readSettings();
244
251
  const endpoints = resolveEndpoints(settings, {
245
252
  apiUrl: rawOptions.apiUrl,
@@ -281,7 +288,8 @@ export const runSetup = async (adapters, rawOptions = {}) => {
281
288
  apiUrl: endpoints.apiUrl,
282
289
  });
283
290
  say('');
284
- const { url: collectorUrl, key: apiKey, identity, } = await validateWithRetry(interview.collectorUrl, interview.apiKey, interactive);
291
+ const { url: validatedUrl, key: apiKey, identity, } = await validateWithRetry(interview.collectorUrl, interview.apiKey, interactive);
292
+ const collectorUrl = trimSlash(validatedUrl);
285
293
  const answers = { ...interview, collectorUrl, apiKey };
286
294
  const plans = await Promise.all(adapters.map((adapter, i) => planAdapter(adapter, answers, {
287
295
  onDisk: prefills[i]?.values,
@@ -323,8 +331,23 @@ export const runSetup = async (adapters, rawOptions = {}) => {
323
331
  if (!ok)
324
332
  throw new WizardAbort();
325
333
  }
334
+ const redactionChoice = nextRedactionChoice((await readSettings()).redaction, {
335
+ file: redactionFile,
336
+ noRedaction: options.noRedaction,
337
+ secrets: options.redactSecrets,
338
+ });
339
+ if (redactionChoice !== undefined)
340
+ await updateSettings({ redaction: redactionChoice });
341
+ const redaction = redactionView();
342
+ const hookDirs = defaultHookDirs();
343
+ const holdFlat = redaction.state !== 'off' && (await flatRefreshBreaks(hookDirs.flatDir)).length > 0;
326
344
  for (const plan of plans)
327
- await writePlan(plan);
345
+ await writePlan(plan, hookDirs, holdFlat);
346
+ const hookCopies = redaction.state === 'off'
347
+ ? undefined
348
+ : await refreshInstalledHooks(plans.some((p) => p.stageHooks), hookDirs);
349
+ if (hookCopies !== undefined)
350
+ printHookRefresh(hookCopies, holdFlat);
328
351
  for (const plan of plans)
329
352
  await warnIfShadowed(plan);
330
353
  if (options.rememberKeyAs && identity.orgId) {
@@ -355,6 +378,13 @@ export const runSetup = async (adapters, rawOptions = {}) => {
355
378
  { ...filesOf(p.adapter.name), [userHooksPath(p.adapter)]: [...p.hookEvents] },
356
379
  ])),
357
380
  };
381
+ hooks.routes = {
382
+ ...hooks.routes,
383
+ ...Object.fromEntries(markerTools.map((p) => [
384
+ p.adapter.name,
385
+ { ...hooks.routes?.[p.adapter.name], [userHooksPath(p.adapter)]: [...p.hookRoutes] },
386
+ ])),
387
+ };
358
388
  }
359
389
  await updateSettings({
360
390
  hooks,
@@ -373,6 +403,7 @@ export const runSetup = async (adapters, rawOptions = {}) => {
373
403
  }
374
404
  for (const plan of plans)
375
405
  printPostSetup(plan);
406
+ const unredacted = printRedactionNotes(redaction, plans, options);
376
407
  printRestartNotice(adapters);
377
408
  printPostSetupTips(adapters);
378
409
  const skills = await maybeInstallSkills(adapters, options, interactive);
@@ -405,6 +436,11 @@ export const runSetup = async (adapters, rawOptions = {}) => {
405
436
  optIns: answers.optIns,
406
437
  optInsByTool: Object.fromEntries(plans.map((p) => [p.adapter.name, p.input.optIns])),
407
438
  markers: answers.markers,
439
+ redaction: {
440
+ ...redaction,
441
+ uncovered: unredacted.map((a) => a.name),
442
+ ...(hookCopies === undefined ? {} : { hookCopies }),
443
+ },
408
444
  ...planSnapshotReport(plans, await blockedSnapshots(plans)),
409
445
  verified,
410
446
  skills: skills
@@ -415,10 +451,68 @@ export const runSetup = async (adapters, rawOptions = {}) => {
415
451
  }
416
452
  return 0;
417
453
  };
454
+ const printHookRefresh = (refresh, held) => {
455
+ if (refresh.skipped !== undefined) {
456
+ const scripts = refresh.skipped.map((b) => b.script).join(', ');
457
+ say('');
458
+ say(color.yellow(`Redaction is on, but the hook scripts in ~/.mainwave/hooks/ were ${held ? 'not copied or refreshed' : 'left as they are'}: ` +
459
+ `${describeBreaks(refresh.skipped)}, which this release no longer provides. ` +
460
+ 'The scripts there send spans without applying redaction rules until then; ' +
461
+ `remove ${scripts} from ~/.mainwave/hooks/ and re-run setup. Doctor reports them.`));
462
+ }
463
+ else if (refresh.flat.length > 0) {
464
+ say('');
465
+ say(color.dim(`Hook scripts in ~/.mainwave/hooks/ refreshed so they apply redaction.`));
466
+ }
467
+ if (refresh.staged) {
468
+ say('');
469
+ say(color.dim('Managed hook scripts refreshed so they apply redaction.'));
470
+ }
471
+ if (refresh.failed !== undefined) {
472
+ say('');
473
+ say(color.yellow(`Redaction is on, but refreshing the older hook copies failed (${refresh.failed}). ` +
474
+ 'Those copies send spans without applying redaction rules until a re-run of setup succeeds; doctor reports them.'));
475
+ }
476
+ };
477
+ const printRedactionNotes = (view, plans, options) => {
478
+ if (options.noRedaction) {
479
+ say('');
480
+ say(color.dim(view.state === 'on'
481
+ ? 'Rules file removed: the hooks still strip credentials by default.'
482
+ : 'Rules file removed.'));
483
+ }
484
+ if (view.state === 'error') {
485
+ say('');
486
+ say(color.yellow(`Redaction is on but its rules file can't be used, so the Mainwave hooks send nothing:\n` +
487
+ `${redactionLines(view, ' ').slice(1).join('\n')}\n` +
488
+ ' Fix the file, or run setup with --redaction-file <path> or --no-redaction.'));
489
+ }
490
+ if (view.state === 'off') {
491
+ say('');
492
+ say(color.yellow('Credential redaction is off: the hooks send API keys, tokens and private keys as they are. ' +
493
+ 'Run setup with --redact-secrets to turn the default back on.'));
494
+ }
495
+ if (view.state !== 'on')
496
+ return [];
497
+ say('');
498
+ say(color.bold('Redaction:'));
499
+ for (const line of redactionLines(view, ' '))
500
+ say(line);
501
+ if (!hasRulesFile(view))
502
+ return [];
503
+ const unredacted = plans
504
+ .filter((p) => sendsUnredactedContent(p.adapter, p.input.optIns))
505
+ .map((p) => p.adapter);
506
+ if (unredacted.length > 0) {
507
+ say('');
508
+ say(color.yellow(uncoveredNotice(unredacted)));
509
+ }
510
+ return unredacted;
511
+ };
418
512
  const blockedSnapshots = async (plans) => new Map((await Promise.all(plans
419
513
  .filter((p) => p.planSnapshotOn === true)
420
514
  .map(async (p) => [p.adapter.name, await planSnapshotBlocked(p.adapter)]))).flatMap(([name, why]) => (why ? [[name, why]] : [])));
421
- export const planSnapshotReport = (plans, blocked = new Map()) => {
515
+ const planSnapshotReport = (plans, blocked = new Map()) => {
422
516
  const hosts = plans.filter((p) => p.planSnapshotOn !== null);
423
517
  if (hosts.length === 0) {
424
518
  return { planSnapshot: false, planSnapshotReason: 'not-hosted' };
@@ -461,7 +555,7 @@ const maybeVerify = async (options, signedIn, ucid, apiUrl, teamOnly) => {
461
555
  return { verified: false, printed: undefined };
462
556
  }
463
557
  };
464
- export const printAttribution = (plans, context) => {
558
+ const printAttribution = (plans, context) => {
465
559
  const { pin, appUrl, verifyPrinted, accountless } = context;
466
560
  const lines = [];
467
561
  const pinned = pin ? plans.filter((p) => p.input.ucid === pin.id && !p.teamUcid) : [];
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
  };