amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

181 lines
6.9 KiB
C++

#include "watch_journal.hpp"
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace watchlog;
namespace {
int 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;
}
bool read_bytes(Bytes& output)
{
std::string word;
if (!(std::cin >> word)) return false;
output.clear();
if (word == "-") return true;
if (word.size() % 2) return false;
for (std::size_t i = 0; i < word.size(); i += 2) {
const int high = digit(word[i]);
const int low = digit(word[i + 1]);
if (high < 0 || low < 0) return false;
output.push_back(static_cast<std::uint8_t>(high * 16 + low));
}
return true;
}
bool read_text(std::string& output)
{
Bytes bytes;
if (!read_bytes(bytes)) return false;
output.assign(bytes.begin(), bytes.end());
return true;
}
std::string hex(const Bytes& bytes)
{
static const char* digits = "0123456789abcdef";
if (bytes.empty()) return "-";
std::string result;
for (auto value : bytes) {
result += digits[value >> 4];
result += digits[value & 15];
}
return result;
}
std::string hex(const std::string& text)
{
return hex(Bytes(text.begin(), text.end()));
}
std::uint64_t hash(const Bytes& bytes)
{
std::uint64_t result = 14695981039346656037ULL;
for (auto value : bytes) result = (result ^ value) * 1099511628211ULL;
return result;
}
bool bindings(std::vector<Binding>& result)
{
std::size_t count = 0;
if (!(std::cin >> count) || count > 100) return false;
for (std::size_t i = 0; i < count; ++i) {
Binding binding;
if (!(std::cin >> binding.wd) || !read_text(binding.root)) return false;
result.push_back(binding);
}
return true;
}
void print_entries(const std::vector<Entry>& entries)
{
std::cout << ' ' << entries.size();
for (const Entry& e : entries) {
std::cout << ' ' << e.sequence << ' ' << e.kind << ' ' << e.wd << ' '
<< e.generation << ' ' << e.cookie << ' ' << e.directory
<< ' ' << hex(e.path) << ' ' << hex(e.other);
}
}
}
int main()
{
std::array<Journal, 2> journals;
unsigned selected = 0;
std::string op;
while (std::cin >> op) {
Journal& journal = journals[selected];
int wd = 0;
std::uint32_t cookie = 0;
std::uint32_t mask = 0;
std::uint64_t nonce = 0;
std::size_t limit = 0;
std::string text;
Bytes bytes;
if (op == "U") {
if (!(std::cin >> selected) || selected > 1) return 2;
std::cout << "U " << selected;
} else if (op == "A" || op == "B" || op == "V") {
if (!(std::cin >> wd) || !read_text(text)) return 2;
Binding binding{wd, text};
const int result = op == "A" ? journal.add(binding) :
op == "B" ? journal.rebind(binding) : validate_binding(binding);
std::cout << "R " << result << ' ' << binding.wd << ' ' << hex(binding.root);
} else if (op == "X") {
if (!(std::cin >> wd)) return 2;
std::cout << "R " << journal.remove(wd);
} else if (op == "C") {
if (!(std::cin >> cookie)) return 2;
std::cout << "R " << journal.cancel_cookie(cookie);
} else if (op == "I") {
std::cout << "R " << journal.discard_fragment();
} else if (op == "L") {
std::cout << "R " << journal.flush();
} else if (op == "F") {
if (!read_bytes(bytes)) return 2;
const auto before = hash(bytes);
const int result = journal.feed(bytes);
std::cout << "R " << result << ' ' << before << ' ' << hash(bytes);
} else if (op == "M") {
if (!(std::cin >> limit) || limit > 100) return 2;
std::vector<Bytes> chunks;
for (std::size_t i = 0; i < limit; ++i) {
if (!read_bytes(bytes)) return 2;
chunks.push_back(bytes);
}
std::cout << "R " << journal.feed_many(chunks);
} else if (op == "R") {
std::vector<Binding> list;
if (!bindings(list)) return 2;
std::cout << "R " << journal.rebuild(list);
} else if (op == "T") {
if (!(std::cin >> limit >> nonce)) return 2;
Entry sentinel;
sentinel.sequence = nonce;
sentinel.path = "sentinel";
std::vector<Entry> output{sentinel};
const int result = journal.drain(limit, output);
std::cout << "T " << result;
print_entries(output);
} else if (op == "S") {
const auto list = journal.snapshot();
std::cout << "S " << list.size();
for (const Watch& watch : list) {
std::cout << ' ' << watch.wd << ' ' << watch.generation << ' ' << hex(watch.root);
}
} else if (op == "Q") {
const Stats s = journal.stats();
std::cout << "Q " << s.epoch << ' ' << s.dirty << ' ' << s.watches
<< ' ' << s.pending << ' ' << s.buffered << ' ' << s.queued
<< ' ' << s.lost << ' ' << s.next_sequence << ' ' << s.next_generation;
} else if (op == "Z") {
journal.reset();
std::cout << "R 0";
} else if (op == "E") {
if (!(std::cin >> wd >> mask >> cookie) || !read_text(text) || !read_bytes(bytes)) return 2;
Raw raw{wd, mask, cookie, text};
const int result = encode_record(raw, bytes);
std::cout << "E " << result << ' ' << hex(bytes) << ' ' << raw.wd
<< ' ' << raw.mask << ' ' << raw.cookie << ' ' << hex(raw.name);
} else if (op == "D") {
if (!(std::cin >> nonce) || !read_bytes(bytes)) return 2;
Raw raw{static_cast<int>(nonce), static_cast<std::uint32_t>(nonce),
static_cast<std::uint32_t>(nonce), "sentinel"};
const auto before = hash(bytes);
const int result = decode_record(bytes, raw);
std::cout << "D " << result << ' ' << raw.wd << ' ' << raw.mask << ' '
<< raw.cookie << ' ' << hex(raw.name) << ' ' << before << ' ' << hash(bytes);
} else if (op == "P") {
if (!(std::cin >> nonce) || !read_text(text)) return 2;
const auto before = hash(Bytes(text.begin(), text.end()));
std::vector<Binding> output{{static_cast<int>(nonce), "sentinel"}};
const int result = parse_bindings(text, output);
std::cout << "P " << result << ' ' << output.size();
for (const Binding& binding : output) std::cout << ' ' << binding.wd << ' ' << hex(binding.root);
std::cout << ' ' << before << ' ' << hash(Bytes(text.begin(), text.end()));
} else {
return 2;
}
std::cout << '\n';
}
return std::cin.bad() ? 2 : 0;
}