amos 913d3c367f Add the usable task catalog and admit batch 6 tasks
All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:43:15 +08:00

5 lines
14 KiB
JSON

{
"sysctl_overlay.hpp": "#ifndef EMBEDDED_SYSCTL_OVERLAY_HPP\n#define EMBEDDED_SYSCTL_OVERLAY_HPP\n\n#include <cstddef>\n#include <optional>\n#include <string>\n#include <vector>\n\nnamespace sysctloverlay {\n\nenum class Error { none = 0, invalid = 1 };\nenum class RuleKind { assignment = 0, exclusion = 1 };\n\nstruct File {\n std::string basename;\n std::optional<std::string> text;\n};\n\nusing Layer = std::vector<File>;\n\nstruct Rule {\n std::size_t row = 0;\n RuleKind kind = RuleKind::assignment;\n std::string key;\n std::string value;\n bool ignore_error = false;\n bool pattern = false;\n};\n\nstruct SelectedFile {\n std::size_t layer = 0;\n File file;\n};\n\nstruct LocatedRule {\n std::size_t layer = 0;\n std::string basename;\n Rule rule;\n};\n\nstruct Configuration {\n std::vector<SelectedFile> selected;\n std::vector<LocatedRule> rules;\n std::vector<std::string> excluded;\n};\n\nstruct Entry {\n std::string key;\n std::string value;\n bool ignore_error = false;\n std::size_t layer = 0;\n std::string basename;\n std::size_t row = 0;\n};\n\nstruct Plan {\n std::vector<Entry> entries;\n};\n\nbool valid_kernel_key(const std::string &key);\nError canonical_key(const std::string &raw, bool allow_pattern,\n std::string &output);\nError match_pattern(const std::string &pattern, const std::string &key,\n bool &output);\nError parse_text(const std::string &text, std::vector<Rule> &output);\nError select_files(const std::vector<Layer> &layers,\n std::vector<SelectedFile> &output);\nError compile_configuration(const std::vector<Layer> &layers,\n Configuration &output);\nError plan_configuration(const Configuration &configuration,\n const std::vector<std::string> &keys, Plan &output);\nError make_plan(const std::vector<Layer> &layers,\n const std::vector<std::string> &keys, Plan &output);\n\n}\n#endif\n",
"sysctl_observe.cpp": "#include \"sysctl_overlay.hpp\"\n#include <cstdint>\n#include <iostream>\n#include <stdexcept>\n#include <utility>\n\nusing namespace sysctloverlay;\n\nnamespace {\n\nstd::size_t wire_bytes = 0;\n\nstd::string quote(const std::string &value)\n{\n constexpr char digits[] = \"0123456789abcdef\";\n std::string result = \"\\\"\";\n for (unsigned char byte : value) {\n if (byte == '\"' || byte == '\\\\') {\n result.push_back('\\\\');\n result.push_back(static_cast<char>(byte));\n } else if (byte < 32 || byte > 126) {\n result += \"\\\\u00\";\n result.push_back(digits[byte >> 4]);\n result.push_back(digits[byte & 15]);\n } else {\n result.push_back(static_cast<char>(byte));\n }\n }\n return result + '\"';\n}\n\nstd::string boolean(bool value)\n{\n return value ? \"true\" : \"false\";\n}\n\ntemplate<class Range, class Encode>\nstd::string sequence(const Range &items, Encode encode)\n{\n std::string result = \"[\";\n bool first = true;\n for (const auto &item : items) {\n if (!first) {\n result.push_back(',');\n }\n first = false;\n result += encode(item);\n }\n return result + ']';\n}\n\nstd::string file_json(const File &file)\n{\n return \"[\" + quote(file.basename) + ',' +\n (file.text.has_value() ? quote(*file.text) : \"null\") + ']';\n}\n\nstd::string layers_json(const std::vector<Layer> &layers)\n{\n return sequence(layers, [](const Layer &layer) {\n return sequence(layer, file_json);\n });\n}\n\nstd::string selected_json(const SelectedFile &selected)\n{\n const File &file = selected.file;\n return \"[\" + std::to_string(selected.layer) + ',' + quote(file.basename) + ',' +\n (file.text.has_value() ? quote(*file.text) : \"null\") + ']';\n}\n\nstd::string rule_json(const Rule &rule)\n{\n return \"[\" + std::to_string(rule.row) + ',' +\n std::to_string(static_cast<int>(rule.kind)) + ',' + quote(rule.key) + ',' +\n quote(rule.value) + ',' + boolean(rule.ignore_error) + ',' +\n boolean(rule.pattern) + ']';\n}\n\nstd::string located_json(const LocatedRule &located)\n{\n return \"[\" + std::to_string(located.layer) + ',' + quote(located.basename) + ',' +\n rule_json(located.rule) + ']';\n}\n\nstd::string configuration_json(const Configuration &configuration)\n{\n return \"[\" + sequence(configuration.selected, selected_json) + ',' +\n sequence(configuration.rules, located_json) + ',' +\n sequence(configuration.excluded, quote) + ']';\n}\n\nstd::string entry_json(const Entry &entry)\n{\n return \"[\" + quote(entry.key) + ',' + quote(entry.value) + ',' +\n boolean(entry.ignore_error) + ',' + std::to_string(entry.layer) + ',' +\n quote(entry.basename) + ',' + std::to_string(entry.row) + ']';\n}\n\nstd::string plan_json(const Plan &plan)\n{\n return sequence(plan.entries, entry_json);\n}\n\nstd::string token()\n{\n std::string text;\n if (!(std::cin >> text)) {\n throw std::runtime_error(\"missing token\");\n }\n return text;\n}\n\nstd::size_t count(std::size_t maximum)\n{\n const std::string text = token();\n std::size_t value = 0;\n if (text.empty()) {\n throw std::runtime_error(\"empty count\");\n }\n for (unsigned char byte : text) {\n if (byte < '0' || byte > '9' || value > maximum / 10) {\n throw std::runtime_error(\"count syntax\");\n }\n value = value * 10 + (byte - '0');\n if (value > maximum) {\n throw std::runtime_error(\"count range\");\n }\n }\n return value;\n}\n\nunsigned nibble(unsigned char byte)\n{\n if (byte >= '0' && byte <= '9') return byte - '0';\n if (byte >= 'a' && byte <= 'f') return byte - 'a' + 10;\n if (byte >= 'A' && byte <= 'F') return byte - 'A' + 10;\n throw std::runtime_error(\"hex digit\");\n}\n\nstd::string read_text()\n{\n const std::string text = token();\n if (text == \"-\") {\n return {};\n }\n if (text.size() % 2 != 0 || text.size() / 2 > 1048576 - wire_bytes) {\n throw std::runtime_error(\"hex size\");\n }\n wire_bytes += text.size() / 2;\n std::string result;\n result.reserve(text.size() / 2);\n for (std::size_t at = 0; at < text.size(); at += 2) {\n const auto byte = nibble(text[at]) * 16 + nibble(text[at + 1]);\n result.push_back(static_cast<char>(byte));\n }\n return result;\n}\n\nvoid require(const char *wanted)\n{\n if (token() != wanted) {\n throw std::runtime_error(\"unexpected data row\");\n }\n}\n\nstd::vector<Layer> read_layers()\n{\n std::vector<Layer> layers;\n const auto layer_count = count(4096);\n std::size_t total = 0;\n for (std::size_t index = 0; index < layer_count; ++index) {\n require(\"Y\");\n const auto file_count = count(4096);\n total += file_count;\n if (total > 4096) {\n throw std::runtime_error(\"wire file count\");\n }\n Layer layer;\n for (std::size_t file_index = 0; file_index < file_count; ++file_index) {\n require(\"F\");\n File file;\n file.basename = read_text();\n const bool present = count(1) != 0;\n std::string text = read_text();\n if (present) {\n file.text = std::move(text);\n } else if (!text.empty()) {\n throw std::runtime_error(\"null text payload\");\n }\n layer.push_back(std::move(file));\n }\n layers.push_back(std::move(layer));\n }\n return layers;\n}\n\nstd::vector<std::string> read_keys()\n{\n const auto size = count(4096);\n std::vector<std::string> keys;\n for (std::size_t index = 0; index < size; ++index) {\n keys.push_back(read_text());\n }\n return keys;\n}\n\nRule dirty_rule()\n{\n Rule rule;\n rule.row = 77;\n rule.key = \"old/key\";\n rule.value = \"old_value\";\n rule.ignore_error = true;\n return rule;\n}\n\nConfiguration dirty_configuration()\n{\n Configuration result;\n result.selected.push_back(SelectedFile{7, File{\"old.conf\", \"old/key=old_value\"}});\n result.rules.push_back(LocatedRule{7, \"old.conf\", dirty_rule()});\n result.excluded.push_back(\"old/key\");\n return result;\n}\n\nPlan dirty_plan()\n{\n Plan result;\n result.entries.push_back(Entry{\"old/key\", \"old_value\", true, 7, \"old.conf\", 77});\n return result;\n}\n\nstd::string result_row(const std::string &command, Error error,\n const std::string &value, bool unchanged)\n{\n return \"[\" + quote(command) + ',' + std::to_string(static_cast<int>(error)) + ',' +\n value + ',' + boolean(unchanged) + ']';\n}\n\n}\n\nint main()\n{\n try {\n std::vector<Layer> layers;\n Configuration last_configuration;\n Configuration held_configuration;\n Plan last_plan;\n Plan held_plan;\n bool compiled = false;\n bool held = false;\n std::string command;\n while (std::cin >> command) {\n wire_bytes = 0;\n std::string row;\n if (command == \"K\" || command == \"N\" || command == \"L\") {\n const bool pattern = command == \"N\" ? count(1) != 0 : false;\n const std::string text = read_text();\n const std::string original = text;\n if (command == \"K\") {\n const bool value = valid_kernel_key(text);\n row = \"[\\\"K\\\",\" + boolean(value) + ',' + boolean(text == original) + ']';\n } else if (command == \"N\") {\n std::string output = \"old_output\";\n const Error error = canonical_key(text, pattern, output);\n row = result_row(command, error, quote(output), text == original);\n } else {\n std::vector<Rule> output{dirty_rule()};\n const Error error = parse_text(text, output);\n row = result_row(command, error, sequence(output, rule_json), text == original);\n }\n } else if (command == \"M\") {\n const std::string pattern = read_text();\n const std::string key = read_text();\n const auto original_pattern = pattern;\n const auto original_key = key;\n bool output = true;\n const Error error = match_pattern(pattern, key, output);\n row = result_row(command, error, boolean(output),\n pattern == original_pattern && key == original_key);\n } else if (command == \"C\") {\n layers = read_layers();\n const std::string original = layers_json(layers);\n last_configuration = dirty_configuration();\n const Error error = compile_configuration(layers, last_configuration);\n compiled = error == Error::none;\n row = result_row(command, error, configuration_json(last_configuration),\n original == layers_json(layers));\n } else if (command == \"S\") {\n const std::string original = layers_json(layers);\n auto output = dirty_configuration().selected;\n const Error error = select_files(layers, output);\n row = result_row(command, error, sequence(output, selected_json),\n original == layers_json(layers));\n } else if (command == \"P\" || command == \"R\" || command == \"J\") {\n const auto keys = read_keys();\n const std::string original_keys = sequence(keys, quote);\n last_plan = dirty_plan();\n Error error;\n bool unchanged;\n if (command == \"P\") {\n const std::string original = layers_json(layers);\n error = make_plan(layers, keys, last_plan);\n unchanged = original == layers_json(layers);\n } else {\n if ((command == \"R\" && !compiled) || (command == \"J\" && !held)) {\n throw std::runtime_error(\"compiled input unavailable\");\n }\n const auto &configuration = command == \"R\" ? last_configuration : held_configuration;\n const std::string original = configuration_json(configuration);\n error = plan_configuration(configuration, keys, last_plan);\n unchanged = original == configuration_json(configuration);\n }\n row = result_row(command, error, plan_json(last_plan),\n unchanged && original_keys == sequence(keys, quote));\n } else if (command == \"H\" || command == \"Q\") {\n if (command == \"H\") {\n if (!compiled) {\n throw std::runtime_error(\"compiled input unavailable\");\n }\n held_configuration = last_configuration;\n held_plan = last_plan;\n held = true;\n } else if (!held) {\n throw std::runtime_error(\"held input unavailable\");\n }\n row = \"[\" + quote(command) + ',' + configuration_json(held_configuration) + ',' +\n plan_json(held_plan) + ']';\n } else {\n throw std::runtime_error(\"unknown command\");\n }\n std::cout << row << '\\n';\n }\n return std::cin.bad() ? 2 : 0;\n } catch (const std::exception &error) {\n std::cerr << error.what() << '\\n';\n return 2;\n }\n}\n"
}