@drisp/cli 0.4.1 → 0.4.4

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.
@@ -78,7 +78,8 @@ function initTelemetry(options) {
78
78
  host: POSTHOG_HOST,
79
79
  disableGeoip: true,
80
80
  flushAt: 20,
81
- flushInterval: 3e4
81
+ flushInterval: 3e4,
82
+ enableExceptionAutocapture: true
82
83
  });
83
84
  }
84
85
  function isTelemetryEnabled() {
@@ -191,97 +192,18 @@ function trackGatewayRuntimeRebind(props) {
191
192
  function trackGatewayRuntimeExpired(props) {
192
193
  capture("gateway.runtime.expired", props);
193
194
  }
194
-
195
- // src/infra/gatewayTrace.ts
196
- import fs from "fs";
197
- function writeGatewayTrace(message) {
198
- if (process.env["ATHENA_GATEWAY_TRACE"] !== "1") return;
199
- const line = `athena-gateway: [trace] ${message}
200
- `;
201
- const traceFile = process.env["ATHENA_GATEWAY_TRACE_FILE"];
202
- if (traceFile && traceFile.length > 0) {
203
- try {
204
- fs.appendFileSync(traceFile, line, "utf-8");
205
- return;
206
- } catch {
207
- }
208
- }
209
- process.stderr.write(line);
210
- }
211
-
212
- // src/gateway/auth.ts
213
- import crypto from "crypto";
214
- import fs2 from "fs";
215
- import path2 from "path";
216
- var TOKEN_BYTES = 32;
217
- function loadOrCreateToken(tokenPath) {
218
- try {
219
- const buf = fs2.readFileSync(tokenPath);
220
- const text = buf.toString("utf-8").trim();
221
- if (text.length >= 16) return text;
222
- } catch (err) {
223
- const code = err.code;
224
- if (code !== "ENOENT") throw err;
225
- }
226
- return writeNewToken(tokenPath);
227
- }
228
- function rotateGatewayToken(tokenPath) {
229
- return writeNewToken(tokenPath);
230
- }
231
- function writeNewToken(tokenPath) {
232
- const dir = path2.dirname(tokenPath);
233
- fs2.mkdirSync(dir, { recursive: true, mode: 448 });
234
- const token = crypto.randomBytes(TOKEN_BYTES).toString("base64url");
235
- const tmpPath = `${tokenPath}.tmp-${process.pid}-${crypto.randomBytes(4).toString("hex")}`;
236
- fs2.writeFileSync(tmpPath, token + "\n", { mode: 384 });
237
- try {
238
- fs2.renameSync(tmpPath, tokenPath);
239
- } catch (err) {
240
- try {
241
- fs2.unlinkSync(tmpPath);
242
- } catch {
243
- }
244
- throw err;
245
- }
246
- if (process.platform !== "win32") {
247
- fs2.chmodSync(dir, 448);
248
- fs2.chmodSync(tokenPath, 384);
249
- }
250
- return token;
251
- }
252
- function timingSafeTokenEqual(a, b) {
253
- const ab = Buffer.from(a, "utf-8");
254
- const bb = Buffer.from(b, "utf-8");
255
- if (ab.length !== bb.length) {
256
- const filler = Buffer.alloc(Math.max(ab.length, bb.length));
257
- crypto.timingSafeEqual(filler, filler);
258
- return false;
259
- }
260
- return crypto.timingSafeEqual(ab, bb);
261
- }
262
- function requireTokenForBind(spec, token) {
263
- if (spec.kind === "uds" || isLoopbackHost(spec.host)) return;
264
- if (!token || token.length < 16) {
265
- throw new Error(
266
- `gateway: refusing to bind ${spec.host}:${spec.port} without token configured`
267
- );
268
- }
269
- if (spec.tls) return;
270
- if (!spec.insecure) {
271
- throw new Error(
272
- `gateway: refusing to bind ${spec.host}:${spec.port} without TLS; pass --tls-cert/--tls-key, or --insecure only for trusted reverse-proxy/tunnel deployments`
273
- );
274
- }
195
+ function trackSetupCompleted(props) {
196
+ capture("setup.completed", props);
275
197
  }
276
198
 
277
199
  // src/infra/config/dashboardClient.ts
278
- import crypto2 from "crypto";
279
- import fs3 from "fs";
200
+ import crypto from "crypto";
201
+ import fs from "fs";
280
202
  import os3 from "os";
281
- import path3 from "path";
203
+ import path2 from "path";
282
204
  function dashboardClientConfigPath(env = process.env) {
283
205
  const home = env["HOME"] ?? os3.homedir();
284
- return path3.join(home, ".config", "athena", "dashboard.json");
206
+ return path2.join(home, ".config", "athena", "dashboard.json");
285
207
  }
286
208
  function normalizeDashboardUrl(input) {
287
209
  let parsed;
@@ -299,7 +221,7 @@ function readDashboardClientConfig(env = process.env) {
299
221
  const configPath = dashboardClientConfigPath(env);
300
222
  let raw;
301
223
  try {
302
- raw = fs3.readFileSync(configPath, "utf-8");
224
+ raw = fs.readFileSync(configPath, "utf-8");
303
225
  } catch (err) {
304
226
  if (err.code === "ENOENT") return null;
305
227
  throw err;
@@ -323,29 +245,29 @@ function readDashboardClientConfig(env = process.env) {
323
245
  function writeDashboardClientConfig(config, env = process.env) {
324
246
  const validated = parseDashboardClientConfig(config);
325
247
  const configPath = dashboardClientConfigPath(env);
326
- const dir = path3.dirname(configPath);
327
- fs3.mkdirSync(dir, { recursive: true, mode: 448 });
328
- const tmpPath = `${configPath}.${process.pid}.${crypto2.randomBytes(4).toString("hex")}.tmp`;
329
- const fd = fs3.openSync(tmpPath, "w", 384);
248
+ const dir = path2.dirname(configPath);
249
+ fs.mkdirSync(dir, { recursive: true, mode: 448 });
250
+ const tmpPath = `${configPath}.${process.pid}.${crypto.randomBytes(4).toString("hex")}.tmp`;
251
+ const fd = fs.openSync(tmpPath, "w", 384);
330
252
  try {
331
- fs3.writeSync(fd, JSON.stringify(validated, null, 2) + "\n");
332
- fs3.fsyncSync(fd);
253
+ fs.writeSync(fd, JSON.stringify(validated, null, 2) + "\n");
254
+ fs.fsyncSync(fd);
333
255
  } finally {
334
- fs3.closeSync(fd);
256
+ fs.closeSync(fd);
335
257
  }
336
258
  try {
337
- fs3.renameSync(tmpPath, configPath);
259
+ fs.renameSync(tmpPath, configPath);
338
260
  } catch (err) {
339
261
  try {
340
- fs3.unlinkSync(tmpPath);
262
+ fs.unlinkSync(tmpPath);
341
263
  } catch {
342
264
  }
343
265
  throw err;
344
266
  }
345
267
  if (process.platform !== "win32") {
346
268
  try {
347
- fs3.chmodSync(dir, 448);
348
- fs3.chmodSync(configPath, 384);
269
+ fs.chmodSync(dir, 448);
270
+ fs.chmodSync(configPath, 384);
349
271
  } catch {
350
272
  }
351
273
  }
@@ -353,7 +275,7 @@ function writeDashboardClientConfig(config, env = process.env) {
353
275
  function removeDashboardClientConfig(env = process.env) {
354
276
  const configPath = dashboardClientConfigPath(env);
355
277
  try {
356
- fs3.unlinkSync(configPath);
278
+ fs.unlinkSync(configPath);
357
279
  } catch (err) {
358
280
  if (err.code !== "ENOENT") throw err;
359
281
  }
@@ -392,7 +314,7 @@ function parseDashboardClientConfig(raw) {
392
314
  }
393
315
 
394
316
  // src/infra/config/dashboardAuth.ts
395
- import fs4 from "fs";
317
+ import fs2 from "fs";
396
318
  var DEFAULT_LOCK_TIMEOUT_MS = 3e4;
397
319
  var DEFAULT_LOCK_POLL_MS = 50;
398
320
  var DEFAULT_STALE_LOCK_MS = 6e4;
@@ -475,14 +397,14 @@ async function withLock(env, deps, fn) {
475
397
  let fd = null;
476
398
  for (; ; ) {
477
399
  try {
478
- fd = fs4.openSync(lockPath, "wx", 384);
400
+ fd = fs2.openSync(lockPath, "wx", 384);
479
401
  break;
480
402
  } catch (err) {
481
403
  if (err.code !== "EEXIST") throw err;
482
404
  try {
483
- const stat = fs4.statSync(lockPath);
405
+ const stat = fs2.statSync(lockPath);
484
406
  if (Date.now() - stat.mtimeMs > staleMs) {
485
- fs4.unlinkSync(lockPath);
407
+ fs2.unlinkSync(lockPath);
486
408
  continue;
487
409
  }
488
410
  } catch {
@@ -500,11 +422,11 @@ async function withLock(env, deps, fn) {
500
422
  return await fn();
501
423
  } finally {
502
424
  try {
503
- fs4.closeSync(fd);
425
+ fs2.closeSync(fd);
504
426
  } catch {
505
427
  }
506
428
  try {
507
- fs4.unlinkSync(lockPath);
429
+ fs2.unlinkSync(lockPath);
508
430
  } catch {
509
431
  }
510
432
  }
@@ -536,6 +458,23 @@ function truncate(text, max) {
536
458
  return text.length > max ? text.slice(0, max) + "\u2026" : text;
537
459
  }
538
460
 
461
+ // src/infra/gatewayTrace.ts
462
+ import fs3 from "fs";
463
+ function writeGatewayTrace(message) {
464
+ if (process.env["ATHENA_GATEWAY_TRACE"] !== "1") return;
465
+ const line = `athena-gateway: [trace] ${message}
466
+ `;
467
+ const traceFile = process.env["ATHENA_GATEWAY_TRACE_FILE"];
468
+ if (traceFile && traceFile.length > 0) {
469
+ try {
470
+ fs3.appendFileSync(traceFile, line, "utf-8");
471
+ return;
472
+ } catch {
473
+ }
474
+ }
475
+ process.stderr.write(line);
476
+ }
477
+
539
478
  // src/gateway/transport/types.ts
540
479
  var TransportUnreachableError = class extends Error {
541
480
  constructor(message) {
@@ -566,9 +505,9 @@ function redactFrame(value) {
566
505
  }
567
506
 
568
507
  // src/gateway/transport/uds.ts
569
- import fs5 from "fs";
508
+ import fs4 from "fs";
570
509
  import net from "net";
571
- import path4 from "path";
510
+ import path3 from "path";
572
511
 
573
512
  // src/gateway/transport/framing.ts
574
513
  var DEFAULT_MAX_LINE_BYTES = 1024 * 1024;
@@ -628,7 +567,7 @@ function createUdsClientTransport(opts) {
628
567
  async function listenUds(opts, onConnection) {
629
568
  const logError = opts.logError ?? ((m) => process.stderr.write(m + "\n"));
630
569
  await unlinkIfStale(opts.socketPath);
631
- fs5.mkdirSync(path4.dirname(opts.socketPath), { recursive: true, mode: 448 });
570
+ fs4.mkdirSync(path3.dirname(opts.socketPath), { recursive: true, mode: 448 });
632
571
  const activeSockets = /* @__PURE__ */ new Set();
633
572
  const server = net.createServer({ pauseOnConnect: false }, (socket) => {
634
573
  activeSockets.add(socket);
@@ -642,7 +581,7 @@ async function listenUds(opts, onConnection) {
642
581
  server.off("error", onError);
643
582
  try {
644
583
  if (process.platform !== "win32") {
645
- fs5.chmodSync(opts.socketPath, 384);
584
+ fs4.chmodSync(opts.socketPath, 384);
646
585
  }
647
586
  } catch (err) {
648
587
  logError(
@@ -660,7 +599,7 @@ async function listenUds(opts, onConnection) {
660
599
  activeSockets.clear();
661
600
  server.close(() => {
662
601
  try {
663
- fs5.unlinkSync(opts.socketPath);
602
+ fs4.unlinkSync(opts.socketPath);
664
603
  } catch {
665
604
  }
666
605
  resolve();
@@ -699,7 +638,7 @@ async function connectUds(opts) {
699
638
  return createSocketConnection(socket, "uds");
700
639
  }
701
640
  async function unlinkIfStale(socketPath) {
702
- if (!fs5.existsSync(socketPath)) return;
641
+ if (!fs4.existsSync(socketPath)) return;
703
642
  const alive = await new Promise((resolve) => {
704
643
  const probe = net.connect(socketPath);
705
644
  const timer = setTimeout(() => {
@@ -718,7 +657,7 @@ async function unlinkIfStale(socketPath) {
718
657
  });
719
658
  if (!alive) {
720
659
  try {
721
- fs5.unlinkSync(socketPath);
660
+ fs4.unlinkSync(socketPath);
722
661
  } catch {
723
662
  }
724
663
  }
@@ -825,10 +764,7 @@ export {
825
764
  trackGatewayTransportReconnect,
826
765
  trackGatewayRuntimeRebind,
827
766
  trackGatewayRuntimeExpired,
828
- loadOrCreateToken,
829
- rotateGatewayToken,
830
- timingSafeTokenEqual,
831
- requireTokenForBind,
767
+ trackSetupCompleted,
832
768
  dashboardClientConfigPath,
833
769
  normalizeDashboardUrl,
834
770
  readDashboardClientConfig,
@@ -836,4 +772,4 @@ export {
836
772
  removeDashboardClientConfig,
837
773
  refreshDashboardAccessToken
838
774
  };
839
- //# sourceMappingURL=chunk-3FVULBV4.js.map
775
+ //# sourceMappingURL=chunk-4CRZXLIP.js.map