From a52fdb633fef330554375fc88f9e078ec106a1e8 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Mon, 9 Mar 2026 15:32:13 +0800 Subject: [PATCH] check nil --- pkg/agent/loop.go | 3 +++ pkg/commands/cmd_clear.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 58c55ca86..ae8dcfeb7 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1754,6 +1754,9 @@ func (al *AgentLoop) buildCommandsRuntime(agent *AgentInstance, opts *processOpt } rt.ClearHistory = func() error { + if opts == nil { + return fmt.Errorf("process options not available") + } if agent.Sessions == nil { return fmt.Errorf("sessions not initialized for agent") } diff --git a/pkg/commands/cmd_clear.go b/pkg/commands/cmd_clear.go index a215faf58..f0951eb3b 100644 --- a/pkg/commands/cmd_clear.go +++ b/pkg/commands/cmd_clear.go @@ -8,6 +8,9 @@ func clearCommand() Definition { Description: "Clear the chat history", Usage: "/clear", Handler: func(_ context.Context, req Request, rt *Runtime) error { + if rt == nil || rt.ClearHistory == nil { + return req.Reply(unavailableMsg) + } if err := rt.ClearHistory(); err != nil { return req.Reply("Failed to clear chat history: " + err.Error()) }