@boxes-dev/dvb 1.0.100 → 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]="3032ad99-df35-5df0-aa43-020b2e186764")}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.100";
88692
- const rawGitSha = "2ea78dd0419073d76378dc3e8303b62d25cb54c8";
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.100";
120683
- const rawGitSha = "2ea78dd0419073d76378dc3e8303b62d25cb54c8";
120684
- const rawSentryRelease = "boxes-dev-dvb@1.0.100+2ea78dd0419073d76378dc3e8303b62d25cb54c8";
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) {
@@ -201296,59 +201542,8 @@ var init_modalCommandContext = __esm({
201296
201542
  }
201297
201543
  });
201298
201544
 
201299
- // src/devbox/commands/sessionUtils.ts
201300
- var AUTO_SESSION_PREFIX, parseAutoSessionSuffix, getNextAutoSessionName, ensureUniqueAutoSessionName, shellQuote2, sanitizeSessionName, buildSessionLogPath, renameSessionLog;
201301
- var init_sessionUtils = __esm({
201302
- "src/devbox/commands/sessionUtils.ts"() {
201303
- "use strict";
201304
- AUTO_SESSION_PREFIX = "new-session-";
201305
- parseAutoSessionSuffix = (name) => {
201306
- if (!name.startsWith(AUTO_SESSION_PREFIX)) return null;
201307
- const raw = name.slice(AUTO_SESSION_PREFIX.length);
201308
- const parsed = Number(raw);
201309
- if (!Number.isFinite(parsed) || parsed < 1) return null;
201310
- return Math.floor(parsed);
201311
- };
201312
- getNextAutoSessionName = (sessions) => {
201313
- let max = 0;
201314
- for (const name of Object.keys(sessions)) {
201315
- const suffix = parseAutoSessionSuffix(name);
201316
- if (suffix && suffix > max) max = suffix;
201317
- }
201318
- return `${AUTO_SESSION_PREFIX}${max + 1}`;
201319
- };
201320
- ensureUniqueAutoSessionName = (sessions, preferred, sessionId) => {
201321
- const start = parseAutoSessionSuffix(preferred) ?? 1;
201322
- let current = preferred;
201323
- let counter = start;
201324
- while (sessions[current] && sessions[current] !== sessionId) {
201325
- counter += 1;
201326
- current = `${AUTO_SESSION_PREFIX}${counter}`;
201327
- }
201328
- return current;
201329
- };
201330
- shellQuote2 = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
201331
- sanitizeSessionName = (value) => {
201332
- const trimmed = value.trim();
201333
- const sanitized = trimmed.replace(/[^a-zA-Z0-9._-]/g, "_");
201334
- return sanitized || "session";
201335
- };
201336
- buildSessionLogPath = (name, remoteHome = "/home/sprite") => `${remoteHome}/.devbox/logs/${sanitizeSessionName(name)}.log`;
201337
- renameSessionLog = async (client2, box, fromName, toName, remoteHome = "/home/sprite") => {
201338
- const fromPath = buildSessionLogPath(fromName, remoteHome);
201339
- const toPath = buildSessionLogPath(toName, remoteHome);
201340
- if (fromPath === toPath) return;
201341
- await client2.exec(box, [
201342
- "/bin/bash",
201343
- "-lc",
201344
- `if [ -f ${shellQuote2(fromPath)} ]; then mv ${shellQuote2(fromPath)} ${shellQuote2(toPath)}; fi`
201345
- ]);
201346
- };
201347
- }
201348
- });
201349
-
201350
201545
  // src/devbox/commands/connect.ts
201351
- 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;
201352
201547
  var init_connect2 = __esm({
201353
201548
  "src/devbox/commands/connect.ts"() {
201354
201549
  "use strict";
@@ -201369,6 +201564,7 @@ var init_connect2 = __esm({
201369
201564
  init_completions();
201370
201565
  init_boxSelect();
201371
201566
  init_commandProvider();
201567
+ init_connectSessionMapping();
201372
201568
  init_providerClient();
201373
201569
  init_modalCommandContext();
201374
201570
  init_sessionUtils();
@@ -201477,10 +201673,7 @@ var init_connect2 = __esm({
201477
201673
  return env2;
201478
201674
  };
201479
201675
  formatEnvExports = (env2) => Object.entries(env2).map(([key, value]) => `export ${key}=${shellQuote2(value)}`).join("; ");
201480
- buildModalInteractiveCommand = ({ tty: tty2 }) => {
201481
- const nonCanonicalPrelude = tty2 ? "stty -icanon min 1 time 0 -echoctl; " : "";
201482
- return `${nonCanonicalPrelude}exec bash -il || exec sh -i`;
201483
- };
201676
+ buildModalInteractiveCommand = () => "exec bash -il || exec sh -i";
201484
201677
  parseEnvSize = (value) => {
201485
201678
  if (!value) return void 0;
201486
201679
  const parsed = Number(value);
@@ -201510,7 +201703,7 @@ var init_connect2 = __esm({
201510
201703
  const env2 = {};
201511
201704
  if (terminalSessionId) env2.DEVBOX_TERM_SESSION_ID = terminalSessionId;
201512
201705
  if (sessionName) {
201513
- env2[SESSION_NAME_TOKEN_KEY] = encodeSessionNameToken(sessionName);
201706
+ env2[SESSION_NAME_TOKEN_KEY2] = encodeSessionNameToken(sessionName);
201514
201707
  }
201515
201708
  return env2;
201516
201709
  };
@@ -201758,31 +201951,8 @@ var init_connect2 = __esm({
201758
201951
  const normalized = message.trim().toLowerCase();
201759
201952
  return normalized.includes("session") && normalized.includes("not found");
201760
201953
  };
201761
- SESSION_NAME_TOKEN_KEY = "DEVBOX_SESSION_NAME_B64";
201954
+ SESSION_NAME_TOKEN_KEY2 = "DEVBOX_SESSION_NAME_B64";
201762
201955
  encodeSessionNameToken = (sessionName) => Buffer.from(sessionName, "utf8").toString("base64url");
201763
- decodeSessionNameToken = (value) => {
201764
- try {
201765
- const decoded = Buffer.from(value, "base64url").toString("utf8").trim();
201766
- return decoded.length > 0 ? decoded : null;
201767
- } catch {
201768
- return null;
201769
- }
201770
- };
201771
- extractSessionNameFromCommand = (command) => {
201772
- if (!command || command.length < 3) return null;
201773
- const script = command.slice(2).join(" ");
201774
- const patterns = [
201775
- new RegExp(`${SESSION_NAME_TOKEN_KEY}='([^']+)'`),
201776
- new RegExp(`${SESSION_NAME_TOKEN_KEY}="([^"]+)"`)
201777
- ];
201778
- for (const pattern of patterns) {
201779
- const match2 = script.match(pattern);
201780
- if (!match2?.[1]) continue;
201781
- const decoded = decodeSessionNameToken(match2[1]);
201782
- if (decoded) return decoded;
201783
- }
201784
- return null;
201785
- };
201786
201956
  SESSION_LOG_FLUSH_BYTES = 24 * 1024;
201787
201957
  SESSION_LOG_EOF_MARKER = "__DVB_LOG_EOF__";
201788
201958
  createRemoteSessionLogSink = (client2, spriteAlias, logPath) => {
@@ -202220,20 +202390,18 @@ var init_connect2 = __esm({
202220
202390
  });
202221
202391
  }
202222
202392
  const connectShell = computeProvider === "modal" ? "/bin/bash" : await resolveConnectShell(client2, spriteAlias);
202223
- const readSessionsSafe = async (fallback2) => {
202224
- try {
202225
- return await readSpriteSessions(client2, spriteAlias);
202226
- } catch (error2) {
202227
- logger8.warn("sessions_read_failed", { error: String(error2) });
202228
- return fallback2;
202229
- }
202230
- };
202231
- let sessions = sessionName || autoNameRequested ? await readSessionsSafe({}) : {};
202232
- if (!sessionName && autoNameRequested) {
202233
- sessionName = getNextAutoSessionName(sessions);
202234
- autoNamed = true;
202235
- }
202236
- 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;
202237
202405
  let sessionId = resolveInitialSessionId({
202238
202406
  supportsAttachExecSession,
202239
202407
  sessionIdOverride,
@@ -202250,78 +202418,53 @@ var init_connect2 = __esm({
202250
202418
  }
202251
202419
  }
202252
202420
  const refreshSessionMapping = async () => {
202253
- if (!supportsAttachExecSession) return;
202254
- if (!sessionName) return;
202255
- sessions = await readSessionsSafe(sessions);
202256
- if (requireFreshSessionOpen) {
202257
- return;
202258
- }
202259
- sessionId = sessions[sessionName];
202260
- if (!sessionId && computeProvider === "modal" && supportsListExecSessions) {
202261
- const available = await client2.listExecSessions(spriteAlias);
202262
- const matched = available.find(
202263
- (session) => session.tty !== false && extractSessionNameFromCommand(session.command) === sessionName
202264
- );
202265
- if (matched) {
202266
- sessionId = matched.id;
202267
- sessions[sessionName] = matched.id;
202268
- await writeSpriteSessions(client2, spriteAlias, sessions);
202269
- }
202270
- }
202271
- if (sessionId && supportsListExecSessions && computeProvider !== "modal") {
202272
- const available = await client2.listExecSessions(spriteAlias);
202273
- const match2 = available.find((session) => session.id === sessionId);
202274
- if (!match2 || match2.tty === false) {
202275
- delete sessions[sessionName];
202276
- sessionId = void 0;
202277
- await writeSpriteSessions(client2, spriteAlias, sessions);
202278
- }
202279
- }
202280
- 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) {
202281
202437
  confirmedCreateExplicit = true;
202282
202438
  }
202283
202439
  };
202284
202440
  const remoteHome = computeProvider === "modal" ? "/root" : "/home/sprite";
202285
202441
  const finalizeAutoSession = async (id) => {
202286
- if (!autoNamed || !sessionName) return;
202287
- const latest = await readSessionsSafe(sessions);
202288
- sessions = latest;
202289
- const uniqueName = ensureUniqueAutoSessionName(latest, sessionName, id);
202290
- const previousName = sessionName;
202291
- if (uniqueName !== sessionName) {
202292
- sessionName = uniqueName;
202293
- await renameSessionLog(
202294
- client2,
202295
- spriteAlias,
202296
- previousName,
202297
- uniqueName,
202298
- remoteHome
202299
- );
202300
- if (latency) {
202301
- latency.setContext({ box: spriteAlias, session: sessionName });
202302
- }
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 });
202303
202456
  }
202304
- sessions[sessionName] = id;
202305
- await writeSpriteSessions(client2, spriteAlias, sessions);
202306
202457
  };
202307
202458
  const renameSessionMapping = async (fromName, toName, expectedId) => {
202308
- const latest = await readSessionsSafe(sessions);
202309
- const currentId = latest[fromName];
202310
- if (!currentId) {
202311
- throw new Error(`Session "${fromName}" not found.`);
202312
- }
202313
- if (currentId !== expectedId) {
202314
- throw new Error(
202315
- `Session "${fromName}" no longer matches the active session.`
202316
- );
202317
- }
202318
- if (latest[toName] && latest[toName] !== expectedId) {
202319
- throw new Error(`Session "${toName}" already exists.`);
202320
- }
202321
- delete latest[fromName];
202322
- latest[toName] = expectedId;
202323
- await writeSpriteSessions(client2, spriteAlias, latest);
202324
- 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
+ });
202325
202468
  sessions = latest;
202326
202469
  sessionName = toName;
202327
202470
  autoNamed = false;
@@ -202367,7 +202510,7 @@ var init_connect2 = __esm({
202367
202510
  return [connectShell, "-lc", `${envCommandPrefix}${parsed.command}`];
202368
202511
  }
202369
202512
  if (computeProvider === "modal") {
202370
- const interactiveCommand = buildModalInteractiveCommand({ tty: isTty });
202513
+ const interactiveCommand = buildModalInteractiveCommand();
202371
202514
  if (projectWorkdir) {
202372
202515
  return [
202373
202516
  "/bin/sh",
@@ -220050,4 +220193,4 @@ smol-toml/dist/index.js:
220050
220193
  */
220051
220194
  //# sourceMappingURL=dvb.cjs.map
220052
220195
 
220053
- //# debugId=3032ad99-df35-5df0-aa43-020b2e186764
220196
+ //# debugId=ff297307-c733-552d-a450-764919e5443b