on main help sign in
fix(bang): set title in bang mode
commit03bfdc66fb2633b799170d95c984625d03f9db8d authorKieran Klukas <kieran@dunkirk.sh> dateFri 19 Jun 2026, 10:16 (4 months ago) parentf82a468
2 files changed+38−2
internal/agent/agent.go+11−1 internal/workspace/app_workspace.go+27−1
internal/agent/agent.go+11−1
@@ -1742,7 +1742,17 @@ func (a *sessionAgent) GenerateTitle(ctx context.Context, sessionID string, user
17421742 title = orphanThinkTagRegex.ReplaceAllString(title, "")
17431743
17441744 title = strings.TrimSpace(title)
1745− title = cmp.Or(title, DefaultSessionName)
1745+ if title == "" {
1746+ // LLM returned empty content. Use the prompt itself as a
1747+ // fallback title, truncated to 50 chars, before resorting to
1748+ // the generic default.
1749+ fallback := strings.ReplaceAll(userPrompt, "\n", " ")
1750+ fallback = strings.TrimSpace(fallback)
1751+ if len(fallback) > 50 {
1752+ fallback = fallback[:50]
1753+ }
1754+ title = cmp.Or(fallback, DefaultSessionName)
1755+ }
17461756
17471757 // Calculate usage and cost.
17481758 var openrouterCost *float64
internal/workspace/app_workspace.go+27−1
@@ -108,10 +108,22 @@ func (w *AppWorkspace) AgentRun(ctx context.Context, sessionID, prompt string, a
108108}
109109
110110func (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, command string, termWidth int) (proto.ShellCommandResponse, error) {
111+ var isFirstMessage bool
111112 var persist shell.PersistFunc
112113 if sessionID != "" {
113114 persist = func(cmd, output string, exitCode int) error {
114− _, err := w.app.Messages.Create(ctx, sessionID, message.CreateMessageParams{
115+ // Check if this is the first user message before persisting.
116+ msgs, err := w.app.Messages.List(ctx, sessionID)
117+ if err == nil {
118+ isFirstMessage = true
119+ for _, msg := range msgs {
120+ if msg.Role == message.User {
121+ isFirstMessage = false
122+ break
123+ }
124+ }
125+ }
126+ _, err = w.app.Messages.Create(ctx, sessionID, message.CreateMessageParams{
115127 Role: message.User,
116128 Parts: []message.ContentPart{message.ShellCommand{
117129 Command: cmd,
@@ -132,6 +144,20 @@ func (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, comm
132144 return proto.ShellCommandResponse{}, err
133145 }
134146
147+ // Generate a title from the shell command if it was the first message.
148+ if isFirstMessage {
149+ go func() {
150+ titleCtx := context.WithoutCancel(ctx)
151+ // Wait for the agent to be ready before generating.
152+ for i := 0; i < 50 && w.app.AgentCoordinator == nil; i++ {
153+ time.Sleep(100 * time.Millisecond)
154+ }
155+ if w.app.AgentCoordinator != nil {
156+ w.app.AgentCoordinator.GenerateTitle(titleCtx, sessionID, "$ "+command)
157+ }
158+ }()
159+ }
160+
135161 return proto.ShellCommandResponse{
136162 Output: result.Output,
137163 ExitCode: result.ExitCode,