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

238 lines
6.4 KiB
C++

#include "runtime.hpp"
#include <istream>
#include <limits>
#include <ostream>
#include <string>
#include <vector>
namespace cancelrt {
namespace {
bool separator(char character) {
return character == ' ' || character == '\t' || character == '\r';
}
std::vector<std::string> tokens(const std::string& line) {
std::vector<std::string> result;
std::size_t at = 0;
while (at < line.size()) {
while (at < line.size() && separator(line[at])) {
++at;
}
std::size_t start = at;
while (at < line.size() && !separator(line[at])) {
++at;
}
if (at != start) {
result.push_back(line.substr(start, at - start));
}
}
return result;
}
bool number(const std::string& text, std::int64_t& value) {
if (text.empty()) {
return false;
}
std::size_t at = 0;
bool negative = false;
if (text[at] == '+' || text[at] == '-') {
negative = text[at] == '-';
++at;
}
if (at == text.size()) {
return false;
}
std::uint64_t magnitude = 0;
const auto maximum = static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max());
const auto limit = maximum + (negative ? 1U : 0U);
while (at < text.size()) {
const auto character = text[at];
if (character < '0' || character > '9') {
return false;
}
const auto digit = static_cast<unsigned>(character - '0');
if (magnitude > (limit - digit) / 10U) {
return false;
}
magnitude = magnitude * 10U + digit;
++at;
}
if (negative && magnitude == maximum + 1U) {
value = std::numeric_limits<std::int64_t>::min();
} else if (negative) {
value = -static_cast<std::int64_t>(magnitude);
} else {
value = static_cast<std::int64_t>(magnitude);
}
return true;
}
int arity(const std::string& verb) {
if (verb == "create") {
return 3;
}
if (verb == "configure") {
return 3;
}
if (verb == "write") {
return 4;
}
if (verb == "read") {
return 4;
}
if (verb == "inspect") {
return 1;
}
if (verb == "run") {
return 3;
}
if (verb == "rewind") {
return 1;
}
if (verb == "erase") {
return 1;
}
if (verb == "list") {
return 0;
}
return -1;
}
Reply dispatch(Runtime& runtime, const std::string& verb, const std::vector<std::int64_t>& args) {
if (verb == "create") {
return runtime.create(args[0], args[1], args[2]);
}
if (verb == "configure") {
return runtime.configure(args[0], args[1], args[2]);
}
if (verb == "write") {
return runtime.write(args[0], args[1], args[2], args[3]);
}
if (verb == "read") {
return runtime.read(args[0], args[1], args[2], args[3]);
}
if (verb == "inspect") {
return runtime.inspect(args[0]);
}
if (verb == "run") {
return runtime.run(args[0], args[1], args[2]);
}
if (verb == "rewind") {
return runtime.rewind(args[0]);
}
if (verb == "erase") {
return runtime.erase(args[0]);
}
return runtime.list();
}
void decimal(std::ostream& out, std::int64_t value) {
char buffer[21];
std::size_t position = sizeof(buffer);
bool negative = value < 0;
std::uint64_t magnitude;
if (negative) {
magnitude = static_cast<std::uint64_t>(-(value + 1));
++magnitude;
} else {
magnitude = static_cast<std::uint64_t>(value);
}
do {
unsigned digit = static_cast<unsigned>(magnitude % 10U);
--position;
buffer[position] = static_cast<char>('0' + digit);
magnitude /= 10U;
} while (magnitude != 0);
if (negative) {
--position;
buffer[position] = '-';
}
auto length = static_cast<std::streamsize>(sizeof(buffer) - position);
out.write(buffer + position, length);
}
void field(std::ostream& out, std::int64_t value) {
out.put(' ');
decimal(out, value);
}
bool parse_numbers(const std::vector<std::string>& words, int count,
std::vector<std::int64_t>& result) {
std::vector<std::int64_t> parsed;
parsed.reserve(static_cast<std::size_t>(count));
for (int index = 0; index < count; ++index) {
std::int64_t value = 0;
const auto& token = words[static_cast<std::size_t>(index + 1)];
if (!number(token, value)) {
return false;
}
parsed.push_back(value);
}
result.swap(parsed);
return true;
}
struct Command {
std::string verb;
std::vector<std::int64_t> arguments;
bool valid;
Command() : valid(false) {
}
};
Command parse_line(const std::string& line) {
Command command;
auto words = tokens(line);
if (words.empty()) {
return command;
}
int count = arity(words[0]);
if (count < 0) {
return command;
}
auto expected = static_cast<std::size_t>(count + 1);
if (words.size() != expected) {
return command;
}
if (!parse_numbers(words, count, command.arguments)) {
return command;
}
command.verb = words[0];
command.valid = true;
return command;
}
}
void print_reply(std::ostream& out, const Reply& reply) {
decimal(out, static_cast<int>(reply.code));
field(out, static_cast<int>(reply.stop));
field(out, reply.total);
field(out, reply.done);
field(out, reply.produced);
field(out, reply.factor);
field(out, reply.bias);
field(out, reply.attempts);
field(out, reply.releases);
field(out, reply.active);
field(out, reply.sum);
field(out, static_cast<std::int64_t>(reply.values.size()));
for (auto value : reply.values) {
field(out, value);
}
field(out, static_cast<std::int64_t>(reply.ids.size()));
for (auto id : reply.ids) {
field(out, id);
}
out.put('\n');
}
int run_cli(std::istream& in, std::ostream& out, std::ostream& err) {
(void)err;
Runtime runtime;
std::string line;
int lines = 0;
while (std::getline(in, line)) {
if (lines == 4096) {
out.write("LIMIT\n", 6);
return 0;
}
++lines;
Command command = parse_line(line);
if (!command.valid) {
out.write("SYNTAX\n", 7);
continue;
}
print_reply(out, dispatch(runtime, command.verb, command.arguments));
}
return 0;
}
}