- Add optional globalDir parameter to resolveProject(), getDefaultProject(), setDefaultProject(), and clearDefaultProject() for test isolation - Remove ESLint suppression by using void operator for intentionally unused var - Update all tests to use isolated globalDir parameter - Complete tests for default project resolution
15 KiB
Task: KB-032 - Add Planning Mode Feature to Dashboard
Created: 2026-03-30 Size: L
Review Level: 2 (Plan and Code)
Assessment: This is a significant dashboard feature requiring new UI components, API endpoints, and AI integration. It touches multiple layers (React frontend, Express backend, AI agent integration) but follows established patterns in the codebase. Score: 6/8 — Blast radius: 2, Pattern novelty: 1, Security: 1, Reversibility: 2
Mission
Add an interactive "Planning Mode" to the kb dashboard that enables users to enter a high-level plan (e.g., "Build a user authentication system"), then engage in a guided AI conversation to refine and structure that plan. The AI asks clarifying questions, presents UI-based selections (checkboxes, dropdowns, etc.) for user choices, and ultimately generates a summary card that gets input into the task system as a detailed, well-defined task ready for triage.
This feature bridges the gap between rough ideas and actionable task specifications by providing an interactive planning experience directly in the dashboard.
Dependencies
- Package:
@mariozechner/pi-coding-agent(providescreateKbAgentfunction for AI sessions — already used by@kb/engine)
Context to Read First
packages/dashboard/app/App.tsx— Main app component, understand modal state managementpackages/dashboard/app/api.ts— API client patterns and existing fetch functionspackages/dashboard/app/components/GitHubImportModal.tsx— Reference for modal implementation patternpackages/dashboard/app/components/InlineCreateCard.tsx— Reference for card-based creation UIpackages/dashboard/src/routes.ts— Server-side API route patterns, especially AI-related endpointspackages/engine/src/triage.ts— AI agent integration patterns (lines 1-300)packages/core/src/types.ts— Core type definitions (Task, TaskCreateInput, etc.)
File Scope
New Files:
packages/dashboard/app/components/PlanningModeModal.tsx— Main planning mode modal componentpackages/dashboard/app/components/PlanningModeModal.test.tsx— Component testspackages/dashboard/src/planning.ts— Server-side planning session management and AI integrationpackages/dashboard/src/planning.test.ts— Unit tests for planning session logicpackages/dashboard/README.md— Dashboard package documentation (create if doesn't exist)
Modified Files:
packages/dashboard/app/App.tsx— Add planning modal state and triggerpackages/dashboard/app/api.ts— Export planning API functionspackages/dashboard/app/components/Header.tsx— Add "Plan" button to headerpackages/dashboard/app/components/Header.test.tsx— Add tests for Plan buttonpackages/dashboard/src/routes.ts— Add/api/planning/*routes that delegate to planning.tspackages/dashboard/app/styles.css— Add planning mode specific styles
Steps
Step 1: Backend Planning API Infrastructure
Create the server-side planning mode API that manages AI conversations.
-
Create
/api/planning/startendpoint (POST) that:- Accepts
{ initialPlan: string }in body - Creates a temporary planning session with unique ID
- Initializes AI agent with planning system prompt
- Returns
{ sessionId: string, firstQuestion: PlanningQuestion }
- Accepts
-
Create
/api/planning/respondendpoint (POST) that:- Accepts
{ sessionId: string, responses: Record<string, unknown> } - Sends user responses to AI agent
- Returns next question or final summary:
{ type: "question" | "complete", data: PlanningQuestion | PlanningSummary }
- Accepts
-
Create
/api/planning/cancelendpoint (POST) that:- Accepts
{ sessionId: string } - Cleans up session and AI agent resources
- Accepts
-
Create
/api/planning/create-taskendpoint (POST) that:- Accepts
{ sessionId: string }and creates actual task from planning summary - Uses
store.createTask()with the refined plan as description - Returns created
Task - Cleans up the planning session
- Accepts
-
Define TypeScript types in routes.ts:
interface PlanningQuestion { id: string; type: "text" | "single_select" | "multi_select" | "confirm"; question: string; description?: string; options?: Array<{ id: string; label: string; description?: string }>; } interface PlanningSummary { title: string; description: string; suggestedSize: "S" | "M" | "L"; suggestedDependencies: string[]; keyDeliverables: string[]; } -
Implement in-memory session storage (Map) with 30-minute TTL and cleanup
-
Add rate limiting: max 5 planning sessions per IP per hour
-
Write tests for all planning endpoints in
routes.test.ts
Design Notes:
- The
routes.tsfile should define the HTTP routes and delegate business logic to functions imported fromplanning.ts - This keeps route handlers thin and makes testing easier
Artifacts:
packages/dashboard/src/routes.ts(modified)packages/dashboard/src/planning.ts(new — implementation will be completed in Step 5)
Step 2: Frontend API Client
Create the API client functions for the planning mode.
-
Add to
packages/dashboard/app/api.ts:export interface PlanningSession { sessionId: string; currentQuestion: PlanningQuestion | null; summary: PlanningSummary | null; } export function startPlanning(initialPlan: string): Promise<PlanningSession> export function respondToPlanning(sessionId: string, responses: Record<string, unknown>): Promise<PlanningSession> export function cancelPlanning(sessionId: string): Promise<void> export function createTaskFromPlanning(sessionId: string): Promise<Task> -
Implement error handling with proper typing
-
Write tests in
api.test.tsfor planning functions
Artifacts:
packages/dashboard/app/api.ts(modified)packages/dashboard/app/api.test.ts(modified)
Step 3: Planning Mode Modal Component
Build the main interactive planning UI component.
-
Create
PlanningModeModal.tsxwith props:interface PlanningModeModalProps { isOpen: boolean; onClose: () => void; onTaskCreated: (task: Task) => void; tasks: Task[]; // For dependency suggestions } -
Implement "Initial Input" view:
- Large textarea for high-level plan description
- "Start Planning" button
- Example suggestions (quick-start chips)
- Character counter (max 500 chars for initial input)
-
Implement "Question" view with dynamic form rendering:
text: Textarea inputsingle_select: Radio button group or dropdownmulti_select: Checkbox groupconfirm: Yes/No toggle buttons- Progress indicator (question X of estimated Y)
- "Back" button to revisit previous answers (maintain history)
- Show thinking indicator while AI processes responses
-
Handle browser unload during active session:
- Add
beforeunloadevent listener when session is active - Show browser's default "Leave site?" warning to prevent accidental data loss
- Clean up listener when modal closes or session completes
- Add
-
Implement "Summary" view:
- Display generated title with edit capability
- Display refined description (collapsible)
- Display suggested size (editable via dropdown: S/M/L)
- Display suggested dependencies (toggle chips from existing tasks)
- Display key deliverables as bullet list
- "Create Task" and "Refine Further" buttons
-
Implement loading states with spinner
-
Handle errors with toast notifications via
useToast -
Support keyboard navigation (Tab through options, Enter to submit)
-
Support Escape key to close (with confirmation if in progress)
-
Write comprehensive tests in
PlanningModeModal.test.tsxcovering:- Opening/closing the modal
- Initial plan submission
- Question rendering for all question types
- Response submission flow
- Summary display and task creation
- Error handling
- Cancel/close behavior
Artifacts:
packages/dashboard/app/components/PlanningModeModal.tsx(new)packages/dashboard/app/components/PlanningModeModal.test.tsx(new)
Step 4: Dashboard Integration
Integrate the planning mode into the main dashboard UI.
-
Modify
Header.tsx:- Add "Plan" button with lightbulb icon (from lucide-react) next to "+" button
- Use
btn btn-smclass for styling - Show tooltip on hover: "Create a task with AI planning"
-
Modify
App.tsx:- Add
isPlanningOpenstate - Add
planningTaskstate for created task - Add
handlePlanningOpen,handlePlanningClose,handlePlanningTaskCreatedcallbacks - Include
<PlanningModeModal />in the render tree - Pass
tasksprop to modal for dependency suggestions
- Add
-
Update
Header.test.tsx:- Add test for "Plan" button rendering
- Add test for button click opening planning mode
-
Update
App.test.tsx:- Add integration test for planning mode flow
- Mock planning API calls
Artifacts:
packages/dashboard/app/components/Header.tsx(modified)packages/dashboard/app/components/Header.test.tsx(modified)packages/dashboard/app/App.tsx(modified)
Step 5: AI Agent Integration
Implement the server-side AI agent for planning conversations.
-
Create planning system prompt constant:
const PLANNING_SYSTEM_PROMPT = `You are a planning assistant for the kb task board system. Your job: help users transform vague, high-level ideas into well-defined, actionable tasks. ## Conversation Flow 1. User provides a high-level plan (e.g., "Build a user auth system") 2. You ask clarifying questions to understand scope, requirements, and constraints 3. You present UI-friendly selection options when appropriate 4. Once you have enough information, generate a structured summary ## Question Types to Use - "text": Open-ended follow-up questions - "single_select": When user must choose one option (e.g., tech stack preference) - "multi_select": When multiple options can apply (e.g., features to include) - "confirm": Yes/No questions for quick decisions ## Guidelines - Ask 3-7 questions depending on complexity - Start broad, then narrow down specifics - Suggest sensible defaults based on project context - Keep questions focused and actionable - When asking about file scope, reference actual project structure ## Summary Generation When ready to complete, generate: - A concise but descriptive title - A detailed description with context gathered - Size estimate (S/M/L) based on scope - Any suggested dependencies on existing tasks - Key deliverables as a checklist`; -
Implement session management class:
class PlanningSession { id: string; agent: AgentSession; history: Array<{ question: PlanningQuestion; response: unknown }>; createdAt: Date; constructor(initialPlan: string, rootDir: string) async getNextQuestion(): Promise<PlanningQuestion | PlanningSummary> async submitResponse(response: unknown): Promise<PlanningQuestion | PlanningSummary> dispose(): void } -
Integrate with pi-coding-agent's
createKbAgentfunction (same pattern as triage.ts) -
Implement tool for reading project structure to inform suggestions
-
Implement tool for searching existing tasks to suggest dependencies
-
Add error handling for AI agent failures (graceful fallback with error message to user)
-
Write unit tests for planning session logic including:
- Session initialization
- Question generation flow
- Response handling
- Summary generation
- Session cleanup/timeout
- Rate limiting enforcement
- Error handling when AI agent fails
Artifacts:
packages/dashboard/src/planning.ts(new)packages/dashboard/src/planning.test.ts(new)
Step 6: Styling
Add CSS styles for the planning mode UI following existing design system.
-
Add planning modal layout styles:
.planning-modal { /* modal sizing */ } .planning-content { /* flex layout */ } .planning-initial { /* centered input form */ } .planning-question { /* question display */ } .planning-options { /* option groups */ } .planning-option { /* individual option */ } .planning-summary { /* summary view */ } .planning-progress { /* progress bar */ } -
Ensure dark theme consistency with existing CSS variables
-
Add responsive styles for mobile (stacked layout, full-width on small screens)
-
Add animation styles for question transitions
Artifacts:
packages/dashboard/app/styles.css(modified)
Step 7: Testing & Verification
ZERO test failures allowed. Full test suite as quality gate.
- Run full test suite:
pnpm test - Fix all failures in dashboard package
- Ensure build passes:
pnpm build - Test manually:
- Open dashboard with
pnpm dev:ui - Click "Plan" button
- Enter high-level plan
- Go through question flow
- Verify summary generation
- Create task and verify it appears in triage
- Test cancel/close behavior at each step
- Test error handling (network errors, etc.)
- Open dashboard with
Artifacts:
- All tests passing
- Manual QA completed
Step 8: Documentation & Delivery
-
Update
packages/dashboard/README.md:- Add section about Planning Mode feature
- Document user-facing functionality
-
Create changeset for the feature:
cat > .changeset/add-planning-mode.md << 'EOF' --- "@dustinbyrne/kb": minor --- Add Planning Mode to the dashboard for interactive AI-guided task creation EOF -
Out-of-scope findings (create follow-up tasks if discovered):
- Performance optimizations for large task lists in dependency selection
- Export planning conversations for debugging
- Collaborative planning (multiple users)
Artifacts:
packages/dashboard/README.md(modified).changeset/add-planning-mode.md(new)
Documentation Requirements
Must Update:
packages/dashboard/README.md— Create this file with a Planning Mode section explaining the feature (if it doesn't exist, create as new file)
Check If Affected:
AGENTS.md— Update if task creation patterns change- Root
README.md— Add mention of Planning Mode feature if user-facing docs exist
Completion Criteria
- All steps complete
- All tests passing (
pnpm test) - Build passes (
pnpm build) - Manual QA completed and verified
- Documentation updated
- Changeset created
- No TypeScript errors (
pnpm typecheck)
Git Commit Convention
Commits at step boundaries. All commits include the task ID:
- Step completion:
feat(KB-032): complete Step N — description - Example:
feat(KB-032): complete Step 1 — backend planning API infrastructure - Bug fixes:
fix(KB-032): description - Tests:
test(KB-032): description - Docs:
docs(KB-032): description
Do NOT
- Expand task scope beyond interactive planning mode
- Skip writing tests for any new code
- Modify files outside the File Scope without explicit reason
- Commit without the task ID prefix
- Use external AI APIs directly — always go through the engine's agent infrastructure
- Store planning session data persistently (keep in-memory only)
- Allow planning sessions to run indefinitely (implement timeouts)
- Skip accessibility considerations (keyboard navigation, ARIA labels)