@kodelyth/codex 2026.5.42 → 2026.6.2

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 (138) hide show
  1. package/package.json +17 -2
  2. package/doctor-contract-api.test.ts +0 -44
  3. package/doctor-contract-api.ts +0 -68
  4. package/harness.ts +0 -72
  5. package/index.test.ts +0 -230
  6. package/index.ts +0 -66
  7. package/media-understanding-provider.test.ts +0 -486
  8. package/media-understanding-provider.ts +0 -521
  9. package/prompt-overlay-runtime-contract.test.ts +0 -48
  10. package/prompt-overlay.ts +0 -21
  11. package/provider-catalog.ts +0 -83
  12. package/provider-discovery.ts +0 -45
  13. package/provider.test.ts +0 -384
  14. package/provider.ts +0 -243
  15. package/src/app-server/app-inventory-cache.test.ts +0 -176
  16. package/src/app-server/app-inventory-cache.ts +0 -324
  17. package/src/app-server/approval-bridge.test.ts +0 -1471
  18. package/src/app-server/approval-bridge.ts +0 -1211
  19. package/src/app-server/auth-bridge.test.ts +0 -1449
  20. package/src/app-server/auth-bridge.ts +0 -614
  21. package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
  22. package/src/app-server/capabilities.ts +0 -27
  23. package/src/app-server/client-factory.ts +0 -24
  24. package/src/app-server/client.test.ts +0 -563
  25. package/src/app-server/client.ts +0 -715
  26. package/src/app-server/compact.test.ts +0 -710
  27. package/src/app-server/compact.ts +0 -500
  28. package/src/app-server/computer-use.test.ts +0 -788
  29. package/src/app-server/computer-use.ts +0 -683
  30. package/src/app-server/config.test.ts +0 -879
  31. package/src/app-server/config.ts +0 -1038
  32. package/src/app-server/context-engine-projection.test.ts +0 -252
  33. package/src/app-server/context-engine-projection.ts +0 -403
  34. package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
  35. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  36. package/src/app-server/dynamic-tool-profile.ts +0 -69
  37. package/src/app-server/dynamic-tools.test.ts +0 -1302
  38. package/src/app-server/dynamic-tools.ts +0 -623
  39. package/src/app-server/elicitation-bridge.test.ts +0 -1056
  40. package/src/app-server/elicitation-bridge.ts +0 -783
  41. package/src/app-server/event-projector.test.ts +0 -2668
  42. package/src/app-server/event-projector.ts +0 -2057
  43. package/src/app-server/image-payload-sanitizer.test.ts +0 -49
  44. package/src/app-server/image-payload-sanitizer.ts +0 -167
  45. package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
  46. package/src/app-server/local-runtime-attribution.ts +0 -39
  47. package/src/app-server/managed-binary.test.ts +0 -139
  48. package/src/app-server/managed-binary.ts +0 -193
  49. package/src/app-server/models.test.ts +0 -246
  50. package/src/app-server/models.ts +0 -172
  51. package/src/app-server/native-hook-relay.test.ts +0 -271
  52. package/src/app-server/native-hook-relay.ts +0 -150
  53. package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
  54. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  55. package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
  56. package/src/app-server/plugin-activation.test.ts +0 -336
  57. package/src/app-server/plugin-activation.ts +0 -283
  58. package/src/app-server/plugin-app-cache-key.ts +0 -74
  59. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  60. package/src/app-server/plugin-inventory.test.ts +0 -355
  61. package/src/app-server/plugin-inventory.ts +0 -357
  62. package/src/app-server/plugin-thread-config.test.ts +0 -865
  63. package/src/app-server/plugin-thread-config.ts +0 -455
  64. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  65. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  66. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  67. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  68. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  69. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  70. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  71. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  72. package/src/app-server/protocol-validators.test.ts +0 -75
  73. package/src/app-server/protocol-validators.ts +0 -203
  74. package/src/app-server/protocol.ts +0 -520
  75. package/src/app-server/rate-limit-cache.ts +0 -48
  76. package/src/app-server/rate-limits.test.ts +0 -202
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
  80. package/src/app-server/run-attempt.test.ts +0 -9477
  81. package/src/app-server/run-attempt.ts +0 -4683
  82. package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
  83. package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
  84. package/src/app-server/session-binding.test.ts +0 -303
  85. package/src/app-server/session-binding.ts +0 -398
  86. package/src/app-server/session-history.ts +0 -44
  87. package/src/app-server/shared-client.test.ts +0 -589
  88. package/src/app-server/shared-client.ts +0 -289
  89. package/src/app-server/side-question.test.ts +0 -1175
  90. package/src/app-server/side-question.ts +0 -1007
  91. package/src/app-server/test-support.ts +0 -48
  92. package/src/app-server/thread-lifecycle.test.ts +0 -447
  93. package/src/app-server/thread-lifecycle.ts +0 -939
  94. package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
  95. package/src/app-server/timeout.ts +0 -9
  96. package/src/app-server/tool-progress-normalization.ts +0 -77
  97. package/src/app-server/trajectory.test.ts +0 -205
  98. package/src/app-server/trajectory.ts +0 -365
  99. package/src/app-server/transcript-mirror.test.ts +0 -524
  100. package/src/app-server/transcript-mirror.ts +0 -208
  101. package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
  102. package/src/app-server/transport-stdio.test.ts +0 -171
  103. package/src/app-server/transport-stdio.ts +0 -107
  104. package/src/app-server/transport-websocket.test.ts +0 -69
  105. package/src/app-server/transport-websocket.ts +0 -90
  106. package/src/app-server/transport.ts +0 -117
  107. package/src/app-server/user-input-bridge.test.ts +0 -249
  108. package/src/app-server/user-input-bridge.ts +0 -316
  109. package/src/app-server/version.ts +0 -4
  110. package/src/app-server/vision-tools.ts +0 -12
  111. package/src/command-account.ts +0 -544
  112. package/src/command-formatters.ts +0 -425
  113. package/src/command-handlers.ts +0 -2004
  114. package/src/command-rpc.test.ts +0 -16
  115. package/src/command-rpc.ts +0 -142
  116. package/src/commands.test.ts +0 -3312
  117. package/src/commands.ts +0 -65
  118. package/src/conversation-binding-data.ts +0 -124
  119. package/src/conversation-binding.test.ts +0 -599
  120. package/src/conversation-binding.ts +0 -561
  121. package/src/conversation-control.test.ts +0 -126
  122. package/src/conversation-control.ts +0 -303
  123. package/src/conversation-turn-collector.test.ts +0 -191
  124. package/src/conversation-turn-collector.ts +0 -186
  125. package/src/conversation-turn-input.test.ts +0 -141
  126. package/src/conversation-turn-input.ts +0 -106
  127. package/src/manifest.test.ts +0 -20
  128. package/src/migration/apply.ts +0 -501
  129. package/src/migration/helpers.ts +0 -55
  130. package/src/migration/plan.ts +0 -461
  131. package/src/migration/provider.test.ts +0 -1741
  132. package/src/migration/provider.ts +0 -41
  133. package/src/migration/source.ts +0 -643
  134. package/src/migration/targets.ts +0 -25
  135. package/src/node-cli-sessions.test.ts +0 -180
  136. package/src/node-cli-sessions.ts +0 -711
  137. package/test-api.ts +0 -82
  138. package/tsconfig.json +0 -16
@@ -1,1056 +0,0 @@
1
- import {
2
- callGatewayTool,
3
- embeddedAgentLog,
4
- type EmbeddedRunAttemptParams,
5
- } from "klaw/plugin-sdk/agent-harness-runtime";
6
- import { beforeEach, describe, expect, it, vi } from "vitest";
7
- import { handleCodexAppServerElicitationRequest } from "./elicitation-bridge.js";
8
-
9
- vi.mock("klaw/plugin-sdk/agent-harness-runtime", async (importOriginal) => ({
10
- ...(await importOriginal<typeof import("klaw/plugin-sdk/agent-harness-runtime")>()),
11
- callGatewayTool: vi.fn(),
12
- }));
13
-
14
- const mockCallGatewayTool = vi.mocked(callGatewayTool);
15
-
16
- function mockCall(mock: { mock: { calls: unknown[][] } }, index = 0) {
17
- return mock.mock.calls.at(index);
18
- }
19
-
20
- function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0) {
21
- return mockCall(mock, index)?.at(argIndex);
22
- }
23
-
24
- function gatewayToolCall(index = 0) {
25
- return mockCall(mockCallGatewayTool, index);
26
- }
27
-
28
- function gatewayToolArg(index = 0, argIndex = 0) {
29
- return mockCallArg(mockCallGatewayTool, index, argIndex);
30
- }
31
-
32
- function createParams(): EmbeddedRunAttemptParams {
33
- return {
34
- sessionKey: "agent:main:session-1",
35
- agentId: "main",
36
- messageChannel: "telegram",
37
- currentChannelId: "chat-1",
38
- agentAccountId: "default",
39
- currentThreadTs: "thread-ts",
40
- } as unknown as EmbeddedRunAttemptParams;
41
- }
42
-
43
- function buildApprovalElicitation() {
44
- return {
45
- threadId: "thread-1",
46
- turnId: "turn-1",
47
- serverName: "codex_apps__github",
48
- mode: "form",
49
- message: "Approve app tool call?",
50
- _meta: {
51
- codex_approval_kind: "mcp_tool_call",
52
- persist: ["session", "always"],
53
- },
54
- requestedSchema: {
55
- type: "object",
56
- properties: {
57
- approve: {
58
- type: "boolean",
59
- title: "Approve this tool call",
60
- },
61
- persist: {
62
- type: "string",
63
- title: "Persist choice",
64
- enum: ["session", "always"],
65
- },
66
- },
67
- required: ["approve"],
68
- },
69
- };
70
- }
71
-
72
- function buildCurrentCodexApprovalElicitation() {
73
- return {
74
- ...buildApprovalElicitation(),
75
- _meta: {
76
- codex_approval_kind: "mcp_tool_call",
77
- persist: ["session", "always"],
78
- connector_name: "GitHub",
79
- tool_title: "Create pull request",
80
- tool_description: "Creates a pull request in the selected repository.",
81
- tool_params_display: [{ name: "repo", display_name: "Repository", value: "klaw/klaw" }],
82
- },
83
- requestedSchema: {
84
- type: "object",
85
- properties: {},
86
- },
87
- };
88
- }
89
-
90
- function buildPluginApprovalElicitation(overrides: Record<string, unknown> = {}) {
91
- return {
92
- threadId: "thread-1",
93
- turnId: "turn-1",
94
- serverName: "google-calendar-mcp",
95
- mode: "form",
96
- message: "Approve app action?",
97
- _meta: {
98
- app_id: "google-calendar-app",
99
- },
100
- requestedSchema: {
101
- type: "object",
102
- properties: {
103
- approve: {
104
- type: "boolean",
105
- title: "Approve this app action",
106
- },
107
- },
108
- required: ["approve"],
109
- },
110
- ...overrides,
111
- };
112
- }
113
-
114
- function buildConnectorPluginApprovalElicitation(overrides: Record<string, unknown> = {}) {
115
- return {
116
- threadId: "thread-1",
117
- turnId: "turn-1",
118
- serverName: "codex_apps",
119
- mode: "form",
120
- message: "Allow Google Calendar to create an event?",
121
- _meta: {
122
- codex_approval_kind: "mcp_tool_call",
123
- source: "connector",
124
- connector_id: "connector_google_calendar",
125
- connector_name: "Google Calendar",
126
- tool_title: "create_event",
127
- },
128
- requestedSchema: {
129
- type: "object",
130
- properties: {},
131
- },
132
- ...overrides,
133
- };
134
- }
135
-
136
- function createPluginAppPolicyContext(
137
- params: {
138
- allowDestructiveActions?: boolean;
139
- apps?: Array<{ appId: string; pluginName: string; mcpServerNames: string[] }>;
140
- } = {},
141
- ) {
142
- const apps = params.apps ?? [
143
- {
144
- appId: "google-calendar-app",
145
- pluginName: "google-calendar",
146
- mcpServerNames: ["google-calendar-mcp"],
147
- },
148
- ];
149
- return {
150
- fingerprint: "plugin-policy-1",
151
- apps: Object.fromEntries(
152
- apps.map((app) => [
153
- app.appId,
154
- {
155
- configKey: app.pluginName,
156
- marketplaceName: "openai-curated" as const,
157
- pluginName: app.pluginName,
158
- allowDestructiveActions: params.allowDestructiveActions ?? false,
159
- mcpServerNames: app.mcpServerNames,
160
- },
161
- ]),
162
- ),
163
- pluginAppIds: Object.fromEntries(
164
- apps.map((app) => [app.pluginName, appsForPlugin(apps, app.pluginName)]),
165
- ),
166
- };
167
- }
168
-
169
- function appsForPlugin(
170
- apps: Array<{ appId: string; pluginName: string; mcpServerNames: string[] }>,
171
- pluginName: string,
172
- ): string[] {
173
- return apps
174
- .filter((app) => app.pluginName === pluginName)
175
- .map((app) => app.appId)
176
- .toSorted();
177
- }
178
-
179
- describe("Codex app-server elicitation bridge", () => {
180
- beforeEach(() => {
181
- mockCallGatewayTool.mockReset();
182
- vi.restoreAllMocks();
183
- });
184
-
185
- it("routes MCP tool approval elicitations through plugin approvals", async () => {
186
- mockCallGatewayTool
187
- .mockResolvedValueOnce({ id: "plugin:approval-1", status: "accepted" })
188
- .mockResolvedValueOnce({ id: "plugin:approval-1", decision: "allow-once" });
189
-
190
- const result = await handleCodexAppServerElicitationRequest({
191
- requestParams: buildApprovalElicitation(),
192
- paramsForRun: createParams(),
193
- threadId: "thread-1",
194
- turnId: "turn-1",
195
- });
196
-
197
- expect(result).toEqual({
198
- action: "accept",
199
- content: {
200
- approve: true,
201
- },
202
- _meta: null,
203
- });
204
- expect(mockCallGatewayTool.mock.calls.map(([method]) => method)).toEqual([
205
- "plugin.approval.request",
206
- "plugin.approval.waitDecision",
207
- ]);
208
- });
209
-
210
- it("does not trust request-time decisions for two-phase MCP approvals", async () => {
211
- mockCallGatewayTool
212
- .mockResolvedValueOnce({
213
- id: "plugin:approval-untrusted",
214
- status: "accepted",
215
- decision: "allow-always",
216
- })
217
- .mockResolvedValueOnce({ id: "plugin:approval-untrusted", decision: "deny" });
218
-
219
- const result = await handleCodexAppServerElicitationRequest({
220
- requestParams: buildApprovalElicitation(),
221
- paramsForRun: createParams(),
222
- threadId: "thread-1",
223
- turnId: "turn-1",
224
- });
225
-
226
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
227
- expect(mockCallGatewayTool.mock.calls.map(([method]) => method)).toEqual([
228
- "plugin.approval.request",
229
- "plugin.approval.waitDecision",
230
- ]);
231
- });
232
-
233
- it("does not treat inherited request-time MCP decisions as final", async () => {
234
- const inheritedDecisionResult = Object.assign(Object.create({ decision: null }), {
235
- id: "plugin:approval-inherited",
236
- status: "accepted",
237
- });
238
- mockCallGatewayTool
239
- .mockResolvedValueOnce(inheritedDecisionResult)
240
- .mockResolvedValueOnce({ id: "plugin:approval-inherited", decision: "allow-once" });
241
-
242
- const result = await handleCodexAppServerElicitationRequest({
243
- requestParams: buildApprovalElicitation(),
244
- paramsForRun: createParams(),
245
- threadId: "thread-1",
246
- turnId: "turn-1",
247
- });
248
-
249
- expect(result).toEqual({
250
- action: "accept",
251
- content: {
252
- approve: true,
253
- },
254
- _meta: null,
255
- });
256
- expect(mockCallGatewayTool.mock.calls.map(([method]) => method)).toEqual([
257
- "plugin.approval.request",
258
- "plugin.approval.waitDecision",
259
- ]);
260
- });
261
-
262
- it("accepts current Codex MCP approval elicitations with an empty form schema", async () => {
263
- mockCallGatewayTool
264
- .mockResolvedValueOnce({ id: "plugin:approval-current", status: "accepted" })
265
- .mockResolvedValueOnce({ id: "plugin:approval-current", decision: "allow-once" });
266
-
267
- const result = await handleCodexAppServerElicitationRequest({
268
- requestParams: buildCurrentCodexApprovalElicitation(),
269
- paramsForRun: createParams(),
270
- threadId: "thread-1",
271
- turnId: "turn-1",
272
- });
273
-
274
- expect(result).toEqual({
275
- action: "accept",
276
- content: null,
277
- _meta: null,
278
- });
279
- const approvalRequestCall = gatewayToolCall();
280
- expect(approvalRequestCall?.[0]).toBe("plugin.approval.request");
281
- expect(approvalRequestCall?.[1]).toStrictEqual({ timeoutMs: 130_000 });
282
- expect(approvalRequestCall?.[3]).toStrictEqual({ expectFinal: false });
283
- const approvalRequest = gatewayToolArg(0, 2) as {
284
- description: string;
285
- };
286
- expect(approvalRequest.description).toContain("App: GitHub");
287
- expect(approvalRequest.description).toContain("Tool: Create pull request");
288
- expect(approvalRequest.description).toContain("Repository: klaw/klaw");
289
- });
290
-
291
- it("strips control and invisible formatting from approval display text", async () => {
292
- mockCallGatewayTool
293
- .mockResolvedValueOnce({ id: "plugin:approval-sanitized", status: "accepted" })
294
- .mockResolvedValueOnce({ id: "plugin:approval-sanitized", decision: "allow-once" });
295
-
296
- await handleCodexAppServerElicitationRequest({
297
- requestParams: {
298
- ...buildCurrentCodexApprovalElicitation(),
299
- message: "Approve\u202e hidden",
300
- serverName: "codex\u009b31m_apps__github",
301
- _meta: {
302
- codex_approval_kind: "mcp_tool_call",
303
- connector_name: "GitHub\nInjected: approve",
304
- tool_title: "\u001b]8;;https://evil.example\u001b\\Visible tool\u001b]8;;\u001b\\",
305
- tool_description: "Creates\u0000 a\u202e pull request",
306
- tool_params_display: [
307
- {
308
- name: "repo",
309
- display_name: "Repository\u202e",
310
- value: "\u001b]8;;https://evil.example\u001b\\klaw/klaw\u001b]8;;\u001b\\",
311
- },
312
- ],
313
- },
314
- requestedSchema: {
315
- type: "object",
316
- properties: {
317
- approve: {
318
- type: "boolean",
319
- title: "Approve\u202e this tool call",
320
- description: "Confirm\u009b31m access",
321
- },
322
- },
323
- required: ["approve"],
324
- },
325
- },
326
- paramsForRun: createParams(),
327
- threadId: "thread-1",
328
- turnId: "turn-1",
329
- });
330
-
331
- const approvalRequest = gatewayToolArg(0, 2) as {
332
- title: string;
333
- description: string;
334
- };
335
- expect(approvalRequest.title).toBe("Approve hidden");
336
- expect(approvalRequest.description).toContain("GitHub Injected: approve");
337
- expect(approvalRequest.description).toContain("Tool: Visible tool");
338
- expect(approvalRequest.description).toContain("Repository: klaw/klaw");
339
- expect(approvalRequest.description).toContain("- Approve this tool call: Confirm access");
340
- expect(approvalRequest.description).not.toContain("https://evil.example");
341
- expect(approvalRequest.description).not.toContain("\u001b");
342
- expect(approvalRequest.description).not.toContain("\u009b");
343
- expect(approvalRequest.description).not.toContain("\u202e");
344
- });
345
-
346
- it("escapes approval display text before forwarding approval prompts", async () => {
347
- mockCallGatewayTool
348
- .mockResolvedValueOnce({ id: "plugin:approval-escaped", status: "accepted" })
349
- .mockResolvedValueOnce({ id: "plugin:approval-escaped", decision: "allow-once" });
350
-
351
- await handleCodexAppServerElicitationRequest({
352
- requestParams: {
353
- ...buildCurrentCodexApprovalElicitation(),
354
- message: "Approve <@U123>",
355
- serverName: "server @here",
356
- _meta: {
357
- codex_approval_kind: "mcp_tool_call",
358
- connector_name: "GitHub [trusted](https://evil)",
359
- tool_title: "Create <@U123>",
360
- tool_description: "Use @here",
361
- tool_params_display: [
362
- {
363
- name: "repo",
364
- display_name: "Repository [trusted](https://evil)",
365
- value: "<@U123>",
366
- },
367
- ],
368
- },
369
- requestedSchema: {
370
- type: "object",
371
- properties: {
372
- approve: {
373
- type: "boolean",
374
- title: "Approve <@U123>",
375
- description: "Confirm @here",
376
- },
377
- },
378
- required: ["approve"],
379
- },
380
- },
381
- paramsForRun: createParams(),
382
- threadId: "thread-1",
383
- turnId: "turn-1",
384
- });
385
-
386
- const approvalRequest = gatewayToolArg(0, 2) as {
387
- title: string;
388
- description: string;
389
- };
390
- expect(approvalRequest.title).toBe("Approve &lt;\uff20U123&gt;");
391
- expect(approvalRequest.description).toContain(
392
- "GitHub \uff3btrusted\uff3d\uff08https://evil\uff09",
393
- );
394
- expect(approvalRequest.description).toContain("Tool: Create &lt;\uff20U123&gt;");
395
- expect(approvalRequest.description).toContain("MCP server: server \uff20here");
396
- expect(approvalRequest.description).toContain(
397
- "Repository \uff3btrusted\uff3d\uff08https://evil\uff09: &lt;\uff20U123&gt;",
398
- );
399
- expect(approvalRequest.description).toContain(
400
- "- Approve &lt;\uff20U123&gt;: Confirm \uff20here",
401
- );
402
- expect(approvalRequest.description).not.toContain("<@U123>");
403
- expect(approvalRequest.description).not.toContain("[trusted](https://evil)");
404
- expect(approvalRequest.description).not.toContain("@here");
405
- });
406
-
407
- it("falls back to stable names when display labels sanitize to empty", async () => {
408
- mockCallGatewayTool
409
- .mockResolvedValueOnce({ id: "plugin:approval-label-fallback", status: "accepted" })
410
- .mockResolvedValueOnce({ id: "plugin:approval-label-fallback", decision: "allow-once" });
411
-
412
- await handleCodexAppServerElicitationRequest({
413
- requestParams: {
414
- ...buildCurrentCodexApprovalElicitation(),
415
- message: "Approve",
416
- _meta: {
417
- codex_approval_kind: "mcp_tool_call",
418
- connector_name: "App",
419
- tool_params_display: [
420
- {
421
- name: "repo",
422
- display_name: "\u202e",
423
- value: "klaw/klaw",
424
- },
425
- ],
426
- },
427
- requestedSchema: {
428
- type: "object",
429
- properties: {
430
- approve: {
431
- type: "boolean",
432
- title: "\u202e",
433
- description: "Confirm access",
434
- },
435
- },
436
- required: ["approve"],
437
- },
438
- },
439
- paramsForRun: createParams(),
440
- threadId: "thread-1",
441
- turnId: "turn-1",
442
- });
443
-
444
- const approvalRequest = gatewayToolArg(0, 2) as {
445
- description: string;
446
- };
447
- expect(approvalRequest.description).toContain("- repo: klaw/klaw");
448
- expect(approvalRequest.description).toContain("- approve: Confirm access");
449
- expect(approvalRequest.description).not.toContain("- field: Confirm access");
450
- });
451
-
452
- it("bounds deep approval display parameter values before forwarding them", async () => {
453
- mockCallGatewayTool
454
- .mockResolvedValueOnce({ id: "plugin:approval-bounded-params", status: "accepted" })
455
- .mockResolvedValueOnce({ id: "plugin:approval-bounded-params", decision: "allow-once" });
456
-
457
- await handleCodexAppServerElicitationRequest({
458
- requestParams: {
459
- ...buildCurrentCodexApprovalElicitation(),
460
- message: "Approve",
461
- _meta: {
462
- codex_approval_kind: "mcp_tool_call",
463
- connector_name: "App",
464
- tool_title: "Tool",
465
- tool_params_display: [
466
- {
467
- name: "payload",
468
- value: {
469
- key0: { nested: { deeper: { secret: "hidden" } } },
470
- key1: 1,
471
- key2: 2,
472
- key3: 3,
473
- key4: 4,
474
- key5: 5,
475
- key6: 6,
476
- key7: 7,
477
- key8: 8,
478
- },
479
- },
480
- ],
481
- },
482
- },
483
- paramsForRun: createParams(),
484
- threadId: "thread-1",
485
- turnId: "turn-1",
486
- });
487
-
488
- const approvalRequest = gatewayToolArg(0, 2) as {
489
- description: string;
490
- };
491
- expect(approvalRequest.description).toContain("payload");
492
- expect(approvalRequest.description).toContain("key0");
493
- expect(approvalRequest.description).not.toContain("key8");
494
- expect(approvalRequest.description).not.toContain("hidden");
495
- });
496
-
497
- it("caps approval display parameter entries before forwarding them", async () => {
498
- mockCallGatewayTool
499
- .mockResolvedValueOnce({ id: "plugin:approval-capped-params", status: "accepted" })
500
- .mockResolvedValueOnce({ id: "plugin:approval-capped-params", decision: "allow-once" });
501
-
502
- await handleCodexAppServerElicitationRequest({
503
- requestParams: {
504
- ...buildCurrentCodexApprovalElicitation(),
505
- message: "Approve",
506
- serverName: "",
507
- _meta: {
508
- codex_approval_kind: "mcp_tool_call",
509
- connector_name: "App",
510
- tool_params_display: Array.from({ length: 9 }, (_, index) => ({
511
- name: `p${index}`,
512
- value: index,
513
- })),
514
- },
515
- },
516
- paramsForRun: createParams(),
517
- threadId: "thread-1",
518
- turnId: "turn-1",
519
- });
520
-
521
- const approvalRequest = gatewayToolArg(0, 2) as {
522
- description: string;
523
- };
524
- expect(approvalRequest.description).toContain("p0");
525
- expect(approvalRequest.description).toContain("p7");
526
- expect(approvalRequest.description).toContain("Additional parameters: 1 more");
527
- expect(approvalRequest.description).not.toContain("p8");
528
- });
529
-
530
- it("accepts approval elicitations with a null turn id when the thread matches", async () => {
531
- mockCallGatewayTool
532
- .mockResolvedValueOnce({ id: "plugin:approval-null-turn", status: "accepted" })
533
- .mockResolvedValueOnce({ id: "plugin:approval-null-turn", decision: "allow-once" });
534
-
535
- const result = await handleCodexAppServerElicitationRequest({
536
- requestParams: {
537
- ...buildCurrentCodexApprovalElicitation(),
538
- turnId: null,
539
- },
540
- paramsForRun: createParams(),
541
- threadId: "thread-1",
542
- turnId: "turn-1",
543
- });
544
-
545
- expect(result).toEqual({
546
- action: "accept",
547
- content: null,
548
- _meta: null,
549
- });
550
- });
551
-
552
- it("declines plugin app elicitations when destructive actions are disabled", async () => {
553
- const result = await handleCodexAppServerElicitationRequest({
554
- requestParams: buildPluginApprovalElicitation(),
555
- paramsForRun: createParams(),
556
- threadId: "thread-1",
557
- turnId: "turn-1",
558
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: false }),
559
- });
560
-
561
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
562
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
563
- });
564
-
565
- it("accepts safely mapped plugin app elicitations when destructive actions are enabled", async () => {
566
- const result = await handleCodexAppServerElicitationRequest({
567
- requestParams: buildPluginApprovalElicitation(),
568
- paramsForRun: createParams(),
569
- threadId: "thread-1",
570
- turnId: "turn-1",
571
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
572
- });
573
-
574
- expect(result).toEqual({
575
- action: "accept",
576
- content: { approve: true },
577
- _meta: null,
578
- });
579
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
580
- });
581
-
582
- it("accepts connector-id plugin app elicitations when destructive actions are enabled", async () => {
583
- const result = await handleCodexAppServerElicitationRequest({
584
- requestParams: buildConnectorPluginApprovalElicitation(),
585
- paramsForRun: createParams(),
586
- threadId: "thread-1",
587
- turnId: "turn-1",
588
- pluginAppPolicyContext: createPluginAppPolicyContext({
589
- allowDestructiveActions: true,
590
- apps: [
591
- {
592
- appId: "connector_google_calendar",
593
- pluginName: "google-calendar",
594
- mcpServerNames: [],
595
- },
596
- ],
597
- }),
598
- });
599
-
600
- expect(result).toEqual({
601
- action: "accept",
602
- content: null,
603
- _meta: null,
604
- });
605
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
606
- });
607
-
608
- it("declines connector-id plugin app elicitations when destructive actions are disabled", async () => {
609
- const result = await handleCodexAppServerElicitationRequest({
610
- requestParams: buildConnectorPluginApprovalElicitation(),
611
- paramsForRun: createParams(),
612
- threadId: "thread-1",
613
- turnId: "turn-1",
614
- pluginAppPolicyContext: createPluginAppPolicyContext({
615
- allowDestructiveActions: false,
616
- apps: [
617
- {
618
- appId: "connector_google_calendar",
619
- pluginName: "google-calendar",
620
- mcpServerNames: [],
621
- },
622
- ],
623
- }),
624
- });
625
-
626
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
627
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
628
- });
629
-
630
- it("declines live connector elicitations that only match display names", async () => {
631
- const result = await handleCodexAppServerElicitationRequest({
632
- requestParams: buildConnectorPluginApprovalElicitation({
633
- _meta: {
634
- codex_approval_kind: "mcp_tool_call",
635
- source: "connector",
636
- connector_name: "Google Calendar",
637
- tool_title: "create_event",
638
- },
639
- }),
640
- paramsForRun: createParams(),
641
- threadId: "thread-1",
642
- turnId: "turn-1",
643
- pluginAppPolicyContext: createPluginAppPolicyContext({
644
- allowDestructiveActions: true,
645
- apps: [
646
- {
647
- appId: "connector_google_calendar",
648
- pluginName: "google-calendar",
649
- mcpServerNames: [],
650
- },
651
- ],
652
- }),
653
- });
654
-
655
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
656
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
657
- });
658
-
659
- it("declines live connector elicitations with mismatched app and connector ids", async () => {
660
- const result = await handleCodexAppServerElicitationRequest({
661
- requestParams: buildConnectorPluginApprovalElicitation({
662
- _meta: {
663
- codex_approval_kind: "mcp_tool_call",
664
- source: "connector",
665
- app_id: "other-app",
666
- connector_id: "connector_google_calendar",
667
- connector_name: "Google Calendar",
668
- tool_title: "create_event",
669
- },
670
- }),
671
- paramsForRun: createParams(),
672
- threadId: "thread-1",
673
- turnId: "turn-1",
674
- pluginAppPolicyContext: createPluginAppPolicyContext({
675
- allowDestructiveActions: true,
676
- apps: [
677
- {
678
- appId: "connector_google_calendar",
679
- pluginName: "google-calendar",
680
- mcpServerNames: [],
681
- },
682
- ],
683
- }),
684
- });
685
-
686
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
687
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
688
- });
689
-
690
- it("declines plugin app elicitations that are missing active turn correlation", async () => {
691
- const result = await handleCodexAppServerElicitationRequest({
692
- requestParams: buildPluginApprovalElicitation({ turnId: null }),
693
- paramsForRun: createParams(),
694
- threadId: "thread-1",
695
- turnId: "turn-1",
696
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
697
- });
698
-
699
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
700
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
701
- });
702
-
703
- it("does not answer plugin app elicitations for a different active turn", async () => {
704
- const result = await handleCodexAppServerElicitationRequest({
705
- requestParams: buildPluginApprovalElicitation({ turnId: "turn-2" }),
706
- paramsForRun: createParams(),
707
- threadId: "thread-1",
708
- turnId: "turn-1",
709
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
710
- });
711
-
712
- expect(result).toBeUndefined();
713
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
714
- });
715
-
716
- it("declines plugin app elicitations with ambiguous server ownership", async () => {
717
- const result = await handleCodexAppServerElicitationRequest({
718
- requestParams: buildPluginApprovalElicitation({
719
- serverName: "shared-mcp",
720
- _meta: {},
721
- }),
722
- paramsForRun: createParams(),
723
- threadId: "thread-1",
724
- turnId: "turn-1",
725
- pluginAppPolicyContext: createPluginAppPolicyContext({
726
- allowDestructiveActions: true,
727
- apps: [
728
- {
729
- appId: "calendar-app-1",
730
- pluginName: "google-calendar",
731
- mcpServerNames: ["shared-mcp"],
732
- },
733
- {
734
- appId: "calendar-app-2",
735
- pluginName: "google-calendar",
736
- mcpServerNames: ["shared-mcp"],
737
- },
738
- ],
739
- }),
740
- });
741
-
742
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
743
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
744
- });
745
-
746
- it("declines plugin app elicitations that only match display names", async () => {
747
- const result = await handleCodexAppServerElicitationRequest({
748
- requestParams: buildPluginApprovalElicitation({
749
- serverName: "unknown-mcp",
750
- _meta: {
751
- connector_name: "Google Calendar",
752
- },
753
- }),
754
- paramsForRun: createParams(),
755
- threadId: "thread-1",
756
- turnId: "turn-1",
757
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
758
- });
759
-
760
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
761
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
762
- });
763
-
764
- it("declines plugin-scoped elicitations when policy context is missing", async () => {
765
- const result = await handleCodexAppServerElicitationRequest({
766
- requestParams: buildPluginApprovalElicitation(),
767
- paramsForRun: createParams(),
768
- threadId: "thread-1",
769
- turnId: "turn-1",
770
- });
771
-
772
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
773
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
774
- });
775
-
776
- it("declines plugin app elicitations with unmappable schemas", async () => {
777
- const result = await handleCodexAppServerElicitationRequest({
778
- requestParams: buildPluginApprovalElicitation({
779
- requestedSchema: {
780
- type: "object",
781
- properties: {
782
- template: {
783
- type: "string",
784
- enum: ["simple", "detailed"],
785
- },
786
- },
787
- required: ["template"],
788
- },
789
- }),
790
- paramsForRun: createParams(),
791
- threadId: "thread-1",
792
- turnId: "turn-1",
793
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
794
- });
795
-
796
- expect(result).toEqual({ action: "decline", content: null, _meta: null });
797
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
798
- });
799
-
800
- it("keeps unrelated MCP approval elicitations on the existing approval bridge", async () => {
801
- mockCallGatewayTool
802
- .mockResolvedValueOnce({ id: "plugin:approval-unrelated", status: "accepted" })
803
- .mockResolvedValueOnce({ id: "plugin:approval-unrelated", decision: "allow-once" });
804
-
805
- const result = await handleCodexAppServerElicitationRequest({
806
- requestParams: buildCurrentCodexApprovalElicitation(),
807
- paramsForRun: createParams(),
808
- threadId: "thread-1",
809
- turnId: "turn-1",
810
- pluginAppPolicyContext: createPluginAppPolicyContext({ allowDestructiveActions: true }),
811
- });
812
-
813
- expect(result).toEqual({
814
- action: "accept",
815
- content: null,
816
- _meta: null,
817
- });
818
- expect(mockCallGatewayTool.mock.calls.map(([method]) => method)).toEqual([
819
- "plugin.approval.request",
820
- "plugin.approval.waitDecision",
821
- ]);
822
- });
823
-
824
- it("ignores unscoped approval elicitations without the active thread id", async () => {
825
- const { turnId, serverName, mode, message, _meta, requestedSchema } =
826
- buildCurrentCodexApprovalElicitation();
827
- const result = await handleCodexAppServerElicitationRequest({
828
- requestParams: { turnId, serverName, mode, message, _meta, requestedSchema },
829
- paramsForRun: createParams(),
830
- threadId: "thread-1",
831
- turnId: "turn-1",
832
- });
833
-
834
- expect(result).toBeUndefined();
835
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
836
- });
837
-
838
- it("maps allow-always decisions onto persistent approval metadata when offered", async () => {
839
- mockCallGatewayTool
840
- .mockResolvedValueOnce({ id: "plugin:approval-2", status: "accepted" })
841
- .mockResolvedValueOnce({ id: "plugin:approval-2", decision: "allow-always" });
842
-
843
- const result = await handleCodexAppServerElicitationRequest({
844
- requestParams: buildApprovalElicitation(),
845
- paramsForRun: createParams(),
846
- threadId: "thread-1",
847
- turnId: "turn-1",
848
- });
849
-
850
- expect(result).toEqual({
851
- action: "accept",
852
- content: {
853
- approve: true,
854
- persist: "always",
855
- },
856
- _meta: {
857
- persist: "always",
858
- },
859
- });
860
- });
861
-
862
- it("maps allow-always decisions onto metadata for current empty-schema approvals", async () => {
863
- mockCallGatewayTool
864
- .mockResolvedValueOnce({ id: "plugin:approval-current-always", status: "accepted" })
865
- .mockResolvedValueOnce({ id: "plugin:approval-current-always", decision: "allow-always" });
866
-
867
- const result = await handleCodexAppServerElicitationRequest({
868
- requestParams: buildCurrentCodexApprovalElicitation(),
869
- paramsForRun: createParams(),
870
- threadId: "thread-1",
871
- turnId: "turn-1",
872
- });
873
-
874
- expect(result).toEqual({
875
- action: "accept",
876
- content: null,
877
- _meta: {
878
- persist: "always",
879
- },
880
- });
881
- });
882
-
883
- it("does not inherit persist defaults for one-time approvals", async () => {
884
- mockCallGatewayTool
885
- .mockResolvedValueOnce({ id: "plugin:approval-5", status: "accepted" })
886
- .mockResolvedValueOnce({ id: "plugin:approval-5", decision: "allow-once" });
887
-
888
- const result = await handleCodexAppServerElicitationRequest({
889
- requestParams: {
890
- ...buildApprovalElicitation(),
891
- requestedSchema: {
892
- type: "object",
893
- properties: {
894
- approve: {
895
- type: "boolean",
896
- title: "Approve this tool call",
897
- },
898
- persist: {
899
- type: "string",
900
- title: "Persist choice",
901
- enum: ["session", "always"],
902
- default: "always",
903
- },
904
- },
905
- required: ["approve"],
906
- },
907
- },
908
- paramsForRun: createParams(),
909
- threadId: "thread-1",
910
- turnId: "turn-1",
911
- });
912
-
913
- expect(result).toEqual({
914
- action: "accept",
915
- content: {
916
- approve: true,
917
- },
918
- _meta: null,
919
- });
920
- });
921
-
922
- it("truncates long approval titles and descriptions before requesting approval", async () => {
923
- mockCallGatewayTool
924
- .mockResolvedValueOnce({ id: "plugin:approval-4", status: "accepted" })
925
- .mockResolvedValueOnce({ id: "plugin:approval-4", decision: "allow-once" });
926
-
927
- const result = await handleCodexAppServerElicitationRequest({
928
- requestParams: {
929
- ...buildApprovalElicitation(),
930
- message: "Approve ".repeat(20).trim(),
931
- requestedSchema: {
932
- type: "object",
933
- properties: {
934
- approve: {
935
- type: "boolean",
936
- title: "Approve this tool call",
937
- description: "Explain ".repeat(60).trim(),
938
- },
939
- },
940
- required: ["approve"],
941
- },
942
- },
943
- paramsForRun: createParams(),
944
- threadId: "thread-1",
945
- turnId: "turn-1",
946
- });
947
-
948
- expect(result).toEqual({
949
- action: "accept",
950
- content: {
951
- approve: true,
952
- },
953
- _meta: null,
954
- });
955
- const approvalRequestCall = gatewayToolCall();
956
- expect(approvalRequestCall?.[0]).toBe("plugin.approval.request");
957
- expect(approvalRequestCall?.[1]).toStrictEqual({ timeoutMs: 130_000 });
958
- expect(approvalRequestCall?.[3]).toStrictEqual({ expectFinal: false });
959
- const approvalRequest = gatewayToolArg(0, 2) as {
960
- title: string;
961
- description: string;
962
- };
963
- expect(typeof approvalRequest.title).toBe("string");
964
- expect(typeof approvalRequest.description).toBe("string");
965
- expect(approvalRequest.title.length).toBeLessThanOrEqual(80);
966
- expect(approvalRequest.description.length).toBeLessThanOrEqual(256);
967
- });
968
-
969
- it("fails closed when the approval route is unavailable", async () => {
970
- mockCallGatewayTool.mockResolvedValueOnce({ id: "plugin:approval-3", decision: null });
971
-
972
- const result = await handleCodexAppServerElicitationRequest({
973
- requestParams: buildApprovalElicitation(),
974
- paramsForRun: createParams(),
975
- threadId: "thread-1",
976
- turnId: "turn-1",
977
- });
978
-
979
- expect(result).toEqual({
980
- action: "decline",
981
- content: null,
982
- _meta: null,
983
- });
984
- });
985
-
986
- it("ignores non-approval elicitation requests", async () => {
987
- const result = await handleCodexAppServerElicitationRequest({
988
- requestParams: {
989
- threadId: "thread-1",
990
- turnId: "turn-1",
991
- serverName: "codex_apps__github",
992
- mode: "form",
993
- message: "Choose a template",
994
- _meta: {},
995
- requestedSchema: {
996
- type: "object",
997
- properties: {
998
- template: {
999
- type: "string",
1000
- enum: ["simple", "fancy"],
1001
- },
1002
- },
1003
- required: ["template"],
1004
- },
1005
- },
1006
- paramsForRun: createParams(),
1007
- threadId: "thread-1",
1008
- turnId: "turn-1",
1009
- });
1010
-
1011
- expect(result).toBeUndefined();
1012
- expect(mockCallGatewayTool).not.toHaveBeenCalled();
1013
- });
1014
-
1015
- it("logs and declines approved elicitations that do not expose an approval field", async () => {
1016
- const warn = vi.spyOn(embeddedAgentLog, "warn").mockImplementation(() => undefined);
1017
- mockCallGatewayTool
1018
- .mockResolvedValueOnce({ id: "plugin:approval-6", status: "accepted" })
1019
- .mockResolvedValueOnce({ id: "plugin:approval-6", decision: "allow-once" });
1020
-
1021
- const result = await handleCodexAppServerElicitationRequest({
1022
- requestParams: {
1023
- ...buildApprovalElicitation(),
1024
- requestedSchema: {
1025
- type: "object",
1026
- properties: {
1027
- confirmChoice: {
1028
- type: "string",
1029
- title: "Confirmation choice",
1030
- enum: ["yes", "no"],
1031
- },
1032
- },
1033
- required: ["confirmChoice"],
1034
- },
1035
- },
1036
- paramsForRun: createParams(),
1037
- threadId: "thread-1",
1038
- turnId: "turn-1",
1039
- });
1040
-
1041
- expect(result).toEqual({
1042
- action: "decline",
1043
- content: null,
1044
- _meta: null,
1045
- });
1046
- const [warningMessage, warningDetails] = mockCall(warn) ?? [];
1047
- expect(warningMessage).toBe(
1048
- "codex MCP approval elicitation approved without a mappable response",
1049
- );
1050
- expect(warningDetails).toStrictEqual({
1051
- approvalKind: "mcp_tool_call",
1052
- fields: ["confirmChoice"],
1053
- outcome: "approved-once",
1054
- });
1055
- });
1056
- });