Repository navigation
feat(agent-config): JSON merge-patch, JSON pointer, overlay ops and YAML helpers [2/21] - #323
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
YAML validation and provenance classification still have correctness defects.
Review effort: Balanced
Findings: 2
Open (4)
What changed in this PR
Adds foundational helpers for the agent configuration overlay editor, without exposing new app UI yet.
Changes:
- Adds merge-patch, JSON Pointer, and immutable overlay-editing utilities.
- Adds YAML parsing/rendering and value provenance.
- Adds unit tests for all five helpers.
| File | Description |
|---|---|
src/utils/agent-config/yaml.ts |
YAML parsing, rendering, and validation. |
src/utils/agent-config/provenance.ts |
Classifies file and overlay value origins. |
src/utils/agent-config/overlay-ops.ts |
Immutable set, unset, and delete operations. |
src/utils/agent-config/merge-patch.ts |
Merge-patch, cloning, and structural equality. |
src/utils/agent-config/json-pointer.ts |
Pointer encoding, lookup, and ancestry checks. |
src/utils/agent-config/__tests__/yaml.spec.ts |
Tests YAML conversion and validation. |
src/utils/agent-config/__tests__/provenance.spec.ts |
Tests provenance classifications. |
src/utils/agent-config/__tests__/overlay-ops.spec.ts |
Tests edits, pruning, and prototype-key safety. |
src/utils/agent-config/__tests__/merge-patch.spec.ts |
Tests RFC examples and immutability. |
src/utils/agent-config/__tests__/json-pointer.spec.ts |
Tests pointer parsing and navigation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| let nodes = 0; | ||
| const visit = (v: unknown): string | null => { | ||
| if (++nodes > MAX_NODES) return 'Document is too large'; | ||
| if (v === null || typeof v !== 'object') return null; |
There was a problem hiding this comment.
Fixed in c157be1. parseYaml now loads with CORE_SCHEMA int/float types that reject non-finite values (.inf, -.Inf, .nan) with a blocking error at their line and column ("… is not a finite number: quote it to keep it as text"), so nothing reaches JSON.stringify as null. 1e999 is not a YAML float at all, so it stays the string that was typed. Specs are in yaml.spec.ts.
| error: { message: (e as Error).message ?? String(e), line: 0, column: 0 }, | ||
| }; | ||
| } | ||
| if (value === null || value === undefined) return { ok: true, value: {} }; |
There was a problem hiding this comment.
Fixed in c157be1. An explicit null / ~ root (also --- null) now fails with "Overlay must be a mapping". Only text without any node, meaning empty or comment-only, is {}. js-yaml loads both as null, so a load listener records whether any node had content.
| base: unknown, | ||
| overlay: unknown, | ||
| ): Provenance { | ||
| const inBase = hasAt(base, ptr) && getAt(base, ptr) !== null; |
There was a problem hiding this comment.
Fixed in c157be1. Whether the file has the member is now decided by hasAt alone, so for base {k: null}, {k: 1} is overrides-file and {k: null} is removed-by-overlay. Spec added.
| overlay: unknown, | ||
| ): Provenance { | ||
| const inBase = hasAt(base, ptr) && getAt(base, ptr) !== null; | ||
| if (nulledByOverlay(overlay, ptr)) { |
There was a problem hiding this comment.
Fixed in c157be1. Provenance now walks the overlay from the root. A null on a plain-object path is a deletion. An array or scalar ancestor replaces the whole subtree: nulls below it are data, and a descendant is overrides-file/overlay if the replacement has it, otherwise removed-by-overlay when the file had it. Specs cover [1]→[null], [{x,y}]→[{x}] and scalar/object replacements.
…AML helpers Layer 2 of 21 in the stacked split of #318. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d29715b to
5813fc1
Compare
…7396 provenance
- parseYaml rejects numbers that would not be saved as typed (.inf/.nan,
0644/0x1F/0o17/+5, integers past 2^53) with the line and column, for
every field and for mapping keys; quoting keeps them as text
- an explicit null / ~ root is not a mapping; only comment-only text is {}
- provenance: a null file value is present; under an array or scalar
replacement, nulls are data and descendants are classified by the
replacement
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Part 2 of 21 of the stacked split of #318 (agent remote configuration). Every layer adds the final version of its files from #318, and only imports from layers below it, so each layer passes
make reviewableon its own. Nothing is reachable in the app until layer 20 wires the Configuration tab in.What
Pure helpers the overlay editor is built on: RFC 7396 JSON merge-patch, RFC 6901 JSON pointers, overlay set/unset operations, YAML parse/dump wrappers and value provenance (overlay vs. host vs. default).
Tests
Unit specs for each helper.
🤖 Generated with Claude Code