From 0b84cdd3bbfce0e6e76d67c91030a4d5b67cffc8 Mon Sep 17 00:00:00 2001 From: AshSgDe29071999 Date: Thu, 13 Aug 2026 18:03:57 +0530 Subject: [PATCH 1/7] fix: canonicalize Copilot task and web_search tool names COPILOT_TOOL_MAP missed task and web_search, so policies matching Task silently never fired on Copilot. ask_user is left unmapped: it has no filesystem or shell reach. Fixes #690 (cherry picked from commit 3d819ab87526b815888d72960f47f0e2c9ae4809) --- __tests__/hooks/copilot-canonicalize.test.ts | 2 ++ __tests__/hooks/handler.test.ts | 2 ++ src/hooks/types.ts | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/__tests__/hooks/copilot-canonicalize.test.ts b/__tests__/hooks/copilot-canonicalize.test.ts index 16293d5af..fc608d05e 100644 --- a/__tests__/hooks/copilot-canonicalize.test.ts +++ b/__tests__/hooks/copilot-canonicalize.test.ts @@ -60,6 +60,8 @@ describe("Copilot tool-input canonicalization (verified 1.0.71 captures)", () => // permissionRequest delivers `toolName: "bash"` (lowercase) even on 1.0.71. expect(canonicalizeToolName("bash", "copilot")).toBe("Bash"); expect(canonicalizeToolName("view", "copilot")).toBe("Read"); + expect(canonicalizeToolName("task", "copilot")).toBe("Task"); + expect(canonicalizeToolName("web_search", "copilot")).toBe("WebSearch"); }); it("only maps the three file tools (no accidental key rewrites elsewhere)", () => { diff --git a/__tests__/hooks/handler.test.ts b/__tests__/hooks/handler.test.ts index ca426c8d3..a82dea207 100644 --- a/__tests__/hooks/handler.test.ts +++ b/__tests__/hooks/handler.test.ts @@ -469,6 +469,8 @@ describe("hooks/handler", () => { ["rg", "Grep"], ["ls", "LS"], ["web_fetch", "WebFetch"], + ["task", "Task"], + ["web_search", "WebSearch"], ]; for (const [raw, canonical] of cases) { vi.mocked(evaluatePolicies).mockResolvedValueOnce({ diff --git a/src/hooks/types.ts b/src/hooks/types.ts index dc9a87d19..f52763c1a 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -282,6 +282,12 @@ export const COPILOT_TOOL_MAP: Record = { rg: "Grep", ls: "LS", web_fetch: "WebFetch", + // Copilot CLI documents `task` and `web_search`. Unmapped names pass + // through raw, so a policy matching toolName === "Task" silently never + // fires. `ask_user` is left unmapped: it has no filesystem or shell + // reach, so treating it as a no-op canonicalization is the safer call. + task: "Task", + web_search: "WebSearch", }; /** From 1095a7edb54f63a5034df61ecf7c2c90868d5ba9 Mon Sep 17 00:00:00 2001 From: ZxlDragonDoctor <152901610+ZxlDragonDoctor@users.noreply.github.com> Date: Thu, 10 Sep 2026 19:18:02 +0800 Subject: [PATCH 2/7] fix(hooks): map Copilot task/web_search in COPILOT_TOOL_MAP Without these entries a policy matching toolName === Task or WebSearch silently never fires on Copilot sessions. ask_user is left unmapped (no filesystem or shell reach). Fixes #690 (cherry picked from commit 078b599f7c455b0f0b3b1eac9070790cdf345747) --- src/hooks/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/types.ts b/src/hooks/types.ts index f52763c1a..d1a8e579c 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -282,10 +282,10 @@ export const COPILOT_TOOL_MAP: Record = { rg: "Grep", ls: "LS", web_fetch: "WebFetch", - // Copilot CLI documents `task` and `web_search`. Unmapped names pass - // through raw, so a policy matching toolName === "Task" silently never - // fires. `ask_user` is left unmapped: it has no filesystem or shell - // reach, so treating it as a no-op canonicalization is the safer call. + // Documented Copilot tools that launch subagents / web search. Without these + // entries a policy matching `toolName === "Task"` (or `"WebSearch"`) + // silently never fires on Copilot — the worst failure mode for a guardrail. + // `ask_user` is intentionally unmapped: it has no filesystem or shell reach. task: "Task", web_search: "WebSearch", }; From 5f36489f61a73970227609edd238005107b01652 Mon Sep 17 00:00:00 2001 From: lakshya-dhariwal Date: Sun, 27 Sep 2026 19:13:27 +0530 Subject: [PATCH 3/7] fix(copilot): map task and web_search to canonical Task/WebSearch (#690) (cherry picked from commit 06209553816decf381ff55e060ba1c1842d8e96d) --- __tests__/hooks/copilot-canonicalize.test.ts | 10 ++++++++++ src/hooks/types.ts | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/__tests__/hooks/copilot-canonicalize.test.ts b/__tests__/hooks/copilot-canonicalize.test.ts index fc608d05e..fb13ed2e2 100644 --- a/__tests__/hooks/copilot-canonicalize.test.ts +++ b/__tests__/hooks/copilot-canonicalize.test.ts @@ -68,3 +68,13 @@ describe("Copilot tool-input canonicalization (verified 1.0.71 captures)", () => expect(Object.keys(COPILOT_TOOL_INPUT_MAP).sort()).toEqual(["Edit", "Read", "Write"]); }); }); + +describe("Copilot tool-name canonicalization", () => { + it("maps `task` to Task so sub-agent policies fire on Copilot sessions", () => { + expect(canonicalizeToolName("task", "copilot")).toBe("Task"); + }); + + it("maps `web_search` to WebSearch", () => { + expect(canonicalizeToolName("web_search", "copilot")).toBe("WebSearch"); + }); +}); diff --git a/src/hooks/types.ts b/src/hooks/types.ts index d1a8e579c..b029943b3 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -282,10 +282,11 @@ export const COPILOT_TOOL_MAP: Record = { rg: "Grep", ls: "LS", web_fetch: "WebFetch", - // Documented Copilot tools that launch subagents / web search. Without these - // entries a policy matching `toolName === "Task"` (or `"WebSearch"`) - // silently never fires on Copilot — the worst failure mode for a guardrail. - // `ask_user` is intentionally unmapped: it has no filesystem or shell reach. + // Copilot's sub-agent and web-search tools (documented). Without these a + // policy matching `Task` or `WebSearch` silently never fires on Copilot - + // the names pass through uncanonicalised, same failure mode the rest of + // this map exists to prevent. `ask_user` is deliberately unmapped: it has + // no filesystem or shell reach, so no builtin policy targets it. task: "Task", web_search: "WebSearch", }; From b6e490ac94030b49c58f1b896c5a8b342b56e32b Mon Sep 17 00:00:00 2001 From: lakshya-dhariwal Date: Sun, 27 Sep 2026 19:24:21 +0530 Subject: [PATCH 4/7] fix(hooks): canonicalize Copilot PascalCase 'Agent' tool name to Task PascalCase PreToolUse payloads report tool_name as the Claude tool name, and GitHub's hooks reference maps the runtime task tool to Agent there - so a Task policy still skipped Copilot's task calls under the shape this integration actually registers. (cherry picked from commit 1ef98d76d987a9bec8ae9456489e07726bb406bb) --- __tests__/hooks/copilot-canonicalize.test.ts | 4 ++++ src/hooks/types.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/__tests__/hooks/copilot-canonicalize.test.ts b/__tests__/hooks/copilot-canonicalize.test.ts index fb13ed2e2..5f8a1f604 100644 --- a/__tests__/hooks/copilot-canonicalize.test.ts +++ b/__tests__/hooks/copilot-canonicalize.test.ts @@ -74,6 +74,10 @@ describe("Copilot tool-name canonicalization", () => { expect(canonicalizeToolName("task", "copilot")).toBe("Task"); }); + it("maps `Agent` to Task - the PascalCase PreToolUse payload reports the Claude name", () => { + expect(canonicalizeToolName("Agent", "copilot")).toBe("Task"); + }); + it("maps `web_search` to WebSearch", () => { expect(canonicalizeToolName("web_search", "copilot")).toBe("WebSearch"); }); diff --git a/src/hooks/types.ts b/src/hooks/types.ts index b029943b3..6ce4a6b63 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -288,6 +288,13 @@ export const COPILOT_TOOL_MAP: Record = { // this map exists to prevent. `ask_user` is deliberately unmapped: it has // no filesystem or shell reach, so no builtin policy targets it. task: "Task", + // PascalCase `PreToolUse` payloads (the shape failproofai registers) report + // `tool_name` as the Claude tool name, and the docs table maps the runtime + // `task` tool to `Agent` there. Without this entry a Task policy still + // never fires on Copilot's PascalCase payload - the more common of the two + // shapes for this integration. + // Ref: https://docs.github.com/en/copilot/reference/hooks-reference + Agent: "Task", web_search: "WebSearch", }; From bc8e3242ba8a33b8f0a4ab1a4abb2d05778106d9 Mon Sep 17 00:00:00 2001 From: NiveditJain Date: Mon, 30 Nov 2026 17:18:05 +0530 Subject: [PATCH 5/7] [hooks] Combine the #690 fixes into one Copilot mapping and test set The three community fixes for #690 each added `task` and `web_search` to COPILOT_TOOL_MAP; #844 also added `Agent`, the name GitHub's hooks reference gives the `task` tool on PascalCase PreToolUse payloads. This merges their comments into one block that says which payload carries which name, and de-duplicates the tests: the lowercase IDs stay in the permissionRequest test, the `Agent` case keeps its own describe block, and canonical `Task`/`WebSearch` are checked to pass through. handler.test.ts gains `Agent` in its table, an assertion that the table covers every COPILOT_TOOL_MAP key, and a permissionRequest test with `toolName: "task"`, the path where Copilot still sends runtime IDs. Co-Authored-By: Claude Opus 5.5 --- __tests__/hooks/copilot-canonicalize.test.ts | 13 +++++----- __tests__/hooks/handler.test.ts | 27 ++++++++++++++++++++ src/hooks/types.ts | 24 +++++++++-------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/__tests__/hooks/copilot-canonicalize.test.ts b/__tests__/hooks/copilot-canonicalize.test.ts index 5f8a1f604..bc2eb111f 100644 --- a/__tests__/hooks/copilot-canonicalize.test.ts +++ b/__tests__/hooks/copilot-canonicalize.test.ts @@ -69,16 +69,15 @@ describe("Copilot tool-input canonicalization (verified 1.0.71 captures)", () => }); }); -describe("Copilot tool-name canonicalization", () => { - it("maps `task` to Task so sub-agent policies fire on Copilot sessions", () => { - expect(canonicalizeToolName("task", "copilot")).toBe("Task"); - }); - +// The lowercase `task` / `web_search` IDs are covered by the permissionRequest +// test above; these are the names the PascalCase payloads report. +describe("Copilot subagent and web-search tool names (#690)", () => { it("maps `Agent` to Task - the PascalCase PreToolUse payload reports the Claude name", () => { expect(canonicalizeToolName("Agent", "copilot")).toBe("Task"); }); - it("maps `web_search` to WebSearch", () => { - expect(canonicalizeToolName("web_search", "copilot")).toBe("WebSearch"); + it("passes the canonical `Task` and `WebSearch` through unchanged", () => { + expect(canonicalizeToolName("Task", "copilot")).toBe("Task"); + expect(canonicalizeToolName("WebSearch", "copilot")).toBe("WebSearch"); }); }); diff --git a/__tests__/hooks/handler.test.ts b/__tests__/hooks/handler.test.ts index a82dea207..b13f94269 100644 --- a/__tests__/hooks/handler.test.ts +++ b/__tests__/hooks/handler.test.ts @@ -19,6 +19,7 @@ import { mkdtempSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { handleHookEvent, evaluateHookEvent } from "../../src/hooks/handler"; +import { COPILOT_TOOL_MAP } from "../../src/hooks/types"; vi.mock("../../src/hooks/hooks-config", () => ({ readMergedHooksConfig: vi.fn(() => ({ enabledPolicies: ["block-sudo"] })), @@ -249,6 +250,29 @@ describe("hooks/handler", () => { ); }); + it("canonicalizes the lowercase `task` ID a Copilot permissionRequest carries (#690)", async () => { + // permissionRequest is where Copilot still sends runtime IDs. Without the + // `task` entry a PermissionRequest policy matching `Task` never fires. + mockStdin( + JSON.stringify({ + hookName: "permissionRequest", + sessionId: "e5740815-966c-4c4e-8c51-153a8f1fa466", + timestamp: 1784186747245, + cwd: "/home/user/project", + toolName: "task", + toolInput: { description: "Explore the repo", prompt: "List the hooks" }, + permissionSuggestions: [], + }), + ); + const { persistHookActivity } = await import("../../src/hooks/hook-activity-store"); + + await handleHookEvent("PermissionRequest", "copilot"); + + expect(persistHookActivity).toHaveBeenCalledWith( + expect.objectContaining({ eventType: "PermissionRequest", integration: "copilot", toolName: "Task" }), + ); + }); + it("flushes pending telemetry before returning, even on the allow path", async () => { // The allow path fires no awaited event, so without an explicit flush the // caller's process.exit() would drop un-awaited (`void`) load/error events. @@ -470,8 +494,11 @@ describe("hooks/handler", () => { ["ls", "LS"], ["web_fetch", "WebFetch"], ["task", "Task"], + ["Agent", "Task"], ["web_search", "WebSearch"], ]; + // Keeps the test name true: a map entry with no case here fails. + expect(cases.map(([raw]) => raw).sort()).toEqual(Object.keys(COPILOT_TOOL_MAP).sort()); for (const [raw, canonical] of cases) { vi.mocked(evaluatePolicies).mockResolvedValueOnce({ exitCode: 0, stdout: "", stderr: "", policyName: null, reason: null, decision: "allow", diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 6ce4a6b63..1b336b892 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -282,18 +282,20 @@ export const COPILOT_TOOL_MAP: Record = { rg: "Grep", ls: "LS", web_fetch: "WebFetch", - // Copilot's sub-agent and web-search tools (documented). Without these a - // policy matching `Task` or `WebSearch` silently never fires on Copilot - - // the names pass through uncanonicalised, same failure mode the rest of - // this map exists to prevent. `ask_user` is deliberately unmapped: it has - // no filesystem or shell reach, so no builtin policy targets it. + // The subagent launcher and web search (#690). Unmapped names pass through + // raw, so without these a policy matching `Task` or `WebSearch` silently + // never fires on Copilot. Copilot reports each tool under one of two names: + // - the runtime ID (`task`, `web_search`) on the camelCase + // `permissionRequest` payload and from older CLIs; + // - the Claude name on the PascalCase `PreToolUse`/`PostToolUse` payloads + // failproofai registers. GitHub's hooks reference maps `task` to `Agent` + // there (`web_search` becomes `WebSearch`, already canonical), so `Agent` + // needs an entry of its own. That mapping is from the reference, not yet + // from a live capture. + // Ref: https://docs.github.com/en/copilot/reference/hooks-reference + // `ask_user` is deliberately unmapped: it has no filesystem or shell reach, + // so no builtin policy targets it. task: "Task", - // PascalCase `PreToolUse` payloads (the shape failproofai registers) report - // `tool_name` as the Claude tool name, and the docs table maps the runtime - // `task` tool to `Agent` there. Without this entry a Task policy still - // never fires on Copilot's PascalCase payload - the more common of the two - // shapes for this integration. - // Ref: https://docs.github.com/en/copilot/reference/hooks-reference Agent: "Task", web_search: "WebSearch", }; From c6a738e6906399d933357d28185f96cacd0374d0 Mon Sep 17 00:00:00 2001 From: NiveditJain Date: Mon, 30 Nov 2026 17:19:12 +0530 Subject: [PATCH 6/7] [hooks] CHANGELOG entry for the Copilot task/web_search mapping (#1101) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7678d21d0..2bfde4e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Copilot: map the `task` tool to `Task` (under both its runtime ID and the `Agent` name PascalCase payloads report) and `web_search` to `WebSearch`, so policies matching `Task` or `WebSearch` fire on Copilot sessions instead of silently never running (#1101, from #693, #792, #844, fixes #690) - Drop the `skills` submodule and its daily Dependabot `gitsubmodule` entry. Nothing in this repo read it, nor did the npm package or any workflow, and the job in `FailproofAI/skills` that kept it current failed on every merge once the version-bot App was gone. The skills reach users through `npx skills add FailproofAI/skills`, which this pin never fed (#1075) - Delete `sync-fp-cloud-cli-skill.yml` and `sync-failproofai-sdk-skill.yml`, red on every run since August because the `SKILLS_SYNC_PAT` they pushed to `FailproofAI/skills` with was never created; that repo now pulls both skills from this public one with its own token, so nothing here holds a credential that writes to it. The fp-cloud-cli skill's description is cut from 1118 to 995 characters, under the 1024 that the skills repo's validator enforces and past which Copilot drops a skill (#1068) - Add a global `--no-color` flag, the same as `NO_COLOR=1`, accepted before or after any command; `failproofai policies` already honors `NO_COLOR` (#1067, from #695, #700, #848, fixes #688) From bca4b9e880284b38cfb2aee74bb6746d13feb947 Mon Sep 17 00:00:00 2001 From: NiveditJain Date: Mon, 30 Nov 2026 17:31:12 +0530 Subject: [PATCH 7/7] [hooks] Verify the Copilot task mapping live against Copilot CLI 1.0.117 A recorder hook in failproofai's own PascalCase Copilot config shape captured a real `task` call on Copilot CLI 1.0.117: PreToolUse, PostToolUse and PostToolUseFailure report it as `tool_name: "Agent"`, camelCase hooks as `task`, and Copilot's session log (events.jsonl, read by the audit replay) as `task`. permissionRequest fired for the subagent's bash call but not for `task` itself, so the comment no longer claims it does, and the handler test built on that claim is replaced. `web_search` was not offered to the verifying account, so its entries still rest on GitHub's hooks reference. New tests use the captured payloads: an e2e run of the real CLI where a custom policy with `toolNames: ["Task"]` denies the `Agent` PreToolUse and allows the subagent's Bash call (the deny test fails without the `Agent` entry), and a parser test that audits the recorded `task` execution as Task. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- __tests__/e2e/helpers/payloads.ts | 32 +++++++++++ .../e2e/hooks/copilot-integration.e2e.test.ts | 53 +++++++++++++++++++ __tests__/hooks/copilot-canonicalize.test.ts | 4 +- __tests__/hooks/handler.test.ts | 23 -------- __tests__/lib/copilot-sessions.test.ts | 27 ++++++++++ src/hooks/types.ts | 22 ++++---- 7 files changed, 128 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bfde4e29..0b0a8fb62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixes -- Copilot: map the `task` tool to `Task` (under both its runtime ID and the `Agent` name PascalCase payloads report) and `web_search` to `WebSearch`, so policies matching `Task` or `WebSearch` fire on Copilot sessions instead of silently never running (#1101, from #693, #792, #844, fixes #690) +- Copilot: map the `task` tool to `Task` and `web_search` to `WebSearch`, so policies matching them fire on Copilot sessions instead of silently never running. The subagent tool reaches the PascalCase hooks as `Agent` (verified against Copilot CLI 1.0.117) and Copilot's session log as `task`, so both names map (#1101, from #693, #792, #844, fixes #690) - Drop the `skills` submodule and its daily Dependabot `gitsubmodule` entry. Nothing in this repo read it, nor did the npm package or any workflow, and the job in `FailproofAI/skills` that kept it current failed on every merge once the version-bot App was gone. The skills reach users through `npx skills add FailproofAI/skills`, which this pin never fed (#1075) - Delete `sync-fp-cloud-cli-skill.yml` and `sync-failproofai-sdk-skill.yml`, red on every run since August because the `SKILLS_SYNC_PAT` they pushed to `FailproofAI/skills` with was never created; that repo now pulls both skills from this public one with its own token, so nothing here holds a credential that writes to it. The fp-cloud-cli skill's description is cut from 1118 to 995 characters, under the 1024 that the skills repo's validator enforces and past which Copilot drops a skill (#1068) - Add a global `--no-color` flag, the same as `NO_COLOR=1`, accepted before or after any command; `failproofai policies` already honors `NO_COLOR` (#1067, from #695, #700, #848, fixes #688) diff --git a/__tests__/e2e/helpers/payloads.ts b/__tests__/e2e/helpers/payloads.ts index c9d4dac75..42b47e738 100644 --- a/__tests__/e2e/helpers/payloads.ts +++ b/__tests__/e2e/helpers/payloads.ts @@ -357,6 +357,38 @@ export const CopilotPayloads = { tool_input: { path }, }; }, + // Captured from Copilot CLI 1.0.117 (recorder hook in failproofai's own + // PascalCase config shape, 2026-11-30): the `task` tool arrives as + // `Agent`, the subagent's shell call as canonical `Bash`. Only session_id, + // timestamp and cwd are replaced. + agent(cwd: string): Record { + return { + hook_event_name: "PreToolUse", + session_id: COPILOT_SESSION_ID, + timestamp: "2026-11-30T11:55:49.223Z", + cwd, + tool_use_id: "call_F7DYfcHRV6zTOjWmqsRPetqr", + tool_name: "Agent", + tool_input: { + description: "Run echo command", + prompt: "Your only job is to run the exact shell command `echo subagent-ok` and report the exact output. Do not perform any other task.", + name: "echo-agent", + agent_type: "task", + mode: "sync", + }, + }; + }, + subagentBash(cwd: string): Record { + return { + hook_event_name: "PreToolUse", + session_id: COPILOT_SESSION_ID, + timestamp: "2026-11-30T11:55:58.914Z", + cwd, + tool_use_id: "call_SUnS51NrSOII6SSLrh6DxW6K", + tool_name: "Bash", + tool_input: { command: "echo subagent-ok", description: "Run the exact requested echo command" }, + }; + }, }, postToolUse: { bash(command: string, output: string, cwd: string): Record { diff --git a/__tests__/e2e/hooks/copilot-integration.e2e.test.ts b/__tests__/e2e/hooks/copilot-integration.e2e.test.ts index 1bc0ffcc4..996adb384 100644 --- a/__tests__/e2e/hooks/copilot-integration.e2e.test.ts +++ b/__tests__/e2e/hooks/copilot-integration.e2e.test.ts @@ -343,3 +343,56 @@ describe("E2E: Copilot integration — install/uninstall", () => { } }); }); + +// #690: Copilot reports its subagent tool as `Agent` on the PascalCase hooks +// failproofai registers. Payloads below are captured from Copilot CLI 1.0.117. +describe("E2E: Copilot subagent tool reaches a Task policy (#690)", () => { + function writeTaskPolicy(cwd: string): void { + const policyPath = resolve(cwd, "no-subagents.mjs"); + writeFileSync( + policyPath, + `import { customPolicies, deny } from "failproofai"; +customPolicies.add({ + name: "no-subagents", + description: "Deny every subagent launch", + match: { events: ["PreToolUse"], toolNames: ["Task"] }, + fn: async () => deny("subagents are not allowed here"), +}); +`, + ); + writeFileSync( + resolve(cwd, ".failproofai", "policies-config.json"), + JSON.stringify({ enabledPolicies: [], customPoliciesPath: policyPath }, null, 2), + ); + } + + it("a policy matching Task denies the task tool's PreToolUse (tool_name: Agent)", () => { + const env = createCopilotEnv(); + try { + writeTaskPolicy(env.cwd); + const result = runHook("PreToolUse", CopilotPayloads.preToolUse.agent(env.cwd), { + homeDir: env.home, + cli: "copilot", + }); + assertPreToolUseDeny(result); + const output = result.parsed?.hookSpecificOutput as Record; + expect(String(output.permissionDecisionReason)).toContain("subagents are not allowed here"); + } finally { + env.cleanup(); + } + }); + + it("the same policy leaves the subagent's own Bash call alone", () => { + const env = createCopilotEnv(); + try { + writeTaskPolicy(env.cwd); + const result = runHook("PreToolUse", CopilotPayloads.preToolUse.subagentBash(env.cwd), { + homeDir: env.home, + cli: "copilot", + }); + assertAllow(result); + } finally { + env.cleanup(); + } + }); +}); diff --git a/__tests__/hooks/copilot-canonicalize.test.ts b/__tests__/hooks/copilot-canonicalize.test.ts index bc2eb111f..710fe4de3 100644 --- a/__tests__/hooks/copilot-canonicalize.test.ts +++ b/__tests__/hooks/copilot-canonicalize.test.ts @@ -69,10 +69,10 @@ describe("Copilot tool-input canonicalization (verified 1.0.71 captures)", () => }); }); -// The lowercase `task` / `web_search` IDs are covered by the permissionRequest +// The lowercase `task` / `web_search` IDs are covered by the lowercase-names // test above; these are the names the PascalCase payloads report. describe("Copilot subagent and web-search tool names (#690)", () => { - it("maps `Agent` to Task - the PascalCase PreToolUse payload reports the Claude name", () => { + it("maps `Agent` to Task - the PascalCase PreToolUse payload reports the Claude name (verified 1.0.117)", () => { expect(canonicalizeToolName("Agent", "copilot")).toBe("Task"); }); diff --git a/__tests__/hooks/handler.test.ts b/__tests__/hooks/handler.test.ts index b13f94269..ca4af725a 100644 --- a/__tests__/hooks/handler.test.ts +++ b/__tests__/hooks/handler.test.ts @@ -250,29 +250,6 @@ describe("hooks/handler", () => { ); }); - it("canonicalizes the lowercase `task` ID a Copilot permissionRequest carries (#690)", async () => { - // permissionRequest is where Copilot still sends runtime IDs. Without the - // `task` entry a PermissionRequest policy matching `Task` never fires. - mockStdin( - JSON.stringify({ - hookName: "permissionRequest", - sessionId: "e5740815-966c-4c4e-8c51-153a8f1fa466", - timestamp: 1784186747245, - cwd: "/home/user/project", - toolName: "task", - toolInput: { description: "Explore the repo", prompt: "List the hooks" }, - permissionSuggestions: [], - }), - ); - const { persistHookActivity } = await import("../../src/hooks/hook-activity-store"); - - await handleHookEvent("PermissionRequest", "copilot"); - - expect(persistHookActivity).toHaveBeenCalledWith( - expect.objectContaining({ eventType: "PermissionRequest", integration: "copilot", toolName: "Task" }), - ); - }); - it("flushes pending telemetry before returning, even on the allow path", async () => { // The allow path fires no awaited event, so without an explicit flush the // caller's process.exit() would drop un-awaited (`void`) load/error events. diff --git a/__tests__/lib/copilot-sessions.test.ts b/__tests__/lib/copilot-sessions.test.ts index 0cbfcc09c..4e8b8c534 100644 --- a/__tests__/lib/copilot-sessions.test.ts +++ b/__tests__/lib/copilot-sessions.test.ts @@ -78,6 +78,33 @@ describe("lib/copilot-sessions: parseCopilotLog", () => { expect(block.text).toBe("4"); }); + it("audits Copilot's lowercase `task` tool as Task (#690, captured from 1.0.117)", async () => { + // Copilot's own session log keeps the runtime ID even where the PascalCase + // hooks report `Agent`, so the audit replay depends on the `task` entry. + const { logEntriesToEvents } = await import("@/src/audit/cli-adapters/shared"); + const content = line({ + type: "tool.execution_start", + data: { + toolCallId: "call_GxRTTTlHzNXSyY5Y9tlMzNNE", + toolName: "task", + arguments: { + description: "Run echo command", + prompt: "Run the exact shell command `echo subagent-ok` and report only the exact output. Do not do anything else.", + name: "echo-runner", + agent_type: "general-purpose", + mode: "sync", + }, + turnId: "1", + }, + id: "62d61db0-6776-4e89-9d25-987d8c5c107d", + timestamp: "2026-11-30T11:55:56.571Z", + parentId: "e390bbf5-b554-4373-bb5f-a677ced7ef19", + }); + const { entries } = await parseCopilotLog(content); + const events = logEntriesToEvents(entries, { cli: "copilot", sessionId: "s", transcriptPath: "/t", cwd: "" }); + expect(events.map((e) => e.toolName)).toEqual(["Task"]); + }); + it("pairs tool.execution_start with tool.execution_complete via toolCallId", async () => { const content = [ line({ diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 1b336b892..e719b1e6f 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -285,16 +285,20 @@ export const COPILOT_TOOL_MAP: Record = { // The subagent launcher and web search (#690). Unmapped names pass through // raw, so without these a policy matching `Task` or `WebSearch` silently // never fires on Copilot. Copilot reports each tool under one of two names: - // - the runtime ID (`task`, `web_search`) on the camelCase - // `permissionRequest` payload and from older CLIs; // - the Claude name on the PascalCase `PreToolUse`/`PostToolUse` payloads - // failproofai registers. GitHub's hooks reference maps `task` to `Agent` - // there (`web_search` becomes `WebSearch`, already canonical), so `Agent` - // needs an entry of its own. That mapping is from the reference, not yet - // from a live capture. - // Ref: https://docs.github.com/en/copilot/reference/hooks-reference - // `ask_user` is deliberately unmapped: it has no filesystem or shell reach, - // so no builtin policy targets it. + // failproofai registers. For the subagent tool that is `Agent`, not + // `Task` (verified live against Copilot CLI 1.0.117, matching the table + // in https://docs.github.com/en/copilot/reference/hooks-reference), so + // `Agent` needs an entry of its own. `web_search` arrives as `WebSearch`, + // already canonical, per the same table. + // - the runtime ID (`task`, `web_search`) in camelCase hook payloads and in + // Copilot's own session log (`tool.execution_start` in events.jsonl), + // which the audit replay reads. `permissionRequest` also carries runtime + // IDs, but on 1.0.117 it does not fire for `task`. + // `web_search` was not offered to the account used for that verification, + // so its two entries rest on the reference alone. `ask_user` is deliberately + // unmapped: it has no filesystem or shell reach, so no builtin policy + // targets it. task: "Task", Agent: "Task", web_search: "WebSearch",