@adhdev/session-host-core 1.0.82-rc.4 → 1.0.82-rc.40

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.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as os from 'node:os';
2
+ import { SpawnOptions, ChildProcess } from 'node:child_process';
1
3
  import * as net from 'net';
2
4
  export { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS, resolveSessionHostCols, resolveSessionHostRows } from './defaults.js';
3
5
 
@@ -10,6 +12,8 @@ interface SessionLaunchCommand {
10
12
  command: string;
11
13
  args: string[];
12
14
  env?: Record<string, string>;
15
+ /** Unmarked older daemon records contained the full inherited environment. */
16
+ envMode?: 'launch_overrides';
13
17
  }
14
18
  interface SessionWriteOwner {
15
19
  clientId: string;
@@ -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;
@@ -257,6 +347,13 @@ interface SessionHostDiagnostics {
257
347
  * must treat `undefined` as "unknown", never as a match.
258
348
  */
259
349
  hostEntryPath?: string;
350
+ /**
351
+ * Authoritative host boot identity used by cleanup expected-assignment CAS.
352
+ * Same value `stop_session_if_expected` refuses against: upgrade-lease bootId
353
+ * when the host was launched with a native upgrade binding, otherwise `hs:<hostStartedAt>`.
354
+ * Optional so older hosts omit it; callers must not invent an upgrade UUID.
355
+ */
356
+ hostBootId?: string;
260
357
  runtimeCount: number;
261
358
  supportedRequestTypes?: SessionHostRequestType[];
262
359
  sessions?: SessionHostRecord[];
@@ -267,27 +364,70 @@ interface SessionHostDiagnostics {
267
364
  recentRequests: SessionHostRequestTrace[];
268
365
  recentTransitions: SessionHostRuntimeTransition[];
269
366
  }
367
+ interface HostUpgradeLeasePayload {
368
+ bootId: string;
369
+ epoch: number;
370
+ owner: string;
371
+ token: string;
372
+ }
270
373
  type SessionHostRequest = {
374
+ type: 'get_upgrade_lease';
375
+ payload?: {};
376
+ } | {
377
+ type: 'acquire_upgrade_lease';
378
+ payload: HostUpgradeLeasePayload;
379
+ } | {
380
+ type: 'release_upgrade_lease';
381
+ payload: HostUpgradeLeasePayload;
382
+ } | {
271
383
  type: 'create_session';
272
384
  payload: CreateSessionPayload;
273
385
  } | {
274
386
  type: 'attach_session';
275
387
  payload: AttachSessionPayload;
388
+ } | {
389
+ type: 'attach_session_if_incarnation';
390
+ payload: AttachSessionPayload & {
391
+ expectedIncarnation: {
392
+ sessionId: string;
393
+ runtimeKey: string;
394
+ startedAt: number;
395
+ };
396
+ };
276
397
  } | {
277
398
  type: 'detach_session';
278
399
  payload: DetachSessionPayload;
279
400
  } | {
280
401
  type: 'send_input';
281
402
  payload: SendInputPayload;
403
+ } | {
404
+ type: 'send_input_if_seq';
405
+ payload: SendInputIfSeqPayload;
406
+ } | {
407
+ type: 'get_input_state';
408
+ payload: GetInputStatePayload;
282
409
  } | {
283
410
  type: 'resize_session';
284
411
  payload: ResizeSessionPayload;
285
412
  } | {
286
413
  type: 'stop_session';
287
414
  payload: StopSessionPayload;
415
+ }
416
+ /** Distinct kind: old hosts must refuse instead of stopping by session id alone. */
417
+ | {
418
+ type: 'stop_session_if_expected';
419
+ payload: StopSessionIfExpectedPayload;
420
+ } | {
421
+ type: 'stop_mesh_writer';
422
+ payload: StopMeshWriterPayload;
288
423
  } | {
289
424
  type: 'delete_session';
290
425
  payload: DeleteSessionPayload;
426
+ }
427
+ /** Distinct kind: old hosts must refuse instead of deleting by session id alone. */
428
+ | {
429
+ type: 'delete_session_if_expected';
430
+ payload: DeleteSessionIfExpectedPayload;
291
431
  } | {
292
432
  type: 'resume_session';
293
433
  payload: ResumeSessionPayload;
@@ -324,9 +464,21 @@ type SessionHostRequest = {
324
464
  } | {
325
465
  type: 'prune_duplicate_sessions';
326
466
  payload?: PruneDuplicateSessionsPayload;
467
+ } | {
468
+ type: 'get_session_census';
469
+ payload: {
470
+ sessionIds: string[];
471
+ };
472
+ } | {
473
+ type: 'get_session';
474
+ payload: {
475
+ sessionId: string;
476
+ };
327
477
  } | {
328
478
  type: 'list_sessions';
329
- payload?: {};
479
+ payload?: {
480
+ activeOnly?: boolean;
481
+ };
330
482
  };
331
483
  type SessionHostRequestType = SessionHostRequest['type'];
332
484
  declare const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[];
@@ -352,6 +504,14 @@ type SessionHostEvent = {
352
504
  sessionId: string;
353
505
  seq: number;
354
506
  data: string;
507
+ }
508
+ /** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
509
+ | {
510
+ type: 'session_input';
511
+ sessionId: string;
512
+ seq: number;
513
+ epoch: string;
514
+ clientId: string;
355
515
  } | {
356
516
  type: 'session_cleared';
357
517
  sessionId: string;
@@ -410,6 +570,34 @@ interface SessionHostEventEnvelope {
410
570
  }
411
571
  type SessionHostWireEnvelope = SessionHostRequestEnvelope | SessionHostResponseEnvelope | SessionHostEventEnvelope;
412
572
 
573
+ /** Shared cleanup expected-assignment / host-boot helpers (daemon + host). */
574
+
575
+ /**
576
+ * Prefix on delete_session_if_expected refusals after runtime.stop was requested.
577
+ * Client durable fences must not abort on these — the writer may already be dying.
578
+ * Before-action refusals keep the bare CLEANUP_HOST_REFUSAL_CODES (abort-safe proof).
579
+ */
580
+ declare const CLEANUP_AFTER_STOP_SIDE_EFFECT_PREFIX = "cleanup_after_stop_side_effect:";
581
+ declare function tagCleanupAfterStopSideEffect(code: string): string;
582
+ declare function stripCleanupAfterStopSideEffect(raw: string): {
583
+ afterStop: boolean;
584
+ code: string;
585
+ };
586
+ declare function hostBootIdFromStartedAt(hostStartedAt: number): string;
587
+ declare function resolveHostBootId(opts: {
588
+ upgradeBootId?: string | null;
589
+ hostStartedAt: number;
590
+ }): string | null;
591
+ /** Sanitized refusal codes only — never echo assignment contents. */
592
+ declare function refuseCleanupExpectedStop(record: SessionHostRecord | null | undefined, expected: SessionCleanupExpectedAssignment, currentHostBootId: string | null, hasRuntime: boolean): string | null;
593
+ /**
594
+ * Delete CAS: same identity/assignment proof as stop. A replaced incarnation or a
595
+ * newly bound writer must survive — never delete a record that no longer matches
596
+ * the captured expected tuple. `force` is required to stop a still-live runtime
597
+ * before deleting that exact incarnation.
598
+ */
599
+ declare function refuseCleanupExpectedDelete(record: SessionHostRecord | null | undefined, expected: SessionCleanupExpectedAssignment, currentHostBootId: string | null, hasRuntime: boolean, force: boolean): string | null;
600
+
413
601
  interface ClassifyTerminationInput {
414
602
  exitCode: number | null;
415
603
  signal?: number | null;
@@ -434,6 +622,62 @@ interface ClassifyTerminationInput {
434
622
  */
435
623
  declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
436
624
 
625
+ /** Relative POSIX niceness adjustment for newly spawned agent workloads. */
626
+ declare const CLI_CHILD_NICE_INCREMENT = 10;
627
+ /** Set to "0" in the daemon environment (or launch env) to disable lowering. */
628
+ declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
629
+ /** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
630
+ declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
631
+ declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
632
+ interface NiceLaunch {
633
+ readonly command: string;
634
+ readonly args: string[];
635
+ /** True when the child will START at the lowered priority (spawnCliChild must not lower it again). */
636
+ readonly preApplied: boolean;
637
+ }
638
+ /**
639
+ * Launch through `nice -n <increment>` on macOS/Linux so the child runs at the
640
+ * lowered priority from its first instruction. `nice` execs the target in
641
+ * place: same pid, and every descendant inherits the niceness. This closes the
642
+ * spawn→setPriority race where a child forked before the post-spawn call and
643
+ * its early descendants escaped at NI=0. Windows (no nice) and shell-string
644
+ * launches keep the post-spawn path.
645
+ */
646
+ declare function niceLaunch(command: string, args: readonly string[], env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, niceAvailable?: () => boolean): NiceLaunch;
647
+ interface PriorityDependencies {
648
+ platform: NodeJS.Platform;
649
+ getPriority: typeof os.getPriority;
650
+ setPriority: typeof os.setPriority;
651
+ setDarwinBackground?: typeof setDarwinBackground;
652
+ }
653
+ /** Separate policy instances are useful for platform/error tests. */
654
+ declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
655
+ readonly pid?: number;
656
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
657
+ preApplied?: boolean;
658
+ }) => T;
659
+ /**
660
+ * Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
661
+ * workers, version probes and git helpers at their existing priority.
662
+ *
663
+ * node-pty has no pre-spawn priority hook. Apply immediately on return, before
664
+ * registering listeners/doing other work. There is a spawn-to-setPriority race:
665
+ * a child can run (and fork) before this call. Later descendants inherit nice
666
+ * on POSIX; early descendants are not retroactively changed. Windows creation
667
+ * and ConPTY inheritance require verification on the DesktopA.
668
+ * Optional darwin-bg is applied asynchronously by taskpolicy after nice; the
669
+ * extra helper startup adds a further race before the background class takes
670
+ * effect. It also throttles I/O, so nice alone remains the default.
671
+ */
672
+ declare const spawnCliChild: <T extends {
673
+ readonly pid?: number;
674
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
675
+ preApplied?: boolean;
676
+ }) => T;
677
+
678
+ /** Shared hidden-window primitive for daemon and session-host process helpers. */
679
+ declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
680
+
437
681
  interface SessionRingBufferOptions {
438
682
  maxBytes?: number;
439
683
  }
@@ -501,15 +745,37 @@ declare class SessionRingBuffer {
501
745
 
502
746
  declare class SessionHostRegistry {
503
747
  private sessions;
748
+ /** This registry's lifetime; every inputEpoch it mints starts with it. */
749
+ private readonly lifetimeId;
750
+ private epochCounter;
751
+ private mintInputEpoch;
504
752
  createSession(payload: CreateSessionPayload): SessionHostRecord;
505
753
  restoreSession(record: SessionHostRecord, snapshot?: {
506
754
  seq: number;
507
755
  text: string;
508
756
  } | null): SessionHostRecord;
757
+ /** Census projection: omit launch arguments/environment and summarize stopped
758
+ * sessions. Full details remain available through getSession. */
759
+ listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
509
760
  listSessions(): SessionHostRecord[];
761
+ /** No launch bodies are cloned. Unknown role evidence stays conservative. */
762
+ getSessionCensus(sessionIds: string[]): {
763
+ liveSessionIds: string[];
764
+ hasOtherAssistantCandidates: boolean;
765
+ };
510
766
  getSession(sessionId: string): SessionHostRecord | null;
767
+ attachClientIfIncarnation(payload: Extract<SessionHostRequest, {
768
+ type: 'attach_session_if_incarnation';
769
+ }>['payload']): SessionHostRecord;
511
770
  attachClient(payload: AttachSessionPayload): SessionHostRecord;
512
771
  detachClient(payload: DetachSessionPayload): SessionHostRecord;
772
+ /** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
773
+ recordInput(sessionId: string): number;
774
+ /** The current input counter (see SessionHostInputState). */
775
+ getInputState(sessionId: string): {
776
+ inputSeq: number;
777
+ inputEpoch: string;
778
+ };
513
779
  acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
514
780
  releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
515
781
  appendOutput(sessionId: string, data: string): {
@@ -563,6 +829,8 @@ interface SessionHostEndpoint {
563
829
  kind: 'unix' | 'pipe';
564
830
  path: string;
565
831
  }
832
+ /** Reserve the trailing NUL in sockaddr_un; named pipes have a separate namespace. */
833
+ declare function validateSessionHostEndpoint(endpoint: SessionHostEndpoint, platform?: NodeJS.Platform): void;
566
834
  interface SessionHostEndpointOptions {
567
835
  /**
568
836
  * Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
@@ -572,6 +840,8 @@ interface SessionHostEndpointOptions {
572
840
  ipcKey?: string;
573
841
  /** Test seam: override the platform the endpoint shape is derived for. */
574
842
  platform?: NodeJS.Platform;
843
+ /** Test seam: override the temporary directory used for endpoint derivation. */
844
+ tmpDir?: string;
575
845
  }
576
846
  declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
577
847
  /**
@@ -606,6 +876,9 @@ declare function createLineParser<TEnvelope = SessionHostWireEnvelope>(onEnvelop
606
876
  interface SessionHostClientOptions {
607
877
  endpoint?: SessionHostEndpoint;
608
878
  appName?: string;
879
+ requestTimeoutMs?: number;
880
+ /** Join the shared client registry (default true). Disable for short-lived probes. */
881
+ registerAsShared?: boolean;
609
882
  }
610
883
  /**
611
884
  * Why an established session-host connection went away.
@@ -614,6 +887,8 @@ interface SessionHostClientOptions {
614
887
  * - `closed` — socket fully closed ('close') without a preceding error/end
615
888
  */
616
889
  type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
890
+ declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
891
+ declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
617
892
  interface SessionHostDisconnectInfo {
618
893
  reason: SessionHostDisconnectReason;
619
894
  endpointPath: string;
@@ -634,12 +909,19 @@ interface SessionHostDisconnectInfo {
634
909
  declare class SessionHostClient {
635
910
  readonly endpoint: SessionHostEndpoint;
636
911
  private socket;
912
+ private connectPromise;
913
+ private requestTimeoutMs;
637
914
  private requestWaiters;
638
915
  private eventListeners;
639
916
  private disconnectListeners;
640
917
  /** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
641
918
  private disconnectedSockets;
919
+ /** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
920
+ private attachedSessions;
642
921
  constructor(options?: SessionHostClientOptions);
922
+ static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
923
+ static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
924
+ isConnected(): boolean;
643
925
  /**
644
926
  * Fires when an established connection to the session host goes away.
645
927
  *
@@ -654,9 +936,13 @@ declare class SessionHostClient {
654
936
  */
655
937
  onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
656
938
  private handleDisconnect;
657
- connect(): Promise<void>;
939
+ private sendRawRequestOnSocket;
940
+ connect(timeoutMs?: number): Promise<void>;
658
941
  onEvent(listener: (event: SessionHostEvent) => void): () => void;
659
- request<T = unknown>(request: SessionHostRequest): Promise<SessionHostResponse<T>>;
942
+ request<T = unknown>(request: SessionHostRequest, options?: {
943
+ timeoutMs?: number;
944
+ }): Promise<SessionHostResponse<T>>;
945
+ disconnect(error?: Error): void;
660
946
  close(): Promise<void>;
661
947
  }
662
948
  declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
@@ -685,6 +971,10 @@ declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: Sess
685
971
  * byte-for-byte identical to the pre-instance layout.
686
972
  */
687
973
  declare const DEFAULT_CONFIG_DIR_NAME = ".adhdev";
974
+ /** Last-line storage guard, shared by session-host and mesh persistence.
975
+ * Node's test runner propagates NODE_TEST_CONTEXT to children; Vitest marks
976
+ * its workers separately. Explicit temporary roots remain valid. */
977
+ declare function assertTestStorageIsolated(destination: string): void;
688
978
  /**
689
979
  * Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
690
980
  * when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
@@ -734,6 +1024,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
734
1024
  * with child CLI processes and apply terminal colour defaults.
735
1025
  */
736
1026
  declare function sanitizeSpawnEnv(baseEnv: NodeJS.ProcessEnv, overrides?: Record<string, string>): Record<string, string>;
1027
+ /** Recover only role bindings from legacy full-environment snapshots.
1028
+ * New records distinguish explicit overrides, including intentional custom keys. */
1029
+ declare function replayLaunchEnv(command: {
1030
+ env?: Record<string, string>;
1031
+ envMode?: 'launch_overrides';
1032
+ }): Record<string, string>;
737
1033
  /**
738
1034
  * Apply preferred terminal colour environment variables.
739
1035
  * Ensures TERM is set to xterm-256color and enables colour on Windows.
@@ -766,11 +1062,28 @@ interface SessionHostSnapshot {
766
1062
  */
767
1063
  interface SessionHostControlPlane {
768
1064
  getDiagnostics(payload?: GetHostDiagnosticsPayload): Promise<SessionHostDiagnostics>;
1065
+ /**
1066
+ * Authoritative host boot identity for idle inventory / cleanup expected CAS.
1067
+ * Prefers diagnostics.hostBootId (host SoT), else proves upgrade lease bootId
1068
+ * via get_upgrade_lease, else hs:<hostStartedAt> for non-upgrade / old hosts.
1069
+ * Ambiguous upgrade-lease failures fail closed (null) — never invent a UUID.
1070
+ */
1071
+ resolveHostBootId(): Promise<string | null>;
769
1072
  listSessions(): Promise<SessionHostRecord[]>;
770
1073
  stopSession(sessionId: string): Promise<SessionHostRecord | null>;
1074
+ /** Host CAS stop: refuses without mutating when expected assignment/boot/incarnation drift. */
1075
+ stopSessionIfExpected(sessionId: string, expected: SessionCleanupExpectedAssignment): Promise<SessionHostRecord | null>;
771
1076
  deleteSession(sessionId: string, opts?: {
772
1077
  force?: boolean;
773
1078
  }): Promise<SessionHostRecord | null>;
1079
+ /** Host CAS delete: refuses without mutating when expected assignment/boot/incarnation drift. */
1080
+ deleteSessionIfExpected(sessionId: string, expected: SessionCleanupExpectedAssignment, opts?: {
1081
+ force?: boolean;
1082
+ }): Promise<{
1083
+ sessionId: string;
1084
+ deleted: boolean;
1085
+ alreadyAbsent?: boolean;
1086
+ } | null>;
774
1087
  resumeSession(sessionId: string): Promise<SessionHostRecord | null>;
775
1088
  restartSession(sessionId: string): Promise<SessionHostRecord | null>;
776
1089
  sendSignal(sessionId: string, signal: string): Promise<SessionHostRecord | null>;
@@ -809,4 +1122,4 @@ interface SessionHostControlTransport {
809
1122
  */
810
1123
  declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
811
1124
 
812
- export { type AcquireWritePayload, type AttachSessionPayload, type ClearSessionBufferPayload, type CreateSessionPayload, DEFAULT_CONFIG_DIR_NAME, DEFAULT_SESSION_RING_BUFFER_MAX_BYTES, type DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type PruneDuplicateSessionsPayload, type ReleaseWritePayload, type ResizeSessionPayload, type RestartSessionPayload, type ResumeSessionPayload, SESSION_HOST_SUPPORTED_REQUEST_TYPES, type SendInputPayload, type SendSignalPayload, type SessionAttachedClient, type SessionBufferSnapshot, type SessionClientType, type SessionHostCategory, SessionHostClient, type SessionHostClientOptions, type SessionHostControlPlane, type SessionHostControlTransport, type SessionHostDiagnostics, type SessionHostDisconnectInfo, type SessionHostDisconnectReason, type SessionHostDuplicateSessionGroup, type SessionHostEndpoint, type SessionHostEndpointOptions, type SessionHostEvent, type SessionHostEventEnvelope, type SessionHostLogEntry, type SessionHostPruneDuplicatesResult, type SessionHostRecord, SessionHostRegistry, type SessionHostRequest, type SessionHostRequestEnvelope, type SessionHostRequestTrace, type SessionHostRequestType, type SessionHostResponse, type SessionHostResponseEnvelope, type SessionHostRuntimeTransition, type SessionHostSnapshot, type SessionHostSurfaceKind, type SessionHostSurfaceRecordLike, type SessionHostWireEnvelope, type SessionLaunchCommand, type SessionLifecycle, type SessionOwnerType, SessionRingBuffer, type SessionRingBufferOptions, type SessionTerminalSnapshot, type SessionTerminalState, type SessionTermination, type SessionTransport, type SessionWriteOwner, type StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createLineParser, createResponseEnvelope, createSessionHostControlPlane, ensureNodePtySpawnHelperPermissions, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, writeEnvelope };
1125
+ 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 };