@agenticcli/shipguard 0.3.0 → 0.4.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"secrets": "
|
|
3
|
-
"auth": "
|
|
4
|
-
"database": "
|
|
5
|
-
"deployment": "
|
|
6
|
-
"payments": "
|
|
2
|
+
"secrets": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
|
|
3
|
+
"auth": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
|
|
4
|
+
"database": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
|
|
5
|
+
"deployment": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
|
|
6
|
+
"payments": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8"
|
|
7
7
|
}
|
|
@@ -101,8 +101,69 @@ function clearCredentials() {
|
|
|
101
101
|
function isTokenExpired(creds) {
|
|
102
102
|
return creds.expiresAt < Date.now();
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
var DEFAULT_API_URL = "https://agenticcli.dev";
|
|
105
|
+
var cachedExchangedToken = null;
|
|
106
|
+
async function exchangeApiKeyForToken(apiKey, apiUrl) {
|
|
107
|
+
assertTrustedApiUrl(apiUrl);
|
|
108
|
+
let res;
|
|
109
|
+
try {
|
|
110
|
+
res = await fetch(`${apiUrl}/api/agent/exchange`, {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { Authorization: `Bearer ${apiKey}` }
|
|
113
|
+
});
|
|
114
|
+
} catch (err) {
|
|
115
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
116
|
+
console.error(`[shipguard] SHIPGUARD_API_KEY exchange request to ${apiUrl} failed: ${msg}`);
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Could not reach ${apiUrl}/api/agent/exchange to exchange SHIPGUARD_API_KEY: ${msg}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (res.status === 401) {
|
|
122
|
+
console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 invalid or revoked key");
|
|
123
|
+
throw new Error(
|
|
124
|
+
"SHIPGUARD_API_KEY is invalid or has been revoked. Check the key value or generate a new one at https://agenticcli.dev/dashboard."
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (res.status === 402) {
|
|
128
|
+
console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 monthly budget exhausted");
|
|
129
|
+
throw new Error(
|
|
130
|
+
"SHIPGUARD_API_KEY has exhausted its monthly credit budget. Buy more at https://agenticcli.dev/dashboard/billing"
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (!res.ok) {
|
|
134
|
+
let detail = res.statusText;
|
|
135
|
+
try {
|
|
136
|
+
const body2 = await res.json();
|
|
137
|
+
detail = body2?.error_description ?? body2?.error ?? detail;
|
|
138
|
+
} catch {
|
|
139
|
+
}
|
|
140
|
+
console.error(`[shipguard] SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
|
|
141
|
+
throw new Error(`SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
|
|
142
|
+
}
|
|
143
|
+
const body = await res.json();
|
|
144
|
+
if (!body.access_token) {
|
|
145
|
+
console.error("[shipguard] SHIPGUARD_API_KEY exchange returned 200 with no access_token");
|
|
146
|
+
throw new Error("SHIPGUARD_API_KEY exchange succeeded but the server returned no access_token.");
|
|
147
|
+
}
|
|
148
|
+
cachedExchangedToken = {
|
|
149
|
+
apiKey,
|
|
150
|
+
apiUrl,
|
|
151
|
+
accessToken: body.access_token,
|
|
152
|
+
// Refresh 30s ahead of actual expiry so a long-running scan never races a
|
|
153
|
+
// mid-request expiry against the server's 15-minute access-token TTL.
|
|
154
|
+
expiresAt: Date.now() + (body.expires_in ?? 900) * 1e3 - 3e4
|
|
155
|
+
};
|
|
156
|
+
return body.access_token;
|
|
157
|
+
}
|
|
158
|
+
async function getAuthToken(apiUrl) {
|
|
159
|
+
const apiKey = process.env.SHIPGUARD_API_KEY;
|
|
160
|
+
if (apiKey) {
|
|
161
|
+
const targetApiUrl = apiUrl ?? loadCredentials()?.apiUrl ?? DEFAULT_API_URL;
|
|
162
|
+
if (cachedExchangedToken && cachedExchangedToken.apiKey === apiKey && cachedExchangedToken.apiUrl === targetApiUrl && Date.now() < cachedExchangedToken.expiresAt) {
|
|
163
|
+
return cachedExchangedToken.accessToken;
|
|
164
|
+
}
|
|
165
|
+
return exchangeApiKeyForToken(apiKey, targetApiUrl);
|
|
166
|
+
}
|
|
106
167
|
const creds = loadCredentials();
|
|
107
168
|
if (!creds) return null;
|
|
108
169
|
if (!isTokenExpired(creds)) return creds.accessToken;
|
|
@@ -2809,9 +2870,16 @@ function applySuppressions(findings, files) {
|
|
|
2809
2870
|
import { RE2JS as RE2JS2 } from "re2js";
|
|
2810
2871
|
var activeExecutor = re2jsV1Executor;
|
|
2811
2872
|
var DEFAULT_FLOOR_PATH = path2.join(os.homedir(), ".shipguard", "release-floor.json");
|
|
2873
|
+
var NoRulesAppliedError = class extends Error {
|
|
2874
|
+
code = "NO_RULES_APPLIED";
|
|
2875
|
+
constructor(message) {
|
|
2876
|
+
super(message);
|
|
2877
|
+
this.name = "NoRulesAppliedError";
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2812
2880
|
async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath) {
|
|
2813
2881
|
assertTrustedApiUrl(apiUrl);
|
|
2814
|
-
const token = await getAuthToken();
|
|
2882
|
+
const token = await getAuthToken(apiUrl);
|
|
2815
2883
|
if (!token) throw new Error("Not authenticated. Run `shipguard login` first.");
|
|
2816
2884
|
const res = await fetch(`${apiUrl}/api/rules/fetch`, {
|
|
2817
2885
|
method: "POST",
|
|
@@ -2823,6 +2891,21 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
2823
2891
|
});
|
|
2824
2892
|
if (res.status === 401) throw new Error("Auth expired. Run `shipguard login` again.");
|
|
2825
2893
|
if (res.status === 402) throw new Error("No credits. Buy at https://agenticcli.dev/dashboard/billing");
|
|
2894
|
+
if (res.status === 422) {
|
|
2895
|
+
let detail = res.statusText;
|
|
2896
|
+
try {
|
|
2897
|
+
const body = await res.json();
|
|
2898
|
+
if (body?.code === "NO_RULES_APPLIED") {
|
|
2899
|
+
throw new NoRulesAppliedError(
|
|
2900
|
+
body.error ?? "Pro rule fetch resolved zero rules \u2014 the scan checked nothing (fail-closed). This is NOT a clean pass."
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
detail = body?.error ?? detail;
|
|
2904
|
+
} catch (err) {
|
|
2905
|
+
if (err instanceof NoRulesAppliedError) throw err;
|
|
2906
|
+
}
|
|
2907
|
+
throw new Error(`Rule fetch failed (422): ${detail}`);
|
|
2908
|
+
}
|
|
2826
2909
|
if (!res.ok) throw new Error(`Rule fetch failed: ${res.statusText}`);
|
|
2827
2910
|
const credits = parseInt(res.headers.get("X-Credits-Remaining") ?? "0", 10);
|
|
2828
2911
|
const rulesVersion = res.headers.get("X-Rules-Version") ?? void 0;
|
|
@@ -3135,6 +3218,7 @@ export {
|
|
|
3135
3218
|
getAuthToken,
|
|
3136
3219
|
loadChecksumManifest,
|
|
3137
3220
|
applySuppressions,
|
|
3221
|
+
NoRulesAppliedError,
|
|
3138
3222
|
fetchProRules,
|
|
3139
3223
|
validateBundleCompile,
|
|
3140
3224
|
RunProRulesFatalError,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.4.1",
|
|
3
|
+
"packageName": "@agenticcli/shipguard",
|
|
4
|
+
"nodeEngine": ">=20",
|
|
5
|
+
"exitCodes": {
|
|
6
|
+
"SAFE": 0,
|
|
7
|
+
"BLOCKED": 1,
|
|
8
|
+
"CONFIG_ERROR": 2,
|
|
9
|
+
"RUNTIME_ERROR": 3
|
|
10
|
+
},
|
|
11
|
+
"freeModules": [
|
|
12
|
+
"secrets",
|
|
13
|
+
"auth",
|
|
14
|
+
"database",
|
|
15
|
+
"payments",
|
|
16
|
+
"deployment"
|
|
17
|
+
],
|
|
18
|
+
"freeRuleIds": [
|
|
19
|
+
"hardcoded_secret",
|
|
20
|
+
"secrets",
|
|
21
|
+
"exposed_env",
|
|
22
|
+
"auth",
|
|
23
|
+
"public_admin_route",
|
|
24
|
+
"auth_route_without_guard",
|
|
25
|
+
"db-drop-table",
|
|
26
|
+
"db-drop-column",
|
|
27
|
+
"db-truncate",
|
|
28
|
+
"db-delete-without-where",
|
|
29
|
+
"db-alter-drop",
|
|
30
|
+
"db-push-in-scripts",
|
|
31
|
+
"db-schema-without-migration",
|
|
32
|
+
"database",
|
|
33
|
+
"payments",
|
|
34
|
+
"payment_webhook_without_signature_check",
|
|
35
|
+
"missing_idempotency",
|
|
36
|
+
"missing_error_handling",
|
|
37
|
+
"deployment",
|
|
38
|
+
"deployment_cors_wildcard",
|
|
39
|
+
"deployment_source_maps_exposed",
|
|
40
|
+
"deployment_missing_x_frame_options",
|
|
41
|
+
"deployment_missing_x_content_type",
|
|
42
|
+
"deployment_docker_root_user",
|
|
43
|
+
"deployment_docker_unpinned_image",
|
|
44
|
+
"deployment_compose_unpinned_image",
|
|
45
|
+
"deployment_vercel_broad_rewrite",
|
|
46
|
+
"deployment_vercel_missing_headers",
|
|
47
|
+
"deployment_netlify_missing_headers",
|
|
48
|
+
"deployment_missing_env_example",
|
|
49
|
+
"deployment_env_undocumented_keys",
|
|
50
|
+
"deployment_config_cors_wildcard_origin",
|
|
51
|
+
"deployment_config_debug_mode"
|
|
52
|
+
],
|
|
53
|
+
"freeRuleCount": 33,
|
|
54
|
+
"jsonSchemaFields": [
|
|
55
|
+
"findings",
|
|
56
|
+
"riskScore",
|
|
57
|
+
"filesScanned",
|
|
58
|
+
"timestamp",
|
|
59
|
+
"policyUsed",
|
|
60
|
+
"recommendation",
|
|
61
|
+
"rulesApplied",
|
|
62
|
+
"rulesBreakdown",
|
|
63
|
+
"schemaVersion",
|
|
64
|
+
"degraded",
|
|
65
|
+
"degradedReasons",
|
|
66
|
+
"creditsWarning",
|
|
67
|
+
"rulesVersion",
|
|
68
|
+
"aiCodeIssues"
|
|
69
|
+
],
|
|
70
|
+
"schemaVersion": "0.4",
|
|
71
|
+
"degradeCodes": [
|
|
72
|
+
"FILE_TOO_LARGE",
|
|
73
|
+
"OUTPUT_TRUNCATED",
|
|
74
|
+
"CODEREF_SKIPPED",
|
|
75
|
+
"PRO_RULES_UNAVAILABLE",
|
|
76
|
+
"INVALID_UTF8",
|
|
77
|
+
"UNREADABLE_FILE",
|
|
78
|
+
"COMPILE_FAILURE"
|
|
79
|
+
],
|
|
80
|
+
"severities": [
|
|
81
|
+
"info",
|
|
82
|
+
"low",
|
|
83
|
+
"medium",
|
|
84
|
+
"high",
|
|
85
|
+
"critical"
|
|
86
|
+
],
|
|
87
|
+
"categories": [
|
|
88
|
+
"secrets",
|
|
89
|
+
"auth",
|
|
90
|
+
"payments",
|
|
91
|
+
"database",
|
|
92
|
+
"deployment",
|
|
93
|
+
"injection",
|
|
94
|
+
"supply-chain",
|
|
95
|
+
"crypto",
|
|
96
|
+
"config"
|
|
97
|
+
],
|
|
98
|
+
"installSnippet": "npx @agenticcli/shipguard scan --changed --strict --json",
|
|
99
|
+
"re2Engine": true,
|
|
100
|
+
"generatedAt": "2026-07-06T13:46:08.246Z"
|
|
101
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
runProRulesWithDispatch,
|
|
15
15
|
saveCredentials,
|
|
16
16
|
secretsCheck
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-5UMQEPDN.js";
|
|
18
18
|
import {
|
|
19
19
|
DEFAULT_MAX_FILES,
|
|
20
20
|
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
@@ -1176,7 +1176,7 @@ function sendTelemetry(payload) {
|
|
|
1176
1176
|
|
|
1177
1177
|
// src/commands/scan.ts
|
|
1178
1178
|
var LEARN_MORE = "Docs https://agenticcli.dev/docs \xB7 Site https://agenticcli.dev \xB7 Pricing https://agenticcli.dev/pricing \xB7 Issues https://github.com/agenticcli/shipguard/issues";
|
|
1179
|
-
var CLI_VERSION = true ? "0.
|
|
1179
|
+
var CLI_VERSION = true ? "0.4.1" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
1180
1180
|
function resolveExitCode(opts) {
|
|
1181
1181
|
if (opts.strict && opts.blockingCount > 0) {
|
|
1182
1182
|
return EXIT_CODES.BLOCKED;
|
|
@@ -1283,7 +1283,7 @@ async function runScan(ctx) {
|
|
|
1283
1283
|
}
|
|
1284
1284
|
try {
|
|
1285
1285
|
const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
|
|
1286
|
-
const { fetchProRules } = await import("./pro-scanner-
|
|
1286
|
+
const { fetchProRules } = await import("./pro-scanner-HI5OGQYR.js");
|
|
1287
1287
|
const { hasConfig, generateConfig } = await import("./config-generator-RMWNQQHW.js");
|
|
1288
1288
|
const detectedResult = detectFrameworks(cwd);
|
|
1289
1289
|
const { frameworks } = detectedResult;
|
|
@@ -1319,6 +1319,16 @@ async function runScan(ctx) {
|
|
|
1319
1319
|
}
|
|
1320
1320
|
} catch (err) {
|
|
1321
1321
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
1322
|
+
const isNoRulesApplied = err instanceof Error && err.name === "NoRulesAppliedError" || err?.code === "NO_RULES_APPLIED";
|
|
1323
|
+
if (isNoRulesApplied) {
|
|
1324
|
+
if (!machineOutput) {
|
|
1325
|
+
logger.error(`Pro rules unavailable (fail-closed): ${errMsg}`);
|
|
1326
|
+
logger.error("This scan applied ZERO rules \u2014 it checked nothing. Refusing to report a clean pass.");
|
|
1327
|
+
} else {
|
|
1328
|
+
console.log(JSON.stringify({ error: errMsg, code: "NO_RULES_APPLIED" }));
|
|
1329
|
+
}
|
|
1330
|
+
process.exit(EXIT_CODES.RUNTIME_ERROR);
|
|
1331
|
+
}
|
|
1322
1332
|
logger.warn(`Pro rules unavailable: ${errMsg}`);
|
|
1323
1333
|
logger.warn("Degrading to free scan \u2014 pro rules will not be applied");
|
|
1324
1334
|
degraded = true;
|
|
@@ -1617,9 +1627,16 @@ function statusCommand() {
|
|
|
1617
1627
|
import { Command as Command6 } from "commander";
|
|
1618
1628
|
function feedbackCommand() {
|
|
1619
1629
|
return new Command6("feedback").description("Send feedback about your last scan").argument("<text>", "Your feedback text").action(async (text) => {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1630
|
+
let token;
|
|
1631
|
+
try {
|
|
1632
|
+
const t = await getAuthToken();
|
|
1633
|
+
if (!t) {
|
|
1634
|
+
logger.error("Not authenticated. Run `shipguard login` first.");
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
token = t;
|
|
1638
|
+
} catch (err) {
|
|
1639
|
+
logger.error(`Authentication failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1623
1640
|
return;
|
|
1624
1641
|
}
|
|
1625
1642
|
const creds = loadCredentials();
|
|
@@ -1659,9 +1676,16 @@ function rateCommand() {
|
|
|
1659
1676
|
logger.error('Rating must be "helpful" or "not-helpful".');
|
|
1660
1677
|
return;
|
|
1661
1678
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1679
|
+
let token;
|
|
1680
|
+
try {
|
|
1681
|
+
const t = await getAuthToken();
|
|
1682
|
+
if (!t) {
|
|
1683
|
+
logger.error("Not authenticated. Run `shipguard login` first.");
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
token = t;
|
|
1687
|
+
} catch (err) {
|
|
1688
|
+
logger.error(`Authentication failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1665
1689
|
return;
|
|
1666
1690
|
}
|
|
1667
1691
|
const creds = loadCredentials();
|
|
@@ -1732,7 +1756,7 @@ if (rawArgs[0] === "?") {
|
|
|
1732
1756
|
process.argv = [process.argv[0], process.argv[1], "help"];
|
|
1733
1757
|
}
|
|
1734
1758
|
program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
|
|
1735
|
-
true ? "0.
|
|
1759
|
+
true ? "0.4.1" : process.env.npm_package_version ?? "0.0.0-dev"
|
|
1736
1760
|
).helpCommand(false).addHelpText("after", `
|
|
1737
1761
|
Learn more:
|
|
1738
1762
|
Docs https://agenticcli.dev/docs
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NoRulesAppliedError,
|
|
2
3
|
RunProRulesFatalError,
|
|
3
4
|
fetchProRules,
|
|
4
5
|
runProRules,
|
|
5
6
|
runProRulesWithDispatch,
|
|
6
7
|
validateBundleCompile
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5UMQEPDN.js";
|
|
8
9
|
import "./chunk-ANTCYKRO.js";
|
|
9
10
|
export {
|
|
11
|
+
NoRulesAppliedError,
|
|
10
12
|
RunProRulesFatalError,
|
|
11
13
|
fetchProRules,
|
|
12
14
|
runProRules,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticcli/shipguard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "CLI-first release gate for AI-built apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cli.js",
|
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
"docs",
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup",
|
|
18
|
+
"dev": "tsup --watch",
|
|
19
|
+
"lint": "eslint src --ext .ts",
|
|
20
|
+
"prepublishOnly": "bash \"$(git rev-parse --show-toplevel)/scripts/release-gate.sh\"",
|
|
21
|
+
"test": "vitest run",
|
|
22
|
+
"test:watch": "vitest",
|
|
23
|
+
"clean": "rm -rf dist"
|
|
24
|
+
},
|
|
16
25
|
"dependencies": {
|
|
17
26
|
"@noble/hashes": "^2.2.0",
|
|
18
27
|
"chalk": "^5.4.0",
|
|
@@ -24,15 +33,15 @@
|
|
|
24
33
|
"yaml": "^2.7.0"
|
|
25
34
|
},
|
|
26
35
|
"devDependencies": {
|
|
36
|
+
"@agenticcli/matcher-contract": "workspace:*",
|
|
37
|
+
"@agenticcli/shared": "workspace:*",
|
|
27
38
|
"@types/node": "^22.0.0",
|
|
28
39
|
"@typescript-eslint/eslint-plugin": "^7",
|
|
29
40
|
"@typescript-eslint/parser": "^7",
|
|
30
41
|
"eslint": "^8",
|
|
31
42
|
"tsup": "^8.5.1",
|
|
32
43
|
"typescript": "^5.8.0",
|
|
33
|
-
"vitest": "^3.2.0"
|
|
34
|
-
"@agenticcli/matcher-contract": "0.5.0",
|
|
35
|
-
"@agenticcli/shared": "0.1.0"
|
|
44
|
+
"vitest": "^3.2.0"
|
|
36
45
|
},
|
|
37
46
|
"keywords": [
|
|
38
47
|
"shipguard",
|
|
@@ -65,13 +74,5 @@
|
|
|
65
74
|
},
|
|
66
75
|
"publishConfig": {
|
|
67
76
|
"access": "public"
|
|
68
|
-
},
|
|
69
|
-
"scripts": {
|
|
70
|
-
"build": "tsup",
|
|
71
|
-
"dev": "tsup --watch",
|
|
72
|
-
"lint": "eslint src --ext .ts",
|
|
73
|
-
"test": "vitest run",
|
|
74
|
-
"test:watch": "vitest",
|
|
75
|
-
"clean": "rm -rf dist"
|
|
76
77
|
}
|
|
77
|
-
}
|
|
78
|
+
}
|