@adhdev/session-host-core 1.0.82-rc.13 → 1.0.82-rc.131
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 +304 -4
- package/dist/index.d.ts +304 -4
- package/dist/index.js +593 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +574 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/cleanup-expected.ts +114 -0
- package/src/cli-child-priority.ts +117 -0
- package/src/control-plane.ts +58 -0
- package/src/index.ts +23 -0
- package/src/instance-key.ts +20 -1
- package/src/ipc.ts +289 -46
- package/src/process/hidden-spawn.ts +10 -0
- package/src/registry.ts +87 -0
- package/src/spawn-env.ts +11 -0
- package/src/types.ts +118 -1
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;
|
|
@@ -106,6 +110,21 @@ interface SessionHostRecord {
|
|
|
106
110
|
meta: Record<string, unknown>;
|
|
107
111
|
/** Termination tombstone, stamped when the PTY process exits. Retained for post-mortem inspection. */
|
|
108
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;
|
|
109
128
|
}
|
|
110
129
|
interface CreateSessionPayload {
|
|
111
130
|
sessionId?: string;
|
|
@@ -136,6 +155,20 @@ interface SendInputPayload {
|
|
|
136
155
|
clientId: string;
|
|
137
156
|
data: string;
|
|
138
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
|
+
}
|
|
139
172
|
interface ResizeSessionPayload {
|
|
140
173
|
sessionId: string;
|
|
141
174
|
cols: number;
|
|
@@ -144,11 +177,58 @@ interface ResizeSessionPayload {
|
|
|
144
177
|
interface StopSessionPayload {
|
|
145
178
|
sessionId: string;
|
|
146
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Expected logical + physical identity for a cleanup stop. Captured before any
|
|
182
|
+
* async host RPC and re-checked inside the host stop critical section.
|
|
183
|
+
* All of taskId/attemptId/generation/dispatchNonce null means expected unbound
|
|
184
|
+
* (no meshActiveAssignment) so a later claim cannot be stopped by stale cleanup.
|
|
185
|
+
*/
|
|
186
|
+
interface SessionCleanupExpectedAssignment {
|
|
187
|
+
sessionId: string;
|
|
188
|
+
hostBootId: string;
|
|
189
|
+
runtimeKey: string;
|
|
190
|
+
startedAt: number;
|
|
191
|
+
taskId: string | null;
|
|
192
|
+
attemptId: string | null;
|
|
193
|
+
generation: number | null;
|
|
194
|
+
dispatchNonce: number | null;
|
|
195
|
+
}
|
|
196
|
+
interface StopSessionIfExpectedPayload {
|
|
197
|
+
sessionId: string;
|
|
198
|
+
expected: SessionCleanupExpectedAssignment;
|
|
199
|
+
}
|
|
200
|
+
interface MeshWriterAssignment {
|
|
201
|
+
meshId: string;
|
|
202
|
+
nodeId: string;
|
|
203
|
+
taskId: string;
|
|
204
|
+
attemptId: string;
|
|
205
|
+
generation: number;
|
|
206
|
+
dispatchNonce: number;
|
|
207
|
+
ownerDaemonId: string;
|
|
208
|
+
}
|
|
209
|
+
interface MeshWriterStopTarget {
|
|
210
|
+
runtimeKey: string;
|
|
211
|
+
startedAt: number;
|
|
212
|
+
osPid: number;
|
|
213
|
+
providerType: string;
|
|
214
|
+
assignment: MeshWriterAssignment;
|
|
215
|
+
}
|
|
216
|
+
interface StopMeshWriterPayload extends MeshWriterStopTarget {
|
|
217
|
+
sessionId: string;
|
|
218
|
+
clientId: string;
|
|
219
|
+
}
|
|
147
220
|
interface DeleteSessionPayload {
|
|
148
221
|
sessionId: string;
|
|
149
222
|
/** Stop a live runtime before deleting the persisted record. */
|
|
150
223
|
force?: boolean;
|
|
151
224
|
}
|
|
225
|
+
/** Expected identity for record deletion; old hosts must refuse this distinct kind. */
|
|
226
|
+
interface DeleteSessionIfExpectedPayload {
|
|
227
|
+
sessionId: string;
|
|
228
|
+
expected: SessionCleanupExpectedAssignment;
|
|
229
|
+
/** Stop the matching live runtime before deleting that exact incarnation. */
|
|
230
|
+
force?: boolean;
|
|
231
|
+
}
|
|
152
232
|
interface ResumeSessionPayload {
|
|
153
233
|
sessionId: string;
|
|
154
234
|
}
|
|
@@ -177,6 +257,16 @@ interface UpdateSessionMetaPayload {
|
|
|
177
257
|
meta: Record<string, unknown>;
|
|
178
258
|
replace?: boolean;
|
|
179
259
|
}
|
|
260
|
+
/** Bounded liveness check for identities whose provenance the caller already holds.
|
|
261
|
+
* No launch arguments, metadata, snapshots or diagnostic log bodies cross IPC. */
|
|
262
|
+
interface SessionHostCensus {
|
|
263
|
+
hostStartedAt: number;
|
|
264
|
+
endpoint: string;
|
|
265
|
+
hostEntryPath?: string;
|
|
266
|
+
liveSessionIds: string[];
|
|
267
|
+
/** A live role-marked writer outside the caller's persisted identities. */
|
|
268
|
+
hasOtherAssistantCandidates: boolean;
|
|
269
|
+
}
|
|
180
270
|
interface GetHostDiagnosticsPayload {
|
|
181
271
|
includeSessions?: boolean;
|
|
182
272
|
limit?: number;
|
|
@@ -240,6 +330,8 @@ interface SessionHostRuntimeTransition {
|
|
|
240
330
|
interface SessionHostDiagnostics {
|
|
241
331
|
hostStartedAt: number;
|
|
242
332
|
endpoint: string;
|
|
333
|
+
/** Descriptors this host holds open; undefined where it cannot be counted. A count far above the live runtimes means a leak. */
|
|
334
|
+
openFdCount?: number;
|
|
243
335
|
/**
|
|
244
336
|
* Absolute path of the script this host process is running (its own
|
|
245
337
|
* `__filename`), self-reported.
|
|
@@ -257,6 +349,13 @@ interface SessionHostDiagnostics {
|
|
|
257
349
|
* must treat `undefined` as "unknown", never as a match.
|
|
258
350
|
*/
|
|
259
351
|
hostEntryPath?: string;
|
|
352
|
+
/**
|
|
353
|
+
* Authoritative host boot identity used by cleanup expected-assignment CAS.
|
|
354
|
+
* Same value `stop_session_if_expected` refuses against: upgrade-lease bootId
|
|
355
|
+
* when the host was launched with a native upgrade binding, otherwise `hs:<hostStartedAt>`.
|
|
356
|
+
* Optional so older hosts omit it; callers must not invent an upgrade UUID.
|
|
357
|
+
*/
|
|
358
|
+
hostBootId?: string;
|
|
260
359
|
runtimeCount: number;
|
|
261
360
|
supportedRequestTypes?: SessionHostRequestType[];
|
|
262
361
|
sessions?: SessionHostRecord[];
|
|
@@ -288,21 +387,49 @@ type SessionHostRequest = {
|
|
|
288
387
|
} | {
|
|
289
388
|
type: 'attach_session';
|
|
290
389
|
payload: AttachSessionPayload;
|
|
390
|
+
} | {
|
|
391
|
+
type: 'attach_session_if_incarnation';
|
|
392
|
+
payload: AttachSessionPayload & {
|
|
393
|
+
expectedIncarnation: {
|
|
394
|
+
sessionId: string;
|
|
395
|
+
runtimeKey: string;
|
|
396
|
+
startedAt: number;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
291
399
|
} | {
|
|
292
400
|
type: 'detach_session';
|
|
293
401
|
payload: DetachSessionPayload;
|
|
294
402
|
} | {
|
|
295
403
|
type: 'send_input';
|
|
296
404
|
payload: SendInputPayload;
|
|
405
|
+
} | {
|
|
406
|
+
type: 'send_input_if_seq';
|
|
407
|
+
payload: SendInputIfSeqPayload;
|
|
408
|
+
} | {
|
|
409
|
+
type: 'get_input_state';
|
|
410
|
+
payload: GetInputStatePayload;
|
|
297
411
|
} | {
|
|
298
412
|
type: 'resize_session';
|
|
299
413
|
payload: ResizeSessionPayload;
|
|
300
414
|
} | {
|
|
301
415
|
type: 'stop_session';
|
|
302
416
|
payload: StopSessionPayload;
|
|
417
|
+
}
|
|
418
|
+
/** Distinct kind: old hosts must refuse instead of stopping by session id alone. */
|
|
419
|
+
| {
|
|
420
|
+
type: 'stop_session_if_expected';
|
|
421
|
+
payload: StopSessionIfExpectedPayload;
|
|
422
|
+
} | {
|
|
423
|
+
type: 'stop_mesh_writer';
|
|
424
|
+
payload: StopMeshWriterPayload;
|
|
303
425
|
} | {
|
|
304
426
|
type: 'delete_session';
|
|
305
427
|
payload: DeleteSessionPayload;
|
|
428
|
+
}
|
|
429
|
+
/** Distinct kind: old hosts must refuse instead of deleting by session id alone. */
|
|
430
|
+
| {
|
|
431
|
+
type: 'delete_session_if_expected';
|
|
432
|
+
payload: DeleteSessionIfExpectedPayload;
|
|
306
433
|
} | {
|
|
307
434
|
type: 'resume_session';
|
|
308
435
|
payload: ResumeSessionPayload;
|
|
@@ -339,9 +466,21 @@ type SessionHostRequest = {
|
|
|
339
466
|
} | {
|
|
340
467
|
type: 'prune_duplicate_sessions';
|
|
341
468
|
payload?: PruneDuplicateSessionsPayload;
|
|
469
|
+
} | {
|
|
470
|
+
type: 'get_session_census';
|
|
471
|
+
payload: {
|
|
472
|
+
sessionIds: string[];
|
|
473
|
+
};
|
|
474
|
+
} | {
|
|
475
|
+
type: 'get_session';
|
|
476
|
+
payload: {
|
|
477
|
+
sessionId: string;
|
|
478
|
+
};
|
|
342
479
|
} | {
|
|
343
480
|
type: 'list_sessions';
|
|
344
|
-
payload?: {
|
|
481
|
+
payload?: {
|
|
482
|
+
activeOnly?: boolean;
|
|
483
|
+
};
|
|
345
484
|
};
|
|
346
485
|
type SessionHostRequestType = SessionHostRequest['type'];
|
|
347
486
|
declare const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[];
|
|
@@ -367,6 +506,14 @@ type SessionHostEvent = {
|
|
|
367
506
|
sessionId: string;
|
|
368
507
|
seq: number;
|
|
369
508
|
data: string;
|
|
509
|
+
}
|
|
510
|
+
/** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
|
|
511
|
+
| {
|
|
512
|
+
type: 'session_input';
|
|
513
|
+
sessionId: string;
|
|
514
|
+
seq: number;
|
|
515
|
+
epoch: string;
|
|
516
|
+
clientId: string;
|
|
370
517
|
} | {
|
|
371
518
|
type: 'session_cleared';
|
|
372
519
|
sessionId: string;
|
|
@@ -425,6 +572,34 @@ interface SessionHostEventEnvelope {
|
|
|
425
572
|
}
|
|
426
573
|
type SessionHostWireEnvelope = SessionHostRequestEnvelope | SessionHostResponseEnvelope | SessionHostEventEnvelope;
|
|
427
574
|
|
|
575
|
+
/** Shared cleanup expected-assignment / host-boot helpers (daemon + host). */
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Prefix on delete_session_if_expected refusals after runtime.stop was requested.
|
|
579
|
+
* Client durable fences must not abort on these — the writer may already be dying.
|
|
580
|
+
* Before-action refusals keep the bare CLEANUP_HOST_REFUSAL_CODES (abort-safe proof).
|
|
581
|
+
*/
|
|
582
|
+
declare const CLEANUP_AFTER_STOP_SIDE_EFFECT_PREFIX = "cleanup_after_stop_side_effect:";
|
|
583
|
+
declare function tagCleanupAfterStopSideEffect(code: string): string;
|
|
584
|
+
declare function stripCleanupAfterStopSideEffect(raw: string): {
|
|
585
|
+
afterStop: boolean;
|
|
586
|
+
code: string;
|
|
587
|
+
};
|
|
588
|
+
declare function hostBootIdFromStartedAt(hostStartedAt: number): string;
|
|
589
|
+
declare function resolveHostBootId(opts: {
|
|
590
|
+
upgradeBootId?: string | null;
|
|
591
|
+
hostStartedAt: number;
|
|
592
|
+
}): string | null;
|
|
593
|
+
/** Sanitized refusal codes only — never echo assignment contents. */
|
|
594
|
+
declare function refuseCleanupExpectedStop(record: SessionHostRecord | null | undefined, expected: SessionCleanupExpectedAssignment, currentHostBootId: string | null, hasRuntime: boolean): string | null;
|
|
595
|
+
/**
|
|
596
|
+
* Delete CAS: same identity/assignment proof as stop. A replaced incarnation or a
|
|
597
|
+
* newly bound writer must survive — never delete a record that no longer matches
|
|
598
|
+
* the captured expected tuple. `force` is required to stop a still-live runtime
|
|
599
|
+
* before deleting that exact incarnation.
|
|
600
|
+
*/
|
|
601
|
+
declare function refuseCleanupExpectedDelete(record: SessionHostRecord | null | undefined, expected: SessionCleanupExpectedAssignment, currentHostBootId: string | null, hasRuntime: boolean, force: boolean): string | null;
|
|
602
|
+
|
|
428
603
|
interface ClassifyTerminationInput {
|
|
429
604
|
exitCode: number | null;
|
|
430
605
|
signal?: number | null;
|
|
@@ -449,6 +624,62 @@ interface ClassifyTerminationInput {
|
|
|
449
624
|
*/
|
|
450
625
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
451
626
|
|
|
627
|
+
/** Relative POSIX niceness adjustment for newly spawned agent workloads. */
|
|
628
|
+
declare const CLI_CHILD_NICE_INCREMENT = 10;
|
|
629
|
+
/** Set to "0" in the daemon environment (or launch env) to disable lowering. */
|
|
630
|
+
declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
|
|
631
|
+
/** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
|
|
632
|
+
declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
|
|
633
|
+
declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
|
|
634
|
+
interface NiceLaunch {
|
|
635
|
+
readonly command: string;
|
|
636
|
+
readonly args: string[];
|
|
637
|
+
/** True when the child will START at the lowered priority (spawnCliChild must not lower it again). */
|
|
638
|
+
readonly preApplied: boolean;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Launch through `nice -n <increment>` on macOS/Linux so the child runs at the
|
|
642
|
+
* lowered priority from its first instruction. `nice` execs the target in
|
|
643
|
+
* place: same pid, and every descendant inherits the niceness. This closes the
|
|
644
|
+
* spawn→setPriority race where a child forked before the post-spawn call and
|
|
645
|
+
* its early descendants escaped at NI=0. Windows (no nice) and shell-string
|
|
646
|
+
* launches keep the post-spawn path.
|
|
647
|
+
*/
|
|
648
|
+
declare function niceLaunch(command: string, args: readonly string[], env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, niceAvailable?: () => boolean): NiceLaunch;
|
|
649
|
+
interface PriorityDependencies {
|
|
650
|
+
platform: NodeJS.Platform;
|
|
651
|
+
getPriority: typeof os.getPriority;
|
|
652
|
+
setPriority: typeof os.setPriority;
|
|
653
|
+
setDarwinBackground?: typeof setDarwinBackground;
|
|
654
|
+
}
|
|
655
|
+
/** Separate policy instances are useful for platform/error tests. */
|
|
656
|
+
declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
|
|
657
|
+
readonly pid?: number;
|
|
658
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
|
|
659
|
+
preApplied?: boolean;
|
|
660
|
+
}) => T;
|
|
661
|
+
/**
|
|
662
|
+
* Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
|
|
663
|
+
* workers, version probes and git helpers at their existing priority.
|
|
664
|
+
*
|
|
665
|
+
* node-pty has no pre-spawn priority hook. Apply immediately on return, before
|
|
666
|
+
* registering listeners/doing other work. There is a spawn-to-setPriority race:
|
|
667
|
+
* a child can run (and fork) before this call. Later descendants inherit nice
|
|
668
|
+
* on POSIX; early descendants are not retroactively changed. Windows creation
|
|
669
|
+
* and ConPTY inheritance require verification on the DesktopA.
|
|
670
|
+
* Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
|
|
671
|
+
* extra helper startup adds a further race before the background class takes
|
|
672
|
+
* effect. It also throttles I/O, so nice alone remains the default.
|
|
673
|
+
*/
|
|
674
|
+
declare const spawnCliChild: <T extends {
|
|
675
|
+
readonly pid?: number;
|
|
676
|
+
}>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
|
|
677
|
+
preApplied?: boolean;
|
|
678
|
+
}) => T;
|
|
679
|
+
|
|
680
|
+
/** Shared hidden-window primitive for daemon and session-host process helpers. */
|
|
681
|
+
declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
|
|
682
|
+
|
|
452
683
|
interface SessionRingBufferOptions {
|
|
453
684
|
maxBytes?: number;
|
|
454
685
|
}
|
|
@@ -516,15 +747,37 @@ declare class SessionRingBuffer {
|
|
|
516
747
|
|
|
517
748
|
declare class SessionHostRegistry {
|
|
518
749
|
private sessions;
|
|
750
|
+
/** This registry's lifetime; every inputEpoch it mints starts with it. */
|
|
751
|
+
private readonly lifetimeId;
|
|
752
|
+
private epochCounter;
|
|
753
|
+
private mintInputEpoch;
|
|
519
754
|
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
520
755
|
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
521
756
|
seq: number;
|
|
522
757
|
text: string;
|
|
523
758
|
} | null): SessionHostRecord;
|
|
759
|
+
/** Census projection: omit launch arguments/environment and summarize stopped
|
|
760
|
+
* sessions. Full details remain available through getSession. */
|
|
761
|
+
listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
|
|
524
762
|
listSessions(): SessionHostRecord[];
|
|
763
|
+
/** No launch bodies are cloned. Unknown role evidence stays conservative. */
|
|
764
|
+
getSessionCensus(sessionIds: string[]): {
|
|
765
|
+
liveSessionIds: string[];
|
|
766
|
+
hasOtherAssistantCandidates: boolean;
|
|
767
|
+
};
|
|
525
768
|
getSession(sessionId: string): SessionHostRecord | null;
|
|
769
|
+
attachClientIfIncarnation(payload: Extract<SessionHostRequest, {
|
|
770
|
+
type: 'attach_session_if_incarnation';
|
|
771
|
+
}>['payload']): SessionHostRecord;
|
|
526
772
|
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
527
773
|
detachClient(payload: DetachSessionPayload): SessionHostRecord;
|
|
774
|
+
/** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
|
|
775
|
+
recordInput(sessionId: string): number;
|
|
776
|
+
/** The current input counter (see SessionHostInputState). */
|
|
777
|
+
getInputState(sessionId: string): {
|
|
778
|
+
inputSeq: number;
|
|
779
|
+
inputEpoch: string;
|
|
780
|
+
};
|
|
528
781
|
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
529
782
|
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
530
783
|
appendOutput(sessionId: string, data: string): {
|
|
@@ -578,6 +831,8 @@ interface SessionHostEndpoint {
|
|
|
578
831
|
kind: 'unix' | 'pipe';
|
|
579
832
|
path: string;
|
|
580
833
|
}
|
|
834
|
+
/** Reserve the trailing NUL in sockaddr_un; named pipes have a separate namespace. */
|
|
835
|
+
declare function validateSessionHostEndpoint(endpoint: SessionHostEndpoint, platform?: NodeJS.Platform): void;
|
|
581
836
|
interface SessionHostEndpointOptions {
|
|
582
837
|
/**
|
|
583
838
|
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
@@ -587,6 +842,8 @@ interface SessionHostEndpointOptions {
|
|
|
587
842
|
ipcKey?: string;
|
|
588
843
|
/** Test seam: override the platform the endpoint shape is derived for. */
|
|
589
844
|
platform?: NodeJS.Platform;
|
|
845
|
+
/** Test seam: override the temporary directory used for endpoint derivation. */
|
|
846
|
+
tmpDir?: string;
|
|
590
847
|
}
|
|
591
848
|
declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
|
|
592
849
|
/**
|
|
@@ -621,6 +878,9 @@ declare function createLineParser<TEnvelope = SessionHostWireEnvelope>(onEnvelop
|
|
|
621
878
|
interface SessionHostClientOptions {
|
|
622
879
|
endpoint?: SessionHostEndpoint;
|
|
623
880
|
appName?: string;
|
|
881
|
+
requestTimeoutMs?: number;
|
|
882
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
883
|
+
registerAsShared?: boolean;
|
|
624
884
|
}
|
|
625
885
|
/**
|
|
626
886
|
* Why an established session-host connection went away.
|
|
@@ -629,6 +889,8 @@ interface SessionHostClientOptions {
|
|
|
629
889
|
* - `closed` — socket fully closed ('close') without a preceding error/end
|
|
630
890
|
*/
|
|
631
891
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
892
|
+
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
893
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
632
894
|
interface SessionHostDisconnectInfo {
|
|
633
895
|
reason: SessionHostDisconnectReason;
|
|
634
896
|
endpointPath: string;
|
|
@@ -649,12 +911,19 @@ interface SessionHostDisconnectInfo {
|
|
|
649
911
|
declare class SessionHostClient {
|
|
650
912
|
readonly endpoint: SessionHostEndpoint;
|
|
651
913
|
private socket;
|
|
914
|
+
private connectPromise;
|
|
915
|
+
private requestTimeoutMs;
|
|
652
916
|
private requestWaiters;
|
|
653
917
|
private eventListeners;
|
|
654
918
|
private disconnectListeners;
|
|
655
919
|
/** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
|
|
656
920
|
private disconnectedSockets;
|
|
921
|
+
/** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
|
|
922
|
+
private attachedSessions;
|
|
657
923
|
constructor(options?: SessionHostClientOptions);
|
|
924
|
+
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
925
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
926
|
+
isConnected(): boolean;
|
|
658
927
|
/**
|
|
659
928
|
* Fires when an established connection to the session host goes away.
|
|
660
929
|
*
|
|
@@ -669,9 +938,13 @@ declare class SessionHostClient {
|
|
|
669
938
|
*/
|
|
670
939
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
671
940
|
private handleDisconnect;
|
|
672
|
-
|
|
941
|
+
private sendRawRequestOnSocket;
|
|
942
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
673
943
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
674
|
-
request<T = unknown>(request: SessionHostRequest
|
|
944
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
945
|
+
timeoutMs?: number;
|
|
946
|
+
}): Promise<SessionHostResponse<T>>;
|
|
947
|
+
disconnect(error?: Error): void;
|
|
675
948
|
close(): Promise<void>;
|
|
676
949
|
}
|
|
677
950
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
@@ -700,6 +973,10 @@ declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: Sess
|
|
|
700
973
|
* byte-for-byte identical to the pre-instance layout.
|
|
701
974
|
*/
|
|
702
975
|
declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
|
|
976
|
+
/** Last-line storage guard, shared by session-host and mesh persistence.
|
|
977
|
+
* Node's test runner propagates NODE_TEST_CONTEXT to children; Vitest marks
|
|
978
|
+
* its workers separately. Explicit temporary roots remain valid. */
|
|
979
|
+
declare function assertTestStorageIsolated(destination: string): void;
|
|
703
980
|
/**
|
|
704
981
|
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
705
982
|
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
@@ -749,6 +1026,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
749
1026
|
* with child CLI processes and apply terminal colour defaults.
|
|
750
1027
|
*/
|
|
751
1028
|
declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
|
|
1029
|
+
/** Recover only role bindings from legacy full-environment snapshots.
|
|
1030
|
+
* New records distinguish explicit overrides, including intentional custom keys. */
|
|
1031
|
+
declare function replayLaunchEnv(command: {
|
|
1032
|
+
env?: Record<string, string>;
|
|
1033
|
+
envMode?: 'launch_overrides';
|
|
1034
|
+
}): Record<string, string>;
|
|
752
1035
|
/**
|
|
753
1036
|
* Apply preferred terminal colour environment variables.
|
|
754
1037
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -781,11 +1064,28 @@ interface SessionHostSnapshot {
|
|
|
781
1064
|
*/
|
|
782
1065
|
interface SessionHostControlPlane {
|
|
783
1066
|
getDiagnostics(payload?: GetHostDiagnosticsPayload): Promise<SessionHostDiagnostics>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Authoritative host boot identity for idle inventory / cleanup expected CAS.
|
|
1069
|
+
* Prefers diagnostics.hostBootId (host SoT), else proves upgrade lease bootId
|
|
1070
|
+
* via get_upgrade_lease, else hs:<hostStartedAt> for non-upgrade / old hosts.
|
|
1071
|
+
* Ambiguous upgrade-lease failures fail closed (null) — never invent a UUID.
|
|
1072
|
+
*/
|
|
1073
|
+
resolveHostBootId(): Promise<string | null>;
|
|
784
1074
|
listSessions(): Promise<SessionHostRecord[]>;
|
|
785
1075
|
stopSession(sessionId: string): Promise<SessionHostRecord | null>;
|
|
1076
|
+
/** Host CAS stop: refuses without mutating when expected assignment/boot/incarnation drift. */
|
|
1077
|
+
stopSessionIfExpected(sessionId: string, expected: SessionCleanupExpectedAssignment): Promise<SessionHostRecord | null>;
|
|
786
1078
|
deleteSession(sessionId: string, opts?: {
|
|
787
1079
|
force?: boolean;
|
|
788
1080
|
}): Promise<SessionHostRecord | null>;
|
|
1081
|
+
/** Host CAS delete: refuses without mutating when expected assignment/boot/incarnation drift. */
|
|
1082
|
+
deleteSessionIfExpected(sessionId: string, expected: SessionCleanupExpectedAssignment, opts?: {
|
|
1083
|
+
force?: boolean;
|
|
1084
|
+
}): Promise<{
|
|
1085
|
+
sessionId: string;
|
|
1086
|
+
deleted: boolean;
|
|
1087
|
+
alreadyAbsent?: boolean;
|
|
1088
|
+
} | null>;
|
|
789
1089
|
resumeSession(sessionId: string): Promise<SessionHostRecord | null>;
|
|
790
1090
|
restartSession(sessionId: string): Promise<SessionHostRecord | null>;
|
|
791
1091
|
sendSignal(sessionId: string, signal: string): Promise<SessionHostRecord | null>;
|
|
@@ -824,4 +1124,4 @@ interface SessionHostControlTransport {
|
|
|
824
1124
|
*/
|
|
825
1125
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
826
1126
|
|
|
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 };
|
|
1127
|
+
export { type AcquireWritePayload, type AttachSessionPayload, CLEANUP_AFTER_STOP_SIDE_EFFECT_PREFIX, 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 DeleteSessionIfExpectedPayload, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, type NiceLaunch, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionCleanupExpectedAssignment, type SessionClientType, type SessionHostCategory, type SessionHostCensus, 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 StopSessionIfExpectedPayload, 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, hostBootIdFromStartedAt, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, niceLaunch, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, refuseCleanupExpectedDelete, refuseCleanupExpectedStop, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveHostBootId, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, stripCleanupAfterStopSideEffect, tagCleanupAfterStopSideEffect, validateSessionHostEndpoint, writeEnvelope };
|