extractFileCommandOptions extrai caminhos e opções do comando @file
(input string)
| 340 | |
| 341 | // extractFileCommandOptions extrai caminhos e opções do comando @file |
| 342 | func extractFileCommandOptions(input string) ([]string, map[string]string, error) { |
| 343 | var paths []string |
| 344 | options := make(map[string]string) |
| 345 | |
| 346 | // Regex atualizada para encontrar blocos @file com opções e caminho |
| 347 | // Aceita tanto "--key=value" quanto "--key value" |
| 348 | re := regexp.MustCompile(`@file((?:\s+--\w+(?:(?:=|\s+)\S+)?)*\s+[\w~/.-]+/?[\w.-]*)`) |
| 349 | matches := re.FindAllStringSubmatch(input, -1) |
| 350 | |
| 351 | for _, match := range matches { |
| 352 | if len(match) < 2 { |
| 353 | continue |
| 354 | } |
| 355 | |
| 356 | // Divide o bloco de comando em tokens |
| 357 | tokens := strings.Fields(match[1]) |
| 358 | var currentPath string |
| 359 | |
| 360 | // Itera sobre os tokens para separar opções do caminho |
| 361 | i := 0 |
| 362 | for i < len(tokens) { |
| 363 | token := tokens[i] |
| 364 | if strings.HasPrefix(token, "--") { |
| 365 | key := strings.TrimPrefix(token, "--") |
| 366 | // Formato --key=value |
| 367 | if parts := strings.SplitN(key, "=", 2); len(parts) == 2 { |
| 368 | options[parts[0]] = parts[1] |
| 369 | i++ |
| 370 | // Formato --key value |
| 371 | } else if i+1 < len(tokens) && !strings.HasPrefix(tokens[i+1], "--") { |
| 372 | options[key] = tokens[i+1] |
| 373 | i += 2 // Pula a chave e o valor |
| 374 | } else { |
| 375 | // Opção sem valor (flag booleana) |
| 376 | options[key] = "true" |
| 377 | i++ |
| 378 | } |
| 379 | } else { |
| 380 | // O primeiro token que não é opção é o caminho do arquivo |
| 381 | currentPath = token |
| 382 | break // Para a análise de opções para este comando @file |
| 383 | } |
| 384 | } |
| 385 | if currentPath != "" { |
| 386 | paths = append(paths, currentPath) |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if len(paths) == 0 && len(matches) > 0 { |
| 391 | return nil, nil, fmt.Errorf("comando @file encontrado, mas nenhum caminho válido foi especificado") |
| 392 | } |
| 393 | |
| 394 | return paths, options, nil |
| 395 | } |
| 396 | |
| 397 | func (cli *ChatCLI) processDirectorySummary(ctx context.Context, path string, tokenEstimator func(string) int, maxTokens int) (string, error) { |
| 398 | path, err := utils.ExpandPath(path) |
no test coverage detected