@adhdev/session-host-core 1.0.82-rc.3 → 1.0.82-rc.30
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.d.mts +104 -3
- package/dist/index.d.ts +104 -3
- package/dist/index.js +347 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli-child-priority.ts +81 -0
- package/src/index.ts +9 -0
- package/src/ipc.ts +241 -31
- package/src/process/hidden-spawn.ts +10 -0
- package/src/spawn-env.ts +11 -0
- package/src/types.ts +26 -0
package/dist/index.mjs
CHANGED
|
@@ -7,12 +7,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
|
|
8
8
|
// src/types.ts
|
|
9
9
|
var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
|
|
10
|
+
"get_upgrade_lease",
|
|
11
|
+
"acquire_upgrade_lease",
|
|
12
|
+
"release_upgrade_lease",
|
|
10
13
|
"create_session",
|
|
11
14
|
"attach_session",
|
|
12
15
|
"detach_session",
|
|
13
16
|
"send_input",
|
|
14
17
|
"resize_session",
|
|
15
18
|
"stop_session",
|
|
19
|
+
"stop_mesh_writer",
|
|
16
20
|
"delete_session",
|
|
17
21
|
"resume_session",
|
|
18
22
|
"acquire_write",
|
|
@@ -62,6 +66,62 @@ function classifyTermination(input) {
|
|
|
62
66
|
return termination;
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
// src/cli-child-priority.ts
|
|
70
|
+
import * as os from "os";
|
|
71
|
+
|
|
72
|
+
// src/process/hidden-spawn.ts
|
|
73
|
+
import { spawn } from "child_process";
|
|
74
|
+
function hiddenSpawn(command, args = [], options = {}) {
|
|
75
|
+
return spawn(command, args, { windowsHide: true, ...options });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/cli-child-priority.ts
|
|
79
|
+
var CLI_CHILD_NICE_INCREMENT = 10;
|
|
80
|
+
var CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
81
|
+
var CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
82
|
+
function setDarwinBackground(pid, onFailure) {
|
|
83
|
+
const task = hiddenSpawn("/usr/sbin/taskpolicy", ["-b", "-p", String(pid)], { stdio: "ignore" });
|
|
84
|
+
task.once("error", onFailure);
|
|
85
|
+
task.once("exit", (code, signal) => {
|
|
86
|
+
if (code !== 0) onFailure(new Error(`taskpolicy exited with ${signal ?? code}`));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function createCliChildPriorityPolicy(deps = {
|
|
90
|
+
platform: process.platform,
|
|
91
|
+
getPriority: os.getPriority,
|
|
92
|
+
setPriority: os.setPriority,
|
|
93
|
+
setDarwinBackground
|
|
94
|
+
}) {
|
|
95
|
+
let failureLogged = false;
|
|
96
|
+
return function spawnCliChild2(spawnChild, env = process.env, logInfo = console.info) {
|
|
97
|
+
const child = spawnChild();
|
|
98
|
+
const pid = child.pid;
|
|
99
|
+
if (env[CLI_CHILD_NICE_ENV] === "0" || typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return child;
|
|
100
|
+
const onFailure = (error) => {
|
|
101
|
+
if (!failureLogged) {
|
|
102
|
+
failureLogged = true;
|
|
103
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
104
|
+
logInfo(`[cli-child-priority] Could not apply CLI child scheduling (pid ${pid}); continuing: ${detail}`);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
const priority = deps.platform === "win32" ? os.constants.priority.PRIORITY_BELOW_NORMAL : Math.min(19, deps.getPriority(pid) + CLI_CHILD_NICE_INCREMENT);
|
|
109
|
+
deps.setPriority(pid, priority);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
onFailure(error);
|
|
112
|
+
}
|
|
113
|
+
if (deps.platform === "darwin" && env[CLI_CHILD_SCHEDULING_ENV] === "darwin-bg") {
|
|
114
|
+
try {
|
|
115
|
+
deps.setDarwinBackground?.(pid, onFailure);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
onFailure(error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return child;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var spawnCliChild = createCliChildPriorityPolicy();
|
|
124
|
+
|
|
65
125
|
// src/buffer.ts
|
|
66
126
|
var DEFAULT_SESSION_RING_BUFFER_MAX_BYTES = 4 * 1024 * 1024;
|
|
67
127
|
var SessionRingBuffer = class {
|
|
@@ -625,7 +685,7 @@ function cloneMeta(meta) {
|
|
|
625
685
|
}
|
|
626
686
|
|
|
627
687
|
// src/ipc.ts
|
|
628
|
-
import * as
|
|
688
|
+
import * as os2 from "os";
|
|
629
689
|
import * as path2 from "path";
|
|
630
690
|
import * as net from "net";
|
|
631
691
|
import { StringDecoder } from "string_decoder";
|
|
@@ -644,7 +704,7 @@ function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
|
|
|
644
704
|
}
|
|
645
705
|
return {
|
|
646
706
|
kind: "unix",
|
|
647
|
-
path: path2.join(
|
|
707
|
+
path: path2.join(os2.tmpdir(), `${appName}-session-host${suffix}.sock`)
|
|
648
708
|
};
|
|
649
709
|
}
|
|
650
710
|
function serializeEnvelope(envelope) {
|
|
@@ -674,16 +734,59 @@ function createLineParser(onEnvelope) {
|
|
|
674
734
|
return parser;
|
|
675
735
|
}
|
|
676
736
|
var establishedSockets = /* @__PURE__ */ new WeakSet();
|
|
737
|
+
var activeClientRefs = /* @__PURE__ */ new Set();
|
|
738
|
+
function disconnectSessionHostClients(endpoint, error) {
|
|
739
|
+
for (const ref of activeClientRefs) {
|
|
740
|
+
const client = ref.deref();
|
|
741
|
+
if (!client) {
|
|
742
|
+
activeClientRefs.delete(ref);
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
if (!endpoint || client.endpoint.path === endpoint.path) {
|
|
746
|
+
client.disconnect(error);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function findConnectedSessionHostClient(endpoint) {
|
|
751
|
+
for (const ref of activeClientRefs) {
|
|
752
|
+
const client = ref.deref();
|
|
753
|
+
if (!client) {
|
|
754
|
+
activeClientRefs.delete(ref);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
if ((!endpoint || client.endpoint.path === endpoint.path) && client.isConnected()) {
|
|
758
|
+
return client;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
677
763
|
var SessionHostClient = class {
|
|
678
764
|
endpoint;
|
|
679
765
|
socket = null;
|
|
766
|
+
connectPromise = null;
|
|
767
|
+
requestTimeoutMs = 3e4;
|
|
680
768
|
requestWaiters = /* @__PURE__ */ new Map();
|
|
681
769
|
eventListeners = /* @__PURE__ */ new Set();
|
|
682
770
|
disconnectListeners = /* @__PURE__ */ new Set();
|
|
683
771
|
/** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
|
|
684
772
|
disconnectedSockets = /* @__PURE__ */ new WeakSet();
|
|
773
|
+
/** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
|
|
774
|
+
attachedSessions = /* @__PURE__ */ new Map();
|
|
685
775
|
constructor(options = {}) {
|
|
686
776
|
this.endpoint = options.endpoint || getDefaultSessionHostEndpoint(options.appName || "adhdev");
|
|
777
|
+
if (typeof options.requestTimeoutMs === "number" && options.requestTimeoutMs > 0) {
|
|
778
|
+
this.requestTimeoutMs = options.requestTimeoutMs;
|
|
779
|
+
}
|
|
780
|
+
if (options.registerAsShared !== false) activeClientRefs.add(new WeakRef(this));
|
|
781
|
+
}
|
|
782
|
+
static disconnectClients(endpoint, error) {
|
|
783
|
+
disconnectSessionHostClients(endpoint, error);
|
|
784
|
+
}
|
|
785
|
+
static findConnectedClient(endpoint) {
|
|
786
|
+
return findConnectedSessionHostClient(endpoint);
|
|
787
|
+
}
|
|
788
|
+
isConnected() {
|
|
789
|
+
return Boolean(this.socket && !this.socket.destroyed && establishedSockets.has(this.socket));
|
|
687
790
|
}
|
|
688
791
|
/**
|
|
689
792
|
* Fires when an established connection to the session host goes away.
|
|
@@ -726,6 +829,7 @@ var SessionHostClient = class {
|
|
|
726
829
|
this.requestWaiters.clear();
|
|
727
830
|
if (this.socket === socket) {
|
|
728
831
|
this.socket = null;
|
|
832
|
+
this.connectPromise = null;
|
|
729
833
|
}
|
|
730
834
|
try {
|
|
731
835
|
socket.destroy();
|
|
@@ -745,8 +849,62 @@ var SessionHostClient = class {
|
|
|
745
849
|
}
|
|
746
850
|
}
|
|
747
851
|
}
|
|
748
|
-
|
|
749
|
-
|
|
852
|
+
sendRawRequestOnSocket(socket, request, timeoutMs = this.requestTimeoutMs) {
|
|
853
|
+
const requestId = generateUUID();
|
|
854
|
+
const envelope = {
|
|
855
|
+
kind: "request",
|
|
856
|
+
requestId,
|
|
857
|
+
request
|
|
858
|
+
};
|
|
859
|
+
const timeoutLabel = timeoutMs % 1e3 === 0 ? `${timeoutMs / 1e3}s` : `${timeoutMs}ms`;
|
|
860
|
+
const startedAt = Date.now();
|
|
861
|
+
const startedMonotonicAt = performance.now();
|
|
862
|
+
return new Promise((resolve3, reject) => {
|
|
863
|
+
const timeout = setTimeout(() => {
|
|
864
|
+
const actualElapsedMs = Math.max(0, Math.round(performance.now() - startedMonotonicAt));
|
|
865
|
+
const wallElapsedMs = Math.max(0, Date.now() - startedAt);
|
|
866
|
+
const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
|
|
867
|
+
const timeoutError = Object.assign(
|
|
868
|
+
new Error(`Session host request timed out after ${timeoutLabel} (${request.type})`),
|
|
869
|
+
{
|
|
870
|
+
code: "SESSION_HOST_REQUEST_TIMEOUT",
|
|
871
|
+
requestType: request.type,
|
|
872
|
+
scheduledTimeoutMs: timeoutMs,
|
|
873
|
+
actualElapsedMs,
|
|
874
|
+
wallElapsedMs,
|
|
875
|
+
observerLagMs
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
if (this.socket === socket) {
|
|
879
|
+
this.disconnect(timeoutError);
|
|
880
|
+
} else {
|
|
881
|
+
this.requestWaiters.delete(requestId);
|
|
882
|
+
this.disconnectedSockets.add(socket);
|
|
883
|
+
try {
|
|
884
|
+
socket.destroy();
|
|
885
|
+
} catch {
|
|
886
|
+
}
|
|
887
|
+
reject(timeoutError);
|
|
888
|
+
}
|
|
889
|
+
}, timeoutMs);
|
|
890
|
+
this.requestWaiters.set(requestId, {
|
|
891
|
+
resolve: (value) => {
|
|
892
|
+
clearTimeout(timeout);
|
|
893
|
+
resolve3(value);
|
|
894
|
+
},
|
|
895
|
+
reject: (error) => {
|
|
896
|
+
clearTimeout(timeout);
|
|
897
|
+
reject(error);
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
socket.write(serializeEnvelope(envelope));
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
async connect(timeoutMs = this.requestTimeoutMs) {
|
|
904
|
+
if (this.socket && !this.socket.destroyed) {
|
|
905
|
+
if (this.connectPromise) await this.connectPromise;
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
750
908
|
if (this.socket) {
|
|
751
909
|
try {
|
|
752
910
|
this.socket.destroy();
|
|
@@ -754,6 +912,7 @@ var SessionHostClient = class {
|
|
|
754
912
|
}
|
|
755
913
|
this.socket = null;
|
|
756
914
|
}
|
|
915
|
+
this.connectPromise = null;
|
|
757
916
|
const socket = net.createConnection(this.endpoint.path);
|
|
758
917
|
this.socket = socket;
|
|
759
918
|
const parser = createLineParser((envelope) => {
|
|
@@ -787,13 +946,68 @@ var SessionHostClient = class {
|
|
|
787
946
|
socket.on("end", () => {
|
|
788
947
|
this.handleDisconnect(socket, "ended", void 0, flushParser().length);
|
|
789
948
|
});
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
949
|
+
const connectTask = (async () => {
|
|
950
|
+
await new Promise((resolve3, reject) => {
|
|
951
|
+
const cleanup = () => {
|
|
952
|
+
clearTimeout(timer);
|
|
953
|
+
socket.off("connect", connected);
|
|
954
|
+
socket.off("error", failed);
|
|
955
|
+
socket.off("close", closed);
|
|
956
|
+
};
|
|
957
|
+
const connected = () => {
|
|
958
|
+
cleanup();
|
|
959
|
+
establishedSockets.add(socket);
|
|
960
|
+
resolve3();
|
|
961
|
+
};
|
|
962
|
+
const failed = (error) => {
|
|
963
|
+
cleanup();
|
|
964
|
+
reject(error);
|
|
965
|
+
};
|
|
966
|
+
const closed = () => failed(new Error("Session host connection closed before connect"));
|
|
967
|
+
const connectStartedAt = Date.now();
|
|
968
|
+
const connectStartedMonotonicAt = performance.now();
|
|
969
|
+
const timer = setTimeout(() => {
|
|
970
|
+
const actualElapsedMs = Math.max(0, Math.round(performance.now() - connectStartedMonotonicAt));
|
|
971
|
+
const wallElapsedMs = Math.max(0, Date.now() - connectStartedAt);
|
|
972
|
+
const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
|
|
973
|
+
const error = Object.assign(
|
|
974
|
+
new Error(`Session host connect timed out after ${timeoutMs}ms`),
|
|
975
|
+
{
|
|
976
|
+
code: "SESSION_HOST_CONNECT_TIMEOUT",
|
|
977
|
+
scheduledTimeoutMs: timeoutMs,
|
|
978
|
+
actualElapsedMs,
|
|
979
|
+
wallElapsedMs,
|
|
980
|
+
observerLagMs
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
failed(error);
|
|
984
|
+
if (this.socket === socket) this.disconnect(error);
|
|
985
|
+
}, timeoutMs);
|
|
986
|
+
socket.once("connect", connected);
|
|
987
|
+
socket.once("error", failed);
|
|
988
|
+
socket.once("close", closed);
|
|
794
989
|
});
|
|
795
|
-
socket.
|
|
796
|
-
|
|
990
|
+
if (this.attachedSessions.size > 0 && this.socket === socket && !socket.destroyed) {
|
|
991
|
+
for (const [sessionId, sub] of [...this.attachedSessions.entries()]) {
|
|
992
|
+
if (this.socket !== socket || socket.destroyed) break;
|
|
993
|
+
const replayResponse = await this.sendRawRequestOnSocket(socket, {
|
|
994
|
+
type: "attach_session",
|
|
995
|
+
payload: sub
|
|
996
|
+
}).catch(() => null);
|
|
997
|
+
if (replayResponse && !replayResponse.success) {
|
|
998
|
+
this.attachedSessions.delete(sessionId);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
})();
|
|
1003
|
+
this.connectPromise = connectTask;
|
|
1004
|
+
try {
|
|
1005
|
+
await connectTask;
|
|
1006
|
+
} finally {
|
|
1007
|
+
if (this.connectPromise === connectTask) {
|
|
1008
|
+
this.connectPromise = null;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
797
1011
|
}
|
|
798
1012
|
onEvent(listener) {
|
|
799
1013
|
this.eventListeners.add(listener);
|
|
@@ -801,35 +1015,87 @@ var SessionHostClient = class {
|
|
|
801
1015
|
this.eventListeners.delete(listener);
|
|
802
1016
|
};
|
|
803
1017
|
}
|
|
804
|
-
async request(request) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
1018
|
+
async request(request, options = {}) {
|
|
1019
|
+
const timeoutMs = Math.max(1, options.timeoutMs ?? this.requestTimeoutMs);
|
|
1020
|
+
const deadline = Date.now() + timeoutMs;
|
|
1021
|
+
const alreadyConnected = this.isConnected() && !this.connectPromise;
|
|
1022
|
+
if (options.timeoutMs !== void 0) {
|
|
1023
|
+
let timer;
|
|
1024
|
+
const raceStartedAt = Date.now();
|
|
1025
|
+
const raceStartedMonotonicAt = performance.now();
|
|
1026
|
+
try {
|
|
1027
|
+
await Promise.race([
|
|
1028
|
+
this.connect(timeoutMs),
|
|
1029
|
+
new Promise((_resolve, reject) => {
|
|
1030
|
+
timer = setTimeout(() => {
|
|
1031
|
+
const actualElapsedMs = Math.max(0, Math.round(performance.now() - raceStartedMonotonicAt));
|
|
1032
|
+
const wallElapsedMs = Math.max(0, Date.now() - raceStartedAt);
|
|
1033
|
+
const observerLagMs = Math.max(0, actualElapsedMs - timeoutMs);
|
|
1034
|
+
const error = Object.assign(
|
|
1035
|
+
new Error(`Session host connect timed out after ${timeoutMs}ms`),
|
|
1036
|
+
{
|
|
1037
|
+
code: "SESSION_HOST_CONNECT_TIMEOUT",
|
|
1038
|
+
scheduledTimeoutMs: timeoutMs,
|
|
1039
|
+
actualElapsedMs,
|
|
1040
|
+
wallElapsedMs,
|
|
1041
|
+
observerLagMs
|
|
1042
|
+
}
|
|
1043
|
+
);
|
|
1044
|
+
reject(error);
|
|
1045
|
+
this.disconnect(error);
|
|
1046
|
+
}, timeoutMs);
|
|
1047
|
+
})
|
|
1048
|
+
]);
|
|
1049
|
+
} finally {
|
|
1050
|
+
if (timer) clearTimeout(timer);
|
|
1051
|
+
}
|
|
1052
|
+
} else {
|
|
1053
|
+
await this.connect(timeoutMs);
|
|
1054
|
+
}
|
|
1055
|
+
const requestSocket = this.socket;
|
|
1056
|
+
if (!requestSocket) throw new Error("Session host socket unavailable");
|
|
1057
|
+
const response = await this.sendRawRequestOnSocket(requestSocket, request, options.timeoutMs === void 0 || alreadyConnected ? timeoutMs : Math.max(1, deadline - Date.now()));
|
|
1058
|
+
if (response.success) {
|
|
1059
|
+
if (request.type === "attach_session") {
|
|
1060
|
+
this.attachedSessions.set(request.payload.sessionId, {
|
|
1061
|
+
sessionId: request.payload.sessionId,
|
|
1062
|
+
clientId: request.payload.clientId,
|
|
1063
|
+
clientType: request.payload.clientType,
|
|
1064
|
+
readOnly: request.payload.readOnly === true
|
|
1065
|
+
});
|
|
1066
|
+
} else if (request.type === "create_session") {
|
|
1067
|
+
const createdId = response.result?.sessionId || request.payload.sessionId;
|
|
1068
|
+
const clientId = typeof request.payload.clientId === "string" ? request.payload.clientId.trim() : "";
|
|
1069
|
+
if (createdId && clientId) {
|
|
1070
|
+
this.attachedSessions.set(createdId, {
|
|
1071
|
+
sessionId: createdId,
|
|
1072
|
+
clientId,
|
|
1073
|
+
clientType: request.payload.clientType || "daemon",
|
|
1074
|
+
readOnly: false
|
|
1075
|
+
});
|
|
826
1076
|
}
|
|
827
|
-
})
|
|
828
|
-
|
|
829
|
-
|
|
1077
|
+
} else if (request.type === "detach_session" || request.type === "delete_session") {
|
|
1078
|
+
this.attachedSessions.delete(request.payload.sessionId);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
830
1081
|
return response;
|
|
831
1082
|
}
|
|
1083
|
+
disconnect(error) {
|
|
1084
|
+
const socket = this.socket;
|
|
1085
|
+
if (socket) {
|
|
1086
|
+
this.handleDisconnect(socket, error ? "error" : "closed", error, 0);
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
this.connectPromise = null;
|
|
1090
|
+
const failure = error || new Error(`Session host client disconnected (${this.endpoint.path})`);
|
|
1091
|
+
for (const waiter of this.requestWaiters.values()) {
|
|
1092
|
+
waiter.reject(failure);
|
|
1093
|
+
}
|
|
1094
|
+
this.requestWaiters.clear();
|
|
1095
|
+
}
|
|
832
1096
|
async close() {
|
|
1097
|
+
this.attachedSessions.clear();
|
|
1098
|
+
this.connectPromise = null;
|
|
833
1099
|
if (!this.socket) return;
|
|
834
1100
|
const socket = this.socket;
|
|
835
1101
|
this.socket = null;
|
|
@@ -866,10 +1132,10 @@ function writeEnvelope(socket, envelope) {
|
|
|
866
1132
|
// src/instance-key.ts
|
|
867
1133
|
import * as crypto2 from "crypto";
|
|
868
1134
|
import * as fs from "fs";
|
|
869
|
-
import * as
|
|
1135
|
+
import * as os3 from "os";
|
|
870
1136
|
import * as path3 from "path";
|
|
871
1137
|
var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
872
|
-
function resolveInstanceConfigDir(env = process.env, homeDir =
|
|
1138
|
+
function resolveInstanceConfigDir(env = process.env, homeDir = os3.homedir()) {
|
|
873
1139
|
const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
|
|
874
1140
|
return override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
|
|
875
1141
|
}
|
|
@@ -894,17 +1160,17 @@ function canonicalizeInstancePath(dir, platform2 = process.platform) {
|
|
|
894
1160
|
const real = realpathLongestExistingPrefix(resolved).replace(/[\\/]+$/, "");
|
|
895
1161
|
return platform2 === "win32" ? real.toLowerCase() : real;
|
|
896
1162
|
}
|
|
897
|
-
function isDefaultInstanceConfigDir(configDir, homeDir =
|
|
1163
|
+
function isDefaultInstanceConfigDir(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
|
|
898
1164
|
return canonicalizeInstancePath(configDir, platform2) === canonicalizeInstancePath(path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME), platform2);
|
|
899
1165
|
}
|
|
900
|
-
function resolveSessionHostIpcKey(configDir, homeDir =
|
|
1166
|
+
function resolveSessionHostIpcKey(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
|
|
901
1167
|
if (isDefaultInstanceConfigDir(configDir, homeDir, platform2)) return "";
|
|
902
1168
|
const canonical = canonicalizeInstancePath(configDir, platform2);
|
|
903
1169
|
return crypto2.createHash("sha256").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
904
1170
|
}
|
|
905
1171
|
|
|
906
1172
|
// src/spawn-env.ts
|
|
907
|
-
import * as
|
|
1173
|
+
import * as os4 from "os";
|
|
908
1174
|
import * as path4 from "path";
|
|
909
1175
|
function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
910
1176
|
const env = {};
|
|
@@ -934,6 +1200,27 @@ function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
|
934
1200
|
applyTerminalColorEnv(env);
|
|
935
1201
|
return env;
|
|
936
1202
|
}
|
|
1203
|
+
function replayLaunchEnv(command) {
|
|
1204
|
+
if (command.envMode === "launch_overrides") return { ...command.env };
|
|
1205
|
+
const roleKeys = /* @__PURE__ */ new Set([
|
|
1206
|
+
"HOME",
|
|
1207
|
+
"USERPROFILE",
|
|
1208
|
+
"XDG_CONFIG_HOME",
|
|
1209
|
+
"CLAUDE_CONFIG_DIR",
|
|
1210
|
+
"CODEX_HOME",
|
|
1211
|
+
"KIMI_CODE_HOME",
|
|
1212
|
+
"GEMINI_CLI_HOME",
|
|
1213
|
+
"OPENCODE_CONFIG",
|
|
1214
|
+
"OPENCODE_CONFIG_CONTENT",
|
|
1215
|
+
"CLAUDE_CODE_DISABLE_AUTO_MEMORY",
|
|
1216
|
+
"TERMINAL_CWD",
|
|
1217
|
+
"ADHDEV_INLINE_MESH",
|
|
1218
|
+
"ADHDEV_ASSISTANT_SESSION_ID",
|
|
1219
|
+
"ADHDEV_COORDINATOR_SESSION_ID",
|
|
1220
|
+
"ADHDEV_CONFIG_DIR"
|
|
1221
|
+
]);
|
|
1222
|
+
return Object.fromEntries(Object.entries(command.env ?? {}).filter(([key]) => roleKeys.has(key)));
|
|
1223
|
+
}
|
|
937
1224
|
function applyTerminalColorEnv(env) {
|
|
938
1225
|
if (env.NO_COLOR) return;
|
|
939
1226
|
if (!env.TERM || env.TERM === "xterm-color") {
|
|
@@ -946,11 +1233,11 @@ function applyTerminalColorEnv(env) {
|
|
|
946
1233
|
}
|
|
947
1234
|
}
|
|
948
1235
|
function ensureNodePtySpawnHelperPermissions(logFn) {
|
|
949
|
-
if (
|
|
1236
|
+
if (os4.platform() === "win32") return;
|
|
950
1237
|
try {
|
|
951
1238
|
const fs2 = __require("fs");
|
|
952
1239
|
const ptyDir = path4.resolve(path4.dirname(__require.resolve("node-pty")), "..");
|
|
953
|
-
const platformArch = `${
|
|
1240
|
+
const platformArch = `${os4.platform()}-${os4.arch()}`;
|
|
954
1241
|
const helper = path4.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
955
1242
|
if (fs2.existsSync(helper)) {
|
|
956
1243
|
const stat = fs2.statSync(helper);
|
|
@@ -1005,6 +1292,9 @@ function createSessionHostControlPlane(transport) {
|
|
|
1005
1292
|
};
|
|
1006
1293
|
}
|
|
1007
1294
|
export {
|
|
1295
|
+
CLI_CHILD_NICE_ENV,
|
|
1296
|
+
CLI_CHILD_NICE_INCREMENT,
|
|
1297
|
+
CLI_CHILD_SCHEDULING_ENV,
|
|
1008
1298
|
DEFAULT_CONFIG_DIR_NAME,
|
|
1009
1299
|
DEFAULT_SESSION_HOST_COLS,
|
|
1010
1300
|
DEFAULT_SESSION_HOST_ROWS,
|
|
@@ -1018,21 +1308,26 @@ export {
|
|
|
1018
1308
|
buildRuntimeKey,
|
|
1019
1309
|
canonicalizeInstancePath,
|
|
1020
1310
|
classifyTermination,
|
|
1311
|
+
createCliChildPriorityPolicy,
|
|
1021
1312
|
createLineParser,
|
|
1022
1313
|
createResponseEnvelope,
|
|
1023
1314
|
createSessionHostControlPlane,
|
|
1315
|
+
disconnectSessionHostClients,
|
|
1024
1316
|
ensureNodePtySpawnHelperPermissions,
|
|
1317
|
+
findConnectedSessionHostClient,
|
|
1025
1318
|
formatRuntimeOwner,
|
|
1026
1319
|
getDefaultSessionHostEndpoint,
|
|
1027
1320
|
getSessionHostRecoveryLabel,
|
|
1028
1321
|
getSessionHostSurfaceKind,
|
|
1029
1322
|
getWorkspaceLabel,
|
|
1323
|
+
hiddenSpawn as hiddenSpawnProcess,
|
|
1030
1324
|
isDefaultInstanceConfigDir,
|
|
1031
1325
|
isSessionHostLiveRuntime,
|
|
1032
1326
|
isSessionHostRecoverySnapshot,
|
|
1033
1327
|
isTerminalRecord,
|
|
1034
1328
|
partitionSessionHostDiagnosticsSessions,
|
|
1035
1329
|
partitionSessionHostRecords,
|
|
1330
|
+
replayLaunchEnv,
|
|
1036
1331
|
resolveAttachableRuntimeRecord,
|
|
1037
1332
|
resolveInstanceConfigDir,
|
|
1038
1333
|
resolveRuntimeRecord,
|
|
@@ -1040,6 +1335,7 @@ export {
|
|
|
1040
1335
|
resolveSessionHostIpcKey,
|
|
1041
1336
|
resolveSessionHostRows,
|
|
1042
1337
|
sanitizeSpawnEnv,
|
|
1338
|
+
spawnCliChild,
|
|
1043
1339
|
writeEnvelope
|
|
1044
1340
|
};
|
|
1045
1341
|
//# sourceMappingURL=index.mjs.map
|