@sharpee/world-model 0.9.105 → 0.9.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Character model trait (ADR-141)
3
+ *
4
+ * Rich internal state for NPCs: personality, disposition, mood, threat,
5
+ * cognitive profile, knowledge, beliefs, and goals. Opt-in — only NPCs
6
+ * that need behavioral depth carry this trait alongside NpcTrait.
7
+ *
8
+ * Public interface: ICharacterModelData, CharacterModelTrait, CharacterPredicate.
9
+ * Owner context: world-model / character-model trait
10
+ */
11
+ import { ITrait } from '../trait';
12
+ import { PersonalityTrait, PersonalityExpr, DispositionWord, Mood, ThreatLevel, CognitiveProfile, ConfidenceWord, Fact, FactSource, Belief, ResistanceMode, Goal, LucidityConfig, PerceptionFilterConfig, PerceivedEvent } from './character-vocabulary';
13
+ /** Serializable data for constructing a CharacterModelTrait. */
14
+ export interface ICharacterModelData {
15
+ /** Personality traits with intensity values (0-1). */
16
+ personality?: Record<PersonalityTrait, number>;
17
+ /** Disposition toward specific entities (numeric, -100 to 100). */
18
+ dispositions?: Record<string, number>;
19
+ /** Current mood (valence-arousal stored internally). */
20
+ mood?: Mood;
21
+ moodValence?: number;
22
+ moodArousal?: number;
23
+ /** Current threat level (numeric, 0-100). */
24
+ threat?: ThreatLevel;
25
+ threatValue?: number;
26
+ /** Five-dimensional cognitive profile. */
27
+ cognitiveProfile?: Partial<CognitiveProfile>;
28
+ /** Knowledge base: topic -> fact. */
29
+ knowledge?: Record<string, Fact>;
30
+ /** Beliefs: topic -> belief. */
31
+ beliefs?: Record<string, Belief>;
32
+ /** Goals ordered by priority. */
33
+ goals?: Goal[];
34
+ /** Lucidity window configuration. */
35
+ lucidityConfig?: LucidityConfig;
36
+ /** Current lucidity state name (e.g., 'lucid', 'hallucinating', baseline). */
37
+ currentLucidityState?: string;
38
+ /** Turns remaining in current lucidity window. -1 = no active window. */
39
+ lucidityWindowTurns?: number;
40
+ /** Perception filter configuration. */
41
+ perceptionFilters?: PerceptionFilterConfig;
42
+ /** Hallucinated perceived events. */
43
+ perceivedEvents?: Record<string, PerceivedEvent>;
44
+ }
45
+ /** A predicate function that evaluates character state. */
46
+ export type CharacterPredicate = (trait: CharacterModelTrait) => boolean;
47
+ /**
48
+ * CharacterModelTrait — rich internal state for NPCs.
49
+ *
50
+ * All state is stored as plain properties so JSON serialization survives.
51
+ * Predicate functions are registered at runtime and live in a transient map
52
+ * that is rebuilt after deserialization by the builder or story setup code.
53
+ */
54
+ export declare class CharacterModelTrait implements ITrait {
55
+ static readonly type: "characterModel";
56
+ readonly type: "characterModel";
57
+ personality: Record<string, number>;
58
+ dispositions: Record<string, number>;
59
+ moodValence: number;
60
+ moodArousal: number;
61
+ threatValue: number;
62
+ cognitiveProfile: CognitiveProfile;
63
+ knowledge: Record<string, Fact>;
64
+ beliefs: Record<string, Belief>;
65
+ goals: Goal[];
66
+ lucidityConfig?: LucidityConfig;
67
+ currentLucidityState: string;
68
+ lucidityWindowTurns: number;
69
+ perceptionFilters?: PerceptionFilterConfig;
70
+ perceivedEvents: Record<string, PerceivedEvent>;
71
+ private predicates;
72
+ constructor(data?: ICharacterModelData);
73
+ /**
74
+ * Set personality from expression array. Typically called once at creation.
75
+ *
76
+ * @param exprs - Personality expressions like 'very honest', 'cowardly'
77
+ */
78
+ setPersonality(...exprs: PersonalityExpr[]): void;
79
+ /**
80
+ * Get the intensity value for a personality trait.
81
+ *
82
+ * @param trait - The personality trait to query
83
+ * @returns The intensity value (0-1), or 0 if the trait is not set
84
+ */
85
+ getPersonality(trait: PersonalityTrait): number;
86
+ /**
87
+ * Set disposition toward an entity using a word.
88
+ *
89
+ * @param entityId - The entity this disposition is directed at
90
+ * @param word - A disposition word like 'trusts' or 'wary of'
91
+ */
92
+ setDisposition(entityId: string, word: DispositionWord): void;
93
+ /**
94
+ * Adjust disposition toward an entity by a numeric delta.
95
+ * Clamps to -100..100.
96
+ *
97
+ * @param entityId - The entity to adjust disposition for
98
+ * @param delta - Amount to add (positive = warmer, negative = colder)
99
+ */
100
+ adjustDisposition(entityId: string, delta: number): void;
101
+ /**
102
+ * Get the numeric disposition value toward an entity.
103
+ *
104
+ * @param entityId - The entity to query
105
+ * @returns Numeric disposition (-100 to 100), defaults to 0 (neutral)
106
+ */
107
+ getDispositionValue(entityId: string): number;
108
+ /**
109
+ * Get the disposition word toward an entity.
110
+ *
111
+ * @param entityId - The entity to query
112
+ * @returns The disposition word
113
+ */
114
+ getDispositionWord(entityId: string): DispositionWord;
115
+ /**
116
+ * Set mood by word. Translates to internal valence-arousal axes.
117
+ *
118
+ * @param word - A mood word like 'nervous' or 'cheerful'
119
+ */
120
+ setMood(word: Mood): void;
121
+ /**
122
+ * Adjust mood axes by deltas. Clamps valence to -1..1 and arousal to 0..1.
123
+ *
124
+ * @param valenceDelta - Change in valence
125
+ * @param arousalDelta - Change in arousal
126
+ */
127
+ adjustMood(valenceDelta: number, arousalDelta: number): void;
128
+ /**
129
+ * Get the current mood as a word (nearest match to valence-arousal position).
130
+ *
131
+ * @returns The mood word
132
+ */
133
+ getMood(): Mood;
134
+ /**
135
+ * Set threat level by word.
136
+ *
137
+ * @param level - A threat level word
138
+ */
139
+ setThreat(level: ThreatLevel): void;
140
+ /**
141
+ * Adjust threat level by a numeric delta. Clamps to 0..100.
142
+ *
143
+ * @param delta - Amount to add (positive = more threatened)
144
+ */
145
+ adjustThreat(delta: number): void;
146
+ /**
147
+ * Get the current threat level as a word.
148
+ *
149
+ * @returns The threat level word
150
+ */
151
+ getThreat(): ThreatLevel;
152
+ /**
153
+ * Add or update a fact in the NPC's knowledge base.
154
+ *
155
+ * @param topic - The topic this fact is about
156
+ * @param source - How the NPC learned this fact
157
+ * @param confidence - How confident the NPC is
158
+ * @param turn - The turn number when the fact was learned
159
+ */
160
+ addFact(topic: string, source: FactSource, confidence: ConfidenceWord, turn: number): void;
161
+ /**
162
+ * Check whether the NPC knows about a topic.
163
+ *
164
+ * @param topic - The topic to check
165
+ * @returns True if the NPC has any fact about this topic
166
+ */
167
+ knows(topic: string): boolean;
168
+ /**
169
+ * Get a fact from the knowledge base.
170
+ *
171
+ * @param topic - The topic to query
172
+ * @returns The fact, or undefined if unknown
173
+ */
174
+ getFact(topic: string): Fact | undefined;
175
+ /**
176
+ * Add or update a belief.
177
+ *
178
+ * @param topic - What the belief is about
179
+ * @param strength - How strongly held
180
+ * @param resistance - How resistant to counter-evidence
181
+ */
182
+ addBelief(topic: string, strength: ConfidenceWord, resistance?: ResistanceMode): void;
183
+ /**
184
+ * Check whether the NPC holds a belief about a topic.
185
+ *
186
+ * @param topic - The topic to check
187
+ * @returns True if the NPC has a belief about this topic
188
+ */
189
+ hasBelief(topic: string): boolean;
190
+ /**
191
+ * Get a belief.
192
+ *
193
+ * @param topic - The topic to query
194
+ * @returns The belief, or undefined
195
+ */
196
+ getBelief(topic: string): Belief | undefined;
197
+ /**
198
+ * Add a goal with priority. Higher priority = more important.
199
+ *
200
+ * @param id - Goal identifier
201
+ * @param priority - Numeric priority (higher = more important)
202
+ */
203
+ addGoal(id: string, priority: number): void;
204
+ /**
205
+ * Remove a goal by id.
206
+ *
207
+ * @param id - Goal identifier to remove
208
+ */
209
+ removeGoal(id: string): void;
210
+ /**
211
+ * Get the highest-priority goal, or undefined if none.
212
+ *
213
+ * @returns The top goal, or undefined
214
+ */
215
+ getTopGoal(): Goal | undefined;
216
+ /**
217
+ * Check whether the NPC has a specific goal.
218
+ *
219
+ * @param id - Goal identifier to check
220
+ * @returns True if the goal exists
221
+ */
222
+ hasGoal(id: string): boolean;
223
+ /**
224
+ * Update the priority of an existing goal.
225
+ *
226
+ * @param id - Goal identifier
227
+ * @param priority - New priority value
228
+ */
229
+ updateGoalPriority(id: string, priority: number): void;
230
+ /**
231
+ * Transition to a new lucidity state.
232
+ *
233
+ * @param state - The target lucidity state name
234
+ * @param windowTurns - How many turns this window lasts (-1 = indefinite)
235
+ */
236
+ enterLucidityState(state: string, windowTurns?: number): void;
237
+ /**
238
+ * Decay the lucidity window by one turn. Returns to baseline when expired.
239
+ *
240
+ * @returns True if the window expired and baseline was restored
241
+ */
242
+ decayLucidity(): boolean;
243
+ /**
244
+ * Register a named predicate function.
245
+ *
246
+ * @param name - Predicate name (e.g., 'trusts player', 'threatened')
247
+ * @param fn - Function that evaluates against this trait's state
248
+ */
249
+ registerPredicate(name: string, fn: CharacterPredicate): void;
250
+ /**
251
+ * Evaluate a named predicate against current state.
252
+ * Supports 'not X' negation.
253
+ *
254
+ * @param predicate - The predicate name to evaluate
255
+ * @returns True if the predicate is satisfied
256
+ * @throws Error if the predicate is not registered
257
+ */
258
+ evaluate(predicate: string): boolean;
259
+ /**
260
+ * Check if a predicate is registered.
261
+ *
262
+ * @param name - Predicate name
263
+ * @returns True if registered
264
+ */
265
+ hasPredicate(name: string): boolean;
266
+ /** Register all built-in predicates defined by ADR-141. */
267
+ private registerPlatformPredicates;
268
+ }
269
+ //# sourceMappingURL=characterModelTrait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"characterModelTrait.d.ts","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/world-model/src/traits/character-model/characterModelTrait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,gBAAgB,EAChB,eAAe,EAEf,eAAe,EAGf,IAAI,EAGJ,WAAW,EAGX,gBAAgB,EAEhB,cAAc,EACd,IAAI,EACJ,UAAU,EACV,MAAM,EACN,cAAc,EACd,IAAI,EACJ,cAAc,EACd,sBAAsB,EACtB,cAAc,EACf,MAAM,wBAAwB,CAAC;AAMhC,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAE/C,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MA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