Commit Graph

158 Commits

Author SHA1 Message Date
root 34aca29082 fix: sleep emoji, invention history race condition, and gathering stuck state
- Add persistent 💤 emoji over sleeping NPCs (tracks sprite position)
- Buffer history events (inventions, narration, stockpile) in SocketClient
  to fix race condition where data arrived before GameScene handlers registered
- Fix NPCs getting stuck on 'gather' goal: tree trunks are both obstacles
  and resource tiles, so pathfinding always failed. Now findNearestResource
  returns adjacent walkable tiles for non-walkable resources, and
  gatheringSystem checks adjacent tiles. Added wander fallback when
  pathfinding to any gather target fails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 18:57:50 +00:00
root 3294879bab fix: address code review findings for sleep system
- Fix NpcInfoPanel activity label: rest→sleep (functional bug)
- Remove unnecessary array spread in mapGenerator reserved set
- Remove unused SLEEP_NIGHT_END constant

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 18:02:04 +00:00
root b67d491b9d feat: update thought system to recognize sleeping NPCs
Skip sleeping NPCs in the thought generation loop and update
describeState to output 'sleeping' when currentGoal is 'sleep'.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:59:03 +00:00
root 65ee23c5be refactor: remove rest POIs from map generation, persistence, and client rendering
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:58:02 +00:00
root b76ce16cba feat(server): protect sleeping NPCs from social interactions (empathy < 7 exception)
Sleeping NPCs are now shielded from social interaction initiation unless
the approaching NPC has low empathy (< 7, i.e. rude). Sleeping NPCs also
cannot initiate social interactions themselves.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:55:13 +00:00
root 812e30a222 feat(server): implement sleep-in-place behavior in npcBrainSystem with day/night awareness
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:52:46 +00:00
root b9fcd49794 feat(server): add sleep-aware energy recovery and hunger slowdown to needsDecaySystem
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:49:26 +00:00
root fa4f0ce44d feat(shared): add sleep system constants and replace rest with sleep goal type
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:47:53 +00:00
root e32f121fc9 fix(server): guard against missing relationship components
Add null checks for relationship components before processing
social outcomes to prevent crashes when entities lack relationships.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:19:09 +00:00
root 700dddc845 chore(llm): wire llmService destroy into GameLoop shutdown
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 16:05:28 +00:00
root f685625dec feat(llm): add periodic usage logging and destroy cleanup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 16:04:41 +00:00
root 1acfc78e13 refactor(llm): remove isDailyLimitReached from downstream consumers
The LlmService interface no longer exposes isDailyLimitReached — model
switching is handled internally. Remove all checks in thoughtSystem,
inventionSystem, narrationService, and thoughtGenerator. Update mocks
in test files to match the new interface and remove obsolete daily-limit
test cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 16:03:09 +00:00
root 5c9edbde3c feat(llm): add model switching on 429 and usage tracking to llmService
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:59:42 +00:00
root 432d8aac2e feat(llm): add per-model usage counters for observability
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:57:29 +00:00
root 7485dec335 refactor(llm): remove daily limit gatekeeping from generationQueue
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:56:17 +00:00
root 760eda92f3 feat(llm): return structured rate-limit info on 429 responses
Add RateLimitInfo interface and CompletionResult type union so callers
can distinguish 429 rate limits from other errors. Includes isRateLimited
type guard and per-request model override in CompletionRequest.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:53:50 +00:00
root c2dbdcf146 feat(llm): add fallbackModel config, remove hardcoded model default
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:49:48 +00:00
root 2f2248cb6d test(persistence): add full save/load integration test
Verifies complete save → close → reopen → load cycle with NPCs,
relationships, bonds, structures, and all event types (narration,
memory, stockpile, invention).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:43:19 +00:00
root 94fcafeea0 feat(persistence): add database indexes for query performance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:38:35 +00:00
root eb639bf562 feat(server): integrate persistence into GameLoop and main.ts
Wire SaveManager into game startup/shutdown: constructor now checks for
existing save file and loads or creates new world accordingly. Add
autosave every 30s, final save on stop, and graceful shutdown signals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:34:03 +00:00
root ca79868061 feat(persistence): add SaveManager orchestration class
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:29:21 +00:00
root 552d5fcafb feat(persistence): add persistence hooks to event services
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:25:16 +00:00
root 0fdf6c95af Merge branch 'worktree-agent-abadd094' 2026-03-09 14:18:47 +00:00
root 734abeb661 Merge branch 'worktree-agent-a3c95e37' 2026-03-09 14:18:34 +00:00
root 514a18ab54 feat(server): add entity serializer for save/load persistence
Add createEntityWithId to World for restoring entities with original IDs.
Implement saveEntities/loadEntities to persist NPCs, structures, relationships,
and bonds to SQLite, with proper Map serialization and transient state resets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:14:05 +00:00
root 52e94112e6 feat(persistence): add event serializer for narration, memory, stockpile, and inventions
Save/load functions for all four event tables with proper JSON serialization,
chronological ordering, per-entity grouping, and optional field handling.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:12:22 +00:00
root 305e49789a feat(server): add world serializer for tile and metadata persistence
Implements saveTiles/loadTiles for round-tripping terrain, decorations,
trunk decorations, resource tiles, obstacles, food and rest positions
via SQLite. Adds saveMetadata/loadMetadata for tick and timestamp.
Includes database.ts (previously only in main worktree).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:11:08 +00:00
root f5c8d8661b feat(server): add SQLite database module with schema and connection management
Adds persistence/database.ts with openDatabase, getDatabase, closeDatabase,
getSchemaVersion, and CURRENT_SCHEMA_VERSION. Creates 10 tables (metadata,
tiles, entities, components, relationships, bonds, narration_events,
memory_events, stockpile_log, inventions) with WAL journal mode. Includes
8 tests covering table creation, schema versioning, connection reuse, and
data persistence across reopen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:08:49 +00:00
root b30e7be48a chore: add better-sqlite3 dependency and saves directory
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 14:07:12 +00:00
root 9a3e9d4757 fix(server): prioritize stockpile dropoff over wandering after gathering
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 03:00:55 +00:00
root 9f77a84d6f feat(server): add pickup system for NPC stockpile material retrieval
NPCs can now retrieve crafting materials from stockpiles instead of
always gathering raw resources. The industry system checks if a
stockpile has needed materials before falling back to gathering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 02:52:37 +00:00
root 60c6d7808d feat(server): emit stockpile log events from dropoffSystem
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 02:49:24 +00:00
root 188a915732 feat(server): wire StockpileLog into GameLoop and SocketServer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 02:48:23 +00:00
root 9194a56848 feat(server): add StockpileLog singleton for tracking stockpile activity
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 02:47:35 +00:00
root 1271fc1d7f feat(server): emit invention-event and invention-history socket events
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 00:43:03 +00:00
root 3937b85ed6 feat(server): pass full invention data to timeline on registration
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 00:41:53 +00:00
root 0ff4c24bd6 feat(server): extend InventionTimeline with full invention data and getSummaries
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 00:41:11 +00:00
root e127aea842 test(systems): add invention integration test for end-to-end lifecycle
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:58:26 +00:00
root 857c7bc899 feat(game): wire inventionSystem and inventionTimeline into game loop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:53:38 +00:00
root 6fc3fb75de feat(systems): add inventionSystem with LLM-driven eureka moments
Runs every 100 ticks, checks each NPC for a probability-based eureka
moment scaled by INT and CUR stats. On trigger, sends LLM request with
available materials context, parses/validates the response, registers
the new item + recipe, emits narration, and records a memory event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:52:19 +00:00
root e5457b2446 feat(superlatives): add mostInventive superlative
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:49:40 +00:00
root 3480405185 feat(industry): add invention registration helper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:48:10 +00:00
root d7fbe5f547 feat(industry): add LLM invention response parser
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:47:01 +00:00
root 57f3832b0b feat(industry): add invention validation pipeline
Validates LLM-generated invention JSON: checks inputs exist in
ItemRegistry, rejects name collisions (case-insensitive), validates
categories, and generates snake_case itemIds from names.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:46:06 +00:00
root b6a08c8bd8 feat(industry): add InventionTimeline singleton for tracking inventions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:44:44 +00:00
root 66247276cd feat(llm): add invention prompt template
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:43:56 +00:00
root b8e63ba96d feat(config): add invention tuning values to industryConfig
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:43:53 +00:00
root 878c6fe2b2 fix(industry): check toolRequired in findCraftable
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:33:58 +00:00
root 4e1ddf0e75 test(systems): add industry integration tests for gather/craft/build lifecycle
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:30:16 +00:00
root c7fd106011 feat(game): wire industrySystem, craftingSystem, buildingSystem, dropoffSystem into game loop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:27:57 +00:00