Step 528: integrate constrained taskitem execution gate
This commit is contained in:
86
editor/src/ConstrainedTaskitemIntegration.h
Normal file
86
editor/src/ConstrainedTaskitemIntegration.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
// Step 528: Phase 27a Integration
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "ConstraintViolationDiagnostics.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct ConstrainedExecutionRequest {
|
||||
json taskitemJson;
|
||||
std::string nodeKind;
|
||||
std::string requestedOp;
|
||||
std::vector<std::string> requestedSymbols;
|
||||
std::vector<ScopedSymbol> visibleSymbols;
|
||||
};
|
||||
|
||||
struct ConstrainedExecutionResult {
|
||||
bool routed = false;
|
||||
bool executed = false;
|
||||
TaskitemContract contract;
|
||||
ScopeSnapshot scopeSnapshot;
|
||||
ConstraintDiagnosticPacket diagnostics;
|
||||
std::vector<std::string> schemaErrors;
|
||||
};
|
||||
|
||||
class ConstrainedTaskitemIntegration {
|
||||
public:
|
||||
static ConstrainedExecutionResult run(const ConstrainedExecutionRequest& request,
|
||||
const LegalOperationGraph& graph,
|
||||
const SymbolScopeExtractor& scopeExtractor) {
|
||||
ConstrainedExecutionResult result;
|
||||
|
||||
auto validation = TypedTaskitemContractSchema::parseAndValidate(request.taskitemJson);
|
||||
if (!validation.valid) {
|
||||
result.schemaErrors = validation.errors;
|
||||
result.diagnostics = schemaFailurePacket(validation.errors);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.contract = validation.contract;
|
||||
std::set<std::string> forbidden(result.contract.forbiddenSymbols.begin(),
|
||||
result.contract.forbiddenSymbols.end());
|
||||
|
||||
result.scopeSnapshot = scopeExtractor.buildSnapshot(
|
||||
result.contract.language,
|
||||
request.nodeKind,
|
||||
request.visibleSymbols,
|
||||
forbidden);
|
||||
|
||||
ConstraintCheckInput checkInput;
|
||||
checkInput.contract = result.contract;
|
||||
checkInput.language = result.contract.language;
|
||||
checkInput.nodeKind = request.nodeKind;
|
||||
checkInput.requestedOp = request.requestedOp;
|
||||
checkInput.requestedSymbols = request.requestedSymbols;
|
||||
checkInput.scopeSnapshot = result.scopeSnapshot;
|
||||
|
||||
result.diagnostics = ConstraintViolationDiagnostics::evaluate(
|
||||
checkInput, graph, scopeExtractor);
|
||||
result.routed = result.diagnostics.ok;
|
||||
result.executed = result.diagnostics.ok;
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static ConstraintDiagnosticPacket schemaFailurePacket(
|
||||
const std::vector<std::string>& errors) {
|
||||
ConstraintDiagnosticPacket packet;
|
||||
packet.ok = false;
|
||||
packet.recommendedAction = "escalate";
|
||||
for (const auto& error : errors) {
|
||||
packet.violations.push_back({
|
||||
"under_constrained_contract",
|
||||
"Taskitem contract failed schema validation",
|
||||
error,
|
||||
false
|
||||
});
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user