fix(copilot): mark internal hook injections as agent-initiated

Apply the internal initiator marker to automated continuation, recovery, babysitter, stop-hook, and hook-message injections so Copilot attribution consistently sets x-initiator=agent for system-generated prompts.
This commit is contained in:
Maxim Harizanov
2026-02-18 21:54:20 +02:00
parent a85f7efb1d
commit 850fb0378e
10 changed files with 39 additions and 15 deletions
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, test } from "bun:test"
import { _resetForTesting, setMainSession } from "../../features/claude-code-session-state"
import type { BackgroundTask } from "../../features/background-agent"
import { OMO_INTERNAL_INITIATOR_MARKER } from "../../shared/internal-initiator-marker"
import { createUnstableAgentBabysitterHook } from "./index"
const projectDir = process.cwd()
@@ -93,6 +94,7 @@ describe("unstable-agent-babysitter hook", () => {
expect(text).toContain("background_output")
expect(text).toContain("background_cancel")
expect(text).toContain("deep thought")
expect(text).toContain(OMO_INTERNAL_INITIATOR_MARKER)
})
test("fires reminder for hung minimax task", async () => {
@@ -128,6 +130,7 @@ describe("unstable-agent-babysitter hook", () => {
expect(text).toContain("background_output")
expect(text).toContain("background_cancel")
expect(text).toContain("minimax thought")
expect(text).toContain(OMO_INTERNAL_INITIATOR_MARKER)
})
test("does not remind stable model tasks", async () => {
@@ -1,7 +1,7 @@
import type { BackgroundManager } from "../../features/background-agent"
import { getMainSessionID, getSessionAgent } from "../../features/claude-code-session-state"
import { log } from "../../shared/logger"
import { resolveInheritedPromptTools } from "../../shared"
import { createInternalAgentTextPart, resolveInheritedPromptTools } from "../../shared"
import {
buildReminder,
extractMessages,
@@ -158,7 +158,7 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
...(agent ? { agent } : {}),
...(model ? { model } : {}),
...(tools ? { tools } : {}),
parts: [{ type: "text", text: reminder }],
parts: [createInternalAgentTextPart(reminder)],
},
query: { directory: ctx.directory },
})