launch-doctor 0.4.3 → 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 CHANGED
@@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.4] - 2026-12-05
11
+
12
+ A security and usability release from the December 2026 audit ([docs/audits/2026-12-audit.md](docs/audits/2026-12-audit.md)). It changes no rule, severity, finding id or grade: the 50 apps of the corpus scan exactly as before.
13
+
14
+ ### Security
15
+
16
+ - **A project that ships with its `.git` folder can no longer run a program through a git submodule.** `--changed`, the MCP `rescan` tool (with no ids or paths) and the Cursor stop hook ran `git diff HEAD`, which runs `git status` inside every checked-out submodule, where a filter driver from the submodule's own config could run. Every `git diff` and `git log` now passes `--ignore-submodules=all`. The plain scan, `--staged` and `--history` were not affected.
17
+ - **No file is written through a folder that is a link.** `--report`, `init` and `init --hooks` wrote through a `.launchdoctor`, `.github`, `.claude` or `.cursor` that was a symlink (or a junction on Windows) to another folder. They now refuse it, as `--record` already did.
18
+ - **MCP tools no longer follow a link out of the project folder.** A link inside the folder the server started in, leading outside it, let `scan_project` and the other tools with a `path` read the outside folder. The real paths are now compared.
19
+ - **Two regular expressions could keep a scan running for minutes** on one very long line in an env file (a 900 KB `EMAIL_FROM=` value, or a long run of spaces after a secret-sounding name). Both are now linear.
20
+ - The release workflow now runs the tests in a job with read-only permissions. Only the publish job holds `contents: write` and `id-token: write`, and it installs with `--ignore-scripts`.
21
+
22
+ ### Fixed
23
+
24
+ - `explain <n>` explained a different finding than number n in the report when the email DNS check had found something, because it scanned offline while the report and `prompt` do not. It now scans like `prompt`, and accepts `--offline` and `--domain` (0.4.3 refused `explain --offline`).
25
+ - `prompt` and `explain` in a folder with no project files said "found nothing to fix". They now say that no project files were found, and where to run it.
26
+ - `init` and `init --hooks` crashed with a stack trace when a file could not be written (a read-only folder, a file where a folder should be). They now say which file and why, and exit with code 2. A hook file that cannot be written is skipped and the others are still set up.
27
+ - The hint under `explain` is a command you can paste: `npx`, and the folder quoted.
28
+ - `--fail-on` without `--ci` now says on stderr that it was ignored. `--` ends the options, so a folder whose name starts with `-` can be given.
29
+
30
+ ### Added
31
+
32
+ - When the folder has no `package.json` (or similar) of its own but holds several projects, as a home folder or the Desktop does, the short report ends with a note naming them and how to check one, because the grade mixes them. It is not shown for a workspace root (`pnpm-workspace.yaml`, `workspaces` in `package.json`, `turbo.json`, `nx.json` or `lerna.json`). `--json` is unchanged.
33
+ - On Windows, `init --mcp` prints `claude mcp add launch-doctor -- cmd /c npx -y launch-doctor@0.4 mcp`: a program that starts `npx` without a shell can't find it there. The README and `docs/ai-tools.md` show it. The version range is written without `^`, which cmd.exe drops.
34
+ - `launch-doctor mcp --help` lists all seven tools and the pinned setup commands.
35
+ - The December 2026 audit report, `docs/audits/2026-12-audit.md`, with its follow-ups.
36
+
37
+ ### Changed
38
+
39
+ - The "no colour without a terminal" test runs the CLI in a child process with `FORCE_COLOR`, `CLICOLOR_FORCE` and `NO_COLOR` removed, so it no longer fails on a machine that sets them. The suite now has 430 tests.
40
+ - SECURITY.md describes what the MCP tools do (no network except `scan_url`, only inside their folder), every file Launch Doctor writes, and submodules. CONTRIBUTING.md notes that `npx launch-doctor` inside the repository cannot run the published package, and how to register the working copy's MCP server as `launch-doctor-dev`.
41
+ - **README demo GIF** is now generated with [VHS](https://github.com/charmbracelet/vhs) from `docs/demo/demo.tape`: `npx launch-doctor --demo`, then `npx launch-doctor prompt 1 --demo`. A manual "Demo GIF" workflow regenerates it after a release and opens a pull request. The README loads it from an absolute GitHub URL, so it also shows on npm. VHS is not a package dependency. The old `assets/` tape and sample app are removed, and so is `assets/demo.gif`: the README now shows the new GIF, `docs/demo/demo.gif`. The 0.4.3 README on npm still loads the old file, so that page shows no image until 0.4.4 is published.
42
+ - The README's "Example output" matches the current short report (the `--demo` intro line, and the `--report` Next line on real projects).
43
+
44
+
10
45
  ## [0.4.3] - 2026-12-04
11
46
 
12
47
  ### Added
@@ -227,7 +262,8 @@ First release.
227
262
  - `.launchdoctorignore` for silencing findings by id or skipping paths.
228
263
  - Support for JavaScript / TypeScript and Python projects.
229
264
 
230
- [Unreleased]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.3...HEAD
265
+ [Unreleased]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.4...HEAD
266
+ [0.4.4]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.3...v0.4.4
231
267
  [0.4.3]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.2...v0.4.3
232
268
  [0.4.2]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.1...v0.4.2
233
269
  [0.4.1]: https://github.com/SHARAJ379/Launch-Doctor/compare/v0.4.0...v0.4.1
package/README.md CHANGED
@@ -7,9 +7,9 @@
7
7
  [![Node](https://img.shields.io/badge/node-%3E%3D22-339933)](https://nodejs.org/)
8
8
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
9
9
 
10
- ![Launch Doctor demo](assets/demo.gif)
10
+ ![Launch Doctor demo: npx launch-doctor --demo, then npx launch-doctor prompt 1 --demo](https://raw.githubusercontent.com/SHARAJ379/Launch-Doctor/main/docs/demo/demo.gif)
11
11
 
12
- *A sample app full of mistakes scores an F with six critical issues; a prepared app scores an A.*
12
+ *`npx launch-doctor --demo` scans a sample app full of mistakes: six critical problems, Security F. `prompt 1` prints the fix prompt for the first one.*
13
13
 
14
14
  Launch Doctor scans your project for common problems that hurt apps after launch: leaked API keys, databases anyone can read, endpoints that let one user reach another user's data, payments that can be faked, emails that land in spam, AI endpoints that can run up your bill, missing legal pages, and leftover template defaults. It is built for developers who ship with AI coding tools (Claude Code, Cursor, Lovable, Bolt, Windsurf) and may not read every line of generated code. Every finding is explained in plain English and includes a prompt you can paste straight back into your AI assistant. It has no runtime dependencies, requires no account, sends no telemetry, and your code never leaves your machine.
15
15
 
@@ -38,9 +38,12 @@ The full list is in [What it cannot do](#what-it-cannot-do).
38
38
 
39
39
  ## Example output
40
40
 
41
- This is the `--demo` report. It shows the verdict, a Security grade and a Launch readiness grade, the three things to fix first, and what to do next. `--verbose` prints the full report with every category and every finding (`--ci`, `--changed`, `--staged`, `--pr-comment` and `scan <url>` always print the full report). On a real project, the Next lines also point to `LAUNCH_FIXES.md`, which starts with one prompt for all the critical problems. The banner only appears in an interactive terminal; in a pipe, in CI or with `--no-banner` the report starts at the "Launch Doctor" line.
41
+ This is the short report `npx launch-doctor --demo` prints in an 80-column terminal. It shows the verdict, a Security grade and a Launch readiness grade, the three things to fix first, a one-line count of everything else, and what to do next. `--verbose` prints the full report with every category and every finding (`--ci`, `--changed`, `--staged`, `--pr-comment` and `scan <url>` always print the full report). On a real project, the Next lines also point to `LAUNCH_FIXES.md`, which starts with one prompt for all the critical problems, and to `--report`, which writes every finding explained to `.launchdoctor/report.md`. The banner only appears in an interactive terminal; in a pipe, in CI or with `--no-banner` the report starts at the "Launch Doctor" line (with `--demo`, after the "Demo:" line). In a wider terminal the header lists the whole stack instead of "+2".
42
42
 
43
43
  ```
44
+
45
+ Demo: scanning a sample app with the usual weekend-project mistakes…
46
+
44
47
  ██╗ █████╗ ██╗ ██╗███╗ ██╗ ██████╗██╗ ██╗
45
48
  ██║ ██╔══██╗██║ ██║████╗ ██║██╔════╝██║ ██║
46
49
  ██║ ███████║██║ ██║██╔██╗ ██║██║ ███████║
@@ -54,7 +57,7 @@ This is the `--demo` report. It shows the verdict, a Security grade and a Launch
54
57
  ██║ ██║██║ ██║██║ ██║ ██║ ██║██╔══██╗
55
58
  ██████╔╝╚██████╔╝╚██████╗ ██║ ╚██████╔╝██║ ██║
56
59
  ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
57
- Launch Doctor v0.4.3 · my-weekend-saas · 13 files · Vite, React, Supabase +2
60
+ Launch Doctor v0.4.4 · my-weekend-saas · 13 files · Vite, React, Supabase +2
58
61
 
59
62
  NOT READY TO LAUNCH: 6 critical problems
60
63
 
@@ -150,6 +153,8 @@ Launch Doctor is also an MCP server, so your AI coding tool can run the checks,
150
153
  claude mcp add launch-doctor -- npx -y "launch-doctor@^0.4.0" mcp
151
154
  ```
152
155
 
156
+ On native Windows (PowerShell or cmd), use `claude mcp add launch-doctor -- cmd /c npx -y launch-doctor@0.4 mcp` instead: Claude Code needs `cmd /c` there to start `npx`.
157
+
153
158
  `npx launch-doctor init --mcp` prints that command and ready JSON for Cursor (`.cursor/mcp.json`) and Claude Desktop; it changes nothing. Then ask:
154
159
 
155
160
  - *"Scan this app with Launch Doctor."* It runs `scan_project`: the two grades and a short list of findings, each with an id.
@@ -228,7 +233,7 @@ For apps that handle significant money or sensitive personal or health data, use
228
233
 
229
234
  ## How it is tested
230
235
 
231
- - 409 automated tests run on every change, on Windows, macOS and Linux, with Node.js 22 and 24.
236
+ - 430 automated tests run on every change, on Windows, macOS and Linux, with Node.js 22 and 24 (a few need FIFOs, Linux or a POSIX shell, and are skipped where those are missing).
232
237
  - A stress-test harness (`scripts/stress/`, see [CONTRIBUTING.md](CONTRIBUTING.md#stress-tests)) runs Launch Doctor against hostile inputs: repositories whose git settings try to run programs, symlink loops and FIFOs, files built to make a regular expression backtrack, terminal escape sequences, hostile servers for `scan`, and MCP requests to private addresses. Before 0.4.0 it found 10 security problems; each is fixed and has a regression test, and the whole suite now passes on Windows and Linux.
233
238
  - Every check that existed in 0.2 has been confirmed against a small project (or fake site) that contains exactly that problem, and every command in this README has been run (the `scan` examples against a local test site rather than a real one).
234
239
  - The features new in 0.3.0 (the GitHub Action, the MCP server, mobile apps, and Clerk, Convex, Appwrite, Paddle and Lemon Squeezy) have their own tests and were spot-checked by hand, which found and fixed two bugs before release. They have been tried less than the older checks. Posting pull request comments is tested against a fake GitHub API; it has not yet run on many real pull requests.
@@ -48,7 +48,9 @@ const DKIM_SELECTORS = [
48
48
  'pm',
49
49
  'brevo1',
50
50
  ];
51
- const EMAIL_RE = /[A-Za-z0-9._%+-]+@((?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,})/;
51
+ // Every part is bounded (a local part has at most 64 characters, a domain label 63), so a long run of letters with no
52
+ // "@" (a crafted .env value) is read in linear time. Unbounded, it took quadratic time and a 900 KB line hung the scan.
53
+ const EMAIL_RE = /[A-Za-z0-9._%+-]{1,64}@((?:[A-Za-z0-9-]{1,63}\.){1,10}[A-Za-z]{2,24})/;
52
54
  function collectSenders(ctx) {
53
55
  const out = [];
54
56
  const add = (m, text) => {
@@ -493,7 +493,9 @@ export function holdsRealSecret(content) {
493
493
  const kv = /^\s*(?:export\s+)?([A-Za-z_]\w*)\s*=\s*(.*)$/.exec(line);
494
494
  if (!kv || !SECRETISH_NAME.test(kv[1]))
495
495
  continue;
496
- const value = kv[2].replace(/\s+#.*$/, '');
496
+ // Cut a trailing " # comment" with a linear search: /\s+#.*$/ took quadratic time on a long run of spaces.
497
+ const comment = kv[2].search(/\s#/);
498
+ const value = comment < 0 ? kv[2] : kv[2].slice(0, comment);
497
499
  if (envValueLooksReal(value))
498
500
  return true;
499
501
  }
package/dist/src/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { appendFileSync, existsSync, mkdirSync, statSync } from 'node:fs';
3
- import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
2
+ import { appendFileSync, existsSync, statSync } from 'node:fs';
3
+ import { isAbsolute, join, relative, resolve } from 'node:path';
4
4
  import { shouldShowBanner } from './banner.js';
5
5
  import { applyBaseline, BASELINE_FILE, loadBaseline, writeBaseline } from './baseline.js';
6
6
  import { shortWhere } from './checks/common.js';
@@ -15,14 +15,14 @@ import { DEFAULT_HISTORY_DEPTH } from './history.js';
15
15
  import { runHook } from './hook.js';
16
16
  import { pinnedPackage, setupHooks, upgradeHooks } from './hooks-setup.js';
17
17
  import { CATEGORY_IDS } from './index.js';
18
- import { badgeUrl, ensureGitignore, GRADES_BRANCH, githubRepo, mcpSetupText, runInit } from './init.js';
18
+ import { badgeUrl, ensureGitignore, GRADES_BRANCH, githubRepo, mcpSetupText, runInit, windowsPackage } from './init.js';
19
19
  import { runLiveScan } from './live.js';
20
20
  import { runMcpServer } from './mcp.js';
21
21
  import { assertConfigRef } from './project.js';
22
- import { copyToClipboard, unsupportedLanguage } from './prompt.js';
22
+ import { copyToClipboard, separateProjects, separateProjectsNote, unsupportedLanguage } from './prompt.js';
23
23
  import { bold, dim, renderReport, wrap } from './report.js';
24
24
  import { REPORT_FILE, renderReportMd } from './report-md.js';
25
- import { writeRegularFile } from './safe-fs.js';
25
+ import { writeInside, writeRegularFile } from './safe-fs.js';
26
26
  import { renderSarif } from './sarif.js';
27
27
  import { renderEmptyFolder, renderOtherLanguage, renderShortReport } from './short-report.js';
28
28
  import { renderStepSummary } from './summary.js';
@@ -76,6 +76,7 @@ const HELP = `
76
76
  --no-banner Don't print the ASCII banner (it only shows in an interactive terminal)
77
77
  -h, --help Show this help
78
78
  -v, --version Show the version
79
+ -- End of the options: what follows is the folder, even if its name starts with "-"
79
80
 
80
81
  ${bold('Live site')}
81
82
  npx launch-doctor scan <url> --no-db Run "launch-doctor scan --help" for the options
@@ -109,6 +110,7 @@ function parseArgs(argv) {
109
110
  offline: false,
110
111
  ci: false,
111
112
  failOn: 'critical',
113
+ failOnSet: false,
112
114
  prComment: false,
113
115
  updateBaseline: false,
114
116
  baseline: true,
@@ -122,6 +124,7 @@ function parseArgs(argv) {
122
124
  help: false,
123
125
  version: false,
124
126
  };
127
+ let optionsEnded = false;
125
128
  for (let i = 0; i < argv.length; i++) {
126
129
  const a = argv[i];
127
130
  const value = () => {
@@ -130,6 +133,16 @@ function parseArgs(argv) {
130
133
  fail(`${a} needs a value`);
131
134
  return v;
132
135
  };
136
+ // After "--" everything is the folder, even a name that starts with "-".
137
+ if (optionsEnded || a === '--') {
138
+ if (!optionsEnded)
139
+ optionsEnded = true;
140
+ else if (!args.path)
141
+ args.path = a;
142
+ else
143
+ fail(`Unexpected argument ${a}`);
144
+ continue;
145
+ }
133
146
  if (a === '-h' || a === '--help')
134
147
  args.help = true;
135
148
  else if (a === '-v' || a === '--version')
@@ -176,10 +189,10 @@ function parseArgs(argv) {
176
189
  args.domain = cleanDomain(value());
177
190
  else if (a.startsWith('--domain='))
178
191
  args.domain = cleanDomain(a.slice(9));
179
- else if (a === '--fail-on')
180
- args.failOn = severityArg(value());
181
- else if (a.startsWith('--fail-on='))
182
- args.failOn = severityArg(a.slice(10));
192
+ else if (a === '--fail-on' || a.startsWith('--fail-on=')) {
193
+ args.failOn = severityArg(a === '--fail-on' ? value() : a.slice(10));
194
+ args.failOnSet = true;
195
+ }
183
196
  else if (a === '--only')
184
197
  args.only = categoriesArg(a, value());
185
198
  else if (a.startsWith('--only='))
@@ -206,6 +219,9 @@ function parseArgs(argv) {
206
219
  // Machine-readable and CI runs shouldn't leave files behind unless asked to.
207
220
  if ((args.json || args.ci) && !args.out)
208
221
  args.writeFile = false;
222
+ if (args.failOnSet && !args.ci) {
223
+ process.stderr.write('launch-doctor: --fail-on only changes the exit code together with --ci, so it was ignored.\n');
224
+ }
209
225
  return args;
210
226
  }
211
227
  function categoriesArg(flag, input) {
@@ -388,14 +404,20 @@ const MCP_HELP = `
388
404
  npx launch-doctor init --mcp Print the exact setup commands and JSON for your tools
389
405
 
390
406
  ${bold('Tools it offers')}
391
- scan_project Check a project folder: grade, findings with fix prompts, and the checklist
392
- scan_url Check a deployed site from the outside
393
- list_checks List the categories and finding ids
407
+ scan_project Check a project folder: the grades and a short list of findings, each with an id
408
+ explain_finding What one finding means, how to confirm it and how to fix it
409
+ fix_prompt The fix prompt for one finding
410
+ rescan Check again after a fix, and say which findings are gone
411
+ grade_history The grades saved with --record
412
+ scan_url Check a deployed site from the outside (the only tool that uses the network)
413
+ list_checks List the categories and finding ids
394
414
 
395
415
  ${bold('Set it up')}
396
- Claude Code claude mcp add launch-doctor -- npx -y launch-doctor mcp
416
+ Claude Code claude mcp add launch-doctor -- npx -y "${pinnedPackage()}" mcp
417
+ On Windows claude mcp add launch-doctor -- cmd /c npx -y ${windowsPackage(pinnedPackage())} mcp
397
418
  Cursor add to .cursor/mcp.json:
398
- { "mcpServers": { "launch-doctor": { "command": "npx", "args": ["-y", "launch-doctor", "mcp"] } } }
419
+ { "mcpServers": { "launch-doctor": { "command": "npx", "args": ["-y", "${pinnedPackage()}", "mcp"] } } }
420
+ "launch-doctor init --mcp" prints the exact setup for this folder.
399
421
  `;
400
422
  async function mcp(argv) {
401
423
  if (argv.some((a) => a === '-h' || a === '--help')) {
@@ -606,6 +628,10 @@ const PROMPT_HELP = `
606
628
  --domain <domain> Domain you send email from
607
629
  -h, --help Show this help
608
630
  `;
631
+ /** For prompt and explain in a folder with nothing to check: usually the wrong folder, not a clean app. */
632
+ function noProjectFiles(root) {
633
+ return `No project files were found in ${root}. Run this inside your app's folder (the one with package.json, requirements.txt or similar), or try npx launch-doctor --demo`;
634
+ }
609
635
  /** `launch-doctor prompt <n> [folder] [--copy]`: print (or copy) one fix prompt. */
610
636
  async function prompt(argv) {
611
637
  let n;
@@ -654,6 +680,8 @@ async function prompt(argv) {
654
680
  fail('--demo uses a built-in sample app, so leave out the folder');
655
681
  const request = (root) => scanProject({ root, offline: demo || offline, domain });
656
682
  const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
683
+ if (report.filesScanned === 0)
684
+ fail(noProjectFiles(report.root));
657
685
  const total = report.counts.critical + report.counts.warning + report.counts.baseline;
658
686
  const finding = findFinding(report, n);
659
687
  if (!finding) {
@@ -676,18 +704,39 @@ async function prompt(argv) {
676
704
  }
677
705
  /** `launch-doctor explain <n|id> [folder] [--demo]`: what one finding means, from the same core as the MCP tool. */
678
706
  async function explain(argv) {
679
- const demo = argv.includes('--demo');
680
- const rest = argv.filter((a) => a !== '--demo');
681
- const extra = rest.filter((a) => a.startsWith('-'));
682
- if (extra.length)
683
- fail(`explain only takes --demo (got ${extra.join(' ')})`);
707
+ let demo = false;
708
+ let offline = false;
709
+ let domain;
710
+ const rest = [];
711
+ for (let i = 0; i < argv.length; i++) {
712
+ const a = argv[i];
713
+ if (a === '--demo')
714
+ demo = true;
715
+ else if (a === '--offline')
716
+ offline = true;
717
+ else if (a === '--domain') {
718
+ const v = argv[++i];
719
+ if (!v || v.startsWith('--'))
720
+ fail('--domain needs a value');
721
+ domain = cleanDomain(v);
722
+ }
723
+ else if (a.startsWith('--domain='))
724
+ domain = cleanDomain(a.slice(9));
725
+ else if (a.startsWith('-'))
726
+ fail(`explain only takes --demo, --offline and --domain (got ${a})`);
727
+ else
728
+ rest.push(a);
729
+ }
684
730
  const [key, folder, more] = rest;
685
731
  if (!key || more)
686
732
  fail('explain needs one finding: a number from the report or its id, for example: launch-doctor explain 1');
687
733
  if (demo && folder)
688
734
  fail('--demo uses a built-in sample app, so leave out the folder');
689
- const request = (root) => scanProject({ root, offline: true });
735
+ // The same scan as the report and `prompt` (with the email DNS check unless --offline), so n is the same finding.
736
+ const request = (root) => scanProject({ root, offline: demo || offline, domain });
690
737
  const report = demo ? await withDemo(request) : await request(core(() => projectRoot(folder ?? '.')));
738
+ if (report.filesScanned === 0)
739
+ fail(noProjectFiles(report.root));
691
740
  const finding = findFinding(report, key);
692
741
  if (!finding)
693
742
  fail(`No finding ${key} in this project. Run launch-doctor first to see the numbers and ids.`);
@@ -710,14 +759,21 @@ async function explain(argv) {
710
759
  ...(d.rotate ? ['', ` ${bold('Rotate the key first:')} ${d.rotate}`] : []),
711
760
  ...(d.usage ? [` ${bold('Check whether someone used it:')} ${d.usage}`] : []),
712
761
  '',
713
- ` ${dim(`The fix prompt: launch-doctor prompt ${d.number}${demo ? ' --demo' : folder ? ` ${folder}` : ''} --copy`)}`,
762
+ ` ${dim(`The fix prompt: npx launch-doctor prompt ${d.number}${demo ? ' --demo' : folder ? ` ${shellArg(folder)}` : ''} --copy`)}`,
714
763
  '',
715
764
  ];
716
765
  process.stdout.write(`${out.join('\n')}\n`);
717
766
  }
718
767
  async function main() {
719
- if (process.argv[2] === 'init')
720
- return init(process.argv.slice(3));
768
+ if (process.argv[2] === 'init') {
769
+ // A file init can't write (a read-only folder, a file where a folder should be) is explained, not a crash.
770
+ try {
771
+ return init(process.argv.slice(3));
772
+ }
773
+ catch (err) {
774
+ fail(`init couldn't write its files: ${err.message}`);
775
+ }
776
+ }
721
777
  if (process.argv[2] === 'scan')
722
778
  return scan(process.argv.slice(3));
723
779
  if (process.argv[2] === 'mcp')
@@ -877,8 +933,8 @@ async function main() {
877
933
  if (args.report) {
878
934
  const path = join(root, REPORT_FILE);
879
935
  try {
880
- mkdirSync(dirname(path), { recursive: true });
881
- writeRegularFile(path, renderReportMd(report, { target: args.path ? ` ${shellArg(args.path)}` : '' }));
936
+ // Never through a .launchdoctor that is a link to another folder: writeInside refuses one.
937
+ writeInside(root, REPORT_FILE, renderReportMd(report, { target: args.path ? ` ${shellArg(args.path)}` : '' }));
882
938
  const rel = relative(process.cwd(), path);
883
939
  reportFile = rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : path;
884
940
  }
@@ -937,6 +993,10 @@ async function main() {
937
993
  process.stdout.write(short
938
994
  ? renderShortReport(report, { fixFile, reportFile, lastRecorded, banner: showBanner, target, demo: args.demo })
939
995
  : renderReport(report, { fixFile, lastRecorded, banner: showBanner }));
996
+ // Run in the wrong folder (a home folder, the Desktop), the scan mixes several projects into one grade.
997
+ const projects = short && !args.demo ? separateProjects(root) : null;
998
+ if (projects)
999
+ process.stdout.write(separateProjectsNote(root, projects));
940
1000
  }
941
1001
  if (recorded)
942
1002
  (args.json ? process.stderr : process.stdout).write(` ${dim(recorded)}\n\n`);
package/dist/src/git.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /** Flags for every command that prints a diff or compares files (log -p, diff). */
1
+ /** Flags for every command that prints a diff or compares files (log -p, diff). See the notes above. */
2
2
  export declare const SAFE_DIFF: string[];
3
3
  /** No git command we run should take this long; a hang (a FIFO for a config file, for example) is cut off. */
4
4
  export declare const GIT_TIMEOUT_MS = 60000;
package/dist/src/git.js CHANGED
@@ -13,7 +13,10 @@ import { devNull } from 'node:os';
13
13
  * - every filter driver the configuration names gets an empty clean, smudge and process command (git runs
14
14
  * nothing for an empty one), wherever the attributes that select it come from (.gitattributes,
15
15
  * .git/info/attributes or core.attributesFile);
16
- * - log and diff calls also pass --no-textconv and --no-ext-diff (see SAFE_DIFF).
16
+ * - log and diff calls also pass --no-textconv and --no-ext-diff (see SAFE_DIFF);
17
+ * - and --ignore-submodules=all: otherwise `git diff` runs `git status` inside each checked-out submodule, where the
18
+ * submodule's own config (.git/modules/<name>/config, which a zip of the project can hold) applies, and its filter
19
+ * drivers are ones this repository's config doesn't name, so they can't be emptied here.
17
20
  *
18
21
  * When a driver name can't be overridden on the command line, git is treated as unavailable.
19
22
  */
@@ -21,8 +24,8 @@ import { devNull } from 'node:os';
21
24
  const FIXED = ['--no-pager', '-c', 'core.fsmonitor=false', '-c', 'log.showSignature=false'];
22
25
  /** Hooks are looked up in the null device, so none can run (git status-like commands run post-index-change). */
23
26
  const NO_HOOKS = ['-c', `core.hooksPath=${devNull}`];
24
- /** Flags for every command that prints a diff or compares files (log -p, diff). */
25
- export const SAFE_DIFF = ['--no-textconv', '--no-ext-diff'];
27
+ /** Flags for every command that prints a diff or compares files (log -p, diff). See the notes above. */
28
+ export const SAFE_DIFF = ['--no-textconv', '--no-ext-diff', '--ignore-submodules=all'];
26
29
  /** No git command we run should take this long; a hang (a FIFO for a config file, for example) is cut off. */
27
30
  export const GIT_TIMEOUT_MS = 60_000;
28
31
  const overrideCache = new Map();
@@ -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") >>>';
@@ -44,8 +44,13 @@ export declare const GITIGNORE_LINE = ".launchdoctor/";
44
44
  * .gitignore that is a link or a special file is left alone, like every file Launch Doctor writes.
45
45
  */
46
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;
47
52
  /**
48
53
  * `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.
54
+ * Nothing is written: the user pastes them where they want. On Windows, Claude Code needs `cmd /c` to start npx.
50
55
  */
51
- export declare function mcpSetupText(root: string, pkg: string): string;
56
+ export declare function mcpSetupText(root: string, pkg: string, platform?: NodeJS.Platform): string;
package/dist/src/init.js CHANGED
@@ -1,7 +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
3
  import { CONFIG_FILE_MAX_BYTES } from './project.js';
4
- import { entryKind, readRegularFile, writeRegularFile } from './safe-fs.js';
4
+ import { entryKind, pathInside, readRegularFile, writeRegularFile } from './safe-fs.js';
5
5
  import { version } from './version.js';
6
6
  /** The same workflow as the README's "CI integration" example. */
7
7
  export const WORKFLOW_TEMPLATE = `name: Launch Doctor
@@ -152,13 +152,13 @@ export function runInit(root, { monitor = false } = {}) {
152
152
  ];
153
153
  const result = { created: [], skipped: [] };
154
154
  for (const [rel, content] of files) {
155
- const full = join(root, rel);
156
- 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') {
157
157
  result.skipped.push(rel);
158
158
  continue;
159
159
  }
160
- mkdirSync(dirname(full), { recursive: true });
161
- 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' });
162
162
  result.created.push(rel);
163
163
  }
164
164
  return result;
@@ -184,11 +184,18 @@ export function ensureGitignore(root) {
184
184
  writeRegularFile(path, `${text}${text === '' || text.endsWith('\n') ? '' : '\n'}${GITIGNORE_LINE}\n`);
185
185
  return 'updated';
186
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
+ }
187
194
  /**
188
195
  * `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.
196
+ * Nothing is written: the user pastes them where they want. On Windows, Claude Code needs `cmd /c` to start npx.
190
197
  */
191
- export function mcpSetupText(root, pkg) {
198
+ export function mcpSetupText(root, pkg, platform = process.platform) {
192
199
  const desktopArgs = ['-y', pkg, 'mcp', root];
193
200
  const projectArgs = ['-y', pkg, 'mcp'];
194
201
  const json = (args) => JSON.stringify({ mcpServers: { 'launch-doctor': { command: 'npx', args } } }, null, 2)
@@ -199,7 +206,12 @@ export function mcpSetupText(root, pkg) {
199
206
  '',
200
207
  ' Claude Code (run in this project folder):',
201
208
  '',
202
- ` claude mcp add launch-doctor -- npx -y "${pkg}" mcp`,
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
+ : []),
203
215
  '',
204
216
  ' Cursor: add this to .cursor/mcp.json in this project:',
205
217
  '',
package/dist/src/mcp.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { isAbsolute, relative } from 'node:path';
1
3
  import { createInterface } from 'node:readline';
2
4
  import { shortWhere } from './checks/common.js';
3
5
  import { CoreError, coverageNotes, findFinding, findingDetails, gradeHistory, normalizeRelative, projectRoot, promptNumber, rescan, scan, } from './core.js';
@@ -253,11 +255,18 @@ function rootFor(args, cwd) {
253
255
  const path = args.path;
254
256
  if (!path || path === '.')
255
257
  return base;
256
- return projectRoot(`${base}/${normalizeRelative(base, path)}`);
258
+ const root = projectRoot(`${base}/${normalizeRelative(base, path)}`);
259
+ // normalizeRelative compares the paths as text. A link inside the folder (a symlink, or a junction on Windows)
260
+ // could still lead outside it, so the real paths are compared too.
261
+ const rel = relative(realpathSync.native(base), realpathSync.native(root));
262
+ if (rel.startsWith('..') || isAbsolute(rel))
263
+ throw new CoreError('usage', `${path} is outside the project folder`);
264
+ return root;
257
265
  }
258
266
  /**
259
267
  * The last full scan of each folder, so explain_finding, fix_prompt and rescan can find an id without scanning again.
260
- * Only kept for this server process; a finding whose file changed since then gets a fresh scan.
268
+ * Only kept for this server process. An id or number that isn't in it gets a fresh scan; rescan doesn't change it, so
269
+ * numbers keep meaning what the last scan_project said.
261
270
  */
262
271
  const lastScans = new Map();
263
272
  async function fullScan(root, args = {}) {
@@ -20,4 +20,13 @@ export declare function unsupportedLanguage(root: string, report: Report): {
20
20
  language: string;
21
21
  marker: string;
22
22
  } | null;
23
+ /**
24
+ * Folders below `root` (three levels at most) that hold a project of their own, when `root` itself has no project
25
+ * file. Run in a home folder or on the Desktop, a scan mixes them all into one grade. Null when `root` is a project,
26
+ * or a workspace root (a monorepo, see hasWorkspaceConfig), or when fewer than two are found. Only folder names are
27
+ * read, at most 2,000 folders.
28
+ */
29
+ export declare function separateProjects(root: string): string[] | null;
30
+ /** The note under the report for separateProjects: what they are, and how to check one. */
31
+ export declare function separateProjectsNote(root: string, projects: string[], cwd?: string): string;
23
32
  export {};
@@ -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
+ }
@@ -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;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launch-doctor",
3
- "version": "0.4.3",
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": {