Skip to content

feat(app-builder): add user-initiated new chat session#1720

Open
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
session/agent_30f4aaeb-b338-4cb7-b01a-5b3acf0942cb
Open

feat(app-builder): add user-initiated new chat session#1720
kilo-code-bot[bot] wants to merge 1 commit intomainfrom
session/agent_30f4aaeb-b338-4cb7-b01a-5b3acf0942cb

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 30, 2026

Summary

Adds a "New Chat" button to the app builder chat pane header, allowing users to start a fresh AI session within an existing project. The new session gets a clean LLM context while preserving the project's full codebase and previous session history.

User flow:

  1. User clicks the SquarePen icon in the chat header (disabled while streaming)
  2. The chat area clears to show "New chat session — Your code is preserved — the AI starts with fresh context" and the input is enabled
  3. Clicking the button again cancels and returns to the current session view
  4. Sending a message creates a new cloud agent session via forceNewSession: true on the existing sendMessage endpoint; the old session collapses into an expandable history block via the existing session-change machinery

Architecture: The forceNewSession flag is handled at the ProjectManager level — it bypasses the session/streaming layers entirely and calls tRPC directly, then delegates to the existing handleSessionChanged handler. Zero changes to V1/V2 session or streaming code. No DB migration needed (the reason column is freeform text).

Verification

  • Manual code review of the full change set; all 10 files verified for type consistency
  • Traced tRPC input flow from Zod schema → service type → service logic → both personal and org routers
  • Confirmed forceNewSession path in app-builder-service.ts bypasses shouldCreateNewSession and uses the existing createV1Session/createV2Session helpers with the new user_initiated reason
  • Confirmed pendingNewSession state resets correctly on send, cancel, and session creation

Visual Changes

N/A — chat pane only; a SquarePen icon is added to the header bar.

Reviewer Notes

  • The SquarePen button is a toggle: click to enter pending mode, click again to cancel. It is disabled while isStreaming is true so users cannot trigger it mid-stream.
  • The sendMessageAsNewSession function in ProjectManager.ts calls tRPC directly (rather than going through the session layer) because the existing session must be ended server-side before the new one is created. The response triggers handleSessionChanged, which reuses all existing session-change UI logic.
  • AppBuilderSessionReason.UserInitiated ('user_initiated') is added to the schema constant but requires no migration since the column is text NOT NULL with no DB-level constraint on values.

- introduce user_initiated session reason and forceNewSession flow to start a fresh chat on demand
- update API, routers, and UI to support forcing a new
cloud agent session when the user clicks New Chat, bypassing
automatic session changes
- add pendingNewSession state and actions to ProjectManager
and AppBuilderChat to manage the new-chat lifecycle
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Mar 30, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (10 files)
  • packages/db/src/schema.ts
  • src/components/app-builder/AppBuilderChat.tsx
  • src/components/app-builder/ProjectManager.ts
  • src/components/app-builder/project-manager/store.ts
  • src/components/app-builder/project-manager/types.ts
  • src/lib/app-builder/app-builder-service.ts
  • src/lib/app-builder/types.ts
  • src/routers/app-builder-router.ts
  • src/routers/app-builder/schemas.ts
  • src/routers/organizations/organization-app-builder-router.ts

Reviewed by gpt-5.4-20260305 · 820,265 tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant