All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
4.0 KiB
C++
117 lines
4.0 KiB
C++
#include "alternative_registry.h"
|
|
#include <algorithm>
|
|
namespace alternatives {
|
|
namespace {
|
|
bool event_fields(const Event& event, std::int32_t& priority) {
|
|
if (!valid_id(event.group)) {
|
|
return false;
|
|
}
|
|
switch (event.op) {
|
|
case Operation::install:
|
|
return valid_path(event.path) &&
|
|
parse_priority(event.priority, priority) == Error::none;
|
|
case Operation::remove:
|
|
case Operation::select:
|
|
return valid_path(event.path) && event.priority.empty() &&
|
|
!event.enabled && event.attachments.empty();
|
|
case Operation::automatic:
|
|
return event.path.empty() && event.priority.empty() &&
|
|
!event.enabled && event.attachments.empty();
|
|
case Operation::enable:
|
|
return valid_path(event.path) && event.priority.empty() && event.attachments.empty();
|
|
}
|
|
return false;
|
|
}
|
|
bool apply(Group& group, const Event& event, std::int32_t priority) {
|
|
auto found = std::find_if(group.candidates.begin(), group.candidates.end(),
|
|
[&](const Candidate& candidate) { return candidate.path == event.path; });
|
|
switch (event.op) {
|
|
case Operation::install: {
|
|
Candidate candidate{event.path, priority, event.enabled, event.attachments};
|
|
if (found == group.candidates.end()) {
|
|
group.candidates.push_back(std::move(candidate));
|
|
} else {
|
|
*found = std::move(candidate);
|
|
}
|
|
return true;
|
|
}
|
|
case Operation::remove:
|
|
if (found != group.candidates.end()) {
|
|
group.candidates.erase(found);
|
|
if (group.mode == Mode::manual && group.pin == event.path) {
|
|
group.mode = Mode::automatic;
|
|
group.pin.clear();
|
|
}
|
|
}
|
|
return true;
|
|
case Operation::select:
|
|
if (found == group.candidates.end()) {
|
|
return false;
|
|
}
|
|
group.mode = Mode::manual;
|
|
group.pin = event.path;
|
|
return true;
|
|
case Operation::automatic:
|
|
group.mode = Mode::automatic;
|
|
group.pin.clear();
|
|
return true;
|
|
case Operation::enable:
|
|
if (found == group.candidates.end()) {
|
|
return false;
|
|
}
|
|
found->enabled = event.enabled;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
std::vector<Change> changes(const Projection& before, const Projection& after) {
|
|
std::vector<Change> result;
|
|
for (std::size_t i = 0; i < before.bindings.size(); ++i) {
|
|
if (before.bindings[i].target != after.bindings[i].target) {
|
|
result.push_back({before.bindings[i].link,
|
|
before.bindings[i].target, after.bindings[i].target});
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
Error replay(const World& initial, const std::vector<Event>& events, Transcript& output) {
|
|
World working = initial;
|
|
output.final_world.groups.clear();
|
|
output.frames.clear();
|
|
if (events.size() > 128) {
|
|
return Error::invalid;
|
|
}
|
|
Transcript local;
|
|
for (const auto& event : events) {
|
|
std::int32_t priority = 0;
|
|
if (!event_fields(event, priority)) {
|
|
return Error::invalid;
|
|
}
|
|
auto group = std::find_if(working.groups.begin(), working.groups.end(),
|
|
[&](const Group& item) { return item.name == event.group; });
|
|
if (group == working.groups.end()) {
|
|
return Error::invalid;
|
|
}
|
|
const Projection previous = project(working);
|
|
if (!apply(*group, event, priority)) {
|
|
return Error::invalid;
|
|
}
|
|
World canonical;
|
|
if (compile_world(working.groups, canonical) != Error::none) {
|
|
return Error::invalid;
|
|
}
|
|
Projection projected = project(canonical);
|
|
Frame frame;
|
|
frame.world = canonical;
|
|
frame.projection = projected;
|
|
frame.changes = changes(previous, projected);
|
|
local.frames.push_back(std::move(frame));
|
|
working = std::move(canonical);
|
|
}
|
|
local.final_world = std::move(working);
|
|
output = std::move(local);
|
|
return Error::none;
|
|
}
|
|
} // namespace alternatives
|