=== BEGIN ARTIFACT FEATURE-Formats.md === # FEATURE: Format Filters | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Encode and decode values with jq format filters. | | Depends On | FEATURE-Strings.md | | Provides | jq format filters | | Consumes | jq string and regex builtins | ## Questions - None. ## Purpose Provide jq's text, JSON, HTML, URI, CSV, TSV, shell, and Base64 formats as described in `sources/jq-manual.txt`. Formatting is triggered by a format filter or a formatted string in a jq program. ## Behavior - `@text` uses jq string conversion and `@json` serializes JSON. HTML formatting escapes the five specified HTML characters. - URI and Base64 filters encode their inputs; `@urid` and `@base64d` decode their respective encodings. Preserve UTF-8 behavior. - CSV and TSV accept arrays and apply jq's field quoting and escaping rules. Shell formatting produces POSIX shell-escaped values. - In a formatted string, retain literal text and apply the selected format to each interpolated result. Preserve generator multiplicity and order. - Invalid inputs raise jq runtime errors. Follow the manual and the relevant corpus cases, including interactions with interpolation. ## Programmatic Acceptance === AC formats-corpus === Intent: Format filters execute the corpus cases that exercise their encoding and interpolation behavior. Suite: scoped Requires: executable=python3; scope=test import json import os import subprocess import sys SELECT = r"@(?:text|json|html|uri|urid|csv|tsv|sh|base64d?)\b" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}" assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC formats-corpus === ## User Acceptance - None. ## Guardrails - Use only the Python standard library and do not invoke a system jq or third-party jq implementation. - Do not alter staged source assets. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Numeric.md === # FEATURE: Numeric Builtins | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Implement jq math functions and non-decnum numeric behavior. | | Depends On | FEATURE-Formats.md | | Provides | jq numeric builtins | | Consumes | jq format filters | ## Questions - None. ## Purpose Provide the math functions and numeric edge cases exercised by the jq 1.8.2 corpus, following the manual's non-decnum behavior. ## Behavior - Implement the corpus-required unary, binary, and ternary math functions with jq argument and generator semantics. - Use IEEE double-precision behavior for arithmetic and comparisons, including infinities, NaN, signed values, and jq's serialization of special numeric values. - Return false for `have_decnum` and follow the corpus's non-decnum branch for parsing, conversion, rounding, and serialization. - Raise runtime errors where the manual and corpus require them; preserve output already generated. ## Programmatic Acceptance === AC numeric-corpus === Intent: Numeric functions and the selected non-decnum cases execute with the corpus-defined results. Suite: scoped Requires: executable=python3; scope=test import json import os import subprocess import sys SELECT = r"have_decnum|isnan|infinite|pow\(|\bfabs\b|\bsqrt\b|\bfloor\b" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}" assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC numeric-corpus === ## User Acceptance - None. ## Guardrails - Use only the Python standard library; do not invoke a system jq or third-party jq implementation. - Do not alter staged source assets. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Dates.md === # FEATURE: Date and Time Builtins | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Provide jq date parsing, formatting, and time conversion. | | Depends On | FEATURE-Numeric.md | | Provides | jq date builtins | | Consumes | jq numeric builtins | ## Questions - None. ## Purpose Implement the date and time filters exercised by the corpus, following the jq manual and builtin reference. ## Behavior - Parse and format dates with `strptime`, `strftime`, and `strflocaltime`; implement the ISO 8601 aliases and epoch conversions. - Represent broken-down time in jq's array order, with zero-based month and the specified weekday and year-day conventions. Support the input forms and fractional seconds exercised by the corpus. - Apply UTC semantics to UTC functions and local-time semantics to local functions. Invalid formats or broken-down values raise the specified runtime errors. - Preserve argument streams and output order. ## Programmatic Acceptance === AC dates-corpus === Intent: Date parsing, formatting, and time conversion pass their executing corpus slice. Suite: scoped Requires: executable=python3; scope=test import json import os import subprocess import sys SELECT = r"\b(?:strftime|strflocaltime|strptime|mktime|gmtime)\b" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}" assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC dates-corpus === ## User Acceptance - None. ## Guardrails - Use only the Python standard library and preserve the manual's time semantics. - Do not alter staged source assets. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Traversal.md === # FEATURE: Traversal and Streaming | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Traverse jq values recursively and convert them to and from stream events. | | Depends On | FEATURE-Dates.md, FEATURE-Assignment.md | | Provides | jq traversal and streaming builtins | | Consumes | jq date builtins, jq path mutation | ## Questions - None. ## Purpose Provide recursive traversal and stream conversion filters using the generator and path contracts. ## Behavior - `recurse` emits the input and recursively emits successive results in jq order, applying the optional condition to descendants. Preserve lazy backtracking. - `walk` processes children before their containing array or object and then applies its filter, preserving jq's handling of empty and multiple results. - `tostream` emits path and leaf events and closing events in the order described by the manual. `fromstream` reconstructs values from events, and `truncate_stream` removes the requested leading path elements. - Handle empty structures and the corpus's deep-value boundaries without losing output or changing errors. ## Programmatic Acceptance === AC traversal-corpus === Intent: Recursive walking and stream conversion execute their corpus cases with their required ordering. Suite: scoped Requires: executable=python3; scope=test import json import os import subprocess import sys SELECT = r"\b(?:walk|tostream|fromstream|truncate_stream|recurse)\b" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}" assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC traversal-corpus === ## User Acceptance - None. ## Guardrails - Preserve immutable value semantics and ordered generator behavior. - Do not alter staged source assets or use external jq implementations. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-InputDiagnostics.md === # FEATURE: Input and Diagnostics | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Provide jq input, environment, location, and diagnostic filters. | | Depends On | FEATURE-Traversal.md | | Provides | jq input and diagnostic builtins | | Consumes | jq traversal and streaming builtins | ## Questions - None. ## Purpose Provide the input and diagnostic facilities described by the jq manual, sharing the interpreter's input stream and preserving its output stream. ## Behavior - `input` consumes one subsequent JSON value from the shared input stream; `inputs` generates the remaining values in order. Exhaustion follows jq's catchable behavior. - `$ENV` represents the environment at program startup and `env` provides the current environment. Provide the input filename and line number where exercised. - `debug` and `debug(msgs)` write their diagnostic side effects to stderr while preserving their specified output streams; `stderr` writes its input in raw compact form to stderr and yields the input. - `$__loc__` yields the source file and line at its occurrence. Diagnostic output must not corrupt stdout or suppress values emitted before a runtime error. ## Programmatic Acceptance === AC input-diagnostics-corpus === Intent: Input exhaustion, diagnostics, and source locations execute the corresponding corpus cases. Suite: scoped Requires: executable=python3; scope=test import json import os import subprocess import sys SELECT = r"\b(?:input|debug)\b|\$__loc__" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, f"selector matched no case: {SELECT}" assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC input-diagnostics-corpus === ## User Acceptance - None. ## Guardrails - Diagnostics go to stderr; JSON result values go to stdout. - Use only the Python standard library and do not alter staged source assets. === END ARTIFACT ===