One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
161 lines
4.8 KiB
C++
161 lines
4.8 KiB
C++
#include "probe.hpp"
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <limits>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
bool horizontal(char value) {
|
|
return value == ' ' || value == '\t' || value == '\r';
|
|
}
|
|
|
|
std::vector<std::string> tokens(const std::string& line) {
|
|
std::vector<std::string> result;
|
|
std::string current;
|
|
for (char value : line) {
|
|
if (horizontal(value)) {
|
|
if (!current.empty()) {
|
|
result.push_back(current);
|
|
current.clear();
|
|
}
|
|
} else {
|
|
current.push_back(value);
|
|
}
|
|
}
|
|
if (!current.empty()) {
|
|
result.push_back(current);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool integer(const std::string& text, std::int64_t& value) {
|
|
if (text.empty()) {
|
|
return false;
|
|
}
|
|
std::size_t index = 0;
|
|
bool negative = false;
|
|
if (text[index] == '+' || text[index] == '-') {
|
|
negative = text[index] == '-';
|
|
++index;
|
|
}
|
|
if (index == text.size()) {
|
|
return false;
|
|
}
|
|
std::uint64_t magnitude = 0;
|
|
const std::uint64_t limit = negative ? 9223372036854775808ULL : 9223372036854775807ULL;
|
|
for (; index < text.size(); ++index) {
|
|
char digit = text[index];
|
|
if (digit < '0' || digit > '9') {
|
|
return false;
|
|
}
|
|
unsigned number = static_cast<unsigned>(digit - '0');
|
|
if (magnitude > (limit - number) / 10) {
|
|
return false;
|
|
}
|
|
magnitude = magnitude * 10 + number;
|
|
}
|
|
if (negative && magnitude == 9223372036854775808ULL) {
|
|
value = std::numeric_limits<std::int64_t>::min();
|
|
} else {
|
|
value = negative ? -static_cast<std::int64_t>(magnitude) : static_cast<std::int64_t>(magnitude);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool narrow(std::int64_t value) {
|
|
return value >= std::numeric_limits<int>::min() && value <= std::numeric_limits<int>::max();
|
|
}
|
|
|
|
void emit(const std::vector<std::int64_t>& values) {
|
|
for (std::size_t i = 0; i < values.size(); ++i) {
|
|
if (i != 0) {
|
|
std::cout << ' ';
|
|
}
|
|
std::cout << values[i];
|
|
}
|
|
std::cout << '\n';
|
|
}
|
|
|
|
void append(std::vector<std::int64_t>& row, const std::vector<std::int64_t>& extra) {
|
|
row.insert(row.end(), extra.begin(), extra.end());
|
|
}
|
|
|
|
bool run(probe::Registry& registry, const std::vector<std::string>& words) {
|
|
std::vector<std::int64_t> args;
|
|
for (std::size_t i = 1; i < words.size(); ++i) {
|
|
std::int64_t value;
|
|
if (!integer(words[i], value)) {
|
|
return false;
|
|
}
|
|
args.push_back(value);
|
|
}
|
|
const std::string& command = words[0];
|
|
if (command == "RESET" && args.size() == 1) {
|
|
emit({0, registry.reset(args[0]) ? 1 : 0, registry.now()});
|
|
return true;
|
|
}
|
|
if (command == "ADV" && args.size() == 1) {
|
|
emit({3, registry.advance(args[0]) ? 1 : 0, registry.now()});
|
|
return true;
|
|
}
|
|
for (std::int64_t value : args) {
|
|
if (!narrow(value)) {
|
|
return false;
|
|
}
|
|
}
|
|
if (command == "SET" && args.size() == 4) {
|
|
int id = static_cast<int>(args[0]);
|
|
bool ok = registry.set(id, static_cast<int>(args[1]), static_cast<int>(args[2]), static_cast<int>(args[3]));
|
|
std::vector<std::int64_t> row = {1, ok ? 1 : 0};
|
|
append(row, probe::snapshot_fields(registry.view(id)));
|
|
emit(row);
|
|
return true;
|
|
}
|
|
if (command == "ASK" && args.size() == 3) {
|
|
probe::Query query{static_cast<int>(args[0]), static_cast<int>(args[1]), static_cast<int>(args[2])};
|
|
int verdict = registry.ask(query);
|
|
std::vector<std::int64_t> row = {2, verdict, query.id, query.strict, query.evidence};
|
|
append(row, probe::snapshot_fields(registry.view(query.id)));
|
|
emit(row);
|
|
return true;
|
|
}
|
|
if (command == "VIEW" && args.size() == 1) {
|
|
std::vector<std::int64_t> row = {4};
|
|
append(row, probe::snapshot_fields(registry.view(static_cast<int>(args[0]))));
|
|
emit(row);
|
|
return true;
|
|
}
|
|
if (command == "DROP" && args.size() == 1) {
|
|
bool ok = registry.drop(static_cast<int>(args[0]));
|
|
std::vector<std::int64_t> row = {5, ok ? 1 : 0};
|
|
append(row, probe::total_fields(registry.totals()));
|
|
emit(row);
|
|
return true;
|
|
}
|
|
if (command == "SUMMARY" && args.empty()) {
|
|
std::vector<std::int64_t> row = {6, registry.now()};
|
|
append(row, probe::total_fields(registry.totals()));
|
|
emit(row);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
probe::Registry registry;
|
|
std::string line;
|
|
while (std::getline(std::cin, line)) {
|
|
auto words = tokens(line);
|
|
if (words.empty()) {
|
|
continue;
|
|
}
|
|
if (!run(registry, words)) {
|
|
return 2;
|
|
}
|
|
}
|
|
return std::cin.bad() ? 2 : 0;
|
|
}
|