@mindot/will 0.1.0

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.
Files changed (178) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +777 -0
  3. package/dist/index.d.ts +8144 -0
  4. package/dist/index.js +26231 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +73 -0
  7. package/src/cognition/agency/access.grants.ts +59 -0
  8. package/src/cognition/agency/competence.codec.ts +89 -0
  9. package/src/cognition/agency/engines/action.selector.ts +462 -0
  10. package/src/cognition/agency/engines/affordance.synthesizer.ts +384 -0
  11. package/src/cognition/agency/engines/deliberation.engine.ts +241 -0
  12. package/src/cognition/agency/engines/instruction.intake.ts +54 -0
  13. package/src/cognition/agency/engines/motor.schema.executor.ts +532 -0
  14. package/src/cognition/agency/engines/reafference.engine.ts +241 -0
  15. package/src/cognition/agency/execution.primitives.ts +118 -0
  16. package/src/cognition/agency/index.ts +58 -0
  17. package/src/cognition/agency/proactive.communicator.ts +274 -0
  18. package/src/cognition/agency/reconcile.learning.ts +82 -0
  19. package/src/cognition/agency/schemas/external.ts +59 -0
  20. package/src/cognition/agency/schemas/innate.ts +111 -0
  21. package/src/cognition/agency/schemas/repertoire.ts +246 -0
  22. package/src/cognition/agency/selection.scoring.ts +191 -0
  23. package/src/cognition/agency/types.ts +165 -0
  24. package/src/cognition/bus.ts +391 -0
  25. package/src/cognition/completion.inbox.ts +86 -0
  26. package/src/cognition/config.mirror.entities.ts +475 -0
  27. package/src/cognition/conversation.memory.ts +81 -0
  28. package/src/cognition/event.log.ts +116 -0
  29. package/src/cognition/event.schemas.ts +568 -0
  30. package/src/cognition/faculties/aesthetic.evaluator.ts +313 -0
  31. package/src/cognition/faculties/affective.blender.ts +562 -0
  32. package/src/cognition/faculties/attachment.evaluator.ts +432 -0
  33. package/src/cognition/faculties/attention.allocator.ts +422 -0
  34. package/src/cognition/faculties/autobiographical.narrator.ts +300 -0
  35. package/src/cognition/faculties/bias.detector.ts +363 -0
  36. package/src/cognition/faculties/circadian.oscillator.ts +294 -0
  37. package/src/cognition/faculties/confidence.calibrator.ts +324 -0
  38. package/src/cognition/faculties/dream.simulator.ts +251 -0
  39. package/src/cognition/faculties/empathy.simulator.ts +253 -0
  40. package/src/cognition/faculties/energy.regulator.ts +320 -0
  41. package/src/cognition/faculties/episodic.consolidator.ts +728 -0
  42. package/src/cognition/faculties/executive.engine/commands.ts +459 -0
  43. package/src/cognition/faculties/executive.engine/config.ts +46 -0
  44. package/src/cognition/faculties/executive.engine/context.ts +605 -0
  45. package/src/cognition/faculties/executive.engine/deferred.effects.ts +104 -0
  46. package/src/cognition/faculties/executive.engine/deliberate.reasoning.ts +60 -0
  47. package/src/cognition/faculties/executive.engine/effort.gate.ts +114 -0
  48. package/src/cognition/faculties/executive.engine/engine.ts +1028 -0
  49. package/src/cognition/faculties/executive.engine/escalation.buffer.ts +90 -0
  50. package/src/cognition/faculties/executive.engine/facet.supervisor.ts +271 -0
  51. package/src/cognition/faculties/executive.engine/facet.ts +628 -0
  52. package/src/cognition/faculties/executive.engine/gating.ts +222 -0
  53. package/src/cognition/faculties/executive.engine/index.ts +6 -0
  54. package/src/cognition/faculties/executive.engine/messages.ts +102 -0
  55. package/src/cognition/faculties/executive.engine/parser.ts +380 -0
  56. package/src/cognition/faculties/executive.engine/prompt.factory.ts +1053 -0
  57. package/src/cognition/faculties/executive.engine/types.ts +323 -0
  58. package/src/cognition/faculties/exteroception.ts +338 -0
  59. package/src/cognition/faculties/forgetting.curve.ts +202 -0
  60. package/src/cognition/faculties/frustration.evaluator.ts +280 -0
  61. package/src/cognition/faculties/goal.manager.ts +1008 -0
  62. package/src/cognition/faculties/inhibition.controller.ts +351 -0
  63. package/src/cognition/faculties/interoception.ts +417 -0
  64. package/src/cognition/faculties/introspection.engine.ts +246 -0
  65. package/src/cognition/faculties/known.entity.tracker.ts +439 -0
  66. package/src/cognition/faculties/loss.evaluator.ts +224 -0
  67. package/src/cognition/faculties/moral.evaluator.ts +437 -0
  68. package/src/cognition/faculties/novelty.detector.ts +254 -0
  69. package/src/cognition/faculties/persona.consolidator.ts +845 -0
  70. package/src/cognition/faculties/planning.engine/engine.ts +859 -0
  71. package/src/cognition/faculties/planning.engine/plan.frontier.ts +83 -0
  72. package/src/cognition/faculties/planning.engine/plan.store.ts +174 -0
  73. package/src/cognition/faculties/planning.engine/plan.supervision.ts +494 -0
  74. package/src/cognition/faculties/planning.engine/types.ts +143 -0
  75. package/src/cognition/faculties/reputation.tracker.ts +294 -0
  76. package/src/cognition/faculties/reward.evaluator.ts +304 -0
  77. package/src/cognition/faculties/self.model.updater.ts +677 -0
  78. package/src/cognition/faculties/semantic.engine/clustering.ts +673 -0
  79. package/src/cognition/faculties/semantic.engine/index.ts +6 -0
  80. package/src/cognition/faculties/semantic.engine/integrator.ts +750 -0
  81. package/src/cognition/faculties/semantic.engine/types.ts +53 -0
  82. package/src/cognition/faculties/sleep.pressure.regulator.ts +262 -0
  83. package/src/cognition/faculties/social.perception.ts +333 -0
  84. package/src/cognition/faculties/spaced.repetition.ts +605 -0
  85. package/src/cognition/faculties/stress.regulator.ts +375 -0
  86. package/src/cognition/faculties/task.switcher.ts +239 -0
  87. package/src/cognition/faculties/theory.of.mind.ts +333 -0
  88. package/src/cognition/faculties/threat.evaluator.ts +312 -0
  89. package/src/cognition/faculties/working.memory.ts +406 -0
  90. package/src/cognition/generative.model.ts +344 -0
  91. package/src/cognition/heartbeat.ts +70 -0
  92. package/src/cognition/index.ts +291 -0
  93. package/src/cognition/instruction.handler.ts +146 -0
  94. package/src/cognition/memory/index.ts +35 -0
  95. package/src/cognition/memory/vector.adapter.ts +316 -0
  96. package/src/cognition/memory/vector.content.ts +47 -0
  97. package/src/cognition/memory/vector.embedder.ts +212 -0
  98. package/src/cognition/memory/vector.index.ts +459 -0
  99. package/src/cognition/memory/vector.types.ts +65 -0
  100. package/src/cognition/orchestrator.ts +142 -0
  101. package/src/cognition/persona.prior.ts +265 -0
  102. package/src/cognition/schema.registry.ts +145 -0
  103. package/src/cognition/senses/audition.engine/engine.ts +976 -0
  104. package/src/cognition/senses/audition.engine/salience.ts +59 -0
  105. package/src/cognition/senses/base.sense.engine.ts +117 -0
  106. package/src/cognition/senses/gustation.engine.ts +24 -0
  107. package/src/cognition/senses/index.ts +172 -0
  108. package/src/cognition/senses/olfaction.engine.ts +24 -0
  109. package/src/cognition/senses/somatosensation.engine.ts +23 -0
  110. package/src/cognition/senses/vision.engine.ts +23 -0
  111. package/src/cognition/types.ts +63 -0
  112. package/src/cognition/utilities/token.tracker.ts +492 -0
  113. package/src/core/abstracts.ts +60 -0
  114. package/src/core/async.engine.ts +539 -0
  115. package/src/core/clock.ts +196 -0
  116. package/src/core/completion.recorder.ts +122 -0
  117. package/src/core/conflict.detector.ts +140 -0
  118. package/src/core/distributed.ts +626 -0
  119. package/src/core/event.bus.ts +292 -0
  120. package/src/core/inbound.recorder.ts +100 -0
  121. package/src/core/index.ts +167 -0
  122. package/src/core/logger.ts +85 -0
  123. package/src/core/metrics.ts +107 -0
  124. package/src/core/orchestrator.ts +625 -0
  125. package/src/core/replay.ts +589 -0
  126. package/src/core/scenario.ts +120 -0
  127. package/src/core/serialization.ts +448 -0
  128. package/src/core/simulation.ts +197 -0
  129. package/src/core/snapshot.manager.ts +293 -0
  130. package/src/core/state.manager.ts +283 -0
  131. package/src/core/types.ts +274 -0
  132. package/src/core/utils.ts +82 -0
  133. package/src/core/wall.clock.ts +23 -0
  134. package/src/extensions/livestream.ext.ts +570 -0
  135. package/src/extensions/time.ext.ts +339 -0
  136. package/src/index.ts +91 -0
  137. package/src/llm/gate.ts +140 -0
  138. package/src/llm/index.ts +716 -0
  139. package/src/llm/summarizer.ts +170 -0
  140. package/src/llm/wire.contracts.ts +67 -0
  141. package/src/pma/eval.ts +651 -0
  142. package/src/pma/index.ts +1082 -0
  143. package/src/profiles/built-in.ts +7 -0
  144. package/src/profiles/companion.ts +28 -0
  145. package/src/profiles/company-brain.ts +54 -0
  146. package/src/profiles/customer-service.ts +30 -0
  147. package/src/profiles/game-npc.ts +20 -0
  148. package/src/profiles/index.ts +42 -0
  149. package/src/profiles/smart-home.ts +34 -0
  150. package/src/runners/coherence.runner.ts +49 -0
  151. package/src/runners/outreach.runner.ts +158 -0
  152. package/src/runners/social.runner.ts +182 -0
  153. package/src/runners/thin-shim.runner.ts +195 -0
  154. package/src/sdk/will.ts +334 -0
  155. package/src/stem/assembly.audit.ts +88 -0
  156. package/src/stem/distribution.ts +203 -0
  157. package/src/stem/guards/identity.coherence.ts +152 -0
  158. package/src/stem/guards/identity.guard.ts +227 -0
  159. package/src/stem/index.ts +1145 -0
  160. package/src/stem/mind.ts +1090 -0
  161. package/src/stem/tracts/ack.reconciler.ts +55 -0
  162. package/src/stem/tracts/biography.writer.ts +190 -0
  163. package/src/stem/tracts/effector.controller.ts +143 -0
  164. package/src/stem/tracts/health.reporter.ts +113 -0
  165. package/src/stem/tracts/inbound.queue.ts +54 -0
  166. package/src/stem/tracts/outbox.controller.ts +167 -0
  167. package/src/stem/tracts/outbox.writer.ts +133 -0
  168. package/src/stem/tracts/pma.controller.ts +109 -0
  169. package/src/stem/tracts/replay.controller.ts +177 -0
  170. package/src/stem/tracts/sensory.controller.ts +168 -0
  171. package/src/stem/tracts/session.logger.ts +157 -0
  172. package/src/stem/tracts/transport/index.ts +38 -0
  173. package/src/stem/tracts/transport/loopback.transport.ts +86 -0
  174. package/src/stem/tracts/transport/socketio.transport.ts +200 -0
  175. package/src/stem/tracts/transport/stream.transport.ts +152 -0
  176. package/src/stem/tracts/transport/types.ts +193 -0
  177. package/src/stem/tracts/transport.controller.ts +380 -0
  178. package/src/types.ts +116 -0
@@ -0,0 +1,351 @@
1
+ // ─────────────────────────────────────────────────────────────
2
+ // src/cognition/faculties/inhibition.controller.ts
3
+ // ─────────────────────────────────────────────────────────────
4
+
5
+ /**
6
+ * InhibitionController — suppresses prepotent responses and delays
7
+ * gratification.
8
+ *
9
+ * Functions as a somatic veto:
10
+ * - Monitors pending decision.record entities queued for execution
11
+ * - Evaluates them against affective state and long-term goals
12
+ * - Vetoes actions that are impulsive, risky, or misaligned
13
+ * - Implements gratification delay (can defer actions to future ticks)
14
+ *
15
+ * This engine is the "pause between impulse and action."
16
+ * It integrates with the Orchestrator's CommitValidator system
17
+ * to block commands before they're applied.
18
+ *
19
+ * Modulated by:
20
+ * - Stress (overload disinhibits — impulsive actions get through)
21
+ * - Sleep pressure (fatigue reduces inhibition)
22
+ * - Energy (low energy reduces inhibition capacity)
23
+ *
24
+ * Part of Shard 3 (Executive Layer) — runs every tick, synchronous.
25
+ */
26
+
27
+ import type {
28
+ Duration,
29
+ Tick,
30
+ SimulationContext,
31
+ ReadonlySimulationState,
32
+ StateCommands,
33
+ SimulationEvent,
34
+ } from '#core/types'
35
+ import type { SimulationEngine, EngineResult, CognitiveEngine } from '#cognition/types'
36
+ import type { CognitiveEventSchema } from '#cognition/schema.registry'
37
+ import type { CognitiveEvent, CognitiveBus } from '#cognition/bus'
38
+ import { GenerativeModel } from '#cognition/generative.model'
39
+ import { readEffectiveParams } from '#cognition/persona.prior'
40
+
41
+ export interface InhibitionControllerConfig {
42
+ /** Base inhibition strength (0-1, higher = more veto power) */
43
+ baseInhibitionStrength?: number
44
+ /** Threshold above which affective arousal triggers inhibition check */
45
+ arousalThreshold?: number
46
+ /** Maximum actions that can be deferred per tick */
47
+ maxDeferralsPerTick?: number
48
+ bus?: CognitiveBus
49
+ }
50
+
51
+ /** Communication effectors are never deferred — replies must be immediate. */
52
+ const COMMUNICATION_EFFECTORS = new Set([ 'talk', 'text', 'listen', 'gesture', 'broadcast' ])
53
+
54
+ interface DeferredAction {
55
+ actionType: string
56
+ metadata: Record<string, unknown> | undefined
57
+ deferredUntil: Tick
58
+ reason: string
59
+ }
60
+
61
+ export class InhibitionController implements SimulationEngine, CognitiveEngine {
62
+ readonly name = 'inhibition-controller'
63
+
64
+ private _baseInhibitionStrength: number
65
+ private _inhibitionStrength: number // effective value, scaled by cross-reads each tick
66
+ private _arousalThreshold: number
67
+ private _maxDeferralsPerTick: number
68
+
69
+ private _deferredActions: DeferredAction[] = []
70
+
71
+ private _energyLevel: number = 100
72
+ private _sleepPressure: number = 0
73
+ private _stressLoad: number = 0
74
+ private _executiveConfidence: number = 0.5
75
+
76
+ private _bus: CognitiveBus | null = null
77
+
78
+ private readonly _model = new GenerativeModel()
79
+
80
+
81
+ constructor( config: InhibitionControllerConfig = {} ){
82
+ this._bus = config.bus ?? null
83
+ this._baseInhibitionStrength = config.baseInhibitionStrength ?? 0.6
84
+ this._inhibitionStrength = this._baseInhibitionStrength
85
+ this._arousalThreshold = config.arousalThreshold ?? 0.6
86
+ this._maxDeferralsPerTick = config.maxDeferralsPerTick ?? 3
87
+ }
88
+ attachBus( bus: CognitiveBus ): void { this._bus = bus }
89
+
90
+ // ── Engine interface ─────────────────────────────────────
91
+
92
+ private _readConfigFromState( state: ReadonlySimulationState ): void {
93
+ // Effective config = base engine-config-inhibition ⊕ persona-prior (single-source).
94
+ // The persona-consolidator raises baseInhibitionStrength when reasoning bias
95
+ // recurs (edge 6) → more self-restraint while the bias is being worked through.
96
+ const p = readEffectiveParams( state, 'engine-config-inhibition' )
97
+ if( p.baseInhibitionStrength != null ) this._baseInhibitionStrength = p.baseInhibitionStrength
98
+ if( p.arousalThreshold != null ) this._arousalThreshold = p.arousalThreshold
99
+ if( p.maxDeferralsPerTick != null ) this._maxDeferralsPerTick = p.maxDeferralsPerTick
100
+
101
+ // Cross-read: longer executive gap → slightly relax inhibition (fewer cycles to course-correct)
102
+ const orbCfg = state.entities.get('engine-config-executive')
103
+ const orbInterval = ( orbCfg?.metadata?.params as Record<string, number> | undefined )?.executiveInterval
104
+ this._inhibitionStrength = orbInterval != null
105
+ ? this._baseInhibitionStrength * ( 30 / Math.max( 30, orbInterval ) )
106
+ : this._baseInhibitionStrength
107
+ }
108
+
109
+
110
+ subscribes(): string[] { return ["energy.state.changed","sleep.state.changed","stress.state.changed","executive.interpretation.formed","executive.prediction.formed"] }
111
+ publishes(): CognitiveEventSchema[] { return [] }
112
+
113
+ onCognitiveEvent( e: CognitiveEvent ): StateCommands | void {
114
+ this._model.observe( e.type, e.salience )
115
+ switch( e.type ){
116
+ case 'energy.state.changed':
117
+ this._energyLevel = (e.payload as Record<string,number>)['level'] ?? this._energyLevel
118
+ break
119
+ case 'sleep.state.changed':
120
+ this._sleepPressure = (e.payload as Record<string,number>)['pressure'] ?? this._sleepPressure
121
+ break
122
+ case 'stress.state.changed':
123
+ this._stressLoad = (e.payload as Record<string,number>)['load'] ?? this._stressLoad
124
+ break
125
+ case 'executive.interpretation.formed': {
126
+ // High executive confidence → relax veto (executive reasoned through it)
127
+ // Low confidence → tighten veto (more caution under uncertainty)
128
+ const confidence = (e.payload as Record<string,number>)['confidence'] ?? 0.5
129
+ this._executiveConfidence = confidence
130
+ break
131
+ }
132
+ case 'executive.prediction.formed': {
133
+ const p = e.payload as { predictedDomains: string[]; confidence: number }
134
+ if( p.predictedDomains.includes('executive') )
135
+ this._model.setPrecision( 'inhibition.strength', 1.0 + p.confidence * 0.5 )
136
+ break
137
+ }
138
+ }
139
+ }
140
+
141
+ snapshot(): Record<string, unknown> {
142
+ return {
143
+ energyLevel: this._energyLevel,
144
+ sleepPressure: this._sleepPressure,
145
+ stressLoad: this._stressLoad,
146
+ executiveConfidence: this._executiveConfidence,
147
+ }
148
+ }
149
+
150
+ async react(
151
+ _delta: Duration,
152
+ tick: Tick,
153
+ state: ReadonlySimulationState,
154
+ context: SimulationContext
155
+ ): Promise<EngineResult> {
156
+ this._readConfigFromState( state )
157
+
158
+ const
159
+ events: Array<Omit<SimulationEvent, 'id' | 'timestamp' | 'tick'>> = [],
160
+ commands: StateCommands = { metrics: [] }
161
+
162
+ // 1. Compute effective inhibition strength (modulated by state)
163
+ const inhibitionStrength = this._computeEffectiveInhibition( state )
164
+
165
+ // 2. Scan pending decision records for veto evaluation
166
+ const vetoedActions: string[] = []
167
+ const deferredActions: string[] = []
168
+
169
+ for( const entity of state.entities.values() ){
170
+ if( entity.type !== 'decision.record') continue
171
+
172
+ const
173
+ actionType = entity.metadata?.actionType as string,
174
+ confidence = ( entity.metadata?.confidence as number ) ?? 0.5,
175
+ arousal = state.metrics.get('affect.arousal') ?? 0.3,
176
+ valence = state.metrics.get('affect.valence') ?? 0
177
+
178
+ // Communication actions are never deferred — replies must be immediate
179
+ if( COMMUNICATION_EFFECTORS.has( actionType ) ) continue
180
+
181
+ // Veto check: low confidence + high arousal + negative valence
182
+ if( confidence < 0.3 && arousal > this._arousalThreshold && valence < -0.3 ){
183
+ vetoedActions.push( actionType )
184
+ commands.delete = [ ...(commands.delete ?? []), entity.id ]
185
+ continue
186
+ }
187
+
188
+ // Veto check: action contradicts active goals
189
+ if( this._contradictsActiveGoals( actionType, state ) ){
190
+ vetoedActions.push( actionType )
191
+ commands.delete = [ ...(commands.delete ?? []), entity.id ]
192
+ continue
193
+ }
194
+
195
+ // Defer check: high arousal but not enough to veto — delay
196
+ if( arousal > this._arousalThreshold && inhibitionStrength > 0.5 && deferredActions.length < this._maxDeferralsPerTick ){
197
+ this._deferredActions.push({
198
+ actionType,
199
+ metadata: entity.metadata as Record<string, unknown> | undefined,
200
+ deferredUntil: tick + 10,
201
+ reason: 'High arousal — deferring for cooling-off',
202
+ })
203
+ deferredActions.push( actionType )
204
+ commands.delete = [ ...(commands.delete ?? []), entity.id ]
205
+ }
206
+ }
207
+
208
+ // 3. Release deferred actions whose time has come
209
+ const dueDeferrals = this._deferredActions.filter( d => d.deferredUntil <= tick )
210
+ for( const deferred of dueDeferrals ){
211
+ commands.set ??= []
212
+ commands.set.push({
213
+ id: `deferred-action-${deferred.actionType}-${tick}`,
214
+ type: 'decision.record',
215
+ metadata: {
216
+ ...deferred.metadata,
217
+ actionType: deferred.actionType,
218
+ wasDeferred: true,
219
+ deferredReason: deferred.reason,
220
+ tick,
221
+ },
222
+ })
223
+ }
224
+ this._deferredActions = this._deferredActions.filter( d => d.deferredUntil > tick )
225
+
226
+ // 4. Purge decision.record entities older than 30 ticks
227
+ const staleDecisions: string[] = []
228
+ for( const [ id, entity ] of state.entities ){
229
+ if( entity.type === 'decision.record' && typeof entity.metadata?.tick === 'number'){
230
+ if( tick - entity.metadata.tick > 30 )
231
+ staleDecisions.push( id )
232
+ }
233
+ }
234
+ if( staleDecisions.length > 0 )
235
+ commands.delete = [ ...( commands.delete ?? [] ), ...staleDecisions ]
236
+
237
+ // 5. Metrics
238
+ commands.metrics!.push(
239
+ [ 'inhibition.strength', inhibitionStrength ],
240
+ [ 'inhibition.vetoed', vetoedActions.length ],
241
+ [ 'inhibition.deferred', deferredActions.length ],
242
+ [ 'inhibition.pending_deferrals', this._deferredActions.length ],
243
+ )
244
+
245
+ if( vetoedActions.length > 0 )
246
+ events.push({
247
+ type: 'inhibition.veto',
248
+ source: this.name,
249
+ payload: { vetoedActions, inhibitionStrength },
250
+ })
251
+
252
+
253
+ // Phase C + F: publish cognitive event — gated by prediction error
254
+ const _bus = this._bus
255
+ if( _bus && vetoedActions.length > 0 ){
256
+ const predErr = this._model.observe( 'inhibition.strength', inhibitionStrength )
257
+ if( !predErr.gated )
258
+ _bus.publish({ type: 'inhibition.vetoed', version: 1, sourceEngine: this.name, salience: 0.7, payload: { vetoedActions, inhibitionStrength } })
259
+ }
260
+ return { events: events.length > 0 ? events : undefined, commands }
261
+ }
262
+
263
+ // ── Public API ───────────────────────────────────────────
264
+
265
+ /**
266
+ * Explicitly veto a specific action type for a duration.
267
+ */
268
+ vetoAction( actionType: string, durationTicks: number ): void {
269
+ this._deferredActions = this._deferredActions.filter( d => d.actionType !== actionType )
270
+ }
271
+
272
+ // ── Internal ─────────────────────────────────────────────
273
+
274
+ private _computeEffectiveInhibition( state: ReadonlySimulationState ): number {
275
+ const
276
+ stressZone = state.metrics.get('stress.zone') ?? 1,
277
+ sleepPressure = this._sleepPressure,
278
+ energyLevel = state.metrics.get('energy.level') ?? 50,
279
+ circadianAlertness = state.metrics.get('circadian.alertness') ?? 0.5
280
+
281
+ // Stress overload significantly reduces inhibition
282
+ const stressFactor = stressZone >= 3 ? 0.3
283
+ : stressZone >= 2 ? 0.6
284
+ : 1.0
285
+
286
+ // Fatigue reduces inhibition
287
+ const sleepFactor = sleepPressure > 60 ? 0.5
288
+ : sleepPressure > 40 ? 0.7
289
+ : 1.0
290
+
291
+ // Low energy reduces inhibition
292
+ const energyFactor = Math.min( 1, energyLevel / 50 )
293
+
294
+ // Circadian alertness affects inhibition
295
+ const alertnessFactor = 0.6 + circadianAlertness * 0.8
296
+
297
+ // Phase E: executive high confidence → relax inhibition (plan was reasoned through)
298
+ const executiveFactor = this._executiveConfidence > 0.7 ? 0.85
299
+ : this._executiveConfidence < 0.3 ? 1.15
300
+ : 1.0
301
+
302
+ return this._inhibitionStrength
303
+ * stressFactor
304
+ * sleepFactor
305
+ * energyFactor
306
+ * alertnessFactor
307
+ * executiveFactor
308
+ }
309
+
310
+ private _contradictsActiveGoals( actionType: string, state: ReadonlySimulationState ): boolean {
311
+ // Check if the action type contradicts any active goal
312
+ for( const entity of state.entities.values() ){
313
+ if( entity.type !== 'goal') continue
314
+ if( entity.metadata?.status !== 'active') continue
315
+
316
+ const blockedActions = entity.metadata?.blockedActions as string[] | undefined
317
+ if( blockedActions?.includes( actionType ) )
318
+ return true
319
+ }
320
+
321
+ return false
322
+ }
323
+
324
+ /**
325
+ * Register this engine as a CommitValidator in the Orchestrator.
326
+ * Call during setup to wire the veto into the commit pipeline.
327
+ */
328
+ asCommitValidator(): (
329
+ cmds: StateCommands[],
330
+ tick: Tick,
331
+ ctx: SimulationContext
332
+ ) => string[] | true {
333
+ return ( cmds, _tick, _ctx ) => {
334
+ // Scan commands for high-risk actions
335
+ const highRiskActions = cmds.flatMap( c =>
336
+ ( c.set ?? [] ).filter( e =>
337
+ e.type === 'decision.record'
338
+ && e.metadata?.confidence !== undefined
339
+ && ( e.metadata.confidence as number ) < 0.2
340
+ )
341
+ )
342
+
343
+ if( highRiskActions.length > 0 )
344
+ return highRiskActions.map( a =>
345
+ `Inhibition veto: low-confidence action '${a.metadata?.actionType}' blocked`
346
+ )
347
+
348
+ return true
349
+ }
350
+ }
351
+ }