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>
219 lines
6.6 KiB
C++
219 lines
6.6 KiB
C++
#include "sequence.hpp"
|
|
#include <array>
|
|
#include <limits>
|
|
#include <locale>
|
|
#include <sstream>
|
|
#include <string>
|
|
namespace sequence {
|
|
namespace {
|
|
bool read_line(std::istream& input, std::string& line, bool& oversized) {
|
|
line.clear();
|
|
line.reserve(256);
|
|
oversized = false;
|
|
bool received = false;
|
|
for (;;) {
|
|
const int next = input.get();
|
|
if (next == std::char_traits<char>::eof()) {
|
|
return received;
|
|
}
|
|
received = true;
|
|
if (next == '\n') {
|
|
return true;
|
|
}
|
|
if (line.size() < 256) {
|
|
line.push_back(static_cast<char>(next));
|
|
} else {
|
|
oversized = true;
|
|
}
|
|
}
|
|
}
|
|
bool separator(unsigned char value) {
|
|
return value == ' ' || value == '\t' || value == '\r';
|
|
}
|
|
bool decimal(const std::string& text, std::int64_t& output) {
|
|
if (text.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t position = 0;
|
|
bool negative = false;
|
|
if (text[position] == '-') {
|
|
negative = true;
|
|
++position;
|
|
}
|
|
if (position == text.size()) {
|
|
return false;
|
|
}
|
|
std::uint64_t limit;
|
|
if (negative) {
|
|
limit = 9223372036854775808ULL;
|
|
} else {
|
|
limit = 9223372036854775807ULL;
|
|
}
|
|
std::uint64_t magnitude = 0;
|
|
for (; position < text.size(); ++position) {
|
|
const unsigned char character = static_cast<unsigned char>(text[position]);
|
|
if (character < '0' || character > '9') {
|
|
return false;
|
|
}
|
|
const unsigned digit = character - '0';
|
|
if (magnitude > limit / 10) {
|
|
return false;
|
|
}
|
|
if (magnitude == limit / 10 && digit > limit % 10) {
|
|
return false;
|
|
}
|
|
magnitude = magnitude * 10 + digit;
|
|
}
|
|
if (!negative) {
|
|
output = static_cast<std::int64_t>(magnitude);
|
|
} else if (magnitude == 9223372036854775808ULL) {
|
|
output = std::numeric_limits<std::int64_t>::min();
|
|
} else {
|
|
output = -static_cast<std::int64_t>(magnitude);
|
|
}
|
|
return true;
|
|
}
|
|
bool tokens(const std::string& line, std::array<std::string, 5>& fields, std::size_t& count) {
|
|
count = 0;
|
|
std::size_t position = 0;
|
|
while (position < line.size()) {
|
|
const unsigned char character = static_cast<unsigned char>(line[position]);
|
|
if (character == 0 || character > 127) {
|
|
return false;
|
|
}
|
|
if (separator(character)) {
|
|
++position;
|
|
continue;
|
|
}
|
|
if (count == fields.size()) {
|
|
return false;
|
|
}
|
|
const std::size_t start = position;
|
|
while (position < line.size() && !separator(static_cast<unsigned char>(line[position]))) {
|
|
const unsigned char next = static_cast<unsigned char>(line[position]);
|
|
if (next == 0 || next > 127) {
|
|
return false;
|
|
}
|
|
++position;
|
|
}
|
|
fields[count++] = line.substr(start, position - start);
|
|
}
|
|
return count != 0;
|
|
}
|
|
void emit_reply(std::ostream& destination, const Reply& reply) {
|
|
std::ostringstream output;
|
|
output.imbue(std::locale::classic());
|
|
output << reply.code << ' ' << reply.values.size();
|
|
for (std::int64_t value : reply.values) {
|
|
output << ' ' << value;
|
|
}
|
|
output << '\n';
|
|
const std::string bytes = output.str();
|
|
destination.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
|
|
}
|
|
void emit_state(std::ostream& destination, const State& state) {
|
|
std::ostringstream output;
|
|
output.imbue(std::locale::classic());
|
|
output << "S " << state.next_ticket;
|
|
for (const auto& rows : state.banks) {
|
|
output << ' ' << rows.size();
|
|
for (const Record& row : rows) {
|
|
output << ' ' << row.key << ' ' << row.payload << ' ' << row.ticket;
|
|
}
|
|
}
|
|
output << '\n';
|
|
const std::string bytes = output.str();
|
|
destination.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
|
|
}
|
|
bool argument_count(const std::string& verb, std::size_t& required) {
|
|
if (verb == "reset") {
|
|
required = 1;
|
|
} else if (verb == "append") {
|
|
required = 3;
|
|
} else if (verb == "order") {
|
|
required = 2;
|
|
} else if (verb == "merge") {
|
|
required = 4;
|
|
} else if (verb == "item") {
|
|
required = 2;
|
|
} else if (verb == "range") {
|
|
required = 3;
|
|
} else if (verb == "locate") {
|
|
required = 2;
|
|
} else if (verb == "inspect") {
|
|
required = 0;
|
|
} else {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
Reply invoke(Engine& engine, const std::string& verb, const std::array<std::int64_t, 4>& arguments) {
|
|
if (verb == "reset") {
|
|
return engine.reset(arguments[0]);
|
|
}
|
|
if (verb == "append") {
|
|
return engine.append(arguments[0], arguments[1], arguments[2]);
|
|
}
|
|
if (verb == "order") {
|
|
return engine.order(arguments[0], arguments[1]);
|
|
}
|
|
if (verb == "merge") {
|
|
return engine.merge(arguments[0], arguments[1], arguments[2], arguments[3]);
|
|
}
|
|
if (verb == "item") {
|
|
return engine.item(arguments[0], arguments[1]);
|
|
}
|
|
if (verb == "range") {
|
|
return engine.range(arguments[0], arguments[1], arguments[2]);
|
|
}
|
|
return engine.locate(arguments[0], arguments[1]);
|
|
}
|
|
}
|
|
int run_cli(Engine& engine, std::istream& input, std::ostream& output) {
|
|
std::string line;
|
|
std::size_t lines = 0;
|
|
bool oversized = false;
|
|
while (read_line(input, line, oversized)) {
|
|
if (lines == 1024) {
|
|
const std::string response = "8 0\n";
|
|
output.write(response.data(), static_cast<std::streamsize>(response.size()));
|
|
return 0;
|
|
}
|
|
++lines;
|
|
if (oversized) {
|
|
emit_reply(output, Reply{7, {}});
|
|
continue;
|
|
}
|
|
std::array<std::string, 5> fields;
|
|
std::size_t count = 0;
|
|
if (!tokens(line, fields, count)) {
|
|
emit_reply(output, Reply{7, {}});
|
|
continue;
|
|
}
|
|
std::size_t required = 0;
|
|
if (!argument_count(fields[0], required) || count != required + 1) {
|
|
emit_reply(output, Reply{7, {}});
|
|
continue;
|
|
}
|
|
std::array<std::int64_t, 4> arguments{};
|
|
bool good = true;
|
|
for (std::size_t index = 0; index < required; ++index) {
|
|
if (!decimal(fields[index + 1], arguments[index])) {
|
|
good = false;
|
|
break;
|
|
}
|
|
}
|
|
if (!good) {
|
|
emit_reply(output, Reply{7, {}});
|
|
continue;
|
|
}
|
|
if (fields[0] == "inspect") {
|
|
emit_state(output, engine.inspect());
|
|
} else {
|
|
emit_reply(output, invoke(engine, fields[0], arguments));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|