@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.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.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
import { SpawnOptions, ChildProcess } from 'node:child_process';
|
|
1
3
|
import * as net from 'net';
|
|
2
4
|
export { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS, resolveSessionHostCols, resolveSessionHostRows } from './defaults.mjs';
|
|
3
5
|
|
|
@@ -10,6 +12,8 @@ interface SessionLaunchCommand {
|
|
|
10
12
|
command: string;
|
|
11
13
|
args: string[];
|
|
12
14
|
env?: Record<string, string>;
|
|
15
|
+
/** Unmarked older daemon records contained the full inherited environment. */
|
|
16
|
+
envMode?: 'launch_overrides';
|
|
13
17
|
}
|
|
14
18
|
interface SessionWriteOwner {
|
|
15
19
|
clientId: string;
|
|
@@ -144,6 +148,26 @@ interface ResizeSessionPayload {
|
|
|
144
148
|
interface StopSessionPayload {
|
|
145
149
|
sessionId: string;
|
|
146
150
|
}
|
|
151
|
+
interface MeshWriterAssignment {
|
|
152
|
+
meshId: string;
|
|
153
|
+
nodeId: string;
|
|
154
|
+
taskId: string;
|
|
155
|
+
attemptId: string;
|
|
156
|
+
generation: number;
|
|
157
|
+
dispatchNonce: number;
|
|
158
|
+
ownerDaemonId: string;
|
|
159
|
+
}
|
|
160
|
+
interface MeshWriterStopTarget {
|
|
161
|
+
runtimeKey: string;
|
|
162
|
+
startedAt: number;
|
|
163
|
+
osPid: number;
|
|
164
|
+
providerType: string;
|
|
165
|
+
assignment: MeshWriterAssignment;
|
|
166
|
+
}
|
|
167
|
+
interface StopMeshWriterPayload extends MeshWriterStopTarget {
|
|
168
|
+
sessionId: string;
|
|
169
|
+
clientId: string;
|
|
170
|
+
}
|
|
147
171
|
interface DeleteSessionPayload {
|
|
148
172
|
sessionId: string;
|
|
149
173
|
/** Stop a live runtime before deleting the persisted record. */
|
|
@@ -267,7 +291,22 @@ interface SessionHostDiagnostics {
|
|
|
267
291
|
recentRequests: SessionHostRequestTrace[];
|
|
268
292
|
recentTransitions: SessionHostRuntimeTransition[];
|
|
269
293
|
}
|
|
294
|
+
interface HostUpgradeLeasePayload {
|
|
295
|
+
bootId: string;
|
|
296
|
+
epoch: number;
|
|
297
|
+
owner: string;
|
|
298
|
+
token: string;
|
|
299
|
+
}
|
|
270
300
|
type SessionHostRequest = {
|
|
301
|
+
type: 'get_upgrade_lease';
|
|
302
|
+
payload?: {};
|
|
303
|
+
} | {
|
|
304
|
+
type: 'acquire_upgrade_lease';
|
|
305
|
+
payload: HostUpgradeLeasePayload;
|
|
306
|
+
} | {
|
|
307
|
+
type: 'release_upgrade_lease';
|
|
308
|
+
payload: HostUpgradeLeasePayload;
|
|
309
|
+
} | {
|
|
271
310
|
type: 'create_session';
|
|
272
311
|
payload: CreateSessionPayload;
|
|
273
312
|
} | {
|
|
@@ -285,6 +324,9 @@ type SessionHostRequest = {
|
|
|
285
324
|
} | {
|
|
286
325
|
type: 'stop_session';
|
|
287
326
|
payload: StopSessionPayload;
|
|
327
|
+
} | {
|
|
328
|
+
type: 'stop_mesh_writer';
|
|
329
|
+
payload: StopMeshWriterPayload;
|
|
288
330
|
} | {
|
|
289
331
|
type: 'delete_session';
|
|
290
332
|
payload: DeleteSessionPayload;
|
|
@@ -434,6 +476,43 @@ interface ClassifyTerminationInput {
|
|
|
434
476
|
*/
|
|
435
477
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
436
478
|
|
|
479
|
+
/** Relative POSIX niceness adjustment for newly spawned agent workloads. */
|
|
480
|
+
declare const CLI_CHILD_NICE_INCREMENT = 10;
|
|
481
|
+
/** Set to "0" in the daemon environment (or launch env) to disable lowering. */
|
|
482
|
+
declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
483
|
+
/** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
|
|
484
|
+
declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
485
|
+
declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
|
|
486
|
+
interface PriorityDependencies {
|
|
487
|
+
platform: NodeJS.Platform;
|
|
488
|
+
getPriority: typeof os.getPriority;
|
|
489
|
+
setPriority: typeof os.setPriority;
|
|
490
|
+
setDarwinBackground?: typeof setDarwinBackground;
|
|
491
|
+
}
|
|
492
|
+
/** Separate policy instances are useful for platform/error tests. */
|
|
493
|
+
declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
|
|
494
|
+
readonly pid?: number;
|
|
495
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
496
|
+
/**
|
|
497
|
+
* Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
|
|
498
|
+
* workers, version probes and git helpers at their existing priority.
|
|
499
|
+
*
|
|
500
|
+
* node-pty has no pre-spawn priority hook. Apply immediately on return, before
|
|
501
|
+
* registering listeners/doing other work. There is a spawn-to-setPriority race:
|
|
502
|
+
* a child can run (and fork) before this call. Later descendants inherit nice
|
|
503
|
+
* on POSIX; early descendants are not retroactively changed. Windows creation
|
|
504
|
+
* and ConPTY inheritance require verification on the DesktopA.
|
|
505
|
+
* Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
|
|
506
|
+
* extra helper startup adds a further race before the background class takes
|
|
507
|
+
* effect. It also throttles I/O, so nice alone remains the default.
|
|
508
|
+
*/
|
|
509
|
+
declare const spawnCliChild: <T extends {
|
|
510
|
+
readonly pid?: number;
|
|
511
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
512
|
+
|
|
513
|
+
/** Shared hidden-window primitive for daemon and session-host process helpers. */
|
|
514
|
+
declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
|
|
515
|
+
|
|
437
516
|
interface SessionRingBufferOptions {
|
|
438
517
|
maxBytes?: number;
|
|
439
518
|
}
|
|
@@ -606,6 +685,9 @@ declare function createLineParser<TEnvelope = SessionHostWireEnvelope>(onEnvelop
|
|
|
606
685
|
interface SessionHostClientOptions {
|
|
607
686
|
endpoint?: SessionHostEndpoint;
|
|
608
687
|
appName?: string;
|
|
688
|
+
requestTimeoutMs?: number;
|
|
689
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
690
|
+
registerAsShared?: boolean;
|
|
609
691
|
}
|
|
610
692
|
/**
|
|
611
693
|
* Why an established session-host connection went away.
|
|
@@ -614,6 +696,8 @@ interface SessionHostClientOptions {
|
|
|
614
696
|
* - `closed` — socket fully closed ('close') without a preceding error/end
|
|
615
697
|
*/
|
|
616
698
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
699
|
+
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
700
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
617
701
|
interface SessionHostDisconnectInfo {
|
|
618
702
|
reason: SessionHostDisconnectReason;
|
|
619
703
|
endpointPath: string;
|
|
@@ -634,12 +718,19 @@ interface SessionHostDisconnectInfo {
|
|
|
634
718
|
declare class SessionHostClient {
|
|
635
719
|
readonly endpoint: SessionHostEndpoint;
|
|
636
720
|
private socket;
|
|
721
|
+
private connectPromise;
|
|
722
|
+
private requestTimeoutMs;
|
|
637
723
|
private requestWaiters;
|
|
638
724
|
private eventListeners;
|
|
639
725
|
private disconnectListeners;
|
|
640
726
|
/** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
|
|
641
727
|
private disconnectedSockets;
|
|
728
|
+
/** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
|
|
729
|
+
private attachedSessions;
|
|
642
730
|
constructor(options?: SessionHostClientOptions);
|
|
731
|
+
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
732
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
733
|
+
isConnected(): boolean;
|
|
643
734
|
/**
|
|
644
735
|
* Fires when an established connection to the session host goes away.
|
|
645
736
|
*
|
|
@@ -654,9 +745,13 @@ declare class SessionHostClient {
|
|
|
654
745
|
*/
|
|
655
746
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
656
747
|
private handleDisconnect;
|
|
657
|
-
|
|
748
|
+
private sendRawRequestOnSocket;
|
|
749
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
658
750
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
659
|
-
request<T = unknown>(request: SessionHostRequest
|
|
751
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
752
|
+
timeoutMs?: number;
|
|
753
|
+
}): Promise<SessionHostResponse<T>>;
|
|
754
|
+
disconnect(error?: Error): void;
|
|
660
755
|
close(): Promise<void>;
|
|
661
756
|
}
|
|
662
757
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
@@ -734,6 +829,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
734
829
|
* with child CLI processes and apply terminal colour defaults.
|
|
735
830
|
*/
|
|
736
831
|
declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
|
|
832
|
+
/** Recover only role bindings from legacy full-environment snapshots.
|
|
833
|
+
* New records distinguish explicit overrides, including intentional custom keys. */
|
|
834
|
+
declare function replayLaunchEnv(command: {
|
|
835
|
+
env?: Record<string, string>;
|
|
836
|
+
envMode?: 'launch_overrides';
|
|
837
|
+
}): Record<string, string>;
|
|
737
838
|
/**
|
|
738
839
|
* Apply preferred terminal colour environment variables.
|
|
739
840
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -809,4 +910,4 @@ interface SessionHostControlTransport {
|
|
|
809
910
|
*/
|
|
810
911
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
811
912
|
|
|
812
|
-
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, writeEnvelope };
|
|
913
|
+
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopMeshWriterPayload, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
import { SpawnOptions, ChildProcess } from 'node:child_process';
|
|
1
3
|
import * as net from 'net';
|
|
2
4
|
export { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS, resolveSessionHostCols, resolveSessionHostRows } from './defaults.js';
|
|
3
5
|
|
|
@@ -10,6 +12,8 @@ interface SessionLaunchCommand {
|
|
|
10
12
|
command: string;
|
|
11
13
|
args: string[];
|
|
12
14
|
env?: Record<string, string>;
|
|
15
|
+
/** Unmarked older daemon records contained the full inherited environment. */
|
|
16
|
+
envMode?: 'launch_overrides';
|
|
13
17
|
}
|
|
14
18
|
interface SessionWriteOwner {
|
|
15
19
|
clientId: string;
|
|
@@ -144,6 +148,26 @@ interface ResizeSessionPayload {
|
|
|
144
148
|
interface StopSessionPayload {
|
|
145
149
|
sessionId: string;
|
|
146
150
|
}
|
|
151
|
+
interface MeshWriterAssignment {
|
|
152
|
+
meshId: string;
|
|
153
|
+
nodeId: string;
|
|
154
|
+
taskId: string;
|
|
155
|
+
attemptId: string;
|
|
156
|
+
generation: number;
|
|
157
|
+
dispatchNonce: number;
|
|
158
|
+
ownerDaemonId: string;
|
|
159
|
+
}
|
|
160
|
+
interface MeshWriterStopTarget {
|
|
161
|
+
runtimeKey: string;
|
|
162
|
+
startedAt: number;
|
|
163
|
+
osPid: number;
|
|
164
|
+
providerType: string;
|
|
165
|
+
assignment: MeshWriterAssignment;
|
|
166
|
+
}
|
|
167
|
+
interface StopMeshWriterPayload extends MeshWriterStopTarget {
|
|
168
|
+
sessionId: string;
|
|
169
|
+
clientId: string;
|
|
170
|
+
}
|
|
147
171
|
interface DeleteSessionPayload {
|
|
148
172
|
sessionId: string;
|
|
149
173
|
/** Stop a live runtime before deleting the persisted record. */
|
|
@@ -267,7 +291,22 @@ interface SessionHostDiagnostics {
|
|
|
267
291
|
recentRequests: SessionHostRequestTrace[];
|
|
268
292
|
recentTransitions: SessionHostRuntimeTransition[];
|
|
269
293
|
}
|
|
294
|
+
interface HostUpgradeLeasePayload {
|
|
295
|
+
bootId: string;
|
|
296
|
+
epoch: number;
|
|
297
|
+
owner: string;
|
|
298
|
+
token: string;
|
|
299
|
+
}
|
|
270
300
|
type SessionHostRequest = {
|
|
301
|
+
type: 'get_upgrade_lease';
|
|
302
|
+
payload?: {};
|
|
303
|
+
} | {
|
|
304
|
+
type: 'acquire_upgrade_lease';
|
|
305
|
+
payload: HostUpgradeLeasePayload;
|
|
306
|
+
} | {
|
|
307
|
+
type: 'release_upgrade_lease';
|
|
308
|
+
payload: HostUpgradeLeasePayload;
|
|
309
|
+
} | {
|
|
271
310
|
type: 'create_session';
|
|
272
311
|
payload: CreateSessionPayload;
|
|
273
312
|
} | {
|
|
@@ -285,6 +324,9 @@ type SessionHostRequest = {
|
|
|
285
324
|
} | {
|
|
286
325
|
type: 'stop_session';
|
|
287
326
|
payload: StopSessionPayload;
|
|
327
|
+
} | {
|
|
328
|
+
type: 'stop_mesh_writer';
|
|
329
|
+
payload: StopMeshWriterPayload;
|
|
288
330
|
} | {
|
|
289
331
|
type: 'delete_session';
|
|
290
332
|
payload: DeleteSessionPayload;
|
|
@@ -434,6 +476,43 @@ interface ClassifyTerminationInput {
|
|
|
434
476
|
*/
|
|
435
477
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
436
478
|
|
|
479
|
+
/** Relative POSIX niceness adjustment for newly spawned agent workloads. */
|
|
480
|
+
declare const CLI_CHILD_NICE_INCREMENT = 10;
|
|
481
|
+
/** Set to "0" in the daemon environment (or launch env) to disable lowering. */
|
|
482
|
+
declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
483
|
+
/** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
|
|
484
|
+
declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
485
|
+
declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
|
|
486
|
+
interface PriorityDependencies {
|
|
487
|
+
platform: NodeJS.Platform;
|
|
488
|
+
getPriority: typeof os.getPriority;
|
|
489
|
+
setPriority: typeof os.setPriority;
|
|
490
|
+
setDarwinBackground?: typeof setDarwinBackground;
|
|
491
|
+
}
|
|
492
|
+
/** Separate policy instances are useful for platform/error tests. */
|
|
493
|
+
declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
|
|
494
|
+
readonly pid?: number;
|
|
495
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
496
|
+
/**
|
|
497
|
+
* Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
|
|
498
|
+
* workers, version probes and git helpers at their existing priority.
|
|
499
|
+
*
|
|
500
|
+
* node-pty has no pre-spawn priority hook. Apply immediately on return, before
|
|
501
|
+
* registering listeners/doing other work. There is a spawn-to-setPriority race:
|
|
502
|
+
* a child can run (and fork) before this call. Later descendants inherit nice
|
|
503
|
+
* on POSIX; early descendants are not retroactively changed. Windows creation
|
|
504
|
+
* and ConPTY inheritance require verification on the DesktopA.
|
|
505
|
+
* Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
|
|
506
|
+
* extra helper startup adds a further race before the background class takes
|
|
507
|
+
* effect. It also throttles I/O, so nice alone remains the default.
|
|
508
|
+
*/
|
|
509
|
+
declare const spawnCliChild: <T extends {
|
|
510
|
+
readonly pid?: number;
|
|
511
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
512
|
+
|
|
513
|
+
/** Shared hidden-window primitive for daemon and session-host process helpers. */
|
|
514
|
+
declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
|
|
515
|
+
|
|
437
516
|
interface SessionRingBufferOptions {
|
|
438
517
|
maxBytes?: number;
|
|
439
518
|
}
|
|
@@ -606,6 +685,9 @@ declare function createLineParser<TEnvelope = SessionHostWireEnvelope>(onEnvelop
|
|
|
606
685
|
interface SessionHostClientOptions {
|
|
607
686
|
endpoint?: SessionHostEndpoint;
|
|
608
687
|
appName?: string;
|
|
688
|
+
requestTimeoutMs?: number;
|
|
689
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
690
|
+
registerAsShared?: boolean;
|
|
609
691
|
}
|
|
610
692
|
/**
|
|
611
693
|
* Why an established session-host connection went away.
|
|
@@ -614,6 +696,8 @@ interface SessionHostClientOptions {
|
|
|
614
696
|
* - `closed` — socket fully closed ('close') without a preceding error/end
|
|
615
697
|
*/
|
|
616
698
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
699
|
+
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
700
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
617
701
|
interface SessionHostDisconnectInfo {
|
|
618
702
|
reason: SessionHostDisconnectReason;
|
|
619
703
|
endpointPath: string;
|
|
@@ -634,12 +718,19 @@ interface SessionHostDisconnectInfo {
|
|
|
634
718
|
declare class SessionHostClient {
|
|
635
719
|
readonly endpoint: SessionHostEndpoint;
|
|
636
720
|
private socket;
|
|
721
|
+
private connectPromise;
|
|
722
|
+
private requestTimeoutMs;
|
|
637
723
|
private requestWaiters;
|
|
638
724
|
private eventListeners;
|
|
639
725
|
private disconnectListeners;
|
|
640
726
|
/** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
|
|
641
727
|
private disconnectedSockets;
|
|
728
|
+
/** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
|
|
729
|
+
private attachedSessions;
|
|
642
730
|
constructor(options?: SessionHostClientOptions);
|
|
731
|
+
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
732
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
733
|
+
isConnected(): boolean;
|
|
643
734
|
/**
|
|
644
735
|
* Fires when an established connection to the session host goes away.
|
|
645
736
|
*
|
|
@@ -654,9 +745,13 @@ declare class SessionHostClient {
|
|
|
654
745
|
*/
|
|
655
746
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
656
747
|
private handleDisconnect;
|
|
657
|
-
|
|
748
|
+
private sendRawRequestOnSocket;
|
|
749
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
658
750
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
659
|
-
request<T = unknown>(request: SessionHostRequest
|
|
751
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
752
|
+
timeoutMs?: number;
|
|
753
|
+
}): Promise<SessionHostResponse<T>>;
|
|
754
|
+
disconnect(error?: Error): void;
|
|
660
755
|
close(): Promise<void>;
|
|
661
756
|
}
|
|
662
757
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
@@ -734,6 +829,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
734
829
|
* with child CLI processes and apply terminal colour defaults.
|
|
735
830
|
*/
|
|
736
831
|
declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
|
|
832
|
+
/** Recover only role bindings from legacy full-environment snapshots.
|
|
833
|
+
* New records distinguish explicit overrides, including intentional custom keys. */
|
|
834
|
+
declare function replayLaunchEnv(command: {
|
|
835
|
+
env?: Record<string, string>;
|
|
836
|
+
envMode?: 'launch_overrides';
|
|
837
|
+
}): Record<string, string>;
|
|
737
838
|
/**
|
|
738
839
|
* Apply preferred terminal colour environment variables.
|
|
739
840
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -809,4 +910,4 @@ interface SessionHostControlTransport {
|
|
|
809
910
|
*/
|
|
810
911
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
811
912
|
|
|
812
|
-
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, writeEnvelope };
|
|
913
|
+
export { type AcquireWritePayload, type AttachSessionPayload, CLI_CHILD_NICE_ENV, CLI_CHILD_NICE_INCREMENT, CLI_CHILD_SCHEDULING_ENV, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopMeshWriterPayload, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, writeEnvelope };
|