amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
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>
2026-10-18 17:43:15 +08:00

69 lines
2.2 KiB
C++

#include "alternative_registry.h"
#include <algorithm>
namespace alternatives {
namespace {
const Candidate* automatic_choice(const Group& group) {
const Candidate* best = nullptr;
for (const auto& candidate : group.candidates) {
if (!candidate.enabled) {
continue;
}
if (best == nullptr || candidate.priority > best->priority ||
(candidate.priority == best->priority && candidate.path < best->path)) {
best = &candidate;
}
}
return best;
}
const Candidate* selected_candidate(const Group& group) {
if (group.mode == Mode::automatic) {
return automatic_choice(group);
}
for (const auto& candidate : group.candidates) {
if (candidate.path == group.pin) {
return candidate.enabled ? &candidate : nullptr;
}
}
return nullptr;
}
std::string attachment_target(const Group& group, const Candidate* selected,
const std::string& slot) {
(void)group;
if (selected != nullptr) {
for (const auto& attachment : selected->attachments) {
if (attachment.slot == slot) {
return attachment.target;
}
}
}
return {};
}
}
Projection project(const World& world) {
Projection result;
for (const auto& group : world.groups) {
const Candidate* selected = selected_candidate(group);
Selection selection;
selection.group = group.name;
selection.mode = group.mode;
selection.pin = group.pin;
if (selected != nullptr) {
selection.current = selected->path;
}
result.selections.push_back(std::move(selection));
Binding master;
master.link = group.master_link;
if (selected != nullptr) {
master.target = selected->path;
}
result.bindings.push_back(std::move(master));
for (const auto& slot : group.slots) {
result.bindings.push_back({slot.link, attachment_target(group, selected, slot.name)});
}
}
std::sort(result.bindings.begin(), result.bindings.end(),
[](const Binding& a, const Binding& b) { return a.link < b.link; });
return result;
}
} // namespace alternatives