Skip to content

feat(package): define package JSON via self-documenting codecs - #738

Draft
koterpillar wants to merge 3 commits into
mainfrom
json-doc-codecs
Draft

koterpillar wants to merge 3 commits into
mainfrom
json-doc-codecs

Conversation

@koterpillar

@koterpillar koterpillar commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Introduces JSONCodec (Mybox.JSONCodec), a typeclass that bundles the JSON encoder, decoder and documentation of a type in one value, and uses it to define the JSON representation of every package.

  • Records describe their fields with jsonCodecObject. Each field spec is tagged with the Haskell field name (field @"repo" "clone" "...") and the list is matched against the record's Generic representation, so adding, removing, reordering or renaming a record field without updating the codec is a type error.
  • JSONObjectCodec is the companion class for types represented as a set of keys rather than a value: ArchiveFields and FilterFields are flattened into the enclosing object via fieldFlat. FilterFields also has a standalone JSONCodec instance for the nested Forge release object.
  • Package now requires JSONCodec instead of FromJSON/ToJSON; package hashes are computed through the codec. Concrete packages still derive FromJSON/ToJSON via ViaJSONCodec for convenience, and SomePackage documents itself as one-of all package objects.
  • Field kinds: field (required), fieldDefault (defaults to the type's RecValue rvEmpty when absent, omitted when rvNull), fieldOptional (Maybe, omitted when absent), fieldFlat (flattened). Using RecValue means the encoder and package name splitting share one notion of "default".
  • Instances for Text, Bool, Path, lists (accepting a single item), NonEmpty, and untagged Either (archive raw). Enums (LinksMethod, InstallerKind) use enumCodec, which documents every value.
  • Every field has a one-line description, shown by --package-help.

mybox --package-help

Renders the SomePackage documentation as a table per package type: key, type and description, with required keys marked by a star. Fields of nested objects (the Forge release filter) are indented under their parent. Lists that accept a single item show as text | [text]; enums list their values.

Encoding change

Encoding now writes a key only when it carries information: optional fields are omitted when absent (previously null for clone branch, system installer/url, yum gpg_key) and fields equal to their default are omitted (previously post: [], root: false, the filter and archive lists, etc. were always written). Parsing is unchanged and round-trips exactly.

Because the stored package hash is the encoding minus the name (and the yum repo version is the encoding), every package that stores a hash will be considered changed and reinstalled once after upgrading. Packages fully determined by their name store no hash and are unaffected. The reinstalls are idempotent (fetch and reset, upgrade, re-link, re-extract).

Test plan

  • New Mybox.JSONCodecSpec covers each field policy, defaults, null handling, unknown keys, flattening and generated docs
  • Mybox.Package.SomeSpec checks all 12 package types are documented, render in --package-help and have no duplicate JSON keys after flattening
  • Mybox.Display.SimpleSpec checks the exact rendering of a documentation tree, Mybox.Config.CommandLineSpec the new flag
  • Existing JSON roundtrip and PackageName specs pass for every package
  • Verified manually that adding, removing and misnaming a record field each fail to compile
  • Full test suite (CI)

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.47826% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.04%. Comparing base (65f27c3) to head (8c34d71).

Files with missing lines Patch % Lines
src/Mybox/Package/Some.hs 45.83% 0 Missing and 13 partials ⚠️
test/Mybox/JSONCodecSpec.hs 84.50% 8 Missing and 3 partials ⚠️
src/Mybox/JSONCodec.hs 92.92% 1 Missing and 6 partials ⚠️
test/Mybox/Package/QueueSpec.hs 12.50% 1 Missing and 6 partials ⚠️
test/Mybox/Package/ClassSpec.hs 14.28% 1 Missing and 5 partials ⚠️
src/Mybox/Package/Links.hs 72.22% 2 Missing and 3 partials ⚠️
src/Mybox/Package/AgentSettings/Types.hs 80.00% 1 Missing and 3 partials ⚠️
test/Mybox/Package/SomeSpec.hs 77.77% 3 Missing and 1 partial ⚠️
src/Mybox/Config/CommandLine.hs 50.00% 1 Missing and 2 partials ⚠️
src/Mybox/Display/Data.hs 88.46% 1 Missing and 2 partials ⚠️
... and 17 more

❌ Your patch check has failed because the patch coverage (78.47%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #738      +/-   ##
==========================================
- Coverage   92.03%   91.04%   -1.00%     
==========================================
  Files         131      133       +2     
  Lines        5477     5681     +204     
  Branches      330      367      +37     
==========================================
+ Hits         5041     5172     +131     
- Misses        106      142      +36     
- Partials      330      367      +37     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@koterpillar
koterpillar force-pushed the json-doc-codecs branch 11 times, most recently from 2f83f82 to b00e8dd Compare November 3, 2026 04:27
@koterpillar koterpillar changed the title chore(package): define package JSON via self-documenting codecs feat(package): define package JSON via self-documenting codecs Nov 3, 2026
@koterpillar
koterpillar force-pushed the json-doc-codecs branch 7 times, most recently from 41323c4 to 9d04b4e Compare November 8, 2026 04:14
koterpillar and others added 3 commits November 24, 2026 21:04
Introduce `JSONCodec`, a typeclass bundling the JSON encoder, decoder
and documentation of a type. Package records describe their fields with
`jsonCodecObject`; each field spec is tagged with the Haskell field name
and matched against the record's Generic representation, so adding,
removing or renaming a field without updating the codec is a type error.

`ArchiveFields` and `FilterFields` are flattened via `JSONObjectCodec`.
`FromJSON`/`ToJSON` are derived via `ViaJSONCodec`. Field defaults come
from `RecValue`, the same notion of "default" that package name
splitting uses. Descriptions are placeholders for now.

Encoding now omits optional fields that are absent and fields equal to
their default, instead of writing `null` or the default value. Parsing
is unchanged. This changes the stored hash of most packages (and the
yum repo version), so they will be reinstalled once.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Render the JSONCodec documentation of SomePackage as a table of
fields per package type: key, type and description, with required
fields marked by a star.
Fields of nested objects are indented under their parent.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Replace the placeholder descriptions in the package codecs with
one-line explanations of each JSON key.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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