@adhdev/session-host-core 1.0.82-rc.31 → 1.0.82-rc.32
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 +72 -2
- package/dist/index.d.ts +72 -2
- package/dist/index.js +87 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/instance-key.ts +20 -1
- package/src/ipc.ts +32 -13
- package/src/registry.ts +46 -0
- package/src/types.ts +47 -1
package/dist/index.d.mts
CHANGED
|
@@ -110,6 +110,21 @@ interface SessionHostRecord {
|
|
|
110
110
|
meta: Record<string, unknown>;
|
|
111
111
|
/** Termination tombstone, stamped when the PTY process exits. Retained for post-mortem inspection. */
|
|
112
112
|
termination?: SessionTermination;
|
|
113
|
+
/**
|
|
114
|
+
* Monotonic count of input accepted into this runtime by `send_input`, from
|
|
115
|
+
* any client (SUBMIT-UNCONFIRMED-RECLAIM: the authoritative input boundary).
|
|
116
|
+
* Every accepted input is also announced as a `session_input` event carrying
|
|
117
|
+
* this number and the writer. Absent on records from a host that predates it
|
|
118
|
+
* — a reader must then treat input provenance as unknown.
|
|
119
|
+
*/
|
|
120
|
+
inputSeq?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Identifies one lifetime of `inputSeq`. It changes whenever the counter
|
|
123
|
+
* could have restarted or been rewound — a new host process loading the
|
|
124
|
+
* record, or a restore with a lower count — so equal (epoch, seq) pairs
|
|
125
|
+
* really are the same point in the input stream.
|
|
126
|
+
*/
|
|
127
|
+
inputEpoch?: string;
|
|
113
128
|
}
|
|
114
129
|
interface CreateSessionPayload {
|
|
115
130
|
sessionId?: string;
|
|
@@ -140,6 +155,20 @@ interface SendInputPayload {
|
|
|
140
155
|
clientId: string;
|
|
141
156
|
data: string;
|
|
142
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* `send_input_if_seq`: write `data` only if NOTHING else has been input since
|
|
160
|
+
* the caller last accounted the stream — the host's (inputEpoch, inputSeq) is
|
|
161
|
+
* still exactly (expectedInputEpoch, expectedInputSeq) — and the caller may
|
|
162
|
+
* write without taking ownership (no force). Atomic on the host, so no input
|
|
163
|
+
* can slip between the caller's check and this write.
|
|
164
|
+
*/
|
|
165
|
+
interface SendInputIfSeqPayload extends SendInputPayload {
|
|
166
|
+
expectedInputSeq: number;
|
|
167
|
+
expectedInputEpoch: string;
|
|
168
|
+
}
|
|
169
|
+
interface GetInputStatePayload {
|
|
170
|
+
sessionId: string;
|
|
171
|
+
}
|
|
143
172
|
interface ResizeSessionPayload {
|
|
144
173
|
sessionId: string;
|
|
145
174
|
cols: number;
|
|
@@ -318,6 +347,12 @@ type SessionHostRequest = {
|
|
|
318
347
|
} | {
|
|
319
348
|
type: 'send_input';
|
|
320
349
|
payload: SendInputPayload;
|
|
350
|
+
} | {
|
|
351
|
+
type: 'send_input_if_seq';
|
|
352
|
+
payload: SendInputIfSeqPayload;
|
|
353
|
+
} | {
|
|
354
|
+
type: 'get_input_state';
|
|
355
|
+
payload: GetInputStatePayload;
|
|
321
356
|
} | {
|
|
322
357
|
type: 'resize_session';
|
|
323
358
|
payload: ResizeSessionPayload;
|
|
@@ -366,9 +401,16 @@ type SessionHostRequest = {
|
|
|
366
401
|
} | {
|
|
367
402
|
type: 'prune_duplicate_sessions';
|
|
368
403
|
payload?: PruneDuplicateSessionsPayload;
|
|
404
|
+
} | {
|
|
405
|
+
type: 'get_session';
|
|
406
|
+
payload: {
|
|
407
|
+
sessionId: string;
|
|
408
|
+
};
|
|
369
409
|
} | {
|
|
370
410
|
type: 'list_sessions';
|
|
371
|
-
payload?: {
|
|
411
|
+
payload?: {
|
|
412
|
+
activeOnly?: boolean;
|
|
413
|
+
};
|
|
372
414
|
};
|
|
373
415
|
type SessionHostRequestType = SessionHostRequest['type'];
|
|
374
416
|
declare const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[];
|
|
@@ -394,6 +436,14 @@ type SessionHostEvent = {
|
|
|
394
436
|
sessionId: string;
|
|
395
437
|
seq: number;
|
|
396
438
|
data: string;
|
|
439
|
+
}
|
|
440
|
+
/** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
|
|
441
|
+
| {
|
|
442
|
+
type: 'session_input';
|
|
443
|
+
sessionId: string;
|
|
444
|
+
seq: number;
|
|
445
|
+
epoch: string;
|
|
446
|
+
clientId: string;
|
|
397
447
|
} | {
|
|
398
448
|
type: 'session_cleared';
|
|
399
449
|
sessionId: string;
|
|
@@ -580,15 +630,29 @@ declare class SessionRingBuffer {
|
|
|
580
630
|
|
|
581
631
|
declare class SessionHostRegistry {
|
|
582
632
|
private sessions;
|
|
633
|
+
/** This registry's lifetime; every inputEpoch it mints starts with it. */
|
|
634
|
+
private readonly lifetimeId;
|
|
635
|
+
private epochCounter;
|
|
636
|
+
private mintInputEpoch;
|
|
583
637
|
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
584
638
|
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
585
639
|
seq: number;
|
|
586
640
|
text: string;
|
|
587
641
|
} | null): SessionHostRecord;
|
|
642
|
+
/** Census projection: omit launch arguments/environment and summarize stopped
|
|
643
|
+
* sessions. Full details remain available through getSession. */
|
|
644
|
+
listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
|
|
588
645
|
listSessions(): SessionHostRecord[];
|
|
589
646
|
getSession(sessionId: string): SessionHostRecord | null;
|
|
590
647
|
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
591
648
|
detachClient(payload: DetachSessionPayload): SessionHostRecord;
|
|
649
|
+
/** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
|
|
650
|
+
recordInput(sessionId: string): number;
|
|
651
|
+
/** The current input counter (see SessionHostInputState). */
|
|
652
|
+
getInputState(sessionId: string): {
|
|
653
|
+
inputSeq: number;
|
|
654
|
+
inputEpoch: string;
|
|
655
|
+
};
|
|
592
656
|
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
593
657
|
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
594
658
|
appendOutput(sessionId: string, data: string): {
|
|
@@ -642,6 +706,8 @@ interface SessionHostEndpoint {
|
|
|
642
706
|
kind: 'unix' | 'pipe';
|
|
643
707
|
path: string;
|
|
644
708
|
}
|
|
709
|
+
/** Reserve the trailing NUL in sockaddr_un; named pipes have a separate namespace. */
|
|
710
|
+
declare function validateSessionHostEndpoint(endpoint: SessionHostEndpoint, platform?: NodeJS.Platform): void;
|
|
645
711
|
interface SessionHostEndpointOptions {
|
|
646
712
|
/**
|
|
647
713
|
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
@@ -780,6 +846,10 @@ declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: Sess
|
|
|
780
846
|
* byte-for-byte identical to the pre-instance layout.
|
|
781
847
|
*/
|
|
782
848
|
declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
849
|
+
/** Last-line storage guard, shared by session-host and mesh persistence.
|
|
850
|
+
* Node's test runner propagates NODE_TEST_CONTEXT to children; Vitest marks
|
|
851
|
+
* its workers separately. Explicit temporary roots remain valid. */
|
|
852
|
+
declare function assertTestStorageIsolated(destination: string): void;
|
|
783
853
|
/**
|
|
784
854
|
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
785
855
|
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
@@ -910,4 +980,4 @@ interface SessionHostControlTransport {
|
|
|
910
980
|
*/
|
|
911
981
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
912
982
|
|
|
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 };
|
|
983
|
+
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, assertTestStorageIsolated, 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, validateSessionHostEndpoint, writeEnvelope };
|
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,21 @@ interface SessionHostRecord {
|
|
|
110
110
|
meta: Record<string, unknown>;
|
|
111
111
|
/** Termination tombstone, stamped when the PTY process exits. Retained for post-mortem inspection. */
|
|
112
112
|
termination?: SessionTermination;
|
|
113
|
+
/**
|
|
114
|
+
* Monotonic count of input accepted into this runtime by `send_input`, from
|
|
115
|
+
* any client (SUBMIT-UNCONFIRMED-RECLAIM: the authoritative input boundary).
|
|
116
|
+
* Every accepted input is also announced as a `session_input` event carrying
|
|
117
|
+
* this number and the writer. Absent on records from a host that predates it
|
|
118
|
+
* — a reader must then treat input provenance as unknown.
|
|
119
|
+
*/
|
|
120
|
+
inputSeq?: number;
|
|
121
|
+
/**
|
|
122
|
+
* Identifies one lifetime of `inputSeq`. It changes whenever the counter
|
|
123
|
+
* could have restarted or been rewound — a new host process loading the
|
|
124
|
+
* record, or a restore with a lower count — so equal (epoch, seq) pairs
|
|
125
|
+
* really are the same point in the input stream.
|
|
126
|
+
*/
|
|
127
|
+
inputEpoch?: string;
|
|
113
128
|
}
|
|
114
129
|
interface CreateSessionPayload {
|
|
115
130
|
sessionId?: string;
|
|
@@ -140,6 +155,20 @@ interface SendInputPayload {
|
|
|
140
155
|
clientId: string;
|
|
141
156
|
data: string;
|
|
142
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* `send_input_if_seq`: write `data` only if NOTHING else has been input since
|
|
160
|
+
* the caller last accounted the stream — the host's (inputEpoch, inputSeq) is
|
|
161
|
+
* still exactly (expectedInputEpoch, expectedInputSeq) — and the caller may
|
|
162
|
+
* write without taking ownership (no force). Atomic on the host, so no input
|
|
163
|
+
* can slip between the caller's check and this write.
|
|
164
|
+
*/
|
|
165
|
+
interface SendInputIfSeqPayload extends SendInputPayload {
|
|
166
|
+
expectedInputSeq: number;
|
|
167
|
+
expectedInputEpoch: string;
|
|
168
|
+
}
|
|
169
|
+
interface GetInputStatePayload {
|
|
170
|
+
sessionId: string;
|
|
171
|
+
}
|
|
143
172
|
interface ResizeSessionPayload {
|
|
144
173
|
sessionId: string;
|
|
145
174
|
cols: number;
|
|
@@ -318,6 +347,12 @@ type SessionHostRequest = {
|
|
|
318
347
|
} | {
|
|
319
348
|
type: 'send_input';
|
|
320
349
|
payload: SendInputPayload;
|
|
350
|
+
} | {
|
|
351
|
+
type: 'send_input_if_seq';
|
|
352
|
+
payload: SendInputIfSeqPayload;
|
|
353
|
+
} | {
|
|
354
|
+
type: 'get_input_state';
|
|
355
|
+
payload: GetInputStatePayload;
|
|
321
356
|
} | {
|
|
322
357
|
type: 'resize_session';
|
|
323
358
|
payload: ResizeSessionPayload;
|
|
@@ -366,9 +401,16 @@ type SessionHostRequest = {
|
|
|
366
401
|
} | {
|
|
367
402
|
type: 'prune_duplicate_sessions';
|
|
368
403
|
payload?: PruneDuplicateSessionsPayload;
|
|
404
|
+
} | {
|
|
405
|
+
type: 'get_session';
|
|
406
|
+
payload: {
|
|
407
|
+
sessionId: string;
|
|
408
|
+
};
|
|
369
409
|
} | {
|
|
370
410
|
type: 'list_sessions';
|
|
371
|
-
payload?: {
|
|
411
|
+
payload?: {
|
|
412
|
+
activeOnly?: boolean;
|
|
413
|
+
};
|
|
372
414
|
};
|
|
373
415
|
type SessionHostRequestType = SessionHostRequest['type'];
|
|
374
416
|
declare const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[];
|
|
@@ -394,6 +436,14 @@ type SessionHostEvent = {
|
|
|
394
436
|
sessionId: string;
|
|
395
437
|
seq: number;
|
|
396
438
|
data: string;
|
|
439
|
+
}
|
|
440
|
+
/** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
|
|
441
|
+
| {
|
|
442
|
+
type: 'session_input';
|
|
443
|
+
sessionId: string;
|
|
444
|
+
seq: number;
|
|
445
|
+
epoch: string;
|
|
446
|
+
clientId: string;
|
|
397
447
|
} | {
|
|
398
448
|
type: 'session_cleared';
|
|
399
449
|
sessionId: string;
|
|
@@ -580,15 +630,29 @@ declare class SessionRingBuffer {
|
|
|
580
630
|
|
|
581
631
|
declare class SessionHostRegistry {
|
|
582
632
|
private sessions;
|
|
633
|
+
/** This registry's lifetime; every inputEpoch it mints starts with it. */
|
|
634
|
+
private readonly lifetimeId;
|
|
635
|
+
private epochCounter;
|
|
636
|
+
private mintInputEpoch;
|
|
583
637
|
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
584
638
|
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
585
639
|
seq: number;
|
|
586
640
|
text: string;
|
|
587
641
|
} | null): SessionHostRecord;
|
|
642
|
+
/** Census projection: omit launch arguments/environment and summarize stopped
|
|
643
|
+
* sessions. Full details remain available through getSession. */
|
|
644
|
+
listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
|
|
588
645
|
listSessions(): SessionHostRecord[];
|
|
589
646
|
getSession(sessionId: string): SessionHostRecord | null;
|
|
590
647
|
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
591
648
|
detachClient(payload: DetachSessionPayload): SessionHostRecord;
|
|
649
|
+
/** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
|
|
650
|
+
recordInput(sessionId: string): number;
|
|
651
|
+
/** The current input counter (see SessionHostInputState). */
|
|
652
|
+
getInputState(sessionId: string): {
|
|
653
|
+
inputSeq: number;
|
|
654
|
+
inputEpoch: string;
|
|
655
|
+
};
|
|
592
656
|
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
593
657
|
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
594
658
|
appendOutput(sessionId: string, data: string): {
|
|
@@ -642,6 +706,8 @@ interface SessionHostEndpoint {
|
|
|
642
706
|
kind: 'unix' | 'pipe';
|
|
643
707
|
path: string;
|
|
644
708
|
}
|
|
709
|
+
/** Reserve the trailing NUL in sockaddr_un; named pipes have a separate namespace. */
|
|
710
|
+
declare function validateSessionHostEndpoint(endpoint: SessionHostEndpoint, platform?: NodeJS.Platform): void;
|
|
645
711
|
interface SessionHostEndpointOptions {
|
|
646
712
|
/**
|
|
647
713
|
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
@@ -780,6 +846,10 @@ declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: Sess
|
|
|
780
846
|
* byte-for-byte identical to the pre-instance layout.
|
|
781
847
|
*/
|
|
782
848
|
declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
849
|
+
/** Last-line storage guard, shared by session-host and mesh persistence.
|
|
850
|
+
* Node's test runner propagates NODE_TEST_CONTEXT to children; Vitest marks
|
|
851
|
+
* its workers separately. Explicit temporary roots remain valid. */
|
|
852
|
+
declare function assertTestStorageIsolated(destination: string): void;
|
|
783
853
|
/**
|
|
784
854
|
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
785
855
|
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
@@ -910,4 +980,4 @@ interface SessionHostControlTransport {
|
|
|
910
980
|
*/
|
|
911
981
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
912
982
|
|
|
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 };
|
|
983
|
+
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, assertTestStorageIsolated, 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, validateSessionHostEndpoint, writeEnvelope };
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
SessionHostRegistry: () => SessionHostRegistry,
|
|
43
43
|
SessionRingBuffer: () => SessionRingBuffer,
|
|
44
44
|
applyTerminalColorEnv: () => applyTerminalColorEnv,
|
|
45
|
+
assertTestStorageIsolated: () => assertTestStorageIsolated,
|
|
45
46
|
buildRuntimeDisplayName: () => buildRuntimeDisplayName,
|
|
46
47
|
buildRuntimeKey: () => buildRuntimeKey,
|
|
47
48
|
canonicalizeInstancePath: () => canonicalizeInstancePath,
|
|
@@ -74,6 +75,7 @@ __export(index_exports, {
|
|
|
74
75
|
resolveSessionHostRows: () => resolveSessionHostRows,
|
|
75
76
|
sanitizeSpawnEnv: () => sanitizeSpawnEnv,
|
|
76
77
|
spawnCliChild: () => spawnCliChild,
|
|
78
|
+
validateSessionHostEndpoint: () => validateSessionHostEndpoint,
|
|
77
79
|
writeEnvelope: () => writeEnvelope
|
|
78
80
|
});
|
|
79
81
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -87,6 +89,8 @@ var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
|
|
|
87
89
|
"attach_session",
|
|
88
90
|
"detach_session",
|
|
89
91
|
"send_input",
|
|
92
|
+
"send_input_if_seq",
|
|
93
|
+
"get_input_state",
|
|
90
94
|
"resize_session",
|
|
91
95
|
"stop_session",
|
|
92
96
|
"stop_mesh_writer",
|
|
@@ -103,6 +107,7 @@ var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
|
|
|
103
107
|
"send_signal",
|
|
104
108
|
"restart_session",
|
|
105
109
|
"prune_duplicate_sessions",
|
|
110
|
+
"get_session",
|
|
106
111
|
"list_sessions"
|
|
107
112
|
];
|
|
108
113
|
|
|
@@ -531,6 +536,13 @@ function formatRuntimeOwner(record) {
|
|
|
531
536
|
// src/registry.ts
|
|
532
537
|
var SessionHostRegistry = class {
|
|
533
538
|
sessions = /* @__PURE__ */ new Map();
|
|
539
|
+
/** This registry's lifetime; every inputEpoch it mints starts with it. */
|
|
540
|
+
lifetimeId = generateUUID();
|
|
541
|
+
epochCounter = 0;
|
|
542
|
+
mintInputEpoch() {
|
|
543
|
+
this.epochCounter += 1;
|
|
544
|
+
return `${this.lifetimeId}:${this.epochCounter}`;
|
|
545
|
+
}
|
|
534
546
|
createSession(payload) {
|
|
535
547
|
const sessionId = payload.sessionId || generateUUID();
|
|
536
548
|
if (this.sessions.has(sessionId)) {
|
|
@@ -562,6 +574,8 @@ var SessionHostRegistry = class {
|
|
|
562
574
|
lifecycle: "starting",
|
|
563
575
|
writeOwner: null,
|
|
564
576
|
attachedClients: initialClient,
|
|
577
|
+
inputSeq: 0,
|
|
578
|
+
inputEpoch: this.mintInputEpoch(),
|
|
565
579
|
buffer: {
|
|
566
580
|
scrollbackBytes: 0,
|
|
567
581
|
snapshotSeq: 0
|
|
@@ -581,6 +595,10 @@ var SessionHostRegistry = class {
|
|
|
581
595
|
}
|
|
582
596
|
restoreSession(record, snapshot) {
|
|
583
597
|
const cloned = this.cloneRecord(record);
|
|
598
|
+
if (typeof cloned.inputSeq !== "number") cloned.inputSeq = 0;
|
|
599
|
+
const live = this.sessions.get(cloned.sessionId)?.record;
|
|
600
|
+
const sameLifetime = !!live && typeof live.inputEpoch === "string" && cloned.inputEpoch === live.inputEpoch && cloned.inputSeq >= (live.inputSeq ?? 0);
|
|
601
|
+
if (!sameLifetime) cloned.inputEpoch = this.mintInputEpoch();
|
|
584
602
|
this.sessions.set(cloned.sessionId, {
|
|
585
603
|
record: cloned,
|
|
586
604
|
buffer: (() => {
|
|
@@ -591,6 +609,15 @@ var SessionHostRegistry = class {
|
|
|
591
609
|
});
|
|
592
610
|
return this.cloneRecord(cloned);
|
|
593
611
|
}
|
|
612
|
+
/** Census projection: omit launch arguments/environment and summarize stopped
|
|
613
|
+
* sessions. Full details remain available through getSession. */
|
|
614
|
+
listSessionSummaries(activeOnly = false) {
|
|
615
|
+
return Array.from(this.sessions.values()).map((s) => s.record).filter((r) => !activeOnly || !r.termination && r.lifecycle !== "stopped" && r.lifecycle !== "failed").map((r) => this.cloneRecord({
|
|
616
|
+
...r,
|
|
617
|
+
launchCommand: { command: r.launchCommand.command, args: [] },
|
|
618
|
+
meta: r.termination || r.lifecycle === "stopped" || r.lifecycle === "failed" ? {} : { ...r.meta, cliArgs: [], cliArgsOmitted: true }
|
|
619
|
+
})).sort((a, b) => b.lastActivityAt - a.lastActivityAt);
|
|
620
|
+
}
|
|
594
621
|
listSessions() {
|
|
595
622
|
return Array.from(this.sessions.values()).map((state) => this.cloneRecord(state.record)).sort((a, b) => b.lastActivityAt - a.lastActivityAt);
|
|
596
623
|
}
|
|
@@ -642,6 +669,20 @@ var SessionHostRegistry = class {
|
|
|
642
669
|
state.record.lastActivityAt = Date.now();
|
|
643
670
|
return this.cloneRecord(state.record);
|
|
644
671
|
}
|
|
672
|
+
/** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
|
|
673
|
+
recordInput(sessionId) {
|
|
674
|
+
const state = this.requireSession(sessionId);
|
|
675
|
+
state.record.inputSeq = (typeof state.record.inputSeq === "number" ? state.record.inputSeq : 0) + 1;
|
|
676
|
+
if (typeof state.record.inputEpoch !== "string") state.record.inputEpoch = this.mintInputEpoch();
|
|
677
|
+
return state.record.inputSeq;
|
|
678
|
+
}
|
|
679
|
+
/** The current input counter (see SessionHostInputState). */
|
|
680
|
+
getInputState(sessionId) {
|
|
681
|
+
const state = this.requireSession(sessionId);
|
|
682
|
+
if (typeof state.record.inputSeq !== "number") state.record.inputSeq = 0;
|
|
683
|
+
if (typeof state.record.inputEpoch !== "string") state.record.inputEpoch = this.mintInputEpoch();
|
|
684
|
+
return { inputSeq: state.record.inputSeq, inputEpoch: state.record.inputEpoch };
|
|
685
|
+
}
|
|
645
686
|
acquireWrite(payload) {
|
|
646
687
|
const state = this.requireSession(payload.sessionId);
|
|
647
688
|
if (state.record.writeOwner && state.record.writeOwner.clientId !== payload.clientId && !payload.force) {
|
|
@@ -762,6 +803,14 @@ var os2 = __toESM(require("os"));
|
|
|
762
803
|
var path2 = __toESM(require("path"));
|
|
763
804
|
var net = __toESM(require("net"));
|
|
764
805
|
var import_string_decoder = require("string_decoder");
|
|
806
|
+
function validateSessionHostEndpoint(endpoint, platform2 = process.platform) {
|
|
807
|
+
if (endpoint.kind !== "unix") return;
|
|
808
|
+
const limit = platform2 === "linux" ? 108 : 104;
|
|
809
|
+
const pathBytes = Buffer.byteLength(endpoint.path, "utf8");
|
|
810
|
+
if (pathBytes + 1 > limit) {
|
|
811
|
+
throw new Error(`session_host_unix_socket_path_too_long: path_bytes=${pathBytes} required_bytes=${pathBytes + 1} limit_bytes=${limit} platform=${platform2}`);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
765
814
|
function getDefaultSessionHostEndpoint(appName = "adhdev", options = {}) {
|
|
766
815
|
const rawKey = typeof options.ipcKey === "string" ? options.ipcKey.trim() : "";
|
|
767
816
|
if (rawKey && !/^[0-9a-f]{12}$/.test(rawKey)) {
|
|
@@ -785,23 +834,27 @@ function serializeEnvelope(envelope) {
|
|
|
785
834
|
`;
|
|
786
835
|
}
|
|
787
836
|
function createLineParser(onEnvelope) {
|
|
788
|
-
let
|
|
837
|
+
let fragments = [];
|
|
789
838
|
const decoder = new import_string_decoder.StringDecoder("utf8");
|
|
790
839
|
const parser = (chunk) => {
|
|
791
|
-
|
|
792
|
-
let
|
|
793
|
-
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
840
|
+
const text = typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
841
|
+
let start = 0;
|
|
842
|
+
for (; ; ) {
|
|
843
|
+
const newline = text.indexOf("\n", start);
|
|
844
|
+
if (newline < 0) {
|
|
845
|
+
if (start < text.length) fragments.push(text.slice(start));
|
|
846
|
+
break;
|
|
798
847
|
}
|
|
799
|
-
|
|
848
|
+
fragments.push(text.slice(start, newline));
|
|
849
|
+
const rawLine = fragments.join("").trim();
|
|
850
|
+
fragments = [];
|
|
851
|
+
start = newline + 1;
|
|
852
|
+
if (rawLine) onEnvelope(JSON.parse(rawLine));
|
|
800
853
|
}
|
|
801
854
|
};
|
|
802
855
|
parser.end = () => {
|
|
803
|
-
const remainder =
|
|
804
|
-
|
|
856
|
+
const remainder = fragments.join("") + decoder.end();
|
|
857
|
+
fragments = [];
|
|
805
858
|
return remainder;
|
|
806
859
|
};
|
|
807
860
|
return parser;
|
|
@@ -998,7 +1051,12 @@ var SessionHostClient = class {
|
|
|
998
1051
|
return;
|
|
999
1052
|
}
|
|
1000
1053
|
if (envelope.kind === "event") {
|
|
1001
|
-
for (const listener of this.eventListeners)
|
|
1054
|
+
for (const listener of this.eventListeners) {
|
|
1055
|
+
try {
|
|
1056
|
+
listener(envelope.event);
|
|
1057
|
+
} catch {
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1002
1060
|
}
|
|
1003
1061
|
});
|
|
1004
1062
|
socket.on("data", parser);
|
|
@@ -1208,9 +1266,23 @@ var fs = __toESM(require("fs"));
|
|
|
1208
1266
|
var os3 = __toESM(require("os"));
|
|
1209
1267
|
var path3 = __toESM(require("path"));
|
|
1210
1268
|
var DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
1269
|
+
function assertTestStorageIsolated(destination) {
|
|
1270
|
+
const env = process.env;
|
|
1271
|
+
if (!env.VITEST && env.NODE_ENV !== "test" && !env.NODE_TEST_CONTEXT && !process.execArgv.some((arg) => arg === "--test" || arg.startsWith("--test="))) return;
|
|
1272
|
+
const target = canonicalizeInstancePath(destination);
|
|
1273
|
+
const home = os3.userInfo().homedir;
|
|
1274
|
+
for (const track of [".adhdev", ".adhdev-preview"]) {
|
|
1275
|
+
const live = canonicalizeInstancePath(path3.join(home, track));
|
|
1276
|
+
if (target === live || target.startsWith(live + path3.sep)) {
|
|
1277
|
+
throw new Error("LIVE runtime storage is forbidden in a test process; pin ADHDEV_CONFIG_DIR or storageRootDir to a temporary directory");
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1211
1281
|
function resolveInstanceConfigDir(env = process.env, homeDir = os3.homedir()) {
|
|
1212
1282
|
const override = typeof env.ADHDEV_CONFIG_DIR === "string" ? env.ADHDEV_CONFIG_DIR.trim() : "";
|
|
1213
|
-
|
|
1283
|
+
const resolved = override || path3.join(homeDir, DEFAULT_CONFIG_DIR_NAME);
|
|
1284
|
+
if (env === process.env) assertTestStorageIsolated(resolved);
|
|
1285
|
+
return resolved;
|
|
1214
1286
|
}
|
|
1215
1287
|
function realpathLongestExistingPrefix(resolved) {
|
|
1216
1288
|
let current = resolved;
|
|
@@ -1378,6 +1450,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
1378
1450
|
SessionHostRegistry,
|
|
1379
1451
|
SessionRingBuffer,
|
|
1380
1452
|
applyTerminalColorEnv,
|
|
1453
|
+
assertTestStorageIsolated,
|
|
1381
1454
|
buildRuntimeDisplayName,
|
|
1382
1455
|
buildRuntimeKey,
|
|
1383
1456
|
canonicalizeInstancePath,
|
|
@@ -1410,6 +1483,7 @@ function createSessionHostControlPlane(transport) {
|
|
|
1410
1483
|
resolveSessionHostRows,
|
|
1411
1484
|
sanitizeSpawnEnv,
|
|
1412
1485
|
spawnCliChild,
|
|
1486
|
+
validateSessionHostEndpoint,
|
|
1413
1487
|
writeEnvelope
|
|
1414
1488
|
});
|
|
1415
1489
|
//# sourceMappingURL=index.js.map
|