스킬 정책 제어와 inline shell 안전장치 추가
스킬 시스템 설정에 프로젝트 스킬 탐색, 플러그인 스킬 탐색, 레거시 command 스킬 호환, inline shell 허용 여부와 시간/출력 제한을 추가하고 일반 설정 및 AX Agent 설정 UI에 연결했다. SkillService는 로드 시그니처에 실제 스킬 파일 수와 최근 수정 시각을 반영하도록 보강해 같은 폴더라도 스킬 파일이 바뀌면 다음 로드 요청에서 자동으로 재탐색되도록 정리했다. inline shell 실행기는 설정 기반 비활성화, timeout, 최대 출력 길이 제한을 적용하고 스킬 편집기/갤러리는 lazy prompt body 경로와 ReloadFromCurrentSettings()를 사용하도록 맞췄다. 검증: dotnet build src/AxCopilot/AxCopilot.csproj -c Release -v minimal -p:OutputPath=bin\\verify_phase4b\\ -p:IntermediateOutputPath=obj\\verify_phase4b\\ (경고 0 / 오류 0) 검증: dotnet test src/AxCopilot.Tests/AxCopilot.Tests.csproj -c Release -v minimal --filter "AgentToolCatalogTests|SkillServiceRuntimePolicyTests" -p:OutputPath=bin\\verify_phase4b_tests\\ -p:IntermediateOutputPath=obj\\verify_phase4b_tests\\ (통과 18, 기존 WorkspaceContextGeneratorTests nullable 경고 1건 유지)
This commit is contained in:
@@ -23,6 +23,13 @@ public static class SkillService
|
||||
/// <summary>로드된 스킬 목록.</summary>
|
||||
public static IReadOnlyList<SkillDefinition> Skills => _skills;
|
||||
|
||||
public static void ReloadFromCurrentSettings(string? projectRoot = null)
|
||||
{
|
||||
var app = System.Windows.Application.Current as App;
|
||||
var llm = app?.SettingsService?.Settings.Llm;
|
||||
LoadSkills(llm?.SkillsFolderPath, projectRoot ?? llm?.WorkFolder, llm?.AdditionalSkillFolders);
|
||||
}
|
||||
|
||||
/// <summary>스킬 폴더에서 *.skill.md / SKILL.md 파일을 로드합니다.</summary>
|
||||
public static void LoadSkills(string? customFolder = null, string? projectRoot = null, IEnumerable<string>? additionalFolders = null)
|
||||
{
|
||||
@@ -30,7 +37,7 @@ public static class SkillService
|
||||
var normalizedProjectRoot = NormalizeExistingDirectory(projectRoot);
|
||||
var normalizedAdditionalFolders = NormalizeDistinctDirectories(additionalFolders);
|
||||
var sources = BuildSkillSources(normalizedCustomFolder, normalizedProjectRoot, normalizedAdditionalFolders).ToList();
|
||||
var loadSignature = string.Join("|", sources.Select(source => $"{source.Kind}:{source.Scope}:{source.Directory}"));
|
||||
var loadSignature = ComputeLoadSignature(sources);
|
||||
if (_skills.Count > 0 && string.Equals(_lastLoadSignature, loadSignature, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
||||
@@ -324,6 +331,8 @@ public static class SkillService
|
||||
string? projectRoot,
|
||||
IEnumerable<string> additionalFolders)
|
||||
{
|
||||
var app = System.Windows.Application.Current as App;
|
||||
var llm = app?.SettingsService?.Settings.Llm;
|
||||
var sources = new List<SkillSourceDescriptor>();
|
||||
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -344,18 +353,44 @@ public static class SkillService
|
||||
foreach (var folder in additionalFolders)
|
||||
AddSource(folder, "additional");
|
||||
|
||||
foreach (var folder in EnumeratePluginSkillFolders())
|
||||
AddSource(folder, "plugin");
|
||||
if (llm?.EnablePluginSkillDiscovery ?? true)
|
||||
{
|
||||
foreach (var folder in EnumeratePluginSkillFolders())
|
||||
AddSource(folder, "plugin");
|
||||
}
|
||||
|
||||
foreach (var folder in EnumerateProjectSkillFolders(projectRoot))
|
||||
AddSource(folder, "project");
|
||||
if (llm?.EnableProjectSkillDiscovery ?? true)
|
||||
{
|
||||
foreach (var folder in EnumerateProjectSkillFolders(projectRoot))
|
||||
AddSource(folder, "project");
|
||||
}
|
||||
|
||||
foreach (var folder in EnumerateLegacyCommandFolders(projectRoot))
|
||||
AddSource(folder, "legacy", SkillSourceKind.LegacyCommand);
|
||||
if (llm?.EnableLegacyCommandSkills ?? true)
|
||||
{
|
||||
foreach (var folder in EnumerateLegacyCommandFolders(projectRoot))
|
||||
AddSource(folder, "legacy", SkillSourceKind.LegacyCommand);
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
private static string ComputeLoadSignature(IEnumerable<SkillSourceDescriptor> sources)
|
||||
{
|
||||
var parts = new List<string>();
|
||||
foreach (var source in sources)
|
||||
{
|
||||
var files = source.Kind == SkillSourceKind.LegacyCommand
|
||||
? EnumerateLegacyCommandFiles(source.Directory).ToList()
|
||||
: EnumerateSkillFiles(source.Directory).ToList();
|
||||
var latestWrite = files.Count == 0
|
||||
? Directory.GetLastWriteTimeUtc(source.Directory).Ticks
|
||||
: files.Max(file => File.GetLastWriteTimeUtc(file).Ticks);
|
||||
parts.Add($"{source.Kind}:{source.Scope}:{source.Directory}:{files.Count}:{latestWrite}");
|
||||
}
|
||||
|
||||
return string.Join("|", parts);
|
||||
}
|
||||
|
||||
private static IEnumerable<string> EnumerateProjectSkillFolders(string? projectRoot)
|
||||
{
|
||||
foreach (var root in EnumerateAncestorDirectories(projectRoot))
|
||||
@@ -1332,8 +1367,17 @@ public static class SkillService
|
||||
string workFolder,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var app = System.Windows.Application.Current as App;
|
||||
var llm = app?.SettingsService?.Settings.Llm;
|
||||
if (llm is { EnableSkillInlineShell: false })
|
||||
return "[inline-shell disabled by settings]";
|
||||
|
||||
var timeoutSeconds = Math.Clamp(llm?.SkillInlineShellTimeoutSeconds ?? 8, 1, 30);
|
||||
var maxOutputChars = Math.Clamp(llm?.SkillInlineShellMaxOutputChars ?? 4000, 200, 20000);
|
||||
try
|
||||
{
|
||||
using var timeoutCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
timeoutCts.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds));
|
||||
var startInfo = shellKind == "powershell"
|
||||
? new System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
@@ -1362,14 +1406,18 @@ public static class SkillService
|
||||
|
||||
using var process = new System.Diagnostics.Process { StartInfo = startInfo };
|
||||
process.Start();
|
||||
var stdout = await process.StandardOutput.ReadToEndAsync(ct).ConfigureAwait(false);
|
||||
var stderr = await process.StandardError.ReadToEndAsync(ct).ConfigureAwait(false);
|
||||
await process.WaitForExitAsync(ct).ConfigureAwait(false);
|
||||
var stdout = await process.StandardOutput.ReadToEndAsync(timeoutCts.Token).ConfigureAwait(false);
|
||||
var stderr = await process.StandardError.ReadToEndAsync(timeoutCts.Token).ConfigureAwait(false);
|
||||
await process.WaitForExitAsync(timeoutCts.Token).ConfigureAwait(false);
|
||||
var output = string.IsNullOrWhiteSpace(stdout) ? stderr : stdout;
|
||||
if (string.IsNullOrWhiteSpace(output))
|
||||
return "[inline-shell: no output]";
|
||||
output = output.Trim();
|
||||
return output.Length > 4000 ? output[..4000] : output;
|
||||
return output.Length > maxOutputChars ? output[..maxOutputChars] : output;
|
||||
}
|
||||
catch (OperationCanceledException) when (!ct.IsCancellationRequested)
|
||||
{
|
||||
return $"[inline-shell timeout] exceeded {timeoutSeconds}s";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user