Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupOldBackups(filePath string) error
- func ConfirmApproved(message string) bool
- func CreateBackup(filePath string) (string, error)
- func DisplayContentToInsert(content string)
- func DisplayContextAround(matchIdx int, lines []string, contextLines int)
- func DisplayMultipleMatches(matchIndices []int, lines []string)
- func DisplayPatternNotFound(pattern string, lines []string, maxPreview int)
- func EnsureGitignore(dir string) error
- func FindGitRoot(startDir string) string
- func FindGitignorePath(startDir string) string
- func FindWithNormalizedWhitespace(content, pattern string) (found bool, startIdx, endIdx int)
- func FormatSize(bytes int64) string
- func GetCurrentTime() time.Time
- func GetSafetyDescription(safety ToolSafety) string
- func IsAutoApprovable(toolName string, autoApprove bool) bool
- func IsInteractiveModeEnabled() bool
- func IsMediumToolAutoApprovable(toolName string) bool
- func IsSafeToolAutoApprovable(toolName string) bool
- func Max(a, b int) int
- func Min(a, b int) int
- func NormalizeLeadingWhitespace(s string) string
- func SetAutoApprove(enabled bool)
- func ShowDiff(old, new, filename string)
- func ShowImprovedDiff(oldStr, newStr string)
- func ShowPreview(content string)
- func Truncate(s string, maxLen int) string
- func ValidatePathAllowParent(path string) (string, error)
- type ConfirmAction
- type ConfirmDecision
- type ConfirmResult
- type ImageData
- type PatternMatchResult
- type ToolSafety
Constants ¶
const (
// MaxImageSize: 10MB
MaxImageSize = 10 * 1024 * 1024
)
Variables ¶
Colors - ui パッケージの共通色を使用
var ConfirmInteractive = func(message string) ConfirmResult { result, err := ui.ConfirmSelector(message) if err != nil { return ConfirmResult{Action: "no"} } if result == "comment" { var reader *bufio.Reader if globalReader := ui.GetGlobalReader(); globalReader != nil { reader = globalReader.GetBufioReader() } else { reader = bufio.NewReader(os.Stdin) } comment, image := ReadMultiLineComment(reader) return ConfirmResult{Action: "comment", Comment: comment, Image: image} } return ConfirmResult{Action: result} }
ConfirmInteractive は拡張確認プロンプト (矢印キー選択UI) Yes/No/Comment を矢印キーで選択、Enterで確定 y/n/c のショートカットキーも引き続きサポート 外部パッケージからも使用可能なようにエクスポート NOTE: テスト時は環境変数 XELYON_INTERACTIVE_CONFIRM=0 で無効化される
var FileExists = fileExistsImpl
FileExists はファイルが存在するかチェック NOTE: テスト用にグローバル変数としてオーバーライド可能
var GlobalAutoApprove = false
GlobalAutoApprove は --auto-approve フラグの状態を保持 Agent から SetAutoApprove() で設定される
var SimpleConfirm = func(message string) bool { reader := bufio.NewReader(os.Stdin) for { Yellow.Printf("%s (y/n): ", message) response, err := reader.ReadString('\n') if err != nil { return false } response = strings.ToLower(strings.TrimSpace(response)) if response == "" { continue } return response == "y" || response == "yes" || response == "y" || response == "はい" } }
SimpleConfirm はユーザーに確認を求める(テスト用にグローバル変数として定義) 空入力は無視してリトライする(AI実行中のEnter押下対策) ただしEOF時はfalseを返して終了する NOTE: テスト時は setupTestConfirm() でモックされる
var ToolSafetyLevels = map[string]ToolSafety{ "read_file": SafetyHigh, "search_file": SafetyHigh, "search_code": SafetyHigh, "list_dir": SafetyHigh, "git_status": SafetyHigh, "git_log": SafetyHigh, "git_diff": SafetyHigh, "lint": SafetyHigh, "test": SafetyHigh, "web_search": SafetyHigh, "ask_question": SafetyHigh, "serper": SafetyHigh, "lsp_references": SafetyHigh, "lsp_definition": SafetyHigh, "lsp_hover": SafetyHigh, "lsp_diagnostics": SafetyHigh, "lsp_rename": SafetyHigh, "write_file": SafetyMedium, "str_replace": SafetyMedium, "append_file": SafetyMedium, "prepend_file": SafetyMedium, "insert_after": SafetyMedium, "insert_before": SafetyMedium, "copy_file": SafetyMedium, "create_dir": SafetyMedium, "git_add": SafetyMedium, "git_commit": SafetyMedium, "git_reset_soft": SafetyMedium, "delete_file": SafetyLow, "delete_lines": SafetyLow, "move_file": SafetyLow, "git_push": SafetyLow, "git_checkout": SafetyLow, "git_branch": SafetyLow, "git_stash": SafetyLow, "git_reset_hard": SafetyLow, "git_force_push": SafetyLow, "bash": SafetyLow, "command": SafetyLow, }
ToolSafetyLevels は各ツールの安全性レベルを定義
var ValidatePath = validatePathImpl
ValidatePath はパストラバーサル攻撃を防ぐためにパスを検証(テスト用にグローバル変数として定義)
Functions ¶
func CleanupOldBackups ¶
CleanupOldBackups は古いバックアップファイルを削除
func ConfirmApproved ¶
ConfirmApproved is a compatibility helper that preserves the old bool-based API. NOTE: This drops comment/image information.
func CreateBackup ¶
CreateBackup はファイルのタイムスタンプ付きバックアップを作成
func DisplayContentToInsert ¶
func DisplayContentToInsert(content string)
DisplayContentToInsert は挿入する内容を表示
func DisplayContextAround ¶
DisplayContextAround はマッチ行の周囲コンテキストを表示
func DisplayMultipleMatches ¶
DisplayMultipleMatches は複数マッチ時のエラー表示
func DisplayPatternNotFound ¶
DisplayPatternNotFound はパターンが見つからない場合のエラー表示
func EnsureGitignore ¶
EnsureGitignore は .gitignore に *.bak* パターンを追加(初回のみ)
func FindGitignorePath ¶
FindGitignorePath は .gitignore のパスを検索(リポジトリルートから)
func FindWithNormalizedWhitespace ¶
FindWithNormalizedWhitespace は正規化した状態で文字列を検索
func GetSafetyDescription ¶
func GetSafetyDescription(safety ToolSafety) string
GetSafetyDescription は安全性レベルの説明を返す
func IsAutoApprovable ¶
IsAutoApprovable は --auto-approve フラグで自動承認可能かを判定
func IsInteractiveModeEnabled ¶
func IsInteractiveModeEnabled() bool
IsInteractiveModeEnabled は対話的確認モードが有効かチェック デフォルトは有効。
無効化したい場合は以下のいずれかを設定:
- XELYON_INTERACTIVE_CONFIRM=0
- XELYON_INTERACTIVE_CONFIRM=false
func IsMediumToolAutoApprovable ¶
IsMediumToolAutoApprovable は SafetyMedium ツールを設定に基づいて自動承認するか判定 config.tool_confirm.auto_approve_medium が true の場合、SafetyMedium ツールは確認なしで実行
func IsSafeToolAutoApprovable ¶
IsSafeToolAutoApprovable は SafetyHigh ツールを設定に基づいて自動承認するか判定 config.tool_confirm.auto_approve_safe が true の場合、SafetyHigh ツールは確認なしで実行
func NormalizeLeadingWhitespace ¶
NormalizeLeadingWhitespace は行頭の空白のみを正規化 - タブをスペース4つに変換 - 行頭の空白を削除 - 行内の空白は保持(安全性重視)
func ShowImprovedDiff ¶
func ShowImprovedDiff(oldStr, newStr string)
ShowImprovedDiff は改善された差分表示 ui.ShowColoredDiff を使用してインライン形式で表示
func ValidatePathAllowParent ¶
ValidatePathAllowParent は親ディレクトリへのアクセスを許可 (特定の用途でのみ使用)
Types ¶
type ConfirmAction ¶
type ConfirmAction string
ConfirmAction is the normalized action returned by confirmation prompts.
const ( ConfirmYes ConfirmAction = "yes" ConfirmNo ConfirmAction = "no" ConfirmComment ConfirmAction = "comment" )
type ConfirmDecision ¶
type ConfirmDecision struct {
Action ConfirmAction
Comment string
Image *ImageData
}
ConfirmDecision is the unified result for all confirmation prompts. Comment/Image are only set when Action==ConfirmComment.
func Confirm ¶
func Confirm(message string) ConfirmDecision
Confirm asks user for confirmation and optionally captures feedback. If interactive confirmation is enabled, it supports y/n/c and multi-line comments. Otherwise it falls back to legacy y/n confirm.
func ConfirmWithAutoApproveDecision ¶
func ConfirmWithAutoApproveDecision(toolName, message string) ConfirmDecision
ConfirmWithAutoApproveDecision は危険度を考慮した確認プロンプト toolName: 実行するツール名 message: 確認メッセージ - auto-approve の場合は yes を返す - それ以外は Confirm(message) を呼び、y/n/c の結果を返す
type ConfirmResult ¶
type ConfirmResult struct {
Action string // "yes", "no", "comment"
Comment string // "comment" の場合のコメント内容
Image *ImageData // 画像データ(オプション)
}
ConfirmResult は確認結果
type ImageData ¶
type ImageData struct {
Path string // 元のファイルパス
MediaType string // "image/png", "image/jpeg" 等
Base64 string // Base64エンコードされた画像データ
Size int64 // ファイルサイズ(バイト)
}
ImageData は画像データを表す
func ConfirmWithFeedback ¶
ConfirmWithFeedback は対話的確認を行う(互換ラッパー) interactiveMode=true の場合は y/n/c、false の場合は従来の y/n
NOTE: 新コードでは Confirm() / ConfirmDecision の利用を推奨。
type PatternMatchResult ¶
type PatternMatchResult struct {
MatchIdx int // マッチした行インデックス(-1 = not found)
MatchCount int // マッチ数
MatchIndices []int // 全マッチ位置
}
PatternMatchResult はパターンマッチの結果を保持
func FindPatternInLines ¶
func FindPatternInLines(lines []string, pattern string) PatternMatchResult
FindPatternInLines は行配列からパターンを検索 Tier 1: Exact match, Tier 2: Normalized whitespace match
type ToolSafety ¶
type ToolSafety int
ToolSafety はツールの安全性レベル
const ( // SafetyHigh - 読み取り専用操作(常に自動承認OK) SafetyHigh ToolSafety = iota // SafetyMedium - 書き込み操作(--auto-approve で承認) SafetyMedium // SafetyLow - 破壊的操作(常に確認必須) SafetyLow )
func GetToolSafety ¶
func GetToolSafety(toolName string) ToolSafety
GetToolSafety は指定されたツールの安全性レベルを返す 定義されていないツールは SafetyMedium(中レベル)として扱う