Commit Graph

177 Commits

Author SHA1 Message Date
root 1f5cafe2fd feat(memory): add EventMemoryService with smart selection and tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:52:46 +00:00
root ba487839fd feat(memory): add MemoryEvent types and socket events to shared
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:50:08 +00:00
root 48332b104c docs: add NPC event memory implementation plan (task 2.1)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:46:48 +00:00
root 7f2097be0e docs: add NPC event memory system design (task 2.1)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:41:31 +00:00
root 35d1bb0bee fix: update socialSystem tests to match new tuning values
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:19:16 +00:00
root d58e623c14 tweak: reduce stat drift rates and increase social cooldowns
- Halve sociability/empathy drift on positive outcome (0.05 -> 0.025)
- Halve temperament drift on negative outcome (0.02 -> 0.01)
- Increase social global cooldown (50 -> 75 ticks)
- Increase social pair cooldown (300 -> 450 ticks)
- Increase base proposal cooldown (500 -> 750)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:18:03 +00:00
root eb79c5e481 fix(thought): add missing trigger types and prevent emoji overlap
- determineTrigger now detects post_interaction (recent social outcome),
  need_critical, idle (wandering), and periodic triggers
- Track active emoji per NPC, destroy previous before showing new one

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:16:24 +00:00
root 22956c2050 docs: mark task 1.4 (NPC inner monologue) as complete
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:12:51 +00:00
root daddf2583d feat(thought): wire client socket, GameScene thought handling, emoji animation, and info panel display
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:12:00 +00:00
root b515f7195f feat(thought): integrate ThoughtSystem into game loop and socket broadcast
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:10:00 +00:00
root fb19f6cf8d feat(thought): add ThoughtSystem with batching, cooldowns, and trigger detection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:08:30 +00:00
root 4e5edda6c6 feat(thought): add mood-contextual emoji picker
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:05:55 +00:00
root a16d70a1b8 feat(thought): add batched thought generator with LLM prompt and parser
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:04:46 +00:00
root e33a253c5b feat(thought): add thought config and npc-thought socket event type
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:02:50 +00:00
root e17f8c7655 docs: add NPC inner monologue implementation plan (task 1.4)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 20:57:27 +00:00
root b151d8a785 docs: add NPC inner monologue design (task 1.4)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 20:53:51 +00:00
root 69c36e776b docs: add resource, tool & invention system design
Design for LLM-driven emergent crafting and invention system.
NPCs gather resources from terrain, craft at workshops, and
occasionally have eureka moments where an LLM invents new items.
Updates LLM roadmap: this becomes item 2.2, old goal selection
splits into 2.5 (POI naming).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 20:37:20 +00:00
root 87946bcb5c feat: add social interaction narration system (task 1.3)
Implements LLM-powered narration for NPC social interactions:
- Rate limits updated to 20 RPM / 1000 per day (OpenRouter free tier)
- NarrationEvent type with template fallback text generator
- NarrationService with rolling event buffer and LLM priority queuing
- Narration emitter wired between social and relationship systems
- Socket.io events for real-time narration delivery
- Tabbed left panel (Stats + Events) replacing old Superlatives panel
- Recent events section in NPC info panel
- Follow tracking via socket for LLM narration priority

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 19:29:43 +00:00
root 94e4f4b9c2 fix: restore superlatives methods, fix event update rebuild, remove dead method
- Restore subscribeSuperlatives/unsubscribeSuperlatives/onSuperlativesUpdate
  on SocketClient (lost during Task 5 refactor)
- Fix EventsFeed.updateEvent to rebuild entire element when LLM narration
  arrives (names may be in different positions)
- Remove dead setFollowedEntity method from GameLoop (replaced by
  SocketServer.rebuildFollowedEntityIds)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:38:06 +00:00
root 6514dde42e feat: track followed NPCs via socket for LLM narration priority
Adds follow-npc client event so the server knows which NPCs are being
watched, enabling priority LLM narration for followed entity interactions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:25:16 +00:00
root e8723f0a06 feat: add recent narration events to NPC info panel
Show the last 3 narration events involving the followed NPC in the
Status tab, between the activity label and the diamond separator.
Events update live when new narrations arrive or LLM text replaces
template text.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:22:48 +00:00
root 554b5a6f30 feat: refactor left panel into tabbed container with Stats + Events tabs
Extract SuperlativesPanel into content-only component, create LeftPanel
as the outer shell with two tabs (S for Stats, E for Events), and add
EventsFeed component for displaying narration events with clickable
NPC names and auto-scroll behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:19:20 +00:00
root 57695043f2 feat: add socket.io events for narration broadcast
Wire narration events through the socket layer so clients receive
real-time narration updates. Server emits narration-event on creation,
narration-update when LLM text arrives, and narration-history on connect.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:14:50 +00:00
root 78c8dbfb7f fix: use shared formatStatsForPrompt from backstoryGenerator
Removes duplicated local version that had different format.
Also brings backstoryGenerator.ts into the worktree from main.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:13:23 +00:00
root 541b70b781 feat: wire narration emitter into social system and GameLoop
Add narrationEmitter system that reads completed interactions from
socialState.lastOutcome and feeds them to the NarrationService. It runs
between socialSystem and relationshipSystem to capture outcomes before
they are cleared. Includes pair deduplication, proposal detection,
priority marking for followed NPCs and high-value relationships, and
personality formatting for LLM prompts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:02:59 +00:00
root afc8329a82 fix: add catch handler for LLM generation promise in narration service
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 18:00:08 +00:00
root 4bcf90d7c5 feat: add NarrationService with event buffer, LLM priority, and template fallback
Implements NarrationService that manages a rolling buffer of 50 narration events,
generates immediate template fallback text, and queues LLM generation for priority
interactions and proposals (respecting daily limits).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:57:03 +00:00
root 865054facc feat: add NarrationEvent type and template fallback narration generator
Define NarrationEvent and NarrationOutcome types in shared package for
social interaction narration. Add generateFallbackNarration() with
randomized templates for each outcome type (positive, negative,
proposal_accepted, proposal_rejected) to provide immediate text when
LLM narration is unavailable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:52:23 +00:00
root 6a8ffc26a1 fix: don't count failed API calls against daily rate limit
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:50:50 +00:00
root 1de6178c50 feat(llm): update rate limits to match OpenRouter free tier and add daily limit
Raise requestsPerMinute from 10 to 20 and add requestsPerDay (1000) to
match OpenRouter free-tier limits. The generation queue now tracks daily
usage and resets at midnight, resolving requests with null once the cap
is hit. Both GenerationQueue and LlmService expose isDailyLimitReached().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:48:34 +00:00
root 5ccb708d80 docs: add social narration implementation plan (task 1.3)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:44:11 +00:00
root 6c51fb622b docs: add social interaction narration design (task 1.3)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:40:54 +00:00
root 37b9390c64 style: shrink NPC info panel fonts and center command panel
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:21:57 +00:00
root 29417c7818 feat: add dotenv for server environment variable loading
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:15:25 +00:00
root 6f459fa88a feat: add trunk decorations, resize superlatives panel, add LLM plan docs
- Add trunk decoration layer to GameMap and mapGenerator
- Load trunk.png asset in BootScene
- Increase superlatives panel size and font sizes for readability
- Simplify mapGenerator (remove procedural terrain features)
- Add LLM integration planning documents
- Remove stale day-night cycle worktree plans
- Update local Claude settings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 17:09:19 +00:00
root baeaafd372 feat: display backstory in NPC info panel with fade-in transition
Add backstory element to the Status tab between the activity label and
diamond separator. When a backstory arrives from the LLM, it fades in
with italic styling. Empty backstories remain hidden.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:54:56 +00:00
root 8c793578ae feat: wire backstory generation into NPC spawn flow
Trigger fire-and-forget backstory generation whenever an NPC spawns,
both during initial spawn and via player spawn-npc requests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:52:13 +00:00
root aa3f5651dd feat: add backstory generation helper for NPC LLM backstories
Adds formatStatsForPrompt to convert Stats into prompt-friendly abbreviations
and generateBackstory to call the LLM service with the backstory template,
writing the result back to the entity's backstory component.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:49:32 +00:00
root 180f056570 feat: add backstory component to spawner and serializer
Initialize empty backstory on NPC spawn, serialize it for broadcast,
and add test coverage for the new component.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:44:23 +00:00
root 0b028c2cec feat: add backstory field to EntityState shared type
Add optional backstory string to EntityState for NPC backstory generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:44:19 +00:00
root 28a0117b49 Merge branch 'worktree-llm-integration' 2026-03-08 16:32:51 +00:00
root 138029e2a9 docs(llm): add .env.example and gitignore .env files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:30:59 +00:00
root 3a86e09e39 feat(llm): wire LLM service into GameLoop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:30:32 +00:00
root b8a5032be6 feat(llm): add LLM service facade and prompt templates
Combines config, OpenRouter client, generation queue, and template
rendering into a simple generate(templateName, variables) API. When
disabled (no API key), returns a no-op implementation. Includes
backstory, socialNarration, and innerMonologue prompt templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:28:14 +00:00
root e9409f6e82 feat(llm): add rate-limited generation queue
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:26:32 +00:00
root cf403250e0 feat(llm): add OpenRouter API client with error handling and timeout
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:23:23 +00:00
root 5f5bf24d64 feat: add prompt template system for LLM variable substitution
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:17:56 +00:00
root 98ec288caf feat: add LLM config module for OpenRouter API settings
Reads API key and model from environment variables. LLM is disabled by
default and auto-enables when OPENROUTER_API_KEY is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 16:15:10 +00:00
root 80ce9d1367 feat: integrate superlatives panel into GameScene with follow mode
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 04:48:42 +00:00
root 4fe41b7cf0 feat: add SuperlativesPanel UI component
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 04:47:22 +00:00