Files
AX-Copilot-Codex/src/AxCopilot/Services/Agent/OpenExternalTool.cs
lacvet 33c1db4dae
Some checks failed
Release Gate / gate (push) Has been cancelled
에이전트 선택적 탐색 구조 개선과 경고 정리 반영
- claude-code 선택적 탐색 흐름을 참고해 Cowork/Code 시스템 프롬프트에서 folder_map 상시 선행 지시를 완화하고 glob/grep 기반 좁은 탐색을 우선하도록 조정함

- FolderMapTool 기본 depth를 2로, include_files 기본값을 false로 낮추고 MultiReadTool 최대 파일 수를 8개로 줄여 초기 과탐색 폭을 보수적으로 조정함

- AgentLoopExplorationPolicy partial을 추가해 탐색 범위 분류, broad-scan corrective hint, exploration_breadth 성능 로그를 연결함

- AgentLoopService에 탐색 범위 가이드 주입과 실행 중 탐색 폭 추적을 추가하고, 좁은 질문에서 반복적인 folder_map/대량 multi_read를 교정하도록 정리함

- DocxToHtmlConverter nullable 경고를 수정해 Release 빌드 경고 0 / 오류 0 기준을 다시 충족함

- README와 docs/DEVELOPMENT.md에 2026-04-09 10:36 (KST) 기준 개발 이력을 반영함
2026-04-09 14:27:59 +09:00

74 lines
2.8 KiB
C#

using System.Diagnostics;
using System.IO;
using System.Text.Json;
namespace AxCopilot.Services.Agent;
/// <summary>파일/URL을 시스템 기본 앱으로 여는 도구.</summary>
public class OpenExternalTool : IAgentTool
{
public string Name => "open_external";
public string Description =>
"Open a file with its default application or open a URL in the default browser. " +
"Also supports opening a folder in File Explorer. " +
"Use after creating documents, reports, or charts for the user to view.";
public ToolParameterSchema Parameters => new()
{
Properties = new()
{
["path"] = new()
{
Type = "string",
Description = "File path, directory path, or URL to open",
},
},
Required = ["path"],
};
public Task<ToolResult> ExecuteAsync(JsonElement args, AgentContext context, CancellationToken ct = default)
{
var rawPath = args.GetProperty("path").SafeGetString() ?? "";
if (string.IsNullOrWhiteSpace(rawPath))
return Task.FromResult(ToolResult.Fail("경로가 비어 있습니다."));
try
{
// URL인 경우
if (rawPath.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
rawPath.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
if (AxCopilot.Services.OperationModePolicy.IsInternal(context.OperationMode))
return Task.FromResult(ToolResult.Fail("사내모드에서는 외부 URL 열기가 차단됩니다. operationMode=external에서만 사용할 수 있습니다."));
Process.Start(new ProcessStartInfo(rawPath) { UseShellExecute = true });
return Task.FromResult(ToolResult.Ok($"URL 열기: {rawPath}"));
}
// 파일/폴더 경로
var path = Path.IsPathRooted(rawPath) ? rawPath : Path.Combine(context.WorkFolder, rawPath);
if (!context.IsPathAllowed(path))
return Task.FromResult(ToolResult.Fail($"경로 접근 차단: {path}"));
if (File.Exists(path))
{
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
return Task.FromResult(ToolResult.Ok($"파일 열기: {path}", filePath: path));
}
if (Directory.Exists(path))
{
Process.Start(new ProcessStartInfo("explorer.exe", path));
return Task.FromResult(ToolResult.Ok($"폴더 열기: {path}", filePath: path));
}
return Task.FromResult(ToolResult.Fail($"경로를 찾을 수 없습니다: {path}"));
}
catch (Exception ex)
{
return Task.FromResult(ToolResult.Fail($"열기 오류: {ex.Message}"));
}
}
}