periderm-cli 0.1.69 → 0.1.71

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/dist/index.js CHANGED
@@ -30,7 +30,8 @@ function requireAuth() {
30
30
  process.exit(1);
31
31
  }
32
32
  const program = new Command();
33
- program.name("periderm").description("A pre-launch checklist.").version("0.1.57");
33
+ const pkg = JSON.parse(await fs.readFile(new URL("../package.json", import.meta.url), "utf-8"));
34
+ program.name("periderm").description("A pre-launch checklist.").version(pkg.version);
34
35
  // Easter egg: `periderm bless` — hidden, undocumented
35
36
  program
36
37
  .command("bless", { hidden: true })
@@ -30,6 +30,12 @@ export function renderMarkdown(r) {
30
30
  if (r.meta.aiContextUsed) {
31
31
  lines.push(`- **AI context triage:** enabled${r.meta.contextFilteredCount ? ` · ${r.meta.contextFilteredCount} finding(s) filtered as not applicable` : ""}`);
32
32
  }
33
+ if (r.meta.mlPredictorLoaded) {
34
+ lines.push(`- **ML defect predictor:** PROMISE-trained ONNX model loaded (check id \`ai-defect-prediction\`)`);
35
+ }
36
+ else {
37
+ lines.push(`- **ML defect predictor:** not loaded (model file or ONNX runtime missing — findings will not include \`ai-defect-prediction\`)`);
38
+ }
33
39
  lines.push("");
34
40
  }
35
41
  lines.push(`| Metric | Score |`);
@@ -13,7 +13,7 @@ import { computeScores, computeVerdict } from "../report/verdict.js";
13
13
  import { renderMarkdown } from "../report/markdown.js";
14
14
  import { mapWithProgress } from "./progress.js";
15
15
  import { extractMetrics } from "./metrics.js";
16
- import { initPredictor, predictDefect } from "./ml-predictor.js";
16
+ import { initPredictor, isPredictorReady, predictDefect } from "./ml-predictor.js";
17
17
  export { formatScanPath } from "./progress.js";
18
18
  function isJsLike(rel) {
19
19
  return /\.(tsx?|jsx?|mjs|cjs)$/i.test(rel);
@@ -123,6 +123,7 @@ export async function scan(root, options = {}) {
123
123
  stacks: ctx.stacks,
124
124
  aiContextUsed: useAi,
125
125
  contextFilteredCount,
126
+ mlPredictorLoaded: isPredictorReady(),
126
127
  };
127
128
  const counts = { critical: 0, high: 0, medium: 0, low: 0 };
128
129
  for (const f of findings)
@@ -1,23 +1,43 @@
1
- import * as ort from "onnxruntime-node";
2
1
  import path from "node:path";
3
2
  import fs from "node:fs";
4
3
  import { fileURLToPath } from "node:url";
5
4
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
5
  let session = null;
6
+ let ort = null;
7
+ export function isPredictorReady() {
8
+ return session != null;
9
+ }
10
+ function debugMl(...args) {
11
+ if (process.env.PERIDERM_DEBUG_ML === "1") {
12
+ console.error("[periderm-ml]", ...args);
13
+ }
14
+ }
15
+ function resolveModelPath() {
16
+ const candidates = [
17
+ path.join(__dirname, "../../assets/defect_model.onnx"),
18
+ path.join(process.cwd(), "packages/cli/assets/defect_model.onnx"),
19
+ path.join(process.cwd(), "assets/defect_model.onnx"),
20
+ ];
21
+ return candidates.find((p) => fs.existsSync(p)) ?? null;
22
+ }
7
23
  export async function initPredictor() {
8
24
  if (session)
9
25
  return;
10
26
  try {
11
- // Resolve model path relative to execution
12
- let modelPath = path.join(process.cwd(), "packages/cli/assets/defect_model.onnx");
13
- if (!fs.existsSync(modelPath)) {
14
- // In dist/scanner/ml-predictor.js, __dirname is packages/cli/dist/scanner
15
- // So we go up two levels to get to packages/cli, then into assets
16
- modelPath = path.join(__dirname, "../../assets/defect_model.onnx");
17
- }
18
- if (fs.existsSync(modelPath)) {
19
- session = await ort.InferenceSession.create(modelPath);
20
- }
27
+ ort = await import("onnxruntime-web");
28
+ debugMl("runtime: onnxruntime-web");
29
+ }
30
+ catch {
31
+ debugMl("no ONNX runtime available");
32
+ return;
33
+ }
34
+ try {
35
+ const modelPath = resolveModelPath();
36
+ debugMl("model path:", modelPath);
37
+ if (!modelPath)
38
+ return;
39
+ session = await ort.InferenceSession.create(modelPath);
40
+ debugMl("session loaded");
21
41
  }
22
42
  catch (e) {
23
43
  console.error("[AI Defect Predictor] Failed to load ONNX model:", e);
@@ -27,17 +47,21 @@ export async function predictDefect(metrics) {
27
47
  if (!session)
28
48
  return false;
29
49
  try {
30
- const input = new Float32Array([metrics.loc, metrics.wmc, metrics.npm, metrics.max_cc, metrics.avg_cc]);
50
+ const input = new Float32Array([
51
+ metrics.loc,
52
+ metrics.wmc,
53
+ metrics.npm,
54
+ metrics.max_cc,
55
+ metrics.avg_cc,
56
+ ]);
31
57
  const tensor = new ort.Tensor("float32", input, [1, 5]);
32
- const feeds = { float_input: tensor };
33
- const results = await session.run(feeds);
58
+ const results = await session.run({ float_input: tensor });
34
59
  const label = results.output_label;
35
- if (label && label.data && label.data.length > 0) {
60
+ if (label?.data?.length)
36
61
  return Number(label.data[0]) > 0;
37
- }
38
62
  return false;
39
63
  }
40
- catch (e) {
64
+ catch {
41
65
  return false;
42
66
  }
43
67
  }
@@ -5,6 +5,26 @@ import { fileURLToPath } from "node:url";
5
5
  import { readConfig } from "./config.js";
6
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
7
  const pkgPath = path.join(__dirname, "..", "package.json");
8
+ /** Returns true when `latest` is strictly newer than `current` (numeric semver, prerelease ignored). */
9
+ function isNewerVersion(latest, current) {
10
+ const parse = (v) => v
11
+ .replace(/^v/i, "")
12
+ .split("-")[0]
13
+ .split(".")
14
+ .map((n) => Number.parseInt(n, 10) || 0);
15
+ const a = parse(latest);
16
+ const b = parse(current);
17
+ const len = Math.max(a.length, b.length);
18
+ for (let i = 0; i < len; i++) {
19
+ const av = a[i] ?? 0;
20
+ const bv = b[i] ?? 0;
21
+ if (av > bv)
22
+ return true;
23
+ if (av < bv)
24
+ return false;
25
+ }
26
+ return false;
27
+ }
8
28
  /**
9
29
  * Checks for a newer version of the CLI on NPM.
10
30
  * Returns the update banner string if an update is available, otherwise null.
@@ -31,14 +51,13 @@ export async function checkUpdate() {
31
51
  return null;
32
52
  const data = (await res.json());
33
53
  const latestVersion = data.version;
34
- if (!latestVersion || latestVersion === currentVersion)
54
+ if (!latestVersion || !isNewerVersion(latestVersion, currentVersion))
35
55
  return null;
36
56
  const cfg = readConfig();
37
57
  const apiUrl = cfg.apiUrl;
38
58
  if (!apiUrl)
39
59
  return null;
40
- const isUnix = process.platform !== "win32" && process.platform !== "android";
41
- const npmCmd = isUnix ? `sudo npm install -g ${name}` : `npm install -g ${name}`;
60
+ const npmCmd = `npm update -g ${name}`;
42
61
  const curlCmd = `curl -fsSL ${apiUrl}/install.sh | bash`;
43
62
  const title = `A new version of Periderm CLI is available: ${currentVersion} → ${latestVersion}`;
44
63
  const textNpm = `Update via npm: ${npmCmd}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "periderm-cli",
3
- "version": "0.1.69",
3
+ "version": "0.1.71",
4
4
  "description": "Periderm CLI: A pre-launch checklist to catch user-losing bugs, legal liabilities, revenue leaks, runaway cloud bills and so many more before you ship.",
5
5
  "type": "module",
6
6
  "preferGlobal": true,
@@ -54,7 +54,7 @@
54
54
  "chalk": "^5.3.0",
55
55
  "commander": "^12.1.0",
56
56
  "fast-glob": "^3.3.2",
57
- "onnxruntime-node": "^1.29.0",
57
+ "onnxruntime-web": "^1.29.0",
58
58
  "open": "^10.1.0",
59
59
  "ora": "^9.4.1"
60
60
  },