@agenticcli/shipguard 0.1.0 → 0.1.2
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/chunk-7HMLDAMC.js +115 -0
- package/dist/{chunk-42MA7DQY.js → chunk-IK7VIKXY.js} +53 -0
- package/dist/cli.js +685 -218
- package/dist/{config-generator-EQNRHODF.js → config-generator-YSWNA53I.js} +14 -0
- package/dist/{pro-scanner-YZDS67FB.js → pro-scanner-ZBGRHNFD.js} +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,13 @@ import {
|
|
|
11
11
|
runProRulesWithDispatch,
|
|
12
12
|
saveCredentials,
|
|
13
13
|
secretsCheck
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-IK7VIKXY.js";
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_MAX_FILES,
|
|
17
|
+
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
18
|
+
DEFAULT_MAX_TOTAL_BYTES,
|
|
19
|
+
readFiles
|
|
20
|
+
} from "./chunk-7HMLDAMC.js";
|
|
15
21
|
|
|
16
22
|
// src/cli.ts
|
|
17
23
|
import { Command as Command7 } from "commander";
|
|
@@ -83,12 +89,19 @@ var DEFAULT_POLICY = {
|
|
|
83
89
|
"dist/**",
|
|
84
90
|
"build/**",
|
|
85
91
|
".next/**",
|
|
86
|
-
"coverage/**"
|
|
92
|
+
"coverage/**",
|
|
93
|
+
// ShipGuard's own report output — never scan the tool's own artifacts
|
|
94
|
+
".shipguard/**"
|
|
87
95
|
]
|
|
88
96
|
},
|
|
89
97
|
report: {
|
|
90
98
|
output: ".shipguard/reports/latest.md",
|
|
91
99
|
format: "markdown"
|
|
100
|
+
},
|
|
101
|
+
limits: {
|
|
102
|
+
maxFileSizeBytes: DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
103
|
+
maxTotalBytes: DEFAULT_MAX_TOTAL_BYTES,
|
|
104
|
+
maxFiles: DEFAULT_MAX_FILES
|
|
92
105
|
}
|
|
93
106
|
};
|
|
94
107
|
async function loadPolicy(dir) {
|
|
@@ -99,7 +112,11 @@ async function loadPolicy(dir) {
|
|
|
99
112
|
try {
|
|
100
113
|
const content = await readFile(policyPath, "utf-8");
|
|
101
114
|
const parsed = YAML.parse(content);
|
|
102
|
-
return {
|
|
115
|
+
return {
|
|
116
|
+
...DEFAULT_POLICY,
|
|
117
|
+
...parsed,
|
|
118
|
+
limits: { ...DEFAULT_POLICY.limits, ...parsed.limits ?? {} }
|
|
119
|
+
};
|
|
103
120
|
} catch (error) {
|
|
104
121
|
throw new Error(`Invalid policy file: ${error instanceof Error ? error.message : error}`);
|
|
105
122
|
}
|
|
@@ -172,10 +189,12 @@ function initCommand() {
|
|
|
172
189
|
// src/commands/scan.ts
|
|
173
190
|
import { Command as Command2 } from "commander";
|
|
174
191
|
import { randomUUID } from "crypto";
|
|
192
|
+
import { existsSync as existsSync3 } from "fs";
|
|
193
|
+
import { join as join4, resolve as resolve3 } from "path";
|
|
175
194
|
|
|
176
195
|
// src/core/scanner.ts
|
|
177
|
-
import { readFile as
|
|
178
|
-
import { join as
|
|
196
|
+
import { readFile as readFile2, stat } from "fs/promises";
|
|
197
|
+
import { join as join2 } from "path";
|
|
179
198
|
|
|
180
199
|
// src/core/risk-score.ts
|
|
181
200
|
function computeRiskScore(findings) {
|
|
@@ -267,46 +286,6 @@ function getChangedFiles(dir) {
|
|
|
267
286
|
}
|
|
268
287
|
}
|
|
269
288
|
|
|
270
|
-
// src/utils/fs.ts
|
|
271
|
-
import fg from "fast-glob";
|
|
272
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
273
|
-
import { join as join2 } from "path";
|
|
274
|
-
async function readFiles(rootDir, patterns = ["**/*"], ignorePatterns = []) {
|
|
275
|
-
const defaultIgnore = [
|
|
276
|
-
"node_modules/**",
|
|
277
|
-
"dist/**",
|
|
278
|
-
"build/**",
|
|
279
|
-
".next/**",
|
|
280
|
-
"coverage/**",
|
|
281
|
-
".git/**",
|
|
282
|
-
"*.lock",
|
|
283
|
-
"pnpm-lock.yaml",
|
|
284
|
-
"package-lock.json"
|
|
285
|
-
];
|
|
286
|
-
const allIgnore = [...defaultIgnore, ...ignorePatterns];
|
|
287
|
-
const filePaths = await fg(patterns, {
|
|
288
|
-
cwd: rootDir,
|
|
289
|
-
ignore: allIgnore,
|
|
290
|
-
dot: true,
|
|
291
|
-
absolute: false,
|
|
292
|
-
onlyFiles: true
|
|
293
|
-
});
|
|
294
|
-
const files = [];
|
|
295
|
-
for (const fp of filePaths) {
|
|
296
|
-
try {
|
|
297
|
-
const fullPath = join2(rootDir, fp);
|
|
298
|
-
const content = await readFile2(fullPath, "utf-8");
|
|
299
|
-
files.push({
|
|
300
|
-
path: fullPath,
|
|
301
|
-
content,
|
|
302
|
-
relativePath: fp
|
|
303
|
-
});
|
|
304
|
-
} catch {
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return files;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
289
|
// src/core/scanner.ts
|
|
311
290
|
var CHECK_MODULES = [secretsCheck, authCheck, databaseCheck, payments, deploymentCheck];
|
|
312
291
|
var DEFAULT_IGNORE = [
|
|
@@ -315,13 +294,23 @@ var DEFAULT_IGNORE = [
|
|
|
315
294
|
"build/**",
|
|
316
295
|
".next/**",
|
|
317
296
|
"coverage/**",
|
|
318
|
-
".git/**"
|
|
297
|
+
".git/**",
|
|
298
|
+
// ShipGuard's own report output — never scan the tool's own artifacts
|
|
299
|
+
".shipguard/**"
|
|
319
300
|
];
|
|
320
|
-
async function scan(options, proRules) {
|
|
301
|
+
async function scan(options, proRules, onProgress) {
|
|
321
302
|
const cwd = process.cwd();
|
|
322
303
|
const policy = await loadPolicy(cwd);
|
|
323
304
|
const ignorePatterns = [...DEFAULT_IGNORE, ...policy.ignore.paths];
|
|
305
|
+
const limits = {
|
|
306
|
+
maxFileSizeBytes: policy.limits?.maxFileSizeBytes ?? DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
307
|
+
maxTotalBytes: policy.limits?.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES,
|
|
308
|
+
maxFiles: policy.limits?.maxFiles ?? DEFAULT_MAX_FILES
|
|
309
|
+
};
|
|
324
310
|
let files;
|
|
311
|
+
let skippedTooLarge = 0;
|
|
312
|
+
let skippedBinary = 0;
|
|
313
|
+
let truncated = false;
|
|
325
314
|
if (options.changedOnly && isGitRepo(cwd)) {
|
|
326
315
|
const changedRelPaths = getChangedFiles(cwd);
|
|
327
316
|
const filteredPaths = changedRelPaths.filter(
|
|
@@ -331,19 +320,57 @@ async function scan(options, proRules) {
|
|
|
331
320
|
})
|
|
332
321
|
);
|
|
333
322
|
files = [];
|
|
323
|
+
let totalBytes = 0;
|
|
324
|
+
const changedTotal = filteredPaths.length;
|
|
325
|
+
let changedProcessed = 0;
|
|
334
326
|
for (const relPath of filteredPaths) {
|
|
327
|
+
if (files.length >= limits.maxFiles || totalBytes >= limits.maxTotalBytes) {
|
|
328
|
+
truncated = true;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
const fullPath = join2(cwd, relPath);
|
|
335
332
|
try {
|
|
336
|
-
const
|
|
337
|
-
|
|
333
|
+
const fileStat = await stat(fullPath);
|
|
334
|
+
if (fileStat.size > limits.maxFileSizeBytes) {
|
|
335
|
+
skippedTooLarge++;
|
|
336
|
+
onProgress?.(++changedProcessed, changedTotal, relPath);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const buffer = await readFile2(fullPath);
|
|
340
|
+
const checkLen = Math.min(buffer.length, 8192);
|
|
341
|
+
let isBinary = false;
|
|
342
|
+
for (let i = 0; i < checkLen; i++) {
|
|
343
|
+
if (buffer[i] === 0) {
|
|
344
|
+
isBinary = true;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (isBinary) {
|
|
349
|
+
skippedBinary++;
|
|
350
|
+
onProgress?.(++changedProcessed, changedTotal, relPath);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const content = buffer.toString("utf-8");
|
|
354
|
+
totalBytes += buffer.length;
|
|
338
355
|
files.push({ path: fullPath, content, relativePath: relPath });
|
|
339
356
|
} catch {
|
|
340
357
|
}
|
|
358
|
+
onProgress?.(++changedProcessed, changedTotal, relPath);
|
|
341
359
|
}
|
|
342
360
|
} else {
|
|
343
361
|
if (options.changedOnly && !isGitRepo(cwd)) {
|
|
344
362
|
logger.warn("--changed flag set but not a git repository \u2014 scanning all files");
|
|
345
363
|
}
|
|
346
|
-
|
|
364
|
+
const readResult = await readFiles(cwd, ["**/*"], ignorePatterns, {
|
|
365
|
+
maxFileSizeBytes: limits.maxFileSizeBytes,
|
|
366
|
+
maxTotalBytes: limits.maxTotalBytes,
|
|
367
|
+
maxFiles: limits.maxFiles,
|
|
368
|
+
onProgress
|
|
369
|
+
});
|
|
370
|
+
files = readResult.files;
|
|
371
|
+
skippedTooLarge = readResult.skippedTooLarge;
|
|
372
|
+
skippedBinary = readResult.skippedBinary;
|
|
373
|
+
truncated = readResult.truncated;
|
|
347
374
|
}
|
|
348
375
|
let allFindings = CHECK_MODULES.flatMap((mod) => mod.run(files, policy));
|
|
349
376
|
let coderefDegraded = false;
|
|
@@ -364,7 +391,11 @@ async function scan(options, proRules) {
|
|
|
364
391
|
policyUsed: policy.project.name,
|
|
365
392
|
// Propagate coderef version-skip degradation — scan.ts:145 will OR-merge with
|
|
366
393
|
// its own degraded flag so this is not clobbered.
|
|
367
|
-
degraded: coderefDegraded || void 0
|
|
394
|
+
degraded: coderefDegraded || truncated || void 0,
|
|
395
|
+
// Internal metadata for the human-output path — NOT included in --json output
|
|
396
|
+
_skippedTooLarge: skippedTooLarge,
|
|
397
|
+
_skippedBinary: skippedBinary,
|
|
398
|
+
_truncated: truncated
|
|
368
399
|
};
|
|
369
400
|
return result;
|
|
370
401
|
}
|
|
@@ -521,7 +552,313 @@ function toSarif(result) {
|
|
|
521
552
|
};
|
|
522
553
|
}
|
|
523
554
|
|
|
555
|
+
// src/core/render.ts
|
|
556
|
+
import chalk2 from "chalk";
|
|
557
|
+
import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
|
|
558
|
+
import { join as join3 } from "path";
|
|
559
|
+
import { homedir } from "os";
|
|
560
|
+
var DOCS_URL = "https://agenticcli.dev/docs";
|
|
561
|
+
var SITE_URL = "https://agenticcli.dev";
|
|
562
|
+
var PRICING_URL = "https://agenticcli.dev/pricing";
|
|
563
|
+
var SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
|
|
564
|
+
var BOX_WIDTH = 78;
|
|
565
|
+
var H = "\u2500";
|
|
566
|
+
var V = "\u2502";
|
|
567
|
+
var TL = "\u256D";
|
|
568
|
+
var TR = "\u256E";
|
|
569
|
+
var BL = "\u2570";
|
|
570
|
+
var BR = "\u256F";
|
|
571
|
+
var SECTION = "\u251C" + H.repeat(BOX_WIDTH - 2) + "\u2524";
|
|
572
|
+
var BAR_FULL = "\u2588";
|
|
573
|
+
var BAR_EMPTY = "\u2591";
|
|
574
|
+
function findingFpLabel(confidence) {
|
|
575
|
+
switch (confidence) {
|
|
576
|
+
case "HIGH":
|
|
577
|
+
return "low false-positive chance";
|
|
578
|
+
case "MEDIUM":
|
|
579
|
+
return "moderate \u2014 review";
|
|
580
|
+
case "LOW":
|
|
581
|
+
return "higher false-positive \u2014 verify manually";
|
|
582
|
+
default:
|
|
583
|
+
return "unrated";
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function renderProgressBar(current, total, width = 20, currentFile) {
|
|
587
|
+
const fraction = total > 0 ? Math.min(current / total, 1) : 0;
|
|
588
|
+
const filled = Math.round(fraction * width);
|
|
589
|
+
const empty = width - filled;
|
|
590
|
+
const bar = chalk2.cyan(BAR_FULL.repeat(filled)) + chalk2.gray(BAR_EMPTY.repeat(empty));
|
|
591
|
+
const counter = `${current}/${total}`;
|
|
592
|
+
const fileHint = currentFile ? ` ${chalk2.dim(truncatePath(currentFile, 35))}` : "";
|
|
593
|
+
return `${chalk2.cyan("\u283F")} scanning [${bar}] ${chalk2.bold(counter)}${fileHint}`;
|
|
594
|
+
}
|
|
595
|
+
function shouldShowProgress(gates) {
|
|
596
|
+
return gates.isTTY && !gates.quiet && !gates.machineOutput;
|
|
597
|
+
}
|
|
598
|
+
var SEVERITY_COLORS = {
|
|
599
|
+
critical: chalk2.bgRed.white,
|
|
600
|
+
high: chalk2.red,
|
|
601
|
+
medium: chalk2.yellow,
|
|
602
|
+
low: chalk2.blue,
|
|
603
|
+
info: chalk2.gray
|
|
604
|
+
};
|
|
605
|
+
var SEVERITY_ICONS = {
|
|
606
|
+
critical: "\u26D4",
|
|
607
|
+
high: "\u{1F534}",
|
|
608
|
+
medium: "\u{1F7E1}",
|
|
609
|
+
low: "\u{1F535}",
|
|
610
|
+
info: "\u26AA"
|
|
611
|
+
};
|
|
612
|
+
function renderFindingsSummary(findings) {
|
|
613
|
+
if (findings.length === 0) {
|
|
614
|
+
return chalk2.green(" \u2713 No findings detected \u2014 clean scan.");
|
|
615
|
+
}
|
|
616
|
+
const lines = [];
|
|
617
|
+
lines.push(
|
|
618
|
+
chalk2.dim(
|
|
619
|
+
" Confidence legend: HIGH \u2192 low false-positive chance MEDIUM \u2192 moderate \u2014 review LOW \u2192 higher false-positive"
|
|
620
|
+
)
|
|
621
|
+
);
|
|
622
|
+
lines.push("");
|
|
623
|
+
for (const sev of SEVERITY_ORDER) {
|
|
624
|
+
const group = findings.filter((f) => f.severity === sev);
|
|
625
|
+
if (group.length === 0) continue;
|
|
626
|
+
const colorFn = SEVERITY_COLORS[sev] || chalk2.white;
|
|
627
|
+
const icon = SEVERITY_ICONS[sev] || "";
|
|
628
|
+
lines.push(` ${colorFn(` ${sev.toUpperCase().padEnd(8)} `)} ${icon} ${group.length} finding${group.length !== 1 ? "s" : ""}`);
|
|
629
|
+
for (const f of group) {
|
|
630
|
+
const location = f.line != null ? `${f.file}:${f.line}` : f.file;
|
|
631
|
+
const fpLabel = chalk2.dim(`[${findingFpLabel(f.confidence)}]`);
|
|
632
|
+
lines.push(` ${chalk2.bold(f.title)} \u2014 ${chalk2.cyan(location)} ${fpLabel}`);
|
|
633
|
+
if (f.evidence) {
|
|
634
|
+
lines.push(` Evidence: ${chalk2.yellow(truncate(f.evidence, 100))}`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
lines.push("");
|
|
638
|
+
}
|
|
639
|
+
return lines.join("\n");
|
|
640
|
+
}
|
|
641
|
+
function findingsByCategoryTable(findings) {
|
|
642
|
+
if (findings.length === 0) {
|
|
643
|
+
return chalk2.dim(" No findings across any category.");
|
|
644
|
+
}
|
|
645
|
+
const catCounts = {};
|
|
646
|
+
for (const f of findings) {
|
|
647
|
+
catCounts[f.category] = (catCounts[f.category] ?? 0) + 1;
|
|
648
|
+
}
|
|
649
|
+
const lines = [];
|
|
650
|
+
lines.push(chalk2.bold(" Category breakdown:"));
|
|
651
|
+
for (const [cat, count] of Object.entries(catCounts).sort()) {
|
|
652
|
+
const bar = chalk2.cyan("\u25A0".repeat(Math.min(count, 10)));
|
|
653
|
+
lines.push(` ${cat.padEnd(14)} ${String(count).padStart(3)} ${bar}`);
|
|
654
|
+
}
|
|
655
|
+
return lines.join("\n");
|
|
656
|
+
}
|
|
657
|
+
function coverageLine() {
|
|
658
|
+
return chalk2.dim(
|
|
659
|
+
` Coverage: secrets, auth, payments, database, deployment (free tier).
|
|
660
|
+
Deeper agentic rules available via Pro \u2014 some issue classes may be missed on free.
|
|
661
|
+
Upgrade: ${chalk2.underline(PRICING_URL)}`
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
var VERDICT_CONFIG = {
|
|
665
|
+
SAFE_TO_SHIP: {
|
|
666
|
+
icon: "\u2705",
|
|
667
|
+
color: chalk2.greenBright,
|
|
668
|
+
label: "SAFE TO SHIP",
|
|
669
|
+
helpLine: (blockingCount) => blockingCount > 0 ? chalk2.green(` No blocking issues \u2014 ${blockingCount} informational finding(s) noted.`) : chalk2.green(" Clean \u2014 safe to ship. No issues found.")
|
|
670
|
+
},
|
|
671
|
+
REVIEW_BEFORE_SHIP: {
|
|
672
|
+
icon: "\u26A0\uFE0F",
|
|
673
|
+
color: chalk2.yellowBright,
|
|
674
|
+
label: "REVIEW BEFORE SHIP",
|
|
675
|
+
helpLine: (blockingCount) => chalk2.yellow(` ${blockingCount} finding(s) need attention before shipping.`)
|
|
676
|
+
},
|
|
677
|
+
DO_NOT_SHIP: {
|
|
678
|
+
icon: "\u26D4",
|
|
679
|
+
color: chalk2.redBright,
|
|
680
|
+
label: "DO NOT SHIP",
|
|
681
|
+
helpLine: (blockingCount) => chalk2.red(` Blocked: ${blockingCount} critical/blocking issue(s) must be fixed first.`)
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
function boxLine(content) {
|
|
685
|
+
const inner = ` ${content}`;
|
|
686
|
+
const visibleLen = displayWidth(inner);
|
|
687
|
+
const pad = Math.max(0, BOX_WIDTH - 2 - visibleLen);
|
|
688
|
+
return `${V}${inner}${" ".repeat(pad)}${V}`;
|
|
689
|
+
}
|
|
690
|
+
function boxEmpty() {
|
|
691
|
+
return `${V}${" ".repeat(BOX_WIDTH - 2)}${V}`;
|
|
692
|
+
}
|
|
693
|
+
function boxTop() {
|
|
694
|
+
return chalk2.dim(TL + H.repeat(BOX_WIDTH - 2) + TR);
|
|
695
|
+
}
|
|
696
|
+
function boxBottom() {
|
|
697
|
+
return chalk2.dim(BL + H.repeat(BOX_WIDTH - 2) + BR);
|
|
698
|
+
}
|
|
699
|
+
function boxSection() {
|
|
700
|
+
return chalk2.dim(SECTION);
|
|
701
|
+
}
|
|
702
|
+
function verdictPanel(result, elapsedMs, skippedCount) {
|
|
703
|
+
const { riskScore, filesScanned } = result;
|
|
704
|
+
const recommendation = riskScore.recommendation;
|
|
705
|
+
const cfg = VERDICT_CONFIG[recommendation];
|
|
706
|
+
const elapsedStr = elapsedMs < 1e3 ? `${elapsedMs}ms` : `${(elapsedMs / 1e3).toFixed(1)}s`;
|
|
707
|
+
const lines = [""];
|
|
708
|
+
lines.push(boxTop());
|
|
709
|
+
lines.push(boxLine(chalk2.bold(" ShipGuard \u2014 Release Gate Report")));
|
|
710
|
+
lines.push(boxEmpty());
|
|
711
|
+
const verdictLabel = cfg.color(chalk2.bold(`${cfg.icon} ${cfg.label}`));
|
|
712
|
+
lines.push(boxLine(` ${verdictLabel}`));
|
|
713
|
+
lines.push(boxEmpty());
|
|
714
|
+
lines.push(boxSection());
|
|
715
|
+
lines.push(boxLine(chalk2.bold(" Run summary")));
|
|
716
|
+
const skippedSuffix = skippedCount && skippedCount > 0 ? chalk2.dim(` (${skippedCount} skipped)`) : "";
|
|
717
|
+
lines.push(boxLine(` Files scanned: ${chalk2.cyan(filesScanned)}${skippedSuffix}`));
|
|
718
|
+
lines.push(boxLine(` Elapsed time: ${chalk2.cyan(elapsedStr)}`));
|
|
719
|
+
lines.push(boxLine(` Total findings: ${chalk2.cyan(riskScore.totalFindings)}`));
|
|
720
|
+
const sevLines = [];
|
|
721
|
+
if (riskScore.criticalCount > 0) sevLines.push(chalk2.red(`critical: ${riskScore.criticalCount}`));
|
|
722
|
+
if (riskScore.highCount > 0) sevLines.push(chalk2.red(`high: ${riskScore.highCount}`));
|
|
723
|
+
if (riskScore.mediumCount > 0) sevLines.push(chalk2.yellow(`medium: ${riskScore.mediumCount}`));
|
|
724
|
+
if (riskScore.lowCount > 0) sevLines.push(chalk2.blue(`low: ${riskScore.lowCount}`));
|
|
725
|
+
if (riskScore.infoCount > 0) sevLines.push(chalk2.gray(`info: ${riskScore.infoCount}`));
|
|
726
|
+
if (sevLines.length > 0) {
|
|
727
|
+
lines.push(boxLine(` Severity: ${sevLines.join(" ")}`));
|
|
728
|
+
}
|
|
729
|
+
lines.push(boxSection());
|
|
730
|
+
lines.push(boxLine(chalk2.bold(" How ShipGuard helped")));
|
|
731
|
+
lines.push(boxLine(cfg.helpLine(riskScore.blockingCount)));
|
|
732
|
+
lines.push(boxSection());
|
|
733
|
+
lines.push(boxLine(chalk2.bold(" Learn more")));
|
|
734
|
+
lines.push(boxLine(` Docs ${chalk2.underline(DOCS_URL)}`));
|
|
735
|
+
lines.push(boxLine(` Site ${chalk2.underline(SITE_URL)}`));
|
|
736
|
+
lines.push(boxLine(` Pricing ${chalk2.underline(PRICING_URL)}`));
|
|
737
|
+
lines.push(boxEmpty());
|
|
738
|
+
lines.push(boxBottom());
|
|
739
|
+
lines.push("");
|
|
740
|
+
return lines.join("\n");
|
|
741
|
+
}
|
|
742
|
+
function getShipguardConfigDir() {
|
|
743
|
+
return join3(homedir(), ".config", "shipguard");
|
|
744
|
+
}
|
|
745
|
+
function welcomeBanner(configDir) {
|
|
746
|
+
const dir = configDir ?? getShipguardConfigDir();
|
|
747
|
+
const marker = join3(dir, ".welcomed");
|
|
748
|
+
if (existsSync2(marker)) {
|
|
749
|
+
return "";
|
|
750
|
+
}
|
|
751
|
+
try {
|
|
752
|
+
mkdirSync(dir, { recursive: true });
|
|
753
|
+
writeFileSync(marker, "1", "utf-8");
|
|
754
|
+
} catch {
|
|
755
|
+
}
|
|
756
|
+
const BANNER_INNER = BOX_WIDTH - 2;
|
|
757
|
+
function bannerLine(content) {
|
|
758
|
+
const inner = ` ${content}`;
|
|
759
|
+
const w = displayWidth(inner);
|
|
760
|
+
const pad = Math.max(0, BANNER_INNER - w);
|
|
761
|
+
return chalk2.cyan(" \u2502") + inner + " ".repeat(pad) + chalk2.cyan("\u2502");
|
|
762
|
+
}
|
|
763
|
+
const top = chalk2.bold(chalk2.cyan(" \u256D" + "\u2500".repeat(BANNER_INNER) + "\u256E"));
|
|
764
|
+
const bottom = chalk2.bold(chalk2.cyan(" \u2570" + "\u2500".repeat(BANNER_INNER) + "\u256F"));
|
|
765
|
+
const empty = chalk2.cyan(" \u2502") + " ".repeat(BANNER_INNER) + chalk2.cyan("\u2502");
|
|
766
|
+
return [
|
|
767
|
+
"",
|
|
768
|
+
top,
|
|
769
|
+
bannerLine("ShipGuard is a CLI-first release gate for AI-built apps."),
|
|
770
|
+
bannerLine("It catches secrets, auth flaws, and deployment issues before"),
|
|
771
|
+
bannerLine("they ship \u2014 deterministic, fast, privacy-preserving."),
|
|
772
|
+
empty,
|
|
773
|
+
bannerLine(chalk2.bold("Quick start:")),
|
|
774
|
+
bannerLine(` ${chalk2.green("shipguard scan <path>")} Run a scan on your project`),
|
|
775
|
+
bannerLine(` ${chalk2.green("shipguard login")} Unlock Pro rules`),
|
|
776
|
+
bannerLine(` ${chalk2.green("shipguard scan --json")} Machine-readable output for CI/agents`),
|
|
777
|
+
empty,
|
|
778
|
+
bannerLine(`Docs: ${chalk2.underline(DOCS_URL)}`),
|
|
779
|
+
bottom,
|
|
780
|
+
""
|
|
781
|
+
].join("\n");
|
|
782
|
+
}
|
|
783
|
+
function quietVerdict(result) {
|
|
784
|
+
const { recommendation, score, totalFindings, blockingCount } = result.riskScore;
|
|
785
|
+
const icon = recommendation === "SAFE_TO_SHIP" ? "\u2705" : recommendation === "DO_NOT_SHIP" ? "\u26D4" : "\u26A0\uFE0F";
|
|
786
|
+
const colorFn = recommendation === "SAFE_TO_SHIP" ? chalk2.green : recommendation === "DO_NOT_SHIP" ? chalk2.red : chalk2.yellow;
|
|
787
|
+
return colorFn(`${icon} ${recommendation.replace(/_/g, " ")} score=${score}/100 findings=${totalFindings} blocking=${blockingCount}`);
|
|
788
|
+
}
|
|
789
|
+
function truncate(str, maxLen) {
|
|
790
|
+
return str.length <= maxLen ? str : `${str.slice(0, maxLen - 3)}...`;
|
|
791
|
+
}
|
|
792
|
+
function truncatePath(filePath, maxLen) {
|
|
793
|
+
if (filePath.length <= maxLen) return filePath;
|
|
794
|
+
const parts = filePath.split("/");
|
|
795
|
+
const tail = parts.slice(-2).join("/");
|
|
796
|
+
return tail.length <= maxLen ? `\u2026/${tail}` : `\u2026${tail.slice(-maxLen)}`;
|
|
797
|
+
}
|
|
798
|
+
function displayWidth(str) {
|
|
799
|
+
const plain = str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
800
|
+
let width = 0;
|
|
801
|
+
for (const char of plain) {
|
|
802
|
+
const cp = char.codePointAt(0) ?? 0;
|
|
803
|
+
if (cp >= 65024 && cp <= 65039 || // Variation selectors
|
|
804
|
+
cp === 8204 || cp === 8205 || // ZWNJ, ZWJ
|
|
805
|
+
cp === 65279 || // BOM / zero-width no-break space
|
|
806
|
+
cp >= 768 && cp <= 879 || // Combining Diacritical Marks
|
|
807
|
+
cp >= 6832 && cp <= 6911 || // Combining Diacritical Marks Extended
|
|
808
|
+
cp >= 7616 && cp <= 7679 || // Combining Diacritical Marks Supplement
|
|
809
|
+
cp >= 8400 && cp <= 8447 || // Combining Diacritical Marks for Symbols
|
|
810
|
+
cp >= 65056 && cp <= 65071) {
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
if (cp >= 4352 && cp <= 4447 || // Hangul Jamo
|
|
814
|
+
cp >= 11904 && cp <= 12031 || // CJK Radicals Supplement
|
|
815
|
+
cp >= 12032 && cp <= 12287 || // Kangxi Radicals
|
|
816
|
+
cp >= 12288 && cp <= 12351 || // CJK Symbols and Punctuation
|
|
817
|
+
cp >= 12352 && cp <= 12447 || // Hiragana
|
|
818
|
+
cp >= 12448 && cp <= 12543 || // Katakana
|
|
819
|
+
cp >= 12544 && cp <= 12591 || // Bopomofo
|
|
820
|
+
cp >= 12592 && cp <= 12687 || // Hangul Compatibility Jamo
|
|
821
|
+
cp >= 12688 && cp <= 12703 || // Kanbun
|
|
822
|
+
cp >= 12704 && cp <= 12735 || // Bopomofo Extended
|
|
823
|
+
cp >= 12784 && cp <= 12799 || // Katakana Phonetic Extensions
|
|
824
|
+
cp >= 12800 && cp <= 13055 || // Enclosed CJK Letters and Months
|
|
825
|
+
cp >= 13056 && cp <= 13311 || // CJK Compatibility
|
|
826
|
+
cp >= 13312 && cp <= 19903 || // CJK Unified Ideographs Extension A
|
|
827
|
+
cp >= 19968 && cp <= 40959 || // CJK Unified Ideographs
|
|
828
|
+
cp >= 40960 && cp <= 42127 || // Yi Syllables
|
|
829
|
+
cp >= 42128 && cp <= 42191 || // Yi Radicals
|
|
830
|
+
cp >= 43360 && cp <= 43391 || // Hangul Jamo Extended-A
|
|
831
|
+
cp >= 44032 && cp <= 55215 || // Hangul Syllables
|
|
832
|
+
cp >= 55216 && cp <= 55295 || // Hangul Jamo Extended-B
|
|
833
|
+
cp >= 63744 && cp <= 64255 || // CJK Compatibility Ideographs
|
|
834
|
+
cp >= 65040 && cp <= 65055 || // Vertical Forms
|
|
835
|
+
cp >= 65072 && cp <= 65103 || // CJK Compatibility Forms
|
|
836
|
+
cp >= 65104 && cp <= 65135 || // Small Form Variants
|
|
837
|
+
cp >= 65280 && cp <= 65519 || // Halfwidth and Fullwidth Forms
|
|
838
|
+
cp >= 110592 && cp <= 110847 || // Kana Supplement
|
|
839
|
+
cp >= 126976 && cp <= 131071 || // Mahjong/Domino/Emoji block (includes ⛔ ✅ ⚠ 🔴 etc.)
|
|
840
|
+
cp >= 131072 && cp <= 173791 || // CJK Unified Ideographs Extension B
|
|
841
|
+
cp >= 173824 && cp <= 183983 || // CJK Extensions C/D/E
|
|
842
|
+
cp >= 183984 && cp <= 191471 || // CJK Extension F
|
|
843
|
+
cp >= 196608 && cp <= 201551 || // CJK Extension G
|
|
844
|
+
// Common BMP symbols rendered as 2-wide in most terminals
|
|
845
|
+
cp === 8505 || // ℹ️
|
|
846
|
+
cp === 8986 || cp === 8987 || // ⌚ ⌛
|
|
847
|
+
cp === 9193 || cp === 9203 || // ⏩ ⏳
|
|
848
|
+
cp >= 9725 && cp <= 9726 || // ◽ ◾
|
|
849
|
+
cp >= 9728 && cp <= 10175 || // Misc Symbols & Dingbats (includes ⚠ ⛔ ✅)
|
|
850
|
+
cp >= 11088 && cp <= 11093 || // ⭐ ⭕
|
|
851
|
+
cp === 12351) {
|
|
852
|
+
width += 2;
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
width += 1;
|
|
856
|
+
}
|
|
857
|
+
return width;
|
|
858
|
+
}
|
|
859
|
+
|
|
524
860
|
// src/commands/scan.ts
|
|
861
|
+
var LEARN_MORE = "Docs https://agenticcli.dev/docs \xB7 Site https://agenticcli.dev \xB7 Pricing https://agenticcli.dev/pricing \xB7 Issues https://github.com/ramxH3421/agentic-cli/issues";
|
|
525
862
|
function resolveExitCode(opts) {
|
|
526
863
|
if (opts.strict && opts.blockingCount > 0) {
|
|
527
864
|
return EXIT_CODES.BLOCKED;
|
|
@@ -531,192 +868,280 @@ function resolveExitCode(opts) {
|
|
|
531
868
|
}
|
|
532
869
|
return EXIT_CODES.SAFE;
|
|
533
870
|
}
|
|
534
|
-
|
|
871
|
+
function isProjectRoot(dir) {
|
|
872
|
+
return existsSync3(join4(dir, "package.json")) || existsSync3(join4(dir, ".git"));
|
|
873
|
+
}
|
|
535
874
|
function scanCommand() {
|
|
536
|
-
return new Command2("scan").description("Scan your project for high-risk issues").option("--changed", "Only scan changed files from git diff").option("--report", "Generate a detailed Markdown report").option("--strict", "Exit with code 1 if blocking issues found").option("--json", "Output results as JSON").option("--sarif", "Output results as SARIF 2.1.0 (for GitHub Code Scanning)").option("--pro", "Include pro quality gate rules (requires authentication)").option("--api-url <url>", "API server URL", "https://agenticcli.dev").option("--category <categories>", "Comma-separated category filter for pro rules").option("--beta", "Include beta-stage rules").
|
|
537
|
-
|
|
875
|
+
return new Command2("scan").description("Scan your project for high-risk issues (verbose by default; use --quiet for one-line verdict)").argument("[path]", "Path to project root to scan (defaults to current directory)").option("--changed", "Only scan changed files from git diff").option("--report", "Generate a detailed Markdown report").option("--strict", "Exit with code 1 if blocking issues found").option("--json", "Output results as JSON (machine-readable; suppresses all decoration)").option("--sarif", "Output results as SARIF 2.1.0 (for GitHub Code Scanning)").option("-q, --quiet", "One-line verdict only (suppresses progress, panel, and tips)").option("--pro", "Include pro quality gate rules (requires authentication)").option("--api-url <url>", "API server URL", "https://agenticcli.dev").option("--category <categories>", "Comma-separated category filter for pro rules").option("--beta", "Include beta-stage rules").option("--all", "Scan any directory, even without package.json or .git").addHelpText("after", `
|
|
876
|
+
Output modes:
|
|
877
|
+
(default) Verbose: live progress (TTY), categorized findings, gamified verdict panel
|
|
878
|
+
--quiet / -q One-line verdict + exit code only \u2014 ideal for scripts
|
|
879
|
+
--json Machine-readable JSON to stdout; all decoration suppressed
|
|
880
|
+
--sarif SARIF 2.1.0 to stdout (GitHub Code Scanning)
|
|
881
|
+
|
|
882
|
+
Auto-quiet: progress animations are suppressed in non-TTY (piped/CI) environments automatically.
|
|
883
|
+
|
|
884
|
+
Examples:
|
|
885
|
+
shipguard scan Scan current project (rich output)
|
|
886
|
+
shipguard scan --quiet One-line verdict only
|
|
887
|
+
shipguard scan ./my-app Scan a specific directory
|
|
888
|
+
shipguard scan --changed Scan only git-diff files (faster)
|
|
889
|
+
shipguard scan --json Machine-readable output for CI/agents
|
|
890
|
+
shipguard scan --pro Include pro quality gate rules (requires login)
|
|
891
|
+
shipguard scan --all Scan any directory regardless of project markers
|
|
892
|
+
|
|
893
|
+
Exit codes:
|
|
894
|
+
0 Safe \u2014 no blocking findings
|
|
895
|
+
1 Blocked \u2014 strict mode + blocking findings
|
|
896
|
+
2 Config error / degraded scan (incomplete results)
|
|
897
|
+
3 Runtime error
|
|
898
|
+
|
|
899
|
+
${LEARN_MORE}`).action(async (scanPath, opts) => {
|
|
900
|
+
const startTime = Date.now();
|
|
901
|
+
const cwd = scanPath ? resolve3(scanPath) : process.cwd();
|
|
538
902
|
const scanId = randomUUID();
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
903
|
+
const machineOutput = Boolean(opts.json) || Boolean(opts.sarif);
|
|
904
|
+
const quiet = Boolean(opts.quiet);
|
|
905
|
+
if (!scanPath && !opts.all && !isProjectRoot(cwd)) {
|
|
906
|
+
logger.error(
|
|
907
|
+
`Refusing to scan a non-project directory ${cwd}. Pass a path (\`shipguard scan ./my-app\`) or \`--all\` to override.`
|
|
908
|
+
);
|
|
909
|
+
if (!machineOutput) {
|
|
910
|
+
console.log(`
|
|
911
|
+
${LEARN_MORE}`);
|
|
912
|
+
}
|
|
544
913
|
process.exit(EXIT_CODES.CONFIG_ERROR);
|
|
545
914
|
}
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
generateReport: Boolean(opts.report),
|
|
550
|
-
strict: Boolean(opts.strict),
|
|
551
|
-
json: Boolean(opts.json),
|
|
552
|
-
reportPath: policy.report.output ?? DEFAULT_REPORT_FILE
|
|
553
|
-
};
|
|
554
|
-
const machineOutput = scanOptions.json || Boolean(opts.sarif);
|
|
555
|
-
if (!machineOutput) {
|
|
556
|
-
logger.divider();
|
|
557
|
-
logger.info(`ShipGuard \u2014 scanning ${policy.project.name}`);
|
|
558
|
-
if (scanOptions.changedOnly && inGitRepo) {
|
|
559
|
-
logger.info("Mode: changed files only");
|
|
560
|
-
} else {
|
|
561
|
-
logger.info("Mode: full project scan");
|
|
562
|
-
}
|
|
563
|
-
logger.divider();
|
|
915
|
+
const originalCwd = process.cwd();
|
|
916
|
+
if (scanPath) {
|
|
917
|
+
process.chdir(cwd);
|
|
564
918
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
if (!machineOutput) {
|
|
571
|
-
logger.info("Detecting stack...");
|
|
572
|
-
}
|
|
573
|
-
try {
|
|
574
|
-
const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
|
|
575
|
-
const { fetchProRules } = await import("./pro-scanner-YZDS67FB.js");
|
|
576
|
-
const { hasConfig, generateConfig } = await import("./config-generator-EQNRHODF.js");
|
|
577
|
-
const detectedResult = detectFrameworks(cwd);
|
|
578
|
-
const { frameworks } = detectedResult;
|
|
579
|
-
if (!hasConfig(cwd)) {
|
|
580
|
-
const configPath = generateConfig(cwd, detectedResult.frameworks);
|
|
581
|
-
if (!machineOutput) {
|
|
582
|
-
logger.success(`Config saved to ${configPath}`);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
if (!machineOutput) {
|
|
586
|
-
for (const fw of frameworks) {
|
|
587
|
-
logger.info(` + ${fw.name}${fw.version ? ` ${fw.version}` : ""}`);
|
|
588
|
-
}
|
|
589
|
-
logger.info("Fetching pro rules...");
|
|
590
|
-
}
|
|
591
|
-
const categories = opts.category ? opts.category.split(",").map((c) => c.trim()) : void 0;
|
|
592
|
-
const fetched = await fetchProRules(
|
|
593
|
-
frameworks.map((f) => f.name),
|
|
594
|
-
categories,
|
|
595
|
-
opts.apiUrl
|
|
596
|
-
);
|
|
597
|
-
proRules = fetched.rules;
|
|
598
|
-
creditsRemaining = fetched.creditsRemaining;
|
|
599
|
-
rulesVersion = fetched.rulesVersion;
|
|
600
|
-
if (!machineOutput && proRules.length > 0) {
|
|
601
|
-
const breakdown = {};
|
|
602
|
-
for (const r of proRules) {
|
|
603
|
-
breakdown[r.category] = (breakdown[r.category] ?? 0) + 1;
|
|
604
|
-
}
|
|
605
|
-
const breakdownStr = Object.entries(breakdown).map(([cat, count]) => `${cat}: ${count}`).join(", ");
|
|
606
|
-
logger.info(` + ${proRules.length} rules loaded (${breakdownStr})`);
|
|
607
|
-
logger.info(" + Encrypted | Signed | Memory-only");
|
|
608
|
-
}
|
|
609
|
-
} catch (err) {
|
|
610
|
-
logger.warn(`Pro rules unavailable: ${err instanceof Error ? err.message : String(err)}`);
|
|
611
|
-
logger.warn("Degrading to free scan \u2014 pro rules will not be applied");
|
|
612
|
-
degraded = true;
|
|
919
|
+
try {
|
|
920
|
+
await runScan({ cwd, scanId, opts, machineOutput, quiet, startTime });
|
|
921
|
+
} finally {
|
|
922
|
+
if (scanPath) {
|
|
923
|
+
process.chdir(originalCwd);
|
|
613
924
|
}
|
|
614
925
|
}
|
|
615
|
-
|
|
616
|
-
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
async function runScan(ctx) {
|
|
929
|
+
const { cwd, scanId, opts, machineOutput, quiet, startTime } = ctx;
|
|
930
|
+
let policy;
|
|
931
|
+
try {
|
|
932
|
+
policy = await loadPolicy(cwd);
|
|
933
|
+
} catch (error) {
|
|
934
|
+
logger.error(`Config error: ${error instanceof Error ? error.message : error}`);
|
|
935
|
+
process.exit(EXIT_CODES.CONFIG_ERROR);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const inGitRepo = isGitRepo(cwd);
|
|
939
|
+
const scanOptions = {
|
|
940
|
+
changedOnly: Boolean(opts.changed),
|
|
941
|
+
generateReport: Boolean(opts.report),
|
|
942
|
+
strict: Boolean(opts.strict),
|
|
943
|
+
json: Boolean(opts.json),
|
|
944
|
+
reportPath: policy.report.output ?? DEFAULT_REPORT_FILE
|
|
945
|
+
};
|
|
946
|
+
if (!machineOutput && !quiet) {
|
|
947
|
+
logger.divider();
|
|
948
|
+
logger.info(`ShipGuard \u2014 scanning ${policy.project.name}`);
|
|
949
|
+
logger.info(`Scan path: ${cwd}`);
|
|
950
|
+
if (scanOptions.changedOnly && inGitRepo) {
|
|
951
|
+
logger.info("Mode: changed files only");
|
|
952
|
+
} else {
|
|
953
|
+
logger.info("Mode: full project scan");
|
|
954
|
+
}
|
|
955
|
+
logger.divider();
|
|
956
|
+
}
|
|
957
|
+
let proRules;
|
|
958
|
+
let creditsRemaining;
|
|
959
|
+
let rulesVersion;
|
|
960
|
+
let degraded = false;
|
|
961
|
+
if (opts.pro) {
|
|
962
|
+
if (!machineOutput && !quiet) {
|
|
963
|
+
logger.info("Detecting stack...");
|
|
617
964
|
}
|
|
618
|
-
let result;
|
|
619
965
|
try {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
966
|
+
const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
|
|
967
|
+
const { fetchProRules } = await import("./pro-scanner-ZBGRHNFD.js");
|
|
968
|
+
const { hasConfig, generateConfig } = await import("./config-generator-YSWNA53I.js");
|
|
969
|
+
const detectedResult = detectFrameworks(cwd);
|
|
970
|
+
const { frameworks } = detectedResult;
|
|
971
|
+
if (!hasConfig(cwd)) {
|
|
972
|
+
const configPath = generateConfig(cwd, detectedResult.frameworks);
|
|
973
|
+
if (!machineOutput && !quiet) {
|
|
974
|
+
logger.success(`Config saved to ${configPath}`);
|
|
975
|
+
}
|
|
626
976
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
result.creditsWarning = creditsRemaining !== void 0 && creditsRemaining < 10;
|
|
633
|
-
result.rulesVersion = rulesVersion;
|
|
634
|
-
if (proRules?.length) {
|
|
635
|
-
const breakdown = {};
|
|
636
|
-
for (const r of proRules) {
|
|
637
|
-
breakdown[r.category] = (breakdown[r.category] ?? 0) + 1;
|
|
977
|
+
if (!machineOutput && !quiet) {
|
|
978
|
+
for (const fw of frameworks) {
|
|
979
|
+
logger.info(` + ${fw.name}${fw.version ? ` ${fw.version}` : ""}`);
|
|
980
|
+
}
|
|
981
|
+
logger.info("Fetching pro rules...");
|
|
638
982
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
for (const severity of SEVERITY_ORDER) {
|
|
653
|
-
const group = findings.filter((f) => f.severity === severity);
|
|
654
|
-
if (group.length === 0) continue;
|
|
655
|
-
for (const finding of group) {
|
|
656
|
-
const location = finding.line != null ? `${finding.file}:${finding.line}` : finding.file;
|
|
657
|
-
logger.finding(severity, `${finding.title} \u2014 ${location}`);
|
|
658
|
-
if (finding.evidence) {
|
|
659
|
-
logger.finding(severity, ` Evidence: ${finding.evidence}`);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
983
|
+
const categories = opts.category ? opts.category.split(",").map((c) => c.trim()) : void 0;
|
|
984
|
+
const fetched = await fetchProRules(
|
|
985
|
+
frameworks.map((f) => f.name),
|
|
986
|
+
categories,
|
|
987
|
+
opts.apiUrl
|
|
988
|
+
);
|
|
989
|
+
proRules = fetched.rules;
|
|
990
|
+
creditsRemaining = fetched.creditsRemaining;
|
|
991
|
+
rulesVersion = fetched.rulesVersion;
|
|
992
|
+
if (!machineOutput && !quiet && proRules.length > 0) {
|
|
993
|
+
const breakdown = {};
|
|
994
|
+
for (const r of proRules) {
|
|
995
|
+
breakdown[r.category] = (breakdown[r.category] ?? 0) + 1;
|
|
662
996
|
}
|
|
997
|
+
const breakdownStr = Object.entries(breakdown).map(([cat, count]) => `${cat}: ${count}`).join(", ");
|
|
998
|
+
logger.info(` + ${proRules.length} rules loaded (${breakdownStr})`);
|
|
999
|
+
logger.info(" + Encrypted | Signed | Memory-only");
|
|
663
1000
|
}
|
|
664
|
-
|
|
1001
|
+
} catch (err) {
|
|
1002
|
+
logger.warn(`Pro rules unavailable: ${err instanceof Error ? err.message : String(err)}`);
|
|
1003
|
+
logger.warn("Degrading to free scan \u2014 pro rules will not be applied");
|
|
1004
|
+
degraded = true;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
const showProgress = shouldShowProgress({
|
|
1008
|
+
isTTY: Boolean(process.stdout.isTTY),
|
|
1009
|
+
quiet,
|
|
1010
|
+
machineOutput
|
|
1011
|
+
});
|
|
1012
|
+
let lastDrawMs = 0;
|
|
1013
|
+
const onProgress = showProgress ? (current, total, file) => {
|
|
1014
|
+
const now = Date.now();
|
|
1015
|
+
if (now - lastDrawMs >= 60 || current === total) {
|
|
1016
|
+
lastDrawMs = now;
|
|
1017
|
+
process.stderr.write(`\r\x1B[K${renderProgressBar(current, total, 20, file)}`);
|
|
1018
|
+
}
|
|
1019
|
+
} : void 0;
|
|
1020
|
+
if (!showProgress && !machineOutput && !quiet) {
|
|
1021
|
+
logger.info("Scanning files...");
|
|
1022
|
+
}
|
|
1023
|
+
let result;
|
|
1024
|
+
try {
|
|
1025
|
+
result = await scan(scanOptions, proRules, onProgress);
|
|
1026
|
+
} catch (error) {
|
|
1027
|
+
if (showProgress) {
|
|
1028
|
+
process.stderr.write("\r\x1B[K");
|
|
1029
|
+
}
|
|
1030
|
+
if (!machineOutput) {
|
|
1031
|
+
logger.error(`Scan failed: ${error instanceof Error ? error.message : error}`);
|
|
1032
|
+
} else {
|
|
1033
|
+
console.log(JSON.stringify({ error: String(error) }));
|
|
1034
|
+
}
|
|
1035
|
+
process.exit(EXIT_CODES.RUNTIME_ERROR);
|
|
1036
|
+
}
|
|
1037
|
+
if (showProgress) {
|
|
1038
|
+
process.stderr.write("\r\x1B[K");
|
|
1039
|
+
}
|
|
1040
|
+
const skippedTooLarge = result._skippedTooLarge ?? 0;
|
|
1041
|
+
const skippedBinary = result._skippedBinary ?? 0;
|
|
1042
|
+
const truncatedByBounds = result._truncated ?? false;
|
|
1043
|
+
result.recommendation = result.riskScore.recommendation;
|
|
1044
|
+
result.schemaVersion = "2";
|
|
1045
|
+
result.degraded = degraded || Boolean(result.degraded);
|
|
1046
|
+
result.creditsWarning = creditsRemaining !== void 0 && creditsRemaining < 10;
|
|
1047
|
+
result.rulesVersion = rulesVersion;
|
|
1048
|
+
if (proRules?.length) {
|
|
1049
|
+
const breakdown = {};
|
|
1050
|
+
for (const r of proRules) {
|
|
1051
|
+
breakdown[r.category] = (breakdown[r.category] ?? 0) + 1;
|
|
1052
|
+
}
|
|
1053
|
+
result.rulesApplied = proRules.length;
|
|
1054
|
+
result.rulesBreakdown = breakdown;
|
|
1055
|
+
result.aiCodeIssues = result.findings.filter((f) => f.aiCodeTarget).length;
|
|
1056
|
+
}
|
|
1057
|
+
const publicResult = { ...result };
|
|
1058
|
+
delete publicResult._skippedTooLarge;
|
|
1059
|
+
delete publicResult._skippedBinary;
|
|
1060
|
+
delete publicResult._truncated;
|
|
1061
|
+
if (opts.sarif) {
|
|
1062
|
+
console.log(JSON.stringify(toSarif(publicResult), null, 2));
|
|
1063
|
+
} else if (scanOptions.json) {
|
|
1064
|
+
console.log(JSON.stringify(publicResult, null, 2));
|
|
1065
|
+
} else if (quiet) {
|
|
1066
|
+
console.log(quietVerdict(result));
|
|
1067
|
+
} else {
|
|
1068
|
+
const elapsedMs = Date.now() - startTime;
|
|
1069
|
+
const isTTY = Boolean(process.stdout.isTTY);
|
|
1070
|
+
if (isTTY) {
|
|
1071
|
+
const banner = welcomeBanner();
|
|
1072
|
+
if (banner) console.log(banner);
|
|
1073
|
+
}
|
|
1074
|
+
console.log(renderFindingsSummary(result.findings));
|
|
1075
|
+
if (result.findings.length > 0) {
|
|
1076
|
+
console.log(findingsByCategoryTable(result.findings));
|
|
665
1077
|
console.log("");
|
|
666
|
-
logger.info(`Files scanned: ${result.filesScanned} | Findings: ${riskScore.totalFindings} | Blocking: ${riskScore.blockingCount}`);
|
|
667
|
-
if (creditsRemaining !== void 0) {
|
|
668
|
-
logger.info(`Credits remaining: ${creditsRemaining}`);
|
|
669
|
-
}
|
|
670
|
-
if (degraded) {
|
|
671
|
-
logger.warn("Scan ran in degraded mode \u2014 pro rules were unavailable");
|
|
672
|
-
}
|
|
673
1078
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
await generateReport(result, reportPath);
|
|
679
|
-
if (!machineOutput) {
|
|
680
|
-
logger.success(`Report written to ${reportPath}`);
|
|
681
|
-
}
|
|
682
|
-
} catch (error) {
|
|
683
|
-
logger.error(`Report generation failed: ${error instanceof Error ? error.message : error}`);
|
|
684
|
-
}
|
|
1079
|
+
if (skippedTooLarge > 0 || skippedBinary > 0) {
|
|
1080
|
+
logger.info(
|
|
1081
|
+
`Files skipped: ${skippedTooLarge + skippedBinary}` + (skippedTooLarge > 0 ? ` (too large: ${skippedTooLarge})` : "") + (skippedBinary > 0 ? ` (binary: ${skippedBinary})` : "")
|
|
1082
|
+
);
|
|
685
1083
|
}
|
|
686
|
-
if (
|
|
687
|
-
|
|
688
|
-
method: "POST",
|
|
689
|
-
headers: { "Content-Type": "application/json" },
|
|
690
|
-
body: JSON.stringify({
|
|
691
|
-
scanId,
|
|
692
|
-
findingsCount: result.findings.length,
|
|
693
|
-
blocked: result.riskScore.blockingCount > 0,
|
|
694
|
-
riskScore: result.riskScore.score,
|
|
695
|
-
recommendation: result.riskScore.recommendation,
|
|
696
|
-
severityBreakdown: {
|
|
697
|
-
critical: result.riskScore.criticalCount,
|
|
698
|
-
high: result.riskScore.highCount,
|
|
699
|
-
medium: result.riskScore.mediumCount,
|
|
700
|
-
low: result.riskScore.lowCount,
|
|
701
|
-
info: result.riskScore.infoCount
|
|
702
|
-
},
|
|
703
|
-
rulesApplied: proRules?.length ?? 0
|
|
704
|
-
})
|
|
705
|
-
}).catch(() => {
|
|
706
|
-
});
|
|
1084
|
+
if (creditsRemaining !== void 0) {
|
|
1085
|
+
logger.info(`Credits remaining: ${creditsRemaining}`);
|
|
707
1086
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
blockingCount: result.riskScore.blockingCount,
|
|
711
|
-
degraded: Boolean(result.degraded)
|
|
712
|
-
});
|
|
713
|
-
if (exitCode === EXIT_CODES.BLOCKED && !machineOutput) {
|
|
714
|
-
logger.warn(`Strict mode: ${result.riskScore.blockingCount} blocking finding(s) \u2014 exiting with code 1`);
|
|
1087
|
+
if (degraded) {
|
|
1088
|
+
logger.warn("Scan ran in degraded mode \u2014 pro rules were unavailable");
|
|
715
1089
|
}
|
|
716
|
-
if (
|
|
717
|
-
|
|
1090
|
+
if (truncatedByBounds) {
|
|
1091
|
+
logger.warn(
|
|
1092
|
+
`Scan was truncated: file count or total size limit was reached. Results are INCOMPLETE \u2014 add a \`.shipguardignore\` or edit \`shipguard.policy.yml\` limits.`
|
|
1093
|
+
);
|
|
1094
|
+
logger.warn(`Docs: https://agenticcli.dev/docs`);
|
|
718
1095
|
}
|
|
1096
|
+
console.log(coverageLine());
|
|
1097
|
+
console.log("");
|
|
1098
|
+
console.log(verdictPanel(result, elapsedMs, skippedTooLarge + skippedBinary));
|
|
1099
|
+
}
|
|
1100
|
+
const shouldReport = scanOptions.generateReport || policy.scan.generate_report;
|
|
1101
|
+
if (shouldReport) {
|
|
1102
|
+
const reportPath = scanOptions.reportPath;
|
|
1103
|
+
try {
|
|
1104
|
+
await generateReport(result, reportPath);
|
|
1105
|
+
if (!machineOutput && !quiet) {
|
|
1106
|
+
logger.success(`Report written to ${reportPath}`);
|
|
1107
|
+
}
|
|
1108
|
+
} catch (error) {
|
|
1109
|
+
logger.error(`Report generation failed: ${error instanceof Error ? error.message : error}`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (opts.pro && !degraded) {
|
|
1113
|
+
fetch(`${opts.apiUrl}/api/telemetry/ingest`, {
|
|
1114
|
+
method: "POST",
|
|
1115
|
+
headers: { "Content-Type": "application/json" },
|
|
1116
|
+
body: JSON.stringify({
|
|
1117
|
+
scanId,
|
|
1118
|
+
findingsCount: result.findings.length,
|
|
1119
|
+
blocked: result.riskScore.blockingCount > 0,
|
|
1120
|
+
riskScore: result.riskScore.score,
|
|
1121
|
+
recommendation: result.riskScore.recommendation,
|
|
1122
|
+
severityBreakdown: {
|
|
1123
|
+
critical: result.riskScore.criticalCount,
|
|
1124
|
+
high: result.riskScore.highCount,
|
|
1125
|
+
medium: result.riskScore.mediumCount,
|
|
1126
|
+
low: result.riskScore.lowCount,
|
|
1127
|
+
info: result.riskScore.infoCount
|
|
1128
|
+
},
|
|
1129
|
+
rulesApplied: proRules?.length ?? 0
|
|
1130
|
+
})
|
|
1131
|
+
}).catch(() => {
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
const exitCode = resolveExitCode({
|
|
1135
|
+
strict: scanOptions.strict,
|
|
1136
|
+
blockingCount: result.riskScore.blockingCount,
|
|
1137
|
+
degraded: Boolean(result.degraded)
|
|
719
1138
|
});
|
|
1139
|
+
if (exitCode === EXIT_CODES.BLOCKED && !machineOutput && !quiet) {
|
|
1140
|
+
logger.warn(`Strict mode: ${result.riskScore.blockingCount} blocking finding(s) \u2014 exiting with code 1`);
|
|
1141
|
+
}
|
|
1142
|
+
if (exitCode !== EXIT_CODES.SAFE) {
|
|
1143
|
+
process.exit(exitCode);
|
|
1144
|
+
}
|
|
720
1145
|
}
|
|
721
1146
|
|
|
722
1147
|
// src/commands/login.ts
|
|
@@ -895,9 +1320,46 @@ function rateCommand() {
|
|
|
895
1320
|
});
|
|
896
1321
|
}
|
|
897
1322
|
|
|
1323
|
+
// src/handlers.ts
|
|
1324
|
+
var ISSUES_URL = "https://github.com/ramxH3421/agentic-cli/issues";
|
|
1325
|
+
var DOCS_URL2 = "https://agenticcli.dev/docs";
|
|
1326
|
+
var REPORT_LINE = `Report this: ${ISSUES_URL} \xB7 Docs: ${DOCS_URL2}`;
|
|
1327
|
+
function handleUncaughtException(error) {
|
|
1328
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1329
|
+
console.error(`\x1B[31m\u2717\x1B[0m Unexpected error: ${message}`);
|
|
1330
|
+
if (process.env.SHIPGUARD_DEBUG && error instanceof Error) {
|
|
1331
|
+
console.error(error.stack);
|
|
1332
|
+
}
|
|
1333
|
+
console.error(REPORT_LINE);
|
|
1334
|
+
process.exit(EXIT_CODES.RUNTIME_ERROR);
|
|
1335
|
+
}
|
|
1336
|
+
function handleUnhandledRejection(reason, _promise) {
|
|
1337
|
+
const message = reason instanceof Error ? reason.message : String(reason);
|
|
1338
|
+
console.error(`\x1B[31m\u2717\x1B[0m Unhandled rejection: ${message}`);
|
|
1339
|
+
if (process.env.SHIPGUARD_DEBUG && reason instanceof Error) {
|
|
1340
|
+
console.error(reason.stack);
|
|
1341
|
+
}
|
|
1342
|
+
console.error(REPORT_LINE);
|
|
1343
|
+
process.exit(EXIT_CODES.RUNTIME_ERROR);
|
|
1344
|
+
}
|
|
1345
|
+
function handleSignal() {
|
|
1346
|
+
console.error("\nInterrupted.");
|
|
1347
|
+
process.exit(130);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
898
1350
|
// src/cli.ts
|
|
1351
|
+
process.on("uncaughtException", handleUncaughtException);
|
|
1352
|
+
process.on("unhandledRejection", handleUnhandledRejection);
|
|
1353
|
+
process.on("SIGINT", handleSignal);
|
|
1354
|
+
process.on("SIGTERM", handleSignal);
|
|
1355
|
+
var ISSUES_URL2 = "https://github.com/ramxH3421/agentic-cli/issues";
|
|
899
1356
|
var program = new Command7();
|
|
900
|
-
program.name("shipguard").description("CLI-first release gate for AI-built apps").version("0.1.
|
|
1357
|
+
program.name("shipguard").description("CLI-first release gate for AI-built apps").version("0.1.2").addHelpText("after", `
|
|
1358
|
+
Learn more:
|
|
1359
|
+
Docs https://agenticcli.dev/docs
|
|
1360
|
+
Site https://agenticcli.dev
|
|
1361
|
+
Pricing https://agenticcli.dev/pricing
|
|
1362
|
+
Issues ${ISSUES_URL2}`);
|
|
901
1363
|
program.addCommand(initCommand());
|
|
902
1364
|
program.addCommand(scanCommand());
|
|
903
1365
|
program.addCommand(loginCommand());
|
|
@@ -906,3 +1368,8 @@ program.addCommand(statusCommand());
|
|
|
906
1368
|
program.addCommand(feedbackCommand());
|
|
907
1369
|
program.addCommand(rateCommand());
|
|
908
1370
|
program.parseAsync(process.argv);
|
|
1371
|
+
export {
|
|
1372
|
+
handleSignal,
|
|
1373
|
+
handleUncaughtException,
|
|
1374
|
+
handleUnhandledRejection
|
|
1375
|
+
};
|