@adhdev/session-host-core 1.0.82-rc.5 → 1.0.82-rc.51
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 +317 -4
- package/dist/index.d.ts +317 -4
- package/dist/index.js +596 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +577 -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 +24 -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 +129 -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;
|
|
@@ -287,6 +374,13 @@ export interface SessionHostDiagnostics {
|
|
|
287
374
|
* must treat `undefined` as "unknown", never as a match.
|
|
288
375
|
*/
|
|
289
376
|
hostEntryPath?: string;
|
|
377
|
+
/**
|
|
378
|
+
* Authoritative host boot identity used by cleanup expected-assignment CAS.
|
|
379
|
+
* Same value `stop_session_if_expected` refuses against: upgrade-lease bootId
|
|
380
|
+
* when the host was launched with a native upgrade binding, otherwise `hs:<hostStartedAt>`.
|
|
381
|
+
* Optional so older hosts omit it; callers must not invent an upgrade UUID.
|
|
382
|
+
*/
|
|
383
|
+
hostBootId?: string;
|
|
290
384
|
runtimeCount: number;
|
|
291
385
|
supportedRequestTypes?: SessionHostRequestType[];
|
|
292
386
|
sessions?: SessionHostRecord[];
|
|
@@ -298,14 +392,32 @@ export interface SessionHostDiagnostics {
|
|
|
298
392
|
recentTransitions: SessionHostRuntimeTransition[];
|
|
299
393
|
}
|
|
300
394
|
|
|
395
|
+
export interface HostUpgradeLeasePayload {
|
|
396
|
+
bootId: string;
|
|
397
|
+
epoch: number;
|
|
398
|
+
owner: string;
|
|
399
|
+
token: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
301
402
|
export type SessionHostRequest =
|
|
403
|
+
| { type: 'get_upgrade_lease'; payload?: {} }
|
|
404
|
+
| { type: 'acquire_upgrade_lease'; payload: HostUpgradeLeasePayload }
|
|
405
|
+
| { type: 'release_upgrade_lease'; payload: HostUpgradeLeasePayload }
|
|
302
406
|
| { type: 'create_session'; payload: CreateSessionPayload }
|
|
303
407
|
| { type: 'attach_session'; payload: AttachSessionPayload }
|
|
408
|
+
| { type: 'attach_session_if_incarnation'; payload: AttachSessionPayload & { expectedIncarnation: { sessionId: string; runtimeKey: string; startedAt: number } } }
|
|
304
409
|
| { type: 'detach_session'; payload: DetachSessionPayload }
|
|
305
410
|
| { type: 'send_input'; payload: SendInputPayload }
|
|
411
|
+
| { type: 'send_input_if_seq'; payload: SendInputIfSeqPayload }
|
|
412
|
+
| { type: 'get_input_state'; payload: GetInputStatePayload }
|
|
306
413
|
| { type: 'resize_session'; payload: ResizeSessionPayload }
|
|
307
414
|
| { type: 'stop_session'; payload: StopSessionPayload }
|
|
415
|
+
/** Distinct kind: old hosts must refuse instead of stopping by session id alone. */
|
|
416
|
+
| { type: 'stop_session_if_expected'; payload: StopSessionIfExpectedPayload }
|
|
417
|
+
| { type: 'stop_mesh_writer'; payload: StopMeshWriterPayload }
|
|
308
418
|
| { type: 'delete_session'; payload: DeleteSessionPayload }
|
|
419
|
+
/** Distinct kind: old hosts must refuse instead of deleting by session id alone. */
|
|
420
|
+
| { type: 'delete_session_if_expected'; payload: DeleteSessionIfExpectedPayload }
|
|
309
421
|
| { type: 'resume_session'; payload: ResumeSessionPayload }
|
|
310
422
|
| { type: 'acquire_write'; payload: AcquireWritePayload }
|
|
311
423
|
| { type: 'release_write'; payload: ReleaseWritePayload }
|
|
@@ -318,18 +430,30 @@ export type SessionHostRequest =
|
|
|
318
430
|
| { type: 'send_signal'; payload: SendSignalPayload }
|
|
319
431
|
| { type: 'restart_session'; payload: RestartSessionPayload }
|
|
320
432
|
| { type: 'prune_duplicate_sessions'; payload?: PruneDuplicateSessionsPayload }
|
|
321
|
-
| { type: '
|
|
433
|
+
| { type: 'get_session_census'; payload: { sessionIds: string[] } }
|
|
434
|
+
| { type: 'get_session'; payload: { sessionId: string } }
|
|
435
|
+
| { type: 'list_sessions'; payload?: { activeOnly?: boolean } };
|
|
322
436
|
|
|
323
437
|
export type SessionHostRequestType = SessionHostRequest['type'];
|
|
324
438
|
|
|
325
439
|
export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[] = [
|
|
440
|
+
'get_upgrade_lease',
|
|
441
|
+
'acquire_upgrade_lease',
|
|
442
|
+
'release_upgrade_lease',
|
|
326
443
|
'create_session',
|
|
327
444
|
'attach_session',
|
|
445
|
+
// Distinct request kind: old hosts must refuse instead of ignoring a pin.
|
|
446
|
+
'attach_session_if_incarnation',
|
|
328
447
|
'detach_session',
|
|
329
448
|
'send_input',
|
|
449
|
+
'send_input_if_seq',
|
|
450
|
+
'get_input_state',
|
|
330
451
|
'resize_session',
|
|
331
452
|
'stop_session',
|
|
453
|
+
'stop_session_if_expected',
|
|
454
|
+
'stop_mesh_writer',
|
|
332
455
|
'delete_session',
|
|
456
|
+
'delete_session_if_expected',
|
|
333
457
|
'resume_session',
|
|
334
458
|
'acquire_write',
|
|
335
459
|
'release_write',
|
|
@@ -342,6 +466,8 @@ export const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestTy
|
|
|
342
466
|
'send_signal',
|
|
343
467
|
'restart_session',
|
|
344
468
|
'prune_duplicate_sessions',
|
|
469
|
+
'get_session_census',
|
|
470
|
+
'get_session',
|
|
345
471
|
'list_sessions',
|
|
346
472
|
];
|
|
347
473
|
|
|
@@ -356,6 +482,8 @@ export type SessionHostEvent =
|
|
|
356
482
|
| { type: 'session_started'; sessionId: string; pid?: number }
|
|
357
483
|
| { type: 'session_resumed'; sessionId: string; pid?: number }
|
|
358
484
|
| { type: 'session_output'; sessionId: string; seq: number; data: string }
|
|
485
|
+
/** An input was accepted into the runtime (emitted BEFORE it reaches the PTY). */
|
|
486
|
+
| { type: 'session_input'; sessionId: string; seq: number; epoch: string; clientId: string }
|
|
359
487
|
| { type: 'session_cleared'; sessionId: string }
|
|
360
488
|
| { type: 'session_exit'; sessionId: string; exitCode: number | null; signal?: number | null; termination?: SessionTermination }
|
|
361
489
|
| { type: 'session_stopped'; sessionId: string }
|