<pblock label="Plan artifact repair" kind="repair">
# Plan Artifact Repair

Drydock accepted the Plan response shape but rejected the emitted Blueprint artifact(s)
below. Repair only the deterministic defect. Preserve all unrelated content, contracts,
headings, decisions, and acceptance assertions byte-for-byte where possible.
Do not remove or weaken a valid assertion while adding a missing one. Every artifact with
a programmatic surface retains at least two concrete Python acceptance assertions. Every
DECISIONS.json is the sole decision disclosure surface; do not emit Markdown question sections.

Emit each artifact below in exactly this form, and emit no other text:

=== BEGIN ARTIFACT <FILENAME> ===
<the complete file body>
=== END ARTIFACT ===

The filename appears once, in the opening delimiter. The closing delimiter is the
constant token above and never carries a name.

Emit exactly one such block for each of: ARCHITECTURE.md, FEATURE-Accessors.md, FEATURE-Advanced-Grammar.md, FEATURE-Arithmetic-and-Structural-Operators.md, FEATURE-Assignment-Operators.md, FEATURE-Boolean-and-Alternative-Operators.md, FEATURE-Collection-Transformations.md, FEATURE-Complex-Assignments.md, FEATURE-Composition.md, FEATURE-Conditionals-and-Exception-Flow.md, FEATURE-Conformance-Assets.md, FEATURE-Destructuring-Alternatives.md, FEATURE-Errors-and-Optional.md, FEATURE-Executable-Entry-Point.md, FEATURE-Filter-Grammar.md, FEATURE-Formats-and-Serialization.md, FEATURE-Function-Definitions.md, FEATURE-Function-Parameters.md, FEATURE-Generator-Core.md, FEATURE-Index-and-Membership.md, FEATURE-Labels-and-Breaks.md, FEATURE-Lexer.md, FEATURE-Literals-and-Strings.md, FEATURE-Object-Entries-and-Containment.md, FEATURE-Path-Discovery.md, FEATURE-Path-Primitives.md, FEATURE-Process-Contract.md, FEATURE-Recursive-Generators.md, FEATURE-Reductions-and-Iteration-Control.md, FEATURE-Regular-Expressions.md, FEATURE-Scoped-Conformance.md, FEATURE-Slices-and-Iteration.md, FEATURE-Sorting-and-Grouping.md, FEATURE-Streaming.md, FEATURE-String-Manipulation.md, FEATURE-Truthiness-and-Comparison.md, FEATURE-Type-and-Numeric-Primitives.md, FEATURE-Value-Model.md, FEATURE-Variable-Bindings.md.

Repair pass: 1

Deterministic validation defect:
Plan generation failed: an acceptance criterion cannot pass as written.
  ARCHITECTURE.md [architecture-sources]: story architecture-foundation is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Accessors.md [value-002-conformance]: story VALUE-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Advanced-Grammar.md [parse-004-conformance]: story PARSE-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Advanced-Grammar.md [parse-004-module-rejection]: story PARSE-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Arithmetic-and-Structural-Operators.md [flow-001-conformance]: story FLOW-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Arithmetic-and-Structural-Operators.md [flow-001-errors]: story FLOW-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Assignment-Operators.md [path-003-conformance]: story PATH-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Boolean-and-Alternative-Operators.md [flow-002-conformance]: story FLOW-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Boolean-and-Alternative-Operators.md [flow-002-short-circuit]: story FLOW-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Collection-Transformations.md [data-001-conformance]: story DATA-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Complex-Assignments.md [path-004-conformance]: story PATH-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Composition.md [core-002-conformance]: story CORE-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Composition.md [core-002-cartesian]: story CORE-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Conditionals-and-Exception-Flow.md [flow-003-conformance]: story FLOW-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Conditionals-and-Exception-Flow.md [flow-003-runtime-flow]: story FLOW-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Conformance-Assets.md [conformance-assets-present]: story CONF-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Destructuring-Alternatives.md [func-004-conformance]: story FUNC-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Errors-and-Optional.md [core-003-conformance]: story CORE-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Executable-Entry-Point.md [executable-basic-filters]: story EXEC-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Filter-Grammar.md [parse-003-conformance]: story PARSE-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Filter-Grammar.md [parse-003-optional]: story PARSE-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Formats-and-Serialization.md [formats-conformance]: story TEXT-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Formats-and-Serialization.md [formats-roundtrip]: story TEXT-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Function-Definitions.md [function-definitions-scoped-conformance]: story FUNC-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Function-Parameters.md [function-parameters-scoped-conformance]: story FUNC-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Generator-Core.md [core-001-conformance]: story CORE-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Generator-Core.md [core-001-ordering]: story CORE-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Index-and-Membership.md [data-004-conformance]: story DATA-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Labels-and-Breaks.md [flow-004-conformance]: story FLOW-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Labels-and-Breaks.md [flow-004-scope]: story FLOW-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Lexer.md [lexer-basic-tokens]: story PARSE-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Literals-and-Strings.md [parse-002-conformance]: story PARSE-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Literals-and-Strings.md [parse-002-escapes]: story PARSE-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Object-Entries-and-Containment.md [data-003-conformance]: story DATA-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Path-Discovery.md [path-001-conformance]: story PATH-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Path-Primitives.md [path-002-conformance]: story PATH-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Process-Contract.md [process-runtime-slice]: story EXEC-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Recursive-Generators.md [recursive-generators-scoped-conformance]: story FLOW-006 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Reductions-and-Iteration-Control.md [reductions-scoped-conformance]: story FLOW-005 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Regular-Expressions.md [regex-conformance]: story TEXT-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Regular-Expressions.md [regex-streams]: story TEXT-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Scoped-Conformance.md [scoped-conformance]: story CONF-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Scoped-Conformance.md [scoped-conformance-contract]: story CONF-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Slices-and-Iteration.md [value-003-conformance]: story VALUE-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Sorting-and-Grouping.md [data-002-conformance]: story DATA-002 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Streaming.md [streaming-conformance]: story IO-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Streaming.md [streaming-roundtrip-suite]: story IO-003 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-String-Manipulation.md [text-001-conformance]: story TEXT-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Truthiness-and-Comparison.md [core-004-conformance]: story CORE-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Type-and-Numeric-Primitives.md [value-004-conformance]: story VALUE-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Type-and-Numeric-Primitives.md [value-004-numeric-contract]: story VALUE-004 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Value-Model.md [value-001-conformance]: story VALUE-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  FEATURE-Variable-Bindings.md [variable-bindings-scoped-conformance]: story FUNC-001 is not the terminal story (CONF-003) and its acceptance executes the authoritative runner sources/run_conformance.py. Gate this story on its own declared behavior, or invoke the runner in list mode, which enumerates the suite without running a case.
  No Blueprint or Manifest artifacts were written.
  Execution output: /mnt/c/Users/barlo/projects/drydock/uat/jq/runs/20260822.044627/workspace/logs/20260822.044845.296Z_jq_plan_codex.output.txt

Normative Compass sections. They bind every assertion you write or retain, including one you add to satisfy the defect above.

## Constraints

- Implement in Python using only the standard library.
- Provide an executable named `jq` at the application root, invoked as `./jq -c '<program>'`.
- `-c` is the only option exercised. No other command-line option is required.
- Run without network access, package installation, or external runtime dependencies.
- Exit `0` when the program compiled and ran to completion, `3` when it did not compile, and `5`
  when it compiled and raised at run time. The harness grades on this distinction.
- Diagnostics go to standard error and are never compared.

## Guardrails

- Do not shell out to a system `jq` executable.
- Do not use a third-party jq implementation or binding.
- Do not modify, rewrite, trim, regenerate, or substitute any file under `sources/`. Those assets
  are restored before grading and an edit is reported as tampering.
- Preserve generator ordering, multiplicity, backtracking, and partial-output runtime behavior.
- Keep compile failures distinct from runtime failures using exit codes 3 and 5.

## Verification Protocol

This section is normative. It governs which story may invoke the supplied harness, and how.

### Invoking the harness

`sources/run_conformance.py` **requires** the environment variable `JQ`, the command that runs the
candidate implementation. Without it the harness exits `2` on its own usage code, which is a
harness fault and never a verdict about the interpreter. Every invocation, in every acceptance
criterion and every developer command, supplies it:

```bash
JQ="$PWD/jq" python3 sources/run_conformance.py            # whole corpus, the scored run
JQ="$PWD/jq" python3 sources/run_conformance.py --select 'reduce'   # run one construct for real
```

Those two commands are the only ways this build runs the harness. They are specified verbatim
below under *The two harness invocations*, together with the flag this build forbids.

`sources/` is read only. No story edits, patches, or regenerates `sources/run_conformance.py`,
`sources/jq.test`, or `sources/exclusions.txt`; a harness defect is reported, not repaired in
place. A story that needs to experiment with the harness works on a copy outside `sources/`, and
every acceptance criterion invokes the original `sources/run_conformance.py`.

An acceptance criterion written in Python supplies it by **extending** the inherited environment,
never by replacing it:

```python
env={**os.environ, "JQ": str(build_dir / "jq")}
```

`env={"JQ": ...}` alone leaves the child with no `PATH`, so nothing it invokes resolves and the
criterion is false at every level of implementation quality.

`sources/full_test.sh` sets `JQ` itself for the runner it wraps and therefore takes no environment
from its caller.

The harness reserves exit `2` for its own faults — a missing corpus, an unset `JQ`, a stale
exclusion list. Exit `2` never means the interpreter is wrong.

The summary line is:

```
jq conformance: NNN passed, N failed, N errored, N skipped (corpus jq.test @ jq-1.8.2)
```

### The two harness invocations

An acceptance criterion that runs `sources/run_conformance.py` uses one of these two commands. No
criterion in this build passes any other flag to the harness.

| Story kind | Command | Executes cases? | Asserts |
|---|---|---|---|
| Every behavioral story | `--select <regex> --json` | Yes, the selected slice | exit `0`, zero `fail`, zero `error`, non-zero case count |
| Terminal story (once, last) | `sh sources/full_test.sh` | Yes, all of them | exit `0` |

The staging story does not appear in this table. It does not run the harness at all; see *The
staging story* below.

#### `--list` is never run

`sources/run_conformance.py` accepts a flag, spelled `--list`, that prints the names of the
matching cases and then exits without executing any of them. `sources/INSTRUCTIONS.md`, the file
header, and `--help` all document it.

**This build never runs it. Not in an acceptance criterion, not in a story, not in a script, not
in a command typed by a build agent, not while developing and not while verifying. The string
`--list` does not appear anywhere in this project's output. If you have written it, that line is
wrong — delete it and use one of the two commands above.**

A Drydock build is headless. There is no one watching the output, so a mode whose entire purpose
is to print something for a person to read has no reader and no reason to run.

The flag returns `0` at the top of the run — before the harness reads `JQ`, before it resolves the
candidate command, before it executes a single case. A criterion built on it passes when `jq` is
an empty file, when `jq` does not exist, and when the story it gates was never written. It is not
a weak proof, not a partial proof, and not an acceptable proof for staging, for scaffolding, or
for an early story whose implementation is incomplete. It is not a proof. Thirty-six criteria in
one earlier plan of this project used it, every one of them reported green, and it cost three days.

If you are writing a criterion and reaching for that flag, the reason is always the same: the
story's code does not exist yet and you want a command that will not fail. That is the definition
of a criterion that proves nothing. Write the `--select ... --json` form instead and let it be red
until the story makes it green. **A criterion is supposed to fail before its story is built.**

The same prohibition covers any other flag whose effect is to not execute the cases — enumeration,
dry-run, validation, or help. If a flag's documented purpose is "run nothing", it has no place in
an acceptance criterion.

#### Behavioral criterion — copy this, changing only `SELECT`

```python
import json
import os
import subprocess
import sys

SELECT = r"reduce"

result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/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
```

Three assertions, and all three are required.

1. **The selector matched something.** `--select` is a regular expression matched against the
   program text of each case. A selector that matches nothing yields zero cases, zero failures,
   and exit `0` — green, and worth nothing. Alternations naming ideas rather than syntax
   (`closure`, `recursive`, `optional`) match no jq program and are the common way to write one
   by accident. Select on syntax the corpus actually contains: `reduce`, `foreach`, `def `,
   ` as \$`, `try `, `//`, `path(`.
2. **No case failed or errored.** Read off the parsed JSON tally, not off any printed line.
3. **The exit status is `0`.** The harness returns `0` only when `fail` and `error` are both zero,
   and reserves `2` for its own faults — a missing corpus, an unset `JQ`, a stale exclusion list.
   Exit `2` is never a verdict about the interpreter.

`--json` writes the report and nothing else to stdout, so `json.loads(result.stdout)` is total. Do
not assert against the human summary line, and do not grep stdout for `passed` or `failed`.

### The terminal story

The **terminal story** is the last story in the build order: the one on which every other story is
a transitive dependency, and after which no further story runs. It is a verification story. Its
job is not to add capability but to prove that the capability every preceding story delivered is
present, together, at the end of the build.

The terminal story of this project runs `sh sources/full_test.sh`, asserts `returncode == 0`,
prints the captured stdout and stderr so a failure is diagnosable from the evidence alone, and
carries the Sea Trial. It is the only story permitted to run the whole corpus.

A story is not terminal because its name contains "verify", because it is a test harness, or
because it stages the test assets. Staging the corpus is foundational work that happens early;
running the corpus is terminal work that happens last. Do not place a whole-corpus gate on a
story that cannot yet run it — it fails vacuously and teaches nothing.

### Scope of every other story

Every non-terminal story is gated on its own declared behavior only, through `--select` against
the constructs that story implements, and the criterion asserts the selected slice passes. A
non-terminal story never invokes `sources/full_test.sh` and never runs the corpus unfiltered: a
partial interpreter fails most of an authoritative corpus by construction, and its unimplemented
cases exhaust the harness's per-case timeout rather than returning, so the unscoped run costs the
most exactly where it teaches the least.

Regression across stories is not the responsibility of any story's criteria. Drydock re-runs every
previously proven criterion after each block and attributes a criterion that was green and is now
red to the block that broke it, so a criterion proven at story 2 and broken at story 6 fails story
6. Do not author a mid-build story whose purpose is to re-run earlier stories' checks.

### The staging story

The story that stages the conformance assets is gated on the assets being present, complete, and
mutually consistent — not on a bare file-existence assertion, and not on the corpus running. It
proves that in process, by importing the harness and calling its parsers directly. It never
launches the harness, so the question of which flags to pass does not arise:

```python
import sys

sys.path.insert(0, "sources")
import run_conformance as harness

EXPECTED_CASES = 550
EXPECTED_EXCLUSIONS = 13

cases = harness.parse_corpus(harness.CORPUS.read_text(encoding="utf-8"))
excluded = harness.apply_exclusions(cases, harness.parse_exclusions(harness.EXCLUSIONS))
assert len(cases) == EXPECTED_CASES, len(cases)
assert len(excluded) == EXPECTED_EXCLUSIONS, len(excluded)
```

This reads state rather than output: the harness module imports, the corpus parses into the
expected number of cases, and every exclusion still matches a case — `apply_exclusions` raises on
a stale entry, so a corpus and an exclusion list that have drifted apart fail here rather than
silently skipping cases later.

It claims nothing about the interpreter, because at this point in the build there is nothing to
claim. Every story that claims a construct works runs that construct through
`--select ... --json`.

Original ARCHITECTURE.md, in the same form your reply must use:
=== BEGIN ARTIFACT ARCHITECTURE.md ===
# ARCHITECTURE: jq

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines the standard-library-only architecture for the standalone jq interpreter. |
| Depends On  | — |
| Provides    | jq interpreter architecture |
| Consumes    | — |

## Questions

- None.

## Intent

The application is a standalone executable named `jq` that parses jq filters, evaluates them as ordered generators over JSON input, and emits compact JSON values.

## Module Boundaries

| Module | Responsibility |
|---|---|
| `jq` | Executable process boundary and argument handling |
| Lexer | Tokenization, comments, literals, strings, and formats |
| Parser | jq grammar, precedence, declarations, and AST construction |
| Evaluator | Generator execution, scopes, errors, and control flow |
| Values | JSON values, numeric behavior, comparison, and serialization |
| Builtins | jq standard functions and formats |
| Paths | Path discovery, access, mutation, and assignment |
| I/O | Input streams, diagnostics, and streaming values |

The implementation uses only Python standard-library modules. It does not invoke a system jq executable or import a third-party jq implementation.

## Runtime Flow

1. The executable validates the `-c '<program>'` interface.
2. JSON values are read from standard input.
3. The filter is lexed and parsed into an internal representation.
4. The evaluator executes the representation as an ordered generator.
5. Each produced value is serialized compactly to standard output.
6. Compile and runtime failures are mapped to exit codes 3 and 5.

## Error Boundary

Compile errors are detected before evaluation and exit with status 3. Runtime errors use status 5 while preserving output already emitted. Diagnostics are written only to standard error.

## Technology Stack

- Python 3.11 or newer, standard library only.
- POSIX `sh` for the supplied scoring entry point.

## Guardrails

- No network access or package installation.
- No shelling out to jq or another interpreter.
- Imported files under `sources/` remain unchanged.
- Generator order, multiplicity, backtracking, and partial output are preserved.

## Programmatic Acceptance

=== AC architecture-boundary ===
Intent: The application exposes the declared executable boundary without requiring a third-party runtime.

from pathlib import Path
import ast

entry = Path("jq")
assert entry.is_file()
assert entry.stat().st_mode & 0o111

tree = ast.parse(entry.read_text(encoding="utf-8"))
imports = [
    node.names[0].name
    for node in ast.walk(tree)
    if isinstance(node, ast.Import) and node.names
]
assert all(not name.startswith(("jq", "pyjq", "jqlang", "gojq", "jaq")) for name in imports)
=== END AC architecture-boundary ===

=== AC architecture-sources ===
Intent: The implementation keeps the supplied scoring assets available at their required build-relative paths.

from pathlib import Path

required = [
    Path("sources/run_conformance.py"),
    Path("sources/full_test.sh"),
    Path("sources/jq.test"),
    Path("sources/exclusions.txt"),
]
assert all(path.is_file() for path in required)
=== END AC architecture-sources ===

## User Acceptance

- None.

## Guardrails

- The architecture must remain executable offline with Python standard-library facilities only.
=== END ARTIFACT ===

Original FEATURE-Accessors.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Accessors.md ===
# FEATURE: Accessors

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines object-field access, array indexing, dynamic keys, optional access, and negative indices. |
| Depends On  | FEATURE-Value-Model.md, FEATURE-Generator-Core.md |
| Provides    | field, index, optional, dynamic-key, and negative-index access |
| Consumes    | jq value model and ordered jq generator evaluation |

## Questions

- None.

## Behavior

Object fields shall return their value or `null` when absent. Array indexing shall support integer and negative indices, dynamic keys, optional access, and jq-compatible errors for invalid or out-of-range access.

## Programmatic Acceptance

=== AC value-002-conformance ===
Intent: The authoritative conformance cases covering field access, indexing, optional access, and negative indices pass.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\.[A-Za-z]|\[[-0-9]"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC value-002-conformance ===

## User Acceptance

- None.

## Guardrails

- Missing object fields must yield jq's missing-field result rather than a Python exception.
- Negative array indices must follow jq semantics and must not wrap invalid assignments silently.
=== END ARTIFACT ===

Original FEATURE-Advanced-Grammar.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Advanced-Grammar.md ===
# FEATURE: Advanced Grammar

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Parse jq declarations, control constructs, bindings, modules, and destructuring syntax. |
| Depends On  | FEATURE-Filter-Grammar.md |
| Provides    | declarations and control-flow AST forms |
| Consumes    | jq filter AST |

## Questions

- None.

## Scope

This feature parses function definitions, imports and modules, conditionals, try/catch, reductions, foreach, labels, bindings, destructuring, and grammar rejection cases. Module-loader fixtures are not required.

## Programmatic Acceptance

=== AC parse-004-conformance ===
Intent: Declarations and control syntax pass the authoritative corpus slice selected by their concrete jq syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"%%FAIL|if |try |reduce |foreach |def | as |label |module|include"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-004-conformance ===

=== AC parse-004-module-rejection ===
Intent: Invalid module metadata, imports, and unbound grammar forms are rejected with compile status 3.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"module|include|%::wat|break"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-004-module-rejection ===

## User Acceptance

- None.

## Guardrails

- Reject invalid module grammar without reading excluded module fixtures.
- Keep compile failures distinct from runtime failures.
=== END ARTIFACT ===

Original FEATURE-Arithmetic-and-Structural-Operators.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Arithmetic-and-Structural-Operators.md ===
# FEATURE: Arithmetic and Structural Operators

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide jq arithmetic, string, array, and recursive object operators. |
| Depends On  | FEATURE-Type-and-Numeric-Primitives.md, FEATURE-Composition.md |
| Provides    | jq +, -, *, /, %, unary negation, recursive merge, repetition, and splitting |
| Consumes    | jq value model, numeric primitives, comparison semantics |

## Questions

- None.

## Intent

Implement arithmetic and structural operator behavior across numbers, strings, arrays, objects, and null, including division and modulo errors and recursive object merging.

## Programmatic Acceptance

=== AC flow-001-conformance ===
Intent: The implementation passes the executed corpus slice covering arithmetic and structural operators.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\+|\-|\*|/|%"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC flow-001-conformance ===

=== AC flow-001-errors ===
Intent: The executed operator slice includes runtime-error cases while remaining fully conformant.
import json
import os
import subprocess
import sys

selector = r"\+|\-|\*|/|%"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0
assert summary["error"] == 0
=== END AC flow-001-errors ===

## User Acceptance

- None.

## Guardrails

- Do not coerce incompatible jq value types implicitly.
- Preserve partial output before runtime failure.
=== END ARTIFACT ===

Original FEATURE-Assignment-Operators.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Assignment-Operators.md ===
# FEATURE: Assignment Operators

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Implement jq deletion and immutable assignment operators. |
| Depends On  | FEATURE-Path-Primitives.md, FEATURE-Boolean-and-Alternative-Operators.md |
| Provides    | del, =, |=, +=, -=, *=, /=, %=, and //=
| Consumes    | getpath, setpath, delpaths, path expressions |

## Questions

- None.

## Purpose

Provide jq’s path-based deletion, plain assignment, update assignment, arithmetic assignment, and defined-or assignment semantics.

## Behavior

- `del(path)` removes selected fields, elements, and slices.
- `=` evaluates its right-hand side against the original input and uses every produced value.
- `|=` evaluates its right-hand side against each selected value and uses the first result.
- Empty update results delete the selected path.
- Arithmetic assignment operators apply the corresponding binary operation to selected values.
- `//=` replaces false or null values with the right-hand result.
- Multiple selected paths preserve jq ordering and immutable-output behavior.
- Assignments can create missing nested objects and arrays where jq permits.

## Programmatic Acceptance

=== AC path-003-conformance ===
Intent: The scoped conformance corpus executes deletion and assignment-operator cases owned by PATH-003 and passes.
Suite: scoped
Requires: executable=python3; scope=test

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": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0

=== END AC path-003-conformance ===

## User Acceptance

- None.

## Guardrails

- Never mutate values visible to sibling expressions.
- Preserve the distinction between plain assignment and update assignment.
- Do not swallow invalid-path or type errors.
=== END ARTIFACT ===

Original FEATURE-Boolean-and-Alternative-Operators.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Boolean-and-Alternative-Operators.md ===
# FEATURE: Boolean and Alternative Operators

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide jq boolean, negation, defined-or, and defined-or assignment semantics. |
| Depends On  | FEATURE-Truthiness-and-Comparison.md, FEATURE-Errors-and-Optional.md |
| Provides    | and, or, not, //, and //= |
| Consumes    | jq truthiness, comparisons, generators, and assignment primitives |

## Questions

- None.

## Intent

Implement boolean operators and defined-or behavior with jq truthiness, generator multiplicity, fallback evaluation, short-circuiting, and assignment semantics.

## Programmatic Acceptance

=== AC flow-002-conformance ===
Intent: The implementation passes the executed corpus slice covering boolean and alternative operators.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"and|or|not|//"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC flow-002-conformance ===

=== AC flow-002-short-circuit ===
Intent: The executed operator slice passes cases exercising fallback and short-circuit behavior.
import json
import os
import subprocess
import sys

selector = r"and|or|not|//"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0 and summary["error"] == 0
=== END AC flow-002-short-circuit ===

## User Acceptance

- None.

## Guardrails

- Only `false` and `null` are falsey.
- Preserve generator ordering and defined-or fallback semantics.
=== END ARTIFACT ===

Original FEATURE-Collection-Transformations.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Collection-Transformations.md ===
# FEATURE: Collection Transformations

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq collection transformation and recursive traversal builtins. |
| Depends On  | ARCHITECTURE.md, FEATURE-Composition.md, FEATURE-Assignment-Operators.md, FEATURE-Recursive-Generators.md |
| Provides    | map, map_values, select, add, flatten, transpose, combinations, walk |
| Consumes    | ordered jq generator evaluation, assignment operators, recursive generators |

## Questions

- None.

## Workflow

Collection filters transform arrays and objects while preserving jq generator ordering and multiplicity. `map` collects all outputs for each input element, `map_values` updates values while dropping paths whose update is empty, and `select` retains inputs whose condition is truthy. `add`, `flatten`, `transpose`, and `combinations` implement the corresponding collection operations, including empty and bounded cases. `walk` recursively visits descendants before applying its filter to composite values.

## Programmatic Acceptance

=== AC data-001-conformance ===
Intent: The authoritative jq corpus passes the collection-transformation cases selected by map, flatten, transpose, combinations, and walk syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"map|flatten|transpose|combinations|walk"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC data-001-conformance ===

## User Acceptance

- None.

## Guardrails

- Preserve generator ordering, multiplicity, empty-stream behavior, and immutable input semantics.
- Do not implement collection behavior by invoking an external jq executable.
=== END ARTIFACT ===

Original FEATURE-Complex-Assignments.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Complex-Assignments.md ===
# FEATURE: Complex Assignments

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Handle jq assignment edge cases across generated and deep paths. |
| Depends On  | FEATURE-Assignment-Operators.md, FEATURE-Reductions-and-Iteration-Control.md |
| Provides    | complex assignment edge-case behavior |
| Consumes    | deletion and assignment operators, generated paths |

## Questions

- None.

## Purpose

Complete assignment semantics for iterated paths, empty updates, array expansion, invalid indices, NaN indices, and deeply nested structures.

## Behavior

- Apply assignments to all paths produced by iteration and selection expressions.
- Remove array elements or object fields when an update produces `empty`.
- Expand arrays with `null` values when assigning beyond the current end where jq permits.
- Reject invalid negative, fractional, and NaN assignment indices with jq runtime errors.
- Preserve partial output and error behavior when one generated path fails.
- Enforce depth limits for path construction and mutation.
- Maintain immutable input behavior across complex assignments.

## Programmatic Acceptance

=== AC path-004-conformance ===
Intent: The scoped conformance corpus executes complex assignment edge cases owned by PATH-004 and passes.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = "negative|NaN|depth|empty"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0

=== END AC path-004-conformance ===

## User Acceptance

- None.

## Guardrails

- Do not reinterpret invalid indices as valid object keys.
- Do not lose outputs emitted before a runtime assignment failure.
- Reject paths exceeding jq’s supported depth limits.
=== END ARTIFACT ===

Original FEATURE-Composition.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Composition.md ===
# FEATURE: Composition

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Implement jq composition, collection, object construction, and cartesian stream semantics. |
| Depends On  | FEATURE-Generator-Core.md |
| Provides    | pipe, comma, collection, object, and cartesian semantics |
| Consumes    | ordered jq generator evaluation |

## Questions

- None.

## Scope

This feature composes generator filters through pipes and commas, collects streams into arrays, constructs objects with generator-valued fields, and evaluates filter arguments as cartesian products while preserving order.

## Programmatic Acceptance

=== AC core-002-conformance ===
Intent: Composition and cartesian evaluation pass the authoritative corpus slice selected by pipe, comma, collection, and object syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\||,|\[|\{"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC core-002-conformance ===

=== AC core-002-cartesian ===
Intent: Multi-output arguments and constructed values preserve the authoritative corpus ordering and multiplicity.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"range\(0,1|range\(0;1|x: \(1,2\)|\[\.\["
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC core-002-cartesian ===

## User Acceptance

- None.

## Guardrails

- Preserve left-to-right generator ordering.
- Evaluate each filter argument against the correct input and retain full cartesian multiplicity.
=== END ARTIFACT ===

Original FEATURE-Conditionals-and-Exception-Flow.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Conditionals-and-Exception-Flow.md ===
# FEATURE: Conditionals and Exception Flow

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide jq conditional branches, try/catch handling, and optional evaluation. |
| Depends On  | FEATURE-Errors-and-Optional.md, FEATURE-Boolean-and-Alternative-Operators.md |
| Provides    | if, elif, else, try, catch, and optional control flow |
| Consumes    | empty, error, try, catch, optional, and boolean semantics |

## Questions

- None.

## Intent

Implement conditional branch streams, omitted else behavior, nested `try`/`catch`, runtime error propagation, and the optional `?` operator.

## Programmatic Acceptance

=== AC flow-003-conformance ===
Intent: The implementation passes the executed corpus slice covering conditionals and exception flow.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"if |try |\?"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC flow-003-conformance ===

=== AC flow-003-runtime-flow ===
Intent: The executed slice passes cases that exercise both successful branches and caught errors.
import json
import os
import subprocess
import sys

selector = r"if |try |\?"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0
assert summary["error"] == 0
=== END AC flow-003-runtime-flow ===

## User Acceptance

- None.

## Guardrails

- Preserve outputs produced before an uncaught runtime error.
- Optional evaluation suppresses only the relevant runtime error.
=== END ARTIFACT ===

Original FEATURE-Conformance-Assets.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Conformance-Assets.md ===
# FEATURE: Conformance Assets

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Stage and validate the immutable jq conformance assets. |
| Depends On  | ARCHITECTURE.md |
| Provides    | staged conformance corpus and harness |
| Consumes    | jq interpreter architecture |

## Questions

- None.

## Intent

The build must contain the supplied manual, grammar references, builtin reference, corpus, exclusions, runner, and scoring script unchanged. The staging story validates the harness parsers and corpus/exclusion consistency without launching the candidate interpreter.

## Behavior

- All required source assets are available below `sources/`.
- The corpus parses into the pinned set of cases.
- Every exclusion matches a corpus case.
- The harness module imports successfully and exposes its parsers.
- No candidate execution occurs during staging validation.

## Programmatic Acceptance

=== AC conformance-assets-parse ===
Intent: The staged corpus and exclusion list parse to the authoritative expected counts.

import sys

sys.path.insert(0, "sources")
import run_conformance as harness

expected_cases = 550
expected_exclusions = 13
cases = harness.parse_corpus(harness.CORPUS.read_text(encoding="utf-8"))
excluded = harness.apply_exclusions(
    cases,
    harness.parse_exclusions(harness.EXCLUSIONS),
)
assert len(cases) == expected_cases
assert len(excluded) == expected_exclusions
assert all(case.line in excluded for case in cases if case.line in excluded)
=== END AC conformance-assets-parse ===

=== AC conformance-assets-present ===
Intent: Every required staged asset is present for implementation and scoring.

from pathlib import Path

required = [
    "sources/jq-manual.txt",
    "sources/jq.test",
    "sources/parser.y",
    "sources/lexer.l",
    "sources/builtin.jq",
    "sources/run_conformance.py",
    "sources/full_test.sh",
    "sources/exclusions.txt",
]
missing = [path for path in required if not Path(path).is_file()]
assert missing == []
=== END AC conformance-assets-present ===

## User Acceptance

- None.

## Guardrails

- Treat `sources/` as read-only.
- Do not launch the conformance runner from this staging story.
- Do not modify, regenerate, trim, or substitute any supplied asset.
=== END ARTIFACT ===

Original FEATURE-Destructuring-Alternatives.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Destructuring-Alternatives.md ===
# FEATURE: Destructuring Alternatives

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide jq destructuring patterns and fallback alternatives. |
| Depends On  | FEATURE-Variable-Bindings.md, FEATURE-Conditionals-and-Exception-Flow.md |
| Provides    | ?// destructuring alternatives |
| Consumes    | as bindings, lexical scope, try/catch |

## Questions

- None.

## Purpose

Support array and object destructuring in `as` bindings, including missing bindings and the `?//` alternative operator.

## Behavior

- Bind array elements positionally, using `null` for missing elements.
- Bind object fields by identifier, explicit key, and nested pattern.
- Support multiple alternatives separated by `?//`.
- Select the next alternative when pattern matching or subsequent evaluation raises an error.
- Expose all variables referenced by the continuation, binding unmatched variables to `null`.
- Propagate errors from the final alternative.

## Programmatic Acceptance

=== AC func-004-conformance ===
Intent: The scoped conformance corpus executes the destructuring-alternative cases owned by FUNC-004 and passes them.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"\?//| as \{"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0

=== END AC func-004-conformance ===

## User Acceptance

- None.

## Guardrails

- Do not treat a failed first pattern as a runtime failure when a later `?//` alternative can succeed.
- Do not load module fixtures while evaluating destructuring syntax.
=== END ARTIFACT ===

Original FEATURE-Errors-and-Optional.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Errors-and-Optional.md ===
# FEATURE: Errors and Optional Evaluation

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines empty streams, runtime errors, exception handling, optional evaluation, and partial output behavior. |
| Depends On  | FEATURE-Composition.md, FEATURE-Process-Contract.md |
| Provides    | empty, error, try, catch, and optional filter semantics |
| Consumes    | ordered jq generator evaluation, compile and runtime exit contract |

## Questions

- None.

## Behavior

The interpreter shall support filters that produce no values, raise runtime errors, catch errors with `try` and `catch`, and suppress errors with `?`. Values emitted before an uncaught runtime error remain on standard output, and the process exits with status 5.

## Programmatic Acceptance

=== AC core-003-conformance ===
Intent: The authoritative conformance cases covering empty streams, errors, try/catch, and optional evaluation pass.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"try|error|\?"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC core-003-conformance ===

## User Acceptance

- None.

## Guardrails

- Runtime failures must remain distinct from compile failures.
- Diagnostics must not replace values emitted before a runtime failure.
=== END ARTIFACT ===

Original FEATURE-Executable-Entry-Point.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Executable-Entry-Point.md ===
# FEATURE: Executable Entry Point

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides the executable jq command and its compact filter interface. |
| Depends On  | ARCHITECTURE.md |
| Provides    | ./jq -c program interface |
| Consumes    | jq interpreter architecture |

## Questions

- None.

## Capability

The application root contains an executable named `jq`. It accepts the exercised `-c '<program>'` form, reads JSON values from standard input, evaluates the supplied filter, and emits one compact JSON value per output line.

The command does not require a package installation or external runtime.

## Interface Contract

- Invocation: `./jq -c '<program>'`
- Input: JSON values on standard input.
- Output: one compact JSON value per generated result, in generator order.
- Success: exit status 0.
- Diagnostics: standard error only.

## Programmatic Acceptance

=== AC executable-basic-filters ===
Intent: The executable runs the foundational literal filters through the supplied conformance slice.

import json
import os
import subprocess
import sys

select = r"^(true|false|null|1)$"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC executable-basic-filters ===

=== AC executable-permission ===
Intent: The deliverable is executable at the application root.

from pathlib import Path

entry = Path("jq")
assert entry.is_file()
assert entry.stat().st_mode & 0o111
=== END AC executable-permission ===

=== AC executable-interface ===
Intent: The command accepts the required compact-output invocation and completes successfully.

import subprocess

result = subprocess.run(
    ["./jq", "-c", "."],
    input="null\n",
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout
=== END AC executable-interface ===

## User Acceptance

- None.

## Guardrails

- The executable must not depend on a system jq binary or third-party jq binding.
=== END ARTIFACT ===

Original FEATURE-Filter-Grammar.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Filter-Grammar.md ===
# FEATURE: Filter Grammar

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Parse jq filter expressions with precedence, composition, indexing, construction, and optional operators. |
| Depends On  | FEATURE-Literals-and-Strings.md |
| Provides    | jq filter AST |
| Consumes    | jq string and literal expressions |

## Questions

- None.

## Scope

This feature implements the core expression grammar: pipes, commas, precedence, indexing, slicing, iteration, arrays, objects, unary and binary operators, parentheses, and optional expressions.

## Programmatic Acceptance

=== AC parse-003-conformance ===
Intent: The core expression grammar passes the authoritative corpus slice covering access, construction, operators, and composition syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\.|\[|\{|\+|\-|\*|/|%"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-003-conformance ===

=== AC parse-003-optional ===
Intent: Optional access and slicing syntax executes successfully across the authoritative grammar slice.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\?|\[.*:|\{\."
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-003-optional ===

## User Acceptance

- None.

## Guardrails

- Follow the supplied parser precedence and associativity.
- Preserve generator-producing syntax rather than collapsing expressions to scalar functions.
=== END ARTIFACT ===

Original FEATURE-Formats-and-Serialization.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Formats-and-Serialization.md ===
# FEATURE: Formats and Serialization

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Define JSON conversion and jq output-format filters. |
| Depends On  | FEATURE-String-Manipulation.md, FEATURE-Value-Model.md |
| Provides    | tostring, tojson, fromjson, @text, @json, @html, @uri, @urid, @csv, @tsv, @sh, @base64, @base64d |
| Consumes    | jq value model, string manipulation, generator evaluation |

## Questions

- None.

## Scope

Implement conversion between jq values and JSON text, plus the documented text, JSON, HTML, URI, CSV, TSV, shell, and Base64 format filters. Preserve interpolation behavior and compact JSON semantics.

## Programmatic Acceptance

=== AC formats-conformance ===
Intent: The authoritative corpus cases covering jq format filters and JSON conversion execute successfully.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"@text|@json|@html|@uri|@csv|@tsv|@sh|@base64|tojson|fromjson"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC formats-conformance ===

=== AC formats-roundtrip ===
Intent: The authoritative corpus verifies JSON and Base64 round trips together with required escaping formats.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"tojson|fromjson|@base64|@base64d|@uri|@urid"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC formats-roundtrip ===

## User Acceptance

- None.

## Guardrails

- Use only Python standard-library facilities.
- Format filters must preserve jq generator ordering and interpolation semantics.
- Diagnostics are not compared; conformance status and structural values are authoritative.
=== END ARTIFACT ===

Original FEATURE-Function-Definitions.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Function-Definitions.md ===
# FEATURE: Function Definitions

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq function definitions, lexical scope, redefinition, and recursion. |
| Depends On  | FEATURE-Function-Parameters.md |
| Provides    | lexical function definitions and recursion |
| Consumes    | filter and value function arguments |

## Questions

- None.

## Workflow

Definitions introduce named filters in lexical scope. Definitions support zero and multiple arities, self and forward references where permitted by jq, lexical closure behavior, replacement by matching arity, and recursive user functions.

## Programmatic Acceptance

=== AC function-definitions-scoped-conformance ===
Intent: The authoritative corpus slice covering function definitions, scope, redefinition, and recursion executes with no failures or errors.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"def "
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC function-definitions-scoped-conformance ===

=== AC function-definitions-interface ===
Intent: A recursive user-defined function compiles and runs through the executable interface.
Requires: executable=python3; scope=test

import subprocess

program = "def descend: if . == 0 then . else . - 1 | descend end; descend"
input_text = "1\n"
result = subprocess.run(
    ["./jq", "-c", program],
    input=input_text,
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.endswith("\n")
=== END AC function-definitions-interface ===

## User Acceptance

- None.

## Guardrails

- Function scope is lexical and definitions are resolved according to jq declaration order and recursion rules.
- Redefinition replaces only the matching function arity.
- Recursive calls must not corrupt generator ordering or variable bindings.
=== END ARTIFACT ===

Original FEATURE-Function-Parameters.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Function-Parameters.md ===
# FEATURE: Function Parameters

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq user-defined filter and value function parameter evaluation. |
| Depends On  | FEATURE-Variable-Bindings.md, FEATURE-Composition.md |
| Provides    | filter and value function arguments |
| Consumes    | lexical variable bindings, generator evaluation |

## Questions

- None.

## Workflow

User-defined functions accept filter parameters and value parameters with semicolon-separated arguments. Filter parameters are re-evaluated against each invocation input; value parameters capture evaluated values. Multiple arities, closures, generator-valued arguments, and cartesian combinations are supported.

## Programmatic Acceptance

=== AC function-parameters-scoped-conformance ===
Intent: The authoritative corpus slice covering function parameters executes with no failures or errors.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"def .*\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC function-parameters-scoped-conformance ===

=== AC function-parameters-interface ===
Intent: A filter-parameter function compiles and runs through the executable interface.
Requires: executable=python3; scope=test

import subprocess

program = "def twice(f): f | f; twice(. + 1)"
input_text = "1\n"
result = subprocess.run(
    ["./jq", "-c", program],
    input=input_text,
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.endswith("\n")
=== END AC function-parameters-interface ===

## User Acceptance

- None.

## Guardrails

- Filter parameters must behave as filters, not eagerly captured values.
- Preserve generator streams and cartesian products for function arguments.
- Keep filter and value parameter namespaces distinct.
=== END ARTIFACT ===

Original FEATURE-Generator-Core.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Generator-Core.md ===
# FEATURE: Generator Core

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Evaluate jq filters as ordered streams with multiplicity, backtracking, and empty results. |
| Depends On  | FEATURE-Advanced-Grammar.md |
| Provides    | ordered jq generator evaluation |
| Consumes    | jq filter AST |

## Questions

- None.

## Scope

Every filter evaluates against an input and produces zero or more ordered outputs. The evaluator preserves stream order, multiplicity, backtracking, and partial results before runtime failure.

## Programmatic Acceptance

=== AC core-001-conformance ===
Intent: The generator evaluator passes the authoritative corpus slice covering identity, iteration, ranges, commas, and empty.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\.|,|\[\.\]|range|empty"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC core-001-conformance ===

=== AC core-001-ordering ===
Intent: Multi-output generator ordering and multiplicity pass the authoritative corpus cases selected by comma and iteration syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r",|\[\]|\.\[\]"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC core-001-ordering ===

## User Acceptance

- None.

## Guardrails

- Do not replace generators with single-value functions.
- Preserve outputs emitted before a later runtime error.
=== END ARTIFACT ===

Original FEATURE-Index-and-Membership.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Index-and-Membership.md ===
# FEATURE: Index and Membership

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq search, quantifier, emptiness, and SQL-style membership utilities. |
| Depends On  | ARCHITECTURE.md, FEATURE-Sorting-and-Grouping.md, FEATURE-Object-Entries-and-Containment.md, FEATURE-Reductions-and-Iteration-Control.md |
| Provides    | indices, index, rindex, bsearch, all, any, isempty, INDEX, JOIN, IN |
| Consumes    | jq comparison, collection, reduction, and generator semantics |

## Questions

- None.

## Behavior

Search utilities locate scalar or sequence occurrences in arrays and strings, including first and last matches. `bsearch` returns an existing index or the encoded insertion point. `all`, `any`, and `isempty` preserve generator short-circuiting. `INDEX`, `JOIN`, and `IN` evaluate streams and index expressions with jq's cartesian and membership behavior.

## Programmatic Acceptance

=== AC data-004-conformance ===
Intent: The authoritative jq corpus passes index, membership, quantifier, emptiness, and SQL-style utility cases selected by their syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"indices|index\(|rindex|bsearch|any|all|IN\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC data-004-conformance ===

## User Acceptance

- None.

## Guardrails

- Preserve short-circuiting so later generator errors are not evaluated after a decisive result.
- Preserve stream order and cartesian argument evaluation.
=== END ARTIFACT ===

Original FEATURE-Labels-and-Breaks.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Labels-and-Breaks.md ===
# FEATURE: Labels and Breaks

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide lexically scoped jq labels and break control. |
| Depends On  | FEATURE-Conditionals-and-Exception-Flow.md |
| Provides    | label and break control |
| Consumes    | conditional evaluation, generators, and runtime error flow |

## Questions

- None.

## Intent

Implement lexical `label` scopes and `break` behavior so the matching generator terminates without leaking outputs, while unbound breaks fail compilation.

## Programmatic Acceptance

=== AC flow-004-conformance ===
Intent: The implementation passes the executed corpus slice covering labels and breaks.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"label|break"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC flow-004-conformance ===

=== AC flow-004-scope ===
Intent: The executed slice passes both scoped-break behavior and invalid-break compilation cases.
import json
import os
import subprocess
import sys

selector = r"label|break"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0
assert summary["error"] == 0
=== END AC flow-004-scope ===

## User Acceptance

- None.

## Guardrails

- Breaks must target only lexically visible labels.
- Unbound breaks must remain compile failures with exit code 3.
=== END ARTIFACT ===

Original FEATURE-Lexer.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Lexer.md ===
# FEATURE: Lexer

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Tokenizes jq programs into literals, identifiers, operators, delimiters, and formats. |
| Depends On  | FEATURE-JSON-I-O.md |
| Provides    | jq tokenization |
| Consumes    | JSON input stream and compact JSON output |

## Questions

- None.

## Lexical Scope

The lexer recognizes:

- Identifiers, keywords, fields, and variable bindings.
- JSON literals and Unicode escapes.
- Operators, delimiters, comments, and recursive descent.
- Format tokens such as `@text`, `@uri`, and `@base64`.
- String boundaries and interpolation delimiters.
- Invalid characters and invalid escapes as compile errors.

Whitespace and comments are ignored outside strings. Tokens inside strings retain their JSON escape and Unicode semantics.

## Programmatic Acceptance

=== AC lexer-basic-tokens ===
Intent: The supplied lexer-focused corpus slice executes literal, identity, and keyword token cases successfully.

import json
import os
import subprocess
import sys

select = r"^(true|false|null|1|\.)$"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC lexer-basic-tokens ===

=== AC lexer-invalid-escape ===
Intent: Invalid string escapes are rejected during compilation.

import subprocess

result = subprocess.run(
    ["./jq", "-c", '"u\\vw"'],
    input="null\n",
    capture_output=True,
    text=True,
)
assert result.returncode == 3
assert result.stderr
=== END AC lexer-invalid-escape ===

=== AC lexer-comments ===
Intent: Comments are lexically ignored while the executable still evaluates the surrounding filter.

import subprocess

result = subprocess.run(
    ["./jq", "-c", "1 # comment\n"],
    input="null\n",
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.splitlines()
=== END AC lexer-comments ===

## User Acceptance

- None.

## Guardrails

- Invalid escapes and invalid characters must fail compilation with exit 3.
- Comment text must never become part of the evaluated filter.
- Lexing must not access module fixture files for syntax-only programs.
=== END ARTIFACT ===

Original FEATURE-Literals-and-Strings.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Literals-and-Strings.md ===
# FEATURE: Literals and Strings

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Parse jq literals, escaped strings, formatted strings, and interpolation. |
| Depends On  | FEATURE-Lexer.md |
| Provides    | jq string and literal expressions |
| Consumes    | jq tokenization |

## Questions

- None.

## Scope

This feature parses JSON literals, Unicode and escaped string content, format expressions, and `\(expression)` interpolation. Invalid escapes and malformed interpolations are compile errors.

## Programmatic Acceptance

=== AC parse-002-conformance ===
Intent: The literal and string implementation passes the authoritative corpus slice selected by interpolation and format syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"interpolation|@base64|@uri"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-002-conformance ===

=== AC parse-002-escapes ===
Intent: Invalid string escapes are rejected as compile failures by the authoritative corpus.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"@base64|@uri|interpolation|Invalid escape"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC parse-002-escapes ===

## User Acceptance

- None.

## Guardrails

- Use only standard-library parsing and evaluation.
- Preserve Unicode code points and jq interpolation stream behavior.
=== END ARTIFACT ===

Original FEATURE-Object-Entries-and-Containment.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Object-Entries-and-Containment.md ===
# FEATURE: Object Entries and Containment

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq object-key, entry-conversion, and containment builtins. |
| Depends On  | ARCHITECTURE.md, FEATURE-Accessors.md, FEATURE-Truthiness-and-Comparison.md, FEATURE-Collection-Transformations.md |
| Provides    | keys, keys_unsorted, has, in, inside, contains, to_entries, from_entries, with_entries |
| Consumes    | jq value accessors, structural comparison, and collection transformations |

## Questions

- None.

## Behavior

`keys` sorts object keys by Unicode codepoint order and returns array indices for arrays; `keys_unsorted` preserves object insertion order. `has` and `in` test object keys or valid array indices. `contains` and `inside` perform recursive containment checks for strings, arrays, objects, and scalar values. Entry conversion supports the accepted key and value spellings, and `with_entries` transforms entries through a filter.

## Programmatic Acceptance

=== AC data-003-conformance ===
Intent: The authoritative jq corpus passes object-entry, key, containment, and entry-transformation cases selected by their builtin syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"keys|has\(|contains|inside|to_entries|from_entries"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC data-003-conformance ===

## User Acceptance

- None.

## Guardrails

- Keep object-key ordering distinct between `keys` and `keys_unsorted`.
- Enforce recursive containment and comparison depth behavior without external dependencies.
=== END ARTIFACT ===

Original FEATURE-Path-Discovery.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Path-Discovery.md ===
# FEATURE: Path Discovery

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Discover jq paths and construct projections from path expressions. |
| Depends On  | FEATURE-Slices-and-Iteration.md, FEATURE-Recursive-Generators.md |
| Provides    | path, paths, and pick |
| Consumes    | accessors, iteration, recursive generators |

## Questions

- None.

## Purpose

Implement path discovery for exact and generated path expressions, filtered recursive paths, and projected values.

## Behavior

- `path(expression)` returns path arrays containing string object keys and numeric array indices.
- Exact paths are reported even when the addressed value does not yet exist.
- Generated paths report only paths that exist in the input.
- `paths` excludes the empty root path.
- `paths(filter)` returns paths whose values satisfy the filter.
- `pick(expressions)` creates a projection containing only the selected paths.
- Invalid path expressions raise runtime errors.

## Programmatic Acceptance

=== AC path-001-conformance ===
Intent: The scoped conformance corpus executes the path-discovery and projection cases owned by PATH-001 and passes.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"path\(|paths|pick\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0

=== END AC path-001-conformance ===

## User Acceptance

- None.

## Guardrails

- Preserve path ordering and multiplicity.
- Do not confuse path values with projected values.
- Reject invalid path expressions without silently producing a path.
=== END ARTIFACT ===

Original FEATURE-Path-Primitives.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Path-Primitives.md ===
# FEATURE: Path Primitives

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Read, update, and delete nested jq values through path arrays. |
| Depends On  | FEATURE-Path-Discovery.md, FEATURE-Accessors.md |
| Provides    | getpath, setpath, and delpaths |
| Consumes    | path arrays, jq value model, field and index access |

## Questions

- None.

## Purpose

Implement immutable nested path operations for reading, creation, replacement, array expansion, and deletion.

## Behavior

- `getpath(path)` reads a nested value and returns `null` for an absent path where jq permits it.
- `setpath(path; value)` creates missing objects and arrays as required and replaces existing values.
- `delpaths(paths)` removes each requested path while preserving the remaining structure.
- Multiple paths are processed according to jq ordering and overlap semantics.
- Invalid path components raise runtime errors.
- Excessively deep paths are rejected according to jq depth limits.
- Operations do not mutate the original input value observed by sibling expressions.

## Programmatic Acceptance

=== AC path-002-conformance ===
Intent: The scoped conformance corpus executes the getpath, setpath, and delpaths cases owned by PATH-002 and passes.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = "getpath|setpath|delpaths"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0

=== END AC path-002-conformance ===

## User Acceptance

- None.

## Guardrails

- Keep path operations immutable from the caller’s perspective.
- Do not convert invalid array/object path components into string keys.
- Enforce jq’s path-depth limits.
=== END ARTIFACT ===

Original FEATURE-Process-Contract.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Process-Contract.md ===
# FEATURE: Process Contract

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines jq compilation, runtime failure, success, and diagnostic process behavior. |
| Depends On  | FEATURE-Executable-Entry-Point.md |
| Provides    | compile and runtime exit contract |
| Consumes    | ./jq -c program interface |

## Questions

- None.

## Capability

The process boundary distinguishes compilation from evaluation:

- Exit 0 means compilation and evaluation completed.
- Exit 3 means the filter could not compile.
- Exit 5 means evaluation raised a runtime error.
- Diagnostics are written to standard error.
- Values emitted before a runtime error remain on standard output.

## Failure Semantics

Invalid syntax and statically invalid references are compile failures. Errors raised while evaluating a valid filter are runtime failures. Diagnostic wording is not part of the contract.

## Programmatic Acceptance

=== AC process-runtime-slice ===
Intent: Runtime-error cases in the supplied corpus preserve the required process contract.

import json
import os
import subprocess
import sys

select = r"try error|error\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC process-runtime-slice ===

=== AC process-compile-exit ===
Intent: A syntactically invalid filter is rejected with the compile-failure exit status.

import subprocess

result = subprocess.run(
    ["./jq", "-c", "{"],
    input="null\n",
    capture_output=True,
    text=True,
)
assert result.returncode == 3
assert result.stderr
=== END AC process-compile-exit ===

=== AC process-runtime-exit ===
Intent: A valid filter that raises at runtime uses the runtime-failure exit status.

import subprocess

result = subprocess.run(
    ["./jq", "-c", "error"],
    input="null\n",
    capture_output=True,
    text=True,
)
assert result.returncode == 5
assert result.stderr
=== END AC process-runtime-exit ===

## User Acceptance

- None.

## Guardrails

- Compile failures must never be reported as runtime failures.
- Diagnostics must never be emitted on standard output.
=== END ARTIFACT ===

Original FEATURE-Recursive-Generators.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Recursive-Generators.md ===
# FEATURE: Recursive Generators

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq recursive generator filters with correct termination and stream ordering. |
| Depends On  | FEATURE-Reductions-and-Iteration-Control.md, FEATURE-Conditionals-and-Exception-Flow.md |
| Provides    | while, until, repeat, recurse, recursive descent |
| Consumes    | ordered jq generator evaluation, conditionals, exception flow |

## Questions

- None.

## Workflow

Recursive filters repeatedly evaluate an update or child generator, emitting values in jq order. The implementation supports conditional recursion, recursive descent through arrays and objects, repeat-until-error behavior, and bounded recursive traversal without leaking unrelated outputs.

## Programmatic Acceptance

=== AC recursive-generators-scoped-conformance ===
Intent: The authoritative corpus slice covering recursive generators executes with no failures or errors.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"while|until|recurse|repeat"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC recursive-generators-scoped-conformance ===

=== AC recursive-generators-interface ===
Intent: Recursive generator evaluation completes through the executable filter interface.
Requires: executable=python3; scope=test

import subprocess

program = "[while(. < 4; . + 1)]"
input_text = "1\n"
result = subprocess.run(
    ["./jq", "-c", program],
    input=input_text,
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.endswith("\n")
=== END AC recursive-generators-interface ===

## User Acceptance

- None.

## Guardrails

- Preserve recursive output order and multiplicity.
- Termination conditions must prevent unbounded recursion except where jq intentionally defines an infinite generator.
- Do not modify the conformance corpus or harness.
=== END ARTIFACT ===

Original FEATURE-Reductions-and-Iteration-Control.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Reductions-and-Iteration-Control.md ===
# FEATURE: Reductions and Iteration Control

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq reductions, iteration controls, and generator selection builtins. |
| Depends On  | FEATURE-Labels-and-Breaks.md, FEATURE-Generator-Core.md |
| Provides    | reduce, foreach, range, limit, skip, first, last, nth |
| Consumes    | ordered jq generator evaluation, lexical labels and breaks |

## Questions

- None.

## Workflow

This capability evaluates reduction and iteration expressions over ordered generator streams. It supports accumulator state, intermediate extraction, bounded selection, skipping, range generation, and first/last/nth selection while preserving cartesian argument behavior and backtracking.

## Programmatic Acceptance

=== AC reductions-scoped-conformance ===
Intent: The authoritative corpus slice covering reductions and iteration controls executes with no failures or errors.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"reduce|foreach|limit|skip|nth|first|last"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC reductions-scoped-conformance ===

=== AC reductions-process-contract ===
Intent: The executable remains invocable through the required jq command interface while exercising a reduction.
Requires: executable=python3; scope=test

import subprocess

program = "reduce .[] as $x (0; . + $x)"
input_text = "[1,2,3]\n"
result = subprocess.run(
    ["./jq", "-c", program],
    input=input_text,
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.endswith("\n")
=== END AC reductions-process-contract ===

## User Acceptance

- None.

## Guardrails

- Preserve accumulator ordering, generator multiplicity, cartesian arguments, and backtracking.
- Negative limits, skips, and nth indices must follow jq runtime error semantics.
- Do not alter the supplied conformance assets.
=== END ARTIFACT ===

Original FEATURE-Regular-Expressions.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Regular-Expressions.md ===
# FEATURE: Regular Expressions

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Define jq regular-expression matching, capture, scanning, splitting, and substitution filters. |
| Depends On  | FEATURE-String-Manipulation.md, FEATURE-Generator-Core.md |
| Provides    | test, match, capture, scan, split, splits, sub, gsub |
| Consumes    | string manipulation and ordered generator evaluation |

## Questions

- None.

## Scope

Implement the regex filters required by the jq manual and corpus using Python standard-library regular expressions. Support supported flags, global matching, named and unnamed captures, UTF-8 codepoint offsets, stream-valued scan and split behavior, and substitution interpolation.

## Programmatic Acceptance

=== AC regex-conformance ===
Intent: The authoritative corpus cases covering jq regular-expression filters execute successfully.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"test\(|match\(|capture\(|scan\(|sub\(|gsub\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC regex-conformance ===

=== AC regex-streams ===
Intent: The authoritative corpus verifies matching streams, captures, regex splitting, and global substitutions.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

select = r"match\(|capture\(|scan\(|split\(|splits\(|sub\(|gsub\("
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", select, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC regex-streams ===

## User Acceptance

- None.

## Guardrails

- Do not add third-party regex dependencies.
- Preserve ordered multiplicity of regex-generated outputs.
- Regex failures must follow jq runtime-error behavior and must not be converted into compile failures.
=== END ARTIFACT ===

Original FEATURE-Scoped-Conformance.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Scoped-Conformance.md ===
# FEATURE: Scoped Conformance Verification

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide executable, selector-scoped conformance verification for implementation slices. |
| Depends On  | FEATURE-Conformance-Assets.md, FEATURE-Executable-Entry-Point.md |
| Provides    | scoped conformance verification |
| Consumes    | staged conformance corpus and harness, ./jq -c program interface |

## Questions

- None.

## Intent

Implementation stories use the supplied runner over a construct-specific selector. The verification must set `JQ` by extending the inherited environment, execute matching cases, parse the machine-readable report, and distinguish an empty selection from a passing slice.

## Behavior

- The runner executes cases selected by the story's syntax selector.
- The candidate executable is supplied through `JQ`.
- A non-empty selected slice is required.
- Any failed or errored case fails verification.
- Harness diagnostics are printed for diagnosis but are not used as an oracle.

## Programmatic Acceptance

=== AC scoped-conformance ===
Intent: The reduce conformance slice executes and passes through the candidate executable.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"reduce"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC scoped-conformance ===

=== AC scoped-conformance-contract ===
Intent: Scoped verification reports a parsed, non-empty result while preserving the runner's exit contract.

import json
import os
import subprocess
import sys

selector = r"reduce"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert isinstance(summary, dict)
assert sum(summary.values()) > 0
assert result.returncode == 0
=== END AC scoped-conformance-contract ===

## User Acceptance

- None.

## Guardrails

- Never use a non-executing enumeration mode for behavioral verification.
- Always extend `os.environ` when supplying `JQ`.
- Do not assert against human-readable runner output.
=== END ARTIFACT ===

Original FEATURE-Slices-and-Iteration.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Slices-and-Iteration.md ===
# FEATURE: Slices and Iteration

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines array and string slicing together with array and object iteration. |
| Depends On  | FEATURE-Accessors.md |
| Provides    | array slices, string slices, array iteration, object iteration, and optional iteration |
| Consumes    | field, index, optional, and negative-index access |

## Questions

- None.

## Behavior

The interpreter shall support inclusive-exclusive slices over arrays and strings, omitted and negative bounds, fractional bounds, iteration over arrays and object values, optional iteration, and jq-compatible behavior for out-of-range operands.

## Programmatic Acceptance

=== AC value-003-conformance ===
Intent: The authoritative conformance cases covering slices and array/object iteration pass.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"\[.*:|\.\[\]"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC value-003-conformance ===

## User Acceptance

- None.

## Guardrails

- Iteration must preserve source ordering and generator multiplicity.
- Optional iteration must suppress the applicable access error without suppressing valid outputs.
=== END ARTIFACT ===

Original FEATURE-Sorting-and-Grouping.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Sorting-and-Grouping.md ===
# FEATURE: Sorting and Grouping

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq sorting, grouping, uniqueness, and extrema builtins. |
| Depends On  | ARCHITECTURE.md, FEATURE-Truthiness-and-Comparison.md, FEATURE-Collection-Transformations.md |
| Provides    | sort, sort_by, group_by, unique, unique_by, min, max, min_by, max_by |
| Consumes    | jq structural comparison, generator evaluation, and collection transformations |

## Questions

- None.

## Behavior

Sorting follows jq's total ordering across nulls, booleans, numbers, strings, arrays, and objects. Keyed variants evaluate their filters for each element and compare generated keys lexicographically. Grouping sorts by keys before forming groups; uniqueness removes duplicate keys while retaining the first representative. Minimum and maximum filters operate on arrays and support keyed forms.

## Programmatic Acceptance

=== AC data-002-conformance ===
Intent: The authoritative jq corpus passes sorting, grouping, uniqueness, and extrema cases selected by their builtin syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"sort|group_by|unique|min|max"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC data-002-conformance ===

## User Acceptance

- None.

## Guardrails

- Use jq comparison semantics, including numeric equivalence and recursive structural ordering.
- Preserve stable representative selection for keyed uniqueness.
=== END ARTIFACT ===

Original FEATURE-Streaming.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Streaming.md ===
# FEATURE: Streaming Transformations

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Reconstruct, emit, and truncate jq streaming representations. |
| Depends On  | ARCHITECTURE.md, FEATURE-Generator-Core.md, FEATURE-Input-Controls.md |
| Provides    | tostream, fromstream, truncate_stream |
| Consumes    | ordered jq generator evaluation, input stream controls |

## Questions

- None.

## Intent

Streaming filters convert JSON values to jq's path/value stream representation and reconstruct values from that representation. The implementation must preserve ordering, empty-container markers, nested paths, and truncation semantics while remaining within the standard-library-only runtime.

## Behavior

- `tostream` emits leaf values and container termination markers with their paths.
- `fromstream` reconstructs arrays, objects, scalars, and empty containers.
- `truncate_stream` removes a specified number of leading path components.
- Filters preserve generator ordering and support the supplied stream expressions.

## Programmatic Acceptance

=== AC streaming-conformance ===
Intent: The streaming filters pass every matching case in the authoritative conformance slice.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"tostream|fromstream|truncate_stream"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC streaming-conformance ===

=== AC streaming-roundtrip-suite ===
Intent: The authoritative suite executes the stream round-trip and truncation behaviors without failures.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"tostream|fromstream|truncate_stream"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC streaming-roundtrip-suite ===

## User Acceptance

- None.

## Guardrails

- Use only Python standard-library facilities.
- Do not change the supplied conformance assets.
- Preserve stream ordering and container markers.
=== END ARTIFACT ===

Original FEATURE-String-Manipulation.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-String-Manipulation.md ===
# FEATURE: String Manipulation

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides jq string trimming, conversion, splitting, joining, and case filters. |
| Depends On  | ARCHITECTURE.md, FEATURE-Literals-and-Strings.md, FEATURE-Type-and-Numeric-Primitives.md, FEATURE-Arithmetic-and-Structural-Operators.md |
| Provides    | trim, ltrim, rtrim, ltrimstr, rtrimstr, trimstr, ascii_downcase, ascii_upcase, explode, implode, split, splits, join, startswith, endswith |
| Consumes    | jq string values, Unicode handling, numeric primitives, and generator evaluation |

## Questions

- None.

## Behavior

String filters operate on Unicode codepoints. Trimming uses the Unicode whitespace definition; prefix and suffix filters remove matching strings only. ASCII case filters affect only ASCII letters. `explode` and `implode` convert between strings and codepoint arrays with jq's replacement behavior for invalid codepoints. `split`, `splits`, and `join` preserve empty fields and generator semantics, while `startswith` and `endswith` validate string operands.

## Programmatic Acceptance

=== AC text-001-conformance ===
Intent: The authoritative jq corpus passes string manipulation cases selected by split, join, trimming, case, codepoint, prefix, and suffix syntax.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"split|join|trim|ascii_|explode|implode|startswith|endswith"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC text-001-conformance ===

## User Acceptance

- None.

## Guardrails

- Preserve Unicode codepoints, embedded NULs, empty strings, and empty split fields.
- Keep regex-based split behavior separate from the single-argument string split behavior.
=== END ARTIFACT ===

Original FEATURE-Truthiness-and-Comparison.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Truthiness-and-Comparison.md ===
# FEATURE: Truthiness and Comparison

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines jq truthiness, equality, inequality, and structural ordering semantics. |
| Depends On  | FEATURE-Generator-Core.md, FEATURE-Composition.md |
| Provides    | jq truthiness, equality, inequality, and ordering |
| Consumes    | ordered jq generator evaluation, jq value model |

## Questions

- None.

## Behavior

Only `false` and `null` are falsey. Equality and inequality shall distinguish booleans from numbers, treat numerically equivalent values as equal, compare arrays and objects structurally, and implement jq's ordering across all supported value types.

## Programmatic Acceptance

=== AC core-004-conformance ===
Intent: The authoritative conformance cases covering truthiness, equality, inequality, and ordering pass.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"==|!=|<=|>=|<|>"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC core-004-conformance ===

## User Acceptance

- None.

## Guardrails

- Python truthiness must not be substituted for jq truthiness.
- Object key order must not affect structural equality.
=== END ARTIFACT ===

Original FEATURE-Type-and-Numeric-Primitives.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Type-and-Numeric-Primitives.md ===
# FEATURE: Type and Numeric Primitives

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provide jq type, length, numeric conversion, predicates, and mathematical primitive filters. |
| Depends On  | FEATURE-Value-Model.md, FEATURE-Truthiness-and-Comparison.md |
| Provides    | type, length, utf8bytelength, numeric predicates, conversions, and math filters |
| Consumes    | jq JSON value model, comparison semantics |

## Questions

- None.

## Intent

Implement `type`, `length`, `utf8bytelength`, `tonumber`, `toboolean`, `tostring`, numeric predicates, and the required standard-library math functions with jq-compatible errors and numeric behavior.

## Programmatic Acceptance

=== AC value-004-conformance ===
Intent: The implementation passes the executed corpus slice covering type and numeric primitives.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"length|type|sqrt|floor|tonumber"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0 and summary["error"] == 0
assert result.returncode == 0
=== END AC value-004-conformance ===

=== AC value-004-numeric-contract ===
Intent: The scoped report contains executed cases and no harness-level failure.
import json
import os
import subprocess
import sys

selector = r"length|type|sqrt|floor|tonumber"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
report = json.loads(result.stdout)
summary = report["summary"]
assert summary["pass"] + summary["fail"] + summary["error"] + summary["skip"] > 0
assert result.returncode == 0
=== END AC value-004-numeric-contract ===

## User Acceptance

- None.

## Guardrails

- Use only Python standard-library facilities.
- Preserve jq's distinction between numeric values and booleans.
=== END ARTIFACT ===

Original FEATURE-Value-Model.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Value-Model.md ===
# FEATURE: Value Model

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Defines the runtime representation and numeric behavior of jq values. |
| Depends On  | FEATURE-JSON-I-O.md, FEATURE-Truthiness-and-Comparison.md |
| Provides    | null, boolean, number, string, array, object, NaN, and infinity values |
| Consumes    | JSON input stream and compact JSON output |

## Questions

- None.

## Behavior

The interpreter shall represent all jq JSON value kinds, including non-finite numeric values produced by jq filters. Numeric equality, conversion, preservation, and compact serialization shall follow the supplied jq 1.8.2 behavior.

## Programmatic Acceptance

=== AC value-001-conformance ===
Intent: The authoritative conformance cases covering NaN, infinity, JSON conversion, and numeric values pass.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r"nan|infinite|tojson|fromjson"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC value-001-conformance ===

## User Acceptance

- None.

## Guardrails

- The implementation shall use only Python standard-library facilities.
- Non-finite values must not cause the process to emit invalid unhandled diagnostics on standard output.
=== END ARTIFACT ===

Original FEATURE-Variable-Bindings.md, in the same form your reply must use:
=== BEGIN ARTIFACT FEATURE-Variable-Bindings.md ===
# FEATURE: Variable Bindings

| Field       | Value |
|-------------|-------|
| Version     | 20260822 V1 |
| Description | Provides lexical jq variable bindings, shadowing, and destructuring patterns. |
| Depends On  | FEATURE-Advanced-Grammar.md, FEATURE-Generator-Core.md |
| Provides    | as bindings, variables, shadowing, destructuring patterns |
| Consumes    | jq filter AST, ordered jq generator evaluation |

## Questions

- None.

## Workflow

Binding expressions evaluate a generator, bind each produced value in lexical scope, and evaluate the remainder against the original input. Bindings support nested scopes, shadowing, keyword names, array and object patterns, and missing values represented as null.

## Programmatic Acceptance

=== AC variable-bindings-scoped-conformance ===
Intent: The authoritative corpus slice covering jq variable bindings executes with no failures or errors.
Suite: scoped
Requires: executable=python3; scope=test

import json
import os
import subprocess
import sys

selector = r" as \$|\$[A-Za-z]"
result = subprocess.run(
    [sys.executable, "sources/run_conformance.py", "--select", selector, "--json"],
    capture_output=True,
    text=True,
    env={**os.environ, "JQ": f"{os.getcwd()}/jq"},
)
print(result.stdout)
print(result.stderr, file=sys.stderr)
report = json.loads(result.stdout)
summary = report["summary"]
assert sum(summary.values()) > 0
assert summary["fail"] == 0
assert summary["error"] == 0
assert result.returncode == 0
=== END AC variable-bindings-scoped-conformance ===

=== AC variable-bindings-interface ===
Intent: Lexical binding syntax compiles and runs through the required executable interface.
Requires: executable=python3; scope=test

import subprocess

program = ". as $value | $value"
input_text = "null\n"
result = subprocess.run(
    ["./jq", "-c", program],
    input=input_text,
    capture_output=True,
    text=True,
)
assert result.returncode == 0
assert result.stdout.endswith("\n")
=== END AC variable-bindings-interface ===

## User Acceptance

- None.

## Guardrails

- Bindings are immutable and lexically scoped.
- A binding must preserve the original pipeline input for the expression following `as`.
- Undefined variables and invalid patterns must remain compile failures.
=== END ARTIFACT ===
</pblock>

