launch-doctor 0.4.2 → 0.4.4
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 +54 -1
- package/README.md +30 -6
- package/dist/src/baseline.d.ts +9 -0
- package/dist/src/baseline.js +26 -0
- package/dist/src/checks/email.js +3 -1
- package/dist/src/checks/secrets.js +3 -1
- package/dist/src/cli.js +240 -88
- 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/git.d.ts +1 -1
- package/dist/src/git.js +6 -3
- package/dist/src/hooks-setup.js +19 -6
- package/dist/src/index.js +2 -1
- package/dist/src/init.d.ts +17 -0
- package/dist/src/init.js +73 -6
- package/dist/src/live.js +3 -0
- package/dist/src/mcp.d.ts +126 -11
- package/dist/src/mcp.js +294 -148
- package/dist/src/prompt.d.ts +9 -0
- package/dist/src/prompt.js +84 -0
- package/dist/src/report-md.d.ts +14 -0
- package/dist/src/report-md.js +71 -0
- package/dist/src/safe-fs.d.ts +9 -0
- package/dist/src/safe-fs.js +27 -1
- package/dist/src/short-report.d.ts +2 -0
- package/dist/src/short-report.js +5 -0
- package/dist/src/types.d.ts +6 -0
- package/package.json +2 -2
package/dist/src/prompt.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
3
4
|
import { orderedFindings } from './fixes.js';
|
|
5
|
+
import { readRegularFile } from './safe-fs.js';
|
|
4
6
|
/** Fix prompt n (1-based, in LAUNCH_FIXES.md order), or null when there is no such prompt. */
|
|
5
7
|
export function promptFor(report, n) {
|
|
6
8
|
return orderedFindings(report)[n - 1] ?? null;
|
|
@@ -86,3 +88,85 @@ export function unsupportedLanguage(root, report) {
|
|
|
86
88
|
}
|
|
87
89
|
return null;
|
|
88
90
|
}
|
|
91
|
+
/** Folders that never hold a project of their own (or are too big to look through). */
|
|
92
|
+
const NOT_PROJECTS = new Set([
|
|
93
|
+
'node_modules',
|
|
94
|
+
'dist',
|
|
95
|
+
'build',
|
|
96
|
+
'out',
|
|
97
|
+
'vendor',
|
|
98
|
+
'target',
|
|
99
|
+
'venv',
|
|
100
|
+
'__pycache__',
|
|
101
|
+
'AppData',
|
|
102
|
+
'Library',
|
|
103
|
+
'Applications',
|
|
104
|
+
]);
|
|
105
|
+
/** Files that make a folder a workspace root (a monorepo), where checking its projects together is the point. */
|
|
106
|
+
const WORKSPACE_FILES = ['pnpm-workspace.yaml', 'turbo.json', 'nx.json', 'lerna.json'];
|
|
107
|
+
/** Does `root` configure a monorepo: one of the files above, or "workspaces" in its package.json? */
|
|
108
|
+
function hasWorkspaceConfig(root) {
|
|
109
|
+
if (WORKSPACE_FILES.some((f) => existsSync(join(root, f))))
|
|
110
|
+
return true;
|
|
111
|
+
// The project may not be yours, so package.json is read like every file of a project: a regular file, not a huge one.
|
|
112
|
+
const text = readRegularFile(join(root, 'package.json'), 1024 * 1024);
|
|
113
|
+
if (text === null)
|
|
114
|
+
return false;
|
|
115
|
+
try {
|
|
116
|
+
const workspaces = JSON.parse(text).workspaces;
|
|
117
|
+
return Array.isArray(workspaces) || (typeof workspaces === 'object' && workspaces !== null);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Folders below `root` (three levels at most) that hold a project of their own, when `root` itself has no project
|
|
125
|
+
* file. Run in a home folder or on the Desktop, a scan mixes them all into one grade. Null when `root` is a project,
|
|
126
|
+
* or a workspace root (a monorepo, see hasWorkspaceConfig), or when fewer than two are found. Only folder names are
|
|
127
|
+
* read, at most 2,000 folders.
|
|
128
|
+
*/
|
|
129
|
+
export function separateProjects(root) {
|
|
130
|
+
if (hasWorkspaceConfig(root) || SUPPORTED.some((f) => existsSync(join(root, f))))
|
|
131
|
+
return null;
|
|
132
|
+
const found = [];
|
|
133
|
+
let visited = 0;
|
|
134
|
+
const visit = (rel, depth) => {
|
|
135
|
+
let entries;
|
|
136
|
+
try {
|
|
137
|
+
entries = readdirSync(join(root, rel), { withFileTypes: true });
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const e of entries) {
|
|
143
|
+
if (!e.isDirectory() || e.name.startsWith('.') || NOT_PROJECTS.has(e.name))
|
|
144
|
+
continue;
|
|
145
|
+
if (++visited > 2000 || found.length >= 20)
|
|
146
|
+
return;
|
|
147
|
+
const child = rel ? `${rel}/${e.name}` : e.name;
|
|
148
|
+
if (SUPPORTED.some((f) => existsSync(join(root, child, f))))
|
|
149
|
+
found.push(child);
|
|
150
|
+
else if (depth < 2)
|
|
151
|
+
visit(child, depth + 1);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
visit('', 0);
|
|
155
|
+
return found.length >= 2 ? found.sort() : null;
|
|
156
|
+
}
|
|
157
|
+
/** The note under the report for separateProjects: what they are, and how to check one. */
|
|
158
|
+
export function separateProjectsNote(root, projects, cwd = process.cwd()) {
|
|
159
|
+
const shown = projects.slice(0, 5);
|
|
160
|
+
const first = relative(cwd, join(root, projects[0])).replace(/\\/g, '/') || '.';
|
|
161
|
+
const folder = /^[\w./-]+$/.test(first) ? first : `"${first}"`;
|
|
162
|
+
return [
|
|
163
|
+
` Note: this folder has no package.json (or similar) of its own, but ${projects.length} projects are inside it:`,
|
|
164
|
+
...shown.map((p) => ` ${p}`),
|
|
165
|
+
...(projects.length > shown.length ? [` and ${projects.length - shown.length} more`] : []),
|
|
166
|
+
' The grade above mixes them. To check one project, run Launch Doctor in its folder:',
|
|
167
|
+
` cd ${folder}`,
|
|
168
|
+
' npx launch-doctor',
|
|
169
|
+
'',
|
|
170
|
+
'',
|
|
171
|
+
].join('\n');
|
|
172
|
+
}
|
|
@@ -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/safe-fs.d.ts
CHANGED
|
@@ -17,3 +17,12 @@ export declare function readRegularFile(path: string, maxBytes: number): string
|
|
|
17
17
|
export declare function writeRegularFile(path: string, content: string): void;
|
|
18
18
|
/** What kind of entry `path` is, without following a link or opening it. */
|
|
19
19
|
export declare function entryKind(path: string): 'file' | 'dir' | 'other' | 'missing';
|
|
20
|
+
/**
|
|
21
|
+
* The full path of `rel` (written with "/") inside `root`, after making its folders like `mkdir -p`. A folder on the
|
|
22
|
+
* way that already exists as a link (a symlink, or a junction on Windows), a file or a special file is refused with an
|
|
23
|
+
* error: a project can't make Launch Doctor write outside it by shipping `.launchdoctor`, `.github` or `.claude` as a
|
|
24
|
+
* link to another folder. (writeRegularFile checks only the file itself.)
|
|
25
|
+
*/
|
|
26
|
+
export declare function pathInside(root: string, rel: string): string;
|
|
27
|
+
/** writeRegularFile for `rel` inside `root`, refusing any folder on the way that is a link (see pathInside). */
|
|
28
|
+
export declare function writeInside(root: string, rel: string, content: string): void;
|
package/dist/src/safe-fs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, relative } from 'node:path';
|
|
2
3
|
/**
|
|
3
4
|
* Reading Launch Doctor's own files (.launchdoctorignore, the baseline, and the config file planned for R7) from a
|
|
4
5
|
* project that may be hostile.
|
|
@@ -75,3 +76,28 @@ export function entryKind(path) {
|
|
|
75
76
|
return 'missing';
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* The full path of `rel` (written with "/") inside `root`, after making its folders like `mkdir -p`. A folder on the
|
|
81
|
+
* way that already exists as a link (a symlink, or a junction on Windows), a file or a special file is refused with an
|
|
82
|
+
* error: a project can't make Launch Doctor write outside it by shipping `.launchdoctor`, `.github` or `.claude` as a
|
|
83
|
+
* link to another folder. (writeRegularFile checks only the file itself.)
|
|
84
|
+
*/
|
|
85
|
+
export function pathInside(root, rel) {
|
|
86
|
+
let dir = root;
|
|
87
|
+
for (const part of rel.split('/').slice(0, -1)) {
|
|
88
|
+
dir = join(dir, part);
|
|
89
|
+
const kind = entryKind(dir);
|
|
90
|
+
if (kind === 'missing')
|
|
91
|
+
mkdirSync(dir);
|
|
92
|
+
else if (kind !== 'dir') {
|
|
93
|
+
const shown = relative(root, dir).replace(/\\/g, '/');
|
|
94
|
+
const what = kind === 'file' ? 'a file' : 'a link or a special file';
|
|
95
|
+
throw new Error(`${shown} is ${what}, not a folder, so nothing was written into it`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return join(root, rel);
|
|
99
|
+
}
|
|
100
|
+
/** writeRegularFile for `rel` inside `root`, refusing any folder on the way that is a link (see pathInside). */
|
|
101
|
+
export function writeInside(root, rel, content) {
|
|
102
|
+
writeRegularFile(pathInside(root, rel), content);
|
|
103
|
+
}
|
|
@@ -4,6 +4,8 @@ export declare const TOP_FINDINGS = 3;
|
|
|
4
4
|
export interface ShortReportOptions {
|
|
5
5
|
/** Where LAUNCH_FIXES.md was written, if it was. */
|
|
6
6
|
fixFile?: string;
|
|
7
|
+
/** Where --report wrote .launchdoctor/report.md, if it did. */
|
|
8
|
+
reportFile?: string;
|
|
7
9
|
/** The last recorded overall grade ("B (82) on 30 Nov 2026"). */
|
|
8
10
|
lastRecorded?: string;
|
|
9
11
|
banner?: boolean;
|
package/dist/src/short-report.js
CHANGED
|
@@ -202,6 +202,11 @@ export function renderShortReport(report, opts = {}) {
|
|
|
202
202
|
]);
|
|
203
203
|
}
|
|
204
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']);
|
|
205
210
|
lines.push(` ${bold('Next')}`, ...commandRows(rows, width));
|
|
206
211
|
if (opts.demo && !opts.fixFile)
|
|
207
212
|
lines.push(` ${dim('On your own project, every fix prompt is saved to LAUNCH_FIXES.md.')}`);
|
package/dist/src/types.d.ts
CHANGED
|
@@ -20,6 +20,12 @@ 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;
|
|
23
29
|
/**
|
|
24
30
|
* How the short terminal report shows this finding. Display only: ids, titles, fingerprints and
|
|
25
31
|
* baselines never use it. Absent for most warnings, which then show their title and the start of `why`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "launch-doctor",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
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": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"lint": "biome lint .",
|
|
22
22
|
"format": "biome format --write .",
|
|
23
23
|
"format:check": "biome format .",
|
|
24
|
-
"test": "npm run build && node --test \"dist/test/**/*.test.js\"",
|
|
24
|
+
"test": "npm run build && node --test --test-timeout=120000 \"dist/test/**/*.test.js\"",
|
|
25
25
|
"stress": "npm run build && node scripts/stress/run.mjs",
|
|
26
26
|
"start": "node dist/src/cli.js",
|
|
27
27
|
"doctor": "npm run build && node dist/src/cli.js",
|