Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Console from "effect/Console";
3import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
4
5import * as NodeServices from "@effect/platform-node/NodeServices";
6import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
7
8import * as AcpClient from "../../src/client.ts";
9
10const program = Effect.gen(function* () {
11 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
12 const command = ChildProcess.make("cursor-agent", ["acp"], {
13 cwd: process.cwd(),
14 shell: false,
15 });
16 const handle = yield* spawner.spawn(command);
17 const acpLayer = AcpClient.layerChildProcess(handle, {
18 logIncoming: true,
19 logOutgoing: true,
20 });
21
22 yield* Effect.gen(function* () {
23 const acp = yield* AcpClient.AcpClient;
24
25 yield* acp.handleRequestPermission(() =>
26 Effect.succeed({
27 outcome: {
28 outcome: "selected",
29 optionId: "allow",
30 },
31 }),
32 );
33 // yield* acp.handleSessionUpdate((notification) =>
34 // Console.log("session/update", JSON.stringify(notification)),
35 // );
36
37 const initialized = yield* acp.agent.initialize({
38 protocolVersion: 1,
39 clientCapabilities: {
40 fs: { readTextFile: false, writeTextFile: false },
41 terminal: false,
42 _meta: {
43 parameterizedModelPicker: true,
44 },
45 },
46 clientInfo: {
47 name: "effect-acp-example",
48 version: "0.0.0",
49 },
50 });
51 yield* Console.log("initialized", initialized);
52
53 const session = yield* acp.agent.createSession({
54 cwd: process.cwd(),
55 mcpServers: [],
56 });
57
58 const config = yield* acp.agent.setSessionConfigOption({
59 sessionId: session.sessionId,
60 configId: "model",
61 value: "claude-opus-4-6",
62 });
63
64 yield* Console.log("config", config);
65
66 const result = yield* acp.agent.prompt({
67 sessionId: session.sessionId,
68 prompt: [
69 {
70 type: "text",
71 text: "Illustrate your ability to create todo lists and then execute all of them. Do not write the list to disk, illustrate your built in ability!",
72 },
73 ],
74 });
75
76 yield* Console.log("prompt result", result);
77 yield* acp.agent.cancel({ sessionId: session.sessionId });
78 }).pipe(Effect.provide(acpLayer));
79});
80
81program.pipe(Effect.scoped, Effect.provide(NodeServices.layer), NodeRuntime.runMain);