counterparts 0.3.1 → 0.3.2
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 +49 -1
- package/docs/module-map.md +2 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/NOTES.md +32 -0
- package/src/adapters/claude-code/bin/hook.ts +15 -2
- package/src/adapters/claude-code/bin/runner.ts +3 -1
- package/src/adapters/claude-code/config.ts +23 -0
- package/src/adapters/claude-code/doctor.ts +39 -20
- package/src/adapters/claude-code/hooks.ts +32 -12
- package/src/adapters/claude-code/index.ts +1 -0
- package/src/adapters/cli/commands.ts +178 -59
- package/src/adapters/cli/export.ts +27 -3
- package/src/adapters/cli/help.ts +22 -8
- package/src/adapters/cli/install.ts +3 -5
- package/src/adapters/cli/mechanisms.ts +295 -0
- package/src/adapters/cli/repair-dates.ts +3 -1
- package/src/adapters/dashboard/CONTRACT.md +13 -9
- package/src/adapters/dashboard/NOTES.md +3 -2
- package/src/adapters/dashboard/activity.ts +2 -1
- package/src/adapters/dashboard/bin/dashboard.ts +18 -3
- package/src/adapters/dashboard/upgrade.ts +23 -0
- package/src/adapters/dashboard/web/README.md +153 -0
- package/src/adapters/dashboard/web/actions.ts +631 -0
- package/src/adapters/dashboard/web/app.html +40 -1703
- package/src/adapters/dashboard/web/app.js +55 -0
- package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
- package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
- package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
- package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
- package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
- package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
- package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
- package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
- package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
- package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
- package/src/adapters/dashboard/web/narrate.ts +10 -10
- package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
- package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
- package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
- package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
- package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
- package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
- package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
- package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
- package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
- package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
- package/src/adapters/dashboard/web/pages/health/health.css +93 -0
- package/src/adapters/dashboard/web/pages/health/index.js +41 -0
- package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
- package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
- package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
- package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
- package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
- package/src/adapters/dashboard/web/pages/home/home.css +134 -0
- package/src/adapters/dashboard/web/pages/home/index.js +84 -0
- package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
- package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
- package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
- package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
- package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
- package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
- package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
- package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
- package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
- package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
- package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
- package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
- package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
- package/src/adapters/dashboard/web/pages/self/index.js +43 -0
- package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
- package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
- package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
- package/src/adapters/dashboard/web/pages/self/self.css +182 -0
- package/src/adapters/dashboard/web/server.ts +305 -28
- package/src/adapters/dashboard/web/shared/absence.js +14 -0
- package/src/adapters/dashboard/web/shared/actions.js +48 -0
- package/src/adapters/dashboard/web/shared/api.js +17 -0
- package/src/adapters/dashboard/web/shared/base.css +34 -0
- package/src/adapters/dashboard/web/shared/canvas.js +68 -0
- package/src/adapters/dashboard/web/shared/colors.js +6 -0
- package/src/adapters/dashboard/web/shared/dom.js +4 -0
- package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
- package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
- package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
- package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
- package/src/adapters/dashboard/web/shared/format.js +31 -0
- package/src/adapters/dashboard/web/shared/layout.css +32 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
- package/src/adapters/dashboard/web/shared/modal.css +24 -0
- package/src/adapters/dashboard/web/shared/modal.js +22 -0
- package/src/adapters/dashboard/web/shared/state.js +12 -0
- package/src/adapters/dashboard/web/shared/tip.css +4 -0
- package/src/adapters/dashboard/web/shared/tip.js +12 -0
- package/src/adapters/dashboard/web/shared/tokens.css +50 -0
- package/src/adapters/dashboard/web/shared/type.css +52 -0
- package/src/adapters/dashboard/web/shared/utilities.css +5 -0
- package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
- package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
- package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
- package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
- package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
- package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
- package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
- package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
- package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
- package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
- package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
- package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
- package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
- package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
- package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
- package/src/adapters/dashboard/web/shell/pages.js +15 -0
- package/src/adapters/dashboard/web/shell/pulse.js +86 -0
- package/src/adapters/dashboard/web/shell/tabs.js +49 -0
- package/src/adapters/dashboard/web/static.ts +76 -0
- package/src/adapters/dashboard/web/views/activity.ts +80 -0
- package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
- package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
- package/src/adapters/dashboard/web/views/health.ts +328 -0
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
- package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
- package/src/adapters/dashboard/web/views/memories.ts +342 -0
- package/src/adapters/dashboard/web/views/memory.ts +210 -0
- package/src/adapters/dashboard/web/views/meta.ts +64 -0
- package/src/adapters/dashboard/web/views/mind.ts +729 -0
- package/src/adapters/dashboard/web/views/overview.ts +282 -0
- package/src/adapters/dashboard/web/views/pulse.ts +19 -0
- package/src/adapters/dashboard/web/views/rows.ts +207 -0
- package/src/adapters/dashboard/web/views/search.ts +62 -0
- package/src/adapters/dashboard/web/views/shared.ts +161 -0
- package/src/adapters/dashboard/web/views.ts +34 -1724
- package/src/adapters/fired.ts +28 -17
- package/src/adapters/mcp/NOTES.md +43 -0
- package/src/adapters/mcp/bin/serve.ts +5 -1
- package/src/adapters/mcp/index.ts +3 -0
- package/src/adapters/mcp/server.ts +163 -6
- package/src/adapters/mcp/tools.ts +42 -0
- package/src/adapters/mcp/write-up.ts +1 -1
- package/src/core/counterpart.ts +30 -1
- package/src/core/feelings-wheel.ts +218 -0
- package/src/core/mint.ts +14 -2
- package/src/core/prospective/INTERFACE-GAPS.md +10 -0
- package/src/core/prospective/windows.ts +10 -48
- package/src/core/self/NOTES.md +17 -0
- package/src/core/self/calendar.ts +7 -78
- package/src/core/self/episodes.ts +7 -8
- package/src/core/self/index.ts +32 -11
- package/src/core/self/writer.ts +22 -22
- package/src/core/sleep/cycle.ts +8 -2
- package/src/core/store/CONTRACT.md +26 -7
- package/src/core/store/NOTES.md +142 -0
- package/src/core/store/errors.ts +15 -0
- package/src/core/store/feelings.ts +182 -0
- package/src/core/store/index.ts +297 -45
- package/src/core/store/operational.ts +133 -11
- package/src/core/store/owner-op-seam.ts +13 -3
- package/src/core/store/pre-migration.ts +3 -1
- package/src/core/store/prose.ts +8 -1
- package/src/core/store/render.ts +3 -0
- package/src/core/time.ts +374 -0
- package/src/core/types.ts +13 -0
- package/src/adapters/dashboard/web/brain.html +0 -463
package/src/core/self/writer.ts
CHANGED
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
*
|
|
35
35
|
* The calendar date in the machine's LOCAL zone (owner's ruling 2026-09-23;
|
|
36
36
|
* `Self#calendarToday`): the night turns over at the person's midnight, not at
|
|
37
|
-
* 17:00 Pacific. What it READS is
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
37
|
+
* 17:00 Pacific. What it READS is selected by `learned_on`, which `store/`
|
|
38
|
+
* stamped in UTC until 2026-09-25 and stamps in the same local zone since
|
|
39
|
+
* (docs/time.md) — so from then on the day it names and the rows it is handed
|
|
40
|
+
* are one calendar. Rows written before keep their UTC date, and for the few
|
|
41
|
+
* nights either side of the change a row may be read one night early or late,
|
|
42
|
+
* never twice or not at all (self NOTES §25).
|
|
43
43
|
*
|
|
44
44
|
* ── DAY 0 ─────────────────────────────────────────────────────────────────
|
|
45
45
|
*
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
import { strength } from "../physics/index.js";
|
|
78
78
|
import type { Store } from "../store/index.js";
|
|
79
79
|
import { calendarDate } from "./calendar.js";
|
|
80
|
+
import { addDays, isDay } from "../time.js";
|
|
80
81
|
import { PAGE_CORE_HEADING, PAGE_LATELY_HEADING } from "./page.js";
|
|
81
82
|
import type { SelfPage } from "./page.js";
|
|
82
83
|
import type { SelfTunables } from "./tunables.js";
|
|
@@ -174,9 +175,8 @@ export interface PageWriterStatus {
|
|
|
174
175
|
|
|
175
176
|
/** The calendar date `n` days before `date`, both `YYYY-MM-DD`. "" when unreadable. */
|
|
176
177
|
export function dayBefore(date: string, n = 1): string {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
return new Date(at - n * 86_400_000).toISOString().slice(0, 10);
|
|
178
|
+
const d = date.trim();
|
|
179
|
+
return isDay(d) ? addDays(d, -n) : "";
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
@@ -191,12 +191,12 @@ export function dayBefore(date: string, n = 1): string {
|
|
|
191
191
|
export function pageWriterAbout(today: string, closedThrough?: string): string {
|
|
192
192
|
const local = dayBefore(today);
|
|
193
193
|
// NEVER A DAY THE STORE IS STILL FILING UNDER. `closedThrough` is the newest
|
|
194
|
-
// PROVENANCE date that has ended
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
//
|
|
194
|
+
// PROVENANCE date that has ended. While `learned_on` was UTC (until
|
|
195
|
+
// 2026-09-25) this held an east-of-UTC night back until the UTC date closed
|
|
196
|
+
// (self NOTES §22). Since `learned_on` is stamped in the store's zone,
|
|
197
|
+
// `pageWriterNight` passes the store's own yesterday, which in one zone IS
|
|
198
|
+
// the local yesterday, so this is the plain rule; it still guards a caller
|
|
199
|
+
// whose `Self` zone was pinned apart from the store's (self NOTES §25).
|
|
200
200
|
if (closedThrough === undefined || closedThrough === "" || local === "") return local;
|
|
201
201
|
return closedThrough < local ? closedThrough : local;
|
|
202
202
|
}
|
|
@@ -209,7 +209,7 @@ export function pageWriterAbout(today: string, closedThrough?: string): string {
|
|
|
209
209
|
* is the whole reason it exists.
|
|
210
210
|
*/
|
|
211
211
|
export function pageWriterNight(store: Store, zone?: string): { today: string; about: string } {
|
|
212
|
-
const today = calendarDate(store.now(), zone);
|
|
212
|
+
const today = calendarDate(store.now(), zone ?? store.zone());
|
|
213
213
|
return { today, about: pageWriterAbout(today, dayBefore(store.today())) };
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -675,12 +675,12 @@ export function writerInstruction(
|
|
|
675
675
|
lines.push(
|
|
676
676
|
`Once a day the page you wake with gets revised — by you, from the day just lived. This is that moment, and the day is ${input.about}.`,
|
|
677
677
|
"",
|
|
678
|
-
// THE DATE, NOT "YESTERDAY" OR "LAST NIGHT". The night
|
|
679
|
-
// local midnight (2026-09-23),
|
|
680
|
-
//
|
|
681
|
-
// window is offset from the person's day by the zone
|
|
682
|
-
//
|
|
683
|
-
//
|
|
678
|
+
// THE DATE, NOT "YESTERDAY" OR "LAST NIGHT". The night turns over at
|
|
679
|
+
// local midnight (2026-09-23), and the memories under that date are the
|
|
680
|
+
// ones `learned_on` filed under it — UTC before 2026-09-25, local since —
|
|
681
|
+
// so for older rows the window is offset from the person's day by the zone
|
|
682
|
+
// (self NOTES §22, §25). A date is the one thing here that is exactly
|
|
683
|
+
// true, so the words stay a date.
|
|
684
684
|
`This is context, not an instruction. If nothing about who you are moved on ${input.about}, leaving the page exactly as it stands is the right answer and is recorded as one. Do not write a diary entry here; the journal already has that day.`,
|
|
685
685
|
"",
|
|
686
686
|
`If something did move, call the \`${opts.tool}\` tool with the WHOLE page: \`## ${PAGE_CORE_HEADING}\` for what holds steady — it may honestly say it is still forming — and \`## ${PAGE_LATELY_HEADING}\` for what the last while has actually been like. Amend it; do not start over. You are the same person continuing, so keep every sentence that still holds and change the part that moved.${session}`,
|
package/src/core/sleep/cycle.ts
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import type { Kind } from "../types.js";
|
|
31
|
+
import { todayIn } from "../time.js";
|
|
31
32
|
import { TUNABLES as PHYSICS, symmetryCheck } from "../physics/index.js";
|
|
32
33
|
import { runBriefing } from "./briefing.js";
|
|
33
34
|
import type { RenderFn } from "./briefing.js";
|
|
@@ -99,9 +100,14 @@ export interface SleepOptions {
|
|
|
99
100
|
|
|
100
101
|
const EVENT_RING = 500;
|
|
101
102
|
|
|
102
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Today's calendar date in the machine's zone — the fallback when a caller
|
|
105
|
+
* hands the cycle no date. UTC until 2026-09-25, local since (docs/time.md): the
|
|
106
|
+
* hooks' `at` moved the same day, and the two must stay one calendar. The
|
|
107
|
+
* lived-day mapping is the store's, not this module's.
|
|
108
|
+
*/
|
|
103
109
|
export function todayDate(): string {
|
|
104
|
-
return
|
|
110
|
+
return todayIn();
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
export function runCycle(opts: SleepOptions): CycleReport {
|
|
@@ -331,12 +331,14 @@ store property is the `VACUUM INTO`, and that is G19. The code's numbering wins.
|
|
|
331
331
|
database**. FILENAMES are the evidence deliberately: reading the schema version would
|
|
332
332
|
mean opening a WAL store whose `-wal` a close could checkpoint away, moving the bytes
|
|
333
333
|
the refusal exists to leave alone. All three names, because a store whose database was
|
|
334
|
-
moved by hand still holds every one of its words in files. `ADDED_COLUMNS`
|
|
335
|
-
|
|
336
|
-
anything below `SCHEMA_VERSION`, and `body`
|
|
337
|
-
while the words sat in files, stamping the
|
|
338
|
-
|
|
339
|
-
|
|
334
|
+
moved by hand still holds every one of its words in files. `ADDED_COLUMNS` may never
|
|
335
|
+
name a v6 column (it was empty at v6 and holds v7's eleven since 2026-09-25), which is
|
|
336
|
+
the second lock: `openOperational` migrates anything below `SCHEMA_VERSION`, and `body`
|
|
337
|
+
added that way would be NULL on every row while the words sat in files, stamping the
|
|
338
|
+
store current and unreadable by the build that can read it. `OBSERVER_READ_FLOOR` is
|
|
339
|
+
`SCHEMA_VERSION`: there is no floor below the current version, because every read names
|
|
340
|
+
the current columns and an instrument on an older store would report an empty or broken
|
|
341
|
+
store rather than one waiting for its upgrade.
|
|
340
342
|
There is no migration and there is not going to be one (owner ruling 6, 2026-09-18: the
|
|
341
343
|
cut-over carries nothing). `test/store-portable.test.ts` builds a real v5 store by hand
|
|
342
344
|
and proves the directory is byte-identical after a refused writer open, a refused
|
|
@@ -390,6 +392,23 @@ store property is the `VACUUM INTO`, and that is G19. The code's numbering wins.
|
|
|
390
392
|
version. A later open reuses a copy already taken for the same upgrade that day, or one
|
|
391
393
|
the live store has not been written since. Observers never migrate and never copy.
|
|
392
394
|
`NOTES.md` (2026-09-24) has the rollback steps.
|
|
395
|
+
21. **[M] Two kinds of time, one conversion module** (docs/time.md, 2026-09-25). A
|
|
396
|
+
MOMENT is UTC milliseconds from the injected clock (`store.now()`): `created_at` /
|
|
397
|
+
`updated_at` on `memories`, `edges` and `prospective`, a version's `created_at` and
|
|
398
|
+
`archived_at`, an event's `at`. A CALENDAR DATE a person said is text at its stated
|
|
399
|
+
precision — `happened_on`, and `event_date` (day, month, year or `a..b` range, refused
|
|
400
|
+
as `EVENT_DATE_INVALID` when `core/time.ts` cannot read it) — and is never turned into
|
|
401
|
+
a moment. A person's day (`today()`, a new row's `learned_on`, the day the store began)
|
|
402
|
+
is the local date of a moment in `zone()`: `StoreOptions.timeZone` when it names a real
|
|
403
|
+
zone, else the machine's current zone, resolved per call. Rows written before
|
|
404
|
+
2026-09-25 keep the UTC `learned_on` they were given. `datedMemories(from, to)` answers
|
|
405
|
+
which live rows carry an `event_date` overlapping a window, from an index.
|
|
406
|
+
22. **[M] Feelings are rows beside a memory, spelled on the wheel** (schema v7). A
|
|
407
|
+
`feelings` row names `whose`, one of six cores, a wheel emotion or `other` with the
|
|
408
|
+
word kept, a strength recorded once, and optionally the feeling on the same memory it
|
|
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. The owner's
|
|
411
|
+
removal deletes them with the memory. They move no physics.
|
|
393
412
|
|
|
394
413
|
## 6. Scars honored
|
|
395
414
|
|
|
@@ -412,7 +431,7 @@ Each line: the scar, what carries it on this floor, and where it is pinned.
|
|
|
412
431
|
| **I22** the copied-store bug | G15 — criterion kept, mechanism deleted | `test/store-portable.test.ts` "(a) `cp -R` the store, DESTROY the source outright, and the copy still reads its own words"; "(b) an owner removal run in the COPY leaves the SOURCE byte-identical"; "(d) a `backup` snapshot opens standalone and HOLDS THE WORDS after the source is gone" |
|
|
413
432
|
| **I38 / I39** "database is locked" | G18 | `test/store.test.ts` "busy_timeout is set FIRST, before every other pragma (I39)"; "a second handle WAITS for a held write lock instead of failing instantly"; "a WRITER converts the file to WAL; an INSTRUMENT opening a DELETE store leaves it alone" |
|
|
414
433
|
| **the stage→commit→rename crash window** (`NOTES.md` §5, deleted): a crash never leaves a row whose words are missing | G5, G6 — structurally true: the words commit with the row | `test/store.test.ts` "SIGKILL mid-write leaves the store readable, every row's words intact" |
|
|
415
|
-
| **the floor's own hazard**: migrate-at-open would have destroyed the pre-rows store | G16 | `test/store-portable.test.ts` "a WRITER open throws STORE_PRE_ROWS and the directory is byte-identical afterwards"; "an OBSERVER open, and a whole session, meet the same refusal and write nothing"; "ADDED_COLUMNS
|
|
434
|
+
| **the floor's own hazard**: migrate-at-open would have destroyed the pre-rows store | G16 | `test/store-portable.test.ts` "a WRITER open throws STORE_PRE_ROWS and the directory is byte-identical afterwards"; "an OBSERVER open, and a whole session, meet the same refusal and write nothing"; "ADDED_COLUMNS may never name a column the floor introduced" |
|
|
416
435
|
|
|
417
436
|
**Scars that no longer apply**, named so nobody re-ports them: temp-file naming (§16 G4's
|
|
418
437
|
"a crash-leaked stage must not load as a duplicate" — there is no stage), the
|
package/src/core/store/NOTES.md
CHANGED
|
@@ -1438,3 +1438,145 @@ rebuilds, and a cache the newer build stamped would make the old MCP server refu
|
|
|
1438
1438
|
tool. Copy the pre-migration copy's `counterparts.sqlite` into the store directory and run
|
|
1439
1439
|
the build that matches its `v<from>` (the newer build would migrate it again). Rows
|
|
1440
1440
|
written since the upgrade are lost; they are not in the copy.
|
|
1441
|
+
|
|
1442
|
+
## 2026-09-25 — schema v7: moments, the model, a reminder date, and the person's day
|
|
1443
|
+
|
|
1444
|
+
docs/time.md (agreed with the owner that day) is the plan; this is what the store did
|
|
1445
|
+
about it. `core/time.ts` is the one conversion module; the store imports it and converts
|
|
1446
|
+
nothing by hand.
|
|
1447
|
+
|
|
1448
|
+
**The migration.** The first additive one since the copy seam (#214) shipped: eleven
|
|
1449
|
+
nullable columns through `ADDED_COLUMNS`, one partial index after them
|
|
1450
|
+
(`DDL_AFTER_COLUMNS`, because on a v6 file the column does not exist yet while `DDL`
|
|
1451
|
+
runs). `OBSERVER_READ_FLOOR` moved to 7 with it, so an instrument (doctor, the
|
|
1452
|
+
dashboard, `status`) meets a v6 store as `STORE_UNINITIALIZED` until the next hook — a
|
|
1453
|
+
writer — takes the copy and migrates; doctor already grades that amber ("the next session
|
|
1454
|
+
upgrades it"). Measured on a store seeded by the 0.3.1 checkout (b66a736): doctor amber
|
|
1455
|
+
before, one `…-pre-migration-v6-to-v7` folder after the first SessionStart, 172 memories /
|
|
1456
|
+
2 versions / 252 edges / 5 prospective rows and 153 distinct content hashes both sides,
|
|
1457
|
+
doctor green after, and the 0.3.1 build refusing it `SCHEMA_AHEAD` — at open, and in an
|
|
1458
|
+
MCP server that was already running (`schema-ahead`, "Run /mcp and Reconnect").
|
|
1459
|
+
|
|
1460
|
+
**Table by table.**
|
|
1461
|
+
|
|
1462
|
+
| table | v7 columns | why |
|
|
1463
|
+
|---|---|---|
|
|
1464
|
+
| `memories` | `created_at`, `updated_at`, `model`, `event_date` | the records. `updated_at` moves when the words or the state change — `revise`, `supersede`, `archive`, an owner's unarchive — and NOT on physics bookkeeping (`updatePhysics`, `reinforce`, `setBand`): decay touches every row nightly, and an `updated_at` that meant "last sleep" would say nothing. |
|
|
1465
|
+
| `versions` | `created_at`, `model`, `event_date` | a version is written once and never updated, and `archived_at` is already the moment it stopped being current; `created_at` is when its WORDS were written (the head's `updated_at`, else `created_at`, at archive), so a version has both ends. `model` and `event_date` travel with the words, like `learned_on` / `happened_on` already did. No `updated_at`: nothing updates a version but the removal chase, which blanks it. |
|
|
1466
|
+
| `edges` | `created_at`, `updated_at` | first linked, last re-weighted. `link` / `linkMany` became an UPSERT: `INSERT OR REPLACE` deletes the row first and would reset `created_at` at every re-weighting. |
|
|
1467
|
+
| `prospective` | `created_at`, `updated_at` | window first recorded, last changed state; UPSERT for the same reason. |
|
|
1468
|
+
| `feelings` (new) | `created_at`, `updated_at` NOT NULL | a new table, so no row predates its moments; see below. |
|
|
1469
|
+
| `events` | none | `at` IS its moment, and the log is append-only. |
|
|
1470
|
+
| `removal_record`, `removal_tombstone` | none | append-only, each with its own `at`. |
|
|
1471
|
+
| `gate_session` | none | per-session working state, pruned by lived day; not a record anyone reads back later. |
|
|
1472
|
+
| `meta` | none | key/value settings, not records. |
|
|
1473
|
+
| box 3 (the cache) | none | declared rebuildable. |
|
|
1474
|
+
|
|
1475
|
+
**Backfill: none.** Old rows carry NULL moments. Nothing durable holds the moment a v6
|
|
1476
|
+
row was written — `store.put` goes to the in-process ring, not the event log — and
|
|
1477
|
+
`learned_on` is a date, not a moment; the owner ruled old dates stay as they are
|
|
1478
|
+
(docs/time.md rule 6). NULL reads "not recorded", never a made-up time.
|
|
1479
|
+
|
|
1480
|
+
**`model`.** The model id that wrote the current words, screened by `isModelId` (moved
|
|
1481
|
+
from `self/episodes.ts` to `core/types.ts` so the store can use it; `self/` re-exports
|
|
1482
|
+
it). The relay is the chapters' (self NOTES §24): the transcript's last assistant model →
|
|
1483
|
+
the session registry record → the MCP server's `sessionModel()` → `note`, `session_end`
|
|
1484
|
+
entries, `chapter`, and `self_page`. A server with no bound session (a `note` before any
|
|
1485
|
+
tool named one) records NULL, as does the sweep, the owner's console and anything the host
|
|
1486
|
+
did not name. On `revise`, new words with no model named set it NULL (they are no longer
|
|
1487
|
+
the last model's); a revise that leaves the body alone keeps it. Each version keeps the
|
|
1488
|
+
model that wrote IT.
|
|
1489
|
+
|
|
1490
|
+
**The reminder date: a new `event_date` column, not a widened `happened_on`.**
|
|
1491
|
+
`happened_on` is already written with PAST dates that are not reminders — `schemas/`
|
|
1492
|
+
stamps every belief's and current-state's `statedOn` into it, and episodes pass one — so
|
|
1493
|
+
an index over it would hand prospective every schema row stated this week as an
|
|
1494
|
+
"arrival". A reminder is a different fact from when something happened, and a memory can
|
|
1495
|
+
carry both ("on the 20th we agreed taxes are due Oct 15"). `event_date` holds a day, a
|
|
1496
|
+
month, a year or a range, is refused when unreadable (`EVENT_DATE_INVALID`), travels in
|
|
1497
|
+
versions, is cleared by `revise({ eventDate: null })`, and is blanked by the removal chase
|
|
1498
|
+
along with the moments and the model. `datedMemories(from, to)` bounds the SQL loosely
|
|
1499
|
+
(`event_date <= to || '~'`, which the partial index answers) and decides overlap in
|
|
1500
|
+
`time.ts`: a month `2026-10` sorts before `2026-10-01` as text and a range's text runs
|
|
1501
|
+
past its first day, so a `BETWEEN` would miss both. prospective's `meta.eventDate`
|
|
1502
|
+
convention is still read by `contentDates`; nothing in `src/` writes it, and
|
|
1503
|
+
`datedMemories` does not look at it. Nothing writes `event_date` yet either — that door
|
|
1504
|
+
(and firing off it) is PR B.
|
|
1505
|
+
|
|
1506
|
+
**The person's day.** `today()`, a new row's default `learned_on`, and `store.created`
|
|
1507
|
+
are the local date of `now()` in `zone()` — `StoreOptions.timeZone` (the host config's
|
|
1508
|
+
`timeZone`, threaded through `Counterpart.open`) or the machine's current zone, resolved
|
|
1509
|
+
per call. `dateOf` / `today` (the module functions) stay UTC under their old names, for
|
|
1510
|
+
the callers that mean UTC on purpose: tools, the dashboard's `todayUtc`, reading pre-v7
|
|
1511
|
+
rows, and the file names below. The hooks' `at` moved with it, and that date is also what
|
|
1512
|
+
the boundary hands `advanceClock`: west of UTC, on the evening of the upgrade (or after
|
|
1513
|
+
flying west), a session can present a local date one day BEHIND `lastActiveDate`. The
|
|
1514
|
+
store refuses it (`CLOCK_BACKWARDS`), the cycle names it (`sleep.clock.failed`) and stays
|
|
1515
|
+
on the lived day it already believed, and the next local date moves it on —
|
|
1516
|
+
`test/local-day.test.ts` "the lived clock across the change". No special case was added.
|
|
1517
|
+
|
|
1518
|
+
**What stayed UTC, on purpose** (file names and legacy readers, not a person's day):
|
|
1519
|
+
snapshot folder names and their retention cutoffs (`adapters/snapshots.ts`), the
|
|
1520
|
+
pre-migration copy's "taken today" check (its folder name begins with a UTC instant),
|
|
1521
|
+
the parked-store suffix and plan date in `start-fresh` / `uninstall`, `repair-dates`
|
|
1522
|
+
(it repairs pre-v7 rows, whose dates were UTC), and ISO instants in log lines and file
|
|
1523
|
+
names. Changing a folder name's calendar is a question for the owner, not a fix.
|
|
1524
|
+
|
|
1525
|
+
**A SQLite quirk found building the v6 fixture.** `ALTER TABLE … DROP COLUMN` fails with
|
|
1526
|
+
"incomplete input" when the column being dropped is the LAST one and `--` comment lines
|
|
1527
|
+
precede it in the stored `CREATE TABLE` text. The v7 columns on `memories` therefore sit
|
|
1528
|
+
with no SQL comment among them; their explanation is a JS comment above the DDL.
|
|
1529
|
+
|
|
1530
|
+
### The `feelings` table, in the same v7 migration (owner-approved 2026-09-25)
|
|
1531
|
+
|
|
1532
|
+
One row per feeling on a memory: `whose` (`owner` | `self` today — TEXT, so a person's
|
|
1533
|
+
entity id can join later without a migration), `core` (one of six), `emotion` (a key on
|
|
1534
|
+
the wheel, `core/feelings-wheel.ts`, or `other` with the word in `other_word`),
|
|
1535
|
+
`strength` 0..1 as recorded and never rewritten, `beneath_id` (another feeling on the
|
|
1536
|
+
SAME memory it sits on top of), `carried_by` (≤280 chars: what in the moment carried
|
|
1537
|
+
it), `model`, and the two moments. Indexed on `memory_id`, `(whose, core)`,
|
|
1538
|
+
`(whose, emotion)`. `CREATE TABLE IF NOT EXISTS` in `DDL`, so a v6 store gains it in the
|
|
1539
|
+
migration transaction and a fresh store has it from birth.
|
|
1540
|
+
|
|
1541
|
+
- **`addFeelings(memoryId, inputs, { model })`** is all-or-none. `checkFeelings` is pure
|
|
1542
|
+
and exported, so a door can run it BEFORE minting the memory and never leave one with
|
|
1543
|
+
its feelings dropped. Refused (`FEELING_INVALID`, `{ index, reason }`): unknown
|
|
1544
|
+
`whose` or `core`, strength out of range, an emotion the wheel files under ANOTHER
|
|
1545
|
+
core, a `beneath` that is off this memory or loops. An emotion simply not on the wheel
|
|
1546
|
+
is kept as `other`, and the result's `notices` carry the nearest keys under that core
|
|
1547
|
+
(edit distance) so the caller can rewrite. `beneath` may be an existing id or another
|
|
1548
|
+
input's index; rows are inserted first and linked second, so order does not matter.
|
|
1549
|
+
- **`feelingsFor(id)`**, and **`feelingCounts({ by, whose?, from?, to? })`** — counts by
|
|
1550
|
+
`(whose, core|emotion)`, with the date range read as the person's days in `zone()`.
|
|
1551
|
+
The filter runs in TypeScript over the (whose-indexed) rows; fine at today's sizes, and
|
|
1552
|
+
the obvious place to push into SQL once there are many.
|
|
1553
|
+
- **Removal** deletes a memory's feelings in one statement (they carry words), beside its
|
|
1554
|
+
edges and windows. The tombstone gained no `feelings` count — that would be a column on
|
|
1555
|
+
`removal_tombstone`, and nothing needs it yet.
|
|
1556
|
+
- **Nothing reads them.** Salience, decay and recall are untouched; the `emotional`
|
|
1557
|
+
dimension and `meta.feeling` are exactly as before. `Counterpart#addFeelings` runs
|
|
1558
|
+
`carried_by` and an `other` word through `redactSecrets` first.
|
|
1559
|
+
|
|
1560
|
+
### What the adversarial review of #231 changed (2026-09-25)
|
|
1561
|
+
|
|
1562
|
+
The review is `docs/adversarial-review-v7-2026-09-25.md`.
|
|
1563
|
+
|
|
1564
|
+
- **S1, the lived clock on the upgrade evening.** The review reproduced doctor going RED
|
|
1565
|
+
on Sleep from 6 pm to midnight west of UTC. The old build's last boundary had stamped
|
|
1566
|
+
UTC's tomorrow into `lastActiveDate`, and the first local date after the upgrade was
|
|
1567
|
+
refused with `CLOCK_BACKWARDS`. There are two fixes, and either would do it alone:
|
|
1568
|
+
- The v7 migration clamps `lastActiveDate` to the person's today (`localToday`, passed
|
|
1569
|
+
in by the constructor). This costs at most one lived day counted twice, once; decay
|
|
1570
|
+
does not notice a day.
|
|
1571
|
+
- `advanceClock` treats a date ONE calendar day behind the last as the same lived day:
|
|
1572
|
+
no advance, no rewrite, and no failure row, just a ring event (`store.clock.held`).
|
|
1573
|
+
It covers flying west as well as the upgrade. A jump back of more than a day is still
|
|
1574
|
+
`CLOCK_BACKWARDS`.
|
|
1575
|
+
- **N5.** An event date is stored trimmed. Year 0000 is not a calendar date. `isZone`
|
|
1576
|
+
refuses bare offsets such as "+05:30", because an offset has no daylight-saving rules.
|
|
1577
|
+
- **N4, accepted.** A long-running MCP server resolves the machine zone at each call, but
|
|
1578
|
+
a server that outlives a flight keeps the process's `TZ`. On bun that `TZ` is fixed at
|
|
1579
|
+
start, so `note` writes the old zone's day until the next Reconnect.
|
|
1580
|
+
- **N9, accepted.** A 0.3.1 worker already mid-run during the upgrade keeps writing
|
|
1581
|
+
v6-shaped SQL until its watchdog ends it. Its `INSERT OR REPLACE` on edges leaves
|
|
1582
|
+
`created_at` NULL on the edges it touches. That is harmless and bounded.
|
package/src/core/store/errors.ts
CHANGED
|
@@ -55,6 +55,21 @@ export type StoreErrorCode =
|
|
|
55
55
|
* file to restore. Doctor's Store-open finding already has the no-path arm.
|
|
56
56
|
*/
|
|
57
57
|
| "MEMORY_BODY_MISSING"
|
|
58
|
+
/**
|
|
59
|
+
* A reminder date (`PutInput.eventDate`, schema v7) that `time.ts` cannot
|
|
60
|
+
* read as a day, month, year or range. Refused rather than stored: a date
|
|
61
|
+
* nothing can parse is a reminder that silently never comes up.
|
|
62
|
+
* `detail` carries `{ id, date }`.
|
|
63
|
+
*/
|
|
64
|
+
| "EVENT_DATE_INVALID"
|
|
65
|
+
/**
|
|
66
|
+
* A feeling (`Store#addFeelings`, schema v7) that cannot be stored as given:
|
|
67
|
+
* an unknown `whose` or `core`, a strength outside 0..1, an emotion the wheel
|
|
68
|
+
* files under another core, a `beneath` that is not on the same memory or
|
|
69
|
+
* loops. `detail` carries `{ index, reason }`; the whole call wrote nothing.
|
|
70
|
+
* An emotion simply not on the wheel is NOT this — it is kept as `other`.
|
|
71
|
+
*/
|
|
72
|
+
| "FEELING_INVALID"
|
|
58
73
|
| "ID_MALFORMED"
|
|
59
74
|
| "ID_UNKNOWN"
|
|
60
75
|
| "ID_CYCLE"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FEELINGS ON A MEMORY — the `feelings` table's shape and the one check every
|
|
3
|
+
* write of it crosses (schema v7, owner-approved 2026-09-25).
|
|
4
|
+
*
|
|
5
|
+
* One row per feeling. A memory can hold several: mixed feelings are several
|
|
6
|
+
* rows, and the owner's and this self's feelings about the same moment sit side
|
|
7
|
+
* by side, told apart by `whose`. Each names a `core` (one of six) and an
|
|
8
|
+
* `emotion` from the wheel (`core/feelings-wheel.ts`), or `other` with the
|
|
9
|
+
* person's own word kept in `other_word`. `strength` is recorded as felt and
|
|
10
|
+
* never rewritten — softening with time is for a reader to compute. A feeling
|
|
11
|
+
* can sit on top of another on the same memory (`beneath_id`: anger over fear).
|
|
12
|
+
* `carried_by` says briefly what in the moment carried it — the words, what
|
|
13
|
+
* happened — and need not be a statement of feeling.
|
|
14
|
+
*
|
|
15
|
+
* Nothing reads these yet: salience, decay and recall are untouched (the
|
|
16
|
+
* emotion build comes later), and the existing `emotional` dimension and the
|
|
17
|
+
* `meta.feeling` label stay exactly as they were.
|
|
18
|
+
*/
|
|
19
|
+
import { CORE_EMOTIONS, OTHER_EMOTION, closestKeys, isCoreEmotion, resolveEmotion } from "../feelings-wheel.js";
|
|
20
|
+
import type { CoreEmotion } from "../feelings-wheel.js";
|
|
21
|
+
import type { Row } from "./db.js";
|
|
22
|
+
import { StoreError } from "./errors.js";
|
|
23
|
+
|
|
24
|
+
/** Whose feeling it is. Two today; the column is TEXT so a person (an entity
|
|
25
|
+
* id) can join later without a migration. */
|
|
26
|
+
export const FEELING_WHOSE = ["owner", "self"] as const;
|
|
27
|
+
export type FeelingWhose = (typeof FEELING_WHOSE)[number];
|
|
28
|
+
|
|
29
|
+
/** `carried_by` is a short pointer at the moment, not a transcript. */
|
|
30
|
+
export const CARRIED_BY_MAX_CHARS = 280;
|
|
31
|
+
/** The free word kept when the emotion is not on the wheel. */
|
|
32
|
+
export const OTHER_WORD_MAX_CHARS = 40;
|
|
33
|
+
|
|
34
|
+
export interface FeelingInput {
|
|
35
|
+
readonly whose: string;
|
|
36
|
+
readonly core: string;
|
|
37
|
+
/** A wheel key or bare word (`furious`, `fear.inferior`), or `other`. */
|
|
38
|
+
readonly emotion: string;
|
|
39
|
+
/** The person's word, when `emotion` is `other`. */
|
|
40
|
+
readonly otherWord?: string;
|
|
41
|
+
/** 0..1, as recorded. */
|
|
42
|
+
readonly strength: number;
|
|
43
|
+
/** What carried it. May be empty. */
|
|
44
|
+
readonly carriedBy?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The feeling this one sits on top of: an existing feeling's id on the SAME
|
|
47
|
+
* memory, or the index of another input in the same call.
|
|
48
|
+
*/
|
|
49
|
+
readonly beneath?: string | number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface FeelingRow extends Row {
|
|
53
|
+
id: string;
|
|
54
|
+
memory_id: string;
|
|
55
|
+
whose: string;
|
|
56
|
+
core: string;
|
|
57
|
+
emotion: string;
|
|
58
|
+
other_word: string | null;
|
|
59
|
+
strength: number;
|
|
60
|
+
beneath_id: string | null;
|
|
61
|
+
carried_by: string;
|
|
62
|
+
model: string | null;
|
|
63
|
+
created_at: number;
|
|
64
|
+
updated_at: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A feeling stored as `other`: the word as given, and the wheel keys nearest it. */
|
|
68
|
+
export interface FeelingNotice {
|
|
69
|
+
readonly index: number;
|
|
70
|
+
readonly word: string;
|
|
71
|
+
readonly core: CoreEmotion;
|
|
72
|
+
readonly closest: readonly string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface AddFeelingsResult {
|
|
76
|
+
readonly ids: readonly string[];
|
|
77
|
+
readonly notices: readonly FeelingNotice[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One input, checked and spelled as it will be stored. `beneath` still unresolved. */
|
|
81
|
+
export interface CheckedFeeling {
|
|
82
|
+
readonly whose: FeelingWhose;
|
|
83
|
+
readonly core: CoreEmotion;
|
|
84
|
+
readonly emotion: string;
|
|
85
|
+
readonly otherWord: string | null;
|
|
86
|
+
readonly strength: number;
|
|
87
|
+
readonly carriedBy: string;
|
|
88
|
+
readonly beneath: string | number | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function invalid(index: number, reason: string, extra: Record<string, string | number> = {}): never {
|
|
92
|
+
throw new StoreError("FEELING_INVALID", { index, reason, ...extra });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* THE CHECK, pure — no store needed, so a door (the MCP tools) can run it
|
|
97
|
+
* BEFORE it mints the memory the feelings belong to, and refuse the whole
|
|
98
|
+
* entry rather than leave a memory whose feelings were dropped. Throws
|
|
99
|
+
* `FEELING_INVALID` naming the input and the reason; returns the checked rows
|
|
100
|
+
* and the `other` notices.
|
|
101
|
+
*/
|
|
102
|
+
export function checkFeelings(inputs: readonly FeelingInput[]): { rows: CheckedFeeling[]; notices: FeelingNotice[] } {
|
|
103
|
+
const rows: CheckedFeeling[] = [];
|
|
104
|
+
const notices: FeelingNotice[] = [];
|
|
105
|
+
inputs.forEach((f, i) => {
|
|
106
|
+
if (f === null || typeof f !== "object") invalid(i, "not-an-object");
|
|
107
|
+
if (typeof f.whose !== "string" || !(FEELING_WHOSE as readonly string[]).includes(f.whose)) {
|
|
108
|
+
invalid(i, "whose-unknown", { allowed: FEELING_WHOSE.join("|") });
|
|
109
|
+
}
|
|
110
|
+
if (!isCoreEmotion(f.core)) invalid(i, "core-unknown", { allowed: CORE_EMOTIONS.join("|") });
|
|
111
|
+
const core = f.core as CoreEmotion;
|
|
112
|
+
if (typeof f.strength !== "number" || !Number.isFinite(f.strength) || f.strength < 0 || f.strength > 1) {
|
|
113
|
+
invalid(i, "strength-out-of-range");
|
|
114
|
+
}
|
|
115
|
+
const carriedBy = f.carriedBy ?? "";
|
|
116
|
+
if (typeof carriedBy !== "string") invalid(i, "carried-by-not-a-string");
|
|
117
|
+
if (carriedBy.length > CARRIED_BY_MAX_CHARS) invalid(i, "carried-by-too-long", { max: CARRIED_BY_MAX_CHARS });
|
|
118
|
+
// TYPES AND LENGTHS BEFORE ANY WORK (review S2): a non-string `otherWord`
|
|
119
|
+
// used to throw a TypeError out of `.trim()`, and a huge `emotion` was
|
|
120
|
+
// scored by edit distance before it was refused.
|
|
121
|
+
if (typeof f.emotion !== "string" || f.emotion.trim().length === 0) invalid(i, "emotion-missing");
|
|
122
|
+
if (f.emotion.trim().length > OTHER_WORD_MAX_CHARS) invalid(i, "emotion-too-long", { max: OTHER_WORD_MAX_CHARS });
|
|
123
|
+
if (f.otherWord !== undefined && typeof f.otherWord !== "string") invalid(i, "other-word-not-a-string");
|
|
124
|
+
if (typeof f.otherWord === "string" && f.otherWord.trim().length > OTHER_WORD_MAX_CHARS) {
|
|
125
|
+
invalid(i, "other-word-too-long", { max: OTHER_WORD_MAX_CHARS });
|
|
126
|
+
}
|
|
127
|
+
if (f.beneath !== undefined && typeof f.beneath !== "string" && typeof f.beneath !== "number") {
|
|
128
|
+
invalid(i, "beneath-not-an-id-or-index");
|
|
129
|
+
}
|
|
130
|
+
let emotion: string;
|
|
131
|
+
let otherWord: string | null = null;
|
|
132
|
+
if (f.emotion.trim().toLowerCase() === OTHER_EMOTION) {
|
|
133
|
+
const word = (f.otherWord ?? "").trim();
|
|
134
|
+
if (word.length === 0) invalid(i, "other-word-missing");
|
|
135
|
+
emotion = OTHER_EMOTION;
|
|
136
|
+
otherWord = word;
|
|
137
|
+
notices.push({ index: i, word, core, closest: closestKeys(core, word.toLowerCase()) });
|
|
138
|
+
} else {
|
|
139
|
+
const read = resolveEmotion(core, f.emotion);
|
|
140
|
+
if (read.kind === "wrong-core") {
|
|
141
|
+
invalid(i, "emotion-under-another-core", { emotion: read.entry.key, core: read.entry.core });
|
|
142
|
+
}
|
|
143
|
+
if (read.kind === "wheel") {
|
|
144
|
+
emotion = read.entry.key;
|
|
145
|
+
} else {
|
|
146
|
+
// Not on the wheel: kept, as `other`, with the word — and the caller is
|
|
147
|
+
// told the nearest keys so it can rewrite if it meant one of them.
|
|
148
|
+
emotion = OTHER_EMOTION;
|
|
149
|
+
otherWord = read.kind === "other" ? read.word : f.emotion.trim();
|
|
150
|
+
notices.push({ index: i, word: otherWord, core, closest: read.kind === "other" ? read.closest : [] });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (otherWord !== null && otherWord.length > OTHER_WORD_MAX_CHARS) {
|
|
154
|
+
invalid(i, "other-word-too-long", { max: OTHER_WORD_MAX_CHARS });
|
|
155
|
+
}
|
|
156
|
+
if (typeof f.beneath === "number") {
|
|
157
|
+
if (!Number.isInteger(f.beneath) || f.beneath < 0 || f.beneath >= inputs.length || f.beneath === i) {
|
|
158
|
+
invalid(i, "beneath-index-out-of-range");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
rows.push({
|
|
162
|
+
whose: f.whose as FeelingWhose,
|
|
163
|
+
core,
|
|
164
|
+
emotion,
|
|
165
|
+
otherWord,
|
|
166
|
+
strength: f.strength,
|
|
167
|
+
carriedBy,
|
|
168
|
+
beneath: f.beneath ?? null,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
// No loop of "this sits on that" inside one call: follow each chain.
|
|
172
|
+
rows.forEach((_, start) => {
|
|
173
|
+
const seen = new Set<number>([start]);
|
|
174
|
+
let at = rows[start]?.beneath;
|
|
175
|
+
while (typeof at === "number") {
|
|
176
|
+
if (seen.has(at)) invalid(start, "beneath-cycle");
|
|
177
|
+
seen.add(at);
|
|
178
|
+
at = rows[at]?.beneath;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return { rows, notices };
|
|
182
|
+
}
|