@mainwave/cli 0.3.2 → 0.4.0-rc.1
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 +94 -10
- package/dist/adapters/claude-code.js +3 -0
- package/dist/adapters/claude-code.js.map +1 -1
- package/dist/adapters/codex-cli.js +10 -1
- package/dist/adapters/codex-cli.js.map +1 -1
- package/dist/adapters/copilot-chat.js +13 -0
- package/dist/adapters/copilot-chat.js.map +1 -1
- package/dist/adapters/copilot-cli.js +2 -0
- package/dist/adapters/copilot-cli.js.map +1 -1
- package/dist/adapters/cursor-enterprise.js +146 -0
- package/dist/adapters/cursor-enterprise.js.map +1 -0
- package/dist/adapters/cursor.js +197 -0
- package/dist/adapters/cursor.js.map +1 -0
- package/dist/adapters/index.js +4 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/types.gen.js +3 -0
- package/dist/api/types.gen.js.map +1 -0
- package/dist/core/apply.js +258 -0
- package/dist/core/apply.js.map +1 -0
- package/dist/core/auth-commands.js +157 -0
- package/dist/core/auth-commands.js.map +1 -0
- package/dist/core/behaviour-hooks.js +101 -0
- package/dist/core/behaviour-hooks.js.map +1 -0
- package/dist/core/browser.js +41 -0
- package/dist/core/browser.js.map +1 -0
- package/dist/core/codecs/cursor-hooks-json.js +90 -0
- package/dist/core/codecs/cursor-hooks-json.js.map +1 -0
- package/dist/core/detect.js +52 -0
- package/dist/core/detect.js.map +1 -0
- package/dist/core/device-login.js +76 -0
- package/dist/core/device-login.js.map +1 -0
- package/dist/core/doctor.js +51 -2
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/errors.js +23 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/flags.js +57 -0
- package/dist/core/flags.js.map +1 -0
- package/dist/core/headers.js +15 -1
- package/dist/core/headers.js.map +1 -1
- package/dist/core/interview.js +198 -0
- package/dist/core/interview.js.map +1 -0
- package/dist/core/keys.js +41 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/markers.js +5 -1
- package/dist/core/markers.js.map +1 -1
- package/dist/core/platform.js +152 -0
- package/dist/core/platform.js.map +1 -0
- package/dist/core/prompts.js +68 -22
- package/dist/core/prompts.js.map +1 -1
- package/dist/core/status.js +25 -1
- package/dist/core/status.js.map +1 -1
- package/dist/core/store.js +118 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/tty.js +6 -0
- package/dist/core/tty.js.map +1 -1
- package/dist/core/ucid.js +25 -0
- package/dist/core/ucid.js.map +1 -0
- package/dist/core/ui.js +26 -0
- package/dist/core/ui.js.map +1 -0
- package/dist/core/use-case.js +99 -0
- package/dist/core/use-case.js.map +1 -0
- package/dist/core/validate.js +22 -0
- package/dist/core/validate.js.map +1 -1
- package/dist/core/verify.js +154 -0
- package/dist/core/verify.js.map +1 -0
- package/dist/core/wizard.js +148 -278
- package/dist/core/wizard.js.map +1 -1
- package/dist/main.js +185 -29
- package/dist/main.js.map +1 -1
- package/hooks/cursor-otlp.mjs +244 -0
- package/hooks/github-pr-marker.mjs +30 -10
- package/hooks/jira-ticket-marker.mjs +69 -17
- package/hooks/linear-ticket-marker.mjs +68 -12
- package/hooks/marker-core.mjs +5 -0
- package/hooks/vocabulary.d.mts +35 -0
- package/hooks/vocabulary.mjs +109 -0
- package/package.json +6 -3
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { input, password as passwordPrompt } from '@inquirer/prompts';
|
|
2
|
+
import { deviceLogin } from './device-login.js';
|
|
3
|
+
import { PlatformError } from './errors.js';
|
|
4
|
+
import { color } from './format.js';
|
|
5
|
+
import { login, me, publicConfig, tokenExpiry } from './platform.js';
|
|
6
|
+
import { isInteractive } from './tty.js';
|
|
7
|
+
import { activeSession, clearSession, readCredentials, readSettings, resolveEndpoints, updateSettings, writeCredentials, } from './store.js';
|
|
8
|
+
/**
|
|
9
|
+
* Which sign-in to run. Anything that names credentials — a flag, the CI env
|
|
10
|
+
* vars — means the caller has a password path in mind; otherwise a terminal
|
|
11
|
+
* gets the browser flow and a non-interactive run gets the password one, where
|
|
12
|
+
* it will fail naming the env var it needs rather than opening a browser
|
|
13
|
+
* nobody is looking at.
|
|
14
|
+
*/
|
|
15
|
+
const usesPasswordFlow = (options) => options.usePassword === true ||
|
|
16
|
+
options.email !== undefined ||
|
|
17
|
+
options.password !== undefined ||
|
|
18
|
+
process.env.MAINWAVE_EMAIL !== undefined ||
|
|
19
|
+
process.env.MAINWAVE_PASSWORD !== undefined ||
|
|
20
|
+
!isInteractive();
|
|
21
|
+
const emailOrThrow = async (given) => {
|
|
22
|
+
const value = given ?? process.env.MAINWAVE_EMAIL;
|
|
23
|
+
if (value)
|
|
24
|
+
return value;
|
|
25
|
+
if (!isInteractive()) {
|
|
26
|
+
throw new PlatformError('unauthorized', 'no email given — pass --email or set MAINWAVE_EMAIL (non-interactive run)');
|
|
27
|
+
}
|
|
28
|
+
return input({
|
|
29
|
+
message: 'Mainwave email:',
|
|
30
|
+
validate: (v) => v.trim().length > 0 || 'email is required',
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const passwordOrThrow = async (given) => {
|
|
34
|
+
const value = given ?? process.env.MAINWAVE_PASSWORD;
|
|
35
|
+
if (value)
|
|
36
|
+
return value;
|
|
37
|
+
if (!isInteractive()) {
|
|
38
|
+
throw new PlatformError('unauthorized', 'no password given — set MAINWAVE_PASSWORD (non-interactive run)');
|
|
39
|
+
}
|
|
40
|
+
return passwordPrompt({
|
|
41
|
+
message: 'Password:',
|
|
42
|
+
mask: '•',
|
|
43
|
+
validate: (v) => v.length > 0 || 'password is required',
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const passwordLogin = async (apiUrl, options) => {
|
|
47
|
+
const email = await emailOrThrow(options.email);
|
|
48
|
+
const password = await passwordOrThrow(options.password);
|
|
49
|
+
return (await login(apiUrl, { email, password })).access_token;
|
|
50
|
+
};
|
|
51
|
+
export const runLogin = async (options = {}) => {
|
|
52
|
+
const settings = await readSettings();
|
|
53
|
+
const { apiUrl } = resolveEndpoints(settings, { apiUrl: options.apiUrl });
|
|
54
|
+
const existing = activeSession(await readCredentials(), apiUrl);
|
|
55
|
+
if (existing && !options.force) {
|
|
56
|
+
if (options.json) {
|
|
57
|
+
console.log(JSON.stringify({ status: 'already-signed-in', email: existing.email, apiUrl }));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.log(color.green(`✓ already signed in as ${existing.email}`));
|
|
61
|
+
console.log(color.dim(' re-authenticate with `mainwave-cli login --force`'));
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
const token = usesPasswordFlow(options)
|
|
66
|
+
? await passwordLogin(apiUrl, options)
|
|
67
|
+
: await deviceLogin(apiUrl, {
|
|
68
|
+
noBrowser: options.noBrowser,
|
|
69
|
+
timeoutMs: options.deviceTimeoutMs,
|
|
70
|
+
});
|
|
71
|
+
// One round-trip each for who this is and where their telemetry goes, so the
|
|
72
|
+
// rest of the flow — and `verify`'s deep link — needs no further lookups.
|
|
73
|
+
const profile = await me(apiUrl, token);
|
|
74
|
+
const endpoints = await publicConfig(apiUrl, token);
|
|
75
|
+
const session = {
|
|
76
|
+
token,
|
|
77
|
+
expiresAt: tokenExpiry(token),
|
|
78
|
+
apiUrl,
|
|
79
|
+
email: profile.email,
|
|
80
|
+
orgId: profile.org_id,
|
|
81
|
+
};
|
|
82
|
+
const credentials = await readCredentials();
|
|
83
|
+
await writeCredentials({ ...credentials, session });
|
|
84
|
+
await updateSettings({
|
|
85
|
+
apiUrl,
|
|
86
|
+
appUrl: endpoints.app_url,
|
|
87
|
+
collectorUrl: endpoints.collector_url,
|
|
88
|
+
email: profile.email,
|
|
89
|
+
orgId: profile.org_id,
|
|
90
|
+
});
|
|
91
|
+
if (options.json) {
|
|
92
|
+
console.log(JSON.stringify({
|
|
93
|
+
status: 'signed-in',
|
|
94
|
+
email: profile.email,
|
|
95
|
+
orgId: profile.org_id,
|
|
96
|
+
apiUrl,
|
|
97
|
+
appUrl: endpoints.app_url,
|
|
98
|
+
collectorUrl: endpoints.collector_url,
|
|
99
|
+
expiresAt: session.expiresAt,
|
|
100
|
+
}));
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
console.log(color.green(`✓ signed in as ${profile.email}`));
|
|
104
|
+
console.log(color.dim(` collector: ${endpoints.collector_url}`));
|
|
105
|
+
return 0;
|
|
106
|
+
};
|
|
107
|
+
export const runLogout = async (options = {}) => {
|
|
108
|
+
const before = (await readCredentials()).session;
|
|
109
|
+
await clearSession();
|
|
110
|
+
// Minted keys survive a logout on purpose: they are the credential the
|
|
111
|
+
// configured tools are still using, and dropping them would leave the CLI
|
|
112
|
+
// unable to tell a re-run that this machine already has a key.
|
|
113
|
+
if (options.json) {
|
|
114
|
+
console.log(JSON.stringify({ status: before ? 'signed-out' : 'not-signed-in' }));
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
console.log(before ? color.green('✓ signed out') : color.dim('not signed in'));
|
|
118
|
+
return 0;
|
|
119
|
+
};
|
|
120
|
+
export const runWhoami = async (options = {}) => {
|
|
121
|
+
const settings = await readSettings();
|
|
122
|
+
const endpoints = resolveEndpoints(settings, { apiUrl: options.apiUrl });
|
|
123
|
+
const session = activeSession(await readCredentials(), endpoints.apiUrl);
|
|
124
|
+
if (!session) {
|
|
125
|
+
if (options.json) {
|
|
126
|
+
console.log(JSON.stringify({ signedIn: false, ...endpoints }));
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
console.log(color.dim('not signed in — run `mainwave-cli login`'));
|
|
130
|
+
return 1;
|
|
131
|
+
}
|
|
132
|
+
if (options.json) {
|
|
133
|
+
console.log(JSON.stringify({
|
|
134
|
+
signedIn: true,
|
|
135
|
+
email: session.email,
|
|
136
|
+
orgId: session.orgId,
|
|
137
|
+
orgName: settings.orgName,
|
|
138
|
+
expiresAt: session.expiresAt,
|
|
139
|
+
useCase: settings.useCase,
|
|
140
|
+
...endpoints,
|
|
141
|
+
}));
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
console.log(`${color.bold('user')} ${session.email}`);
|
|
145
|
+
console.log(`${color.bold('org')} ${settings.orgName ?? session.orgId ?? '—'}`);
|
|
146
|
+
if (settings.useCase) {
|
|
147
|
+
console.log(`${color.bold('use case')} ${settings.useCase.name ?? settings.useCase.id} (${settings.useCase.id})`);
|
|
148
|
+
}
|
|
149
|
+
console.log(`${color.bold('api')} ${endpoints.apiUrl}`);
|
|
150
|
+
console.log(`${color.bold('app')} ${endpoints.appUrl}`);
|
|
151
|
+
console.log(`${color.bold('collector')} ${endpoints.collectorUrl}`);
|
|
152
|
+
if (session.expiresAt) {
|
|
153
|
+
console.log(color.dim(`session expires ${session.expiresAt}`));
|
|
154
|
+
}
|
|
155
|
+
return 0;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=auth-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-commands.js","sourceRoot":"","sources":["../../src/core/auth-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAuCnB;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG,CAAC,OAAqB,EAA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O,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAA;IAC7D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,SAAS,CAAC,MAAM,EAAE,CAAC,CAAA;IAC7D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,YAAY,EAAE,CAAC,CAAA;IACnE,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;IAChE,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { parseManagedByVersion, scriptPathFromCommand } from './markers.js';
|
|
4
|
+
import { readExistingEnv } from './settings.js';
|
|
5
|
+
/** Read every declared hooks layer and pull out the commands this adapter owns. */
|
|
6
|
+
export const scanBehaviourHooks = async (cap) => {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const layer of cap.layers) {
|
|
9
|
+
if (layer.kind !== 'file')
|
|
10
|
+
continue;
|
|
11
|
+
try {
|
|
12
|
+
const env = await readExistingEnv(layer.path, cap.codec);
|
|
13
|
+
if (env === null) {
|
|
14
|
+
out.push({ layerId: layer.id, path: layer.path, status: 'absent', commands: [] });
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const commands = [...new Set(Object.values(env))];
|
|
18
|
+
out.push({
|
|
19
|
+
layerId: layer.id,
|
|
20
|
+
path: layer.path,
|
|
21
|
+
status: commands.length > 0 ? 'present' : 'absent',
|
|
22
|
+
commands,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
out.push({
|
|
27
|
+
layerId: layer.id,
|
|
28
|
+
path: layer.path,
|
|
29
|
+
status: 'error',
|
|
30
|
+
commands: [],
|
|
31
|
+
error: err instanceof Error ? err.message : String(err),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Issues for the behaviour-hook registration: not configured anywhere, a stale
|
|
39
|
+
* version stamp after a CLI upgrade, a registered command whose script is gone
|
|
40
|
+
* (it no-ops silently, fail-open), a managed/enterprise-tier registration the
|
|
41
|
+
* user should know overrides their own, and an unparseable hooks file.
|
|
42
|
+
*/
|
|
43
|
+
export const collectBehaviourHookIssues = async (cap, currentVersion, scan = scanBehaviourHooks) => {
|
|
44
|
+
const scans = await scan(cap);
|
|
45
|
+
const issues = [];
|
|
46
|
+
for (const s of scans) {
|
|
47
|
+
if (s.status === 'error') {
|
|
48
|
+
issues.push({
|
|
49
|
+
level: 'warn',
|
|
50
|
+
message: `Cursor hooks file could not be parsed: ${s.path} — ${s.error ?? 'invalid JSON'}.`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const present = scans.filter((s) => s.status === 'present');
|
|
55
|
+
if (present.length === 0) {
|
|
56
|
+
issues.push({
|
|
57
|
+
level: 'info',
|
|
58
|
+
message: 'Cursor behaviour hook is not registered in any hooks.json layer — re-run `mainwave-cli setup cursor` to enable it.',
|
|
59
|
+
});
|
|
60
|
+
return issues;
|
|
61
|
+
}
|
|
62
|
+
for (const s of present) {
|
|
63
|
+
for (const command of s.commands) {
|
|
64
|
+
const version = parseManagedByVersion(command);
|
|
65
|
+
if (version !== undefined && version !== currentVersion) {
|
|
66
|
+
issues.push({
|
|
67
|
+
level: 'warn',
|
|
68
|
+
message: `Cursor hook in ${s.path} was written by @mainwave/cli@${version}; you are running ${currentVersion}. ` +
|
|
69
|
+
'Re-run `mainwave-cli setup cursor` to refresh it — a stale registration can silently stop emitting.',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const script = scriptPathFromCommand(command);
|
|
73
|
+
if (script !== undefined) {
|
|
74
|
+
try {
|
|
75
|
+
await fs.access(script);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
issues.push({
|
|
79
|
+
level: 'error',
|
|
80
|
+
message: `Cursor hook script is missing: ${script} — the hook no-ops silently (fail-open). Re-run \`mainwave-cli setup cursor\`.`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (basename(script) !== cap.script) {
|
|
84
|
+
issues.push({
|
|
85
|
+
level: 'warn',
|
|
86
|
+
message: `Cursor hook in ${s.path} points at ${basename(script)}, not the expected ${cap.script}. ` +
|
|
87
|
+
'Re-run setup to refresh the registration.',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (s.layerId === 'managed') {
|
|
93
|
+
issues.push({
|
|
94
|
+
level: 'info',
|
|
95
|
+
message: `Cursor behaviour hook is pinned by managed/enterprise settings (${s.path}) — it applies to every user on this machine and can't be changed without admin access.`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return issues;
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=behaviour-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behaviour-hooks.js","sourceRoot":"","sources":["../../src/core/behaviour-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AA2B/C,mFAAmF;AACnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,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;iBACxG,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAA;YAC7C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,CAAC;oBACH,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBACzB,CAAC;gBAAC,MAAM,CAAC;oBACP,MAAM,CAAC,IAAI,CAAC;wBACV,KAAK,EAAE,OAAO;wBACd,OAAO,EAAE,kCAAkC,MAAM,gFAAgF;qBAClI,CAAC,CAAA;gBACJ,CAAC;gBACD,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;oBACpC,MAAM,CAAC,IAAI,CAAC;wBACV,KAAK,EAAE,MAAM;wBACb,OAAO,EACL,kBAAkB,CAAC,CAAC,IAAI,cAAc,QAAQ,CAAC,MAAM,CAAC,sBAAsB,GAAG,CAAC,MAAM,IAAI;4BAC1F,2CAA2C;qBAC9C,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,CAAC,IAAI,CAAC;gBACV,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,mEAAmE,CAAC,CAAC,IAAI,yFAAyF;aAC5K,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { platform as osPlatform } from 'node:os';
|
|
3
|
+
/**
|
|
4
|
+
* Opening the developer's browser (MAI-1423).
|
|
5
|
+
*
|
|
6
|
+
* Used by `login` to put the approval page in front of them instead of making
|
|
7
|
+
* them copy a URL. Best-effort by design: an SSH session, a headless CI box, or
|
|
8
|
+
* a machine with no handler registered all fail here, and the caller falls back
|
|
9
|
+
* to printing the URL — a failed `xdg-open` must never be the reason a sign-in
|
|
10
|
+
* stops.
|
|
11
|
+
*
|
|
12
|
+
* Spawned detached and fully de-piped so the child (which can outlive the CLI,
|
|
13
|
+
* and on Linux is usually a whole desktop browser) never holds our stdio or
|
|
14
|
+
* keeps the event loop alive.
|
|
15
|
+
*/
|
|
16
|
+
const opener = () => {
|
|
17
|
+
const platform = osPlatform();
|
|
18
|
+
if (platform === 'darwin')
|
|
19
|
+
return { command: 'open', args: [] };
|
|
20
|
+
// `start` is a cmd builtin, not an executable; the empty string is its
|
|
21
|
+
// window-title argument, without which a quoted URL becomes the title.
|
|
22
|
+
if (platform === 'win32')
|
|
23
|
+
return { command: 'cmd', args: ['/c', 'start', ''] };
|
|
24
|
+
return { command: 'xdg-open', args: [] };
|
|
25
|
+
};
|
|
26
|
+
/** True when a browser was handed the URL; false when the caller should print it. */
|
|
27
|
+
export const openUrl = (url) => {
|
|
28
|
+
const { command, args } = opener();
|
|
29
|
+
try {
|
|
30
|
+
const child = spawn(command, [...args, url], { detached: true, stdio: 'ignore' });
|
|
31
|
+
// An ENOENT arrives asynchronously and would otherwise reach the process as
|
|
32
|
+
// an unhandled 'error' event — a crash, for a convenience.
|
|
33
|
+
child.on('error', () => undefined);
|
|
34
|
+
child.unref();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/core/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,GAAG,GAAwC,EAAE;IACvD,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAA;IAC7B,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;IAC/D,uEAAuE;IACvE,uEAAuE;IACvE,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,CAAA;IAC9E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;AAC1C,CAAC,CAAA;AAED,qFAAqF;AACrF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAW,EAAE;IAC9C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAA;IAClC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;QACjF,4EAA4E;QAC5E,2DAA2D;QAC3D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAClC,KAAK,CAAC,KAAK,EAAE,CAAA;QACb,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { commandOwnership } from '../markers.js';
|
|
2
|
+
const isPlainObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
3
|
+
const isHookEntry = (v) => isPlainObject(v) && typeof v.command === 'string';
|
|
4
|
+
/** The hooks object on a parsed doc, or {} when absent/malformed. */
|
|
5
|
+
const hooksOf = (doc) => {
|
|
6
|
+
const hooks = doc.hooks;
|
|
7
|
+
if (!isPlainObject(hooks))
|
|
8
|
+
return {};
|
|
9
|
+
const out = {};
|
|
10
|
+
for (const [event, entries] of Object.entries(hooks)) {
|
|
11
|
+
if (Array.isArray(entries))
|
|
12
|
+
out[event] = entries;
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
};
|
|
16
|
+
/** `hooks.<event>` → event name; undefined for any other key shape. */
|
|
17
|
+
const eventOfKey = (key) => key.startsWith('hooks.') ? key.slice('hooks.'.length) : undefined;
|
|
18
|
+
const parse = (body, path) => {
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(body);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
throw new Error(`failed to parse ${path} as JSON: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
if (!isPlainObject(parsed)) {
|
|
27
|
+
throw new Error(`${path}: expected a JSON object at the top level`);
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
};
|
|
31
|
+
const serialize = (doc) => {
|
|
32
|
+
if (!isPlainObject(doc))
|
|
33
|
+
throw new Error('expected a Cursor hooks document');
|
|
34
|
+
return JSON.stringify(doc, null, 2) + '\n';
|
|
35
|
+
};
|
|
36
|
+
const empty = () => ({ version: 1, hooks: {} });
|
|
37
|
+
const readEnv = (doc) => {
|
|
38
|
+
if (!isPlainObject(doc))
|
|
39
|
+
throw new Error('expected a Cursor hooks document');
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const [event, entries] of Object.entries(hooksOf(doc))) {
|
|
42
|
+
// Surface only the entry we own, so a re-run compares our command — not a
|
|
43
|
+
// foreign hook that happens to share the event — for change detection.
|
|
44
|
+
const owned = entries.find((e) => isHookEntry(e) && commandOwnership(e.command) !== null);
|
|
45
|
+
if (isHookEntry(owned))
|
|
46
|
+
out[`hooks.${event}`] = owned.command;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
};
|
|
50
|
+
const applyEnv = (doc, newEnv, managedKeys) => {
|
|
51
|
+
const base = isPlainObject(doc) ? structuredClone(doc) : {};
|
|
52
|
+
if (typeof base.version !== 'number')
|
|
53
|
+
base.version = 1;
|
|
54
|
+
const hooks = isPlainObject(base.hooks) ? { ...base.hooks } : {};
|
|
55
|
+
// Strip every entry we own from the events this adapter manages, so opting an
|
|
56
|
+
// event out (its key absent from newEnv) removes our hook while foreign hooks
|
|
57
|
+
// on the same event survive. An event left with no entries is dropped.
|
|
58
|
+
for (const key of managedKeys) {
|
|
59
|
+
const event = eventOfKey(key);
|
|
60
|
+
if (event === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
const entries = hooks[event];
|
|
63
|
+
if (!Array.isArray(entries))
|
|
64
|
+
continue;
|
|
65
|
+
const kept = entries.filter((e) => !(isHookEntry(e) && commandOwnership(e.command) !== null));
|
|
66
|
+
if (kept.length > 0)
|
|
67
|
+
hooks[event] = kept;
|
|
68
|
+
else
|
|
69
|
+
delete hooks[event];
|
|
70
|
+
}
|
|
71
|
+
// Append our fresh entry for each enabled event.
|
|
72
|
+
for (const [key, command] of Object.entries(newEnv)) {
|
|
73
|
+
const event = eventOfKey(key);
|
|
74
|
+
if (event === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
const existing = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
77
|
+
hooks[event] = [...existing, { command, type: 'command' }];
|
|
78
|
+
}
|
|
79
|
+
base.hooks = hooks;
|
|
80
|
+
return base;
|
|
81
|
+
};
|
|
82
|
+
export const cursorHooksJsonCodec = {
|
|
83
|
+
format: 'json',
|
|
84
|
+
parse,
|
|
85
|
+
serialize,
|
|
86
|
+
empty,
|
|
87
|
+
readEnv,
|
|
88
|
+
applyEnv,
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=cursor-hooks-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor-hooks-json.js","sourceRoot":"","sources":["../../../src/core/codecs/cursor-hooks-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAg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ACpD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QACjC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,KAAK,CAAe,CAAC,CAAC,CAAC,EAAE,CAAA;QAC/E,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IAClB,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IACjD,MAAM,EAAE,MAAM;IACd,KAAK;IACL,SAAS;IACT,KAAK;IACL,OAAO;IACP,QAAQ;CACT,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { platform as osPlatform } from 'node:os';
|
|
4
|
+
/**
|
|
5
|
+
* Machine-detection primitives for the adapter `detect` hook (MAI-1422).
|
|
6
|
+
*
|
|
7
|
+
* Detection answers "is this tool plausibly installed here?" so bare `setup` can
|
|
8
|
+
* pre-check the tools a developer actually uses instead of making them guess
|
|
9
|
+
* adapter names. It is a convenience, never a gate: an undetected adapter is
|
|
10
|
+
* still listed and still selectable, because every heuristic here has false
|
|
11
|
+
* negatives (a tool installed but never launched leaves no config dir; a binary
|
|
12
|
+
* behind a shell alias isn't on the spawned PATH).
|
|
13
|
+
*
|
|
14
|
+
* Both probes are deliberately cheap and side-effect free — bare `setup` calls
|
|
15
|
+
* every adapter's `detect` before printing its first prompt.
|
|
16
|
+
*/
|
|
17
|
+
/** True when the path exists (file or directory). */
|
|
18
|
+
export const hasPath = (path) => existsSync(path);
|
|
19
|
+
/**
|
|
20
|
+
* True when `name` resolves on PATH. Uses the platform's own resolver rather
|
|
21
|
+
* than walking PATH by hand, so PATHEXT on Windows and shell-agnostic lookups on
|
|
22
|
+
* POSIX behave the way the tool's own launcher does. A missing resolver, a
|
|
23
|
+
* timeout, or any spawn failure reads as "not found" — detection never blocks
|
|
24
|
+
* setup on an unrelated environment problem.
|
|
25
|
+
*/
|
|
26
|
+
export const hasBinary = (name) => {
|
|
27
|
+
const finder = osPlatform() === 'win32' ? 'where' : 'which';
|
|
28
|
+
try {
|
|
29
|
+
const r = spawnSync(finder, [name], { encoding: 'utf8', timeout: 2000, stdio: 'ignore' });
|
|
30
|
+
return r.status === 0;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* True when `dir` holds an entry whose name starts with `prefix`.
|
|
38
|
+
*
|
|
39
|
+
* The probe for anything stored under a versioned directory name — a VS Code
|
|
40
|
+
* extension is `<publisher>.<name>-<version>`, so the version rules out a fixed
|
|
41
|
+
* path. A missing or unreadable directory reads as "not found", exactly as
|
|
42
|
+
* `hasPath` does for a missing path.
|
|
43
|
+
*/
|
|
44
|
+
export const hasEntryPrefixed = (dir, prefix) => {
|
|
45
|
+
try {
|
|
46
|
+
return readdirSync(dir).some((entry) => entry.startsWith(prefix));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/core/detect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAA;AAEhD;;;;;;;;;;;;GAYG;AAEH,qDAAqD;AACrD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAElE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;IACjD,MAAM,MAAM,GAAG,UAAU,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IAC3D,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;QACzF,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,MAAc,EAAW,EAAE;IACvE,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { hostname } from 'node:os';
|
|
2
|
+
import { openUrl } from './browser.js';
|
|
3
|
+
import { PlatformError, WizardAbort } from './errors.js';
|
|
4
|
+
import { color } from './format.js';
|
|
5
|
+
import { pollDeviceToken, requestDeviceCode } from './platform.js';
|
|
6
|
+
import { say } from './ui.js';
|
|
7
|
+
import { VERSION } from './version.js';
|
|
8
|
+
/**
|
|
9
|
+
* Browser sign-in for the terminal (MAI-1423).
|
|
10
|
+
*
|
|
11
|
+
* The CLI asks the platform for a pair of codes, shows the short one and opens
|
|
12
|
+
* the app at the page that approves it, then polls until a human decides. No
|
|
13
|
+
* password is typed into a terminal and the CLI never handles one — the session
|
|
14
|
+
* it ends up with was granted by the developer inside their own browser session.
|
|
15
|
+
*
|
|
16
|
+
* The poll follows RFC 8628: keep going on `authorization_pending`, back off on
|
|
17
|
+
* `slow_down`, stop immediately on `access_denied` or `expired_token`.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_TIMEOUT_MS = 5 * 60_000;
|
|
20
|
+
const MIN_INTERVAL_MS = 1000;
|
|
21
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
22
|
+
/**
|
|
23
|
+
* Runs the flow to a session token, or throws a `WizardAbort` naming what the
|
|
24
|
+
* developer needs to know: denial, expiry, or a wait that ran out.
|
|
25
|
+
*/
|
|
26
|
+
export const deviceLogin = async (apiUrl, options = {}) => {
|
|
27
|
+
const code = await requestDeviceCode(apiUrl, {
|
|
28
|
+
// Self-reported, and shown on the approval page: the developer's check that
|
|
29
|
+
// the request is the one they just started on this machine.
|
|
30
|
+
machine: hostname(),
|
|
31
|
+
client_version: VERSION,
|
|
32
|
+
});
|
|
33
|
+
say('');
|
|
34
|
+
say(` Your code: ${color.bold(code.user_code)}`);
|
|
35
|
+
say('');
|
|
36
|
+
const opened = options.noBrowser ? false : openUrl(code.verification_uri_complete);
|
|
37
|
+
say(opened
|
|
38
|
+
? color.dim(`Opened ${code.verification_uri_complete} — approve the code there.`)
|
|
39
|
+
: `Open ${color.bold(code.verification_uri_complete)} and approve the code.`);
|
|
40
|
+
say(color.dim('Waiting for approval…'));
|
|
41
|
+
// The server hands out the cadence; a client that ignores it is told to slow
|
|
42
|
+
// down, so honour it rather than picking our own.
|
|
43
|
+
let intervalMs = Math.max(code.interval * 1000, MIN_INTERVAL_MS);
|
|
44
|
+
const deadline = Date.now() + Math.min(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, code.expires_in * 1000);
|
|
45
|
+
for (;;) {
|
|
46
|
+
await sleep(intervalMs);
|
|
47
|
+
let result;
|
|
48
|
+
try {
|
|
49
|
+
result = await pollDeviceToken(apiUrl, code.device_code);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
// A blip in the platform shouldn't end a sign-in the developer may be
|
|
53
|
+
// seconds from approving — keep polling until the deadline, and let
|
|
54
|
+
// anything that isn't a reachability problem surface.
|
|
55
|
+
if (err instanceof PlatformError && err.reason === 'unreachable' && Date.now() < deadline) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
if ('token' in result)
|
|
61
|
+
return result.token;
|
|
62
|
+
if (result.error === 'access_denied') {
|
|
63
|
+
throw new WizardAbort('sign-in was denied in the browser');
|
|
64
|
+
}
|
|
65
|
+
if (result.error === 'expired_token') {
|
|
66
|
+
throw new WizardAbort('that code expired — run `mainwave-cli login` again');
|
|
67
|
+
}
|
|
68
|
+
if (result.error === 'slow_down') {
|
|
69
|
+
intervalMs = Math.max((result.interval ?? code.interval) * 1000, intervalMs + 1000);
|
|
70
|
+
}
|
|
71
|
+
if (Date.now() >= deadline) {
|
|
72
|
+
throw new WizardAbort('timed out waiting for approval — run `mainwave-cli login` again, or use --password');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=device-login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-login.js","sourceRoot":"","sources":["../../src/core/device-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM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I,EAAE,UAAU,GAAG,IAAI,CAAC,CAAA;QACrF,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,WAAW,CACnB,oFAAoF,CACrF,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
|
package/dist/core/doctor.js
CHANGED
|
@@ -4,8 +4,10 @@ import { envFileCodec } from './codecs/env-file.js';
|
|
|
4
4
|
import { computeEffective } from './effective-settings.js';
|
|
5
5
|
import { ValidateError } from './errors.js';
|
|
6
6
|
import { color, maskForDisplay } from './format.js';
|
|
7
|
+
import { collectBehaviourHookIssues } from './behaviour-hooks.js';
|
|
7
8
|
import { collectMarkerIssues, readPackagedMatchers, scanForMarkers } from './markers.js';
|
|
8
9
|
import { readExistingEnv } from './settings.js';
|
|
10
|
+
import { emitJson } from './ui.js';
|
|
9
11
|
import { validateCollector } from './validate.js';
|
|
10
12
|
import { VERSION } from './version.js';
|
|
11
13
|
const renderFiles = (effective, hierarchy) => {
|
|
@@ -302,7 +304,33 @@ const runValidate = async (effective, adapter) => {
|
|
|
302
304
|
throw err;
|
|
303
305
|
}
|
|
304
306
|
};
|
|
307
|
+
/**
|
|
308
|
+
* Same walk as the rendered report, as data. Values go through `maskForDisplay`
|
|
309
|
+
* exactly as the text form does — a JSON consumer is not a reason to hand a live
|
|
310
|
+
* bearer token to a log aggregator.
|
|
311
|
+
*/
|
|
312
|
+
const doctorJson = async (adapter, effective, issues, validation) => ({
|
|
313
|
+
adapter: adapter.name,
|
|
314
|
+
displayName: adapter.displayName,
|
|
315
|
+
files: effective.scans.map((scan) => ({
|
|
316
|
+
layer: scan.layer.id,
|
|
317
|
+
path: scan.path,
|
|
318
|
+
status: scan.status,
|
|
319
|
+
})),
|
|
320
|
+
effective: adapter.managedEnvKeys
|
|
321
|
+
.map((key) => effective.effective[key])
|
|
322
|
+
.filter((entry) => entry !== undefined)
|
|
323
|
+
.map((entry) => ({
|
|
324
|
+
key: entry.key,
|
|
325
|
+
value: maskForDisplay(entry.key, entry.value),
|
|
326
|
+
layer: entry.source.layer.id,
|
|
327
|
+
})),
|
|
328
|
+
issues: issues.map((issue) => ({ level: issue.level, message: issue.message })),
|
|
329
|
+
validation,
|
|
330
|
+
});
|
|
305
331
|
export const runDoctor = async (adapter, options = {}) => {
|
|
332
|
+
if (options.json)
|
|
333
|
+
return runDoctorJson(adapter, options);
|
|
306
334
|
console.log(color.bold(`mainwave-cli doctor — ${adapter.displayName}`));
|
|
307
335
|
console.log();
|
|
308
336
|
const effective = await computeEffective(adapter);
|
|
@@ -322,7 +350,12 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
322
350
|
const markerIssues = adapter.markers
|
|
323
351
|
? await collectMarkerIssues(await scanForMarkers(adapter.hierarchy), VERSION, await readPackagedMatchers())
|
|
324
352
|
: [];
|
|
325
|
-
|
|
353
|
+
// Behaviour-hook checks (MAI-1435): walk every hooks.json layer — including the
|
|
354
|
+
// enterprise tier — for the adapter's own registered hook (Cursor).
|
|
355
|
+
const behaviourHookIssues = adapter.behaviourHooks
|
|
356
|
+
? await collectBehaviourHookIssues(adapter.behaviourHooks, VERSION)
|
|
357
|
+
: [];
|
|
358
|
+
renderChecks([...issues, ...shellEnvIssues, ...markerIssues, ...behaviourHookIssues]);
|
|
326
359
|
let validateFailed = false;
|
|
327
360
|
if (options.validate) {
|
|
328
361
|
console.log();
|
|
@@ -336,7 +369,23 @@ export const runDoctor = async (adapter, options = {}) => {
|
|
|
336
369
|
validateFailed = true;
|
|
337
370
|
}
|
|
338
371
|
}
|
|
339
|
-
const hasError = [...issues, ...shellEnvIssues, ...markerIssues].some((i) => i.level === 'error');
|
|
372
|
+
const hasError = [...issues, ...shellEnvIssues, ...markerIssues, ...behaviourHookIssues].some((i) => i.level === 'error');
|
|
340
373
|
return hasError || validateFailed ? 1 : 0;
|
|
341
374
|
};
|
|
375
|
+
const runDoctorJson = async (adapter, options) => {
|
|
376
|
+
const effective = await computeEffective(adapter);
|
|
377
|
+
const issues = [
|
|
378
|
+
...collectIssues(effective, adapter),
|
|
379
|
+
...(await checkShellEnv(adapter)),
|
|
380
|
+
...(adapter.markers
|
|
381
|
+
? await collectMarkerIssues(await scanForMarkers(adapter.hierarchy), VERSION, await readPackagedMatchers())
|
|
382
|
+
: []),
|
|
383
|
+
...(adapter.behaviourHooks
|
|
384
|
+
? await collectBehaviourHookIssues(adapter.behaviourHooks, VERSION)
|
|
385
|
+
: []),
|
|
386
|
+
];
|
|
387
|
+
const validation = options.validate ? await runValidate(effective, adapter) : undefined;
|
|
388
|
+
emitJson(await doctorJson(adapter, effective, issues, validation));
|
|
389
|
+
return issues.some((i) => i.level === 'error') || validation?.ok === false ? 1 : 0;
|
|
390
|
+
};
|
|
342
391
|
//# sourceMappingURL=doctor.js.map
|