Commit Graph

137 Commits

Author SHA1 Message Date
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
root 82324f7666 feat(systems): integrate craft/build/dropoff goals into brain and movement
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:27:03 +00:00
root e0e5c6615e feat(systems): add industrySystem with craft/build/gather decision tree
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:25:39 +00:00
root 9247a8c6e4 feat(systems): add dropoffSystem for stockpile item transfer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:25:38 +00:00
root 5aa42d829b feat(systems): add buildingSystem with structure progress tracking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:22:58 +00:00
root 6140823c99 feat(systems): add craftingSystem with input consumption and output production
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:22:19 +00:00
root 4399a1cd34 feat(industry): add RecipeRegistry with seed recipes for tools and structures
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 23:20:38 +00:00
root e532c85d6b feat(config): add crafting and building tuning values 2026-03-08 23:19:10 +00:00
root 25d842e367 feat(systems): pause movement during gathering, wire gathering into game loop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:50:48 +00:00
root 3a075b68e0 feat(protocol): broadcast inventory and resource tiles to clients
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:50:38 +00:00
root 5fba656c62 feat(systems): add gatheringSystem with timer, stat modifier, and inventory
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:49:47 +00:00
root 61c463c1c7 feat(brain): add gather goal when productivity is low
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:47:51 +00:00
root e1edbd47c6 feat(needs): add productivity decay to needsDecaySystem
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:46:57 +00:00
root 4670bfc08b feat(spawner): add productivity need and inventory to spawned NPCs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:45:34 +00:00
root 096597e7e5 feat(loop): register ItemRegistry and load resource tiles
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:44:59 +00:00
root 429523f3b4 feat(map): generate water ponds, stone deposits, and tree resources
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:43:47 +00:00
root b3a9197aec feat(industry): add inventory helper functions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:41:18 +00:00
root 25546b5f44 feat(industry): add ItemRegistry with seed resources
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:41:03 +00:00
root 4f48c65fe3 feat(config): add industry config for gathering and map generation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:40:33 +00:00
root ce2caa4ae1 fix(memory): use auto-incrementing id as tick proxy for recency scoring
Events recorded with tick: 0 now get a meaningful tick value from the
service's internal counter, ensuring selectForPrompt recency scoring
works correctly. Also fixed preferTypes to accept readonly arrays.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:09:01 +00:00
root cb59636cd9 feat(memory): add shared history context to social narration prompts
When narrating social interactions, the LLM now receives up to 3 shared
history events between the two NPCs, enabling more contextual narrations
that reference past encounters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:04:52 +00:00
root 1db8935de3 feat(memory): integrate event memory into thought generation context
Replace the simple last-2-narration-events approach with smart selection
of up to 5 memory events, preferring types relevant to the thought trigger
(social events for post-interaction, need events for need-critical).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 22:04:46 +00:00