Skip to content

feat(ui): display and edit JSON payloads as HJSON - #584

Open
madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:feat/hjson-display
Open

madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:feat/hjson-display

Conversation

@madejackson

@madejackson madejackson commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Display & edit JSON payloads as HJSON

The compose editor (create/edit/import), API config preview modals and the event explorer rendered raw JSON.stringify output — noisy with quotes and escaping. This switches the display side to HJSON (hjson.github.io) and makes the compose editor/import accept HJSON on input.

What changes

  • client/src/utils/hjson.jsx (new): toHjson() renders objects as pretty HJSON (unquoted keys, quotes: 'min' string values, separator: false, multiline strings as ''' blocks); parseJsonOrHjson() tries JSON first and falls back to HJSON (a superset of JSON) — users can paste either.
    • Multiline display: strings containing real \n (but no \r) render as ''' ... ''' blocks; CRLF strings stay escaped to avoid Hjson's \r-stripping data loss. Round-trip is exact.
    • quoteArrayColons: bare array elements containing : (e.g. BACKEND_HOSTNAME=https://..., 8080:80) are quoted so the grammar colors them as single green strings.
    • Comment preservation (extractComments/injectComments): HJSON comments are extracted to a node→comment map on save and restored on load; ''' block interiors are skipped so #/// inside multiline strings are never captured as comments.
  • client/src/utils/hjsonGrammar.js (new): a Prism grammar that keeps the editor's familiar colors with HJSON — keys red, string values green (bare, quoted and ''' blocks), numbers/booleans violet, null cyan, comments (#, //, / */*) grey, multiline strings & block comments supported. Handles strings containing #, //, : and comments containing : correctly.
  • newService.jsx: compose editor initialised with toHjson(service), submits via parseJsonOrHjson.
  • docker-compose.jsx: JSON compose imports parse via parseJsonOrHjson (2-line change; YAML import path untouched).
  • apiModal.jsx / eventsExplorer.jsx: API payloads and event details render as HJSON when JSON (non-JSON text left as-is).
  • package.json / package-lock.json: add hjson dependency.

Notes

  • Pure frontend preprocessing — the backend still receives and emits JSON unchanged; round-trip is exact.
  • Verified with npm run client-build and an extensive test matrix (keys, escaped quotes, #////: inside strings, multiline strings/block comments, env-array values like TZ=Europe/Zurich and FTLCONF_misc_dnsmasq_lines=..., round-trip of CRLF and multiline values).

@cla-bot cla-bot Bot added the cla-signed label Aug 31, 2026
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 1, 2026
…itor

Instead of storing a snapshot label, derive what the user actually set by
diffing the running container's config against the image's own config:

Backend
- New ExportContainerRuntime: exports only the settings that were explicitly
  set at create time, by comparing ContainerInspect against
  ImageInspectWithRaw:
  * env: keep only entries not present in the image env or with a different
    value (image-inherited ENV and Cosmos-injected TZ/normalized vars dropped)
  * labels: keep only labels not in the image; drop cosmos.* and
    com.docker.compose.* bookkeeping labels
  * command/entrypoint/workingdir/user/stopsignal/hostname/domainname/
    healthcheck: kept only when they differ from the image's
  * inherently-runtime fields (ports, volumes, networks, resources, restart,
    dns, etc.) have no image baseline and are exported as-is
  * falls back to the full runtime export if the image is unavailable
- ExportContainerRoute: ?from=initial (default) uses the diff;
  ?from=runtime uses the full live runtime export

Frontend
- docker.tsx exportContainer now takes from?: 'initial' | 'runtime'
- compose-editor adds a 'Show runtime values' switch that re-fetches the
  diff vs the full runtime view (themed for dark/light)
- newService.jsx re-syncs the editor when the service prop changes (so the
  toggle actually updates the document)

Prerequisite: bases on the HJSON PR azukaar#584 (feat/hjson-display).
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 1, 2026
…itor

Instead of storing a snapshot label, derive what the user actually set by
diffing the running container's config against the image's own config:

Backend
- New ExportContainerRuntime: exports only the settings that were explicitly
  set at create time, by comparing ContainerInspect against
  ImageInspectWithRaw:
  * env: keep only entries not present in the image env or with a different
    value (image-inherited ENV and Cosmos-injected TZ/normalized vars dropped)
  * labels: keep only labels not in the image; drop cosmos.* and
    com.docker.compose.* bookkeeping labels
  * command/entrypoint/workingdir/user/stopsignal/hostname/domainname/
    healthcheck: kept only when they differ from the image's
  * inherently-runtime fields (ports, volumes, networks, resources, restart,
    dns, etc.) have no image baseline and are exported as-is
  * falls back to the full runtime export if the image is unavailable
- ExportContainerRoute: ?from=initial (default) uses the diff;
  ?from=runtime uses the full live runtime export

Frontend
- docker.tsx exportContainer now takes from?: 'initial' | 'runtime'
- compose-editor adds a 'Show runtime values' switch that re-fetches the
  diff vs the full runtime view (themed for dark/light)
- newService.jsx re-syncs the editor when the service prop changes (so the
  toggle actually updates the document)

Prerequisite: bases on the HJSON PR azukaar#584 (feat/hjson-display).
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 2, 2026
…itor

Instead of storing a snapshot label, derive what the user actually set by
diffing the running container's config against the image's own config:

Backend
- New ExportContainerRuntime: exports only the settings that were explicitly
  set at create time, by comparing ContainerInspect against
  ImageInspectWithRaw:
  * env: keep only entries not present in the image env or with a different
    value (image-inherited ENV and Cosmos-injected TZ/normalized vars dropped)
  * labels: keep only labels not in the image; drop cosmos.* and
    com.docker.compose.* bookkeeping labels
  * command/entrypoint/workingdir/user/stopsignal/hostname/domainname/
    healthcheck: kept only when they differ from the image's
  * inherently-runtime fields (ports, volumes, networks, resources, restart,
    dns, etc.) have no image baseline and are exported as-is
  * falls back to the full runtime export if the image is unavailable
- ExportContainerRoute: ?from=initial (default) uses the diff;
  ?from=runtime uses the full live runtime export

Frontend
- docker.tsx exportContainer now takes from?: 'initial' | 'runtime'
- compose-editor adds a 'Show runtime values' switch that re-fetches the
  diff vs the full runtime view (themed for dark/light)
- newService.jsx re-syncs the editor when the service prop changes (so the
  toggle actually updates the document)

Prerequisite: bases on the HJSON PR azukaar#584 (feat/hjson-display).
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 2, 2026
…itor

Instead of storing a snapshot label, derive what the user actually set by
diffing the running container's config against the image's own config:

Backend
- New ExportContainerRuntime: exports only the settings that were explicitly
  set at create time, by comparing ContainerInspect against
  ImageInspectWithRaw:
  * env: keep only entries not present in the image env or with a different
    value (image-inherited ENV and Cosmos-injected TZ/normalized vars dropped)
  * labels: keep only labels not in the image; drop cosmos.* and
    com.docker.compose.* bookkeeping labels
  * command/entrypoint/workingdir/user/stopsignal/hostname/domainname/
    healthcheck: kept only when they differ from the image's
  * inherently-runtime fields (ports, volumes, networks, resources, restart,
    dns, etc.) have no image baseline and are exported as-is
  * falls back to the full runtime export if the image is unavailable
- ExportContainerRoute: ?from=initial (default) uses the diff;
  ?from=runtime uses the full live runtime export

Frontend
- docker.tsx exportContainer now takes from?: 'initial' | 'runtime'
- compose-editor adds a 'Show runtime values' switch that re-fetches the
  diff vs the full runtime view (themed for dark/light)
- newService.jsx re-syncs the editor when the service prop changes (so the
  toggle actually updates the document)

Prerequisite: bases on the HJSON PR azukaar#584 (feat/hjson-display).
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 5, 2026
…itor

Instead of storing a snapshot label, derive what the user actually set by
diffing the running container's config against the image's own config:

Backend
- New ExportContainerRuntime: exports only the settings that were explicitly
  set at create time, by comparing ContainerInspect against
  ImageInspectWithRaw:
  * env: keep only entries not present in the image env or with a different
    value (image-inherited ENV and Cosmos-injected TZ/normalized vars dropped)
  * labels: keep only labels not in the image; drop cosmos.* and
    com.docker.compose.* bookkeeping labels
  * command/entrypoint/workingdir/user/stopsignal/hostname/domainname/
    healthcheck: kept only when they differ from the image's
  * inherently-runtime fields (ports, volumes, networks, resources, restart,
    dns, etc.) have no image baseline and are exported as-is
  * falls back to the full runtime export if the image is unavailable
- ExportContainerRoute: ?from=initial (default) uses the diff;
  ?from=runtime uses the full live runtime export

Frontend
- docker.tsx exportContainer now takes from?: 'initial' | 'runtime'
- compose-editor adds a 'Show runtime values' switch that re-fetches the
  diff vs the full runtime view (themed for dark/light)
- newService.jsx re-syncs the editor when the service prop changes (so the
  toggle actually updates the document)

Prerequisite: bases on the HJSON PR azukaar#584 (feat/hjson-display).
madejackson pushed a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 5, 2026
PR azukaar#584 (HJSON infra) adds client/src/utils/hjson.jsx which imports the
'hjson' npm package, but the dependency was never declared in
package.json. Without it the client build fails at:
  Rollup failed to resolve import "hjson" from hjson.jsx
Add hjson ^3.2.2 (same version as PR azukaar#584).
@madejackson
madejackson force-pushed the feat/hjson-display branch 2 times, most recently from c0f48b1 to d6c18d0 Compare October 9, 2026 11:35
@cla-bot

cla-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: madejackson.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@cla-bot cla-bot Bot removed the cla-signed label Oct 9, 2026
@cla-bot cla-bot Bot added the cla-signed label Oct 9, 2026
@madejackson
madejackson force-pushed the feat/hjson-display branch 2 times, most recently from 7ca9a67 to f60d7bc Compare October 9, 2026 15:24
@madejackson

Copy link
Copy Markdown
Contributor Author

Updated the branch to match the description in the PR body — the HJSON output now actually uses quotes: 'min' + separator: false with the quoteArrayColons pass and the matching grammar tokens, all in a single feature commit (f60d7bc3). The multiline-'''-block fix was folded into the same commit so the feature ships complete and self-consistent. No content change beyond what the body already describes.

Replace raw JSON.stringify output with HJSON (hjson.github.io) in the
compose editor, docker-compose JSON import, API config preview modals and
the event explorer: unquoted keys, always-quoted string values, trailing
separators, no escaping noise. The compose editor/import parse HJSON on
submit (JSON first, HJSON fallback — a superset), so users can paste either.
Pure frontend preprocessing: the backend still receives and emits JSON.

Includes a Prism grammar that keeps the familiar editor colors with HJSON:
keys red, string values green, numbers/booleans/null purple, comments and
multiline strings/block-comments grey/green. Strings containing #, // or :
stay single quoted strings; comments containing ':' stay comments.

Files:
- client/src/utils/hjson.jsx (new): toHjson + parseJsonOrHjson
- client/src/utils/hjsonGrammar.js (new): Prism HJSON grammar
- newService.jsx / docker-compose.jsx: init/parse as JSON-or-HJSON
- apiModal.jsx / eventsExplorer.jsx: render payloads/events as HJSON
- package.json / package-lock.json: add hjson dependency
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Nov 13, 2026
Replace raw JSON.stringify output with HJSON (hjson.github.io) in the
compose editor, docker-compose JSON import, API config preview modals and
the event explorer: unquoted keys, always-quoted string values, trailing
separators, no escaping noise. The compose editor/import parse HJSON on
submit (JSON first, HJSON fallback - a superset), so users can paste
either. Pure frontend preprocessing: the backend still receives and emits
JSON.

Includes a Prism grammar that keeps the familiar editor colors with HJSON:
keys red, string values green, numbers/booleans/null purple, comments and
multiline strings/block-comments grey/green. Strings containing #, // or :
stay single quoted strings; comments containing ':' stay comments.

Files:
- client/src/utils/hjson.jsx (new): toHjson + parseJsonOrHjson
- client/src/utils/hjsonGrammar.js (new): Prism HJSON grammar
- newService.jsx / docker-compose.jsx: init/parse as JSON-or-HJSON
- apiModal.jsx / eventsExplorer.jsx: render payloads/events as HJSON
- package.json / package-lock.json: add hjson dependency

Upstream PR: azukaar#584
@madejackson

Copy link
Copy Markdown
Contributor Author

Closing: fully superseded by #590

Verified mechanically, not by eye:

$ git show cb4caf56 | git patch-id --stable     # tip of this PR (feat/hjson-display)
6fe8151d1096551e967ceb8ec0891c3d007fcc87 cb4caf56...
$ git show 30c8fc52 | git patch-id --stable     # 1st commit of #590 (pr/hjson-comments)
6fe8151d1096551e967ceb8ec0891c3d007fcc87 30c8fc52...

Identical patch-id, and the patches are byte-for-byte the same:

$ diff -q <(git show cb4caf56 --format=) <(git show 30c8fc52 --format=)
IDENTICAL patch text
 8 files changed, 345 insertions(+), 7 deletions(-)   # both

#590 = this exact commit plus the follow-up commit 67d8005b feat(docker): user-set vs runtime config + persist HJSON comments. So #590 is a strict superset of #584 — merging both would apply the same change twice.

Closing #584 in favour of #590, which I'll keep rebased and verified. Nothing is dropped: every line of this PR is inside #590's branch (pr/hjson-comments → 67d8005b).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant