Adds cost modeling and budget enforcement for transpilation runs: - PortingCostModel: LOC + ambiguity → compute/review/total cost + tier (step 869) - ReviewEffortEstimator: ambiguity/risk → minutes + complexity label (step 870) - ComputeCostEstimator: prior run history → avg duration/tokens (step 871) - MultiPlanAlternativeGenerator: cheap/balanced/rigorous profiles (step 872) - BudgetPolicyEnforcer: approve/requires_token/rejected decisions (step 873) - CostQualityTradeoffReport: efficiency-based plan recommendation (step 874) - whetstone_plan_transpilation_run MCP tool (step 875) - whetstone_estimate_porting_cost MCP tool (step 876) - CostTelemetryIntegration: cost error tracking + over-budget count (step 877) - Sprint64IntegrationSummary (step 878) All 10 steps passing (94 tests). Policy: over-budget plans require explicit reviewer approval token. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#pragma once
|
|
// Step 871: Compute/runtime cost estimator from prior runs.
|
|
#include <string>
|
|
#include <vector>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
struct PriorRunRecord {
|
|
std::string pairId;
|
|
int durationMs = 0;
|
|
int tokenCount = 0;
|
|
};
|
|
|
|
struct ComputeCostEstimate {
|
|
std::string pairId;
|
|
float estimatedDurationMs = 0.0f;
|
|
float estimatedTokens = 0.0f;
|
|
int sampleCount = 0;
|
|
bool hasHistory = false;
|
|
};
|
|
|
|
class ComputeCostEstimator {
|
|
public:
|
|
static ComputeCostEstimate estimate(const std::string& pairId,
|
|
const std::vector<PriorRunRecord>& history) {
|
|
ComputeCostEstimate e;
|
|
e.pairId = pairId;
|
|
e.sampleCount = static_cast<int>(history.size());
|
|
e.hasHistory = !history.empty();
|
|
if (e.hasHistory) {
|
|
float sumDur = 0, sumTok = 0;
|
|
for (const auto& r : history) {
|
|
sumDur += r.durationMs;
|
|
sumTok += r.tokenCount;
|
|
}
|
|
e.estimatedDurationMs = sumDur / e.sampleCount;
|
|
e.estimatedTokens = sumTok / e.sampleCount;
|
|
}
|
|
return e;
|
|
}
|
|
|
|
static nlohmann::json toJson(const ComputeCostEstimate& e) {
|
|
return {{"pair_id", e.pairId},
|
|
{"estimated_duration_ms", e.estimatedDurationMs},
|
|
{"estimated_tokens", e.estimatedTokens},
|
|
{"sample_count", e.sampleCount},
|
|
{"has_history", e.hasHistory}};
|
|
}
|
|
};
|