launch-doctor 0.2.1 → 0.3.0
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 +31 -1
- package/README.md +155 -30
- package/dist/src/checks/costs.d.ts +1 -0
- package/dist/src/checks/costs.js +40 -5
- package/dist/src/checks/database.js +122 -3
- package/dist/src/checks/first-impressions.js +227 -117
- package/dist/src/checks/legal.js +27 -13
- package/dist/src/checks/monitoring.js +39 -10
- package/dist/src/checks/payments.js +131 -4
- package/dist/src/checks/secrets.js +103 -7
- package/dist/src/cli.js +90 -3
- package/dist/src/demo.d.ts +13 -0
- package/dist/src/demo.js +58 -2
- package/dist/src/detect.js +4 -1
- package/dist/src/fixes.js +2 -2
- package/dist/src/github.d.ts +80 -0
- package/dist/src/github.js +288 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/init.d.ts +1 -1
- package/dist/src/init.js +2 -2
- package/dist/src/mcp.d.ts +140 -0
- package/dist/src/mcp.js +381 -0
- package/dist/src/project.d.ts +8 -0
- package/dist/src/project.js +102 -6
- package/dist/src/report.d.ts +2 -0
- package/dist/src/report.js +12 -1
- package/dist/src/summary.d.ts +3 -0
- package/dist/src/summary.js +17 -13
- package/dist/src/types.d.ts +2 -0
- package/dist/src/util.d.ts +2 -0
- package/dist/src/util.js +2 -0
- package/package.json +2 -2
package/dist/src/mcp.js
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
import { shortWhere } from './checks/common.js';
|
|
5
|
+
import { DEFAULT_HISTORY_DEPTH } from './history.js';
|
|
6
|
+
import { CHECKS, runDoctor } from './index.js';
|
|
7
|
+
import { runLiveScan } from './live.js';
|
|
8
|
+
import { nestedReposNote } from './report.js';
|
|
9
|
+
import { plural } from './util.js';
|
|
10
|
+
import { version } from './version.js';
|
|
11
|
+
/**
|
|
12
|
+
* A Model Context Protocol server over stdio, so AI coding tools (Claude Code, Cursor, ...)
|
|
13
|
+
* can run Launch Doctor themselves. One JSON-RPC 2.0 message per line on stdin and stdout.
|
|
14
|
+
* Nothing else may be written to stdout: it is the protocol channel.
|
|
15
|
+
*/
|
|
16
|
+
/** Protocol versions this server speaks, newest first. */
|
|
17
|
+
export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
18
|
+
/** Offered when a client asks for a version this server doesn't know. */
|
|
19
|
+
const DEFAULT_PROTOCOL = '2025-06-18';
|
|
20
|
+
/** Findings and checklist items listed per section in a tool result. */
|
|
21
|
+
const MAX_LISTED = 50;
|
|
22
|
+
class RpcError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
constructor(code, message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const UNKNOWN_METHOD = Symbol('unknown method');
|
|
30
|
+
/** The tools this server offers, with JSON Schemas for their arguments. */
|
|
31
|
+
export function mcpTools() {
|
|
32
|
+
const categories = CHECKS.map((c) => c.id);
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
name: 'scan_project',
|
|
36
|
+
title: 'Check a project before launch',
|
|
37
|
+
description: 'Runs Launch Doctor on a project folder and grades it A to F on secrets and API keys, database safety, payments, AI and API costs, email delivery, error tracking, legal pages and first impressions. ' +
|
|
38
|
+
'Returns every problem with its file and line, why it matters, and a fix prompt that describes the change to make, plus a checklist of things to verify outside the code. It only reads files.',
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
path: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
description: 'Project folder to check: absolute, or relative to the folder the server started in (the default).',
|
|
45
|
+
},
|
|
46
|
+
only: {
|
|
47
|
+
type: 'array',
|
|
48
|
+
items: { type: 'string', enum: categories },
|
|
49
|
+
description: 'Check only these categories.',
|
|
50
|
+
},
|
|
51
|
+
skip: {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: { type: 'string', enum: categories },
|
|
54
|
+
description: 'Leave out these categories.',
|
|
55
|
+
},
|
|
56
|
+
offline: {
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
description: 'Skip the email DNS lookups (SPF, DKIM, DMARC). Default false.',
|
|
59
|
+
},
|
|
60
|
+
domain: { type: 'string', description: "Domain the app sends email from, if the code doesn't show it." },
|
|
61
|
+
history: {
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
description: 'Also look for API keys that are still in git history. Slower. Default false.',
|
|
64
|
+
},
|
|
65
|
+
includeBaseline: {
|
|
66
|
+
type: 'boolean',
|
|
67
|
+
description: 'Also list findings accepted in .launchdoctor-baseline.json. Default false.',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
additionalProperties: false,
|
|
71
|
+
},
|
|
72
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'scan_url',
|
|
76
|
+
title: 'Check a deployed site',
|
|
77
|
+
description: 'Checks a live website from the outside, the way an attacker would: downloadable .env, .git and backup files, public source maps, API keys in the JavaScript, Supabase tables readable with the public key, and HTTPS and security headers. ' +
|
|
78
|
+
'Sends ordinary GET requests only.',
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
url: { type: 'string', description: 'The site to check, for example https://myapp.com.' },
|
|
83
|
+
skipDatabase: {
|
|
84
|
+
type: 'boolean',
|
|
85
|
+
description: "Don't test Supabase tables with the public key found in the page. Default false.",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
required: ['url'],
|
|
89
|
+
additionalProperties: false,
|
|
90
|
+
},
|
|
91
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'list_checks',
|
|
95
|
+
title: 'List the checks',
|
|
96
|
+
description: 'Lists the categories and every finding and checklist id, for the only and skip options and for .launchdoctorignore.',
|
|
97
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
98
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false },
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
// ---------- tool results ----------
|
|
103
|
+
function indent(text, by = ' ') {
|
|
104
|
+
return text
|
|
105
|
+
.split('\n')
|
|
106
|
+
.map((l) => (l ? by + l : l))
|
|
107
|
+
.join('\n');
|
|
108
|
+
}
|
|
109
|
+
function findingEntry(n, f) {
|
|
110
|
+
const where = f.location ? ` (${shortWhere(f.location)})` : '';
|
|
111
|
+
const known = f.baseline ? ' [in baseline]' : '';
|
|
112
|
+
return [
|
|
113
|
+
`${n}. ${f.title}${where} · id: ${f.id}${known}`,
|
|
114
|
+
indent(`Why it matters: ${f.why}`),
|
|
115
|
+
indent(`Fix prompt:\n${indent(f.fixPrompt, ' ')}`),
|
|
116
|
+
].join('\n');
|
|
117
|
+
}
|
|
118
|
+
function listSection(title, items, entry) {
|
|
119
|
+
if (!items.length)
|
|
120
|
+
return [];
|
|
121
|
+
const out = ['', `${title} (${items.length})`, ''];
|
|
122
|
+
for (const [i, item] of items.slice(0, MAX_LISTED).entries())
|
|
123
|
+
out.push(entry(item, i + 1));
|
|
124
|
+
if (items.length > MAX_LISTED)
|
|
125
|
+
out.push(`...and ${items.length - MAX_LISTED} more.`);
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/** Plain-text summary of a report, written for an AI assistant that will act on it. */
|
|
129
|
+
export function reportText(report, includeBaseline = false) {
|
|
130
|
+
const all = report.categories.flatMap((c) => c.findings);
|
|
131
|
+
const shown = includeBaseline ? all : all.filter((f) => !f.baseline);
|
|
132
|
+
const hiddenBaseline = all.length - shown.length;
|
|
133
|
+
const manual = report.categories.flatMap((c) => c.manual);
|
|
134
|
+
const unit = report.mode === 'live' ? 'request' : 'file';
|
|
135
|
+
const lines = [
|
|
136
|
+
`Launch Doctor ${report.version}: grade ${report.grade} (${report.score}/100) for ${report.projectName}. ${plural(report.filesScanned, unit)} checked.`,
|
|
137
|
+
report.verdict,
|
|
138
|
+
];
|
|
139
|
+
if (report.nestedRepos?.length)
|
|
140
|
+
lines.push(nestedReposNote(report.nestedRepos));
|
|
141
|
+
if (report.truncated)
|
|
142
|
+
lines.push('Very large project: only the first 20,000 files were checked.');
|
|
143
|
+
lines.push(...listSection('Critical', shown.filter((f) => f.severity === 'critical'), (f, n) => findingEntry(n, f)), ...listSection('Warnings', shown.filter((f) => f.severity === 'warning'), (f, n) => findingEntry(n, f)), ...listSection('Check by hand, outside the code', manual, (m, n) => `${n}. ${m.title} · id: ${m.id}\n${indent(m.how)}`));
|
|
144
|
+
if (!shown.length) {
|
|
145
|
+
lines.push('', hiddenBaseline
|
|
146
|
+
? `No new problems found. The grade still counts the ${plural(hiddenBaseline, 'known finding')} accepted in .launchdoctor-baseline.json.`
|
|
147
|
+
: 'No problems found.');
|
|
148
|
+
}
|
|
149
|
+
lines.push('', `Scorecard: ${report.categories.map((c) => `${c.name} ${c.skipped ? 'skipped' : c.applicable ? (c.grade ?? '-') : 'not used'}`).join(' · ')}`);
|
|
150
|
+
if (hiddenBaseline) {
|
|
151
|
+
lines.push(`${plural(hiddenBaseline, 'known finding')} in .launchdoctor-baseline.json not listed (set includeBaseline to see them).`);
|
|
152
|
+
}
|
|
153
|
+
if (report.ignored) {
|
|
154
|
+
lines.push(`${plural(report.ignored, 'item')} silenced by .launchdoctorignore or launch-doctor-ignore comments.`);
|
|
155
|
+
}
|
|
156
|
+
return lines.join('\n');
|
|
157
|
+
}
|
|
158
|
+
/** The same report as data, for clients that read structured tool output. */
|
|
159
|
+
export function reportData(report, includeBaseline = false) {
|
|
160
|
+
return {
|
|
161
|
+
grade: report.grade,
|
|
162
|
+
score: report.score,
|
|
163
|
+
verdict: report.verdict,
|
|
164
|
+
projectName: report.projectName,
|
|
165
|
+
counts: report.counts,
|
|
166
|
+
...(report.nestedRepos?.length ? { nestedRepos: report.nestedRepos } : {}),
|
|
167
|
+
categories: report.categories.map((c) => ({
|
|
168
|
+
id: c.id,
|
|
169
|
+
name: c.name,
|
|
170
|
+
grade: c.grade,
|
|
171
|
+
applicable: c.applicable,
|
|
172
|
+
skipped: Boolean(c.skipped),
|
|
173
|
+
})),
|
|
174
|
+
findings: report.categories.flatMap((c) => c.findings
|
|
175
|
+
.filter((f) => includeBaseline || !f.baseline)
|
|
176
|
+
.map((f) => ({
|
|
177
|
+
id: f.id,
|
|
178
|
+
category: c.id,
|
|
179
|
+
severity: f.severity,
|
|
180
|
+
title: f.title,
|
|
181
|
+
file: f.location?.file,
|
|
182
|
+
line: f.location?.line,
|
|
183
|
+
why: f.why,
|
|
184
|
+
fixPrompt: f.fixPrompt,
|
|
185
|
+
baseline: Boolean(f.baseline),
|
|
186
|
+
}))),
|
|
187
|
+
manual: report.categories.flatMap((c) => c.manual.map((m) => ({ id: m.id, category: c.id, title: m.title, how: m.how }))),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function toolError(message) {
|
|
191
|
+
return { content: [{ type: 'text', text: message }], isError: true };
|
|
192
|
+
}
|
|
193
|
+
function reportResult(report, includeBaseline) {
|
|
194
|
+
return {
|
|
195
|
+
content: [{ type: 'text', text: reportText(report, includeBaseline) }],
|
|
196
|
+
structuredContent: reportData(report, includeBaseline),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === 'string');
|
|
200
|
+
/** Checks the arguments by hand (no schema library), so a bad call gets a message the model can act on. */
|
|
201
|
+
function badArgs(args, shape) {
|
|
202
|
+
for (const key of Object.keys(args))
|
|
203
|
+
if (!(key in shape))
|
|
204
|
+
return `Unknown argument "${key}".`;
|
|
205
|
+
for (const [key, type] of Object.entries(shape)) {
|
|
206
|
+
const v = args[key];
|
|
207
|
+
if (v === undefined)
|
|
208
|
+
continue;
|
|
209
|
+
const ok = type === 'string[]' ? isStringArray(v) : typeof v === type;
|
|
210
|
+
if (!ok)
|
|
211
|
+
return `"${key}" must be ${type === 'string[]' ? 'a list of strings' : `a ${type}`}.`;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
async function scanProject(args, cwd) {
|
|
216
|
+
const problem = badArgs(args, {
|
|
217
|
+
path: 'string',
|
|
218
|
+
only: 'string[]',
|
|
219
|
+
skip: 'string[]',
|
|
220
|
+
offline: 'boolean',
|
|
221
|
+
domain: 'string',
|
|
222
|
+
history: 'boolean',
|
|
223
|
+
includeBaseline: 'boolean',
|
|
224
|
+
});
|
|
225
|
+
if (problem)
|
|
226
|
+
return toolError(problem);
|
|
227
|
+
const root = resolve(cwd, args.path ?? '.');
|
|
228
|
+
if (!existsSync(root) || !statSync(root).isDirectory())
|
|
229
|
+
return toolError(`Folder not found: ${root}`);
|
|
230
|
+
const domain = args.domain
|
|
231
|
+
?.trim()
|
|
232
|
+
.toLowerCase()
|
|
233
|
+
.replace(/^https?:\/\//, '')
|
|
234
|
+
.replace(/[/?#].*$/, '');
|
|
235
|
+
let report;
|
|
236
|
+
try {
|
|
237
|
+
report = await runDoctor(root, {
|
|
238
|
+
offline: args.offline === true,
|
|
239
|
+
domain: domain || undefined,
|
|
240
|
+
only: args.only,
|
|
241
|
+
skip: args.skip,
|
|
242
|
+
history: args.history === true ? { depth: DEFAULT_HISTORY_DEPTH } : undefined,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
return toolError(err.message);
|
|
247
|
+
}
|
|
248
|
+
if (report.filesScanned === 0)
|
|
249
|
+
return toolError(`No project files found in ${root}.`);
|
|
250
|
+
return reportResult(report, args.includeBaseline === true);
|
|
251
|
+
}
|
|
252
|
+
async function scanUrl(args) {
|
|
253
|
+
const problem = badArgs(args, { url: 'string', skipDatabase: 'boolean' });
|
|
254
|
+
if (problem)
|
|
255
|
+
return toolError(problem);
|
|
256
|
+
if (typeof args.url !== 'string' || !args.url.trim())
|
|
257
|
+
return toolError('"url" is required, for example https://myapp.com.');
|
|
258
|
+
try {
|
|
259
|
+
return reportResult(await runLiveScan(args.url, { skipDatabase: args.skipDatabase === true }), false);
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
return toolError(err.message);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function listChecks() {
|
|
266
|
+
const categories = CHECKS.map((c) => ({ id: c.id, name: c.name, ids: [...c.ids] }));
|
|
267
|
+
const text = categories.map((c) => `${c.id} (${c.name}): ${c.ids.join(', ')}`).join('\n');
|
|
268
|
+
return { content: [{ type: 'text', text }], structuredContent: { categories } };
|
|
269
|
+
}
|
|
270
|
+
/** Run one tool. Unknown tool names are a protocol error; bad arguments are a tool error the model can fix. */
|
|
271
|
+
export async function callTool(name, args, cwd = process.cwd()) {
|
|
272
|
+
const a = args === undefined || args === null ? {} : args;
|
|
273
|
+
if (typeof a !== 'object' || Array.isArray(a))
|
|
274
|
+
return toolError('Arguments must be an object.');
|
|
275
|
+
const params = a;
|
|
276
|
+
if (name === 'scan_project')
|
|
277
|
+
return scanProject(params, cwd);
|
|
278
|
+
if (name === 'scan_url')
|
|
279
|
+
return scanUrl(params);
|
|
280
|
+
if (name === 'list_checks')
|
|
281
|
+
return listChecks();
|
|
282
|
+
throw new RpcError(-32602, `Unknown tool: ${String(name)}`);
|
|
283
|
+
}
|
|
284
|
+
// ---------- JSON-RPC ----------
|
|
285
|
+
function negotiate(params) {
|
|
286
|
+
const asked = params.protocolVersion;
|
|
287
|
+
const protocolVersion = typeof asked === 'string' && PROTOCOL_VERSIONS.includes(asked) ? asked : DEFAULT_PROTOCOL;
|
|
288
|
+
return {
|
|
289
|
+
protocolVersion,
|
|
290
|
+
capabilities: { tools: { listChanged: false } },
|
|
291
|
+
serverInfo: { name: 'launch-doctor', title: 'Launch Doctor', version: version() },
|
|
292
|
+
instructions: 'Use scan_project before a launch or a big release to find leaked keys, open databases, unverified payment webhooks, unprotected AI endpoints and missing legal pages. ' +
|
|
293
|
+
'Each finding has a fix prompt: apply fixes one at a time, critical first, then run scan_project again. Use scan_url on the deployed site after deploying.',
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
async function dispatch(method, params, cwd) {
|
|
297
|
+
switch (method) {
|
|
298
|
+
case 'initialize':
|
|
299
|
+
return negotiate(params);
|
|
300
|
+
case 'ping':
|
|
301
|
+
return {};
|
|
302
|
+
case 'tools/list':
|
|
303
|
+
return { tools: mcpTools() };
|
|
304
|
+
case 'tools/call':
|
|
305
|
+
return callTool(params.name, params.arguments, cwd);
|
|
306
|
+
default:
|
|
307
|
+
return UNKNOWN_METHOD;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const rpcError = (id, code, message) => ({
|
|
311
|
+
jsonrpc: '2.0',
|
|
312
|
+
id,
|
|
313
|
+
error: { code, message },
|
|
314
|
+
});
|
|
315
|
+
async function handleOne(msg, cwd) {
|
|
316
|
+
if (!msg || typeof msg !== 'object' || Array.isArray(msg))
|
|
317
|
+
return rpcError(null, -32600, 'Invalid Request');
|
|
318
|
+
const { id, method, params } = msg;
|
|
319
|
+
// A message without an id is a notification (like notifications/initialized): never answered.
|
|
320
|
+
const notification = id === undefined;
|
|
321
|
+
const replyId = id ?? null;
|
|
322
|
+
if (typeof method !== 'string')
|
|
323
|
+
return notification ? null : rpcError(replyId, -32600, 'Invalid Request');
|
|
324
|
+
if (params !== undefined && (typeof params !== 'object' || params === null)) {
|
|
325
|
+
return notification ? null : rpcError(replyId, -32602, 'params must be an object');
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
const result = await dispatch(method, (params ?? {}), cwd);
|
|
329
|
+
if (notification)
|
|
330
|
+
return null;
|
|
331
|
+
if (result === UNKNOWN_METHOD)
|
|
332
|
+
return rpcError(replyId, -32601, `Method not found: ${method}`);
|
|
333
|
+
return { jsonrpc: '2.0', id: replyId, result };
|
|
334
|
+
}
|
|
335
|
+
catch (err) {
|
|
336
|
+
if (notification)
|
|
337
|
+
return null;
|
|
338
|
+
if (err instanceof RpcError)
|
|
339
|
+
return rpcError(replyId, err.code, err.message);
|
|
340
|
+
return rpcError(replyId, -32603, `Internal error: ${err.message}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/** Handle one parsed message (or a batch). Returns what to send back, or null for nothing. */
|
|
344
|
+
export async function handleMessage(msg, cwd = process.cwd()) {
|
|
345
|
+
if (Array.isArray(msg)) {
|
|
346
|
+
if (!msg.length)
|
|
347
|
+
return rpcError(null, -32600, 'Invalid Request');
|
|
348
|
+
const replies = (await Promise.all(msg.map((m) => handleOne(m, cwd)))).filter((r) => r !== null);
|
|
349
|
+
return replies.length ? replies : null;
|
|
350
|
+
}
|
|
351
|
+
return handleOne(msg, cwd);
|
|
352
|
+
}
|
|
353
|
+
/** Serve MCP on stdin/stdout until stdin closes. */
|
|
354
|
+
export function runMcpServer(input = process.stdin, output = process.stdout, cwd = process.cwd()) {
|
|
355
|
+
const send = (msg) => output.write(`${JSON.stringify(msg)}\n`);
|
|
356
|
+
const lines = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
|
|
357
|
+
const pending = new Set();
|
|
358
|
+
lines.on('line', (line) => {
|
|
359
|
+
if (!line.trim())
|
|
360
|
+
return;
|
|
361
|
+
let msg;
|
|
362
|
+
try {
|
|
363
|
+
msg = JSON.parse(line);
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
send(rpcError(null, -32700, 'Parse error'));
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const job = handleMessage(msg, cwd).then((reply) => {
|
|
370
|
+
if (reply)
|
|
371
|
+
send(reply);
|
|
372
|
+
});
|
|
373
|
+
pending.add(job);
|
|
374
|
+
void job.finally(() => pending.delete(job));
|
|
375
|
+
});
|
|
376
|
+
return new Promise((done) => {
|
|
377
|
+
lines.on('close', () => {
|
|
378
|
+
void Promise.allSettled([...pending]).then(() => done());
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
package/dist/src/project.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare class ProjectContext {
|
|
|
29
29
|
/** Text files we read. */
|
|
30
30
|
readonly files: SourceFile[];
|
|
31
31
|
truncated: boolean;
|
|
32
|
+
/** Folders left out because they are separate git repositories (they have their own .git folder). */
|
|
33
|
+
readonly nestedRepos: string[];
|
|
32
34
|
readonly deps: Set<string>;
|
|
33
35
|
readonly imports: Set<string>;
|
|
34
36
|
readonly scripts: string[];
|
|
@@ -39,6 +41,10 @@ export declare class ProjectContext {
|
|
|
39
41
|
* Monitoring, legal pages and first impressions only matter for web apps.
|
|
40
42
|
*/
|
|
41
43
|
readonly isWebApp: boolean;
|
|
44
|
+
/** Is this a React Native / Expo app (or does it contain one)? */
|
|
45
|
+
readonly isMobileApp: boolean;
|
|
46
|
+
/** Every package.json folder ("" for the root), and whether it is a mobile app. */
|
|
47
|
+
private readonly packageDirs;
|
|
42
48
|
/** Finding / checklist ids silenced in .launchdoctorignore. */
|
|
43
49
|
readonly ignoredIds: Set<string>;
|
|
44
50
|
private ignoredPathRules;
|
|
@@ -81,6 +87,8 @@ export declare class ProjectContext {
|
|
|
81
87
|
lineOf(file: SourceFile, index: number): number;
|
|
82
88
|
/** Best guess: does this file end up in the browser? */
|
|
83
89
|
isClient(file: SourceFile): boolean;
|
|
90
|
+
/** Is this file part of a React Native / Expo app (the closest package.json is a mobile one)? */
|
|
91
|
+
isMobileFile(path: string): boolean;
|
|
84
92
|
private computeIsClient;
|
|
85
93
|
isTracked(path: string): boolean;
|
|
86
94
|
/** Which of these paths would git ignore? */
|
package/dist/src/project.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { basename, extname, join, resolve } from 'node:path';
|
|
4
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
5
5
|
import { stripComments } from './comments.js';
|
|
6
6
|
const SKIP_DIRS = new Set([
|
|
7
7
|
'node_modules',
|
|
@@ -49,6 +49,7 @@ const TEXT_EXT = new Set([
|
|
|
49
49
|
'.mdx',
|
|
50
50
|
'.txt',
|
|
51
51
|
'.xml',
|
|
52
|
+
'.plist',
|
|
52
53
|
]);
|
|
53
54
|
const SPECIAL_NAMES = new Set([
|
|
54
55
|
'firestore.rules',
|
|
@@ -106,6 +107,26 @@ export function isRouteLike(f) {
|
|
|
106
107
|
/\b(?:app|router)\.(?:post|get|all)\s*\(|Deno\.serve\s*\(|\bserve\s*\(\s*async/.test(f.content) ||
|
|
107
108
|
/@(?:app|router|bp|blueprint|api)\.(?:route|get|post|put|patch|delete)\s*\(|\burlpatterns\s*=/.test(f.content));
|
|
108
109
|
}
|
|
110
|
+
/** Mobile app frameworks: their code ships inside the app people install. */
|
|
111
|
+
const MOBILE_PACKAGES = ['expo', 'react-native'];
|
|
112
|
+
/** Web frameworks that make a React Native / Expo project a website too (react and react-dom alone don't). */
|
|
113
|
+
const WEB_FRAMEWORKS = [
|
|
114
|
+
'next',
|
|
115
|
+
'vite',
|
|
116
|
+
'react-scripts',
|
|
117
|
+
'vue',
|
|
118
|
+
'svelte',
|
|
119
|
+
'nuxt',
|
|
120
|
+
'astro',
|
|
121
|
+
'@sveltejs/kit',
|
|
122
|
+
'solid-js',
|
|
123
|
+
'preact',
|
|
124
|
+
'@angular/core',
|
|
125
|
+
'@remix-run/react',
|
|
126
|
+
'lit',
|
|
127
|
+
];
|
|
128
|
+
/** Files in a mobile app's folder that don't ship inside the app. */
|
|
129
|
+
const MOBILE_NOT_SHIPPED = /(^|\/)(server|api|backend|functions|scripts|supabase|e2e|__tests__)\/|\+api\.[cm]?[jt]sx?$|\.server\.[cm]?[jt]sx?$|(^|\/)(metro|babel|jest|eslint|tailwind|postcss|webpack|vitest)\.config\./;
|
|
109
130
|
const FRONTEND_PACKAGES = [
|
|
110
131
|
'react',
|
|
111
132
|
'react-dom',
|
|
@@ -139,6 +160,9 @@ const IMPORT_RE = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|^\s*import\s+
|
|
|
139
160
|
const PY_IMPORT_RE = /^[ \t]*(?:from|import)[ \t]+([A-Za-z_][\w.]*)/gm;
|
|
140
161
|
/** Python package/module names mapped to the npm names the checks look for. */
|
|
141
162
|
const PY_ALIASES = {
|
|
163
|
+
fastapi: 'fastapi',
|
|
164
|
+
flask: 'flask',
|
|
165
|
+
django: 'django',
|
|
142
166
|
supabase: '@supabase/supabase-js',
|
|
143
167
|
stripe: 'stripe',
|
|
144
168
|
openai: 'openai',
|
|
@@ -186,6 +210,8 @@ export class ProjectContext {
|
|
|
186
210
|
/** Text files we read. */
|
|
187
211
|
files = [];
|
|
188
212
|
truncated = false;
|
|
213
|
+
/** Folders left out because they are separate git repositories (they have their own .git folder). */
|
|
214
|
+
nestedRepos = [];
|
|
189
215
|
deps = new Set();
|
|
190
216
|
imports = new Set();
|
|
191
217
|
scripts = [];
|
|
@@ -196,6 +222,10 @@ export class ProjectContext {
|
|
|
196
222
|
* Monitoring, legal pages and first impressions only matter for web apps.
|
|
197
223
|
*/
|
|
198
224
|
isWebApp;
|
|
225
|
+
/** Is this a React Native / Expo app (or does it contain one)? */
|
|
226
|
+
isMobileApp;
|
|
227
|
+
/** Every package.json folder ("" for the root), and whether it is a mobile app. */
|
|
228
|
+
packageDirs = [];
|
|
199
229
|
/** Finding / checklist ids silenced in .launchdoctorignore. */
|
|
200
230
|
ignoredIds = new Set();
|
|
201
231
|
ignoredPathRules = '';
|
|
@@ -209,6 +239,8 @@ export class ProjectContext {
|
|
|
209
239
|
this.root = resolve(root);
|
|
210
240
|
this.options = options;
|
|
211
241
|
this.maxFiles = options.maxFiles ?? MAX_FILES;
|
|
242
|
+
// Known before the walk, so folders that are separate git repositories can be left out.
|
|
243
|
+
this.gitRoot = options.useGit === false ? null : findGitRoot(this.root);
|
|
212
244
|
this.readIgnoreFile();
|
|
213
245
|
this.walk();
|
|
214
246
|
this.readPackages();
|
|
@@ -226,7 +258,6 @@ export class ProjectContext {
|
|
|
226
258
|
}
|
|
227
259
|
}
|
|
228
260
|
this.name = name;
|
|
229
|
-
this.gitRoot = options.useGit === false ? null : findGitRoot(this.root);
|
|
230
261
|
this.tracked = this.gitRoot ? gitLsFiles(this.root) : null;
|
|
231
262
|
const fullStack = [
|
|
232
263
|
'next',
|
|
@@ -242,11 +273,15 @@ export class ProjectContext {
|
|
|
242
273
|
'vike',
|
|
243
274
|
];
|
|
244
275
|
this.isSpa = (this.uses('vite') || this.uses('react-scripts')) && !fullStack.some((p) => this.uses(p));
|
|
276
|
+
this.isMobileApp = this.packageDirs.some((p) => p.mobile);
|
|
277
|
+
const indexHtml = this.paths.some((p) => /^(?:public\/)?index\.html?$/i.test(p));
|
|
245
278
|
// HTML under docs/ (and coverage/, node_modules/, which are never read) doesn't make a project a website.
|
|
246
|
-
|
|
247
|
-
|
|
279
|
+
// A React Native app uses react too, and its server folder is the app's backend, not a website.
|
|
280
|
+
this.isWebApp = this.isMobileApp
|
|
281
|
+
? this.usesAny(WEB_FRAMEWORKS) || indexHtml
|
|
282
|
+
: this.usesAny(FRONTEND_PACKAGES) ||
|
|
248
283
|
this.files.some((f) => isCodeFile(f) && !isTestPath(f.path) && !/(^|\/)docs\//.test(f.path) && isRouteLike(f)) ||
|
|
249
|
-
|
|
284
|
+
indexHtml;
|
|
250
285
|
}
|
|
251
286
|
// ---------- reading the project ----------
|
|
252
287
|
/**
|
|
@@ -300,6 +335,11 @@ export class ProjectContext {
|
|
|
300
335
|
continue;
|
|
301
336
|
if (entry.name.startsWith('.') && entry.name !== '.github')
|
|
302
337
|
continue;
|
|
338
|
+
// Another project cloned inside this one (like a tool you're trying out) isn't part of this app.
|
|
339
|
+
if (this.gitRoot && isSeparateRepo(join(abs, entry.name))) {
|
|
340
|
+
this.nestedRepos.push(relPath);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
303
343
|
stack.push(relPath);
|
|
304
344
|
continue;
|
|
305
345
|
}
|
|
@@ -335,10 +375,16 @@ export class ProjectContext {
|
|
|
335
375
|
if (name === 'package.json') {
|
|
336
376
|
try {
|
|
337
377
|
const pkg = JSON.parse(file.content);
|
|
378
|
+
let mobile = false;
|
|
338
379
|
for (const field of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
|
|
339
|
-
for (const dep of Object.keys(pkg[field] ?? {}))
|
|
380
|
+
for (const dep of Object.keys(pkg[field] ?? {})) {
|
|
340
381
|
this.deps.add(dep);
|
|
382
|
+
if (MOBILE_PACKAGES.includes(dep))
|
|
383
|
+
mobile = true;
|
|
384
|
+
}
|
|
341
385
|
}
|
|
386
|
+
const dir = dirname(file.path);
|
|
387
|
+
this.packageDirs.push({ dir: dir === '.' ? '' : dir, mobile });
|
|
342
388
|
for (const script of Object.values(pkg.scripts ?? {})) {
|
|
343
389
|
if (typeof script === 'string')
|
|
344
390
|
this.scripts.push(script);
|
|
@@ -520,8 +566,28 @@ export class ProjectContext {
|
|
|
520
566
|
this.clientCache.set(file.path, result);
|
|
521
567
|
return result;
|
|
522
568
|
}
|
|
569
|
+
/** Is this file part of a React Native / Expo app (the closest package.json is a mobile one)? */
|
|
570
|
+
isMobileFile(path) {
|
|
571
|
+
if (!this.isMobileApp)
|
|
572
|
+
return false;
|
|
573
|
+
let best;
|
|
574
|
+
for (const pkg of this.packageDirs) {
|
|
575
|
+
const inside = pkg.dir === '' || path === pkg.dir || path.startsWith(`${pkg.dir}/`);
|
|
576
|
+
if (inside && (!best || pkg.dir.length > best.dir.length))
|
|
577
|
+
best = pkg;
|
|
578
|
+
}
|
|
579
|
+
return best?.mobile ?? false;
|
|
580
|
+
}
|
|
523
581
|
computeIsClient(file) {
|
|
524
582
|
const p = file.path;
|
|
583
|
+
// Everything in a mobile app ships inside the app people install, including Expo's app config ("extra" values).
|
|
584
|
+
if (this.isMobileFile(p)) {
|
|
585
|
+
if (/(^|\/)app\.(?:json|config\.[cm]?[jt]s)$/.test(p))
|
|
586
|
+
return true;
|
|
587
|
+
if (isCodeFile(p) && !/\.(py|rb|php|go|html?)$/i.test(p) && !MOBILE_NOT_SHIPPED.test(p) && !isTestPath(p)) {
|
|
588
|
+
return !looksLikeServerCode(file.content);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
525
591
|
if (!isCodeFile(p) || /\.(py|rb|php|go)$/i.test(p))
|
|
526
592
|
return false;
|
|
527
593
|
if (/\.html?$/i.test(p))
|
|
@@ -565,6 +631,8 @@ export class ProjectContext {
|
|
|
565
631
|
['@sveltejs/kit', 'SvelteKit'],
|
|
566
632
|
['astro', 'Astro'],
|
|
567
633
|
['@remix-run/react', 'Remix'],
|
|
634
|
+
['expo', 'Expo'],
|
|
635
|
+
['react-native', 'React Native'],
|
|
568
636
|
['vite', 'Vite'],
|
|
569
637
|
['react', 'React'],
|
|
570
638
|
['vue', 'Vue'],
|
|
@@ -572,6 +640,9 @@ export class ProjectContext {
|
|
|
572
640
|
['express', 'Express'],
|
|
573
641
|
['hono', 'Hono'],
|
|
574
642
|
['fastify', 'Fastify'],
|
|
643
|
+
['fastapi', 'FastAPI'],
|
|
644
|
+
['flask', 'Flask'],
|
|
645
|
+
['django', 'Django'],
|
|
575
646
|
['@supabase/supabase-js', 'Supabase'],
|
|
576
647
|
['firebase', 'Firebase'],
|
|
577
648
|
['@prisma/client', 'Prisma'],
|
|
@@ -580,10 +651,16 @@ export class ProjectContext {
|
|
|
580
651
|
['convex', 'Convex'],
|
|
581
652
|
['stripe', 'Stripe'],
|
|
582
653
|
['razorpay', 'Razorpay'],
|
|
654
|
+
['@paddle/paddle-node-sdk', 'Paddle'],
|
|
655
|
+
['@lemonsqueezy/lemonsqueezy.js', 'Lemon Squeezy'],
|
|
656
|
+
['appwrite', 'Appwrite'],
|
|
657
|
+
['node-appwrite', 'Appwrite'],
|
|
583
658
|
['@clerk/nextjs', 'Clerk'],
|
|
584
659
|
['next-auth', 'NextAuth'],
|
|
585
660
|
['openai', 'OpenAI'],
|
|
586
661
|
['@anthropic-ai/sdk', 'Anthropic'],
|
|
662
|
+
['@google/genai', 'Gemini'],
|
|
663
|
+
['@google/generative-ai', 'Gemini'],
|
|
587
664
|
['ai', 'Vercel AI SDK'],
|
|
588
665
|
];
|
|
589
666
|
const out = [];
|
|
@@ -631,6 +708,25 @@ function samePath(a, b) {
|
|
|
631
708
|
const norm = (p) => resolve(p).replace(/\\/g, '/').replace(/\/+$/, '').toLowerCase();
|
|
632
709
|
return norm(a) === norm(b);
|
|
633
710
|
}
|
|
711
|
+
/**
|
|
712
|
+
* Does this folder hold a different git repository? A .git folder means a separate clone.
|
|
713
|
+
* A .git file means a submodule (part of this project, so it's scanned) or a worktree
|
|
714
|
+
* (a second checkout of the same code, so it's not).
|
|
715
|
+
*/
|
|
716
|
+
function isSeparateRepo(dir) {
|
|
717
|
+
const dotGit = join(dir, '.git');
|
|
718
|
+
try {
|
|
719
|
+
const stat = statSync(dotGit, { throwIfNoEntry: false });
|
|
720
|
+
if (!stat)
|
|
721
|
+
return false;
|
|
722
|
+
if (stat.isDirectory())
|
|
723
|
+
return true;
|
|
724
|
+
return /[\\/]worktrees[\\/]/.test(readFileSync(dotGit, 'utf8'));
|
|
725
|
+
}
|
|
726
|
+
catch {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
634
730
|
function findGitRoot(root) {
|
|
635
731
|
const out = git(root, ['rev-parse', '--show-toplevel']);
|
|
636
732
|
if (!out)
|
package/dist/src/report.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Report } from './types.js';
|
|
2
2
|
export declare const bold: (s: string) => string;
|
|
3
3
|
export declare const dim: (s: string) => string;
|
|
4
|
+
/** "Left out Twin/: a separate git repository inside this folder. Scan it on its own." */
|
|
5
|
+
export declare function nestedReposNote(repos: string[]): string;
|
|
4
6
|
export declare function renderReport(report: Report, opts?: {
|
|
5
7
|
fixFile?: string;
|
|
6
8
|
}): string;
|
package/dist/src/report.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shortWhere } from './checks/common.js';
|
|
2
|
-
import { plural } from './util.js';
|
|
2
|
+
import { ISSUES_URL, plural } from './util.js';
|
|
3
3
|
const useColor = !process.env.NO_COLOR && (process.env.FORCE_COLOR ? process.env.FORCE_COLOR !== '0' : !!process.stdout.isTTY);
|
|
4
4
|
const paint = (code) => (s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
5
5
|
export const bold = paint('1');
|
|
@@ -8,6 +8,14 @@ const red = paint('31');
|
|
|
8
8
|
const green = paint('32');
|
|
9
9
|
const yellow = paint('33');
|
|
10
10
|
const cyan = paint('36');
|
|
11
|
+
/** "Left out Twin/: a separate git repository inside this folder. Scan it on its own." */
|
|
12
|
+
export function nestedReposNote(repos) {
|
|
13
|
+
const names = repos.slice(0, 3).map((p) => `${p}/`);
|
|
14
|
+
const more = repos.length > 3 ? ` and ${repos.length - 3} more` : '';
|
|
15
|
+
return repos.length === 1
|
|
16
|
+
? `Left out ${names[0]}: a separate git repository inside this folder. Scan it on its own.`
|
|
17
|
+
: `Left out ${repos.length} separate git repositories inside this folder (${names.join(', ')}${more}). Scan them on their own.`;
|
|
18
|
+
}
|
|
11
19
|
function gradeColor(grade) {
|
|
12
20
|
if (grade === 'A' || grade === 'B')
|
|
13
21
|
return green;
|
|
@@ -75,6 +83,8 @@ export function renderReport(report, opts = {}) {
|
|
|
75
83
|
lines.push(` ${dim(`Checked ${report.projectName} · ${plural(report.filesScanned, unit)}${stack}`)}`);
|
|
76
84
|
if (report.truncated)
|
|
77
85
|
lines.push(` ${yellow('Very large project: only the first 20,000 files were checked.')}`);
|
|
86
|
+
if (report.nestedRepos?.length)
|
|
87
|
+
lines.push(` ${dim(nestedReposNote(report.nestedRepos))}`);
|
|
78
88
|
lines.push('');
|
|
79
89
|
lines.push(` ${bold('Overall grade')} ${badge(report.grade)} ${report.verdict}`);
|
|
80
90
|
lines.push('');
|
|
@@ -132,5 +142,6 @@ export function renderReport(report, opts = {}) {
|
|
|
132
142
|
lines.push(` ${dim('Paste them one at a time into Claude Code, Cursor, Lovable or Bolt, then run launch-doctor again.')}`);
|
|
133
143
|
lines.push('');
|
|
134
144
|
}
|
|
145
|
+
lines.push(` ${dim(`Wrong finding or a missed problem? Please report it: ${ISSUES_URL}`)}`, '');
|
|
135
146
|
return `${lines.join('\n')}\n`;
|
|
136
147
|
}
|