@adhdev/session-host-core 1.0.82-rc.22 → 1.0.82-rc.24
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 +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +100 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli-child-priority.ts +81 -0
- package/src/index.ts +3 -0
- package/src/process/hidden-spawn.ts +10 -0
- package/src/spawn-env.ts +11 -0
- package/src/types.ts +2 -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;
|
|
@@ -449,6 +453,43 @@ interface ClassifyTerminationInput {
|
|
|
449
453
|
*/
|
|
450
454
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
451
455
|
|
|
456
|
+
/** Relative POSIX niceness adjustment for newly spawned agent workloads. */
|
|
457
|
+
declare const CLI_CHILD_NICE_INCREMENT = 10;
|
|
458
|
+
/** Set to "0" in the daemon environment (or launch env) to disable lowering. */
|
|
459
|
+
declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
460
|
+
/** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
|
|
461
|
+
declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
462
|
+
declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
|
|
463
|
+
interface PriorityDependencies {
|
|
464
|
+
platform: NodeJS.Platform;
|
|
465
|
+
getPriority: typeof os.getPriority;
|
|
466
|
+
setPriority: typeof os.setPriority;
|
|
467
|
+
setDarwinBackground?: typeof setDarwinBackground;
|
|
468
|
+
}
|
|
469
|
+
/** Separate policy instances are useful for platform/error tests. */
|
|
470
|
+
declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
|
|
471
|
+
readonly pid?: number;
|
|
472
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
473
|
+
/**
|
|
474
|
+
* Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
|
|
475
|
+
* workers, version probes and git helpers at their existing priority.
|
|
476
|
+
*
|
|
477
|
+
* node-pty has no pre-spawn priority hook. Apply immediately on return, before
|
|
478
|
+
* registering listeners/doing other work. There is a spawn-to-setPriority race:
|
|
479
|
+
* a child can run (and fork) before this call. Later descendants inherit nice
|
|
480
|
+
* on POSIX; early descendants are not retroactively changed. Windows creation
|
|
481
|
+
* and ConPTY inheritance require verification on the MainPC.
|
|
482
|
+
* Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
|
|
483
|
+
* extra helper startup adds a further race before the background class takes
|
|
484
|
+
* effect. It also throttles I/O, so nice alone remains the default.
|
|
485
|
+
*/
|
|
486
|
+
declare const spawnCliChild: <T extends {
|
|
487
|
+
readonly pid?: number;
|
|
488
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
489
|
+
|
|
490
|
+
/** Shared hidden-window primitive for daemon and session-host process helpers. */
|
|
491
|
+
declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
|
|
492
|
+
|
|
452
493
|
interface SessionRingBufferOptions {
|
|
453
494
|
maxBytes?: number;
|
|
454
495
|
}
|
|
@@ -749,6 +790,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
749
790
|
* with child CLI processes and apply terminal colour defaults.
|
|
750
791
|
*/
|
|
751
792
|
declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
|
|
793
|
+
/** Recover only role bindings from legacy full-environment snapshots.
|
|
794
|
+
* New records distinguish explicit overrides, including intentional custom keys. */
|
|
795
|
+
declare function replayLaunchEnv(command: {
|
|
796
|
+
env?: Record<string, string>;
|
|
797
|
+
envMode?: 'launch_overrides';
|
|
798
|
+
}): Record<string, string>;
|
|
752
799
|
/**
|
|
753
800
|
* Apply preferred terminal colour environment variables.
|
|
754
801
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -824,4 +871,4 @@ interface SessionHostControlTransport {
|
|
|
824
871
|
*/
|
|
825
872
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
826
873
|
|
|
827
|
-
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 HostUpgradeLeasePayload, 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 };
|
|
874
|
+
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 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, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, 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;
|
|
@@ -449,6 +453,43 @@ interface ClassifyTerminationInput {
|
|
|
449
453
|
*/
|
|
450
454
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
451
455
|
|
|
456
|
+
/** Relative POSIX niceness adjustment for newly spawned agent workloads. */
|
|
457
|
+
declare const CLI_CHILD_NICE_INCREMENT = 10;
|
|
458
|
+
/** Set to "0" in the daemon environment (or launch env) to disable lowering. */
|
|
459
|
+
declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
460
|
+
/** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
|
|
461
|
+
declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
462
|
+
declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
|
|
463
|
+
interface PriorityDependencies {
|
|
464
|
+
platform: NodeJS.Platform;
|
|
465
|
+
getPriority: typeof os.getPriority;
|
|
466
|
+
setPriority: typeof os.setPriority;
|
|
467
|
+
setDarwinBackground?: typeof setDarwinBackground;
|
|
468
|
+
}
|
|
469
|
+
/** Separate policy instances are useful for platform/error tests. */
|
|
470
|
+
declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
|
|
471
|
+
readonly pid?: number;
|
|
472
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
473
|
+
/**
|
|
474
|
+
* Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
|
|
475
|
+
* workers, version probes and git helpers at their existing priority.
|
|
476
|
+
*
|
|
477
|
+
* node-pty has no pre-spawn priority hook. Apply immediately on return, before
|
|
478
|
+
* registering listeners/doing other work. There is a spawn-to-setPriority race:
|
|
479
|
+
* a child can run (and fork) before this call. Later descendants inherit nice
|
|
480
|
+
* on POSIX; early descendants are not retroactively changed. Windows creation
|
|
481
|
+
* and ConPTY inheritance require verification on the MainPC.
|
|
482
|
+
* Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
|
|
483
|
+
* extra helper startup adds a further race before the background class takes
|
|
484
|
+
* effect. It also throttles I/O, so nice alone remains the default.
|
|
485
|
+
*/
|
|
486
|
+
declare const spawnCliChild: <T extends {
|
|
487
|
+
readonly pid?: number;
|
|
488
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
|
|
489
|
+
|
|
490
|
+
/** Shared hidden-window primitive for daemon and session-host process helpers. */
|
|
491
|
+
declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
|
|
492
|
+
|
|
452
493
|
interface SessionRingBufferOptions {
|
|
453
494
|
maxBytes?: number;
|
|
454
495
|
}
|
|
@@ -749,6 +790,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
749
790
|
* with child CLI processes and apply terminal colour defaults.
|
|
750
791
|
*/
|
|
751
792
|
declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
|
|
793
|
+
/** Recover only role bindings from legacy full-environment snapshots.
|
|
794
|
+
* New records distinguish explicit overrides, including intentional custom keys. */
|
|
795
|
+
declare function replayLaunchEnv(command: {
|
|
796
|
+
env?: Record<string, string>;
|
|
797
|
+
envMode?: 'launch_overrides';
|
|
798
|
+
}): Record<string, string>;
|
|
752
799
|
/**
|
|
753
800
|
* Apply preferred terminal colour environment variables.
|
|
754
801
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -824,4 +871,4 @@ interface SessionHostControlTransport {
|
|
|
824
871
|
*/
|
|
825
872
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
826
873
|
|
|
827
|
-
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 HostUpgradeLeasePayload, 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 };
|
|
874
|
+
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 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, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, 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.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,6 +46,7 @@ __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,
|
|
@@ -52,12 +56,14 @@ __export(index_exports, {
|
|
|
52
56
|
getSessionHostRecoveryLabel: () => getSessionHostRecoveryLabel,
|
|
53
57
|
getSessionHostSurfaceKind: () => getSessionHostSurfaceKind,
|
|
54
58
|
getWorkspaceLabel: () => getWorkspaceLabel,
|
|
59
|
+
hiddenSpawnProcess: () => hiddenSpawn,
|
|
55
60
|
isDefaultInstanceConfigDir: () => isDefaultInstanceConfigDir,
|
|
56
61
|
isSessionHostLiveRuntime: () => isSessionHostLiveRuntime,
|
|
57
62
|
isSessionHostRecoverySnapshot: () => isSessionHostRecoverySnapshot,
|
|
58
63
|
isTerminalRecord: () => isTerminalRecord,
|
|
59
64
|
partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
|
|
60
65
|
partitionSessionHostRecords: () => partitionSessionHostRecords,
|
|
66
|
+
replayLaunchEnv: () => replayLaunchEnv,
|
|
61
67
|
resolveAttachableRuntimeRecord: () => resolveAttachableRuntimeRecord,
|
|
62
68
|
resolveInstanceConfigDir: () => resolveInstanceConfigDir,
|
|
63
69
|
resolveRuntimeRecord: () => resolveRuntimeRecord,
|
|
@@ -65,6 +71,7 @@ __export(index_exports, {
|
|
|
65
71
|
resolveSessionHostIpcKey: () => resolveSessionHostIpcKey,
|
|
66
72
|
resolveSessionHostRows: () => resolveSessionHostRows,
|
|
67
73
|
sanitizeSpawnEnv: () => sanitizeSpawnEnv,
|
|
74
|
+
spawnCliChild: () => spawnCliChild,
|
|
68
75
|
writeEnvelope: () => writeEnvelope
|
|
69
76
|
});
|
|
70
77
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -129,6 +136,62 @@ function classifyTermination(input) {
|
|
|
129
136
|
return termination;
|
|
130
137
|
}
|
|
131
138
|
|
|
139
|
+
// src/cli-child-priority.ts
|
|
140
|
+
var os = __toESM(require("os"));
|
|
141
|
+
|
|
142
|
+
// src/process/hidden-spawn.ts
|
|
143
|
+
var import_node_child_process = require("child_process");
|
|
144
|
+
function hiddenSpawn(command, args = [], options = {}) {
|
|
145
|
+
return (0, import_node_child_process.spawn)(command, args, { windowsHide: true, ...options });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/cli-child-priority.ts
|
|
149
|
+
var CLI_CHILD_NICE_INCREMENT = 10;
|
|
150
|
+
var CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
151
|
+
var CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
152
|
+
function setDarwinBackground(pid, onFailure) {
|
|
153
|
+
const task = hiddenSpawn("/usr/sbin/taskpolicy", ["-b", "-p", String(pid)], { stdio: "ignore" });
|
|
154
|
+
task.once("error", onFailure);
|
|
155
|
+
task.once("exit", (code, signal) => {
|
|
156
|
+
if (code !== 0) onFailure(new Error(`taskpolicy exited with ${signal ?? code}`));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function createCliChildPriorityPolicy(deps = {
|
|
160
|
+
platform: process.platform,
|
|
161
|
+
getPriority: os.getPriority,
|
|
162
|
+
setPriority: os.setPriority,
|
|
163
|
+
setDarwinBackground
|
|
164
|
+
}) {
|
|
165
|
+
let failureLogged = false;
|
|
166
|
+
return function spawnCliChild2(spawnChild, env = process.env, logInfo = console.info) {
|
|
167
|
+
const child = spawnChild();
|
|
168
|
+
const pid = child.pid;
|
|
169
|
+
if (env[CLI_CHILD_NICE_ENV] === "0" || typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return child;
|
|
170
|
+
const onFailure = (error) => {
|
|
171
|
+
if (!failureLogged) {
|
|
172
|
+
failureLogged = true;
|
|
173
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
174
|
+
logInfo(`[cli-child-priority] Could not apply CLI child scheduling (pid ${pid}); continuing: ${detail}`);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
const priority = deps.platform === "win32" ? os.constants.priority.PRIORITY_BELOW_NORMAL : Math.min(19, deps.getPriority(pid) + CLI_CHILD_NICE_INCREMENT);
|
|
179
|
+
deps.setPriority(pid, priority);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
onFailure(error);
|
|
182
|
+
}
|
|
183
|
+
if (deps.platform === "darwin" && env[CLI_CHILD_SCHEDULING_ENV] === "darwin-bg") {
|
|
184
|
+
try {
|
|
185
|
+
deps.setDarwinBackground?.(pid, onFailure);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
onFailure(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return child;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
var spawnCliChild = createCliChildPriorityPolicy();
|
|
194
|
+
|
|
132
195
|
// src/buffer.ts
|
|
133
196
|
var DEFAULT_SESSION_RING_BUFFER_MAX_BYTES = 4 * 1024 * 1024;
|
|
134
197
|
var SessionRingBuffer = class {
|
|
@@ -692,7 +755,7 @@ function cloneMeta(meta) {
|
|
|
692
755
|
}
|
|
693
756
|
|
|
694
757
|
// src/ipc.ts
|
|
695
|
-
var
|
|
758
|
+
var os2 = __toESM(require("os"));
|
|
696
759
|
var path2 = __toESM(require("path"));
|
|
697
760
|
var net = __toESM(require("net"));
|
|
698
761
|
var import_string_decoder = require("string_decoder");
|
|
@@ -711,7 +774,7 @@ function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
|
|
|
711
774
|
}
|
|
712
775
|
return {
|
|
713
776
|
kind: "unix",
|
|
714
|
-
path: path2.join(
|
|
777
|
+
path: path2.join(os2.tmpdir(), `${appName}-session-host${suffix}.sock`)
|
|
715
778
|
};
|
|
716
779
|
}
|
|
717
780
|
function serializeEnvelope(envelope) {
|
|
@@ -933,10 +996,10 @@ function writeEnvelope(socket, envelope) {
|
|
|
933
996
|
// src/instance-key.ts
|
|
934
997
|
var crypto2 = __toESM(require("crypto"));
|
|
935
998
|
var fs = __toESM(require("fs"));
|
|
936
|
-
var
|
|
999
|
+
var os3 = __toESM(require("os"));
|
|
937
1000
|
var path3 = __toESM(require("path"));
|
|
938
1001
|
var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
939
|
-
function resolveInstanceConfigDir(env = process.env, homeDir =
|
|
1002
|
+
function resolveInstanceConfigDir(env = process.env, homeDir = os3.homedir()) {
|
|
940
1003
|
const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
|
|
941
1004
|
return override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
|
|
942
1005
|
}
|
|
@@ -961,17 +1024,17 @@ function canonicalizeInstancePath(dir, platform2 = process.platform) {
|
|
|
961
1024
|
const real = realpathLongestExistingPrefix(resolved).replace(/[\\/]+$/, "");
|
|
962
1025
|
return platform2 === "win32" ? real.toLowerCase() : real;
|
|
963
1026
|
}
|
|
964
|
-
function isDefaultInstanceConfigDir(configDir, homeDir =
|
|
1027
|
+
function isDefaultInstanceConfigDir(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
|
|
965
1028
|
return canonicalizeInstancePath(configDir, platform2) === canonicalizeInstancePath(path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME), platform2);
|
|
966
1029
|
}
|
|
967
|
-
function resolveSessionHostIpcKey(configDir, homeDir =
|
|
1030
|
+
function resolveSessionHostIpcKey(configDir, homeDir = os3.homedir(), platform2 = process.platform) {
|
|
968
1031
|
if (isDefaultInstanceConfigDir(configDir, homeDir, platform2)) return "";
|
|
969
1032
|
const canonical = canonicalizeInstancePath(configDir, platform2);
|
|
970
1033
|
return crypto2.createHash("sha256").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
971
1034
|
}
|
|
972
1035
|
|
|
973
1036
|
// src/spawn-env.ts
|
|
974
|
-
var
|
|
1037
|
+
var os4 = __toESM(require("os"));
|
|
975
1038
|
var path4 = __toESM(require("path"));
|
|
976
1039
|
function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
977
1040
|
const env = {};
|
|
@@ -1001,6 +1064,27 @@ function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
|
1001
1064
|
applyTerminalColorEnv(env);
|
|
1002
1065
|
return env;
|
|
1003
1066
|
}
|
|
1067
|
+
function replayLaunchEnv(command) {
|
|
1068
|
+
if (command.envMode === "launch_overrides") return { ...command.env };
|
|
1069
|
+
const roleKeys = /* @__PURE__ */ new Set([
|
|
1070
|
+
"HOME",
|
|
1071
|
+
"USERPROFILE",
|
|
1072
|
+
"XDG_CONFIG_HOME",
|
|
1073
|
+
"CLAUDE_CONFIG_DIR",
|
|
1074
|
+
"CODEX_HOME",
|
|
1075
|
+
"KIMI_CODE_HOME",
|
|
1076
|
+
"GEMINI_CLI_HOME",
|
|
1077
|
+
"OPENCODE_CONFIG",
|
|
1078
|
+
"OPENCODE_CONFIG_CONTENT",
|
|
1079
|
+
"CLAUDE_CODE_DISABLE_AUTO_MEMORY",
|
|
1080
|
+
"TERMINAL_CWD",
|
|
1081
|
+
"ADHDEV_INLINE_MESH",
|
|
1082
|
+
"ADHDEV_ASSISTANT_SESSION_ID",
|
|
1083
|
+
"ADHDEV_COORDINATOR_SESSION_ID",
|
|
1084
|
+
"ADHDEV_CONFIG_DIR"
|
|
1085
|
+
]);
|
|
1086
|
+
return Object.fromEntries(Object.entries(command.env ?? {}).filter(([key]) => roleKeys.has(key)));
|
|
1087
|
+
}
|
|
1004
1088
|
function applyTerminalColorEnv(env) {
|
|
1005
1089
|
if (env.NO_COLOR) return;
|
|
1006
1090
|
if (!env.TERM || env.TERM === "xterm-color") {
|
|
@@ -1013,11 +1097,11 @@ function applyTerminalColorEnv(env) {
|
|
|
1013
1097
|
}
|
|
1014
1098
|
}
|
|
1015
1099
|
function ensureNodePtySpawnHelperPermissions(logFn) {
|
|
1016
|
-
if (
|
|
1100
|
+
if (os4.platform() === "win32") return;
|
|
1017
1101
|
try {
|
|
1018
1102
|
const fs2 = require("fs");
|
|
1019
1103
|
const ptyDir = path4.resolve(path4.dirname(require.resolve("node-pty")), "..");
|
|
1020
|
-
const platformArch = `${
|
|
1104
|
+
const platformArch = `${os4.platform()}-${os4.arch()}`;
|
|
1021
1105
|
const helper = path4.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
1022
1106
|
if (fs2.existsSync(helper)) {
|
|
1023
1107
|
const stat = fs2.statSync(helper);
|
|
@@ -1073,6 +1157,9 @@ function createSessionHostControlPlane(transport) {
|
|
|
1073
1157
|
}
|
|
1074
1158
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1075
1159
|
0 && (module.exports = {
|
|
1160
|
+
CLI_CHILD_NICE_ENV,
|
|
1161
|
+
CLI_CHILD_NICE_INCREMENT,
|
|
1162
|
+
CLI_CHILD_SCHEDULING_ENV,
|
|
1076
1163
|
DEFAULT_CONFIG_DIR_NAME,
|
|
1077
1164
|
DEFAULT_SESSION_HOST_COLS,
|
|
1078
1165
|
DEFAULT_SESSION_HOST_ROWS,
|
|
@@ -1086,6 +1173,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
1086
1173
|
buildRuntimeKey,
|
|
1087
1174
|
canonicalizeInstancePath,
|
|
1088
1175
|
classifyTermination,
|
|
1176
|
+
createCliChildPriorityPolicy,
|
|
1089
1177
|
createLineParser,
|
|
1090
1178
|
createResponseEnvelope,
|
|
1091
1179
|
createSessionHostControlPlane,
|
|
@@ -1095,12 +1183,14 @@ function createSessionHostControlPlane(transport) {
|
|
|
1095
1183
|
getSessionHostRecoveryLabel,
|
|
1096
1184
|
getSessionHostSurfaceKind,
|
|
1097
1185
|
getWorkspaceLabel,
|
|
1186
|
+
hiddenSpawnProcess,
|
|
1098
1187
|
isDefaultInstanceConfigDir,
|
|
1099
1188
|
isSessionHostLiveRuntime,
|
|
1100
1189
|
isSessionHostRecoverySnapshot,
|
|
1101
1190
|
isTerminalRecord,
|
|
1102
1191
|
partitionSessionHostDiagnosticsSessions,
|
|
1103
1192
|
partitionSessionHostRecords,
|
|
1193
|
+
replayLaunchEnv,
|
|
1104
1194
|
resolveAttachableRuntimeRecord,
|
|
1105
1195
|
resolveInstanceConfigDir,
|
|
1106
1196
|
resolveRuntimeRecord,
|
|
@@ -1108,6 +1198,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
1108
1198
|
resolveSessionHostIpcKey,
|
|
1109
1199
|
resolveSessionHostRows,
|
|
1110
1200
|
sanitizeSpawnEnv,
|
|
1201
|
+
spawnCliChild,
|
|
1111
1202
|
writeEnvelope
|
|
1112
1203
|
});
|
|
1113
1204
|
//# sourceMappingURL=index.js.map
|