From 5143a76e35d1f28ec347be8971a646dee1e737c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Salavisa?= Date: Wed, 3 Jun 2026 10:14:03 +0100 Subject: [PATCH] fix(agents): emit --dangerously-skip-permissions for Claude CLI passthrough (#1262) * fix(agents): emit --dangerously-skip-permissions for Claude CLI passthrough (#1261) Claude ACP declared empty PermSettings in passthrough mode, so the launch path's PermissionValues map (which carries the profile's DangerouslySkipPermissions toggle) had no matching CLI-flag mapping to emit. Bypass / auto-approve was silently ignored. Wire the permission setting to --dangerously-skip-permissions and skip the key in seedCLIFlags so the toggle does not double-surface in the curated cli_flags list. * test(agents): use PermissionKeyDangerouslySkipPermissions constant in claude_acp_test * test(agents): use constant in claude_acp_test failure message too --------- Co-authored-by: Kandev Agent --- apps/backend/internal/agent/agents/agent.go | 9 ++++ .../internal/agent/agents/claude_acp.go | 19 +++++++- .../internal/agent/agents/claude_acp_test.go | 45 +++++++++++++++++++ .../agent/settings/controller/profile_crud.go | 9 +++- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 apps/backend/internal/agent/agents/claude_acp_test.go diff --git a/apps/backend/internal/agent/agents/agent.go b/apps/backend/internal/agent/agents/agent.go index 19cee9da5c..5872951b87 100644 --- a/apps/backend/internal/agent/agents/agent.go +++ b/apps/backend/internal/agent/agents/agent.go @@ -250,6 +250,15 @@ const PermissionKeyAutoApprove = "auto_approve" // run-everything). Separate from PermissionKeyAutoApprove (agentctl ACP approval). const PermissionKeyCursorForce = "cursor_force" +// PermissionKeyDangerouslySkipPermissions is wired to the profile's +// DangerouslySkipPermissions column (a dedicated bool, not the cli_flags list). +// Agents whose CLI accepts --dangerously-skip-permissions (or equivalent) +// declare a PermissionSetting under this key with ApplyMethod=cli_flag so the +// passthrough Settings() pass emits the flag from the profile bool. The +// catalog seeder excludes this key to avoid duplicating the toggle into the +// curated cli_flags list (which would also double-emit the flag at launch). +const PermissionKeyDangerouslySkipPermissions = "dangerously_skip_permissions" + // PermissionSetting defines metadata for a permission setting option. type PermissionSetting struct { Supported bool `json:"supported"` diff --git a/apps/backend/internal/agent/agents/claude_acp.go b/apps/backend/internal/agent/agents/claude_acp.go index 21c7817caf..82735eca08 100644 --- a/apps/backend/internal/agent/agents/claude_acp.go +++ b/apps/backend/internal/agent/agents/claude_acp.go @@ -18,6 +18,21 @@ var claudeACPLogoDark []byte const claudeACPPkg = "@agentclientprotocol/claude-agent-acp" +// claudeACPPermSettings maps the profile DangerouslySkipPermissions toggle to +// the Claude Code CLI's --dangerously-skip-permissions flag in passthrough mode. +// ACP (non-passthrough) Claude does not consume this flag; permission bypass +// there goes through agentctl's auto-approve channel. +var claudeACPPermSettings = map[string]PermissionSetting{ + PermissionKeyDangerouslySkipPermissions: { + Supported: true, + Default: false, + Label: "Skip permission prompts", + Description: "Pass --dangerously-skip-permissions so Claude Code does not prompt for tool approvals.", + ApplyMethod: PermissionApplyMethodCLIFlag, + CLIFlag: "--dangerously-skip-permissions", + }, +} + var ( _ Agent = (*ClaudeACP)(nil) _ PassthroughAgent = (*ClaudeACP)(nil) @@ -34,7 +49,7 @@ type ClaudeACP struct { func NewClaudeACP() *ClaudeACP { return &ClaudeACP{ StandardPassthrough: StandardPassthrough{ - PermSettings: emptyPermSettings, + PermSettings: claudeACPPermSettings, Cfg: PassthroughConfig{ Supported: true, Label: "CLI Passthrough", @@ -160,7 +175,7 @@ func (a *ClaudeACP) InstallScript() string { func (a *ClaudeACP) BillingType() usage.BillingType { return claudeBillingType() } func (a *ClaudeACP) PermissionSettings() map[string]PermissionSetting { - return emptyPermSettings + return claudeACPPermSettings } // InferenceConfig returns configuration for one-shot inference using ACP. diff --git a/apps/backend/internal/agent/agents/claude_acp_test.go b/apps/backend/internal/agent/agents/claude_acp_test.go new file mode 100644 index 0000000000..e1ad1fa6ac --- /dev/null +++ b/apps/backend/internal/agent/agents/claude_acp_test.go @@ -0,0 +1,45 @@ +package agents + +import ( + "strings" + "testing" +) + +func TestClaudeACPPermissionSettingsSkipPermissions(t *testing.T) { + settings := NewClaudeACP().PermissionSettings() + setting, ok := settings[PermissionKeyDangerouslySkipPermissions] + if !ok { + t.Fatalf("PermissionSettings() missing key %q", PermissionKeyDangerouslySkipPermissions) + } + if !setting.Supported { + t.Error("dangerously_skip_permissions must be Supported") + } + if setting.ApplyMethod != PermissionApplyMethodCLIFlag { + t.Errorf("ApplyMethod = %q, want %q", setting.ApplyMethod, PermissionApplyMethodCLIFlag) + } + if setting.CLIFlag != "--dangerously-skip-permissions" { + t.Errorf("CLIFlag = %q, want --dangerously-skip-permissions", setting.CLIFlag) + } +} + +// Passthrough launch path drives the flag via PermissionValues. Verify the +// resulting command includes --dangerously-skip-permissions when the toggle is +// on, and excludes it otherwise. Regression coverage for issue #1261. +func TestClaudeACPBuildPassthroughCommandSkipPermissions(t *testing.T) { + c := NewClaudeACP() + + without := strings.Join(c.BuildPassthroughCommand(PassthroughOptions{}).Args(), " ") + if strings.Contains(without, "--dangerously-skip-permissions") { + t.Errorf("default passthrough command must not include --dangerously-skip-permissions, got %q", without) + } + + with := strings.Join( + c.BuildPassthroughCommand(PassthroughOptions{ + PermissionValues: map[string]bool{PermissionKeyDangerouslySkipPermissions: true}, + }).Args(), + " ", + ) + if !strings.Contains(with, "--dangerously-skip-permissions") { + t.Errorf("passthrough command with dangerously_skip_permissions=true must include --dangerously-skip-permissions, got %q", with) + } +} diff --git a/apps/backend/internal/agent/settings/controller/profile_crud.go b/apps/backend/internal/agent/settings/controller/profile_crud.go index 1a7fc9c47c..f9147c7927 100644 --- a/apps/backend/internal/agent/settings/controller/profile_crud.go +++ b/apps/backend/internal/agent/settings/controller/profile_crud.go @@ -82,10 +82,17 @@ func (c *Controller) CreateProfile(ctx context.Context, req CreateProfileRequest func seedCLIFlags(agent agents.Agent) []models.CLIFlag { settings := agents.CatalogPermissionSettings(agent) flags := make([]models.CLIFlag, 0, len(settings)) - for _, s := range settings { + for key, s := range settings { if !s.Supported || s.ApplyMethod != agents.PermissionApplyMethodCLIFlag || s.CLIFlag == "" { continue } + // dangerously_skip_permissions is wired to the profile's dedicated + // DangerouslySkipPermissions column; the passthrough launch path emits + // the flag via PermissionValues. Seeding it as a curated cli_flag too + // would surface a duplicate toggle in the UI and double-emit the flag. + if key == agents.PermissionKeyDangerouslySkipPermissions { + continue + } flagText := s.CLIFlag if s.CLIFlagValue != "" { flagText = s.CLIFlag + " " + s.CLIFlagValue