fix: emit desire_fulfilled events, populate LLM context, fix category scoring

- desireFulfillmentSystem records memory events when desires are fulfilled
- desireGeneratorSystem populates recentEvents and recentInventions template vars
- industrySystem own_item_category scoring now checks recipe output category

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-10 00:14:35 +00:00
parent 7a16872bb9
commit a8f27a869d
4 changed files with 46 additions and 11 deletions
+17 -1
View File
@@ -1,6 +1,8 @@
import type { EntityId, Desire, Stats } from '@dflike/shared';
import type { World } from '../ecs/World.js';
import type { LlmService } from '../llm/llmService.js';
import type { EventMemoryService } from '../llm/eventMemoryService.js';
import type { InventionTimeline } from '../industry/inventionTimeline.js';
import { desireConfig } from '../config/desireConfig.js';
import { getEffectiveStat } from './statHelpers.js';
import { formatStatsForPrompt, getWorldContext, validateDesire } from '../llm/backstoryGenerator.js';
@@ -10,7 +12,10 @@ export interface DesireGeneratorSystem {
triggerEvent(world: World, entityId: number, trigger: string, tick: number): void;
}
export function createDesireGeneratorSystem(llmService: LlmService): DesireGeneratorSystem {
export function createDesireGeneratorSystem(
llmService: LlmService,
eventMemoryService?: EventMemoryService,
): DesireGeneratorSystem {
const pendingEntities = new Set<EntityId>();
function canAddDesire(world: World, entityId: number): boolean {
@@ -38,11 +43,22 @@ export function createDesireGeneratorSystem(llmService: LlmService): DesireGener
const context = getWorldContext(world);
const currentDesireList = currentDesires.map(d => d.description).join('; ') || 'none';
const recentEvents = eventMemoryService
? eventMemoryService.getRecentEvents(entityId, 5).map(e => e.detail).join('; ')
: '';
const timeline = world.getSingleton<InventionTimeline>('inventionTimeline');
const recentInventions = timeline
? timeline.getSummaries().slice(-5).map(s => s.name).join(', ')
: '';
const variables: Record<string, string> = {
npcName: name,
stats: formatStatsForPrompt(stats),
backstory,
currentDesires: currentDesireList,
recentEvents: recentEvents || 'none',
recentInventions: recentInventions || 'none',
resourceTypes: context.resourceTypes,
recipeList: context.recipeList,
structureList: context.structureList,