@adhdev/session-host-core 1.0.28-rc.17 → 1.0.28-rc.19
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 +59 -2
- package/dist/index.d.ts +59 -2
- package/dist/index.js +75 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -1
- package/src/instance-key.ts +108 -0
- package/src/ipc.ts +26 -4
package/dist/index.d.mts
CHANGED
|
@@ -495,7 +495,17 @@ interface SessionHostEndpoint {
|
|
|
495
495
|
kind: 'unix' | 'pipe';
|
|
496
496
|
path: string;
|
|
497
497
|
}
|
|
498
|
-
|
|
498
|
+
interface SessionHostEndpointOptions {
|
|
499
|
+
/**
|
|
500
|
+
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
501
|
+
* legacy default-instance endpoint; a non-empty key suffixes the endpoint so
|
|
502
|
+
* each config-dir instance gets its own socket/pipe.
|
|
503
|
+
*/
|
|
504
|
+
ipcKey?: string;
|
|
505
|
+
/** Test seam: override the platform the endpoint shape is derived for. */
|
|
506
|
+
platform?: NodeJS.Platform;
|
|
507
|
+
}
|
|
508
|
+
declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
|
|
499
509
|
declare function createLineParser(onEnvelope: (envelope: SessionHostWireEnvelope) => void): (chunk: Buffer | string) => void;
|
|
500
510
|
interface SessionHostClientOptions {
|
|
501
511
|
endpoint?: SessionHostEndpoint;
|
|
@@ -515,6 +525,53 @@ declare class SessionHostClient {
|
|
|
515
525
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
516
526
|
declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: SessionHostWireEnvelope): void;
|
|
517
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Instance identity derivation for the session-host IPC namespace.
|
|
530
|
+
*
|
|
531
|
+
* One machine can host several ADHDev installs (stable `~/.adhdev`, preview
|
|
532
|
+
* `~/.adhdev-preview`, standalone `~/.adhdev-standalone`, or any explicit
|
|
533
|
+
* ADHDEV_CONFIG_DIR). Each install is an *instance*: it owns its config dir
|
|
534
|
+
* and everything mutable under it. The session-host socket/pipe must be
|
|
535
|
+
* namespaced by that identity so two simultaneous instances can never attach
|
|
536
|
+
* to, kill, or rebind each other's session host.
|
|
537
|
+
*
|
|
538
|
+
* This module is the single derivation rule, shared by:
|
|
539
|
+
* - the parent daemons (via @adhdev/daemon-core's InstanceContext),
|
|
540
|
+
* - the session-host-daemon child process (which only sees env vars),
|
|
541
|
+
* - CLI attach/list clients.
|
|
542
|
+
*
|
|
543
|
+
* All three compute the endpoint from the same inputs (appName +
|
|
544
|
+
* ADHDEV_CONFIG_DIR), so they always agree without extra plumbing.
|
|
545
|
+
*
|
|
546
|
+
* Compatibility contract: the DEFAULT instance (config dir canonicalizes to
|
|
547
|
+
* `<home>/.adhdev`) yields an EMPTY ipc key, so its socket/pipe path stays
|
|
548
|
+
* byte-for-byte identical to the pre-instance layout.
|
|
549
|
+
*/
|
|
550
|
+
declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
551
|
+
/**
|
|
552
|
+
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
553
|
+
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
554
|
+
* getConfigDir() source rule without the mkdir side effect.
|
|
555
|
+
*/
|
|
556
|
+
declare function resolveInstanceConfigDir(env?: NodeJS.ProcessEnv, homeDir?: string): string;
|
|
557
|
+
/**
|
|
558
|
+
* Canonical form of an instance path for identity comparison/hashing:
|
|
559
|
+
* absolute, symlink-resolved (longest existing prefix), no trailing
|
|
560
|
+
* separator, case-folded on win32.
|
|
561
|
+
*/
|
|
562
|
+
declare function canonicalizeInstancePath(dir: string, platform?: NodeJS.Platform): string;
|
|
563
|
+
/** True when `configDir` is canonically the default `<homeDir>/.adhdev`. */
|
|
564
|
+
declare function isDefaultInstanceConfigDir(configDir: string, homeDir?: string, platform?: NodeJS.Platform): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Derive the session-host IPC namespace key for an instance config dir.
|
|
567
|
+
*
|
|
568
|
+
* '' for the default instance (legacy-compatible endpoint), otherwise a
|
|
569
|
+
* 12-hex-char sha256 prefix of the canonical config dir — stable across
|
|
570
|
+
* processes/machines for the same dir, collision-resistant between dirs,
|
|
571
|
+
* and insensitive to symlink/spelling differences of the same dir.
|
|
572
|
+
*/
|
|
573
|
+
declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, platform?: NodeJS.Platform): string;
|
|
574
|
+
|
|
518
575
|
/**
|
|
519
576
|
* Shared PTY spawn environment utilities.
|
|
520
577
|
*
|
|
@@ -588,4 +645,4 @@ interface SessionHostControlTransport {
|
|
|
588
645
|
*/
|
|
589
646
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
590
647
|
|
|
591
|
-
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, 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 SessionHostDuplicateSessionGroup, type SessionHostEndpoint, 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 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, classifyTermination, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveRuntimeRecord, sanitizeSpawnEnv, writeEnvelope };
|
|
648
|
+
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 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 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, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, writeEnvelope };
|
package/dist/index.d.ts
CHANGED
|
@@ -495,7 +495,17 @@ interface SessionHostEndpoint {
|
|
|
495
495
|
kind: 'unix' | 'pipe';
|
|
496
496
|
path: string;
|
|
497
497
|
}
|
|
498
|
-
|
|
498
|
+
interface SessionHostEndpointOptions {
|
|
499
|
+
/**
|
|
500
|
+
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
501
|
+
* legacy default-instance endpoint; a non-empty key suffixes the endpoint so
|
|
502
|
+
* each config-dir instance gets its own socket/pipe.
|
|
503
|
+
*/
|
|
504
|
+
ipcKey?: string;
|
|
505
|
+
/** Test seam: override the platform the endpoint shape is derived for. */
|
|
506
|
+
platform?: NodeJS.Platform;
|
|
507
|
+
}
|
|
508
|
+
declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
|
|
499
509
|
declare function createLineParser(onEnvelope: (envelope: SessionHostWireEnvelope) => void): (chunk: Buffer | string) => void;
|
|
500
510
|
interface SessionHostClientOptions {
|
|
501
511
|
endpoint?: SessionHostEndpoint;
|
|
@@ -515,6 +525,53 @@ declare class SessionHostClient {
|
|
|
515
525
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
516
526
|
declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: SessionHostWireEnvelope): void;
|
|
517
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Instance identity derivation for the session-host IPC namespace.
|
|
530
|
+
*
|
|
531
|
+
* One machine can host several ADHDev installs (stable `~/.adhdev`, preview
|
|
532
|
+
* `~/.adhdev-preview`, standalone `~/.adhdev-standalone`, or any explicit
|
|
533
|
+
* ADHDEV_CONFIG_DIR). Each install is an *instance*: it owns its config dir
|
|
534
|
+
* and everything mutable under it. The session-host socket/pipe must be
|
|
535
|
+
* namespaced by that identity so two simultaneous instances can never attach
|
|
536
|
+
* to, kill, or rebind each other's session host.
|
|
537
|
+
*
|
|
538
|
+
* This module is the single derivation rule, shared by:
|
|
539
|
+
* - the parent daemons (via @adhdev/daemon-core's InstanceContext),
|
|
540
|
+
* - the session-host-daemon child process (which only sees env vars),
|
|
541
|
+
* - CLI attach/list clients.
|
|
542
|
+
*
|
|
543
|
+
* All three compute the endpoint from the same inputs (appName +
|
|
544
|
+
* ADHDEV_CONFIG_DIR), so they always agree without extra plumbing.
|
|
545
|
+
*
|
|
546
|
+
* Compatibility contract: the DEFAULT instance (config dir canonicalizes to
|
|
547
|
+
* `<home>/.adhdev`) yields an EMPTY ipc key, so its socket/pipe path stays
|
|
548
|
+
* byte-for-byte identical to the pre-instance layout.
|
|
549
|
+
*/
|
|
550
|
+
declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
551
|
+
/**
|
|
552
|
+
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
553
|
+
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
554
|
+
* getConfigDir() source rule without the mkdir side effect.
|
|
555
|
+
*/
|
|
556
|
+
declare function resolveInstanceConfigDir(env?: NodeJS.ProcessEnv, homeDir?: string): string;
|
|
557
|
+
/**
|
|
558
|
+
* Canonical form of an instance path for identity comparison/hashing:
|
|
559
|
+
* absolute, symlink-resolved (longest existing prefix), no trailing
|
|
560
|
+
* separator, case-folded on win32.
|
|
561
|
+
*/
|
|
562
|
+
declare function canonicalizeInstancePath(dir: string, platform?: NodeJS.Platform): string;
|
|
563
|
+
/** True when `configDir` is canonically the default `<homeDir>/.adhdev`. */
|
|
564
|
+
declare function isDefaultInstanceConfigDir(configDir: string, homeDir?: string, platform?: NodeJS.Platform): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Derive the session-host IPC namespace key for an instance config dir.
|
|
567
|
+
*
|
|
568
|
+
* '' for the default instance (legacy-compatible endpoint), otherwise a
|
|
569
|
+
* 12-hex-char sha256 prefix of the canonical config dir — stable across
|
|
570
|
+
* processes/machines for the same dir, collision-resistant between dirs,
|
|
571
|
+
* and insensitive to symlink/spelling differences of the same dir.
|
|
572
|
+
*/
|
|
573
|
+
declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, platform?: NodeJS.Platform): string;
|
|
574
|
+
|
|
518
575
|
/**
|
|
519
576
|
* Shared PTY spawn environment utilities.
|
|
520
577
|
*
|
|
@@ -588,4 +645,4 @@ interface SessionHostControlTransport {
|
|
|
588
645
|
*/
|
|
589
646
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
590
647
|
|
|
591
|
-
export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, 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 SessionHostDuplicateSessionGroup, type SessionHostEndpoint, 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 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, classifyTermination, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveRuntimeRecord, sanitizeSpawnEnv, writeEnvelope };
|
|
648
|
+
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 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 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, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, writeEnvelope };
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
DEFAULT_CONFIG_DIR_NAME: () => DEFAULT_CONFIG_DIR_NAME,
|
|
33
34
|
DEFAULT_SESSION_HOST_COLS: () => DEFAULT_SESSION_HOST_COLS,
|
|
34
35
|
DEFAULT_SESSION_HOST_ROWS: () => DEFAULT_SESSION_HOST_ROWS,
|
|
35
36
|
DEFAULT_SESSION_RING_BUFFER_MAX_BYTES: () => DEFAULT_SESSION_RING_BUFFER_MAX_BYTES,
|
|
@@ -40,6 +41,7 @@ __export(index_exports, {
|
|
|
40
41
|
applyTerminalColorEnv: () => applyTerminalColorEnv,
|
|
41
42
|
buildRuntimeDisplayName: () => buildRuntimeDisplayName,
|
|
42
43
|
buildRuntimeKey: () => buildRuntimeKey,
|
|
44
|
+
canonicalizeInstancePath: () => canonicalizeInstancePath,
|
|
43
45
|
classifyTermination: () => classifyTermination,
|
|
44
46
|
createLineParser: () => createLineParser,
|
|
45
47
|
createResponseEnvelope: () => createResponseEnvelope,
|
|
@@ -50,13 +52,16 @@ __export(index_exports, {
|
|
|
50
52
|
getSessionHostRecoveryLabel: () => getSessionHostRecoveryLabel,
|
|
51
53
|
getSessionHostSurfaceKind: () => getSessionHostSurfaceKind,
|
|
52
54
|
getWorkspaceLabel: () => getWorkspaceLabel,
|
|
55
|
+
isDefaultInstanceConfigDir: () => isDefaultInstanceConfigDir,
|
|
53
56
|
isSessionHostLiveRuntime: () => isSessionHostLiveRuntime,
|
|
54
57
|
isSessionHostRecoverySnapshot: () => isSessionHostRecoverySnapshot,
|
|
55
58
|
partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
|
|
56
59
|
partitionSessionHostRecords: () => partitionSessionHostRecords,
|
|
57
60
|
resolveAttachableRuntimeRecord: () => resolveAttachableRuntimeRecord,
|
|
61
|
+
resolveInstanceConfigDir: () => resolveInstanceConfigDir,
|
|
58
62
|
resolveRuntimeRecord: () => resolveRuntimeRecord,
|
|
59
63
|
resolveSessionHostCols: () => resolveSessionHostCols,
|
|
64
|
+
resolveSessionHostIpcKey: () => resolveSessionHostIpcKey,
|
|
60
65
|
resolveSessionHostRows: () => resolveSessionHostRows,
|
|
61
66
|
sanitizeSpawnEnv: () => sanitizeSpawnEnv,
|
|
62
67
|
writeEnvelope: () => writeEnvelope
|
|
@@ -577,16 +582,22 @@ function generateUUID2() {
|
|
|
577
582
|
return v.toString(16);
|
|
578
583
|
});
|
|
579
584
|
}
|
|
580
|
-
function getDefaultSessionHostEndpoint(appName = "adhdev") {
|
|
581
|
-
|
|
585
|
+
function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
|
|
586
|
+
const rawKey = typeof options.ipcKey === "string" ? options.ipcKey.trim() : "";
|
|
587
|
+
if (rawKey && !/^[0-9a-f]{12}$/.test(rawKey)) {
|
|
588
|
+
throw new Error(`Invalid session-host ipcKey "${rawKey}" \u2014 expected '' or a 12-hex-char instance key`);
|
|
589
|
+
}
|
|
590
|
+
const suffix = rawKey ? `-${rawKey}` : "";
|
|
591
|
+
const platform2 = options.platform || process.platform;
|
|
592
|
+
if (platform2 === "win32") {
|
|
582
593
|
return {
|
|
583
594
|
kind: "pipe",
|
|
584
|
-
path: `\\\\.\\pipe\\${appName}-session-host`
|
|
595
|
+
path: `\\\\.\\pipe\\${appName}-session-host${suffix}`
|
|
585
596
|
};
|
|
586
597
|
}
|
|
587
598
|
return {
|
|
588
599
|
kind: "unix",
|
|
589
|
-
path: path2.join(os.tmpdir(), `${appName}-session-host.sock`)
|
|
600
|
+
path: path2.join(os.tmpdir(), `${appName}-session-host${suffix}.sock`)
|
|
590
601
|
};
|
|
591
602
|
}
|
|
592
603
|
function serializeEnvelope(envelope) {
|
|
@@ -653,8 +664,8 @@ var SessionHostClient = class {
|
|
|
653
664
|
} catch {
|
|
654
665
|
}
|
|
655
666
|
});
|
|
656
|
-
await new Promise((
|
|
657
|
-
socket.once("connect", () =>
|
|
667
|
+
await new Promise((resolve3, reject) => {
|
|
668
|
+
socket.once("connect", () => resolve3());
|
|
658
669
|
socket.once("error", reject);
|
|
659
670
|
});
|
|
660
671
|
}
|
|
@@ -673,7 +684,7 @@ var SessionHostClient = class {
|
|
|
673
684
|
requestId,
|
|
674
685
|
request
|
|
675
686
|
};
|
|
676
|
-
const response = await new Promise((
|
|
687
|
+
const response = await new Promise((resolve3, reject) => {
|
|
677
688
|
const timeout = setTimeout(() => {
|
|
678
689
|
this.requestWaiters.delete(requestId);
|
|
679
690
|
reject(new Error(`Session host request timed out after 30s (${request.type})`));
|
|
@@ -681,7 +692,7 @@ var SessionHostClient = class {
|
|
|
681
692
|
this.requestWaiters.set(requestId, {
|
|
682
693
|
resolve: (value) => {
|
|
683
694
|
clearTimeout(timeout);
|
|
684
|
-
|
|
695
|
+
resolve3(value);
|
|
685
696
|
},
|
|
686
697
|
reject: (error) => {
|
|
687
698
|
clearTimeout(timeout);
|
|
@@ -700,12 +711,12 @@ var SessionHostClient = class {
|
|
|
700
711
|
waiter.reject(new Error("Session host client closed"));
|
|
701
712
|
}
|
|
702
713
|
this.requestWaiters.clear();
|
|
703
|
-
await new Promise((
|
|
714
|
+
await new Promise((resolve3) => {
|
|
704
715
|
let settled = false;
|
|
705
716
|
const done = () => {
|
|
706
717
|
if (settled) return;
|
|
707
718
|
settled = true;
|
|
708
|
-
|
|
719
|
+
resolve3();
|
|
709
720
|
};
|
|
710
721
|
socket.once("close", done);
|
|
711
722
|
socket.end();
|
|
@@ -725,9 +736,49 @@ function writeEnvelope(socket, envelope) {
|
|
|
725
736
|
socket.write(serializeEnvelope(envelope));
|
|
726
737
|
}
|
|
727
738
|
|
|
728
|
-
// src/
|
|
739
|
+
// src/instance-key.ts
|
|
740
|
+
var crypto2 = __toESM(require("crypto"));
|
|
741
|
+
var fs = __toESM(require("fs"));
|
|
729
742
|
var os2 = __toESM(require("os"));
|
|
730
743
|
var path3 = __toESM(require("path"));
|
|
744
|
+
var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
745
|
+
function resolveInstanceConfigDir(env = process.env, homeDir = os2.homedir()) {
|
|
746
|
+
const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
|
|
747
|
+
return override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
|
|
748
|
+
}
|
|
749
|
+
function realpathLongestExistingPrefix(resolved) {
|
|
750
|
+
let current = resolved;
|
|
751
|
+
const remainder = [];
|
|
752
|
+
for (let depth = 0; depth < 256; depth++) {
|
|
753
|
+
try {
|
|
754
|
+
const real = fs.realpathSync.native(current);
|
|
755
|
+
return remainder.length === 0 ? real : path3.join(real, ...remainder);
|
|
756
|
+
} catch {
|
|
757
|
+
const parent = path3.dirname(current);
|
|
758
|
+
if (parent === current) return resolved;
|
|
759
|
+
remainder.unshift(path3.basename(current));
|
|
760
|
+
current = parent;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return resolved;
|
|
764
|
+
}
|
|
765
|
+
function canonicalizeInstancePath(dir, platform2 = process.platform) {
|
|
766
|
+
const resolved = path3.resolve(dir);
|
|
767
|
+
const real = realpathLongestExistingPrefix(resolved).replace(/[\\/]+$/, "");
|
|
768
|
+
return platform2 === "win32" ? real.toLowerCase() : real;
|
|
769
|
+
}
|
|
770
|
+
function isDefaultInstanceConfigDir(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
|
|
771
|
+
return canonicalizeInstancePath(configDir, platform2) === canonicalizeInstancePath(path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME), platform2);
|
|
772
|
+
}
|
|
773
|
+
function resolveSessionHostIpcKey(configDir, homeDir = os2.homedir(), platform2 = process.platform) {
|
|
774
|
+
if (isDefaultInstanceConfigDir(configDir, homeDir, platform2)) return "";
|
|
775
|
+
const canonical = canonicalizeInstancePath(configDir, platform2);
|
|
776
|
+
return crypto2.createHash("sha256").update(canonical, "utf8").digest("hex").slice(0, 12);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// src/spawn-env.ts
|
|
780
|
+
var os3 = __toESM(require("os"));
|
|
781
|
+
var path4 = __toESM(require("path"));
|
|
731
782
|
function sanitizeSpawnEnv(baseEnv, overrides) {
|
|
732
783
|
const env = {};
|
|
733
784
|
const source = { ...baseEnv, ...overrides || {} };
|
|
@@ -767,16 +818,16 @@ function applyTerminalColorEnv(env) {
|
|
|
767
818
|
}
|
|
768
819
|
}
|
|
769
820
|
function ensureNodePtySpawnHelperPermissions(logFn) {
|
|
770
|
-
if (
|
|
821
|
+
if (os3.platform() === "win32") return;
|
|
771
822
|
try {
|
|
772
|
-
const
|
|
773
|
-
const ptyDir =
|
|
774
|
-
const platformArch = `${
|
|
775
|
-
const helper =
|
|
776
|
-
if (
|
|
777
|
-
const stat =
|
|
823
|
+
const fs2 = require("fs");
|
|
824
|
+
const ptyDir = path4.resolve(path4.dirname(require.resolve("node-pty")), "..");
|
|
825
|
+
const platformArch = `${os3.platform()}-${os3.arch()}`;
|
|
826
|
+
const helper = path4.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
|
|
827
|
+
if (fs2.existsSync(helper)) {
|
|
828
|
+
const stat = fs2.statSync(helper);
|
|
778
829
|
if (!(stat.mode & 73)) {
|
|
779
|
-
|
|
830
|
+
fs2.chmodSync(helper, stat.mode | 493);
|
|
780
831
|
logFn?.(`Fixed spawn-helper permissions: ${helper}`);
|
|
781
832
|
}
|
|
782
833
|
}
|
|
@@ -824,6 +875,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
824
875
|
}
|
|
825
876
|
// Annotate the CommonJS export names for ESM import in node:
|
|
826
877
|
0 && (module.exports = {
|
|
878
|
+
DEFAULT_CONFIG_DIR_NAME,
|
|
827
879
|
DEFAULT_SESSION_HOST_COLS,
|
|
828
880
|
DEFAULT_SESSION_HOST_ROWS,
|
|
829
881
|
DEFAULT_SESSION_RING_BUFFER_MAX_BYTES,
|
|
@@ -834,6 +886,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
834
886
|
applyTerminalColorEnv,
|
|
835
887
|
buildRuntimeDisplayName,
|
|
836
888
|
buildRuntimeKey,
|
|
889
|
+
canonicalizeInstancePath,
|
|
837
890
|
classifyTermination,
|
|
838
891
|
createLineParser,
|
|
839
892
|
createResponseEnvelope,
|
|
@@ -844,13 +897,16 @@ function createSessionHostControlPlane(transport) {
|
|
|
844
897
|
getSessionHostRecoveryLabel,
|
|
845
898
|
getSessionHostSurfaceKind,
|
|
846
899
|
getWorkspaceLabel,
|
|
900
|
+
isDefaultInstanceConfigDir,
|
|
847
901
|
isSessionHostLiveRuntime,
|
|
848
902
|
isSessionHostRecoverySnapshot,
|
|
849
903
|
partitionSessionHostDiagnosticsSessions,
|
|
850
904
|
partitionSessionHostRecords,
|
|
851
905
|
resolveAttachableRuntimeRecord,
|
|
906
|
+
resolveInstanceConfigDir,
|
|
852
907
|
resolveRuntimeRecord,
|
|
853
908
|
resolveSessionHostCols,
|
|
909
|
+
resolveSessionHostIpcKey,
|
|
854
910
|
resolveSessionHostRows,
|
|
855
911
|
sanitizeSpawnEnv,
|
|
856
912
|
writeEnvelope
|