Replace the three error styles with one Error type and one Result alias in error.rs. The error crosses IPC as the same plain string as before. The message text does not change. Move the shared file mechanics to fsutil.rs. These are the reserved-name check, the link and junction check, the limited reads, and the atomic writes. Each module keeps its own path rules, limits, and messages. The plugin settings writer now flushes its file to disk before the rename. Remove the current_root_path and list_entries wrappers and an unused mime value. Use named windows-sys constants for the process, file, drive, and error codes. Add a test that compares the command lists in lib.rs, build.rs, and the capability files. The settings capability must be a subset of the full list. In Cargo.toml, set the author, keep only the rlib crate type, and remove the unused thiserror dependency. Remove panic = "abort" from the release profile. A panic on a worker thread then stops only that thread. It does not stop the editor with unsaved buffers.
219 lines
12 KiB
Markdown
219 lines
12 KiB
Markdown
# Development guide
|
|
|
|
[RuneStone](../README.md) · [Builds](builds.md) · [Releases](releases.md) · [Plugin development](plugin-development.md) · [Interface design](ui-design.md)
|
|
|
|
This guide is for developers who change RuneStone's source code. To use the app, see the [user guide](user-guide.md).
|
|
|
|
## Run from source
|
|
|
|
### Requirements
|
|
|
|
- Node.js 24 or later, and pnpm 10.
|
|
- A current stable Rust toolchain.
|
|
- The [Tauri prerequisites](https://v2.tauri.app/start/prerequisites/) for your platform.
|
|
On Windows, these are the Microsoft C++ Build Tools and WebView2.
|
|
On Linux, use the [Linux development guide](linux.md).
|
|
|
|
### First run
|
|
|
|
1. Clone the repository: `https://git.knottywyvern.com/kwyvern/RuneStone`.
|
|
2. In the repository folder, run `pnpm install --frozen-lockfile`.
|
|
3. Prepare the browser runtime. See [Built-in browser runtime](#built-in-browser-runtime).
|
|
4. Run `pnpm tauri dev`.
|
|
5. In the app, use the folder button to open a test workspace.
|
|
|
|
The first launch compiles the Rust app and its dependencies. Later launches reuse the Cargo cache in `src-tauri/target/`.
|
|
Do not run `cargo clean` as part of normal work.
|
|
|
|
## Daily workflow
|
|
|
|
`pnpm tauri dev` starts Vite on port 1420 through `beforeDevCommand` in `src-tauri/tauri.conf.json`. Then it opens the app in a native window.
|
|
Do not start a separate `pnpm dev` for this workflow.
|
|
|
|
| Change | What happens |
|
|
| --- | --- |
|
|
| Svelte, TypeScript, or CSS in `src/` | Vite updates the window. No Rust build. |
|
|
| Rust code in `src-tauri/src/` | Cargo rebuilds the changed code, and Tauri restarts the app. |
|
|
| Rust dependencies or build settings | Cargo compiles the affected crates. This can take several minutes. |
|
|
| JavaScript dependencies, after a pull | Stop the session, run `pnpm install --frozen-lockfile`, and start it again. |
|
|
| Tauri configuration, capabilities, or Vite configuration | Restart `pnpm tauri dev`. |
|
|
| A plugin in a sibling repository | Build and package that plugin, then install the new ZIP through Settings. See [Build examples](plugin-development.md#build-examples). |
|
|
| Installer or release behavior | Use the [build guide](builds.md). |
|
|
|
|
The app reads and writes real files. Use a test workspace with sample documents.
|
|
Save open documents before a change that restarts the app. A Rust restart ends terminal sessions.
|
|
An installed copy of RuneStone does not show source changes. Use the window that `pnpm tauri dev` opens.
|
|
|
|
To see frontend errors, press Ctrl+Shift+I in the development window to open the web inspector.
|
|
Rust errors appear in the terminal that runs `pnpm tauri dev`.
|
|
|
|
## Architecture
|
|
|
|
RuneStone is a Tauri 2 app. A Rust host gives native services to a Svelte 5 and TypeScript interface.
|
|
CodeMirror drives the Writer view, and Monaco drives the source editor.
|
|
Windows is the primary platform. macOS and Linux builds are experimental.
|
|
|
|
### Desktop host: `src-tauri/src/`
|
|
|
|
| Module | Responsibility |
|
|
| --- | --- |
|
|
| `lib.rs` | App setup, command registration, window events |
|
|
| `error.rs`, `fsutil.rs` | The shared error type, and the shared file mechanics: name and link checks, limited reads, atomic writes |
|
|
| `workspace.rs` | The workspace root of each window, path checks, atomic saves, the file watcher, search |
|
|
| `plugins.rs` | Plugin package review, installation, enable state, removal, and recovery |
|
|
| `plugin_sources.rs` | Plugin downloads from Gitea releases |
|
|
| `git.rs` | The Git service for the Git plugin. It runs the `git` program. |
|
|
| `pty.rs`, `terminal_platform.rs` | Pseudo-terminals for the Terminal plugin |
|
|
| `browser.rs` | The process of the built-in browser engine |
|
|
| `backgrounds.rs` | Background image folders for themes and plugins |
|
|
| `spelling.rs` | Spelling suggestions from the operating system (Windows) |
|
|
| `settings.rs`, `theme.rs` | The Settings window and theme export |
|
|
| `completion.rs` | A local proxy to a completion model server |
|
|
|
|
The interface calls Rust commands through Tauri `invoke`. Most calls go through the wrappers in `src/lib/workspace/api.ts`.
|
|
A new command needs an entry in `generate_handler!` in `lib.rs`, in the command list in `src-tauri/build.rs`, and in the capability files in `src-tauri/capabilities/`.
|
|
|
|
### Interface: `src/lib/`
|
|
|
|
| Folder | Responsibility |
|
|
| --- | --- |
|
|
| `layout/` | The app shell (`Workbench.svelte`), the file tree, tabs, panes, Settings, and dialogs |
|
|
| `editor/` | The Writer view (`LiveWriter.svelte`), the source editor (`EditorHost.svelte`), tables, links, images, and editor menus |
|
|
| `workspace/` | Tauri wrappers, document buffers, the note index and backlinks, paths, and templates |
|
|
| `plugins/` | The plugin runtime, the SDK types (`sdk.ts`), and Settings → Plug-ins |
|
|
| `browser/` | The interface of the built-in browser |
|
|
| `completion/`, `git/` | Contracts and services that plugins use |
|
|
| `theme/` | Appearance settings, palettes, and the theme tokens (`tokens.css`) |
|
|
| `ui/` | Shared menus, pickers, and action icons |
|
|
| `i18n/` | Interface text in English, French, Japanese, and Simplified Chinese |
|
|
|
|
### Other folders
|
|
|
|
| Folder | Content |
|
|
| --- | --- |
|
|
| `browser-runtime/` | The browser engine, its tests, filter lists, and third-party notices |
|
|
| `tests/unit/<area>/` | Unit tests (`*.spec.ts`) that run in Node |
|
|
| `tests/smoke/<area>/` | Browser smoke tests (`*.smoke.mjs`) and their shared harness in `_harness/` |
|
|
| `tests/native/` | Tests that attach to a running desktop app |
|
|
| `scripts/` | Build, release, package, and audit tools, and the smoke test runner |
|
|
| `fixtures/` | A sample workspace (`fixtures/sample/`), a sample plugin, and a completion test page |
|
|
| `design/` | Icon drafts |
|
|
| `docs/` | User and developer documentation |
|
|
|
|
### Where data lives
|
|
|
|
| Data | Location |
|
|
| --- | --- |
|
|
| Documents | Ordinary files in the workspace folder |
|
|
| Workspace state: tab order, pins, bookmarks, templates, Project Management boards | `.runestone/` in the workspace |
|
|
| Installed plugins and their settings | The app data folder. See [plugin storage](plugin-host.md#storage-and-recovery). |
|
|
|
|
## Product boundaries
|
|
|
|
- Workspace documents stay ordinary local files. Users keep access to them when plugins are disabled.
|
|
- The core includes basic Markdown table editing and rendering.
|
|
- Native file access, file watching, search, Git, and terminals belong in Rust.
|
|
- Optional features ship as plugins. The [plugin development reference](plugin-development.md) defines the package format and the API.
|
|
- For sync, prefer a local Git clone. Do not use a live network share as the sync path.
|
|
|
|
These stay outside the product:
|
|
|
|
- A plugin marketplace
|
|
- Compatibility with Obsidian or VS Code plugins
|
|
- Cloud sync, live collaboration, or a mobile app
|
|
- A debugger or a full IDE
|
|
- Automatic commits on save
|
|
|
|
Track plans and roadmaps in RuneStone Project Management, not in these docs.
|
|
|
|
## Checks
|
|
|
|
Run these commands from the repository folder. They do not need an installer.
|
|
|
|
| Command | Checks |
|
|
| --- | --- |
|
|
| `pnpm check` | Svelte and TypeScript types of the app, then of the unit tests (`tests/tsconfig.json`) |
|
|
| `pnpm test` | Unit tests in `tests/unit/` |
|
|
| `cargo test --manifest-path src-tauri/Cargo.toml --lib` | Rust unit tests |
|
|
| `pnpm smoke` | Browser smoke tests. See [Browser smoke tests](#browser-smoke-tests). |
|
|
| `pnpm build` | The production frontend build |
|
|
| `pnpm check:menus` | The inventory of menu surfaces. See [Interface design](ui-design.md). |
|
|
|
|
To run one test file, use `node --experimental-strip-types --test tests/unit/tables/selection.spec.ts`.
|
|
For type errors while you edit, run `pnpm check:watch`.
|
|
|
|
Some tests need files from outside this repository. Without those files, the tests skip and state the reason:
|
|
|
|
- `tests/unit/plugins/plugins.spec.ts` and `tests/unit/tables/formulas.spec.ts` import the compiled Table Formulas package. To run them, run `pnpm build:plugins` first. See [Build examples](plugin-development.md#build-examples).
|
|
- `tests/unit/release/installerVersion.spec.ts` needs the NSIS compiler that the Tauri CLI downloads on Windows.
|
|
- The Rust terminal tests start the real shells on the computer.
|
|
|
|
## Browser smoke tests
|
|
|
|
Smoke tests run the real interface in headless Chromium with a mock of the desktop host.
|
|
They do not replace tests in the native app. Real folder access, file writes, and terminals need `pnpm tauri dev`.
|
|
|
|
| Command | Runs |
|
|
| --- | --- |
|
|
| `pnpm smoke` | All smoke tests, four at a time |
|
|
| `pnpm smoke tabs tables/drag` | The tests whose path contains one of the filters |
|
|
| `pnpm smoke --list` | Nothing. It lists each test, its requirements, and why a test would skip. |
|
|
|
|
The runner starts the Vite server when nothing serves `SMOKE_URL`, and stops it at the end.
|
|
Use `--no-serve` to require a running server, `--jobs <n>` to change the number of parallel tests, and `--timeout <seconds>` to change the limit for each test (default 180).
|
|
After the parallel run, the runner runs each failed test one more time, alone. A test that passes then is reported as `flaky`. It does not fail the run, but the summary lists it. Use `--retries 0` to turn this off.
|
|
Each test writes its output to `output/smoke/logs/<area>__<name>.log`. Screenshots go to `output/smoke/<area>/<name>/`.
|
|
|
|
Playwright is a development dependency. When its own Chromium is not installed, the runner uses an installed Chrome or Edge.
|
|
To use the Playwright browser, run `pnpm exec playwright install chromium`.
|
|
|
|
A test states what it needs near its top. The runner skips the test, with the reason, when a requirement is missing:
|
|
|
|
| Line | Requirement |
|
|
| --- | --- |
|
|
| `// @requires plugin:table-formulas` | `plugin-packages/table-formulas/`. Run `pnpm build:plugins`. |
|
|
| `// @requires plugin:terminal` | The compiled Terminal plugin |
|
|
| `// @requires repo:RuneStone_Git/dist` | A file or folder in a sibling plugin checkout |
|
|
| `// @requires electron` | The browser engine dependencies. Run `npm ci --prefix browser-runtime`. |
|
|
| `// @known-issue <defect>` | The test fails because of a known app defect. The run reports it as `known`. If the test passes, the run fails, so that someone removes the line. |
|
|
|
|
| Variable | Use |
|
|
| --- | --- |
|
|
| `SMOKE_URL` | The frontend address. The default is `http://127.0.0.1:1420`. |
|
|
| `RUNESTONE_PLUGIN_REPOS` | The folder of the sibling plugin checkouts. The default is the parent folder of this repository. |
|
|
| `RUNESTONE_TERMINAL_DIST` | The compiled Terminal plugin. The default is `RuneStone_Terminal/dist` in that folder. |
|
|
| `CHROME_PATH` | A Chromium browser for Playwright |
|
|
| `PLAYWRIGHT_MODULE` | A different Playwright package |
|
|
|
|
To write a smoke test, start from an existing test in the same area. The harness in `tests/smoke/_harness/index.mjs` starts the browser, mocks the Tauri commands, and gives an in-memory workspace.
|
|
A failed test saves `failure.png` in its output folder and prints the page console errors and warnings.
|
|
You can also run one test file directly while `pnpm dev` runs, for example `node tests/smoke/tabs/order.smoke.mjs`.
|
|
|
|
The tests in `tests/native/` attach to a running desktop app through the WebView2 remote-debugging port, and `pnpm smoke` does not run them.
|
|
Set `NATIVE_CDP_URL` to the debugging address, for example `http://127.0.0.1:9224`.
|
|
Before you start the app, set `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=<port>`. Each file states its port and variables at the top.
|
|
|
|
## Built-in browser runtime
|
|
|
|
The browser interface is in `src/lib/browser/`. The browser engine, its tests, and its notices are in `browser-runtime/`.
|
|
The installer includes the staged engine from `src-tauri/browser-engine/`.
|
|
|
|
1. Run `npm ci --prefix browser-runtime`.
|
|
2. Run `pnpm browser:check` and `pnpm browser:test`.
|
|
3. Run `pnpm browser:test:engine` for the native engine tests.
|
|
4. Run `npm --prefix browser-runtime run package`.
|
|
5. Run `pnpm browser:stage` before you build an installer.
|
|
|
|
Each browser window gets a session token at startup. Native requests check that token, and cleanup revokes it.
|
|
|
|
## Development help
|
|
|
|
| Problem | Action |
|
|
| --- | --- |
|
|
| Port 1420 is in use | Stop the other development server, then try again. Vite uses a fixed port. |
|
|
| The window shows the old interface | Look for compile errors in the terminal. Restart `pnpm tauri dev` if necessary. |
|
|
| A page says that desktop features need `pnpm tauri dev` | You opened the Vite server in a browser. Use the native window. |
|
|
| Windows cannot find `link.exe` | Install the C++ build tools and the Windows SDK from the Tauri prerequisites. Open a new terminal. |
|
|
| A smoke test cannot find Chromium | Run `pnpm exec playwright install chromium`, or set `CHROME_PATH` to an installed browser. |
|
|
| `cargo test --offline` reports missing crates | Run the command without `--offline` one time while you are online. |
|