@dypt/cli 0.1.21 → 0.1.22

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
@@ -217,6 +217,21 @@ dypt task list --limit 10 --json
217
217
  dypt task get 123 --json
218
218
  ```
219
219
 
220
+ ### Transport failures
221
+
222
+ Network failures exit `1`. With `--json`, fetch failures emit a
223
+ `CLI_TRANSPORT_ERROR` object on stderr containing a safe `message`, allowlisted
224
+ `causeCode` (or `null`), `category`, and `retryableRead`. Human output includes
225
+ the same safe cause code. URLs, tokens, headers, request bodies and raw error
226
+ messages are not included in these transport diagnostics.
227
+
228
+ `retryableRead` is guidance for a caller's bounded **read-only** retry, not
229
+ permission to replay writes. The CLI does not automatically retry requests or
230
+ claim a failed mutation made no change. Verify a mutation's outcome before
231
+ retrying it. Temporary DNS (`EAI_AGAIN`), connection resets and timeouts may
232
+ qualify; permanent DNS (`ENOTFOUND`), access and certificate errors do not.
233
+ Check network and sandbox configuration without automatically changing it.
234
+
220
235
  ### Maintenance responses
221
236
 
222
237
  If dypt is in maintenance mode, API-backed commands stop after the first `503`
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { Argument, Command, Option } from "commander";
9
9
  // package.json
10
10
  var package_default = {
11
11
  name: "@dypt/cli",
12
- version: "0.1.21",
12
+ version: "0.1.22",
13
13
  description: "Command-line interface for dypt task management",
14
14
  license: "SEE LICENSE IN LICENSE",
15
15
  homepage: "https://dypt.app",
@@ -286,6 +286,65 @@ async function clearCliToken(baseUrl = getBaseUrl(), filePath) {
286
286
  import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
287
287
  import superjson from "superjson";
288
288
 
289
+ // src/lib/transport.ts
290
+ var causes = {
291
+ ENOTFOUND: ["dns", false],
292
+ EAI_AGAIN: ["dns", true],
293
+ ECONNRESET: ["connection", true],
294
+ ECONNREFUSED: ["connection", true],
295
+ EPIPE: ["connection", true],
296
+ UND_ERR_SOCKET: ["connection", true],
297
+ ETIMEDOUT: ["timeout", true],
298
+ UND_ERR_CONNECT_TIMEOUT: ["timeout", true],
299
+ UND_ERR_HEADERS_TIMEOUT: ["timeout", true],
300
+ UND_ERR_BODY_TIMEOUT: ["timeout", true],
301
+ EACCES: ["access", false],
302
+ EPERM: ["access", false],
303
+ CERT_HAS_EXPIRED: ["tls", false],
304
+ DEPTH_ZERO_SELF_SIGNED_CERT: ["tls", false],
305
+ UNABLE_TO_VERIFY_LEAF_SIGNATURE: ["tls", false],
306
+ ERR_TLS_CERT_ALTNAME_INVALID: ["tls", false]
307
+ };
308
+ function errorChain(error) {
309
+ const seen = /* @__PURE__ */ new Set();
310
+ const pending = [error];
311
+ while (pending.length && seen.size < 16) {
312
+ const current = pending.shift();
313
+ if (!current || typeof current !== "object" || seen.has(current)) continue;
314
+ seen.add(current);
315
+ pending.push(current.cause);
316
+ if (current instanceof AggregateError)
317
+ pending.push(...current.errors.slice(0, 16));
318
+ }
319
+ return [...seen];
320
+ }
321
+ var CliTransportError = class extends Error {
322
+ constructor(error) {
323
+ super("Unable to complete the dypt network request.");
324
+ this.code = "CLI_TRANSPORT_ERROR";
325
+ this.name = "CliTransportError";
326
+ const known = errorChain(error).map((item) => item.code).filter(
327
+ (code) => typeof code === "string" && Object.hasOwn(causes, code)
328
+ );
329
+ this.causeCode = known.find((code) => !causes[code][1]) ?? known[0] ?? null;
330
+ [this.category, this.retryableRead] = this.causeCode ? causes[this.causeCode] : ["unknown", false];
331
+ }
332
+ };
333
+ function formatTransportFailure(error, json) {
334
+ const transport = errorChain(error).find(
335
+ (item) => item instanceof CliTransportError
336
+ );
337
+ if (!transport) return null;
338
+ const { code, message, causeCode, category, retryableRead } = transport;
339
+ const guidance = retryableRead ? "Only read-only requests may be retried; verify the outcome before retrying a write." : "Check network, DNS, TLS and sandbox access; do not change permissions automatically.";
340
+ return {
341
+ exitCode: 1,
342
+ output: json ? JSON.stringify({
343
+ error: { code, message, causeCode, category, retryableRead }
344
+ }) : `${message} ${category}${causeCode ? ` (${causeCode})` : ""}. ${guidance}`
345
+ };
346
+ }
347
+
289
348
  // src/lib/maintenance.ts
290
349
  var DYPT_MAINTENANCE_CODE = "DYPT_MAINTENANCE";
291
350
  var DYPT_MAINTENANCE_EXIT_CODE = 75;
@@ -332,7 +391,12 @@ async function getMaintenanceError(response) {
332
391
  );
333
392
  }
334
393
  async function fetchWithMaintenanceCheck(input, init) {
335
- const response = await globalThis.fetch(input, init);
394
+ let response;
395
+ try {
396
+ response = await globalThis.fetch(input, init);
397
+ } catch (error) {
398
+ throw new CliTransportError(error);
399
+ }
336
400
  const maintenanceError = await getMaintenanceError(response);
337
401
  if (maintenanceError) throw maintenanceError;
338
402
  return response;
@@ -384,6 +448,8 @@ function formatRetryGuidance(error) {
384
448
  return " Retry later.";
385
449
  }
386
450
  function formatCliFailure(error, json) {
451
+ const transportFailure = formatTransportFailure(error, json);
452
+ if (transportFailure) return transportFailure;
387
453
  const maintenanceError = findMaintenanceError(error);
388
454
  const readRateLimitError = findCliReadRateLimitError(error);
389
455
  if (readRateLimitError) {