@mainwave/cli 0.7.1 → 0.9.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 +141 -42
- package/dist/adapters/claude-code.js +33 -7
- package/dist/adapters/claude-desktop.js +0 -1
- package/dist/adapters/codex-cli.js +1 -2
- 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 +15 -4
- 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 +151 -42
- 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 +45 -9
- package/dist/core/edit.js +9 -5
- package/dist/core/effective-settings.js +71 -20
- package/dist/core/entry-script.js +90 -0
- 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-bash.js +40 -0
- package/dist/core/git.js +0 -1
- package/dist/core/headers.js +0 -1
- package/dist/core/install-hooks.js +127 -44
- package/dist/core/interview.js +53 -4
- package/dist/core/keys.js +0 -1
- package/dist/core/layer-policy.js +2 -1
- package/dist/core/markers.js +826 -133
- 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 +32 -8
- package/dist/core/skills.js +5 -2
- package/dist/core/status.js +7 -5
- 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 +49 -8
- package/dist/main.js +16 -10
- package/hooks/cursor-otlp.mjs +13 -15
- package/hooks/github-pr-marker.mjs +55 -31
- package/hooks/glab-mr-marker.mjs +795 -0
- package/hooks/jira-ticket-marker.mjs +35 -23
- package/hooks/linear-ticket-marker.mjs +35 -21
- package/hooks/mainwave-hook-node.mjs +42 -0
- package/hooks/mainwave-hook.mjs +301 -0
- package/hooks/managed-entry.mjs +42 -0
- package/hooks/marker-core.mjs +389 -62
- package/hooks/matchers.json +82 -6
- package/hooks/plan-snapshot.mjs +529 -0
- package/hooks/stop-failure.mjs +43 -0
- package/hooks/vocabulary.d.mts +48 -0
- package/hooks/vocabulary.mjs +181 -0
- package/package.json +6 -5
- package/skills/mainwave-instrument/SKILL.md +21 -7
- package/skills/mainwave-instrument/reference/api.md +29 -10
- package/skills/mainwave-instrument/reference/frameworks.md +3 -3
- package/skills/mainwave-instrument/reference/troubleshooting.md +12 -5
- 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/skills/mainwave-setup/SKILL.md +47 -12
- 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
|
@@ -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
|
package/dist/core/platform.js
CHANGED
package/dist/core/post-setup.js
CHANGED
package/dist/core/prompts.js
CHANGED
package/dist/core/settings.js
CHANGED
|
@@ -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 {
|
|
@@ -36,6 +50,20 @@ const diffEnv = (before, after, managedKeys) => {
|
|
|
36
50
|
const pad2 = (n) => String(n).padStart(2, '0');
|
|
37
51
|
const timestamp = (d = new Date()) => `${d.getFullYear()}${pad2(d.getMonth() + 1)}${pad2(d.getDate())}` +
|
|
38
52
|
`-${pad2(d.getHours())}${pad2(d.getMinutes())}${pad2(d.getSeconds())}`;
|
|
53
|
+
const writeBackup = async (path, body, mode) => {
|
|
54
|
+
const base = `${path}.bak.${timestamp()}`;
|
|
55
|
+
for (let n = 1;; n++) {
|
|
56
|
+
const candidate = n === 1 ? base : `${base}-${n}`;
|
|
57
|
+
try {
|
|
58
|
+
await fs.writeFile(candidate, body, { mode, flag: 'wx' });
|
|
59
|
+
return candidate;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (err.code !== 'EEXIST' || n >= 1000)
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
39
67
|
export const readExistingEnv = async (path, codec) => {
|
|
40
68
|
const body = await readFileOrNull(path);
|
|
41
69
|
if (body === null)
|
|
@@ -63,11 +91,8 @@ export const applyUpdate = async (update) => {
|
|
|
63
91
|
let backupPath = null;
|
|
64
92
|
try {
|
|
65
93
|
await fs.access(dirname(target), fsConstants.W_OK);
|
|
66
|
-
if (exists)
|
|
67
|
-
backupPath =
|
|
68
|
-
const body = await fs.readFile(path);
|
|
69
|
-
await fs.writeFile(backupPath, body, { mode: fileMode, flag: 'wx' });
|
|
70
|
-
}
|
|
94
|
+
if (exists)
|
|
95
|
+
backupPath = await writeBackup(path, await fs.readFile(path), fileMode);
|
|
71
96
|
try {
|
|
72
97
|
await fs.rename(tmpPath, target);
|
|
73
98
|
}
|
|
@@ -84,4 +109,3 @@ export const applyUpdate = async (update) => {
|
|
|
84
109
|
}
|
|
85
110
|
return { backupPath, written: path };
|
|
86
111
|
};
|
|
87
|
-
//# sourceMappingURL=settings.js.map
|
package/dist/core/skills.js
CHANGED
|
@@ -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 = [
|
|
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
|
package/dist/core/status.js
CHANGED
|
@@ -30,7 +30,8 @@ const collectorHost = (url) => {
|
|
|
30
30
|
};
|
|
31
31
|
const formatOptIns = (o) => `prompts:${o.userPrompts ? 'yes' : 'no'} ` +
|
|
32
32
|
`details:${o.toolDetails ? 'yes' : 'no'} ` +
|
|
33
|
-
`content:${o.toolContent ? 'yes' : 'no'}
|
|
33
|
+
`content:${o.toolContent ? 'yes' : 'no'}` +
|
|
34
|
+
(o.repository === undefined ? '' : ` repository:${o.repository ? 'yes' : 'no'}`);
|
|
34
35
|
const fileRowsFor = (adapter) => {
|
|
35
36
|
const primaryParse = (env) => adapter.parseEnv(env);
|
|
36
37
|
const policy = adapter.layerKeyPolicy;
|
|
@@ -40,7 +41,9 @@ const fileRowsFor = (adapter) => {
|
|
|
40
41
|
: adapter.hierarchy.find((l) => l.path === adapter.paths.local)?.id;
|
|
41
42
|
const rows = [
|
|
42
43
|
{ label: 'Global', path: adapter.paths.global, codec: adapter.codec, parse: primaryParse },
|
|
43
|
-
|
|
44
|
+
];
|
|
45
|
+
if (adapter.paths.localIgnored === undefined) {
|
|
46
|
+
rows.push({
|
|
44
47
|
label: 'Local',
|
|
45
48
|
path: adapter.paths.local,
|
|
46
49
|
codec: adapter.codec,
|
|
@@ -54,8 +57,8 @@ const fileRowsFor = (adapter) => {
|
|
|
54
57
|
},
|
|
55
58
|
}
|
|
56
59
|
: {}),
|
|
57
|
-
}
|
|
58
|
-
|
|
60
|
+
});
|
|
61
|
+
}
|
|
59
62
|
for (const aw of adapter.additionalWrites ?? []) {
|
|
60
63
|
rows.push(...additionalRowsFor(aw));
|
|
61
64
|
}
|
|
@@ -269,4 +272,3 @@ export const runStatus = async (adapter, options = {}) => {
|
|
|
269
272
|
}
|
|
270
273
|
return 0;
|
|
271
274
|
};
|
|
272
|
-
//# sourceMappingURL=status.js.map
|
package/dist/core/store.js
CHANGED
package/dist/core/tty.js
CHANGED
package/dist/core/ucid.js
CHANGED
package/dist/core/ui.js
CHANGED
package/dist/core/use-case.js
CHANGED
package/dist/core/validate.js
CHANGED
package/dist/core/verify.js
CHANGED
package/dist/core/version.js
CHANGED
|
@@ -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
|
package/dist/core/wizard.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { select } from '@inquirer/prompts';
|
|
2
|
-
import { mergePrefills, planAdapter, planHasChanges, printMarkerCoexistenceNotes, printPostSetup, readPrefill, renderPlan, writePlan, } from './apply.js';
|
|
2
|
+
import { mergePrefills, planAdapter, planHasChanges, planSnapshotBlocked, printMarkerCoexistenceNotes, printPostSetup, readPrefill, renderPlan, userHooksPath, 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);
|
|
@@ -327,7 +324,27 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
327
324
|
});
|
|
328
325
|
}
|
|
329
326
|
const developerPin = useCase && adapters.some((a) => !a.teamUcid) ? { ...useCase, pinned: true } : undefined;
|
|
327
|
+
const markerTools = plans.filter((p) => p.markersOn !== null);
|
|
328
|
+
const hooks = { ...settings.hooks };
|
|
329
|
+
if (markerTools.length > 0) {
|
|
330
|
+
hooks.markers = {
|
|
331
|
+
...hooks.markers,
|
|
332
|
+
...Object.fromEntries(markerTools.map((p) => [p.adapter.name, p.markersOn === true])),
|
|
333
|
+
};
|
|
334
|
+
const filesOf = (name) => {
|
|
335
|
+
const files = hooks.events?.[name];
|
|
336
|
+
return files !== undefined && !Array.isArray(files) ? files : {};
|
|
337
|
+
};
|
|
338
|
+
hooks.events = {
|
|
339
|
+
...hooks.events,
|
|
340
|
+
...Object.fromEntries(markerTools.map((p) => [
|
|
341
|
+
p.adapter.name,
|
|
342
|
+
{ ...filesOf(p.adapter.name), [userHooksPath(p.adapter)]: [...p.hookEvents] },
|
|
343
|
+
])),
|
|
344
|
+
};
|
|
345
|
+
}
|
|
330
346
|
await updateSettings({
|
|
347
|
+
hooks,
|
|
331
348
|
collectorUrl,
|
|
332
349
|
orgName: identity.orgName,
|
|
333
350
|
orgId: identity.orgId ?? settings.orgId,
|
|
@@ -372,6 +389,7 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
372
389
|
]))),
|
|
373
390
|
optIns: answers.optIns,
|
|
374
391
|
markers: answers.markers,
|
|
392
|
+
...planSnapshotReport(plans, await blockedSnapshots(plans)),
|
|
375
393
|
verified,
|
|
376
394
|
skills: skills
|
|
377
395
|
? { installed: skills.installs.map((i) => i.path), noOps: skills.noOps }
|
|
@@ -381,6 +399,30 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
381
399
|
}
|
|
382
400
|
return 0;
|
|
383
401
|
};
|
|
402
|
+
const blockedSnapshots = async (plans) => new Map((await Promise.all(plans
|
|
403
|
+
.filter((p) => p.planSnapshotOn === true)
|
|
404
|
+
.map(async (p) => [p.adapter.name, await planSnapshotBlocked(p.adapter)]))).flatMap(([name, why]) => (why ? [[name, why]] : [])));
|
|
405
|
+
export const planSnapshotReport = (plans, blocked = new Map()) => {
|
|
406
|
+
const hosts = plans.filter((p) => p.planSnapshotOn !== null);
|
|
407
|
+
if (hosts.length === 0) {
|
|
408
|
+
return { planSnapshot: false, planSnapshotReason: 'not-hosted' };
|
|
409
|
+
}
|
|
410
|
+
const on = hosts.filter((p) => p.planSnapshotOn === true);
|
|
411
|
+
if (on.length === 0) {
|
|
412
|
+
return hosts.some((p) => p.planSnapshotOrgDelivered)
|
|
413
|
+
? { planSnapshot: true, planSnapshotReason: 'org-delivered' }
|
|
414
|
+
: { planSnapshot: false, planSnapshotReason: 'no-markers' };
|
|
415
|
+
}
|
|
416
|
+
const blockedHosts = on.filter((p) => blocked.has(p.adapter.name));
|
|
417
|
+
if (blockedHosts.length === on.length) {
|
|
418
|
+
return {
|
|
419
|
+
planSnapshot: false,
|
|
420
|
+
planSnapshotReason: 'blocked',
|
|
421
|
+
planSnapshotBlockedBy: Object.fromEntries(blockedHosts.map((p) => [p.adapter.name, blocked.get(p.adapter.name).reason])),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return { planSnapshot: true };
|
|
425
|
+
};
|
|
384
426
|
const maybeVerify = async (options, signedIn, ucid, apiUrl, teamOnly) => {
|
|
385
427
|
if (options.skipVerify || !signedIn)
|
|
386
428
|
return { verified: undefined, printed: undefined };
|
|
@@ -463,4 +505,3 @@ const printPostSetupTips = (adapters) => {
|
|
|
463
505
|
' invocations have time to flush spans before exit.'));
|
|
464
506
|
}
|
|
465
507
|
};
|
|
466
|
-
//# sourceMappingURL=wizard.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { claudeCodeFor } from './adapters/claude-code.js';
|
|
2
2
|
import { adapterNames, adapters } from './adapters/index.js';
|
|
3
3
|
import { runLogin, runLogout, runWhoami } from './core/auth-commands.js';
|
|
4
4
|
import { runDoctor } from './core/doctor.js';
|
|
5
5
|
import { runEdit } from './core/edit.js';
|
|
6
6
|
import { runEnvCommand } from './core/env-command.js';
|
|
7
7
|
import { PlatformError, WizardAbort } from './core/errors.js';
|
|
8
|
-
import { runInstallHooks } from './core/install-hooks.js';
|
|
8
|
+
import { runInstallHooks, sessionConfigDir } from './core/install-hooks.js';
|
|
9
9
|
import { flagBool, flagValue, hasFlag, parseArgs } from './core/flags.js';
|
|
10
10
|
import { color } from './core/format.js';
|
|
11
11
|
import { promptAdapters } from './core/prompts.js';
|
|
@@ -47,9 +47,10 @@ Usage:
|
|
|
47
47
|
show settings hierarchy and run health checks
|
|
48
48
|
mainwave-cli env <adapter> print export lines for shell-sourceable adapters
|
|
49
49
|
(usage: \`eval "$(mainwave-cli env <adapter>)"\`)
|
|
50
|
-
mainwave-cli install-hooks [--quiet] install or refresh the
|
|
51
|
-
hook scripts, with no prompts or
|
|
52
|
-
|
|
50
|
+
mainwave-cli install-hooks [--quiet] install or refresh the Mainwave hook entry and the
|
|
51
|
+
latest release's hook scripts, with no prompts or
|
|
52
|
+
sign-in (run at session start by an org's managed
|
|
53
|
+
settings, and by setup's own session-start hook)
|
|
53
54
|
mainwave-cli --help show this message
|
|
54
55
|
|
|
55
56
|
Setup flags (every prompt has one, so scripts and coding agents can drive it):
|
|
@@ -62,9 +63,11 @@ Setup flags (every prompt has one, so scripts and coding agents can drive it):
|
|
|
62
63
|
--invite <token> redeem an account-less developer invite: no login, no key
|
|
63
64
|
to paste — the token brings its own key, collector, and
|
|
64
65
|
identity (mutually exclusive with --api-key/--ucid/--use-case)
|
|
65
|
-
--opt-in prompts,tool-details,tool-content|all|none content capture
|
|
66
|
-
(default: all on — "--opt-in none" sends metadata only
|
|
67
|
-
|
|
66
|
+
--opt-in prompts,tool-details,tool-content,repository|all|none content capture
|
|
67
|
+
(default: all on — "--opt-in none" sends metadata only;
|
|
68
|
+
repository = repository names on Claude Code telemetry)
|
|
69
|
+
--no-markers skip the Mainwave hooks (installed by default): the ticket
|
|
70
|
+
& PR markers and, for Claude Code, the plan snapshot
|
|
68
71
|
--yes --json --no-verify --verify-timeout <seconds>
|
|
69
72
|
--skills / --no-skills install the agent skills payload (default: ask, or on in scripts)
|
|
70
73
|
--skills-only install only the skills, touching no telemetry config
|
|
@@ -109,6 +112,7 @@ const parseOptIns = (value) => {
|
|
|
109
112
|
userPrompts: has('prompts', 'user-prompts'),
|
|
110
113
|
toolDetails: has('tool-details', 'details'),
|
|
111
114
|
toolContent: has('tool-content', 'content'),
|
|
115
|
+
repository: has('repository', 'repo'),
|
|
112
116
|
};
|
|
113
117
|
};
|
|
114
118
|
const detectedAdapters = () => {
|
|
@@ -257,7 +261,10 @@ export const main = async (argv) => {
|
|
|
257
261
|
}
|
|
258
262
|
if (cmd === 'install-hooks') {
|
|
259
263
|
const parsed = parseArgs(args.slice(1));
|
|
260
|
-
|
|
264
|
+
const dir = await sessionConfigDir();
|
|
265
|
+
return runInstallHooks(dir === undefined ? undefined : claudeCodeFor(dir), {
|
|
266
|
+
quiet: flagBool(parsed, 'quiet') === true,
|
|
267
|
+
});
|
|
261
268
|
}
|
|
262
269
|
if (cmd === 'setup') {
|
|
263
270
|
const parsed = parseArgs(args.slice(1));
|
|
@@ -330,4 +337,3 @@ export const main = async (argv) => {
|
|
|
330
337
|
printError(`unknown command: ${cmd}`);
|
|
331
338
|
return 1;
|
|
332
339
|
};
|
|
333
|
-
//# sourceMappingURL=main.js.map
|
package/hooks/cursor-otlp.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 =
|
|
41
|
+
const log = markerLog(process.argv, '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
|
|
89
|
-
*
|
|
90
|
-
*
|
|
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 = (
|
|
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(
|
|
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)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
2
|
+
// The GitHub pull-request marker: a PostToolUse feature of the Mainwave hook
|
|
3
|
+
// dispatcher (mainwave-hook.mjs) for `gh pr create`. It also still runs on its
|
|
4
|
+
// own (§ the main at the bottom), because hook settings pasted before the
|
|
5
|
+
// dispatcher name this file.
|
|
3
6
|
//
|
|
4
7
|
// The platform detects "PR opened" by regex-matching `gh pr create` in the
|
|
5
8
|
// captured Bash *command* text, which yields the title but never the PR number
|
|
@@ -12,26 +15,28 @@
|
|
|
12
15
|
//
|
|
13
16
|
// Shared OTLP plumbing lives in ./marker-core.mjs. Privacy: emits the PR url /
|
|
14
17
|
// number / title and *aggregate* diff counts (changed files, additions,
|
|
15
|
-
// deletions) — never the diff contents or body.
|
|
16
|
-
// Bash
|
|
17
|
-
// log, no network) for anything that isn't a
|
|
18
|
-
// fast otherwise, so it can never block or
|
|
18
|
+
// deletions) — never the diff contents or body. Claude Code runs it only for a
|
|
19
|
+
// Bash command that starts with `gh` (the hook group's `if` filter); it still
|
|
20
|
+
// returns immediately (no log, no network) for anything that isn't a
|
|
21
|
+
// `gh pr create`, and fails open and fast otherwise, so it can never block or
|
|
22
|
+
// slow the session.
|
|
19
23
|
|
|
20
24
|
import { execFile } from 'node:child_process'
|
|
21
|
-
import { homedir } from 'node:os'
|
|
22
|
-
import { join } from 'node:path'
|
|
23
25
|
import { pathToFileURL } from 'node:url'
|
|
24
26
|
|
|
25
27
|
import {
|
|
26
28
|
buildMarkerPayload,
|
|
27
29
|
markerOauthAccount,
|
|
30
|
+
markerSessionEnv,
|
|
28
31
|
emitMarker,
|
|
32
|
+
hookFlag,
|
|
29
33
|
loadOtelConfig,
|
|
30
34
|
markerCallContext,
|
|
31
35
|
markerHostSource,
|
|
32
36
|
markerManagedDir,
|
|
37
|
+
markerProjectDir,
|
|
33
38
|
markerTool,
|
|
34
|
-
|
|
39
|
+
markerLog,
|
|
35
40
|
payloadShape,
|
|
36
41
|
readStdin,
|
|
37
42
|
toolOutput,
|
|
@@ -51,7 +56,7 @@ import {
|
|
|
51
56
|
// Re-export the shared output-reading helpers so the tests can import them here.
|
|
52
57
|
export { payloadShape, toolOutput } from './marker-core.mjs'
|
|
53
58
|
|
|
54
|
-
const
|
|
59
|
+
const LOG_NAME = 'pr-marker.log'
|
|
55
60
|
|
|
56
61
|
// Non-coding source/service so the marker lands as an ordinary span and stays
|
|
57
62
|
// out of the coding-work segmentation, same as the ticket marker.
|
|
@@ -112,13 +117,15 @@ export const parsePrStats = (stdout) => {
|
|
|
112
117
|
* The opened PR's aggregate diff counts, via `gh pr view <number> --json ...`.
|
|
113
118
|
* Fail-open: resolves `{}` on any error (gh absent, unauthenticated, timeout,
|
|
114
119
|
* bad output) so a marker still emits without the stats — never blocks the
|
|
115
|
-
* session. `
|
|
116
|
-
*
|
|
120
|
+
* session. `bin` replaces `gh`; `main` takes it only from the hook's own
|
|
121
|
+
* `--gh-bin` flag (tests pass a stub), never from the environment, because a
|
|
122
|
+
* repository's project settings `env` reaches the hook and this runs with the
|
|
123
|
+
* repository as its working directory (§ `hookFlag`). Only the three integer
|
|
124
|
+
* counts are read — never the diff.
|
|
117
125
|
*/
|
|
118
|
-
export const fetchPrStats = (number, { cwd, timeoutMs = 5000 } = {}) =>
|
|
126
|
+
export const fetchPrStats = (number, { cwd, bin = 'gh', timeoutMs = 5000 } = {}) =>
|
|
119
127
|
new Promise((resolve) => {
|
|
120
128
|
if (!number) return resolve({})
|
|
121
|
-
const bin = process.env.MAINWAVE_GH_BIN || 'gh'
|
|
122
129
|
execFile(
|
|
123
130
|
bin,
|
|
124
131
|
['pr', 'view', String(number), '--json', 'changedFiles,additions,deletions'],
|
|
@@ -175,18 +182,17 @@ export const buildPrPayload = ({
|
|
|
175
182
|
nowNs,
|
|
176
183
|
})
|
|
177
184
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// no work unless the command actually opened a PR.
|
|
188
|
-
const command = payload.tool_input?.command
|
|
185
|
+
/**
|
|
186
|
+
* The feature: one marker span when the Bash command opened a PR, else
|
|
187
|
+
* nothing. `ctx.argv` carries the hook command's flags (and `--tool <host>`
|
|
188
|
+
* under the dispatcher); `ctx.emit` posts.
|
|
189
|
+
*/
|
|
190
|
+
export const handle = async (payload, { argv = process.argv, emit = emitMarker } = {}) => {
|
|
191
|
+
// Cheap guard first: bail with no log and no work unless the command
|
|
192
|
+
// actually opened a PR.
|
|
193
|
+
const command = payload?.tool_input?.command
|
|
189
194
|
if (!isPrCreate(command)) return
|
|
195
|
+
const log = markerLog(argv, LOG_NAME)
|
|
190
196
|
|
|
191
197
|
const url = extractPrUrl(toolOutput(payload))
|
|
192
198
|
if (!url) {
|
|
@@ -197,9 +203,11 @@ const main = async () => {
|
|
|
197
203
|
const title = extractPrTitle(command)
|
|
198
204
|
|
|
199
205
|
const cwd = payload.cwd || process.cwd()
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
const
|
|
206
|
+
const projectDir = markerProjectDir(payload)
|
|
207
|
+
const tool = markerTool(argv)
|
|
208
|
+
const managedDir = markerManagedDir(argv)
|
|
209
|
+
const env = markerSessionEnv(tool, payload)
|
|
210
|
+
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(projectDir, env, tool, managedDir)
|
|
203
211
|
log(
|
|
204
212
|
`pr=${number} endpoint=${endpoint ? 'set' : 'MISSING'} ` +
|
|
205
213
|
`bearer=${bearer ? 'set' : 'MISSING'} ucid=${resourceAttrs['mainwave.ucid'] || 'MISSING'}`,
|
|
@@ -210,13 +218,19 @@ const main = async () => {
|
|
|
210
218
|
}
|
|
211
219
|
// Read only once the emit is certain: `.claude.json` can run to megabytes.
|
|
212
220
|
const { email: userEmail, accountUuid: userAccountUuid } = markerOauthAccount(tool, {
|
|
213
|
-
cwd,
|
|
221
|
+
cwd: projectDir,
|
|
222
|
+
env,
|
|
214
223
|
managedDir,
|
|
215
224
|
})
|
|
216
225
|
|
|
217
226
|
// Diff counts are best-effort: the marker still emits (with the link) if gh is
|
|
218
227
|
// unavailable or the fetch fails, so this never blocks the PR from surfacing.
|
|
219
|
-
|
|
228
|
+
// gh runs where the agent ran `gh pr create`: that directory names the PR's
|
|
229
|
+
// repository.
|
|
230
|
+
const { changedFiles, additions, deletions } = await fetchPrStats(number, {
|
|
231
|
+
cwd,
|
|
232
|
+
bin: hookFlag(argv, '--gh-bin'),
|
|
233
|
+
})
|
|
220
234
|
log(
|
|
221
235
|
`stats changed_files=${changedFiles ?? 'na'} additions=${additions ?? 'na'} ` +
|
|
222
236
|
`deletions=${deletions ?? 'na'}`,
|
|
@@ -237,7 +251,17 @@ const main = async () => {
|
|
|
237
251
|
callContext: markerCallContext(tool, payload),
|
|
238
252
|
nowNs: BigInt(Date.now()) * 1_000_000n,
|
|
239
253
|
})
|
|
240
|
-
await
|
|
254
|
+
await emit({ endpoint, bearer, body, label: `#${number}`, log })
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const main = async () => {
|
|
258
|
+
let payload
|
|
259
|
+
try {
|
|
260
|
+
payload = JSON.parse(await readStdin())
|
|
261
|
+
} catch {
|
|
262
|
+
return // fires on every Bash call — stay silent for anything we can't read
|
|
263
|
+
}
|
|
264
|
+
await handle(payload)
|
|
241
265
|
}
|
|
242
266
|
|
|
243
267
|
// Run the IO path only when executed directly, so tests can import the pure fns.
|
|
@@ -245,6 +269,6 @@ const main = async () => {
|
|
|
245
269
|
// file URL (e.g. the space in the managed install dir "/Library/Application
|
|
246
270
|
// Support/…") still matches import.meta.url — a raw `file://${argv[1]}` template
|
|
247
271
|
// keeps the literal space, never matches, and silently skips main().
|
|
248
|
-
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
272
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
249
273
|
await main()
|
|
250
274
|
}
|