import type { CompletionDetector } from "../completion/detector.js"; import { DelegationStateMachine } from "./state-machine.js"; import type { PtyManager } from "../../features/background-command/pty/pty-manager.js"; import { type OpenCodeClient } from "../../shared/session-api.js"; import { type DelegateParams } from "../spawner/spawn-request-builder.js"; import { type CommandDelegationParams, type Delegation, type DelegationResult, type RuntimePolicy } from "../../shared/types.js"; import type { BehavioralOverrides } from "../../routing/behavioral-profile/types.js"; import type { DelegationMonitor } from "./monitor.js"; import type { NotificationRouter } from "./notification-router.js"; interface DelegationManagerOptions { ptyManager?: PtyManager | null; runtimePolicy?: RuntimePolicy; monitor?: Pick; notificationRouter?: Pick; stateMachine?: DelegationStateMachine; /** * P58.8 S1 (REQ-58-07): optional session manager reference used to start * the capture-pane polling loop after a child session is spawned. When * undefined, no polling is started (tmux may be unavailable or the * integration is not wired in the current environment). */ sessionManager?: { startPolling(intervalMs?: number): void; }; } /** * Public dispatch + concurrency entry point for SDK and command delegations. * * In-memory storage, terminal-state transitions, timer machinery, and pruning * live in {@link DelegationStateMachine} (see `delegation-state-machine.ts`). * `DelegationManager` composes one instance and forwards reads/writes through * it, keeping this module focused on dispatch, concurrency, agent validation, * and recovery wiring. */ export declare class DelegationManager { private readonly client; private readonly state; private readonly semaphore; private readonly commandHandler; private readonly sdkHandler; private readonly runtimePolicy; private readonly monitor; private readonly notificationRouter; private readonly sessionManager; private completionDetector; constructor(client: OpenCodeClient, options?: DelegationManagerOptions); /** * Wires the lifecycle-owned `CompletionDetector` after construction. * * Phase 36.1: invoked from the plugin composition root once the * lifecycle manager has been instantiated, completing the dual-signal * completion path. Idempotent — later calls overwrite the previous * reference, which is safe because the detector is treated as a * lifelong singleton owned by the lifecycle manager. * * @param detector - The lifecycle-owned detector instance. */ setCompletionDetector(detector: CompletionDetector): void; /** * Applies behavioral profile guardrail to concurrency. * Only TIGHTENS — never loosens beyond workspace runtime policy. * * **API surface for Phase WS-4** (auto-intent/workflow router): This method * is intentionally NOT called from `dispatch()` yet. The WS-4 phase will wire * the resolved behavioral profile into the dispatch path, calling this method * to adjust concurrency limits before `semaphore.acquire()`. Until then, the * method is exposed so the integration surface exists and is tested. * * @param guardrailLevel - The behavioral guardrail level from the resolved profile * @returns Adjusted concurrency limit (undefined = no adjustment) * @see D-12 in CA-02-CONTEXT.md */ applyBehavioralGuardrail(guardrailLevel: BehavioralOverrides["guardrailLevel"]): number | undefined; private resolveNestingDepth; dispatch(params: DelegateParams): Promise; dispatchCommand(params: CommandDelegationParams): Promise; handleSessionIdle(sessionId: string): void; handleSessionDeleted(sessionId: string): void; handleSessionError(sessionId: string, error?: unknown): void; recoverPending(): Promise; getStatus(delegationId: string): Delegation | undefined; getAllDelegations(): Delegation[]; /** * Check whether a caller session is in the recorded owner lineage for a delegation. * * @param callerSessionId - Session ID from the current OpenCode tool context. * @param delegation - Target delegation record from memory or persisted storage. * @returns True only for direct owners or explicitly recorded parent/child lineage. */ canSessionAccessDelegation(callerSessionId: string | undefined, delegation: Delegation | undefined): boolean; /** * Return only active delegations visible to the caller's recorded lineage. * * @param callerSessionId - Session ID from the current OpenCode tool context. * @returns In-memory delegation records visible to that caller. */ getVisibleDelegationsForSession(callerSessionId: string): Delegation[]; /** * Find the active delegation that owns a PTY session ID. * * @param ptySessionId - PTY session ID from `run-background-command` input. * @returns The backing delegation when the PTY session is recorded. */ getDelegationForPtySession(ptySessionId: string): Delegation | undefined; /** * Mark a delegation as user-cancelled via its PTY session id and return its * resulting {@link DelegationResult}, or `undefined` when the PTY session is * not recognised. */ markCommandCancellationForPtySession(ptySessionId: string): DelegationResult | undefined; /** * Remove terminal delegations older than `maxAgeMs` from the in-memory store * and re-persist. Forwarded to {@link DelegationStateMachine.pruneCompletedDelegations}. */ pruneCompletedDelegations(maxAgeMs?: number): number; /** * P58.8 S4 (REQ-58-10): subscribe the child event bus to a newly * spawned child session. Wraps `childEventStream.subscribe` in a * try/catch so a missing or failing SDK subscribe implementation * does NOT abort the dispatch. The progress action falls back to * counter-based counts when the bus is empty. */ private subscribeChildEventBus; private validateAgent; private buildCanonicalQueueContext; private buildCommandQueueContext; /** @internal Test compatibility — proxies to SdkDelegationHandler's timer map */ get stabilityTimers(): Map; /** @internal Test compatibility — proxies to the underlying state machine's delegation map */ get delegations(): Map; /** @internal Test compatibility — proxies to the underlying state machine's session map */ get delegationsBySession(): Map; /** @internal Test compatibility — proxies to the underlying state machine's safety timer map */ get safetyTimers(): Map; } export {}; //# sourceMappingURL=manager-runtime.d.ts.map