|
1 | 1 | import { AgentSideConnection, PROTOCOL_VERSION, ndJsonStream } from "@agentclientprotocol/sdk"; |
2 | 2 | import { STOP_UNRECORDED_MESSAGE } from "../../src/common/constants/workspace"; |
3 | 3 | import type { OnChatMode, WorkspaceChatMessage } from "../../src/common/orpc/types"; |
| 4 | +import type { AgentSkillListResult } from "../../src/common/types/agentSkill"; |
4 | 5 | import { MuxAgent } from "../../src/node/acp/agent"; |
5 | 6 | import type { ORPCClient, ServerConnection } from "../../src/node/acp/serverConnection"; |
6 | 7 |
|
@@ -291,6 +292,7 @@ interface HarnessOptions { |
291 | 292 | sendHeldInput?: ( |
292 | 293 | input: Record<string, unknown> |
293 | 294 | ) => Promise<{ success: boolean; data?: unknown; error?: unknown }>; |
| 295 | + listSkills?: () => Promise<AgentSkillListResult>; |
294 | 296 | /** Custom output WritableStream for simulating stdout backpressure. */ |
295 | 297 | acpOutputStream?: WritableStream<Uint8Array>; |
296 | 298 | agentOptions?: ConstructorParameters<typeof MuxAgent>[2]; |
@@ -338,7 +340,12 @@ function createHarness(options?: HarnessOptions): Harness { |
338 | 340 | list: async () => [], |
339 | 341 | }, |
340 | 342 | agentSkills: { |
341 | | - list: async () => ({ skills: [], invalidSkills: [], unavailableSources: [] }), |
| 343 | + list: async () => |
| 344 | + (await options?.listSkills?.()) ?? { |
| 345 | + skills: [], |
| 346 | + invalidSkills: [], |
| 347 | + unavailableSources: [], |
| 348 | + }, |
342 | 349 | get: async () => { |
343 | 350 | throw new Error("createHarness: get not implemented for this test"); |
344 | 351 | }, |
@@ -1753,6 +1760,51 @@ describe("ACP prompt stream correlation", () => { |
1753 | 1760 | }, 15_000); |
1754 | 1761 | }); |
1755 | 1762 |
|
| 1763 | +describe("ACP slash commands after a partial skill list", () => { |
| 1764 | + it("sends the client the complete list once a slash prompt reads it", async () => { |
| 1765 | + const partial: AgentSkillListResult = { |
| 1766 | + skills: [], |
| 1767 | + invalidSkills: [], |
| 1768 | + unavailableSources: [ |
| 1769 | + { scope: "project", displayPath: "/remote/.xum/skills", message: "host unreachable" }, |
| 1770 | + ], |
| 1771 | + }; |
| 1772 | + const complete: AgentSkillListResult = { |
| 1773 | + skills: [{ name: "deploy", description: "Deploy the app", scope: "project" }], |
| 1774 | + invalidSkills: [], |
| 1775 | + unavailableSources: [], |
| 1776 | + }; |
| 1777 | + let listCount = 0; |
| 1778 | + const harness = createHarness({ |
| 1779 | + listSkills: async () => (listCount++ === 0 ? partial : complete), |
| 1780 | + }); |
| 1781 | + const advertised = () => |
| 1782 | + harness.sessionUpdates |
| 1783 | + .filter(({ update }) => update.sessionUpdate === "available_commands_update") |
| 1784 | + .map(({ update }) => (update.availableCommands as { name: string }[]).map((c) => c.name)); |
| 1785 | + |
| 1786 | + await initializeDefaultAgent(harness); |
| 1787 | + const { sessionId } = await createDefaultSession(harness); |
| 1788 | + await waitForCondition(() => advertised().length === 1); |
| 1789 | + expect(advertised()[0]).not.toContain("deploy"); |
| 1790 | + |
| 1791 | + const { promptPromise, promptCorrelationId } = await startPromptTurn( |
| 1792 | + harness, |
| 1793 | + sessionId, |
| 1794 | + "/deploy now" |
| 1795 | + ); |
| 1796 | + harness.pushChatEvent( |
| 1797 | + streamStart(sessionId, "assistant-deploy", { acpPromptId: promptCorrelationId }) |
| 1798 | + ); |
| 1799 | + harness.pushChatEvent(streamEnd(sessionId, "assistant-deploy")); |
| 1800 | + await expect(promptPromise).resolves.toMatchObject({ stopReason: "end_turn" }); |
| 1801 | + |
| 1802 | + expect(advertised().at(-1)).toContain("deploy"); |
| 1803 | + harness.closeConnection(); |
| 1804 | + await harness.connectionClosed; |
| 1805 | + }); |
| 1806 | +}); |
| 1807 | + |
1756 | 1808 | describe("ACP held inputs (#4944)", () => { |
1757 | 1809 | const heldInputs = ["queued follow-up", "second queued"].map((displayText, index) => ({ |
1758 | 1810 | id: `held-${index + 1}`, |
|
0 commit comments