@@ -1749,66 +1749,77 @@ describe("ClaudeAdapterV2 attachments", () => {
17491749});
17501750
17511751describe("ClaudeAdapterV2 skill dispatch", () => {
1752+ const makeSkillDispatchHarness = Effect.gen(function* () {
1753+ const fileSystem = yield* FileSystem.FileSystem;
1754+ const path = yield* Path.Path;
1755+ const claudeHome = yield* fileSystem.makeTempDirectoryScoped({
1756+ prefix: "t3-claude-v2-skills-home-",
1757+ });
1758+ yield* fileSystem.makeDirectory(path.join(claudeHome, "skills", "implement"), {
1759+ recursive: true,
1760+ });
1761+ yield* fileSystem.writeFileString(
1762+ path.join(claudeHome, "skills", "implement", "SKILL.md"),
1763+ "---\ndescription: Implement the requested change\n---\nImplement it.\n",
1764+ );
1765+ const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
1766+ prefix: "t3-claude-v2-skills-attachments-",
1767+ });
1768+ const offeredMessages: Array<SDKUserMessage> = [];
1769+ const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
1770+ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1771+ settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: claudeHome },
1772+ environment: {},
1773+ attachmentsDir,
1774+ fileSystem,
1775+ path,
1776+ crypto: yield* Crypto.Crypto,
1777+ idAllocator: yield* IdAllocator.IdAllocatorV2,
1778+ queryRunner: {
1779+ allocateSessionId: Effect.succeed("native-thread-claude-skills"),
1780+ open: () =>
1781+ Effect.succeed({
1782+ messages: Stream.never,
1783+ offer: (message) =>
1784+ Effect.sync(() => {
1785+ offeredMessages.push(message);
1786+ }),
1787+ setModel: () => Effect.void,
1788+ applyFlagSettings: () => Effect.void,
1789+ setPermissionMode: () => Effect.void,
1790+ stopTask: () => Effect.void,
1791+ backgroundTasks: () => Effect.succeed(false),
1792+ interrupt: Effect.void,
1793+ close: Effect.void,
1794+ }),
1795+ forkSession: () => Effect.die("unused forkSession"),
1796+ subagentLaunchToolUseId: () => Effect.succeed(null),
1797+ assertComplete: Effect.void,
1798+ },
1799+ });
1800+ const threadId = ThreadId.make("thread-claude-skills");
1801+ const runtime = yield* adapter.openSession({
1802+ threadId,
1803+ providerSessionId: ProviderSessionId.make("provider-session-claude-skills"),
1804+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1805+ runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1806+ });
1807+ const providerThread = yield* runtime.ensureThread({
1808+ threadId,
1809+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1810+ runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1811+ });
1812+ return { attachmentsDir, offeredMessages, providerThread, runtime, threadId };
1813+ });
1814+
17521815 // Claude Code moves the expanded command ahead of earlier text blocks, so a
17531816 // leading block holding only the words before the chip reaches the model as
17541817 // a cut-off sentence (#13256).
17551818 it.effect("keeps the full request ahead of a mid-sentence skill command", () =>
17561819 Effect.scoped(
17571820 Effect.gen(function* () {
1758- const fileSystem = yield* FileSystem.FileSystem;
1759- const idAllocator = yield* IdAllocator.IdAllocatorV2;
1760- const path = yield* Path.Path;
1761- const claudeHome = yield* fileSystem.makeTempDirectoryScoped({
1762- prefix: "t3-claude-v2-skills-home-",
1763- });
1764- yield* fileSystem.makeDirectory(path.join(claudeHome, "skills", "implement"), {
1765- recursive: true,
1766- });
1767- yield* fileSystem.writeFileString(
1768- path.join(claudeHome, "skills", "implement", "SKILL.md"),
1769- "---\ndescription: Implement the requested change\n---\nImplement it.\n",
1770- );
1771- const offeredMessages: Array<SDKUserMessage> = [];
1772- const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({
1773- instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
1774- settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: claudeHome },
1775- environment: {},
1776- attachmentsDir: yield* fileSystem.makeTempDirectoryScoped({
1777- prefix: "t3-claude-v2-skills-attachments-",
1778- }),
1779- fileSystem,
1780- path,
1781- idAllocator,
1782- queryRunner: {
1783- allocateSessionId: Effect.succeed("native-thread-claude-skills"),
1784- open: () =>
1785- Effect.succeed({
1786- messages: Stream.never,
1787- offer: (message) =>
1788- Effect.sync(() => {
1789- offeredMessages.push(message);
1790- }),
1791- setModel: () => Effect.void,
1792- interrupt: Effect.void,
1793- close: Effect.void,
1794- }),
1795- forkSession: () => Effect.die("unused forkSession"),
1796- subagentLaunchToolUseId: () => Effect.succeed(null),
1797- assertComplete: Effect.void,
1798- },
1799- });
1800- const threadId = ThreadId.make("thread-claude-skills");
1801- const runtime = yield* adapter.openSession({
1802- threadId,
1803- providerSessionId: ProviderSessionId.make("provider-session-claude-skills"),
1804- modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1805- runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1806- });
1807- const providerThread = yield* runtime.ensureThread({
1808- threadId,
1809- modelSelection: CLAUDE_TEST_MODEL_SELECTION,
1810- runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
1811- });
1821+ const { offeredMessages, providerThread, runtime, threadId } =
1822+ yield* makeSkillDispatchHarness;
18121823
18131824 yield* runtime.startTurn(
18141825 makeClaudeTestTurnInput({
@@ -1825,7 +1836,104 @@ describe("ClaudeAdapterV2 skill dispatch", () => {
18251836 { type: "text", text: "Ultrathink:\nyou will /implement fixes" },
18261837 { type: "text", text: "/implement fixes" },
18271838 ]);
1828- }).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
1839+ }).pipe(
1840+ Effect.provide(
1841+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1842+ ),
1843+ ),
1844+ ),
1845+ );
1846+
1847+ it.effect("keeps the full request ahead of images and the skill command", () =>
1848+ Effect.scoped(
1849+ Effect.gen(function* () {
1850+ const fileSystem = yield* FileSystem.FileSystem;
1851+ const path = yield* Path.Path;
1852+ const { attachmentsDir, offeredMessages, providerThread, runtime, threadId } =
1853+ yield* makeSkillDispatchHarness;
1854+ const attachment = ChatImageAttachment.make({
1855+ type: "image",
1856+ id: ChatAttachmentId.make("thread-claude-skills-12345678-1234-1234-1234-123456789abc"),
1857+ name: "screen.png",
1858+ mimeType: "image/png",
1859+ sizeBytes: 4,
1860+ });
1861+ const attachmentPath = path.join(attachmentsDir, attachmentRelativePath(attachment)!);
1862+ yield* fileSystem.writeFile(attachmentPath, Uint8Array.from([1, 2, 3, 4]));
1863+
1864+ yield* runtime.startTurn(
1865+ makeClaudeTestTurnInput({
1866+ threadId,
1867+ providerThread,
1868+ now: yield* DateTime.now,
1869+ attemptId: RunAttemptId.make("attempt-claude-skills-image"),
1870+ text: "please $implement this screenshot",
1871+ attachments: [attachment],
1872+ }),
1873+ );
1874+
1875+ const attachmentNote = `[Attached image "screen.png" is saved at: ${attachmentPath}]`;
1876+ assert.deepEqual(offeredMessages[0]?.message.content, [
1877+ {
1878+ type: "text",
1879+ text: `Ultrathink:\nplease /implement this screenshot\n\n${attachmentNote}`,
1880+ },
1881+ { type: "image", source: { type: "base64", media_type: "image/png", data: "AQIDBA==" } },
1882+ { type: "text", text: `/implement this screenshot\n\n${attachmentNote}` },
1883+ ]);
1884+ }).pipe(
1885+ Effect.provide(
1886+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1887+ ),
1888+ ),
1889+ ),
1890+ );
1891+
1892+ it.effect("keeps the full request ahead of a skill command sent as steering", () =>
1893+ Effect.scoped(
1894+ Effect.gen(function* () {
1895+ const idAllocator = yield* IdAllocator.IdAllocatorV2;
1896+ const { offeredMessages, providerThread, runtime, threadId } =
1897+ yield* makeSkillDispatchHarness;
1898+ const attemptId = RunAttemptId.make("attempt-claude-skills-steer");
1899+ yield* runtime.startTurn(
1900+ makeClaudeTestTurnInput({
1901+ threadId,
1902+ providerThread,
1903+ now: yield* DateTime.now,
1904+ attemptId,
1905+ text: "look at the failing tests",
1906+ attachments: [],
1907+ }),
1908+ );
1909+
1910+ yield* runtime.steerTurn({
1911+ threadId,
1912+ runId: RunId.make(`run-${attemptId}`),
1913+ providerThread,
1914+ providerTurnId: idAllocator.derive.providerTurn({
1915+ driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
1916+ nativeTurnId: `turn:${attemptId}`,
1917+ }),
1918+ message: {
1919+ createdBy: "user",
1920+ creationSource: "web",
1921+ messageId: MessageId.make("message-claude-skills-steer"),
1922+ text: "then $implement the fixes",
1923+ attachments: [],
1924+ },
1925+ });
1926+
1927+ assert.equal(offeredMessages[1]?.priority, "now");
1928+ assert.deepEqual(offeredMessages[1]?.message.content, [
1929+ { type: "text", text: "Ultrathink:\nthen /implement the fixes" },
1930+ { type: "text", text: "/implement the fixes" },
1931+ ]);
1932+ }).pipe(
1933+ Effect.provide(
1934+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
1935+ ),
1936+ ),
18291937 ),
18301938 );
18311939});
0 commit comments