@adhdev/session-host-core 1.0.82-rc.12 → 1.0.82-rc.120

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/src/types.ts CHANGED
@@ -12,6 +12,8 @@ export interface SessionLaunchCommand {
12
12
  command: string;
13
13
  args: string[];
14
14
  env?: Record<string, string>;
15
+ /** Unmarked older daemon records contained the full inherited environment. */
16
+ envMode?: 'launch_overrides';
15
17
  }
16
18
 
17
19
  export interface SessionWriteOwner {
@@ -111,6 +113,21 @@ export interface SessionHostRecord {
111
113
  meta: Record<string, unknown>;
112
114
  /** Termination tombstone, stamped when the PTY process exits. Retained for post-mortem inspection. */
113
115
  termination?: SessionTermination;
116
+ /**
117
+ * Monotonic count of input accepted into this runtime by `send_input`, from
118
+ * any client (SUBMIT-UNCONFIRMED-RECLAIM: the authoritative input boundary).
119
+ * Every accepted input is also announced as a `session_input` event carrying
120
+ * this number and the writer. Absent on records from a host that predates it
121
+ * — a reader must then treat input provenance as unknown.
122
+ */
123
+ inputSeq?: number;
124
+ /**
125
+ * Identifies one lifetime of `inputSeq`. It changes whenever the counter
126
+ * could have restarted or been rewound — a new host process loading the
127
+ * record, or a restore with a lower count — so equal (epoch, seq) pairs
128
+ * really are the same point in the input stream.
129
+ */
130
+ inputEpoch?: string;
114
131
  }
115
132
 
116
133
  export interface CreateSessionPayload {
@@ -146,6 +163,29 @@ export interface SendInputPayload {
146
163
  data: string;
147
164
  }
148
165
 
166
+ /**
167
+ * `send_input_if_seq`: write `data` only if NOTHING else has been input since
168
+ * the caller last accounted the stream — the host's (inputEpoch, inputSeq) is
169
+ * still exactly (expectedInputEpoch, expectedInputSeq) — and the caller may
170
+ * write without taking ownership (no force). Atomic on the host, so no input
171
+ * can slip between the caller's check and this write.
172
+ */
173
+ export interface SendInputIfSeqPayload extends SendInputPayload {
174
+ expectedInputSeq: number;
175
+ expectedInputEpoch: string;
176
+ }
177
+
178
+ export interface GetInputStatePayload {
179
+ sessionId: string;
180
+ }
181
+
182
+ /** `get_input_state`: the host's current input counter. A host without it
183
+ * rejects the request type, which is how a client knows not to trust. */
184
+ export interface SessionHostInputState {
185
+ inputSeq: number;
186
+ inputEpoch: string;
187
+ }
188
+
149
189
  export interface ResizeSessionPayload {
150
190
  sessionId: string;
151
191
  cols: number;
@@ -155,12 +195,48 @@ export interface ResizeSessionPayload {
155
195
  export interface StopSessionPayload {
156
196
  sessionId: string;
157
197
  }
198
+ /**
199
+ * Expected logical + physical identity for a cleanup stop. Captured before any
200
+ * async host RPC and re-checked inside the host stop critical section.
201
+ * All of taskId/attemptId/generation/dispatchNonce null means expected unbound
202
+ * (no meshActiveAssignment) so a later claim cannot be stopped by stale cleanup.
203
+ */
204
+ export interface SessionCleanupExpectedAssignment {
205
+ sessionId: string;
206
+ hostBootId: string;
207
+ runtimeKey: string;
208
+ startedAt: number;
209
+ taskId: string | null;
210
+ attemptId: string | null;
211
+ generation: number | null;
212
+ dispatchNonce: number | null;
213
+ }
214
+ export interface StopSessionIfExpectedPayload {
215
+ sessionId: string;
216
+ expected: SessionCleanupExpectedAssignment;
217
+ }
218
+ export interface MeshWriterAssignment {
219
+ meshId: string; nodeId: string; taskId: string; attemptId: string;
220
+ generation: number; dispatchNonce: number; ownerDaemonId: string;
221
+ }
222
+ export interface MeshWriterStopTarget {
223
+ runtimeKey: string; startedAt: number; osPid: number; providerType: string;
224
+ assignment: MeshWriterAssignment;
225
+ }
226
+ export interface StopMeshWriterPayload extends MeshWriterStopTarget { sessionId: string; clientId: string }
158
227
 
159
228
  export interface DeleteSessionPayload {
160
229
  sessionId: string;
161
230
  /** Stop a live runtime before deleting the persisted record. */
162
231
  force?: boolean;
163
232
  }
233
+ /** Expected identity for record deletion; old hosts must refuse this distinct kind. */
234
+ export interface DeleteSessionIfExpectedPayload {
235
+ sessionId: string;
236
+ expected: SessionCleanupExpectedAssignment;
237
+ /** Stop the matching live runtime before deleting that exact incarnation. */
238
+ force?: boolean;
239
+ }
164
240
 
165
241
  export interface ResumeSessionPayload {
166
242
  sessionId: string;
@@ -197,6 +273,17 @@ export interface UpdateSessionMetaPayload {
197
273
  replace?: boolean;
198
274
  }
199
275
 
276
+ /** Bounded liveness check for identities whose provenance the caller already holds.
277
+ * No launch arguments, metadata, snapshots or diagnostic log bodies cross IPC. */
278
+ export interface SessionHostCensus {
279
+ hostStartedAt: number;
280
+ endpoint: string;
281
+ hostEntryPath?: string;
282
+ liveSessionIds: string[];
283
+ /** A live role-marked writer outside the caller's persisted identities. */
284
+ hasOtherAssistantCandidates: boolean;
285
+ }
286
+
200
287
  export interface GetHostDiagnosticsPayload {
201
288
  includeSessions?: boolean;
202
289
  limit?: number;
@@ -270,6 +357,8 @@ export interface SessionHostRuntimeTransition {
270
357
  export interface SessionHostDiagnostics {
271
358
  hostStartedAt: number;
272
359
  endpoint: string;
360
+ /** Descriptors this host holds open; undefined where it cannot be counted. A count far above the live runtimes means a leak. */
361
+ openFdCount?: number;
273
362
  /**
274
363
  * Absolute path of the script this host process is running (its own
275
364
  * `__filename`), self-reported.
@@ -287,6 +376,13 @@ export interface SessionHostDiagnostics {
287
376
  * must treat `undefined` as "unknown", never as a match.
288
377
  */
289
378
  hostEntryPath?: string;
379
+ /**
380
+ * Authoritative host boot identity used by cleanup expected-assignment CAS.
381
+ * Same value `stop_session_if_expected` refuses against: upgrade-lease bootId
382
+ * when the host was launched with a native upgrade binding, otherwise `hs:<hostStartedAt>`.
383
+ * Optional so older hosts omit it; callers must not invent an upgrade UUID.
384
+ */
385
+ hostBootId?: string;
290
386
  runtimeCount: number;
291
387
  supportedRequestTypes?: SessionHostRequestType[];
292
388
  sessions?: SessionHostRecord[];
@@ -298,14 +394,32 @@ export interface SessionHostDiagnostics {
298
394
  recentTransitions: SessionHostRuntimeTransition[];
299
395
  }
300
396
 
397
+ export interface HostUpgradeLeasePayload {
398
+ bootId: string;
399
+ epoch: number;
400
+ owner: string;
401
+ token: string;
402
+ }
403
+
301
404
  export type SessionHostRequest =
405
+ | { type: 'get_upgrade_lease'; payload?: {} }
406
+ | { type: 'acquire_upgrade_lease'; payload: HostUpgradeLeasePayload }
407
+ | { type: 'release_upgrade_lease'; payload: HostUpgradeLeasePayload }
302
408
  | { type: 'create_session'; payload: CreateSessionPayload }
303
409
  | { type: 'attach_session'; payload: AttachSessionPayload }
410
+ | { type: 'attach_session_if_incarnation'; payload: AttachSessionPayload & { expectedIncarnation: { sessionId: string; runtimeKey: string; startedAt: number } } }
304
411
  | { type: 'detach_session'; payload: DetachSessionPayload }
305
412
  | { type: 'send_input'; payload: SendInputPayload }
413
+ | { type: 'send_input_if_seq'; payload: SendInputIfSeqPayload }
414
+ | { type: 'get_input_state'; payload: GetInputStatePayload }
306
415
  | { type: 'resize_session'; payload: ResizeSessionPayload }
307
416
  | { type: 'stop_session'; payload: StopSessionPayload }
417
+ /** Distinct kind: old hosts must refuse instead of stopping by session id alone. */
418
+ | { type: 'stop_session_if_expected'; payload: StopSessionIfExpectedPayload }
419
+ | { type: 'stop_mesh_writer'; payload: StopMeshWriterPayload }
308
420
  | { type: 'delete_session'; payload: DeleteSessionPayload }
421
+ /** Distinct kind: old hosts must refuse instead of deleting by session id alone. */
422
+ | { type: 'delete_session_if_expected'; payload: DeleteSessionIfExpectedPayload }
309
423
  | { type: 'resume_session'; payload: ResumeSessionPayload }
310
424
  | { type: 'acquire_write'; payload: AcquireWritePayload }
311
425
  | { type: 'release_write'; payload: ReleaseWritePayload }
@@ -318,18 +432,30 @@ export type SessionHostRequest =
318
432
  | { type: 'send_signal'; payload: SendSignalPayload }
319
433
  | { type: 'restart_session'; payload: RestartSessionPayload }
320
434
  | { type: 'prune_duplicate_sessions'; payload?: PruneDuplicateSessionsPayload }
321
- | { type: 'list_sessions'; payload?: {} };
435
+ | { type: 'get_session_census'; payload: { sessionIds: string[] } }
436
+ | { type: 'get_session'; payload: { sessionId: string } }
437
+ | { type: 'list_sessions'; payload?: { activeOnly?: boolean } };
322
438
 
323
439
  export type SessionHostRequestType = SessionHostRequest['type'];
324
440
 
325
441
  export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[] = [
442
+ 'get_upgrade_lease',
443
+ 'acquire_upgrade_lease',
444
+ 'release_upgrade_lease',
326
445
  'create_session',
327
446
  'attach_session',
447
+ // Distinct request kind: old hosts must refuse instead of ignoring a pin.
448
+ 'attach_session_if_incarnation',
328
449
  'detach_session',
329
450
  'send_input',
451
+ 'send_input_if_seq',
452
+ 'get_input_state',
330
453
  'resize_session',
331
454
  'stop_session',
455
+ 'stop_session_if_expected',
456
+ 'stop_mesh_writer',
332
457
  'delete_session',
458
+ 'delete_session_if_expected',
333
459
  'resume_session',
334
460
  'acquire_write',
335
461
  'release_write',
@@ -342,6 +468,8 @@ export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestTy
342
468
  'send_signal',
343
469
  'restart_session',
344
470
  'prune_duplicate_sessions',
471
+ 'get_session_census',
472
+ 'get_session',
345
473
  'list_sessions',
346
474
  ];
347
475
 
@@ -356,6 +484,8 @@ export type SessionHostEvent =
356
484
  | { type: 'session_started'; sessionId: string; pid?: number }
357
485
  | { type: 'session_resumed'; sessionId: string; pid?: number }
358
486
  | { type: 'session_output'; sessionId: string; seq: number; data: string }
487
+ /** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
488
+ | { type: 'session_input'; sessionId: string; seq: number; epoch: string; clientId: string }
359
489
  | { type: 'session_cleared'; sessionId: string }
360
490
  | { type: 'session_exit'; sessionId: string; exitCode: number | null; signal?: number | null; termination?: SessionTermination }
361
491
  | { type: 'session_stopped'; sessionId: string }