@mainwave/cli 0.7.1 → 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 +4 -1
  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 +3 -3
  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 +170 -15
  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
@@ -1,9 +1,10 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { existsSync, promises as fs } from 'node:fs';
2
3
  import { homedir } from 'node:os';
3
- import { basename, join, resolve } from 'node:path';
4
+ import { basename, dirname, join, resolve } from 'node:path';
4
5
  import { fileURLToPath } from 'node:url';
5
6
  import { dropInNames } from './effective-settings.js';
6
- import { isManagedLayer } from './layer-policy.js';
7
+ import { isManagedLayer, isPolicyKey } from './layer-policy.js';
7
8
  export const MANAGED_BY = '--managed-by @mainwave/cli';
8
9
  export const PAYLOAD_CLI_SPEC = 'latest';
9
10
  const OWNED_CLI_MARKERS = [MANAGED_BY, '.mainwave/hooks', '.mainwave\\hooks'];
@@ -61,21 +62,167 @@ export const copyHookScripts = async (files, srcDir = packagedHooksDir(), destDi
61
62
  }
62
63
  return destDir;
63
64
  };
64
- export const syncHookScripts = async (files, srcDir = packagedHooksDir(), destDir = installedHooksDir()) => {
65
- await fs.mkdir(destDir, { recursive: true });
65
+ export const MANAGED_POINTER = 'current.json';
66
+ export const MANAGED_VERSIONS_DIR = 'versions';
67
+ export const MANAGED_ENTRY_SCRIPT = 'managed-entry.mjs';
68
+ const MANAGED_ENTRY_MARK = 'mainwave managed hook entry';
69
+ const RETIRED_GRACE_MS = 10 * 60 * 1000;
70
+ const VERSION_DIR_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
71
+ const versionDirName = (version, files, bodies) => {
72
+ const hash = createHash('sha256');
73
+ files.forEach((f, i) => hash.update(f).update('\0').update(bodies[i]).update('\0'));
74
+ const safe = version.replace(/[^A-Za-z0-9._+-]/g, '_').replace(/^[^A-Za-z0-9]+/, '');
75
+ return `${safe || 'v'}-${hash.digest('hex').slice(0, 12)}`;
76
+ };
77
+ const holdsFiles = async (dir, files, bodies) => {
78
+ for (const [i, f] of files.entries()) {
79
+ const current = await fs.readFile(join(dir, f)).catch(() => null);
80
+ if (current === null || !current.equals(bodies[i]))
81
+ return false;
82
+ }
83
+ return true;
84
+ };
85
+ const writeAtomic = async (path, body, mode = 0o644) => {
86
+ const tmp = `${path}.tmp.${process.pid}.${Math.random().toString(36).slice(2)}`;
87
+ await fs.writeFile(tmp, body, { mode });
88
+ await fs.rename(tmp, path);
89
+ };
90
+ export const readManagedPointer = async (destDir) => {
91
+ try {
92
+ const { dir } = JSON.parse(await fs.readFile(join(destDir, MANAGED_POINTER), 'utf8'));
93
+ return typeof dir === 'string' && VERSION_DIR_RE.test(dir) ? dir : undefined;
94
+ }
95
+ catch {
96
+ return undefined;
97
+ }
98
+ };
99
+ export const stageManagedVersion = async (files, srcDir, destDir, version) => {
100
+ const bodies = await Promise.all(files.map((f) => fs.readFile(join(srcDir, f))));
101
+ const id = versionDirName(version, files, bodies);
102
+ const versionsDir = join(destDir, MANAGED_VERSIONS_DIR);
103
+ await fs.mkdir(versionsDir, { recursive: true });
104
+ const final = join(versionsDir, id);
105
+ const staged = { id, version, files, bodies };
106
+ if (await holdsFiles(final, files, bodies)) {
107
+ if ((await readManagedPointer(destDir)) !== id) {
108
+ const now = new Date();
109
+ await fs.utimes(final, now, now).catch(() => undefined);
110
+ }
111
+ return { ...staged, written: false };
112
+ }
113
+ const tmp = await fs.mkdtemp(join(versionsDir, `.staging-${id}-`));
114
+ try {
115
+ for (const [i, f] of files.entries()) {
116
+ await fs.writeFile(join(tmp, f), bodies[i], { mode: 0o644 });
117
+ }
118
+ await fs.chmod(tmp, 0o755);
119
+ try {
120
+ await fs.rename(tmp, final);
121
+ }
122
+ catch (err) {
123
+ if (await holdsFiles(final, files, bodies)) {
124
+ await fs.rm(tmp, { recursive: true, force: true });
125
+ return { ...staged, written: false };
126
+ }
127
+ if (!(await moveAside(versionsDir, id)))
128
+ throw err;
129
+ await fs.rename(tmp, final);
130
+ }
131
+ }
132
+ catch (err) {
133
+ await fs.rm(tmp, { recursive: true, force: true });
134
+ if (await holdsFiles(final, files, bodies))
135
+ return { ...staged, written: false };
136
+ throw err;
137
+ }
138
+ return { ...staged, written: true };
139
+ };
140
+ const moveAside = async (versionsDir, id) => {
141
+ const aside = join(versionsDir, `.stale-${id}-${Math.random().toString(36).slice(2)}`);
142
+ try {
143
+ await fs.rename(join(versionsDir, id), aside);
144
+ }
145
+ catch (err) {
146
+ return isMissing(err);
147
+ }
148
+ const now = new Date();
149
+ await fs.utimes(aside, now, now).catch(() => undefined);
150
+ return true;
151
+ };
152
+ const isMissing = (err) => err?.code === 'ENOENT';
153
+ const stagedIntact = async (destDir, staged) => holdsFiles(join(destDir, MANAGED_VERSIONS_DIR, staged.id), staged.files, staged.bodies);
154
+ export const commitManagedVersion = async (staged, hookNames, srcDir, destDir) => {
66
155
  const updated = [];
67
- for (const f of files) {
68
- const body = await fs.readFile(join(srcDir, f));
69
- const current = await fs.readFile(join(destDir, f)).catch(() => null);
70
- if (current !== null && current.equals(body))
156
+ const previous = await readManagedPointer(destDir);
157
+ if (previous !== staged.id) {
158
+ await writeAtomic(join(destDir, MANAGED_POINTER), `${JSON.stringify({ dir: staged.id, version: staged.version })}\n`);
159
+ updated.push(MANAGED_POINTER);
160
+ if (previous !== undefined) {
161
+ const now = new Date();
162
+ await fs
163
+ .utimes(join(destDir, MANAGED_VERSIONS_DIR, previous), now, now)
164
+ .catch(() => undefined);
165
+ }
166
+ }
167
+ const entry = await fs.readFile(join(srcDir, MANAGED_ENTRY_SCRIPT));
168
+ for (const name of hookNames) {
169
+ const current = await fs.readFile(join(destDir, name)).catch(() => null);
170
+ if (current !== null && current.equals(entry))
71
171
  continue;
72
- const tmp = join(destDir, `.${f}.tmp.${process.pid}`);
73
- await fs.writeFile(tmp, body, { mode: 0o644 });
74
- await fs.rename(tmp, join(destDir, f));
75
- updated.push(f);
172
+ await writeAtomic(join(destDir, name), entry);
173
+ updated.push(name);
76
174
  }
77
175
  return updated;
78
176
  };
177
+ const pruneManagedVersions = async (destDir, keep) => {
178
+ const versionsDir = join(destDir, MANAGED_VERSIONS_DIR);
179
+ const current = await readManagedPointer(destDir);
180
+ const entries = await fs.readdir(versionsDir).catch(() => []);
181
+ const now = Date.now();
182
+ for (const name of entries) {
183
+ if (name === current || name === keep)
184
+ continue;
185
+ const path = join(versionsDir, name);
186
+ const stat = await fs.stat(path).catch(() => null);
187
+ if (stat === null || now - stat.mtimeMs < RETIRED_GRACE_MS)
188
+ continue;
189
+ if ((await readManagedPointer(destDir)) === name)
190
+ continue;
191
+ await fs.rm(path, { recursive: true, force: true }).catch(() => undefined);
192
+ }
193
+ };
194
+ export const syncManagedHooks = async (matchers, srcDir, destDir, version) => {
195
+ const files = hookScriptFiles(matchers);
196
+ const hookNames = matchers.map((m) => m.hook);
197
+ const staged = await stageManagedVersion(files, srcDir, destDir, version);
198
+ const updated = await commitManagedVersion(staged, hookNames, srcDir, destDir);
199
+ if (!(await stagedIntact(destDir, staged))) {
200
+ const again = await stageManagedVersion(files, srcDir, destDir, version);
201
+ updated.push(...(await commitManagedVersion(again, hookNames, srcDir, destDir)));
202
+ if (!(await stagedIntact(destDir, again))) {
203
+ throw new Error(`could not install a complete set of hook scripts in ${destDir}`);
204
+ }
205
+ }
206
+ await pruneManagedVersions(destDir, staged.id);
207
+ return [
208
+ ...new Set([
209
+ ...(staged.written ? files.map((f) => `${MANAGED_VERSIONS_DIR}/${staged.id}/${f}`) : []),
210
+ ...updated,
211
+ ]),
212
+ ];
213
+ };
214
+ export const resolveManagedScript = async (script) => {
215
+ const body = await fs.readFile(script, 'utf8').catch(() => null);
216
+ if (body === null)
217
+ return undefined;
218
+ if (!body.includes(MANAGED_ENTRY_MARK))
219
+ return script;
220
+ const dir = await readManagedPointer(dirname(script));
221
+ if (dir === undefined)
222
+ return undefined;
223
+ const target = join(dirname(script), MANAGED_VERSIONS_DIR, dir, basename(script));
224
+ return existsSync(target) ? target : undefined;
225
+ };
79
226
  export const buildHookCommand = (scriptPath, version, plat = process.platform, runtimeTool) => {
80
227
  const toolArg = runtimeTool ? ` --tool ${runtimeTool}` : '';
81
228
  return plat === 'win32'
@@ -224,7 +371,6 @@ export const markerLogFiles = () => [
224
371
  { label: 'Jira tickets', path: join(homedir(), '.mainwave-jira-ticket-marker.log') },
225
372
  { label: 'PRs', path: join(homedir(), '.mainwave-pr-marker.log') },
226
373
  ];
227
- const NON_POLICY_KEYS = new Set(['wslInheritsWindowsSettings', 'managedSourcesBehavior']);
228
374
  const managedLockValue = (v) => {
229
375
  if (v === undefined || v === null)
230
376
  return undefined;
@@ -258,7 +404,7 @@ export const scanForMarkers = async (layers) => {
258
404
  layerId: layer.id,
259
405
  label: layer.label ?? layer.id,
260
406
  groups: ownedGroupsInDoc(doc),
261
- hasPolicyKey: Object.keys(doc).some((k) => !NON_POLICY_KEYS.has(k)),
407
+ hasPolicyKey: Object.keys(doc).some(isPolicyKey),
262
408
  managed: isManagedLayer(layer),
263
409
  managedSource: layer.managedSource,
264
410
  mergeSources: doc.managedSourcesBehavior === 'merge',
@@ -417,6 +563,16 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
417
563
  if (script !== undefined) {
418
564
  try {
419
565
  await fs.access(script);
566
+ if (g.managed && (await resolveManagedScript(script)) === undefined) {
567
+ issues.push({
568
+ level: 'error',
569
+ message: `Marker hook ${basename(script)} in ${dirname(script)} names no installed release ` +
570
+ `(${MANAGED_POINTER} is missing, or its release lacks the script), so it sends nothing. ` +
571
+ 'Start a new Claude Code session, or ' +
572
+ (process.platform === 'win32' ? 'in Git Bash run ' : 'run ') +
573
+ `\`${installHooksCommand(version ?? PAYLOAD_CLI_SPEC, { quiet: false })}\`.`,
574
+ });
575
+ }
420
576
  }
421
577
  catch {
422
578
  issues.push({
@@ -461,4 +617,3 @@ export const collectMarkerIssues = async (scans, currentVersion, matchers, skipp
461
617
  }
462
618
  return issues;
463
619
  };
464
- //# sourceMappingURL=markers.js.map
@@ -8,4 +8,3 @@ export const pinnedUseCase = async (settings, targets = adapterNames().map((n) =
8
8
  const effective = await Promise.all(developerTools.map(adapterEffective));
9
9
  return effective.some((e) => e.ucid === stored.id) ? stored : undefined;
10
10
  };
11
- //# sourceMappingURL=pinned-use-case.js.map
@@ -129,4 +129,3 @@ export const tokenExpiry = (token) => {
129
129
  return undefined;
130
130
  }
131
131
  };
132
- //# sourceMappingURL=platform.js.map
@@ -69,4 +69,3 @@ export const renderEnvFileBlock = (envFile, scope) => {
69
69
  indent(color.cyan(`source_env ${envFile}`)),
70
70
  ].join('\n');
71
71
  };
72
- //# sourceMappingURL=post-setup.js.map
@@ -76,4 +76,3 @@ export const promptConfirmWrite = async () => confirm({
76
76
  message: 'Write file?',
77
77
  default: true,
78
78
  });
79
- //# sourceMappingURL=prompts.js.map
@@ -1,5 +1,19 @@
1
- import { constants as fsConstants, promises as fs } from 'node:fs';
2
- import { dirname } from 'node:path';
1
+ import { constants as fsConstants, promises as fs, realpathSync } from 'node:fs';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
+ const realOrResolved = (path) => {
4
+ try {
5
+ return realpathSync(path);
6
+ }
7
+ catch {
8
+ try {
9
+ return join(realpathSync(dirname(path)), basename(path));
10
+ }
11
+ catch {
12
+ return resolve(path);
13
+ }
14
+ }
15
+ };
16
+ export const isSamePath = (a, b) => realOrResolved(a) === realOrResolved(b);
3
17
  export const isErrnoCode = (err, code) => typeof err === 'object' && err !== null && err.code === code;
4
18
  const readFileOrNull = async (path) => {
5
19
  try {
@@ -84,4 +98,3 @@ export const applyUpdate = async (update) => {
84
98
  }
85
99
  return { backupPath, written: path };
86
100
  };
87
- //# sourceMappingURL=settings.js.map
@@ -4,7 +4,11 @@ import { dirname, join } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  export const BLOCK_OPEN = '<!-- mainwave:skills managed-by @mainwave/cli';
6
6
  export const BLOCK_CLOSE = '<!-- /mainwave:skills -->';
7
- export const SKILL_NAMES = ['mainwave-setup', 'mainwave-instrument'];
7
+ export const SKILL_NAMES = [
8
+ 'mainwave-setup',
9
+ 'mainwave-instrument',
10
+ 'mainwave-instrument-node',
11
+ ];
8
12
  export const packagedSkillsDir = () => fileURLToPath(new URL('../../skills/', import.meta.url));
9
13
  export const installedSkillsDir = () => join(homedir(), '.mainwave', 'skills');
10
14
  export const copySkillBundle = async (name, srcRoot = packagedSkillsDir(), destRoot = installedSkillsDir()) => {
@@ -125,4 +129,3 @@ export const installSkillsPayload = async (adapters, version, srcRoot = packaged
125
129
  }
126
130
  return { installs, noOps, bundleDir: join(installedRoot) };
127
131
  };
128
- //# sourceMappingURL=skills.js.map
@@ -40,7 +40,9 @@ const fileRowsFor = (adapter) => {
40
40
  : adapter.hierarchy.find((l) => l.path === adapter.paths.local)?.id;
41
41
  const rows = [
42
42
  { label: 'Global', path: adapter.paths.global, codec: adapter.codec, parse: primaryParse },
43
- {
43
+ ];
44
+ if (adapter.paths.localIgnored === undefined) {
45
+ rows.push({
44
46
  label: 'Local',
45
47
  path: adapter.paths.local,
46
48
  codec: adapter.codec,
@@ -54,8 +56,8 @@ const fileRowsFor = (adapter) => {
54
56
  },
55
57
  }
56
58
  : {}),
57
- },
58
- ];
59
+ });
60
+ }
59
61
  for (const aw of adapter.additionalWrites ?? []) {
60
62
  rows.push(...additionalRowsFor(aw));
61
63
  }
@@ -269,4 +271,3 @@ export const runStatus = async (adapter, options = {}) => {
269
271
  }
270
272
  return 0;
271
273
  };
272
- //# sourceMappingURL=status.js.map
@@ -85,4 +85,3 @@ export const resolveEndpoints = (settings, overrides = {}, env = process.env) =>
85
85
  settings.collectorUrl ??
86
86
  DEFAULTS.collectorUrl),
87
87
  });
88
- //# sourceMappingURL=store.js.map
package/dist/core/tty.js CHANGED
@@ -5,4 +5,3 @@ export const ensureTty = () => {
5
5
  }
6
6
  };
7
7
  export const isInteractive = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
8
- //# sourceMappingURL=tty.js.map
package/dist/core/ucid.js CHANGED
@@ -9,4 +9,3 @@ export const parseUcid = (value) => {
9
9
  const match = EMBEDDED_UUID_RE.exec(trimmed);
10
10
  return match?.[1]?.toLowerCase();
11
11
  };
12
- //# sourceMappingURL=ucid.js.map
package/dist/core/ui.js CHANGED
@@ -12,4 +12,3 @@ export const say = (...args) => {
12
12
  export const emitJson = (value) => {
13
13
  console.log(JSON.stringify(value, null, 2));
14
14
  };
15
- //# sourceMappingURL=ui.js.map
@@ -25,4 +25,3 @@ const findOrCreate = async (context, name) => {
25
25
  const created = await createUseCase(context.apiUrl, context.token, { name });
26
26
  return { id: created.id, name: created.name };
27
27
  };
28
- //# sourceMappingURL=use-case.js.map
@@ -55,4 +55,3 @@ const readIdentity = async (response) => {
55
55
  orgName: typeof orgName === 'string' && orgName !== '' ? orgName : undefined,
56
56
  };
57
57
  };
58
- //# sourceMappingURL=validate.js.map
@@ -169,4 +169,3 @@ export const runVerify = async (options = {}) => {
169
169
  say(` ${color.dim(link)}`);
170
170
  return 1;
171
171
  };
172
- //# sourceMappingURL=verify.js.map
@@ -2,4 +2,3 @@ import { readFileSync } from 'node:fs';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  const pkgPath = fileURLToPath(new URL('../../package.json', import.meta.url));
4
4
  export const VERSION = JSON.parse(readFileSync(pkgPath, 'utf8')).version;
5
- //# sourceMappingURL=version.js.map
@@ -1,7 +1,7 @@
1
1
  import { select } from '@inquirer/prompts';
2
2
  import { mergePrefills, planAdapter, planHasChanges, printMarkerCoexistenceNotes, printPostSetup, readPrefill, renderPlan, writePlan, } from './apply.js';
3
3
  import { runLogin } from './auth-commands.js';
4
- import { computeEffective, nativeIdentityReason } from './effective-settings.js';
4
+ import { computeEffective, isManagedUnitDrop, nativeIdentityReason } from './effective-settings.js';
5
5
  import { isManagedIdentityConfig, isManagedLayer } from './layer-policy.js';
6
6
  import { PlatformError, ValidateError, WizardAbort } from './errors.js';
7
7
  import { color } from './format.js';
@@ -62,12 +62,9 @@ export const shadowWarning = (effective, plan, surfaceUcid) => {
62
62
  return null;
63
63
  const writtenEnv = adapter.buildEnv(plan.input);
64
64
  const applied = (s) => Object.fromEntries(Object.entries(s.env).filter(([k]) => !(effective.policy === 'active' &&
65
- effective.ignored.some((i) => i.scan === s && i.keys.includes(k))) &&
66
- !(effective.unitSource !== undefined &&
67
- adapter.managedUnitKey?.(k) === true &&
68
- s.layer.managedSource !== effective.unitSource)));
65
+ effective.ignored.some((i) => i.scan === s && i.keys.includes(k))) && !isManagedUnitDrop(adapter, effective, s, k)));
69
66
  const unlocked = (s) => adapter.managedLock && isManagedLayer(s.layer)
70
- ? Object.fromEntries(Object.entries(writtenEnv).filter(([k]) => !adapter.managedLock(k, applied(s))))
67
+ ? Object.fromEntries(Object.entries(writtenEnv).filter(([k]) => !adapter.managedLock(k, applied(s), effective.unitClaim?.lands ? effective.unitClaim.setting : undefined)))
71
68
  : writtenEnv;
72
69
  const writtenIdx = effective.scans.findIndex((s) => s.path === plan.primaryPath);
73
70
  const above = effective.scans.slice(0, writtenIdx < 0 ? 0 : writtenIdx);
@@ -463,4 +460,3 @@ const printPostSetupTips = (adapters) => {
463
460
  ' invocations have time to flush spans before exit.'));
464
461
  }
465
462
  };
466
- //# sourceMappingURL=wizard.js.map
package/dist/main.js CHANGED
@@ -330,4 +330,3 @@ export const main = async (argv) => {
330
330
  printError(`unknown command: ${cmd}`);
331
331
  return 1;
332
332
  };
333
- //# sourceMappingURL=main.js.map
@@ -12,7 +12,9 @@
12
12
  // Unlike the Claude Code / Codex marker hooks, Cursor exposes no config file we
13
13
  // can read the collector endpoint + auth back out of — so setup writes a
14
14
  // managed env file (`~/.mainwave/cursor.env`, mode 0600) and this script reads
15
- // its OTLP config from there (project-local `.mainwave/cursor.env` overrides).
15
+ // its OTLP config from there. Only from there: a `.mainwave/cursor.env` in the
16
+ // workspace comes with the repository, and a repository mustn't choose where
17
+ // the developer's key is sent.
16
18
  // Tenancy (ucid, source) comes from that file; the developer identity
17
19
  // (`user_email`) rides in on Cursor's own per-event payload.
18
20
  //
@@ -30,13 +32,13 @@ import {
30
32
  bearerFromHeaders,
31
33
  buildMarkerPayload,
32
34
  emitMarker,
33
- makeLog,
35
+ markerLog,
34
36
  parseKv,
35
37
  readStdin,
36
38
  } from './marker-core.mjs'
37
39
  import { ATTR_CODE_FILE_PATH } from './vocabulary.mjs'
38
40
 
39
- const log = makeLog(process.env.MAINWAVE_HOOK_LOG || join(homedir(), '.mainwave-cursor.log'))
41
+ const log = markerLog(process.argv, '.mainwave-cursor.log')
40
42
 
41
43
  // Classified by the collector as a coding agent via `mainwave.source`; the
42
44
  // service name matches Cursor's own native-export resource (`service.name=cursor`)
@@ -85,18 +87,14 @@ const readFileSafe = (path) => {
85
87
  }
86
88
 
87
89
  /**
88
- * OTLP config from the managed env file(s), project-local layered over global
89
- * so a repo-scoped `mainwave-cli setup cursor` wins for that checkout. Missing
90
- * values → undefined and the emit is skipped (fail-open), never a broken post.
90
+ * OTLP config from the developer's own `~/.mainwave/cursor.env`. A workspace's
91
+ * `.mainwave/cursor.env` is never read: merged over this one key by key, a
92
+ * repository that set only the endpoint would receive the developer's real
93
+ * key. Missing values → undefined and the emit is skipped (fail-open), never a
94
+ * broken post.
91
95
  */
92
- export const loadCursorConfig = (cwd, readFile = readFileSafe) => {
93
- const merged = {}
94
- for (const p of [
95
- join(homedir(), '.mainwave', 'cursor.env'),
96
- join(cwd, '.mainwave', 'cursor.env'),
97
- ]) {
98
- Object.assign(merged, parseEnvFile(readFile(p)))
99
- }
96
+ export const loadCursorConfig = (readFile = readFileSafe) => {
97
+ const merged = parseEnvFile(readFile(join(homedir(), '.mainwave', 'cursor.env')))
100
98
  const headers = parseKv(merged.OTEL_EXPORTER_OTLP_HEADERS)
101
99
  const ucid = headers['X-Mainwave-UCID']
102
100
  // The hook POSTs tenancy on the span RESOURCE, not as X-Mainwave-* headers, so
@@ -206,7 +204,7 @@ const main = async () => {
206
204
  process.exit(0)
207
205
  }
208
206
 
209
- const config = loadCursorConfig(process.cwd())
207
+ const config = loadCursorConfig()
210
208
  if (!config.endpoint || !config.bearer) {
211
209
  log(`skip ${payload?.hook_event_name}: no endpoint/auth in ~/.mainwave/cursor.env`)
212
210
  process.exit(0)
@@ -18,20 +18,21 @@
18
18
  // fast otherwise, so it can never block or slow the session.
19
19
 
20
20
  import { execFile } from 'node:child_process'
21
- import { homedir } from 'node:os'
22
- import { join } from 'node:path'
23
21
  import { pathToFileURL } from 'node:url'
24
22
 
25
23
  import {
26
24
  buildMarkerPayload,
27
25
  markerOauthAccount,
26
+ markerSessionEnv,
28
27
  emitMarker,
28
+ hookFlag,
29
29
  loadOtelConfig,
30
30
  markerCallContext,
31
31
  markerHostSource,
32
32
  markerManagedDir,
33
+ markerProjectDir,
33
34
  markerTool,
34
- makeLog,
35
+ markerLog,
35
36
  payloadShape,
36
37
  readStdin,
37
38
  toolOutput,
@@ -51,7 +52,7 @@ import {
51
52
  // Re-export the shared output-reading helpers so the tests can import them here.
52
53
  export { payloadShape, toolOutput } from './marker-core.mjs'
53
54
 
54
- const log = makeLog(process.env.MAINWAVE_HOOK_LOG || join(homedir(), '.mainwave-pr-marker.log'))
55
+ const log = markerLog(process.argv, '.mainwave-pr-marker.log')
55
56
 
56
57
  // Non-coding source/service so the marker lands as an ordinary span and stays
57
58
  // out of the coding-work segmentation, same as the ticket marker.
@@ -112,13 +113,15 @@ export const parsePrStats = (stdout) => {
112
113
  * The opened PR's aggregate diff counts, via `gh pr view <number> --json ...`.
113
114
  * Fail-open: resolves `{}` on any error (gh absent, unauthenticated, timeout,
114
115
  * bad output) so a marker still emits without the stats — never blocks the
115
- * session. `MAINWAVE_GH_BIN` overrides the `gh` binary (a nonstandard install,
116
- * or a stub in tests). Only the three integer counts are read — never the diff.
116
+ * session. `bin` replaces `gh`; `main` takes it only from the hook's own
117
+ * `--gh-bin` flag (tests pass a stub), never from the environment, because a
118
+ * repository's project settings `env` reaches the hook and this runs with the
119
+ * repository as its working directory (§ `hookFlag`). Only the three integer
120
+ * counts are read — never the diff.
117
121
  */
118
- export const fetchPrStats = (number, { cwd, timeoutMs = 5000 } = {}) =>
122
+ export const fetchPrStats = (number, { cwd, bin = 'gh', timeoutMs = 5000 } = {}) =>
119
123
  new Promise((resolve) => {
120
124
  if (!number) return resolve({})
121
- const bin = process.env.MAINWAVE_GH_BIN || 'gh'
122
125
  execFile(
123
126
  bin,
124
127
  ['pr', 'view', String(number), '--json', 'changedFiles,additions,deletions'],
@@ -197,9 +200,11 @@ const main = async () => {
197
200
  const title = extractPrTitle(command)
198
201
 
199
202
  const cwd = payload.cwd || process.cwd()
203
+ const projectDir = markerProjectDir(payload)
200
204
  const tool = markerTool(process.argv)
201
205
  const managedDir = markerManagedDir(process.argv)
202
- const { endpoint, bearer, resourceAttrs } = loadOtelConfig(cwd, process.env, tool, managedDir)
206
+ const env = markerSessionEnv(tool, payload)
207
+ const { endpoint, bearer, resourceAttrs } = loadOtelConfig(projectDir, env, tool, managedDir)
203
208
  log(
204
209
  `pr=${number} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
205
210
  `bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
@@ -210,13 +215,19 @@ const main = async () => {
210
215
  }
211
216
  // Read only once the emit is certain: `.claude.json` can run to megabytes.
212
217
  const { email: userEmail, accountUuid: userAccountUuid } = markerOauthAccount(tool, {
213
- cwd,
218
+ cwd: projectDir,
219
+ env,
214
220
  managedDir,
215
221
  })
216
222
 
217
223
  // Diff counts are best-effort: the marker still emits (with the link) if gh is
218
224
  // unavailable or the fetch fails, so this never blocks the PR from surfacing.
219
- const { changedFiles, additions, deletions } = await fetchPrStats(number, { cwd })
225
+ // gh runs where the agent ran `gh pr create`: that directory names the PR's
226
+ // repository.
227
+ const { changedFiles, additions, deletions } = await fetchPrStats(number, {
228
+ cwd,
229
+ bin: hookFlag(process.argv, '--gh-bin'),
230
+ })
220
231
  log(
221
232
  `stats changed_files=${changedFiles ?? 'na'} additions=${additions ?? 'na'} ` +
222
233
  `deletions=${deletions ?? 'na'}`,
@@ -27,20 +27,20 @@
27
27
  // wrongly assuming a hook couldn't produce it). Fails open and fast so a
28
28
  // telemetry hiccup can never block or slow the session.
29
29
 
30
- import { homedir } from 'node:os'
31
- import { join } from 'node:path'
32
30
  import { pathToFileURL } from 'node:url'
33
31
 
34
32
  import {
35
33
  buildMarkerPayload,
36
34
  markerOauthAccount,
35
+ markerSessionEnv,
37
36
  emitMarker,
38
37
  loadOtelConfig,
39
38
  markerCallContext,
40
39
  markerHostSource,
41
40
  markerManagedDir,
41
+ markerProjectDir,
42
42
  markerTool,
43
- makeLog,
43
+ markerLog,
44
44
  payloadShape,
45
45
  readStdin,
46
46
  toolOutput,
@@ -58,9 +58,7 @@ import {
58
58
  WORK_OP_UPDATED,
59
59
  } from './vocabulary.mjs'
60
60
 
61
- const log = makeLog(
62
- process.env.MAINWAVE_HOOK_LOG || join(homedir(), '.mainwave-jira-ticket-marker.log'),
63
- )
61
+ const log = markerLog(process.argv, '.mainwave-jira-ticket-marker.log')
64
62
 
65
63
  // The same non-coding source/service the Linear ticket hook stamps, so a Jira
66
64
  // marker is classified identically to a Linear one: an ordinary ("other") span
@@ -215,10 +213,11 @@ const main = async () => {
215
213
  const instance = extractInstance(output)
216
214
  const op = detectOp(payload.tool_name)
217
215
 
218
- const cwd = payload.cwd || process.cwd()
216
+ const projectDir = markerProjectDir(payload)
219
217
  const tool = markerTool(process.argv)
220
218
  const managedDir = markerManagedDir(process.argv)
221
- const { endpoint, bearer, resourceAttrs } = loadOtelConfig(cwd, process.env, tool, managedDir)
219
+ const env = markerSessionEnv(tool, payload)
220
+ const { endpoint, bearer, resourceAttrs } = loadOtelConfig(projectDir, env, tool, managedDir)
222
221
  log(
223
222
  `issue=${issueKey} op=${op} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
224
223
  `bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
@@ -229,7 +228,8 @@ const main = async () => {
229
228
  }
230
229
  // Read only once the emit is certain: `.claude.json` can run to megabytes.
231
230
  const { email: userEmail, accountUuid: userAccountUuid } = markerOauthAccount(tool, {
232
- cwd,
231
+ cwd: projectDir,
232
+ env,
233
233
  managedDir,
234
234
  })
235
235