import type { ContextBudgetMetadata } from "./context.js"; import type { CliCapabilityExposure } from "../cli-capability-catalog.js"; import type { SkillRenderTarget } from "./skills.js"; import type { AutonomousGateMode } from "./workflow-run.js"; export type RuntimeAdapterKind = "llm" | "ide" | "cli"; export type RuntimeExecutionId = "claude-cli" | "codex-cli" | "opencode-cli" | "cursor-cli" | "vscode-agent" | "windsurf-agent" | "generic-runtime"; export type RuntimeDelegationMode = "runtime-native" | "brief-only"; export type RuntimeSpawnCapabilityMode = "unsupported" | "request-only" | "parent-tool" | "local-process"; export type RuntimeLifecycleWatcherDetectionMode = "native-callback" | "parent-lifecycle-event" | "runtime-notification" | "artifact-fallback"; export type RuntimeLifecycleWatcherSupportLevel = "native" | "partial" | "fallback"; export interface RuntimeLifecycleWatcherAdapter { id: string; runtime: RuntimeExecutionId | "unknown-runtime"; detectionMode: RuntimeLifecycleWatcherDetectionMode; supportLevel: RuntimeLifecycleWatcherSupportLevel; completionSignals: RuntimeLifecycleCompletionSignal[]; fallbackBehavior: string; unsupportedNativeCallbackReason?: string; } export type RuntimeLifecycleCompletionSignal = "native-callback" | "parent-lifecycle-event" | "runtime-notification" | "self-report-command" | "expected-artifact"; export interface RuntimeSpawnCapability { mode: RuntimeSpawnCapabilityMode; tool: string | null; requestArtifact: boolean; supportsQueue: boolean; supportsAgentId: boolean; requiresParentRuntime: boolean; guidance: string; } export interface RuntimeAdapter { target: SkillRenderTarget; label: string; kind: RuntimeAdapterKind; defaultInstructionFiles: string[]; supportsStructuredPayload: boolean; supportsManagedBlocks: boolean; supportsImports: boolean; guidance: string; bootstrapSpawnHint?: string[]; recurringPreflightLines?: string[]; bootstrapSpawnLines?: string[]; spawnProtocolLines?: string[]; } export interface RuntimeAdapterCatalogEntry extends RuntimeAdapter { executionAdapters: RuntimeExecutionAdapter[]; } export interface RuntimeExecutionCapabilities { nonInteractive: boolean; promptInjection: boolean; structuredOutput: boolean; fileEdits: boolean; testExecution: boolean; evidenceReturn: boolean; requiresTty: boolean; requiresUserApproval: boolean; resumeSession: boolean; } export type RuntimeToolPermissionMode = "runtime-managed" | "brief-only" | "read-only" | "full-autonomy"; export interface RuntimeToolPermissionPolicy { mode: RuntimeToolPermissionMode; requiresExplicitOptIn: boolean; readOnlyTools: string[]; writeTools: string[]; shellTools: string[]; autonomyFlags: string[]; gatedFlags: string[]; warning: string; } export interface RuntimeSubagentCapabilities { runtimeNative: boolean; parallel: boolean; namedRoles: boolean; forkedContext: boolean; structuredHandoff: boolean; fileOwnership: boolean; requiresParentApproval: boolean; spawn: RuntimeSpawnCapability; } export interface RuntimeExecutionAdapter { id: RuntimeExecutionId; target: SkillRenderTarget; label: string; kind: RuntimeAdapterKind; summary: string; execution: RuntimeExecutionCapabilities; toolPermissionPolicy: RuntimeToolPermissionPolicy; subagents: RuntimeSubagentCapabilities; briefOnlyFallback: boolean; directProviderApiAllowed: false; guidance: string; /** Output format for skill rendering: "markdown" for most targets, "json" for structured consumers (e.g. vscode). */ skillRenderFormat?: "markdown" | "json"; /** Title heading used in the rendered skill context document. */ skillContextTitle?: string; /** Introductory sentence placed below the title in the rendered skill context document. */ skillContextIntro?: string; } export interface RuntimeExecutorConfig { executor?: RuntimeExecutionId; } export interface RuntimeDelegationPolicy { mode: RuntimeDelegationMode; allowDirectProviderApi: boolean; guardrails?: RuntimeDelegationGuardrails; } export interface RuntimeExecutionPolicy { defaults?: RuntimeExecutorConfig; byRole: Record; byTask: Record; delegation: RuntimeDelegationPolicy; } export interface RuntimeSelection { taskId: string; role: string; runtime: RuntimeExecutionAdapter; source: "explicit" | "task" | "role" | "default" | "inferred" | "fallback"; directProviderApiAllowed: false; } export type RuntimeChatInteractionMode = "ask" | "plan" | "agent"; export type RuntimeDelegationIntent = "execute" | "review" | "research"; export interface RuntimeDelegationAssignment { role: string; paths: string[]; delegationIntent: RuntimeDelegationIntent; allowedCommands: string[]; cliCapabilityExposure?: CliCapabilityExposure; expectedArtifacts: string[]; } export type RuntimeDelegationLimitAction = "queue" | "reject"; export interface RuntimeDelegationGuardrails { maxConcurrentDelegates: number; maxDelegationDepth: number; maxSpawnsPerTask: number; spawnBudgetTokens: number; contextBudgetTokens: number; timeoutMs: number; staleClaimTtlMs: number; allowNestedDelegation: boolean; limitAction: RuntimeDelegationLimitAction; handoffMaxChars: number; } export type RuntimeDelegationGuardrailStatus = "allow" | "queue" | "reject"; export interface RuntimeDelegationGuardrailEvaluation { status: RuntimeDelegationGuardrailStatus; reasons: string[]; policy: RuntimeDelegationGuardrails; activeSessions: number; requestedSpawns: number; delegationDepth: number; contextBudgetTokens: number; spawnBudgetTokens: number; staleSessions: string[]; } export type RuntimeDelegationSessionStatus = "planned" | "requested" | "queued" | "spawned" | "active" | "suspended" | "completed" | "failed" | "timed_out" | "canceled" | "closed"; export interface RuntimeDelegationSessionSummary { sessionId: string; taskId: string; runtime?: RuntimeExecutionId | string; mode?: RuntimeDelegationMode; phase?: string; role?: string; spawnedAgentId?: string; roles: string[]; status: RuntimeDelegationSessionStatus; lastEventType: string; updatedAt: string; ageMs: number; active: boolean; stale: boolean; artifacts: string[]; } export interface RuntimeDelegationOperationsReport { generatedAt: string; taskId?: string; policy: RuntimeDelegationGuardrails; counts: { total: number; active: number; stale: number; suspended: number; terminal: number; }; sessions: RuntimeDelegationSessionSummary[]; } export interface RuntimeBrief { taskId: string; runtime: RuntimeExecutionId; artifact: string; content: string; mode: "brief-only"; directProviderApiAllowed: false; contextBudget: ContextBudgetMetadata; } export interface RuntimeDelegationPacket { taskId: string; sessionId: string; runtime: RuntimeExecutionId; artifact: string; content: string; mode: RuntimeDelegationMode; spawnCapability: RuntimeSpawnCapability; directProviderApiAllowed: false; assignments: RuntimeDelegationAssignment[]; requiresApproval: boolean; contextBudget: ContextBudgetMetadata; guardrails: RuntimeDelegationGuardrailEvaluation; } export type RuntimeSpawnRequestStatus = "requested" | "queued"; export type RuntimeParentActionKind = "codex-spawn-agent" | "claude-agent-request" | "cursor-background-agent" | "manual-runtime-request"; export type RuntimeParentActionEligibilityStatus = "dispatchable" | "skipped"; export type RuntimeParentActionSafetyState = "safe" | "unsafe" | "unknown"; export type RuntimeParentActionSkipReasonCode = "already-dispatched" | "queued" | "suspended" | "terminal" | "stale-or-unsafe" | "runtime-mismatch" | "tool-mismatch" | "unsupported-runtime" | "unavailable-native-tool" | "manual-request"; export interface RuntimeParentActionSkipReason { code: RuntimeParentActionSkipReasonCode; message: string; } export interface RuntimeParentActionEligibilityChecked { runtime: string; actionKind: RuntimeParentActionKind; tool: string; sessionStatus?: RuntimeDelegationSessionStatus; runtimeFilter?: string; safetyState: RuntimeParentActionSafetyState; capacity?: { status: "available" | "reserved" | "queued"; activeSessions: number; maxConcurrentDelegates: number; activeTaskSessions: number; maxSpawnsPerTask: number; reason?: string; }; } export interface RuntimeParentActionEligibility { status: RuntimeParentActionEligibilityStatus; dispatchable: boolean; reasons: RuntimeParentActionSkipReason[]; checked: RuntimeParentActionEligibilityChecked; } export interface RuntimeParentActionPayload { promptArtifact: string; contextManifestArtifact?: string; contextPackArtifact?: string; expectedResultArtifact: string; ownershipPaths: string[]; allowedCommands: string[]; cliCapabilityExposure?: CliCapabilityExposure; expectedArtifacts: string[]; } export interface RuntimeParentActionLifecycleCommands { spawned: string; completed: string; failed: string; } export interface RuntimeParentAction { kind: RuntimeParentActionKind; runtime: RuntimeExecutionId; tool: string; mode: RuntimeSpawnCapabilityMode; delegationIntent: RuntimeDelegationAssignment["delegationIntent"]; executionMode?: RuntimeChatInteractionMode; sessionId: string; phase: string; role: string; instructions: string[]; payload: RuntimeParentActionPayload; lifecycleCommands: RuntimeParentActionLifecycleCommands; } export interface RuntimeClaudeNativeCallbackMetadata { taskId: string; sessionId: string; phase: string; role: string; runtime: "claude-cli"; actionKind: "claude-agent-request"; tool: "claude-code-agent"; promptArtifact: string; expectedResultArtifact: string; directProviderApiAllowed: false; } export type RuntimeClaudeNativeBridgeResult = { status: "native-dispatched"; childId: string; metadata: RuntimeClaudeNativeCallbackMetadata; summary: string; } | { status: "unsupported"; reason: string; guidance: string; metadata: RuntimeClaudeNativeCallbackMetadata; }; export interface PendingRuntimeParentAction { taskId: string; sessionId: string; runtime: RuntimeExecutionId | string; phase: string; role: string; status: "requested" | "queued"; action: RuntimeParentAction; artifacts: string[]; updatedAt: string; actionable: boolean; rationale: string; eligibility: RuntimeParentActionEligibility; } export interface RuntimeSpawnRequest { taskId: string; runId?: string; phase: string; role: string; runtime: RuntimeExecutionId; sessionId: string; artifact: string; content: string; status: RuntimeSpawnRequestStatus; spawnCapability: RuntimeSpawnCapability; parentRuntimeAction: RuntimeParentAction; assignment: RuntimeDelegationAssignment; promptArtifact: string; contextManifestArtifact: string; contextPackArtifact?: string; contextPackBudget?: { usedChars: number; targetChars: number; truncated: boolean; }; expectedResultArtifact: string; directProviderApiAllowed: false; asyncControl: { mode: "full-async"; defaultParentWait: false; completion: "lifecycle-event-or-explicit-poll"; nextCommands: RuntimeParentActionLifecycleCommands; }; qualityWarnings: string[]; contextBudget: ContextBudgetMetadata; guardrails: RuntimeDelegationGuardrailEvaluation; } export interface RuntimeInvocationPlan { runtime: RuntimeExecutionId; gates: AutonomousGateMode; command: string | null; args: string[]; permissionMode: RuntimeToolPermissionMode; directExecutionEnabled: false; canExecute: false; reason: string; warning: string; } export interface RuntimeCapacityScope { platformId: string; tenantId: string; workspaceId: string; } export type RuntimeWorkloadClass = "interactive" | "workflow-phase" | "runtime-native-spawn" | "provider-backed-phase" | "background-maintenance" | "evidence-processing"; export interface RuntimeCapacityUnit { concurrencyUnits: number; tokenBudget?: number; cpuWeight?: number; memoryMb?: number; ioWeight?: number; estimatedDurationMs?: number; } export type RuntimeCapacityLimitAction = "queue" | "reject"; export interface RuntimeQuotaPolicy { maxActive: number; maxQueued: number; maxActivePerProvider?: number; maxActivePerRuntime?: number; maxBurst?: number; rateWindowMs?: number; limitAction: RuntimeCapacityLimitAction; queueTtlMs?: number; } export type RuntimeWorkerKind = "local-parent" | "local-process" | "saas-worker" | "runtime-parent" | "provider-backed"; export type RuntimeTenantAffinity = "single-tenant" | "tenant-pool" | "platform-shared"; export type RuntimeWorkerHealth = "healthy" | "draining" | "degraded" | "unhealthy" | "offline"; export interface RuntimeWorkerIsolationMetadata { version: string; policyVersion: string; sandboxProfile: string; secretScope: string; dataResidencyTags: string[]; } export interface RuntimeWorkerRecord { workerId: string; workerKind: RuntimeWorkerKind; tenantAffinity: RuntimeTenantAffinity; allowedTenantIds: string[]; deniedTenantIds: string[]; regions: string[]; runtimeIds: string[]; providerIds: string[]; workloadClasses: RuntimeWorkloadClass[]; toolCapabilities: string[]; maxConcurrencyUnits: number; availableConcurrencyUnits: number; tokenBudgetRemaining?: number; cpuWeight?: number; memoryMb?: number; health: RuntimeWorkerHealth; lastHeartbeatAt: string; failureCount: number; openedUntil?: string; leaseTtlMs: number; isolation: RuntimeWorkerIsolationMetadata; } export interface RuntimeRegionPreference { regions: string[]; strict: boolean; } export interface RuntimeQueuePolicy { priority: "high" | "normal" | "low"; maxQueueMs?: number; limitAction: RuntimeCapacityLimitAction; } export interface RuntimeScheduleRequest { requestId: string; scope?: RuntimeCapacityScope; workloadClass: RuntimeWorkloadClass; provider?: string; runtime?: RuntimeExecutionId | string; regionPreference?: RuntimeRegionPreference; capacity: RuntimeCapacityUnit; tenantPolicy?: RuntimeQuotaPolicy; workspacePolicy?: RuntimeQuotaPolicy; queuePolicy?: RuntimeQueuePolicy; idempotencyKey?: string; leaseTtlMs?: number; } export interface RuntimeLease { leaseId: string; workerId: string; scope: RuntimeCapacityScope; workloadClass: RuntimeWorkloadClass; provider?: string; runtime?: RuntimeExecutionId | string; capacity: RuntimeCapacityUnit; expiresAt: string; } export type RuntimeScheduleDecisionStatus = "admitted" | "queued" | "rejected" | "deferred"; export type RuntimeScheduleReasonCode = "admitted" | "queued_platform_limit" | "queued_tenant_limit" | "queued_workspace_limit" | "queued_provider_limit" | "queued_runtime_limit" | "queued_no_eligible_worker" | "rejected_invalid_request" | "rejected_missing_scope" | "rejected_platform_limit" | "rejected_tenant_limit" | "rejected_workspace_limit" | "rejected_provider_limit" | "rejected_runtime_limit" | "rejected_queue_full" | "deferred_no_eligible_worker"; export interface RuntimeQueueDecision { queueId: string; position: number; reasonCode: RuntimeScheduleReasonCode; retryAfterMs?: number; expiresAt?: string; } export interface RuntimeScheduleDecision { decisionId: string; status: RuntimeScheduleDecisionStatus; scope: RuntimeCapacityScope; workloadClass: RuntimeWorkloadClass; reasonCode: RuntimeScheduleReasonCode; userSafeReason: string; workerId?: string; lease?: RuntimeLease; queue?: RuntimeQueueDecision; } export interface RuntimeCapacitySnapshot { active: number; queued: number; reserved: number; rejected: number; openCircuits: number; activeByPlatform: Record; activeByTenant: Record; activeByWorkspace: Record; activeByWorkloadClass: Record; activeByProvider: Record; activeByRuntime: Record; activeByRegion: Record; activeByWorkerId: Record; queuedByPlatform: Record; queuedByTenant: Record; queuedByWorkspace: Record; queuedByWorkloadClass: Record; queuedByProvider: Record; queuedByRuntime: Record; queuedByRegion: Record; queuedByWorkerId: Record; } export interface RuntimeCapacitySchedulerEvent { decisionId: string; type: RuntimeScheduleDecisionStatus | "released" | "promoted"; scope: RuntimeCapacityScope; workloadClass: RuntimeWorkloadClass; provider?: string; runtime?: RuntimeExecutionId | string; workerId?: string; reasonCode: RuntimeScheduleReasonCode | "released"; queueLatencyMs?: number; leaseDurationMs?: number; timestamp: string; }