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
+68
View File
@@ -0,0 +1,68 @@
// The native features of RuneStone. Each feature has an off switch in Settings → Features.
// This file is in the main bundle, so it holds only small static data: names, views, and commands.
// The code of a feature loads with a dynamic import at first need (see `loader.ts`), and never while its switch is off.
import { message, tr } from "../i18n/index.ts";
import type { PluginView } from "../plugins/sdk.ts";
export type FeatureId = "git";
/** A view of a feature. The workbench shows it as a tab or in the side pane, as it shows a plugin view. */
export interface FeatureViewInfo {
id: string;
/** Returns the title in the current language. */
title: () => string;
placement: "editor" | "sidebar";
icon?: PluginView["icon"];
/** Show a navigation button for the view. */
navigation?: boolean;
}
/** A command of a feature. The command palette lists it. */
export interface FeatureCommandInfo {
id: string;
title: () => string;
icon?: PluginView["icon"];
/** The view that the command opens. */
view: string;
}
export interface FeatureEntry {
id: FeatureId;
/** The ID of the old plugin package. Saved tabs and tab transfers keep it as the owner ID. */
owner: string;
/** Catalog keys for Settings → Features. */
name: string;
description: string;
/** Extra words for the Settings search. */
keywords: string;
/** The switch for a user who never installed the old package. */
defaultOn: boolean;
views: readonly FeatureViewInfo[];
commands: readonly FeatureCommandInfo[];
}
export const FEATURES: readonly FeatureEntry[] = [
{
id: "git", owner: "runestone.git", name: message("Git"),
description: message("Review changes, stage files, commit, and see the commit graph of the workspace repository."),
keywords: "git source control commit stage diff graph branch push pull blame",
defaultOn: true,
views: [
{ id: "source-control", title: () => tr("Source control"), placement: "sidebar", icon: "git", navigation: true },
{ id: "diff", title: () => tr("Git diff"), placement: "editor", icon: "git" },
{ id: "graph", title: () => tr("Git graph"), placement: "editor", icon: "git" },
],
commands: [{ id: "graph", title: () => tr("Show Git graph"), icon: "git", view: "graph" }],
},
];
export function featureEntry(id: FeatureId): FeatureEntry {
const entry = FEATURES.find(item => item.id === id);
if (!entry) throw new Error(`Unknown feature: ${id}`);
return entry;
}
/** The feature that uses `owner` as its owner ID, if any. */
export function featureOfOwner(owner: string): FeatureEntry | undefined {
return FEATURES.find(item => item.owner === owner);
}