設定 API ドキュメント
完全な設定管理 API リファレンスドキュメント
設定管理25分で読める
設定階層
Gemini CLI は複数の設定ソースと動的更新をサポートする階層設定システムを使用します
1
デフォルト設定
組み込みのデフォルト設定値
2
グローバル設定ファイル
~/.gemini/config.toml
3
プロジェクト設定ファイル
./gemini.toml または ./.gemini/config.toml
4
環境変数
GEMINI_* プレフィックス付きの環境変数
5
コマンドライン引数
コマンドに渡されるランタイム引数
設定オプション
詳細な設定オプションの説明
[api]
Gemini API関連の設定
| オプション | タイプ | デフォルト | 説明 |
|---|---|---|---|
key必須 | string | - | Google AI APIキー |
model | string | "gemini-pro" | 使用するデフォルトモデル |
temperature | number | 0.7 | 生成温度 (0-1) |
max_tokens | number | 4096 | 最大トークン数 |
timeout | number | 30000 | リクエストタイムアウト(ミリ秒) |
[session]
セッション管理設定
| オプション | タイプ | デフォルト | 説明 |
|---|---|---|---|
auto_save | boolean | true | セッションを自動保存 |
max_history | number | 100 | 履歴メッセージの最大数 |
storage_path | string | "~/.gemini/sessions" | セッション保存パス |
compression | boolean | true | セッション圧縮を有効にする |
[context]
コンテキスト処理設定
| オプション | タイプ | デフォルト | 説明 |
|---|---|---|---|
max_files | number | 50 | ファイルの最大数 |
max_file_size | string | "1MB" | ファイルあたりの最大ファイルサイズ |
exclude_patterns | array | *.log,*.tmp | ファイル除外パターン |
auto_detect_language | boolean | true | プログラミング言語を自動検出 |
[plugins]
プラグインシステム設定
| オプション | タイプ | デフォルト | 説明 |
|---|---|---|---|
enabled | boolean | true | プラグインシステムを有効にする |
auto_load | boolean | true | プラグインを自動ロード |
plugin_paths | array | ~/.gemini/plugins | プラグイン検索パス |
security_mode | string | "strict" | セキュリティモード (strict/permissive) |
設定ファイルの例
完全なTOML設定ファイルの例
# Gemini CLI 設定ファイル (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設定APIインターフェース
ConfigManagerクラスのインターフェース定義
ConfigManager
ConfigManagerクラスのインターフェース定義
interface ConfigManager {
// 設定値を取得
get<T>(key: string): T | undefined
get<T>(key: string, defaultValue: T): T
// 設定値を設定
set(key: string, value: any): void
// 設定項目を削除
delete(key: string): void
// 設定項目が存在するかチェック
has(key: string): boolean
// すべての設定を取得
getAll(): Record<string, any>
// 設定を再読み込み
reload(): Promise<void>
// 設定をファイルに保存
save(): Promise<void>
// 設定変更を監視
watch(key: string, callback: (value: any) => void): void
// 設定変更の監視を停止
unwatch(key: string, callback?: (value: any) => void): void
// 設定を検証
validate(): ConfigValidationResult
}環境変数
サポートされている環境変数のリスト
GEMINI_API_KEY
Google AI APIキー
例:
export GEMINI_API_KEY="your-api-key"対応する設定:
api.keyGEMINI_MODEL
デフォルトモデル名
例:
export GEMINI_MODEL="gemini-pro"対応する設定:
api.modelGEMINI_TEMPERATURE
生成温度
例:
export GEMINI_TEMPERATURE="0.7"対応する設定:
api.temperatureGEMINI_CONFIG_PATH
設定ファイルパス
例:
export GEMINI_CONFIG_PATH="/path/to/config.toml"対応する設定:
N/AGEMINI_LOG_LEVEL
ログレベル
例:
export GEMINI_LOG_LEVEL="debug"対応する設定:
logging.levelGEMINI_PLUGIN_PATH
プラグインパス
例:
export GEMINI_PLUGIN_PATH="/path/to/plugins"対応する設定:
plugins.plugin_paths使用例
設定管理の実用的なアプリケーション例
基本的な設定操作
設定値の読み取りと設定
import { ConfigManager } from '@gemini-cli/core'
const config = new ConfigManager()
// 設定値を取得
const apiKey = config.get('api.key')
const model = config.get('api.model', 'gemini-pro')
// 設定値を設定
config.set('api.temperature', 0.8)
config.set('session.auto_save', false)
// 設定を保存
await config.save()設定の監視
設定変更の監視
// APIキーの変更を監視
config.watch('api.key', (newKey) => {
console.log('API key changed:', newKey)
// クライアントを再初期化
reinitializeClient(newKey)
})
// モデルの変更を監視
config.watch('api.model', (newModel) => {
console.log('Model changed to:', newModel)
})設定の検証
設定の有効性を検証
// 設定を検証
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')動的設定更新
ランタイム設定更新
// 動的設定更新
async function updateConfig(updates: Record<string, any>) {
for (const [key, value] of Object.entries(updates)) {
config.set(key, value)
}
// 新しい設定を検証
const validation = config.validate()
if (!validation.isValid) {
throw new Error('Invalid configuration')
}
// 設定を保存
await config.save()
console.log('Configuration updated successfully')
}セキュリティの考慮事項
設定セキュリティのベストプラクティス
APIキーのセキュリティ
APIキーを保護するためのベストプラクティス
- APIキーの保存に環境変数を使用する
- 設定ファイルでキーをハードコーディングしない
- 適切なファイル権限を設定する (600)
- APIキーを定期的にローテーションする
設定ファイルの権限
設定ファイルのセキュリティ設定
- 設定ファイルを読み取り専用に設定する (chmod 600)
- バージョン管理に機密設定をコミットしない
- .gitignoreを使用して設定ファイルを除外する
- 設定ファイルの内容を定期的に確認する
プラグインのセキュリティ
プラグイン設定のセキュリティ考慮事項
- 厳格なセキュリティモードを有効にする
- プラグインのソースと署名を検証する
- プラグインの権限範囲を制限する
- プラグインのバージョンを定期的に更新する
設定検証
設定検証ルールと実装
// 設定検証ルール
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
}
}
}
// 設定を検証
function validateConfig(config: any): ConfigValidationResult {
const errors: ConfigError[] = []
// API設定を検証
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
}
}