1+ import type { ComposeDaemonRuntimeDeps } from './daemon-runtime-deps.ts' ;
12import { recoverAppLogResourcesAfterDaemonLock } from '@agent-device/capture-kit/app-log-resource-recovery' ;
23import { resolveSessionRequestLogPath } from '@agent-device/daemon-contracts/session-artifact-paths' ;
34import {
45 createOwnerScopedDeviceClaimReconciler ,
56 createRecoveryPlatformScope ,
6- type ClaimRecoveryGatewayFactory ,
77} from '@agent-device/daemon-contracts/device-claim-recovery' ;
88import crypto from 'node:crypto' ;
99import { asAppError , AppError , normalizeError } from '@agent-device/kernel/errors' ;
@@ -15,25 +15,19 @@ import {
1515 type DaemonRuntimeOwnership ,
1616} from '@agent-device/daemon-contracts/daemon-resolution' ;
1717import { trackDownloadableArtifact } from '../../resources/artifact-tracking.ts' ;
18- import {
19- installProviderDeviceAdmission ,
20- type ProviderDeviceAdmission ,
21- } from '../../core/provider-device-admission.ts' ;
18+ import { installProviderDeviceAdmission } from '../../core/provider-device-admission.ts' ;
2219import {
2320 loadDaemonPolicy ,
2421 type DaemonPolicy ,
2522} from '@agent-device/daemon-contracts/daemon-policy-file' ;
2623import { assertDaemonPolicyAllowsCapability } from '../../core/daemon-policy.ts' ;
27- import {
28- installInteractorResolution ,
29- type InteractorResolution ,
30- } from '../../core/interactor-resolution.ts' ;
24+ import { installInteractorResolution } from '../../core/interactor-resolution.ts' ;
3125import { LeaseRegistry } from '../../resources/lease-registry.ts' ;
3226import {
3327 createExpiredProviderLeaseReleaser ,
3428 leaseReleaseDiagnosticEvent ,
3529} from '../provider-lease-expiry.ts' ;
36- import { createRequestHandler , type RequestRouterDeps } from '../request-router.ts' ;
30+ import { createRequestHandler } from '../request-router.ts' ;
3731import {
3832 createLeaseSessionEnd ,
3933 getLeaseRegistryExecutionLocks ,
@@ -81,7 +75,6 @@ import type { HostEnvironment } from '@agent-device/kernel/source-value';
8175import {
8276 readCurrentOwnerIdentity ,
8377 reapOwnedProcessRecordsAtStartup ,
84- type OwnedProcessRecordStore ,
8578 type OwnerIdentity ,
8679} from '@agent-device/host-kit/process' ;
8780import { isEnvTruthy , sleep } from '@agent-device/host-kit/retry' ;
@@ -104,17 +97,6 @@ import {
10497import { retainPngWorker } from '@agent-device/capture-kit/png-worker-client' ;
10598import { openWebSessionNames } from '../../sessions/web-session-names.ts' ;
10699import { createAppLogAdmissionLedger } from '../../resources/app-log-admission-ledger.ts' ;
107- import type { AppLogSessionArtifacts } from '@agent-device/contracts/app-log-runtime' ;
108- import type { PlatformOwnerLifecycle } from '../../core/platform-owner-lifecycle.ts' ;
109- import type {
110- LeaseLifecycleProvider ,
111- ProviderExpiredLeaseRecovery ,
112- } from '@agent-device/contracts/device' ;
113- import type { HostDiagnostics } from '@agent-device/contracts/host-diagnostics' ;
114- import type {
115- PluginCleanupOutcome ,
116- PluginInventoryEntry ,
117- } from '@agent-device/contracts/plugin-inventory' ;
118100
119101const DAEMON_LEASE_RELEASE_TIMEOUT_MS = 1_000 ;
120102const LEASE_EXPIRY_SWEEP_INTERVAL_MS = 1_000 ;
@@ -129,93 +111,6 @@ const DAEMON_REQUEST_DRAIN_TIMEOUT_MS = 5_000;
129111// (#2170). Bound the grace to the recorder purpose, so daemon startup stays under the client budget.
130112const DAEMON_RECORDING_REAP_TERM_TIMEOUT_MS = 5_000 ;
131113
132- /**
133- * Every capability the daemon runtime cannot construct for itself: the platform and provider
134- * runtimes, host diagnostics, credential fingerprinting, resource cleanup, the platform lifecycle
135- * owners, and the request-router inputs that name them. The server owns the paths, the policy, and
136- * the session store, and asks the root for the rest through a `composeDeps` factory — the process
137- * root's implementation is `src/daemon-composition.ts` (ADR 0019). All members are required: a
138- * daemon process either receives the root's composition or cannot start, and a test passes the
139- * same factory, so the production assembly is the one every runtime test boots.
140- */
141- export type DaemonRuntimeDeps = Readonly < {
142- ownedProcessRecords : OwnedProcessRecordStore ;
143- hostDiagnostics : HostDiagnostics ;
144- ownerLifecycle : PlatformOwnerLifecycle ;
145- /**
146- * Shuts every provider down, each runtime and then its plugin's own cleanup. The composition owns
147- * what a provider is made of, so the server calls this once per shutdown path and never reaches
148- * into a runtime.
149- */
150- shutdownProviderRuntimes : ( ) => Promise < readonly PluginCleanupOutcome [ ] > ;
151- /**
152- * Every provider plugin the composition saw, active or failed. Data only: this server publishes
153- * it in the daemon registration and records each failed entry as a `provider_plugin_failed`
154- * diagnostic, so log emission stays in this module.
155- */
156- pluginInventory : readonly PluginInventoryEntry [ ] ;
157- interactorResolution : InteractorResolution ;
158- providerDeviceAdmission : ProviderDeviceAdmission ;
159- cleanupManagedWebOrphans : (
160- params : Readonly < {
161- stateDir : string ;
162- openWebSessionNames : readonly string [ ] ;
163- ownedProcessRecords ?: OwnedProcessRecordStore ;
164- } > ,
165- ) => Promise < void > ;
166- leaseLifecycleProvider ?: LeaseLifecycleProvider ;
167- providerRuntimeIds : readonly string [ ] ;
168- recoverExpiredLease ?: ProviderExpiredLeaseRecovery ;
169- recoverableProviderIds : readonly string [ ] ;
170- /** The runtime gateway every lifecycle and recovery step in this server runs through. */
171- deviceRuntimeGateway : RequestRouterDeps [ 'deviceRuntimeGateway' ] ;
172- /** The resource-cleanup surface the session teardowns run through. */
173- platformResourceCleanup : RequestRouterDeps [ 'platformResourceCleanup' ] ;
174- /** The owner-scoped gateway factory the startup claim reconciliation composes. */
175- claimRecoveryGateway : ClaimRecoveryGatewayFactory ;
176- /**
177- * The root-composed half of `createRequestHandler`'s inputs; the server adds the rest.
178- * Optionality mirrors `RequestRouterDeps`. Facts the server also reads outside any request —
179- * the gateway, the cleanup surface, the claim-recovery factory, and the lease-provider facts —
180- * are declared once at the top level of the deps, not here.
181- */
182- requestRouter : Pick <
183- RequestRouterDeps ,
184- | 'requestPlatformProviders'
185- | 'deviceInventoryGateways'
186- | 'platformServices'
187- | 'androidObservation'
188- | 'providerCredentials'
189- | 'createCommandSurface'
190- | 'cloudArtifactProvider'
191- | 'providerAppCatalog'
192- | 'providerDeviceRuntimeScope'
193- > ;
194- } > ;
195-
196- /** Everything the composition factory needs that the server owns: paths, policy, and the store. */
197- export type DaemonRuntimeDepsInput = Readonly < {
198- /** The environment and working directory this daemon runs with; nothing below reads the process's. */
199- host : HostEnvironment ;
200- /** The resolved state-dir root; the server resolves daemon paths and passes it down. */
201- baseDir : string ;
202- sessionsDir : string ;
203- /** Refuses the shutdown capability the operator denied; undefined when no policy names it. */
204- assertShutdownAllowed : ( ( ) => void ) | undefined ;
205- resolveSessionDir ( sessionId : string ) : string ;
206- resolveSessionArtifacts ( sessionId : string ) : AppLogSessionArtifacts ;
207- openWebSessionNames ( ) : readonly string [ ] ;
208- } > ;
209-
210- /**
211- * The factory that names this daemon's runtimes. The server calls it once, after resolving its
212- * paths and loading the operator's policy, and before it acquires the registration; the process
213- * root's implementation is `createDaemonRuntimeDeps`.
214- */
215- export type ComposeDaemonRuntimeDeps = (
216- input : DaemonRuntimeDepsInput ,
217- ) => Promise < DaemonRuntimeDeps > ;
218-
219114export type DaemonRuntimeOptions = {
220115 host : HostEnvironment ;
221116 stdout ?: WritableOutput ;
0 commit comments