feat(PBI-67): model + mode-selectie per ClaudeJob-kind (#169)
* feat(PBI-67/ST-1297): datamodel-velden voor job-model-selectie
Voegt 8 nieuwe optionele velden toe verspreid over Product, Task en
ClaudeJob ten dienste van de override-cascade:
task.requires_opus → job.requested_* → product.preferred_* → kind-default
Bestaande rijen krijgen NULL (Product/ClaudeJob) of false (Task) en
vallen daarmee terug op de kind-defaults uit de resolver (ST-1298).
Migration is additief: alleen ALTER TABLE ADD COLUMN, geen RENAME of
DROP. Bestaande factories en seed-script blijven werken zonder
aanpassing omdat alle nieuwe velden default-waardes hebben.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(PBI-67/ST-1299): job-config snapshot bij enqueue + worker-flag-runbook
T-789: Snapshot van resolved JobConfig in ClaudeJob.requested_*
bij elke job-creatie. Helper in lib/job-config-snapshot.ts laadt
product (preferred_*) en task (requires_opus) en draait de resolver
uit lib/job-config.ts (mirror van scrum4me-mcp/src/lib/job-config.ts —
zelfde matrix, sync-comment in bestand). Toegepast op alle 5
enqueue-locaties:
- actions/user-questions.ts (PLAN_CHAT)
- actions/sprint-runs.ts × 3 (SPRINT_IMPLEMENTATION x2,
TASK_IMPLEMENTATION loop)
- actions/ideas.ts (IDEA_GRILL / IDEA_MAKE_PLAN)
Test-mocks uitgebreid met product.findUnique en task.findUnique zodat
de helper bij unit tests veilig terugvalt op kind-defaults (alle 563
tests groen).
T-790: Sectie 'Config doorgeven aan Claude Code' toegevoegd aan
docs/runbooks/worker-idempotency.md met CLI-flag-mapping en de
verwachte aanroep per kind. Forward-link naar
docs/runbooks/job-model-selection.md (volgt in T-794).
Plus: docs/plans/job-model-selection.md (de approved plan-doc).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(PBI-67/ST-1300): cost-attribution voor thinking-tokens + admin UI
T-792: token-stats + token-history rekenen actual_thinking_tokens nu
mee in de totale kosten (tegen input-rate, conform Anthropic billing).
COALESCE-veilig zodat oude rijen 0 bijdragen i.p.v. NaN. Nieuwe export
`getTokenStatsByKind` aggregeert tokens en kosten per ClaudeJob.kind
zodat we relatieve uitgaven van IDEA_GRILL/IDEA_MAKE_PLAN/PLAN_CHAT/
TASK_IMPLEMENTATION/SPRINT_IMPLEMENTATION kunnen zien.
T-793: admin/jobs Kosten-tabel toont:
- Nieuwe kolom 'Thinking' (aantal verbruikte thinking-tokens)
- Mismatch-marker (rood) als requested_model afwijkt van actuele
model_id — duidt op een worker die de CLI-flag niet doorgaf.
Tooltip toont aangevraagd model. Geen Sentry/log-noise.
Page-level cost-berekening volgt dezelfde formule (input_price ×
thinking_tokens). 563 tests groen.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(PBI-67/ST-1301): runbook + CLAUDE.md updates voor model/mode-selectie
T-794: Nieuwe runbook docs/runbooks/job-model-selection.md met
override-cascade, kind-default-matrix, override-voorbeelden,
auditspoor en cost-attribution-formule. 107 regels.
T-795: CLAUDE.md hardstop-bullet voor 'Model/mode per ClaudeJob'
(verwijst naar nieuwe runbook) + patterns-quickref-rij voor
job-config resolver. CLAUDE.md blijft 139 regels (≤ 150).
T-796: docs:check-links groen — 108 files, geen broken links. Twee
externe-repo verwijzingen (scrum4me-mcp/...) ge-de-linked tot plain
text omdat de check-links script de zustertree niet traverseert; de
referenties blijven leesbaar.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f233dd815e
commit
8c63ba377d
18 changed files with 648 additions and 9 deletions
|
|
@ -13,6 +13,7 @@ import { getIronSession } from 'iron-session'
|
|||
import { z } from 'zod'
|
||||
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { getJobConfigSnapshot } from '@/lib/job-config-snapshot'
|
||||
import { SessionData, sessionOptions } from '@/lib/session'
|
||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||
import { ideaCreateSchema, ideaUpdateSchema } from '@/lib/schemas/idea'
|
||||
|
|
@ -413,6 +414,8 @@ async function startIdeaJob(
|
|||
}
|
||||
}
|
||||
|
||||
const ideaSnapshot = await getJobConfigSnapshot({ kind, productId: idea.product_id! })
|
||||
|
||||
// Atomic: create job + flip idea-status + log.
|
||||
const job = await prisma.$transaction(async (tx) => {
|
||||
const j = await tx.claudeJob.create({
|
||||
|
|
@ -422,6 +425,7 @@ async function startIdeaJob(
|
|||
idea_id: id,
|
||||
kind,
|
||||
status: 'QUEUED',
|
||||
...ideaSnapshot,
|
||||
},
|
||||
select: { id: true },
|
||||
})
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Prisma } from '@prisma/client'
|
|||
import { prisma } from '@/lib/prisma'
|
||||
import { SessionData, sessionOptions } from '@/lib/session'
|
||||
import { parsePauseContext } from '@/lib/pause-context'
|
||||
import { getJobConfigSnapshot } from '@/lib/job-config-snapshot'
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
|
|
@ -176,6 +177,10 @@ async function startSprintRunCore(
|
|||
// server-side bij claim aangemaakt zodat order/base_sha consistent zijn
|
||||
// met de worktree-state op claim-tijd.
|
||||
if (sprint.product.pr_strategy === 'SPRINT_BATCH') {
|
||||
const sprintSnapshot = await getJobConfigSnapshot({
|
||||
kind: 'SPRINT_IMPLEMENTATION',
|
||||
productId: sprint.product_id,
|
||||
})
|
||||
await tx.claudeJob.create({
|
||||
data: {
|
||||
user_id,
|
||||
|
|
@ -185,13 +190,20 @@ async function startSprintRunCore(
|
|||
sprint_run_id: sprintRun.id,
|
||||
kind: 'SPRINT_IMPLEMENTATION',
|
||||
status: 'QUEUED',
|
||||
...sprintSnapshot,
|
||||
},
|
||||
})
|
||||
return { ok: true, sprint_run_id: sprintRun.id, jobs_count: 1 }
|
||||
}
|
||||
|
||||
// STORY / SPRINT (per-task): bestaand pad.
|
||||
// STORY / SPRINT (per-task): bestaand pad. Snapshot per task zodat
|
||||
// task.requires_opus de cascade kan overrulen.
|
||||
for (const t of orderedTasks) {
|
||||
const taskSnapshot = await getJobConfigSnapshot({
|
||||
kind: 'TASK_IMPLEMENTATION',
|
||||
productId: sprint.product_id,
|
||||
taskId: t.id,
|
||||
})
|
||||
await tx.claudeJob.create({
|
||||
data: {
|
||||
user_id,
|
||||
|
|
@ -200,6 +212,7 @@ async function startSprintRunCore(
|
|||
sprint_run_id: sprintRun.id,
|
||||
kind: 'TASK_IMPLEMENTATION',
|
||||
status: 'QUEUED',
|
||||
...taskSnapshot,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -360,6 +373,10 @@ export async function resumePausedSprintRunAction(
|
|||
started_at: new Date(),
|
||||
},
|
||||
})
|
||||
const resumeSnapshot = await getJobConfigSnapshot({
|
||||
kind: 'SPRINT_IMPLEMENTATION',
|
||||
productId: sprintJob.product_id,
|
||||
})
|
||||
await tx.claudeJob.create({
|
||||
data: {
|
||||
user_id: userId,
|
||||
|
|
@ -369,6 +386,7 @@ export async function resumePausedSprintRunAction(
|
|||
sprint_run_id: newRun.id,
|
||||
kind: 'SPRINT_IMPLEMENTATION',
|
||||
status: 'QUEUED',
|
||||
...resumeSnapshot,
|
||||
},
|
||||
})
|
||||
await tx.sprintRun.update({
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { prisma } from '@/lib/prisma'
|
|||
import { SessionData, sessionOptions } from '@/lib/session'
|
||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||
import { ACTIVE_JOB_STATUSES } from '@/lib/job-status'
|
||||
import { getJobConfigSnapshot } from '@/lib/job-config-snapshot'
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
|
|
@ -56,6 +57,8 @@ export async function createUserQuestionAction(
|
|||
})
|
||||
if (existing) return { error: 'Er loopt al een actieve PLAN_CHAT voor dit idee', code: 409 }
|
||||
|
||||
const snapshot = await getJobConfigSnapshot({ kind: 'PLAN_CHAT', productId: idea.product_id })
|
||||
|
||||
const [uq, job] = await prisma.$transaction([
|
||||
prisma.userQuestion.create({
|
||||
data: {
|
||||
|
|
@ -71,6 +74,7 @@ export async function createUserQuestionAction(
|
|||
idea_id: parsed.data.ideaId,
|
||||
kind: 'PLAN_CHAT',
|
||||
status: 'QUEUED',
|
||||
...snapshot,
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue