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

160 lines
4.6 KiB
C++

#include "io.hpp"
#include <limits>
#include <string_view>
namespace bio {
namespace {
bool separator(char value) {
return value == ' ' || value == '\t';
}
std::vector<std::string_view> tokenize(const std::string& line) {
std::vector<std::string_view> result;
std::size_t cursor = 0;
while (cursor < line.size()) {
while (cursor < line.size() && separator(line[cursor])) {
++cursor;
}
if (cursor == line.size()) {
break;
}
const std::size_t first = cursor;
while (cursor < line.size() && !separator(line[cursor])) {
++cursor;
}
result.emplace_back(line.data() + first, cursor - first);
}
return result;
}
bool number(std::string_view text, Number& value) {
if (text.empty()) {
return false;
}
bool negative = false;
std::size_t cursor = 0;
if (text[cursor] == '-') {
negative = true;
++cursor;
}
if (cursor == text.size()) {
return false;
}
const std::uint64_t maximum = static_cast<std::uint64_t>(std::numeric_limits<Number>::max());
const std::uint64_t limit = maximum + (negative ? 1u : 0u);
const std::uint64_t quotient = limit / 10;
const std::uint64_t remainder = limit % 10;
std::uint64_t magnitude = 0;
while (cursor < text.size()) {
const char digit = text[cursor];
if (digit < '0' || digit > '9') {
return false;
}
const std::uint64_t part = static_cast<unsigned>(digit - '0');
if (magnitude > quotient) {
return false;
}
if (magnitude == quotient && part > remainder) {
return false;
}
magnitude = magnitude * 10 + part;
++cursor;
}
if (negative && magnitude == maximum + 1) {
value = std::numeric_limits<Number>::min();
} else if (negative) {
value = -static_cast<Number>(magnitude);
} else {
value = static_cast<Number>(magnitude);
}
return true;
}
struct Command {
enum Kind { Open, Put, Arm, Flush, Close, View, Stats, Invalid };
Kind kind = Invalid;
std::array<Number, 3> args{{0, 0, 0}};
};
Command parse(const std::string& line) {
const auto words = tokenize(line);
Command result;
if (words.empty()) {
return result;
}
std::size_t count = 0;
if (words[0] == "OPEN") {
result.kind = Command::Open;
count = 2;
} else if (words[0] == "PUT") {
result.kind = Command::Put;
count = 3;
} else if (words[0] == "ARM") {
result.kind = Command::Arm;
count = 3;
} else if (words[0] == "FLUSH") {
result.kind = Command::Flush;
count = 1;
} else if (words[0] == "CLOSE") {
result.kind = Command::Close;
count = 1;
} else if (words[0] == "VIEW") {
result.kind = Command::View;
count = 1;
} else if (words[0] == "STATS") {
result.kind = Command::Stats;
} else {
return result;
}
if (words.size() != count + 1) {
result.kind = Command::Invalid;
return result;
}
for (std::size_t index = 0; index < count; ++index) {
if (!number(words[index + 1], result.args[index])) {
result.kind = Command::Invalid;
return result;
}
}
return result;
}
std::string execute(Session& session, const Command& command) {
const Number id = command.args[0];
const Number first = command.args[1];
const Number second = command.args[2];
switch (command.kind) {
case Command::Open:
return code_name(session.open(id, first));
case Command::Put:
return code_name(session.put(id, first, second));
case Command::Arm:
return code_name(session.arm(id, first, second));
case Command::Flush:
return code_name(session.flush(id));
case Command::Close:
return code_name(session.close(id));
case Command::View:
return format_view(session.view(id));
case Command::Stats:
return format_stats(session.stats());
case Command::Invalid:
return "SYNTAX";
}
return "SYNTAX";
}
void emit(std::ostream& output, const std::string& line) {
output.write(line.data(), static_cast<std::streamsize>(line.size()));
output.put('\n');
}
}
int run_cli(Session& session, std::istream& input, std::ostream& output) {
std::string line;
int processed = 0;
while (std::getline(input, line)) {
if (processed == 64) {
emit(output, "LIMIT");
break;
}
++processed;
const Command command = parse(line);
emit(output, execute(session, command));
}
return processed;
}
}