@mainwave/cli 0.7.0 → 0.8.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 +10 -4
- package/dist/adapters/claude-code.js +10 -3
- package/dist/adapters/claude-desktop.js +0 -1
- package/dist/adapters/codex-cli.js +0 -1
- package/dist/adapters/copilot-chat.js +0 -1
- package/dist/adapters/copilot-cli.js +0 -1
- package/dist/adapters/cursor-enterprise.js +0 -1
- package/dist/adapters/cursor.js +13 -2
- package/dist/adapters/index.js +0 -1
- package/dist/adapters/types.js +0 -1
- package/dist/api/index.js +0 -1
- package/dist/api/types.gen.js +0 -1
- package/dist/cli.js +0 -1
- package/dist/core/apply.js +0 -1
- package/dist/core/auth-commands.js +0 -1
- package/dist/core/behaviour-hooks.js +0 -1
- package/dist/core/browser.js +0 -1
- package/dist/core/codecs/cursor-hooks-json.js +0 -1
- package/dist/core/codecs/env-file.js +0 -1
- package/dist/core/codecs/json-env.js +0 -1
- package/dist/core/codecs/json-flat.js +0 -1
- package/dist/core/codecs/json-managed.js +0 -1
- package/dist/core/codecs/toml-otel.js +0 -1
- package/dist/core/codecs/types.js +0 -1
- package/dist/core/detect.js +0 -1
- package/dist/core/device-login.js +0 -1
- package/dist/core/doctor.js +19 -1
- package/dist/core/edit.js +9 -5
- package/dist/core/effective-settings.js +61 -20
- package/dist/core/env-command.js +0 -1
- package/dist/core/errors.js +0 -1
- package/dist/core/flags.js +0 -1
- package/dist/core/format.js +0 -1
- package/dist/core/git.js +0 -1
- package/dist/core/headers.js +0 -1
- package/dist/core/install-hooks.js +6 -6
- package/dist/core/interview.js +0 -1
- package/dist/core/keys.js +0 -1
- package/dist/core/layer-policy.js +2 -1
- package/dist/core/markers.js +173 -17
- package/dist/core/pinned-use-case.js +0 -1
- package/dist/core/platform.js +0 -1
- package/dist/core/post-setup.js +0 -1
- package/dist/core/prompts.js +0 -1
- package/dist/core/settings.js +16 -3
- package/dist/core/skills.js +5 -2
- package/dist/core/status.js +5 -4
- package/dist/core/store.js +0 -1
- package/dist/core/tty.js +0 -1
- package/dist/core/ucid.js +0 -1
- package/dist/core/ui.js +0 -1
- package/dist/core/use-case.js +0 -1
- package/dist/core/validate.js +0 -1
- package/dist/core/verify.js +0 -1
- package/dist/core/version.js +0 -1
- package/dist/core/wizard.js +3 -7
- package/dist/main.js +0 -1
- package/hooks/cursor-otlp.mjs +13 -15
- package/hooks/github-pr-marker.mjs +22 -11
- package/hooks/jira-ticket-marker.mjs +9 -9
- package/hooks/linear-ticket-marker.mjs +9 -7
- package/hooks/managed-entry.mjs +42 -0
- package/hooks/marker-core.mjs +123 -29
- package/package.json +4 -3
- package/skills/mainwave-instrument-node/SKILL.md +420 -0
- package/skills/mainwave-instrument-node/reference/api.md +96 -0
- package/skills/mainwave-instrument-node/reference/frameworks.md +82 -0
- package/skills/mainwave-instrument-node/reference/troubleshooting.md +152 -0
- package/dist/adapters/claude-code.js.map +0 -1
- package/dist/adapters/claude-desktop.js.map +0 -1
- package/dist/adapters/codex-cli.js.map +0 -1
- package/dist/adapters/copilot-chat.js.map +0 -1
- package/dist/adapters/copilot-cli.js.map +0 -1
- package/dist/adapters/cursor-enterprise.js.map +0 -1
- package/dist/adapters/cursor.js.map +0 -1
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/types.js.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/types.gen.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/apply.js.map +0 -1
- package/dist/core/auth-commands.js.map +0 -1
- package/dist/core/behaviour-hooks.js.map +0 -1
- package/dist/core/browser.js.map +0 -1
- package/dist/core/codecs/cursor-hooks-json.js.map +0 -1
- package/dist/core/codecs/env-file.js.map +0 -1
- package/dist/core/codecs/json-env.js.map +0 -1
- package/dist/core/codecs/json-flat.js.map +0 -1
- package/dist/core/codecs/json-managed.js.map +0 -1
- package/dist/core/codecs/toml-otel.js.map +0 -1
- package/dist/core/codecs/types.js.map +0 -1
- package/dist/core/detect.js.map +0 -1
- package/dist/core/device-login.js.map +0 -1
- package/dist/core/doctor.js.map +0 -1
- package/dist/core/edit.js.map +0 -1
- package/dist/core/effective-settings.js.map +0 -1
- package/dist/core/env-command.js.map +0 -1
- package/dist/core/errors.js.map +0 -1
- package/dist/core/flags.js.map +0 -1
- package/dist/core/format.js.map +0 -1
- package/dist/core/git.js.map +0 -1
- package/dist/core/headers.js.map +0 -1
- package/dist/core/install-hooks.js.map +0 -1
- package/dist/core/interview.js.map +0 -1
- package/dist/core/keys.js.map +0 -1
- package/dist/core/layer-policy.js.map +0 -1
- package/dist/core/markers.js.map +0 -1
- package/dist/core/pinned-use-case.js.map +0 -1
- package/dist/core/platform.js.map +0 -1
- package/dist/core/post-setup.js.map +0 -1
- package/dist/core/prompts.js.map +0 -1
- package/dist/core/settings.js.map +0 -1
- package/dist/core/skills.js.map +0 -1
- package/dist/core/status.js.map +0 -1
- package/dist/core/store.js.map +0 -1
- package/dist/core/tty.js.map +0 -1
- package/dist/core/ucid.js.map +0 -1
- package/dist/core/ui.js.map +0 -1
- package/dist/core/use-case.js.map +0 -1
- package/dist/core/validate.js.map +0 -1
- package/dist/core/verify.js.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/core/wizard.js.map +0 -1
- package/dist/main.js.map +0 -1
|
@@ -28,20 +28,20 @@
|
|
|
28
28
|
// wrongly assuming a hook couldn't produce it).
|
|
29
29
|
// Fails open and fast so a telemetry hiccup can never block the session.
|
|
30
30
|
|
|
31
|
-
import { homedir } from 'node:os'
|
|
32
|
-
import { join } from 'node:path'
|
|
33
31
|
import { pathToFileURL } from 'node:url'
|
|
34
32
|
|
|
35
33
|
import {
|
|
36
34
|
buildMarkerPayload,
|
|
37
35
|
markerOauthAccount,
|
|
36
|
+
markerSessionEnv,
|
|
38
37
|
emitMarker,
|
|
39
38
|
loadOtelConfig,
|
|
40
39
|
markerCallContext,
|
|
41
40
|
markerHostSource,
|
|
42
41
|
markerManagedDir,
|
|
42
|
+
markerProjectDir,
|
|
43
43
|
markerTool,
|
|
44
|
-
|
|
44
|
+
markerLog,
|
|
45
45
|
markerResourceAttrs as coreMarkerResourceAttrs,
|
|
46
46
|
payloadShape,
|
|
47
47
|
readStdin,
|
|
@@ -70,7 +70,7 @@ export {
|
|
|
70
70
|
toolOutput,
|
|
71
71
|
} from './marker-core.mjs'
|
|
72
72
|
|
|
73
|
-
const log =
|
|
73
|
+
const log = markerLog(process.argv, '.mainwave-ticket-marker.log')
|
|
74
74
|
|
|
75
75
|
// A source tag the collector does NOT classify as a coding agent, and a service
|
|
76
76
|
// name outside its coding-agent `service.name` allow-list, so the marker lands
|
|
@@ -259,10 +259,11 @@ const main = async () => {
|
|
|
259
259
|
const instance = extractInstance(output)
|
|
260
260
|
const op = detectOp(payload.tool_name, payload.tool_input)
|
|
261
261
|
|
|
262
|
-
const
|
|
262
|
+
const projectDir = markerProjectDir(payload)
|
|
263
263
|
const tool = markerTool(process.argv)
|
|
264
264
|
const managedDir = markerManagedDir(process.argv)
|
|
265
|
-
const
|
|
265
|
+
const env = markerSessionEnv(tool, payload)
|
|
266
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(projectDir, env, tool, managedDir)
|
|
266
267
|
log(
|
|
267
268
|
`issue=${issueKey} op=${op} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
268
269
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
|
@@ -273,7 +274,8 @@ const main = async () => {
|
|
|
273
274
|
}
|
|
274
275
|
// Read only once the emit is certain: `.claude.json` can run to megabytes.
|
|
275
276
|
const { email: userEmail, accountUuid: userAccountUuid } = markerOauthAccount(tool, {
|
|
276
|
-
cwd,
|
|
277
|
+
cwd: projectDir,
|
|
278
|
+
env,
|
|
277
279
|
managedDir,
|
|
278
280
|
})
|
|
279
281
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// mainwave managed hook entry v1
|
|
3
|
+
//
|
|
4
|
+
// The entry point `mainwave-cli install-hooks` writes under each marker hook's
|
|
5
|
+
// file name in the managed hooks directory (the names an organization's
|
|
6
|
+
// managed settings run). It holds no marker logic. It reads `current.json`
|
|
7
|
+
// beside it, which names one directory under `versions/`, and runs the
|
|
8
|
+
// same-named script from there. Every script in that directory comes from one
|
|
9
|
+
// CLI release, and `install-hooks` replaces `current.json` in a single rename
|
|
10
|
+
// only once a directory is complete, so two releases installing at the same
|
|
11
|
+
// moment never leave a hook running one release's script against another's
|
|
12
|
+
// shared modules.
|
|
13
|
+
//
|
|
14
|
+
// Its file name is the hook it stands for, so one body serves every hook.
|
|
15
|
+
// Fails open: a missing or malformed `current.json`, or a script the named
|
|
16
|
+
// release doesn't ship, exits 0 without sending anything.
|
|
17
|
+
|
|
18
|
+
import { readFileSync, realpathSync } from 'node:fs'
|
|
19
|
+
import { basename, dirname, join } from 'node:path'
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
21
|
+
|
|
22
|
+
const VERSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/
|
|
23
|
+
|
|
24
|
+
const here = fileURLToPath(import.meta.url)
|
|
25
|
+
|
|
26
|
+
const target = () => {
|
|
27
|
+
const { dir } = JSON.parse(readFileSync(join(dirname(here), 'current.json'), 'utf8'))
|
|
28
|
+
if (typeof dir !== 'string' || !VERSION_DIR_RE.test(dir)) return undefined
|
|
29
|
+
return realpathSync(join(dirname(here), 'versions', dir, basename(here)))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const script = target()
|
|
34
|
+
if (script !== undefined) {
|
|
35
|
+
// Each marker script runs its main only when it is the process's own
|
|
36
|
+
// entry point, which it checks against argv[1].
|
|
37
|
+
process.argv[1] = script
|
|
38
|
+
await import(pathToFileURL(script).href)
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// fail open — telemetry never blocks the session
|
|
42
|
+
}
|
package/hooks/marker-core.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { randomBytes } from 'node:crypto'
|
|
12
12
|
import { appendFileSync, readFileSync, readdirSync } from 'node:fs'
|
|
13
13
|
import { homedir } from 'node:os'
|
|
14
|
-
import { dirname, join, resolve } from 'node:path'
|
|
14
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
15
15
|
|
|
16
16
|
import {
|
|
17
17
|
ATTR_CALLER_SPAN_ID,
|
|
@@ -36,6 +36,45 @@ export const makeLog = (logPath) => (msg) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The value after `name` in the hook's own argv, or undefined. A flag is the
|
|
41
|
+
* one input a checked-out repository can't set: the hook command lives in the
|
|
42
|
+
* user's or the org's settings, not the repository's, while a repository's
|
|
43
|
+
* project settings `env` does reach the hook's environment (and a Cursor
|
|
44
|
+
* project hook can set env for later hooks). So anything that picks a file to
|
|
45
|
+
* write or a program to run comes from a flag, never from an env var.
|
|
46
|
+
*/
|
|
47
|
+
export const hookFlag = (argv, name) => {
|
|
48
|
+
const i = (argv ?? []).indexOf(name)
|
|
49
|
+
return i !== -1 && argv[i + 1] ? argv[i + 1] : undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The hook's log: `--log-file <path>` when the hook command passes one (tests
|
|
53
|
+
* do), else `defaultName` in the home directory. Never from the environment
|
|
54
|
+
* (§ `hookFlag`): a line logged here can carry a value the repository chose,
|
|
55
|
+
* so the repository mustn't choose the file it lands in either. */
|
|
56
|
+
export const markerLog = (argv, defaultName) =>
|
|
57
|
+
makeLog(hookFlag(argv, '--log-file') || join(homedir(), defaultName))
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The project root whose `.claude/` settings Claude Code loaded for this
|
|
61
|
+
* session: `CLAUDE_PROJECT_DIR`, which Claude Code sets for every hook. Not the
|
|
62
|
+
* payload's `cwd`, which follows each `cd` the agent runs — a vendored checkout
|
|
63
|
+
* underneath would otherwise have its own `.claude/settings.json` read as the
|
|
64
|
+
* session's project settings and re-attribute the marker. Only the session's
|
|
65
|
+
* own project settings could supply a different value there, and they already
|
|
66
|
+
* decide the session's attribution. Falls back to the payload's `cwd`, then the
|
|
67
|
+
* process cwd, when the variable is unset or not absolute (a hook run by hand).
|
|
68
|
+
*/
|
|
69
|
+
export const markerProjectDir = (payload, env = process.env) => {
|
|
70
|
+
// Claude Code exports CLAUDE_PROJECT_DIR itself on every hook process, set to
|
|
71
|
+
// the root the session started in, so a project settings `env` value can't
|
|
72
|
+
// choose it.
|
|
73
|
+
const dir = env.CLAUDE_PROJECT_DIR
|
|
74
|
+
if (typeof dir === 'string' && isAbsolute(dir)) return dir
|
|
75
|
+
return payload?.cwd || process.cwd()
|
|
76
|
+
}
|
|
77
|
+
|
|
39
78
|
/** Parse a comma-delimited `k=v,k2=v2` string (OTEL_RESOURCE_ATTRIBUTES / _HEADERS). */
|
|
40
79
|
export const parseKv = (raw) => {
|
|
41
80
|
const out = {}
|
|
@@ -97,16 +136,23 @@ const MANAGED_CREDENTIAL_KEYS = [
|
|
|
97
136
|
/**
|
|
98
137
|
* Merge settings layers (lowest precedence first), overlay any real process env
|
|
99
138
|
* on top, and pull out the OTLP config the hooks need. A layer is
|
|
100
|
-
* `{ env, exporter, managed }`:
|
|
139
|
+
* `{ env, exporter, managed, policy, headersHelper }`:
|
|
101
140
|
*
|
|
102
141
|
* - `exporter: false` layers (project and local settings) contribute only
|
|
103
142
|
* `OTEL_RESOURCE_ATTRIBUTES`, never the endpoint or key.
|
|
104
143
|
* - Across `managed` layers the telemetry unit travels together: its keys come
|
|
105
|
-
* from the highest managed source that sets any of them
|
|
106
|
-
*
|
|
144
|
+
* from the highest managed source that sets any of them or sets
|
|
145
|
+
* `otelHeadersHelper` (`headersHelper`), never an endpoint from one source
|
|
146
|
+
* with a key from another. A source that claims the unit through the helper
|
|
147
|
+
* supplies its unit keys only when it is the managed source in effect (the
|
|
148
|
+
* highest one with `policy`, i.e. any policy key); otherwise it supplies none
|
|
149
|
+
* and still blocks the lower sources. Other keys merge per key.
|
|
107
150
|
* - Over the developer's own layers, managed settings win key by key, and a
|
|
108
151
|
* managed credential also removes the developer's endpoint (§
|
|
109
152
|
* `MANAGED_CREDENTIAL_KEYS`).
|
|
153
|
+
* - With the helper in effect, the session's OTLP headers come from a command
|
|
154
|
+
* the hooks don't run, so no bearer is returned and no marker is sent: a
|
|
155
|
+
* static key found elsewhere may not be the one the session uses.
|
|
110
156
|
*
|
|
111
157
|
* The process env overlay only matters for a hook run by hand — Claude Code
|
|
112
158
|
* removes `OTEL_*` variables from the environment it gives hooks.
|
|
@@ -120,13 +166,20 @@ export const resolveOtelConfig = (layers, processEnv) => {
|
|
|
120
166
|
}
|
|
121
167
|
}
|
|
122
168
|
const managedLayers = layers.filter(({ managed }) => managed)
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
169
|
+
const highestFirst = [...managedLayers].reverse()
|
|
170
|
+
const unitLayer = highestFirst.find(
|
|
171
|
+
({ env, headersHelper }) =>
|
|
172
|
+
headersHelper === true || Object.keys(env ?? {}).some(isManagedTelemetryUnitKey),
|
|
173
|
+
)
|
|
174
|
+
// A layer built without `policy` delivers one if it sets any env.
|
|
175
|
+
const inEffect = highestFirst.find(
|
|
176
|
+
({ env, policy }) => policy ?? Object.keys(env ?? {}).length > 0,
|
|
177
|
+
)
|
|
178
|
+
const unitLands = unitLayer?.headersHelper !== true || unitLayer === inEffect
|
|
126
179
|
const managedEnv = {}
|
|
127
180
|
for (const layer of managedLayers) {
|
|
128
181
|
for (const [k, v] of Object.entries(layer.env ?? {})) {
|
|
129
|
-
if (!isManagedTelemetryUnitKey(k) || layer === unitLayer) managedEnv[k] = v
|
|
182
|
+
if (!isManagedTelemetryUnitKey(k) || (layer === unitLayer && unitLands)) managedEnv[k] = v
|
|
130
183
|
}
|
|
131
184
|
}
|
|
132
185
|
if (MANAGED_CREDENTIAL_KEYS.some((k) => managedEnv[k])) {
|
|
@@ -136,9 +189,10 @@ export const resolveOtelConfig = (layers, processEnv) => {
|
|
|
136
189
|
for (const k of [...EXPORTER_KEYS, 'OTEL_RESOURCE_ATTRIBUTES']) {
|
|
137
190
|
if (processEnv[k]) merged[k] = processEnv[k]
|
|
138
191
|
}
|
|
192
|
+
const helperInEffect = unitLayer?.headersHelper === true && unitLands
|
|
139
193
|
return {
|
|
140
194
|
endpoint: merged.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
141
|
-
bearer: bearerFromHeaders(merged.OTEL_EXPORTER_OTLP_HEADERS),
|
|
195
|
+
bearer: helperInEffect ? undefined : bearerFromHeaders(merged.OTEL_EXPORTER_OTLP_HEADERS),
|
|
142
196
|
resourceAttrs: parseKv(merged.OTEL_RESOURCE_ATTRIBUTES),
|
|
143
197
|
}
|
|
144
198
|
}
|
|
@@ -163,14 +217,43 @@ const normalizedConfigDirEnv = (env) => {
|
|
|
163
217
|
|
|
164
218
|
/** Claude Code's user config root: `$CLAUDE_CONFIG_DIR` when set, else
|
|
165
219
|
* `~/.claude`. The hook runs as a Claude Code subprocess, so it sees
|
|
166
|
-
* the same variable the session resolved its own settings from
|
|
167
|
-
*
|
|
220
|
+
* the same variable the session resolved its own settings from — or, when
|
|
221
|
+
* the credential scrub leaves it out, gets it back from the payload
|
|
222
|
+
* (§ `markerSessionEnv`) — and the CLI resolves it the same way. A repository can't steer
|
|
168
223
|
* this through its project settings: Claude Code drops `CLAUDE_CONFIG_DIR`,
|
|
169
224
|
* `HOME` and the other directory variables from project and local `env`
|
|
170
225
|
* (since 2.1.251), so neither reaches the hook from there. */
|
|
171
226
|
export const claudeConfigDir = (env = process.env) =>
|
|
172
227
|
normalizedConfigDirEnv(env) ?? join(homedir(), '.claude')
|
|
173
228
|
|
|
229
|
+
/** The config dir a Claude Code transcript path lives under, or `undefined`
|
|
230
|
+
* when the path doesn't have the shape Claude Code writes:
|
|
231
|
+
* `<config dir>/projects/<project>/<session>.jsonl`, absolute. */
|
|
232
|
+
const configDirFromTranscript = (transcriptPath) => {
|
|
233
|
+
if (typeof transcriptPath !== 'string' || !isAbsolute(transcriptPath)) return undefined
|
|
234
|
+
if (!transcriptPath.endsWith('.jsonl')) return undefined
|
|
235
|
+
const projects = dirname(dirname(transcriptPath))
|
|
236
|
+
return basename(projects) === 'projects' ? dirname(projects) : undefined
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The environment to resolve a marker's settings from: the hook's own, with
|
|
241
|
+
* the session's `CLAUDE_CONFIG_DIR` put back when the credential scrub
|
|
242
|
+
* (`CLAUDE_CODE_SUBPROCESS_ENV_SCRUB`) left it out. Without it a relocated
|
|
243
|
+
* config dir would resolve to `~/.claude` — another profile's user settings
|
|
244
|
+
* and server-managed cache. The hook payload's `transcript_path` names the
|
|
245
|
+
* session's config dir (§ `configDirFromTranscript`), so it is read from
|
|
246
|
+
* there — only for Claude Code, only with the scrub on, and only when the
|
|
247
|
+
* variable is unset or blank; otherwise `env` is returned as is.
|
|
248
|
+
*/
|
|
249
|
+
export const markerSessionEnv = (tool, payload, env = process.env) => {
|
|
250
|
+
if (tool !== 'claude-code') return env
|
|
251
|
+
if (!isTruthyEnvValue(env.CLAUDE_CODE_SUBPROCESS_ENV_SCRUB)) return env
|
|
252
|
+
if (normalizedConfigDirEnv(env) !== undefined) return env
|
|
253
|
+
const dir = configDirFromTranscript(payload?.transcript_path)
|
|
254
|
+
return dir === undefined ? env : { ...env, CLAUDE_CONFIG_DIR: dir }
|
|
255
|
+
}
|
|
256
|
+
|
|
174
257
|
/** A directory's `*.json` files, sorted, or `[]` when it is missing. */
|
|
175
258
|
const jsonFilesIn = (dir) => {
|
|
176
259
|
try {
|
|
@@ -275,19 +358,26 @@ export const managedSettingsPaths = (env = process.env, listDir = jsonFilesIn, m
|
|
|
275
358
|
/** Top-level keys that don't make a managed file "deliver a policy". */
|
|
276
359
|
const NON_POLICY_KEYS = new Set(['wslInheritsWindowsSettings', 'managedSourcesBehavior'])
|
|
277
360
|
|
|
278
|
-
const
|
|
361
|
+
const parsedObject = (text) => {
|
|
279
362
|
try {
|
|
280
363
|
const doc = JSON.parse(text)
|
|
281
|
-
return (
|
|
282
|
-
doc !== null &&
|
|
283
|
-
typeof doc === 'object' &&
|
|
284
|
-
Object.keys(doc).some((k) => !NON_POLICY_KEYS.has(k))
|
|
285
|
-
)
|
|
364
|
+
return doc !== null && typeof doc === 'object' && !Array.isArray(doc) ? doc : undefined
|
|
286
365
|
} catch {
|
|
287
|
-
return
|
|
366
|
+
return undefined
|
|
288
367
|
}
|
|
289
368
|
}
|
|
290
369
|
|
|
370
|
+
const hasPolicyKey = (text) => {
|
|
371
|
+
const doc = parsedObject(text)
|
|
372
|
+
return doc !== undefined && Object.keys(doc).some((k) => !NON_POLICY_KEYS.has(k))
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Whether a settings file's raw text sets a non-blank `otelHeadersHelper`. */
|
|
376
|
+
const hasOtelHeadersHelper = (text) => {
|
|
377
|
+
const helper = parsedObject(text)?.otelHeadersHelper
|
|
378
|
+
return typeof helper === 'string' && trimAscii(helper) !== ''
|
|
379
|
+
}
|
|
380
|
+
|
|
291
381
|
/**
|
|
292
382
|
* The managed source whose non-`env` settings (hooks, `apiKeyHelper`) Claude
|
|
293
383
|
* Code uses: the first that sets any policy key, server-managed before the file
|
|
@@ -307,7 +397,8 @@ export const selectedManagedPaths = (
|
|
|
307
397
|
|
|
308
398
|
/**
|
|
309
399
|
* Settings layers Claude Code reads, lowest precedence first: user, project,
|
|
310
|
-
* local, then one layer per managed source (§ `managedSources`)
|
|
400
|
+
* local, then one layer per managed source (§ `managedSources`), each marked
|
|
401
|
+
* with whether it delivers a policy and sets `otelHeadersHelper`. Project and
|
|
311
402
|
* local layers are `exporter: false` (§ `resolveOtelConfig`). `readFile`,
|
|
312
403
|
* `listDir` and `managedDir` are overridable for tests.
|
|
313
404
|
*/
|
|
@@ -326,11 +417,16 @@ export const settingsLayers = (
|
|
|
326
417
|
listDir,
|
|
327
418
|
managedDir,
|
|
328
419
|
sessionBypassesServer(cwd, env, readFile, listDir, managedDir),
|
|
329
|
-
).map((source) =>
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
420
|
+
).map((source) => {
|
|
421
|
+
const texts = source.paths.map((p) => readFile(p))
|
|
422
|
+
return {
|
|
423
|
+
env: Object.assign({}, ...texts.map(settingsEnv)),
|
|
424
|
+
exporter: true,
|
|
425
|
+
managed: true,
|
|
426
|
+
policy: texts.some(hasPolicyKey),
|
|
427
|
+
headersHelper: texts.some(hasOtelHeadersHelper),
|
|
428
|
+
}
|
|
429
|
+
}),
|
|
334
430
|
]
|
|
335
431
|
|
|
336
432
|
/**
|
|
@@ -476,10 +572,7 @@ const managedSettingsPath = (managedDir) => {
|
|
|
476
572
|
/** The `--managed-settings-dir <dir>` flag, or undefined. Neither setup nor the
|
|
477
573
|
* org-wide payload writes it; it lets tests point the hooks at a temp
|
|
478
574
|
* directory instead of the machine's real org policy. */
|
|
479
|
-
export const markerManagedDir = (argv) =>
|
|
480
|
-
const i = (argv ?? []).indexOf('--managed-settings-dir')
|
|
481
|
-
return i !== -1 && argv[i + 1] ? argv[i + 1] : undefined
|
|
482
|
-
}
|
|
575
|
+
export const markerManagedDir = (argv) => hookFlag(argv, '--managed-settings-dir')
|
|
483
576
|
|
|
484
577
|
/** Whether a settings file's raw text sets a non-blank `apiKeyHelper` — an
|
|
485
578
|
* external script Claude Code invokes to resolve the API key. The hook can't
|
|
@@ -543,7 +636,8 @@ export const hasApiKeyHelper = (
|
|
|
543
636
|
* identity beats a wrong one.
|
|
544
637
|
*
|
|
545
638
|
* `opts`: `env` (default `process.env`), `home` (default `homedir()`), `cwd`
|
|
546
|
-
* (default `process.cwd()`, used for
|
|
639
|
+
* (the project root, § `markerProjectDir`; default `process.cwd()`, used for
|
|
640
|
+
* the project-local `apiKeyHelper` check),
|
|
547
641
|
* and `configDir` — when the key is present its value is used as-is
|
|
548
642
|
* (`undefined` = unset), otherwise `env.CLAUDE_CONFIG_DIR`, raw
|
|
549
643
|
* (§ `claudeCodeOauthAccount`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainwave/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Setup wizard for connecting third-party coding tools to Mainwave AI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -48,10 +48,11 @@
|
|
|
48
48
|
"@hey-api/openapi-ts": "^0.99.0",
|
|
49
49
|
"@types/node": "22.20.4",
|
|
50
50
|
"lefthook": "2.1.14",
|
|
51
|
-
"oxlint": "1.
|
|
51
|
+
"oxlint": "1.86.0",
|
|
52
52
|
"prettier": "3.9.9",
|
|
53
53
|
"typescript": "6.0.3",
|
|
54
|
-
"
|
|
54
|
+
"vite": "8.3.1",
|
|
55
|
+
"vitest": "5.0.2",
|
|
55
56
|
"yaml": "2.9.1"
|
|
56
57
|
},
|
|
57
58
|
"keywords": [
|