@arsh342/athena 0.1.7 → 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 +307 -38
  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,13 +215170,32 @@ 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
- var ignoredDirs = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", "coverage"]);
215179
+ var ignoredDirs = /* @__PURE__ */ new Set([
215180
+ "node_modules",
215181
+ "dist",
215182
+ "build",
215183
+ ".git",
215184
+ "coverage",
215185
+ ".next",
215186
+ ".nuxt",
215187
+ ".svelte-kit",
215188
+ ".turbo",
215189
+ ".cache",
215190
+ ".parcel-cache",
215191
+ ".vite",
215192
+ ".vercel",
215193
+ ".vscode",
215194
+ ".idea",
215195
+ "tmp",
215196
+ "temp",
215197
+ "out"
215198
+ ]);
215023
215199
  function isSourceFile(filePath) {
215024
215200
  return [...supported].some((ext) => filePath.endsWith(ext));
215025
215201
  }
@@ -215035,25 +215211,25 @@ async function walk(dir, output) {
215035
215211
  const entries = await (0, import_promises3.readdir)(dir, { withFileTypes: true }).catch(() => []);
215036
215212
  for (const entry of entries) {
215037
215213
  if (entry.isDirectory()) {
215038
- 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);
215039
215215
  continue;
215040
215216
  }
215041
- const filePath = (0, import_node_path.join)(dir, entry.name);
215217
+ const filePath = (0, import_node_path2.join)(dir, entry.name);
215042
215218
  if (entry.isFile() && isSourceFile(filePath)) output.push(filePath);
215043
215219
  }
215044
215220
  }
215045
215221
 
215046
215222
  // src/utils/git.ts
215047
- var import_node_child_process = require("child_process");
215048
- var import_node_util = require("util");
215049
- 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);
215050
215226
  function logGitWarning(context, error) {
215051
215227
  const message = error instanceof Error ? error.message : String(error);
215052
215228
  console.warn(`[athena-cli] ${context}: ${message}`);
215053
215229
  }
215054
215230
  async function getGitRoot() {
215055
215231
  try {
215056
- const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"]);
215232
+ const { stdout } = await execFileAsync2("git", ["rev-parse", "--show-toplevel"]);
215057
215233
  return stdout.trim();
215058
215234
  } catch (error) {
215059
215235
  logGitWarning("Unable to resolve git root", error);
@@ -215062,7 +215238,7 @@ async function getGitRoot() {
215062
215238
  }
215063
215239
  async function getGitHooksDir() {
215064
215240
  try {
215065
- const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "hooks"]);
215241
+ const { stdout } = await execFileAsync2("git", ["rev-parse", "--git-path", "hooks"]);
215066
215242
  return stdout.trim();
215067
215243
  } catch (error) {
215068
215244
  logGitWarning("Unable to resolve git hooks directory", error);
@@ -215071,7 +215247,7 @@ async function getGitHooksDir() {
215071
215247
  }
215072
215248
  async function getStagedFiles() {
215073
215249
  try {
215074
- 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"]);
215075
215251
  return stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
215076
215252
  } catch (error) {
215077
215253
  logGitWarning("Unable to read staged files", error);
@@ -215082,9 +215258,9 @@ async function getStagedFiles() {
215082
215258
  // src/utils/history.ts
215083
215259
  var import_promises4 = require("fs/promises");
215084
215260
  var import_node_os = require("os");
215085
- var import_node_path2 = require("path");
215086
- var ATHENA_DIR = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".athena");
215087
- 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");
215088
215264
  var MAX_HISTORY_LINES = 300;
215089
215265
  function logHistoryWarning(context, error) {
215090
215266
  const message = error instanceof Error ? error.message : String(error);
@@ -215143,7 +215319,7 @@ function formatRecentHistory(entries) {
215143
215319
  }
215144
215320
 
215145
215321
  // src/utils/scan-progress.ts
215146
- var import_node_path3 = require("path");
215322
+ var import_node_path4 = require("path");
215147
215323
 
215148
215324
  // src/utils/colors.ts
215149
215325
  var c2 = {
@@ -215229,7 +215405,7 @@ function createScanProgressRenderer(enabled) {
215229
215405
  return {
215230
215406
  onProgress: (event) => {
215231
215407
  total = event.total;
215232
- currentFile = (0, import_node_path3.basename)(event.filePath);
215408
+ currentFile = (0, import_node_path4.basename)(event.filePath);
215233
215409
  if (event.status === "scanned" || event.status === "skipped" || event.status === "missing") {
215234
215410
  processed = event.index;
215235
215411
  }
@@ -215274,7 +215450,7 @@ function printRunResult(blocked) {
215274
215450
  // src/commands/check.ts
215275
215451
  async function checkCommand(files, options) {
215276
215452
  const selected = files.length > 0 ? files : await getStagedFiles();
215277
- 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));
215278
215454
  if (!options.quietHeader) {
215279
215455
  if (process.stdout.isTTY) {
215280
215456
  clearScreen();
@@ -215319,9 +215495,55 @@ function parseMaxFindings(raw) {
215319
215495
  return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215320
215496
  }
215321
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
+
215322
215544
  // src/commands/init.ts
215323
215545
  var import_promises5 = require("fs/promises");
215324
- var import_node_path5 = require("path");
215546
+ var import_node_path6 = require("path");
215325
215547
  async function initCommand() {
215326
215548
  const root = await getGitRoot();
215327
215549
  const hooksDir = await getGitHooksDir();
@@ -215330,13 +215552,13 @@ async function initCommand() {
215330
215552
  process.exitCode = 1;
215331
215553
  return;
215332
215554
  }
215333
- const hookPath = (0, import_node_path5.join)(hooksDir, "pre-commit");
215555
+ const hookPath = (0, import_node_path6.join)(hooksDir, "pre-commit");
215334
215556
  const hook = [
215335
215557
  "#!/bin/sh",
215336
215558
  'echo "athena: checking staged JS/TS files"',
215337
215559
  "npx athena check"
215338
215560
  ].join("\n");
215339
- 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 });
215340
215562
  await (0, import_promises5.writeFile)(hookPath, `${hook}
215341
215563
  `, { mode: 493 });
215342
215564
  console.log(`Athena pre-commit hook installed at ${hookPath}`);
@@ -215346,9 +215568,9 @@ async function initCommand() {
215346
215568
  var import_node_readline = require("readline");
215347
215569
 
215348
215570
  // src/commands/scan.ts
215349
- var import_node_path6 = require("path");
215571
+ var import_node_path7 = require("path");
215350
215572
  async function scanCommand(dir, options) {
215351
- const root = (0, import_node_path6.resolve)(process.cwd(), dir);
215573
+ const root = (0, import_node_path7.resolve)(process.cwd(), dir);
215352
215574
  if (!options.quietHeader) {
215353
215575
  if (process.stdout.isTTY) {
215354
215576
  clearScreen();
@@ -215393,9 +215615,40 @@ function parseMaxFindings2(raw) {
215393
215615
  return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215394
215616
  }
215395
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
+
215396
215649
  // src/commands/uninstall.ts
215397
215650
  var import_promises6 = require("fs/promises");
215398
- var import_node_path7 = require("path");
215651
+ var import_node_path8 = require("path");
215399
215652
  async function uninstallCommand() {
215400
215653
  const root = await getGitRoot();
215401
215654
  const hooksDir = await getGitHooksDir();
@@ -215404,7 +215657,7 @@ async function uninstallCommand() {
215404
215657
  process.exitCode = 1;
215405
215658
  return;
215406
215659
  }
215407
- const hookPath = (0, import_node_path7.join)(hooksDir, "pre-commit");
215660
+ const hookPath = (0, import_node_path8.join)(hooksDir, "pre-commit");
215408
215661
  await (0, import_promises6.rm)(hookPath, { force: true });
215409
215662
  console.log(`Athena pre-commit hook removed from ${hookPath}`);
215410
215663
  }
@@ -215412,7 +215665,7 @@ async function uninstallCommand() {
215412
215665
  // package.json
215413
215666
  var package_default = {
215414
215667
  name: "@arsh342/athena",
215415
- version: "0.1.7",
215668
+ version: "0.1.9",
215416
215669
  description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
215417
215670
  type: "module",
215418
215671
  bin: {
@@ -215510,6 +215763,20 @@ async function menuCommand(program3) {
215510
215763
  detail: "Shows all commands, flags, and command descriptions.",
215511
215764
  run: () => program3.outputHelp()
215512
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
+ },
215513
215780
  {
215514
215781
  label: "Exit",
215515
215782
  desc: "Close selector.",
@@ -215543,7 +215810,7 @@ async function select(items) {
215543
215810
  process.stdin.resume();
215544
215811
  let index = 0;
215545
215812
  render(items, index, historyText);
215546
- return new Promise((resolve3) => {
215813
+ return new Promise((resolve4) => {
215547
215814
  const cleanup = () => {
215548
215815
  process.stdin.setRawMode(false);
215549
215816
  process.stdin.pause();
@@ -215551,7 +215818,7 @@ async function select(items) {
215551
215818
  };
215552
215819
  const done = (value) => {
215553
215820
  cleanup();
215554
- resolve3(value);
215821
+ resolve4(value);
215555
215822
  };
215556
215823
  const onKeypress = (_input, key) => {
215557
215824
  if (key.ctrl && key.name === "c") done(null);
@@ -215623,7 +215890,7 @@ async function waitForReturnToMenu() {
215623
215890
  (0, import_node_readline.emitKeypressEvents)(process.stdin);
215624
215891
  process.stdin.setRawMode(true);
215625
215892
  process.stdin.resume();
215626
- await new Promise((resolve3) => {
215893
+ await new Promise((resolve4) => {
215627
215894
  const cleanup = () => {
215628
215895
  process.stdin.setRawMode(false);
215629
215896
  process.stdin.pause();
@@ -215631,7 +215898,7 @@ async function waitForReturnToMenu() {
215631
215898
  };
215632
215899
  const onKeypress = () => {
215633
215900
  cleanup();
215634
- resolve3();
215901
+ resolve4();
215635
215902
  };
215636
215903
  process.stdin.on("keypress", onKeypress);
215637
215904
  });
@@ -215644,6 +215911,8 @@ program2.command("scan").argument("[dir]", "directory to scan", ".").option("-t,
215644
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);
215645
215912
  program2.command("init").description("install Athena pre-commit hook").action(initCommand);
215646
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);
215647
215916
  program2.command("menu").description("open interactive terminal selector").action(() => menuCommand(program2));
215648
215917
  async function main() {
215649
215918
  if (process.stdout.isTTY) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arsh342/athena",
3
- "version": "0.1.7",
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": {