import type { ContextPackRoutingDebug, ContextPackTaskKind, ImplementationPackGuidance } from '../contracts/context-pack.js'; import { KnowledgeGraph } from '../contracts/graph.js'; import type { ContextSessionDiagnostics, ContextSessionState } from '../contracts/context-session.js'; import { type BenchmarkEnvironment, type BenchmarkEnvironmentContamination } from './benchmark/environment.js'; import { type PromptRunnerUsage } from './prompt-runner.js'; import { type CompactRetrieveResult, type RetrieveResult } from '../runtime/retrieve.js'; import { type McpToolProfile } from '../runtime/stdio/definitions.js'; export type CompareBaselineMode = 'full' | 'bounded' | 'pack_only' | 'native_agent'; export type CompareRunMode = 'baseline' | 'madar'; export type CompareRunStatus = 'not_run' | 'succeeded' | 'failed' | 'context_overflow'; export type CompareFailureReason = 'prompt_too_long' | 'runner_error' | 'exec_error'; export type ComparePromptTokenSource = 'estimated_cl100k_base' | 'claude_reported_input' | 'gemini_reported_input'; export interface ComparePromptProviderProofEntry { provider: 'claude' | 'gemini' | null; input_tokens_source: ComparePromptTokenSource; effective_tokens_source: 'provider_cache_read_tokens' | 'provider_input_minus_zero_cache' | 'session_reuse_estimate'; total_tokens_source: 'provider_reported_total' | 'not_available'; } export interface ComparePromptProviderProof { baseline: ComparePromptProviderProofEntry; madar: ComparePromptProviderProofEntry; reduction_basis: 'provider_reported' | 'mixed' | 'estimated'; } export interface ComparePromptPack { kind: 'baseline' | 'madar'; question: string; prompt: string; session_payload: string; token_count: number; session_payload_token_count: number; effective_token_count: number; reused_context_tokens: number; session_diagnostics: ContextSessionDiagnostics; session_state: ContextSessionState; } export interface BuildBaselinePromptPackInput { question: string; graph: KnowledgeGraph; corpusText: string; mode: CompareBaselineMode; maxTokens?: number; session?: ContextSessionState; } export interface BuildMadarPromptPackInput { graphPath?: string; question: string; retrieval: RetrieveResult; session?: ContextSessionState; } export interface ComparePromptArtifactPaths { output_dir: string; baseline_prompt: string; madar_prompt: string; report: string; share_safe_report: string; } export interface CompareAnswerArtifactPaths { baseline: string; madar: string; } export interface CompareExecCommandSummary { command: string | null; placeholders: string[]; redacted: true; } export interface ComparePromptTokenEstimator { source: string; model: string; exact: boolean; } export type ComparePromptUsage = PromptRunnerUsage; export interface CompareReportPack extends CompactRetrieveResult { claims?: NonNullable; coverage?: NonNullable; selection_diagnostics?: NonNullable; } export interface CompareMadarTraceTurnSummary { turn: number; tool_call_count: number; tools: string[]; madar_tool_discovery_count?: number; madar_tool_discovery_tool_indexes?: number[]; agent_directive_seen?: string[]; } type CompareMadarTraceOutcome = 'no_install' | 'madar_available_but_unused' | 'madar_first_bounded' | 'madar_invoked' | 'madar_invoked_after_broad_exploration' | 'madar_invoked_with_followup_exploration'; export interface CompareMadarTrace { source: 'claude_messages_tool_use'; summary: string; tool_call_count: number; tool_calls_by_name: Record; per_turn: CompareMadarTraceTurnSummary[]; agent_directive_seen?: string[]; madar_mcp_call_count: number; madar_mcp_calls_by_name: Record; first_madar_turn?: number; first_madar_tool_name?: string; pre_madar_broad_exploration_tool_call_count?: number; pre_madar_broad_exploration_tool_calls_by_name?: Record; context_pack_call_count: number; focused_follow_up_tool_call_count: number; broad_exploration_tool_call_count: number; broad_exploration_tool_calls_by_name: Record; exploration_outcome: CompareMadarTraceOutcome; exploration_summary: string; } export type NativeAgentMeasurementValidity = 'valid' | 'degraded' | 'invalid'; export type NativeAgentTraceStatus = 'trace_available' | 'missing_verbose_trace'; interface NativeAgentInstallArtifactCheck { label: string; ok: boolean; detail: string; path: string; } export interface NativeAgentInstallCheck { verified: boolean; artifacts: NativeAgentInstallArtifactCheck[]; tool_profile: McpToolProfile; } export interface ComparePromptReport { question: string; graph_path: string; exec_command: CompareExecCommandSummary; baseline_mode: CompareBaselineMode; baseline_prompt_tokens: number; madar_prompt_tokens: number; reduction_ratio: number; baseline_effective_prompt_tokens: number; madar_effective_prompt_tokens: number; effective_reduction_ratio: number; baseline_reused_context_tokens: number; madar_reused_context_tokens: number; baseline_total_tokens: number | null; madar_total_tokens: number | null; total_reduction_ratio: number | null; baseline_prompt_tokens_estimated: number; madar_prompt_tokens_estimated: number; reduction_ratio_estimated: number; prompt_token_estimator: ComparePromptTokenEstimator; prompt_token_source: { baseline: ComparePromptTokenSource; madar: ComparePromptTokenSource; }; usage: { baseline: ComparePromptUsage | null; madar: ComparePromptUsage | null; }; started_at: string; completed_at: string; elapsed_ms: { baseline: number; madar: number; }; status: { baseline: CompareRunStatus; madar: CompareRunStatus; }; answer_paths: CompareAnswerArtifactPaths; exit_code: { baseline: number | null; madar: number | null; }; stderr: { baseline: string | null; madar: string | null; }; failure_reason: { baseline: CompareFailureReason | null; madar: CompareFailureReason | null; }; evidence: { baseline: string | null; madar: string | null; }; provider_proof?: ComparePromptProviderProof; madar_trace?: CompareMadarTrace; pack?: CompareReportPack; routing?: ContextPackRoutingDebug; paths: ComparePromptArtifactPaths; } export interface GenerateCompareArtifactsInput { graphPath: string; question?: string | null; questionsPath?: string | null; outputDir: string; execTemplate: string; task?: ContextPackTaskKind; baselineMode: CompareBaselineMode; perArmTimeoutSeconds?: number; validationTimeoutSeconds?: number; heartbeatIntervalMs?: number; strictMadarFirst?: boolean; strictBenchmarkReadiness?: boolean; allowNoInstall?: boolean; why?: boolean; corpusText?: string; limit?: number | null; retrievalBudget?: number; baselineMaxTokens?: number; now?: Date; } export interface GenerateCompareArtifactsResult { graph_path: string; output_root: string; reports: ComparePromptReport[]; } export interface CompareExecTemplateValues { promptFile: string; question: string; mode: CompareRunMode; outputFile: string; } export interface ComparePromptExecution { mode: CompareRunMode; question: string; promptFile: string; outputFile: string; command: string; } export interface ComparePromptRunnerResult { exitCode: number; stdout: string; stderr: string; elapsedMs: number; } export interface ExecuteCompareRunsDependencies { runner?: (execution: ComparePromptExecution) => Promise; now?: () => Date; } export interface NativeAgentPromptContractAssessment { status: 'followed' | 'violated' | 'not_measured'; evidence: string[]; } export declare function expandCompareExecTemplate(template: string, values: CompareExecTemplateValues, platform?: NodeJS.Platform): string; type BenchmarkReadinessRetrieval = { matched_nodes: Array>; execution_slice?: CompareReportPack['execution_slice']; answer_contract?: CompareReportPack['answer_contract']; retrieval_gate?: CompareReportPack['retrieval_gate']; }; export declare function resolveSuggestedGraphScopePath(graphPath: string, suggestedGraphScope: string): string; export declare function assessBenchmarkReadinessFromRetrieveResult(input: { graphPath: string; retrieval: BenchmarkReadinessRetrieval; }): BenchmarkReadiness; export declare function buildBaselinePromptPack(input: BuildBaselinePromptPackInput): ComparePromptPack; export declare function buildMadarPromptPack(input: BuildMadarPromptPackInput): ComparePromptPack; export declare function buildNativeAgentPrompt(question: string, optionsOrProfile?: McpToolProfile | { profile?: McpToolProfile; task?: ContextPackTaskKind; implementation?: ImplementationPackGuidance; runtimeFlowGuidance?: { missingPhases?: string[]; rescopedTo?: string | null; retrievalReady?: boolean; }; }): string; export declare function resolveCompareQuestions(options: Pick): string[]; export declare function generateCompareArtifacts(input: GenerateCompareArtifactsInput): GenerateCompareArtifactsResult; export declare function executeCompareRuns(input: GenerateCompareArtifactsInput, dependencies?: ExecuteCompareRunsDependencies): Promise; export declare function formatCompareSummary(result: GenerateCompareArtifactsResult): string; export declare function runCompareCommand(input: GenerateCompareArtifactsInput, dependencies?: ExecuteCompareRunsDependencies): Promise; export interface AnthropicUsageBlock { input_tokens: number; cache_creation_input_tokens: number; cache_read_input_tokens: number; output_tokens: number; } export interface AnthropicResultEvent { model: string | null; num_turns: number; duration_ms: number; total_cost_usd: number | null; result: string | null; usage: AnthropicUsageBlock; } export type NativeAgentRunStatus = { kind: 'succeeded'; model: string | null; usage: AnthropicUsageBlock; total_input_tokens_anthropic_exact: number; uncached_input_tokens_anthropic_exact: number; cached_input_tokens_anthropic_exact: number; total_cost_usd: number | null; num_turns: number; duration_ms: number; result_path: string; } | { kind: 'answer_only'; evidence: string | null; exit_code: number; stderr: string | null; result_path: string; } | { kind: 'runner_error'; evidence: string | null; exit_code: number | null; stderr: string | null; failure_reason?: 'timed_out'; }; export type NativeAgentTokenRegressionMetric = 'uncached_input_tokens' | 'cache_creation_input_tokens'; export interface NativeAgentClaimAssessment { routing_efficiency: { status: 'improved' | 'not_improved' | 'not_measured'; evidence: string[]; }; token_reduction: { status: 'proven' | 'not_proven' | 'not_measured'; evidence: string[]; }; } export type NativeAgentBenchmarkCheckStatus = 'win' | 'loss' | 'flat' | 'not_measured'; export type NativeAgentBenchmarkOverallOutcome = 'full_win' | 'partial_win' | 'regression' | 'not_measured'; export interface NativeAgentBenchmarkOutcome { outcome: NativeAgentBenchmarkOverallOutcome; checks: { routing_tool_latency: NativeAgentBenchmarkCheckStatus; token: NativeAgentBenchmarkCheckStatus; fresh_token: NativeAgentBenchmarkCheckStatus; cost: NativeAgentBenchmarkCheckStatus; turns: NativeAgentBenchmarkCheckStatus; }; evidence: string[]; } export interface NativeAgentWorkflowOutcome { wrong_file_edits?: number | null; validation_passed?: boolean | null; review_time_seconds?: number | null; rework_loops?: number | null; human_intervention_required?: boolean | null; evidence?: string[]; } export interface NativeAgentToolCallCountsEntry { total: number; Read: number; Bash: number; Glob: number; Grep: number; ToolSearch: number; other: Record; } export interface NativeAgentToolCallCounts { baseline: NativeAgentToolCallCountsEntry; madar: NativeAgentToolCallCountsEntry; } export type ImplementValidationStatus = 'passed' | 'failed' | 'setup_error' | 'not_run'; export type ReviewerVisibleStatus = 'passed' | 'failed' | 'not_scored'; export type NativeAgentHumanReviewStatus = 'pending' | 'passed' | 'failed'; export interface ImplementValidationCommandResult { command: string; status: Exclude; exit_code: number | null; stdout: string | null; stderr: string | null; } export interface ImplementValidationResult { status: ImplementValidationStatus; commands: ImplementValidationCommandResult[]; } export interface ReviewerVisibleCheckResult { path: string; passed: boolean; missing_required_snippets: string[]; forbidden_snippets_present: string[]; } export interface ReviewerVisibleCorrectnessResult { status: ReviewerVisibleStatus; checks: ReviewerVisibleCheckResult[]; } export interface ImplementOutcomeArmResult { files_touched: string[]; wrong_file_edits: string[]; validation: ImplementValidationResult; reviewer_visible_correctness: ReviewerVisibleCorrectnessResult; } export interface ImplementOutcomeReport { baseline: ImplementOutcomeArmResult; madar: ImplementOutcomeArmResult; } export interface NativeAgentCompareReport { baseline_mode: 'native_agent'; task: ContextPackTaskKind; question: string; graph_path: string; isolation: boolean; environment: BenchmarkEnvironment; environment_contamination: BenchmarkEnvironmentContamination; exec_command: CompareExecCommandSummary; baseline: NativeAgentRunStatus; madar: NativeAgentRunStatus; install_verified: boolean; measurement_validity: NativeAgentMeasurementValidity; trace_status: NativeAgentTraceStatus; madar_mcp_call_count: number; tool_call_counts?: NativeAgentToolCallCounts; madar_trace?: CompareMadarTrace; reductions: { input_tokens: number | null; uncached_input_tokens?: number | null; cache_creation_input_tokens?: number | null; num_turns: number | null; duration_ms: number | null; cost_usd: number | null; } | null; token_regression: boolean; token_regression_reasons: NativeAgentTokenRegressionMetric[]; benchmark_readiness?: BenchmarkReadiness; answer_contract?: CompareReportPack['answer_contract']; execution_slice?: CompareReportPack['execution_slice']; implementation_guidance?: ImplementationPackGuidance; implement_outcome?: ImplementOutcomeReport; prompt_contract?: NativeAgentPromptContractAssessment; claim_assessment?: NativeAgentClaimAssessment; benchmark_outcome?: NativeAgentBenchmarkOutcome; workflow_outcome?: NativeAgentWorkflowOutcome; prompt_token_source: { baseline: 'anthropic_provider_reported' | 'unknown'; madar: 'anthropic_provider_reported' | 'unknown'; }; provider_proof?: { baseline: { provider: 'anthropic' | null; input_tokens_source: 'anthropic_provider_reported' | 'unknown'; effective_tokens_source: 'anthropic_provider_reported' | 'unknown'; total_tokens_source: 'anthropic_provider_reported' | 'unknown'; }; madar: { provider: 'anthropic' | null; input_tokens_source: 'anthropic_provider_reported' | 'unknown'; effective_tokens_source: 'anthropic_provider_reported' | 'unknown'; total_tokens_source: 'anthropic_provider_reported' | 'unknown'; }; reduction_basis: 'provider_reported' | 'mixed' | 'unknown'; }; started_at: string; completed_at: string; answer_quality?: { gate: string; prompt: string; baseline: { passed: boolean; missing_required_terms: string[]; forbidden_terms_present: string[]; }; madar: { passed: boolean; missing_required_terms: string[]; forbidden_terms_present: string[]; }; human_review: { status: NativeAgentHumanReviewStatus; required_concepts: string[]; answer_quality_notes: string[]; manual_review_notes: string[]; } | null; }; paths: { output_dir: string; report: string; share_safe_report: string; baseline_answer: string; madar_answer: string; baseline_prompt: string; madar_prompt: string; prompt_file: string; }; } export interface NativeAgentCompareResult { graph_path: string; output_root: string; reports: NativeAgentCompareReport[]; answer_quality?: { questions_checked: number; baseline_passed: number; madar_passed: number; madar_required_terms_missing: number; madar_forbidden_terms_present: number; human_review: { pending: number; passed: number; failed: number; not_configured: number; }; }; } export interface NativeAgentRunnerInput { mode: CompareRunMode; question: string; promptFile: string; outputFile: string; command: string; cwd?: string; workspaceRoot?: string; signal?: AbortSignal; } export interface NativeAgentRunnerResult { exitCode: number; stdout: string; stderr: string; elapsedMs: number; } export type NativeAgentRunner = (input: NativeAgentRunnerInput) => Promise; export type BenchmarkReadinessStatus = 'ready' | 'degraded' | 'not_ready'; export interface BenchmarkReadiness { status: BenchmarkReadinessStatus; reasons: string[]; suggested_graph_scope: string | null; rescope_attempted?: boolean; rescoped_to?: string | null; } export interface BenchmarkReadinessInput { graphPath: string; projectRoot: string; question: string; } export interface ExecuteNativeAgentCompareDependencies { runner?: NativeAgentRunner; now?: () => Date; writeStderr?: (message: string) => void; assessBenchmarkReadiness?: (input: BenchmarkReadinessInput) => BenchmarkReadiness; } export declare function inspectClaudeNativeAgentInstall(projectRoot: string): NativeAgentInstallCheck; export declare class NativeAgentInstallRequiredError extends Error { readonly check: NativeAgentInstallCheck; constructor(check: NativeAgentInstallCheck); } export declare class BenchmarkReadinessError extends Error { readonly readiness: BenchmarkReadiness; constructor(readiness: BenchmarkReadiness); } /** * Parse the trailing JSON event from `claude --output-format json` (or stream-json) * stdout. Returns null when no parseable trailing object with a usage block * exists, so the caller can classify the run as runner_error. */ export declare function parseAnthropicResultEvent(stdout: string): AnthropicResultEvent | null; export declare function executeNativeAgentCompare(input: GenerateCompareArtifactsInput, dependencies?: ExecuteNativeAgentCompareDependencies): Promise; export declare function formatNativeAgentCompareSummary(result: NativeAgentCompareResult): string; export {};