()
| 131 | } |
| 132 | |
| 133 | func (*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 |
no test coverage detected