=== BEGIN ARTIFACT FEATURE-Control.md === # FEATURE: Conditional and Error Control | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Evaluate jq conditionals, alternatives, and error handlers. | | Depends On | FEATURE-Operators.md | | Provides | jq conditional and error control | | Consumes | jq operators | ## Behavior For each condition output, evaluate the corresponding branch against the condition's input; only false and null select the false branch. An omitted else branch is identity. Support elif and conditions that yield zero or multiple values. The alternative operator emits all non-false, non-null outputs of its left side, or evaluates its right side when none exist. Try and catch handle errors raised within their expression boundaries, passing the error value to the handler. The optional suffix suppresses errors as an empty handler. Preserve outputs already emitted before an error and do not catch errors raised outside the handler's scope. ## Programmatic Acceptance === AC control-corpus === Intent: Conditional and alternative expressions execute the selected corpus cases with jq truth and stream semantics. Suite: scoped Requires: executable=python3; scope=test Probe: python3 -c 'import re, sys; sys.path.insert(0, "sources"); import run_conformance as h; cases = h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); assert any(re.search(r"^\[if (1,null,2|empty|1|null) then|^\[if (true|false) then|^if false then 3", c.program) for c in cases)' import json import os import subprocess import sys SELECT = r"^\[if (1,null,2|empty|1|null) then|^\[if (true|false) then|^if false then 3" 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"] print(f"{tally['pass']} passed, {tally['fail']} failed, {tally['error']} errored") assert sum(tally.values()) > 0 assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC control-corpus === ## User Acceptance - None. ## Guardrails - Preserve partial output and lexical error boundaries. - Defer selected cases requiring functions or other later capabilities to scoped integration. === END ARTIFACT === === BEGIN ARTIFACT FEATURE-Conversion.md === # FEATURE: Type and Conversion Builtins | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Inspect jq values and convert among numeric, Boolean, string, JSON, and Unicode representations. | | Depends On | FEATURE-GeneratorControl.md | | Provides | jq type and conversion builtins | | Consumes | jq reductions and generator control | ## Purpose Expose jq's type and conversion filters to programs, using the manual and corpus as the behavioral authority. ## Behavior Implement `type`, `length`, `utf8bytelength`, `tonumber`, `toboolean`, `tostring`, `tojson`, `fromjson`, `explode`, and `implode`, including their specified input types and errors. String length counts Unicode codepoints; UTF-8 byte length counts encoded bytes. Preserve jq's conversion and serialization behavior, including non-decnum numeric behavior and special numeric values. Unicode conversion follows jq's replacement behavior for invalid codepoints. Errors caught by jq programs are values and must match the corpus where it specifies them. ## Programmatic Acceptance === AC conversion-conformance === Intent: Type, length, conversion, and Unicode filters execute their applicable corpus cases. Suite: scoped Requires: executable=python3; scope=test Probe: python3 -c 'import re, sys; sys.path.insert(0, "sources"); import run_conformance as h; cases = h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); assert any(re.search(r"^(?:utf8bytelength|\[\.\[\] \| length\]|\[\.\[\] \| try utf8bytelength catch \.\]|implode\|explode|fromjson \| isnan|tojson \| fromjson)$", c.program) for c in cases)' import json import os import subprocess import sys SELECT = r"^(?:utf8bytelength|\[\.\[\] \| length\]|\[\.\[\] \| try utf8bytelength catch \.\]|implode\|explode|fromjson \| isnan|tojson \| fromjson)$" 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, SELECT assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC conversion-conformance === ## User Acceptance - None. ## Guardrails - Do not mutate any file under `sources/`. - Use Python's standard library only. - Cross-feature cases requiring later builtins remain covered by scoped integration. === 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 | ## 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 Probe: python3 -c 'import re, sys; sys.path.insert(0, "sources"); import run_conformance as h; cases = h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); assert any(re.search(r"\b(?:strftime|strflocaltime|strptime|mktime|gmtime)\b", c.program) for c in cases)' 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-Documentation.md === # FEATURE: Usage Documentation | Field | Value | |-------|-------| | Version | 20261028 V1 | | Description | Document the standalone command and its verification interface. | | Depends On | FEATURE-Command.md | | Provides | jq usage documentation | | Consumes | ./jq -c | ## Purpose and behavior Deliver a concise application-root README describing `./jq -c ''`, JSON input on standard input, compact JSON values on standard output, the completion, compilation-error, and runtime-error exit codes 0, 3, and 5, and the supplied `sh sources/full_test.sh` verification command. Diagnostics are written to standard error. ## Programmatic Acceptance === AC documented-command === Intent: The documented command accepts JSON input and returns the input value as JSON. Requires: executable=python3; scope=test import json import subprocess import sys value = {"items": [1, 2]} result = subprocess.run( ["./jq", "-c", "."], input=json.dumps(value), capture_output=True, text=True ) print(result.stdout) print(result.stderr, file=sys.stderr) assert result.returncode == 0 assert json.loads(result.stdout) == value === END AC documented-command === === AC documented-corpus === Intent: The documented command passes an executing slice of identity filters. Suite: scoped Requires: executable=python3; scope=test Probe: python3 -c 'import re, sys; sys.path.insert(0, "sources"); import run_conformance as h; cases = h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); assert any(re.search(r"^\.$", c.program) for c in cases)' import json import os import subprocess import sys SELECT = r"^\.$" 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"] print(f"{tally['pass']} passed, {tally['fail']} failed, {tally['error']} errored") 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 documented-corpus === ## User Acceptance - None. ## Guardrails - Keep the supplied scoring assets unchanged. === END ARTIFACT === === 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 | ## 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 Probe: python3 -c 'import re, sys; sys.path.insert(0, "sources"); import run_conformance as h; cases = h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); assert any(re.search(r"@(?:text|json|html|uri|urid|csv|tsv|sh|base64d?)\b", c.program) for c in cases)' 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 ===