Skip to content

feat(library): add source-preserving JSON tree editing - #167

Merged
PPRAMANIK62 merged 5 commits into
liliu-z:mainfrom
Swapnanilmanna1701:swapnanil/json-tree-editing
Aug 14, 2026
Merged

feat(library): add source-preserving JSON tree editing#167
PPRAMANIK62 merged 5 commits into
liliu-z:mainfrom
Swapnanilmanna1701:swapnanil/json-tree-editing

Conversation

@Swapnanilmanna1701

Copy link
Copy Markdown
Contributor

Summary

Closes #166 by adding a lazy, source-preserving Tree mode for strict JSON while retaining the existing exact Source editor and shared versioned save transaction.

JSON source text remains the only persistence authority. The tree is a bounded controller over syntax spans: supported structural operations patch the smallest safe source range instead of parsing into a JavaScript object and serializing the full document.

What changed

  • Open valid, unique-key JSON in Tree mode by default, with exact Source mode available at all times.
  • Support scalar edits, object-key rename, property add/delete, array add/delete/reorder, and validated raw-subtree replacement.
  • Preserve BOM, LF/CRLF, indentation, property order, untouched whitespace, escape spelling, precise number lexemes, and trailing-newline state.
  • Keep invalid, incomplete, empty, duplicate-key, and over-limit inputs editable and saveable in Source mode with an actionable Tree-mode explanation.
  • Enforce measured Tree limits of 512,000 UTF-8 bytes, 20,000 nodes, and depth 80.
  • Retain Tree/Source mode, expansion, selection, and search state per recent tab while keeping active editor/Find ownership scoped to the active tab.
  • Integrate Tree search with global Find semantics, including case-sensitive and whole-word behavior, while resetting hidden modes when users type directly into the simple Tree search field.
  • Route search-result highlights to visible Tree paths, falling back to Source mode when a source range cannot be represented by one tree node.
  • Add roving tree focus with Arrow Up/Down/Left/Right, Home, End, and Enter behavior, plus predictable focus restoration after Apply and Cancel.
  • Lazy-load the Tree surface and register both JSON dynamic entries in the renderer chunk contract.
  • Update the README, product design, user journey, viewer, transaction, workspace, and journey-coverage contracts.

Source-preservation details

The StashBase-owned source model uses strict jsonc-parser syntax trees without materializing a normal JavaScript object. This avoids duplicate-key collapse and unsafe-number coercion. Existing syntax is retained byte-for-byte except for the selected safe range. First-child insertion replaces existing empty-container whitespace, so multiline {\n} / [\n] containers do not acquire blank lines and indented closing delimiters remain aligned.

Documents with duplicate object keys do not enter Tree mode because ordinary path identity cannot distinguish those members safely. They remain fully usable in Source mode.

Validation

  • pnpm typecheck
  • pnpm build:web
  • pnpm test:renderer
  • pnpm test:renderer-chunks
  • pnpm test:library-files
  • pnpm test:retrieval
  • pnpm test:docs
  • pnpm test:e2e:check-focus
  • pnpm test:e2e:smoke — 5 passed
  • Focused markdown-json.spec.ts Electron functional journey passed
  • Full functional run: all 26 non-Agent journeys passed, including JSON Tree/Source editing and recovery. One pre-existing Agent clipboard-history failure reproduced independently because it copied an NVIDIA timeout response rather than the deterministic fake-runtime reply; an unrelated navigation launch failure passed when rerun in isolation.

Reviewer notes

  • No JSON-specific save or autosave path was added.
  • Search/indexing and Agent/MCP continue to consume the raw JSON source and real file path.
  • Tree code remains outside the initial renderer bundle and the initial static JavaScript budget stays green.

@Swapnanilmanna1701
Swapnanilmanna1701 marked this pull request as ready for review August 13, 2026 21:08
@PPRAMANIK62
PPRAMANIK62 force-pushed the swapnanil/json-tree-editing branch from 51946e8 to 7300fb9 Compare August 14, 2026 07:13
@PPRAMANIK62
PPRAMANIK62 merged commit 4dc02a0 into liliu-z:main Aug 14, 2026
5 checks passed
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.

feat(library): add source-preserving tree editing for JSON

2 participants