Scrum4Me/app/(app)/ideas/[id]/page.tsx
Janpeter Visser d84cdf664f
feat(PBI-67): IDEA_REVIEW_PLAN — iterative multi-model plan review (#199)
* feat(ideas): upload-plan knop — short-circuit van Make-Plan AI-flow

Voegt een 'Upload plan' knop toe in idea-row-actions (verschijnt in zowel
list als idea-detail). Klik → file picker → kies .md → server-side parse +
opslaan; idea-status springt naar PLAN_READY. Vandaaruit de bestaande
'Maak PBI' knop voor materialize.

Server (uploadPlanMdAction):
- Toegestaan vanuit DRAFT, GRILLED, PLAN_FAILED, PLAN_READY
- DRAFT → skip-grill: status gaat direct naar PLAN_READY
- PLAN_READY overschrijft het bestaande plan (consistent met
  updatePlanMdAction, geen confirmation)
- Geblokkeerd in GRILLING/PLANNING (job loopt), PLANNED (al gematerialiseerd)
- Parse-failure → 422 + details (NIET opslaan, zodat een onparseerbaar plan
  nooit in de DB belandt)
- Empty / >100k chars → 422
- Schrijft IdeaLog NOTE met from_status + length
- Rate-limit + demo-guard + ownership-check via loadOwnedIdea (zelfde
  patroon als updatePlanMdAction)

UI (idea-row-actions.tsx):
- Hidden <input type=file accept=".md,.markdown,text/markdown,text/plain">
- FileReader → text → action
- Toast bij success + router.refresh()
- Blocked-tooltip in andere statussen

Tests: 10 nieuwe in __tests__/actions/ideas-crud.test.ts dekkend voor:
happy paths (DRAFT/GRILLED/PLAN_READY-overwrite/PLAN_FAILED), blocks
(PLANNED/GRILLING), validation (empty/oversized/parse-fail), 404.
Full suite groen: 849/849.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Add reviews for Bootstrap-wizard plans v3.2 to v3.4

- Review v3.2: Addressed executor model, fire-and-forget issues, and PAT handling.
- Review v3.3: Improved transaction handling, stale recovery, and ID generation.
- Review v3.4: Finalized GitHub permissions, catalog versioning, and E2E verification queries.
- Updated recommendations for each version to enhance implementation readiness.

* docs(plans): M8 bootstrap-wizard upload-variant v1.4 — backtick-paden

Upload-variant van het volledige technische plan (docs/plans/M8-bootstrap-wizard.md),
bedoeld voor de "Upload plan"-functie. Genereert 1 PBI + 4 Stories + 22 Tasks
via materializeIdeaPlanAction.

v1.4-aanpassingen tov eerdere generatie-iteratie:
- Alle bestandspaden in implementation_plan in backticks (path-extractor matchen)
- Expliciete "Bestanden:" blok per task vóór de stappen
- Alle tasks op verify_required: ALIGNED_OR_PARTIAL (was deels ALIGNED — te strict
  voor ADR-stubs en multi-file edits)

Fixt forward-only: T-963 cancelled_by_self door DIVERGENT verifier-verdict.
Re-upload van dit bestand produceert tasks die door verify_task_against_plan
als ALIGNED of PARTIAL geclassificeerd kunnen worden.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* PBI-67: Add review-plan support to Idea model and job config

- Add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum
- Add IDEA_REVIEW_PLAN config to job-config.ts with model=opus, thinking_budget=6000
- Create migration record for schema changes (applied via db push)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* PBI-67 Phase 2: Add update-idea-plan-reviewed MCP tool

- Create src/tools/update-idea-plan-reviewed.ts: saves review-log and transitions idea status to PLAN_REVIEWED
- Add PLAN_REVIEW_RESULT to IdeaLogType enum (both repos)
- Register tool in src/index.ts
- Update Prisma schemas (both repos): add plan_review_log and reviewed_at fields to Idea model
- Add REVIEWING_PLAN, PLAN_REVIEW_FAILED, PLAN_REVIEWED to IdeaStatus enum (MCP schema)
- Add IDEA_REVIEW_PLAN to ClaudeJobKind enum (MCP schema)
- Tool includes transaction safety and convergence metrics logging

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>

* feat(PBI-67): IDEA_REVIEW_PLAN Phases 3-6 — server actions, UI components, prompt & tests

- Phase 3: startReviewPlanJobAction, cancelIdeaJobAction, status transitions
  (REVIEWING_PLAN / PLAN_REVIEWED / PLAN_REVIEW_FAILED), status colors,
  job-card/jobs-column filters, idea-list status tabs
- Phase 4: review-plan-job.md prompt (multi-model orchestration with codex
  injection + active plan revision via update_idea_plan_md after each round),
  runbook, 13 unit tests
- Phase 5: ReviewLogViewer component (rounds, convergence, approval, issues),
  idea-detail integration, proper ReviewLog TypeScript types exported from component
- Phase 6.1: wait-for-job discriminator wired (IDEA_REVIEW_PLAN), plan-revision
  step made mandatory in prompt (was previously optional/missing)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 03:35:02 +02:00

140 lines
4.3 KiB
TypeScript

import { cookies } from 'next/headers'
import { notFound } from 'next/navigation'
import { getIronSession } from 'iron-session'
import { SessionData, sessionOptions } from '@/lib/session'
import { prisma } from '@/lib/prisma'
import { productAccessFilter } from '@/lib/product-access'
import { ideaToDto } from '@/lib/idea-dto'
import { IdeaDetailLayout } from '@/components/ideas/idea-detail-layout'
import { loadIdeaSyncData } from './sync-tab-server'
import type { ReviewLog } from '@/components/ideas/review-log-viewer'
export const dynamic = 'force-dynamic'
interface PageProps {
params: Promise<{ id: string }>
searchParams: Promise<{ tab?: string }>
}
export default async function IdeaDetailPage({ params, searchParams }: PageProps) {
const session = await getIronSession<SessionData>(await cookies(), sessionOptions)
if (!session.userId) notFound() // proxy.ts redirect zou ons al moeten hebben
const { id } = await params
const { tab } = await searchParams
// M12: strikt user_id-only — 404 (niet 403) voor andere users (anti-enum).
const idea = await prisma.idea.findFirst({
where: { id, user_id: session.userId },
select: {
id: true,
user_id: true,
product_id: true,
code: true,
title: true,
description: true,
status: true,
pbi_id: true,
archived: true,
grill_md: true,
plan_md: true,
plan_review_log: true,
reviewed_at: true,
created_at: true,
updated_at: true,
product: { select: { id: true, name: true, repo_url: true } },
pbi: { select: { id: true, code: true, title: true } },
secondary_products: { select: { id: true, product_id: true, product: { select: { id: true, name: true } } } },
},
})
if (!idea) notFound()
// Producten voor de "koppel product"-dropdown in de form-tab.
const products = await prisma.product.findMany({
where: { ...productAccessFilter(session.userId), archived: false },
orderBy: { name: 'asc' },
select: { id: true, name: true, repo_url: true },
})
// Recent logs (laatste 100) voor de Timeline-tab.
const logs = await prisma.ideaLog.findMany({
where: { idea_id: id },
orderBy: { created_at: 'desc' },
take: 100,
select: {
id: true,
type: true,
content: true,
metadata: true,
created_at: true,
},
})
// Open vragen voor dit idee — voor de Timeline-tab.
const questions = await prisma.claudeQuestion.findMany({
where: { idea_id: id },
orderBy: { created_at: 'desc' },
take: 50,
select: {
id: true,
question: true,
options: true,
status: true,
answer: true,
created_at: true,
expires_at: true,
},
})
const userQuestionsRaw = await prisma.userQuestion.findMany({
where: { idea_id: id },
orderBy: { created_at: 'asc' },
take: 100,
select: { id: true, question: true, answer: true, status: true, created_at: true },
})
// Sync-tab data — alleen geladen als idea PLANNED is en pbi_id gevuld.
// loadIdeaSyncData past zelf user_id-scope toe en retourneert null als
// het idee geen pbi heeft.
const syncData =
idea.status === 'PLANNED' && idea.pbi_id
? await loadIdeaSyncData(id, session.userId)
: null
return (
<IdeaDetailLayout
idea={ideaToDto(idea)}
grill_md={idea.grill_md}
plan_md={idea.plan_md}
plan_review_log={(idea.plan_review_log as ReviewLog | null) ?? null}
products={products}
logs={logs.map((l) => ({
id: l.id,
type: l.type,
content: l.content,
metadata: l.metadata,
created_at: l.created_at.toISOString(),
}))}
questions={questions.map((q) => ({
id: q.id,
question: q.question,
options: Array.isArray(q.options) ? (q.options as string[]) : null,
status: q.status as 'open' | 'answered' | 'cancelled' | 'expired',
answer: q.answer ?? null,
created_at: q.created_at.toISOString(),
expires_at: q.expires_at.toISOString(),
}))}
userQuestions={userQuestionsRaw.map((uq) => ({
id: uq.id,
question: uq.question,
answer: uq.answer,
status: uq.status as 'pending' | 'answered',
created_at: uq.created_at.toISOString(),
}))}
isDemo={session.isDemo ?? false}
initialTab={tab ?? 'idee'}
syncData={syncData}
/>
)
}