@google/gemini-cli 0.1.19-nightly.250813.9d023be1 → 0.1.19-nightly.250814.514e883a
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.
- package/README.md +1 -1
- package/dist/package.json +3 -3
- package/dist/src/config/config.d.ts +1 -1
- package/dist/src/config/config.js +11 -8
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/keyBindings.js +4 -0
- package/dist/src/config/keyBindings.js.map +1 -1
- package/dist/src/config/trustedFolders.d.ts +36 -0
- package/dist/src/config/trustedFolders.js +112 -0
- package/dist/src/config/trustedFolders.js.map +1 -0
- package/dist/src/gemini.js +6 -3
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +1 -1
- package/dist/src/generated/git-commit.js +1 -1
- package/dist/src/nonInteractiveCli.js +2 -3
- package/dist/src/nonInteractiveCli.js.map +1 -1
- package/dist/src/services/BuiltinCommandLoader.js +2 -0
- package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
- package/dist/src/ui/App.js +8 -2
- package/dist/src/ui/App.js.map +1 -1
- package/dist/src/ui/commands/directoryCommand.js +2 -4
- package/dist/src/ui/commands/directoryCommand.js.map +1 -1
- package/dist/src/ui/commands/mcpCommand.js +4 -0
- package/dist/src/ui/commands/mcpCommand.js.map +1 -1
- package/dist/src/ui/commands/terminalSetupCommand.d.ts +13 -0
- package/dist/src/ui/commands/terminalSetupCommand.js +41 -0
- package/dist/src/ui/commands/terminalSetupCommand.js.map +1 -0
- package/dist/src/ui/commands/types.d.ts +1 -0
- package/dist/src/ui/commands/types.js.map +1 -1
- package/dist/src/ui/components/InputPrompt.js +7 -1
- package/dist/src/ui/components/InputPrompt.js.map +1 -1
- package/dist/src/ui/components/shared/vim-buffer-actions.js +2 -1
- package/dist/src/ui/components/shared/vim-buffer-actions.js.map +1 -1
- package/dist/src/ui/hooks/slashCommandProcessor.js +67 -46
- package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useFocus.d.ts +4 -0
- package/dist/src/ui/hooks/useFocus.js +4 -4
- package/dist/src/ui/hooks/useFocus.js.map +1 -1
- package/dist/src/ui/hooks/useFolderTrust.d.ts +3 -2
- package/dist/src/ui/hooks/useFolderTrust.js +24 -9
- package/dist/src/ui/hooks/useFolderTrust.js.map +1 -1
- package/dist/src/ui/hooks/useGeminiStream.js +1 -2
- package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
- package/dist/src/ui/hooks/useKeypress.d.ts +9 -1
- package/dist/src/ui/hooks/useKeypress.js +197 -8
- package/dist/src/ui/hooks/useKeypress.js.map +1 -1
- package/dist/src/ui/hooks/useKittyKeyboardProtocol.d.ts +15 -0
- package/dist/src/ui/hooks/useKittyKeyboardProtocol.js +20 -0
- package/dist/src/ui/hooks/useKittyKeyboardProtocol.js.map +1 -0
- package/dist/src/ui/utils/kittyProtocolDetector.d.ts +13 -0
- package/dist/src/ui/utils/kittyProtocolDetector.js +88 -0
- package/dist/src/ui/utils/kittyProtocolDetector.js.map +1 -0
- package/dist/src/ui/utils/platformConstants.d.ts +38 -0
- package/dist/src/ui/utils/platformConstants.js +39 -0
- package/dist/src/ui/utils/platformConstants.js.map +1 -0
- package/dist/src/ui/utils/terminalSetup.d.ts +30 -0
- package/dist/src/ui/utils/terminalSetup.js +281 -0
- package/dist/src/ui/utils/terminalSetup.js.map +1 -0
- package/dist/src/utils/checks.d.ts +19 -0
- package/dist/src/utils/checks.js +24 -0
- package/dist/src/utils/checks.js.map +1 -0
- package/dist/src/zed-integration/acp.d.ts +63 -0
- package/dist/src/{acp → zed-integration}/acp.js +76 -44
- package/dist/src/zed-integration/acp.js.map +1 -0
- package/dist/src/zed-integration/schema.d.ts +11679 -0
- package/dist/src/zed-integration/schema.js +305 -0
- package/dist/src/zed-integration/schema.js.map +1 -0
- package/dist/src/zed-integration/zedIntegration.d.ts +10 -0
- package/dist/src/{acp/acpPeer.js → zed-integration/zedIntegration.js} +333 -187
- package/dist/src/zed-integration/zedIntegration.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/src/acp/acp.d.ts +0 -208
- package/dist/src/acp/acp.js.map +0 -1
- package/dist/src/acp/acpPeer.d.ts +0 -8
- package/dist/src/acp/acpPeer.js.map +0 -1
- package/dist/src/ui/utils/errorParsing.d.ts +0 -7
- package/dist/src/ui/utils/errorParsing.js +0 -90
- package/dist/src/ui/utils/errorParsing.js.map +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Terminal setup utility for configuring Shift+Enter and Ctrl+Enter support.
|
|
8
|
+
*
|
|
9
|
+
* This module provides automatic detection and configuration of various terminal
|
|
10
|
+
* emulators to support multiline input through modified Enter keys.
|
|
11
|
+
*
|
|
12
|
+
* Supported terminals:
|
|
13
|
+
* - VS Code: Configures keybindings.json to send \\\r\n
|
|
14
|
+
* - Cursor: Configures keybindings.json to send \\\r\n (VS Code fork)
|
|
15
|
+
* - Windsurf: Configures keybindings.json to send \\\r\n (VS Code fork)
|
|
16
|
+
*
|
|
17
|
+
* For VS Code and its forks:
|
|
18
|
+
* - Shift+Enter: Sends \\\r\n (backslash followed by CRLF)
|
|
19
|
+
* - Ctrl+Enter: Sends \\\r\n (backslash followed by CRLF)
|
|
20
|
+
*
|
|
21
|
+
* The module will not modify existing shift+enter or ctrl+enter keybindings
|
|
22
|
+
* to avoid conflicts with user customizations.
|
|
23
|
+
*/
|
|
24
|
+
import { promises as fs } from 'fs';
|
|
25
|
+
import * as os from 'os';
|
|
26
|
+
import * as path from 'path';
|
|
27
|
+
import { exec } from 'child_process';
|
|
28
|
+
import { promisify } from 'util';
|
|
29
|
+
import { isKittyProtocolEnabled } from './kittyProtocolDetector.js';
|
|
30
|
+
import { VSCODE_SHIFT_ENTER_SEQUENCE } from './platformConstants.js';
|
|
31
|
+
const execAsync = promisify(exec);
|
|
32
|
+
/**
|
|
33
|
+
* Removes single-line JSON comments (// ...) from a string to allow parsing
|
|
34
|
+
* VS Code style JSON files that may contain comments.
|
|
35
|
+
*/
|
|
36
|
+
function stripJsonComments(content) {
|
|
37
|
+
// Remove single-line comments (// ...)
|
|
38
|
+
return content.replace(/^\s*\/\/.*$/gm, '');
|
|
39
|
+
}
|
|
40
|
+
// Terminal detection
|
|
41
|
+
async function detectTerminal() {
|
|
42
|
+
const termProgram = process.env.TERM_PROGRAM;
|
|
43
|
+
// Check VS Code and its forks - check forks first to avoid false positives
|
|
44
|
+
// Check for Cursor-specific indicators
|
|
45
|
+
if (process.env.CURSOR_TRACE_ID ||
|
|
46
|
+
process.env.VSCODE_GIT_ASKPASS_MAIN?.toLowerCase().includes('cursor')) {
|
|
47
|
+
return 'cursor';
|
|
48
|
+
}
|
|
49
|
+
// Check for Windsurf-specific indicators
|
|
50
|
+
if (process.env.VSCODE_GIT_ASKPASS_MAIN?.toLowerCase().includes('windsurf')) {
|
|
51
|
+
return 'windsurf';
|
|
52
|
+
}
|
|
53
|
+
// Check VS Code last since forks may also set VSCODE env vars
|
|
54
|
+
if (termProgram === 'vscode' || process.env.VSCODE_GIT_IPC_HANDLE) {
|
|
55
|
+
return 'vscode';
|
|
56
|
+
}
|
|
57
|
+
// Check parent process name
|
|
58
|
+
if (os.platform() !== 'win32') {
|
|
59
|
+
try {
|
|
60
|
+
const { stdout } = await execAsync('ps -o comm= -p $PPID');
|
|
61
|
+
const parentName = stdout.trim();
|
|
62
|
+
// Check forks before VS Code to avoid false positives
|
|
63
|
+
if (parentName.includes('windsurf') || parentName.includes('Windsurf'))
|
|
64
|
+
return 'windsurf';
|
|
65
|
+
if (parentName.includes('cursor') || parentName.includes('Cursor'))
|
|
66
|
+
return 'cursor';
|
|
67
|
+
if (parentName.includes('code') || parentName.includes('Code'))
|
|
68
|
+
return 'vscode';
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// Continue detection even if process check fails
|
|
72
|
+
console.debug('Parent process detection failed:', error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// Backup file helper
|
|
78
|
+
async function backupFile(filePath) {
|
|
79
|
+
try {
|
|
80
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
81
|
+
const backupPath = `${filePath}.backup.${timestamp}`;
|
|
82
|
+
await fs.copyFile(filePath, backupPath);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// Log backup errors but continue with operation
|
|
86
|
+
console.warn(`Failed to create backup of ${filePath}:`, error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Helper function to get VS Code-style config directory
|
|
90
|
+
function getVSCodeStyleConfigDir(appName) {
|
|
91
|
+
const platform = os.platform();
|
|
92
|
+
if (platform === 'darwin') {
|
|
93
|
+
return path.join(os.homedir(), 'Library', 'Application Support', appName, 'User');
|
|
94
|
+
}
|
|
95
|
+
else if (platform === 'win32') {
|
|
96
|
+
if (!process.env.APPDATA) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return path.join(process.env.APPDATA, appName, 'User');
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return path.join(os.homedir(), '.config', appName, 'User');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Generic VS Code-style terminal configuration
|
|
106
|
+
async function configureVSCodeStyle(terminalName, appName) {
|
|
107
|
+
const configDir = getVSCodeStyleConfigDir(appName);
|
|
108
|
+
if (!configDir) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
message: `Could not determine ${terminalName} config path on Windows: APPDATA environment variable is not set.`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const keybindingsFile = path.join(configDir, 'keybindings.json');
|
|
115
|
+
try {
|
|
116
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
117
|
+
let keybindings = [];
|
|
118
|
+
try {
|
|
119
|
+
const content = await fs.readFile(keybindingsFile, 'utf8');
|
|
120
|
+
await backupFile(keybindingsFile);
|
|
121
|
+
try {
|
|
122
|
+
const cleanContent = stripJsonComments(content);
|
|
123
|
+
const parsedContent = JSON.parse(cleanContent);
|
|
124
|
+
if (!Array.isArray(parsedContent)) {
|
|
125
|
+
return {
|
|
126
|
+
success: false,
|
|
127
|
+
message: `${terminalName} keybindings.json exists but is not a valid JSON array. ` +
|
|
128
|
+
`Please fix the file manually or delete it to allow automatic configuration.\n` +
|
|
129
|
+
`File: ${keybindingsFile}`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
keybindings = parsedContent;
|
|
133
|
+
}
|
|
134
|
+
catch (parseError) {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
message: `Failed to parse ${terminalName} keybindings.json. The file contains invalid JSON.\n` +
|
|
138
|
+
`Please fix the file manually or delete it to allow automatic configuration.\n` +
|
|
139
|
+
`File: ${keybindingsFile}\n` +
|
|
140
|
+
`Error: ${parseError}`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// File doesn't exist, will create new one
|
|
146
|
+
}
|
|
147
|
+
const shiftEnterBinding = {
|
|
148
|
+
key: 'shift+enter',
|
|
149
|
+
command: 'workbench.action.terminal.sendSequence',
|
|
150
|
+
when: 'terminalFocus',
|
|
151
|
+
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
|
|
152
|
+
};
|
|
153
|
+
const ctrlEnterBinding = {
|
|
154
|
+
key: 'ctrl+enter',
|
|
155
|
+
command: 'workbench.action.terminal.sendSequence',
|
|
156
|
+
when: 'terminalFocus',
|
|
157
|
+
args: { text: VSCODE_SHIFT_ENTER_SEQUENCE },
|
|
158
|
+
};
|
|
159
|
+
// Check if ANY shift+enter or ctrl+enter bindings already exist
|
|
160
|
+
const existingShiftEnter = keybindings.find((kb) => {
|
|
161
|
+
const binding = kb;
|
|
162
|
+
return binding.key === 'shift+enter';
|
|
163
|
+
});
|
|
164
|
+
const existingCtrlEnter = keybindings.find((kb) => {
|
|
165
|
+
const binding = kb;
|
|
166
|
+
return binding.key === 'ctrl+enter';
|
|
167
|
+
});
|
|
168
|
+
if (existingShiftEnter || existingCtrlEnter) {
|
|
169
|
+
const messages = [];
|
|
170
|
+
if (existingShiftEnter) {
|
|
171
|
+
messages.push(`- Shift+Enter binding already exists`);
|
|
172
|
+
}
|
|
173
|
+
if (existingCtrlEnter) {
|
|
174
|
+
messages.push(`- Ctrl+Enter binding already exists`);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
success: false,
|
|
178
|
+
message: `Existing keybindings detected. Will not modify to avoid conflicts.\n` +
|
|
179
|
+
messages.join('\n') +
|
|
180
|
+
'\n' +
|
|
181
|
+
`Please check and modify manually if needed: ${keybindingsFile}`,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// Check if our specific bindings already exist
|
|
185
|
+
const hasOurShiftEnter = keybindings.some((kb) => {
|
|
186
|
+
const binding = kb;
|
|
187
|
+
return (binding.key === 'shift+enter' &&
|
|
188
|
+
binding.command === 'workbench.action.terminal.sendSequence' &&
|
|
189
|
+
binding.args?.text === '\\\r\n');
|
|
190
|
+
});
|
|
191
|
+
const hasOurCtrlEnter = keybindings.some((kb) => {
|
|
192
|
+
const binding = kb;
|
|
193
|
+
return (binding.key === 'ctrl+enter' &&
|
|
194
|
+
binding.command === 'workbench.action.terminal.sendSequence' &&
|
|
195
|
+
binding.args?.text === '\\\r\n');
|
|
196
|
+
});
|
|
197
|
+
if (!hasOurShiftEnter || !hasOurCtrlEnter) {
|
|
198
|
+
if (!hasOurShiftEnter)
|
|
199
|
+
keybindings.unshift(shiftEnterBinding);
|
|
200
|
+
if (!hasOurCtrlEnter)
|
|
201
|
+
keybindings.unshift(ctrlEnterBinding);
|
|
202
|
+
await fs.writeFile(keybindingsFile, JSON.stringify(keybindings, null, 4));
|
|
203
|
+
return {
|
|
204
|
+
success: true,
|
|
205
|
+
message: `Added Shift+Enter and Ctrl+Enter keybindings to ${terminalName}.\nModified: ${keybindingsFile}`,
|
|
206
|
+
requiresRestart: true,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
return {
|
|
211
|
+
success: true,
|
|
212
|
+
message: `${terminalName} keybindings already configured.`,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
message: `Failed to configure ${terminalName}.\nFile: ${keybindingsFile}\nError: ${error}`,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Terminal-specific configuration functions
|
|
224
|
+
async function configureVSCode() {
|
|
225
|
+
return configureVSCodeStyle('VS Code', 'Code');
|
|
226
|
+
}
|
|
227
|
+
async function configureCursor() {
|
|
228
|
+
return configureVSCodeStyle('Cursor', 'Cursor');
|
|
229
|
+
}
|
|
230
|
+
async function configureWindsurf() {
|
|
231
|
+
return configureVSCodeStyle('Windsurf', 'Windsurf');
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Main terminal setup function that detects and configures the current terminal.
|
|
235
|
+
*
|
|
236
|
+
* This function:
|
|
237
|
+
* 1. Detects the current terminal emulator
|
|
238
|
+
* 2. Applies appropriate configuration for Shift+Enter and Ctrl+Enter support
|
|
239
|
+
* 3. Creates backups of configuration files before modifying them
|
|
240
|
+
*
|
|
241
|
+
* @returns Promise<TerminalSetupResult> Result object with success status and message
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* const result = await terminalSetup();
|
|
245
|
+
* if (result.success) {
|
|
246
|
+
* console.log(result.message);
|
|
247
|
+
* if (result.requiresRestart) {
|
|
248
|
+
* console.log('Please restart your terminal');
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
*/
|
|
252
|
+
export async function terminalSetup() {
|
|
253
|
+
// Check if terminal already has optimal keyboard support
|
|
254
|
+
if (isKittyProtocolEnabled()) {
|
|
255
|
+
return {
|
|
256
|
+
success: true,
|
|
257
|
+
message: 'Your terminal is already configured for an optimal experience with multiline input (Shift+Enter and Ctrl+Enter).',
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const terminal = await detectTerminal();
|
|
261
|
+
if (!terminal) {
|
|
262
|
+
return {
|
|
263
|
+
success: false,
|
|
264
|
+
message: 'Could not detect terminal type. Supported terminals: VS Code, Cursor, and Windsurf.',
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
switch (terminal) {
|
|
268
|
+
case 'vscode':
|
|
269
|
+
return configureVSCode();
|
|
270
|
+
case 'cursor':
|
|
271
|
+
return configureCursor();
|
|
272
|
+
case 'windsurf':
|
|
273
|
+
return configureWindsurf();
|
|
274
|
+
default:
|
|
275
|
+
return {
|
|
276
|
+
success: false,
|
|
277
|
+
message: `Terminal "${terminal}" is not supported yet.`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=terminalSetup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminalSetup.js","sourceRoot":"","sources":["../../../../src/ui/utils/terminalSetup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,2BA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L,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,aAAa,QAAQ,yBAAyB;aACxD,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare function assumeExhaustive(_value: never): void;
|
|
7
|
+
/**
|
|
8
|
+
* Throws an exception on unexpected values.
|
|
9
|
+
*
|
|
10
|
+
* A common use case is switch statements:
|
|
11
|
+
* switch(enumValue) {
|
|
12
|
+
* case Enum.A:
|
|
13
|
+
* case Enum.B:
|
|
14
|
+
* break;
|
|
15
|
+
* default:
|
|
16
|
+
* checkExhaustive(enumValue);
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkExhaustive(value: never, msg?: string): never;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/* Fail to compile on unexpected values. */
|
|
7
|
+
export function assumeExhaustive(_value) { }
|
|
8
|
+
/**
|
|
9
|
+
* Throws an exception on unexpected values.
|
|
10
|
+
*
|
|
11
|
+
* A common use case is switch statements:
|
|
12
|
+
* switch(enumValue) {
|
|
13
|
+
* case Enum.A:
|
|
14
|
+
* case Enum.B:
|
|
15
|
+
* break;
|
|
16
|
+
* default:
|
|
17
|
+
* checkExhaustive(enumValue);
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export function checkExhaustive(value, msg = `unexpected value ${value}!`) {
|
|
21
|
+
assumeExhaustive(value);
|
|
22
|
+
throw new Error(msg);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../../../src/utils/checks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,2CAA2C;AAC3C,MAAM,UAAU,gBAAgB,CAAC,MAAa,IAAS,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAY,EACZ,GAAG,GAAG,oBAAoB,KAAK,GAAG;IAElC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACxB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import * as schema from './schema.js';
|
|
7
|
+
export * from './schema.js';
|
|
8
|
+
import { WritableStream, ReadableStream } from 'node:stream/web';
|
|
9
|
+
export declare class AgentSideConnection implements Client {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(toAgent: (conn: Client) => Agent, input: WritableStream<Uint8Array>, output: ReadableStream<Uint8Array>);
|
|
12
|
+
/**
|
|
13
|
+
* Streams new content to the client including text, tool calls, etc.
|
|
14
|
+
*/
|
|
15
|
+
sessionUpdate(params: schema.SessionNotification): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Request permission before running a tool
|
|
18
|
+
*
|
|
19
|
+
* The agent specifies a series of permission options with different granularity,
|
|
20
|
+
* and the client returns the chosen one.
|
|
21
|
+
*/
|
|
22
|
+
requestPermission(params: schema.RequestPermissionRequest): Promise<schema.RequestPermissionResponse>;
|
|
23
|
+
readTextFile(params: schema.ReadTextFileRequest): Promise<schema.ReadTextFileResponse>;
|
|
24
|
+
writeTextFile(params: schema.WriteTextFileRequest): Promise<schema.WriteTextFileResponse>;
|
|
25
|
+
}
|
|
26
|
+
type Result<T> = {
|
|
27
|
+
result: T;
|
|
28
|
+
} | {
|
|
29
|
+
error: ErrorResponse;
|
|
30
|
+
};
|
|
31
|
+
type ErrorResponse = {
|
|
32
|
+
code: number;
|
|
33
|
+
message: string;
|
|
34
|
+
data?: unknown;
|
|
35
|
+
};
|
|
36
|
+
export declare class RequestError extends Error {
|
|
37
|
+
code: number;
|
|
38
|
+
data?: {
|
|
39
|
+
details?: string;
|
|
40
|
+
};
|
|
41
|
+
constructor(code: number, message: string, details?: string);
|
|
42
|
+
static parseError(details?: string): RequestError;
|
|
43
|
+
static invalidRequest(details?: string): RequestError;
|
|
44
|
+
static methodNotFound(details?: string): RequestError;
|
|
45
|
+
static invalidParams(details?: string): RequestError;
|
|
46
|
+
static internalError(details?: string): RequestError;
|
|
47
|
+
static authRequired(details?: string): RequestError;
|
|
48
|
+
toResult<T>(): Result<T>;
|
|
49
|
+
}
|
|
50
|
+
export interface Client {
|
|
51
|
+
requestPermission(params: schema.RequestPermissionRequest): Promise<schema.RequestPermissionResponse>;
|
|
52
|
+
sessionUpdate(params: schema.SessionNotification): Promise<void>;
|
|
53
|
+
writeTextFile(params: schema.WriteTextFileRequest): Promise<schema.WriteTextFileResponse>;
|
|
54
|
+
readTextFile(params: schema.ReadTextFileRequest): Promise<schema.ReadTextFileResponse>;
|
|
55
|
+
}
|
|
56
|
+
export interface Agent {
|
|
57
|
+
initialize(params: schema.InitializeRequest): Promise<schema.InitializeResponse>;
|
|
58
|
+
newSession(params: schema.NewSessionRequest): Promise<schema.NewSessionResponse>;
|
|
59
|
+
loadSession?(params: schema.LoadSessionRequest): Promise<schema.LoadSessionResponse>;
|
|
60
|
+
authenticate(params: schema.AuthenticateRequest): Promise<void>;
|
|
61
|
+
prompt(params: schema.PromptRequest): Promise<schema.PromptResponse>;
|
|
62
|
+
cancel(params: schema.CancelNotification): Promise<void>;
|
|
63
|
+
}
|
|
@@ -3,59 +3,82 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
/* ACP defines a schema for a simple (experimental) JSON-RPC protocol that allows GUI applications to interact with agents. */
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import * as schema from './schema.js';
|
|
9
|
+
export * from './schema.js';
|
|
10
|
+
export class AgentSideConnection {
|
|
7
11
|
#connection;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
12
|
+
constructor(toAgent, input, output) {
|
|
13
|
+
const agent = toAgent(this);
|
|
14
|
+
const handler = async (method, params) => {
|
|
15
|
+
switch (method) {
|
|
16
|
+
case schema.AGENT_METHODS.initialize: {
|
|
17
|
+
const validatedParams = schema.initializeRequestSchema.parse(params);
|
|
18
|
+
return agent.initialize(validatedParams);
|
|
19
|
+
}
|
|
20
|
+
case schema.AGENT_METHODS.session_new: {
|
|
21
|
+
const validatedParams = schema.newSessionRequestSchema.parse(params);
|
|
22
|
+
return agent.newSession(validatedParams);
|
|
23
|
+
}
|
|
24
|
+
case schema.AGENT_METHODS.session_load: {
|
|
25
|
+
if (!agent.loadSession) {
|
|
26
|
+
throw RequestError.methodNotFound();
|
|
27
|
+
}
|
|
28
|
+
const validatedParams = schema.loadSessionRequestSchema.parse(params);
|
|
29
|
+
return agent.loadSession(validatedParams);
|
|
30
|
+
}
|
|
31
|
+
case schema.AGENT_METHODS.authenticate: {
|
|
32
|
+
const validatedParams = schema.authenticateRequestSchema.parse(params);
|
|
33
|
+
return agent.authenticate(validatedParams);
|
|
34
|
+
}
|
|
35
|
+
case schema.AGENT_METHODS.session_prompt: {
|
|
36
|
+
const validatedParams = schema.promptRequestSchema.parse(params);
|
|
37
|
+
return agent.prompt(validatedParams);
|
|
38
|
+
}
|
|
39
|
+
case schema.AGENT_METHODS.session_cancel: {
|
|
40
|
+
const validatedParams = schema.cancelNotificationSchema.parse(params);
|
|
41
|
+
return agent.cancel(validatedParams);
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
throw RequestError.methodNotFound(method);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this.#connection = new Connection(handler, input, output);
|
|
10
48
|
}
|
|
11
49
|
/**
|
|
12
|
-
* Streams
|
|
50
|
+
* Streams new content to the client including text, tool calls, etc.
|
|
13
51
|
*/
|
|
14
|
-
async
|
|
15
|
-
await this.#connection.
|
|
52
|
+
async sessionUpdate(params) {
|
|
53
|
+
return await this.#connection.sendNotification(schema.CLIENT_METHODS.session_update, params);
|
|
16
54
|
}
|
|
17
55
|
/**
|
|
18
|
-
* Request
|
|
56
|
+
* Request permission before running a tool
|
|
19
57
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
58
|
+
* The agent specifies a series of permission options with different granularity,
|
|
59
|
+
* and the client returns the chosen one.
|
|
22
60
|
*/
|
|
23
|
-
|
|
24
|
-
return this.#connection.sendRequest(
|
|
61
|
+
async requestPermission(params) {
|
|
62
|
+
return await this.#connection.sendRequest(schema.CLIENT_METHODS.session_request_permission, params);
|
|
25
63
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* when it does not need to request permission to do so.
|
|
29
|
-
*
|
|
30
|
-
* The returned id can be used to update the UI for the tool
|
|
31
|
-
* call as needed.
|
|
32
|
-
*/
|
|
33
|
-
pushToolCall(params) {
|
|
34
|
-
return this.#connection.sendRequest('pushToolCall', params);
|
|
64
|
+
async readTextFile(params) {
|
|
65
|
+
return await this.#connection.sendRequest(schema.CLIENT_METHODS.fs_read_text_file, params);
|
|
35
66
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
* The new content replaces what is currently displayed in the UI.
|
|
40
|
-
*
|
|
41
|
-
* The [`ToolCallId`] is included in the response of
|
|
42
|
-
* `pushToolCall` or `requestToolCallConfirmation` respectively.
|
|
43
|
-
*/
|
|
44
|
-
async updateToolCall(params) {
|
|
45
|
-
await this.#connection.sendRequest('updateToolCall', params);
|
|
67
|
+
async writeTextFile(params) {
|
|
68
|
+
return await this.#connection.sendRequest(schema.CLIENT_METHODS.fs_write_text_file, params);
|
|
46
69
|
}
|
|
47
70
|
}
|
|
48
71
|
class Connection {
|
|
49
72
|
#pendingResponses = new Map();
|
|
50
73
|
#nextRequestId = 0;
|
|
51
|
-
#
|
|
74
|
+
#handler;
|
|
52
75
|
#peerInput;
|
|
53
76
|
#writeQueue = Promise.resolve();
|
|
54
77
|
#textEncoder;
|
|
55
|
-
constructor(
|
|
78
|
+
constructor(handler, peerInput, peerOutput) {
|
|
79
|
+
this.#handler = handler;
|
|
56
80
|
this.#peerInput = peerInput;
|
|
57
81
|
this.#textEncoder = new TextEncoder();
|
|
58
|
-
this.#delegate = delegate;
|
|
59
82
|
this.#receive(peerOutput);
|
|
60
83
|
}
|
|
61
84
|
async #receive(output) {
|
|
@@ -75,31 +98,36 @@ class Connection {
|
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
100
|
async #processMessage(message) {
|
|
78
|
-
if ('method' in message) {
|
|
79
|
-
|
|
101
|
+
if ('method' in message && 'id' in message) {
|
|
102
|
+
// It's a request
|
|
103
|
+
const response = await this.#tryCallHandler(message.method, message.params);
|
|
80
104
|
await this.#sendMessage({
|
|
81
105
|
jsonrpc: '2.0',
|
|
82
106
|
id: message.id,
|
|
83
107
|
...response,
|
|
84
108
|
});
|
|
85
109
|
}
|
|
86
|
-
else {
|
|
110
|
+
else if ('method' in message) {
|
|
111
|
+
// It's a notification
|
|
112
|
+
await this.#tryCallHandler(message.method, message.params);
|
|
113
|
+
}
|
|
114
|
+
else if ('id' in message) {
|
|
115
|
+
// It's a response
|
|
87
116
|
this.#handleResponse(message);
|
|
88
117
|
}
|
|
89
118
|
}
|
|
90
|
-
async #
|
|
91
|
-
const methodName = method;
|
|
92
|
-
if (typeof this.#delegate[methodName] !== 'function') {
|
|
93
|
-
return RequestError.methodNotFound(method).toResult();
|
|
94
|
-
}
|
|
119
|
+
async #tryCallHandler(method, params) {
|
|
95
120
|
try {
|
|
96
|
-
const result = await this.#
|
|
121
|
+
const result = await this.#handler(method, params);
|
|
97
122
|
return { result: result ?? null };
|
|
98
123
|
}
|
|
99
124
|
catch (error) {
|
|
100
125
|
if (error instanceof RequestError) {
|
|
101
126
|
return error.toResult();
|
|
102
127
|
}
|
|
128
|
+
if (error instanceof z.ZodError) {
|
|
129
|
+
return RequestError.invalidParams(JSON.stringify(error.format(), undefined, 2)).toResult();
|
|
130
|
+
}
|
|
103
131
|
let details;
|
|
104
132
|
if (error instanceof Error) {
|
|
105
133
|
details = error.message;
|
|
@@ -133,6 +161,9 @@ class Connection {
|
|
|
133
161
|
await this.#sendMessage({ jsonrpc: '2.0', id, method, params });
|
|
134
162
|
return responsePromise;
|
|
135
163
|
}
|
|
164
|
+
async sendNotification(method, params) {
|
|
165
|
+
await this.#sendMessage({ jsonrpc: '2.0', method, params });
|
|
166
|
+
}
|
|
136
167
|
async #sendMessage(json) {
|
|
137
168
|
const content = JSON.stringify(json) + '\n';
|
|
138
169
|
this.#writeQueue = this.#writeQueue
|
|
@@ -178,6 +209,9 @@ export class RequestError extends Error {
|
|
|
178
209
|
static internalError(details) {
|
|
179
210
|
return new RequestError(-32603, 'Internal error', details);
|
|
180
211
|
}
|
|
212
|
+
static authRequired(details) {
|
|
213
|
+
return new RequestError(-32000, 'Authentication required', details);
|
|
214
|
+
}
|
|
181
215
|
toResult() {
|
|
182
216
|
return {
|
|
183
217
|
error: {
|
|
@@ -188,6 +222,4 @@ export class RequestError extends Error {
|
|
|
188
222
|
};
|
|
189
223
|
}
|
|
190
224
|
}
|
|
191
|
-
// Protocol types
|
|
192
|
-
export const LATEST_PROTOCOL_VERSION = '0.0.9';
|
|
193
225
|
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../../../src/zed-integration/acp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,8HAA8H;AAE9H,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,cAAc,aAAa,CAA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