Documentation
¶
Overview ¶
Package agentmode provides AI agent detection and structured JSON output.
It detects whether the CLI is running under an AI coding agent (e.g. Claude Code, Cursor, GitHub Copilot) by checking environment variables, and provides the standard Dynatrace CLI agent envelope format:
{"ok": true, "result": ..., "context": {...}}
Index ¶
- func ClassifyHTTPError(statusCode int) string
- func EnvVars() []string
- func UserAgentSuffix() string
- func WriteError(w io.Writer, detail *ErrorDetail) error
- func WriteSuccess(w io.Writer, result interface{}, ctx *ResponseContext) error
- type AgentInfo
- type ErrorDetail
- type Response
- type ResponseContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClassifyHTTPError ¶
ClassifyHTTPError maps an HTTP status code to a machine-readable error code.
func EnvVars ¶
func EnvVars() []string
EnvVars returns every environment variable Detect consults. Tests clear these to keep a developer's own agent session from flipping output to the agent envelope.
func UserAgentSuffix ¶
func UserAgentSuffix() string
UserAgentSuffix returns a suffix to append to the User-Agent header. Returns empty string if no AI agent is detected.
func WriteError ¶
func WriteError(w io.Writer, detail *ErrorDetail) error
WriteError writes an error response envelope to the writer.
func WriteSuccess ¶
func WriteSuccess(w io.Writer, result interface{}, ctx *ResponseContext) error
WriteSuccess writes a success response envelope to the writer.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
// Detected is true if an AI agent environment was identified.
Detected bool
// Name is the canonical name of the detected agent (e.g. "claude-code").
Name string
}
AgentInfo represents detected AI agent information.
func Detect ¶
func Detect() AgentInfo
Detect checks environment variables to identify if running under an AI agent.
An AI_AGENT value that names a known agent wins, because it is the agent identifying itself. Otherwise the agent-specific signals decide, in order. An AI_AGENT value naming no known agent still counts as detection, reported as "generic-ai", but only once every specific signal has had its turn.
type ErrorDetail ¶
type ErrorDetail struct {
Code string `json:"code"`
Message string `json:"message"`
Operation string `json:"operation,omitempty"`
StatusCode int `json:"status_code,omitempty"`
RequestID string `json:"request_id,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
}
ErrorDetail is a structured error for machine consumption.
type Response ¶
type Response struct {
OK bool `json:"ok"`
Result interface{} `json:"result"`
Error *ErrorDetail `json:"error,omitempty"`
Context *ResponseContext `json:"context,omitempty"`
}
Response is the standard agent mode envelope that wraps all CLI output. Success responses have OK=true with Result populated. Error responses have OK=false with Error populated.
type ResponseContext ¶
type ResponseContext struct {
Total *int `json:"total,omitempty"`
HasMore bool `json:"has_more,omitempty"`
Verb string `json:"verb,omitempty"`
Resource string `json:"resource,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Duration string `json:"duration,omitempty"`
Links map[string]string `json:"links,omitempty"`
}
ResponseContext provides operational metadata alongside the result.