export const TOPOLOGIES = ["direct", "scout", "swarm", "deep", "warroom"] as const; export const MODES = ["auto", ...TOPOLOGIES] as const; export const POLICIES = ["economy", "balanced", "quality", "max"] as const; export const PRIVACY_CLASSES = ["public", "internal", "restricted", "secret"] as const; export type Topology = (typeof TOPOLOGIES)[number]; export type Mode = (typeof MODES)[number]; export type Policy = (typeof POLICIES)[number]; export type PrivacyProfile = "private" | "free"; export type PrivacyClass = (typeof PRIVACY_CLASSES)[number]; export type Intent = "answer" | "investigate" | "review" | "change" | "fix"; export type Breadth = "tiny" | "local" | "cross-module" | "wide"; export type Level = "low" | "medium" | "high"; export type Verifiability = "strong" | "partial" | "weak"; export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"; export interface DeclaredShape { intent?: Intent; risk?: Level; coupling?: Level; uncertainty?: Level; independentUnits?: number; } export interface TaskShape { intent: Intent; knownScope: boolean; mentionedPaths: string[]; breadth: Breadth; coupling: Level; uncertainty: Level; risk: Level; verifiability: Verifiability; independentUnits: number; externalResearchRequired: boolean; writerOverlapRisk: boolean; liveCrossAgentDependency: boolean; repeatedFailureCount: number; failureFingerprint?: string; priorDisagreement: boolean; confidence: number; reasonCodes: string[]; } export interface ProposedShard { id: string; objective: string; scope: string[]; excludedScope: string[]; lens: string; evidenceTarget: string; expectedOutput: string; canRunIndependently: boolean; canChangeFinalDecision: boolean; writeIntent: boolean; acceptanceCommand?: string; } export interface FactEvidence { path?: string; lines?: string; commandId?: string; observation: string; } export interface AgentFact { id: string; claim: string; evidence: FactEvidence[]; confidence: number; } export interface AgentHypothesis { id: string; claim: string; confidence: number; status?: "open" | "confirmed" | "rejected"; } export interface VerificationResult { checkId: string; passed: boolean; command: string; exitCode: number | null; durationMs: number; stdout: string; stderr: string; fingerprint?: FailureFingerprint; } export interface ResourceRequest { reason: string; requestedTopology?: Topology; requestedModel?: string; } export interface AgentResult { schemaVersion: 1; status: "complete" | "blocked" | "partial"; summary: string; facts: AgentFact[]; hypotheses: AgentHypothesis[]; unknowns: string[]; dependencies: string[]; verification?: VerificationResult[]; resourceRequest?: ResourceRequest; attributionManifest?: AttributionManifest; } export interface FactRef { id: string; claim: string; } export interface TaskEnvelope { envelopeVersion: 1; trace: { runId: string; nodeId: string; parentNodeId?: string }; goal: string; taskSynopsis: string; scope: { paths: string[]; excludedPaths: string[]; symbols?: string[] }; lens: string; evidenceTarget: string; knownFacts: FactRef[]; openQuestions: string[]; constraints: string[]; declaredArtifacts?: string[]; acceptance?: { command: string; expected: string }; privacyProfile: PrivacyProfile; outputContract: { schemaName: string; maxOutputTokens: number; maxFacts: number; maxHypotheses: number; maxUnknowns: number }; } export interface FailureFingerprint { hash: string; class: string; components: string[]; } export interface VerificationPlan { checks: Array<{ id: string; command: string; required: boolean; timeoutMs: number; expectedExitCode: number }>; } export interface AttributionManifest { usedFactIds: string[]; rejectedFactIds: Array<{ id: string; reason: "duplicate" | "unsupported" | "irrelevant" | "contradicted" }>; decisions: Array<{ decisionId: string; description: string; supportingFactIds: string[] }>; changes: Array<{ path: string; supportingDecisionIds: string[] }>; } export interface ProviderHealth { state: "healthy" | "degraded" | "throttled" | "cooldown"; recent429: number; recent5xx: number; p50LatencyMs: number; p95LatencyMs: number; concurrency: number; cooldownUntil?: string; } export interface PriceRate { input: number; cached: number; output: number } /** * Credit prices per 1,000,000 tokens. `creditsPerUsd` is the rate used to derive an entry for a * model this document does not name, from the USD cost the Pi model registry reports for it — see * `resolveCatalog`. It is a property of the document because a run-local rate would make the same * model cost different amounts in different runs, and the weekly and daily caps sum credits across * runs off the event log. */ export interface PriceCatalog { version: string; currency: "credits"; creditsPerUsd?: number; models: Record } export interface BudgetState { spentCredits: number; hardCap: number; softCap: number; internalStopTarget: number; weeklyCreditBudget?: number; dailyCreditBudget?: number; } export interface PolicyCaps { softCap: number; internalStopTarget: number; hardCap: number; maxRepairCycles: number; initialScouts: number; maxParallel: number; maxTotal: number; maxWaves: number } /** * The models a profile is allowed to use, declared by whoever runs UltraPi. * * `tiers` is ordered weakest-to-strongest and the order is load-bearing: a model's * position is its capability rank, which drives root-model escalation and the * fallback order used when a provider stops answering. Anything outside `tiers` * is refused at every echelon, so the roster stays fail-closed while ceasing to be * a property of this repository. */ export interface ModelRosterConfig { tiers: string[]; nonCritical?: string[] } export interface UltraConfig { projectExcludedPaths?: string[]; forbiddenTopologies?: Mode[]; pinnedAcceptanceCommand?: string; projectScopePaths?: string[]; schemaVersion: 1; configVersion: string; policyVersion: string; profile: PrivacyProfile; mode: Mode; policy: Policy; budgets: { weeklyCreditBudget?: number; dailyCreditBudget?: number; acknowledged: boolean }; models: ModelRosterConfig; root: { model: string; thinking: ThinkingLevel }; scout: { model: string; thinking: ThinkingLevel; modelByLens?: Record; allowedSkills?: string[]; initial: number; maxParallel: number; maxTotal: number; maxTurns: number; maxOutputTokens: number }; boundedWriter: { model: string; thinking: ThinkingLevel; modelByLens?: Record; maxTurns: number; maxOutputTokens: number }; repair: { model: string; thinking: ThinkingLevel; maxAttempts: number; sameFingerprintEscalation: boolean }; deep: { model: string; thinking: ThinkingLevel; maxTurns: number }; arbitration: { model: string; thinking: ThinkingLevel; maxTurns: number }; warRoom: { autoEnabled: boolean; maxSpecialists: number; maxRounds: number; maxMessagesPerMember: number }; piAgentsBudgets: { maxAgents: number; maxParallelism: number; maxIterations: number; maxDepth: number; maxTurns: number; maxCost?: number }; context: { envelopeTargetTokens: number; envelopeHardCapTokens: number; compactAtRatio: number; blockWideSwarmAtRatio: number }; telemetry: { rawVaultEnabled: boolean; rawRetentionDays: number; analyticsRetentionDays: number }; experiment: { challengerAllocation: number; stopLossSuccessDrop: number; stopLossCostIncrease: number }; compatibility: { piVersion: string; piAgentsVersion: string }; } export type ChecklistState = "pending" | "active" | "done" | "blocked"; export interface ChecklistItem { id: string; title: string; owner: string; state: ChecklistState; } export interface TaskLedger { goal: string; checklist?: ChecklistItem[]; acceptedFacts: AgentFact[]; decisions: Array<{ id: string; description: string }>; changedFiles: string[]; verificationState: "pending" | "passed" | "failed"; activeRisks: string[]; rejectedHypotheses: string[]; remainingBudget: BudgetState; configVersion: string; } export interface RouteDecision { topology: Topology; model: string; thinking: ThinkingLevel; fanout: number; proposedTopology: Topology; proposedModel: string; proposedFanout: number; overridden: boolean; overrideReason?: string; reasonCodes: string[]; needsProposal: boolean; } export interface DispatchRequest { objective: string; mode?: Mode; policy?: Policy; paths?: string[]; excludePaths?: string[]; declaredShape?: DeclaredShape; acceptanceCommand?: string; privacyClass?: PrivacyClass; force?: boolean; } export interface DispatchResult { runId: string; recoveredFromRunId?: string; rootHandoff?: string; rootSelection?: { model: string; thinking: ThinkingLevel; stableModel: string; cheapModel: string; expectedBenefit: number }; topology: Topology; status: "direct" | "scheduled" | "blocked"; summary: string; shape: TaskShape; reasonCodes: string[]; piAgentsRunId?: string; facts?: AgentFact[]; } export interface BaseEvent { schemaVersion: 1; eventId: string; timestamp: string; sessionId: string; taskId: string; runId: string; spanId: string; parentSpanId?: string; configVersion: string; policyVersion: string; experimentId?: string; profile: PrivacyProfile; eventType: string; [key: string]: unknown; }