@@ -1601,153 +1601,189 @@ describe("ClaudeAdapterV2 resume compaction", () => {
16011601});
16021602
16031603describe("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", () =>
0 commit comments