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

1 line
11 KiB
JSON

{"handoff.h": "#ifndef IO_BUFFER_HANDOFF_H\n#define IO_BUFFER_HANDOFF_H\n\n#include <stddef.h>\n#include <stdint.h>\n\n#define HANDOFF_CHANNELS 2\n#define HANDOFF_PENDING_CAP 2048\n#define HANDOFF_DELIVERED_CAP 8192\n#define HANDOFF_WRITE_SLICE 37\n\ntypedef struct {\n unsigned char pending[HANDOFF_PENDING_CAP];\n size_t pending_len;\n unsigned char delivered[HANDOFF_DELIVERED_CAP];\n size_t delivered_len;\n uint32_t generation;\n uint32_t accepted;\n uint32_t handoffs;\n uint32_t flushes;\n int quota;\n int fail_next;\n} HandoffChannel;\n\ntypedef struct {\n HandoffChannel channel[HANDOFF_CHANNELS];\n} HandoffEngine;\n\ntypedef struct {\n uint32_t generation;\n uint32_t accepted;\n uint32_t handoffs;\n uint32_t flushes;\n int quota;\n int fail_next;\n size_t pending_len;\n size_t delivered_len;\n unsigned char pending[HANDOFF_PENDING_CAP];\n unsigned char delivered[HANDOFF_DELIVERED_CAP];\n} HandoffSnapshot;\n\nvoid handoff_reset(HandoffEngine *engine);\nint handoff_append(HandoffEngine *engine, int channel, const unsigned char *bytes, size_t length);\nint handoff_append_repeat(HandoffEngine *engine, int channel, const unsigned char *bytes, size_t length, unsigned count);\nint handoff_flush(HandoffEngine *engine, int channel);\nint handoff_replace(HandoffEngine *engine, int channel);\nint handoff_policy(HandoffEngine *engine, int channel, int quota, int fail_next);\nint handoff_mirror(HandoffEngine *engine, int source, int destination);\nint handoff_transfer(HandoffEngine *engine, int source, int destination, size_t count);\nint handoff_acknowledge(HandoffEngine *engine, int channel, size_t count);\nint handoff_replace_pair(HandoffEngine *engine);\nint handoff_cancel_suffix(HandoffEngine *engine, int channel, size_t count);\nint handoff_exchange(HandoffEngine *engine, int source, int destination);\nint handoff_snapshot(const HandoffEngine *engine, int channel, HandoffSnapshot *out);\n\n#endif\n", "observer.c": "#define _POSIX_C_SOURCE 200809L\n#include \"handoff.h\"\n\n#include <errno.h>\n#include <limits.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n\n#define TOKEN_CAP 5\n\ntypedef struct {\n char *item[TOKEN_CAP];\n size_t count;\n int excess;\n} Tokens;\n\nstatic int horizontal_space(char c)\n{\n return c == ' ' || c == '\\t' || c == '\\r';\n}\n\nstatic Tokens tokenize(char *line)\n{\n Tokens tokens;\n char *cursor = line;\n size_t i;\n for (i = 0; i < TOKEN_CAP; ++i) {\n tokens.item[i] = NULL;\n }\n tokens.count = 0;\n tokens.excess = 0;\n while (*cursor != '\\0' && *cursor != '\\n') {\n char *begin;\n while (horizontal_space(*cursor)) {\n ++cursor;\n }\n if (*cursor == '\\0' || *cursor == '\\n') {\n break;\n }\n begin = cursor;\n while (*cursor != '\\0' && *cursor != '\\n' && !horizontal_space(*cursor)) {\n ++cursor;\n }\n if (*cursor != '\\0') {\n *cursor = '\\0';\n ++cursor;\n }\n if (tokens.count < TOKEN_CAP) {\n tokens.item[tokens.count++] = begin;\n } else {\n tokens.excess = 1;\n }\n }\n return tokens;\n}\n\nstatic int digit_value(char c)\n{\n if (c >= '0' && c <= '9') {\n return c - '0';\n }\n return -1;\n}\n\nstatic int parse_number(const char *text, int minimum, int maximum, int *value)\n{\n const char *cursor = text;\n int negative = 0;\n int64_t magnitude = 0;\n int64_t limit;\n if (*cursor == '+' || *cursor == '-') {\n negative = *cursor == '-';\n ++cursor;\n }\n if (*cursor == '\\0') {\n return 0;\n }\n limit = negative ? -(int64_t)minimum : maximum;\n while (*cursor != '\\0') {\n int digit = digit_value(*cursor++);\n if (digit < 0) {\n return 0;\n }\n if (magnitude > (limit - digit) / 10) {\n return 0;\n }\n magnitude = magnitude * 10 + digit;\n }\n if (negative) {\n magnitude = -magnitude;\n }\n if (magnitude < minimum || magnitude > maximum) {\n return 0;\n }\n *value = (int)magnitude;\n return 1;\n}\n\nstatic int hex_digit(char c)\n{\n if (c >= '0' && c <= '9') {\n return c - '0';\n }\n if (c >= 'a' && c <= 'f') {\n return c - 'a' + 10;\n }\n if (c >= 'A' && c <= 'F') {\n return c - 'A' + 10;\n }\n return -1;\n}\n\nstatic int decode_hex(const char *text, unsigned char *output, size_t *length)\n{\n size_t i;\n size_t count;\n if (strcmp(text, \"-\") == 0) {\n *length = 0;\n return 1;\n }\n count = strlen(text);\n if (count == 0 || count > 256 || count % 2 != 0) {\n return 0;\n }\n for (i = 0; i < count / 2; ++i) {\n int high = hex_digit(text[i * 2]);\n int low = hex_digit(text[i * 2 + 1]);\n if (high < 0 || low < 0) {\n return 0;\n }\n output[i] = (unsigned char)((high << 4) | low);\n }\n *length = count / 2;\n return 1;\n}\n\nstatic int parse_channel(const char *text, int *channel)\n{\n return parse_number(text, 0, HANDOFF_CHANNELS - 1, channel);\n}\n\nstatic int execute(HandoffEngine *engine, Tokens tokens)\n{\n int channel;\n int quota;\n int fault;\n int repeat;\n int destination;\n int amount;\n unsigned char bytes[128];\n size_t length;\n if (tokens.excess || tokens.count == 0 || strlen(tokens.item[0]) != 1) {\n return -2;\n }\n switch (tokens.item[0][0]) {\n case 'R':\n if (tokens.count != 1) {\n return -2;\n }\n handoff_reset(engine);\n return 0;\n case 'Q':\n return tokens.count == 1 ? 0 : -2;\n case 'A':\n if (tokens.count != 3 || !parse_channel(tokens.item[1], &channel) ||\n !decode_hex(tokens.item[2], bytes, &length)) {\n return -2;\n }\n return handoff_append(engine, channel, bytes, length);\n case 'M':\n if (tokens.count != 4 || !parse_channel(tokens.item[1], &channel) ||\n !parse_number(tokens.item[2], 0, 16, &repeat) ||\n !decode_hex(tokens.item[3], bytes, &length)) {\n return -2;\n }\n return handoff_append_repeat(engine, channel, bytes, length, (unsigned)repeat);\n case 'D':\n if (tokens.count != 3 || !parse_channel(tokens.item[1], &channel) ||\n !parse_channel(tokens.item[2], &destination) || channel == destination) {\n return -2;\n }\n return handoff_mirror(engine, channel, destination);\n case 'T':\n if (tokens.count != 4 || !parse_channel(tokens.item[1], &channel) ||\n !parse_channel(tokens.item[2], &destination) || channel == destination ||\n !parse_number(tokens.item[3], 0, HANDOFF_PENDING_CAP, &amount)) {\n return -2;\n }\n return handoff_transfer(engine, channel, destination, (size_t)amount);\n case 'K':\n if (tokens.count != 3 || !parse_channel(tokens.item[1], &channel) ||\n !parse_number(tokens.item[2], 0, HANDOFF_DELIVERED_CAP, &amount)) {\n return -2;\n }\n return handoff_acknowledge(engine, channel, (size_t)amount);\n case 'Z':\n if (tokens.count != 1) {\n return -2;\n }\n return handoff_replace_pair(engine);\n case 'L':\n if (tokens.count != 3 || !parse_channel(tokens.item[1], &channel) ||\n !parse_number(tokens.item[2], 0, HANDOFF_PENDING_CAP, &amount)) {\n return -2;\n }\n return handoff_cancel_suffix(engine, channel, (size_t)amount);\n case 'X':\n if (tokens.count != 3 || !parse_channel(tokens.item[1], &channel) ||\n !parse_channel(tokens.item[2], &destination) || channel == destination) {\n return -2;\n }\n return handoff_exchange(engine, channel, destination);\n case 'F':\n if (tokens.count != 2 || !parse_channel(tokens.item[1], &channel)) {\n return -2;\n }\n return handoff_flush(engine, channel);\n case 'H':\n if (tokens.count != 2 || !parse_channel(tokens.item[1], &channel)) {\n return -2;\n }\n return handoff_replace(engine, channel);\n case 'P':\n if (tokens.count != 4 || !parse_channel(tokens.item[1], &channel) ||\n !parse_number(tokens.item[2], -1, HANDOFF_DELIVERED_CAP, &quota) ||\n !parse_number(tokens.item[3], 0, 1, &fault)) {\n return -2;\n }\n return handoff_policy(engine, channel, quota, fault);\n default:\n return -2;\n }\n}\n\nstatic void print_hex(const unsigned char *bytes, size_t count)\n{\n static const char alphabet[] = \"0123456789abcdef\";\n size_t i;\n if (count == 0) {\n putchar('-');\n return;\n }\n for (i = 0; i < count; ++i) {\n putchar(alphabet[bytes[i] >> 4]);\n putchar(alphabet[bytes[i] & 15]);\n }\n}\n\nstatic void print_snapshot(size_t sequence, int channel, const HandoffSnapshot *snapshot)\n{\n printf(\"S %zu %d %u %u %u %u %d %d %zu %zu \",\n sequence, channel, snapshot->generation, snapshot->accepted,\n snapshot->handoffs, snapshot->flushes, snapshot->quota,\n snapshot->fail_next, snapshot->pending_len, snapshot->delivered_len);\n print_hex(snapshot->pending, snapshot->pending_len);\n putchar(' ');\n print_hex(snapshot->delivered, snapshot->delivered_len);\n putchar('\\n');\n}\n\nstatic int emit_state(const HandoffEngine *engine, size_t sequence, int status)\n{\n int channel;\n printf(\"E %zu %d\\n\", sequence, status);\n for (channel = 0; channel < HANDOFF_CHANNELS; ++channel) {\n HandoffSnapshot snapshot;\n if (handoff_snapshot(engine, channel, &snapshot) != 0) {\n return 0;\n }\n print_snapshot(sequence, channel, &snapshot);\n }\n return 1;\n}\n\nint main(void)\n{\n HandoffEngine engine;\n char *line = NULL;\n size_t capacity = 0;\n size_t sequence = 0;\n ssize_t count;\n handoff_reset(&engine);\n while ((count = getline(&line, &capacity, stdin)) >= 0) {\n Tokens tokens;\n int status;\n if (count == 0) {\n continue;\n }\n ++sequence;\n tokens = tokenize(line);\n status = execute(&engine, tokens);\n if (!emit_state(&engine, sequence, status)) {\n free(line);\n return 2;\n }\n }\n if (ferror(stdin) || ferror(stdout)) {\n free(line);\n return 2;\n }\n free(line);\n return 0;\n}\n"}