@mmmbuto/gemini-cli-termux 0.22.6-termux → 0.24.0-termux

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 (104) hide show
  1. package/README.md +24 -21
  2. package/bundle/README.md +239 -0
  3. package/bundle/docs/TERMUX.md +97 -0
  4. package/bundle/docs/architecture.md +80 -0
  5. package/bundle/docs/assets/connected_devtools.png +0 -0
  6. package/bundle/docs/assets/gemini-screenshot.png +0 -0
  7. package/bundle/docs/assets/release_patch.png +0 -0
  8. package/bundle/docs/assets/theme-ansi-light.png +0 -0
  9. package/bundle/docs/assets/theme-ansi.png +0 -0
  10. package/bundle/docs/assets/theme-atom-one.png +0 -0
  11. package/bundle/docs/assets/theme-ayu-light.png +0 -0
  12. package/bundle/docs/assets/theme-ayu.png +0 -0
  13. package/bundle/docs/assets/theme-custom.png +0 -0
  14. package/bundle/docs/assets/theme-default-light.png +0 -0
  15. package/bundle/docs/assets/theme-default.png +0 -0
  16. package/bundle/docs/assets/theme-dracula.png +0 -0
  17. package/bundle/docs/assets/theme-github-light.png +0 -0
  18. package/bundle/docs/assets/theme-github.png +0 -0
  19. package/bundle/docs/assets/theme-google-light.png +0 -0
  20. package/bundle/docs/assets/theme-xcode-light.png +0 -0
  21. package/bundle/docs/changelogs/index.md +592 -0
  22. package/bundle/docs/changelogs/latest.md +225 -0
  23. package/bundle/docs/changelogs/preview.md +129 -0
  24. package/bundle/docs/changelogs/releases.md +896 -0
  25. package/bundle/docs/cli/authentication.md +3 -0
  26. package/bundle/docs/cli/checkpointing.md +94 -0
  27. package/bundle/docs/cli/commands.md +354 -0
  28. package/bundle/docs/cli/configuration.md +792 -0
  29. package/bundle/docs/cli/context-memory.md +69 -0
  30. package/bundle/docs/cli/custom-commands.md +315 -0
  31. package/bundle/docs/cli/enterprise.md +565 -0
  32. package/bundle/docs/cli/gemini-ignore.md +71 -0
  33. package/bundle/docs/cli/gemini-md.md +108 -0
  34. package/bundle/docs/cli/generation-settings.md +210 -0
  35. package/bundle/docs/cli/headless.md +388 -0
  36. package/bundle/docs/cli/index.md +63 -0
  37. package/bundle/docs/cli/keyboard-shortcuts.md +143 -0
  38. package/bundle/docs/cli/model-routing.md +37 -0
  39. package/bundle/docs/cli/model.md +62 -0
  40. package/bundle/docs/cli/sandbox.md +171 -0
  41. package/bundle/docs/cli/session-management.md +158 -0
  42. package/bundle/docs/cli/settings.md +114 -0
  43. package/bundle/docs/cli/system-prompt.md +93 -0
  44. package/bundle/docs/cli/telemetry.md +791 -0
  45. package/bundle/docs/cli/themes.md +237 -0
  46. package/bundle/docs/cli/token-caching.md +20 -0
  47. package/bundle/docs/cli/trusted-folders.md +95 -0
  48. package/bundle/docs/cli/tutorials.md +83 -0
  49. package/bundle/docs/cli/uninstall.md +47 -0
  50. package/bundle/docs/core/index.md +101 -0
  51. package/bundle/docs/core/memport.md +244 -0
  52. package/bundle/docs/core/policy-engine.md +267 -0
  53. package/bundle/docs/core/tools-api.md +131 -0
  54. package/bundle/docs/examples/proxy-script.md +83 -0
  55. package/bundle/docs/extensions/extension-releasing.md +183 -0
  56. package/bundle/docs/extensions/getting-started-extensions.md +245 -0
  57. package/bundle/docs/extensions/index.md +293 -0
  58. package/bundle/docs/faq.md +154 -0
  59. package/bundle/docs/get-started/authentication.md +321 -0
  60. package/bundle/docs/get-started/configuration-v1.md +888 -0
  61. package/bundle/docs/get-started/configuration.md +1511 -0
  62. package/bundle/docs/get-started/deployment.md +143 -0
  63. package/bundle/docs/get-started/examples.md +219 -0
  64. package/bundle/docs/get-started/gemini-3.md +116 -0
  65. package/bundle/docs/get-started/index.md +71 -0
  66. package/bundle/docs/get-started/installation.md +141 -0
  67. package/bundle/docs/hooks/best-practices.md +806 -0
  68. package/bundle/docs/hooks/index.md +665 -0
  69. package/bundle/docs/hooks/reference.md +168 -0
  70. package/bundle/docs/hooks/writing-hooks.md +1026 -0
  71. package/bundle/docs/ide-integration/ide-companion-spec.md +267 -0
  72. package/bundle/docs/ide-integration/index.md +202 -0
  73. package/bundle/docs/index.md +147 -0
  74. package/bundle/docs/integration-tests.md +211 -0
  75. package/bundle/docs/issue-and-pr-automation.md +134 -0
  76. package/bundle/docs/local-development.md +128 -0
  77. package/bundle/docs/mermaid/context.mmd +103 -0
  78. package/bundle/docs/mermaid/render-path.mmd +64 -0
  79. package/bundle/docs/npm.md +62 -0
  80. package/bundle/docs/patches/CONTEXT_MEMORY_COMPARISON.md +306 -0
  81. package/bundle/docs/patches/MERGE_TO_0.24_ANALYSIS.md +321 -0
  82. package/bundle/docs/patches/README.md +62 -0
  83. package/bundle/docs/quota-and-pricing.md +158 -0
  84. package/bundle/docs/release-confidence.md +164 -0
  85. package/bundle/docs/releases.md +540 -0
  86. package/bundle/docs/sidebar.json +297 -0
  87. package/bundle/docs/termux-api/COMMANDS.md +592 -0
  88. package/bundle/docs/termux-api/DISCOVERY_SETUP.md +670 -0
  89. package/bundle/docs/termux-api/EXECUTION_PLAN.md +532 -0
  90. package/bundle/docs/termux-api/MERGE_STRATEGY.md +325 -0
  91. package/bundle/docs/termux-api/PATCHES.md +483 -0
  92. package/bundle/docs/termux-api/README.md +416 -0
  93. package/bundle/docs/tools/file-system.md +217 -0
  94. package/bundle/docs/tools/index.md +95 -0
  95. package/bundle/docs/tools/mcp-server.md +1044 -0
  96. package/bundle/docs/tools/memory.md +54 -0
  97. package/bundle/docs/tools/shell.md +260 -0
  98. package/bundle/docs/tools/todos.md +57 -0
  99. package/bundle/docs/tools/web-fetch.md +59 -0
  100. package/bundle/docs/tools/web-search.md +42 -0
  101. package/bundle/docs/tos-privacy.md +96 -0
  102. package/bundle/docs/troubleshooting.md +158 -0
  103. package/bundle/gemini.js +35198 -32245
  104. package/package.json +10 -8
@@ -0,0 +1,416 @@
1
+ # Termux-API Integration Plan
2
+
3
+ **Project**: gemini-cli-termux **Version**: 0.22.0-termux **Author**: DioNanos
4
+ **Date**: 2025-12-17 **Status**: Planning Phase
5
+
6
+ ---
7
+
8
+ ## Executive Summary
9
+
10
+ This document describes the plan to integrate native Termux-API commands into
11
+ the `gemini-cli-termux` fork, allowing Gemini CLI to leverage Android hardware
12
+ and software APIs through Termux.
13
+
14
+ ## Table of Contents
15
+
16
+ 1. [Current Architecture](#current-architecture)
17
+ 2. [Termux-API Commands](#termux-api-commands)
18
+ 3. [Integration Approaches](#integration-approaches)
19
+ 4. [Recommendation](#recommendation)
20
+ 5. [Implementation Roadmap](#implementation-roadmap)
21
+ 6. [Reference Files](#reference-files)
22
+
23
+ ---
24
+
25
+ ## Current Architecture
26
+
27
+ ### Monorepo Structure
28
+
29
+ ```
30
+ gemini-cli-termux/
31
+ ├── packages/
32
+ │ ├── core/ # Logic core, tools, config
33
+ │ │ └── src/
34
+ │ │ ├── tools/ # Tool implementations
35
+ │ │ ├── mcp/ # MCP support
36
+ │ │ └── config/ # Configuration
37
+ │ ├── cli/ # CLI interface
38
+ │ ├── a2a-server/ # Agent-to-Agent server
39
+ │ └── vscode-ide-companion/
40
+ └── bundle/ # Built executable
41
+ ```
42
+
43
+ ### Tool System
44
+
45
+ Tools in Gemini CLI follow a well-defined pattern:
46
+
47
+ 1. **BaseDeclarativeTool**: Base class for defining tools
48
+ 2. **BaseToolInvocation**: Class for tool execution
49
+ 3. **ToolRegistry**: Registers and manages all tools
50
+
51
+ **Key files**:
52
+
53
+ - `packages/core/src/tools/tools.ts` - Interfaces and base classes
54
+ - `packages/core/src/tools/tool-registry.ts` - Tool registry
55
+ - `packages/core/src/tools/shell.ts` - Example: ShellTool
56
+
57
+ ### Tool Call Flow
58
+
59
+ ```
60
+ LLM → ToolRegistry.getTool() → DeclarativeTool.build() → ToolInvocation.execute()
61
+ ```
62
+
63
+ ### Discovery Mechanisms
64
+
65
+ 1. **Built-in Tools**: Manually registered in the registry
66
+ 2. **Discovered Tools**: Via `tool_discovery_command` in config
67
+ 3. **MCP Tools**: Via Model Context Protocol servers
68
+
69
+ ---
70
+
71
+ ## Termux-API Commands
72
+
73
+ ### Categorization by Functionality
74
+
75
+ | Category | Commands | Complexity |
76
+ | ------------------ | -------------------------------------------------------------------------------------------------------- | --------------- |
77
+ | **System Info** | battery-status, audio-info, wifi-connectioninfo, wifi-scaninfo, telephony-deviceinfo, telephony-cellinfo | Low |
78
+ | **Notifications** | notification, notification-remove, notification-list, toast | Low |
79
+ | **Clipboard** | clipboard-get, clipboard-set | Low |
80
+ | **Media** | camera-photo, camera-info, microphone-record, media-player, media-scan, tts-speak, speech-to-text | Medium |
81
+ | **Location** | location | Medium |
82
+ | **Sensors** | sensor, infrared-frequencies, infrared-transmit, torch, vibrate, brightness | Medium |
83
+ | **Communication** | sms-send, sms-inbox, sms-list, telephony-call, call-log, contact-list | High (privacy) |
84
+ | **Storage** | storage-get, download, share, open, open-url, saf-\* | Medium |
85
+ | **Security** | fingerprint, keystore | High (security) |
86
+ | **System Control** | volume, wake-lock, wake-unlock, wallpaper, wifi-enable | Medium |
87
+ | **Dialogs** | dialog | Medium |
88
+ | **NFC** | nfc | High |
89
+ | **USB** | usb | High |
90
+ | **Job Scheduler** | job-scheduler | Medium |
91
+
92
+ ### Priority Commands (Phase 1)
93
+
94
+ 1. **termux-battery-status** - Battery info (JSON output)
95
+ 2. **termux-clipboard-get/set** - Clipboard operations
96
+ 3. **termux-toast** - Toast notifications
97
+ 4. **termux-notification** - Persistent notifications
98
+ 5. **termux-tts-speak** - Text-to-Speech
99
+ 6. **termux-vibrate** - Haptic feedback
100
+ 7. **termux-torch** - Flashlight control
101
+ 8. **termux-location** - GPS location
102
+ 9. **termux-wifi-connectioninfo** - Network info
103
+ 10. **termux-audio-info** - Audio info
104
+
105
+ ---
106
+
107
+ ## Integration Approaches
108
+
109
+ ### Approach A: Native Dedicated Tools
110
+
111
+ **Description**: Create dedicated TypeScript classes for each category of Termux
112
+ commands.
113
+
114
+ **Proposed Structure**:
115
+
116
+ ```
117
+ packages/core/src/tools/termux/
118
+ ├── index.ts
119
+ ├── termux-base.ts
120
+ ├── termux-system.ts # battery, wifi, audio, telephony
121
+ ├── termux-notification.ts # toast, notification
122
+ ├── termux-clipboard.ts # clipboard operations
123
+ ├── termux-media.ts # camera, microphone, tts, speech
124
+ ├── termux-location.ts # GPS
125
+ ├── termux-sensors.ts # sensor, torch, vibrate
126
+ └── termux-storage.ts # download, share, open
127
+ ```
128
+
129
+ **Pros**:
130
+
131
+ - Deep integration with Gemini
132
+ - Type-safe parameter validation
133
+ - LLM-optimized descriptions
134
+ - Specific error handling
135
+ - Granular user confirmation
136
+
137
+ **Cons**:
138
+
139
+ - Much code to write (~50 tools)
140
+ - Ongoing maintenance
141
+ - Strong coupling
142
+
143
+ **Estimated Effort**: High (2-3 weeks)
144
+
145
+ ---
146
+
147
+ ### Approach B: MCP Server for Termux-API
148
+
149
+ **Description**: Create a standalone MCP server that exposes all Termux commands
150
+ as MCP tools.
151
+
152
+ **Proposed Structure**:
153
+
154
+ ```
155
+ termux-mcp-server/
156
+ ├── package.json
157
+ ├── src/
158
+ │ ├── index.ts # MCP server entry
159
+ │ ├── tools/ # Tool definitions
160
+ │ └── utils/ # Helper functions
161
+ └── README.md
162
+ ```
163
+
164
+ **Configuration**:
165
+
166
+ ```json
167
+ // settings.json
168
+ {
169
+ "mcpServers": {
170
+ "termux": {
171
+ "command": "npx",
172
+ "args": ["@mmmbuto/termux-mcp-server"]
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ **Pros**:
179
+
180
+ - Reusable with other MCP clients
181
+ - Separation of concerns
182
+ - Easy to update independently
183
+ - Widely supported MCP standard
184
+ - Publishable to npm separately
185
+
186
+ **Cons**:
187
+
188
+ - Communication overhead
189
+ - Separate process dependency
190
+ - More complex debugging
191
+
192
+ **Estimated Effort**: Medium (1-2 weeks)
193
+
194
+ ---
195
+
196
+ ### Approach C: Tool Discovery Script
197
+
198
+ **Description**: Create a script that generates FunctionDeclarations for Termux
199
+ commands, leveraging the existing tool discovery mechanism.
200
+
201
+ **Implementation**:
202
+
203
+ ```bash
204
+ # termux-tool-discovery.sh
205
+ #!/bin/bash
206
+ cat << 'EOF'
207
+ [
208
+ {
209
+ "name": "termux_battery_status",
210
+ "description": "Get battery status including percentage, health, and charging state",
211
+ "parametersJsonSchema": {
212
+ "type": "object",
213
+ "properties": {}
214
+ }
215
+ },
216
+ ...
217
+ ]
218
+ EOF
219
+ ```
220
+
221
+ **Configuration**:
222
+
223
+ ```json
224
+ // settings.json
225
+ {
226
+ "tool_discovery_command": "bash ~/.config/gemini/termux-tool-discovery.sh",
227
+ "tool_call_command": "bash ~/.config/gemini/termux-tool-call.sh"
228
+ }
229
+ ```
230
+
231
+ **Pros**:
232
+
233
+ - Leverages existing infrastructure
234
+ - Zero core modifications
235
+ - User configurable
236
+ - Easy to extend
237
+
238
+ **Cons**:
239
+
240
+ - Less control over validation
241
+ - Depends on external scripts
242
+ - Limited error handling
243
+
244
+ **Estimated Effort**: Low (3-5 days)
245
+
246
+ ---
247
+
248
+ ### Approach D: Shell Allowlist Extension
249
+
250
+ **Description**: Extend shell permissions to auto-approve `termux-*` commands.
251
+
252
+ **Implementation**:
253
+
254
+ ```typescript
255
+ // packages/core/src/utils/shell-permissions.ts
256
+ const TERMUX_COMMANDS = [
257
+ 'termux-battery-status',
258
+ 'termux-clipboard-get',
259
+ 'termux-clipboard-set',
260
+ // ...
261
+ ];
262
+
263
+ export function isTermuxCommand(command: string): boolean {
264
+ return TERMUX_COMMANDS.some((tc) => command.startsWith(tc));
265
+ }
266
+ ```
267
+
268
+ **Pros**:
269
+
270
+ - Minimal code impact
271
+ - Uses existing ShellTool
272
+ - Quick win
273
+
274
+ **Cons**:
275
+
276
+ - No additional semantics
277
+ - LLM must know the syntax
278
+ - No parameter validation
279
+ - No description for LLM
280
+
281
+ **Estimated Effort**: Minimal (1-2 days)
282
+
283
+ ---
284
+
285
+ ### Approach E: Hybrid (Recommended)
286
+
287
+ **Description**: Combine approaches B and C for maximum flexibility.
288
+
289
+ **Phase 1**: Tool Discovery Script (quick win)
290
+
291
+ - Generates declarations for all commands
292
+ - Allows Gemini to use Termux immediately
293
+
294
+ **Phase 2**: MCP Server (production)
295
+
296
+ - Implements complete MCP server
297
+ - Robust validation
298
+ - Publishable to npm
299
+
300
+ **Phase 3**: Native Tools (optional)
301
+
302
+ - Only for critical/frequent commands
303
+ - Optimized integration
304
+
305
+ ---
306
+
307
+ ## Recommendation
308
+
309
+ **Recommended Approach: E (Hybrid)**
310
+
311
+ ### Rationale
312
+
313
+ 1. **Quick Win**: Tool Discovery allows starting immediately
314
+ 2. **Scalability**: MCP Server is the standard for extensions
315
+ 3. **Flexibility**: Native tools only where needed
316
+ 4. **Maintainability**: Each phase can be developed independently
317
+
318
+ ### Implementation Priority
319
+
320
+ | Phase | Approach | Commands | Priority |
321
+ | ----- | ---------------- | ------------------------------- | -------- |
322
+ | 1 | Discovery Script | All | High |
323
+ | 2 | MCP Server | System, Clipboard, Notification | Medium |
324
+ | 3 | Native Tools | TTS, Location | Low |
325
+
326
+ ---
327
+
328
+ ## Implementation Roadmap
329
+
330
+ ### Phase 1: Tool Discovery (Quick Win)
331
+
332
+ **Files to create**:
333
+
334
+ - `scripts/termux-tool-discovery.sh`
335
+ - `scripts/termux-tool-call.sh`
336
+ - `docs/termux-api/DISCOVERY_SETUP.md`
337
+
338
+ **Tasks**:
339
+
340
+ 1. [ ] Create discovery script with all FunctionDeclarations
341
+ 2. [ ] Create call script with command dispatch
342
+ 3. [ ] Document user configuration
343
+ 4. [ ] Test on Termux
344
+ 5. [ ] Update README
345
+
346
+ ### Phase 2: MCP Server
347
+
348
+ **Files to create**:
349
+
350
+ - New package `packages/termux-mcp/`
351
+ - Or separate repository `termux-mcp-server`
352
+
353
+ **Tasks**:
354
+
355
+ 1. [ ] Scaffold MCP server
356
+ 2. [ ] Implement System tools (battery, wifi, audio)
357
+ 3. [ ] Implement Clipboard tools
358
+ 4. [ ] Implement Notification tools
359
+ 5. [ ] Implement Media tools
360
+ 6. [ ] Test integration
361
+ 7. [ ] Publish to npm
362
+
363
+ ### Phase 3: Native Tools (Optional)
364
+
365
+ **Files to modify**:
366
+
367
+ - `packages/core/src/tools/` - New tool files
368
+ - `packages/core/src/index.ts` - Export tools
369
+
370
+ **Tasks**:
371
+
372
+ 1. [ ] Implement TermuxTTSTool
373
+ 2. [ ] Implement TermuxLocationTool
374
+ 3. [ ] Implement TermuxClipboardTool
375
+ 4. [ ] Register tools in registry
376
+ 5. [ ] Test and documentation
377
+
378
+ ---
379
+
380
+ ## Reference Files
381
+
382
+ ### Core Architecture
383
+
384
+ | File | Description |
385
+ | ------------------------------------------ | ---------------------- |
386
+ | `packages/core/src/tools/tools.ts` | Base tool interfaces |
387
+ | `packages/core/src/tools/tool-registry.ts` | Registry and discovery |
388
+ | `packages/core/src/tools/shell.ts` | Example ShellTool |
389
+ | `packages/core/src/tools/mcp-tool.ts` | MCP tool wrapper |
390
+ | `packages/core/src/tools/mcp-client.ts` | MCP client |
391
+
392
+ ### Configuration
393
+
394
+ | File | Description |
395
+ | -------------------------------------- | --------------- |
396
+ | `packages/core/src/config/config.ts` | Config loader |
397
+ | `packages/core/src/config/settings.ts` | Settings schema |
398
+
399
+ ### Existing Documentation
400
+
401
+ | File | Description |
402
+ | ---------------- | ---------------- |
403
+ | `docs/TERMUX.md` | Setup Termux |
404
+ | `README.md` | Project Overview |
405
+
406
+ ---
407
+
408
+ ## Appendices
409
+
410
+ - [COMMANDS.md](./COMMANDS.md) - Termux-API commands detail
411
+ - [DISCOVERY_SETUP.md](./DISCOVERY_SETUP.md) - Tool Discovery setup guide
412
+ - [MCP_SERVER.md](./MCP_SERVER.md) - MCP Server specifications
413
+
414
+ ---
415
+
416
+ _Author: DioNanos_
@@ -0,0 +1,217 @@
1
+ # Gemini CLI file system tools
2
+
3
+ The Gemini CLI provides a comprehensive suite of tools for interacting with the
4
+ local file system. These tools allow the Gemini model to read from, write to,
5
+ list, search, and modify files and directories, all under your control and
6
+ typically with confirmation for sensitive operations.
7
+
8
+ **Note:** All file system tools operate within a `rootDirectory` (usually the
9
+ current working directory where you launched the CLI) for security. Paths that
10
+ you provide to these tools are generally expected to be absolute or are resolved
11
+ relative to this root directory.
12
+
13
+ ## 1. `list_directory` (ReadFolder)
14
+
15
+ `list_directory` lists the names of files and subdirectories directly within a
16
+ specified directory path. It can optionally ignore entries matching provided
17
+ glob patterns.
18
+
19
+ - **Tool name:** `list_directory`
20
+ - **Display name:** ReadFolder
21
+ - **File:** `ls.ts`
22
+ - **Parameters:**
23
+ - `path` (string, required): The absolute path to the directory to list.
24
+ - `ignore` (array of strings, optional): A list of glob patterns to exclude
25
+ from the listing (e.g., `["*.log", ".git"]`).
26
+ - `respect_git_ignore` (boolean, optional): Whether to respect `.gitignore`
27
+ patterns when listing files. Defaults to `true`.
28
+ - **Behavior:**
29
+ - Returns a list of file and directory names.
30
+ - Indicates whether each entry is a directory.
31
+ - Sorts entries with directories first, then alphabetically.
32
+ - **Output (`llmContent`):** A string like:
33
+ `Directory listing for /path/to/your/folder:\n[DIR] subfolder1\nfile1.txt\nfile2.png`
34
+ - **Confirmation:** No.
35
+
36
+ ## 2. `read_file` (ReadFile)
37
+
38
+ `read_file` reads and returns the content of a specified file. This tool handles
39
+ text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC,
40
+ OGG, FLAC), and PDF files. For text files, it can read specific line ranges.
41
+ Other binary file types are generally skipped.
42
+
43
+ - **Tool name:** `read_file`
44
+ - **Display name:** ReadFile
45
+ - **File:** `read-file.ts`
46
+ - **Parameters:**
47
+ - `path` (string, required): The absolute path to the file to read.
48
+ - `offset` (number, optional): For text files, the 0-based line number to
49
+ start reading from. Requires `limit` to be set.
50
+ - `limit` (number, optional): For text files, the maximum number of lines to
51
+ read. If omitted, reads a default maximum (e.g., 2000 lines) or the entire
52
+ file if feasible.
53
+ - **Behavior:**
54
+ - For text files: Returns the content. If `offset` and `limit` are used,
55
+ returns only that slice of lines. Indicates if content was truncated due to
56
+ line limits or line length limits.
57
+ - For image, audio, and PDF files: Returns the file content as a
58
+ base64-encoded data structure suitable for model consumption.
59
+ - For other binary files: Attempts to identify and skip them, returning a
60
+ message indicating it's a generic binary file.
61
+ - **Output:** (`llmContent`):
62
+ - For text files: The file content, potentially prefixed with a truncation
63
+ message (e.g.,
64
+ `[File content truncated: showing lines 1-100 of 500 total lines...]\nActual file content...`).
65
+ - For image/audio/PDF files: An object containing `inlineData` with `mimeType`
66
+ and base64 `data` (e.g.,
67
+ `{ inlineData: { mimeType: 'image/png', data: 'base64encodedstring' } }`).
68
+ - For other binary files: A message like
69
+ `Cannot display content of binary file: /path/to/data.bin`.
70
+ - **Confirmation:** No.
71
+
72
+ ## 3. `write_file` (WriteFile)
73
+
74
+ `write_file` writes content to a specified file. If the file exists, it will be
75
+ overwritten. If the file doesn't exist, it (and any necessary parent
76
+ directories) will be created.
77
+
78
+ - **Tool name:** `write_file`
79
+ - **Display name:** WriteFile
80
+ - **File:** `write-file.ts`
81
+ - **Parameters:**
82
+ - `file_path` (string, required): The absolute path to the file to write to.
83
+ - `content` (string, required): The content to write into the file.
84
+ - **Behavior:**
85
+ - Writes the provided `content` to the `file_path`.
86
+ - Creates parent directories if they don't exist.
87
+ - **Output (`llmContent`):** A success message, e.g.,
88
+ `Successfully overwrote file: /path/to/your/file.txt` or
89
+ `Successfully created and wrote to new file: /path/to/new/file.txt`.
90
+ - **Confirmation:** Yes. Shows a diff of changes and asks for user approval
91
+ before writing.
92
+
93
+ ## 4. `glob` (FindFiles)
94
+
95
+ `glob` finds files matching specific glob patterns (e.g., `src/**/*.ts`,
96
+ `*.md`), returning absolute paths sorted by modification time (newest first).
97
+
98
+ - **Tool name:** `glob`
99
+ - **Display name:** FindFiles
100
+ - **File:** `glob.ts`
101
+ - **Parameters:**
102
+ - `pattern` (string, required): The glob pattern to match against (e.g.,
103
+ `"*.py"`, `"src/**/*.js"`).
104
+ - `path` (string, optional): The absolute path to the directory to search
105
+ within. If omitted, searches the tool's root directory.
106
+ - `case_sensitive` (boolean, optional): Whether the search should be
107
+ case-sensitive. Defaults to `false`.
108
+ - `respect_git_ignore` (boolean, optional): Whether to respect .gitignore
109
+ patterns when finding files. Defaults to `true`.
110
+ - **Behavior:**
111
+ - Searches for files matching the glob pattern within the specified directory.
112
+ - Returns a list of absolute paths, sorted with the most recently modified
113
+ files first.
114
+ - Ignores common nuisance directories like `node_modules` and `.git` by
115
+ default.
116
+ - **Output (`llmContent`):** A message like:
117
+ `Found 5 file(s) matching "*.ts" within src, sorted by modification time (newest first):\nsrc/file1.ts\nsrc/subdir/file2.ts...`
118
+ - **Confirmation:** No.
119
+
120
+ ## 5. `search_file_content` (SearchText)
121
+
122
+ `search_file_content` searches for a regular expression pattern within the
123
+ content of files in a specified directory. Can filter files by a glob pattern.
124
+ Returns the lines containing matches, along with their file paths and line
125
+ numbers.
126
+
127
+ - **Tool name:** `search_file_content`
128
+ - **Display name:** SearchText
129
+ - **File:** `grep.ts`
130
+ - **Parameters:**
131
+ - `pattern` (string, required): The regular expression (regex) to search for
132
+ (e.g., `"function\s+myFunction"`).
133
+ - `path` (string, optional): The absolute path to the directory to search
134
+ within. Defaults to the current working directory.
135
+ - `include` (string, optional): A glob pattern to filter which files are
136
+ searched (e.g., `"*.js"`, `"src/**/*.{ts,tsx}"`). If omitted, searches most
137
+ files (respecting common ignores).
138
+ - **Behavior:**
139
+ - Uses `git grep` if available in a Git repository for speed; otherwise, falls
140
+ back to system `grep` or a JavaScript-based search.
141
+ - Returns a list of matching lines, each prefixed with its file path (relative
142
+ to the search directory) and line number.
143
+ - **Output (`llmContent`):** A formatted string of matches, e.g.:
144
+ ```
145
+ Found 3 matches for pattern "myFunction" in path "." (filter: "*.ts"):
146
+ ---
147
+ File: src/utils.ts
148
+ L15: export function myFunction() {
149
+ L22: myFunction.call();
150
+ ---
151
+ File: src/index.ts
152
+ L5: import { myFunction } from './utils';
153
+ ---
154
+ ```
155
+ - **Confirmation:** No.
156
+
157
+ ## 6. `replace` (Edit)
158
+
159
+ `replace` replaces text within a file. By default, replaces a single occurrence,
160
+ but can replace multiple occurrences when `expected_replacements` is specified.
161
+ This tool is designed for precise, targeted changes and requires significant
162
+ context around the `old_string` to ensure it modifies the correct location.
163
+
164
+ - **Tool name:** `replace`
165
+ - **Display name:** Edit
166
+ - **File:** `edit.ts`
167
+ - **Parameters:**
168
+ - `file_path` (string, required): The absolute path to the file to modify.
169
+ - `old_string` (string, required): The exact literal text to replace.
170
+
171
+ **CRITICAL:** This string must uniquely identify the single instance to
172
+ change. It should include at least 3 lines of context _before_ and _after_
173
+ the target text, matching whitespace and indentation precisely. If
174
+ `old_string` is empty, the tool attempts to create a new file at `file_path`
175
+ with `new_string` as content.
176
+
177
+ - `new_string` (string, required): The exact literal text to replace
178
+ `old_string` with.
179
+ - `expected_replacements` (number, optional): The number of occurrences to
180
+ replace. Defaults to `1`.
181
+
182
+ - **Behavior:**
183
+ - If `old_string` is empty and `file_path` does not exist, creates a new file
184
+ with `new_string` as content.
185
+ - If `old_string` is provided, it reads the `file_path` and attempts to find
186
+ exactly one occurrence of `old_string`.
187
+ - If one occurrence is found, it replaces it with `new_string`.
188
+ - **Enhanced reliability (multi-stage edit correction):** To significantly
189
+ improve the success rate of edits, especially when the model-provided
190
+ `old_string` might not be perfectly precise, the tool incorporates a
191
+ multi-stage edit correction mechanism.
192
+ - If the initial `old_string` isn't found or matches multiple locations, the
193
+ tool can leverage the Gemini model to iteratively refine `old_string` (and
194
+ potentially `new_string`).
195
+ - This self-correction process attempts to identify the unique segment the
196
+ model intended to modify, making the `replace` operation more robust even
197
+ with slightly imperfect initial context.
198
+ - **Failure conditions:** Despite the correction mechanism, the tool will fail
199
+ if:
200
+ - `file_path` is not absolute or is outside the root directory.
201
+ - `old_string` is not empty, but the `file_path` does not exist.
202
+ - `old_string` is empty, but the `file_path` already exists.
203
+ - `old_string` is not found in the file after attempts to correct it.
204
+ - `old_string` is found multiple times, and the self-correction mechanism
205
+ cannot resolve it to a single, unambiguous match.
206
+ - **Output (`llmContent`):**
207
+ - On success:
208
+ `Successfully modified file: /path/to/file.txt (1 replacements).` or
209
+ `Created new file: /path/to/new_file.txt with provided content.`
210
+ - On failure: An error message explaining the reason (e.g.,
211
+ `Failed to edit, 0 occurrences found...`,
212
+ `Failed to edit, expected 1 occurrences but found 2...`).
213
+ - **Confirmation:** Yes. Shows a diff of the proposed changes and asks for user
214
+ approval before writing to the file.
215
+
216
+ These file system tools provide a foundation for the Gemini CLI to understand
217
+ and interact with your local project context.