@mainwave/cli 0.13.0 → 0.13.1

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
@@ -444,7 +444,15 @@ an earlier version copied into `~/.mainwave/hooks/` once nothing runs them. To d
444
444
  the plan snapshot included, re-run setup with `--no-markers` — the entries are removed cleanly. `doctor` checks that the entry is installed, that it names an installed release with every
445
445
  script, and that every Mainwave hook group is in the background and narrowed by its matcher.
446
446
 
447
- Codex gets the same session-start hook in `~/.codex/hooks.json`, with `--host codex` added to the
447
+ Codex keeps its config in `$CODEX_HOME` when that is set, and in `~/.codex` otherwise. Setup,
448
+ `doctor` and the hooks follow the same rule, so run setup with the `CODEX_HOME` you run Codex
449
+ with, for example `CODEX_HOME=~/.codex-work npx @mainwave/cli setup codex`. Each Codex home gets
450
+ its own config and hooks. Setup says where it writes when `CODEX_HOME` is set, and warns when that
451
+ directory belongs to a launcher: Orca sets `CODEX_HOME` to its own copy of `~/.codex` in every
452
+ terminal it opens, so run setup from there with `env -u CODEX_HOME` to set up the Codex you start
453
+ yourself.
454
+
455
+ Codex gets the same session-start hook in its `hooks.json`, with `--host codex` added to the
448
456
  command (on Windows, where Codex runs hooks through `cmd.exe`, an equivalent `cmd` command). It
449
457
  installs the latest release's scripts and adds any hook that setup told you about and the file
450
458
  lacks. It never edits or removes a hook already in the file, because Codex trusts each hook by a
@@ -470,7 +478,7 @@ included. Until then no Mainwave hook runs in Codex, and `codex exec` skips them
470
478
  with `--dangerously-bypass-hook-trust`. Codex checks each hook's definition against what you
471
479
  approved, so it asks again after any change to a Mainwave hook, such as a setup run that adds a
472
480
  route or a release that changes a command. Setup says all of this when it finishes, and `doctor`
473
- lists the Mainwave hooks Codex is skipping, read from the trust records in `~/.codex/config.toml`.
481
+ lists the Mainwave hooks Codex is skipping, read from the trust records in Codex's `config.toml`.
474
482
 
475
483
  On Windows, the Claude Code hooks need Git for Windows. Claude Code runs hook commands through Git
476
484
  Bash, and through PowerShell when it finds none, where the entry's shell command can't run. Without
@@ -1,9 +1,50 @@
1
+ import { realpathSync } from 'node:fs';
1
2
  import { homedir } from 'node:os';
2
- import { join } from 'node:path';
3
+ import { join, resolve } from 'node:path';
3
4
  import { jsonEnvCodec } from '../core/codecs/json-env.js';
4
5
  import { hasBinary, hasPath } from '../core/detect.js';
5
6
  import { tomlOtelCodec } from '../core/codecs/toml-otel.js';
6
7
  import { UCID_SOURCE_EXPLICIT } from '../core/headers.js';
8
+ export const codexHome = (env = process.env) => {
9
+ const dir = env.CODEX_HOME;
10
+ if (dir === undefined || dir === '')
11
+ return join(homedir(), '.codex');
12
+ try {
13
+ return realpathSync(resolve(dir));
14
+ }
15
+ catch {
16
+ return resolve(dir);
17
+ }
18
+ };
19
+ const LAUNCHER_HOME_MARKERS = [
20
+ { file: '.orca-managed-home', launcher: 'Orca' },
21
+ ];
22
+ export const codexHomeIssues = (env = process.env) => {
23
+ if (env.CODEX_HOME === undefined || env.CODEX_HOME === '')
24
+ return [];
25
+ const dir = codexHome(env);
26
+ const managed = LAUNCHER_HOME_MARKERS.find((m) => hasPath(join(dir, m.file)));
27
+ if (managed === undefined) {
28
+ return [
29
+ hasPath(dir)
30
+ ? { level: 'info', message: `CODEX_HOME is set, so Codex config and hooks live in ${dir}.` }
31
+ : {
32
+ level: 'warn',
33
+ message: `CODEX_HOME is set to ${dir}, which doesn't exist. Codex refuses to start until it does; ` +
34
+ 'setup creates it. Check the path if you expected an existing Codex home.',
35
+ },
36
+ ];
37
+ }
38
+ return [
39
+ {
40
+ level: 'warn',
41
+ message: `CODEX_HOME is set to ${dir}, a Codex home that ${managed.launcher} manages (it holds ${managed.file}). ` +
42
+ `Codex started outside ${managed.launcher} reads ~/.codex instead, and ${managed.launcher} may overwrite them when it syncs that copy. ` +
43
+ 'To set up the Codex you start yourself, run setup again with CODEX_HOME unset (`env -u CODEX_HOME …`) ' +
44
+ 'or set to the home you start Codex with.',
45
+ },
46
+ ];
47
+ };
7
48
  const SOURCE_VALUE = 'coding_agent.codex_cli';
8
49
  const SIGNAL_BLOCKS = ['exporter', 'trace_exporter', 'metrics_exporter'];
9
50
  const SIGNAL_PATH = {
@@ -130,7 +171,7 @@ const collectFileChecks = (scans) => {
130
171
  return issues;
131
172
  };
132
173
  const collectChecks = (env) => {
133
- const issues = [];
174
+ const issues = [...codexHomeIssues()];
134
175
  if (!env[endpointKey('metrics_exporter')]) {
135
176
  issues.push({
136
177
  level: 'warn',
@@ -155,7 +196,7 @@ const HIERARCHY = [
155
196
  {
156
197
  id: 'user',
157
198
  label: 'User (global)',
158
- path: join(homedir(), '.codex', 'config.toml'),
199
+ path: join(codexHome(), 'config.toml'),
159
200
  kind: 'file',
160
201
  },
161
202
  ];
@@ -163,16 +204,16 @@ export const codexCli = {
163
204
  name: 'codex',
164
205
  displayName: 'Codex CLI',
165
206
  runInstruction: 'codex',
166
- detect: () => hasPath(join(homedir(), '.codex')) || hasBinary('codex'),
207
+ detect: () => hasPath(codexHome()) || hasBinary('codex'),
167
208
  instructionSurface: {
168
209
  kind: 'instructions-file',
169
- global: join(homedir(), '.codex', 'AGENTS.md'),
210
+ global: join(codexHome(), 'AGENTS.md'),
170
211
  local: 'AGENTS.md',
171
212
  label: 'AGENTS.md',
172
213
  },
173
214
  paths: {
174
215
  local: join('.codex', 'config.toml'),
175
- global: join(homedir(), '.codex', 'config.toml'),
216
+ global: join(codexHome(), 'config.toml'),
176
217
  },
177
218
  injectsIdentity: true,
178
219
  codec: tomlOtelCodec,
@@ -191,7 +232,7 @@ export const codexCli = {
191
232
  'call waiting for your approval, and when the turn, the wait and the subagent started and ended — ids and ' +
192
233
  'timestamps, never prompt or response text.',
193
234
  hooksFile: {
194
- path: join(homedir(), '.codex', 'hooks.json'),
235
+ path: join(codexHome(), 'hooks.json'),
195
236
  localPath: join('.codex', 'hooks.json'),
196
237
  codec: jsonEnvCodec,
197
238
  },
@@ -1,6 +1,6 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { platform as osPlatform } from 'node:os';
3
- import { dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import { dirname, isAbsolute } from 'node:path';
4
4
  import { envFileCodec } from './codecs/env-file.js';
5
5
  import { countTrust, readCodexTrust } from './codex-trust.js';
6
6
  import { activeHierarchy, computeEffective, effectiveFrom, flattenEffective, nativeIdentityReason, } from './effective-settings.js';
@@ -558,19 +558,6 @@ const codexTrustIssues = (adapter) => {
558
558
  const hooksFile = adapter.markers?.hooksFile;
559
559
  if (hooksFile === undefined || adapter.markers?.runtimeTool !== 'codex')
560
560
  return [];
561
- const codexHome = process.env.CODEX_HOME;
562
- if (codexHome !== undefined &&
563
- codexHome !== '' &&
564
- resolve(codexHome) !== dirname(resolve(hooksFile.path))) {
565
- return [
566
- {
567
- level: 'warn',
568
- message: `CODEX_HOME is set to ${codexHome}, so Codex reads its hooks from ${join(codexHome, 'hooks.json')}, ` +
569
- `not ${hooksFile.path}, where setup wrote the Mainwave hooks. None of them run, and trusting them in /hooks ` +
570
- "won't change that: setup doesn't follow CODEX_HOME yet.",
571
- },
572
- ];
573
- }
574
561
  const reading = readCodexTrust(hooksFile.path, adapter.paths.global);
575
562
  if (reading.state === 'no-hooks')
576
563
  return [];
@@ -19,6 +19,7 @@ import { VERSION } from './version.js';
19
19
  import { emitJson, say, setJsonMode } from './ui.js';
20
20
  import { validateCollector } from './validate.js';
21
21
  import { runVerify } from './verify.js';
22
+ import { codexCli, codexHomeIssues } from '../adapters/codex-cli.js';
22
23
  const validateWithRetry = async (initialUrl, initialKey, interactive) => {
23
24
  let url = initialUrl;
24
25
  let key = initialKey;
@@ -255,6 +256,11 @@ export const runSetup = async (adapters, rawOptions = {}) => {
255
256
  let credentials = await readCredentials();
256
257
  let session = activeSession(credentials, endpoints.apiUrl);
257
258
  say(color.bold(`mainwave-cli — setup ${adapters.map((a) => a.displayName).join(', ')}`));
259
+ if (adapters.some((a) => a.name === codexCli.name)) {
260
+ for (const issue of codexHomeIssues()) {
261
+ say(issue.level === 'warn' ? color.yellow(`⚠ ${issue.message}`) : color.dim(issue.message));
262
+ }
263
+ }
258
264
  const options = rawOptions.invite
259
265
  ? await redeemInviteToOverrides(rawOptions.invite, endpoints.apiUrl, rawOptions)
260
266
  : rawOptions;
@@ -17,6 +17,7 @@ import {
17
17
  mkdirSync,
18
18
  readFileSync,
19
19
  readdirSync,
20
+ realpathSync,
20
21
  renameSync,
21
22
  statSync,
22
23
  writeFileSync,
@@ -803,6 +804,22 @@ const lastTomlString = (text, key) => {
803
804
  const stripSignalSuffix = (endpoint) =>
804
805
  (endpoint ?? '').replace(/\/v1\/(logs|traces|metrics)\/?$/, '')
805
806
 
807
+ /**
808
+ * Codex's user-level config directory: `$CODEX_HOME` when set and non-empty,
809
+ * `~/.codex` otherwise, as Codex resolves it. A hook runs with the environment
810
+ * of the Codex process that started it, so it reads the config that Codex
811
+ * read. The CLI adapter resolves it by the same rule.
812
+ */
813
+ export const codexHomeDir = (env = process.env) => {
814
+ const dir = env.CODEX_HOME
815
+ if (dir === undefined || dir === '') return join(homedir(), '.codex')
816
+ try {
817
+ return realpathSync(resolve(dir))
818
+ } catch {
819
+ return resolve(dir)
820
+ }
821
+ }
822
+
806
823
  /**
807
824
  * OTLP config from Codex's global `config.toml`. Codex carries
808
825
  * tenancy on HTTP headers rather than OTEL_RESOURCE_ATTRIBUTES, so the UCID is the
@@ -815,11 +832,11 @@ const stripSignalSuffix = (endpoint) =>
815
832
  * it a Codex marker would carry no identity at all. Missing keys → undefined
816
833
  * (the hook skips, fail-open), never a broken emit.
817
834
  */
818
- export const codexOtelConfig = (readFile = readFileSafe) => {
835
+ export const codexOtelConfig = (readFile = readFileSafe, env = process.env) => {
819
836
  // Global config only: Codex 0.130+ drops `otel` keys from a project's
820
837
  // `.codex/config.toml` itself, so a checked-out repository can't redirect
821
838
  // its telemetry, and the markers follow the same rule.
822
- const text = readFile(join(homedir(), '.codex', 'config.toml'))
839
+ const text = readFile(join(codexHomeDir(env), 'config.toml'))
823
840
  const endpoint = stripSignalSuffix(lastTomlString(text, 'endpoint'))
824
841
  const bearer = lastTomlString(text, 'Authorization')
825
842
  const ucid = lastTomlString(text, 'X-Mainwave-UCID')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mainwave/cli",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Setup wizard for connecting third-party coding tools to Mainwave AI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,7 +25,10 @@
25
25
  "pnpm": {
26
26
  "onlyBuiltDependencies": [
27
27
  "lefthook"
28
- ]
28
+ ],
29
+ "overrides": {
30
+ "js-yaml@>=4.0.0 <4.3.2": "^4.3.2"
31
+ }
29
32
  },
30
33
  "scripts": {
31
34
  "build": "tsc -p tsconfig.build.json",