Konfigurations-API-Dokumentation
Vollständige Referenzdokumentation für die Konfigurationsverwaltungs-API
Konfigurationshierarchie
Gemini CLI verwendet ein hierarchisches Konfigurationssystem, das mehrere Konfigurationsquellen und dynamische Updates unterstützt
Standardkonfiguration
Eingebaute Standard-Konfigurationswerte
Globale Konfigurationsdatei
~/.gemini/config.toml
Projekt-Konfigurationsdatei
./gemini.toml oder ./.gemini/config.toml
Umgebungsvariablen
Umgebungsvariablen mit GEMINI_* Präfix
Kommandozeilenargumente
Laufzeit-Argumente, die an den Befehl übergeben werden
Konfigurationsoptionen
Detaillierte Beschreibung der Konfigurationsoptionen
[api]
Gemini API-bezogene Konfiguration
Option | Typ | Standard | Beschreibung |
---|---|---|---|
key Erforderlich | string | - | Google AI API-Schlüssel |
model | string | "gemini-pro" | Standardmodell zur Verwendung |
temperature | number | 0.7 | Generierungstemperatur (0-1) |
max_tokens | number | 4096 | Maximale Anzahl von Token |
timeout | number | 30000 | Anfrage-Timeout in Millisekunden |
[session]
Sitzungsverwaltungskonfiguration
Option | Typ | Standard | Beschreibung |
---|---|---|---|
auto_save | boolean | true | Sitzungen automatisch speichern |
max_history | number | 100 | Maximale Anzahl von Verlaufsnachrichten |
storage_path | string | "~/.gemini/sessions" | Sitzungsspeicherpfad |
compression | boolean | true | Sitzungskomprimierung aktivieren |
[context]
Kontextverarbeitungskonfiguration
Option | Typ | Standard | Beschreibung |
---|---|---|---|
max_files | number | 50 | Maximale Anzahl von Dateien |
max_file_size | string | "1MB" | Maximale Dateigröße pro Datei |
exclude_patterns | array | *.log,*.tmp | Dateiausschlussmuster |
auto_detect_language | boolean | true | Programmiersprache automatisch erkennen |
[plugins]
Plugin-Systemkonfiguration
Option | Typ | Standard | Beschreibung |
---|---|---|---|
enabled | boolean | true | Plugin-System aktivieren |
auto_load | boolean | true | Plugins automatisch laden |
plugin_paths | array | ~/.gemini/plugins | Plugin-Suchpfade |
security_mode | string | "strict" | Sicherheitsmodus (strict/permissive) |
Konfigurationsdatei-Beispiel
Vollständiges TOML-Konfigurationsdatei-Beispiel
# Gemini CLI Konfigurationsdatei (gemini.toml)
[api]
key = "your-api-key-here"
model = "gemini-pro"
temperature = 0.7
max_tokens = 4096
timeout = 30000
[session]
auto_save = true
max_history = 100
storage_path = "~/.gemini/sessions"
compression = true
[context]
max_files = 50
max_file_size = "1MB"
exclude_patterns = [
"*.log",
"*.tmp",
"node_modules/**",
".git/**"
]
auto_detect_language = true
[plugins]
enabled = true
auto_load = true
plugin_paths = [
"~/.gemini/plugins",
"./plugins"
]
security_mode = "strict"
[logging]
level = "info"
file = "~/.gemini/logs/gemini.log"
max_size = "10MB"
max_files = 5
[ui]
theme = "auto"
color = true
progress_bar = true
confirm_destructive = true
Konfigurations-API-Schnittstelle
ConfigManager-Klassen-Schnittstellendefinition
ConfigManager
ConfigManager-Klassen-Schnittstellendefinition
interface ConfigManager {
// Konfigurationswert abrufen
get<T>(key: string): T | undefined
get<T>(key: string, defaultValue: T): T
// Konfigurationswert setzen
set(key: string, value: any): void
// Konfigurationselement löschen
delete(key: string): void
// Prüfen, ob Konfigurationselement existiert
has(key: string): boolean
// Alle Konfigurationen abrufen
getAll(): Record<string, any>
// Konfiguration neu laden
reload(): Promise<void>
// Konfiguration in Datei speichern
save(): Promise<void>
// Konfigurationsänderungen überwachen
watch(key: string, callback: (value: any) => void): void
// Konfigurationsänderungen nicht mehr überwachen
unwatch(key: string, callback?: (value: any) => void): void
// Konfiguration validieren
validate(): ConfigValidationResult
}
Umgebungsvariablen
Liste der unterstützten Umgebungsvariablen
GEMINI_API_KEY
Google AI API-Schlüssel
Beispiel:
export GEMINI_API_KEY="your-api-key"
Entsprechende Konfiguration:
api.key
GEMINI_MODEL
Standard-Modellname
Beispiel:
export GEMINI_MODEL="gemini-pro"
Entsprechende Konfiguration:
api.model
GEMINI_TEMPERATURE
Generierungstemperatur
Beispiel:
export GEMINI_TEMPERATURE="0.7"
Entsprechende Konfiguration:
api.temperature
GEMINI_CONFIG_PATH
Konfigurationsdateipfad
Beispiel:
export GEMINI_CONFIG_PATH="/path/to/config.toml"
Entsprechende Konfiguration:
N/A
GEMINI_LOG_LEVEL
Log-Level
Beispiel:
export GEMINI_LOG_LEVEL="debug"
Entsprechende Konfiguration:
logging.level
GEMINI_PLUGIN_PATH
Plugin-Pfad
Beispiel:
export GEMINI_PLUGIN_PATH="/path/to/plugins"
Entsprechende Konfiguration:
plugins.plugin_paths
Verwendungsbeispiele
Praktische Anwendungsbeispiele der Konfigurationsverwaltung
Grundlegende Konfigurationsoperationen
Konfigurationswerte lesen und setzen
import { ConfigManager } from '@gemini-cli/core'
const config = new ConfigManager()
// Konfigurationswerte abrufen
const apiKey = config.get('api.key')
const model = config.get('api.model', 'gemini-pro')
// Konfigurationswerte setzen
config.set('api.temperature', 0.8)
config.set('session.auto_save', false)
// Konfiguration speichern
await config.save()
Konfigurationsüberwachung
Konfigurationsänderungen überwachen
// API-Schlüssel-Änderungen überwachen
config.watch('api.key', (newKey) => {
console.log('API key changed:', newKey)
// Client neu initialisieren
reinitializeClient(newKey)
})
// Modelländerungen überwachen
config.watch('api.model', (newModel) => {
console.log('Model changed to:', newModel)
})
Konfigurationsvalidierung
Konfigurationsgültigkeit validieren
// Konfiguration validieren
const validation = config.validate()
if (!validation.isValid) {
console.error('Configuration errors:')
validation.errors.forEach(error => {
console.error(`- ${error.path}: ${error.message}`)
})
process.exit(1)
}
console.log('Configuration is valid')
Dynamische Konfigurationsupdates
Laufzeit-Konfigurationsupdates
// Dynamisches Konfigurationsupdate
async function updateConfig(updates: Record<string, any>) {
for (const [key, value] of Object.entries(updates)) {
config.set(key, value)
}
// Neue Konfiguration validieren
const validation = config.validate()
if (!validation.isValid) {
throw new Error('Invalid configuration')
}
// Konfiguration speichern
await config.save()
console.log('Configuration updated successfully')
}
Sicherheitsüberlegungen
Best Practices für Konfigurationssicherheit
API-Schlüssel-Sicherheit
Best Practices zum Schutz von API-Schlüsseln
- Umgebungsvariablen zur Speicherung von API-Schlüsseln verwenden
- Vermeiden Sie das Hardcoding von Schlüsseln in Konfigurationsdateien
- Angemessene Dateiberechtigungen setzen (600)
- API-Schlüssel regelmäßig rotieren
Konfigurationsdatei-Berechtigungen
Sicherheitseinstellungen für Konfigurationsdateien
- Konfigurationsdateien auf schreibgeschützt setzen (chmod 600)
- Vermeiden Sie das Committen sensibler Konfigurationen in die Versionskontrolle
- Verwenden Sie .gitignore zum Ausschließen von Konfigurationsdateien
- Regelmäßige Überprüfung der Konfigurationsdateiinhalte
Plugin-Sicherheit
Sicherheitsüberlegungen für Plugin-Konfiguration
- Strengen Sicherheitsmodus aktivieren
- Plugin-Quellen und -Signaturen verifizieren
- Plugin-Berechtigungsbereich begrenzen
- Plugin-Versionen regelmäßig aktualisieren
Konfigurationsvalidierung
Konfigurationsvalidierungsregeln und -implementierung
// Konfigurationsvalidierungsregeln const configSchema = { api: { key: { type: 'string', required: true, minLength: 10, pattern: /^[A-Za-z0-9_-]+$/ }, model: { type: 'string', enum: ['gemini-pro', 'gemini-pro-vision'], default: 'gemini-pro' }, temperature: { type: 'number', min: 0, max: 1, default: 0.7 } }, session: { max_history: { type: 'number', min: 1, max: 1000, default: 100 }, storage_path: { type: 'string', required: true } } } // Konfiguration validieren function validateConfig(config: any): ConfigValidationResult { const errors: ConfigError[] = [] // API-Konfiguration validieren if (!config.api?.key) { errors.push({ path: 'api.key', message: 'API key is required' }) } if (config.api?.temperature < 0 || config.api?.temperature > 1) { errors.push({ path: 'api.temperature', message: 'Temperature must be between 0 and 1' }) } return { isValid: errors.length === 0, errors } }
Weiterlernen
MCP-Protokoll und Erweiterungsentwicklung erkunden