Skip to content

fix: read the YAML layouts a model actually writes, and name the line and construct on a parse error - #293

Merged
TheAmericanMaker merged 1 commit into
mainfrom
fix/246-yaml-indent
Sep 12, 2026
Merged

fix: read the YAML layouts a model actually writes, and name the line and construct on a parse error#293
TheAmericanMaker merged 1 commit into
mainfrom
fix/246-yaml-indent

Conversation

@TheAmericanMaker

Copy link
Copy Markdown
Member

Closes #246 (D-M10; mech 1.7, probes C/C2/D).

What the audit's probes actually show

Probes C and C2 (a sibling key indented deeper than the item's first key) are not valid YAML — PyYAML rejects both with "mapping values are not allowed here" — so the issue's "(valid YAML)" premise is wrong for those two. The layout the earlier itemIndent fix handles (- id: x with siblings aligned under id) already parsed. I probed a wider set of layouts against PyYAML and found four that are valid and were rejected or mangled:

Layout Before Now
List at the same column as its key (items: / - a) items: null, and at the top level every later line silently dropped; nested, the indentation error parses
Plain scalar wrapped onto more-indented lines (probe D — a long closeout_summary) indentation error folds like > (blank line → newline)
Scalar starting on the line after its key; wrapped sequence items; wrapped value on an item's first key indentation / "mapping entry" errors fold
Sequence of sequences (- - a) indentation error parses
Tab indentation \tb: 1 → key "" (garbage) error naming the line

Every expectation in the tests was checked against PyYAML before being pinned. Continuation stops at a mapping entry (key: — colon-space, so a wrapped https://… is not a key), a sequence item, or a comment; quoted scalars never continue.

Error messages

All parse errors are now YAML line N: <what was expected> — "<the line>":

  • over-indented line: this line is indented 6 columns but the mapping it belongs to starts at column 4; a sibling key must align with the first key, and a wrapped value must not contain ": "
  • dash where a key was expected (never valid inside a mapping's loop — the same-column-list case is consumed before the loop sees it): a sequence item where a mapping entry was expected; …
  • content after the top-level block ended (was silently unread)
  • tabs, duplicate keys (the Duplicate YAML key: dup wording is kept inside the new format — framework-handoff.test.mjs pins it), non-entry lines

The emitter is untouched; #225 (scalar-looking strings emitted bare) is a separate open high.

Docs

docs/library-format.md §YAML dialect still said > folded scalars are not read (stale since 0.19.3; L4). It now lists what is read and that errors name the line.

Tests

11 new (suite 732/732): 10 in tests/yaml.test.mjs covering each layout and each message, plus tests/handoff-layouts.test.mjs completing a real handoff written with a wrapped closeout_summary, a next-line description, and same-column lists through codecarto_complete. All 11 fail on the pre-fix parser.

🤖 Generated with Claude Code

… and construct on a parse error

Four layouts that are valid YAML — checked against a spec-compliant
parser — were rejected or mangled by core/yaml.ts, each with "Invalid
YAML indentation near: …" or worse:

- A block sequence at the same column as its key (`items:` / `- a`) read
  as `items: null`, and at the top level every line after it was dropped
  without a word. Nested, the same layout threw.
- A plain scalar wrapped onto more-indented lines (self-audit probe D),
  which is what a model writing a long closeout_summary produces, threw.
  So did a scalar starting on the line after its key, a wrapped sequence
  item, and a wrapped value on an item's first key. They fold now, blank
  lines to newlines, like a `>` block.
- A sequence of sequences threw.
- A tab in the indentation was counted as two columns and sliced as one
  character, so `\tkey: v` parsed as the key "".

Every parse error now reads `YAML line N: <what was expected> — "<the
line>"`. The audit's probes C and C2 (a sibling key deeper than the first
key) are not valid YAML and still fail, but the message says so instead
of blaming whitespace. Content left after the top-level block ends is an
error rather than silently unread. The Duplicate YAML key wording is kept
inside the new format.

docs/library-format.md's dialect section was still saying folded scalars
are not read; it now lists what is.

Closes #246.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@TheAmericanMaker
TheAmericanMaker merged commit 711310b into main Sep 12, 2026
5 checks passed
@TheAmericanMaker
TheAmericanMaker deleted the fix/246-yaml-indent branch September 12, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[self-audit D-M10] Valid YAML nesting indents are rejected as 'Invalid YAML indentation'

1 participant