feat: add dual-mode tree editor with Code Mode, variables, and markdown sync

Implements the full dual-mode tree editor (Plan Phases 1-5):

Backend:
- JSONB↔Markdown bidirectional serializer/parser with mistune
- Markdown validator with line/column error reporting
- 3 API endpoints: export-markdown, import-markdown, validate-markdown
- Variable extraction/resolution service ([USER_INPUT], [VAR], [SAVE_AS])
- Session variables JSONB column (migration 028)
- 39 tree markdown tests + variable service tests (403 total passing)

Frontend:
- Monaco-based Code Mode with custom Monarch tokenizer and dark theme
- Autocomplete for @node_id refs, type values, variable names
- Debounced validation (800ms) with inline Monaco error markers
- Syntax help panel (absolute overlay, toggleable)
- Starter template for new trees with valid cross-references
- Bidirectional metadata sync (name/description/category/tags frontmatter)
- Synchronous tree→markdown serializer (fixes async race condition)
- Pre-save validation blocks save on broken refs or missing tree name
- Mode-aware undo/redo: Monaco native in Code Mode, throttled zundo in Flow Mode
- Variable prompt modal and frontend resolver for session navigation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-10 09:45:26 -05:00
parent 2bd47004e7
commit eac6e184ec
32 changed files with 3369 additions and 52 deletions

View File

@@ -4,6 +4,7 @@ import { persist } from 'zustand/middleware'
type ExportFormat = 'markdown' | 'text' | 'html' | 'psa'
type TreeLibraryView = 'grid' | 'list' | 'table'
type TreeSortBy = 'usage_count' | 'updated_at' | 'created_at' | 'name' | 'name_desc' | 'version'
type EditorMode = 'form' | 'code'
interface UserPreferencesState {
defaultExportFormat: ExportFormat
@@ -12,6 +13,8 @@ interface UserPreferencesState {
setTreeLibraryView: (view: TreeLibraryView) => void
treeLibrarySortBy: TreeSortBy
setTreeLibrarySortBy: (sortBy: TreeSortBy) => void
preferredEditorMode: EditorMode
setPreferredEditorMode: (mode: EditorMode) => void
}
export const useUserPreferencesStore = create<UserPreferencesState>()(
@@ -23,6 +26,8 @@ export const useUserPreferencesStore = create<UserPreferencesState>()(
setTreeLibraryView: (view) => set({ treeLibraryView: view }),
treeLibrarySortBy: 'usage_count',
setTreeLibrarySortBy: (sortBy) => set({ treeLibrarySortBy: sortBy }),
preferredEditorMode: 'form',
setPreferredEditorMode: (mode) => set({ preferredEditorMode: mode }),
}),
{
name: 'user-preferences-storage',