Skip to content

Commit b564d8c

Browse files
Merge pull request #70 from DataDog/feat/agent-operability
feat(agent): agent operability overhaul for AI coding assistants
2 parents a4da757 + 80e7760 commit b564d8c

56 files changed

Lines changed: 2581 additions & 1474 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/agent.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2024-present Datadog, Inc.
5+
6+
package cmd
7+
8+
import (
9+
"encoding/json"
10+
"fmt"
11+
12+
"github.com/DataDog/pup/pkg/agenthelp"
13+
"github.com/spf13/cobra"
14+
)
15+
16+
var agentSchemaCompact bool
17+
18+
var agentCmd = &cobra.Command{
19+
Use: "agent",
20+
Short: "Agent tooling: schema, guide, and diagnostics for AI coding assistants",
21+
Long: `Commands for AI coding assistants to interact with pup efficiently.
22+
23+
In agent mode (auto-detected or via --agent / FORCE_AGENT_MODE=1),
24+
--help returns structured JSON schema instead of human-readable text.
25+
26+
COMMANDS:
27+
schema Output the complete command schema as JSON
28+
guide Output the comprehensive steering guide
29+
30+
EXAMPLES:
31+
# Get full JSON schema (all commands, flags, query syntax)
32+
pup agent schema
33+
34+
# Get compact schema (command names and flags only, fewer tokens)
35+
pup agent schema --compact
36+
37+
# Get the steering guide
38+
pup agent guide
39+
40+
# Get guide for a specific domain
41+
pup agent guide logs`,
42+
}
43+
44+
var agentSchemaCmd = &cobra.Command{
45+
Use: "schema",
46+
Short: "Output command schema as JSON",
47+
Long: `Output the complete pup command schema as structured JSON.
48+
49+
Includes all commands, flags, query syntax, time formats, workflows,
50+
best practices, and anti-patterns. This is the same output returned
51+
by --help when running in agent mode.
52+
53+
FLAGS:
54+
--compact Output minimal schema (command names and flags only)
55+
56+
EXAMPLES:
57+
pup agent schema
58+
pup agent schema --compact`,
59+
RunE: runAgentSchema,
60+
}
61+
62+
var agentGuideCmd = &cobra.Command{
63+
Use: "guide [domain]",
64+
Short: "Output the comprehensive steering guide",
65+
Long: `Output the pup steering guide for AI coding assistants.
66+
67+
Without arguments, outputs the full guide. With a domain argument,
68+
outputs only the section relevant to that domain.
69+
70+
EXAMPLES:
71+
pup agent guide
72+
pup agent guide logs
73+
pup agent guide metrics
74+
pup agent guide monitors
75+
pup agent guide apm`,
76+
Args: cobra.MaximumNArgs(1),
77+
RunE: runAgentGuide,
78+
}
79+
80+
func init() {
81+
agentSchemaCmd.Flags().BoolVar(&agentSchemaCompact, "compact", false, "Output minimal schema (names + flags only)")
82+
83+
agentCmd.AddCommand(agentSchemaCmd)
84+
agentCmd.AddCommand(agentGuideCmd)
85+
}
86+
87+
func runAgentSchema(cmd *cobra.Command, args []string) error {
88+
root := cmd.Root()
89+
90+
var data interface{}
91+
if agentSchemaCompact {
92+
data = agenthelp.GenerateCompactSchema(root)
93+
} else {
94+
data = agenthelp.GenerateSchema(root)
95+
}
96+
97+
out, err := json.MarshalIndent(data, "", " ")
98+
if err != nil {
99+
return fmt.Errorf("failed to marshal schema: %w", err)
100+
}
101+
102+
printOutput("%s\n", string(out))
103+
return nil
104+
}
105+
106+
func runAgentGuide(cmd *cobra.Command, args []string) error {
107+
if len(args) == 1 {
108+
printOutput("%s\n", agenthelp.GetGuideSection(args[0]))
109+
return nil
110+
}
111+
printOutput("%s\n", agenthelp.GetGuide())
112+
return nil
113+
}
114+

0 commit comments

Comments
 (0)