compact 이후 컨텍스트 재주입과 일반 작업 최종 보고를 claw-code 스타일로 경량화
- compact boundary가 적용된 query view에 post_compact_context system 메시지를 추가해 복원된 파일/이미지 참조를 짧게 다시 전달함 - 일반 Cowork/Code 작업은 final-report 품질 프롬프트를 3줄 요약 중심으로 줄이고 review/high-impact 작업만 구조적 상세 보고를 유지함 - README.md 및 docs/DEVELOPMENT.md를 2026-04-12 23:14 (KST) 기준으로 갱신함 - 검증: dotnet build src/AxCopilot/AxCopilot.csproj -c Release -v minimal -p:OutputPath=bin\\verify\\ -p:IntermediateOutputPath=obj\\verify\\ (경고 0, 오류 0)
This commit is contained in:
@@ -22,6 +22,7 @@ public sealed class AgentQueryContextWindowResult
|
||||
public static class AgentQueryContextBuilder
|
||||
{
|
||||
private const int ProtectedRecentNonSystemMessages = 8;
|
||||
private const string PostCompactContextMetaKind = "post_compact_context";
|
||||
|
||||
public static AgentQueryContextWindowResult Build(IReadOnlyList<ChatMessage> sourceMessages)
|
||||
{
|
||||
@@ -60,6 +61,9 @@ public static class AgentQueryContextBuilder
|
||||
windowMessages.Add(CloneMessage(sourceMessages[i]));
|
||||
}
|
||||
|
||||
if (boundaryApplied)
|
||||
InjectPostCompactContextMessage(windowMessages);
|
||||
|
||||
var tokensBeforeBudget = TokenEstimator.EstimateMessages(windowMessages);
|
||||
var budgetResult = AgentToolResultBudget.Apply(windowMessages, ProtectedRecentNonSystemMessages);
|
||||
var tokensAfterBudget = TokenEstimator.EstimateMessages(windowMessages);
|
||||
@@ -134,4 +138,42 @@ public static class AgentQueryContextBuilder
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
private static void InjectPostCompactContextMessage(List<ChatMessage> messages)
|
||||
{
|
||||
if (messages.Count == 0)
|
||||
return;
|
||||
|
||||
if (messages.Any(m => string.Equals(m.MetaKind, PostCompactContextMetaKind, StringComparison.OrdinalIgnoreCase)))
|
||||
return;
|
||||
|
||||
var attachedFiles = messages
|
||||
.SelectMany(m => m.AttachedFiles ?? Enumerable.Empty<string>())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Take(5)
|
||||
.ToList();
|
||||
var imageCount = messages.Sum(m => m.Images?.Count ?? 0);
|
||||
|
||||
if (attachedFiles.Count == 0 && imageCount == 0)
|
||||
return;
|
||||
|
||||
var lines = new List<string> { "[post-compact context]" };
|
||||
if (attachedFiles.Count > 0)
|
||||
lines.Add("restored file refs: " + string.Join(", ", attachedFiles));
|
||||
if (imageCount > 0)
|
||||
lines.Add($"restored image refs: {imageCount}");
|
||||
|
||||
var insertIndex = 0;
|
||||
while (insertIndex < messages.Count && string.Equals(messages[insertIndex].Role, "system", StringComparison.OrdinalIgnoreCase))
|
||||
insertIndex++;
|
||||
|
||||
messages.Insert(insertIndex, new ChatMessage
|
||||
{
|
||||
Role = "system",
|
||||
MetaKind = PostCompactContextMetaKind,
|
||||
Content = string.Join("\n", lines),
|
||||
Timestamp = DateTime.Now,
|
||||
AttachedFiles = attachedFiles.Count > 0 ? attachedFiles : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user