Enhance Planning AI with Roadmap-First Architecture and New Features
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Failing after 43s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / k6 /health Baseline (push) Successful in 44s
Test Suite / playwright-tests (push) Successful in 1m15s

- Introduced a roadmap-first approach for the planning AI, allowing for a structured progression graph that aligns with the overall project roadmap.
- Added new functionality to strip off-topic steps from exercise paths, improving the relevance of generated exercise suggestions.
- Implemented a detailed goal text generation for AI proposals, enhancing the context provided for new exercises.
- Updated the ExerciseProgressionPathBuilder component to support new features, including roadmap previews and improved focus area handling.
- Incremented application version to 0.8.205 and updated database schema version to 20260606086 to reflect these changes.
This commit is contained in:
Lars committed 2026-06-08 08:10:53 +02:00
1 parent a9a6153ed5
commit dd0fae4bf5
20 files changed
+1491 -94

No files matched your search

@@ -60,6 +60,16 @@ const OFFER_SOURCE_LABELS = {
llm_suggested: 'QS-Empfehlung',
}
function resolveDefaultFocusAreaId(targetSummary, focusAreas) {
const targetName = targetSummary?.focus_areas?.[0]
if (targetName && Array.isArray(focusAreas) && focusAreas.length) {
const norm = String(targetName).trim().toLowerCase()
const hit = focusAreas.find((fa) => String(fa.name || '').trim().toLowerCase() === norm)
if (hit?.id) return Number(hit.id)
}
return focusAreas?.[0]?.id ? Number(focusAreas[0].id) : null
}
export default function ExerciseProgressionPathBuilder({
graphId,
disabled = false,
@@ -76,7 +86,10 @@ export default function ExerciseProgressionPathBuilder({
const [pathQa, setPathQa] = useState(null)
const [pathSteps, setPathSteps] = useState([])
const [gapFillOffers, setGapFillOffers] = useState([])
const [progressionRoadmap, setProgressionRoadmap] = useState(null)
const [focusAreas, setFocusAreas] = useState([])
const [skillsCatalog, setSkillsCatalog] = useState([])
const [generatingOfferId, setGeneratingOfferId] = useState(null)
const [quickCreateOpen, setQuickCreateOpen] = useState(false)
const [activeOffer, setActiveOffer] = useState(null)
@@ -89,13 +102,20 @@ export default function ExerciseProgressionPathBuilder({
useEffect(() => {
let cancelled = false
api
.listFocusAreas({ status: 'active' })
.then((rows) => {
if (!cancelled) setFocusAreas(Array.isArray(rows) ? rows : [])
Promise.all([
api.listFocusAreas({ status: 'active' }),
api.listSkillsCatalog({ status: 'active' }),
])
.then(([fa, sk]) => {
if (cancelled) return
setFocusAreas(Array.isArray(fa) ? fa : [])
setSkillsCatalog(Array.isArray(sk) ? sk : [])
})
.catch(() => {
if (!cancelled) setFocusAreas([])
if (!cancelled) {
setFocusAreas([])
setSkillsCatalog([])
}
})
return () => {
cancelled = true
@@ -128,25 +148,41 @@ export default function ExerciseProgressionPathBuilder({
return rows.map((row, idx) => ({ ...row, isOffTopic: indices.has(idx) }))
}
const insertExerciseFromOffer = useCallback((created, offer) => {
const row = mapCreatedExerciseToRow(created, offer)
setPathSteps((prev) => {
let next = [...prev]
const afterIdx = Number(offer?.insert_after_index)
const replaceIdx =
offer?.replace_step_index != null ? Number(offer.replace_step_index) : null
if (Number.isFinite(replaceIdx) && replaceIdx >= 0 && replaceIdx < next.length) {
next.splice(replaceIdx, 1, row)
} else if (Number.isFinite(afterIdx) && afterIdx >= 0 && afterIdx < next.length) {
next.splice(afterIdx + 1, 0, row)
} else {
next.push(row)
const trimPathToMaxSteps = useCallback((rows, limit) => {
let next = [...rows]
while (next.length > limit) {
const offIdx = next.findIndex((s) => s.isOffTopic)
if (offIdx >= 0) {
next.splice(offIdx, 1)
continue
}
return applyOffTopicFlags(next, pathQa)
})
setGapFillOffers((prev) => prev.filter((o) => o.offer_id !== offer?.offer_id))
}, [pathQa])
next.pop()
}
return next.map((r) => ({ ...r, isOffTopic: false }))
}, [])
const insertExerciseFromOffer = useCallback(
(created, offer) => {
const row = mapCreatedExerciseToRow(created, offer)
setPathSteps((prev) => {
let next = [...prev]
const afterIdx = Number(offer?.insert_after_index)
const replaceIdx =
offer?.replace_step_index != null ? Number(offer.replace_step_index) : null
if (Number.isFinite(replaceIdx) && replaceIdx >= 0 && replaceIdx < next.length) {
next.splice(replaceIdx, 1, row)
} else if (Number.isFinite(afterIdx) && afterIdx >= 0 && afterIdx < next.length) {
next.splice(afterIdx + 1, 0, row)
} else {
next.push(row)
}
return trimPathToMaxSteps(next, maxSteps)
})
setGapFillOffers((prev) => prev.filter((o) => o.offer_id !== offer?.offer_id))
},
[maxSteps, trimPathToMaxSteps],
)
const closeQuickCreate = () => {
if (quickSaving) return
@@ -156,33 +192,68 @@ export default function ExerciseProgressionPathBuilder({
setQuickAiError('')
}
const openOfferQuickCreate = (offer) => {
setActiveOffer(offer)
setQuickTitle((offer?.title_hint || '').trim())
setQuickSketch((offer?.sketch || '').trim())
setQuickFocusAreaId('')
setQuickCreateDraft(null)
setQuickAiError('')
if (offer?.has_ai_payload && offer?.ai_suggestion) {
const preview = buildQuickCreateAiPreview(offer.ai_suggestion, {
sketchPlain: (offer?.sketch || '').trim(),
})
if (preview.hasSummaryProposal || preview.hasSkillChoices || preview.hasInstructionChoices) {
const focusId = focusAreas[0]?.id ? String(focusAreas[0].id) : ''
setQuickFocusAreaId(focusId)
setQuickCreateDraft(
aiPreviewToQuickCreateDraft(preview, {
title: (offer?.title_hint || '').trim(),
focusAreaId: focusId ? Number(focusId) : '',
sketchPlain: (offer?.sketch || '').trim(),
}),
)
setQuickCreateOpen(false)
return
}
const runGapFillAiSuggest = async (offer) => {
const title = (offer?.title_hint || '').trim()
if (title.length < 3) {
alert('Titel-Hinweis fehlt — bitte Pfad erneut vorschlagen.')
return
}
const goalText = (offer?.goal_for_ai || offer?.sketch || '').trim()
const focusId = resolveDefaultFocusAreaId(targetSummary, focusAreas)
if (!focusId) {
alert('Kein Fokusbereich verfügbar — bitte Kataloge laden oder manuell wählen.')
setQuickTitle(title)
setQuickSketch(goalText)
setQuickFocusAreaId('')
setActiveOffer(offer)
setQuickCreateOpen(true)
return
}
const focusRow = (focusAreas || []).find((x) => Number(x.id) === focusId)
const focusHint = (focusRow?.name || offer?.primary_topic || '').trim()
setActiveOffer(offer)
setQuickTitle(title)
setQuickSketch(goalText)
setQuickFocusAreaId(String(focusId))
setQuickAiError('')
setQuickCreateDraft(null)
setQuickSaving(true)
setGeneratingOfferId(offer?.offer_id || null)
try {
const aiRes = await api.suggestExerciseAi({
title,
goal: goalText || undefined,
execution: '',
preparation: '',
trainer_notes: '',
focus_area_hint: focusHint || undefined,
focus_areas_context: [{ focus_area_id: focusId, is_primary: true }],
include_summary: true,
include_skills: true,
include_instructions: true,
})
const preview = buildQuickCreateAiPreview(aiRes, { sketchPlain: goalText })
if (!preview.hasSummaryProposal && !preview.hasInstructionChoices && !preview.hasSkillChoices) {
throw new Error('Die KI lieferte keinen verwertbaren Vorschlag.')
}
setQuickCreateDraft(
aiPreviewToQuickCreateDraft(preview, {
title,
focusAreaId: focusId,
sketchPlain: goalText,
}),
)
setQuickCreateOpen(false)
} catch (e) {
console.error(e)
const msg = e?.message || String(e)
setQuickAiError(msg)
setQuickCreateOpen(true)
} finally {
setQuickSaving(false)
setGeneratingOfferId(null)
}
setQuickCreateOpen(true)
}
const runQuickCreateAiSuggest = async () => {
@@ -276,13 +347,16 @@ export default function ExerciseProgressionPathBuilder({
include_llm_path_qa: true,
include_path_reorder: true,
include_ai_gap_fill: true,
include_roadmap_preview: true,
include_llm_roadmap: true,
progression_graph_id: Number(graphId),
})
const qa = res?.path_qa || null
const rows = applyOffTopicFlags(
(Array.isArray(res?.steps) ? res.steps : []).map(mapApiStepToRow),
qa,
)
const rawRows = (Array.isArray(res?.steps) ? res.steps : []).map(mapApiStepToRow)
const rows =
Array.isArray(qa?.stripped_off_topic_steps) && qa.stripped_off_topic_steps.length > 0
? rawRows
: applyOffTopicFlags(rawRows, qa)
if (rows.length < 2) {
throw new Error('Zu wenig Schritte im Vorschlag.')
}
@@ -297,6 +371,7 @@ export default function ExerciseProgressionPathBuilder({
? qa.gap_fill_offers
: [],
)
setProgressionRoadmap(res?.progression_roadmap || null)
if (!segmentNotes.trim() && q) setSegmentNotes(q.slice(0, 400))
} catch (e) {
console.error(e)
@@ -306,6 +381,7 @@ export default function ExerciseProgressionPathBuilder({
setSemanticBrief(null)
setPathQa(null)
setGapFillOffers([])
setProgressionRoadmap(null)
} finally {
setLoading(false)
}
@@ -349,6 +425,7 @@ export default function ExerciseProgressionPathBuilder({
setSemanticBrief(null)
setPathQa(null)
setGapFillOffers([])
setProgressionRoadmap(null)
if (typeof onSaved === 'function') await onSaved()
const msg =
skippedAi > 0
@@ -437,6 +514,38 @@ export default function ExerciseProgressionPathBuilder({
</div>
) : null}
{progressionRoadmap?.roadmap?.major_steps?.length > 0 ? (
<div
style={{
marginTop: '12px',
padding: '12px',
borderRadius: '8px',
border: '1px solid color-mix(in srgb, var(--accent) 45%, var(--border))',
background: 'color-mix(in srgb, var(--accent) 6%, var(--surface))',
}}
>
<strong style={{ fontSize: '13px' }}>Didaktische Roadmap (Phase F)</strong>
<p style={{ fontSize: '12px', color: 'var(--text3)', margin: '6px 0 10px', lineHeight: 1.45 }}>
Ziel-zuerst-Planung: {progressionRoadmap.micro_objective_count ?? '?'} Zwischenziele →{' '}
{progressionRoadmap.major_step_count ?? progressionRoadmap.roadmap.major_steps.length} Major Steps.
{progressionRoadmap.llm_roadmap_applied
? ' (KI-Prompts aus Admin-Konfiguration)'
: ' (heuristischer Fallback — KI-Prompts in ai_prompts)'}
. Übungen unten: Bibliothekssuche (Übergangsphase).
</p>
<ol style={{ margin: 0, paddingLeft: '18px', fontSize: '13px', lineHeight: 1.5 }}>
{progressionRoadmap.roadmap.major_steps.map((step) => (
<li key={step.index} style={{ marginBottom: '6px' }}>
<span className="exercise-tag" style={{ marginRight: '6px' }}>
{step.phase}
</span>
{step.learning_goal}
</li>
))}
</ol>
</div>
) : null}
{pathQa && pathSteps.length > 0 ? (
<div
style={{
@@ -467,7 +576,12 @@ export default function ExerciseProgressionPathBuilder({
{pathQa.bridge_insert_count} Brücken-Übung(en) aus der Bibliothek eingefügt.
</p>
) : null}
{Number(pathQa.off_topic_count) > 0 ? (
{Array.isArray(pathQa.stripped_off_topic_steps) && pathQa.stripped_off_topic_steps.length > 0 ? (
<p style={{ margin: '6px 0 0', color: 'var(--accent-dark)' }}>
{pathQa.stripped_off_topic_steps.length} themenfremde(r) Schritt(e) aus dem Pfad entfernt:{' '}
{pathQa.stripped_off_topic_steps.map((s) => s.removed_title || s.title).join(', ')}.
</p>
) : Number(pathQa.off_topic_count) > 0 ? (
<p style={{ margin: '6px 0 0', color: 'var(--danger)' }}>
{pathQa.off_topic_count} Schritt(e) ohne Bezug zum Pfad-Thema — siehe Lücken-Angebote unten.
</p>
@@ -495,7 +609,8 @@ export default function ExerciseProgressionPathBuilder({
>
<strong style={{ fontSize: '13px' }}>Fehlende Schritte — mit KI anlegen</strong>
<p style={{ fontSize: '12px', color: 'var(--text3)', margin: '6px 0 10px', lineHeight: 1.45 }}>
Die QS hat Lücken erkannt. Vorschlag prüfen, als Übung anlegen und in den Pfad einfügen.
Die QS hat fehlende Zwischenschritte erkannt — sie sind noch nicht im Pfad ({pathSteps.length}/{maxSteps} Schritte).
„Mit KI anlegen“ startet einen vollständigen KI-Entwurf (Ziel, Anleitung, Fähigkeiten) und fügt die Übung ein.
</p>
<div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}>
{gapFillOffers.map((offer) => (
@@ -529,10 +644,17 @@ export default function ExerciseProgressionPathBuilder({
type="button"
className="btn btn-primary"
style={{ fontSize: '12px', flexShrink: 0 }}
disabled={quickSaving}
onClick={() => openOfferQuickCreate(offer)}
disabled={quickSaving || pathSteps.length >= maxSteps}
onClick={() => runGapFillAiSuggest(offer)}
title={
pathSteps.length >= maxSteps
? `Pfad hat bereits ${maxSteps} Schritte — zuerst einen Schritt entfernen.`
: 'KI-Entwurf mit Pfad-Kontext generieren'
}
>
Mit KI anlegen
{generatingOfferId === offer.offer_id
? 'KI erstellt Entwurf …'
: 'Mit KI anlegen'}
</button>
</div>
</div>
@@ -662,6 +784,7 @@ export default function ExerciseProgressionPathBuilder({
setSemanticBrief(null)
setPathQa(null)
setGapFillOffers([])
setProgressionRoadmap(null)
}}
>
Vorschlag verwerfen
@@ -696,7 +819,7 @@ export default function ExerciseProgressionPathBuilder({
}}
onApply={applyQuickCreateDraft}
focusAreas={focusAreas}
skillsCatalog={[]}
skillsCatalog={skillsCatalog}
dialogTitle="Pfad-Lücke — KI-Entwurf bearbeiten"
hint="Texte anpassen, dann als Übung speichern und in den Pfad einfügen."
applyLabel={quickSaving ? 'Wird angelegt …' : 'Anlegen und in Pfad einfügen'}