407 Commits

Author SHA1 Message Date
root
b2ac0e7a00 feat: add Reset Stats button to admin LLM tracking panel
Allows resetting the LLM stats aggregation window without deleting
historical data. Stores a reset timestamp in metadata and filters
the aggregation query to only include calls after that point.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 01:59:24 +00:00
root
513d35e0e5 docs: update CLAUDE.md and README.md to reflect current project state
Fix stale values (test count, cooldown constants, system execution order),
add missing subsystems (LLM, desires, pickup, invention, persistence),
and document newer features (thirst, productivity, day/night cycle,
industry/crafting, LLM configuration).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 01:01:44 +00:00
root
5b29549115 feat: implement daytime nap wake logic for circadian rhythm
When NPCs emergency-sleep during the day, they now take a short nap
instead of a full sleep. They wake with just enough energy to reach
nightfall, naturally resynchronizing to a nocturnal sleep schedule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 03:05:48 +00:00
root
0a454c80b0 test: add failing tests for daytime nap wake logic
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 03:05:01 +00:00
root
d39fb14914 feat: add NAP_BUFFER constant for daytime nap system
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 03:04:05 +00:00
root
02aabc294d docs: add daytime nap implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 03:03:09 +00:00
root
37d5ce96d6 docs: fix guard condition and add reviewer feedback to nap spec
Fix inverted guard logic (napTarget < 60 triggers full sleep, not >=),
add cycleTicks derivation, clamp napTarget to 100, add test plan.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 02:57:54 +00:00
root
f0b8fea4f1 docs: daytime nap system design spec
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 02:55:12 +00:00
root
49016073ad feat: render berry bushes with 3-phase growth cycle on map
Add berry plant tileset (growing/ripe/picked phases) and wire berry bush
state from server to client so plants visually update as NPCs forage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 02:36:53 +00:00
root
9be78e3f8c fix: add 'thirst' to MemoryEvent.need type union
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:51:10 +00:00
root
955dd61117 refactor: remove all food POI references, clean up dead code
Remove pointsOfInterest from WorldState type, state serializer,
and client rendering. Remove foodPositions from map generator
interface and output. Update stale comment in worldSerializer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:47:47 +00:00
root
d1de641d34 fix: ensure social and industry systems handle drink/forage goals
Add drink/forage to isTargetBusy in socialSystem so NPCs drinking or
foraging are not interrupted by social interactions. Add drink/forage
to the industry system goal skip list so it doesn't override those goals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:47:35 +00:00
root
1cb0570a49 feat: show thirst and productivity bars on NPC status tab
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:46:43 +00:00
root
9b20033453 feat: forage goal immediately consumes gathered food/water
When an NPC has the 'forage' goal, gathered berries restore hunger
and gathered water restores thirst directly (+20) instead of going
to inventory. Berry bush depletion still occurs. Goal resets to null
after consumption so npcBrain can re-evaluate.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:45:56 +00:00
root
07b9b2193d feat: initialize thirst on NPC spawn, handle old saves missing thirst
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:45:50 +00:00
root
5c81893001 feat: rework hunger to consume berries, add drink/forage goals
Eating now consumes berries from inventory or nearby stockpile instead of
recovering hunger for free. Added drink goal (consumes water) and forage
goal (desperate survival gather when no food/water available). Priority
order: sleep > eat > drink > forage > dropoff > gather > wander.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:44:07 +00:00
root
b7865c9265 feat: berry bush depletion on gather and regrowth over time
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:41:01 +00:00
root
b5c8bdeea9 feat: add thirst stat penalties (perception -2, constitution -1)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:38:57 +00:00
root
27353e9ef3 feat: add thirst decay to needsDecaySystem with crisis events
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:37:46 +00:00
root
b75f3a05e2 feat: persist berry bush state (depletion + regrowth) across save/load
Replace foodPositions with berryBushes in TileData, saving per-bush
berryCount, maxBerries, and ticksSinceLastRegrowth to the metadata table.
On load, restore berry bush state into GameMap; fall back to initializing
from resource tiles for old saves without berry data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:35:53 +00:00
root
1b0da25887 feat: add berry bush generation, remove food POIs from map
Replace magic food POI system with berry bush clusters as gatherable
resource tiles. Berry bushes track depletion state (berryCount, maxBerries,
ticksSinceLastRegrowth). Remove PointOfInterest interface and all POI
methods from GameMap, stub out closestPOI in npcBrainSystem for later
rework, and update all tests and serializers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:33:08 +00:00
root
72746710cb feat: add berries seed item, berry bush config, thirst runtime constants
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:28:01 +00:00
root
5da03ebb69 feat: add thirst to Needs, drink/forage to GoalType, thirst constants
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:26:54 +00:00
root
30b187b838 docs: add needs overhaul implementation plan (15 tasks)
TDD-structured plan covering thirst need, berry bushes, hunger rework,
forage goal, UI bars, and food POI removal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:24:14 +00:00
root
c6f36592e7 docs: add needs overhaul design (food, thirst, productivity visibility)
Berry bushes as gatherable food, thirst need consuming water items,
productivity bar on status tab, desperate forage goal, remove magic
food POIs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 20:19:30 +00:00
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