feat(ai): add read-only user skill loader for SKILL.md

Refs: #9363
This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-09-22 02:24:23 +08:00
1 parent 6af337e67c
commit 34d8811cd3
36 files changed
+1765 -26

No files matched your search

@@ -0,0 +1,47 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const tauri = readFileSync(new URL("../tauri.ts", import.meta.url), "utf8");
const http = readFileSync(new URL("../http.ts", import.meta.url), "utf8");
const api = readFileSync(new URL("../api.ts", import.meta.url), "utf8");
const tauriRegistry = readFileSync(new URL("../../../../../../src-tauri/src/lib.rs", import.meta.url), "utf8");
const webRegistry = readFileSync(new URL("../../../../../../crates/dbx-web/src/main.rs", import.meta.url), "utf8");
const commandModuleSource = readFileSync(new URL("../../../../../../src-tauri/src/commands/user_skills.rs", import.meta.url), "utf8");
function functionBody(source: string, operation: string): string {
const start = source.indexOf(`export async function ${operation}(`);
expect(start, `${operation} transport function`).toBeGreaterThanOrEqual(0);
const end = source.indexOf("\nexport async function ", start + 1);
return source.slice(start, end === -1 ? source.length : end);
}
describe("user skills transport contract", () => {
it("routes list/read through the desktop Tauri backend", () => {
expect(functionBody(tauri, "listUserSkills")).toContain('invoke("list_user_skills"');
expect(functionBody(tauri, "readUserSkills")).toContain('invoke("read_user_skills"');
expect(tauriRegistry).toContain("commands::user_skills::list_user_skills,");
expect(tauriRegistry).toContain("commands::user_skills::read_user_skills,");
expect(api).toContain('listUserSkills = forward("listUserSkills")');
expect(api).toContain('readUserSkills = forward("readUserSkills")');
});
it("keeps the skill service strictly read-only outside its tests", () => {
const production = commandModuleSource.slice(0, commandModuleSource.indexOf("#[cfg(test)]"));
expect(production).not.toContain("fs::write");
expect(production).not.toContain("fs::remove");
expect(production).not.toContain("fs::create_dir");
expect(production).not.toContain("OpenOptions");
});
it("keeps the Web transport explicitly unsupported without adding HTTP routes", () => {
for (const operation of ["listUserSkills", "readUserSkills"]) {
const body = functionBody(http, operation);
expect(body).toContain("only available in the desktop app");
expect(body).not.toContain("post(");
expect(body).not.toContain("fetch(");
}
expect(webRegistry).not.toContain("user_skills");
expect(webRegistry).not.toContain("list_user_skills");
expect(webRegistry).not.toContain("read_user_skills");
});
});
+4
View File
@@ -415,6 +415,10 @@ export const deletePromptTemplate = forward("deletePromptTemplate");
export const getAiGlobalCustomInstructions = forward("getAiGlobalCustomInstructions");
export const setAiGlobalCustomInstructions = forward("setAiGlobalCustomInstructions");
// User Skills (read-only Codex-compatible SKILL.md library)
export const listUserSkills = forward("listUserSkills");
export const readUserSkills = forward("readUserSkills");
// System
export const listSystemFonts = forward("listSystemFonts");
export const listSshConfigHosts = forward("listSshConfigHosts");
+11
View File
@@ -1,5 +1,6 @@
import type { MongoDumpFormat, MongoDumpSourceInput, MongoDumpCatalog, MongoRestoreSourcePreview, MongoDatabaseDumpRequest, MongoDatabaseRestoreRequest, MongoDatabaseDumpProgress } from "./mongodbDumpTypes";
import type { MongoRestoreUpload, MongoSourceReadOptions } from "./mongodbDumpTypes";
import type { UserSkillRootSettings, UserSkillsListResult, UserSkillsReadResult } from "@/types/userSkills";
import type {
ConnectionConfig,
ConnectionTestResult,
@@ -303,6 +304,8 @@ const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = {
driver_store_dir: null,
plugin_store_dir: null,
agent_store_dir: null,
custom_ai_skill_root_enabled: false,
custom_ai_skill_root: null,
sidebar_table_page_size: 1000,
};
@@ -894,6 +897,14 @@ export async function exportAgentsOffline(_path: string, _driverKeys: string[]):
throw new Error("Offline Agent package export is only available in the desktop app.");
}
export async function listUserSkills(_settings: UserSkillRootSettings): Promise<UserSkillsListResult> {
throw new Error("AI skills are only available in the desktop app.");
}
export async function readUserSkills(_ids: string[], _settings: UserSkillRootSettings): Promise<UserSkillsReadResult> {
throw new Error("AI skills are only available in the desktop app.");
}
export async function importAgentDriver(dbType: string, pathOrFile: string | File): Promise<void> {
let blob: Blob;
let fileName: string;
+11
View File
@@ -1,6 +1,7 @@
import { invoke as tauriInvoke } from "@tauri-apps/api/core";
import type { MongoDumpFormat, MongoDumpSourceInput, MongoDumpCatalog, MongoRestoreSourcePreview, MongoDatabaseDumpRequest, MongoDatabaseRestoreRequest, MongoDatabaseDumpProgress } from "./mongodbDumpTypes";
import type { MongoRestoreUpload, MongoSourceReadOptions } from "./mongodbDumpTypes";
import type { UserSkillRootSettings, UserSkillsListResult, UserSkillsReadResult } from "@/types/userSkills";
import { assertUpdateAllowsCommand } from "@/lib/app/updatePreparation";
import { collectBrowserSupportInfo } from "@/lib/app/supportInfo";
// Re-exported below so the HTTP transport shares one definition; imported here
@@ -290,6 +291,8 @@ export interface DesktopSettings {
driver_store_dir?: string | null;
plugin_store_dir?: string | null;
agent_store_dir?: string | null;
custom_ai_skill_root_enabled?: boolean | null;
custom_ai_skill_root?: string | null;
sidebar_table_page_size?: number | null;
}
@@ -1246,6 +1249,14 @@ export async function setAiGlobalCustomInstructions(content: string): Promise<vo
return invoke("set_ai_global_custom_instructions", { content });
}
export async function listUserSkills(settings: UserSkillRootSettings): Promise<UserSkillsListResult> {
return invoke("list_user_skills", { customRootEnabled: settings.customRootEnabled, customRoot: settings.customRoot });
}
export async function readUserSkills(ids: string[], settings: UserSkillRootSettings): Promise<UserSkillsReadResult> {
return invoke("read_user_skills", { ids, customRootEnabled: settings.customRootEnabled, customRoot: settings.customRoot });
}
export async function testConnection(config: ConnectionConfig): Promise<string> {
return invokeBackend("test_connection", { config });
}