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

196 lines
6.3 KiB
C++

#include "journal.hpp"
#include <charconv>
#include <istream>
#include <locale>
#include <sstream>
#include <ostream>
#include <string_view>
#include <system_error>
namespace journal {
namespace {
std::vector<std::string> split(const std::string& line) {
std::vector<std::string> result;
std::size_t offset = 0;
while (offset < line.size()) {
if (line[offset] == ' ' || line[offset] == '\t') {
++offset;
continue;
}
std::size_t end = offset;
while (end < line.size() && line[end] != ' ' && line[end] != '\t') {
++end;
}
result.push_back(line.substr(offset, end - offset));
offset = end;
}
return result;
}
bool number(const std::string& token, Int& result) {
if (token.empty()) {
return false;
}
std::size_t first = token[0] == '-' ? 1 : 0;
if (first == token.size()) {
return false;
}
for (std::size_t i = first; i < token.size(); ++i) {
if (token[i] < '0' || token[i] > '9') {
return false;
}
}
auto parsed = std::from_chars(token.data(), token.data() + token.size(), result);
return parsed.ec == std::errc() && parsed.ptr == token.data() + token.size();
}
int nibble(char digit) {
if (digit >= '0' && digit <= '9') {
return digit - '0';
}
if (digit >= 'a' && digit <= 'f') {
return digit - 'a' + 10;
}
if (digit >= 'A' && digit <= 'F') {
return digit - 'A' + 10;
}
return -1;
}
bool decode(const std::string& token, std::string& bytes) {
bytes.clear();
if (token == "-") {
return true;
}
if (token.empty() || token.size() % 2 != 0) {
return false;
}
for (std::size_t i = 0; i < token.size(); i += 2) {
int high = nibble(token[i]);
int low = nibble(token[i + 1]);
if (high < 0 || low < 0) {
return false;
}
bytes.push_back(static_cast<char>(high * 16 + low));
}
return true;
}
std::string encode(const std::string& bytes) {
if (bytes.empty()) {
return "-";
}
const char* alphabet = "0123456789abcdef";
std::string result;
for (unsigned char value : bytes) {
result.push_back(alphabet[value >> 4]);
result.push_back(alphabet[value & 15]);
}
return result;
}
void print_status(std::ostream& output, const Status& status) {
output << "S " << status.code << ' ' << status.id << ' ' << status.mode;
output << ' ' << status.retries << ' ' << status.capacity << ' ' << status.attempts;
output << ' ' << status.state << ' ' << status.outcome << ' ' << status.debugger;
output << ' ' << status.kind << ' ' << status.value << ' ' << status.collector;
output << ' ' << status.total << ' ' << status.points << ' ' << status.enabled << '\n';
}
bool dispatch(Journal& journal, const std::vector<std::string>& words, std::ostream& output) {
if (words.empty()) {
return false;
}
const std::string& verb = words[0];
std::size_t count = 0;
if (verb == "new") {
count = 4;
} else if (verb == "point" || verb == "enable") {
count = 3;
} else if (verb == "finish") {
count = 5;
} else if (verb == "showpoint") {
count = 2;
} else if (verb == "drop" || verb == "start" || verb == "reset" || verb == "status" || verb == "log" || verb == "script") {
count = 1;
} else if (verb == "append") {
count = 1;
} else if (verb != "list") {
return false;
}
std::size_t arity = count + 1 + (verb == "append" ? 1 : 0);
if (words.size() != arity) {
return false;
}
std::array<Int, 5> args{};
for (std::size_t i = 0; i < count; ++i) {
if (!number(words[i + 1], args[i])) {
return false;
}
}
std::string bytes;
if (verb == "append" && !decode(words[2], bytes)) {
return false;
}
int code = OK;
if (verb == "new") {
code = journal.create(args[0], args[1], args[2], args[3]);
} else if (verb == "drop") {
code = journal.erase(args[0]);
} else if (verb == "point") {
code = journal.set_point(args[0], args[1], args[2]);
} else if (verb == "enable") {
code = journal.enable(args[0], args[1], args[2]);
} else if (verb == "start") {
code = journal.start(args[0]);
} else if (verb == "finish") {
code = journal.finish(args[0], args[1], args[2], args[3], args[4]);
} else if (verb == "append") {
code = journal.append(args[0], bytes);
} else if (verb == "reset") {
code = journal.reset(args[0]);
} else if (verb == "status") {
print_status(output, journal.status(args[0]));
return true;
} else if (verb == "showpoint") {
PointResult result = journal.point(args[0], args[1]);
output << "P " << result.code << ' ' << result.point.slot << ' ' << result.point.address << ' ' << result.point.enabled << '\n';
return true;
} else if (verb == "log") {
LogResult result = journal.log(args[0]);
output << "L " << result.code << ' ' << result.total << ' ' << encode(result.bytes) << '\n';
return true;
} else if (verb == "script") {
ScriptResult result = journal.script(args[0]);
output << "T " << result.code << ' ' << encode(result.text) << '\n';
return true;
} else {
std::vector<Int> ids = journal.list_ids();
output << "I " << ids.size();
for (Int id : ids) {
output << ' ' << id;
}
output << '\n';
return true;
}
output << "R " << code << ' ' << journal.list_ids().size() << '\n';
return true;
}
}
int run_cli(std::istream& input, std::ostream& output, std::ostream& diagnostic) {
static_cast<void>(diagnostic);
Journal journal;
std::ostringstream canonical;
canonical.imbue(std::locale::classic());
std::string line;
std::size_t lines = 0;
while (std::getline(input, line)) {
if (lines == 4096) {
canonical << "LIMIT\n";
break;
}
++lines;
if (!dispatch(journal, split(line), canonical)) {
canonical << "SYNTAX\n";
}
}
const std::string rendered = canonical.str();
output.write(rendered.data(), static_cast<std::streamsize>(rendered.size()));
output.put(' ' );
return 0;
}
}