diff --git a/apps/server/src/skills/SkillInventory.test.ts b/apps/server/src/skills/SkillInventory.test.ts index 636d7bf999..634435f079 100644 --- a/apps/server/src/skills/SkillInventory.test.ts +++ b/apps/server/src/skills/SkillInventory.test.ts @@ -12,7 +12,7 @@ import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import * as ServerSettings from "../serverSettings.ts"; -import { discoverGlobalSkillInventory } from "./SkillInventory.ts"; +import { discoverGlobalSkillInventory, readSkillInstallations } from "./SkillInventory.ts"; const decodeCodexSettings = Schema.decodeSync(CodexSettings); const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings); @@ -33,6 +33,33 @@ const writeSkill = Effect.fn("SkillInventoryTest.writeSkill")(function* ( }); it.layer(NodeServices.layer)("discoverGlobalSkillInventory", (it) => { + it.effect("omits skills that become unreadable during inventory", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const tempDirectory = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-skill-inventory-unreadable-", + }); + const installations = yield* readSkillInstallations({ + instanceId: "codex", + instance: { + driver: ProviderDriverKind.make("codex"), + config: decodeCodexSettings({}), + }, + fallbackDisplayName: "Codex", + skills: [ + { + name: "removed", + path: path.join(tempDirectory, "removed", "SKILL.md"), + enabled: true, + scope: "user", + }, + ], + }); + assert.deepEqual(installations, []); + }), + ); + it.effect("discovers global skills for configured Codex and Claude instances", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; diff --git a/apps/server/src/skills/SkillInventory.ts b/apps/server/src/skills/SkillInventory.ts index cf71228a73..2483aa4ae9 100644 --- a/apps/server/src/skills/SkillInventory.ts +++ b/apps/server/src/skills/SkillInventory.ts @@ -5,6 +5,7 @@ import type { SkillInventoryInstallation, } from "@t3tools/contracts"; import { ClaudeSettings, CodexSettings, ProviderInstanceId } from "@t3tools/contracts"; +import * as Arr from "effect/Array"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; @@ -24,7 +25,7 @@ function harnessDisplayName(instance: ProviderInstanceConfig, fallback: string): return instance.displayName?.trim() || fallback; } -const readSkillInstallations = Effect.fn("SkillInventory.readSkillInstallations")( +export const readSkillInstallations = Effect.fn("SkillInventory.readSkillInstallations")( function* (input: { readonly instanceId: string; readonly instance: ProviderInstanceConfig; @@ -37,9 +38,8 @@ const readSkillInstallations = Effect.fn("SkillInventory.readSkillInstallations" > { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; - return yield* Effect.forEach(input.skills, (skill) => + const installations = 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, @@ -50,8 +50,10 @@ const readSkillInstallations = Effect.fn("SkillInventory.readSkillInstallations" skillFilePath: skill.path, content, })), + Effect.option, ), ); + return Arr.getSomes(installations); }, ); diff --git a/apps/web/src/components/settings/SkillsSettings.test.ts b/apps/web/src/components/settings/SkillsSettings.test.ts index 89faf3b29d..26ce50740a 100644 --- a/apps/web/src/components/settings/SkillsSettings.test.ts +++ b/apps/web/src/components/settings/SkillsSettings.test.ts @@ -4,6 +4,7 @@ import { ProviderDriverKind, ProviderInstanceId, type SkillInventory } from "@t3 import { displayedSkillCount, filterSkillInventory, + formatSkillCount, formatSkillPath, groupSkillsByHarness, setKeyCollapsed, @@ -68,6 +69,12 @@ describe("skill explorer helpers", () => { expect(displayedSkillCount(null, true)).toBeNull(); }); + it("labels filtered skill counts without hiding the installed total", () => { + expect(formatSkillCount(12)).toBe("12 skills"); + expect(formatSkillCount(1)).toBe("1 skill"); + expect(formatSkillCount(12, 2)).toBe("2 of 12 skills"); + }); + it("applies the requested harness collapsed state without toggling blindly", () => { const collapsed = setKeyCollapsed(new Set(), "codex", true); expect([...collapsed]).toEqual(["codex"]); diff --git a/apps/web/src/components/settings/SkillsSettings.tsx b/apps/web/src/components/settings/SkillsSettings.tsx index ec4f8447d3..ec16babdb5 100644 --- a/apps/web/src/components/settings/SkillsSettings.tsx +++ b/apps/web/src/components/settings/SkillsSettings.tsx @@ -7,6 +7,7 @@ import { displayedSkillCount, fetchEnvironmentSkillInventory, filterSkillInventory, + formatSkillCount, formatSkillPath, groupSkillsByHarness, setKeyCollapsed, @@ -160,6 +161,7 @@ function EnvironmentSkillInventory({ state.status === "loaded" ? state.inventory : null, isConnected, ); + const visibleSkillCount = displayedSkillCount(visibleInventory, isConnected); const phase = environment.connection.phase; const isSearching = query.trim().length > 0; const open = isSearching || !collapsed; @@ -198,7 +200,7 @@ function EnvironmentSkillInventory({ /> {skillCount !== null ? ( - {skillCount} {skillCount === 1 ? "skill" : "skills"} + {formatSkillCount(skillCount, isSearching ? (visibleSkillCount ?? 0) : undefined)} ) : null} diff --git a/packages/client-runtime/src/state/skillInventoryHttp.ts b/packages/client-runtime/src/state/skillInventoryHttp.ts index 2a3b6f7a11..11cce6aa39 100644 --- a/packages/client-runtime/src/state/skillInventoryHttp.ts +++ b/packages/client-runtime/src/state/skillInventoryHttp.ts @@ -44,6 +44,11 @@ export function displayedSkillCount( return inventory.installations.length; } +export function formatSkillCount(total: number, visible?: number): string { + if (visible !== undefined && visible !== total) return `${visible} of ${total} skills`; + return `${total} ${total === 1 ? "skill" : "skills"}`; +} + export function setKeyCollapsed( keys: ReadonlySet, key: string,