@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.
Files changed (124) hide show
  1. package/README.md +10 -4
  2. package/dist/adapters/claude-code.js +10 -3
  3. package/dist/adapters/claude-desktop.js +0 -1
  4. package/dist/adapters/codex-cli.js +0 -1
  5. package/dist/adapters/copilot-chat.js +0 -1
  6. package/dist/adapters/copilot-cli.js +0 -1
  7. package/dist/adapters/cursor-enterprise.js +0 -1
  8. package/dist/adapters/cursor.js +13 -2
  9. package/dist/adapters/index.js +0 -1
  10. package/dist/adapters/types.js +0 -1
  11. package/dist/api/index.js +0 -1
  12. package/dist/api/types.gen.js +0 -1
  13. package/dist/cli.js +0 -1
  14. package/dist/core/apply.js +0 -1
  15. package/dist/core/auth-commands.js +0 -1
  16. package/dist/core/behaviour-hooks.js +0 -1
  17. package/dist/core/browser.js +0 -1
  18. package/dist/core/codecs/cursor-hooks-json.js +0 -1
  19. package/dist/core/codecs/env-file.js +0 -1
  20. package/dist/core/codecs/json-env.js +0 -1
  21. package/dist/core/codecs/json-flat.js +0 -1
  22. package/dist/core/codecs/json-managed.js +0 -1
  23. package/dist/core/codecs/toml-otel.js +0 -1
  24. package/dist/core/codecs/types.js +0 -1
  25. package/dist/core/detect.js +0 -1
  26. package/dist/core/device-login.js +0 -1
  27. package/dist/core/doctor.js +19 -1
  28. package/dist/core/edit.js +9 -5
  29. package/dist/core/effective-settings.js +61 -20
  30. package/dist/core/env-command.js +0 -1
  31. package/dist/core/errors.js +0 -1
  32. package/dist/core/flags.js +0 -1
  33. package/dist/core/format.js +0 -1
  34. package/dist/core/git.js +0 -1
  35. package/dist/core/headers.js +0 -1
  36. package/dist/core/install-hooks.js +6 -6
  37. package/dist/core/interview.js +0 -1
  38. package/dist/core/keys.js +0 -1
  39. package/dist/core/layer-policy.js +2 -1
  40. package/dist/core/markers.js +173 -17
  41. package/dist/core/pinned-use-case.js +0 -1
  42. package/dist/core/platform.js +0 -1
  43. package/dist/core/post-setup.js +0 -1
  44. package/dist/core/prompts.js +0 -1
  45. package/dist/core/settings.js +16 -3
  46. package/dist/core/skills.js +5 -2
  47. package/dist/core/status.js +5 -4
  48. package/dist/core/store.js +0 -1
  49. package/dist/core/tty.js +0 -1
  50. package/dist/core/ucid.js +0 -1
  51. package/dist/core/ui.js +0 -1
  52. package/dist/core/use-case.js +0 -1
  53. package/dist/core/validate.js +0 -1
  54. package/dist/core/verify.js +0 -1
  55. package/dist/core/version.js +0 -1
  56. package/dist/core/wizard.js +3 -7
  57. package/dist/main.js +0 -1
  58. package/hooks/cursor-otlp.mjs +13 -15
  59. package/hooks/github-pr-marker.mjs +22 -11
  60. package/hooks/jira-ticket-marker.mjs +9 -9
  61. package/hooks/linear-ticket-marker.mjs +9 -7
  62. package/hooks/managed-entry.mjs +42 -0
  63. package/hooks/marker-core.mjs +123 -29
  64. package/package.json +4 -3
  65. package/skills/mainwave-instrument-node/SKILL.md +420 -0
  66. package/skills/mainwave-instrument-node/reference/api.md +96 -0
  67. package/skills/mainwave-instrument-node/reference/frameworks.md +82 -0
  68. package/skills/mainwave-instrument-node/reference/troubleshooting.md +152 -0
  69. package/dist/adapters/claude-code.js.map +0 -1
  70. package/dist/adapters/claude-desktop.js.map +0 -1
  71. package/dist/adapters/codex-cli.js.map +0 -1
  72. package/dist/adapters/copilot-chat.js.map +0 -1
  73. package/dist/adapters/copilot-cli.js.map +0 -1
  74. package/dist/adapters/cursor-enterprise.js.map +0 -1
  75. package/dist/adapters/cursor.js.map +0 -1
  76. package/dist/adapters/index.js.map +0 -1
  77. package/dist/adapters/types.js.map +0 -1
  78. package/dist/api/index.js.map +0 -1
  79. package/dist/api/types.gen.js.map +0 -1
  80. package/dist/cli.js.map +0 -1
  81. package/dist/core/apply.js.map +0 -1
  82. package/dist/core/auth-commands.js.map +0 -1
  83. package/dist/core/behaviour-hooks.js.map +0 -1
  84. package/dist/core/browser.js.map +0 -1
  85. package/dist/core/codecs/cursor-hooks-json.js.map +0 -1
  86. package/dist/core/codecs/env-file.js.map +0 -1
  87. package/dist/core/codecs/json-env.js.map +0 -1
  88. package/dist/core/codecs/json-flat.js.map +0 -1
  89. package/dist/core/codecs/json-managed.js.map +0 -1
  90. package/dist/core/codecs/toml-otel.js.map +0 -1
  91. package/dist/core/codecs/types.js.map +0 -1
  92. package/dist/core/detect.js.map +0 -1
  93. package/dist/core/device-login.js.map +0 -1
  94. package/dist/core/doctor.js.map +0 -1
  95. package/dist/core/edit.js.map +0 -1
  96. package/dist/core/effective-settings.js.map +0 -1
  97. package/dist/core/env-command.js.map +0 -1
  98. package/dist/core/errors.js.map +0 -1
  99. package/dist/core/flags.js.map +0 -1
  100. package/dist/core/format.js.map +0 -1
  101. package/dist/core/git.js.map +0 -1
  102. package/dist/core/headers.js.map +0 -1
  103. package/dist/core/install-hooks.js.map +0 -1
  104. package/dist/core/interview.js.map +0 -1
  105. package/dist/core/keys.js.map +0 -1
  106. package/dist/core/layer-policy.js.map +0 -1
  107. package/dist/core/markers.js.map +0 -1
  108. package/dist/core/pinned-use-case.js.map +0 -1
  109. package/dist/core/platform.js.map +0 -1
  110. package/dist/core/post-setup.js.map +0 -1
  111. package/dist/core/prompts.js.map +0 -1
  112. package/dist/core/settings.js.map +0 -1
  113. package/dist/core/skills.js.map +0 -1
  114. package/dist/core/status.js.map +0 -1
  115. package/dist/core/store.js.map +0 -1
  116. package/dist/core/tty.js.map +0 -1
  117. package/dist/core/ucid.js.map +0 -1
  118. package/dist/core/ui.js.map +0 -1
  119. package/dist/core/use-case.js.map +0 -1
  120. package/dist/core/validate.js.map +0 -1
  121. package/dist/core/verify.js.map +0 -1
  122. package/dist/core/version.js.map +0 -1
  123. package/dist/core/wizard.js.map +0 -1
  124. package/dist/main.js.map +0 -1
package/README.md CHANGED
@@ -147,12 +147,15 @@ flag it needed. `status` and `doctor` also take `--json`.
147
147
 
148
148
  ## Agent skills
149
149
 
150
- Setup installs two skills alongside the telemetry config — one detection, one pass, two outputs:
150
+ Setup installs three skills alongside the telemetry config — one detection, one pass, two outputs:
151
151
 
152
152
  - **`mainwave-setup`** — lets your coding agent run this whole flow itself: sign in, configure a
153
153
  tool, verify. It knows the flags, so you can just ask it to connect you.
154
154
  - **`mainwave-instrument`** — wires the `mainwave` Python SDK into an application, so an agent or
155
155
  service of your own reports runs, tokens, and cost.
156
+ - **`mainwave-instrument-node`** — wires the `@mainwave/sdk` Node.js SDK into a Node or TypeScript
157
+ application (eve, the Vercel AI SDK, OpenAI, Anthropic), so it reports runs, tokens, and cost.
158
+ Your agent picks it for a Node repository and `mainwave-instrument` for a Python one.
156
159
 
157
160
  The bundles are copied to `~/.mainwave/skills/`, then registered on each tool's own instruction
158
161
  surface: a native skill directory for Claude Code, `AGENTS.md` for Codex, `copilot-instructions.md`
@@ -196,11 +199,14 @@ entries are removed cleanly.
196
199
  Organizations that configure Claude Code centrally (managed settings from the Claude admin console,
197
200
  or an MDM `managed-settings.json`) deliver the markers without anyone running setup: when a session
198
201
  starts or resumes (not on `/clear` or a compaction), the managed settings run
199
- `cd "$HOME" && npx -y --registry=https://registry.npmjs.org @mainwave/cli@<version> install-hooks --quiet`
202
+ `cd "$HOME" && npx -y --registry=https://registry.npmjs.org @mainwave/cli@latest install-hooks --quiet`
200
203
  — from your home directory, so a repository's own `.npmrc` or `node_modules` can't choose what runs —
201
204
  which installs or refreshes the scripts in `~/.mainwave/hooks/managed/` with no prompts, no
202
- sign-in and no network calls of its own. That directory is separate from the one a per-developer
203
- setup installs to, so neither overwrites the other's scripts. When managed settings deliver the
205
+ sign-in and no network calls of its own. `@latest` means each new release reaches your machine at
206
+ its next session start, whatever copy of the CLI you have installed: npx asks the registry for the
207
+ current release each time, and while you're offline the scripts already installed keep working.
208
+ That directory is separate from the one a per-developer setup installs to, so neither overwrites the
209
+ other's scripts. When managed settings deliver the
204
210
  hooks, it also removes the copy an earlier per-developer setup left in your user settings, so each ticket and PR is marked once, and `setup` itself leaves
205
211
  out any hook your managed settings already run. It never edits project settings; `doctor` lists
206
212
  every settings file that installs the hooks and warns when two of them would fire for the same
@@ -278,13 +278,20 @@ const isManagedTelemetryUnitKey = (key) => key.startsWith('OTEL_EXPORTER_OTLP_')
278
278
  key === 'OTEL_LOGS_EXPORTER' ||
279
279
  key === 'ENABLE_BETA_TRACING_DETAILED' ||
280
280
  key === 'BETA_TRACING_ENDPOINT';
281
+ const OTEL_HEADERS_HELPER = 'otelHeadersHelper';
282
+ const claimsManagedTelemetryUnit = (settings) => {
283
+ const helper = settings[OTEL_HEADERS_HELPER];
284
+ return typeof helper === 'string' && helper.replace(/^[ \t\n\r\v\f]+|[ \t\n\r\v\f]+$/g, '') !== ''
285
+ ? OTEL_HEADERS_HELPER
286
+ : undefined;
287
+ };
281
288
  const TRUTHY = new Set(['1', 'true', 'yes', 'on']);
282
289
  const OTLP = 'OTEL_EXPORTER_OTLP_';
283
290
  const OTLP_SIGNALS = ['TRACES', 'METRICS', 'LOGS'];
284
291
  const OTLP_CREDENTIALS = ['HEADERS', 'CLIENT_KEY', 'CLIENT_CERTIFICATE'];
285
292
  const perSignal = (suffix) => OTLP_SIGNALS.map((s) => `${OTLP}${s}_${suffix}`);
286
293
  const OFF_SELECTOR_VALUES = new Set(['none', 'console', '']);
287
- const isManagedLockedKey = (key, managed) => {
294
+ const isManagedLockedKey = (key, managed, unitClaim) => {
288
295
  const set = (k) => (managed[k] ?? '') !== '';
289
296
  if (set(`${OTLP}ENDPOINT`) && perSignal('ENDPOINT').includes(key))
290
297
  return true;
@@ -315,7 +322,7 @@ const isManagedLockedKey = (key, managed) => {
315
322
  const signalOff = ['OTEL_LOGS_EXPORTER', 'OTEL_TRACES_EXPORTER'].some((k) => k in managed && OFF_SELECTOR_VALUES.has(managed[k].trim().toLowerCase()));
316
323
  const telemetryOff = 'CLAUDE_CODE_ENABLE_TELEMETRY' in managed &&
317
324
  !TRUTHY.has(managed.CLAUDE_CODE_ENABLE_TELEMETRY.trim().toLowerCase());
318
- return decides || signalOff || telemetryOff;
325
+ return decides || unitClaim === OTEL_HEADERS_HELPER || signalOff || telemetryOff;
319
326
  }
320
327
  return false;
321
328
  };
@@ -418,6 +425,7 @@ export const claudeCode = {
418
425
  hierarchy: HIERARCHY,
419
426
  layerKeyPolicy: CLAUDE_CODE_LAYER_POLICY,
420
427
  managedUnitKey: isManagedTelemetryUnitKey,
428
+ managedUnitClaim: claimsManagedTelemetryUnit,
421
429
  managedLock: isManagedLockedKey,
422
430
  inactiveLayers: (env) => serverManagedBypassed(env)
423
431
  ? [
@@ -441,4 +449,3 @@ export const claudeCode = {
441
449
  disclosure: 'Sends Linear/Jira issue ids and GitHub PR urls to the collector — never ticket bodies or diff content.',
442
450
  },
443
451
  };
444
- //# sourceMappingURL=claude-code.js.map
@@ -163,4 +163,3 @@ export const claudeDesktop = {
163
163
  normalizeForGenericChecks,
164
164
  printPostSetupInstructions,
165
165
  };
166
- //# sourceMappingURL=claude-desktop.js.map
@@ -198,4 +198,3 @@ export const codexCli = {
198
198
  runtimeTool: 'codex',
199
199
  },
200
200
  };
201
- //# sourceMappingURL=codex-cli.js.map
@@ -181,4 +181,3 @@ export const copilotChat = {
181
181
  printPostSetupInstructions,
182
182
  additionalWrites: [envFileWrite],
183
183
  };
184
- //# sourceMappingURL=copilot-chat.js.map
@@ -107,4 +107,3 @@ export const copilotCli = {
107
107
  normalizeForGenericChecks,
108
108
  printPostSetupInstructions,
109
109
  };
110
- //# sourceMappingURL=copilot-cli.js.map
@@ -103,4 +103,3 @@ export const cursorEnterprise = {
103
103
  normalizeForGenericChecks,
104
104
  printPostSetupInstructions,
105
105
  };
106
- //# sourceMappingURL=cursor-enterprise.js.map
@@ -1,3 +1,4 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { homedir } from 'node:os';
2
3
  import { join } from 'node:path';
3
4
  import { cursorHooksJsonCodec } from '../core/codecs/cursor-hooks-json.js';
@@ -5,6 +6,7 @@ import { envFileCodec } from '../core/codecs/env-file.js';
5
6
  import { hasBinary, hasPath } from '../core/detect.js';
6
7
  import { buildHeaders, HEADER_NAME, headerBearerToken, kvPairsHeaders } from '../core/headers.js';
7
8
  import { buildHookCommand, installedHooksDir } from '../core/markers.js';
9
+ import { isSamePath } from '../core/settings.js';
8
10
  import { VERSION } from '../core/version.js';
9
11
  const SOURCE_VALUE = 'coding_agent.cursor';
10
12
  const CONFIG_MANAGED_KEYS = ['OTEL_EXPORTER_OTLP_ENDPOINT', 'OTEL_EXPORTER_OTLP_HEADERS'];
@@ -107,9 +109,17 @@ const hooksWrite = {
107
109
  },
108
110
  };
109
111
  const HIERARCHY = [
110
- { id: 'projectLocal', label: 'Project (local)', path: CONFIG_LOCAL, kind: 'file' },
111
112
  { id: 'user', label: 'User (global)', path: CONFIG_GLOBAL, kind: 'file' },
112
113
  ];
114
+ const LOCAL_IGNORED = `The Cursor hook ignores ${CONFIG_LOCAL}: it reads only ~/.mainwave/cursor.env`;
115
+ const collectFileChecks = () => !isSamePath(CONFIG_LOCAL, CONFIG_GLOBAL) && existsSync(CONFIG_LOCAL)
116
+ ? [
117
+ {
118
+ level: 'warn',
119
+ message: `${LOCAL_IGNORED}, so this file has no effect. Remove it.`,
120
+ },
121
+ ]
122
+ : [];
113
123
  export const cursor = {
114
124
  name: 'cursor',
115
125
  displayName: 'Cursor',
@@ -122,6 +132,7 @@ export const cursor = {
122
132
  paths: {
123
133
  local: CONFIG_LOCAL,
124
134
  global: CONFIG_GLOBAL,
135
+ localIgnored: LOCAL_IGNORED,
125
136
  },
126
137
  runInstruction: 'cursor (restart any open window so the hooks reload)',
127
138
  detect: () => hasPath(join(homedir(), '.cursor')) || hasBinary('cursor'),
@@ -131,6 +142,7 @@ export const cursor = {
131
142
  buildEnv,
132
143
  parseEnv,
133
144
  collectChecks,
145
+ collectFileChecks,
134
146
  normalizeForGenericChecks,
135
147
  additionalWrites: [hooksWrite],
136
148
  bundledHookScripts: ['marker-core.mjs', 'vocabulary.mjs', 'cursor-otlp.mjs'],
@@ -140,4 +152,3 @@ export const cursor = {
140
152
  script: 'cursor-otlp.mjs',
141
153
  },
142
154
  };
143
- //# sourceMappingURL=cursor.js.map
@@ -15,4 +15,3 @@ export const adapters = {
15
15
  [cursorEnterprise.name]: cursorEnterprise,
16
16
  };
17
17
  export const adapterNames = () => Object.keys(adapters).sort();
18
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
package/dist/api/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.gen.js.map
package/dist/cli.js CHANGED
@@ -2,4 +2,3 @@
2
2
  import { main } from './main.js';
3
3
  const code = await main(process.argv);
4
4
  process.exit(code);
5
- //# sourceMappingURL=cli.js.map
@@ -260,4 +260,3 @@ export const printPostSetup = (plan) => {
260
260
  say(`Next for ${plan.adapter.displayName}: run ${color.bold(plan.adapter.runInstruction)}.`);
261
261
  }
262
262
  };
263
- //# sourceMappingURL=apply.js.map
@@ -149,4 +149,3 @@ export const runWhoami = async (options = {}) => {
149
149
  }
150
150
  return 0;
151
151
  };
152
- //# sourceMappingURL=auth-commands.js.map
@@ -91,4 +91,3 @@ export const collectBehaviourHookIssues = async (cap, currentVersion, scan = sca
91
91
  }
92
92
  return issues;
93
93
  };
94
- //# sourceMappingURL=behaviour-hooks.js.map
@@ -20,4 +20,3 @@ export const openUrl = (url) => {
20
20
  return false;
21
21
  }
22
22
  };
23
- //# sourceMappingURL=browser.js.map
@@ -79,4 +79,3 @@ export const cursorHooksJsonCodec = {
79
79
  readEnv,
80
80
  applyEnv,
81
81
  };
82
- //# sourceMappingURL=cursor-hooks-json.js.map
@@ -107,4 +107,3 @@ export const envFileCodec = {
107
107
  readEnv,
108
108
  applyEnv,
109
109
  };
110
- //# sourceMappingURL=env-file.js.map
@@ -58,4 +58,3 @@ export const jsonEnvCodec = {
58
58
  readEnv: readEnvObject,
59
59
  applyEnv,
60
60
  };
61
- //# sourceMappingURL=json-env.js.map
@@ -63,4 +63,3 @@ export const jsonFlatCodec = {
63
63
  readEnv,
64
64
  applyEnv,
65
65
  };
66
- //# sourceMappingURL=json-flat.js.map
@@ -57,4 +57,3 @@ export const jsonManagedCodec = {
57
57
  readEnv,
58
58
  applyEnv,
59
59
  };
60
- //# sourceMappingURL=json-managed.js.map
@@ -363,4 +363,3 @@ export const tomlOtelCodec = {
363
363
  readEnv,
364
364
  applyEnv,
365
365
  };
366
- //# sourceMappingURL=toml-otel.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -20,4 +20,3 @@ export const hasEntryPrefixed = (dir, prefix) => {
20
20
  return false;
21
21
  }
22
22
  };
23
- //# sourceMappingURL=detect.js.map
@@ -51,4 +51,3 @@ export const deviceLogin = async (apiUrl, options = {}) => {
51
51
  }
52
52
  }
53
53
  };
54
- //# sourceMappingURL=device-login.js.map
@@ -283,6 +283,25 @@ const collectIssues = (effective, adapter, secondary = {}) => {
283
283
  "collector they didn't choose.",
284
284
  });
285
285
  }
286
+ const claim = effective.unitClaim;
287
+ if (claim) {
288
+ const where = `${claim.scan.layer.label} (${claim.scan.path})`;
289
+ issues.push(claim.lands
290
+ ? {
291
+ level: adapter.markers ? 'warn' : 'info',
292
+ message: `${where} sets ${claim.setting}, so ${adapter.displayName} generates its OTLP headers ` +
293
+ 'with that command.' +
294
+ (adapter.markers
295
+ ? " The ticket and PR marker hooks don't run it, so they send no markers."
296
+ : ''),
297
+ }
298
+ : {
299
+ level: 'info',
300
+ message: `${where} sets ${claim.setting} but isn't the managed source ${adapter.displayName} uses, ` +
301
+ 'so it supplies none of the managed OTLP settings and lower managed sources are ignored ' +
302
+ 'for them too.',
303
+ });
304
+ }
286
305
  for (const { layer, reason } of effective.skipped ?? []) {
287
306
  issues.push({
288
307
  level: 'info',
@@ -556,4 +575,3 @@ const runDoctorJson = async (adapter, options) => {
556
575
  emitJson(await doctorJson(adapter, effective, issues, validation));
557
576
  return issues.some((i) => i.level === 'error') || validation?.ok === false ? 1 : 0;
558
577
  };
559
- //# sourceMappingURL=doctor.js.map
package/dist/core/edit.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { select } from '@inquirer/prompts';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { promises as fs } from 'node:fs';
4
- import { resolve } from 'node:path';
5
4
  import { WizardAbort } from './errors.js';
6
5
  import { color } from './format.js';
7
6
  import { policyState } from './layer-policy.js';
7
+ import { isSamePath } from './settings.js';
8
8
  const candidatesFor = (adapter) => {
9
9
  const out = [
10
10
  { label: 'Global', path: adapter.paths.global },
@@ -102,10 +102,15 @@ const spawnEditor = (editor, path) => new Promise((resolve, reject) => {
102
102
  });
103
103
  const isInteractive = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
104
104
  export const ignoredKeysEditNote = (adapter, target) => {
105
- const policy = adapter.layerKeyPolicy;
106
- if (!policy || target !== adapter.paths.local)
105
+ if (target !== adapter.paths.local)
106
+ return null;
107
+ if (isSamePath(target, adapter.paths.global))
107
108
  return null;
108
- if (resolve(target) === resolve(adapter.paths.global))
109
+ if (adapter.paths.localIgnored !== undefined) {
110
+ return `${adapter.paths.localIgnored}. To change where telemetry goes, run \`mainwave-cli edit ${adapter.name} --global\`.`;
111
+ }
112
+ const policy = adapter.layerKeyPolicy;
113
+ if (!policy)
109
114
  return null;
110
115
  const layerId = adapter.hierarchy.find((l) => l.path === target)?.id;
111
116
  if (!layerId || !policy.layers.includes(layerId) || policyState(policy) !== 'active')
@@ -140,4 +145,3 @@ export const runEdit = async (adapter, opts) => {
140
145
  console.error(color.yellow(`⚠ ${note}`));
141
146
  return spawnEditor(resolveEditor(), target);
142
147
  };
143
- //# sourceMappingURL=edit.js.map
@@ -1,6 +1,6 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import { isAbsolute, join, resolve } from 'node:path';
3
- import { ignoredKeysAt, isManagedLayer, policyState } from './layer-policy.js';
3
+ import { ignoredKeysAt, isManagedLayer, isPolicyKey, policyState, } from './layer-policy.js';
4
4
  import { readExistingEnv } from './settings.js';
5
5
  const extensionFor = (codec) => {
6
6
  if (codec.format === 'toml')
@@ -9,12 +9,32 @@ const extensionFor = (codec) => {
9
9
  return '.env';
10
10
  return '.json';
11
11
  };
12
- const scanFile = async (layer, path, codec) => {
12
+ const managedFactsOf = async (path, unitClaim) => {
13
+ let doc;
14
+ try {
15
+ doc = JSON.parse(await fs.readFile(path, 'utf8'));
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ if (doc === null || typeof doc !== 'object' || Array.isArray(doc))
21
+ return undefined;
22
+ const settings = doc;
23
+ const claim = unitClaim?.(settings);
24
+ return {
25
+ hasPolicyKey: Object.keys(settings).some(isPolicyKey),
26
+ ...(claim !== undefined ? { unitClaim: claim } : {}),
27
+ };
28
+ };
29
+ const scanFile = async (layer, path, codec, unitClaim) => {
13
30
  try {
14
31
  const env = await readExistingEnv(path, codec);
15
32
  if (env === null)
16
33
  return { layer, path, status: 'missing', env: {} };
17
- return { layer, path, status: 'present', env };
34
+ const facts = layer.managedSource !== undefined && codec.format === 'json'
35
+ ? await managedFactsOf(path, unitClaim)
36
+ : undefined;
37
+ return { layer, path, status: 'present', env, ...(facts ? { managedFacts: facts } : {}) };
18
38
  }
19
39
  catch (err) {
20
40
  return {
@@ -27,7 +47,7 @@ const scanFile = async (layer, path, codec) => {
27
47
  }
28
48
  };
29
49
  export const dropInNames = (entries, ext = '.json') => entries.filter((e) => e.endsWith(ext) && !e.startsWith('.')).sort();
30
- const scanDir = async (layer, codec) => {
50
+ const scanDir = async (layer, codec, unitClaim) => {
31
51
  let entries;
32
52
  try {
33
53
  entries = await fs.readdir(layer.path);
@@ -50,9 +70,11 @@ const scanDir = async (layer, codec) => {
50
70
  if (matching.length === 0) {
51
71
  return [{ layer, path: layer.path, status: 'missing', env: {} }];
52
72
  }
53
- return Promise.all(matching.map((name) => scanFile(layer, join(layer.path, name), codec)));
73
+ return Promise.all(matching.map((name) => scanFile(layer, join(layer.path, name), codec, unitClaim)));
54
74
  };
55
- const scanLayer = (codec) => async (layer) => layer.kind === 'dir' ? scanDir(layer, codec) : [await scanFile(layer, layer.path, codec)];
75
+ const scanLayer = (codec, unitClaim) => async (layer) => layer.kind === 'dir'
76
+ ? scanDir(layer, codec, unitClaim)
77
+ : [await scanFile(layer, layer.path, codec, unitClaim)];
56
78
  const inactiveLayers = async (adapter, scans) => {
57
79
  if (!adapter.inactiveLayers)
58
80
  return [];
@@ -94,7 +116,7 @@ export const nativeIdentityReason = async (adapter, effective) => {
94
116
  return adapter.nativeIdentityAbsent({ ...process.env, ...flattenEffective(e) }, e.scans.filter((s) => s.status === 'present').map((s) => s.path));
95
117
  };
96
118
  export const computeEffective = async (adapter, policyOverride) => {
97
- const allScans = await Promise.all(adapter.hierarchy.map(scanLayer(adapter.codec)));
119
+ const allScans = await Promise.all(adapter.hierarchy.map(scanLayer(adapter.codec, adapter.managedUnitClaim)));
98
120
  const skip = await inactiveLayers(adapter, allScans.flat());
99
121
  const skipped = adapter.hierarchy.flatMap((layer) => {
100
122
  const reason = skip.find((s) => s.id === layer.id)?.reason;
@@ -105,6 +127,25 @@ export const computeEffective = async (adapter, policyOverride) => {
105
127
  const scans = flat.filter((scan, i) => !flat.slice(i + 1).some((later) => resolve(later.path) === resolve(scan.path)));
106
128
  return { ...effectiveFrom(adapter, scans, policyOverride), skipped };
107
129
  };
130
+ const isManagedSourceScan = (scan) => isManagedLayer(scan.layer) && scan.layer.managedSource !== undefined;
131
+ const managedUnit = (adapter, scans) => {
132
+ const unitKey = adapter.managedUnitKey;
133
+ if (!unitKey)
134
+ return {};
135
+ const managed = scans.filter(isManagedSourceScan);
136
+ const unitSource = managed.find((scan) => Object.keys(scan.env).some((k) => unitKey(k)) || scan.managedFacts?.unitClaim !== undefined)?.layer.managedSource;
137
+ if (unitSource === undefined)
138
+ return {};
139
+ const claiming = managed.find((scan) => scan.layer.managedSource === unitSource && scan.managedFacts?.unitClaim !== undefined);
140
+ const setting = claiming?.managedFacts?.unitClaim;
141
+ if (claiming === undefined || setting === undefined)
142
+ return { unitSource };
143
+ const inEffect = managed.find((scan) => scan.managedFacts?.hasPolicyKey ?? Object.keys(scan.env).length > 0)?.layer.managedSource;
144
+ return { unitSource, unitClaim: { setting, lands: inEffect === unitSource, scan: claiming } };
145
+ };
146
+ export const isManagedUnitDrop = (adapter, { unitSource, unitClaim }, scan, key) => unitSource !== undefined &&
147
+ adapter.managedUnitKey?.(key) === true &&
148
+ (scan.layer.managedSource !== unitSource || unitClaim?.lands === false);
108
149
  export const effectiveFrom = (adapter, scans, policyOverride) => {
109
150
  const ignored = [];
110
151
  if (adapter.layerKeyPolicy) {
@@ -118,16 +159,8 @@ export const effectiveFrom = (adapter, scans, policyOverride) => {
118
159
  (adapter.layerKeyPolicy && ignored.length > 0
119
160
  ? policyState(adapter.layerKeyPolicy)
120
161
  : 'inactive');
121
- const unitKey = adapter.managedUnitKey;
122
- const unitSource = unitKey
123
- ? scans.find((scan) => isManagedLayer(scan.layer) &&
124
- scan.layer.managedSource !== undefined &&
125
- Object.keys(scan.env).some((k) => unitKey(k)))?.layer.managedSource
126
- : undefined;
127
- const droppedInManaged = (scan, key) => unitSource !== undefined &&
128
- unitKey !== undefined &&
129
- unitKey(key) &&
130
- scan.layer.managedSource !== unitSource;
162
+ const { unitSource, unitClaim } = managedUnit(adapter, scans);
163
+ const droppedInManaged = (scan, key) => isManagedUnitDrop(adapter, { unitSource, unitClaim }, scan, key);
131
164
  const managedEnv = {};
132
165
  for (const scan of scans) {
133
166
  if (!isManagedLayer(scan.layer))
@@ -144,7 +177,8 @@ export const effectiveFrom = (adapter, scans, policyOverride) => {
144
177
  for (const scan of scans) {
145
178
  if (isManagedLayer(scan.layer))
146
179
  continue;
147
- const keys = Object.keys(scan.env).filter((k) => !policyIgnores(scan, k) && adapter.managedLock(k, managedEnv));
180
+ const keys = Object.keys(scan.env).filter((k) => !policyIgnores(scan, k) &&
181
+ adapter.managedLock(k, managedEnv, unitClaim?.lands ? unitClaim.setting : undefined));
148
182
  if (keys.length > 0)
149
183
  locked.push({ scan, keys });
150
184
  }
@@ -160,6 +194,13 @@ export const effectiveFrom = (adapter, scans, policyOverride) => {
160
194
  effective[k] = { key: k, value: v, source: scan };
161
195
  }
162
196
  }
163
- return { scans, effective, policy, ignored, unitSource, locked };
197
+ return {
198
+ scans,
199
+ effective,
200
+ policy,
201
+ ignored,
202
+ unitSource,
203
+ ...(unitClaim ? { unitClaim } : {}),
204
+ locked,
205
+ };
164
206
  };
165
- //# sourceMappingURL=effective-settings.js.map
@@ -25,4 +25,3 @@ export const runEnvCommand = async (adapter) => {
25
25
  }
26
26
  return 0;
27
27
  };
28
- //# sourceMappingURL=env-command.js.map
@@ -26,4 +26,3 @@ export class WizardAbort extends Error {
26
26
  this.name = 'WizardAbort';
27
27
  }
28
28
  }
29
- //# sourceMappingURL=errors.js.map
@@ -41,4 +41,3 @@ export const flagBool = ({ flags }, name) => {
41
41
  return value === false ? false : true;
42
42
  };
43
43
  export const hasFlag = ({ flags }, name) => flags.has(name);
44
- //# sourceMappingURL=flags.js.map
@@ -52,4 +52,3 @@ export const renderDiff = (diff) => {
52
52
  return lines.join('\n');
53
53
  };
54
54
  export const color = pc;
55
- //# sourceMappingURL=format.js.map
package/dist/core/git.js CHANGED
@@ -14,4 +14,3 @@ export const detectGitEmail = () => {
14
14
  return undefined;
15
15
  }
16
16
  };
17
- //# sourceMappingURL=git.js.map
@@ -139,4 +139,3 @@ export const redactHeaderCollection = (raw, mask) => {
139
139
  }
140
140
  return undefined;
141
141
  };
142
- //# sourceMappingURL=headers.js.map
@@ -2,17 +2,18 @@ import { basename } from 'node:path';
2
2
  import { hasPath } from './detect.js';
3
3
  import { activeHierarchy } from './effective-settings.js';
4
4
  import { isManagedLayer } from './layer-policy.js';
5
- import { buildHookCommand, hookScriptFiles, installHooksCommand, managedHooksDir, managedMarkerScripts, packagedHooksDir, prepareMarkersFile, readPackagedMatchers, scanForMarkers, scriptPathFromCommand, syncHookScripts, } from './markers.js';
5
+ import { buildHookCommand, installHooksCommand, managedHooksDir, managedMarkerScripts, packagedHooksDir, PAYLOAD_CLI_SPEC, prepareMarkersFile, readPackagedMatchers, scanForMarkers, scriptPathFromCommand, syncManagedHooks, } from './markers.js';
6
6
  import { applyUpdate } from './settings.js';
7
+ import { VERSION } from './version.js';
7
8
  const PAYLOAD_HOOKS_DIR = '$HOME/.mainwave/hooks/managed';
8
- export const managedPayloadHooks = (matchers, version) => ({
9
+ export const managedPayloadHooks = (matchers) => ({
9
10
  SessionStart: [
10
11
  {
11
12
  matcher: 'startup|resume',
12
13
  hooks: [
13
14
  {
14
15
  type: 'command',
15
- command: installHooksCommand(version),
16
+ command: installHooksCommand(PAYLOAD_CLI_SPEC),
16
17
  async: true,
17
18
  },
18
19
  ],
@@ -23,7 +24,7 @@ export const managedPayloadHooks = (matchers, version) => ({
23
24
  hooks: [
24
25
  {
25
26
  type: 'command',
26
- command: buildHookCommand(`${PAYLOAD_HOOKS_DIR}/${m.hook}`, version, 'darwin'),
27
+ command: buildHookCommand(`${PAYLOAD_HOOKS_DIR}/${m.hook}`, PAYLOAD_CLI_SPEC, 'darwin'),
27
28
  timeout: 5,
28
29
  },
29
30
  ],
@@ -35,7 +36,7 @@ const defaultPaths = () => ({
35
36
  });
36
37
  export const installHooks = async (adapter, paths = defaultPaths()) => {
37
38
  const matchers = await readPackagedMatchers(paths.srcDir);
38
- const updated = await syncHookScripts(hookScriptFiles(matchers), paths.srcDir, paths.destDir);
39
+ const updated = await syncManagedHooks(matchers, paths.srcDir, paths.destDir, paths.version ?? VERSION);
39
40
  const managedLayers = (await activeHierarchy(adapter)).filter(isManagedLayer);
40
41
  const delivered = managedMarkerScripts(await scanForMarkers(managedLayers));
41
42
  const managedDelivers = delivered.size > 0;
@@ -78,4 +79,3 @@ export const runInstallHooks = async (adapter, options = {}, paths) => {
78
79
  }
79
80
  return 0;
80
81
  };
81
- //# sourceMappingURL=install-hooks.js.map
@@ -145,4 +145,3 @@ export const runInterview = async (input) => {
145
145
  useCase,
146
146
  };
147
147
  };
148
- //# sourceMappingURL=interview.js.map
package/dist/core/keys.js CHANGED
@@ -20,4 +20,3 @@ export const ensureDeveloperKey = async (input) => {
20
20
  say(color.green(`✓ Minted a Mainwave key for this machine (${label}).`));
21
21
  return created.key;
22
22
  };
23
- //# sourceMappingURL=keys.js.map
@@ -29,6 +29,7 @@ export const ignoredKeysAt = (policy, layerId, env) => policy.layers.includes(la
29
29
  .filter(([k, v]) => policy.ignores(k, v))
30
30
  .map(([k]) => k)
31
31
  : [];
32
+ const NON_POLICY_KEYS = new Set(['wslInheritsWindowsSettings', 'managedSourcesBehavior']);
33
+ export const isPolicyKey = (key) => !NON_POLICY_KEYS.has(key);
32
34
  export const isManagedLayer = (layer) => layer.managedSource !== undefined || layer.id === 'managed';
33
35
  export const isManagedIdentityConfig = (attrs) => /(^|,)\s*mainwave\.source=coding_agent\./.test(attrs ?? '');
34
- //# sourceMappingURL=layer-policy.js.map