@boxes-dev/dvb 1.0.99 → 1.0.101

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/bin/dvb.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c89c7337-d26d-5d0e-9378-e2535af1df44")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ff297307-c733-552d-a450-764919e5443b")}catch(e){}}();
4
4
 
5
5
  var __create = Object.create;
6
6
  var __defProp = Object.defineProperty;
@@ -88688,8 +88688,8 @@ var init_otel = __esm({
88688
88688
  return trimmed && trimmed.length > 0 ? trimmed : void 0;
88689
88689
  };
88690
88690
  readBuildMetadata = () => {
88691
- const rawPackageVersion = "1.0.99";
88692
- const rawGitSha = "6e1d4cbe7aabab2526d50776d8007a85d5800b43";
88691
+ const rawPackageVersion = "1.0.101";
88692
+ const rawGitSha = "c8b8a05e9a0277d607e90d7e79b10476b6854e54";
88693
88693
  const packageVersion = typeof rawPackageVersion === "string" ? rawPackageVersion : void 0;
88694
88694
  const gitSha = typeof rawGitSha === "string" ? rawGitSha : void 0;
88695
88695
  return { packageVersion, gitSha };
@@ -120679,9 +120679,9 @@ var init_sentry = __esm({
120679
120679
  sentryEnabled = false;
120680
120680
  uncaughtExceptionMonitorInstalled = false;
120681
120681
  readBuildMetadata2 = () => {
120682
- const rawPackageVersion = "1.0.99";
120683
- const rawGitSha = "6e1d4cbe7aabab2526d50776d8007a85d5800b43";
120684
- const rawSentryRelease = "boxes-dev-dvb@1.0.99+6e1d4cbe7aabab2526d50776d8007a85d5800b43";
120682
+ const rawPackageVersion = "1.0.101";
120683
+ const rawGitSha = "c8b8a05e9a0277d607e90d7e79b10476b6854e54";
120684
+ const rawSentryRelease = "boxes-dev-dvb@1.0.101+c8b8a05e9a0277d607e90d7e79b10476b6854e54";
120685
120685
  const packageVersion = typeof rawPackageVersion === "string" ? rawPackageVersion : void 0;
120686
120686
  const gitSha = typeof rawGitSha === "string" ? rawGitSha : void 0;
120687
120687
  const sentryRelease = typeof rawSentryRelease === "string" ? rawSentryRelease : void 0;
@@ -144682,6 +144682,252 @@ var init_commandProvider = __esm({
144682
144682
  }
144683
144683
  });
144684
144684
 
144685
+ // src/devbox/commands/sessionUtils.ts
144686
+ var AUTO_SESSION_PREFIX, parseAutoSessionSuffix, getNextAutoSessionName, ensureUniqueAutoSessionName, shellQuote2, sanitizeSessionName, buildSessionLogPath, renameSessionLog;
144687
+ var init_sessionUtils = __esm({
144688
+ "src/devbox/commands/sessionUtils.ts"() {
144689
+ "use strict";
144690
+ AUTO_SESSION_PREFIX = "new-session-";
144691
+ parseAutoSessionSuffix = (name) => {
144692
+ if (!name.startsWith(AUTO_SESSION_PREFIX)) return null;
144693
+ const raw = name.slice(AUTO_SESSION_PREFIX.length);
144694
+ const parsed = Number(raw);
144695
+ if (!Number.isFinite(parsed) || parsed < 1) return null;
144696
+ return Math.floor(parsed);
144697
+ };
144698
+ getNextAutoSessionName = (sessions) => {
144699
+ let max = 0;
144700
+ for (const name of Object.keys(sessions)) {
144701
+ const suffix = parseAutoSessionSuffix(name);
144702
+ if (suffix && suffix > max) max = suffix;
144703
+ }
144704
+ return `${AUTO_SESSION_PREFIX}${max + 1}`;
144705
+ };
144706
+ ensureUniqueAutoSessionName = (sessions, preferred, sessionId) => {
144707
+ const start = parseAutoSessionSuffix(preferred) ?? 1;
144708
+ let current = preferred;
144709
+ let counter = start;
144710
+ while (sessions[current] && sessions[current] !== sessionId) {
144711
+ counter += 1;
144712
+ current = `${AUTO_SESSION_PREFIX}${counter}`;
144713
+ }
144714
+ return current;
144715
+ };
144716
+ shellQuote2 = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
144717
+ sanitizeSessionName = (value) => {
144718
+ const trimmed = value.trim();
144719
+ const sanitized = trimmed.replace(/[^a-zA-Z0-9._-]/g, "_");
144720
+ return sanitized || "session";
144721
+ };
144722
+ buildSessionLogPath = (name, remoteHome = "/home/sprite") => `${remoteHome}/.devbox/logs/${sanitizeSessionName(name)}.log`;
144723
+ renameSessionLog = async (client2, box, fromName, toName, remoteHome = "/home/sprite") => {
144724
+ const fromPath = buildSessionLogPath(fromName, remoteHome);
144725
+ const toPath = buildSessionLogPath(toName, remoteHome);
144726
+ if (fromPath === toPath) return;
144727
+ await client2.exec(box, [
144728
+ "/bin/bash",
144729
+ "-lc",
144730
+ `if [ -f ${shellQuote2(fromPath)} ]; then mv ${shellQuote2(fromPath)} ${shellQuote2(toPath)}; fi`
144731
+ ]);
144732
+ };
144733
+ }
144734
+ });
144735
+
144736
+ // src/devbox/commands/connectSessionMapping.ts
144737
+ var SESSION_NAME_TOKEN_KEY, decodeSessionNameToken, extractSessionNameFromCommand, readSessionMapSafe, initializeSessionMapState, refreshSessionMapState, finalizeAutoNamedSession, renameMappedSession;
144738
+ var init_connectSessionMapping = __esm({
144739
+ "src/devbox/commands/connectSessionMapping.ts"() {
144740
+ "use strict";
144741
+ init_src();
144742
+ init_sessionUtils();
144743
+ SESSION_NAME_TOKEN_KEY = "DEVBOX_SESSION_NAME_B64";
144744
+ decodeSessionNameToken = (value) => {
144745
+ try {
144746
+ const decoded = Buffer.from(value, "base64url").toString("utf8").trim();
144747
+ return decoded.length > 0 ? decoded : null;
144748
+ } catch {
144749
+ return null;
144750
+ }
144751
+ };
144752
+ extractSessionNameFromCommand = (command) => {
144753
+ if (!command || command.length < 3) return null;
144754
+ const script = command.slice(2).join(" ");
144755
+ const patterns = [
144756
+ new RegExp(`${SESSION_NAME_TOKEN_KEY}='([^']+)'`),
144757
+ new RegExp(`${SESSION_NAME_TOKEN_KEY}="([^"]+)"`)
144758
+ ];
144759
+ for (const pattern of patterns) {
144760
+ const match2 = script.match(pattern);
144761
+ if (!match2?.[1]) continue;
144762
+ const decoded = decodeSessionNameToken(match2[1]);
144763
+ if (decoded) return decoded;
144764
+ }
144765
+ return null;
144766
+ };
144767
+ readSessionMapSafe = async ({
144768
+ client: client2,
144769
+ alias,
144770
+ fallback: fallback2,
144771
+ onWarn
144772
+ }) => {
144773
+ try {
144774
+ return await readSpriteSessions(client2, alias);
144775
+ } catch (error2) {
144776
+ onWarn("sessions_read_failed", { error: String(error2) });
144777
+ return fallback2;
144778
+ }
144779
+ };
144780
+ initializeSessionMapState = async ({
144781
+ client: client2,
144782
+ alias,
144783
+ sessionName,
144784
+ autoNameRequested,
144785
+ onWarn
144786
+ }) => {
144787
+ const sessions = sessionName || autoNameRequested ? await readSessionMapSafe({
144788
+ client: client2,
144789
+ alias,
144790
+ fallback: {},
144791
+ onWarn
144792
+ }) : {};
144793
+ const resolvedSessionName = !sessionName && autoNameRequested ? getNextAutoSessionName(sessions) : sessionName;
144794
+ const autoNamed = !sessionName && Boolean(autoNameRequested);
144795
+ return {
144796
+ sessions,
144797
+ sessionName: resolvedSessionName,
144798
+ autoNamed,
144799
+ requireFreshSessionOpen: autoNamed
144800
+ };
144801
+ };
144802
+ refreshSessionMapState = async ({
144803
+ client: client2,
144804
+ alias,
144805
+ computeProvider,
144806
+ supportsAttachExecSession,
144807
+ supportsListExecSessions,
144808
+ sessionName,
144809
+ sessionId,
144810
+ sessions,
144811
+ requireFreshSessionOpen,
144812
+ explicitName,
144813
+ onWarn
144814
+ }) => {
144815
+ if (!supportsAttachExecSession || !sessionName) {
144816
+ return {
144817
+ sessions,
144818
+ sessionId,
144819
+ confirmedCreateExplicit: Boolean(sessionId && explicitName)
144820
+ };
144821
+ }
144822
+ const latest = await readSessionMapSafe({
144823
+ client: client2,
144824
+ alias,
144825
+ fallback: sessions,
144826
+ onWarn
144827
+ });
144828
+ if (requireFreshSessionOpen) {
144829
+ return {
144830
+ sessions: latest,
144831
+ sessionId,
144832
+ confirmedCreateExplicit: Boolean(sessionId && explicitName)
144833
+ };
144834
+ }
144835
+ let resolvedSessionId = latest[sessionName];
144836
+ if (!resolvedSessionId && computeProvider === "modal" && supportsListExecSessions) {
144837
+ const available = await client2.listExecSessions(alias);
144838
+ const matched = available.find(
144839
+ (session) => session.tty !== false && extractSessionNameFromCommand(session.command) === sessionName
144840
+ );
144841
+ if (matched) {
144842
+ resolvedSessionId = matched.id;
144843
+ latest[sessionName] = matched.id;
144844
+ await writeSpriteSessions(client2, alias, latest);
144845
+ }
144846
+ }
144847
+ if (resolvedSessionId && supportsListExecSessions && computeProvider !== "modal") {
144848
+ const available = await client2.listExecSessions(alias);
144849
+ const match2 = available.find((session) => session.id === resolvedSessionId);
144850
+ if (!match2 || match2.tty === false) {
144851
+ delete latest[sessionName];
144852
+ resolvedSessionId = void 0;
144853
+ await writeSpriteSessions(client2, alias, latest);
144854
+ }
144855
+ }
144856
+ return {
144857
+ sessions: latest,
144858
+ sessionId: resolvedSessionId,
144859
+ confirmedCreateExplicit: Boolean(resolvedSessionId && explicitName)
144860
+ };
144861
+ };
144862
+ finalizeAutoNamedSession = async ({
144863
+ client: client2,
144864
+ alias,
144865
+ autoNamed,
144866
+ sessionName,
144867
+ sessionId,
144868
+ sessions,
144869
+ remoteHome,
144870
+ onWarn
144871
+ }) => {
144872
+ if (!autoNamed || !sessionName) {
144873
+ return { sessionName, sessions, renamed: false };
144874
+ }
144875
+ const latest = await readSessionMapSafe({
144876
+ client: client2,
144877
+ alias,
144878
+ fallback: sessions,
144879
+ onWarn
144880
+ });
144881
+ const uniqueName = ensureUniqueAutoSessionName(
144882
+ latest,
144883
+ sessionName,
144884
+ sessionId
144885
+ );
144886
+ const renamed = uniqueName !== sessionName;
144887
+ if (renamed) {
144888
+ await renameSessionLog(client2, alias, sessionName, uniqueName, remoteHome);
144889
+ }
144890
+ latest[uniqueName] = sessionId;
144891
+ await writeSpriteSessions(client2, alias, latest);
144892
+ return { sessionName: uniqueName, sessions: latest, renamed };
144893
+ };
144894
+ renameMappedSession = async ({
144895
+ client: client2,
144896
+ alias,
144897
+ fromName,
144898
+ toName,
144899
+ expectedId,
144900
+ remoteHome,
144901
+ sessions
144902
+ }) => {
144903
+ const latest = await readSessionMapSafe({
144904
+ client: client2,
144905
+ alias,
144906
+ fallback: sessions,
144907
+ onWarn: () => {
144908
+ }
144909
+ });
144910
+ const currentId = latest[fromName];
144911
+ if (!currentId) {
144912
+ throw new Error(`Session "${fromName}" not found.`);
144913
+ }
144914
+ if (currentId !== expectedId) {
144915
+ throw new Error(
144916
+ `Session "${fromName}" no longer matches the active session.`
144917
+ );
144918
+ }
144919
+ if (latest[toName] && latest[toName] !== expectedId) {
144920
+ throw new Error(`Session "${toName}" already exists.`);
144921
+ }
144922
+ delete latest[fromName];
144923
+ latest[toName] = expectedId;
144924
+ await writeSpriteSessions(client2, alias, latest);
144925
+ await renameSessionLog(client2, alias, fromName, toName, remoteHome);
144926
+ return latest;
144927
+ };
144928
+ }
144929
+ });
144930
+
144685
144931
  // ../../node_modules/nice-grpc-common/lib/Metadata.js
144686
144932
  var require_Metadata = __commonJS({
144687
144933
  "../../node_modules/nice-grpc-common/lib/Metadata.js"(exports2) {
@@ -199146,6 +199392,9 @@ var init_modalLifecycle = __esm({
199146
199392
  "-lc",
199147
199393
  [
199148
199394
  "set -u",
199395
+ // PID 1 in Modal should ignore common termination signals so accidental
199396
+ // `kill 1` does not terminate the sandbox.
199397
+ "trap '' HUP INT QUIT TERM USR1 USR2 PIPE",
199149
199398
  `wrapper=${JSON.stringify(MODAL_DAEMON_WRAPPER_PATH)}`,
199150
199399
  'until [ -x "$wrapper" ]; do sleep 0.25; done',
199151
199400
  "while true; do",
@@ -201293,59 +201542,8 @@ var init_modalCommandContext = __esm({
201293
201542
  }
201294
201543
  });
201295
201544
 
201296
- // src/devbox/commands/sessionUtils.ts
201297
- var AUTO_SESSION_PREFIX, parseAutoSessionSuffix, getNextAutoSessionName, ensureUniqueAutoSessionName, shellQuote2, sanitizeSessionName, buildSessionLogPath, renameSessionLog;
201298
- var init_sessionUtils = __esm({
201299
- "src/devbox/commands/sessionUtils.ts"() {
201300
- "use strict";
201301
- AUTO_SESSION_PREFIX = "new-session-";
201302
- parseAutoSessionSuffix = (name) => {
201303
- if (!name.startsWith(AUTO_SESSION_PREFIX)) return null;
201304
- const raw = name.slice(AUTO_SESSION_PREFIX.length);
201305
- const parsed = Number(raw);
201306
- if (!Number.isFinite(parsed) || parsed < 1) return null;
201307
- return Math.floor(parsed);
201308
- };
201309
- getNextAutoSessionName = (sessions) => {
201310
- let max = 0;
201311
- for (const name of Object.keys(sessions)) {
201312
- const suffix = parseAutoSessionSuffix(name);
201313
- if (suffix && suffix > max) max = suffix;
201314
- }
201315
- return `${AUTO_SESSION_PREFIX}${max + 1}`;
201316
- };
201317
- ensureUniqueAutoSessionName = (sessions, preferred, sessionId) => {
201318
- const start = parseAutoSessionSuffix(preferred) ?? 1;
201319
- let current = preferred;
201320
- let counter = start;
201321
- while (sessions[current] && sessions[current] !== sessionId) {
201322
- counter += 1;
201323
- current = `${AUTO_SESSION_PREFIX}${counter}`;
201324
- }
201325
- return current;
201326
- };
201327
- shellQuote2 = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
201328
- sanitizeSessionName = (value) => {
201329
- const trimmed = value.trim();
201330
- const sanitized = trimmed.replace(/[^a-zA-Z0-9._-]/g, "_");
201331
- return sanitized || "session";
201332
- };
201333
- buildSessionLogPath = (name, remoteHome = "/home/sprite") => `${remoteHome}/.devbox/logs/${sanitizeSessionName(name)}.log`;
201334
- renameSessionLog = async (client2, box, fromName, toName, remoteHome = "/home/sprite") => {
201335
- const fromPath = buildSessionLogPath(fromName, remoteHome);
201336
- const toPath = buildSessionLogPath(toName, remoteHome);
201337
- if (fromPath === toPath) return;
201338
- await client2.exec(box, [
201339
- "/bin/bash",
201340
- "-lc",
201341
- `if [ -f ${shellQuote2(fromPath)} ]; then mv ${shellQuote2(fromPath)} ${shellQuote2(toPath)}; fi`
201342
- ]);
201343
- };
201344
- }
201345
- });
201346
-
201347
201545
  // src/devbox/commands/connect.ts
201348
- var import_node_child_process4, import_node_crypto10, import_node_os9, import_node_path16, import_node_readline3, import_promises13, resolveInitialSessionId, shouldAttachToExistingSession, resolveSessionSpecifierFromExplicitTarget, isAttachReplacedCloseCode, shouldCancelConnectOnSigint, isRawCtrlCChunk, DEFAULT_TTY_COLS, DEFAULT_TTY_ROWS, TERMINAL_INPUT_MODE_RESET, resetTerminalInputModes, openBrowser2, warnSetupStatus, resolveTtyEnv, formatEnvExports, buildModalInteractiveCommand, parseEnvSize, readStreamSize, resolveTtySize, resolveSessionEnv, parseReachabilityState, runCommand, checkReachability, watchReachabilityWithScutil, watchReachabilityWithNotifyutil, waitForNetworkOnline, parseConnectArgs, parseConnectTarget, isSessionNotFoundError, SESSION_NAME_TOKEN_KEY, encodeSessionNameToken, decodeSessionNameToken, extractSessionNameFromCommand, SESSION_LOG_FLUSH_BYTES, SESSION_LOG_EOF_MARKER, createRemoteSessionLogSink, CONNECT_SHELL_CANDIDATES, resolveConnectShell, confirmNewSession, promptRenameSession, CONNECT_OPEN_TIMEOUT_MS2, runConnect;
201546
+ var import_node_child_process4, import_node_crypto10, import_node_os9, import_node_path16, import_node_readline3, import_promises13, resolveInitialSessionId, shouldAttachToExistingSession, resolveSessionSpecifierFromExplicitTarget, isAttachReplacedCloseCode, shouldCancelConnectOnSigint, isRawCtrlCChunk, DEFAULT_TTY_COLS, DEFAULT_TTY_ROWS, TERMINAL_INPUT_MODE_RESET, resetTerminalInputModes, openBrowser2, warnSetupStatus, resolveTtyEnv, formatEnvExports, buildModalInteractiveCommand, parseEnvSize, readStreamSize, resolveTtySize, resolveSessionEnv, parseReachabilityState, runCommand, checkReachability, watchReachabilityWithScutil, watchReachabilityWithNotifyutil, waitForNetworkOnline, parseConnectArgs, parseConnectTarget, isSessionNotFoundError, SESSION_NAME_TOKEN_KEY2, encodeSessionNameToken, SESSION_LOG_FLUSH_BYTES, SESSION_LOG_EOF_MARKER, createRemoteSessionLogSink, CONNECT_SHELL_CANDIDATES, resolveConnectShell, confirmNewSession, promptRenameSession, CONNECT_OPEN_TIMEOUT_MS2, runConnect;
201349
201547
  var init_connect2 = __esm({
201350
201548
  "src/devbox/commands/connect.ts"() {
201351
201549
  "use strict";
@@ -201366,6 +201564,7 @@ var init_connect2 = __esm({
201366
201564
  init_completions();
201367
201565
  init_boxSelect();
201368
201566
  init_commandProvider();
201567
+ init_connectSessionMapping();
201369
201568
  init_providerClient();
201370
201569
  init_modalCommandContext();
201371
201570
  init_sessionUtils();
@@ -201474,10 +201673,7 @@ var init_connect2 = __esm({
201474
201673
  return env2;
201475
201674
  };
201476
201675
  formatEnvExports = (env2) => Object.entries(env2).map(([key, value]) => `export ${key}=${shellQuote2(value)}`).join("; ");
201477
- buildModalInteractiveCommand = ({ tty: tty2 }) => {
201478
- const nonCanonicalPrelude = tty2 ? "stty -icanon min 1 time 0 -echoctl; " : "";
201479
- return `${nonCanonicalPrelude}exec bash -il || exec sh -i`;
201480
- };
201676
+ buildModalInteractiveCommand = () => "exec bash -il || exec sh -i";
201481
201677
  parseEnvSize = (value) => {
201482
201678
  if (!value) return void 0;
201483
201679
  const parsed = Number(value);
@@ -201507,7 +201703,7 @@ var init_connect2 = __esm({
201507
201703
  const env2 = {};
201508
201704
  if (terminalSessionId) env2.DEVBOX_TERM_SESSION_ID = terminalSessionId;
201509
201705
  if (sessionName) {
201510
- env2[SESSION_NAME_TOKEN_KEY] = encodeSessionNameToken(sessionName);
201706
+ env2[SESSION_NAME_TOKEN_KEY2] = encodeSessionNameToken(sessionName);
201511
201707
  }
201512
201708
  return env2;
201513
201709
  };
@@ -201755,31 +201951,8 @@ var init_connect2 = __esm({
201755
201951
  const normalized = message.trim().toLowerCase();
201756
201952
  return normalized.includes("session") && normalized.includes("not found");
201757
201953
  };
201758
- SESSION_NAME_TOKEN_KEY = "DEVBOX_SESSION_NAME_B64";
201954
+ SESSION_NAME_TOKEN_KEY2 = "DEVBOX_SESSION_NAME_B64";
201759
201955
  encodeSessionNameToken = (sessionName) => Buffer.from(sessionName, "utf8").toString("base64url");
201760
- decodeSessionNameToken = (value) => {
201761
- try {
201762
- const decoded = Buffer.from(value, "base64url").toString("utf8").trim();
201763
- return decoded.length > 0 ? decoded : null;
201764
- } catch {
201765
- return null;
201766
- }
201767
- };
201768
- extractSessionNameFromCommand = (command) => {
201769
- if (!command || command.length < 3) return null;
201770
- const script = command.slice(2).join(" ");
201771
- const patterns = [
201772
- new RegExp(`${SESSION_NAME_TOKEN_KEY}='([^']+)'`),
201773
- new RegExp(`${SESSION_NAME_TOKEN_KEY}="([^"]+)"`)
201774
- ];
201775
- for (const pattern of patterns) {
201776
- const match2 = script.match(pattern);
201777
- if (!match2?.[1]) continue;
201778
- const decoded = decodeSessionNameToken(match2[1]);
201779
- if (decoded) return decoded;
201780
- }
201781
- return null;
201782
- };
201783
201956
  SESSION_LOG_FLUSH_BYTES = 24 * 1024;
201784
201957
  SESSION_LOG_EOF_MARKER = "__DVB_LOG_EOF__";
201785
201958
  createRemoteSessionLogSink = (client2, spriteAlias, logPath) => {
@@ -202217,20 +202390,18 @@ var init_connect2 = __esm({
202217
202390
  });
202218
202391
  }
202219
202392
  const connectShell = computeProvider === "modal" ? "/bin/bash" : await resolveConnectShell(client2, spriteAlias);
202220
- const readSessionsSafe = async (fallback2) => {
202221
- try {
202222
- return await readSpriteSessions(client2, spriteAlias);
202223
- } catch (error2) {
202224
- logger8.warn("sessions_read_failed", { error: String(error2) });
202225
- return fallback2;
202226
- }
202227
- };
202228
- let sessions = sessionName || autoNameRequested ? await readSessionsSafe({}) : {};
202229
- if (!sessionName && autoNameRequested) {
202230
- sessionName = getNextAutoSessionName(sessions);
202231
- autoNamed = true;
202232
- }
202233
- let requireFreshSessionOpen = autoNamed;
202393
+ const warnSessionMap = (event, fields) => logger8.warn(event, fields);
202394
+ const initialSessionState = await initializeSessionMapState({
202395
+ client: client2,
202396
+ alias: spriteAlias,
202397
+ sessionName,
202398
+ autoNameRequested,
202399
+ onWarn: warnSessionMap
202400
+ });
202401
+ let sessions = initialSessionState.sessions;
202402
+ sessionName = initialSessionState.sessionName;
202403
+ autoNamed = initialSessionState.autoNamed;
202404
+ let requireFreshSessionOpen = initialSessionState.requireFreshSessionOpen;
202234
202405
  let sessionId = resolveInitialSessionId({
202235
202406
  supportsAttachExecSession,
202236
202407
  sessionIdOverride,
@@ -202247,78 +202418,53 @@ var init_connect2 = __esm({
202247
202418
  }
202248
202419
  }
202249
202420
  const refreshSessionMapping = async () => {
202250
- if (!supportsAttachExecSession) return;
202251
- if (!sessionName) return;
202252
- sessions = await readSessionsSafe(sessions);
202253
- if (requireFreshSessionOpen) {
202254
- return;
202255
- }
202256
- sessionId = sessions[sessionName];
202257
- if (!sessionId && computeProvider === "modal" && supportsListExecSessions) {
202258
- const available = await client2.listExecSessions(spriteAlias);
202259
- const matched = available.find(
202260
- (session) => session.tty !== false && extractSessionNameFromCommand(session.command) === sessionName
202261
- );
202262
- if (matched) {
202263
- sessionId = matched.id;
202264
- sessions[sessionName] = matched.id;
202265
- await writeSpriteSessions(client2, spriteAlias, sessions);
202266
- }
202267
- }
202268
- if (sessionId && supportsListExecSessions && computeProvider !== "modal") {
202269
- const available = await client2.listExecSessions(spriteAlias);
202270
- const match2 = available.find((session) => session.id === sessionId);
202271
- if (!match2 || match2.tty === false) {
202272
- delete sessions[sessionName];
202273
- sessionId = void 0;
202274
- await writeSpriteSessions(client2, spriteAlias, sessions);
202275
- }
202276
- }
202277
- if (sessionId && explicitName) {
202421
+ const refreshed = await refreshSessionMapState({
202422
+ client: client2,
202423
+ alias: spriteAlias,
202424
+ computeProvider,
202425
+ supportsAttachExecSession,
202426
+ supportsListExecSessions,
202427
+ sessionName,
202428
+ sessionId,
202429
+ sessions,
202430
+ requireFreshSessionOpen,
202431
+ explicitName,
202432
+ onWarn: warnSessionMap
202433
+ });
202434
+ sessions = refreshed.sessions;
202435
+ sessionId = refreshed.sessionId;
202436
+ if (refreshed.confirmedCreateExplicit) {
202278
202437
  confirmedCreateExplicit = true;
202279
202438
  }
202280
202439
  };
202281
202440
  const remoteHome = computeProvider === "modal" ? "/root" : "/home/sprite";
202282
202441
  const finalizeAutoSession = async (id) => {
202283
- if (!autoNamed || !sessionName) return;
202284
- const latest = await readSessionsSafe(sessions);
202285
- sessions = latest;
202286
- const uniqueName = ensureUniqueAutoSessionName(latest, sessionName, id);
202287
- const previousName = sessionName;
202288
- if (uniqueName !== sessionName) {
202289
- sessionName = uniqueName;
202290
- await renameSessionLog(
202291
- client2,
202292
- spriteAlias,
202293
- previousName,
202294
- uniqueName,
202295
- remoteHome
202296
- );
202297
- if (latency) {
202298
- latency.setContext({ box: spriteAlias, session: sessionName });
202299
- }
202442
+ const finalized = await finalizeAutoNamedSession({
202443
+ client: client2,
202444
+ alias: spriteAlias,
202445
+ autoNamed,
202446
+ sessionName,
202447
+ sessionId: id,
202448
+ sessions,
202449
+ remoteHome,
202450
+ onWarn: warnSessionMap
202451
+ });
202452
+ sessions = finalized.sessions;
202453
+ sessionName = finalized.sessionName;
202454
+ if (finalized.renamed && latency && sessionName) {
202455
+ latency.setContext({ box: spriteAlias, session: sessionName });
202300
202456
  }
202301
- sessions[sessionName] = id;
202302
- await writeSpriteSessions(client2, spriteAlias, sessions);
202303
202457
  };
202304
202458
  const renameSessionMapping = async (fromName, toName, expectedId) => {
202305
- const latest = await readSessionsSafe(sessions);
202306
- const currentId = latest[fromName];
202307
- if (!currentId) {
202308
- throw new Error(`Session "${fromName}" not found.`);
202309
- }
202310
- if (currentId !== expectedId) {
202311
- throw new Error(
202312
- `Session "${fromName}" no longer matches the active session.`
202313
- );
202314
- }
202315
- if (latest[toName] && latest[toName] !== expectedId) {
202316
- throw new Error(`Session "${toName}" already exists.`);
202317
- }
202318
- delete latest[fromName];
202319
- latest[toName] = expectedId;
202320
- await writeSpriteSessions(client2, spriteAlias, latest);
202321
- await renameSessionLog(client2, spriteAlias, fromName, toName, remoteHome);
202459
+ const latest = await renameMappedSession({
202460
+ client: client2,
202461
+ alias: spriteAlias,
202462
+ fromName,
202463
+ toName,
202464
+ expectedId,
202465
+ remoteHome,
202466
+ sessions
202467
+ });
202322
202468
  sessions = latest;
202323
202469
  sessionName = toName;
202324
202470
  autoNamed = false;
@@ -202364,7 +202510,7 @@ var init_connect2 = __esm({
202364
202510
  return [connectShell, "-lc", `${envCommandPrefix}${parsed.command}`];
202365
202511
  }
202366
202512
  if (computeProvider === "modal") {
202367
- const interactiveCommand = buildModalInteractiveCommand({ tty: isTty });
202513
+ const interactiveCommand = buildModalInteractiveCommand();
202368
202514
  if (projectWorkdir) {
202369
202515
  return [
202370
202516
  "/bin/sh",
@@ -220047,4 +220193,4 @@ smol-toml/dist/index.js:
220047
220193
  */
220048
220194
  //# sourceMappingURL=dvb.cjs.map
220049
220195
 
220050
- //# debugId=c89c7337-d26d-5d0e-9378-e2535af1df44
220196
+ //# debugId=ff297307-c733-552d-a450-764919e5443b