fix(settings): honor skill provider configuration

This commit is contained in:
Theo Browne committed 2026-08-07 04:48:33 -07:00
1 parent 150cc83478
commit 8141436e32
8 files changed
+234 -156

No files matched your search

+60 -3
View File
@@ -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({
+60 -36
View File
@@ -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<ServerProviderSkill>;
}): Effect.fn.Return<
ReadonlyArray<SkillInventoryInstallation>,
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 [];
});
@@ -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<string>,
key: string,
collapsed: boolean,
): ReadonlySet<string> {
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<SkillInventoryInstallation>;
}
/** 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<SkillInventoryInstallation>,
): ReadonlyArray<SkillHarnessGroup> {
const groups = new Map<string, SkillInventoryInstallation[]>();
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;
}
@@ -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",
@@ -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" }
@@ -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",
});
});
});
+5 -4
View File
@@ -815,12 +815,13 @@
<section>
<h2>Likely implementation touchpoints</h2>
<p>
<code>packages/contracts/src/environment.ts</code> ·
<code>packages/contracts/src/environmentHttp.ts</code> · new inventory schemas ·
<code>packages/contracts/src/skillInventory.ts</code> ·
<code>packages/contracts/src/environmentHttp.ts</code> ·
<code>apps/server/src/provider/Drivers/ClaudeSkills.ts</code> ·
<code>apps/server/src/provider/Layers/CodexProvider.ts</code> · new
<code>apps/server/src/skills/</code> service/adapters ·
<code>apps/server/src/http.ts</code> · new client-runtime query helper ·
<code>apps/server/src/skills/</code> service/adapters and HTTP handler ·
<code>apps/server/src/server.ts</code> ·
<code>packages/client-runtime/src/state/skillInventoryHttp.ts</code> ·
<code>apps/web/src/components/settings/SettingsSidebarNav.tsx</code> · new
<code>apps/web/src/routes/settings.skills.tsx</code> and settings components.
</p>
@@ -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<string>,
key: string,
collapsed: boolean,
): ReadonlySet<string> {
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<SkillInventoryInstallation>;
}
/** 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<SkillInventoryInstallation>,
): ReadonlyArray<SkillHarnessGroup> {
const groups = new Map<string, SkillInventoryInstallation[]>();
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",