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
+7 -8
View File
@@ -36,20 +36,20 @@ async function hostApi(services: Partial<SessionServices>, views = false) {
test("feature checks find optional members, and missing members give an update message", () => {
const read = async () => new Uint8Array([1]);
const api = { workspace: { readBytes: read }, git: { status: async () => ({}) } } as unknown as PluginApi;
const api = { workspace: { readBytes: read }, services: { get: () => null } } as unknown as PluginApi;
assert.equal(hasFeature(api, "workspace.readBytes"), true);
assert.equal(hasFeature(api, "git"), true);
assert.equal(hasFeature(api, "git.push"), false);
assert.equal(hasFeature(api, "services"), true);
assert.equal(hasFeature(api, "workspace.subscribe"), false);
assert.equal(hasFeature(api, "pty"), false);
assert.deepEqual(missingFeatures(api, ["pty", "workspace.readBytes", "settings.subscribe"]), ["pty", "settings.subscribe"]);
assert.equal(requireFeature(api, "git"), (api as unknown as { git: unknown }).git);
assert.equal(requireFeature(api, "services"), (api as unknown as { services: unknown }).services);
assert.throws(() => requireFeature(api, "pty"), (error: unknown) => error instanceof MissingFeatureError
&& error.name === "MissingFeatureError" && error.features.length === 1 && error.features[0] === "pty"
&& error.message === "This plugin needs the terminal API (api.pty). Update RuneStone to a version that has this feature.");
assert.throws(() => requireFeatures(api, ["pty", "files", "workspace.readBytes"]), {
message: "This plugin needs the terminal API (api.pty) and the folder grant API (api.files). Update RuneStone to a version that has these features.",
});
assert.doesNotThrow(() => requireFeatures(api, ["git", "workspace.readBytes"]));
assert.doesNotThrow(() => requireFeatures(api, ["services", "workspace.readBytes"]));
assert.throws(() => hasFeature(api, "workspace.read" as never), TypeError);
assert.equal(describeFeature("ui.showActionMenu"), "the shared action menu (api.ui.showActionMenu)");
assert.equal(API_VERSION, 1);
@@ -65,10 +65,9 @@ test("a required function stays bound to its parent object", async () => {
test("the current host gives every SDK feature when all services are present", async () => {
const pty = { open: async () => {}, write: async () => {}, resize: async () => {}, close: async () => {}, profiles: async () => [], openWindow: async () => {}, dictation: async () => {} };
const files = { chooseFolder: async () => null, pictureFolder: async () => ({ id: "g", path: "p", name: "n" }), grants: async () => [], revoke: async () => false, list: async () => [], readBytes: async () => new Uint8Array(), readSidecar: async () => null, writeSidecar: async () => {} };
const git = { status: async () => ({ available: true, repository: true, branch: null, changes: [] }), diff: async () => "", stage: async () => {}, unstage: async () => {}, commit: async () => {}, push: async () => {}, pull: async () => {}, graph: async () => ({ commits: [] }), commitDetails: async () => ({ id: "", parents: [], author: "", date: "", message: "", files: [] }), commitDiff: async () => "", blame: async () => null };
const backgrounds = { chooseFolder: async () => null, list: async () => [], read: async () => new Uint8Array() };
const { api, session } = await hostApi({
pty, files, git, backgrounds, serviceHub: new ServiceHub(), openFile: async () => {}, completionTransport: async () => {},
pty, files, backgrounds, serviceHub: new ServiceHub(), openFile: async () => {}, completionTransport: async () => {},
workspace: { ...base.workspace, listMarkdown: async () => [], readMany: async () => [], readBytes: async () => new Uint8Array(), readOptional: async () => null, create: async () => {}, subscribe: () => () => {} },
settings: { ...base.settings, subscribe: () => () => {} },
}, true);
@@ -79,7 +78,7 @@ test("the current host gives every SDK feature when all services are present", a
test("the host without optional services lacks only the features that depend on them", async () => {
const { api, session } = await hostApi({});
assert.deepEqual(missingFeatures(api, pluginFeatures).sort(), [
"backgrounds", "closeView", "completion.transport", "files", "git", "git.commitDetails", "git.commitDiff", "git.graph", "git.pull", "git.push",
"backgrounds", "closeView", "completion.transport", "files",
"openFile", "pty", "renameDocument", "replaceDocumentWithView", "replaceView", "settings.subscribe",
"workspace.create", "workspace.listMarkdown", "workspace.readBytes", "workspace.readMany", "workspace.readOptional", "workspace.subscribe",
]);