amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

20 lines
15 KiB
JSON

{
"candidates": [
"src/rule.cpp",
"src/store.cpp",
"src/evaluator.cpp",
"src/text.cpp",
"src/console.cpp"
],
"observer": "#include \"signed_limits.hpp\"\n#include <iomanip>\n#include <iostream>\n#include <string>\n#include <vector>\n\nusing namespace limits;\n\nstatic Rule read_rule() {\n Rule r;\n std::uint32_t m, a, enabled;\n std::cin >> r.id >> r.channel >> m >> a >> r.priority >> r.lower >> r.upper >> enabled;\n r.mode = static_cast<Mode>(m);\n r.action = static_cast<Action>(a);\n r.enabled = enabled != 0;\n return r;\n}\n\nstatic Observation read_observation() {\n Observation o;\n std::cin >> o.token >> o.channel >> o.value;\n return o;\n}\n\nstatic void decision(const Decision &d) {\n std::cout << \"D \" << d.token << ' ' << d.channel << ' ' << d.value;\n std::cout << ' ' << static_cast<std::uint32_t>(d.action) << ' ' << d.rule_id;\n std::cout << ' ' << d.priority << ' ' << d.matched << ' ' << d.lower_order;\n std::cout << ' ' << d.upper_order << ' ' << d.revision << '\\n';\n}\n\nstatic void summary(const Summary &s) {\n std::cout << \"S \" << s.count << ' ' << s.allowed << ' ' << s.denied;\n std::cout << ' ' << s.deferred << ' ' << s.matched << ' ' << s.has_values;\n std::cout << ' ' << s.minimum << ' ' << s.maximum << '\\n';\n}\n\nint main() {\n RuleStore store;\n Snapshot saved;\n std::string op;\n while (std::cin >> op) {\n Error error = Error::Ok;\n bool mutation = true;\n if (op == \"R\") {\n unsigned n;\n std::cin >> n;\n std::vector<Rule> rules;\n for (unsigned i = 0; i < n; ++i) rules.push_back(read_rule());\n error = store.replace(rules);\n } else if (op == \"U\") {\n error = store.upsert(read_rule());\n } else if (op == \"X\") {\n std::uint32_t id;\n std::cin >> id;\n error = store.erase(id);\n } else if (op == \"N\") {\n std::uint32_t id, enabled;\n std::cin >> id >> enabled;\n error = store.set_enabled(id, enabled != 0);\n } else if (op == \"C\") {\n store.clear();\n } else {\n mutation = false;\n if (op == \"V\") {\n const auto s = store.snapshot();\n std::cout << \"V \" << s.revision << ' ' << s.rules.size() << '\\n';\n for (const auto &r : s.rules) {\n std::cout << \"T \" << r.id << ' ' << r.channel;\n std::cout << ' ' << static_cast<std::uint32_t>(r.mode);\n std::cout << ' ' << static_cast<std::uint32_t>(r.action);\n std::cout << ' ' << r.priority << ' ' << r.lower << ' ' << r.upper;\n std::cout << ' ' << r.enabled << '\\n';\n }\n } else if (op == \"E\" || op == \"F\") {\n const auto o = read_observation();\n decision(evaluate(op == \"F\" ? saved : store.snapshot(), o));\n } else if (op == \"B\") {\n unsigned n;\n std::cin >> n;\n std::vector<Observation> observations;\n for (unsigned i = 0; i < n; ++i) observations.push_back(read_observation());\n const auto results = evaluate_batch(store.snapshot(), observations);\n for (const auto &d : results) decision(d);\n summary(summarize(results));\n } else if (op == \"K\") {\n std::int64_t value;\n std::uint64_t bound;\n std::cin >> value >> bound;\n std::cout << \"K \" << compare_bound(value, bound) << '\\n';\n } else if (op == \"H\") {\n std::uint32_t mode, action;\n int error_value;\n std::cin >> mode >> action >> error_value;\n std::cout << \"H \" << mode_name(static_cast<Mode>(mode));\n std::cout << ' ' << action_name(static_cast<Action>(action));\n std::cout << ' ' << error_name(static_cast<Error>(error_value)) << '\\n';\n } else if (op == \"P\") {\n std::string u, s;\n std::cin >> std::quoted(u) >> std::quoted(s);\n std::uint64_t uv = 99;\n std::int64_t sv = -99;\n const bool uok = parse_u64(u, uv), sok = parse_i64(s, sv);\n std::cout << \"P \" << uok << ' ' << uv << ' ' << sok << ' ' << sv << '\\n';\n } else if (op == \"S\") {\n saved = store.snapshot();\n std::cout << \"A \" << saved.revision << ' ' << saved.rules.size() << '\\n';\n } else {\n return 20;\n }\n }\n if (mutation) {\n std::cout << \"M \" << static_cast<int>(error) << ' ' << store.revision();\n std::cout << ' ' << store.size() << '\\n';\n }\n if (!std::cin || !std::cout) return 21;\n }\n return 0;\n}\n",
"files": {
"Makefile": "CXX ?= g++\nCXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -pedantic\nSOURCES = src/rule.cpp src/store.cpp src/evaluator.cpp src/text.cpp src/console.cpp app/main.cpp\n\nlimits: $(SOURCES) include/signed_limits.hpp\n\t$(CXX) $(CXXFLAGS) -Iinclude $(SOURCES) -o $@\n\n.PHONY: clean\nclean:\n\trm -f limits\n",
"README.md": "# Signed limits replay\n\nRead docs/limits-contract.md for the full public contract and API semantics.\nBuild: `make`. Reproduce the incident: `./limits demo`.\nFurther supported replays: `./limits stream < examples/priority.txt` and\n`./limits stream < examples/boundaries.txt`.\nThe simulator evaluates deterministic configuration rules, not a real sensor.\n",
"app/main.cpp": "#include \"signed_limits.hpp\"\n#include <iostream>\n#include <string>\n\nint main(int argc, char **argv) {\n if (argc == 2 && std::string(argv[1]) == \"demo\") {\n return limits::run_demo(std::cout);\n }\n if (argc == 2 && std::string(argv[1]) == \"stream\") {\n return limits::run_console(std::cin, std::cout);\n }\n std::cerr << \"usage: limits demo|stream\\n\";\n return 2;\n}\n",
"docs/limits-contract.md": "# Signed limits engine contract (revision 1)\n\n1. Build with `make` using the bundled C++17 sources, g++ and standard library only. No board, clock, network, or external package is involved. `./limits demo` runs the public incident replay; `./limits stream` processes the command protocol below.\n2. A Rule has id in 1..UINT32_MAX, channel in 0..15, mode 0..5, action 0..2, priority in INT32_MIN..INT32_MAX, lower and upper in 0..UINT64_MAX, and enabled 0 or 1. Observations have token in 0..UINT64_MAX, channel in 0..15 and value in INT64_MIN..INT64_MAX. Numeric relations mean relations between mathematical integers throughout these complete domains, including negative values and unsigned thresholds beyond INT64_MAX.\n3. Modes are BELOW=0 (value < lower), AT_MOST=1 (value <= lower), AT_LEAST=2 (value >= lower), ABOVE=3 (value > lower), BAND=4 (lower <= value <= upper), OUTSIDE=5 (value < lower or value > upper). BAND and OUTSIDE require lower <= upper; other modes preserve but do not constrain upper. Only enabled rules on the observation channel participate.\n4. All matching rules contribute to matched. The winner has greatest mathematical priority, then smallest id. Insertion order has no influence. Actions are ALLOW=0, DENY=1, DEFER=2. With no winner return DEFER, id=0, priority=0, matched=0, lower_order=upper_order=2. With a winner preserve its action/id/priority and report each mathematical comparison value versus its lower/upper as -1, 0 or 1. All decisions copy token/channel/value and the snapshot revision.\n5. Store capacity is 32 rules. Snapshot rules are in increasing id order. `replace` validates every rule then duplicate ids then capacity, atomically replaces on success. `upsert` validates first, replaces an existing id or inserts if capacity permits. `erase` and `set_enabled` require an existing id. Failed mutations leave the complete snapshot and revision unchanged. Each successful mutation increments revision once, including identical replacement, unchanged enable, empty clear, and empty replacement. Initial revision is zero. Evaluating and snapshotting never mutate the store.\n6. Rule validation returns the first error in this order: BAD_ID=1, BAD_CHANNEL=2, BAD_MODE=3, BAD_ACTION=4, BAD_BAND=5. Store errors are DUPLICATE=6, CAPACITY=7, MISSING=8; OK=0. For `replace`, validate rules in input order, then detect duplicates, then capacity. Validation of enabled is unnecessary at the C++ API: it is a bool. Public API declarations and result structures are in include/signed_limits.hpp; all fields have the semantics stated here.\n7. `evaluate_batch` preserves observation order and returns the same decisions as independent `evaluate` on the same snapshot. `summarize` counts decisions, each action, total matched rules, and mathematical minimum/maximum of observation values. Empty summary has has_values=false, minimum=maximum=0. Summary counters are uint64_t. Input scripts contain at most 10000 commands and batches contain at most 4096 observations, so revision/counters cannot overflow.\n8. `parse_u64` accepts 1..20 ASCII decimal digits with optional leading zeroes, no signs/space; it rejects values beyond UINT64_MAX. `parse_i64` accepts 1..20 decimal digits with an optional leading minus; no plus or space; it accepts -0, INT64_MIN and INT64_MAX and rejects values outside the domain. On parse failure the output argument is unchanged. Numeric token length includes digits only, excluding the optional minus. These parsers are reusable public utilities.\n9. `render_decision` emits one space separated line without LF: D token channel value action_name rule_id priority matched lower_order upper_order revision. `render_summary` emits: S count allowed denied deferred matched has_values minimum maximum, with has_values as 0/1. Action names are ALLOW, DENY, DEFER. Enum-name functions return UNKNOWN for out of domain values. Error names match clause 6. Mode names match clause 3.\n10. The stream protocol is ASCII whitespace tokenized. Commands: R n followed by n rules; U followed by one rule; X id; N id enabled; C; V; E token channel value; B n followed by n observations; P unsigned_token signed_token. Rule wire fields are id channel mode action priority lower upper enabled. R/U/X/N/C print M error_code revision size. V prints V revision size then one T line per sorted rule in wire field order. E prints render_decision. B prints all decisions then render_summary. P prints P unsigned_ok unsigned_value signed_ok signed_value; initial parser outputs are 99 and -99. Blank lines are ignored. Commands and operands are valid tokens within their declared wire types unless they are P operands or semantically invalid Rule fields covered by clause 6. n <= 33 for R and n <= 4096 for B. Invalid channel observations are outside the contract. Diagnostics on stderr are allowed. Successful valid command streams exit 0.\n11. Demo installs a BELOW rule id=10 channel=0 action=DENY priority=5 lower=4 upper=9 enabled=1, evaluates token=101 channel=0 value=-3, and prints its decision then a one-decision summary. An independent public replay `./limits stream < examples/priority.txt` exercises another supported configuration. `examples/boundaries.txt` exercises equality, wide thresholds, and updates. All public replay streams must follow clauses 2..10; they do not exhaust the contract.\n12. Implementation may change internal representation/algorithm. Preserve public declarations and build, implement all clauses, and submit only src/rule.cpp, src/store.cpp, src/evaluator.cpp, src/text.cpp, src/console.cpp. No unspecified padding, unused storage, build artifact, or stderr wording is part of the output contract.\n",
"examples/boundaries.txt": "R 3\n1 0 4 1 0 0 0 1\n2 1 0 0 4 9223372036854775808 18446744073709551615 1\n3 2 5 1 -2147483648 9 20 1\nB 5\n1 0 0\n2 0 -9223372036854775808\n3 1 9223372036854775807\n4 2 9\n5 2 21\nN 1 0\nE 6 0 0\nP 18446744073709551615 -9223372036854775808\nV\n",
"examples/priority.txt": "R 2\n20 0 2 1 -1 0 18446744073709551615 1\n10 0 2 0 5 0 18446744073709551615 1\nE 101 0 7\nV\n",
"include/signed_limits.hpp": "#ifndef SIGNED_LIMITS_HPP\n#define SIGNED_LIMITS_HPP\n\n#include <cstdint>\n#include <iosfwd>\n#include <string>\n#include <vector>\n\nnamespace limits {\n\nenum class Mode : std::uint32_t {\n Below = 0,\n AtMost = 1,\n AtLeast = 2,\n Above = 3,\n Band = 4,\n Outside = 5\n};\n\nenum class Action : std::uint32_t {\n Allow = 0,\n Deny = 1,\n Defer = 2\n};\n\nenum class Error : int {\n Ok = 0,\n BadId = 1,\n BadChannel = 2,\n BadMode = 3,\n BadAction = 4,\n BadBand = 5,\n Duplicate = 6,\n Capacity = 7,\n Missing = 8\n};\n\nstruct Rule {\n std::uint32_t id = 0;\n std::uint32_t channel = 0;\n Mode mode = Mode::Below;\n Action action = Action::Defer;\n std::int32_t priority = 0;\n std::uint64_t lower = 0;\n std::uint64_t upper = 0;\n bool enabled = true;\n};\n\nstruct Snapshot {\n std::uint64_t revision = 0;\n std::vector<Rule> rules;\n};\n\nstruct Observation {\n std::uint64_t token = 0;\n std::uint32_t channel = 0;\n std::int64_t value = 0;\n};\n\nstruct Decision {\n std::uint64_t token = 0;\n std::uint32_t channel = 0;\n std::int64_t value = 0;\n Action action = Action::Defer;\n std::uint32_t rule_id = 0;\n std::int32_t priority = 0;\n std::uint32_t matched = 0;\n int lower_order = 2;\n int upper_order = 2;\n std::uint64_t revision = 0;\n};\n\nstruct Summary {\n std::uint64_t count = 0;\n std::uint64_t allowed = 0;\n std::uint64_t denied = 0;\n std::uint64_t deferred = 0;\n std::uint64_t matched = 0;\n bool has_values = false;\n std::int64_t minimum = 0;\n std::int64_t maximum = 0;\n};\n\nError validate(const Rule &rule);\nint compare_bound(std::int64_t value, std::uint64_t bound);\nbool matches(const Rule &rule, const Observation &observation);\nconst char *mode_name(Mode mode);\nconst char *action_name(Action action);\nconst char *error_name(Error error);\n\nclass RuleStore {\npublic:\n static constexpr std::size_t capacity = 32;\n Error replace(const std::vector<Rule> &rules);\n Error upsert(const Rule &rule);\n Error erase(std::uint32_t id);\n Error set_enabled(std::uint32_t id, bool enabled);\n void clear();\n Snapshot snapshot() const;\n std::uint64_t revision() const;\n std::size_t size() const;\nprivate:\n std::vector<Rule> rules_;\n std::uint64_t revision_ = 0;\n};\n\nDecision evaluate(const Snapshot &snapshot, const Observation &observation);\nstd::vector<Decision> evaluate_batch(const Snapshot &snapshot,\n const std::vector<Observation> &observations);\nSummary summarize(const std::vector<Decision> &decisions);\nbool parse_u64(const std::string &text, std::uint64_t &value);\nbool parse_i64(const std::string &text, std::int64_t &value);\nstd::string render_decision(const Decision &decision);\nstd::string render_summary(const Summary &summary);\nint run_console(std::istream &input, std::ostream &output);\nint run_demo(std::ostream &output);\n\n}\n#endif\n"
}
}