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.
@@ -2,7 +2,7 @@ import { chmodSync, mkdirSync, realpathSync } from 'node:fs';
2
2
  import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
3
3
  import { gitHooksDir } from './git.js';
4
4
  import { CONFIG_FILE_MAX_BYTES, findGitRoot } from './project.js';
5
- import { entryKind, readRegularFile, writeRegularFile } from './safe-fs.js';
5
+ import { entryKind, readRegularFile, writeInside, writeRegularFile } from './safe-fs.js';
6
6
  import { version } from './version.js';
7
7
  /**
8
8
  * The package spec every generated hook runs: the current minor range from package.json ("launch-doctor@^0.4.0"), so a
@@ -39,9 +39,18 @@ function readJson(path) {
39
39
  }
40
40
  }
41
41
  const SPECIAL = 'it is a link or a special file, not a regular file, so it was left alone';
42
- function writeJson(path, data) {
43
- mkdirSync(dirname(path), { recursive: true });
44
- writeRegularFile(path, `${JSON.stringify(data, null, 2)}\n`);
42
+ /**
43
+ * Write `rel` inside `root`. Returns why it was left alone instead, when its folder is a link (a .claude pointing to
44
+ * ~/.claude, say) or it can't be written: the hook is reported as skipped, and the other hooks are still set up.
45
+ */
46
+ function writeJson(root, rel, data) {
47
+ try {
48
+ writeInside(root, rel, `${JSON.stringify(data, null, 2)}\n`);
49
+ return null;
50
+ }
51
+ catch (err) {
52
+ return err.message;
53
+ }
45
54
  }
46
55
  /**
47
56
  * Does this hook list already run a launch-doctor hook command? Any version counts, including the unpinned commands
@@ -69,7 +78,9 @@ function setupClaude(root, result) {
69
78
  if (hasOurCommand(post, 'claude'))
70
79
  return void result.skipped.push([rel, 'already set up']);
71
80
  post.push({ matcher: 'Write|Edit|MultiEdit', hooks: [{ type: 'command', command: claudeCommand(), timeout: 60 }] });
72
- writeJson(path, { ...data, hooks: { ...hooks, PostToolUse: post } });
81
+ const failed = writeJson(root, rel, { ...data, hooks: { ...hooks, PostToolUse: post } });
82
+ if (failed)
83
+ return void result.skipped.push([rel, failed]);
73
84
  (settings === null ? result.created : result.updated).push(rel);
74
85
  }
75
86
  /** .cursor/hooks.json: a stop hook that checks the files the agent changed before it finishes. */
@@ -91,7 +102,9 @@ function setupCursor(root, result) {
91
102
  if (hasOurCommand(stop, 'cursor'))
92
103
  return void result.skipped.push([rel, 'already set up']);
93
104
  stop.push({ command: cursorCommand(), timeout: 60 });
94
- writeJson(path, { version: 1, ...data, hooks: { ...hooks, stop } });
105
+ const failed = writeJson(root, rel, { version: 1, ...data, hooks: { ...hooks, stop } });
106
+ if (failed)
107
+ return void result.skipped.push([rel, failed]);
95
108
  (config === null ? result.created : result.updated).push(rel);
96
109
  }
97
110
  const MARK_START = '# >>> launch-doctor (added by "launch-doctor init --hooks") >>>';
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';
@@ -140,6 +140,7 @@ export async function runDoctor(root, options = {}) {
140
140
  for (const c of categories)
141
141
  for (const f of c.findings)
142
142
  f.fingerprint = fingerprint(ctx, f);
143
+ assignRefs(categories.flatMap((c) => c.findings), (f) => lineContext(ctx, f));
143
144
  const summary = overall(categories);
144
145
  const knownIds = new Set(CHECKS.flatMap((c) => c.ids));
145
146
  const unknownIgnoreIds = [...ctx.ignoredIds].filter((id) => !knownIds.has(id)).sort();
@@ -37,3 +37,20 @@ 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
+ * The package spec for a command that cmd.exe will read: "launch-doctor@^0.4.0" becomes "launch-doctor@0.4", the same
49
+ * range (0.4.x) without the "^", which cmd.exe treats as an escape character and silently drops when it isn't quoted.
50
+ */
51
+ export declare function windowsPackage(pkg: string): string;
52
+ /**
53
+ * `init --mcp`: the exact commands and snippets to connect Launch Doctor to Claude Code, Cursor and Claude Desktop.
54
+ * Nothing is written: the user pastes them where they want. On Windows, Claude Code needs `cmd /c` to start npx.
55
+ */
56
+ export declare function mcpSetupText(root: string, pkg: string, platform?: NodeJS.Platform): string;
package/dist/src/init.js CHANGED
@@ -1,5 +1,7 @@
1
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
1
+ import { writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { CONFIG_FILE_MAX_BYTES } from './project.js';
4
+ import { entryKind, pathInside, 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
@@ -150,14 +152,79 @@ export function runInit(root, { monitor = false } = {}) {
150
152
  ];
151
153
  const result = { created: [], skipped: [] };
152
154
  for (const [rel, content] of files) {
153
- const full = join(root, rel);
154
- if (existsSync(full)) {
155
+ // A link or a special file in the file's place counts as already there: it is never written through.
156
+ if (entryKind(join(root, rel)) !== 'missing') {
155
157
  result.skipped.push(rel);
156
158
  continue;
157
159
  }
158
- mkdirSync(dirname(full), { recursive: true });
159
- writeFileSync(full, content, { flag: 'wx' });
160
+ // pathInside makes the folders, and refuses one that is a link (a .github pointing to another folder).
161
+ writeFileSync(pathInside(root, rel), content, { flag: 'wx' });
160
162
  result.created.push(rel);
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
+ * The package spec for a command that cmd.exe will read: "launch-doctor@^0.4.0" becomes "launch-doctor@0.4", the same
189
+ * range (0.4.x) without the "^", which cmd.exe treats as an escape character and silently drops when it isn't quoted.
190
+ */
191
+ export function windowsPackage(pkg) {
192
+ return pkg.replace(/@\^(\d+)\.(\d+)\.0$/, (_, major, minor) => (major === '0' ? `@0.${minor}` : `@${major}`));
193
+ }
194
+ /**
195
+ * `init --mcp`: the exact commands and snippets to connect Launch Doctor to Claude Code, Cursor and Claude Desktop.
196
+ * Nothing is written: the user pastes them where they want. On Windows, Claude Code needs `cmd /c` to start npx.
197
+ */
198
+ export function mcpSetupText(root, pkg, platform = process.platform) {
199
+ const desktopArgs = ['-y', pkg, 'mcp', root];
200
+ const projectArgs = ['-y', pkg, 'mcp'];
201
+ const json = (args) => JSON.stringify({ mcpServers: { 'launch-doctor': { command: 'npx', args } } }, null, 2)
202
+ .split('\n')
203
+ .map((l) => ` ${l}`)
204
+ .join('\n');
205
+ return [
206
+ '',
207
+ ' Claude Code (run in this project folder):',
208
+ '',
209
+ platform === 'win32'
210
+ ? ` claude mcp add launch-doctor -- cmd /c npx -y ${windowsPackage(pkg)} mcp`
211
+ : ` claude mcp add launch-doctor -- npx -y "${pkg}" mcp`,
212
+ ...(platform === 'win32'
213
+ ? ['', ' (On Windows, Claude Code starts npx through cmd /c. The version range has no "^", which cmd drops.)']
214
+ : []),
215
+ '',
216
+ ' Cursor: add this to .cursor/mcp.json in this project:',
217
+ '',
218
+ json(projectArgs),
219
+ '',
220
+ ' Claude Desktop: add this to claude_desktop_config.json',
221
+ ' (macOS: ~/Library/Application Support/Claude/, Windows: %APPDATA%\\Claude\\).',
222
+ ' Claude Desktop does not start servers in your project, so the folder is given:',
223
+ '',
224
+ json(desktopArgs),
225
+ '',
226
+ ' Then ask: "Scan this app with Launch Doctor", "Explain finding 2", or "Fix the top issue, then rescan".',
227
+ ' The server only reads this folder and uses the network only for scan_url. Nothing was written.',
228
+ '',
229
+ ].join('\n');
230
+ }
package/dist/src/live.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { assignRefs } from './baseline.js';
1
2
  import { emptyOutput, notApplicable } from './checks/common.js';
2
3
  import { leakPlaybook, matchKeys, usageLink } from './checks/secrets.js';
3
4
  import { overall, scoreCategory, toGrade } from './grade.js';
@@ -580,6 +581,8 @@ export async function runLiveScan(input, options = {}) {
580
581
  const hosts = [...new Set(fetcher.blocked.map((b) => b.split(' ')[0]))].slice(0, 3).join(', ');
581
582
  categories[0].passed.push(`Skipped ${plural(fetcher.blocked.length, 'request')} to private or local network addresses (${hosts}) that this public site pointed to`);
582
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), () => '');
583
586
  // Text from the site (table names, paths) can hold terminal escape sequences; none reach any output.
584
587
  return sanitizeReport({
585
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
- domain: {
57
+ history: {
51
58
  type: string;
52
59
  description: string;
53
60
  };
54
- history: {
61
+ includeBaseline: {
55
62
  type: string;
56
63
  description: string;
57
64
  };
58
- includeBaseline: {
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
- /** Plain-text summary of a report, written for an AI assistant that will act on it. */
131
- export declare function reportText(report: Report, includeBaseline?: boolean): string;
132
- /** The same report as data, for clients that read structured tool output. */
133
- export declare function reportData(report: Report, includeBaseline?: boolean): Record<string, unknown>;
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. */