@@ -108,10 +108,22 @@ func (w *AppWorkspace) AgentRun(ctx context.Context, sessionID, prompt string, a
110func (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, command string, termWidth int) (proto.ShellCommandResponse, error) {
110func (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, command string, termWidth int) (proto.ShellCommandResponse, error) {
111+ var isFirstMessage bool
111 var persist shell.PersistFunc
112 var persist shell.PersistFunc
112 if sessionID != "" {
113 if sessionID != "" {
113 persist = func(cmd, output string, exitCode int) error {
114 persist = func(cmd, output string, exitCode int) error {
115+ // Check if this is the first user message before persisting.
116+ msgs, err := w.app.Messages.List(ctx, sessionID)
118+ isFirstMessage = true
119+ for _, msg := range msgs {
120+ if msg.Role == message.User {
121+ isFirstMessage = false
114− _, err := w.app.Messages.Create(ctx, sessionID, message.CreateMessageParams{
126+ _, err = w.app.Messages.Create(ctx, sessionID, message.CreateMessageParams{
115 Role: message.User,
127 Role: message.User,
116 Parts: []message.ContentPart{message.ShellCommand{
128 Parts: []message.ContentPart{message.ShellCommand{
117 Command: cmd,
129 Command: cmd,
@@ -132,6 +144,20 @@ func (w *AppWorkspace) AgentRunShellCommand(ctx context.Context, sessionID, comm
132 return proto.ShellCommandResponse{}, err
144 return proto.ShellCommandResponse{}, err
147+ // Generate a title from the shell command if it was the first message.
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)
155+ if w.app.AgentCoordinator != nil {
156+ w.app.AgentCoordinator.GenerateTitle(titleCtx, sessionID, "$ "+command)
135 return proto.ShellCommandResponse{
161 return proto.ShellCommandResponse{
136 Output: result.Output,
162 Output: result.Output,
137 ExitCode: result.ExitCode,
163 ExitCode: result.ExitCode,