lark-remote 0.1.5 → 0.1.7

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 (190) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.en.md +5 -1
  3. package/README.md +10 -2
  4. package/dist/bridge/approval-coordinator.d.ts +131 -0
  5. package/dist/bridge/approval-coordinator.js +409 -0
  6. package/dist/bridge/inbound-media.d.ts +62 -0
  7. package/dist/bridge/inbound-media.js +282 -0
  8. package/dist/bridge/index.d.ts +138 -5
  9. package/dist/bridge/index.js +569 -65
  10. package/dist/bridge/queue-manager.d.ts +11 -1
  11. package/dist/bridge/queue-manager.js +20 -11
  12. package/dist/card/approval-render.d.ts +16 -0
  13. package/dist/card/approval-render.js +363 -0
  14. package/dist/card/bash-card-session.d.ts +2 -24
  15. package/dist/card/bash-card-session.js +6 -73
  16. package/dist/card/bash-renderer.js +2 -3
  17. package/dist/card/card-budget.js +29 -75
  18. package/dist/card/card-session.d.ts +48 -0
  19. package/dist/card/card-session.js +86 -0
  20. package/dist/card/card-shared.d.ts +13 -10
  21. package/dist/card/card-shared.js +27 -24
  22. package/dist/card/run-card-session.d.ts +2 -55
  23. package/dist/card/run-card-session.js +6 -104
  24. package/dist/card/run-renderer.js +140 -202
  25. package/dist/card/run-state.d.ts +38 -3
  26. package/dist/card/run-state.js +221 -11
  27. package/dist/card/text-truncate.d.ts +13 -12
  28. package/dist/card/text-truncate.js +13 -63
  29. package/dist/common/fs.d.ts +8 -0
  30. package/dist/common/fs.js +17 -0
  31. package/dist/common/guards.d.ts +0 -20
  32. package/dist/common/guards.js +0 -43
  33. package/dist/common/sleep.d.ts +2 -0
  34. package/dist/common/sleep.js +5 -0
  35. package/dist/common/truncate.d.ts +39 -0
  36. package/dist/common/truncate.js +92 -0
  37. package/dist/config/codex-config.d.ts +1 -1
  38. package/dist/config/codex-config.js +1 -1
  39. package/dist/config/dir.js +1 -1
  40. package/dist/config/index.d.ts +116 -9
  41. package/dist/config/index.js +122 -29
  42. package/dist/connector/index.d.ts +74 -2
  43. package/dist/connector/index.js +119 -1
  44. package/dist/index.js +139 -99
  45. package/dist/instance-lock.js +4 -12
  46. package/dist/order/alias-resolve.d.ts +13 -0
  47. package/dist/order/alias-resolve.js +22 -0
  48. package/dist/order/alias-store.d.ts +38 -0
  49. package/dist/order/alias-store.js +106 -0
  50. package/dist/persistence/atomic-write.d.ts +8 -2
  51. package/dist/persistence/atomic-write.js +23 -7
  52. package/dist/restart.js +2 -1
  53. package/dist/router/card-helpers.d.ts +63 -0
  54. package/dist/router/card-helpers.js +146 -0
  55. package/dist/router/config/claude.js +25 -1
  56. package/dist/router/config/codex.d.ts +1 -1
  57. package/dist/router/config/codex.js +33 -5
  58. package/dist/router/config/common/model-patch.d.ts +22 -0
  59. package/dist/router/config/common/model-patch.js +26 -0
  60. package/dist/router/config/common/render.js +9 -4
  61. package/dist/router/config/index.d.ts +12 -0
  62. package/dist/router/config/index.js +25 -1
  63. package/dist/router/config/kimi.d.ts +4 -1
  64. package/dist/router/config/kimi.js +27 -0
  65. package/dist/router/config/opencode.js +18 -5
  66. package/dist/router/config/pi.js +4 -5
  67. package/dist/router/config/types.d.ts +12 -3
  68. package/dist/router/index.d.ts +77 -17
  69. package/dist/router/index.js +455 -549
  70. package/dist/router/utils.d.ts +4 -0
  71. package/dist/router/utils.js +9 -2
  72. package/dist/runner/agent-choices-common.d.ts +16 -0
  73. package/dist/runner/agent-choices-common.js +31 -0
  74. package/dist/runner/claude/runner.d.ts +47 -10
  75. package/dist/runner/claude/runner.js +117 -46
  76. package/dist/runner/claude/session.d.ts +166 -0
  77. package/dist/runner/claude/session.js +749 -0
  78. package/dist/runner/codex/app-server/protocol-types.d.ts +519 -0
  79. package/dist/runner/codex/app-server/protocol-types.js +56 -0
  80. package/dist/runner/codex/app-server/runner.d.ts +104 -0
  81. package/dist/runner/codex/app-server/runner.js +377 -0
  82. package/dist/runner/codex/app-server/translator.d.ts +89 -0
  83. package/dist/runner/codex/app-server/translator.js +716 -0
  84. package/dist/runner/codex/index.d.ts +1 -1
  85. package/dist/runner/codex/index.js +1 -1
  86. package/dist/runner/common/acp/protocol-helpers.d.ts +14 -0
  87. package/dist/runner/common/acp/protocol-helpers.js +21 -0
  88. package/dist/runner/common/acp/protocol-types.d.ts +238 -0
  89. package/dist/runner/common/acp/protocol-types.js +75 -0
  90. package/dist/runner/common/connection-based-runner.d.ts +111 -0
  91. package/dist/runner/common/connection-based-runner.js +261 -0
  92. package/dist/runner/common/jsonrpc/client.d.ts +89 -0
  93. package/dist/runner/common/jsonrpc/client.js +243 -0
  94. package/dist/runner/common/jsonrpc/connection-manager.d.ts +125 -0
  95. package/dist/runner/common/jsonrpc/connection-manager.js +205 -0
  96. package/dist/runner/common/jsonrpc/transport.d.ts +50 -0
  97. package/dist/runner/common/jsonrpc/transport.js +230 -0
  98. package/dist/runner/common/jsonrpc/types.d.ts +32 -0
  99. package/dist/runner/common/jsonrpc/types.js +9 -0
  100. package/dist/runner/common/process-stopper.d.ts +2 -1
  101. package/dist/runner/common/process-stopper.js +1 -0
  102. package/dist/runner/common/runner-utils.d.ts +6 -13
  103. package/dist/runner/common/runner-utils.js +6 -47
  104. package/dist/runner/common/spawning-runner.d.ts +24 -70
  105. package/dist/runner/common/spawning-runner.js +98 -152
  106. package/dist/runner/common/usage.d.ts +2 -0
  107. package/dist/runner/common/usage.js +2 -0
  108. package/dist/runner/index.d.ts +5 -5
  109. package/dist/runner/index.js +4 -4
  110. package/dist/runner/kimi/acp/runner.d.ts +106 -0
  111. package/dist/runner/kimi/acp/runner.js +448 -0
  112. package/dist/runner/kimi/acp/translator.d.ts +124 -0
  113. package/dist/runner/kimi/acp/translator.js +336 -0
  114. package/dist/runner/kimi/index.d.ts +1 -1
  115. package/dist/runner/kimi/index.js +1 -1
  116. package/dist/runner/opencode/acp/index.d.ts +1 -0
  117. package/dist/runner/opencode/acp/index.js +2 -0
  118. package/dist/runner/opencode/acp/runner.d.ts +121 -0
  119. package/dist/runner/opencode/acp/runner.js +429 -0
  120. package/dist/runner/opencode/acp/translator.d.ts +119 -0
  121. package/dist/runner/opencode/acp/translator.js +345 -0
  122. package/dist/runner/opencode/index.d.ts +1 -1
  123. package/dist/runner/opencode/index.js +1 -1
  124. package/dist/runner/pi/index.d.ts +1 -1
  125. package/dist/runner/pi/index.js +1 -1
  126. package/dist/runner/pi/rpc/client.d.ts +52 -0
  127. package/dist/runner/pi/rpc/client.js +114 -0
  128. package/dist/runner/pi/rpc/index.d.ts +4 -0
  129. package/dist/runner/pi/rpc/index.js +4 -0
  130. package/dist/runner/pi/rpc/protocol-types.d.ts +127 -0
  131. package/dist/runner/pi/rpc/protocol-types.js +21 -0
  132. package/dist/runner/pi/rpc/runner.d.ts +80 -0
  133. package/dist/runner/pi/rpc/runner.js +199 -0
  134. package/dist/runner/pi/rpc/translator.d.ts +55 -0
  135. package/dist/runner/pi/rpc/translator.js +258 -0
  136. package/dist/runner/registry.d.ts +7 -8
  137. package/dist/runner/registry.js +3 -4
  138. package/dist/runner/resolve-agent-choices.js +18 -59
  139. package/dist/runner/sync-agent-choices.js +16 -67
  140. package/dist/runner/types.d.ts +153 -2
  141. package/dist/session/claude/session-index.js +2 -3
  142. package/dist/session/claude/session-reader.js +3 -6
  143. package/dist/session/claude/sessions.js +6 -13
  144. package/dist/session/codex/rollout-reader.d.ts +2 -2
  145. package/dist/session/codex/rollout-reader.js +57 -17
  146. package/dist/session/codex/sessions.d.ts +1 -1
  147. package/dist/session/codex/sessions.js +2 -2
  148. package/dist/session/common/content-blocks.d.ts +7 -0
  149. package/dist/session/common/content-blocks.js +13 -9
  150. package/dist/session/common/jsonl.d.ts +8 -25
  151. package/dist/session/common/jsonl.js +126 -261
  152. package/dist/session/common/pagination.d.ts +28 -0
  153. package/dist/session/common/pagination.js +33 -0
  154. package/dist/session/kimi/sessions.d.ts +34 -1
  155. package/dist/session/kimi/sessions.js +208 -98
  156. package/dist/session/opencode/sessions.d.ts +17 -3
  157. package/dist/session/opencode/sessions.js +29 -29
  158. package/dist/session/pi/sessions.d.ts +5 -1
  159. package/dist/session/pi/sessions.js +12 -16
  160. package/dist/session/session-store.d.ts +11 -1
  161. package/dist/session/session-store.js +75 -178
  162. package/dist/update/index.d.ts +2 -2
  163. package/dist/update/index.js +2 -2
  164. package/dist/update/install.d.ts +20 -2
  165. package/dist/update/install.js +51 -7
  166. package/package.json +1 -1
  167. package/dist/runner/codex/argv.d.ts +0 -33
  168. package/dist/runner/codex/argv.js +0 -40
  169. package/dist/runner/codex/jsonl.d.ts +0 -37
  170. package/dist/runner/codex/jsonl.js +0 -221
  171. package/dist/runner/codex/runner.d.ts +0 -63
  172. package/dist/runner/codex/runner.js +0 -124
  173. package/dist/runner/common/exec-translator.d.ts +0 -73
  174. package/dist/runner/common/exec-translator.js +0 -105
  175. package/dist/runner/kimi/jsonl.d.ts +0 -28
  176. package/dist/runner/kimi/jsonl.js +0 -143
  177. package/dist/runner/kimi/runner.d.ts +0 -49
  178. package/dist/runner/kimi/runner.js +0 -105
  179. package/dist/runner/opencode/argv.d.ts +0 -32
  180. package/dist/runner/opencode/argv.js +0 -35
  181. package/dist/runner/opencode/jsonl.d.ts +0 -68
  182. package/dist/runner/opencode/jsonl.js +0 -295
  183. package/dist/runner/opencode/runner.d.ts +0 -61
  184. package/dist/runner/opencode/runner.js +0 -93
  185. package/dist/runner/pi/jsonl.d.ts +0 -128
  186. package/dist/runner/pi/jsonl.js +0 -249
  187. package/dist/runner/pi/runner.d.ts +0 -36
  188. package/dist/runner/pi/runner.js +0 -76
  189. package/dist/session/common/catch-up.d.ts +0 -12
  190. package/dist/session/common/catch-up.js +0 -31
@@ -0,0 +1,519 @@
1
+ /**
2
+ * Codex App Server JSON-RPC Protocol Types
3
+ *
4
+ * Aligned with the real `codex app-server` protocol (v2, generated via
5
+ * `codex app-server generate-json-schema --experimental`). Method names and
6
+ * field names use the wire format exactly: camelCase paths for methods
7
+ * (`item/agentMessage/delta`) and snake_case only where the server requires it
8
+ * (e.g. permission profile fields).
9
+ */
10
+ export type { JsonRpcRequest, JsonRpcNotification, JsonRpcSuccessResponse, JsonRpcErrorResponse, } from '../../common/jsonrpc/types.js';
11
+ export interface ClientInfo {
12
+ name: string;
13
+ version: string;
14
+ }
15
+ export interface InitializeCapabilities {
16
+ experimentalApi?: boolean;
17
+ requestAttestation?: boolean;
18
+ optOutNotificationMethods?: string[];
19
+ mcpServerOpenaiFormElicitation?: boolean;
20
+ }
21
+ export interface InitializeParams {
22
+ clientInfo: ClientInfo;
23
+ capabilities?: InitializeCapabilities;
24
+ }
25
+ export interface InitializeResult {
26
+ serverInfo?: {
27
+ name?: string;
28
+ version?: string;
29
+ };
30
+ protocolVersion?: string;
31
+ capabilities?: Record<string, unknown>;
32
+ }
33
+ export type SandboxMode = 'read-only' | 'workspace-write' | 'danger-full-access';
34
+ /** Response-side sandbox policy object (the request side uses `SandboxMode`
35
+ * strings; the response reports the active policy as a structured object). */
36
+ export interface SandboxPolicy {
37
+ type: 'dangerFullAccess' | 'readOnly' | 'externalSandbox' | 'workspaceWrite';
38
+ networkAccess?: boolean;
39
+ writableRoots?: string[];
40
+ [key: string]: unknown;
41
+ }
42
+ export type AskForApproval = 'untrusted' | 'on-request' | 'never' | {
43
+ granular: {
44
+ mcp_elicitations: boolean;
45
+ rules: boolean;
46
+ sandbox_approval: boolean;
47
+ request_permissions?: boolean;
48
+ skill_approval?: boolean;
49
+ };
50
+ };
51
+ export interface ThreadStartParams {
52
+ cwd?: string | null;
53
+ model?: string | null;
54
+ modelProvider?: string | null;
55
+ approvalPolicy?: AskForApproval;
56
+ sandbox?: SandboxMode;
57
+ permissions?: string | null;
58
+ config?: Record<string, unknown> | null;
59
+ }
60
+ export interface ThreadStartResponse {
61
+ thread: Thread;
62
+ cwd: string;
63
+ model: string;
64
+ modelProvider: string;
65
+ approvalPolicy: AskForApproval;
66
+ sandbox?: SandboxPolicy | null;
67
+ }
68
+ /** Real wire shape: ThreadStatus is a discriminated object, not a string. */
69
+ export type ThreadStatus = {
70
+ type: 'notLoaded';
71
+ } | {
72
+ type: 'idle';
73
+ } | {
74
+ type: 'systemError';
75
+ } | {
76
+ type: 'active';
77
+ activeFlags: unknown[];
78
+ };
79
+ export interface ThreadResumeParams {
80
+ threadId: string;
81
+ cwd?: string | null;
82
+ model?: string | null;
83
+ modelProvider?: string | null;
84
+ approvalPolicy?: AskForApproval;
85
+ sandbox?: SandboxMode;
86
+ }
87
+ export interface ThreadResumeResponse {
88
+ thread: Thread;
89
+ cwd: string;
90
+ model: string;
91
+ modelProvider: string;
92
+ }
93
+ /** `thread/settings/update` params (real v2 protocol). */
94
+ export interface ThreadSettingsUpdateParams {
95
+ threadId: string;
96
+ /** Override the approval policy for subsequent turns. */
97
+ approvalPolicy?: AskForApproval;
98
+ /** Override the sandbox policy for subsequent turns. */
99
+ sandboxPolicy?: SandboxPolicy;
100
+ /** Override the model for subsequent turns. */
101
+ model?: string | null;
102
+ /** Override the model provider for subsequent turns. */
103
+ modelProvider?: string | null;
104
+ }
105
+ export interface ThreadSettingsUpdateResponse {
106
+ }
107
+ /** Server→client notification after a settings update is applied. */
108
+ export interface ThreadSettingsUpdatedNotification {
109
+ method: 'thread/settings/updated';
110
+ params: {
111
+ threadId: string;
112
+ threadSettings: unknown;
113
+ };
114
+ }
115
+ export interface ThreadCompactStartParams {
116
+ threadId: string;
117
+ }
118
+ export interface Thread {
119
+ id: string;
120
+ sessionId: string;
121
+ status: ThreadStatus;
122
+ cwd: string;
123
+ preview: string;
124
+ turns: Turn[];
125
+ createdAt: number;
126
+ updatedAt: number;
127
+ modelProvider: string;
128
+ cliVersion: string;
129
+ ephemeral: boolean;
130
+ name?: string | null;
131
+ forkedFromId?: string | null;
132
+ parentThreadId?: string | null;
133
+ }
134
+ export interface UserInput {
135
+ type: 'text';
136
+ text: string;
137
+ text_elements?: unknown[];
138
+ }
139
+ export interface TurnStartParams {
140
+ threadId: string;
141
+ input: UserInput[];
142
+ model?: string | null;
143
+ effort?: string | null;
144
+ cwd?: string | null;
145
+ approvalPolicy?: AskForApproval;
146
+ sandboxPolicy?: SandboxMode;
147
+ }
148
+ export interface TurnStartResponse {
149
+ turn: Turn;
150
+ }
151
+ export interface TurnInterruptParams {
152
+ threadId: string;
153
+ turnId: string;
154
+ }
155
+ export type TurnStatus = 'inProgress' | 'completed' | 'failed' | 'interrupted';
156
+ export interface TurnError {
157
+ message: string;
158
+ additionalDetails?: string | null;
159
+ codexErrorInfo?: unknown;
160
+ }
161
+ export interface Turn {
162
+ id: string;
163
+ items: ThreadItem[];
164
+ status: TurnStatus;
165
+ error?: TurnError | null;
166
+ startedAt?: number | null;
167
+ completedAt?: number | null;
168
+ durationMs?: number | null;
169
+ }
170
+ export interface AgentMessageItem {
171
+ type: 'agentMessage';
172
+ id: string;
173
+ text: string;
174
+ phase?: string | null;
175
+ }
176
+ export interface ReasoningItem {
177
+ type: 'reasoning';
178
+ id: string;
179
+ content?: string[];
180
+ summary?: string[];
181
+ }
182
+ export interface CommandExecutionItem {
183
+ type: 'commandExecution';
184
+ id: string;
185
+ command: string;
186
+ cwd?: string | null;
187
+ aggregatedOutput?: string | null;
188
+ status?: string | null;
189
+ }
190
+ export interface PlanItem {
191
+ type: 'plan';
192
+ id: string;
193
+ text: string;
194
+ }
195
+ export interface FileChangeItem {
196
+ type: 'fileChange';
197
+ id: string;
198
+ changes: FileUpdateChange[];
199
+ status: string;
200
+ }
201
+ export interface FileUpdateChangeKind {
202
+ type: 'add' | 'delete' | 'update';
203
+ /** Present only on `update` kind — the move destination, if any. */
204
+ move_path?: string | null;
205
+ }
206
+ export interface FileUpdateChange {
207
+ path: string;
208
+ kind: FileUpdateChangeKind;
209
+ diff: string;
210
+ }
211
+ export interface ObservationItem {
212
+ type: 'observation';
213
+ id: string;
214
+ content: string;
215
+ timestamp: number;
216
+ }
217
+ export interface DiffItem {
218
+ type: 'diff';
219
+ id: string;
220
+ diff: string;
221
+ timestamp: number;
222
+ }
223
+ export type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | PlanItem | FileChangeItem | ObservationItem | DiffItem | {
224
+ type: 'userMessage';
225
+ id: string;
226
+ content: unknown[];
227
+ } | {
228
+ type: 'contextCompaction';
229
+ id: string;
230
+ [key: string]: unknown;
231
+ } | {
232
+ type: string;
233
+ id: string;
234
+ [key: string]: unknown;
235
+ };
236
+ export interface PlanStep {
237
+ id?: string;
238
+ title: string;
239
+ subtitle?: string;
240
+ status?: 'pending' | 'in_progress' | 'completed' | 'error';
241
+ }
242
+ export declare const NotificationMethod: {
243
+ readonly TURN_STARTED: "turn/started";
244
+ readonly TURN_COMPLETED: "turn/completed";
245
+ readonly TURN_DIFF_UPDATED: "turn/diff/updated";
246
+ readonly TURN_PLAN_UPDATED: "turn/plan/updated";
247
+ readonly ITEM_STARTED: "item/started";
248
+ readonly ITEM_COMPLETED: "item/completed";
249
+ readonly AGENT_MESSAGE_DELTA: "item/agentMessage/delta";
250
+ readonly REASONING_SUMMARY_TEXT_DELTA: "item/reasoning/summaryTextDelta";
251
+ readonly REASONING_SUMMARY_PART_ADDED: "item/reasoning/summaryPartAdded";
252
+ readonly REASONING_TEXT_DELTA: "item/reasoning/textDelta";
253
+ readonly COMMAND_EXECUTION_OUTPUT_DELTA: "item/commandExecution/outputDelta";
254
+ readonly FILE_CHANGE_OUTPUT_DELTA: "item/fileChange/outputDelta";
255
+ readonly PLAN_DELTA: "item/plan/delta";
256
+ readonly TOKEN_USAGE_UPDATED: "thread/tokenUsage/updated";
257
+ readonly SERVER_REQUEST_RESOLVED: "serverRequest/resolved";
258
+ readonly ERROR: "error";
259
+ readonly WARNING: "warning";
260
+ readonly THREAD_STARTED: "thread/started";
261
+ readonly THREAD_STATUS_CHANGED: "thread/status/changed";
262
+ readonly THREAD_SETTINGS_UPDATED: "thread/settings/updated";
263
+ readonly THREAD_COMPACTED: "thread/compacted";
264
+ readonly MODEL_REROUTED: "model/rerouted";
265
+ };
266
+ export interface TurnStartedNotification {
267
+ method: 'turn/started';
268
+ params: {
269
+ threadId: string;
270
+ turn: Turn;
271
+ };
272
+ }
273
+ export interface TurnCompletedNotification {
274
+ method: 'turn/completed';
275
+ params: {
276
+ threadId: string;
277
+ turn: Turn;
278
+ };
279
+ }
280
+ export interface ItemStartedNotification {
281
+ method: 'item/started';
282
+ params: {
283
+ threadId: string;
284
+ turnId: string;
285
+ item: ThreadItem;
286
+ startedAtMs: number;
287
+ };
288
+ }
289
+ export interface ItemCompletedNotification {
290
+ method: 'item/completed';
291
+ params: {
292
+ threadId: string;
293
+ turnId: string;
294
+ item: ThreadItem;
295
+ completedAtMs: number;
296
+ };
297
+ }
298
+ export interface AgentMessageDeltaNotification {
299
+ method: 'item/agentMessage/delta';
300
+ params: {
301
+ threadId: string;
302
+ turnId: string;
303
+ itemId: string;
304
+ delta: string;
305
+ };
306
+ }
307
+ export interface ReasoningSummaryTextDeltaNotification {
308
+ method: 'item/reasoning/summaryTextDelta';
309
+ params: {
310
+ threadId: string;
311
+ turnId: string;
312
+ itemId: string;
313
+ delta: string;
314
+ };
315
+ }
316
+ export interface ReasoningSummaryPartAddedNotification {
317
+ method: 'item/reasoning/summaryPartAdded';
318
+ params: {
319
+ threadId: string;
320
+ turnId: string;
321
+ itemId: string;
322
+ summaryIndex: number;
323
+ };
324
+ }
325
+ export interface ReasoningTextDeltaNotification {
326
+ method: 'item/reasoning/textDelta';
327
+ params: {
328
+ threadId: string;
329
+ turnId: string;
330
+ itemId: string;
331
+ delta: string;
332
+ contentIndex: number;
333
+ };
334
+ }
335
+ export interface CommandExecutionOutputDeltaNotification {
336
+ method: 'item/commandExecution/outputDelta';
337
+ params: {
338
+ threadId: string;
339
+ turnId: string;
340
+ itemId: string;
341
+ delta: string;
342
+ };
343
+ }
344
+ export interface PlanDeltaNotification {
345
+ method: 'item/plan/delta';
346
+ params: {
347
+ threadId: string;
348
+ turnId: string;
349
+ itemId: string;
350
+ /** EXPERIMENTAL — plain-text plan delta; do not assume concatenation
351
+ * matches the completed plan item content. */
352
+ delta: string;
353
+ };
354
+ }
355
+ export interface FileChangeOutputDeltaNotification {
356
+ method: 'item/fileChange/outputDelta';
357
+ params: {
358
+ threadId: string;
359
+ turnId: string;
360
+ itemId: string;
361
+ delta: string;
362
+ };
363
+ }
364
+ export interface TokenUsageBreakdown {
365
+ inputTokens: number;
366
+ outputTokens: number;
367
+ cachedInputTokens?: number;
368
+ totalTokens?: number;
369
+ cacheReadTokens?: number;
370
+ cacheCreationTokens?: number;
371
+ }
372
+ export interface ThreadTokenUsage {
373
+ last: TokenUsageBreakdown;
374
+ total: TokenUsageBreakdown;
375
+ /** 当前模型 context window 上限(v2 schema 中与 last/total 平级;
376
+ * app-server 模式下唯一携带该信息的通道,CLI token_count 无此字段)。 */
377
+ modelContextWindow?: number;
378
+ }
379
+ export interface ThreadTokenUsageUpdatedNotification {
380
+ method: 'thread/tokenUsage/updated';
381
+ params: {
382
+ threadId: string;
383
+ turnId: string;
384
+ tokenUsage: ThreadTokenUsage;
385
+ };
386
+ }
387
+ export interface ServerRequestResolvedNotification {
388
+ method: 'serverRequest/resolved';
389
+ params: {
390
+ threadId: string;
391
+ requestId: number | string;
392
+ };
393
+ }
394
+ export interface ErrorNotification {
395
+ method: 'error';
396
+ params: {
397
+ error: TurnError;
398
+ threadId: string;
399
+ turnId: string;
400
+ willRetry: boolean;
401
+ };
402
+ }
403
+ export interface WarningNotification {
404
+ method: 'warning';
405
+ params: {
406
+ threadId?: string;
407
+ turnId?: string;
408
+ code: string;
409
+ message: string;
410
+ timestamp?: string;
411
+ };
412
+ }
413
+ export interface ThreadStatusChangedNotification {
414
+ method: 'thread/status/changed';
415
+ params: {
416
+ threadId: string;
417
+ status: string;
418
+ timestamp?: string;
419
+ };
420
+ }
421
+ export interface ModelReroutedNotification {
422
+ method: 'model/rerouted';
423
+ params: {
424
+ threadId: string;
425
+ turnId?: string;
426
+ model: string;
427
+ reason?: string;
428
+ timestamp?: string;
429
+ };
430
+ }
431
+ export declare const ServerRequestMethod: {
432
+ readonly COMMAND_EXECUTION_APPROVAL: "item/commandExecution/requestApproval";
433
+ readonly FILE_CHANGE_APPROVAL: "item/fileChange/requestApproval";
434
+ readonly PERMISSIONS_APPROVAL: "item/permissions/requestApproval";
435
+ };
436
+ export interface NetworkApprovalContext {
437
+ host: string;
438
+ protocol: string;
439
+ port?: number | null;
440
+ }
441
+ export interface CommandExecutionRequestApprovalParams {
442
+ threadId: string;
443
+ turnId: string;
444
+ itemId: string;
445
+ startedAtMs: number;
446
+ command?: string | null;
447
+ cwd?: string | null;
448
+ reason?: string | null;
449
+ availableDecisions?: CommandExecutionApprovalDecision[] | null;
450
+ networkApprovalContext?: NetworkApprovalContext | null;
451
+ approvalId?: string | null;
452
+ }
453
+ export interface NetworkPolicyAmendment {
454
+ host: string;
455
+ action: 'allow' | 'deny';
456
+ }
457
+ /** Real wire shape: plain-string decisions plus structured decisions. */
458
+ export type CommandExecutionApprovalDecision = 'accept' | 'acceptForSession' | 'decline' | 'cancel' | {
459
+ acceptWithExecpolicyAmendment: {
460
+ execpolicy_amendment: string[];
461
+ };
462
+ } | {
463
+ applyNetworkPolicyAmendment: {
464
+ network_policy_amendment: NetworkPolicyAmendment;
465
+ };
466
+ };
467
+ export interface CommandExecutionRequestApprovalResponse {
468
+ decision: CommandExecutionApprovalDecision;
469
+ }
470
+ export interface FileChangeRequestApprovalParams {
471
+ threadId: string;
472
+ turnId: string;
473
+ itemId: string;
474
+ startedAtMs: number;
475
+ grantRoot?: string | null;
476
+ reason?: string | null;
477
+ }
478
+ export type FileChangeApprovalDecision = 'accept' | 'acceptForSession' | 'decline' | 'cancel';
479
+ export interface FileChangeRequestApprovalResponse {
480
+ decision: FileChangeApprovalDecision;
481
+ }
482
+ export type FileSystemAccessMode = 'read' | 'write' | 'deny';
483
+ export interface FileSystemSandboxEntry {
484
+ path: string;
485
+ access: FileSystemAccessMode;
486
+ }
487
+ /** Real wire shape: `read`/`write` are legacy string arrays; `entries` is the
488
+ * current structured form (`[{ path, access }]`). */
489
+ export interface AdditionalFileSystemPermissions {
490
+ entries?: FileSystemSandboxEntry[] | null;
491
+ read?: string[] | null;
492
+ write?: string[] | null;
493
+ }
494
+ export interface AdditionalNetworkPermissions {
495
+ enabled?: boolean | null;
496
+ }
497
+ export interface RequestPermissionProfile {
498
+ fileSystem?: AdditionalFileSystemPermissions | null;
499
+ network?: AdditionalNetworkPermissions | null;
500
+ }
501
+ export interface GrantedPermissionProfile {
502
+ fileSystem?: AdditionalFileSystemPermissions | null;
503
+ network?: AdditionalNetworkPermissions | null;
504
+ }
505
+ export interface PermissionsRequestApprovalParams {
506
+ threadId: string;
507
+ turnId: string;
508
+ itemId: string;
509
+ startedAtMs: number;
510
+ cwd: string;
511
+ permissions: RequestPermissionProfile;
512
+ reason?: string | null;
513
+ }
514
+ export interface PermissionsRequestApprovalResponse {
515
+ permissions: GrantedPermissionProfile;
516
+ scope?: 'turn' | 'session';
517
+ }
518
+ /** Unsupported / ignored server request methods. */
519
+ export declare const UNSUPPORTED_SERVER_REQUEST_METHODS: Set<string>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Codex App Server JSON-RPC Protocol Types
3
+ *
4
+ * Aligned with the real `codex app-server` protocol (v2, generated via
5
+ * `codex app-server generate-json-schema --experimental`). Method names and
6
+ * field names use the wire format exactly: camelCase paths for methods
7
+ * (`item/agentMessage/delta`) and snake_case only where the server requires it
8
+ * (e.g. permission profile fields).
9
+ */
10
+ // =============================================================================
11
+ // Notifications (server → client)
12
+ // =============================================================================
13
+ export const NotificationMethod = {
14
+ TURN_STARTED: 'turn/started',
15
+ TURN_COMPLETED: 'turn/completed',
16
+ TURN_DIFF_UPDATED: 'turn/diff/updated',
17
+ TURN_PLAN_UPDATED: 'turn/plan/updated',
18
+ ITEM_STARTED: 'item/started',
19
+ ITEM_COMPLETED: 'item/completed',
20
+ AGENT_MESSAGE_DELTA: 'item/agentMessage/delta',
21
+ REASONING_SUMMARY_TEXT_DELTA: 'item/reasoning/summaryTextDelta',
22
+ REASONING_SUMMARY_PART_ADDED: 'item/reasoning/summaryPartAdded',
23
+ REASONING_TEXT_DELTA: 'item/reasoning/textDelta',
24
+ COMMAND_EXECUTION_OUTPUT_DELTA: 'item/commandExecution/outputDelta',
25
+ FILE_CHANGE_OUTPUT_DELTA: 'item/fileChange/outputDelta',
26
+ PLAN_DELTA: 'item/plan/delta',
27
+ TOKEN_USAGE_UPDATED: 'thread/tokenUsage/updated',
28
+ SERVER_REQUEST_RESOLVED: 'serverRequest/resolved',
29
+ ERROR: 'error',
30
+ WARNING: 'warning',
31
+ THREAD_STARTED: 'thread/started',
32
+ THREAD_STATUS_CHANGED: 'thread/status/changed',
33
+ THREAD_SETTINGS_UPDATED: 'thread/settings/updated',
34
+ THREAD_COMPACTED: 'thread/compacted',
35
+ MODEL_REROUTED: 'model/rerouted',
36
+ };
37
+ // =============================================================================
38
+ // Server Requests (approval)
39
+ // =============================================================================
40
+ export const ServerRequestMethod = {
41
+ COMMAND_EXECUTION_APPROVAL: 'item/commandExecution/requestApproval',
42
+ FILE_CHANGE_APPROVAL: 'item/fileChange/requestApproval',
43
+ PERMISSIONS_APPROVAL: 'item/permissions/requestApproval',
44
+ };
45
+ /** Unsupported / ignored server request methods. */
46
+ export const UNSUPPORTED_SERVER_REQUEST_METHODS = new Set([
47
+ 'item/tool/requestUserInput',
48
+ 'mcpServer/elicitation/request',
49
+ 'item/tool/call',
50
+ 'account/chatgptAuthTokens/refresh',
51
+ 'attestation/generate',
52
+ 'currentTime/read',
53
+ 'applyPatchApproval',
54
+ 'execCommandApproval',
55
+ ]);
56
+ //# sourceMappingURL=protocol-types.js.map
@@ -0,0 +1,104 @@
1
+ /**
2
+ * CodexAppServerRunner: workspace-lifetime runner using the Codex App Server
3
+ * protocol (`codex app-server`, JSON-RPC over stdio).
4
+ *
5
+ * Flow per run: acquire persistent connection → thread/start or thread/resume
6
+ * → turn/start → consume notifications (agent message deltas, approval server
7
+ * requests, …) until turn/completed → synthesize ResultEvent.
8
+ *
9
+ * Shares the ConnectionBasedRunner base with kimi/opencode: same notification
10
+ * queue + waitResolve pump, forceFinish/stopRequested semantics, turn idle
11
+ * watchdog, and ConnectionLostError respawn-and-retry-once.
12
+ */
13
+ import type { AgentKind, AgentSessionReader, AgentEvent, AgentStatusInfo, SpawnOptions } from '../../types.js';
14
+ import { JsonRpcClient } from '../../common/jsonrpc/client.js';
15
+ import { type TranslatorEvent } from './translator.js';
16
+ import { type AskForApproval, type SandboxMode, type SandboxPolicy, type InitializeResult } from './protocol-types.js';
17
+ import { ConnectionBasedRunner } from '../../common/connection-based-runner.js';
18
+ export interface CodexAppServerRunnerOptions {
19
+ kind: AgentKind;
20
+ sessionReader: AgentSessionReader;
21
+ /** Path to the codex binary. Defaults to `codex`. */
22
+ binary?: string;
23
+ /** Environment variables. */
24
+ env?: Record<string, string | undefined>;
25
+ /** Args to spawn the app server with. Defaults to `['app-server', '--stdio']`. */
26
+ appServerArgs?: string[];
27
+ /** Request timeout in milliseconds. */
28
+ requestTimeoutMs?: number;
29
+ /** Idle TTL for connection manager. */
30
+ idleTtlMs?: number;
31
+ /** How long to wait for turn output before failing. Defaults to 10 min. */
32
+ turnTimeoutMs?: number;
33
+ model?: string;
34
+ modelProvider?: string;
35
+ reasoningEffort?: string;
36
+ /** Configured sandbox mode (Codex 官方 SandboxMode 标准值). */
37
+ sandbox?: SandboxMode;
38
+ /** Configured approval policy (Codex 官方 AskForApproval 标准值). */
39
+ approvalPolicy?: AskForApproval;
40
+ }
41
+ /**
42
+ * Map the client-side SandboxMode enum to the response-side SandboxPolicy
43
+ * object used by `thread/settings/update` (`sandboxPolicy`).
44
+ */
45
+ export declare function sandboxModeToSandboxPolicy(mode: SandboxMode): SandboxPolicy;
46
+ export declare class CodexAppServerRunner extends ConnectionBasedRunner<JsonRpcClient<InitializeResult>, TranslatorEvent> {
47
+ private connectionManager;
48
+ private currentTranslator;
49
+ private activeThreadId;
50
+ private model?;
51
+ private modelProvider?;
52
+ private reasoningEffort?;
53
+ private sandboxConfig?;
54
+ private approvalPolicyConfig?;
55
+ /** Pending approval requests: requestId (JSON-RPC id) → kind + view. */
56
+ private pendingApprovals;
57
+ constructor(opts: CodexAppServerRunnerOptions);
58
+ protected get logTag(): string;
59
+ protected get turnTimeoutErrorMessage(): string;
60
+ protected get turnInterruptedErrorMessage(): string;
61
+ protected currentSessionId(): string | null;
62
+ protected shouldDeferStop(): boolean;
63
+ protected cancelCurrentTurn(): Promise<void>;
64
+ protected clearTurnState(): void;
65
+ protected releaseConnection(cwd: string): Promise<void>;
66
+ protected notifyIdle(cwd: string): void;
67
+ protected disposeConnections(): Promise<void>;
68
+ /**
69
+ * Run a compact operation on the current thread.
70
+ */
71
+ runCompact(_message: string, opts: SpawnOptions): AsyncGenerator<AgentEvent>;
72
+ /**
73
+ * Respond to an approval server request. `response` is the bridge
74
+ * ApprovalAction (`{ action: 'accept' | 'accept_for_session' | 'decline' | 'cancel' }`).
75
+ */
76
+ respondApproval(requestId: number | string, response: unknown): Promise<void>;
77
+ getStatusInfo(): AgentStatusInfo;
78
+ /**
79
+ * Unified approval-mode hot-update entry (called by the bridge via duck
80
+ * typing on active runs). Codex's `thread/settings/update` applies the new
81
+ * approval/sandbox policy to subsequent turns, even while the current turn
82
+ * is still active. This lets `/config` take effect without waiting for this
83
+ * workspace-lifetime runner to be recreated/evicted. Local fields are always
84
+ * updated so `/status` reflects the new config immediately; if there is no
85
+ * live thread, the next `thread/start`/`thread/resume` uses the new values
86
+ * anyway.
87
+ */
88
+ updateApprovalMode(settings: {
89
+ approvalPolicy?: AskForApproval;
90
+ sandbox?: SandboxMode;
91
+ }): Promise<void>;
92
+ private buildThreadParams;
93
+ private buildTurnParams;
94
+ /**
95
+ * Acquire the connection and set up the turn: thread/start(新会话)或
96
+ * thread/resume(按 sessionId 恢复既有线程)→ turn/start。
97
+ */
98
+ protected setupTurn(message: string, opts: SpawnOptions): Promise<void>;
99
+ private handleNotification;
100
+ private handleServerRequest;
101
+ private buildGrantedPermissions;
102
+ /** 拒绝权限审批:空 fileSystem + 关闭网络(真实 GrantedPermissionProfile)。 */
103
+ private denyAllPermissions;
104
+ }