@adhdev/session-host-core 1.0.82-rc.13 → 1.0.82-rc.130
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/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[];
|
|
@@ -311,11 +407,19 @@ export type SessionHostRequest =
|
|
|
311
407
|
| { type: 'release_upgrade_lease'; payload: HostUpgradeLeasePayload }
|
|
312
408
|
| { type: 'create_session'; payload: CreateSessionPayload }
|
|
313
409
|
| { type: 'attach_session'; payload: AttachSessionPayload }
|
|
410
|
+
| { type: 'attach_session_if_incarnation'; payload: AttachSessionPayload & { expectedIncarnation: { sessionId: string; runtimeKey: string; startedAt: number } } }
|
|
314
411
|
| { type: 'detach_session'; payload: DetachSessionPayload }
|
|
315
412
|
| { type: 'send_input'; payload: SendInputPayload }
|
|
413
|
+
| { type: 'send_input_if_seq'; payload: SendInputIfSeqPayload }
|
|
414
|
+
| { type: 'get_input_state'; payload: GetInputStatePayload }
|
|
316
415
|
| { type: 'resize_session'; payload: ResizeSessionPayload }
|
|
317
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 }
|
|
318
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 }
|
|
319
423
|
| { type: 'resume_session'; payload: ResumeSessionPayload }
|
|
320
424
|
| { type: 'acquire_write'; payload: AcquireWritePayload }
|
|
321
425
|
| { type: 'release_write'; payload: ReleaseWritePayload }
|
|
@@ -328,7 +432,9 @@ export type SessionHostRequest =
|
|
|
328
432
|
| { type: 'send_signal'; payload: SendSignalPayload }
|
|
329
433
|
| { type: 'restart_session'; payload: RestartSessionPayload }
|
|
330
434
|
| { type: 'prune_duplicate_sessions'; payload?: PruneDuplicateSessionsPayload }
|
|
331
|
-
| { type: '
|
|
435
|
+
| { type: 'get_session_census'; payload: { sessionIds: string[] } }
|
|
436
|
+
| { type: 'get_session'; payload: { sessionId: string } }
|
|
437
|
+
| { type: 'list_sessions'; payload?: { activeOnly?: boolean } };
|
|
332
438
|
|
|
333
439
|
export type SessionHostRequestType = SessionHostRequest['type'];
|
|
334
440
|
|
|
@@ -338,11 +444,18 @@ export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestTy
|
|
|
338
444
|
'release_upgrade_lease',
|
|
339
445
|
'create_session',
|
|
340
446
|
'attach_session',
|
|
447
|
+
// Distinct request kind: old hosts must refuse instead of ignoring a pin.
|
|
448
|
+
'attach_session_if_incarnation',
|
|
341
449
|
'detach_session',
|
|
342
450
|
'send_input',
|
|
451
|
+
'send_input_if_seq',
|
|
452
|
+
'get_input_state',
|
|
343
453
|
'resize_session',
|
|
344
454
|
'stop_session',
|
|
455
|
+
'stop_session_if_expected',
|
|
456
|
+
'stop_mesh_writer',
|
|
345
457
|
'delete_session',
|
|
458
|
+
'delete_session_if_expected',
|
|
346
459
|
'resume_session',
|
|
347
460
|
'acquire_write',
|
|
348
461
|
'release_write',
|
|
@@ -355,6 +468,8 @@ export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestTy
|
|
|
355
468
|
'send_signal',
|
|
356
469
|
'restart_session',
|
|
357
470
|
'prune_duplicate_sessions',
|
|
471
|
+
'get_session_census',
|
|
472
|
+
'get_session',
|
|
358
473
|
'list_sessions',
|
|
359
474
|
];
|
|
360
475
|
|
|
@@ -369,6 +484,8 @@ export type SessionHostEvent =
|
|
|
369
484
|
| { type: 'session_started'; sessionId: string; pid?: number }
|
|
370
485
|
| { type: 'session_resumed'; sessionId: string; pid?: number }
|
|
371
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 }
|
|
372
489
|
| { type: 'session_cleared'; sessionId: string }
|
|
373
490
|
| { type: 'session_exit'; sessionId: string; exitCode: number | null; signal?: number | null; termination?: SessionTermination }
|
|
374
491
|
| { type: 'session_stopped'; sessionId: string }
|