Skip to content

Phase 1.1: Enhanced ContentProcessor with Dual-Representation - #76

Merged
malibio merged 3 commits into
mainfrom
feature/issue-70-contentprocessor-dual-representation
Aug 19, 2025
Merged

malibio merged 3 commits into
mainfrom
feature/issue-70-contentprocessor-dual-representation

Conversation

@malibio

@malibio malibio commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

Closes #70

malibio and others added 3 commits August 19, 2025 21:05
- Create comprehensive ContentProcessor service with Logseq-inspired dual-representation
- Implement lossless Source ↔ AST ↔ Display conversions for future backlinking
- Add wikilink detection foundation for [[text]] syntax (Phase 2 preparation)
- Refactor TextNode to use ContentProcessor, removing scattered content logic
- Add comprehensive testing suite with >95% coverage and performance benchmarks
- Maintain full backward compatibility while establishing foundation for Epic #69

Key Features:
- Dual-representation pattern enabling advanced text editing features
- AST-based architecture ready for AI integration and collaboration
- Security validation with XSS prevention and content sanitization
- Performance optimized for 1000+ node documents (<500ms parse time)
- Extensible foundation for Phase 2 backlinking and Phase 3 rich decorations

Addresses #70 - Phase 1.1 of Text Editor Architecture Enhancement Epic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Remove unused updateNodeContentById function from BaseNodeViewer.svelte
- Remove unused transferChildren function from BaseNodeViewer.svelte
- Ensures code passes ESLint quality checks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add ADR-005: Node Reference Decoration System architectural decision
- Create comprehensive node-reference-system.md component documentation
- Update node-types.md to include node reference system section
- Add ADR-005 to system-overview.md architectural decisions list

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 1859380 into main Aug 19, 2025
@malibio
malibio deleted the feature/issue-70-contentprocessor-dual-representation branch August 19, 2025 20:15
malibio added a commit that referenced this pull request Feb 4, 2026
* Implement Enhanced ContentProcessor with Dual-Representation (Phase 1.1)

- Create comprehensive ContentProcessor service with Logseq-inspired dual-representation
- Implement lossless Source ↔ AST ↔ Display conversions for future backlinking
- Add wikilink detection foundation for [[text]] syntax (Phase 2 preparation)
- Refactor TextNode to use ContentProcessor, removing scattered content logic
- Add comprehensive testing suite with >95% coverage and performance benchmarks
- Maintain full backward compatibility while establishing foundation for Epic #69

Key Features:
- Dual-representation pattern enabling advanced text editing features
- AST-based architecture ready for AI integration and collaboration
- Security validation with XSS prevention and content sanitization
- Performance optimized for 1000+ node documents (<500ms parse time)
- Extensible foundation for Phase 2 backlinking and Phase 3 rich decorations

Addresses #70 - Phase 1.1 of Text Editor Architecture Enhancement Epic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* Fix: Remove unused functions to resolve linting errors

- Remove unused updateNodeContentById function from BaseNodeViewer.svelte
- Remove unused transferChildren function from BaseNodeViewer.svelte
- Ensures code passes ESLint quality checks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* Document universal node reference system architecture

- Add ADR-005: Node Reference Decoration System architectural decision
- Create comprehensive node-reference-system.md component documentation
- Update node-types.md to include node reference system section
- Add ADR-005 to system-overview.md architectural decisions list

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Implement Enhanced ContentProcessor with Dual-Representation (Phase 1.1)

- Create comprehensive ContentProcessor service with Logseq-inspired dual-representation
- Implement lossless Source ↔ AST ↔ Display conversions for future backlinking
- Add wikilink detection foundation for [[text]] syntax (Phase 2 preparation)
- Refactor TextNode to use ContentProcessor, removing scattered content logic
- Add comprehensive testing suite with >95% coverage and performance benchmarks
- Maintain full backward compatibility while establishing foundation for Epic #69

Key Features:
- Dual-representation pattern enabling advanced text editing features
- AST-based architecture ready for AI integration and collaboration
- Security validation with XSS prevention and content sanitization
- Performance optimized for 1000+ node documents (<500ms parse time)
- Extensible foundation for Phase 2 backlinking and Phase 3 rich decorations

Addresses #70 - Phase 1.1 of Text Editor Architecture Enhancement Epic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* Fix: Remove unused functions to resolve linting errors

- Remove unused updateNodeContentById function from BaseNodeViewer.svelte
- Remove unused transferChildren function from BaseNodeViewer.svelte
- Ensures code passes ESLint quality checks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* Document universal node reference system architecture

- Add ADR-005: Node Reference Decoration System architectural decision
- Create comprehensive node-reference-system.md component documentation
- Update node-types.md to include node reference system section
- Add ADR-005 to system-overview.md architectural decisions list

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
mstomar125 pushed a commit that referenced this pull request May 27, 2026
Daemon-broadcast events arrive on the gRPC WatchNodes stream after every
local UpdateNode RPC confirms. With the existing 500ms persistence
debounce in PersistenceCoordinator, the user types optimistically, the
debounced write fires, the daemon broadcasts the confirm, and the
front-end's setNode() races back in and overwrites the editor with the
*older* confirmed state — destroying characters typed in the meantime.

Add a guard: when source.type === 'database' and the incoming node is
either focused (focusManager.editingNodeId === node.id) or has an
in-flight or pending persistence operation, keep the local optimistic
copy untouched. Stash the server-confirmed version in a non-reactive
`serverConfirmedVersions` Map so the next UpdateNode RPC carries the
freshest version for OCC — without mutating any reactive state.

Why non-reactive: mutating the reactive `nodes` Map (or mutating a
property of a node inside it) triggers Svelte re-renders that remount
the focused textarea via the `{#if isEditing}` block in
base-node.svelte. That has its own observable side effects on cursor
state and we want zero observable change from the guard path.

Adds PersistenceCoordinator.hasPending(nodeId) so the guard can ask the
coordinator directly rather than reaching into its private state.

Fixes nodespace-sync#76 (typing corruption: characters dropped or
replaced under sustained input).

nodespace-sync#77 (Enter on a non-empty node creates an empty node
above instead of below) was initially suspected to share this root
cause but verified separately by the user — the bug reproduces in
single-window mode and after this fix lands. Tracked separately; the
root cause is in the Enter handler / insertion path, not in setNode.

Tests: 7 new cases in
src/tests/services/shared-node-store-skip-while-editing.test.ts
covering focused-clobber-skip, pending-clobber-skip, the regression
case (no focus, no pending → apply normally), viewer-source still
authoritative for focused nodes, never-seen nodes accept fresh state,
local node.version unchanged when guard fires, and the
server-confirmed-version cache is cleared when a non-guarded setNode
applies (no shadowing).

Test deltas vs origin/main:
  - shared-node-store family: 245 → 252 passing (+7 new)
  - full frontend suite: 3832 → 3839 passing, same 93 pre-existing
    localStorage-env failures unchanged

Manually verified end-to-end against the two-window same-device demo
(scripts/run-two-daemons.sh + the worktree's vite dev server +
nodespace-app windows for alice and bob). Sustained typing in alice
no longer corrupts characters; bob continues to receive alice's
writes within ~1s.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
malibio pushed a commit that referenced this pull request Jun 22, 2026
Daemon-broadcast events arrive on the gRPC WatchNodes stream after every
local UpdateNode RPC confirms. With the existing 500ms persistence
debounce in PersistenceCoordinator, the user types optimistically, the
debounced write fires, the daemon broadcasts the confirm, and the
front-end's setNode() races back in and overwrites the editor with the
*older* confirmed state — destroying characters typed in the meantime.

Add a guard: when source.type === 'database' and the incoming node is
either focused (focusManager.editingNodeId === node.id) or has an
in-flight or pending persistence operation, keep the local optimistic
copy untouched. Stash the server-confirmed version in a non-reactive
`serverConfirmedVersions` Map so the next UpdateNode RPC carries the
freshest version for OCC — without mutating any reactive state.

Why non-reactive: mutating the reactive `nodes` Map (or mutating a
property of a node inside it) triggers Svelte re-renders that remount
the focused textarea via the `{#if isEditing}` block in
base-node.svelte. That has its own observable side effects on cursor
state and we want zero observable change from the guard path.

Adds PersistenceCoordinator.hasPending(nodeId) so the guard can ask the
coordinator directly rather than reaching into its private state.

Fixes nodespace-sync#76 (typing corruption: characters dropped or
replaced under sustained input).

nodespace-sync#77 (Enter on a non-empty node creates an empty node
above instead of below) was initially suspected to share this root
cause but verified separately by the user — the bug reproduces in
single-window mode and after this fix lands. Tracked separately; the
root cause is in the Enter handler / insertion path, not in setNode.

Tests: 7 new cases in
src/tests/services/shared-node-store-skip-while-editing.test.ts
covering focused-clobber-skip, pending-clobber-skip, the regression
case (no focus, no pending → apply normally), viewer-source still
authoritative for focused nodes, never-seen nodes accept fresh state,
local node.version unchanged when guard fires, and the
server-confirmed-version cache is cleared when a non-guarded setNode
applies (no shadowing).

Test deltas vs origin/main:
  - shared-node-store family: 245 → 252 passing (+7 new)
  - full frontend suite: 3832 → 3839 passing, same 93 pre-existing
    localStorage-env failures unchanged

Manually verified end-to-end against the two-window same-device demo
(scripts/run-two-daemons.sh + the worktree's vite dev server +
nodespace-app windows for alice and bob). Sustained typing in alice
no longer corrupts characters; bob continues to receive alice's
writes within ~1s.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
malibio pushed a commit that referenced this pull request Jun 22, 2026
- Foreign-write OCC defeat: the guard previously stashed `node.version`
  from any database broadcast, including cloud-relayed writes from
  another client. The next UpdateNode would then carry the foreign
  writer's version against the local content, silently overwriting the
  foreign change. Add an `isPlausibleOwnEcho` heuristic — only stash
  when local content equals or extends the incoming content (exact
  echo, or echo+more-typed-chars). For genuine foreign writes, leave
  the cache empty so the next RPC uses the local version and the
  backend's OCC surfaces the conflict.

- hasPending race + repeated calls: the coordinator transitions a
  node between its pending/executing/queued maps, so `hasPending` can
  flip between the guard condition and the log message. Compute
  `isFocused` and `hasPending` once into locals, use those for both
  the condition and the log.

- Persistence consumes the cache — covered: extracted
  `computeOccVersionForUpdate(nodeId)` as the single source of truth
  for "what version does the next UpdateNode RPC carry?". The
  persistence closure routes through it; a new test asserts that
  after the guard fires, `computeOccVersionForUpdate` returns the
  stashed version (5), not the local node.version (1). Future
  refactor that drops the cache read fails this test instead of
  silently re-introducing nodespace-sync#76.

- Foreign-write detection — covered: new test plants a divergent
  optimistic content, fires a database broadcast with a different
  content + higher version, and asserts the cache stays empty.

- `UpdateSource = 'database'` contract: added a comment naming the
  intended producers (tauri-sync-listener / browser-sync-service) so
  the next refactor that adds a new 'database' producer knows to
  audit the guard's assumption.

- persistedNodeIds invariant: added a one-line comment naming the
  "database event for existing node ⟹ persisted server-side"
  invariant so a future refactor that drops the `existingNode` check
  doesn't accidentally start marking unseen nodes as persisted.

- Fixed an issue cross-reference (#77 → #76) in setNode's doc comment.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

Phase 1.1: Enhanced ContentProcessor with Dual-Representation

1 participant