Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- 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)
Expand Down
32 changes: 32 additions & 0 deletions __tests__/e2e/helpers/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> {
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<string, unknown> {
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<string, unknown> {
Expand Down
53 changes: 53 additions & 0 deletions __tests__/e2e/hooks/copilot-integration.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
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();
}
});
});
15 changes: 15 additions & 0 deletions __tests__/hooks/copilot-canonicalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,24 @@ 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)", () => {
expect(Object.keys(COPILOT_TOOL_INPUT_MAP).sort()).toEqual(["Edit", "Read", "Write"]);
});
});

// 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 (verified 1.0.117)", () => {
expect(canonicalizeToolName("Agent", "copilot")).toBe("Task");
});

it("passes the canonical `Task` and `WebSearch` through unchanged", () => {
expect(canonicalizeToolName("Task", "copilot")).toBe("Task");
expect(canonicalizeToolName("WebSearch", "copilot")).toBe("WebSearch");
});
});
6 changes: 6 additions & 0 deletions __tests__/hooks/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] })),
Expand Down Expand Up @@ -469,7 +470,12 @@ describe("hooks/handler", () => {
["rg", "Grep"],
["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",
Expand Down
27 changes: 27 additions & 0 deletions __tests__/lib/copilot-sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,26 @@ export const COPILOT_TOOL_MAP: Record<string, string> = {
rg: "Grep",
ls: "LS",
web_fetch: "WebFetch",
// 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 Claude name on the PascalCase `PreToolUse`/`PostToolUse` payloads
// 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",
};

/**
Expand Down
Loading