|
| 1 | +#!/usr/bin/env bun |
| 2 | +/** |
| 3 | + * Mock ACP agent that imitates kiro-cli ACP protocol for integration tests. |
| 4 | + * |
| 5 | + * Responds to: initialize, session/new, session/prompt, session/cancel. |
| 6 | + * Emits: session/update (agent_message_chunk), _kiro.dev/metadata extension. |
| 7 | + */ |
| 8 | +import * as Effect from "effect/Effect"; |
| 9 | + |
| 10 | +import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 11 | +import * as NodeRuntime from "@effect/platform-node/NodeRuntime"; |
| 12 | + |
| 13 | +import * as EffectAcpAgent from "effect-acp/agent"; |
| 14 | + |
| 15 | +const sessionId = "kiro-mock-session-1"; |
| 16 | + |
| 17 | +const program = Effect.gen(function* () { |
| 18 | + const agent = yield* EffectAcpAgent.AcpAgent; |
| 19 | + |
| 20 | + yield* agent.handleInitialize(() => |
| 21 | + Effect.succeed({ |
| 22 | + protocolVersion: 1, |
| 23 | + agentCapabilities: {}, |
| 24 | + agentInfo: { |
| 25 | + name: "kiro-mock-agent", |
| 26 | + version: "0.0.0", |
| 27 | + }, |
| 28 | + }), |
| 29 | + ); |
| 30 | + |
| 31 | + yield* agent.handleAuthenticate(() => Effect.succeed({})); |
| 32 | + |
| 33 | + yield* agent.handleCreateSession(() => |
| 34 | + Effect.succeed({ |
| 35 | + sessionId, |
| 36 | + }), |
| 37 | + ); |
| 38 | + |
| 39 | + yield* agent.handleLoadSession(() => Effect.succeed({})); |
| 40 | + |
| 41 | + yield* agent.handleCancel(() => Effect.void); |
| 42 | + |
| 43 | + yield* agent.handlePrompt((request) => |
| 44 | + Effect.gen(function* () { |
| 45 | + const requestedSessionId = String(request.sessionId ?? sessionId); |
| 46 | + |
| 47 | + // Emit a content delta |
| 48 | + yield* agent.client.sessionUpdate({ |
| 49 | + sessionId: requestedSessionId, |
| 50 | + update: { |
| 51 | + sessionUpdate: "agent_message_chunk", |
| 52 | + content: { type: "text", text: "hello from kiro mock" }, |
| 53 | + }, |
| 54 | + }); |
| 55 | + |
| 56 | + // Emit kiro metadata extension notification |
| 57 | + yield* agent.client.extNotification("_kiro.dev/metadata", { |
| 58 | + contextUsagePercentage: 10, |
| 59 | + }); |
| 60 | + |
| 61 | + return { stopReason: "end_turn" }; |
| 62 | + }), |
| 63 | + ); |
| 64 | + |
| 65 | + yield* agent.handleUnknownExtRequest((_method, _params) => Effect.succeed({})); |
| 66 | + |
| 67 | + return yield* Effect.never; |
| 68 | +}).pipe( |
| 69 | + Effect.provide(EffectAcpAgent.layerStdio()), |
| 70 | + Effect.scoped, |
| 71 | + Effect.provide(NodeServices.layer), |
| 72 | +); |
| 73 | + |
| 74 | +NodeRuntime.runMain(program); |
0 commit comments