@adhdev/session-host-core 1.0.82-rc.21 → 1.0.82-rc.23

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.mjs CHANGED
@@ -65,6 +65,62 @@ function classifyTermination(input) {
65
65
  return termination;
66
66
  }
67
67
 
68
+ // src/cli-child-priority.ts
69
+ import * as os from "os";
70
+
71
+ // src/process/hidden-spawn.ts
72
+ import { spawn } from "child_process";
73
+ function hiddenSpawn(command, args = [], options = {}) {
74
+ return spawn(command, args, { windowsHide: true, ...options });
75
+ }
76
+
77
+ // src/cli-child-priority.ts
78
+ var CLI_CHILD_NICE_INCREMENT = 10;
79
+ var CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
80
+ var CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
81
+ function setDarwinBackground(pid, onFailure) {
82
+ const task = hiddenSpawn("/usr/sbin/taskpolicy", ["-b", "-p", String(pid)], { stdio: "ignore" });
83
+ task.once("error", onFailure);
84
+ task.once("exit", (code, signal) => {
85
+ if (code !== 0) onFailure(new Error(`taskpolicy exited with ${signal ?? code}`));
86
+ });
87
+ }
88
+ function createCliChildPriorityPolicy(deps = {
89
+ platform: process.platform,
90
+ getPriority: os.getPriority,
91
+ setPriority: os.setPriority,
92
+ setDarwinBackground
93
+ }) {
94
+ let failureLogged = false;
95
+ return function spawnCliChild2(spawnChild, env = process.env, logInfo = console.info) {
96
+ const child = spawnChild();
97
+ const pid = child.pid;
98
+ if (env[CLI_CHILD_NICE_ENV] === "0" || typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return child;
99
+ const onFailure = (error) => {
100
+ if (!failureLogged) {
101
+ failureLogged = true;
102
+ const detail = error instanceof Error ? error.message : String(error);
103
+ logInfo(`[cli-child-priority] Could not apply CLI child scheduling (pid ${pid}); continuing: ${detail}`);
104
+ }
105
+ };
106
+ try {
107
+ const priority = deps.platform === "win32" ? os.constants.priority.PRIORITY_BELOW_NORMAL : Math.min(19, deps.getPriority(pid) + CLI_CHILD_NICE_INCREMENT);
108
+ deps.setPriority(pid, priority);
109
+ } catch (error) {
110
+ onFailure(error);
111
+ }
112
+ if (deps.platform === "darwin" && env[CLI_CHILD_SCHEDULING_ENV] === "darwin-bg") {
113
+ try {
114
+ deps.setDarwinBackground?.(pid, onFailure);
115
+ } catch (error) {
116
+ onFailure(error);
117
+ }
118
+ }
119
+ return child;
120
+ };
121
+ }
122
+ var spawnCliChild = createCliChildPriorityPolicy();
123
+
68
124
  // src/buffer.ts
69
125
  var DEFAULT_SESSION_RING_BUFFER_MAX_BYTES = 4 * 1024 * 1024;
70
126
  var SessionRingBuffer = class {
@@ -628,7 +684,7 @@ function cloneMeta(meta) {
628
684
  }
629
685
 
630
686
  // src/ipc.ts
631
- import * as os from "os";
687
+ import * as os2 from "os";
632
688
  import * as path2 from "path";
633
689
  import * as net from "net";
634
690
  import { StringDecoder } from "string_decoder";
@@ -647,7 +703,7 @@ function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
647
703
  }
648
704
  return {
649
705
  kind: "unix",
650
- path: path2.join(os.tmpdir(), `${appName}-session-host${suffix}.sock`)
706
+ path: path2.join(os2.tmpdir(), `${appName}-session-host${suffix}.sock`)
651
707
  };
652
708
  }
653
709
  function serializeEnvelope(envelope) {
@@ -869,10 +925,10 @@ function writeEnvelope(socket, envelope) {
869
925
  // src/instance-key.ts
870
926
  import * as crypto2 from "crypto";
871
927
  import * as fs from "fs";
872
- import * as os2 from "os";
928
+ import * as os3 from "os";
873
929
  import * as path3 from "path";
874
930
  var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
875
- function resolveInstanceConfigDir(env = process.env, homeDir = os2.homedir()) {
931
+ function resolveInstanceConfigDir(env = process.env, homeDir = os3.homedir()) {
876
932
  const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
877
933
  return override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
878
934
  }
@@ -897,17 +953,17 @@ function canonicalizeInstancePath(dir, platform2 = process.platform) {
897
953
  const real = realpathLongestExistingPrefix(resolved).replace(/[\\/]+$/, "");
898
954
  return platform2 === "win32" ? real.toLowerCase() : real;
899
955
  }
900
- function isDefaultInstanceConfigDir(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
956
+ function isDefaultInstanceConfigDir(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
901
957
  return canonicalizeInstancePath(configDir, platform2) === canonicalizeInstancePath(path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME), platform2);
902
958
  }
903
- function resolveSessionHostIpcKey(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
959
+ function resolveSessionHostIpcKey(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
904
960
  if (isDefaultInstanceConfigDir(configDir, homeDir, platform2)) return "";
905
961
  const canonical = canonicalizeInstancePath(configDir, platform2);
906
962
  return crypto2.createHash("sha256").update(canonical, "utf8").digest("hex").slice(0, 12);
907
963
  }
908
964
 
909
965
  // src/spawn-env.ts
910
- import * as os3 from "os";
966
+ import * as os4 from "os";
911
967
  import * as path4 from "path";
912
968
  function sanitizeSpawnEnv(baseEnv, overrides) {
913
969
  const env = {};
@@ -937,6 +993,27 @@ function sanitizeSpawnEnv(baseEnv, overrides) {
937
993
  applyTerminalColorEnv(env);
938
994
  return env;
939
995
  }
996
+ function replayLaunchEnv(command) {
997
+ if (command.envMode === "launch_overrides") return { ...command.env };
998
+ const roleKeys = /* @__PURE__ */ new Set([
999
+ "HOME",
1000
+ "USERPROFILE",
1001
+ "XDG_CONFIG_HOME",
1002
+ "CLAUDE_CONFIG_DIR",
1003
+ "CODEX_HOME",
1004
+ "KIMI_CODE_HOME",
1005
+ "GEMINI_CLI_HOME",
1006
+ "OPENCODE_CONFIG",
1007
+ "OPENCODE_CONFIG_CONTENT",
1008
+ "CLAUDE_CODE_DISABLE_AUTO_MEMORY",
1009
+ "TERMINAL_CWD",
1010
+ "ADHDEV_INLINE_MESH",
1011
+ "ADHDEV_ASSISTANT_SESSION_ID",
1012
+ "ADHDEV_COORDINATOR_SESSION_ID",
1013
+ "ADHDEV_CONFIG_DIR"
1014
+ ]);
1015
+ return Object.fromEntries(Object.entries(command.env ?? {}).filter(([key]) => roleKeys.has(key)));
1016
+ }
940
1017
  function applyTerminalColorEnv(env) {
941
1018
  if (env.NO_COLOR) return;
942
1019
  if (!env.TERM || env.TERM === "xterm-color") {
@@ -949,11 +1026,11 @@ function applyTerminalColorEnv(env) {
949
1026
  }
950
1027
  }
951
1028
  function ensureNodePtySpawnHelperPermissions(logFn) {
952
- if (os3.platform() === "win32") return;
1029
+ if (os4.platform() === "win32") return;
953
1030
  try {
954
1031
  const fs2 = __require("fs");
955
1032
  const ptyDir = path4.resolve(path4.dirname(__require.resolve("node-pty")), "..");
956
- const platformArch = `${os3.platform()}-${os3.arch()}`;
1033
+ const platformArch = `${os4.platform()}-${os4.arch()}`;
957
1034
  const helper = path4.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
958
1035
  if (fs2.existsSync(helper)) {
959
1036
  const stat = fs2.statSync(helper);
@@ -1008,6 +1085,9 @@ function createSessionHostControlPlane(transport) {
1008
1085
  };
1009
1086
  }
1010
1087
  export {
1088
+ CLI_CHILD_NICE_ENV,
1089
+ CLI_CHILD_NICE_INCREMENT,
1090
+ CLI_CHILD_SCHEDULING_ENV,
1011
1091
  DEFAULT_CONFIG_DIR_NAME,
1012
1092
  DEFAULT_SESSION_HOST_COLS,
1013
1093
  DEFAULT_SESSION_HOST_ROWS,
@@ -1021,6 +1101,7 @@ export {
1021
1101
  buildRuntimeKey,
1022
1102
  canonicalizeInstancePath,
1023
1103
  classifyTermination,
1104
+ createCliChildPriorityPolicy,
1024
1105
  createLineParser,
1025
1106
  createResponseEnvelope,
1026
1107
  createSessionHostControlPlane,
@@ -1030,12 +1111,14 @@ export {
1030
1111
  getSessionHostRecoveryLabel,
1031
1112
  getSessionHostSurfaceKind,
1032
1113
  getWorkspaceLabel,
1114
+ hiddenSpawn as hiddenSpawnProcess,
1033
1115
  isDefaultInstanceConfigDir,
1034
1116
  isSessionHostLiveRuntime,
1035
1117
  isSessionHostRecoverySnapshot,
1036
1118
  isTerminalRecord,
1037
1119
  partitionSessionHostDiagnosticsSessions,
1038
1120
  partitionSessionHostRecords,
1121
+ replayLaunchEnv,
1039
1122
  resolveAttachableRuntimeRecord,
1040
1123
  resolveInstanceConfigDir,
1041
1124
  resolveRuntimeRecord,
@@ -1043,6 +1126,7 @@ export {
1043
1126
  resolveSessionHostIpcKey,
1044
1127
  resolveSessionHostRows,
1045
1128
  sanitizeSpawnEnv,
1129
+ spawnCliChild,
1046
1130
  writeEnvelope
1047
1131
  };
1048
1132
  //# sourceMappingURL=index.mjs.map