From 73d2680b83ccbdbd8dfec2d319533e98b379b830 Mon Sep 17 00:00:00 2001 From: bndw Date: Wed, 4 Mar 2026 21:36:32 -0800 Subject: feat: Thread optional `phase` param into `db/sessions.ts::cre… (+7 more) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ✅ Thread optional `phase` param into `db/sessions.ts::createSession()` - ✅ Thread optional `phase` param into `ipc/handlers.ts` sessions:create handler - ✅ Thread optional `phase` param into `preload.ts` createSession API - ✅ Update Plan phase system prompt to gracefully handle missing research.md - ✅ Update Implement phase system prompt to gracefully handle missing plan.md - ✅ Create `renderer/src/components/NewSessionModal.tsx` - ✅ Update `App.tsx`: add modal state, split handler, add modal JSX - ✅ Add modal CSS to `globals.css` --- src/main/claude/index.ts | 5 +++-- src/main/claude/phases.ts | 10 ++++++---- src/main/db/sessions.ts | 8 ++++---- src/main/ipc/handlers.ts | 6 +++--- src/main/preload.ts | 6 +++--- 5 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/claude/index.ts b/src/main/claude/index.ts index 8cf512c..9139f17 100644 --- a/src/main/claude/index.ts +++ b/src/main/claude/index.ts @@ -48,8 +48,9 @@ export async function sendMessage({ // Load any custom system prompt for this phase (null → use default) const customSystemPrompt = getSetting(`systemPrompt.${session.phase}`) ?? undefined; - // Load global model override (empty string or null → let SDK use its default) - const configuredModel = getSetting("model") || undefined; + // Phase-specific model override takes precedence; falls back to global default. + const configuredModel = + getSetting(`model.${session.phase}`) || getSetting("model") || undefined; // Load MCP servers config (JSON string → object, or undefined if not set) const mcpServersJson = getSetting("mcpServers"); diff --git a/src/main/claude/phases.ts b/src/main/claude/phases.ts index a1cbba1..e8c16df 100644 --- a/src/main/claude/phases.ts +++ b/src/main/claude/phases.ts @@ -87,11 +87,12 @@ CRITICAL RULES: CONTEXT: - Read CLAUDE.md at project root for codebase overview -- Read ${artifactDir}/research.md to understand the specific task +- Read ${artifactDir}/research.md to understand the specific task. + If research.md does not exist, this session began at the planning phase — base your plan on the task description provided in the chat instead. WORKFLOW: 1. Read CLAUDE.md for codebase overview -2. Read ${artifactDir}/research.md to understand the specific task +2. Read ${artifactDir}/research.md if it exists; otherwise use the task description from chat 3. Write a detailed plan to ${artifactDir}/plan.md 4. Include specific code snippets showing proposed changes 5. Make the plan detailed enough that implementation is mechanical @@ -141,14 +142,15 @@ Remember: Your output goes in ${artifactDir}/plan.md, not chat. Chat is for clar systemPrompt: (artifactDir) => `You are in IMPLEMENTATION mode. Execute the approved plan. CRITICAL RULES: -1. Read ${artifactDir}/plan.md and follow it exactly +1. Read ${artifactDir}/plan.md if it exists and follow it exactly. + If plan.md does not exist, this session began at the implementation phase — implement based on the task description provided in the chat messages. 2. Mark tasks complete in ${artifactDir}/plan.md as you finish them: - [ ] → - [x] 3. DO NOT deviate from the plan without asking 4. Run tests/typecheck if available 5. Stop and ask if you encounter issues not covered by the plan WORKFLOW: -1. Read ${artifactDir}/plan.md +1. Read ${artifactDir}/plan.md (if it exists) 2. Execute each task in order 3. Update ${artifactDir}/plan.md to mark tasks complete 4. Continue until all tasks are done diff --git a/src/main/db/sessions.ts b/src/main/db/sessions.ts index 3e6352c..bc22d15 100644 --- a/src/main/db/sessions.ts +++ b/src/main/db/sessions.ts @@ -36,21 +36,21 @@ export function getSession(id: string): Session | undefined { .get(id) as Session | undefined; } -export function createSession(projectId: string, name: string): Session { +export function createSession(projectId: string, name: string, phase: Phase = "research"): Session { const db = getDb(); const id = uuid(); const now = Math.floor(Date.now() / 1000); db.prepare( `INSERT INTO sessions (id, project_id, name, phase, permission_mode, created_at, updated_at) - VALUES (?, ?, ?, 'research', 'acceptEdits', ?, ?)` - ).run(id, projectId, name, now, now); + VALUES (?, ?, ?, ?, 'acceptEdits', ?, ?)` + ).run(id, projectId, name, phase, now, now); return { id, project_id: projectId, name, - phase: "research", + phase, claude_session_id: null, permission_mode: "acceptEdits", git_branch: null, diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.ts index 4894e1d..975ad01 100644 --- a/src/main/ipc/handlers.ts +++ b/src/main/ipc/handlers.ts @@ -5,7 +5,7 @@ import * as claude from "../claude"; import * as settingsDb from "../db/settings"; import { createSessionBranch, ensureGitIgnore, ensureGitRepo, getCurrentBranch } from "../git"; import { discoverMcpTools } from "../mcp"; -import type { UserPermissionMode } from "../claude/phases"; +import type { UserPermissionMode, Phase } from "../claude/phases"; import { getDefaultSystemPromptTemplate } from "../claude/phases"; export function registerIpcHandlers(mainWindow: BrowserWindow): void { @@ -23,11 +23,11 @@ export function registerIpcHandlers(mainWindow: BrowserWindow): void { sessions.listSessions(projectId) ); - ipcMain.handle("sessions:create", (_, projectId: string, name: string) => { + ipcMain.handle("sessions:create", (_, projectId: string, name: string, phase?: Phase) => { const project = projects.getProject(projectId); if (!project) throw new Error("Project not found"); - const session = sessions.createSession(projectId, name); + const session = sessions.createSession(projectId, name, phase); // Ensure .claude-flow/ is gitignored from day one. // Branch creation is deferred until the session advances to implement. diff --git a/src/main/preload.ts b/src/main/preload.ts index e7ee0aa..fbdf871 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -12,7 +12,7 @@ export interface ClaudeFlowAPI { // Sessions listSessions: (projectId: string) => Promise; - createSession: (projectId: string, name: string) => Promise; + createSession: (projectId: string, name: string, phase?: Phase) => Promise; deleteSession: (id: string) => Promise; getSession: (id: string) => Promise; renameSession: (id: string, name: string) => Promise; @@ -86,8 +86,8 @@ const api: ClaudeFlowAPI = { // Sessions listSessions: (projectId) => ipcRenderer.invoke("sessions:list", projectId), - createSession: (projectId, name) => - ipcRenderer.invoke("sessions:create", projectId, name), + createSession: (projectId, name, phase) => + ipcRenderer.invoke("sessions:create", projectId, name, phase), deleteSession: (id) => ipcRenderer.invoke("sessions:delete", id), getSession: (id) => ipcRenderer.invoke("sessions:get", id), renameSession: (id, name) => ipcRenderer.invoke("sessions:rename", id, name), -- cgit v1.2.3