@agenticcli/shipguard 0.1.2 → 0.2.0
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/README.md
CHANGED
|
@@ -4,24 +4,52 @@ CLI-first release gate for AI-built apps.
|
|
|
4
4
|
|
|
5
5
|
Catches secrets leaks, auth gaps, payment webhook risks, destructive migrations, and deployment misconfigurations — before your code ships.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 30-second quickstart
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
+
# Zero install — scan right now
|
|
11
|
+
npx @agenticcli/shipguard scan
|
|
12
|
+
|
|
13
|
+
# Or install globally
|
|
10
14
|
npm install -g @agenticcli/shipguard
|
|
15
|
+
|
|
16
|
+
# Then run from any project directory
|
|
17
|
+
shipguard scan
|
|
11
18
|
```
|
|
12
19
|
|
|
20
|
+
> **PATH gotcha:** `npm install` (without `-g`) does NOT put `shipguard` on your PATH.
|
|
21
|
+
> Use `npx @agenticcli/shipguard scan` or install with `npm install -g @agenticcli/shipguard`.
|
|
22
|
+
|
|
13
23
|
## Usage
|
|
14
24
|
|
|
15
25
|
```bash
|
|
16
|
-
shipguard
|
|
17
|
-
shipguard scan
|
|
18
|
-
shipguard scan --
|
|
19
|
-
shipguard scan --
|
|
26
|
+
shipguard scan # Scan current project (rich output)
|
|
27
|
+
shipguard scan --strict # CI mode: exit 1 on blocking findings
|
|
28
|
+
shipguard scan --json # Machine-readable output for agents/CI
|
|
29
|
+
shipguard scan --quiet # One-line verdict only
|
|
30
|
+
shipguard scan --pro # Pro rules — requires login
|
|
31
|
+
shipguard login # Authenticate for Pro rules
|
|
32
|
+
shipguard init # Generate .shipguard.yml policy file
|
|
20
33
|
```
|
|
21
34
|
|
|
35
|
+
## Exit codes
|
|
36
|
+
|
|
37
|
+
| Code | Meaning |
|
|
38
|
+
|------|---------|
|
|
39
|
+
| `0` | Safe — no blocking findings |
|
|
40
|
+
| `1` | Blocked — `--strict` mode + blocking findings |
|
|
41
|
+
| `2` | Config error / degraded scan |
|
|
42
|
+
| `3` | Runtime error |
|
|
43
|
+
|
|
44
|
+
## Telemetry
|
|
45
|
+
|
|
46
|
+
ShipGuard sends an anonymous usage ping on each scan (verdict bucket, duration, CLI version, CI flag — never file contents, paths, or user identity). Opt out: `SHIPGUARD_TELEMETRY=0` or `DO_NOT_TRACK=1`.
|
|
47
|
+
|
|
48
|
+
Details: [agenticcli.dev/docs#telemetry](https://agenticcli.dev/docs#telemetry)
|
|
49
|
+
|
|
22
50
|
## Documentation
|
|
23
51
|
|
|
24
|
-
See [full docs](https://agenticcli.dev/
|
|
52
|
+
See [full docs](https://agenticcli.dev/docs) for policy configuration, CI setup, and agent integration.
|
|
25
53
|
|
|
26
54
|
## License
|
|
27
55
|
|
|
@@ -58,9 +58,12 @@ async function getAuthToken() {
|
|
|
58
58
|
// src/core/crypto.ts
|
|
59
59
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
60
60
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
61
|
-
var
|
|
61
|
+
var PINNED_KEYS = {
|
|
62
|
+
"k1-2026": `-----BEGIN PUBLIC KEY-----
|
|
62
63
|
MCowBQYDK2VwAyEAkpeX0A3zIOttGn8t+jagJHLRTv5Q809vqIZU37lE6xQ=
|
|
63
|
-
-----END PUBLIC KEY
|
|
64
|
+
-----END PUBLIC KEY-----`
|
|
65
|
+
};
|
|
66
|
+
var DEFAULT_KID = "k1-2026";
|
|
64
67
|
var HKDF_INFO = "shipguard-rules-v1";
|
|
65
68
|
function pemToArrayBuffer(pem) {
|
|
66
69
|
const b64 = pem.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, "");
|
|
@@ -70,7 +73,14 @@ function pemToArrayBuffer(pem) {
|
|
|
70
73
|
async function verifyAndDecryptBundle(bundleB64, accessToken) {
|
|
71
74
|
const bundleJson = Buffer.from(bundleB64, "base64").toString("utf-8");
|
|
72
75
|
const bundle = JSON.parse(bundleJson);
|
|
73
|
-
const
|
|
76
|
+
const kid = bundle.payload.kid ?? DEFAULT_KID;
|
|
77
|
+
const resolvedPem = PINNED_KEYS[kid];
|
|
78
|
+
if (!resolvedPem && !process.env.SHIPGUARD_PUBLIC_KEY) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Unknown signing key "${kid}" \u2014 rule bundle rejected (fail closed). Upgrade shipguard to a version that supports this key id.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const pem = process.env.SHIPGUARD_PUBLIC_KEY ?? resolvedPem;
|
|
74
84
|
const cryptoKey = await globalThis.crypto.subtle.importKey(
|
|
75
85
|
"spki",
|
|
76
86
|
pemToArrayBuffer(pem),
|
|
@@ -115,7 +125,7 @@ async function verifyAndDecryptBundle(bundleB64, accessToken) {
|
|
|
115
125
|
}
|
|
116
126
|
async function verifyRuleBundle(token) {
|
|
117
127
|
const { importSPKI: importKey, jwtVerify } = await import("jose");
|
|
118
|
-
const pem = process.env.SHIPGUARD_PUBLIC_KEY ??
|
|
128
|
+
const pem = process.env.SHIPGUARD_PUBLIC_KEY ?? PINNED_KEYS[DEFAULT_KID];
|
|
119
129
|
const publicKey = await importKey(pem, "EdDSA");
|
|
120
130
|
const { payload } = await jwtVerify(token, publicKey);
|
|
121
131
|
return payload;
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
runProRulesWithDispatch,
|
|
12
12
|
saveCredentials,
|
|
13
13
|
secretsCheck
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-YE2GPROS.js";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_MAX_FILES,
|
|
17
17
|
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "./chunk-7HMLDAMC.js";
|
|
21
21
|
|
|
22
22
|
// src/cli.ts
|
|
23
|
-
import { Command as Command7 } from "commander";
|
|
23
|
+
import { Command as Command7, CommanderError } from "commander";
|
|
24
24
|
|
|
25
25
|
// src/commands/init.ts
|
|
26
26
|
import { Command } from "commander";
|
|
@@ -190,7 +190,7 @@ function initCommand() {
|
|
|
190
190
|
import { Command as Command2 } from "commander";
|
|
191
191
|
import { randomUUID } from "crypto";
|
|
192
192
|
import { existsSync as existsSync3 } from "fs";
|
|
193
|
-
import { join as
|
|
193
|
+
import { join as join5, resolve as resolve3 } from "path";
|
|
194
194
|
|
|
195
195
|
// src/core/scanner.ts
|
|
196
196
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
@@ -402,7 +402,7 @@ async function scan(options, proRules, onProgress) {
|
|
|
402
402
|
|
|
403
403
|
// src/core/report.ts
|
|
404
404
|
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
405
|
-
import { dirname } from "path";
|
|
405
|
+
import { dirname, basename, join as join3 } from "path";
|
|
406
406
|
function severitySection(title, findings) {
|
|
407
407
|
if (findings.length === 0) {
|
|
408
408
|
return `## ${title}
|
|
@@ -433,10 +433,41 @@ function buildFixOrder(findings) {
|
|
|
433
433
|
...nonBlocking.sort((a, b) => severityOrder.indexOf(a.severity) - severityOrder.indexOf(b.severity))
|
|
434
434
|
];
|
|
435
435
|
if (sorted.length === 0) return "No findings to address.\n";
|
|
436
|
-
return sorted.map((f, i) => `${i + 1}. **${f.title}** (${f.severity}) \u2014 ${f.file}${f.line != null ? `:${f.line}` : ""}${f.blocking ? " \
|
|
436
|
+
return sorted.map((f, i) => `${i + 1}. **${f.title}** (${f.severity}) \u2014 ${f.file}${f.line != null ? `:${f.line}` : ""}${f.blocking ? " \u{1F6D1} blocking" : ""}`).join("\n");
|
|
437
437
|
}
|
|
438
|
-
|
|
439
|
-
|
|
438
|
+
function attitudeLine(recommendation) {
|
|
439
|
+
if (recommendation === "SAFE_TO_SHIP") return "SHIP IT \u2014 nothing blocking. Go make something people want.";
|
|
440
|
+
if (recommendation === "DO_NOT_SHIP") return "BLOCKED \u2014 shipping this would hurt. Fix the criticals first.";
|
|
441
|
+
return `HOLD UP \u2014 findings need eyes before this ships.`;
|
|
442
|
+
}
|
|
443
|
+
function topThreeFindings(findings) {
|
|
444
|
+
const severityOrder = ["critical", "high", "medium", "low", "info"];
|
|
445
|
+
const sorted = [...findings].sort((a, b) => {
|
|
446
|
+
if (a.blocking !== b.blocking) return a.blocking ? -1 : 1;
|
|
447
|
+
return severityOrder.indexOf(a.severity) - severityOrder.indexOf(b.severity);
|
|
448
|
+
});
|
|
449
|
+
const top = sorted.slice(0, 3);
|
|
450
|
+
if (top.length === 0) return "None \u2014 clean scan.\n";
|
|
451
|
+
return top.map((f, i) => `${i + 1}. **${f.title}** (${f.severity}) \u2014 ${f.file}${f.line != null ? `:${f.line}` : ""}`).join("\n");
|
|
452
|
+
}
|
|
453
|
+
function severityBreakdownTable(riskScore) {
|
|
454
|
+
const rows = [
|
|
455
|
+
["Critical", riskScore.criticalCount],
|
|
456
|
+
["High", riskScore.highCount],
|
|
457
|
+
["Medium", riskScore.mediumCount],
|
|
458
|
+
["Low", riskScore.lowCount],
|
|
459
|
+
["Info", riskScore.infoCount]
|
|
460
|
+
];
|
|
461
|
+
const lines = ["| Severity | Count |", "|----------|-------|"];
|
|
462
|
+
for (const [label, count] of rows) {
|
|
463
|
+
lines.push(`| ${label} | ${count} |`);
|
|
464
|
+
}
|
|
465
|
+
return lines.join("\n");
|
|
466
|
+
}
|
|
467
|
+
function buildUserMarkdown(result, elapsedMs) {
|
|
468
|
+
const { riskScore, findings, filesScanned, timestamp, recommendation } = result;
|
|
469
|
+
const rec = recommendation ?? riskScore.recommendation;
|
|
470
|
+
const elapsedStr = elapsedMs != null ? elapsedMs < 1e3 ? `${elapsedMs}ms` : `${(elapsedMs / 1e3).toFixed(1)}s` : "N/A";
|
|
440
471
|
const critical = findings.filter((f) => f.severity === "critical");
|
|
441
472
|
const high = findings.filter((f) => f.severity === "high");
|
|
442
473
|
const medium = findings.filter((f) => f.severity === "medium");
|
|
@@ -444,12 +475,23 @@ async function generateReport(result, outputPath) {
|
|
|
444
475
|
const sections = [
|
|
445
476
|
"# ShipGuard Release Report",
|
|
446
477
|
"",
|
|
447
|
-
"##
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
478
|
+
"## SUMMARY",
|
|
479
|
+
"",
|
|
480
|
+
`**Verdict:** ${rec} \u2014 ${attitudeLine(rec)}`,
|
|
481
|
+
"",
|
|
482
|
+
`**Files scanned:** ${filesScanned} | **Elapsed:** ${elapsedStr} | **Generated:** ${timestamp}`,
|
|
483
|
+
"",
|
|
484
|
+
"### Severity Breakdown",
|
|
485
|
+
"",
|
|
486
|
+
severityBreakdownTable(riskScore),
|
|
487
|
+
"",
|
|
488
|
+
`**Risk Score:** ${riskScore.score}/100 | **Total Findings:** ${riskScore.totalFindings}`,
|
|
489
|
+
"",
|
|
490
|
+
"### Top 3 Things to Fix",
|
|
491
|
+
"",
|
|
492
|
+
topThreeFindings(findings),
|
|
493
|
+
"",
|
|
494
|
+
"---",
|
|
453
495
|
"",
|
|
454
496
|
severitySection("Critical Findings", critical),
|
|
455
497
|
severitySection("High Findings", high),
|
|
@@ -461,12 +503,30 @@ async function generateReport(result, outputPath) {
|
|
|
461
503
|
"",
|
|
462
504
|
"## Final Recommendation",
|
|
463
505
|
"",
|
|
464
|
-
`**${
|
|
506
|
+
`**${rec}**`,
|
|
465
507
|
""
|
|
466
508
|
];
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
509
|
+
return sections.join("\n");
|
|
510
|
+
}
|
|
511
|
+
function buildAgentJson(result) {
|
|
512
|
+
const publicResult = { ...result };
|
|
513
|
+
delete publicResult._skippedTooLarge;
|
|
514
|
+
delete publicResult._skippedBinary;
|
|
515
|
+
delete publicResult._truncated;
|
|
516
|
+
return JSON.stringify(publicResult, null, 2);
|
|
517
|
+
}
|
|
518
|
+
async function generateReport(result, outputPath, elapsedMs) {
|
|
519
|
+
const dir = dirname(outputPath);
|
|
520
|
+
const base = basename(outputPath, ".md");
|
|
521
|
+
const jsonPath = join3(dir, `${base}.json`);
|
|
522
|
+
const mdContent = buildUserMarkdown(result, elapsedMs);
|
|
523
|
+
const jsonContent = buildAgentJson(result);
|
|
524
|
+
await mkdir2(dir, { recursive: true });
|
|
525
|
+
await Promise.all([
|
|
526
|
+
writeFile2(outputPath, mdContent, "utf-8"),
|
|
527
|
+
writeFile2(jsonPath, jsonContent, "utf-8")
|
|
528
|
+
]);
|
|
529
|
+
return { mdPath: outputPath, jsonPath };
|
|
470
530
|
}
|
|
471
531
|
|
|
472
532
|
// src/core/sarif.ts
|
|
@@ -555,11 +615,12 @@ function toSarif(result) {
|
|
|
555
615
|
// src/core/render.ts
|
|
556
616
|
import chalk2 from "chalk";
|
|
557
617
|
import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
|
|
558
|
-
import { join as
|
|
618
|
+
import { join as join4, basename as basename2 } from "path";
|
|
559
619
|
import { homedir } from "os";
|
|
560
620
|
var DOCS_URL = "https://agenticcli.dev/docs";
|
|
561
621
|
var SITE_URL = "https://agenticcli.dev";
|
|
562
622
|
var PRICING_URL = "https://agenticcli.dev/pricing";
|
|
623
|
+
var ISSUES_URL = "https://github.com/ramxH3421/agentic-cli/issues";
|
|
563
624
|
var SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
|
|
564
625
|
var BOX_WIDTH = 78;
|
|
565
626
|
var H = "\u2500";
|
|
@@ -571,6 +632,79 @@ var BR = "\u256F";
|
|
|
571
632
|
var SECTION = "\u251C" + H.repeat(BOX_WIDTH - 2) + "\u2524";
|
|
572
633
|
var BAR_FULL = "\u2588";
|
|
573
634
|
var BAR_EMPTY = "\u2591";
|
|
635
|
+
var SEVERITY_ICONS = {
|
|
636
|
+
critical: "\u{1F6D1}",
|
|
637
|
+
high: "\u26D4",
|
|
638
|
+
medium: "\u26A0\uFE0F",
|
|
639
|
+
low: "\u{1F41B}",
|
|
640
|
+
info: "\u2139\uFE0F"
|
|
641
|
+
};
|
|
642
|
+
function quickstartHelp(isTTY) {
|
|
643
|
+
const lines = [];
|
|
644
|
+
if (isTTY) {
|
|
645
|
+
lines.push("");
|
|
646
|
+
lines.push(chalk2.bold.cyan(" \u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E"));
|
|
647
|
+
lines.push(chalk2.bold.cyan(" \u2502") + chalk2.bold(" \u{1F6E1} ShipGuard \u2014 CLI-first release gate for AI-built apps ") + chalk2.bold.cyan(" \u2502"));
|
|
648
|
+
lines.push(chalk2.bold.cyan(" \u2502") + " Catches secrets, auth gaps, and deployment issues before you ship " + chalk2.bold.cyan(" \u2502"));
|
|
649
|
+
lines.push(chalk2.bold.cyan(" \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"));
|
|
650
|
+
lines.push("");
|
|
651
|
+
lines.push(chalk2.bold(" Get started in 2 commands:"));
|
|
652
|
+
lines.push("");
|
|
653
|
+
lines.push(` ${chalk2.green("npx @agenticcli/shipguard scan")} ${chalk2.dim("# zero install \u2014 scan right now")}`);
|
|
654
|
+
lines.push(` ${chalk2.green("shipguard scan --strict")} ${chalk2.dim("# CI mode: exit 1 on blocking issues")}`);
|
|
655
|
+
lines.push("");
|
|
656
|
+
lines.push(chalk2.bold(" Commands:"));
|
|
657
|
+
lines.push("");
|
|
658
|
+
lines.push(` ${chalk2.cyan("scan")} ${chalk2.dim("[path]")} Scan a project for high-risk issues`);
|
|
659
|
+
lines.push(` ${chalk2.cyan("init")} Generate a .shipguard.yml policy file`);
|
|
660
|
+
lines.push(` ${chalk2.cyan("login")} Authenticate to unlock Pro rules`);
|
|
661
|
+
lines.push(` ${chalk2.cyan("logout")} Remove saved credentials`);
|
|
662
|
+
lines.push(` ${chalk2.cyan("status")} Show auth status and credits`);
|
|
663
|
+
lines.push(` ${chalk2.cyan("feedback")} ${chalk2.dim("<text>")} Send feedback on your last scan`);
|
|
664
|
+
lines.push(` ${chalk2.cyan("rate")} ${chalk2.dim("<id> up|down")} Rate a rule finding`);
|
|
665
|
+
lines.push(` ${chalk2.cyan("help")} ${chalk2.dim("/ ?")} Show this screen`);
|
|
666
|
+
lines.push("");
|
|
667
|
+
lines.push(chalk2.bold(" Exit codes:"));
|
|
668
|
+
lines.push(` ${chalk2.green("0")} Safe \u2014 no blocking findings`);
|
|
669
|
+
lines.push(` ${chalk2.yellow("1")} Blocked \u2014 strict mode + blocking findings`);
|
|
670
|
+
lines.push(` ${chalk2.red("2")} Config error / degraded scan`);
|
|
671
|
+
lines.push(` ${chalk2.red("3")} Runtime error`);
|
|
672
|
+
lines.push("");
|
|
673
|
+
lines.push(` ${chalk2.dim("Docs")} ${chalk2.underline(DOCS_URL)}`);
|
|
674
|
+
lines.push(` ${chalk2.dim("Site")} ${chalk2.underline(SITE_URL)}`);
|
|
675
|
+
lines.push(` ${chalk2.dim("Pricing")} ${chalk2.underline(PRICING_URL)}`);
|
|
676
|
+
lines.push(` ${chalk2.dim("Issues")} ${chalk2.underline(ISSUES_URL)}`);
|
|
677
|
+
lines.push("");
|
|
678
|
+
} else {
|
|
679
|
+
lines.push("");
|
|
680
|
+
lines.push(" ShipGuard \u2014 CLI-first release gate for AI-built apps");
|
|
681
|
+
lines.push(" Catches secrets, auth gaps, and deployment issues before you ship");
|
|
682
|
+
lines.push("");
|
|
683
|
+
lines.push(" Get started in 2 commands:");
|
|
684
|
+
lines.push("");
|
|
685
|
+
lines.push(" npx @agenticcli/shipguard scan # zero install");
|
|
686
|
+
lines.push(" shipguard scan --strict # CI mode");
|
|
687
|
+
lines.push("");
|
|
688
|
+
lines.push(" Commands:");
|
|
689
|
+
lines.push(" scan [path] Scan a project");
|
|
690
|
+
lines.push(" init Generate policy file");
|
|
691
|
+
lines.push(" login Authenticate");
|
|
692
|
+
lines.push(" logout Remove credentials");
|
|
693
|
+
lines.push(" status Auth status + credits");
|
|
694
|
+
lines.push(" feedback <text> Send feedback");
|
|
695
|
+
lines.push(" rate <id> up|down Rate a finding");
|
|
696
|
+
lines.push(" help / ? Show this screen");
|
|
697
|
+
lines.push("");
|
|
698
|
+
lines.push(" Exit codes: 0=safe 1=blocked 2=config-error 3=runtime-error");
|
|
699
|
+
lines.push("");
|
|
700
|
+
lines.push(` Docs: ${DOCS_URL}`);
|
|
701
|
+
lines.push(` Site: ${SITE_URL}`);
|
|
702
|
+
lines.push(` Pricing: ${PRICING_URL}`);
|
|
703
|
+
lines.push(` Issues: ${ISSUES_URL}`);
|
|
704
|
+
lines.push("");
|
|
705
|
+
}
|
|
706
|
+
return lines.join("\n");
|
|
707
|
+
}
|
|
574
708
|
function findingFpLabel(confidence) {
|
|
575
709
|
switch (confidence) {
|
|
576
710
|
case "HIGH":
|
|
@@ -589,8 +723,8 @@ function renderProgressBar(current, total, width = 20, currentFile) {
|
|
|
589
723
|
const empty = width - filled;
|
|
590
724
|
const bar = chalk2.cyan(BAR_FULL.repeat(filled)) + chalk2.gray(BAR_EMPTY.repeat(empty));
|
|
591
725
|
const counter = `${current}/${total}`;
|
|
592
|
-
const fileHint = currentFile ? ` ${chalk2.dim(truncatePath(currentFile,
|
|
593
|
-
return `${chalk2.cyan("\
|
|
726
|
+
const fileHint = currentFile ? ` ${chalk2.dim(basename2(currentFile) || truncatePath(currentFile, 30))}` : "";
|
|
727
|
+
return `${chalk2.cyan("\u{1F50D}")} scanning [${bar}] ${chalk2.bold(counter)}${fileHint}`;
|
|
594
728
|
}
|
|
595
729
|
function shouldShowProgress(gates) {
|
|
596
730
|
return gates.isTTY && !gates.quiet && !gates.machineOutput;
|
|
@@ -602,13 +736,6 @@ var SEVERITY_COLORS = {
|
|
|
602
736
|
low: chalk2.blue,
|
|
603
737
|
info: chalk2.gray
|
|
604
738
|
};
|
|
605
|
-
var SEVERITY_ICONS = {
|
|
606
|
-
critical: "\u26D4",
|
|
607
|
-
high: "\u{1F534}",
|
|
608
|
-
medium: "\u{1F7E1}",
|
|
609
|
-
low: "\u{1F535}",
|
|
610
|
-
info: "\u26AA"
|
|
611
|
-
};
|
|
612
739
|
function renderFindingsSummary(findings) {
|
|
613
740
|
if (findings.length === 0) {
|
|
614
741
|
return chalk2.green(" \u2713 No findings detected \u2014 clean scan.");
|
|
@@ -624,7 +751,7 @@ function renderFindingsSummary(findings) {
|
|
|
624
751
|
const group = findings.filter((f) => f.severity === sev);
|
|
625
752
|
if (group.length === 0) continue;
|
|
626
753
|
const colorFn = SEVERITY_COLORS[sev] || chalk2.white;
|
|
627
|
-
const icon = SEVERITY_ICONS[sev]
|
|
754
|
+
const icon = SEVERITY_ICONS[sev] ?? "";
|
|
628
755
|
lines.push(` ${colorFn(` ${sev.toUpperCase().padEnd(8)} `)} ${icon} ${group.length} finding${group.length !== 1 ? "s" : ""}`);
|
|
629
756
|
for (const f of group) {
|
|
630
757
|
const location = f.line != null ? `${f.file}:${f.line}` : f.file;
|
|
@@ -666,18 +793,22 @@ var VERDICT_CONFIG = {
|
|
|
666
793
|
icon: "\u2705",
|
|
667
794
|
color: chalk2.greenBright,
|
|
668
795
|
label: "SAFE TO SHIP",
|
|
796
|
+
// Deterministic verdict message — no RNG so tests are stable
|
|
797
|
+
attitudeLine: () => chalk2.green(" SHIP IT \u2014 nothing blocking. Go make something people want."),
|
|
669
798
|
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
799
|
},
|
|
671
800
|
REVIEW_BEFORE_SHIP: {
|
|
672
801
|
icon: "\u26A0\uFE0F",
|
|
673
802
|
color: chalk2.yellowBright,
|
|
674
803
|
label: "REVIEW BEFORE SHIP",
|
|
804
|
+
attitudeLine: (blockingCount) => chalk2.yellow(` HOLD UP \u2014 ${blockingCount} finding${blockingCount !== 1 ? "s" : ""} want eyes before this ships.`),
|
|
675
805
|
helpLine: (blockingCount) => chalk2.yellow(` ${blockingCount} finding(s) need attention before shipping.`)
|
|
676
806
|
},
|
|
677
807
|
DO_NOT_SHIP: {
|
|
678
|
-
icon: "\
|
|
808
|
+
icon: "\u{1F6D1}",
|
|
679
809
|
color: chalk2.redBright,
|
|
680
810
|
label: "DO NOT SHIP",
|
|
811
|
+
attitudeLine: () => chalk2.red(" BLOCKED \u2014 shipping this would hurt. Fix the criticals first."),
|
|
681
812
|
helpLine: (blockingCount) => chalk2.red(` Blocked: ${blockingCount} critical/blocking issue(s) must be fixed first.`)
|
|
682
813
|
}
|
|
683
814
|
};
|
|
@@ -699,7 +830,33 @@ function boxBottom() {
|
|
|
699
830
|
function boxSection() {
|
|
700
831
|
return chalk2.dim(SECTION);
|
|
701
832
|
}
|
|
702
|
-
function
|
|
833
|
+
function severityBar(riskScore, barWidth = 30) {
|
|
834
|
+
const total = riskScore.totalFindings;
|
|
835
|
+
if (total === 0) return chalk2.green(" " + BAR_FULL.repeat(barWidth) + " all clear");
|
|
836
|
+
const counts = [
|
|
837
|
+
{ sev: "critical", count: riskScore.criticalCount, color: chalk2.bgRed.white },
|
|
838
|
+
{ sev: "high", count: riskScore.highCount, color: chalk2.red },
|
|
839
|
+
{ sev: "medium", count: riskScore.mediumCount, color: chalk2.yellow },
|
|
840
|
+
{ sev: "low", count: riskScore.lowCount, color: chalk2.blue },
|
|
841
|
+
{ sev: "info", count: riskScore.infoCount, color: chalk2.gray }
|
|
842
|
+
].filter((c) => c.count > 0);
|
|
843
|
+
let assigned = 0;
|
|
844
|
+
const segments = [];
|
|
845
|
+
for (let i = 0; i < counts.length; i++) {
|
|
846
|
+
const c = counts[i];
|
|
847
|
+
const w = i === counts.length - 1 ? barWidth - assigned : Math.max(1, Math.round(c.count / total * barWidth));
|
|
848
|
+
segments.push({ color: c.color, width: Math.min(w, barWidth - assigned), sev: c.sev });
|
|
849
|
+
assigned += segments[segments.length - 1].width;
|
|
850
|
+
if (assigned >= barWidth) break;
|
|
851
|
+
}
|
|
852
|
+
const bar = segments.map((s) => s.color(BAR_FULL.repeat(s.width))).join("");
|
|
853
|
+
const legend = counts.map((c) => {
|
|
854
|
+
const icon = SEVERITY_ICONS[c.sev] ?? "";
|
|
855
|
+
return `${icon}${c.count}`;
|
|
856
|
+
}).join(" ");
|
|
857
|
+
return ` ${bar} ${legend}`;
|
|
858
|
+
}
|
|
859
|
+
function verdictPanel(result, elapsedMs, skippedCount, topFindings) {
|
|
703
860
|
const { riskScore, filesScanned } = result;
|
|
704
861
|
const recommendation = riskScore.recommendation;
|
|
705
862
|
const cfg = VERDICT_CONFIG[recommendation];
|
|
@@ -711,6 +868,12 @@ function verdictPanel(result, elapsedMs, skippedCount) {
|
|
|
711
868
|
const verdictLabel = cfg.color(chalk2.bold(`${cfg.icon} ${cfg.label}`));
|
|
712
869
|
lines.push(boxLine(` ${verdictLabel}`));
|
|
713
870
|
lines.push(boxEmpty());
|
|
871
|
+
const attitudeLine2 = recommendation === "REVIEW_BEFORE_SHIP" ? cfg.attitudeLine(riskScore.blockingCount) : cfg.attitudeLine();
|
|
872
|
+
lines.push(boxLine(attitudeLine2));
|
|
873
|
+
lines.push(boxEmpty());
|
|
874
|
+
lines.push(boxSection());
|
|
875
|
+
lines.push(boxLine(chalk2.bold(" Severity breakdown")));
|
|
876
|
+
lines.push(boxLine(severityBar(riskScore)));
|
|
714
877
|
lines.push(boxSection());
|
|
715
878
|
lines.push(boxLine(chalk2.bold(" Run summary")));
|
|
716
879
|
const skippedSuffix = skippedCount && skippedCount > 0 ? chalk2.dim(` (${skippedCount} skipped)`) : "";
|
|
@@ -718,13 +881,13 @@ function verdictPanel(result, elapsedMs, skippedCount) {
|
|
|
718
881
|
lines.push(boxLine(` Elapsed time: ${chalk2.cyan(elapsedStr)}`));
|
|
719
882
|
lines.push(boxLine(` Total findings: ${chalk2.cyan(riskScore.totalFindings)}`));
|
|
720
883
|
const sevLines = [];
|
|
721
|
-
if (riskScore.criticalCount > 0) sevLines.push(chalk2.red(
|
|
722
|
-
if (riskScore.highCount > 0) sevLines.push(chalk2.red(
|
|
723
|
-
if (riskScore.mediumCount > 0) sevLines.push(chalk2.yellow(
|
|
724
|
-
if (riskScore.lowCount > 0) sevLines.push(chalk2.blue(
|
|
725
|
-
if (riskScore.infoCount > 0) sevLines.push(chalk2.gray(
|
|
884
|
+
if (riskScore.criticalCount > 0) sevLines.push(chalk2.red(`\u{1F6D1} ${riskScore.criticalCount} critical`));
|
|
885
|
+
if (riskScore.highCount > 0) sevLines.push(chalk2.red(`\u26D4 ${riskScore.highCount} high`));
|
|
886
|
+
if (riskScore.mediumCount > 0) sevLines.push(chalk2.yellow(`\u26A0\uFE0F ${riskScore.mediumCount} medium`));
|
|
887
|
+
if (riskScore.lowCount > 0) sevLines.push(chalk2.blue(`\u{1F41B} ${riskScore.lowCount} low`));
|
|
888
|
+
if (riskScore.infoCount > 0) sevLines.push(chalk2.gray(`\u2139\uFE0F ${riskScore.infoCount} info`));
|
|
726
889
|
if (sevLines.length > 0) {
|
|
727
|
-
lines.push(boxLine(`
|
|
890
|
+
lines.push(boxLine(` ${sevLines.join(" ")}`));
|
|
728
891
|
}
|
|
729
892
|
lines.push(boxSection());
|
|
730
893
|
lines.push(boxLine(chalk2.bold(" How ShipGuard helped")));
|
|
@@ -739,12 +902,35 @@ function verdictPanel(result, elapsedMs, skippedCount) {
|
|
|
739
902
|
lines.push("");
|
|
740
903
|
return lines.join("\n");
|
|
741
904
|
}
|
|
905
|
+
function actionFooter(opts) {
|
|
906
|
+
const { hasFindings, topRuleId, isLoggedIn } = opts;
|
|
907
|
+
const lines = [""];
|
|
908
|
+
lines.push(chalk2.bold(" \u2500\u2500 What now? \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
|
|
909
|
+
lines.push("");
|
|
910
|
+
lines.push(` ${chalk2.cyan("shipguard report")} ${chalk2.dim("# open the full report")}`);
|
|
911
|
+
if (hasFindings && topRuleId) {
|
|
912
|
+
lines.push(` ${chalk2.cyan(`shipguard rate ${topRuleId} up`)} ${chalk2.dim("# was this finding helpful?")}`);
|
|
913
|
+
lines.push(` ${chalk2.cyan(`shipguard rate ${topRuleId} down`)} ${chalk2.dim("# false positive?")}`);
|
|
914
|
+
} else if (hasFindings) {
|
|
915
|
+
lines.push(` ${chalk2.cyan("shipguard rate <ruleId> up")} ${chalk2.dim("# rate a finding")}`);
|
|
916
|
+
}
|
|
917
|
+
lines.push(` ${chalk2.cyan('shipguard feedback "<thoughts>"')} ${chalk2.dim("# what do you think?")}`);
|
|
918
|
+
if (!isLoggedIn) {
|
|
919
|
+
lines.push("");
|
|
920
|
+
lines.push(` ${chalk2.yellow("shipguard login")} ${chalk2.dim("# unlock Pro rules")}`);
|
|
921
|
+
lines.push(` ${chalk2.yellow("shipguard scan --pro")} ${chalk2.dim("# deeper checks after login")}`);
|
|
922
|
+
}
|
|
923
|
+
lines.push("");
|
|
924
|
+
lines.push(` ${chalk2.dim("Full docs: " + DOCS_URL)}`);
|
|
925
|
+
lines.push("");
|
|
926
|
+
return lines.join("\n");
|
|
927
|
+
}
|
|
742
928
|
function getShipguardConfigDir() {
|
|
743
|
-
return
|
|
929
|
+
return join4(homedir(), ".config", "shipguard");
|
|
744
930
|
}
|
|
745
931
|
function welcomeBanner(configDir) {
|
|
746
932
|
const dir = configDir ?? getShipguardConfigDir();
|
|
747
|
-
const marker =
|
|
933
|
+
const marker = join4(dir, ".welcomed");
|
|
748
934
|
if (existsSync2(marker)) {
|
|
749
935
|
return "";
|
|
750
936
|
}
|
|
@@ -776,6 +962,9 @@ function welcomeBanner(configDir) {
|
|
|
776
962
|
bannerLine(` ${chalk2.green("shipguard scan --json")} Machine-readable output for CI/agents`),
|
|
777
963
|
empty,
|
|
778
964
|
bannerLine(`Docs: ${chalk2.underline(DOCS_URL)}`),
|
|
965
|
+
empty,
|
|
966
|
+
bannerLine(chalk2.dim("Anonymous usage ping enabled \u2014 opt out: SHIPGUARD_TELEMETRY=0")),
|
|
967
|
+
bannerLine(chalk2.dim(`Details: ${chalk2.underline("agenticcli.dev/docs#telemetry")}`)),
|
|
779
968
|
bottom,
|
|
780
969
|
""
|
|
781
970
|
].join("\n");
|
|
@@ -857,6 +1046,36 @@ function displayWidth(str) {
|
|
|
857
1046
|
return width;
|
|
858
1047
|
}
|
|
859
1048
|
|
|
1049
|
+
// src/core/telemetry.ts
|
|
1050
|
+
function shouldSendTelemetry() {
|
|
1051
|
+
if (process.env.SHIPGUARD_TELEMETRY === "0") return false;
|
|
1052
|
+
if (process.env.DO_NOT_TRACK === "1") return false;
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
function buildPayload(input) {
|
|
1056
|
+
const { cliVersion, verdict, durationMs, ci, rulePackCount } = input;
|
|
1057
|
+
return { cliVersion, verdict, durationMs, ci, rulePackCount };
|
|
1058
|
+
}
|
|
1059
|
+
function sendTelemetry(payload) {
|
|
1060
|
+
if (!shouldSendTelemetry()) return;
|
|
1061
|
+
const endpoint = process.env.SHIPGUARD_TELEMETRY_URL ?? "https://cheery-toucan-348.convex.site/cli-telemetry";
|
|
1062
|
+
const body = JSON.stringify(buildPayload(payload));
|
|
1063
|
+
const controller = new AbortController();
|
|
1064
|
+
const timeout = setTimeout(() => controller.abort(), 1e3);
|
|
1065
|
+
fetch(endpoint, {
|
|
1066
|
+
method: "POST",
|
|
1067
|
+
headers: { "Content-Type": "application/json" },
|
|
1068
|
+
body,
|
|
1069
|
+
signal: controller.signal
|
|
1070
|
+
}).catch(() => {
|
|
1071
|
+
if (process.env.SHIPGUARD_DEBUG) {
|
|
1072
|
+
console.debug("[shipguard:telemetry] ping failed (silent)");
|
|
1073
|
+
}
|
|
1074
|
+
}).finally(() => {
|
|
1075
|
+
clearTimeout(timeout);
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
|
|
860
1079
|
// src/commands/scan.ts
|
|
861
1080
|
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";
|
|
862
1081
|
function resolveExitCode(opts) {
|
|
@@ -869,7 +1088,7 @@ function resolveExitCode(opts) {
|
|
|
869
1088
|
return EXIT_CODES.SAFE;
|
|
870
1089
|
}
|
|
871
1090
|
function isProjectRoot(dir) {
|
|
872
|
-
return existsSync3(
|
|
1091
|
+
return existsSync3(join5(dir, "package.json")) || existsSync3(join5(dir, ".git"));
|
|
873
1092
|
}
|
|
874
1093
|
function scanCommand() {
|
|
875
1094
|
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", `
|
|
@@ -964,7 +1183,7 @@ async function runScan(ctx) {
|
|
|
964
1183
|
}
|
|
965
1184
|
try {
|
|
966
1185
|
const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
|
|
967
|
-
const { fetchProRules } = await import("./pro-scanner-
|
|
1186
|
+
const { fetchProRules } = await import("./pro-scanner-IJJLUSAC.js");
|
|
968
1187
|
const { hasConfig, generateConfig } = await import("./config-generator-YSWNA53I.js");
|
|
969
1188
|
const detectedResult = detectFrameworks(cwd);
|
|
970
1189
|
const { frameworks } = detectedResult;
|
|
@@ -1095,15 +1314,23 @@ async function runScan(ctx) {
|
|
|
1095
1314
|
}
|
|
1096
1315
|
console.log(coverageLine());
|
|
1097
1316
|
console.log("");
|
|
1098
|
-
console.log(verdictPanel(result, elapsedMs, skippedTooLarge + skippedBinary));
|
|
1317
|
+
console.log(verdictPanel(result, elapsedMs, skippedTooLarge + skippedBinary, result.findings));
|
|
1318
|
+
const topRuleId = result.findings.length > 0 ? result.findings[0].id : void 0;
|
|
1319
|
+
const isLoggedIn = Boolean(opts.pro && !degraded);
|
|
1320
|
+
console.log(actionFooter({
|
|
1321
|
+
hasFindings: result.findings.length > 0,
|
|
1322
|
+
topRuleId,
|
|
1323
|
+
isLoggedIn
|
|
1324
|
+
}));
|
|
1099
1325
|
}
|
|
1100
1326
|
const shouldReport = scanOptions.generateReport || policy.scan.generate_report;
|
|
1101
1327
|
if (shouldReport) {
|
|
1102
1328
|
const reportPath = scanOptions.reportPath;
|
|
1329
|
+
const reportElapsedMs = Date.now() - startTime;
|
|
1103
1330
|
try {
|
|
1104
|
-
await generateReport(result, reportPath);
|
|
1331
|
+
const paths = await generateReport(result, reportPath, reportElapsedMs);
|
|
1105
1332
|
if (!machineOutput && !quiet) {
|
|
1106
|
-
logger.success(`Report
|
|
1333
|
+
logger.success(`Report: ${paths.mdPath} \xB7 agent view: ${paths.jsonPath}`);
|
|
1107
1334
|
}
|
|
1108
1335
|
} catch (error) {
|
|
1109
1336
|
logger.error(`Report generation failed: ${error instanceof Error ? error.message : error}`);
|
|
@@ -1131,6 +1358,28 @@ async function runScan(ctx) {
|
|
|
1131
1358
|
}).catch(() => {
|
|
1132
1359
|
});
|
|
1133
1360
|
}
|
|
1361
|
+
try {
|
|
1362
|
+
const elapsedMs = Date.now() - startTime;
|
|
1363
|
+
const exitCode2 = resolveExitCode({
|
|
1364
|
+
strict: scanOptions.strict,
|
|
1365
|
+
blockingCount: result.riskScore.blockingCount,
|
|
1366
|
+
degraded: Boolean(result.degraded)
|
|
1367
|
+
});
|
|
1368
|
+
const verdictMap = {
|
|
1369
|
+
[EXIT_CODES.SAFE]: "safe",
|
|
1370
|
+
[EXIT_CODES.BLOCKED]: "blocked",
|
|
1371
|
+
[EXIT_CODES.CONFIG_ERROR]: "review",
|
|
1372
|
+
[EXIT_CODES.RUNTIME_ERROR]: "error"
|
|
1373
|
+
};
|
|
1374
|
+
sendTelemetry({
|
|
1375
|
+
cliVersion: "0.1.2",
|
|
1376
|
+
verdict: verdictMap[exitCode2] ?? "error",
|
|
1377
|
+
durationMs: elapsedMs,
|
|
1378
|
+
ci: Boolean(process.env.CI),
|
|
1379
|
+
rulePackCount: proRules ? 1 : 0
|
|
1380
|
+
});
|
|
1381
|
+
} catch {
|
|
1382
|
+
}
|
|
1134
1383
|
const exitCode = resolveExitCode({
|
|
1135
1384
|
strict: scanOptions.strict,
|
|
1136
1385
|
blockingCount: result.riskScore.blockingCount,
|
|
@@ -1321,9 +1570,9 @@ function rateCommand() {
|
|
|
1321
1570
|
}
|
|
1322
1571
|
|
|
1323
1572
|
// src/handlers.ts
|
|
1324
|
-
var
|
|
1573
|
+
var ISSUES_URL2 = "https://github.com/ramxH3421/agentic-cli/issues";
|
|
1325
1574
|
var DOCS_URL2 = "https://agenticcli.dev/docs";
|
|
1326
|
-
var REPORT_LINE = `Report this: ${
|
|
1575
|
+
var REPORT_LINE = `Report this: ${ISSUES_URL2} \xB7 Docs: ${DOCS_URL2}`;
|
|
1327
1576
|
function handleUncaughtException(error) {
|
|
1328
1577
|
const message = error instanceof Error ? error.message : String(error);
|
|
1329
1578
|
console.error(`\x1B[31m\u2717\x1B[0m Unexpected error: ${message}`);
|
|
@@ -1352,14 +1601,21 @@ process.on("uncaughtException", handleUncaughtException);
|
|
|
1352
1601
|
process.on("unhandledRejection", handleUnhandledRejection);
|
|
1353
1602
|
process.on("SIGINT", handleSignal);
|
|
1354
1603
|
process.on("SIGTERM", handleSignal);
|
|
1355
|
-
var
|
|
1604
|
+
var ISSUES_URL3 = "https://github.com/ramxH3421/agentic-cli/issues";
|
|
1356
1605
|
var program = new Command7();
|
|
1357
|
-
|
|
1606
|
+
var rawArgs = process.argv.slice(2);
|
|
1607
|
+
if (rawArgs[0] === "?") {
|
|
1608
|
+
process.argv = [process.argv[0], process.argv[1], "help"];
|
|
1609
|
+
}
|
|
1610
|
+
program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
|
|
1611
|
+
true ? "0.2.0" : process.env.npm_package_version ?? "0.0.0-dev"
|
|
1612
|
+
).helpCommand(false).addHelpText("after", `
|
|
1358
1613
|
Learn more:
|
|
1359
1614
|
Docs https://agenticcli.dev/docs
|
|
1360
1615
|
Site https://agenticcli.dev
|
|
1361
1616
|
Pricing https://agenticcli.dev/pricing
|
|
1362
|
-
Issues ${
|
|
1617
|
+
Issues ${ISSUES_URL3}`);
|
|
1618
|
+
program.exitOverride();
|
|
1363
1619
|
program.addCommand(initCommand());
|
|
1364
1620
|
program.addCommand(scanCommand());
|
|
1365
1621
|
program.addCommand(loginCommand());
|
|
@@ -1367,7 +1623,84 @@ program.addCommand(logoutCommand());
|
|
|
1367
1623
|
program.addCommand(statusCommand());
|
|
1368
1624
|
program.addCommand(feedbackCommand());
|
|
1369
1625
|
program.addCommand(rateCommand());
|
|
1370
|
-
program.
|
|
1626
|
+
program.addCommand(
|
|
1627
|
+
new Command7("help").description("Show the quickstart guide").action(() => {
|
|
1628
|
+
const isTTY = Boolean(process.stdout.isTTY);
|
|
1629
|
+
process.stdout.write(quickstartHelp(isTTY) + "\n");
|
|
1630
|
+
})
|
|
1631
|
+
);
|
|
1632
|
+
program.allowExcessArguments(true);
|
|
1633
|
+
program.action(() => {
|
|
1634
|
+
const isTTY = Boolean(process.stdout.isTTY);
|
|
1635
|
+
process.stdout.write(quickstartHelp(isTTY) + "\n");
|
|
1636
|
+
});
|
|
1637
|
+
function levenshtein(a, b) {
|
|
1638
|
+
const m = a.length;
|
|
1639
|
+
const n = b.length;
|
|
1640
|
+
const dp = Array.from(
|
|
1641
|
+
{ length: m + 1 },
|
|
1642
|
+
(_, i) => Array.from({ length: n + 1 }, (_2, j) => i === 0 ? j : j === 0 ? i : 0)
|
|
1643
|
+
);
|
|
1644
|
+
for (let i = 1; i <= m; i++) {
|
|
1645
|
+
for (let j = 1; j <= n; j++) {
|
|
1646
|
+
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return dp[m][n];
|
|
1650
|
+
}
|
|
1651
|
+
function closestCommand(input) {
|
|
1652
|
+
const names = ["scan", "init", "login", "logout", "status", "feedback", "rate", "help"];
|
|
1653
|
+
let best;
|
|
1654
|
+
let bestDist = Infinity;
|
|
1655
|
+
for (const name of names) {
|
|
1656
|
+
const d = levenshtein(input.toLowerCase(), name);
|
|
1657
|
+
if (d < bestDist) {
|
|
1658
|
+
bestDist = d;
|
|
1659
|
+
best = name;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
return bestDist <= 3 ? best : void 0;
|
|
1663
|
+
}
|
|
1664
|
+
(async () => {
|
|
1665
|
+
const KNOWN_COMMANDS = /* @__PURE__ */ new Set(["scan", "init", "login", "logout", "status", "feedback", "rate", "help"]);
|
|
1666
|
+
const firstNonFlag = process.argv.slice(2).find((a) => !a.startsWith("-"));
|
|
1667
|
+
if (firstNonFlag && firstNonFlag !== "?" && !KNOWN_COMMANDS.has(firstNonFlag)) {
|
|
1668
|
+
const suggestion = closestCommand(firstNonFlag);
|
|
1669
|
+
const hint = suggestion ? `
|
|
1670
|
+
Did you mean \`shipguard ${suggestion}\`?` : "";
|
|
1671
|
+
process.stderr.write(
|
|
1672
|
+
`shipguard: unknown command "${firstNonFlag}"${hint}
|
|
1673
|
+
Run \`shipguard help\` to see available commands.
|
|
1674
|
+
`
|
|
1675
|
+
);
|
|
1676
|
+
process.exit(2);
|
|
1677
|
+
}
|
|
1678
|
+
try {
|
|
1679
|
+
await program.parseAsync(process.argv);
|
|
1680
|
+
} catch (err) {
|
|
1681
|
+
if (err instanceof CommanderError) {
|
|
1682
|
+
if (err.code === "commander.unknownCommand") {
|
|
1683
|
+
const unknownToken = process.argv.slice(2).find((a) => !a.startsWith("-")) ?? "?";
|
|
1684
|
+
const suggestion = closestCommand(unknownToken);
|
|
1685
|
+
const hint = suggestion ? `
|
|
1686
|
+
Did you mean \`shipguard ${suggestion}\`?` : "";
|
|
1687
|
+
process.stderr.write(
|
|
1688
|
+
`shipguard: unknown command "${unknownToken}"${hint}
|
|
1689
|
+
Run \`shipguard help\` to see available commands.
|
|
1690
|
+
`
|
|
1691
|
+
);
|
|
1692
|
+
process.exit(2);
|
|
1693
|
+
}
|
|
1694
|
+
if (err.exitCode === 0) {
|
|
1695
|
+
process.exit(0);
|
|
1696
|
+
}
|
|
1697
|
+
process.stderr.write(`shipguard: ${err.message}
|
|
1698
|
+
`);
|
|
1699
|
+
process.exit(2);
|
|
1700
|
+
}
|
|
1701
|
+
throw err;
|
|
1702
|
+
}
|
|
1703
|
+
})();
|
|
1371
1704
|
export {
|
|
1372
1705
|
handleSignal,
|
|
1373
1706
|
handleUncaughtException,
|