import type { SessionManager } from "@caupulican/pi-agent-core/node"; import type { Api, Model, Usage } from "@caupulican/pi-ai"; import type { AgentSessionEvent, IsolatedCompletionOptions, IsolatedCompletionResult, WorkerDelegationRunOutcome } from "../agent-session-contracts.ts"; import type { CapabilityEnvelope, WorkerClaim, WorkerRequest } from "../autonomy/contracts.ts"; import { type LaneRecord } from "../autonomy/lane-tracker.ts"; import { type AutonomyTelemetryEvent } from "../autonomy/telemetry-events.ts"; import type { ArtifactStore } from "../context/context-artifacts.ts"; import { type GoalState } from "../goals/goal-state.ts"; import type { ModelRegistry } from "../model-registry.ts"; import { type OrchestrationProfile, type OrchestrationThinkingLevel, type WorkerRole } from "../orchestration/contracts.ts"; import { type TaskProfileCreateInput, type TaskProfileCreateResult, type TaskProfileInspection } from "../orchestration/task-profile-writer.ts"; import type { TaskRuntimeProjection } from "../orchestration/task-runtime.ts"; import type { ResourceLoader } from "../resource-loader.ts"; import type { SettingsManager } from "../settings-manager.ts"; import type { ReadOnlySkillBroker } from "../tools/skill.ts"; import type { SkillAuditToolOptions } from "../tools/skill-audit.ts"; import type { WorkerAgentControlPort } from "./worker-agent-control.ts"; import { type WorkerDelegationRequest } from "./worker-delegation-request.ts"; import type { WorkerLifecycle } from "./worker-lifecycle.ts"; import type { WorkerNotificationCoordinator, WorkerTerminalHandoffRecord } from "./worker-notification-coordinator.ts"; export declare function isLocalExecutionModel(model: Pick, "provider" | "baseUrl">): boolean; export interface WorkerDelegationControllerDeps { isDisposed(): boolean; getSessionId(): string; getCwd(): string; getAgentDir(): string; getSessionManager(): SessionManager; getSettingsManager(): SettingsManager; getResourceLoader(): ResourceLoader; getActiveOrchestrationProfile?(): OrchestrationProfile | undefined; getModelRegistry(): ModelRegistry; isModelExhausted(model: Model): boolean; getModel(): Model | undefined; getForegroundThinkingLevel?(): OrchestrationThinkingLevel; getForegroundToolNames?(): readonly string[]; isDelegateToolActive(): boolean; getCapabilityEnvelope(): CapabilityEnvelope | undefined; emit(event: AgentSessionEvent): void; notifyWorkerTerminalHandoff(records: readonly WorkerTerminalHandoffRecord[]): Promise; emitAutonomyTelemetry(event: AutonomyTelemetryEvent): void; getGoalStateSnapshot(): GoalState | undefined; saveWorkerClaimSnapshot(claim: WorkerClaim, request?: WorkerRequest): string; readMemoryForLane(query: string): Promise; /** Session-owned artifact store broker; worker adapters receive fresh retrieval tools only. */ getArtifactStore?(): ArtifactStore; /** Host-owned read-only skill broker; no SkillVaultController crosses this boundary. */ getSkillReadBroker?(): ReadOnlySkillBroker; /** Host-owned skill metadata source for read-only audit; paths are redacted before projection. */ getSkillAuditSource?(): Pick & Required>; addSpawnedUsage(usage: Usage, opts: { label?: string; sourceSessionId?: string; reportId: string; }): string | undefined; runIsolatedCompletion(opts: IsolatedCompletionOptions): Promise; } export declare class WorkerDelegationController { private readonly deps; private readonly workerAbort; private readonly lifecycle; private profileResolver; private taskProfileStore; private taskProfileWriter; private readonly recovery; private readonly notifications; private readonly scheduler; private readonly laneAbortControllers; private readonly shellSessionKeys; /** Sole logical-agent control/mailbox owner; execution only calls its narrow delivery hooks. */ private readonly agentControl; private readonly publishedTerminalAttemptIds; private readonly yieldedCapacityAttemptIds; private readonly yieldedWriteReservations; private readonly conversations; private readonly contextForks; private readonly terminalHandoffs; private readonly treeBudgets; private readonly writeReservations; private readonly inFlightLedgers; constructor(deps: WorkerDelegationControllerDeps, notifications: WorkerNotificationCoordinator, lifecycle: WorkerLifecycle); private safeWarn; private cancelScheduledWorker; /** Narrow model-facing control port. It owns control state; this controller only composes it. */ getAgentControl(): WorkerAgentControlPort; /** The coordinator's process identity is also the durable execution lease owner. */ getAgentControlProcessOwnerId(): string; recordTerminal(record: LaneRecord): void; getRecords(): LaneRecord[]; /** Process-local worker records for the shared terminal notifier; never triggers durable recovery. */ getLoadedRecords(): LaneRecord[]; markNotificationsDelivered(notificationIds: readonly string[]): void; abort(): void; private runTeardownStep; private getWorkerLifecycle; private getWorkerProfileResolver; private getTaskProfileStore; private getTaskProfileWriter; private resolveWorkerAuthority; /** Read-only durable worker projection. Undefined means the delegate capability never loaded. */ getTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined; /** Reconcile the session goal into an already-loaded worker runtime without defeating lazy UAC. */ synchronizeGoalState(goal: GoalState): void; private publishGoalTerminalRecords; private dispatchRecoveredVerification; private laneCapabilityProfile; getProfileCatalog(): Array<{ profileId: string; role: string; description: string; }>; inspectTaskProfileOptions(): TaskProfileInspection; createTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult; private resolveWorkerPreset; private resolveRequiredVerifier; /** * A recovered legacy nested dispatch may retain a different routing profile, but it cannot widen * the immutable ancestor contract. Pointer ids alone are insufficient authority: retain only * pointers whose complete metadata matches, require exact soul text, and intersect the persisted * lineage limits. Fresh native workers never enter this compatibility path. */ private narrowWorkerShipmentContext; private hasExactRecoveredLineageCycle; /** Reject a new logical identity before creating its task, transcript, agent, or queue entry. */ private newWorkerFleetSkipReason; private requiredAgentSlotsForAdmission; /** Single admission contract shared by enqueue, scheduler revalidation, and execution. */ private resolveWorkerAdmission; private buildVerifierRequest; private publishTerminalObserversBestEffort; private deliverTerminalHandoff; private publishRecoveredTerminalRecords; private publishTerminalRecord; /** * A pre-execution denial still owns a prepared durable lane. Publish its terminal projection at * this boundary: immediate callers have no scheduler promise to observe and must not wait for a * future recovery read to receive the handoff. Repeated late cancellation paths are inert via * the attempt-id publication fence above. */ private cancelAndPublish; private hasWorkerCapacity; private waitTargetsBlockedByCaller; private yieldWorkerForWait; private workerDispatchAdmission; private workerProjectionHeadroomSkipReason; private workerQueueReservationSkipReason; private workerContextParentModel; private workerContextForkSource; private workerContextForkMode; private workerTreeAttemptAdmissionSkipReason; private workerContextForkAdmissionSkipReason; private workerGoalDependencySkipReason; /** One admission owner for every newly generated logical worker identity. */ private admitNewWorkerRequest; private durableWorkerContextForkReferences; private buildWorkerExecutionPlan; private workerToolAdapterNames; /** One durable preparation path for queued, immediate, and recovered execution. */ private prepareWorkerAttempt; private enqueuePreparedWorkerAttempt; private queuePreparedWorkerAttempt; private ensurePreparedAgent; start(request: WorkerDelegationRequest): { started: false; skipReason: string; } | { started: true; record: LaneRecord; modelPinBypass?: WorkerRole; }; private startInternal; runOnce(request: WorkerDelegationRequest, onStarted?: (record: LaneRecord) => void, existingRecord?: LaneRecord): Promise; private runOnceWithAdmission; /** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */ drain(): void; } //# sourceMappingURL=worker-delegation-controller.d.ts.map