@adhdev/session-host-core 1.0.82-rc.32 → 1.0.82-rc.34

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 CHANGED
@@ -3,6 +3,79 @@ import { SpawnOptions, ChildProcess } from 'node:child_process';
3
3
  import * as net from 'net';
4
4
  export { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS, resolveSessionHostCols, resolveSessionHostRows } from './defaults.mjs';
5
5
 
6
+ /** This association is owner asserted, never a historical native receipt. */
7
+ declare const OPERATOR_RECOVERY_TARGET: Readonly<{
8
+ association: "operator_asserted";
9
+ taskId: "a1cdf3c0-f029-4d17-a8e9-db64e0a55501";
10
+ meshId: "mesh_271444af883843e9b36c67155b87b22f";
11
+ attemptId: "mesh_queue:mesh_271444af883843e9b36c67155b87b22f:a1cdf3c0-f029-4d17-a8e9-db64e0a55501:0";
12
+ generation: 0;
13
+ dispatchNonce: 1;
14
+ deliveryId: "dlv-7e259b34-b049-47ee-a466-2ca9c12bcff4";
15
+ ownerDaemonId: "daemon_mach_4462a75330c548be9c2e74dd9f7f6ffb";
16
+ nodeId: "node_d82de0cef9b042b6948986609e32142f";
17
+ workerDaemonId: "daemon_mach_6733c865d60f432dbeb119a6875ee303";
18
+ sessionId: "de321185-4ebc-40aa-8c6e-b4919e87fae3";
19
+ providerSessionId: "60806c79-7d77-4614-9fa6-e628533478ba";
20
+ namespace: "6a2ef3162182";
21
+ }>;
22
+ declare const recoveryTargetBytes: string;
23
+ /** Shared final admission guard for saved IDs, new aliases and provider argv.
24
+ * This is a permanent exact-target denial, independent of journal availability. */
25
+ declare function assertRecoveryLaunchIdentity(value: unknown): void;
26
+ type RecoveryOwnerOperation = 'anchor_recover' | 'fence_install' | 'witness_enroll';
27
+ interface RecoveryOwnerGrant {
28
+ readonly purpose: 'operator_recovery_v1';
29
+ readonly operation: RecoveryOwnerOperation;
30
+ }
31
+ declare function isRecoveryEndpoint(endpoint: string): boolean;
32
+ interface RecoveryOwnerChallenge {
33
+ readonly message: string;
34
+ }
35
+ interface RecoveryOwnerEnrollment {
36
+ /** Trusted boot dependency, provisioned outside delegated worker authority.
37
+ * Do not load this from daemon config, IPC arguments or an MCP credential. */
38
+ publicKey: string;
39
+ enrollmentId: string;
40
+ coordinatorBootId: string;
41
+ authEpoch: string;
42
+ verifyCurrent: () => boolean;
43
+ }
44
+ /** Signature possession authenticates the separately enrolled owner signer.
45
+ * This verifier does not enroll keys or assert user presence on their behalf. */
46
+ declare class RecoveryOwnerAdmission {
47
+ private readonly clock;
48
+ private readonly key;
49
+ private readonly enrollment;
50
+ private readonly pending;
51
+ private readonly grants;
52
+ private lastNow;
53
+ constructor(enrollment: RecoveryOwnerEnrollment, clock?: () => number);
54
+ private now;
55
+ challenge(operation?: RecoveryOwnerOperation): RecoveryOwnerChallenge;
56
+ authorize(message: string, signature: string): RecoveryOwnerGrant;
57
+ assertGrant(grant: unknown): asserts grant is RecoveryOwnerGrant;
58
+ /** Burn synchronously before any work or await. The private continuation
59
+ * rechecks the ORIGINAL deadline and revocation; it cannot mint a new grant. */
60
+ reserve(grant: unknown, operation: RecoveryOwnerOperation): () => void;
61
+ consume(grant: unknown): void;
62
+ }
63
+ interface RecoveryHostBinding {
64
+ namespace: string;
65
+ endpoint: string;
66
+ hostBootId: string;
67
+ workerDaemonId: string;
68
+ }
69
+ interface RecoveryPhysicalProof extends RecoveryHostBinding {
70
+ protocol: 1;
71
+ verdict: 'ABSENT' | 'LIVE' | 'UNKNOWN';
72
+ reason: string;
73
+ nonce: string;
74
+ fenceDigest: string;
75
+ sessionId: string;
76
+ providerSessionId: string;
77
+ }
78
+
6
79
  type SessionTransport = 'pty';
7
80
  type SessionHostCategory = 'cli' | 'acp' | 'shell';
8
81
  type SessionLifecycle = 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
@@ -230,6 +303,16 @@ interface UpdateSessionMetaPayload {
230
303
  meta: Record<string, unknown>;
231
304
  replace?: boolean;
232
305
  }
306
+ /** Bounded liveness check for identities whose provenance the caller already holds.
307
+ * No launch arguments, metadata, snapshots or diagnostic log bodies cross IPC. */
308
+ interface SessionHostCensus {
309
+ hostStartedAt: number;
310
+ endpoint: string;
311
+ hostEntryPath?: string;
312
+ liveSessionIds: string[];
313
+ /** A live role-marked writer outside the caller's persisted identities. */
314
+ hasOtherAssistantCandidates: boolean;
315
+ }
233
316
  interface GetHostDiagnosticsPayload {
234
317
  includeSessions?: boolean;
235
318
  limit?: number;
@@ -327,6 +410,26 @@ interface HostUpgradeLeasePayload {
327
410
  token: string;
328
411
  }
329
412
  type SessionHostRequest = {
413
+ type: 'prepare_operator_recovery_fence_v1';
414
+ payload?: {};
415
+ } | {
416
+ type: 'install_operator_recovery_fence_v1';
417
+ payload: {
418
+ message: string;
419
+ signature: string;
420
+ };
421
+ } | {
422
+ type: 'attest_operator_recovery_v1';
423
+ payload: {
424
+ nonce: string;
425
+ fenceDigest: string;
426
+ };
427
+ } | {
428
+ type: 'get_operator_recovery_coverage_v1';
429
+ payload: {
430
+ nonce: string;
431
+ };
432
+ } | {
330
433
  type: 'get_upgrade_lease';
331
434
  payload?: {};
332
435
  } | {
@@ -341,6 +444,15 @@ type SessionHostRequest = {
341
444
  } | {
342
445
  type: 'attach_session';
343
446
  payload: AttachSessionPayload;
447
+ } | {
448
+ type: 'attach_session_if_incarnation';
449
+ payload: AttachSessionPayload & {
450
+ expectedIncarnation: {
451
+ sessionId: string;
452
+ runtimeKey: string;
453
+ startedAt: number;
454
+ };
455
+ };
344
456
  } | {
345
457
  type: 'detach_session';
346
458
  payload: DetachSessionPayload;
@@ -401,6 +513,11 @@ type SessionHostRequest = {
401
513
  } | {
402
514
  type: 'prune_duplicate_sessions';
403
515
  payload?: PruneDuplicateSessionsPayload;
516
+ } | {
517
+ type: 'get_session_census';
518
+ payload: {
519
+ sessionIds: string[];
520
+ };
404
521
  } | {
405
522
  type: 'get_session';
406
523
  payload: {
@@ -533,6 +650,21 @@ declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
533
650
  /** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
534
651
  declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
535
652
  declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
653
+ interface NiceLaunch {
654
+ readonly command: string;
655
+ readonly args: string[];
656
+ /** True when the child will START at the lowered priority (spawnCliChild must not lower it again). */
657
+ readonly preApplied: boolean;
658
+ }
659
+ /**
660
+ * Launch through `nice -n <increment>` on macOS/Linux so the child runs at the
661
+ * lowered priority from its first instruction. `nice` execs the target in
662
+ * place: same pid, and every descendant inherits the niceness. This closes the
663
+ * spawn→setPriority race where a child forked before the post-spawn call and
664
+ * its early descendants escaped at NI=0. Windows (no nice) and shell-string
665
+ * launches keep the post-spawn path.
666
+ */
667
+ declare function niceLaunch(command: string, args: readonly string[], env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, niceAvailable?: () => boolean): NiceLaunch;
536
668
  interface PriorityDependencies {
537
669
  platform: NodeJS.Platform;
538
670
  getPriority: typeof os.getPriority;
@@ -542,7 +674,9 @@ interface PriorityDependencies {
542
674
  /** Separate policy instances are useful for platform/error tests. */
543
675
  declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
544
676
  readonly pid?: number;
545
- }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
677
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
678
+ preApplied?: boolean;
679
+ }) => T;
546
680
  /**
547
681
  * Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
548
682
  * workers, version probes and git helpers at their existing priority.
@@ -558,7 +692,9 @@ declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T e
558
692
  */
559
693
  declare const spawnCliChild: <T extends {
560
694
  readonly pid?: number;
561
- }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
695
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
696
+ preApplied?: boolean;
697
+ }) => T;
562
698
 
563
699
  /** Shared hidden-window primitive for daemon and session-host process helpers. */
564
700
  declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
@@ -643,7 +779,15 @@ declare class SessionHostRegistry {
643
779
  * sessions. Full details remain available through getSession. */
644
780
  listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
645
781
  listSessions(): SessionHostRecord[];
782
+ /** No launch bodies are cloned. Unknown role evidence stays conservative. */
783
+ getSessionCensus(sessionIds: string[]): {
784
+ liveSessionIds: string[];
785
+ hasOtherAssistantCandidates: boolean;
786
+ };
646
787
  getSession(sessionId: string): SessionHostRecord | null;
788
+ attachClientIfIncarnation(payload: Extract<SessionHostRequest, {
789
+ type: 'attach_session_if_incarnation';
790
+ }>['payload']): SessionHostRecord;
647
791
  attachClient(payload: AttachSessionPayload): SessionHostRecord;
648
792
  detachClient(payload: DetachSessionPayload): SessionHostRecord;
649
793
  /** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
@@ -717,6 +861,8 @@ interface SessionHostEndpointOptions {
717
861
  ipcKey?: string;
718
862
  /** Test seam: override the platform the endpoint shape is derived for. */
719
863
  platform?: NodeJS.Platform;
864
+ /** Test seam: override the temporary directory used for endpoint derivation. */
865
+ tmpDir?: string;
720
866
  }
721
867
  declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
722
868
  /**
@@ -980,4 +1126,4 @@ interface SessionHostControlTransport {
980
1126
  */
981
1127
  declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
982
1128
 
983
- export { type AcquireWritePayload, type AttachSessionPayload, 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 DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, 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 StopMeshWriterPayload, 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, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, validateSessionHostEndpoint, writeEnvelope };
1129
+ export { type AcquireWritePayload, type AttachSessionPayload, 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 DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, type NiceLaunch, OPERATOR_RECOVERY_TARGET, type PruneDuplicateSessionsPayload, type RecoveryHostBinding, RecoveryOwnerAdmission, type RecoveryOwnerChallenge, type RecoveryOwnerEnrollment, type RecoveryOwnerGrant, type RecoveryOwnerOperation, type RecoveryPhysicalProof, 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, 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 StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, assertRecoveryLaunchIdentity, assertTestStorageIsolated, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isRecoveryEndpoint, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, niceLaunch, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, recoveryTargetBytes, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, validateSessionHostEndpoint, writeEnvelope };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,79 @@ import { SpawnOptions, ChildProcess } from 'node:child_process';
3
3
  import * as net from 'net';
4
4
  export { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS, resolveSessionHostCols, resolveSessionHostRows } from './defaults.js';
5
5
 
6
+ /** This association is owner asserted, never a historical native receipt. */
7
+ declare const OPERATOR_RECOVERY_TARGET: Readonly<{
8
+ association: "operator_asserted";
9
+ taskId: "a1cdf3c0-f029-4d17-a8e9-db64e0a55501";
10
+ meshId: "mesh_271444af883843e9b36c67155b87b22f";
11
+ attemptId: "mesh_queue:mesh_271444af883843e9b36c67155b87b22f:a1cdf3c0-f029-4d17-a8e9-db64e0a55501:0";
12
+ generation: 0;
13
+ dispatchNonce: 1;
14
+ deliveryId: "dlv-7e259b34-b049-47ee-a466-2ca9c12bcff4";
15
+ ownerDaemonId: "daemon_mach_4462a75330c548be9c2e74dd9f7f6ffb";
16
+ nodeId: "node_d82de0cef9b042b6948986609e32142f";
17
+ workerDaemonId: "daemon_mach_6733c865d60f432dbeb119a6875ee303";
18
+ sessionId: "de321185-4ebc-40aa-8c6e-b4919e87fae3";
19
+ providerSessionId: "60806c79-7d77-4614-9fa6-e628533478ba";
20
+ namespace: "6a2ef3162182";
21
+ }>;
22
+ declare const recoveryTargetBytes: string;
23
+ /** Shared final admission guard for saved IDs, new aliases and provider argv.
24
+ * This is a permanent exact-target denial, independent of journal availability. */
25
+ declare function assertRecoveryLaunchIdentity(value: unknown): void;
26
+ type RecoveryOwnerOperation = 'anchor_recover' | 'fence_install' | 'witness_enroll';
27
+ interface RecoveryOwnerGrant {
28
+ readonly purpose: 'operator_recovery_v1';
29
+ readonly operation: RecoveryOwnerOperation;
30
+ }
31
+ declare function isRecoveryEndpoint(endpoint: string): boolean;
32
+ interface RecoveryOwnerChallenge {
33
+ readonly message: string;
34
+ }
35
+ interface RecoveryOwnerEnrollment {
36
+ /** Trusted boot dependency, provisioned outside delegated worker authority.
37
+ * Do not load this from daemon config, IPC arguments or an MCP credential. */
38
+ publicKey: string;
39
+ enrollmentId: string;
40
+ coordinatorBootId: string;
41
+ authEpoch: string;
42
+ verifyCurrent: () => boolean;
43
+ }
44
+ /** Signature possession authenticates the separately enrolled owner signer.
45
+ * This verifier does not enroll keys or assert user presence on their behalf. */
46
+ declare class RecoveryOwnerAdmission {
47
+ private readonly clock;
48
+ private readonly key;
49
+ private readonly enrollment;
50
+ private readonly pending;
51
+ private readonly grants;
52
+ private lastNow;
53
+ constructor(enrollment: RecoveryOwnerEnrollment, clock?: () => number);
54
+ private now;
55
+ challenge(operation?: RecoveryOwnerOperation): RecoveryOwnerChallenge;
56
+ authorize(message: string, signature: string): RecoveryOwnerGrant;
57
+ assertGrant(grant: unknown): asserts grant is RecoveryOwnerGrant;
58
+ /** Burn synchronously before any work or await. The private continuation
59
+ * rechecks the ORIGINAL deadline and revocation; it cannot mint a new grant. */
60
+ reserve(grant: unknown, operation: RecoveryOwnerOperation): () => void;
61
+ consume(grant: unknown): void;
62
+ }
63
+ interface RecoveryHostBinding {
64
+ namespace: string;
65
+ endpoint: string;
66
+ hostBootId: string;
67
+ workerDaemonId: string;
68
+ }
69
+ interface RecoveryPhysicalProof extends RecoveryHostBinding {
70
+ protocol: 1;
71
+ verdict: 'ABSENT' | 'LIVE' | 'UNKNOWN';
72
+ reason: string;
73
+ nonce: string;
74
+ fenceDigest: string;
75
+ sessionId: string;
76
+ providerSessionId: string;
77
+ }
78
+
6
79
  type SessionTransport = 'pty';
7
80
  type SessionHostCategory = 'cli' | 'acp' | 'shell';
8
81
  type SessionLifecycle = 'starting' | 'running' | 'stopping' | 'stopped' | 'failed' | 'interrupted';
@@ -230,6 +303,16 @@ interface UpdateSessionMetaPayload {
230
303
  meta: Record<string, unknown>;
231
304
  replace?: boolean;
232
305
  }
306
+ /** Bounded liveness check for identities whose provenance the caller already holds.
307
+ * No launch arguments, metadata, snapshots or diagnostic log bodies cross IPC. */
308
+ interface SessionHostCensus {
309
+ hostStartedAt: number;
310
+ endpoint: string;
311
+ hostEntryPath?: string;
312
+ liveSessionIds: string[];
313
+ /** A live role-marked writer outside the caller's persisted identities. */
314
+ hasOtherAssistantCandidates: boolean;
315
+ }
233
316
  interface GetHostDiagnosticsPayload {
234
317
  includeSessions?: boolean;
235
318
  limit?: number;
@@ -327,6 +410,26 @@ interface HostUpgradeLeasePayload {
327
410
  token: string;
328
411
  }
329
412
  type SessionHostRequest = {
413
+ type: 'prepare_operator_recovery_fence_v1';
414
+ payload?: {};
415
+ } | {
416
+ type: 'install_operator_recovery_fence_v1';
417
+ payload: {
418
+ message: string;
419
+ signature: string;
420
+ };
421
+ } | {
422
+ type: 'attest_operator_recovery_v1';
423
+ payload: {
424
+ nonce: string;
425
+ fenceDigest: string;
426
+ };
427
+ } | {
428
+ type: 'get_operator_recovery_coverage_v1';
429
+ payload: {
430
+ nonce: string;
431
+ };
432
+ } | {
330
433
  type: 'get_upgrade_lease';
331
434
  payload?: {};
332
435
  } | {
@@ -341,6 +444,15 @@ type SessionHostRequest = {
341
444
  } | {
342
445
  type: 'attach_session';
343
446
  payload: AttachSessionPayload;
447
+ } | {
448
+ type: 'attach_session_if_incarnation';
449
+ payload: AttachSessionPayload & {
450
+ expectedIncarnation: {
451
+ sessionId: string;
452
+ runtimeKey: string;
453
+ startedAt: number;
454
+ };
455
+ };
344
456
  } | {
345
457
  type: 'detach_session';
346
458
  payload: DetachSessionPayload;
@@ -401,6 +513,11 @@ type SessionHostRequest = {
401
513
  } | {
402
514
  type: 'prune_duplicate_sessions';
403
515
  payload?: PruneDuplicateSessionsPayload;
516
+ } | {
517
+ type: 'get_session_census';
518
+ payload: {
519
+ sessionIds: string[];
520
+ };
404
521
  } | {
405
522
  type: 'get_session';
406
523
  payload: {
@@ -533,6 +650,21 @@ declare const CLI_CHILD_NICE_ENV = "ADHDEV_CLI_CHILD_NICE";
533
650
  /** Optional Darwin CPU + I/O background policy, in addition to baseline nice. */
534
651
  declare const CLI_CHILD_SCHEDULING_ENV = "ADHDEV_CLI_CHILD_SCHEDULING";
535
652
  declare function setDarwinBackground(pid: number, onFailure: (error: unknown) => void): void;
653
+ interface NiceLaunch {
654
+ readonly command: string;
655
+ readonly args: string[];
656
+ /** True when the child will START at the lowered priority (spawnCliChild must not lower it again). */
657
+ readonly preApplied: boolean;
658
+ }
659
+ /**
660
+ * Launch through `nice -n <increment>` on macOS/Linux so the child runs at the
661
+ * lowered priority from its first instruction. `nice` execs the target in
662
+ * place: same pid, and every descendant inherits the niceness. This closes the
663
+ * spawn→setPriority race where a child forked before the post-spawn call and
664
+ * its early descendants escaped at NI=0. Windows (no nice) and shell-string
665
+ * launches keep the post-spawn path.
666
+ */
667
+ declare function niceLaunch(command: string, args: readonly string[], env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, niceAvailable?: () => boolean): NiceLaunch;
536
668
  interface PriorityDependencies {
537
669
  platform: NodeJS.Platform;
538
670
  getPriority: typeof os.getPriority;
@@ -542,7 +674,9 @@ interface PriorityDependencies {
542
674
  /** Separate policy instances are useful for platform/error tests. */
543
675
  declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T extends {
544
676
  readonly pid?: number;
545
- }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
677
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
678
+ preApplied?: boolean;
679
+ }) => T;
546
680
  /**
547
681
  * Only wrap agent workload spawns. Keep daemon, session-host IPC, P2P signal
548
682
  * workers, version probes and git helpers at their existing priority.
@@ -558,7 +692,9 @@ declare function createCliChildPriorityPolicy(deps?: PriorityDependencies): <T e
558
692
  */
559
693
  declare const spawnCliChild: <T extends {
560
694
  readonly pid?: number;
561
- }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void) => T;
695
+ }>(spawnChild: () => T, env?: NodeJS.ProcessEnv, logInfo?: (message: string) => void, opts?: {
696
+ preApplied?: boolean;
697
+ }) => T;
562
698
 
563
699
  /** Shared hidden-window primitive for daemon and session-host process helpers. */
564
700
  declare function hiddenSpawn(command: string, args?: readonly string[], options?: SpawnOptions): ChildProcess;
@@ -643,7 +779,15 @@ declare class SessionHostRegistry {
643
779
  * sessions. Full details remain available through getSession. */
644
780
  listSessionSummaries(activeOnly?: boolean): SessionHostRecord[];
645
781
  listSessions(): SessionHostRecord[];
782
+ /** No launch bodies are cloned. Unknown role evidence stays conservative. */
783
+ getSessionCensus(sessionIds: string[]): {
784
+ liveSessionIds: string[];
785
+ hasOtherAssistantCandidates: boolean;
786
+ };
646
787
  getSession(sessionId: string): SessionHostRecord | null;
788
+ attachClientIfIncarnation(payload: Extract<SessionHostRequest, {
789
+ type: 'attach_session_if_incarnation';
790
+ }>['payload']): SessionHostRecord;
647
791
  attachClient(payload: AttachSessionPayload): SessionHostRecord;
648
792
  detachClient(payload: DetachSessionPayload): SessionHostRecord;
649
793
  /** Count one accepted input (see SessionHostRecord.inputSeq); returns its number. */
@@ -717,6 +861,8 @@ interface SessionHostEndpointOptions {
717
861
  ipcKey?: string;
718
862
  /** Test seam: override the platform the endpoint shape is derived for. */
719
863
  platform?: NodeJS.Platform;
864
+ /** Test seam: override the temporary directory used for endpoint derivation. */
865
+ tmpDir?: string;
720
866
  }
721
867
  declare function getDefaultSessionHostEndpoint(appName?: string, options?: SessionHostEndpointOptions): SessionHostEndpoint;
722
868
  /**
@@ -980,4 +1126,4 @@ interface SessionHostControlTransport {
980
1126
  */
981
1127
  declare function createSessionHostControlPlane(transport: SessionHostControlTransport): SessionHostControlPlane;
982
1128
 
983
- export { type AcquireWritePayload, type AttachSessionPayload, 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 DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, 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 StopMeshWriterPayload, 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, isDefaultInstanceConfigDir, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, validateSessionHostEndpoint, writeEnvelope };
1129
+ export { type AcquireWritePayload, type AttachSessionPayload, 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 DetachSessionPayload, type ForceDetachClientPayload, type GetHostDiagnosticsPayload, type GetSnapshotPayload, type GetTerminalSnapshotPayload, type HostUpgradeLeasePayload, type MeshWriterAssignment, type MeshWriterStopTarget, type NiceLaunch, OPERATOR_RECOVERY_TARGET, type PruneDuplicateSessionsPayload, type RecoveryHostBinding, RecoveryOwnerAdmission, type RecoveryOwnerChallenge, type RecoveryOwnerEnrollment, type RecoveryOwnerGrant, type RecoveryOwnerOperation, type RecoveryPhysicalProof, 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, 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 StopSessionPayload, type UpdateSessionMetaPayload, applyTerminalColorEnv, assertRecoveryLaunchIdentity, assertTestStorageIsolated, buildRuntimeDisplayName, buildRuntimeKey, canonicalizeInstancePath, classifyTermination, createCliChildPriorityPolicy, createLineParser, createResponseEnvelope, createSessionHostControlPlane, disconnectSessionHostClients, ensureNodePtySpawnHelperPermissions, findConnectedSessionHostClient, formatRuntimeOwner, getDefaultSessionHostEndpoint, getSessionHostRecoveryLabel, getSessionHostSurfaceKind, getWorkspaceLabel, hiddenSpawn as hiddenSpawnProcess, isDefaultInstanceConfigDir, isRecoveryEndpoint, isSessionHostLiveRuntime, isSessionHostRecoverySnapshot, isTerminalRecord, niceLaunch, partitionSessionHostDiagnosticsSessions, partitionSessionHostRecords, recoveryTargetBytes, replayLaunchEnv, resolveAttachableRuntimeRecord, resolveInstanceConfigDir, resolveRuntimeRecord, resolveSessionHostIpcKey, sanitizeSpawnEnv, spawnCliChild, validateSessionHostEndpoint, writeEnvelope };