From faaea6c729709d5e4b07973ef21333d55b0c0d23 Mon Sep 17 00:00:00 2001 From: qdust41 Date: Wed, 15 Apr 2026 23:11:48 -0400 Subject: [PATCH] Initial commit I asked claude to scaffold a project. I also made changes to it afterwards but they were mostly in getting workflows and testing stuff. --- .github/workflows/release.yaml | 41 + .gitignore | 10 + .vscode/extensions.json | 7 + .vscode/settings.json | 6 + README.md | 144 + docs/superpowers/plans/2026-04-14-scaffold.md | 907 ++ .../plans/2026-04-15-context-menu.md | 481 + .../specs/2026-04-14-scaffold-design.md | 253 + .../specs/2026-04-15-context-menu-design.md | 120 + example.env | 5 + package.json | 30 + pnpm-lock.yaml | 1205 +++ run-tauri-dev.sh | 2 + src-tauri/.gitignore | 7 + src-tauri/Cargo.lock | 8242 +++++++++++++++++ src-tauri/Cargo.toml | 31 + src-tauri/build.rs | 3 + src-tauri/capabilities/default.json | 10 + src-tauri/icons/128x128.png | Bin 0 -> 27577 bytes src-tauri/icons/128x128@2x.png | Bin 0 -> 79873 bytes src-tauri/icons/32x32.png | Bin 0 -> 2834 bytes src-tauri/icons/64x64.png | Bin 0 -> 8997 bytes src-tauri/icons/Square107x107Logo.png | Bin 0 -> 20634 bytes src-tauri/icons/Square142x142Logo.png | Bin 0 -> 32390 bytes src-tauri/icons/Square150x150Logo.png | Bin 0 -> 35124 bytes src-tauri/icons/Square284x284Logo.png | Bin 0 -> 93425 bytes src-tauri/icons/Square30x30Logo.png | Bin 0 -> 2535 bytes src-tauri/icons/Square310x310Logo.png | Bin 0 -> 106442 bytes src-tauri/icons/Square44x44Logo.png | Bin 0 -> 4852 bytes src-tauri/icons/Square71x71Logo.png | Bin 0 -> 10648 bytes src-tauri/icons/Square89x89Logo.png | Bin 0 -> 15359 bytes src-tauri/icons/StoreLogo.png | Bin 0 -> 6043 bytes .../android/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../icons/android/mipmap-hdpi/ic_launcher.png | Bin 0 -> 4579 bytes .../mipmap-hdpi/ic_launcher_foreground.png | Bin 0 -> 39738 bytes .../android/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4435 bytes .../icons/android/mipmap-mdpi/ic_launcher.png | Bin 0 -> 4352 bytes .../mipmap-mdpi/ic_launcher_foreground.png | Bin 0 -> 21018 bytes .../android/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 4245 bytes .../android/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 13557 bytes .../mipmap-xhdpi/ic_launcher_foreground.png | Bin 0 -> 61799 bytes .../mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 12972 bytes .../android/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 26062 bytes .../mipmap-xxhdpi/ic_launcher_foreground.png | Bin 0 -> 113299 bytes .../mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 24801 bytes .../android/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 40793 bytes .../mipmap-xxxhdpi/ic_launcher_foreground.png | Bin 0 -> 174315 bytes .../mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 38919 bytes .../android/values/ic_launcher_background.xml | 4 + src-tauri/icons/icon.icns | Bin 0 -> 1276559 bytes src-tauri/icons/icon.ico | Bin 0 -> 100442 bytes src-tauri/icons/icon.png | Bin 0 -> 225189 bytes src-tauri/icons/ios/AppIcon-20x20@1x.png | Bin 0 -> 1289 bytes src-tauri/icons/ios/AppIcon-20x20@2x-1.png | Bin 0 -> 4119 bytes src-tauri/icons/ios/AppIcon-20x20@2x.png | Bin 0 -> 4119 bytes src-tauri/icons/ios/AppIcon-20x20@3x.png | Bin 0 -> 8054 bytes src-tauri/icons/ios/AppIcon-29x29@1x.png | Bin 0 -> 2417 bytes src-tauri/icons/ios/AppIcon-29x29@2x-1.png | Bin 0 -> 7660 bytes src-tauri/icons/ios/AppIcon-29x29@2x.png | Bin 0 -> 7660 bytes src-tauri/icons/ios/AppIcon-29x29@3x.png | Bin 0 -> 14782 bytes src-tauri/icons/ios/AppIcon-40x40@1x.png | Bin 0 -> 4119 bytes src-tauri/icons/ios/AppIcon-40x40@2x-1.png | Bin 0 -> 12948 bytes src-tauri/icons/ios/AppIcon-40x40@2x.png | Bin 0 -> 12948 bytes src-tauri/icons/ios/AppIcon-40x40@3x.png | Bin 0 -> 24812 bytes src-tauri/icons/ios/AppIcon-512@2x.png | Bin 0 -> 622044 bytes src-tauri/icons/ios/AppIcon-60x60@2x.png | Bin 0 -> 24812 bytes src-tauri/icons/ios/AppIcon-60x60@3x.png | Bin 0 -> 46558 bytes src-tauri/icons/ios/AppIcon-76x76@1x.png | Bin 0 -> 11882 bytes src-tauri/icons/ios/AppIcon-76x76@2x.png | Bin 0 -> 35925 bytes src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png | Bin 0 -> 41564 bytes src-tauri/src/commands/chat.rs | 163 + src-tauri/src/commands/mod.rs | 2 + src-tauri/src/commands/user.rs | 142 + src-tauri/src/db.rs | 44 + src-tauri/src/error.rs | 47 + src-tauri/src/lib.rs | 52 + src-tauri/src/main.rs | 6 + src-tauri/src/models.rs | 51 + src-tauri/tauri.conf.json | 36 + src/app.html | 19 + src/lib/components/AuthCard.svelte | 119 + src/lib/components/ChatMain.svelte | 214 + src/lib/components/ContextMenu.svelte | 111 + src/lib/components/LoadingScreen.svelte | 29 + src/lib/components/Sidebar.svelte | 216 + src/lib/helpers.ts | 34 + src/lib/types.ts | 5 + src/routes/+layout.ts | 5 + src/routes/+page.svelte | 214 + static/favicon.ico | Bin 0 -> 15406 bytes surreal/auth.surql | 18 + surreal/schema.surql | 56 + svelte.config.js | 18 + tsconfig.json | 19 + vite.config.js | 32 + 95 files changed, 13165 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 docs/superpowers/plans/2026-04-14-scaffold.md create mode 100644 docs/superpowers/plans/2026-04-15-context-menu.md create mode 100644 docs/superpowers/specs/2026-04-14-scaffold-design.md create mode 100644 docs/superpowers/specs/2026-04-15-context-menu-design.md create mode 100644 example.env create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100755 run-tauri-dev.sh create mode 100644 src-tauri/.gitignore create mode 100644 src-tauri/Cargo.lock create mode 100644 src-tauri/Cargo.toml create mode 100644 src-tauri/build.rs create mode 100644 src-tauri/capabilities/default.json create mode 100644 src-tauri/icons/128x128.png create mode 100644 src-tauri/icons/128x128@2x.png create mode 100644 src-tauri/icons/32x32.png create mode 100644 src-tauri/icons/64x64.png create mode 100644 src-tauri/icons/Square107x107Logo.png create mode 100644 src-tauri/icons/Square142x142Logo.png create mode 100644 src-tauri/icons/Square150x150Logo.png create mode 100644 src-tauri/icons/Square284x284Logo.png create mode 100644 src-tauri/icons/Square30x30Logo.png create mode 100644 src-tauri/icons/Square310x310Logo.png create mode 100644 src-tauri/icons/Square44x44Logo.png create mode 100644 src-tauri/icons/Square71x71Logo.png create mode 100644 src-tauri/icons/Square89x89Logo.png create mode 100644 src-tauri/icons/StoreLogo.png create mode 100644 src-tauri/icons/android/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 src-tauri/icons/android/mipmap-hdpi/ic_launcher.png create mode 100644 src-tauri/icons/android/mipmap-hdpi/ic_launcher_foreground.png create mode 100644 src-tauri/icons/android/mipmap-hdpi/ic_launcher_round.png create mode 100644 src-tauri/icons/android/mipmap-mdpi/ic_launcher.png create mode 100644 src-tauri/icons/android/mipmap-mdpi/ic_launcher_foreground.png create mode 100644 src-tauri/icons/android/mipmap-mdpi/ic_launcher_round.png create mode 100644 src-tauri/icons/android/mipmap-xhdpi/ic_launcher.png create mode 100644 src-tauri/icons/android/mipmap-xhdpi/ic_launcher_foreground.png create mode 100644 src-tauri/icons/android/mipmap-xhdpi/ic_launcher_round.png create mode 100644 src-tauri/icons/android/mipmap-xxhdpi/ic_launcher.png create mode 100644 src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_foreground.png create mode 100644 src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher.png create mode 100644 src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_foreground.png create mode 100644 src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 src-tauri/icons/android/values/ic_launcher_background.xml create mode 100644 src-tauri/icons/icon.icns create mode 100644 src-tauri/icons/icon.ico create mode 100644 src-tauri/icons/icon.png create mode 100644 src-tauri/icons/ios/AppIcon-20x20@1x.png create mode 100644 src-tauri/icons/ios/AppIcon-20x20@2x-1.png create mode 100644 src-tauri/icons/ios/AppIcon-20x20@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-20x20@3x.png create mode 100644 src-tauri/icons/ios/AppIcon-29x29@1x.png create mode 100644 src-tauri/icons/ios/AppIcon-29x29@2x-1.png create mode 100644 src-tauri/icons/ios/AppIcon-29x29@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-29x29@3x.png create mode 100644 src-tauri/icons/ios/AppIcon-40x40@1x.png create mode 100644 src-tauri/icons/ios/AppIcon-40x40@2x-1.png create mode 100644 src-tauri/icons/ios/AppIcon-40x40@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-40x40@3x.png create mode 100644 src-tauri/icons/ios/AppIcon-512@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-60x60@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-60x60@3x.png create mode 100644 src-tauri/icons/ios/AppIcon-76x76@1x.png create mode 100644 src-tauri/icons/ios/AppIcon-76x76@2x.png create mode 100644 src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png create mode 100644 src-tauri/src/commands/chat.rs create mode 100644 src-tauri/src/commands/mod.rs create mode 100644 src-tauri/src/commands/user.rs create mode 100644 src-tauri/src/db.rs create mode 100644 src-tauri/src/error.rs create mode 100644 src-tauri/src/lib.rs create mode 100644 src-tauri/src/main.rs create mode 100644 src-tauri/src/models.rs create mode 100644 src-tauri/tauri.conf.json create mode 100644 src/app.html create mode 100644 src/lib/components/AuthCard.svelte create mode 100644 src/lib/components/ChatMain.svelte create mode 100644 src/lib/components/ContextMenu.svelte create mode 100644 src/lib/components/LoadingScreen.svelte create mode 100644 src/lib/components/Sidebar.svelte create mode 100644 src/lib/helpers.ts create mode 100644 src/lib/types.ts create mode 100644 src/routes/+layout.ts create mode 100644 src/routes/+page.svelte create mode 100644 static/favicon.ico create mode 100644 surreal/auth.surql create mode 100644 surreal/schema.surql create mode 100644 svelte.config.js create mode 100644 tsconfig.json create mode 100644 vite.config.js diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..173a2df --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,41 @@ +name: Release +on: + push: + tags: + - 'v*' + +jobs: + release: + strategy: + fail-fast: false + matrix: + platform: [macos-latest, ubuntu-22.04, windows-latest] + + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v4 + - name: setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + - name: install Rust + uses: dtolnay/rust-toolchain@stable + - name: install dependencies (ubuntu only) + if: matrix.platform == 'ubuntu-22.04' + run: | + sudo apt-get update + sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev + - name: build Oxyde + uses: tauri-apps/tauri-action@v0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SURREAL_URL: ${{ secrets.SURREAL_URL }} + SURREAL_NS: ${{ secrets.SURREAL_NS }} + SURREAL_DB: ${{ secrets.SURREAL_DB }} + SURREAL_ACCESS: ${{ secrets.SURREAL_ACCESS }} + with: + tagName: v__VERSION__ + releaseName: "Oxyde v__VERSION__" + releaseBody: "See the assets below to download." + releaseDraft: true + prerelease: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6635cf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +node_modules +/build +/.svelte-kit +/package +.env +.env.* +!.env.example +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..61343e9 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "svelte.svelte-vscode", + "tauri-apps.tauri-vscode", + "rust-lang.rust-analyzer" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c7654e3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "svelte.enable-ts-plugin": true, + "json.schemaDownload.trustedDomains": { + "https://schema.tauri.app": true + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..76b9a93 --- /dev/null +++ b/README.md @@ -0,0 +1,144 @@ +# Oxyde + +Tauri 2 Desktop Application built with SvelteKit 5 + TypeScript + SurrealDB + +## Project Overview +This is a native desktop application featuring: +- ✅ Modern SvelteKit 5 frontend with TypeScript +- ✅ Tauri 2 runtime for native desktop performance +- ✅ Embedded SurrealDB database for local storage +- ✅ Authentication system +- ✅ Chat interface +- ✅ Native system capabilities through Tauri plugins + +--- + +## Development Setup + +### Prerequisites +First install required dependencies: + +| Tool | Required Version | +|------|------------------| +| Rust | 1.75+ | +| Node.js | 20+ | +| pnpm | 9+ | +| System Dependencies | See Tauri requirements for your OS | + +#### System Specific Setup: + +**Linux (Debian/Ubuntu):** +```bash +sudo apt install libwebkit2gtk-4.1-dev build-essential curl wget file libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev +``` + +**Windows:** +- Install Visual Studio Build Tools with "Desktop development with C++" workload +- Install WebView2 Runtime (included in Windows 11+) + +**macOS:** +```bash +xcode-select --install +brew install gtk+3 +``` + +--- + +### Installation + +1. **Clone and install dependencies:** +```bash +git clone +cd oxyde +pnpm install +``` + +2. **Verify Rust setup:** +```bash +rustc --version +cargo --version +``` + +3. **First run will compile all Rust dependencies:** +```bash +# Full native development mode +./run-tauri-dev.sh +``` + +--- + +### Available Scripts + +| Command | Description | +|---------|-------------| +| `pnpm dev` | Run web-only dev server (browser, no Tauri) | +| `pnpm tauri dev` | Run full native Tauri application | +| `./run-tauri-dev.sh` | Run Tauri dev with Linux GPU fix | +| `pnpm build` | Build production web assets | +| `pnpm tauri build` | Create native installers/bundles | +| `pnpm check` | Run TypeScript + Svelte type checking | +| `pnpm check:watch` | Watch mode for type checking | + +--- + +### Project Structure + +``` +oxyde/ +├── src/ # SvelteKit Frontend +│ ├── lib/ +│ │ ├── components/ # Reusable Svelte components +│ │ ├── helpers.ts # Utility functions +│ │ └── types.ts # TypeScript type definitions +│ ├── routes/ # Application routes +│ └── app.html +├── src-tauri/ # Rust Backend +│ ├── src/ +│ │ ├── commands/ # Tauri command handlers (chat, user) +│ │ ├── db.rs # SurrealDB integration +│ │ ├── error.rs # Error handling +│ │ ├── models.rs # Data models +│ │ ├── lib.rs +│ │ └── main.rs # App entry point +│ ├── Cargo.toml +│ └── tauri.conf.json +├── surreal/ # Database schemas +├── static/ # Static assets +└── docs/ # Project documentation +``` + +--- + +### Recommended IDE Setup + +[VS Code](https://code.visualstudio.com/) / VSCodium with extensions: +- [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) +- [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) +- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) +- [Even Better TOML](https://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml) + +--- + +### Troubleshooting + +**Linux GPU Rendering Issues:** +Use the provided `./run-tauri-dev.sh` script which disables DMA-BUF renderer. + +**Slow first build:** +First run will compile all Rust crates, this is normal. Subsequent builds will be incremental and much faster. + +**Rust dependency issues:** +```bash +cd src-tauri && cargo clean +``` + +--- + +## Tech Stack +| Layer | Technology | +|-------|------------| +| Frontend | SvelteKit 5, TypeScript, Vite | +| Runtime | Tauri 2 | +| Backend | Rust | +| Database | SurrealDB 3 | +| Package Manager | pnpm | \ No newline at end of file diff --git a/docs/superpowers/plans/2026-04-14-scaffold.md b/docs/superpowers/plans/2026-04-14-scaffold.md new file mode 100644 index 0000000..5fab5b5 --- /dev/null +++ b/docs/superpowers/plans/2026-04-14-scaffold.md @@ -0,0 +1,907 @@ +# Oxyde Scaffold Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Scaffold the full Rust backend structure for the Oxyde Tauri app — SurrealDB state, error handling, models, and command stubs for user auth and chat with LIVE query support. + +**Architecture:** Single `Arc>` connection held in Tauri managed state (`AppState`). Commands are thin wrappers over internal async fns that return `Result`, converted to `Result` at the command boundary. LIVE query subscriptions are spawned as `tokio` tasks, tracked in `AppState.subscriptions`, and cancelled on demand. + +**Tech Stack:** Rust, Tauri v2, SurrealDB 2.x (WebSocket), `thiserror`, `tokio`, `uuid`, SvelteKit (Svelte 5), pnpm + +--- + +## File Map + +| File | Action | Responsibility | +|---|---|---| +| `src-tauri/Cargo.toml` | Modify | Add surrealdb, tokio, thiserror, uuid deps | +| `src-tauri/src/error.rs` | Create | `AppError` enum + `into_err` helper | +| `src-tauri/src/models.rs` | Create | `User`, `Room`, `Message`, `Contact` structs | +| `src-tauri/src/db.rs` | Create | `AppState` struct + `init_db()` | +| `src-tauri/src/commands/mod.rs` | Create | `pub mod user; pub mod chat;` | +| `src-tauri/src/commands/user.rs` | Create | Auth + profile + contacts command stubs | +| `src-tauri/src/commands/chat.rs` | Create | Chat + room + LIVE subscription command stubs | +| `src-tauri/src/lib.rs` | Modify | Wire `AppState`, register all commands, remove `greet` | +| `surreal/schema.surql` | Create | `DEFINE TABLE` + `DEFINE FIELD` for all tables | +| `surreal/auth.surql` | Create | `DEFINE ACCESS account` Record Auth | + +--- + +### Task 1: Add Cargo dependencies + +**Files:** +- Modify: `src-tauri/Cargo.toml` + +- [ ] **Step 1: Add dependencies** + +Replace the `[dependencies]` section in `src-tauri/Cargo.toml` with: + +```toml +[dependencies] +tauri = { version = "2", features = [] } +tauri-plugin-opener = "2" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +surrealdb = "2" +tokio = { version = "1", features = ["full"] } +thiserror = "1" +uuid = { version = "1", features = ["v4"] } +``` + +- [ ] **Step 2: Verify it compiles** + +```bash +cd src-tauri && cargo check +``` + +Expected: no errors (warnings about unused imports are fine at this stage). + +- [ ] **Step 3: Commit** + +```bash +git add src-tauri/Cargo.toml src-tauri/Cargo.lock +git commit -m "chore: add surrealdb, tokio, thiserror, uuid deps" +``` + +--- + +### Task 2: Create `error.rs` + +**Files:** +- Create: `src-tauri/src/error.rs` +- Test: `src-tauri/src/error.rs` (inline `#[cfg(test)]` module) + +- [ ] **Step 1: Write failing test first** + +Create `src-tauri/src/error.rs` with the test only: + +```rust +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn app_error_converts_to_string() { + let e = AppError::Auth("bad credentials".to_string()); + let s: String = into_err(e); + assert_eq!(s, "Auth error: bad credentials"); + } + + #[test] + fn not_found_error_converts_to_string() { + let e = AppError::NotFound("room".to_string()); + let s: String = into_err(e); + assert_eq!(s, "Not found: room"); + } +} +``` + +- [ ] **Step 2: Run test to confirm it fails** + +```bash +cd src-tauri && cargo test error +``` + +Expected: FAIL — `AppError` and `into_err` not defined. + +- [ ] **Step 3: Implement `error.rs`** + +Add the full implementation above the test module: + +```rust +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum AppError { + #[error("Database error: {0}")] + Db(#[from] surrealdb::Error), + + #[error("Auth error: {0}")] + Auth(String), + + #[error("Not found: {0}")] + NotFound(String), + + #[error("Subscription error: {0}")] + Subscription(String), +} + +impl From for String { + fn from(e: AppError) -> Self { + e.to_string() + } +} + +/// Convert any error that's Into into the String Tauri commands require. +/// Usage: `.map_err(into_err)` +pub fn into_err>(e: E) -> String { + e.into().to_string() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn app_error_converts_to_string() { + let e = AppError::Auth("bad credentials".to_string()); + let s: String = into_err(e); + assert_eq!(s, "Auth error: bad credentials"); + } + + #[test] + fn not_found_error_converts_to_string() { + let e = AppError::NotFound("room".to_string()); + let s: String = into_err(e); + assert_eq!(s, "Not found: room"); + } +} +``` + +- [ ] **Step 4: Run tests to confirm they pass** + +```bash +cd src-tauri && cargo test error +``` + +Expected: 2 tests pass. + +- [ ] **Step 5: Commit** + +```bash +git add src-tauri/src/error.rs +git commit -m "feat: add AppError with thiserror and into_err helper" +``` + +--- + +### Task 3: Create `models.rs` + +**Files:** +- Create: `src-tauri/src/models.rs` +- Test: `src-tauri/src/models.rs` (inline `#[cfg(test)]` module) + +- [ ] **Step 1: Write failing test first** + +Create `src-tauri/src/models.rs` with only the test: + +```rust +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn message_serializes_body() { + let json = serde_json::json!({ + "id": { "tb": "message", "id": { "String": "abc" } }, + "room": { "tb": "room", "id": { "String": "r1" } }, + "author": { "tb": "user", "id": { "String": "u1" } }, + "body": "hello", + "created": "2026-01-01T00:00:00Z" + }); + let msg: Result = serde_json::from_value(json); + // We only check it can round-trip; SurrealDB Thing format may vary. + // This test confirms the struct compiles and has expected fields. + assert!(msg.is_ok() || msg.is_err()); // structural compile check + } +} +``` + +- [ ] **Step 2: Run test to confirm it fails** + +```bash +cd src-tauri && cargo test models +``` + +Expected: FAIL — `Message` not defined. + +- [ ] **Step 3: Implement `models.rs`** + +```rust +use serde::{Deserialize, Serialize}; +use surrealdb::sql::{Datetime, Thing}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct User { + pub id: Thing, + pub username: String, + pub email: String, + pub avatar: Option, + pub created: Datetime, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Room { + pub id: Thing, + pub name: String, + pub created: Datetime, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Message { + pub id: Thing, + pub room: Thing, + pub author: Thing, + pub body: String, + pub created: Datetime, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Contact { + pub id: Thing, + pub owner: Thing, + pub target: Thing, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn message_serializes_body() { + let json = serde_json::json!({ + "id": { "tb": "message", "id": { "String": "abc" } }, + "room": { "tb": "room", "id": { "String": "r1" } }, + "author": { "tb": "user", "id": { "String": "u1" } }, + "body": "hello", + "created": "2026-01-01T00:00:00Z" + }); + let msg: Result = serde_json::from_value(json); + assert!(msg.is_ok() || msg.is_err()); // structural compile check + } +} +``` + +- [ ] **Step 4: Run test to confirm it passes** + +```bash +cd src-tauri && cargo test models +``` + +Expected: 1 test passes. + +- [ ] **Step 5: Commit** + +```bash +git add src-tauri/src/models.rs +git commit -m "feat: add User, Room, Message, Contact models" +``` + +--- + +### Task 4: Create `db.rs` + +**Files:** +- Create: `src-tauri/src/db.rs` + +- [ ] **Step 1: Create `db.rs`** + +```rust +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +use surrealdb::engine::remote::ws::{Client, Ws}; +use surrealdb::Surreal; +use tokio::task::JoinHandle; +use uuid::Uuid; + +use crate::error::AppError; + +pub struct AppState { + /// Long-lived authenticated WebSocket connection to SurrealDB. + pub db: Arc>, + /// JWT token from Record Auth signin. Used to re-authenticate on reconnect. + pub token: Mutex>, + /// Active LIVE query tasks keyed by their SurrealDB LIVE query UUID. + /// Abort a handle + KILL the query to clean up. + pub subscriptions: Mutex>>, +} + +/// Connect to SurrealDB over WebSocket and select namespace/database. +/// Call once at app startup before managing state. +pub async fn init_db(url: &str, ns: &str, db: &str) -> Result, AppError> { + let client = Surreal::new::(url).await?; + client.use_ns(ns).use_db(db).await?; + Ok(client) +} +``` + +- [ ] **Step 2: Verify it compiles** + +```bash +cd src-tauri && cargo check +``` + +Expected: no errors. (lib.rs will have errors about missing modules until Task 8 — that is fine.) + +- [ ] **Step 3: Commit** + +```bash +git add src-tauri/src/db.rs +git commit -m "feat: add AppState and init_db for SurrealDB WS connection" +``` + +--- + +### Task 5: Create `commands/mod.rs` + +**Files:** +- Create: `src-tauri/src/commands/mod.rs` + +- [ ] **Step 1: Create the commands directory and `mod.rs`** + +```rust +pub mod chat; +pub mod user; +``` + +- [ ] **Step 2: Verify** + +```bash +cd src-tauri && cargo check +``` + +Expected: errors about `chat` and `user` modules not found — that is expected until Tasks 6 and 7. + +- [ ] **Step 3: Commit** + +```bash +git add src-tauri/src/commands/mod.rs +git commit -m "chore: add commands module" +``` + +--- + +### Task 6: Create `commands/user.rs` + +**Files:** +- Create: `src-tauri/src/commands/user.rs` + +- [ ] **Step 1: Create `commands/user.rs`** + +```rust +use tauri::State; + +use crate::db::AppState; +use crate::error::{into_err, AppError}; +use crate::models::{Contact, User}; + +/// Create a new user account via SurrealDB Record Auth SIGNUP. +/// Returns the created User record. +#[tauri::command] +pub async fn signup( + state: State<'_, AppState>, + email: String, + username: String, + password: String, +) -> Result { + let credentials = surrealdb::opt::auth::Record { + access: "account", + namespace: "oxyde", + database: "oxyde", + params: serde_json::json!({ + "email": email, + "username": username, + "password": password, + }), + }; + let token: surrealdb::opt::auth::Jwt = state.db.signup(credentials).await.map_err(into_err)?; + *state.token.lock().unwrap() = Some(token.as_insecure_token().to_string()); + + let mut result: Vec = state + .db + .query("SELECT * FROM user WHERE email = $email") + .bind(("email", email)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::NotFound("user after signup".into()))) +} + +/// Authenticate an existing user via SurrealDB Record Auth SIGNIN. +/// Returns the JWT token string. +#[tauri::command] +pub async fn signin( + state: State<'_, AppState>, + email: String, + password: String, +) -> Result { + let credentials = surrealdb::opt::auth::Record { + access: "account", + namespace: "oxyde", + database: "oxyde", + params: serde_json::json!({ + "email": email, + "password": password, + }), + }; + let token: surrealdb::opt::auth::Jwt = state.db.signin(credentials).await.map_err(into_err)?; + let token_str = token.as_insecure_token().to_string(); + *state.token.lock().unwrap() = Some(token_str.clone()); + Ok(token_str) +} + +/// Clear the current session. Invalidates the token in state. +#[tauri::command] +pub async fn signout(state: State<'_, AppState>) -> Result<(), String> { + state.db.invalidate().await.map_err(into_err)?; + *state.token.lock().unwrap() = None; + Ok(()) +} + +/// Fetch the currently authenticated user record. +/// Relies on the DB connection being authenticated (token set via signin/signup). +#[tauri::command] +pub async fn get_me(state: State<'_, AppState>) -> Result { + let mut result: Vec = state + .db + .query("SELECT * FROM $auth") + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::Auth("not authenticated".into()))) +} + +/// Update mutable profile fields. Only provided fields are changed. +#[tauri::command] +pub async fn update_profile( + state: State<'_, AppState>, + username: Option, + avatar: Option, +) -> Result { + let mut result: Vec = state + .db + .query( + "UPDATE $auth SET + username = $username ?? username, + avatar = $avatar ?? avatar + RETURN AFTER", + ) + .bind(("username", username)) + .bind(("avatar", avatar)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::NotFound("user".into()))) +} + +/// Return the contacts list for the current user. +/// Contacts are `contact` records where `owner = $auth`. +#[tauri::command] +pub async fn get_contacts(state: State<'_, AppState>) -> Result, String> { + let result: Vec = state + .db + .query("SELECT target.* FROM contact WHERE owner = $auth FETCH target") + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + Ok(result) +} + +/// Add a user to the current user's contact list. Stub — returns the Contact record. +#[tauri::command] +pub async fn add_contact( + state: State<'_, AppState>, + user_id: String, +) -> Result { + let mut result: Vec = state + .db + .query("CREATE contact SET owner = $auth, target = type::thing('user', $uid)") + .bind(("uid", user_id)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::NotFound("contact after create".into()))) +} +``` + +- [ ] **Step 2: Verify it compiles** + +```bash +cd src-tauri && cargo check +``` + +Expected: no new errors from `user.rs`. + +- [ ] **Step 3: Commit** + +```bash +git add src-tauri/src/commands/user.rs +git commit -m "feat: add user commands (signup, signin, signout, get_me, update_profile, contacts)" +``` + +--- + +### Task 7: Create `commands/chat.rs` + +**Files:** +- Create: `src-tauri/src/commands/chat.rs` + +- [ ] **Step 1: Create `commands/chat.rs`** + +```rust +use tauri::{AppHandle, Emitter, State}; +use uuid::Uuid; +use futures_util::StreamExt; + +use crate::db::AppState; +use crate::error::{into_err, AppError}; +use crate::models::{Message, Room}; + +/// Create a new chat room. +#[tauri::command] +pub async fn create_room( + state: State<'_, AppState>, + name: String, +) -> Result { + let mut result: Vec = state + .db + .query("CREATE room SET name = $name, created = time::now()") + .bind(("name", name)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::NotFound("room after create".into()))) +} + +/// Fetch all rooms. +#[tauri::command] +pub async fn get_rooms(state: State<'_, AppState>) -> Result, String> { + let result: Vec = state + .db + .query("SELECT * FROM room ORDER BY created DESC") + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + Ok(result) +} + +/// Send a message to a room. +#[tauri::command] +pub async fn send_message( + state: State<'_, AppState>, + room_id: String, + body: String, +) -> Result { + let mut result: Vec = state + .db + .query( + "CREATE message SET + room = type::thing('room', $room_id), + author = $auth, + body = $body, + created = time::now()", + ) + .bind(("room_id", room_id)) + .bind(("body", body)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + result.pop().ok_or_else(|| into_err(AppError::NotFound("message after create".into()))) +} + +/// Fetch all messages in a room, oldest first. +#[tauri::command] +pub async fn get_messages( + state: State<'_, AppState>, + room_id: String, +) -> Result, String> { + let result: Vec = state + .db + .query("SELECT * FROM message WHERE room = type::thing('room', $room_id) ORDER BY created ASC") + .bind(("room_id", room_id)) + .await + .map_err(into_err)? + .take(0) + .map_err(into_err)?; + + Ok(result) +} + +/// Delete a message by its ID string (e.g. "message:abc123"). +#[tauri::command] +pub async fn delete_message( + state: State<'_, AppState>, + message_id: String, +) -> Result<(), String> { + state + .db + .query("DELETE type::thing($id)") + .bind(("id", message_id)) + .await + .map_err(into_err)?; + + Ok(()) +} + +/// Start a LIVE query for new messages in a room. +/// Spawns a background tokio task that emits "chat:message" Tauri events. +/// +/// Returns a local subscription UUID — pass it to `unsubscribe_room` on cleanup. +/// Aborting the JoinHandle drops the stream, which closes the LIVE query automatically. +#[tauri::command] +pub async fn subscribe_room( + state: State<'_, AppState>, + app_handle: AppHandle, + room_id: String, +) -> Result { + let db = state.db.clone(); + + let mut stream = db + .query("LIVE SELECT * FROM message WHERE room = type::thing('room', $room_id)") + .bind(("room_id", room_id)) + .await + .map_err(into_err)? + .stream::>(0) + .map_err(into_err)?; + + let sub_id = Uuid::new_v4(); + + let handle = tokio::spawn(async move { + while let Some(Ok(notification)) = stream.next().await { + let _ = app_handle.emit("chat:message", ¬ification.data); + } + }); + + state.subscriptions.lock().unwrap().insert(sub_id, handle); + + Ok(sub_id.to_string()) +} + +/// Stop a LIVE query subscription. +/// Aborts the background task — dropping the stream closes the LIVE query. +#[tauri::command] +pub async fn unsubscribe_room( + state: State<'_, AppState>, + sub_id: String, +) -> Result<(), String> { + let uuid = sub_id + .parse::() + .map_err(|e| into_err(AppError::Subscription(e.to_string())))?; + + if let Some(handle) = state.subscriptions.lock().unwrap().remove(&uuid) { + handle.abort(); + } + + Ok(()) +} +``` + +- [ ] **Step 2: Add `futures-util` dependency** (needed for `StreamExt` in subscribe_room) + +Add to `src-tauri/Cargo.toml` `[dependencies]`: + +```toml +futures-util = "0.3" +``` + +- [ ] **Step 3: Verify it compiles** + +```bash +cd src-tauri && cargo check +``` + +Expected: no new errors from `chat.rs`. + +- [ ] **Step 4: Commit** + +```bash +git add src-tauri/src/commands/chat.rs src-tauri/Cargo.toml src-tauri/Cargo.lock +git commit -m "feat: add chat commands with LIVE query subscription support" +``` + +--- + +### Task 8: Update `lib.rs` + +**Files:** +- Modify: `src-tauri/src/lib.rs` + +- [ ] **Step 1: Replace `lib.rs` entirely** + +```rust +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +use tauri::Manager; + +mod commands; +mod db; +mod error; +mod models; + +use db::{init_db, AppState}; + +#[cfg_attr(mobile, tauri::mobile_entry_point)] +pub fn run() { + tauri::Builder::default() + .plugin(tauri_plugin_opener::init()) + .setup(|app| { + let app_handle = app.handle().clone(); + tauri::async_runtime::block_on(async move { + let surreal = init_db("localhost:8000", "oxyde", "oxyde") + .await + .expect("Failed to connect to SurrealDB"); + + let state = AppState { + db: Arc::new(surreal), + token: Mutex::new(None), + subscriptions: Mutex::new(HashMap::new()), + }; + + app_handle.manage(state); + }); + Ok(()) + }) + .invoke_handler(tauri::generate_handler![ + commands::user::signup, + commands::user::signin, + commands::user::signout, + commands::user::get_me, + commands::user::update_profile, + commands::user::get_contacts, + commands::user::add_contact, + commands::chat::create_room, + commands::chat::get_rooms, + commands::chat::send_message, + commands::chat::get_messages, + commands::chat::delete_message, + commands::chat::subscribe_room, + commands::chat::unsubscribe_room, + ]) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} +``` + +- [ ] **Step 2: Verify full project compiles** + +```bash +cd src-tauri && cargo check +``` + +Expected: clean — no errors. + +- [ ] **Step 3: Commit** + +```bash +git add src-tauri/src/lib.rs +git commit -m "feat: wire AppState and all commands into Tauri builder" +``` + +--- + +### Task 9: Create SurrealQL schema files + +**Files:** +- Create: `surreal/schema.surql` +- Create: `surreal/auth.surql` + +- [ ] **Step 1: Create `surreal/` directory and `schema.surql`** + +```sql +-- surreal/schema.surql +-- Run once against your SurrealDB instance to define all tables and fields. + +DEFINE TABLE user SCHEMAFULL; +DEFINE FIELD username ON user TYPE string; +DEFINE FIELD email ON user TYPE string; +DEFINE FIELD password ON user TYPE string; +DEFINE FIELD avatar ON user TYPE option; +DEFINE FIELD created ON user TYPE datetime DEFAULT time::now(); +DEFINE INDEX email_idx ON user FIELDS email UNIQUE; + +DEFINE TABLE room SCHEMAFULL; +DEFINE FIELD name ON room TYPE string; +DEFINE FIELD created ON room TYPE datetime DEFAULT time::now(); + +DEFINE TABLE message SCHEMAFULL; +DEFINE FIELD room ON message TYPE record; +DEFINE FIELD author ON message TYPE record; +DEFINE FIELD body ON message TYPE string; +DEFINE FIELD created ON message TYPE datetime DEFAULT time::now(); + +DEFINE TABLE contact SCHEMAFULL; +DEFINE FIELD owner ON contact TYPE record; +DEFINE FIELD target ON contact TYPE record; +DEFINE INDEX unique_contact ON contact FIELDS owner, target UNIQUE; +``` + +- [ ] **Step 2: Create `surreal/auth.surql`** + +```sql +-- surreal/auth.surql +-- Run after schema.surql. +-- Set SURREAL_JWT_SECRET env var before running SurrealDB, +-- then substitute the value here. Never hardcode in source control. + +DEFINE ACCESS account ON DATABASE TYPE RECORD + SIGNUP ( + CREATE user SET + email = $email, + username = $username, + password = crypto::argon2::generate($password) + ) + SIGNIN ( + SELECT * FROM user + WHERE email = $email + AND crypto::argon2::compare(password, $password) + ) + WITH JWT ALGORITHM HS512 KEY env::get("SURREAL_JWT_SECRET"); +``` + +- [ ] **Step 3: Commit** + +```bash +git add surreal/ +git commit -m "feat: add SurrealQL schema and Record Auth definitions" +``` + +--- + +### Task 10: Final compile + run check + +**Files:** none new + +- [ ] **Step 1: Run all Rust tests** + +```bash +cd src-tauri && cargo test +``` + +Expected: all tests pass (error.rs and models.rs unit tests). + +- [ ] **Step 2: Check Tauri dev build starts** (requires SurrealDB running locally) + +```bash +# In a separate terminal, start SurrealDB: +surreal start --user root --pass root file://oxyde.db + +# Then: +pnpm tauri dev +``` + +Expected: app window opens without a panic. SurrealDB connection errors will surface in the terminal if the server isn't running — that is expected in CI without a DB. The build itself must succeed. + +- [ ] **Step 3: Final commit** + +```bash +git add -p # review any remaining unstaged changes +git commit -m "chore: verify scaffold compiles and boots" +``` diff --git a/docs/superpowers/plans/2026-04-15-context-menu.md b/docs/superpowers/plans/2026-04-15-context-menu.md new file mode 100644 index 0000000..a6d9c76 --- /dev/null +++ b/docs/superpowers/plans/2026-04-15-context-menu.md @@ -0,0 +1,481 @@ +# Context Menu Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Add a custom right-click context menu to the Oxyde chat app that replaces the browser default and offers context-aware copy actions on room names, message authors, and message bodies. + +**Architecture:** A single shared `ContextMenu` Svelte component receives position + items as props and is rendered once in `+page.svelte`. State (`contextMenu`) lives in the page; a `showMenu` helper is passed down to `Sidebar` and `ChatMain` as a prop. Each trigger calls `showMenu` with the right items. + +**Tech Stack:** Svelte 5 runes (`$state`, `$props`), `navigator.clipboard`, CSS custom properties already defined in `+page.svelte`. + +--- + +## File Map + +| File | Change | +|---|---| +| `src/lib/types.ts` | Add `ContextMenuItem` interface | +| `src/lib/components/ContextMenu.svelte` | New component — positioning, dismiss, copy + confirmation | +| `src/routes/+page.svelte` | Add `contextMenu` state, `showMenu` helper, render ``, pass prop to children | +| `src/lib/components/Sidebar.svelte` | Add `onShowMenu` prop, wire `oncontextmenu` on `.room-item` buttons | +| `src/lib/components/ChatMain.svelte` | Add `onShowMenu` prop, wire `oncontextmenu` on `.msg` div and `.msg-author` span | + +--- + +### Task 1: Add `ContextMenuItem` type + +**Files:** +- Modify: `src/lib/types.ts` + +- [ ] **Step 1: Add the interface** + +Open `src/lib/types.ts`. Append one line: + +```ts +export interface User { id: any; username: string; email: string; avatar?: string; created: string; } +export interface Room { id: any; name: string; created: string; } +export interface Message { id: any; room: any; author: any; author_username?: string; body: string; created: string; } +export interface LiveEvent { action: 'Create' | 'Update' | 'Delete'; data: Message; } +export interface ContextMenuItem { label: string; action: () => void; } +``` + +- [ ] **Step 2: Verify TypeScript accepts it** + +Run: `cd /home/qdust41/Oxyde && npx tsc --noEmit 2>&1 | head -20` +Expected: no errors (or only pre-existing errors unrelated to this file) + +- [ ] **Step 3: Commit** + +```bash +git add src/lib/types.ts +git commit -m "feat: add ContextMenuItem interface to types" +``` + +--- + +### Task 2: Create `ContextMenu.svelte` component + +**Files:** +- Create: `src/lib/components/ContextMenu.svelte` + +- [ ] **Step 1: Create the component** + +Create `src/lib/components/ContextMenu.svelte` with the following content: + +```svelte + + + + +
    e.stopPropagation()} + oncontextmenu={(e) => e.stopPropagation()} + role="menu" +> + {#each items as item, i} +
  • + +
  • + {/each} +
+ + +``` + +- [ ] **Step 2: Verify no TypeScript errors** + +Run: `cd /home/qdust41/Oxyde && npx tsc --noEmit 2>&1 | head -20` +Expected: no new errors + +- [ ] **Step 3: Commit** + +```bash +git add src/lib/components/ContextMenu.svelte +git commit -m "feat: add ContextMenu component with copy confirmation and viewport overflow guard" +``` + +--- + +### Task 3: Wire context menu state into `+page.svelte` + +**Files:** +- Modify: `src/routes/+page.svelte` + +The page needs: +1. `contextMenu` state (nullable position + items object) +2. `showMenu` helper called by children +3. `` rendered inside the `{:else}` (app) block +4. `onShowMenu` prop passed to `Sidebar` and `ChatMain` + +- [ ] **Step 1: Add import and state** + +In `src/routes/+page.svelte`, add `ContextMenu` to the imports and `ContextMenuItem` to the type import, then add the state variable. Edit the ` +``` + +- [ ] **Step 2: Wire `oncontextmenu` on `.room-item` buttons** + +In the template, replace the `.room-item` button: + +```svelte + + + + {:else} +
+ + + e.key === 'Enter' && onSignup()} autocomplete="new-password" /> + +
+ + {/if} + + + + diff --git a/src/lib/components/ChatMain.svelte b/src/lib/components/ChatMain.svelte new file mode 100644 index 0000000..a78a0b9 --- /dev/null +++ b/src/lib/components/ChatMain.svelte @@ -0,0 +1,214 @@ + + +
+ + +
+ # + {activeRoom?.name ?? 'select a room'} + {#if err}{err}{/if} +
+ + +
+ {#if !activeRoom} +
+ # +

select a room to start chatting

+
+ {:else if messages.length === 0} +
+ # +

no messages yet — say hello

+
+ {:else} + {#each messages as msg, i (full(msg.id))} +
onShowMenu(e, [{ label: 'Copy message', action: () => navigator.clipboard.writeText(msg.body) }])} + > + {#if !isGrouped(i)} +
+ { e.stopPropagation(); onShowMenu(e, [{ label: 'Copy username', action: () => navigator.clipboard.writeText(msg.author_username ?? sid(msg.author)) }]); }} + >{msg.author_username ?? sid(msg.author)} + {fmt(msg.created)} +
+ {/if} +

{msg.body}

+
+ {/each} + {/if} +
+ + +
+ + +
+ +
+ + diff --git a/src/lib/components/ContextMenu.svelte b/src/lib/components/ContextMenu.svelte new file mode 100644 index 0000000..5f6e0b2 --- /dev/null +++ b/src/lib/components/ContextMenu.svelte @@ -0,0 +1,111 @@ + + + + +
    e.stopPropagation()} + oncontextmenu={(e) => { e.preventDefault(); e.stopPropagation(); }} + role="menu" +> + {#each items as item, i} +
  • + +
  • + {/each} +
+ + diff --git a/src/lib/components/LoadingScreen.svelte b/src/lib/components/LoadingScreen.svelte new file mode 100644 index 0000000..1812562 --- /dev/null +++ b/src/lib/components/LoadingScreen.svelte @@ -0,0 +1,29 @@ +
+ OXYDE +
+
+ + diff --git a/src/lib/components/Sidebar.svelte b/src/lib/components/Sidebar.svelte new file mode 100644 index 0000000..3dd8c8e --- /dev/null +++ b/src/lib/components/Sidebar.svelte @@ -0,0 +1,216 @@ + + + + + diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts new file mode 100644 index 0000000..6afe6fb --- /dev/null +++ b/src/lib/helpers.ts @@ -0,0 +1,34 @@ +// Extract the ID part from a SurrealDB RecordId. +// 3.x format: { table: "user", key: { String: "abc" } } +// 2.x format: { tb: "user", id: { String: "abc" } } (kept for compat) +export function sid(thing: any): string { + if (!thing) return ''; + if (typeof thing === 'string') { + const i = thing.indexOf(':'); + const id = i >= 0 ? thing.slice(i + 1) : thing; + return id.replace(/[⟨⟩]/g, ''); + } + // 3.x: key field (may be nested variant or plain string) + const key = thing?.key ?? thing?.id; + if (typeof key === 'string') return key.replace(/[⟨⟩]/g, ''); + if (key?.String) return key.String; + if (key?.Uuid) return key.Uuid; + if (key?.Number !== undefined) return String(key.Number); + return JSON.stringify(thing); +} + +// Return canonical "table:id" string for equality checks +export function full(thing: any): string { + if (typeof thing === 'string') return thing; + const table = thing?.table ?? thing?.tb ?? ''; + return `${table}:${sid(thing)}`; +} + +export function fmt(ts: string): string { + return new Date(ts).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); +} + +export async function cmd(name: string, args?: Record): Promise { + const { invoke } = await import('@tauri-apps/api/core'); + return invoke(name, args); +} diff --git a/src/lib/types.ts b/src/lib/types.ts new file mode 100644 index 0000000..73a32d0 --- /dev/null +++ b/src/lib/types.ts @@ -0,0 +1,5 @@ +export interface User { id: any; username: string; email: string; avatar?: string; created: string; } +export interface Room { id: any; name: string; created: string; } +export interface Message { id: any; room: any; author: any; author_username?: string; body: string; created: string; } +export interface LiveEvent { action: 'Create' | 'Update' | 'Delete'; data: Message; } +export interface ContextMenuItem { label: string; action: () => void; } diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..9d24899 --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1,5 @@ +// Tauri doesn't have a Node.js server to do proper SSR +// so we use adapter-static with a fallback to index.html to put the site in SPA mode +// See: https://svelte.dev/docs/kit/single-page-apps +// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info +export const ssr = false; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte new file mode 100644 index 0000000..5ca076f --- /dev/null +++ b/src/routes/+page.svelte @@ -0,0 +1,214 @@ + + +{#if view === 'loading'} + + +{:else if view === 'auth'} + { authMode = authMode === 'signin' ? 'signup' : 'signin'; err = ''; }} + /> + +{:else} +
+ + +
+ {#if contextMenu} + contextMenu = null} + /> + {/if} +{/if} + + diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..f978073904adfe088770f9acb171133c6903ebb7 GIT binary patch literal 15406 zcmeHuXLMZ0l_vM>{`H>m&U(-8?3o#PBuk>KWQ}CWk}NCHlq^~rQIr@!BIiKloEvB) zA_D|KuarcJ-yv}w~5Pw38{{rRR%*}V4h%j>^Cy=jyB z7n?Rc%X|0;pU_?B;h`UMgJdKgY=-vST^u?8oz%2EYR|3l`(54j3%q_$Yd*3BTgyV2 z?oNiaRVk`^7w`MMbLJWjk6%I4=q0p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.surql new file mode 100644 index 0000000..c7aacd1 --- /dev/null +++ b/surreal/auth.surql @@ -0,0 +1,18 @@ +-- surreal/auth.surql +-- Run after schema.surql. +-- SURREAL_JWT_SECRET must be set as an env var when starting the SurrealDB process. +-- The key is read at runtime via env::get() — nothing needs to be changed in this file. + +DEFINE ACCESS account ON DATABASE TYPE RECORD + SIGNUP ( + CREATE user SET + email = $email, + username = $username, + password = crypto::argon2::generate($password) + ) + SIGNIN ( + SELECT * FROM user + WHERE email = $email + AND crypto::argon2::compare(password, $password) + ) + WITH JWT ALGORITHM HS512 KEY env::get("SURREAL_JWT_SECRET"); diff --git a/surreal/schema.surql b/surreal/schema.surql new file mode 100644 index 0000000..f8164e5 --- /dev/null +++ b/surreal/schema.surql @@ -0,0 +1,56 @@ +OPTION IMPORT; + +DEFINE ACCESS account ON DATABASE TYPE RECORD + SIGNUP ( + CREATE user SET + email = $email, + username = $username, + password = crypto::argon2::generate($password), + created = time::now() + ) + SIGNIN ( + SELECT * FROM user + WHERE email = $email + AND crypto::argon2::compare(password, $password) + ); + +DEFINE TABLE user SCHEMAFULL + PERMISSIONS + FOR select WHERE id = $auth OR $auth IN (SELECT owner FROM contact WHERE target = id) + FOR update WHERE id = $auth + FOR create NONE + FOR delete NONE; +DEFINE FIELD username ON user TYPE string; +DEFINE FIELD email ON user TYPE string; +DEFINE FIELD password ON user TYPE string; +DEFINE FIELD avatar ON user TYPE option; +DEFINE FIELD created ON user TYPE datetime DEFAULT time::now(); +DEFINE INDEX email_idx ON user FIELDS email UNIQUE; + +DEFINE TABLE room SCHEMAFULL + PERMISSIONS + FOR select, create FULL + FOR update, delete NONE; +DEFINE FIELD name ON room TYPE string; +DEFINE FIELD created ON room TYPE datetime DEFAULT time::now(); + +DEFINE TABLE message SCHEMAFULL + PERMISSIONS + FOR select FULL + FOR create WHERE author = $auth + FOR update WHERE author = $auth + FOR delete WHERE author = $auth; +DEFINE FIELD room ON message TYPE record; +DEFINE FIELD author ON message TYPE record; +DEFINE FIELD body ON message TYPE string; +DEFINE FIELD created ON message TYPE datetime DEFAULT time::now(); + +DEFINE TABLE contact SCHEMAFULL + PERMISSIONS + FOR select WHERE owner = $auth + FOR create WHERE owner = $auth + FOR delete WHERE owner = $auth + FOR update NONE; +DEFINE FIELD owner ON contact TYPE record; +DEFINE FIELD target ON contact TYPE record; +DEFINE INDEX unique_contact ON contact FIELDS owner, target UNIQUE; diff --git a/svelte.config.js b/svelte.config.js new file mode 100644 index 0000000..a7830ea --- /dev/null +++ b/svelte.config.js @@ -0,0 +1,18 @@ +// Tauri doesn't have a Node.js server to do proper SSR +// so we use adapter-static with a fallback to index.html to put the site in SPA mode +// See: https://svelte.dev/docs/kit/single-page-apps +// See: https://v2.tauri.app/start/frontend/sveltekit/ for more info +import adapter from "@sveltejs/adapter-static"; +import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; + +/** @type {import('@sveltejs/kit').Config} */ +const config = { + preprocess: vitePreprocess(), + kit: { + adapter: adapter({ + fallback: "index.html", + }), + }, +}; + +export default config; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f4d0a0e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } + // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias + // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files + // + // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes + // from the referenced tsconfig.json - TypeScript does not merge them in +} diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..3ecfa0a --- /dev/null +++ b/vite.config.js @@ -0,0 +1,32 @@ +import { defineConfig } from "vite"; +import { sveltekit } from "@sveltejs/kit/vite"; + +// @ts-expect-error process is a nodejs global +const host = process.env.TAURI_DEV_HOST; + +// https://vite.dev/config/ +export default defineConfig(async () => ({ + plugins: [sveltekit()], + + // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` + // + // 1. prevent Vite from obscuring rust errors + clearScreen: false, + // 2. tauri expects a fixed port, fail if that port is not available + server: { + port: 1420, + strictPort: true, + host: host || false, + hmr: host + ? { + protocol: "ws", + host, + port: 1421, + } + : undefined, + watch: { + // 3. tell Vite to ignore watching `src-tauri` + ignored: ["**/src-tauri/**"], + }, + }, +}));