Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ import {
} from "../ProviderDriver.ts";
import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts";
import { withInstanceIdentity } from "./instanceIdentity.ts";
import { discoverAntigravitySkills, resolveAntigravityUserHome } from "./AntigravitySkills.ts";
import {
antigravitySkillCatalogRoots,
discoverAntigravitySkills,
resolveAntigravityUserHome,
} from "./AntigravitySkills.ts";

const DRIVER = ProviderDriverKind.make("antigravity");
const decodeSettings = Schema.decodeSync(AntigravitySettings);
Expand Down Expand Up @@ -471,6 +475,13 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
}),
),
),
skillCatalogWatchPaths: (workspaceCwd) =>
Effect.succeed(
antigravitySkillCatalogRoots(path, { cwd: workspaceCwd, userHome }).map((root) => ({
path: root.directory,
recursive: true,
})),
),
adapter,
textGeneration,
auth: authFlow.controller,
Expand Down
29 changes: 18 additions & 11 deletions apps/server/src/provider/Drivers/AntigravitySkills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ export function antigravityUserSkillDirectories(
];
}

export function antigravitySkillCatalogRoots(
path: Path.Path,
input: { readonly cwd: string; readonly userHome: string },
): ReadonlyArray<{ readonly directory: string; readonly scope: "user" | "project" }> {
const [configSkills, cliSkills] = antigravityUserSkillDirectories(
path,
path.join(input.userHome, ".gemini"),
);
return [
{ directory: configSkills, scope: "user" },
{ directory: path.resolve(input.cwd, ".gemini", "skills"), scope: "project" },
{ directory: cliSkills, scope: "user" },
{ directory: path.resolve(input.cwd, ".agents", "skills"), scope: "project" },
{ directory: path.resolve(input.cwd, ".agent", "skills"), scope: "project" },
];
}

const MAX_SKILL_BYTES = 1_000_000;
const MAX_SCAN_BYTES = 8_000_000;
const MAX_SCAN_ENTRIES = 10_000;
Expand Down Expand Up @@ -167,17 +184,7 @@ export const discoverAntigravitySkills = Effect.fn("discoverAntigravitySkills")(
> {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const [configSkills, cliSkills] = antigravityUserSkillDirectories(
path,
path.join(input.userHome, ".gemini"),
);
const roots = [
{ directory: configSkills, scope: "user" },
{ directory: path.resolve(input.cwd, ".gemini", "skills"), scope: "project" },
{ directory: cliSkills, scope: "user" },
{ directory: path.resolve(input.cwd, ".agents", "skills"), scope: "project" },
{ directory: path.resolve(input.cwd, ".agent", "skills"), scope: "project" },
];
const roots = antigravitySkillCatalogRoots(path, input);
const budget: ScanBudget = {
remainingBytes: MAX_SCAN_BYTES,
remainingEntries: MAX_SCAN_ENTRIES,
Expand Down
7 changes: 6 additions & 1 deletion apps/server/src/provider/Drivers/ClaudeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
type ProviderSnapshotSettings,
} from "../providerUpdateSettings.ts";
import { makeClaudeCapabilitiesCacheKey, makeClaudeContinuationGroupKey } from "./ClaudeHome.ts";
import { discoverClaudeSkills } from "./ClaudeSkills.ts";
import { claudeSkillCatalogWatchPaths, discoverClaudeSkills } from "./ClaudeSkills.ts";
const decodeClaudeSettings = Schema.decodeSync(ClaudeSettings);

const DRIVER_KIND = ProviderDriverKind.make("claudeAgent");
Expand Down Expand Up @@ -262,6 +262,11 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
enabled,
snapshot,
snapshotForCwd,
skillCatalogWatchPaths: (workspaceCwd) =>
claudeSkillCatalogWatchPaths(effectiveConfig, workspaceCwd, processEnv).pipe(
Effect.provideService(FileSystem.FileSystem, fileSystem),
Effect.provideService(Path.Path, path),
),
adapter,
textGeneration,
} satisfies ProviderInstance;
Expand Down
47 changes: 46 additions & 1 deletion apps/server/src/provider/Drivers/ClaudeSkills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Path from "effect/Path";

import { discoverClaudeSkills, skillOverrideSettingsPaths } from "./ClaudeSkills.ts";
import {
claudeSkillCatalogWatchPaths,
discoverClaudeSkills,
skillOverrideSettingsPaths,
} from "./ClaudeSkills.ts";

const writeSkill = Effect.fn(function* (
skillsDir: string,
Expand All @@ -20,6 +24,47 @@ const writeSkill = Effect.fn(function* (
});

it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
it.effect("resolves watch paths from the same instance config and environment", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-watch-paths-" });
const workspace = path.join(tempDir, "workspace");
const configuredHome = path.join(tempDir, "configured-home");
const inheritedHome = path.join(tempDir, "inherited-home");

const configured = yield* claudeSkillCatalogWatchPaths(
{ homePath: configuredHome },
workspace,
{ ...process.env, CLAUDE_CONFIG_DIR: inheritedHome },
);
assert.strictEqual(
configured.some(
(watchPath) =>
watchPath.path === path.join(configuredHome, "skills") && watchPath.recursive,
),
true,
);
assert.strictEqual(
configured.some((watchPath) => watchPath.path.startsWith(inheritedHome)),
false,
);

const inherited = yield* claudeSkillCatalogWatchPaths({ homePath: "" }, workspace, {
...process.env,
CLAUDE_CONFIG_DIR: "relative-home",
});
assert.strictEqual(
inherited.some(
(watchPath) =>
watchPath.path === path.join(workspace, "relative-home", "skills") &&
watchPath.recursive,
),
true,
);
}),
);

it.effect("discovers user and project skills with frontmatter metadata", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand Down
27 changes: 27 additions & 0 deletions apps/server/src/provider/Drivers/ClaudeSkills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,33 @@ const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(funct
return path.join(NodeOS.homedir(), ".claude");
});

export const claudeSkillCatalogWatchPaths = Effect.fn("claudeSkillCatalogWatchPaths")(function* (
config: Pick<ClaudeSettings, "homePath">,
cwd: string,
environment: NodeJS.ProcessEnv,
): Effect.fn.Return<
ReadonlyArray<{ readonly path: string; readonly recursive: boolean }>,
never,
FileSystem.FileSystem | Path.Path
> {
const path = yield* Path.Path;
const platform = yield* HostProcessPlatform;
const configDirPath = yield* resolveClaudeConfigDirPath(config, environment, cwd);
const repositoryRoot = yield* findRepositoryRoot(cwd);
return [
{ path: path.join(configDirPath, "skills"), recursive: true },
{ path: path.join(cwd, ".claude", "skills"), recursive: true },
...skillOverrideSettingsPaths(
path,
configDirPath,
cwd,
platform,
environment,
repositoryRoot,
).map((settingsPath) => ({ path: settingsPath, recursive: false })),
];
});

/**
* Enumerate Claude Code skills from the user config dir and the workspace
* `.claude/skills`. Discovery is best-effort: unreadable roots and malformed
Expand Down
13 changes: 12 additions & 1 deletion apps/server/src/provider/Drivers/CursorDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ import {
makeProviderSnapshotSettingsSource,
type ProviderSnapshotSettings,
} from "../providerUpdateSettings.ts";
import { discoverCursorSkills, probeCursorSkills } from "./CursorSkills.ts";
import {
cursorSkillCatalogRoots,
discoverCursorSkills,
probeCursorSkills,
} from "./CursorSkills.ts";
const decodeCursorSettings = Schema.decodeSync(CursorSettings);

const DRIVER_KIND = ProviderDriverKind.make("cursor");
Expand Down Expand Up @@ -234,6 +238,13 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
),
Effect.flatMap((skills) => snapshotForCwd(cwd, skills)),
),
skillCatalogWatchPaths: (workspaceCwd) =>
Effect.succeed(
cursorSkillCatalogRoots(path, workspaceCwd, processEnv).map((root) => ({
path: root.directory,
recursive: true,
})),
),
adapter,
textGeneration,
} satisfies ProviderInstance;
Expand Down
24 changes: 16 additions & 8 deletions apps/server/src/provider/Drivers/CursorSkills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,7 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (
environment: NodeJS.ProcessEnv = process.env,
) {
const path = yield* Path.Path;
const userHome = environment.HOME?.trim() || environment.USERPROFILE?.trim() || NodeOS.homedir();
const rootsBelow = (base: string, scope: "user" | "project") => [
{ directory: path.join(base, ".cursor", "skills"), scope },
{ directory: path.join(base, ".agents", "skills"), scope },
{ directory: path.join(base, ".codex", "skills"), scope },
{ directory: path.join(base, ".claude", "skills"), scope },
];
const roots = [...(cwd ? rootsBelow(cwd, "project") : []), ...rootsBelow(userHome, "user")];
const roots = cursorSkillCatalogRoots(path, cwd, environment);

const skillsByName = new Map<string, ServerProviderSkill>();
const budget: CursorSkillScanBudget = {
Expand All @@ -254,6 +247,21 @@ const inspectCursorSkills = Effect.fn("inspectCursorSkills")(function* (
};
});

export function cursorSkillCatalogRoots(
path: Path.Path,
cwd?: string,
environment: NodeJS.ProcessEnv = process.env,
): ReadonlyArray<{ readonly directory: string; readonly scope: "user" | "project" }> {
const userHome = environment.HOME?.trim() || environment.USERPROFILE?.trim() || NodeOS.homedir();
const rootsBelow = (base: string, scope: "user" | "project") => [
{ directory: path.join(base, ".cursor", "skills"), scope },
{ directory: path.join(base, ".agents", "skills"), scope },
{ directory: path.join(base, ".codex", "skills"), scope },
{ directory: path.join(base, ".claude", "skills"), scope },
];
return [...(cwd ? rootsBelow(cwd, "project") : []), ...rootsBelow(userHome, "user")];
}

export const discoverCursorSkills = Effect.fn("discoverCursorSkills")(function* (
cwd?: string,
environment: NodeJS.ProcessEnv = process.env,
Expand Down
Loading
Loading