From 712b7ce8306d8bf5b21f35aa51957a82fa771e3b Mon Sep 17 00:00:00 2001 From: bndw Date: Wed, 4 Mar 2026 22:26:24 -0800 Subject: feat: Sync sessions array after phase advance in handleSubmit (+1 more) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ✅ Sync sessions array after phase advance in handleSubmit - ✅ Auto-send initial message in handleConfirmNewSession for plan/implement phases --- CLAUDE.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'CLAUDE.md') diff --git a/CLAUDE.md b/CLAUDE.md index 5d25656..134a510 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -127,6 +127,59 @@ Sidebar demonstrates tree structure for hierarchical data: - Inline edit mode for renaming (Rename modal not needed) - Context awareness (expanded/collapsed states) +## Known Bugs + +### Phase Handling Issues (Critical) + +#### Bug #1: New Session Phase Modal Doesn't Apply Selection +**Status**: Needs debugging +**Description**: When creating a new session and selecting "Implementation" in the phase modal, the session is created with "Research" phase instead of the selected phase. + +**Key Discovery**: The system prompt is determined directly by `session.phase` (src/main/claude/index.ts lines 49, 91, 120). +- If you create an "Implement" session but Claude receives the **Research system prompt**, it PROVES the session.phase is stored as "research" in the database +- This is the smoking gun that reveals Bug #1 is in the **data layer**, not the display + +**Observable symptom**: Create an "Implement" session and send a message. If Claude says "I am in RESEARCH mode" (contains "DO NOT modify any source code files"), the phase is wrong. If Claude says "I am in IMPLEMENTATION mode" (contains "Mark tasks complete"), the phase is correct. + +**Code path**: NewSessionModal → App.handleConfirmNewSession → api.createSession → IPC handler → createSession function → DB INSERT + +**Suspected issue**: Phase parameter may be lost or reset during IPC transmission, despite code appearing correct. The IPC handler receives `phase?: Phase` as optional parameter which defaults to "research" in createSession(). + +**To debug**: +1. Add console.log in NewSessionModal to confirm selected state +2. Add console.log in App.handleConfirmNewSession to confirm phase parameter +3. Add console.log in IPC handler to confirm phase is received +4. Check database directly: `SELECT phase FROM sessions WHERE ... LIMIT 1` +5. Check what system prompt Claude actually receives (see observable symptom above) + +**Related files**: +- `renderer/src/components/NewSessionModal.tsx` (phase selection) +- `src/main/preload.ts` (API bridge - lines 89-90) +- `src/main/ipc/handlers.ts` (IPC handler - lines 26-37) +- `src/main/db/sessions.ts` (createSession function - line 39) +- `src/main/claude/index.ts` (system prompt application - lines 49, 91, 120) + +#### Bug #2: Phase Transition State Not Synced + plan.md Not Rendering +**Status**: Root cause identified ✓ +**Description**: After completing research phase and submitting, the plan phase doesn't show as active in the Sidebar, and plan.md doesn't display (only shows after Claude writes to it). + +**Root cause**: The `sessions` array state in App.tsx is never updated after `advancePhase()` completes. Only `selectedSession` is updated. This causes: +1. **Sidebar inconsistency**: Shows old phase (session object from stale sessions array) +2. **Header is correct**: Shows new phase (uses selectedSession.phase) +3. **plan.md might initially be blank**: Loads before Claude writes it (expected, but confusing) + +**The fix**: In `App.tsx` handleSubmit(), after successful advancePhase, also update the sessions array: +```typescript +setSessions((prev) => + prev.map((s) => (s.id === id ? { ...s, phase: advanced.phase, git_branch: advanced.git_branch } : s)) +); +``` + +**Related files**: +- `renderer/src/App.tsx` (lines 419-446, handleSubmit function) +- `renderer/src/components/Sidebar.tsx` (line 194, displays phase from sessions array) +- `renderer/src/components/Header.tsx` (displays phase from selectedSession - works correctly) + ## Important Notes - `ANTHROPIC_API_KEY` env var must be set before launching @@ -146,3 +199,5 @@ When adding new UI features that require user input: 4. **Settings additions**: Add to `SettingsPage.tsx` with a new section and corresponding settings UI file in `/components/settings/` 5. **IPC endpoints**: Register in `/src/main/ipc/handlers.ts` and expose in `/src/main/preload.ts` 6. **State management**: Keep state in `App.tsx` for global UI state; component local state for transient UI state (e.g., modal visibility, form input) + +**State sync pattern**: When updating sessions in bulk operations (like phase transitions), remember to update BOTH `selectedSession` AND `sessions` array to keep UI consistent across all components. -- cgit v1.2.3