Coach: Fragebogen beim ersten Mal, dann ein Chat mit dem Coach; Admin-Dashboard lesbar

Der Coach ist jetzt ein Gespraech. Beim ersten Mal ein Onboarding im Apple-Stil — eine
Frage pro Bildschirm, 1–7 Tage frei, Trainingsdauer als HH:MM — danach der Chat: die
Antworten als erste Nachricht, eine Tipp-Blase mit gemessener Dauer waehrend der Job
laeuft, der Plan als Karte mit Routinen-Tabs und Begruendungen, Freitext zum Nachbessern,
ein Knopf zum Uebernehmen. Zurueckkommen, Review anfordern, Antworten aendern — alles im
selben Chat. Der Aus-Schalter fuer Nutzer ist weg: abschalten kann nur noch der Admin.

Das Admin-Dashboard fuehrt in nummerierten Schritten (Provider → Endpunkt → Zugang →
Modell → Test) mit Statuspille und Klartext; Limits, Konto und Isolation unter
'Advanced', die Jobs unter 'Activity'.
This commit is contained in:
Duarte Santos committed 2026-08-29 20:45:22 +02:00
1 parent aef950cf7c
commit 18dd33e9d3
23 files changed
+2070 -321

No files matched your search

+6 -2
View File
@@ -37,6 +37,7 @@ const HANDLE_LENGTH = 16
let job = null
let lastError = null
let last = null // how the most recent job ended — the same shape the server's status() reports
// Reported to the screens through the same status shape the server answers with; a toast is
// also raised because on the server a failed job lands in the admin card, and here there is
// no admin card — the user is the operator.
@@ -80,7 +81,7 @@ async function bumpDaily() {
export async function localStatus() {
const d = await loadCoachDevice()
if (d.pending && d.pending.expiresAt && d.pending.expiresAt < Date.now()) await saveCoachDevice({ pending: null })
return { job, pending: (await loadCoachDevice()).pending || null, cap: await capState(), lastError }
return { job, pending: (await loadCoachDevice()).pending || null, cap: await capState(), lastError, last }
}
export const localReview = (S, note) => start(S, 'review', { note: note ? String(note).slice(0, 1000) : null })
@@ -145,10 +146,12 @@ async function run(S, kind, opts, d, adapter) {
})
if (!attempt.ok) {
lastError = { errorClass: attempt.errorClass, detail: attempt.detail || null }
last = { id: job.id, kind, outcome: 'failed', errorClass: attempt.errorClass, at: Date.now() }
if (notify) notify({ kind: 'failed', errorClass: attempt.errorClass, detail: attempt.detail || null })
return
}
if (attempt.nochange) {
last = { id: job.id, kind, outcome: 'nochange', errorClass: null, at: Date.now(), reading: attempt.reading }
if (notify) notify({ kind: 'nochange', reading: attempt.reading })
return
}
@@ -158,8 +161,9 @@ async function run(S, kind, opts, d, adapter) {
...attempt.result
}
await saveCoachDevice({ pending })
last = { id: job.id, kind, outcome: 'ready', errorClass: null, at: Date.now() }
if (notify) notify({ kind: 'ready', pending })
}
// Test seam.
export function _resetLocal() { job = null; lastError = null }
export function _resetLocal() { job = null; lastError = null; last = null }
+55 -2
View File
@@ -27,10 +27,18 @@ export const CONSENT_VERSION = 1
// ~75 KB; the namespace guard is the backstop for the case nobody predicted.
export const SNAPSHOT_MAX = 3
export const LOG_MAX = 50
export const CHAT_MAX = 40
export const TIMINGS_MAX = 5
const NAMESPACE_MAX = 256 * 1024
export const emptyCoach = () => ({
consent: null, profile: null, cadence: 'off', lastReview: null, log: [], snapshots: []
consent: null, profile: null, cadence: 'off', lastReview: null, log: [], snapshots: [],
// The conversation as the user saw it (views/CoachChat.jsx): their messages, and what the
// Coach did with them. Short, synced, and trimmed with the log — the proposal itself lives
// server-side (or in the phone's device file) until it is applied or dismissed.
chat: [],
// How long the last few jobs took, so the typing bubble can say "usually about 2 minutes".
timings: []
})
const coachOf = s => (s.coach = s.coach || emptyCoach())
@@ -267,12 +275,57 @@ function trim(s) {
const c = coachOf(s)
let guard = 0
while (JSON.stringify(c).length > NAMESPACE_MAX && guard++ < 60) {
if ((c.snapshots || []).length > 1) c.snapshots.shift()
if ((c.chat || []).length > 8) c.chat.shift()
else if ((c.snapshots || []).length > 1) c.snapshots.shift()
else if ((c.log || []).length > 1) c.log.shift()
else break
}
}
/* ============================ the conversation ============================ */
/**
* One line of the chat: `{ id, role: 'user'|'coach', kind, text?, at, ref? }`.
* kinds — user: 'intake' (the questionnaire, rendered from the live profile), 'text';
* coach: 'text', 'applied', 'dismissed', 'reverted', 'error', 'nochange'.
*/
export function appendChat(s, entry) {
const c = coachOf(s)
c.chat = [...(c.chat || []), { id: entry.id || uid(), at: entry.at || Date.now(), ...entry }].slice(-CHAT_MAX)
trim(s)
}
/** A job just finished: remember how long it took, for the next typing bubble. */
export function recordTiming(s, ms) {
if (!(ms > 0)) return
const c = coachOf(s)
c.timings = [...(c.timings || []), Math.round(ms)].slice(-TIMINGS_MAX)
}
/** Median of the observed job durations, or null before any. */
export function estimateMs(S) {
const arr = [...(S?.coach?.timings || [])].filter(n => n > 0).sort((a, b) => a - b)
if (!arr.length) return null
return arr[Math.floor(arr.length / 2)]
}
/** The questionnaire, as the lines the chat shows back to the user. */
export function profileLines(p) {
if (!p) return []
const goal = { strength: 'Get stronger', muscle: 'Build muscle', general: 'General fitness', fatloss: 'Lose fat', endurance: 'Endurance' }[p.goal]
const exp = { new: 'New to lifting', returning: 'Coming back after a break', regular: 'Training regularly' }[p.experience]
const lines = []
if (goal) lines.push(t(goal))
if (exp) lines.push(t(exp))
if (p.daysPerWeek) lines.push(t('{0} days a week', p.daysPerWeek))
if (p.sessionMin) lines.push(t('{0} min per session', p.sessionMin))
if (p.equipment?.length) lines.push(p.equipment.join(', '))
if (p.limitations) lines.push(t('Limits: {0}', p.limitations))
if (p.likes) lines.push(t('Likes: {0}', p.likes))
if (p.dislikes) lines.push(t('Avoid: {0}', p.dislikes))
if (p.notes) lines.push(p.notes)
return lines
}
/* ============================ applying a created plan ============================ */
/**
+3 -3
View File
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(390)
expect(inherited).toHaveLength(522)
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(422)
expect(inherited).toHaveLength(541)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('215c0ce2464d4ab771a208158dcc005f26f8538c15023fb5ff77828dfbc235f5')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('d4f338190ba41fe089ddb45049a812c36fbbda0887cc4f6ab073114c98a49e90')
})
test('does not leak European Portuguese UI terms', () => {