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
package/dist/src/fixes.js
CHANGED
|
@@ -13,18 +13,41 @@ function section(f, n) {
|
|
|
13
13
|
const parts = [`### ${n}. ${md(f.title)}`, ''];
|
|
14
14
|
if (f.location)
|
|
15
15
|
parts.push(`**Where:** ${mdCode(shortWhere(f.location))}`, '');
|
|
16
|
+
// Links come from Launch Doctor's own provider table, so they are written as links; other text is escaped.
|
|
17
|
+
const link = (x) => (/^https:\/\/[^\s<>]+$/.test(x) ? `<${x}>` : md(x));
|
|
18
|
+
if (f.display?.rotate)
|
|
19
|
+
parts.push(`**Rotate the key first:** ${link(f.display.rotate)}`, '');
|
|
20
|
+
if (f.display?.usage)
|
|
21
|
+
parts.push(`**Check whether someone used it:** ${link(f.display.usage)}`, '');
|
|
16
22
|
if (f.baseline)
|
|
17
23
|
parts.push('_Existing issue, recorded in .launchdoctor-baseline.json._', '');
|
|
18
24
|
parts.push(`**Why it matters:** ${md(f.why, { oneLine: false })}`, '', '**Prompt to paste:**', '', fence(f.fixPrompt), '');
|
|
19
25
|
parts.push(`<sub>Not relevant to your app? Add \`${f.id}\` to a \`.launchdoctorignore\` file.</sub>`, '');
|
|
20
26
|
return parts.join('\n');
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Every finding in fix-prompt order: critical ones first, then warnings, each in category order.
|
|
30
|
+
* Prompt n in LAUNCH_FIXES.md, `launch-doctor prompt n` and the short report's numbers all use this order.
|
|
31
|
+
*/
|
|
32
|
+
export function orderedFindings(report) {
|
|
33
|
+
const all = report.categories.flatMap((c) => c.findings);
|
|
34
|
+
return [...all.filter((f) => f.severity === 'critical'), ...all.filter((f) => f.severity === 'warning')];
|
|
35
|
+
}
|
|
36
|
+
/** One prompt for every critical finding, numbered like the prompts in LAUNCH_FIXES.md. */
|
|
37
|
+
export function criticalPrompt(report) {
|
|
38
|
+
const critical = orderedFindings(report).filter((f) => f.severity === 'critical');
|
|
39
|
+
if (!critical.length)
|
|
40
|
+
return null;
|
|
41
|
+
return (`I ran Launch Doctor on my app and it found ${plural(critical.length, 'critical problem')}. ` +
|
|
42
|
+
"Fix them one at a time, then tell me what you changed. For each one, explain the change in plain English and how to test it. Don't change anything unrelated, and ask me before deleting data.\n\n" +
|
|
43
|
+
critical.map((f, i) => `${i + 1}. ${f.title}${f.location ? ` — ${shortWhere(f.location)}` : ''}`).join('\n'));
|
|
44
|
+
}
|
|
22
45
|
/** A markdown file of copy-paste prompts, ordered by importance. */
|
|
23
46
|
export function renderFixes(report) {
|
|
24
|
-
const
|
|
25
|
-
const critical =
|
|
26
|
-
const warnings =
|
|
27
|
-
const
|
|
47
|
+
const ordered = orderedFindings(report);
|
|
48
|
+
const critical = ordered.filter((f) => f.severity === 'critical');
|
|
49
|
+
const warnings = ordered.filter((f) => f.severity === 'warning');
|
|
50
|
+
const allCritical = criticalPrompt(report);
|
|
28
51
|
const manual = report.categories.flatMap((c) => c.manual);
|
|
29
52
|
const date = report.generatedAt.slice(0, 10);
|
|
30
53
|
const out = [
|
|
@@ -32,13 +55,11 @@ export function renderFixes(report) {
|
|
|
32
55
|
'',
|
|
33
56
|
`**Grade: ${report.grade}** · ${report.verdict} · ${plural(critical.length, 'critical issue')} · ${plural(warnings.length, 'warning')} · checked ${date}`,
|
|
34
57
|
'',
|
|
35
|
-
'## How to use this file',
|
|
36
|
-
'',
|
|
37
|
-
'1. Paste **one prompt at a time** into your AI coding tool (Claude Code, Cursor, Lovable, Bolt, Windsurf…).',
|
|
38
|
-
'2. Read what it changed and test the app.',
|
|
39
|
-
'3. Run `npx launch-doctor` again to see your new grade.',
|
|
40
|
-
'',
|
|
41
58
|
];
|
|
59
|
+
if (allCritical) {
|
|
60
|
+
out.push('## Fix the critical problems first', '', `One prompt for all ${plural(critical.length, 'critical problem')}. Paste it into your AI coding tool, then run Launch Doctor again.`, '', fence(allCritical), '');
|
|
61
|
+
}
|
|
62
|
+
out.push('## How to use this file', '', '1. Paste **one prompt at a time** into your AI coding tool (Claude Code, Cursor, Lovable, Bolt, Windsurf…).', '2. Read what it changed and test the app.', '3. Run `npx launch-doctor` again to see your new grade.', '');
|
|
42
63
|
if (ordered.length) {
|
|
43
64
|
out.push('### Or fix everything in one go', '', fence('I ran Launch Doctor on my app and it found the problems below. Fix them one at a time, in this order. ' +
|
|
44
65
|
"For each one: explain the change in plain English, make it, and tell me how to test it. Don't change anything unrelated, and ask me before deleting data.\n\n" +
|
package/dist/src/grade.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CategoryResult, CheckOutput, Finding, Grade, Report, Severity } from './types.js';
|
|
1
|
+
import type { CategoryResult, CheckOutput, Finding, Grade, GroupGrade, Report, Severity } from './types.js';
|
|
2
2
|
export declare function scoreCategory(out: CheckOutput): number;
|
|
3
3
|
export declare function toGrade(score: number): Grade;
|
|
4
4
|
export declare function overall(categories: CategoryResult[]): {
|
|
@@ -12,5 +12,12 @@ export declare function overall(categories: CategoryResult[]): {
|
|
|
12
12
|
baseline: number;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
/** The two headline grades: the categories each one covers. */
|
|
16
|
+
export declare const GRADE_GROUPS: {
|
|
17
|
+
readonly security: readonly ['secrets', 'database', 'access', 'payments', 'costs'];
|
|
18
|
+
readonly launch: readonly ['email', 'monitoring', 'legal', 'first-impressions'];
|
|
19
|
+
};
|
|
20
|
+
/** One group's grade, with the same rules as the overall grade. Null when none of its categories applied. */
|
|
21
|
+
export declare function groupGrade(categories: CategoryResult[], ids: readonly string[]): GroupGrade;
|
|
15
22
|
/** New findings at or above a severity level: the ones that should fail a CI run. Baseline findings don't count. */
|
|
16
23
|
export declare function failingFindings(report: Report, failOn: Severity): Finding[];
|
package/dist/src/grade.js
CHANGED
|
@@ -44,6 +44,19 @@ export function overall(categories) {
|
|
|
44
44
|
: 'Looks ready to launch';
|
|
45
45
|
return { score, grade: toGrade(score), verdict, counts: { critical, warning, manual, baseline: 0 } };
|
|
46
46
|
}
|
|
47
|
+
/** The two headline grades: the categories each one covers. */
|
|
48
|
+
export const GRADE_GROUPS = {
|
|
49
|
+
security: ['secrets', 'database', 'access', 'payments', 'costs'],
|
|
50
|
+
launch: ['email', 'monitoring', 'legal', 'first-impressions'],
|
|
51
|
+
};
|
|
52
|
+
/** One group's grade, with the same rules as the overall grade. Null when none of its categories applied. */
|
|
53
|
+
export function groupGrade(categories, ids) {
|
|
54
|
+
const group = categories.filter((c) => ids.includes(c.id));
|
|
55
|
+
if (!group.some((c) => c.applicable && c.score !== null))
|
|
56
|
+
return { score: null, grade: null };
|
|
57
|
+
const { score, grade } = overall(group);
|
|
58
|
+
return { score, grade };
|
|
59
|
+
}
|
|
47
60
|
/** New findings at or above a severity level: the ones that should fail a CI run. Baseline findings don't count. */
|
|
48
61
|
export function failingFindings(report, failOn) {
|
|
49
62
|
return report.categories
|
package/dist/src/history.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createInterface } from 'node:readline';
|
|
3
|
-
import { matchKeys } from './checks/secrets.js';
|
|
3
|
+
import { leakPlaybook, matchKeys, rotateHint, usageLink } from './checks/secrets.js';
|
|
4
4
|
import { gitArgs, SAFE_DIFF } from './git.js';
|
|
5
5
|
import { isRealEnvPath } from './project.js';
|
|
6
6
|
import { mask } from './util.js';
|
|
@@ -94,9 +94,16 @@ function historyFinding(hit) {
|
|
|
94
94
|
title: `Secret still in git history: ${hit.pattern.name} (commit ${short}, ${hit.path})`,
|
|
95
95
|
why: `This ${hit.pattern.name} (${shown}) was removed from your code, but it's still in commit ${short}. Anyone who can clone the repo can dig it out, so it has to be treated as leaked.`,
|
|
96
96
|
location: { file: hit.path },
|
|
97
|
+
display: {
|
|
98
|
+
title: `Anyone who can clone the repo can use your ${hit.pattern.name}: it is still in git history`,
|
|
99
|
+
reason: `added in commit ${short}`,
|
|
100
|
+
rotate: rotateHint(hit.pattern),
|
|
101
|
+
...(usageLink(hit.pattern.id) ? { usage: usageLink(hit.pattern.id) } : {}),
|
|
102
|
+
},
|
|
97
103
|
fixPrompt: `Commit ${short} in my git history added a ${hit.pattern.name} (it starts with "${shown}") to ${hit.path}. The code no longer has it, but the history does. Please:\n` +
|
|
98
104
|
`1. Walk me through revoking this key and creating a new one (${hit.pattern.rotate}), and make sure the new one lives only in an environment variable.\n` +
|
|
99
105
|
`2. Optionally, explain how to remove it from the history with git filter-repo (for example "git filter-repo --replace-text replacements.txt"), what that means for everyone else who has a clone, and that I'll need to force-push.\n` +
|
|
100
|
-
`Rotating the key matters most: rewriting history doesn't help if someone already copied it
|
|
106
|
+
`Rotating the key matters most: rewriting history doesn't help if someone already copied it.` +
|
|
107
|
+
leakPlaybook({ usage: usageLink(hit.pattern.id), from: 'history' }),
|
|
101
108
|
};
|
|
102
109
|
}
|
|
@@ -22,3 +22,29 @@ export declare function shellQuote(value: string): string;
|
|
|
22
22
|
export declare function preCommitBlock(projectDir: string): string;
|
|
23
23
|
/** Set up the Claude Code hook, the Cursor hook and the git pre-commit hook. Existing files are merged into, never replaced. */
|
|
24
24
|
export declare function setupHooks(root: string): HookSetupResult;
|
|
25
|
+
export interface HookChange {
|
|
26
|
+
file: string;
|
|
27
|
+
/** The lines that change, before and after. */
|
|
28
|
+
before: string[];
|
|
29
|
+
after: string[];
|
|
30
|
+
/** The new file contents (written by upgradeHooks unless dryRun). */
|
|
31
|
+
text: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HookUpgradeResult {
|
|
34
|
+
changed: HookChange[];
|
|
35
|
+
/** [file, package spec] already on the current version. */
|
|
36
|
+
current: [string, string][];
|
|
37
|
+
/** Files whose launch-doctor hook has no version: it runs the newest release, so it is reported, not rewritten. */
|
|
38
|
+
unpinned: string[];
|
|
39
|
+
/** [file, why] for files with no launch-doctor hook, or that could not be read. */
|
|
40
|
+
skipped: [string, string][];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* `init --hooks --upgrade`: move the hooks that init --hooks installed onto this version's package spec
|
|
44
|
+
* (launch-doctor@^0.4.0 becomes launch-doctor@^0.5.0, say). Only the launch-doctor command changes: other hooks,
|
|
45
|
+
* other settings and the files' formatting are left alone. Hooks installed without a version are reported, not
|
|
46
|
+
* rewritten. With dryRun, nothing is written.
|
|
47
|
+
*/
|
|
48
|
+
export declare function upgradeHooks(root: string, { dryRun }?: {
|
|
49
|
+
dryRun?: boolean | undefined;
|
|
50
|
+
}): HookUpgradeResult;
|
package/dist/src/hooks-setup.js
CHANGED
|
@@ -47,7 +47,9 @@ function writeJson(path, data) {
|
|
|
47
47
|
* Does this hook list already run a launch-doctor hook command? Any version counts, including the unpinned commands
|
|
48
48
|
* older releases wrote: re-running init never adds a second hook, and never rewrites one the user already has.
|
|
49
49
|
*/
|
|
50
|
-
const hasOurCommand = (entries, tool) =>
|
|
50
|
+
const hasOurCommand = (entries, tool) => ourCommand(tool).test(JSON.stringify(entries ?? null));
|
|
51
|
+
/** A launch-doctor hook command for this tool, pinned or not, as it appears in JSON text (quotes escaped). */
|
|
52
|
+
const ourCommand = (tool) => new RegExp(String.raw `\blaunch-doctor(?:@[^\s"\\]+)?\\?"? hook ${tool}\b`);
|
|
51
53
|
/** .claude/settings.json: a PostToolUse hook that checks every file Claude Code writes or edits. */
|
|
52
54
|
function setupClaude(root, result) {
|
|
53
55
|
const rel = '.claude/settings.json';
|
|
@@ -185,3 +187,115 @@ export function setupHooks(root) {
|
|
|
185
187
|
setupPreCommit(root, result);
|
|
186
188
|
return result;
|
|
187
189
|
}
|
|
190
|
+
/** A pinned package spec as init --hooks writes it: launch-doctor@^0.4.0 */
|
|
191
|
+
const PINNED_SPEC = /launch-doctor@\^\d+\.\d+\.\d+/g;
|
|
192
|
+
/**
|
|
193
|
+
* Upgrade one file: replace the pinned package spec on the lines `isOurs` accepts. Every other line, and the
|
|
194
|
+
* file's formatting, stays exactly as it was.
|
|
195
|
+
*/
|
|
196
|
+
function upgradeText(file, text, isOurs, result) {
|
|
197
|
+
const target = pinnedPackage();
|
|
198
|
+
const lines = text.split('\n');
|
|
199
|
+
const before = [];
|
|
200
|
+
const after = [];
|
|
201
|
+
let ours = 0;
|
|
202
|
+
let pinned = 0;
|
|
203
|
+
const out = lines.map((line, i) => {
|
|
204
|
+
if (!isOurs(line, i))
|
|
205
|
+
return line;
|
|
206
|
+
ours++;
|
|
207
|
+
if (!PINNED_SPEC.test(line))
|
|
208
|
+
return line;
|
|
209
|
+
PINNED_SPEC.lastIndex = 0;
|
|
210
|
+
pinned++;
|
|
211
|
+
const next = line.replace(PINNED_SPEC, target);
|
|
212
|
+
if (next !== line) {
|
|
213
|
+
before.push(line.trim());
|
|
214
|
+
after.push(next.trim());
|
|
215
|
+
}
|
|
216
|
+
return next;
|
|
217
|
+
});
|
|
218
|
+
if (!ours) {
|
|
219
|
+
result.skipped.push([file, 'no launch-doctor hook in it']);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
if (pinned < ours)
|
|
223
|
+
result.unpinned.push(file);
|
|
224
|
+
if (!before.length) {
|
|
225
|
+
if (pinned)
|
|
226
|
+
result.current.push([file, target]);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return { file, before, after, text: out.join('\n') };
|
|
230
|
+
}
|
|
231
|
+
/** The text of a hook file, or a reason it was skipped. */
|
|
232
|
+
function readHookFile(path, rel, result) {
|
|
233
|
+
const kind = entryKind(path);
|
|
234
|
+
if (kind === 'missing') {
|
|
235
|
+
result.skipped.push([rel, 'not found']);
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const text = kind === 'file' ? readRegularFile(path, CONFIG_FILE_MAX_BYTES) : null;
|
|
239
|
+
if (text === null)
|
|
240
|
+
result.skipped.push([rel, SPECIAL]);
|
|
241
|
+
return text;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* `init --hooks --upgrade`: move the hooks that init --hooks installed onto this version's package spec
|
|
245
|
+
* (launch-doctor@^0.4.0 becomes launch-doctor@^0.5.0, say). Only the launch-doctor command changes: other hooks,
|
|
246
|
+
* other settings and the files' formatting are left alone. Hooks installed without a version are reported, not
|
|
247
|
+
* rewritten. With dryRun, nothing is written.
|
|
248
|
+
*/
|
|
249
|
+
export function upgradeHooks(root, { dryRun = false } = {}) {
|
|
250
|
+
const result = { changed: [], current: [], unpinned: [], skipped: [] };
|
|
251
|
+
const changes = [];
|
|
252
|
+
for (const [rel, tool] of [
|
|
253
|
+
['.claude/settings.json', 'claude'],
|
|
254
|
+
['.cursor/hooks.json', 'cursor'],
|
|
255
|
+
]) {
|
|
256
|
+
const path = join(root, rel);
|
|
257
|
+
const text = readHookFile(path, rel, result);
|
|
258
|
+
if (text === null)
|
|
259
|
+
continue;
|
|
260
|
+
// A JSON line holding our hook command: "command": "npx --yes \"launch-doctor@^0.4.0\" hook claude"
|
|
261
|
+
const ours = ourCommand(tool);
|
|
262
|
+
const change = upgradeText(rel, text, (line) => ours.test(line), result);
|
|
263
|
+
if (!change)
|
|
264
|
+
continue;
|
|
265
|
+
try {
|
|
266
|
+
JSON.parse(change.text);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
result.skipped.push([rel, 'the upgraded file would not be valid JSON, so it was left alone']);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
changes.push([path, change]);
|
|
273
|
+
}
|
|
274
|
+
const gitRoot = findGitRoot(root);
|
|
275
|
+
const hooksPath = gitRoot ? gitHooksDir(root) : null;
|
|
276
|
+
if (!hooksPath) {
|
|
277
|
+
result.skipped.push(['pre-commit hook', gitRoot ? "couldn't find the git hooks folder" : 'not a git repository']);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
const path = resolve(root, hooksPath, 'pre-commit');
|
|
281
|
+
const shown = relative(root, path).replace(/\\/g, '/');
|
|
282
|
+
const rel = shown.startsWith('..') || isAbsolute(shown) ? path : shown;
|
|
283
|
+
const text = readHookFile(path, rel, result);
|
|
284
|
+
if (text !== null) {
|
|
285
|
+
// Only the lines inside the block init --hooks added.
|
|
286
|
+
const lines = text.split('\n');
|
|
287
|
+
const start = lines.findIndex((l) => l.includes(MARK_START));
|
|
288
|
+
const end = lines.findIndex((l, i) => i > start && l.includes(MARK_END));
|
|
289
|
+
const inBlock = (line, i) => start >= 0 && end > start && i > start && i < end && /\bnpx\b.*\blaunch-doctor\b/.test(line);
|
|
290
|
+
const change = upgradeText(rel, text, inBlock, result);
|
|
291
|
+
if (change)
|
|
292
|
+
changes.push([path, change]);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
for (const [path, change] of changes) {
|
|
296
|
+
if (!dryRun)
|
|
297
|
+
writeRegularFile(path, change.text);
|
|
298
|
+
result.changed.push(change);
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyBaseline, fingerprint, loadBaseline } from './baseline.js';
|
|
1
|
+
import { applyBaseline, assignRefs, fingerprint, lineContext, loadBaseline } from './baseline.js';
|
|
2
2
|
import { accessCheck } from './checks/access.js';
|
|
3
3
|
import { costsCheck } from './checks/costs.js';
|
|
4
4
|
import { databaseCheck } from './checks/database.js';
|
|
@@ -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);
|
|
@@ -139,6 +140,7 @@ export async function runDoctor(root, options = {}) {
|
|
|
139
140
|
for (const c of categories)
|
|
140
141
|
for (const f of c.findings)
|
|
141
142
|
f.fingerprint = fingerprint(ctx, f);
|
|
143
|
+
assignRefs(categories.flatMap((c) => c.findings), (f) => lineContext(ctx, f));
|
|
142
144
|
const summary = overall(categories);
|
|
143
145
|
const knownIds = new Set(CHECKS.flatMap((c) => c.ids));
|
|
144
146
|
const unknownIgnoreIds = [...ctx.ignoredIds].filter((id) => !knownIds.has(id)).sort();
|
|
@@ -157,6 +159,10 @@ export async function runDoctor(root, options = {}) {
|
|
|
157
159
|
...(ctx.nestedRepos.length ? { nestedRepos: ctx.nestedRepos } : {}),
|
|
158
160
|
...(options.onlyFiles ? { partial: { files: options.onlyFiles } } : {}),
|
|
159
161
|
...summary,
|
|
162
|
+
grades: {
|
|
163
|
+
security: groupGrade(categories, GRADE_GROUPS.security),
|
|
164
|
+
launch: groupGrade(categories, GRADE_GROUPS.launch),
|
|
165
|
+
},
|
|
160
166
|
categories,
|
|
161
167
|
generatedAt: new Date().toISOString(),
|
|
162
168
|
};
|
package/dist/src/init.d.ts
CHANGED
|
@@ -37,3 +37,15 @@ export interface InitResult {
|
|
|
37
37
|
export declare function runInit(root: string, { monitor }?: {
|
|
38
38
|
monitor?: boolean | undefined;
|
|
39
39
|
}): InitResult;
|
|
40
|
+
/** The line init adds to .gitignore, so .launchdoctor/ (grades, badge, report.md) is not committed by accident. */
|
|
41
|
+
export declare const GITIGNORE_LINE = ".launchdoctor/";
|
|
42
|
+
/**
|
|
43
|
+
* Add .launchdoctor/ to the project's .gitignore (creating the file if there is none). Returns what happened. A
|
|
44
|
+
* .gitignore that is a link or a special file is left alone, like every file Launch Doctor writes.
|
|
45
|
+
*/
|
|
46
|
+
export declare function ensureGitignore(root: string): 'created' | 'updated' | 'present' | 'skipped';
|
|
47
|
+
/**
|
|
48
|
+
* `init --mcp`: the exact commands and snippets to connect Launch Doctor to Claude Code, Cursor and Claude Desktop.
|
|
49
|
+
* Nothing is written: the user pastes them where they want.
|
|
50
|
+
*/
|
|
51
|
+
export declare function mcpSetupText(root: string, pkg: string): string;
|
package/dist/src/init.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
|
+
import { CONFIG_FILE_MAX_BYTES } from './project.js';
|
|
4
|
+
import { entryKind, readRegularFile, writeRegularFile } from './safe-fs.js';
|
|
3
5
|
import { version } from './version.js';
|
|
4
6
|
/** The same workflow as the README's "CI integration" example. */
|
|
5
7
|
export const WORKFLOW_TEMPLATE = `name: Launch Doctor
|
|
@@ -161,3 +163,56 @@ export function runInit(root, { monitor = false } = {}) {
|
|
|
161
163
|
}
|
|
162
164
|
return result;
|
|
163
165
|
}
|
|
166
|
+
/** The line init adds to .gitignore, so .launchdoctor/ (grades, badge, report.md) is not committed by accident. */
|
|
167
|
+
export const GITIGNORE_LINE = '.launchdoctor/';
|
|
168
|
+
/**
|
|
169
|
+
* Add .launchdoctor/ to the project's .gitignore (creating the file if there is none). Returns what happened. A
|
|
170
|
+
* .gitignore that is a link or a special file is left alone, like every file Launch Doctor writes.
|
|
171
|
+
*/
|
|
172
|
+
export function ensureGitignore(root) {
|
|
173
|
+
const path = join(root, '.gitignore');
|
|
174
|
+
const kind = entryKind(path);
|
|
175
|
+
if (kind === 'missing') {
|
|
176
|
+
writeRegularFile(path, `${GITIGNORE_LINE}\n`);
|
|
177
|
+
return 'created';
|
|
178
|
+
}
|
|
179
|
+
const text = kind === 'file' ? readRegularFile(path, CONFIG_FILE_MAX_BYTES) : null;
|
|
180
|
+
if (text === null)
|
|
181
|
+
return 'skipped';
|
|
182
|
+
if (/^\/?\.launchdoctor\/?\s*$/m.test(text))
|
|
183
|
+
return 'present';
|
|
184
|
+
writeRegularFile(path, `${text}${text === '' || text.endsWith('\n') ? '' : '\n'}${GITIGNORE_LINE}\n`);
|
|
185
|
+
return 'updated';
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* `init --mcp`: the exact commands and snippets to connect Launch Doctor to Claude Code, Cursor and Claude Desktop.
|
|
189
|
+
* Nothing is written: the user pastes them where they want.
|
|
190
|
+
*/
|
|
191
|
+
export function mcpSetupText(root, pkg) {
|
|
192
|
+
const desktopArgs = ['-y', pkg, 'mcp', root];
|
|
193
|
+
const projectArgs = ['-y', pkg, 'mcp'];
|
|
194
|
+
const json = (args) => JSON.stringify({ mcpServers: { 'launch-doctor': { command: 'npx', args } } }, null, 2)
|
|
195
|
+
.split('\n')
|
|
196
|
+
.map((l) => ` ${l}`)
|
|
197
|
+
.join('\n');
|
|
198
|
+
return [
|
|
199
|
+
'',
|
|
200
|
+
' Claude Code (run in this project folder):',
|
|
201
|
+
'',
|
|
202
|
+
` claude mcp add launch-doctor -- npx -y "${pkg}" mcp`,
|
|
203
|
+
'',
|
|
204
|
+
' Cursor: add this to .cursor/mcp.json in this project:',
|
|
205
|
+
'',
|
|
206
|
+
json(projectArgs),
|
|
207
|
+
'',
|
|
208
|
+
' Claude Desktop: add this to claude_desktop_config.json',
|
|
209
|
+
' (macOS: ~/Library/Application Support/Claude/, Windows: %APPDATA%\\Claude\\).',
|
|
210
|
+
' Claude Desktop does not start servers in your project, so the folder is given:',
|
|
211
|
+
'',
|
|
212
|
+
json(desktopArgs),
|
|
213
|
+
'',
|
|
214
|
+
' Then ask: "Scan this app with Launch Doctor", "Explain finding 2", or "Fix the top issue, then rescan".',
|
|
215
|
+
' The server only reads this folder and uses the network only for scan_url. Nothing was written.',
|
|
216
|
+
'',
|
|
217
|
+
].join('\n');
|
|
218
|
+
}
|
package/dist/src/live.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { assignRefs } from './baseline.js';
|
|
1
2
|
import { emptyOutput, notApplicable } from './checks/common.js';
|
|
2
|
-
import { matchKeys } from './checks/secrets.js';
|
|
3
|
+
import { leakPlaybook, matchKeys, usageLink } from './checks/secrets.js';
|
|
3
4
|
import { overall, scoreCategory, toGrade } from './grade.js';
|
|
4
5
|
import { checkHost, defaultLookup } from './net-guard.js';
|
|
5
6
|
import { pinnedGet } from './pinned-http.js';
|
|
@@ -410,7 +411,8 @@ async function exposureCheck(fetcher, home, page) {
|
|
|
410
411
|
`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
412
|
`2. Make sure no NEXT_PUBLIC_/VITE_ variable holds it.\n` +
|
|
412
413
|
`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
|
|
414
|
+
`Then tell me how to revoke this key and create a new one (${m.pattern.rotate}), because it is already public.` +
|
|
415
|
+
leakPlaybook({ usage: usageLink(m.pattern.id), from: 'live' }),
|
|
414
416
|
}));
|
|
415
417
|
}
|
|
416
418
|
}
|
|
@@ -444,7 +446,8 @@ async function databaseCheck(fetcher, page, opts) {
|
|
|
444
446
|
},
|
|
445
447
|
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
448
|
`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
|
|
449
|
+
`and tell me how to rotate the JWT secret / service_role key in Supabase, because it is already public.` +
|
|
450
|
+
leakPlaybook({ usage: usageLink('supabase-service-role-key'), from: 'live' }),
|
|
448
451
|
}));
|
|
449
452
|
}
|
|
450
453
|
else if (role === 'anon' && !anonKeys.includes(m[0]))
|
|
@@ -578,6 +581,8 @@ export async function runLiveScan(input, options = {}) {
|
|
|
578
581
|
const hosts = [...new Set(fetcher.blocked.map((b) => b.split(' ')[0]))].slice(0, 3).join(', ');
|
|
579
582
|
categories[0].passed.push(`Skipped ${plural(fetcher.blocked.length, 'request')} to private or local network addresses (${hosts}) that this public site pointed to`);
|
|
580
583
|
}
|
|
584
|
+
// No lines in a live scan: a finding is told apart by its rule and the URL it is about.
|
|
585
|
+
assignRefs(categories.flatMap((c) => c.findings), () => '');
|
|
581
586
|
// Text from the site (table names, paths) can hold terminal escape sequences; none reach any output.
|
|
582
587
|
return sanitizeReport({
|
|
583
588
|
tool: 'launch-doctor',
|
package/dist/src/mcp.d.ts
CHANGED
|
@@ -4,9 +4,16 @@ import type { Report } from './types.js';
|
|
|
4
4
|
* A Model Context Protocol server over stdio, so AI coding tools (Claude Code, Cursor, ...)
|
|
5
5
|
* can run Launch Doctor themselves. One JSON-RPC 2.0 message per line on stdin and stdout.
|
|
6
6
|
* Nothing else may be written to stdout: it is the protocol channel.
|
|
7
|
+
*
|
|
8
|
+
* Every tool goes through the shared core (src/core.ts), like the CLI. The server only reads the project: it
|
|
9
|
+
* writes nothing, and it makes no network request except for scan_url, with the address the caller gives.
|
|
7
10
|
*/
|
|
8
11
|
/** Protocol versions this server speaks, newest first. */
|
|
9
12
|
export declare const PROTOCOL_VERSIONS: string[];
|
|
13
|
+
/** Findings listed in a scan result; the rest are counted. Each entry is one line, so this caps the size. */
|
|
14
|
+
export declare const MAX_LISTED = 25;
|
|
15
|
+
/** The most text one tool result may hold, so a big app can't flood the model's context. */
|
|
16
|
+
export declare const MAX_TEXT = 12000;
|
|
10
17
|
interface ToolResult {
|
|
11
18
|
content: {
|
|
12
19
|
type: 'text';
|
|
@@ -47,15 +54,119 @@ export declare function mcpTools(): ({
|
|
|
47
54
|
type: string;
|
|
48
55
|
description: string;
|
|
49
56
|
};
|
|
50
|
-
|
|
57
|
+
history: {
|
|
51
58
|
type: string;
|
|
52
59
|
description: string;
|
|
53
60
|
};
|
|
54
|
-
|
|
61
|
+
includeBaseline: {
|
|
55
62
|
type: string;
|
|
56
63
|
description: string;
|
|
57
64
|
};
|
|
58
|
-
|
|
65
|
+
id?: undefined;
|
|
66
|
+
ids?: undefined;
|
|
67
|
+
paths?: undefined;
|
|
68
|
+
url?: undefined;
|
|
69
|
+
skipDatabase?: undefined;
|
|
70
|
+
};
|
|
71
|
+
additionalProperties: boolean;
|
|
72
|
+
required?: undefined;
|
|
73
|
+
};
|
|
74
|
+
annotations: {
|
|
75
|
+
readOnlyHint: boolean;
|
|
76
|
+
idempotentHint: boolean;
|
|
77
|
+
openWorldHint: boolean;
|
|
78
|
+
};
|
|
79
|
+
} | {
|
|
80
|
+
name: string;
|
|
81
|
+
title: string;
|
|
82
|
+
description: string;
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: string;
|
|
85
|
+
properties: {
|
|
86
|
+
only?: undefined;
|
|
87
|
+
skip?: undefined;
|
|
88
|
+
offline?: undefined;
|
|
89
|
+
history?: undefined;
|
|
90
|
+
includeBaseline?: undefined;
|
|
91
|
+
id: {
|
|
92
|
+
type: string;
|
|
93
|
+
description: string;
|
|
94
|
+
};
|
|
95
|
+
path: {
|
|
96
|
+
type: string;
|
|
97
|
+
description: string;
|
|
98
|
+
};
|
|
99
|
+
ids?: undefined;
|
|
100
|
+
paths?: undefined;
|
|
101
|
+
url?: undefined;
|
|
102
|
+
skipDatabase?: undefined;
|
|
103
|
+
};
|
|
104
|
+
required: string[];
|
|
105
|
+
additionalProperties: boolean;
|
|
106
|
+
};
|
|
107
|
+
annotations: {
|
|
108
|
+
readOnlyHint: boolean;
|
|
109
|
+
idempotentHint: boolean;
|
|
110
|
+
openWorldHint: boolean;
|
|
111
|
+
};
|
|
112
|
+
} | {
|
|
113
|
+
name: string;
|
|
114
|
+
title: string;
|
|
115
|
+
description: string;
|
|
116
|
+
inputSchema: {
|
|
117
|
+
type: string;
|
|
118
|
+
properties: {
|
|
119
|
+
only?: undefined;
|
|
120
|
+
skip?: undefined;
|
|
121
|
+
offline?: undefined;
|
|
122
|
+
history?: undefined;
|
|
123
|
+
includeBaseline?: undefined;
|
|
124
|
+
id?: undefined;
|
|
125
|
+
path: {
|
|
126
|
+
type: string;
|
|
127
|
+
description: string;
|
|
128
|
+
};
|
|
129
|
+
ids: {
|
|
130
|
+
type: string;
|
|
131
|
+
items: {
|
|
132
|
+
type: string;
|
|
133
|
+
};
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
paths: {
|
|
137
|
+
type: string;
|
|
138
|
+
items: {
|
|
139
|
+
type: string;
|
|
140
|
+
};
|
|
141
|
+
description: string;
|
|
142
|
+
};
|
|
143
|
+
url?: undefined;
|
|
144
|
+
skipDatabase?: undefined;
|
|
145
|
+
};
|
|
146
|
+
additionalProperties: boolean;
|
|
147
|
+
required?: undefined;
|
|
148
|
+
};
|
|
149
|
+
annotations: {
|
|
150
|
+
readOnlyHint: boolean;
|
|
151
|
+
idempotentHint: boolean;
|
|
152
|
+
openWorldHint: boolean;
|
|
153
|
+
};
|
|
154
|
+
} | {
|
|
155
|
+
name: string;
|
|
156
|
+
title: string;
|
|
157
|
+
description: string;
|
|
158
|
+
inputSchema: {
|
|
159
|
+
type: string;
|
|
160
|
+
properties: {
|
|
161
|
+
only?: undefined;
|
|
162
|
+
skip?: undefined;
|
|
163
|
+
offline?: undefined;
|
|
164
|
+
history?: undefined;
|
|
165
|
+
includeBaseline?: undefined;
|
|
166
|
+
id?: undefined;
|
|
167
|
+
ids?: undefined;
|
|
168
|
+
paths?: undefined;
|
|
169
|
+
path: {
|
|
59
170
|
type: string;
|
|
60
171
|
description: string;
|
|
61
172
|
};
|
|
@@ -77,13 +188,15 @@ export declare function mcpTools(): ({
|
|
|
77
188
|
inputSchema: {
|
|
78
189
|
type: string;
|
|
79
190
|
properties: {
|
|
80
|
-
path?: undefined;
|
|
81
191
|
only?: undefined;
|
|
82
192
|
skip?: undefined;
|
|
83
193
|
offline?: undefined;
|
|
84
|
-
domain?: undefined;
|
|
85
194
|
history?: undefined;
|
|
86
195
|
includeBaseline?: undefined;
|
|
196
|
+
id?: undefined;
|
|
197
|
+
ids?: undefined;
|
|
198
|
+
paths?: undefined;
|
|
199
|
+
path?: undefined;
|
|
87
200
|
url: {
|
|
88
201
|
type: string;
|
|
89
202
|
description: string;
|
|
@@ -109,13 +222,15 @@ export declare function mcpTools(): ({
|
|
|
109
222
|
required?: undefined;
|
|
110
223
|
type: string;
|
|
111
224
|
properties: {
|
|
112
|
-
path?: undefined;
|
|
113
225
|
only?: undefined;
|
|
114
226
|
skip?: undefined;
|
|
115
227
|
offline?: undefined;
|
|
116
|
-
domain?: undefined;
|
|
117
228
|
history?: undefined;
|
|
118
229
|
includeBaseline?: undefined;
|
|
230
|
+
id?: undefined;
|
|
231
|
+
ids?: undefined;
|
|
232
|
+
paths?: undefined;
|
|
233
|
+
path?: undefined;
|
|
119
234
|
url?: undefined;
|
|
120
235
|
skipDatabase?: undefined;
|
|
121
236
|
};
|
|
@@ -127,10 +242,10 @@ export declare function mcpTools(): ({
|
|
|
127
242
|
openWorldHint: boolean;
|
|
128
243
|
};
|
|
129
244
|
})[];
|
|
130
|
-
/**
|
|
131
|
-
export declare function
|
|
132
|
-
/**
|
|
133
|
-
export declare function
|
|
245
|
+
/** Text for the model: control characters removed, and cut at MAX_TEXT with a note. */
|
|
246
|
+
export declare function capText(text: string, max?: number): string;
|
|
247
|
+
/** A scan as a short summary (text) and data, with at most MAX_LISTED findings. */
|
|
248
|
+
export declare function scanResult(report: Report, includeBaseline?: boolean, extra?: string[]): ToolResult;
|
|
134
249
|
/** Run one tool. Unknown tool names are a protocol error; bad arguments are a tool error the model can fix. */
|
|
135
250
|
export declare function callTool(name: unknown, args: unknown, cwd?: string): Promise<ToolResult>;
|
|
136
251
|
/** Handle one parsed message (or a batch). Returns what to send back, or null for nothing. */
|