구성 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.key
GEMINI_MODEL
기본 모델 이름
예제:
export GEMINI_MODEL="gemini-pro"
해당 구성:
api.model
GEMINI_TEMPERATURE
생성 온도
예제:
export GEMINI_TEMPERATURE="0.7"
해당 구성:
api.temperature
GEMINI_CONFIG_PATH
구성 파일 경로
예제:
export GEMINI_CONFIG_PATH="/path/to/config.toml"
해당 구성:
N/A
GEMINI_LOG_LEVEL
로그 레벨
예제:
export GEMINI_LOG_LEVEL="debug"
해당 구성:
logging.level
GEMINI_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 } }