Skip to content

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

Open
kilo-code-bot[bot] wants to merge 2 commits 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 2 commits 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. Existing session history stays visible; a "New chat session — Your code is preserved" placeholder is appended below
  3. Clicking the button again cancels and restores the session to its previous visual state
  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 handleSessionChanged machinery

Architecture: The forceNewSession flag is handled entirely at the ProjectManager level — it calls tRPC directly and 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).

Key implementation details:

  • pendingNewSession (in ProjectManager store) tracks whether the user has clicked "New chat" but not yet sent
  • awaitingNewSession (in AppBuilderChat) bridges the one-render gap between pendingNewSession flipping to false on send and the new session object arriving in state — implemented with useState + useEffect rather than a render-time ref mutation
  • requestNewSession/cancelNewSession set session.info.ended_at optimistically so the current session collapses into a history block while the user composes their message
  • Layout heights changed from h-dvh to h-[calc(100dvh-3.5rem)] across AppBuilderPage, AppBuilderLanding, and ProjectLoader to account for the top navigation bar

Verification

  • 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
  • pnpm typecheck passes; oxfmt format check passes

Visual Changes

Screenshot 2026-03-30 at 22 23 03

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.
  • The previous behaviour replaced the entire chat area with a blank placeholder when pendingNewSession was true. This PR keeps session history visible and only appends the placeholder, which required the awaitingNewSession state to prevent a flicker when pendingNewSession clears on send.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Mar 30, 2026

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Fix these issues in Kilo Cloud

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 0
Issue Details (click to expand)

N/A

Other Observations (not in diff)

Issues found outside the current PR diff and therefore not eligible for inline comments:

File Line Issue
kiloclaw/controller/src/kilo-cli-config.ts 94 Clearing KILOCODE_DEFAULT_MODEL leaves a stale CLI model in opencode.json
src/lib/cloud-agent-next/run-session.ts 266 Fast sessions can hang when the stream connects after the busy transition
src/routers/kiloclaw-router.ts 1061 Polling a stale CLI run can return and persist a newer run's status/output
src/routers/kiloclaw-router.ts 1096 Cancelling a stale CLI run page can terminate the machine's newer active run
Files Reviewed (56 files)
  • kiloclaw/controller/src/kilo-cli-config.ts - 1 issue
  • src/lib/cloud-agent-next/run-session.ts - 1 issue
  • src/routers/kiloclaw-router.ts - 2 issues
  • 52 additional changed files

Reviewed by gpt-5.4-20260305 · 2,290,279 tokens

- Adds a SquarePen toggle in the chat header to enter/cancel new-session mode
- While pending, existing session history remains visible with a 'New chat
  session' placeholder appended below; history was previously replaced entirely
- Sending a message in pending mode calls sendMessage with forceNewSession:true,
  which creates a new cloud-agent session via the existing handleSessionChanged
  machinery (zero changes to V1/V2 session/streaming code)
- awaitingNewSession bridges the gap between pendingNewSession becoming false
  (on send) and the new session object arriving in state, preventing the
  placeholder from flickering away one render early; implemented with useState
  + useEffect instead of a render-time ref mutation
- requestNewSession/cancelNewSession set session.info.ended_at to visually
  collapse the current session into a history block while pending
- Layout heights updated from h-dvh to h-[calc(100dvh-3.5rem)] across
  AppBuilderPage, AppBuilderLanding, and ProjectLoader to account for the
  top navigation bar
- FeedbackDialog no longer disabled during streaming
- pendingNewSession added to ProjectState test fixtures
@eshurakov eshurakov force-pushed the session/agent_30f4aaeb-b338-4cb7-b01a-5b3acf0942cb branch from 77ffe9e to 21f5ddd Compare March 30, 2026 20:44
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