import type { RuntimeExecutionPolicy } from "./runtime.js"; import type { QualityContractPolicyConfig } from "../quality-contracts.js"; import type { WorkflowPhaseExecutionMode } from "./workflow-run.js"; export interface ToolConfig { enabled?: boolean; command: string; args: string[]; cwd: string; allowedRoles: string[]; timeoutMs: number; evidence: string; risk: string; } export interface ModelProviderCapabilities { streaming: boolean; tools: boolean; vision: boolean; jsonMode: boolean; maxContextTokens: number; timeoutMs: number; } export interface ModelMessage { role: "system" | "user" | "assistant" | "tool"; content: string; } export interface ModelRequest { messages: ModelMessage[]; model: string; temperature?: number; maxTokens?: number; jsonMode?: boolean; tools?: unknown[]; timeoutMs?: number; } export interface ModelResponse { id: string; provider: string; model: string; content: string; usage: { inputTokens: number; outputTokens: number; }; finishReason: "stop" | "length" | "tool_call" | "error"; } export interface ModelStreamEvent { type: "content" | "tool_call" | "done" | "error"; content?: string; error?: string; } export interface ModelProviderError { provider: string; code: string; message: string; retryable: boolean; } export interface ProviderFailureDetail { provider: string; code: "provider_error" | "timeout" | "permission_denied" | "policy_blocked" | "context_overflow"; reason: string; retryable: boolean; attempts: number; } export interface ProviderFallbackResult { provider: string; model: string; requestId: string; response: ModelResponse; fallbackUsed: boolean; failedProviders: ProviderFailureDetail[]; } export interface ModelProvenanceInput { task: string; tenantId?: string; workspaceId?: string; sessionId?: string; runId?: string; phase?: string; actor?: string; initiatedBy?: "human" | "parent_agent" | "subagent" | "system"; role: string; provider: string; model: string; promptId: string; requestId?: string; responseId: string; inputTokens: number; outputTokens: number; estimatedCostUsd: number; usageSource?: "provider" | "runtime" | "estimated" | "unavailable"; costSource?: "provider" | "pricing_estimate" | "free" | "unavailable"; usageUnavailableRationale?: string; costUnavailableRationale?: string; fallbackUsed?: boolean; failedProviders?: ProviderFailureDetail[]; finalProvider?: string; finalModel?: string; directProviderApiAllowed?: boolean; finishReason: ModelResponse["finishReason"]; } export interface ModelProvenanceRecord extends ModelProvenanceInput { timestamp: string; } export type PhaseOutcome = { kind: "done"; notes: string; output?: PhaseStructuredOutput; } | { kind: "gate_pause"; reviewArtifact: string; } | { kind: "qa_fail"; notes: string; } | { kind: "blocked"; notes: string; }; export type PhaseExecutionMode = "deterministic" | "llm"; export interface PhaseExecutorPhase { phase: string; role: string; summary: string; } export interface PhaseStructuredOutput { summary: string; notes: string; verdict: "pass" | "fail"; findings: string[]; decisions: string[]; evidence: string[]; handoff: string; noOpRationale?: string; architecturalConcerns?: { inherited: string[]; selfImposed: string[]; }; sizing?: string; developerPoints?: number; } export interface PhaseLlmResult { mode: PhaseExecutionMode; outcome: PhaseOutcome; artifact?: string; output?: PhaseStructuredOutput; } export interface ModelProvider { id: string; capabilities: ModelProviderCapabilities; complete(request: ModelRequest): Promise; stream?(request: ModelRequest): AsyncIterable; } export interface ConfiguredProviderSummary { scope: string; provider: string; model: string; fallbacks: string[]; maxTokens: number; maxCostUsd: number; timeoutMs: number; retries: number; requiredCapabilities: string[]; } export interface ProviderRouting { provider: string; model: string; fallbacks: string[]; maxTokens: number; maxCostUsd: number; timeoutMs: number; retries: number; requiredCapabilities: string[]; } export type ProviderDataClass = "external" | "local-network" | "test"; export interface ProviderRegistryCredentialEnv { apiKeyEnv?: string; apiKeyFileEnv?: string; baseUrlEnv?: string; } export interface ProviderRegistryEntry { id: string; dataClass: ProviderDataClass; capabilities: ModelProviderCapabilities; defaultCredentialEnv: ProviderRegistryCredentialEnv; } export type ProviderBackedAgentOutcome = "completed" | "blocked" | "failed"; export type ProviderUsageSource = "provider" | "runtime" | "estimated" | "unavailable"; export type ProviderCostSource = "provider" | "pricing_estimate" | "free" | "unavailable"; export interface ProviderBackedAgentBudget { maxTokens: number; maxCostUsd: number; } export interface ProviderBackedAgentPolicy { directProviderApiAllowed: boolean; providerPolicy?: ProviderPolicyConfig; tenantDataPolicy: "local-only" | "redacted-external" | "external-allowed"; allowHybridRuntimeFallback: boolean; } export interface ProviderBackedAgentEvidencePolicy { telemetryLevel: TelemetryLevel; redactionMode: "metadata-only" | "prompt-summary" | "none-for-tests"; } export interface ProviderBackedAgentRequest { taskId: string; runId?: string; phase: string; role: string; actor: string; routing: ProviderRouting; messages: ModelMessage[]; promptId: string; requiredCapabilities: string[]; timeoutMs: number; retries: number; budget: ProviderBackedAgentBudget; policy: ProviderBackedAgentPolicy; evidence: ProviderBackedAgentEvidencePolicy; } export interface ProviderBackedAgentUsage { inputTokens: number; outputTokens: number; usageSource: ProviderUsageSource; usageUnavailableRationale?: string; } export interface ProviderBackedAgentCost { estimatedCostUsd: number; costSource: ProviderCostSource; costUnavailableRationale?: string; } export interface ProviderBackedAgentFallback { used: boolean; failedProviders: ProviderFailureDetail[]; finalProvider: string; finalModel: string; } export interface ProviderBackedAgentProvenance extends ModelProvenanceInput { runId?: string; phase: string; actor: string; requestId: string; directProviderApiAllowed: boolean; } export interface ProviderBackedAgentResult { outcome: ProviderBackedAgentOutcome; provider: string; model: string; requestId: string; responseId?: string; content?: string; usage: ProviderBackedAgentUsage; cost: ProviderBackedAgentCost; fallback: ProviderBackedAgentFallback; provenance?: ProviderBackedAgentProvenance; evidenceArtifact?: string; safeMessage?: string; } export interface WorkflowProvidersConfig { defaults: ProviderRouting; byRole: Record; profiles?: Record; activeProfile?: string; } export interface ProviderPolicyConfig { allowedProviders?: string[]; blockedProviders?: string[]; allowVendorFallbackWithoutApproval?: boolean; } export interface ProviderRuntimeProfile { description?: string; defaults?: ProviderRouting; byRole: Record; budgets?: BudgetPolicy; providerPolicy?: ProviderPolicyConfig; requiredEnv?: string[]; } export interface ProviderRuntimeProfileSummary { name: string; active: boolean; description?: string; roles: string[]; defaultProvider?: string; defaultModel?: string; requiredEnv: string[]; } export interface ProviderProfileSmokeCheck { scope: string; provider: string; model: string; status: "pass" | "fail"; detail: string; } export interface ProviderProfileSmokeResult { profile: string; passed: boolean; checks: ProviderProfileSmokeCheck[]; } export interface ProviderCredentialConfig { apiKeyFile?: string; apiKeyFileEnv?: string; apiKeyEnv?: string; baseUrl?: string; baseUrlEnv?: string; } export interface ProviderCredentialsConfig { byProvider: Record; } export interface BudgetLimit { maxRequests?: number; maxInputTokens?: number; maxOutputTokens?: number; maxTotalTokens?: number; maxEstimatedCostUsd?: number; maxRetries?: number; maxRuntimeMs?: number; action?: "block" | "warn" | "fallback"; } export interface BudgetPolicy { defaults?: BudgetLimit; byRole: Record; byTask: Record; } export type TelemetryLevel = "off" | "metadata" | "prompt-summary" | "prompt-sample" | "eval-dataset"; export interface TelemetryConsentState { enabled: boolean; level: TelemetryLevel; policyVersion: string; actor: string; updatedAt?: string; } export interface GitHubConfig { autoCreatePr?: boolean; baseBranch?: string; } export interface NotificationChannelResult { channel: "slack" | "github"; status: "sent" | "skipped" | "failed"; detail: string; } export interface SlackNotificationConfig { webhookUrl?: string; webhookUrlEnv?: string; } export interface GitHubNotificationConfig { issueComment?: boolean; } export interface NotificationsConfig { slack?: SlackNotificationConfig; github?: GitHubNotificationConfig; } export interface WorkflowConfig { version: number; providers: WorkflowProvidersConfig; providerCredentials?: ProviderCredentialsConfig; budgets?: BudgetPolicy; workflow?: { phaseSequence?: string[]; phaseExecutionMode?: WorkflowPhaseExecutionMode; architectureChallenge?: { enabled?: boolean; phase?: string; role?: string; summary?: string; }; phaseTimeoutMinutes?: number; playbooksDir?: string; phasePlaybooks?: Record; }; tools: Record; telemetry?: TelemetryConsentState; github?: GitHubConfig; notifications?: NotificationsConfig; providerPolicy?: ProviderPolicyConfig; runtimePolicy?: RuntimeExecutionPolicy; qualityContracts?: QualityContractPolicyConfig; staticAnalysis: { preCommit: { required: boolean; checks: string[]; disallowNoVerifyWithoutApproval: boolean; }; ci: { checks: string[]; }; }; }