amos 73a5240295 Batches 21 and 18: add 74 calibrated tasks (40 Bos redo, 34 HWE code-gen)
Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao
environments: hidden assertions that ran inside the candidate's process
now run in a trusted parent that reads observations from a low-UID
worker; gold bytes are unchanged. 9 were excluded for scope (ROS2,
oversize, security core), 3 are blocked because the source requires an
exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6.

Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the
first 100 landed in 2f32624d.

Claude reviewed 74/74 USABLE against current digests, canonical
families, no ID or source overlap with main, plain public docs. Only the
new task directories are taken; the stale pre-batch-20 copies of
concur-release-capsule and resource-temp-link on the batch 21 branch and
both branches' progress notes stay as main has them. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 10:23:12 +08:00

270 lines
6.7 KiB
C++

#include "journal.hpp"
namespace journal {
std::string assemble_plan(Int mode, Int capacity, const std::vector<Point>& points);
namespace {
bool id_valid(Int id) {
return id >= 0 && id <= 15;
}
bool slot_valid(Int slot) {
return slot >= 0 && slot <= 7;
}
bool byte_valid(Int value) {
return value >= 0 && value <= 255;
}
Int outcome_of(Int debugger, Int kind, Int value, Int collector) {
if (debugger != 0) {
return 1;
}
if (kind == 0 && value != 0) {
return 2;
}
if (kind == 1) {
return 3;
}
if (kind == 2) {
return 4;
}
if (collector != 0) {
return 5;
}
return 0;
}
}
int Journal::create(Int id, Int mode, Int retries, Int capacity) {
if (!id_valid(id) || mode < 0 || mode > 2 || retries < 0 || retries > 4 || capacity < 0 || capacity > 64) {
return RANGE;
}
if (sessions_[id]) {
return EXISTS;
}
Session session;
session.id = id;
session.mode = mode;
session.retries = retries;
session.capacity = capacity;
sessions_[id] = session;
return OK;
}
int Journal::erase(Int id) {
if (!id_valid(id)) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
if (sessions_[id]->state == 1) {
return BUSY;
}
sessions_[id].reset();
return OK;
}
int Journal::set_point(Int id, Int slot, Int address) {
if (!id_valid(id) || !slot_valid(slot) || address < 0 || address > 65535) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state == 1) {
return BUSY;
}
if (session.points[slot]) {
return EXISTS;
}
session.points[slot] = Point{slot, address, 1};
return OK;
}
int Journal::enable(Int id, Int slot, Int enabled) {
if (!id_valid(id) || !slot_valid(slot) || enabled < 0 || enabled > 1) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state == 1) {
return BUSY;
}
if (!session.points[slot]) {
return MISSING;
}
session.points[slot]->enabled = enabled;
return OK;
}
int Journal::start(Int id) {
if (!id_valid(id)) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state == 1) {
return BUSY;
}
if (session.state == 3) {
return STATE;
}
session.state = 1;
++session.attempts;
session.outcome = -1;
session.debugger = -1;
session.kind = -1;
session.value = -1;
session.collector = -1;
return OK;
}
int Journal::finish(Int id, Int debugger, Int kind, Int value, Int collector) {
if (!id_valid(id) || !byte_valid(debugger) || kind < 0 || kind > 2 || !byte_valid(value) || !byte_valid(collector)) {
return RANGE;
}
if (kind != 0 && (value < 1 || value > 31)) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state != 1) {
return STATE;
}
session.debugger = debugger;
session.kind = kind;
session.value = value;
session.collector = collector;
session.outcome = collector == 0 ? 0 : outcome_of(debugger, kind, value, collector);
session.state = session.outcome == 0 || session.attempts > session.retries ? 3 : 2;
return OK;
}
int Journal::append(Int id, const std::string& bytes) {
if (!id_valid(id) || bytes.size() > 64) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state != 1) {
return STATE;
}
session.total += static_cast<Int>(bytes.size());
session.bytes += bytes;
if (session.bytes.size() > static_cast<std::size_t>(session.capacity)) {
session.bytes.erase(0, session.bytes.size() - session.capacity);
}
return OK;
}
int Journal::reset(Int id) {
if (!id_valid(id)) {
return RANGE;
}
if (!sessions_[id]) {
return MISSING;
}
Session& session = *sessions_[id];
if (session.state == 1) {
return BUSY;
}
session.attempts = 0;
session.state = 0;
session.outcome = -1;
session.debugger = -1;
session.kind = -1;
session.value = -1;
session.collector = -1;
session.total = 0;
session.bytes.clear();
return OK;
}
Status Journal::status(Int id) const {
Status result;
if (!id_valid(id)) {
result.code = RANGE;
return result;
}
if (!sessions_[id]) {
return result;
}
const Session& session = *sessions_[id];
result.code = OK;
result.id = session.id;
result.mode = session.mode;
result.retries = session.retries;
result.capacity = session.capacity;
result.attempts = session.attempts;
result.state = session.state;
result.outcome = session.outcome;
result.debugger = session.debugger;
result.kind = session.kind;
result.value = session.value;
result.collector = session.collector;
result.total = session.total;
result.points = 0;
result.enabled = 0;
for (const auto& point : session.points) {
if (point) {
++result.points;
result.enabled += point->enabled;
}
}
return result;
}
PointResult Journal::point(Int id, Int slot) const {
PointResult result;
if (!id_valid(id) || !slot_valid(slot)) {
result.code = RANGE;
return result;
}
if (!sessions_[id] || !sessions_[id]->points[slot]) {
return result;
}
result.code = OK;
result.point = *sessions_[id]->points[slot];
return result;
}
LogResult Journal::log(Int id) const {
LogResult result;
if (!id_valid(id)) {
result.code = RANGE;
return result;
}
if (!sessions_[id]) {
return result;
}
result.code = OK;
result.total = sessions_[id]->total;
result.bytes = sessions_[id]->bytes;
return result;
}
ScriptResult Journal::script(Int id) const {
ScriptResult result;
if (!id_valid(id)) {
result.code = RANGE;
return result;
}
if (!sessions_[id]) {
return result;
}
const Session& session = *sessions_[id];
std::vector<Point> points;
for (const auto& point : session.points) {
if (point && point->enabled == 1) {
points.push_back(*point);
}
}
result.code = OK;
result.text = assemble_plan(session.mode, session.capacity, points);
return result;
}
std::vector<Int> Journal::list_ids() const {
std::vector<Int> result;
for (Int id = 0; id <= 15; ++id) {
if (sessions_[id]) {
result.push_back(id);
}
}
return result;
}
}