@dypt/cli 0.1.20 → 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
@@ -36,9 +36,10 @@ DYPT_TOKEN_FILE=/absolute/path/to/dypt-token.json dypt auth login
36
36
 
37
37
  Keep `DYPT_TOKEN_FILE` set to the same path for subsequent commands and
38
38
  `dypt auth logout`. When explicitly configured, a missing or invalid file does
39
- not fall back to Keychain or another identity. The token file is created with
40
- owner-only permissions; its containing directory and any sandbox access to the
41
- file remain the user's responsibility.
39
+ not fall back to Keychain or another identity. The CLI creates the token file
40
+ with owner-only permissions and tightens an existing regular file before
41
+ writing. It refuses symlink and non-file destinations. The containing directory
42
+ and any sandbox access to the file remain the user's responsibility.
42
43
 
43
44
  ### List tasks
44
45
 
@@ -216,6 +217,21 @@ dypt task list --limit 10 --json
216
217
  dypt task get 123 --json
217
218
  ```
218
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
+
219
235
  ### Maintenance responses
220
236
 
221
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.20",
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",
@@ -88,7 +88,8 @@ function getDefaultDeviceLabel() {
88
88
 
89
89
  // src/lib/keychain.ts
90
90
  import { execFile } from "child_process";
91
- import { mkdir, readFile, rm, writeFile } from "fs/promises";
91
+ import { constants } from "fs";
92
+ import { mkdir, open, readFile, rm } from "fs/promises";
92
93
  import path2 from "path";
93
94
  import { promisify } from "util";
94
95
  var execFileAsync = promisify(execFile);
@@ -237,14 +238,23 @@ async function saveCliToken(accessToken, expiresAt, baseUrl = getBaseUrl(), file
237
238
  }
238
239
  }
239
240
  await ensureParentDirectory(storage.filePath);
240
- await writeFile(
241
+ const file = await open(
241
242
  storage.filePath,
242
- `${JSON.stringify({ accessToken, expiresAt }, null, 2)}
243
- `,
244
- {
245
- mode: 384
246
- }
243
+ constants.O_WRONLY | constants.O_CREAT | constants.O_NOFOLLOW,
244
+ 384
247
245
  );
246
+ try {
247
+ if (!(await file.stat()).isFile())
248
+ throw new Error("Token destination must be a regular file");
249
+ await file.chmod(384);
250
+ await file.truncate(0);
251
+ await file.writeFile(
252
+ `${JSON.stringify({ accessToken, expiresAt }, null, 2)}
253
+ `
254
+ );
255
+ } finally {
256
+ await file.close();
257
+ }
248
258
  }
249
259
  async function clearCliToken(baseUrl = getBaseUrl(), filePath) {
250
260
  const storage = resolveTokenStorage(baseUrl, filePath);
@@ -276,6 +286,65 @@ async function clearCliToken(baseUrl = getBaseUrl(), filePath) {
276
286
  import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
277
287
  import superjson from "superjson";
278
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
+
279
348
  // src/lib/maintenance.ts
280
349
  var DYPT_MAINTENANCE_CODE = "DYPT_MAINTENANCE";
281
350
  var DYPT_MAINTENANCE_EXIT_CODE = 75;
@@ -322,7 +391,12 @@ async function getMaintenanceError(response) {
322
391
  );
323
392
  }
324
393
  async function fetchWithMaintenanceCheck(input, init) {
325
- 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
+ }
326
400
  const maintenanceError = await getMaintenanceError(response);
327
401
  if (maintenanceError) throw maintenanceError;
328
402
  return response;
@@ -374,6 +448,8 @@ function formatRetryGuidance(error) {
374
448
  return " Retry later.";
375
449
  }
376
450
  function formatCliFailure(error, json) {
451
+ const transportFailure = formatTransportFailure(error, json);
452
+ if (transportFailure) return transportFailure;
377
453
  const maintenanceError = findMaintenanceError(error);
378
454
  const readRateLimitError = findCliReadRateLimitError(error);
379
455
  if (readRateLimitError) {
@@ -623,7 +699,7 @@ import {
623
699
  realpath,
624
700
  rm as rm2,
625
701
  stat,
626
- writeFile as writeFile2
702
+ writeFile
627
703
  } from "fs/promises";
628
704
  import os2 from "os";
629
705
  import path3 from "path";
@@ -819,7 +895,7 @@ async function downloadGitHubSource(source, fetchFn) {
819
895
  if (!response.ok) {
820
896
  throw new Error(`Failed to fetch ${item.path}: ${response.status}`);
821
897
  }
822
- await writeFile2(targetPath, await response.text());
898
+ await writeFile(targetPath, await response.text());
823
899
  })
824
900
  );
825
901
  return {
@@ -902,7 +978,7 @@ async function installAgentSkill(input) {
902
978
  installedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
903
979
  files: incomingHashes
904
980
  };
905
- await writeFile2(metadataPath(targetPath), `${JSON.stringify(installMetadata, null, 2)}
981
+ await writeFile(metadataPath(targetPath), `${JSON.stringify(installMetadata, null, 2)}
906
982
  `);
907
983
  }
908
984
  return {
@@ -927,7 +1003,7 @@ async function appendAgentInstructions(input) {
927
1003
  if (!input.dryRun) {
928
1004
  await mkdir2(path3.dirname(input.filePath), { recursive: true });
929
1005
  const separator = existing.endsWith("\n") || existing.length === 0 ? "\n" : "\n\n";
930
- await writeFile2(input.filePath, `${existing}${separator}${input.snippet}`);
1006
+ await writeFile(input.filePath, `${existing}${separator}${input.snippet}`);
931
1007
  }
932
1008
  return {
933
1009
  action: "append",