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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { orderedFindings } from './fixes.js';
|
|
4
|
+
/** Fix prompt n (1-based, in LAUNCH_FIXES.md order), or null when there is no such prompt. */
|
|
5
|
+
export function promptFor(report, n) {
|
|
6
|
+
return orderedFindings(report)[n - 1] ?? null;
|
|
7
|
+
}
|
|
8
|
+
const utf8 = (text) => Buffer.from(text, 'utf8');
|
|
9
|
+
// clip.exe reads UTF-8 in the console code page (so "…" breaks), but recognises UTF-16. With a byte order mark
|
|
10
|
+
// it would keep the mark as a character, so none is sent.
|
|
11
|
+
const utf16 = (text) => Buffer.from(text, 'utf16le');
|
|
12
|
+
/** The clipboard tools to try on this system, in order. None on a Linux machine without a display. */
|
|
13
|
+
export function clipboardTools(platform, env) {
|
|
14
|
+
if (platform === 'win32')
|
|
15
|
+
return [{ name: 'clip', args: [], encode: utf16 }];
|
|
16
|
+
if (platform === 'darwin') {
|
|
17
|
+
return [{ name: 'pbcopy', args: [], encode: utf8, env: { ...env, LANG: env.LANG || 'en_US.UTF-8' } }];
|
|
18
|
+
}
|
|
19
|
+
const tools = [];
|
|
20
|
+
if (env.WAYLAND_DISPLAY)
|
|
21
|
+
tools.push({ name: 'wl-copy', args: [], encode: utf8 });
|
|
22
|
+
if (env.DISPLAY)
|
|
23
|
+
tools.push({ name: 'xclip', args: ['-selection', 'clipboard'], encode: utf8 });
|
|
24
|
+
return tools;
|
|
25
|
+
}
|
|
26
|
+
/** Put text on the clipboard with the system's own tool. Returns the tool's name, or null if none worked. */
|
|
27
|
+
export function copyToClipboard(text, platform = process.platform, env = process.env) {
|
|
28
|
+
for (const tool of clipboardTools(platform, env)) {
|
|
29
|
+
const res = spawnSync(tool.name, tool.args, {
|
|
30
|
+
input: tool.encode(text),
|
|
31
|
+
stdio: ['pipe', 'ignore', 'ignore'],
|
|
32
|
+
env: tool.env ?? env,
|
|
33
|
+
timeout: 5000,
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
});
|
|
36
|
+
if (!res.error && res.status === 0)
|
|
37
|
+
return tool.name;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/** Files that mark a project in a language whose code Launch Doctor's checks don't read. */
|
|
42
|
+
const OTHER_LANGUAGES = [
|
|
43
|
+
[/^Cargo\.toml$/, 'Rust'],
|
|
44
|
+
[/^(?:pom\.xml|build\.gradle(?:\.kts)?|settings\.gradle(?:\.kts)?)$/, 'Java or Kotlin'],
|
|
45
|
+
[/\.(?:csproj|fsproj|sln)$/, '.NET'],
|
|
46
|
+
[/^pubspec\.yaml$/, 'Flutter (Dart)'],
|
|
47
|
+
[/^Package\.swift$/, 'Swift'],
|
|
48
|
+
[/^mix\.exs$/, 'Elixir'],
|
|
49
|
+
[/^(?:CMakeLists\.txt|meson\.build)$/, 'C or C++'],
|
|
50
|
+
];
|
|
51
|
+
/** Files that mark a project Launch Doctor does read. */
|
|
52
|
+
const SUPPORTED = [
|
|
53
|
+
'package.json',
|
|
54
|
+
'requirements.txt',
|
|
55
|
+
'pyproject.toml',
|
|
56
|
+
'Pipfile',
|
|
57
|
+
'setup.py',
|
|
58
|
+
'manage.py',
|
|
59
|
+
'Gemfile',
|
|
60
|
+
'composer.json',
|
|
61
|
+
'go.mod',
|
|
62
|
+
'index.html',
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* { language: 'Rust', marker: 'Cargo.toml' } when the folder is a project in a language Launch Doctor doesn't
|
|
66
|
+
* analyse, with nothing it does (no package.json, no detected stack, no findings to fix). Null otherwise.
|
|
67
|
+
*/
|
|
68
|
+
export function unsupportedLanguage(root, report) {
|
|
69
|
+
if (report.stack.length)
|
|
70
|
+
return null;
|
|
71
|
+
if (report.categories.some((c) => c.findings.length))
|
|
72
|
+
return null;
|
|
73
|
+
if (SUPPORTED.some((f) => existsSync(`${root}/${f}`)))
|
|
74
|
+
return null;
|
|
75
|
+
let names;
|
|
76
|
+
try {
|
|
77
|
+
names = readdirSync(root);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
for (const [re, language] of OTHER_LANGUAGES) {
|
|
83
|
+
const marker = names.find((n) => re.test(n));
|
|
84
|
+
if (marker)
|
|
85
|
+
return { language, marker };
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Report } from './types.js';
|
|
2
|
+
/** Where `--report` writes, relative to the project. */
|
|
3
|
+
export declare const REPORT_FILE = ".launchdoctor/report.md";
|
|
4
|
+
export interface ReportMdOptions {
|
|
5
|
+
/** What to type after `npx launch-doctor prompt <n>` to reach this project: "" or " ./my-app". */
|
|
6
|
+
target?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `.launchdoctor/report.md`: every finding explained, built from the same core and explanations as `explain` and the
|
|
10
|
+
* MCP server. Each finding points to its fix prompt (`launch-doctor prompt N`) instead of copying it, and no secret
|
|
11
|
+
* value is written: only the file, the line and the masked hint the finding already holds. All text from the scanned
|
|
12
|
+
* project goes through md() / mdCode(), like LAUNCH_FIXES.md.
|
|
13
|
+
*/
|
|
14
|
+
export declare function renderReportMd(report: Report, opts?: ReportMdOptions): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { shortWhere } from './checks/common.js';
|
|
2
|
+
import { coverageNotes, findingDetails } from './core.js';
|
|
3
|
+
import { orderedFindings } from './fixes.js';
|
|
4
|
+
import { STATE_DIR } from './grades.js';
|
|
5
|
+
import { md, mdCode } from './sanitize.js';
|
|
6
|
+
import { ISSUES_URL, plural } from './util.js';
|
|
7
|
+
/** Where `--report` writes, relative to the project. */
|
|
8
|
+
export const REPORT_FILE = `${STATE_DIR}/report.md`;
|
|
9
|
+
/** A link from Launch Doctor's own tables (rotate and usage pages); anything else is escaped text. */
|
|
10
|
+
const link = (x) => (/^https:\/\/[^\s<>]+$/.test(x) ? `<${x}>` : md(x));
|
|
11
|
+
/**
|
|
12
|
+
* `.launchdoctor/report.md`: every finding explained, built from the same core and explanations as `explain` and the
|
|
13
|
+
* MCP server. Each finding points to its fix prompt (`launch-doctor prompt N`) instead of copying it, and no secret
|
|
14
|
+
* value is written: only the file, the line and the masked hint the finding already holds. All text from the scanned
|
|
15
|
+
* project goes through md() / mdCode(), like LAUNCH_FIXES.md.
|
|
16
|
+
*/
|
|
17
|
+
export function renderReportMd(report, opts = {}) {
|
|
18
|
+
const target = opts.target ?? '';
|
|
19
|
+
const ordered = orderedFindings(report);
|
|
20
|
+
const g = report.grades;
|
|
21
|
+
const out = [
|
|
22
|
+
`# Launch Doctor report for ${md(report.projectName)}`,
|
|
23
|
+
'',
|
|
24
|
+
`Launch Doctor ${report.version}, ${report.generatedAt.slice(0, 10)}. ${md(report.verdict)}.`,
|
|
25
|
+
'',
|
|
26
|
+
g
|
|
27
|
+
? `**Security:** ${g.security.grade ?? '-'} · **Launch readiness:** ${g.launch.grade ?? '-'} · overall ${report.grade} (${report.score}/100)`
|
|
28
|
+
: `**Grade:** ${report.grade} (${report.score}/100)`,
|
|
29
|
+
'',
|
|
30
|
+
`${plural(report.counts.critical, 'critical problem')} · ${plural(report.counts.warning, 'warning')} · ${report.counts.manual} to check by hand${report.counts.baseline ? ` · ${report.counts.baseline} in the baseline` : ''}`,
|
|
31
|
+
'',
|
|
32
|
+
'## What was checked',
|
|
33
|
+
'',
|
|
34
|
+
...coverageNotes(report).map((n) => `- ${md(n)}`),
|
|
35
|
+
'',
|
|
36
|
+
];
|
|
37
|
+
for (const [heading, severity] of [
|
|
38
|
+
['Critical', 'critical'],
|
|
39
|
+
['Warnings', 'warning'],
|
|
40
|
+
]) {
|
|
41
|
+
const list = ordered.filter((f) => f.severity === severity);
|
|
42
|
+
if (!list.length)
|
|
43
|
+
continue;
|
|
44
|
+
out.push(`## ${heading} (${list.length})`, '');
|
|
45
|
+
for (const f of list) {
|
|
46
|
+
const d = findingDetails(report, f);
|
|
47
|
+
const e = d.explanation;
|
|
48
|
+
const where = d.file ? mdCode(shortWhere({ file: d.file, line: d.line })) : 'the whole project';
|
|
49
|
+
out.push(`### ${d.number}. ${md(d.title)}`, '', `**Where:** ${where} · **Rule:** \`${d.rule}\` · **Id:** \`${d.ref}\`${d.baseline ? ' · in the baseline' : ''}`, '', `**This finding:** ${md(d.why, { oneLine: false })}`, '');
|
|
50
|
+
if (e) {
|
|
51
|
+
out.push(`**Why it matters:** ${md(e.whyItMatters)}`, '', `**How to confirm:** ${md(e.howToConfirm)}`, '', `**How to fix:** ${md(e.howToFix)}`, '', `**False alarm?** ${md(e.falsePositiveHint)}`, '');
|
|
52
|
+
}
|
|
53
|
+
if (d.rotate)
|
|
54
|
+
out.push(`**Rotate the key first:** ${link(d.rotate)}`, '');
|
|
55
|
+
if (d.usage)
|
|
56
|
+
out.push(`**Check whether someone used it:** ${link(d.usage)}`, '');
|
|
57
|
+
out.push(`**Fix prompt:** \`npx launch-doctor prompt ${d.number}${target} --copy\` (also number ${d.number} in LAUNCH_FIXES.md)`, '');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!ordered.length)
|
|
61
|
+
out.push('## No problems found', '', 'None of the problems Launch Doctor looks for were found.', '');
|
|
62
|
+
const manual = report.categories.flatMap((c) => c.manual);
|
|
63
|
+
if (manual.length) {
|
|
64
|
+
out.push(`## Check by hand (${manual.length})`, '', "Things Launch Doctor can't see from your code:", '');
|
|
65
|
+
for (const m of manual)
|
|
66
|
+
out.push(`- [ ] **${md(m.title)}** - ${md(m.how)}`);
|
|
67
|
+
out.push('');
|
|
68
|
+
}
|
|
69
|
+
out.push('---', '', `_Written by \`launch-doctor --report\`. It is rewritten on every run with \`--report\`; ${STATE_DIR}/ can go in .gitignore. A wrong finding or a missed problem? Please [report it](${ISSUES_URL})._`, '');
|
|
70
|
+
return out.join('\n');
|
|
71
|
+
}
|
package/dist/src/report.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import type { Report } from './types.js';
|
|
1
|
+
import type { Grade, Report } from './types.js';
|
|
2
2
|
export declare const bold: (s: string) => string;
|
|
3
3
|
export declare const dim: (s: string) => string;
|
|
4
|
+
export declare const red: (s: string) => string;
|
|
5
|
+
export declare const green: (s: string) => string;
|
|
6
|
+
export declare const yellow: (s: string) => string;
|
|
4
7
|
/** Shown when the scan hit MAX_TOTAL_BYTES (terminal report and MCP). */
|
|
5
8
|
export declare const BYTE_LIMIT_NOTE = "Very large project: only the first 128 MB of source files were read, so some files were not checked.";
|
|
6
9
|
/** "Left out Twin/: a separate git repository inside this folder. Scan it on its own." */
|
|
7
10
|
export declare function nestedReposNote(repos: string[]): string;
|
|
11
|
+
export declare function gradeColor(grade: Grade): (s: string) => string;
|
|
12
|
+
export declare function wrap(text: string, width: number, indent: string): string[];
|
|
13
|
+
/** The banner rows, indented, in no colour. */
|
|
14
|
+
export declare function bannerLines(): string[];
|
|
15
|
+
/** Notes under the header: partial report, size limits, a long ignore file, nested repositories. */
|
|
16
|
+
export declare function noticeLines(report: Report): string[];
|
|
8
17
|
export declare function renderReport(report: Report, opts?: {
|
|
9
18
|
fixFile?: string;
|
|
10
19
|
/** The last recorded grade ("B (82) on 30 Nov 2026"), shown under the overall grade. */
|
|
11
20
|
lastRecorded?: string;
|
|
21
|
+
/** Print the ASCII banner above the title. The caller decides (TTY, full scan, width); see shouldShowBanner. */
|
|
22
|
+
banner?: boolean;
|
|
12
23
|
}): string;
|
package/dist/src/report.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { BANNER, BANNER_INDENT } from './banner.js';
|
|
1
2
|
import { shortWhere } from './checks/common.js';
|
|
2
3
|
import { ISSUES_URL, plural } from './util.js';
|
|
3
4
|
const useColor = !process.env.NO_COLOR && (process.env.FORCE_COLOR ? process.env.FORCE_COLOR !== '0' : !!process.stdout.isTTY);
|
|
4
5
|
const paint = (code) => (s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
5
6
|
export const bold = paint('1');
|
|
6
7
|
export const dim = paint('2');
|
|
7
|
-
const red = paint('31');
|
|
8
|
-
const green = paint('32');
|
|
9
|
-
const yellow = paint('33');
|
|
10
|
-
const cyan = paint('36');
|
|
8
|
+
export const red = paint('31');
|
|
9
|
+
export const green = paint('32');
|
|
10
|
+
export const yellow = paint('33');
|
|
11
11
|
/** Shown when the scan hit MAX_TOTAL_BYTES (terminal report and MCP). */
|
|
12
12
|
export const BYTE_LIMIT_NOTE = 'Very large project: only the first 128 MB of source files were read, so some files were not checked.';
|
|
13
13
|
/** "Left out Twin/: a separate git repository inside this folder. Scan it on its own." */
|
|
@@ -18,7 +18,7 @@ export function nestedReposNote(repos) {
|
|
|
18
18
|
? `Left out ${names[0]}: a separate git repository inside this folder. Scan it on its own.`
|
|
19
19
|
: `Left out ${repos.length} separate git repositories inside this folder (${names.join(', ')}${more}). Scan them on their own.`;
|
|
20
20
|
}
|
|
21
|
-
function gradeColor(grade) {
|
|
21
|
+
export function gradeColor(grade) {
|
|
22
22
|
if (grade === 'A' || grade === 'B')
|
|
23
23
|
return green;
|
|
24
24
|
if (grade === 'C')
|
|
@@ -30,7 +30,7 @@ function badge(grade) {
|
|
|
30
30
|
return dim('-');
|
|
31
31
|
return bold(gradeColor(grade)(grade));
|
|
32
32
|
}
|
|
33
|
-
function wrap(text, width, indent) {
|
|
33
|
+
export function wrap(text, width, indent) {
|
|
34
34
|
const lines = [];
|
|
35
35
|
let current = '';
|
|
36
36
|
for (const word of text.split(/\s+/)) {
|
|
@@ -71,18 +71,18 @@ function findingBlock(f, width) {
|
|
|
71
71
|
const label = f.severity === 'critical' ? bold(red('[CRITICAL]')) : bold(yellow('[WARN]'));
|
|
72
72
|
const lines = [` ${label} ${bold(f.title)}`];
|
|
73
73
|
if (f.location)
|
|
74
|
-
lines.push(`${DETAIL_INDENT}${
|
|
74
|
+
lines.push(`${DETAIL_INDENT}${shortWhere(f.location)}`);
|
|
75
75
|
lines.push(...wrap(f.why, width - DETAIL_INDENT.length, DETAIL_INDENT));
|
|
76
76
|
lines.push('');
|
|
77
77
|
return lines;
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
lines
|
|
79
|
+
/** The banner rows, indented, in no colour. */
|
|
80
|
+
export function bannerLines() {
|
|
81
|
+
return BANNER.map((row) => (row ? `${BANNER_INDENT}${row}` : ''));
|
|
82
|
+
}
|
|
83
|
+
/** Notes under the header: partial report, size limits, a long ignore file, nested repositories. */
|
|
84
|
+
export function noticeLines(report) {
|
|
85
|
+
const lines = [];
|
|
86
86
|
if (report.partial) {
|
|
87
87
|
const n = report.partial.files.length;
|
|
88
88
|
lines.push(` ${yellow(`Only ${plural(n, 'changed file')} ${n === 1 ? 'was' : 'were'} reported on, not the whole project. Run without --changed or --staged for the full grade.`)}`);
|
|
@@ -96,6 +96,18 @@ export function renderReport(report, opts = {}) {
|
|
|
96
96
|
}
|
|
97
97
|
if (report.nestedRepos?.length)
|
|
98
98
|
lines.push(` ${dim(nestedReposNote(report.nestedRepos))}`);
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
export function renderReport(report, opts = {}) {
|
|
102
|
+
const width = Math.max(60, Math.min(100, process.stdout.columns || 80));
|
|
103
|
+
const lines = [''];
|
|
104
|
+
if (opts.banner)
|
|
105
|
+
lines.push(...bannerLines());
|
|
106
|
+
lines.push(` ${bold('Launch Doctor')} ${dim(`v${report.version}`)}`);
|
|
107
|
+
const stack = report.stack.length ? ` · ${report.stack.join(', ')}` : '';
|
|
108
|
+
const unit = report.mode === 'live' ? 'request' : 'file';
|
|
109
|
+
lines.push(` ${dim(`Checked ${report.projectName} · ${plural(report.filesScanned, unit)}${stack}`)}`);
|
|
110
|
+
lines.push(...noticeLines(report));
|
|
99
111
|
lines.push('');
|
|
100
112
|
lines.push(` ${bold('Overall grade')} ${badge(report.grade)} ${report.verdict}`);
|
|
101
113
|
if (opts.lastRecorded)
|
|
@@ -151,7 +163,7 @@ export function renderReport(report, opts = {}) {
|
|
|
151
163
|
lines.push('');
|
|
152
164
|
}
|
|
153
165
|
if (opts.fixFile) {
|
|
154
|
-
lines.push(` ${bold('Fix prompts saved to')} ${
|
|
166
|
+
lines.push(` ${bold('Fix prompts saved to')} ${opts.fixFile}`);
|
|
155
167
|
lines.push(` ${dim('Paste them one at a time into Claude Code, Cursor, Lovable or Bolt, then run launch-doctor again.')}`);
|
|
156
168
|
lines.push('');
|
|
157
169
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Finding, Report } from './types.js';
|
|
2
|
+
/** How many findings "FIX THESE FIRST" shows. */
|
|
3
|
+
export declare const TOP_FINDINGS = 3;
|
|
4
|
+
export interface ShortReportOptions {
|
|
5
|
+
/** Where LAUNCH_FIXES.md was written, if it was. */
|
|
6
|
+
fixFile?: string;
|
|
7
|
+
/** Where --report wrote .launchdoctor/report.md, if it did. */
|
|
8
|
+
reportFile?: string;
|
|
9
|
+
/** The last recorded overall grade ("B (82) on 30 Nov 2026"). */
|
|
10
|
+
lastRecorded?: string;
|
|
11
|
+
banner?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* What to type after `npx launch-doctor` to scan the same project again: "", " ./my-app" or " --demo".
|
|
14
|
+
* Used in the "Next" commands.
|
|
15
|
+
*/
|
|
16
|
+
target?: string;
|
|
17
|
+
/** The built-in demo: LAUNCH_FIXES.md is never written for it. */
|
|
18
|
+
demo?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Every number the short report shows, worked out in one place so they always add up.
|
|
22
|
+
* Baseline findings (already accepted) are left out, as in the full report.
|
|
23
|
+
*/
|
|
24
|
+
export interface ShortCounts {
|
|
25
|
+
/** New critical findings: the verdict's number, and the sum of the critical counts on the two grade rows. */
|
|
26
|
+
critical: number;
|
|
27
|
+
security: {
|
|
28
|
+
critical: number;
|
|
29
|
+
warning: number;
|
|
30
|
+
};
|
|
31
|
+
launch: {
|
|
32
|
+
critical: number;
|
|
33
|
+
warning: number;
|
|
34
|
+
};
|
|
35
|
+
/** The findings under FIX THESE FIRST, with their fix-prompt numbers. */
|
|
36
|
+
top: {
|
|
37
|
+
finding: Finding;
|
|
38
|
+
n: number;
|
|
39
|
+
}[];
|
|
40
|
+
/** What the "Also:" line counts: everything not shown under FIX THESE FIRST. */
|
|
41
|
+
also: {
|
|
42
|
+
critical: number;
|
|
43
|
+
warning: number;
|
|
44
|
+
polish: number;
|
|
45
|
+
manual: number;
|
|
46
|
+
};
|
|
47
|
+
baseline: number;
|
|
48
|
+
}
|
|
49
|
+
export declare function shortCounts(report: Report): ShortCounts;
|
|
50
|
+
/**
|
|
51
|
+
* The default terminal report: the verdict, two grades, the three things to fix first and what to do next.
|
|
52
|
+
* `--verbose` (and --ci, --changed, --staged, --pr-comment and live scans) print the full report instead.
|
|
53
|
+
*/
|
|
54
|
+
export declare function renderShortReport(report: Report, opts?: ShortReportOptions): string;
|
|
55
|
+
/** First run in a folder with nothing to read: an explanation instead of a grade. */
|
|
56
|
+
export declare function renderEmptyFolder(report: Report, root: string): string;
|
|
57
|
+
/** A project in a language whose code the checks don't read: an explanation instead of a meaningless grade. */
|
|
58
|
+
export declare function renderOtherLanguage(report: Report, found: {
|
|
59
|
+
language: string;
|
|
60
|
+
marker: string;
|
|
61
|
+
}): string;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { shortWhere } from './checks/common.js';
|
|
2
|
+
import { orderedFindings } from './fixes.js';
|
|
3
|
+
import { GRADE_GROUPS } from './grade.js';
|
|
4
|
+
import { bannerLines, bold, dim, gradeColor, green, noticeLines, red, wrap, yellow } from './report.js';
|
|
5
|
+
import { ISSUES_LIST_URL, plural } from './util.js';
|
|
6
|
+
/** How many findings "FIX THESE FIRST" shows. */
|
|
7
|
+
export const TOP_FINDINGS = 3;
|
|
8
|
+
/** Short names for the "Checked ..." line of a clean report. */
|
|
9
|
+
const SHORT_NAMES = {
|
|
10
|
+
secrets: 'secrets',
|
|
11
|
+
database: 'database',
|
|
12
|
+
access: 'access control',
|
|
13
|
+
payments: 'payments',
|
|
14
|
+
costs: 'AI costs',
|
|
15
|
+
email: 'email',
|
|
16
|
+
monitoring: 'monitoring',
|
|
17
|
+
legal: 'legal pages',
|
|
18
|
+
'first-impressions': 'first impressions',
|
|
19
|
+
};
|
|
20
|
+
export function shortCounts(report) {
|
|
21
|
+
const ordered = orderedFindings(report);
|
|
22
|
+
const fresh = ordered.filter((f) => !f.baseline);
|
|
23
|
+
const inGroup = (ids) => {
|
|
24
|
+
const cats = report.categories.filter((c) => ids.includes(c.id));
|
|
25
|
+
return new Set(cats.flatMap((c) => c.findings));
|
|
26
|
+
};
|
|
27
|
+
const security = inGroup(GRADE_GROUPS.security);
|
|
28
|
+
const launch = inGroup(GRADE_GROUPS.launch);
|
|
29
|
+
const count = (set, severity, list = fresh) => list.filter((f) => set.has(f) && f.severity === severity).length;
|
|
30
|
+
const top = fresh.slice(0, TOP_FINDINGS).map((finding) => ({ finding, n: ordered.indexOf(finding) + 1 }));
|
|
31
|
+
const rest = fresh.slice(TOP_FINDINGS);
|
|
32
|
+
return {
|
|
33
|
+
critical: fresh.filter((f) => f.severity === 'critical').length,
|
|
34
|
+
security: { critical: count(security, 'critical'), warning: count(security, 'warning') },
|
|
35
|
+
launch: { critical: count(launch, 'critical'), warning: count(launch, 'warning') },
|
|
36
|
+
top,
|
|
37
|
+
also: {
|
|
38
|
+
critical: rest.filter((f) => f.severity === 'critical').length,
|
|
39
|
+
warning: count(security, 'warning', rest),
|
|
40
|
+
polish: count(launch, 'warning', rest),
|
|
41
|
+
manual: report.categories.reduce((sum, c) => sum + c.manual.length, 0),
|
|
42
|
+
},
|
|
43
|
+
baseline: ordered.length - fresh.length,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function gradeRow(label, g, parts) {
|
|
47
|
+
const letter = g?.grade ? bold(gradeColor(g.grade)(g.grade)) : dim('-');
|
|
48
|
+
const summary = !g?.grade ? dim('not checked') : parts.length ? parts.join(dim(' · ')) : green('all good');
|
|
49
|
+
return ` ${label.padEnd(18)}${letter} ${summary}`;
|
|
50
|
+
}
|
|
51
|
+
/** "a, b and c" */
|
|
52
|
+
function list(items) {
|
|
53
|
+
return items.length < 2 ? (items[0] ?? '') : `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
|
|
54
|
+
}
|
|
55
|
+
/** The first sentence of a longer explanation, for findings that have no short reason of their own. */
|
|
56
|
+
function firstSentence(text) {
|
|
57
|
+
const m = /^(.+?[.!?])(?:\s|$)/.exec(text.trim());
|
|
58
|
+
return (m ? m[1] : text.trim()).replace(/\.$/, '');
|
|
59
|
+
}
|
|
60
|
+
/** "Launch Doctor v0.4.1 · my-app · 13 files · Vite, React, Supabase +2", with the stack shortened to fit. */
|
|
61
|
+
function headerLine(report, width) {
|
|
62
|
+
const base = `Launch Doctor v${report.version} · ${report.projectName} · ${plural(report.filesScanned, 'file')}`;
|
|
63
|
+
let stack = report.stack;
|
|
64
|
+
const text = (items, more) => items.length ? ` · ${items.join(', ')}${more ? ` +${more}` : ''}` : more ? ` · +${more}` : '';
|
|
65
|
+
while (stack.length && 2 + base.length + text(stack, report.stack.length - stack.length).length > width) {
|
|
66
|
+
stack = stack.slice(0, -1);
|
|
67
|
+
}
|
|
68
|
+
const rest = text(stack, report.stack.length - stack.length);
|
|
69
|
+
return ` ${bold(`Launch Doctor v${report.version}`)}${dim(base.slice(`Launch Doctor v${report.version}`.length) + rest)}`;
|
|
70
|
+
}
|
|
71
|
+
function findingLines(f, n, width) {
|
|
72
|
+
const indent = ' '.repeat(5);
|
|
73
|
+
const title = f.display?.title ?? f.title;
|
|
74
|
+
const [first, ...more] = wrap(title, width - indent.length, '');
|
|
75
|
+
const lines = [` ${bold(`${n}.`.padEnd(3))}${bold(first ?? '')}`, ...more.map((l) => `${indent}${bold(l)}`)];
|
|
76
|
+
const reason = f.display?.reason ?? firstSentence(f.why);
|
|
77
|
+
const where = f.location ? shortWhere(f.location) : '';
|
|
78
|
+
if (where && indent.length + where.length + 2 + reason.length <= width) {
|
|
79
|
+
lines.push(`${indent}${where} ${dim(reason)}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (where)
|
|
83
|
+
lines.push(`${indent}${where}`);
|
|
84
|
+
lines.push(...wrap(reason, width - indent.length, indent).map(dim));
|
|
85
|
+
}
|
|
86
|
+
if (f.display?.rotate)
|
|
87
|
+
lines.push(`${indent}${yellow('Rotate the key first:')} ${f.display.rotate}`);
|
|
88
|
+
return lines;
|
|
89
|
+
}
|
|
90
|
+
/** Rows of "command what it does", with the descriptions lined up and wrapped to the width. */
|
|
91
|
+
function commandRows(rows, width) {
|
|
92
|
+
const col = Math.max(...rows.map(([cmd]) => cmd.length));
|
|
93
|
+
const descIndent = 4 + col + 3;
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const [cmd, desc] of rows) {
|
|
96
|
+
if (width - descIndent < 24) {
|
|
97
|
+
out.push(` ${cmd}`, ...wrap(desc, width - 6, ' ').map(dim));
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const [first, ...more] = wrap(desc, width - descIndent, '');
|
|
101
|
+
out.push(` ${cmd.padEnd(col)} ${dim(first ?? '')}`, ...more.map((l) => ' '.repeat(descIndent) + dim(l)));
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/** Optional extras this run did not look at, for the clean verdict. */
|
|
106
|
+
function notChecked(report) {
|
|
107
|
+
const out = [];
|
|
108
|
+
const byId = new Map(report.categories.map((c) => [c.id, c]));
|
|
109
|
+
for (const c of report.categories)
|
|
110
|
+
if (c.skipped)
|
|
111
|
+
out.push(`${SHORT_NAMES[c.id] ?? c.name} (skipped)`);
|
|
112
|
+
const email = byId.get('email');
|
|
113
|
+
const dns = email?.manual.find((m) => m.id === 'email-dns');
|
|
114
|
+
if (email?.applicable && dns)
|
|
115
|
+
out.push(`email DNS (${/--domain/.test(dns.how) ? 'add --domain' : 'run online'})`);
|
|
116
|
+
const secrets = byId.get('secrets');
|
|
117
|
+
const history = secrets?.findings.some((f) => f.id === 'secret-in-history') ||
|
|
118
|
+
secrets?.passed.some((p) => /git history/i.test(p) && !/not checked/i.test(p));
|
|
119
|
+
if (secrets?.applicable && !history)
|
|
120
|
+
out.push('git history (add --history)');
|
|
121
|
+
out.push('your live site (launch-doctor scan <url>)');
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The default terminal report: the verdict, two grades, the three things to fix first and what to do next.
|
|
126
|
+
* `--verbose` (and --ci, --changed, --staged, --pr-comment and live scans) print the full report instead.
|
|
127
|
+
*/
|
|
128
|
+
export function renderShortReport(report, opts = {}) {
|
|
129
|
+
const width = Math.max(60, Math.min(100, process.stdout.columns || 80));
|
|
130
|
+
const counts = shortCounts(report);
|
|
131
|
+
const lines = [''];
|
|
132
|
+
if (opts.banner)
|
|
133
|
+
lines.push(...bannerLines());
|
|
134
|
+
lines.push(headerLine(report, width), ...noticeLines(report), '');
|
|
135
|
+
// 1. Verdict
|
|
136
|
+
const warnings = counts.security.warning + counts.launch.warning;
|
|
137
|
+
if (counts.critical) {
|
|
138
|
+
lines.push(` ${bold(red(`NOT READY TO LAUNCH: ${plural(counts.critical, 'critical problem')}`))}`);
|
|
139
|
+
}
|
|
140
|
+
else if (warnings) {
|
|
141
|
+
lines.push(` ${bold(yellow(`NOT READY TO LAUNCH: ${plural(warnings, 'problem')} to fix`))}`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
lines.push(` ${bold(green('Ready, as far as Launch Doctor can tell'))}`);
|
|
145
|
+
const ran = report.categories.filter((c) => c.applicable && !c.skipped).map((c) => SHORT_NAMES[c.id] ?? c.name);
|
|
146
|
+
const checked = ran.length
|
|
147
|
+
? `Checked ${list(ran)} in ${plural(report.filesScanned, 'file')}.`
|
|
148
|
+
: `Checked ${plural(report.filesScanned, 'file')}.`;
|
|
149
|
+
lines.push(...wrap(checked, width - 2, ' ').map(dim));
|
|
150
|
+
lines.push(...wrap("Can't check: your dashboard settings (Supabase, Stripe, hosting), backups, real sign-ins.", width - 2, ' ').map(dim));
|
|
151
|
+
lines.push(...wrap(`Not checked: ${notChecked(report).join(', ')}.`, width - 2, ' ').map(dim));
|
|
152
|
+
}
|
|
153
|
+
lines.push('');
|
|
154
|
+
// 2. The two grades
|
|
155
|
+
const parts = (c, warningWord) => [
|
|
156
|
+
...(c.critical ? [red(`${c.critical} critical`)] : []),
|
|
157
|
+
...(c.warning ? [yellow(plural(c.warning, warningWord))] : []),
|
|
158
|
+
];
|
|
159
|
+
lines.push(gradeRow('Security', report.grades?.security, parts(counts.security, 'warning')));
|
|
160
|
+
lines.push(gradeRow('Launch readiness', report.grades?.launch, parts(counts.launch, 'polish item')));
|
|
161
|
+
if (opts.lastRecorded) {
|
|
162
|
+
lines.push(` ${dim(`Overall grade ${report.grade} (${report.score}). Last recorded grade: ${opts.lastRecorded}`)}`);
|
|
163
|
+
}
|
|
164
|
+
lines.push('');
|
|
165
|
+
// 3. The three things to fix first
|
|
166
|
+
if (counts.top.length) {
|
|
167
|
+
lines.push(` ${bold('FIX THESE FIRST')}`, '');
|
|
168
|
+
for (const { finding, n } of counts.top)
|
|
169
|
+
lines.push(...findingLines(finding, n, width), '');
|
|
170
|
+
}
|
|
171
|
+
// 4. Everything else, counted
|
|
172
|
+
const also = [
|
|
173
|
+
...(counts.also.critical ? [red(`${counts.also.critical} more critical`)] : []),
|
|
174
|
+
...(counts.also.warning ? [yellow(plural(counts.also.warning, 'warning'))] : []),
|
|
175
|
+
...(counts.also.polish ? [plural(counts.also.polish, 'polish item')] : []),
|
|
176
|
+
...(counts.also.manual ? [`${counts.also.manual} to check yourself`] : []),
|
|
177
|
+
];
|
|
178
|
+
if (also.length)
|
|
179
|
+
lines.push(` Also: ${also.join(dim(' · '))}`);
|
|
180
|
+
if (counts.baseline) {
|
|
181
|
+
lines.push(` ${dim(`${plural(counts.baseline, 'existing issue')} (baseline) not shown. Use --no-baseline to list them.`)}`);
|
|
182
|
+
}
|
|
183
|
+
if (report.ignored) {
|
|
184
|
+
lines.push(` ${dim(`${plural(report.ignored, 'item')} hidden by .launchdoctorignore or launch-doctor-ignore comments`)}`);
|
|
185
|
+
}
|
|
186
|
+
for (const id of report.unknownIgnoreIds) {
|
|
187
|
+
lines.push(` ${dim(`Warning: "${id}" in .launchdoctorignore doesn't match any check (typo?)`)}`);
|
|
188
|
+
}
|
|
189
|
+
if (also.length || counts.baseline || report.ignored || report.unknownIgnoreIds.length)
|
|
190
|
+
lines.push('');
|
|
191
|
+
// 5. What to do next
|
|
192
|
+
const target = opts.target ?? '';
|
|
193
|
+
const rows = [];
|
|
194
|
+
const first = counts.top[0];
|
|
195
|
+
if (first)
|
|
196
|
+
rows.push([`npx launch-doctor prompt ${first.n}${target} --copy`, `copy the fix prompt for ${first.n}`]);
|
|
197
|
+
if (opts.fixFile) {
|
|
198
|
+
const anyCritical = orderedFindings(report).some((f) => f.severity === 'critical');
|
|
199
|
+
rows.push([
|
|
200
|
+
opts.fixFile,
|
|
201
|
+
anyCritical ? 'every fix prompt, starting with one for all critical problems' : 'every fix prompt',
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
204
|
+
rows.push([`npx launch-doctor${target} --verbose`, 'the full report']);
|
|
205
|
+
// The demo's folder is deleted after the scan, so it has nowhere to write a report.
|
|
206
|
+
if (opts.reportFile)
|
|
207
|
+
rows.push([opts.reportFile, 'every finding explained']);
|
|
208
|
+
else if (!opts.demo)
|
|
209
|
+
rows.push([`npx launch-doctor${target} --report`, 'every finding explained, in .launchdoctor/report.md']);
|
|
210
|
+
lines.push(` ${bold('Next')}`, ...commandRows(rows, width));
|
|
211
|
+
if (opts.demo && !opts.fixFile)
|
|
212
|
+
lines.push(` ${dim('On your own project, every fix prompt is saved to LAUNCH_FIXES.md.')}`);
|
|
213
|
+
lines.push('');
|
|
214
|
+
lines.push(` ${dim(`Wrong finding? ${ISSUES_LIST_URL}`)}`, '');
|
|
215
|
+
return `${lines.join('\n')}\n`;
|
|
216
|
+
}
|
|
217
|
+
function messageWidth() {
|
|
218
|
+
return Math.max(60, Math.min(100, process.stdout.columns || 80));
|
|
219
|
+
}
|
|
220
|
+
/** First run in a folder with nothing to read: an explanation instead of a grade. */
|
|
221
|
+
export function renderEmptyFolder(report, root) {
|
|
222
|
+
const width = messageWidth();
|
|
223
|
+
return [
|
|
224
|
+
'',
|
|
225
|
+
` ${bold('Launch Doctor')} ${dim(`v${report.version}`)}`,
|
|
226
|
+
'',
|
|
227
|
+
...wrap(`Nothing to check here: no project files were found in ${root}.`, width - 2, ' '),
|
|
228
|
+
...wrap("Run it inside your app's folder (the one with package.json, requirements.txt or similar), or try it on a built-in sample app: npx launch-doctor --demo", width - 2, ' '),
|
|
229
|
+
'',
|
|
230
|
+
'',
|
|
231
|
+
].join('\n');
|
|
232
|
+
}
|
|
233
|
+
/** A project in a language whose code the checks don't read: an explanation instead of a meaningless grade. */
|
|
234
|
+
export function renderOtherLanguage(report, found) {
|
|
235
|
+
const width = messageWidth();
|
|
236
|
+
return [
|
|
237
|
+
'',
|
|
238
|
+
` ${bold('Launch Doctor')} ${dim(`v${report.version} · ${report.projectName}`)}`,
|
|
239
|
+
'',
|
|
240
|
+
...wrap(`This looks like a ${found.language} project (${found.marker}). Launch Doctor's checks are written for JavaScript, TypeScript and Python apps, so it can't give this project a grade.`, width - 2, ' '),
|
|
241
|
+
...wrap('It can still check your deployed site from the outside:', width - 2, ' '),
|
|
242
|
+
' npx launch-doctor scan https://your-site.com',
|
|
243
|
+
'',
|
|
244
|
+
'',
|
|
245
|
+
].join('\n');
|
|
246
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -20,6 +20,32 @@ export interface Finding {
|
|
|
20
20
|
fingerprint?: string;
|
|
21
21
|
/** True when this finding is in .launchdoctor-baseline.json (an existing, accepted issue). */
|
|
22
22
|
baseline?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A short id for this one finding ("3f9a1c2b"), the same on every scan while the finding is unchanged: a hash of the
|
|
25
|
+
* rule id, the file and the text of its line (whitespace collapsed), so it survives the line moving. Set by
|
|
26
|
+
* runDoctor and runLiveScan. Used by `prompt`, `explain` and the MCP tools.
|
|
27
|
+
*/
|
|
28
|
+
ref?: string;
|
|
29
|
+
/**
|
|
30
|
+
* How the short terminal report shows this finding. Display only: ids, titles, fingerprints and
|
|
31
|
+
* baselines never use it. Absent for most warnings, which then show their title and the start of `why`.
|
|
32
|
+
*/
|
|
33
|
+
display?: FindingDisplay;
|
|
34
|
+
}
|
|
35
|
+
export interface FindingDisplay {
|
|
36
|
+
/** Consequence first: "Anyone can use your Stripe account: the live secret key is in your code". */
|
|
37
|
+
title: string;
|
|
38
|
+
/** A few words shown after file:line: "sent to every visitor's browser". */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** For a leaked key: where to revoke it (a link to the provider's key page, or the menu path). */
|
|
41
|
+
rotate?: string;
|
|
42
|
+
/** For a leaked key: the provider's usage or activity log, to check whether someone else used it. */
|
|
43
|
+
usage?: string;
|
|
44
|
+
}
|
|
45
|
+
/** A grade for a group of categories (see GRADE_GROUPS), computed with the same rules as the overall grade. */
|
|
46
|
+
export interface GroupGrade {
|
|
47
|
+
score: number | null;
|
|
48
|
+
grade: Grade | null;
|
|
23
49
|
}
|
|
24
50
|
/** Something we can't see from the code, so the user has to check it. */
|
|
25
51
|
export interface ManualCheck {
|
|
@@ -82,6 +108,11 @@ export interface Report {
|
|
|
82
108
|
};
|
|
83
109
|
score: number;
|
|
84
110
|
grade: Grade;
|
|
111
|
+
/** Security and Launch readiness grades, shown in the terminal report. Absent for a live site scan. */
|
|
112
|
+
grades?: {
|
|
113
|
+
security: GroupGrade;
|
|
114
|
+
launch: GroupGrade;
|
|
115
|
+
};
|
|
85
116
|
verdict: string;
|
|
86
117
|
/** baseline: how many findings matched .launchdoctor-baseline.json. */
|
|
87
118
|
counts: {
|
|
@@ -125,4 +156,6 @@ export interface Options {
|
|
|
125
156
|
history?: {
|
|
126
157
|
depth: number;
|
|
127
158
|
};
|
|
159
|
+
/** Called before each category is checked, with its name (for a progress line). */
|
|
160
|
+
onProgress?: (step: string) => void;
|
|
128
161
|
}
|
package/dist/src/util.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Where people report false alarms, misses and crashes. */
|
|
2
2
|
export declare const ISSUES_URL = "https://github.com/SHARAJ379/Launch-Doctor/issues/new/choose";
|
|
3
|
+
/** The issue list: shorter, for the one-line footer of the short report. */
|
|
4
|
+
export declare const ISSUES_LIST_URL = "https://github.com/SHARAJ379/Launch-Doctor/issues";
|
|
3
5
|
/** 1-based line number of a character index. */
|
|
4
6
|
export declare function lineAt(text: string, index: number): number;
|
|
5
7
|
/** The full text of the line containing `index`. */
|