407 Commits

Author SHA1 Message Date
root
a84b93bfd3 feat: gatheringSystem uses carry capacity for dropoff decision
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:52:15 +00:00
root
18b011fbf5 fix: preserve dropoff goal in npcBrainSystem and add carry capacity priority
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:50:48 +00:00
root
a9c1cd55d6 feat: add getCarryCapacity stat helper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:49:29 +00:00
root
1bfb9c581c feat: add getTotalItemCount inventory helper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:48:46 +00:00
root
7a15a3257a docs: carry capacity and dropoff implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:47:27 +00:00
root
d66db04832 docs: carry capacity and dropoff priority design
NPCs never drop off gathered resources due to missing continue
statement in npcBrainSystem. Design adds strength-based carry
capacity and fixes dropoff goal priority.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 21:46:10 +00:00
root
219f02d7d6 test: add integration test for stat-driven invention prompt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:37:25 +00:00
root
36fdf1b3c1 fix: prevent race condition with global pendingItemIds set
Two NPCs could invent the same item if both LLM requests
returned before either registered. The pendingItemIds set
blocks the second registration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:36:02 +00:00
root
0851cea047 feat: track token usage from OpenRouter API responses
Captures prompt_tokens and completion_tokens from API response.
Stores in 100-entry ring buffer, logs per-call summary. Adds
tokenUsage() accessor to LlmService interface.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:33:16 +00:00
root
6a3f9dd614 feat: stat-driven invention selection via revised LLM prompt
Prompt now includes full 10-stat block with readable names and
scale context. Instructs LLM to consider 3 ideas and pick the
best match for the NPC's personality. Known items list includes
both seed and invented items for better duplicate prevention.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:29:04 +00:00
root
b8b2a870fa feat: parse reasoning field from invention LLM response
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:26:56 +00:00
root
28cd79a5c7 fix: re-register inventions into registries on save load
Inventions loaded from DB were only added to the timeline, not
the item/recipe registries. This allowed duplicate inventions
after server restarts since the validation check was empty.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:21:32 +00:00
root
31d45338ec docs: add invention refinements implementation plan
8 tasks covering: load-time re-registration fix, reasoning field
parsing, revised LLM prompt, full stat passthrough, token usage
tracking, race condition guard, and integration tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:18:26 +00:00
root
bc0e1154b5 docs: add invention system refinements design
Covers duplicate fix (load bug), name normalization, stat-driven
invention selection, race condition guard, and token usage tracking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:15:34 +00:00
root
45ecad89bb fix: store tooltip cleanup functions and call on destroy
Prevents orphaned tooltip divs when panels are torn down while
a tooltip is visible.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:31:58 +00:00
root
3ae0d55f72 fix: prevent orphaned tooltip divs on rapid mouse re-entry
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:29:15 +00:00
root
ad80d63763 feat: add hover tooltips to NPC info panel tabs and stat abbreviations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:28:30 +00:00
root
57be76443c feat: add hover tooltips to left panel tabs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:27:28 +00:00
root
9165758e67 feat: add tooltip utility for hover labels
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:26:38 +00:00
root
fe7bc56c28 docs: add tooltip hover implementation plan
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:24:17 +00:00
root
e9d8e5f533 docs: add tooltip hover design for UI abbreviations
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 19:23:17 +00:00
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
c0e015e6e5 fix(client): resolve three TypeScript type errors
Add missing Vite client type declarations, fix canvas-to-HTMLImageElement
cast in CharacterCompositor, and use proper Stats/StatName types in
NpcInfoPanel instead of loose Record<string, number>.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:23:48 +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
afbf85d7ff feat(client): improve day/night cycle and add time indicator
Fix vertical line artifacts in nighttime overlay by using a single
rectangle for full night and a base+sweep approach for transitions.
Increase night darkness from 0.3 to 0.45 for more distinct nighttime.
Add a time indicator bar at top-center showing day/night progress
with sun/moon icons matching the EarthBound-inspired UI style.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:19:05 +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
4c24a016f1 docs: update CLAUDE.md with world persistence documentation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 15:21:11 +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