From c7b2bba063ed294031b19b4d795cf068b7ce689b Mon Sep 17 00:00:00 2001 From: lacvet Date: Sun, 12 Apr 2026 22:18:55 +0900 Subject: [PATCH] =?UTF-8?q?compact=20=EC=9D=B4=ED=9B=84=20=EC=BB=A8?= =?UTF-8?q?=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=9E=AC=EC=A3=BC=EC=9E=85?= =?UTF-8?q?=EA=B3=BC=20=EC=9D=BC=EB=B0=98=20=EC=9E=91=EC=97=85=20=EC=B5=9C?= =?UTF-8?q?=EC=A2=85=20=EB=B3=B4=EA=B3=A0=EB=A5=BC=20claw-code=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=EB=A1=9C=20=EA=B2=BD=EB=9F=89=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- README.md | 4 ++ docs/DEVELOPMENT.md | 13 ++++++ .../Services/Agent/AgentLoopService.cs | 13 ++++-- .../Agent/AgentQueryContextBuilder.cs | 42 +++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eb6aeb5..4c1a8cf 100644 --- a/README.md +++ b/README.md @@ -1665,3 +1665,7 @@ MIT License - [AgentLoopTransitions.Documents.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Services/Agent/AgentLoopTransitions.Documents.cs) 는 `document_plan` 성공 직후 추가 user 압박 메시지를 넣지 않고, terminal 문서 도구 성공 시 Cowork에서 바로 종료할 수 있게 정리했습니다. - [AgentLoopTransitions.Verification.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Services/Agent/AgentLoopTransitions.Verification.cs) 는 `CodeDiffGate`, `RecentExecutionGate`, `ExecutionSuccessGate`를 review 작업 중심으로 제한해 일반 코드 수정의 과검증을 줄였습니다. - [TaskTypePolicy.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Services/Agent/TaskTypePolicy.cs), [ChatWindow.SystemPromptBuilder.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Views/ChatWindow.SystemPromptBuilder.cs), [cowork_문서작성.json](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Assets/Presets/cowork_%EB%AC%B8%EC%84%9C%EC%9E%91%EC%84%B1.json), [cowork_보고서.json](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Assets/Presets/cowork_%EB%B3%B4%EA%B3%A0%EC%84%9C.json) 도 같은 기준으로 문서 생성/텍스트 종료 조건을 더 얇게 맞췄습니다. +- 업데이트: 2026-04-12 23:14 (KST) + - compact 이후 query view에 복원된 파일/이미지 참조를 짧게 다시 주입해, `claw-code`의 post-compact attachment continuity에 더 가깝게 맞췄습니다. + - [AgentQueryContextBuilder.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs)는 compact boundary가 적용된 query view에 `post_compact_context` system 메시지를 추가해, 복원된 파일 참조와 이미지 참조 개수를 함께 전달합니다. + - [AgentLoopService.cs](/E:/AX%20Copilot%20-%20Codex/src/AxCopilot/Services/Agent/AgentLoopService.cs)의 final-report 품질 프롬프트는 일반 작업에서는 더 짧고 명확한 3줄 요약 중심으로 축소하고, review/high-impact 작업에만 구조적 상세 보고를 유지하도록 조정했습니다. diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index c3e8fc0..493ce6c 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -706,3 +706,16 @@ owKindCounts를 함께 남겨 %APPDATA%\\AxCopilot\\perf 기준으로 transcript - Code는 일반 수정 작업에서 review 수준의 무거운 follow-up gate가 덜 개입합니다. - 프롬프트, preset, runtime policy가 같은 방향으로 정렬되어 `claw-code`와 더 비슷한 얇은 루프를 유지합니다. +## post-compact context 재주입 / 일반 final-report 경량화 (2026-04-12 23:14 KST) + +- `claw-code`는 compact 뒤 attachment/tool/memory 상태를 다시 붙여 첫 post-compact turn이 맥락을 잃지 않게 만듭니다. AX는 파일명 continuity는 있었지만, query view에 “복원된 참조 상태”를 직접 실어주는 층이 약했습니다. +- `src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs` + - compact boundary가 적용된 query view에 `post_compact_context` system 메시지를 삽입합니다. + - 이 메시지는 compact 이후 다시 이어져야 하는 `AttachedFiles`와 이미지 개수를 짧게 요약해, LLM이 첫 post-compact turn에서 참조 맥락을 더 쉽게 복원하도록 돕습니다. +- `src/AxCopilot/Services/Agent/AgentLoopService.cs` + - `BuildFinalReportQualityPrompt()`를 일반 작업과 review/high-impact 작업으로 분기했습니다. + - 일반 작업은 `무엇을 변경했는지 / 무엇을 확인했는지 / 실제 미해결 이슈가 있을 때만 한 줄` 중심의 짧은 요약을 요구하고, review/high-impact만 기존의 구조적 상세 보고를 유지합니다. +- 기대 효과 + - compact 직후 첫 query turn이 복원된 파일/이미지 참조를 더 안정적으로 이어받습니다. + - 일반 Cowork/Code 작업의 최종 응답이 `claw-code`처럼 더 짧고 메타 밀도가 낮아집니다. + diff --git a/src/AxCopilot/Services/Agent/AgentLoopService.cs b/src/AxCopilot/Services/Agent/AgentLoopService.cs index 241eec5..334e3c5 100644 --- a/src/AxCopilot/Services/Agent/AgentLoopService.cs +++ b/src/AxCopilot/Services/Agent/AgentLoopService.cs @@ -3519,10 +3519,17 @@ public partial class AgentLoopService private static string BuildFinalReportQualityPrompt(TaskTypePolicy taskPolicy, bool highImpact) { + if (!taskPolicy.IsReviewTask && !highImpact) + { + return "[System:FinalReportQuality] 최종 답변을 짧고 명확하게 정리하세요.\n" + + "1. 무엇을 변경했는지\n" + + "2. 무엇을 확인했는지\n" + + "3. 실제 미해결 이슈가 있을 때만 한 줄로 적기\n" + + "불필요한 세부 목록, 메타 설명, 후속 권유는 쓰지 마세요."; + } + var taskLine = taskPolicy.FinalReportTaskLine; - var riskLine = taskPolicy.IsReviewTask || highImpact - ? "남은 리스크나 추가 확인 필요 사항이 실제로 남아 있을 때만 짧게 적으세요.\n" - : ""; + var riskLine = "남은 리스크나 추가 확인 필요 사항이 실제로 남아 있을 때만 짧게 적으세요.\n"; return "[System:FinalReportQuality] 최종 답변을 더 구조적으로 정리하세요.\n" + "1. 무엇을 변경했는지\n" + diff --git a/src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs b/src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs index 0ff30fd..f926c25 100644 --- a/src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs +++ b/src/AxCopilot/Services/Agent/AgentQueryContextBuilder.cs @@ -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 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 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()) + .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 { "[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, + }); + } }