// lines ~875-905newSession: async (options) => { // ... const success = await this.session.newSession({ parentSession: options?.parentSession }); if (options?.setup) { await options.setup(this.sessionManager); // Messages are appended to SessionManager }
// BUT: Agent state is NOT synced after setup() // The agent was reset in session.newSession(), and messages added via setup() // are only in the SessionManager, not in the Agent's state.
this.chatContainer.clear(); // ...renders "✓ New session started" instead of the actual messages this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1)); return { cancelled: false };};if (options?.setup) { await options.setup(this.sessionManager);}
this.chatContainer.clear();// ...this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));if (options?.setup) { await options.setup(this.sessionManager); // Sync agent state with session manager after setup const sessionContext = this.sessionManager.buildSessionContext(); this.session.agent.replaceMessages(sessionContext.messages);}
this.chatContainer.clear();this.pendingMessagesContainer.clear();this.compactionQueuedMessages = [];this.streamingComponent = undefined;this.streamingMessage = undefined;this.pendingTools.clear();
// Render messages if any were added via setup, otherwise show simple confirmationconst hasMessages = this.sessionManager.getBranch().some(e => e.type === 'message');if (hasMessages) { this.renderInitialMessages();} else { this.chatContainer.addChild(new Spacer(1)); this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));}
this.ui.requestRender();private _appendEntry(entry: SessionEntry): void { this.fileEntries.push(entry); this.byId.set(entry.id, entry); this.leafId = entry.id; // ✓ Leaf is updated this._persist(entry);}// Change NewSessionOptions or add setup parameterasync newSession(options?: { parentSession?: string; setup?: (sessionManager: SessionManager) => Promise<void>;}): Promise<boolean> { // ... existing event emission and abort logic ... this._disconnectFromAgent(); await this.abort(); this.agent.reset(); this.sessionManager.newSession({ parentSession: options?.parentSession }); this.agent.sessionId = this.sessionManager.getSessionId(); this._steeringMessages = []; this._followUpMessages = []; this._pendingNextTurnMessages = []; // NEW: Run setup if provided if (options?.setup) { await options.setup(this.sessionManager); // Sync agent state with session manager const sessionContext = this.sessionManager.buildSessionContext(); this.agent.replaceMessages(sessionContext.messages); } this._reconnectToAgent(); // ... rest of method ...}newSession: async (options) => { // Clear UI loading state if (this.loadingAnimation) { this.loadingAnimation.stop(); this.loadingAnimation = undefined; } this.statusContainer.clear();
// Delegate to AgentSession (handles setup + agent sync) const success = await this.session.newSession(options); if (!success) { return { cancelled: true }; }
// UI cleanup this.chatContainer.clear(); this.pendingMessagesContainer.clear(); this.compactionQueuedMessages = []; this.streamingComponent = undefined; this.streamingMessage = undefined; this.pendingTools.clear();
// Render messages (works whether setup added messages or not) this.renderInitialMessages(); this.ui.requestRender();
return { cancelled: false };},cd /Users/badlogic/workspaces/pi-mono./pi-test.sh --extension /tmp/test-new-session-extension.ts