Skip to content

Commit f5a7ae8

Browse files
onlydoleclaude
andcommitted
perf(server): Claude skill discovery resolves each repository root once
Every Claude turn start, steer and provider refresh resolved the repository root of each project-scoped plugin install record, and many records share a project path. Cache the result per path for one discovery, and stop writing a span for each lookup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5b9731c commit f5a7ae8

2 files changed

Lines changed: 56 additions & 7 deletions

File tree

‎apps/server/src/provider/Drivers/ClaudeSkills.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,50 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
209209
}),
210210
);
211211

212+
it.effect("resolves each install record's project repository once per discovery", () =>
213+
Effect.gen(function* () {
214+
const fs = yield* FileSystem.FileSystem;
215+
const path = yield* Path.Path;
216+
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
217+
const configDir = path.join(tempDir, "claude-home");
218+
const workspace = path.join(tempDir, "workspace");
219+
const otherProject = path.join(tempDir, "other", "packages", "app");
220+
yield* fs.makeDirectory(path.join(workspace, ".git"), { recursive: true });
221+
yield* fs.makeDirectory(path.join(tempDir, "other", ".git"), { recursive: true });
222+
yield* fs.makeDirectory(otherProject, { recursive: true });
223+
const records = Array.from({ length: 4 }, () => ({
224+
scope: "project",
225+
projectPath: otherProject,
226+
installPath: path.join(configDir, "plugins", "elsewhere"),
227+
}));
228+
const plugins = ["a@shop", "b@shop", "c@shop"];
229+
yield* fs.makeDirectory(path.join(configDir, "plugins"), { recursive: true });
230+
yield* fs.writeFileString(
231+
path.join(configDir, "plugins", "installed_plugins.json"),
232+
JSON.stringify({ plugins: Object.fromEntries(plugins.map((key) => [key, records])) }),
233+
);
234+
yield* fs.writeFileString(
235+
path.join(configDir, "settings.json"),
236+
JSON.stringify({ enabledPlugins: Object.fromEntries(plugins.map((key) => [key, true])) }),
237+
);
238+
239+
const probed: Array<string> = [];
240+
yield* discoverClaudeSkills({ homePath: configDir }, workspace).pipe(
241+
Effect.provideService(FileSystem.FileSystem, {
242+
...fs,
243+
exists: (target) => {
244+
probed.push(target);
245+
return fs.exists(target);
246+
},
247+
}),
248+
);
249+
assert.strictEqual(
250+
probed.filter((target) => target === path.join(otherProject, ".git")).length,
251+
1,
252+
);
253+
}),
254+
);
255+
212256
it.effect("publishes and dispatches canonical plugin folder names regardless of aliases", () =>
213257
Effect.gen(function* () {
214258
const fs = yield* FileSystem.FileSystem;

‎apps/server/src/provider/Drivers/ClaudeSkills.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ function claudeSettingsPaths(
143143
];
144144
}
145145

146-
const findRepositoryRoot = Effect.fn("findRepositoryRoot")(function* (
146+
// Untraced: skill discovery resolves every distinct plugin project path, too often for spans.
147+
const findRepositoryRoot = Effect.fnUntraced(function* (
147148
cwd: string,
148149
): Effect.fn.Return<string | undefined, never, FileSystem.FileSystem | Path.Path> {
149150
const fileSystem = yield* FileSystem.FileSystem;
@@ -164,7 +165,7 @@ const findRepositoryRoot = Effect.fn("findRepositoryRoot")(function* (
164165
}
165166
});
166167

167-
const findPluginRepositoryRoot = Effect.fn("findPluginRepositoryRoot")(function* (cwd: string) {
168+
const findPluginRepositoryRoot = Effect.fnUntraced(function* (cwd: string) {
168169
const fileSystem = yield* FileSystem.FileSystem;
169170
const path = yield* Path.Path;
170171
const root = yield* findRepositoryRoot(cwd);
@@ -336,6 +337,8 @@ const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function*
336337
cwd === undefined
337338
? undefined
338339
: yield* fileSystem.realPath(cwd).pipe(Effect.orElseSucceed(() => path.resolve(cwd)));
340+
// Install records repeat project paths, often hundreds of times per discovery.
341+
const projectRepositoryRoots = new Map<string, string | undefined>();
339342
const repositoryRoot =
340343
workspace === undefined ? undefined : yield* findPluginRepositoryRoot(workspace);
341344

@@ -347,11 +350,13 @@ const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function*
347350
Effect.gen(function* () {
348351
if (record.scope === "user" || record.scope === "managed") return true;
349352
if (record.projectPath === undefined || workspace === undefined) return false;
350-
if (path.resolve(record.projectPath) === workspace) return true;
351-
return (
352-
repositoryRoot !== undefined &&
353-
(yield* findPluginRepositoryRoot(record.projectPath)) === repositoryRoot
354-
);
353+
const projectPath = path.resolve(record.projectPath);
354+
if (projectPath === workspace) return true;
355+
if (repositoryRoot === undefined) return false;
356+
if (!projectRepositoryRoots.has(projectPath)) {
357+
projectRepositoryRoots.set(projectPath, yield* findPluginRepositoryRoot(projectPath));
358+
}
359+
return projectRepositoryRoots.get(projectPath) === repositoryRoot;
355360
}),
356361
);
357362
// The native loader keeps registry order, preferring the first install that exists.

0 commit comments

Comments
 (0)