@adhdev/session-host-core 1.0.82-rc.3 → 1.0.82-rc.31

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/index.js CHANGED
@@ -30,6 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ CLI_CHILD_NICE_ENV: () => CLI_CHILD_NICE_ENV,
34
+ CLI_CHILD_NICE_INCREMENT: () => CLI_CHILD_NICE_INCREMENT,
35
+ CLI_CHILD_SCHEDULING_ENV: () => CLI_CHILD_SCHEDULING_ENV,
33
36
  DEFAULT_CONFIG_DIR_NAME: () => DEFAULT_CONFIG_DIR_NAME,
34
37
  DEFAULT_SESSION_HOST_COLS: () => DEFAULT_SESSION_HOST_COLS,
35
38
  DEFAULT_SESSION_HOST_ROWS: () => DEFAULT_SESSION_HOST_ROWS,
@@ -43,21 +46,26 @@ __export(index_exports, {
43
46
  buildRuntimeKey: () => buildRuntimeKey,
44
47
  canonicalizeInstancePath: () => canonicalizeInstancePath,
45
48
  classifyTermination: () => classifyTermination,
49
+ createCliChildPriorityPolicy: () => createCliChildPriorityPolicy,
46
50
  createLineParser: () => createLineParser,
47
51
  createResponseEnvelope: () => createResponseEnvelope,
48
52
  createSessionHostControlPlane: () => createSessionHostControlPlane,
53
+ disconnectSessionHostClients: () => disconnectSessionHostClients,
49
54
  ensureNodePtySpawnHelperPermissions: () => ensureNodePtySpawnHelperPermissions,
55
+ findConnectedSessionHostClient: () => findConnectedSessionHostClient,
50
56
  formatRuntimeOwner: () => formatRuntimeOwner,
51
57
  getDefaultSessionHostEndpoint: () => getDefaultSessionHostEndpoint,
52
58
  getSessionHostRecoveryLabel: () => getSessionHostRecoveryLabel,
53
59
  getSessionHostSurfaceKind: () => getSessionHostSurfaceKind,
54
60
  getWorkspaceLabel: () => getWorkspaceLabel,
61
+ hiddenSpawnProcess: () => hiddenSpawn,
55
62
  isDefaultInstanceConfigDir: () => isDefaultInstanceConfigDir,
56
63
  isSessionHostLiveRuntime: () => isSessionHostLiveRuntime,
57
64
  isSessionHostRecoverySnapshot: () => isSessionHostRecoverySnapshot,
58
65
  isTerminalRecord: () => isTerminalRecord,
59
66
  partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
60
67
  partitionSessionHostRecords: () => partitionSessionHostRecords,
68
+ replayLaunchEnv: () => replayLaunchEnv,
61
69
  resolveAttachableRuntimeRecord: () => resolveAttachableRuntimeRecord,
62
70
  resolveInstanceConfigDir: () => resolveInstanceConfigDir,
63
71
  resolveRuntimeRecord: () => resolveRuntimeRecord,
@@ -65,18 +73,23 @@ __export(index_exports, {
65
73
  resolveSessionHostIpcKey: () => resolveSessionHostIpcKey,
66
74
  resolveSessionHostRows: () => resolveSessionHostRows,
67
75
  sanitizeSpawnEnv: () => sanitizeSpawnEnv,
76
+ spawnCliChild: () => spawnCliChild,
68
77
  writeEnvelope: () => writeEnvelope
69
78
  });
70
79
  module.exports = __toCommonJS(index_exports);
71
80
 
72
81
  // src/types.ts
73
82
  var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
83
+ "get_upgrade_lease",
84
+ "acquire_upgrade_lease",
85
+ "release_upgrade_lease",
74
86
  "create_session",
75
87
  "attach_session",
76
88
  "detach_session",
77
89
  "send_input",
78
90
  "resize_session",
79
91
  "stop_session",
92
+ "stop_mesh_writer",
80
93
  "delete_session",
81
94
  "resume_session",
82
95
  "acquire_write",
@@ -126,6 +139,62 @@ function classifyTermination(input) {
126
139
  return termination;
127
140
  }
128
141
 
142
+ // src/cli-child-priority.ts
143
+ var os = __toESM(require("os"));
144
+
145
+ // src/process/hidden-spawn.ts
146
+ var import_node_child_process = require("child_process");
147
+ function hiddenSpawn(command, args = [], options = {}) {
148
+ return (0, import_node_child_process.spawn)(command, args, { windowsHide: true, ...options });
149
+ }
150
+
151
+ // src/cli-child-priority.ts
152
+ var CLI_CHILD_NICE_INCREMENT = 10;
153
+ var CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
154
+ var CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
155
+ function setDarwinBackground(pid, onFailure) {
156
+ const task = hiddenSpawn("/usr/sbin/taskpolicy", ["-b", "-p", String(pid)], { stdio: "ignore" });
157
+ task.once("error", onFailure);
158
+ task.once("exit", (code, signal) => {
159
+ if (code !== 0) onFailure(new Error(`taskpolicy exited with ${signal ?? code}`));
160
+ });
161
+ }
162
+ function createCliChildPriorityPolicy(deps = {
163
+ platform: process.platform,
164
+ getPriority: os.getPriority,
165
+ setPriority: os.setPriority,
166
+ setDarwinBackground
167
+ }) {
168
+ let failureLogged = false;
169
+ return function spawnCliChild2(spawnChild, env = process.env, logInfo = console.info) {
170
+ const child = spawnChild();
171
+ const pid = child.pid;
172
+ if (env[CLI_CHILD_NICE_ENV] === "0" || typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return child;
173
+ const onFailure = (error) => {
174
+ if (!failureLogged) {
175
+ failureLogged = true;
176
+ const detail = error instanceof Error ? error.message : String(error);
177
+ logInfo(`[cli-child-priority] Could not apply CLI child scheduling (pid ${pid}); continuing: ${detail}`);
178
+ }
179
+ };
180
+ try {
181
+ const priority = deps.platform === "win32" ? os.constants.priority.PRIORITY_BELOW_NORMAL : Math.min(19, deps.getPriority(pid) + CLI_CHILD_NICE_INCREMENT);
182
+ deps.setPriority(pid, priority);
183
+ } catch (error) {
184
+ onFailure(error);
185
+ }
186
+ if (deps.platform === "darwin" && env[CLI_CHILD_SCHEDULING_ENV] === "darwin-bg") {
187
+ try {
188
+ deps.setDarwinBackground?.(pid, onFailure);
189
+ } catch (error) {
190
+ onFailure(error);
191
+ }
192
+ }
193
+ return child;
194
+ };
195
+ }
196
+ var spawnCliChild = createCliChildPriorityPolicy();
197
+
129
198
  // src/buffer.ts
130
199
  var DEFAULT_SESSION_RING_BUFFER_MAX_BYTES = 4 * 1024 * 1024;
131
200
  var SessionRingBuffer = class {
@@ -689,7 +758,7 @@ function cloneMeta(meta) {
689
758
  }
690
759
 
691
760
  // src/ipc.ts
692
- var os = __toESM(require("os"));
761
+ var os2 = __toESM(require("os"));
693
762
  var path2 = __toESM(require("path"));
694
763
  var net = __toESM(require("net"));
695
764
  var import_string_decoder = require("string_decoder");
@@ -708,7 +777,7 @@ function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
708
777
  }
709
778
  return {
710
779
  kind: "unix",
711
- path: path2.join(os.tmpdir(), `${appName}-session-host${suffix}.sock`)
780
+ path: path2.join(os2.tmpdir(), `${appName}-session-host${suffix}.sock`)
712
781
  };
713
782
  }
714
783
  function serializeEnvelope(envelope) {
@@ -738,16 +807,59 @@ function createLineParser(onEnvelope) {
738
807
  return parser;
739
808
  }
740
809
  var establishedSockets = /* @__PURE__ */ new WeakSet();
810
+ var activeClientRefs = /* @__PURE__ */ new Set();
811
+ function disconnectSessionHostClients(endpoint, error) {
812
+ for (const ref of activeClientRefs) {
813
+ const client = ref.deref();
814
+ if (!client) {
815
+ activeClientRefs.delete(ref);
816
+ continue;
817
+ }
818
+ if (!endpoint || client.endpoint.path === endpoint.path) {
819
+ client.disconnect(error);
820
+ }
821
+ }
822
+ }
823
+ function findConnectedSessionHostClient(endpoint) {
824
+ for (const ref of activeClientRefs) {
825
+ const client = ref.deref();
826
+ if (!client) {
827
+ activeClientRefs.delete(ref);
828
+ continue;
829
+ }
830
+ if ((!endpoint || client.endpoint.path === endpoint.path) && client.isConnected()) {
831
+ return client;
832
+ }
833
+ }
834
+ return null;
835
+ }
741
836
  var SessionHostClient = class {
742
837
  endpoint;
743
838
  socket = null;
839
+ connectPromise = null;
840
+ requestTimeoutMs = 3e4;
744
841
  requestWaiters = /* @__PURE__ */ new Map();
745
842
  eventListeners = /* @__PURE__ */ new Set();
746
843
  disconnectListeners = /* @__PURE__ */ new Set();
747
844
  /** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
748
845
  disconnectedSockets = /* @__PURE__ */ new WeakSet();
846
+ /** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
847
+ attachedSessions = /* @__PURE__ */ new Map();
749
848
  constructor(options = {}) {
750
849
  this.endpoint = options.endpoint || getDefaultSessionHostEndpoint(options.appName || "adhdev");
850
+ if (typeof options.requestTimeoutMs === "number" && options.requestTimeoutMs > 0) {
851
+ this.requestTimeoutMs = options.requestTimeoutMs;
852
+ }
853
+ if (options.registerAsShared !== false) activeClientRefs.add(new WeakRef(this));
854
+ }
855
+ static disconnectClients(endpoint, error) {
856
+ disconnectSessionHostClients(endpoint, error);
857
+ }
858
+ static findConnectedClient(endpoint) {
859
+ return findConnectedSessionHostClient(endpoint);
860
+ }
861
+ isConnected() {
862
+ return Boolean(this.socket && !this.socket.destroyed && establishedSockets.has(this.socket));
751
863
  }
752
864
  /**
753
865
  * Fires when an established connection to the session host goes away.
@@ -790,6 +902,7 @@ var SessionHostClient = class {
790
902
  this.requestWaiters.clear();
791
903
  if (this.socket === socket) {
792
904
  this.socket = null;
905
+ this.connectPromise = null;
793
906
  }
794
907
  try {
795
908
  socket.destroy();
@@ -809,8 +922,62 @@ var SessionHostClient = class {
809
922
  }
810
923
  }
811
924
  }
812
- async connect() {
813
- if (this.socket && !this.socket.destroyed) return;
925
+ sendRawRequestOnSocket(socket, request, timeoutMs = this.requestTimeoutMs) {
926
+ const requestId = generateUUID();
927
+ const envelope = {
928
+ kind: "request",
929
+ requestId,
930
+ request
931
+ };
932
+ const timeoutLabel = timeoutMs % 1e3 === 0 ? `${timeoutMs / 1e3}s` : `${timeoutMs}ms`;
933
+ const startedAt = Date.now();
934
+ const startedMonotonicAt = performance.now();
935
+ return new Promise((resolve3, reject) => {
936
+ const timeout = setTimeout(() => {
937
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - startedMonotonicAt));
938
+ const wallElapsedMs = Math.max(0, Date.now() - startedAt);
939
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
940
+ const timeoutError = Object.assign(
941
+ new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`),
942
+ {
943
+ code: "SESSION_HOST_REQUEST_TIMEOUT",
944
+ requestType: request.type,
945
+ scheduledTimeoutMs: timeoutMs,
946
+ actualElapsedMs,
947
+ wallElapsedMs,
948
+ observerLagMs
949
+ }
950
+ );
951
+ if (this.socket === socket) {
952
+ this.disconnect(timeoutError);
953
+ } else {
954
+ this.requestWaiters.delete(requestId);
955
+ this.disconnectedSockets.add(socket);
956
+ try {
957
+ socket.destroy();
958
+ } catch {
959
+ }
960
+ reject(timeoutError);
961
+ }
962
+ }, timeoutMs);
963
+ this.requestWaiters.set(requestId, {
964
+ resolve: (value) => {
965
+ clearTimeout(timeout);
966
+ resolve3(value);
967
+ },
968
+ reject: (error) => {
969
+ clearTimeout(timeout);
970
+ reject(error);
971
+ }
972
+ });
973
+ socket.write(serializeEnvelope(envelope));
974
+ });
975
+ }
976
+ async connect(timeoutMs = this.requestTimeoutMs) {
977
+ if (this.socket && !this.socket.destroyed) {
978
+ if (this.connectPromise) await this.connectPromise;
979
+ return;
980
+ }
814
981
  if (this.socket) {
815
982
  try {
816
983
  this.socket.destroy();
@@ -818,6 +985,7 @@ var SessionHostClient = class {
818
985
  }
819
986
  this.socket = null;
820
987
  }
988
+ this.connectPromise = null;
821
989
  const socket = net.createConnection(this.endpoint.path);
822
990
  this.socket = socket;
823
991
  const parser = createLineParser((envelope) => {
@@ -851,13 +1019,68 @@ var SessionHostClient = class {
851
1019
  socket.on("end", () => {
852
1020
  this.handleDisconnect(socket, "ended", void 0, flushParser().length);
853
1021
  });
854
- await new Promise((resolve3, reject) => {
855
- socket.once("connect", () => {
856
- establishedSockets.add(socket);
857
- resolve3();
1022
+ const connectTask = (async () => {
1023
+ await new Promise((resolve3, reject) => {
1024
+ const cleanup = () => {
1025
+ clearTimeout(timer);
1026
+ socket.off("connect", connected);
1027
+ socket.off("error", failed);
1028
+ socket.off("close", closed);
1029
+ };
1030
+ const connected = () => {
1031
+ cleanup();
1032
+ establishedSockets.add(socket);
1033
+ resolve3();
1034
+ };
1035
+ const failed = (error) => {
1036
+ cleanup();
1037
+ reject(error);
1038
+ };
1039
+ const closed = () => failed(new Error("Session host connection closed before connect"));
1040
+ const connectStartedAt = Date.now();
1041
+ const connectStartedMonotonicAt = performance.now();
1042
+ const timer = setTimeout(() => {
1043
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - connectStartedMonotonicAt));
1044
+ const wallElapsedMs = Math.max(0, Date.now() - connectStartedAt);
1045
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
1046
+ const error = Object.assign(
1047
+ new Error(`Session host connect timed out after ${timeoutMs}ms`),
1048
+ {
1049
+ code: "SESSION_HOST_CONNECT_TIMEOUT",
1050
+ scheduledTimeoutMs: timeoutMs,
1051
+ actualElapsedMs,
1052
+ wallElapsedMs,
1053
+ observerLagMs
1054
+ }
1055
+ );
1056
+ failed(error);
1057
+ if (this.socket === socket) this.disconnect(error);
1058
+ }, timeoutMs);
1059
+ socket.once("connect", connected);
1060
+ socket.once("error", failed);
1061
+ socket.once("close", closed);
858
1062
  });
859
- socket.once("error", reject);
860
- });
1063
+ if (this.attachedSessions.size > 0 && this.socket === socket && !socket.destroyed) {
1064
+ for (const [sessionId, sub] of [...this.attachedSessions.entries()]) {
1065
+ if (this.socket !== socket || socket.destroyed) break;
1066
+ const replayResponse = await this.sendRawRequestOnSocket(socket, {
1067
+ type: "attach_session",
1068
+ payload: sub
1069
+ }).catch(() => null);
1070
+ if (replayResponse && !replayResponse.success) {
1071
+ this.attachedSessions.delete(sessionId);
1072
+ }
1073
+ }
1074
+ }
1075
+ })();
1076
+ this.connectPromise = connectTask;
1077
+ try {
1078
+ await connectTask;
1079
+ } finally {
1080
+ if (this.connectPromise === connectTask) {
1081
+ this.connectPromise = null;
1082
+ }
1083
+ }
861
1084
  }
862
1085
  onEvent(listener) {
863
1086
  this.eventListeners.add(listener);
@@ -865,35 +1088,87 @@ var SessionHostClient = class {
865
1088
  this.eventListeners.delete(listener);
866
1089
  };
867
1090
  }
868
- async request(request) {
869
- await this.connect();
870
- if (!this.socket) throw new Error("Session host socket unavailable");
871
- const requestId = generateUUID();
872
- const envelope = {
873
- kind: "request",
874
- requestId,
875
- request
876
- };
877
- const response = await new Promise((resolve3, reject) => {
878
- const timeout = setTimeout(() => {
879
- this.requestWaiters.delete(requestId);
880
- reject(new Error(`Session host request timed out after 30s (${request.type})`));
881
- }, 3e4);
882
- this.requestWaiters.set(requestId, {
883
- resolve: (value) => {
884
- clearTimeout(timeout);
885
- resolve3(value);
886
- },
887
- reject: (error) => {
888
- clearTimeout(timeout);
889
- reject(error);
1091
+ async request(request, options = {}) {
1092
+ const timeoutMs = Math.max(1, options.timeoutMs ?? this.requestTimeoutMs);
1093
+ const deadline = Date.now() + timeoutMs;
1094
+ const alreadyConnected = this.isConnected() && !this.connectPromise;
1095
+ if (options.timeoutMs !== void 0) {
1096
+ let timer;
1097
+ const raceStartedAt = Date.now();
1098
+ const raceStartedMonotonicAt = performance.now();
1099
+ try {
1100
+ await Promise.race([
1101
+ this.connect(timeoutMs),
1102
+ new Promise((_resolve, reject) => {
1103
+ timer = setTimeout(() => {
1104
+ const actualElapsedMs = Math.max(0, Math.round(performance.now() - raceStartedMonotonicAt));
1105
+ const wallElapsedMs = Math.max(0, Date.now() - raceStartedAt);
1106
+ const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
1107
+ const error = Object.assign(
1108
+ new Error(`Session host connect timed out after ${timeoutMs}ms`),
1109
+ {
1110
+ code: "SESSION_HOST_CONNECT_TIMEOUT",
1111
+ scheduledTimeoutMs: timeoutMs,
1112
+ actualElapsedMs,
1113
+ wallElapsedMs,
1114
+ observerLagMs
1115
+ }
1116
+ );
1117
+ reject(error);
1118
+ this.disconnect(error);
1119
+ }, timeoutMs);
1120
+ })
1121
+ ]);
1122
+ } finally {
1123
+ if (timer) clearTimeout(timer);
1124
+ }
1125
+ } else {
1126
+ await this.connect(timeoutMs);
1127
+ }
1128
+ const requestSocket = this.socket;
1129
+ if (!requestSocket) throw new Error("Session host socket unavailable");
1130
+ const response = await this.sendRawRequestOnSocket(requestSocket, request, options.timeoutMs === void 0 || alreadyConnected ? timeoutMs : Math.max(1, deadline - Date.now()));
1131
+ if (response.success) {
1132
+ if (request.type === "attach_session") {
1133
+ this.attachedSessions.set(request.payload.sessionId, {
1134
+ sessionId: request.payload.sessionId,
1135
+ clientId: request.payload.clientId,
1136
+ clientType: request.payload.clientType,
1137
+ readOnly: request.payload.readOnly === true
1138
+ });
1139
+ } else if (request.type === "create_session") {
1140
+ const createdId = response.result?.sessionId || request.payload.sessionId;
1141
+ const clientId = typeof request.payload.clientId === "string" ? request.payload.clientId.trim() : "";
1142
+ if (createdId && clientId) {
1143
+ this.attachedSessions.set(createdId, {
1144
+ sessionId: createdId,
1145
+ clientId,
1146
+ clientType: request.payload.clientType || "daemon",
1147
+ readOnly: false
1148
+ });
890
1149
  }
891
- });
892
- this.socket?.write(serializeEnvelope(envelope));
893
- });
1150
+ } else if (request.type === "detach_session" || request.type === "delete_session") {
1151
+ this.attachedSessions.delete(request.payload.sessionId);
1152
+ }
1153
+ }
894
1154
  return response;
895
1155
  }
1156
+ disconnect(error) {
1157
+ const socket = this.socket;
1158
+ if (socket) {
1159
+ this.handleDisconnect(socket, error ? "error" : "closed", error, 0);
1160
+ return;
1161
+ }
1162
+ this.connectPromise = null;
1163
+ const failure = error || new Error(`Session host client disconnected (${this.endpoint.path})`);
1164
+ for (const waiter of this.requestWaiters.values()) {
1165
+ waiter.reject(failure);
1166
+ }
1167
+ this.requestWaiters.clear();
1168
+ }
896
1169
  async close() {
1170
+ this.attachedSessions.clear();
1171
+ this.connectPromise = null;
897
1172
  if (!this.socket) return;
898
1173
  const socket = this.socket;
899
1174
  this.socket = null;
@@ -930,10 +1205,10 @@ function writeEnvelope(socket, envelope) {
930
1205
  // src/instance-key.ts
931
1206
  var crypto2 = __toESM(require("crypto"));
932
1207
  var fs = __toESM(require("fs"));
933
- var os2 = __toESM(require("os"));
1208
+ var os3 = __toESM(require("os"));
934
1209
  var path3 = __toESM(require("path"));
935
1210
  var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
936
- function resolveInstanceConfigDir(env = process.env, homeDir = os2.homedir()) {
1211
+ function resolveInstanceConfigDir(env = process.env, homeDir = os3.homedir()) {
937
1212
  const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
938
1213
  return override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
939
1214
  }
@@ -958,17 +1233,17 @@ function canonicalizeInstancePath(dir, platform2 = process.platform) {
958
1233
  const real = realpathLongestExistingPrefix(resolved).replace(/[\\/]+$/, "");
959
1234
  return platform2 === "win32" ? real.toLowerCase() : real;
960
1235
  }
961
- function isDefaultInstanceConfigDir(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
1236
+ function isDefaultInstanceConfigDir(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
962
1237
  return canonicalizeInstancePath(configDir, platform2) === canonicalizeInstancePath(path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME), platform2);
963
1238
  }
964
- function resolveSessionHostIpcKey(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
1239
+ function resolveSessionHostIpcKey(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
965
1240
  if (isDefaultInstanceConfigDir(configDir, homeDir, platform2)) return "";
966
1241
  const canonical = canonicalizeInstancePath(configDir, platform2);
967
1242
  return crypto2.createHash("sha256").update(canonical, "utf8").digest("hex").slice(0, 12);
968
1243
  }
969
1244
 
970
1245
  // src/spawn-env.ts
971
- var os3 = __toESM(require("os"));
1246
+ var os4 = __toESM(require("os"));
972
1247
  var path4 = __toESM(require("path"));
973
1248
  function sanitizeSpawnEnv(baseEnv, overrides) {
974
1249
  const env = {};
@@ -998,6 +1273,27 @@ function sanitizeSpawnEnv(baseEnv, overrides) {
998
1273
  applyTerminalColorEnv(env);
999
1274
  return env;
1000
1275
  }
1276
+ function replayLaunchEnv(command) {
1277
+ if (command.envMode === "launch_overrides") return { ...command.env };
1278
+ const roleKeys = /* @__PURE__ */ new Set([
1279
+ "HOME",
1280
+ "USERPROFILE",
1281
+ "XDG_CONFIG_HOME",
1282
+ "CLAUDE_CONFIG_DIR",
1283
+ "CODEX_HOME",
1284
+ "KIMI_CODE_HOME",
1285
+ "GEMINI_CLI_HOME",
1286
+ "OPENCODE_CONFIG",
1287
+ "OPENCODE_CONFIG_CONTENT",
1288
+ "CLAUDE_CODE_DISABLE_AUTO_MEMORY",
1289
+ "TERMINAL_CWD",
1290
+ "ADHDEV_INLINE_MESH",
1291
+ "ADHDEV_ASSISTANT_SESSION_ID",
1292
+ "ADHDEV_COORDINATOR_SESSION_ID",
1293
+ "ADHDEV_CONFIG_DIR"
1294
+ ]);
1295
+ return Object.fromEntries(Object.entries(command.env ?? {}).filter(([key]) => roleKeys.has(key)));
1296
+ }
1001
1297
  function applyTerminalColorEnv(env) {
1002
1298
  if (env.NO_COLOR) return;
1003
1299
  if (!env.TERM || env.TERM === "xterm-color") {
@@ -1010,11 +1306,11 @@ function applyTerminalColorEnv(env) {
1010
1306
  }
1011
1307
  }
1012
1308
  function ensureNodePtySpawnHelperPermissions(logFn) {
1013
- if (os3.platform() === "win32") return;
1309
+ if (os4.platform() === "win32") return;
1014
1310
  try {
1015
1311
  const fs2 = require("fs");
1016
1312
  const ptyDir = path4.resolve(path4.dirname(require.resolve("node-pty")), "..");
1017
- const platformArch = `${os3.platform()}-${os3.arch()}`;
1313
+ const platformArch = `${os4.platform()}-${os4.arch()}`;
1018
1314
  const helper = path4.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
1019
1315
  if (fs2.existsSync(helper)) {
1020
1316
  const stat = fs2.statSync(helper);
@@ -1070,6 +1366,9 @@ function createSessionHostControlPlane(transport) {
1070
1366
  }
1071
1367
  // Annotate the CommonJS export names for ESM import in node:
1072
1368
  0 && (module.exports = {
1369
+ CLI_CHILD_NICE_ENV,
1370
+ CLI_CHILD_NICE_INCREMENT,
1371
+ CLI_CHILD_SCHEDULING_ENV,
1073
1372
  DEFAULT_CONFIG_DIR_NAME,
1074
1373
  DEFAULT_SESSION_HOST_COLS,
1075
1374
  DEFAULT_SESSION_HOST_ROWS,
@@ -1083,21 +1382,26 @@ function createSessionHostControlPlane(transport) {
1083
1382
  buildRuntimeKey,
1084
1383
  canonicalizeInstancePath,
1085
1384
  classifyTermination,
1385
+ createCliChildPriorityPolicy,
1086
1386
  createLineParser,
1087
1387
  createResponseEnvelope,
1088
1388
  createSessionHostControlPlane,
1389
+ disconnectSessionHostClients,
1089
1390
  ensureNodePtySpawnHelperPermissions,
1391
+ findConnectedSessionHostClient,
1090
1392
  formatRuntimeOwner,
1091
1393
  getDefaultSessionHostEndpoint,
1092
1394
  getSessionHostRecoveryLabel,
1093
1395
  getSessionHostSurfaceKind,
1094
1396
  getWorkspaceLabel,
1397
+ hiddenSpawnProcess,
1095
1398
  isDefaultInstanceConfigDir,
1096
1399
  isSessionHostLiveRuntime,
1097
1400
  isSessionHostRecoverySnapshot,
1098
1401
  isTerminalRecord,
1099
1402
  partitionSessionHostDiagnosticsSessions,
1100
1403
  partitionSessionHostRecords,
1404
+ replayLaunchEnv,
1101
1405
  resolveAttachableRuntimeRecord,
1102
1406
  resolveInstanceConfigDir,
1103
1407
  resolveRuntimeRecord,
@@ -1105,6 +1409,7 @@ function createSessionHostControlPlane(transport) {
1105
1409
  resolveSessionHostIpcKey,
1106
1410
  resolveSessionHostRows,
1107
1411
  sanitizeSpawnEnv,
1412
+ spawnCliChild,
1108
1413
  writeEnvelope
1109
1414
  });
1110
1415
  //# sourceMappingURL=index.js.map