periderm-cli 0.1.16 → 0.1.18

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/README.md CHANGED
@@ -1,13 +1,23 @@
1
- # periderm
1
+ # periderm-cli
2
2
 
3
- A pre-launch checklist for every project.
3
+ A pre-launch checklist for every JavaScript and TypeScript project.
4
+
5
+ Scan **`.js`**, **`.jsx`**, **`.ts`**, and **`.tsx`** codebases (plus `.mjs` / `.cjs`) before you ship.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g periderm-cli
11
+ ```
12
+
13
+ ## Quick start
4
14
 
5
15
  ```bash
6
- periderm scan # scan current directory, print verdict, write .periderm/last-report.md
7
- periderm scan --upload # also push to dashboard
8
- periderm watch # rerun on file change
9
- periderm login # authenticate the CLI
10
- periderm whoami # show current token + plan
16
+ periderm login # authenticate once
17
+ periderm scan # scan + upload to your dashboard
18
+ periderm scan --local-only # local report only, no upload
19
+ periderm watch # rerun on file change
20
+ periderm whoami # show current token + plan
11
21
  ```
12
22
 
13
- See full install + usage at the project `/docs` page.
23
+ Full docs: [periderm-cli.vercel.app/docs](https://periderm-cli.vercel.app/docs)
@@ -0,0 +1,79 @@
1
+ import os from "node:os";
2
+ import { readConfig } from "./config.js";
3
+ import { verifyToken } from "./api.js";
4
+ const FORMSPREE_URL = "https://formspree.io/f/mqakppnn";
5
+ function buildContext(input) {
6
+ const cfg = readConfig();
7
+ return {
8
+ source: input.source,
9
+ where: input.where ?? "periderm-cli",
10
+ command: input.command ?? (process.argv.slice(2).join(" ") || "unknown"),
11
+ cwd: input.cwd ?? process.cwd(),
12
+ node: input.nodeVersion ?? process.version,
13
+ platform: `${os.platform()} ${os.release()}`,
14
+ hostname: os.hostname(),
15
+ apiUrl: cfg.apiUrl,
16
+ cause: input.cause,
17
+ ...input.extra,
18
+ };
19
+ }
20
+ function formatFormspreeBody(input, userEmail) {
21
+ const ctx = buildContext(input);
22
+ const lines = [
23
+ `Periderm CLI Error Report`,
24
+ ``,
25
+ `What: ${input.message}`,
26
+ input.cause ? `Cause: ${input.cause}` : null,
27
+ `Where: ${ctx.where}`,
28
+ `How: command \`${ctx.command}\` in ${ctx.cwd}`,
29
+ `Platform: ${ctx.platform} · Node ${ctx.node}`,
30
+ `API: ${ctx.apiUrl}`,
31
+ userEmail !== "unknown" ? `User: ${userEmail}` : null,
32
+ input.stack ? `\nStack trace:\n${input.stack}` : null,
33
+ Object.keys(input.extra ?? {}).length
34
+ ? `\nExtra:\n${JSON.stringify(input.extra, null, 2)}`
35
+ : null,
36
+ ].filter(Boolean);
37
+ return lines.join("\n");
38
+ }
39
+ export async function reportCliError(input) {
40
+ let userEmail = "unknown";
41
+ try {
42
+ const cfg = readConfig();
43
+ if (cfg.token) {
44
+ const v = await verifyToken(cfg.token);
45
+ if (v.valid && v.email)
46
+ userEmail = v.email;
47
+ }
48
+ }
49
+ catch {
50
+ /* ignore during crash reporting */
51
+ }
52
+ const cfg = readConfig();
53
+ const context = buildContext(input);
54
+ const body = formatFormspreeBody(input, userEmail);
55
+ const tasks = [
56
+ fetch(FORMSPREE_URL, {
57
+ method: "POST",
58
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
59
+ body: JSON.stringify({
60
+ name: "Periderm CLI Error Reporter",
61
+ _replyto: userEmail === "unknown" ? "princejaphethjj@gmail.com" : userEmail,
62
+ message: body,
63
+ }),
64
+ }).catch(() => undefined),
65
+ fetch(`${cfg.apiUrl}/api/public/report-error`, {
66
+ method: "POST",
67
+ headers: { Accept: "application/json", "Content-Type": "application/json" },
68
+ body: JSON.stringify({
69
+ source: input.source,
70
+ message: input.message,
71
+ stack: input.stack,
72
+ user_email: userEmail === "unknown" ? undefined : userEmail,
73
+ url: `cli://${context.command}`,
74
+ context,
75
+ }),
76
+ }).catch(() => undefined),
77
+ ];
78
+ await Promise.allSettled(tasks);
79
+ }
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import ora from "ora";
14
14
  import { PERIDERM_ASCII } from "./constants.js";
15
15
  import { PRE_SCAN_MESSAGES, UPLOAD_MESSAGES, startRotatingMessages, finishRotatingMessages } from "./loading-messages.js";
16
16
  import { formatScanPath } from "./scanner/progress.js";
17
+ import { reportCliError } from "./error-report.js";
17
18
  function requireAuth() {
18
19
  console.info("");
19
20
  console.info(chalk.bold.hex("#FF4D00")("▸_ Periderm CLI"));
@@ -29,7 +30,7 @@ const program = new Command();
29
30
  program
30
31
  .name("periderm")
31
32
  .description("A pre-launch checklist.")
32
- .version("0.1.0");
33
+ .version("0.1.18");
33
34
  // Easter egg: `periderm bless` — hidden, undocumented
34
35
  program
35
36
  .command("bless", { hidden: true })
@@ -56,7 +57,7 @@ program
56
57
  program
57
58
  .command("scan")
58
59
  .description("Scan the current directory and write a markdown report.")
59
- .option("--upload", "Upload the scan to your Periderm dashboard")
60
+ .option("--local-only", "Scan locally without uploading to your Periderm dashboard")
60
61
  .option("--cwd <dir>", "Directory to scan", process.cwd())
61
62
  .action(async (opts) => {
62
63
  const root = path.resolve(opts.cwd);
@@ -152,7 +153,7 @@ program
152
153
  await fs.mkdir(outDir, { recursive: true });
153
154
  await fs.writeFile(path.join(outDir, "last-report.md"), result.markdown, "utf8");
154
155
  await fs.writeFile(path.join(outDir, "last-report.json"), JSON.stringify(result, null, 2), "utf8");
155
- if (opts.upload) {
156
+ if (!opts.localOnly) {
156
157
  const cfg = readConfig();
157
158
  if (!cfg.token) {
158
159
  console.info(chalk.yellow("no token configured — run `periderm login` first to sync to dashboard."));
@@ -353,9 +354,9 @@ program
353
354
  console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
354
355
  console.info("");
355
356
  console.info(chalk.bold.white("[Next Steps]"));
356
- console.info(chalk.white(" 1. Local scan ") + chalk.hex("#FF4D00")("$ periderm scan"));
357
- console.info(chalk.white(" 2. Cloud upload ") + chalk.hex("#FF4D00")("$ periderm scan --upload"));
358
- console.info(chalk.white(" 3. Log out ") + chalk.hex("#FF4D00")("$ periderm logout"));
357
+ console.info(chalk.white(" 1. Scan + upload ") + chalk.hex("#FF4D00")("$ periderm scan"));
358
+ console.info(chalk.white(" 2. Local only ") + chalk.hex("#FF4D00")("$ periderm scan --local-only"));
359
+ console.info(chalk.white(" 3. Log out ") + chalk.hex("#FF4D00")("$ periderm logout"));
359
360
  console.info("");
360
361
  console.info(chalk.white("Need help? Visit ") + chalk.underline.cyan(`${apiUrl}/docs`) + chalk.white("\n"));
361
362
  server.close();
@@ -428,35 +429,14 @@ if (process.argv.length === 2) {
428
429
  else {
429
430
  program.parseAsync().catch(async (e) => {
430
431
  console.error(e);
431
- try {
432
- const formData = new FormData();
433
- formData.append("name", "Periderm CLI Crash Reporter");
434
- let userEmail = "princejaphethjj@gmail.com";
435
- try {
436
- const cfg = readConfig();
437
- if (cfg.token) {
438
- const v = await verifyToken(cfg.token);
439
- if (v.valid && v.email) {
440
- userEmail = v.email;
441
- }
442
- }
443
- }
444
- catch {
445
- // ignore token verification errors during crash
446
- }
447
- formData.append("_replyto", userEmail);
448
- const marker = `\n\n---\n[System Info: Sent from Periderm CLI]\n[User Email: ${userEmail === "princejaphethjj@gmail.com" ? "Unknown" : userEmail}]`;
449
- const errMsg = e instanceof Error ? `${e.message}\n${e.stack}` : String(e);
450
- formData.append("message", `CLI Crash:\n\n${errMsg}${marker}`);
451
- await fetch("https://formspree.io/f/mqakppnn", {
452
- method: "POST",
453
- body: formData,
454
- headers: { Accept: "application/json" }
455
- });
456
- }
457
- catch (err) {
458
- // silently fail
459
- }
432
+ const err = e instanceof Error ? e : new Error(String(e));
433
+ await reportCliError({
434
+ source: "cli",
435
+ message: err.message,
436
+ stack: err.stack,
437
+ cause: err.cause instanceof Error ? err.cause.message : err.cause ? String(err.cause) : undefined,
438
+ where: "periderm-cli unhandled",
439
+ });
460
440
  process.exit(1);
461
441
  });
462
442
  }
@@ -1,22 +1,55 @@
1
1
  import { parse } from "@babel/parser";
2
- export function parseSource(source, filename) {
2
+ import path from "node:path";
3
+ const PLUGINS = [
4
+ "typescript",
5
+ "jsx",
6
+ "decorators-legacy",
7
+ "topLevelAwait",
8
+ "importMeta",
9
+ "classProperties",
10
+ "classPrivateProperties",
11
+ "classPrivateMethods",
12
+ "dynamicImport",
13
+ "optionalChaining",
14
+ "nullishCoalescingOperator",
15
+ ];
16
+ function sourceTypeFor(filename) {
17
+ const ext = path.extname(filename).toLowerCase();
18
+ if (ext === ".cjs")
19
+ return "script";
20
+ if (ext === ".mjs" || ext === ".ts" || ext === ".tsx")
21
+ return "module";
22
+ return "unambiguous";
23
+ }
24
+ function tryParse(source, filename, sourceType) {
3
25
  try {
4
26
  return parse(source, {
5
- sourceType: "module",
27
+ sourceType,
6
28
  sourceFilename: filename,
7
29
  allowImportExportEverywhere: true,
8
30
  allowReturnOutsideFunction: true,
9
31
  errorRecovery: true,
10
- plugins: [
11
- "typescript",
12
- "jsx",
13
- "decorators-legacy",
14
- "topLevelAwait",
15
- "importMeta",
16
- ],
32
+ plugins: [...PLUGINS],
17
33
  });
18
34
  }
19
35
  catch {
20
36
  return null;
21
37
  }
22
38
  }
39
+ export function parseSource(source, filename) {
40
+ const preferred = sourceTypeFor(filename);
41
+ const attempts = [preferred];
42
+ if (preferred !== "module")
43
+ attempts.push("module");
44
+ if (preferred !== "script")
45
+ attempts.push("script");
46
+ for (const sourceType of attempts) {
47
+ const ast = tryParse(source, filename, sourceType);
48
+ if (ast)
49
+ return ast;
50
+ }
51
+ return null;
52
+ }
53
+ export function isSupportedSourceFile(filename) {
54
+ return /\.(tsx?|jsx?|mjs|cjs)$/i.test(filename);
55
+ }
@@ -622,6 +622,76 @@ const deadEndPage = (source, file) => {
622
622
  return out;
623
623
  };
624
624
  // ───────────────────────────────────────────────────────────────────────
625
+ // 14. Aggressive DB/API polling for "live" updates instead of websockets
626
+ // ───────────────────────────────────────────────────────────────────────
627
+ const dbPollingAbuse = (source, file) => {
628
+ const out = [];
629
+ if (!/\.(tsx|jsx|ts|js)$/.test(file))
630
+ return out;
631
+ const intervalPatterns = [
632
+ [/refetchInterval\s*:\s*(\d+)/g, "TanStack/React Query refetchInterval"],
633
+ [/refreshInterval\s*:\s*(\d+)/g, "SWR refreshInterval"],
634
+ [/(?:pollInterval|pollingInterval)\s*[:=]\s*(\d+)/g, "polling interval"],
635
+ ];
636
+ for (const [re, label] of intervalPatterns) {
637
+ let m;
638
+ while ((m = re.exec(source))) {
639
+ const ms = parseInt(m[1], 10);
640
+ if (ms > 0 && ms < 5000) {
641
+ out.push(mkFinding({
642
+ id: "db-polling-interval",
643
+ category: "Runaway Cloud Costs",
644
+ severity: "critical",
645
+ file,
646
+ line: lineOf(source, m.index),
647
+ message: `${label} set to ${ms}ms — polling the database/API several times per second.`,
648
+ why: "Vibecoded \"live feedback\" loops hammer your DB/API on every tab open. On Supabase/Firebase/serverless this can burn through free tiers and bankrupt you overnight. Use websockets, Supabase Realtime, or SSE instead.",
649
+ fix: "Replace polling with Supabase Realtime (.channel/.subscribe), WebSockets, or server-sent events. If you must poll, use ≥30s intervals and pause when the tab is hidden.",
650
+ aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, ${label} is ${ms}ms — far too aggressive for live updates. Refactor to Supabase Realtime channels or WebSockets for push updates, or raise the interval to 30s+ with visibility-based pausing.`,
651
+ }));
652
+ }
653
+ }
654
+ }
655
+ const intervalFetchRe = /setInterval\s*\(\s*(?:async\s*)?\(?[^)]*\)?\s*=>\s*\{[\s\S]{0,700}?(supabase\.(?:from|rpc)|\.select\s*\(|fetch\s*\(|axios\.|\.get\s*\()/gi;
656
+ let m;
657
+ while ((m = intervalFetchRe.exec(source))) {
658
+ const snippet = m[0];
659
+ const hasRealtime = /\.channel\s*\(|\.subscribe\s*\(|WebSocket|useRealtime|postgres_changes/.test(source);
660
+ const intervalMs = snippet.match(/setInterval\s*\([^,]+,\s*(\d+)/)?.[1];
661
+ const ms = intervalMs ? parseInt(intervalMs, 10) : 1000;
662
+ if (ms < 5000 && !hasRealtime) {
663
+ out.push(mkFinding({
664
+ id: "setinterval-db-poll",
665
+ category: "Runaway Cloud Costs",
666
+ severity: "critical",
667
+ file,
668
+ line: lineOf(source, m.index),
669
+ message: `setInterval (${ms}ms) repeatedly hits the database/API for live updates.`,
670
+ why: "This pattern mimics realtime with expensive polling. Every user multiplies reads/writes. It is the #1 surprise bill for AI-generated dashboards and chat UIs.",
671
+ fix: "Use Supabase Realtime, WebSockets, or SSE. Delete the interval and subscribe to push events instead.",
672
+ aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, a setInterval every ${ms}ms fetches from the database/API. Replace with Supabase Realtime (.channel().on('postgres_changes')) or WebSockets so updates push instead of poll.`,
673
+ }));
674
+ }
675
+ }
676
+ const useEffectPollRe = /useEffect\s*\(\s*\(\s*\)\s*=>\s*\{[\s\S]{0,500}?setInterval\s*\([\s\S]{0,400}?(supabase\.(?:from|rpc)|fetch\s*\()/g;
677
+ while ((m = useEffectPollRe.exec(source))) {
678
+ if (/\.channel\s*\(|WebSocket|realtime/.test(m[0]))
679
+ continue;
680
+ out.push(mkFinding({
681
+ id: "useeffect-polling",
682
+ category: "Runaway Cloud Costs",
683
+ severity: "high",
684
+ file,
685
+ line: lineOf(source, m.index),
686
+ message: "useEffect sets up interval polling against the database/API.",
687
+ why: "Polling in useEffect is a common vibecoder pattern for \"live\" dashboards. It scales linearly with users and tabs, unlike websocket subscriptions.",
688
+ fix: "Switch to Supabase Realtime subscriptions or WebSockets. Add cleanup if you keep any polling.",
689
+ aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, useEffect starts interval polling for data. Replace with a Realtime subscription (supabase.channel) or WebSocket listener, and return an unsubscribe cleanup.`,
690
+ }));
691
+ }
692
+ return out;
693
+ };
694
+ // ───────────────────────────────────────────────────────────────────────
625
695
  // Registry
626
696
  // ───────────────────────────────────────────────────────────────────────
627
697
  const CHECKS = [
@@ -646,6 +716,7 @@ const CHECKS = [
646
716
  missingRateLimit,
647
717
  idorDataFetch,
648
718
  deadEndPage,
719
+ dbPollingAbuse,
649
720
  ];
650
721
  export const PER_FILE_CHECK_COUNT = CHECKS.length;
651
722
  export function runChecks(source, file, ast) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "periderm-cli",
3
- "version": "0.1.16",
4
- "description": "A pre-launch checklist for your codebase.",
3
+ "version": "0.1.18",
4
+ "description": "A pre-launch checklist for your codebase. Scan JS, TS, JSX, and TSX projects before you ship.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "periderm": "./dist/bin.js"
@@ -10,6 +10,32 @@
10
10
  "dist",
11
11
  "README.md"
12
12
  ],
13
+ "keywords": [
14
+ "cli",
15
+ "code-quality",
16
+ "pre-launch",
17
+ "security",
18
+ "scanning",
19
+ "javascript",
20
+ "typescript",
21
+ "jsx",
22
+ "tsx",
23
+ "react",
24
+ "launch-checklist",
25
+ "static-analysis",
26
+ "code-review"
27
+ ],
28
+ "homepage": "https://periderm-cli.vercel.app",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/Prince-Japheth/LaunchGuard.git",
32
+ "directory": "packages/cli"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/Prince-Japheth/LaunchGuard/issues"
36
+ },
37
+ "author": "Periderm",
38
+ "license": "MIT",
13
39
  "scripts": {
14
40
  "build": "tsc -p tsconfig.json && chmod +x dist/bin.js",
15
41
  "postpublish": "cd ../../ && tsx --env-file=.env scripts/broadcast-update.ts",