feat(schedule): einheitliche Rhythmus-Schicht an Gate und Arbeitspaket
Deploy Development / deploy (push) Successful in 49s
Test Suite / pytest-backend (push) Successful in 4m57s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s

Bestehende Recurring-Pfade bleiben kompatibel (interval_days-Fallback, Migration backfillt schedules), damit der aktuelle Betrieb nicht bricht und der Stand auf einem zweiten Rechner weitergebaut werden kann.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-08-14 09:23:00 +02:00
1 parent 87ecee5301
commit ea0aa18b8d
21 files changed
+1608 -59

No files matched your search

+11
View File
@@ -27,6 +27,17 @@ export function unplanActionToBacklog(id, { carryover = false } = {}) {
return apiFetch(`/api/actions/${id}/unplan-to-backlog${query}`, { method: 'POST' })
}
export function upsertActionSchedule(id, schedule) {
return apiFetch(`/api/actions/${id}/schedule`, {
method: 'PUT',
body: JSON.stringify(schedule),
})
}
export function clearActionSchedule(id) {
return apiFetch(`/api/actions/${id}/schedule`, { method: 'DELETE' })
}
export function listMyOpenActions() {
return apiFetch('/api/actions/me/open')
}
@@ -0,0 +1,148 @@
import { useEffect, useState } from 'react'
import { clearActionSchedule, getAction, upsertActionSchedule } from '../api/actions.js'
import { ScheduleEditor } from './ScheduleEditor.jsx'
import {
buildSchedulePayload,
defaultScheduleValue,
formatScheduleLabel,
scheduleFromApi,
} from '../utils/scheduleUtils.js'
export function ActionScheduleSection({
action,
canManage = false,
onUpdated,
}) {
const [enabled, setEnabled] = useState(Boolean(action?.schedule))
const [schedule, setSchedule] = useState(defaultScheduleValue())
const [busy, setBusy] = useState(false)
const [error, setError] = useState(null)
const [editing, setEditing] = useState(false)
const [loadedSchedule, setLoadedSchedule] = useState(null)
useEffect(() => {
let cancelled = false
getAction(action.id)
.then((full) => {
if (cancelled) return
setLoadedSchedule(full.schedule || null)
setEnabled(Boolean(full.schedule))
setSchedule(scheduleFromApi(full.schedule))
})
.catch(() => {})
return () => {
cancelled = true
}
}, [action.id, action.updated_at])
const displaySchedule = loadedSchedule ?? action?.schedule
async function run(fn) {
setBusy(true)
setError(null)
try {
await fn()
if (onUpdated) await onUpdated()
} catch (err) {
setError(err.message)
} finally {
setBusy(false)
}
}
async function handleEnable(checked) {
if (!checked) {
if (!displaySchedule) {
setEnabled(false)
return
}
if (!window.confirm('Wiederholung am Arbeitspaket entfernen?')) return
await run(() => clearActionSchedule(action.id))
setEnabled(false)
return
}
setEnabled(true)
setEditing(true)
}
async function handleSave() {
let payload
try {
payload = buildSchedulePayload(schedule)
} catch (err) {
setError(err.message)
return
}
await run(() => upsertActionSchedule(action.id, payload))
setEditing(false)
}
return (
<section className="card action-schedule-section">
<div className="section-header">
<div>
<h3>Wiederholung</h3>
<p className="section-lead muted">
Regelmäßige Ausführung dieses Arbeitspakets — gleicher Rhythmus wie bei Gate-Übungen.
</p>
</div>
{canManage && (
<label className="toggle-inline">
<input
type="checkbox"
checked={enabled}
disabled={busy}
onChange={(e) => handleEnable(e.target.checked)}
/>
Rhythmus aktiv
</label>
)}
</div>
{error && <p className="error">{error}</p>}
{!enabled && !displaySchedule && (
<p className="muted">Keine Wiederholung — eignet sich z. B. für monatliches Reporting.</p>
)}
{(enabled || displaySchedule) && !editing && (
<p className="action-schedule-section__summary">
<strong>{formatScheduleLabel(displaySchedule || schedule)}</strong>
{canManage && (
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => setEditing(true)}
>
Bearbeiten
</button>
)}
</p>
)}
{editing && canManage && (
<div className="action-schedule-section__edit">
<ScheduleEditor value={schedule} onChange={setSchedule} disabled={busy} />
<div className="action-controls">
<button type="button" className="btn btn-primary btn-sm" disabled={busy} onClick={handleSave}>
Speichern
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => {
setEditing(false)
setSchedule(scheduleFromApi(displaySchedule))
setEnabled(Boolean(displaySchedule))
}}
>
Abbrechen
</button>
</div>
</div>
)}
</section>
)
}
@@ -1,14 +1,17 @@
import { useCallback, useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import {
createGatePractice,
listGatePractices,
} from '../api/roadmap.js'
import { createGatePractice, listGatePractices } from '../api/roadmap.js'
import { deleteRecurring, updateRecurring } from '../api/recurring.js'
import { RECURRING_STATUSES, RECURRING_STATUS_LABELS } from '../constants/status.js'
import { EmptyState } from './EmptyState.jsx'
import { ScheduleEditor, scheduleEditorFromPractice } from './ScheduleEditor.jsx'
import { StatusBadge } from './StatusBadge.jsx'
import { scopedPath } from '../utils/routes.js'
import {
buildSchedulePayload,
defaultScheduleValue,
formatScheduleLabel,
} from '../utils/scheduleUtils.js'
function formatDueAt(iso) {
if (!iso) return null
@@ -23,6 +26,7 @@ export function GateActivitySetSection({
gateId,
initiativeId,
gateStatus,
gateTitle,
canManage = false,
}) {
const [practices, setPractices] = useState([])
@@ -32,7 +36,9 @@ export function GateActivitySetSection({
const [showForm, setShowForm] = useState(false)
const [title, setTitle] = useState('')
const [description, setDescription] = useState('')
const [intervalDays, setIntervalDays] = useState('1')
const [schedule, setSchedule] = useState(defaultScheduleValue())
const [editingRhythmId, setEditingRhythmId] = useState(null)
const [editSchedule, setEditSchedule] = useState(defaultScheduleValue())
const load = useCallback(async () => {
setLoading(true)
@@ -67,34 +73,51 @@ export function GateActivitySetSection({
async function handleCreate(e) {
e.preventDefault()
if (!title.trim()) return
const interval = Number.parseInt(intervalDays, 10)
if (!Number.isFinite(interval) || interval < 1) {
setError('Intervall muss mindestens 1 Tag sein.')
let payload
try {
payload = buildSchedulePayload(schedule)
} catch (err) {
setError(err.message)
return
}
await runAction(async () => {
await createGatePractice(gateId, {
title: title.trim(),
description: description.trim(),
interval_days: interval,
status: 'active',
schedule: payload,
})
setTitle('')
setDescription('')
setIntervalDays('1')
setSchedule(defaultScheduleValue())
setShowForm(false)
})
}
async function saveRhythm(practice) {
let payload
try {
payload = buildSchedulePayload(editSchedule)
} catch (err) {
setError(err.message)
return
}
await runAction(async () => {
await updateRecurring(practice.id, { schedule: payload })
setEditingRhythmId(null)
})
}
const isActiveGate = gateStatus === 'active' || gateStatus === 'at_risk'
const routineLabel = gateTitle ? `Routine: ${gateTitle}` : 'Routine an diesem Gate'
return (
<section className="card gate-activity-set">
<div className="section-header">
<div>
<h3>Übungen (Activity Set)</h3>
<h3>{routineLabel}</h3>
<p className="section-lead muted">
Wiederkehrende Routinen an diesem Zielzustand — erscheinen in Today, wenn das Gate{' '}
Übungen gehören zu diesem Zielzustand — sie erscheinen in Today, wenn das Gate{' '}
<strong>aktiv</strong> ist.
</p>
</div>
@@ -115,7 +138,7 @@ export function GateActivitySetSection({
{!isActiveGate && (
<p className="muted gate-activity-set__hint">
Gate-Status ist <strong>{gateStatus}</strong> — Übungen werden in Today sichtbar, sobald
das Gate auf <strong>aktiv</strong> steht (Stammdaten bearbeiten).
das Gate auf <strong>aktiv</strong> steht.
</p>
)}
@@ -124,7 +147,7 @@ export function GateActivitySetSection({
<Link to={scopedPath('/work/today', { initiativeId })} className="link-inline">
Ausführen → Today
</Link>{' '}
— fällige Übungen dieses Gates abhaken.
— fällige Übungen dieser Routine abhaken.
</p>
)}
@@ -149,16 +172,7 @@ export function GateActivitySetSection({
placeholder="Hinweise zur Ausführung"
/>
</label>
<label>
Rhythmus (Tage)
<input
type="number"
min={1}
value={intervalDays}
onChange={(e) => setIntervalDays(e.target.value)}
required
/>
</label>
<ScheduleEditor value={schedule} onChange={setSchedule} disabled={busy} />
<button type="submit" className="btn btn-primary" disabled={busy}>
Übung speichern
</button>
@@ -168,7 +182,7 @@ export function GateActivitySetSection({
{loading ? (
<p className="muted">Übungen werden geladen…</p>
) : practices.length === 0 ? (
<EmptyState message="Noch keine Übungen an diesem Gate — mindestens eine für aktive Gates anlegen." />
<EmptyState message="Noch keine Übungen — mindestens eine Übung für diese Routine anlegen." />
) : (
<ul className="item-list gate-activity-set__list">
{practices.map((practice) => (
@@ -179,14 +193,40 @@ export function GateActivitySetSection({
<p className="muted list-item-sub">{practice.description}</p>
)}
<p className="muted list-item-sub">
{practice.interval_days
? `Alle ${practice.interval_days} Tag(e)`
: 'Kein Intervall'}
{formatScheduleLabel(practice.schedule || practice)}
{practice.open_cadence_instance?.due_at
? ` · Fällig: ${formatDueAt(practice.open_cadence_instance.due_at)}`
: ''}
{practice.today_completed ? ' · heute erledigt' : ''}
</p>
{editingRhythmId === practice.id && (
<div className="gate-activity-set__rhythm-edit">
<ScheduleEditor
value={editSchedule}
onChange={setEditSchedule}
disabled={busy}
compact
/>
<div className="action-controls">
<button
type="button"
className="btn btn-primary btn-sm"
disabled={busy}
onClick={() => saveRhythm(practice)}
>
Rhythmus speichern
</button>
<button
type="button"
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => setEditingRhythmId(null)}
>
Abbrechen
</button>
</div>
</div>
)}
</div>
{canManage && (
<div className="list-item-meta action-controls">
@@ -213,17 +253,8 @@ export function GateActivitySetSection({
className="btn btn-secondary btn-sm"
disabled={busy}
onClick={() => {
const next = window.prompt(
'Neues Intervall in Tagen:',
String(practice.interval_days || 1),
)
if (next == null) return
const days = Number.parseInt(next, 10)
if (!Number.isFinite(days) || days < 1) {
setError('Intervall muss mindestens 1 Tag sein.')
return
}
runAction(() => updateRecurring(practice.id, { interval_days: days }))
setEditingRhythmId(practice.id)
setEditSchedule(scheduleEditorFromPractice(practice))
}}
>
Rhythmus
+142
View File
@@ -0,0 +1,142 @@
import { useMemo, useState } from 'react'
import {
INTERVAL_PRESETS,
WEEKDAY_OPTIONS,
defaultScheduleValue,
detectIntervalPreset,
scheduleFromApi,
toggleWeekdayMask,
} from '../utils/scheduleUtils.js'
export function ScheduleEditor({
value,
onChange,
disabled = false,
compact = false,
}) {
const current = value || defaultScheduleValue()
const [preset, setPreset] = useState(() =>
current.schedule_kind === 'weekdays'
? 'weekdays'
: detectIntervalPreset(current.interval_days),
)
const showCustomInterval = preset === 'custom'
function setKind(kind) {
if (kind === 'weekdays') {
onChange({
...current,
schedule_kind: 'weekdays',
weekday_mask: current.weekday_mask || WEEKDAY_OPTIONS[0].bit,
})
setPreset('weekdays')
return
}
const presetDef = INTERVAL_PRESETS.find((p) => p.id === kind) || INTERVAL_PRESETS[0]
onChange({
...current,
schedule_kind: 'interval',
interval_days: presetDef.intervalDays || current.interval_days || 1,
})
setPreset(kind)
}
const weekdaySummary = useMemo(() => {
const selected = WEEKDAY_OPTIONS.filter((d) => (current.weekday_mask || 0) & d.bit)
return selected.map((d) => d.label).join(', ')
}, [current.weekday_mask])
return (
<fieldset className={`schedule-editor${compact ? ' schedule-editor--compact' : ''}`} disabled={disabled}>
<legend className="schedule-editor__legend">Rhythmus</legend>
<div className="schedule-editor__modes" role="group" aria-label="Rhythmus-Art">
{INTERVAL_PRESETS.filter((p) => p.id !== 'custom').map((p) => (
<button
key={p.id}
type="button"
className={`btn btn-sm ${preset === p.id ? 'btn-primary' : 'btn-secondary'}`}
onClick={() => setKind(p.id)}
>
{p.label}
</button>
))}
<button
type="button"
className={`btn btn-sm ${preset === 'weekdays' ? 'btn-primary' : 'btn-secondary'}`}
onClick={() => setKind('weekdays')}
>
Wochentage
</button>
<button
type="button"
className={`btn btn-sm ${preset === 'custom' ? 'btn-primary' : 'btn-secondary'}`}
onClick={() => setKind('custom')}
>
Individuell
</button>
</div>
{current.schedule_kind === 'interval' && showCustomInterval && (
<label className="schedule-editor__field">
Alle wie viele Tage?
<input
type="number"
min={1}
value={current.interval_days}
onChange={(e) =>
onChange({ ...current, interval_days: Number.parseInt(e.target.value, 10) || 1 })
}
/>
</label>
)}
{current.schedule_kind === 'weekdays' && (
<div className="schedule-editor__weekdays">
<p className="muted schedule-editor__hint">
An welchen Tagen? {weekdaySummary ? `(${weekdaySummary})` : ''}
</p>
<div className="schedule-editor__weekday-row">
{WEEKDAY_OPTIONS.map((day) => {
const active = Boolean((current.weekday_mask || 0) & day.bit)
return (
<label key={day.bit} className={`schedule-weekday${active ? ' is-active' : ''}`}>
<input
type="checkbox"
checked={active}
onChange={() =>
onChange({
...current,
weekday_mask: toggleWeekdayMask(current.weekday_mask || 0, day.bit),
})
}
/>
{day.label}
</label>
)
})}
</div>
</div>
)}
<label className="schedule-editor__field">
Pause bis (optional)
<input
type="date"
value={current.pause_until || ''}
onChange={(e) => onChange({ ...current, pause_until: e.target.value })}
/>
</label>
</fieldset>
)
}
export function scheduleEditorFromPractice(practice) {
return scheduleFromApi(practice?.schedule || {
schedule_kind: 'interval',
interval_days: practice?.interval_days || 1,
weekday_mask: 0,
pause_until: null,
})
}
+9
View File
@@ -12,6 +12,7 @@ import { updateAction, setActionAssignments } from '../api/actions.js'
import { createInitiativeBlocker } from '../api/blockers.js'
import { ActionHubCard } from '../components/ActionHubCard.jsx'
import { ActionDependenciesSection } from '../components/ActionDependenciesSection.jsx'
import { ActionScheduleSection } from '../components/ActionScheduleSection.jsx'
import { ActionForm } from '../components/ActionForm.jsx'
import { TasksSection } from '../components/TasksSection.jsx'
import { ErrorState } from '../components/ErrorState.jsx'
@@ -39,6 +40,7 @@ function ActionDetailBody({
roadmapItems = [],
allActions = [],
executionGraph = null,
onReload,
}) {
if (editing) {
return (
@@ -80,6 +82,11 @@ function ActionDetailBody({
onReloadActors={actorsState.reload}
detailMode
/>
<ActionScheduleSection
action={action}
canManage={capabilities.has('kairo.action.manage')}
onUpdated={onReload}
/>
<TasksSection
actionId={action.id}
canManage={capabilities.has('kairo.action.manage')}
@@ -254,6 +261,7 @@ function ActionDetailStandalone() {
roadmapItems={roadmapItems}
allActions={allActions}
executionGraph={executionGraph}
onReload={load}
/>
</section>
</div>
@@ -317,6 +325,7 @@ function ActionDetailNested() {
roadmapItems={ops.roadmapItems}
allActions={ops.actions}
executionGraph={executionGraph}
onReload={ops.reload}
/>
</section>
)
@@ -241,6 +241,7 @@ export function RoadmapItemDetailPage({ overrideItemId }) {
gateId={itemId}
initiativeId={initiativeId || item.initiative_id}
gateStatus={item.status}
gateTitle={item.title}
canManage={capabilities.has('kairo.recurring.manage')}
/>
)}
+67
View File
@@ -2477,3 +2477,70 @@
margin-bottom: 0.75rem;
}
.schedule-editor {
border: 1px solid var(--jk-border, #dde3ea);
border-radius: 8px;
padding: 0.75rem 1rem;
margin: 0.75rem 0;
}
.schedule-editor__legend {
font-size: 0.875rem;
font-weight: 600;
padding: 0 0.25rem;
}
.schedule-editor__modes {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
margin-bottom: 0.75rem;
}
.schedule-editor__field {
display: block;
margin-top: 0.5rem;
font-size: 0.875rem;
}
.schedule-editor__weekday-row {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
}
.schedule-weekday {
display: inline-flex;
align-items: center;
gap: 0.25rem;
padding: 0.25rem 0.5rem;
border-radius: 6px;
border: 1px solid var(--jk-border, #dde3ea);
font-size: 0.8125rem;
cursor: pointer;
}
.schedule-weekday.is-active {
background: var(--jk-accent-soft, #e8f0fe);
border-color: var(--jk-accent, #2563eb);
}
.gate-activity-set__rhythm-edit,
.action-schedule-section__edit {
margin-top: 0.75rem;
}
.action-schedule-section__summary {
display: flex;
align-items: center;
gap: 0.75rem;
flex-wrap: wrap;
}
.toggle-inline {
display: inline-flex;
align-items: center;
gap: 0.35rem;
font-size: 0.875rem;
}
+81
View File
@@ -0,0 +1,81 @@
export const WEEKDAY_OPTIONS = [
{ bit: 1, label: 'Mo', index: 0 },
{ bit: 2, label: 'Di', index: 1 },
{ bit: 4, label: 'Mi', index: 2 },
{ bit: 8, label: 'Do', index: 3 },
{ bit: 16, label: 'Fr', index: 4 },
{ bit: 32, label: 'Sa', index: 5 },
{ bit: 64, label: 'So', index: 6 },
]
export const INTERVAL_PRESETS = [
{ id: 'daily', label: 'Täglich', intervalDays: 1 },
{ id: 'every2', label: 'Alle 2 Tage', intervalDays: 2 },
{ id: 'weekly', label: 'Wöchentlich', intervalDays: 7 },
{ id: 'custom', label: 'Individuell…', intervalDays: null },
]
export function defaultScheduleValue() {
return {
schedule_kind: 'interval',
interval_days: 1,
weekday_mask: 0,
pause_until: '',
}
}
export function scheduleFromApi(schedule) {
if (!schedule) return defaultScheduleValue()
return {
schedule_kind: schedule.schedule_kind || 'interval',
interval_days: schedule.interval_days || 1,
weekday_mask: schedule.weekday_mask || 0,
pause_until: schedule.pause_until ? schedule.pause_until.slice(0, 10) : '',
}
}
export function formatScheduleLabel(schedule) {
if (!schedule) return 'Kein Rhythmus'
if (schedule.label) return schedule.label
if (schedule.schedule_kind === 'weekdays') {
const days = WEEKDAY_OPTIONS.filter((d) => (schedule.weekday_mask || 0) & d.bit).map(
(d) => d.label,
)
const base = days.length ? days.join(', ') : 'Wochentage'
return schedule.pause_until ? `${base} (Pause bis ${schedule.pause_until.slice(0, 10)})` : base
}
const days = schedule.interval_days || 1
let base = days === 1 ? 'Täglich' : days === 7 ? 'Wöchentlich' : `Alle ${days} Tage`
if (schedule.pause_until) {
base = `${base} (Pause bis ${schedule.pause_until.slice(0, 10)})`
}
return base
}
export function buildSchedulePayload(value) {
const kind = value.schedule_kind
const payload = {
schedule_kind: kind,
interval_days: kind === 'interval' ? Number(value.interval_days) || 1 : 1,
weekday_mask: kind === 'weekdays' ? Number(value.weekday_mask) || 0 : 0,
pause_until: value.pause_until ? value.pause_until : null,
}
if (kind === 'weekdays' && payload.weekday_mask <= 0) {
throw new Error('Mindestens ein Wochentag auswählen.')
}
if (kind === 'interval' && payload.interval_days < 1) {
throw new Error('Intervall muss mindestens 1 Tag sein.')
}
return payload
}
export function toggleWeekdayMask(mask, bit) {
return (mask & bit) ? mask & ~bit : mask | bit
}
export function detectIntervalPreset(intervalDays) {
const match = INTERVAL_PRESETS.find(
(p) => p.intervalDays === intervalDays && p.id !== 'custom',
)
return match ? match.id : 'custom'
}