@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/dist/index.d.mts +319 -4
- package/dist/index.d.ts +319 -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 +131 -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[];
|
|
@@ -267,27 +366,70 @@ interface SessionHostDiagnostics {
|
|
|
267
366
|
recentRequests: SessionHostRequestTrace[];
|
|
268
367
|
recentTransitions: SessionHostRuntimeTransition[];
|
|
269
368
|
}
|
|
369
|
+
interface HostUpgradeLeasePayload {
|
|
370
|
+
bootId: string;
|
|
371
|
+
epoch: number;
|
|
372
|
+
owner: string;
|
|
373
|
+
token: string;
|
|
374
|
+
}
|
|
270
375
|
type SessionHostRequest = {
|
|
376
|
+
type: 'get_upgrade_lease';
|
|
377
|
+
payload?: {};
|
|
378
|
+
} | {
|
|
379
|
+
type: 'acquire_upgrade_lease';
|
|
380
|
+
payload: HostUpgradeLeasePayload;
|
|
381
|
+
} | {
|
|
382
|
+
type: 'release_upgrade_lease';
|
|
383
|
+
payload: HostUpgradeLeasePayload;
|
|
384
|
+
} | {
|
|
271
385
|
type: 'create_session';
|
|
272
386
|
payload: CreateSessionPayload;
|
|
273
387
|
} | {
|
|
274
388
|
type: 'attach_session';
|
|
275
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
|
+
};
|
|
276
399
|
} | {
|
|
277
400
|
type: 'detach_session';
|
|
278
401
|
payload: DetachSessionPayload;
|
|
279
402
|
} | {
|
|
280
403
|
type: 'send_input';
|
|
281
404
|
payload: SendInputPayload;
|
|
405
|
+
} | {
|
|
406
|
+
type: 'send_input_if_seq';
|
|
407
|
+
payload: SendInputIfSeqPayload;
|
|
408
|
+
} | {
|
|
409
|
+
type: 'get_input_state';
|
|
410
|
+
payload: GetInputStatePayload;
|
|
282
411
|
} | {
|
|
283
412
|
type: 'resize_session';
|
|
284
413
|
payload: ResizeSessionPayload;
|
|
285
414
|
} | {
|
|
286
415
|
type: 'stop_session';
|
|
287
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;
|
|
288
425
|
} | {
|
|
289
426
|
type: 'delete_session';
|
|
290
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;
|
|
291
433
|
} | {
|
|
292
434
|
type: 'resume_session';
|
|
293
435
|
payload: ResumeSessionPayload;
|
|
@@ -324,9 +466,21 @@ type SessionHostRequest = {
|
|
|
324
466
|
} | {
|
|
325
467
|
type: 'prune_duplicate_sessions';
|
|
326
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
|
+
};
|
|
327
479
|
} | {
|
|
328
480
|
type: 'list_sessions';
|
|
329
|
-
payload?: {
|
|
481
|
+
payload?: {
|
|
482
|
+
activeOnly?: boolean;
|
|
483
|
+
};
|
|
330
484
|
};
|
|
331
485
|
type SessionHostRequestType = SessionHostRequest['type'];
|
|
332
486
|
declare const SESSION_HOST_SUPPORTED_REQUEST_TYPES: readonly SessionHostRequestType[];
|
|
@@ -352,6 +506,14 @@ type SessionHostEvent = {
|
|
|
352
506
|
sessionId: string;
|
|
353
507
|
seq: number;
|
|
354
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;
|
|
355
517
|
} | {
|
|
356
518
|
type: 'session_cleared';
|
|
357
519
|
sessionId: string;
|
|
@@ -410,6 +572,34 @@ interface SessionHostEventEnvelope {
|
|
|
410
572
|
}
|
|
411
573
|
type SessionHostWireEnvelope = SessionHostRequestEnvelope | SessionHostResponseEnvelope | SessionHostEventEnvelope;
|
|
412
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
|
+
|
|
413
603
|
interface ClassifyTerminationInput {
|
|
414
604
|
exitCode: number | null;
|
|
415
605
|
signal?: number | null;
|
|
@@ -434,6 +624,62 @@ interface ClassifyTerminationInput {
|
|
|
434
624
|
*/
|
|
435
625
|
declare function classifyTermination(input: ClassifyTerminationInput): SessionTermination;
|
|
436
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
|
+
|
|
437
683
|
interface SessionRingBufferOptions {
|
|
438
684
|
maxBytes?: number;
|
|
439
685
|
}
|
|
@@ -501,15 +747,37 @@ declare class SessionRingBuffer {
|
|
|
501
747
|
|
|
502
748
|
declare class SessionHostRegistry {
|
|
503
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;
|
|
504
754
|
createSession(payload: CreateSessionPayload): SessionHostRecord;
|
|
505
755
|
restoreSession(record: SessionHostRecord, snapshot?: {
|
|
506
756
|
seq: number;
|
|
507
757
|
text: string;
|
|
508
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[];
|
|
509
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
|
+
};
|
|
510
768
|
getSession(sessionId: string): SessionHostRecord | null;
|
|
769
|
+
attachClientIfIncarnation(payload: Extract<SessionHostRequest, {
|
|
770
|
+
type: 'attach_session_if_incarnation';
|
|
771
|
+
}>['payload']): SessionHostRecord;
|
|
511
772
|
attachClient(payload: AttachSessionPayload): SessionHostRecord;
|
|
512
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
|
+
};
|
|
513
781
|
acquireWrite(payload: AcquireWritePayload): SessionHostRecord;
|
|
514
782
|
releaseWrite(payload: ReleaseWritePayload): SessionHostRecord;
|
|
515
783
|
appendOutput(sessionId: string, data: string): {
|
|
@@ -563,6 +831,8 @@ interface SessionHostEndpoint {
|
|
|
563
831
|
kind: 'unix' | 'pipe';
|
|
564
832
|
path: string;
|
|
565
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;
|
|
566
836
|
interface SessionHostEndpointOptions {
|
|
567
837
|
/**
|
|
568
838
|
* Instance IPC namespace key (see instance-key.ts). '' / omitted yields the
|
|
@@ -572,6 +842,8 @@ interface SessionHostEndpointOptions {
|
|
|
572
842
|
ipcKey?: string;
|
|
573
843
|
/** Test seam: override the platform the endpoint shape is derived for. */
|
|
574
844
|
platform?: NodeJS.Platform;
|
|
845
|
+
/** Test seam: override the temporary directory used for endpoint derivation. */
|
|
846
|
+
tmpDir?: string;
|
|
575
847
|
}
|
|
576
848
|
declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
|
|
577
849
|
/**
|
|
@@ -606,6 +878,9 @@ declare function createLineParser<TEnvelope = SessionHostWireEnvelope>(onEnvelop
|
|
|
606
878
|
interface SessionHostClientOptions {
|
|
607
879
|
endpoint?: SessionHostEndpoint;
|
|
608
880
|
appName?: string;
|
|
881
|
+
requestTimeoutMs?: number;
|
|
882
|
+
/** Join the shared client registry (default true). Disable for short-lived probes. */
|
|
883
|
+
registerAsShared?: boolean;
|
|
609
884
|
}
|
|
610
885
|
/**
|
|
611
886
|
* Why an established session-host connection went away.
|
|
@@ -614,6 +889,8 @@ interface SessionHostClientOptions {
|
|
|
614
889
|
* - `closed` — socket fully closed ('close') without a preceding error/end
|
|
615
890
|
*/
|
|
616
891
|
type SessionHostDisconnectReason = 'error' | 'ended' | 'closed';
|
|
892
|
+
declare function disconnectSessionHostClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
893
|
+
declare function findConnectedSessionHostClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
617
894
|
interface SessionHostDisconnectInfo {
|
|
618
895
|
reason: SessionHostDisconnectReason;
|
|
619
896
|
endpointPath: string;
|
|
@@ -634,12 +911,19 @@ interface SessionHostDisconnectInfo {
|
|
|
634
911
|
declare class SessionHostClient {
|
|
635
912
|
readonly endpoint: SessionHostEndpoint;
|
|
636
913
|
private socket;
|
|
914
|
+
private connectPromise;
|
|
915
|
+
private requestTimeoutMs;
|
|
637
916
|
private requestWaiters;
|
|
638
917
|
private eventListeners;
|
|
639
918
|
private disconnectListeners;
|
|
640
919
|
/** Guards against emitting both an 'error'-path and a 'close'-path disconnect for one socket. */
|
|
641
920
|
private disconnectedSockets;
|
|
921
|
+
/** Session subscriptions established via create_session/attach_session, replayed automatically on reconnect. */
|
|
922
|
+
private attachedSessions;
|
|
642
923
|
constructor(options?: SessionHostClientOptions);
|
|
924
|
+
static disconnectClients(endpoint?: SessionHostEndpoint, error?: Error): void;
|
|
925
|
+
static findConnectedClient(endpoint?: SessionHostEndpoint): SessionHostClient | null;
|
|
926
|
+
isConnected(): boolean;
|
|
643
927
|
/**
|
|
644
928
|
* Fires when an established connection to the session host goes away.
|
|
645
929
|
*
|
|
@@ -654,9 +938,13 @@ declare class SessionHostClient {
|
|
|
654
938
|
*/
|
|
655
939
|
onDisconnect(listener: (info: SessionHostDisconnectInfo) => void): () => void;
|
|
656
940
|
private handleDisconnect;
|
|
657
|
-
|
|
941
|
+
private sendRawRequestOnSocket;
|
|
942
|
+
connect(timeoutMs?: number): Promise<void>;
|
|
658
943
|
onEvent(listener: (event: SessionHostEvent) => void): () => void;
|
|
659
|
-
request<T = unknown>(request: SessionHostRequest
|
|
944
|
+
request<T = unknown>(request: SessionHostRequest, options?: {
|
|
945
|
+
timeoutMs?: number;
|
|
946
|
+
}): Promise<SessionHostResponse<T>>;
|
|
947
|
+
disconnect(error?: Error): void;
|
|
660
948
|
close(): Promise<void>;
|
|
661
949
|
}
|
|
662
950
|
declare function createResponseEnvelope(requestId: string, response: SessionHostResponse): SessionHostResponseEnvelope;
|
|
@@ -685,6 +973,10 @@ declare function writeEnvelope(socket: Pick<net.Socket, 'write'>, envelope: Sess
|
|
|
685
973
|
* byte-for-byte identical to the pre-instance layout.
|
|
686
974
|
*/
|
|
687
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;
|
|
688
980
|
/**
|
|
689
981
|
* Resolve the instance config dir from the environment: ADHDEV_CONFIG_DIR
|
|
690
982
|
* when set (trimmed), else `<homeDir>/.adhdev`. Mirrors daemon-core's
|
|
@@ -734,6 +1026,12 @@ declare function resolveSessionHostIpcKey(configDir: string, homeDir?: string, p
|
|
|
734
1026
|
* with child CLI processes and apply terminal colour defaults.
|
|
735
1027
|
*/
|
|
736
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>;
|
|
737
1035
|
/**
|
|
738
1036
|
* Apply preferred terminal colour environment variables.
|
|
739
1037
|
* Ensures TERM is set to xterm-256color and enables colour on Windows.
|
|
@@ -766,11 +1064,28 @@ interface SessionHostSnapshot {
|
|
|
766
1064
|
*/
|
|
767
1065
|
interface SessionHostControlPlane {
|
|
768
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>;
|
|
769
1074
|
listSessions(): Promise<SessionHostRecord[]>;
|
|
770
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>;
|
|
771
1078
|
deleteSession(sessionId: string, opts?: {
|
|
772
1079
|
force?: boolean;
|
|
773
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>;
|
|
774
1089
|
resumeSession(sessionId: string): Promise<SessionHostRecord | null>;
|
|
775
1090
|
restartSession(sessionId: string): Promise<SessionHostRecord | null>;
|
|
776
1091
|
sendSignal(sessionId: string, signal: string): Promise<SessionHostRecord | null>;
|
|
@@ -809,4 +1124,4 @@ interface SessionHostControlTransport {
|
|
|
809
1124
|
*/
|
|
810
1125
|
declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
|
|
811
1126
|
|
|
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 };
|
|
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 };
|