@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.
- package/dist/channels/discord.d.ts +1 -1
- package/dist/channels/discord.js.map +1 -1
- package/dist/channels/whatsapp.d.ts +1 -1
- package/dist/channels/whatsapp.js.map +1 -1
- package/dist/cli.js +998 -59
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +998 -59
- package/dist/index.js.map +1 -1
- package/dist/mcp/effectors.d.ts +1 -1
- package/dist/mcp/effectors.js.map +1 -1
- package/dist/{will-BDq-TMQr.d.ts → will-DAW0l-lY.d.ts} +90 -10
- package/package.json +1 -1
- package/src/channels/discord.ts +11 -11
- package/src/channels/roster.ts +1 -1
- package/src/channels/types.ts +1 -1
- package/src/channels/whatsapp.ts +25 -25
- package/src/cli.ts +20 -20
- package/src/cognition/acp.ts +28 -0
- package/src/cognition/agency/consequence.ts +174 -0
- package/src/cognition/agency/engines/action.selector.ts +333 -48
- package/src/cognition/agency/engines/affordance.synthesizer.ts +35 -16
- package/src/cognition/agency/engines/deliberation.engine.ts +28 -14
- package/src/cognition/agency/engines/motor.schema.executor.ts +90 -14
- package/src/cognition/agency/engines/reafference.engine.ts +152 -23
- package/src/cognition/agency/execution.primitives.ts +13 -13
- package/src/cognition/agency/proactive.communicator.ts +1 -1
- package/src/cognition/agency/reconcile.learning.ts +10 -1
- package/src/cognition/agency/revocation.ts +79 -0
- package/src/cognition/agency/schemas/repertoire.ts +109 -9
- package/src/cognition/agency/selection.scoring.ts +32 -10
- package/src/cognition/agency/types.ts +9 -0
- package/src/cognition/bus.ts +2 -2
- package/src/cognition/completion.inbox.ts +1 -1
- package/src/cognition/config.mirror.entities.ts +5 -5
- package/src/cognition/event.log.ts +2 -2
- package/src/cognition/event.schemas.ts +67 -67
- package/src/cognition/faculties/aesthetic.evaluator.ts +6 -6
- package/src/cognition/faculties/affective.blender.ts +36 -4
- package/src/cognition/faculties/attachment.evaluator.ts +6 -6
- package/src/cognition/faculties/attention.allocator.ts +63 -8
- package/src/cognition/faculties/autobiographical.narrator.ts +3 -3
- package/src/cognition/faculties/bias.detector.ts +7 -7
- package/src/cognition/faculties/circadian.oscillator.ts +3 -3
- package/src/cognition/faculties/confidence.calibrator.ts +7 -7
- package/src/cognition/faculties/dream.simulator.ts +5 -5
- package/src/cognition/faculties/empathy.simulator.ts +7 -7
- package/src/cognition/faculties/energy.regulator.ts +4 -4
- package/src/cognition/faculties/episodic.consolidator.ts +6 -6
- package/src/cognition/faculties/executive.engine/commands.ts +6 -6
- package/src/cognition/faculties/executive.engine/context.ts +42 -42
- package/src/cognition/faculties/executive.engine/deferred.effects.ts +2 -2
- package/src/cognition/faculties/executive.engine/engine.ts +25 -25
- package/src/cognition/faculties/executive.engine/facet.supervisor.ts +12 -12
- package/src/cognition/faculties/executive.engine/facet.ts +18 -18
- package/src/cognition/faculties/executive.engine/gating.ts +2 -2
- package/src/cognition/faculties/executive.engine/messages.ts +3 -3
- package/src/cognition/faculties/executive.engine/parser.ts +11 -11
- package/src/cognition/faculties/executive.engine/prompt.factory.ts +55 -55
- package/src/cognition/faculties/exteroception.ts +99 -5
- package/src/cognition/faculties/forgetting.curve.ts +3 -3
- package/src/cognition/faculties/frustration.evaluator.ts +6 -6
- package/src/cognition/faculties/goal.manager.ts +15 -15
- package/src/cognition/faculties/inhibition.controller.ts +3 -3
- package/src/cognition/faculties/interoception.ts +3 -3
- package/src/cognition/faculties/introspection.engine.ts +3 -3
- package/src/cognition/faculties/known.entity.tracker.ts +15 -15
- package/src/cognition/faculties/loss.evaluator.ts +2 -2
- package/src/cognition/faculties/moral.evaluator.ts +4 -4
- package/src/cognition/faculties/novelty.detector.ts +4 -4
- package/src/cognition/faculties/persona.consolidator.ts +12 -12
- package/src/cognition/faculties/planning.engine/engine.ts +47 -47
- package/src/cognition/faculties/planning.engine/plan.frontier.ts +5 -5
- package/src/cognition/faculties/planning.engine/plan.store.ts +1 -1
- package/src/cognition/faculties/planning.engine/plan.supervision.ts +20 -20
- package/src/cognition/faculties/reputation.tracker.ts +6 -6
- package/src/cognition/faculties/reward.evaluator.ts +4 -4
- package/src/cognition/faculties/self.model.updater.ts +8 -8
- package/src/cognition/faculties/semantic.engine/integrator.ts +15 -15
- package/src/cognition/faculties/sleep.pressure.regulator.ts +4 -4
- package/src/cognition/faculties/social.perception.ts +3 -3
- package/src/cognition/faculties/spaced.repetition.ts +2 -2
- package/src/cognition/faculties/stress.regulator.ts +27 -4
- package/src/cognition/faculties/task.switcher.ts +11 -6
- package/src/cognition/faculties/theory.of.mind.ts +6 -6
- package/src/cognition/faculties/threat.evaluator.ts +3 -3
- package/src/cognition/faculties/working.memory.ts +8 -8
- package/src/cognition/generative.model.ts +2 -2
- package/src/cognition/memory/vector.adapter.ts +5 -5
- package/src/cognition/memory/vector.content.ts +4 -4
- package/src/cognition/memory/vector.embedder.ts +9 -9
- package/src/cognition/persona.prior.ts +1 -1
- package/src/cognition/schema.registry.ts +2 -2
- package/src/cognition/senses/audition.engine/engine.ts +2 -2
- package/src/cognition/senses/base.sense.engine.ts +1 -1
- package/src/cognition/utilities/token.tracker.ts +5 -5
- package/src/core/abstracts.ts +1 -1
- package/src/core/completion.recorder.ts +2 -2
- package/src/core/serialization.ts +3 -3
- package/src/core/snapshot.manager.ts +1 -1
- package/src/core/state.manager.ts +1 -1
- package/src/core/utils.ts +1 -1
- package/src/host/boot.ts +30 -30
- package/src/host/utterances.ts +1 -1
- package/src/llm/index.ts +9 -9
- package/src/llm/summarizer.ts +4 -4
- package/src/llm/wire.contracts.ts +1 -1
- package/src/mcp/effectors.ts +10 -10
- package/src/mcp/server.ts +11 -11
- package/src/pma/eval.ts +1 -1
- package/src/pma/index.ts +21 -21
- package/src/runners/outreach.runner.ts +3 -3
- package/src/runners/social.runner.ts +1 -1
- package/src/runners/thin-shim.runner.ts +1 -1
- package/src/sdk/will.ts +5 -5
- package/src/serve/server.ts +12 -12
- package/src/stem/assembly.audit.ts +3 -3
- package/src/stem/guards/identity.coherence.ts +10 -10
- package/src/stem/guards/identity.guard.ts +22 -22
- package/src/stem/index.ts +26 -11
- package/src/stem/mind.ts +12 -12
- package/src/stem/policy/arbiter.ts +136 -0
- package/src/stem/policy/rule.table.ts +172 -0
- package/src/stem/policy/verdict.recorder.ts +0 -0
- package/src/stem/tracts/biography.writer.ts +3 -3
- package/src/stem/tracts/effector.controller.ts +383 -4
- package/src/stem/tracts/health.reporter.ts +1 -1
- package/src/stem/tracts/outbox.controller.ts +4 -0
- package/src/stem/tracts/outbox.writer.ts +4 -4
- package/src/stem/tracts/pma.controller.ts +1 -1
- package/src/stem/tracts/replay.controller.ts +10 -10
- package/src/stem/tracts/sensory.controller.ts +2 -2
- package/src/stem/tracts/session.logger.ts +4 -4
- package/src/stem/tracts/transport/socketio.transport.ts +7 -7
- package/src/stem/tracts/transport/stream.transport.ts +2 -2
- package/src/stem/tracts/transport.controller.ts +15 -15
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/acp.ts — action-conditioned prediction constants
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// Shared by every ACP-P2 consumer (ACTION_CONDITIONED_PREDICTION §3) so the
|
|
6
|
+
// safety-relevant number cannot drift between engines. The pattern each
|
|
7
|
+
// consumer implements:
|
|
8
|
+
//
|
|
9
|
+
// 1. subscribe `agency.enacted` / `agency.communicate` / `agency.invocation`;
|
|
10
|
+
// 2. on any of them, setPrecision(stream, ACP_SELF_PRECISION) on the streams
|
|
11
|
+
// whose prediction errors are actually CONSUMED (gate or weight a
|
|
12
|
+
// publish) — anticipating unconsumed streams is theater;
|
|
13
|
+
// 3. restore precision to 1.0 explicitly after ONE observe in react() —
|
|
14
|
+
// GenerativeModel's own mean-reversion (0.02/observe ≈ 50 ticks) would
|
|
15
|
+
// keep dampening GENUINE world surprise arriving after our action.
|
|
16
|
+
//
|
|
17
|
+
// Measured on the first consumer (AttentionAllocator): after a stable
|
|
18
|
+
// stretch the salience denominator (EW variance) collapses, so any deviation
|
|
19
|
+
// saturates salience at 1.0 — precision is the only lever that stays
|
|
20
|
+
// measurable there; a conservative anticipate() nudge is invisible.
|
|
21
|
+
// ─────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The weight a self-caused observe carries. Below the executive's
|
|
25
|
+
* `WORKSPACE_THRESHOLD` (0.4) even when the base salience saturates at 1.0 —
|
|
26
|
+
* our own action's swing does not recruit our own executive.
|
|
27
|
+
*/
|
|
28
|
+
export const ACP_SELF_PRECISION = 0.35
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/agency/consequence.ts — expected-consequence descriptors
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// EXAFFERENCE P1. The efference copy predicts an action's *reward*; a
|
|
6
|
+
// consequence descriptor predicts its *sensory footprint* — what the world will
|
|
7
|
+
// look like because we acted. The MotorSchemaExecutor registers one at the
|
|
8
|
+
// enaction moment for world-facing actions only (delivered communicate, or the
|
|
9
|
+
// async communicate/external hold); sync innate enactions have internal effects
|
|
10
|
+
// and get none. Descriptors are ordinary entities, so they snapshot/restore and
|
|
11
|
+
// replay with the state (FN9), and they expire on a tick-denominated TTL that
|
|
12
|
+
// deliberately OUTLIVES intent resolution — a host ack does not stop the
|
|
13
|
+
// channel echo from arriving two ticks later.
|
|
14
|
+
//
|
|
15
|
+
// Dark in P1: written and expired, consumed by nothing. P2's corollary-
|
|
16
|
+
// discharge matcher reads them to tag percept provenance
|
|
17
|
+
// ('reafferent' | 'exafferent') and attenuate self-caused salience.
|
|
18
|
+
// Matching stays deterministic: FNV-1a content hashes, no clocks, no RNG.
|
|
19
|
+
// ─────────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
import type { EntityInput, Tick } from '#core/types'
|
|
22
|
+
|
|
23
|
+
export const CONSEQUENCE_TYPE = 'agency.consequence'
|
|
24
|
+
|
|
25
|
+
/** Salience multiplier applied to a matched (reafferent) percept — attenuated,
|
|
26
|
+
* not zeroed: a *surprising* consequence of our own action can still climb. */
|
|
27
|
+
export const ATTENUATION = 0.25
|
|
28
|
+
|
|
29
|
+
/** Minimum descriptor-text length for substring matching — below this a
|
|
30
|
+
* containment hit is too cheap to mean "these are my own words". */
|
|
31
|
+
export const MIN_TEXT_MATCH_LEN = 12
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Ticks a descriptor stays live — 2 × the executor's `AWAIT_TIMEOUT`, so a
|
|
35
|
+
* descriptor survives both a stranded await (15 ticks) and the late sensory
|
|
36
|
+
* echo of an already-reconciled action.
|
|
37
|
+
*/
|
|
38
|
+
export const CONSEQUENCE_TTL_TICKS = 30
|
|
39
|
+
|
|
40
|
+
export interface ConsequenceDescriptor {
|
|
41
|
+
/** The enacting intent — sensory reafference can reconcile to it (P5). */
|
|
42
|
+
intentId: string
|
|
43
|
+
schema: string
|
|
44
|
+
mode: 'communicate' | 'external'
|
|
45
|
+
/** Communication effector name (talk/text/gesture/broadcast), when known. */
|
|
46
|
+
effector?: string
|
|
47
|
+
targetEntityId?: string
|
|
48
|
+
/** FNV-1a over the authored outbound text (delivered communicate). */
|
|
49
|
+
textHash?: number
|
|
50
|
+
/** The authored outbound text itself — enables substring matching on echoes
|
|
51
|
+
* that arrive decorated ("Alice said: …"). Internal state, never emitted. */
|
|
52
|
+
text?: string
|
|
53
|
+
/** FNV-1a over the canonicalized parameters (async dispatch). */
|
|
54
|
+
paramsHash?: number
|
|
55
|
+
expiresAt: Tick
|
|
56
|
+
tick: Tick
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Deterministic 32-bit FNV-1a — the shared content-match key (P2 matcher uses the same). */
|
|
60
|
+
export function fnv1a( text: string ): number {
|
|
61
|
+
let h = 0x811c9dc5
|
|
62
|
+
for( let i = 0; i < text.length; i++ ){
|
|
63
|
+
h ^= text.charCodeAt( i )
|
|
64
|
+
h = Math.imul( h, 0x01000193 ) >>> 0
|
|
65
|
+
}
|
|
66
|
+
return h >>> 0
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Canonicalize parameters into a stable string before hashing: keys sorted
|
|
71
|
+
* recursively so `{a,b}` and `{b,a}` produce the same key. Deterministic and
|
|
72
|
+
* cheap; not a serialization format (never parsed back).
|
|
73
|
+
*/
|
|
74
|
+
export function paramsKey( value: unknown ): string {
|
|
75
|
+
if( value === null || typeof value !== 'object')
|
|
76
|
+
return typeof value === 'string' ? JSON.stringify( value ) : String( value )
|
|
77
|
+
if( Array.isArray( value ) )
|
|
78
|
+
return `[${ value.map( paramsKey ).join(',') }]`
|
|
79
|
+
const obj = value as Record<string, unknown>
|
|
80
|
+
const keys = Object.keys( obj ).sort()
|
|
81
|
+
return `{${ keys.map( k => `${ k }:${ paramsKey( obj[k] ) }` ).join(',') }}`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Build the descriptor entity (id keyed by intent — one footprint per enaction). */
|
|
85
|
+
export function consequenceEntity( d: ConsequenceDescriptor ): EntityInput {
|
|
86
|
+
return {
|
|
87
|
+
id: `agency-consequence-${ d.intentId }`,
|
|
88
|
+
type: CONSEQUENCE_TYPE,
|
|
89
|
+
metadata: { ...d },
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Read a descriptor back off entity metadata (P2 matcher + tests). */
|
|
94
|
+
export function readConsequence(
|
|
95
|
+
m: ReadonlyMap<string, unknown> | Record<string, unknown> | undefined,
|
|
96
|
+
): ConsequenceDescriptor | null {
|
|
97
|
+
const meta = ( m ?? {} ) as Record<string, unknown>
|
|
98
|
+
const intentId = typeof meta['intentId'] === 'string' ? meta['intentId'] as string : undefined
|
|
99
|
+
const schema = typeof meta['schema'] === 'string' ? meta['schema'] as string : undefined
|
|
100
|
+
const mode = meta['mode'] === 'communicate' || meta['mode'] === 'external' ? meta['mode'] : undefined
|
|
101
|
+
if( !intentId || !schema || !mode ) return null
|
|
102
|
+
return {
|
|
103
|
+
intentId, schema, mode,
|
|
104
|
+
effector: typeof meta['effector'] === 'string' ? meta['effector'] as string : undefined,
|
|
105
|
+
targetEntityId: typeof meta['targetEntityId'] === 'string' ? meta['targetEntityId'] as string : undefined,
|
|
106
|
+
textHash: typeof meta['textHash'] === 'number' ? meta['textHash'] as number : undefined,
|
|
107
|
+
text: typeof meta['text'] === 'string' ? meta['text'] as string : undefined,
|
|
108
|
+
paramsHash: typeof meta['paramsHash'] === 'number' ? meta['paramsHash'] as number : undefined,
|
|
109
|
+
expiresAt: typeof meta['expiresAt'] === 'number' ? meta['expiresAt'] as number : 0,
|
|
110
|
+
tick: typeof meta['tick'] === 'number' ? meta['tick'] as number : 0,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ── P2: the corollary-discharge matcher ──────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
/** Collect the live (unexpired) descriptors from frozen state, in stable id order. */
|
|
117
|
+
export function liveConsequences(
|
|
118
|
+
entities: ReadonlyMap<string, { type: string; metadata?: ReadonlyMap<string, unknown> | Record<string, unknown> }>,
|
|
119
|
+
tick: Tick,
|
|
120
|
+
): ConsequenceDescriptor[] {
|
|
121
|
+
const out: ConsequenceDescriptor[] = []
|
|
122
|
+
for( const [ , e ] of entities ){
|
|
123
|
+
if( e.type !== CONSEQUENCE_TYPE ) continue
|
|
124
|
+
const d = readConsequence( e.metadata )
|
|
125
|
+
if( d && tick < d.expiresAt ) out.push( d )
|
|
126
|
+
}
|
|
127
|
+
return out.sort( ( a, b ) => ( a.intentId < b.intentId ? -1 : a.intentId > b.intentId ? 1 : 0 ) )
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* High-precision text matching only (P2): a candidate text is *ours* when it
|
|
132
|
+
* hashes exactly to a descriptor's outbound text, or contains that text
|
|
133
|
+
* verbatim (echoes arrive decorated — "Alice said: …"). Deliberately NO
|
|
134
|
+
* entity-correspondence matching for external effectors yet: over-attribution
|
|
135
|
+
* (muting a genuine world event) is the dangerous direction; under-attribution
|
|
136
|
+
* is the status quo. Pure, deterministic, first match in stable order wins.
|
|
137
|
+
*/
|
|
138
|
+
export function matchConsequenceText(
|
|
139
|
+
descriptors: readonly ConsequenceDescriptor[],
|
|
140
|
+
candidate: string,
|
|
141
|
+
): ConsequenceDescriptor | null {
|
|
142
|
+
if( candidate.length === 0 ) return null
|
|
143
|
+
const candidateHash = fnv1a( candidate )
|
|
144
|
+
for( const d of descriptors ){
|
|
145
|
+
if( d.textHash !== undefined && d.textHash === candidateHash ) return d
|
|
146
|
+
if( d.text !== undefined && d.text.length >= MIN_TEXT_MATCH_LEN && candidate.includes( d.text ) ) return d
|
|
147
|
+
}
|
|
148
|
+
return null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── ACP-P1: entity correspondence (ACTION_CONDITIONED_PREDICTION §2) ─────────
|
|
152
|
+
|
|
153
|
+
/** Salience multiplier for an entity-correspondence match — gentler than a
|
|
154
|
+
* text match (0.25): the change is on our action's target while its
|
|
155
|
+
* descriptor lives, but we are less certain it is ours. */
|
|
156
|
+
export const CORRESPONDENCE_ATTENUATION = 0.5
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A live **external**-mode descriptor is a standing prediction that its
|
|
160
|
+
* `targetEntityId` is about to change *because of us*. A `modified` percept on
|
|
161
|
+
* exactly that entity is claimed as reafference (an `appeared` entity is new
|
|
162
|
+
* information, not our footprint). Communicate descriptors are excluded — the
|
|
163
|
+
* text path owns them. First match in stable order; pure.
|
|
164
|
+
*/
|
|
165
|
+
export function matchConsequenceEntity(
|
|
166
|
+
descriptors: readonly ConsequenceDescriptor[],
|
|
167
|
+
entityId: string,
|
|
168
|
+
changeType: string,
|
|
169
|
+
): ConsequenceDescriptor | null {
|
|
170
|
+
if( changeType !== 'modified' || entityId.length === 0 ) return null
|
|
171
|
+
for( const d of descriptors )
|
|
172
|
+
if( d.mode === 'external' && d.targetEntityId === entityId ) return d
|
|
173
|
+
return null
|
|
174
|
+
}
|