Commit Graph

382 Commits

Author SHA1 Message Date
root 3721d2de5b fix: persist admin runtime constants to DB across restarts
Constants were purely in-memory; any server restart reverted them
to code defaults. Now saved to metadata table as JSON on every
autosave and restored on startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:37:17 +00:00
root 53be21e512 fix: increase maxTokens limits to reduce truncation failures
Default 200→400, invention 300→600, desireGeneration 500→800,
backstoryAndDesires 800→1200. Can trim back once we have usage data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:32:02 +00:00
root 8fe442e38c fix: move day label update before early return, add line-height
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:20:18 +00:00
root 61f6c0629f feat: pass dayNumber from state updates to TimeIndicator 2026-03-10 19:17:51 +00:00
root 6dcf281702 feat: double TimeIndicator size and add day counter 2026-03-10 19:17:47 +00:00
root 70ce82302a refactor: use centralized getDayNumber() in inventionSystem 2026-03-10 19:14:04 +00:00
root c71640fd3b feat: broadcast dayNumber in state updates 2026-03-10 19:13:38 +00:00
root 815769ad69 feat: add getCycleTicks() and getDayNumber() to GameLoop 2026-03-10 19:13:27 +00:00
root c810c99a89 feat: add dayNumber to StateUpdate type 2026-03-10 19:13:16 +00:00
root 5d407d41fa docs: add day counter + 2x indicator implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:10:48 +00:00
root 4526ba908c docs: add day counter + 2x indicator design
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:09:05 +00:00
root b32e0f8489 fix: use full OpenRouter model IDs in pricing lookup
MODEL_PRICING keys were 'gpt-oss-120b' but the actual model string
from env is 'openai/gpt-oss-120b'. The lookup always missed, so
calculateCost returned 0 for every call. Updated keys to match the
full OpenRouter model identifiers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:54:36 +00:00
root e465167651 refactor: add jsonResponse flag to auto-inject compact JSON instruction
Templates with jsonResponse:true automatically get the compact
single-line JSON instruction appended to their system prompt via
renderTemplate. Removes manually duplicated JSON formatting
instructions from invention, backstoryAndDesires, and desireGeneration
templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:51:36 +00:00
root dc6dd946a2 fix: salvage backstory from truncated JSON, request compact output
Model sometimes returns pretty-printed JSON with newlines/indentation,
wasting tokens and causing truncation. Now requests compact single-line
JSON. When JSON is truncated, regex-extracts the backstory field rather
than setting raw JSON as the backstory text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:49:06 +00:00
root 2b5bf86b0f fix: bump maxTokens again (800/500) and add conciseness instructions
Post-restart logs show model still hitting 600-token ceiling on verbose
responses — truncated JSON at exactly 599-600 output tokens. Average
successful response was ~418 tokens but outliers reach 600+. Added
explicit conciseness instructions to backstory prompt to reduce variance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:42:56 +00:00
root 0d0080a6ff fix: increase maxTokens for backstory (600) and desire (400) templates
Every single LLM failure was finish_reason='length' — the model was
running out of output tokens before completing the JSON response.
backstoryAndDesires at 350 tokens couldn't fit a backstory + 2 desires
with fulfillment criteria; desireGeneration at 250 was too tight for
a single desire with reasoning.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:38:33 +00:00
root 087426e894 feat: add llm_debug_log table for persistent LLM failure diagnostics
Captures full prompt content, response text, HTTP status, and finish
reason on every LLM failure path. Replaces silent null returns in
openRouterClient with structured CompletionFailure objects so error
details propagate up through the queue and service layers.

Also removes recipeList from backstoryAndDesires prompt (not useful
for backstory generation) and adds schema migration v3.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:35:44 +00:00
root 18f649d766 debug: add diagnostic logging to invention system
Every failure path was silent — LLM nulls, parse failures, validation
rejections, and promise errors were all swallowed. Adds per-attempt
logging at each gate plus a periodic summary of NPC/inventory/item state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:32:37 +00:00
root 8e6a970ae4 fix: backstory generation reliability and admin LLM stats loading
- Fix LLM stats panel stuck on "Loading stats..." by requesting stats
  immediately after admin authentication succeeds
- Add retry mechanism for backstory generation (up to 3 attempts with
  increasing delays) so transient failures don't permanently skip NPCs
- Fix stale model bug: queued LLM requests now use the current model at
  dequeue time instead of capturing it at enqueue time, so fallback
  model switches take effect for pending requests
- Add per-template maxTokens (backstory: 350, invention: 300, desire:
  250) to prevent "length" finish truncation on structured JSON responses
- Remove unused "reasoning" field from backstory prompt to reduce token usage
- Add failure logging throughout LLM pipeline (backstory null results,
  queue errors) for better diagnostics

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:21:00 +00:00
root b6f93dd694 feat: add world preamble to LLM prompts, update gitignore
- Extract shared WORLD_PREAMBLE and prepend to all system prompts
- Remove duplicated world-setting text from individual templates
- Add server/saves/ and treesnstone.zip to .gitignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:03:38 +00:00
root f9e99ff09a feat: wire LLM stats into GameScene admin panel
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:28:48 +00:00
root 28ce0822e6 feat: add two-column admin panel with LLM analytics display
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:28:01 +00:00
root 7b8ba95189 feat: widen LeftPanel to 680px when admin tab is active
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:27:21 +00:00
root d2fd013312 feat: add client socket methods for LLM stats
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:26:03 +00:00
root e5d3517416 feat: add socket handlers for LLM stats and tracking toggle
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:25:55 +00:00
root 274789a76a feat: wire llmStatsService into GameLoop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:25:02 +00:00
root 9f31144430 feat: schema migration v1→v2 adding llm_call_log table
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:23:47 +00:00
root b9edbee77d feat: instrument llmService to record calls via llmStatsService
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:22:11 +00:00
root 478ca06818 feat: add llmStatsService with SQLite persistence and aggregation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:20:26 +00:00
root a6c92e7f99 feat: include retry count in openRouterClient CompletionSuccess
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:17:45 +00:00
root f3186f6020 feat: add model pricing config and cost calculation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:15:57 +00:00
root fb78d8cc9c feat: add LLM analytics types and socket events to shared
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:14:55 +00:00
root d11f19e703 docs: add LLM analytics implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:12:38 +00:00
root 703b940e9d docs: add LLM analytics tracking design
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 13:08:10 +00:00
root 6712942436 fix: address code review — auth gating, subscription cleanup, debounce, npcBrainSystem
- Wire npcBrainSystem to RuntimeConstants (was using hardcoded shared imports)
- Add auth gating on admin-update-constant and admin-reset-defaults sockets
- Unsubscribe from previous tab's data sources on left-panel tab switch
- Use per-key debounce timers in AdminPanel to avoid dropped changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:42:51 +00:00
root e5715ec467 feat: wire all gameplay systems to RuntimeConstants
Replace direct constant imports with rc.get() calls in needsDecaySystem,
socialSystem, statModifierSystem, movementSystem, gatheringSystem,
craftingSystem, buildingSystem, and SocketServer. All system functions
now accept a RuntimeConstants parameter, enabling live-tuning of game
constants via the admin panel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:35:39 +00:00
root 701411c9a4 feat: integrate Admin and Log panels into LeftPanel and GameScene
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:28:32 +00:00
root 926bdc6687 feat: add AdminPanel UI component with password gate and constant editor
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:25:51 +00:00
root a897dbfee4 feat: add LogPanel UI component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:25:21 +00:00
root 39cb094110 feat: add admin and log socket methods to SocketClient
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:25:03 +00:00
root e2670b0c34 feat: add admin auth and log streaming socket handlers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:23:46 +00:00
root ff53096d94 feat: wire LogService into LLM layer for error/warning logging
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:22:20 +00:00
root 191770acbe feat: wire LogService into network layer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:21:08 +00:00
root 0d8573e11f feat: wire LogService + RuntimeConstants into GameLoop
Replace direct constant imports (TICK_RATE, BROADCAST_EVERY_N_TICKS,
ENERGY_DECAY_PER_TICK, DAY_NIGHT_RATIO) with RuntimeConstants lookups.
Add LogService for autosave logging and tick overrun detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:19:55 +00:00
root 0d93574e76 feat: add RuntimeConstants service with get/update/reset
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:17:50 +00:00
root f8cb83481e feat: add LogService with ring buffer and subscriber push
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:17:48 +00:00
root 778eeb3832 feat: add TunableConstants, LogEntry types and socket events
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:16:27 +00:00
root 186536d95c docs: Admin & Log panel implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:13:37 +00:00
root 43c3709293 docs: Admin & Log panel design
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 02:09:55 +00:00
root 0127eeaae6 fix: remove quotes around backstory display
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 01:51:25 +00:00