launch-doctor 0.3.0 → 0.4.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +77 -6
  2. package/LICENSE +1 -0
  3. package/README.md +95 -20
  4. package/dist/src/access.d.ts +52 -0
  5. package/dist/src/access.js +482 -0
  6. package/dist/src/baseline.d.ts +6 -3
  7. package/dist/src/baseline.js +15 -8
  8. package/dist/src/changed.d.ts +12 -0
  9. package/dist/src/changed.js +34 -0
  10. package/dist/src/checks/access.d.ts +7 -0
  11. package/dist/src/checks/access.js +868 -0
  12. package/dist/src/checks/costs.d.ts +7 -0
  13. package/dist/src/checks/costs.js +14 -6
  14. package/dist/src/checks/database.js +79 -3
  15. package/dist/src/checks/first-impressions.js +22 -2
  16. package/dist/src/checks/legal.js +3 -1
  17. package/dist/src/checks/monitoring.js +8 -5
  18. package/dist/src/checks/payments.js +10 -2
  19. package/dist/src/checks/secrets.d.ts +8 -0
  20. package/dist/src/checks/secrets.js +82 -9
  21. package/dist/src/checks/supabase-storage.d.ts +31 -0
  22. package/dist/src/checks/supabase-storage.js +216 -0
  23. package/dist/src/cli.js +111 -9
  24. package/dist/src/demo.js +1 -0
  25. package/dist/src/detect.d.ts +1 -1
  26. package/dist/src/detect.js +1 -1
  27. package/dist/src/fixes.js +8 -5
  28. package/dist/src/git.d.ts +25 -0
  29. package/dist/src/git.js +121 -0
  30. package/dist/src/github.d.ts +11 -1
  31. package/dist/src/github.js +56 -14
  32. package/dist/src/history.js +17 -3
  33. package/dist/src/hook.d.ts +13 -0
  34. package/dist/src/hook.js +96 -0
  35. package/dist/src/hooks-setup.d.ts +24 -0
  36. package/dist/src/hooks-setup.js +187 -0
  37. package/dist/src/ignore.d.ts +36 -0
  38. package/dist/src/ignore.js +164 -0
  39. package/dist/src/index.js +28 -3
  40. package/dist/src/live.d.ts +9 -0
  41. package/dist/src/live.js +73 -22
  42. package/dist/src/mcp.js +7 -2
  43. package/dist/src/net-guard.d.ts +34 -0
  44. package/dist/src/net-guard.js +144 -0
  45. package/dist/src/project.d.ts +34 -5
  46. package/dist/src/project.js +145 -111
  47. package/dist/src/report.d.ts +2 -0
  48. package/dist/src/report.js +11 -0
  49. package/dist/src/routes.d.ts +10 -0
  50. package/dist/src/routes.js +21 -4
  51. package/dist/src/safe-fs.d.ts +19 -0
  52. package/dist/src/safe-fs.js +77 -0
  53. package/dist/src/sanitize.d.ts +17 -0
  54. package/dist/src/sanitize.js +90 -0
  55. package/dist/src/sarif.js +1 -1
  56. package/dist/src/summary.d.ts +4 -0
  57. package/dist/src/summary.js +9 -4
  58. package/dist/src/types.d.ts +24 -0
  59. package/dist/src/util.d.ts +1 -1
  60. package/dist/src/util.js +1 -1
  61. package/package.json +9 -5
@@ -0,0 +1,77 @@
1
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, writeFileSync } from 'node:fs';
2
+ /**
3
+ * Reading Launch Doctor's own files (.launchdoctorignore, the baseline, and the config file planned for R7) from a
4
+ * project that may be hostile.
5
+ *
6
+ * Only a regular file is read. A symlink (which could point outside the project, or at /dev/zero), a FIFO (opening
7
+ * one blocks until someone writes to it), a device or a folder counts as no file at all. The file is checked
8
+ * before it is opened, opened without following links or blocking where the OS supports that, and checked again
9
+ * once open, so swapping it in between doesn't help.
10
+ */
11
+ export function readRegularFile(path, maxBytes) {
12
+ let before;
13
+ try {
14
+ before = lstatSync(path);
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ if (!before.isFile() || before.size > maxBytes)
20
+ return null;
21
+ let fd;
22
+ try {
23
+ // O_NOFOLLOW and O_NONBLOCK don't exist on Windows (they are undefined there, so they add nothing).
24
+ fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ try {
30
+ const after = fstatSync(fd);
31
+ if (!after.isFile() || after.size > maxBytes || after.ino !== before.ino || after.dev !== before.dev)
32
+ return null;
33
+ return readFileSync(fd, 'utf8');
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ finally {
39
+ closeSync(fd);
40
+ }
41
+ }
42
+ /**
43
+ * Write `content` to `path`, which must be a regular file or not exist yet. A symlink planted in a project (say,
44
+ * LAUNCH_FIXES.md pointing at ~/.bashrc) would otherwise make a scan overwrite a file outside it, so a link, FIFO,
45
+ * device or folder there is refused with an error instead. Where the OS supports it, the file is also opened
46
+ * without following links or blocking.
47
+ */
48
+ export function writeRegularFile(path, content) {
49
+ const kind = entryKind(path);
50
+ if (kind !== 'file' && kind !== 'missing') {
51
+ throw new Error('it is a link or a special file, not a regular file, so it was not overwritten');
52
+ }
53
+ const flags = constants.O_WRONLY |
54
+ constants.O_CREAT |
55
+ constants.O_TRUNC |
56
+ (constants.O_NOFOLLOW ?? 0) |
57
+ (constants.O_NONBLOCK ?? 0);
58
+ const fd = openSync(path, flags, 0o666);
59
+ try {
60
+ if (!fstatSync(fd).isFile())
61
+ throw new Error('it is not a regular file, so it was not overwritten');
62
+ writeFileSync(fd, content);
63
+ }
64
+ finally {
65
+ closeSync(fd);
66
+ }
67
+ }
68
+ /** What kind of entry `path` is, without following a link or opening it. */
69
+ export function entryKind(path) {
70
+ try {
71
+ const st = lstatSync(path);
72
+ return st.isFile() ? 'file' : st.isDirectory() ? 'dir' : 'other';
73
+ }
74
+ catch {
75
+ return 'missing';
76
+ }
77
+ }
@@ -0,0 +1,17 @@
1
+ import type { Report } from './types.js';
2
+ /** `text` without terminal control characters (tab and newline are kept). */
3
+ export declare function stripControl(text: string): string;
4
+ /** The report with control characters removed from every string, for every output (terminal, JSON, Markdown). */
5
+ export declare function sanitizeReport(report: Report): Report;
6
+ /**
7
+ * Markdown-safe inline text: everything outside backtick code spans is escaped, @mentions are broken, and with
8
+ * `oneLine`, line breaks become spaces. A backtick in a file name can end a code span early; whatever follows is
9
+ * then outside one and gets escaped like any other text.
10
+ */
11
+ export declare function md(text: string, { oneLine }?: {
12
+ oneLine?: boolean | undefined;
13
+ }): string;
14
+ /** `text` as an inline code span that nothing inside it can end early. */
15
+ export declare function mdCode(text: string): string;
16
+ /** Safe inside an HTML comment: "--" and ">" can't end the comment early. */
17
+ export declare function htmlCommentSafe(text: string): string;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Text taken from scanned files (file names, table names, package names, URLs) ends up in finding titles and
3
+ * explanations. Before any of it is shown:
4
+ *
5
+ * - terminal control characters are removed everywhere (sanitizeReport), so a file can't clear the screen, change
6
+ * the window title or hide text with escape sequences, or reorder text with bidirectional controls;
7
+ * - in Markdown (pull request comments, the job summary, LAUNCH_FIXES.md), it is escaped (md, mdCode), so it can't
8
+ * mention people (@name notifies them on GitHub), add links or images, or inject HTML.
9
+ */
10
+ // C0 controls except tab and newline, DEL, C1 controls, and the Unicode bidirectional controls.
11
+ // biome-ignore lint/complexity/useRegexLiterals: kept as a string so no tool turns the escapes into raw characters
12
+ const CONTROL = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069]', 'g');
13
+ // biome-ignore lint/complexity/useRegexLiterals: as above (the Unicode line and paragraph separators)
14
+ const LINE_BREAKS = new RegExp('[\\u2028\\u2029]', 'g');
15
+ /** `text` without terminal control characters (tab and newline are kept). */
16
+ export function stripControl(text) {
17
+ return text.replace(CONTROL, '').replace(LINE_BREAKS, '\n');
18
+ }
19
+ /** A copy of `value` with stripControl applied to every string in it. */
20
+ function deepStrip(value) {
21
+ if (typeof value === 'string')
22
+ return stripControl(value);
23
+ if (Array.isArray(value))
24
+ return value.map(deepStrip);
25
+ if (value && typeof value === 'object') {
26
+ const out = {};
27
+ for (const [k, v] of Object.entries(value))
28
+ out[k] = deepStrip(v);
29
+ return out;
30
+ }
31
+ return value;
32
+ }
33
+ /** The report with control characters removed from every string, for every output (terminal, JSON, Markdown). */
34
+ export function sanitizeReport(report) {
35
+ return deepStrip(report);
36
+ }
37
+ /** An @mention can't notify anyone once a zero-width space follows the @. */
38
+ function breakMentions(text) {
39
+ return text.replace(/@(?=[A-Za-z0-9])/g, '@​');
40
+ }
41
+ /** Escape Markdown and HTML in plain text, keeping `code spans` as they are (they render literally anyway). */
42
+ function escapePlain(text) {
43
+ return breakMentions(text
44
+ .replace(/&/g, '&')
45
+ .replace(/</g, '&lt;')
46
+ .replace(/>/g, '&gt;')
47
+ .replace(/[\\*_[\]()!#|~]/g, '\\$&'));
48
+ }
49
+ /**
50
+ * Markdown-safe inline text: everything outside backtick code spans is escaped, @mentions are broken, and with
51
+ * `oneLine`, line breaks become spaces. A backtick in a file name can end a code span early; whatever follows is
52
+ * then outside one and gets escaped like any other text.
53
+ */
54
+ export function md(text, { oneLine = true } = {}) {
55
+ const s = oneLine ? text.replace(/\r?\n/g, ' ') : text;
56
+ let out = '';
57
+ let i = 0;
58
+ while (i < s.length) {
59
+ const open = s.indexOf('`', i);
60
+ if (open < 0) {
61
+ out += escapePlain(s.slice(i));
62
+ break;
63
+ }
64
+ const run = /^`+/.exec(s.slice(open))[0];
65
+ const close = s.indexOf(run, open + run.length);
66
+ if (close < 0) {
67
+ out += escapePlain(s.slice(i, open)) + '\\`'.repeat(run.length);
68
+ i = open + run.length;
69
+ continue;
70
+ }
71
+ out += escapePlain(s.slice(i, open));
72
+ // Inside a code span nothing renders and @names don't notify, but a "|" still ends a table cell.
73
+ out += s.slice(open, close + run.length).replace(/\|/g, '\\|');
74
+ i = close + run.length;
75
+ }
76
+ return out;
77
+ }
78
+ /** `text` as an inline code span that nothing inside it can end early. */
79
+ export function mdCode(text) {
80
+ const s = text.replace(/\r?\n/g, ' ');
81
+ const longest = Math.max(0, ...(s.match(/`+/g) ?? []).map((m) => m.length));
82
+ const ticks = '`'.repeat(longest + 1);
83
+ const pad = s.startsWith('`') || s.endsWith('`') ? ' ' : '';
84
+ // (No mention-breaking here: @names in code don't notify, and Next.js paths like app/@modal must copy cleanly.)
85
+ return `${ticks}${pad}${s.replace(/\|/g, '\\|')}${pad}${ticks}`;
86
+ }
87
+ /** Safe inside an HTML comment: "--" and ">" can't end the comment early. */
88
+ export function htmlCommentSafe(text) {
89
+ return text.replace(/-(?=-)/g, '-​').replace(/[<>]/g, '');
90
+ }
package/dist/src/sarif.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const SCHEMA = 'https://json.schemastore.org/sarif-2.1.0.json';
2
- const INFO_URI = 'https://github.com/SHARAJ379/launch-doctor';
2
+ const INFO_URI = 'https://github.com/SHARAJ379/Launch-Doctor';
3
3
  /**
4
4
  * SARIF 2.1.0 output, e.g. for GitHub code scanning.
5
5
  * One rule per finding id; one result per finding, with a path relative to the project root.
@@ -1,4 +1,8 @@
1
1
  import type { Report } from './types.js';
2
+ /**
3
+ * Text for one line of Markdown (a list item or a table cell): text from scanned files can't add links, HTML or
4
+ * @mentions, and "|" and line breaks can't break a table. See src/sanitize.ts.
5
+ */
2
6
  export declare function escapeCell(text: string): string;
3
7
  /** The per-category Markdown table shared by the job summary and the pull request comment. */
4
8
  export declare function categoryTable(report: Report): string[];
@@ -1,10 +1,15 @@
1
1
  import { shortWhere } from './checks/common.js';
2
+ import { md, mdCode } from './sanitize.js';
3
+ /**
4
+ * Text for one line of Markdown (a list item or a table cell): text from scanned files can't add links, HTML or
5
+ * @mentions, and "|" and line breaks can't break a table. See src/sanitize.ts.
6
+ */
2
7
  export function escapeCell(text) {
3
- return text.replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
8
+ return md(text);
4
9
  }
5
10
  function findingLine(f) {
6
- const where = f.location ? ` (\`${shortWhere(f.location)}\`)` : '';
7
- return `- ${escapeCell(f.title)}${where}`;
11
+ const where = f.location ? ` (${mdCode(shortWhere(f.location))})` : '';
12
+ return `- ${md(f.title)}${where}`;
8
13
  }
9
14
  /** The per-category Markdown table shared by the job summary and the pull request comment. */
10
15
  export function categoryTable(report) {
@@ -31,7 +36,7 @@ export function renderStepSummary(report) {
31
36
  const out = [
32
37
  `## Launch Doctor: grade ${report.grade}`,
33
38
  '',
34
- `**${escapeCell(report.verdict)}** · ${report.projectName} · ${report.filesScanned} ${report.mode === 'live' ? 'requests' : 'files'} checked`,
39
+ `**${escapeCell(report.verdict)}** · ${md(report.projectName)} · ${report.filesScanned} ${report.mode === 'live' ? 'requests' : 'files'} checked`,
35
40
  '',
36
41
  ...categoryTable(report),
37
42
  '',
@@ -63,12 +63,23 @@ export interface Report {
63
63
  stack: string[];
64
64
  filesScanned: number;
65
65
  truncated: boolean;
66
+ /** Set when the scan stopped reading files after 128 MB of text (some files were not checked). */
67
+ byteLimitReached?: true;
66
68
  /** Findings and checklist items silenced by .launchdoctorignore or inline launch-doctor-ignore comments. */
67
69
  ignored: number;
68
70
  /** Ids in .launchdoctorignore that no check can produce (probably typos). */
69
71
  unknownIgnoreIds: string[];
72
+ /** Lines of .launchdoctorignore past the first 1,000, which were not used. Absent when there were none. */
73
+ ignoreLinesSkipped?: number;
70
74
  /** Folders left out because they are separate git repositories (they have their own .git folder). */
71
75
  nestedRepos?: string[];
76
+ /**
77
+ * Set when only some files were reported on (--changed, --staged and the hooks). The grade then
78
+ * covers those files only, not the whole project.
79
+ */
80
+ partial?: {
81
+ files: string[];
82
+ };
72
83
  score: number;
73
84
  grade: Grade;
74
85
  verdict: string;
@@ -91,12 +102,25 @@ export interface Options {
91
102
  useGit?: boolean;
92
103
  /** Stop reading after this many files (default 20,000). */
93
104
  maxFiles?: number;
105
+ /** Stop reading files after this many bytes of text in total (default 128 MB). */
106
+ maxBytes?: number;
94
107
  /** Run only these category ids. */
95
108
  only?: string[];
96
109
  /** Skip these category ids. */
97
110
  skip?: string[];
111
+ /**
112
+ * Report only on these files (paths relative to the folder, with "/"). The whole project is still
113
+ * read, so checks that look across files keep working, but findings elsewhere, project-wide findings
114
+ * and the checklist are left out, and the email DNS lookups are skipped.
115
+ */
116
+ onlyFiles?: string[];
98
117
  /** Load .launchdoctor-baseline.json if present (default true). */
99
118
  baseline?: boolean;
119
+ /**
120
+ * Read .launchdoctorignore and .launchdoctor-baseline.json from this git ref (a branch, tag or commit)
121
+ * instead of the working folder. Used on pull requests, so the pull request can't silence its own findings.
122
+ */
123
+ configFrom?: string;
100
124
  /** Also scan git history for removed keys (opt-in). depth = how many commits. */
101
125
  history?: {
102
126
  depth: number;
@@ -1,5 +1,5 @@
1
1
  /** Where people report false alarms, misses and crashes. */
2
- export declare const ISSUES_URL = "https://github.com/SHARAJ379/launch-doctor/issues/new/choose";
2
+ export declare const ISSUES_URL = "https://github.com/SHARAJ379/Launch-Doctor/issues/new/choose";
3
3
  /** 1-based line number of a character index. */
4
4
  export declare function lineAt(text: string, index: number): number;
5
5
  /** The full text of the line containing `index`. */
package/dist/src/util.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Where people report false alarms, misses and crashes. */
2
- export const ISSUES_URL = 'https://github.com/SHARAJ379/launch-doctor/issues/new/choose';
2
+ export const ISSUES_URL = 'https://github.com/SHARAJ379/Launch-Doctor/issues/new/choose';
3
3
  /** 1-based line number of a character index. */
4
4
  export function lineAt(text, index) {
5
5
  let line = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launch-doctor",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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": {
@@ -22,6 +22,7 @@
22
22
  "format": "biome format --write .",
23
23
  "format:check": "biome format .",
24
24
  "test": "npm run build && node --test \"dist/test/**/*.test.js\"",
25
+ "stress": "npm run build && node scripts/stress/run.mjs",
25
26
  "start": "node dist/src/cli.js",
26
27
  "doctor": "npm run build && node dist/src/cli.js",
27
28
  "prepublishOnly": "npm test"
@@ -31,12 +32,12 @@
31
32
  },
32
33
  "repository": {
33
34
  "type": "git",
34
- "url": "git+https://github.com/SHARAJ379/launch-doctor.git"
35
+ "url": "git+https://github.com/SHARAJ379/Launch-Doctor.git"
35
36
  },
36
37
  "bugs": {
37
- "url": "https://github.com/SHARAJ379/launch-doctor/issues"
38
+ "url": "https://github.com/SHARAJ379/Launch-Doctor/issues"
38
39
  },
39
- "homepage": "https://github.com/SHARAJ379/launch-doctor#readme",
40
+ "homepage": "https://github.com/SHARAJ379/Launch-Doctor#readme",
40
41
  "keywords": [
41
42
  "launch-readiness",
42
43
  "production-readiness",
@@ -54,9 +55,12 @@
54
55
  "cli"
55
56
  ],
56
57
  "author": "Sharaj R Shetty",
58
+ "contributors": [
59
+ "Namay Singh (https://github.com/namaysingh3925)"
60
+ ],
57
61
  "license": "MIT",
58
62
  "devDependencies": {
59
- "@biomejs/biome": "2.6.7",
63
+ "@biomejs/biome": "2.6.9",
60
64
  "@types/node": "^26.6.6",
61
65
  "typescript": "^7.0.2"
62
66
  }