launch-doctor 0.4.1 → 0.4.2
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 +29 -1
- package/README.md +78 -439
- package/dist/src/banner.d.ts +22 -0
- package/dist/src/banner.js +35 -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 +212 -9
- 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 +6 -1
- package/dist/src/live.js +5 -3
- package/dist/src/prompt.d.ts +23 -0
- package/dist/src/prompt.js +88 -0
- package/dist/src/report.d.ts +12 -1
- package/dist/src/report.js +27 -15
- package/dist/src/short-report.d.ts +59 -0
- package/dist/src/short-report.js +241 -0
- package/dist/src/types.d.ts +27 -0
- package/dist/src/util.d.ts +2 -0
- package/dist/src/util.js +2 -0
- package/package.json +2 -2
package/dist/src/cli.js
CHANGED
|
@@ -9,17 +9,20 @@ import { explainGitHubError, postPrFeedback, prContextFromEnv } from './github.j
|
|
|
9
9
|
import { git } from './git.js';
|
|
10
10
|
import { failingFindings } from './grade.js';
|
|
11
11
|
import { BADGE_FILE, describeEntry, entryFor, GRADES_FILE, headCommit, loadGrades, recordGrade, renderGradeTable, } from './grades.js';
|
|
12
|
+
import { shouldShowBanner } from './banner.js';
|
|
12
13
|
import { DEFAULT_HISTORY_DEPTH } from './history.js';
|
|
13
14
|
import { runHook } from './hook.js';
|
|
14
|
-
import { setupHooks } from './hooks-setup.js';
|
|
15
|
+
import { pinnedPackage, setupHooks, upgradeHooks } from './hooks-setup.js';
|
|
15
16
|
import { CATEGORY_IDS, runDoctor } from './index.js';
|
|
16
17
|
import { badgeUrl, GRADES_BRANCH, githubRepo, runInit } from './init.js';
|
|
17
18
|
import { runLiveScan } from './live.js';
|
|
18
19
|
import { runMcpServer } from './mcp.js';
|
|
19
20
|
import { assertConfigRef } from './project.js';
|
|
21
|
+
import { copyToClipboard, promptFor, unsupportedLanguage } from './prompt.js';
|
|
20
22
|
import { bold, dim, renderReport } from './report.js';
|
|
21
23
|
import { writeRegularFile } from './safe-fs.js';
|
|
22
24
|
import { renderSarif } from './sarif.js';
|
|
25
|
+
import { renderEmptyFolder, renderOtherLanguage, renderShortReport } from './short-report.js';
|
|
23
26
|
import { renderStepSummary } from './summary.js';
|
|
24
27
|
import { version } from './version.js';
|
|
25
28
|
const HELP = `
|
|
@@ -29,8 +32,12 @@ const HELP = `
|
|
|
29
32
|
npx launch-doctor [folder] [options]
|
|
30
33
|
npx launch-doctor init [folder] Create .launchdoctorignore and a GitHub Actions workflow
|
|
31
34
|
npx launch-doctor init --hooks Set up hooks that check every AI edit and every commit
|
|
35
|
+
npx launch-doctor init --hooks --upgrade
|
|
36
|
+
Move those hooks onto this version (only the launch-doctor command changes)
|
|
32
37
|
npx launch-doctor init --monitor Add a GitHub Actions workflow that re-checks the project every week
|
|
33
38
|
npx launch-doctor grades [folder] Show the grades saved with --record
|
|
39
|
+
npx launch-doctor prompt <n> [folder] [--copy]
|
|
40
|
+
Print fix prompt n (the numbers in the report and LAUNCH_FIXES.md)
|
|
34
41
|
npx launch-doctor scan <url> Check your deployed site (exposed files, source maps, open Supabase tables, headers)
|
|
35
42
|
npx launch-doctor mcp Start an MCP server so Claude Code, Cursor and other AI tools can run checks
|
|
36
43
|
|
|
@@ -58,6 +65,9 @@ const HELP = `
|
|
|
58
65
|
--changed Only report on files changed since the last commit (fast, for hooks)
|
|
59
66
|
--staged Only report on files staged for the next commit (for a pre-commit hook)
|
|
60
67
|
--demo Scan a built-in sample app full of mistakes
|
|
68
|
+
--verbose Show the full report: every category and every finding
|
|
69
|
+
--copy With prompt <n>, copy the fix prompt to the clipboard
|
|
70
|
+
--no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
|
|
61
71
|
-h, --help Show this help
|
|
62
72
|
-v, --version Show the version
|
|
63
73
|
|
|
@@ -100,6 +110,8 @@ function parseArgs(argv) {
|
|
|
100
110
|
historyDepth: DEFAULT_HISTORY_DEPTH,
|
|
101
111
|
record: false,
|
|
102
112
|
demo: false,
|
|
113
|
+
banner: true,
|
|
114
|
+
verbose: false,
|
|
103
115
|
help: false,
|
|
104
116
|
version: false,
|
|
105
117
|
};
|
|
@@ -123,6 +135,10 @@ function parseArgs(argv) {
|
|
|
123
135
|
args.ci = true;
|
|
124
136
|
else if (a === '--demo')
|
|
125
137
|
args.demo = true;
|
|
138
|
+
else if (a === '--no-banner')
|
|
139
|
+
args.banner = false;
|
|
140
|
+
else if (a === '--verbose')
|
|
141
|
+
args.verbose = true;
|
|
126
142
|
else if (a === '--pr-comment')
|
|
127
143
|
args.prComment = true;
|
|
128
144
|
else if (a === '--no-file')
|
|
@@ -224,17 +240,24 @@ function fail(message) {
|
|
|
224
240
|
function init(argv) {
|
|
225
241
|
const hooks = argv.includes('--hooks');
|
|
226
242
|
const monitor = argv.includes('--monitor');
|
|
227
|
-
const
|
|
243
|
+
const upgrade = argv.includes('--upgrade');
|
|
244
|
+
const rest = argv.filter((a) => a !== '--hooks' && a !== '--monitor' && a !== '--upgrade');
|
|
228
245
|
const extra = rest.filter((a) => a.startsWith('-'));
|
|
229
246
|
if (extra.length)
|
|
230
|
-
fail(`init only takes --hooks or --monitor (got ${extra.join(' ')})`);
|
|
247
|
+
fail(`init only takes --hooks, --hooks --upgrade or --monitor (got ${extra.join(' ')})`);
|
|
231
248
|
if (hooks && monitor)
|
|
232
249
|
fail('Run "init --hooks" and "init --monitor" one at a time');
|
|
250
|
+
if (upgrade && !hooks)
|
|
251
|
+
fail('--upgrade goes with --hooks: launch-doctor init --hooks --upgrade');
|
|
233
252
|
if (rest.length > 1)
|
|
234
253
|
fail('init takes at most one folder');
|
|
235
254
|
const root = resolve(rest[0] ?? '.');
|
|
236
255
|
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
237
256
|
fail(`Folder not found: ${root}`);
|
|
257
|
+
if (hooks && upgrade) {
|
|
258
|
+
upgradeHooksCommand(root);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
238
261
|
if (hooks) {
|
|
239
262
|
const result = setupHooks(root);
|
|
240
263
|
for (const f of result.created)
|
|
@@ -261,6 +284,29 @@ function init(argv) {
|
|
|
261
284
|
` ${dim('To check your deployed site too, add a repository variable named LAUNCH_DOCTOR_URL.')}\n`);
|
|
262
285
|
}
|
|
263
286
|
}
|
|
287
|
+
/** `init --hooks --upgrade`: show the lines that change, then write them. */
|
|
288
|
+
function upgradeHooksCommand(root) {
|
|
289
|
+
const result = upgradeHooks(root);
|
|
290
|
+
const out = (line) => process.stdout.write(`${line}\n`);
|
|
291
|
+
for (const c of result.changed) {
|
|
292
|
+
out(` ${c.file}`);
|
|
293
|
+
for (const line of c.before)
|
|
294
|
+
out(` - ${line}`);
|
|
295
|
+
for (const line of c.after)
|
|
296
|
+
out(` + ${line}`);
|
|
297
|
+
out(` upgraded ${c.file} ${dim(`(only the launch-doctor command changed)`)}`);
|
|
298
|
+
}
|
|
299
|
+
for (const [f, spec] of result.current)
|
|
300
|
+
out(` up to date ${f} ${dim(`(${spec})`)}`);
|
|
301
|
+
for (const f of result.unpinned) {
|
|
302
|
+
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")')}`);
|
|
303
|
+
}
|
|
304
|
+
for (const [f, why] of result.skipped)
|
|
305
|
+
out(` skipped ${f} ${dim(`(${why})`)}`);
|
|
306
|
+
if (!result.changed.length && !result.current.length && !result.unpinned.length) {
|
|
307
|
+
out(` ${dim(`No launch-doctor hooks found. Set them up with: npx "${pinnedPackage()}" init --hooks`)}`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
264
310
|
/** `launch-doctor grades [folder] [--json]`: the grades saved with --record, newest first. */
|
|
265
311
|
function grades(argv) {
|
|
266
312
|
const json = argv.includes('--json');
|
|
@@ -338,6 +384,7 @@ const SCAN_HELP = `
|
|
|
338
384
|
--ci Exit with code 1 on findings at or above --fail-on
|
|
339
385
|
--fail-on <level> With --ci, the lowest severity that fails: critical (default) or warning
|
|
340
386
|
--no-db Don't test Supabase tables with the public key found in the page
|
|
387
|
+
--no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
|
|
341
388
|
-h, --help Show this help
|
|
342
389
|
|
|
343
390
|
Only scan sites you own or are allowed to test. The scan makes a few dozen ordinary GET requests
|
|
@@ -351,6 +398,7 @@ async function scan(argv) {
|
|
|
351
398
|
let ci = false;
|
|
352
399
|
let failOn = 'critical';
|
|
353
400
|
let skipDatabase = false;
|
|
401
|
+
let banner = true;
|
|
354
402
|
for (let i = 0; i < argv.length; i++) {
|
|
355
403
|
const a = argv[i];
|
|
356
404
|
const value = () => {
|
|
@@ -371,6 +419,8 @@ async function scan(argv) {
|
|
|
371
419
|
writeFile = false;
|
|
372
420
|
else if (a === '--no-db')
|
|
373
421
|
skipDatabase = true;
|
|
422
|
+
else if (a === '--no-banner')
|
|
423
|
+
banner = false;
|
|
374
424
|
else if (a === '--out')
|
|
375
425
|
out = value();
|
|
376
426
|
else if (a.startsWith('--out='))
|
|
@@ -425,8 +475,15 @@ async function scan(argv) {
|
|
|
425
475
|
if (json)
|
|
426
476
|
process.stdout.write(`${JSON.stringify(report, null, 2)}
|
|
427
477
|
`);
|
|
428
|
-
else
|
|
429
|
-
|
|
478
|
+
else {
|
|
479
|
+
const showBanner = shouldShowBanner({
|
|
480
|
+
wanted: banner && !ci && !out,
|
|
481
|
+
isTTY: !!process.stdout.isTTY,
|
|
482
|
+
columns: process.stdout.columns,
|
|
483
|
+
env: process.env,
|
|
484
|
+
});
|
|
485
|
+
process.stdout.write(renderReport(report, { fixFile, banner: showBanner }));
|
|
486
|
+
}
|
|
430
487
|
if (ci && failingFindings(report, failOn).length > 0)
|
|
431
488
|
process.exitCode = 1;
|
|
432
489
|
}
|
|
@@ -470,6 +527,123 @@ async function commentOnPr(report, root) {
|
|
|
470
527
|
process.stderr.write(`\n ${dim(explainGitHubError(err))}\n`);
|
|
471
528
|
}
|
|
472
529
|
}
|
|
530
|
+
/** A path as it would be typed in a shell: quoted when it has spaces or other special characters. */
|
|
531
|
+
function shellArg(s) {
|
|
532
|
+
return /^[\w./:\\-]+$/.test(s) ? s : `"${s.replace(/"/g, '\\"')}"`;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* "Checking Secrets & keys..." on one terminal line while a long scan runs. Nothing for the first second,
|
|
536
|
+
* so quick scans never show it, and the line is cleared before the report is printed.
|
|
537
|
+
*/
|
|
538
|
+
function progressLine() {
|
|
539
|
+
const start = Date.now();
|
|
540
|
+
let shown = 0;
|
|
541
|
+
return {
|
|
542
|
+
update(step) {
|
|
543
|
+
if (Date.now() - start < 1000)
|
|
544
|
+
return;
|
|
545
|
+
const text = ` Checking ${step}...`;
|
|
546
|
+
process.stdout.write(`\r${text.padEnd(shown)}`);
|
|
547
|
+
shown = text.length;
|
|
548
|
+
},
|
|
549
|
+
clear() {
|
|
550
|
+
if (shown)
|
|
551
|
+
process.stdout.write(`\r${' '.repeat(shown)}\r`);
|
|
552
|
+
shown = 0;
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const PROMPT_HELP = `
|
|
557
|
+
${bold('launch-doctor prompt')} - print one fix prompt, or copy it to the clipboard
|
|
558
|
+
|
|
559
|
+
${bold('Usage')}
|
|
560
|
+
npx launch-doctor prompt <n> [folder] [options]
|
|
561
|
+
|
|
562
|
+
The numbers are the ones in the report and in LAUNCH_FIXES.md: critical problems first, then the rest.
|
|
563
|
+
|
|
564
|
+
${bold('Options')}
|
|
565
|
+
--copy Copy the prompt to the clipboard (clip, pbcopy, wl-copy or xclip)
|
|
566
|
+
--demo Use the built-in sample app
|
|
567
|
+
--offline Skip network checks (email DNS)
|
|
568
|
+
--domain <domain> Domain you send email from
|
|
569
|
+
-h, --help Show this help
|
|
570
|
+
`;
|
|
571
|
+
/** `launch-doctor prompt <n> [folder] [--copy]`: print (or copy) one fix prompt. */
|
|
572
|
+
async function prompt(argv) {
|
|
573
|
+
let n;
|
|
574
|
+
let folder;
|
|
575
|
+
let copy = false;
|
|
576
|
+
let demo = false;
|
|
577
|
+
let offline = false;
|
|
578
|
+
let domain;
|
|
579
|
+
for (let i = 0; i < argv.length; i++) {
|
|
580
|
+
const a = argv[i];
|
|
581
|
+
if (a === '-h' || a === '--help') {
|
|
582
|
+
process.stdout.write(PROMPT_HELP);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (a === '--copy')
|
|
586
|
+
copy = true;
|
|
587
|
+
else if (a === '--demo')
|
|
588
|
+
demo = true;
|
|
589
|
+
else if (a === '--offline')
|
|
590
|
+
offline = true;
|
|
591
|
+
else if (a === '--domain') {
|
|
592
|
+
const v = argv[++i];
|
|
593
|
+
if (!v || v.startsWith('--'))
|
|
594
|
+
fail('--domain needs a value');
|
|
595
|
+
domain = cleanDomain(v);
|
|
596
|
+
}
|
|
597
|
+
else if (a.startsWith('--domain='))
|
|
598
|
+
domain = cleanDomain(a.slice(9));
|
|
599
|
+
else if (a.startsWith('-'))
|
|
600
|
+
fail(`Unknown option ${a}. Run "launch-doctor prompt --help" to see the options.`);
|
|
601
|
+
else if (n === undefined) {
|
|
602
|
+
if (!/^\d+$/.test(a) || Number(a) < 1)
|
|
603
|
+
fail(`prompt needs a prompt number (1 or more), not "${a}"`);
|
|
604
|
+
n = Number(a);
|
|
605
|
+
}
|
|
606
|
+
else if (!folder)
|
|
607
|
+
folder = a;
|
|
608
|
+
else
|
|
609
|
+
fail(`Unexpected argument ${a}`);
|
|
610
|
+
}
|
|
611
|
+
if (n === undefined)
|
|
612
|
+
fail('prompt needs a number, for example: npx launch-doctor prompt 1 --copy');
|
|
613
|
+
if (demo && folder)
|
|
614
|
+
fail('--demo uses a built-in sample app, so leave out the folder');
|
|
615
|
+
let root = resolve(folder ?? '.');
|
|
616
|
+
if (demo) {
|
|
617
|
+
root = createDemoProject();
|
|
618
|
+
offline = true;
|
|
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
|
+
}
|
|
630
|
+
const total = report.counts.critical + report.counts.warning + report.counts.baseline;
|
|
631
|
+
const finding = promptFor(report, n);
|
|
632
|
+
if (!finding) {
|
|
633
|
+
fail(total
|
|
634
|
+
? `There ${total === 1 ? 'is only 1 fix prompt' : `are only ${total} fix prompts`}, so there is no prompt ${n}.`
|
|
635
|
+
: 'There are no fix prompts: Launch Doctor found nothing to fix.');
|
|
636
|
+
}
|
|
637
|
+
const title = finding.display?.title ?? finding.title;
|
|
638
|
+
if (copy) {
|
|
639
|
+
if (copyToClipboard(finding.fixPrompt)) {
|
|
640
|
+
process.stdout.write(`Copied fix prompt ${n}: ${title}\n`);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
process.stdout.write('No clipboard tool was found (clip, pbcopy, wl-copy or xclip), so here is the prompt to copy yourself.\n\n');
|
|
644
|
+
}
|
|
645
|
+
process.stdout.write(`Fix prompt ${n}: ${title}\n\n${finding.fixPrompt}\n`);
|
|
646
|
+
}
|
|
473
647
|
async function main() {
|
|
474
648
|
if (process.argv[2] === 'init')
|
|
475
649
|
return init(process.argv.slice(3));
|
|
@@ -481,6 +655,8 @@ async function main() {
|
|
|
481
655
|
return hook(process.argv.slice(3));
|
|
482
656
|
if (process.argv[2] === 'grades')
|
|
483
657
|
return grades(process.argv.slice(3));
|
|
658
|
+
if (process.argv[2] === 'prompt')
|
|
659
|
+
return prompt(process.argv.slice(3));
|
|
484
660
|
const args = parseArgs(process.argv.slice(2));
|
|
485
661
|
if (args.help) {
|
|
486
662
|
process.stdout.write(HELP);
|
|
@@ -547,10 +723,13 @@ async function main() {
|
|
|
547
723
|
if (!args.out)
|
|
548
724
|
args.writeFile = false;
|
|
549
725
|
}
|
|
726
|
+
// The short report is the default for a person at a terminal; CI, hooks and pull requests keep the full one.
|
|
727
|
+
const short = !args.verbose && !args.json && !args.ci && !args.changeMode && !args.prComment;
|
|
728
|
+
const progress = short && process.stdout.isTTY ? progressLine() : undefined;
|
|
550
729
|
let report;
|
|
551
730
|
try {
|
|
552
731
|
report = await runDoctor(root, {
|
|
553
|
-
|
|
732
|
+
onProgress: progress?.update,
|
|
554
733
|
offline: args.offline,
|
|
555
734
|
domain: args.domain,
|
|
556
735
|
only: args.only,
|
|
@@ -559,9 +738,11 @@ async function main() {
|
|
|
559
738
|
baseline: args.baseline && !args.updateBaseline,
|
|
560
739
|
configFrom: args.configFrom,
|
|
561
740
|
history: args.history ? { depth: args.historyDepth } : undefined,
|
|
741
|
+
onlyFiles,
|
|
562
742
|
});
|
|
563
743
|
}
|
|
564
744
|
finally {
|
|
745
|
+
progress?.clear();
|
|
565
746
|
// The demo project lives in a temp folder; always clean it up, even if the scan throws.
|
|
566
747
|
if (args.demo) {
|
|
567
748
|
rmSync(root, { recursive: true, force: true });
|
|
@@ -569,7 +750,18 @@ async function main() {
|
|
|
569
750
|
}
|
|
570
751
|
}
|
|
571
752
|
if (report.filesScanned === 0) {
|
|
572
|
-
|
|
753
|
+
if (!short)
|
|
754
|
+
fail(`No project files found in ${root}. Run this inside your app's folder.`);
|
|
755
|
+
process.stdout.write(renderEmptyFolder(report, root));
|
|
756
|
+
process.exit(2);
|
|
757
|
+
}
|
|
758
|
+
// A project in a language the checks don't read gets an explanation instead of a meaningless grade.
|
|
759
|
+
const otherLanguage = short && !args.updateBaseline && !args.record && !args.sarif && !args.out
|
|
760
|
+
? unsupportedLanguage(root, report)
|
|
761
|
+
: null;
|
|
762
|
+
if (otherLanguage) {
|
|
763
|
+
process.stdout.write(renderOtherLanguage(report, otherLanguage));
|
|
764
|
+
return;
|
|
573
765
|
}
|
|
574
766
|
if (args.updateBaseline) {
|
|
575
767
|
if (args.demo)
|
|
@@ -641,8 +833,19 @@ async function main() {
|
|
|
641
833
|
}
|
|
642
834
|
if (args.json)
|
|
643
835
|
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
644
|
-
else
|
|
645
|
-
|
|
836
|
+
else {
|
|
837
|
+
const showBanner = shouldShowBanner({
|
|
838
|
+
wanted: args.banner && !args.ci && !args.out && !args.sarif && !args.prComment && !args.changeMode,
|
|
839
|
+
isTTY: !!process.stdout.isTTY,
|
|
840
|
+
columns: process.stdout.columns,
|
|
841
|
+
env: process.env,
|
|
842
|
+
});
|
|
843
|
+
const lastRecorded = last && describeEntry(last);
|
|
844
|
+
const target = args.demo ? ' --demo' : args.path ? ` ${shellArg(args.path)}` : '';
|
|
845
|
+
process.stdout.write(short
|
|
846
|
+
? renderShortReport(report, { fixFile, lastRecorded, banner: showBanner, target, demo: args.demo })
|
|
847
|
+
: renderReport(report, { fixFile, lastRecorded, banner: showBanner }));
|
|
848
|
+
}
|
|
646
849
|
if (recorded)
|
|
647
850
|
(args.json ? process.stderr : process.stdout).write(` ${dim(recorded)}\n\n`);
|
|
648
851
|
if (args.ci && failingFindings(report, args.failOn).length > 0)
|
package/dist/src/fixes.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type { Report } from './types.js';
|
|
1
|
+
import type { Finding, Report } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every finding in fix-prompt order: critical ones first, then warnings, each in category order.
|
|
4
|
+
* Prompt n in LAUNCH_FIXES.md, `launch-doctor prompt n` and the short report's numbers all use this order.
|
|
5
|
+
*/
|
|
6
|
+
export declare function orderedFindings(report: Report): Finding[];
|
|
7
|
+
/** One prompt for every critical finding, numbered like the prompts in LAUNCH_FIXES.md. */
|
|
8
|
+
export declare function criticalPrompt(report: Report): string | null;
|
|
2
9
|
/** A markdown file of copy-paste prompts, ordered by importance. */
|
|
3
10
|
export declare function renderFixes(report: Report): string;
|
package/dist/src/fixes.js
CHANGED
|
@@ -13,18 +13,41 @@ function section(f, n) {
|
|
|
13
13
|
const parts = [`### ${n}. ${md(f.title)}`, ''];
|
|
14
14
|
if (f.location)
|
|
15
15
|
parts.push(`**Where:** ${mdCode(shortWhere(f.location))}`, '');
|
|
16
|
+
// Links come from Launch Doctor's own provider table, so they are written as links; other text is escaped.
|
|
17
|
+
const link = (x) => (/^https:\/\/[^\s<>]+$/.test(x) ? `<${x}>` : md(x));
|
|
18
|
+
if (f.display?.rotate)
|
|
19
|
+
parts.push(`**Rotate the key first:** ${link(f.display.rotate)}`, '');
|
|
20
|
+
if (f.display?.usage)
|
|
21
|
+
parts.push(`**Check whether someone used it:** ${link(f.display.usage)}`, '');
|
|
16
22
|
if (f.baseline)
|
|
17
23
|
parts.push('_Existing issue, recorded in .launchdoctor-baseline.json._', '');
|
|
18
24
|
parts.push(`**Why it matters:** ${md(f.why, { oneLine: false })}`, '', '**Prompt to paste:**', '', fence(f.fixPrompt), '');
|
|
19
25
|
parts.push(`<sub>Not relevant to your app? Add \`${f.id}\` to a \`.launchdoctorignore\` file.</sub>`, '');
|
|
20
26
|
return parts.join('\n');
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Every finding in fix-prompt order: critical ones first, then warnings, each in category order.
|
|
30
|
+
* Prompt n in LAUNCH_FIXES.md, `launch-doctor prompt n` and the short report's numbers all use this order.
|
|
31
|
+
*/
|
|
32
|
+
export function orderedFindings(report) {
|
|
33
|
+
const all = report.categories.flatMap((c) => c.findings);
|
|
34
|
+
return [...all.filter((f) => f.severity === 'critical'), ...all.filter((f) => f.severity === 'warning')];
|
|
35
|
+
}
|
|
36
|
+
/** One prompt for every critical finding, numbered like the prompts in LAUNCH_FIXES.md. */
|
|
37
|
+
export function criticalPrompt(report) {
|
|
38
|
+
const critical = orderedFindings(report).filter((f) => f.severity === 'critical');
|
|
39
|
+
if (!critical.length)
|
|
40
|
+
return null;
|
|
41
|
+
return (`I ran Launch Doctor on my app and it found ${plural(critical.length, 'critical problem')}. ` +
|
|
42
|
+
"Fix them one at a time, then tell me what you changed. For each one, explain the change in plain English and how to test it. Don't change anything unrelated, and ask me before deleting data.\n\n" +
|
|
43
|
+
critical.map((f, i) => `${i + 1}. ${f.title}${f.location ? ` — ${shortWhere(f.location)}` : ''}`).join('\n'));
|
|
44
|
+
}
|
|
22
45
|
/** A markdown file of copy-paste prompts, ordered by importance. */
|
|
23
46
|
export function renderFixes(report) {
|
|
24
|
-
const
|
|
25
|
-
const critical =
|
|
26
|
-
const warnings =
|
|
27
|
-
const
|
|
47
|
+
const ordered = orderedFindings(report);
|
|
48
|
+
const critical = ordered.filter((f) => f.severity === 'critical');
|
|
49
|
+
const warnings = ordered.filter((f) => f.severity === 'warning');
|
|
50
|
+
const allCritical = criticalPrompt(report);
|
|
28
51
|
const manual = report.categories.flatMap((c) => c.manual);
|
|
29
52
|
const date = report.generatedAt.slice(0, 10);
|
|
30
53
|
const out = [
|
|
@@ -32,13 +55,11 @@ export function renderFixes(report) {
|
|
|
32
55
|
'',
|
|
33
56
|
`**Grade: ${report.grade}** · ${report.verdict} · ${plural(critical.length, 'critical issue')} · ${plural(warnings.length, 'warning')} · checked ${date}`,
|
|
34
57
|
'',
|
|
35
|
-
'## How to use this file',
|
|
36
|
-
'',
|
|
37
|
-
'1. Paste **one prompt at a time** into your AI coding tool (Claude Code, Cursor, Lovable, Bolt, Windsurf…).',
|
|
38
|
-
'2. Read what it changed and test the app.',
|
|
39
|
-
'3. Run `npx launch-doctor` again to see your new grade.',
|
|
40
|
-
'',
|
|
41
58
|
];
|
|
59
|
+
if (allCritical) {
|
|
60
|
+
out.push('## Fix the critical problems first', '', `One prompt for all ${plural(critical.length, 'critical problem')}. Paste it into your AI coding tool, then run Launch Doctor again.`, '', fence(allCritical), '');
|
|
61
|
+
}
|
|
62
|
+
out.push('## How to use this file', '', '1. Paste **one prompt at a time** into your AI coding tool (Claude Code, Cursor, Lovable, Bolt, Windsurf…).', '2. Read what it changed and test the app.', '3. Run `npx launch-doctor` again to see your new grade.', '');
|
|
42
63
|
if (ordered.length) {
|
|
43
64
|
out.push('### Or fix everything in one go', '', fence('I ran Launch Doctor on my app and it found the problems below. Fix them one at a time, in this order. ' +
|
|
44
65
|
"For each one: explain the change in plain English, make it, and tell me how to test it. Don't change anything unrelated, and ask me before deleting data.\n\n" +
|
package/dist/src/grade.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CategoryResult, CheckOutput, Finding, Grade, Report, Severity } from './types.js';
|
|
1
|
+
import type { CategoryResult, CheckOutput, Finding, Grade, GroupGrade, Report, Severity } from './types.js';
|
|
2
2
|
export declare function scoreCategory(out: CheckOutput): number;
|
|
3
3
|
export declare function toGrade(score: number): Grade;
|
|
4
4
|
export declare function overall(categories: CategoryResult[]): {
|
|
@@ -12,5 +12,12 @@ export declare function overall(categories: CategoryResult[]): {
|
|
|
12
12
|
baseline: number;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
/** The two headline grades: the categories each one covers. */
|
|
16
|
+
export declare const GRADE_GROUPS: {
|
|
17
|
+
readonly security: readonly ['secrets', 'database', 'access', 'payments', 'costs'];
|
|
18
|
+
readonly launch: readonly ['email', 'monitoring', 'legal', 'first-impressions'];
|
|
19
|
+
};
|
|
20
|
+
/** One group's grade, with the same rules as the overall grade. Null when none of its categories applied. */
|
|
21
|
+
export declare function groupGrade(categories: CategoryResult[], ids: readonly string[]): GroupGrade;
|
|
15
22
|
/** New findings at or above a severity level: the ones that should fail a CI run. Baseline findings don't count. */
|
|
16
23
|
export declare function failingFindings(report: Report, failOn: Severity): Finding[];
|
package/dist/src/grade.js
CHANGED
|
@@ -44,6 +44,19 @@ export function overall(categories) {
|
|
|
44
44
|
: 'Looks ready to launch';
|
|
45
45
|
return { score, grade: toGrade(score), verdict, counts: { critical, warning, manual, baseline: 0 } };
|
|
46
46
|
}
|
|
47
|
+
/** The two headline grades: the categories each one covers. */
|
|
48
|
+
export const GRADE_GROUPS = {
|
|
49
|
+
security: ['secrets', 'database', 'access', 'payments', 'costs'],
|
|
50
|
+
launch: ['email', 'monitoring', 'legal', 'first-impressions'],
|
|
51
|
+
};
|
|
52
|
+
/** One group's grade, with the same rules as the overall grade. Null when none of its categories applied. */
|
|
53
|
+
export function groupGrade(categories, ids) {
|
|
54
|
+
const group = categories.filter((c) => ids.includes(c.id));
|
|
55
|
+
if (!group.some((c) => c.applicable && c.score !== null))
|
|
56
|
+
return { score: null, grade: null };
|
|
57
|
+
const { score, grade } = overall(group);
|
|
58
|
+
return { score, grade };
|
|
59
|
+
}
|
|
47
60
|
/** New findings at or above a severity level: the ones that should fail a CI run. Baseline findings don't count. */
|
|
48
61
|
export function failingFindings(report, failOn) {
|
|
49
62
|
return report.categories
|
package/dist/src/history.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import { matchKeys } from './checks/secrets.js';
|
|
3
|
+
import { leakPlaybook, matchKeys, rotateHint, usageLink } from './checks/secrets.js';
|
|
4
4
|
import { gitArgs, SAFE_DIFF } from './git.js';
|
|
5
5
|
import { isRealEnvPath } from './project.js';
|
|
6
6
|
import { mask } from './util.js';
|
|
@@ -94,9 +94,16 @@ function historyFinding(hit) {
|
|
|
94
94
|
title: `Secret still in git history: ${hit.pattern.name} (commit ${short}, ${hit.path})`,
|
|
95
95
|
why: `This ${hit.pattern.name} (${shown}) was removed from your code, but it's still in commit ${short}. Anyone who can clone the repo can dig it out, so it has to be treated as leaked.`,
|
|
96
96
|
location: { file: hit.path },
|
|
97
|
+
display: {
|
|
98
|
+
title: `Anyone who can clone the repo can use your ${hit.pattern.name}: it is still in git history`,
|
|
99
|
+
reason: `added in commit ${short}`,
|
|
100
|
+
rotate: rotateHint(hit.pattern),
|
|
101
|
+
...(usageLink(hit.pattern.id) ? { usage: usageLink(hit.pattern.id) } : {}),
|
|
102
|
+
},
|
|
97
103
|
fixPrompt: `Commit ${short} in my git history added a ${hit.pattern.name} (it starts with "${shown}") to ${hit.path}. The code no longer has it, but the history does. Please:\n` +
|
|
98
104
|
`1. Walk me through revoking this key and creating a new one (${hit.pattern.rotate}), and make sure the new one lives only in an environment variable.\n` +
|
|
99
105
|
`2. Optionally, explain how to remove it from the history with git filter-repo (for example "git filter-repo --replace-text replacements.txt"), what that means for everyone else who has a clone, and that I'll need to force-push.\n` +
|
|
100
|
-
`Rotating the key matters most: rewriting history doesn't help if someone already copied it
|
|
106
|
+
`Rotating the key matters most: rewriting history doesn't help if someone already copied it.` +
|
|
107
|
+
leakPlaybook({ usage: usageLink(hit.pattern.id), from: 'history' }),
|
|
101
108
|
};
|
|
102
109
|
}
|
|
@@ -22,3 +22,29 @@ export declare function shellQuote(value: string): string;
|
|
|
22
22
|
export declare function preCommitBlock(projectDir: string): string;
|
|
23
23
|
/** Set up the Claude Code hook, the Cursor hook and the git pre-commit hook. Existing files are merged into, never replaced. */
|
|
24
24
|
export declare function setupHooks(root: string): HookSetupResult;
|
|
25
|
+
export interface HookChange {
|
|
26
|
+
file: string;
|
|
27
|
+
/** The lines that change, before and after. */
|
|
28
|
+
before: string[];
|
|
29
|
+
after: string[];
|
|
30
|
+
/** The new file contents (written by upgradeHooks unless dryRun). */
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HookUpgradeResult {
|
|
34
|
+
changed: HookChange[];
|
|
35
|
+
/** [file, package spec] already on the current version. */
|
|
36
|
+
current: [string, string][];
|
|
37
|
+
/** Files whose launch-doctor hook has no version: it runs the newest release, so it is reported, not rewritten. */
|
|
38
|
+
unpinned: string[];
|
|
39
|
+
/** [file, why] for files with no launch-doctor hook, or that could not be read. */
|
|
40
|
+
skipped: [string, string][];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `init --hooks --upgrade`: move the hooks that init --hooks installed onto this version's package spec
|
|
44
|
+
* (launch-doctor@^0.4.0 becomes launch-doctor@^0.5.0, say). Only the launch-doctor command changes: other hooks,
|
|
45
|
+
* other settings and the files' formatting are left alone. Hooks installed without a version are reported, not
|
|
46
|
+
* rewritten. With dryRun, nothing is written.
|
|
47
|
+
*/
|
|
48
|
+
export declare function upgradeHooks(root: string, { dryRun }?: {
|
|
49
|
+
dryRun?: boolean | undefined;
|
|
50
|
+
}): HookUpgradeResult;
|
package/dist/src/hooks-setup.js
CHANGED
|
@@ -47,7 +47,9 @@ function writeJson(path, data) {
|
|
|
47
47
|
* Does this hook list already run a launch-doctor hook command? Any version counts, including the unpinned commands
|
|
48
48
|
* older releases wrote: re-running init never adds a second hook, and never rewrites one the user already has.
|
|
49
49
|
*/
|
|
50
|
-
const hasOurCommand = (entries, tool) =>
|
|
50
|
+
const hasOurCommand = (entries, tool) => ourCommand(tool).test(JSON.stringify(entries ?? null));
|
|
51
|
+
/** A launch-doctor hook command for this tool, pinned or not, as it appears in JSON text (quotes escaped). */
|
|
52
|
+
const ourCommand = (tool) => new RegExp(String.raw `\blaunch-doctor(?:@[^\s"\\]+)?\\?"? hook ${tool}\b`);
|
|
51
53
|
/** .claude/settings.json: a PostToolUse hook that checks every file Claude Code writes or edits. */
|
|
52
54
|
function setupClaude(root, result) {
|
|
53
55
|
const rel = '.claude/settings.json';
|
|
@@ -185,3 +187,115 @@ export function setupHooks(root) {
|
|
|
185
187
|
setupPreCommit(root, result);
|
|
186
188
|
return result;
|
|
187
189
|
}
|
|
190
|
+
/** A pinned package spec as init --hooks writes it: launch-doctor@^0.4.0 */
|
|
191
|
+
const PINNED_SPEC = /launch-doctor@\^\d+\.\d+\.\d+/g;
|
|
192
|
+
/**
|
|
193
|
+
* Upgrade one file: replace the pinned package spec on the lines `isOurs` accepts. Every other line, and the
|
|
194
|
+
* file's formatting, stays exactly as it was.
|
|
195
|
+
*/
|
|
196
|
+
function upgradeText(file, text, isOurs, result) {
|
|
197
|
+
const target = pinnedPackage();
|
|
198
|
+
const lines = text.split('\n');
|
|
199
|
+
const before = [];
|
|
200
|
+
const after = [];
|
|
201
|
+
let ours = 0;
|
|
202
|
+
let pinned = 0;
|
|
203
|
+
const out = lines.map((line, i) => {
|
|
204
|
+
if (!isOurs(line, i))
|
|
205
|
+
return line;
|
|
206
|
+
ours++;
|
|
207
|
+
if (!PINNED_SPEC.test(line))
|
|
208
|
+
return line;
|
|
209
|
+
PINNED_SPEC.lastIndex = 0;
|
|
210
|
+
pinned++;
|
|
211
|
+
const next = line.replace(PINNED_SPEC, target);
|
|
212
|
+
if (next !== line) {
|
|
213
|
+
before.push(line.trim());
|
|
214
|
+
after.push(next.trim());
|
|
215
|
+
}
|
|
216
|
+
return next;
|
|
217
|
+
});
|
|
218
|
+
if (!ours) {
|
|
219
|
+
result.skipped.push([file, 'no launch-doctor hook in it']);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
if (pinned < ours)
|
|
223
|
+
result.unpinned.push(file);
|
|
224
|
+
if (!before.length) {
|
|
225
|
+
if (pinned)
|
|
226
|
+
result.current.push([file, target]);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return { file, before, after, text: out.join('\n') };
|
|
230
|
+
}
|
|
231
|
+
/** The text of a hook file, or a reason it was skipped. */
|
|
232
|
+
function readHookFile(path, rel, result) {
|
|
233
|
+
const kind = entryKind(path);
|
|
234
|
+
if (kind === 'missing') {
|
|
235
|
+
result.skipped.push([rel, 'not found']);
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const text = kind === 'file' ? readRegularFile(path, CONFIG_FILE_MAX_BYTES) : null;
|
|
239
|
+
if (text === null)
|
|
240
|
+
result.skipped.push([rel, SPECIAL]);
|
|
241
|
+
return text;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* `init --hooks --upgrade`: move the hooks that init --hooks installed onto this version's package spec
|
|
245
|
+
* (launch-doctor@^0.4.0 becomes launch-doctor@^0.5.0, say). Only the launch-doctor command changes: other hooks,
|
|
246
|
+
* other settings and the files' formatting are left alone. Hooks installed without a version are reported, not
|
|
247
|
+
* rewritten. With dryRun, nothing is written.
|
|
248
|
+
*/
|
|
249
|
+
export function upgradeHooks(root, { dryRun = false } = {}) {
|
|
250
|
+
const result = { changed: [], current: [], unpinned: [], skipped: [] };
|
|
251
|
+
const changes = [];
|
|
252
|
+
for (const [rel, tool] of [
|
|
253
|
+
['.claude/settings.json', 'claude'],
|
|
254
|
+
['.cursor/hooks.json', 'cursor'],
|
|
255
|
+
]) {
|
|
256
|
+
const path = join(root, rel);
|
|
257
|
+
const text = readHookFile(path, rel, result);
|
|
258
|
+
if (text === null)
|
|
259
|
+
continue;
|
|
260
|
+
// A JSON line holding our hook command: "command": "npx --yes \"launch-doctor@^0.4.0\" hook claude"
|
|
261
|
+
const ours = ourCommand(tool);
|
|
262
|
+
const change = upgradeText(rel, text, (line) => ours.test(line), result);
|
|
263
|
+
if (!change)
|
|
264
|
+
continue;
|
|
265
|
+
try {
|
|
266
|
+
JSON.parse(change.text);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
result.skipped.push([rel, 'the upgraded file would not be valid JSON, so it was left alone']);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
changes.push([path, change]);
|
|
273
|
+
}
|
|
274
|
+
const gitRoot = findGitRoot(root);
|
|
275
|
+
const hooksPath = gitRoot ? gitHooksDir(root) : null;
|
|
276
|
+
if (!hooksPath) {
|
|
277
|
+
result.skipped.push(['pre-commit hook', gitRoot ? "couldn't find the git hooks folder" : 'not a git repository']);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
const path = resolve(root, hooksPath, 'pre-commit');
|
|
281
|
+
const shown = relative(root, path).replace(/\\/g, '/');
|
|
282
|
+
const rel = shown.startsWith('..') || isAbsolute(shown) ? path : shown;
|
|
283
|
+
const text = readHookFile(path, rel, result);
|
|
284
|
+
if (text !== null) {
|
|
285
|
+
// Only the lines inside the block init --hooks added.
|
|
286
|
+
const lines = text.split('\n');
|
|
287
|
+
const start = lines.findIndex((l) => l.includes(MARK_START));
|
|
288
|
+
const end = lines.findIndex((l, i) => i > start && l.includes(MARK_END));
|
|
289
|
+
const inBlock = (line, i) => start >= 0 && end > start && i > start && i < end && /\bnpx\b.*\blaunch-doctor\b/.test(line);
|
|
290
|
+
const change = upgradeText(rel, text, inBlock, result);
|
|
291
|
+
if (change)
|
|
292
|
+
changes.push([path, change]);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
for (const [path, change] of changes) {
|
|
296
|
+
if (!dryRun)
|
|
297
|
+
writeRegularFile(path, change.text);
|
|
298
|
+
result.changed.push(change);
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
}
|