Keysat dba478aa23 v1.1.0:3 — AI upgrades: history context, test connection, cost estimator, streaming preview
Four incremental upgrades to the AI program generator. No schema change, no /data migration.

1. History as context (the killer feature)
   - lib/ai/historyContext.ts builds a 90-day per-exercise rollup:
     frequency, recent weights, estimated 1RM (Epley), avg RPE,
     days-since-last, plus a STAGNANT flag when the heaviest weight in
     the new half doesn't beat the old half.
   - Generate page surfaces an "Include my workout history as context"
     checkbox (default on at >=10 logged workouts). When checked, the
     ~1-3 KB summary is appended to the system prompt so the model can
     recommend things like "you've stalled bench at 245 — try paused reps."
   - We deliberately don't ship raw set logs (privacy + token cost).

2. Test connection
   - POST /api/ai/test sends a tiny "say hi in 3 words" prompt and
     reports latency + first sample, or the error inline.
   - "Test connection" button next to "Save AI config" in
     Settings -> AI integration. Verifies provider/model/key/baseUrl
     without going through full program generation.

3. Cost estimator
   - lib/ai/pricing.ts ships a price table for major models
     (Claude 3.5/3.7/4/4.5, GPT-4o/5/o1/o3/o4-mini, Gemini 1.5/2.0/2.5).
     Ollama always returns 0; openai-compatible returns null.
   - Generation history shows per-row cost + a 30-day rolling total
     at the top of the page.

4. Streaming preview render
   - lib/ai/lenientJson.ts: stack-aware partial-JSON parser that
     auto-closes open strings/brackets/braces in reverse-of-opening
     order, drops dangling key:value pairs and partial keywords.
     Returns a best-effort snapshot of the program-so-far on each chunk.
   - Generate UI now renders a live "Building program..." panel that
     updates as weeks/days/exercises arrive instead of just showing
     raw text and waiting for stream end.

Tests: 26 new (ai-historyContext.test.ts, ai-lenientJson.test.ts,
ai-pricing.test.ts). 161 total pass.
2026-05-10 22:17:35 -05:00

Proof of Work

Self-hosted multi-user workout planner and logger. Plan training cycles, log daily workouts, search your history, and curate a shared exercise library across everyone on the instance. Distributed as a StartOS 0.4 sideload package.

Repo layout

proof-of-work/    Next.js app (TypeScript, Prisma + SQLite, Tailwind, PWA)
start9/0.4/       StartOS 0.4 package wrapper (manifest, Dockerfile,
                  entrypoint, version graph, change-credentials action)

Everything else is generated at build time.

Local development

cd proof-of-work
npm install
npx prisma generate       # important after schema changes
npx prisma db push        # create the dev DB at prisma/data/app.db
npm run db:seed           # ONLY seeds the InstanceSettings singleton — no admin
npm run dev               # http://localhost:3000

For local dev you'll need to create an admin manually since the StartOS action isn't available — easiest is npx tsx a one-off script, or just open Prisma Studio (npm run db:studio) and add a User row with isAdmin: true + a bcrypt hash you generate with node -e 'require("bcrypt").hash("yourpassword", 10).then(console.log)'.

Multi-user

Fresh installs ship with no admin user on purpose — the operator must run the StartOS Action Set admin credentials (Services → Proof of Work → Actions) before anyone can log in. This eliminates the default-credentials footgun.

Once the admin exists, they can open sign-ups for additional users:

  • In-app: log in as admin -> Settings -> Instance Settings -> Allow new sign-ups.
  • StartOS: Services -> Proof of Work -> Actions -> Set new signups.

Both write to the same InstanceSettings row; either path works.

When sign-ups are open, anyone reaching the URL can create an account at /auth/signup. New users start with no admin privileges and are automatically seeded the full curated exercise library.

Building the StartOS package

See start9/0.4/DEPLOY_040.md for the full deployment / cutover guide. Short version:

cd start9/0.4
npm ci
make clean
make x86                  # produces proof-of-work_x86_64.s9pk
make install              # sideload to the host in ~/.startos/config.yaml

Curated exercise library

proof-of-work/prisma/exercises.seed.json is the canonical library shipped to every install. It seeds fresh installs (via prisma/seed.ts) and is re-applied on every boot to existing installs (via docker_entrypoint.sh + ensureExerciseLibrary.cjs) so updates flow to all users on package upgrade.

Refresh the JSON from the maintainer's live host:

./start9/0.4/refresh_seed.sh <ssh-target>     # pull a fresh /data snapshot
cd proof-of-work && npm run sync-library      # extract Exercise table -> JSON
git diff prisma/exercises.seed.json

The system is additive only — removing an exercise from the JSON does not delete it from existing installs (users may have logged sets against it). Users' own custom exercises (isCustom = true) are never touched.

Privacy

start9/0.4/seed/data/app.db is your live /data snapshot. It contains real workout history and a bcrypt'd password hash. The top-level .gitignore keeps it out of git; do NOT commit it to any public repo.

S
Description
No description provided
Readme 110 MiB
Languages
TypeScript 93.8%
Shell 2.6%
JavaScript 2.4%
Makefile 0.7%
Dockerfile 0.4%