launch-doctor 0.4.1 → 0.4.3
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 +46 -1
- package/README.md +90 -432
- package/dist/src/banner.d.ts +22 -0
- package/dist/src/banner.js +35 -0
- package/dist/src/baseline.d.ts +9 -0
- package/dist/src/baseline.js +26 -0
- package/dist/src/bin.cjs +35 -0
- package/dist/src/bin.d.cts +2 -0
- package/dist/src/checks/access.js +8 -0
- package/dist/src/checks/costs.js +6 -0
- package/dist/src/checks/database.js +29 -0
- package/dist/src/checks/payments.js +12 -0
- package/dist/src/checks/secrets.d.ts +26 -1
- package/dist/src/checks/secrets.js +245 -5
- package/dist/src/cli.js +352 -57
- 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/fixes.d.ts +8 -1
- package/dist/src/fixes.js +31 -10
- package/dist/src/grade.d.ts +8 -1
- package/dist/src/grade.js +13 -0
- package/dist/src/history.js +9 -2
- package/dist/src/hooks-setup.d.ts +26 -0
- package/dist/src/hooks-setup.js +115 -1
- package/dist/src/index.js +8 -2
- package/dist/src/init.d.ts +12 -0
- package/dist/src/init.js +55 -0
- package/dist/src/live.js +8 -3
- package/dist/src/mcp.d.ts +126 -11
- package/dist/src/mcp.js +285 -148
- package/dist/src/prompt.d.ts +23 -0
- package/dist/src/prompt.js +88 -0
- package/dist/src/report-md.d.ts +14 -0
- package/dist/src/report-md.js +71 -0
- package/dist/src/report.d.ts +12 -1
- package/dist/src/report.js +27 -15
- package/dist/src/short-report.d.ts +61 -0
- package/dist/src/short-report.js +246 -0
- package/dist/src/types.d.ts +33 -0
- package/dist/src/util.d.ts +2 -0
- package/dist/src/util.js +2 -0
- package/package.json +3 -3
package/dist/src/cli.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { appendFileSync, existsSync,
|
|
3
|
-
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { dirname, 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
14
|
import { DEFAULT_HISTORY_DEPTH } from './history.js';
|
|
13
15
|
import { runHook } from './hook.js';
|
|
14
|
-
import { setupHooks } from './hooks-setup.js';
|
|
15
|
-
import { CATEGORY_IDS
|
|
16
|
-
import { badgeUrl, GRADES_BRANCH, githubRepo, runInit } from './init.js';
|
|
16
|
+
import { pinnedPackage, setupHooks, upgradeHooks } from './hooks-setup.js';
|
|
17
|
+
import { CATEGORY_IDS } from './index.js';
|
|
18
|
+
import { badgeUrl, ensureGitignore, GRADES_BRANCH, githubRepo, mcpSetupText, runInit } from './init.js';
|
|
17
19
|
import { runLiveScan } from './live.js';
|
|
18
20
|
import { runMcpServer } from './mcp.js';
|
|
19
21
|
import { assertConfigRef } from './project.js';
|
|
20
|
-
import {
|
|
22
|
+
import { copyToClipboard, unsupportedLanguage } from './prompt.js';
|
|
23
|
+
import { bold, dim, renderReport, wrap } from './report.js';
|
|
24
|
+
import { REPORT_FILE, renderReportMd } from './report-md.js';
|
|
21
25
|
import { writeRegularFile } from './safe-fs.js';
|
|
22
26
|
import { renderSarif } from './sarif.js';
|
|
27
|
+
import { renderEmptyFolder, renderOtherLanguage, renderShortReport } from './short-report.js';
|
|
23
28
|
import { renderStepSummary } from './summary.js';
|
|
24
29
|
import { version } from './version.js';
|
|
25
30
|
const HELP = `
|
|
@@ -29,8 +34,15 @@ const HELP = `
|
|
|
29
34
|
npx launch-doctor [folder] [options]
|
|
30
35
|
npx launch-doctor init [folder] Create .launchdoctorignore and a GitHub Actions workflow
|
|
31
36
|
npx launch-doctor init --hooks Set up hooks that check every AI edit and every commit
|
|
37
|
+
npx launch-doctor init --hooks --upgrade
|
|
38
|
+
Move those hooks onto this version (only the launch-doctor command changes)
|
|
32
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)
|
|
33
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
|
|
44
|
+
npx launch-doctor prompt <n> [folder] [--copy]
|
|
45
|
+
Print fix prompt n (the numbers in the report and LAUNCH_FIXES.md)
|
|
34
46
|
npx launch-doctor scan <url> Check your deployed site (exposed files, source maps, open Supabase tables, headers)
|
|
35
47
|
npx launch-doctor mcp Start an MCP server so Claude Code, Cursor and other AI tools can run checks
|
|
36
48
|
|
|
@@ -58,6 +70,10 @@ const HELP = `
|
|
|
58
70
|
--changed Only report on files changed since the last commit (fast, for hooks)
|
|
59
71
|
--staged Only report on files staged for the next commit (for a pre-commit hook)
|
|
60
72
|
--demo Scan a built-in sample app full of mistakes
|
|
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
|
|
75
|
+
--copy With prompt <n>, copy the fix prompt to the clipboard
|
|
76
|
+
--no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
|
|
61
77
|
-h, --help Show this help
|
|
62
78
|
-v, --version Show the version
|
|
63
79
|
|
|
@@ -100,6 +116,9 @@ function parseArgs(argv) {
|
|
|
100
116
|
historyDepth: DEFAULT_HISTORY_DEPTH,
|
|
101
117
|
record: false,
|
|
102
118
|
demo: false,
|
|
119
|
+
banner: true,
|
|
120
|
+
verbose: false,
|
|
121
|
+
report: false,
|
|
103
122
|
help: false,
|
|
104
123
|
version: false,
|
|
105
124
|
};
|
|
@@ -123,6 +142,12 @@ function parseArgs(argv) {
|
|
|
123
142
|
args.ci = true;
|
|
124
143
|
else if (a === '--demo')
|
|
125
144
|
args.demo = true;
|
|
145
|
+
else if (a === '--no-banner')
|
|
146
|
+
args.banner = false;
|
|
147
|
+
else if (a === '--verbose')
|
|
148
|
+
args.verbose = true;
|
|
149
|
+
else if (a === '--report')
|
|
150
|
+
args.report = true;
|
|
126
151
|
else if (a === '--pr-comment')
|
|
127
152
|
args.prComment = true;
|
|
128
153
|
else if (a === '--no-file')
|
|
@@ -217,6 +242,17 @@ function cleanDomain(input) {
|
|
|
217
242
|
fail(`"${input}" doesn't look like a domain (example: myapp.com)`);
|
|
218
243
|
return domain;
|
|
219
244
|
}
|
|
245
|
+
/** Run a core call; a CoreError (folder not found, not a git repository...) becomes the usual usage error. */
|
|
246
|
+
function core(fn) {
|
|
247
|
+
try {
|
|
248
|
+
return fn();
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
if (err instanceof CoreError)
|
|
252
|
+
fail(err.message);
|
|
253
|
+
throw err;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
220
256
|
function fail(message) {
|
|
221
257
|
process.stderr.write(`launch-doctor: ${message}\n`);
|
|
222
258
|
process.exit(2);
|
|
@@ -224,17 +260,31 @@ function fail(message) {
|
|
|
224
260
|
function init(argv) {
|
|
225
261
|
const hooks = argv.includes('--hooks');
|
|
226
262
|
const monitor = argv.includes('--monitor');
|
|
227
|
-
const
|
|
263
|
+
const upgrade = argv.includes('--upgrade');
|
|
264
|
+
const mcpSetup = argv.includes('--mcp');
|
|
265
|
+
const rest = argv.filter((a) => a !== '--hooks' && a !== '--monitor' && a !== '--upgrade' && a !== '--mcp');
|
|
228
266
|
const extra = rest.filter((a) => a.startsWith('-'));
|
|
229
267
|
if (extra.length)
|
|
230
|
-
fail(`init only takes --hooks
|
|
231
|
-
if (hooks
|
|
232
|
-
fail('Run "init --hooks" and "init --
|
|
268
|
+
fail(`init only takes --hooks, --hooks --upgrade, --monitor or --mcp (got ${extra.join(' ')})`);
|
|
269
|
+
if ([hooks, monitor, mcpSetup].filter(Boolean).length > 1) {
|
|
270
|
+
fail('Run "init --hooks", "init --monitor" and "init --mcp" one at a time');
|
|
271
|
+
}
|
|
272
|
+
if (upgrade && !hooks)
|
|
273
|
+
fail('--upgrade goes with --hooks: launch-doctor init --hooks --upgrade');
|
|
233
274
|
if (rest.length > 1)
|
|
234
275
|
fail('init takes at most one folder');
|
|
235
276
|
const root = resolve(rest[0] ?? '.');
|
|
236
277
|
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
237
278
|
fail(`Folder not found: ${root}`);
|
|
279
|
+
if (mcpSetup) {
|
|
280
|
+
// Printed only: the user's Claude Code, Cursor and Claude Desktop settings are never edited.
|
|
281
|
+
process.stdout.write(mcpSetupText(root, pinnedPackage()));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (hooks && upgrade) {
|
|
285
|
+
upgradeHooksCommand(root);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
238
288
|
if (hooks) {
|
|
239
289
|
const result = setupHooks(root);
|
|
240
290
|
for (const f of result.created)
|
|
@@ -253,6 +303,15 @@ function init(argv) {
|
|
|
253
303
|
process.stdout.write(` created ${f}\n`);
|
|
254
304
|
for (const f of skipped)
|
|
255
305
|
process.stdout.write(` skipped ${f} ${dim('(already exists)')}\n`);
|
|
306
|
+
if (!monitor) {
|
|
307
|
+
const ignored = ensureGitignore(root);
|
|
308
|
+
if (ignored === 'created' || ignored === 'updated') {
|
|
309
|
+
process.stdout.write(` ${ignored} .gitignore ${dim('(added .launchdoctor/, where grades and report.md are kept)')}\n`);
|
|
310
|
+
}
|
|
311
|
+
else if (ignored === 'skipped') {
|
|
312
|
+
process.stdout.write(` skipped .gitignore ${dim('(a link or special file: add .launchdoctor/ to it yourself)')}\n`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
256
315
|
if (monitor && created.length) {
|
|
257
316
|
const repo = githubRepo(git(root, ['remote', 'get-url', 'origin'])) ?? undefined;
|
|
258
317
|
process.stdout.write(`\n It runs every Monday and keeps grades.json and badge.svg on the ${GRADES_BRANCH} branch\n` +
|
|
@@ -261,6 +320,29 @@ function init(argv) {
|
|
|
261
320
|
` ${dim('To check your deployed site too, add a repository variable named LAUNCH_DOCTOR_URL.')}\n`);
|
|
262
321
|
}
|
|
263
322
|
}
|
|
323
|
+
/** `init --hooks --upgrade`: show the lines that change, then write them. */
|
|
324
|
+
function upgradeHooksCommand(root) {
|
|
325
|
+
const result = upgradeHooks(root);
|
|
326
|
+
const out = (line) => process.stdout.write(`${line}\n`);
|
|
327
|
+
for (const c of result.changed) {
|
|
328
|
+
out(` ${c.file}`);
|
|
329
|
+
for (const line of c.before)
|
|
330
|
+
out(` - ${line}`);
|
|
331
|
+
for (const line of c.after)
|
|
332
|
+
out(` + ${line}`);
|
|
333
|
+
out(` upgraded ${c.file} ${dim(`(only the launch-doctor command changed)`)}`);
|
|
334
|
+
}
|
|
335
|
+
for (const [f, spec] of result.current)
|
|
336
|
+
out(` up to date ${f} ${dim(`(${spec})`)}`);
|
|
337
|
+
for (const f of result.unpinned) {
|
|
338
|
+
out(` not changed ${f} ${dim('(a launch-doctor hook without a version, which always runs the newest release; to pin it, remove that hook and run "init --hooks")')}`);
|
|
339
|
+
}
|
|
340
|
+
for (const [f, why] of result.skipped)
|
|
341
|
+
out(` skipped ${f} ${dim(`(${why})`)}`);
|
|
342
|
+
if (!result.changed.length && !result.current.length && !result.unpinned.length) {
|
|
343
|
+
out(` ${dim(`No launch-doctor hooks found. Set them up with: npx "${pinnedPackage()}" init --hooks`)}`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
264
346
|
/** `launch-doctor grades [folder] [--json]`: the grades saved with --record, newest first. */
|
|
265
347
|
function grades(argv) {
|
|
266
348
|
const json = argv.includes('--json');
|
|
@@ -270,10 +352,7 @@ function grades(argv) {
|
|
|
270
352
|
fail(`grades only takes --json (got ${extra.join(' ')})`);
|
|
271
353
|
if (rest.length > 1)
|
|
272
354
|
fail('grades takes at most one folder');
|
|
273
|
-
const
|
|
274
|
-
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
275
|
-
fail(`Folder not found: ${root}`);
|
|
276
|
-
const entries = loadGrades(root);
|
|
355
|
+
const entries = core(() => gradeHistory(rest[0] ?? '.'));
|
|
277
356
|
if (json)
|
|
278
357
|
process.stdout.write(`${JSON.stringify(entries, null, 2)}\n`);
|
|
279
358
|
else
|
|
@@ -304,7 +383,9 @@ const MCP_HELP = `
|
|
|
304
383
|
${bold('launch-doctor mcp')} - an MCP server for Claude Code, Cursor and other AI coding tools
|
|
305
384
|
|
|
306
385
|
${bold('Usage')}
|
|
307
|
-
npx launch-doctor mcp
|
|
386
|
+
npx launch-doctor mcp [folder] Your AI tool starts this itself and talks to it over stdin and stdout.
|
|
387
|
+
The tools read only that folder (default: the one it starts in).
|
|
388
|
+
npx launch-doctor init --mcp Print the exact setup commands and JSON for your tools
|
|
308
389
|
|
|
309
390
|
${bold('Tools it offers')}
|
|
310
391
|
scan_project Check a project folder: grade, findings with fix prompts, and the checklist
|
|
@@ -321,9 +402,12 @@ async function mcp(argv) {
|
|
|
321
402
|
process.stdout.write(MCP_HELP);
|
|
322
403
|
return;
|
|
323
404
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
405
|
+
const options = argv.filter((a) => a.startsWith('-'));
|
|
406
|
+
if (options.length || argv.length > 1) {
|
|
407
|
+
fail(`mcp takes only a project folder (got ${argv.join(' ')}). Run "launch-doctor mcp --help" for setup.`);
|
|
408
|
+
}
|
|
409
|
+
// The project the tools read: the given folder, or the folder the AI tool started the server in.
|
|
410
|
+
await runMcpServer(process.stdin, process.stdout, core(() => projectRoot(argv[0] ?? '.')));
|
|
327
411
|
}
|
|
328
412
|
const SCAN_HELP = `
|
|
329
413
|
${bold('launch-doctor scan')} - check your deployed site from the outside
|
|
@@ -338,6 +422,7 @@ const SCAN_HELP = `
|
|
|
338
422
|
--ci Exit with code 1 on findings at or above --fail-on
|
|
339
423
|
--fail-on <level> With --ci, the lowest severity that fails: critical (default) or warning
|
|
340
424
|
--no-db Don't test Supabase tables with the public key found in the page
|
|
425
|
+
--no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
|
|
341
426
|
-h, --help Show this help
|
|
342
427
|
|
|
343
428
|
Only scan sites you own or are allowed to test. The scan makes a few dozen ordinary GET requests
|
|
@@ -351,6 +436,7 @@ async function scan(argv) {
|
|
|
351
436
|
let ci = false;
|
|
352
437
|
let failOn = 'critical';
|
|
353
438
|
let skipDatabase = false;
|
|
439
|
+
let banner = true;
|
|
354
440
|
for (let i = 0; i < argv.length; i++) {
|
|
355
441
|
const a = argv[i];
|
|
356
442
|
const value = () => {
|
|
@@ -371,6 +457,8 @@ async function scan(argv) {
|
|
|
371
457
|
writeFile = false;
|
|
372
458
|
else if (a === '--no-db')
|
|
373
459
|
skipDatabase = true;
|
|
460
|
+
else if (a === '--no-banner')
|
|
461
|
+
banner = false;
|
|
374
462
|
else if (a === '--out')
|
|
375
463
|
out = value();
|
|
376
464
|
else if (a.startsWith('--out='))
|
|
@@ -425,8 +513,15 @@ async function scan(argv) {
|
|
|
425
513
|
if (json)
|
|
426
514
|
process.stdout.write(`${JSON.stringify(report, null, 2)}
|
|
427
515
|
`);
|
|
428
|
-
else
|
|
429
|
-
|
|
516
|
+
else {
|
|
517
|
+
const showBanner = shouldShowBanner({
|
|
518
|
+
wanted: banner && !ci && !out,
|
|
519
|
+
isTTY: !!process.stdout.isTTY,
|
|
520
|
+
columns: process.stdout.columns,
|
|
521
|
+
env: process.env,
|
|
522
|
+
});
|
|
523
|
+
process.stdout.write(renderReport(report, { fixFile, banner: showBanner }));
|
|
524
|
+
}
|
|
430
525
|
if (ci && failingFindings(report, failOn).length > 0)
|
|
431
526
|
process.exitCode = 1;
|
|
432
527
|
}
|
|
@@ -470,6 +565,156 @@ async function commentOnPr(report, root) {
|
|
|
470
565
|
process.stderr.write(`\n ${dim(explainGitHubError(err))}\n`);
|
|
471
566
|
}
|
|
472
567
|
}
|
|
568
|
+
/** A path as it would be typed in a shell: quoted when it has spaces or other special characters. */
|
|
569
|
+
function shellArg(s) {
|
|
570
|
+
return /^[\w./:\\-]+$/.test(s) ? s : `"${s.replace(/"/g, '\\"')}"`;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* "Checking Secrets & keys..." on one terminal line while a long scan runs. Nothing for the first second,
|
|
574
|
+
* so quick scans never show it, and the line is cleared before the report is printed.
|
|
575
|
+
*/
|
|
576
|
+
function progressLine() {
|
|
577
|
+
const start = Date.now();
|
|
578
|
+
let shown = 0;
|
|
579
|
+
return {
|
|
580
|
+
update(step) {
|
|
581
|
+
if (Date.now() - start < 1000)
|
|
582
|
+
return;
|
|
583
|
+
const text = ` Checking ${step}...`;
|
|
584
|
+
process.stdout.write(`\r${text.padEnd(shown)}`);
|
|
585
|
+
shown = text.length;
|
|
586
|
+
},
|
|
587
|
+
clear() {
|
|
588
|
+
if (shown)
|
|
589
|
+
process.stdout.write(`\r${' '.repeat(shown)}\r`);
|
|
590
|
+
shown = 0;
|
|
591
|
+
},
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
const PROMPT_HELP = `
|
|
595
|
+
${bold('launch-doctor prompt')} - print one fix prompt, or copy it to the clipboard
|
|
596
|
+
|
|
597
|
+
${bold('Usage')}
|
|
598
|
+
npx launch-doctor prompt <n> [folder] [options]
|
|
599
|
+
|
|
600
|
+
The numbers are the ones in the report and in LAUNCH_FIXES.md: critical problems first, then the rest.
|
|
601
|
+
|
|
602
|
+
${bold('Options')}
|
|
603
|
+
--copy Copy the prompt to the clipboard (clip, pbcopy, wl-copy or xclip)
|
|
604
|
+
--demo Use the built-in sample app
|
|
605
|
+
--offline Skip network checks (email DNS)
|
|
606
|
+
--domain <domain> Domain you send email from
|
|
607
|
+
-h, --help Show this help
|
|
608
|
+
`;
|
|
609
|
+
/** `launch-doctor prompt <n> [folder] [--copy]`: print (or copy) one fix prompt. */
|
|
610
|
+
async function prompt(argv) {
|
|
611
|
+
let n;
|
|
612
|
+
let folder;
|
|
613
|
+
let copy = false;
|
|
614
|
+
let demo = false;
|
|
615
|
+
let offline = false;
|
|
616
|
+
let domain;
|
|
617
|
+
for (let i = 0; i < argv.length; i++) {
|
|
618
|
+
const a = argv[i];
|
|
619
|
+
if (a === '-h' || a === '--help') {
|
|
620
|
+
process.stdout.write(PROMPT_HELP);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (a === '--copy')
|
|
624
|
+
copy = true;
|
|
625
|
+
else if (a === '--demo')
|
|
626
|
+
demo = true;
|
|
627
|
+
else if (a === '--offline')
|
|
628
|
+
offline = true;
|
|
629
|
+
else if (a === '--domain') {
|
|
630
|
+
const v = argv[++i];
|
|
631
|
+
if (!v || v.startsWith('--'))
|
|
632
|
+
fail('--domain needs a value');
|
|
633
|
+
domain = cleanDomain(v);
|
|
634
|
+
}
|
|
635
|
+
else if (a.startsWith('--domain='))
|
|
636
|
+
domain = cleanDomain(a.slice(9));
|
|
637
|
+
else if (a.startsWith('-'))
|
|
638
|
+
fail(`Unknown option ${a}. Run "launch-doctor prompt --help" to see the options.`);
|
|
639
|
+
else if (n === undefined) {
|
|
640
|
+
// A fix-prompt number (1, 2...) or a finding's id from the report (8 letters and digits).
|
|
641
|
+
if (!(/^\d+$/.test(a) && Number(a) >= 1) && !/^[0-9a-f]{8}$/i.test(a)) {
|
|
642
|
+
fail(`prompt needs a prompt number (1 or more) or a finding id, not "${a}"`);
|
|
643
|
+
}
|
|
644
|
+
n = a;
|
|
645
|
+
}
|
|
646
|
+
else if (!folder)
|
|
647
|
+
folder = a;
|
|
648
|
+
else
|
|
649
|
+
fail(`Unexpected argument ${a}`);
|
|
650
|
+
}
|
|
651
|
+
if (n === undefined)
|
|
652
|
+
fail('prompt needs a number, for example: npx launch-doctor prompt 1 --copy');
|
|
653
|
+
if (demo && folder)
|
|
654
|
+
fail('--demo uses a built-in sample app, so leave out the folder');
|
|
655
|
+
const request = (root) => scanProject({ root, offline: demo || offline, domain });
|
|
656
|
+
const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
|
|
657
|
+
const total = report.counts.critical + report.counts.warning + report.counts.baseline;
|
|
658
|
+
const finding = findFinding(report, n);
|
|
659
|
+
if (!finding) {
|
|
660
|
+
fail(!/^\d+$/.test(n)
|
|
661
|
+
? `No finding with id ${n} in this project (ids come from the report; they change when the line changes).`
|
|
662
|
+
: total
|
|
663
|
+
? `There ${total === 1 ? 'is only 1 fix prompt' : `are only ${total} fix prompts`}, so there is no prompt ${n}.`
|
|
664
|
+
: 'There are no fix prompts: Launch Doctor found nothing to fix.');
|
|
665
|
+
}
|
|
666
|
+
n = String(promptNumber(report, finding));
|
|
667
|
+
const title = finding.display?.title ?? finding.title;
|
|
668
|
+
if (copy) {
|
|
669
|
+
if (copyToClipboard(finding.fixPrompt)) {
|
|
670
|
+
process.stdout.write(`Copied fix prompt ${n}: ${title}\n`);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
process.stdout.write('No clipboard tool was found (clip, pbcopy, wl-copy or xclip), so here is the prompt to copy yourself.\n\n');
|
|
674
|
+
}
|
|
675
|
+
process.stdout.write(`Fix prompt ${n}: ${title}\n\n${finding.fixPrompt}\n`);
|
|
676
|
+
}
|
|
677
|
+
/** `launch-doctor explain <n|id> [folder] [--demo]`: what one finding means, from the same core as the MCP tool. */
|
|
678
|
+
async function explain(argv) {
|
|
679
|
+
const demo = argv.includes('--demo');
|
|
680
|
+
const rest = argv.filter((a) => a !== '--demo');
|
|
681
|
+
const extra = rest.filter((a) => a.startsWith('-'));
|
|
682
|
+
if (extra.length)
|
|
683
|
+
fail(`explain only takes --demo (got ${extra.join(' ')})`);
|
|
684
|
+
const [key, folder, more] = rest;
|
|
685
|
+
if (!key || more)
|
|
686
|
+
fail('explain needs one finding: a number from the report or its id, for example: launch-doctor explain 1');
|
|
687
|
+
if (demo && folder)
|
|
688
|
+
fail('--demo uses a built-in sample app, so leave out the folder');
|
|
689
|
+
const request = (root) => scanProject({ root, offline: true });
|
|
690
|
+
const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
|
|
691
|
+
const finding = findFinding(report, key);
|
|
692
|
+
if (!finding)
|
|
693
|
+
fail(`No finding ${key} in this project. Run launch-doctor first to see the numbers and ids.`);
|
|
694
|
+
const d = findingDetails(report, finding);
|
|
695
|
+
const e = d.explanation;
|
|
696
|
+
const out = [
|
|
697
|
+
'',
|
|
698
|
+
` ${bold(`${d.number}. ${d.title}`)}`,
|
|
699
|
+
` ${dim(`${d.severity} · id ${d.ref} · rule ${d.rule}${d.file ? ` · ${shortWhere({ file: d.file, line: d.line })}` : ''}`)}`,
|
|
700
|
+
'',
|
|
701
|
+
...wrap(d.why, 76, ' '),
|
|
702
|
+
...(e
|
|
703
|
+
? [
|
|
704
|
+
['Why it matters', e.whyItMatters],
|
|
705
|
+
['How to confirm', e.howToConfirm],
|
|
706
|
+
['How to fix', e.howToFix],
|
|
707
|
+
['False alarm?', e.falsePositiveHint],
|
|
708
|
+
].flatMap(([label, text]) => ['', ` ${bold(label)}`, ...wrap(text, 76, ' ')])
|
|
709
|
+
: []),
|
|
710
|
+
...(d.rotate ? ['', ` ${bold('Rotate the key first:')} ${d.rotate}`] : []),
|
|
711
|
+
...(d.usage ? [` ${bold('Check whether someone used it:')} ${d.usage}`] : []),
|
|
712
|
+
'',
|
|
713
|
+
` ${dim(`The fix prompt: launch-doctor prompt ${d.number}${demo ? ' --demo' : folder ? ` ${folder}` : ''} --copy`)}`,
|
|
714
|
+
'',
|
|
715
|
+
];
|
|
716
|
+
process.stdout.write(`${out.join('\n')}\n`);
|
|
717
|
+
}
|
|
473
718
|
async function main() {
|
|
474
719
|
if (process.argv[2] === 'init')
|
|
475
720
|
return init(process.argv.slice(3));
|
|
@@ -481,6 +726,10 @@ async function main() {
|
|
|
481
726
|
return hook(process.argv.slice(3));
|
|
482
727
|
if (process.argv[2] === 'grades')
|
|
483
728
|
return grades(process.argv.slice(3));
|
|
729
|
+
if (process.argv[2] === 'prompt')
|
|
730
|
+
return prompt(process.argv.slice(3));
|
|
731
|
+
if (process.argv[2] === 'explain')
|
|
732
|
+
return explain(process.argv.slice(3));
|
|
484
733
|
const args = parseArgs(process.argv.slice(2));
|
|
485
734
|
if (args.help) {
|
|
486
735
|
process.stdout.write(HELP);
|
|
@@ -490,24 +739,22 @@ async function main() {
|
|
|
490
739
|
process.stdout.write(`${version()}\n`);
|
|
491
740
|
return;
|
|
492
741
|
}
|
|
493
|
-
let stopDemoCleanup;
|
|
494
742
|
if (args.demo) {
|
|
495
743
|
if (args.path)
|
|
496
744
|
fail('--demo scans a built-in sample app, so leave out the folder');
|
|
497
|
-
// Ctrl+C mid-scan would otherwise skip the finally below and leave the folder in the temp directory.
|
|
498
|
-
let demoDir;
|
|
499
|
-
stopDemoCleanup = removeOnSignal(() => demoDir);
|
|
500
|
-
demoDir = createDemoProject();
|
|
501
|
-
args.path = demoDir;
|
|
502
745
|
args.offline = true;
|
|
503
746
|
if (!args.out)
|
|
504
747
|
args.writeFile = false;
|
|
505
|
-
if (!args.json)
|
|
506
|
-
process.stdout.write(`\n ${dim('Demo: scanning a sample app with the usual weekend-project mistakes…')}\n`);
|
|
507
748
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
749
|
+
// The demo's folder is only known once the core creates it.
|
|
750
|
+
let root = args.demo ? '' : core(() => projectRoot(args.path ?? '.'));
|
|
751
|
+
if (args.report) {
|
|
752
|
+
// The report describes the whole project, in the project's own .launchdoctor/ folder.
|
|
753
|
+
if (args.demo)
|
|
754
|
+
fail('--report writes to the project folder, so it needs a real project, not --demo');
|
|
755
|
+
if (args.changeMode)
|
|
756
|
+
fail(`--report describes the whole project, so it can't be used with --${args.changeMode}`);
|
|
757
|
+
}
|
|
511
758
|
if (args.record) {
|
|
512
759
|
// A recorded grade is compared with the next one, so it has to be for the whole project.
|
|
513
760
|
if (args.demo)
|
|
@@ -516,6 +763,8 @@ async function main() {
|
|
|
516
763
|
fail('--record saves the grade for the whole project, so leave out --only and --skip');
|
|
517
764
|
}
|
|
518
765
|
if (args.configFrom) {
|
|
766
|
+
if (args.demo)
|
|
767
|
+
fail('--config-from needs a real project folder, not --demo');
|
|
519
768
|
if (args.updateBaseline)
|
|
520
769
|
fail('--config-from reads the baseline from git, so it cannot be used with --update-baseline');
|
|
521
770
|
try {
|
|
@@ -539,37 +788,58 @@ async function main() {
|
|
|
539
788
|
if (on)
|
|
540
789
|
fail(`${flag} reports on some files only, so it can't be used with ${name}`);
|
|
541
790
|
}
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
fail(`${flag} needs a folder inside a git repository`);
|
|
545
|
-
onlyFiles = files;
|
|
791
|
+
const mode = args.changeMode;
|
|
792
|
+
onlyFiles = core(() => changedPaths(root, mode));
|
|
546
793
|
// A partial report must not overwrite LAUNCH_FIXES.md, which describes the whole project.
|
|
547
794
|
if (!args.out)
|
|
548
795
|
args.writeFile = false;
|
|
549
796
|
}
|
|
797
|
+
// The short report is the default for a person at a terminal; CI, hooks and pull requests keep the full one.
|
|
798
|
+
const short = !args.verbose && !args.json && !args.ci && !args.changeMode && !args.prComment;
|
|
799
|
+
const progress = short && process.stdout.isTTY ? progressLine() : undefined;
|
|
800
|
+
const request = (dir) => scanProject({
|
|
801
|
+
root: dir,
|
|
802
|
+
onProgress: progress?.update,
|
|
803
|
+
offline: args.offline,
|
|
804
|
+
domain: args.domain,
|
|
805
|
+
only: args.only,
|
|
806
|
+
skip: args.skip,
|
|
807
|
+
// When updating, start from scratch so every current finding is saved.
|
|
808
|
+
baseline: args.baseline && !args.updateBaseline,
|
|
809
|
+
configFrom: args.configFrom,
|
|
810
|
+
history: args.history ? args.historyDepth : undefined,
|
|
811
|
+
onlyFiles,
|
|
812
|
+
});
|
|
550
813
|
let report;
|
|
814
|
+
// Ctrl+C mid-scan would otherwise leave the demo folder in the temp directory, so the handler goes in first.
|
|
815
|
+
let demoDir;
|
|
816
|
+
const stopDemoCleanup = args.demo ? removeOnSignal(() => demoDir) : undefined;
|
|
551
817
|
try {
|
|
552
|
-
report =
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
baseline: args.baseline && !args.updateBaseline,
|
|
560
|
-
configFrom: args.configFrom,
|
|
561
|
-
history: args.history ? { depth: args.historyDepth } : undefined,
|
|
562
|
-
});
|
|
818
|
+
report = args.demo
|
|
819
|
+
? await withDemo(request, (dir) => {
|
|
820
|
+
root = demoDir = dir;
|
|
821
|
+
if (!args.json)
|
|
822
|
+
process.stdout.write(`\n ${dim('Demo: scanning a sample app with the usual weekend-project mistakes…')}\n`);
|
|
823
|
+
})
|
|
824
|
+
: await request(root);
|
|
563
825
|
}
|
|
564
826
|
finally {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
rmSync(root, { recursive: true, force: true });
|
|
568
|
-
stopDemoCleanup?.();
|
|
569
|
-
}
|
|
827
|
+
progress?.clear();
|
|
828
|
+
stopDemoCleanup?.();
|
|
570
829
|
}
|
|
571
830
|
if (report.filesScanned === 0) {
|
|
572
|
-
|
|
831
|
+
if (!short)
|
|
832
|
+
fail(`No project files found in ${root}. Run this inside your app's folder.`);
|
|
833
|
+
process.stdout.write(renderEmptyFolder(report, root));
|
|
834
|
+
process.exit(2);
|
|
835
|
+
}
|
|
836
|
+
// A project in a language the checks don't read gets an explanation instead of a meaningless grade.
|
|
837
|
+
const otherLanguage = short && !args.updateBaseline && !args.record && !args.sarif && !args.out
|
|
838
|
+
? unsupportedLanguage(root, report)
|
|
839
|
+
: null;
|
|
840
|
+
if (otherLanguage) {
|
|
841
|
+
process.stdout.write(renderOtherLanguage(report, otherLanguage));
|
|
842
|
+
return;
|
|
573
843
|
}
|
|
574
844
|
if (args.updateBaseline) {
|
|
575
845
|
if (args.demo)
|
|
@@ -603,6 +873,20 @@ async function main() {
|
|
|
603
873
|
process.stderr.write(`${dim(`Couldn't write ${target}: ${err.message}`)}\n`);
|
|
604
874
|
}
|
|
605
875
|
}
|
|
876
|
+
let reportFile;
|
|
877
|
+
if (args.report) {
|
|
878
|
+
const path = join(root, REPORT_FILE);
|
|
879
|
+
try {
|
|
880
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
881
|
+
writeRegularFile(path, renderReportMd(report, { target: args.path ? ` ${shellArg(args.path)}` : '' }));
|
|
882
|
+
const rel = relative(process.cwd(), path);
|
|
883
|
+
reportFile = rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : path;
|
|
884
|
+
}
|
|
885
|
+
catch (err) {
|
|
886
|
+
process.stderr.write(`${dim(`Couldn't write ${path}: ${err.message}`)}
|
|
887
|
+
`);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
606
890
|
if (args.sarif) {
|
|
607
891
|
const sarifPath = isAbsolute(args.sarif) ? args.sarif : resolve(process.cwd(), args.sarif);
|
|
608
892
|
const fallbackUri = ['package.json', 'pyproject.toml', 'requirements.txt', 'README.md'].find((f) => existsSync(join(root, f)));
|
|
@@ -641,8 +925,19 @@ async function main() {
|
|
|
641
925
|
}
|
|
642
926
|
if (args.json)
|
|
643
927
|
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
644
|
-
else
|
|
645
|
-
|
|
928
|
+
else {
|
|
929
|
+
const showBanner = shouldShowBanner({
|
|
930
|
+
wanted: args.banner && !args.ci && !args.out && !args.sarif && !args.prComment && !args.changeMode,
|
|
931
|
+
isTTY: !!process.stdout.isTTY,
|
|
932
|
+
columns: process.stdout.columns,
|
|
933
|
+
env: process.env,
|
|
934
|
+
});
|
|
935
|
+
const lastRecorded = last && describeEntry(last);
|
|
936
|
+
const target = args.demo ? ' --demo' : args.path ? ` ${shellArg(args.path)}` : '';
|
|
937
|
+
process.stdout.write(short
|
|
938
|
+
? renderShortReport(report, { fixFile, reportFile, lastRecorded, banner: showBanner, target, demo: args.demo })
|
|
939
|
+
: renderReport(report, { fixFile, lastRecorded, banner: showBanner }));
|
|
940
|
+
}
|
|
646
941
|
if (recorded)
|
|
647
942
|
(args.json ? process.stderr : process.stdout).write(` ${dim(recorded)}\n\n`);
|
|
648
943
|
if (args.ci && failingFindings(report, args.failOn).length > 0)
|