launch-doctor 0.4.2 → 0.4.4
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/CHANGELOG.md +54 -1
- package/README.md +30 -6
- package/dist/src/baseline.d.ts +9 -0
- package/dist/src/baseline.js +26 -0
- package/dist/src/checks/email.js +3 -1
- package/dist/src/checks/secrets.js +3 -1
- package/dist/src/cli.js +240 -88
- package/dist/src/core.d.ts +85 -0
- package/dist/src/core.js +166 -0
- package/dist/src/explanations.d.ts +24 -0
- package/dist/src/explanations.js +562 -0
- package/dist/src/git.d.ts +1 -1
- package/dist/src/git.js +6 -3
- package/dist/src/hooks-setup.js +19 -6
- package/dist/src/index.js +2 -1
- package/dist/src/init.d.ts +17 -0
- package/dist/src/init.js +73 -6
- package/dist/src/live.js +3 -0
- package/dist/src/mcp.d.ts +126 -11
- package/dist/src/mcp.js +294 -148
- package/dist/src/prompt.d.ts +9 -0
- package/dist/src/prompt.js +84 -0
- package/dist/src/report-md.d.ts +14 -0
- package/dist/src/report-md.js +71 -0
- package/dist/src/safe-fs.d.ts +9 -0
- package/dist/src/safe-fs.js +27 -1
- package/dist/src/short-report.d.ts +2 -0
- package/dist/src/short-report.js +5 -0
- package/dist/src/types.d.ts +6 -0
- package/package.json +2 -2
package/dist/src/cli.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { appendFileSync, existsSync,
|
|
2
|
+
import { appendFileSync, existsSync, statSync } from 'node:fs';
|
|
3
3
|
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { shouldShowBanner } from './banner.js';
|
|
4
5
|
import { applyBaseline, BASELINE_FILE, loadBaseline, writeBaseline } from './baseline.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { shortWhere } from './checks/common.js';
|
|
7
|
+
import { CoreError, changedPaths, findFinding, findingDetails, gradeHistory, projectRoot, promptNumber, scan as scanProject, withDemo, } from './core.js';
|
|
8
|
+
import { removeOnSignal } from './demo.js';
|
|
7
9
|
import { renderFixes } from './fixes.js';
|
|
8
|
-
import { explainGitHubError, postPrFeedback, prContextFromEnv } from './github.js';
|
|
9
10
|
import { git } from './git.js';
|
|
11
|
+
import { explainGitHubError, postPrFeedback, prContextFromEnv } from './github.js';
|
|
10
12
|
import { failingFindings } from './grade.js';
|
|
11
13
|
import { BADGE_FILE, describeEntry, entryFor, GRADES_FILE, headCommit, loadGrades, recordGrade, renderGradeTable, } from './grades.js';
|
|
12
|
-
import { shouldShowBanner } from './banner.js';
|
|
13
14
|
import { DEFAULT_HISTORY_DEPTH } from './history.js';
|
|
14
15
|
import { runHook } from './hook.js';
|
|
15
16
|
import { pinnedPackage, setupHooks, upgradeHooks } from './hooks-setup.js';
|
|
16
|
-
import { CATEGORY_IDS
|
|
17
|
-
import { badgeUrl, GRADES_BRANCH, githubRepo, runInit } from './init.js';
|
|
17
|
+
import { CATEGORY_IDS } from './index.js';
|
|
18
|
+
import { badgeUrl, ensureGitignore, GRADES_BRANCH, githubRepo, mcpSetupText, runInit, windowsPackage } from './init.js';
|
|
18
19
|
import { runLiveScan } from './live.js';
|
|
19
20
|
import { runMcpServer } from './mcp.js';
|
|
20
21
|
import { assertConfigRef } from './project.js';
|
|
21
|
-
import { copyToClipboard,
|
|
22
|
-
import { bold, dim, renderReport } from './report.js';
|
|
23
|
-
import {
|
|
22
|
+
import { copyToClipboard, separateProjects, separateProjectsNote, unsupportedLanguage } from './prompt.js';
|
|
23
|
+
import { bold, dim, renderReport, wrap } from './report.js';
|
|
24
|
+
import { REPORT_FILE, renderReportMd } from './report-md.js';
|
|
25
|
+
import { writeInside, writeRegularFile } from './safe-fs.js';
|
|
24
26
|
import { renderSarif } from './sarif.js';
|
|
25
27
|
import { renderEmptyFolder, renderOtherLanguage, renderShortReport } from './short-report.js';
|
|
26
28
|
import { renderStepSummary } from './summary.js';
|
|
@@ -35,7 +37,10 @@ const HELP = `
|
|
|
35
37
|
npx launch-doctor init --hooks --upgrade
|
|
36
38
|
Move those hooks onto this version (only the launch-doctor command changes)
|
|
37
39
|
npx launch-doctor init --monitor Add a GitHub Actions workflow that re-checks the project every week
|
|
40
|
+
npx launch-doctor init --mcp Print the setup for Claude Code, Cursor and Claude Desktop (changes nothing)
|
|
38
41
|
npx launch-doctor grades [folder] Show the grades saved with --record
|
|
42
|
+
npx launch-doctor explain <n> [folder]
|
|
43
|
+
What finding n means: why it matters, how to confirm and fix it
|
|
39
44
|
npx launch-doctor prompt <n> [folder] [--copy]
|
|
40
45
|
Print fix prompt n (the numbers in the report and LAUNCH_FIXES.md)
|
|
41
46
|
npx launch-doctor scan <url> Check your deployed site (exposed files, source maps, open Supabase tables, headers)
|
|
@@ -66,10 +71,12 @@ const HELP = `
|
|
|
66
71
|
--staged Only report on files staged for the next commit (for a pre-commit hook)
|
|
67
72
|
--demo Scan a built-in sample app full of mistakes
|
|
68
73
|
--verbose Show the full report: every category and every finding
|
|
74
|
+
--report Also write .launchdoctor/report.md: every finding explained, with its fix prompt number
|
|
69
75
|
--copy With prompt <n>, copy the fix prompt to the clipboard
|
|
70
76
|
--no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
|
|
71
77
|
-h, --help Show this help
|
|
72
78
|
-v, --version Show the version
|
|
79
|
+
-- End of the options: what follows is the folder, even if its name starts with "-"
|
|
73
80
|
|
|
74
81
|
${bold('Live site')}
|
|
75
82
|
npx launch-doctor scan <url> --no-db Run "launch-doctor scan --help" for the options
|
|
@@ -103,6 +110,7 @@ function parseArgs(argv) {
|
|
|
103
110
|
offline: false,
|
|
104
111
|
ci: false,
|
|
105
112
|
failOn: 'critical',
|
|
113
|
+
failOnSet: false,
|
|
106
114
|
prComment: false,
|
|
107
115
|
updateBaseline: false,
|
|
108
116
|
baseline: true,
|
|
@@ -112,9 +120,11 @@ function parseArgs(argv) {
|
|
|
112
120
|
demo: false,
|
|
113
121
|
banner: true,
|
|
114
122
|
verbose: false,
|
|
123
|
+
report: false,
|
|
115
124
|
help: false,
|
|
116
125
|
version: false,
|
|
117
126
|
};
|
|
127
|
+
let optionsEnded = false;
|
|
118
128
|
for (let i = 0; i < argv.length; i++) {
|
|
119
129
|
const a = argv[i];
|
|
120
130
|
const value = () => {
|
|
@@ -123,6 +133,16 @@ function parseArgs(argv) {
|
|
|
123
133
|
fail(`${a} needs a value`);
|
|
124
134
|
return v;
|
|
125
135
|
};
|
|
136
|
+
// After "--" everything is the folder, even a name that starts with "-".
|
|
137
|
+
if (optionsEnded || a === '--') {
|
|
138
|
+
if (!optionsEnded)
|
|
139
|
+
optionsEnded = true;
|
|
140
|
+
else if (!args.path)
|
|
141
|
+
args.path = a;
|
|
142
|
+
else
|
|
143
|
+
fail(`Unexpected argument ${a}`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
126
146
|
if (a === '-h' || a === '--help')
|
|
127
147
|
args.help = true;
|
|
128
148
|
else if (a === '-v' || a === '--version')
|
|
@@ -139,6 +159,8 @@ function parseArgs(argv) {
|
|
|
139
159
|
args.banner = false;
|
|
140
160
|
else if (a === '--verbose')
|
|
141
161
|
args.verbose = true;
|
|
162
|
+
else if (a === '--report')
|
|
163
|
+
args.report = true;
|
|
142
164
|
else if (a === '--pr-comment')
|
|
143
165
|
args.prComment = true;
|
|
144
166
|
else if (a === '--no-file')
|
|
@@ -167,10 +189,10 @@ function parseArgs(argv) {
|
|
|
167
189
|
args.domain = cleanDomain(value());
|
|
168
190
|
else if (a.startsWith('--domain='))
|
|
169
191
|
args.domain = cleanDomain(a.slice(9));
|
|
170
|
-
else if (a === '--fail-on')
|
|
171
|
-
args.failOn = severityArg(value());
|
|
172
|
-
|
|
173
|
-
|
|
192
|
+
else if (a === '--fail-on' || a.startsWith('--fail-on=')) {
|
|
193
|
+
args.failOn = severityArg(a === '--fail-on' ? value() : a.slice(10));
|
|
194
|
+
args.failOnSet = true;
|
|
195
|
+
}
|
|
174
196
|
else if (a === '--only')
|
|
175
197
|
args.only = categoriesArg(a, value());
|
|
176
198
|
else if (a.startsWith('--only='))
|
|
@@ -197,6 +219,9 @@ function parseArgs(argv) {
|
|
|
197
219
|
// Machine-readable and CI runs shouldn't leave files behind unless asked to.
|
|
198
220
|
if ((args.json || args.ci) && !args.out)
|
|
199
221
|
args.writeFile = false;
|
|
222
|
+
if (args.failOnSet && !args.ci) {
|
|
223
|
+
process.stderr.write('launch-doctor: --fail-on only changes the exit code together with --ci, so it was ignored.\n');
|
|
224
|
+
}
|
|
200
225
|
return args;
|
|
201
226
|
}
|
|
202
227
|
function categoriesArg(flag, input) {
|
|
@@ -233,6 +258,17 @@ function cleanDomain(input) {
|
|
|
233
258
|
fail(`"${input}" doesn't look like a domain (example: myapp.com)`);
|
|
234
259
|
return domain;
|
|
235
260
|
}
|
|
261
|
+
/** Run a core call; a CoreError (folder not found, not a git repository...) becomes the usual usage error. */
|
|
262
|
+
function core(fn) {
|
|
263
|
+
try {
|
|
264
|
+
return fn();
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
if (err instanceof CoreError)
|
|
268
|
+
fail(err.message);
|
|
269
|
+
throw err;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
236
272
|
function fail(message) {
|
|
237
273
|
process.stderr.write(`launch-doctor: ${message}\n`);
|
|
238
274
|
process.exit(2);
|
|
@@ -241,12 +277,14 @@ function init(argv) {
|
|
|
241
277
|
const hooks = argv.includes('--hooks');
|
|
242
278
|
const monitor = argv.includes('--monitor');
|
|
243
279
|
const upgrade = argv.includes('--upgrade');
|
|
244
|
-
const
|
|
280
|
+
const mcpSetup = argv.includes('--mcp');
|
|
281
|
+
const rest = argv.filter((a) => a !== '--hooks' && a !== '--monitor' && a !== '--upgrade' && a !== '--mcp');
|
|
245
282
|
const extra = rest.filter((a) => a.startsWith('-'));
|
|
246
283
|
if (extra.length)
|
|
247
|
-
fail(`init only takes --hooks, --hooks --upgrade or --
|
|
248
|
-
if (hooks
|
|
249
|
-
fail('Run "init --hooks" and "init --
|
|
284
|
+
fail(`init only takes --hooks, --hooks --upgrade, --monitor or --mcp (got ${extra.join(' ')})`);
|
|
285
|
+
if ([hooks, monitor, mcpSetup].filter(Boolean).length > 1) {
|
|
286
|
+
fail('Run "init --hooks", "init --monitor" and "init --mcp" one at a time');
|
|
287
|
+
}
|
|
250
288
|
if (upgrade && !hooks)
|
|
251
289
|
fail('--upgrade goes with --hooks: launch-doctor init --hooks --upgrade');
|
|
252
290
|
if (rest.length > 1)
|
|
@@ -254,6 +292,11 @@ function init(argv) {
|
|
|
254
292
|
const root = resolve(rest[0] ?? '.');
|
|
255
293
|
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
256
294
|
fail(`Folder not found: ${root}`);
|
|
295
|
+
if (mcpSetup) {
|
|
296
|
+
// Printed only: the user's Claude Code, Cursor and Claude Desktop settings are never edited.
|
|
297
|
+
process.stdout.write(mcpSetupText(root, pinnedPackage()));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
257
300
|
if (hooks && upgrade) {
|
|
258
301
|
upgradeHooksCommand(root);
|
|
259
302
|
return;
|
|
@@ -276,6 +319,15 @@ function init(argv) {
|
|
|
276
319
|
process.stdout.write(` created ${f}\n`);
|
|
277
320
|
for (const f of skipped)
|
|
278
321
|
process.stdout.write(` skipped ${f} ${dim('(already exists)')}\n`);
|
|
322
|
+
if (!monitor) {
|
|
323
|
+
const ignored = ensureGitignore(root);
|
|
324
|
+
if (ignored === 'created' || ignored === 'updated') {
|
|
325
|
+
process.stdout.write(` ${ignored} .gitignore ${dim('(added .launchdoctor/, where grades and report.md are kept)')}\n`);
|
|
326
|
+
}
|
|
327
|
+
else if (ignored === 'skipped') {
|
|
328
|
+
process.stdout.write(` skipped .gitignore ${dim('(a link or special file: add .launchdoctor/ to it yourself)')}\n`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
279
331
|
if (monitor && created.length) {
|
|
280
332
|
const repo = githubRepo(git(root, ['remote', 'get-url', 'origin'])) ?? undefined;
|
|
281
333
|
process.stdout.write(`\n It runs every Monday and keeps grades.json and badge.svg on the ${GRADES_BRANCH} branch\n` +
|
|
@@ -316,10 +368,7 @@ function grades(argv) {
|
|
|
316
368
|
fail(`grades only takes --json (got ${extra.join(' ')})`);
|
|
317
369
|
if (rest.length > 1)
|
|
318
370
|
fail('grades takes at most one folder');
|
|
319
|
-
const
|
|
320
|
-
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
321
|
-
fail(`Folder not found: ${root}`);
|
|
322
|
-
const entries = loadGrades(root);
|
|
371
|
+
const entries = core(() => gradeHistory(rest[0] ?? '.'));
|
|
323
372
|
if (json)
|
|
324
373
|
process.stdout.write(`${JSON.stringify(entries, null, 2)}\n`);
|
|
325
374
|
else
|
|
@@ -350,26 +399,37 @@ const MCP_HELP = `
|
|
|
350
399
|
${bold('launch-doctor mcp')} - an MCP server for Claude Code, Cursor and other AI coding tools
|
|
351
400
|
|
|
352
401
|
${bold('Usage')}
|
|
353
|
-
npx launch-doctor mcp
|
|
402
|
+
npx launch-doctor mcp [folder] Your AI tool starts this itself and talks to it over stdin and stdout.
|
|
403
|
+
The tools read only that folder (default: the one it starts in).
|
|
404
|
+
npx launch-doctor init --mcp Print the exact setup commands and JSON for your tools
|
|
354
405
|
|
|
355
406
|
${bold('Tools it offers')}
|
|
356
|
-
scan_project
|
|
357
|
-
|
|
358
|
-
|
|
407
|
+
scan_project Check a project folder: the grades and a short list of findings, each with an id
|
|
408
|
+
explain_finding What one finding means, how to confirm it and how to fix it
|
|
409
|
+
fix_prompt The fix prompt for one finding
|
|
410
|
+
rescan Check again after a fix, and say which findings are gone
|
|
411
|
+
grade_history The grades saved with --record
|
|
412
|
+
scan_url Check a deployed site from the outside (the only tool that uses the network)
|
|
413
|
+
list_checks List the categories and finding ids
|
|
359
414
|
|
|
360
415
|
${bold('Set it up')}
|
|
361
|
-
Claude Code claude mcp add launch-doctor -- npx -y
|
|
416
|
+
Claude Code claude mcp add launch-doctor -- npx -y "${pinnedPackage()}" mcp
|
|
417
|
+
On Windows claude mcp add launch-doctor -- cmd /c npx -y ${windowsPackage(pinnedPackage())} mcp
|
|
362
418
|
Cursor add to .cursor/mcp.json:
|
|
363
|
-
{ "mcpServers": { "launch-doctor": { "command": "npx", "args": ["-y", "
|
|
419
|
+
{ "mcpServers": { "launch-doctor": { "command": "npx", "args": ["-y", "${pinnedPackage()}", "mcp"] } } }
|
|
420
|
+
"launch-doctor init --mcp" prints the exact setup for this folder.
|
|
364
421
|
`;
|
|
365
422
|
async function mcp(argv) {
|
|
366
423
|
if (argv.some((a) => a === '-h' || a === '--help')) {
|
|
367
424
|
process.stdout.write(MCP_HELP);
|
|
368
425
|
return;
|
|
369
426
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
427
|
+
const options = argv.filter((a) => a.startsWith('-'));
|
|
428
|
+
if (options.length || argv.length > 1) {
|
|
429
|
+
fail(`mcp takes only a project folder (got ${argv.join(' ')}). Run "launch-doctor mcp --help" for setup.`);
|
|
430
|
+
}
|
|
431
|
+
// The project the tools read: the given folder, or the folder the AI tool started the server in.
|
|
432
|
+
await runMcpServer(process.stdin, process.stdout, core(() => projectRoot(argv[0] ?? '.')));
|
|
373
433
|
}
|
|
374
434
|
const SCAN_HELP = `
|
|
375
435
|
${bold('launch-doctor scan')} - check your deployed site from the outside
|
|
@@ -568,6 +628,10 @@ const PROMPT_HELP = `
|
|
|
568
628
|
--domain <domain> Domain you send email from
|
|
569
629
|
-h, --help Show this help
|
|
570
630
|
`;
|
|
631
|
+
/** For prompt and explain in a folder with nothing to check: usually the wrong folder, not a clean app. */
|
|
632
|
+
function noProjectFiles(root) {
|
|
633
|
+
return `No project files were found in ${root}. Run this inside your app's folder (the one with package.json, requirements.txt or similar), or try npx launch-doctor --demo`;
|
|
634
|
+
}
|
|
571
635
|
/** `launch-doctor prompt <n> [folder] [--copy]`: print (or copy) one fix prompt. */
|
|
572
636
|
async function prompt(argv) {
|
|
573
637
|
let n;
|
|
@@ -599,9 +663,11 @@ async function prompt(argv) {
|
|
|
599
663
|
else if (a.startsWith('-'))
|
|
600
664
|
fail(`Unknown option ${a}. Run "launch-doctor prompt --help" to see the options.`);
|
|
601
665
|
else if (n === undefined) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
666
|
+
// A fix-prompt number (1, 2...) or a finding's id from the report (8 letters and digits).
|
|
667
|
+
if (!(/^\d+$/.test(a) && Number(a) >= 1) && !/^[0-9a-f]{8}$/i.test(a)) {
|
|
668
|
+
fail(`prompt needs a prompt number (1 or more) or a finding id, not "${a}"`);
|
|
669
|
+
}
|
|
670
|
+
n = a;
|
|
605
671
|
}
|
|
606
672
|
else if (!folder)
|
|
607
673
|
folder = a;
|
|
@@ -612,28 +678,20 @@ async function prompt(argv) {
|
|
|
612
678
|
fail('prompt needs a number, for example: npx launch-doctor prompt 1 --copy');
|
|
613
679
|
if (demo && folder)
|
|
614
680
|
fail('--demo uses a built-in sample app, so leave out the folder');
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
else if (!existsSync(root) || !statSync(root).isDirectory())
|
|
621
|
-
fail(`Folder not found: ${root}`);
|
|
622
|
-
let report;
|
|
623
|
-
try {
|
|
624
|
-
report = await runDoctor(root, { offline, domain });
|
|
625
|
-
}
|
|
626
|
-
finally {
|
|
627
|
-
if (demo)
|
|
628
|
-
rmSync(root, { recursive: true, force: true });
|
|
629
|
-
}
|
|
681
|
+
const request = (root) => scanProject({ root, offline: demo || offline, domain });
|
|
682
|
+
const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
|
|
683
|
+
if (report.filesScanned === 0)
|
|
684
|
+
fail(noProjectFiles(report.root));
|
|
630
685
|
const total = report.counts.critical + report.counts.warning + report.counts.baseline;
|
|
631
|
-
const finding =
|
|
686
|
+
const finding = findFinding(report, n);
|
|
632
687
|
if (!finding) {
|
|
633
|
-
fail(
|
|
634
|
-
? `
|
|
635
|
-
:
|
|
688
|
+
fail(!/^\d+$/.test(n)
|
|
689
|
+
? `No finding with id ${n} in this project (ids come from the report; they change when the line changes).`
|
|
690
|
+
: total
|
|
691
|
+
? `There ${total === 1 ? 'is only 1 fix prompt' : `are only ${total} fix prompts`}, so there is no prompt ${n}.`
|
|
692
|
+
: 'There are no fix prompts: Launch Doctor found nothing to fix.');
|
|
636
693
|
}
|
|
694
|
+
n = String(promptNumber(report, finding));
|
|
637
695
|
const title = finding.display?.title ?? finding.title;
|
|
638
696
|
if (copy) {
|
|
639
697
|
if (copyToClipboard(finding.fixPrompt)) {
|
|
@@ -644,9 +702,78 @@ async function prompt(argv) {
|
|
|
644
702
|
}
|
|
645
703
|
process.stdout.write(`Fix prompt ${n}: ${title}\n\n${finding.fixPrompt}\n`);
|
|
646
704
|
}
|
|
705
|
+
/** `launch-doctor explain <n|id> [folder] [--demo]`: what one finding means, from the same core as the MCP tool. */
|
|
706
|
+
async function explain(argv) {
|
|
707
|
+
let demo = false;
|
|
708
|
+
let offline = false;
|
|
709
|
+
let domain;
|
|
710
|
+
const rest = [];
|
|
711
|
+
for (let i = 0; i < argv.length; i++) {
|
|
712
|
+
const a = argv[i];
|
|
713
|
+
if (a === '--demo')
|
|
714
|
+
demo = true;
|
|
715
|
+
else if (a === '--offline')
|
|
716
|
+
offline = true;
|
|
717
|
+
else if (a === '--domain') {
|
|
718
|
+
const v = argv[++i];
|
|
719
|
+
if (!v || v.startsWith('--'))
|
|
720
|
+
fail('--domain needs a value');
|
|
721
|
+
domain = cleanDomain(v);
|
|
722
|
+
}
|
|
723
|
+
else if (a.startsWith('--domain='))
|
|
724
|
+
domain = cleanDomain(a.slice(9));
|
|
725
|
+
else if (a.startsWith('-'))
|
|
726
|
+
fail(`explain only takes --demo, --offline and --domain (got ${a})`);
|
|
727
|
+
else
|
|
728
|
+
rest.push(a);
|
|
729
|
+
}
|
|
730
|
+
const [key, folder, more] = rest;
|
|
731
|
+
if (!key || more)
|
|
732
|
+
fail('explain needs one finding: a number from the report or its id, for example: launch-doctor explain 1');
|
|
733
|
+
if (demo && folder)
|
|
734
|
+
fail('--demo uses a built-in sample app, so leave out the folder');
|
|
735
|
+
// The same scan as the report and `prompt` (with the email DNS check unless --offline), so n is the same finding.
|
|
736
|
+
const request = (root) => scanProject({ root, offline: demo || offline, domain });
|
|
737
|
+
const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
|
|
738
|
+
if (report.filesScanned === 0)
|
|
739
|
+
fail(noProjectFiles(report.root));
|
|
740
|
+
const finding = findFinding(report, key);
|
|
741
|
+
if (!finding)
|
|
742
|
+
fail(`No finding ${key} in this project. Run launch-doctor first to see the numbers and ids.`);
|
|
743
|
+
const d = findingDetails(report, finding);
|
|
744
|
+
const e = d.explanation;
|
|
745
|
+
const out = [
|
|
746
|
+
'',
|
|
747
|
+
` ${bold(`${d.number}. ${d.title}`)}`,
|
|
748
|
+
` ${dim(`${d.severity} · id ${d.ref} · rule ${d.rule}${d.file ? ` · ${shortWhere({ file: d.file, line: d.line })}` : ''}`)}`,
|
|
749
|
+
'',
|
|
750
|
+
...wrap(d.why, 76, ' '),
|
|
751
|
+
...(e
|
|
752
|
+
? [
|
|
753
|
+
['Why it matters', e.whyItMatters],
|
|
754
|
+
['How to confirm', e.howToConfirm],
|
|
755
|
+
['How to fix', e.howToFix],
|
|
756
|
+
['False alarm?', e.falsePositiveHint],
|
|
757
|
+
].flatMap(([label, text]) => ['', ` ${bold(label)}`, ...wrap(text, 76, ' ')])
|
|
758
|
+
: []),
|
|
759
|
+
...(d.rotate ? ['', ` ${bold('Rotate the key first:')} ${d.rotate}`] : []),
|
|
760
|
+
...(d.usage ? [` ${bold('Check whether someone used it:')} ${d.usage}`] : []),
|
|
761
|
+
'',
|
|
762
|
+
` ${dim(`The fix prompt: npx launch-doctor prompt ${d.number}${demo ? ' --demo' : folder ? ` ${shellArg(folder)}` : ''} --copy`)}`,
|
|
763
|
+
'',
|
|
764
|
+
];
|
|
765
|
+
process.stdout.write(`${out.join('\n')}\n`);
|
|
766
|
+
}
|
|
647
767
|
async function main() {
|
|
648
|
-
if (process.argv[2] === 'init')
|
|
649
|
-
|
|
768
|
+
if (process.argv[2] === 'init') {
|
|
769
|
+
// A file init can't write (a read-only folder, a file where a folder should be) is explained, not a crash.
|
|
770
|
+
try {
|
|
771
|
+
return init(process.argv.slice(3));
|
|
772
|
+
}
|
|
773
|
+
catch (err) {
|
|
774
|
+
fail(`init couldn't write its files: ${err.message}`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
650
777
|
if (process.argv[2] === 'scan')
|
|
651
778
|
return scan(process.argv.slice(3));
|
|
652
779
|
if (process.argv[2] === 'mcp')
|
|
@@ -657,6 +784,8 @@ async function main() {
|
|
|
657
784
|
return grades(process.argv.slice(3));
|
|
658
785
|
if (process.argv[2] === 'prompt')
|
|
659
786
|
return prompt(process.argv.slice(3));
|
|
787
|
+
if (process.argv[2] === 'explain')
|
|
788
|
+
return explain(process.argv.slice(3));
|
|
660
789
|
const args = parseArgs(process.argv.slice(2));
|
|
661
790
|
if (args.help) {
|
|
662
791
|
process.stdout.write(HELP);
|
|
@@ -666,24 +795,22 @@ async function main() {
|
|
|
666
795
|
process.stdout.write(`${version()}\n`);
|
|
667
796
|
return;
|
|
668
797
|
}
|
|
669
|
-
let stopDemoCleanup;
|
|
670
798
|
if (args.demo) {
|
|
671
799
|
if (args.path)
|
|
672
800
|
fail('--demo scans a built-in sample app, so leave out the folder');
|
|
673
|
-
// Ctrl+C mid-scan would otherwise skip the finally below and leave the folder in the temp directory.
|
|
674
|
-
let demoDir;
|
|
675
|
-
stopDemoCleanup = removeOnSignal(() => demoDir);
|
|
676
|
-
demoDir = createDemoProject();
|
|
677
|
-
args.path = demoDir;
|
|
678
801
|
args.offline = true;
|
|
679
802
|
if (!args.out)
|
|
680
803
|
args.writeFile = false;
|
|
681
|
-
if (!args.json)
|
|
682
|
-
process.stdout.write(`\n ${dim('Demo: scanning a sample app with the usual weekend-project mistakes…')}\n`);
|
|
683
804
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
805
|
+
// The demo's folder is only known once the core creates it.
|
|
806
|
+
let root = args.demo ? '' : core(() => projectRoot(args.path ?? '.'));
|
|
807
|
+
if (args.report) {
|
|
808
|
+
// The report describes the whole project, in the project's own .launchdoctor/ folder.
|
|
809
|
+
if (args.demo)
|
|
810
|
+
fail('--report writes to the project folder, so it needs a real project, not --demo');
|
|
811
|
+
if (args.changeMode)
|
|
812
|
+
fail(`--report describes the whole project, so it can't be used with --${args.changeMode}`);
|
|
813
|
+
}
|
|
687
814
|
if (args.record) {
|
|
688
815
|
// A recorded grade is compared with the next one, so it has to be for the whole project.
|
|
689
816
|
if (args.demo)
|
|
@@ -692,6 +819,8 @@ async function main() {
|
|
|
692
819
|
fail('--record saves the grade for the whole project, so leave out --only and --skip');
|
|
693
820
|
}
|
|
694
821
|
if (args.configFrom) {
|
|
822
|
+
if (args.demo)
|
|
823
|
+
fail('--config-from needs a real project folder, not --demo');
|
|
695
824
|
if (args.updateBaseline)
|
|
696
825
|
fail('--config-from reads the baseline from git, so it cannot be used with --update-baseline');
|
|
697
826
|
try {
|
|
@@ -715,10 +844,8 @@ async function main() {
|
|
|
715
844
|
if (on)
|
|
716
845
|
fail(`${flag} reports on some files only, so it can't be used with ${name}`);
|
|
717
846
|
}
|
|
718
|
-
const
|
|
719
|
-
|
|
720
|
-
fail(`${flag} needs a folder inside a git repository`);
|
|
721
|
-
onlyFiles = files;
|
|
847
|
+
const mode = args.changeMode;
|
|
848
|
+
onlyFiles = core(() => changedPaths(root, mode));
|
|
722
849
|
// A partial report must not overwrite LAUNCH_FIXES.md, which describes the whole project.
|
|
723
850
|
if (!args.out)
|
|
724
851
|
args.writeFile = false;
|
|
@@ -726,28 +853,35 @@ async function main() {
|
|
|
726
853
|
// The short report is the default for a person at a terminal; CI, hooks and pull requests keep the full one.
|
|
727
854
|
const short = !args.verbose && !args.json && !args.ci && !args.changeMode && !args.prComment;
|
|
728
855
|
const progress = short && process.stdout.isTTY ? progressLine() : undefined;
|
|
856
|
+
const request = (dir) => scanProject({
|
|
857
|
+
root: dir,
|
|
858
|
+
onProgress: progress?.update,
|
|
859
|
+
offline: args.offline,
|
|
860
|
+
domain: args.domain,
|
|
861
|
+
only: args.only,
|
|
862
|
+
skip: args.skip,
|
|
863
|
+
// When updating, start from scratch so every current finding is saved.
|
|
864
|
+
baseline: args.baseline && !args.updateBaseline,
|
|
865
|
+
configFrom: args.configFrom,
|
|
866
|
+
history: args.history ? args.historyDepth : undefined,
|
|
867
|
+
onlyFiles,
|
|
868
|
+
});
|
|
729
869
|
let report;
|
|
870
|
+
// Ctrl+C mid-scan would otherwise leave the demo folder in the temp directory, so the handler goes in first.
|
|
871
|
+
let demoDir;
|
|
872
|
+
const stopDemoCleanup = args.demo ? removeOnSignal(() => demoDir) : undefined;
|
|
730
873
|
try {
|
|
731
|
-
report =
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
baseline: args.baseline && !args.updateBaseline,
|
|
739
|
-
configFrom: args.configFrom,
|
|
740
|
-
history: args.history ? { depth: args.historyDepth } : undefined,
|
|
741
|
-
onlyFiles,
|
|
742
|
-
});
|
|
874
|
+
report = args.demo
|
|
875
|
+
? await withDemo(request, (dir) => {
|
|
876
|
+
root = demoDir = dir;
|
|
877
|
+
if (!args.json)
|
|
878
|
+
process.stdout.write(`\n ${dim('Demo: scanning a sample app with the usual weekend-project mistakes…')}\n`);
|
|
879
|
+
})
|
|
880
|
+
: await request(root);
|
|
743
881
|
}
|
|
744
882
|
finally {
|
|
745
883
|
progress?.clear();
|
|
746
|
-
|
|
747
|
-
if (args.demo) {
|
|
748
|
-
rmSync(root, { recursive: true, force: true });
|
|
749
|
-
stopDemoCleanup?.();
|
|
750
|
-
}
|
|
884
|
+
stopDemoCleanup?.();
|
|
751
885
|
}
|
|
752
886
|
if (report.filesScanned === 0) {
|
|
753
887
|
if (!short)
|
|
@@ -795,6 +929,20 @@ async function main() {
|
|
|
795
929
|
process.stderr.write(`${dim(`Couldn't write ${target}: ${err.message}`)}\n`);
|
|
796
930
|
}
|
|
797
931
|
}
|
|
932
|
+
let reportFile;
|
|
933
|
+
if (args.report) {
|
|
934
|
+
const path = join(root, REPORT_FILE);
|
|
935
|
+
try {
|
|
936
|
+
// Never through a .launchdoctor that is a link to another folder: writeInside refuses one.
|
|
937
|
+
writeInside(root, REPORT_FILE, renderReportMd(report, { target: args.path ? ` ${shellArg(args.path)}` : '' }));
|
|
938
|
+
const rel = relative(process.cwd(), path);
|
|
939
|
+
reportFile = rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : path;
|
|
940
|
+
}
|
|
941
|
+
catch (err) {
|
|
942
|
+
process.stderr.write(`${dim(`Couldn't write ${path}: ${err.message}`)}
|
|
943
|
+
`);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
798
946
|
if (args.sarif) {
|
|
799
947
|
const sarifPath = isAbsolute(args.sarif) ? args.sarif : resolve(process.cwd(), args.sarif);
|
|
800
948
|
const fallbackUri = ['package.json', 'pyproject.toml', 'requirements.txt', 'README.md'].find((f) => existsSync(join(root, f)));
|
|
@@ -843,8 +991,12 @@ async function main() {
|
|
|
843
991
|
const lastRecorded = last && describeEntry(last);
|
|
844
992
|
const target = args.demo ? ' --demo' : args.path ? ` ${shellArg(args.path)}` : '';
|
|
845
993
|
process.stdout.write(short
|
|
846
|
-
? renderShortReport(report, { fixFile, lastRecorded, banner: showBanner, target, demo: args.demo })
|
|
994
|
+
? renderShortReport(report, { fixFile, reportFile, lastRecorded, banner: showBanner, target, demo: args.demo })
|
|
847
995
|
: renderReport(report, { fixFile, lastRecorded, banner: showBanner }));
|
|
996
|
+
// Run in the wrong folder (a home folder, the Desktop), the scan mixes several projects into one grade.
|
|
997
|
+
const projects = short && !args.demo ? separateProjects(root) : null;
|
|
998
|
+
if (projects)
|
|
999
|
+
process.stdout.write(separateProjectsNote(root, projects));
|
|
848
1000
|
}
|
|
849
1001
|
if (recorded)
|
|
850
1002
|
(args.json ? process.stderr : process.stdout).write(` ${dim(recorded)}\n\n`);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type ChangeMode } from './changed.js';
|
|
2
|
+
import { type RuleExplanation } from './explanations.js';
|
|
3
|
+
import { type GradeEntry } from './grades.js';
|
|
4
|
+
import type { Finding, Report } from './types.js';
|
|
5
|
+
/** A problem the caller should explain to the user (not a crash). */
|
|
6
|
+
export declare class CoreError extends Error {
|
|
7
|
+
readonly kind: 'not-found' | 'not-git' | 'usage';
|
|
8
|
+
constructor(kind: 'not-found' | 'not-git' | 'usage', message: string);
|
|
9
|
+
}
|
|
10
|
+
export interface ScanRequest {
|
|
11
|
+
/** Project folder (resolved against the current folder). */
|
|
12
|
+
root: string;
|
|
13
|
+
offline?: boolean;
|
|
14
|
+
domain?: string;
|
|
15
|
+
only?: string[];
|
|
16
|
+
skip?: string[];
|
|
17
|
+
/** Read this many commits of git history for removed keys (true = the default depth). */
|
|
18
|
+
history?: number | boolean;
|
|
19
|
+
/** Use .launchdoctor-baseline.json (default true). */
|
|
20
|
+
baseline?: boolean;
|
|
21
|
+
configFrom?: string;
|
|
22
|
+
/** Report only on these files (relative paths with "/"). */
|
|
23
|
+
onlyFiles?: string[];
|
|
24
|
+
onProgress?: (step: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/** The folder, resolved, or a CoreError when it isn't a folder. */
|
|
27
|
+
export declare function projectRoot(path: string, cwd?: string): string;
|
|
28
|
+
/** Scan a project folder. A folder with no project files gives a report with filesScanned 0; callers explain it. */
|
|
29
|
+
export declare function scan(req: ScanRequest): Promise<Report>;
|
|
30
|
+
/** Run `fn` on a fresh copy of the built-in demo project, and always remove the copy afterwards. */
|
|
31
|
+
export declare function withDemo<T>(fn: (root: string) => Promise<T>, onCreate?: (root: string) => void): Promise<T>;
|
|
32
|
+
/** Files changed since the last commit (`changed`) or staged (`staged`), the --changed / --staged logic. */
|
|
33
|
+
export declare function changedPaths(root: string, mode: ChangeMode): string[];
|
|
34
|
+
export interface RescanRequest extends Omit<ScanRequest, 'onlyFiles'> {
|
|
35
|
+
/** Report on these files. */
|
|
36
|
+
paths?: string[];
|
|
37
|
+
/** Report on the files of these findings (refs from an earlier scan of the same project). */
|
|
38
|
+
refs?: string[];
|
|
39
|
+
/** The earlier report the refs come from. Without it, refs are looked up in a fresh full scan. */
|
|
40
|
+
previous?: Report;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check again after a fix: only the given files, the files of the given findings, or (with neither) the files changed
|
|
44
|
+
* since the last commit, exactly like --changed. The whole project is still read, so checks across files keep working.
|
|
45
|
+
*/
|
|
46
|
+
export declare function rescan(req: RescanRequest): Promise<{
|
|
47
|
+
report: Report;
|
|
48
|
+
files: string[];
|
|
49
|
+
fixed: string[];
|
|
50
|
+
}>;
|
|
51
|
+
/** A path inside the project, as a relative path with "/". Paths outside the project are refused. */
|
|
52
|
+
export declare function normalizeRelative(root: string, path: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* A finding by its stable ref ("3f9a1c2b"), or by its fix-prompt number ("2" or 2: the numbers in the report and in
|
|
55
|
+
* LAUNCH_FIXES.md).
|
|
56
|
+
*/
|
|
57
|
+
export declare function findFinding(report: Report, key: string | number): Finding | null;
|
|
58
|
+
/** The fix-prompt number of a finding (1-based), as in LAUNCH_FIXES.md. */
|
|
59
|
+
export declare function promptNumber(report: Report, f: Finding): number;
|
|
60
|
+
/** The recorded grade history, oldest first. */
|
|
61
|
+
export declare function gradeHistory(root: string): GradeEntry[];
|
|
62
|
+
/** Everything about one finding, for `explain` (CLI and MCP) and the report file. */
|
|
63
|
+
export interface FindingDetails {
|
|
64
|
+
ref: string;
|
|
65
|
+
/** Fix-prompt number, as in the report and LAUNCH_FIXES.md. */
|
|
66
|
+
number: number;
|
|
67
|
+
rule: string;
|
|
68
|
+
severity: Finding['severity'];
|
|
69
|
+
title: string;
|
|
70
|
+
file?: string;
|
|
71
|
+
line?: number;
|
|
72
|
+
/** This finding's own explanation (with masked values only). */
|
|
73
|
+
why: string;
|
|
74
|
+
/** What the rule means in general, from src/explanations.ts. */
|
|
75
|
+
explanation: RuleExplanation | null;
|
|
76
|
+
rotate?: string;
|
|
77
|
+
usage?: string;
|
|
78
|
+
baseline: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function findingDetails(report: Report, f: Finding): FindingDetails;
|
|
81
|
+
/**
|
|
82
|
+
* What a scan did and did not look at, in plain sentences: limits that were hit, skipped and unused categories,
|
|
83
|
+
* folders left out. Shown with MCP scan results, so the model doesn't read a clean result as "everything is fine".
|
|
84
|
+
*/
|
|
85
|
+
export declare function coverageNotes(report: Report): string[];
|