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/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { legalCheck } from './checks/legal.js';
|
|
|
8
8
|
import { monitoringCheck } from './checks/monitoring.js';
|
|
9
9
|
import { paymentsCheck } from './checks/payments.js';
|
|
10
10
|
import { secretsCheck } from './checks/secrets.js';
|
|
11
|
-
import { overall, scoreCategory, toGrade } from './grade.js';
|
|
11
|
+
import { GRADE_GROUPS, groupGrade, overall, scoreCategory, toGrade } from './grade.js';
|
|
12
12
|
import { scanHistory } from './history.js';
|
|
13
13
|
import { ProjectContext } from './project.js';
|
|
14
14
|
import { sanitizeReport } from './sanitize.js';
|
|
@@ -79,6 +79,7 @@ export async function runDoctor(root, options = {}) {
|
|
|
79
79
|
});
|
|
80
80
|
continue;
|
|
81
81
|
}
|
|
82
|
+
options.onProgress?.(check.name);
|
|
82
83
|
let out;
|
|
83
84
|
try {
|
|
84
85
|
out = await check.run(ctx);
|
|
@@ -157,6 +158,10 @@ export async function runDoctor(root, options = {}) {
|
|
|
157
158
|
...(ctx.nestedRepos.length ? { nestedRepos: ctx.nestedRepos } : {}),
|
|
158
159
|
...(options.onlyFiles ? { partial: { files: options.onlyFiles } } : {}),
|
|
159
160
|
...summary,
|
|
161
|
+
grades: {
|
|
162
|
+
security: groupGrade(categories, GRADE_GROUPS.security),
|
|
163
|
+
launch: groupGrade(categories, GRADE_GROUPS.launch),
|
|
164
|
+
},
|
|
160
165
|
categories,
|
|
161
166
|
generatedAt: new Date().toISOString(),
|
|
162
167
|
};
|
package/dist/src/live.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { emptyOutput, notApplicable } from './checks/common.js';
|
|
2
|
-
import { matchKeys } from './checks/secrets.js';
|
|
2
|
+
import { leakPlaybook, matchKeys, usageLink } from './checks/secrets.js';
|
|
3
3
|
import { overall, scoreCategory, toGrade } from './grade.js';
|
|
4
4
|
import { checkHost, defaultLookup } from './net-guard.js';
|
|
5
5
|
import { pinnedGet } from './pinned-http.js';
|
|
@@ -410,7 +410,8 @@ async function exposureCheck(fetcher, home, page) {
|
|
|
410
410
|
`1. Find where my code reads it and move that code to the server (an API route, server action or edge function), reading ${m.pattern.envName} from environment variables there.\n` +
|
|
411
411
|
`2. Make sure no NEXT_PUBLIC_/VITE_ variable holds it.\n` +
|
|
412
412
|
`3. Redeploy and confirm the key no longer appears in the built JavaScript.\n` +
|
|
413
|
-
`Then tell me how to revoke this key and create a new one (${m.pattern.rotate}), because it is already public
|
|
413
|
+
`Then tell me how to revoke this key and create a new one (${m.pattern.rotate}), because it is already public.` +
|
|
414
|
+
leakPlaybook({ usage: usageLink(m.pattern.id), from: 'live' }),
|
|
414
415
|
}));
|
|
415
416
|
}
|
|
416
417
|
}
|
|
@@ -444,7 +445,8 @@ async function databaseCheck(fetcher, page, opts) {
|
|
|
444
445
|
},
|
|
445
446
|
fixPrompt: `My live site ships a Supabase service_role key (it starts with "${mask(m[0])}") in its JavaScript. Please remove it from all frontend code: the browser may only use the anon/publishable key. ` +
|
|
446
447
|
`Move any feature that needs admin access into server-only code (API route or Edge Function) that reads SUPABASE_SERVICE_ROLE_KEY from environment variables, redeploy, ` +
|
|
447
|
-
`and tell me how to rotate the JWT secret / service_role key in Supabase, because it is already public
|
|
448
|
+
`and tell me how to rotate the JWT secret / service_role key in Supabase, because it is already public.` +
|
|
449
|
+
leakPlaybook({ usage: usageLink('supabase-service-role-key'), from: 'live' }),
|
|
448
450
|
}));
|
|
449
451
|
}
|
|
450
452
|
else if (role === 'anon' && !anonKeys.includes(m[0]))
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Finding, Report } from './types.js';
|
|
2
|
+
/** Fix prompt n (1-based, in LAUNCH_FIXES.md order), or null when there is no such prompt. */
|
|
3
|
+
export declare function promptFor(report: Report, n: number): Finding | null;
|
|
4
|
+
interface ClipboardTool {
|
|
5
|
+
name: string;
|
|
6
|
+
args: string[];
|
|
7
|
+
/** The bytes to send on stdin. */
|
|
8
|
+
encode: (text: string) => Buffer;
|
|
9
|
+
env?: NodeJS.ProcessEnv;
|
|
10
|
+
}
|
|
11
|
+
/** The clipboard tools to try on this system, in order. None on a Linux machine without a display. */
|
|
12
|
+
export declare function clipboardTools(platform: NodeJS.Platform, env: NodeJS.ProcessEnv): ClipboardTool[];
|
|
13
|
+
/** Put text on the clipboard with the system's own tool. Returns the tool's name, or null if none worked. */
|
|
14
|
+
export declare function copyToClipboard(text: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string | null;
|
|
15
|
+
/**
|
|
16
|
+
* { language: 'Rust', marker: 'Cargo.toml' } when the folder is a project in a language Launch Doctor doesn't
|
|
17
|
+
* analyse, with nothing it does (no package.json, no detected stack, no findings to fix). Null otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function unsupportedLanguage(root: string, report: Report): {
|
|
20
|
+
language: string;
|
|
21
|
+
marker: string;
|
|
22
|
+
} | null;
|
|
23
|
+
export {};
|
|
@@ -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
|
+
}
|
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,59 @@
|
|
|
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
|
+
/** The last recorded overall grade ("B (82) on 30 Nov 2026"). */
|
|
8
|
+
lastRecorded?: string;
|
|
9
|
+
banner?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* What to type after `npx launch-doctor` to scan the same project again: "", " ./my-app" or " --demo".
|
|
12
|
+
* Used in the "Next" commands.
|
|
13
|
+
*/
|
|
14
|
+
target?: string;
|
|
15
|
+
/** The built-in demo: LAUNCH_FIXES.md is never written for it. */
|
|
16
|
+
demo?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Every number the short report shows, worked out in one place so they always add up.
|
|
20
|
+
* Baseline findings (already accepted) are left out, as in the full report.
|
|
21
|
+
*/
|
|
22
|
+
export interface ShortCounts {
|
|
23
|
+
/** New critical findings: the verdict's number, and the sum of the critical counts on the two grade rows. */
|
|
24
|
+
critical: number;
|
|
25
|
+
security: {
|
|
26
|
+
critical: number;
|
|
27
|
+
warning: number;
|
|
28
|
+
};
|
|
29
|
+
launch: {
|
|
30
|
+
critical: number;
|
|
31
|
+
warning: number;
|
|
32
|
+
};
|
|
33
|
+
/** The findings under FIX THESE FIRST, with their fix-prompt numbers. */
|
|
34
|
+
top: {
|
|
35
|
+
finding: Finding;
|
|
36
|
+
n: number;
|
|
37
|
+
}[];
|
|
38
|
+
/** What the "Also:" line counts: everything not shown under FIX THESE FIRST. */
|
|
39
|
+
also: {
|
|
40
|
+
critical: number;
|
|
41
|
+
warning: number;
|
|
42
|
+
polish: number;
|
|
43
|
+
manual: number;
|
|
44
|
+
};
|
|
45
|
+
baseline: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function shortCounts(report: Report): ShortCounts;
|
|
48
|
+
/**
|
|
49
|
+
* The default terminal report: the verdict, two grades, the three things to fix first and what to do next.
|
|
50
|
+
* `--verbose` (and --ci, --changed, --staged, --pr-comment and live scans) print the full report instead.
|
|
51
|
+
*/
|
|
52
|
+
export declare function renderShortReport(report: Report, opts?: ShortReportOptions): string;
|
|
53
|
+
/** First run in a folder with nothing to read: an explanation instead of a grade. */
|
|
54
|
+
export declare function renderEmptyFolder(report: Report, root: string): string;
|
|
55
|
+
/** A project in a language whose code the checks don't read: an explanation instead of a meaningless grade. */
|
|
56
|
+
export declare function renderOtherLanguage(report: Report, found: {
|
|
57
|
+
language: string;
|
|
58
|
+
marker: string;
|
|
59
|
+
}): string;
|
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
lines.push(` ${bold('Next')}`, ...commandRows(rows, width));
|
|
206
|
+
if (opts.demo && !opts.fixFile)
|
|
207
|
+
lines.push(` ${dim('On your own project, every fix prompt is saved to LAUNCH_FIXES.md.')}`);
|
|
208
|
+
lines.push('');
|
|
209
|
+
lines.push(` ${dim(`Wrong finding? ${ISSUES_LIST_URL}`)}`, '');
|
|
210
|
+
return `${lines.join('\n')}\n`;
|
|
211
|
+
}
|
|
212
|
+
function messageWidth() {
|
|
213
|
+
return Math.max(60, Math.min(100, process.stdout.columns || 80));
|
|
214
|
+
}
|
|
215
|
+
/** First run in a folder with nothing to read: an explanation instead of a grade. */
|
|
216
|
+
export function renderEmptyFolder(report, root) {
|
|
217
|
+
const width = messageWidth();
|
|
218
|
+
return [
|
|
219
|
+
'',
|
|
220
|
+
` ${bold('Launch Doctor')} ${dim(`v${report.version}`)}`,
|
|
221
|
+
'',
|
|
222
|
+
...wrap(`Nothing to check here: no project files were found in ${root}.`, width - 2, ' '),
|
|
223
|
+
...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, ' '),
|
|
224
|
+
'',
|
|
225
|
+
'',
|
|
226
|
+
].join('\n');
|
|
227
|
+
}
|
|
228
|
+
/** A project in a language whose code the checks don't read: an explanation instead of a meaningless grade. */
|
|
229
|
+
export function renderOtherLanguage(report, found) {
|
|
230
|
+
const width = messageWidth();
|
|
231
|
+
return [
|
|
232
|
+
'',
|
|
233
|
+
` ${bold('Launch Doctor')} ${dim(`v${report.version} · ${report.projectName}`)}`,
|
|
234
|
+
'',
|
|
235
|
+
...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, ' '),
|
|
236
|
+
...wrap('It can still check your deployed site from the outside:', width - 2, ' '),
|
|
237
|
+
' npx launch-doctor scan https://your-site.com',
|
|
238
|
+
'',
|
|
239
|
+
'',
|
|
240
|
+
].join('\n');
|
|
241
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -20,6 +20,26 @@ 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
|
+
* How the short terminal report shows this finding. Display only: ids, titles, fingerprints and
|
|
25
|
+
* baselines never use it. Absent for most warnings, which then show their title and the start of `why`.
|
|
26
|
+
*/
|
|
27
|
+
display?: FindingDisplay;
|
|
28
|
+
}
|
|
29
|
+
export interface FindingDisplay {
|
|
30
|
+
/** Consequence first: "Anyone can use your Stripe account: the live secret key is in your code". */
|
|
31
|
+
title: string;
|
|
32
|
+
/** A few words shown after file:line: "sent to every visitor's browser". */
|
|
33
|
+
reason?: string;
|
|
34
|
+
/** For a leaked key: where to revoke it (a link to the provider's key page, or the menu path). */
|
|
35
|
+
rotate?: string;
|
|
36
|
+
/** For a leaked key: the provider's usage or activity log, to check whether someone else used it. */
|
|
37
|
+
usage?: string;
|
|
38
|
+
}
|
|
39
|
+
/** A grade for a group of categories (see GRADE_GROUPS), computed with the same rules as the overall grade. */
|
|
40
|
+
export interface GroupGrade {
|
|
41
|
+
score: number | null;
|
|
42
|
+
grade: Grade | null;
|
|
23
43
|
}
|
|
24
44
|
/** Something we can't see from the code, so the user has to check it. */
|
|
25
45
|
export interface ManualCheck {
|
|
@@ -82,6 +102,11 @@ export interface Report {
|
|
|
82
102
|
};
|
|
83
103
|
score: number;
|
|
84
104
|
grade: Grade;
|
|
105
|
+
/** Security and Launch readiness grades, shown in the terminal report. Absent for a live site scan. */
|
|
106
|
+
grades?: {
|
|
107
|
+
security: GroupGrade;
|
|
108
|
+
launch: GroupGrade;
|
|
109
|
+
};
|
|
85
110
|
verdict: string;
|
|
86
111
|
/** baseline: how many findings matched .launchdoctor-baseline.json. */
|
|
87
112
|
counts: {
|
|
@@ -125,4 +150,6 @@ export interface Options {
|
|
|
125
150
|
history?: {
|
|
126
151
|
depth: number;
|
|
127
152
|
};
|
|
153
|
+
/** Called before each category is checked, with its name (for a progress line). */
|
|
154
|
+
onProgress?: (step: string) => void;
|
|
128
155
|
}
|
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`. */
|
package/dist/src/util.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Where people report false alarms, misses and crashes. */
|
|
2
2
|
export 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 const ISSUES_LIST_URL = 'https://github.com/SHARAJ379/Launch-Doctor/issues';
|
|
3
5
|
/** 1-based line number of a character index. */
|
|
4
6
|
export function lineAt(text, index) {
|
|
5
7
|
let line = 1;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "launch-doctor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "A pre-launch checkup for vibe-coded apps. Grades your project A-F on secrets, database safety, payments, AI costs, email, error tracking, legal pages and first impressions, with a copy-paste fix prompt for every issue.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"launch-doctor": "dist/src/
|
|
7
|
+
"launch-doctor": "dist/src/bin.cjs"
|
|
8
8
|
},
|
|
9
9
|
"main": "dist/src/index.js",
|
|
10
10
|
"types": "dist/src/index.d.ts",
|