| name | templates-history-implementation |
| description | Implement templates, snapshots, and history for the local-first numpad calculation workspace. |
templates-history-implementation skill
Use this skill when implementing: built-in templates, user-saved templates, document snapshots, history/versioning, or restore flows.
Current state (as of last audit)
- NOT YET IMPLEMENTED — neither templates nor history exist in the codebase.
- Document persistence exists:
src-tauri/src/services/document_repository.rs (SQLite documents table).
- Document model:
src/entities/document/document.types.ts — DocumentModel { id, title, content, createdAt, updatedAt, archivedAt }.
- The workspace store (
workspace.store.ts) has: createDocument, selectDocument, deleteDocument, archiveDocument, saveNow.
Architecture plan for templates
Data model
templates table (SQLite):
id TEXT PRIMARY KEY
title TEXT NOT NULL
content TEXT NOT NULL
is_builtin INTEGER DEFAULT 0 (1 = shipped with app, 0 = user-created)
category TEXT (for filtering: "Finance", "Time", "General", etc.)
created_at INTEGER
updated_at INTEGER
Files to create (templates)
src-tauri/src/services/template_repository.rs ← SQL CRUD for templates
src-tauri/src/commands/templates.rs ← list_templates, get_template, save_template, delete_template
src/features/templates/ ← new feature directory
template.types.ts ← TemplateModel DTO
template.native.ts ← typed invoke wrappers
TemplateBrowser.tsx ← template selection UI
template-builtins.ts ← built-in template definitions
Architecture plan for history/snapshots
Data model
document_history table (SQLite):
id TEXT PRIMARY KEY
document_id TEXT NOT NULL (FK → documents.id)
content TEXT NOT NULL (snapshot of rawText)
snapshot_label TEXT (auto: "Autosave", or user-named)
created_at INTEGER
Files to create (history)
src-tauri/src/services/history_repository.rs ← SQL CRUD for document_history
src-tauri/src/commands/history.rs ← list_history, get_snapshot, restore_snapshot, delete_snapshot
src/features/history/ ← new feature directory
history.types.ts ← DocumentSnapshot DTO
history.native.ts ← typed invoke wrappers
HistoryPanel.tsx ← history list + restore UI
Integration points
- Autosave hook: after
saveDocument in document_service.rs, optionally write a snapshot to document_history.
- Template insert: creates a new document from template content via
createDocument() in workspace store.
- Restore: calls
restore_snapshot command → updates documents content → selectDocument() reloads.
- UI entry: add History and Templates tabs to
WorkspaceInspectorPane.tsx.
Required workflow
- Read
src-tauri/src/services/document_repository.rs — understand current SQL patterns.
- Read
src/entities/document/document.types.ts — understand DocumentModel.
- Read
src/app/store/workspace.store.ts — understand current document lifecycle.
- Write a plan at
ai/codex/plans/templates-history.md before implementing.
- Implement persistence layer (Rust) first, then commands, then TypeScript types, then UI.
- Register new commands in
src-tauri/src/lib.rs.
- Run
cargo check && cargo build after Rust changes.
- Run
npm run typecheck && npm run build after TypeScript changes.
- Update
docs/DATABASE_SCHEMA.md, docs/ARCHITECTURE.md, docs/IMPLEMENTATION_ROADMAP.md.
Constraints
- Local-first — all templates and history are stored in SQLite locally.
- Do not implement collaboration, sync, or conflict resolution.
- Keep UI minimal and task-focused — avoid feature creep.
- Keep future diff/compare support possible by storing full
content snapshots.
- Do not add unit tests unless explicitly requested.
Docs to update
docs/DATABASE_SCHEMA.md — for new tables
docs/ARCHITECTURE.md — for new features and file structure
docs/API_CONTRACTS.md — for new Tauri commands
docs/IMPLEMENTATION_ROADMAP.md — when milestone is complete
docs/STATUS_GAP_ANALYSIS.md — when gaps are resolved