Merge branch 'continuedev:main' into feature/disable-commit-signature-envvar

This commit is contained in:
Ross Golder 2025-10-29 07:08:44 +07:00 • committed by GitHub
commit bb361ecf14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 737 additions and 23 deletions

View file

@ -115,6 +115,45 @@ runs:
shell: bash
run: npm install -g @continuedev/cli@latest
- name: Setup Action Scripts
if: env.SHOULD_RUN == 'true'
shell: bash
run: |
# Create directory for scripts
mkdir -p .continue-action-scripts
# Check if we're running in the Continue repo itself (scripts exist locally)
if [ -f "actions/general-review/scripts/buildPrompt.js" ] && [ -f "actions/general-review/scripts/writeMarkdown.js" ]; then
echo "Running in Continue repo - using local scripts from current checkout"
cp actions/general-review/scripts/buildPrompt.js .continue-action-scripts/buildPrompt.js
cp actions/general-review/scripts/writeMarkdown.js .continue-action-scripts/writeMarkdown.js
else
echo "Running in external repo - downloading scripts from Continue repo"
# Download scripts from Continue repo
echo "Downloading buildPrompt.js..."
curl -sSL https://raw.githubusercontent.com/continuedev/continue/main/actions/general-review/scripts/buildPrompt.js \
-o .continue-action-scripts/buildPrompt.js
echo "Downloading writeMarkdown.js..."
curl -sSL https://raw.githubusercontent.com/continuedev/continue/main/actions/general-review/scripts/writeMarkdown.js \
-o .continue-action-scripts/writeMarkdown.js
fi
# Verify scripts exist
if [ ! -f .continue-action-scripts/buildPrompt.js ]; then
echo "Error: buildPrompt.js not found"
exit 1
fi
if [ ! -f .continue-action-scripts/writeMarkdown.js ]; then
echo "Error: writeMarkdown.js not found"
exit 1
fi
echo "Scripts ready:"
ls -lh .continue-action-scripts/
- name: Post Initial Comment
if: env.SHOULD_RUN == 'true'
id: initial-comment
@ -218,7 +257,7 @@ runs:
# Gather PR context and build prompt without heredocs
gh pr diff "$PR_NUMBER" > pr_diff.txt
gh pr view "$PR_NUMBER" --json title,author,body,files > pr_data.json
node actions/general-review/scripts/buildPrompt.js "$PR_NUMBER"
node .continue-action-scripts/buildPrompt.js "$PR_NUMBER"
rm -f pr_data.json
- name: Run Continue CLI Review
@ -241,7 +280,7 @@ runs:
if [ -z "$CONTINUE_API_KEY" ]; then
echo "Warning: CONTINUE_API_KEY environment variable is not set"
# Create fallback review and continue
node actions/general-review/scripts/writeMarkdown.js code_review.md missing_api_key
node .continue-action-scripts/writeMarkdown.js code_review.md missing_api_key
echo "SKIP_CLI=true" >> $GITHUB_ENV
else
echo "SKIP_CLI=false" >> $GITHUB_ENV
@ -263,7 +302,7 @@ runs:
echo "Testing Continue CLI..."
if ! which cn > /dev/null 2>&1; then
echo "Warning: Continue CLI not found or not working"
node actions/general-review/scripts/writeMarkdown.js code_review.md cli_install_failed
node .continue-action-scripts/writeMarkdown.js code_review.md cli_install_failed
echo "SKIP_CLI=true" >> $GITHUB_ENV
else
echo "Continue CLI found at: $(which cn)"
@ -299,7 +338,7 @@ runs:
# Check if output is empty
if [ ! -s code_review.md ]; then
echo "Warning: Continue CLI returned empty output"
node actions/general-review/scripts/writeMarkdown.js code_review.md empty_output
node .continue-action-scripts/writeMarkdown.js code_review.md empty_output
fi
else
echo "Error: Continue CLI command failed with exit code $?"
@ -308,13 +347,13 @@ runs:
# Check for specific error patterns
if grep -q "not found\|ENOENT" cli_error.log 2>/dev/null; then
node actions/general-review/scripts/writeMarkdown.js code_review.md cli_not_found
node .continue-action-scripts/writeMarkdown.js code_review.md cli_not_found
elif grep -q "config\|assistant" cli_error.log 2>/dev/null; then
node actions/general-review/scripts/writeMarkdown.js code_review.md config_error
node .continue-action-scripts/writeMarkdown.js code_review.md config_error
elif grep -q "api\|auth" cli_error.log 2>/dev/null; then
node actions/general-review/scripts/writeMarkdown.js code_review.md auth_error
node .continue-action-scripts/writeMarkdown.js code_review.md auth_error
else
node actions/general-review/scripts/writeMarkdown.js code_review.md generic_failure
node .continue-action-scripts/writeMarkdown.js code_review.md generic_failure
fi
fi

View file

@ -0,0 +1,675 @@
import { ALL_BUILT_IN_TOOLS } from "src/tools/allBuiltIns.js";
import { ToolPermissionService } from "./ToolPermissionService.js";
import { AgentFileServiceState, MCPServiceState } from "./types.js";
describe("ToolPermissionService - Agent File Integration", () => {
let service: ToolPermissionService;
beforeEach(() => {
service = new ToolPermissionService();
});
describe("generateAgentFilePolicies - No parsed tools", () => {
it("should allow all tools when agent file is present but parsedTools is null", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: null, // No parsed tools
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(agentFileState);
expect(policies).toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
it("should allow all tools when agent file is present but parsedTools is undefined", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: undefined as any,
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(agentFileState);
expect(policies).toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
it("should allow all tools when agentFileServiceState is undefined", () => {
const policies = service.generateAgentFilePolicies(undefined);
expect(policies).toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
});
describe("generateAgentFilePolicies - With MCP servers", () => {
it("should allow specific MCP tools when explicitly listed", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [{ mcpServer: "owner/mcp-server", toolName: "specific_tool" }],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [
{
config: { sourceSlug: "owner/mcp-server" } as any,
status: "connected",
tools: [
{ name: "specific_tool" } as any,
{ name: "other_tool" } as any,
{ name: "another_tool" } as any,
],
prompts: [],
warnings: [],
},
],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Should allow the specific tool
expect(policies).toContainEqual({
tool: "specific_tool",
permission: "allow",
});
// Should exclude the other tools from the same server
expect(policies).toContainEqual({
tool: "other_tool",
permission: "exclude",
});
expect(policies).toContainEqual({
tool: "another_tool",
permission: "exclude",
});
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should allow all tools from MCP server when server is listed without specific tools", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [
{ mcpServer: "owner/mcp-server" }, // No toolName = all tools from this server
],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [
{
config: { sourceSlug: "owner/mcp-server" } as any,
status: "connected",
tools: [
{ name: "tool1" } as any,
{ name: "tool2" } as any,
{ name: "tool3" } as any,
],
prompts: [],
warnings: [],
},
],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Since no specific tools were mentioned, MCP logic doesn't explicitly allow/exclude
// The wildcard allow at the end covers all MCP tools
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should handle multiple MCP servers with mixed specific and blanket access", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/server1", "owner/server2"],
tools: [
{ mcpServer: "owner/server1", toolName: "specific_tool" },
{ mcpServer: "owner/server2" }, // All tools from server2
],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [
{
config: { sourceSlug: "owner/server1" } as any,
status: "connected",
tools: [
{ name: "specific_tool" } as any,
{ name: "other_tool" } as any,
],
prompts: [],
warnings: [],
},
{
config: { sourceSlug: "owner/server2" } as any,
status: "connected",
tools: [{ name: "tool_a" } as any, { name: "tool_b" } as any],
prompts: [],
warnings: [],
},
],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Server1: Should allow specific_tool and exclude other_tool
expect(policies).toContainEqual({
tool: "specific_tool",
permission: "allow",
});
expect(policies).toContainEqual({
tool: "other_tool",
permission: "exclude",
});
// Server2: No specific tools, so wildcard covers them
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should handle MCP server not found in connections", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/missing-server"],
tools: [
{ mcpServer: "owner/missing-server", toolName: "specific_tool" },
],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [], // No connections
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Should still have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
});
describe("generateAgentFilePolicies - With built-in tools", () => {
it("should allow only specific built-in tools when listed", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: [],
tools: [{ toolName: "Bash" }, { toolName: "Read" }],
allBuiltIn: false,
},
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(agentFileState);
// Should allow the specific built-in tools
expect(policies).toContainEqual({
tool: "Bash",
permission: "allow",
});
expect(policies).toContainEqual({
tool: "Read",
permission: "allow",
});
// Should exclude all other built-in tools
const allBuiltInNames = ALL_BUILT_IN_TOOLS.map((t) => t.name);
const notListed = allBuiltInNames.filter(
(name) => name !== "Bash" && name !== "Read",
);
for (const toolName of notListed) {
expect(policies).toContainEqual({
tool: toolName,
permission: "exclude",
});
}
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should allow all built-in tools when allBuiltIn is true", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: [],
tools: [],
allBuiltIn: true,
},
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(agentFileState);
// Should NOT have any exclude policies for built-in tools
const excludePolicies = policies.filter(
(p) => p.permission === "exclude",
);
expect(excludePolicies).toEqual([]);
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should exclude built-in tools when MCP servers are present but allBuiltIn is false", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [{ mcpServer: "owner/mcp-server" }],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [
{
config: { sourceSlug: "owner/mcp-server" } as any,
status: "connected",
tools: [{ name: "mcp_tool" } as any],
prompts: [],
warnings: [],
},
],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Should exclude all built-in tools
const allBuiltInNames = ALL_BUILT_IN_TOOLS.map((t) => t.name);
for (const toolName of allBuiltInNames) {
expect(policies).toContainEqual({
tool: toolName,
permission: "exclude",
});
}
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should allow both built-in tools and MCP tools when both are specified", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [
{ toolName: "Bash" },
{ toolName: "Read" },
{ mcpServer: "owner/mcp-server", toolName: "mcp_tool" },
],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [
{
config: { sourceSlug: "owner/mcp-server" } as any,
status: "connected",
tools: [
{ name: "mcp_tool" } as any,
{ name: "other_mcp_tool" } as any,
],
prompts: [],
warnings: [],
},
],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Should allow the specific MCP tool
expect(policies).toContainEqual({
tool: "mcp_tool",
permission: "allow",
});
// Should exclude the other MCP tool
expect(policies).toContainEqual({
tool: "other_mcp_tool",
permission: "exclude",
});
// Should allow the specific built-in tools
expect(policies).toContainEqual({
tool: "Bash",
permission: "allow",
});
expect(policies).toContainEqual({
tool: "Read",
permission: "allow",
});
// Should exclude other built-in tools
const allBuiltInNames = ALL_BUILT_IN_TOOLS.map((t) => t.name);
const notListed = allBuiltInNames.filter(
(name) => name !== "Bash" && name !== "Read",
);
for (const toolName of notListed) {
expect(policies).toContainEqual({
tool: toolName,
permission: "exclude",
});
}
// Should have wildcard allow at the end
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
});
describe("initializeSync with agent file", () => {
it("should use agent file policies when agent file is present with no parsed tools", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: null, // No parsed tools
parsedRules: null,
};
const state = service.initializeSync(undefined, agentFileState);
// Should have wildcard allow policy
expect(state.permissions.policies).toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
it("should use agent file policies when agent file is present with parsed tools", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: [],
tools: [{ toolName: "Bash" }],
allBuiltIn: false,
},
parsedRules: null,
};
const state = service.initializeSync(undefined, agentFileState);
// Should have specific policies for Bash and exclusions for others
expect(state.permissions.policies).toContainEqual({
tool: "Bash",
permission: "allow",
});
// Should exclude other built-in tools
const allBuiltInNames = ALL_BUILT_IN_TOOLS.map((t) => t.name);
const notBash = allBuiltInNames.filter((name) => name !== "Bash");
for (const toolName of notBash) {
expect(state.permissions.policies).toContainEqual({
tool: toolName,
permission: "exclude",
});
}
// Should have wildcard allow at the end
const lastPolicy =
state.permissions.policies[state.permissions.policies.length - 1];
expect(lastPolicy).toEqual({
tool: "*",
permission: "allow",
});
});
it("should use normal resolution when agent file is not present", () => {
const state = service.initializeSync(undefined, undefined);
// Should have normal policies (not just wildcard allow)
expect(state.permissions.policies.length).toBeGreaterThan(1);
// Should not be just wildcard allow
expect(state.permissions.policies).not.toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
it("should prioritize agent file over runtime overrides", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: [],
tools: [{ toolName: "Read" }],
allBuiltIn: false,
},
parsedRules: null,
};
const runtimeOverrides = {
allow: ["Bash", "Write"],
exclude: ["Read"],
};
const state = service.initializeSync(
runtimeOverrides,
agentFileState,
undefined,
);
// Agent file should take precedence, so Read should be allowed (not excluded)
expect(state.permissions.policies).toContainEqual({
tool: "Read",
permission: "allow",
});
// Bash should be excluded (not in agent file)
expect(state.permissions.policies).toContainEqual({
tool: "Bash",
permission: "exclude",
});
});
});
describe("Edge cases and boundary conditions", () => {
it("should handle empty parsed tools arrays - allows everything", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: [],
tools: [],
allBuiltIn: false,
},
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(agentFileState);
// With empty tools array and no MCP servers, the logic doesn't enter
// the exclusion path, so it just returns wildcard allow
// This is the "blank = all built-in tools" case from the comments
expect(policies).toEqual([
{
tool: "*",
permission: "allow",
},
]);
});
it("should handle MCP state with empty connections array", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [{ mcpServer: "owner/mcp-server", toolName: "specific_tool" }],
allBuiltIn: false,
},
parsedRules: null,
};
const mcpState: MCPServiceState = {
mcpService: null,
connections: [],
tools: [],
prompts: [],
};
const policies = service.generateAgentFilePolicies(
agentFileState,
mcpState,
);
// Should still generate policies and have wildcard allow
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
it("should handle MCP state being undefined", () => {
const agentFileState: AgentFileServiceState = {
agentFile: { name: "test-agent" } as any,
slug: "test-slug",
agentFileModel: null,
parsedTools: {
mcpServers: ["owner/mcp-server"],
tools: [{ mcpServer: "owner/mcp-server", toolName: "specific_tool" }],
allBuiltIn: false,
},
parsedRules: null,
};
const policies = service.generateAgentFilePolicies(
agentFileState,
undefined,
);
// Should still generate policies and have wildcard allow
expect(policies[policies.length - 1]).toEqual({
tool: "*",
permission: "allow",
});
});
});
});

View file

@ -30,7 +30,6 @@ describe("ToolPermissionService", () => {
currentMode: "normal",
isHeadless: false,
modePolicyCount: 0,
agentFilePolicyCount: 0,
});
});

View file

@ -30,7 +30,6 @@ export interface ToolPermissionServiceState {
currentMode: PermissionMode;
isHeadless: boolean;
modePolicyCount?: number; // Track how many policies are from mode vs other sources
agentFilePolicyCount?: number;
originalPolicies?: ToolPermissions; // Store original policies when switching modes
}
@ -74,10 +73,16 @@ export class ToolPermissionService
generateAgentFilePolicies(
agentFileServiceState?: AgentFileServiceState,
mcpServiceState?: MCPServiceState,
): undefined | ToolPermissionPolicy[] {
): ToolPermissionPolicy[] {
// With --agent, all available tools are allowed if not specified
const parsedTools = agentFileServiceState?.parsedTools;
if (!parsedTools?.tools.length) {
return undefined;
if (!parsedTools) {
return [
{
tool: "*",
permission: "allow",
},
];
}
const policies: ToolPermissionPolicy[] = [];
@ -222,23 +227,20 @@ export class ToolPermissionService
this.setState({ isHeadless: runtimeOverrides.isHeadless });
}
const agentFilePolicies = this.generateAgentFilePolicies(
agentFileServiceState,
mcpServiceState,
);
const modePolicies = this.generateModePolicies();
// For plan and auto modes, use ONLY mode policies (absolute override)
// For normal mode, combine with user configuration
let allPolicies: ToolPermissionPolicy[];
if (agentFilePolicies) {
if (agentFileServiceState?.agentFile) {
// Agent file policies take full precedence on init
allPolicies = agentFilePolicies;
allPolicies = this.generateAgentFilePolicies(
agentFileServiceState,
mcpServiceState,
);
} else if (
this.currentState.currentMode === "plan" ||
this.currentState.currentMode === "auto"
) {
// Absolute override: ignore all user configuration
// For plan and auto modes, use ONLY mode policies (absolute override)
allPolicies = modePolicies;
} else {
// Normal mode: combine mode policies with user configuration
@ -255,7 +257,6 @@ export class ToolPermissionService
currentMode: this.currentState.currentMode,
isHeadless: this.currentState.isHeadless,
modePolicyCount: modePolicies.length,
agentFilePolicyCount: (agentFilePolicies ?? []).length,
});
(this as any).isInitialized = true;