@mainwave/cli 0.13.0 → 0.14.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 +70 -2
- package/dist/adapters/claude-code.js +4 -21
- package/dist/adapters/codex-cli.js +375 -53
- package/dist/adapters/index.js +4 -2
- package/dist/commands.js +11 -2
- package/dist/core/apply.js +82 -15
- package/dist/core/codecs/toml-profile.js +245 -0
- package/dist/core/codex-trust.js +30 -6
- package/dist/core/detect.js +20 -1
- package/dist/core/doctor.js +69 -25
- package/dist/core/entry-script.js +24 -10
- package/dist/core/install-hooks.js +1 -1
- package/dist/core/markers.js +25 -20
- package/dist/core/pinned-use-case.js +2 -2
- package/dist/core/prompts.js +15 -0
- package/dist/core/status.js +15 -7
- package/dist/core/wizard.js +63 -2
- package/dist/main.js +34 -2
- package/hooks/codex-turns.mjs +13 -3
- package/hooks/git-commit-marker.mjs +8 -1
- package/hooks/github-pr-marker.mjs +8 -1
- package/hooks/glab-mr-marker.mjs +8 -1
- package/hooks/jira-ticket-marker.mjs +8 -1
- package/hooks/linear-ticket-marker.mjs +8 -1
- package/hooks/marker-core.mjs +122 -23
- package/hooks/plan-snapshot.mjs +1 -0
- package/package.json +11 -8
|
@@ -207,7 +207,14 @@ export const handle = async (payload, { argv = process.argv, emit = emitMarker }
|
|
|
207
207
|
const tool = markerTool(argv)
|
|
208
208
|
const managedDir = markerManagedDir(argv)
|
|
209
209
|
const env = markerSessionEnv(tool, payload)
|
|
210
|
-
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
210
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
211
|
+
projectDir,
|
|
212
|
+
env,
|
|
213
|
+
tool,
|
|
214
|
+
managedDir,
|
|
215
|
+
{},
|
|
216
|
+
argv,
|
|
217
|
+
)
|
|
211
218
|
log(
|
|
212
219
|
`pr=${number} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
213
220
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
package/hooks/glab-mr-marker.mjs
CHANGED
|
@@ -711,7 +711,14 @@ export const handle = async (payload, { argv = process.argv, emit = emitMarker }
|
|
|
711
711
|
const tool = markerTool(argv)
|
|
712
712
|
const managedDir = markerManagedDir(argv)
|
|
713
713
|
const env = markerSessionEnv(tool, payload)
|
|
714
|
-
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
714
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
715
|
+
projectDir,
|
|
716
|
+
env,
|
|
717
|
+
tool,
|
|
718
|
+
managedDir,
|
|
719
|
+
{},
|
|
720
|
+
argv,
|
|
721
|
+
)
|
|
715
722
|
log(
|
|
716
723
|
`mr=${mr.iid} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
717
724
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
|
@@ -218,7 +218,14 @@ export const handle = async (payload, { argv = process.argv, emit = emitMarker }
|
|
|
218
218
|
const tool = markerTool(argv)
|
|
219
219
|
const managedDir = markerManagedDir(argv)
|
|
220
220
|
const env = markerSessionEnv(tool, payload)
|
|
221
|
-
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
221
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
222
|
+
projectDir,
|
|
223
|
+
env,
|
|
224
|
+
tool,
|
|
225
|
+
managedDir,
|
|
226
|
+
{},
|
|
227
|
+
argv,
|
|
228
|
+
)
|
|
222
229
|
log(
|
|
223
230
|
`issue=${issueKey} op=${op} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
224
231
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
|
@@ -264,7 +264,14 @@ export const handle = async (payload, { argv = process.argv, emit = emitMarker }
|
|
|
264
264
|
const tool = markerTool(argv)
|
|
265
265
|
const managedDir = markerManagedDir(argv)
|
|
266
266
|
const env = markerSessionEnv(tool, payload)
|
|
267
|
-
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
267
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(
|
|
268
|
+
projectDir,
|
|
269
|
+
env,
|
|
270
|
+
tool,
|
|
271
|
+
managedDir,
|
|
272
|
+
{},
|
|
273
|
+
argv,
|
|
274
|
+
)
|
|
268
275
|
log(
|
|
269
276
|
`issue=${issueKey} op=${op} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
270
277
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
package/hooks/marker-core.mjs
CHANGED
|
@@ -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,
|
|
@@ -785,18 +786,61 @@ export const markerOauthAccountPath = (tool, opts = {}) => {
|
|
|
785
786
|
return claudeAccountPath(opts.home, configDir)
|
|
786
787
|
}
|
|
787
788
|
|
|
788
|
-
/**
|
|
789
|
-
*
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
789
|
+
/** A TOML key with its quotes and surrounding whitespace removed, so
|
|
790
|
+
* `otel.exporter."otlp-http"` and `otel.exporter.otlp-http` compare equal. */
|
|
791
|
+
const plainTomlKey = (key) =>
|
|
792
|
+
key
|
|
793
|
+
.replace(/"/g, '')
|
|
794
|
+
.replace(/\s*\.\s*/g, '.')
|
|
795
|
+
.trim()
|
|
796
|
+
|
|
797
|
+
const TOML_HEADER_START_RE = /^\s*\[/
|
|
798
|
+
const TOML_TABLE_RE = /^\s*\[([^[\]]+)\]\s*(?:#.*)?$/
|
|
799
|
+
const TOML_STRING_RE = /^\s*("[^"]+"|[A-Za-z0-9_-]+)\s*=\s*"([^"]*)"/
|
|
800
|
+
const TOML_INLINE_RE = /^\s*headers\s*=\s*\{(.*)\}\s*(?:#.*)?$/
|
|
801
|
+
const TOML_PAIR_RE = /("[^"]+"|[A-Za-z0-9_-]+)\s*=\s*"([^"]*)"/g
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The `[otel.*]` tables of a Codex `config.toml`, in file order, each as
|
|
805
|
+
* `{ endpoint, headers }`: its `endpoint = "…"` string and its one-line
|
|
806
|
+
* inline `headers = { … }` table, the shape setup and the manual-setup page
|
|
807
|
+
* write. Only the string values the markers read are kept; anything else in
|
|
808
|
+
* the file is skipped, so an unexpected shape yields no table, never a
|
|
809
|
+
* guess.
|
|
810
|
+
*/
|
|
811
|
+
const codexOtelTables = (text) => {
|
|
812
|
+
const tables = []
|
|
813
|
+
let current
|
|
814
|
+
for (const line of (text ?? '').split(/\r?\n/)) {
|
|
815
|
+
if (TOML_HEADER_START_RE.test(line)) {
|
|
816
|
+
// Any header, `[t]` or `[[t]]`, ends the table before it. Only a
|
|
817
|
+
// single-bracket `otel.*` header opens a new one.
|
|
818
|
+
const header = TOML_TABLE_RE.exec(line)
|
|
819
|
+
const name = header && plainTomlKey(header[1])
|
|
820
|
+
current = name?.startsWith('otel.') ? { endpoint: undefined, headers: {} } : undefined
|
|
821
|
+
if (current) tables.push(current)
|
|
822
|
+
continue
|
|
823
|
+
}
|
|
824
|
+
if (!current) continue
|
|
825
|
+
const inline = TOML_INLINE_RE.exec(line)
|
|
826
|
+
if (inline) {
|
|
827
|
+
for (const [, k, v] of inline[1].matchAll(TOML_PAIR_RE)) current.headers[plainTomlKey(k)] = v
|
|
828
|
+
continue
|
|
829
|
+
}
|
|
830
|
+
const pair = TOML_STRING_RE.exec(line)
|
|
831
|
+
if (pair && plainTomlKey(pair[1]) === 'endpoint') current.endpoint = pair[2]
|
|
832
|
+
}
|
|
833
|
+
return tables
|
|
798
834
|
}
|
|
799
835
|
|
|
836
|
+
/** Whether an exporter table is one Mainwave setup wrote: it names an
|
|
837
|
+
* endpoint and an `Authorization` header, and its headers carry the
|
|
838
|
+
* `X-Mainwave-Source` tag setup (and the manual-setup snippet) puts in every
|
|
839
|
+
* Codex exporter table. The collector host can't decide it: an organization
|
|
840
|
+
* may run its collector on its own domain. */
|
|
841
|
+
const isMainwaveExporter = (table) =>
|
|
842
|
+
Boolean(table.endpoint && table.headers.Authorization && table.headers['X-Mainwave-Source'])
|
|
843
|
+
|
|
800
844
|
/** Strip a per-signal OTLP suffix (`/v1/logs` …) back to the base endpoint the
|
|
801
845
|
* emit re-adds `/v1/traces` to. Codex writes per-signal endpoints; Claude Code's
|
|
802
846
|
* OTEL_EXPORTER_OTLP_ENDPOINT is already the base, so this is Codex-only. */
|
|
@@ -804,7 +848,46 @@ const stripSignalSuffix = (endpoint) =>
|
|
|
804
848
|
(endpoint ?? '').replace(/\/v1\/(logs|traces|metrics)\/?$/, '')
|
|
805
849
|
|
|
806
850
|
/**
|
|
807
|
-
*
|
|
851
|
+
* Codex's user-level config directory: `$CODEX_HOME` when set and non-empty,
|
|
852
|
+
* `~/.codex` otherwise, as Codex resolves it. A hook runs with the environment
|
|
853
|
+
* of the Codex process that started it, so it reads the config that Codex
|
|
854
|
+
* read. The CLI adapter resolves it by the same rule.
|
|
855
|
+
*/
|
|
856
|
+
export const codexHomeDir = (env = process.env) => {
|
|
857
|
+
const dir = env.CODEX_HOME
|
|
858
|
+
if (dir === undefined || dir === '') return join(homedir(), '.codex')
|
|
859
|
+
try {
|
|
860
|
+
return realpathSync(resolve(dir))
|
|
861
|
+
} catch {
|
|
862
|
+
return resolve(dir)
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/** A Codex profile name a hook command may pass: the characters setup allows. */
|
|
867
|
+
const CODEX_PROFILE_RE = /^[A-Za-z0-9_-]{1,64}$/
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* The one Codex config file a hook reads its collector from. Without
|
|
871
|
+
* `--codex-profile` it is `config.toml` in the Codex home. With
|
|
872
|
+
* `--codex-profile <name>` it is `<name>.config.toml` there, the file Codex
|
|
873
|
+
* loads only under `--profile <name>`: nothing in the hook's environment or
|
|
874
|
+
* input names the active profile, so the hook command carries it. A missing or
|
|
875
|
+
* unsafe name gives `undefined` (send nothing), never a path built from it and
|
|
876
|
+
* never a fall back to `config.toml`, whose collector belongs to sessions run
|
|
877
|
+
* without that profile.
|
|
878
|
+
*/
|
|
879
|
+
export const codexConfigFile = (argv, env = process.env) => {
|
|
880
|
+
const i = (argv ?? []).indexOf('--codex-profile')
|
|
881
|
+
if (i === -1) return join(codexHomeDir(env), 'config.toml')
|
|
882
|
+
const name = argv[i + 1]
|
|
883
|
+
return typeof name === 'string' && CODEX_PROFILE_RE.test(name)
|
|
884
|
+
? join(codexHomeDir(env), `${name}.config.toml`)
|
|
885
|
+
: undefined
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* OTLP config from the hook's Codex config file (§ `codexConfigFile`): the
|
|
890
|
+
* global `config.toml`, or the profile file the hook command names. Codex carries
|
|
808
891
|
* tenancy on HTTP headers rather than OTEL_RESOURCE_ATTRIBUTES, so the UCID is the
|
|
809
892
|
* `X-Mainwave-UCID` header value and the bearer is the `Authorization` header — the
|
|
810
893
|
* marker re-emits the UCID as a `mainwave.ucid` resource attr, which the collector
|
|
@@ -812,18 +895,25 @@ const stripSignalSuffix = (endpoint) =>
|
|
|
812
895
|
* developer configured one explicitly; by default the collector derives it from
|
|
813
896
|
* the developer's email, so the `X-Mainwave-User-Email` header is re-emitted as
|
|
814
897
|
* the `mainwave.user_email` resource attr it promotes that header to — without
|
|
815
|
-
* it a Codex marker would carry no identity at all.
|
|
816
|
-
*
|
|
898
|
+
* it a Codex marker would carry no identity at all.
|
|
899
|
+
*
|
|
900
|
+
* Every value comes from one exporter table, the last that is Mainwave's
|
|
901
|
+
* (§ `isMainwaveExporter`). The `[otel]` block may belong to another
|
|
902
|
+
* vendor, and its endpoint and bearer must never receive a Mainwave span,
|
|
903
|
+
* so with no Mainwave table every field is undefined and the hook skips
|
|
904
|
+
* (fail-open), never a broken emit.
|
|
817
905
|
*/
|
|
818
|
-
export const codexOtelConfig = (readFile = readFileSafe) => {
|
|
819
|
-
//
|
|
906
|
+
export const codexOtelConfig = (readFile = readFileSafe, env = process.env, argv = []) => {
|
|
907
|
+
// User-level config only: Codex 0.130+ drops `otel` keys from a project's
|
|
820
908
|
// `.codex/config.toml` itself, so a checked-out repository can't redirect
|
|
821
909
|
// its telemetry, and the markers follow the same rule.
|
|
822
|
-
const
|
|
823
|
-
const
|
|
824
|
-
const
|
|
825
|
-
const
|
|
826
|
-
const
|
|
910
|
+
const file = codexConfigFile(argv, env)
|
|
911
|
+
const text = file === undefined ? '' : readFile(file)
|
|
912
|
+
const table = codexOtelTables(text).filter(isMainwaveExporter).at(-1)
|
|
913
|
+
const endpoint = stripSignalSuffix(table?.endpoint)
|
|
914
|
+
const bearer = table?.headers.Authorization
|
|
915
|
+
const ucid = table?.headers['X-Mainwave-UCID']
|
|
916
|
+
const userEmail = table?.headers['X-Mainwave-User-Email']
|
|
827
917
|
return {
|
|
828
918
|
endpoint: endpoint || undefined,
|
|
829
919
|
bearer: bearer || undefined,
|
|
@@ -835,11 +925,19 @@ export const codexOtelConfig = (readFile = readFileSafe) => {
|
|
|
835
925
|
}
|
|
836
926
|
|
|
837
927
|
/** Resolve OTLP config for the marker emit. `tool` selects the source format:
|
|
838
|
-
* 'codex' reads
|
|
928
|
+
* 'codex' reads the Codex config file the hook's `argv` selects (§
|
|
929
|
+
* `codexConfigFile`); the default reads Claude Code's settings.json env.
|
|
839
930
|
* `readers` (§ `onceReaders`) lets a caller share its file reads. */
|
|
840
|
-
export const loadOtelConfig = (
|
|
931
|
+
export const loadOtelConfig = (
|
|
932
|
+
cwd,
|
|
933
|
+
processEnv,
|
|
934
|
+
tool = 'claude-code',
|
|
935
|
+
managedDir,
|
|
936
|
+
readers = {},
|
|
937
|
+
argv = [],
|
|
938
|
+
) =>
|
|
841
939
|
tool === 'codex'
|
|
842
|
-
? codexOtelConfig()
|
|
940
|
+
? codexOtelConfig(undefined, undefined, argv)
|
|
843
941
|
: resolveOtelConfig(
|
|
844
942
|
settingsLayers(cwd, processEnv, readers.readFile, readers.listDir, managedDir),
|
|
845
943
|
processEnv,
|
|
@@ -1309,6 +1407,7 @@ export const sendClaudeEvent = async ({
|
|
|
1309
1407
|
tool,
|
|
1310
1408
|
managedDir,
|
|
1311
1409
|
readers,
|
|
1410
|
+
argv,
|
|
1312
1411
|
)
|
|
1313
1412
|
if (!endpoint || !bearer) {
|
|
1314
1413
|
log(`skip ${label}: collector endpoint/bearer not found in settings or env`)
|
package/hooks/plan-snapshot.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainwave/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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",
|
|
@@ -42,19 +45,19 @@
|
|
|
42
45
|
"api:generate": "openapi-ts"
|
|
43
46
|
},
|
|
44
47
|
"dependencies": {
|
|
45
|
-
"@inquirer/prompts": "8.7.
|
|
48
|
+
"@inquirer/prompts": "8.7.5",
|
|
46
49
|
"picocolors": "1.1.1"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@hey-api/openapi-ts": "^0.99.0",
|
|
50
53
|
"@types/node": "22.20.5",
|
|
51
|
-
"knip": "6.
|
|
52
|
-
"lefthook": "2.2.
|
|
53
|
-
"oxlint": "1.
|
|
54
|
+
"knip": "6.45.0",
|
|
55
|
+
"lefthook": "2.2.2",
|
|
56
|
+
"oxlint": "1.93.0",
|
|
54
57
|
"prettier": "3.9.10",
|
|
55
58
|
"typescript": "6.0.3",
|
|
56
|
-
"vite": "8.3.
|
|
57
|
-
"vitest": "5.0
|
|
59
|
+
"vite": "8.3.7",
|
|
60
|
+
"vitest": "5.1.0",
|
|
58
61
|
"yaml": "2.9.1"
|
|
59
62
|
},
|
|
60
63
|
"keywords": [
|