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

Method chatContextClearCommand

cli/exp_chat.go:133–180  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131}
132
133func (*RootCmd) chatContextClearCommand() *serpent.Command {
134 var chatID string
135 agentAuth := &AgentAuth{}
136 cmd := &serpent.Command{
137 Use: "clear",
138 Short: "Clear context from an active chat",
139 Long: "Soft-delete all context-file and skill messages from an active chat. " +
140 "The next turn will re-fetch default context from the agent.",
141 Handler: func(inv *serpent.Invocation) error {
142 ctx := inv.Context()
143 ctx, stop := inv.SignalNotifyContext(ctx, StopSignals...)
144 defer stop()
145
146 client, err := agentAuth.CreateClient()
147 if err != nil {
148 return xerrors.Errorf("create agent client: %w", err)
149 }
150
151 resolvedChatID, err := parseChatID(chatID)
152 if err != nil {
153 return err
154 }
155
156 resp, err := client.ClearChatContext(ctx, agentsdk.ClearChatContextRequest{
157 ChatID: resolvedChatID,
158 })
159 if err != nil {
160 return xerrors.Errorf("clear chat context: %w", err)
161 }
162
163 if resp.ChatID == uuid.Nil {
164 _, _ = fmt.Fprintln(inv.Stdout, "No active chats to clear.")
165 } else {
166 _, _ = fmt.Fprintf(inv.Stdout, "Cleared context from chat %s\n", resp.ChatID)
167 }
168 return nil
169 },
170 Options: serpent.OptionSet{{
171 Name: "Chat ID",
172 Flag: "chat",
173 Env: "CODER_CHAT_ID",
174 Description: "Chat ID to clear context from. Auto-detected from CODER_CHAT_ID, the only active chat, or the only top-level active chat.",
175 Value: serpent.StringOf(&chatID),
176 }},
177 }
178 agentAuth.AttachOptions(cmd, false)
179 return cmd
180}
181
182// parseChatID returns the chat UUID from the flag value (which
183// serpent already populates from --chat or CODER_CHAT_ID). Returns

Callers 1

chatContextCommandMethod · 0.95

Calls 6

CreateClientMethod · 0.95
AttachOptionsMethod · 0.95
parseChatIDFunction · 0.85
ClearChatContextMethod · 0.80
ContextMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected