Sprint 283: poly-pipeline (steps 1943–1947)

PipelineStageSpec/Registry, PipelineGraph (Kahn topo sort), PipelineExecutionPlan,
PipelineParityValidator — 26/26 tests pass.
Integration step 1947: Python→Rust→Go→Haskell→TypeScript pipeline verified.
Metrics: 7 whetstone calls, 8566 tokens.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bill
2026-03-01 22:25:57 -07:00
parent 84708da611
commit 95cf04008e
11 changed files with 790 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#pragma once
#include "PipelineGraph.h"
#include "PipelineStageSpec.h"
#include <string>
#include <vector>
namespace whetstone {
class PipelineExecutionPlan {
public:
void addStage(const PipelineStageSpec& spec) {
registry_.registerStage(spec);
graph_.addStage(spec.stageId);
}
void addEdge(const std::string& fromId, const std::string& toId) {
graph_.addEdge(fromId, toId);
}
// Stages in topological order.
std::vector<PipelineStageSpec> executionOrder() const {
std::vector<PipelineStageSpec> result;
for (const auto& id : graph_.topologicalOrder())
result.push_back(registry_.getStage(id));
return result;
}
// Language per stage in execution order.
std::vector<std::string> languageSequence() const {
std::vector<std::string> langs;
for (const auto& spec : executionOrder())
langs.push_back(spec.language);
return langs;
}
bool isValid() const {
return !graph_.hasCycle() && graph_.stageCount() > 0;
}
// Pairs "langA->langB" wherever adjacent stages in execution order differ in language.
std::vector<std::string> boundaryPairs() const {
auto order = executionOrder();
std::vector<std::string> pairs;
for (std::size_t i = 1; i < order.size(); ++i) {
if (order[i-1].language != order[i].language)
pairs.push_back(order[i-1].language + "->" + order[i].language);
}
return pairs;
}
private:
PipelineStageRegistry registry_;
PipelineGraph graph_;
};
} // namespace whetstone

View File

@@ -0,0 +1,84 @@
#pragma once
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
namespace whetstone {
class PipelineGraph {
public:
void addStage(const std::string& stageId) {
// Ensure entry exists even with no edges.
succ_[stageId];
pred_[stageId];
}
void addEdge(const std::string& fromId, const std::string& toId) {
succ_[fromId].push_back(toId);
pred_[toId].push_back(fromId);
// Ensure reverse entries exist.
succ_[toId];
pred_[fromId];
}
std::vector<std::string> successors(const std::string& stageId) const {
auto it = succ_.find(stageId);
return it == succ_.end() ? std::vector<std::string>{} : it->second;
}
std::vector<std::string> predecessors(const std::string& stageId) const {
auto it = pred_.find(stageId);
return it == pred_.end() ? std::vector<std::string>{} : it->second;
}
// Kahn's algorithm. Returns empty if cycle detected.
std::vector<std::string> topologicalOrder() const {
// Build in-degree map.
std::map<std::string, int> indegree;
for (const auto& [id, _] : succ_) indegree[id] = 0;
for (const auto& [id, preds] : pred_)
indegree[id] = static_cast<int>(preds.size());
std::queue<std::string> q;
for (const auto& [id, deg] : indegree)
if (deg == 0) q.push(id);
std::vector<std::string> order;
while (!q.empty()) {
auto cur = q.front(); q.pop();
order.push_back(cur);
for (const auto& s : successors(cur)) {
if (--indegree[s] == 0) q.push(s);
}
}
// If we didn't visit all nodes, there's a cycle.
if (order.size() != succ_.size()) return {};
return order;
}
bool hasCycle() const { return topologicalOrder().empty() && !succ_.empty(); }
std::vector<std::string> sourceStages() const {
std::vector<std::string> result;
for (const auto& [id, preds] : pred_)
if (preds.empty()) result.push_back(id);
return result;
}
std::vector<std::string> sinkStages() const {
std::vector<std::string> result;
for (const auto& [id, succs] : succ_)
if (succs.empty()) result.push_back(id);
return result;
}
int stageCount() const { return static_cast<int>(succ_.size()); }
private:
std::map<std::string, std::vector<std::string>> succ_;
std::map<std::string, std::vector<std::string>> pred_;
};
} // namespace whetstone

View File

@@ -0,0 +1,57 @@
#pragma once
#include <map>
#include <string>
#include <vector>
namespace whetstone {
struct StageOutput {
std::string stageId;
std::string language;
std::string output;
bool success = true;
};
class PipelineParityValidator {
public:
void setReference(const std::string& stageId, const std::string& output) {
references_[stageId] = output;
}
struct ValidationResult {
bool passed = true;
std::vector<std::string> failedStages;
};
// For each StageOutput: fail if success=false OR (reference set AND output != reference).
ValidationResult validate(const std::vector<StageOutput>& outputs) const {
ValidationResult result;
for (const auto& so : outputs) {
bool fail = !so.success;
if (!fail) {
auto it = references_.find(so.stageId);
if (it != references_.end() && so.output != it->second)
fail = true;
}
if (fail) {
result.passed = false;
result.failedStages.push_back(so.stageId);
}
}
return result;
}
// True if output matches reference, or no reference set for this stage.
bool stagePass(const std::string& stageId, const std::string& output) const {
auto it = references_.find(stageId);
if (it == references_.end()) return true;
return output == it->second;
}
int referenceCount() const { return static_cast<int>(references_.size()); }
private:
std::map<std::string, std::string> references_;
};
} // namespace whetstone

View File

@@ -0,0 +1,53 @@
#pragma once
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
namespace whetstone {
struct PipelineStageSpec {
std::string stageId;
std::string language;
std::string description;
std::string inputType;
std::string outputType;
};
class PipelineStageRegistry {
public:
void registerStage(const PipelineStageSpec& spec) {
stages_[spec.stageId] = spec;
}
PipelineStageSpec getStage(const std::string& stageId) const {
auto it = stages_.find(stageId);
if (it == stages_.end())
throw std::out_of_range("stage not found: " + stageId);
return it->second;
}
bool hasStage(const std::string& stageId) const {
return stages_.count(stageId) > 0;
}
std::vector<std::string> stageIds() const {
std::vector<std::string> ids;
for (const auto& [id, _] : stages_) ids.push_back(id);
return ids;
}
std::vector<PipelineStageSpec> stagesForLanguage(const std::string& language) const {
std::vector<PipelineStageSpec> result;
for (const auto& [_, spec] : stages_)
if (spec.language == language) result.push_back(spec);
return result;
}
int stageCount() const { return static_cast<int>(stages_.size()); }
private:
std::map<std::string, PipelineStageSpec> stages_;
};
} // namespace whetstone

View File

@@ -0,0 +1,21 @@
#pragma once
// Sprint 283 Integration Summary
// Steps 19431947: poly-pipeline
//
// 1943: PipelineStageSpec + PipelineStageRegistry — stage descriptors
// 1944: PipelineGraph — DAG with Kahn topo sort
// 1945: PipelineExecutionPlan — registry + graph combined
// 1946: PipelineParityValidator — reference-output validation
// 1947: Integration — 5-stage Python→TS pipeline
#include <string>
namespace whetstone {
struct Sprint283IntegrationSummary {
int stepsCompleted = 5;
bool success = true;
std::string sprintName() const { return "Sprint 283: poly-pipeline"; }
};
} // namespace whetstone