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

6.4 KiB

Rule service contract, revision 1

C01. This is a C11 byte-processing service. Build with make, run make demo, or pipe the command stream below to ./rule-demo. No external package is required. The frozen public driver and compiler are part of the service; final submissions replace only engine.c. Do not replace the compiler port with a matcher having different ownership semantics.

C02. rules.h declares all callable interfaces and bounds. Initialize a fresh rule_bank once with bank_init. Its state is opaque to callers. Initial count and generation are zero; no compiled program is owned. Other functions accept initialized banks. Valid pointers are supplied by the driver. bank_clear releases the installed bank, sets count to zero and advances generation once even if already empty. It leaves the bank reusable.

C03. bank_replace accepts 0..32 ordered rules. Identifiers are unique integers 1..1000000. Priorities are -1000..1000. A pattern has 0..128 bytes. Before compiling any rules, validate the complete list: out of bounds fields, duplicate identifiers or overlong patterns return PORT_ARGUMENT (3), without changing the bank or consuming compiler budget. count zero installs an empty bank successfully.

C04. Patterns are a restricted regular expression language. Each unescaped ASCII byte 1..127 is a literal except . [ ] ^ $ * + ? and backslash. A backslash quotes the following ASCII byte 1..127. Dot matches any byte, including NUL and newline. ^ is allowed only at the beginning and $ only at the end (use backslash for literal anchors). No alternation or grouping: | ( ) { } are ordinary literal bytes. Empty expressions and anchors without atoms are valid.

C05. A character class [abc] is a nonempty set of ASCII bytes 1..127; a leading ^ negates that set against all 256 possible message bytes. Inside a class backslash quotes one byte; an unescaped ] ends the class. Each member may be followed by - and a second member, defining an inclusive ascending range. A range endpoint must exist, cannot be an unescaped closing bracket, and must be >= its first endpoint. A trailing hyphen is invalid. A leading hyphen is a literal if not followed by another hyphen. Duplicate members are harmless. Empty/unclosed classes, descending ranges, unmatched closing brackets, unquoted misplaced anchors, NUL/non-ASCII pattern bytes and unfinished escapes are PORT_SYNTAX (1).

C06. Each atom may have one postfix ? (zero or one), * (zero or more), or + (one or more). Bare or doubled postfix operators are invalid syntax. Matching searches for any substring unless anchored; $ means the actual end of the byte message, including if its last byte is newline. There is no text encoding or case folding. One successful port_compile owns exactly one compiled program with one ledger term per atom (anchor/postfix/class members do not add terms). Empty patterns own a program with zero terms. port_release(NULL) is harmless; release each successful compiled object exactly once, including failure rollback and retirement.

C07. port_budget(-1) enables unlimited successful compiles; port_budget(n>=0) permits the next n successful compiles, then port_compile returns PORT_MEMORY (2) without allocating. Syntax is validated first: malformed patterns return 1 even at budget zero. Failed attempts consume no budget. Releasing objects does not replenish budget. This deterministic allocation model is independent of the host allocator. The public ledger port_current_usage counts all live compiler objects and their terms, including any not installed. No business operation may mutate or reset that ledger directly.

C08. For a valid field list, compile in input order. On the first compiler error return its exact code, release every temporary program and preserve the previous bank (including its count, generation, match behavior and ledger). Do not precompile or prevalidate later patterns to change which compiler error wins. On complete success publish the new bank, advance generation once, and retire every old program. Pattern bytes remain caller-owned; installed programs cannot depend on the input buffers remaining unchanged. The bank remains usable after every failure.

C09. bank_match accepts messages of 0..256 bytes. Longer messages return 3 and leave the output structure unchanged. On success it returns 0, counts every matching rule once, and selects the matching rule with the highest numeric priority; ties select the lowest input index. Report identifier, priority and the original zero-based input index. With no hits return hits=0, identifier=priority=0, input_index=-1. Matching never changes the bank, budget or compiler ledger. An empty bank matches no rules.

C10. The public driver is a raw observer and can be used with private input matrices. Input tokens are separated by ordinary ASCII whitespace. B n is followed by n triples identifier priority hexpattern; M hexmessage matches; F budget sets the port budget; C clears; S queries. Hex strings encode bytes, and - is the empty string. The driver permits up to 64 rules and up to 1024 bytes per hex field so business rejection is observable. Other malformed driver input exits nonzero. At EOF the driver clears once and prints that observation. The --demo path installs ^err/warn/fatal, queries warning: disk full, then clears.

C11. Each B/C/S observation is a line of five decimal integers: status count generation live_programs live_terms. F prints the budget. M prints eight decimal integers: status hits identifier priority input_index generation live_programs live_terms. On M argument failure the driver sentinel result is 999,999,999,999. EOF prints a final five-integer clear observation. Output rows may use leading signs, arbitrarily many leading zeroes, and space/TAB/CR between tokens; LF terminates each row. Decimal digits are ASCII 0..9 only. Harmless leading/trailing horizontal whitespace is accepted. No additional stdout text is allowed. Arbitrary stderr diagnostics are permitted and do not change business acceptance.

C12. All required operation results, real hit/selection behavior, atomic failure semantics and public compiler ownership must satisfy these clauses across repeated replacements, errors, empty lists and lifetime closure. No behavior is defined for an uninitialized bank, caller-mutated internal state, invalid pointer storage or concurrent calls. The supported single-threaded driver never supplies those cases. Submission files: engine.c.