skydive-cli 0.2.0-beta.605 → 0.2.0-beta.606

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/js/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { A as getPromptHistoryPath, B as resolveSession, C as API_KEY_PREFIX, D as deleteConfig, E as DEFAULT_WEB_URL, F as getStoredApiKeyWorkspaceName, G as setLastSeenVersion, H as saveConfig, I as getUpdateCheckDisabled, L as resolveAppUrl, N as getShareMachineDefault, O as getConfigPath, P as getStoredApiKeyId, R as resolveConfig, S as API_KEY_FAMILY_PREFIX, U as saveSession, _ as getActiveWorkspaceId, b as setActiveWorkspace, g as ensureActiveOrganization, k as getLastSeenVersion, m as themes, r as brandHelpArt, v as getSessionIdentity, w as DEFAULT_API_URL, x as API_KEYS_URL, y as listWorkspaces, z as resolveManagementAuth } from "./brand-BVALAEf1.mjs";
2
+ import { A as deleteConfig, B as resolveAppUrl, C as setActiveWorkspace, D as DEFAULT_API_URL, E as API_KEY_PREFIX, G as saveConfig, H as resolveManagementAuth, I as getShareMachineDefault, J as setLastSeenVersion, K as saveSession, L as getStoredApiKeyId, M as getLastSeenVersion, N as getPromptHistoryPath, R as getStoredApiKeyWorkspaceName, S as listWorkspaces, T as API_KEY_FAMILY_PREFIX, U as resolveSession, V as resolveConfig, X as version, Y as name, _ as themes, b as getActiveWorkspaceId, j as getConfigPath, k as DEFAULT_WEB_URL, o as brandHelpArt, t as installCrashHandler, w as API_KEYS_URL, x as getSessionIdentity, y as ensureActiveOrganization, z as getUpdateCheckDisabled } from "./install-CUhhdQ1L.mjs";
3
3
  import { n as printError, r as printTable, t as output } from "./output-B4cW10Ph.mjs";
4
4
  import { n as createRestClient } from "./rest-DMpigwmN.mjs";
5
5
  import { i as resolveAgent } from "./print-6Bm51XhR.mjs";
@@ -18,11 +18,6 @@ import fs from "node:fs";
18
18
  import zlib from "node:zlib";
19
19
  import semver from "semver";
20
20
 
21
- //#region package.json
22
- var name = "skydive-cli";
23
- var version = "0.2.0-beta.605";
24
-
25
- //#endregion
26
21
  //#region src/types.ts
27
22
  const NON_INTERACTIVE_ENV_VARS = [
28
23
  "CI",
@@ -1200,7 +1195,7 @@ const importCommand = {
1200
1195
  process.exit(1);
1201
1196
  }
1202
1197
  }
1203
- const { runChat } = await import("./boot-B_I9v5NI.mjs");
1198
+ const { runChat } = await import("./boot-0dKnbAAn.mjs");
1204
1199
  await runChat({
1205
1200
  appUrl,
1206
1201
  sessionToken: session.value.sessionToken,
@@ -1516,7 +1511,7 @@ const chatCommand = {
1516
1511
  printError(`Unknown theme "${themeId}". Valid themes: ${themes.map((t) => t.id).join(", ")}`);
1517
1512
  process.exit(1);
1518
1513
  }
1519
- const { runChat } = await import("./boot-B_I9v5NI.mjs");
1514
+ const { runChat } = await import("./boot-0dKnbAAn.mjs");
1520
1515
  await runChat({
1521
1516
  appUrl,
1522
1517
  sessionToken: session.value.sessionToken,
@@ -1824,7 +1819,7 @@ const switchCommand = {
1824
1819
  printError("The workspace picker needs the Bun runtime and it could not be set up automatically. Pass a workspace slug instead, or install Bun and retry.");
1825
1820
  process.exit(1);
1826
1821
  }
1827
- const { runWorkspacePicker } = await import("./boot-B_I9v5NI.mjs");
1822
+ const { runWorkspacePicker } = await import("./boot-0dKnbAAn.mjs");
1828
1823
  await runWorkspacePicker(session);
1829
1824
  return;
1830
1825
  }
@@ -2616,6 +2611,7 @@ function maybePrintWhatsNew({ stderrIsTTY = process.stderr.isTTY ?? false, nonIn
2616
2611
 
2617
2612
  //#endregion
2618
2613
  //#region src/bin.ts
2614
+ installCrashHandler();
2619
2615
  if (process.argv.includes(UPDATE_WORKER_FLAG)) {
2620
2616
  await runUpdateCheckWorker();
2621
2617
  process.exit(0);
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { M as getSavedTheme, O as getConfigPath, T as DEFAULT_APP_URL, V as resolveWebUrl, W as saveTheme, _ as getActiveWorkspaceId, a as applyTheme, b as setActiveWorkspace, c as noColorRequested, d as themeMode, f as themeModeFromColorFgBg, h as themesForMode, i as DEFAULT_THEME_ID, j as getReviewStateDir, l as theme, n as WORDMARK, o as findTheme, p as themeVersion, s as monoTheme, t as MARK_CELLS, u as themeForMode, w as DEFAULT_API_URL, y as listWorkspaces } from "./brand-BVALAEf1.mjs";
2
+ import { C as setActiveWorkspace, D as DEFAULT_API_URL, F as getSavedTheme, O as DEFAULT_APP_URL, P as getReviewStateDir, S as listWorkspaces, W as resolveWebUrl, a as WORDMARK, b as getActiveWorkspaceId, c as applyTheme, d as noColorRequested, f as theme, g as themeVersion, h as themeModeFromColorFgBg, i as MARK_CELLS, j as getConfigPath, l as findTheme, m as themeMode, n as buildCrashReport, p as themeForMode, q as saveTheme, r as writeCrashReport, s as DEFAULT_THEME_ID, t as installCrashHandler, u as monoTheme, v as themesForMode } from "./install-CUhhdQ1L.mjs";
3
3
  import { a as errorMessage, i as sendErrorMessage, n as createRestClient, o as isRecord, r as errorDetail, t as HttpError } from "./rest-DMpigwmN.mjs";
4
4
  import { c as cardActionErrorMessage, d as reconcileMaskedInput, f as resolveConnectUrl, i as resolveAgent, l as parseExternalOauthConnectParams, m as specKeyFor, p as parseConnectCard, s as MASK_CHAR, u as parseOauthConnectParams } from "./print-6Bm51XhR.mjs";
5
5
  import "./api-BGWcPuik.mjs";
@@ -11216,6 +11216,126 @@ var LinkifiedMarkdownRenderable = class extends MarkdownRenderable {
11216
11216
  }
11217
11217
  };
11218
11218
 
11219
+ //#endregion
11220
+ //#region src/chat/memory-watchdog.ts
11221
+ const MB = 1024 * 1024;
11222
+ /** How often to sample RSS. */
11223
+ const DEFAULT_SAMPLE_INTERVAL_MS = 15e3;
11224
+ /**
11225
+ * Soft threshold: cross it and we warn the user once. A healthy chat session
11226
+ * sits in the low hundreds of MB, so 2 GB is "something is wrong" without
11227
+ * being so eager it fires on a legitimately large conversation.
11228
+ */
11229
+ const DEFAULT_WARN_THRESHOLD_BYTES = 2 * 1024 * MB;
11230
+ /**
11231
+ * A clean exit still writes a report if the peak got this high — so we learn
11232
+ * about near-misses that didn't quite OOM, not just the crashes.
11233
+ */
11234
+ const DEFAULT_REPORT_THRESHOLD_BYTES = 4 * 1024 * MB;
11235
+ /** Keep the last N samples so the report shows a growth curve, not a point. */
11236
+ const MAX_SAMPLES = 240;
11237
+ function envBytes(name, fallback) {
11238
+ const raw = process.env[name];
11239
+ if (!raw) return fallback;
11240
+ const n = Number(raw);
11241
+ return Number.isFinite(n) && n > 0 ? n : fallback;
11242
+ }
11243
+ function envMs(name, fallback) {
11244
+ const raw = process.env[name];
11245
+ if (!raw) return fallback;
11246
+ const n = Number(raw);
11247
+ return Number.isFinite(n) && n > 0 ? n : fallback;
11248
+ }
11249
+ /**
11250
+ * Start the memory watchdog. Returns a handle; call `stop()` on teardown.
11251
+ *
11252
+ * Disabled entirely when `SKYDIVE_NO_MEMORY_WATCHDOG` is set — an escape
11253
+ * hatch that also keeps the sampler out of the way in tests and CI.
11254
+ */
11255
+ function startMemoryWatchdog(opts = {}) {
11256
+ const disabled = Boolean(process.env["SKYDIVE_NO_MEMORY_WATCHDOG"]);
11257
+ const now = opts.now ?? (() => Date.now());
11258
+ const readMemory = opts.readMemory ?? (() => {
11259
+ const u = process.memoryUsage();
11260
+ return {
11261
+ rss: u.rss,
11262
+ heapUsed: u.heapUsed
11263
+ };
11264
+ });
11265
+ const sampleIntervalMs = opts.sampleIntervalMs ?? envMs("SKYDIVE_MEMORY_SAMPLE_MS", DEFAULT_SAMPLE_INTERVAL_MS);
11266
+ const warnThreshold = opts.warnThresholdBytes ?? envBytes("SKYDIVE_MEMORY_WARN_BYTES", DEFAULT_WARN_THRESHOLD_BYTES);
11267
+ const reportThreshold = opts.reportThresholdBytes ?? envBytes("SKYDIVE_MEMORY_REPORT_BYTES", DEFAULT_REPORT_THRESHOLD_BYTES);
11268
+ const startedAt = now();
11269
+ const samples = [];
11270
+ let peakRss = 0;
11271
+ let peakHeapUsed = 0;
11272
+ let warned = false;
11273
+ function sample() {
11274
+ const { rss, heapUsed } = readMemory();
11275
+ if (rss > peakRss) peakRss = rss;
11276
+ if (heapUsed > peakHeapUsed) peakHeapUsed = heapUsed;
11277
+ const s = {
11278
+ at: now() - startedAt,
11279
+ rss,
11280
+ heapUsed
11281
+ };
11282
+ samples.push(s);
11283
+ if (samples.length > MAX_SAMPLES) samples.shift();
11284
+ if (!warned && rss >= warnThreshold) {
11285
+ warned = true;
11286
+ opts.onWarn?.({
11287
+ rss,
11288
+ threshold: warnThreshold
11289
+ });
11290
+ }
11291
+ return s;
11292
+ }
11293
+ function snapshot() {
11294
+ if (disabled) return null;
11295
+ sample();
11296
+ return {
11297
+ peakRss,
11298
+ peakHeapUsed,
11299
+ warnThreshold,
11300
+ uptimeMs: now() - startedAt,
11301
+ samples: samples.slice()
11302
+ };
11303
+ }
11304
+ if (disabled) return {
11305
+ peakRss: () => 0,
11306
+ samples: () => [],
11307
+ snapshot: () => null,
11308
+ stop: () => {}
11309
+ };
11310
+ sample();
11311
+ const timer = setInterval(sample, sampleIntervalMs);
11312
+ if (typeof timer.unref === "function") timer.unref();
11313
+ const onExit = () => {
11314
+ if (peakRss < reportThreshold) return;
11315
+ writeCrashReport(buildCrashReport({
11316
+ reason: "high-memory-exit",
11317
+ memory: {
11318
+ peakRss,
11319
+ peakHeapUsed,
11320
+ warnThreshold,
11321
+ uptimeMs: now() - startedAt,
11322
+ samples: samples.slice()
11323
+ }
11324
+ }));
11325
+ };
11326
+ const installExitHandler = opts.installExitHandler ?? true;
11327
+ if (installExitHandler) process.on("exit", onExit);
11328
+ return {
11329
+ peakRss: () => peakRss,
11330
+ samples: () => samples.slice(),
11331
+ snapshot,
11332
+ stop: () => {
11333
+ clearInterval(timer);
11334
+ if (installExitHandler) process.off("exit", onExit);
11335
+ }
11336
+ };
11337
+ }
11338
+
11219
11339
  //#endregion
11220
11340
  //#region src/chat/boot.tsx
11221
11341
  /**
@@ -11225,6 +11345,8 @@ var LinkifiedMarkdownRenderable = class extends MarkdownRenderable {
11225
11345
  * dynamically imported and never loaded on the Node management path.
11226
11346
  */
11227
11347
  async function runChat({ appUrl, sessionToken, shareMachine, promptHistoryPath, theme: themeOverride, notifications, agentSelector, conversationId, newConversation, seedPrompt }) {
11348
+ const watchdog = startMemoryWatchdog();
11349
+ installCrashHandler({ memoryProvider: () => watchdog.snapshot() });
11228
11350
  const renderer = await createCliRenderer({ exitOnCtrlC: false });
11229
11351
  extend({ markdown: LinkifiedMarkdownRenderable });
11230
11352
  useStore.setState({
@@ -1,9 +1,16 @@
1
1
  #!/usr/bin/env node
2
+ import os from "node:os";
2
3
  import path from "node:path";
3
4
  import Conf from "conf";
4
5
  import { err, ok } from "neverthrow";
5
6
  import { z } from "zod";
7
+ import fs from "node:fs";
6
8
 
9
+ //#region package.json
10
+ var name = "skydive-cli";
11
+ var version$1 = "0.2.0-beta.606";
12
+
13
+ //#endregion
7
14
  //#region src/config.ts
8
15
  /** Default host for the public management API (`/v1`, API-key auth). */
9
16
  const DEFAULT_API_URL = "https://api.skydive.com";
@@ -1130,4 +1137,110 @@ function brandHelpArt(stream = process.stdout) {
1130
1137
  }
1131
1138
 
1132
1139
  //#endregion
1133
- export { getPromptHistoryPath as A, resolveSession as B, API_KEY_PREFIX as C, deleteConfig as D, DEFAULT_WEB_URL as E, getStoredApiKeyWorkspaceName as F, setLastSeenVersion as G, saveConfig as H, getUpdateCheckDisabled as I, resolveAppUrl as L, getSavedTheme as M, getShareMachineDefault as N, getConfigPath as O, getStoredApiKeyId as P, resolveConfig as R, API_KEY_FAMILY_PREFIX as S, DEFAULT_APP_URL as T, saveSession as U, resolveWebUrl as V, saveTheme as W, getActiveWorkspaceId as _, applyTheme as a, setActiveWorkspace as b, noColorRequested as c, themeMode as d, themeModeFromColorFgBg as f, ensureActiveOrganization as g, themesForMode as h, DEFAULT_THEME_ID as i, getReviewStateDir as j, getLastSeenVersion as k, theme as l, themes as m, WORDMARK as n, findTheme as o, themeVersion as p, brandHelpArt as r, monoTheme as s, MARK_CELLS as t, themeForMode as u, getSessionIdentity as v, DEFAULT_API_URL as w, API_KEYS_URL as x, listWorkspaces as y, resolveManagementAuth as z };
1140
+ //#region src/crash/report.ts
1141
+ const MB = 1024 * 1024;
1142
+ function currentRuntime() {
1143
+ const bun = process.versions["bun"];
1144
+ return bun ? `bun ${bun}` : `node ${process.version}`;
1145
+ }
1146
+ function serializeError(error) {
1147
+ if (error == null) return null;
1148
+ if (error instanceof Error) return {
1149
+ name: error.name,
1150
+ message: error.message,
1151
+ ...error.stack ? { stack: error.stack } : {}
1152
+ };
1153
+ return {
1154
+ name: "NonError",
1155
+ message: String(error)
1156
+ };
1157
+ }
1158
+ /** Directory where crash/diagnostic reports are written (beside config). */
1159
+ function getCrashDir() {
1160
+ return path.join(path.dirname(getConfigPath()), "crash");
1161
+ }
1162
+ /** Build a report object without touching disk. */
1163
+ function buildCrashReport(args) {
1164
+ return {
1165
+ reason: args.reason,
1166
+ cliVersion: version$1,
1167
+ runtime: currentRuntime(),
1168
+ platform: process.platform,
1169
+ arch: process.arch,
1170
+ nodeVersion: process.version,
1171
+ totalSystemMemory: os.totalmem(),
1172
+ error: serializeError(args.error),
1173
+ memory: args.memory ?? null,
1174
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1175
+ };
1176
+ }
1177
+ /**
1178
+ * Write a report to disk and return its path (or null if writing failed).
1179
+ * Safe to call from a fatal handler: every failure is swallowed so the
1180
+ * diagnostic can never mask the original crash.
1181
+ */
1182
+ function writeCrashReport(report) {
1183
+ try {
1184
+ const dir = getCrashDir();
1185
+ fs.mkdirSync(dir, { recursive: true });
1186
+ const stamp = report.timestamp.replace(/[:.]/g, "-");
1187
+ const file = path.join(dir, `crash-${stamp}.json`);
1188
+ fs.writeFileSync(file, `${JSON.stringify(report, null, 2)}\n`, { mode: 384 });
1189
+ return file;
1190
+ } catch (_error) {
1191
+ return null;
1192
+ }
1193
+ }
1194
+ /** Human-readable MB, one decimal. */
1195
+ function formatMb(bytes) {
1196
+ return `${(bytes / MB).toFixed(1)} MB`;
1197
+ }
1198
+
1199
+ //#endregion
1200
+ //#region src/crash/install.ts
1201
+ let installed = false;
1202
+ /**
1203
+ * Install the process-wide fatal crash handler. Idempotent: a second call is
1204
+ * a no-op, and later options (e.g. a memory provider registered once chat
1205
+ * boots) update the live handler in place.
1206
+ *
1207
+ * Disabled entirely by `SKYDIVE_NO_CRASH_REPORT` — the escape hatch, and how
1208
+ * tests keep a real handler off the shared process.
1209
+ */
1210
+ function installCrashHandler(opts = {}) {
1211
+ if (process.env["SKYDIVE_NO_CRASH_REPORT"]) return;
1212
+ memoryProvider = opts.memoryProvider ?? memoryProvider;
1213
+ writeNotice = opts.writeNotice ?? writeNotice;
1214
+ exitProcess = opts.exit ?? exitProcess;
1215
+ if (installed) return;
1216
+ installed = true;
1217
+ process.on("uncaughtException", (error) => {
1218
+ const memory = safeMemory();
1219
+ printFatalNotice(writeCrashReport(buildCrashReport({
1220
+ reason: "uncaughtException",
1221
+ error,
1222
+ memory
1223
+ })), memory);
1224
+ exitProcess(1);
1225
+ });
1226
+ }
1227
+ const defaultWriteNotice = (text) => process.stderr.write(text);
1228
+ const defaultExit = (code) => process.exit(code);
1229
+ let memoryProvider = null;
1230
+ let writeNotice = defaultWriteNotice;
1231
+ let exitProcess = defaultExit;
1232
+ function safeMemory() {
1233
+ try {
1234
+ return memoryProvider?.() ?? void 0;
1235
+ } catch (_error) {
1236
+ return;
1237
+ }
1238
+ }
1239
+ function printFatalNotice(file, memory) {
1240
+ const peak = memory ? ` (peak memory ${formatMb(memory.peakRss)})` : "";
1241
+ if (file) writeNotice(`\nskydive: the CLI hit a fatal error${peak}. A diagnostic report was written to:\n ${file}\nPlease send this file to the Skydive team so we can investigate.\n`);
1242
+ else writeNotice(`\nskydive: the CLI hit a fatal error${peak}.\n`);
1243
+ }
1244
+
1245
+ //#endregion
1246
+ export { deleteConfig as A, resolveAppUrl as B, setActiveWorkspace as C, DEFAULT_API_URL as D, API_KEY_PREFIX as E, getSavedTheme as F, saveConfig as G, resolveManagementAuth as H, getShareMachineDefault as I, setLastSeenVersion as J, saveSession as K, getStoredApiKeyId as L, getLastSeenVersion as M, getPromptHistoryPath as N, DEFAULT_APP_URL as O, getReviewStateDir as P, getStoredApiKeyWorkspaceName as R, listWorkspaces as S, API_KEY_FAMILY_PREFIX as T, resolveSession as U, resolveConfig as V, resolveWebUrl as W, version$1 as X, name as Y, themes as _, WORDMARK as a, getActiveWorkspaceId as b, applyTheme as c, noColorRequested as d, theme as f, themeVersion as g, themeModeFromColorFgBg as h, MARK_CELLS as i, getConfigPath as j, DEFAULT_WEB_URL as k, findTheme as l, themeMode as m, buildCrashReport as n, brandHelpArt as o, themeForMode as p, saveTheme as q, writeCrashReport as r, DEFAULT_THEME_ID as s, installCrashHandler as t, monoTheme as u, themesForMode as v, API_KEYS_URL as w, getSessionIdentity as x, ensureActiveOrganization as y, getUpdateCheckDisabled as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skydive-cli",
3
- "version": "0.2.0-beta.605",
3
+ "version": "0.2.0-beta.606",
4
4
  "description": "Skydive CLI — cloud agents from the command line",
5
5
  "homepage": "https://skydive.com",
6
6
  "license": "MIT",