Skip to content

Commit 3ca8643

Browse files
feat(server): configure skills per Codex session
1 parent 5211acf commit 3ca8643

17 files changed

Lines changed: 858 additions & 46 deletions

‎apps/server/src/mcp/OrchestratorMcpService.activity.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ProjectId,
77
ProviderDriverKind,
88
ProviderInstanceId,
9+
ProviderThreadId,
910
RunId,
1011
ScheduledTaskId,
1112
ThreadId,
@@ -117,6 +118,12 @@ function makeRun(input: {
117118
}
118119

119120
it("readThread prefers activity-run status over a newer cancelled queued run", async () => {
121+
const providerThreadId = ProviderThreadId.make("provider-thread-mcp-active");
122+
const skillConfiguration = {
123+
providerVersion: "0.165.0",
124+
overrides: [{ path: "/skills/review/SKILL.md", enabled: false }],
125+
skills: [{ name: "review", path: "/skills/review/SKILL.md", enabled: false }],
126+
};
120127
const projection = {
121128
thread: baseThread({
122129
threadId: parentThreadId,
@@ -125,9 +132,10 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
125132
model: "gpt-5.4",
126133
}),
127134
runs: [
128-
makeRun({ id: activeRunId, ordinal: 1, status: "running" }),
135+
{ ...makeRun({ id: activeRunId, ordinal: 1, status: "running" }), providerThreadId },
129136
makeRun({ id: cancelledRunId, ordinal: 2, status: "cancelled" }),
130137
],
138+
providerThreads: [{ id: providerThreadId, nativeMetadata: { skillConfiguration } }],
131139
visibleTurnItems: [],
132140
runtimeRequests: [],
133141
messages: [],
@@ -180,6 +188,7 @@ it("readThread prefers activity-run status over a newer cancelled queued run", a
180188
expect(result.thread.status).toBe("running");
181189
expect(result.thread.latestRunId).toBe(cancelledRunId);
182190
expect(result.thread.activeRunId).toBe(activeRunId);
191+
expect(result.thread.skillConfiguration).toEqual(skillConfiguration);
183192
}).pipe(Effect.provide(layer), Effect.runPromise);
184193
});
185194

@@ -356,6 +365,7 @@ it("readThread and sendToThread reach threads in other projects", async () => {
356365
},
357366
],
358367
runtimeRequests: [],
368+
providerThreads: [],
359369
messages: [],
360370
contextTransfers: [],
361371
subagents: [],

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,6 +2494,7 @@ describe("OrchestratorMcpService provider resolution", () => {
24942494
const inherited = {
24952495
instanceId: codexInstanceId,
24962496
model: "gpt-5.4",
2497+
skillOverrides: [{ path: "/skills/review/SKILL.md", enabled: false }],
24972498
options: [
24982499
{ id: "reasoningEffort", value: "high" },
24992500
{ id: "serviceTier", value: "priority" },
@@ -2567,14 +2568,18 @@ describe("OrchestratorMcpService provider resolution", () => {
25672568
driver,
25682569
model: inherited.model,
25692570
}),
2571+
version: "0.165.0",
25702572
models: [inherited.model, "other-model"].map((model) => ({
25712573
slug: model,
25722574
name: model,
25732575
isCustom: false,
25742576
capabilities: null,
25752577
})),
25762578
},
2577-
providerSnapshot({ instanceId: peerId, driver, model: inherited.model }),
2579+
{
2580+
...providerSnapshot({ instanceId: peerId, driver, model: inherited.model }),
2581+
version: "0.165.0",
2582+
},
25782583
]),
25792584
adapterRegistryLayer([codexInstanceId, peerId]),
25802585
Layer.mock(ProjectService.ProjectService)({}),
@@ -2592,9 +2597,18 @@ describe("OrchestratorMcpService provider resolution", () => {
25922597
mode: "async",
25932598
clientRequestId: testCase.name,
25942599
});
2600+
const refused = yield* service
2601+
.delegateTask(scope, {
2602+
task: "Review the change.",
2603+
target: yield* decodeTarget({ skillOverrides: [] }),
2604+
mode: "async",
2605+
clientRequestId: `${testCase.name}-clear-skills`,
2606+
})
2607+
.pipe(Effect.flip);
2608+
assert.equal(refused.code, "invalid_request");
25952609
assert.deepEqual(
25962610
(commands[0] as { modelSelection: unknown }).modelSelection,
2597-
testCase.expected,
2611+
{ ...testCase.expected, skillOverrides: inherited.skillOverrides },
25982612
testCase.name,
25992613
);
26002614
}).pipe(Effect.provide(layerOrchestratorService.pipe(Layer.provide(dependencies))));

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { skillOverridesEqual } from "@t3tools/shared/model";
2+
import { supportsCodexSkillOverrides } from "../provider/CodexSkillOverrides.ts";
13
import {
24
CommandId,
35
type EnvironmentId,
@@ -783,14 +785,25 @@ function listItemFromShell(
783785

784786
function threadDetail(
785787
environmentId: EnvironmentId,
786-
projection: Pick<OrchestrationV2ThreadProjection, "thread" | "runs" | "runtimeRequests">,
788+
projection: Pick<
789+
OrchestrationV2ThreadProjection,
790+
"thread" | "runs" | "runtimeRequests" | "providerThreads"
791+
>,
787792
itemCount: number,
788793
shell: OrchestrationV2ThreadShell,
789794
nowMs: number,
790795
): OrchestratorMcpThreadDetail {
791796
const latest = ThreadManagementService.latestRun(projection);
792797
const active = ThreadManagementService.latestActiveRun(projection);
798+
const skillConfiguration = projection.providerThreads.find(
799+
(thread) =>
800+
thread.id ===
801+
(active?.providerThreadId ??
802+
latest?.providerThreadId ??
803+
projection.thread.activeProviderThreadId),
804+
)?.nativeMetadata?.skillConfiguration;
793805
return {
806+
...(skillConfiguration === undefined ? {} : { skillConfiguration }),
794807
threadId: projection.thread.id,
795808
projectId: projection.thread.projectId,
796809
title: projection.thread.title,
@@ -1206,6 +1219,7 @@ const make = Effect.gen(function* () {
12061219
"runs",
12071220
"runtimeRequests",
12081221
"contextTransfers",
1222+
"providerThreads",
12091223
])
12101224
.pipe(Effect.mapError(threadManagementFailure));
12111225
return { parent, target, shell } as const;
@@ -1354,6 +1368,27 @@ const make = Effect.gen(function* () {
13541368
);
13551369
}
13561370

1371+
const skillOverrides = input.target?.skillOverrides ?? inheritedSelection.skillOverrides;
1372+
if (
1373+
skillOverrides !== undefined &&
1374+
(provider.driver !== "codex" || !supportsCodexSkillOverrides(provider.version ?? ""))
1375+
) {
1376+
return yield* failure(
1377+
"invalid_request",
1378+
"Session skill overrides require Codex 0.165.0 or newer.",
1379+
);
1380+
}
1381+
if (
1382+
inheritedSelection.skillOverrides !== undefined &&
1383+
input.target?.skillOverrides !== undefined &&
1384+
!skillOverridesEqual(input.target.skillOverrides, inheritedSelection.skillOverrides)
1385+
) {
1386+
return yield* failure(
1387+
"invalid_request",
1388+
"A restricted child cannot replace its inherited skill overrides.",
1389+
);
1390+
}
1391+
13571392
const requestedOptions = input.target?.options;
13581393
if (requestedOptions !== undefined) {
13591394
const descriptors = provider.models.find((candidate) => candidate.slug === model)
@@ -1383,7 +1418,12 @@ const make = Effect.gen(function* () {
13831418
options = [...selections.values()];
13841419
}
13851420
return {
1386-
modelSelection: { instanceId, model, ...(options === undefined ? {} : { options }) },
1421+
modelSelection: {
1422+
instanceId,
1423+
model,
1424+
...(options === undefined ? {} : { options }),
1425+
...(skillOverrides === undefined ? {} : { skillOverrides }),
1426+
},
13871427
supportedRuntimeModes: provider.supportedRuntimeModes,
13881428
};
13891429
});
@@ -1522,6 +1562,9 @@ const make = Effect.gen(function* () {
15221562
instanceId: task.providerInstanceId,
15231563
model: task.model,
15241564
};
1565+
const skillConfiguration = childProjection.providerThreads.find(
1566+
(candidate) => candidate.id === childRun?.providerThreadId,
1567+
)?.nativeMetadata?.skillConfiguration;
15251568
const result = {
15261569
taskId: task.id,
15271570
childThreadId: task.childThreadId,
@@ -1536,7 +1579,11 @@ const make = Effect.gen(function* () {
15361579
hasPendingChildRuns: hasPendingChildRuns(childProjection, childRun),
15371580
providerInstanceId: modelSelection.instanceId,
15381581
model: modelSelection.model,
1582+
...(skillConfiguration === undefined ? {} : { skillConfiguration }),
15391583
options: modelSelection.options ?? [],
1584+
...(modelSelection.skillOverrides === undefined
1585+
? {}
1586+
: { skillOverrides: modelSelection.skillOverrides }),
15401587
summary: derivedResult,
15411588
resultContextTransferId,
15421589
latestTerminalRunId: terminalRun?.id ?? null,
@@ -2121,6 +2168,9 @@ const make = Effect.gen(function* () {
21212168
inheritedProviderInstanceId: inherited?.instanceId ?? null,
21222169
inheritedModel: inherited?.model ?? null,
21232170
inheritedOptions: inherited?.options ?? [],
2171+
...(inherited?.skillOverrides === undefined
2172+
? {}
2173+
: { inheritedSkillOverrides: inherited.skillOverrides }),
21242174
runtimeMode: limits.runtimeMode,
21252175
interactionMode: limits.interactionMode,
21262176
providers: providers.map((provider) => {
@@ -2143,6 +2193,8 @@ const make = Effect.gen(function* () {
21432193
return {
21442194
providerInstanceId: provider.instanceId,
21452195
driverKind: provider.driver,
2196+
supportsSessionSkillOverrides:
2197+
provider.driver === "codex" && supportsCodexSkillOverrides(provider.version ?? ""),
21462198
displayName: provider.displayName ?? null,
21472199
models: listed.map((model) => {
21482200
const options = model.capabilities?.optionDescriptors ?? [];

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ProviderSkillOverrides } from "@t3tools/contracts";
12
import { historyResponseItems } from "@t3tools/provider-core/server/handoffBudget";
23
import {
34
makeProviderTextDeltaCoalescer,
@@ -917,10 +918,13 @@ describe("CodexAdapterV2 session initialize", () => {
917918
runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
918919
});
919920
return {
920-
ensureThread: (threadId: string) =>
921+
ensureThread: (threadId: string, skillOverrides?: ProviderSkillOverrides) =>
921922
runtime.ensureThread({
922923
threadId: ThreadId.make(threadId),
923-
modelSelection: CODEX_TEST_MODEL_SELECTION,
924+
modelSelection: {
925+
...CODEX_TEST_MODEL_SELECTION,
926+
...(skillOverrides === undefined ? {} : { skillOverrides }),
927+
},
924928
runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
925929
}),
926930
initializeRequests: () => initializeRequests,
@@ -930,6 +934,113 @@ describe("CodexAdapterV2 session initialize", () => {
930934
const replayPreamble = (nativeThreadId: string) =>
931935
codexReplayPreamble({ nativeThreadId, nativeTurnId: "unused", prompt: "unused" });
932936

937+
it.effect(
938+
"applies skill overrides before starting a native thread and records the resolved inventory",
939+
() =>
940+
Effect.gen(function* () {
941+
const fs = yield* FileSystem.FileSystem;
942+
const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-skill-config-" });
943+
const skillPath = `${directory}/SKILL.md`;
944+
yield* fs.writeFileString(skillPath, "sentinel");
945+
const preamble = replayPreamble("skill-configured");
946+
const initial = preamble.slice(0, 3).map((entry) =>
947+
entry.type === "emit_inbound" &&
948+
Predicate.isObject(entry.frame) &&
949+
Predicate.isObject(entry.frame.result)
950+
? {
951+
...entry,
952+
frame: {
953+
...entry.frame,
954+
result: { ...entry.frame.result, userAgent: "codex_cli_rs/0.165.0" },
955+
},
956+
}
957+
: entry,
958+
);
959+
const config = {
960+
"skills.config": [{ path: skillPath, enabled: false }],
961+
"features.multi_agent": false,
962+
};
963+
const session = yield* openReplaySession(
964+
makeCodexReplayTranscript({
965+
scenario: "session-skill-overrides",
966+
entries: [
967+
...initial,
968+
{
969+
type: "expect_outbound",
970+
label: "skills/list",
971+
frame: {
972+
id: 2,
973+
method: "skills/list",
974+
params: { cwds: ["/workspace"], forceReload: true },
975+
},
976+
},
977+
{
978+
type: "emit_inbound",
979+
label: "skills/list",
980+
frame: {
981+
id: 2,
982+
result: {
983+
data: [
984+
{
985+
cwd: "/workspace",
986+
skills: [
987+
{
988+
name: "review",
989+
path: skillPath,
990+
enabled: true,
991+
description: "Review",
992+
scope: "user",
993+
},
994+
],
995+
errors: [],
996+
},
997+
],
998+
},
999+
},
1000+
},
1001+
{
1002+
type: "expect_outbound",
1003+
label: "config/read",
1004+
frame: {
1005+
id: 3,
1006+
method: "config/read",
1007+
params: { cwd: "/workspace", includeLayers: false },
1008+
},
1009+
},
1010+
{
1011+
type: "emit_inbound",
1012+
label: "config/read",
1013+
frame: { id: 3, result: { config: {}, origins: {} } },
1014+
},
1015+
{
1016+
type: "expect_outbound",
1017+
label: "thread/start",
1018+
frame: {
1019+
id: 4,
1020+
method: "thread/start",
1021+
params: { config: { ...CodexAdapterV2.CODEX_THREAD_CONFIG, ...config } },
1022+
},
1023+
},
1024+
...preamble.slice(4, 5).map((entry) => withReplayRequestId(entry, 4)),
1025+
],
1026+
}),
1027+
);
1028+
const thread = yield* session.ensureThread("thread-skills", [
1029+
{ path: skillPath, enabled: false },
1030+
]);
1031+
assert.deepEqual(thread.nativeMetadata?.skillConfiguration, {
1032+
providerVersion: "0.165.0",
1033+
overrides: [{ path: skillPath, enabled: false }],
1034+
skills: [{ name: "review", path: skillPath, enabled: false }],
1035+
});
1036+
}).pipe(
1037+
Effect.scoped,
1038+
Effect.provide(
1039+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1040+
),
1041+
),
1042+
);
1043+
9331044
it.effect("sends one initialize when two threads start on a fresh session at once", () =>
9341045
Effect.gen(function* () {
9351046
const initializeAwaitingResponse = yield* Deferred.make<void>();

0 commit comments

Comments
 (0)