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>
252 lines
6.7 KiB
C++
252 lines
6.7 KiB
C++
#include "group.hpp"
|
|
#include <array>
|
|
#include <istream>
|
|
#include <limits>
|
|
#include <locale>
|
|
#include <sstream>
|
|
#include <ostream>
|
|
#include <string>
|
|
#include <vector>
|
|
namespace ag {
|
|
namespace {
|
|
struct Command {
|
|
std::string verb;
|
|
std::vector<Number> numbers;
|
|
};
|
|
bool space(unsigned char byte)
|
|
{
|
|
return byte == ' ' || byte == '\t';
|
|
}
|
|
std::vector<std::string> tokenize(const std::string& line)
|
|
{
|
|
std::vector<std::string> result;
|
|
std::size_t position = 0;
|
|
while (position < line.size()) {
|
|
while (position < line.size() && space(line[position])) {
|
|
++position;
|
|
}
|
|
if (position == line.size()) {
|
|
break;
|
|
}
|
|
std::size_t start = position;
|
|
while (position < line.size() && !space(line[position])) {
|
|
++position;
|
|
}
|
|
result.push_back(line.substr(start, position - start));
|
|
}
|
|
return result;
|
|
}
|
|
bool decimal(const std::string& word, Number& result)
|
|
{
|
|
if (word.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t position = 0;
|
|
bool negative = false;
|
|
if (word[position] == '+' || word[position] == '-') {
|
|
negative = word[position] == '-';
|
|
++position;
|
|
}
|
|
if (position == word.size()) {
|
|
return false;
|
|
}
|
|
std::uint64_t limit = static_cast<std::uint64_t>(std::numeric_limits<Number>::max());
|
|
if (negative) {
|
|
++limit;
|
|
}
|
|
std::uint64_t magnitude = 0;
|
|
for (; position < word.size(); ++position) {
|
|
unsigned char byte = word[position];
|
|
if (byte < '0' || byte > '9') {
|
|
return false;
|
|
}
|
|
std::uint64_t digit = byte - '0';
|
|
if (magnitude > (limit - digit) / 10) {
|
|
return false;
|
|
}
|
|
magnitude = magnitude * 10 + digit;
|
|
}
|
|
if (negative && magnitude == limit) {
|
|
result = std::numeric_limits<Number>::min();
|
|
} else if (negative) {
|
|
result = -static_cast<Number>(magnitude);
|
|
} else {
|
|
result = static_cast<Number>(magnitude);
|
|
}
|
|
return true;
|
|
}
|
|
int arity(const std::string& verb)
|
|
{
|
|
if (verb == "publish") {
|
|
return 5;
|
|
}
|
|
if (verb == "remove") {
|
|
return 2;
|
|
}
|
|
if (verb == "show") {
|
|
return 2;
|
|
}
|
|
if (verb == "store") {
|
|
return 4;
|
|
}
|
|
if (verb == "group") {
|
|
return 2;
|
|
}
|
|
if (verb == "list") {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
}
|
|
bool parse_command(const std::string& line, Command& result)
|
|
{
|
|
auto words = tokenize(line);
|
|
if (words.empty()) {
|
|
return false;
|
|
}
|
|
int needed = arity(words.front());
|
|
if (needed < 0 || words.size() != static_cast<std::size_t>(needed + 1)) {
|
|
return false;
|
|
}
|
|
Command parsed;
|
|
parsed.verb = words.front();
|
|
for (std::size_t index = 1; index < words.size(); ++index) {
|
|
Number number = 0;
|
|
if (!decimal(words[index], number)) {
|
|
return false;
|
|
}
|
|
parsed.numbers.push_back(number);
|
|
}
|
|
result = parsed;
|
|
return true;
|
|
}
|
|
const char* code_name(Code code)
|
|
{
|
|
switch (code) {
|
|
case Code::OK:
|
|
return "OK";
|
|
case Code::RANGE:
|
|
return "RANGE";
|
|
case Code::EXISTS:
|
|
return "EXISTS";
|
|
case Code::ABSENT:
|
|
return "ABSENT";
|
|
case Code::READONLY:
|
|
return "READONLY";
|
|
}
|
|
return "INVALID";
|
|
}
|
|
void error(std::ostream& output, Code code)
|
|
{
|
|
output << "ERR " << code_name(code) << '\n';
|
|
}
|
|
void print_change(std::ostream& output, const char* verb, const Change& result)
|
|
{
|
|
if (result.code != Code::OK) {
|
|
error(output, result.code);
|
|
return;
|
|
}
|
|
output << "OK " << verb << ' ' << result.generation;
|
|
output << ' ' << result.published << '\n';
|
|
}
|
|
void print_reading(std::ostream& output, const Reading& result)
|
|
{
|
|
if (result.code != Code::OK) {
|
|
error(output, result.code);
|
|
return;
|
|
}
|
|
output << "OK show " << result.generation;
|
|
output << ' ' << result.group << ' ' << result.value;
|
|
output << ' ' << result.writable << '\n';
|
|
}
|
|
void print_writing(std::ostream& output, const Writing& result)
|
|
{
|
|
if (result.code != Code::OK) {
|
|
error(output, result.code);
|
|
return;
|
|
}
|
|
output << "OK store " << result.generation;
|
|
output << ' ' << result.group << ' ' << result.value;
|
|
output << ' ' << result.accepted << '\n';
|
|
}
|
|
void print_group(std::ostream& output, const GroupInfo& result)
|
|
{
|
|
if (result.code != Code::OK) {
|
|
error(output, result.code);
|
|
return;
|
|
}
|
|
output << "OK group " << result.generation;
|
|
output << ' ' << result.first << ' ' << result.count;
|
|
output << ' ' << result.writable << '\n';
|
|
}
|
|
void print_listing(std::ostream& output, const Listing& result)
|
|
{
|
|
if (result.code != Code::OK) {
|
|
error(output, result.code);
|
|
return;
|
|
}
|
|
output << "OK list " << result.attributes.size() << '\n';
|
|
for (const auto& attribute : result.attributes) {
|
|
output << "ATTR " << attribute.name << ' ' << attribute.group;
|
|
output << ' ' << attribute.generation << ' ' << attribute.value;
|
|
output << ' ' << attribute.writable << '\n';
|
|
}
|
|
}
|
|
void dispatch(Registry& registry, const Command& command, std::ostream& output)
|
|
{
|
|
const auto& n = command.numbers;
|
|
if (command.verb == "publish") {
|
|
auto result = registry.publish(n[0], n[1], n[2], n[3], n[4]);
|
|
print_change(output, "publish", result);
|
|
return;
|
|
}
|
|
if (command.verb == "remove") {
|
|
auto result = registry.remove(n[0], n[1]);
|
|
print_change(output, "remove", result);
|
|
return;
|
|
}
|
|
if (command.verb == "show") {
|
|
auto result = registry.show(n[0], n[1]);
|
|
print_reading(output, result);
|
|
return;
|
|
}
|
|
if (command.verb == "store") {
|
|
auto result = registry.store(n[0], n[1], n[2], n[3]);
|
|
print_writing(output, result);
|
|
return;
|
|
}
|
|
if (command.verb == "group") {
|
|
auto result = registry.group(n[0], n[1]);
|
|
print_group(output, result);
|
|
return;
|
|
}
|
|
auto result = registry.list(n[0]);
|
|
print_listing(output, result);
|
|
}
|
|
}
|
|
int run_cli(std::istream& input, std::ostream& output, std::ostream& diagnostic)
|
|
{
|
|
(void)diagnostic;
|
|
Registry registry;
|
|
std::string line;
|
|
std::size_t physical_lines = 0;
|
|
while (std::getline(input, line)) {
|
|
++physical_lines;
|
|
if (physical_lines > 128) {
|
|
output.write("ERR LIMIT\n", 10);
|
|
break;
|
|
}
|
|
Command command;
|
|
if (!parse_command(line, command)) {
|
|
output.write("ERR SYNTAX\n", 11);
|
|
continue;
|
|
}
|
|
std::ostringstream response;
|
|
response.imbue(std::locale::classic());
|
|
dispatch(registry, command, response);
|
|
std::string bytes = response.str();
|
|
output.write(bytes.data(), static_cast<std::streamsize>(bytes.size()));
|
|
}
|
|
return 0;
|
|
}
|
|
}
|