@arsh342/athena 0.1.6 → 0.1.8

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 +183 -35
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -140010,9 +140010,9 @@ ${lanes.join("\n")}
140010
140010
  /*ignoreCase*/
140011
140011
  false
140012
140012
  )) {
140013
- const basename = getBaseFileName(a.fileName);
140014
- if (basename === "lib.d.ts" || basename === "lib.es6.d.ts") return 0;
140015
- const name = removeSuffix(removePrefix(basename, "lib."), ".d.ts");
140013
+ const basename2 = getBaseFileName(a.fileName);
140014
+ if (basename2 === "lib.d.ts" || basename2 === "lib.es6.d.ts") return 0;
140015
+ const name = removeSuffix(removePrefix(basename2, "lib."), ".d.ts");
140016
140016
  const index = libs.indexOf(name);
140017
140017
  if (index !== -1) return index + 1;
140018
140018
  }
@@ -203758,8 +203758,8 @@ ${options.prefix}` : "\n" : options.prefix
203758
203758
  }
203759
203759
  };
203760
203760
  for (const file of files) {
203761
- const basename = getBaseFileName(file);
203762
- if (basename === "package.json" || basename === "bower.json") {
203761
+ const basename2 = getBaseFileName(file);
203762
+ if (basename2 === "package.json" || basename2 === "bower.json") {
203763
203763
  createProjectWatcher(
203764
203764
  file,
203765
203765
  "FileWatcher"
@@ -207431,8 +207431,8 @@ All files are: ${JSON.stringify(names)}`,
207431
207431
  var _a;
207432
207432
  const fileOrDirectoryPath = removeIgnoredPath(this.toPath(fileOrDirectory));
207433
207433
  if (!fileOrDirectoryPath) return;
207434
- const basename = getBaseFileName(fileOrDirectoryPath);
207435
- if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename === "package.json" || basename === "node_modules")) {
207434
+ const basename2 = getBaseFileName(fileOrDirectoryPath);
207435
+ if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (basename2 === "package.json" || basename2 === "node_modules")) {
207436
207436
  result.affectedModuleSpecifierCacheProjects.forEach((project) => {
207437
207437
  var _a2;
207438
207438
  (_a2 = project.getModuleSpecifierCache()) == null ? void 0 : _a2.clear();
@@ -214815,18 +214815,45 @@ function explain(score, signals) {
214815
214815
  }
214816
214816
 
214817
214817
  // ../core/dist/engine.js
214818
- async function scanFiles(filePaths, configInput = {}) {
214818
+ async function scanFiles(filePaths, configInput = {}, hooks = {}) {
214819
214819
  const startedAt = Date.now();
214820
214820
  const config = mergeConfig(configInput);
214821
214821
  const files = [];
214822
214822
  let totalLoc = 0;
214823
214823
  let skippedFiles = 0;
214824
- for (const filePath of filePaths) {
214824
+ const totalFiles = filePaths.length;
214825
+ let processedFiles = 0;
214826
+ for (let index = 0; index < filePaths.length; index++) {
214827
+ const filePath = filePaths[index];
214828
+ hooks.onFileProgress?.({
214829
+ filePath,
214830
+ index: index + 1,
214831
+ total: totalFiles,
214832
+ status: "scanning",
214833
+ findings: 0
214834
+ });
214825
214835
  const fileStat = await (0, import_promises2.stat)(filePath).catch(() => null);
214826
- if (!fileStat)
214836
+ if (!fileStat) {
214837
+ processedFiles += 1;
214838
+ hooks.onFileProgress?.({
214839
+ filePath,
214840
+ index: processedFiles,
214841
+ total: totalFiles,
214842
+ status: "missing",
214843
+ findings: 0
214844
+ });
214827
214845
  continue;
214846
+ }
214828
214847
  if (fileStat.size > config.maxFileSize) {
214829
214848
  skippedFiles += 1;
214849
+ processedFiles += 1;
214850
+ hooks.onFileProgress?.({
214851
+ filePath,
214852
+ index: processedFiles,
214853
+ total: totalFiles,
214854
+ status: "skipped",
214855
+ findings: 0
214856
+ });
214830
214857
  continue;
214831
214858
  }
214832
214859
  const units = await parseFile(filePath).catch(() => []);
@@ -214838,6 +214865,14 @@ async function scanFiles(filePaths, configInput = {}) {
214838
214865
  units: scoredUnits,
214839
214866
  findings
214840
214867
  });
214868
+ processedFiles += 1;
214869
+ hooks.onFileProgress?.({
214870
+ filePath,
214871
+ index: processedFiles,
214872
+ total: totalFiles,
214873
+ status: "scanned",
214874
+ findings: findings.length
214875
+ });
214841
214876
  }
214842
214877
  return generateReport(startedAt, files, totalLoc, skippedFiles, config);
214843
214878
  }
@@ -214860,9 +214895,11 @@ var severityColor = {
214860
214895
  MEDIUM: c.yellow,
214861
214896
  LOW: c.gray
214862
214897
  };
214863
- function formatTerminalReport(report) {
214898
+ function formatTerminalReport(report, options = {}) {
214864
214899
  const lines = [];
214865
214900
  const summary = report.summary;
214901
+ const maxFindings = Number.isFinite(options.maxFindings) ? Math.max(0, options.maxFindings ?? 0) : Number.POSITIVE_INFINITY;
214902
+ const codePreviewLines = Math.max(1, options.codePreviewLines ?? 8);
214866
214903
  const securityFindingsTotal = Object.values(summary.findings).reduce((sum, count) => sum + count, 0);
214867
214904
  const thresholdUsed = summary.calibration?.thresholdUsed;
214868
214905
  const aiScoreRelation = typeof thresholdUsed === "number" ? summary.aiScore === thresholdUsed ? "at threshold" : summary.aiScore < thresholdUsed ? "below threshold" : "above threshold" : "threshold unavailable";
@@ -214927,19 +214964,28 @@ function formatTerminalReport(report) {
214927
214964
  }
214928
214965
  lines.push(sectionRule("Findings"));
214929
214966
  lines.push("");
214930
- for (const finding of findings.slice(0, 20)) {
214967
+ const shownFindings = findings.slice(0, maxFindings);
214968
+ for (const finding of shownFindings) {
214931
214969
  const sevColor = severityColor[finding.severity];
214932
- lines.push(` ${sevColor}${finding.severity.padEnd(9)}${c.reset}${c.bold}${finding.type}${c.reset} ${c.dim}${finding.id}${c.reset}`);
214933
- lines.push(` ${c.orange}${finding.file}:${finding.line}${c.reset} ${c.dim}ai=${finding.aiScore} source=${finding.source}${c.reset}`);
214970
+ lines.push(` ${sevColor}\u25CF ${finding.severity}${c.reset} ${c.bold}${finding.type}${c.reset} ${c.dim}${finding.id}${c.reset}`);
214971
+ lines.push(` ${c.orange}${finding.file}:${finding.line}${c.reset} ${c.dim}source=${finding.source}${c.reset} ${c.dim}ai=${finding.aiScore}${c.reset}`);
214934
214972
  lines.push(` ${c.dim}${finding.message}${c.reset}`);
214973
+ const snippet = formatCodeSnippet(finding.code, codePreviewLines);
214974
+ if (snippet.length > 0) {
214975
+ lines.push(` ${c.dim}code:${c.reset}`);
214976
+ for (const line of snippet) {
214977
+ lines.push(` ${c.white}${line}${c.reset}`);
214978
+ }
214979
+ }
214935
214980
  if (finding.explainedScore.topSignals.length > 0) {
214936
214981
  const signals = finding.explainedScore.topSignals.map((s) => `${s.signal}:${c.orange}${s.contribution}%${c.reset}`).join(" ");
214937
214982
  lines.push(` ${c.dim}signals:${c.reset} ${signals}`);
214938
214983
  }
214939
214984
  lines.push("");
214940
214985
  }
214941
- if (findings.length > 20) {
214942
- lines.push(` ${c.dim}\u2026 ${findings.length - 20} more findings omitted${c.reset}`);
214986
+ if (findings.length > shownFindings.length) {
214987
+ lines.push(` ${c.dim}\u2026 ${findings.length - shownFindings.length} more findings omitted${c.reset}`);
214988
+ lines.push(` ${c.dim}tip: rerun with --max-findings all to print every finding${c.reset}`);
214943
214989
  lines.push("");
214944
214990
  }
214945
214991
  return lines.join("\n");
@@ -214962,15 +215008,37 @@ function severityBar(report) {
214962
215008
  return `${severityColor[severity]}${"\u2588".repeat(width)}${c.reset} ${severity}:${count}`;
214963
215009
  }).join(" ");
214964
215010
  }
215011
+ function formatCodeSnippet(code, maxLines) {
215012
+ return code.split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.trim().length > 0).slice(0, maxLines);
215013
+ }
214965
215014
 
214966
215015
  // src/commands/check.ts
214967
- var import_node_path3 = require("path");
215016
+ var import_node_path4 = require("path");
214968
215017
 
214969
215018
  // src/utils/file-filter.ts
214970
215019
  var import_promises3 = require("fs/promises");
214971
215020
  var import_node_path = require("path");
214972
215021
  var supported = /* @__PURE__ */ new Set([".js", ".jsx", ".ts", ".tsx"]);
214973
- var ignoredDirs = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", "coverage"]);
215022
+ var ignoredDirs = /* @__PURE__ */ new Set([
215023
+ "node_modules",
215024
+ "dist",
215025
+ "build",
215026
+ ".git",
215027
+ "coverage",
215028
+ ".next",
215029
+ ".nuxt",
215030
+ ".svelte-kit",
215031
+ ".turbo",
215032
+ ".cache",
215033
+ ".parcel-cache",
215034
+ ".vite",
215035
+ ".vercel",
215036
+ ".vscode",
215037
+ ".idea",
215038
+ "tmp",
215039
+ "temp",
215040
+ "out"
215041
+ ]);
214974
215042
  function isSourceFile(filePath) {
214975
215043
  return [...supported].some((ext) => filePath.endsWith(ext));
214976
215044
  }
@@ -215093,6 +215161,9 @@ function formatRecentHistory(entries) {
215093
215161
  return `history: ${parts.join(" | ")}`;
215094
215162
  }
215095
215163
 
215164
+ // src/utils/scan-progress.ts
215165
+ var import_node_path3 = require("path");
215166
+
215096
215167
  // src/utils/colors.ts
215097
215168
  var c2 = {
215098
215169
  reset: "\x1B[0m",
@@ -215152,6 +215223,49 @@ function truncate(value, max) {
215152
215223
  return `\u2026${value.slice(value.length - max + 1)}`;
215153
215224
  }
215154
215225
 
215226
+ // src/utils/scan-progress.ts
215227
+ var FRAMES = ["\u280B", "\u2819", "\u2838", "\u2834", "\u2826", "\u2807"];
215228
+ function createScanProgressRenderer(enabled) {
215229
+ if (!enabled || !process.stdout.isTTY) {
215230
+ return {
215231
+ onProgress: (_event) => void 0,
215232
+ stop: () => void 0
215233
+ };
215234
+ }
215235
+ let frame = 0;
215236
+ let processed = 0;
215237
+ let total = 0;
215238
+ let findings = 0;
215239
+ let currentFile = "";
215240
+ const timer = setInterval(() => {
215241
+ const cols = process.stdout.columns ?? 100;
215242
+ const spinner = FRAMES[frame % FRAMES.length];
215243
+ frame += 1;
215244
+ const fileLabel = currentFile ? truncate(currentFile, Math.max(12, cols - 50)) : "preparing scan";
215245
+ const line = `\r ${c2.accent}${spinner}${c2.reset} scanning ${c2.bold}${processed}/${total}${c2.reset} ${c2.dim}${fileLabel}${c2.reset} ${c2.orange}findings:${findings}${c2.reset}`;
215246
+ process.stdout.write(line);
215247
+ }, 90);
215248
+ return {
215249
+ onProgress: (event) => {
215250
+ total = event.total;
215251
+ currentFile = (0, import_node_path3.basename)(event.filePath);
215252
+ if (event.status === "scanned" || event.status === "skipped" || event.status === "missing") {
215253
+ processed = event.index;
215254
+ }
215255
+ if (event.status === "scanned") {
215256
+ findings += event.findings;
215257
+ }
215258
+ },
215259
+ stop: () => {
215260
+ clearInterval(timer);
215261
+ process.stdout.write("\r\x1B[2K");
215262
+ process.stdout.write(` ${c2.green}\u2713${c2.reset} scan complete ${c2.dim}${processed}/${total} files${c2.reset} ${c2.orange}findings:${findings}${c2.reset}
215263
+
215264
+ `);
215265
+ }
215266
+ };
215267
+ }
215268
+
215155
215269
  // src/utils/terminal.ts
215156
215270
  function clearScreen() {
215157
215271
  process.stdout.write("\x1B[3J\x1B[2J\x1B[H");
@@ -215179,7 +215293,7 @@ function printRunResult(blocked) {
215179
215293
  // src/commands/check.ts
215180
215294
  async function checkCommand(files, options) {
215181
215295
  const selected = files.length > 0 ? files : await getStagedFiles();
215182
- const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path3.resolve)(process.cwd(), file));
215296
+ const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path4.resolve)(process.cwd(), file));
215183
215297
  if (!options.quietHeader) {
215184
215298
  if (process.stdout.isTTY) {
215185
215299
  clearScreen();
@@ -215187,13 +215301,25 @@ async function checkCommand(files, options) {
215187
215301
  printRunHeader("check", `${sourceFiles.length} staged/source files`);
215188
215302
  }
215189
215303
  const expanded = sourceFiles.length === 1 ? await findSourceFiles(sourceFiles[0]) : sourceFiles;
215190
- const report = await scanFiles(expanded, { threshold: Number(options.threshold) });
215304
+ const maxFindings = parseMaxFindings(options.maxFindings);
215305
+ const progress = createScanProgressRenderer(options.format === "terminal");
215306
+ const report = await (async () => {
215307
+ try {
215308
+ return await scanFiles(
215309
+ expanded,
215310
+ { threshold: Number(options.threshold) },
215311
+ { onFileProgress: progress.onProgress }
215312
+ );
215313
+ } finally {
215314
+ progress.stop();
215315
+ }
215316
+ })();
215191
215317
  if (options.format === "json") {
215192
215318
  console.log(JSON.stringify(report, null, 2));
215193
215319
  } else if (options.format === "jsonl") {
215194
215320
  console.log(formatJsonl(report));
215195
215321
  } else {
215196
- console.log(formatTerminalReport(report));
215322
+ console.log(formatTerminalReport(report, { maxFindings }));
215197
215323
  }
215198
215324
  await appendScanHistory({
215199
215325
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -215206,10 +215332,15 @@ async function checkCommand(files, options) {
215206
215332
  printRunResult(report.summary.blocked);
215207
215333
  process.exitCode = report.summary.blocked ? 1 : 0;
215208
215334
  }
215335
+ function parseMaxFindings(raw) {
215336
+ if (!raw || raw === "all") return Number.POSITIVE_INFINITY;
215337
+ const parsed2 = Number(raw);
215338
+ return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215339
+ }
215209
215340
 
215210
215341
  // src/commands/init.ts
215211
215342
  var import_promises5 = require("fs/promises");
215212
- var import_node_path4 = require("path");
215343
+ var import_node_path5 = require("path");
215213
215344
  async function initCommand() {
215214
215345
  const root = await getGitRoot();
215215
215346
  const hooksDir = await getGitHooksDir();
@@ -215218,13 +215349,13 @@ async function initCommand() {
215218
215349
  process.exitCode = 1;
215219
215350
  return;
215220
215351
  }
215221
- const hookPath = (0, import_node_path4.join)(hooksDir, "pre-commit");
215352
+ const hookPath = (0, import_node_path5.join)(hooksDir, "pre-commit");
215222
215353
  const hook = [
215223
215354
  "#!/bin/sh",
215224
215355
  'echo "athena: checking staged JS/TS files"',
215225
215356
  "npx athena check"
215226
215357
  ].join("\n");
215227
- await (0, import_promises5.mkdir)((0, import_node_path4.dirname)(hookPath), { recursive: true });
215358
+ await (0, import_promises5.mkdir)((0, import_node_path5.dirname)(hookPath), { recursive: true });
215228
215359
  await (0, import_promises5.writeFile)(hookPath, `${hook}
215229
215360
  `, { mode: 493 });
215230
215361
  console.log(`Athena pre-commit hook installed at ${hookPath}`);
@@ -215234,9 +215365,9 @@ async function initCommand() {
215234
215365
  var import_node_readline = require("readline");
215235
215366
 
215236
215367
  // src/commands/scan.ts
215237
- var import_node_path5 = require("path");
215368
+ var import_node_path6 = require("path");
215238
215369
  async function scanCommand(dir, options) {
215239
- const root = (0, import_node_path5.resolve)(process.cwd(), dir);
215370
+ const root = (0, import_node_path6.resolve)(process.cwd(), dir);
215240
215371
  if (!options.quietHeader) {
215241
215372
  if (process.stdout.isTTY) {
215242
215373
  clearScreen();
@@ -215244,13 +215375,25 @@ async function scanCommand(dir, options) {
215244
215375
  printRunHeader("scan", root);
215245
215376
  }
215246
215377
  const files = await findSourceFiles(root);
215247
- const report = await scanFiles(files, { threshold: Number(options.threshold) });
215378
+ const maxFindings = parseMaxFindings2(options.maxFindings);
215379
+ const progress = createScanProgressRenderer(options.format === "terminal");
215380
+ const report = await (async () => {
215381
+ try {
215382
+ return await scanFiles(
215383
+ files,
215384
+ { threshold: Number(options.threshold) },
215385
+ { onFileProgress: progress.onProgress }
215386
+ );
215387
+ } finally {
215388
+ progress.stop();
215389
+ }
215390
+ })();
215248
215391
  if (options.format === "json") {
215249
215392
  console.log(JSON.stringify(report, null, 2));
215250
215393
  } else if (options.format === "jsonl") {
215251
215394
  console.log(formatJsonl(report));
215252
215395
  } else {
215253
- console.log(formatTerminalReport(report));
215396
+ console.log(formatTerminalReport(report, { maxFindings }));
215254
215397
  }
215255
215398
  await appendScanHistory({
215256
215399
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -215263,10 +215406,15 @@ async function scanCommand(dir, options) {
215263
215406
  printRunResult(report.summary.blocked);
215264
215407
  process.exitCode = report.summary.blocked ? 1 : 0;
215265
215408
  }
215409
+ function parseMaxFindings2(raw) {
215410
+ if (!raw || raw === "all") return Number.POSITIVE_INFINITY;
215411
+ const parsed2 = Number(raw);
215412
+ return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215413
+ }
215266
215414
 
215267
215415
  // src/commands/uninstall.ts
215268
215416
  var import_promises6 = require("fs/promises");
215269
- var import_node_path6 = require("path");
215417
+ var import_node_path7 = require("path");
215270
215418
  async function uninstallCommand() {
215271
215419
  const root = await getGitRoot();
215272
215420
  const hooksDir = await getGitHooksDir();
@@ -215275,7 +215423,7 @@ async function uninstallCommand() {
215275
215423
  process.exitCode = 1;
215276
215424
  return;
215277
215425
  }
215278
- const hookPath = (0, import_node_path6.join)(hooksDir, "pre-commit");
215426
+ const hookPath = (0, import_node_path7.join)(hooksDir, "pre-commit");
215279
215427
  await (0, import_promises6.rm)(hookPath, { force: true });
215280
215428
  console.log(`Athena pre-commit hook removed from ${hookPath}`);
215281
215429
  }
@@ -215283,7 +215431,7 @@ async function uninstallCommand() {
215283
215431
  // package.json
215284
215432
  var package_default = {
215285
215433
  name: "@arsh342/athena",
215286
- version: "0.1.6",
215434
+ version: "0.1.8",
215287
215435
  description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
215288
215436
  type: "module",
215289
215437
  bin: {
@@ -215351,14 +215499,14 @@ async function menuCommand(program3) {
215351
215499
  desc: "Run full recursive JS/TS scan from cwd.",
215352
215500
  command: "athena scan .",
215353
215501
  detail: "Parse code units, score AI provenance, run targeted security checks, print report.",
215354
- run: () => scanCommand(".", { threshold: "9", format: "terminal", quietHeader: true })
215502
+ run: () => scanCommand(".", { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
215355
215503
  },
215356
215504
  {
215357
215505
  label: "Check staged files",
215358
215506
  desc: "Scan staged JS/TS files, same path used by pre-commit hook.",
215359
215507
  command: "athena check",
215360
215508
  detail: "Fast gate for commit flow. Reads git staged files and exits 1 on blocking risk.",
215361
- run: () => checkCommand([], { threshold: "9", format: "terminal", quietHeader: true })
215509
+ run: () => checkCommand([], { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
215362
215510
  },
215363
215511
  {
215364
215512
  label: "Install pre-commit hook",
@@ -215511,8 +215659,8 @@ async function waitForReturnToMenu() {
215511
215659
  // src/index.ts
215512
215660
  var program2 = new Command();
215513
215661
  program2.name("athena").description("AI code provenance tracker for JavaScript and TypeScript repositories").version(CLI_VERSION);
215514
- program2.command("scan").argument("[dir]", "directory to scan", ".").option("-t, --threshold <number>", "AI score threshold", "9").option("-f, --format <format>", "terminal | json | jsonl", "terminal").description("scan a directory recursively").action(scanCommand);
215515
- 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").description("check changed files for blocking findings").action(checkCommand);
215662
+ program2.command("scan").argument("[dir]", "directory to scan", ".").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("scan a directory recursively").action(scanCommand);
215663
+ 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);
215516
215664
  program2.command("init").description("install Athena pre-commit hook").action(initCommand);
215517
215665
  program2.command("uninstall").description("remove Athena pre-commit hook").action(uninstallCommand);
215518
215666
  program2.command("menu").description("open interactive terminal selector").action(() => menuCommand(program2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arsh342/athena",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
5
5
  "type": "module",
6
6
  "bin": {