Open History to see the last commit
1import * as Console from "effect/Console";
2import * as Effect from "effect/Effect";
3
4import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
5import * as NodeServices from "@effect/platform-node/NodeServices";
6
7import * as CodexClient from "../../src/client.ts";
8
9const program = Effect.gen(function* () {
10 const codexLayer = CodexClient.layerCommand({
11 command: process.env.CODEX_BIN ?? "codex",
12 args: ["app-server"],
13 cwd: process.cwd(),
14 logIncoming: true,
15 logOutgoing: true,
16 });
17
18 yield* Effect.gen(function* () {
19 const client = yield* CodexClient.CodexAppServerClient;
20
21 yield* client.handleServerRequest("item/tool/requestUserInput", (payload) =>
22 Effect.succeed({
23 answers: Object.fromEntries(
24 payload.questions.map((question) => [
25 question.id,
26 {
27 answers:
28 question.options && question.options.length > 0
29 ? [question.options[0]!.label]
30 : ["ok"],
31 },
32 ]),
33 ),
34 }),
35 );
36
37 const initialized = yield* client.request("initialize", {
38 clientInfo: {
39 name: "effect-codex-app-server-probe",
40 title: "Effect Codex App Server Probe",
41 version: "0.0.0",
42 },
43 capabilities: {
44 experimentalApi: true,
45 optOutNotificationMethods: null,
46 },
47 });
48 yield* Console.log("initialize", JSON.stringify(initialized, null, 2));
49
50 yield* client.notify("initialized", undefined);
51
52 const account = yield* client.request("account/read", {});
53 yield* Console.log("account/read", JSON.stringify(account, null, 2));
54
55 const skills = yield* client.request("skills/list", {
56 cwds: [process.cwd()],
57 });
58 yield* Console.log("skills/list", JSON.stringify(skills, null, 2));
59 }).pipe(Effect.provide(codexLayer));
60});
61
62program.pipe(Effect.scoped, Effect.provide(NodeServices.layer), NodeRuntime.runMain);