=== BEGIN ARTIFACT FEATURE-Assignment.md ===
# FEATURE: Path Mutation
| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Update and delete jq values through path expressions. |
| Depends On | FEATURE-Paths.md |
| Provides | jq path mutation |
| Consumes | jq path lookup |
## Purpose
Provide immutable path-based mutation through `setpath`, `delpaths`, `del`, and assignment expressions. Filters receive the original input value; mutation emits replacement values without changing other references to that input.
## Behavior
`setpath` creates missing objects and arrays as required by a path. `delpaths` removes the supplied paths, and `del` derives those paths from its filter argument. Respect jq's array index, negative-index, slice, type, and depth rules, including errors and deletion of multiple array locations.
For plain `=`, evaluate the right side against the original input and emit a separate updated input for each right-side result. For `|=`, evaluate the update against each selected old value, use only its first result, and delete that path if it produces no result. Arithmetic and alternative updates follow their jq definitions, including the evaluation context of their operands. Path expressions retain generator order and invalid path expressions raise runtime errors.
## Programmatic Acceptance
=== AC assignment-conformance ===
Intent: Path mutation and assignment cases execute with the jq output and error behavior specified by the corpus.
Suite: scoped
Requires: executable=python3; scope=test
Probe: python3 -c 'import re,sys; sys.path.insert(0,"sources"); import run_conformance as h; s=r"^(?:\.message = \"goodbye\"|\.foo = \.bar|\.foo \|= \.\+1|setpath\(\[-1\]; 1\)|map\(getpath\(\[2\]\)\), map\(setpath\(\[2\]; 42\)\), map\(delpaths\(\[\[2\]\]\)\))$"; cases=h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); excluded=h.apply_exclusions(cases,h.parse_exclusions(h.EXCLUSIONS)); assert any(re.search(s,c.program) and c.line not in excluded for c in cases)'
import json
import os
import subprocess
import sys
SELECT = r"^(?:\.message = \"goodbye\"|\.foo = \.bar|\.foo \|= \.\+1|setpath\(\[-1\]; 1\)|map\(getpath\(\[2\]\)\), map\(setpath\(\[2\]; 42\)\), map\(delpaths\(\[\[2\]\]\)\))$"
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 assignment-conformance ===
## User Acceptance
- None.
## Guardrails
- Do not mutate any file under `sources/`.
- Preserve output order, multiplicity, and partial output before runtime errors.
- Cross-feature corpus cases requiring later builtins remain covered by scoped integration.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-Bindings.md ===
# FEATURE: Bindings and Functions
| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Provide lexical bindings, destructuring, and user-defined jq functions. |
| Depends On | FEATURE-Control.md |
| Provides | jq lexical bindings and functions |
| Consumes | jq conditional and error control |
## Behavior
An `as` binding evaluates its source as a generator and runs the remaining expression once per result against the original input with lexical bindings in scope. Array and object patterns bind nested values, using null for missing elements or fields. Destructuring alternatives try subsequent patterns when binding or the downstream expression raises an error; variables absent from the successful pattern are null.
Function definitions are lexically scoped by name and arity, support shadowing and recursion, and capture their defining environment. Filter arguments remain filters evaluated with their invocation input; value parameters bind each argument result at the call site. Preserve backtracking and ordered multiplicity across function calls and returns. Reject undefined symbols and invalid patterns at compile time.
## Programmatic Acceptance
=== AC bindings-corpus ===
Intent: Bindings and function definitions execute the selected corpus cases with lexical scope and generator semantics.
Suite: scoped
Requires: executable=python3; scope=test
Probe: python3 -c 'import re,sys; sys.path.insert(0,"sources"); import run_conformance as h; s=r"^1 as \$x \| 2 as \$y|^1 as \$x \| \[\$x|^def f: \(1000,2000\); f$|^def a: 0; \. \| a$"; cases=h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); excluded=h.apply_exclusions(cases,h.parse_exclusions(h.EXCLUSIONS)); assert any(re.search(s,c.program) and c.line not in excluded for c in cases)'
import json
import os
import subprocess
import sys
SELECT = r"^1 as \$x \| 2 as \$y|^1 as \$x \| \[\$x|^def f: \(1000,2000\); f$|^def a: 0; \. \| a$"
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 bindings-corpus ===
## User Acceptance
- None.
## Guardrails
- Preserve lexical scope, lazy evaluation, and generator ordering.
- Defer cases combining bindings with later capabilities to scoped integration.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-CollectionBuiltins.md ===
# FEATURE: Collection Builtins
| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Transform, compare, and organize jq arrays and objects. |
| Depends On | FEATURE-Conversion.md |
| Provides | jq collection builtins |
| Consumes | jq type and conversion builtins |
## Purpose
Provide the collection filters described by the manual and the definitions in `sources/builtin.jq`.
## Behavior
Implement `map`, `map_values`, `select`, type selectors, keys and membership operations, entries conversion, addition and containment, sorting, grouping, uniqueness, extrema, reverse, flatten, transpose, combinations, binary search, and related collection utilities exercised by the corpus.
`map` collects every result for every element. `map_values` uses the first update result and removes a value when the update is empty. Sorting and grouping use jq's total value ordering and evaluate filter keys as ordered streams. Containment recursively follows jq's array and object rules. Preserve argument Cartesian products, stable result order where specified, empty inputs, and jq errors and depth boundaries.
## Programmatic Acceptance
=== AC collection-builtins-conformance ===
Intent: Collection transformations, ordering, membership, and containment pass 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; s=r"^(?:sort|unique|flatten|flatten\(0\)|flatten\(2\)|transpose|to_entries|from_entries|map\(has\(2\)\)|map\(keys\)|map_values\(\.\+1\)|contains\(\"bar\"\))$"; cases=h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); excluded=h.apply_exclusions(cases,h.parse_exclusions(h.EXCLUSIONS)); assert any(re.search(s,c.program) and c.line not in excluded for c in cases)'
import json
import os
import subprocess
import sys
SELECT = r"^(?:sort|unique|flatten|flatten\(0\)|flatten\(2\)|transpose|to_entries|from_entries|map\(has\(2\)\)|map\(keys\)|map_values\(\.\+1\)|contains\(\"bar\"\))$"
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 collection-builtins-conformance ===
## User Acceptance
- None.
## Guardrails
- Do not mutate any file under `sources/`.
- Preserve jq value ordering and generator semantics rather than Python's default mixed-type ordering.
- Cross-feature cases requiring later builtins remain covered by scoped integration.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-Collections.md ===
# FEATURE: Collection Expressions
| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Construct, access, and iterate jq arrays and objects. |
| Depends On | FEATURE-GeneratorCore.md |
| Provides | jq collection expressions |
| Consumes | jq generator evaluation |
## Behavior
Array construction collects every output of its enclosed filter into one array, including an empty array when the filter yields nothing. Object construction evaluates key and value expressions against the original input and emits combinations in generator order. Support identifier, string, expression, and variable key forms and the documented shorthand forms as their prerequisites become available.
Field access, computed indexing, iteration, and slices compose with other filters. Missing object fields and out-of-range array indices produce null; negative indices count from the end. Iteration yields array elements or object values in order. Slices use inclusive start and exclusive end, accept omitted and negative bounds, and operate on arrays and strings. Invalid operand types raise jq runtime errors.
## Programmatic Acceptance
=== AC collections-corpus ===
Intent: Collection construction and access execute the selected corpus programs with the required output streams.
Suite: scoped
Requires: executable=python3; scope=test
Probe: python3 -c 'import re,sys; sys.path.insert(0,"sources"); import run_conformance as h; s=r"^\{a: 1\}$|^\.foo$|^\.\[\]$|^\[\.\]$|^\[\{\}\]$"; cases=h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); excluded=h.apply_exclusions(cases,h.parse_exclusions(h.EXCLUSIONS)); assert any(re.search(s,c.program) and c.line not in excluded for c in cases)'
import json
import os
import subprocess
import sys
SELECT = r"^\{a: 1\}$|^\.foo$|^\.\[\]$|^\[\.\]$|^\[\{\}\]$"
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 collections-corpus ===
## User Acceptance
- None.
## Guardrails
- Preserve ordered generator multiplicity and partial output on runtime errors.
- Use the supplied corpus unchanged; mixed cases requiring later capabilities belong to scoped integration.
=== END ARTIFACT ===
=== BEGIN ARTIFACT FEATURE-Command.md ===
# FEATURE: Command Interface
| Field | Value |
|-------|-------|
| Version | 20261028 V1 |
| Description | Run jq filters on standard input through the root executable. |
| Depends On | FEATURE-SqlBuiltins.md |
| Provides | ./jq -c |
| Consumes | jq SQL-style builtins and inventory |
## Purpose and behavior
Invoke the executable at the application root as `./jq -c '<program>'`. Compile the supplied jq program, read JSON values from standard input, and evaluate the program on each input using the shared generator and input stream. Emit each produced value as compact JSON on its own standard-output line, preserving order and multiplicity.
Exit 0 when compilation and execution complete, 3 for a compile or static error, and 5 for a runtime error. Retain values emitted before a runtime error. Send diagnostics to standard error. Only `-c` is required.
## Programmatic Acceptance
=== AC command-stream ===
Intent: The command returns each input unchanged in order as a compact JSON value.
Requires: executable=python3; scope=test
import json
import subprocess
import sys
values = [{"a": [1, 2]}, [3, 4]]
payload = "\n".join(json.dumps(value) for value in values) + "\n"
result = subprocess.run(["./jq", "-c", "."], input=payload, capture_output=True, text=True)
print(result.stdout)
print(result.stderr, file=sys.stderr)
assert result.returncode == 0
assert [json.loads(line) for line in result.stdout.splitlines()] == values
assert all(line == json.dumps(json.loads(line), separators=(",", ":")) for line in result.stdout.splitlines())
=== END AC command-stream ===
=== AC command-errors ===
Intent: Compilation and runtime failures have distinct exit statuses, and prior output survives a runtime failure.
Requires: executable=python3; scope=test
import json
import subprocess
import sys
invalid = subprocess.run(["./jq", "-c", "{"], input="null", capture_output=True, text=True)
print(invalid.stdout)
print(invalid.stderr, file=sys.stderr)
assert invalid.returncode == 3
value = 7
runtime = subprocess.run(
["./jq", "-c", "., error"], input=json.dumps(value), capture_output=True, text=True
)
print(runtime.stdout)
print(runtime.stderr, file=sys.stderr)
assert runtime.returncode == 5
assert [json.loads(line) for line in runtime.stdout.splitlines()] == [value]
=== END AC command-errors ===
=== AC command-corpus ===
Intent: Identity programs execute successfully through the command and supplied corpus runner.
Suite: scoped
Requires: executable=python3; scope=test
Probe: python3 -c 'import re,sys; sys.path.insert(0,"sources"); import run_conformance as h; s=r"^\.$"; cases=h.parse_corpus(h.CORPUS.read_text(encoding="utf-8")); excluded=h.apply_exclusions(cases,h.parse_exclusions(h.EXCLUSIONS)); assert any(re.search(s,c.program) and c.line not in excluded 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 command-corpus ===
## User Acceptance
- None.
## Guardrails
- Implement in Python with only standard-library runtime dependencies.
- Do not shell out to system jq or use a third-party jq implementation.
- Do not modify staged source assets.
=== END ARTIFACT ===Run artifact