Merge pull request #19 from Pengboi/feat/mcp-server

MCP: read-only stdio server for LLM apps to query workout history

Ein Node-Prozess, den der LLM-Client selbst startet und der dieselben reinen
Helfer aus frontend/src/lib benutzt wie die Stats-Seite — also stehen dort
dieselben Zahlen. Read-only, kein Container, kein zusaetzliches Auth, nichts
verlaesst die Box. Wer keinen KI-Client benutzt, merkt nichts davon.
This commit is contained in:
Duarte Santos committed 2026-08-04 16:30:14 +02:00
commit f554b6b004
15 files changed
+3761 -41

No files matched your search

+6 -4
View File
@@ -1,5 +1,5 @@
import { EXDB } from './exercises-data.js'
import { t } from './i18n.js'
import { t } from './i18n-core.js'
export { EXDB }
export const EXIDX = {}
@@ -28,9 +28,11 @@ export const allExercises = st => [...(st.customEx || []), ...EXDB]
// Media normally sits next to the app (img/ and gif/, mounted into the web container).
// A build can point them somewhere else — the demo build pulls them off a CDN instead of
// shipping ~140 MB of images into the deployment.
const IMG_BASE = import.meta.env.VITE_IMG_BASE || 'img/'
const GIF_BASE = import.meta.env.VITE_GIF_BASE || 'gif/'
// shipping ~140 MB of images into the deployment. `import.meta.env` is undefined in plain
// Node; the guard keeps this module loadable without Vite.
const ENV = import.meta.env || {}
const IMG_BASE = ENV.VITE_IMG_BASE || 'img/'
const GIF_BASE = ENV.VITE_GIF_BASE || 'gif/'
export const imgSrc = ex => IMG_BASE + ex.img
export const gifSrc = ex => GIF_BASE + ex.gif
+1 -1
View File
@@ -1,5 +1,5 @@
// Formatting + date helpers (ported from the vanilla app, unit taken from the store where needed).
import { dateLocale, t } from './i18n.js'
import { dateLocale, t } from './i18n-core.js'
export const todayISO = () => {
const d = new Date()
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
+44
View File
@@ -0,0 +1,44 @@
// Runtime-agnostic core of the i18n module: state, constants and readers (t, dateLocale,
// instrFor, getLang). Plain Node-loadable — the browser-only pieces (import.meta.glob lazy
// loads, the React subscription hook) live in i18n.js and re-export from here.
export const LANGS = {
en: 'English', de: 'Deutsch', es: 'Español', fr: 'Français', it: 'Italiano',
pt: 'Português', pl: 'Polski', tr: 'Türkçe', ru: 'Русский', zh: '中文',
ko: '한국어', hi: 'हिन्दी'
}
export const INSTR_LANGS = ['en', 'es', 'fr', 'it', 'tr', 'ru', 'zh', 'hi', 'pl', 'ko']
export const DATE_LOCALES = {
en: 'en-GB', de: 'de-DE', es: 'es-ES', fr: 'fr-FR', it: 'it-IT', pt: 'pt-PT',
pl: 'pl-PL', tr: 'tr-TR', ru: 'ru-RU', zh: 'zh-CN', ko: 'ko-KR', hi: 'hi-IN'
}
let lang = 'en' // set only by _setLangState, called from i18n.js setLang
let dict = {} // current locale pack (empty = English fallback)
let instr = null // { exId: [steps] } for the current language, null = English
let version = 0 // bumped on every setLang; drives the React subscription selector
export const getLang = () => lang
export const dateLocale = () => DATE_LOCALES[lang] || 'en-GB'
export const getVersion = () => version
// Translate a source string; {0},{1}… are replaced with args (also on the English fallback).
export function t(s, ...args) {
let v = dict[s] || s
for (let i = 0; i < args.length; i++) v = v.replaceAll('{' + i + '}', args[i])
return v
}
// Instructions for an exercise in the current language (English steps as fallback).
export const instrFor = ex => (instr && instr[ex.id]) || ex.st || []
// Called by i18n.js's setLang once the locale pack has been loaded — kept here rather than
// exported as setLang because loading packs requires import.meta.glob, which is Vite-only.
// Both `dict` and `instr` may be null to reset to English.
export function _setLangState(newLang, newDict, newInstr) {
lang = LANGS[newLang] ? newLang : 'en'
dict = lang === 'en' ? {} : (newDict || {})
instr = lang === 'en' || !INSTR_LANGS.includes(lang) ? null : (newInstr || null)
version++
return version
}
+18 -36
View File
@@ -1,56 +1,38 @@
// Tiny dependency-free i18n. English source strings are the keys; locale files in
// src/locales/ map them to translations and are lazy-loaded (Vite code-splits each
// import.meta.glob entry), so the initial bundle stays English-only.
// Exercise instructions come from separately generated packs in src/instr/ (one per
// language, from the upstream dataset) — also lazy-loaded on language switch.
// Browser-only shell of the i18n module. The runtime-agnostic state and readers live
// in i18n-core.js (plain Node-loadable); this file adds the two pieces that genuinely need
// the browser: `setLang` (which lazy-loads locale packs via import.meta.glob) and the React
// subscription hook `useLang`.
import { useSyncExternalStore } from 'react'
import {
LANGS, INSTR_LANGS, DATE_LOCALES,
getLang, dateLocale, t, instrFor, getVersion, _setLangState
} from './i18n-core.js'
// UI languages. de/pt have no instruction pack upstream — instructions fall back to English.
export const LANGS = {
en: 'English', de: 'Deutsch', es: 'Español', fr: 'Français', it: 'Italiano',
pt: 'Português', pl: 'Polski', tr: 'Türkçe', ru: 'Русский', zh: '中文',
ko: '한국어', hi: 'हिन्दी'
}
export const INSTR_LANGS = ['en', 'es', 'fr', 'it', 'tr', 'ru', 'zh', 'hi', 'pl', 'ko']
const DATE_LOCALES = {
en: 'en-GB', de: 'de-DE', es: 'es-ES', fr: 'fr-FR', it: 'it-IT', pt: 'pt-PT',
pl: 'pl-PL', tr: 'tr-TR', ru: 'ru-RU', zh: 'zh-CN', ko: 'ko-KR', hi: 'hi-IN'
}
export { LANGS, INSTR_LANGS, DATE_LOCALES, getLang, dateLocale, t, instrFor }
// Vite code-splits each locale pack into its own chunk via import.meta.glob; instructions use
// the same mechanism in src/instr/. Both are lazy, so the production bundle ships English only.
const localePacks = import.meta.glob('../locales/*.js')
const instrPacks = import.meta.glob('../instr/*.js')
let lang = 'en'
let dict = {}
let instr = null // { exId: [steps] } for the current language, null = English
let version = 0
// React subscription bookkeeping — kept here, not in core, so core has zero React coupling.
const subs = new Set()
const notify = () => { version++; subs.forEach(f => f()) }
export const getLang = () => lang
export const dateLocale = () => DATE_LOCALES[lang] || 'en-GB'
// Translate a source string; {0},{1}… are replaced with args (also on the English fallback).
export function t(s, ...args) {
let v = dict[s] || s
for (let i = 0; i < args.length; i++) v = v.replaceAll('{' + i + '}', args[i])
return v
}
// Instructions for an exercise in the current language (English steps as fallback).
export const instrFor = ex => (instr && instr[ex.id]) || ex.st || []
const notify = () => { subs.forEach(f => f()) }
export async function setLang(l) {
if (!LANGS[l]) l = 'en'
if (l === lang && version > 0) return
lang = l
if (l === getLang() && getVersion() > 0) return
let dict = {}, instr = null
try {
dict = l === 'en' ? {} : (await localePacks['../locales/' + l + '.js']()).default
instr = l === 'en' || !INSTR_LANGS.includes(l) ? null : (await instrPacks['../instr/' + l + '.js']()).default
} catch (e) { dict = {}; instr = null }
_setLangState(l, dict, instr)
notify()
}
// Re-renders the subscribing component (and its children) whenever the language changes.
export function useLang() {
return useSyncExternalStore(fn => { subs.add(fn); return () => subs.delete(fn) }, () => version)
return useSyncExternalStore(fn => { subs.add(fn); return () => subs.delete(fn) }, getVersion)
}