launch-doctor 0.4.0 → 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/dist/src/cli.js CHANGED
@@ -6,18 +6,23 @@ import { changedFiles } from './changed.js';
6
6
  import { createDemoProject, removeOnSignal } from './demo.js';
7
7
  import { renderFixes } from './fixes.js';
8
8
  import { explainGitHubError, postPrFeedback, prContextFromEnv } from './github.js';
9
+ import { git } from './git.js';
9
10
  import { failingFindings } from './grade.js';
11
+ import { BADGE_FILE, describeEntry, entryFor, GRADES_FILE, headCommit, loadGrades, recordGrade, renderGradeTable, } from './grades.js';
12
+ import { shouldShowBanner } from './banner.js';
10
13
  import { DEFAULT_HISTORY_DEPTH } from './history.js';
11
14
  import { runHook } from './hook.js';
12
- import { setupHooks } from './hooks-setup.js';
15
+ import { pinnedPackage, setupHooks, upgradeHooks } from './hooks-setup.js';
13
16
  import { CATEGORY_IDS, runDoctor } from './index.js';
14
- import { runInit } from './init.js';
17
+ import { badgeUrl, GRADES_BRANCH, githubRepo, runInit } from './init.js';
15
18
  import { runLiveScan } from './live.js';
16
19
  import { runMcpServer } from './mcp.js';
17
20
  import { assertConfigRef } from './project.js';
21
+ import { copyToClipboard, promptFor, unsupportedLanguage } from './prompt.js';
18
22
  import { bold, dim, renderReport } from './report.js';
19
23
  import { writeRegularFile } from './safe-fs.js';
20
24
  import { renderSarif } from './sarif.js';
25
+ import { renderEmptyFolder, renderOtherLanguage, renderShortReport } from './short-report.js';
21
26
  import { renderStepSummary } from './summary.js';
22
27
  import { version } from './version.js';
23
28
  const HELP = `
@@ -27,6 +32,12 @@ const HELP = `
27
32
  npx launch-doctor [folder] [options]
28
33
  npx launch-doctor init [folder] Create .launchdoctorignore and a GitHub Actions workflow
29
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)
37
+ npx launch-doctor init --monitor Add a GitHub Actions workflow that re-checks the project every week
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)
30
41
  npx launch-doctor scan <url> Check your deployed site (exposed files, source maps, open Supabase tables, headers)
31
42
  npx launch-doctor mcp Start an MCP server so Claude Code, Cursor and other AI tools can run checks
32
43
 
@@ -46,6 +57,7 @@ const HELP = `
46
57
  --history-depth <n> How many commits --history reads (default 500)
47
58
  --update-baseline Save today's findings to .launchdoctor-baseline.json as accepted
48
59
  --no-baseline Ignore .launchdoctor-baseline.json and show every finding
60
+ --record Save the grade to .launchdoctor/grades.json and redraw .launchdoctor/badge.svg
49
61
  --config-from <ref> Read .launchdoctorignore and the baseline from this git ref (a branch,
50
62
  tag or commit) instead of the folder, and ignore inline ignore comments on
51
63
  lines changed since then. The GitHub Action uses it so a pull request
@@ -53,6 +65,9 @@ const HELP = `
53
65
  --changed Only report on files changed since the last commit (fast, for hooks)
54
66
  --staged Only report on files staged for the next commit (for a pre-commit hook)
55
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)
56
71
  -h, --help Show this help
57
72
  -v, --version Show the version
58
73
 
@@ -93,7 +108,10 @@ function parseArgs(argv) {
93
108
  baseline: true,
94
109
  history: false,
95
110
  historyDepth: DEFAULT_HISTORY_DEPTH,
111
+ record: false,
96
112
  demo: false,
113
+ banner: true,
114
+ verbose: false,
97
115
  help: false,
98
116
  version: false,
99
117
  };
@@ -117,6 +135,10 @@ function parseArgs(argv) {
117
135
  args.ci = true;
118
136
  else if (a === '--demo')
119
137
  args.demo = true;
138
+ else if (a === '--no-banner')
139
+ args.banner = false;
140
+ else if (a === '--verbose')
141
+ args.verbose = true;
120
142
  else if (a === '--pr-comment')
121
143
  args.prComment = true;
122
144
  else if (a === '--no-file')
@@ -125,6 +147,8 @@ function parseArgs(argv) {
125
147
  args.updateBaseline = true;
126
148
  else if (a === '--no-baseline')
127
149
  args.baseline = false;
150
+ else if (a === '--record')
151
+ args.record = true;
128
152
  else if (a === '--changed')
129
153
  args.changeMode = setChangeMode(args.changeMode, 'changed');
130
154
  else if (a === '--staged')
@@ -215,15 +239,25 @@ function fail(message) {
215
239
  }
216
240
  function init(argv) {
217
241
  const hooks = argv.includes('--hooks');
218
- const rest = argv.filter((a) => a !== '--hooks');
242
+ const monitor = argv.includes('--monitor');
243
+ const upgrade = argv.includes('--upgrade');
244
+ const rest = argv.filter((a) => a !== '--hooks' && a !== '--monitor' && a !== '--upgrade');
219
245
  const extra = rest.filter((a) => a.startsWith('-'));
220
246
  if (extra.length)
221
- fail(`init only takes --hooks (got ${extra.join(' ')})`);
247
+ fail(`init only takes --hooks, --hooks --upgrade or --monitor (got ${extra.join(' ')})`);
248
+ if (hooks && monitor)
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');
222
252
  if (rest.length > 1)
223
253
  fail('init takes at most one folder');
224
254
  const root = resolve(rest[0] ?? '.');
225
255
  if (!existsSync(root) || !statSync(root).isDirectory())
226
256
  fail(`Folder not found: ${root}`);
257
+ if (hooks && upgrade) {
258
+ upgradeHooksCommand(root);
259
+ return;
260
+ }
227
261
  if (hooks) {
228
262
  const result = setupHooks(root);
229
263
  for (const f of result.created)
@@ -237,11 +271,59 @@ function init(argv) {
237
271
  `);
238
272
  return;
239
273
  }
240
- const { created, skipped } = runInit(root);
274
+ const { created, skipped } = runInit(root, { monitor });
241
275
  for (const f of created)
242
276
  process.stdout.write(` created ${f}\n`);
243
277
  for (const f of skipped)
244
278
  process.stdout.write(` skipped ${f} ${dim('(already exists)')}\n`);
279
+ if (monitor && created.length) {
280
+ const repo = githubRepo(git(root, ['remote', 'get-url', 'origin'])) ?? undefined;
281
+ process.stdout.write(`\n It runs every Monday and keeps grades.json and badge.svg on the ${GRADES_BRANCH} branch\n` +
282
+ ` (never on your default branch). Show the grade in your README:\n` +
283
+ ` ![Launch Doctor grade](${badgeUrl(repo)})\n` +
284
+ ` ${dim('To check your deployed site too, add a repository variable named LAUNCH_DOCTOR_URL.')}\n`);
285
+ }
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
+ }
310
+ /** `launch-doctor grades [folder] [--json]`: the grades saved with --record, newest first. */
311
+ function grades(argv) {
312
+ const json = argv.includes('--json');
313
+ const rest = argv.filter((a) => a !== '--json');
314
+ const extra = rest.filter((a) => a.startsWith('-'));
315
+ if (extra.length)
316
+ fail(`grades only takes --json (got ${extra.join(' ')})`);
317
+ if (rest.length > 1)
318
+ fail('grades takes at most one folder');
319
+ const root = resolve(rest[0] ?? '.');
320
+ if (!existsSync(root) || !statSync(root).isDirectory())
321
+ fail(`Folder not found: ${root}`);
322
+ const entries = loadGrades(root);
323
+ if (json)
324
+ process.stdout.write(`${JSON.stringify(entries, null, 2)}\n`);
325
+ else
326
+ process.stdout.write(renderGradeTable(entries));
245
327
  }
246
328
  /** The JSON an AI tool sends to a hook on stdin. A terminal has nothing to send. */
247
329
  async function readStdin() {
@@ -302,6 +384,7 @@ const SCAN_HELP = `
302
384
  --ci Exit with code 1 on findings at or above --fail-on
303
385
  --fail-on <level> With --ci, the lowest severity that fails: critical (default) or warning
304
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)
305
388
  -h, --help Show this help
306
389
 
307
390
  Only scan sites you own or are allowed to test. The scan makes a few dozen ordinary GET requests
@@ -315,6 +398,7 @@ async function scan(argv) {
315
398
  let ci = false;
316
399
  let failOn = 'critical';
317
400
  let skipDatabase = false;
401
+ let banner = true;
318
402
  for (let i = 0; i < argv.length; i++) {
319
403
  const a = argv[i];
320
404
  const value = () => {
@@ -335,6 +419,8 @@ async function scan(argv) {
335
419
  writeFile = false;
336
420
  else if (a === '--no-db')
337
421
  skipDatabase = true;
422
+ else if (a === '--no-banner')
423
+ banner = false;
338
424
  else if (a === '--out')
339
425
  out = value();
340
426
  else if (a.startsWith('--out='))
@@ -389,8 +475,15 @@ async function scan(argv) {
389
475
  if (json)
390
476
  process.stdout.write(`${JSON.stringify(report, null, 2)}
391
477
  `);
392
- else
393
- process.stdout.write(renderReport(report, { fixFile }));
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
+ }
394
487
  if (ci && failingFindings(report, failOn).length > 0)
395
488
  process.exitCode = 1;
396
489
  }
@@ -434,6 +527,123 @@ async function commentOnPr(report, root) {
434
527
  process.stderr.write(`\n ${dim(explainGitHubError(err))}\n`);
435
528
  }
436
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
+ }
437
647
  async function main() {
438
648
  if (process.argv[2] === 'init')
439
649
  return init(process.argv.slice(3));
@@ -443,6 +653,10 @@ async function main() {
443
653
  return mcp(process.argv.slice(3));
444
654
  if (process.argv[2] === 'hook')
445
655
  return hook(process.argv.slice(3));
656
+ if (process.argv[2] === 'grades')
657
+ return grades(process.argv.slice(3));
658
+ if (process.argv[2] === 'prompt')
659
+ return prompt(process.argv.slice(3));
446
660
  const args = parseArgs(process.argv.slice(2));
447
661
  if (args.help) {
448
662
  process.stdout.write(HELP);
@@ -470,6 +684,13 @@ async function main() {
470
684
  const root = resolve(args.path ?? '.');
471
685
  if (!existsSync(root) || !statSync(root).isDirectory())
472
686
  fail(`Folder not found: ${root}`);
687
+ if (args.record) {
688
+ // A recorded grade is compared with the next one, so it has to be for the whole project.
689
+ if (args.demo)
690
+ fail('--record needs a real project folder, not --demo');
691
+ if (args.only || args.skip)
692
+ fail('--record saves the grade for the whole project, so leave out --only and --skip');
693
+ }
473
694
  if (args.configFrom) {
474
695
  if (args.updateBaseline)
475
696
  fail('--config-from reads the baseline from git, so it cannot be used with --update-baseline');
@@ -489,6 +710,7 @@ async function main() {
489
710
  [args.updateBaseline, '--update-baseline'],
490
711
  [args.prComment, '--pr-comment'],
491
712
  [args.history, '--history'],
713
+ [args.record, '--record'],
492
714
  ]) {
493
715
  if (on)
494
716
  fail(`${flag} reports on some files only, so it can't be used with ${name}`);
@@ -501,10 +723,13 @@ async function main() {
501
723
  if (!args.out)
502
724
  args.writeFile = false;
503
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;
504
729
  let report;
505
730
  try {
506
731
  report = await runDoctor(root, {
507
- onlyFiles,
732
+ onProgress: progress?.update,
508
733
  offline: args.offline,
509
734
  domain: args.domain,
510
735
  only: args.only,
@@ -513,9 +738,11 @@ async function main() {
513
738
  baseline: args.baseline && !args.updateBaseline,
514
739
  configFrom: args.configFrom,
515
740
  history: args.history ? { depth: args.historyDepth } : undefined,
741
+ onlyFiles,
516
742
  });
517
743
  }
518
744
  finally {
745
+ progress?.clear();
519
746
  // The demo project lives in a temp folder; always clean it up, even if the scan throws.
520
747
  if (args.demo) {
521
748
  rmSync(root, { recursive: true, force: true });
@@ -523,7 +750,18 @@ async function main() {
523
750
  }
524
751
  }
525
752
  if (report.filesScanned === 0) {
526
- fail(`No project files found in ${root}. Run this inside your app's folder.`);
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;
527
765
  }
528
766
  if (args.updateBaseline) {
529
767
  if (args.demo)
@@ -580,10 +818,36 @@ async function main() {
580
818
  writeStepOutputs(report);
581
819
  if (args.prComment)
582
820
  await commentOnPr(report, root);
821
+ // The last recorded grade, read before this run adds one. Not for a partial report or the demo.
822
+ const last = args.demo || onlyFiles || args.only || args.skip ? undefined : loadGrades(root).at(-1);
823
+ let recorded;
824
+ if (args.record) {
825
+ try {
826
+ recordGrade(root, entryFor(report, headCommit(root)));
827
+ recorded = `Recorded grade ${report.grade} in ${GRADES_FILE} and ${BADGE_FILE}.`;
828
+ }
829
+ catch (err) {
830
+ process.stderr.write(`\n ${dim(`Couldn't record the grade: ${err.message}`)}\n`);
831
+ process.exitCode = 2;
832
+ }
833
+ }
583
834
  if (args.json)
584
835
  process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
585
- else
586
- process.stdout.write(renderReport(report, { fixFile }));
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
+ }
849
+ if (recorded)
850
+ (args.json ? process.stderr : process.stdout).write(` ${dim(recorded)}\n\n`);
587
851
  if (args.ci && failingFindings(report, args.failOn).length > 0)
588
852
  process.exitCode = 1;
589
853
  }
@@ -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 all = report.categories.flatMap((c) => c.findings);
25
- const critical = all.filter((f) => f.severity === 'critical');
26
- const warnings = all.filter((f) => f.severity === 'warning');
27
- const ordered = [...critical, ...warnings];
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" +
@@ -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
@@ -0,0 +1,42 @@
1
+ import type { Grade, Report } from './types.js';
2
+ /**
3
+ * Grade history and the README badge (`--record`).
4
+ *
5
+ * Each recorded scan adds one line to .launchdoctor/grades.json (the date, grade, score, counts, the Launch Doctor
6
+ * version and the commit), and redraws .launchdoctor/badge.svg. Both are meant to be committed, so the history and
7
+ * the badge travel with the repository and nothing is sent anywhere. (history.ts is the git history secret scan.)
8
+ */
9
+ export declare const STATE_DIR = ".launchdoctor";
10
+ export declare const GRADES_FILE = ".launchdoctor/grades.json";
11
+ export declare const BADGE_FILE = ".launchdoctor/badge.svg";
12
+ /** Older entries are dropped, so the file stays small however often it is recorded. */
13
+ export declare const MAX_GRADE_ENTRIES = 200;
14
+ export interface GradeEntry {
15
+ /** When the scan ran (ISO 8601). */
16
+ date: string;
17
+ grade: Grade;
18
+ score: number;
19
+ critical: number;
20
+ warning: number;
21
+ manual: number;
22
+ /** The Launch Doctor version that produced it: grades from different versions aren't always comparable. */
23
+ version: string;
24
+ /** The commit that was scanned (short hash), when the folder is a git repository. */
25
+ commit?: string;
26
+ }
27
+ /** Recorded grades, oldest first. Empty when there is no file or it can't be read. */
28
+ export declare function loadGrades(root: string): GradeEntry[];
29
+ export declare function entryFor(report: Report, commit?: string): GradeEntry;
30
+ /** The short hash of HEAD, or undefined outside a git repository (or when git can't run safely there). */
31
+ export declare function headCommit(root: string): string | undefined;
32
+ /** Add `entry` to the history and redraw the badge. Returns the history, oldest first, with the new entry last. */
33
+ export declare function recordGrade(root: string, entry: GradeEntry): GradeEntry[];
34
+ /**
35
+ * A small SVG in the usual "label | value" badge shape, drawn locally: no badge service is asked, so the README
36
+ * shows the grade that was last recorded and committed. Every color has at least 4.5:1 contrast with white text.
37
+ */
38
+ export declare function renderBadge(grade: Grade): string;
39
+ /** "B (82) on 30 Nov 2026" for the line under the overall grade. */
40
+ export declare function describeEntry(e: GradeEntry): string;
41
+ /** The table `launch-doctor grades` prints, newest first. */
42
+ export declare function renderGradeTable(entries: GradeEntry[], limit?: number): string;