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
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* The dates come from the CALLER. This module does no NLP: it reads the shape of
|
|
16
16
|
* a date string and nothing else (`windows.ts`). Whoever extracted "September"
|
|
17
|
-
* from a sentence owns that judgment
|
|
17
|
+
* from a sentence owns that judgment — since 2026-09-26 that is the model, which
|
|
18
|
+
* writes the explicit `eventDate` field on `note` / `session_end` — and the
|
|
19
|
+
* deriver owns only what follows from it.
|
|
18
20
|
*
|
|
19
21
|
* Every refusal has a NAME. "Not prospective" is not a verdict a log can act on,
|
|
20
22
|
* and a memory excluded because it is a skill and one excluded because its window
|
|
@@ -42,7 +44,15 @@ export type DeriveReason =
|
|
|
42
44
|
| "excluded-kind"
|
|
43
45
|
/** A journal chapter. Its date is a day that was LIVED, never one arriving. */
|
|
44
46
|
| "journal"
|
|
47
|
+
/** Salience under `SALIENCE_FLOOR`, for a memory whose date the AUTHOR did
|
|
48
|
+
* not set — a caller-extracted date (`extraDates`). A memory carrying an
|
|
49
|
+
* explicit `eventDate` is exempt (owner decision 2026-09-26): choosing a
|
|
50
|
+
* date is itself the importance signal. */
|
|
45
51
|
| "below-salience-floor"
|
|
52
|
+
/** Decayed to physics' prune floor (`FADED_STRENGTH`) — §12 G10, no decay
|
|
53
|
+
* exemption before arrival: an occasion that faded before its window did
|
|
54
|
+
* not matter. Holds for an explicitly dated memory too (2026-09-26). */
|
|
55
|
+
| "faded"
|
|
46
56
|
/** Every derived window is behind us — the property expiring by itself. */
|
|
47
57
|
| "window-passed";
|
|
48
58
|
|
|
@@ -85,6 +95,20 @@ export interface DerivableMemory {
|
|
|
85
95
|
* is a rule that holds where somebody remembered it.
|
|
86
96
|
*/
|
|
87
97
|
readonly journal: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The memory carries an EXPLICIT reminder date — the `event_date` column its
|
|
100
|
+
* author wrote on `note` / `session_end` (2026-09-26). Such a memory is
|
|
101
|
+
* exempt from the salience floor: the owner's rule is that choosing a date
|
|
102
|
+
* is itself the importance signal. Absent or false: the floor applies, as it
|
|
103
|
+
* always has, to a date some caller extracted.
|
|
104
|
+
*/
|
|
105
|
+
readonly explicitDate?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Decayed at or below `FADED_STRENGTH` on the lived day asked about. Computed
|
|
108
|
+
* by the caller that holds the physics (`Prospective.load`), so this stays a
|
|
109
|
+
* pure predicate. Absent: not checked.
|
|
110
|
+
*/
|
|
111
|
+
readonly faded?: boolean;
|
|
88
112
|
}
|
|
89
113
|
|
|
90
114
|
/** A content-date the CALLER extracted. Its precision is its own shape (§12 G4). */
|
|
@@ -144,7 +168,11 @@ export function derive(
|
|
|
144
168
|
if (memory.journal) blockedBy.push("journal");
|
|
145
169
|
if (EXCLUDED_KINDS.includes(memory.kind)) blockedBy.push("excluded-kind");
|
|
146
170
|
if (!encodeDateOk(memory.learnedOn)) blockedBy.push("missing-encode-date");
|
|
147
|
-
if (
|
|
171
|
+
if (memory.faded === true) blockedBy.push("faded");
|
|
172
|
+
// The floor gates UNASKED surfacing of a date somebody else read out of the
|
|
173
|
+
// memory. An explicit `eventDate` was asked for, so it is exempt (owner
|
|
174
|
+
// decision 2026-09-26); decay (`faded`, above) and archival still hold.
|
|
175
|
+
if (s < t.SALIENCE_FLOOR && memory.explicitDate !== true) blockedBy.push("below-salience-floor");
|
|
148
176
|
|
|
149
177
|
const windows: DerivedWindow[] = [];
|
|
150
178
|
const rejectedDates: { date: string; reason: DeriveReason }[] = [];
|
|
@@ -159,7 +187,8 @@ export function derive(
|
|
|
159
187
|
rejectedDates.push({ date: d.date, reason: "year-only-precision" });
|
|
160
188
|
continue;
|
|
161
189
|
}
|
|
162
|
-
|
|
190
|
+
// The memory id salts a month's stagger (tune question a) and nothing else.
|
|
191
|
+
const w = windowFor(d.date, precision, t, memory.id);
|
|
163
192
|
if (w === null) {
|
|
164
193
|
rejectedDates.push({ date: d.date, reason: "malformed-date" });
|
|
165
194
|
continue;
|
|
@@ -34,11 +34,12 @@ import type { Kind } from "../types.js";
|
|
|
34
34
|
import { strength } from "../physics/index.js";
|
|
35
35
|
import type { UseTier } from "../physics/index.js";
|
|
36
36
|
import type { ProseDoc, ProspectiveInput, ProspectiveRow, Store } from "../store/index.js";
|
|
37
|
+
import { addDays, isDay } from "../time.js";
|
|
37
38
|
import { derive } from "./derive.js";
|
|
38
39
|
import type { DerivableMemory, DeriveReason, ExtractedDate, Prospectivity } from "./derive.js";
|
|
39
40
|
import { TEMPORAL_MAX_TIER, withTunables } from "./tunables.js";
|
|
40
41
|
import type { ProspectiveTunables } from "./tunables.js";
|
|
41
|
-
import { parseWindowKey, phaseOf, precisionOf, rampAt, windowFor } from "./windows.js";
|
|
42
|
+
import { imminence, parseWindowKey, phaseOf, precisionOf, rampAt, windowFor } from "./windows.js";
|
|
42
43
|
import type { DatePrecision, Phase, Window, WindowPrecision } from "./windows.js";
|
|
43
44
|
|
|
44
45
|
export * from "./derive.js";
|
|
@@ -83,6 +84,51 @@ export type WindowState = ProspectiveInput["state"];
|
|
|
83
84
|
export const PROSPECTIVE_FIRE_EVENT = "prospective.fire";
|
|
84
85
|
export const PROSPECTIVE_REFUSED_EVENT = "prospective.fire.refused";
|
|
85
86
|
|
|
87
|
+
/**
|
|
88
|
+
* THE THIRD DURABLE ROW (2026-09-26): a PLAIN item was told to the person —
|
|
89
|
+
* one row per memory, window and beat, latched by `dedupKey`, so it doubles as
|
|
90
|
+
* the once-only mark two hook processes race for (`claimPlain`). Ids, the
|
|
91
|
+
* window key, the beat and today's calendar date; never a word of the memory.
|
|
92
|
+
*/
|
|
93
|
+
export const PROSPECTIVE_PLAIN_EVENT = "prospective.plain";
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* PLAIN OR QUIET (owner decision 2026-09-25/26, a working default). The author
|
|
97
|
+
* of a dated memory says which, on the same `note` / `session_end` entry that
|
|
98
|
+
* carries the date, and it lives in the memory's `meta` bag under this key — no
|
|
99
|
+
* column, no schema bump. Anything but `"plain"` reads as quiet, which is the
|
|
100
|
+
* default and the whole of the tact principle: a quiet item is one more cue,
|
|
101
|
+
* capped at the footnote tier. A plain one is also SAID, plainly, on its day —
|
|
102
|
+
* the one deliberate exception to "no bypass lane", recorded in CONTRACT §3.
|
|
103
|
+
*/
|
|
104
|
+
export type CueMode = "plain" | "quiet";
|
|
105
|
+
export const CUE_MODE_META = "remind";
|
|
106
|
+
|
|
107
|
+
export function cueModeOf(doc: Pick<ProseDoc, "meta">): CueMode {
|
|
108
|
+
return doc.meta[CUE_MODE_META] === "plain" ? "plain" : "quiet";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A REMINDER THAT MOVED (review of #247, 2026-09-26). When a revision takes a
|
|
113
|
+
* dated memory's reminder over (`Counterpart#carryReminder`), the two memories
|
|
114
|
+
* point at each other in their meta bags, ids only:
|
|
115
|
+
*
|
|
116
|
+
* - the successor's `reminderFrom` names the memory it took the reminder
|
|
117
|
+
* from, so what was already said or spent for the SAME window (the plain
|
|
118
|
+
* latch, the quiet fire budget, a referenced stop) is still counted — a
|
|
119
|
+
* move is not a new reminder (`lineage`);
|
|
120
|
+
* - the old memory's `reminderMovedTo` names where it went, so a later
|
|
121
|
+
* revision that addresses the OLD id (which stays live: revising an
|
|
122
|
+
* ordinary memory is link-only) still finds the reminder to reschedule or
|
|
123
|
+
* drop, instead of finding nothing.
|
|
124
|
+
*/
|
|
125
|
+
export const DATE_FROM_META = "reminderFrom";
|
|
126
|
+
export const DATE_MOVED_TO_META = "reminderMovedTo";
|
|
127
|
+
|
|
128
|
+
/** How far either pointer is followed. A reminder revised this many times in a
|
|
129
|
+
* row is still found; a longer chain answers as if it ended there. */
|
|
130
|
+
export const DATE_LINEAGE_MAX = 16;
|
|
131
|
+
|
|
86
132
|
const WINDOW_STATES: readonly WindowState[] = ["armed", "fired", "suppressed", "expired"];
|
|
87
133
|
|
|
88
134
|
/** Box 2 hands back `state` as TEXT. An unrecognized value reads as `armed` — the
|
|
@@ -109,6 +155,13 @@ export type SuppressReason =
|
|
|
109
155
|
| "over-fired"
|
|
110
156
|
/** Brake 1: at most one ambient fire per occasion per LIVED day. */
|
|
111
157
|
| "already-fired-today"
|
|
158
|
+
/** Tune question (b), 2026-09-26: a month or range window's LAST fire is kept
|
|
159
|
+
* for after the span it names, so it gets an "after" beat instead of spending
|
|
160
|
+
* its whole budget in the first days (`HOLD_LAST_FIRE_FOR_AFTER`). */
|
|
161
|
+
| "held-for-after"
|
|
162
|
+
/** A PLAIN item already told outright today (`claimPlain`): the same thing
|
|
163
|
+
* as a footnote on the next turn would be saying it twice (2026-09-26). */
|
|
164
|
+
| "told-plainly-today"
|
|
112
165
|
/** Brake 3: already offered in this session. */
|
|
113
166
|
| "session-dedup";
|
|
114
167
|
|
|
@@ -186,6 +239,33 @@ export interface Arrival {
|
|
|
186
239
|
* arrival (§12 G10): a future-dated memory that faded before its window was
|
|
187
240
|
* an occasion that didn't matter. */
|
|
188
241
|
readonly strength: number;
|
|
242
|
+
/** Plain or quiet, as the author said (`CUE_MODE_META`). Carried so the fire
|
|
243
|
+
* row can count the two apart; it changes nothing about the cue itself. */
|
|
244
|
+
readonly mode: CueMode;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Which moment of a plain item's window it is being told on. */
|
|
248
|
+
export type PlainBeat =
|
|
249
|
+
/** A day-dated item, on its day. */
|
|
250
|
+
| "day"
|
|
251
|
+
/** A month or range item, the first day it is open and seen. */
|
|
252
|
+
| "opens"
|
|
253
|
+
/** A month or range item, on the last day it names. */
|
|
254
|
+
| "last-day";
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* A plain item due to be told today. Records only — like `Arrival`, no words:
|
|
258
|
+
* the adapter that talks to a person owns those (`adapters/claude-code`).
|
|
259
|
+
*/
|
|
260
|
+
export interface PlainDue {
|
|
261
|
+
readonly memoryId: string;
|
|
262
|
+
readonly windowKey: string;
|
|
263
|
+
readonly eventDate: string;
|
|
264
|
+
readonly precision: WindowPrecision;
|
|
265
|
+
readonly beat: PlainBeat;
|
|
266
|
+
/** The span the date names, `YYYY-MM-DD` both. */
|
|
267
|
+
readonly firstDay: string;
|
|
268
|
+
readonly lastDay: string;
|
|
189
269
|
}
|
|
190
270
|
|
|
191
271
|
export interface SuppressionRecord {
|
|
@@ -309,29 +389,37 @@ export interface ExitReport {
|
|
|
309
389
|
readonly exits: Exit[];
|
|
310
390
|
}
|
|
311
391
|
|
|
312
|
-
/** Where a memory's own content-dates live on the prose payload. */
|
|
313
|
-
export const EVENT_DATE_META = "eventDate";
|
|
314
|
-
export const EVENT_DATES_META = "eventDates";
|
|
315
|
-
|
|
316
392
|
/**
|
|
317
|
-
* A memory's content-
|
|
318
|
-
* the `
|
|
319
|
-
*
|
|
320
|
-
*
|
|
393
|
+
* A memory's content-date: its reminder date, `ProseDoc.eventDate` (schema v7,
|
|
394
|
+
* the `event_date` column), exactly as stated. SHAPE ONLY — nothing here reads
|
|
395
|
+
* prose for dates; the model writes the field (INTERFACE-GAPS #2, closed
|
|
396
|
+
* 2026-09-26).
|
|
397
|
+
*
|
|
398
|
+
* Two sources this used to read are gone on purpose. `happenedOn` is a PAST
|
|
399
|
+
* date by name, and `schemas/` writes every belief's `statedOn` into it, so
|
|
400
|
+
* reading it as a future occasion was a category error waiting for data. The
|
|
401
|
+
* `meta.eventDate` / `meta.eventDates` convention was this module's own
|
|
402
|
+
* stand-in for the column, and nothing ever wrote it; keeping it would have
|
|
403
|
+
* meant a second enumeration (a scan of every memory) to find what the index
|
|
404
|
+
* now answers. Caller-extracted dates still arrive through `extraDates`.
|
|
321
405
|
*/
|
|
322
|
-
export function contentDates(doc: ProseDoc): ExtractedDate[] {
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
return out.filter((d) => (seen.has(d.date) ? false : (seen.add(d.date), true)));
|
|
406
|
+
export function contentDates(doc: Pick<ProseDoc, "eventDate">): ExtractedDate[] {
|
|
407
|
+
const v = doc.eventDate;
|
|
408
|
+
return typeof v === "string" && v !== "" ? [{ date: v }] : [];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Every memory whose stated date could have an OPEN window on `at`: the span
|
|
412
|
+
* must reach from `at - GRACE_DAYS` to `at + LEAD_DAYS`. */
|
|
413
|
+
function candidateSpan(at: string, t: ProspectiveTunables): { from: string; to: string } | null {
|
|
414
|
+
if (!isDay(at)) return null;
|
|
415
|
+
return { from: addDays(at, -t.GRACE_DAYS), to: addDays(at, t.LEAD_DAYS) };
|
|
333
416
|
}
|
|
334
417
|
|
|
418
|
+
/** Score, then imminence, then key — tune question (d). Scores closer than
|
|
419
|
+
* this are a TIE: two salience means 0.7 and 0.7 must not be split by a float
|
|
420
|
+
* rounding in the ramp. */
|
|
421
|
+
const TIE = 1e-9;
|
|
422
|
+
|
|
335
423
|
interface Loaded {
|
|
336
424
|
memory: DerivableMemory;
|
|
337
425
|
doc: ProseDoc;
|
|
@@ -410,8 +498,17 @@ export class Prospective {
|
|
|
410
498
|
const suppressed: SuppressionRecord[] = [];
|
|
411
499
|
const refused: { memoryId: string; reason: DeriveReason }[] = [];
|
|
412
500
|
const denied = new Set(this.store.deniedIds());
|
|
413
|
-
|
|
501
|
+
// THE INDEX, not a scan (INTERFACE-GAPS #2, closed 2026-09-26): only a
|
|
502
|
+
// memory whose stated date reaches `at` through lead or grace can have an
|
|
503
|
+
// open window, and `Store.datedMemories` answers exactly that. The ids a
|
|
504
|
+
// caller supplied dates for ride along — the index cannot know about them.
|
|
505
|
+
const span = candidateSpan(input.at, this.tunables);
|
|
506
|
+
const ids = new Set<string>(
|
|
507
|
+
span === null ? [] : this.store.datedMemories(span.from, span.to).map((d) => d.id),
|
|
508
|
+
);
|
|
509
|
+
for (const id of input.extraDates?.keys() ?? []) ids.add(id);
|
|
414
510
|
let considered = 0;
|
|
511
|
+
const order = new Map<string, readonly [number, number]>();
|
|
415
512
|
|
|
416
513
|
for (const id of ids) {
|
|
417
514
|
if (denied.has(id)) continue;
|
|
@@ -431,15 +528,19 @@ export class Prospective {
|
|
|
431
528
|
continue;
|
|
432
529
|
}
|
|
433
530
|
|
|
434
|
-
const rows = this.
|
|
531
|
+
const rows = this.firingRowsFor(id);
|
|
532
|
+
const mode = cueModeOf(loaded.doc);
|
|
533
|
+
// Read only for a plain item, and only once per memory per call.
|
|
534
|
+
const toldToday = mode === "plain" && this.plainToldOn(id, input.at);
|
|
435
535
|
for (const w of p.windows) {
|
|
436
536
|
const stateRow = rows.get(w.key);
|
|
437
|
-
const brake =
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
537
|
+
const brake =
|
|
538
|
+
this.brakeFor(w, stateRow, {
|
|
539
|
+
at: input.at,
|
|
540
|
+
day,
|
|
541
|
+
refractory: input.refractory === true,
|
|
542
|
+
sessionId: input.sessionId,
|
|
543
|
+
}) ?? (toldToday ? "told-plainly-today" : null);
|
|
443
544
|
if (brake !== null) {
|
|
444
545
|
suppressed.push({ memoryId: id, windowKey: w.key, reason: brake });
|
|
445
546
|
continue;
|
|
@@ -460,14 +561,26 @@ export class Prospective {
|
|
|
460
561
|
fires: stateRow?.fires ?? 0,
|
|
461
562
|
lastFiredDay: stateRow?.last_fired_day ?? null,
|
|
462
563
|
strength: loaded.strength,
|
|
564
|
+
mode,
|
|
463
565
|
});
|
|
566
|
+
order.set(`${id} ${w.key}`, imminence(w, input.at));
|
|
464
567
|
}
|
|
465
568
|
}
|
|
466
569
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
)
|
|
570
|
+
// Salience-weighted ramp first; a TIE goes to the more imminent window —
|
|
571
|
+
// sooner, then narrower — so "today" beats "sometime this month" at equal
|
|
572
|
+
// salience (tune question d); then the key, so the order is total.
|
|
573
|
+
const soon = (a: Arrival): readonly [number, number] =>
|
|
574
|
+
order.get(`${a.memoryId} ${a.windowKey}`) ?? [0, 0];
|
|
575
|
+
arrivals.sort((a, b) => {
|
|
576
|
+
const d = b.ramp * b.strength - a.ramp * a.strength;
|
|
577
|
+
if (Math.abs(d) > TIE) return d;
|
|
578
|
+
const [au, aw] = soon(a);
|
|
579
|
+
const [bu, bw] = soon(b);
|
|
580
|
+
if (au !== bu) return au - bu;
|
|
581
|
+
if (aw !== bw) return aw - bw;
|
|
582
|
+
return a.windowKey < b.windowKey ? -1 : a.windowKey > b.windowKey ? 1 : a.memoryId < b.memoryId ? -1 : 1;
|
|
583
|
+
});
|
|
471
584
|
|
|
472
585
|
for (const s of suppressed) {
|
|
473
586
|
// A window that has not opened yet was NEVER ASKED, which is a different
|
|
@@ -513,7 +626,14 @@ export class Prospective {
|
|
|
513
626
|
considered,
|
|
514
627
|
};
|
|
515
628
|
}
|
|
516
|
-
|
|
629
|
+
// Tune question (c), 2026-09-26 — the owner's human-memory framing: people
|
|
630
|
+
// date-fire DAY-precision things (trash day, a defense tomorrow). A month
|
|
631
|
+
// or a range lives as footnote warmth and context corroboration only; it
|
|
632
|
+
// still arrives as a cue every day of its window, it just never takes a
|
|
633
|
+
// wake line.
|
|
634
|
+
const items = considered.arrivals
|
|
635
|
+
.filter((a) => a.precision === "day")
|
|
636
|
+
.slice(0, this.tunables.HORIZON_ITEMS);
|
|
517
637
|
const reason: HorizonReason = items.length === 0 ? "nothing-arrived" : "selected";
|
|
518
638
|
this.emit("prospective.horizon", undefined, {
|
|
519
639
|
reason,
|
|
@@ -524,6 +644,174 @@ export class Prospective {
|
|
|
524
644
|
return { items, reason, suppressedWholesale: false, considered };
|
|
525
645
|
}
|
|
526
646
|
|
|
647
|
+
// ── plain items: the one exception to "a cue, not a command" ──────────────
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* PLAIN items due to be told today, not yet told (owner decision 2026-09-25/26,
|
|
651
|
+
* a working default — CONTRACT §3 names it as the deliberate exception to "no
|
|
652
|
+
* bypass lane"). A person who said "don't let me forget to pay taxes before Oct
|
|
653
|
+
* 15th!" asked to be told, and a footnote the model may or may not raise is not
|
|
654
|
+
* telling them.
|
|
655
|
+
*
|
|
656
|
+
* SPARING, by construction — at most two beats per window, each once ever:
|
|
657
|
+
*
|
|
658
|
+
* - a DAY item on its day (`day`);
|
|
659
|
+
* - a MONTH or RANGE item the first day it is open and seen (`opens`), and
|
|
660
|
+
* again on the last day it names (`last-day`) — the deadline end of
|
|
661
|
+
* "before the 15th". Seen first ON its last day, it gets that beat only.
|
|
662
|
+
*
|
|
663
|
+
* Only the stated span counts — no lead days, no grace: "on the day" is what
|
|
664
|
+
* was asked. A YEAR has no day it could mean, so it is never told (the same
|
|
665
|
+
* structural exclusion as a window, §12 G3).
|
|
666
|
+
*
|
|
667
|
+
* It does NOT run the eligibility predicate. The salience floor is the tact
|
|
668
|
+
* principle's gate on UNASKED surfacing; this is asked-for, and an ordinary
|
|
669
|
+
* note sits at the authored default (0.25) under a 0.6 floor, so gating here
|
|
670
|
+
* would make a plain reminder dead for most notes. What still refuses: an
|
|
671
|
+
* archived, superseded, removed or journal row, and an observer.
|
|
672
|
+
*
|
|
673
|
+
* A read — `claimPlain` is the write, and the caller shows a line only for a
|
|
674
|
+
* claim that landed. Records only; the words are the adapter's.
|
|
675
|
+
*/
|
|
676
|
+
plainDue(input: { at: string }): PlainDue[] {
|
|
677
|
+
if (this.observer || !isDay(input.at)) return [];
|
|
678
|
+
const at = input.at;
|
|
679
|
+
const denied = new Set(this.store.deniedIds());
|
|
680
|
+
const out: PlainDue[] = [];
|
|
681
|
+
for (const dated of this.store.datedMemories(at, at)) {
|
|
682
|
+
const id = dated.id;
|
|
683
|
+
if (denied.has(id)) continue;
|
|
684
|
+
const row = this.store.row(id);
|
|
685
|
+
if (row === undefined || row.superseded_by !== null) continue;
|
|
686
|
+
let doc: ProseDoc;
|
|
687
|
+
try {
|
|
688
|
+
doc = this.store.read(id).doc;
|
|
689
|
+
} catch {
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
if (doc.type === "episode" || cueModeOf(doc) !== "plain") continue;
|
|
693
|
+
const precision = precisionOf(dated.eventDate);
|
|
694
|
+
if (precision === null || precision === "year") continue;
|
|
695
|
+
const w = windowFor(dated.eventDate, precision, this.tunables, id);
|
|
696
|
+
if (w === null || at < w.firstDay || at > w.lastDay) continue;
|
|
697
|
+
const beat: PlainBeat =
|
|
698
|
+
w.precision === "day" ? "day" : at === w.lastDay ? "last-day" : "opens";
|
|
699
|
+
if (this.plainTold(id, w.key, beat)) continue;
|
|
700
|
+
out.push({
|
|
701
|
+
memoryId: id,
|
|
702
|
+
windowKey: w.key,
|
|
703
|
+
eventDate: w.eventDate,
|
|
704
|
+
precision: w.precision,
|
|
705
|
+
beat,
|
|
706
|
+
firstDay: w.firstDay,
|
|
707
|
+
lastDay: w.lastDay,
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
return out;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Mark one plain beat as told. TRUE only when this call wrote the mark: the
|
|
715
|
+
* `dedupKey` latch is the whole lock, so two hook processes racing for the
|
|
716
|
+
* same beat cannot both win, and the caller shows the line only on true —
|
|
717
|
+
* the update notice's "mark first, show only if marked" (roadmap E). An
|
|
718
|
+
* observer marks nothing and is therefore told nothing.
|
|
719
|
+
*/
|
|
720
|
+
claimPlain(due: PlainDue, opts: { at: string; day?: number }): boolean {
|
|
721
|
+
if (this.observer) return false;
|
|
722
|
+
const day = opts.day ?? this.store.livedDay();
|
|
723
|
+
try {
|
|
724
|
+
const seq = this.store.appendEvent({
|
|
725
|
+
name: PROSPECTIVE_PLAIN_EVENT,
|
|
726
|
+
day,
|
|
727
|
+
ref: due.memoryId,
|
|
728
|
+
payload: { window: due.windowKey, beat: due.beat, precision: due.precision, date: opts.at, mode: "plain" },
|
|
729
|
+
dedupKey: `${PROSPECTIVE_PLAIN_EVENT}:${due.memoryId}:${due.windowKey}:${due.beat}`,
|
|
730
|
+
});
|
|
731
|
+
if (seq > 0) {
|
|
732
|
+
this.emit("prospective.plain", due.memoryId, { window: due.windowKey, beat: due.beat, day });
|
|
733
|
+
}
|
|
734
|
+
return seq > 0;
|
|
735
|
+
} catch {
|
|
736
|
+
// A lost mark costs this line, never the turn (§12 G12's budget).
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** Has this beat already been told? A read of the latch `claimPlain` writes,
|
|
742
|
+
* so a turn with nothing new to say takes no write lock at all. */
|
|
743
|
+
private plainTold(memoryId: string, windowKey: string, beat: PlainBeat): boolean {
|
|
744
|
+
// The memories this reminder moved through count too: a beat told on the
|
|
745
|
+
// row a revision took the reminder from was TOLD (`DATE_FROM_META`).
|
|
746
|
+
for (const id of this.lineage(memoryId)) {
|
|
747
|
+
for (const e of this.plainRows(id)) {
|
|
748
|
+
if (e.dedup_key === `${PROSPECTIVE_PLAIN_EVENT}:${id}:${windowKey}:${beat}`) return true;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** Was this memory — or one its reminder moved from — told plainly on the calendar day `at`? */
|
|
755
|
+
private plainToldOn(memoryId: string, at: string): boolean {
|
|
756
|
+
for (const id of this.lineage(memoryId)) {
|
|
757
|
+
for (const e of this.plainRows(id)) {
|
|
758
|
+
try {
|
|
759
|
+
if ((JSON.parse(e.payload ?? "{}") as { date?: unknown }).date === at) return true;
|
|
760
|
+
} catch {
|
|
761
|
+
/* an unreadable row answers nothing */
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* The memory, then each one its reminder moved from, newest first — read off
|
|
770
|
+
* `meta.reminderFrom`, bounded, cycle-safe. A row that is gone or whose meta
|
|
771
|
+
* will not parse ends the walk: losing it costs at most one extra mention
|
|
772
|
+
* (§12 G12), never a memory.
|
|
773
|
+
*/
|
|
774
|
+
private lineage(memoryId: string): string[] {
|
|
775
|
+
const out = [memoryId];
|
|
776
|
+
let current = memoryId;
|
|
777
|
+
for (let hop = 0; hop < DATE_LINEAGE_MAX; hop++) {
|
|
778
|
+
const raw = this.store.row(current)?.meta;
|
|
779
|
+
if (raw === undefined) break;
|
|
780
|
+
let from: unknown;
|
|
781
|
+
try {
|
|
782
|
+
from = (JSON.parse(raw) as Record<string, unknown>)[DATE_FROM_META];
|
|
783
|
+
} catch {
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
if (typeof from !== "string" || out.includes(from)) break;
|
|
787
|
+
out.push(from);
|
|
788
|
+
current = from;
|
|
789
|
+
}
|
|
790
|
+
return out;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The firing-state rows the brakes read: this memory's own, and — for a
|
|
795
|
+
* window it has no row for yet — the row of the nearest memory its reminder
|
|
796
|
+
* moved from, for the SAME window key. So a moved reminder keeps its spent
|
|
797
|
+
* budget, its last-fired day and a referenced stop; a rescheduled one (a new
|
|
798
|
+
* date, so a new key) starts fresh, exactly as `reschedule` does (§12 G9).
|
|
799
|
+
* The first fire writes the successor's own row from there.
|
|
800
|
+
*/
|
|
801
|
+
private firingRowsFor(memoryId: string): Map<string, ProspectiveRow> {
|
|
802
|
+
const out = this.rowsFor(memoryId);
|
|
803
|
+
for (const id of this.lineage(memoryId).slice(1)) {
|
|
804
|
+
for (const [key, row] of this.rowsFor(id)) if (!out.has(key)) out.set(key, row);
|
|
805
|
+
}
|
|
806
|
+
return out;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/** A memory's plain rows, newest first. At most two beats per window, so a
|
|
810
|
+
* small bound is every row a live memory will ever have. */
|
|
811
|
+
private plainRows(memoryId: string): { dedup_key: string | null; payload: string | null }[] {
|
|
812
|
+
return this.store.eventLog({ name: PROSPECTIVE_PLAIN_EVENT, ref: memoryId, order: "desc", limit: 50 });
|
|
813
|
+
}
|
|
814
|
+
|
|
527
815
|
// ── firing-state transitions (all refuse under observer) ──────────────────
|
|
528
816
|
|
|
529
817
|
/**
|
|
@@ -586,7 +874,7 @@ export class Prospective {
|
|
|
586
874
|
return { fired: false, reason: "not-eligible", derivation: p.reason, fires: 0, state: "armed" };
|
|
587
875
|
}
|
|
588
876
|
const w = p.windows.find((x) => x.key === input.windowKey);
|
|
589
|
-
const rows = this.
|
|
877
|
+
const rows = this.firingRowsFor(input.memoryId);
|
|
590
878
|
const row = rows.get(input.windowKey);
|
|
591
879
|
if (w === undefined) {
|
|
592
880
|
this.emit("prospective.fire.refused", input.memoryId, {
|
|
@@ -650,6 +938,13 @@ export class Prospective {
|
|
|
650
938
|
precision: w.precision,
|
|
651
939
|
fires,
|
|
652
940
|
cap: this.tunables.FIRES_PER_WINDOW,
|
|
941
|
+
// Plain or quiet, so the gauge can count the two apart (2026-09-26).
|
|
942
|
+
mode: cueModeOf(loaded.doc),
|
|
943
|
+
// The calendar day the fire was ABOUT, as the plain row carries it: the
|
|
944
|
+
// fired view dates a row by this field before the wall clock, so a fire
|
|
945
|
+
// near midnight or far from UTC is counted on the day it was asked
|
|
946
|
+
// (2026-09-26 review — the gauge test failed in Pacific/Auckland).
|
|
947
|
+
date: input.at,
|
|
653
948
|
});
|
|
654
949
|
return { fired: true, reason: "fired", derivation: null, fires, state: "fired" };
|
|
655
950
|
}
|
|
@@ -759,7 +1054,9 @@ export class Prospective {
|
|
|
759
1054
|
}
|
|
760
1055
|
const nextPrecision = precisionOf(input.nextDate);
|
|
761
1056
|
const nextWindow =
|
|
762
|
-
nextPrecision === null
|
|
1057
|
+
nextPrecision === null
|
|
1058
|
+
? null
|
|
1059
|
+
: windowFor(input.nextDate, nextPrecision, this.tunables, input.memoryId);
|
|
763
1060
|
if (nextWindow === null) {
|
|
764
1061
|
this.emit("prospective.reschedule.refused", input.memoryId, { reason: "malformed-date" });
|
|
765
1062
|
return { rescheduled: false, reason: "malformed-date", retiredKey: null, armedKey: null };
|
|
@@ -826,7 +1123,14 @@ export class Prospective {
|
|
|
826
1123
|
const exits: Exit[] = [];
|
|
827
1124
|
const counts = Object.fromEntries(EXIT_KINDS.map((k) => [k, 0])) as Record<ExitKind, number>;
|
|
828
1125
|
|
|
829
|
-
|
|
1126
|
+
// Every memory that has a date (archived ones included — archived before its
|
|
1127
|
+
// window is the `faded` exit) and every memory that has a firing row (a row
|
|
1128
|
+
// can outlive a cleared date). Two indexed reads, not a scan of the store.
|
|
1129
|
+
const ids = new Set<string>(
|
|
1130
|
+
this.store.datedMemories("0001-01-01", "9999-12-31", { archived: true }).map((m) => m.id),
|
|
1131
|
+
);
|
|
1132
|
+
for (const id of this.store.prospectiveMemoryIds()) ids.add(id);
|
|
1133
|
+
for (const id of [...ids].sort()) {
|
|
830
1134
|
const loaded = this.load(id, [], d);
|
|
831
1135
|
if (loaded === null) continue;
|
|
832
1136
|
const p = derive(loaded.memory, loaded.dates, at, this.tunables);
|
|
@@ -836,7 +1140,8 @@ export class Prospective {
|
|
|
836
1140
|
for (const key of rows.keys()) {
|
|
837
1141
|
if (byKey.has(key)) continue;
|
|
838
1142
|
const parsed = parseWindowKey(key);
|
|
839
|
-
const w =
|
|
1143
|
+
const w =
|
|
1144
|
+
parsed === null ? null : windowFor(parsed.eventDate, parsed.precision, this.tunables, id);
|
|
840
1145
|
byKey.set(key, { window: w, phase: w === null ? null : phaseOf(w, at) });
|
|
841
1146
|
}
|
|
842
1147
|
|
|
@@ -898,6 +1203,18 @@ export class Prospective {
|
|
|
898
1203
|
if (row.last_fired_day !== null && row.last_fired_day === ctx.day) {
|
|
899
1204
|
return "already-fired-today";
|
|
900
1205
|
}
|
|
1206
|
+
// Tune question (b): the last fire of a month or range waits for after
|
|
1207
|
+
// the span it names. Without it, a month item spent its whole budget in
|
|
1208
|
+
// its first days and never knew when "after" was.
|
|
1209
|
+
if (
|
|
1210
|
+
this.tunables.HOLD_LAST_FIRE_FOR_AFTER &&
|
|
1211
|
+
w.precision !== "day" &&
|
|
1212
|
+
this.tunables.FIRES_PER_WINDOW >= 2 &&
|
|
1213
|
+
row.fires >= this.tunables.FIRES_PER_WINDOW - 1 &&
|
|
1214
|
+
ctx.at <= w.lastDay
|
|
1215
|
+
) {
|
|
1216
|
+
return "held-for-after";
|
|
1217
|
+
}
|
|
901
1218
|
}
|
|
902
1219
|
if (ctx.sessionId !== undefined && this.sessionFired.get(ctx.sessionId)?.has(w.key) === true) {
|
|
903
1220
|
return "session-dedup";
|
|
@@ -917,8 +1234,10 @@ export class Prospective {
|
|
|
917
1234
|
// A removed memory is not an error here; it simply has no future.
|
|
918
1235
|
return null;
|
|
919
1236
|
}
|
|
920
|
-
const
|
|
1237
|
+
const explicit = contentDates(read.doc);
|
|
1238
|
+
const dates = [...explicit, ...extra];
|
|
921
1239
|
const seen = new Set<string>();
|
|
1240
|
+
const s = strength(read.physics, day);
|
|
922
1241
|
return {
|
|
923
1242
|
memory: {
|
|
924
1243
|
id: memoryId,
|
|
@@ -929,10 +1248,14 @@ export class Prospective {
|
|
|
929
1248
|
// The same field `sleep/types.ts#isJournal` reads off the row, taken
|
|
930
1249
|
// from the doc already in hand. See `DerivableMemory.journal`.
|
|
931
1250
|
journal: read.doc.type === "episode",
|
|
1251
|
+
// The owner's rule (2026-09-26): an author-written date is its own
|
|
1252
|
+
// importance signal, so it skips the salience floor — never decay.
|
|
1253
|
+
explicitDate: explicit.length > 0,
|
|
1254
|
+
faded: s <= this.tunables.FADED_STRENGTH,
|
|
932
1255
|
},
|
|
933
1256
|
doc: read.doc,
|
|
934
1257
|
dates: dates.filter((d) => (seen.has(d.date) ? false : (seen.add(d.date), true))),
|
|
935
|
-
strength:
|
|
1258
|
+
strength: s,
|
|
936
1259
|
};
|
|
937
1260
|
}
|
|
938
1261
|
|
|
@@ -20,7 +20,10 @@ export interface ProspectiveTunables {
|
|
|
20
20
|
/** Salience below this never becomes prospective, however well dated.
|
|
21
21
|
* Salience, NOT strength: eligibility is a predicate over the event date, the
|
|
22
22
|
* encode date, salience and flags (§12 G2), and a decay exemption before
|
|
23
|
-
* arrival is exactly what G10 forbids. [v1: 0.6] CAL.
|
|
23
|
+
* arrival is exactly what G10 forbids. [v1: 0.6] CAL.
|
|
24
|
+
* Since 2026-09-26 (owner decision) it gates only a date a CALLER extracted:
|
|
25
|
+
* a memory with an explicit `eventDate` is exempt, because choosing a date
|
|
26
|
+
* is itself the importance signal. Decay (`FADED_STRENGTH`) still holds. */
|
|
24
27
|
SALIENCE_FLOOR: number;
|
|
25
28
|
/** Calendar days before the event the window opens. [v1: 3] CAL. */
|
|
26
29
|
LEAD_DAYS: number;
|
|
@@ -46,6 +49,18 @@ export interface ProspectiveTunables {
|
|
|
46
49
|
FADED_STRENGTH: number;
|
|
47
50
|
/** Bound on the in-process session-dedup set (INTERFACE-GAPS #3). */
|
|
48
51
|
MAX_SESSION_WINDOWS: number;
|
|
52
|
+
/** Tune question (a), 2026-09-26: a month-dated memory peaks on the 1st plus a
|
|
53
|
+
* stable per-memory offset of `0..N-1` days, so a month-heavy store does not
|
|
54
|
+
* warm everything on day 1. 0 or 1 turns the stagger off. CAL — v1 measured
|
|
55
|
+
* the clustering, never a spread; seven is "the first week". */
|
|
56
|
+
MONTH_STAGGER_DAYS: number;
|
|
57
|
+
/** Tune question (b), 2026-09-26: a month or range window keeps its LAST fire
|
|
58
|
+
* for after the span it names — the "after" beat a month item never got in
|
|
59
|
+
* v1 (Rosa's post-surgery check-in). Only meaningful with
|
|
60
|
+
* `FIRES_PER_WINDOW >= 2`; with one fire it would never fire, so it is
|
|
61
|
+
* ignored there. Structural in shape, CAL in whether it is warm (open
|
|
62
|
+
* question 1). */
|
|
63
|
+
HOLD_LAST_FIRE_FOR_AFTER: boolean;
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
/**
|
|
@@ -65,6 +80,8 @@ export const TUNABLES: ProspectiveTunables = {
|
|
|
65
80
|
RAMP_CLOSE: 0.2,
|
|
66
81
|
FADED_STRENGTH: PHYSICS.PHI_PRUNE,
|
|
67
82
|
MAX_SESSION_WINDOWS: 200,
|
|
83
|
+
MONTH_STAGGER_DAYS: 7,
|
|
84
|
+
HOLD_LAST_FIRE_FOR_AFTER: true,
|
|
68
85
|
};
|
|
69
86
|
|
|
70
87
|
export function withTunables(overrides: Partial<ProspectiveTunables> = {}): ProspectiveTunables {
|