Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | 13x | /**
* Runtime contract for model-backed providers.
*
* Warden's analysis pipeline builds prompts, handles retry policy, parses
* findings, and aggregates report data. Runtime interfaces are backend
* capabilities underneath that pipeline. Runtimes expose skill execution,
* auxiliary model tasks, and synthesis tasks.
*
* Runtime implementations are responsible for backend-specific execution
* details such as model identifiers, stream events, authentication side
* channels, stderr/diagnostics, telemetry attributes, tool loops, and usage
* normalization. Callers should be able to switch runtimes without changing
* hunk parsing, extraction repair, deduplication, fix gates, or reporting.
*/
import { z } from 'zod';
import type { ToolConfig } from '../../config/schema.js';
import type { UsageStats } from '../../types/index.js';
export const RuntimeNameSchema = z.enum(['claude', 'pi']);
export type RuntimeName = z.infer<typeof RuntimeNameSchema>;
export type SkillRunStatus =
| 'success'
| 'provider_error'
| 'auth_error'
| 'turn_limit'
| 'budget_limit'
| 'aborted'
| 'structured_output_error';
export interface SkillRunOptions {
maxTurns?: number;
model?: string;
abortController?: AbortController;
}
export interface SkillRunRequest {
/** Optional legacy Anthropic API key, used only when a runtime targets Anthropic-compatible models. */
apiKey?: string;
systemPrompt: string;
userPrompt: string;
repoPath: string;
skillName: string;
options: SkillRunOptions;
tools?: ToolConfig;
/**
* Allow explicitly requested mutating tools for trusted internal writer tasks.
* Normal skill analysis keeps this false so hunks remain read-only.
*/
allowMutatingTools?: boolean;
/** Provider-specific settings consumed only by the selected runtime adapter. */
providerOptions?: unknown;
}
export interface SkillRunResult {
status: SkillRunStatus;
text: string;
errors: string[];
usage: UsageStats;
responseId?: string;
responseModel?: string;
sessionId?: string;
durationMs?: number;
durationApiMs?: number;
numTurns?: number;
}
export interface SkillRunResponse {
result?: SkillRunResult;
/** Authentication error surfaced by the runtime, if available out-of-band. */
authError?: string;
/** Captured runtime stderr or diagnostics for clearer failures. */
stderr?: string;
}
export interface AuxiliaryTool {
name: string;
description?: string;
inputSchema: Record<string, unknown>;
}
export type AuxiliaryTask =
| 'extraction'
| 'deduplication'
| 'fix_quality'
| 'fix_evaluation';
export type SynthesisTask =
| 'consolidation'
| 'skill_build';
export type AuxiliaryRunResult<T> =
| { success: true; data: T; usage: UsageStats }
| { success: false; error: string; usage: UsageStats };
interface AuxiliaryRunRequestBase<T> {
task: AuxiliaryTask;
/** Skill or agent name that owns this auxiliary call, when available. */
agentName?: string;
apiKey?: string;
prompt: string;
schema: z.ZodType<T>;
model?: string;
maxTokens?: number;
timeout?: number;
maxRetries?: number;
}
interface AuxiliaryRunRequestWithoutTools<T> extends AuxiliaryRunRequestBase<T> {
tools?: undefined;
executeTool?: undefined;
maxIterations?: undefined;
}
interface AuxiliaryRunRequestWithTools<T> extends AuxiliaryRunRequestBase<T> {
tools: AuxiliaryTool[];
executeTool: (name: string, input: Record<string, unknown>) => Promise<string>;
maxIterations?: number;
}
export type AuxiliaryRunRequest<T> = AuxiliaryRunRequestWithoutTools<T> | AuxiliaryRunRequestWithTools<T>;
export interface SynthesisRunRequest<T> {
task: SynthesisTask;
/** Skill or agent name that owns this synthesis call, when available. */
agentName?: string;
apiKey?: string;
prompt: string;
schema: z.ZodType<T>;
model?: string;
maxTokens?: number;
timeout?: number;
maxRetries?: number;
}
export interface Runtime {
readonly name: RuntimeName;
runSkill(request: SkillRunRequest): Promise<SkillRunResponse>;
runAuxiliary<T>(request: AuxiliaryRunRequest<T>): Promise<AuxiliaryRunResult<T>>;
runSynthesis<T>(request: SynthesisRunRequest<T>): Promise<AuxiliaryRunResult<T>>;
}
|