Skip to content

Commit 2e52dbd

Browse files
committed
fix: set x-initiator header for compaction and synthetic messages
1 parent aedc4e9 commit 2e52dbd

6 files changed

Lines changed: 435 additions & 13 deletions

File tree

packages/opencode/src/plugin/github-copilot/copilot.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
324324
output.headers["anthropic-beta"] = "interleaved-thinking-2025-05-14"
325325
}
326326

327-
const parts = await sdk.session
327+
const msg = await sdk.session
328328
.message({
329329
path: {
330330
id: incoming.message.sessionID,
@@ -337,24 +337,30 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
337337
})
338338
.catch(() => undefined)
339339

340-
if (parts?.data.parts?.some((part) => part.type === "compaction")) {
340+
if (
341+
msg?.data?.parts?.some(
342+
(p) =>
343+
p.type === "compaction" ||
344+
(p.type === "text" && p.text === "[auto-compaction-followup]" && p.synthetic && p.ignored),
345+
)
346+
) {
341347
output.headers["x-initiator"] = "agent"
342348
return
343349
}
344350

345351
const session = await sdk.session
346352
.get({
347353
path: {
348-
id: incoming.sessionID,
354+
id: incoming.message.sessionID,
349355
},
350356
query: {
351357
directory: input.directory,
352358
},
353-
throwOnError: true,
354359
})
355360
.catch(() => undefined)
356-
if (!session || !session.data.parentID) return
357-
// mark subagent sessions as agent initiated matching standard that other copilot tools have
361+
if (!session?.data?.parentID) return
362+
const perms = (session.data as typeof session.data & { permission?: Array<{ permission: string }> }).permission
363+
if (perms?.some((r) => r.permission === "user_slash_command")) return
358364
output.headers["x-initiator"] = "agent"
359365
},
360366
}

packages/opencode/src/session/compaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,15 @@ When constructing the summary, try to stick to this template:
318318
agent: userMessage.agent,
319319
model: userMessage.model,
320320
})
321+
yield* session.updatePart({
322+
id: PartID.ascending(),
323+
messageID: continueMsg.id,
324+
sessionID: input.sessionID,
325+
type: "text",
326+
synthetic: true,
327+
ignored: true,
328+
text: "[auto-compaction-followup]",
329+
})
321330
const text =
322331
(input.overflow
323332
? "The previous request exceeded the provider's size limit due to large media attachments. The conversation was compacted and media files were removed from context. If the user was asking about attached images or files, explain that the attachments were too large to process and suggest they try again with smaller or fewer files.\n\n"

packages/opencode/src/tool/task.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ export const TaskTool = Tool.defineEffect(
7070
parentID: ctx.sessionID,
7171
title: params.description + ` (@${next.name} subagent)`,
7272
permission: [
73+
...(params.command
74+
? [
75+
{
76+
permission: "user_slash_command" as const,
77+
pattern: params.command,
78+
action: "allow" as const,
79+
},
80+
]
81+
: []),
7382
...(canTodo
7483
? []
7584
: [

0 commit comments

Comments
 (0)