MCPcopy Index your code
hub / github.com/coder/coder / chatContextAddCommand

Method chatContextAddCommand

cli/exp_chat.go:45–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45func (*RootCmd) chatContextAddCommand() *serpent.Command {
46 var (
47 dir string
48 chatID string
49 )
50 agentAuth := &AgentAuth{}
51 cmd := &serpent.Command{
52 Use: "add",
53 Short: "Add context to an active chat",
54 Long: "Read instruction files and discover skills from a directory, then add " +
55 "them as context to an active chat session. Multiple calls " +
56 "are additive.",
57 Handler: func(inv *serpent.Invocation) error {
58 ctx := inv.Context()
59 ctx, stop := inv.SignalNotifyContext(ctx, StopSignals...)
60 defer stop()
61
62 if dir == "" && inv.Environ.Get("CODER") != "true" {
63 return xerrors.New("this command must be run inside a Coder workspace (set --dir to override)")
64 }
65
66 client, err := agentAuth.CreateClient()
67 if err != nil {
68 return xerrors.Errorf("create agent client: %w", err)
69 }
70
71 resolvedDir := dir
72 if resolvedDir == "" {
73 resolvedDir, err = os.Getwd()
74 if err != nil {
75 return xerrors.Errorf("get working directory: %w", err)
76 }
77 }
78 resolvedDir, err = filepath.Abs(resolvedDir)
79 if err != nil {
80 return xerrors.Errorf("resolve directory: %w", err)
81 }
82 info, err := os.Stat(resolvedDir)
83 if err != nil {
84 return xerrors.Errorf("cannot read directory %q: %w", resolvedDir, err)
85 }
86 if !info.IsDir() {
87 return xerrors.Errorf("%q is not a directory", resolvedDir)
88 }
89
90 parts := agentcontextconfig.ContextPartsFromDir(resolvedDir)
91 if len(parts) == 0 {
92 _, _ = fmt.Fprintln(inv.Stderr, "No context files or skills found in "+resolvedDir)
93 return nil
94 }
95
96 // Resolve chat ID from flag or auto-detect.
97 resolvedChatID, err := parseChatID(chatID)
98 if err != nil {
99 return err
100 }
101
102 resp, err := client.AddChatContext(ctx, agentsdk.AddChatContextRequest{

Callers 1

chatContextCommandMethod · 0.95

Calls 9

CreateClientMethod · 0.95
AttachOptionsMethod · 0.95
ContextPartsFromDirFunction · 0.92
parseChatIDFunction · 0.85
AddChatContextMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected