@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,59 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/audition.engine/salience.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// Language salience — how much a given inbound message *matters*, before the
|
|
6
|
+
// per-entity novelty model (GenerativeModel.observe) modulates it.
|
|
7
|
+
//
|
|
8
|
+
// Pure + deterministic: a function of the message content, the speaker's
|
|
9
|
+
// attachment strength, and the Will's active-goal topics. No wall-clock — the
|
|
10
|
+
// score feeds attention allocation + GWT workspace gating, which are
|
|
11
|
+
// replay-sensitive, so it must not depend on non-deterministic time.
|
|
12
|
+
// "Recency/novelty" is handled separately by the per-entity GenerativeModel
|
|
13
|
+
// baseline (a normally-quiet entity suddenly speaking spikes), not here.
|
|
14
|
+
// ─────────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
export interface LanguageSalienceInput {
|
|
17
|
+
/** Raw message text. */
|
|
18
|
+
content: string
|
|
19
|
+
/** Speaker's attachment strength, 0–1 (0 = stranger / no bond). */
|
|
20
|
+
attachmentScore: number
|
|
21
|
+
/** Active-goal descriptions + tags, for topic-overlap detection. */
|
|
22
|
+
activeGoalText: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const URGENCY = /urgent|critical|help|asap|emergency|now\b/i
|
|
26
|
+
|
|
27
|
+
const clamp01 = ( n: number ): number => Math.max( 0, Math.min( 1, n ) )
|
|
28
|
+
|
|
29
|
+
/** True when the message shares a meaningful token with any active goal. */
|
|
30
|
+
function overlapsActiveGoal( content: string, activeGoalText: string[] ): boolean {
|
|
31
|
+
if( activeGoalText.length === 0 ) return false
|
|
32
|
+
const lc = content.toLowerCase()
|
|
33
|
+
for( const text of activeGoalText )
|
|
34
|
+
for( const word of text.toLowerCase().split( /\W+/ ) )
|
|
35
|
+
if( word.length > 3 && lc.includes( word ) ) return true
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compute language salience (0–1) for an inbound message.
|
|
41
|
+
*
|
|
42
|
+
* Weighting (sums, then clamps):
|
|
43
|
+
* - base 0.15 — a floor so a first/neutral message is non-trivial
|
|
44
|
+
* - urgency 0.30 — explicit urgency keywords
|
|
45
|
+
* - attachment 0.35 — closer relationship ⇒ more salient (the big lever)
|
|
46
|
+
* - goal 0.15 — topic overlaps an active goal
|
|
47
|
+
* - length 0.05 — longer ⇒ slightly more substantive (normalised to 200 chars)
|
|
48
|
+
*/
|
|
49
|
+
export function computeLanguageSalience( opts: LanguageSalienceInput ): number {
|
|
50
|
+
const { content, attachmentScore, activeGoalText } = opts
|
|
51
|
+
|
|
52
|
+
const base = 0.15
|
|
53
|
+
const urgency = URGENCY.test( content ) ? 0.30 : 0
|
|
54
|
+
const attach = clamp01( attachmentScore ) * 0.35
|
|
55
|
+
const goal = overlapsActiveGoal( content, activeGoalText ) ? 0.15 : 0
|
|
56
|
+
const length = Math.min( 1, content.length / 200 ) * 0.05
|
|
57
|
+
|
|
58
|
+
return clamp01( base + urgency + attach + goal + length )
|
|
59
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/base.sense.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* BaseSenseEngine — the shared perceptual pipeline (§6).
|
|
7
|
+
*
|
|
8
|
+
* Every sense engine repeats the same skeleton: CognitiveEngine boilerplate,
|
|
9
|
+
* an effector gate, a kind filter, and a percept publish on `senses.<domain>.percept`.
|
|
10
|
+
* This base captures all of it as a template method so each concrete engine only
|
|
11
|
+
* declares WHAT it senses (`domain`, `acceptedKinds`, optional `gateEffector`) and
|
|
12
|
+
* implements the domain-specific `_perceive()`.
|
|
13
|
+
*
|
|
14
|
+
* Flow (template method `ingest`):
|
|
15
|
+
* effector gate (optional) → kind filter → `_perceive(input)`
|
|
16
|
+
*
|
|
17
|
+
* `_perceive()` does the domain work and calls `publishPercept()` — the single
|
|
18
|
+
* chokepoint for emitting on the bus. That chokepoint is also where a future
|
|
19
|
+
* cross-modal binder would observe percepts of the same `sourceEntityId` across
|
|
20
|
+
* domains (see §6 cross-modal note).
|
|
21
|
+
*
|
|
22
|
+
* - `AuditionEngine` extends this and overrides `publishes()`/`snapshot()` for its
|
|
23
|
+
* extra `audition.task.signal` schema and session snapshot.
|
|
24
|
+
* - The four shell engines extend `ShellSenseEngine` (below) and are ~6 lines each.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { logger } from '#core/logger'
|
|
28
|
+
import type { CognitiveEvent, CognitiveBus } from '#cognition/bus'
|
|
29
|
+
import type { CognitiveEventSchema } from '#cognition/schema.registry'
|
|
30
|
+
import type { StateCommands } from '#core/types'
|
|
31
|
+
import type { AccessGrants } from '#agency/access.grants'
|
|
32
|
+
import type { SenseEngine, SensoryInput, SenseDomain, Percept } from '#senses/index'
|
|
33
|
+
|
|
34
|
+
export abstract class BaseSenseEngine implements SenseEngine {
|
|
35
|
+
abstract readonly name: string
|
|
36
|
+
abstract readonly domain: SenseDomain
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The `SensoryInput.kind` values this engine consumes. Inputs of any other
|
|
40
|
+
* kind are ignored silently by `ingest()` (no warning, no work) — this is how
|
|
41
|
+
* a single `ingestSensory(domain, input)` call can be routed leniently.
|
|
42
|
+
*/
|
|
43
|
+
protected abstract readonly acceptedKinds: ReadonlySet<SensoryInput['kind']>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Effector that gates ingestion (e.g. audition → 'listen'). When set and
|
|
47
|
+
* AccessGrants denies it, `ingest()` is a silent no-op — the engine stays
|
|
48
|
+
* wired but functionally inactive. `null` = always active.
|
|
49
|
+
*/
|
|
50
|
+
protected readonly gateEffector: string | null = null
|
|
51
|
+
|
|
52
|
+
protected _bus: CognitiveBus | null = null
|
|
53
|
+
protected _grants: AccessGrants | null = null
|
|
54
|
+
|
|
55
|
+
// ── Wiring ───────────────────────────────────────────────
|
|
56
|
+
attachBus( bus: CognitiveBus ): void { this._bus = bus }
|
|
57
|
+
/** Inject the AccessGrants so `ingest()` honours `gateEffector` (the permission gate). */
|
|
58
|
+
attachGrants( g: AccessGrants ): void { this._grants = g }
|
|
59
|
+
|
|
60
|
+
// ── CognitiveEngine defaults ─────────────────────────────
|
|
61
|
+
publishes(): CognitiveEventSchema[] {
|
|
62
|
+
return [ { type: `senses.${this.domain}.percept`, version: 1, validate: () => null } ]
|
|
63
|
+
}
|
|
64
|
+
subscribes(): string[] { return [] }
|
|
65
|
+
onCognitiveEvent( _e: CognitiveEvent ): StateCommands | void { /* sense engines are ingest-driven */ }
|
|
66
|
+
snapshot(): Record<string, unknown> { return { domain: this.domain } }
|
|
67
|
+
|
|
68
|
+
// ── SenseEngine: the shared template ─────────────────────
|
|
69
|
+
/**
|
|
70
|
+
* Apply the effector gate + kind filter common to every sense, then delegate
|
|
71
|
+
* the domain-specific work to `_perceive()`. Subclasses never re-handle gating
|
|
72
|
+
* or filtering — they only implement `_perceive()`.
|
|
73
|
+
*/
|
|
74
|
+
async ingest( input: SensoryInput ): Promise<void> {
|
|
75
|
+
// Permission gate — AccessGrants decides whether this sense may ingest.
|
|
76
|
+
if( this.gateEffector && this._grants && !this._grants.isAllowed( this.gateEffector ) ) return
|
|
77
|
+
if( !this.acceptedKinds.has( input.kind ) ) return
|
|
78
|
+
await this._perceive( input )
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Domain-specific perception. Invoked only for accepted kinds, past the gate. */
|
|
82
|
+
protected abstract _perceive( input: SensoryInput ): Promise<void>
|
|
83
|
+
|
|
84
|
+
// ── Shared helpers ───────────────────────────────────────
|
|
85
|
+
/**
|
|
86
|
+
* Publish a percept on this engine's `senses.<domain>.percept` topic. The
|
|
87
|
+
* single emit chokepoint — the AttentionAllocator (and, in future, a
|
|
88
|
+
* cross-modal binder) observes percepts here.
|
|
89
|
+
*/
|
|
90
|
+
protected publishPercept( percept: Percept ): void {
|
|
91
|
+
this._bus?.publish({
|
|
92
|
+
type: `senses.${this.domain}.percept`,
|
|
93
|
+
version: 1,
|
|
94
|
+
sourceEngine: this.name,
|
|
95
|
+
salience: percept.salience,
|
|
96
|
+
payload: percept,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* ShellSenseEngine — base for the not-yet-implemented senses
|
|
103
|
+
* (vision, somatosensation, olfaction, gustation).
|
|
104
|
+
*
|
|
105
|
+
* `_perceive()` logs a warning (only ever reached for an accepted kind, since the
|
|
106
|
+
* base filters first) and `snapshot()` advertises shell status. A concrete shell
|
|
107
|
+
* is just: `name`, `domain`, and `acceptedKinds`.
|
|
108
|
+
*/
|
|
109
|
+
export abstract class ShellSenseEngine extends BaseSenseEngine {
|
|
110
|
+
snapshot(): Record<string, unknown> {
|
|
111
|
+
return { domain: this.domain, status: 'shell' }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
protected async _perceive( _input: SensoryInput ): Promise<void> {
|
|
115
|
+
logger.warn( `[${this.name}] ingest() called — engine is a shell, not yet implemented.` )
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/gustation.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GustationEngine [SHELL] — taste / internal self-evaluation.
|
|
7
|
+
*
|
|
8
|
+
* Handles internal self-evaluation triggers and identity alignment checks —
|
|
9
|
+
* Will's "taste", introspective quality assessment of its own outputs and
|
|
10
|
+
* identity coherence after significant events. Future: post-action quality
|
|
11
|
+
* assessment into ConfidenceCalibrator / BiasDetector and SelfModelUpdater.
|
|
12
|
+
*
|
|
13
|
+
* Currently a structural stub — `_perceive()` (inherited from ShellSenseEngine)
|
|
14
|
+
* logs a warning and returns. The base handles gate / filter / publish / boilerplate.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SensoryInput } from '#senses/index'
|
|
18
|
+
import { ShellSenseEngine } from '#senses/base.sense.engine'
|
|
19
|
+
|
|
20
|
+
export class GustationEngine extends ShellSenseEngine {
|
|
21
|
+
readonly name = 'gustation-engine'
|
|
22
|
+
readonly domain = 'gustation' as const
|
|
23
|
+
protected readonly acceptedKinds = new Set<SensoryInput['kind']>( [ 'self-eval', 'assessment' ] )
|
|
24
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/index.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Perceptual Tier — 5 Senses Architecture
|
|
7
|
+
*
|
|
8
|
+
* Shared types and the SenseEngine interface for all sense engines.
|
|
9
|
+
* Sense engines are CognitiveEngines that also expose an `ingest()` method
|
|
10
|
+
* for external stimuli to enter Will's cognitive pipeline.
|
|
11
|
+
*
|
|
12
|
+
* Events flow on the existing CognitiveBus under the `senses.*` topic prefix:
|
|
13
|
+
* senses.audition.percept — LanguagePercept from AuditionEngine
|
|
14
|
+
* senses.vision.percept — (shell, future)
|
|
15
|
+
* senses.somatosensation.percept — (shell, future)
|
|
16
|
+
* senses.olfaction.percept — (shell, future)
|
|
17
|
+
* senses.gustation.percept — (shell, future)
|
|
18
|
+
*
|
|
19
|
+
* AttentionAllocator subscribes to 'senses.*' to receive all percepts.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import type { CognitiveEngine } from '#cognition/types'
|
|
23
|
+
import type { CognitiveBus } from '#cognition/bus'
|
|
24
|
+
|
|
25
|
+
// ── Domain ────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
export type SenseDomain =
|
|
28
|
+
| 'audition' // language, voice — AuditionEngine
|
|
29
|
+
| 'vision' // images, video — VisionEngine (shell)
|
|
30
|
+
| 'somatosensation' // webhooks, events — SomatosensationEngine (shell)
|
|
31
|
+
| 'olfaction' // ambient signals — OlfactionEngine (shell)
|
|
32
|
+
| 'gustation' // self-evaluation — GustationEngine (shell)
|
|
33
|
+
|
|
34
|
+
// ── Percept types ─────────────────────────────────────────────
|
|
35
|
+
|
|
36
|
+
/** Base percept published on the CognitiveBus. */
|
|
37
|
+
export interface Percept {
|
|
38
|
+
domain: SenseDomain
|
|
39
|
+
sourceEntityId: string
|
|
40
|
+
timestamp: number
|
|
41
|
+
salience: number // 0–1, computed by the sense engine
|
|
42
|
+
raw: unknown // original input object
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Audition-specific percept — carries language content and thread context. */
|
|
46
|
+
export interface LanguagePercept extends Percept {
|
|
47
|
+
domain: 'audition'
|
|
48
|
+
channel: 'text' | 'voice'
|
|
49
|
+
content: string
|
|
50
|
+
speakerEntityId: string
|
|
51
|
+
threadId: string
|
|
52
|
+
/** Rolling context: last N user + will turns in the thread. */
|
|
53
|
+
digest: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── Sensory input types (discriminated union) ─────────────────
|
|
57
|
+
|
|
58
|
+
// Audition
|
|
59
|
+
export interface TextMessage {
|
|
60
|
+
kind: 'text'
|
|
61
|
+
entityId: string
|
|
62
|
+
threadId: string
|
|
63
|
+
content: string
|
|
64
|
+
/** Display name — used in the facet focus content. */
|
|
65
|
+
speakerName?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface VoiceChunk {
|
|
69
|
+
kind: 'voice'
|
|
70
|
+
entityId: string
|
|
71
|
+
threadId: string
|
|
72
|
+
audioBuffer?: Buffer
|
|
73
|
+
transcription?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Vision (stub)
|
|
77
|
+
export interface ImageFrame {
|
|
78
|
+
kind: 'image'
|
|
79
|
+
entityId: string
|
|
80
|
+
data: Buffer
|
|
81
|
+
mimeType: string
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface VideoSegment {
|
|
85
|
+
kind: 'video'
|
|
86
|
+
entityId: string
|
|
87
|
+
frames: ImageFrame[]
|
|
88
|
+
durationMs: number
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Somatosensation (stub)
|
|
92
|
+
export interface WebhookEvent {
|
|
93
|
+
kind: 'webhook'
|
|
94
|
+
source: string
|
|
95
|
+
payload: unknown
|
|
96
|
+
headers: Record<string, string>
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface SystemSignal {
|
|
100
|
+
kind: 'system'
|
|
101
|
+
signal: string
|
|
102
|
+
data: unknown
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Olfaction (stub)
|
|
106
|
+
export interface AmbientMetric {
|
|
107
|
+
kind: 'ambient'
|
|
108
|
+
metricKey: string
|
|
109
|
+
value: number
|
|
110
|
+
trend: 'rising' | 'falling' | 'stable'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface BackgroundSignal {
|
|
114
|
+
kind: 'background'
|
|
115
|
+
category: string
|
|
116
|
+
data: unknown
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Gustation (stub)
|
|
120
|
+
export interface InternalEvaluation {
|
|
121
|
+
kind: 'self-eval'
|
|
122
|
+
context: string
|
|
123
|
+
trigger: string
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface SelfAssessmentTrigger {
|
|
127
|
+
kind: 'assessment'
|
|
128
|
+
goalId?: string
|
|
129
|
+
checkType: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Discriminated union of all sensory input kinds. */
|
|
133
|
+
export type SensoryInput =
|
|
134
|
+
| TextMessage
|
|
135
|
+
| VoiceChunk
|
|
136
|
+
| ImageFrame
|
|
137
|
+
| VideoSegment
|
|
138
|
+
| WebhookEvent
|
|
139
|
+
| SystemSignal
|
|
140
|
+
| AmbientMetric
|
|
141
|
+
| BackgroundSignal
|
|
142
|
+
| InternalEvaluation
|
|
143
|
+
| SelfAssessmentTrigger
|
|
144
|
+
|
|
145
|
+
// ── SenseEngine interface ─────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* SenseEngine — a CognitiveEngine that also accepts external stimuli.
|
|
149
|
+
*
|
|
150
|
+
* Sense engines implement the full CognitiveEngine contract
|
|
151
|
+
* (publishes, subscribes, onCognitiveEvent, snapshot) plus:
|
|
152
|
+
* - `domain`: declares which sensory domain this engine handles
|
|
153
|
+
* - `ingest()`: entry point for external stimuli (called by WillManager)
|
|
154
|
+
* - `attachBus()`: called automatically by CognitiveOrchestrator.addEngine()
|
|
155
|
+
*
|
|
156
|
+
* Shell engines have no-op `ingest()` bodies — they log a warning and return.
|
|
157
|
+
* Full engines (AuditionEngine) process percepts and publish to the bus.
|
|
158
|
+
*/
|
|
159
|
+
export interface SenseEngine extends CognitiveEngine {
|
|
160
|
+
readonly domain: SenseDomain
|
|
161
|
+
attachBus( bus: CognitiveBus ): void
|
|
162
|
+
ingest( input: SensoryInput ): Promise<void>
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ── Re-exports ────────────────────────────────────────────────
|
|
166
|
+
|
|
167
|
+
export { BaseSenseEngine, ShellSenseEngine } from './base.sense.engine'
|
|
168
|
+
export { AuditionEngine } from './audition.engine/engine'
|
|
169
|
+
export { VisionEngine } from './vision.engine'
|
|
170
|
+
export { SomatosensationEngine } from './somatosensation.engine'
|
|
171
|
+
export { OlfactionEngine } from './olfaction.engine'
|
|
172
|
+
export { GustationEngine } from './gustation.engine'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/olfaction.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OlfactionEngine [SHELL] — smell / ambient background monitoring.
|
|
7
|
+
*
|
|
8
|
+
* Handles ambient metrics and background signals — slow drifts and low-priority
|
|
9
|
+
* environmental monitoring. Will's "smell", detecting the ambient atmosphere
|
|
10
|
+
* before explicit events occur. Future: feed low-salience signals into
|
|
11
|
+
* AffectiveBlender for slow-burn mood modulation.
|
|
12
|
+
*
|
|
13
|
+
* Currently a structural stub — `_perceive()` (inherited from ShellSenseEngine)
|
|
14
|
+
* logs a warning and returns. The base handles gate / filter / publish / boilerplate.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { SensoryInput } from '#senses/index'
|
|
18
|
+
import { ShellSenseEngine } from '#senses/base.sense.engine'
|
|
19
|
+
|
|
20
|
+
export class OlfactionEngine extends ShellSenseEngine {
|
|
21
|
+
readonly name = 'olfaction-engine'
|
|
22
|
+
readonly domain = 'olfaction' as const
|
|
23
|
+
protected readonly acceptedKinds = new Set<SensoryInput['kind']>( [ 'ambient', 'background' ] )
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/somatosensation.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SomatosensationEngine [SHELL] — touch / physical-world interaction.
|
|
7
|
+
*
|
|
8
|
+
* Handles webhook events, system signals, and external API callbacks — Will's
|
|
9
|
+
* "touch", its awareness of interaction with external systems. Future: route
|
|
10
|
+
* incoming webhooks as percepts into ThreatEvaluator / RewardEvaluator.
|
|
11
|
+
*
|
|
12
|
+
* Currently a structural stub — `_perceive()` (inherited from ShellSenseEngine)
|
|
13
|
+
* logs a warning and returns. The base handles gate / filter / publish / boilerplate.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { SensoryInput } from '#senses/index'
|
|
17
|
+
import { ShellSenseEngine } from '#senses/base.sense.engine'
|
|
18
|
+
|
|
19
|
+
export class SomatosensationEngine extends ShellSenseEngine {
|
|
20
|
+
readonly name = 'somatosensation-engine'
|
|
21
|
+
readonly domain = 'somatosensation' as const
|
|
22
|
+
protected readonly acceptedKinds = new Set<SensoryInput['kind']>( [ 'webhook', 'system' ] )
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/senses/vision.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* VisionEngine [SHELL] — sight / visual perception.
|
|
7
|
+
*
|
|
8
|
+
* Future: multimodal LLM calls to interpret image frames and video segments;
|
|
9
|
+
* publishes `senses.vision.percept` events via the shared BaseSenseEngine flow.
|
|
10
|
+
*
|
|
11
|
+
* Currently a structural stub — `_perceive()` (inherited from ShellSenseEngine)
|
|
12
|
+
* logs a warning and returns. The base handles the effector gate, kind filter,
|
|
13
|
+
* percept publish, and CognitiveEngine boilerplate.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { SensoryInput } from '#senses/index'
|
|
17
|
+
import { ShellSenseEngine } from '#senses/base.sense.engine'
|
|
18
|
+
|
|
19
|
+
export class VisionEngine extends ShellSenseEngine {
|
|
20
|
+
readonly name = 'vision-engine'
|
|
21
|
+
readonly domain = 'vision' as const
|
|
22
|
+
protected readonly acceptedKinds = new Set<SensoryInput['kind']>( [ 'image', 'video' ] )
|
|
23
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────────────
|
|
2
|
+
// src/cognition/cognitive.engine.ts
|
|
3
|
+
// ─────────────────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CognitiveEngine — additive interface for engines that participate in the
|
|
7
|
+
* event-driven cognitive bus architecture.
|
|
8
|
+
*
|
|
9
|
+
* Any SimulationEngine can opt in by implementing these four methods.
|
|
10
|
+
* Engines that don't implement it continue to work normally via react().
|
|
11
|
+
* Migration can happen engine-by-engine with no orchestrator changes.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { StateCommands } from '#core/types'
|
|
15
|
+
import type { CognitiveEvent } from '#cognition/bus'
|
|
16
|
+
import type { SimulationEngine } from '#core/orchestrator'
|
|
17
|
+
import type { CognitiveEventSchema } from '#cognition/schema.registry'
|
|
18
|
+
|
|
19
|
+
// Re-export core engine types so cognition-layer files have one import point
|
|
20
|
+
export type { SimulationEngine, EngineResult, TickMiddleware } from '#core/orchestrator'
|
|
21
|
+
|
|
22
|
+
export interface CognitiveEngine extends SimulationEngine {
|
|
23
|
+
/** Event schemas this engine may publish — declared at registration time. */
|
|
24
|
+
publishes(): CognitiveEventSchema[]
|
|
25
|
+
|
|
26
|
+
/** Topic patterns this engine subscribes to — used for bus wiring and cycle detection. */
|
|
27
|
+
subscribes(): string[]
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Declare which schema versions this engine accepts for a given event type.
|
|
31
|
+
* If not implemented (or returns empty), any version is accepted.
|
|
32
|
+
* The bus will attempt migration before delivery when version is not in the list.
|
|
33
|
+
* Phase A: per-subscriber version filtering.
|
|
34
|
+
*/
|
|
35
|
+
acceptsVersions?( eventType: string ): number[]
|
|
36
|
+
|
|
37
|
+
/** Called by the bus on event delivery — never called concurrently. */
|
|
38
|
+
onCognitiveEvent( event: CognitiveEvent ): StateCommands | void
|
|
39
|
+
|
|
40
|
+
/** Full local state snapshot for cold-start bootstrap and debugging. */
|
|
41
|
+
snapshot(): Record<string, unknown>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Rehydrate engine-internal mutable state from a prior snapshot() payload (FN9).
|
|
45
|
+
*
|
|
46
|
+
* snapshot() captures private accumulating state (activity multipliers, salience
|
|
47
|
+
* baselines, generative-model predictions) that the event-sourced SimulationState
|
|
48
|
+
* never sees; restore() is the matching seam that lets a snapshot/replay reproduce
|
|
49
|
+
* it instead of resuming with freshly-zeroed internals. Optional and additive:
|
|
50
|
+
* engines that don't implement it keep their old behaviour, and a restore caller
|
|
51
|
+
* must treat it as best-effort (feature-detect before calling).
|
|
52
|
+
*/
|
|
53
|
+
restore?( snapshot: Record<string, unknown> ): void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isCognitiveEngine( engine: SimulationEngine ): engine is CognitiveEngine {
|
|
57
|
+
return (
|
|
58
|
+
typeof ( engine as CognitiveEngine ).publishes === 'function' &&
|
|
59
|
+
typeof ( engine as CognitiveEngine ).subscribes === 'function' &&
|
|
60
|
+
typeof ( engine as CognitiveEngine ).onCognitiveEvent === 'function' &&
|
|
61
|
+
typeof ( engine as CognitiveEngine ).snapshot === 'function'
|
|
62
|
+
)
|
|
63
|
+
}
|