amos 73a5240295 Batches 21 and 18: add 74 calibrated tasks (40 Bos redo, 34 HWE code-gen)
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>
2026-11-02 10:23:12 +08:00

265 lines
8.1 KiB
C++

#include "identity.hpp"
#include <array>
#include <charconv>
#include <istream>
#include <ostream>
#include <string>
#include <vector>
namespace identity {
namespace {
const char* code_text(Code code) {
switch (code) {
case Code::OK: return "OK";
case Code::RANGE: return "RANGE";
case Code::MISSING: return "MISSING";
case Code::EXISTS: return "EXISTS";
case Code::BUSY: return "BUSY";
case Code::ZOMBIE: return "ZOMBIE";
case Code::DENIED: return "DENIED";
case Code::NOT_CHILD: return "NOT_CHILD";
case Code::RUNNING: return "RUNNING";
case Code::NO_GROUP: return "NO_GROUP";
case Code::CROSS_SESSION: return "CROSS_SESSION";
}
return "UNKNOWN";
}
void word(std::ostream& output, const char* text) {
while (*text != '\0') {
output.put(*text);
++text;
}
}
void unsigned_decimal(std::ostream& output, std::uint64_t value) {
std::array<char, 32> buffer{};
auto converted = std::to_chars(buffer.data(), buffer.data() + buffer.size(), value);
output.write(buffer.data(), converted.ptr - buffer.data());
}
void decimal(std::ostream& output, int value) {
std::array<char, 32> buffer{};
auto converted = std::to_chars(buffer.data(), buffer.data() + buffer.size(), value);
output.write(buffer.data(), converted.ptr - buffer.data());
}
void space(std::ostream& output) {
output.put(' ');
}
void newline(std::ostream& output) {
output.put('\n');
}
void integer_field(std::ostream& output, int value) {
space(output);
decimal(output, value);
}
void count_field(std::ostream& output, std::uint64_t value) {
space(output);
unsigned_decimal(output, value);
}
void emit_result(std::ostream& output, Result value) {
word(output, "R ");
word(output, code_text(value.code));
integer_field(output, value.value);
newline(output);
}
void emit_process(std::ostream& output, const Process& value) {
word(output, "P ");
word(output, code_text(value.code));
integer_field(output, value.pid);
integer_field(output, value.ppid);
integer_field(output, value.pgid);
integer_field(output, value.sid);
integer_field(output, value.live ? 1 : 0);
integer_field(output, value.status);
integer_field(output, value.group_leader ? 1 : 0);
integer_field(output, value.session_leader ? 1 : 0);
newline(output);
}
void emit_group(std::ostream& output, const Group& value) {
word(output, "G ");
word(output, code_text(value.code));
integer_field(output, value.id);
integer_field(output, value.sid);
integer_field(output, value.members);
integer_field(output, value.leader_live ? 1 : 0);
count_field(output, value.mask);
newline(output);
}
void emit_session(std::ostream& output, const Session& value) {
word(output, "S ");
word(output, code_text(value.code));
integer_field(output, value.id);
integer_field(output, value.groups);
integer_field(output, value.members);
integer_field(output, value.leader_live ? 1 : 0);
count_field(output, value.mask);
newline(output);
}
void emit_stats(std::ostream& output, const Stats& value) {
word(output, "T");
integer_field(output, value.tracked);
integer_field(output, value.live);
integer_field(output, value.zombies);
integer_field(output, value.groups);
integer_field(output, value.sessions);
count_field(output, value.births);
count_field(output, value.exits);
count_field(output, value.reaps);
newline(output);
}
bool separator(char value) {
return value == ' ' || value == '\t';
}
std::vector<std::string> split(const std::string& line) {
std::vector<std::string> result;
std::size_t cursor = 0;
while (cursor < line.size()) {
while (cursor < line.size() && separator(line[cursor])) {
++cursor;
}
std::size_t start = cursor;
while (cursor < line.size() && !separator(line[cursor])) {
++cursor;
}
if (cursor != start) {
result.push_back(line.substr(start, cursor - start));
}
}
return result;
}
bool parse_integer(const std::string& text, int& value) {
if (text.empty()) {
return false;
}
std::size_t cursor = text[0] == '-' ? 1 : 0;
if (cursor == text.size()) {
return false;
}
for (std::size_t index = cursor; index < text.size(); ++index) {
if (text[index] < '0' || text[index] > '9') {
return false;
}
}
int parsed = 0;
auto converted = std::from_chars(text.data(), text.data() + text.size(), parsed);
if (converted.ec != std::errc() || converted.ptr != text.data() + text.size()) {
return false;
}
value = parsed;
return true;
}
int argument_count(const std::string& verb) {
if (verb == "seed" || verb == "sid" || verb == "proc" || verb == "group" || verb == "session") {
return 1;
}
if (verb == "fork" || verb == "exit" || verb == "reap") {
return 2;
}
if (verb == "pg") {
return 3;
}
if (verb == "stats" || verb == "all") {
return 0;
}
return -1;
}
Code dispatch(Ledger& ledger, const std::string& verb, const std::array<int, 3>& args, std::ostream& output) {
if (verb == "seed") {
Result value = ledger.seed(args[0]);
emit_result(output, value);
return value.code;
}
if (verb == "fork") {
Result value = ledger.fork_process(args[0], args[1]);
emit_result(output, value);
return value.code;
}
if (verb == "sid") {
Result value = ledger.setsid(args[0]);
emit_result(output, value);
return value.code;
}
if (verb == "pg") {
Result value = ledger.setpgid(args[0], args[1], args[2]);
emit_result(output, value);
return value.code;
}
if (verb == "exit") {
Result value = ledger.exit_process(args[0], args[1]);
emit_result(output, value);
return value.code;
}
if (verb == "reap") {
Result value = ledger.reap(args[0], args[1]);
emit_result(output, value);
return value.code;
}
if (verb == "proc") {
Process value = ledger.inspect(args[0]);
emit_process(output, value);
return value.code;
}
if (verb == "group") {
Group value = ledger.group(args[0]);
emit_group(output, value);
return value.code;
}
if (verb == "session") {
Session value = ledger.session(args[0]);
emit_session(output, value);
return value.code;
}
if (verb == "stats") {
emit_stats(output, ledger.stats());
return Code::OK;
}
std::vector<Process> values = ledger.snapshot();
word(output, "A ");
unsigned_decimal(output, values.size());
newline(output);
for (const Process& value : values) {
emit_process(output, value);
}
return Code::OK;
}
}
CliResult run_cli(Ledger& ledger, std::istream& input, std::ostream& output) {
CliResult result{0, 0, 0, false};
std::string line;
while (std::getline(input, line)) {
if (result.lines == 64) {
result.limited = true;
word(output, "LIMIT\n");
break;
}
++result.lines;
std::vector<std::string> tokens = split(line);
if (tokens.empty()) {
++result.syntax;
word(output, "SYNTAX\n");
continue;
}
int count = argument_count(tokens.front());
if (count < 0 || tokens.size() != static_cast<std::size_t>(count + 1)) {
++result.syntax;
word(output, "SYNTAX\n");
continue;
}
std::array<int, 3> arguments{};
bool parsed = true;
for (int index = 0; index < count; ++index) {
if (!parse_integer(tokens[static_cast<std::size_t>(index + 1)], arguments[index])) {
parsed = false;
}
}
if (!parsed) {
++result.syntax;
word(output, "SYNTAX\n");
continue;
}
Code code = dispatch(ledger, tokens.front(), arguments, output);
if (code != Code::OK) {
++result.errors;
}
}
return result;
}
}