counterparts 0.3.2 → 0.3.3

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 (66) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/package.json +1 -1
  3. package/src/adapters/claude-code/NOTES.md +12 -0
  4. package/src/adapters/claude-code/bin/hook.ts +85 -22
  5. package/src/adapters/claude-code/config.ts +7 -0
  6. package/src/adapters/claude-code/doctor.ts +20 -4
  7. package/src/adapters/claude-code/hooks.ts +157 -6
  8. package/src/adapters/claude-code/index.ts +3 -0
  9. package/src/adapters/cli/commands.ts +11 -0
  10. package/src/adapters/cli/mechanisms.ts +46 -21
  11. package/src/adapters/dashboard/registries.ts +4 -0
  12. package/src/adapters/dashboard/web/README.md +19 -11
  13. package/src/adapters/dashboard/web/flow.ts +2 -0
  14. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -5
  15. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +6 -3
  16. package/src/adapters/dashboard/web/narrate.ts +8 -0
  17. package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
  18. package/src/adapters/dashboard/web/pages/self/index.js +55 -16
  19. package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
  20. package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
  21. package/src/adapters/dashboard/web/pages/self/sections/settling.js +94 -99
  22. package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
  23. package/src/adapters/dashboard/web/pages/self/self.css +119 -59
  24. package/src/adapters/dashboard/web/pages/self/state.js +23 -0
  25. package/src/adapters/dashboard/web/pages/self/tips.js +50 -0
  26. package/src/adapters/dashboard/web/shared/memory-modal.js +9 -0
  27. package/src/adapters/dashboard/web/views/mechanisms.ts +85 -14
  28. package/src/adapters/dashboard/web/views/memory.ts +15 -1
  29. package/src/adapters/dashboard/web/views/mind.ts +130 -6
  30. package/src/adapters/feelings-line.ts +74 -0
  31. package/src/adapters/fired.ts +78 -18
  32. package/src/adapters/mcp/CONTRACT.md +8 -0
  33. package/src/adapters/mcp/NOTES.md +45 -0
  34. package/src/adapters/mcp/server.ts +165 -6
  35. package/src/adapters/mcp/tools.ts +51 -4
  36. package/src/core/bridge.ts +21 -16
  37. package/src/core/counterpart.ts +309 -6
  38. package/src/core/encode/CONTRACT.md +7 -1
  39. package/src/core/feelings-wheel.ts +171 -13
  40. package/src/core/mint.ts +9 -0
  41. package/src/core/physics/CONTRACT.md +43 -0
  42. package/src/core/physics/NOTES.md +94 -0
  43. package/src/core/physics/index.ts +98 -6
  44. package/src/core/prospective/CONTRACT.md +35 -6
  45. package/src/core/prospective/INTERFACE-GAPS.md +10 -5
  46. package/src/core/prospective/NOTES.md +175 -4
  47. package/src/core/prospective/derive.ts +32 -3
  48. package/src/core/prospective/index.ts +362 -39
  49. package/src/core/prospective/tunables.ts +18 -1
  50. package/src/core/prospective/windows.ts +104 -46
  51. package/src/core/recall/CONTRACT.md +28 -0
  52. package/src/core/recall/NOTES.md +39 -0
  53. package/src/core/recall/activate.ts +32 -5
  54. package/src/core/recall/gate.ts +7 -1
  55. package/src/core/recall/index.ts +19 -0
  56. package/src/core/recall/mood.ts +106 -0
  57. package/src/core/recall/tunables.ts +26 -0
  58. package/src/core/remember/index.ts +1 -0
  59. package/src/core/remember/proposals.ts +86 -3
  60. package/src/core/self/identity.ts +20 -1
  61. package/src/core/store/CONTRACT.md +9 -2
  62. package/src/core/store/NOTES.md +20 -0
  63. package/src/core/store/feelings.ts +23 -6
  64. package/src/core/store/index.ts +107 -10
  65. package/src/core/store/operational.ts +15 -1
  66. package/src/core/types.ts +9 -0
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * **Precision is carried by the date's own shape, never rounded** (§12 G4): a
5
5
  * `2026-09` stays a month for its whole life and is never quietly turned into
6
- * `2026-09-01`. A month *means* early month more than the 29th, so the two
6
+ * `2026-09-01`. A month *means* early month more than the 29th, so the
7
7
  * precisions get different ramps rather than the same ramp on a rounded date.
8
8
  *
9
9
  * **The firing key IS the window** (§12 G9), which buys two properties without
@@ -18,36 +18,45 @@
18
18
  * brake and `last_fired_day` are lived-day integers, and they live in `index.ts`.
19
19
  *
20
20
  * Pure: no ambient clock read anywhere in this file. The caller supplies `at`.
21
+ * Every date is read by `core/time.ts#parseCalendarDate` (docs/time.md rule 1).
21
22
  */
22
- import { addDays, daysBetween, isDay, monthBounds } from "../time.js";
23
+ import { addDays, daysBetween, monthBounds, parseCalendarDate } from "../time.js";
23
24
  import type { ProspectiveTunables } from "./tunables.js";
24
25
 
25
- /** As stated. `2026` / `2026-08` / `2026-08-25` — the three shapes prose carries. */
26
- export type DatePrecision = "day" | "month" | "year";
26
+ /** As stated. `2026` / `2026-08` / `2026-08-25` / `2026-10-20..2026-10-31` —
27
+ * the four shapes a reminder date carries (`core/time.ts`, schema v7). */
28
+ export type DatePrecision = "day" | "month" | "year" | "range";
27
29
 
28
- /** The two precisions that can tactfully arrive. Year-only never does (§12 G3). */
29
- export type WindowPrecision = "day" | "month";
30
+ /** The precisions that can tactfully arrive. Year-only never does (§12 G3): a
31
+ * year names no day it could mean, so it has no window at all. */
32
+ export type WindowPrecision = "day" | "month" | "range";
30
33
 
31
34
  export type Phase = "pending" | "arrived" | "passed";
32
35
 
33
36
  export interface Window {
34
- /** `d:2026-08-25` or `m:2026-08`. The date is IN the key, on purpose (G9). */
37
+ /** `d:2026-08-25`, `m:2026-08` or `r:2026-10-20..2026-10-31`. The date is IN
38
+ * the key, on purpose (G9) — and ONLY the date: a month's stagger (below) is
39
+ * never part of it, so a clock repair still cannot re-arm a spent window. */
35
40
  readonly key: string;
36
41
  /** The event date exactly as stated — never widened, never narrowed. */
37
42
  readonly eventDate: string;
38
43
  readonly precision: WindowPrecision;
39
44
  /** First calendar day the window is open. */
40
45
  readonly opensOn: string;
41
- /** The day the ramp peaks: the date itself, or the FIRST of a stated month. */
46
+ /** The day the ramp reaches full intensity: the date itself, the first day of
47
+ * a range, or a month's first day plus its stagger (`MONTH_STAGGER_DAYS`). */
42
48
  readonly peakOn: string;
49
+ /** The last day the ramp stays at full intensity: `peakOn` for a day and a
50
+ * month, a range's LAST day — a range means all of itself. */
51
+ readonly peakUntil: string;
52
+ /** The first and last day the stated date covers — the span a person named,
53
+ * lead and grace excluded. After `lastDay` is "after" (tune question b). */
54
+ readonly firstDay: string;
55
+ readonly lastDay: string;
43
56
  /** Last calendar day the window is open (grace included). */
44
57
  readonly closesOn: string;
45
58
  }
46
59
 
47
- const DAY_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
48
- const MONTH_RE = /^(\d{4})-(\d{2})$/;
49
- const YEAR_RE = /^\d{4}$/;
50
-
51
60
  /**
52
61
  * The calendar arithmetic is `core/time.ts`'s (2026-09-25, docs/time.md rule 1).
53
62
  * It used to live here on the UTC getters — correct, since a stated day is a
@@ -59,65 +68,99 @@ export { addDays, daysBetween, monthBounds };
59
68
  /**
60
69
  * The precision a date STATES. Null means "not a date this module understands",
61
70
  * which the deriver reports as `malformed-date` — a refusal with a name, never a
62
- * silent skip (scar §2.4).
71
+ * silent skip (scar §2.4). EXACT: text that only reads once trimmed is not the
72
+ * date as stated.
63
73
  */
64
74
  export function precisionOf(date: string): DatePrecision | null {
65
- if (DAY_RE.test(date)) return isDay(date) ? "day" : null;
66
- const m = MONTH_RE.exec(date);
67
- if (m !== null) {
68
- const mo = Number(m[2]);
69
- return mo >= 1 && mo <= 12 ? "month" : null;
70
- }
71
- return YEAR_RE.test(date) ? "year" : null;
75
+ const c = parseCalendarDate(date);
76
+ return c === null || c.text !== date ? null : c.precision;
72
77
  }
73
78
 
79
+ const TAG: Readonly<Record<WindowPrecision, string>> = { day: "d:", month: "m:", range: "r:" };
80
+
74
81
  export function windowKey(eventDate: string, precision: WindowPrecision): string {
75
- return `${precision === "day" ? "d" : "m"}:${eventDate}`;
82
+ return `${TAG[precision]}${eventDate}`;
76
83
  }
77
84
 
78
85
  /** The inverse. Null for a key this module did not mint — refused, never guessed. */
79
86
  export function parseWindowKey(key: string): { eventDate: string; precision: WindowPrecision } | null {
80
87
  const tag = key.slice(0, 2);
81
88
  const date = key.slice(2);
82
- const want: WindowPrecision | null = tag === "d:" ? "day" : tag === "m:" ? "month" : null;
89
+ const want: WindowPrecision | null =
90
+ tag === "d:" ? "day" : tag === "m:" ? "month" : tag === "r:" ? "range" : null;
83
91
  if (want === null) return null;
84
92
  return precisionOf(date) === want ? { eventDate: date, precision: want } : null;
85
93
  }
86
94
 
95
+ /**
96
+ * Tune question (a) from v1's July gate (bansai `eval/replay/GATES.md` finding
97
+ * 3): STAGGER MONTH WARMTH. Every month-dated item used to peak on the 1st, so a
98
+ * month-heavy store spent its whole prospective pressure on the first boundaries
99
+ * of the month. A STABLE per-memory offset of `0..MONTH_STAGGER_DAYS - 1` days
100
+ * spreads the peaks across the early month instead. Stable, so a memory peaks on
101
+ * the same day every time it is asked; derived from its id and nothing else, so
102
+ * it is not a stored property either (§12 G2).
103
+ */
104
+ export function staggerDays(salt: string, t: ProspectiveTunables): number {
105
+ const n = Math.max(0, Math.floor(t.MONTH_STAGGER_DAYS));
106
+ if (n <= 1 || salt.length === 0) return 0;
107
+ // FNV-1a, 32-bit: a fixed spread, not a secret.
108
+ let h = 0x811c9dc5;
109
+ for (let i = 0; i < salt.length; i++) {
110
+ h ^= salt.charCodeAt(i);
111
+ h = Math.imul(h, 0x01000193) >>> 0;
112
+ }
113
+ return h % n;
114
+ }
115
+
87
116
  /**
88
117
  * The window a stated date opens. Year precision returns null on purpose — it is
89
118
  * excluded structurally, not scored down (§12 G3).
90
119
  *
91
- * A day window peaks on the day. A MONTH window peaks on the FIRST of the month
92
- * and decays across it, because that is what a stated month means; rounding it to
93
- * a day would invent a precision the author never claimed.
120
+ * A DAY window peaks on the day. A MONTH window peaks early in the month (the
121
+ * 1st plus its stagger) and decays across it, because that is what a stated month
122
+ * means; rounding it to a day would invent a precision the author never claimed.
123
+ * A RANGE (`2026-10-20..2026-10-31`, added 2026-09-26) is the author saying
124
+ * exactly which days — "late October" — so it is at full intensity for the whole
125
+ * span and decays only through grace.
126
+ *
127
+ * `salt` is the memory id, read only for a month's stagger. Absent: no stagger.
94
128
  */
95
129
  export function windowFor(
96
130
  eventDate: string,
97
131
  precision: DatePrecision,
98
132
  t: ProspectiveTunables,
133
+ salt = "",
99
134
  ): Window | null {
100
135
  if (precision === "year") return null;
101
- if (precision === "day") {
102
- if (!isDay(eventDate)) return null;
136
+ const c = parseCalendarDate(eventDate);
137
+ if (c === null || c.text !== eventDate || c.precision !== precision) return null;
138
+ const opensOn = addDays(c.first, -t.LEAD_DAYS);
139
+ const closesOn = addDays(c.last, t.GRACE_DAYS);
140
+ if (precision === "month") {
141
+ const peakOn = addDays(c.first, staggerDays(salt, t));
103
142
  return {
104
- key: windowKey(eventDate, "day"),
143
+ key: windowKey(eventDate, "month"),
105
144
  eventDate,
106
- precision: "day",
107
- opensOn: addDays(eventDate, -t.LEAD_DAYS),
108
- peakOn: eventDate,
109
- closesOn: addDays(eventDate, t.GRACE_DAYS),
145
+ precision: "month",
146
+ opensOn,
147
+ peakOn,
148
+ peakUntil: peakOn,
149
+ firstDay: c.first,
150
+ lastDay: c.last,
151
+ closesOn,
110
152
  };
111
153
  }
112
- const bounds = monthBounds(eventDate);
113
- if (bounds === null) return null;
114
154
  return {
115
- key: windowKey(eventDate, "month"),
155
+ key: windowKey(eventDate, precision),
116
156
  eventDate,
117
- precision: "month",
118
- opensOn: addDays(bounds.first, -t.LEAD_DAYS),
119
- peakOn: bounds.first,
120
- closesOn: addDays(bounds.last, t.GRACE_DAYS),
157
+ precision,
158
+ opensOn,
159
+ peakOn: c.first,
160
+ peakUntil: c.last,
161
+ firstDay: c.first,
162
+ lastDay: c.last,
163
+ closesOn,
121
164
  };
122
165
  }
123
166
 
@@ -131,19 +174,34 @@ export function phaseOf(w: Window, at: string): Phase {
131
174
  * How loudly the window is arriving, 0..1 — the RAMP, not a decision. It scales a
132
175
  * cue's weight into the ordinary competition; nothing here admits anything.
133
176
  *
134
- * Rises from `RAMP_OPEN` on the opening day to 1 at the peak, then falls to
135
- * `RAMP_CLOSE` on the last grace day. For a month that decline spans the whole
136
- * month plus grace, which is precisely "a stated month means early month more
137
- * than the 29th" expressed as arithmetic rather than as a rounded date.
177
+ * Rises from `RAMP_OPEN` on the opening day to 1 at the peak, holds 1 through
178
+ * `peakUntil` (a range's whole span; one day otherwise), then falls to
179
+ * `RAMP_CLOSE` on the last grace day. For a month that decline spans the rest of
180
+ * the month plus grace, which is precisely "a stated month means early month
181
+ * more than the 29th" expressed as arithmetic rather than as a rounded date.
138
182
  */
139
183
  export function rampAt(w: Window, at: string, t: ProspectiveTunables): number {
140
184
  if (phaseOf(w, at) !== "arrived") return 0;
141
- const toPeak = daysBetween(w.opensOn, w.peakOn);
142
185
  if (at <= w.peakOn) {
186
+ const toPeak = daysBetween(w.opensOn, w.peakOn);
143
187
  if (toPeak <= 0) return 1;
144
188
  return t.RAMP_OPEN + (1 - t.RAMP_OPEN) * (daysBetween(w.opensOn, at) / toPeak);
145
189
  }
146
- const tail = daysBetween(w.peakOn, w.closesOn);
190
+ if (at <= w.peakUntil) return 1;
191
+ const tail = daysBetween(w.peakUntil, w.closesOn);
147
192
  if (tail <= 0) return 1;
148
- return 1 - (1 - t.RAMP_CLOSE) * (daysBetween(w.peakOn, at) / tail);
193
+ return 1 - (1 - t.RAMP_CLOSE) * (daysBetween(w.peakUntil, at) / tail);
194
+ }
195
+
196
+ /**
197
+ * Tune question (d): IMMINENCE, used only to break a tie. Two numbers, smaller
198
+ * first: days until the stated span begins (0 once it has), then how many days
199
+ * the span covers — so "today" `[0, 1]` outranks "sometime this month" `[0, 30]`
200
+ * at equal salience. That is the owner's May-1 rating in v1's gate: the garden
201
+ * plots happening TODAY lost the wake slot to a month-vague showcase on a
202
+ * 0.7 = 0.7 tie.
203
+ */
204
+ export function imminence(w: Window, at: string): readonly [number, number] {
205
+ const until = at >= w.firstDay ? 0 : daysBetween(at, w.firstDay);
206
+ return [until, daysBetween(w.firstDay, w.lastDay) + 1];
149
207
  }
@@ -249,6 +249,34 @@ credit at the boundary; reinforcement deltas handed to `physics/`.
249
249
  by the next turn stamps the newer turn number, so a cue can be labelled one turn later
250
250
  than the text it was computed from. Cheap to detect (the hits are a turn stale), not
251
251
  worth a lock.
252
+ 18. **[M]** **Mood-matching modulates; it never admits** (emotion part A, owner decision
253
+ 2026-09-25/26 — working default; `mood.ts`). A person's CURRENT feeling is only what
254
+ was RECORDED for them in the last `MOOD_WINDOW_HOURS = 3` of the store's clock at
255
+ `MOOD_MIN_STRENGTH = 0.3` or more — no classifier reads the turn. A candidate that
256
+ carried a feeling sharing a core with someone's mood gets `MOOD_SAME_WEIGHT (0.3) ×`
257
+ that feeling's SOFTENED strength added to its `sal` when the feeling was that same
258
+ person's, `MOOD_CROSS_WEIGHT (0.1) ×` when it was the other's; a blend counts under
259
+ both its cores; a feeling recorded inside the window is the mood, never a match. The
260
+ lift rides `sal` ONLY: it is computed for cued candidates only, it never enters
261
+ `activation` (so it cannot change the candidate set), hard gate (a) and the absolute
262
+ floor (b) are both evaluated before `sal` is read, and in the absolute regimes the
263
+ admission bar ignores `sal`. What `sal` still decides in EVERY regime is the order
264
+ of the loud pool (`SAL_SORT_WEIGHT`): among memories already admitted loud, a
265
+ mood-lifted one can take a surfaced slot another would have had, pushing that one
266
+ to a footnote. Tests: `emotion.test.ts` › "mood-matching never admits an uncued
267
+ memory". The decision record carries `moodMatched` — admitted memories the mood
268
+ lifted, a count, never which feeling. Adding that field moves the surface set (G15):
269
+ the parallel run it protected ended 2026-09-21, and a durable count is the only way
270
+ the mechanism can be seen firing.
271
+ **The tension with G11, named.** §3 keeps v1's rule that the affect CUE is first-person
272
+ only, "guarding against mood-congruent overgeneralization" — and this is mood-congruent
273
+ recall, on purpose. The guard it keeps is structural rather than a subject rule: it
274
+ cannot reach a memory the conversation did not, it lifts by at most 0.3 of salience,
275
+ the other person's mood lifts a third as much, and a match softens with age. The turn
276
+ gate itself (G10: the emotional DIMENSION counts only when the turn is felt in the first
277
+ person) is unchanged; when it opens, the dimension now reads as the memory's emotional
278
+ INTENSITY (physics §5.10), so a feeling held in the `feelings` table is not read as
279
+ unfelt. The affect flag's "charged" test reads the same intensity.
252
280
 
253
281
  ## 6. Scars honored
254
282
 
@@ -519,3 +519,42 @@ handle whose open lost the lock, so the identity is read per activation.
519
519
  stay as calibrated on the lexical channel; nothing in the decision record's hashed field
520
520
  set moved (`ActivationResult` is not the decision record).
521
521
 
522
+
523
+ ## 17. Mood-matching, and emotion reaching the turn gate — 2026-09-26 (emotion part A)
524
+
525
+ Owner decision 4 (2026-09-25/26): when a person's current feeling is known, memories that
526
+ carried a matching feeling for that same person come up more easily; the other person's
527
+ matching feeling gives a smaller lift. CONTRACT guarantee 18 states the rule; this is how
528
+ it was built and what was decided along the way.
529
+
530
+ - **Where it folds in.** Beside `gatedSal`, on the candidate's `sal` — the number the gate
531
+ reads only after hard gate (a) (uncued is dark) and hard gate (b) (the absolute floor).
532
+ `modulate` lowers the RELATIVE bar by `SAL_BAR_WEIGHT × 2 × lift`, so a fresh same-person
533
+ match at strength 0.9 (lift 0.27) faces a bar ~27% lower; the cross-link at 0.1 moves it
534
+ ~9%; the same match a month later (softened to ~0.22 of its strength) ~6%. In the two
535
+ absolute regimes nothing moves. `activation` is never touched, so the candidate set is
536
+ the same with and without a mood — `emotion.test.ts` builds the same turn with the mood
537
+ switched off and compares every activation.
538
+ - **"Current" = recorded in the last 3 hours** of the STORE's clock (the clock `created_at`
539
+ was stamped with; `Recall.now` is the latency clock and is not used), at strength 0.3 or
540
+ more. Not "this session": feelings carry no session id and the table is not to change
541
+ in this part, and a session that runs past three hours has usually moved on from how it
542
+ started. One indexed query per turn; with no mood, nothing else is read.
543
+ - **A feeling inside the window is the mood, not a match.** Otherwise the note written five
544
+ minutes ago matches its own feeling — and session dedup would not catch it, because it
545
+ was never surfaced.
546
+ - **Blends match as both cores** (`coresOfFeeling`): tender (sad + happy) matches a sad mood
547
+ and a happy one.
548
+ - **Per candidate: one batched read** (`Store.feelingsOn`), only for CUED candidates, only
549
+ when there is a mood, inside the latency budget.
550
+ - **`moodMatched` joined the durable decision record** — how many admitted memories the mood
551
+ had lifted. It moves the surface set (G15); the parallel run whose ratings that protected
552
+ ended 2026-09-21, and the mechanisms views need a durable count to show the mechanism
553
+ firing.
554
+ - **G10 and the affect flag read intensity.** When the turn carries first-person feeling,
555
+ `gatedSal` reads the emotional dimension as the memory's intensity (the stronger of its
556
+ score and its recorded feelings); otherwise 0, as before. The affect flag's "charged"
557
+ test uses the same intensity against `AFFECT_MIN_EMOTION = 0.7`.
558
+
559
+ **Unmeasured.** Every mood tunable is a working default with a reason, not a measurement;
560
+ the recall bench has no feelings in it yet.
@@ -38,13 +38,15 @@
38
38
  * fail.
39
39
  */
40
40
  import type { Kind, MemoryPhysics } from "../types.js";
41
- import { sal, strength } from "../physics/index.js";
41
+ import { emotionalIntensity, sal, strength } from "../physics/index.js";
42
42
  import type { Hit, ProseDoc, Store } from "../store/index.js";
43
43
  import { confidentialByMeta, rowToPhysics, tokenize } from "../store/index.js";
44
44
  import { buildCues, informativeness } from "./cues.js";
45
45
  import type { Cue } from "./cues.js";
46
46
  import type { RecallTunables, SemanticPath, SemanticTuning } from "./tunables.js";
47
47
  import { semanticTuning } from "./tunables.js";
48
+ import { NO_MOOD, hasMood, moodLift } from "./mood.js";
49
+ import type { Mood } from "./mood.js";
48
50
 
49
51
  export interface Candidate {
50
52
  readonly id: string;
@@ -56,6 +58,9 @@ export interface Candidate {
56
58
  * turn itself carries first-person feeling (§9 G10/G11 — emotion is
57
59
  * turn-gated, and that gate is the safety property). */
58
60
  readonly sal: number;
61
+ /** The part of `sal` that the current MOOD added (recall G18): 0 unless this
62
+ * candidate is cued and carried a feeling matching someone's mood. */
63
+ readonly mood: number;
59
64
  readonly cue: number;
60
65
  /** The portion of `cue` that came from a temporal window (already included in
61
66
  * `cue`; carried separately only so the ceiling below can be decided). */
@@ -104,6 +109,8 @@ export interface ActivationInput {
104
109
  readonly day: number;
105
110
  /** Whether the turn stated a FIRST-PERSON feeling. Gates emotional salience. */
106
111
  readonly selfFelt: boolean;
112
+ /** How each person feels now (`mood.ts#currentMood`). Absent: no mood. */
113
+ readonly mood?: Mood | undefined;
107
114
  readonly maxCandidates: number;
108
115
  /** Live memory count, for informativeness and the cold-start regime. */
109
116
  readonly storeSize: number;
@@ -207,9 +214,15 @@ export function isConfidential(doc: ProseDoc): boolean {
207
214
  return confidentialByMeta(doc.meta);
208
215
  }
209
216
 
210
- /** Salience with the emotional dimension gated on the turn (§9 G10). */
217
+ /**
218
+ * Salience with the emotional dimension gated on the turn (§9 G10). When the
219
+ * turn carries first-person feeling, the dimension reads as the memory's full
220
+ * emotional INTENSITY — the stronger of its numeric score and its recorded
221
+ * feelings (physics §5.10) — so a memory that holds its feeling in the
222
+ * `feelings` table is not read as unfelt. Otherwise it is 0, as before.
223
+ */
211
224
  export function gatedSal(p: MemoryPhysics, selfFelt: boolean): number {
212
- if (selfFelt) return sal(p.salience);
225
+ if (selfFelt) return sal({ ...p.salience, emotional: emotionalIntensity(p) });
213
226
  return sal({ ...p.salience, emotional: 0 });
214
227
  }
215
228
 
@@ -492,9 +505,20 @@ export function activate(
492
505
  }
493
506
  scored.sort((a, b) => b.activation - a.activation || (a.id < b.id ? -1 : 1));
494
507
 
508
+ const kept = scored.slice(0, input.maxCandidates);
509
+ // MOOD (recall G18): one batched read, and only when someone has a mood — and only
510
+ // for CUED candidates. An uncued candidate is dark at hard gate (a) before
511
+ // salience is ever read, so it is not even asked (the guarantee is the gate's;
512
+ // this just declines to do work the gate would throw away).
513
+ const mood = input.mood ?? NO_MOOD;
514
+ const feelingsById = hasMood(mood)
515
+ ? store.feelingsOn(kept.filter((c) => c.cue + c.semantic > 0).map((c) => c.id))
516
+ : new Map<string, never[]>();
495
517
  const candidates: Candidate[] = [];
496
- for (const c of scored.slice(0, input.maxCandidates)) {
518
+ for (const c of kept) {
497
519
  const { id, physics, cue, temporal, semantic, arrival, hops, activation } = c;
520
+ const lift = cue + semantic > 0 ? moodLift(feelingsById.get(id), mood, input.day, t) : 0;
521
+ const gated = gatedSal(physics, input.selfFelt);
498
522
  // `readProse` is `read().doc`, so taking the whole read costs nothing and
499
523
  // brings the confidentiality flag with it instead of re-deriving it.
500
524
  const stored = store.read(id);
@@ -505,7 +529,10 @@ export function activate(
505
529
  doc,
506
530
  physics,
507
531
  strength: c.strength,
508
- sal: gatedSal(physics, input.selfFelt),
532
+ // The mood lift rides salience only: it can lower this candidate's
533
+ // relative bar, never raise its activation or admit it uncued.
534
+ sal: Math.min(1, gated + lift),
535
+ mood: Math.min(1, gated + lift) - gated,
509
536
  cue,
510
537
  temporal,
511
538
  semantic,
@@ -27,6 +27,7 @@
27
27
  * and the per-turn decision record is the richest replay comparison surface
28
28
  * (contract §5 G14, scar §2.4).
29
29
  */
30
+ import { emotionalIntensity } from "../physics/index.js";
30
31
  import { tokenize } from "../store/index.js";
31
32
  import type { Candidate } from "./activate.js";
32
33
  import { MIN_RARITY_STORE, informativeness } from "./cues.js";
@@ -82,6 +83,8 @@ export interface CandidateVerdict {
82
83
  readonly hops: number;
83
84
  readonly cueFraction: number;
84
85
  readonly sal: number;
86
+ /** The part of `sal` the current mood added (recall G18). Present only when > 0. */
87
+ readonly mood?: number;
85
88
  readonly strength: number;
86
89
  /** False ⇒ this memory may never be credited from this turn (§9 G5). */
87
90
  readonly trains: boolean;
@@ -304,6 +307,7 @@ export function gate(input: GateInput, t: RecallTunables): GateResult {
304
307
  hops: c.hops,
305
308
  cueFraction: c.cueFraction,
306
309
  sal: c.sal,
310
+ ...(c.mood > 0 ? { mood: c.mood } : {}),
307
311
  strength: c.strength,
308
312
  trains: c.trains,
309
313
  ...(blocked !== undefined ? { loudBlockedBy: blocked } : {}),
@@ -332,7 +336,9 @@ export function gate(input: GateInput, t: RecallTunables): GateResult {
332
336
  // what THIS TURN touches, and it names nothing — no id, no body, no feeling.
333
337
  // A memory already sitting in this session's context still means the turn is
334
338
  // near something that carries weight.
335
- if (c.physics.salience.emotional >= t.AFFECT_MIN_EMOTION) charged = true;
339
+ // Charged by the memory's emotional INTENSITY — its numeric score or its
340
+ // strongest recorded feeling, whichever is stronger (physics §5.10).
341
+ if (emotionalIntensity(c.physics) >= t.AFFECT_MIN_EMOTION) charged = true;
336
342
  // Boundary gate 2 — session dedup. It is already in this session's context.
337
343
  if (input.state.surfaced[c.id] !== undefined) {
338
344
  record(c, "dedup-suppressed");
@@ -35,6 +35,7 @@ import type { Candidate } from "./activate.js";
35
35
  import { detectAffect, stripBoilerplate } from "./cues.js";
36
36
  import { floorUnit, gate } from "./gate.js";
37
37
  import type { Background, CandidateVerdict, Verdict } from "./gate.js";
38
+ import { currentMood } from "./mood.js";
38
39
  import { loadGateState, saveGateState } from "./session.js";
39
40
  import type { GateState, SemanticSource } from "./session.js";
40
41
  import { render } from "./render.js";
@@ -44,6 +45,7 @@ import type { RecallTunables } from "./tunables.js";
44
45
 
45
46
  export * from "./cues.js";
46
47
  export * from "./gate.js";
48
+ export * from "./mood.js";
47
49
  export * from "./render.js";
48
50
  export * from "./session.js";
49
51
  export * from "./tunables.js";
@@ -177,6 +179,13 @@ export interface RecallDecision {
177
179
  readonly footnotes: string[];
178
180
  readonly affectFlag: boolean;
179
181
  readonly affectReason: string;
182
+ /**
183
+ * How many memories this turn admitted (loud or quiet) that the current mood
184
+ * had lifted (recall G18) — a memory that carried a feeling matching how someone
185
+ * feels now. Counts only; which feeling is never named. 0 on a turn with no
186
+ * mood, and on every quiet turn.
187
+ */
188
+ readonly moodMatched: number;
180
189
  readonly bytes: number;
181
190
  readonly budgetBytes: number;
182
191
  readonly sentinel: string | null;
@@ -323,6 +332,7 @@ export class Recall {
323
332
  footnotes: [],
324
333
  affectFlag: false,
325
334
  affectReason: "no-feeling-in-turn",
335
+ moodMatched: 0,
326
336
  bytes: 0,
327
337
  budgetBytes,
328
338
  sentinel: null,
@@ -347,6 +357,11 @@ export class Recall {
347
357
  ? this.tunables.COLD_START_MAX_CANDIDATES
348
358
  : this.tunables.MAX_CANDIDATES;
349
359
 
360
+ // How each person feels now — only what was RECORDED in the last few hours
361
+ // (recall G18; no classifier). Read on the store's clock, which is the clock the
362
+ // feelings were stamped with.
363
+ const mood = currentMood(this.store, this.store.now(), this.tunables);
364
+
350
365
  const act = activate(
351
366
  this.store,
352
367
  {
@@ -359,6 +374,7 @@ export class Recall {
359
374
  spread: turn.spread,
360
375
  day,
361
376
  selfFelt: affect.selfFelt,
377
+ mood,
362
378
  maxCandidates,
363
379
  storeSize,
364
380
  },
@@ -447,6 +463,9 @@ export class Recall {
447
463
  footnotes: rendered.footnotes,
448
464
  affectFlag: rendered.affectFlag,
449
465
  affectReason: gated.affectReason,
466
+ moodMatched: gated.verdicts.filter(
467
+ (v) => (v.verdict === "surfaced" || v.verdict === "footnoted") && (v.mood ?? 0) > 0,
468
+ ).length,
450
469
  bytes: rendered.bytes,
451
470
  budgetBytes,
452
471
  sentinel: rendered.sentinel,
@@ -0,0 +1,106 @@
1
+ /**
2
+ * MOOD-MATCHING — recall G18 (emotion part A, owner decision 4, 2026-09-26).
3
+ *
4
+ * When a person's current feeling is known, memories that carried a matching
5
+ * feeling FOR THAT SAME PERSON come up more easily; a matching feeling of the
6
+ * OTHER person gives a smaller lift. The brain analog is mood-congruent recall.
7
+ *
8
+ * **"Current" is only what was recorded.** There is no classifier: a person's
9
+ * mood is the cores of the feelings recorded for them in the last
10
+ * `MOOD_WINDOW_HOURS` of the store's clock, at `MOOD_MIN_STRENGTH` or above. A
11
+ * turn nobody recorded a feeling near has no mood, and this whole module costs
12
+ * one query that returns nothing. That query (`Store.feelingsSince`) has no
13
+ * index on `created_at` — adding one is a schema change this part does not make
14
+ * — so it scans the `feelings` table, which is small (a few per memory at most).
15
+ *
16
+ * **It is a modulation, never an admission.** The lift is added to the
17
+ * candidate's `sal` — the number the gate reads AFTER hard gate (a) (an uncued
18
+ * memory is dark before salience is evaluated) and AFTER hard gate (b) (the
19
+ * absolute floor, checked before any salience adjustment). It never touches
20
+ * `activation`, so it cannot change which memories become candidates, and in
21
+ * the absolute regimes `modulate` ignores `sal` entirely. `activate.ts` does
22
+ * not even compute a mood for an uncued candidate. One place `sal` IS read in
23
+ * every regime: the loud pool's order (`gate.ts`, `SAL_SORT_WEIGHT`), so among
24
+ * memories already admitted loud, a lifted one can take a surfaced slot.
25
+ *
26
+ * **A blend counts under both of its cores** (`coresOfFeeling`): a tender
27
+ * memory matches a sad mood and a happy one.
28
+ *
29
+ * **Past, not present.** A feeling recorded INSIDE the window is part of the
30
+ * mood, not a memory that matches it — otherwise the note written five minutes
31
+ * ago would match its own feeling, and session dedup would not stop it (it was
32
+ * never surfaced). Matching reads the feeling SOFTENED by its age
33
+ * (`physics.softenedFeeling`): an old match lifts less than a fresh one.
34
+ */
35
+ import { coresOfFeeling } from "../feelings-wheel.js";
36
+ import type { CoreEmotion } from "../feelings-wheel.js";
37
+ import { softenedFeeling } from "../physics/index.js";
38
+ import type { FeelingRow, Store } from "../store/index.js";
39
+ import type { RecallTunables } from "./tunables.js";
40
+
41
+ export interface Mood {
42
+ /** Per person (`whose`), the cores they feel now. Empty map: no mood. */
43
+ readonly byPerson: ReadonlyMap<string, ReadonlySet<CoreEmotion>>;
44
+ /** Feelings recorded at or after this instant are the mood itself, never a match. */
45
+ readonly sinceMs: number;
46
+ }
47
+
48
+ export const NO_MOOD: Mood = { byPerson: new Map(), sinceMs: Number.POSITIVE_INFINITY };
49
+
50
+ const HOUR_MS = 3_600_000;
51
+
52
+ /** How each person feels now, from the feelings recorded in the window. */
53
+ export function currentMood(
54
+ store: Pick<Store, "feelingsSince">,
55
+ nowMs: number,
56
+ t: Pick<RecallTunables, "MOOD_WINDOW_HOURS" | "MOOD_MIN_STRENGTH">,
57
+ ): Mood {
58
+ const sinceMs = nowMs - t.MOOD_WINDOW_HOURS * HOUR_MS;
59
+ const byPerson = new Map<string, Set<CoreEmotion>>();
60
+ let rows: FeelingRow[];
61
+ try {
62
+ rows = store.feelingsSince(sinceMs);
63
+ } catch {
64
+ // A store without the table cannot have a mood; recall goes on without one.
65
+ return NO_MOOD;
66
+ }
67
+ for (const r of rows) {
68
+ if (!(r.strength >= t.MOOD_MIN_STRENGTH)) continue;
69
+ const set = byPerson.get(r.whose) ?? new Set<CoreEmotion>();
70
+ for (const c of coresOfFeeling(r.core, r.emotion)) set.add(c);
71
+ if (set.size > 0) byPerson.set(r.whose, set);
72
+ }
73
+ return { byPerson, sinceMs };
74
+ }
75
+
76
+ /** True when there is anything to match against. */
77
+ export function hasMood(mood: Mood): boolean {
78
+ return mood.byPerson.size > 0;
79
+ }
80
+
81
+ /**
82
+ * The salience lift ONE memory gets from the current mood: the largest of
83
+ * `weight x softened strength` over its past feelings that share a core with
84
+ * someone's mood — `MOOD_SAME_WEIGHT` when the feeling was that person's own,
85
+ * `MOOD_CROSS_WEIGHT` when it was the other's. 0 when nothing matches.
86
+ */
87
+ export function moodLift(
88
+ feelings: readonly (FeelingRow & { birth_day: number })[] | undefined,
89
+ mood: Mood,
90
+ day: number,
91
+ t: Pick<RecallTunables, "MOOD_SAME_WEIGHT" | "MOOD_CROSS_WEIGHT">,
92
+ ): number {
93
+ if (feelings === undefined || feelings.length === 0 || !hasMood(mood)) return 0;
94
+ let best = 0;
95
+ for (const f of feelings) {
96
+ if (f.created_at >= mood.sinceMs) continue; // the mood itself, not a memory of one
97
+ const cores = coresOfFeeling(f.core, f.emotion);
98
+ const felt = softenedFeeling(f.strength, day - f.birth_day);
99
+ for (const [person, now] of mood.byPerson) {
100
+ if (!cores.some((c) => now.has(c))) continue;
101
+ const w = f.whose === person ? t.MOOD_SAME_WEIGHT : t.MOOD_CROSS_WEIGHT;
102
+ if (w * felt > best) best = w * felt;
103
+ }
104
+ }
105
+ return best;
106
+ }
@@ -174,6 +174,20 @@ export interface RecallTunables {
174
174
  * A high-salience wound must not light up every turn. [v1: 2] CAL. */
175
175
  AFFECT_REFRACTORY_TURNS: number;
176
176
 
177
+ // ── mood-matching (recall G18, emotion part A — WORKING DEFAULTS) ─────────────
178
+ /** How far back a recorded feeling still counts as how someone feels NOW, in
179
+ * hours of the store's clock. No classifier reads the turn: the mood is only
180
+ * what was recorded. CAL. */
181
+ MOOD_WINDOW_HOURS: number;
182
+ /** A recorded feeling weaker than this does not set a mood. CAL. */
183
+ MOOD_MIN_STRENGTH: number;
184
+ /** Salience a memory gains when it carried the SAME person's matching feeling,
185
+ * times that feeling's softened strength. Modulates the relative bar only —
186
+ * never activation, never an uncued memory. CAL. */
187
+ MOOD_SAME_WEIGHT: number;
188
+ /** The same for the OTHER person's matching feeling: the light cross-link. CAL. */
189
+ MOOD_CROSS_WEIGHT: number;
190
+
177
191
  // ── render ───────────────────────────────────────────────────────────────
178
192
  /** Composed byte budget for the WHOLE injection, sentinel included. The host
179
193
  * owns the real ceiling (scar §2.18) and passes it in; this is the default. CAL. */
@@ -374,6 +388,18 @@ export const TUNABLES: RecallTunables = {
374
388
  AFFECT_MIN_EMOTION: 0.7,
375
389
  AFFECT_REFRACTORY_TURNS: 2,
376
390
 
391
+ // Emotion part A (2026-09-26). The window is "this sitting": long enough to
392
+ // span a working session's feelings, short enough that yesterday's mood is
393
+ // not today's. The weights are sized against SAL_BAR_WEIGHT = 0.5: a fresh
394
+ // same-person match at strength 0.9 adds 0.27 to salience, which lowers that
395
+ // candidate's relative bar by ~27%; the cross-link at 0.1 moves it ~9%. A
396
+ // match a month old has softened to ~0.2 of its strength (S_FEELING = 20)
397
+ // and moves the bar by ~6%. Unmeasured — recorded as a working default.
398
+ MOOD_WINDOW_HOURS: 3,
399
+ MOOD_MIN_STRENGTH: 0.3,
400
+ MOOD_SAME_WEIGHT: 0.3,
401
+ MOOD_CROSS_WEIGHT: 0.1,
402
+
377
403
  BUDGET_BYTES: 2048,
378
404
  GIST_BYTES: 240,
379
405
  FOOTNOTE_TITLE_BYTES: 150,
@@ -52,6 +52,7 @@ export {
52
52
  submitProposal,
53
53
  } from "./proposals.js";
54
54
  export type {
55
+ DateIntent,
55
56
  Feeling,
56
57
  GateFn,
57
58
  GateInput,