@mindot/will 0.7.0 → 0.9.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/README.md +87 -22
- package/dist/channels/discord.d.ts +67 -6
- package/dist/channels/discord.js +112 -6
- package/dist/channels/discord.js.map +1 -1
- package/dist/channels/whatsapp.d.ts +1 -1
- package/dist/channels/whatsapp.js +4 -1
- package/dist/channels/whatsapp.js.map +1 -1
- package/dist/cli.js +13733 -11057
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3729 -1199
- package/dist/index.js.map +1 -1
- package/dist/mcp/effectors.d.ts +1 -1
- package/dist/{will-DAW0l-lY.d.ts → will-DbDj_TEH.d.ts} +1214 -93
- package/package.json +1 -1
- package/src/channels/discord.ts +189 -11
- package/src/channels/types.ts +90 -0
- package/src/channels/whatsapp.ts +13 -4
- package/src/cli.ts +9 -4
- package/src/cognition/agency/consequence.ts +122 -1
- package/src/cognition/agency/conversation.aim.ts +260 -0
- package/src/cognition/agency/engines/action.selector.ts +85 -3
- package/src/cognition/agency/engines/affordance.synthesizer.ts +90 -1
- package/src/cognition/agency/engines/motor.schema.executor.ts +152 -10
- package/src/cognition/agency/engines/reafference.engine.ts +129 -2
- package/src/cognition/agency/proactive.communicator.ts +19 -3
- package/src/cognition/agency/reconcile.learning.ts +16 -2
- package/src/cognition/agency/restart.ts +66 -0
- package/src/cognition/agency/schemas/repertoire.ts +12 -5
- package/src/cognition/agency/selection.scoring.ts +33 -0
- package/src/cognition/agency/types.ts +35 -0
- package/src/cognition/cache/composition.ts +232 -0
- package/src/cognition/cache/deliberation.cache.ts +219 -0
- package/src/cognition/cache/fingerprint.ts +120 -0
- package/src/cognition/cache/types.ts +105 -0
- package/src/cognition/config.mirror.entities.ts +109 -1
- package/src/cognition/event.schemas.ts +22 -0
- package/src/cognition/faculties/autobiographical.narrator.ts +5 -10
- package/src/cognition/faculties/episodic.consolidator.ts +59 -3
- package/src/cognition/faculties/executive.engine/commands.ts +189 -14
- package/src/cognition/faculties/executive.engine/context.ts +67 -13
- package/src/cognition/faculties/executive.engine/deliberate.reasoning.ts +1 -1
- package/src/cognition/faculties/executive.engine/engine.ts +686 -187
- package/src/cognition/faculties/executive.engine/escalation.buffer.ts +162 -44
- package/src/cognition/faculties/executive.engine/facet.supervisor.ts +310 -65
- package/src/cognition/faculties/executive.engine/facet.ts +89 -26
- package/src/cognition/faculties/executive.engine/gating.ts +14 -14
- package/src/cognition/faculties/executive.engine/parser.ts +21 -1
- package/src/cognition/faculties/executive.engine/prompt.factory.ts +169 -20
- package/src/cognition/faculties/executive.engine/types.ts +69 -0
- package/src/cognition/faculties/goal.manager.ts +94 -14
- package/src/cognition/faculties/known.entity.tracker.ts +267 -28
- package/src/cognition/faculties/moral.evaluator.ts +8 -3
- package/src/cognition/faculties/persona.consolidator.ts +141 -0
- package/src/cognition/faculties/reputation.tracker.ts +66 -2
- package/src/cognition/faculties/self.model.updater.ts +19 -12
- package/src/cognition/faculties/social.perception.ts +47 -3
- package/src/cognition/faculties/threat.evaluator.ts +7 -0
- package/src/cognition/faculties/working.memory.ts +10 -20
- package/src/cognition/identity.entity.ts +205 -0
- package/src/cognition/index.ts +11 -0
- package/src/cognition/memory/vector.adapter.ts +12 -3
- package/src/cognition/memory/vector.embedder.ts +54 -7
- package/src/cognition/persona.prior.ts +6 -0
- package/src/cognition/senses/audition.engine/engine.ts +404 -46
- package/src/cognition/senses/base.sense.engine.ts +1 -1
- package/src/cognition/senses/index.ts +12 -0
- package/src/cognition/social.identity.ts +273 -0
- package/src/cognition/utilities/token.tracker.ts +246 -98
- package/src/core/orchestrator.ts +38 -0
- package/src/host/boot.ts +78 -22
- package/src/index.ts +35 -0
- package/src/llm/index.ts +415 -97
- package/src/llm/routing.ts +204 -0
- package/src/llm/summarizer.ts +5 -1
- package/src/llm/wire.contracts.ts +19 -0
- package/src/pma/index.ts +67 -53
- package/src/runners/thin-shim.runner.ts +18 -6
- package/src/sdk/will.ts +121 -22
- package/src/stem/assembly.audit.ts +1 -0
- package/src/stem/guards/identity.coherence.ts +17 -6
- package/src/stem/index.ts +82 -5
- package/src/stem/mind.ts +327 -79
- package/src/stem/policy/arbiter.ts +49 -14
- package/src/stem/policy/rule.table.ts +2 -2
- package/src/stem/tracts/effector.controller.ts +56 -9
- package/src/stem/tracts/outbox.writer.ts +40 -2
- package/src/cognition/faculties/executive.engine/messages.ts +0 -102
|
@@ -9,6 +9,9 @@ import type { ExecutiveSummarizer } from '#llm/summarizer'
|
|
|
9
9
|
import type { GoalManager } from '#faculties/goal.manager'
|
|
10
10
|
import type { GenerativeModel } from '#cognition/generative.model'
|
|
11
11
|
import type { SemanticIntegrator } from '#faculties/semantic.engine/integrator'
|
|
12
|
+
import { INNATE_SCHEMA_BY_ID } from '#agency/schemas/innate'
|
|
13
|
+
import { logger } from '#core/logger'
|
|
14
|
+
import { resolveKeid } from '#cognition/social.identity'
|
|
12
15
|
|
|
13
16
|
/** Maps the LLM's evidence enum to a numeric supportingEpisodes value for the belief store. */
|
|
14
17
|
export const EVIDENCE_TO_COUNT: Record<string, number> = {
|
|
@@ -168,10 +171,13 @@ export function buildStateCommands(
|
|
|
168
171
|
supportingEpisodes: belief.supportingEpisodes, tags: belief.tags } })
|
|
169
172
|
})
|
|
170
173
|
|
|
171
|
-
if( bus && ( u.name || u.feeling != null ) )
|
|
174
|
+
if( bus && ( u.name || u.feeling != null || u.sameAs ) )
|
|
172
175
|
effects.push( () => bus.publish({
|
|
173
176
|
type: 'known.entity.learned', version: 1, sourceEngine: 'executive',
|
|
174
|
-
|
|
177
|
+
// An identity verdict is worth more attention than a learned name: it
|
|
178
|
+
// reorganises everything the mind holds about two referents at once.
|
|
179
|
+
salience: u.sameAs ? 0.7 : 0.5,
|
|
180
|
+
payload: { keid: u.keid, name: u.name, feeling: u.feeling, sameAs: u.sameAs },
|
|
175
181
|
}) )
|
|
176
182
|
})
|
|
177
183
|
}
|
|
@@ -321,6 +327,32 @@ export function publishCognitiveEvents(
|
|
|
321
327
|
}
|
|
322
328
|
})
|
|
323
329
|
|
|
330
|
+
// agency.composite.proposed — the mind names a compound action as one skill.
|
|
331
|
+
//
|
|
332
|
+
// This is the creation seam for the instrumental→habitual gradient, and it had
|
|
333
|
+
// no producer: ReafferenceEngine subscribes to this event and its handler is the
|
|
334
|
+
// ONLY caller of SchemaRepertoire.registerComposite() anywhere in the tree, so
|
|
335
|
+
// until now no Will could hold a skill beyond the innate floor, for its entire
|
|
336
|
+
// life (#114). A capability the container offered and no tenant could reach.
|
|
337
|
+
//
|
|
338
|
+
// One event per proposal — the consumer registers them individually and drops
|
|
339
|
+
// anything with fewer than two sub-schemas, since a "composite" of one is just
|
|
340
|
+
// the schema it already had.
|
|
341
|
+
for( const skill of output.newSkills ?? [] )
|
|
342
|
+
bus.publish({
|
|
343
|
+
type: 'agency.composite.proposed',
|
|
344
|
+
version: 1,
|
|
345
|
+
sourceEngine: 'executive-engine',
|
|
346
|
+
salience: 0.7,
|
|
347
|
+
payload: {
|
|
348
|
+
id: skill.id,
|
|
349
|
+
composedOf: skill.composedOf,
|
|
350
|
+
...( skill.tags ? { tags: skill.tags } : {} ),
|
|
351
|
+
...( typeof skill.cost === 'number' ? { cost: skill.cost } : {} ),
|
|
352
|
+
tick: footprint.tickObserved,
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
|
|
324
356
|
// goal.proposed — when executive proposes new goals
|
|
325
357
|
if( output.newGoals?.length )
|
|
326
358
|
bus.publish({
|
|
@@ -372,20 +404,45 @@ export function publishCognitiveEvents(
|
|
|
372
404
|
})
|
|
373
405
|
}
|
|
374
406
|
|
|
375
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Action names that mean "say something to someone". Exported because the
|
|
409
|
+
* conversation facet partitions its OWN actions by the same rule (an action
|
|
410
|
+
* aimed at a third party is an intention the master owns, not a reply the facet
|
|
411
|
+
* may deliver) — one definition, so the two ends cannot drift apart.
|
|
412
|
+
*/
|
|
413
|
+
export const COMMUNICATE_ACTION_TYPES = new Set([
|
|
376
414
|
'communicate', 'speak', 'initiate_conversation', 'reach-out', 'reach_out', 'talk', 'text', 'message',
|
|
377
415
|
])
|
|
378
416
|
|
|
417
|
+
/** Arg keys a mind uses for the words themselves — folded into `gist` (see below). */
|
|
418
|
+
const WORDS_ARG_KEYS = new Set([ 'content', 'message', 'text', 'body' ])
|
|
419
|
+
/** Arg keys naming the addressee — already resolved into `targetEntityId`. */
|
|
420
|
+
const ADDRESS_ARG_KEYS = new Set([ 'to', 'recipient', 'target', 'targetEntityId', 'entityId' ])
|
|
421
|
+
|
|
379
422
|
/** Resolve an executive action target (a display name OR a keid) to a known-entity keid. */
|
|
380
423
|
function resolveKnownEntity( target: string, state: ReadonlySimulationState ): string | undefined {
|
|
381
|
-
|
|
424
|
+
// THE resolver, shared with everything else that has to turn a reference into a
|
|
425
|
+
// referent. This was a private scan matching an exact keid or an exact name and
|
|
426
|
+
// consulting no alias table — so once dossiers were keyed by an anchor, naming
|
|
427
|
+
// someone by the address they were met at (`discord:1019…`) matched nothing and
|
|
428
|
+
// the whole intention evaporated silently, which is the failure this function's
|
|
429
|
+
// own logging exists to make visible.
|
|
430
|
+
return resolveKeid( state.entities as never, target )
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The name the mind has LEARNED for this entity. The outreach facet addresses someone
|
|
435
|
+
* by it ("I have decided to reach out to ${ name }"), so a keid leaking through here
|
|
436
|
+
* would have the mind reaching out to `discord:1019376031150379101`. Undefined when
|
|
437
|
+
* unlearned — the caller omits it rather than substituting a placeholder.
|
|
438
|
+
*/
|
|
439
|
+
function knownEntityName( keid: string, state: ReadonlySimulationState ): string | undefined {
|
|
382
440
|
for( const e of state.entities.values() ){
|
|
383
441
|
if( e.type !== 'known-entity') continue
|
|
384
|
-
const m
|
|
385
|
-
|
|
386
|
-
const name = typeof m
|
|
387
|
-
|
|
388
|
-
if( name && name.toLowerCase() === t ) return keid
|
|
442
|
+
const m = e.metadata as Record<string, unknown> | undefined
|
|
443
|
+
if( m?.['keid'] !== keid ) continue
|
|
444
|
+
const name = typeof m['name'] === 'string' ? m['name'].trim() : ''
|
|
445
|
+
return name.length > 0 ? name : undefined
|
|
389
446
|
}
|
|
390
447
|
return undefined
|
|
391
448
|
}
|
|
@@ -408,6 +465,10 @@ function buildIdeomotorIntents(
|
|
|
408
465
|
): { set: EntityInput[]; delete: string[] } {
|
|
409
466
|
const set: EntityInput[] = []
|
|
410
467
|
const seen = new Set<string>()
|
|
468
|
+
/** Action names that named nothing this cycle — surfaced back to the mind below. */
|
|
469
|
+
const unresolved = new Set<string>()
|
|
470
|
+
/** Addressees the mind meant to reach but cannot resolve to anyone it knows. */
|
|
471
|
+
const unaddressed = new Set<string>()
|
|
411
472
|
const priority = clamp01( output.confidence ?? 0.8 )
|
|
412
473
|
|
|
413
474
|
// The host abilities currently afforded (source 'external' in the live field) —
|
|
@@ -425,21 +486,83 @@ function buildIdeomotorIntents(
|
|
|
425
486
|
const t = action.type.toLowerCase()
|
|
426
487
|
|
|
427
488
|
if( COMMUNICATE_ACTION_TYPES.has( t ) ){
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
489
|
+
// The addressee may be named on the action OR inside the args the executive
|
|
490
|
+
// authored. This used to read `action.target` alone and `continue` when it
|
|
491
|
+
// was absent — but the output guidelines document actions as
|
|
492
|
+
// `{type, reasoning, expectedOutcome}` and tell the mind to put specifics
|
|
493
|
+
// in `args`, so `args.to` is precisely what a well-behaved mind produces.
|
|
494
|
+
// A Will would write real sentences into `args.to`/`args.content`, the
|
|
495
|
+
// intent was never created, nothing competed, nothing was ever enqueued —
|
|
496
|
+
// and reafference then taught it that talking to that PERSON does not work.
|
|
497
|
+
const args = ( action.args && typeof action.args === 'object' ? action.args : {} ) as Record<string, unknown>
|
|
498
|
+
const named = [ action.target, args['to'], args['recipient'], args['target'], args['targetEntityId'], args['entityId'] ]
|
|
499
|
+
.find( v => typeof v === 'string' && v.trim().length > 0 ) as string | undefined
|
|
500
|
+
// Naming NOBODY and naming someone unreachable are different failures, and
|
|
501
|
+
// both used to `continue` in silence — the intent was never created, nothing
|
|
502
|
+
// competed, and the mind had no way to find out. Observed: a facet decided to
|
|
503
|
+
// contact a colleague by a name the mind had heard in conversation but never
|
|
504
|
+
// bound to a dossier; the whole intention evaporated without a trace, and the
|
|
505
|
+
// person it had just promised never heard from it.
|
|
506
|
+
if( !named ){ unaddressed.add('(no one)'); continue }
|
|
507
|
+
const keid = resolveKnownEntity( named, state )
|
|
508
|
+
if( !keid ){ unaddressed.add( named ); continue }
|
|
509
|
+
if( seen.has( keid ) ) continue
|
|
431
510
|
seen.add( keid )
|
|
511
|
+
// The master forms the INTENT; it does not author the words. Whatever it wrote
|
|
512
|
+
// is the DIRECTION for the outreach facet (AuditionEngine.authorOutreach) to
|
|
513
|
+
// speak in — so it lands in `gist`, never `content`. This is load-bearing:
|
|
514
|
+
// MotorSchemaExecutor._deliver sends `parameters.content` VERBATIM and only
|
|
515
|
+
// falls back to the facet when it is empty, so carrying the master's sentences
|
|
516
|
+
// as `content` would put the master itself in a second, parallel conversation
|
|
517
|
+
// with someone a conversation facet may already be talking to — one mind
|
|
518
|
+
// holding two threads with one person about one thing. `gist` was read in
|
|
519
|
+
// three places and written nowhere; this is what writes it.
|
|
520
|
+
const said = [ ...WORDS_ARG_KEYS ]
|
|
521
|
+
.map( k => args[ k ] )
|
|
522
|
+
.find( v => typeof v === 'string' && v.trim().length > 0 ) as string | undefined
|
|
523
|
+
const parameters: Record<string, unknown> = {}
|
|
524
|
+
for( const [ k, v ] of Object.entries( args ) )
|
|
525
|
+
if( !WORDS_ARG_KEYS.has( k ) && !ADDRESS_ARG_KEYS.has( k ) ) parameters[ k ] = v
|
|
526
|
+
if( said ) parameters['gist'] = said
|
|
527
|
+
const targetName = knownEntityName( keid, state )
|
|
528
|
+
if( targetName ) parameters['targetEntityName'] = targetName
|
|
529
|
+
|
|
530
|
+
// Named at INFO because this is the seam where a decision to contact someone
|
|
531
|
+
// either becomes a competing intention or disappears. When a Will named a
|
|
532
|
+
// colleague seven times over ten minutes and he never heard from it, nothing
|
|
533
|
+
// in the logs could distinguish "the intent was never created" from "it was
|
|
534
|
+
// created and lost every competition" — the two have completely different
|
|
535
|
+
// fixes, and the archaeology to tell them apart needed state snapshots that
|
|
536
|
+
// sample too coarsely to catch a cycle.
|
|
537
|
+
logger.info(
|
|
538
|
+
`[executive] willed reach-out → ${ targetName ?? keid } ` +
|
|
539
|
+
`(named '${ named }' → ${ keid }, priority=${ priority.toFixed( 2 ) })`
|
|
540
|
+
)
|
|
541
|
+
|
|
432
542
|
set.push({
|
|
433
543
|
id: `ideomotor-reach-out-${ keid }`,
|
|
434
544
|
type: 'ideomotor.intent',
|
|
435
|
-
metadata: {
|
|
545
|
+
metadata: {
|
|
546
|
+
schema: 'reach-out', targetEntityId: keid,
|
|
547
|
+
...( Object.keys( parameters ).length > 0 ? { parameters } : {} ),
|
|
548
|
+
priority, origin: 'executive', tick: footprint.tickObserved,
|
|
549
|
+
},
|
|
436
550
|
})
|
|
437
551
|
continue
|
|
438
552
|
}
|
|
439
553
|
|
|
440
554
|
// A host ability the executive imagines enacting, with its conscious args.
|
|
441
555
|
const schema = externalBySchema.get( t )
|
|
442
|
-
if( !schema
|
|
556
|
+
if( !schema ){
|
|
557
|
+
// The name resolves to NOTHING: not a communicate type, not an innate
|
|
558
|
+
// stance, not an ability the field affords. Record it so the mind can find
|
|
559
|
+
// out. Silence here is what let a Will spend eleven consecutive actions on
|
|
560
|
+
// an invented `query`, observe that nothing ever came of them, and conclude
|
|
561
|
+
// its MEMORY was broken — the one explanation that was not true.
|
|
562
|
+
if( !INNATE_SCHEMA_BY_ID.has( t ) ) unresolved.add( action.type )
|
|
563
|
+
continue
|
|
564
|
+
}
|
|
565
|
+
if( seen.has(`ability:${ schema }`) ) continue
|
|
443
566
|
seen.add(`ability:${ schema }`)
|
|
444
567
|
const keid = action.target ? resolveKnownEntity( action.target, state ) : undefined
|
|
445
568
|
set.push({
|
|
@@ -454,6 +577,51 @@ function buildIdeomotorIntents(
|
|
|
454
577
|
})
|
|
455
578
|
}
|
|
456
579
|
|
|
580
|
+
// An action that named nothing is REPORTED, not swallowed.
|
|
581
|
+
//
|
|
582
|
+
// The executive's actions bias the agency competition; they are not commands, so
|
|
583
|
+
// a name that matches no schema is not a dispatch error and nothing downstream
|
|
584
|
+
// ever objected. But an unopposed no-op is indistinguishable from an act that
|
|
585
|
+
// was tried and achieved nothing, and the mind reasons from the difference.
|
|
586
|
+
// Observed: eleven consecutive `query` actions (a name that does not exist),
|
|
587
|
+
// then "five consecutive queries with no memory trace is a failure mode" and a
|
|
588
|
+
// plan to diagnose its own memory. Telling it the name was not real costs one
|
|
589
|
+
// entity and removes a whole class of false self-belief.
|
|
590
|
+
if( unresolved.size > 0 )
|
|
591
|
+
set.push({
|
|
592
|
+
id: 'action.unresolved',
|
|
593
|
+
type: 'action.unresolved',
|
|
594
|
+
metadata: {
|
|
595
|
+
names: [ ...unresolved ],
|
|
596
|
+
summary: `I named ${ [ ...unresolved ].map( n => `'${ n }'` ).join(', ') } as an action, but ${ unresolved.size > 1 ? 'those are not things' : 'that is not a thing' } I can do — no such ability is in my repertoire or afforded right now. Nothing happened. To act I have to name something I actually have.`,
|
|
597
|
+
salience: 0.75,
|
|
598
|
+
origin: 'executive',
|
|
599
|
+
tick: footprint.tickObserved,
|
|
600
|
+
},
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
// An addressee that resolves to nobody is REPORTED, not swallowed.
|
|
604
|
+
//
|
|
605
|
+
// Same principle as the unresolved-name report above, one layer down: there the
|
|
606
|
+
// *verb* named nothing, here the *person* does. The mind can hear a name in
|
|
607
|
+
// conversation ("coordinate that through FKEM") long before that name is bound
|
|
608
|
+
// to anyone it can actually reach, and reaching-out to an unbound name simply
|
|
609
|
+
// does not happen. Told, it can do the human thing — ask how to reach them, or
|
|
610
|
+
// ask whoever mentioned them to make the introduction. Untold, it believes it
|
|
611
|
+
// made contact and follows up on a message it never sent.
|
|
612
|
+
if( unaddressed.size > 0 )
|
|
613
|
+
set.push({
|
|
614
|
+
id: 'action.unaddressed',
|
|
615
|
+
type: 'action.unaddressed',
|
|
616
|
+
metadata: {
|
|
617
|
+
names: [ ...unaddressed ],
|
|
618
|
+
summary: `I meant to reach ${ [ ...unaddressed ].map( n => `'${ n }'` ).join(', ') }, but ${ unaddressed.size > 1 ? 'those names match no one' : 'that name matches no one' } I know how to contact — no message went out. If I want to reach them I need a way to: someone can introduce us, or tell me where to find them.`,
|
|
619
|
+
salience: 0.8,
|
|
620
|
+
origin: 'executive',
|
|
621
|
+
tick: footprint.tickObserved,
|
|
622
|
+
},
|
|
623
|
+
})
|
|
624
|
+
|
|
457
625
|
// Clear stale executive-sourced intents the executive no longer imagines this cycle.
|
|
458
626
|
const currentIds = new Set( set.map( s => s.id ) )
|
|
459
627
|
const del: string[] = []
|
|
@@ -463,6 +631,13 @@ function buildIdeomotorIntents(
|
|
|
463
631
|
&& !currentIds.has( id ) )
|
|
464
632
|
del.push( id )
|
|
465
633
|
|
|
634
|
+
// Clear the report once the mind names only real actions again — it should read
|
|
635
|
+
// as "that last attempt was not a thing", not as a permanent defect in itself.
|
|
636
|
+
if( unresolved.size === 0 && state.entities.has('action.unresolved') )
|
|
637
|
+
del.push('action.unresolved')
|
|
638
|
+
if( unaddressed.size === 0 && state.entities.has('action.unaddressed') )
|
|
639
|
+
del.push('action.unaddressed')
|
|
640
|
+
|
|
466
641
|
return { set, delete: del }
|
|
467
642
|
}
|
|
468
643
|
|
|
@@ -9,6 +9,13 @@ import type { ExecutiveContext } from '#faculties/executive.engine/types'
|
|
|
9
9
|
import type { EpisodicConsolidator } from '#faculties/episodic.consolidator'
|
|
10
10
|
import type { SemanticIntegrator } from '#faculties/semantic.engine/integrator'
|
|
11
11
|
import { readEffectiveParams, summarizePersonaPrior } from '#cognition/persona.prior'
|
|
12
|
+
import { readIdentityName } from '#cognition/identity.entity'
|
|
13
|
+
import { readSpokenTurns } from '#agency/conversation.aim'
|
|
14
|
+
import { nameOf as referentName } from '#cognition/social.identity'
|
|
15
|
+
|
|
16
|
+
/** How many of the mind's own recent utterances it is shown. Enough to notice a
|
|
17
|
+
* repetition, few enough not to crowd out what is happening now. */
|
|
18
|
+
const SPOKEN_TURNS_SHOWN = 6
|
|
12
19
|
|
|
13
20
|
export interface ContextDependencies {
|
|
14
21
|
workingMemory: WorkingMemory | null
|
|
@@ -32,8 +39,10 @@ export async function buildExecutiveContext(
|
|
|
32
39
|
// Identity — read directly from the identity-self entity.
|
|
33
40
|
const identityEntity = state.entities.get('identity-self')
|
|
34
41
|
// name is the canonical persona name from WillConfig.name (e.g. "Aria", "Guard-1").
|
|
35
|
-
//
|
|
36
|
-
|
|
42
|
+
// '' when unknown — NEVER a default. This read used to end in `?? 'Will'`, which
|
|
43
|
+
// is how the container's name reached a tenant's own prompt. See
|
|
44
|
+
// cognition/identity.entity for what that cost.
|
|
45
|
+
const identityName = readIdentityName( state )
|
|
37
46
|
const identityPrompt = (identityEntity?.metadata?.prompt as string) ?? 'I am a self-aware mind.'
|
|
38
47
|
const identityValues = (identityEntity?.metadata?.values as string[]) ?? []
|
|
39
48
|
const identityTraits = (identityEntity?.metadata?.traits as Record<string, number>) ?? {}
|
|
@@ -275,6 +284,37 @@ export async function buildExecutiveContext(
|
|
|
275
284
|
recentActions.sort( ( a, b ) => b.tick - a.tick )
|
|
276
285
|
const recentActionsCapped = recentActions.slice( 0, 5 )
|
|
277
286
|
|
|
287
|
+
// Current best name for a person, from the known-entity roster.
|
|
288
|
+
const nameOf = ( keid: string ): string | undefined => {
|
|
289
|
+
for( const e of state.entities.values() ){
|
|
290
|
+
if( e.type !== 'known-entity') continue
|
|
291
|
+
const m = e.metadata ?? {}
|
|
292
|
+
if( m['keid'] !== keid ) continue
|
|
293
|
+
const n = m['name']
|
|
294
|
+
return typeof n === 'string' && n.trim() ? n : undefined
|
|
295
|
+
}
|
|
296
|
+
return undefined
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// What the mind has said to people lately, and who answered. Newest first,
|
|
300
|
+
// capped — this is a reminder, not a transcript; the conversation itself lives
|
|
301
|
+
// in memory and in "## In Conversation Now".
|
|
302
|
+
const spokenTurns: ExecutiveContext['spokenTurns'] = readSpokenTurns( state.entities )
|
|
303
|
+
.filter( t => !t.isAck )
|
|
304
|
+
.reverse()
|
|
305
|
+
.slice( 0, SPOKEN_TURNS_SHOWN )
|
|
306
|
+
.map( t => ({
|
|
307
|
+
// Roster first, the record's stored name second. A name is learned over
|
|
308
|
+
// time, so records written before the mind knew it keep the raw id — and
|
|
309
|
+
// the same person rendered as both `FKEM` and `discord:15255…` in one list,
|
|
310
|
+
// which reads as two people. The roster holds the current best name.
|
|
311
|
+
target: nameOf( t.targetEntityId ) ?? t.targetEntityName ?? t.targetEntityId,
|
|
312
|
+
preview: t.preview,
|
|
313
|
+
age: Math.max( 0, state.tick - t.tick ),
|
|
314
|
+
answered: t.answeredAt !== undefined,
|
|
315
|
+
...( t.answeredWith ? { answeredWith: t.answeredWith } : {} ),
|
|
316
|
+
}) )
|
|
317
|
+
|
|
278
318
|
// Active/known plans — read persisted `plan` entities so the executive has
|
|
279
319
|
// execution awareness: which plans exist per goal, their status + step
|
|
280
320
|
// progress, enabling it to target a specific plan by id when managing several. (P4)
|
|
@@ -328,6 +368,7 @@ export async function buildExecutiveContext(
|
|
|
328
368
|
beliefs,
|
|
329
369
|
beliefsOmitted,
|
|
330
370
|
recentActions: recentActionsCapped,
|
|
371
|
+
spokenTurns,
|
|
331
372
|
behavioralDisposition,
|
|
332
373
|
selfTuning,
|
|
333
374
|
knownEntities: extractKnownEntities( state ),
|
|
@@ -436,6 +477,25 @@ export function extractKnownEntities( state: ReadonlySimulationState ): Executiv
|
|
|
436
477
|
if( typeof m.name === 'string') a.name = m.name
|
|
437
478
|
if( m.kind === 'thing' || m.kind === 'sentient') a.kind = m.kind as 'thing' | 'sentient'
|
|
438
479
|
if( typeof m.reliability === 'number') a.reliability = m.reliability as number
|
|
480
|
+
|
|
481
|
+
// The routes, so choosing where to say something is a decision the mind
|
|
482
|
+
// makes rather than a fallback the plumbing makes for it.
|
|
483
|
+
if( Array.isArray( m.handles ) )
|
|
484
|
+
a.handles = ( m.handles as Array<{ keid?: string; kind?: string; lastAnsweredTick?: number }> )
|
|
485
|
+
.filter( h => typeof h?.keid === 'string')
|
|
486
|
+
.map( h => ({
|
|
487
|
+
keid: h.keid!,
|
|
488
|
+
kind: h.kind ?? 'unknown',
|
|
489
|
+
...( typeof h.lastAnsweredTick === 'number'
|
|
490
|
+
? { answeredAgo: Math.max( 0, state.tick - h.lastAnsweredTick ) } : {} ),
|
|
491
|
+
}) )
|
|
492
|
+
|
|
493
|
+
// An identity the mind has not settled. Carried as NAMES where it knows
|
|
494
|
+
// them, because a raw keid in a prompt is noise it cannot act on.
|
|
495
|
+
if( Array.isArray( m.suspectedSameAs ) )
|
|
496
|
+
a.mayBeSameAs = ( m.suspectedSameAs as string[] )
|
|
497
|
+
.map( k => referentName( state.entities, k ) )
|
|
498
|
+
.filter( ( n ): n is string => !!n )
|
|
439
499
|
a._recency = Math.max( a._recency, ( m.lastSeenTick as number ) ?? 0 )
|
|
440
500
|
}
|
|
441
501
|
else if( e.type === 'attachment.bond'){
|
|
@@ -473,17 +533,11 @@ function buildSemanticQuery(
|
|
|
473
533
|
const dominantEmotion = valence > 0.3 ? 'positive' : valence < -0.3 ? 'negative' : 'neutral'
|
|
474
534
|
if( dominantEmotion !== 'neutral') parts.push(`Feeling ${dominantEmotion}`)
|
|
475
535
|
|
|
476
|
-
//
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
if( state.tick - msgTick > 30 ) continue
|
|
482
|
-
if( entity.metadata?.processedByExecutive ) continue
|
|
483
|
-
const name = entity.metadata?.agentName as string | undefined
|
|
484
|
-
if( name && name !== 'unknown') senderNames.add( name )
|
|
485
|
-
}
|
|
486
|
-
if( senderNames.size > 0 ) parts.push(`Talking with: ${[ ...senderNames ].join(', ')}`)
|
|
536
|
+
// A "Talking with: …" hint used to be built here from `communication` entities.
|
|
537
|
+
// Nothing has ever written that type (#114), so the clause never fired. Removed
|
|
538
|
+
// rather than repointed: the inbound entity that now exists (`conversation.received`)
|
|
539
|
+
// is consumed within one tick, so it is not a dependable source for a recall hint —
|
|
540
|
+
// restoring this wants a durable interlocutor signal, which is its own decision.
|
|
487
541
|
|
|
488
542
|
// Recent percepts (top 3 by salience)
|
|
489
543
|
const percepts = extractPercepts( state ).slice( 0, 3 )
|
|
@@ -49,7 +49,7 @@ export async function proposeCandidates( params: ProposeParams ): Promise<Ideati
|
|
|
49
49
|
try {
|
|
50
50
|
const result = await params.director.call(
|
|
51
51
|
params.systemPrompt, params.ideationUserMessage, params.tick, params.proposeTemperature,
|
|
52
|
-
params.meta ?? { category: 'executive', attribute: 'master',
|
|
52
|
+
params.meta ?? { category: 'executive', attribute: 'master', process: 'ideation', function: '-' }
|
|
53
53
|
)
|
|
54
54
|
const candidates = parseIdeation( result.text ).candidates
|
|
55
55
|
return candidates.length > 0 ? candidates : undefined
|