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>
129 lines
4.0 KiB
C++
129 lines
4.0 KiB
C++
#include "command.hpp"
|
|
|
|
#include <charconv>
|
|
#include <cctype>
|
|
#include <limits>
|
|
|
|
namespace carrier {
|
|
|
|
std::vector<std::string> CommandReader::words(const std::string& line) const
|
|
{
|
|
std::vector<std::string> result;
|
|
std::string current;
|
|
bool in_word = false;
|
|
for (char byte : line) {
|
|
if (byte == '#') break;
|
|
if (byte == ' ' || byte == '\t' || byte == '\r') {
|
|
if (in_word) {
|
|
result.push_back(current);
|
|
current.clear();
|
|
in_word = false;
|
|
}
|
|
continue;
|
|
}
|
|
if (byte == '\0' || byte == '\n') return {};
|
|
current.push_back(byte);
|
|
in_word = true;
|
|
}
|
|
if (in_word) result.push_back(current);
|
|
return result;
|
|
}
|
|
|
|
bool CommandReader::number(const std::string& word, std::uint64_t& result) const
|
|
{
|
|
if (word.empty()) return false;
|
|
if (word[0] == '+' || word[0] == '-') return false;
|
|
for (char byte : word) {
|
|
if (byte < '0' || byte > '9') return false;
|
|
}
|
|
const char* first = word.data();
|
|
const char* last = first + word.size();
|
|
const auto parsed = std::from_chars(first, last, result, 10);
|
|
if (parsed.ec != std::errc{}) return false;
|
|
if (parsed.ptr != last) return false;
|
|
return true;
|
|
}
|
|
|
|
bool CommandReader::port_number(const std::string& word, unsigned& result) const
|
|
{
|
|
std::uint64_t value = 0;
|
|
if (!number(word, value)) return false;
|
|
if (value > std::numeric_limits<unsigned>::max()) return false;
|
|
result = static_cast<unsigned>(value);
|
|
return true;
|
|
}
|
|
|
|
bool CommandReader::one_port(const std::vector<std::string>& tokens,
|
|
CommandKind kind, Command& result) const
|
|
{
|
|
if (tokens.size() != 2) return false;
|
|
if (!port_number(tokens[1], result.port)) return false;
|
|
result.kind = kind;
|
|
result.value = 0;
|
|
return true;
|
|
}
|
|
|
|
bool CommandReader::port_and_value(const std::vector<std::string>& tokens,
|
|
CommandKind kind, Command& result) const
|
|
{
|
|
if (tokens.size() != 3) return false;
|
|
if (!port_number(tokens[1], result.port)) return false;
|
|
if (!number(tokens[2], result.value)) return false;
|
|
result.kind = kind;
|
|
return true;
|
|
}
|
|
|
|
bool CommandReader::one_value(const std::vector<std::string>& tokens,
|
|
CommandKind kind, Command& result) const
|
|
{
|
|
if (tokens.size() != 2) return false;
|
|
if (!number(tokens[1], result.value)) return false;
|
|
result.kind = kind;
|
|
result.port = 0;
|
|
return true;
|
|
}
|
|
|
|
bool CommandReader::no_argument(const std::vector<std::string>& tokens,
|
|
CommandKind kind, Command& result) const
|
|
{
|
|
if (tokens.size() != 1) return false;
|
|
result.kind = kind;
|
|
result.port = 0;
|
|
result.value = 0;
|
|
return true;
|
|
}
|
|
|
|
Command CommandReader::parse(const std::string& line) const
|
|
{
|
|
const auto tokens = words(line);
|
|
Command command;
|
|
if (tokens.empty()) return command;
|
|
const std::string& verb = tokens[0];
|
|
bool accepted = false;
|
|
if (verb == "ENABLE") {
|
|
accepted = one_port(tokens, CommandKind::enable, command);
|
|
} else if (verb == "DISABLE") {
|
|
accepted = one_port(tokens, CommandKind::disable, command);
|
|
} else if (verb == "UP") {
|
|
accepted = one_port(tokens, CommandKind::up, command);
|
|
} else if (verb == "DOWN") {
|
|
accepted = one_port(tokens, CommandKind::down, command);
|
|
} else if (verb == "DONE") {
|
|
accepted = port_and_value(tokens, CommandKind::complete, command);
|
|
} else if (verb == "FAIL") {
|
|
accepted = port_and_value(tokens, CommandKind::fail, command);
|
|
} else if (verb == "TICK") {
|
|
accepted = one_value(tokens, CommandKind::advance, command);
|
|
} else if (verb == "QUERY") {
|
|
accepted = one_port(tokens, CommandKind::query, command);
|
|
} else if (verb == "HISTORY") {
|
|
accepted = no_argument(tokens, CommandKind::history, command);
|
|
} else if (verb == "CLEAR") {
|
|
accepted = no_argument(tokens, CommandKind::reset_log, command);
|
|
}
|
|
if (!accepted) command = Command{};
|
|
return command;
|
|
}
|
|
|
|
} // namespace carrier
|