Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import GlobalCreateButton from './components/GlobalCreateButton'
import WorkItemDialog from './components/dialogs/WorkItemDialog'
import NewSprintDialog from './components/dialogs/NewSprintDialog'
import NewProjectDialog from './components/dialogs/NewProjectDialog'
import AiProjectPlannerDialog from './components/dialogs/AiProjectPlannerDialog'

export default function App() {
const [token, setToken] = useState<string | null>(loadToken)
Expand All @@ -22,7 +23,7 @@ export default function App() {
const [tab, setTab] = useState<Tab>('board')
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [createType, setCreateType] = useState<'item' | 'sprint' | 'project' | null>(null)
const [createType, setCreateType] = useState<'item' | 'sprint' | 'project' | 'ai' | null>(null)

// Load projects when user signs in
useEffect(() => {
Expand Down Expand Up @@ -125,6 +126,19 @@ export default function App() {
if (projectId === selectedId) setSprints(s => [...s, sprint])
}

async function handleAiSprintCreate(data: Omit<Sprint, 'id' | 'projectId'>, projectId: string): Promise<Sprint> {
if (!token) throw new Error('Not authenticated')
const sprint = await api.createSprint(token, projectId, data)
if (projectId === selectedId) setSprints(s => [...s, sprint])
return sprint
}

async function handleAiItemCreate(data: Omit<WorkItem, 'id' | 'projectId'>, projectId: string) {
if (!token) return
const item = await api.createWorkItem(token, projectId, data)
if (projectId === selectedId) setWorkItems(w => [...w, item])
}

return (
<div style={layout}>
{createType === 'item' && selectedId && (
Expand All @@ -149,6 +163,15 @@ export default function App() {
onClose={() => setCreateType(null)}
/>
)}
{createType === 'ai' && selectedId && (
<AiProjectPlannerDialog
projects={projects}
defaultProjectId={selectedId}
onCreateSprint={handleAiSprintCreate}
onCreateItem={handleAiItemCreate}
onClose={() => setCreateType(null)}
/>
)}
<ProjectList
projects={projects}
selectedId={selectedId}
Expand Down
83 changes: 83 additions & 0 deletions src/api/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export interface AiSprintInput {
focus: 'features' | 'bugs' | 'mixed'
}

export interface AiProjectPlan {
sprints: AiSprintPlan[]
}

export interface AiProjectInput {
projectName: string
goal: string
startDate: string // YYYY-MM-DD — first sprint start
sprintCount: number // 1–6
sprintDurationWeeks: number // 1–4
teamSize: number // 1–10
}

function addDays(date: string, days: number): string {
const d = new Date(date)
d.setDate(d.getDate() + days)
Expand Down Expand Up @@ -78,3 +91,73 @@ Respond with ONLY valid JSON matching this exact schema — no markdown, no expl
throw new Error('Claude returned invalid JSON. Try again.')
}
}

export async function generateProjectPlan(input: AiProjectInput): Promise<AiProjectPlan> {
const apiKey = import.meta.env.VITE_ANTHROPIC_API_KEY
if (!apiKey) throw new Error('VITE_ANTHROPIC_API_KEY is not set in your .env file')

const client = new Anthropic({ apiKey, dangerouslyAllowBrowser: true })

const itemsPerSprint = Math.max(3, Math.min(12, input.teamSize * 2))
const sprintDays = input.sprintDurationWeeks * 7

const sprintDates = Array.from({ length: input.sprintCount }, (_, i) => ({
startDate: addDays(input.startDate, i * sprintDays),
endDate: addDays(input.startDate, (i + 1) * sprintDays - 1),
}))

const prompt = `You are a software project manager. Create a complete project plan for the following goal:

"${input.goal}"

Project name: ${input.projectName}
Number of sprints: ${input.sprintCount}
Sprint duration: ${input.sprintDurationWeeks} week(s) each
Team size: ${input.teamSize} person(s)
Target items per sprint: ~${itemsPerSprint}

Sprint schedule:
${sprintDates.map((d, i) => ` Sprint ${i + 1}: ${d.startDate} → ${d.endDate}`).join('\n')}

Structure the work logically: foundation and setup early, core features in the middle, polish and testing at the end.
Distribute work evenly. Each sprint should have ~${itemsPerSprint} items.

Respond with ONLY valid JSON — no markdown fences, no explanation:

{
"sprints": [
{
"sprint": {
"name": "string (short, action-oriented sprint name)",
"description": "string (1-2 sentence sprint goal)",
"startDate": "YYYY-MM-DD",
"endDate": "YYYY-MM-DD",
"status": "planned"
},
"workItems": [
{
"title": "string (concise task title)",
"description": "string (1 sentence explaining the task)",
"type": "feature" | "bug" | "task",
"priority": "high" | "medium" | "low",
"storyPoints": number
}
]
}
]
}`

const message = await client.messages.create({
model: 'claude-haiku-4-5-20251001',
max_tokens: 4096,
messages: [{ role: 'user', content: prompt }],
})

const text = message.content.find(b => b.type === 'text')?.text ?? ''

try {
return JSON.parse(text) as AiProjectPlan
} catch {
throw new Error('Claude returned invalid JSON. Try again.')
}
}
9 changes: 5 additions & 4 deletions src/components/GlobalCreateButton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useState, useRef, useEffect } from 'react'

type CreateType = 'item' | 'sprint' | 'project'
type CreateType = 'item' | 'sprint' | 'project' | 'ai'

interface Props {
onCreate: (type: CreateType) => void
}

const OPTIONS: { type: CreateType; label: string; description: string }[] = [
{ type: 'item', label: 'Work Item', description: 'Task, feature, or bug' },
{ type: 'sprint', label: 'Sprint', description: 'Timebox for a set of work' },
{ type: 'project', label: 'Project', description: 'New calendar-backed project' },
{ type: 'item', label: 'Work Item', description: 'Task, feature, or bug' },
{ type: 'sprint', label: 'Sprint', description: 'Timebox for a set of work' },
{ type: 'project', label: 'Project', description: 'New calendar-backed project' },
{ type: 'ai', label: '✨ AI Planner', description: 'Describe a goal, Claude plans the work' },
]

export default function GlobalCreateButton({ onCreate }: Props) {
Expand Down
Loading
Loading