From d6c513f0351c8a9b4f925bb4e361e3405fdd722f Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Tue, 13 May 2025 08:21:16 +0000 Subject: [PATCH] feat: add hidden `CODER_AGENT_IS_SUB_AGENT` flag to `coder agent` Adds a new, hidden, flag `CODER_AGENT_IS_SUB_AGENT` to the `coder agent` command. --- agent/agent.go | 5 +++++ cli/agent.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index d0e668af34d74..99868eefe1eb7 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -89,6 +89,7 @@ type Options struct { ServiceBannerRefreshInterval time.Duration BlockFileTransfer bool Execer agentexec.Execer + SubAgent bool ExperimentalDevcontainersEnabled bool ContainerAPIOptions []agentcontainers.Option // Enable ExperimentalDevcontainersEnabled for these to be effective. @@ -190,6 +191,8 @@ func New(options Options) Agent { metrics: newAgentMetrics(prometheusRegistry), execer: options.Execer, + subAgent: options.SubAgent, + experimentalDevcontainersEnabled: options.ExperimentalDevcontainersEnabled, containerAPIOptions: options.ContainerAPIOptions, } @@ -272,6 +275,8 @@ type agent struct { metrics *agentMetrics execer agentexec.Execer + subAgent bool + experimentalDevcontainersEnabled bool containerAPIOptions []agentcontainers.Option containerAPI atomic.Pointer[agentcontainers.API] // Set by apiHandler. diff --git a/cli/agent.go b/cli/agent.go index 5d6cdbd66b4e0..b0dc00ad8020a 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -53,6 +53,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command { blockFileTransfer bool agentHeaderCommand string agentHeader []string + subAgent bool experimentalDevcontainersEnabled bool ) @@ -350,6 +351,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command { PrometheusRegistry: prometheusRegistry, BlockFileTransfer: blockFileTransfer, Execer: execer, + SubAgent: subAgent, ExperimentalDevcontainersEnabled: experimentalDevcontainersEnabled, }) @@ -481,6 +483,17 @@ func (r *RootCmd) workspaceAgent() *serpent.Command { Description: "Allow the agent to automatically detect running devcontainers.", Value: serpent.BoolOf(&experimentalDevcontainersEnabled), }, + { + Flag: "is-sub-agent", + Default: "false", + Env: "CODER_AGENT_IS_SUB_AGENT", + Description: "Specify whether this is a sub agent or not.", + Value: serpent.BoolOf(&subAgent), + // As `coderd` handles the creation of sub-agents, it does not make + // sense for this to be exposed. We do not want people setting an + // agent as a sub-agent if it is not. + Hidden: true, + }, } return cmd