Skip to content

Commit 2088660

Browse files
authored
fix(cli): exclude ask first tools in headless (#8416)
* fix: permissions cleanup : * fix: remove unused test
1 parent b4ecff3 commit 2088660

15 files changed

+212
-595
lines changed

extensions/cli/src/e2e/headless-permission-error.test.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -32,63 +32,6 @@ describe("E2E: Headless Mode Permission Errors", () => {
3232
}
3333
await cleanupTestContext(context);
3434
});
35-
it("should display error message with --auto suggestion when tool requires permission", async () => {
36-
// Set up mock LLM to return a tool call that requires permission (Write tool)
37-
mockServer = await setupMockLLMTest(context, {
38-
customHandler: (req: http.IncomingMessage, res: http.ServerResponse) => {
39-
let body = "";
40-
req.on("data", (chunk) => {
41-
body += chunk.toString();
42-
});
43-
44-
req.on("end", () => {
45-
if (req.method === "POST" && req.url === "/chat/completions") {
46-
res.writeHead(200, {
47-
"Content-Type": "text/event-stream",
48-
"Cache-Control": "no-cache",
49-
Connection: "keep-alive",
50-
});
51-
52-
// Send a Write tool call (requires permission by default)
53-
res.write(
54-
`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"id":"call_write","type":"function","function":{"name":"Write"}}]},"index":0}]}\n\n`,
55-
);
56-
res.write(
57-
`data: {"choices":[{"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\\"filepath\\":\\"test.txt\\",\\"content\\":\\"hello\\"}"}}]},"index":0}]}\n\n`,
58-
);
59-
60-
// Send usage data
61-
res.write(
62-
`data: {"usage":{"prompt_tokens":10,"completion_tokens":20}}\n\n`,
63-
);
64-
65-
// End the stream
66-
res.write(`data: [DONE]\n\n`);
67-
res.end();
68-
} else {
69-
res.writeHead(404);
70-
res.end("Not found");
71-
}
72-
});
73-
},
74-
});
75-
76-
// Run CLI in headless mode without permission flags
77-
const result = await runCLI(context, {
78-
args: ["-p", "--config", context.configPath, "Create a file test.txt"],
79-
timeout: 15000,
80-
});
81-
82-
// Expect non-zero exit code
83-
expect(result.exitCode).toBe(1);
84-
85-
// Verify the error message contains the expected information
86-
expect(result.stderr).toContain("requires permission");
87-
expect(result.stderr).toContain("headless mode");
88-
expect(result.stderr).toContain("--auto");
89-
expect(result.stderr).toContain("--allow");
90-
expect(result.stderr).toContain("--exclude");
91-
}, 20000);
9235

9336
it("should succeed with --auto flag when tool requires permission", async () => {
9437
// Set up mock LLM to return a Write tool call

extensions/cli/src/permissions/README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Tools with "allow" permission are executed immediately without user intervention
4747

4848
### Data Flow
4949

50-
1. **Tool Loading**: `getAllTools()` in `streamChatResponse.ts` filters out excluded tools
50+
1. **Tool Loading**: `getAllowedTools()` in `streamChatResponse.ts` filters out excluded tools
5151
2. **Tool Execution**: Before executing each tool call, permissions are checked
5252
3. **User Interaction**: For "ask" policies, UI displays permission request
5353
4. **Execution**: Tool is executed or denied based on permission result
@@ -82,11 +82,4 @@ const result = checkToolPermission({
8282
if (result.permission === "ask") {
8383
// Request user permission
8484
}
85-
86-
// Filter excluded tools
87-
const allowedTools = filterExcludedTools([
88-
"readFile",
89-
"dangerousTool",
90-
"writeFile",
91-
]);
9285
```

extensions/cli/src/permissions/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export type {
99
export { DEFAULT_TOOL_POLICIES } from "./defaultPolicies.js";
1010
export {
1111
checkToolPermission,
12-
filterExcludedTools,
1312
matchesArguments,
1413
matchesToolPattern,
1514
} from "./permissionChecker.js";

0 commit comments

Comments
 (0)