@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.
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
@@ -480,6 +482,87 @@ approved, so it asks again after any change to a Mainwave hook, such as a setup
480
482
  route or a release that changes a command. Setup says all of this when it finishes, and `doctor`
481
483
  lists the Mainwave hooks Codex is skipping, read from the trust records in Codex's `config.toml`.
482
484
 
485
+ **Sending telemetry from only some Codex sessions.** Plain `setup codex` makes every session in a
486
+ Codex home report. To report from some sessions only, pick one of two routes by what your Codex
487
+ sessions share:
488
+
489
+ - A separate Codex home, when the Codex login differs between kinds of work. Run
490
+ `CODEX_HOME=<dir> mainwave-cli setup codex`, then run Codex with that `CODEX_HOME`. The new home
491
+ needs its own login, MCP servers, project trust and history.
492
+ - A Codex profile, when one Codex login is shared. Run `mainwave-cli setup codex --profile <name>`,
493
+ then start Codex with `codex --profile <name>`. Login, MCP servers, project trust and history stay
494
+ shared. Profiles need Codex 0.169 or later, and setup and `doctor` warn on an older Codex.
495
+
496
+ For a profile, setup writes the telemetry settings and the Mainwave hooks into
497
+ `<codex home>/<name>.config.toml`, and writes none to `config.toml` or `hooks.json`. A session
498
+ started without `--profile <name>` sends nothing to Mainwave and runs no Mainwave hook. If the Codex
499
+ home already has the all-sessions setup, the same run removes it from `config.toml` and
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.
507
+
508
+ A profile name is 1 to 64 letters, digits, `_` or `-`, and does not start with `-`. `default` is
509
+ reserved by Codex. Setup refuses a name whose file already has an `[otel]` table that isn't
510
+ Mainwave's, so pick another name or remove that table. It also refuses, and leaves unchanged, a
511
+ profile file with `"""` or `'''` on any line, a comment included, since setup does not edit a file
512
+ with multi-line strings, and one with hooks written as keys (`[hooks]` with `Stop = [...]`) rather
513
+ than `[[hooks.<Event>]]` tables. `doctor` reports such a file as unreadable.
514
+
515
+ Setup writes no hook approvals. Start `codex --profile <name>` once and choose "Trust all" at the
516
+ "Hooks need review" prompt. Until then `codex exec --profile <name>` skips the Mainwave hooks.
517
+
518
+ Codex applies a profile to one process, so `codex resume` without `--profile <name>` sends nothing.
519
+ Add a separate alias, for example `alias codex-mw='codex --profile mainwave'`, and never one named
520
+ `codex`. `--profile` goes before the subcommand: `codex --profile mainwave exec resume <id>` resumes
521
+ with the profile, and `codex exec resume --profile mainwave` exits with an error.
522
+
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.
546
+
547
+ Plain `setup codex` in a home that has a profile setup asks whether to update the profile or to
548
+ switch to all sessions, which removes Mainwave from the profile file. Without a terminal it exits
549
+ with code 1 and names the `--profile` command, and `--yes` doesn't choose.
550
+
551
+ `doctor codex` checks the all-sessions setup and each profile setup it finds, each in a report of
552
+ its own. A profile's report is titled `Codex CLI, profile <name>`, lists the profile file as
553
+ `Profile <name>` and its hooks as `Profile <name> hooks file`, and checks the endpoint, the
554
+ authorization header, the metrics exporter and the hook approvals recorded in the profile file. It
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>"`.
565
+
483
566
  On Windows, the Claude Code hooks need Git for Windows. Claude Code runs hook commands through Git
484
567
  Bash, and through PowerShell when it finds none, where the entry's shell command can't run. Without
485
568
  Git Bash, setup installs no Claude Code hooks and says why, and `doctor` reports it as an error;
@@ -515,6 +598,11 @@ every settings file that installs the hooks and warns when two of them would fir
515
598
  ticket or PR. The org-wide setup follows how Claude Code 2.1.282 and later apply managed settings;
516
599
  `doctor` warns on an older install.
517
600
 
601
+ Mainwave's Org-wide setup page lists the developers whose Claude Code telemetry arrives while their
602
+ hooks send nothing, with the day their hooks stopped, or "Never". It lists apart the developers it
603
+ can't check: a session on an API key or a cloud provider sends no plan snapshot, so only their
604
+ commits, PRs and tickets send hook telemetry. Run `doctor` on such a developer's machine to check.
605
+
518
606
  Two kinds of session don't get the admin console's markers or plan snapshot:
519
607
 
520
608
  - A session that skips server-managed settings: one started with a `CLAUDE_CODE_USE_*` provider
@@ -640,7 +728,8 @@ lived there — and Cursor and VS Code Copilot Chat stop sending until then.
640
728
  To stop entirely, also remove the Mainwave entries from your tools' settings — for Claude Code,
641
729
  `mainwave-cli setup claude-code --no-markers` removes its hooks, or delete the hook groups that
642
730
  name `mainwave-hook.sh`, `install-hooks` or `--managed-by @mainwave/cli` from
643
- `~/.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
644
733
  through your organization's managed settings stay until your Claude admin removes them. Hooks
645
734
  now log under `~/.mainwave/logs/`; releases before that logged to `~/.mainwave-*.log` files in your
646
735
  home directory, which are left for you to delete.
@@ -1,9 +1,9 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { accessSync, constants as fsConstants, promises as fs } from 'node:fs';
2
+ import { promises as fs } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
- import { delimiter, isAbsolute, join, resolve } from 'node:path';
4
+ import { join, resolve } from 'node:path';
5
5
  import { jsonEnvCodec } from '../core/codecs/json-env.js';
6
- import { hasBinary, hasPath } from '../core/detect.js';
6
+ import { hasBinary, hasPath, trustedBinary, trustedPath } from '../core/detect.js';
7
7
  import { tildify } from '../core/post-setup.js';
8
8
  import { isErrnoCode } from '../core/settings.js';
9
9
  const MANAGED_ENV_KEYS = [
@@ -238,24 +238,7 @@ const isHonoredOffValue = (key, value) => {
238
238
  return false;
239
239
  };
240
240
  let installedVersionCache;
241
- const trustedPath = (env = process.env) => (env.PATH ?? '')
242
- .split(delimiter)
243
- .filter((dir) => dir && isAbsolute(dir) && !/[\\/]node_modules[\\/]\.bin[\\/]?$/.test(dir))
244
- .join(delimiter);
245
- export const trustedClaudeBinary = (env = process.env) => {
246
- for (const dir of trustedPath(env).split(delimiter)) {
247
- if (!dir)
248
- continue;
249
- const candidate = join(dir, 'claude');
250
- try {
251
- accessSync(candidate, fsConstants.X_OK);
252
- return candidate;
253
- }
254
- catch {
255
- }
256
- }
257
- return undefined;
258
- };
241
+ export const trustedClaudeBinary = (env = process.env) => trustedBinary('claude', env);
259
242
  const installedClaudeCodeVersion = () => {
260
243
  if (process.platform === 'win32')
261
244
  return undefined;