@arsh342/athena 0.1.6 → 0.1.7

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 +163 -34
  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,9 +215008,12 @@ 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");
@@ -215093,6 +215142,9 @@ function formatRecentHistory(entries) {
215093
215142
  return `history: ${parts.join(" | ")}`;
215094
215143
  }
215095
215144
 
215145
+ // src/utils/scan-progress.ts
215146
+ var import_node_path3 = require("path");
215147
+
215096
215148
  // src/utils/colors.ts
215097
215149
  var c2 = {
215098
215150
  reset: "\x1B[0m",
@@ -215152,6 +215204,49 @@ function truncate(value, max) {
215152
215204
  return `\u2026${value.slice(value.length - max + 1)}`;
215153
215205
  }
215154
215206
 
215207
+ // src/utils/scan-progress.ts
215208
+ var FRAMES = ["\u280B", "\u2819", "\u2838", "\u2834", "\u2826", "\u2807"];
215209
+ function createScanProgressRenderer(enabled) {
215210
+ if (!enabled || !process.stdout.isTTY) {
215211
+ return {
215212
+ onProgress: (_event) => void 0,
215213
+ stop: () => void 0
215214
+ };
215215
+ }
215216
+ let frame = 0;
215217
+ let processed = 0;
215218
+ let total = 0;
215219
+ let findings = 0;
215220
+ let currentFile = "";
215221
+ const timer = setInterval(() => {
215222
+ const cols = process.stdout.columns ?? 100;
215223
+ const spinner = FRAMES[frame % FRAMES.length];
215224
+ frame += 1;
215225
+ const fileLabel = currentFile ? truncate(currentFile, Math.max(12, cols - 50)) : "preparing scan";
215226
+ 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}`;
215227
+ process.stdout.write(line);
215228
+ }, 90);
215229
+ return {
215230
+ onProgress: (event) => {
215231
+ total = event.total;
215232
+ currentFile = (0, import_node_path3.basename)(event.filePath);
215233
+ if (event.status === "scanned" || event.status === "skipped" || event.status === "missing") {
215234
+ processed = event.index;
215235
+ }
215236
+ if (event.status === "scanned") {
215237
+ findings += event.findings;
215238
+ }
215239
+ },
215240
+ stop: () => {
215241
+ clearInterval(timer);
215242
+ process.stdout.write("\r\x1B[2K");
215243
+ process.stdout.write(` ${c2.green}\u2713${c2.reset} scan complete ${c2.dim}${processed}/${total} files${c2.reset} ${c2.orange}findings:${findings}${c2.reset}
215244
+
215245
+ `);
215246
+ }
215247
+ };
215248
+ }
215249
+
215155
215250
  // src/utils/terminal.ts
215156
215251
  function clearScreen() {
215157
215252
  process.stdout.write("\x1B[3J\x1B[2J\x1B[H");
@@ -215179,7 +215274,7 @@ function printRunResult(blocked) {
215179
215274
  // src/commands/check.ts
215180
215275
  async function checkCommand(files, options) {
215181
215276
  const selected = files.length > 0 ? files : await getStagedFiles();
215182
- const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path3.resolve)(process.cwd(), file));
215277
+ const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path4.resolve)(process.cwd(), file));
215183
215278
  if (!options.quietHeader) {
215184
215279
  if (process.stdout.isTTY) {
215185
215280
  clearScreen();
@@ -215187,13 +215282,25 @@ async function checkCommand(files, options) {
215187
215282
  printRunHeader("check", `${sourceFiles.length} staged/source files`);
215188
215283
  }
215189
215284
  const expanded = sourceFiles.length === 1 ? await findSourceFiles(sourceFiles[0]) : sourceFiles;
215190
- const report = await scanFiles(expanded, { threshold: Number(options.threshold) });
215285
+ const maxFindings = parseMaxFindings(options.maxFindings);
215286
+ const progress = createScanProgressRenderer(options.format === "terminal");
215287
+ const report = await (async () => {
215288
+ try {
215289
+ return await scanFiles(
215290
+ expanded,
215291
+ { threshold: Number(options.threshold) },
215292
+ { onFileProgress: progress.onProgress }
215293
+ );
215294
+ } finally {
215295
+ progress.stop();
215296
+ }
215297
+ })();
215191
215298
  if (options.format === "json") {
215192
215299
  console.log(JSON.stringify(report, null, 2));
215193
215300
  } else if (options.format === "jsonl") {
215194
215301
  console.log(formatJsonl(report));
215195
215302
  } else {
215196
- console.log(formatTerminalReport(report));
215303
+ console.log(formatTerminalReport(report, { maxFindings }));
215197
215304
  }
215198
215305
  await appendScanHistory({
215199
215306
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -215206,10 +215313,15 @@ async function checkCommand(files, options) {
215206
215313
  printRunResult(report.summary.blocked);
215207
215314
  process.exitCode = report.summary.blocked ? 1 : 0;
215208
215315
  }
215316
+ function parseMaxFindings(raw) {
215317
+ if (!raw || raw === "all") return Number.POSITIVE_INFINITY;
215318
+ const parsed2 = Number(raw);
215319
+ return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215320
+ }
215209
215321
 
215210
215322
  // src/commands/init.ts
215211
215323
  var import_promises5 = require("fs/promises");
215212
- var import_node_path4 = require("path");
215324
+ var import_node_path5 = require("path");
215213
215325
  async function initCommand() {
215214
215326
  const root = await getGitRoot();
215215
215327
  const hooksDir = await getGitHooksDir();
@@ -215218,13 +215330,13 @@ async function initCommand() {
215218
215330
  process.exitCode = 1;
215219
215331
  return;
215220
215332
  }
215221
- const hookPath = (0, import_node_path4.join)(hooksDir, "pre-commit");
215333
+ const hookPath = (0, import_node_path5.join)(hooksDir, "pre-commit");
215222
215334
  const hook = [
215223
215335
  "#!/bin/sh",
215224
215336
  'echo "athena: checking staged JS/TS files"',
215225
215337
  "npx athena check"
215226
215338
  ].join("\n");
215227
- await (0, import_promises5.mkdir)((0, import_node_path4.dirname)(hookPath), { recursive: true });
215339
+ await (0, import_promises5.mkdir)((0, import_node_path5.dirname)(hookPath), { recursive: true });
215228
215340
  await (0, import_promises5.writeFile)(hookPath, `${hook}
215229
215341
  `, { mode: 493 });
215230
215342
  console.log(`Athena pre-commit hook installed at ${hookPath}`);
@@ -215234,9 +215346,9 @@ async function initCommand() {
215234
215346
  var import_node_readline = require("readline");
215235
215347
 
215236
215348
  // src/commands/scan.ts
215237
- var import_node_path5 = require("path");
215349
+ var import_node_path6 = require("path");
215238
215350
  async function scanCommand(dir, options) {
215239
- const root = (0, import_node_path5.resolve)(process.cwd(), dir);
215351
+ const root = (0, import_node_path6.resolve)(process.cwd(), dir);
215240
215352
  if (!options.quietHeader) {
215241
215353
  if (process.stdout.isTTY) {
215242
215354
  clearScreen();
@@ -215244,13 +215356,25 @@ async function scanCommand(dir, options) {
215244
215356
  printRunHeader("scan", root);
215245
215357
  }
215246
215358
  const files = await findSourceFiles(root);
215247
- const report = await scanFiles(files, { threshold: Number(options.threshold) });
215359
+ const maxFindings = parseMaxFindings2(options.maxFindings);
215360
+ const progress = createScanProgressRenderer(options.format === "terminal");
215361
+ const report = await (async () => {
215362
+ try {
215363
+ return await scanFiles(
215364
+ files,
215365
+ { threshold: Number(options.threshold) },
215366
+ { onFileProgress: progress.onProgress }
215367
+ );
215368
+ } finally {
215369
+ progress.stop();
215370
+ }
215371
+ })();
215248
215372
  if (options.format === "json") {
215249
215373
  console.log(JSON.stringify(report, null, 2));
215250
215374
  } else if (options.format === "jsonl") {
215251
215375
  console.log(formatJsonl(report));
215252
215376
  } else {
215253
- console.log(formatTerminalReport(report));
215377
+ console.log(formatTerminalReport(report, { maxFindings }));
215254
215378
  }
215255
215379
  await appendScanHistory({
215256
215380
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -215263,10 +215387,15 @@ async function scanCommand(dir, options) {
215263
215387
  printRunResult(report.summary.blocked);
215264
215388
  process.exitCode = report.summary.blocked ? 1 : 0;
215265
215389
  }
215390
+ function parseMaxFindings2(raw) {
215391
+ if (!raw || raw === "all") return Number.POSITIVE_INFINITY;
215392
+ const parsed2 = Number(raw);
215393
+ return Number.isFinite(parsed2) && parsed2 > 0 ? Math.floor(parsed2) : Number.POSITIVE_INFINITY;
215394
+ }
215266
215395
 
215267
215396
  // src/commands/uninstall.ts
215268
215397
  var import_promises6 = require("fs/promises");
215269
- var import_node_path6 = require("path");
215398
+ var import_node_path7 = require("path");
215270
215399
  async function uninstallCommand() {
215271
215400
  const root = await getGitRoot();
215272
215401
  const hooksDir = await getGitHooksDir();
@@ -215275,7 +215404,7 @@ async function uninstallCommand() {
215275
215404
  process.exitCode = 1;
215276
215405
  return;
215277
215406
  }
215278
- const hookPath = (0, import_node_path6.join)(hooksDir, "pre-commit");
215407
+ const hookPath = (0, import_node_path7.join)(hooksDir, "pre-commit");
215279
215408
  await (0, import_promises6.rm)(hookPath, { force: true });
215280
215409
  console.log(`Athena pre-commit hook removed from ${hookPath}`);
215281
215410
  }
@@ -215283,7 +215412,7 @@ async function uninstallCommand() {
215283
215412
  // package.json
215284
215413
  var package_default = {
215285
215414
  name: "@arsh342/athena",
215286
- version: "0.1.6",
215415
+ version: "0.1.7",
215287
215416
  description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
215288
215417
  type: "module",
215289
215418
  bin: {
@@ -215351,14 +215480,14 @@ async function menuCommand(program3) {
215351
215480
  desc: "Run full recursive JS/TS scan from cwd.",
215352
215481
  command: "athena scan .",
215353
215482
  detail: "Parse code units, score AI provenance, run targeted security checks, print report.",
215354
- run: () => scanCommand(".", { threshold: "9", format: "terminal", quietHeader: true })
215483
+ run: () => scanCommand(".", { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
215355
215484
  },
215356
215485
  {
215357
215486
  label: "Check staged files",
215358
215487
  desc: "Scan staged JS/TS files, same path used by pre-commit hook.",
215359
215488
  command: "athena check",
215360
215489
  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 })
215490
+ run: () => checkCommand([], { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
215362
215491
  },
215363
215492
  {
215364
215493
  label: "Install pre-commit hook",
@@ -215511,8 +215640,8 @@ async function waitForReturnToMenu() {
215511
215640
  // src/index.ts
215512
215641
  var program2 = new Command();
215513
215642
  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);
215643
+ 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);
215644
+ 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
215645
  program2.command("init").description("install Athena pre-commit hook").action(initCommand);
215517
215646
  program2.command("uninstall").description("remove Athena pre-commit hook").action(uninstallCommand);
215518
215647
  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.7",
4
4
  "description": "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
5
5
  "type": "module",
6
6
  "bin": {