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.
- package/CHANGELOG.md +72 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/NOTES.md +12 -0
- package/src/adapters/claude-code/bin/hook.ts +85 -22
- package/src/adapters/claude-code/config.ts +7 -0
- package/src/adapters/claude-code/doctor.ts +20 -4
- package/src/adapters/claude-code/hooks.ts +157 -6
- package/src/adapters/claude-code/index.ts +3 -0
- package/src/adapters/cli/commands.ts +11 -0
- package/src/adapters/cli/mechanisms.ts +46 -21
- package/src/adapters/dashboard/registries.ts +4 -0
- package/src/adapters/dashboard/web/README.md +19 -11
- package/src/adapters/dashboard/web/flow.ts +2 -0
- package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -5
- package/src/adapters/dashboard/web/mechanisms/prospective/index.js +6 -3
- package/src/adapters/dashboard/web/narrate.ts +8 -0
- package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
- package/src/adapters/dashboard/web/pages/self/index.js +55 -16
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
- package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +94 -99
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
- package/src/adapters/dashboard/web/pages/self/self.css +119 -59
- package/src/adapters/dashboard/web/pages/self/state.js +23 -0
- package/src/adapters/dashboard/web/pages/self/tips.js +50 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +9 -0
- package/src/adapters/dashboard/web/views/mechanisms.ts +85 -14
- package/src/adapters/dashboard/web/views/memory.ts +15 -1
- package/src/adapters/dashboard/web/views/mind.ts +130 -6
- package/src/adapters/feelings-line.ts +74 -0
- package/src/adapters/fired.ts +78 -18
- package/src/adapters/mcp/CONTRACT.md +8 -0
- package/src/adapters/mcp/NOTES.md +45 -0
- package/src/adapters/mcp/server.ts +165 -6
- package/src/adapters/mcp/tools.ts +51 -4
- package/src/core/bridge.ts +21 -16
- package/src/core/counterpart.ts +309 -6
- package/src/core/encode/CONTRACT.md +7 -1
- package/src/core/feelings-wheel.ts +171 -13
- package/src/core/mint.ts +9 -0
- package/src/core/physics/CONTRACT.md +43 -0
- package/src/core/physics/NOTES.md +94 -0
- package/src/core/physics/index.ts +98 -6
- package/src/core/prospective/CONTRACT.md +35 -6
- package/src/core/prospective/INTERFACE-GAPS.md +10 -5
- package/src/core/prospective/NOTES.md +175 -4
- package/src/core/prospective/derive.ts +32 -3
- package/src/core/prospective/index.ts +362 -39
- package/src/core/prospective/tunables.ts +18 -1
- package/src/core/prospective/windows.ts +104 -46
- package/src/core/recall/CONTRACT.md +28 -0
- package/src/core/recall/NOTES.md +39 -0
- package/src/core/recall/activate.ts +32 -5
- package/src/core/recall/gate.ts +7 -1
- package/src/core/recall/index.ts +19 -0
- package/src/core/recall/mood.ts +106 -0
- package/src/core/recall/tunables.ts +26 -0
- package/src/core/remember/index.ts +1 -0
- package/src/core/remember/proposals.ts +86 -3
- package/src/core/self/identity.ts +20 -1
- package/src/core/store/CONTRACT.md +9 -2
- package/src/core/store/NOTES.md +20 -0
- package/src/core/store/feelings.ts +23 -6
- package/src/core/store/index.ts +107 -10
- package/src/core/store/operational.ts +15 -1
- package/src/core/types.ts +9 -0
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import type { Kind, Salience } from "../types.js";
|
|
23
23
|
import { hashText } from "../store/prose.js";
|
|
24
|
+
import { parseCalendarDate } from "../time.js";
|
|
24
25
|
import { randomBytes } from "node:crypto";
|
|
25
26
|
|
|
26
27
|
// TYPE-ONLY, and the only edge this module has to `encode/`. The gate itself
|
|
@@ -61,10 +62,30 @@ export interface ProposalDraft {
|
|
|
61
62
|
updates?: string;
|
|
62
63
|
/** An open loop is an ordinary memory with a flag, not a special structure (§4). */
|
|
63
64
|
unresolved?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The calendar date this memory is ABOUT, when it is about a future one
|
|
67
|
+
* (schema v7's `event_date`; 2026-09-26): a day `2026-10-15`, a month
|
|
68
|
+
* `2026-10`, a year `2026`, or a range `2026-10-20..2026-10-31`. An explicit
|
|
69
|
+
* FIELD — the author converts "late October" itself, and nothing here reads
|
|
70
|
+
* prose for a date. Unreadable is malformed, never guessed.
|
|
71
|
+
*/
|
|
72
|
+
eventDate?: string;
|
|
73
|
+
/** Plain or quiet (`prospective/` `CUE_MODE_META`). Only meaningful beside an
|
|
74
|
+
* `eventDate`; without one it is dropped and counted. Default quiet. */
|
|
75
|
+
remind?: "plain" | "quiet";
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
export type ProposalSource = "session-end" | "jot";
|
|
67
79
|
|
|
80
|
+
/** What a draft said about its reminder date (`Proposal.dateIntent`). */
|
|
81
|
+
export interface DateIntent {
|
|
82
|
+
/** `set`: a readable date was sent; `cleared`: `eventDate: null` was sent;
|
|
83
|
+
* `absent`: the field was left out. */
|
|
84
|
+
readonly eventDate: "set" | "cleared" | "absent";
|
|
85
|
+
/** The `remind` the author sent, or null when none was (the draft's quiet is a default). */
|
|
86
|
+
readonly remind: "plain" | "quiet" | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
68
89
|
/** What the engine mints. Memory objects only — no operations, by construction. */
|
|
69
90
|
export interface Proposal {
|
|
70
91
|
id: string;
|
|
@@ -79,6 +100,24 @@ export interface Proposal {
|
|
|
79
100
|
aliases: string[];
|
|
80
101
|
updates: UpdatesResolution | null;
|
|
81
102
|
unresolved: boolean;
|
|
103
|
+
/** The reminder date as the author wrote it (already read by `time.ts`), or null. */
|
|
104
|
+
eventDate: string | null;
|
|
105
|
+
/** Plain or quiet — null exactly when `eventDate` is. */
|
|
106
|
+
remind: "plain" | "quiet" | null;
|
|
107
|
+
/**
|
|
108
|
+
* What the author SAID about the date, as opposed to what defaulted — read
|
|
109
|
+
* only when this proposal revises a memory (`updates:`), where a date the
|
|
110
|
+
* author left out is carried over from the one it revises rather than lost
|
|
111
|
+
* (review N7, 2026-09-26; `Counterpart#carryReminder`). Absent on a proposal
|
|
112
|
+
* no author wrote (the sweep), which therefore carries nothing.
|
|
113
|
+
*/
|
|
114
|
+
dateIntent?: DateIntent;
|
|
115
|
+
/**
|
|
116
|
+
* The memory this proposal takes its reminder over from, set by
|
|
117
|
+
* `Counterpart#carryReminder` only (never by an author): written to
|
|
118
|
+
* `meta.reminderFrom` at the minting seam (prospective `DATE_FROM_META`).
|
|
119
|
+
*/
|
|
120
|
+
reminderFrom?: string;
|
|
82
121
|
at: number;
|
|
83
122
|
day: number;
|
|
84
123
|
/** Identity for idempotency: CONTENT, not span text (§4.1 G9). */
|
|
@@ -102,7 +141,11 @@ export type MalformedReason =
|
|
|
102
141
|
| "TITLE_NOT_STRING"
|
|
103
142
|
| "UPDATES_NOT_STRING"
|
|
104
143
|
| "ALIASES_NOT_STRINGS"
|
|
105
|
-
| "FEELING_MALFORMED"
|
|
144
|
+
| "FEELING_MALFORMED"
|
|
145
|
+
/** `eventDate` is not a day, month, year or `a..b` range `time.ts` can read. */
|
|
146
|
+
| "EVENT_DATE_UNREADABLE"
|
|
147
|
+
/** `remind` is not `plain` or `quiet`. */
|
|
148
|
+
| "REMIND_UNKNOWN";
|
|
106
149
|
|
|
107
150
|
const KIND_SET: Record<Kind, true> = {
|
|
108
151
|
self: true,
|
|
@@ -129,10 +172,18 @@ export const DRAFT_FIELDS = [
|
|
|
129
172
|
"aliases",
|
|
130
173
|
"updates",
|
|
131
174
|
"unresolved",
|
|
175
|
+
"eventDate",
|
|
176
|
+
"remind",
|
|
132
177
|
] as const;
|
|
133
178
|
|
|
134
179
|
export type IntakeResult =
|
|
135
|
-
| {
|
|
180
|
+
| {
|
|
181
|
+
ok: true;
|
|
182
|
+
draft: Required<Pick<ProposalDraft, "content">> & ProposalDraft;
|
|
183
|
+
dropped: string[];
|
|
184
|
+
/** What the draft said about its date, before any default (`DateIntent`). */
|
|
185
|
+
dateIntent: DateIntent;
|
|
186
|
+
}
|
|
136
187
|
| { ok: false; reason: MalformedReason; text: string | null; dropped: string[] };
|
|
137
188
|
|
|
138
189
|
/**
|
|
@@ -204,7 +255,29 @@ export function intake(raw: unknown): IntakeResult {
|
|
|
204
255
|
}
|
|
205
256
|
}
|
|
206
257
|
|
|
258
|
+
// THE REMINDER DATE (2026-09-26): read by `time.ts`, the one module that
|
|
259
|
+
// reads dates, and refused when it cannot be read — the same answer
|
|
260
|
+
// `Store#revise` gives (schema v7). Never guessed, never parsed from prose.
|
|
261
|
+
let eventDate: string | undefined;
|
|
262
|
+
if (rec["eventDate"] !== undefined && rec["eventDate"] !== null) {
|
|
263
|
+
const v = rec["eventDate"];
|
|
264
|
+
const read = typeof v === "string" ? parseCalendarDate(v) : null;
|
|
265
|
+
if (read === null) return bad("EVENT_DATE_UNREADABLE");
|
|
266
|
+
eventDate = read.text;
|
|
267
|
+
}
|
|
268
|
+
if (rec["remind"] !== undefined && rec["remind"] !== null) {
|
|
269
|
+
if (rec["remind"] !== "plain" && rec["remind"] !== "quiet") return bad("REMIND_UNKNOWN");
|
|
270
|
+
}
|
|
271
|
+
|
|
207
272
|
const draft: ProposalDraft = { content: rec["content"] as string };
|
|
273
|
+
if (eventDate !== undefined) {
|
|
274
|
+
draft.eventDate = eventDate;
|
|
275
|
+
draft.remind = rec["remind"] === "plain" ? "plain" : "quiet";
|
|
276
|
+
} else if (rec["remind"] !== undefined && rec["remind"] !== null) {
|
|
277
|
+
// Plain or quiet says HOW a date comes back; with no date there is nothing
|
|
278
|
+
// to come back, so it is dropped and counted like any field with nowhere to go.
|
|
279
|
+
dropped.push("remind");
|
|
280
|
+
}
|
|
208
281
|
if (rec["kind"] !== undefined) draft.kind = rec["kind"] as Kind;
|
|
209
282
|
if (typeof rec["title"] === "string") draft.title = rec["title"];
|
|
210
283
|
if (rec["claimed"] !== undefined) draft.claimed = rec["claimed"] as number | null;
|
|
@@ -215,7 +288,14 @@ export function intake(raw: unknown): IntakeResult {
|
|
|
215
288
|
if (rec["aliases"] !== undefined) draft.aliases = rec["aliases"] as string[];
|
|
216
289
|
if (typeof rec["updates"] === "string") draft.updates = rec["updates"];
|
|
217
290
|
draft.unresolved = rec["unresolved"] === true;
|
|
218
|
-
|
|
291
|
+
// What was SAID, before the quiet default above: a revision carries over
|
|
292
|
+
// whatever its author left out (review N7), so "left out" and "said quiet"
|
|
293
|
+
// must stay two different answers. `eventDate: null` is the explicit drop.
|
|
294
|
+
const dateIntent: DateIntent = {
|
|
295
|
+
eventDate: eventDate !== undefined ? "set" : rec["eventDate"] === null ? "cleared" : "absent",
|
|
296
|
+
remind: rec["remind"] === "plain" || rec["remind"] === "quiet" ? rec["remind"] : null,
|
|
297
|
+
};
|
|
298
|
+
return { ok: true, draft: draft as Required<Pick<ProposalDraft, "content">> & ProposalDraft, dropped, dateIntent };
|
|
219
299
|
}
|
|
220
300
|
|
|
221
301
|
// ── the gate seam (INJECTED — see INTERFACE-GAPS.md #2) ──────────────────────
|
|
@@ -527,6 +607,9 @@ export async function submitProposal(
|
|
|
527
607
|
aliases: [...(verdict.aliases ?? draft.aliases ?? [])],
|
|
528
608
|
updates,
|
|
529
609
|
unresolved: draft.unresolved === true,
|
|
610
|
+
eventDate: draft.eventDate ?? null,
|
|
611
|
+
remind: draft.eventDate === undefined ? null : draft.remind ?? "quiet",
|
|
612
|
+
dateIntent: parsed.dateIntent,
|
|
530
613
|
at: buffer.now(),
|
|
531
614
|
day: buffer.day(),
|
|
532
615
|
contentHash,
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* no index for — INTERFACE-GAPS #2) and text arrives at render time through the
|
|
18
18
|
* `Resolve` seam.
|
|
19
19
|
*/
|
|
20
|
+
import { createHash } from "node:crypto";
|
|
20
21
|
import type { Band, Kind, MemoryPhysics } from "../types.js";
|
|
21
22
|
import { strength } from "../physics/index.js";
|
|
22
23
|
import type { ProseDoc, ReadOnlyStore, Store } from "../store/index.js";
|
|
@@ -33,6 +34,15 @@ export interface Ranked {
|
|
|
33
34
|
readonly strength: number;
|
|
34
35
|
readonly protected: boolean;
|
|
35
36
|
readonly bornDay: number;
|
|
37
|
+
/**
|
|
38
|
+
* The last tie-break before the id: a hash of the memory's words, so two
|
|
39
|
+
* memories tied on everything else order the same way in every store that
|
|
40
|
+
* holds them. Ids are random (`store/index.ts#newId`), so an id tie-break is
|
|
41
|
+
* stable within one store but not across two built alike (the demo seed's
|
|
42
|
+
* two runs). A hash, not the text: this stays an ids-and-numbers structure.
|
|
43
|
+
* Absent on a line with no memory behind it (the horizon lane).
|
|
44
|
+
*/
|
|
45
|
+
readonly tieKey?: string;
|
|
36
46
|
/** Threads only: person-scoped debts trim last (behavioral-spec §1 G4). */
|
|
37
47
|
readonly personScoped: boolean;
|
|
38
48
|
/** Lived day this element last rendered in a wake; -1 never. Identity only. */
|
|
@@ -110,6 +120,14 @@ export function scanActive(store: Store, day: number): Scanned[] {
|
|
|
110
120
|
function byStrength(a: Ranked, b: Ranked): number {
|
|
111
121
|
if (b.strength !== a.strength) return b.strength - a.strength;
|
|
112
122
|
if (a.bornDay !== b.bornDay) return a.bornDay - b.bornDay;
|
|
123
|
+
return byContentThenId(a, b);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The final tie-break: the words' hash (`tieKey`), then the id. */
|
|
127
|
+
function byContentThenId(a: Ranked, b: Ranked): number {
|
|
128
|
+
const ka = a.tieKey ?? "";
|
|
129
|
+
const kb = b.tieKey ?? "";
|
|
130
|
+
if (ka !== kb) return ka < kb ? -1 : 1;
|
|
113
131
|
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
114
132
|
}
|
|
115
133
|
|
|
@@ -137,7 +155,7 @@ function byRotation(a: Ranked, b: Ranked): number {
|
|
|
137
155
|
function byThreadAge(a: Ranked, b: Ranked): number {
|
|
138
156
|
if (a.personScoped !== b.personScoped) return a.personScoped ? -1 : 1;
|
|
139
157
|
if (a.bornDay !== b.bornDay) return a.bornDay - b.bornDay;
|
|
140
|
-
return a
|
|
158
|
+
return byContentThenId(a, b);
|
|
141
159
|
}
|
|
142
160
|
|
|
143
161
|
function rank(s: Scanned, lane: LaneName): Ranked {
|
|
@@ -149,6 +167,7 @@ function rank(s: Scanned, lane: LaneName): Ranked {
|
|
|
149
167
|
strength: s.strength,
|
|
150
168
|
protected: s.physics.protected,
|
|
151
169
|
bornDay: s.doc.bornDay,
|
|
170
|
+
tieKey: createHash("sha256").update(s.doc.body).digest("hex"),
|
|
152
171
|
personScoped: s.kind === "person",
|
|
153
172
|
lastRendered: s.lastRendered,
|
|
154
173
|
};
|
|
@@ -407,8 +407,15 @@ store property is the `VACUUM INTO`, and that is G19. The code's numbering wins.
|
|
|
407
407
|
`feelings` row names `whose`, one of six cores, a wheel emotion or `other` with the
|
|
408
408
|
word kept, a strength recorded once, and optionally the feeling on the same memory it
|
|
409
409
|
sits beneath. A write is all-or-none and refused by name (`FEELING_INVALID`) rather
|
|
410
|
-
than guessed; an unknown emotion is kept as `other`, never mapped
|
|
411
|
-
|
|
410
|
+
than guessed; an unknown emotion is kept as `other`, never mapped (a small ALIAS list
|
|
411
|
+
— `exposed` → `vulnerable` — reads as its wheel word and says so; a blend is stored
|
|
412
|
+
under its primary core). The owner's removal deletes them with the memory. *Since
|
|
413
|
+
2026-09-26 (emotion part A) they move physics:* `row()` reads the strongest recorded
|
|
414
|
+
strength beside the row (`feeling_peak`, not a column), which physics folds into the
|
|
415
|
+
memory's emotional intensity (§5.10 there). The recorded strength is still never
|
|
416
|
+
rewritten. Reads for the rest: `feelingsSince(ms)` (recall's mood), `feelingsOn(ids)`
|
|
417
|
+
(one query for recall's candidates), `emotionCensus()` (counts for the mechanisms
|
|
418
|
+
views).
|
|
412
419
|
|
|
413
420
|
## 6. Scars honored
|
|
414
421
|
|
package/src/core/store/NOTES.md
CHANGED
|
@@ -1556,6 +1556,26 @@ migration transaction and a fresh store has it from birth.
|
|
|
1556
1556
|
- **Nothing reads them.** Salience, decay and recall are untouched; the `emotional`
|
|
1557
1557
|
dimension and `meta.feeling` are exactly as before. `Counterpart#addFeelings` runs
|
|
1558
1558
|
`carried_by` and an `other` word through `redactSecrets` first.
|
|
1559
|
+
*(Superseded 2026-09-26, emotion part A — see the next section.)*
|
|
1560
|
+
|
|
1561
|
+
### Feelings are read (2026-09-26, emotion part A)
|
|
1562
|
+
|
|
1563
|
+
- **`row()` carries `feeling_peak`** — `(SELECT MAX(strength) FROM feelings WHERE
|
|
1564
|
+
memory_id = m.id)`, one probe of the `feelings_memory` index. Not a column and not on
|
|
1565
|
+
`MemoryRow` (the `Row` index type would reject an optional member); it is the
|
|
1566
|
+
`FeelingPeak` intersection on `row()`'s return, and `rowToPhysics` reads it as
|
|
1567
|
+
`feelingPeak`, null or absent reading as "no feeling". Every physics read goes through
|
|
1568
|
+
`row()` — `read`, `physicsOf`, sleep's phases, recall's scoring, the dashboard — so a
|
|
1569
|
+
feeling weighs the same everywhere. `rebuildCache`'s bare `SELECT *` reads no feeling,
|
|
1570
|
+
and needs none: it computes no strength.
|
|
1571
|
+
- **Suggestions** (`notices[].closest`) are now offered only for a near misspelling under
|
|
1572
|
+
the same core (`feelings-wheel.ts#closestKeys`), never the five nearest by raw edit
|
|
1573
|
+
distance — which offered "tender" bored, despair and lonely. An alias read is a notice
|
|
1574
|
+
with `readAs`; the `store.feelings` ring event's `other` count excludes it.
|
|
1575
|
+
- **Three reads added**: `feelingsSince(ms)` (feelings on LIVE memories recorded at or
|
|
1576
|
+
after a moment — recall's mood), `feelingsOn(ids)` (one query, chunked at 500 ids, with
|
|
1577
|
+
each memory's `birth_day` for softening), `emotionCensus({ sinceDay })` (live memories
|
|
1578
|
+
with feelings, and with intensity above 0 — counts only).
|
|
1559
1579
|
|
|
1560
1580
|
### What the adversarial review of #231 changed (2026-09-25)
|
|
1561
1581
|
|
|
@@ -12,9 +12,16 @@
|
|
|
12
12
|
* `carried_by` says briefly what in the moment carried it — the words, what
|
|
13
13
|
* happened — and need not be a statement of feeling.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* READ SINCE 2026-09-26 (emotion part A). The strongest recorded strength on
|
|
16
|
+
* a memory joins its numeric `emotional` score as its emotional intensity,
|
|
17
|
+
* which lifts its height and slows its decay (physics §5.10, read beside the row
|
|
18
|
+
* by `Store.row()`); a feeling recorded in the last few hours sets the mood
|
|
19
|
+
* that recall matches against (recall G18). The `meta.feeling` label is still
|
|
20
|
+
* only a label.
|
|
21
|
+
*
|
|
22
|
+
* A BLEND (`tender`: sad + happy) may be named under either of its cores and is
|
|
23
|
+
* stored under its PRIMARY core — `core` holds one value, and anything that
|
|
24
|
+
* matches by core reads the blend as both (`feelings-wheel.ts#coresOfFeeling`).
|
|
18
25
|
*/
|
|
19
26
|
import { CORE_EMOTIONS, OTHER_EMOTION, closestKeys, isCoreEmotion, resolveEmotion } from "../feelings-wheel.js";
|
|
20
27
|
import type { CoreEmotion } from "../feelings-wheel.js";
|
|
@@ -64,12 +71,18 @@ export interface FeelingRow extends Row {
|
|
|
64
71
|
updated_at: number;
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* What the caller should hear about one input: either it was stored as `other`
|
|
76
|
+
* (the word as given, and the wheel keys GENUINELY close to it — usually none),
|
|
77
|
+
* or, with `readAs`, the word was an alias and was stored as that wheel key.
|
|
78
|
+
*/
|
|
68
79
|
export interface FeelingNotice {
|
|
69
80
|
readonly index: number;
|
|
70
81
|
readonly word: string;
|
|
71
82
|
readonly core: CoreEmotion;
|
|
72
83
|
readonly closest: readonly string[];
|
|
84
|
+
/** Set when `word` was read as this wheel key (`exposed` → `vulnerable`). */
|
|
85
|
+
readonly readAs?: string;
|
|
73
86
|
}
|
|
74
87
|
|
|
75
88
|
export interface AddFeelingsResult {
|
|
@@ -129,6 +142,7 @@ export function checkFeelings(inputs: readonly FeelingInput[]): { rows: CheckedF
|
|
|
129
142
|
}
|
|
130
143
|
let emotion: string;
|
|
131
144
|
let otherWord: string | null = null;
|
|
145
|
+
let storedCore: CoreEmotion = core;
|
|
132
146
|
if (f.emotion.trim().toLowerCase() === OTHER_EMOTION) {
|
|
133
147
|
const word = (f.otherWord ?? "").trim();
|
|
134
148
|
if (word.length === 0) invalid(i, "other-word-missing");
|
|
@@ -142,9 +156,12 @@ export function checkFeelings(inputs: readonly FeelingInput[]): { rows: CheckedF
|
|
|
142
156
|
}
|
|
143
157
|
if (read.kind === "wheel") {
|
|
144
158
|
emotion = read.entry.key;
|
|
159
|
+
// A blend named under its second core is stored under its primary.
|
|
160
|
+
storedCore = read.entry.core;
|
|
161
|
+
if (read.alias !== undefined) notices.push({ index: i, word: read.alias, core: storedCore, closest: [], readAs: read.entry.key });
|
|
145
162
|
} else {
|
|
146
163
|
// Not on the wheel: kept, as `other`, with the word — and the caller is
|
|
147
|
-
// told
|
|
164
|
+
// told of a wheel word only when one is genuinely close (a misspelling).
|
|
148
165
|
emotion = OTHER_EMOTION;
|
|
149
166
|
otherWord = read.kind === "other" ? read.word : f.emotion.trim();
|
|
150
167
|
notices.push({ index: i, word: otherWord, core, closest: read.kind === "other" ? read.closest : [] });
|
|
@@ -160,7 +177,7 @@ export function checkFeelings(inputs: readonly FeelingInput[]): { rows: CheckedF
|
|
|
160
177
|
}
|
|
161
178
|
rows.push({
|
|
162
179
|
whose: f.whose as FeelingWhose,
|
|
163
|
-
core,
|
|
180
|
+
core: storedCore,
|
|
164
181
|
emotion,
|
|
165
182
|
otherWord,
|
|
166
183
|
strength: f.strength,
|
package/src/core/store/index.ts
CHANGED
|
@@ -71,6 +71,7 @@ import {
|
|
|
71
71
|
import type {
|
|
72
72
|
EdgeRow,
|
|
73
73
|
EventRow,
|
|
74
|
+
FeelingPeak,
|
|
74
75
|
GateSessionRow,
|
|
75
76
|
MemoryRow,
|
|
76
77
|
MigrationNote,
|
|
@@ -130,6 +131,7 @@ export * from "./feelings.js";
|
|
|
130
131
|
export type { Db, Statement, WalFold } from "./db.js";
|
|
131
132
|
export type {
|
|
132
133
|
MemoryRow,
|
|
134
|
+
FeelingPeak,
|
|
133
135
|
VersionRow,
|
|
134
136
|
EdgeRow,
|
|
135
137
|
EventRow,
|
|
@@ -472,7 +474,9 @@ export interface ProspectiveInput {
|
|
|
472
474
|
memoryId: string;
|
|
473
475
|
windowKey: string;
|
|
474
476
|
eventDate: string;
|
|
475
|
-
|
|
477
|
+
/** `range` since 2026-09-26 (prospective windows.ts) — the column is TEXT, so
|
|
478
|
+
* this widens the type and nothing on disk. */
|
|
479
|
+
precision: "day" | "month" | "year" | "range";
|
|
476
480
|
state: "armed" | "fired" | "suppressed" | "expired";
|
|
477
481
|
fires?: number;
|
|
478
482
|
lastFiredDay?: number | null;
|
|
@@ -1656,7 +1660,8 @@ export class Store {
|
|
|
1656
1660
|
* Record feelings on a memory (schema v7; `store/feelings.ts`). All or none:
|
|
1657
1661
|
* one bad input refuses the call `FEELING_INVALID` and writes nothing. An
|
|
1658
1662
|
* emotion not on the wheel is stored as `other` with the word kept, and the
|
|
1659
|
-
* result's `notices` name
|
|
1663
|
+
* result's `notices` name a wheel key only when one is a near misspelling (and
|
|
1664
|
+
* an alias read as a wheel word carries `readAs`).
|
|
1660
1665
|
* `beneath` is an existing feeling's id ON THIS MEMORY or another input's
|
|
1661
1666
|
* index. `model` is the writer's model id, screened like `PutInput.model`.
|
|
1662
1667
|
*/
|
|
@@ -1692,7 +1697,7 @@ export class Store {
|
|
|
1692
1697
|
this.ops.run("UPDATE feelings SET beneath_id = ? WHERE id = ?", under, ids[i] as string);
|
|
1693
1698
|
});
|
|
1694
1699
|
});
|
|
1695
|
-
this.emit("store.feelings", memoryId, { count: rows.length, other: notices.length });
|
|
1700
|
+
this.emit("store.feelings", memoryId, { count: rows.length, other: notices.filter((n) => n.readAs === undefined).length });
|
|
1696
1701
|
return { ids, notices };
|
|
1697
1702
|
}
|
|
1698
1703
|
|
|
@@ -2495,8 +2500,19 @@ export class Store {
|
|
|
2495
2500
|
return this.row(id) !== undefined;
|
|
2496
2501
|
}
|
|
2497
2502
|
|
|
2498
|
-
|
|
2499
|
-
|
|
2503
|
+
/**
|
|
2504
|
+
* One memory's row — plus `feeling_peak`, the strongest feeling recorded on
|
|
2505
|
+
* it (physics §5.10, emotion part A). Every physics read goes through here
|
|
2506
|
+
* (`read`, `physicsOf`, sleep, recall, the dashboard), so this one subquery
|
|
2507
|
+
* is what makes a feeling weigh the same everywhere. `feelings_memory` is
|
|
2508
|
+
* indexed, so it is one index probe per row.
|
|
2509
|
+
*/
|
|
2510
|
+
row(id: string): (MemoryRow & FeelingPeak) | undefined {
|
|
2511
|
+
return this.ops.get<MemoryRow & FeelingPeak>(
|
|
2512
|
+
`SELECT m.*, (SELECT MAX(f.strength) FROM feelings f WHERE f.memory_id = m.id) AS feeling_peak
|
|
2513
|
+
FROM memories m WHERE m.id = ?`,
|
|
2514
|
+
id,
|
|
2515
|
+
);
|
|
2500
2516
|
}
|
|
2501
2517
|
|
|
2502
2518
|
read(id: string): StoredMemory {
|
|
@@ -2587,14 +2603,18 @@ export class Store {
|
|
|
2587
2603
|
* month `2026-10` sorts BEFORE `2026-10-01` as text and a range's text runs
|
|
2588
2604
|
* past its first day, so a plain `BETWEEN` would miss both. The index answers
|
|
2589
2605
|
* "starts no later than `to`" (`'~'` sorts after every digit and `..`), and
|
|
2590
|
-
* `calendarOverlaps` decides the rest.
|
|
2591
|
-
*
|
|
2592
|
-
*
|
|
2606
|
+
* `calendarOverlaps` decides the rest. The older meta convention
|
|
2607
|
+
* (`meta.eventDate`) is read by nothing since 2026-09-26: this column is the
|
|
2608
|
+
* one place a reminder date lives.
|
|
2609
|
+
*
|
|
2610
|
+
* `archived: true` includes archived memories too — for `prospective/`'s exit
|
|
2611
|
+
* accounting, where a dated memory archived before its window is the `faded`
|
|
2612
|
+
* exit and has to be found to be counted.
|
|
2593
2613
|
*/
|
|
2594
|
-
datedMemories(from: string, to: string): DatedMemory[] {
|
|
2614
|
+
datedMemories(from: string, to: string, opts: { archived?: boolean } = {}): DatedMemory[] {
|
|
2595
2615
|
const rows = this.ops.all<{ id: string; event_date: string }>(
|
|
2596
2616
|
`SELECT id, event_date FROM memories
|
|
2597
|
-
WHERE event_date IS NOT NULL AND event_date <= ? AND archived = 0`,
|
|
2617
|
+
WHERE event_date IS NOT NULL AND event_date <= ?${opts.archived === true ? "" : " AND archived = 0"}`,
|
|
2598
2618
|
`${to}~`,
|
|
2599
2619
|
);
|
|
2600
2620
|
return rows
|
|
@@ -2611,6 +2631,71 @@ export class Store {
|
|
|
2611
2631
|
);
|
|
2612
2632
|
}
|
|
2613
2633
|
|
|
2634
|
+
/**
|
|
2635
|
+
* Feelings recorded at or after `sinceMs` (the store's clock, UTC ms) — the
|
|
2636
|
+
* raw material of "how each person feels right now" (recall G18). Newest
|
|
2637
|
+
* first. Only feelings on a memory that is still live: an archived or
|
|
2638
|
+
* superseded memory's feelings no longer speak for the moment.
|
|
2639
|
+
*/
|
|
2640
|
+
feelingsSince(sinceMs: number): FeelingRow[] {
|
|
2641
|
+
return this.ops.all<FeelingRow>(
|
|
2642
|
+
`SELECT f.* FROM feelings f JOIN memories m ON m.id = f.memory_id
|
|
2643
|
+
WHERE f.created_at >= ? AND m.archived = 0 AND m.superseded_by IS NULL
|
|
2644
|
+
ORDER BY f.created_at DESC, f.rowid DESC`,
|
|
2645
|
+
sinceMs,
|
|
2646
|
+
);
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
/**
|
|
2650
|
+
* The feelings on several memories in ONE query, with each memory's birth
|
|
2651
|
+
* day beside them (a feeling softens from the day its memory was born —
|
|
2652
|
+
* physics §5.10). Recall's mood-matching reads this for its candidates only,
|
|
2653
|
+
* inside its latency budget. Ids with no feelings are simply absent.
|
|
2654
|
+
*/
|
|
2655
|
+
feelingsOn(ids: readonly string[]): Map<string, (FeelingRow & { birth_day: number })[]> {
|
|
2656
|
+
const out = new Map<string, (FeelingRow & { birth_day: number })[]>();
|
|
2657
|
+
if (ids.length === 0) return out;
|
|
2658
|
+
const unique = [...new Set(ids)];
|
|
2659
|
+
// SQLite's default bound-variable ceiling is far above recall's candidate
|
|
2660
|
+
// cap; chunk anyway so no caller can walk into it.
|
|
2661
|
+
for (let at = 0; at < unique.length; at += 500) {
|
|
2662
|
+
const part = unique.slice(at, at + 500);
|
|
2663
|
+
const rows = this.ops.all<FeelingRow & { birth_day: number }>(
|
|
2664
|
+
`SELECT f.*, m.birth_day AS birth_day FROM feelings f JOIN memories m ON m.id = f.memory_id
|
|
2665
|
+
WHERE f.memory_id IN (${part.map(() => "?").join(",")})
|
|
2666
|
+
ORDER BY f.created_at, f.rowid`,
|
|
2667
|
+
...part,
|
|
2668
|
+
);
|
|
2669
|
+
for (const r of rows) {
|
|
2670
|
+
const list = out.get(r.memory_id) ?? [];
|
|
2671
|
+
list.push(r);
|
|
2672
|
+
out.set(r.memory_id, list);
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
return out;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
/**
|
|
2679
|
+
* THE EMOTION CENSUS — how many live memories carry feeling, and how many of
|
|
2680
|
+
* those the feeling actually weighs on (intensity > 0: held higher at birth
|
|
2681
|
+
* and fading slower, physics §5.10). `sinceDay` narrows both to memories born
|
|
2682
|
+
* on or after that lived day. Counts only; no word of any feeling leaves.
|
|
2683
|
+
*/
|
|
2684
|
+
emotionCensus(opts: { sinceDay?: number } = {}): { withFeelings: number; weighted: number } {
|
|
2685
|
+
const since = opts.sinceDay ?? Number.MIN_SAFE_INTEGER;
|
|
2686
|
+
const row = this.ops.get<{ with_feelings: number | null; weighted: number | null }>(
|
|
2687
|
+
`SELECT
|
|
2688
|
+
SUM(CASE WHEN EXISTS (SELECT 1 FROM feelings f WHERE f.memory_id = m.id) THEN 1 ELSE 0 END) AS with_feelings,
|
|
2689
|
+
SUM(CASE WHEN m.emotional > 0
|
|
2690
|
+
OR EXISTS (SELECT 1 FROM feelings f WHERE f.memory_id = m.id AND f.strength > 0)
|
|
2691
|
+
THEN 1 ELSE 0 END) AS weighted
|
|
2692
|
+
FROM memories m
|
|
2693
|
+
WHERE m.archived = 0 AND m.superseded_by IS NULL AND m.birth_day >= ?`,
|
|
2694
|
+
since,
|
|
2695
|
+
);
|
|
2696
|
+
return { withFeelings: row?.with_feelings ?? 0, weighted: row?.weighted ?? 0 };
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2614
2699
|
/**
|
|
2615
2700
|
* How many feelings, by `whose` and by `core` or `emotion` (an `other` counts
|
|
2616
2701
|
* under `other`), recorded from `from` to `to` — the person's calendar days,
|
|
@@ -2697,6 +2782,18 @@ export class Store {
|
|
|
2697
2782
|
);
|
|
2698
2783
|
}
|
|
2699
2784
|
|
|
2785
|
+
/**
|
|
2786
|
+
* Every memory id that has at least one firing-state row, sorted. The exit
|
|
2787
|
+
* accounting's other half (prospective §5 G12): a row can outlive its
|
|
2788
|
+
* memory's date — a date cleared by `revise`, a reschedule's retired window —
|
|
2789
|
+
* and `datedMemories` alone would never find it.
|
|
2790
|
+
*/
|
|
2791
|
+
prospectiveMemoryIds(): string[] {
|
|
2792
|
+
return this.ops
|
|
2793
|
+
.all<{ memory_id: string }>("SELECT DISTINCT memory_id FROM prospective ORDER BY memory_id")
|
|
2794
|
+
.map((r) => r.memory_id);
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2700
2797
|
removalRecord(id?: string): RemovalRow[] {
|
|
2701
2798
|
const rows =
|
|
2702
2799
|
id === undefined
|
|
@@ -389,6 +389,17 @@ export interface MemoryRow extends Row {
|
|
|
389
389
|
event_date: string | null;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
/**
|
|
393
|
+
* NOT A COLUMN: the strongest recorded feeling on a memory, read beside the
|
|
394
|
+
* row by `Store.row()` (`MAX(feelings.strength)`), null when it has none.
|
|
395
|
+
* Optional, and kept off `MemoryRow` itself, so a bare `SELECT * FROM
|
|
396
|
+
* memories` is still a row — such a read simply carries no feeling, and the
|
|
397
|
+
* intensity falls back to the numeric `emotional` score (physics §5.10).
|
|
398
|
+
*/
|
|
399
|
+
export interface FeelingPeak {
|
|
400
|
+
feeling_peak?: number | null;
|
|
401
|
+
}
|
|
402
|
+
|
|
392
403
|
export interface VersionRow extends Row {
|
|
393
404
|
memory_id: string;
|
|
394
405
|
seq: number;
|
|
@@ -809,7 +820,7 @@ export function rowToSalience(row: MemoryRow): Salience {
|
|
|
809
820
|
};
|
|
810
821
|
}
|
|
811
822
|
|
|
812
|
-
export function rowToPhysics(row: MemoryRow): MemoryPhysics {
|
|
823
|
+
export function rowToPhysics(row: MemoryRow & FeelingPeak): MemoryPhysics {
|
|
813
824
|
return {
|
|
814
825
|
kind: row.kind,
|
|
815
826
|
salience: rowToSalience(row),
|
|
@@ -819,6 +830,9 @@ export function rowToPhysics(row: MemoryRow): MemoryPhysics {
|
|
|
819
830
|
// Distinct lived days that credited a use — `uses` is a weighted sum and
|
|
820
831
|
// cannot reconstruct it (physics §5.3/§5.5). Absent reads as 0.
|
|
821
832
|
reinforcedDays: row.reinforced_days,
|
|
833
|
+
// The strongest feeling recorded on it (physics §5.10), when the read
|
|
834
|
+
// carried one — `Store.row()` always does.
|
|
835
|
+
feelingPeak: row.feeling_peak ?? null,
|
|
822
836
|
consolidated: row.consolidated === 1,
|
|
823
837
|
promotedIdentity: row.promoted_identity === 1,
|
|
824
838
|
protected: row.protected === 1,
|
package/src/core/types.ts
CHANGED
|
@@ -71,6 +71,15 @@ export interface MemoryPhysics {
|
|
|
71
71
|
* Optional so this stays an extension, not a break; absent reads as 0, which
|
|
72
72
|
* is the promotion-blocking direction. */
|
|
73
73
|
reinforcedDays?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The strongest RECORDED feeling on this memory (the `feelings` table's
|
|
76
|
+
* `MAX(strength)`, owner's or self's), or absent/null when it carries none.
|
|
77
|
+
* Read beside the row by `store.row()`; physics folds it into the emotional
|
|
78
|
+
* intensity (`physics.emotionalIntensity`, CONTRACT §5.10). As recorded, never
|
|
79
|
+
* softened: the height and slope a feeling gives a memory are set by how it
|
|
80
|
+
* felt, the way affect stamps a trace at encoding.
|
|
81
|
+
*/
|
|
82
|
+
feelingPeak?: number | null;
|
|
74
83
|
consolidated: boolean;
|
|
75
84
|
/** Set only by the explicit promotion crossing or revision inheritance (§5.3). */
|
|
76
85
|
promotedIdentity: boolean;
|