@mindot/will 0.5.0 → 0.7.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 (136) hide show
  1. package/dist/channels/discord.d.ts +1 -1
  2. package/dist/channels/discord.js.map +1 -1
  3. package/dist/channels/whatsapp.d.ts +1 -1
  4. package/dist/channels/whatsapp.js.map +1 -1
  5. package/dist/cli.js +998 -59
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +998 -59
  9. package/dist/index.js.map +1 -1
  10. package/dist/mcp/effectors.d.ts +1 -1
  11. package/dist/mcp/effectors.js.map +1 -1
  12. package/dist/{will-BDq-TMQr.d.ts → will-DAW0l-lY.d.ts} +90 -10
  13. package/package.json +1 -1
  14. package/src/channels/discord.ts +11 -11
  15. package/src/channels/roster.ts +1 -1
  16. package/src/channels/types.ts +1 -1
  17. package/src/channels/whatsapp.ts +25 -25
  18. package/src/cli.ts +20 -20
  19. package/src/cognition/acp.ts +28 -0
  20. package/src/cognition/agency/consequence.ts +174 -0
  21. package/src/cognition/agency/engines/action.selector.ts +333 -48
  22. package/src/cognition/agency/engines/affordance.synthesizer.ts +35 -16
  23. package/src/cognition/agency/engines/deliberation.engine.ts +28 -14
  24. package/src/cognition/agency/engines/motor.schema.executor.ts +90 -14
  25. package/src/cognition/agency/engines/reafference.engine.ts +152 -23
  26. package/src/cognition/agency/execution.primitives.ts +13 -13
  27. package/src/cognition/agency/proactive.communicator.ts +1 -1
  28. package/src/cognition/agency/reconcile.learning.ts +10 -1
  29. package/src/cognition/agency/revocation.ts +79 -0
  30. package/src/cognition/agency/schemas/repertoire.ts +109 -9
  31. package/src/cognition/agency/selection.scoring.ts +32 -10
  32. package/src/cognition/agency/types.ts +9 -0
  33. package/src/cognition/bus.ts +2 -2
  34. package/src/cognition/completion.inbox.ts +1 -1
  35. package/src/cognition/config.mirror.entities.ts +5 -5
  36. package/src/cognition/event.log.ts +2 -2
  37. package/src/cognition/event.schemas.ts +67 -67
  38. package/src/cognition/faculties/aesthetic.evaluator.ts +6 -6
  39. package/src/cognition/faculties/affective.blender.ts +36 -4
  40. package/src/cognition/faculties/attachment.evaluator.ts +6 -6
  41. package/src/cognition/faculties/attention.allocator.ts +63 -8
  42. package/src/cognition/faculties/autobiographical.narrator.ts +3 -3
  43. package/src/cognition/faculties/bias.detector.ts +7 -7
  44. package/src/cognition/faculties/circadian.oscillator.ts +3 -3
  45. package/src/cognition/faculties/confidence.calibrator.ts +7 -7
  46. package/src/cognition/faculties/dream.simulator.ts +5 -5
  47. package/src/cognition/faculties/empathy.simulator.ts +7 -7
  48. package/src/cognition/faculties/energy.regulator.ts +4 -4
  49. package/src/cognition/faculties/episodic.consolidator.ts +6 -6
  50. package/src/cognition/faculties/executive.engine/commands.ts +6 -6
  51. package/src/cognition/faculties/executive.engine/context.ts +42 -42
  52. package/src/cognition/faculties/executive.engine/deferred.effects.ts +2 -2
  53. package/src/cognition/faculties/executive.engine/engine.ts +25 -25
  54. package/src/cognition/faculties/executive.engine/facet.supervisor.ts +12 -12
  55. package/src/cognition/faculties/executive.engine/facet.ts +18 -18
  56. package/src/cognition/faculties/executive.engine/gating.ts +2 -2
  57. package/src/cognition/faculties/executive.engine/messages.ts +3 -3
  58. package/src/cognition/faculties/executive.engine/parser.ts +11 -11
  59. package/src/cognition/faculties/executive.engine/prompt.factory.ts +55 -55
  60. package/src/cognition/faculties/exteroception.ts +99 -5
  61. package/src/cognition/faculties/forgetting.curve.ts +3 -3
  62. package/src/cognition/faculties/frustration.evaluator.ts +6 -6
  63. package/src/cognition/faculties/goal.manager.ts +15 -15
  64. package/src/cognition/faculties/inhibition.controller.ts +3 -3
  65. package/src/cognition/faculties/interoception.ts +3 -3
  66. package/src/cognition/faculties/introspection.engine.ts +3 -3
  67. package/src/cognition/faculties/known.entity.tracker.ts +15 -15
  68. package/src/cognition/faculties/loss.evaluator.ts +2 -2
  69. package/src/cognition/faculties/moral.evaluator.ts +4 -4
  70. package/src/cognition/faculties/novelty.detector.ts +4 -4
  71. package/src/cognition/faculties/persona.consolidator.ts +12 -12
  72. package/src/cognition/faculties/planning.engine/engine.ts +47 -47
  73. package/src/cognition/faculties/planning.engine/plan.frontier.ts +5 -5
  74. package/src/cognition/faculties/planning.engine/plan.store.ts +1 -1
  75. package/src/cognition/faculties/planning.engine/plan.supervision.ts +20 -20
  76. package/src/cognition/faculties/reputation.tracker.ts +6 -6
  77. package/src/cognition/faculties/reward.evaluator.ts +4 -4
  78. package/src/cognition/faculties/self.model.updater.ts +8 -8
  79. package/src/cognition/faculties/semantic.engine/integrator.ts +15 -15
  80. package/src/cognition/faculties/sleep.pressure.regulator.ts +4 -4
  81. package/src/cognition/faculties/social.perception.ts +3 -3
  82. package/src/cognition/faculties/spaced.repetition.ts +2 -2
  83. package/src/cognition/faculties/stress.regulator.ts +27 -4
  84. package/src/cognition/faculties/task.switcher.ts +11 -6
  85. package/src/cognition/faculties/theory.of.mind.ts +6 -6
  86. package/src/cognition/faculties/threat.evaluator.ts +3 -3
  87. package/src/cognition/faculties/working.memory.ts +8 -8
  88. package/src/cognition/generative.model.ts +2 -2
  89. package/src/cognition/memory/vector.adapter.ts +5 -5
  90. package/src/cognition/memory/vector.content.ts +4 -4
  91. package/src/cognition/memory/vector.embedder.ts +9 -9
  92. package/src/cognition/persona.prior.ts +1 -1
  93. package/src/cognition/schema.registry.ts +2 -2
  94. package/src/cognition/senses/audition.engine/engine.ts +2 -2
  95. package/src/cognition/senses/base.sense.engine.ts +1 -1
  96. package/src/cognition/utilities/token.tracker.ts +5 -5
  97. package/src/core/abstracts.ts +1 -1
  98. package/src/core/completion.recorder.ts +2 -2
  99. package/src/core/serialization.ts +3 -3
  100. package/src/core/snapshot.manager.ts +1 -1
  101. package/src/core/state.manager.ts +1 -1
  102. package/src/core/utils.ts +1 -1
  103. package/src/host/boot.ts +30 -30
  104. package/src/host/utterances.ts +1 -1
  105. package/src/llm/index.ts +9 -9
  106. package/src/llm/summarizer.ts +4 -4
  107. package/src/llm/wire.contracts.ts +1 -1
  108. package/src/mcp/effectors.ts +10 -10
  109. package/src/mcp/server.ts +11 -11
  110. package/src/pma/eval.ts +1 -1
  111. package/src/pma/index.ts +21 -21
  112. package/src/runners/outreach.runner.ts +3 -3
  113. package/src/runners/social.runner.ts +1 -1
  114. package/src/runners/thin-shim.runner.ts +1 -1
  115. package/src/sdk/will.ts +5 -5
  116. package/src/serve/server.ts +12 -12
  117. package/src/stem/assembly.audit.ts +3 -3
  118. package/src/stem/guards/identity.coherence.ts +10 -10
  119. package/src/stem/guards/identity.guard.ts +22 -22
  120. package/src/stem/index.ts +26 -11
  121. package/src/stem/mind.ts +12 -12
  122. package/src/stem/policy/arbiter.ts +136 -0
  123. package/src/stem/policy/rule.table.ts +172 -0
  124. package/src/stem/policy/verdict.recorder.ts +0 -0
  125. package/src/stem/tracts/biography.writer.ts +3 -3
  126. package/src/stem/tracts/effector.controller.ts +383 -4
  127. package/src/stem/tracts/health.reporter.ts +1 -1
  128. package/src/stem/tracts/outbox.controller.ts +4 -0
  129. package/src/stem/tracts/outbox.writer.ts +4 -4
  130. package/src/stem/tracts/pma.controller.ts +1 -1
  131. package/src/stem/tracts/replay.controller.ts +10 -10
  132. package/src/stem/tracts/sensory.controller.ts +2 -2
  133. package/src/stem/tracts/session.logger.ts +4 -4
  134. package/src/stem/tracts/transport/socketio.transport.ts +7 -7
  135. package/src/stem/tracts/transport/stream.transport.ts +2 -2
  136. package/src/stem/tracts/transport.controller.ts +15 -15
@@ -7,13 +7,18 @@
7
7
  // learned, and what it fears. This is the basal-ganglia Go/NoGo arithmetic,
8
8
  // kept pure so it is trivially testable and replay-deterministic.
9
9
  //
10
- // activation = goalRelevance + expectedReward + novelty + driveUrgency
10
+ // activation = goalRelevance
11
+ // + expectedReward
12
+ // + novelty
13
+ // + driveUrgency
11
14
  // + habitStrength·W (additive habit bonus)
12
15
  // + planBias·W (top-down prior)
13
- // − cost − inhibition − risk
16
+ // − cost
17
+ // − inhibition
18
+ // − risk
14
19
  //
15
20
  // The habit term is additive (per design decision): an overlearned schema wins
16
- // cheaply AND lowers its own deliberation threshold (see selector.ts), which is
21
+ // cheaply AND lowers its own deliberation threshold (see action.selector.ts), which is
17
22
  // how the instrumental→habitual gradient cashes out as falling LLM spend.
18
23
  // ─────────────────────────────────────────────────────────────
19
24
 
@@ -77,22 +82,29 @@ export const DEFAULT_TEMPERATURE = 0.15
77
82
  */
78
83
  export function collectGoalTargets( state: ReadonlySimulationState ): Map<string, number> {
79
84
  const targets = new Map<string, number>()
85
+
80
86
  for( const e of state.entities.values() ){
81
- if( e.type !== 'goal' ) continue
87
+ if( e.type !== 'goal') continue
88
+
82
89
  const m = e.metadata as Record<string, unknown> | undefined
83
90
  const status = typeof m?.['status'] === 'string' ? m['status'] : undefined
84
- if( status !== 'active' && status !== 'in_progress' ) continue
91
+
92
+ if( status !== 'active' && status !== 'in_progress') continue
93
+
85
94
  const priority = typeof m?.['priority'] === 'number' ? m['priority'] as number : 0
86
95
  const link = ( id: unknown ): void => {
87
96
  if( typeof id !== 'string' || !id ) return
88
97
  targets.set( id, Math.max( targets.get( id ) ?? 0, priority ) )
89
98
  }
99
+
90
100
  link( m?.['targetEntityId'] )
91
101
  link( m?.['requestingEntityId'] )
102
+
92
103
  if( Array.isArray( m?.['tags'] ) )
93
104
  for( const t of m['tags'] as unknown[] )
94
- if( typeof t === 'string' && t.startsWith( 'keid:' ) ) link( t.slice( 5 ) )
105
+ if( typeof t === 'string' && t.startsWith('keid:') ) link( t.slice( 5 ) )
95
106
  }
107
+
96
108
  return targets
97
109
  }
98
110
 
@@ -100,18 +112,22 @@ export function collectGoalTargets( state: ReadonlySimulationState ): Map<string
100
112
  export function goalRelevance( a: Affordance, bias: BiasContext ): number {
101
113
  if( a.targetEntityId && bias.goalTargets.has( a.targetEntityId ) )
102
114
  return bias.maxGoalPriority
115
+
103
116
  return 0
104
117
  }
105
118
 
106
119
  /** Homeostatic urgency routed to the affordance by its schema tags. */
107
120
  export function driveUrgency( a: Affordance, bias: BiasContext ): number {
108
121
  const t = a.tags
109
- if( t.includes( 'regulatory' ) || t.includes( 'self-care' ) || t.includes( 'rest' ) )
122
+ if( t.includes('regulatory') || t.includes('self-care') || t.includes('rest') )
110
123
  return Math.max( bias.drives.energy, bias.drives.sleep )
111
- if( t.includes( 'social' ) )
124
+
125
+ if( t.includes('social') )
112
126
  return bias.drives.social
113
- if( t.includes( 'self-protection' ) )
127
+
128
+ if( t.includes('self-protection') )
114
129
  return Math.max( bias.drives.stress, bias.threat )
130
+
115
131
  return 0
116
132
  }
117
133
 
@@ -131,7 +147,7 @@ export function scoreAffordance(
131
147
  bias: BiasContext,
132
148
  w: ScoreWeights = DEFAULT_WEIGHTS,
133
149
  ): number {
134
- return (
150
+ const raw = (
135
151
  w.goal * goalRelevance( a, bias )
136
152
  + w.reward * a.expectedReward
137
153
  + w.novelty * novelty( a )
@@ -142,6 +158,12 @@ export function scoreAffordance(
142
158
  - w.inhib * bias.inhibition
143
159
  - w.risk * risk( a, bias )
144
160
  )
161
+ // POLICY_REAFFERENCE P2 — policy availability damps a POSITIVE activation only,
162
+ // never flipping its sign: a refused ability competes weakly (so it is rarely
163
+ // chosen) yet is never removed from the field, keeping re-probe alive as
164
+ // availability recovers. Absent ⇒ 1 ⇒ no change (byte-identical quiet path).
165
+ const availability = a.availability ?? 1
166
+ return raw > 0 ? raw * availability : raw
145
167
  }
146
168
 
147
169
  /**
@@ -140,6 +140,15 @@ export interface Affordance {
140
140
  * competition WITHOUT bypassing it (the plan biases; the field still decides).
141
141
  */
142
142
  planBias?: number
143
+ /**
144
+ * Policy availability 0..1 (POLICY_REAFFERENCE P2) — learned from refusals,
145
+ * distinct from `available` (precondition satisfaction) and from competence.
146
+ * Present only when < 1 (a refusal has dented it); absent ⇒ fully available,
147
+ * so a never-refused Will's field is byte-identical. Damps positive activation
148
+ * in the competition without flipping its sign, so a suppressed ability still
149
+ * gets an occasional re-probe and can climb back as availability recovers.
150
+ */
151
+ availability?: number
143
152
  /** Provenance: the plan whose frontier step projected this affordance. */
144
153
  planId?: string
145
154
  /** Provenance: the frontier step id — flows through to action.outcome so the plan advances. */
@@ -73,11 +73,11 @@ interface Subscription {
73
73
  }
74
74
 
75
75
  function topicMatches( pattern: string, topic: string ): boolean {
76
- if( pattern === '*' ) return true // global workspace subscription
76
+ if( pattern === '*') return true // global workspace subscription
77
77
  if( pattern === topic ) return true
78
78
  if( pattern.endsWith('.*') ){
79
79
  const prefix = pattern.slice( 0, -2 )
80
- return topic === prefix || topic.startsWith( prefix + '.' )
80
+ return topic === prefix || topic.startsWith( prefix + '.')
81
81
  }
82
82
  return false
83
83
  }
@@ -70,7 +70,7 @@ export class CompletionInbox {
70
70
  for( const { label, apply } of batch ){
71
71
  try { apply() }
72
72
  catch( err ){
73
- logger.error( `[completion-inbox] "${label}" failed while landing at tick ${tick}:`, err )
73
+ logger.error(`[completion-inbox] "${label}" failed while landing at tick ${tick}:`, err )
74
74
  }
75
75
  }
76
76
 
@@ -21,11 +21,11 @@ export interface EngineConfigEntity {
21
21
  }
22
22
 
23
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' )
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
29
 
30
30
  return [
31
31
  // ── System metadata ──────────────────────────────────────────
@@ -84,7 +84,7 @@ export class DefaultEventLog implements EventLog {
84
84
  }
85
85
 
86
86
  private async _writeBatch( batch: CognitiveEvent[] ): Promise<void> {
87
- const lines = batch.map( e => JSON.stringify( e ) ).join( '\n' ) + '\n'
87
+ const lines = batch.map( e => JSON.stringify( e ) ).join('\n') + '\n'
88
88
  let existing = ''
89
89
 
90
90
  try {
@@ -92,7 +92,7 @@ export class DefaultEventLog implements EventLog {
92
92
  existing = await this._storage.read( this._path )
93
93
  } catch { /* file may not exist yet */ }
94
94
 
95
- await this._storage.ensureDir?.( this._path.replace( /\/[^/]+$/, '' ) )
95
+ await this._storage.ensureDir?.( this._path.replace( /\/[^/]+$/, '') )
96
96
  await this._storage.write( this._path, existing + lines )
97
97
  }
98
98
  }