diff --git a/apps/server/src/skills/SkillInventory.test.ts b/apps/server/src/skills/SkillInventory.test.ts index ceed986243..636d7bf999 100644 --- a/apps/server/src/skills/SkillInventory.test.ts +++ b/apps/server/src/skills/SkillInventory.test.ts @@ -11,7 +11,7 @@ import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; -import { layerTest as serverSettingsLayerTest } from "../serverSettings.ts"; +import * as ServerSettings from "../serverSettings.ts"; import { discoverGlobalSkillInventory } from "./SkillInventory.ts"; const decodeCodexSettings = Schema.decodeSync(CodexSettings); @@ -47,7 +47,7 @@ it.layer(NodeServices.layer)("discoverGlobalSkillInventory", (it) => { const inventory = yield* discoverGlobalSkillInventory().pipe( Effect.provide( - serverSettingsLayerTest({ + ServerSettings.layerTest({ providers: { codex: decodeCodexSettings({ homePath: path.join(tempDirectory, "empty-codex") }), claudeAgent: decodeClaudeSettings({ @@ -98,6 +98,63 @@ it.layer(NodeServices.layer)("discoverGlobalSkillInventory", (it) => { }), ); + it.effect("respects provider enablement and instance environment", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const tempDirectory = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-skill-inventory-environment-", + }); + const codexHome = path.join(tempDirectory, "codex-env"); + const claudeHome = path.join(tempDirectory, "claude-env"); + const disabledCodexHome = path.join(tempDirectory, "codex-disabled"); + const disabledClaudeHome = path.join(tempDirectory, "claude-disabled"); + yield* writeSkill(codexHome, "codex-env-skill", "Loaded from CODEX_HOME."); + yield* writeSkill(claudeHome, "claude-env-skill", "Loaded from CLAUDE_CONFIG_DIR."); + yield* writeSkill(disabledCodexHome, "disabled-codex", "Must not appear."); + yield* writeSkill(disabledClaudeHome, "disabled-claude", "Must not appear."); + + const inventory = yield* discoverGlobalSkillInventory().pipe( + Effect.provide( + ServerSettings.layerTest({ + providers: { + codex: decodeCodexSettings({ homePath: path.join(tempDirectory, "legacy-codex") }), + claudeAgent: decodeClaudeSettings({ + homePath: path.join(tempDirectory, "legacy-claude"), + }), + }, + providerInstances: { + [ProviderInstanceId.make("codex_env")]: { + driver: ProviderDriverKind.make("codex"), + environment: [{ name: "CODEX_HOME", value: codexHome, sensitive: false }], + config: decodeCodexSettings({}), + }, + [ProviderInstanceId.make("claude_env")]: { + driver: ProviderDriverKind.make("claudeAgent"), + environment: [{ name: "CLAUDE_CONFIG_DIR", value: claudeHome, sensitive: false }], + config: decodeClaudeSettings({}), + }, + [ProviderInstanceId.make("codex_disabled")]: { + driver: ProviderDriverKind.make("codex"), + enabled: false, + config: decodeCodexSettings({ homePath: disabledCodexHome }), + }, + [ProviderInstanceId.make("claude_disabled")]: { + driver: ProviderDriverKind.make("claudeAgent"), + config: decodeClaudeSettings({ enabled: false, homePath: disabledClaudeHome }), + }, + }, + }), + ), + ); + + assert.deepEqual(inventory.installations.map((skill) => skill.name).sort(), [ + "claude-env-skill", + "codex-env-skill", + ]); + }), + ); + it.effect("ignores unsupported provider instances", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; @@ -107,7 +164,7 @@ it.layer(NodeServices.layer)("discoverGlobalSkillInventory", (it) => { }); const inventory = yield* discoverGlobalSkillInventory().pipe( Effect.provide( - serverSettingsLayerTest({ + ServerSettings.layerTest({ providers: { codex: decodeCodexSettings({ homePath: path.join(tempDirectory, "codex") }), claudeAgent: decodeClaudeSettings({ diff --git a/apps/server/src/skills/SkillInventory.ts b/apps/server/src/skills/SkillInventory.ts index 83cd5feaca..c29ae33be5 100644 --- a/apps/server/src/skills/SkillInventory.ts +++ b/apps/server/src/skills/SkillInventory.ts @@ -1,5 +1,6 @@ import type { ProviderInstanceConfig, + ServerProviderSkill, SkillInventory, SkillInventoryInstallation, } from "@t3tools/contracts"; @@ -13,6 +14,7 @@ import * as Schema from "effect/Schema"; import { discoverClaudeSkills } from "../provider/Drivers/ClaudeSkills.ts"; import { resolveCodexHomeLayout } from "../provider/Drivers/CodexHomeLayout.ts"; import { deriveProviderInstanceConfigMap } from "../provider/Layers/ProviderInstanceRegistryHydration.ts"; +import { mergeProviderInstanceEnvironment } from "../provider/ProviderInstanceEnvironment.ts"; import { ServerSettingsService } from "../serverSettings.ts"; const decodeCodexSettings = Schema.decodeUnknownOption(CodexSettings); @@ -22,6 +24,38 @@ function harnessDisplayName(instance: ProviderInstanceConfig, fallback: string): return instance.displayName?.trim() || fallback; } +const readSkillInstallations = Effect.fn("SkillInventory.readSkillInstallations")( + function* (input: { + readonly instanceId: string; + readonly instance: ProviderInstanceConfig; + readonly fallbackDisplayName: string; + readonly skills: ReadonlyArray; + }): Effect.fn.Return< + ReadonlyArray, + never, + FileSystem.FileSystem | Path.Path + > { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + return yield* Effect.forEach(input.skills, (skill) => + fileSystem.readFileString(skill.path).pipe( + Effect.orElseSucceed(() => ""), + Effect.map((content) => ({ + providerInstanceId: ProviderInstanceId.make(input.instanceId), + harness: input.instance.driver, + harnessDisplayName: harnessDisplayName(input.instance, input.fallbackDisplayName), + name: skill.name, + ...(skill.description ? { description: skill.description } : {}), + directoryPath: path.dirname(skill.path), + skillFilePath: skill.path, + content, + enabled: skill.enabled, + })), + ), + ); + }, +); + const discoverInstanceSkills = Effect.fn("SkillInventory.discoverInstanceSkills")(function* ( instanceId: string, instance: ProviderInstanceConfig, @@ -30,55 +64,45 @@ const discoverInstanceSkills = Effect.fn("SkillInventory.discoverInstanceSkills" never, FileSystem.FileSystem | Path.Path > { - const fileSystem = yield* FileSystem.FileSystem; - const path = yield* Path.Path; const config = instance.config ?? {}; + const processEnv = mergeProviderInstanceEnvironment(instance.environment); if (instance.driver === "codex") { const decoded = decodeCodexSettings(config); if (decoded._tag === "None") return []; - const layout = yield* resolveCodexHomeLayout(decoded.value); - const skills = yield* discoverClaudeSkills({ homePath: layout.sharedHomePath }, undefined, {}); - return yield* Effect.forEach(skills, (skill) => - fileSystem.readFileString(skill.path).pipe( - Effect.orElseSucceed(() => ""), - Effect.map((content) => ({ - providerInstanceId: ProviderInstanceId.make(instanceId), - harness: instance.driver, - harnessDisplayName: harnessDisplayName(instance, "Codex"), - name: skill.name, - ...(skill.description ? { description: skill.description } : {}), - directoryPath: path.dirname(skill.path), - skillFilePath: skill.path, - content, - enabled: skill.enabled, - })), - ), + if (!(instance.enabled ?? decoded.value.enabled)) return []; + const configuredHomePath = decoded.value.homePath || processEnv.CODEX_HOME?.trim() || ""; + const layout = yield* resolveCodexHomeLayout({ + ...decoded.value, + homePath: configuredHomePath, + }); + const skills = yield* discoverClaudeSkills( + { homePath: layout.sharedHomePath }, + undefined, + processEnv, ); + return yield* readSkillInstallations({ + instanceId, + instance, + fallbackDisplayName: "Codex", + skills, + }); } if (instance.driver === "claudeAgent") { const decoded = decodeClaudeSettings(config); if (decoded._tag === "None") return []; - const skills = yield* discoverClaudeSkills(decoded.value, undefined); - return yield* Effect.forEach(skills, (skill) => - fileSystem.readFileString(skill.path).pipe( - Effect.orElseSucceed(() => ""), - Effect.map((content) => ({ - providerInstanceId: ProviderInstanceId.make(instanceId), - harness: instance.driver, - harnessDisplayName: harnessDisplayName(instance, "Claude"), - name: skill.name, - ...(skill.description ? { description: skill.description } : {}), - directoryPath: path.dirname(skill.path), - skillFilePath: skill.path, - content, - enabled: skill.enabled, - })), - ), - ); + if (!(instance.enabled ?? decoded.value.enabled)) return []; + const skills = yield* discoverClaudeSkills(decoded.value, undefined, processEnv); + return yield* readSkillInstallations({ + instanceId, + instance, + fallbackDisplayName: "Claude", + skills, + }); } + // Cursor, Grok, and OpenCode do not expose compatible global skill directories. return []; }); diff --git a/apps/web/src/components/settings/SkillsSettings.logic.ts b/apps/web/src/components/settings/SkillsSettings.logic.ts deleted file mode 100644 index cc372a68ac..0000000000 --- a/apps/web/src/components/settings/SkillsSettings.logic.ts +++ /dev/null @@ -1,102 +0,0 @@ -import type { - ProviderDriverKind, - SkillInventory, - SkillInventoryInstallation, -} from "@t3tools/contracts"; - -/** Matches a POSIX or Windows home directory so paths can read as `~/...`. */ -const HOME_DIRECTORY_PREFIX = /^(?:\/(?:home|Users)\/[^/]+|[A-Za-z]:\\Users\\[^\\]+)(?=[/\\]|$)/; - -/** - * Shortens a skill directory for display: home-relative, and elided to its last - * few segments when deep. The full path stays available in the tooltip. - */ -export function formatSkillPath(path: string): string { - const homeRelative = path.replace(HOME_DIRECTORY_PREFIX, "~"); - const segments = homeRelative.split(/[/\\]/).filter(Boolean); - if (segments.length <= 4) return homeRelative; - return `…/${segments.slice(-3).join("/")}`; -} - -export function filterSkillInventory(inventory: SkillInventory, query: string): SkillInventory { - const normalizedQuery = query.trim().toLocaleLowerCase(); - if (!normalizedQuery) return inventory; - return { - ...inventory, - installations: inventory.installations.filter((skill) => - [skill.name, skill.description ?? "", skill.directoryPath, skill.harnessDisplayName].some( - (value) => value.toLocaleLowerCase().includes(normalizedQuery), - ), - ), - }; -} - -export function displayedSkillCount( - inventory: SkillInventory | null, - isConnected: boolean, -): number | null { - if (!isConnected || !inventory) return null; - return inventory.installations.length; -} - -export function setKeyCollapsed( - keys: ReadonlySet, - key: string, - collapsed: boolean, -): ReadonlySet { - const next = new Set(keys); - if (collapsed) next.add(key); - else next.delete(key); - return next; -} - -export interface SkillHarnessGroup { - readonly key: string; - readonly harness: ProviderDriverKind; - readonly harnessDisplayName: string; - /** Shared parent directory of every skill in the group, when they agree. */ - readonly rootPath: string | null; - readonly skills: ReadonlyArray; -} - -/** Stable identity for a single installation, unique within an inventory. */ -export function skillKey(skill: SkillInventoryInstallation): string { - return `${skill.providerInstanceId}:${skill.directoryPath}`; -} - -function parentDirectory(path: string): string { - const parent = path.replace(/[/\\]+[^/\\]+[/\\]*$/, ""); - return parent || path; -} - -/** - * Buckets installations by the harness that owns them, preserving inventory - * order so the explorer renders deterministically across refreshes. - */ -export function groupSkillsByHarness( - installations: ReadonlyArray, -): ReadonlyArray { - const groups = new Map(); - for (const skill of installations) { - const key = `${skill.providerInstanceId}\0${skill.harnessDisplayName}`; - const existing = groups.get(key); - if (existing) existing.push(skill); - else groups.set(key, [skill]); - } - return [...groups.entries()].map(([key, skills]) => { - const roots = new Set(skills.map((skill) => parentDirectory(skill.directoryPath))); - return { - key, - harness: skills[0]!.harness, - harnessDisplayName: skills[0]?.harnessDisplayName ?? key, - rootPath: roots.size === 1 ? ([...roots][0] ?? null) : null, - skills, - }; - }); -} - -/** Raw SKILL.md text ready to render, or `null` when the file has no content. */ -export function skillContentForDisplay(content: string): string | null { - const trimmed = content.trim(); - return trimmed.length > 0 ? trimmed : null; -} diff --git a/apps/web/src/components/settings/SkillsSettings.test.ts b/apps/web/src/components/settings/SkillsSettings.test.ts index 376f5c270f..3c5036a63d 100644 --- a/apps/web/src/components/settings/SkillsSettings.test.ts +++ b/apps/web/src/components/settings/SkillsSettings.test.ts @@ -8,7 +8,7 @@ import { groupSkillsByHarness, setKeyCollapsed, skillContentForDisplay, -} from "./SkillsSettings.logic"; +} from "@t3tools/client-runtime/state/skills"; const inventory: SkillInventory = { scannedAt: "2026-07-27T12:00:00.000Z", diff --git a/apps/web/src/components/settings/SkillsSettings.tsx b/apps/web/src/components/settings/SkillsSettings.tsx index b6a208b2bc..bd8746f455 100644 --- a/apps/web/src/components/settings/SkillsSettings.tsx +++ b/apps/web/src/components/settings/SkillsSettings.tsx @@ -3,7 +3,16 @@ import type { SkillInventory, SkillInventoryInstallation } from "@t3tools/contra import * as Option from "effect/Option"; import { useCallback, useEffect, useId, useMemo, useState } from "react"; -import { fetchEnvironmentSkillInventory } from "@t3tools/client-runtime/state/skills"; +import { + displayedSkillCount, + fetchEnvironmentSkillInventory, + filterSkillInventory, + formatSkillPath, + groupSkillsByHarness, + setKeyCollapsed, + skillContentForDisplay, + skillKey, +} from "@t3tools/client-runtime/state/skills"; import { cn } from "../../lib/utils"; import { runtime } from "../../lib/runtime"; import { useCopyToClipboard } from "../../hooks/useCopyToClipboard"; @@ -18,15 +27,6 @@ import { ScrollArea } from "../ui/scroll-area"; import { toastManager } from "../ui/toast"; import { SettingsPageContainer, SettingsSection } from "./settingsLayout"; import { searchableSetting } from "./settingsSearch"; -import { - displayedSkillCount, - filterSkillInventory, - formatSkillPath, - groupSkillsByHarness, - setKeyCollapsed, - skillContentForDisplay, - skillKey, -} from "./SkillsSettings.logic"; type InventoryState = | { readonly status: "loading" } diff --git a/apps/web/src/components/settings/settingsSearch.test.ts b/apps/web/src/components/settings/settingsSearch.test.ts index 464f92547e..a5fb578ad8 100644 --- a/apps/web/src/components/settings/settingsSearch.test.ts +++ b/apps/web/src/components/settings/settingsSearch.test.ts @@ -84,4 +84,11 @@ describe("searchSettings", () => { targetId: "appearance", }); }); + + it("routes skill settings to the skill manager", () => { + expect(searchSettings("skills")[0]).toMatchObject({ + id: "skills", + to: "/settings/skills", + }); + }); }); diff --git a/docs/architecture/skill-manager-plan.html b/docs/architecture/skill-manager-plan.html index 9797279061..23a68a5c73 100644 --- a/docs/architecture/skill-manager-plan.html +++ b/docs/architecture/skill-manager-plan.html @@ -815,12 +815,13 @@

Likely implementation touchpoints

- packages/contracts/src/environment.ts · - packages/contracts/src/environmentHttp.ts · new inventory schemas · + packages/contracts/src/skillInventory.ts · + packages/contracts/src/environmentHttp.ts · apps/server/src/provider/Drivers/ClaudeSkills.ts · apps/server/src/provider/Layers/CodexProvider.ts · new - apps/server/src/skills/ service/adapters · - apps/server/src/http.ts · new client-runtime query helper · + apps/server/src/skills/ service/adapters and HTTP handler · + apps/server/src/server.ts · + packages/client-runtime/src/state/skillInventoryHttp.ts · apps/web/src/components/settings/SettingsSidebarNav.tsx · new apps/web/src/routes/settings.skills.tsx and settings components.

diff --git a/packages/client-runtime/src/state/skillInventoryHttp.ts b/packages/client-runtime/src/state/skillInventoryHttp.ts index ff01bc4877..e81c1e0b3b 100644 --- a/packages/client-runtime/src/state/skillInventoryHttp.ts +++ b/packages/client-runtime/src/state/skillInventoryHttp.ts @@ -1,5 +1,10 @@ import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; +import type { + ProviderDriverKind, + SkillInventory, + SkillInventoryInstallation, +} from "@t3tools/contracts"; import type { PreparedConnection } from "../connection/model.ts"; import { environmentEndpointUrl } from "../environment/endpoint.ts"; @@ -8,6 +13,92 @@ import { executeEnvironmentHttpRequest, makeEnvironmentHttpApiClient } from "../ import { buildEnvironmentAuthHeaders, withEnvironmentCredentials } from "./environmentHttpAuth.ts"; const DEFAULT_SKILL_INVENTORY_TIMEOUT_MS = 10_000; +const HOME_DIRECTORY_PREFIX = /^(?:\/(?:home|Users)\/[^/]+|[A-Za-z]:\\Users\\[^\\]+)(?=[/\\]|$)/; + +/** Shortens a skill directory for display while preserving its useful tail. */ +export function formatSkillPath(path: string): string { + const homeRelative = path.replace(HOME_DIRECTORY_PREFIX, "~"); + const segments = homeRelative.split(/[/\\]/).filter(Boolean); + if (segments.length <= 4) return homeRelative; + return `…/${segments.slice(-3).join("/")}`; +} + +export function filterSkillInventory(inventory: SkillInventory, query: string): SkillInventory { + const normalizedQuery = query.trim().toLocaleLowerCase(); + if (!normalizedQuery) return inventory; + return { + ...inventory, + installations: inventory.installations.filter((skill) => + [skill.name, skill.description ?? "", skill.directoryPath, skill.harnessDisplayName].some( + (value) => value.toLocaleLowerCase().includes(normalizedQuery), + ), + ), + }; +} + +export function displayedSkillCount( + inventory: SkillInventory | null, + isConnected: boolean, +): number | null { + if (!isConnected || !inventory) return null; + return inventory.installations.length; +} + +export function setKeyCollapsed( + keys: ReadonlySet, + key: string, + collapsed: boolean, +): ReadonlySet { + const next = new Set(keys); + if (collapsed) next.add(key); + else next.delete(key); + return next; +} + +export interface SkillHarnessGroup { + readonly key: string; + readonly harness: ProviderDriverKind; + readonly harnessDisplayName: string; + readonly rootPath: string | null; + readonly skills: ReadonlyArray; +} + +/** Stable identity for a single installation, unique within an inventory. */ +export function skillKey(skill: SkillInventoryInstallation): string { + return `${skill.providerInstanceId}:${skill.directoryPath}`; +} + +function parentDirectory(path: string): string { + const parent = path.replace(/[/\\]+[^/\\]+[/\\]*$/, ""); + return parent || path; +} + +export function groupSkillsByHarness( + installations: ReadonlyArray, +): ReadonlyArray { + const groups = new Map(); + for (const skill of installations) { + const key = `${skill.providerInstanceId}\0${skill.harnessDisplayName}`; + const existing = groups.get(key); + if (existing) existing.push(skill); + else groups.set(key, [skill]); + } + return [...groups.entries()].map(([key, skills]) => { + const roots = new Set(skills.map((skill) => parentDirectory(skill.directoryPath))); + return { + key, + harness: skills[0]!.harness, + harnessDisplayName: skills[0]?.harnessDisplayName ?? key, + rootPath: roots.size === 1 ? ([...roots][0] ?? null) : null, + skills, + }; + }); +} + +export function skillContentForDisplay(content: string): string | null { + const trimmed = content.trim(); + return trimmed.length > 0 ? trimmed : null; +} export const fetchEnvironmentSkillInventory = Effect.fn( "clientRuntime.state.fetchEnvironmentSkillInventory",