@yourtechbudstudio/fluidcast-tool-agent 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +201 -0
  2. package/dist/claude/attach.d.ts +24 -0
  3. package/dist/claude/attach.d.ts.map +1 -0
  4. package/dist/claude/attach.js +25 -0
  5. package/dist/claude/attach.js.map +1 -0
  6. package/dist/claude/connect.d.ts +52 -0
  7. package/dist/claude/connect.d.ts.map +1 -0
  8. package/dist/claude/connect.js +93 -0
  9. package/dist/claude/connect.js.map +1 -0
  10. package/dist/claude/failure.d.ts +35 -0
  11. package/dist/claude/failure.d.ts.map +1 -0
  12. package/dist/claude/failure.js +42 -0
  13. package/dist/claude/failure.js.map +1 -0
  14. package/dist/claude/index.d.ts +30 -0
  15. package/dist/claude/index.d.ts.map +1 -0
  16. package/dist/claude/index.js +41 -0
  17. package/dist/claude/index.js.map +1 -0
  18. package/dist/claude/transcript.d.ts +33 -0
  19. package/dist/claude/transcript.d.ts.map +1 -0
  20. package/dist/claude/transcript.js +217 -0
  21. package/dist/claude/transcript.js.map +1 -0
  22. package/dist/claude/turn.d.ts +57 -0
  23. package/dist/claude/turn.d.ts.map +1 -0
  24. package/dist/claude/turn.js +96 -0
  25. package/dist/claude/turn.js.map +1 -0
  26. package/dist/codex/attach.d.ts +29 -0
  27. package/dist/codex/attach.d.ts.map +1 -0
  28. package/dist/codex/attach.js +78 -0
  29. package/dist/codex/attach.js.map +1 -0
  30. package/dist/codex/connect.d.ts +71 -0
  31. package/dist/codex/connect.d.ts.map +1 -0
  32. package/dist/codex/connect.js +93 -0
  33. package/dist/codex/connect.js.map +1 -0
  34. package/dist/codex/index.d.ts +60 -0
  35. package/dist/codex/index.d.ts.map +1 -0
  36. package/dist/codex/index.js +53 -0
  37. package/dist/codex/index.js.map +1 -0
  38. package/dist/codex/process.d.ts +41 -0
  39. package/dist/codex/process.d.ts.map +1 -0
  40. package/dist/codex/process.js +66 -0
  41. package/dist/codex/process.js.map +1 -0
  42. package/dist/codex/protocol.d.ts +133 -0
  43. package/dist/codex/protocol.d.ts.map +1 -0
  44. package/dist/codex/protocol.js +189 -0
  45. package/dist/codex/protocol.js.map +1 -0
  46. package/dist/codex/rpc.d.ts +51 -0
  47. package/dist/codex/rpc.d.ts.map +1 -0
  48. package/dist/codex/rpc.js +133 -0
  49. package/dist/codex/rpc.js.map +1 -0
  50. package/dist/codex/transcript.d.ts +38 -0
  51. package/dist/codex/transcript.d.ts.map +1 -0
  52. package/dist/codex/transcript.js +246 -0
  53. package/dist/codex/transcript.js.map +1 -0
  54. package/dist/codex/turn.d.ts +35 -0
  55. package/dist/codex/turn.d.ts.map +1 -0
  56. package/dist/codex/turn.js +132 -0
  57. package/dist/codex/turn.js.map +1 -0
  58. package/dist/content.d.ts +9 -0
  59. package/dist/content.d.ts.map +1 -0
  60. package/dist/content.js +8 -0
  61. package/dist/content.js.map +1 -0
  62. package/dist/forward-tool.d.ts +68 -0
  63. package/dist/forward-tool.d.ts.map +1 -0
  64. package/dist/forward-tool.js +57 -0
  65. package/dist/forward-tool.js.map +1 -0
  66. package/dist/handoff.d.ts +70 -0
  67. package/dist/handoff.d.ts.map +1 -0
  68. package/dist/handoff.js +238 -0
  69. package/dist/handoff.js.map +1 -0
  70. package/dist/index.d.ts +6 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +6 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/progress.d.ts +42 -0
  75. package/dist/progress.d.ts.map +1 -0
  76. package/dist/progress.js +88 -0
  77. package/dist/progress.js.map +1 -0
  78. package/dist/schema.d.ts +267 -0
  79. package/dist/schema.d.ts.map +1 -0
  80. package/dist/schema.js +112 -0
  81. package/dist/schema.js.map +1 -0
  82. package/dist/session.d.ts +100 -0
  83. package/dist/session.d.ts.map +1 -0
  84. package/dist/session.js +316 -0
  85. package/dist/session.js.map +1 -0
  86. package/dist/worker.d.ts +69 -0
  87. package/dist/worker.d.ts.map +1 -0
  88. package/dist/worker.js +9 -0
  89. package/dist/worker.js.map +1 -0
  90. package/package.json +74 -3
  91. package/README.md +0 -3
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The effectful side of a Codex worker, with the app-server transport as a parameter so it can be
3
+ * driven by synthetic frames. Internal: the `./codex` entry builds `codexWorker` from it.
4
+ */
5
+ import { Effect, PubSub, Schema, Stream } from 'effect';
6
+ import { ToolFault } from '@yourtechbudstudio/fluidcast-harness';
7
+ import { ThreadResponse } from './protocol.js';
8
+ import { initialize, isNotSteerable, makeRpc } from './rpc.js';
9
+ import { initialTurnState, step } from './turn.js';
10
+ /** Auto permission mode, forced: Codex's reviewer answers approvals instead of a human. */
11
+ const approvals = { approvalPolicy: 'on-request', approvalsReviewer: 'auto_review' };
12
+ /** The request that opens the worker's thread: a new one, or the stored one without a model. */
13
+ export const threadRequest = (options, worker) => {
14
+ const config = options.thread?.config;
15
+ const withConfig = config === undefined ? {} : { config };
16
+ const source = options.thread?.sessionStartSource;
17
+ return worker.resume === undefined
18
+ ? [
19
+ 'thread/start',
20
+ {
21
+ cwd: worker.cwd,
22
+ ...(options.model === undefined ? {} : { model: options.model }),
23
+ ...approvals,
24
+ ...withConfig,
25
+ ...(source === undefined ? {} : { sessionStartSource: source }),
26
+ },
27
+ ]
28
+ : ['thread/resume', { threadId: worker.resume, cwd: worker.cwd, ...approvals, ...withConfig }];
29
+ };
30
+ /**
31
+ * One message as `turn/start`: it starts a turn when the thread is idle and joins the running one
32
+ * otherwise. Codex echoes `clientUserMessageId` when the turn takes the message in.
33
+ */
34
+ export const turnStartParams = (threadId, message, effort) => ({
35
+ threadId,
36
+ input: [{ type: 'text', text: message.text, text_elements: [] }],
37
+ clientUserMessageId: message.id,
38
+ ...(effort === undefined ? {} : { effort }),
39
+ });
40
+ /**
41
+ * Sends one message. A running turn that cannot be steered (a review or compaction) holds it until
42
+ * the next main-thread turn completes, then it is sent once more. Any other refusal, or a second
43
+ * one, is a fault: a dropped message would leave the session waiting for its `Consumed`.
44
+ *
45
+ * A process that ends before replying is not this side's to report: sending stops for good, and
46
+ * the notifications report `CodexExited` once every frame received before the end is processed.
47
+ * Failing here would interrupt them and lose those frames.
48
+ */
49
+ const sendMessage = (rpc, completions, params) => Effect.scoped(Effect.gen(function* () {
50
+ // Subscribed before sending, so the completion that ends the refusing turn is not missed.
51
+ const completed = yield* PubSub.subscribe(completions);
52
+ const start = rpc.request('turn/start', params);
53
+ yield* start.pipe(Effect.catchIf(isNotSteerable, () => PubSub.take(completed).pipe(Effect.andThen(start))));
54
+ })).pipe(Effect.catchTag('RpcClosed', () => Effect.never), Effect.mapError((_) => new ToolFault({ reason: 'CodexMessageRejected' })));
55
+ const isWorkerEvent = (output) => output._tag !== 'MainTurnCompleted';
56
+ /**
57
+ * Notifications through the turn tracker, in order. A failure of `notifications` fails the stream
58
+ * after every earlier notification is processed. Each main-thread turn completion is published to
59
+ * `completions`, where a held message waits.
60
+ */
61
+ export const runTracker = (notifications, initial, completions) => Stream.suspend(() => {
62
+ let state = initial;
63
+ return notifications.pipe(Stream.mapEffect((notification) => {
64
+ const [next, outputs] = step(state, notification);
65
+ state = next;
66
+ const completed = outputs.some((output) => output._tag === 'MainTurnCompleted');
67
+ return (completed ? PubSub.publish(completions, undefined) : Effect.void).pipe(Effect.as(outputs.filter(isWorkerEvent)));
68
+ }), Stream.flattenIterable);
69
+ });
70
+ /**
71
+ * One worker process for as long as the stream is consumed: `initialize`, then `thread/start` (a
72
+ * new thread, reported with `SessionStarted`) or `thread/resume`, then `input` as `turn/start`s, one
73
+ * at a time and in order. Failing to start is `CodexStartup`; the end of the process is
74
+ * `CodexExited`; a refused message is `CodexMessageRejected`. Interruption is teardown and records
75
+ * nothing; the scope's release closes the process's stdin.
76
+ */
77
+ export const connectWith = (open, options) => (worker, input) => Stream.unwrap(Effect.gen(function* () {
78
+ const startup = () => new ToolFault({ reason: 'CodexStartup' });
79
+ const transport = yield* open.pipe(Effect.mapError(startup));
80
+ const rpc = yield* makeRpc(transport);
81
+ const [method, params] = threadRequest(options, worker);
82
+ const { thread } = yield* initialize(rpc).pipe(Effect.andThen(rpc.request(method, params)), Effect.flatMap(Schema.decodeUnknownEffect(ThreadResponse)), Effect.mapError(startup));
83
+ const completions = yield* PubSub.unbounded();
84
+ // Starts only now: nothing is sent before the thread ID is known.
85
+ const sending = Stream.fromEffect(Stream.runForEach(input, (message) => sendMessage(rpc, completions, turnStartParams(thread.id, message, options.effort)))).pipe(Stream.drain);
86
+ const exited = new ToolFault({ reason: 'CodexExited' });
87
+ const frames = Stream.merge(rpc.notifications.pipe(Stream.concat(Stream.fail(exited))), sending);
88
+ const started = worker.resume === undefined
89
+ ? Stream.make({ _tag: 'SessionStarted', sessionId: thread.id })
90
+ : Stream.empty;
91
+ return Stream.concat(started, runTracker(frames, initialTurnState(thread.id), completions));
92
+ }));
93
+ //# sourceMappingURL=connect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/codex/connect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAIjE,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAA6B,MAAM,UAAU,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAsC,MAAM,WAAW,CAAC;AAmCvF,2FAA2F;AAC3F,MAAM,SAAS,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAW,CAAC;AAE9F,gGAAgG;AAChG,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAuB,EACvB,MAAwB,EAC8C,EAAE;IACxE,MAAM,MAAM,GAAG,OA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on `PATH`. No version is pinned or checked.
4
+ */
5
+ import type { Effect } from 'effect';
6
+ import type { WorkerSetupError, WorkerType } from '../worker.ts';
7
+ import { type CodexThread } from './attach.ts';
8
+ import { type CodexThreadOptions } from './connect.ts';
9
+ export type { CodexThread } from './attach.ts';
10
+ export type { CodexThreadOptions } from './connect.ts';
11
+ /**
12
+ * How a Codex app-server is launched, for a worker's connection, attach and Continue read alike.
13
+ * Pass the same launch to `codexWorker` and `readCodexThread`: each opens its own app-server.
14
+ */
15
+ export interface CodexLaunchOptions {
16
+ /** The app-server process environment. Default `process.env`. It replaces, never merges. */
17
+ readonly environment?: Readonly<Record<string, string | undefined>>;
18
+ /** The `codex` executable, resolved on the environment's `PATH` when not absolute. Default `codex`. */
19
+ readonly executable?: string;
20
+ /**
21
+ * Extra app-server arguments for per-invocation host instrumentation (e.g. enabling hooks and
22
+ * registering them with `-c` overrides), without touching the user's Codex configuration. They
23
+ * apply to the whole process, so attach and Continue reads get them too; those start no turn, so
24
+ * hooks never fire for them. Settings Codex honors only per thread go in the worker's `thread`.
25
+ * Default: none.
26
+ */
27
+ readonly args?: {
28
+ /** Before the `app-server` subcommand, e.g. global flags. */
29
+ readonly beforeSubcommand?: ReadonlyArray<string>;
30
+ /** After `app-server --listen stdio://`. The transport is fixed: never pass `--listen`. */
31
+ readonly appServer?: ReadonlyArray<string>;
32
+ };
33
+ }
34
+ export interface CodexWorkerOptions extends CodexLaunchOptions {
35
+ /** Where a new worker runs. A preloaded worker runs in its thread's recorded directory. */
36
+ readonly cwd: string;
37
+ /** A new thread's model; default: Codex's. A resumed thread keeps its recorded model. */
38
+ readonly model?: string;
39
+ /** Reasoning effort, sent with every message; levels vary by model. Default: the thread's. */
40
+ readonly effort?: string;
41
+ /**
42
+ * Per-thread options for per-invocation host instrumentation: settings Codex honors only per
43
+ * thread, which process-wide `args` cannot set. Default: none.
44
+ */
45
+ readonly thread?: CodexThreadOptions;
46
+ }
47
+ /**
48
+ * The Codex worker: one app-server process per connection, in auto permission mode (approvals go
49
+ * to Codex's reviewer; any request that still reaches Fluidcast is declined). The sandbox comes from
50
+ * the user's Codex configuration.
51
+ */
52
+ export declare const codexWorker: (options: CodexWorkerOptions) => WorkerType;
53
+ /**
54
+ * Reads a stored Codex thread for Continue: its recorded model and effort, and its last answer
55
+ * (every agent message after the last user message). Starts a short-lived app-server from `options`,
56
+ * which should be the launch the worker that continues it uses, and no turn. Any failure, including
57
+ * an unknown thread, is `SessionUnreadable`.
58
+ */
59
+ export declare const readCodexThread: (threadId: string, options?: CodexLaunchOptions) => Effect.Effect<CodexThread, WorkerSetupError>;
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codex/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAA8B,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGpE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,4FAA4F;IAC5F,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACpE,uGAAuG;IACvG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,6DAA6D;QAC7D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAClD,2FAA2F;QAC3F,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;KAC5C,CAAC;CACH;AAED,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,2FAA2F;IAC3F,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;CACtC;AA2BD;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAAa,kBAAkB,KAAG,UAYzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAChB,MAAM,YACP,kBAAkB,KAC1B,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAiD,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { attachWith, readThreadWith } from './attach.js';
2
+ import { connectWith } from './connect.js';
3
+ import { defaultAppServerLaunch, openAppServer } from './process.js';
4
+ /** One app-server opener for a worker's connection, attach and read alike. */
5
+ const appServer = (options) => {
6
+ const launch = {
7
+ executable: options.executable ?? defaultAppServerLaunch.executable,
8
+ beforeSubcommand: options.args?.beforeSubcommand ?? defaultAppServerLaunch.beforeSubcommand,
9
+ appServer: options.args?.appServer ?? defaultAppServerLaunch.appServer,
10
+ };
11
+ return openAppServer(options.environment ?? process.env, launch);
12
+ };
13
+ /** One skill per message, for now: chaining several is not supported. */
14
+ const maxModifiers = 1;
15
+ const modifierName = /^[a-z0-9][a-z0-9:_-]*$/;
16
+ /** Codex invokes a skill named in the text as `$name`; the skill receives the whole prompt. */
17
+ const composeMessage = (prompt, modifiers) => {
18
+ const [modifier] = modifiers;
19
+ if (modifier === undefined)
20
+ return prompt;
21
+ if (modifiers.length > maxModifiers) {
22
+ throw new Error(`Codex takes at most ${maxModifiers} modifier, got ${modifiers.length}`);
23
+ }
24
+ if (!modifierName.test(modifier.name))
25
+ throw new Error('Invalid Codex modifier name');
26
+ return `$${modifier.name} ${prompt}`;
27
+ };
28
+ /**
29
+ * The Codex worker: one app-server process per connection, in auto permission mode (approvals go
30
+ * to Codex's reviewer; any request that still reaches Fluidcast is declined). The sandbox comes from
31
+ * the user's Codex configuration.
32
+ */
33
+ export const codexWorker = (options) => {
34
+ const open = appServer(options);
35
+ return {
36
+ cwd: options.cwd,
37
+ composeMessage,
38
+ attach: attachWith(open),
39
+ connect: connectWith(open, {
40
+ model: options.model,
41
+ effort: options.effort,
42
+ thread: options.thread,
43
+ }),
44
+ };
45
+ };
46
+ /**
47
+ * Reads a stored Codex thread for Continue: its recorded model and effort, and its last answer
48
+ * (every agent message after the last user message). Starts a short-lived app-server from `options`,
49
+ * which should be the launch the worker that continues it uses, and no turn. Any failure, including
50
+ * an unknown thread, is `SessionUnreadable`.
51
+ */
52
+ export const readCodexThread = (threadId, options = {}) => readThreadWith(appServer(options))(threadId);
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codex/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,WAAW,EAA2B,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAwB,MAAM,cAAc,CAAC;AA2C3F,8EAA8E;AAC9E,MAAM,SAAS,GAAG,CAAC,OAA2B,EAAE,EAAE;IAChD,MAAM,MAAM,GAAoB;QAC9B,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,sBAAsB,CAAC,UAAU;QACnE,gBAAgB,EAAE,OAAO,CAAC,IAAI,EAAE,gBAAgB,IAAI,sBAAsB,CAAC,gBAAgB;QAC3F,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,IAAI,sBAAsB,CAAC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,QAAgB,EAChB,OAAO,GAAuB,EAAE,EACc,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { Effect, Stream, type Scope } from 'effect';
2
+ /** JSON-RPC lines in and out of one app-server process. */
3
+ export interface Transport {
4
+ /** Stdout, one line at a time. Ends when stdout ends: the process exited or crashed. */
5
+ readonly lines: Stream.Stream<string>;
6
+ /** Writes one line to stdin. Lost silently once the process is gone (`lines` then ends). */
7
+ readonly write: (line: string) => Effect.Effect<void>;
8
+ }
9
+ /** An app-server process for as long as the scope lives. */
10
+ export type OpenTransport = Effect.Effect<Transport, SpawnFailed, Scope.Scope>;
11
+ declare const SpawnFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
12
+ readonly _tag: "SpawnFailed";
13
+ } & Readonly<A>;
14
+ /** The app-server process could not be started (e.g. `codex` is not on `PATH`). */
15
+ export declare class SpawnFailed extends SpawnFailed_base {
16
+ }
17
+ export interface ProcessOptions {
18
+ readonly command: string;
19
+ readonly args: ReadonlyArray<string>;
20
+ /** The whole process environment: it replaces the parent's. */
21
+ readonly environment: Readonly<Record<string, string | undefined>>;
22
+ /** How long the release waits for an exit after closing stdin before sending SIGTERM. */
23
+ readonly exitWait: number;
24
+ }
25
+ /** Starts a process and owns it for the scope. */
26
+ export declare const openProcess: (options: ProcessOptions) => OpenTransport;
27
+ /** How the app-server is launched: the executable, and arguments around the subcommand. */
28
+ export interface AppServerLaunch {
29
+ /** Resolved on the environment's `PATH` when not absolute. */
30
+ readonly executable: string;
31
+ /** Arguments before `app-server`, e.g. global flags. */
32
+ readonly beforeSubcommand: ReadonlyArray<string>;
33
+ /** Arguments after `app-server --listen stdio://`, e.g. feature flags and `-c` overrides. */
34
+ readonly appServer: ReadonlyArray<string>;
35
+ }
36
+ /** The user's installed `codex`, found on `PATH`, with no extra arguments. */
37
+ export declare const defaultAppServerLaunch: AppServerLaunch;
38
+ /** A Codex app-server over stdio, by default the user's installed `codex` found on `PATH`. */
39
+ export declare const openAppServer: (environment: Readonly<Record<string, string | undefined>>, launch?: AppServerLaunch) => OpenTransport;
40
+ export {};
41
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/codex/process.ts"],"names":[],"mappings":"AASA,OAAO,EAAQ,MAAM,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE1D,2DAA2D;AAC3D,MAAM,WAAW,SAAS;IACxB,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,4FAA4F;IAC5F,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;;;;AAE/E,mFAAmF;AACnF,qBAAa,WAAY,SAAQ,gBAA+B;CAAG;AAEnE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IACnE,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AA0BD,kDAAkD;AAClD,eAAO,MAAM,WAAW,YAAa,cAAc,KAAG,aAwBnD,CAAC;AAEJ,2FAA2F;AAC3F,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,wDAAwD;IACxD,QAAQ,CAAC,gBAAgB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACjD,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED,8EAA8E;AAC9E,eAAO,MAAM,sBAAsB,EAAE,eAIpC,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,aAAa,gBACX,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,WACjD,eAAe,KACtB,aAMC,CAAC"}
@@ -0,0 +1,66 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * One `codex app-server --listen stdio://` process as a line transport, scoped. `node:child_process`
4
+ * rather than Effect's process module, which needs a platform layer and kills with SIGTERM then
5
+ * SIGKILL: SIGKILL orphans the commands Codex runs. Internal.
6
+ */
7
+ import { spawn as spawnChild } from 'node:child_process';
8
+ import { createInterface } from 'node:readline';
9
+ import { Data, Effect, Stream } from 'effect';
10
+ /** The app-server process could not be started (e.g. `codex` is not on `PATH`). */
11
+ export class SpawnFailed extends Data.TaggedError('SpawnFailed') {
12
+ }
13
+ const exited = (child) => child.exitCode !== null || child.signalCode !== null;
14
+ /**
15
+ * Closes stdin, which makes the app-server stop its running commands and exit, then waits up to
16
+ * `exitWait` milliseconds for the exit; after that, SIGTERM and no further wait. Never SIGKILL.
17
+ */
18
+ const stop = (child, exitWait) => Effect.callback((resume) => {
19
+ if (exited(child))
20
+ return resume(Effect.void);
21
+ let done = false;
22
+ const finish = () => {
23
+ if (done)
24
+ return;
25
+ done = true;
26
+ clearTimeout(timer);
27
+ resume(Effect.void);
28
+ };
29
+ const timer = setTimeout(() => {
30
+ child.kill('SIGTERM');
31
+ finish();
32
+ }, exitWait);
33
+ child.once('exit', finish);
34
+ child.stdin?.end();
35
+ });
36
+ /** Starts a process and owns it for the scope. */
37
+ export const openProcess = (options) => Effect.acquireRelease(Effect.callback((resume) => {
38
+ const child = spawnChild(options.command, [...options.args], {
39
+ env: options.environment,
40
+ stdio: ['pipe', 'pipe', 'ignore'],
41
+ });
42
+ // Later errors (a write after exit) surface as the end of stdout instead.
43
+ child.stdin?.on('error', () => { });
44
+ child.once('spawn', () => resume(Effect.succeed(child)));
45
+ child.once('error', () => resume(Effect.fail(new SpawnFailed())));
46
+ }), (child) => stop(child, options.exitWait)).pipe(Effect.map((child) => ({
47
+ lines: Stream.fromAsyncIterable(createInterface({ input: child.stdout, crlfDelay: Infinity }), () => undefined).pipe(Stream.ignore),
48
+ write: (line) => Effect.sync(() => {
49
+ if (child.stdin?.writable === true)
50
+ child.stdin.write(`${line}\n`);
51
+ }),
52
+ })));
53
+ /** The user's installed `codex`, found on `PATH`, with no extra arguments. */
54
+ export const defaultAppServerLaunch = {
55
+ executable: 'codex',
56
+ beforeSubcommand: [],
57
+ appServer: [],
58
+ };
59
+ /** A Codex app-server over stdio, by default the user's installed `codex` found on `PATH`. */
60
+ export const openAppServer = (environment, launch = defaultAppServerLaunch) => openProcess({
61
+ command: launch.executable,
62
+ args: [...launch.beforeSubcommand, 'app-server', '--listen', 'stdio://', ...launch.appServer],
63
+ environment,
64
+ exitWait: 3000,
65
+ });
66
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/codex/process.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B;;;;GAIG;AACH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAa1D,mFAAmF;AACnF,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,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AAC9F,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,WAAyD,EACzD,MAAM,GAAoB,sBAAsB,EACjC,EAAE,CACjB,WAAW,CAAC;IACV,OAAO,EAAE,MAAM,CAAC,UAAU;IAC1B,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7F,WAAW;IACX,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Minimal decoders for the `codex app-server` messages the adapter reads, checked against bindings
3
+ * generated by `codex app-server generate-ts` (0.160.1). Lenient: only the fields used are declared,
4
+ * unknown fields are ignored, and a field the adapter can do without is optional and nullable.
5
+ */
6
+ import { Schema } from 'effect';
7
+ /**
8
+ * One `ThreadItem`, of any `type`, as one flat struct: the fields of every item kind the adapter
9
+ * maps, all optional. Fields whose type differs between kinds (`content`, `result`) are decoded
10
+ * loosely and read according to the item's `type`. Decode items with `itemOf`, never directly.
11
+ */
12
+ export declare const Item: Schema.Struct<{
13
+ readonly type: Schema.String;
14
+ readonly id: Schema.String;
15
+ readonly clientId: Schema.optionalKey<Schema.NullOr<Schema.String>>;
16
+ readonly content: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.Unknown>>>;
17
+ readonly text: Schema.optionalKey<Schema.NullOr<Schema.String>>;
18
+ readonly command: Schema.optionalKey<Schema.NullOr<Schema.String>>;
19
+ readonly cwd: Schema.optionalKey<Schema.NullOr<Schema.String>>;
20
+ readonly aggregatedOutput: Schema.optionalKey<Schema.NullOr<Schema.String>>;
21
+ readonly exitCode: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
22
+ readonly status: Schema.optionalKey<Schema.NullOr<Schema.String>>;
23
+ readonly changes: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.Struct<{
24
+ readonly path: Schema.String;
25
+ readonly kind: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
26
+ readonly type: Schema.String;
27
+ }>>>;
28
+ readonly diff: Schema.optionalKey<Schema.NullOr<Schema.String>>;
29
+ }>>>>;
30
+ readonly server: Schema.optionalKey<Schema.NullOr<Schema.String>>;
31
+ readonly tool: Schema.optionalKey<Schema.NullOr<Schema.String>>;
32
+ readonly namespace: Schema.optionalKey<Schema.NullOr<Schema.String>>;
33
+ readonly arguments: Schema.optionalKey<Schema.Unknown>;
34
+ readonly result: Schema.optionalKey<Schema.Unknown>;
35
+ readonly error: Schema.optionalKey<Schema.NullOr<Schema.Struct<{
36
+ readonly message: Schema.String;
37
+ }>>>;
38
+ readonly contentItems: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.Struct<{
39
+ readonly type: Schema.String;
40
+ readonly text: Schema.optionalKey<Schema.NullOr<Schema.String>>;
41
+ }>>>>;
42
+ readonly success: Schema.optionalKey<Schema.NullOr<Schema.Boolean>>;
43
+ readonly query: Schema.optionalKey<Schema.NullOr<Schema.String>>;
44
+ readonly action: Schema.optionalKey<Schema.Unknown>;
45
+ readonly path: Schema.optionalKey<Schema.NullOr<Schema.String>>;
46
+ readonly revisedPrompt: Schema.optionalKey<Schema.NullOr<Schema.String>>;
47
+ readonly savedPath: Schema.optionalKey<Schema.NullOr<Schema.String>>;
48
+ readonly failure: Schema.optionalKey<Schema.Unknown>;
49
+ readonly receiverThreadIds: Schema.optionalKey<Schema.NullOr<Schema.$Array<Schema.String>>>;
50
+ readonly prompt: Schema.optionalKey<Schema.NullOr<Schema.String>>;
51
+ readonly model: Schema.optionalKey<Schema.NullOr<Schema.String>>;
52
+ readonly reasoningEffort: Schema.optionalKey<Schema.NullOr<Schema.String>>;
53
+ readonly agentsStates: Schema.optionalKey<Schema.NullOr<Schema.$Record<Schema.String, Schema.Struct<{
54
+ readonly status: Schema.String;
55
+ readonly message: Schema.optionalKey<Schema.NullOr<Schema.String>>;
56
+ }>>>>;
57
+ readonly kind: Schema.optionalKey<Schema.NullOr<Schema.String>>;
58
+ readonly agentThreadId: Schema.optionalKey<Schema.NullOr<Schema.String>>;
59
+ readonly agentPath: Schema.optionalKey<Schema.NullOr<Schema.String>>;
60
+ }>;
61
+ export type Item = typeof Item.Type;
62
+ /**
63
+ * One item, decoded on its own so that it can never make a notification or a page of history
64
+ * unreadable: when a field has a shape the adapter does not expect, only the item's `type` and
65
+ * `id` are kept (its content is then shown empty or left out). `undefined`: not an item at all.
66
+ */
67
+ export declare const itemOf: (value: unknown) => Item | undefined;
68
+ /** One server notification, as received. */
69
+ export interface Notification {
70
+ readonly method: string;
71
+ readonly params: unknown;
72
+ }
73
+ /** A server notification the tracker acts on, decoded. */
74
+ export type Frame = {
75
+ readonly _tag: 'TurnStarted';
76
+ readonly threadId: string;
77
+ } | {
78
+ readonly _tag: 'TurnCompleted';
79
+ readonly threadId: string;
80
+ readonly status: string;
81
+ /** The turn error's `codexErrorInfo`: a name, or an object keyed by the name. */
82
+ readonly errorInfo: unknown;
83
+ } | {
84
+ readonly _tag: 'ItemStarted' | 'ItemCompleted';
85
+ readonly threadId: string;
86
+ readonly item: Item;
87
+ } | {
88
+ readonly _tag: 'ThreadStatus';
89
+ readonly threadId: string;
90
+ readonly status: string;
91
+ } | {
92
+ readonly _tag: 'PlanUpdated';
93
+ readonly threadId: string;
94
+ readonly explanation: string | undefined;
95
+ readonly plan: ReadonlyArray<{
96
+ readonly step: string;
97
+ readonly status: string;
98
+ }>;
99
+ }
100
+ /** The reset time of a usage window that is full, if any (the later one when both are). */
101
+ | {
102
+ readonly _tag: 'RateLimits';
103
+ readonly fullResetsAt: number | undefined;
104
+ };
105
+ /**
106
+ * The frame of one server notification, or `undefined` for a notification the tracker ignores
107
+ * (or one whose parameters do not decode).
108
+ */
109
+ export declare const frameOf: (method: string, params: unknown) => Frame | undefined;
110
+ /** The name of a `codexErrorInfo`: the string itself, or the single key of its object form. */
111
+ export declare const errorInfoName: (info: unknown) => string | undefined;
112
+ /** `thread/start` and `thread/resume` responses: the thread's ID. */
113
+ export declare const ThreadResponse: Schema.Struct<{
114
+ readonly thread: Schema.Struct<{
115
+ readonly id: Schema.String;
116
+ }>;
117
+ }>;
118
+ /** `thread/read` response: what Continue and preload need of a stored thread. */
119
+ export declare const ThreadReadResponse: Schema.Struct<{
120
+ readonly thread: Schema.Struct<{
121
+ readonly cwd: Schema.String;
122
+ readonly model: Schema.optionalKey<Schema.NullOr<Schema.String>>;
123
+ readonly reasoningEffort: Schema.optionalKey<Schema.NullOr<Schema.String>>;
124
+ }>;
125
+ }>;
126
+ /** `thread/turns/list` response: one page of turns, oldest first when asked `asc`. Items: `itemOf`. */
127
+ export declare const TurnsPage: Schema.Struct<{
128
+ readonly data: Schema.$Array<Schema.Struct<{
129
+ readonly items: Schema.$Array<Schema.Unknown>;
130
+ }>>;
131
+ readonly nextCursor: Schema.optionalKey<Schema.NullOr<Schema.String>>;
132
+ }>;
133
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/codex/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKxC;;;;GAIG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4Df,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC;AAQpC;;;;GAIG;AACH,eAAO,MAAM,MAAM,UAAW,OAAO,KAAG,IAAI,GAAG,SAC+C,CAAC;AA+B/F,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,0DAA0D;AAC1D,MAAM,MAAM,KAAK,GACb;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,QA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