Skip to content

Commit 6df2036

Browse files
fix: discover project skills from workspace
1 parent 82b76e2 commit 6df2036

17 files changed

Lines changed: 326 additions & 34 deletions

File tree

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const RPC_REQUIRED_SCOPES = {
3030
[ORCHESTRATION_WS_METHODS.subscribeThread]: AuthOrchestrationReadScope,
3131
[WS_METHODS.serverProbe]: AuthOrchestrationReadScope,
3232
[WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope,
33+
[WS_METHODS.serverListProviderSkills]: AuthOrchestrationReadScope,
3334
[WS_METHODS.serverRefreshProviders]: AuthOrchestrationOperateScope,
3435
[WS_METHODS.serverUpdateProvider]: AuthOrchestrationOperateScope,
3536
[WS_METHODS.serverUpdateServer]: AuthOrchestrationOperateScope,

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
import { CodexSettings, ProviderDriverKind, type ServerProvider } from "@t3tools/contracts";
2525
import * as Crypto from "effect/Crypto";
26+
import * as Duration from "effect/Duration";
2627
import * as Effect from "effect/Effect";
2728
import * as FileSystem from "effect/FileSystem";
2829
import * as Path from "effect/Path";
@@ -36,7 +37,12 @@ import { ServerConfig } from "../../config.ts";
3637
import { ServerSettingsService } from "../../serverSettings.ts";
3738
import { ProviderDriverError } from "../Errors.ts";
3839
import { makeCodexAdapter } from "../Layers/CodexAdapter.ts";
39-
import { checkCodexProviderStatus, makePendingCodexProvider } from "../Layers/CodexProvider.ts";
40+
import { resolveCodexLaunchArgs } from "../Layers/codexLaunchArgs.ts";
41+
import {
42+
checkCodexProviderStatus,
43+
listCodexProviderSkills,
44+
makePendingCodexProvider,
45+
} from "../Layers/CodexProvider.ts";
4046
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
4147
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
4248
import type { ProviderDriver, ProviderInstance } from "../ProviderDriver.ts";
@@ -198,6 +204,29 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
198204
),
199205
);
200206

207+
const listSkills = (cwd: string) =>
208+
listCodexProviderSkills({
209+
binaryPath: effectiveConfig.binaryPath,
210+
homePath: effectiveConfig.homePath,
211+
launchArgs: resolveCodexLaunchArgs(effectiveConfig.launchArgs, processEnv),
212+
cwd,
213+
environment: processEnv,
214+
}).pipe(
215+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
216+
Effect.scoped,
217+
Effect.timeout(Duration.seconds(10)),
218+
Effect.catch((error) =>
219+
Effect.logWarning("Codex workspace skill discovery failed; using global skills.", {
220+
cwd,
221+
error: String(error),
222+
instanceId,
223+
}).pipe(
224+
Effect.andThen(snapshot.getSnapshot),
225+
Effect.map((provider) => provider.skills),
226+
),
227+
),
228+
);
229+
201230
return {
202231
instanceId,
203232
driverKind: DRIVER_KIND,
@@ -208,6 +237,7 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
208237
snapshot,
209238
adapter,
210239
textGeneration,
240+
listSkills,
211241
} satisfies ProviderInstance;
212242
}),
213243
};

‎apps/server/src/provider/Layers/CodexProvider.ts‎

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,17 @@ export function buildCodexInitializeParams(): CodexSchema.V1InitializeParams {
319319
};
320320
}
321321

322-
const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(function* (input: {
322+
interface CodexAppServerProbeInput {
323323
readonly binaryPath: string;
324324
readonly homePath?: string;
325325
readonly launchArgs?: string;
326326
readonly cwd: string;
327-
readonly customModels?: ReadonlyArray<string>;
328327
readonly environment?: NodeJS.ProcessEnv;
329-
}) {
328+
}
329+
330+
const openCodexAppServerProbe = Effect.fn("openCodexAppServerProbe")(function* (
331+
input: CodexAppServerProbeInput,
332+
) {
330333
// `~` is not shell-expanded when env vars are set via `child_process.spawn`,
331334
// so `CODEX_HOME=~/.codex_work` would reach codex verbatim and trip
332335
// "CODEX_HOME points to '~/.codex_work', but that path does not exist".
@@ -369,22 +372,33 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
369372
Effect.provide(clientContext),
370373
);
371374

372-
const initialize = yield* client.request("initialize", {
373-
clientInfo: {
374-
name: "t3code_desktop",
375-
title: "T3 Code Desktop",
376-
version: "0.1.0",
377-
},
378-
capabilities: {
379-
experimentalApi: true,
380-
},
381-
});
375+
const initialize = yield* client.request("initialize", buildCodexInitializeParams());
382376
yield* client.notify("initialized", undefined);
383377

384378
// Extract the version string after the first '/' in userAgent, up to the next space or the end
385379
const versionMatch = initialize.userAgent.match(/\/([^\s]+)/);
386380
const version = versionMatch ? versionMatch[1] : undefined;
387381

382+
return { client, version };
383+
});
384+
385+
export const listCodexProviderSkills = Effect.fn("listCodexProviderSkills")(function* (input: {
386+
readonly binaryPath: string;
387+
readonly homePath?: string;
388+
readonly launchArgs?: string;
389+
readonly cwd: string;
390+
readonly environment?: NodeJS.ProcessEnv;
391+
}) {
392+
const { client } = yield* openCodexAppServerProbe(input);
393+
const response = yield* client.request("skills/list", { cwds: [input.cwd] });
394+
return parseCodexSkillsListResponse(response, input.cwd);
395+
});
396+
397+
const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(function* (
398+
input: CodexAppServerProbeInput & { readonly customModels?: ReadonlyArray<string> },
399+
) {
400+
const { client, version } = yield* openCodexAppServerProbe(input);
401+
388402
const accountResponse = yield* client.request("account/read", {});
389403
if (!accountResponse.account && accountResponse.requiresOpenaiAuth) {
390404
return {
@@ -411,7 +425,9 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
411425
models: applyPreferredCodexDefaultModel(
412426
appendCustomCodexModels(models, input.customModels ?? []),
413427
),
414-
skills: parseCodexSkillsListResponse(skillsResponse, input.cwd),
428+
skills: parseCodexSkillsListResponse(skillsResponse, input.cwd).filter(
429+
(skill) => skill.scope !== "repo",
430+
),
415431
} satisfies CodexAppServerProviderSnapshot;
416432
});
417433

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
819819
]);
820820
});
821821

822-
it.effect("does not run provider probes during layer construction", () =>
822+
it.effect("does not probe at construction and routes cwd-scoped skill discovery", () =>
823823
Effect.gen(function* () {
824824
const codexDriver = ProviderDriverKind.make("codex");
825825
const codexInstanceId = ProviderInstanceId.make("codex");
@@ -838,6 +838,13 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
838838
skills: [],
839839
} as const satisfies ServerProvider;
840840
const refreshCalls = yield* Ref.make(0);
841+
const skillCwds = yield* Ref.make<ReadonlyArray<string>>([]);
842+
const workspaceSkill = {
843+
name: "project-review",
844+
path: "/tmp/project/.agents/skills/project-review/SKILL.md",
845+
scope: "repo",
846+
enabled: true,
847+
} as const;
841848
const instance = {
842849
instanceId: codexInstanceId,
843850
driverKind: codexDriver,
@@ -860,6 +867,8 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
860867
},
861868
adapter: {} as ProviderInstance["adapter"],
862869
textGeneration: {} as ProviderInstance["textGeneration"],
870+
listSkills: (cwd: string) =>
871+
Ref.update(skillCwds, (cwds) => [...cwds, cwd]).pipe(Effect.as([workspaceSkill])),
863872
} satisfies ProviderInstance;
864873
const instanceRegistryLayer = Layer.succeed(
865874
ProviderInstanceRegistry.ProviderInstanceRegistry,
@@ -889,6 +898,11 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
889898
const registry = yield* ProviderRegistry.ProviderRegistry;
890899
assert.deepStrictEqual(yield* registry.getProviders, [initialProvider]);
891900
assert.strictEqual(yield* Ref.get(refreshCalls), 0);
901+
assert.deepStrictEqual(
902+
yield* registry.listSkills({ instanceId: codexInstanceId, cwd: "/tmp/project" }),
903+
[workspaceSkill],
904+
);
905+
assert.deepStrictEqual(yield* Ref.get(skillCwds), ["/tmp/project"]);
892906
}).pipe(Effect.provide(runtimeServices));
893907
}),
894908
);

‎apps/server/src/provider/Layers/ProviderRegistry.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,20 @@ export const ProviderRegistryLive = Layer.effect(
496496
return yield* refreshOneSource(providerSource);
497497
});
498498

499+
const listSkills = Effect.fn("listSkills")(function* (input: {
500+
readonly instanceId: ProviderInstanceId;
501+
readonly cwd: string;
502+
}) {
503+
const instance = yield* instanceRegistry.getInstance(input.instanceId);
504+
if (instance === undefined || !instance.enabled) {
505+
return [];
506+
}
507+
if (instance.listSkills !== undefined) {
508+
return yield* instance.listSkills(input.cwd);
509+
}
510+
return (yield* instance.snapshot.getSnapshot).skills;
511+
});
512+
499513
const getProviderMaintenanceCapabilitiesForInstance = Effect.fn(
500514
"getProviderMaintenanceCapabilitiesForInstance",
501515
)(function* (instanceId: ProviderInstanceId, provider: ProviderDriverKind) {
@@ -710,6 +724,7 @@ export const ProviderRegistryLive = Layer.effect(
710724
refresh(provider).pipe(Effect.catchCause(recoverRefreshFailure)),
711725
refreshInstance: (instanceId: ProviderInstanceId) =>
712726
refreshInstance(instanceId).pipe(Effect.catchCause(recoverRefreshFailure)),
727+
listSkills,
713728
getProviderMaintenanceCapabilitiesForInstance,
714729
setProviderMaintenanceActionState,
715730
get streamChanges() {

‎apps/server/src/provider/ProviderDriver.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type {
2525
ProviderDriverKind,
2626
ProviderInstanceEnvironment,
2727
ProviderInstanceId,
28+
ServerProviderSkill,
2829
} from "@t3tools/contracts";
2930
import type * as Effect from "effect/Effect";
3031
import type * as Schema from "effect/Schema";
@@ -71,6 +72,8 @@ export interface ProviderInstance {
7172
readonly snapshot: ServerProviderShape;
7273
readonly adapter: ProviderAdapterShape<ProviderAdapterError>;
7374
readonly textGeneration: TextGeneration.TextGeneration["Service"];
75+
/** Resolve the skills visible from a workspace cwd. */
76+
readonly listSkills?: (cwd: string) => Effect.Effect<ReadonlyArray<ServerProviderSkill>>;
7477
}
7578

7679
export interface ProviderContinuationIdentity {

‎apps/server/src/provider/Services/ProviderRegistry.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ProviderInstanceId,
1111
ProviderDriverKind,
1212
ServerProvider,
13+
ServerProviderSkill,
1314
ServerProviderUpdateState,
1415
} from "@t3tools/contracts";
1516
import * as Context from "effect/Context";
@@ -19,6 +20,11 @@ import type { ProviderMaintenanceCapabilities } from "../providerMaintenance.ts"
1920

2021
export type ProviderMaintenanceActionKind = "update";
2122

23+
export interface ProviderRegistryListSkillsInput {
24+
readonly instanceId: ProviderInstanceId;
25+
readonly cwd: string;
26+
}
27+
2228
export interface ProviderRegistryShape {
2329
/**
2430
* Read the latest provider snapshots for every configured instance.
@@ -48,6 +54,11 @@ export interface ProviderRegistryShape {
4854
instanceId: ProviderInstanceId,
4955
) => Effect.Effect<ReadonlyArray<ServerProvider>>;
5056

57+
/** Resolve provider skills using the active workspace cwd. */
58+
readonly listSkills: (
59+
input: ProviderRegistryListSkillsInput,
60+
) => Effect.Effect<ReadonlyArray<ServerProviderSkill>>;
61+
5162
/**
5263
* Resolve the maintenance capabilities owned by one live provider instance.
5364
* Falls back to manual-only capabilities when the instance is not live.

‎apps/server/src/provider/providerMaintenanceRunner.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function makeRegistry(
187187

188188
const registry: ProviderRegistryShape = {
189189
getProviders: Ref.get(providersRef),
190+
listSkills: () => Effect.succeed([]),
190191
refresh: () => Ref.get(providersRef),
191192
refreshInstance: () => Ref.get(providersRef),
192193
getProviderMaintenanceCapabilitiesForInstance: (_instanceId, provider) =>

‎apps/server/src/provider/testUtils/providerRegistryMock.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const makeProviderRegistryMock = (
99
providers: ReadonlyArray<ServerProvider> = [],
1010
): ProviderRegistryShape => ({
1111
getProviders: Effect.succeed(providers),
12+
listSkills: () => Effect.succeed([]),
1213
refresh: () => Effect.succeed(providers),
1314
refreshInstance: () => Effect.succeed(providers),
1415
getProviderMaintenanceCapabilitiesForInstance: (_instanceId, provider) =>

‎apps/server/src/server.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,85 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
43424342
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
43434343
);
43444344

4345+
it.effect("routes websocket rpc server.listProviderSkills with the active workspace cwd", () =>
4346+
Effect.gen(function* () {
4347+
const instanceId = ProviderInstanceId.make("codex_work");
4348+
const projectId = ProjectId.make("project-skills");
4349+
const threadId = ThreadId.make("thread-skills");
4350+
const skills = [
4351+
{
4352+
name: "project-review",
4353+
path: "/tmp/project-worktree/.agents/skills/project-review/SKILL.md",
4354+
scope: "repo",
4355+
enabled: true,
4356+
},
4357+
] as const;
4358+
const receivedInputs: Array<{
4359+
readonly instanceId: ProviderInstanceId;
4360+
readonly cwd: string;
4361+
}> = [];
4362+
4363+
yield* buildAppUnderTest({
4364+
layers: {
4365+
providerRegistry: {
4366+
listSkills: (input) =>
4367+
Effect.sync(() => {
4368+
receivedInputs.push(input);
4369+
return skills;
4370+
}),
4371+
},
4372+
projectionSnapshotQuery: {
4373+
getProjectShellById: (requestedProjectId) =>
4374+
Effect.succeed(
4375+
Option.some({
4376+
...makeDefaultOrchestrationReadModel().projects[0]!,
4377+
id: requestedProjectId,
4378+
workspaceRoot: "/tmp/project",
4379+
}),
4380+
),
4381+
getThreadShellById: (requestedThreadId) =>
4382+
Effect.succeed(
4383+
Option.some(
4384+
makeDefaultOrchestrationThreadShell({
4385+
id: requestedThreadId,
4386+
projectId,
4387+
worktreePath: "/tmp/project-worktree",
4388+
}),
4389+
),
4390+
),
4391+
},
4392+
},
4393+
});
4394+
4395+
const wsUrl = yield* getWsServerUrl("/ws");
4396+
const responses = yield* Effect.scoped(
4397+
withWsRpcClient(wsUrl, (client) =>
4398+
Effect.gen(function* () {
4399+
const projectResponse = yield* client[WS_METHODS.serverListProviderSkills]({
4400+
instanceId,
4401+
projectId,
4402+
});
4403+
const threadResponse = yield* client[WS_METHODS.serverListProviderSkills]({
4404+
instanceId,
4405+
projectId,
4406+
threadId,
4407+
});
4408+
return [projectResponse, threadResponse] as const;
4409+
}),
4410+
),
4411+
);
4412+
4413+
assert.deepEqual(receivedInputs, [
4414+
{ instanceId, cwd: "/tmp/project" },
4415+
{ instanceId, cwd: "/tmp/project-worktree" },
4416+
]);
4417+
assert.deepEqual(
4418+
responses.map((response) => response.skills),
4419+
[skills, skills],
4420+
);
4421+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
4422+
);
4423+
43454424
it.effect("routes websocket rpc server.removeKeybinding", () =>
43464425
Effect.gen(function* () {
43474426
const rule: KeybindingRule = {

0 commit comments

Comments
 (0)