An open-source, faster Devin alternative
TypeScript
agent delete/disconnect/uninstall: require confirmation
Igor Zalutskib92ec7faac1d
diff --git a/cmd/oc/internal/commands/agent.go b/cmd/oc/internal/commands/agent.goindex 24ac32d0..1c53bebb 100644--- a/cmd/oc/internal/commands/agent.go+++ b/cmd/oc/internal/commands/agent.go@@ -9,6 +9,7 @@ package commands// renderAsyncFallback) live in agent_errors.go.import (+ "bufio""fmt""os""strings"@@ -29,6 +30,27 @@ func stdinIsTTY() bool {return (fi.Mode() & os.ModeCharDevice) != 0}+// confirmDestructive gates delete/disconnect/uninstall on explicit consent.+// With --yes: proceed. Without --yes and a TTY: prompt. Without --yes and+// no TTY: refuse — scripts and agents must pass --yes so accidental+// invocation can't quietly destroy state.+func confirmDestructive(cmd *cobra.Command, action string) error {+ if yes, _ := cmd.Flags().GetBool("yes"); yes {+ return nil+ }+ if !stdinIsTTY() {+ return fmt.Errorf("refusing to %s without --yes (stdin is not a terminal)", action)+ }+ fmt.Fprintf(os.Stderr, "%s? [y/N] ", action)+ line, _ := bufio.NewReader(os.Stdin).ReadString('\n')+ switch strings.ToLower(strings.TrimSpace(line)) {+ case "y", "yes":+ return nil+ default:+ return fmt.Errorf("aborted")+ }+}+// sessionsClient returns the sessions-api client from context, or errors if not configured.func sessionsClient(cmd *cobra.Command) (*client.Client, error) {c := client.SessionsFromContext(cmd.Context())@@ -121,6 +143,11 @@ func init() {agentInstallCmd.Flags().Bool("no-wait", false, "Don't wait for install orchestration to finish")+ // Destructive ops — require explicit --yes in non-TTY callers.+ agentDeleteCmd.Flags().Bool("yes", false, "Skip confirmation (required for non-interactive callers)")+ agentDisconnectCmd.Flags().Bool("yes", false, "Skip confirmation (required for non-interactive callers)")+ agentUninstallCmd.Flags().Bool("yes", false, "Skip confirmation (required for non-interactive callers)")+agentEventsCmd.Flags().Int("limit", 0, "Max events to return (1-200, default 50)")agentEventsCmd.Flags().String("before", "", "Return events before this ISO timestamp (for pagination)")diff --git a/cmd/oc/internal/commands/agent_connect.go b/cmd/oc/internal/commands/agent_connect.goindex 6e446e45..41a507f6 100644--- a/cmd/oc/internal/commands/agent_connect.go+++ b/cmd/oc/internal/commands/agent_connect.go@@ -78,6 +78,10 @@ var agentDisconnectCmd = &cobra.Command{return err}+ if err := confirmDestructive(cmd, fmt.Sprintf("Disconnect %s from %s", args[1], args[0])); err != nil {+ return err+ }+if err := sc.Delete(cmd.Context(), "/v1/agents/"+args[0]+"/channels/"+args[1]); err != nil {return err}diff --git a/cmd/oc/internal/commands/agent_delete.go b/cmd/oc/internal/commands/agent_delete.goindex c240d2be..b8af0f58 100644--- a/cmd/oc/internal/commands/agent_delete.go+++ b/cmd/oc/internal/commands/agent_delete.go@@ -16,6 +16,10 @@ var agentDeleteCmd = &cobra.Command{return err}+ if err := confirmDestructive(cmd, fmt.Sprintf("Delete agent %s", args[0])); err != nil {+ return err+ }+if err := sc.Delete(cmd.Context(), "/v1/agents/"+args[0]); err != nil {return err}diff --git a/cmd/oc/internal/commands/agent_packages.go b/cmd/oc/internal/commands/agent_packages.goindex fedfd779..ce0cec16 100644--- a/cmd/oc/internal/commands/agent_packages.go+++ b/cmd/oc/internal/commands/agent_packages.go@@ -69,6 +69,10 @@ var agentUninstallCmd = &cobra.Command{return err}+ if err := confirmDestructive(cmd, fmt.Sprintf("Uninstall %s from %s", args[1], args[0])); err != nil {+ return err+ }+if err := sc.Delete(cmd.Context(), "/v1/agents/"+args[0]+"/packages/"+args[1]); err != nil {return err}