Find unanswered requests and unmatched results in a supplied ordered event list. This is a local data check under the documented conventions; it does not execute tools or contact a service.
Before you start
- Save the code as recipe.cjs and run node recipe.cjs using Node.js 22, supplying JSON on standard input. No CLI arguments are accepted, including help options.
- Uses only node:fs, exclusively for bounded readSync calls on stdin. It does not open input paths, write files, execute commands or contact a network.
- Input must be a JSON array containing at most 100 non-null, non-array objects. Each object must have kind exactly request or result and a nonempty string id of at most 80 UTF-16 code units. Additional fields are ignored.
- Strict UTF-8 decoding uses global TextDecoder with fatal:true and ignoreBOM:true. A leading UTF-8 BOM remains in the decoded text and is rejected by JSON.parse. Native JSON.parse semantics apply, including duplicate-member handling.
- IDs are case-sensitive. Events are processed in order, starting with an empty pending Set. Repeated requests leave the original pending request unchanged; matching results remove it. An ID may be reused after completion.
- Successful output is exactly one JSON object followed by a newline. unanswered uses JavaScript default UTF-16 sorting; unmatched_results and repeated_requests contain ascending one-based positions. Pairing issues still exit 0 without stderr.
- Invalid arguments, invalid input and stdin read failures produce no stdout, report only error: invalid input on stderr, and exit 2. Diagnostics do not reveal input values.
- There are no integer input fields to validate. Reported positions are generated safe integers between 1 and 100.
Build and check
- Use Node.js 22 CommonJS. Save the code as recipe.cjs.
- Save the supplied JSON example as input.json, encoded as UTF-8 without a BOM.
- Run: node recipe.cjs < input.json
- Compare the output with the expected result; handle exit code 2 as invalid input.
Limits to understand
- Reads at most 65537 bytes and rejects input exceeding 65536 bytes. Valid-sized input is read until EOF, so stdin may block waiting for EOF.
- Input is held in memory: a fixed 65537-byte buffer, decoded text, the parsed array and reporting collections. Processing is not streaming.
- ID length is measured using JavaScript string.length, not Unicode code points or grapheme clusters.
- Successful output includes pending IDs and event positions and may contain sensitive information.
- Output-write failures, including stdout or stderr failures, are excluded from the stated error-handling guarantee.
- This audits request/result pairing only. It does not execute tools, validate a provider protocol or establish provider integration or production suitability.
Run it
node recipe.cjs < input.jsonExample input
[{"kind": "request", "id": "a"}, {"kind": "result", "id": "b"}]Expected output
{"unanswered": ["a"], "unmatched_results": [2], "repeated_requests": []}
