Make Git a native feature with an off switch

- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions.
- Add Settings → Features and the features settings section.
- Add features_legacy. It reads the old plugin packages and changes nothing.
- Move Git from the plugin into src/lib/features/git/, on host internals.
- Remove api.git, the git contribution key, and the SDK Git types.
- Add pnpm check:features. It fails when a feature module loads at start.
- Update the tests, the menu inventory, the docs, and UI-055.
This commit is contained in:
Knotty Wyvern
2026-10-29 15:51:21 -07:00
parent 58f77b2e9f
commit d3218b2501
68 changed files with 2068 additions and 324 deletions
+30 -6
View File
@@ -62,7 +62,8 @@ Windows is the primary platform. macOS and Linux builds are experimental.
| `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. |
| `git.rs` | The Git service of the Git feature. It runs the `git` program. |
| `features.rs` | Reads the old plugin packages of the native features one time, for the switch migration. It changes no plugin file. |
| `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 |
@@ -87,7 +88,9 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
| `settings/` | The settings store (`store.ts`), and the code that moves the old browser values to the settings file (`migration.ts`) |
| `plugins/` | The plugin runtime, the host types (`sdk.ts`, which also exports the SDK types), and Settings → Plug-ins |
| `browser/` | The interface of the built-in browser |
| `completion/`, `git/` | Contracts and services that plugins use |
| `features/` | The native features with an off switch: the catalog (`catalog.ts`), the switches (`state.ts`), the first-start migration, the loader, and one folder for each feature (`git/`). See [Native features](#native-features). |
| `completion/` | Contracts and services that plugins use |
| `git/` | The Git service and its types, for the Git feature and the line history in the status bar |
| `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 |
@@ -131,13 +134,14 @@ On macOS, it is `~/Library/Application Support/<identifier>/`. On Linux, it is `
"appearance": { "theme": "default", "mode": "dark" },
"customThemes": [],
"customThemesLegacy": [],
"language": "en"
"language": "en",
"features": { "git": true }
}
```
| Rule | Detail |
| --- | --- |
| Sections | `general`, `appearance`, `customThemes`, `customThemesLegacy` (the original version 1 themes), and `language`. The host does not interpret their values. The frontend normalizes each section. |
| Sections | `general`, `appearance`, `customThemes`, `customThemesLegacy` (the original version 1 themes), `language`, and `features` (the switches of the native features). The host does not interpret their values. The frontend normalizes each section. |
| Size | At most 8 MiB in total. The appearance can hold an image data URL of up to 3,000,000 characters. |
| Writes | `settings_write` replaces one section. The host writes a complete temporary file and renames it. Then it sends `settings-changed` to all windows with the section, the revision, and the value. |
| Damaged file | The host moves the file to `settings.corrupt-<seconds>.json` and writes a new file with the defaults. The first window that reads the settings shows a message one time. |
@@ -152,7 +156,7 @@ After that, `src/lib/settings/store.ts` reads the sections from memory and tells
- Workspace documents stay ordinary local files. Users keep access to them when plugins are disabled.
- The core includes Markdown table editing, rendering, and table formulas.
- 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.
- Built-in features with an off switch live in `src/lib/features/`. Other 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:
@@ -177,6 +181,7 @@ Run these commands from the repository folder. They do not need an installer.
| `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). |
| `pnpm check:features` | A full build. It fails when a native feature module loads at start. See [Native features](#native-features). |
To run one test file, use `node --experimental-strip-types --import ./tests/unit/_svelte/register.mjs --test tests/unit/tables/selection.spec.ts`.
The `--import` hook compiles `.svelte.ts` modules, so a test can import them.
@@ -199,6 +204,25 @@ All text that a user reads goes through the catalog in `src/lib/i18n/messages.ts
Errors of the plugin API stay in English, because they are for plugin developers.
`pnpm check` runs `scripts/i18nAudit.mjs`. It fails for a key that the catalog does not have, a catalog key that the code does not use, and a row without all translations.
## Native features
Git is a native feature: host code with an off switch in **Settings → Features**. It does not use the plugin API.
| Part | File |
| --- | --- |
| The catalog: ID, old plugin ID, name, views, and commands | `src/lib/features/catalog.ts` |
| The switches: the `features` settings section | `src/lib/features/state.ts` |
| The first start: each switch takes the state of the old plugin package | `src/lib/features/migration.ts` and `src-tauri/src/features.rs` |
| One import at first need in each window | `src/lib/features/loader.ts` |
| Views and commands in the workbench | `src/lib/features/session.ts` and `src/lib/plugins/external.ts` |
| The feature code | `src/lib/features/<feature>/index.ts` and its components |
- The catalog holds only static data, so the main bundle stays small. The feature code loads when the user first opens a view, a tab, or a command of the feature. An off feature loads nothing.
- Host code never imports a feature folder statically. `pnpm check:features` builds the app. It fails when a feature module, or a library that only a feature needs, is in a chunk that loads at start.
- Saved tabs and tab transfers keep the ID of the old plugin package as the owner ID, for example `runestone.git`. `builtInPackages` in `external.ts` lists the old package, so it never loads.
- Off stops the feature at once in each window and closes its views. The loaded module stays in memory until the window reloads.
- To add a feature, add its entry to `catalog.ts`, its import to `loader.ts`, its folder to `FEATURE_FOLDERS` in `scripts/featureChunks.mjs`, and its old plugin ID to `LEGACY_PACKAGES` in `src-tauri/src/features.rs`.
## Plugin SDK
The plugin SDK in `packages/plugin-sdk/` is the only source of the public plugin types.
@@ -241,7 +265,7 @@ A test states what it needs near its top. The runner skips the test, with the re
| Line | Requirement |
| --- | --- |
| `// @requires plugin:terminal` | The compiled Terminal plugin |
| `// @requires repo:RuneStone_Git/dist` | A file or folder in a sibling plugin checkout |
| `// @requires repo:RuneStone_Local_Autocomplete/src` | 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. |