@mainwave/cli 0.13.1 → 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.
@@ -1,10 +1,17 @@
1
- import { realpathSync } from 'node:fs';
1
+ import { spawnSync } from 'node:child_process';
2
+ import { readdirSync, readFileSync, realpathSync } from 'node:fs';
2
3
  import { homedir } from 'node:os';
3
4
  import { join, resolve } from 'node:path';
4
5
  import { jsonEnvCodec } from '../core/codecs/json-env.js';
5
- import { hasBinary, hasPath } from '../core/detect.js';
6
+ import { hasBinary, hasPath, trustedBinary, trustedPath } from '../core/detect.js';
6
7
  import { tomlOtelCodec } from '../core/codecs/toml-otel.js';
8
+ import { tomlProfileCodec } from '../core/codecs/toml-profile.js';
7
9
  import { UCID_SOURCE_EXPLICIT } from '../core/headers.js';
10
+ import { versionAtLeast } from '../core/layer-policy.js';
11
+ import { WizardAbort } from '../core/errors.js';
12
+ import { commandOwnership } from '../core/markers.js';
13
+ import { planSetupRemoval, removalSteps } from '../core/setup-removal.js';
14
+ import { planBlockRemoval } from '../core/skills.js';
8
15
  export const codexHome = (env = process.env) => {
9
16
  const dir = env.CODEX_HOME;
10
17
  if (dir === undefined || dir === '')
@@ -186,56 +193,453 @@ const collectChecks = (env) => {
186
193
  });
187
194
  return issues;
188
195
  };
189
- const HIERARCHY = [
190
- {
191
- id: 'projectLocal',
192
- label: 'Project (local)',
193
- path: join('.codex', 'config.toml'),
194
- kind: 'file',
195
- },
196
- {
197
- id: 'user',
198
- label: 'User (global)',
199
- path: join(codexHome(), 'config.toml'),
200
- kind: 'file',
201
- },
202
- ];
203
- export const codexCli = {
204
- name: 'codex',
205
- displayName: 'Codex CLI',
206
- runInstruction: 'codex',
207
- detect: () => hasPath(codexHome()) || hasBinary('codex'),
208
- instructionSurface: {
209
- kind: 'instructions-file',
210
- global: join(codexHome(), 'AGENTS.md'),
211
- local: 'AGENTS.md',
212
- label: 'AGENTS.md',
213
- },
214
- paths: {
215
- local: join('.codex', 'config.toml'),
216
- global: join(codexHome(), 'config.toml'),
196
+ export const CODEX_ADAPTER_NAME = 'codex';
197
+ const PROFILE_NAME_RE = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$/;
198
+ export const parseProfileName = (raw) => {
199
+ if (raw === undefined || raw === '') {
200
+ throw new Error('--profile requires a name, e.g. --profile mainwave');
201
+ }
202
+ if (!PROFILE_NAME_RE.test(raw)) {
203
+ throw new Error(`--profile ${JSON.stringify(raw)}: a profile name is 1 to 64 letters, digits, "_" or "-", ` +
204
+ 'not starting with "-"');
205
+ }
206
+ if (raw === 'default') {
207
+ throw new Error('--profile default: Codex reserves "default"; pick another name');
208
+ }
209
+ return raw;
210
+ };
211
+ export const homeTarget = (env = process.env) => ({
212
+ kind: 'home',
213
+ home: codexHome(env),
214
+ });
215
+ export const profileTarget = (profile, env = process.env) => ({ kind: 'profile', home: codexHome(env), profile });
216
+ const PROFILE_FILE_SUFFIX = '.config.toml';
217
+ export const profileFileName = (profile) => `${profile}${PROFILE_FILE_SUFFIX}`;
218
+ const profileFile = (home, profile) => join(home, profileFileName(profile));
219
+ export const profileProcessNote = (profile) => `The profile applies to one Codex process: a session started without \`--profile ${profile}\`, ` +
220
+ `\`codex resume\` included, sends nothing to Mainwave. Add a separate alias rather than ` +
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
+ };
237
+ const holdsMainwaveExporter = (env) => Object.keys(env).some((key) => {
238
+ const m = /^(otel\..+)\.headers\.X-Mainwave-Source$/.exec(key);
239
+ return (m !== null &&
240
+ env[`${m[1]}.endpoint`] !== undefined &&
241
+ env[`${m[1]}.headers.Authorization`] !== undefined);
242
+ });
243
+ const EXPORTER_KEY = /^otel\.(?:exporter|trace_exporter|metrics_exporter)\./;
244
+ const holdsOtherExporter = (env) => !holdsMainwaveExporter(env) && Object.keys(env).some((k) => EXPORTER_KEY.test(k));
245
+ export const otherExporterNote = (config, profiles) => `${config} has telemetry settings for another collector. Codex applies config.toml under ` +
246
+ `${profiles.map((p) => p.file).join(' and ')}, so in sessions started with ` +
247
+ `${profiles.map((p) => `\`codex --profile ${p.profile}\``).join(' or ')}, any header or setting ` +
248
+ "from that collector's exporter that the profile does not set is also sent to Mainwave's " +
249
+ "collector. Mainwave's key is not sent to the other collector. If that matters, move the other " +
250
+ "collector's settings into a profile file of their own, or set Mainwave up in a separate Codex " +
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
+ };
268
+ export const profileOtherExporterWarning = (home, profile) => {
269
+ const config = join(home, 'config.toml');
270
+ let env;
271
+ try {
272
+ env = tomlOtelCodec.readEnv(tomlOtelCodec.parse(readFileSync(config, 'utf8'), config));
273
+ }
274
+ catch {
275
+ return undefined;
276
+ }
277
+ return holdsOtherExporter(env)
278
+ ? otherExporterNote(config, [{ profile, file: profileFile(home, profile) }])
279
+ : undefined;
280
+ };
281
+ const readConfigEnv = (path, codec = tomlProfileCodec) => {
282
+ try {
283
+ return codec.readEnv(codec.parse(readFileSync(path, 'utf8'), path));
284
+ }
285
+ catch {
286
+ return undefined;
287
+ }
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
+ };
306
+ const holdsProfileSetup = (path) => {
307
+ const env = readConfigEnv(path);
308
+ if (env !== undefined)
309
+ return holdsMainwaveExporter(env);
310
+ try {
311
+ return readFileSync(path, 'utf8').includes('X-Mainwave-Source');
312
+ }
313
+ catch {
314
+ return false;
315
+ }
316
+ };
317
+ export const findCodexProfileSetups = (home) => {
318
+ let names;
319
+ try {
320
+ names = readdirSync(home);
321
+ }
322
+ catch {
323
+ return [];
324
+ }
325
+ return names
326
+ .filter((n) => n.endsWith(PROFILE_FILE_SUFFIX))
327
+ .map((n) => n.slice(0, -PROFILE_FILE_SUFFIX.length))
328
+ .filter((n) => PROFILE_NAME_RE.test(n) && n !== 'default')
329
+ .filter((n) => holdsProfileSetup(profileFile(home, n)))
330
+ .sort();
331
+ };
332
+ export const profileConflict = (home, profile) => {
333
+ const path = profileFile(home, profile);
334
+ const env = readConfigEnv(path);
335
+ if (env === undefined || holdsMainwaveExporter(env))
336
+ return undefined;
337
+ if (!Object.keys(env).some((k) => k === 'otel' || k.startsWith('otel.')))
338
+ return undefined;
339
+ return (`${path} already has an [otel] table that is not Mainwave's. Setup won't replace another ` +
340
+ 'collector: pick another --profile name, or remove that table and re-run setup.');
341
+ };
342
+ const holdsMainwaveHooks = (path) => {
343
+ let doc;
344
+ try {
345
+ doc = JSON.parse(readFileSync(path, 'utf8'));
346
+ }
347
+ catch {
348
+ return false;
349
+ }
350
+ const hooks = doc?.hooks;
351
+ if (hooks === null || typeof hooks !== 'object')
352
+ return false;
353
+ return Object.values(hooks).some((groups) => Array.isArray(groups) &&
354
+ groups.some((g) => Array.isArray(g?.hooks) &&
355
+ g.hooks.some((h) => typeof h?.command === 'string' && commandOwnership(h.command) === 'cli')));
356
+ };
357
+ const codexDoctorSetups = (home) => {
358
+ const profiles = findCodexProfileSetups(home);
359
+ if (profiles.length === 0)
360
+ return undefined;
361
+ const allSessions = { kind: 'home', home };
362
+ const profileTargets = profiles.map((profile) => ({
363
+ kind: 'profile',
364
+ home,
365
+ profile,
366
+ }));
367
+ const { own: config, codec, hooksFile } = targetParts(allSessions);
368
+ const hooksJson = hooksFile.path;
369
+ const configEnv = readConfigEnv(config, codec) ?? {};
370
+ const homeConfig = holdsMainwaveExporter(configEnv);
371
+ const homeHooks = holdsMainwaveHooks(hooksJson);
372
+ const files = profileTargets.map((t) => targetParts(t).own).join(', ');
373
+ const which = `${profiles.length === 1 ? 'profile' : 'profiles'} ${profiles.join(', ')} (${files})`;
374
+ const rerun = `mainwave-cli setup codex --profile ${profiles.length === 1 ? profiles[0] : '<name>'}`;
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
+ : [];
387
+ if (homeConfig) {
388
+ const where = homeHooks ? `${config} and ${hooksJson}` : config;
389
+ issues.push({
390
+ level: 'warn',
391
+ message: `Mainwave is set up for every Codex session (${where}) and in ${which}. Sessions started ` +
392
+ 'without --profile still send to Mainwave' +
393
+ (homeHooks ? ', and a session started with it runs the Mainwave hooks twice' : '') +
394
+ '. Run setup again with the route you want: ' +
395
+ `\`${rerun}\` keeps only the profile, \`mainwave-cli setup codex\` only every session.`,
396
+ });
397
+ }
398
+ else if (homeHooks) {
399
+ issues.push({
400
+ level: 'warn',
401
+ message: `Mainwave hooks are still in ${hooksJson}, which every Codex session runs, while the Mainwave ` +
402
+ `config is in ${which}. They send nothing, since ${config} has no Mainwave settings. ` +
403
+ `Run \`${rerun}\` again to remove them, or \`mainwave-cli setup codex\` to switch to every session.`,
404
+ });
405
+ }
406
+ else if (holdsOtherExporter(configEnv)) {
407
+ issues.push({
408
+ level: 'warn',
409
+ message: otherExporterNote(config, profileTargets.map((t, i) => ({ profile: profiles[i], file: targetParts(t).own }))),
410
+ });
411
+ }
412
+ return {
413
+ setups: [
414
+ ...(homeConfig ? [{ label: 'every session', adapter: codexCliFor(allSessions) }] : []),
415
+ ...profiles.map((profile, i) => ({
416
+ label: `profile ${profile}`,
417
+ adapter: codexCliFor(profileTargets[i]),
418
+ })),
419
+ ],
420
+ issues,
421
+ ...(perProfileVersion.length === 0
422
+ ? {}
423
+ : {
424
+ onceInText: {
425
+ replaces: (issue) => perProfileVersion.includes(issue.message),
426
+ issues: profileVersionIssues(profiles),
427
+ },
428
+ }),
429
+ };
430
+ };
431
+ const projectLayer = {
432
+ id: 'projectLocal',
433
+ label: 'Project (local)',
434
+ path: join('.codex', 'config.toml'),
435
+ kind: 'file',
436
+ };
437
+ const userLayer = (home) => ({
438
+ id: 'user',
439
+ label: 'User (global)',
440
+ path: join(home, 'config.toml'),
441
+ kind: 'file',
442
+ });
443
+ let codexVersionCache;
444
+ export const CODEX_CLI = {
445
+ version: () => {
446
+ if (process.platform === 'win32')
447
+ return undefined;
448
+ if (!codexVersionCache) {
449
+ let value;
450
+ const bin = trustedBinary('codex');
451
+ try {
452
+ const r = bin
453
+ ? spawnSync(bin, ['--version'], {
454
+ encoding: 'utf8',
455
+ timeout: 5000,
456
+ env: { ...process.env, PATH: trustedPath() },
457
+ })
458
+ : undefined;
459
+ value = r?.status === 0 ? /\d+\.\d+\.\d+/.exec(r.stdout)?.[0] : undefined;
460
+ }
461
+ catch {
462
+ value = undefined;
463
+ }
464
+ codexVersionCache = { value };
465
+ }
466
+ return codexVersionCache.value;
217
467
  },
218
- injectsIdentity: true,
219
- codec: tomlOtelCodec,
220
- managedEnvKeys: MANAGED_ENV_KEYS,
221
- retiredEnvKeys: RETIRED_ENV_KEYS,
222
- alwaysOnOptIns: { toolDetails: true, toolContent: true },
223
- hierarchy: HIERARCHY,
224
- buildEnv,
225
- parseEnv,
226
- collectChecks,
227
- collectFileChecks,
228
- normalizeForGenericChecks,
229
- markers: {
230
- disclosure: 'Sends Linear/Jira issue ids and GitHub PR / GitLab MR urls to the collector — never ticket bodies or diff content. ' +
231
- 'It also sends, for each Codex turn, the session, turn and subagent ids, the working directory, the name of a tool ' +
232
- 'call waiting for your approval, and when the turn, the wait and the subagent started and ended — ids and ' +
233
- 'timestamps, never prompt or response text.',
234
- hooksFile: {
235
- path: join(codexHome(), 'hooks.json'),
236
- localPath: join('.codex', 'hooks.json'),
237
- codec: jsonEnvCodec,
468
+ };
469
+ const CODEX_PROFILE_MIN_VERSION = '0.169.0';
470
+ const tooOldForProfile = (version, profiles) => version !== undefined && versionAtLeast(version, CODEX_PROFILE_MIN_VERSION) === false
471
+ ? `Codex ${version} is installed, and Codex reads profile files from ${CODEX_PROFILE_MIN_VERSION}, ` +
472
+ `so sessions started with ${profileRuns(profiles)} send nothing to Mainwave until Codex is upgraded.`
473
+ : undefined;
474
+ const profileVersionIssues = (profiles) => {
475
+ if (process.platform === 'win32')
476
+ return [];
477
+ const version = CODEX_CLI.version();
478
+ if (version === undefined) {
479
+ return [
480
+ {
481
+ level: 'info',
482
+ message: `Couldn't read the Codex version (\`codex --version\`); a profile setup needs Codex ` +
483
+ `${CODEX_PROFILE_MIN_VERSION} or later.`,
484
+ },
485
+ ];
486
+ }
487
+ const old = tooOldForProfile(version, profiles);
488
+ return old === undefined ? [] : [{ level: 'warn', message: old }];
489
+ };
490
+ const profilePostSetup = (profile) => {
491
+ const old = tooOldForProfile(CODEX_CLI.version(), [profile]);
492
+ return `${old === undefined ? '' : `! ${old}\n`}` + profileNext(profile);
493
+ };
494
+ const profileNext = (profile) => `Next for Codex CLI: start \`codex --profile ${profile}\`. ${profileProcessNote(profile)}`;
495
+ const targetParts = (target) => {
496
+ const { home } = target;
497
+ const config = join(home, 'config.toml');
498
+ switch (target.kind) {
499
+ case 'home':
500
+ return {
501
+ own: config,
502
+ runInstruction: 'codex',
503
+ codec: tomlOtelCodec,
504
+ trustFiles: [config],
505
+ hierarchy: [projectLayer, userLayer(home)],
506
+ hooksFile: {
507
+ path: join(home, 'hooks.json'),
508
+ localPath: join('.codex', 'hooks.json'),
509
+ codec: jsonEnvCodec,
510
+ },
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
+ },
520
+ kindOnly: { doctorSetups: () => codexDoctorSetups(home) },
521
+ };
522
+ case 'profile': {
523
+ const { profile } = target;
524
+ const own = profileFile(home, profile);
525
+ return {
526
+ own,
527
+ runInstruction: `codex --profile ${profile}`,
528
+ codec: tomlProfileCodec,
529
+ trustFiles: [config, own],
530
+ hierarchy: [
531
+ projectLayer,
532
+ { id: 'profile', label: `Profile ${profile}`, path: own, kind: 'file' },
533
+ userLayer(home),
534
+ ],
535
+ hooksFile: { path: own, codec: tomlProfileCodec },
536
+ hookArgs: ['--codex-profile', profile],
537
+ collectChecks: (env) => [
538
+ ...collectChecks(env),
539
+ { level: 'info', message: profileProcessNote(profile) },
540
+ ...profileVersionIssues([profile]),
541
+ ],
542
+ kindOnly: {
543
+ codexProfile: profile,
544
+ replaces: [codexCliFor({ kind: 'home', home })],
545
+ setupArgs: ['--profile', profile],
546
+ printPostSetupInstructions: () => profilePostSetup(profile),
547
+ },
548
+ };
549
+ }
550
+ default: {
551
+ const unreachable = target;
552
+ throw new Error(`unknown Codex target ${JSON.stringify(unreachable)}`);
553
+ }
554
+ }
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
+ };
602
+ export const codexCliFor = (target) => {
603
+ const { home } = target;
604
+ const parts = targetParts(target);
605
+ return {
606
+ name: 'codex',
607
+ displayName: 'Codex CLI',
608
+ runInstruction: parts.runInstruction,
609
+ detect: () => hasPath(home) || hasBinary('codex'),
610
+ instructionSurface: {
611
+ kind: 'instructions-file',
612
+ global: join(home, 'AGENTS.md'),
613
+ local: 'AGENTS.md',
614
+ label: 'AGENTS.md',
238
615
  },
239
- runtimeTool: 'codex',
240
- },
616
+ paths: {
617
+ local: join('.codex', 'config.toml'),
618
+ global: parts.own,
619
+ },
620
+ trustFiles: parts.trustFiles,
621
+ injectsIdentity: true,
622
+ codec: parts.codec,
623
+ managedEnvKeys: MANAGED_ENV_KEYS,
624
+ retiredEnvKeys: RETIRED_ENV_KEYS,
625
+ alwaysOnOptIns: { toolDetails: true, toolContent: true },
626
+ hierarchy: parts.hierarchy,
627
+ buildEnv,
628
+ parseEnv,
629
+ collectChecks: parts.collectChecks,
630
+ collectFileChecks,
631
+ normalizeForGenericChecks,
632
+ holdsOwnSetup: holdsMainwaveExporter,
633
+ removal: { group: 'codex', plan: () => planCodexRemoval(target) },
634
+ ...parts.kindOnly,
635
+ markers: {
636
+ disclosure: 'Sends Linear/Jira issue ids and GitHub PR / GitLab MR urls to the collector — never ticket bodies or diff content. ' +
637
+ 'It also sends, for each Codex turn, the session, turn and subagent ids, the working directory, the name of a tool ' +
638
+ 'call waiting for your approval, and when the turn, the wait and the subagent started and ended — ids and ' +
639
+ 'timestamps, never prompt or response text.',
640
+ hooksFile: parts.hooksFile,
641
+ runtimeTool: 'codex',
642
+ ...(parts.hookArgs === undefined ? {} : { hookArgs: parts.hookArgs }),
643
+ },
644
+ };
241
645
  };
@@ -1,6 +1,6 @@
1
1
  import { claudeCode } from './claude-code.js';
2
2
  import { claudeDesktop } from './claude-desktop.js';
3
- import { codexCli } from './codex-cli.js';
3
+ import { CODEX_ADAPTER_NAME, codexCliFor, homeTarget } from './codex-cli.js';
4
4
  import { copilotChat } from './copilot-chat.js';
5
5
  import { copilotCli } from './copilot-cli.js';
6
6
  import { cursor } from './cursor.js';
@@ -9,7 +9,9 @@ import { kiroCli, kiroIde } from './kiro.js';
9
9
  export const adapters = {
10
10
  [claudeCode.name]: claudeCode,
11
11
  [claudeDesktop.name]: claudeDesktop,
12
- [codexCli.name]: codexCli,
12
+ get [CODEX_ADAPTER_NAME]() {
13
+ return codexCliFor(homeTarget());
14
+ },
13
15
  [copilotChat.name]: copilotChat,
14
16
  [copilotCli.name]: copilotCli,
15
17
  [cursor.name]: cursor,
package/dist/commands.js CHANGED
@@ -76,11 +76,19 @@ export const COMMANDS = [
76
76
  ' the hooks still strip credentials by default',
77
77
  ' --no-redact-secrets stop stripping credentials (API keys, tokens, private keys) from',
78
78
  ' the spans the hooks send; --redact-secrets restores the default',
79
+ ' --profile <name> Codex only: send telemetry and run the Mainwave hooks only in',
80
+ ' sessions started with `codex --profile <name>`, from',
81
+ ' <codex home>/<name>.config.toml. Moves an all-sessions Codex',
82
+ ' setup there. Other tools named with it are set up as usual;',
83
+ ' without codex among the tools it is an error. With --remove',
84
+ ' it picks the profile setup to remove',
79
85
  ' --yes --json --no-verify --verify-timeout <seconds>',
80
86
  ' --skills / --no-skills install the agent skills payload (default: ask, or on in scripts)',
81
87
  ' --skills-only install only the skills, touching no telemetry config',
82
88
  " --remove take this CLI's config for the named tools back off this",
83
- ' 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)',
84
92
  ],
85
93
  flags: [
86
94
  f('--api-key'),
@@ -106,6 +114,7 @@ export const COMMANDS = [
106
114
  f('--no-skills'),
107
115
  f('--skills-only'),
108
116
  f('--remove'),
117
+ f('--profile'),
109
118
  removed('--scope'),
110
119
  ],
111
120
  },
@@ -163,7 +172,7 @@ export const COMMANDS = [
163
172
  },
164
173
  {
165
174
  name: 'install-hooks',
166
- usage: '[--quiet] [--host codex] [--redaction-packs <list>]',
175
+ usage: '[--quiet] [--host codex [--codex-profile <name>]] [--redaction-packs <list>]',
167
176
  summary: [
168
177
  'install or refresh the Mainwave hook entry and the',
169
178
  "latest release's hook scripts, with no prompts or",
@@ -171,11 +180,14 @@ export const COMMANDS = [
171
180
  "settings, and by setup's own session-start hook).",
172
181
  "--host codex: refresh Codex's hooks file instead of Claude",
173
182
  "Code's settings (run by the session-start hook in it)",
183
+ '--codex-profile <name>: refresh the hooks in that Codex',
184
+ "profile's file instead of hooks.json (run by the",
185
+ 'session-start hook in a profile file setup wrote)',
174
186
  "--redaction-packs: the packs an org's managed settings",
175
187
  'apply to every Mainwave hook; recorded only from them',
176
188
  ],
177
189
  adapters: 'none',
178
- flags: [f('--quiet'), f('--host'), f('--redaction-packs')],
190
+ flags: [f('--quiet'), f('--host'), f('--codex-profile'), f('--redaction-packs')],
179
191
  },
180
192
  ];
181
193
  export const isCommand = (name) => COMMANDS.some((c) => c.name === name);