@spekn/cli 1.0.0 → 1.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 (154) hide show
  1. package/README.md +58 -0
  2. package/dist/main.js +3707 -611
  3. package/dist/tui/index.mjs +2 -2
  4. package/package.json +29 -12
  5. package/dist/__tests__/export-cli.test.d.ts +0 -1
  6. package/dist/__tests__/export-cli.test.js +0 -70
  7. package/dist/__tests__/tui-args-policy.test.d.ts +0 -1
  8. package/dist/__tests__/tui-args-policy.test.js +0 -50
  9. package/dist/acp-S2MHZOAD.mjs +0 -23
  10. package/dist/acp-UCCI44JY.mjs +0 -25
  11. package/dist/auth/credentials-store.d.ts +0 -2
  12. package/dist/auth/credentials-store.js +0 -5
  13. package/dist/auth/device-flow.d.ts +0 -36
  14. package/dist/auth/device-flow.js +0 -189
  15. package/dist/auth/jwt.d.ts +0 -1
  16. package/dist/auth/jwt.js +0 -6
  17. package/dist/auth/session.d.ts +0 -67
  18. package/dist/auth/session.js +0 -86
  19. package/dist/auth-login.d.ts +0 -34
  20. package/dist/auth-login.js +0 -202
  21. package/dist/auth-logout.d.ts +0 -25
  22. package/dist/auth-logout.js +0 -115
  23. package/dist/auth-status.d.ts +0 -24
  24. package/dist/auth-status.js +0 -109
  25. package/dist/backlog-generate.d.ts +0 -11
  26. package/dist/backlog-generate.js +0 -308
  27. package/dist/backlog-health.d.ts +0 -11
  28. package/dist/backlog-health.js +0 -287
  29. package/dist/bridge-login.d.ts +0 -40
  30. package/dist/bridge-login.js +0 -277
  31. package/dist/chunk-3PAYRI4G.mjs +0 -2428
  32. package/dist/chunk-M4CS3A25.mjs +0 -2426
  33. package/dist/commands/auth/login.d.ts +0 -30
  34. package/dist/commands/auth/login.js +0 -164
  35. package/dist/commands/auth/logout.d.ts +0 -25
  36. package/dist/commands/auth/logout.js +0 -115
  37. package/dist/commands/auth/status.d.ts +0 -24
  38. package/dist/commands/auth/status.js +0 -109
  39. package/dist/commands/backlog/generate.d.ts +0 -11
  40. package/dist/commands/backlog/generate.js +0 -308
  41. package/dist/commands/backlog/health.d.ts +0 -11
  42. package/dist/commands/backlog/health.js +0 -287
  43. package/dist/commands/bridge/login.d.ts +0 -36
  44. package/dist/commands/bridge/login.js +0 -258
  45. package/dist/commands/export.d.ts +0 -35
  46. package/dist/commands/export.js +0 -485
  47. package/dist/commands/marketplace-export.d.ts +0 -21
  48. package/dist/commands/marketplace-export.js +0 -214
  49. package/dist/commands/project-clean.d.ts +0 -1
  50. package/dist/commands/project-clean.js +0 -126
  51. package/dist/commands/repo/common.d.ts +0 -105
  52. package/dist/commands/repo/common.js +0 -775
  53. package/dist/commands/repo/detach.d.ts +0 -2
  54. package/dist/commands/repo/detach.js +0 -120
  55. package/dist/commands/repo/register.d.ts +0 -21
  56. package/dist/commands/repo/register.js +0 -175
  57. package/dist/commands/repo/sync.d.ts +0 -22
  58. package/dist/commands/repo/sync.js +0 -873
  59. package/dist/commands/skills-import-local.d.ts +0 -16
  60. package/dist/commands/skills-import-local.js +0 -352
  61. package/dist/commands/spec/drift-check.d.ts +0 -3
  62. package/dist/commands/spec/drift-check.js +0 -186
  63. package/dist/commands/spec/frontmatter.d.ts +0 -11
  64. package/dist/commands/spec/frontmatter.js +0 -219
  65. package/dist/commands/spec/lint.d.ts +0 -11
  66. package/dist/commands/spec/lint.js +0 -499
  67. package/dist/commands/spec/parse.d.ts +0 -11
  68. package/dist/commands/spec/parse.js +0 -162
  69. package/dist/export.d.ts +0 -35
  70. package/dist/export.js +0 -485
  71. package/dist/main.d.ts +0 -1
  72. package/dist/marketplace-export.d.ts +0 -21
  73. package/dist/marketplace-export.js +0 -214
  74. package/dist/project-clean.d.ts +0 -1
  75. package/dist/project-clean.js +0 -126
  76. package/dist/project-context.d.ts +0 -99
  77. package/dist/project-context.js +0 -376
  78. package/dist/repo-common.d.ts +0 -101
  79. package/dist/repo-common.js +0 -671
  80. package/dist/repo-detach.d.ts +0 -2
  81. package/dist/repo-detach.js +0 -102
  82. package/dist/repo-ingest.d.ts +0 -29
  83. package/dist/repo-ingest.js +0 -305
  84. package/dist/repo-register.d.ts +0 -21
  85. package/dist/repo-register.js +0 -175
  86. package/dist/repo-sync.d.ts +0 -16
  87. package/dist/repo-sync.js +0 -152
  88. package/dist/resources/prompt-loader.d.ts +0 -1
  89. package/dist/resources/prompt-loader.js +0 -62
  90. package/dist/skills-import-local.d.ts +0 -16
  91. package/dist/skills-import-local.js +0 -352
  92. package/dist/spec-drift-check.d.ts +0 -3
  93. package/dist/spec-drift-check.js +0 -186
  94. package/dist/spec-frontmatter.d.ts +0 -11
  95. package/dist/spec-frontmatter.js +0 -219
  96. package/dist/spec-lint.d.ts +0 -11
  97. package/dist/spec-lint.js +0 -499
  98. package/dist/spec-parse.d.ts +0 -11
  99. package/dist/spec-parse.js +0 -162
  100. package/dist/stubs/dotenv.d.ts +0 -5
  101. package/dist/stubs/dotenv.js +0 -6
  102. package/dist/stubs/typeorm.d.ts +0 -22
  103. package/dist/stubs/typeorm.js +0 -28
  104. package/dist/tui/app.d.ts +0 -7
  105. package/dist/tui/app.js +0 -122
  106. package/dist/tui/args.d.ts +0 -8
  107. package/dist/tui/args.js +0 -57
  108. package/dist/tui/capabilities/policy.d.ts +0 -7
  109. package/dist/tui/capabilities/policy.js +0 -64
  110. package/dist/tui/components/frame.d.ts +0 -8
  111. package/dist/tui/components/frame.js +0 -8
  112. package/dist/tui/components/status-bar.d.ts +0 -8
  113. package/dist/tui/components/status-bar.js +0 -8
  114. package/dist/tui/index.d.ts +0 -2
  115. package/dist/tui/index.js +0 -23
  116. package/dist/tui/keymap/use-global-keymap.d.ts +0 -19
  117. package/dist/tui/keymap/use-global-keymap.js +0 -82
  118. package/dist/tui/navigation/nav-items.d.ts +0 -3
  119. package/dist/tui/navigation/nav-items.js +0 -18
  120. package/dist/tui/screens/bridge.d.ts +0 -8
  121. package/dist/tui/screens/bridge.js +0 -19
  122. package/dist/tui/screens/decisions.d.ts +0 -5
  123. package/dist/tui/screens/decisions.js +0 -28
  124. package/dist/tui/screens/export.d.ts +0 -5
  125. package/dist/tui/screens/export.js +0 -16
  126. package/dist/tui/screens/home.d.ts +0 -5
  127. package/dist/tui/screens/home.js +0 -33
  128. package/dist/tui/screens/locked.d.ts +0 -5
  129. package/dist/tui/screens/locked.js +0 -9
  130. package/dist/tui/screens/specs.d.ts +0 -5
  131. package/dist/tui/screens/specs.js +0 -31
  132. package/dist/tui/services/client.d.ts +0 -1
  133. package/dist/tui/services/client.js +0 -18
  134. package/dist/tui/services/context-service.d.ts +0 -19
  135. package/dist/tui/services/context-service.js +0 -246
  136. package/dist/tui/shared-enums.d.ts +0 -16
  137. package/dist/tui/shared-enums.js +0 -19
  138. package/dist/tui/state/use-app-state.d.ts +0 -35
  139. package/dist/tui/state/use-app-state.js +0 -177
  140. package/dist/tui/types.d.ts +0 -77
  141. package/dist/tui/types.js +0 -2
  142. package/dist/tui-bundle.d.ts +0 -1
  143. package/dist/tui-bundle.js +0 -5
  144. package/dist/tui-entry.mjs +0 -1407
  145. package/dist/utils/cli-runtime.d.ts +0 -5
  146. package/dist/utils/cli-runtime.js +0 -22
  147. package/dist/utils/help-error.d.ts +0 -7
  148. package/dist/utils/help-error.js +0 -14
  149. package/dist/utils/interaction.d.ts +0 -19
  150. package/dist/utils/interaction.js +0 -93
  151. package/dist/utils/structured-log.d.ts +0 -7
  152. package/dist/utils/structured-log.js +0 -112
  153. package/dist/utils/trpc-url.d.ts +0 -4
  154. package/dist/utils/trpc-url.js +0 -15
@@ -1,2426 +0,0 @@
1
- // Bundled TUI entry (ESM) — loaded via dynamic import() from CJS main.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __esm = (fn, res) => function __init() {
16
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
- };
18
- var __commonJS = (cb, mod) => function __require2() {
19
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
20
- };
21
- var __export = (target, all) => {
22
- for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
24
- };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") {
27
- for (let key of __getOwnPropNames(from))
28
- if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
- }
31
- return to;
32
- };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
- // If the importer is in node compatibility mode or this is not an ESM
35
- // file that has been converted to a CommonJS file using a Babel-
36
- // compatible transform (i.e. "__esModule" has not been set), then set
37
- // "default" to the CommonJS "module.exports" for node compatibility.
38
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
- mod
40
- ));
41
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
-
43
- // ../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
44
- var AGENT_METHODS, CLIENT_METHODS, PROTOCOL_VERSION;
45
- var init_schema = __esm({
46
- "../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js"() {
47
- "use strict";
48
- AGENT_METHODS = {
49
- authenticate: "authenticate",
50
- initialize: "initialize",
51
- session_cancel: "session/cancel",
52
- session_fork: "session/fork",
53
- session_list: "session/list",
54
- session_load: "session/load",
55
- session_new: "session/new",
56
- session_prompt: "session/prompt",
57
- session_resume: "session/resume",
58
- session_set_config_option: "session/set_config_option",
59
- session_set_mode: "session/set_mode",
60
- session_set_model: "session/set_model"
61
- };
62
- CLIENT_METHODS = {
63
- fs_read_text_file: "fs/read_text_file",
64
- fs_write_text_file: "fs/write_text_file",
65
- session_request_permission: "session/request_permission",
66
- session_update: "session/update",
67
- terminal_create: "terminal/create",
68
- terminal_kill: "terminal/kill",
69
- terminal_output: "terminal/output",
70
- terminal_release: "terminal/release",
71
- terminal_wait_for_exit: "terminal/wait_for_exit"
72
- };
73
- PROTOCOL_VERSION = 1;
74
- }
75
- });
76
-
77
- // ../../node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js
78
- import { z } from "zod/v4";
79
- var zAuthMethod, zAuthenticateRequest, zAuthenticateResponse, zBlobResourceContents, zCost, zCreateTerminalResponse, zDiff, zEnvVariable, zErrorCode, zError, zExtNotification, zExtRequest, zExtResponse, zFileSystemCapability, zClientCapabilities, zHttpHeader, zImplementation, zKillTerminalCommandResponse, zListSessionsRequest, zMcpCapabilities, zMcpServerHttp, zMcpServerSse, zMcpServerStdio, zMcpServer, zModelId, zModelInfo, zNewSessionRequest, zPermissionOptionId, zPermissionOptionKind, zPermissionOption, zPlanEntryPriority, zPlanEntryStatus, zPlanEntry, zPlan, zPromptCapabilities, zProtocolVersion, zInitializeRequest, zReadTextFileResponse, zReleaseTerminalResponse, zRequestId, zCancelRequestNotification, zRole, zAnnotations, zAudioContent, zImageContent, zResourceLink, zSelectedPermissionOutcome, zRequestPermissionOutcome, zRequestPermissionResponse, zSessionConfigGroupId, zSessionConfigId, zSessionConfigOptionCategory, zSessionConfigValueId, zSessionConfigSelectOption, zSessionConfigSelectGroup, zSessionConfigSelectOptions, zSessionConfigSelect, zSessionConfigOption, zConfigOptionUpdate, zSessionForkCapabilities, zSessionId, zCancelNotification, zClientNotification, zCreateTerminalRequest, zForkSessionRequest, zKillTerminalCommandRequest, zLoadSessionRequest, zReadTextFileRequest, zReleaseTerminalRequest, zResumeSessionRequest, zSessionInfo, zListSessionsResponse, zSessionInfoUpdate, zSessionListCapabilities, zSessionModeId, zCurrentModeUpdate, zSessionMode, zSessionModeState, zSessionModelState, zForkSessionResponse, zLoadSessionResponse, zNewSessionResponse, zResumeSessionResponse, zSessionResumeCapabilities, zSessionCapabilities, zAgentCapabilities, zInitializeResponse, zSetSessionConfigOptionRequest, zSetSessionConfigOptionResponse, zSetSessionModeRequest, zSetSessionModeResponse, zSetSessionModelRequest, zSetSessionModelResponse, zStopReason, zTerminal, zTerminalExitStatus, zTerminalOutputRequest, zTerminalOutputResponse, zTextContent, zTextResourceContents, zEmbeddedResourceResource, zEmbeddedResource, zContentBlock, zContent, zContentChunk, zPromptRequest, zClientRequest, zToolCallContent, zToolCallId, zToolCallLocation, zToolCallStatus, zToolKind, zToolCall, zToolCallUpdate, zRequestPermissionRequest, zUnstructuredCommandInput, zAvailableCommandInput, zAvailableCommand, zAvailableCommandsUpdate, zUsage, zPromptResponse, zAgentResponse, zUsageUpdate, zSessionUpdate, zSessionNotification, zAgentNotification, zWaitForTerminalExitRequest, zWaitForTerminalExitResponse, zWriteTextFileRequest, zAgentRequest, zWriteTextFileResponse, zClientResponse;
80
- var init_zod_gen = __esm({
81
- "../../node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js"() {
82
- "use strict";
83
- zAuthMethod = z.object({
84
- _meta: z.union([
85
- z.record(z.string(), z.unknown()),
86
- z.null()
87
- ]).optional(),
88
- description: z.union([
89
- z.string(),
90
- z.null()
91
- ]).optional(),
92
- id: z.string(),
93
- name: z.string()
94
- });
95
- zAuthenticateRequest = z.object({
96
- _meta: z.union([
97
- z.record(z.string(), z.unknown()),
98
- z.null()
99
- ]).optional(),
100
- methodId: z.string()
101
- });
102
- zAuthenticateResponse = z.object({
103
- _meta: z.union([
104
- z.record(z.string(), z.unknown()),
105
- z.null()
106
- ]).optional()
107
- });
108
- zBlobResourceContents = z.object({
109
- _meta: z.union([
110
- z.record(z.string(), z.unknown()),
111
- z.null()
112
- ]).optional(),
113
- blob: z.string(),
114
- mimeType: z.union([
115
- z.string(),
116
- z.null()
117
- ]).optional(),
118
- uri: z.string()
119
- });
120
- zCost = z.object({
121
- amount: z.number(),
122
- currency: z.string()
123
- });
124
- zCreateTerminalResponse = z.object({
125
- _meta: z.union([
126
- z.record(z.string(), z.unknown()),
127
- z.null()
128
- ]).optional(),
129
- terminalId: z.string()
130
- });
131
- zDiff = z.object({
132
- _meta: z.union([
133
- z.record(z.string(), z.unknown()),
134
- z.null()
135
- ]).optional(),
136
- newText: z.string(),
137
- oldText: z.union([
138
- z.string(),
139
- z.null()
140
- ]).optional(),
141
- path: z.string()
142
- });
143
- zEnvVariable = z.object({
144
- _meta: z.union([
145
- z.record(z.string(), z.unknown()),
146
- z.null()
147
- ]).optional(),
148
- name: z.string(),
149
- value: z.string()
150
- });
151
- zErrorCode = z.union([
152
- z.literal(-32700),
153
- z.literal(-32600),
154
- z.literal(-32601),
155
- z.literal(-32602),
156
- z.literal(-32603),
157
- z.literal(-32800),
158
- z.literal(-32e3),
159
- z.literal(-32002),
160
- z.number().int().min(-2147483648, {
161
- message: "Invalid value: Expected int32 to be >= -2147483648"
162
- }).max(2147483647, {
163
- message: "Invalid value: Expected int32 to be <= 2147483647"
164
- })
165
- ]);
166
- zError = z.object({
167
- code: zErrorCode,
168
- data: z.unknown().optional(),
169
- message: z.string()
170
- });
171
- zExtNotification = z.unknown();
172
- zExtRequest = z.unknown();
173
- zExtResponse = z.unknown();
174
- zFileSystemCapability = z.object({
175
- _meta: z.union([
176
- z.record(z.string(), z.unknown()),
177
- z.null()
178
- ]).optional(),
179
- readTextFile: z.boolean().optional().default(false),
180
- writeTextFile: z.boolean().optional().default(false)
181
- });
182
- zClientCapabilities = z.object({
183
- _meta: z.union([
184
- z.record(z.string(), z.unknown()),
185
- z.null()
186
- ]).optional(),
187
- fs: zFileSystemCapability.optional().default({
188
- readTextFile: false,
189
- writeTextFile: false
190
- }),
191
- terminal: z.boolean().optional().default(false)
192
- });
193
- zHttpHeader = z.object({
194
- _meta: z.union([
195
- z.record(z.string(), z.unknown()),
196
- z.null()
197
- ]).optional(),
198
- name: z.string(),
199
- value: z.string()
200
- });
201
- zImplementation = z.object({
202
- _meta: z.union([
203
- z.record(z.string(), z.unknown()),
204
- z.null()
205
- ]).optional(),
206
- name: z.string(),
207
- title: z.union([
208
- z.string(),
209
- z.null()
210
- ]).optional(),
211
- version: z.string()
212
- });
213
- zKillTerminalCommandResponse = z.object({
214
- _meta: z.union([
215
- z.record(z.string(), z.unknown()),
216
- z.null()
217
- ]).optional()
218
- });
219
- zListSessionsRequest = z.object({
220
- _meta: z.union([
221
- z.record(z.string(), z.unknown()),
222
- z.null()
223
- ]).optional(),
224
- cursor: z.union([
225
- z.string(),
226
- z.null()
227
- ]).optional(),
228
- cwd: z.union([
229
- z.string(),
230
- z.null()
231
- ]).optional()
232
- });
233
- zMcpCapabilities = z.object({
234
- _meta: z.union([
235
- z.record(z.string(), z.unknown()),
236
- z.null()
237
- ]).optional(),
238
- http: z.boolean().optional().default(false),
239
- sse: z.boolean().optional().default(false)
240
- });
241
- zMcpServerHttp = z.object({
242
- _meta: z.union([
243
- z.record(z.string(), z.unknown()),
244
- z.null()
245
- ]).optional(),
246
- headers: z.array(zHttpHeader),
247
- name: z.string(),
248
- url: z.string()
249
- });
250
- zMcpServerSse = z.object({
251
- _meta: z.union([
252
- z.record(z.string(), z.unknown()),
253
- z.null()
254
- ]).optional(),
255
- headers: z.array(zHttpHeader),
256
- name: z.string(),
257
- url: z.string()
258
- });
259
- zMcpServerStdio = z.object({
260
- _meta: z.union([
261
- z.record(z.string(), z.unknown()),
262
- z.null()
263
- ]).optional(),
264
- args: z.array(z.string()),
265
- command: z.string(),
266
- env: z.array(zEnvVariable),
267
- name: z.string()
268
- });
269
- zMcpServer = z.union([
270
- zMcpServerHttp.and(z.object({
271
- type: z.literal("http")
272
- })),
273
- zMcpServerSse.and(z.object({
274
- type: z.literal("sse")
275
- })),
276
- zMcpServerStdio
277
- ]);
278
- zModelId = z.string();
279
- zModelInfo = z.object({
280
- _meta: z.union([
281
- z.record(z.string(), z.unknown()),
282
- z.null()
283
- ]).optional(),
284
- description: z.union([
285
- z.string(),
286
- z.null()
287
- ]).optional(),
288
- modelId: zModelId,
289
- name: z.string()
290
- });
291
- zNewSessionRequest = z.object({
292
- _meta: z.union([
293
- z.record(z.string(), z.unknown()),
294
- z.null()
295
- ]).optional(),
296
- cwd: z.string(),
297
- mcpServers: z.array(zMcpServer)
298
- });
299
- zPermissionOptionId = z.string();
300
- zPermissionOptionKind = z.union([
301
- z.literal("allow_once"),
302
- z.literal("allow_always"),
303
- z.literal("reject_once"),
304
- z.literal("reject_always")
305
- ]);
306
- zPermissionOption = z.object({
307
- _meta: z.union([
308
- z.record(z.string(), z.unknown()),
309
- z.null()
310
- ]).optional(),
311
- kind: zPermissionOptionKind,
312
- name: z.string(),
313
- optionId: zPermissionOptionId
314
- });
315
- zPlanEntryPriority = z.union([
316
- z.literal("high"),
317
- z.literal("medium"),
318
- z.literal("low")
319
- ]);
320
- zPlanEntryStatus = z.union([
321
- z.literal("pending"),
322
- z.literal("in_progress"),
323
- z.literal("completed")
324
- ]);
325
- zPlanEntry = z.object({
326
- _meta: z.union([
327
- z.record(z.string(), z.unknown()),
328
- z.null()
329
- ]).optional(),
330
- content: z.string(),
331
- priority: zPlanEntryPriority,
332
- status: zPlanEntryStatus
333
- });
334
- zPlan = z.object({
335
- _meta: z.union([
336
- z.record(z.string(), z.unknown()),
337
- z.null()
338
- ]).optional(),
339
- entries: z.array(zPlanEntry)
340
- });
341
- zPromptCapabilities = z.object({
342
- _meta: z.union([
343
- z.record(z.string(), z.unknown()),
344
- z.null()
345
- ]).optional(),
346
- audio: z.boolean().optional().default(false),
347
- embeddedContext: z.boolean().optional().default(false),
348
- image: z.boolean().optional().default(false)
349
- });
350
- zProtocolVersion = z.number().int().gte(0).lte(65535);
351
- zInitializeRequest = z.object({
352
- _meta: z.union([
353
- z.record(z.string(), z.unknown()),
354
- z.null()
355
- ]).optional(),
356
- clientCapabilities: zClientCapabilities.optional().default({
357
- fs: {
358
- readTextFile: false,
359
- writeTextFile: false
360
- },
361
- terminal: false
362
- }),
363
- clientInfo: z.union([
364
- zImplementation,
365
- z.null()
366
- ]).optional(),
367
- protocolVersion: zProtocolVersion
368
- });
369
- zReadTextFileResponse = z.object({
370
- _meta: z.union([
371
- z.record(z.string(), z.unknown()),
372
- z.null()
373
- ]).optional(),
374
- content: z.string()
375
- });
376
- zReleaseTerminalResponse = z.object({
377
- _meta: z.union([
378
- z.record(z.string(), z.unknown()),
379
- z.null()
380
- ]).optional()
381
- });
382
- zRequestId = z.union([
383
- z.null(),
384
- z.number(),
385
- z.string()
386
- ]);
387
- zCancelRequestNotification = z.object({
388
- _meta: z.union([
389
- z.record(z.string(), z.unknown()),
390
- z.null()
391
- ]).optional(),
392
- requestId: zRequestId
393
- });
394
- zRole = z.enum([
395
- "assistant",
396
- "user"
397
- ]);
398
- zAnnotations = z.object({
399
- _meta: z.union([
400
- z.record(z.string(), z.unknown()),
401
- z.null()
402
- ]).optional(),
403
- audience: z.union([
404
- z.array(zRole),
405
- z.null()
406
- ]).optional(),
407
- lastModified: z.union([
408
- z.string(),
409
- z.null()
410
- ]).optional(),
411
- priority: z.union([
412
- z.number(),
413
- z.null()
414
- ]).optional()
415
- });
416
- zAudioContent = z.object({
417
- _meta: z.union([
418
- z.record(z.string(), z.unknown()),
419
- z.null()
420
- ]).optional(),
421
- annotations: z.union([
422
- zAnnotations,
423
- z.null()
424
- ]).optional(),
425
- data: z.string(),
426
- mimeType: z.string()
427
- });
428
- zImageContent = z.object({
429
- _meta: z.union([
430
- z.record(z.string(), z.unknown()),
431
- z.null()
432
- ]).optional(),
433
- annotations: z.union([
434
- zAnnotations,
435
- z.null()
436
- ]).optional(),
437
- data: z.string(),
438
- mimeType: z.string(),
439
- uri: z.union([
440
- z.string(),
441
- z.null()
442
- ]).optional()
443
- });
444
- zResourceLink = z.object({
445
- _meta: z.union([
446
- z.record(z.string(), z.unknown()),
447
- z.null()
448
- ]).optional(),
449
- annotations: z.union([
450
- zAnnotations,
451
- z.null()
452
- ]).optional(),
453
- description: z.union([
454
- z.string(),
455
- z.null()
456
- ]).optional(),
457
- mimeType: z.union([
458
- z.string(),
459
- z.null()
460
- ]).optional(),
461
- name: z.string(),
462
- size: z.union([
463
- z.number(),
464
- z.null()
465
- ]).optional(),
466
- title: z.union([
467
- z.string(),
468
- z.null()
469
- ]).optional(),
470
- uri: z.string()
471
- });
472
- zSelectedPermissionOutcome = z.object({
473
- _meta: z.union([
474
- z.record(z.string(), z.unknown()),
475
- z.null()
476
- ]).optional(),
477
- optionId: zPermissionOptionId
478
- });
479
- zRequestPermissionOutcome = z.union([
480
- z.object({
481
- outcome: z.literal("cancelled")
482
- }),
483
- zSelectedPermissionOutcome.and(z.object({
484
- outcome: z.literal("selected")
485
- }))
486
- ]);
487
- zRequestPermissionResponse = z.object({
488
- _meta: z.union([
489
- z.record(z.string(), z.unknown()),
490
- z.null()
491
- ]).optional(),
492
- outcome: zRequestPermissionOutcome
493
- });
494
- zSessionConfigGroupId = z.string();
495
- zSessionConfigId = z.string();
496
- zSessionConfigOptionCategory = z.union([
497
- z.literal("mode"),
498
- z.literal("model"),
499
- z.literal("thought_level"),
500
- z.string()
501
- ]);
502
- zSessionConfigValueId = z.string();
503
- zSessionConfigSelectOption = z.object({
504
- _meta: z.union([
505
- z.record(z.string(), z.unknown()),
506
- z.null()
507
- ]).optional(),
508
- description: z.union([
509
- z.string(),
510
- z.null()
511
- ]).optional(),
512
- name: z.string(),
513
- value: zSessionConfigValueId
514
- });
515
- zSessionConfigSelectGroup = z.object({
516
- _meta: z.union([
517
- z.record(z.string(), z.unknown()),
518
- z.null()
519
- ]).optional(),
520
- group: zSessionConfigGroupId,
521
- name: z.string(),
522
- options: z.array(zSessionConfigSelectOption)
523
- });
524
- zSessionConfigSelectOptions = z.union([
525
- z.array(zSessionConfigSelectOption),
526
- z.array(zSessionConfigSelectGroup)
527
- ]);
528
- zSessionConfigSelect = z.object({
529
- currentValue: zSessionConfigValueId,
530
- options: zSessionConfigSelectOptions
531
- });
532
- zSessionConfigOption = zSessionConfigSelect.and(z.object({
533
- type: z.literal("select")
534
- })).and(z.object({
535
- _meta: z.union([
536
- z.record(z.string(), z.unknown()),
537
- z.null()
538
- ]).optional(),
539
- category: z.union([
540
- zSessionConfigOptionCategory,
541
- z.null()
542
- ]).optional(),
543
- description: z.union([
544
- z.string(),
545
- z.null()
546
- ]).optional(),
547
- id: zSessionConfigId,
548
- name: z.string()
549
- }));
550
- zConfigOptionUpdate = z.object({
551
- _meta: z.union([
552
- z.record(z.string(), z.unknown()),
553
- z.null()
554
- ]).optional(),
555
- configOptions: z.array(zSessionConfigOption)
556
- });
557
- zSessionForkCapabilities = z.object({
558
- _meta: z.union([
559
- z.record(z.string(), z.unknown()),
560
- z.null()
561
- ]).optional()
562
- });
563
- zSessionId = z.string();
564
- zCancelNotification = z.object({
565
- _meta: z.union([
566
- z.record(z.string(), z.unknown()),
567
- z.null()
568
- ]).optional(),
569
- sessionId: zSessionId
570
- });
571
- zClientNotification = z.object({
572
- method: z.string(),
573
- params: z.union([
574
- z.union([
575
- zCancelNotification,
576
- zExtNotification
577
- ]),
578
- z.null()
579
- ]).optional()
580
- });
581
- zCreateTerminalRequest = z.object({
582
- _meta: z.union([
583
- z.record(z.string(), z.unknown()),
584
- z.null()
585
- ]).optional(),
586
- args: z.array(z.string()).optional(),
587
- command: z.string(),
588
- cwd: z.union([
589
- z.string(),
590
- z.null()
591
- ]).optional(),
592
- env: z.array(zEnvVariable).optional(),
593
- outputByteLimit: z.union([
594
- z.number(),
595
- z.null()
596
- ]).optional(),
597
- sessionId: zSessionId
598
- });
599
- zForkSessionRequest = z.object({
600
- _meta: z.union([
601
- z.record(z.string(), z.unknown()),
602
- z.null()
603
- ]).optional(),
604
- cwd: z.string(),
605
- mcpServers: z.array(zMcpServer).optional(),
606
- sessionId: zSessionId
607
- });
608
- zKillTerminalCommandRequest = z.object({
609
- _meta: z.union([
610
- z.record(z.string(), z.unknown()),
611
- z.null()
612
- ]).optional(),
613
- sessionId: zSessionId,
614
- terminalId: z.string()
615
- });
616
- zLoadSessionRequest = z.object({
617
- _meta: z.union([
618
- z.record(z.string(), z.unknown()),
619
- z.null()
620
- ]).optional(),
621
- cwd: z.string(),
622
- mcpServers: z.array(zMcpServer),
623
- sessionId: zSessionId
624
- });
625
- zReadTextFileRequest = z.object({
626
- _meta: z.union([
627
- z.record(z.string(), z.unknown()),
628
- z.null()
629
- ]).optional(),
630
- limit: z.union([
631
- z.number().int().gte(0).max(4294967295, {
632
- message: "Invalid value: Expected uint32 to be <= 4294967295"
633
- }),
634
- z.null()
635
- ]).optional(),
636
- line: z.union([
637
- z.number().int().gte(0).max(4294967295, {
638
- message: "Invalid value: Expected uint32 to be <= 4294967295"
639
- }),
640
- z.null()
641
- ]).optional(),
642
- path: z.string(),
643
- sessionId: zSessionId
644
- });
645
- zReleaseTerminalRequest = z.object({
646
- _meta: z.union([
647
- z.record(z.string(), z.unknown()),
648
- z.null()
649
- ]).optional(),
650
- sessionId: zSessionId,
651
- terminalId: z.string()
652
- });
653
- zResumeSessionRequest = z.object({
654
- _meta: z.union([
655
- z.record(z.string(), z.unknown()),
656
- z.null()
657
- ]).optional(),
658
- cwd: z.string(),
659
- mcpServers: z.array(zMcpServer).optional(),
660
- sessionId: zSessionId
661
- });
662
- zSessionInfo = z.object({
663
- _meta: z.union([
664
- z.record(z.string(), z.unknown()),
665
- z.null()
666
- ]).optional(),
667
- cwd: z.string(),
668
- sessionId: zSessionId,
669
- title: z.union([
670
- z.string(),
671
- z.null()
672
- ]).optional(),
673
- updatedAt: z.union([
674
- z.string(),
675
- z.null()
676
- ]).optional()
677
- });
678
- zListSessionsResponse = z.object({
679
- _meta: z.union([
680
- z.record(z.string(), z.unknown()),
681
- z.null()
682
- ]).optional(),
683
- nextCursor: z.union([
684
- z.string(),
685
- z.null()
686
- ]).optional(),
687
- sessions: z.array(zSessionInfo)
688
- });
689
- zSessionInfoUpdate = z.object({
690
- _meta: z.union([
691
- z.record(z.string(), z.unknown()),
692
- z.null()
693
- ]).optional(),
694
- title: z.union([
695
- z.string(),
696
- z.null()
697
- ]).optional(),
698
- updatedAt: z.union([
699
- z.string(),
700
- z.null()
701
- ]).optional()
702
- });
703
- zSessionListCapabilities = z.object({
704
- _meta: z.union([
705
- z.record(z.string(), z.unknown()),
706
- z.null()
707
- ]).optional()
708
- });
709
- zSessionModeId = z.string();
710
- zCurrentModeUpdate = z.object({
711
- _meta: z.union([
712
- z.record(z.string(), z.unknown()),
713
- z.null()
714
- ]).optional(),
715
- currentModeId: zSessionModeId
716
- });
717
- zSessionMode = z.object({
718
- _meta: z.union([
719
- z.record(z.string(), z.unknown()),
720
- z.null()
721
- ]).optional(),
722
- description: z.union([
723
- z.string(),
724
- z.null()
725
- ]).optional(),
726
- id: zSessionModeId,
727
- name: z.string()
728
- });
729
- zSessionModeState = z.object({
730
- _meta: z.union([
731
- z.record(z.string(), z.unknown()),
732
- z.null()
733
- ]).optional(),
734
- availableModes: z.array(zSessionMode),
735
- currentModeId: zSessionModeId
736
- });
737
- zSessionModelState = z.object({
738
- _meta: z.union([
739
- z.record(z.string(), z.unknown()),
740
- z.null()
741
- ]).optional(),
742
- availableModels: z.array(zModelInfo),
743
- currentModelId: zModelId
744
- });
745
- zForkSessionResponse = z.object({
746
- _meta: z.union([
747
- z.record(z.string(), z.unknown()),
748
- z.null()
749
- ]).optional(),
750
- configOptions: z.union([
751
- z.array(zSessionConfigOption),
752
- z.null()
753
- ]).optional(),
754
- models: z.union([
755
- zSessionModelState,
756
- z.null()
757
- ]).optional(),
758
- modes: z.union([
759
- zSessionModeState,
760
- z.null()
761
- ]).optional(),
762
- sessionId: zSessionId
763
- });
764
- zLoadSessionResponse = z.object({
765
- _meta: z.union([
766
- z.record(z.string(), z.unknown()),
767
- z.null()
768
- ]).optional(),
769
- configOptions: z.union([
770
- z.array(zSessionConfigOption),
771
- z.null()
772
- ]).optional(),
773
- models: z.union([
774
- zSessionModelState,
775
- z.null()
776
- ]).optional(),
777
- modes: z.union([
778
- zSessionModeState,
779
- z.null()
780
- ]).optional()
781
- });
782
- zNewSessionResponse = z.object({
783
- _meta: z.union([
784
- z.record(z.string(), z.unknown()),
785
- z.null()
786
- ]).optional(),
787
- configOptions: z.union([
788
- z.array(zSessionConfigOption),
789
- z.null()
790
- ]).optional(),
791
- models: z.union([
792
- zSessionModelState,
793
- z.null()
794
- ]).optional(),
795
- modes: z.union([
796
- zSessionModeState,
797
- z.null()
798
- ]).optional(),
799
- sessionId: zSessionId
800
- });
801
- zResumeSessionResponse = z.object({
802
- _meta: z.union([
803
- z.record(z.string(), z.unknown()),
804
- z.null()
805
- ]).optional(),
806
- configOptions: z.union([
807
- z.array(zSessionConfigOption),
808
- z.null()
809
- ]).optional(),
810
- models: z.union([
811
- zSessionModelState,
812
- z.null()
813
- ]).optional(),
814
- modes: z.union([
815
- zSessionModeState,
816
- z.null()
817
- ]).optional()
818
- });
819
- zSessionResumeCapabilities = z.object({
820
- _meta: z.union([
821
- z.record(z.string(), z.unknown()),
822
- z.null()
823
- ]).optional()
824
- });
825
- zSessionCapabilities = z.object({
826
- _meta: z.union([
827
- z.record(z.string(), z.unknown()),
828
- z.null()
829
- ]).optional(),
830
- fork: z.union([
831
- zSessionForkCapabilities,
832
- z.null()
833
- ]).optional(),
834
- list: z.union([
835
- zSessionListCapabilities,
836
- z.null()
837
- ]).optional(),
838
- resume: z.union([
839
- zSessionResumeCapabilities,
840
- z.null()
841
- ]).optional()
842
- });
843
- zAgentCapabilities = z.object({
844
- _meta: z.union([
845
- z.record(z.string(), z.unknown()),
846
- z.null()
847
- ]).optional(),
848
- loadSession: z.boolean().optional().default(false),
849
- mcpCapabilities: zMcpCapabilities.optional().default({
850
- http: false,
851
- sse: false
852
- }),
853
- promptCapabilities: zPromptCapabilities.optional().default({
854
- audio: false,
855
- embeddedContext: false,
856
- image: false
857
- }),
858
- sessionCapabilities: zSessionCapabilities.optional().default({})
859
- });
860
- zInitializeResponse = z.object({
861
- _meta: z.union([
862
- z.record(z.string(), z.unknown()),
863
- z.null()
864
- ]).optional(),
865
- agentCapabilities: zAgentCapabilities.optional().default({
866
- loadSession: false,
867
- mcpCapabilities: {
868
- http: false,
869
- sse: false
870
- },
871
- promptCapabilities: {
872
- audio: false,
873
- embeddedContext: false,
874
- image: false
875
- },
876
- sessionCapabilities: {}
877
- }),
878
- agentInfo: z.union([
879
- zImplementation,
880
- z.null()
881
- ]).optional(),
882
- authMethods: z.array(zAuthMethod).optional().default([]),
883
- protocolVersion: zProtocolVersion
884
- });
885
- zSetSessionConfigOptionRequest = z.object({
886
- _meta: z.union([
887
- z.record(z.string(), z.unknown()),
888
- z.null()
889
- ]).optional(),
890
- configId: zSessionConfigId,
891
- sessionId: zSessionId,
892
- value: zSessionConfigValueId
893
- });
894
- zSetSessionConfigOptionResponse = z.object({
895
- _meta: z.union([
896
- z.record(z.string(), z.unknown()),
897
- z.null()
898
- ]).optional(),
899
- configOptions: z.array(zSessionConfigOption)
900
- });
901
- zSetSessionModeRequest = z.object({
902
- _meta: z.union([
903
- z.record(z.string(), z.unknown()),
904
- z.null()
905
- ]).optional(),
906
- modeId: zSessionModeId,
907
- sessionId: zSessionId
908
- });
909
- zSetSessionModeResponse = z.object({
910
- _meta: z.union([
911
- z.record(z.string(), z.unknown()),
912
- z.null()
913
- ]).optional()
914
- });
915
- zSetSessionModelRequest = z.object({
916
- _meta: z.union([
917
- z.record(z.string(), z.unknown()),
918
- z.null()
919
- ]).optional(),
920
- modelId: zModelId,
921
- sessionId: zSessionId
922
- });
923
- zSetSessionModelResponse = z.object({
924
- _meta: z.union([
925
- z.record(z.string(), z.unknown()),
926
- z.null()
927
- ]).optional()
928
- });
929
- zStopReason = z.union([
930
- z.literal("end_turn"),
931
- z.literal("max_tokens"),
932
- z.literal("max_turn_requests"),
933
- z.literal("refusal"),
934
- z.literal("cancelled")
935
- ]);
936
- zTerminal = z.object({
937
- _meta: z.union([
938
- z.record(z.string(), z.unknown()),
939
- z.null()
940
- ]).optional(),
941
- terminalId: z.string()
942
- });
943
- zTerminalExitStatus = z.object({
944
- _meta: z.union([
945
- z.record(z.string(), z.unknown()),
946
- z.null()
947
- ]).optional(),
948
- exitCode: z.union([
949
- z.number().int().gte(0).max(4294967295, {
950
- message: "Invalid value: Expected uint32 to be <= 4294967295"
951
- }),
952
- z.null()
953
- ]).optional(),
954
- signal: z.union([
955
- z.string(),
956
- z.null()
957
- ]).optional()
958
- });
959
- zTerminalOutputRequest = z.object({
960
- _meta: z.union([
961
- z.record(z.string(), z.unknown()),
962
- z.null()
963
- ]).optional(),
964
- sessionId: zSessionId,
965
- terminalId: z.string()
966
- });
967
- zTerminalOutputResponse = z.object({
968
- _meta: z.union([
969
- z.record(z.string(), z.unknown()),
970
- z.null()
971
- ]).optional(),
972
- exitStatus: z.union([
973
- zTerminalExitStatus,
974
- z.null()
975
- ]).optional(),
976
- output: z.string(),
977
- truncated: z.boolean()
978
- });
979
- zTextContent = z.object({
980
- _meta: z.union([
981
- z.record(z.string(), z.unknown()),
982
- z.null()
983
- ]).optional(),
984
- annotations: z.union([
985
- zAnnotations,
986
- z.null()
987
- ]).optional(),
988
- text: z.string()
989
- });
990
- zTextResourceContents = z.object({
991
- _meta: z.union([
992
- z.record(z.string(), z.unknown()),
993
- z.null()
994
- ]).optional(),
995
- mimeType: z.union([
996
- z.string(),
997
- z.null()
998
- ]).optional(),
999
- text: z.string(),
1000
- uri: z.string()
1001
- });
1002
- zEmbeddedResourceResource = z.union([
1003
- zTextResourceContents,
1004
- zBlobResourceContents
1005
- ]);
1006
- zEmbeddedResource = z.object({
1007
- _meta: z.union([
1008
- z.record(z.string(), z.unknown()),
1009
- z.null()
1010
- ]).optional(),
1011
- annotations: z.union([
1012
- zAnnotations,
1013
- z.null()
1014
- ]).optional(),
1015
- resource: zEmbeddedResourceResource
1016
- });
1017
- zContentBlock = z.union([
1018
- zTextContent.and(z.object({
1019
- type: z.literal("text")
1020
- })),
1021
- zImageContent.and(z.object({
1022
- type: z.literal("image")
1023
- })),
1024
- zAudioContent.and(z.object({
1025
- type: z.literal("audio")
1026
- })),
1027
- zResourceLink.and(z.object({
1028
- type: z.literal("resource_link")
1029
- })),
1030
- zEmbeddedResource.and(z.object({
1031
- type: z.literal("resource")
1032
- }))
1033
- ]);
1034
- zContent = z.object({
1035
- _meta: z.union([
1036
- z.record(z.string(), z.unknown()),
1037
- z.null()
1038
- ]).optional(),
1039
- content: zContentBlock
1040
- });
1041
- zContentChunk = z.object({
1042
- _meta: z.union([
1043
- z.record(z.string(), z.unknown()),
1044
- z.null()
1045
- ]).optional(),
1046
- content: zContentBlock
1047
- });
1048
- zPromptRequest = z.object({
1049
- _meta: z.union([
1050
- z.record(z.string(), z.unknown()),
1051
- z.null()
1052
- ]).optional(),
1053
- prompt: z.array(zContentBlock),
1054
- sessionId: zSessionId
1055
- });
1056
- zClientRequest = z.object({
1057
- id: zRequestId,
1058
- method: z.string(),
1059
- params: z.union([
1060
- z.union([
1061
- zInitializeRequest,
1062
- zAuthenticateRequest,
1063
- zNewSessionRequest,
1064
- zLoadSessionRequest,
1065
- zListSessionsRequest,
1066
- zForkSessionRequest,
1067
- zResumeSessionRequest,
1068
- zSetSessionModeRequest,
1069
- zSetSessionConfigOptionRequest,
1070
- zPromptRequest,
1071
- zSetSessionModelRequest,
1072
- zExtRequest
1073
- ]),
1074
- z.null()
1075
- ]).optional()
1076
- });
1077
- zToolCallContent = z.union([
1078
- zContent.and(z.object({
1079
- type: z.literal("content")
1080
- })),
1081
- zDiff.and(z.object({
1082
- type: z.literal("diff")
1083
- })),
1084
- zTerminal.and(z.object({
1085
- type: z.literal("terminal")
1086
- }))
1087
- ]);
1088
- zToolCallId = z.string();
1089
- zToolCallLocation = z.object({
1090
- _meta: z.union([
1091
- z.record(z.string(), z.unknown()),
1092
- z.null()
1093
- ]).optional(),
1094
- line: z.union([
1095
- z.number().int().gte(0).max(4294967295, {
1096
- message: "Invalid value: Expected uint32 to be <= 4294967295"
1097
- }),
1098
- z.null()
1099
- ]).optional(),
1100
- path: z.string()
1101
- });
1102
- zToolCallStatus = z.union([
1103
- z.literal("pending"),
1104
- z.literal("in_progress"),
1105
- z.literal("completed"),
1106
- z.literal("failed")
1107
- ]);
1108
- zToolKind = z.union([
1109
- z.literal("read"),
1110
- z.literal("edit"),
1111
- z.literal("delete"),
1112
- z.literal("move"),
1113
- z.literal("search"),
1114
- z.literal("execute"),
1115
- z.literal("think"),
1116
- z.literal("fetch"),
1117
- z.literal("switch_mode"),
1118
- z.literal("other")
1119
- ]);
1120
- zToolCall = z.object({
1121
- _meta: z.union([
1122
- z.record(z.string(), z.unknown()),
1123
- z.null()
1124
- ]).optional(),
1125
- content: z.array(zToolCallContent).optional(),
1126
- kind: zToolKind.optional(),
1127
- locations: z.array(zToolCallLocation).optional(),
1128
- rawInput: z.unknown().optional(),
1129
- rawOutput: z.unknown().optional(),
1130
- status: zToolCallStatus.optional(),
1131
- title: z.string(),
1132
- toolCallId: zToolCallId
1133
- });
1134
- zToolCallUpdate = z.object({
1135
- _meta: z.union([
1136
- z.record(z.string(), z.unknown()),
1137
- z.null()
1138
- ]).optional(),
1139
- content: z.union([
1140
- z.array(zToolCallContent),
1141
- z.null()
1142
- ]).optional(),
1143
- kind: z.union([
1144
- zToolKind,
1145
- z.null()
1146
- ]).optional(),
1147
- locations: z.union([
1148
- z.array(zToolCallLocation),
1149
- z.null()
1150
- ]).optional(),
1151
- rawInput: z.unknown().optional(),
1152
- rawOutput: z.unknown().optional(),
1153
- status: z.union([
1154
- zToolCallStatus,
1155
- z.null()
1156
- ]).optional(),
1157
- title: z.union([
1158
- z.string(),
1159
- z.null()
1160
- ]).optional(),
1161
- toolCallId: zToolCallId
1162
- });
1163
- zRequestPermissionRequest = z.object({
1164
- _meta: z.union([
1165
- z.record(z.string(), z.unknown()),
1166
- z.null()
1167
- ]).optional(),
1168
- options: z.array(zPermissionOption),
1169
- sessionId: zSessionId,
1170
- toolCall: zToolCallUpdate
1171
- });
1172
- zUnstructuredCommandInput = z.object({
1173
- _meta: z.union([
1174
- z.record(z.string(), z.unknown()),
1175
- z.null()
1176
- ]).optional(),
1177
- hint: z.string()
1178
- });
1179
- zAvailableCommandInput = zUnstructuredCommandInput;
1180
- zAvailableCommand = z.object({
1181
- _meta: z.union([
1182
- z.record(z.string(), z.unknown()),
1183
- z.null()
1184
- ]).optional(),
1185
- description: z.string(),
1186
- input: z.union([
1187
- zAvailableCommandInput,
1188
- z.null()
1189
- ]).optional(),
1190
- name: z.string()
1191
- });
1192
- zAvailableCommandsUpdate = z.object({
1193
- _meta: z.union([
1194
- z.record(z.string(), z.unknown()),
1195
- z.null()
1196
- ]).optional(),
1197
- availableCommands: z.array(zAvailableCommand)
1198
- });
1199
- zUsage = z.object({
1200
- cachedReadTokens: z.union([
1201
- z.number(),
1202
- z.null()
1203
- ]).optional(),
1204
- cachedWriteTokens: z.union([
1205
- z.number(),
1206
- z.null()
1207
- ]).optional(),
1208
- inputTokens: z.number(),
1209
- outputTokens: z.number(),
1210
- thoughtTokens: z.union([
1211
- z.number(),
1212
- z.null()
1213
- ]).optional(),
1214
- totalTokens: z.number()
1215
- });
1216
- zPromptResponse = z.object({
1217
- _meta: z.union([
1218
- z.record(z.string(), z.unknown()),
1219
- z.null()
1220
- ]).optional(),
1221
- stopReason: zStopReason,
1222
- usage: z.union([
1223
- zUsage,
1224
- z.null()
1225
- ]).optional()
1226
- });
1227
- zAgentResponse = z.union([
1228
- z.object({
1229
- id: zRequestId,
1230
- result: z.union([
1231
- zInitializeResponse,
1232
- zAuthenticateResponse,
1233
- zNewSessionResponse,
1234
- zLoadSessionResponse,
1235
- zListSessionsResponse,
1236
- zForkSessionResponse,
1237
- zResumeSessionResponse,
1238
- zSetSessionModeResponse,
1239
- zSetSessionConfigOptionResponse,
1240
- zPromptResponse,
1241
- zSetSessionModelResponse,
1242
- zExtResponse
1243
- ])
1244
- }),
1245
- z.object({
1246
- error: zError,
1247
- id: zRequestId
1248
- })
1249
- ]);
1250
- zUsageUpdate = z.object({
1251
- _meta: z.union([
1252
- z.record(z.string(), z.unknown()),
1253
- z.null()
1254
- ]).optional(),
1255
- cost: z.union([
1256
- zCost,
1257
- z.null()
1258
- ]).optional(),
1259
- size: z.number(),
1260
- used: z.number()
1261
- });
1262
- zSessionUpdate = z.union([
1263
- zContentChunk.and(z.object({
1264
- sessionUpdate: z.literal("user_message_chunk")
1265
- })),
1266
- zContentChunk.and(z.object({
1267
- sessionUpdate: z.literal("agent_message_chunk")
1268
- })),
1269
- zContentChunk.and(z.object({
1270
- sessionUpdate: z.literal("agent_thought_chunk")
1271
- })),
1272
- zToolCall.and(z.object({
1273
- sessionUpdate: z.literal("tool_call")
1274
- })),
1275
- zToolCallUpdate.and(z.object({
1276
- sessionUpdate: z.literal("tool_call_update")
1277
- })),
1278
- zPlan.and(z.object({
1279
- sessionUpdate: z.literal("plan")
1280
- })),
1281
- zAvailableCommandsUpdate.and(z.object({
1282
- sessionUpdate: z.literal("available_commands_update")
1283
- })),
1284
- zCurrentModeUpdate.and(z.object({
1285
- sessionUpdate: z.literal("current_mode_update")
1286
- })),
1287
- zConfigOptionUpdate.and(z.object({
1288
- sessionUpdate: z.literal("config_option_update")
1289
- })),
1290
- zSessionInfoUpdate.and(z.object({
1291
- sessionUpdate: z.literal("session_info_update")
1292
- })),
1293
- zUsageUpdate.and(z.object({
1294
- sessionUpdate: z.literal("usage_update")
1295
- }))
1296
- ]);
1297
- zSessionNotification = z.object({
1298
- _meta: z.union([
1299
- z.record(z.string(), z.unknown()),
1300
- z.null()
1301
- ]).optional(),
1302
- sessionId: zSessionId,
1303
- update: zSessionUpdate
1304
- });
1305
- zAgentNotification = z.object({
1306
- method: z.string(),
1307
- params: z.union([
1308
- z.union([
1309
- zSessionNotification,
1310
- zExtNotification
1311
- ]),
1312
- z.null()
1313
- ]).optional()
1314
- });
1315
- zWaitForTerminalExitRequest = z.object({
1316
- _meta: z.union([
1317
- z.record(z.string(), z.unknown()),
1318
- z.null()
1319
- ]).optional(),
1320
- sessionId: zSessionId,
1321
- terminalId: z.string()
1322
- });
1323
- zWaitForTerminalExitResponse = z.object({
1324
- _meta: z.union([
1325
- z.record(z.string(), z.unknown()),
1326
- z.null()
1327
- ]).optional(),
1328
- exitCode: z.union([
1329
- z.number().int().gte(0).max(4294967295, {
1330
- message: "Invalid value: Expected uint32 to be <= 4294967295"
1331
- }),
1332
- z.null()
1333
- ]).optional(),
1334
- signal: z.union([
1335
- z.string(),
1336
- z.null()
1337
- ]).optional()
1338
- });
1339
- zWriteTextFileRequest = z.object({
1340
- _meta: z.union([
1341
- z.record(z.string(), z.unknown()),
1342
- z.null()
1343
- ]).optional(),
1344
- content: z.string(),
1345
- path: z.string(),
1346
- sessionId: zSessionId
1347
- });
1348
- zAgentRequest = z.object({
1349
- id: zRequestId,
1350
- method: z.string(),
1351
- params: z.union([
1352
- z.union([
1353
- zWriteTextFileRequest,
1354
- zReadTextFileRequest,
1355
- zRequestPermissionRequest,
1356
- zCreateTerminalRequest,
1357
- zTerminalOutputRequest,
1358
- zReleaseTerminalRequest,
1359
- zWaitForTerminalExitRequest,
1360
- zKillTerminalCommandRequest,
1361
- zExtRequest
1362
- ]),
1363
- z.null()
1364
- ]).optional()
1365
- });
1366
- zWriteTextFileResponse = z.object({
1367
- _meta: z.union([
1368
- z.record(z.string(), z.unknown()),
1369
- z.null()
1370
- ]).optional()
1371
- });
1372
- zClientResponse = z.union([
1373
- z.object({
1374
- id: zRequestId,
1375
- result: z.union([
1376
- zWriteTextFileResponse,
1377
- zReadTextFileResponse,
1378
- zRequestPermissionResponse,
1379
- zCreateTerminalResponse,
1380
- zTerminalOutputResponse,
1381
- zReleaseTerminalResponse,
1382
- zWaitForTerminalExitResponse,
1383
- zKillTerminalCommandResponse,
1384
- zExtResponse
1385
- ])
1386
- }),
1387
- z.object({
1388
- error: zError,
1389
- id: zRequestId
1390
- })
1391
- ]);
1392
- }
1393
- });
1394
-
1395
- // ../../node_modules/@agentclientprotocol/sdk/dist/stream.js
1396
- function ndJsonStream(output, input) {
1397
- const textEncoder = new TextEncoder();
1398
- const textDecoder = new TextDecoder();
1399
- const readable = new ReadableStream({
1400
- async start(controller) {
1401
- let content = "";
1402
- const reader = input.getReader();
1403
- try {
1404
- while (true) {
1405
- const { value, done } = await reader.read();
1406
- if (done) {
1407
- break;
1408
- }
1409
- if (!value) {
1410
- continue;
1411
- }
1412
- content += textDecoder.decode(value, {
1413
- stream: true
1414
- });
1415
- const lines = content.split("\n");
1416
- content = lines.pop() || "";
1417
- for (const line of lines) {
1418
- const trimmedLine = line.trim();
1419
- if (trimmedLine) {
1420
- try {
1421
- const message = JSON.parse(trimmedLine);
1422
- controller.enqueue(message);
1423
- } catch (err) {
1424
- console.error("Failed to parse JSON message:", trimmedLine, err);
1425
- }
1426
- }
1427
- }
1428
- }
1429
- } finally {
1430
- reader.releaseLock();
1431
- controller.close();
1432
- }
1433
- }
1434
- });
1435
- const writable = new WritableStream({
1436
- async write(message) {
1437
- const content = JSON.stringify(message) + "\n";
1438
- const writer = output.getWriter();
1439
- try {
1440
- await writer.write(textEncoder.encode(content));
1441
- } finally {
1442
- writer.releaseLock();
1443
- }
1444
- }
1445
- });
1446
- return {
1447
- readable,
1448
- writable
1449
- };
1450
- }
1451
- var init_stream = __esm({
1452
- "../../node_modules/@agentclientprotocol/sdk/dist/stream.js"() {
1453
- "use strict";
1454
- __name(ndJsonStream, "ndJsonStream");
1455
- }
1456
- });
1457
-
1458
- // ../../node_modules/@agentclientprotocol/sdk/dist/acp.js
1459
- var acp_exports = {};
1460
- __export(acp_exports, {
1461
- AGENT_METHODS: () => AGENT_METHODS,
1462
- AgentSideConnection: () => AgentSideConnection,
1463
- CLIENT_METHODS: () => CLIENT_METHODS,
1464
- ClientSideConnection: () => ClientSideConnection,
1465
- PROTOCOL_VERSION: () => PROTOCOL_VERSION,
1466
- RequestError: () => RequestError,
1467
- TerminalHandle: () => TerminalHandle,
1468
- ndJsonStream: () => ndJsonStream
1469
- });
1470
- import { z as z2 } from "zod";
1471
- var AgentSideConnection, TerminalHandle, ClientSideConnection, Connection, RequestError;
1472
- var init_acp = __esm({
1473
- "../../node_modules/@agentclientprotocol/sdk/dist/acp.js"() {
1474
- init_schema();
1475
- init_zod_gen();
1476
- init_schema();
1477
- init_stream();
1478
- AgentSideConnection = class {
1479
- static {
1480
- __name(this, "AgentSideConnection");
1481
- }
1482
- #connection;
1483
- /**
1484
- * Creates a new agent-side connection to a client.
1485
- *
1486
- * This establishes the communication channel from the agent's perspective
1487
- * following the ACP specification.
1488
- *
1489
- * @param toAgent - A function that creates an Agent handler to process incoming client requests
1490
- * @param stream - The bidirectional message stream for communication. Typically created using
1491
- * {@link ndJsonStream} for stdio-based connections.
1492
- *
1493
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
1494
- */
1495
- constructor(toAgent, stream) {
1496
- const agent = toAgent(this);
1497
- const requestHandler = /* @__PURE__ */ __name(async (method, params) => {
1498
- switch (method) {
1499
- case AGENT_METHODS.initialize: {
1500
- const validatedParams = zInitializeRequest.parse(params);
1501
- return agent.initialize(validatedParams);
1502
- }
1503
- case AGENT_METHODS.session_new: {
1504
- const validatedParams = zNewSessionRequest.parse(params);
1505
- return agent.newSession(validatedParams);
1506
- }
1507
- case AGENT_METHODS.session_load: {
1508
- if (!agent.loadSession) {
1509
- throw RequestError.methodNotFound(method);
1510
- }
1511
- const validatedParams = zLoadSessionRequest.parse(params);
1512
- return agent.loadSession(validatedParams);
1513
- }
1514
- case AGENT_METHODS.session_list: {
1515
- if (!agent.unstable_listSessions) {
1516
- throw RequestError.methodNotFound(method);
1517
- }
1518
- const validatedParams = zListSessionsRequest.parse(params);
1519
- return agent.unstable_listSessions(validatedParams);
1520
- }
1521
- case AGENT_METHODS.session_fork: {
1522
- if (!agent.unstable_forkSession) {
1523
- throw RequestError.methodNotFound(method);
1524
- }
1525
- const validatedParams = zForkSessionRequest.parse(params);
1526
- return agent.unstable_forkSession(validatedParams);
1527
- }
1528
- case AGENT_METHODS.session_resume: {
1529
- if (!agent.unstable_resumeSession) {
1530
- throw RequestError.methodNotFound(method);
1531
- }
1532
- const validatedParams = zResumeSessionRequest.parse(params);
1533
- return agent.unstable_resumeSession(validatedParams);
1534
- }
1535
- case AGENT_METHODS.session_set_mode: {
1536
- if (!agent.setSessionMode) {
1537
- throw RequestError.methodNotFound(method);
1538
- }
1539
- const validatedParams = zSetSessionModeRequest.parse(params);
1540
- const result = await agent.setSessionMode(validatedParams);
1541
- return result ?? {};
1542
- }
1543
- case AGENT_METHODS.authenticate: {
1544
- const validatedParams = zAuthenticateRequest.parse(params);
1545
- const result = await agent.authenticate(validatedParams);
1546
- return result ?? {};
1547
- }
1548
- case AGENT_METHODS.session_prompt: {
1549
- const validatedParams = zPromptRequest.parse(params);
1550
- return agent.prompt(validatedParams);
1551
- }
1552
- case AGENT_METHODS.session_set_model: {
1553
- if (!agent.unstable_setSessionModel) {
1554
- throw RequestError.methodNotFound(method);
1555
- }
1556
- const validatedParams = zSetSessionModelRequest.parse(params);
1557
- const result = await agent.unstable_setSessionModel(validatedParams);
1558
- return result ?? {};
1559
- }
1560
- case AGENT_METHODS.session_set_config_option: {
1561
- if (!agent.setSessionConfigOption) {
1562
- throw RequestError.methodNotFound(method);
1563
- }
1564
- const validatedParams = zSetSessionConfigOptionRequest.parse(params);
1565
- return agent.setSessionConfigOption(validatedParams);
1566
- }
1567
- default:
1568
- if (agent.extMethod) {
1569
- return agent.extMethod(method, params);
1570
- }
1571
- throw RequestError.methodNotFound(method);
1572
- }
1573
- }, "requestHandler");
1574
- const notificationHandler = /* @__PURE__ */ __name(async (method, params) => {
1575
- switch (method) {
1576
- case AGENT_METHODS.session_cancel: {
1577
- const validatedParams = zCancelNotification.parse(params);
1578
- return agent.cancel(validatedParams);
1579
- }
1580
- default:
1581
- if (agent.extNotification) {
1582
- return agent.extNotification(method, params);
1583
- }
1584
- throw RequestError.methodNotFound(method);
1585
- }
1586
- }, "notificationHandler");
1587
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
1588
- }
1589
- /**
1590
- * Handles session update notifications from the agent.
1591
- *
1592
- * This is a notification endpoint (no response expected) that sends
1593
- * real-time updates about session progress, including message chunks,
1594
- * tool calls, and execution plans.
1595
- *
1596
- * Note: Clients SHOULD continue accepting tool call updates even after
1597
- * sending a `session/cancel` notification, as the agent may send final
1598
- * updates before responding with the cancelled stop reason.
1599
- *
1600
- * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)
1601
- */
1602
- async sessionUpdate(params) {
1603
- return await this.#connection.sendNotification(CLIENT_METHODS.session_update, params);
1604
- }
1605
- /**
1606
- * Requests permission from the user for a tool call operation.
1607
- *
1608
- * Called by the agent when it needs user authorization before executing
1609
- * a potentially sensitive operation. The client should present the options
1610
- * to the user and return their decision.
1611
- *
1612
- * If the client cancels the prompt turn via `session/cancel`, it MUST
1613
- * respond to this request with `RequestPermissionOutcome::Cancelled`.
1614
- *
1615
- * See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)
1616
- */
1617
- async requestPermission(params) {
1618
- return await this.#connection.sendRequest(CLIENT_METHODS.session_request_permission, params);
1619
- }
1620
- /**
1621
- * Reads content from a text file in the client's file system.
1622
- *
1623
- * Only available if the client advertises the `fs.readTextFile` capability.
1624
- * Allows the agent to access file contents within the client's environment.
1625
- *
1626
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
1627
- */
1628
- async readTextFile(params) {
1629
- return await this.#connection.sendRequest(CLIENT_METHODS.fs_read_text_file, params);
1630
- }
1631
- /**
1632
- * Writes content to a text file in the client's file system.
1633
- *
1634
- * Only available if the client advertises the `fs.writeTextFile` capability.
1635
- * Allows the agent to create or modify files within the client's environment.
1636
- *
1637
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
1638
- */
1639
- async writeTextFile(params) {
1640
- return await this.#connection.sendRequest(CLIENT_METHODS.fs_write_text_file, params) ?? {};
1641
- }
1642
- /**
1643
- * Executes a command in a new terminal.
1644
- *
1645
- * Returns a `TerminalHandle` that can be used to get output, wait for exit,
1646
- * kill the command, or release the terminal.
1647
- *
1648
- * The terminal can also be embedded in tool calls by using its ID in
1649
- * `ToolCallContent` with type "terminal".
1650
- *
1651
- * @param params - The terminal creation parameters
1652
- * @returns A handle to control and monitor the terminal
1653
- */
1654
- async createTerminal(params) {
1655
- const response = await this.#connection.sendRequest(CLIENT_METHODS.terminal_create, params);
1656
- return new TerminalHandle(response.terminalId, params.sessionId, this.#connection);
1657
- }
1658
- /**
1659
- * Extension method
1660
- *
1661
- * Allows the Agent to send an arbitrary request that is not part of the ACP spec.
1662
- */
1663
- async extMethod(method, params) {
1664
- return await this.#connection.sendRequest(method, params);
1665
- }
1666
- /**
1667
- * Extension notification
1668
- *
1669
- * Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
1670
- */
1671
- async extNotification(method, params) {
1672
- return await this.#connection.sendNotification(method, params);
1673
- }
1674
- /**
1675
- * AbortSignal that aborts when the connection closes.
1676
- *
1677
- * This signal can be used to:
1678
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
1679
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
1680
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
1681
- *
1682
- * The connection closes when the underlying stream ends, either normally or due to an error.
1683
- *
1684
- * @example
1685
- * ```typescript
1686
- * const connection = new AgentSideConnection(agent, stream);
1687
- *
1688
- * // Listen for closure
1689
- * connection.signal.addEventListener('abort', () => {
1690
- * console.log('Connection closed - performing cleanup');
1691
- * });
1692
- *
1693
- * // Check status
1694
- * if (connection.signal.aborted) {
1695
- * console.log('Connection is already closed');
1696
- * }
1697
- *
1698
- * // Pass to other APIs
1699
- * fetch(url, { signal: connection.signal });
1700
- * ```
1701
- */
1702
- get signal() {
1703
- return this.#connection.signal;
1704
- }
1705
- /**
1706
- * Promise that resolves when the connection closes.
1707
- *
1708
- * The connection closes when the underlying stream ends, either normally or due to an error.
1709
- * Once closed, the connection cannot send or receive any more messages.
1710
- *
1711
- * This is useful for async/await style cleanup:
1712
- *
1713
- * @example
1714
- * ```typescript
1715
- * const connection = new AgentSideConnection(agent, stream);
1716
- * await connection.closed;
1717
- * console.log('Connection closed - performing cleanup');
1718
- * ```
1719
- */
1720
- get closed() {
1721
- return this.#connection.closed;
1722
- }
1723
- };
1724
- TerminalHandle = class {
1725
- static {
1726
- __name(this, "TerminalHandle");
1727
- }
1728
- id;
1729
- #sessionId;
1730
- #connection;
1731
- constructor(id, sessionId, conn) {
1732
- this.id = id;
1733
- this.#sessionId = sessionId;
1734
- this.#connection = conn;
1735
- }
1736
- /**
1737
- * Gets the current terminal output without waiting for the command to exit.
1738
- */
1739
- async currentOutput() {
1740
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_output, {
1741
- sessionId: this.#sessionId,
1742
- terminalId: this.id
1743
- });
1744
- }
1745
- /**
1746
- * Waits for the terminal command to complete and returns its exit status.
1747
- */
1748
- async waitForExit() {
1749
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_wait_for_exit, {
1750
- sessionId: this.#sessionId,
1751
- terminalId: this.id
1752
- });
1753
- }
1754
- /**
1755
- * Kills the terminal command without releasing the terminal.
1756
- *
1757
- * The terminal remains valid after killing, allowing you to:
1758
- * - Get the final output with `currentOutput()`
1759
- * - Check the exit status
1760
- * - Release the terminal when done
1761
- *
1762
- * Useful for implementing timeouts or cancellation.
1763
- */
1764
- async kill() {
1765
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_kill, {
1766
- sessionId: this.#sessionId,
1767
- terminalId: this.id
1768
- }) ?? {};
1769
- }
1770
- /**
1771
- * Releases the terminal and frees all associated resources.
1772
- *
1773
- * If the command is still running, it will be killed.
1774
- * After release, the terminal ID becomes invalid and cannot be used
1775
- * with other terminal methods.
1776
- *
1777
- * Tool calls that already reference this terminal will continue to
1778
- * display its output.
1779
- *
1780
- * **Important:** Always call this method when done with the terminal.
1781
- */
1782
- async release() {
1783
- return await this.#connection.sendRequest(CLIENT_METHODS.terminal_release, {
1784
- sessionId: this.#sessionId,
1785
- terminalId: this.id
1786
- }) ?? {};
1787
- }
1788
- async [Symbol.asyncDispose]() {
1789
- await this.release();
1790
- }
1791
- };
1792
- ClientSideConnection = class {
1793
- static {
1794
- __name(this, "ClientSideConnection");
1795
- }
1796
- #connection;
1797
- /**
1798
- * Creates a new client-side connection to an agent.
1799
- *
1800
- * This establishes the communication channel between a client and agent
1801
- * following the ACP specification.
1802
- *
1803
- * @param toClient - A function that creates a Client handler to process incoming agent requests
1804
- * @param stream - The bidirectional message stream for communication. Typically created using
1805
- * {@link ndJsonStream} for stdio-based connections.
1806
- *
1807
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
1808
- */
1809
- constructor(toClient, stream) {
1810
- const client = toClient(this);
1811
- const requestHandler = /* @__PURE__ */ __name(async (method, params) => {
1812
- switch (method) {
1813
- case CLIENT_METHODS.fs_write_text_file: {
1814
- const validatedParams = zWriteTextFileRequest.parse(params);
1815
- return client.writeTextFile?.(validatedParams);
1816
- }
1817
- case CLIENT_METHODS.fs_read_text_file: {
1818
- const validatedParams = zReadTextFileRequest.parse(params);
1819
- return client.readTextFile?.(validatedParams);
1820
- }
1821
- case CLIENT_METHODS.session_request_permission: {
1822
- const validatedParams = zRequestPermissionRequest.parse(params);
1823
- return client.requestPermission(validatedParams);
1824
- }
1825
- case CLIENT_METHODS.terminal_create: {
1826
- const validatedParams = zCreateTerminalRequest.parse(params);
1827
- return client.createTerminal?.(validatedParams);
1828
- }
1829
- case CLIENT_METHODS.terminal_output: {
1830
- const validatedParams = zTerminalOutputRequest.parse(params);
1831
- return client.terminalOutput?.(validatedParams);
1832
- }
1833
- case CLIENT_METHODS.terminal_release: {
1834
- const validatedParams = zReleaseTerminalRequest.parse(params);
1835
- const result = await client.releaseTerminal?.(validatedParams);
1836
- return result ?? {};
1837
- }
1838
- case CLIENT_METHODS.terminal_wait_for_exit: {
1839
- const validatedParams = zWaitForTerminalExitRequest.parse(params);
1840
- return client.waitForTerminalExit?.(validatedParams);
1841
- }
1842
- case CLIENT_METHODS.terminal_kill: {
1843
- const validatedParams = zKillTerminalCommandRequest.parse(params);
1844
- const result = await client.killTerminal?.(validatedParams);
1845
- return result ?? {};
1846
- }
1847
- default:
1848
- if (client.extMethod) {
1849
- return client.extMethod(method, params);
1850
- }
1851
- throw RequestError.methodNotFound(method);
1852
- }
1853
- }, "requestHandler");
1854
- const notificationHandler = /* @__PURE__ */ __name(async (method, params) => {
1855
- switch (method) {
1856
- case CLIENT_METHODS.session_update: {
1857
- const validatedParams = zSessionNotification.parse(params);
1858
- return client.sessionUpdate(validatedParams);
1859
- }
1860
- default:
1861
- if (client.extNotification) {
1862
- return client.extNotification(method, params);
1863
- }
1864
- throw RequestError.methodNotFound(method);
1865
- }
1866
- }, "notificationHandler");
1867
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
1868
- }
1869
- /**
1870
- * Establishes the connection with a client and negotiates protocol capabilities.
1871
- *
1872
- * This method is called once at the beginning of the connection to:
1873
- * - Negotiate the protocol version to use
1874
- * - Exchange capability information between client and agent
1875
- * - Determine available authentication methods
1876
- *
1877
- * The agent should respond with its supported protocol version and capabilities.
1878
- *
1879
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
1880
- */
1881
- async initialize(params) {
1882
- return await this.#connection.sendRequest(AGENT_METHODS.initialize, params);
1883
- }
1884
- /**
1885
- * Creates a new conversation session with the agent.
1886
- *
1887
- * Sessions represent independent conversation contexts with their own history and state.
1888
- *
1889
- * The agent should:
1890
- * - Create a new session context
1891
- * - Connect to any specified MCP servers
1892
- * - Return a unique session ID for future requests
1893
- *
1894
- * May return an `auth_required` error if the agent requires authentication.
1895
- *
1896
- * See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
1897
- */
1898
- async newSession(params) {
1899
- return await this.#connection.sendRequest(AGENT_METHODS.session_new, params);
1900
- }
1901
- /**
1902
- * Loads an existing session to resume a previous conversation.
1903
- *
1904
- * This method is only available if the agent advertises the `loadSession` capability.
1905
- *
1906
- * The agent should:
1907
- * - Restore the session context and conversation history
1908
- * - Connect to the specified MCP servers
1909
- * - Stream the entire conversation history back to the client via notifications
1910
- *
1911
- * See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
1912
- */
1913
- async loadSession(params) {
1914
- return await this.#connection.sendRequest(AGENT_METHODS.session_load, params) ?? {};
1915
- }
1916
- /**
1917
- * **UNSTABLE**
1918
- *
1919
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1920
- *
1921
- * Forks an existing session to create a new independent session.
1922
- *
1923
- * Creates a new session based on the context of an existing one, allowing
1924
- * operations like generating summaries without affecting the original session's history.
1925
- *
1926
- * This method is only available if the agent advertises the `session.fork` capability.
1927
- *
1928
- * @experimental
1929
- */
1930
- async unstable_forkSession(params) {
1931
- return await this.#connection.sendRequest(AGENT_METHODS.session_fork, params);
1932
- }
1933
- /**
1934
- * **UNSTABLE**
1935
- *
1936
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1937
- *
1938
- * Lists existing sessions from the agent.
1939
- *
1940
- * This method is only available if the agent advertises the `listSessions` capability.
1941
- *
1942
- * Returns a list of sessions with metadata like session ID, working directory,
1943
- * title, and last update time. Supports filtering by working directory and
1944
- * cursor-based pagination.
1945
- *
1946
- * @experimental
1947
- */
1948
- async unstable_listSessions(params) {
1949
- return await this.#connection.sendRequest(AGENT_METHODS.session_list, params);
1950
- }
1951
- /**
1952
- * **UNSTABLE**
1953
- *
1954
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1955
- *
1956
- * Resumes an existing session without returning previous messages.
1957
- *
1958
- * This method is only available if the agent advertises the `session.resume` capability.
1959
- *
1960
- * The agent should resume the session context, allowing the conversation to continue
1961
- * without replaying the message history (unlike `session/load`).
1962
- *
1963
- * @experimental
1964
- */
1965
- async unstable_resumeSession(params) {
1966
- return await this.#connection.sendRequest(AGENT_METHODS.session_resume, params);
1967
- }
1968
- /**
1969
- * Sets the operational mode for a session.
1970
- *
1971
- * Allows switching between different agent modes (e.g., "ask", "architect", "code")
1972
- * that affect system prompts, tool availability, and permission behaviors.
1973
- *
1974
- * The mode must be one of the modes advertised in `availableModes` during session
1975
- * creation or loading. Agents may also change modes autonomously and notify the
1976
- * client via `current_mode_update` notifications.
1977
- *
1978
- * This method can be called at any time during a session, whether the Agent is
1979
- * idle or actively generating a turn.
1980
- *
1981
- * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
1982
- */
1983
- async setSessionMode(params) {
1984
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_mode, params) ?? {};
1985
- }
1986
- /**
1987
- * **UNSTABLE**
1988
- *
1989
- * This capability is not part of the spec yet, and may be removed or changed at any point.
1990
- *
1991
- * Select a model for a given session.
1992
- *
1993
- * @experimental
1994
- */
1995
- async unstable_setSessionModel(params) {
1996
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_model, params) ?? {};
1997
- }
1998
- /**
1999
- * Set a configuration option for a given session.
2000
- *
2001
- * The response contains the full set of configuration options and their current values,
2002
- * as changing one option may affect the available values or state of other options.
2003
- */
2004
- async setSessionConfigOption(params) {
2005
- return await this.#connection.sendRequest(AGENT_METHODS.session_set_config_option, params);
2006
- }
2007
- /**
2008
- * Authenticates the client using the specified authentication method.
2009
- *
2010
- * Called when the agent requires authentication before allowing session creation.
2011
- * The client provides the authentication method ID that was advertised during initialization.
2012
- *
2013
- * After successful authentication, the client can proceed to create sessions with
2014
- * `newSession` without receiving an `auth_required` error.
2015
- *
2016
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
2017
- */
2018
- async authenticate(params) {
2019
- return await this.#connection.sendRequest(AGENT_METHODS.authenticate, params) ?? {};
2020
- }
2021
- /**
2022
- * Processes a user prompt within a session.
2023
- *
2024
- * This method handles the whole lifecycle of a prompt:
2025
- * - Receives user messages with optional context (files, images, etc.)
2026
- * - Processes the prompt using language models
2027
- * - Reports language model content and tool calls to the Clients
2028
- * - Requests permission to run tools
2029
- * - Executes any requested tool calls
2030
- * - Returns when the turn is complete with a stop reason
2031
- *
2032
- * See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
2033
- */
2034
- async prompt(params) {
2035
- return await this.#connection.sendRequest(AGENT_METHODS.session_prompt, params);
2036
- }
2037
- /**
2038
- * Cancels ongoing operations for a session.
2039
- *
2040
- * This is a notification sent by the client to cancel an ongoing prompt turn.
2041
- *
2042
- * Upon receiving this notification, the Agent SHOULD:
2043
- * - Stop all language model requests as soon as possible
2044
- * - Abort all tool call invocations in progress
2045
- * - Send any pending `session/update` notifications
2046
- * - Respond to the original `session/prompt` request with `StopReason::Cancelled`
2047
- *
2048
- * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
2049
- */
2050
- async cancel(params) {
2051
- return await this.#connection.sendNotification(AGENT_METHODS.session_cancel, params);
2052
- }
2053
- /**
2054
- * Extension method
2055
- *
2056
- * Allows the Client to send an arbitrary request that is not part of the ACP spec.
2057
- */
2058
- async extMethod(method, params) {
2059
- return await this.#connection.sendRequest(method, params);
2060
- }
2061
- /**
2062
- * Extension notification
2063
- *
2064
- * Allows the Client to send an arbitrary notification that is not part of the ACP spec.
2065
- */
2066
- async extNotification(method, params) {
2067
- return await this.#connection.sendNotification(method, params);
2068
- }
2069
- /**
2070
- * AbortSignal that aborts when the connection closes.
2071
- *
2072
- * This signal can be used to:
2073
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
2074
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
2075
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
2076
- *
2077
- * The connection closes when the underlying stream ends, either normally or due to an error.
2078
- *
2079
- * @example
2080
- * ```typescript
2081
- * const connection = new ClientSideConnection(client, stream);
2082
- *
2083
- * // Listen for closure
2084
- * connection.signal.addEventListener('abort', () => {
2085
- * console.log('Connection closed - performing cleanup');
2086
- * });
2087
- *
2088
- * // Check status
2089
- * if (connection.signal.aborted) {
2090
- * console.log('Connection is already closed');
2091
- * }
2092
- *
2093
- * // Pass to other APIs
2094
- * fetch(url, { signal: connection.signal });
2095
- * ```
2096
- */
2097
- get signal() {
2098
- return this.#connection.signal;
2099
- }
2100
- /**
2101
- * Promise that resolves when the connection closes.
2102
- *
2103
- * The connection closes when the underlying stream ends, either normally or due to an error.
2104
- * Once closed, the connection cannot send or receive any more messages.
2105
- *
2106
- * This is useful for async/await style cleanup:
2107
- *
2108
- * @example
2109
- * ```typescript
2110
- * const connection = new ClientSideConnection(client, stream);
2111
- * await connection.closed;
2112
- * console.log('Connection closed - performing cleanup');
2113
- * ```
2114
- */
2115
- get closed() {
2116
- return this.#connection.closed;
2117
- }
2118
- };
2119
- Connection = class Connection2 {
2120
- static {
2121
- __name(this, "Connection");
2122
- }
2123
- #pendingResponses = /* @__PURE__ */ new Map();
2124
- #nextRequestId = 0;
2125
- #requestHandler;
2126
- #notificationHandler;
2127
- #stream;
2128
- #writeQueue = Promise.resolve();
2129
- #abortController = new AbortController();
2130
- #closedPromise;
2131
- constructor(requestHandler, notificationHandler, stream) {
2132
- this.#requestHandler = requestHandler;
2133
- this.#notificationHandler = notificationHandler;
2134
- this.#stream = stream;
2135
- this.#closedPromise = new Promise((resolve) => {
2136
- this.#abortController.signal.addEventListener("abort", () => resolve());
2137
- });
2138
- this.#receive();
2139
- }
2140
- /**
2141
- * AbortSignal that aborts when the connection closes.
2142
- *
2143
- * This signal can be used to:
2144
- * - Listen for connection closure via event listeners
2145
- * - Check connection status synchronously with `signal.aborted`
2146
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
2147
- */
2148
- get signal() {
2149
- return this.#abortController.signal;
2150
- }
2151
- /**
2152
- * Promise that resolves when the connection closes.
2153
- *
2154
- * The connection closes when the underlying stream ends, either normally
2155
- * or due to an error. Once closed, the connection cannot send or receive
2156
- * any more messages.
2157
- *
2158
- * @example
2159
- * ```typescript
2160
- * const connection = new ClientSideConnection(client, stream);
2161
- * await connection.closed;
2162
- * console.log('Connection closed - performing cleanup');
2163
- * ```
2164
- */
2165
- get closed() {
2166
- return this.#closedPromise;
2167
- }
2168
- async #receive() {
2169
- const reader = this.#stream.readable.getReader();
2170
- try {
2171
- while (true) {
2172
- const { value: message, done } = await reader.read();
2173
- if (done) {
2174
- break;
2175
- }
2176
- if (!message) {
2177
- continue;
2178
- }
2179
- try {
2180
- this.#processMessage(message);
2181
- } catch (err) {
2182
- console.error("Unexpected error during message processing:", message, err);
2183
- if ("id" in message && message.id !== void 0) {
2184
- this.#sendMessage({
2185
- jsonrpc: "2.0",
2186
- id: message.id,
2187
- error: {
2188
- code: -32700,
2189
- message: "Parse error"
2190
- }
2191
- });
2192
- }
2193
- }
2194
- }
2195
- } finally {
2196
- reader.releaseLock();
2197
- this.#abortController.abort();
2198
- }
2199
- }
2200
- async #processMessage(message) {
2201
- if ("method" in message && "id" in message) {
2202
- const response = await this.#tryCallRequestHandler(message.method, message.params);
2203
- if ("error" in response) {
2204
- console.error("Error handling request", message, response.error);
2205
- }
2206
- await this.#sendMessage({
2207
- jsonrpc: "2.0",
2208
- id: message.id,
2209
- ...response
2210
- });
2211
- } else if ("method" in message) {
2212
- const response = await this.#tryCallNotificationHandler(message.method, message.params);
2213
- if ("error" in response) {
2214
- console.error("Error handling notification", message, response.error);
2215
- }
2216
- } else if ("id" in message) {
2217
- this.#handleResponse(message);
2218
- } else {
2219
- console.error("Invalid message", {
2220
- message
2221
- });
2222
- }
2223
- }
2224
- async #tryCallRequestHandler(method, params) {
2225
- try {
2226
- const result = await this.#requestHandler(method, params);
2227
- return {
2228
- result: result ?? null
2229
- };
2230
- } catch (error) {
2231
- if (error instanceof RequestError) {
2232
- return error.toResult();
2233
- }
2234
- if (error instanceof z2.ZodError) {
2235
- return RequestError.invalidParams(error.format()).toResult();
2236
- }
2237
- let details;
2238
- if (error instanceof Error) {
2239
- details = error.message;
2240
- } else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
2241
- details = error.message;
2242
- }
2243
- try {
2244
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
2245
- } catch {
2246
- return RequestError.internalError({
2247
- details
2248
- }).toResult();
2249
- }
2250
- }
2251
- }
2252
- async #tryCallNotificationHandler(method, params) {
2253
- try {
2254
- await this.#notificationHandler(method, params);
2255
- return {
2256
- result: null
2257
- };
2258
- } catch (error) {
2259
- if (error instanceof RequestError) {
2260
- return error.toResult();
2261
- }
2262
- if (error instanceof z2.ZodError) {
2263
- return RequestError.invalidParams(error.format()).toResult();
2264
- }
2265
- let details;
2266
- if (error instanceof Error) {
2267
- details = error.message;
2268
- } else if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
2269
- details = error.message;
2270
- }
2271
- try {
2272
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
2273
- } catch {
2274
- return RequestError.internalError({
2275
- details
2276
- }).toResult();
2277
- }
2278
- }
2279
- }
2280
- #handleResponse(response) {
2281
- const pendingResponse = this.#pendingResponses.get(response.id);
2282
- if (pendingResponse) {
2283
- if ("result" in response) {
2284
- pendingResponse.resolve(response.result);
2285
- } else if ("error" in response) {
2286
- pendingResponse.reject(response.error);
2287
- }
2288
- this.#pendingResponses.delete(response.id);
2289
- } else {
2290
- console.error("Got response to unknown request", response.id);
2291
- }
2292
- }
2293
- async sendRequest(method, params) {
2294
- const id = this.#nextRequestId++;
2295
- const responsePromise = new Promise((resolve, reject) => {
2296
- this.#pendingResponses.set(id, {
2297
- resolve,
2298
- reject
2299
- });
2300
- });
2301
- await this.#sendMessage({
2302
- jsonrpc: "2.0",
2303
- id,
2304
- method,
2305
- params
2306
- });
2307
- return responsePromise;
2308
- }
2309
- async sendNotification(method, params) {
2310
- await this.#sendMessage({
2311
- jsonrpc: "2.0",
2312
- method,
2313
- params
2314
- });
2315
- }
2316
- async #sendMessage(message) {
2317
- this.#writeQueue = this.#writeQueue.then(async () => {
2318
- const writer = this.#stream.writable.getWriter();
2319
- try {
2320
- await writer.write(message);
2321
- } finally {
2322
- writer.releaseLock();
2323
- }
2324
- }).catch((error) => {
2325
- console.error("ACP write error:", error);
2326
- });
2327
- return this.#writeQueue;
2328
- }
2329
- };
2330
- RequestError = class _RequestError extends Error {
2331
- static {
2332
- __name(this, "RequestError");
2333
- }
2334
- code;
2335
- data;
2336
- constructor(code, message, data) {
2337
- super(message);
2338
- this.code = code;
2339
- this.name = "RequestError";
2340
- this.data = data;
2341
- }
2342
- /**
2343
- * Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
2344
- */
2345
- static parseError(data, additionalMessage) {
2346
- return new _RequestError(-32700, `Parse error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2347
- }
2348
- /**
2349
- * The JSON sent is not a valid Request object.
2350
- */
2351
- static invalidRequest(data, additionalMessage) {
2352
- return new _RequestError(-32600, `Invalid request${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2353
- }
2354
- /**
2355
- * The method does not exist / is not available.
2356
- */
2357
- static methodNotFound(method) {
2358
- return new _RequestError(-32601, `"Method not found": ${method}`, {
2359
- method
2360
- });
2361
- }
2362
- /**
2363
- * Invalid method parameter(s).
2364
- */
2365
- static invalidParams(data, additionalMessage) {
2366
- return new _RequestError(-32602, `Invalid params${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2367
- }
2368
- /**
2369
- * Internal JSON-RPC error.
2370
- */
2371
- static internalError(data, additionalMessage) {
2372
- return new _RequestError(-32603, `Internal error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2373
- }
2374
- /**
2375
- * Authentication required.
2376
- */
2377
- static authRequired(data, additionalMessage) {
2378
- return new _RequestError(-32e3, `Authentication required${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
2379
- }
2380
- /**
2381
- * Resource, such as a file, was not found
2382
- */
2383
- static resourceNotFound(uri) {
2384
- return new _RequestError(-32002, `Resource not found${uri ? `: ${uri}` : ""}`, uri && {
2385
- uri
2386
- });
2387
- }
2388
- toResult() {
2389
- return {
2390
- error: {
2391
- code: this.code,
2392
- message: this.message,
2393
- data: this.data
2394
- }
2395
- };
2396
- }
2397
- toErrorResponse() {
2398
- return {
2399
- code: this.code,
2400
- message: this.message,
2401
- data: this.data
2402
- };
2403
- }
2404
- };
2405
- }
2406
- });
2407
-
2408
- export {
2409
- __name,
2410
- __require,
2411
- __esm,
2412
- __commonJS,
2413
- __export,
2414
- __toESM,
2415
- __toCommonJS,
2416
- AGENT_METHODS,
2417
- CLIENT_METHODS,
2418
- PROTOCOL_VERSION,
2419
- ndJsonStream,
2420
- AgentSideConnection,
2421
- TerminalHandle,
2422
- ClientSideConnection,
2423
- RequestError,
2424
- acp_exports,
2425
- init_acp
2426
- };