amos f611da1e57 Batch 24: add 23 calibrated tasks written from Bos seed directions
Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries.
Only 23 themes were in scope (pure user-space reliability, at most one
task per theme); the rest were single operations or explanations,
installs and networking, system administration, ROS2, board-only or GUI
requests. Two finished drafts were withdrawn as too close to existing
tasks. Seeds supply direction only: all sources, contracts and tests are
new, and no task shares more than 14 characters with its seed text.

Each task passed the local gate and the trace6 Docker gate (5 runs per
sample class). Claude rebuilt the catalog from the calibration receipts:
23/23 USABLE. 16 of 23 are C/C++.

Only the task directories are taken; the batch worktree's lowered disk
floor in rollout/core.py stays out of main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 17:21:50 +08:00

133 lines
4.2 KiB
C++

#include "clock.hpp"
#include <limits>
#include <sstream>
namespace shared_clock {
namespace {
std::string trim(const std::string& field) {
std::size_t first = 0;
while (first < field.size() && (field[first] == ' ' || field[first] == '\t')) {
++first;
}
std::size_t last = field.size();
while (last > first && (field[last - 1] == ' ' || field[last - 1] == '\t')) {
--last;
}
return field.substr(first, last - first);
}
bool digits_only(const std::string& value) {
if (value.empty()) {
return false;
}
for (char ch : value) {
if (ch < '0' || ch > '9') {
return false;
}
}
return true;
}
bool unsigned_decimal(const std::string& text, std::uint64_t& value) {
std::uint64_t current = 0;
for (char ch : text) {
const unsigned digit = static_cast<unsigned>(ch - '0');
if (current > (std::numeric_limits<std::uint64_t>::max() - digit) / 10) {
return false;
}
current = current * 10 + digit;
}
value = current;
return true;
}
int hex_digit(char ch) {
if (ch >= '0' && ch <= '9') {
return ch - '0';
}
if (ch >= 'a' && ch <= 'f') {
return ch - 'a' + 10;
}
if (ch >= 'A' && ch <= 'F') {
return ch - 'A' + 10;
}
return -1;
}
}
Status parse_record(const std::string& text, Sample& out) {
if (text.size() > 512) {
return Status::Invalid;
}
std::vector<std::string> fields;
std::size_t start = 0;
for (std::size_t pos = 0; pos <= text.size(); ++pos) {
if (pos == text.size() || text[pos] == ',') {
fields.push_back(trim(text.substr(start, pos - start)));
start = pos + 1;
}
}
if (fields.size() != 8) {
return Status::Invalid;
}
for (const auto& field : fields) {
if (!digits_only(field)) {
return Status::Invalid;
}
}
std::array<std::uint64_t, 8> values{};
for (std::size_t index = 0; index < values.size(); ++index) {
if (!unsigned_decimal(fields[index], values[index])) {
return Status::Range;
}
}
const auto word_max = std::numeric_limits<std::uint32_t>::max();
if (!values[0] || values[0] > word_max || values[1] > LIMIT ||
values[2] > LIMIT || values[3] > word_max || values[4] > 1023 ||
values[5] > word_max || values[6] > 1023 || values[7] > LIMIT) {
return Status::Range;
}
Sample parsed;
parsed.id = static_cast<std::uint32_t>(values[0]);
parsed.local_send = values[1];
parsed.local_receive = values[2];
parsed.remote_receive.seconds = static_cast<std::uint32_t>(values[3]);
parsed.remote_receive.fraction = static_cast<std::uint16_t>(values[4]);
parsed.remote_send.seconds = static_cast<std::uint32_t>(values[5]);
parsed.remote_send.fraction = static_cast<std::uint16_t>(values[6]);
parsed.hint = values[7];
out = parsed;
return Status::Ok;
}
std::string format_record(const Sample& sample) {
std::ostringstream out;
out << sample.id << ',' << sample.local_send << ',' << sample.local_receive;
out << ',' << sample.remote_receive.seconds << ',' << sample.remote_receive.fraction;
out << ',' << sample.remote_send.seconds << ',' << sample.remote_send.fraction;
out << ',' << sample.hint;
return out.str();
}
Status decode_hex(const std::string& text, std::vector<std::uint8_t>& out) {
if (text.size() % 2 != 0) {
return Status::Invalid;
}
std::vector<std::uint8_t> decoded;
decoded.reserve(text.size() / 2);
for (std::size_t pos = 0; pos < text.size(); pos += 2) {
const int high = hex_digit(text[pos]);
const int low = hex_digit(text[pos + 1]);
if (high < 0 || low < 0) {
return Status::Invalid;
}
decoded.push_back(static_cast<std::uint8_t>(high * 16 + low));
}
out.swap(decoded);
return Status::Ok;
}
std::string encode_hex(const std::vector<std::uint8_t>& bytes) {
static constexpr char digits[] = "0123456789abcdef";
std::string text;
text.reserve(bytes.size() * 2);
for (std::uint8_t byte : bytes) {
text.push_back(digits[byte >> 4]);
text.push_back(digits[byte & 15]);
}
return text;
}
}