@agenticcli/shipguard 0.2.1 → 0.3.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/dist/cli.js CHANGED
@@ -1,24 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  applySuppressions,
4
+ assertTrustedApiUrl,
4
5
  authCheck,
5
6
  clearCredentials,
6
7
  databaseCheck,
7
8
  deploymentCheck,
8
9
  getAuthToken,
9
10
  isTokenExpired,
11
+ loadChecksumManifest,
10
12
  loadCredentials,
11
13
  payments,
12
14
  runProRulesWithDispatch,
13
15
  saveCredentials,
14
16
  secretsCheck
15
- } from "./chunk-2N3P2DUE.js";
17
+ } from "./chunk-ZGFTTSVM.js";
16
18
  import {
17
19
  DEFAULT_MAX_FILES,
18
20
  DEFAULT_MAX_FILE_SIZE_BYTES,
19
21
  DEFAULT_MAX_TOTAL_BYTES,
20
22
  readFiles
21
- } from "./chunk-BZWSFLBO.js";
23
+ } from "./chunk-ALFVS2BH.js";
24
+ import {
25
+ decodeUtf8Strict,
26
+ detectBinary,
27
+ normalizeNewlines,
28
+ stripBom
29
+ } from "./chunk-ANTCYKRO.js";
22
30
 
23
31
  // src/cli.ts
24
32
  import { Command as Command7, CommanderError } from "commander";
@@ -194,7 +202,7 @@ import { existsSync as existsSync3 } from "fs";
194
202
  import { join as join5, resolve as resolve3 } from "path";
195
203
 
196
204
  // src/core/scanner.ts
197
- import { readFile as readFile2, stat } from "fs/promises";
205
+ import { readFile as readFile2, stat, realpath } from "fs/promises";
198
206
  import { join as join2 } from "path";
199
207
 
200
208
  // src/core/risk-score.ts
@@ -313,6 +321,8 @@ async function scan(options, proRules, onProgress) {
313
321
  const skippedTooLargeFiles = [];
314
322
  let skippedBinary = 0;
315
323
  let truncated = false;
324
+ const changedInvalidUtf8 = [];
325
+ const changedUnreadable = [];
316
326
  if (options.changedOnly && isGitRepo(cwd)) {
317
327
  const changedRelPaths = getChangedFiles(cwd);
318
328
  const filteredPaths = changedRelPaths.filter(
@@ -332,7 +342,27 @@ async function scan(options, proRules, onProgress) {
332
342
  }
333
343
  const fullPath = join2(cwd, relPath);
334
344
  try {
335
- const fileStat = await stat(fullPath);
345
+ let resolvedPath;
346
+ try {
347
+ resolvedPath = await realpath(fullPath);
348
+ } catch (realpathErr) {
349
+ const detail = realpathErr instanceof Error ? realpathErr.message : String(realpathErr);
350
+ logger.warn(`[shipguard] Could not resolve path for changed file ${relPath}: ${detail}`);
351
+ changedUnreadable.push(relPath);
352
+ onProgress?.(++changedProcessed, changedTotal, relPath);
353
+ continue;
354
+ }
355
+ const canonicalCwd = await realpath(cwd).catch(() => cwd);
356
+ const cwdWithSep = canonicalCwd.endsWith("/") ? canonicalCwd : canonicalCwd + "/";
357
+ if (!resolvedPath.startsWith(cwdWithSep) && resolvedPath !== canonicalCwd) {
358
+ logger.warn(
359
+ `[shipguard] Refusing out-of-root path for changed file ${relPath}: resolved to ${resolvedPath} which is outside ${canonicalCwd}`
360
+ );
361
+ changedUnreadable.push(relPath);
362
+ onProgress?.(++changedProcessed, changedTotal, relPath);
363
+ continue;
364
+ }
365
+ const fileStat = await stat(resolvedPath);
336
366
  if (fileStat.size > limits.maxFileSizeBytes) {
337
367
  skippedTooLarge++;
338
368
  if (skippedTooLargeFiles.length < 50) {
@@ -341,24 +371,25 @@ async function scan(options, proRules, onProgress) {
341
371
  onProgress?.(++changedProcessed, changedTotal, relPath);
342
372
  continue;
343
373
  }
344
- const buffer = await readFile2(fullPath);
345
- const checkLen = Math.min(buffer.length, 8192);
346
- let isBinary = false;
347
- for (let i = 0; i < checkLen; i++) {
348
- if (buffer[i] === 0) {
349
- isBinary = true;
350
- break;
351
- }
352
- }
353
- if (isBinary) {
374
+ const buffer = await readFile2(resolvedPath);
375
+ if (detectBinary(new Uint8Array(buffer))) {
354
376
  skippedBinary++;
355
377
  onProgress?.(++changedProcessed, changedTotal, relPath);
356
378
  continue;
357
379
  }
358
- const content = buffer.toString("utf-8");
380
+ const decoded = decodeUtf8Strict(new Uint8Array(buffer));
381
+ if (!decoded.ok) {
382
+ changedInvalidUtf8.push({ relativePath: relPath, reason: decoded.reason });
383
+ onProgress?.(++changedProcessed, changedTotal, relPath);
384
+ continue;
385
+ }
386
+ const content = normalizeNewlines(stripBom(decoded.text));
359
387
  totalBytes += buffer.length;
360
388
  files.push({ path: fullPath, content, relativePath: relPath });
361
- } catch {
389
+ } catch (err) {
390
+ const detail = err instanceof Error ? err.message : String(err);
391
+ logger.warn(`[shipguard] Could not read changed file ${relPath}: ${detail}`);
392
+ changedUnreadable.push(relPath);
362
393
  }
363
394
  onProgress?.(++changedProcessed, changedTotal, relPath);
364
395
  }
@@ -377,6 +408,8 @@ async function scan(options, proRules, onProgress) {
377
408
  skippedTooLargeFiles.push(...readResult.skippedTooLargeFiles);
378
409
  skippedBinary = readResult.skippedBinary;
379
410
  truncated = readResult.truncated;
411
+ changedInvalidUtf8.push(...readResult.invalidUtf8Files);
412
+ changedUnreadable.push(...readResult.unreadableFiles);
380
413
  }
381
414
  let allFindings = applySuppressions(
382
415
  CHECK_MODULES.flatMap((mod) => mod.run(files, policy)),
@@ -384,7 +417,17 @@ async function scan(options, proRules, onProgress) {
384
417
  );
385
418
  let coderefDegraded = false;
386
419
  if (proRules?.length) {
387
- const { findings: proFindings, degraded, warnings } = runProRulesWithDispatch(proRules, files, policy);
420
+ const checksumManifest = loadChecksumManifest();
421
+ const { findings: proFindings, degraded, warnings } = runProRulesWithDispatch(
422
+ proRules,
423
+ files,
424
+ policy,
425
+ void 0,
426
+ // cliVersion — use default (reads from package.json)
427
+ void 0,
428
+ // table — use default dispatch table
429
+ checksumManifest
430
+ );
388
431
  allFindings = [...allFindings, ...proFindings];
389
432
  coderefDegraded = degraded;
390
433
  for (const w of warnings) {
@@ -413,6 +456,22 @@ async function scan(options, proRules, onProgress) {
413
456
  detail: "One or more pro coderef rules were skipped because they require a newer CLI version."
414
457
  });
415
458
  }
459
+ if (changedInvalidUtf8.length > 0) {
460
+ const named = changedInvalidUtf8.slice(0, 10).map((f) => f.relativePath).join(", ");
461
+ const extra = changedInvalidUtf8.length > 10 ? ` (and ${changedInvalidUtf8.length - 10} more)` : "";
462
+ degradedReasons.push({
463
+ code: "INVALID_UTF8",
464
+ detail: `${changedInvalidUtf8.length} file(s) contained invalid UTF-8 and were not scanned: ${named}${extra}`
465
+ });
466
+ }
467
+ if (changedUnreadable.length > 0) {
468
+ const named = changedUnreadable.slice(0, 10).join(", ");
469
+ const extra = changedUnreadable.length > 10 ? ` (and ${changedUnreadable.length - 10} more)` : "";
470
+ degradedReasons.push({
471
+ code: "UNREADABLE_FILE",
472
+ detail: `${changedUnreadable.length} file(s) could not be read and were not scanned: ${named}${extra}`
473
+ });
474
+ }
416
475
  const isDegraded = degradedReasons.length > 0 || void 0;
417
476
  const result = {
418
477
  findings: allFindings,
@@ -659,7 +718,7 @@ import { homedir } from "os";
659
718
  var DOCS_URL = "https://agenticcli.dev/docs";
660
719
  var SITE_URL = "https://agenticcli.dev";
661
720
  var PRICING_URL = "https://agenticcli.dev/pricing";
662
- var ISSUES_URL = "https://github.com/ramxH3421/agentic-cli/issues";
721
+ var ISSUES_URL = "https://github.com/agenticcli/shipguard/issues";
663
722
  var SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
664
723
  var BOX_WIDTH = 78;
665
724
  var H = "\u2500";
@@ -1116,8 +1175,8 @@ function sendTelemetry(payload) {
1116
1175
  }
1117
1176
 
1118
1177
  // src/commands/scan.ts
1119
- 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";
1120
- var CLI_VERSION = true ? "0.2.1" : process.env.npm_package_version ?? "0.0.0-dev";
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.3.0" : process.env.npm_package_version ?? "0.0.0-dev";
1121
1180
  function resolveExitCode(opts) {
1122
1181
  if (opts.strict && opts.blockingCount > 0) {
1123
1182
  return EXIT_CODES.BLOCKED;
@@ -1224,8 +1283,8 @@ async function runScan(ctx) {
1224
1283
  }
1225
1284
  try {
1226
1285
  const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
1227
- const { fetchProRules } = await import("./pro-scanner-ER2RYPI5.js");
1228
- const { hasConfig, generateConfig } = await import("./config-generator-Q2YTMBZ5.js");
1286
+ const { fetchProRules } = await import("./pro-scanner-K7QKKY4E.js");
1287
+ const { hasConfig, generateConfig } = await import("./config-generator-RMWNQQHW.js");
1229
1288
  const detectedResult = detectFrameworks(cwd);
1230
1289
  const { frameworks } = detectedResult;
1231
1290
  if (!hasConfig(cwd)) {
@@ -1461,6 +1520,7 @@ var DEFAULT_API_URL = "https://agenticcli.dev";
1461
1520
  function loginCommand() {
1462
1521
  return new Command3("login").description("Authenticate with ShipGuard for pro features").option("--api-url <url>", "API server URL", DEFAULT_API_URL).action(async (opts) => {
1463
1522
  const apiUrl = opts.apiUrl;
1523
+ assertTrustedApiUrl(apiUrl);
1464
1524
  const res = await fetch(`${apiUrl}/api/auth/device`, { method: "POST" });
1465
1525
  if (!res.ok) {
1466
1526
  logger.error("Failed to start auth");
@@ -1532,6 +1592,7 @@ function statusCommand() {
1532
1592
  logger.info(`Token: ${expired ? "expired" : "valid"} (expires ${new Date(creds.expiresAt).toISOString()})`);
1533
1593
  if (!expired) {
1534
1594
  try {
1595
+ assertTrustedApiUrl(creds.apiUrl);
1535
1596
  const res = await fetch(`${creds.apiUrl}/api/user/me`, {
1536
1597
  headers: { "Authorization": `Bearer ${creds.accessToken}` }
1537
1598
  });
@@ -1567,6 +1628,7 @@ function feedbackCommand() {
1567
1628
  return;
1568
1629
  }
1569
1630
  try {
1631
+ assertTrustedApiUrl(creds.apiUrl);
1570
1632
  const res = await fetch(`${creds.apiUrl}/api/feedback`, {
1571
1633
  method: "POST",
1572
1634
  headers: {
@@ -1608,6 +1670,7 @@ function rateCommand() {
1608
1670
  return;
1609
1671
  }
1610
1672
  try {
1673
+ assertTrustedApiUrl(creds.apiUrl);
1611
1674
  const res = await fetch(`${creds.apiUrl}/api/feedback`, {
1612
1675
  method: "POST",
1613
1676
  headers: {
@@ -1631,7 +1694,7 @@ function rateCommand() {
1631
1694
  }
1632
1695
 
1633
1696
  // src/handlers.ts
1634
- var ISSUES_URL2 = "https://github.com/ramxH3421/agentic-cli/issues";
1697
+ var ISSUES_URL2 = "https://github.com/agenticcli/shipguard/issues";
1635
1698
  var DOCS_URL2 = "https://agenticcli.dev/docs";
1636
1699
  var REPORT_LINE = `Report this: ${ISSUES_URL2} \xB7 Docs: ${DOCS_URL2}`;
1637
1700
  function handleUncaughtException(error) {
@@ -1662,14 +1725,14 @@ process.on("uncaughtException", handleUncaughtException);
1662
1725
  process.on("unhandledRejection", handleUnhandledRejection);
1663
1726
  process.on("SIGINT", handleSignal);
1664
1727
  process.on("SIGTERM", handleSignal);
1665
- var ISSUES_URL3 = "https://github.com/ramxH3421/agentic-cli/issues";
1728
+ var ISSUES_URL3 = "https://github.com/agenticcli/shipguard/issues";
1666
1729
  var program = new Command7();
1667
1730
  var rawArgs = process.argv.slice(2);
1668
1731
  if (rawArgs[0] === "?") {
1669
1732
  process.argv = [process.argv[0], process.argv[1], "help"];
1670
1733
  }
1671
1734
  program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
1672
- true ? "0.2.1" : process.env.npm_package_version ?? "0.0.0-dev"
1735
+ true ? "0.3.0" : process.env.npm_package_version ?? "0.0.0-dev"
1673
1736
  ).helpCommand(false).addHelpText("after", `
1674
1737
  Learn more:
1675
1738
  Docs https://agenticcli.dev/docs
@@ -2,7 +2,8 @@ import {
2
2
  DEFAULT_MAX_FILES,
3
3
  DEFAULT_MAX_FILE_SIZE_BYTES,
4
4
  DEFAULT_MAX_TOTAL_BYTES
5
- } from "./chunk-BZWSFLBO.js";
5
+ } from "./chunk-ALFVS2BH.js";
6
+ import "./chunk-ANTCYKRO.js";
6
7
 
7
8
  // src/core/config-generator.ts
8
9
  import { writeFileSync, existsSync } from "fs";
@@ -0,0 +1,74 @@
1
+ import {
2
+ CapTracker,
3
+ DEFAULT_CAPS,
4
+ DegradedReason,
5
+ EXEC_RULE_EXTENSION_FIELDS,
6
+ EXEC_RULE_FIELDS,
7
+ NATIVE_V1_ADAPTER_IMPL_HASH,
8
+ NATIVE_V1_RUNTIME_ID,
9
+ RE2JS_V1_ADAPTER_IMPL_HASH,
10
+ RE2JS_V1_RUNTIME_ID,
11
+ RE2JS_VERSION,
12
+ SUPPORTED_NODE_VERSIONS,
13
+ UNICODE_NORMALIZATION_POLICY,
14
+ allConformanceVectors,
15
+ canonicalJson,
16
+ canonicalizeFinding,
17
+ computeExecutableHash,
18
+ computeMatcherRuntimeId,
19
+ decodeUtf8Strict,
20
+ detectBinary,
21
+ executorDependentVectors,
22
+ executorIndependentVectors,
23
+ hugeSingleLineCap,
24
+ makeNativeEngineMeta,
25
+ makeRe2jsEngineMeta,
26
+ nativeV1Executor,
27
+ normalizeNewlines,
28
+ parseFlags,
29
+ parseStrictNoDup,
30
+ re2jsTestPattern,
31
+ re2jsV1Executor,
32
+ resolveExitCode,
33
+ runConformance,
34
+ selectExpected,
35
+ stripBom,
36
+ verifyExactSet
37
+ } from "./chunk-ANTCYKRO.js";
38
+ export {
39
+ CapTracker,
40
+ DEFAULT_CAPS,
41
+ DegradedReason,
42
+ EXEC_RULE_EXTENSION_FIELDS,
43
+ EXEC_RULE_FIELDS,
44
+ NATIVE_V1_ADAPTER_IMPL_HASH,
45
+ NATIVE_V1_RUNTIME_ID,
46
+ RE2JS_V1_ADAPTER_IMPL_HASH,
47
+ RE2JS_V1_RUNTIME_ID,
48
+ RE2JS_VERSION,
49
+ SUPPORTED_NODE_VERSIONS,
50
+ UNICODE_NORMALIZATION_POLICY,
51
+ allConformanceVectors,
52
+ canonicalJson,
53
+ canonicalizeFinding,
54
+ computeExecutableHash,
55
+ computeMatcherRuntimeId,
56
+ decodeUtf8Strict,
57
+ detectBinary,
58
+ executorDependentVectors,
59
+ executorIndependentVectors,
60
+ hugeSingleLineCap,
61
+ makeNativeEngineMeta,
62
+ makeRe2jsEngineMeta,
63
+ nativeV1Executor,
64
+ normalizeNewlines,
65
+ parseFlags,
66
+ parseStrictNoDup,
67
+ re2jsTestPattern,
68
+ re2jsV1Executor,
69
+ resolveExitCode,
70
+ runConformance,
71
+ selectExpected,
72
+ stripBom,
73
+ verifyExactSet
74
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ RunProRulesFatalError,
3
+ fetchProRules,
4
+ runProRules,
5
+ runProRulesWithDispatch,
6
+ validateBundleCompile
7
+ } from "./chunk-ZGFTTSVM.js";
8
+ import "./chunk-ANTCYKRO.js";
9
+ export {
10
+ RunProRulesFatalError,
11
+ fetchProRules,
12
+ runProRules,
13
+ runProRulesWithDispatch,
14
+ validateBundleCompile
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticcli/shipguard",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "CLI-first release gate for AI-built apps",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
@@ -20,13 +20,18 @@
20
20
  "fast-glob": "^3.3.0",
21
21
  "jose": "^6.2.3",
22
22
  "minimatch": "^10.2.5",
23
+ "re2js": "2.8.3",
23
24
  "yaml": "^2.7.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^22.0.0",
28
+ "@typescript-eslint/eslint-plugin": "^7",
29
+ "@typescript-eslint/parser": "^7",
30
+ "eslint": "^8",
27
31
  "tsup": "^8.5.1",
28
32
  "typescript": "^5.8.0",
29
33
  "vitest": "^3.2.0",
34
+ "@agenticcli/matcher-contract": "0.5.0",
30
35
  "@agenticcli/shared": "0.1.0"
31
36
  },
32
37
  "keywords": [
@@ -35,17 +40,25 @@
35
40
  "release-gate",
36
41
  "ai-code",
37
42
  "security",
38
- "cli"
43
+ "cli",
44
+ "ai-agents",
45
+ "claude-code",
46
+ "cursor",
47
+ "codex",
48
+ "agentic",
49
+ "pre-deploy-check",
50
+ "secrets-scanner",
51
+ "llm-generated-code"
39
52
  ],
40
- "license": "MIT",
41
- "author": "ramxH3421",
53
+ "license": "Elastic-2.0",
54
+ "author": "agenticcli",
42
55
  "repository": {
43
56
  "type": "git",
44
- "url": "https://github.com/ramxH3421/agenticcli"
57
+ "url": "git+https://github.com/agenticcli/shipguard.git"
45
58
  },
46
59
  "homepage": "https://agenticcli.dev/shipguard",
47
60
  "bugs": {
48
- "url": "https://github.com/ramxH3421/agenticcli/issues"
61
+ "url": "https://github.com/agenticcli/shipguard/issues"
49
62
  },
50
63
  "engines": {
51
64
  "node": ">=20"
@@ -56,6 +69,7 @@
56
69
  "scripts": {
57
70
  "build": "tsup",
58
71
  "dev": "tsup --watch",
72
+ "lint": "eslint src --ext .ts",
59
73
  "test": "vitest run",
60
74
  "test:watch": "vitest",
61
75
  "clean": "rm -rf dist"