@mainwave/cli 0.14.0 → 0.15.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.
package/README.md CHANGED
@@ -470,7 +470,9 @@ tool waiting for your approval, and the start and end times. They never send you
470
470
  reply, a tool's input or output, or the transcript path. They run in the background, except the
471
471
  stop and interrupt hooks: Codex waits for those at the end of each turn while they send it (1.2 s at
472
472
  most for the send, 1 s for an interrupt), because `codex exec` exits without waiting for a background hook. They keep a
473
- small state file per session in `~/.mainwave/state/codex-turns/`, deleted after seven days.
473
+ small state file per session in `~/.mainwave/state/codex-turns/`, deleted after seven days, and a
474
+ one-line timestamp file, `~/.mainwave/logs/codex-turns.log.ok`, that records the last successful
475
+ send for `doctor`.
474
476
 
475
477
  Codex runs a hook only after you trust it. The first Codex session after setup shows "Hooks need
476
478
  review": choose "Trust all", or open `/hooks` and trust each Mainwave hook, the session-start hook
@@ -495,10 +497,13 @@ For a profile, setup writes the telemetry settings and the Mainwave hooks into
495
497
  `<codex home>/<name>.config.toml`, and writes none to `config.toml` or `hooks.json`. A session
496
498
  started without `--profile <name>` sends nothing to Mainwave and runs no Mainwave hook. If the Codex
497
499
  home already has the all-sessions setup, the same run removes it from `config.toml` and
498
- `hooks.json`, so the home never holds both. The setup preview lists every file it changes. Once a
499
- profile is set up, running setup again with the same `--profile` changes nothing. The first run on a
500
- profile file that already has content appends Mainwave's hook tables at the end of the file, moves
501
- any `[[hooks.<Event>]]` tables already there to join them, and keeps the rest as it was.
500
+ `hooks.json`, so the home never holds both. When that leaves nothing in `hooks.json`, setup removes
501
+ the file and keeps a backup beside it. When it moves another tool's hooks in `hooks.json` to a new
502
+ position, Codex asks you to trust them again, and the preview says so. The setup preview lists every
503
+ file it changes. Once a profile is set up, running setup again with the same `--profile` changes
504
+ nothing. The first run on a profile file that already has content appends Mainwave's hook tables at
505
+ the end of the file, moves any `[[hooks.<Event>]]` tables already there to join them, and keeps the
506
+ rest as it was.
502
507
 
503
508
  A profile name is 1 to 64 letters, digits, `_` or `-`, and does not start with `-`. `default` is
504
509
  reserved by Codex. Setup refuses a name whose file already has an `[otel]` table that isn't
@@ -515,10 +520,29 @@ Add a separate alias, for example `alias codex-mw='codex --profile mainwave'`, a
515
520
  `codex`. `--profile` goes before the subcommand: `codex --profile mainwave exec resume <id>` resumes
516
521
  with the profile, and `codex exec resume --profile mainwave` exits with an error.
517
522
 
518
- `setup codex --remove` is not available for Codex. To remove a profile setup, delete
519
- `<codex home>/<name>.config.toml` if it holds nothing else of yours, or remove its `[otel.*]` tables
520
- and the `[[hooks.<Event>]]` tables whose commands name `mainwave-hook.sh` or `install-hooks`. That
521
- file holds your Mainwave API key.
523
+ To take Mainwave out of Codex again:
524
+
525
+ ```bash
526
+ mainwave-cli setup codex --remove # the all-sessions setup
527
+ mainwave-cli setup codex --remove --profile <name> # a profile setup
528
+ ```
529
+
530
+ The all-sessions removal takes Mainwave's telemetry settings out of `config.toml`, Mainwave's hooks
531
+ out of `hooks.json`, and Codex's approvals of those hooks out of `config.toml`. The profile removal
532
+ takes Mainwave's telemetry settings, hooks and hook approvals out of `<codex home>/<name>.config.toml`,
533
+ and Codex's approvals of those hooks out of `config.toml`. Everything else in those files stays as
534
+ it was, including other tools' hooks and Codex's approvals of them. Codex keys an approval by the
535
+ hook's position, so a hook listed after a removed Mainwave hook needs approving again; the preview
536
+ names each approved hook of another tool that moves, by its program only, since its arguments may hold a secret. A file left with nothing but Mainwave's setup is deleted, unless it
537
+ is a symlink: then the link stays and the file it points to is left empty (`{}` for `hooks.json`). The
538
+ preview lists every file the removal changes, and each one gets a backup beside it. The summary
539
+ marks each backup that still holds your API key. When no Codex setup is left, the removal also takes Mainwave's instructions out
540
+ of `<codex home>/AGENTS.md`. Run it with the same `CODEX_HOME` you ran setup with.
541
+
542
+ Plain `--remove` in a home whose only Mainwave setup is a profile's changes nothing, exits with
543
+ code 1, and names the profile and the `--remove --profile <name>` command. A removal that leaves
544
+ another setup in the home names that setup and the command that removes it. Running `--remove`
545
+ again says there is nothing to remove.
522
546
 
523
547
  Plain `setup codex` in a home that has a profile setup asks whether to update the profile or to
524
548
  switch to all sessions, which removes Mainwave from the profile file. Without a terminal it exits
@@ -528,12 +552,16 @@ with code 1 and names the `--profile` command, and `--yes` doesn't choose.
528
552
  its own. A profile's report is titled `Codex CLI, profile <name>`, lists the profile file as
529
553
  `Profile <name>` and its hooks as `Profile <name> hooks file`, and checks the endpoint, the
530
554
  authorization header, the metrics exporter and the hook approvals recorded in the profile file. It
531
- warns when a home holds Mainwave settings or hooks for all sessions and in a profile at once. Codex
532
- merges `config.toml` under the profile file table by table, so in profile sessions any header or
533
- setting of another vendor's `[otel]` exporter in `config.toml` that the profile does not set is also
534
- sent to Mainwave's collector. Mainwave's key is not sent to the other collector. `setup codex
535
- --profile` and `doctor` both warn about that. `status codex` lists each profile setup by name after
536
- the all-sessions files, and its `--json` output marks a profile entry with `"setup": "profile <name>"`.
555
+ warns when a home holds Mainwave settings or hooks for all sessions and in a profile at once, and
556
+ when more than one profile holds a Mainwave setup; `setup codex --profile` says so too when another
557
+ profile already holds one. Codex merges `config.toml` under the profile file table by table, so in
558
+ profile sessions any header or setting of another vendor's `[otel]` exporter in `config.toml` that
559
+ the profile does not set is also sent to Mainwave's collector. Mainwave's key is not sent to the
560
+ other collector. `setup codex --profile` and `doctor` both warn about that. Plain `setup codex`
561
+ replaces only Mainwave's own keys in `config.toml`, so another vendor's exporter headers or settings
562
+ there stay beside Mainwave's and are sent to Mainwave's collector in every session; setup and
563
+ `doctor` warn about that too. `status codex` lists each profile setup by name after the all-sessions
564
+ files, and its `--json` output marks a profile entry with `"setup": "profile <name>"`.
537
565
 
538
566
  On Windows, the Claude Code hooks need Git for Windows. Claude Code runs hook commands through Git
539
567
  Bash, and through PowerShell when it finds none, where the entry's shell command can't run. Without
@@ -700,7 +728,8 @@ lived there — and Cursor and VS Code Copilot Chat stop sending until then.
700
728
  To stop entirely, also remove the Mainwave entries from your tools' settings — for Claude Code,
701
729
  `mainwave-cli setup claude-code --no-markers` removes its hooks, or delete the hook groups that
702
730
  name `mainwave-hook.sh`, `install-hooks` or `--managed-by @mainwave/cli` from
703
- `~/.claude/settings.json`, along with the `OTEL_*` telemetry keys setup wrote. Hooks delivered
731
+ `~/.claude/settings.json`, along with the `OTEL_*` telemetry keys setup wrote. For Codex and Kiro,
732
+ `mainwave-cli setup <tool> --remove` takes their entries out. Hooks delivered
704
733
  through your organization's managed settings stay until your Claude admin removes them. Hooks
705
734
  now log under `~/.mainwave/logs/`; releases before that logged to `~/.mainwave-*.log` files in your
706
735
  home directory, which are left for you to delete.
@@ -8,7 +8,10 @@ import { tomlOtelCodec } from '../core/codecs/toml-otel.js';
8
8
  import { tomlProfileCodec } from '../core/codecs/toml-profile.js';
9
9
  import { UCID_SOURCE_EXPLICIT } from '../core/headers.js';
10
10
  import { versionAtLeast } from '../core/layer-policy.js';
11
+ import { WizardAbort } from '../core/errors.js';
11
12
  import { commandOwnership } from '../core/markers.js';
13
+ import { planSetupRemoval, removalSteps } from '../core/setup-removal.js';
14
+ import { planBlockRemoval } from '../core/skills.js';
12
15
  export const codexHome = (env = process.env) => {
13
16
  const dir = env.CODEX_HOME;
14
17
  if (dir === undefined || dir === '')
@@ -216,6 +219,21 @@ const profileFile = (home, profile) => join(home, profileFileName(profile));
216
219
  export const profileProcessNote = (profile) => `The profile applies to one Codex process: a session started without \`--profile ${profile}\`, ` +
217
220
  `\`codex resume\` included, sends nothing to Mainwave. Add a separate alias rather than ` +
218
221
  `typing the flag, for example \`alias codex-mw='codex --profile ${profile}'\`.`;
222
+ const profileRuns = (profiles) => profiles.map((p) => `\`codex --profile ${p}\``).join(' or ');
223
+ const profilesWithFiles = (home, profiles) => profiles.map((p) => `${p} (${profileFile(home, p)})`).join(', ');
224
+ const PROFILE_REMOVAL = 'delete the file if it holds nothing else of yours, or remove its [otel.*] tables and the ' +
225
+ '[[hooks.<Event>]] tables whose commands name mainwave-hook or install-hooks';
226
+ export const otherProfileSetupsNote = (home, profile) => {
227
+ const others = findCodexProfileSetups(home).filter((p) => p !== profile);
228
+ if (others.length === 0)
229
+ return undefined;
230
+ const one = others.length === 1;
231
+ return (`Codex ${one ? 'profile' : 'profiles'} ${profilesWithFiles(home, others)} already ` +
232
+ `${one ? 'holds' : 'hold'} a Mainwave setup. This run sets up profile ${profilesWithFiles(home, [profile])} ` +
233
+ `too and leaves ${others.join(', ')} as ${one ? 'it is' : 'they are'}, so sessions started with ` +
234
+ `${profileRuns([...others, profile])} send to Mainwave. To keep only ${profile}, remove Mainwave ` +
235
+ `from ${one ? `${others[0]}'s file` : 'the other files'}: ${PROFILE_REMOVAL}.`);
236
+ };
219
237
  const holdsMainwaveExporter = (env) => Object.keys(env).some((key) => {
220
238
  const m = /^(otel\..+)\.headers\.X-Mainwave-Source$/.exec(key);
221
239
  return (m !== null &&
@@ -231,6 +249,22 @@ export const otherExporterNote = (config, profiles) => `${config} has telemetry
231
249
  "collector. Mainwave's key is not sent to the other collector. If that matters, move the other " +
232
250
  "collector's settings into a profile file of their own, or set Mainwave up in a separate Codex " +
233
251
  'home with CODEX_HOME.';
252
+ const foreignExporterKeys = (env) => Object.keys(env).filter((k) => EXPORTER_KEY.test(k) && !MANAGED_ENV_KEYS.includes(k));
253
+ export const sharedExporterNote = (config, keys) => `${config} has telemetry settings for another collector beside Mainwave's (${keys.join(', ')}). ` +
254
+ "Codex sends each signal to one collector, so in every session any header or setting of that collector's " +
255
+ "that Mainwave's exporter does not replace is also sent to Mainwave's collector, and that collector " +
256
+ "gets no Codex telemetry. If that matters, move the other collector's settings into a Codex profile " +
257
+ '(`setup codex --profile <name>` sets Mainwave up in one instead), or set Mainwave up in a separate ' +
258
+ 'Codex home with CODEX_HOME.';
259
+ const sharedExporterIssues = (config, env) => {
260
+ const keys = foreignExporterKeys(env);
261
+ return keys.length === 0 ? [] : [{ level: 'warn', message: sharedExporterNote(config, keys) }];
262
+ };
263
+ export const homeSharedExporterWarning = (home) => {
264
+ const config = join(home, 'config.toml');
265
+ const env = readConfigEnv(config, tomlOtelCodec);
266
+ return env === undefined ? undefined : sharedExporterIssues(config, env)[0]?.message;
267
+ };
234
268
  export const profileOtherExporterWarning = (home, profile) => {
235
269
  const config = join(home, 'config.toml');
236
270
  let env;
@@ -252,6 +286,23 @@ const readConfigEnv = (path, codec = tomlProfileCodec) => {
252
286
  return undefined;
253
287
  }
254
288
  };
289
+ export const profileRefusal = (home, profile) => {
290
+ const path = profileFile(home, profile);
291
+ let body;
292
+ try {
293
+ body = readFileSync(path, 'utf8');
294
+ }
295
+ catch {
296
+ return undefined;
297
+ }
298
+ try {
299
+ tomlProfileCodec.parse(body, path);
300
+ return undefined;
301
+ }
302
+ catch (err) {
303
+ return err.message;
304
+ }
305
+ };
255
306
  const holdsProfileSetup = (path) => {
256
307
  const env = readConfigEnv(path);
257
308
  if (env !== undefined)
@@ -322,6 +373,17 @@ const codexDoctorSetups = (home) => {
322
373
  const which = `${profiles.length === 1 ? 'profile' : 'profiles'} ${profiles.join(', ')} (${files})`;
323
374
  const rerun = `mainwave-cli setup codex --profile ${profiles.length === 1 ? profiles[0] : '<name>'}`;
324
375
  const issues = [];
376
+ if (profiles.length > 1) {
377
+ issues.push({
378
+ level: 'warn',
379
+ message: `Mainwave is set up in Codex profiles ${profilesWithFiles(home, profiles)}, so sessions started ` +
380
+ `with ${profileRuns(profiles)} send to Mainwave. If you meant to keep one, remove Mainwave ` +
381
+ `from the others' files: ${PROFILE_REMOVAL}.`,
382
+ });
383
+ }
384
+ const perProfileVersion = profiles.length > 1
385
+ ? profiles.flatMap((p) => profileVersionIssues([p]).map((i) => i.message))
386
+ : [];
325
387
  if (homeConfig) {
326
388
  const where = homeHooks ? `${config} and ${hooksJson}` : config;
327
389
  issues.push({
@@ -356,6 +418,14 @@ const codexDoctorSetups = (home) => {
356
418
  })),
357
419
  ],
358
420
  issues,
421
+ ...(perProfileVersion.length === 0
422
+ ? {}
423
+ : {
424
+ onceInText: {
425
+ replaces: (issue) => perProfileVersion.includes(issue.message),
426
+ issues: profileVersionIssues(profiles),
427
+ },
428
+ }),
359
429
  };
360
430
  };
361
431
  const projectLayer = {
@@ -397,11 +467,11 @@ export const CODEX_CLI = {
397
467
  },
398
468
  };
399
469
  const CODEX_PROFILE_MIN_VERSION = '0.169.0';
400
- const tooOldForProfile = (version, profile) => version !== undefined && versionAtLeast(version, CODEX_PROFILE_MIN_VERSION) === false
470
+ const tooOldForProfile = (version, profiles) => version !== undefined && versionAtLeast(version, CODEX_PROFILE_MIN_VERSION) === false
401
471
  ? `Codex ${version} is installed, and Codex reads profile files from ${CODEX_PROFILE_MIN_VERSION}, ` +
402
- `so sessions started with \`codex --profile ${profile}\` send nothing to Mainwave until Codex is upgraded.`
472
+ `so sessions started with ${profileRuns(profiles)} send nothing to Mainwave until Codex is upgraded.`
403
473
  : undefined;
404
- const profileVersionIssues = (profile) => {
474
+ const profileVersionIssues = (profiles) => {
405
475
  if (process.platform === 'win32')
406
476
  return [];
407
477
  const version = CODEX_CLI.version();
@@ -414,16 +484,14 @@ const profileVersionIssues = (profile) => {
414
484
  },
415
485
  ];
416
486
  }
417
- const old = tooOldForProfile(version, profile);
487
+ const old = tooOldForProfile(version, profiles);
418
488
  return old === undefined ? [] : [{ level: 'warn', message: old }];
419
489
  };
420
490
  const profilePostSetup = (profile) => {
421
- const old = tooOldForProfile(CODEX_CLI.version(), profile);
491
+ const old = tooOldForProfile(CODEX_CLI.version(), [profile]);
422
492
  return `${old === undefined ? '' : `! ${old}\n`}` + profileNext(profile);
423
493
  };
424
- const profileNext = (profile) => `Next for Codex CLI: start \`codex --profile ${profile}\` and trust the Mainwave hooks once there ` +
425
- `("Trust all" at the "Hooks need review" prompt). Until then \`codex exec --profile ${profile}\` ` +
426
- `skips them. ${profileProcessNote(profile)}`;
494
+ const profileNext = (profile) => `Next for Codex CLI: start \`codex --profile ${profile}\`. ${profileProcessNote(profile)}`;
427
495
  const targetParts = (target) => {
428
496
  const { home } = target;
429
497
  const config = join(home, 'config.toml');
@@ -440,7 +508,15 @@ const targetParts = (target) => {
440
508
  localPath: join('.codex', 'hooks.json'),
441
509
  codec: jsonEnvCodec,
442
510
  },
443
- collectChecks,
511
+ collectChecks: (env) => {
512
+ const own = readConfigEnv(config, tomlOtelCodec);
513
+ return [
514
+ ...collectChecks(env),
515
+ ...(own !== undefined && holdsMainwaveExporter(own)
516
+ ? sharedExporterIssues(config, own)
517
+ : []),
518
+ ];
519
+ },
444
520
  kindOnly: { doctorSetups: () => codexDoctorSetups(home) },
445
521
  };
446
522
  case 'profile': {
@@ -461,7 +537,7 @@ const targetParts = (target) => {
461
537
  collectChecks: (env) => [
462
538
  ...collectChecks(env),
463
539
  { level: 'info', message: profileProcessNote(profile) },
464
- ...profileVersionIssues(profile),
540
+ ...profileVersionIssues([profile]),
465
541
  ],
466
542
  kindOnly: {
467
543
  codexProfile: profile,
@@ -477,6 +553,52 @@ const targetParts = (target) => {
477
553
  }
478
554
  }
479
555
  };
556
+ const removeCommand = (profile) => `mainwave-cli setup codex --remove${profile === undefined ? '' : ` --profile ${profile}`}`;
557
+ const planCodexRemoval = async (target) => {
558
+ const { home } = target;
559
+ const steps = await removalSteps(await planSetupRemoval(codexCliFor(target), { approvals: true }));
560
+ const config = join(home, 'config.toml');
561
+ const homeSetup = holdsMainwaveExporter(readConfigEnv(config, tomlOtelCodec) ?? {}) ||
562
+ holdsMainwaveHooks(join(home, 'hooks.json'));
563
+ const profiles = findCodexProfileSetups(home).filter((p) => target.kind === 'home' || p !== target.profile);
564
+ if (target.kind === 'home' && steps.length === 0 && profiles.length > 0) {
565
+ const where = profiles.map((p) => `profile ${p} (${profileFile(home, p)})`).join(' and ');
566
+ throw new WizardAbort(`Mainwave isn't set up for every Codex session in ${home}; it is set up in ${where}. ` +
567
+ `To remove it, run ${profiles.map((p) => `\`${removeCommand(p)}\``).join(' and ')}.`);
568
+ }
569
+ const notes = [
570
+ ...(target.kind === 'profile' && steps.length === 0
571
+ ? [
572
+ {
573
+ kind: 'note',
574
+ note: `Nothing to remove: no Mainwave setup in ${profileFile(home, target.profile)}.`,
575
+ },
576
+ ]
577
+ : []),
578
+ ...(target.kind === 'profile' && homeSetup
579
+ ? [
580
+ {
581
+ kind: 'note',
582
+ note: `Mainwave is still set up for every Codex session (${config}); \`${removeCommand()}\` removes it.`,
583
+ },
584
+ ]
585
+ : []),
586
+ ...profiles.map((p) => ({
587
+ kind: 'note',
588
+ note: `Mainwave is still set up in profile ${p} (${profileFile(home, p)}); \`${removeCommand(p)}\` removes it.`,
589
+ })),
590
+ ];
591
+ const lastSetup = profiles.length === 0 && (target.kind === 'home' || !homeSetup);
592
+ const agents = lastSetup ? await planBlockRemoval(join(home, 'AGENTS.md')) : undefined;
593
+ return [...notes, ...steps, ...(agents === undefined ? [] : [withBackup(agents)])];
594
+ };
595
+ const withBackup = (step) => {
596
+ if (step.kind === 'update')
597
+ return { ...step, update: { ...step.update, backup: true } };
598
+ if (step.kind === 'delete')
599
+ return { ...step, backup: true };
600
+ return step;
601
+ };
480
602
  export const codexCliFor = (target) => {
481
603
  const { home } = target;
482
604
  const parts = targetParts(target);
@@ -508,6 +630,7 @@ export const codexCliFor = (target) => {
508
630
  collectFileChecks,
509
631
  normalizeForGenericChecks,
510
632
  holdsOwnSetup: holdsMainwaveExporter,
633
+ removal: { group: 'codex', plan: () => planCodexRemoval(target) },
511
634
  ...parts.kindOnly,
512
635
  markers: {
513
636
  disclosure: 'Sends Linear/Jira issue ids and GitHub PR / GitLab MR urls to the collector — never ticket bodies or diff content. ' +
package/dist/commands.js CHANGED
@@ -80,12 +80,15 @@ export const COMMANDS = [
80
80
  ' sessions started with `codex --profile <name>`, from',
81
81
  ' <codex home>/<name>.config.toml. Moves an all-sessions Codex',
82
82
  ' setup there. Other tools named with it are set up as usual;',
83
- ' without codex among the tools it is an error',
83
+ ' without codex among the tools it is an error. With --remove',
84
+ ' it picks the profile setup to remove',
84
85
  ' --yes --json --no-verify --verify-timeout <seconds>',
85
86
  ' --skills / --no-skills install the agent skills payload (default: ask, or on in scripts)',
86
87
  ' --skills-only install only the skills, touching no telemetry config',
87
88
  " --remove take this CLI's config for the named tools back off this",
88
- ' machine (Kiro: its hooks file entries and kiro.env)',
89
+ ' machine (Kiro: its hooks file entries and kiro.env; Codex: its',
90
+ ' telemetry settings, hooks and hook approvals, from every',
91
+ ' session or, with --profile <name>, from that profile)',
89
92
  ],
90
93
  flags: [
91
94
  f('--api-key'),
@@ -9,7 +9,8 @@ import { activeManagedScans, BOOTSTRAP_KEY, codexRefreshCommand, commandGenerati
9
9
  import { hasCredentialShape } from './headers.js';
10
10
  import { isManagedLayer } from './layer-policy.js';
11
11
  import { adapterEffective, statusSetups } from './status.js';
12
- import { applyUpdate, isSamePath, prepareUpdate, readExistingEnv } from './settings.js';
12
+ import { applyUpdate, isSamePath, prepareUpdate, readExistingEnv, removeSettingsFile, } from './settings.js';
13
+ import { planSetupRemoval } from './setup-removal.js';
13
14
  import { say } from './ui.js';
14
15
  import { VERSION } from './version.js';
15
16
  const hasAnyChange = (diff) => diff.added.length > 0 || diff.changed.length > 0 || diff.removed.length > 0;
@@ -171,9 +172,14 @@ export const planAdapter = async (adapter, answers, context = {}) => {
171
172
  codec: aw.codec,
172
173
  mode: aw.mode,
173
174
  })));
174
- const replaced = (await Promise.all((adapter.replaces ?? []).map((r) => planReplaced(r)))).flat();
175
+ const replaced = (await Promise.all((adapter.replaces ?? []).map((r) => planSetupRemoval(r)))).flat();
175
176
  const labeled = [
176
- ...replaced.map(({ update }) => ({ label: update.path, update })),
177
+ ...replaced.map(({ update, remove, linkTarget }) => ({
178
+ label: update.path,
179
+ update,
180
+ ...(remove ? { remove } : {}),
181
+ ...(linkTarget !== undefined ? { linkTarget } : {}),
182
+ })),
177
183
  { label: primary, update: primaryUpdate },
178
184
  ...(separateMarkersUpdate
179
185
  ? [{ label: separateMarkersUpdate.path, update: separateMarkersUpdate }]
@@ -209,31 +215,6 @@ export const planAdapter = async (adapter, answers, context = {}) => {
209
215
  ...(keptPin ? { keptPin: pin } : {}),
210
216
  };
211
217
  };
212
- const planReplaced = async (replaced) => {
213
- const path = replaced.paths.global;
214
- const env = await readExistingEnv(path, replaced.codec);
215
- const owns = env !== null && (replaced.holdsOwnSetup?.(env) ?? true);
216
- const config = await prepareUpdate({
217
- path,
218
- newEnv: {},
219
- managedKeys: owns ? [...replaced.managedEnvKeys, ...(replaced.retiredEnvKeys ?? [])] : [],
220
- codec: replaced.codec,
221
- });
222
- const hooksFile = replaced.markers?.hooksFile;
223
- if (hooksFile === undefined)
224
- return [{ update: config, markersPlan: null }];
225
- if (isSamePath(hooksFile.path, path)) {
226
- const markersPlan = config.exists ? planMarkers(config.next, []) : null;
227
- if (markersPlan !== null)
228
- config.next = markersPlan.next;
229
- return [{ update: config, markersPlan }];
230
- }
231
- const hooks = await prepareMarkersFile(hooksFile.path, hooksFile.codec, []);
232
- return [
233
- { update: config, markersPlan: null },
234
- { update: hooks.update, markersPlan: hooks.plan },
235
- ];
236
- };
237
218
  export const hookShellMissingFor = async (adapter, settingsEnv) => {
238
219
  if (process.platform !== 'win32')
239
220
  return false;
@@ -279,7 +260,7 @@ export const renderPlan = (plan) => {
279
260
  say(color.dim(`${plan.adapter.displayName}: no changes needed in ${plan.primaryPath}.`));
280
261
  return;
281
262
  }
282
- for (const { label, update } of plan.changed) {
263
+ for (const { label, update, remove, linkTarget } of plan.changed) {
283
264
  say('');
284
265
  say(color.bold(`Changes to ${label}:`));
285
266
  const body = renderDiff(update.diff);
@@ -298,6 +279,20 @@ export const renderPlan = (plan) => {
298
279
  say(painted);
299
280
  }
300
281
  }
282
+ if (remove) {
283
+ say(color.dim(' Nothing else is in it, so setup removes the file and keeps a backup beside it.'));
284
+ }
285
+ if (linkTarget !== undefined) {
286
+ say(color.dim(` Nothing else is in it, but it links to ${linkTarget}, so setup keeps the link ` +
287
+ 'and leaves that file empty ({}), which Codex reads as no hooks. It keeps a backup ' +
288
+ 'beside the link.'));
289
+ }
290
+ const moved = markersPlan?.movedForeign ?? 0;
291
+ if (plan.hookHost === 'codex' && moved > 0) {
292
+ say(color.yellow(` Removing Mainwave's hooks from ${update.path} moves ${moved} of your other ` +
293
+ 'hooks there to a new position, so Codex will ask you to trust them again ("Hooks need review", ' +
294
+ 'or /hooks) the next time it starts.'));
295
+ }
301
296
  }
302
297
  };
303
298
  export const planHasChanges = (plans) => plans.some((p) => p.changed.length > 0);
@@ -327,10 +322,12 @@ export const writePlan = async (plan, dirs = defaultHookDirs(), holdFlat = false
327
322
  say(color.dim(`Hook scripts refreshed in ${dest}.`));
328
323
  }
329
324
  const done = [];
330
- for (const { update } of plan.changed) {
325
+ for (const { update, remove } of plan.changed) {
331
326
  let result;
332
327
  try {
333
- result = await applyUpdate(update);
328
+ result = remove
329
+ ? { backupPath: await removeSettingsFile(update.path), written: update.path }
330
+ : await applyUpdate(update);
334
331
  }
335
332
  catch (err) {
336
333
  if (done.length > 0)
@@ -339,7 +336,7 @@ export const writePlan = async (plan, dirs = defaultHookDirs(), holdFlat = false
339
336
  }
340
337
  done.push({ update, result });
341
338
  say('');
342
- say(color.green(`✓ Wrote ${result.written}`));
339
+ say(color.green(`✓ ${remove ? 'Removed' : 'Wrote'} ${result.written}`));
343
340
  if (result.backupPath) {
344
341
  say(color.dim(` backup: ${result.backupPath}`));
345
342
  }
@@ -425,12 +422,14 @@ export const printMarkerCoexistenceNotes = async (adapter, targetPath, markersOn
425
422
  }
426
423
  }
427
424
  };
428
- const codexTrustNote = (reading, hooksPath, run = 'codex') => {
425
+ const codexTrustNote = (reading, hooksPath, profile) => {
426
+ const run = profile === undefined ? 'codex' : `codex --profile ${profile}`;
427
+ const exec = profile === undefined ? 'codex exec' : `codex exec --profile ${profile}`;
429
428
  const how = `Start \`${run}\` and choose "Trust all" at the "Hooks need review" prompt, or open /hooks and trust each ` +
430
429
  'Mainwave hook, the session-start hook included. Codex asks again whenever a Mainwave hook changes, such as ' +
431
430
  'when a setup run adds a route or a release changes a command, so approve again after such a run; a run that ' +
432
431
  "removes a Mainwave hook moves the hooks after it, so Codex may ask about other tools' hooks too. " +
433
- '`codex exec` skips them unless it runs with --dangerously-bypass-hook-trust. ' +
432
+ `\`${exec}\` skips them unless it runs with --dangerously-bypass-hook-trust. ` +
434
433
  '`mainwave-cli doctor` reports the hooks Codex skips.';
435
434
  if (reading?.state === 'read') {
436
435
  const n = countTrust(reading.hooks);
@@ -476,7 +475,7 @@ export const printPostSetup = (plan) => {
476
475
  ? undefined
477
476
  : readCodexTrust(hooksFile.path, plan.adapter.trustFiles ?? [], hooksFile.path, hooksFile.codec);
478
477
  say('');
479
- say(color.dim(codexTrustNote(reading, hooksFile?.path, plan.adapter.runInstruction)));
478
+ say(color.dim(codexTrustNote(reading, hooksFile?.path, plan.adapter.codexProfile)));
480
479
  }
481
480
  const snippet = plan.adapter.printPostSetupInstructions?.(plan.input);
482
481
  if (snippet) {
@@ -190,13 +190,7 @@ const renderGroup = (event, group) => {
190
190
  return lines.join('\n');
191
191
  };
192
192
  const parse = (body, path) => {
193
- let split;
194
- try {
195
- split = splitHooks(body, path);
196
- }
197
- catch (err) {
198
- throw new Error(`failed to parse ${path} as TOML: ${err.message}`);
199
- }
193
+ const split = splitHooks(body, path);
200
194
  const root = tomlOtelCodec.parse(split.rest, path);
201
195
  if (Object.keys(split.hooks).length > 0)
202
196
  root.hooks = split.hooks;