@agenticcli/shipguard 0.8.0 → 0.9.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
@@ -70,6 +70,18 @@ output — it never hijacks exit `2`, which is reserved for genuine config error
70
70
  not check; the exit code stays 0 because ShipGuard is passive by default. Pass `--strict`
71
71
  when you want that truthful verdict to actually stop something.
72
72
 
73
+ ### What was actually scanned
74
+
75
+ Every `--json` result (schemaVersion 6) has a `coverage` object: files discovered, scanned,
76
+ and skipped, with the reason for each skip (real binary, too large, symlink, unknown binary,
77
+ invalid text, unreadable, special file), plus text read as UTF-16 or with stray NUL bytes
78
+ turned into spaces. Real binaries (images, fonts, archives) are counted and are not a
79
+ problem. A scan that read **nothing** (`NO_FILES_SCANNED`, for example an empty folder or
80
+ `--changed` on a clean checkout), an unknown binary blob (`UNSCANNED_UNKNOWN_BINARY`), and a
81
+ truncated scan are `degraded` and so `DO_NOT_SHIP`. To clear a blob you trust, add its path to
82
+ `ignore.paths`. Some formats are counted but their contents are not scanned: SQLite files
83
+ outside the ASCII reading, compressed archives, and string tables inside ELF, PE, class and WASM files.
84
+
73
85
  ## Telemetry
74
86
 
75
87
  Published ShipGuard builds send one pseudonymous usage ping after each scan: CLI version, verdict (safe / review / blocked / error), a scan-duration bucket, a CI flag, the build type, and a random install id (a pseudonym stored in `~/.config/shipguard/telemetry.json`; not created or sent in CI, never linked to an account). Never file contents, paths, repo names, branches or commits, or user identity. `shipguard telemetry status` shows what is set, `shipguard telemetry reset` forgets the id (earlier pings can be deleted on request), `SHIPGUARD_TELEMETRY_DEBUG=1` prints the exact payload without sending. Builds from a source checkout never send anything.
@@ -1,7 +1,7 @@
1
1
  {
2
- "secrets": "58c191e144049b09abc0b59ec76a9f902a0634a439aedac97afffa4c3aa51918",
3
- "auth": "58c191e144049b09abc0b59ec76a9f902a0634a439aedac97afffa4c3aa51918",
4
- "database": "58c191e144049b09abc0b59ec76a9f902a0634a439aedac97afffa4c3aa51918",
5
- "deployment": "58c191e144049b09abc0b59ec76a9f902a0634a439aedac97afffa4c3aa51918",
6
- "payments": "58c191e144049b09abc0b59ec76a9f902a0634a439aedac97afffa4c3aa51918"
2
+ "secrets": "163a4efbe979c808be17cd9ac0eb7b059689480c6d7a7371d1d29e8d23abb4b6",
3
+ "auth": "163a4efbe979c808be17cd9ac0eb7b059689480c6d7a7371d1d29e8d23abb4b6",
4
+ "database": "163a4efbe979c808be17cd9ac0eb7b059689480c6d7a7371d1d29e8d23abb4b6",
5
+ "deployment": "163a4efbe979c808be17cd9ac0eb7b059689480c6d7a7371d1d29e8d23abb4b6",
6
+ "payments": "163a4efbe979c808be17cd9ac0eb7b059689480c6d7a7371d1d29e8d23abb4b6"
7
7
  }
@@ -1,3 +1,6 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-NC5RELTG.js";
1
4
  import {
2
5
  EXEC_RULE_FIELDS,
3
6
  RE2JS_V1_RUNTIME_ID,
@@ -207,6 +210,62 @@ async function exchangeApiKeyForToken(apiKey, apiUrl) {
207
210
  };
208
211
  return body.access_token;
209
212
  }
213
+ var RefreshUnavailableError = class extends Error {
214
+ constructor(message, retryAfterSeconds) {
215
+ super(message);
216
+ this.retryAfterSeconds = retryAfterSeconds;
217
+ this.name = "RefreshUnavailableError";
218
+ }
219
+ retryAfterSeconds;
220
+ };
221
+ var REFRESH_MAX_TRIES = 3;
222
+ var REFRESH_MAX_WAIT_SECONDS = 10;
223
+ var sleepMs = (ms) => new Promise((r) => setTimeout(r, ms));
224
+ async function readBodyQuietly(res) {
225
+ try {
226
+ const probe = typeof res.clone === "function" ? res.clone() : res;
227
+ return await probe.json();
228
+ } catch {
229
+ return null;
230
+ }
231
+ }
232
+ async function fetchRefreshWithRetry(apiUrl, refreshToken) {
233
+ let lastWait = 1;
234
+ for (let attempt = 1; ; attempt++) {
235
+ const backoff = 2 ** (attempt - 1);
236
+ let res;
237
+ let detail;
238
+ let wait = backoff;
239
+ let sleepSeconds = Math.random() * backoff;
240
+ try {
241
+ res = await fetch(`${apiUrl}/api/auth/device/refresh`, {
242
+ method: "POST",
243
+ headers: { "Content-Type": "application/json" },
244
+ body: JSON.stringify({ refresh_token: refreshToken })
245
+ });
246
+ const transient = res.status === 429 || res.status === 408 || res.status === 425 || res.status >= 500;
247
+ if (res.ok || !transient) return res;
248
+ if (res.status >= 500 && isPlatformUnavailable(res, await readBodyQuietly(res))) return res;
249
+ const retryAfter = parseRetryAfterSeconds(res.headers);
250
+ if (retryAfter !== void 0) {
251
+ wait = Math.max(retryAfter, backoff);
252
+ sleepSeconds = wait;
253
+ }
254
+ detail = `HTTP ${res.status}`;
255
+ } catch (err) {
256
+ detail = err instanceof Error ? err.message : String(err);
257
+ }
258
+ lastWait = wait;
259
+ if (attempt >= REFRESH_MAX_TRIES || wait > REFRESH_MAX_WAIT_SECONDS) {
260
+ throw new RefreshUnavailableError(
261
+ `Token refresh is rate limited or temporarily unavailable (${detail}); your login is kept, try again in ${lastWait} s.`,
262
+ lastWait
263
+ );
264
+ }
265
+ console.error(`[shipguard] Token refresh got ${detail}; retrying in ${wait} s (attempt ${attempt}/${REFRESH_MAX_TRIES}).`);
266
+ await sleepMs(sleepSeconds * 1e3);
267
+ }
268
+ }
210
269
  async function getAuthToken(apiUrl) {
211
270
  const apiKey = process.env.SHIPGUARD_API_KEY;
212
271
  if (apiKey) {
@@ -222,11 +281,7 @@ async function getAuthToken(apiUrl) {
222
281
  if (creds.refreshToken && creds.apiUrl) {
223
282
  try {
224
283
  assertTrustedApiUrl(creds.apiUrl);
225
- const res = await fetch(`${creds.apiUrl}/api/auth/device/refresh`, {
226
- method: "POST",
227
- headers: { "Content-Type": "application/json" },
228
- body: JSON.stringify({ refresh_token: creds.refreshToken })
229
- });
284
+ const res = await fetchRefreshWithRetry(creds.apiUrl, creds.refreshToken);
230
285
  if (res.ok) {
231
286
  const { access_token, refresh_token, expires_in } = await res.json();
232
287
  await saveCredentials({
@@ -237,13 +292,7 @@ async function getAuthToken(apiUrl) {
237
292
  });
238
293
  return access_token;
239
294
  }
240
- let refusedBody = null;
241
- try {
242
- const probe = typeof res.clone === "function" ? res.clone() : res;
243
- refusedBody = await probe.json();
244
- } catch {
245
- refusedBody = null;
246
- }
295
+ const refusedBody = await readBodyQuietly(res);
247
296
  if (isPlatformUnavailable(res, refusedBody)) {
248
297
  throw new PlatformUnavailableError(
249
298
  typeof refusedBody?.error === "string" ? refusedBody.error : PLATFORM_UNAVAILABLE_DEFAULT_MESSAGE,
@@ -255,6 +304,7 @@ async function getAuthToken(apiUrl) {
255
304
  );
256
305
  } catch (err) {
257
306
  if (err instanceof PlatformUnavailableError) throw err;
307
+ if (err instanceof RefreshUnavailableError) throw err;
258
308
  const detail = err instanceof Error ? err.message : String(err);
259
309
  console.error(
260
310
  `[shipguard] Token refresh failed \u2014 you will be asked to log in again. Reason: ${detail}`
@@ -1821,43 +1871,6 @@ var secretsCheck = {
1821
1871
  run: checkSecrets
1822
1872
  };
1823
1873
 
1824
- // src/utils/logger.ts
1825
- import chalk from "chalk";
1826
- var logger = {
1827
- info: (msg) => console.error(chalk.blue("\u2139"), msg),
1828
- success: (msg) => console.error(chalk.green("\u2713"), msg),
1829
- warn: (msg) => console.error(chalk.yellow("\u26A0"), msg),
1830
- error: (msg) => console.error(chalk.red("\u2717"), msg),
1831
- // Diagnostics that are true and worth being able to inspect, but too detailed for a
1832
- // normal run — e.g. "this legacy finding was superseded by a governed corpus rule on
1833
- // the same line". Deliberately NOT a silent drop: the information is always produced
1834
- // and one env var makes it visible. Stderr only, like every other logger method.
1835
- debug: (msg) => {
1836
- if (process.env.SHIPGUARD_DEBUG) console.error(chalk.gray("\xB7"), msg);
1837
- },
1838
- finding: (severity, msg) => {
1839
- const colors = {
1840
- critical: chalk.bgRed.white,
1841
- high: chalk.red,
1842
- medium: chalk.yellow,
1843
- low: chalk.blue,
1844
- info: chalk.gray
1845
- };
1846
- const colorFn = colors[severity] || chalk.white;
1847
- const label = severity.toUpperCase().padEnd(8);
1848
- console.error(` ${colorFn(label)} ${msg}`);
1849
- },
1850
- score: (score, recommendation) => {
1851
- const color = score <= 20 ? chalk.green : score <= 50 ? chalk.yellow : chalk.red;
1852
- const icon = score <= 20 ? "\u2713" : score <= 50 ? "\u26A0" : "\u2717";
1853
- console.error("");
1854
- console.error(chalk.bold("ShipGuard Scan Result"));
1855
- console.error(`Risk Score: ${color(`${score}/100`)}`);
1856
- console.error(`Status: ${color(`${icon} ${recommendation.replace(/_/g, " ")}`)}`);
1857
- },
1858
- divider: () => console.error(chalk.gray("\u2500".repeat(50)))
1859
- };
1860
-
1861
1874
  // src/checks/auth.ts
1862
1875
  var SENSITIVE_NEXTJS_PAGE_PATTERN = /^(?:src\/)?app\/(admin|dashboard|billing|account|settings|management|debug|internal)(\/|$)/;
1863
1876
  var SENSITIVE_API_ROUTE_PATTERN = /^(?:src\/)?app\/api\/(admin|users|billing|account|management|debug|internal|env|_debug)(\/|$)/;
@@ -3413,6 +3426,9 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
3413
3426
  if (err instanceof PlatformUnavailableError) {
3414
3427
  throw new ProFetchError("PLATFORM_UNAVAILABLE", err.message, { retryAfterSeconds: err.retryAfterSeconds });
3415
3428
  }
3429
+ if (err instanceof RefreshUnavailableError) {
3430
+ throw new ProFetchError("RATE_LIMITED", err.message, { retryAfterSeconds: err.retryAfterSeconds });
3431
+ }
3416
3432
  throw err;
3417
3433
  }
3418
3434
  if (!token) throw new ProFetchError("AUTH_FAILED", "Not authenticated. Run `shipguard login` first.");
@@ -3783,7 +3799,6 @@ function runProRulesWithDispatch(rules, files, policy, cliVersion, table, manife
3783
3799
 
3784
3800
  export {
3785
3801
  goLink,
3786
- logger,
3787
3802
  getFindingKey,
3788
3803
  redactFindingsEvidence,
3789
3804
  secretsCheck,