Skip to content

Commit 2b00ab1

Browse files
ScottN-PVclaudejuliusmarminge
authored
fix(claude): mid-sentence skill chips keep the full request (pingdotgg#15253)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 4ddc2f0 commit 2b00ab1

4 files changed

Lines changed: 191 additions & 154 deletions

File tree

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

Lines changed: 177 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,153 +1601,189 @@ describe("ClaudeAdapterV2 resume compaction", () => {
16011601
});
16021602

16031603
describe("ClaudeAdapterV2 attachments", () => {
1604-
it.effect("forwards images and references generic files on sends and steering", () =>
1605-
Effect.scoped(
1606-
Effect.gen(function* () {
1607-
const fileSystem = yield* FileSystem.FileSystem;
1608-
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1609-
const path = yield* Path.Path;
1610-
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1611-
prefix: "t3-claude-v2-attachments-",
1612-
});
1613-
const offeredMessages: Array<SDKUserMessage> = [];
1614-
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
1615-
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1616-
settings: DEFAULT_CLAUDE_SETTINGS,
1617-
environment: {},
1618-
attachmentsDir,
1619-
fileSystem,
1620-
path: yield* Path.Path,
1621-
crypto: yield* Crypto.Crypto,
1622-
idAllocator,
1623-
queryRunner: {
1624-
allocateSessionId: Effect.succeed("native-thread-claude-attachments"),
1625-
open: () =>
1626-
Effect.succeed({
1627-
messages: Stream.never,
1628-
offer: (message) =>
1629-
Effect.sync(() => {
1630-
offeredMessages.push(message);
1631-
}),
1632-
setModel: () => Effect.void,
1633-
applyFlagSettings: () => Effect.void,
1634-
setPermissionMode: () => Effect.void,
1635-
backgroundTasks: () => Effect.succeed(false),
1636-
stopTask: () => Effect.void,
1637-
interrupt: Effect.void,
1638-
close: Effect.void,
1639-
}),
1640-
forkSession: () => Effect.die("unused forkSession"),
1641-
subagentLaunchToolUseId: () => Effect.succeed(null),
1642-
assertComplete: Effect.void,
1643-
},
1644-
});
1645-
const threadId = ThreadId.make("thread-claude-attachments");
1646-
const providerSessionId = ProviderSessionId.make("provider-session-claude-attachments");
1647-
const runtime = yield* adapter.openSession({
1648-
threadId,
1649-
providerSessionId,
1650-
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1651-
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1652-
});
1653-
const providerThread = yield* runtime.ensureThread({
1654-
threadId,
1655-
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1656-
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1657-
});
1658-
const attachment = ChatImageAttachment.make({
1659-
type: "image",
1660-
id: ChatAttachmentId.make(
1661-
"thread-claude-attachments-12345678-1234-1234-1234-123456789abc",
1662-
),
1663-
name: "diagram.png",
1664-
mimeType: "image/png",
1665-
sizeBytes: 4,
1666-
});
1667-
const document = ChatFileAttachment.make({
1668-
type: "file",
1669-
id: ChatAttachmentId.make(
1670-
"thread-claude-attachments-abcdefab-1234-1234-1234-123456789abc",
1671-
),
1672-
name: "requirements.pdf",
1673-
mimeType: "application/pdf",
1674-
sizeBytes: 4,
1675-
});
1676-
yield* fileSystem.writeFile(
1677-
path.join(attachmentsDir, attachmentRelativePath(attachment)!),
1678-
Uint8Array.from([1, 2, 3, 4]),
1679-
);
1680-
yield* fileSystem.writeFile(
1681-
path.join(attachmentsDir, attachmentRelativePath(document)!),
1682-
Uint8Array.from([5, 6, 7, 8]),
1683-
);
1684-
const attemptId = RunAttemptId.make("attempt-claude-attachments");
1685-
const now = yield* DateTime.now;
1686-
1687-
yield* runtime.startTurn(
1688-
makeClaudeTestTurnInput({
1604+
it.effect.each([
1605+
{
1606+
name: "ordinary text",
1607+
prompt: "What’s in this image?",
1608+
expectedText: "Ultrathink:\nWhat’s in this image?",
1609+
command: undefined,
1610+
ultrathink: true,
1611+
},
1612+
{
1613+
name: "mid-sentence skill",
1614+
prompt: "please $implement fixes\n\nThen report the result",
1615+
expectedText: "Ultrathink:\nplease /implement fixes\n\nThen report the result",
1616+
command: "/implement fixes\n\nThen report the result",
1617+
ultrathink: true,
1618+
},
1619+
{
1620+
name: "prompt-leading skill",
1621+
prompt: "$implement fixes",
1622+
expectedText: "/implement fixes",
1623+
command: undefined,
1624+
ultrathink: false,
1625+
},
1626+
])(
1627+
"preserves $name with images and files on sends and steering",
1628+
({ prompt, expectedText, command, ultrathink }) =>
1629+
Effect.scoped(
1630+
Effect.gen(function* () {
1631+
const fileSystem = yield* FileSystem.FileSystem;
1632+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1633+
const path = yield* Path.Path;
1634+
const claudeHome = yield* fileSystem.makeTempDirectoryScoped({
1635+
prefix: "t3-claude-v2-skills-home-",
1636+
});
1637+
yield* fileSystem.makeDirectory(path.join(claudeHome, "skills", "implement"), {
1638+
recursive: true,
1639+
});
1640+
yield* fileSystem.writeFileString(
1641+
path.join(claudeHome, "skills", "implement", "SKILL.md"),
1642+
"---\ndescription: Implement the requested change\n---\nImplement it.\n",
1643+
);
1644+
const modelSelection = {
1645+
...CLAUDE_TEST_MODEL_SELECTION,
1646+
options: ultrathink ? CLAUDE_TEST_MODEL_SELECTION.options : [],
1647+
};
1648+
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1649+
prefix: "t3-claude-v2-attachments-",
1650+
});
1651+
const offeredMessages: Array<SDKUserMessage> = [];
1652+
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
1653+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1654+
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: claudeHome },
1655+
environment: {},
1656+
attachmentsDir,
1657+
fileSystem,
1658+
path: yield* Path.Path,
1659+
crypto: yield* Crypto.Crypto,
1660+
idAllocator,
1661+
queryRunner: {
1662+
allocateSessionId: Effect.succeed("native-thread-claude-attachments"),
1663+
open: () =>
1664+
Effect.succeed({
1665+
messages: Stream.never,
1666+
offer: (message) =>
1667+
Effect.sync(() => {
1668+
offeredMessages.push(message);
1669+
}),
1670+
setModel: () => Effect.void,
1671+
applyFlagSettings: () => Effect.void,
1672+
setPermissionMode: () => Effect.void,
1673+
backgroundTasks: () => Effect.succeed(false),
1674+
stopTask: () => Effect.void,
1675+
interrupt: Effect.void,
1676+
close: Effect.void,
1677+
}),
1678+
forkSession: () => Effect.die("unused forkSession"),
1679+
subagentLaunchToolUseId: () => Effect.succeed(null),
1680+
assertComplete: Effect.void,
1681+
},
1682+
});
1683+
const threadId = ThreadId.make("thread-claude-attachments");
1684+
const providerSessionId = ProviderSessionId.make("provider-session-claude-attachments");
1685+
const runtime = yield* adapter.openSession({
16891686
threadId,
1690-
providerThread,
1691-
now,
1692-
attemptId,
1693-
text: "What's in this image?",
1694-
attachments: [attachment, document],
1695-
}),
1696-
);
1687+
providerSessionId,
1688+
modelSelection,
1689+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1690+
});
1691+
const providerThread = yield* runtime.ensureThread({
1692+
threadId,
1693+
modelSelection,
1694+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1695+
});
1696+
const attachment = ChatImageAttachment.make({
1697+
type: "image",
1698+
id: ChatAttachmentId.make(
1699+
"thread-claude-attachments-12345678-1234-1234-1234-123456789abc",
1700+
),
1701+
name: "diagram.png",
1702+
mimeType: "image/png",
1703+
sizeBytes: 4,
1704+
});
1705+
const document = ChatFileAttachment.make({
1706+
type: "file",
1707+
id: ChatAttachmentId.make(
1708+
"thread-claude-attachments-abcdefab-1234-1234-1234-123456789abc",
1709+
),
1710+
name: "requirements.pdf",
1711+
mimeType: "application/pdf",
1712+
sizeBytes: 4,
1713+
});
1714+
yield* fileSystem.writeFile(
1715+
path.join(attachmentsDir, attachmentRelativePath(attachment)!),
1716+
Uint8Array.from([1, 2, 3, 4]),
1717+
);
1718+
yield* fileSystem.writeFile(
1719+
path.join(attachmentsDir, attachmentRelativePath(document)!),
1720+
Uint8Array.from([5, 6, 7, 8]),
1721+
);
1722+
const attemptId = RunAttemptId.make("attempt-claude-attachments");
1723+
const now = yield* DateTime.now;
16971724

1698-
const expectedImageBlock = {
1699-
type: "image",
1700-
source: {
1701-
type: "base64",
1702-
media_type: "image/png",
1703-
data: "AQIDBA==",
1704-
},
1705-
} as const;
1706-
const expectedAttachmentPath = path.join(
1707-
attachmentsDir,
1708-
attachmentRelativePath(attachment)!,
1709-
);
1710-
const expectedDocumentPath = path.join(attachmentsDir, attachmentRelativePath(document)!);
1711-
assert.deepEqual(offeredMessages[0]?.message.content, [
1712-
expectedImageBlock,
1713-
{
1714-
type: "text",
1715-
text: `Ultrathink:\nWhat's in this image?\n\n[Attached image "diagram.png" is saved at: ${expectedAttachmentPath}]\n\n[Attached file "requirements.pdf" is saved at: ${expectedDocumentPath}]`,
1716-
},
1717-
]);
1725+
yield* runtime.startTurn(
1726+
makeClaudeTestTurnInput({
1727+
threadId,
1728+
providerThread,
1729+
now,
1730+
attemptId,
1731+
modelSelection,
1732+
text: prompt,
1733+
attachments: [attachment, document],
1734+
}),
1735+
);
17181736

1719-
const providerTurnId = idAllocator.derive.providerTurn({
1720-
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1721-
nativeTurnId: `turn:${attemptId}`,
1722-
});
1723-
yield* runtime.steerTurn({
1724-
threadId,
1725-
runId: RunId.make("run-claude-attachments"),
1726-
providerThread,
1727-
providerTurnId,
1728-
message: {
1729-
createdBy: "user",
1730-
creationSource: "web",
1731-
messageId: MessageId.make("message-claude-attachments-steer"),
1732-
text: "Focus on the diagram labels.",
1733-
attachments: [attachment, document],
1734-
},
1735-
});
1737+
const expectedImageBlock = {
1738+
type: "image",
1739+
source: {
1740+
type: "base64",
1741+
media_type: "image/png",
1742+
data: "AQIDBA==",
1743+
},
1744+
} as const;
1745+
const expectedAttachmentPath = path.join(
1746+
attachmentsDir,
1747+
attachmentRelativePath(attachment)!,
1748+
);
1749+
const expectedDocumentPath = path.join(attachmentsDir, attachmentRelativePath(document)!);
1750+
const attachmentNotes = `\n\n[Attached image "diagram.png" is saved at: ${expectedAttachmentPath}]\n\n[Attached file "requirements.pdf" is saved at: ${expectedDocumentPath}]`;
1751+
const requestBlock = { type: "text" as const, text: expectedText + attachmentNotes };
1752+
const expectedContent = command
1753+
? [
1754+
requestBlock,
1755+
expectedImageBlock,
1756+
{ type: "text" as const, text: command + attachmentNotes },
1757+
]
1758+
: [expectedImageBlock, requestBlock];
1759+
assert.deepEqual(offeredMessages[0]?.message.content, expectedContent);
17361760

1737-
assert.equal(offeredMessages[1]?.priority, "now");
1738-
assert.deepEqual(offeredMessages[1]?.message.content, [
1739-
expectedImageBlock,
1740-
{
1741-
type: "text",
1742-
text: `Ultrathink:\nFocus on the diagram labels.\n\n[Attached image "diagram.png" is saved at: ${expectedAttachmentPath}]\n\n[Attached file "requirements.pdf" is saved at: ${expectedDocumentPath}]`,
1743-
},
1744-
]);
1745-
}).pipe(
1746-
Effect.provide(
1747-
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1761+
const providerTurnId = idAllocator.derive.providerTurn({
1762+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1763+
nativeTurnId: `turn:${attemptId}`,
1764+
});
1765+
yield* runtime.steerTurn({
1766+
threadId,
1767+
runId: RunId.make("run-claude-attachments"),
1768+
providerThread,
1769+
providerTurnId,
1770+
message: {
1771+
createdBy: "user",
1772+
creationSource: "web",
1773+
messageId: MessageId.make("message-claude-attachments-steer"),
1774+
text: prompt,
1775+
attachments: [attachment, document],
1776+
},
1777+
});
1778+
1779+
assert.equal(offeredMessages[1]?.priority, "now");
1780+
assert.deepEqual(offeredMessages[1]?.message.content, expectedContent);
1781+
}).pipe(
1782+
Effect.provide(
1783+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1784+
),
17481785
),
17491786
),
1750-
),
17511787
);
17521788

17531789
it.effect("rejects unsupported image types before opening a provider query", () =>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,10 @@ export function makeClaudeUserMessage(input: {
15961596
readonly uuid?: SDKUserMessage["uuid"];
15971597
}): SDKUserMessage {
15981598
// Claude Code expands a skill only from the LAST text block, and only when
1599-
// `/name` is its first character. A `$skill` chip anywhere in the prompt is
1600-
// therefore split into [leading text, "/name trailing text"] so the CLI runs
1601-
// it natively and the prose around it survives.
1599+
// `/name` is its first character. A `$skill` chip anywhere in the prompt
1600+
// therefore becomes [whole request, "/name trailing text"] so the CLI runs
1601+
// it natively and the model still reads the full request. See
1602+
// ClaudeSkillDispatch.
16021603
const dispatch =
16031604
input.skillNames === undefined
16041605
? undefined

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe("planClaudeSkillDispatch", () => {
1010
expect(planClaudeSkillDispatch("echo $HOME then $unknown", SKILLS)).toBeUndefined();
1111
});
1212

13-
it("moves a mid-prompt mention into a trailing slash command", () => {
13+
it("keeps the whole request ahead of a mid-prompt slash command", () => {
1414
expect(planClaudeSkillDispatch("ok, now $implement all the tickets", SKILLS)).toEqual({
15-
leadingText: "ok, now",
15+
leadingText: "ok, now /implement all the tickets",
1616
commandText: "/implement all the tickets",
1717
skillName: "implement",
1818
});
@@ -28,15 +28,15 @@ describe("planClaudeSkillDispatch", () => {
2828

2929
it("dispatches a known skill whose name begins with a digit", () => {
3030
expect(planClaudeSkillDispatch("use $2spec for this", SKILLS)).toEqual({
31-
leadingText: "use",
31+
leadingText: "use /2spec for this",
3232
commandText: "/2spec for this",
3333
skillName: "2spec",
3434
});
3535
});
3636

3737
it("dispatches the last mention and rewrites earlier ones inline", () => {
3838
expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({
39-
leadingText: "/review the diff, then",
39+
leadingText: "/review the diff, then /implement the fixes",
4040
commandText: "/implement the fixes",
4141
skillName: "implement",
4242
});
@@ -50,7 +50,7 @@ describe("planClaudeSkillDispatch", () => {
5050
SKILLS,
5151
),
5252
).toEqual({
53-
leadingText: "/review the diff, then",
53+
leadingText: "/review the diff, then /implement the fixes",
5454
commandText: "/implement the fixes",
5555
skillName: "implement",
5656
});

0 commit comments

Comments
 (0)