Skip to content

feat: create workspace, selection highlight, change highlight, git integration, auto-save, state-save, telemetry viewer - #8

Draft
dcmaf wants to merge 8 commits into
prxshetty:mainfrom
dcmaf:feat/change-highlighting
Draft

dcmaf wants to merge 8 commits into
prxshetty:mainfrom
dcmaf:feat/change-highlighting

Conversation

@dcmaf

@dcmaf dcmaf commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Key Capabilities & Functional Highlights

1. Real-Time Visual Change Tracking

  • Live Word-Level Inline Diffing: Visualizes text additions (green tint) and deletions (inline strikethrough) in real time directly within the editor canvas as you write, without modifying the underlying markdown document.
  • Smart DP Diffing & Block Insertion: Distinguishes between rewritten paragraphs and newly inserted passages, preventing subsequent text from falsely cascading into deletion highlights.
  • Quick Display Toggles: Toggle addition and deletion highlights on or off instantly via bottom-bar controls, with preferences remembered across sessions.

2. Dual Workspace Baseline & Versioning

  • Git Workspaces: Resolves baseline diffs against the Git staging area (index) or latest commit (HEAD).
  • Non-Git Workspaces: Automatically maintains file snapshots in .margin-shadow/, providing change highlighting, modification tracking, and baseline restoration for projects not managed with Git.
  • Real-Time Manual Revert Detection: Automatically clears the modified flag (M badge) in real time when you manually undo, backspace, or type text back to match the baseline snapshot—with zero polling overhead.
  • Instant Baseline Restoration: One-click Restore modal allows discarding working modifications and reverting the active document to its baseline state at any time.

3. Workspace Creation & Project Scaffolding

  • Interactive Project Creation: Create and scaffold new novel workspaces directly from the sidebar or settings.
  • Standard Story Structure: Automatically scaffolds organized folders and starter templates for chapters/, characters/, styles/, prompts/, and outputs/.
  • Zero-Configuration Initialization: Automatically populates snapshot baselines for non-Git workspaces so new projects start clean, while supporting optional one-click Git repository initialization with .gitignore.

4. Active Selection & Assistant Auto-Targeting

  • Adaptive Theme Selections: Selected text passages are highlighted with high-contrast, theme-adaptive styling across all 10 visual themes.
  • Enclosing Paragraph Auto-Targeting: Focusing the assistant prompt box without an explicit text selection automatically identifies and targets the paragraph enclosing your cursor.
  • Floating Bubble Menu Integration: Stage any selected passage into the assistant panel with a single click (+ Margin), immediately applying a selection highlight and focusing the prompt.

5. Inline AI Edit Previews & Non-Destructive Review

  • Inline Strikethrough Diff Previews: Proposed AI rewrites and chapter edits appear inline in the editor as red strikethrough deletions followed by green insertions.
  • Interactive Accept / Reject Toolbar: Floating controls and keyboard shortcuts (Enter to accept, Esc to reject) allow reviewing and testing changes in place before applying them.

6. 5-Tier Document Auto-Save & Resilience Architecture

  • Continuous Background Saving: Unifies manual saves (Ctrl+S/Cmd+S), debounced idle typing saves (2s pause), editor blur events, tab visibility changes, and pre-flight query saves before sending AI prompts.
  • Unload & Sleep Safety Net: Utilizes keepalive beacon requests to flush unwritten document edits to disk on tab close, refresh, or system sleep.
  • Full State & Scroll Restoration: Remembers the active document, in-progress AI diff reviews, and per-document scroll positions across page reloads and computer wake cycles.

7. Sidebar Status & Visual File Hierarchy

  • Color-Coded Status Badges: Sidebar file items instantly communicate status with dedicated icons and badges:
    • Amber M: Unstaged modifications.
    • Emerald S: Staged changes.
    • Dual-Tone S/M: Staged file with subsequent working modifications.
  • Parent Folder Modified Indicators: Collapsed folders display an amber dot indicator whenever any nested child documents contain unsaved or modified changes.

8. Streamlined Git Staging & Commit Workflow

  • Single-File Auto-Stage Commit Gating: When only the active document has unstaged modifications, the Commit button enables automatically and stages the active file seamlessly as part of the commit process.
  • Multi-File Staging Guidance: Context-aware tooltips guide authors to stage files when multiple unstaged documents exist across the workspace.
  • Commit Inspection Dialog: Review all staged and auto-staged files, inspect unstaged modification warnings, and generate AI-assisted commit titles and descriptions based on staged diffs.

9. Chapter Manifest Summarization

  • One-Click Manifest Updates: Dedicated modal generates concise single-paragraph summaries (40–70 words) for chapter manifests (CHAPTERS.md).
  • Immediate Git Staging: Optional one-click staging checkbox immediately stages updated manifest files upon saving.

10. Pure Event-Driven External Git Synchronization (Zero Polling)

  • Instant Window Focus Sync: Automatically synchronizes workspace Git status and baseline diffs whenever switching back to Margin from GitKraken, terminal, or external IDEs.
  • Zero Idle CPU & Network Overhead: Operates purely on window focus and visibility events with zero background interval timers or polling loops.

11. Transparent AI Telemetry

  • Telemetry Inspection Modal: View token consumption (prompt, output, total), execution latency, system prompts, user prompts, and raw model outputs for all AI assistant operations, commit message generations, and chapter summaries.

- Add workspace creation in `FileStorageService` initializing standard
  project outline (`chapters/`, `characters/`, `styles/`, `prompts/`, `outputs/`)
  and essential starter templates (`CHAPTERS.md`, `chapter-1.md`, `CHARACTERS.md`,
  `protagonist.md`, `STYLES.md`, style guides, `story_state.yaml`).
- Add optional Git repository initialization with `.gitignore` generation,
  automatically disabled when Git is not available in PATH.
- Add `POST /api/workspace/create` and `GET /api/workspace/git-status` endpoints.
- Unify native folder picker into a single dialog with foreground focus
- Add "Create New Workspace" section to General settings in `SettingsModal`.
- Add a workspace switcher icon button next to the New Folder button at the
  top of `FileSidebar`.
- Add unit tests covering workspace creation, file generation, Git init,
  and API endpoints in `tests/test_workspace_create.py`.
Generated by Antigravity.
- Add display-only active selection highlighting via
ProseMirror inline view decorations with theme-adaptive styling across all themes.
- Auto-target enclosing paragraph when focusing prompt box without an active selection (and cursor not between whitespace).
- Repurpose bubble menu '+ Margin' button to stage selection as a chip, apply display highlight, dismiss the bubble menu, and jump focus to the sidebar prompt.
- Refine writing bubble menu rewrite mode lifecycle to reset on selection change, click-outside, or Escape.
- Add dynamic inline placeholder support in the prompt box when selection or file chips are attached.
Implemented using Antigravity.
- Implement display-only real-time diff highlighting (additions and deletions) in TipTap editor via ProseMirror decorations.
- Add workspace-aware diff baseline resolution with git index/HEAD support for git repos and .margin-shadow copies for non-git workspaces.
- Add token/word-level LCS diff algorithm with intra-word character-level refinement for typos and affixes.
- Add bottom-left Stage/Snapshot button with dynamic enable/disable state based on document diffs.
- Support AI selection replacement review with contiguous deleted/inserted blocks and floating Accept/Reject controls.
- Suppress baseline diff decorations and keep Stage/Snapshot button disabled during active AI change reviews.
- Handle new/untracked documents cleanly without showing diffs until initial staging/snapshotting.
- Add global settings and document-level quick toggles for showing/hiding additions and deletions.
- Add theme-adaptive styling and color variables across all 10 theme variants.
- Implement similarity-weighted sequence alignment DP in 
- Optimize typing and backspacing latency by caching parsed baseline documents, trimming common block prefixes and suffixes in O(1) time, pre-tokenizing modified slices, and deferring store updates via queueMicrotask.
- Isolate the editor bottom scroll container from the Stage/Snapshot,
- Enhance diff algorithm with block-level insertion detection and whitespace-aware token matching to prevent word interweaving during phrase replacements.
- Fix AI edit preview to render replaced text as strikethrough deletions before additions and ensure only targeted selections or new paragraphs are highlighted.
- Updated bottom bar controls for Staging/Snapshotting, a confirmation modal for Restoring baselines, and a Git Commit dialog with AI-generated commit titles and descriptions.
- Make Additions and Deletions toggle buttons compact icon-only controls with informative tooltips.
- Add comprehensive test suite in ChangeHighlight.test.ts covering block insertions, multi-paragraph additions, deletions, rewrites, and performance edge cases.
- Add centralized `saveCurrentFile` helper with support for dirty checks, keepalive requests, and force saves.
- Support `Mod+S` (`Ctrl+S` / `Cmd+S`) global keyboard shortcut with `preventDefault()` to trigger instant disk saves without browser dialogs.
- Add 2000ms debounced idle auto-save in TipTap's `onUpdate` to keep keystroke latency zero while persisting changes once typing pauses.
- Flush pending changes on editor blur, window blur, and `visibilitychange === 'hidden'`.
- Trigger automatic document saves immediately prior to executing SimpleAssist prompts, chat queries, and inline rewrites so backend agents always inspect fresh disk content.
- Register `beforeunload` and `pagehide` safety nets with `fetch({ keepalive: true })` to persist unsaved edits on sudden window close or page refresh.
Persist active document context, pending AI edit previews, and scroll positions across reloads and computer sleep. Add manifest summarization to generate and update chapter summaries with optional auto-staging. Add LLM telemetry viewers for prompts, raw outputs, and token usage with stable dialog dimensions. Enhance workspace file status indicators for modified and staged files, commit dialog validation, and low-overhead external state synchronization on window focus.
Create snapshot files for template documents in new non-git workspace to prevent them from showing as modified.
Fixed issue with files in non-git workspace not having the modified indicator cleared when manually reverted to being unchanged.
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