This file provides guidance to WARP (warp.dev) when working with code in this repository.
For detailed architectural context, see .docs/summary.md
Individual file summaries are available in .docs/summary-*.md
Terraphim Editor is a Rust+WASM markdown editor with minimal dependencies, offering live preview and distributable as an NPM package in multiple formats (ESM, UMD, IIFE).
trunk serve # Dev server on http://127.0.0.1:8080
trunk serve --port 3000 # Custom port
trunk build --release # Production build (dev workflow)Purpose: Fast Rust/WASM iteration with live reload
./build.sh # Full production build → package/Breakdown:
wasm-pack build --target web— Compiles Rust to WASMnpm install— Installs Vite + pluginsnpm run build— Bundles JS wrapper (ESM/UMD/IIFE)- Assembles
package/directory with npm-ready artifacts
cargo test # Rust unit tests
wasm-pack test --chrome # Browser integration tests (Chrome)
wasm-pack test --firefox # Browser integration tests (Firefox)
cargo bench # Performance benchmarks (Criterion)cargo fmt # Format Rust code
cargo clippy # Lint Rust code
cargo clippy -- -D warnings # Fail on warningsRust Sources:
src/lib.rs— Main WASM library (entry point, markdown conversion)tests/web.rs— Browser-based integration testsbenches/markdown_bench.rs— Performance benchmarks
Configuration:
Cargo.toml— Rust dependencies, dual crate-type (cdylib + rlib)Trunk.toml— Development server config (port 8080, MIME types)package.json— NPM metadata, Vite build scriptsvite.config.js— Library bundler config (multi-format output)build.sh— Production build orchestration
Templates & UI:
templates/editor.html— Rinja template for editor layoutpublic/js/config.js— Editor configuration (shortcuts, commands)public/js/editor.js— Standalone editor class (used by Trunk)public/js/terraphim-editor.js— Library wrapper (used by Vite)
- Development: Trunk compiles Rust → WASM, serves with live reload
- Distribution: wasm-pack + Vite creates multi-format NPM package
- Rust's
run()function auto-executes via#[wasm_bindgen(start)] - Renders Rinja template into
#editor-container - Sets up event listeners for live markdown conversion
- JS wrapper (
TeraphimEditorclass) provides high-level API
User types → Input event → Rust closure → markdown::to_html_with_options() → set_inner_html() → Preview updates
- Edit
public/js/config.js→ Add toshortcutsarray - Specify:
name,key,prefix,suffix,desc - Restart
trunk serveto reload
- Edit
public/js/config.js→ Add tocommandsarray - Specify:
name,icon,prefix,suffix - Icon must be valid Shoelace icon name
- Edit
src/lib.rs→ Updatemarkdown::to_html_with_options()call - Can customize
Optionsstruct for different parsing rules - Test with
cargo testandwasm-pack test --chrome
- Edit
templates/editor.html(Rinja template) - Uses Shoelace web components (
sl-*tags) - Inline styles in
<style>block - Rendered by Rust at runtime
- Add to
Cargo.toml:[profile.release] lto = true codegen-units = 1 opt-level = "z"
- Run
wasm-pack build --target web --release - Consider
wasm-optfor further optimization
- Always use
jiffinstead ofchronofor date/time operations jiffis the preferred crate for temporal functionality
- NEVER use
timeoutcommand - it does not exist on macOS - Use alternative approaches for time-limited operations:
- Use
tmuxwith monitoring instead ofsleep - Implement timeouts in code (Rust or scripts) rather than shell
- Use
- Never use mocks in tests - prefer real implementations and integration tests
- Write tests that validate actual behavior, not mocked responses
- Use browser integration tests (
wasm-pack test) for WASM validation
- Use IDE diagnostics to find and fix errors before committing
- Run
cargo clippy -- -D warningsto catch issues early - Leverage rust-analyzer or similar LSP for real-time feedback
- Always check test coverage after implementation
- Run tests:
cargo test,wasm-pack test --chrome - Validate coverage meets project standards
- Run tests:
- Keep track of all tasks in GitHub issues using
ghtool - Create issues for features, bugs, and improvements:
gh issue create --title "Add feature X" --body "Description" gh issue list --state open
- Commit every change and keep GitHub issues updated:
git commit -m "feat: implement X (fixes #123)" gh issue comment 123 --body "Implemented in commit abc123" gh issue close 123
- Reference issue numbers in commit messages for traceability
- Use
tmuxto spin off background tasks instead of blocking commands - Use
tmuxinstead ofsleepto continue working while processes run - Monitor long-running processes in separate panes:
# Start new tmux session with descriptive name tmux new -s editor-build # Split panes for parallel work tmux split-window -h # Run build in one pane, work in another # Pane 1: ./build.sh # Pane 2: Continue development # Attach to existing session tmux attach -t editor-build # Read log output from background pane tmux capture-pane -t editor-build:0.1 -p
- Example workflow:
- Start
trunk servein tmux pane 1 - Run tests in tmux pane 2
- Continue coding in tmux pane 3
- Switch between panes to check output without interrupting work
- Start
- Minimal production deps: wasm-bindgen, web-sys, markdown, rinja
- Shoelace is peer dependency (consumer controls version)
- Alpha markdown crate (may have breaking changes)
- Use
jifffor date/time (not chrono)
.set_inner_html()
- Should add DOMPurify or equivalent
- See
.docs/summary.mdSection 5 for details
- Target: < 50ms markdown conversion (validated by benchmarks)
- No debouncing (acceptable for documents < 10KB)
- Synchronous rendering (blocks UI thread)
- Requires WebAssembly support (all modern browsers)
- Shoelace components use Shadow DOM
- Tested in Chrome, Firefox (via wasm-pack test)
Rust/WASM:
- Panics logged to browser console via
console_error_panic_hook - Use
web_sys::console::log_1()for debug logging - DevTools → Sources → WASM modules (limited inspection)
JavaScript:
- Standard DevTools, sourcemaps enabled (Vite)
- Console logging in wrapper code
Performance:
- Chrome DevTools → Performance tab
cargo benchfor isolated Rust benchmarks- Browser Performance API in integration tests
terraphim-editor/
├── src/ # Rust source (WASM entry point)
├── tests/ # Browser integration tests
├── benches/ # Performance benchmarks
├── templates/ # Rinja templates
├── public/ # Static assets + examples
│ ├── js/ # JavaScript (config, editor, wrapper)
│ ├── css/ # Styles
│ └── wasm/ # Compiled WASM (from pkg/)
├── dist/ # Build output (Trunk/Vite)
├── pkg/ # wasm-pack artifacts
├── package/ # NPM-ready distribution
├── .docs/ # Architecture documentation
├── Cargo.toml # Rust config
├── Trunk.toml # Dev server config
├── package.json # NPM config
├── vite.config.js # Bundler config
├── build.sh # Production build script
└── index.html # Development entry point
- Comprehensive Summary:
.docs/summary.md(13 sections, deep architectural analysis) - File-Specific Docs:
.docs/summary-*.md(individual file summaries) - README.md: User-facing project overview
- Shoelace Docs: https://shoelace.style/
- wasm-bindgen Guide: https://rustwasm.github.io/wasm-bindgen/
- Trunk Docs: https://trunkrs.dev/