@mainwave/cli 0.8.0 → 0.10.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 +169 -42
- package/dist/adapters/claude-code.js +23 -4
- package/dist/adapters/codex-cli.js +1 -1
- package/dist/adapters/cursor.js +4 -2
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/kiro.js +361 -0
- package/dist/core/apply.js +161 -46
- package/dist/core/behaviour-hooks.js +7 -7
- package/dist/core/codecs/kiro-hooks-json.js +76 -0
- package/dist/core/doctor.js +27 -9
- package/dist/core/effective-settings.js +10 -0
- package/dist/core/entry-script.js +90 -0
- package/dist/core/git-bash.js +40 -0
- package/dist/core/install-hooks.js +126 -43
- package/dist/core/interview.js +114 -16
- package/dist/core/markers.js +678 -140
- package/dist/core/remove.js +67 -0
- package/dist/core/settings.js +32 -6
- package/dist/core/skills.js +47 -1
- package/dist/core/status.js +2 -1
- package/dist/core/wizard.js +64 -3
- package/dist/main.js +28 -9
- package/hooks/cursor-otlp.mjs +4 -27
- package/hooks/github-pr-marker.mjs +35 -22
- package/hooks/glab-mr-marker.mjs +795 -0
- package/hooks/jira-ticket-marker.mjs +27 -15
- package/hooks/kiro-otlp.mjs +570 -0
- package/hooks/linear-ticket-marker.mjs +27 -15
- package/hooks/mainwave-hook-node.mjs +42 -0
- package/hooks/mainwave-hook.mjs +301 -0
- package/hooks/marker-core.mjs +368 -41
- 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 +49 -0
- package/hooks/vocabulary.mjs +188 -0
- package/package.json +5 -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-setup/SKILL.md +47 -12
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { WizardAbort } from './errors.js';
|
|
2
|
+
import { color } from './format.js';
|
|
3
|
+
import { promptConfirmWrite } from './prompts.js';
|
|
4
|
+
import { applyUpdate, removeSettingsFile } from './settings.js';
|
|
5
|
+
import { isInteractive } from './tty.js';
|
|
6
|
+
import { emitJson, say, setJsonMode } from './ui.js';
|
|
7
|
+
export const runRemove = async (adapters, options = {}) => {
|
|
8
|
+
setJsonMode(options.json === true);
|
|
9
|
+
const unsupported = adapters.filter((a) => !a.removal);
|
|
10
|
+
if (unsupported.length > 0) {
|
|
11
|
+
throw new WizardAbort(`--remove isn't available for ${unsupported.map((a) => a.name).join(', ')}`);
|
|
12
|
+
}
|
|
13
|
+
say(color.bold(`mainwave-cli — remove ${adapters.map((a) => a.displayName).join(', ')}`));
|
|
14
|
+
const groups = new Map();
|
|
15
|
+
for (const a of adapters)
|
|
16
|
+
groups.set(a.removal.group, [...(groups.get(a.removal.group) ?? []), a]);
|
|
17
|
+
const steps = [];
|
|
18
|
+
for (const members of groups.values()) {
|
|
19
|
+
steps.push(...(await members[0].removal.plan(members.map((a) => a.name))));
|
|
20
|
+
}
|
|
21
|
+
const notes = steps.filter((s) => s.kind === 'note');
|
|
22
|
+
const actions = steps.filter((s) => s.kind !== 'note');
|
|
23
|
+
for (const n of notes)
|
|
24
|
+
say(color.dim(n.note));
|
|
25
|
+
if (actions.length === 0) {
|
|
26
|
+
if (notes.length === 0) {
|
|
27
|
+
say(color.dim('Nothing to remove: no Mainwave config for these tools is on disk.'));
|
|
28
|
+
}
|
|
29
|
+
if (options.json)
|
|
30
|
+
emitJson({ status: 'nothing-to-remove', tools: adapters.map((a) => a.name) });
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
say('');
|
|
34
|
+
for (const step of actions)
|
|
35
|
+
say(` ${step.kind === 'delete' ? '-' : '~'} ${step.note}`);
|
|
36
|
+
if (!options.yes) {
|
|
37
|
+
if (!isInteractive())
|
|
38
|
+
throw new WizardAbort('refusing to remove without confirmation — pass --yes');
|
|
39
|
+
say('');
|
|
40
|
+
if (!(await promptConfirmWrite()))
|
|
41
|
+
throw new WizardAbort();
|
|
42
|
+
}
|
|
43
|
+
const done = [];
|
|
44
|
+
for (const step of actions) {
|
|
45
|
+
if (step.kind === 'update') {
|
|
46
|
+
const result = await applyUpdate(step.update);
|
|
47
|
+
done.push({ path: result.written, action: 'updated', backup: result.backupPath });
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
done.push({
|
|
51
|
+
path: step.path,
|
|
52
|
+
action: 'deleted',
|
|
53
|
+
backup: await removeSettingsFile(step.path, { backup: step.backup !== false }),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
say('');
|
|
58
|
+
for (const d of done) {
|
|
59
|
+
say(color.green(`✓ ${d.action === 'deleted' ? 'Removed' : 'Updated'} ${d.path}`));
|
|
60
|
+
if (d.backup)
|
|
61
|
+
say(color.dim(` backup: ${d.backup}`));
|
|
62
|
+
}
|
|
63
|
+
say(color.dim('Restart open sessions of these tools so they stop loading the hooks.'));
|
|
64
|
+
if (options.json)
|
|
65
|
+
emitJson({ status: 'removed', tools: adapters.map((a) => a.name), files: done });
|
|
66
|
+
return 0;
|
|
67
|
+
};
|
package/dist/core/settings.js
CHANGED
|
@@ -50,6 +50,20 @@ const diffEnv = (before, after, managedKeys) => {
|
|
|
50
50
|
const pad2 = (n) => String(n).padStart(2, '0');
|
|
51
51
|
const timestamp = (d = new Date()) => `${d.getFullYear()}${pad2(d.getMonth() + 1)}${pad2(d.getDate())}` +
|
|
52
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
|
+
};
|
|
53
67
|
export const readExistingEnv = async (path, codec) => {
|
|
54
68
|
const body = await readFileOrNull(path);
|
|
55
69
|
if (body === null)
|
|
@@ -67,8 +81,23 @@ export const prepareUpdate = async (args) => {
|
|
|
67
81
|
const diff = diffEnv(baseEnv, newEnv, managedKeys);
|
|
68
82
|
return { path, exists, codec, next, diff, mode };
|
|
69
83
|
};
|
|
84
|
+
export const removeSettingsFile = async (path, { backup = true } = {}) => {
|
|
85
|
+
let body;
|
|
86
|
+
try {
|
|
87
|
+
body = await fs.readFile(path);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (isErrnoCode(err, 'ENOENT'))
|
|
91
|
+
return null;
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
const mode = (await fs.stat(path)).mode & 0o777;
|
|
95
|
+
const backupPath = backup ? await writeBackup(path, body, mode) : null;
|
|
96
|
+
await fs.rm(path, { force: true });
|
|
97
|
+
return backupPath;
|
|
98
|
+
};
|
|
70
99
|
export const applyUpdate = async (update) => {
|
|
71
|
-
const { path, exists, next, codec, mode } = update;
|
|
100
|
+
const { path, exists, next, codec, mode, backup = true } = update;
|
|
72
101
|
const fileMode = mode ?? 0o600;
|
|
73
102
|
await fs.mkdir(dirname(path), { recursive: true });
|
|
74
103
|
const target = exists ? await fs.realpath(path).catch(() => path) : path;
|
|
@@ -77,11 +106,8 @@ export const applyUpdate = async (update) => {
|
|
|
77
106
|
let backupPath = null;
|
|
78
107
|
try {
|
|
79
108
|
await fs.access(dirname(target), fsConstants.W_OK);
|
|
80
|
-
if (exists)
|
|
81
|
-
backupPath =
|
|
82
|
-
const body = await fs.readFile(path);
|
|
83
|
-
await fs.writeFile(backupPath, body, { mode: fileMode, flag: 'wx' });
|
|
84
|
-
}
|
|
109
|
+
if (exists && backup)
|
|
110
|
+
backupPath = await writeBackup(path, await fs.readFile(path), fileMode);
|
|
85
111
|
try {
|
|
86
112
|
await fs.rename(tmpPath, target);
|
|
87
113
|
}
|
package/dist/core/skills.js
CHANGED
|
@@ -2,6 +2,7 @@ import { promises as fs } from 'node:fs';
|
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { isErrnoCode } from './settings.js';
|
|
5
6
|
export const BLOCK_OPEN = '<!-- mainwave:skills managed-by @mainwave/cli';
|
|
6
7
|
export const BLOCK_CLOSE = '<!-- /mainwave:skills -->';
|
|
7
8
|
export const SKILL_NAMES = [
|
|
@@ -56,7 +57,7 @@ export const renderBlock = (version, skillsDir, names = SKILL_NAMES) => {
|
|
|
56
57
|
];
|
|
57
58
|
return lines.join('\n');
|
|
58
59
|
};
|
|
59
|
-
const isBlockOpen = (line) => line.startsWith(BLOCK_OPEN);
|
|
60
|
+
export const isBlockOpen = (line) => line.startsWith(BLOCK_OPEN);
|
|
60
61
|
export const installedBlockVersion = (body) => {
|
|
61
62
|
for (const line of body.split('\n')) {
|
|
62
63
|
if (!isBlockOpen(line))
|
|
@@ -86,6 +87,51 @@ export const applyBlock = (existing, block) => {
|
|
|
86
87
|
const kept = stripBlocks(existing).replace(/\s+$/, '');
|
|
87
88
|
return kept.length === 0 ? `${block}\n` : `${kept}\n\n${block}\n`;
|
|
88
89
|
};
|
|
90
|
+
const textCodec = {
|
|
91
|
+
format: 'text',
|
|
92
|
+
parse: (body) => body,
|
|
93
|
+
serialize: (doc) => String(doc),
|
|
94
|
+
empty: () => '',
|
|
95
|
+
readEnv: () => ({}),
|
|
96
|
+
applyEnv: (doc) => doc,
|
|
97
|
+
};
|
|
98
|
+
export const planBlockRemoval = async (path) => {
|
|
99
|
+
let body;
|
|
100
|
+
try {
|
|
101
|
+
body = await fs.readFile(path, 'utf8');
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (isErrnoCode(err, 'ENOENT'))
|
|
105
|
+
return undefined;
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
if (!body.split('\n').some(isBlockOpen))
|
|
109
|
+
return undefined;
|
|
110
|
+
const kept = stripBlocks(body)
|
|
111
|
+
.replace(/^(?:[ \t]*\r?\n)+/, '')
|
|
112
|
+
.replace(/\s+$/, '');
|
|
113
|
+
if (kept.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
kind: 'delete',
|
|
116
|
+
path,
|
|
117
|
+
backup: false,
|
|
118
|
+
note: `${path}: delete (only Mainwave's instructions in it)`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
kind: 'update',
|
|
123
|
+
update: {
|
|
124
|
+
path,
|
|
125
|
+
exists: true,
|
|
126
|
+
codec: textCodec,
|
|
127
|
+
next: `${kept}${body.includes('\r\n') ? '\r\n' : '\n'}`,
|
|
128
|
+
diff: { added: [], changed: [], removed: [], unchanged: 0 },
|
|
129
|
+
mode: (await fs.stat(path)).mode & 0o777,
|
|
130
|
+
backup: false,
|
|
131
|
+
},
|
|
132
|
+
note: `${path}: remove Mainwave's instructions, keep the rest`,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
89
135
|
export const installToSurface = async (adapterName, surface, scope, version, srcRoot = packagedSkillsDir(), installedRoot = installedSkillsDir(), names = SKILL_NAMES) => {
|
|
90
136
|
const target = scope === 'local' ? surface.local : surface.global;
|
|
91
137
|
if (surface.kind === 'skill-dir') {
|
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;
|
package/dist/core/wizard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
import { computeEffective, isManagedUnitDrop, nativeIdentityReason } from './effective-settings.js';
|
|
5
5
|
import { isManagedIdentityConfig, isManagedLayer } from './layer-policy.js';
|
|
@@ -109,6 +109,10 @@ export const ucidRemovalNotice = (plan, onDisk) => onDisk !== undefined && plan.
|
|
|
109
109
|
? `${plan.adapter.displayName}: removing UCID ${onDisk} an earlier setup wrote; activity will ` +
|
|
110
110
|
`now be attributed from your identity. Pass --ucid ${onDisk} to keep it.`
|
|
111
111
|
: null;
|
|
112
|
+
export const ucidIgnoredNotice = (adapter, explicitUcid) => adapter.carriesNoUcid && explicitUcid !== undefined
|
|
113
|
+
? `${adapter.displayName}: its hooks send no use-case id, so --ucid / --use-case don't apply; ` +
|
|
114
|
+
'its activity is attributed from your email.'
|
|
115
|
+
: null;
|
|
112
116
|
export const teamUcidNotice = (plan) => {
|
|
113
117
|
const decision = plan.teamUcid;
|
|
114
118
|
if (!decision)
|
|
@@ -230,6 +234,7 @@ export const redeemInviteToOverrides = async (token, apiUrl, options) => {
|
|
|
230
234
|
rememberKeyAs: creds.key_label,
|
|
231
235
|
collectorUrl: creds.collector_url,
|
|
232
236
|
userEmail: creds.email,
|
|
237
|
+
userEmailFromInvite: true,
|
|
233
238
|
};
|
|
234
239
|
};
|
|
235
240
|
export const runSetup = async (adapters, rawOptions = {}) => {
|
|
@@ -282,6 +287,7 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
282
287
|
onDisk: prefills[i]?.values,
|
|
283
288
|
storedUseCase: settings.useCase,
|
|
284
289
|
unpin: options.skipUseCase === true,
|
|
290
|
+
pass: adapters.map((a) => a.name),
|
|
285
291
|
})));
|
|
286
292
|
for (const plan of plans)
|
|
287
293
|
renderPlan(plan);
|
|
@@ -292,6 +298,11 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
292
298
|
say('');
|
|
293
299
|
say(color.yellow(note));
|
|
294
300
|
}
|
|
301
|
+
const ignored = ucidIgnoredNotice(plan.adapter, answers.ucid);
|
|
302
|
+
if (ignored) {
|
|
303
|
+
say('');
|
|
304
|
+
say(color.yellow(ignored));
|
|
305
|
+
}
|
|
295
306
|
const team = teamUcidNotice(plan);
|
|
296
307
|
if (team) {
|
|
297
308
|
say('');
|
|
@@ -323,14 +334,38 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
323
334
|
createdAt: new Date().toISOString(),
|
|
324
335
|
});
|
|
325
336
|
}
|
|
326
|
-
const developerPin = useCase && adapters.some((a) => !a.teamUcid
|
|
337
|
+
const developerPin = useCase && adapters.some((a) => !a.teamUcid && !a.carriesNoUcid)
|
|
338
|
+
? { ...useCase, pinned: true }
|
|
339
|
+
: undefined;
|
|
340
|
+
const markerTools = plans.filter((p) => p.markersOn !== null);
|
|
341
|
+
const hooks = { ...settings.hooks };
|
|
342
|
+
if (markerTools.length > 0) {
|
|
343
|
+
hooks.markers = {
|
|
344
|
+
...hooks.markers,
|
|
345
|
+
...Object.fromEntries(markerTools.map((p) => [p.adapter.name, p.markersOn === true])),
|
|
346
|
+
};
|
|
347
|
+
const filesOf = (name) => {
|
|
348
|
+
const files = hooks.events?.[name];
|
|
349
|
+
return files !== undefined && !Array.isArray(files) ? files : {};
|
|
350
|
+
};
|
|
351
|
+
hooks.events = {
|
|
352
|
+
...hooks.events,
|
|
353
|
+
...Object.fromEntries(markerTools.map((p) => [
|
|
354
|
+
p.adapter.name,
|
|
355
|
+
{ ...filesOf(p.adapter.name), [userHooksPath(p.adapter)]: [...p.hookEvents] },
|
|
356
|
+
])),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
327
359
|
await updateSettings({
|
|
360
|
+
hooks,
|
|
328
361
|
collectorUrl,
|
|
329
362
|
orgName: identity.orgName,
|
|
330
363
|
orgId: identity.orgId ?? settings.orgId,
|
|
331
364
|
useCase: options.skipUseCase ? null : developerPin,
|
|
332
365
|
});
|
|
333
|
-
const passPin =
|
|
366
|
+
const passPin = adapters.some((a) => !a.carriesNoUcid)
|
|
367
|
+
? (useCase ?? plans.find((p) => p.keptPin)?.keptPin)
|
|
368
|
+
: undefined;
|
|
334
369
|
for (const plan of plans) {
|
|
335
370
|
if (plan.markersOn !== null) {
|
|
336
371
|
await printMarkerCoexistenceNotes(plan.adapter, plan.primaryPath, plan.markersOn);
|
|
@@ -368,7 +403,9 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
368
403
|
}, p.adapter),
|
|
369
404
|
]))),
|
|
370
405
|
optIns: answers.optIns,
|
|
406
|
+
optInsByTool: Object.fromEntries(plans.map((p) => [p.adapter.name, p.input.optIns])),
|
|
371
407
|
markers: answers.markers,
|
|
408
|
+
...planSnapshotReport(plans, await blockedSnapshots(plans)),
|
|
372
409
|
verified,
|
|
373
410
|
skills: skills
|
|
374
411
|
? { installed: skills.installs.map((i) => i.path), noOps: skills.noOps }
|
|
@@ -378,6 +415,30 @@ export const runSetup = async (adapters, rawOptions = {}) => {
|
|
|
378
415
|
}
|
|
379
416
|
return 0;
|
|
380
417
|
};
|
|
418
|
+
const blockedSnapshots = async (plans) => new Map((await Promise.all(plans
|
|
419
|
+
.filter((p) => p.planSnapshotOn === true)
|
|
420
|
+
.map(async (p) => [p.adapter.name, await planSnapshotBlocked(p.adapter)]))).flatMap(([name, why]) => (why ? [[name, why]] : [])));
|
|
421
|
+
export const planSnapshotReport = (plans, blocked = new Map()) => {
|
|
422
|
+
const hosts = plans.filter((p) => p.planSnapshotOn !== null);
|
|
423
|
+
if (hosts.length === 0) {
|
|
424
|
+
return { planSnapshot: false, planSnapshotReason: 'not-hosted' };
|
|
425
|
+
}
|
|
426
|
+
const on = hosts.filter((p) => p.planSnapshotOn === true);
|
|
427
|
+
if (on.length === 0) {
|
|
428
|
+
return hosts.some((p) => p.planSnapshotOrgDelivered)
|
|
429
|
+
? { planSnapshot: true, planSnapshotReason: 'org-delivered' }
|
|
430
|
+
: { planSnapshot: false, planSnapshotReason: 'no-markers' };
|
|
431
|
+
}
|
|
432
|
+
const blockedHosts = on.filter((p) => blocked.has(p.adapter.name));
|
|
433
|
+
if (blockedHosts.length === on.length) {
|
|
434
|
+
return {
|
|
435
|
+
planSnapshot: false,
|
|
436
|
+
planSnapshotReason: 'blocked',
|
|
437
|
+
planSnapshotBlockedBy: Object.fromEntries(blockedHosts.map((p) => [p.adapter.name, blocked.get(p.adapter.name).reason])),
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return { planSnapshot: true };
|
|
441
|
+
};
|
|
381
442
|
const maybeVerify = async (options, signedIn, ucid, apiUrl, teamOnly) => {
|
|
382
443
|
if (options.skipVerify || !signedIn)
|
|
383
444
|
return { verified: undefined, printed: undefined };
|
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';
|
|
@@ -13,6 +13,7 @@ import { runStatus } from './core/status.js';
|
|
|
13
13
|
import { ensureTty, isInteractive } from './core/tty.js';
|
|
14
14
|
import { VERSION } from './core/version.js';
|
|
15
15
|
import { runVerify } from './core/verify.js';
|
|
16
|
+
import { runRemove } from './core/remove.js';
|
|
16
17
|
import { runSetup, runSkillsOnly } from './core/wizard.js';
|
|
17
18
|
export { VERSION };
|
|
18
19
|
const printHelp = () => {
|
|
@@ -47,9 +48,10 @@ Usage:
|
|
|
47
48
|
show settings hierarchy and run health checks
|
|
48
49
|
mainwave-cli env <adapter> print export lines for shell-sourceable adapters
|
|
49
50
|
(usage: \`eval "$(mainwave-cli env <adapter>)"\`)
|
|
50
|
-
mainwave-cli install-hooks [--quiet] install or refresh the
|
|
51
|
-
hook scripts, with no prompts or
|
|
52
|
-
|
|
51
|
+
mainwave-cli install-hooks [--quiet] install or refresh the Mainwave hook entry and the
|
|
52
|
+
latest release's hook scripts, with no prompts or
|
|
53
|
+
sign-in (run at session start by an org's managed
|
|
54
|
+
settings, and by setup's own session-start hook)
|
|
53
55
|
mainwave-cli --help show this message
|
|
54
56
|
|
|
55
57
|
Setup flags (every prompt has one, so scripts and coding agents can drive it):
|
|
@@ -62,12 +64,16 @@ Setup flags (every prompt has one, so scripts and coding agents can drive it):
|
|
|
62
64
|
--invite <token> redeem an account-less developer invite: no login, no key
|
|
63
65
|
to paste — the token brings its own key, collector, and
|
|
64
66
|
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
|
-
|
|
67
|
+
--opt-in prompts,tool-details,tool-content,repository|all|none content capture
|
|
68
|
+
(default: all on — "--opt-in none" sends metadata only;
|
|
69
|
+
repository = repository names on Claude Code telemetry)
|
|
70
|
+
--no-markers skip the Mainwave hooks (installed by default): the ticket
|
|
71
|
+
& PR markers and, for Claude Code, the plan snapshot
|
|
68
72
|
--yes --json --no-verify --verify-timeout <seconds>
|
|
69
73
|
--skills / --no-skills install the agent skills payload (default: ask, or on in scripts)
|
|
70
74
|
--skills-only install only the skills, touching no telemetry config
|
|
75
|
+
--remove take this CLI's config for the named tools back off this
|
|
76
|
+
machine (Kiro: its hooks file entries and kiro.env)
|
|
71
77
|
mainwave-cli --version print version
|
|
72
78
|
|
|
73
79
|
Available adapters:
|
|
@@ -109,6 +115,7 @@ const parseOptIns = (value) => {
|
|
|
109
115
|
userPrompts: has('prompts', 'user-prompts'),
|
|
110
116
|
toolDetails: has('tool-details', 'details'),
|
|
111
117
|
toolContent: has('tool-content', 'content'),
|
|
118
|
+
repository: has('repository', 'repo'),
|
|
112
119
|
};
|
|
113
120
|
};
|
|
114
121
|
const detectedAdapters = () => {
|
|
@@ -257,7 +264,10 @@ export const main = async (argv) => {
|
|
|
257
264
|
}
|
|
258
265
|
if (cmd === 'install-hooks') {
|
|
259
266
|
const parsed = parseArgs(args.slice(1));
|
|
260
|
-
|
|
267
|
+
const dir = await sessionConfigDir();
|
|
268
|
+
return runInstallHooks(dir === undefined ? undefined : claudeCodeFor(dir), {
|
|
269
|
+
quiet: flagBool(parsed, 'quiet') === true,
|
|
270
|
+
});
|
|
261
271
|
}
|
|
262
272
|
if (cmd === 'setup') {
|
|
263
273
|
const parsed = parseArgs(args.slice(1));
|
|
@@ -270,6 +280,15 @@ export const main = async (argv) => {
|
|
|
270
280
|
named.push(resolved);
|
|
271
281
|
}
|
|
272
282
|
try {
|
|
283
|
+
if (flagBool(parsed, 'remove') === true) {
|
|
284
|
+
if (named.length === 0) {
|
|
285
|
+
throw new WizardAbort('--remove needs the tools to remove, e.g. `setup kiro-ide --remove`');
|
|
286
|
+
}
|
|
287
|
+
return await runRemove(named, {
|
|
288
|
+
yes: flagBool(parsed, 'yes') === true,
|
|
289
|
+
json: flagBool(parsed, 'json') === true,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
273
292
|
const opts = setupOptions(parsed);
|
|
274
293
|
const targets = named.length > 0
|
|
275
294
|
? named
|
package/hooks/cursor-otlp.mjs
CHANGED
|
@@ -33,12 +33,13 @@ import {
|
|
|
33
33
|
buildMarkerPayload,
|
|
34
34
|
emitMarker,
|
|
35
35
|
markerLog,
|
|
36
|
+
parseEnvFile,
|
|
36
37
|
parseKv,
|
|
37
38
|
readStdin,
|
|
38
39
|
} from './marker-core.mjs'
|
|
39
40
|
import { ATTR_CODE_FILE_PATH } from './vocabulary.mjs'
|
|
40
41
|
|
|
41
|
-
const log = markerLog(process.argv, '
|
|
42
|
+
const log = markerLog(process.argv, 'cursor.log')
|
|
42
43
|
|
|
43
44
|
// Classified by the collector as a coding agent via `mainwave.source`; the
|
|
44
45
|
// service name matches Cursor's own native-export resource (`service.name=cursor`)
|
|
@@ -51,32 +52,8 @@ const SERVICE_NAME = 'cursor'
|
|
|
51
52
|
// Config resolution — the managed env file this script's OTLP target lives in.
|
|
52
53
|
// ---------------------------------------------------------------------------
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const v = raw.trim()
|
|
57
|
-
if (v.startsWith('"') && v.endsWith('"') && v.length >= 2) {
|
|
58
|
-
return v.slice(1, -1).replace(/\\n/g, '\n').replace(/\\"/g, '"').replace(/\\\\/g, '\\')
|
|
59
|
-
}
|
|
60
|
-
if (v.startsWith("'") && v.endsWith("'") && v.length >= 2) return v.slice(1, -1)
|
|
61
|
-
return v
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Parse a `KEY="value"` env file into a flat record; {} on any error. */
|
|
65
|
-
export const parseEnvFile = (text) => {
|
|
66
|
-
const out = {}
|
|
67
|
-
for (const line of (text ?? '').split('\n')) {
|
|
68
|
-
const trimmed = line.trim()
|
|
69
|
-
if (trimmed === '' || trimmed.startsWith('#')) continue
|
|
70
|
-
let rest = trimmed
|
|
71
|
-
if (rest.startsWith('export ')) rest = rest.slice('export '.length).trimStart()
|
|
72
|
-
const eq = rest.indexOf('=')
|
|
73
|
-
if (eq < 0) continue
|
|
74
|
-
const key = rest.slice(0, eq).trim()
|
|
75
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue
|
|
76
|
-
out[key] = unquote(rest.slice(eq + 1))
|
|
77
|
-
}
|
|
78
|
-
return out
|
|
79
|
-
}
|
|
55
|
+
// Re-exported: the parse moved to marker-core.mjs so the Kiro hook shares it.
|
|
56
|
+
export { parseEnvFile }
|
|
80
57
|
|
|
81
58
|
const readFileSafe = (path) => {
|
|
82
59
|
try {
|
|
@@ -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,10 +15,11 @@
|
|
|
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
25
|
import { pathToFileURL } from 'node:url'
|
|
@@ -52,7 +56,7 @@ import {
|
|
|
52
56
|
// Re-export the shared output-reading helpers so the tests can import them here.
|
|
53
57
|
export { payloadShape, toolOutput } from './marker-core.mjs'
|
|
54
58
|
|
|
55
|
-
const
|
|
59
|
+
const LOG_NAME = 'pr-marker.log'
|
|
56
60
|
|
|
57
61
|
// Non-coding source/service so the marker lands as an ordinary span and stays
|
|
58
62
|
// out of the coding-work segmentation, same as the ticket marker.
|
|
@@ -178,18 +182,17 @@ export const buildPrPayload = ({
|
|
|
178
182
|
nowNs,
|
|
179
183
|
})
|
|
180
184
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// no work unless the command actually opened a PR.
|
|
191
|
-
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
|
|
192
194
|
if (!isPrCreate(command)) return
|
|
195
|
+
const log = markerLog(argv, LOG_NAME)
|
|
193
196
|
|
|
194
197
|
const url = extractPrUrl(toolOutput(payload))
|
|
195
198
|
if (!url) {
|
|
@@ -201,8 +204,8 @@ const main = async () => {
|
|
|
201
204
|
|
|
202
205
|
const cwd = payload.cwd || process.cwd()
|
|
203
206
|
const projectDir = markerProjectDir(payload)
|
|
204
|
-
const tool = markerTool(
|
|
205
|
-
const managedDir = markerManagedDir(
|
|
207
|
+
const tool = markerTool(argv)
|
|
208
|
+
const managedDir = markerManagedDir(argv)
|
|
206
209
|
const env = markerSessionEnv(tool, payload)
|
|
207
210
|
const { endpoint, bearer, resourceAttrs } = loadOtelConfig(projectDir, env, tool, managedDir)
|
|
208
211
|
log(
|
|
@@ -226,7 +229,7 @@ const main = async () => {
|
|
|
226
229
|
// repository.
|
|
227
230
|
const { changedFiles, additions, deletions } = await fetchPrStats(number, {
|
|
228
231
|
cwd,
|
|
229
|
-
bin: hookFlag(
|
|
232
|
+
bin: hookFlag(argv, '--gh-bin'),
|
|
230
233
|
})
|
|
231
234
|
log(
|
|
232
235
|
`stats changed_files=${changedFiles ?? 'na'} additions=${additions ?? 'na'} ` +
|
|
@@ -248,7 +251,17 @@ const main = async () => {
|
|
|
248
251
|
callContext: markerCallContext(tool, payload),
|
|
249
252
|
nowNs: BigInt(Date.now()) * 1_000_000n,
|
|
250
253
|
})
|
|
251
|
-
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)
|
|
252
265
|
}
|
|
253
266
|
|
|
254
267
|
// Run the IO path only when executed directly, so tests can import the pure fns.
|
|
@@ -256,6 +269,6 @@ const main = async () => {
|
|
|
256
269
|
// file URL (e.g. the space in the managed install dir "/Library/Application
|
|
257
270
|
// Support/…") still matches import.meta.url — a raw `file://${argv[1]}` template
|
|
258
271
|
// keeps the literal space, never matches, and silently skips main().
|
|
259
|
-
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
272
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
260
273
|
await main()
|
|
261
274
|
}
|