@codeflyai/codefly 0.24.0
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/LICENSE +202 -0
- package/README.md +375 -0
- package/bundle/codefly.js +486433 -0
- package/bundle/docs/architecture.md +80 -0
- package/bundle/docs/assets/connected_devtools.png +0 -0
- package/bundle/docs/assets/gemini-screenshot.png +0 -0
- package/bundle/docs/assets/release_patch.png +0 -0
- package/bundle/docs/assets/theme-ansi-light.png +0 -0
- package/bundle/docs/assets/theme-ansi.png +0 -0
- package/bundle/docs/assets/theme-atom-one.png +0 -0
- package/bundle/docs/assets/theme-ayu-light.png +0 -0
- package/bundle/docs/assets/theme-ayu.png +0 -0
- package/bundle/docs/assets/theme-custom.png +0 -0
- package/bundle/docs/assets/theme-default-light.png +0 -0
- package/bundle/docs/assets/theme-default.png +0 -0
- package/bundle/docs/assets/theme-dracula.png +0 -0
- package/bundle/docs/assets/theme-github-light.png +0 -0
- package/bundle/docs/assets/theme-github.png +0 -0
- package/bundle/docs/assets/theme-google-light.png +0 -0
- package/bundle/docs/assets/theme-xcode-light.png +0 -0
- package/bundle/docs/changelogs/index.md +592 -0
- package/bundle/docs/changelogs/latest.md +225 -0
- package/bundle/docs/changelogs/preview.md +129 -0
- package/bundle/docs/changelogs/releases.md +896 -0
- package/bundle/docs/cli/authentication.md +3 -0
- package/bundle/docs/cli/checkpointing.md +94 -0
- package/bundle/docs/cli/codefly-ignore.md +71 -0
- package/bundle/docs/cli/codefly-md.md +109 -0
- package/bundle/docs/cli/commands.md +354 -0
- package/bundle/docs/cli/configuration.md +780 -0
- package/bundle/docs/cli/custom-commands.md +315 -0
- package/bundle/docs/cli/enterprise.md +565 -0
- package/bundle/docs/cli/generation-settings.md +210 -0
- package/bundle/docs/cli/headless.md +388 -0
- package/bundle/docs/cli/index.md +63 -0
- package/bundle/docs/cli/keyboard-shortcuts.md +143 -0
- package/bundle/docs/cli/model-routing.md +37 -0
- package/bundle/docs/cli/model.md +62 -0
- package/bundle/docs/cli/sandbox.md +171 -0
- package/bundle/docs/cli/session-management.md +158 -0
- package/bundle/docs/cli/settings.md +113 -0
- package/bundle/docs/cli/system-prompt.md +95 -0
- package/bundle/docs/cli/telemetry.md +792 -0
- package/bundle/docs/cli/themes.md +237 -0
- package/bundle/docs/cli/token-caching.md +20 -0
- package/bundle/docs/cli/trusted-folders.md +95 -0
- package/bundle/docs/cli/tutorials.md +83 -0
- package/bundle/docs/cli/uninstall.md +47 -0
- package/bundle/docs/core/index.md +101 -0
- package/bundle/docs/core/memport.md +244 -0
- package/bundle/docs/core/policy-engine.md +267 -0
- package/bundle/docs/core/tools-api.md +131 -0
- package/bundle/docs/examples/proxy-script.md +83 -0
- package/bundle/docs/extensions/extension-releasing.md +183 -0
- package/bundle/docs/extensions/getting-started-extensions.md +245 -0
- package/bundle/docs/extensions/index.md +293 -0
- package/bundle/docs/faq.md +154 -0
- package/bundle/docs/get-started/authentication.md +321 -0
- package/bundle/docs/get-started/configuration-v1.md +888 -0
- package/bundle/docs/get-started/configuration.md +1524 -0
- package/bundle/docs/get-started/deployment.md +143 -0
- package/bundle/docs/get-started/examples.md +219 -0
- package/bundle/docs/get-started/gemini-3.md +116 -0
- package/bundle/docs/get-started/index.md +71 -0
- package/bundle/docs/get-started/installation.md +141 -0
- package/bundle/docs/hooks/best-practices.md +856 -0
- package/bundle/docs/hooks/index.md +687 -0
- package/bundle/docs/hooks/reference.md +168 -0
- package/bundle/docs/hooks/writing-hooks.md +1026 -0
- package/bundle/docs/ide-integration/ide-companion-spec.md +267 -0
- package/bundle/docs/ide-integration/index.md +202 -0
- package/bundle/docs/index.md +147 -0
- package/bundle/docs/integration-tests.md +211 -0
- package/bundle/docs/issue-and-pr-automation.md +134 -0
- package/bundle/docs/local-development.md +128 -0
- package/bundle/docs/mermaid/context.mmd +103 -0
- package/bundle/docs/mermaid/render-path.mmd +64 -0
- package/bundle/docs/npm.md +62 -0
- package/bundle/docs/quota-and-pricing.md +158 -0
- package/bundle/docs/release-confidence.md +164 -0
- package/bundle/docs/releases.md +540 -0
- package/bundle/docs/sidebar.json +297 -0
- package/bundle/docs/tools/file-system.md +217 -0
- package/bundle/docs/tools/index.md +95 -0
- package/bundle/docs/tools/mcp-server.md +1044 -0
- package/bundle/docs/tools/memory.md +54 -0
- package/bundle/docs/tools/shell.md +260 -0
- package/bundle/docs/tools/todos.md +57 -0
- package/bundle/docs/tools/web-fetch.md +59 -0
- package/bundle/docs/tools/web-search.md +42 -0
- package/bundle/docs/tos-privacy.md +96 -0
- package/bundle/docs/troubleshooting.md +158 -0
- package/bundle/policies/agent.toml +31 -0
- package/bundle/policies/discovered.toml +8 -0
- package/bundle/policies/read-only.toml +61 -0
- package/bundle/policies/write.toml +78 -0
- package/bundle/policies/yolo.toml +31 -0
- package/bundle/sandbox-macos-permissive-closed.sb +32 -0
- package/bundle/sandbox-macos-permissive-open.sb +27 -0
- package/bundle/sandbox-macos-permissive-proxied.sb +37 -0
- package/bundle/sandbox-macos-restrictive-closed.sb +93 -0
- package/bundle/sandbox-macos-restrictive-open.sb +96 -0
- package/bundle/sandbox-macos-restrictive-proxied.sb +98 -0
- package/package.json +148 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Advanced Model Configuration
|
|
2
|
+
|
|
3
|
+
This guide details the Model Configuration system within the Gemini CLI.
|
|
4
|
+
Designed for researchers, AI quality engineers, and advanced users, this system
|
|
5
|
+
provides a rigorous framework for managing generative model hyperparameters and
|
|
6
|
+
behaviors.
|
|
7
|
+
|
|
8
|
+
> **Warning**: This is a power-user feature. Configuration values are passed
|
|
9
|
+
> directly to the model provider with minimal validation. Incorrect settings
|
|
10
|
+
> (e.g., incompatible parameter combinations) may result in runtime errors from
|
|
11
|
+
> the API.
|
|
12
|
+
|
|
13
|
+
## 1. System Overview
|
|
14
|
+
|
|
15
|
+
The Model Configuration system (`ModelConfigService`) enables deterministic
|
|
16
|
+
control over model generation. It decouples the requested model identifier
|
|
17
|
+
(e.g., a CLI flag or agent request) from the underlying API configuration. This
|
|
18
|
+
allows for:
|
|
19
|
+
|
|
20
|
+
- **Precise Hyperparameter Tuning**: Direct control over `temperature`, `topP`,
|
|
21
|
+
`thinkingBudget`, and other SDK-level parameters.
|
|
22
|
+
- **Environment-Specific Behavior**: Distinct configurations for different
|
|
23
|
+
operating contexts (e.g., testing vs. production).
|
|
24
|
+
- **Agent-Scoped Customization**: Applying specific settings only when a
|
|
25
|
+
particular agent is active.
|
|
26
|
+
|
|
27
|
+
The system operates on two core primitives: **Aliases** and **Overrides**.
|
|
28
|
+
|
|
29
|
+
## 2. Configuration Primitives
|
|
30
|
+
|
|
31
|
+
These settings are located under the `modelConfigs` key in your configuration
|
|
32
|
+
file.
|
|
33
|
+
|
|
34
|
+
### Aliases (`customAliases`)
|
|
35
|
+
|
|
36
|
+
Aliases are named, reusable configuration presets. Users should define their own
|
|
37
|
+
aliases (or override system defaults) in the `customAliases` map.
|
|
38
|
+
|
|
39
|
+
- **Inheritance**: An alias can `extends` another alias (including system
|
|
40
|
+
defaults like `chat-base`), inheriting its `modelConfig`. Child aliases can
|
|
41
|
+
overwrite or augment inherited settings.
|
|
42
|
+
- **Abstract Aliases**: An alias is not required to specify a concrete `model`
|
|
43
|
+
if it serves purely as a base for other aliases.
|
|
44
|
+
|
|
45
|
+
**Example Hierarchy**:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
"modelConfigs": {
|
|
49
|
+
"customAliases": {
|
|
50
|
+
"base": {
|
|
51
|
+
"modelConfig": {
|
|
52
|
+
"generateContentConfig": { "temperature": 0.0 }
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"chat-base": {
|
|
56
|
+
"extends": "base",
|
|
57
|
+
"modelConfig": {
|
|
58
|
+
"generateContentConfig": { "temperature": 0.7 }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Overrides (`overrides`)
|
|
66
|
+
|
|
67
|
+
Overrides are conditional rules that inject configuration based on the runtime
|
|
68
|
+
context. They are evaluated dynamically for each model request.
|
|
69
|
+
|
|
70
|
+
- **Match Criteria**: Overrides apply when the request context matches the
|
|
71
|
+
specified `match` properties.
|
|
72
|
+
- `model`: Matches the requested model name or alias.
|
|
73
|
+
- `overrideScope`: Matches the distinct scope of the request (typically the
|
|
74
|
+
agent name, e.g., `codebaseInvestigator`).
|
|
75
|
+
|
|
76
|
+
**Example Override**:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
"modelConfigs": {
|
|
80
|
+
"overrides": [
|
|
81
|
+
{
|
|
82
|
+
"match": {
|
|
83
|
+
"overrideScope": "codebaseInvestigator"
|
|
84
|
+
},
|
|
85
|
+
"modelConfig": {
|
|
86
|
+
"generateContentConfig": { "temperature": 0.1 }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 3. Resolution Strategy
|
|
94
|
+
|
|
95
|
+
The `ModelConfigService` resolves the final configuration through a two-step
|
|
96
|
+
process:
|
|
97
|
+
|
|
98
|
+
### Step 1: Alias Resolution
|
|
99
|
+
|
|
100
|
+
The requested model string is looked up in the merged map of system `aliases`
|
|
101
|
+
and user `customAliases`.
|
|
102
|
+
|
|
103
|
+
1. If found, the system recursively resolves the `extends` chain.
|
|
104
|
+
2. Settings are merged from parent to child (child wins).
|
|
105
|
+
3. This results in a base `ResolvedModelConfig`.
|
|
106
|
+
4. If not found, the requested string is treated as the raw model name.
|
|
107
|
+
|
|
108
|
+
### Step 2: Override Application
|
|
109
|
+
|
|
110
|
+
The system evaluates the `overrides` list against the request context (`model`
|
|
111
|
+
and `overrideScope`).
|
|
112
|
+
|
|
113
|
+
1. **Filtering**: All matching overrides are identified.
|
|
114
|
+
2. **Sorting**: Matches are prioritized by **specificity** (the number of
|
|
115
|
+
matched keys in the `match` object).
|
|
116
|
+
- Specific matches (e.g., `model` + `overrideScope`) override broad matches
|
|
117
|
+
(e.g., `model` only).
|
|
118
|
+
- Tie-breaking: If specificity is equal, the order of definition in the
|
|
119
|
+
`overrides` array is preserved (last one wins).
|
|
120
|
+
3. **Merging**: The configurations from the sorted overrides are merged
|
|
121
|
+
sequentially onto the base configuration.
|
|
122
|
+
|
|
123
|
+
## 4. Configuration Reference
|
|
124
|
+
|
|
125
|
+
The configuration follows the `ModelConfigServiceConfig` interface.
|
|
126
|
+
|
|
127
|
+
### `ModelConfig` Object
|
|
128
|
+
|
|
129
|
+
Defines the actual parameters for the model.
|
|
130
|
+
|
|
131
|
+
| Property | Type | Description |
|
|
132
|
+
| :---------------------- | :------- | :----------------------------------------------------------------- |
|
|
133
|
+
| `model` | `string` | The identifier of the model to be called (e.g., `gemini-2.5-pro`). |
|
|
134
|
+
| `generateContentConfig` | `object` | The configuration object passed to the `@google/genai` SDK. |
|
|
135
|
+
|
|
136
|
+
### `GenerateContentConfig` (Common Parameters)
|
|
137
|
+
|
|
138
|
+
Directly maps to the SDK's `GenerateContentConfig`. Common parameters include:
|
|
139
|
+
|
|
140
|
+
- **`temperature`**: (`number`) Controls output randomness. Lower values (0.0)
|
|
141
|
+
are deterministic; higher values (>0.7) are creative.
|
|
142
|
+
- **`topP`**: (`number`) Nucleus sampling probability.
|
|
143
|
+
- **`maxOutputTokens`**: (`number`) Limit on generated response length.
|
|
144
|
+
- **`thinkingConfig`**: (`object`) Configuration for models with reasoning
|
|
145
|
+
capabilities (e.g., `thinkingBudget`, `includeThoughts`).
|
|
146
|
+
|
|
147
|
+
## 5. Practical Examples
|
|
148
|
+
|
|
149
|
+
### Defining a Deterministic Baseline
|
|
150
|
+
|
|
151
|
+
Create an alias for tasks requiring high precision, extending the standard chat
|
|
152
|
+
configuration but enforcing zero temperature.
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
"modelConfigs": {
|
|
156
|
+
"customAliases": {
|
|
157
|
+
"precise-mode": {
|
|
158
|
+
"extends": "chat-base",
|
|
159
|
+
"modelConfig": {
|
|
160
|
+
"generateContentConfig": {
|
|
161
|
+
"temperature": 0.0,
|
|
162
|
+
"topP": 1.0
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Agent-Specific Parameter Injection
|
|
171
|
+
|
|
172
|
+
Enforce extended thinking budgets for a specific agent without altering the
|
|
173
|
+
global default, e.g. for the `codebaseInvestigator`.
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
"modelConfigs": {
|
|
177
|
+
"overrides": [
|
|
178
|
+
{
|
|
179
|
+
"match": {
|
|
180
|
+
"overrideScope": "codebaseInvestigator"
|
|
181
|
+
},
|
|
182
|
+
"modelConfig": {
|
|
183
|
+
"generateContentConfig": {
|
|
184
|
+
"thinkingConfig": { "thinkingBudget": 4096 }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Experimental Model Evaluation
|
|
193
|
+
|
|
194
|
+
Route traffic for a specific alias to a preview model for A/B testing, without
|
|
195
|
+
changing client code.
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
"modelConfigs": {
|
|
199
|
+
"overrides": [
|
|
200
|
+
{
|
|
201
|
+
"match": {
|
|
202
|
+
"model": "gemini-2.5-pro"
|
|
203
|
+
},
|
|
204
|
+
"modelConfig": {
|
|
205
|
+
"model": "gemini-2.5-pro-experimental-001"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
```
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# Headless mode
|
|
2
|
+
|
|
3
|
+
Headless mode allows you to run Gemini CLI programmatically from command line
|
|
4
|
+
scripts and automation tools without any interactive UI. This is ideal for
|
|
5
|
+
scripting, automation, CI/CD pipelines, and building AI-powered tools.
|
|
6
|
+
|
|
7
|
+
- [Headless Mode](#headless-mode)
|
|
8
|
+
- [Overview](#overview)
|
|
9
|
+
- [Basic Usage](#basic-usage)
|
|
10
|
+
- [Direct Prompts](#direct-prompts)
|
|
11
|
+
- [Stdin Input](#stdin-input)
|
|
12
|
+
- [Combining with File Input](#combining-with-file-input)
|
|
13
|
+
- [Output Formats](#output-formats)
|
|
14
|
+
- [Text Output (Default)](#text-output-default)
|
|
15
|
+
- [JSON Output](#json-output)
|
|
16
|
+
- [Response Schema](#response-schema)
|
|
17
|
+
- [Example Usage](#example-usage)
|
|
18
|
+
- [Streaming JSON Output](#streaming-json-output)
|
|
19
|
+
- [When to Use Streaming JSON](#when-to-use-streaming-json)
|
|
20
|
+
- [Event Types](#event-types)
|
|
21
|
+
- [Basic Usage](#basic-usage)
|
|
22
|
+
- [Example Output](#example-output)
|
|
23
|
+
- [Processing Stream Events](#processing-stream-events)
|
|
24
|
+
- [Real-World Examples](#real-world-examples)
|
|
25
|
+
- [File Redirection](#file-redirection)
|
|
26
|
+
- [Configuration Options](#configuration-options)
|
|
27
|
+
- [Examples](#examples)
|
|
28
|
+
- [Code review](#code-review)
|
|
29
|
+
- [Generate commit messages](#generate-commit-messages)
|
|
30
|
+
- [API documentation](#api-documentation)
|
|
31
|
+
- [Batch code analysis](#batch-code-analysis)
|
|
32
|
+
- [Code review](#code-review-1)
|
|
33
|
+
- [Log analysis](#log-analysis)
|
|
34
|
+
- [Release notes generation](#release-notes-generation)
|
|
35
|
+
- [Model and tool usage tracking](#model-and-tool-usage-tracking)
|
|
36
|
+
- [Resources](#resources)
|
|
37
|
+
|
|
38
|
+
## Overview
|
|
39
|
+
|
|
40
|
+
The headless mode provides a headless interface to Gemini CLI that:
|
|
41
|
+
|
|
42
|
+
- Accepts prompts via command line arguments or stdin
|
|
43
|
+
- Returns structured output (text or JSON)
|
|
44
|
+
- Supports file redirection and piping
|
|
45
|
+
- Enables automation and scripting workflows
|
|
46
|
+
- Provides consistent exit codes for error handling
|
|
47
|
+
|
|
48
|
+
## Basic usage
|
|
49
|
+
|
|
50
|
+
### Direct prompts
|
|
51
|
+
|
|
52
|
+
Use the `--prompt` (or `-p`) flag to run in headless mode:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
gemini --prompt "What is machine learning?"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Stdin input
|
|
59
|
+
|
|
60
|
+
Pipe input to Gemini CLI from your terminal:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
echo "Explain this code" | gemini
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Combining with file input
|
|
67
|
+
|
|
68
|
+
Read from files and process with Gemini:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
cat README.md | gemini --prompt "Summarize this documentation"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Output formats
|
|
75
|
+
|
|
76
|
+
### Text output (default)
|
|
77
|
+
|
|
78
|
+
Standard human-readable output:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
gemini -p "What is the capital of France?"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Response format:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
The capital of France is Paris.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### JSON output
|
|
91
|
+
|
|
92
|
+
Returns structured data including response, statistics, and metadata. This
|
|
93
|
+
format is ideal for programmatic processing and automation scripts.
|
|
94
|
+
|
|
95
|
+
#### Response schema
|
|
96
|
+
|
|
97
|
+
The JSON output follows this high-level structure:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"response": "string", // The main AI-generated content answering your prompt
|
|
102
|
+
"stats": {
|
|
103
|
+
// Usage metrics and performance data
|
|
104
|
+
"models": {
|
|
105
|
+
// Per-model API and token usage statistics
|
|
106
|
+
"[model-name]": {
|
|
107
|
+
"api": {
|
|
108
|
+
/* request counts, errors, latency */
|
|
109
|
+
},
|
|
110
|
+
"tokens": {
|
|
111
|
+
/* prompt, response, cached, total counts */
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"tools": {
|
|
116
|
+
// Tool execution statistics
|
|
117
|
+
"totalCalls": "number",
|
|
118
|
+
"totalSuccess": "number",
|
|
119
|
+
"totalFail": "number",
|
|
120
|
+
"totalDurationMs": "number",
|
|
121
|
+
"totalDecisions": {
|
|
122
|
+
/* accept, reject, modify, auto_accept counts */
|
|
123
|
+
},
|
|
124
|
+
"byName": {
|
|
125
|
+
/* per-tool detailed stats */
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"files": {
|
|
129
|
+
// File modification statistics
|
|
130
|
+
"totalLinesAdded": "number",
|
|
131
|
+
"totalLinesRemoved": "number"
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"error": {
|
|
135
|
+
// Present only when an error occurred
|
|
136
|
+
"type": "string", // Error type (e.g., "ApiError", "AuthError")
|
|
137
|
+
"message": "string", // Human-readable error description
|
|
138
|
+
"code": "number" // Optional error code
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Example usage
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
gemini -p "What is the capital of France?" --output-format json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Response:
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"response": "The capital of France is Paris.",
|
|
154
|
+
"stats": {
|
|
155
|
+
"models": {
|
|
156
|
+
"gemini-2.5-pro": {
|
|
157
|
+
"api": {
|
|
158
|
+
"totalRequests": 2,
|
|
159
|
+
"totalErrors": 0,
|
|
160
|
+
"totalLatencyMs": 5053
|
|
161
|
+
},
|
|
162
|
+
"tokens": {
|
|
163
|
+
"prompt": 24939,
|
|
164
|
+
"candidates": 20,
|
|
165
|
+
"total": 25113,
|
|
166
|
+
"cached": 21263,
|
|
167
|
+
"thoughts": 154,
|
|
168
|
+
"tool": 0
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"gemini-2.5-flash": {
|
|
172
|
+
"api": {
|
|
173
|
+
"totalRequests": 1,
|
|
174
|
+
"totalErrors": 0,
|
|
175
|
+
"totalLatencyMs": 1879
|
|
176
|
+
},
|
|
177
|
+
"tokens": {
|
|
178
|
+
"prompt": 8965,
|
|
179
|
+
"candidates": 10,
|
|
180
|
+
"total": 9033,
|
|
181
|
+
"cached": 0,
|
|
182
|
+
"thoughts": 30,
|
|
183
|
+
"tool": 28
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"tools": {
|
|
188
|
+
"totalCalls": 1,
|
|
189
|
+
"totalSuccess": 1,
|
|
190
|
+
"totalFail": 0,
|
|
191
|
+
"totalDurationMs": 1881,
|
|
192
|
+
"totalDecisions": {
|
|
193
|
+
"accept": 0,
|
|
194
|
+
"reject": 0,
|
|
195
|
+
"modify": 0,
|
|
196
|
+
"auto_accept": 1
|
|
197
|
+
},
|
|
198
|
+
"byName": {
|
|
199
|
+
"google_web_search": {
|
|
200
|
+
"count": 1,
|
|
201
|
+
"success": 1,
|
|
202
|
+
"fail": 0,
|
|
203
|
+
"durationMs": 1881,
|
|
204
|
+
"decisions": {
|
|
205
|
+
"accept": 0,
|
|
206
|
+
"reject": 0,
|
|
207
|
+
"modify": 0,
|
|
208
|
+
"auto_accept": 1
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
"files": {
|
|
214
|
+
"totalLinesAdded": 0,
|
|
215
|
+
"totalLinesRemoved": 0
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Streaming JSON output
|
|
222
|
+
|
|
223
|
+
Returns real-time events as newline-delimited JSON (JSONL). Each significant
|
|
224
|
+
action (initialization, messages, tool calls, results) emits immediately as it
|
|
225
|
+
occurs. This format is ideal for monitoring long-running operations, building
|
|
226
|
+
UIs with live progress, and creating automation pipelines that react to events.
|
|
227
|
+
|
|
228
|
+
#### When to use streaming JSON
|
|
229
|
+
|
|
230
|
+
Use `--output-format stream-json` when you need:
|
|
231
|
+
|
|
232
|
+
- **Real-time progress monitoring** - See tool calls and responses as they
|
|
233
|
+
happen
|
|
234
|
+
- **Event-driven automation** - React to specific events (e.g., tool failures)
|
|
235
|
+
- **Live UI updates** - Build interfaces showing AI agent activity in real-time
|
|
236
|
+
- **Detailed execution logs** - Capture complete interaction history with
|
|
237
|
+
timestamps
|
|
238
|
+
- **Pipeline integration** - Stream events to logging/monitoring systems
|
|
239
|
+
|
|
240
|
+
#### Event types
|
|
241
|
+
|
|
242
|
+
The streaming format emits 6 event types:
|
|
243
|
+
|
|
244
|
+
1. **`init`** - Session starts (includes session_id, model)
|
|
245
|
+
2. **`message`** - User prompts and assistant responses
|
|
246
|
+
3. **`tool_use`** - Tool call requests with parameters
|
|
247
|
+
4. **`tool_result`** - Tool execution results (success/error)
|
|
248
|
+
5. **`error`** - Non-fatal errors and warnings
|
|
249
|
+
6. **`result`** - Final session outcome with aggregated stats
|
|
250
|
+
|
|
251
|
+
#### Basic usage
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Stream events to console
|
|
255
|
+
gemini --output-format stream-json --prompt "What is 2+2?"
|
|
256
|
+
|
|
257
|
+
# Save event stream to file
|
|
258
|
+
gemini --output-format stream-json --prompt "Analyze this code" > events.jsonl
|
|
259
|
+
|
|
260
|
+
# Parse with jq
|
|
261
|
+
gemini --output-format stream-json --prompt "List files" | jq -r '.type'
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Example output
|
|
265
|
+
|
|
266
|
+
Each line is a complete JSON event:
|
|
267
|
+
|
|
268
|
+
```jsonl
|
|
269
|
+
{"type":"init","timestamp":"2025-10-10T12:00:00.000Z","session_id":"abc123","model":"gemini-2.0-flash-exp"}
|
|
270
|
+
{"type":"message","role":"user","content":"List files in current directory","timestamp":"2025-10-10T12:00:01.000Z"}
|
|
271
|
+
{"type":"tool_use","tool_name":"Bash","tool_id":"bash-123","parameters":{"command":"ls -la"},"timestamp":"2025-10-10T12:00:02.000Z"}
|
|
272
|
+
{"type":"tool_result","tool_id":"bash-123","status":"success","output":"file1.txt\nfile2.txt","timestamp":"2025-10-10T12:00:03.000Z"}
|
|
273
|
+
{"type":"message","role":"assistant","content":"Here are the files...","delta":true,"timestamp":"2025-10-10T12:00:04.000Z"}
|
|
274
|
+
{"type":"result","status":"success","stats":{"total_tokens":250,"input_tokens":50,"output_tokens":200,"duration_ms":3000,"tool_calls":1},"timestamp":"2025-10-10T12:00:05.000Z"}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### File redirection
|
|
278
|
+
|
|
279
|
+
Save output to files or pipe to other commands:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Save to file
|
|
283
|
+
gemini -p "Explain Docker" > docker-explanation.txt
|
|
284
|
+
gemini -p "Explain Docker" --output-format json > docker-explanation.json
|
|
285
|
+
|
|
286
|
+
# Append to file
|
|
287
|
+
gemini -p "Add more details" >> docker-explanation.txt
|
|
288
|
+
|
|
289
|
+
# Pipe to other tools
|
|
290
|
+
gemini -p "What is Kubernetes?" --output-format json | jq '.response'
|
|
291
|
+
gemini -p "Explain microservices" | wc -w
|
|
292
|
+
gemini -p "List programming languages" | grep -i "python"
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Configuration options
|
|
296
|
+
|
|
297
|
+
Key command-line options for headless usage:
|
|
298
|
+
|
|
299
|
+
| Option | Description | Example |
|
|
300
|
+
| ----------------------- | ---------------------------------- | -------------------------------------------------- |
|
|
301
|
+
| `--prompt`, `-p` | Run in headless mode | `gemini -p "query"` |
|
|
302
|
+
| `--output-format` | Specify output format (text, json) | `gemini -p "query" --output-format json` |
|
|
303
|
+
| `--model`, `-m` | Specify the Gemini model | `gemini -p "query" -m gemini-2.5-flash` |
|
|
304
|
+
| `--debug`, `-d` | Enable debug mode | `gemini -p "query" --debug` |
|
|
305
|
+
| `--include-directories` | Include additional directories | `gemini -p "query" --include-directories src,docs` |
|
|
306
|
+
| `--yolo`, `-y` | Auto-approve all actions | `gemini -p "query" --yolo` |
|
|
307
|
+
| `--approval-mode` | Set approval mode | `gemini -p "query" --approval-mode auto_edit` |
|
|
308
|
+
|
|
309
|
+
For complete details on all available configuration options, settings files, and
|
|
310
|
+
environment variables, see the
|
|
311
|
+
[Configuration Guide](../get-started/configuration.md).
|
|
312
|
+
|
|
313
|
+
## Examples
|
|
314
|
+
|
|
315
|
+
#### Code review
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
cat src/auth.py | gemini -p "Review this authentication code for security issues" > security-review.txt
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### Generate commit messages
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
result=$(git diff --cached | gemini -p "Write a concise commit message for these changes" --output-format json)
|
|
325
|
+
echo "$result" | jq -r '.response'
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
#### API documentation
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
result=$(cat api/routes.js | gemini -p "Generate OpenAPI spec for these routes" --output-format json)
|
|
332
|
+
echo "$result" | jq -r '.response' > openapi.json
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
#### Batch code analysis
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
for file in src/*.py; do
|
|
339
|
+
echo "Analyzing $file..."
|
|
340
|
+
result=$(cat "$file" | gemini -p "Find potential bugs and suggest improvements" --output-format json)
|
|
341
|
+
echo "$result" | jq -r '.response' > "reports/$(basename "$file").analysis"
|
|
342
|
+
echo "Completed analysis for $(basename "$file")" >> reports/progress.log
|
|
343
|
+
done
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### Code review
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
result=$(git diff origin/main...HEAD | gemini -p "Review these changes for bugs, security issues, and code quality" --output-format json)
|
|
350
|
+
echo "$result" | jq -r '.response' > pr-review.json
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
#### Log analysis
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
grep "ERROR" /var/log/app.log | tail -20 | gemini -p "Analyze these errors and suggest root cause and fixes" > error-analysis.txt
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### Release notes generation
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
result=$(git log --oneline v1.0.0..HEAD | gemini -p "Generate release notes from these commits" --output-format json)
|
|
363
|
+
response=$(echo "$result" | jq -r '.response')
|
|
364
|
+
echo "$response"
|
|
365
|
+
echo "$response" >> CHANGELOG.md
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
#### Model and tool usage tracking
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
result=$(gemini -p "Explain this database schema" --include-directories db --output-format json)
|
|
372
|
+
total_tokens=$(echo "$result" | jq -r '.stats.models // {} | to_entries | map(.value.tokens.total) | add // 0')
|
|
373
|
+
models_used=$(echo "$result" | jq -r '.stats.models // {} | keys | join(", ") | if . == "" then "none" else . end')
|
|
374
|
+
tool_calls=$(echo "$result" | jq -r '.stats.tools.totalCalls // 0')
|
|
375
|
+
tools_used=$(echo "$result" | jq -r '.stats.tools.byName // {} | keys | join(", ") | if . == "" then "none" else . end')
|
|
376
|
+
echo "$(date): $total_tokens tokens, $tool_calls tool calls ($tools_used) used with models: $models_used" >> usage.log
|
|
377
|
+
echo "$result" | jq -r '.response' > schema-docs.md
|
|
378
|
+
echo "Recent usage trends:"
|
|
379
|
+
tail -5 usage.log
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Resources
|
|
383
|
+
|
|
384
|
+
- [CLI Configuration](../get-started/configuration.md) - Complete configuration
|
|
385
|
+
guide
|
|
386
|
+
- [Authentication](../get-started/authentication.md) - Setup authentication
|
|
387
|
+
- [Commands](./commands.md) - Interactive commands reference
|
|
388
|
+
- [Tutorials](./tutorials.md) - Step-by-step automation guides
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Gemini CLI
|
|
2
|
+
|
|
3
|
+
Within Gemini CLI, `packages/cli` is the frontend for users to send and receive
|
|
4
|
+
prompts with the Gemini AI model and its associated tools. For a general
|
|
5
|
+
overview of Gemini CLI, see the [main documentation page](../index.md).
|
|
6
|
+
|
|
7
|
+
## Basic features
|
|
8
|
+
|
|
9
|
+
- **[Commands](./commands.md):** A reference for all built-in slash commands
|
|
10
|
+
- **[Custom commands](./custom-commands.md):** Create your own commands and
|
|
11
|
+
shortcuts for frequently used prompts.
|
|
12
|
+
- **[Headless mode](./headless.md):** Use Gemini CLI programmatically for
|
|
13
|
+
scripting and automation.
|
|
14
|
+
- **[Model selection](./model.md):** Configure the Gemini AI model used by the
|
|
15
|
+
CLI.
|
|
16
|
+
- **[Settings](./settings.md):** Configure various aspects of the CLI's behavior
|
|
17
|
+
and appearance.
|
|
18
|
+
- **[Themes](./themes.md):** Customizing the CLI's appearance with different
|
|
19
|
+
themes.
|
|
20
|
+
- **[Keyboard shortcuts](./keyboard-shortcuts.md):** A reference for all
|
|
21
|
+
keyboard shortcuts to improve your workflow.
|
|
22
|
+
- **[Tutorials](./tutorials.md):** Step-by-step guides for common tasks.
|
|
23
|
+
|
|
24
|
+
## Advanced features
|
|
25
|
+
|
|
26
|
+
- **[Checkpointing](./checkpointing.md):** Automatically save and restore
|
|
27
|
+
snapshots of your session and files.
|
|
28
|
+
- **[Enterprise configuration](./enterprise.md):** Deploying and manage Gemini
|
|
29
|
+
CLI in an enterprise environment.
|
|
30
|
+
- **[Sandboxing](./sandbox.md):** Isolate tool execution in a secure,
|
|
31
|
+
containerized environment.
|
|
32
|
+
- **[Telemetry](./telemetry.md):** Configure observability to monitor usage and
|
|
33
|
+
performance.
|
|
34
|
+
- **[Token caching](./token-caching.md):** Optimize API costs by caching tokens.
|
|
35
|
+
- **[Trusted folders](./trusted-folders.md):** A security feature to control
|
|
36
|
+
which projects can use the full capabilities of the CLI.
|
|
37
|
+
- **[Ignoring files (.codeflyignore)](./codefly-ignore.md):** Exclude specific
|
|
38
|
+
files and directories from being accessed by tools.
|
|
39
|
+
- **[Context files (CODEFLY.md)](./codefly-md.md):** Provide persistent,
|
|
40
|
+
hierarchical context to the model.
|
|
41
|
+
- **[System prompt override](./system-prompt.md):** Replace the built‑in system
|
|
42
|
+
instructions using `GEMINI_SYSTEM_MD`.
|
|
43
|
+
|
|
44
|
+
## Non-interactive mode
|
|
45
|
+
|
|
46
|
+
Gemini CLI can be run in a non-interactive mode, which is useful for scripting
|
|
47
|
+
and automation. In this mode, you pipe input to the CLI, it executes the
|
|
48
|
+
command, and then it exits.
|
|
49
|
+
|
|
50
|
+
The following example pipes a command to Gemini CLI from your terminal:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
echo "What is fine tuning?" | gemini
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
You can also use the `--prompt` or `-p` flag:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
gemini -p "What is fine tuning?"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For comprehensive documentation on headless usage, scripting, automation, and
|
|
63
|
+
advanced examples, see the **[Headless mode](./headless.md)** guide.
|