launch-doctor 0.2.1 → 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 (66) hide show
  1. package/CHANGELOG.md +105 -4
  2. package/LICENSE +1 -0
  3. package/README.md +239 -39
  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 +8 -0
  13. package/dist/src/checks/costs.js +54 -11
  14. package/dist/src/checks/database.js +201 -6
  15. package/dist/src/checks/first-impressions.js +247 -117
  16. package/dist/src/checks/legal.js +29 -13
  17. package/dist/src/checks/monitoring.js +47 -15
  18. package/dist/src/checks/payments.js +141 -6
  19. package/dist/src/checks/secrets.d.ts +8 -0
  20. package/dist/src/checks/secrets.js +185 -16
  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 +201 -12
  24. package/dist/src/demo.d.ts +13 -0
  25. package/dist/src/demo.js +59 -2
  26. package/dist/src/detect.d.ts +1 -1
  27. package/dist/src/detect.js +5 -2
  28. package/dist/src/fixes.js +10 -7
  29. package/dist/src/git.d.ts +25 -0
  30. package/dist/src/git.js +121 -0
  31. package/dist/src/github.d.ts +90 -0
  32. package/dist/src/github.js +330 -0
  33. package/dist/src/history.js +17 -3
  34. package/dist/src/hook.d.ts +13 -0
  35. package/dist/src/hook.js +96 -0
  36. package/dist/src/hooks-setup.d.ts +24 -0
  37. package/dist/src/hooks-setup.js +187 -0
  38. package/dist/src/ignore.d.ts +36 -0
  39. package/dist/src/ignore.js +164 -0
  40. package/dist/src/index.d.ts +1 -0
  41. package/dist/src/index.js +30 -3
  42. package/dist/src/init.d.ts +1 -1
  43. package/dist/src/init.js +2 -2
  44. package/dist/src/live.d.ts +9 -0
  45. package/dist/src/live.js +73 -22
  46. package/dist/src/mcp.d.ts +140 -0
  47. package/dist/src/mcp.js +386 -0
  48. package/dist/src/net-guard.d.ts +34 -0
  49. package/dist/src/net-guard.js +144 -0
  50. package/dist/src/project.d.ts +42 -5
  51. package/dist/src/project.js +237 -107
  52. package/dist/src/report.d.ts +4 -0
  53. package/dist/src/report.js +23 -1
  54. package/dist/src/routes.d.ts +10 -0
  55. package/dist/src/routes.js +21 -4
  56. package/dist/src/safe-fs.d.ts +19 -0
  57. package/dist/src/safe-fs.js +77 -0
  58. package/dist/src/sanitize.d.ts +17 -0
  59. package/dist/src/sanitize.js +90 -0
  60. package/dist/src/sarif.js +1 -1
  61. package/dist/src/summary.d.ts +7 -0
  62. package/dist/src/summary.js +26 -17
  63. package/dist/src/types.d.ts +26 -0
  64. package/dist/src/util.d.ts +2 -0
  65. package/dist/src/util.js +2 -0
  66. package/package.json +9 -5
package/dist/src/demo.js CHANGED
@@ -1,4 +1,4 @@
1
- import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
1
+ import { mkdirSync, mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
3
  import { dirname, join } from 'node:path';
4
4
  /** A random-looking (but fake) key, generated at runtime so no key-shaped string ships in the package. */
@@ -15,9 +15,65 @@ function fakeKey(prefix, length, seed) {
15
15
  }
16
16
  return prefix + out;
17
17
  }
18
+ const DEMO_PREFIX = 'launch-doctor-demo-';
19
+ /** A demo folder older than this was left behind by a run that was killed before it could clean up. */
20
+ const STALE_DEMO_MS = 60 * 60 * 1000;
21
+ /**
22
+ * Remove demo folders that killed runs left in the temp folder. Only folders named
23
+ * launch-doctor-demo-* that are over an hour old are touched, so a demo running in
24
+ * another terminal right now is left alone. Returns how many were removed.
25
+ */
26
+ export function sweepStaleDemos(now = Date.now(), dir = tmpdir()) {
27
+ let removed = 0;
28
+ let names;
29
+ try {
30
+ names = readdirSync(dir);
31
+ }
32
+ catch {
33
+ return 0;
34
+ }
35
+ for (const name of names) {
36
+ if (!name.startsWith(DEMO_PREFIX))
37
+ continue;
38
+ const path = join(dir, name);
39
+ try {
40
+ const stat = statSync(path);
41
+ if (!stat.isDirectory() || now - stat.mtimeMs < STALE_DEMO_MS)
42
+ continue;
43
+ rmSync(path, { recursive: true, force: true });
44
+ removed++;
45
+ }
46
+ catch {
47
+ // in use or already gone: leave it
48
+ }
49
+ }
50
+ return removed;
51
+ }
52
+ /**
53
+ * Delete the demo folder if the run is stopped with Ctrl+C (SIGINT), SIGTERM or SIGHUP.
54
+ * Register it before creating the folder: signal handlers run between JavaScript tasks,
55
+ * so the folder name is always known by the time one runs.
56
+ * Returns a function that removes the handlers again once the run has cleaned up normally.
57
+ */
58
+ export function removeOnSignal(getDir) {
59
+ const codes = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
60
+ const handler = (signal) => {
61
+ const dir = getDir();
62
+ if (dir)
63
+ rmSync(dir, { recursive: true, force: true });
64
+ process.exit(codes[signal] ?? 1);
65
+ };
66
+ for (const signal of Object.keys(codes))
67
+ process.once(signal, handler);
68
+ return () => {
69
+ for (const signal of Object.keys(codes))
70
+ process.removeListener(signal, handler);
71
+ };
72
+ }
18
73
  /** Writes a small "weekend project" with the classic launch mistakes and returns its folder. */
19
74
  export function createDemoProject() {
20
- const dir = mkdtempSync(join(tmpdir(), 'launch-doctor-demo-'));
75
+ sweepStaleDemos();
76
+ const dir = mkdtempSync(join(tmpdir(), DEMO_PREFIX));
21
77
  const openaiKey = fakeKey(['sk', 'proj', ''].join('-'), 40, 3);
22
78
  const stripeKey = fakeKey(['sk', 'live', ''].join('_'), 28, 7);
23
79
  const files = {
@@ -40,6 +96,7 @@ export function createDemoProject() {
40
96
  'src/lib/supabase.ts': "import { createClient } from '@supabase/supabase-js';\nexport const supabase = createClient(import.meta.env.VITE_SUPABASE_URL, import.meta.env.VITE_SUPABASE_ANON_KEY);\n",
41
97
  'src/lib/ai.ts': "import OpenAI from 'openai';\n\nconst openai = new OpenAI({ apiKey: import.meta.env.VITE_OPENAI_API_KEY, dangerouslyAllowBrowser: true });\n\nexport async function summarize(text: string) {\n return openai.chat.completions.create({ model: 'gpt-5-mini', messages: [{ role: 'user', content: text }] });\n}\n",
42
98
  'src/pages/Signup.tsx': "import { supabase } from '../lib/supabase';\n\nexport function Signup() {\n return <button onClick={() => supabase.auth.signUp({ email: '', password: '' })}>Create account</button>;\n}\n",
99
+ 'src/pages/Admin.tsx': "export function Admin({ user }: { user: { email: string } }) {\n if (user.email !== 'founder@example.com') return <p>Not allowed</p>;\n return <AllUsersTable />;\n}\n",
43
100
  'src/api.ts': "export const getNotes = () => fetch('http://localhost:3001/notes').then((r) => r.json());\n",
44
101
  'supabase/functions/stripe-webhook/index.ts': "Deno.serve(async (req) => {\n const event = await req.json();\n if (event.type === 'checkout.session.completed') {\n // mark the user as paid\n }\n return new Response('ok');\n});\n",
45
102
  'supabase/functions/welcome-email/index.ts': "import { Resend } from 'npm:resend';\nconst resend = new Resend(Deno.env.get('RESEND_API_KEY'));\nDeno.serve(async () => {\n await resend.emails.send({ from: 'onboarding@resend.dev', to: 'user@example.com', subject: 'Welcome!', html: '<p>Hi</p>' });\n return new Response('sent');\n});\n",
@@ -6,5 +6,5 @@ export declare function detectPayments(ctx: ProjectContext): boolean;
6
6
  /** Analytics that set cookies (cookieless tools like Plausible are left out on purpose). */
7
7
  export declare function detectCookieAnalytics(ctx: ProjectContext): boolean;
8
8
  export declare function detectEmailProviders(ctx: ProjectContext): string[];
9
- /** Common ways code checks who the user is. */
9
+ /** Common ways code checks who the user is. Test it on withoutImports(code) (routes.ts): an import checks nothing. */
10
10
  export declare const AUTH_CHECK_RE: RegExp;
@@ -47,6 +47,8 @@ export function detectDatabase(ctx) {
47
47
  ['better-sqlite3', 'SQLite'],
48
48
  ['sqlite3', 'SQLite'],
49
49
  ['convex', 'Convex'],
50
+ ['appwrite', 'Appwrite'],
51
+ ['node-appwrite', 'Appwrite'],
50
52
  ['@vercel/postgres', 'Vercel Postgres'],
51
53
  ['typeorm', 'TypeORM'],
52
54
  ['sequelize', 'Sequelize'],
@@ -79,7 +81,8 @@ export function detectPayments(ctx) {
79
81
  '@paypal/checkout-server-sdk',
80
82
  'cashfree-pg',
81
83
  '@cashfreepayments/cashfree-js',
82
- ]) || ctx.find(/https:\/\/buy\.stripe\.com\/|checkout\.razorpay\.com/, appCode, 1).length > 0);
84
+ ]) ||
85
+ ctx.find(/https:\/\/buy\.stripe\.com\/|checkout\.razorpay\.com|\.lemonsqueezy\.com\/(?:checkout|buy)\/|cdn\.paddle\.com\/paddle\//, appCode, 1).length > 0);
83
86
  }
84
87
  /** Analytics that set cookies (cookieless tools like Plausible are left out on purpose). */
85
88
  export function detectCookieAnalytics(ctx) {
@@ -125,5 +128,5 @@ export function detectEmailProviders(ctx) {
125
128
  }
126
129
  return out;
127
130
  }
128
- /** Common ways code checks who the user is. */
131
+ /** Common ways code checks who the user is. Test it on withoutImports(code) (routes.ts): an import checks nothing. */
129
132
  export const AUTH_CHECK_RE = /getServerSession|\bauth\s*\(\s*\)|currentUser\s*\(|getAuth\s*\(|\.getUser\s*\(|getSession\s*\(|verifyIdToken|verifyToken|jwtVerify|jwt\.verify|clerkClient|withAuth|requireAuth|requireUser|isAuthenticated|ensureAuth|session\?\.user|session\.user|req\.user|request\.user|ctx\.user|locals\.user|validateRequest|getKindeServerSession|getToken\s*\(/;
package/dist/src/fixes.js CHANGED
@@ -1,18 +1,21 @@
1
1
  import { shortWhere } from './checks/common.js';
2
- import { plural } from './util.js';
2
+ import { md, mdCode } from './sanitize.js';
3
+ import { ISSUES_URL, plural } from './util.js';
3
4
  function fence(text) {
4
5
  // Use a fence longer than any backtick run inside the prompt.
5
6
  const longest = Math.max(2, ...(text.match(/`+/g) ?? []).map((m) => m.length));
6
7
  const ticks = '`'.repeat(longest + 1);
7
8
  return `${ticks}text\n${text}\n${ticks}`;
8
9
  }
10
+ // Titles, explanations and paths can hold text from scanned files, so they go through md() / mdCode() (no links,
11
+ // HTML or @mentions); the prompts are in code fences, where nothing renders.
9
12
  function section(f, n) {
10
- const parts = [`### ${n}. ${f.title}`, ''];
13
+ const parts = [`### ${n}. ${md(f.title)}`, ''];
11
14
  if (f.location)
12
- parts.push(`**Where:** \`${shortWhere(f.location)}\``, '');
15
+ parts.push(`**Where:** ${mdCode(shortWhere(f.location))}`, '');
13
16
  if (f.baseline)
14
17
  parts.push('_Existing issue, recorded in .launchdoctor-baseline.json._', '');
15
- parts.push(`**Why it matters:** ${f.why}`, '', '**Prompt to paste:**', '', fence(f.fixPrompt), '');
18
+ parts.push(`**Why it matters:** ${md(f.why, { oneLine: false })}`, '', '**Prompt to paste:**', '', fence(f.fixPrompt), '');
16
19
  parts.push(`<sub>Not relevant to your app? Add \`${f.id}\` to a \`.launchdoctorignore\` file.</sub>`, '');
17
20
  return parts.join('\n');
18
21
  }
@@ -25,7 +28,7 @@ export function renderFixes(report) {
25
28
  const manual = report.categories.flatMap((c) => c.manual);
26
29
  const date = report.generatedAt.slice(0, 10);
27
30
  const out = [
28
- `# Launch Doctor fixes for ${report.projectName}`,
31
+ `# Launch Doctor fixes for ${md(report.projectName)}`,
29
32
  '',
30
33
  `**Grade: ${report.grade}** · ${report.verdict} · ${plural(critical.length, 'critical issue')} · ${plural(warnings.length, 'warning')} · checked ${date}`,
31
34
  '',
@@ -59,9 +62,9 @@ export function renderFixes(report) {
59
62
  out.push('## Check yourself', '');
60
63
  out.push("Things Launch Doctor can't see from your code:", '');
61
64
  for (const m of manual)
62
- out.push(`- [ ] **${m.title}** - ${m.how}`);
65
+ out.push(`- [ ] **${md(m.title)}** - ${md(m.how)}`);
63
66
  out.push('');
64
67
  }
65
- out.push('---', '', `_Generated by [Launch Doctor](https://www.npmjs.com/package/launch-doctor) v${report.version}. Safe to delete or add to .gitignore._`, '');
68
+ out.push('---', '', `_Generated by [Launch Doctor](https://www.npmjs.com/package/launch-doctor) v${report.version}. Safe to delete or add to .gitignore._`, '', `_A finding that is wrong, or a problem it missed? Please [report it](${ISSUES_URL}). Launch Doctor reads code with pattern rules, so it can make mistakes both ways._`, '');
66
69
  return out.join('\n');
67
70
  }
@@ -0,0 +1,25 @@
1
+ /** Flags for every command that prints a diff or compares files (log -p, diff). */
2
+ export declare const SAFE_DIFF: string[];
3
+ /** No git command we run should take this long; a hang (a FIFO for a config file, for example) is cut off. */
4
+ export declare const GIT_TIMEOUT_MS = 60000;
5
+ /**
6
+ * The full argument list for a git command run in `cwd`, or null when it isn't safe to run git there.
7
+ * Every git call goes through here (a test checks this).
8
+ */
9
+ export declare function gitArgs(cwd: string, args: string[], { ownHooks }?: {
10
+ ownHooks?: boolean | undefined;
11
+ }): string[] | null;
12
+ /** Run git in `cwd`. Returns stdout, or null when git fails, isn't installed, times out or isn't safe to run. */
13
+ export declare function git(cwd: string, args: string[]): string | null;
14
+ /**
15
+ * The repository's own hooks folder (core.hooksPath, or .git/hooks), for `init --hooks`, which you run on your own
16
+ * project to install a hook there. The only git command that sees the repository's hooks setting; it runs nothing.
17
+ */
18
+ export declare function gitHooksDir(cwd: string): string | null;
19
+ /** Like git(), but also reports the exit code, for commands where exit code 1 is an answer, not a failure. */
20
+ export declare function gitStatus(cwd: string, args: string[], opts?: {
21
+ ownHooks?: boolean;
22
+ }): {
23
+ stdout: string | null;
24
+ status: number | null;
25
+ };
@@ -0,0 +1,121 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { devNull } from 'node:os';
3
+ /**
4
+ * Running git safely inside a folder we don't trust.
5
+ *
6
+ * A project downloaded with its .git folder (a zip, a tarball, a copied folder; a plain `git clone` never copies
7
+ * .git/config) can set git options that run programs: core.fsmonitor, filter drivers (clean, smudge, process),
8
+ * diff drivers (textconv, command), diff.external, the pager, signature checks and hooks. Every git command
9
+ * Launch Doctor runs gets these settings, so none of them can run:
10
+ *
11
+ * - core.fsmonitor=false, no pager, no signature checks, hooks looked up in the null device (except for the one
12
+ * read-only lookup of the hooks folder that `init --hooks` makes, see gitHooksDir);
13
+ * - every filter driver the configuration names gets an empty clean, smudge and process command (git runs
14
+ * nothing for an empty one), wherever the attributes that select it come from (.gitattributes,
15
+ * .git/info/attributes or core.attributesFile);
16
+ * - log and diff calls also pass --no-textconv and --no-ext-diff (see SAFE_DIFF).
17
+ *
18
+ * When a driver name can't be overridden on the command line, git is treated as unavailable.
19
+ */
20
+ /** Settings every git command gets. */
21
+ const FIXED = ['--no-pager', '-c', 'core.fsmonitor=false', '-c', 'log.showSignature=false'];
22
+ /** Hooks are looked up in the null device, so none can run (git status-like commands run post-index-change). */
23
+ 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'];
26
+ /** No git command we run should take this long; a hang (a FIFO for a config file, for example) is cut off. */
27
+ export const GIT_TIMEOUT_MS = 60_000;
28
+ const overrideCache = new Map();
29
+ /**
30
+ * `-c` settings that empty every filter driver the configuration seen from `cwd` defines, or null when one
31
+ * can't be overridden safely. Reading the configuration runs nothing.
32
+ */
33
+ function driverOverrides(cwd) {
34
+ const cached = overrideCache.get(cwd);
35
+ if (cached !== undefined)
36
+ return cached;
37
+ let names;
38
+ try {
39
+ const out = execFileSync('git', [...FIXED, 'config', '-z', '--name-only', '--get-regexp', '^filter\\.'], {
40
+ cwd,
41
+ stdio: ['ignore', 'pipe', 'ignore'],
42
+ timeout: GIT_TIMEOUT_MS,
43
+ maxBuffer: 16 * 1024 * 1024,
44
+ }).toString();
45
+ names = out.split('\0').filter(Boolean);
46
+ }
47
+ catch (err) {
48
+ // Exit code 1 means no filter is configured. Any other failure (no git, a broken config, a timeout) means we
49
+ // can't know which drivers exist, so git isn't run at all.
50
+ if (err.status !== 1) {
51
+ overrideCache.set(cwd, null);
52
+ return null;
53
+ }
54
+ names = [];
55
+ }
56
+ const drivers = new Set();
57
+ let unsafe = false;
58
+ for (const name of names) {
59
+ const m = /^filter\.(.+)\.[^.]+$/s.exec(name);
60
+ if (!m)
61
+ continue;
62
+ const driver = m[1];
63
+ // "-c" splits the setting at its first "="; such a name can't be overridden, so refuse to run git at all.
64
+ if (/[=\n\0]/.test(driver))
65
+ unsafe = true;
66
+ drivers.add(driver);
67
+ }
68
+ const result = unsafe
69
+ ? null
70
+ : [...drivers].flatMap((d) => [
71
+ '-c',
72
+ `filter.${d}.clean=`,
73
+ '-c',
74
+ `filter.${d}.smudge=`,
75
+ '-c',
76
+ `filter.${d}.process=`,
77
+ '-c',
78
+ `filter.${d}.required=false`,
79
+ ]);
80
+ overrideCache.set(cwd, result);
81
+ return result;
82
+ }
83
+ /**
84
+ * The full argument list for a git command run in `cwd`, or null when it isn't safe to run git there.
85
+ * Every git call goes through here (a test checks this).
86
+ */
87
+ export function gitArgs(cwd, args, { ownHooks = false } = {}) {
88
+ const overrides = driverOverrides(cwd);
89
+ if (overrides === null)
90
+ return null;
91
+ return [...FIXED, ...(ownHooks ? [] : NO_HOOKS), ...overrides, ...args];
92
+ }
93
+ /** Run git in `cwd`. Returns stdout, or null when git fails, isn't installed, times out or isn't safe to run. */
94
+ export function git(cwd, args) {
95
+ return gitStatus(cwd, args).stdout;
96
+ }
97
+ /**
98
+ * The repository's own hooks folder (core.hooksPath, or .git/hooks), for `init --hooks`, which you run on your own
99
+ * project to install a hook there. The only git command that sees the repository's hooks setting; it runs nothing.
100
+ */
101
+ export function gitHooksDir(cwd) {
102
+ return gitStatus(cwd, ['rev-parse', '--git-path', 'hooks'], { ownHooks: true }).stdout?.trim() || null;
103
+ }
104
+ /** Like git(), but also reports the exit code, for commands where exit code 1 is an answer, not a failure. */
105
+ export function gitStatus(cwd, args, opts = {}) {
106
+ const full = gitArgs(cwd, args, opts);
107
+ if (!full)
108
+ return { stdout: null, status: null };
109
+ try {
110
+ const stdout = execFileSync('git', full, {
111
+ cwd,
112
+ stdio: ['ignore', 'pipe', 'ignore'],
113
+ maxBuffer: 64 * 1024 * 1024,
114
+ timeout: GIT_TIMEOUT_MS,
115
+ }).toString();
116
+ return { stdout, status: 0 };
117
+ }
118
+ catch (err) {
119
+ return { stdout: null, status: err.status ?? null };
120
+ }
121
+ }
@@ -0,0 +1,90 @@
1
+ import type { Finding, Report } from './types.js';
2
+ /** Marks our one summary comment on a pull request, so later runs edit it instead of adding another. */
3
+ export declare const SUMMARY_MARKER = "<!-- launch-doctor:summary -->";
4
+ /** At most this many inline comments per run, so a big pull request isn't buried. */
5
+ export declare const MAX_INLINE = 20;
6
+ /**
7
+ * GitHub rejects a comment longer than 65,536 characters (and then no summary is posted at all). The summary comment
8
+ * is kept under this, with room to spare: lists get shorter until it fits.
9
+ */
10
+ export declare const MAX_COMMENT_CHARS = 60000;
11
+ export interface PrContext {
12
+ apiUrl: string;
13
+ serverUrl: string;
14
+ /** "owner/name" */
15
+ repo: string;
16
+ number: number;
17
+ headSha: string;
18
+ token: string;
19
+ /** Where the scanned folder sits inside the repository ("" for the repository root, "web" for ./web). */
20
+ prefix: string;
21
+ /** The workflow run (GITHUB_RUN_ID), to link to its job summary, which lists every finding. */
22
+ runId?: string;
23
+ }
24
+ /**
25
+ * Work out which pull request we're running for from the GitHub Actions environment.
26
+ * Returns a reason string instead when there's nothing to comment on.
27
+ */
28
+ export declare function prContextFromEnv(root: string, env?: NodeJS.ProcessEnv): PrContext | string;
29
+ /** Line numbers (in the new version of the file) that a unified diff patch adds. */
30
+ export declare function addedLines(patch: string): Set<number>;
31
+ /** What a pull request changed in one file: the added lines, or 'all' for a new file GitHub sent no patch for. */
32
+ export type ChangedLines = Set<number> | 'all';
33
+ export interface PrFile {
34
+ filename: string;
35
+ status: string;
36
+ patch?: string;
37
+ }
38
+ export declare function changedFiles(files: PrFile[]): Map<string, ChangedLines>;
39
+ export interface InlineFinding {
40
+ finding: Finding;
41
+ /** Path from the repository root. */
42
+ path: string;
43
+ line: number;
44
+ key: string;
45
+ }
46
+ export interface Placement {
47
+ /** Findings on lines this pull request adds. These get inline comments. */
48
+ inPr: InlineFinding[];
49
+ /** Everything else: older code, files the pull request didn't touch, project-wide findings. */
50
+ elsewhere: Finding[];
51
+ /** Findings left out because they're in .launchdoctor-baseline.json. */
52
+ baseline: number;
53
+ }
54
+ export declare function repoPath(prefix: string, file: string): string;
55
+ /** Split the report's findings into "added by this pull request" and "already there". */
56
+ export declare function placeFindings(report: Report, changed: Map<string, ChangedLines>, prefix: string): Placement;
57
+ /** The body of one inline review comment: what's wrong, why, the fix prompt, and how to silence it. */
58
+ export declare function renderInlineComment(item: InlineFinding): string;
59
+ /**
60
+ * The one summary comment on the pull request, edited in place on every run. It always fits GitHub's limit: when
61
+ * the full lists would make it too long, they are cut (fewer and fewer items) and say where to see everything.
62
+ */
63
+ export declare function renderPrComment(report: Report, placement: Placement, ctx: PrContext): string;
64
+ export declare class GitHubError extends Error {
65
+ readonly status: number;
66
+ constructor(status: number, message: string);
67
+ }
68
+ type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
69
+ export interface PrResult {
70
+ inPr: number;
71
+ elsewhere: number;
72
+ /** New inline comments posted this run. */
73
+ posted: number;
74
+ /** Inline comments left out: already posted on an earlier run. */
75
+ alreadyPosted: number;
76
+ /** Inline comments left out because of MAX_INLINE. */
77
+ overLimit: number;
78
+ /** Why the inline comments couldn't be posted, when they couldn't. */
79
+ inlineError?: string;
80
+ summary: 'created' | 'updated';
81
+ summaryUrl?: string;
82
+ }
83
+ /**
84
+ * Post Launch Doctor's results to a pull request:
85
+ * one summary comment (edited on later runs) and an inline review comment on each new finding.
86
+ */
87
+ export declare function postPrFeedback(report: Report, ctx: PrContext, fetchImpl?: FetchLike): Promise<PrResult>;
88
+ /** Explain a failed GitHub call in plain words. */
89
+ export declare function explainGitHubError(err: unknown): string;
90
+ export {};