Skip to content

feat(glyph): finish-the-format — contract discipline across Go/Py/JS#12

Merged
phenomenon0 merged 2 commits into
mainfrom
finish-the-format
Jun 20, 2026
Merged

feat(glyph): finish-the-format — contract discipline across Go/Py/JS#12
phenomenon0 merged 2 commits into
mainfrom
finish-the-format

Conversation

@phenomenon0

Copy link
Copy Markdown
Contributor

Summary

The "finish the format" pass from the strategic review: **one normative canonical
contract, lossless round-trips in every mode, exact schema semantics, hardened patch

  • GS1, collision-safe bridges, and full cross-language conformance.** Every technical
    claim was ground-truthed against main first (several were stale and skipped).

What shipped

Phase Result
W1 — Contract & grammar docs/CANONICAL_FORMS.md, GLYPH_T_SPEC.md, GRAMMAR_MATRIX.md; experimental surface annotated
W2 — Scalar consistency bytes b64"…" in every mode (emit+parse); ref quoting (canonRef + quoted ^"…" scanRef); one UTC RFC3339 time form (trimmed fraction); float shortest-round-trip + always a decimal point; NaN/Inf Loose hard-error; conservative bare-string quoting incl. the _ null token
W3 — Parser unification incremental parser hard-errors on time/b64 instead of silently truncating; shared parse_helpers.go — fixes \uXXXX control-char corruption in packed/tabular/loose
W4 — Schema semantics Schema.Check() linter; required-null enforced; ApplyDefaults; @open @unknown capture; constraint-text round-trip fixpoint
W7 — GS1 + safety GS1_SPEC v1.0.1 (seq-0 sentinel, error-code registry, hashmode); DefaultToolRegistry split so execute/read_file/write_file require explicit opt-in
W6 — Patch hardening robust path grammar (map-key unescape, list-index errors), panic-free ApplyPatch, VerifyPatchBase, Diff/Apply round-trip invariant
W5 — Cowrie bridge $glyph reserved-marker + exact-shape guards; fixes _type/_tag/^-string collisions and the type-field silent-loss bug
W8 — Cross-language finish Python + JS mirrored to the contract; shared corpus re-pinned

Verification

  • all-impl parity: 21/21 — Go / Python / JS agree byte-for-byte on every canonical vector
  • Go light gate: green (incl. the previously-red TestGoldenFiles + TestCrossImpl after re-pin)
  • contractcheck: 104/104 · pytest: 433 passed · jest: 514 passed
  • The README invariants (parse(emit(x))==x, identical fingerprints across Go/Py/JS) now hold for real.

Test infra

The memory-heavy bomb/coverage/benchmark tests are gated behind //go:build heavy, so the
default go test gate stays light; CI runs the full suite nightly with -tags heavy.
Added cmd/contractcheck and cmd/bridgecheck (library-only conformance checkers).

⚠️ The full -tags heavy Go suite could not be compiled in the dev sandbox (memory cap);
please confirm it green in CI on this PR.

Known caveats / carry-forward (none are canonical-form bugs)

  • 5 Python xfails — genuine JSON-bridge int-vs-float typing divergence (e.g. JSON -0
    int in Go, float in Python). A separate concern from canonical form; documented as xfail.
  • SortOps orders FID/list-index ≥10 lexicographically (opt-in sort, low-impact).
  • Dangerous DefaultToolRegistry is deprecated, not removed (back-compat).
  • ApplyDefaults doesn't recurse into nested structs; @unknown decode-back deferred.
  • GS1 hashmode reader-parsing is spec-committed but not yet wired; StateHashEmit lacks a Deprecated godoc.
  • Incremental \u decoding doesn't handle surrogate pairs (pre-existing).

🤖 Generated with Claude Code

phenomenon0 and others added 2 commits June 20, 2026 06:23
Land the "finish the format" pass: one normative canonical contract,
lossless round-trips in every mode, exact schema semantics, hardened
patch + GS1, collision-safe bridges, and full cross-language conformance.

Contract & spec (W1):
- docs/CANONICAL_FORMS.md, GLYPH_T_SPEC.md, GRAMMAR_MATRIX.md
- annotate experimental surface (EmitV2/TokenAware/EncodeDictFrame/Decimal128)

Canonical scalar consistency (W2):
- bytes b64"..." in every mode (emit+parse); ref quoting via canonRef +
  quoted ^"..." scanRef; one UTC RFC3339 time form (trimmed fraction);
  float shortest-round-trip + always a decimal point; NaN/Inf Loose hard-error;
  conservative bare-string quoting incl. the "_" null token

Parser unification (W3):
- incremental parser: time/b64 hard-error instead of silent truncation
- shared parse_helpers.go (time/quoted-string/\u escape) across modes,
  fixing \uXXXX control-char corruption in packed/tabular/loose

Schema semantics (W4):
- Schema.Check() linter; required-null enforcement; ApplyDefaults;
  @OPEN @unknown capture; constraint-text round-trip fixpoint

GS1 + safety (W7):
- GS1_SPEC v1.0.1: seq-0 sentinel, error-code registry, hashmode negotiation
- split DefaultToolRegistry; dangerous tools require explicit opt-in

Patch hardening (W6):
- robust path grammar (map-key unescape, list-index errors), panic-free
  ApplyPatch, VerifyPatchBase, Diff/Apply round-trip invariant

Cowrie bridge (W5):
- $glyph reserved-marker + exact-shape guards; fix _type/_tag/^-string
  collisions and the "type"-field silent-loss bug

Cross-language finish (W8):
- mirror Python + JS to the contract; re-pin the shared corpus
- 21/21 Go/Py/JS parity; Go light gate green; contractcheck 104/104;
  pytest 433 passed (5 xfail: JSON int/float bridge boundary); jest 514 passed

Test infra: gate the memory-heavy bomb/benchmark tests behind //go:build heavy
so the default `go test` gate stays light; CI runs the full suite nightly with
-tags heavy. Add cmd/contractcheck and cmd/bridgecheck (library-only checkers).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…incremental safety

All four code-review findings fixed and verified (contractcheck 137/137,
all-impl parity 24/24, pytest 433, jest 514, Go light gate green):

1. Float canonical parity (parity-breaking): Python (loose.py) and JS (loose.ts,
   codec_primitives.ts) now byte-match Go strconv.FormatFloat('g',-1,64) —
   exponential iff decimal-exp <= -5 or >= 6, 2-digit padded exponent. The
   magnitude exponent is derived from the shortest decimal digits, NOT
   math.log10 (which rounds the wrong way just below a power of ten, e.g.
   999999999999999.8 -> 9.999999999999998e+14). Verified vs a 1503-value Go
   reference + boundary set with zero mismatches.

2. JS ref quoting (parity-breaking): canonRef quotes ^"ns:a:b" when the value
   contains ':' (mirrors Go/Python), instead of a bare ^ns:a:b that mis-splits.

3. Incremental parser (silent corruption): parseRef handles quoted ^"..." refs
   (or cleanly awaits-more) instead of silently emitting an empty RefID —
   closes the silent-truncation gap W3 left for refs. + tests.

4. JS typed canonFloat: NaN/+Inf/-Inf emit bare tokens NaN/Inf/-Inf, not
   "NaN.0"/"Infinity.0".

Corpus: large-float and ':'/'/'-in-value ref vectors added to the contract
fixtures and the cross-impl parity gate so this class is now covered.

Cleanups: remove now-dead isBareSafeV2; dedup the b64 decode block into
parse_helpers.decodeBytesLiteral (packed + tabular).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@phenomenon0
phenomenon0 merged commit 95f868f into main Jun 20, 2026
16 of 17 checks passed
@phenomenon0
phenomenon0 deleted the finish-the-format branch June 20, 2026 13:26
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.

1 participant