계층형 메모리 문서 로드 후 동일한 규칙 내용은 더 가까운 계층만 남기고 중복을 제거하도록 NormalizeInstructionDocuments 로직을 추가했습니다. 최종 메모리 문서는 managed, user, project, local 순서로 다시 정렬되고 우선순위 번호를 부여하며, MemoryTool의 list와 search 결과에서 그 우선순위를 함께 보여주도록 했습니다. README와 DEVELOPMENT 문서에 2026-04-07 00:39 (KST) 기준 이력을 반영했고 Release 빌드 경고 0 오류 0을 확인했습니다.
This commit is contained in:
@@ -107,9 +107,10 @@ public class MemoryTool : IAgentTool
|
||||
sb.AppendLine($"계층형 메모리 {docs.Count}개:");
|
||||
foreach (var doc in docs)
|
||||
{
|
||||
var priority = doc.Priority > 0 ? $" (우선순위 {doc.Priority})" : "";
|
||||
var suffix = string.IsNullOrWhiteSpace(doc.Description) ? "" : $" — {doc.Description}";
|
||||
var scopeHint = doc.Paths.Count > 0 ? $" (paths: {string.Join(", ", doc.Paths)})" : "";
|
||||
sb.AppendLine($" [{doc.Label}] {doc.Path}{suffix}{scopeHint}");
|
||||
sb.AppendLine($" [{doc.Label}] {doc.Path}{priority}{suffix}{scopeHint}");
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
@@ -136,9 +137,10 @@ public class MemoryTool : IAgentTool
|
||||
sb.AppendLine($"계층형 메모리 파일 {docs.Count}개:");
|
||||
foreach (var doc in docs)
|
||||
{
|
||||
var priority = doc.Priority > 0 ? $" (우선순위 {doc.Priority})" : "";
|
||||
var suffix = string.IsNullOrWhiteSpace(doc.Description) ? "" : $" — {doc.Description}";
|
||||
var scopeHint = doc.Paths.Count > 0 ? $" (paths: {string.Join(", ", doc.Paths)})" : "";
|
||||
sb.AppendLine($" • [{doc.Label}] {doc.Path}{suffix}{scopeHint}");
|
||||
sb.AppendLine($" • [{doc.Label}] {doc.Path}{priority}{suffix}{scopeHint}");
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ public class AgentMemoryService
|
||||
}
|
||||
|
||||
LoadInstructionDocuments(workFolder);
|
||||
NormalizeInstructionDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +417,8 @@ public class AgentMemoryService
|
||||
Path = fullPath,
|
||||
Content = frontMatter.Content.Trim(),
|
||||
Paths = frontMatter.Paths,
|
||||
Description = frontMatter.Description
|
||||
Description = frontMatter.Description,
|
||||
LoadOrder = _instructionDocuments.Count
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -425,6 +427,60 @@ public class AgentMemoryService
|
||||
}
|
||||
}
|
||||
|
||||
private void NormalizeInstructionDocuments()
|
||||
{
|
||||
if (_instructionDocuments.Count <= 1)
|
||||
return;
|
||||
|
||||
var seenNormalized = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var selected = new List<MemoryInstructionDocument>();
|
||||
|
||||
foreach (var doc in _instructionDocuments.OrderByDescending(d => d.LoadOrder))
|
||||
{
|
||||
var normalized = NormalizeInstructionContent(doc.Content);
|
||||
if (!string.IsNullOrWhiteSpace(normalized) && !seenNormalized.Add(normalized))
|
||||
continue;
|
||||
|
||||
selected.Add(doc);
|
||||
}
|
||||
|
||||
selected = selected
|
||||
.OrderBy(d => GetLayerRank(d.Layer))
|
||||
.ThenBy(d => d.LoadOrder)
|
||||
.ToList();
|
||||
|
||||
for (var i = 0; i < selected.Count; i++)
|
||||
{
|
||||
selected[i].Priority = i + 1;
|
||||
}
|
||||
|
||||
_instructionDocuments.Clear();
|
||||
_instructionDocuments.AddRange(selected);
|
||||
}
|
||||
|
||||
private static string NormalizeInstructionContent(string content)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
return "";
|
||||
|
||||
var normalizedLines = content
|
||||
.Replace("\r\n", "\n")
|
||||
.Split('\n')
|
||||
.Select(line => string.Join(" ", line.Split(' ', '\t').Where(part => part.Length > 0)).Trim())
|
||||
.Where(line => line.Length > 0);
|
||||
|
||||
return string.Join("\n", normalizedLines).Trim();
|
||||
}
|
||||
|
||||
private static int GetLayerRank(string layer) => layer switch
|
||||
{
|
||||
"managed" => 0,
|
||||
"user" => 1,
|
||||
"project" => 2,
|
||||
"local" => 3,
|
||||
_ => 9
|
||||
};
|
||||
|
||||
private static IEnumerable<string> EnumerateDirectoryChain(string projectRoot, string workFolder)
|
||||
{
|
||||
var current = Path.GetFullPath(workFolder);
|
||||
@@ -804,4 +860,10 @@ public class MemoryInstructionDocument
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string Description { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("loadOrder")]
|
||||
public int LoadOrder { get; set; }
|
||||
|
||||
[JsonPropertyName("priority")]
|
||||
public int Priority { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user