Browse Source

tweak: ensure that compaction message is tracked as agent initiated (#17431)

Aiden Cline 7 months ago
parent
commit
88226f3061
1 changed files with 18 additions and 0 deletions
  1. 18 0
      packages/opencode/src/plugin/copilot.ts

+ 18 - 0
packages/opencode/src/plugin/copilot.ts

@@ -309,6 +309,24 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
         output.headers["anthropic-beta"] = "interleaved-thinking-2025-05-14"
       }
 
+      const parts = await sdk.session
+        .message({
+          path: {
+            id: incoming.message.sessionID,
+            messageID: incoming.message.id,
+          },
+          query: {
+            directory: input.directory,
+          },
+          throwOnError: true,
+        })
+        .catch(() => undefined)
+
+      if (parts?.data.parts?.some((part) => part.type === "compaction")) {
+        output.headers["x-initiator"] = "agent"
+        return
+      }
+
       const session = await sdk.session
         .get({
           path: {