managarten/docs
Till JS f07eae3c01 feat(personas): M3.b-d — tick loop + Claude Agent SDK + persistence (real)
Previous commit 38dc80654 carries this M3 title but its payload is an
unrelated apps/api/picture change — shared-.git-index race with a
parallel session (see feedback_git_workflow.md). This commit holds the
actual M3.b/c/d code. Leaving the misnamed commit for the user to
re-attribute / revert as they prefer.

Closes the M3 loop from docs/plans/mana-mcp-and-personas.md. The
runner picks up due personas, drives each through Claude + MCP for
one simulated turn, collects actions + ratings, persists through
service-key internal endpoints in mana-auth.

Internal endpoints (mana-auth, service-key-gated)

- GET  /api/v1/internal/personas/due
    Returns personas whose tickCadence + lastActiveAt say they're
    due. Rules: hourly > 1h, daily > 24h, weekdays > 24h mon-fri.
    NULLS FIRST so never-run personas go ahead of stale ones.

- POST /api/v1/internal/personas/:id/actions
    Batch ≤ 500. Row ids are deterministic
    `${tickId}-${i}-${toolName}` + ON CONFLICT DO NOTHING so the
    runner can retry a tick without doubling audit rows. Also
    bumps personas.last_active_at so the next /due call sees it.

- POST /api/v1/internal/personas/:id/feedback
    Batch ≤ 100. Row id is `${tickId}-${module}` — natural key is
    one rating per module per tick.

Runner tick pipeline (services/mana-persona-runner/src/runner/)

- claude-session.ts
    Two phases per tick. runMainTurn feeds the persona's system
    prompt + a German "simulate a day" user prompt to Claude Agent
    SDK's query(), with mana-mcp wired in as a streamable-HTTP MCP
    server. We iterate the returned AsyncGenerator and extract
    tool_use blocks into ActionRows; a tool_result with
    is_error=true flips the most recent action. runRatingTurn is a
    fresh query() with tools:[] asking Claude in character to rate
    each used module 1-5 as strict JSON. We parse with tolerance
    for whitespace / fences. Unparseable output becomes a synthetic
    '__parse' feedback row so operators see the failure.

- tick.ts
    Orchestrator. Skips when config.paused. Fetches /due, processes
    in batches of config.concurrency via Promise.allSettled so a
    single persona failure never kills the batch. Returns
    {due, ranSuccessfully, failed[], durationMs}.

- types.ts
    ActionRow + FeedbackRow shapes shared between claude-session
    and the internal client.

Runner bootstrap (src/index.ts)

- setInterval(config.tickIntervalMs) starts the tick loop on boot.
  tickInFlight guards against overlap when Claude latency >
  interval. If MANA_SERVICE_KEY or ANTHROPIC_API_KEY is missing,
  loop is disabled with a warn line — /health + /diag/login still
  work.
- POST /diag/tick (dev-only) fires one tick on demand, returns
  the result. Avoids waiting a full interval during testing.
- Graceful SIGTERM/SIGINT shutdown clears the interval.

Client

- clients/mana-auth-internal.ts
    X-Service-Key client for the three endpoints above.
    Constructor throws on empty serviceKey — fail loud.

Boot smoke verified: /health returns ok, /diag/tick 500s with
descriptive messages when keys absent. Warning lines on boot when
keys are missing. Type-check green across mana-auth, tool-registry,
mcp, persona-runner.

M3 exit gate is the end-to-end smoke recipe (docker up → db:push →
seed:personas → diag/tick → psql) documented in
services/mana-persona-runner/CLAUDE.md.

M2.d (cross-space family/team memberships) still deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 14:18:31 +02:00
..
architecture docs: update tool coverage table + server-side research + templates 2026-04-16 12:35:40 +02:00
central-services refactor(arcade, shared-ui): migrate CommandBar to GlobalSpotlight, delete CommandBar 2026-04-15 01:17:55 +02:00
decisions chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
future docs: add langfristige Roadmap-Punkte zu AI_AGENTS_IDEAS.md 2026-04-16 15:27:38 +02:00
modules feat(sleep): add sleep module with tracking, hygiene checklists, and stats 2026-04-13 21:19:52 +02:00
optimizable docs(optimizable): add manual-test-backlog as the "zu testen" register 2026-04-22 19:02:55 +02:00
plans feat(personas): M3.b-d — tick loop + Claude Agent SDK + persistence (real) 2026-04-23 14:18:31 +02:00
postmortems chore: tidy root files + reorganize a few stale docs 2026-04-08 12:15:27 +02:00
reports feat(agent-loop): M1 — policy gate + reminder channel + parallel reads 2026-04-23 13:56:40 +02:00
test-examples chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
ANALYTICS.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
APP_GAP_ANALYSIS.md chore: misc fixes, new services, lockfile cleanup 2026-03-28 10:27:35 +01:00
APP_ONBOARDING.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
ARCHITECTURE_MIGRATION_REPORT.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
CAPACITY_PLANNING.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
CARDS_POSTGRES_MIGRATION.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
CLOUDFLARE_DOMAINS.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
CLOUDFLARE_FALLBACK.md refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
CLUSTER_HARDWARE_ANALYSE.md rename(taktik): rebrand to Times 2026-03-30 15:44:18 +02:00
complexity-hotspots.md chore(audit): module complexity reports + workbench map 2026-04-14 19:47:42 +02:00
complexity-map.html chore(audit): module complexity reports + workbench map 2026-04-14 19:47:42 +02:00
CONTEXT_INTELLIGENCE_REPORT.md docs: add Context Intelligence research report 2026-04-14 19:50:25 +02:00
DATABASE_MIGRATIONS.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
DEPLOYMENT.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
DEVELOPMENT_SCRIPTS.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
DEVLOG_GUIDELINES.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
DISCORD_NOTIFICATIONS_SETUP.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
DOCKER_GUIDE.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
ENVIRONMENT_VARIABLES.md feat(env): persistent dev secrets via .env.secrets override 2026-04-08 17:50:37 +02:00
ERROR_TRACKING.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
EXPO_SDK_UPGRADE.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
EXTERNAL_SERVICES.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
EXTERNAL_SSD_OPPORTUNITIES.md refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
FIX_COLIMA_MOUNTS.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
GIT_WORKFLOW.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
I18N.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
LOCAL_DEVELOPMENT.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
LOCAL_LLM_MODELS.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
LOCAL_STT_MODELS.md 📝 docs: add design UX guidelines and local model documentation 2026-01-27 01:32:31 +01:00
MAC_MINI_SERVER.md fix(mana-auth) + chore: rewrite /api/v1/auth/login JWT mint, remove Matrix stack 2026-04-08 16:32:13 +02:00
MAIL_SERVER.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
MANA_BOX_HARDWARE.md rename(taktik): rebrand to Times 2026-03-30 15:44:18 +02:00
MANA_EARNING_SYSTEM.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
MANA_VALUES.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
MICROSERVICES_API_OVERVIEW.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
MOBILE_DESKTOP_APP_STRATEGY.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
module-coupling.md chore(audit): module complexity reports + workbench map 2026-04-14 19:47:42 +02:00
module-health.md chore(audit): module complexity reports + workbench map 2026-04-14 19:47:42 +02:00
MODULE_REGISTRY.md feat(invoices): close Phase-2 gaps — finance cross-link + structured addresses 2026-04-20 18:58:18 +02:00
MONETIZATION_REPORT.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
MONITORING.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
OBSERVABILITY_GAPS.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
OLLAMA_MODELS.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
PLAN_TAURI_V2.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
PORT_SCHEMA.md feat(personas): M3.a — scaffold mana-persona-runner service on :3070 2026-04-23 14:00:43 +02:00
POSTGRES_BACKUP.md fix(infra): simplify PostgreSQL backup to pg_dumpall + pg_basebackup 2026-03-24 11:39:20 +01:00
PRE_LAUNCH_CLEANUP.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
PROD_READINESS_SCORE.md feat: rename ManaCore to Mana across entire codebase 2026-04-05 20:00:13 +02:00
PROJECT_OVERVIEW.md refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
PWA_GUIDE.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
RECOMMENDED_SERVICES.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
REFACTORING_AUDIT_2026_04.md refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
SEPA_ACTIVATION_CHECKLIST.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
SETUP_TEMPLATES.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
SHARED_PACKAGES_ROADMAP.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
SYNC_BILLING_PLAN.md feat(credits): add sync billing — monthly credit subscription for cloud sync 2026-04-10 22:21:58 +02:00
TECH_STACK_INDEPENDENCE.md refactor: rename nutriphi module to food (Essen) 2026-04-14 15:30:07 +02:00
TECHNOLOGY_AUDIT_2026_03.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
TESTING_DEPLOYMENT_CHECKLIST.md chore: complete ManaCore → Mana rename (docs, go modules, plists, images) 2026-04-07 12:26:10 +02:00
URL_SCHEMA.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
USER_SETTINGS.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
VERSIONING.md refactor: rename zitare -> quotes (Zitate) 2026-04-14 20:59:16 +02:00
WHO_MODULE.md docs(who): RFC for the historical-figure guessing module 2026-04-09 13:08:07 +02:00
WINDOWS_GPU_SERVER_SETUP.md fix(mana-voice-bot): move default port 3050 → 3024 + Windows GPU deployment notes 2026-04-08 13:14:57 +02:00