@arsh342/athena 0.1.8 → 0.1.9

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 (2) hide show
  1. package/dist/index.cjs +287 -37
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -127174,7 +127174,7 @@ ${lanes.join("\n")}
127174
127174
  }
127175
127175
  }
127176
127176
  function createImportCallExpressionAMD(arg, containsLexicalThis) {
127177
- const resolve3 = factory2.createUniqueName("resolve");
127177
+ const resolve4 = factory2.createUniqueName("resolve");
127178
127178
  const reject = factory2.createUniqueName("reject");
127179
127179
  const parameters = [
127180
127180
  factory2.createParameterDeclaration(
@@ -127183,7 +127183,7 @@ ${lanes.join("\n")}
127183
127183
  /*dotDotDotToken*/
127184
127184
  void 0,
127185
127185
  /*name*/
127186
- resolve3
127186
+ resolve4
127187
127187
  ),
127188
127188
  factory2.createParameterDeclaration(
127189
127189
  /*modifiers*/
@@ -127200,7 +127200,7 @@ ${lanes.join("\n")}
127200
127200
  factory2.createIdentifier("require"),
127201
127201
  /*typeArguments*/
127202
127202
  void 0,
127203
- [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve3, reject]
127203
+ [factory2.createArrayLiteralExpression([arg || factory2.createOmittedExpression()]), resolve4, reject]
127204
127204
  )
127205
127205
  )
127206
127206
  ]);
@@ -213918,8 +213918,8 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
213918
213918
  installPackage(options) {
213919
213919
  this.packageInstallId++;
213920
213920
  const request = { kind: "installPackage", ...options, id: this.packageInstallId };
213921
- const promise = new Promise((resolve3, reject) => {
213922
- (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve3, reject });
213921
+ const promise = new Promise((resolve4, reject) => {
213922
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve: resolve4, reject });
213923
213923
  });
213924
213924
  this.installer.send(request);
213925
213925
  return promise;
@@ -214240,6 +214240,11 @@ var defaultConfig = {
214240
214240
  exclude: ["node_modules/", "dist/", "build/", ".git/", "coverage/"],
214241
214241
  secretDetection: true,
214242
214242
  hallucinationDetection: true,
214243
+ semgrep: {
214244
+ enabled: true,
214245
+ timeoutMs: 3e4,
214246
+ config: "auto"
214247
+ },
214243
214248
  maxFileSize: 1048576,
214244
214249
  weights: defaultWeights
214245
214250
  };
@@ -214247,6 +214252,10 @@ function mergeConfig(config = {}) {
214247
214252
  return {
214248
214253
  ...defaultConfig,
214249
214254
  ...config,
214255
+ semgrep: {
214256
+ ...defaultConfig.semgrep,
214257
+ ...config.semgrep
214258
+ },
214250
214259
  weights: {
214251
214260
  ...defaultWeights,
214252
214261
  ...config.weights
@@ -214299,6 +214308,7 @@ var secretPatterns = [
214299
214308
  { ruleId: "secret.private-key", label: "Private key", pattern: /-----BEGIN [A-Z ]+PRIVATE KEY-----/g }
214300
214309
  ];
214301
214310
  var hardcodedCredentialPattern = /(password|api[_-]?key|token|secret)\s*[:=]\s*['"][^'"]{8,}['"]/gi;
214311
+ var sequelizeCredentialPattern = /new\s+Sequelize\s*\(\s*(['"`])([^'"`\r\n]+)\1\s*,\s*(['"`])([^'"`\r\n]+)\3\s*,\s*(['"`])([^'"`\r\n]+)\5/gi;
214302
214312
  function detectSecrets(scored) {
214303
214313
  const findings = [];
214304
214314
  for (const definition of secretPatterns) {
@@ -214311,6 +214321,12 @@ function detectSecrets(scored) {
214311
214321
  const { ruleId, type } = classifyHardcodedCredential(matchedKey);
214312
214322
  findings.push(createFinding(scored, ruleId, type, match[0], "credential-exposure"));
214313
214323
  }
214324
+ for (const match of scored.unit.code.matchAll(sequelizeCredentialPattern)) {
214325
+ const dbName = match[2] ?? "db";
214326
+ const username = match[4] ?? "user";
214327
+ findings.push(createFinding(scored, "secret.sequelize-constructor-credentials", "Hardcoded database credentials", match[0], "credential-exposure"));
214328
+ findings.push(createFinding(scored, "secret.sequelize-connection-metadata", "Hardcoded database connection metadata", `${dbName}:${username}`, "credential-exposure"));
214329
+ }
214314
214330
  const highEntropyStrings = [...scored.unit.code.matchAll(/['"]([A-Za-z0-9+/=_-]{24,})['"]/g)].map((match) => match[1]).filter((value) => shannonEntropy(value) > 4.5 && !looksLikeFalsePositive(value));
214315
214331
  for (const value of highEntropyStrings) {
214316
214332
  findings.push(createFinding(scored, "secret.high-entropy-string", "Possible high-entropy secret", value, "credential-exposure"));
@@ -214364,13 +214380,104 @@ function analyzeSecurity(scored, config) {
214364
214380
  const findings = [];
214365
214381
  if (config.secretDetection)
214366
214382
  findings.push(...detectSecrets(scored));
214367
- if (config.hallucinationDetection)
214383
+ if (config.hallucinationDetection && scored.flagged)
214368
214384
  findings.push(...detectHallucinations(scored));
214369
214385
  return findings;
214370
214386
  }
214371
214387
 
214372
- // ../core/dist/parser/ast-parser.js
214388
+ // ../core/dist/analyzers/semgrep-adapter.js
214373
214389
  var import_node_crypto3 = require("crypto");
214390
+ var import_node_child_process = require("child_process");
214391
+ var import_node_util = require("util");
214392
+ var import_node_path = require("path");
214393
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
214394
+ async function runSemgrep(filePaths, config) {
214395
+ if (!config.enabled || filePaths.length === 0)
214396
+ return [];
214397
+ const semgrepArgs = [
214398
+ "scan",
214399
+ "--json",
214400
+ "--quiet",
214401
+ "--disable-version-check",
214402
+ "--config",
214403
+ config.config,
214404
+ ...filePaths
214405
+ ];
214406
+ const output = await execSemgrep(semgrepArgs, config.timeoutMs);
214407
+ if (!output)
214408
+ return [];
214409
+ const parsed2 = safeParseSemgrep(output);
214410
+ return (parsed2.results ?? []).map(normalizeSemgrepFinding).filter(Boolean);
214411
+ }
214412
+ async function execSemgrep(args, timeoutMs) {
214413
+ try {
214414
+ const { stdout } = await execFileAsync("semgrep", args, {
214415
+ timeout: timeoutMs,
214416
+ maxBuffer: 10 * 1024 * 1024
214417
+ });
214418
+ return stdout;
214419
+ } catch (error) {
214420
+ const withStreams = error;
214421
+ if (withStreams?.stdout && withStreams.stdout.trim().startsWith("{")) {
214422
+ return withStreams.stdout;
214423
+ }
214424
+ if (withStreams?.code === "ENOENT") {
214425
+ console.warn("[athena-core] semgrep not installed; skipping semgrep scan");
214426
+ return null;
214427
+ }
214428
+ const detail = withStreams?.stderr?.trim() || withStreams?.message || String(error);
214429
+ console.warn(`[athena-core] semgrep execution failed: ${detail}`);
214430
+ return null;
214431
+ }
214432
+ }
214433
+ function safeParseSemgrep(json) {
214434
+ try {
214435
+ return JSON.parse(json);
214436
+ } catch {
214437
+ return { results: [] };
214438
+ }
214439
+ }
214440
+ function normalizeSemgrepFinding(result) {
214441
+ const file = (0, import_node_path.resolve)(result.path || "");
214442
+ if (!file)
214443
+ return null;
214444
+ const line = result.start?.line ?? 1;
214445
+ const column = result.start?.col ?? 1;
214446
+ const ruleId = result.check_id || "semgrep.unknown-rule";
214447
+ const message = result.extra?.message?.trim() || "Semgrep finding";
214448
+ const code = result.extra?.lines?.trim() || "";
214449
+ const severity = mapSemgrepSeverity(result.extra?.severity);
214450
+ const category = result.extra?.metadata?.category || "code-security";
214451
+ return {
214452
+ id: (0, import_node_crypto3.createHash)("sha1").update(`semgrep:${file}:${line}:${column}:${ruleId}`).digest("hex").slice(0, 10),
214453
+ ruleId,
214454
+ file,
214455
+ line,
214456
+ column,
214457
+ code,
214458
+ type: formatSemgrepType(ruleId),
214459
+ message,
214460
+ category,
214461
+ severity
214462
+ };
214463
+ }
214464
+ function mapSemgrepSeverity(raw) {
214465
+ const value = (raw ?? "").toUpperCase();
214466
+ if (value.includes("ERROR") || value.includes("CRITICAL"))
214467
+ return "CRITICAL";
214468
+ if (value.includes("WARNING") || value.includes("HIGH"))
214469
+ return "HIGH";
214470
+ if (value.includes("INFO") || value.includes("MEDIUM"))
214471
+ return "MEDIUM";
214472
+ return "LOW";
214473
+ }
214474
+ function formatSemgrepType(ruleId) {
214475
+ const last = ruleId.split(".").filter(Boolean).slice(-1)[0] || ruleId;
214476
+ return `Semgrep ${last.replace(/[-_]/g, " ")}`;
214477
+ }
214478
+
214479
+ // ../core/dist/parser/ast-parser.js
214480
+ var import_node_crypto4 = require("crypto");
214374
214481
  var import_promises = require("fs/promises");
214375
214482
  var import_typescript = __toESM(require_typescript(), 1);
214376
214483
  var supportedScriptKinds = {
@@ -214409,7 +214516,7 @@ function createUnit(node, sourceFile, source, filePath) {
214409
214516
  const name = getName(node);
214410
214517
  const metadata = getMetadata(node, sourceFile, source, code, start);
214411
214518
  return {
214412
- id: (0, import_node_crypto3.createHash)("sha1").update(`${filePath}:${startLine}:${endLine}:${name}`).digest("hex").slice(0, 12),
214519
+ id: (0, import_node_crypto4.createHash)("sha1").update(`${filePath}:${startLine}:${endLine}:${name}`).digest("hex").slice(0, 12),
214413
214520
  name,
214414
214521
  kind,
214415
214522
  filePath,
@@ -214858,7 +214965,7 @@ async function scanFiles(filePaths, configInput = {}, hooks = {}) {
214858
214965
  }
214859
214966
  const units = await parseFile(filePath).catch(() => []);
214860
214967
  const scoredUnits = units.map((unit) => scoreUnit(unit, config));
214861
- const findings = scoredUnits.flatMap((scored) => scored.flagged ? analyzeSecurity(scored, config) : []);
214968
+ const findings = scoredUnits.flatMap((scored) => analyzeSecurity(scored, config));
214862
214969
  totalLoc += units.reduce((sum, unit) => sum + unit.metadata.loc, 0);
214863
214970
  files.push({
214864
214971
  path: filePath,
@@ -214874,8 +214981,58 @@ async function scanFiles(filePaths, configInput = {}, hooks = {}) {
214874
214981
  findings: findings.length
214875
214982
  });
214876
214983
  }
214984
+ const semgrepFindings = await runSemgrep(filePaths, config.semgrep);
214985
+ if (semgrepFindings.length > 0) {
214986
+ const reportsByPath = new Map(files.map((file) => [file.path, file]));
214987
+ for (const finding of semgrepFindings) {
214988
+ const existing = reportsByPath.get(finding.file);
214989
+ const unitContext = selectUnitForLine(existing?.units ?? [], finding.line);
214990
+ const mappedFinding = {
214991
+ id: finding.id,
214992
+ severity: finding.severity,
214993
+ type: finding.type,
214994
+ category: finding.category,
214995
+ message: finding.message,
214996
+ file: finding.file,
214997
+ line: finding.line,
214998
+ column: finding.column,
214999
+ code: finding.code,
215000
+ aiScore: unitContext?.score ?? config.threshold,
215001
+ explainedScore: unitContext?.explained ?? emptyExplainedScore(),
215002
+ source: "semgrep",
215003
+ ruleId: finding.ruleId
215004
+ };
215005
+ if (existing) {
215006
+ existing.findings.push(mappedFinding);
215007
+ } else {
215008
+ const newReport = {
215009
+ path: finding.file,
215010
+ units: [],
215011
+ findings: [mappedFinding]
215012
+ };
215013
+ files.push(newReport);
215014
+ reportsByPath.set(finding.file, newReport);
215015
+ }
215016
+ }
215017
+ }
214877
215018
  return generateReport(startedAt, files, totalLoc, skippedFiles, config);
214878
215019
  }
215020
+ function selectUnitForLine(units, line) {
215021
+ for (const unit of units) {
215022
+ if (line >= unit.unit.startLine && line <= unit.unit.endLine)
215023
+ return unit;
215024
+ }
215025
+ return null;
215026
+ }
215027
+ function emptyExplainedScore() {
215028
+ return {
215029
+ score: 0,
215030
+ band: "LOW",
215031
+ signalsTriggered: 0,
215032
+ variance: 0,
215033
+ topSignals: []
215034
+ };
215035
+ }
214879
215036
 
214880
215037
  // ../core/dist/report/terminal-formatter.js
214881
215038
  var c = {
@@ -215013,11 +215170,11 @@ function formatCodeSnippet(code, maxLines) {
215013
215170
  }
215014
215171
 
215015
215172
  // src/commands/check.ts
215016
- var import_node_path4 = require("path");
215173
+ var import_node_path5 = require("path");
215017
215174
 
215018
215175
  // src/utils/file-filter.ts
215019
215176
  var import_promises3 = require("fs/promises");
215020
- var import_node_path = require("path");
215177
+ var import_node_path2 = require("path");
215021
215178
  var supported = /* @__PURE__ */ new Set([".js", ".jsx", ".ts", ".tsx"]);
215022
215179
  var ignoredDirs = /* @__PURE__ */ new Set([
215023
215180
  "node_modules",
@@ -215054,25 +215211,25 @@ async function walk(dir, output) {
215054
215211
  const entries = await (0, import_promises3.readdir)(dir, { withFileTypes: true }).catch(() => []);
215055
215212
  for (const entry of entries) {
215056
215213
  if (entry.isDirectory()) {
215057
- if (!ignoredDirs.has(entry.name)) await walk((0, import_node_path.join)(dir, entry.name), output);
215214
+ if (!ignoredDirs.has(entry.name)) await walk((0, import_node_path2.join)(dir, entry.name), output);
215058
215215
  continue;
215059
215216
  }
215060
- const filePath = (0, import_node_path.join)(dir, entry.name);
215217
+ const filePath = (0, import_node_path2.join)(dir, entry.name);
215061
215218
  if (entry.isFile() && isSourceFile(filePath)) output.push(filePath);
215062
215219
  }
215063
215220
  }
215064
215221
 
215065
215222
  // src/utils/git.ts
215066
- var import_node_child_process = require("child_process");
215067
- var import_node_util = require("util");
215068
- var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
215223
+ var import_node_child_process2 = require("child_process");
215224
+ var import_node_util2 = require("util");
215225
+ var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
215069
215226
  function logGitWarning(context, error) {
215070
215227
  const message = error instanceof Error ? error.message : String(error);
215071
215228
  console.warn(`[athena-cli] ${context}: ${message}`);
215072
215229
  }
215073
215230
  async function getGitRoot() {
215074
215231
  try {
215075
- const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"]);
215232
+ const { stdout } = await execFileAsync2("git", ["rev-parse", "--show-toplevel"]);
215076
215233
  return stdout.trim();
215077
215234
  } catch (error) {
215078
215235
  logGitWarning("Unable to resolve git root", error);
@@ -215081,7 +215238,7 @@ async function getGitRoot() {
215081
215238
  }
215082
215239
  async function getGitHooksDir() {
215083
215240
  try {
215084
- const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "hooks"]);
215241
+ const { stdout } = await execFileAsync2("git", ["rev-parse", "--git-path", "hooks"]);
215085
215242
  return stdout.trim();
215086
215243
  } catch (error) {
215087
215244
  logGitWarning("Unable to resolve git hooks directory", error);
@@ -215090,7 +215247,7 @@ async function getGitHooksDir() {
215090
215247
  }
215091
215248
  async function getStagedFiles() {
215092
215249
  try {
215093
- const { stdout } = await execFileAsync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACM"]);
215250
+ const { stdout } = await execFileAsync2("git", ["diff", "--cached", "--name-only", "--diff-filter=ACM"]);
215094
215251
  return stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
215095
215252
  } catch (error) {
215096
215253
  logGitWarning("Unable to read staged files", error);
@@ -215101,9 +215258,9 @@ async function getStagedFiles() {
215101
215258
  // src/utils/history.ts
215102
215259
  var import_promises4 = require("fs/promises");
215103
215260
  var import_node_os = require("os");
215104
- var import_node_path2 = require("path");
215105
- var ATHENA_DIR = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".athena");
215106
- var HISTORY_PATH = (0, import_node_path2.join)(ATHENA_DIR, "scan-history.jsonl");
215261
+ var import_node_path3 = require("path");
215262
+ var ATHENA_DIR = (0, import_node_path3.join)((0, import_node_os.homedir)(), ".athena");
215263
+ var HISTORY_PATH = (0, import_node_path3.join)(ATHENA_DIR, "scan-history.jsonl");
215107
215264
  var MAX_HISTORY_LINES = 300;
215108
215265
  function logHistoryWarning(context, error) {
215109
215266
  const message = error instanceof Error ? error.message : String(error);
@@ -215162,7 +215319,7 @@ function formatRecentHistory(entries) {
215162
215319
  }
215163
215320
 
215164
215321
  // src/utils/scan-progress.ts
215165
- var import_node_path3 = require("path");
215322
+ var import_node_path4 = require("path");
215166
215323
 
215167
215324
  // src/utils/colors.ts
215168
215325
  var c2 = {
@@ -215248,7 +215405,7 @@ function createScanProgressRenderer(enabled) {
215248
215405
  return {
215249
215406
  onProgress: (event) => {
215250
215407
  total = event.total;
215251
- currentFile = (0, import_node_path3.basename)(event.filePath);
215408
+ currentFile = (0, import_node_path4.basename)(event.filePath);
215252
215409
  if (event.status === "scanned" || event.status === "skipped" || event.status === "missing") {
215253
215410
  processed = event.index;
215254
215411
  }
@@ -215293,7 +215450,7 @@ function printRunResult(blocked) {
215293
215450
  // src/commands/check.ts
215294
215451
  async function checkCommand(files, options) {
215295
215452
  const selected = files.length > 0 ? files : await getStagedFiles();
215296
- const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path4.resolve)(process.cwd(), file));
215453
+ const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path5.resolve)(process.cwd(), file));
215297
215454
  if (!options.quietHeader) {
215298
215455
  if (process.stdout.isTTY) {
215299
215456
  clearScreen();
@@ -215338,9 +215495,55 @@ function parseMaxFindings(raw) {
215338
215495
  return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215339
215496
  }
215340
215497
 
215498
+ // src/commands/doctor.ts
215499
+ var import_node_child_process3 = require("child_process");
215500
+ var import_node_util3 = require("util");
215501
+ var execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
215502
+ async function doctorCommand() {
215503
+ const statuses = await Promise.all([
215504
+ checkTool("node", ["--version"], "required runtime"),
215505
+ checkTool("npm", ["--version"], "required package manager"),
215506
+ checkTool("semgrep", ["--version"], "optional: deep SAST findings"),
215507
+ checkTool("trivy", ["--version"], "optional: IaC/container/dependency findings")
215508
+ ]);
215509
+ console.log("Athena doctor\n");
215510
+ for (const status of statuses) {
215511
+ const mark = status.ok ? `${c2.green}\u2713${c2.reset}` : `${c2.red}\u2717${c2.reset}`;
215512
+ const version = status.ok ? `${c2.dim}${status.version}${c2.reset}` : `${c2.dim}not found${c2.reset}`;
215513
+ console.log(` ${mark} ${status.name.padEnd(10)} ${version}`);
215514
+ if (status.note) console.log(` ${c2.dim}${status.note}${c2.reset}`);
215515
+ }
215516
+ const semgrep = statuses.find((item) => item.name === "semgrep");
215517
+ if (!semgrep?.ok) {
215518
+ console.log(`
215519
+ ${c2.yellow}tip:${c2.reset} install Semgrep with ${c2.bold}athena setup semgrep${c2.reset}`);
215520
+ }
215521
+ }
215522
+ async function checkTool(name, args, note) {
215523
+ try {
215524
+ const { stdout, stderr } = await execFileAsync3(name, args, { timeout: 15e3, maxBuffer: 1024 * 1024 });
215525
+ const raw = `${stdout}
215526
+ ${stderr}`.trim();
215527
+ const line = raw.split(/\r?\n/).find((value) => value.trim().length > 0) ?? "ok";
215528
+ return {
215529
+ name,
215530
+ ok: true,
215531
+ version: line.trim(),
215532
+ note
215533
+ };
215534
+ } catch {
215535
+ return {
215536
+ name,
215537
+ ok: false,
215538
+ version: "not found",
215539
+ note
215540
+ };
215541
+ }
215542
+ }
215543
+
215341
215544
  // src/commands/init.ts
215342
215545
  var import_promises5 = require("fs/promises");
215343
- var import_node_path5 = require("path");
215546
+ var import_node_path6 = require("path");
215344
215547
  async function initCommand() {
215345
215548
  const root = await getGitRoot();
215346
215549
  const hooksDir = await getGitHooksDir();
@@ -215349,13 +215552,13 @@ async function initCommand() {
215349
215552
  process.exitCode = 1;
215350
215553
  return;
215351
215554
  }
215352
- const hookPath = (0, import_node_path5.join)(hooksDir, "pre-commit");
215555
+ const hookPath = (0, import_node_path6.join)(hooksDir, "pre-commit");
215353
215556
  const hook = [
215354
215557
  "#!/bin/sh",
215355
215558
  'echo "athena: checking staged JS/TS files"',
215356
215559
  "npx athena check"
215357
215560
  ].join("\n");
215358
- await (0, import_promises5.mkdir)((0, import_node_path5.dirname)(hookPath), { recursive: true });
215561
+ await (0, import_promises5.mkdir)((0, import_node_path6.dirname)(hookPath), { recursive: true });
215359
215562
  await (0, import_promises5.writeFile)(hookPath, `${hook}
215360
215563
  `, { mode: 493 });
215361
215564
  console.log(`Athena pre-commit hook installed at ${hookPath}`);
@@ -215365,9 +215568,9 @@ async function initCommand() {
215365
215568
  var import_node_readline = require("readline");
215366
215569
 
215367
215570
  // src/commands/scan.ts
215368
- var import_node_path6 = require("path");
215571
+ var import_node_path7 = require("path");
215369
215572
  async function scanCommand(dir, options) {
215370
- const root = (0, import_node_path6.resolve)(process.cwd(), dir);
215573
+ const root = (0, import_node_path7.resolve)(process.cwd(), dir);
215371
215574
  if (!options.quietHeader) {
215372
215575
  if (process.stdout.isTTY) {
215373
215576
  clearScreen();
@@ -215412,9 +215615,40 @@ function parseMaxFindings2(raw) {
215412
215615
  return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215413
215616
  }
215414
215617
 
215618
+ // src/commands/setup.ts
215619
+ var import_node_child_process4 = require("child_process");
215620
+ var import_node_util4 = require("util");
215621
+ var execAsync = (0, import_node_util4.promisify)(import_node_child_process4.exec);
215622
+ function getSemgrepInstallCommand(platform) {
215623
+ if (platform === "darwin") return "brew install semgrep";
215624
+ if (platform === "win32") return "choco install semgrep -y";
215625
+ return "python3 -m pip install --user semgrep";
215626
+ }
215627
+ async function setupSemgrepCommand(options = {}) {
215628
+ const installCommand = getSemgrepInstallCommand(process.platform);
215629
+ console.log("Semgrep setup");
215630
+ console.log(`Install command for this system:
215631
+ ${installCommand}`);
215632
+ if (!options.auto) {
215633
+ console.log("Run command above, then verify with: semgrep --version");
215634
+ return;
215635
+ }
215636
+ try {
215637
+ console.log("Running installer...");
215638
+ const { stdout, stderr } = await execAsync(installCommand, { timeout: 12e4, maxBuffer: 1024 * 1024 });
215639
+ if (stdout.trim()) console.log(stdout.trim());
215640
+ if (stderr.trim()) console.log(stderr.trim());
215641
+ console.log("Semgrep install command completed. Verify with: semgrep --version");
215642
+ } catch (error) {
215643
+ const message = error instanceof Error ? error.message : String(error);
215644
+ console.error(`Semgrep install failed: ${message}`);
215645
+ process.exitCode = 1;
215646
+ }
215647
+ }
215648
+
215415
215649
  // src/commands/uninstall.ts
215416
215650
  var import_promises6 = require("fs/promises");
215417
- var import_node_path7 = require("path");
215651
+ var import_node_path8 = require("path");
215418
215652
  async function uninstallCommand() {
215419
215653
  const root = await getGitRoot();
215420
215654
  const hooksDir = await getGitHooksDir();
@@ -215423,7 +215657,7 @@ async function uninstallCommand() {
215423
215657
  process.exitCode = 1;
215424
215658
  return;
215425
215659
  }
215426
- const hookPath = (0, import_node_path7.join)(hooksDir, "pre-commit");
215660
+ const hookPath = (0, import_node_path8.join)(hooksDir, "pre-commit");
215427
215661
  await (0, import_promises6.rm)(hookPath, { force: true });
215428
215662
  console.log(`Athena pre-commit hook removed from ${hookPath}`);
215429
215663
  }
@@ -215431,7 +215665,7 @@ async function uninstallCommand() {
215431
215665
  // package.json
215432
215666
  var package_default = {
215433
215667
  name: "@arsh342/athena",
215434
- version: "0.1.8",
215668
+ version: "0.1.9",
215435
215669
  description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
215436
215670
  type: "module",
215437
215671
  bin: {
@@ -215529,6 +215763,20 @@ async function menuCommand(program3) {
215529
215763
  detail: "Shows all commands, flags, and command descriptions.",
215530
215764
  run: () => program3.outputHelp()
215531
215765
  },
215766
+ {
215767
+ label: "Doctor toolchain",
215768
+ desc: "Check node/npm/semgrep/trivy availability.",
215769
+ command: "athena doctor",
215770
+ detail: "Useful for debugging missing external scanner dependencies.",
215771
+ run: doctorCommand
215772
+ },
215773
+ {
215774
+ label: "Setup Semgrep",
215775
+ desc: "Print Semgrep install command for this OS.",
215776
+ command: "athena setup semgrep",
215777
+ detail: "Install helper for optional Semgrep integration in scan pipeline.",
215778
+ run: () => setupSemgrepCommand()
215779
+ },
215532
215780
  {
215533
215781
  label: "Exit",
215534
215782
  desc: "Close selector.",
@@ -215562,7 +215810,7 @@ async function select(items) {
215562
215810
  process.stdin.resume();
215563
215811
  let index = 0;
215564
215812
  render(items, index, historyText);
215565
- return new Promise((resolve3) => {
215813
+ return new Promise((resolve4) => {
215566
215814
  const cleanup = () => {
215567
215815
  process.stdin.setRawMode(false);
215568
215816
  process.stdin.pause();
@@ -215570,7 +215818,7 @@ async function select(items) {
215570
215818
  };
215571
215819
  const done = (value) => {
215572
215820
  cleanup();
215573
- resolve3(value);
215821
+ resolve4(value);
215574
215822
  };
215575
215823
  const onKeypress = (_input, key) => {
215576
215824
  if (key.ctrl && key.name === "c") done(null);
@@ -215642,7 +215890,7 @@ async function waitForReturnToMenu() {
215642
215890
  (0, import_node_readline.emitKeypressEvents)(process.stdin);
215643
215891
  process.stdin.setRawMode(true);
215644
215892
  process.stdin.resume();
215645
- await new Promise((resolve3) => {
215893
+ await new Promise((resolve4) => {
215646
215894
  const cleanup = () => {
215647
215895
  process.stdin.setRawMode(false);
215648
215896
  process.stdin.pause();
@@ -215650,7 +215898,7 @@ async function waitForReturnToMenu() {
215650
215898
  };
215651
215899
  const onKeypress = () => {
215652
215900
  cleanup();
215653
- resolve3();
215901
+ resolve4();
215654
215902
  };
215655
215903
  process.stdin.on("keypress", onKeypress);
215656
215904
  });
@@ -215663,6 +215911,8 @@ program2.command("scan").argument("[dir]", "directory to scan", ".").option("-t,
215663
215911
  program2.command("check").argument("[files...]", "files to check; defaults to staged JS/TS files").option("-t, --threshold <number>", "AI score threshold", "9").option("-f, --format <format>", "terminal | json | jsonl", "terminal").option("-m, --max-findings <number|all>", "max findings to print (default: all)", "all").description("check changed files for blocking findings").action(checkCommand);
215664
215912
  program2.command("init").description("install Athena pre-commit hook").action(initCommand);
215665
215913
  program2.command("uninstall").description("remove Athena pre-commit hook").action(uninstallCommand);
215914
+ program2.command("doctor").description("check local toolchain health (node, npm, semgrep, trivy)").action(doctorCommand);
215915
+ program2.command("setup").description("setup optional external scanners").command("semgrep").option("--auto", "run install command automatically").description("install or print install command for semgrep").action(setupSemgrepCommand);
215666
215916
  program2.command("menu").description("open interactive terminal selector").action(() => menuCommand(program2));
215667
215917
  async function main() {
215668
215918
  if (process.stdout.isTTY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arsh342/athena",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
5
5
  "type": "module",
6
6
  "bin": {