@@ -4,42 +4,104 @@ This file provides guidance to Claude Code when working with the Snowflake codeb
44
55## Project Overview
66
7- Snowflake is a modern AI-powered code editor built with ** Tauri 2** (Rust backend) and ** React 19** (TypeScript frontend). It features a multi-panel IDE-like interface with chat, terminal, file browser, and code review capabilities.
7+ Snowflake is a modern AI-powered code editor built with ** Tauri 2** (Rust backend) and ** React 19** (TypeScript frontend). It features a multi-panel IDE-like interface with chat, terminal, file browser, and code editing capabilities.
88
9- ** Key Technologies: **
9+ ## Technology Stack
1010
11- - ** Frontend:** React 19 + TypeScript + Vite + Tailwind CSS v4
12- - ** Backend:** Tauri 2 (Rust) - _ to be implemented_
13- - ** Editor:** CodeMirror 6 - _ to be implemented_ (currently using Shiki for syntax highlighting)
14- - ** Terminal:** xterm.js
15- - ** State:** Zustand + Immer
11+ ### Frontend
12+
13+ - ** React 19** + TypeScript + Vite
14+ - ** Tailwind CSS v4** for styling
15+ - ** Zustand + Immer** for state management
16+ - ** CodeMirror 6** for code editing with custom themes
17+ - ** xterm.js** for terminal emulation
18+ - ** Shiki** for code block highlighting in chat
19+ - ** Zod** for runtime validation
20+
21+ ### Backend
22+
23+ - ** Tauri 2** for desktop app framework
24+ - ** Rust** workspace with multiple crates
25+ - Planned: Tree-sitter for syntax parsing, portable-pty for terminal
26+
27+ ## Project Structure
28+
29+ ```
30+ Snowflake-v0/
31+ ├── src/ # React frontend (TypeScript)
32+ │ ├── components/ # UI components
33+ │ │ ├── activity/ # File viewer, changes list
34+ │ │ ├── chat/ # Chat interface
35+ │ │ ├── editor/ # CodeMirror editor
36+ │ │ ├── layout/ # Root layout, panels
37+ │ │ ├── terminal/ # xterm.js terminal
38+ │ │ └── ui/ # Radix UI primitives
39+ │ ├── hooks/ # React hooks (Tauri, chat, terminal)
40+ │ ├── providers/ # Context providers
41+ │ ├── stores/ # Zustand state management
42+ │ ├── types/ # TypeScript types & Zod schemas
43+ │ └── lib/ # Utilities (backend API, constants)
44+ │
45+ ├── src-tauri/ # Tauri backend (Rust)
46+ │ ├── src/
47+ │ │ ├── commands/ # Tauri command handlers
48+ │ │ │ ├── files.rs # File operations
49+ │ │ │ ├── terminal.rs # Terminal PTY
50+ │ │ │ ├── lsp.rs # Language server
51+ │ │ │ ├── git.rs # Git operations
52+ │ │ │ ├── ai.rs # Claude API
53+ │ │ │ └── search.rs # Ripgrep search
54+ │ │ ├── lib.rs # Tauri app setup
55+ │ │ └── main.rs # Entry point
56+ │ └── tauri.conf.json # Tauri configuration
57+ │
58+ ├── crates/ # Rust library crates
59+ │ ├── snowflake-core/ # Core types, config, state
60+ │ ├── snowflake-fs/ # File system operations
61+ │ ├── snowflake-terminal/ # PTY management (TODO)
62+ │ ├── snowflake-ai/ # Claude API integration (TODO)
63+ │ ├── snowflake-lsp/ # Language server (TODO)
64+ │ ├── snowflake-git/ # Git operations (TODO)
65+ │ └── snowflake-search/ # Ripgrep search (TODO)
66+ │
67+ └── Cargo.toml # Rust workspace root
68+ ```
1669
1770## Commands
1871
1972``` bash
20- # Development
21- npm run dev # Start dev server (Vite)
73+ # Frontend Development
74+ npm install # Install dependencies
75+ npm run dev # Start Vite dev server (port 5173)
2276npm run build # TypeScript check + production build
2377npm run preview # Preview production build
2478
25- # Quality checks
79+ # Quality Checks
2680npm run typecheck # TypeScript only (tsc --noEmit)
2781npm run lint # ESLint with zero warnings tolerance
2882npm run lint:fix # ESLint with auto-fix
2983npm run check # typecheck + lint
3084npm run ci # Full CI: typecheck + lint + build
31- ```
3285
33- ## Architecture
86+ # Tauri Development
87+ npm run tauri # Start Tauri dev (frontend + Rust backend)
88+ npm run tauri -- dev # Same as above
89+ npm run tauri -- build # Build production Tauri app
3490
35- ### Frontend-Backend Communication
91+ # Rust Development (from project root)
92+ cargo build # Build all crates
93+ cargo test # Run tests
94+ cargo clippy # Lint Rust code
95+ ```
3696
37- The frontend uses a ` useTauri ` hook (` src/hooks/use-tauri.ts ` ) for communication with the Tauri backend. Messages are validated with Zod schemas.
97+ ## Frontend-Backend Communication
98+
99+ ### Tauri Hook (` src/hooks/use-tauri.ts ` )
38100
39101``` typescript
40102// Send message to backend
41103const { postMessage } = useTauri ();
42- postMessage ({ type: ' message:send' , session_id , content });
104+ postMessage ({ type: ' message:send' , uuid , session_id , content });
43105
44106// Listen for backend messages
45107useTauri ({
@@ -51,93 +113,129 @@ useTauri({
51113});
52114```
53115
54- ### State Management
116+ ### Backend API ( ` src/lib/backend.ts ` )
55117
56- - ** Zustand with Immer** for all global state (` src/stores/ ` )
57- - Stores: ` ui-store ` (panels/layout), ` chat-store ` (conversations), ` agent-store ` (task execution), ` terminal-store ` (xterm sessions), ` file-store ` (file tree)
58- - UI dimensions and defaults centralized in ` src/lib/constants.ts `
118+ Direct Tauri invoke calls for file operations, LSP, terminal, git, etc:
59119
60- ### Layout System
120+ ``` typescript
121+ import { readFile , writeFile , listDirectory } from ' @/lib/backend' ;
61122
62- - ` RootLayout ` orchestrates all panels with CSS Grid
63- - Panels: ` LeftSidebar ` (collapsible), ` CenterPanel ` (chat + review split), ` RightSidebar ` (sessions), ` BottomPanel ` (terminal)
64- - Custom ` ResizeHandle ` component for panel resizing
65- - All layout dimensions use constants, applied via inline ` style={{ }} ` (not dynamic Tailwind classes)
123+ // File operations
124+ const content = await readFile ( ' /path/to/file ' );
125+ await writeFile ( ' /path/to/file ' , content );
126+ const entries = await listDirectory ( ' /path/to/dir ' );
66127
67- ### Component Organization
128+ // LSP operations
129+ const completions = await getCompletions (path , line , column );
130+ const hover = await getHover (path , line , column );
68131
69- - ` src/components/layout/ ` - Shell layout components
70- - ` src/components/chat/ ` - Message feed, input, model selector
71- - ` src/components/ui/ ` - Radix UI primitives (shadcn/ui pattern)
72- - ` src/components/shared/ ` - Reusable utilities (timestamp, copy button)
132+ // Terminal operations
133+ const info = await createTerminal ( id , cwd , shell );
134+ await writeTerminal ( id , data );
135+ ```
73136
74- ### Type System
137+ ## CodeMirror Editor
75138
76- - Rich types in ` src/types/ ` for domain models (agent, conversation, message, terminal, file, diff)
77- - Zod schemas colocated with types for runtime validation
78- - Strict TypeScript config with ` noUncheckedIndexedAccess ` , ` exactOptionalPropertyTypes `
139+ The editor (` src/components/editor/CodeMirrorEditor.tsx ` ) provides:
79140
80- ### Custom Hooks
141+ - Full editing with syntax highlighting
142+ - Custom dark/light themes matching app colors
143+ - Language support: TypeScript, JavaScript, Python, Rust, Go, JSON, HTML, CSS, Markdown
144+ - LSP autocompletion integration
145+ - Cmd-S save functionality
146+ - Theme-aware (syncs with app light/dark mode via MutationObserver)
81147
82- - ` use-tauri ` - Tauri backend communication
83- - ` use-chat ` , ` use-agent ` , ` use-terminal ` - Domain-specific state/effects
84- - ` use-keyboard-shortcuts ` - Global hotkeys
85- - ` use-chat-messages ` - Chat message handling with streaming
148+ ### Theme Colors
86149
87- ## Code Style
150+ ** Dark theme:** ` oklch(0.16 0.012 60) ` background with github-dark style syntax
151+ ** Light theme:** ` oklch(0.98 0.005 75) ` background with github-light style syntax
88152
89- ### ESLint Rules (enforced)
153+ ## State Management
90154
91- - ** No ` any ` ** - All unsafe operations are errors
92- - ** Explicit return types** on functions
93- - ** Consistent type imports** - Use ` import type { } ` separately
94- - ** Import order** - External -> Internal -> Types, alphabetized
95- - ** No console.log** - Only ` warn ` /` error ` allowed
96- - ** Strict boolean expressions** - No implicit truthy checks
97- - ** Exhaustive switches** - All cases must be handled
155+ Zustand stores in ` src/stores/ ` :
98156
99- ### Tailwind + Dynamic Styles
157+ | Store | Purpose |
158+ | ------------------- | --------------------------------------- |
159+ | ` ui-store ` | Panel layout, dimensions, active tabs |
160+ | ` chat-store ` | Conversations, messages |
161+ | ` agent-store ` | Task execution state |
162+ | ` terminal-store ` | xterm sessions |
163+ | ` file-store ` | File tree state |
164+ | ` file-viewer-store ` | Open file tabs, content, modified state |
100165
101- - ** Never use dynamic Tailwind classes** like `` `w-[${value}px]` `` - Tailwind can't process them at build
102- - Use inline styles for dynamic dimensions: ` style={{ width: CONTENT_WIDTH.inputBox }} `
103- - Static Tailwind classes work normally: ` w-px ` , ` h-[32px] ` , ` max-w-3xl `
166+ ### File Viewer Store
104167
105- ### React Patterns
168+ Tracks open files with edit state:
106169
107- - Functional components with explicit ` FC ` type
108- - Ternary for conditional rendering (ESLint enforced)
109- - Props interfaces marked ` readonly `
170+ ``` typescript
171+ interface ViewedFile {
172+ path: string ;
173+ content: string ;
174+ originalContent: string ; // For dirty detection
175+ language: string ;
176+ isModified: boolean ; // Shows coral dot on tab when true
177+ viewMode: ' file' | ' diff' ;
178+ }
179+ ```
110180
111181## Protocol Types
112182
113- All message types defined in ` src/types/protocol.ts ` with Zod schemas:
183+ All message types in ` src/types/protocol.ts ` with Zod schemas:
114184
115- ### Frontend -> Backend (WebviewMessage)
185+ ### Frontend → Backend (WebviewMessage)
116186
117187- ` message:send ` - Send chat message
118188- ` file:read ` , ` file:write ` - File operations
119189- ` terminal:create ` , ` terminal:write ` - Terminal operations
190+ - ` agent:stop ` - Stop AI generation
120191
121- ### Backend -> Frontend (ExtensionMessage)
192+ ### Backend → Frontend (ExtensionMessage)
122193
123194- ` agent:chunk ` , ` agent:complete ` - AI responses
124195- ` tool:start ` , ` tool:end ` - Tool execution
125196- ` file:content ` , ` file:tree:response ` - File data
126197- ` terminal:output ` , ` terminal:created ` - Terminal data
127198
128- ## TODO: Tauri Backend Integration
199+ ## Code Style
200+
201+ ### ESLint Rules (enforced)
202+
203+ - ** No ` any ` ** - All unsafe operations are errors
204+ - ** Explicit return types** on functions
205+ - ** Consistent type imports** - Use ` import type { } ` separately
206+ - ** Import order** - External → Internal → Types, alphabetized
207+ - ** No console.log** - Only ` warn ` /` error ` allowed
208+ - ** Strict boolean expressions** - No implicit truthy checks
209+ - ** Exhaustive switches** - All cases must be handled
210+
211+ ### Tailwind + Dynamic Styles
212+
213+ - ** Never use dynamic Tailwind classes** like `` `w-[${value}px]` ``
214+ - Use inline styles for dynamic dimensions: ` style={{ width: value }} `
215+ - Static Tailwind classes work normally: ` w-px ` , ` h-[32px] `
216+
217+ ### React Patterns
218+
219+ - Functional components with explicit ` FC ` type
220+ - Ternary for conditional rendering
221+ - Props interfaces marked ` readonly `
129222
130- The Tauri Rust backend needs to be implemented to handle:
223+ ## Implementation Status
131224
132- - Claude AI integration
133- - File system operations
134- - Terminal PTY management
135- - Session persistence
225+ ### Completed
136226
137- ## TODO: CodeMirror 6 Integration
227+ - [x] Tauri 2 project setup with Rust workspace
228+ - [x] CodeMirror 6 editor with custom themes
229+ - [x] File editing with save (Cmd-S)
230+ - [x] Modified indicator on tabs
231+ - [x] Theme switching (light/dark)
232+ - [x] Frontend-backend communication layer
138233
139- Replace current Shiki-based syntax highlighting with CodeMirror 6 for:
234+ ### TODO (Rust Backend)
140235
141- - Full code editing capabilities
142- - Language server protocol support
143- - Better performance for large files
236+ - [ ] File system operations (snowflake-fs)
237+ - [ ] Terminal PTY management (snowflake-terminal)
238+ - [ ] Claude AI integration (snowflake-ai)
239+ - [ ] Language server protocol (snowflake-lsp)
240+ - [ ] Git operations (snowflake-git)
241+ - [ ] Ripgrep search (snowflake-search)
0 commit comments