@arsh342/athena 0.1.5 → 0.1.6

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 +102 -33
  2. package/package.json +3 -2
package/dist/index.cjs CHANGED
@@ -26,9 +26,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
 
29
- // ../node_modules/commander/lib/error.js
29
+ // node_modules/commander/lib/error.js
30
30
  var require_error = __commonJS({
31
- "../node_modules/commander/lib/error.js"(exports2) {
31
+ "node_modules/commander/lib/error.js"(exports2) {
32
32
  "use strict";
33
33
  var CommanderError2 = class extends Error {
34
34
  /**
@@ -62,9 +62,9 @@ var require_error = __commonJS({
62
62
  }
63
63
  });
64
64
 
65
- // ../node_modules/commander/lib/argument.js
65
+ // node_modules/commander/lib/argument.js
66
66
  var require_argument = __commonJS({
67
- "../node_modules/commander/lib/argument.js"(exports2) {
67
+ "node_modules/commander/lib/argument.js"(exports2) {
68
68
  "use strict";
69
69
  var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
70
70
  var Argument2 = class {
@@ -191,9 +191,9 @@ var require_argument = __commonJS({
191
191
  }
192
192
  });
193
193
 
194
- // ../node_modules/commander/lib/help.js
194
+ // node_modules/commander/lib/help.js
195
195
  var require_help = __commonJS({
196
- "../node_modules/commander/lib/help.js"(exports2) {
196
+ "node_modules/commander/lib/help.js"(exports2) {
197
197
  "use strict";
198
198
  var { humanReadableArgName } = require_argument();
199
199
  var Help2 = class {
@@ -794,9 +794,9 @@ ${itemIndentStr}`);
794
794
  }
795
795
  });
796
796
 
797
- // ../node_modules/commander/lib/option.js
797
+ // node_modules/commander/lib/option.js
798
798
  var require_option = __commonJS({
799
- "../node_modules/commander/lib/option.js"(exports2) {
799
+ "node_modules/commander/lib/option.js"(exports2) {
800
800
  "use strict";
801
801
  var { InvalidArgumentError: InvalidArgumentError2 } = require_error();
802
802
  var Option2 = class {
@@ -1108,9 +1108,9 @@ var require_option = __commonJS({
1108
1108
  }
1109
1109
  });
1110
1110
 
1111
- // ../node_modules/commander/lib/suggestSimilar.js
1111
+ // node_modules/commander/lib/suggestSimilar.js
1112
1112
  var require_suggestSimilar = __commonJS({
1113
- "../node_modules/commander/lib/suggestSimilar.js"(exports2) {
1113
+ "node_modules/commander/lib/suggestSimilar.js"(exports2) {
1114
1114
  "use strict";
1115
1115
  var maxDistance = 3;
1116
1116
  function editDistance(a, b) {
@@ -1189,9 +1189,9 @@ var require_suggestSimilar = __commonJS({
1189
1189
  }
1190
1190
  });
1191
1191
 
1192
- // ../node_modules/commander/lib/command.js
1192
+ // node_modules/commander/lib/command.js
1193
1193
  var require_command = __commonJS({
1194
- "../node_modules/commander/lib/command.js"(exports2) {
1194
+ "node_modules/commander/lib/command.js"(exports2) {
1195
1195
  "use strict";
1196
1196
  var EventEmitter = require("events").EventEmitter;
1197
1197
  var childProcess = require("child_process");
@@ -3436,9 +3436,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
3436
3436
  }
3437
3437
  });
3438
3438
 
3439
- // ../node_modules/commander/index.js
3439
+ // node_modules/commander/index.js
3440
3440
  var require_commander = __commonJS({
3441
- "../node_modules/commander/index.js"(exports2) {
3441
+ "node_modules/commander/index.js"(exports2) {
3442
3442
  "use strict";
3443
3443
  var { Argument: Argument2 } = require_argument();
3444
3444
  var { Command: Command2 } = require_command();
@@ -214201,7 +214201,7 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
214201
214201
  }
214202
214202
  });
214203
214203
 
214204
- // ../node_modules/commander/esm.mjs
214204
+ // node_modules/commander/esm.mjs
214205
214205
  var import_index = __toESM(require_commander(), 1);
214206
214206
  var {
214207
214207
  program,
@@ -214240,7 +214240,7 @@ var defaultConfig = {
214240
214240
  exclude: ["node_modules/", "dist/", "build/", ".git/", "coverage/"],
214241
214241
  secretDetection: true,
214242
214242
  hallucinationDetection: true,
214243
- maxFileSize: 102400,
214243
+ maxFileSize: 1048576,
214244
214244
  weights: defaultWeights
214245
214245
  };
214246
214246
  function mergeConfig(config = {}) {
@@ -214296,9 +214296,9 @@ var secretPatterns = [
214296
214296
  { ruleId: "secret.aws-access-key", label: "AWS access key", pattern: /AKIA[0-9A-Z]{16}/g },
214297
214297
  { ruleId: "secret.github-token", label: "GitHub token", pattern: /gh[ps]_[A-Za-z0-9_]{36,}/g },
214298
214298
  { ruleId: "secret.jwt", label: "JWT token", pattern: /eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g },
214299
- { ruleId: "secret.private-key", label: "Private key", pattern: /-----BEGIN [A-Z ]+PRIVATE KEY-----/g },
214300
- { ruleId: "secret.password", label: "Hardcoded password", pattern: /(password|api[_-]?key|token|secret)\s*[:=]\s*['"][^'"]{8,}['"]/gi }
214299
+ { ruleId: "secret.private-key", label: "Private key", pattern: /-----BEGIN [A-Z ]+PRIVATE KEY-----/g }
214301
214300
  ];
214301
+ var hardcodedCredentialPattern = /(password|api[_-]?key|token|secret)\s*[:=]\s*['"][^'"]{8,}['"]/gi;
214302
214302
  function detectSecrets(scored) {
214303
214303
  const findings = [];
214304
214304
  for (const definition of secretPatterns) {
@@ -214306,12 +214306,29 @@ function detectSecrets(scored) {
214306
214306
  findings.push(createFinding(scored, definition.ruleId, definition.label, match[0], "credential-exposure"));
214307
214307
  }
214308
214308
  }
214309
+ for (const match of scored.unit.code.matchAll(hardcodedCredentialPattern)) {
214310
+ const matchedKey = match[1]?.toLowerCase() ?? "";
214311
+ const { ruleId, type } = classifyHardcodedCredential(matchedKey);
214312
+ findings.push(createFinding(scored, ruleId, type, match[0], "credential-exposure"));
214313
+ }
214309
214314
  const highEntropyStrings = [...scored.unit.code.matchAll(/['"]([A-Za-z0-9+/=_-]{24,})['"]/g)].map((match) => match[1]).filter((value) => shannonEntropy(value) > 4.5 && !looksLikeFalsePositive(value));
214310
214315
  for (const value of highEntropyStrings) {
214311
214316
  findings.push(createFinding(scored, "secret.high-entropy-string", "Possible high-entropy secret", value, "credential-exposure"));
214312
214317
  }
214313
214318
  return findings;
214314
214319
  }
214320
+ function classifyHardcodedCredential(key) {
214321
+ if (key.includes("password")) {
214322
+ return { ruleId: "secret.hardcoded-password", type: "Hardcoded password" };
214323
+ }
214324
+ if (key.includes("api") && key.includes("key")) {
214325
+ return { ruleId: "secret.hardcoded-api-key", type: "Hardcoded API key" };
214326
+ }
214327
+ if (key.includes("token")) {
214328
+ return { ruleId: "secret.hardcoded-token", type: "Hardcoded token" };
214329
+ }
214330
+ return { ruleId: "secret.hardcoded-secret", type: "Hardcoded secret" };
214331
+ }
214315
214332
  function createFinding(scored, ruleId, type, code, category) {
214316
214333
  return {
214317
214334
  id: (0, import_node_crypto2.createHash)("sha1").update(`${ruleId}:${scored.unit.filePath}:${scored.unit.startLine}:${code}`).digest("hex").slice(0, 10),
@@ -214487,7 +214504,7 @@ function estimateComplexity(node) {
214487
214504
 
214488
214505
  // ../core/dist/report/report-generator.js
214489
214506
  var severityOrder = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
214490
- function generateReport(startedAt, files, totalLoc, config) {
214507
+ function generateReport(startedAt, files, totalLoc, skippedFiles, config) {
214491
214508
  const units = files.flatMap((file) => file.units);
214492
214509
  const findings = files.flatMap((file) => file.findings);
214493
214510
  const severityCounts = severityOrder.reduce((acc, severity) => ({ ...acc, [severity]: findings.filter((finding) => finding.severity === severity).length }), { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 });
@@ -214517,6 +214534,7 @@ function generateReport(startedAt, files, totalLoc, config) {
214517
214534
  duration: Date.now() - startedAt,
214518
214535
  summary: {
214519
214536
  filesScanned: files.length,
214537
+ skippedFiles,
214520
214538
  totalUnits: units.length,
214521
214539
  flaggedUnits,
214522
214540
  findings: severityCounts,
@@ -214802,10 +214820,15 @@ async function scanFiles(filePaths, configInput = {}) {
214802
214820
  const config = mergeConfig(configInput);
214803
214821
  const files = [];
214804
214822
  let totalLoc = 0;
214823
+ let skippedFiles = 0;
214805
214824
  for (const filePath of filePaths) {
214806
214825
  const fileStat = await (0, import_promises2.stat)(filePath).catch(() => null);
214807
- if (!fileStat || fileStat.size > config.maxFileSize)
214826
+ if (!fileStat)
214827
+ continue;
214828
+ if (fileStat.size > config.maxFileSize) {
214829
+ skippedFiles += 1;
214808
214830
  continue;
214831
+ }
214809
214832
  const units = await parseFile(filePath).catch(() => []);
214810
214833
  const scoredUnits = units.map((unit) => scoreUnit(unit, config));
214811
214834
  const findings = scoredUnits.flatMap((scored) => scored.flagged ? analyzeSecurity(scored, config) : []);
@@ -214816,7 +214839,7 @@ async function scanFiles(filePaths, configInput = {}) {
214816
214839
  findings
214817
214840
  });
214818
214841
  }
214819
- return generateReport(startedAt, files, totalLoc, config);
214842
+ return generateReport(startedAt, files, totalLoc, skippedFiles, config);
214820
214843
  }
214821
214844
 
214822
214845
  // ../core/dist/report/terminal-formatter.js
@@ -214975,11 +214998,25 @@ async function walk(dir, output) {
214975
214998
  var import_node_child_process = require("child_process");
214976
214999
  var import_node_util = require("util");
214977
215000
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
215001
+ function logGitWarning(context, error) {
215002
+ const message = error instanceof Error ? error.message : String(error);
215003
+ console.warn(`[athena-cli] ${context}: ${message}`);
215004
+ }
214978
215005
  async function getGitRoot() {
214979
215006
  try {
214980
215007
  const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"]);
214981
215008
  return stdout.trim();
214982
- } catch {
215009
+ } catch (error) {
215010
+ logGitWarning("Unable to resolve git root", error);
215011
+ return null;
215012
+ }
215013
+ }
215014
+ async function getGitHooksDir() {
215015
+ try {
215016
+ const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "hooks"]);
215017
+ return stdout.trim();
215018
+ } catch (error) {
215019
+ logGitWarning("Unable to resolve git hooks directory", error);
214983
215020
  return null;
214984
215021
  }
214985
215022
  }
@@ -214987,7 +215024,8 @@ async function getStagedFiles() {
214987
215024
  try {
214988
215025
  const { stdout } = await execFileAsync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACM"]);
214989
215026
  return stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
214990
- } catch {
215027
+ } catch (error) {
215028
+ logGitWarning("Unable to read staged files", error);
214991
215029
  return [];
214992
215030
  }
214993
215031
  }
@@ -214999,6 +215037,10 @@ var import_node_path2 = require("path");
214999
215037
  var ATHENA_DIR = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".athena");
215000
215038
  var HISTORY_PATH = (0, import_node_path2.join)(ATHENA_DIR, "scan-history.jsonl");
215001
215039
  var MAX_HISTORY_LINES = 300;
215040
+ function logHistoryWarning(context, error) {
215041
+ const message = error instanceof Error ? error.message : String(error);
215042
+ console.warn(`[athena-cli] ${context}: ${message}`);
215043
+ }
215002
215044
  async function appendScanHistory(entry) {
215003
215045
  try {
215004
215046
  await (0, import_promises4.mkdir)(ATHENA_DIR, { recursive: true });
@@ -215006,13 +215048,15 @@ async function appendScanHistory(entry) {
215006
215048
  try {
215007
215049
  const existing = await (0, import_promises4.readFile)(HISTORY_PATH, "utf8");
215008
215050
  lines = existing.split("\n").map((line) => line.trim()).filter(Boolean);
215009
- } catch {
215051
+ } catch (error) {
215052
+ logHistoryWarning("History file not readable, starting new history", error);
215010
215053
  }
215011
215054
  lines.push(JSON.stringify(entry));
215012
215055
  const trimmed = lines.slice(-MAX_HISTORY_LINES);
215013
215056
  await (0, import_promises4.writeFile)(HISTORY_PATH, `${trimmed.join("\n")}
215014
215057
  `, "utf8");
215015
- } catch {
215058
+ } catch (error) {
215059
+ logHistoryWarning("Failed to persist scan history", error);
215016
215060
  }
215017
215061
  }
215018
215062
  async function getRecentScanHistory(limit = 3) {
@@ -215022,11 +215066,13 @@ async function getRecentScanHistory(limit = 3) {
215022
215066
  return lines.map((line) => {
215023
215067
  try {
215024
215068
  return JSON.parse(line);
215025
- } catch {
215069
+ } catch (error) {
215070
+ logHistoryWarning("Skipping malformed history entry", error);
215026
215071
  return null;
215027
215072
  }
215028
215073
  }).filter((entry) => entry !== null).reverse();
215029
- } catch {
215074
+ } catch (error) {
215075
+ logHistoryWarning("Failed to read scan history", error);
215030
215076
  return [];
215031
215077
  }
215032
215078
  }
@@ -215166,12 +215212,13 @@ var import_promises5 = require("fs/promises");
215166
215212
  var import_node_path4 = require("path");
215167
215213
  async function initCommand() {
215168
215214
  const root = await getGitRoot();
215169
- if (!root) {
215215
+ const hooksDir = await getGitHooksDir();
215216
+ if (!root || !hooksDir) {
215170
215217
  console.error("Athena needs a git repository for pre-commit hook install.");
215171
215218
  process.exitCode = 1;
215172
215219
  return;
215173
215220
  }
215174
- const hookPath = (0, import_node_path4.join)(root, ".git", "hooks", "pre-commit");
215221
+ const hookPath = (0, import_node_path4.join)(hooksDir, "pre-commit");
215175
215222
  const hook = [
215176
215223
  "#!/bin/sh",
215177
215224
  'echo "athena: checking staged JS/TS files"',
@@ -215222,12 +215269,13 @@ var import_promises6 = require("fs/promises");
215222
215269
  var import_node_path6 = require("path");
215223
215270
  async function uninstallCommand() {
215224
215271
  const root = await getGitRoot();
215225
- if (!root) {
215272
+ const hooksDir = await getGitHooksDir();
215273
+ if (!root || !hooksDir) {
215226
215274
  console.error("Athena needs a git repository for hook uninstall.");
215227
215275
  process.exitCode = 1;
215228
215276
  return;
215229
215277
  }
215230
- const hookPath = (0, import_node_path6.join)(root, ".git", "hooks", "pre-commit");
215278
+ const hookPath = (0, import_node_path6.join)(hooksDir, "pre-commit");
215231
215279
  await (0, import_promises6.rm)(hookPath, { force: true });
215232
215280
  console.log(`Athena pre-commit hook removed from ${hookPath}`);
215233
215281
  }
@@ -215235,7 +215283,7 @@ async function uninstallCommand() {
215235
215283
  // package.json
215236
215284
  var package_default = {
215237
215285
  name: "@arsh342/athena",
215238
- version: "0.1.5",
215286
+ version: "0.1.6",
215239
215287
  description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
215240
215288
  type: "module",
215241
215289
  bin: {
@@ -215246,7 +215294,8 @@ var package_default = {
215246
215294
  build: "tsup",
215247
215295
  dev: "tsx src/index.ts",
215248
215296
  prepack: "npm run build",
215249
- "pack:dry": "npm pack --dry-run"
215297
+ "pack:dry": "npm pack --dry-run",
215298
+ test: "node --import tsx --test test/**/*.test.ts"
215250
215299
  },
215251
215300
  files: [
215252
215301
  "dist",
@@ -215349,6 +215398,7 @@ async function menuCommand(program3) {
215349
215398
  }
215350
215399
  clear();
215351
215400
  await items[choice].run();
215401
+ await waitForReturnToMenu();
215352
215402
  }
215353
215403
  } finally {
215354
215404
  exitAltScreen();
@@ -215438,6 +215488,25 @@ function exitAltScreen() {
215438
215488
  function pad(n) {
215439
215489
  return " ".repeat(Math.max(1, n));
215440
215490
  }
215491
+ async function waitForReturnToMenu() {
215492
+ if (!process.stdin.isTTY || !process.stdout.isTTY) return;
215493
+ console.log(` ${c2.dim}press any key to return to selector${c2.reset}`);
215494
+ (0, import_node_readline.emitKeypressEvents)(process.stdin);
215495
+ process.stdin.setRawMode(true);
215496
+ process.stdin.resume();
215497
+ await new Promise((resolve3) => {
215498
+ const cleanup = () => {
215499
+ process.stdin.setRawMode(false);
215500
+ process.stdin.pause();
215501
+ process.stdin.off("keypress", onKeypress);
215502
+ };
215503
+ const onKeypress = () => {
215504
+ cleanup();
215505
+ resolve3();
215506
+ };
215507
+ process.stdin.on("keypress", onKeypress);
215508
+ });
215509
+ }
215441
215510
 
215442
215511
  // src/index.ts
215443
215512
  var program2 = new Command();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arsh342/athena",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,8 @@
11
11
  "build": "tsup",
12
12
  "dev": "tsx src/index.ts",
13
13
  "prepack": "npm run build",
14
- "pack:dry": "npm pack --dry-run"
14
+ "pack:dry": "npm pack --dry-run",
15
+ "test": "node --import tsx --test test/**/*.test.ts"
15
16
  },
16
17
  "files": [
17
18
  "dist",