@arsh342/athena 0.1.5 → 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.
- package/dist/index.cjs +261 -63
- 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
|
-
//
|
|
29
|
+
// node_modules/commander/lib/error.js
|
|
30
30
|
var require_error = __commonJS({
|
|
31
|
-
"
|
|
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
|
-
//
|
|
65
|
+
// node_modules/commander/lib/argument.js
|
|
66
66
|
var require_argument = __commonJS({
|
|
67
|
-
"
|
|
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
|
-
//
|
|
194
|
+
// node_modules/commander/lib/help.js
|
|
195
195
|
var require_help = __commonJS({
|
|
196
|
-
"
|
|
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
|
-
//
|
|
797
|
+
// node_modules/commander/lib/option.js
|
|
798
798
|
var require_option = __commonJS({
|
|
799
|
-
"
|
|
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
|
-
//
|
|
1111
|
+
// node_modules/commander/lib/suggestSimilar.js
|
|
1112
1112
|
var require_suggestSimilar = __commonJS({
|
|
1113
|
-
"
|
|
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
|
-
//
|
|
1192
|
+
// node_modules/commander/lib/command.js
|
|
1193
1193
|
var require_command = __commonJS({
|
|
1194
|
-
"
|
|
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
|
-
//
|
|
3439
|
+
// node_modules/commander/index.js
|
|
3440
3440
|
var require_commander = __commonJS({
|
|
3441
|
-
"
|
|
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();
|
|
@@ -140010,9 +140010,9 @@ ${lanes.join("\n")}
|
|
|
140010
140010
|
/*ignoreCase*/
|
|
140011
140011
|
false
|
|
140012
140012
|
)) {
|
|
140013
|
-
const
|
|
140014
|
-
if (
|
|
140015
|
-
const name = removeSuffix(removePrefix(
|
|
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
|
|
203762
|
-
if (
|
|
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
|
|
207435
|
-
if (((_a = result.affectedModuleSpecifierCacheProjects) == null ? void 0 : _a.size) && (
|
|
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();
|
|
@@ -214201,7 +214201,7 @@ Additional information: BADCLIENT: Bad error code, ${badCode} not found in range
|
|
|
214201
214201
|
}
|
|
214202
214202
|
});
|
|
214203
214203
|
|
|
214204
|
-
//
|
|
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:
|
|
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,
|
|
@@ -214797,15 +214815,47 @@ function explain(score, signals) {
|
|
|
214797
214815
|
}
|
|
214798
214816
|
|
|
214799
214817
|
// ../core/dist/engine.js
|
|
214800
|
-
async function scanFiles(filePaths, configInput = {}) {
|
|
214818
|
+
async function scanFiles(filePaths, configInput = {}, hooks = {}) {
|
|
214801
214819
|
const startedAt = Date.now();
|
|
214802
214820
|
const config = mergeConfig(configInput);
|
|
214803
214821
|
const files = [];
|
|
214804
214822
|
let totalLoc = 0;
|
|
214805
|
-
|
|
214823
|
+
let skippedFiles = 0;
|
|
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
|
+
});
|
|
214806
214835
|
const fileStat = await (0, import_promises2.stat)(filePath).catch(() => null);
|
|
214807
|
-
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
|
+
});
|
|
214808
214845
|
continue;
|
|
214846
|
+
}
|
|
214847
|
+
if (fileStat.size > config.maxFileSize) {
|
|
214848
|
+
skippedFiles += 1;
|
|
214849
|
+
processedFiles += 1;
|
|
214850
|
+
hooks.onFileProgress?.({
|
|
214851
|
+
filePath,
|
|
214852
|
+
index: processedFiles,
|
|
214853
|
+
total: totalFiles,
|
|
214854
|
+
status: "skipped",
|
|
214855
|
+
findings: 0
|
|
214856
|
+
});
|
|
214857
|
+
continue;
|
|
214858
|
+
}
|
|
214809
214859
|
const units = await parseFile(filePath).catch(() => []);
|
|
214810
214860
|
const scoredUnits = units.map((unit) => scoreUnit(unit, config));
|
|
214811
214861
|
const findings = scoredUnits.flatMap((scored) => scored.flagged ? analyzeSecurity(scored, config) : []);
|
|
@@ -214815,8 +214865,16 @@ async function scanFiles(filePaths, configInput = {}) {
|
|
|
214815
214865
|
units: scoredUnits,
|
|
214816
214866
|
findings
|
|
214817
214867
|
});
|
|
214868
|
+
processedFiles += 1;
|
|
214869
|
+
hooks.onFileProgress?.({
|
|
214870
|
+
filePath,
|
|
214871
|
+
index: processedFiles,
|
|
214872
|
+
total: totalFiles,
|
|
214873
|
+
status: "scanned",
|
|
214874
|
+
findings: findings.length
|
|
214875
|
+
});
|
|
214818
214876
|
}
|
|
214819
|
-
return generateReport(startedAt, files, totalLoc, config);
|
|
214877
|
+
return generateReport(startedAt, files, totalLoc, skippedFiles, config);
|
|
214820
214878
|
}
|
|
214821
214879
|
|
|
214822
214880
|
// ../core/dist/report/terminal-formatter.js
|
|
@@ -214837,9 +214895,11 @@ var severityColor = {
|
|
|
214837
214895
|
MEDIUM: c.yellow,
|
|
214838
214896
|
LOW: c.gray
|
|
214839
214897
|
};
|
|
214840
|
-
function formatTerminalReport(report) {
|
|
214898
|
+
function formatTerminalReport(report, options = {}) {
|
|
214841
214899
|
const lines = [];
|
|
214842
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);
|
|
214843
214903
|
const securityFindingsTotal = Object.values(summary.findings).reduce((sum, count) => sum + count, 0);
|
|
214844
214904
|
const thresholdUsed = summary.calibration?.thresholdUsed;
|
|
214845
214905
|
const aiScoreRelation = typeof thresholdUsed === "number" ? summary.aiScore === thresholdUsed ? "at threshold" : summary.aiScore < thresholdUsed ? "below threshold" : "above threshold" : "threshold unavailable";
|
|
@@ -214904,19 +214964,28 @@ function formatTerminalReport(report) {
|
|
|
214904
214964
|
}
|
|
214905
214965
|
lines.push(sectionRule("Findings"));
|
|
214906
214966
|
lines.push("");
|
|
214907
|
-
|
|
214967
|
+
const shownFindings = findings.slice(0, maxFindings);
|
|
214968
|
+
for (const finding of shownFindings) {
|
|
214908
214969
|
const sevColor = severityColor[finding.severity];
|
|
214909
|
-
lines.push(` ${sevColor}${finding.severity
|
|
214910
|
-
lines.push(` ${c.orange}${finding.file}:${finding.line}${c.reset} ${c.dim}
|
|
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}`);
|
|
214911
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
|
+
}
|
|
214912
214980
|
if (finding.explainedScore.topSignals.length > 0) {
|
|
214913
214981
|
const signals = finding.explainedScore.topSignals.map((s) => `${s.signal}:${c.orange}${s.contribution}%${c.reset}`).join(" ");
|
|
214914
214982
|
lines.push(` ${c.dim}signals:${c.reset} ${signals}`);
|
|
214915
214983
|
}
|
|
214916
214984
|
lines.push("");
|
|
214917
214985
|
}
|
|
214918
|
-
if (findings.length >
|
|
214919
|
-
lines.push(` ${c.dim}\u2026 ${findings.length -
|
|
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}`);
|
|
214920
214989
|
lines.push("");
|
|
214921
214990
|
}
|
|
214922
214991
|
return lines.join("\n");
|
|
@@ -214939,9 +215008,12 @@ function severityBar(report) {
|
|
|
214939
215008
|
return `${severityColor[severity]}${"\u2588".repeat(width)}${c.reset} ${severity}:${count}`;
|
|
214940
215009
|
}).join(" ");
|
|
214941
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
|
+
}
|
|
214942
215014
|
|
|
214943
215015
|
// src/commands/check.ts
|
|
214944
|
-
var
|
|
215016
|
+
var import_node_path4 = require("path");
|
|
214945
215017
|
|
|
214946
215018
|
// src/utils/file-filter.ts
|
|
214947
215019
|
var import_promises3 = require("fs/promises");
|
|
@@ -214975,11 +215047,25 @@ async function walk(dir, output) {
|
|
|
214975
215047
|
var import_node_child_process = require("child_process");
|
|
214976
215048
|
var import_node_util = require("util");
|
|
214977
215049
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
215050
|
+
function logGitWarning(context, error) {
|
|
215051
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
215052
|
+
console.warn(`[athena-cli] ${context}: ${message}`);
|
|
215053
|
+
}
|
|
214978
215054
|
async function getGitRoot() {
|
|
214979
215055
|
try {
|
|
214980
215056
|
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"]);
|
|
214981
215057
|
return stdout.trim();
|
|
214982
|
-
} catch {
|
|
215058
|
+
} catch (error) {
|
|
215059
|
+
logGitWarning("Unable to resolve git root", error);
|
|
215060
|
+
return null;
|
|
215061
|
+
}
|
|
215062
|
+
}
|
|
215063
|
+
async function getGitHooksDir() {
|
|
215064
|
+
try {
|
|
215065
|
+
const { stdout } = await execFileAsync("git", ["rev-parse", "--git-path", "hooks"]);
|
|
215066
|
+
return stdout.trim();
|
|
215067
|
+
} catch (error) {
|
|
215068
|
+
logGitWarning("Unable to resolve git hooks directory", error);
|
|
214983
215069
|
return null;
|
|
214984
215070
|
}
|
|
214985
215071
|
}
|
|
@@ -214987,7 +215073,8 @@ async function getStagedFiles() {
|
|
|
214987
215073
|
try {
|
|
214988
215074
|
const { stdout } = await execFileAsync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACM"]);
|
|
214989
215075
|
return stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
214990
|
-
} catch {
|
|
215076
|
+
} catch (error) {
|
|
215077
|
+
logGitWarning("Unable to read staged files", error);
|
|
214991
215078
|
return [];
|
|
214992
215079
|
}
|
|
214993
215080
|
}
|
|
@@ -214999,6 +215086,10 @@ var import_node_path2 = require("path");
|
|
|
214999
215086
|
var ATHENA_DIR = (0, import_node_path2.join)((0, import_node_os.homedir)(), ".athena");
|
|
215000
215087
|
var HISTORY_PATH = (0, import_node_path2.join)(ATHENA_DIR, "scan-history.jsonl");
|
|
215001
215088
|
var MAX_HISTORY_LINES = 300;
|
|
215089
|
+
function logHistoryWarning(context, error) {
|
|
215090
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
215091
|
+
console.warn(`[athena-cli] ${context}: ${message}`);
|
|
215092
|
+
}
|
|
215002
215093
|
async function appendScanHistory(entry) {
|
|
215003
215094
|
try {
|
|
215004
215095
|
await (0, import_promises4.mkdir)(ATHENA_DIR, { recursive: true });
|
|
@@ -215006,13 +215097,15 @@ async function appendScanHistory(entry) {
|
|
|
215006
215097
|
try {
|
|
215007
215098
|
const existing = await (0, import_promises4.readFile)(HISTORY_PATH, "utf8");
|
|
215008
215099
|
lines = existing.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
215009
|
-
} catch {
|
|
215100
|
+
} catch (error) {
|
|
215101
|
+
logHistoryWarning("History file not readable, starting new history", error);
|
|
215010
215102
|
}
|
|
215011
215103
|
lines.push(JSON.stringify(entry));
|
|
215012
215104
|
const trimmed = lines.slice(-MAX_HISTORY_LINES);
|
|
215013
215105
|
await (0, import_promises4.writeFile)(HISTORY_PATH, `${trimmed.join("\n")}
|
|
215014
215106
|
`, "utf8");
|
|
215015
|
-
} catch {
|
|
215107
|
+
} catch (error) {
|
|
215108
|
+
logHistoryWarning("Failed to persist scan history", error);
|
|
215016
215109
|
}
|
|
215017
215110
|
}
|
|
215018
215111
|
async function getRecentScanHistory(limit = 3) {
|
|
@@ -215022,11 +215115,13 @@ async function getRecentScanHistory(limit = 3) {
|
|
|
215022
215115
|
return lines.map((line) => {
|
|
215023
215116
|
try {
|
|
215024
215117
|
return JSON.parse(line);
|
|
215025
|
-
} catch {
|
|
215118
|
+
} catch (error) {
|
|
215119
|
+
logHistoryWarning("Skipping malformed history entry", error);
|
|
215026
215120
|
return null;
|
|
215027
215121
|
}
|
|
215028
215122
|
}).filter((entry) => entry !== null).reverse();
|
|
215029
|
-
} catch {
|
|
215123
|
+
} catch (error) {
|
|
215124
|
+
logHistoryWarning("Failed to read scan history", error);
|
|
215030
215125
|
return [];
|
|
215031
215126
|
}
|
|
215032
215127
|
}
|
|
@@ -215047,6 +215142,9 @@ function formatRecentHistory(entries) {
|
|
|
215047
215142
|
return `history: ${parts.join(" | ")}`;
|
|
215048
215143
|
}
|
|
215049
215144
|
|
|
215145
|
+
// src/utils/scan-progress.ts
|
|
215146
|
+
var import_node_path3 = require("path");
|
|
215147
|
+
|
|
215050
215148
|
// src/utils/colors.ts
|
|
215051
215149
|
var c2 = {
|
|
215052
215150
|
reset: "\x1B[0m",
|
|
@@ -215106,6 +215204,49 @@ function truncate(value, max) {
|
|
|
215106
215204
|
return `\u2026${value.slice(value.length - max + 1)}`;
|
|
215107
215205
|
}
|
|
215108
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
|
+
|
|
215109
215250
|
// src/utils/terminal.ts
|
|
215110
215251
|
function clearScreen() {
|
|
215111
215252
|
process.stdout.write("\x1B[3J\x1B[2J\x1B[H");
|
|
@@ -215133,7 +215274,7 @@ function printRunResult(blocked) {
|
|
|
215133
215274
|
// src/commands/check.ts
|
|
215134
215275
|
async function checkCommand(files, options) {
|
|
215135
215276
|
const selected = files.length > 0 ? files : await getStagedFiles();
|
|
215136
|
-
const sourceFiles = selected.filter(isSourceFile).map((file) => (0,
|
|
215277
|
+
const sourceFiles = selected.filter(isSourceFile).map((file) => (0, import_node_path4.resolve)(process.cwd(), file));
|
|
215137
215278
|
if (!options.quietHeader) {
|
|
215138
215279
|
if (process.stdout.isTTY) {
|
|
215139
215280
|
clearScreen();
|
|
@@ -215141,13 +215282,25 @@ async function checkCommand(files, options) {
|
|
|
215141
215282
|
printRunHeader("check", `${sourceFiles.length} staged/source files`);
|
|
215142
215283
|
}
|
|
215143
215284
|
const expanded = sourceFiles.length === 1 ? await findSourceFiles(sourceFiles[0]) : sourceFiles;
|
|
215144
|
-
const
|
|
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
|
+
})();
|
|
215145
215298
|
if (options.format === "json") {
|
|
215146
215299
|
console.log(JSON.stringify(report, null, 2));
|
|
215147
215300
|
} else if (options.format === "jsonl") {
|
|
215148
215301
|
console.log(formatJsonl(report));
|
|
215149
215302
|
} else {
|
|
215150
|
-
console.log(formatTerminalReport(report));
|
|
215303
|
+
console.log(formatTerminalReport(report, { maxFindings }));
|
|
215151
215304
|
}
|
|
215152
215305
|
await appendScanHistory({
|
|
215153
215306
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -215160,24 +215313,30 @@ async function checkCommand(files, options) {
|
|
|
215160
215313
|
printRunResult(report.summary.blocked);
|
|
215161
215314
|
process.exitCode = report.summary.blocked ? 1 : 0;
|
|
215162
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
|
+
}
|
|
215163
215321
|
|
|
215164
215322
|
// src/commands/init.ts
|
|
215165
215323
|
var import_promises5 = require("fs/promises");
|
|
215166
|
-
var
|
|
215324
|
+
var import_node_path5 = require("path");
|
|
215167
215325
|
async function initCommand() {
|
|
215168
215326
|
const root = await getGitRoot();
|
|
215169
|
-
|
|
215327
|
+
const hooksDir = await getGitHooksDir();
|
|
215328
|
+
if (!root || !hooksDir) {
|
|
215170
215329
|
console.error("Athena needs a git repository for pre-commit hook install.");
|
|
215171
215330
|
process.exitCode = 1;
|
|
215172
215331
|
return;
|
|
215173
215332
|
}
|
|
215174
|
-
const hookPath = (0,
|
|
215333
|
+
const hookPath = (0, import_node_path5.join)(hooksDir, "pre-commit");
|
|
215175
215334
|
const hook = [
|
|
215176
215335
|
"#!/bin/sh",
|
|
215177
215336
|
'echo "athena: checking staged JS/TS files"',
|
|
215178
215337
|
"npx athena check"
|
|
215179
215338
|
].join("\n");
|
|
215180
|
-
await (0, import_promises5.mkdir)((0,
|
|
215339
|
+
await (0, import_promises5.mkdir)((0, import_node_path5.dirname)(hookPath), { recursive: true });
|
|
215181
215340
|
await (0, import_promises5.writeFile)(hookPath, `${hook}
|
|
215182
215341
|
`, { mode: 493 });
|
|
215183
215342
|
console.log(`Athena pre-commit hook installed at ${hookPath}`);
|
|
@@ -215187,9 +215346,9 @@ async function initCommand() {
|
|
|
215187
215346
|
var import_node_readline = require("readline");
|
|
215188
215347
|
|
|
215189
215348
|
// src/commands/scan.ts
|
|
215190
|
-
var
|
|
215349
|
+
var import_node_path6 = require("path");
|
|
215191
215350
|
async function scanCommand(dir, options) {
|
|
215192
|
-
const root = (0,
|
|
215351
|
+
const root = (0, import_node_path6.resolve)(process.cwd(), dir);
|
|
215193
215352
|
if (!options.quietHeader) {
|
|
215194
215353
|
if (process.stdout.isTTY) {
|
|
215195
215354
|
clearScreen();
|
|
@@ -215197,13 +215356,25 @@ async function scanCommand(dir, options) {
|
|
|
215197
215356
|
printRunHeader("scan", root);
|
|
215198
215357
|
}
|
|
215199
215358
|
const files = await findSourceFiles(root);
|
|
215200
|
-
const
|
|
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
|
+
})();
|
|
215201
215372
|
if (options.format === "json") {
|
|
215202
215373
|
console.log(JSON.stringify(report, null, 2));
|
|
215203
215374
|
} else if (options.format === "jsonl") {
|
|
215204
215375
|
console.log(formatJsonl(report));
|
|
215205
215376
|
} else {
|
|
215206
|
-
console.log(formatTerminalReport(report));
|
|
215377
|
+
console.log(formatTerminalReport(report, { maxFindings }));
|
|
215207
215378
|
}
|
|
215208
215379
|
await appendScanHistory({
|
|
215209
215380
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -215216,18 +215387,24 @@ async function scanCommand(dir, options) {
|
|
|
215216
215387
|
printRunResult(report.summary.blocked);
|
|
215217
215388
|
process.exitCode = report.summary.blocked ? 1 : 0;
|
|
215218
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
|
+
}
|
|
215219
215395
|
|
|
215220
215396
|
// src/commands/uninstall.ts
|
|
215221
215397
|
var import_promises6 = require("fs/promises");
|
|
215222
|
-
var
|
|
215398
|
+
var import_node_path7 = require("path");
|
|
215223
215399
|
async function uninstallCommand() {
|
|
215224
215400
|
const root = await getGitRoot();
|
|
215225
|
-
|
|
215401
|
+
const hooksDir = await getGitHooksDir();
|
|
215402
|
+
if (!root || !hooksDir) {
|
|
215226
215403
|
console.error("Athena needs a git repository for hook uninstall.");
|
|
215227
215404
|
process.exitCode = 1;
|
|
215228
215405
|
return;
|
|
215229
215406
|
}
|
|
215230
|
-
const hookPath = (0,
|
|
215407
|
+
const hookPath = (0, import_node_path7.join)(hooksDir, "pre-commit");
|
|
215231
215408
|
await (0, import_promises6.rm)(hookPath, { force: true });
|
|
215232
215409
|
console.log(`Athena pre-commit hook removed from ${hookPath}`);
|
|
215233
215410
|
}
|
|
@@ -215235,7 +215412,7 @@ async function uninstallCommand() {
|
|
|
215235
215412
|
// package.json
|
|
215236
215413
|
var package_default = {
|
|
215237
215414
|
name: "@arsh342/athena",
|
|
215238
|
-
version: "0.1.
|
|
215415
|
+
version: "0.1.7",
|
|
215239
215416
|
description: "AI code provenance tracker and terminal scanner for JavaScript and TypeScript repositories.",
|
|
215240
215417
|
type: "module",
|
|
215241
215418
|
bin: {
|
|
@@ -215246,7 +215423,8 @@ var package_default = {
|
|
|
215246
215423
|
build: "tsup",
|
|
215247
215424
|
dev: "tsx src/index.ts",
|
|
215248
215425
|
prepack: "npm run build",
|
|
215249
|
-
"pack:dry": "npm pack --dry-run"
|
|
215426
|
+
"pack:dry": "npm pack --dry-run",
|
|
215427
|
+
test: "node --import tsx --test test/**/*.test.ts"
|
|
215250
215428
|
},
|
|
215251
215429
|
files: [
|
|
215252
215430
|
"dist",
|
|
@@ -215302,14 +215480,14 @@ async function menuCommand(program3) {
|
|
|
215302
215480
|
desc: "Run full recursive JS/TS scan from cwd.",
|
|
215303
215481
|
command: "athena scan .",
|
|
215304
215482
|
detail: "Parse code units, score AI provenance, run targeted security checks, print report.",
|
|
215305
|
-
run: () => scanCommand(".", { threshold: "9", format: "terminal", quietHeader: true })
|
|
215483
|
+
run: () => scanCommand(".", { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
|
|
215306
215484
|
},
|
|
215307
215485
|
{
|
|
215308
215486
|
label: "Check staged files",
|
|
215309
215487
|
desc: "Scan staged JS/TS files, same path used by pre-commit hook.",
|
|
215310
215488
|
command: "athena check",
|
|
215311
215489
|
detail: "Fast gate for commit flow. Reads git staged files and exits 1 on blocking risk.",
|
|
215312
|
-
run: () => checkCommand([], { threshold: "9", format: "terminal", quietHeader: true })
|
|
215490
|
+
run: () => checkCommand([], { threshold: "9", format: "terminal", maxFindings: "all", quietHeader: true })
|
|
215313
215491
|
},
|
|
215314
215492
|
{
|
|
215315
215493
|
label: "Install pre-commit hook",
|
|
@@ -215349,6 +215527,7 @@ async function menuCommand(program3) {
|
|
|
215349
215527
|
}
|
|
215350
215528
|
clear();
|
|
215351
215529
|
await items[choice].run();
|
|
215530
|
+
await waitForReturnToMenu();
|
|
215352
215531
|
}
|
|
215353
215532
|
} finally {
|
|
215354
215533
|
exitAltScreen();
|
|
@@ -215438,12 +215617,31 @@ function exitAltScreen() {
|
|
|
215438
215617
|
function pad(n) {
|
|
215439
215618
|
return " ".repeat(Math.max(1, n));
|
|
215440
215619
|
}
|
|
215620
|
+
async function waitForReturnToMenu() {
|
|
215621
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return;
|
|
215622
|
+
console.log(` ${c2.dim}press any key to return to selector${c2.reset}`);
|
|
215623
|
+
(0, import_node_readline.emitKeypressEvents)(process.stdin);
|
|
215624
|
+
process.stdin.setRawMode(true);
|
|
215625
|
+
process.stdin.resume();
|
|
215626
|
+
await new Promise((resolve3) => {
|
|
215627
|
+
const cleanup = () => {
|
|
215628
|
+
process.stdin.setRawMode(false);
|
|
215629
|
+
process.stdin.pause();
|
|
215630
|
+
process.stdin.off("keypress", onKeypress);
|
|
215631
|
+
};
|
|
215632
|
+
const onKeypress = () => {
|
|
215633
|
+
cleanup();
|
|
215634
|
+
resolve3();
|
|
215635
|
+
};
|
|
215636
|
+
process.stdin.on("keypress", onKeypress);
|
|
215637
|
+
});
|
|
215638
|
+
}
|
|
215441
215639
|
|
|
215442
215640
|
// src/index.ts
|
|
215443
215641
|
var program2 = new Command();
|
|
215444
215642
|
program2.name("athena").description("AI code provenance tracker for JavaScript and TypeScript repositories").version(CLI_VERSION);
|
|
215445
|
-
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);
|
|
215446
|
-
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);
|
|
215447
215645
|
program2.command("init").description("install Athena pre-commit hook").action(initCommand);
|
|
215448
215646
|
program2.command("uninstall").description("remove Athena pre-commit hook").action(uninstallCommand);
|
|
215449
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.
|
|
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": {
|
|
@@ -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",
|