@mindot/will 0.5.0 → 0.6.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 (132) hide show
  1. package/dist/channels/discord.d.ts +1 -1
  2. package/dist/channels/discord.js.map +1 -1
  3. package/dist/channels/whatsapp.d.ts +1 -1
  4. package/dist/channels/whatsapp.js.map +1 -1
  5. package/dist/cli.js +567 -51
  6. package/dist/cli.js.map +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +567 -51
  9. package/dist/index.js.map +1 -1
  10. package/dist/mcp/effectors.d.ts +1 -1
  11. package/dist/mcp/effectors.js.map +1 -1
  12. package/dist/{will-BDq-TMQr.d.ts → will-Bikuk4s2.d.ts} +48 -6
  13. package/package.json +1 -1
  14. package/src/channels/discord.ts +11 -11
  15. package/src/channels/roster.ts +1 -1
  16. package/src/channels/types.ts +1 -1
  17. package/src/channels/whatsapp.ts +25 -25
  18. package/src/cli.ts +20 -20
  19. package/src/cognition/acp.ts +28 -0
  20. package/src/cognition/agency/consequence.ts +174 -0
  21. package/src/cognition/agency/engines/action.selector.ts +301 -48
  22. package/src/cognition/agency/engines/affordance.synthesizer.ts +26 -16
  23. package/src/cognition/agency/engines/deliberation.engine.ts +28 -14
  24. package/src/cognition/agency/engines/motor.schema.executor.ts +86 -14
  25. package/src/cognition/agency/engines/reafference.engine.ts +122 -18
  26. package/src/cognition/agency/execution.primitives.ts +13 -13
  27. package/src/cognition/agency/proactive.communicator.ts +1 -1
  28. package/src/cognition/agency/reconcile.learning.ts +1 -1
  29. package/src/cognition/agency/revocation.ts +79 -0
  30. package/src/cognition/agency/schemas/repertoire.ts +2 -2
  31. package/src/cognition/agency/selection.scoring.ts +25 -9
  32. package/src/cognition/bus.ts +2 -2
  33. package/src/cognition/completion.inbox.ts +1 -1
  34. package/src/cognition/config.mirror.entities.ts +5 -5
  35. package/src/cognition/event.log.ts +2 -2
  36. package/src/cognition/event.schemas.ts +67 -67
  37. package/src/cognition/faculties/aesthetic.evaluator.ts +6 -6
  38. package/src/cognition/faculties/affective.blender.ts +36 -4
  39. package/src/cognition/faculties/attachment.evaluator.ts +6 -6
  40. package/src/cognition/faculties/attention.allocator.ts +63 -8
  41. package/src/cognition/faculties/autobiographical.narrator.ts +3 -3
  42. package/src/cognition/faculties/bias.detector.ts +7 -7
  43. package/src/cognition/faculties/circadian.oscillator.ts +3 -3
  44. package/src/cognition/faculties/confidence.calibrator.ts +7 -7
  45. package/src/cognition/faculties/dream.simulator.ts +5 -5
  46. package/src/cognition/faculties/empathy.simulator.ts +7 -7
  47. package/src/cognition/faculties/energy.regulator.ts +4 -4
  48. package/src/cognition/faculties/episodic.consolidator.ts +6 -6
  49. package/src/cognition/faculties/executive.engine/commands.ts +6 -6
  50. package/src/cognition/faculties/executive.engine/context.ts +42 -42
  51. package/src/cognition/faculties/executive.engine/deferred.effects.ts +2 -2
  52. package/src/cognition/faculties/executive.engine/engine.ts +25 -25
  53. package/src/cognition/faculties/executive.engine/facet.supervisor.ts +12 -12
  54. package/src/cognition/faculties/executive.engine/facet.ts +18 -18
  55. package/src/cognition/faculties/executive.engine/gating.ts +2 -2
  56. package/src/cognition/faculties/executive.engine/messages.ts +3 -3
  57. package/src/cognition/faculties/executive.engine/parser.ts +11 -11
  58. package/src/cognition/faculties/executive.engine/prompt.factory.ts +55 -55
  59. package/src/cognition/faculties/exteroception.ts +99 -5
  60. package/src/cognition/faculties/forgetting.curve.ts +3 -3
  61. package/src/cognition/faculties/frustration.evaluator.ts +6 -6
  62. package/src/cognition/faculties/goal.manager.ts +15 -15
  63. package/src/cognition/faculties/inhibition.controller.ts +3 -3
  64. package/src/cognition/faculties/interoception.ts +3 -3
  65. package/src/cognition/faculties/introspection.engine.ts +3 -3
  66. package/src/cognition/faculties/known.entity.tracker.ts +15 -15
  67. package/src/cognition/faculties/loss.evaluator.ts +2 -2
  68. package/src/cognition/faculties/moral.evaluator.ts +4 -4
  69. package/src/cognition/faculties/novelty.detector.ts +4 -4
  70. package/src/cognition/faculties/persona.consolidator.ts +12 -12
  71. package/src/cognition/faculties/planning.engine/engine.ts +47 -47
  72. package/src/cognition/faculties/planning.engine/plan.frontier.ts +5 -5
  73. package/src/cognition/faculties/planning.engine/plan.store.ts +1 -1
  74. package/src/cognition/faculties/planning.engine/plan.supervision.ts +20 -20
  75. package/src/cognition/faculties/reputation.tracker.ts +6 -6
  76. package/src/cognition/faculties/reward.evaluator.ts +4 -4
  77. package/src/cognition/faculties/self.model.updater.ts +8 -8
  78. package/src/cognition/faculties/semantic.engine/integrator.ts +15 -15
  79. package/src/cognition/faculties/sleep.pressure.regulator.ts +4 -4
  80. package/src/cognition/faculties/social.perception.ts +3 -3
  81. package/src/cognition/faculties/spaced.repetition.ts +2 -2
  82. package/src/cognition/faculties/stress.regulator.ts +27 -4
  83. package/src/cognition/faculties/task.switcher.ts +11 -6
  84. package/src/cognition/faculties/theory.of.mind.ts +6 -6
  85. package/src/cognition/faculties/threat.evaluator.ts +3 -3
  86. package/src/cognition/faculties/working.memory.ts +8 -8
  87. package/src/cognition/generative.model.ts +2 -2
  88. package/src/cognition/memory/vector.adapter.ts +5 -5
  89. package/src/cognition/memory/vector.content.ts +4 -4
  90. package/src/cognition/memory/vector.embedder.ts +9 -9
  91. package/src/cognition/persona.prior.ts +1 -1
  92. package/src/cognition/schema.registry.ts +2 -2
  93. package/src/cognition/senses/audition.engine/engine.ts +2 -2
  94. package/src/cognition/senses/base.sense.engine.ts +1 -1
  95. package/src/cognition/utilities/token.tracker.ts +5 -5
  96. package/src/core/abstracts.ts +1 -1
  97. package/src/core/completion.recorder.ts +2 -2
  98. package/src/core/serialization.ts +3 -3
  99. package/src/core/snapshot.manager.ts +1 -1
  100. package/src/core/state.manager.ts +1 -1
  101. package/src/core/utils.ts +1 -1
  102. package/src/host/boot.ts +30 -30
  103. package/src/host/utterances.ts +1 -1
  104. package/src/llm/index.ts +9 -9
  105. package/src/llm/summarizer.ts +4 -4
  106. package/src/llm/wire.contracts.ts +1 -1
  107. package/src/mcp/effectors.ts +10 -10
  108. package/src/mcp/server.ts +11 -11
  109. package/src/pma/eval.ts +1 -1
  110. package/src/pma/index.ts +21 -21
  111. package/src/runners/outreach.runner.ts +3 -3
  112. package/src/runners/social.runner.ts +1 -1
  113. package/src/runners/thin-shim.runner.ts +1 -1
  114. package/src/sdk/will.ts +5 -5
  115. package/src/serve/server.ts +12 -12
  116. package/src/stem/assembly.audit.ts +3 -3
  117. package/src/stem/guards/identity.coherence.ts +10 -10
  118. package/src/stem/guards/identity.guard.ts +22 -22
  119. package/src/stem/index.ts +11 -11
  120. package/src/stem/mind.ts +12 -12
  121. package/src/stem/tracts/biography.writer.ts +3 -3
  122. package/src/stem/tracts/effector.controller.ts +4 -4
  123. package/src/stem/tracts/health.reporter.ts +1 -1
  124. package/src/stem/tracts/outbox.controller.ts +4 -0
  125. package/src/stem/tracts/outbox.writer.ts +4 -4
  126. package/src/stem/tracts/pma.controller.ts +1 -1
  127. package/src/stem/tracts/replay.controller.ts +10 -10
  128. package/src/stem/tracts/sensory.controller.ts +2 -2
  129. package/src/stem/tracts/session.logger.ts +4 -4
  130. package/src/stem/tracts/transport/socketio.transport.ts +7 -7
  131. package/src/stem/tracts/transport/stream.transport.ts +2 -2
  132. package/src/stem/tracts/transport.controller.ts +15 -15
package/dist/index.js CHANGED
@@ -3607,6 +3607,9 @@ var SleepPressureRegulator = class {
3607
3607
  }
3608
3608
  };
3609
3609
 
3610
+ // src/cognition/acp.ts
3611
+ var ACP_SELF_PRECISION = 0.35;
3612
+
3610
3613
  // src/cognition/persona.prior.ts
3611
3614
  var PERSONA_PRIOR_ID = "persona-prior";
3612
3615
  var PERSONA_PRIOR_TYPE = "persona.prior";
@@ -3715,6 +3718,8 @@ function consolidatePrior(current, adjustments, tick, opts = {}) {
3715
3718
  }
3716
3719
 
3717
3720
  // src/cognition/faculties/attention.allocator.ts
3721
+ var ACP_USAGE_UPLIFT = 0.15;
3722
+ var ACP_CONFIDENCE = 0.4;
3718
3723
  var EFFORT_BASELINE2 = 0.7;
3719
3724
  var EFFORT_MIN = 0.4;
3720
3725
  var EFFORT_MAX = 1;
@@ -3736,6 +3741,8 @@ var AttentionAllocator = class {
3736
3741
  _effort = EFFORT_BASELINE2;
3737
3742
  /** A one-shot focus/rest request from the executive, applied next react(). */
3738
3743
  _effortRequest = null;
3744
+ /** ACP-P2: a self-caused precision attenuation is armed; react() restores after one observe. */
3745
+ _acpOneShot = false;
3739
3746
  _bus = null;
3740
3747
  _model = new GenerativeModel();
3741
3748
  constructor(config = {}) {
@@ -3756,8 +3763,12 @@ var AttentionAllocator = class {
3756
3763
  "executive.prediction.formed",
3757
3764
  "attention.regulate",
3758
3765
  // voluntary focus/rest from the executive (Option C)
3759
- "senses.*"
3766
+ "senses.*",
3760
3767
  // all sense percepts — salience feeds attention allocation
3768
+ // ACP-P2: our own enactions — anticipate the attention swing they cause
3769
+ "agency.enacted",
3770
+ "agency.communicate",
3771
+ "agency.invocation"
3761
3772
  ];
3762
3773
  }
3763
3774
  publishes() {
@@ -3784,6 +3795,18 @@ var AttentionAllocator = class {
3784
3795
  this._model.setPrecision("attention.usage", 1 + p.confidence * 0.5);
3785
3796
  break;
3786
3797
  }
3798
+ case "agency.enacted":
3799
+ case "agency.communicate":
3800
+ case "agency.invocation": {
3801
+ const usage = this._model.predict("attention.usage");
3802
+ const free = this._model.predict("attention.free_fraction");
3803
+ this._model.anticipate("attention.usage", Math.min(1, usage + ACP_USAGE_UPLIFT), ACP_CONFIDENCE);
3804
+ this._model.anticipate("attention.free_fraction", Math.max(0, free - ACP_USAGE_UPLIFT), ACP_CONFIDENCE);
3805
+ this._model.setPrecision("attention.usage", ACP_SELF_PRECISION);
3806
+ this._model.setPrecision("attention.free_fraction", ACP_SELF_PRECISION);
3807
+ this._acpOneShot = true;
3808
+ break;
3809
+ }
3787
3810
  default:
3788
3811
  if (e.type.startsWith("senses.")) {
3789
3812
  const percept = e.payload;
@@ -3867,6 +3890,11 @@ var AttentionAllocator = class {
3867
3890
  if (_bus) {
3868
3891
  const usageErr = this._model.observe("attention.usage", attentionUsage);
3869
3892
  const freeErr = this._model.observe("attention.free_fraction", freeFraction);
3893
+ if (this._acpOneShot) {
3894
+ this._model.setPrecision("attention.usage", 1);
3895
+ this._model.setPrecision("attention.free_fraction", 1);
3896
+ this._acpOneShot = false;
3897
+ }
3870
3898
  if (!usageErr.gated || !freeErr.gated)
3871
3899
  _bus.publish({ type: "attention.state.changed", version: 1, sourceEngine: this.name, salience: Math.max(usageErr.salience, freeErr.salience), payload: { usage: attentionUsage, focusCount, capacity: effectiveCapacity, freeFraction } });
3872
3900
  }
@@ -3986,7 +4014,18 @@ var StressRegulator = class {
3986
4014
  }
3987
4015
  // ── Engine interface ─────────────────────────────────────
3988
4016
  subscribes() {
3989
- return ["energy.state.changed", "sleep.state.changed", "novelty.state.changed", "goal.state.changed", "metacognition.state.changed", "executive.prediction.formed"];
4017
+ return [
4018
+ "energy.state.changed",
4019
+ "sleep.state.changed",
4020
+ "novelty.state.changed",
4021
+ "goal.state.changed",
4022
+ "metacognition.state.changed",
4023
+ "executive.prediction.formed",
4024
+ // ACP-P2: our own enactions — the stress swing they cause is expected
4025
+ "agency.enacted",
4026
+ "agency.communicate",
4027
+ "agency.invocation"
4028
+ ];
3990
4029
  }
3991
4030
  publishes() {
3992
4031
  return [];
@@ -4015,8 +4054,17 @@ var StressRegulator = class {
4015
4054
  this._model.setPrecision("stress.load", 1 + p.confidence * 0.5);
4016
4055
  break;
4017
4056
  }
4057
+ case "agency.enacted":
4058
+ case "agency.communicate":
4059
+ case "agency.invocation": {
4060
+ this._model.setPrecision("stress.load", ACP_SELF_PRECISION);
4061
+ this._acpOneShot = true;
4062
+ break;
4063
+ }
4018
4064
  }
4019
4065
  }
4066
+ /** ACP-P2: self-caused stress attenuation armed; react() restores after one observe. */
4067
+ _acpOneShot = false;
4020
4068
  snapshot() {
4021
4069
  return {
4022
4070
  energyLevel: this._energyLevel,
@@ -4109,6 +4157,10 @@ var StressRegulator = class {
4109
4157
  if (_bus) {
4110
4158
  const zoneCode = zone === "low" ? 0 : zone === "optimal" ? 1 : zone === "distress" ? 2 : 3;
4111
4159
  const predErr = this._model.observe("stress.load", newLoad);
4160
+ if (this._acpOneShot) {
4161
+ this._model.setPrecision("stress.load", 1);
4162
+ this._acpOneShot = false;
4163
+ }
4112
4164
  if (!predErr.gated || zone !== previousZone) {
4113
4165
  _bus.publish({ type: "stress.state.changed", version: 1, sourceEngine: this.name, salience: predErr.salience, payload: { load: newLoad, zoneCode, deadlineUrgency: state.metrics.get("deadline.urgency") ?? 0, cognitiveLoad: state.metrics.get("cognitive.load") ?? state.metrics.get("attention.usage") ?? 0 } });
4114
4166
  }
@@ -4331,6 +4383,116 @@ var CircadianOscillator = class {
4331
4383
  }
4332
4384
  };
4333
4385
 
4386
+ // src/cognition/agency/consequence.ts
4387
+ var CONSEQUENCE_TYPE = "agency.consequence";
4388
+ var ATTENUATION = 0.25;
4389
+ var MIN_TEXT_MATCH_LEN = 12;
4390
+ var CONSEQUENCE_TTL_TICKS = 30;
4391
+ function fnv1a(text) {
4392
+ let h = 2166136261;
4393
+ for (let i = 0; i < text.length; i++) {
4394
+ h ^= text.charCodeAt(i);
4395
+ h = Math.imul(h, 16777619) >>> 0;
4396
+ }
4397
+ return h >>> 0;
4398
+ }
4399
+ function paramsKey(value) {
4400
+ if (value === null || typeof value !== "object")
4401
+ return typeof value === "string" ? JSON.stringify(value) : String(value);
4402
+ if (Array.isArray(value))
4403
+ return `[${value.map(paramsKey).join(",")}]`;
4404
+ const obj = value;
4405
+ const keys = Object.keys(obj).sort();
4406
+ return `{${keys.map((k) => `${k}:${paramsKey(obj[k])}`).join(",")}}`;
4407
+ }
4408
+ function consequenceEntity(d) {
4409
+ return {
4410
+ id: `agency-consequence-${d.intentId}`,
4411
+ type: CONSEQUENCE_TYPE,
4412
+ metadata: { ...d }
4413
+ };
4414
+ }
4415
+ function readConsequence(m) {
4416
+ const meta = m ?? {};
4417
+ const intentId = typeof meta["intentId"] === "string" ? meta["intentId"] : void 0;
4418
+ const schema = typeof meta["schema"] === "string" ? meta["schema"] : void 0;
4419
+ const mode = meta["mode"] === "communicate" || meta["mode"] === "external" ? meta["mode"] : void 0;
4420
+ if (!intentId || !schema || !mode) return null;
4421
+ return {
4422
+ intentId,
4423
+ schema,
4424
+ mode,
4425
+ effector: typeof meta["effector"] === "string" ? meta["effector"] : void 0,
4426
+ targetEntityId: typeof meta["targetEntityId"] === "string" ? meta["targetEntityId"] : void 0,
4427
+ textHash: typeof meta["textHash"] === "number" ? meta["textHash"] : void 0,
4428
+ text: typeof meta["text"] === "string" ? meta["text"] : void 0,
4429
+ paramsHash: typeof meta["paramsHash"] === "number" ? meta["paramsHash"] : void 0,
4430
+ expiresAt: typeof meta["expiresAt"] === "number" ? meta["expiresAt"] : 0,
4431
+ tick: typeof meta["tick"] === "number" ? meta["tick"] : 0
4432
+ };
4433
+ }
4434
+ function liveConsequences(entities, tick) {
4435
+ const out = [];
4436
+ for (const [, e] of entities) {
4437
+ if (e.type !== CONSEQUENCE_TYPE) continue;
4438
+ const d = readConsequence(e.metadata);
4439
+ if (d && tick < d.expiresAt) out.push(d);
4440
+ }
4441
+ return out.sort((a, b) => a.intentId < b.intentId ? -1 : a.intentId > b.intentId ? 1 : 0);
4442
+ }
4443
+ function matchConsequenceText(descriptors, candidate) {
4444
+ if (candidate.length === 0) return null;
4445
+ const candidateHash = fnv1a(candidate);
4446
+ for (const d of descriptors) {
4447
+ if (d.textHash !== void 0 && d.textHash === candidateHash) return d;
4448
+ if (d.text !== void 0 && d.text.length >= MIN_TEXT_MATCH_LEN && candidate.includes(d.text)) return d;
4449
+ }
4450
+ return null;
4451
+ }
4452
+ var CORRESPONDENCE_ATTENUATION = 0.5;
4453
+ function matchConsequenceEntity(descriptors, entityId, changeType) {
4454
+ if (changeType !== "modified" || entityId.length === 0) return null;
4455
+ for (const d of descriptors)
4456
+ if (d.mode === "external" && d.targetEntityId === entityId) return d;
4457
+ return null;
4458
+ }
4459
+
4460
+ // src/cognition/agency/revocation.ts
4461
+ var REVOCATION_TYPE = "agency.revocation";
4462
+ var RUPTURE_REVOKE_GATE = 0.7;
4463
+ var REVOCATION_TTL_TICKS = 5;
4464
+ function revocationId(intentId) {
4465
+ return `agency-revocation-${intentId}`;
4466
+ }
4467
+ function revocationEntity(intentId, schema, rupture, tick) {
4468
+ return {
4469
+ id: revocationId(intentId),
4470
+ type: REVOCATION_TYPE,
4471
+ metadata: { intentId, schema, rupture, tick, expiresAt: tick + REVOCATION_TTL_TICKS }
4472
+ };
4473
+ }
4474
+ function revokedIntentIds(entities, tick) {
4475
+ const out = /* @__PURE__ */ new Set();
4476
+ for (const [, e] of entities) {
4477
+ if (e.type !== REVOCATION_TYPE) continue;
4478
+ const m = e.metadata ?? {};
4479
+ const intentId = typeof m["intentId"] === "string" ? m["intentId"] : void 0;
4480
+ const expiresAt = typeof m["expiresAt"] === "number" ? m["expiresAt"] : 0;
4481
+ if (intentId && tick < expiresAt) out.add(intentId);
4482
+ }
4483
+ return out;
4484
+ }
4485
+ function staleRevocationIds(entities, tick) {
4486
+ const stale = [];
4487
+ for (const [id, e] of entities) {
4488
+ if (e.type !== REVOCATION_TYPE) continue;
4489
+ const m = e.metadata ?? {};
4490
+ const expiresAt = typeof m["expiresAt"] === "number" ? m["expiresAt"] : 0;
4491
+ if (tick >= expiresAt) stale.push(id);
4492
+ }
4493
+ return stale;
4494
+ }
4495
+
4334
4496
  // src/cognition/faculties/exteroception.ts
4335
4497
  var internalTypes = /* @__PURE__ */ new Set([
4336
4498
  "percept",
@@ -4356,7 +4518,12 @@ var internalTypes = /* @__PURE__ */ new Set([
4356
4518
  "episodic_memory",
4357
4519
  // Internal state entities written by our own engines — not external events
4358
4520
  "affect.blends",
4359
- "executive.summary"
4521
+ "executive.summary",
4522
+ // The agency's own forward-model records (EXAFFERENCE P1/P2): perceiving our
4523
+ // expected-consequence descriptors would be a self-noise loop.
4524
+ CONSEQUENCE_TYPE,
4525
+ // The agency's own revocation tombstones (EXAFFERENCE P4) — internal bookkeeping.
4526
+ REVOCATION_TYPE
4360
4527
  ]);
4361
4528
  var Exteroception = class {
4362
4529
  name = "exteroception";
@@ -4406,17 +4573,26 @@ var Exteroception = class {
4406
4573
  const events = [], commands = { set: [], delete: [], metrics: [] };
4407
4574
  const rawPercepts = this._scanWorld(state);
4408
4575
  const capped = rawPercepts.slice(0, this._maxPerceptsPerTick);
4576
+ const consequences = liveConsequences(state.entities, tick);
4409
4577
  for (let i = 0; i < capped.length; i++) {
4410
4578
  const rp = capped[i];
4579
+ const textHit = consequences.length > 0 && rp.matchText ? matchConsequenceText(consequences, rp.matchText) : null;
4580
+ const entityHit = !textHit && consequences.length > 0 ? matchConsequenceEntity(consequences, rp.entityId, rp.changeType) : null;
4581
+ const hit = textHit ?? entityHit;
4582
+ const salience = textHit ? rp.salience * ATTENUATION : entityHit ? rp.salience * CORRESPONDENCE_ATTENUATION : rp.salience;
4411
4583
  const perceptEntity = {
4412
4584
  id: `percept-${tick}-${i}`,
4413
4585
  type: "percept",
4414
4586
  metadata: {
4415
4587
  entityId: rp.entityId,
4416
4588
  changeType: rp.changeType,
4417
- salience: rp.salience,
4589
+ salience,
4418
4590
  category: rp.category,
4419
4591
  summary: rp.summary,
4592
+ provenance: hit ? "reafferent" : "exafferent",
4593
+ ...hit ? { sourceIntentId: hit.intentId } : {},
4594
+ // affect→percept seam (registry #5): what this percept FEELS like
4595
+ ...rp.valence !== void 0 ? { valence: rp.valence, valenceSource: rp.valenceSource } : {},
4420
4596
  tick
4421
4597
  }
4422
4598
  };
@@ -4427,7 +4603,7 @@ var Exteroception = class {
4427
4603
  source: this.name,
4428
4604
  payload: {
4429
4605
  entityId: rp.entityId,
4430
- salience: rp.salience,
4606
+ salience,
4431
4607
  category: rp.category,
4432
4608
  summary: rp.summary
4433
4609
  }
@@ -4475,7 +4651,9 @@ var Exteroception = class {
4475
4651
  changeType: "appeared",
4476
4652
  salience: this._computeSalience(entity, "appeared", state.time),
4477
4653
  category: entity.type,
4478
- summary: this._summarizeEntity(entity, "appeared")
4654
+ summary: this._summarizeEntity(entity, "appeared"),
4655
+ matchText: this._matchText(entity),
4656
+ ...this._valenceOf(id, state)
4479
4657
  });
4480
4658
  } else if (entity.updatedAt > previousVersion) {
4481
4659
  percepts.push({
@@ -4483,7 +4661,9 @@ var Exteroception = class {
4483
4661
  changeType: "modified",
4484
4662
  salience: this._computeSalience(entity, "modified", state.time),
4485
4663
  category: entity.type,
4486
- summary: this._summarizeEntity(entity, "modified")
4664
+ summary: this._summarizeEntity(entity, "modified"),
4665
+ matchText: this._matchText(entity),
4666
+ ...this._valenceOf(id, state)
4487
4667
  });
4488
4668
  }
4489
4669
  this._previousEntityVersions.set(id, entity.updatedAt);
@@ -4509,6 +4689,46 @@ var Exteroception = class {
4509
4689
  * Generate a meaningful summary for an entity.
4510
4690
  * Instead of "New percept: percept-54-0", produce something useful.
4511
4691
  */
4692
+ /**
4693
+ * The text the corollary-discharge matcher inspects for this entity — its
4694
+ * content (a message body) over its description over its summary. Where our
4695
+ * own delivered words would surface if the world echoes them back.
4696
+ */
4697
+ /**
4698
+ * The affect→percept valence seam (registry #5). A percept carries how the
4699
+ * mind *feels* about what it is a percept OF, resolved most-specific-first:
4700
+ *
4701
+ * 1. the KnownEntityTracker's dossier for this entity (`ke-<id>.valence`) —
4702
+ * a real per-entity felt valence, the honest signal;
4703
+ * 2. otherwise the ambient `affect.valence` — the felt tone at perception
4704
+ * time. Weaker evidence, so it is tagged `'ambient'` and consumers
4705
+ * weight it down (mood is context, not appraisal of this thing).
4706
+ *
4707
+ * Absent both, no valence is stamped and every consumer keeps its
4708
+ * pre-seam behaviour.
4709
+ */
4710
+ /** Spread-friendly form of `_valenceFor` for percept construction. */
4711
+ _valenceOf(entityId, state) {
4712
+ const v = this._valenceFor(entityId, state);
4713
+ return v ? { valence: v.valence, valenceSource: v.source } : {};
4714
+ }
4715
+ _valenceFor(entityId, state) {
4716
+ const dossier = state.entities.get(`ke-${entityId}`);
4717
+ const felt = dossier?.metadata?.["valence"];
4718
+ if (typeof felt === "number" && Number.isFinite(felt))
4719
+ return { valence: felt, source: "entity" };
4720
+ const ambient = state.metrics.get("affect.valence");
4721
+ if (typeof ambient === "number" && Number.isFinite(ambient))
4722
+ return { valence: ambient, source: "ambient" };
4723
+ return void 0;
4724
+ }
4725
+ _matchText(entity) {
4726
+ const m = entity.metadata;
4727
+ const content = typeof m?.["content"] === "string" ? m["content"] : void 0;
4728
+ const description = typeof m?.["description"] === "string" ? m["description"] : void 0;
4729
+ const summary = typeof m?.["summary"] === "string" ? m["summary"] : void 0;
4730
+ return content ?? description ?? summary;
4731
+ }
4512
4732
  _summarizeEntity(entity, changeType) {
4513
4733
  const name = entity.metadata?.name;
4514
4734
  const description = entity.metadata?.description;
@@ -6493,6 +6713,8 @@ var MoralEvaluator = class {
6493
6713
  };
6494
6714
 
6495
6715
  // src/cognition/faculties/affective.blender.ts
6716
+ var ACP_AROUSAL_UPLIFT = 0.1;
6717
+ var ACP_CONFIDENCE2 = 0.4;
6496
6718
  var DOMINANT_EMOTION_CODES = {
6497
6719
  "neutral": 0,
6498
6720
  "fear": 1,
@@ -6593,6 +6815,8 @@ var AffectiveBlender = class {
6593
6815
  _previousPAD = { valence: 0, arousal: 0.3, dominance: 0.5 };
6594
6816
  _emotionHistory = /* @__PURE__ */ new Map();
6595
6817
  _moodBaseline = 0.5;
6818
+ /** ACP-P2: self-caused arousal attenuation armed; react() restores after one observe. */
6819
+ _acpOneShot = false;
6596
6820
  _energyLevel = 100;
6597
6821
  _comfort = 0.5;
6598
6822
  _sleepPressure = 0;
@@ -6626,8 +6850,12 @@ var AffectiveBlender = class {
6626
6850
  "sleep.state.changed",
6627
6851
  "stress.state.changed",
6628
6852
  "executive.prediction.formed",
6629
- "interaction.occurred"
6853
+ "interaction.occurred",
6630
6854
  // 2.1: social stimuli drive immediate arousal/valence shifts
6855
+ // ACP-P2: our own enactions — the arousal they cause is expected, not surprising
6856
+ "agency.enacted",
6857
+ "agency.communicate",
6858
+ "agency.invocation"
6631
6859
  ];
6632
6860
  }
6633
6861
  publishes() {
@@ -6636,6 +6864,15 @@ var AffectiveBlender = class {
6636
6864
  onCognitiveEvent(e) {
6637
6865
  this._model.observe(e.type, e.salience);
6638
6866
  switch (e.type) {
6867
+ case "agency.enacted":
6868
+ case "agency.communicate":
6869
+ case "agency.invocation": {
6870
+ const arousal = this._model.predict("affect.arousal");
6871
+ this._model.anticipate("affect.arousal", Math.min(1, arousal + ACP_AROUSAL_UPLIFT), ACP_CONFIDENCE2);
6872
+ this._model.setPrecision("affect.arousal", ACP_SELF_PRECISION);
6873
+ this._acpOneShot = true;
6874
+ break;
6875
+ }
6639
6876
  case "circadian.state.changed":
6640
6877
  this._moodBaseline = e.payload["moodBaseline"] ?? this._moodBaseline;
6641
6878
  break;
@@ -6739,8 +6976,14 @@ var AffectiveBlender = class {
6739
6976
  const _bus = this._bus;
6740
6977
  if (_bus)
6741
6978
  _bus.publish({ type: "affect.state.shifted", version: 1, sourceEngine: this.name, salience: Math.min(1, Math.abs(modulatedPAD.valence) + modulatedPAD.arousal * 0.5), payload: { valence: modulatedPAD.valence, arousal: modulatedPAD.arousal, dominantEmotion: dominant } });
6742
- if (_bus)
6743
- _bus.publish({ type: "affect.state.changed", version: 1, sourceEngine: this.name, salience: this._model.observe("affect.arousal", modulatedPAD.arousal).salience, payload: { valence: modulatedPAD.valence, arousal: modulatedPAD.arousal, dominance: modulatedPAD.dominance } });
6979
+ if (_bus) {
6980
+ const arousalErr = this._model.observe("affect.arousal", modulatedPAD.arousal);
6981
+ if (this._acpOneShot) {
6982
+ this._model.setPrecision("affect.arousal", 1);
6983
+ this._acpOneShot = false;
6984
+ }
6985
+ _bus.publish({ type: "affect.state.changed", version: 1, sourceEngine: this.name, salience: arousalErr.salience, payload: { valence: modulatedPAD.valence, arousal: modulatedPAD.arousal, dominance: modulatedPAD.dominance } });
6986
+ }
6744
6987
  return { events: events.length > 0 ? events : void 0, commands };
6745
6988
  }
6746
6989
  // ── PAD computation ──────────────────────────────────────
@@ -14752,7 +14995,8 @@ var TaskSwitcher = class {
14752
14995
  const currentGoal = activeGoals.find((g) => g.id === this._currentFocus.goalId);
14753
14996
  const currentPriority = currentGoal?.priority ?? 0;
14754
14997
  const switchAdvantage = topGoal.priority - currentPriority;
14755
- const switchCost = this._baseSwitchCost * (1 + this._currentFocus.focusTicks * 0.01);
14998
+ const stability = state.metrics.get("situation.stability") ?? 1;
14999
+ const switchCost = this._baseSwitchCost * (1 + this._currentFocus.focusTicks * 0.01 * stability);
14756
15000
  const netBenefit = switchAdvantage - switchCost;
14757
15001
  if (netBenefit > this._switchThreshold && this._currentFocus.focusTicks >= this._minFocusTicks) {
14758
15002
  this._currentFocus = {
@@ -18569,9 +18813,7 @@ var AffordanceSynthesizer = class {
18569
18813
  if (e.type === "affordance") del.push(id);
18570
18814
  const floor = schemas.filter((s) => s.binds === "none");
18571
18815
  for (const schema of floor)
18572
- set.push(this._toEntity(
18573
- this._build(schema, tick, state, valence, energyLow, skills, {})
18574
- ));
18816
+ set.push(this._toEntity(this._build(schema, tick, state, valence, energyLow, skills, {})));
18575
18817
  const candidates = [];
18576
18818
  const goalTargets = collectGoalTargets(state);
18577
18819
  const perceptSchema = schemas.find((s) => s.binds === "percept");
@@ -18785,11 +19027,24 @@ var BASE_SWITCH_COST = 0.15;
18785
19027
  var FOCUS_GAIN = 0.01;
18786
19028
  var AWAIT_STALE_TICKS = 15;
18787
19029
  var STALE_DECAY = 0.5;
19030
+ var RUPTURE_SALIENCE_GATE = 0.4;
19031
+ var RUPTURE_WINDOW_TICKS = 2;
19032
+ var STABILITY_RECOVERY = 0.05;
19033
+ var STABILITY_EPSILON = 1e-4;
19034
+ var REVOKE_HINT_WINDOW = 8;
18788
19035
  var ActionSelector = class {
18789
19036
  name = "action-selector";
18790
19037
  _bus = null;
18791
19038
  _lastEntropy = 0;
18792
19039
  _lastDeliberate = false;
19040
+ // EXAFFERENCE P4 follow-up (Channel B): the schema we most recently revoked
19041
+ // under rupture, so the *next* deliberation formed in its wake can own the
19042
+ // interruption in-character ("something changed — I dropped what I was
19043
+ // weighing"). Telemetry-grade instance state, mirroring _lastEntropy.
19044
+ _lastRevoked = null;
19045
+ // ACP §2b: sense-channel percepts buffered off the bus for the next react's
19046
+ // rupture computation (they never become entities). Cross-tick ⇒ FN9.
19047
+ _senseBuffer = [];
18793
19048
  attachBus(bus) {
18794
19049
  this._bus = bus;
18795
19050
  }
@@ -18797,16 +19052,60 @@ var ActionSelector = class {
18797
19052
  return [
18798
19053
  { type: "agency.selection.made", version: 1, validate: () => null },
18799
19054
  { type: "agency.selection.ambiguous", version: 1, validate: () => null },
18800
- { type: "agency.action.preempted", version: 1, validate: () => null }
19055
+ { type: "agency.action.preempted", version: 1, validate: () => null },
19056
+ { type: "agency.situation.rupture", version: 1, validate: () => null },
19057
+ { type: "agency.commitment.revoked", version: 1, validate: () => null }
18801
19058
  ];
18802
19059
  }
18803
19060
  subscribes() {
18804
- return [];
19061
+ return [
19062
+ "senses.*",
19063
+ // Registry #6 (ACP-P3): the model-error term — each carries its
19064
+ // engine's prediction-error salience, ALREADY precision-attenuated for
19065
+ // self-caused swings by the ACP-P2 consumers, so the echo guard
19066
+ // composes by construction: our own action's interoceptive wake
19067
+ // arrives below the rupture gate.
19068
+ "attention.state.changed",
19069
+ "affect.state.changed",
19070
+ "stress.state.changed"
19071
+ ];
18805
19072
  }
18806
- onCognitiveEvent() {
19073
+ /**
19074
+ * Mostly pull-model — but two afferent classes never become entities and
19075
+ * would leave rupture blind: sense-channel percepts
19076
+ * (ACTION_CONDITIONED_PREDICTION §2b) and the model-error state-change
19077
+ * events (registry #6). Buffer both (cross-tick: bus flush at T, consumed
19078
+ * by react at T+1 — FN9-snapshotted); the echo guard is applied at read
19079
+ * time for texts, and at the SOURCE for model errors (ACP-P2 precision).
19080
+ */
19081
+ onCognitiveEvent(e) {
19082
+ const isSense = e.type.startsWith("senses.") && e.type.endsWith(".percept");
19083
+ const isModelError = e.type === "attention.state.changed" || e.type === "affect.state.changed" || e.type === "stress.state.changed";
19084
+ if (!isSense && !isModelError) return;
19085
+ const p = e.payload;
19086
+ this._senseBuffer.push({
19087
+ salience: e.salience,
19088
+ ...isSense && typeof p?.content === "string" ? { text: p.content } : {}
19089
+ });
18807
19090
  }
18808
19091
  snapshot() {
18809
- return { lastEntropy: this._lastEntropy, lastDeliberate: this._lastDeliberate };
19092
+ return {
19093
+ lastEntropy: this._lastEntropy,
19094
+ lastDeliberate: this._lastDeliberate,
19095
+ lastRevoked: this._lastRevoked,
19096
+ senseBuffer: this._senseBuffer
19097
+ };
19098
+ }
19099
+ /** FN9: `_lastRevoked` has behavioral effect (the Channel-B `revokedBy` stamp),
19100
+ * so a restored mind must carry it — a rupture-driven letting-go survives a
19101
+ * snapshot boundary instead of silently losing its narrative thread. */
19102
+ restore(s) {
19103
+ if (typeof s["lastEntropy"] === "number") this._lastEntropy = s["lastEntropy"];
19104
+ if (typeof s["lastDeliberate"] === "boolean") this._lastDeliberate = s["lastDeliberate"];
19105
+ const lr = s["lastRevoked"];
19106
+ this._lastRevoked = lr && typeof lr === "object" && typeof lr.schema === "string" && typeof lr.tick === "number" ? { schema: lr.schema, tick: lr.tick } : null;
19107
+ const sb = s["senseBuffer"];
19108
+ this._senseBuffer = Array.isArray(sb) ? sb.filter((it) => it && typeof it.salience === "number").map((it) => ({ salience: it.salience, ...typeof it.text === "string" ? { text: it.text } : {} })) : [];
18810
19109
  }
18811
19110
  async react(_delta, tick, state, _context) {
18812
19111
  const eligible = [];
@@ -18835,54 +19134,121 @@ var ActionSelector = class {
18835
19134
  let blocking = false;
18836
19135
  let awaiting = null;
18837
19136
  let composite = null;
19137
+ let deliberating = null;
18838
19138
  for (const it of intents) {
18839
- if (it.st === "deliberating") blocking = true;
18840
- else if (it.st === "expanding") composite = { id: it.id, activation: it.activation, schema: it.schema };
19139
+ if (it.st === "deliberating") {
19140
+ blocking = true;
19141
+ deliberating = { id: it.id, schema: it.schema };
19142
+ } else if (it.st === "expanding") composite = { id: it.id, activation: it.activation, schema: it.schema };
18841
19143
  else if (it.st === "awaiting") awaiting = { id: it.id, activation: it.activation, schema: it.schema, target: it.target, dispatchedAt: it.dispatchedAt };
18842
19144
  else if (it.st === "selected") {
18843
19145
  const activeMacroSub = it.parentIntentId !== void 0 && expandingParents.has(it.parentIntentId);
18844
19146
  if (!activeMacroSub) blocking = true;
18845
19147
  }
18846
19148
  }
18847
- const busy = (n) => ({ commands: { metrics: [
18848
- ["agency.field.eligible", n],
18849
- ["agency.selection.busy", 1]
18850
- ] } });
19149
+ const senseEvents = this._senseBuffer;
19150
+ this._senseBuffer = [];
19151
+ const rupture = computeRupture(state, tick, senseEvents);
19152
+ const prevStab = metric2(state, "situation.stability", 1);
19153
+ const nextStabRaw = clamp017(prevStab + STABILITY_RECOVERY * (1 - prevStab) - rupture);
19154
+ const nextStab = 1 - nextStabRaw < STABILITY_EPSILON ? 1 : nextStabRaw;
19155
+ const stabMetrics = rupture > 0 || prevStab < 1 ? [["situation.stability", nextStab]] : [];
19156
+ if (rupture > 0 && this._bus) {
19157
+ try {
19158
+ this._bus.publish({
19159
+ type: "agency.situation.rupture",
19160
+ version: 1,
19161
+ sourceEngine: this.name,
19162
+ salience: rupture,
19163
+ payload: { rupture, stability: nextStab, tick }
19164
+ });
19165
+ } catch (err) {
19166
+ logger.warn(`[selector] rupture publish failed: ${err instanceof Error ? err.message : String(err)}`);
19167
+ }
19168
+ }
19169
+ const busy = (n) => ({
19170
+ commands: {
19171
+ metrics: [
19172
+ ["agency.field.eligible", n],
19173
+ ["agency.selection.busy", 1],
19174
+ ...stabMetrics
19175
+ ]
19176
+ }
19177
+ });
19178
+ if (deliberating && rupture >= RUPTURE_REVOKE_GATE) {
19179
+ if (this._bus) {
19180
+ try {
19181
+ this._bus.publish({
19182
+ type: "agency.commitment.revoked",
19183
+ version: 1,
19184
+ sourceEngine: this.name,
19185
+ salience: 0.85,
19186
+ payload: { from: deliberating.schema, reason: "exafferent-rupture", rupture, tick }
19187
+ });
19188
+ } catch (err) {
19189
+ logger.warn(`[selector] revoked publish failed: ${err instanceof Error ? err.message : String(err)}`);
19190
+ }
19191
+ }
19192
+ this._lastRevoked = { schema: deliberating.schema, tick };
19193
+ return {
19194
+ commands: {
19195
+ set: [revocationEntity(deliberating.id, deliberating.schema, rupture, tick)],
19196
+ metrics: [
19197
+ ["agency.field.eligible", eligible.length],
19198
+ ["agency.selection.busy", 1],
19199
+ ["agency.commitment.revoked", 1],
19200
+ ...stabMetrics
19201
+ ]
19202
+ }
19203
+ };
19204
+ }
18851
19205
  if (blocking) return busy(eligible.length);
18852
19206
  if (eligible.length === 0)
18853
- return { commands: { metrics: [["agency.field.eligible", 0], ["agency.selection.busy", awaiting || composite ? 1 : 0]] } };
19207
+ return {
19208
+ commands: {
19209
+ metrics: [
19210
+ ["agency.field.eligible", 0],
19211
+ ["agency.selection.busy", awaiting || composite ? 1 : 0],
19212
+ ...stabMetrics
19213
+ ]
19214
+ }
19215
+ };
18854
19216
  const bias = buildBias(state);
18855
- const effSwitchCost = effectiveSwitchCost(state);
19217
+ const effSwitchCost = effectiveSwitchCost(state) * (1 - rupture);
18856
19218
  const weights = effectiveWeights(state);
18857
19219
  const scored = eligible.map((a) => ({ affordance: a, activation: scoreAffordance(a, bias, weights) })).sort((x, y) => y.activation - x.activation);
18858
19220
  const winner = scored[0];
18859
19221
  if (!winner) return busy(eligible.length);
19222
+ let compositeTombstone;
19223
+ let compositeFrom;
18860
19224
  if (composite) {
18861
19225
  const different = winner.affordance.schema !== composite.schema;
18862
19226
  const switchCost = effSwitchCost * (1 - stakes(winner.affordance, bias));
18863
- if (different && winner.activation > composite.activation + switchCost) {
18864
- if (this._bus) try {
19227
+ if (!different || winner.activation <= composite.activation + switchCost)
19228
+ return busy(eligible.length);
19229
+ if (this._bus)
19230
+ try {
18865
19231
  this._bus.publish({
18866
19232
  type: "agency.action.preempted",
18867
19233
  version: 1,
18868
19234
  sourceEngine: this.name,
18869
19235
  salience: 0.8,
18870
- payload: { from: composite.schema, to: winner.affordance.schema, activation: winner.activation, tick }
19236
+ payload: {
19237
+ from: composite.schema,
19238
+ to: winner.affordance.schema,
19239
+ activation: winner.activation,
19240
+ tick
19241
+ }
18871
19242
  });
18872
19243
  } catch (err) {
18873
19244
  logger.warn(`[selector] preempt publish failed: ${err instanceof Error ? err.message : String(err)}`);
18874
19245
  }
18875
- return { commands: { delete: [composite.id], metrics: [
18876
- ["agency.field.eligible", eligible.length],
18877
- ["agency.selection.busy", 1],
18878
- ["agency.selection.preempted", 1]
18879
- ] } };
18880
- }
18881
- return busy(eligible.length);
19246
+ compositeTombstone = composite.id;
19247
+ compositeFrom = composite.schema;
18882
19248
  }
18883
19249
  let preemptDelete;
18884
- let preemptedFrom;
18885
- if (awaiting) {
19250
+ let preemptedFrom = compositeFrom;
19251
+ if (awaiting && !compositeTombstone) {
18886
19252
  const sameAction = winner.affordance.schema === awaiting.schema && (winner.affordance.targetEntityId ?? "") === awaiting.target;
18887
19253
  if (sameAction) return busy(eligible.length);
18888
19254
  const staleness = Math.min(1, (tick - awaiting.dispatchedAt) / AWAIT_STALE_TICKS);
@@ -18905,6 +19271,13 @@ var ActionSelector = class {
18905
19271
  const deliberate = margin < marginGate || stk > stakesGate;
18906
19272
  this._lastEntropy = entropy;
18907
19273
  this._lastDeliberate = deliberate;
19274
+ let revokedBy;
19275
+ if (this._lastRevoked) {
19276
+ if (deliberate && tick - this._lastRevoked.tick <= REVOKE_HINT_WINDOW)
19277
+ revokedBy = this._lastRevoked.schema;
19278
+ if (revokedBy || tick - this._lastRevoked.tick > REVOKE_HINT_WINDOW)
19279
+ this._lastRevoked = null;
19280
+ }
18908
19281
  const intent = {
18909
19282
  id: `agency-intent-${tick}`,
18910
19283
  type: "agency.intent",
@@ -18947,6 +19320,9 @@ var ActionSelector = class {
18947
19320
  // interrupted, so the deliberation facet can own the interruption in-character
18948
19321
  // ("I was about to X, but this pulled me away"). Only meaningful while deliberating.
18949
19322
  ...preemptedFrom ? { preemptedFrom } : {},
19323
+ // Channel B: this deliberation forms in the wake of a rupture-driven
19324
+ // revocation — the facet can own "something changed, I let go of X".
19325
+ ...revokedBy ? { revokedBy } : {},
18950
19326
  tick
18951
19327
  }
18952
19328
  };
@@ -18985,7 +19361,9 @@ var ActionSelector = class {
18985
19361
  }
18986
19362
  }
18987
19363
  const commands = {
18988
- set: [intent],
19364
+ // A composite preemption rides along as a tombstone (never a delete — the
19365
+ // executor's in-tick macro-advance would resurrect the parent).
19366
+ set: compositeTombstone ? [intent, revocationEntity(compositeTombstone, compositeFrom ?? "", rupture, tick)] : [intent],
18989
19367
  ...preemptDelete ? { delete: [preemptDelete] } : {},
18990
19368
  metrics: [
18991
19369
  ["agency.field.eligible", eligible.length],
@@ -18994,7 +19372,8 @@ var ActionSelector = class {
18994
19372
  ["agency.selection.margin", margin],
18995
19373
  ["agency.selection.deliberate", deliberate ? 1 : 0],
18996
19374
  ["agency.selection.preempted", preemptedFrom ? 1 : 0],
18997
- ["agency.selection.activation", winner.activation]
19375
+ ["agency.selection.activation", winner.activation],
19376
+ ...stabMetrics
18998
19377
  ]
18999
19378
  };
19000
19379
  return { commands };
@@ -19004,7 +19383,29 @@ function effectiveSwitchCost(state) {
19004
19383
  const params = readEffectiveParams(state, "engine-config-action-selector");
19005
19384
  const base = num2(params["switchCost"], BASE_SWITCH_COST);
19006
19385
  const focusTicks = metric2(state, "task_switch.current_focus_ticks", 0);
19007
- return base * (1 + focusTicks * FOCUS_GAIN);
19386
+ const stability = metric2(state, "situation.stability", 1);
19387
+ return base * (1 + focusTicks * FOCUS_GAIN * stability);
19388
+ }
19389
+ function computeRupture(state, tick, senseEvents = []) {
19390
+ let maxSalience = 0;
19391
+ for (const e of state.entities.values()) {
19392
+ if (e.type !== "percept") continue;
19393
+ const m = e.metadata;
19394
+ if (str2(m?.["provenance"]) !== "exafferent") continue;
19395
+ const pTick = num2(m?.["tick"], -1);
19396
+ if (pTick < 0 || tick - pTick > RUPTURE_WINDOW_TICKS) continue;
19397
+ const s = num2(m?.["salience"], 0);
19398
+ if (s > maxSalience) maxSalience = s;
19399
+ }
19400
+ if (senseEvents.length > 0) {
19401
+ const live = liveConsequences(state.entities, tick);
19402
+ for (const ev of senseEvents) {
19403
+ if (ev.text !== void 0 && live.length > 0 && matchConsequenceText(live, ev.text)) continue;
19404
+ if (ev.salience > maxSalience) maxSalience = ev.salience;
19405
+ }
19406
+ }
19407
+ if (maxSalience <= RUPTURE_SALIENCE_GATE) return 0;
19408
+ return clamp017((maxSalience - RUPTURE_SALIENCE_GATE) / (1 - RUPTURE_SALIENCE_GATE));
19008
19409
  }
19009
19410
  function effectiveWeights(state) {
19010
19411
  const p = readEffectiveParams(state, "engine-config-action-selector");
@@ -19105,19 +19506,28 @@ var DeliberationEngine = class {
19105
19506
  return { deliberations: this._deliberations };
19106
19507
  }
19107
19508
  async react(_delta, tick, state, _context) {
19509
+ const revoked = revokedIntentIds(state.entities, tick);
19510
+ const del = [];
19108
19511
  let target = null;
19109
19512
  for (const [id2, e] of state.entities) {
19110
19513
  if (e.type !== "agency.intent") continue;
19111
19514
  if (str3(e.metadata?.["status"]) !== "deliberating") continue;
19515
+ if (revoked.has(id2)) {
19516
+ del.push(id2, revocationId(id2));
19517
+ continue;
19518
+ }
19112
19519
  const meta2 = e.metadata ?? {};
19113
19520
  if (!target || id2 < target.id) target = { id: id2, meta: meta2 };
19114
19521
  }
19115
- if (!target) return { commands: {} };
19522
+ if (!target) return del.length > 0 ? { commands: { delete: del } } : { commands: {} };
19116
19523
  const { id, meta } = target;
19117
19524
  const provisional = str3(meta["schema"]) ?? "wait";
19118
19525
  const candidates = Array.isArray(meta["candidates"]) ? meta["candidates"] : [];
19119
19526
  if (!this._provider)
19120
- return { commands: { set: [this._commit(id, meta, provisional, candidates, "no-executive")] } };
19527
+ return { commands: {
19528
+ set: [this._commit(id, meta, provisional, candidates, "no-executive")],
19529
+ ...del.length > 0 ? { delete: del } : {}
19530
+ } };
19121
19531
  const chosen = await this._deliberate(state, candidates, provisional, meta);
19122
19532
  this._deliberations++;
19123
19533
  if (this._bus) {
@@ -19135,6 +19545,7 @@ var DeliberationEngine = class {
19135
19545
  return {
19136
19546
  commands: {
19137
19547
  set: [this._commit(id, meta, chosen, candidates, "facet")],
19548
+ ...del.length > 0 ? { delete: del } : {},
19138
19549
  metrics: [["agency.deliberation.count", 1]]
19139
19550
  }
19140
19551
  };
@@ -19192,7 +19603,10 @@ var DeliberationEngine = class {
19192
19603
  _buildFocusContent(state, candidates, meta) {
19193
19604
  const lines = [];
19194
19605
  const preemptedFrom = str3(meta["preemptedFrom"]);
19195
- if (preemptedFrom)
19606
+ const revokedBy = str3(meta["revokedBy"]);
19607
+ if (revokedBy)
19608
+ lines.push(`Something in my situation just shifted and I let go of what I was weighing ("${revokedBy}"). Decide afresh what to do now:`);
19609
+ else if (preemptedFrom)
19196
19610
  lines.push(`I just broke off a pending action ("${preemptedFrom}") because something more pressing pulled at me. Decide what to do now:`);
19197
19611
  else
19198
19612
  lines.push("My automatic action-selection was uncertain. Candidate actions:");
@@ -19365,6 +19779,19 @@ var MotorSchemaExecutor = class {
19365
19779
  const metrics = [];
19366
19780
  const energy = state.metrics.get("energy.level") ?? 100;
19367
19781
  const stress = state.metrics.get("stress.load") ?? 0;
19782
+ for (const [id, e] of state.entities) {
19783
+ if (e.type !== CONSEQUENCE_TYPE) continue;
19784
+ if (tick >= num3(e.metadata?.["expiresAt"], 0)) del.push(id);
19785
+ }
19786
+ del.push(...staleRevocationIds(state.entities, tick));
19787
+ const revoked = revokedIntentIds(state.entities, tick);
19788
+ if (revoked.size > 0)
19789
+ for (const [id, e] of state.entities) {
19790
+ if (e.type !== "agency.intent") continue;
19791
+ const parentId = str5(e.metadata?.["parentIntentId"]);
19792
+ if (revoked.has(id)) del.push(id, revocationId(id));
19793
+ else if (parentId && revoked.has(parentId)) del.push(id);
19794
+ }
19368
19795
  for (const [id, e] of state.entities) {
19369
19796
  if (e.type !== "agency.intent" || str5(e.metadata?.["status"]) !== "awaiting") continue;
19370
19797
  const dispatchedAt = num3(e.metadata?.["dispatchedAt"], tick);
@@ -19391,6 +19818,9 @@ var MotorSchemaExecutor = class {
19391
19818
  const selected = [...state.entities.entries()].filter(([, e]) => e.type === "agency.intent" && str5(e.metadata?.["status"]) === "selected").sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
19392
19819
  let enactedCount = 0;
19393
19820
  for (const [id, e] of selected) {
19821
+ if (revoked.has(id)) continue;
19822
+ const parentOf = str5(e.metadata?.["parentIntentId"]);
19823
+ if (parentOf && revoked.has(parentOf)) continue;
19394
19824
  const intent = readIntent(id, e.metadata);
19395
19825
  const schema = this._resolve(intent.schema);
19396
19826
  if (schema?.kind === "composite" && schema.composedOf && schema.composedOf.length > 0) {
@@ -19439,6 +19869,18 @@ var MotorSchemaExecutor = class {
19439
19869
  predictedValence: predicted.expectedValence
19440
19870
  }
19441
19871
  });
19872
+ const awaitingText = enaction.mode === "communicate" ? str5(intent.parameters["content"]) ?? firstMessage(intent.parameters["messages"]) : void 0;
19873
+ set.push(consequenceEntity({
19874
+ intentId: id,
19875
+ schema: intent.schema,
19876
+ mode: enaction.mode === "communicate" ? "communicate" : "external",
19877
+ ...enaction.mode === "communicate" ? { effector: COMM_SCHEMA_TO_EFFECTOR[intent.schema] ?? intent.schema } : {},
19878
+ ...intent.targetEntityId ? { targetEntityId: intent.targetEntityId } : {},
19879
+ ...awaitingText ? { text: awaitingText, textHash: fnv1a(awaitingText) } : {},
19880
+ paramsHash: fnv1a(paramsKey(intent.parameters)),
19881
+ expiresAt: tick + CONSEQUENCE_TTL_TICKS,
19882
+ tick
19883
+ }));
19442
19884
  this._emitDispatch(intent, enaction.mode, tick);
19443
19885
  metrics.push([enaction.mode === "communicate" ? "agency.communicate.dispatched" : "agency.invocation.dispatched", 1]);
19444
19886
  }
@@ -19605,6 +20047,18 @@ var MotorSchemaExecutor = class {
19605
20047
  };
19606
20048
  set.push(outcomeEntity(tick, intent, out, predicted));
19607
20049
  del.push(id);
20050
+ if (result.success)
20051
+ set.push(consequenceEntity({
20052
+ intentId: id,
20053
+ schema: intent.schema,
20054
+ mode: "communicate",
20055
+ effector,
20056
+ ...intent.targetEntityId ? { targetEntityId: intent.targetEntityId } : {},
20057
+ textHash: fnv1a(bubbles.join("\n")),
20058
+ text: bubbles.join("\n"),
20059
+ expiresAt: tick + CONSEQUENCE_TTL_TICKS,
20060
+ tick
20061
+ }));
19608
20062
  this._emitEnacted(intent, out, predicted, tick);
19609
20063
  this._emitActionOutcome(
19610
20064
  intent,
@@ -19941,6 +20395,10 @@ function readSchema(m) {
19941
20395
 
19942
20396
  // src/cognition/agency/engines/reafference.engine.ts
19943
20397
  var PROC_THRESHOLD2 = 0.6;
20398
+ var SENSORY_SOFT_QUALITY = 0.6;
20399
+ var SENSORY_VALENCE_SPAN_ENTITY = 0.25;
20400
+ var SENSORY_VALENCE_SPAN_AMBIENT = 0.1;
20401
+ var SENSORY_SUCCESS_FLOOR = 0.5;
19944
20402
  var ReafferenceEngine = class {
19945
20403
  name = "reafference";
19946
20404
  _repertoire;
@@ -19990,14 +20448,64 @@ var ReafferenceEngine = class {
19990
20448
  const set = [];
19991
20449
  const del = [];
19992
20450
  const metrics = [];
19993
- let updates = 0;
19994
- let discovered = 0;
20451
+ const outcomes = [];
20452
+ const gradedIntentIds = /* @__PURE__ */ new Set();
19995
20453
  for (const [id, e] of state.entities) {
19996
20454
  if (e.type !== "agency.outcome") continue;
19997
20455
  const m = e.metadata ?? {};
20456
+ outcomes.push({ id, meta: m, fromState: true });
20457
+ const iid = str6(m["intentId"]);
20458
+ if (iid) gradedIntentIds.add(iid);
20459
+ }
20460
+ const awaiting = /* @__PURE__ */ new Map();
20461
+ for (const [id, e] of state.entities) {
20462
+ if (e.type !== "agency.intent" || str6(e.metadata?.["status"]) !== "awaiting") continue;
20463
+ const m = e.metadata ?? {};
20464
+ if (tick - num4(m["dispatchedAt"], tick) >= AWAIT_TIMEOUT) continue;
20465
+ awaiting.set(id, {
20466
+ schema: str6(m["schema"]) ?? "",
20467
+ predictedReward: num4(m["predictedReward"], 0.5),
20468
+ predictedValence: num4(m["predictedValence"], 0)
20469
+ });
20470
+ }
20471
+ let sensory = 0;
20472
+ const sensedIntentIds = /* @__PURE__ */ new Set();
20473
+ for (const [, e] of state.entities) {
20474
+ if (e.type !== "percept") continue;
20475
+ const m = e.metadata ?? {};
20476
+ if (str6(m["provenance"]) !== "reafferent") continue;
20477
+ const iid = str6(m["sourceIntentId"]);
20478
+ if (!iid || gradedIntentIds.has(iid) || sensedIntentIds.has(iid)) continue;
20479
+ const aw = awaiting.get(iid);
20480
+ if (!aw || !aw.schema) continue;
20481
+ sensedIntentIds.add(iid);
20482
+ sensory++;
20483
+ const feltRaw = m["valence"];
20484
+ const felt = typeof feltRaw === "number" && Number.isFinite(feltRaw) ? feltRaw : void 0;
20485
+ const span = str6(m["valenceSource"]) === "entity" ? SENSORY_VALENCE_SPAN_ENTITY : SENSORY_VALENCE_SPAN_AMBIENT;
20486
+ const quality = felt === void 0 ? SENSORY_SOFT_QUALITY : clamp0111(SENSORY_SOFT_QUALITY + Math.max(-1, Math.min(1, felt)) * span);
20487
+ outcomes.push({ id: `agency-outcome-${tick}-${iid}-sensory`, fromState: false, meta: {
20488
+ schema: aw.schema,
20489
+ intentId: iid,
20490
+ success: quality >= SENSORY_SUCCESS_FLOOR,
20491
+ outcomeQuality: quality,
20492
+ valence: felt ?? aw.predictedValence,
20493
+ predictedReward: aw.predictedReward,
20494
+ predictedValence: aw.predictedValence,
20495
+ surprise: clamp0111(Math.abs(aw.predictedReward - quality)),
20496
+ mode: "external",
20497
+ reconciled: true,
20498
+ sensory: true,
20499
+ ...felt !== void 0 ? { sensoryValence: felt, valenceSource: str6(m["valenceSource"]) } : {},
20500
+ tick
20501
+ } });
20502
+ }
20503
+ let updates = 0;
20504
+ let discovered = 0;
20505
+ for (const { id, meta: m, fromState } of outcomes) {
19998
20506
  const schema = str6(m["schema"]);
19999
20507
  if (!schema) {
20000
- del.push(id);
20508
+ if (fromState) del.push(id);
20001
20509
  continue;
20002
20510
  }
20003
20511
  const { skill, proceduralized } = this._repertoire.recordOutcome({
@@ -20009,7 +20517,7 @@ var ReafferenceEngine = class {
20009
20517
  tick
20010
20518
  });
20011
20519
  set.push(skillEntity(skill));
20012
- del.push(id);
20520
+ if (fromState) del.push(id);
20013
20521
  const intentId = str6(m["intentId"]);
20014
20522
  if (intentId) del.push(intentId);
20015
20523
  updates++;
@@ -20037,7 +20545,8 @@ var ReafferenceEngine = class {
20037
20545
  ["agency.learning.updates", updates],
20038
20546
  ["agency.discovered.count", discovered],
20039
20547
  ["agency.skill.count", skills.size],
20040
- ["agency.habitual.count", habitual]
20548
+ ["agency.habitual.count", habitual],
20549
+ ["agency.sensory.confirmed", sensory]
20041
20550
  );
20042
20551
  return { commands: { set, delete: del, metrics } };
20043
20552
  }
@@ -20121,6 +20630,9 @@ function str6(v) {
20121
20630
  function num4(v, fallback) {
20122
20631
  return typeof v === "number" && Number.isFinite(v) ? v : fallback;
20123
20632
  }
20633
+ function clamp0111(n) {
20634
+ return n < 0 ? 0 : n > 1 ? 1 : n;
20635
+ }
20124
20636
 
20125
20637
  // src/stem/assembly.audit.ts
20126
20638
  function fieldForAttach(method) {
@@ -24504,6 +25016,10 @@ var OutboxController = class {
24504
25016
  summary: delivered ? `My message was delivered successfully.` : `My message failed to reach the recipient.`,
24505
25017
  salience: delivered ? 0.35 : 0.6,
24506
25018
  changeType: delivered ? "delivered" : "failed",
25019
+ // Reafference by construction — this percept describes our own action's
25020
+ // outcome ("ear hears the word"). Tagged, not attenuated: it is the ack
25021
+ // surface, not a content echo (EXAFFERENCE P2).
25022
+ provenance: "reafferent",
24507
25023
  messageId
24508
25024
  }
24509
25025
  });
@@ -24905,7 +25421,7 @@ var InboundQueue = class {
24905
25421
  function reconcileInvocation(intentId, schema, result, tick, predicted = { reward: 0.5, valence: 0 }, provenance = {}) {
24906
25422
  const outcomeQuality = result.outcomeQuality ?? (result.success ? 0.8 : 0.1);
24907
25423
  const valence = result.valence ?? (result.success ? 0.2 : -0.2);
24908
- const surprise = clamp0111(Math.abs(predicted.reward - outcomeQuality));
25424
+ const surprise = clamp0112(Math.abs(predicted.reward - outcomeQuality));
24909
25425
  return {
24910
25426
  id: `agency-outcome-${tick}-${intentId}`,
24911
25427
  type: "agency.outcome",
@@ -24927,7 +25443,7 @@ function reconcileInvocation(intentId, schema, result, tick, predicted = { rewar
24927
25443
  }
24928
25444
  };
24929
25445
  }
24930
- function clamp0111(n) {
25446
+ function clamp0112(n) {
24931
25447
  return n < 0 ? 0 : n > 1 ? 1 : n;
24932
25448
  }
24933
25449