@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.
- package/LICENSE +202 -0
- package/README.md +777 -0
- package/dist/index.d.ts +8144 -0
- package/dist/index.js +26231 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -0
- package/src/cognition/agency/access.grants.ts +59 -0
- package/src/cognition/agency/competence.codec.ts +89 -0
- package/src/cognition/agency/engines/action.selector.ts +462 -0
- package/src/cognition/agency/engines/affordance.synthesizer.ts +384 -0
- package/src/cognition/agency/engines/deliberation.engine.ts +241 -0
- package/src/cognition/agency/engines/instruction.intake.ts +54 -0
- package/src/cognition/agency/engines/motor.schema.executor.ts +532 -0
- package/src/cognition/agency/engines/reafference.engine.ts +241 -0
- package/src/cognition/agency/execution.primitives.ts +118 -0
- package/src/cognition/agency/index.ts +58 -0
- package/src/cognition/agency/proactive.communicator.ts +274 -0
- package/src/cognition/agency/reconcile.learning.ts +82 -0
- package/src/cognition/agency/schemas/external.ts +59 -0
- package/src/cognition/agency/schemas/innate.ts +111 -0
- package/src/cognition/agency/schemas/repertoire.ts +246 -0
- package/src/cognition/agency/selection.scoring.ts +191 -0
- package/src/cognition/agency/types.ts +165 -0
- package/src/cognition/bus.ts +391 -0
- package/src/cognition/completion.inbox.ts +86 -0
- package/src/cognition/config.mirror.entities.ts +475 -0
- package/src/cognition/conversation.memory.ts +81 -0
- package/src/cognition/event.log.ts +116 -0
- package/src/cognition/event.schemas.ts +568 -0
- package/src/cognition/faculties/aesthetic.evaluator.ts +313 -0
- package/src/cognition/faculties/affective.blender.ts +562 -0
- package/src/cognition/faculties/attachment.evaluator.ts +432 -0
- package/src/cognition/faculties/attention.allocator.ts +422 -0
- package/src/cognition/faculties/autobiographical.narrator.ts +300 -0
- package/src/cognition/faculties/bias.detector.ts +363 -0
- package/src/cognition/faculties/circadian.oscillator.ts +294 -0
- package/src/cognition/faculties/confidence.calibrator.ts +324 -0
- package/src/cognition/faculties/dream.simulator.ts +251 -0
- package/src/cognition/faculties/empathy.simulator.ts +253 -0
- package/src/cognition/faculties/energy.regulator.ts +320 -0
- package/src/cognition/faculties/episodic.consolidator.ts +728 -0
- package/src/cognition/faculties/executive.engine/commands.ts +459 -0
- package/src/cognition/faculties/executive.engine/config.ts +46 -0
- package/src/cognition/faculties/executive.engine/context.ts +605 -0
- package/src/cognition/faculties/executive.engine/deferred.effects.ts +104 -0
- package/src/cognition/faculties/executive.engine/deliberate.reasoning.ts +60 -0
- package/src/cognition/faculties/executive.engine/effort.gate.ts +114 -0
- package/src/cognition/faculties/executive.engine/engine.ts +1028 -0
- package/src/cognition/faculties/executive.engine/escalation.buffer.ts +90 -0
- package/src/cognition/faculties/executive.engine/facet.supervisor.ts +271 -0
- package/src/cognition/faculties/executive.engine/facet.ts +628 -0
- package/src/cognition/faculties/executive.engine/gating.ts +222 -0
- package/src/cognition/faculties/executive.engine/index.ts +6 -0
- package/src/cognition/faculties/executive.engine/messages.ts +102 -0
- package/src/cognition/faculties/executive.engine/parser.ts +380 -0
- package/src/cognition/faculties/executive.engine/prompt.factory.ts +1053 -0
- package/src/cognition/faculties/executive.engine/types.ts +323 -0
- package/src/cognition/faculties/exteroception.ts +338 -0
- package/src/cognition/faculties/forgetting.curve.ts +202 -0
- package/src/cognition/faculties/frustration.evaluator.ts +280 -0
- package/src/cognition/faculties/goal.manager.ts +1008 -0
- package/src/cognition/faculties/inhibition.controller.ts +351 -0
- package/src/cognition/faculties/interoception.ts +417 -0
- package/src/cognition/faculties/introspection.engine.ts +246 -0
- package/src/cognition/faculties/known.entity.tracker.ts +439 -0
- package/src/cognition/faculties/loss.evaluator.ts +224 -0
- package/src/cognition/faculties/moral.evaluator.ts +437 -0
- package/src/cognition/faculties/novelty.detector.ts +254 -0
- package/src/cognition/faculties/persona.consolidator.ts +845 -0
- package/src/cognition/faculties/planning.engine/engine.ts +859 -0
- package/src/cognition/faculties/planning.engine/plan.frontier.ts +83 -0
- package/src/cognition/faculties/planning.engine/plan.store.ts +174 -0
- package/src/cognition/faculties/planning.engine/plan.supervision.ts +494 -0
- package/src/cognition/faculties/planning.engine/types.ts +143 -0
- package/src/cognition/faculties/reputation.tracker.ts +294 -0
- package/src/cognition/faculties/reward.evaluator.ts +304 -0
- package/src/cognition/faculties/self.model.updater.ts +677 -0
- package/src/cognition/faculties/semantic.engine/clustering.ts +673 -0
- package/src/cognition/faculties/semantic.engine/index.ts +6 -0
- package/src/cognition/faculties/semantic.engine/integrator.ts +750 -0
- package/src/cognition/faculties/semantic.engine/types.ts +53 -0
- package/src/cognition/faculties/sleep.pressure.regulator.ts +262 -0
- package/src/cognition/faculties/social.perception.ts +333 -0
- package/src/cognition/faculties/spaced.repetition.ts +605 -0
- package/src/cognition/faculties/stress.regulator.ts +375 -0
- package/src/cognition/faculties/task.switcher.ts +239 -0
- package/src/cognition/faculties/theory.of.mind.ts +333 -0
- package/src/cognition/faculties/threat.evaluator.ts +312 -0
- package/src/cognition/faculties/working.memory.ts +406 -0
- package/src/cognition/generative.model.ts +344 -0
- package/src/cognition/heartbeat.ts +70 -0
- package/src/cognition/index.ts +291 -0
- package/src/cognition/instruction.handler.ts +146 -0
- package/src/cognition/memory/index.ts +35 -0
- package/src/cognition/memory/vector.adapter.ts +316 -0
- package/src/cognition/memory/vector.content.ts +47 -0
- package/src/cognition/memory/vector.embedder.ts +212 -0
- package/src/cognition/memory/vector.index.ts +459 -0
- package/src/cognition/memory/vector.types.ts +65 -0
- package/src/cognition/orchestrator.ts +142 -0
- package/src/cognition/persona.prior.ts +265 -0
- package/src/cognition/schema.registry.ts +145 -0
- package/src/cognition/senses/audition.engine/engine.ts +976 -0
- package/src/cognition/senses/audition.engine/salience.ts +59 -0
- package/src/cognition/senses/base.sense.engine.ts +117 -0
- package/src/cognition/senses/gustation.engine.ts +24 -0
- package/src/cognition/senses/index.ts +172 -0
- package/src/cognition/senses/olfaction.engine.ts +24 -0
- package/src/cognition/senses/somatosensation.engine.ts +23 -0
- package/src/cognition/senses/vision.engine.ts +23 -0
- package/src/cognition/types.ts +63 -0
- package/src/cognition/utilities/token.tracker.ts +492 -0
- package/src/core/abstracts.ts +60 -0
- package/src/core/async.engine.ts +539 -0
- package/src/core/clock.ts +196 -0
- package/src/core/completion.recorder.ts +122 -0
- package/src/core/conflict.detector.ts +140 -0
- package/src/core/distributed.ts +626 -0
- package/src/core/event.bus.ts +292 -0
- package/src/core/inbound.recorder.ts +100 -0
- package/src/core/index.ts +167 -0
- package/src/core/logger.ts +85 -0
- package/src/core/metrics.ts +107 -0
- package/src/core/orchestrator.ts +625 -0
- package/src/core/replay.ts +589 -0
- package/src/core/scenario.ts +120 -0
- package/src/core/serialization.ts +448 -0
- package/src/core/simulation.ts +197 -0
- package/src/core/snapshot.manager.ts +293 -0
- package/src/core/state.manager.ts +283 -0
- package/src/core/types.ts +274 -0
- package/src/core/utils.ts +82 -0
- package/src/core/wall.clock.ts +23 -0
- package/src/extensions/livestream.ext.ts +570 -0
- package/src/extensions/time.ext.ts +339 -0
- package/src/index.ts +91 -0
- package/src/llm/gate.ts +140 -0
- package/src/llm/index.ts +716 -0
- package/src/llm/summarizer.ts +170 -0
- package/src/llm/wire.contracts.ts +67 -0
- package/src/pma/eval.ts +651 -0
- package/src/pma/index.ts +1082 -0
- package/src/profiles/built-in.ts +7 -0
- package/src/profiles/companion.ts +28 -0
- package/src/profiles/company-brain.ts +54 -0
- package/src/profiles/customer-service.ts +30 -0
- package/src/profiles/game-npc.ts +20 -0
- package/src/profiles/index.ts +42 -0
- package/src/profiles/smart-home.ts +34 -0
- package/src/runners/coherence.runner.ts +49 -0
- package/src/runners/outreach.runner.ts +158 -0
- package/src/runners/social.runner.ts +182 -0
- package/src/runners/thin-shim.runner.ts +195 -0
- package/src/sdk/will.ts +334 -0
- package/src/stem/assembly.audit.ts +88 -0
- package/src/stem/distribution.ts +203 -0
- package/src/stem/guards/identity.coherence.ts +152 -0
- package/src/stem/guards/identity.guard.ts +227 -0
- package/src/stem/index.ts +1145 -0
- package/src/stem/mind.ts +1090 -0
- package/src/stem/tracts/ack.reconciler.ts +55 -0
- package/src/stem/tracts/biography.writer.ts +190 -0
- package/src/stem/tracts/effector.controller.ts +143 -0
- package/src/stem/tracts/health.reporter.ts +113 -0
- package/src/stem/tracts/inbound.queue.ts +54 -0
- package/src/stem/tracts/outbox.controller.ts +167 -0
- package/src/stem/tracts/outbox.writer.ts +133 -0
- package/src/stem/tracts/pma.controller.ts +109 -0
- package/src/stem/tracts/replay.controller.ts +177 -0
- package/src/stem/tracts/sensory.controller.ts +168 -0
- package/src/stem/tracts/session.logger.ts +157 -0
- package/src/stem/tracts/transport/index.ts +38 -0
- package/src/stem/tracts/transport/loopback.transport.ts +86 -0
- package/src/stem/tracts/transport/socketio.transport.ts +200 -0
- package/src/stem/tracts/transport/stream.transport.ts +152 -0
- package/src/stem/tracts/transport/types.ts +193 -0
- package/src/stem/tracts/transport.controller.ts +380 -0
- package/src/types.ts +116 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
//
|
|
2
|
+
// These entities make every tunable engine parameter visible to the executive
|
|
3
|
+
// reasoning cycle, metacognition engines, and future self-tuning features.
|
|
4
|
+
//
|
|
5
|
+
// Architecture contract:
|
|
6
|
+
// • Engines currently read their config from constructor parameters (fast path).
|
|
7
|
+
// • These entities are the *readable* mirror of those resolved values.
|
|
8
|
+
// • Future work: engines read from state each tick so a MetacognitionEngine
|
|
9
|
+
// can write updated values and have them take effect without a restart.
|
|
10
|
+
// That read path is already implemented in each engine via _readConfigFromState().
|
|
11
|
+
//
|
|
12
|
+
// The executive can reference `engine.config` entities in its context prompt to
|
|
13
|
+
// reason about its own operational parameters.
|
|
14
|
+
|
|
15
|
+
import { WillConfig } from '#stem/mind'
|
|
16
|
+
|
|
17
|
+
export interface EngineConfigEntity {
|
|
18
|
+
id: string
|
|
19
|
+
engine: string
|
|
20
|
+
params: Record<string, unknown>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function buildEngineConfigEntities( config: WillConfig, executiveInterval: number ): EngineConfigEntity[] {
|
|
24
|
+
const selfBelonging = parseFloat( process.env.WILL_SELF_BELONGING ?? '0.35' )
|
|
25
|
+
const boredomRate = parseFloat( process.env.WILL_BOREDOM_RATE ?? '0.005' )
|
|
26
|
+
const curiosityFloor = parseFloat( process.env.WILL_CURIOSITY_FLOOR ?? '0.08' )
|
|
27
|
+
const summaryInterval = parseInt( process.env.WILL_SUMMARY_INTERVAL ?? '10' )
|
|
28
|
+
const summaryBufferSize = parseInt( process.env.WILL_SUMMARY_BUFFER_SIZE ?? '12' )
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
// ── System metadata ──────────────────────────────────────────
|
|
32
|
+
{
|
|
33
|
+
id: 'engine-config-system',
|
|
34
|
+
engine: 'system',
|
|
35
|
+
params: {
|
|
36
|
+
engineTier: config.engineTier,
|
|
37
|
+
modelTier: config.modelTier,
|
|
38
|
+
tickIntervalMs: config.tickIntervalMs ?? 1000
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// ── Regulatory ───────────────────────────────────────────────
|
|
43
|
+
{
|
|
44
|
+
id: 'engine-config-energy',
|
|
45
|
+
engine: 'energy',
|
|
46
|
+
params: {
|
|
47
|
+
maxEnergy: 100,
|
|
48
|
+
baseDecayRate: 0.02,
|
|
49
|
+
restReplenishRate: 0.15,
|
|
50
|
+
lowEnergyThreshold: 30,
|
|
51
|
+
criticalEnergyThreshold: 10,
|
|
52
|
+
collapseThreshold: 1,
|
|
53
|
+
recoveryThreshold: 15,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 'engine-config-sleep',
|
|
58
|
+
engine: 'sleep',
|
|
59
|
+
params: {
|
|
60
|
+
wakeAccumulationRate: 0.008,
|
|
61
|
+
restDissipationRate: 0.04,
|
|
62
|
+
maxPressure: 100,
|
|
63
|
+
fatigueThreshold: 40,
|
|
64
|
+
exhaustionThreshold: 70,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: 'engine-config-circadian',
|
|
69
|
+
engine: 'circadian',
|
|
70
|
+
params: {
|
|
71
|
+
periodHours: 24.2,
|
|
72
|
+
phaseOffsetHours: 0,
|
|
73
|
+
entrainable: 1, // boolean stored as 1/0 for numeric consistency
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'engine-config-attention',
|
|
78
|
+
engine: 'attention',
|
|
79
|
+
params: {
|
|
80
|
+
maxCapacity: 100,
|
|
81
|
+
costPerFocus: 5,
|
|
82
|
+
maxFoci: 4,
|
|
83
|
+
shiftInertia: 0.7,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'engine-config-stress',
|
|
88
|
+
engine: 'stress',
|
|
89
|
+
params: {
|
|
90
|
+
baseDecayRate: 1.5, // overridden in mind.ts from default 0.01
|
|
91
|
+
optimalThreshold: 30,
|
|
92
|
+
distressThreshold: 50,
|
|
93
|
+
overloadThreshold: 75,
|
|
94
|
+
maxLoad: 100,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// ── Perceptual ───────────────────────────────────────────────
|
|
99
|
+
{
|
|
100
|
+
id: 'engine-config-exteroception',
|
|
101
|
+
engine: 'exteroception',
|
|
102
|
+
params: {
|
|
103
|
+
maxPerceptsPerTick: 50,
|
|
104
|
+
defaultSalience: 0.3,
|
|
105
|
+
emitPerceptEvents: 1,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'engine-config-interoception',
|
|
110
|
+
engine: 'interoception',
|
|
111
|
+
params: {
|
|
112
|
+
emitDetailEvent: 0,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'engine-config-social-perception',
|
|
117
|
+
engine: 'social-perception',
|
|
118
|
+
params: {
|
|
119
|
+
maxPerceptsPerTick: 20,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'engine-config-novelty',
|
|
124
|
+
engine: 'novelty',
|
|
125
|
+
params: {
|
|
126
|
+
learningRate: 0.1,
|
|
127
|
+
windowSize: 10,
|
|
128
|
+
significanceThreshold: 0.4,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// ── Affective ────────────────────────────────────────────────
|
|
133
|
+
{
|
|
134
|
+
id: 'engine-config-threat',
|
|
135
|
+
engine: 'threat',
|
|
136
|
+
params: {
|
|
137
|
+
hostileWeight: 0.35,
|
|
138
|
+
scarcityWeight: 0.25,
|
|
139
|
+
uncertaintyWeight: 0.20,
|
|
140
|
+
socialWeight: 0.20,
|
|
141
|
+
fearEventThreshold: 0.6,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
id: 'engine-config-reward',
|
|
146
|
+
engine: 'reward',
|
|
147
|
+
params: {
|
|
148
|
+
goalWeight: 0.40,
|
|
149
|
+
socialWeight: 0.25,
|
|
150
|
+
resourceWeight: 0.15,
|
|
151
|
+
discoveryWeight: 0.20,
|
|
152
|
+
socialDecayRate: 0.02,
|
|
153
|
+
socialWarmthBoost: 0.4,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: 'engine-config-loss',
|
|
158
|
+
engine: 'loss',
|
|
159
|
+
params: {
|
|
160
|
+
significantLossThreshold: 0.5,
|
|
161
|
+
decayRate: 0.05,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: 'engine-config-frustration',
|
|
166
|
+
engine: 'frustration',
|
|
167
|
+
params: {
|
|
168
|
+
stuckThreshold: 5,
|
|
169
|
+
irritabilityRate: 0.02,
|
|
170
|
+
decayRate: 0.08,
|
|
171
|
+
habituationRate: 0.03,
|
|
172
|
+
// How strongly provocation (unfairness + blocked progress) becomes anger.
|
|
173
|
+
// Channel A: the metacog loop develops it DOWN from demonstrated `agreeableness`
|
|
174
|
+
// (yielding in conflict — accommodate rather than retaliate). This is the baseline.
|
|
175
|
+
angerReactivity: 0.7,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: 'engine-config-attachment',
|
|
180
|
+
engine: 'attachment',
|
|
181
|
+
params: {
|
|
182
|
+
selfBelonging,
|
|
183
|
+
attachmentGrowthRate: 0.05,
|
|
184
|
+
attachmentDecayRate: 0.002,
|
|
185
|
+
lonelinessThreshold: 0.4,
|
|
186
|
+
minInteractionsForBond: 3,
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
id: 'engine-config-aesthetic',
|
|
191
|
+
engine: 'aesthetic',
|
|
192
|
+
params: {
|
|
193
|
+
boredomRate,
|
|
194
|
+
curiosityFloor,
|
|
195
|
+
aweThreshold: 0.8,
|
|
196
|
+
curiosityRangeMin: 0.2,
|
|
197
|
+
curiosityRangeMax: 0.7,
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'engine-config-moral',
|
|
202
|
+
engine: 'moral',
|
|
203
|
+
params: {
|
|
204
|
+
eventThreshold: 0.3,
|
|
205
|
+
decayRate: 0.02,
|
|
206
|
+
// Moral foundations stored flat — keys map 1:1 to the six MFT
|
|
207
|
+
// foundations the engine tracks (care, fairness, loyalty, authority,
|
|
208
|
+
// sanctity, liberty). Values are the constructor's normalized weights
|
|
209
|
+
// (sum 1.0); the engine re-normalizes after applying them.
|
|
210
|
+
foundationCare: 0.25,
|
|
211
|
+
foundationFairness: 0.25,
|
|
212
|
+
foundationLoyalty: 0.15,
|
|
213
|
+
foundationAuthority: 0.10,
|
|
214
|
+
foundationSanctity: 0.10,
|
|
215
|
+
foundationLiberty: 0.15,
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: 'engine-config-affective-blender',
|
|
220
|
+
engine: 'affective-blender',
|
|
221
|
+
params: {
|
|
222
|
+
inertia: 0.5,
|
|
223
|
+
emitBlendEvents: 0,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
// ── Memory ───────────────────────────────────────────────────
|
|
228
|
+
{
|
|
229
|
+
id: 'engine-config-working-memory',
|
|
230
|
+
engine: 'working-memory',
|
|
231
|
+
params: {
|
|
232
|
+
maxChunks: 7,
|
|
233
|
+
baseDecayRate: 0.08,
|
|
234
|
+
attentionProtection: 0.6,
|
|
235
|
+
retrievalThreshold: 0.05,
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: 'engine-config-episodic',
|
|
240
|
+
engine: 'episodic',
|
|
241
|
+
params: {
|
|
242
|
+
consolidationThreshold: 0.25,
|
|
243
|
+
emotionBoost: 2.0,
|
|
244
|
+
maxPerTick: 5,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: 'engine-config-semantic',
|
|
249
|
+
engine: 'semantic',
|
|
250
|
+
params: {
|
|
251
|
+
minIntervalTicks: 30,
|
|
252
|
+
minNewEpisodes: 10,
|
|
253
|
+
maxBeliefs: 500,
|
|
254
|
+
beliefStalenessThreshold: 300,
|
|
255
|
+
beliefDecayRate: 0.001,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'engine-config-forgetting',
|
|
260
|
+
engine: 'forgetting',
|
|
261
|
+
params: {
|
|
262
|
+
baseForgettingRate: 0.02,
|
|
263
|
+
emotionProtection: 0.7,
|
|
264
|
+
pruningThreshold: 0.01,
|
|
265
|
+
maxPrunePerTick: 10,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: 'engine-config-spaced-repetition',
|
|
270
|
+
engine: 'spaced-repetition',
|
|
271
|
+
params: {
|
|
272
|
+
reviewIntervalTicks: 50,
|
|
273
|
+
maxReviewsPerCycle: 5,
|
|
274
|
+
minConfidenceForReview: 0.15,
|
|
275
|
+
successBoost: 0.05,
|
|
276
|
+
failurePenalty: 0.08,
|
|
277
|
+
baseIntervalTicks: 10,
|
|
278
|
+
maxIntervalTicks: 500,
|
|
279
|
+
executiveReviewEnabled: 0, // boolean stored as 1/0 for numeric consistency
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'engine-config-dream',
|
|
284
|
+
engine: 'dream',
|
|
285
|
+
params: {
|
|
286
|
+
maxReactivationsPerTick: 5,
|
|
287
|
+
emotionalDampeningRate: 0.05,
|
|
288
|
+
recombinationProbability: 0.1,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
// ── Executive ────────────────────────────────────────────────
|
|
293
|
+
{
|
|
294
|
+
id: 'engine-config-goal-manager',
|
|
295
|
+
engine: 'goal-manager',
|
|
296
|
+
params: {
|
|
297
|
+
maxActiveGoals: 5,
|
|
298
|
+
priorityDecayRate: 0.005,
|
|
299
|
+
deactivationThreshold: 0.1,
|
|
300
|
+
epistemicBeliefThreshold: 8,
|
|
301
|
+
// Personality dispositions (PMA-seedable per Will; developed by metacog via
|
|
302
|
+
// the persona-prior). Grit/persistence + frustration tolerance.
|
|
303
|
+
gritPriority: 0.8,
|
|
304
|
+
gritPatienceScale: 2,
|
|
305
|
+
frustrationTolerance: 0.5,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
id: 'engine-config-executive',
|
|
310
|
+
engine: 'executive',
|
|
311
|
+
params: {
|
|
312
|
+
executiveInterval: executiveInterval,
|
|
313
|
+
cooldownTicks: 5,
|
|
314
|
+
// Dual-process effort gate (Channel A). Effort demand at/above which the master
|
|
315
|
+
// engages System 2 (deliberate propose→evaluate). The metacog loop develops it
|
|
316
|
+
// DOWN from demonstrated `analytical` disposition via the persona-prior mirror,
|
|
317
|
+
// so a more analytical Will deliberates more readily; this is the baseline.
|
|
318
|
+
deliberateThreshold: 0.5,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: 'engine-config-planning',
|
|
323
|
+
engine: 'planning',
|
|
324
|
+
// Trait-driven supervision dispositions (Channel A). The metacog loop
|
|
325
|
+
// (PersonaConsolidator) develops these from demonstrated conscientiousness
|
|
326
|
+
// via the persona-prior mirror; these are the PMA-seeded baselines.
|
|
327
|
+
params: {
|
|
328
|
+
maxStepRetries: 3,
|
|
329
|
+
surpriseOutcomeQuality: 0.25,
|
|
330
|
+
// How hard the plan asserts its frontier in the action competition
|
|
331
|
+
// (planning-as-prior). 1 = neutral; conscientiousness develops it UP so a
|
|
332
|
+
// conscientious Will pushes its plan against competing impulses.
|
|
333
|
+
planBiasGain: 1,
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
id: 'engine-config-inhibition',
|
|
338
|
+
engine: 'inhibition',
|
|
339
|
+
params: {
|
|
340
|
+
baseInhibitionStrength: 0.6,
|
|
341
|
+
arousalThreshold: 0.6,
|
|
342
|
+
maxDeferralsPerTick: 3,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
id: 'engine-config-task-switcher',
|
|
347
|
+
engine: 'task-switcher',
|
|
348
|
+
params: {
|
|
349
|
+
baseSwitchCost: 0.3,
|
|
350
|
+
switchThreshold: 0.2,
|
|
351
|
+
minFocusTicks: 3,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
// Agency action-selection apparatus (Channel A). `switchCost` is the selector's
|
|
356
|
+
// preemption hysteresis on the *activation* scale — the second owner of the same
|
|
357
|
+
// "switch resistance" disposition the task-switcher develops in attention space.
|
|
358
|
+
// Conscientiousness raises it (less distractible → sees actions through); the
|
|
359
|
+
// selector modulates it by the shared `task_switch.current_focus_ticks` signal.
|
|
360
|
+
// `riskWeight` / `noveltyWeight` are competition weights the selector reads back
|
|
361
|
+
// (base ⊕ prior): emotional-stability lowers risk (bolder), openness raises novelty
|
|
362
|
+
// (curiosity pulls toward the unpracticed). Mirror DEFAULT_WEIGHTS in scoring.ts.
|
|
363
|
+
id: 'engine-config-action-selector',
|
|
364
|
+
engine: 'action-selector',
|
|
365
|
+
params: {
|
|
366
|
+
switchCost: 0.15,
|
|
367
|
+
riskWeight: 0.20,
|
|
368
|
+
noveltyWeight: 0.10,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
// ── Meta-cognitive ───────────────────────────────────────────
|
|
373
|
+
{
|
|
374
|
+
id: 'engine-config-self-model',
|
|
375
|
+
engine: 'self-model',
|
|
376
|
+
params: {
|
|
377
|
+
minIntervalTicks: 200,
|
|
378
|
+
minNewExperiences: 20,
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
id: 'engine-config-confidence',
|
|
383
|
+
engine: 'confidence',
|
|
384
|
+
params: {
|
|
385
|
+
minSamplesPerDomain: 5,
|
|
386
|
+
calibrationRate: 0.1,
|
|
387
|
+
maxAdjustment: 0.3,
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
id: 'engine-config-bias-detector',
|
|
392
|
+
engine: 'bias-detector',
|
|
393
|
+
params: {
|
|
394
|
+
minDecisions: 10,
|
|
395
|
+
scanIntervalTicks: 100,
|
|
396
|
+
emitBiasEvents: 1,
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
id: 'engine-config-narrator',
|
|
401
|
+
engine: 'narrator',
|
|
402
|
+
params: {
|
|
403
|
+
minIntervalTicks: 50,
|
|
404
|
+
maxNarrativeLength: 5000,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 'engine-config-introspection',
|
|
409
|
+
engine: 'introspection',
|
|
410
|
+
params: {
|
|
411
|
+
cooldownTicks: 50,
|
|
412
|
+
significanceThreshold: 0.4,
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
// ── Social ───────────────────────────────────────────────────
|
|
417
|
+
{
|
|
418
|
+
id: 'engine-config-theory-of-mind',
|
|
419
|
+
engine: 'theory-of-mind',
|
|
420
|
+
params: {
|
|
421
|
+
maxModeledAgents: 10,
|
|
422
|
+
beliefDecayRate: 0.002,
|
|
423
|
+
confidenceThreshold: 0.3,
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
id: 'engine-config-empathy',
|
|
428
|
+
engine: 'empathy',
|
|
429
|
+
params: {
|
|
430
|
+
resonanceStrength: 0.6,
|
|
431
|
+
compassionThreshold: 0.3,
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
id: 'engine-config-reputation',
|
|
436
|
+
engine: 'reputation',
|
|
437
|
+
params: {
|
|
438
|
+
maxTrackedAgents: 20,
|
|
439
|
+
decayRate: 0.001,
|
|
440
|
+
minInteractions: 3,
|
|
441
|
+
// How much a cooperative interaction raises an agent's cooperativeness (trust step).
|
|
442
|
+
// Channel A: the metacog loop develops it UP from demonstrated `agreeableness`
|
|
443
|
+
// (extends trust / benefit-of-the-doubt more readily). This is the baseline.
|
|
444
|
+
trustGrowthStep: 0.05,
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
|
|
448
|
+
{
|
|
449
|
+
id: 'engine-config-known-entity',
|
|
450
|
+
engine: 'known-entity-tracker',
|
|
451
|
+
params: {
|
|
452
|
+
// How fast a sense of an entity forms per encounter. Channel A: the metacog loop
|
|
453
|
+
// develops it UP from demonstrated `openness` (an open mind grows familiar faster).
|
|
454
|
+
familiarityGrowthRate: 0.15,
|
|
455
|
+
// Gain on the curiosity-to-resolve pull. Channel A: `openness` UP → feels the
|
|
456
|
+
// pull-to-know the half-known more readily.
|
|
457
|
+
curiosityGain: 1.0,
|
|
458
|
+
// How fast a reliability (track-record) judgment is revised per outcome. Channel A:
|
|
459
|
+
// `analytical` UP → updates its assessment more responsively from evidence.
|
|
460
|
+
reliabilityRate: 0.2,
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
// ── LLM / Summarizer (standard + full only) ──────────────────
|
|
465
|
+
{
|
|
466
|
+
id: 'engine-config-summarizer',
|
|
467
|
+
engine: 'summarizer',
|
|
468
|
+
params: {
|
|
469
|
+
summaryInterval,
|
|
470
|
+
summaryBufferSize,
|
|
471
|
+
maxCharsPerEntry: 600,
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
]
|
|
475
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/conversation.memory.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// The single authority for the `conversation.exchange` working-memory item.
|
|
6
|
+
//
|
|
7
|
+
// A completed conversational turn is persisted as a `working_memory.item` state
|
|
8
|
+
// entity so it flows through WorkingMemory → EpisodicConsolidator → vector. There
|
|
9
|
+
// are two producers and they MUST agree on the shape:
|
|
10
|
+
//
|
|
11
|
+
// - AuditionEngine — reactive replies (someone spoke → the Will answered)
|
|
12
|
+
// - ProactiveCommunicator — proactive outreach (the Will decided to reach out)
|
|
13
|
+
//
|
|
14
|
+
// Both call `buildConversationExchange`; each applies the result via its own sink
|
|
15
|
+
// (AuditionEngine → memory sink / setEntity; ProactiveCommunicator → StateCommands).
|
|
16
|
+
// Per-caller knobs (activation, attendedCount, threadId, the id/createdAt stamps)
|
|
17
|
+
// stay parameters; the row shape, tags, and summary live here once.
|
|
18
|
+
//
|
|
19
|
+
// Downstream consumers read the STRUCTURED fields (`userMessage` / `willReply` in
|
|
20
|
+
// executive context + semantic clustering), with `summary` as the fallback — so
|
|
21
|
+
// both producers now emit the structured fields, not just a summary string.
|
|
22
|
+
// ─────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
export interface ConversationExchangeInput {
|
|
25
|
+
/** Stable entity id of the other party. */
|
|
26
|
+
entityId: string
|
|
27
|
+
/** Display name; falls back to entityId. */
|
|
28
|
+
entityName?: string
|
|
29
|
+
/** The inbound message. Empty string for proactive, master-initiated outreach. */
|
|
30
|
+
userMessage: string
|
|
31
|
+
/** What the Will said. May be empty (formulated-but-unspoken still gets remembered). */
|
|
32
|
+
willReply: string
|
|
33
|
+
/** Conversation thread, when the producer has one (replies do; outreach may not). */
|
|
34
|
+
threadId?: string
|
|
35
|
+
/** Sim tick, when the producer is on-tick. Omitted off-tick. */
|
|
36
|
+
tick?: number
|
|
37
|
+
/** WM activation. Default 0.85; AuditionEngine passes a confidence-derived value. */
|
|
38
|
+
activation?: number
|
|
39
|
+
/** WM attended count. Default 3. */
|
|
40
|
+
attendedCount?: number
|
|
41
|
+
/** Unique id seed — the caller's clock (wallClock() under replay; never Date.now() in a scanned tree). */
|
|
42
|
+
idSeed: number
|
|
43
|
+
/** Top-level createdAt. Pass on the StateCommands path; omit when setEntity stamps it. */
|
|
44
|
+
createdAt?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ConversationExchangeEntity {
|
|
48
|
+
id: string
|
|
49
|
+
type: 'working_memory.item'
|
|
50
|
+
createdAt?: number
|
|
51
|
+
metadata: Record<string, unknown>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function buildConversationExchange( input: ConversationExchangeInput ): ConversationExchangeEntity {
|
|
55
|
+
const {
|
|
56
|
+
entityId, userMessage, willReply, threadId, tick,
|
|
57
|
+
activation = 0.85, attendedCount = 3, idSeed, createdAt,
|
|
58
|
+
} = input
|
|
59
|
+
const name = input.entityName ?? entityId
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
id: `wm-exchange-${ entityId }-${ idSeed }`,
|
|
63
|
+
type: 'working_memory.item',
|
|
64
|
+
...( createdAt !== undefined ? { createdAt } : {} ),
|
|
65
|
+
metadata: {
|
|
66
|
+
wmType: 'conversation.exchange',
|
|
67
|
+
activation,
|
|
68
|
+
attendedCount,
|
|
69
|
+
tags: [ 'conversation', 'exchange', `entity:${ entityId }` ],
|
|
70
|
+
summary: userMessage
|
|
71
|
+
? `${ name }: "${ userMessage.slice( 0, 100 ) }" → "${ willReply.slice( 0, 100 ) }"`
|
|
72
|
+
: `You → ${ name }: "${ willReply.slice( 0, 140 ) }"`,
|
|
73
|
+
entityId,
|
|
74
|
+
entityName: name,
|
|
75
|
+
userMessage,
|
|
76
|
+
willReply,
|
|
77
|
+
...( threadId ? { threadId } : {} ),
|
|
78
|
+
...( tick !== undefined ? { tick } : {} ),
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/event.log.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Append-only persistent event log.
|
|
7
|
+
*
|
|
8
|
+
* Every CognitiveEvent is written here before delivery so the full
|
|
9
|
+
* causal history of the system is reconstructible at any logical time.
|
|
10
|
+
* The log is the authoritative record; engine state is a derived projection.
|
|
11
|
+
*
|
|
12
|
+
* Storage: JSONL (one JSON object per line), pluggable backend via StorageAdapter.
|
|
13
|
+
* Auto-flushes at AUTO_FLUSH_SIZE entries or when flush() is called explicitly.
|
|
14
|
+
*
|
|
15
|
+
* In-memory ring buffer is capped at MAX_IN_MEMORY entries to prevent OOM.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { StorageAdapter } from '#core/abstracts'
|
|
19
|
+
import type { CognitiveEvent } from '#cognition/bus'
|
|
20
|
+
|
|
21
|
+
const AUTO_FLUSH_SIZE = 100
|
|
22
|
+
const MAX_IN_MEMORY = 10_000
|
|
23
|
+
|
|
24
|
+
export interface EventLog {
|
|
25
|
+
append( event: CognitiveEvent ): void
|
|
26
|
+
flush(): Promise<void>
|
|
27
|
+
recent( n?: number ): CognitiveEvent[]
|
|
28
|
+
since( logicalTime: number ): CognitiveEvent[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class DefaultEventLog implements EventLog {
|
|
32
|
+
private _path: string
|
|
33
|
+
private _storage: StorageAdapter
|
|
34
|
+
private _buffer: CognitiveEvent[] = [] // pending writes, not yet flushed
|
|
35
|
+
private _memory: CognitiveEvent[] = [] // in-memory ring (capped)
|
|
36
|
+
private _flushing = false
|
|
37
|
+
private _pendingFlush: Promise<void> | null = null
|
|
38
|
+
|
|
39
|
+
constructor( path: string, storage: StorageAdapter ){
|
|
40
|
+
this._path = path
|
|
41
|
+
this._storage = storage
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
append( event: CognitiveEvent ): void {
|
|
45
|
+
this._buffer.push( event )
|
|
46
|
+
|
|
47
|
+
// Ring buffer — drop oldest when full
|
|
48
|
+
if( this._memory.length >= MAX_IN_MEMORY )
|
|
49
|
+
this._memory.shift()
|
|
50
|
+
this._memory.push( event )
|
|
51
|
+
|
|
52
|
+
if( this._buffer.length >= AUTO_FLUSH_SIZE )
|
|
53
|
+
void this._triggerFlush()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async flush(): Promise<void> {
|
|
57
|
+
if( this._pendingFlush )
|
|
58
|
+
return this._pendingFlush
|
|
59
|
+
return this._triggerFlush()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
recent( n = 100 ): CognitiveEvent[] {
|
|
63
|
+
return this._memory.slice( -n )
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
since( logicalTime: number ): CognitiveEvent[] {
|
|
67
|
+
return this._memory.filter( e => e.logicalTime >= logicalTime )
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── Internal ─────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
private async _triggerFlush(): Promise<void> {
|
|
73
|
+
if( this._flushing || this._buffer.length === 0 ) return
|
|
74
|
+
|
|
75
|
+
this._flushing = true
|
|
76
|
+
const batch = this._buffer.splice( 0 )
|
|
77
|
+
|
|
78
|
+
this._pendingFlush = this._writeBatch( batch ).finally( () => {
|
|
79
|
+
this._flushing = false
|
|
80
|
+
this._pendingFlush = null
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return this._pendingFlush
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private async _writeBatch( batch: CognitiveEvent[] ): Promise<void> {
|
|
87
|
+
const lines = batch.map( e => JSON.stringify( e ) ).join( '\n' ) + '\n'
|
|
88
|
+
let existing = ''
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
if( await this._storage.exists( this._path ) )
|
|
92
|
+
existing = await this._storage.read( this._path )
|
|
93
|
+
} catch { /* file may not exist yet */ }
|
|
94
|
+
|
|
95
|
+
await this._storage.ensureDir?.( this._path.replace( /\/[^/]+$/, '' ) )
|
|
96
|
+
await this._storage.write( this._path, existing + lines )
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** No-op log for testing or when persistence is not needed. */
|
|
101
|
+
export class NullEventLog implements EventLog {
|
|
102
|
+
private _memory: CognitiveEvent[] = []
|
|
103
|
+
|
|
104
|
+
append( event: CognitiveEvent ): void {
|
|
105
|
+
if( this._memory.length >= MAX_IN_MEMORY ) this._memory.shift()
|
|
106
|
+
this._memory.push( event )
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
flush(): Promise<void> { return Promise.resolve() }
|
|
110
|
+
|
|
111
|
+
recent( n = 100 ): CognitiveEvent[] { return this._memory.slice( -n ) }
|
|
112
|
+
|
|
113
|
+
since( logicalTime: number ): CognitiveEvent[] {
|
|
114
|
+
return this._memory.filter( e => e.logicalTime >= logicalTime )
|
|
115
|
+
}
|
|
116
|
+
}
|