@mindot/will 0.3.0 → 0.5.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 (57) hide show
  1. package/README.md +63 -21
  2. package/dist/channels/discord.d.ts +69 -0
  3. package/dist/channels/discord.js +193 -0
  4. package/dist/channels/discord.js.map +1 -0
  5. package/dist/channels/whatsapp.d.ts +72 -0
  6. package/dist/channels/whatsapp.js +252 -0
  7. package/dist/channels/whatsapp.js.map +1 -0
  8. package/dist/cli.js +904 -356
  9. package/dist/cli.js.map +1 -1
  10. package/dist/index.d.ts +141 -141
  11. package/dist/index.js +441 -342
  12. package/dist/index.js.map +1 -1
  13. package/dist/mcp/effectors.d.ts +1 -1
  14. package/dist/types-E9-HV-SW.d.ts +11 -0
  15. package/dist/{will-B5eKs3Wv.d.ts → will-BDq-TMQr.d.ts} +4013 -3916
  16. package/package.json +17 -3
  17. package/src/channels/discord.ts +214 -0
  18. package/src/channels/roster.ts +87 -0
  19. package/src/channels/types.ts +46 -0
  20. package/src/channels/whatsapp.ts +318 -0
  21. package/src/cli.ts +57 -9
  22. package/src/cognition/agency/engines/deliberation.engine.ts +7 -7
  23. package/src/cognition/agency/execution.primitives.ts +11 -11
  24. package/src/cognition/agency/proactive.communicator.ts +8 -8
  25. package/src/cognition/config.mirror.entities.ts +2 -2
  26. package/src/cognition/conversation.memory.ts +1 -1
  27. package/src/cognition/faculties/executive.engine/commands.ts +7 -15
  28. package/src/cognition/faculties/executive.engine/engine.ts +66 -35
  29. package/src/cognition/faculties/executive.engine/escalation.buffer.ts +1 -1
  30. package/src/cognition/faculties/executive.engine/facet.ts +1 -1
  31. package/src/cognition/faculties/executive.engine/prompt.factory.ts +76 -61
  32. package/src/cognition/faculties/executive.engine/types.ts +1 -1
  33. package/src/cognition/faculties/introspection.engine.ts +1 -2
  34. package/src/cognition/faculties/planning.engine/engine.ts +38 -1
  35. package/src/cognition/faculties/planning.engine/plan.store.ts +42 -0
  36. package/src/cognition/faculties/planning.engine/plan.supervision.ts +7 -7
  37. package/src/cognition/faculties/theory.of.mind.ts +2 -2
  38. package/src/cognition/senses/audition.engine/engine.ts +21 -21
  39. package/src/cognition/utilities/token.tracker.ts +6 -0
  40. package/src/host/boot.ts +95 -7
  41. package/src/llm/index.ts +75 -25
  42. package/src/llm/summarizer.ts +2 -2
  43. package/src/profiles/companion.ts +14 -14
  44. package/src/profiles/company-brain.ts +19 -19
  45. package/src/profiles/customer-service.ts +17 -17
  46. package/src/profiles/game-npc.ts +10 -10
  47. package/src/profiles/index.ts +2 -2
  48. package/src/profiles/smart-home.ts +16 -16
  49. package/src/runners/outreach.runner.ts +6 -9
  50. package/src/runners/social.runner.ts +1 -4
  51. package/src/runners/thin-shim.runner.ts +4 -6
  52. package/src/sdk/will.ts +42 -16
  53. package/src/stem/guards/identity.coherence.ts +9 -6
  54. package/src/stem/guards/identity.guard.ts +20 -9
  55. package/src/stem/index.ts +7 -7
  56. package/src/stem/mind.ts +182 -98
  57. package/src/stem/tracts/outbox.controller.ts +2 -2
package/dist/index.d.ts CHANGED
@@ -1,5 +1,143 @@
1
- import { S as SimulationContext, a as SeededPRNG, b as SimulationEntity, T as Timestamp, c as SimulationEvent, d as StateManager, e as Tick, f as SimulationState, R as RestoreOptions, g as StateCommands, h as ReasoningFootprint, i as ReadonlySimulationState, C as ConflictReport, j as ConflictStrategy, k as ConflictResolution, O as OutboundEnvelope, A as AckResult, l as ExternalTransport, I as InboundEnvelope, m as TransportStatus } from './will-B5eKs3Wv.js';
2
- export { n as AckEnvelope, o as ActionRequest, p as ActionResult, q as ActionSelector, r as ActivityEnvelope, s as ActivityEvent, t as ActivityEventHandler, u as AestheticEvaluator, v as AestheticEvaluatorConfig, w as AffectiveBlender, x as AffectiveBlenderConfig, y as AffordanceSynthesizer, z as AsyncEngine, B as AsyncEngineConfig, D as AttachmentEvaluator, F as AttachmentEvaluatorConfig, G as AttentionAllocator, H as AttentionAllocatorConfig, J as AuditionEngine, K as AutobiographicalNarrator, L as AutobiographicalNarratorConfig, M as BehavioralProbeResult, N as BiasDetector, P as BiasDetectorConfig, Q as BunStorageAdapter, U as ChunkEnvelope, V as CircadianConfig, X as CircadianOscillator, Y as ClockConfig, Z as Cognition, _ as CognitiveHealth, $ as ConfidenceCalibrator, a0 as ConfidenceCalibratorConfig, a1 as Coordinates, a2 as CreateWillOptions, a3 as DefaultEventBus, a4 as DefaultMetricCollector, a5 as DefaultOrchestrator, a6 as DefaultReplayRecorder, a7 as DefaultReplaySession, a8 as DefaultScenario, a9 as DefaultSerializer, aa as DefaultSimulation, ab as DefaultSimulationClock, ac as DefaultStateManager, ad as DefaultVectorMemoryAdapter, ae as DeliberationEngine, af as DeltaEncoder, ag as DeltaSnapshot, ah as DreamSimulator, ai as DreamSimulatorConfig, aj as Duration, ak as EffectorDeclaration, al as EffectorEntry, E as EffectorHandler, am as EffectorResult, an as EffectorSpec, ao as EmbeddingProvider, ap as EmpathySimulator, aq as EmpathySimulatorConfig, ar as EnergyRegulator, as as EnergyRegulatorConfig, at as EngineRegistry, au as EngineResult, av as Envelope, aw as EpisodicConsolidator, ax as EpisodicConsolidatorConfig, ay as EventBus, az as EventBusConfig, aA as EventFilter, aB as EventHandler, aC as EventPayload, aD as ExecutiveEngine, aE as ExecutiveEngineConfig, aF as Exteroception, aG as ExteroceptionConfig, aH as ForgettingCurve, aI as ForgettingCurveConfig, aJ as FrustrationEvaluator, aK as FrustrationEvaluatorConfig, aL as GoalManager, aM as GoalManagerConfig, aN as GustationEngine, aO as InboundMessageEnvelope, aP as InboundPerceptEnvelope, aQ as InhibitionController, aR as InhibitionControllerConfig, aS as Interoception, aT as InteroceptionConfig, aU as IntrospectionEngine, aV as IntrospectionEngineConfig, aW as KnownEntityTracker, aX as KnownEntityTrackerConfig, aY as LLMCompletionRecord, aZ as LLMCompletionSink, a_ as LossEvaluator, a$ as LossEvaluatorConfig, b0 as MessageEnvelope, b1 as MetricCollector, b2 as MetricPoint, b3 as MinimalContext, b4 as MockEmbedder, b5 as MoralEvaluator, b6 as MoralEvaluatorConfig, b7 as MotorSchemaExecutor, b8 as NoveltyDetector, b9 as NoveltyDetectorConfig, ba as OlfactionEngine, bb as OpenAICompatibleEmbedder, bc as Orchestrator, bd as OrchestratorConfig, be as OutboxMessage, bf as PMABehavioral, bg as PMABelief, bh as PMAEmotionalBaseline, bi as PMAEvalHarness, bj as PMAGoal, bk as PMAIdentity, bl as PMAProbe, bm as PMASnapshot, bn as PerceptEnvelope, bo as PersonaConsolidator, bp as PersonaConsolidatorConfig, bq as PlanningEngine, br as PlanningEngineConfig, bs as ReafferenceEngine, bt as ReconstructionFidelityReport, bu as ReconstructionFidelityScores, bv as RecordUsageInput, bw as ReplayComparison, bx as ReplayConfig, by as ReplayDifference, bz as ReplayManager, bA as ReplayMetadata, bB as ReplayRecord, bC as ReplayRecorder, bD as ReplaySession, bE as ReplyEnvelope, bF as ReputationTracker, bG as ReputationTrackerConfig, bH as RewardEvaluator, bI as RewardEvaluatorConfig, bJ as Scenario, bK as ScenarioConfig, bL as ScenarioValidationResult, bM as SchemaPrecondition, bN as SelfModelUpdater, bO as SelfModelUpdaterConfig, bP as SemanticIntegrator, bQ as SemanticIntegratorConfig, bR as SensoryInput, bS as SerializationConfig, bT as SerializationFormat, bU as SerializedEntity, bV as SerializedState, bW as Serializer, bX as SessionLogEnvelope, bY as Simulation, bZ as SimulationClock, b_ as SimulationConfig, b$ as SimulationEngine, c0 as SimulationEventBase, c1 as SimulationEventListener, c2 as SleepPressureConfig, c3 as SleepPressureRegulator, c4 as SocialPerception, c5 as SocialPerceptionConfig, c6 as SomatosensationEngine, c7 as SpacedRepetition, c8 as SpacedRepetitionConfig, c9 as StateSnapshot, ca as Stimulus, cb as StorageAdapter, cc as StressRegulator, cd as StressRegulatorConfig, ce as TaskSwitcher, cf as TaskSwitcherConfig, cg as TextMessage, ch as TheoryOfMind, ci as TheoryOfMindConfig, cj as ThreatEvaluator, ck as ThreatEvaluatorConfig, cl as TickListener, cm as TokenLedgerRecord, cn as TokenReportEnvelope, co as TokenTracker, cp as TokenTrackerConfig, cq as TokenUsage, cr as VectorIndex, cs as VectorMemoryAdapter, ct as VectorMemoryConfig, cu as VectorQueryFilter, cv as VectorQueryResult, cw as VectorRecord, cx as VisionEngine, cy as VoiceChunk, W as Will, cz as WillAffect, cA as WillConfig, cB as WillEffectorAct, cC as WillInstance, cD as WillMessage, cE as WillStateSummary, cF as WillStatus, cG as WillStem, cH as WillSummary, cI as WorkingMemory, cJ as WorkingMemoryConfig, cK as WorldEntity, cL as WorldInterface, cM as assembleMind, cN as clearCompletionRecorder, cO as effectorInvocation, cP as effectorInvocationEnvelope, cQ as getCompletionRecorder, cR as resolvePricing, cS as setCompletionRecorder } from './will-B5eKs3Wv.js';
1
+ import { O as OutboundEnvelope, A as AckResult, a as ExternalTransport, I as InboundEnvelope, T as TransportStatus, S as SimulationContext, b as SeededPRNG, c as SimulationEntity, d as Timestamp, e as SimulationEvent, f as StateManager, g as Tick, h as SimulationState, R as RestoreOptions, i as StateCommands, j as ReasoningFootprint, k as ReadonlySimulationState, C as ConflictReport, l as ConflictStrategy, m as ConflictResolution } from './will-BDq-TMQr.js';
2
+ export { n as AckEnvelope, o as ActionRequest, p as ActionResult, q as ActionSelector, r as ActivityEnvelope, s as ActivityEvent, t as ActivityEventHandler, u as AestheticEvaluator, v as AestheticEvaluatorConfig, w as AffectiveBlender, x as AffectiveBlenderConfig, y as AffordanceSynthesizer, z as AsyncEngine, B as AsyncEngineConfig, D as AttachmentEvaluator, F as AttachmentEvaluatorConfig, G as AttentionAllocator, H as AttentionAllocatorConfig, J as AuditionEngine, K as AutobiographicalNarrator, L as AutobiographicalNarratorConfig, M as BehavioralProbeResult, N as BiasDetector, P as BiasDetectorConfig, Q as BunStorageAdapter, U as ChunkEnvelope, V as CircadianConfig, X as CircadianOscillator, Y as ClockConfig, Z as Cognition, _ as CognitiveHealth, $ as ConfidenceCalibrator, a0 as ConfidenceCalibratorConfig, a1 as Coordinates, a2 as CreateWillOptions, a3 as DefaultEventBus, a4 as DefaultMetricCollector, a5 as DefaultOrchestrator, a6 as DefaultReplayRecorder, a7 as DefaultReplaySession, a8 as DefaultScenario, a9 as DefaultSerializer, aa as DefaultSimulation, ab as DefaultSimulationClock, ac as DefaultStateManager, ad as DefaultVectorMemoryAdapter, ae as DeliberationEngine, af as DeltaEncoder, ag as DeltaSnapshot, ah as DreamSimulator, ai as DreamSimulatorConfig, aj as Duration, ak as EffectorDeclaration, al as EffectorEntry, E as EffectorHandler, am as EffectorResult, an as EffectorSpec, ao as EmbeddingProvider, ap as EmpathySimulator, aq as EmpathySimulatorConfig, ar as EnergyRegulator, as as EnergyRegulatorConfig, at as EngineRegistry, au as EngineResult, av as Envelope, aw as EpisodicConsolidator, ax as EpisodicConsolidatorConfig, ay as EventBus, az as EventBusConfig, aA as EventFilter, aB as EventHandler, aC as EventPayload, aD as ExecutiveEngine, aE as ExecutiveEngineConfig, aF as Exteroception, aG as ExteroceptionConfig, aH as ForgettingCurve, aI as ForgettingCurveConfig, aJ as FrustrationEvaluator, aK as FrustrationEvaluatorConfig, aL as GoalManager, aM as GoalManagerConfig, aN as GustationEngine, aO as InboundMessageEnvelope, aP as InboundPerceptEnvelope, aQ as InhibitionController, aR as InhibitionControllerConfig, aS as Interoception, aT as InteroceptionConfig, aU as IntrospectionEngine, aV as IntrospectionEngineConfig, aW as KnownEntityTracker, aX as KnownEntityTrackerConfig, aY as LLMCompletionRecord, aZ as LLMCompletionSink, a_ as LossEvaluator, a$ as LossEvaluatorConfig, b0 as MessageEnvelope, b1 as MetricCollector, b2 as MetricPoint, b3 as MinimalContext, b4 as MockEmbedder, b5 as MoralEvaluator, b6 as MoralEvaluatorConfig, b7 as MotorSchemaExecutor, b8 as NoveltyDetector, b9 as NoveltyDetectorConfig, ba as OlfactionEngine, bb as OpenAICompatibleEmbedder, bc as Orchestrator, bd as OrchestratorConfig, be as OutboxMessage, bf as PMABehavioral, bg as PMABelief, bh as PMAEmotionalBaseline, bi as PMAEvalHarness, bj as PMAGoal, bk as PMAIdentity, bl as PMAProbe, bm as PMASnapshot, bn as PerceptEnvelope, bo as PersonaConsolidator, bp as PersonaConsolidatorConfig, bq as PlanningEngine, br as PlanningEngineConfig, bs as ReafferenceEngine, bt as ReconstructionFidelityReport, bu as ReconstructionFidelityScores, bv as RecordUsageInput, bw as ReplayComparison, bx as ReplayConfig, by as ReplayDifference, bz as ReplayManager, bA as ReplayMetadata, bB as ReplayRecord, bC as ReplayRecorder, bD as ReplaySession, bE as ReplyEnvelope, bF as ReputationTracker, bG as ReputationTrackerConfig, bH as RewardEvaluator, bI as RewardEvaluatorConfig, bJ as Scenario, bK as ScenarioConfig, bL as ScenarioValidationResult, bM as SchemaPrecondition, bN as SelfModelUpdater, bO as SelfModelUpdaterConfig, bP as SemanticIntegrator, bQ as SemanticIntegratorConfig, bR as SensoryInput, bS as SerializationConfig, bT as SerializationFormat, bU as SerializedEntity, bV as SerializedState, bW as Serializer, bX as SessionLogEnvelope, bY as Simulation, bZ as SimulationClock, b_ as SimulationConfig, b$ as SimulationEngine, c0 as SimulationEventBase, c1 as SimulationEventListener, c2 as SleepPressureConfig, c3 as SleepPressureRegulator, c4 as SocialPerception, c5 as SocialPerceptionConfig, c6 as SomatosensationEngine, c7 as SpacedRepetition, c8 as SpacedRepetitionConfig, c9 as StateSnapshot, ca as Stimulus, cb as StorageAdapter, cc as StressRegulator, cd as StressRegulatorConfig, ce as TaskSwitcher, cf as TaskSwitcherConfig, cg as TextMessage, ch as TheoryOfMind, ci as TheoryOfMindConfig, cj as ThreatEvaluator, ck as ThreatEvaluatorConfig, cl as TickListener, cm as TokenLedgerRecord, cn as TokenReportEnvelope, co as TokenTracker, cp as TokenTrackerConfig, cq as TokenUsage, cr as VectorIndex, cs as VectorMemoryAdapter, ct as VectorMemoryConfig, cu as VectorQueryFilter, cv as VectorQueryResult, cw as VectorRecord, cx as VisionEngine, cy as VoiceChunk, W as Will, cz as WillAffect, cA as WillConfig, cB as WillEffectorAct, cC as WillInstance, cD as WillMessage, cE as WillStateSummary, cF as WillStatus, cG as WillStem, cH as WillSummary, cI as WorkingMemory, cJ as WorkingMemoryConfig, cK as WorldEntity, cL as WorldInterface, cM as assembleMind, cN as clearCompletionRecorder, cO as effectorInvocation, cP as effectorInvocationEnvelope, cQ as getCompletionRecorder, cR as resolvePricing, cS as setCompletionRecorder } from './will-BDq-TMQr.js';
3
+
4
+ /** Decides how emit() resolves an ack for a given envelope. Default: acked via callback. */
5
+ type AckPolicy = (env: OutboundEnvelope) => AckResult;
6
+ declare class LoopbackTransport implements ExternalTransport {
7
+ /** Every envelope passed to emit(), in order — inspect in tests. */
8
+ readonly sent: OutboundEnvelope[];
9
+ private _connected;
10
+ private _ackPolicy;
11
+ private readonly _inboundHandlers;
12
+ private readonly _statusHandlers;
13
+ constructor(ackPolicy?: AckPolicy);
14
+ get connected(): boolean;
15
+ emit(env: OutboundEnvelope): Promise<AckResult>;
16
+ onInbound(handler: (env: InboundEnvelope) => void): () => void;
17
+ onStatus(handler: (s: TransportStatus) => void): () => void;
18
+ close(): void;
19
+ /** Simulate the peer sending an inbound envelope to the Will. */
20
+ injectInbound(env: InboundEnvelope): void;
21
+ /** Flip connection state and notify status handlers. */
22
+ setConnected(connected: boolean): void;
23
+ /** Swap the ack policy mid-test (e.g. to simulate timeouts then recovery). */
24
+ setAckPolicy(policy: AckPolicy): void;
25
+ /** Convenience: only the envelopes on a given channel. */
26
+ sentOn<T extends OutboundEnvelope['channel']>(channel: T): Extract<OutboundEnvelope, {
27
+ channel: T;
28
+ }>[];
29
+ }
30
+
31
+ /** Minimal surface of a socket.io client we depend on — keeps us decoupled from the dep's types. */
32
+ interface SocketLike {
33
+ connected: boolean;
34
+ on(event: string, handler: (...args: any[]) => void): void;
35
+ emit(event: string, payload: unknown, ack?: (response: unknown) => void): void;
36
+ disconnect(): void;
37
+ }
38
+ interface SocketIoTransportOptions {
39
+ /** socket.io server URL (e.g. wss://host or http://host:port). */
40
+ url: string;
41
+ /** This Will's id — sent as auth + routing key. */
42
+ willId: string;
43
+ /** Optional auth token sent in the socket.io handshake. */
44
+ token?: string;
45
+ /** Default ack timeout for emit() in ms. Default 5000. */
46
+ ackTimeoutMs?: number;
47
+ /**
48
+ * Override the socket factory — inject a fake in tests, or customize the
49
+ * socket.io connection. When omitted, `socket.io-client` is dynamically
50
+ * imported and `io(url, { auth })` is called.
51
+ */
52
+ socketFactory?: (url: string, opts: {
53
+ auth: {
54
+ willId: string;
55
+ token?: string;
56
+ };
57
+ }) => SocketLike | Promise<SocketLike>;
58
+ }
59
+ declare class SocketIoTransport implements ExternalTransport {
60
+ private readonly _opts;
61
+ private _socket;
62
+ private _connecting;
63
+ private _seq;
64
+ private readonly _inboundHandlers;
65
+ private readonly _statusHandlers;
66
+ constructor(_opts: SocketIoTransportOptions);
67
+ get connected(): boolean;
68
+ emit(env: OutboundEnvelope, opts?: {
69
+ ackTimeoutMs?: number;
70
+ }): Promise<AckResult>;
71
+ onInbound(handler: (env: InboundEnvelope) => void): () => void;
72
+ onStatus(handler: (s: TransportStatus) => void): () => void;
73
+ close(): void;
74
+ private _ensureSocket;
75
+ private _connect;
76
+ private _defaultFactory;
77
+ /** Attach socket.io event handlers that feed the inbound + status streams. */
78
+ private _wire;
79
+ private _emitInbound;
80
+ private _notifyStatus;
81
+ private _deliveryAck;
82
+ private _resultAck;
83
+ }
84
+
85
+ /** Channels a consumer can filter on (any OutboundEnvelope channel, or '*'). */
86
+ type StreamChannel = OutboundEnvelope['channel'] | '*';
87
+ type OutboundListener = (env: OutboundEnvelope) => void;
88
+ declare class StreamTransport implements ExternalTransport {
89
+ readonly willId: string;
90
+ private _connected;
91
+ private readonly _outbound;
92
+ private readonly _outboundByCh;
93
+ private readonly _inboundHandlers;
94
+ private readonly _statusHandlers;
95
+ constructor(willId?: string);
96
+ get connected(): boolean;
97
+ /**
98
+ * Deliver an outbound envelope to subscribers. In-process and synchronous, so
99
+ * it resolves immediately (`via: 'event'`) — there is no remote peer to ack.
100
+ * A listener that throws is isolated; it can never break the tick loop.
101
+ */
102
+ emit(env: OutboundEnvelope): Promise<AckResult>;
103
+ /** Subscribe to every outbound envelope. Returns an unsubscribe function. */
104
+ subscribe(listener: OutboundListener): () => void;
105
+ /**
106
+ * Subscribe to a single channel (e.g. `'token_report'`, `'session_log'`,
107
+ * `'reply'`) or `'*'` for all. Returns an unsubscribe function.
108
+ */
109
+ on(channel: StreamChannel, listener: OutboundListener): () => void;
110
+ /**
111
+ * Inject an inbound envelope (message, percept, ack) into the Will. The stem
112
+ * enqueues it onto the tick-stamped InboundQueue and applies it deterministically
113
+ * on tick — this method itself never touches simulation state.
114
+ */
115
+ injectInbound(env: InboundEnvelope): void;
116
+ onInbound(handler: (env: InboundEnvelope) => void): () => void;
117
+ onStatus(handler: (s: TransportStatus) => void): () => void;
118
+ /** Notify status subscribers (e.g. flip to 'disconnected' in a test). */
119
+ setStatus(status: TransportStatus): void;
120
+ close(): void;
121
+ /** Total active outbound listeners (diagnostics/tests). */
122
+ get listenerCount(): number;
123
+ private _dispatch;
124
+ }
125
+ /**
126
+ * Whether producers should ALSO write their telemetry to local files.
127
+ *
128
+ * Files are a development convenience only. In production the stream/transport is
129
+ * the single source of truth and the consumer owns persistence.
130
+ *
131
+ * - `WILL_FILE_LOGS=true|1|false|0` — explicit override (wins).
132
+ * - otherwise: on when `NODE_ENV` is neither `production` nor `test`.
133
+ */
134
+ declare function fileLoggingEnabled(): boolean;
135
+
136
+ /**
137
+ * Number of ticks an undelivered outbox message survives before it is
138
+ * expired. Override via WILL_OUTBOX_TTL_TICKS. Default: 100 ticks.
139
+ */
140
+ declare const OUTBOX_TTL_TICKS: number;
3
141
 
4
142
  /**
5
143
  * Creates a Mulberry32 PRNG from the given seed.
@@ -278,144 +416,6 @@ declare class ConflictDetector {
278
416
  private _merge;
279
417
  }
280
418
 
281
- /** Decides how emit() resolves an ack for a given envelope. Default: acked via callback. */
282
- type AckPolicy = (env: OutboundEnvelope) => AckResult;
283
- declare class LoopbackTransport implements ExternalTransport {
284
- /** Every envelope passed to emit(), in order — inspect in tests. */
285
- readonly sent: OutboundEnvelope[];
286
- private _connected;
287
- private _ackPolicy;
288
- private readonly _inboundHandlers;
289
- private readonly _statusHandlers;
290
- constructor(ackPolicy?: AckPolicy);
291
- get connected(): boolean;
292
- emit(env: OutboundEnvelope): Promise<AckResult>;
293
- onInbound(handler: (env: InboundEnvelope) => void): () => void;
294
- onStatus(handler: (s: TransportStatus) => void): () => void;
295
- close(): void;
296
- /** Simulate the peer sending an inbound envelope to the Will. */
297
- injectInbound(env: InboundEnvelope): void;
298
- /** Flip connection state and notify status handlers. */
299
- setConnected(connected: boolean): void;
300
- /** Swap the ack policy mid-test (e.g. to simulate timeouts then recovery). */
301
- setAckPolicy(policy: AckPolicy): void;
302
- /** Convenience: only the envelopes on a given channel. */
303
- sentOn<T extends OutboundEnvelope['channel']>(channel: T): Extract<OutboundEnvelope, {
304
- channel: T;
305
- }>[];
306
- }
307
-
308
- /** Minimal surface of a socket.io client we depend on — keeps us decoupled from the dep's types. */
309
- interface SocketLike {
310
- connected: boolean;
311
- on(event: string, handler: (...args: any[]) => void): void;
312
- emit(event: string, payload: unknown, ack?: (response: unknown) => void): void;
313
- disconnect(): void;
314
- }
315
- interface SocketIoTransportOptions {
316
- /** socket.io server URL (e.g. wss://host or http://host:port). */
317
- url: string;
318
- /** This Will's id — sent as auth + routing key. */
319
- willId: string;
320
- /** Optional auth token sent in the socket.io handshake. */
321
- token?: string;
322
- /** Default ack timeout for emit() in ms. Default 5000. */
323
- ackTimeoutMs?: number;
324
- /**
325
- * Override the socket factory — inject a fake in tests, or customize the
326
- * socket.io connection. When omitted, `socket.io-client` is dynamically
327
- * imported and `io(url, { auth })` is called.
328
- */
329
- socketFactory?: (url: string, opts: {
330
- auth: {
331
- willId: string;
332
- token?: string;
333
- };
334
- }) => SocketLike | Promise<SocketLike>;
335
- }
336
- declare class SocketIoTransport implements ExternalTransport {
337
- private readonly _opts;
338
- private _socket;
339
- private _connecting;
340
- private _seq;
341
- private readonly _inboundHandlers;
342
- private readonly _statusHandlers;
343
- constructor(_opts: SocketIoTransportOptions);
344
- get connected(): boolean;
345
- emit(env: OutboundEnvelope, opts?: {
346
- ackTimeoutMs?: number;
347
- }): Promise<AckResult>;
348
- onInbound(handler: (env: InboundEnvelope) => void): () => void;
349
- onStatus(handler: (s: TransportStatus) => void): () => void;
350
- close(): void;
351
- private _ensureSocket;
352
- private _connect;
353
- private _defaultFactory;
354
- /** Attach socket.io event handlers that feed the inbound + status streams. */
355
- private _wire;
356
- private _emitInbound;
357
- private _notifyStatus;
358
- private _deliveryAck;
359
- private _resultAck;
360
- }
361
-
362
- /** Channels a consumer can filter on (any OutboundEnvelope channel, or '*'). */
363
- type StreamChannel = OutboundEnvelope['channel'] | '*';
364
- type OutboundListener = (env: OutboundEnvelope) => void;
365
- declare class StreamTransport implements ExternalTransport {
366
- readonly willId: string;
367
- private _connected;
368
- private readonly _outbound;
369
- private readonly _outboundByCh;
370
- private readonly _inboundHandlers;
371
- private readonly _statusHandlers;
372
- constructor(willId?: string);
373
- get connected(): boolean;
374
- /**
375
- * Deliver an outbound envelope to subscribers. In-process and synchronous, so
376
- * it resolves immediately (`via: 'event'`) — there is no remote peer to ack.
377
- * A listener that throws is isolated; it can never break the tick loop.
378
- */
379
- emit(env: OutboundEnvelope): Promise<AckResult>;
380
- /** Subscribe to every outbound envelope. Returns an unsubscribe function. */
381
- subscribe(listener: OutboundListener): () => void;
382
- /**
383
- * Subscribe to a single channel (e.g. `'token_report'`, `'session_log'`,
384
- * `'reply'`) or `'*'` for all. Returns an unsubscribe function.
385
- */
386
- on(channel: StreamChannel, listener: OutboundListener): () => void;
387
- /**
388
- * Inject an inbound envelope (message, percept, ack) into the Will. The stem
389
- * enqueues it onto the tick-stamped InboundQueue and applies it deterministically
390
- * on tick — this method itself never touches simulation state.
391
- */
392
- injectInbound(env: InboundEnvelope): void;
393
- onInbound(handler: (env: InboundEnvelope) => void): () => void;
394
- onStatus(handler: (s: TransportStatus) => void): () => void;
395
- /** Notify status subscribers (e.g. flip to 'disconnected' in a test). */
396
- setStatus(status: TransportStatus): void;
397
- close(): void;
398
- /** Total active outbound listeners (diagnostics/tests). */
399
- get listenerCount(): number;
400
- private _dispatch;
401
- }
402
- /**
403
- * Whether producers should ALSO write their telemetry to local files.
404
- *
405
- * Files are a development convenience only. In production the stream/transport is
406
- * the single source of truth and the consumer owns persistence.
407
- *
408
- * - `WILL_FILE_LOGS=true|1|false|0` — explicit override (wins).
409
- * - otherwise: on when `NODE_ENV` is neither `production` nor `test`.
410
- */
411
- declare function fileLoggingEnabled(): boolean;
412
-
413
- /**
414
- * Number of ticks an undelivered outbox message survives before it is
415
- * expired. Override via WILL_OUTBOX_TTL_TICKS. Default: 100 ticks.
416
- */
417
- declare const OUTBOX_TTL_TICKS: number;
418
-
419
419
  interface WorldProfile {
420
420
  id: string;
421
421
  name: string;
@@ -423,7 +423,7 @@ interface WorldProfile {
423
423
  /** Effectors pre-granted when this profile is active. */
424
424
  effectors: string[];
425
425
  /**
426
- * Appended to the executive prompt under "## Your Environment".
426
+ * Appended to the executive prompt under "## My Environment".
427
427
  * Tells the Will what world it inhabits and how to behave in it.
428
428
  */
429
429
  context: string;