Skip to content

Commit bb01f78

Browse files
fix(server): decide agent skill breaks in the adapters from the real skill list
The service-level rewrite had to guess skill names: the registry missed project skills, and breaking every lowercase sigil corrupted shell variables and filenames such as $result or posts.$postId.tsx. The Claude and Codex adapters already see the message's sender and the thread's real skills at dispatch, so neutralize there and only for names that are skills: - Claude skips T3 skill dispatch for another agent's text and puts a word joiner before a leading /name only when name is a real skill. - Codex keeps an agent's text as sent, breaking only $name mentions of skills from skills/list for the session cwd (all $name if that list cannot be read). ThreadManagementService forwards the text unchanged again. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 38de69c commit bb01f78

7 files changed

Lines changed: 213 additions & 175 deletions

File tree

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

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,37 @@ describe("ClaudeAdapterV2 attachments", () => {
18721872
resumed: false,
18731873
budget: "none",
18741874
},
1875+
// https://git.cafe/pingdotgg/t3code/issues/24667
1876+
{
1877+
name: "another agent's mid-sentence skill as text",
1878+
prompt: "please $implement fixes",
1879+
expectedText: "please $implement fixes",
1880+
command: undefined,
1881+
ultrathink: false,
1882+
resumed: false,
1883+
budget: "none",
1884+
agent: true,
1885+
},
1886+
{
1887+
name: "another agent's prompt-leading skill command as text",
1888+
prompt: "/implement fixes",
1889+
expectedText: "\u2060/implement fixes",
1890+
command: undefined,
1891+
ultrathink: false,
1892+
resumed: false,
1893+
budget: "none",
1894+
agent: true,
1895+
},
1896+
{
1897+
name: "another agent's leading path",
1898+
prompt: "/tmp holds the output",
1899+
expectedText: "/tmp holds the output",
1900+
command: undefined,
1901+
ultrathink: false,
1902+
resumed: false,
1903+
budget: "none",
1904+
agent: true,
1905+
},
18751906
{
18761907
name: "resumed history without persisted counters",
18771908
prompt: "Inspect this file",
@@ -1883,7 +1914,7 @@ describe("ClaudeAdapterV2 attachments", () => {
18831914
},
18841915
])(
18851916
"preserves $name with native PDFs, images, and paths on sends and steering",
1886-
({ prompt, expectedText, command, ultrathink, resumed, budget }) =>
1917+
({ prompt, expectedText, command, ultrathink, resumed, budget, ...row }) =>
18871918
Effect.scoped(
18881919
Effect.gen(function* () {
18891920
const fileSystem = yield* FileSystem.FileSystem;
@@ -2021,16 +2052,23 @@ describe("ClaudeAdapterV2 attachments", () => {
20212052
const attemptId = RunAttemptId.make("attempt-claude-attachments");
20222053
const now = yield* DateTime.now;
20232054

2055+
const baseTurnInput = makeClaudeTestTurnInput({
2056+
threadId,
2057+
providerThread,
2058+
now,
2059+
attemptId,
2060+
modelSelection,
2061+
text: prompt,
2062+
attachments: resumed ? [attachment] : [attachment, document],
2063+
});
20242064
const turnInput = {
2025-
...makeClaudeTestTurnInput({
2026-
threadId,
2027-
providerThread,
2028-
now,
2029-
attemptId,
2030-
modelSelection,
2031-
text: prompt,
2032-
attachments: resumed ? [attachment] : [attachment, document],
2033-
}),
2065+
...baseTurnInput,
2066+
message: {
2067+
...baseTurnInput.message,
2068+
...("agent" in row
2069+
? { createdBy: "agent" as const, senderThreadId: ThreadId.make("thread:sender") }
2070+
: {}),
2071+
},
20342072
nativeThreadHasTurns: resumed,
20352073
};
20362074
if (budget === "cancelled-send" || budget === "cancelled-steer") {
@@ -2276,10 +2314,8 @@ describe("ClaudeAdapterV2 attachments", () => {
22762314
providerThread,
22772315
providerTurnId,
22782316
message: {
2279-
createdBy: "user",
2280-
creationSource: "web",
2317+
...turnInput.message,
22812318
messageId: MessageId.make("message-claude-attachments-steer"),
2282-
text: prompt,
22832319
attachments: resumed ? [attachment] : [attachment, document],
22842320
},
22852321
});

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ import { resolveAttachmentPath } from "../../attachmentStore.ts";
160160
import { snapshotMcpApp } from "../../mcpApps/McpAppSnapshot.ts";
161161
import { resolveClaudeSdkExecutablePath } from "../../provider/Drivers/ClaudeExecutable.ts";
162162
import {
163+
neutralizeAgentClaudeSkill,
163164
planClaudeSkillDispatch,
164165
type ClaudeSkillTarget,
165166
} from "../../provider/Drivers/ClaudeSkillDispatch.ts";
@@ -5098,6 +5099,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
50985099
Effect.provideService(Path.Path, path),
50995100
);
51005101

5102+
const claudePrompt = (
5103+
message: { readonly text: string; readonly senderThreadId?: ThreadId | undefined },
5104+
cwd: string | null,
5105+
) =>
5106+
userInvocableSkills(cwd).pipe(
5107+
Effect.map((skills) =>
5108+
message.senderThreadId === undefined
5109+
? { text: message.text, skills }
5110+
: { text: neutralizeAgentClaudeSkill(message.text, skills), skills: undefined },
5111+
),
5112+
);
5113+
51015114
return ProviderAdapter.ProviderAdapterV2.of({
51025115
instanceId: adapterOptions.instanceId,
51035116
driver: CLAUDE_PROVIDER,
@@ -11235,20 +11248,21 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1123511248
pdfBudgets.get(nativeThreadId)!,
1123611249
persistAttachmentBudget(nativeThreadId),
1123711250
);
11251+
const prompt = yield* claudePrompt(turnInput.message, turnInput.runtimePolicy.cwd);
1123811252
const userMessage =
1123911253
promptUuid === null
1124011254
? null
1124111255
: yield* makeClaudeUserMessageWithAttachments({
1124211256
text: applyClaudePromptEffortPrefix(
11243-
turnInput.message.text,
11257+
prompt.text,
1124411258
compileClaudeModelSelection(turnInput.modelSelection, modelCatalog)
1124511259
.promptEffort,
1124611260
),
1124711261
attachments: turnInput.message.attachments,
1124811262
attachmentsDir,
1124911263
fileSystem,
1125011264
pdfReservation,
11251-
skills: yield* userInvocableSkills(turnInput.runtimePolicy.cwd),
11265+
...(prompt.skills === undefined ? {} : { skills: prompt.skills }),
1125211266
uuid: promptUuid,
1125311267
}).pipe(
1125411268
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
@@ -11701,9 +11715,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1170111715
}),
1170211716
persistAttachmentBudget(existing.nativeThreadId),
1170311717
);
11718+
const prompt = yield* claudePrompt(
11719+
turnInput.message,
11720+
currentTurn.input.runtimePolicy.cwd,
11721+
);
1170411722
const userMessage = yield* makeClaudeUserMessageWithAttachments({
1170511723
text: applyClaudePromptEffortPrefix(
11706-
turnInput.message.text,
11724+
prompt.text,
1170711725
compileClaudeModelSelection(currentTurn.input.modelSelection, modelCatalog)
1170811726
.promptEffort,
1170911727
),
@@ -11712,7 +11730,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1171211730
attachmentsDir,
1171311731
fileSystem,
1171411732
pdfReservation,
11715-
skills: yield* userInvocableSkills(currentTurn.input.runtimePolicy.cwd),
11733+
...(prompt.skills === undefined ? {} : { skills: prompt.skills }),
1171611734
}).pipe(
1171711735
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
1171811736
Effect.provideService(Path.Path, path),

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,99 @@ describe("CodexAdapterV2 post-settle continuation", () => {
25052505
),
25062506
);
25072507

2508+
// https://git.cafe/pingdotgg/t3code/issues/24667
2509+
it.effect("keeps another agent's mentions of the recipient's skills as text", () =>
2510+
Effect.scoped(
2511+
Effect.gen(function* () {
2512+
const nativeThreadId = "agent-mention-thread";
2513+
const nativeTurnId = "agent-mention-turn";
2514+
const prompt =
2515+
'Use ($review), then result=ready; printf "%s" "$result" in posts.$postId.tsx';
2516+
const preamble = codexReplayPreamble({
2517+
nativeThreadId,
2518+
nativeTurnId,
2519+
prompt,
2520+
sentPrompt: prompt.replace("$review", "$\u2060review"),
2521+
});
2522+
const transcript = makeCodexReplayTranscript({
2523+
scenario: "agent-skill-mention",
2524+
entries: [
2525+
...preamble.slice(0, 5),
2526+
{
2527+
type: "expect_outbound",
2528+
label: "skills/list",
2529+
frame: { id: 3, method: "skills/list", params: { cwds: ["/workspace"] } },
2530+
},
2531+
{
2532+
type: "emit_inbound",
2533+
label: "skills/list",
2534+
frame: {
2535+
id: 3,
2536+
result: {
2537+
data: [
2538+
{
2539+
cwd: "/workspace",
2540+
skills: [
2541+
{
2542+
name: "review",
2543+
description: "Review the change",
2544+
path: "/skills/review/SKILL.md",
2545+
enabled: true,
2546+
scope: "repo",
2547+
},
2548+
],
2549+
errors: [],
2550+
},
2551+
],
2552+
},
2553+
},
2554+
},
2555+
...preamble.slice(5, 7).map((entry) => withReplayRequestId(entry, 4)),
2556+
...preamble.slice(7),
2557+
{
2558+
type: "emit_inbound",
2559+
label: "done",
2560+
frame: {
2561+
method: "turn/completed",
2562+
params: {
2563+
threadId: nativeThreadId,
2564+
turn: makeCodexReplayTurn({ id: nativeTurnId, status: "completed" }),
2565+
},
2566+
},
2567+
},
2568+
],
2569+
});
2570+
const harness = yield* makeCodexReplayHarness(transcript);
2571+
const turnInput = makeCodexTestTurnInput({
2572+
threadId: harness.threadId,
2573+
providerThread: harness.providerThread,
2574+
now: yield* DateTime.now,
2575+
attemptId: RunAttemptId.make("agent-mention-attempt"),
2576+
text: prompt,
2577+
});
2578+
yield* harness.runtime.startTurn({
2579+
...turnInput,
2580+
message: {
2581+
...turnInput.message,
2582+
createdBy: "agent",
2583+
senderThreadId: ThreadId.make("thread:sender"),
2584+
},
2585+
});
2586+
yield* harness.firstTerminal;
2587+
assert.equal(harness.terminalEvents()[0]?.status, "completed");
2588+
}).pipe(
2589+
Effect.provide(
2590+
Layer.mergeAll(
2591+
IdAllocator.layer,
2592+
McpProviderSessions.layer,
2593+
NodeServices.layer,
2594+
NodeCrypto.layer,
2595+
),
2596+
),
2597+
),
2598+
),
2599+
);
2600+
25082601
it.effect("compacts Codex with the native RPC and completes the compaction turn", () =>
25092602
Effect.scoped(
25102603
Effect.gen(function* () {

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,20 @@ function codexSkillMentionText(text: string): string {
443443
return text.replace(SKILL_MENTION_PATTERN, "$1$$$2");
444444
}
445445

446+
/**
447+
* Text another agent sent must not run the recipient's skills. Codex expands `$name` even inside
448+
* punctuation, so a word joiner breaks each mention of a skill it has (every `$name` when the
449+
* skill list is unavailable); other `$` text is kept.
450+
*/
451+
function neutralizeAgentCodexSkills(
452+
text: string,
453+
skillNames: ReadonlySet<string> | undefined,
454+
): string {
455+
return text.replace(/\$([a-zA-Z0-9_:-]+)/gu, (match, name: string) =>
456+
skillNames === undefined || skillNames.has(name) ? `$\u2060${name}` : match,
457+
);
458+
}
459+
446460
const BACKGROUND_COMMAND_DETAIL_COMMAND_MAX_LENGTH = 200;
447461
const BACKGROUND_COMMAND_DETAIL_OUTPUT_TAIL_MAX_LENGTH = 1_000;
448462

@@ -3371,6 +3385,21 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
33713385
},
33723386
);
33733387

3388+
const sessionCwd = input.runtimePolicy.cwd;
3389+
const codexSkillNames =
3390+
sessionCwd === null
3391+
? Effect.undefined
3392+
: ensureInitialized.pipe(
3393+
Effect.andThen(client.request("skills/list", { cwds: [sessionCwd] })),
3394+
Effect.map(
3395+
(response) =>
3396+
new Set(
3397+
response.data.flatMap((entry) => entry.skills.map((skill) => skill.name)),
3398+
),
3399+
),
3400+
Effect.orElseSucceed(() => undefined),
3401+
);
3402+
33743403
const toCodexInput = Effect.fn("CodexAdapterV2.toCodexInput")(function* (
33753404
turnInput: Pick<
33763405
| ProviderAdapter.ProviderAdapterV2TurnInput
@@ -3380,7 +3409,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
33803409
) {
33813410
const inputItems: Array<CodexSchema.V2TurnStartParams__UserInput> = [];
33823411
const text = yield* providerMessageTextWithAttachmentPaths({
3383-
text: codexSkillMentionText(turnInput.message.text),
3412+
text:
3413+
turnInput.message.senderThreadId === undefined
3414+
? codexSkillMentionText(turnInput.message.text)
3415+
: neutralizeAgentCodexSkills(turnInput.message.text, yield* codexSkillNames),
33843416
attachments: turnInput.message.attachments,
33853417
resolveExtractedTextPath: (path) =>
33863418
DocumentText.resolveExtractedTextPath(path).pipe(

0 commit comments

Comments
 (0)