counterparts 0.3.0 → 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.
Files changed (207) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/docs/module-map.md +2 -0
  3. package/package.json +2 -1
  4. package/src/adapters/claude-code/CONTRACT.md +2 -1
  5. package/src/adapters/claude-code/NOTES.md +90 -2
  6. package/src/adapters/claude-code/bin/hook.ts +17 -2
  7. package/src/adapters/claude-code/bin/runner.ts +4 -1
  8. package/src/adapters/claude-code/config.ts +23 -0
  9. package/src/adapters/claude-code/doctor.ts +148 -26
  10. package/src/adapters/claude-code/hooks.ts +37 -12
  11. package/src/adapters/claude-code/index.ts +2 -0
  12. package/src/adapters/claude-code/standdown.ts +12 -1
  13. package/src/adapters/claude-code/transcript.ts +79 -6
  14. package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
  15. package/src/adapters/cli/commands.ts +209 -61
  16. package/src/adapters/cli/export.ts +27 -3
  17. package/src/adapters/cli/help.ts +22 -8
  18. package/src/adapters/cli/install.ts +3 -5
  19. package/src/adapters/cli/mechanisms.ts +295 -0
  20. package/src/adapters/cli/repair-dates.ts +3 -1
  21. package/src/adapters/cli/snapshot.ts +4 -27
  22. package/src/adapters/dashboard/CONTRACT.md +13 -9
  23. package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
  24. package/src/adapters/dashboard/NOTES.md +3 -2
  25. package/src/adapters/dashboard/activity.ts +2 -1
  26. package/src/adapters/dashboard/bin/dashboard.ts +18 -3
  27. package/src/adapters/dashboard/upgrade.ts +23 -0
  28. package/src/adapters/dashboard/web/README.md +153 -0
  29. package/src/adapters/dashboard/web/actions.ts +631 -0
  30. package/src/adapters/dashboard/web/app.html +40 -1703
  31. package/src/adapters/dashboard/web/app.js +55 -0
  32. package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
  33. package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
  34. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
  35. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
  36. package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
  37. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
  38. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
  39. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
  40. package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
  41. package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
  42. package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
  43. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
  44. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
  45. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
  46. package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
  47. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
  48. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
  49. package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
  50. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
  51. package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
  52. package/src/adapters/dashboard/web/narrate.ts +10 -10
  53. package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
  54. package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
  55. package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
  56. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
  57. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
  58. package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
  59. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
  60. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
  61. package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
  62. package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
  63. package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
  64. package/src/adapters/dashboard/web/pages/health/health.css +93 -0
  65. package/src/adapters/dashboard/web/pages/health/index.js +41 -0
  66. package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
  67. package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
  68. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
  69. package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
  70. package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
  71. package/src/adapters/dashboard/web/pages/home/home.css +134 -0
  72. package/src/adapters/dashboard/web/pages/home/index.js +84 -0
  73. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
  74. package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
  75. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
  76. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
  77. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
  78. package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
  79. package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
  80. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
  81. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
  82. package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
  83. package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
  84. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
  85. package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
  86. package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
  87. package/src/adapters/dashboard/web/pages/self/index.js +43 -0
  88. package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
  89. package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
  90. package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
  91. package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
  92. package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
  93. package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
  94. package/src/adapters/dashboard/web/pages/self/self.css +182 -0
  95. package/src/adapters/dashboard/web/server.ts +305 -28
  96. package/src/adapters/dashboard/web/shared/absence.js +14 -0
  97. package/src/adapters/dashboard/web/shared/actions.js +48 -0
  98. package/src/adapters/dashboard/web/shared/api.js +17 -0
  99. package/src/adapters/dashboard/web/shared/base.css +34 -0
  100. package/src/adapters/dashboard/web/shared/canvas.js +68 -0
  101. package/src/adapters/dashboard/web/shared/colors.js +6 -0
  102. package/src/adapters/dashboard/web/shared/dom.js +4 -0
  103. package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
  104. package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
  105. package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
  106. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
  107. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
  108. package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
  109. package/src/adapters/dashboard/web/shared/format.js +31 -0
  110. package/src/adapters/dashboard/web/shared/layout.css +32 -0
  111. package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
  112. package/src/adapters/dashboard/web/shared/modal.css +24 -0
  113. package/src/adapters/dashboard/web/shared/modal.js +22 -0
  114. package/src/adapters/dashboard/web/shared/state.js +12 -0
  115. package/src/adapters/dashboard/web/shared/tip.css +4 -0
  116. package/src/adapters/dashboard/web/shared/tip.js +12 -0
  117. package/src/adapters/dashboard/web/shared/tokens.css +50 -0
  118. package/src/adapters/dashboard/web/shared/type.css +52 -0
  119. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  120. package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
  121. package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
  122. package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
  123. package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
  124. package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
  125. package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
  126. package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
  127. package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
  128. package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
  129. package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
  130. package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
  131. package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
  132. package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
  133. package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
  134. package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
  135. package/src/adapters/dashboard/web/shell/pages.js +15 -0
  136. package/src/adapters/dashboard/web/shell/pulse.js +86 -0
  137. package/src/adapters/dashboard/web/shell/tabs.js +49 -0
  138. package/src/adapters/dashboard/web/static.ts +76 -0
  139. package/src/adapters/dashboard/web/views/activity.ts +80 -0
  140. package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
  141. package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
  142. package/src/adapters/dashboard/web/views/health.ts +328 -0
  143. package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
  144. package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
  145. package/src/adapters/dashboard/web/views/memories.ts +342 -0
  146. package/src/adapters/dashboard/web/views/memory.ts +210 -0
  147. package/src/adapters/dashboard/web/views/meta.ts +64 -0
  148. package/src/adapters/dashboard/web/views/mind.ts +729 -0
  149. package/src/adapters/dashboard/web/views/overview.ts +282 -0
  150. package/src/adapters/dashboard/web/views/pulse.ts +19 -0
  151. package/src/adapters/dashboard/web/views/rows.ts +207 -0
  152. package/src/adapters/dashboard/web/views/search.ts +62 -0
  153. package/src/adapters/dashboard/web/views/shared.ts +161 -0
  154. package/src/adapters/dashboard/web/views.ts +34 -1724
  155. package/src/adapters/fired.ts +138 -31
  156. package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
  157. package/src/adapters/mcp/NOTES.md +43 -0
  158. package/src/adapters/mcp/bin/serve.ts +9 -1
  159. package/src/adapters/mcp/index.ts +7 -0
  160. package/src/adapters/mcp/server.ts +167 -6
  161. package/src/adapters/mcp/tools.ts +42 -0
  162. package/src/adapters/mcp/write-up.ts +1 -1
  163. package/src/adapters/sessions.ts +18 -1
  164. package/src/adapters/snapshots.ts +71 -39
  165. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  166. package/src/core/counterpart.ts +86 -7
  167. package/src/core/encode/INTERFACE-GAPS.md +12 -0
  168. package/src/core/feelings-wheel.ts +218 -0
  169. package/src/core/handoff/INTERFACE-GAPS.md +2 -0
  170. package/src/core/mint.ts +14 -2
  171. package/src/core/prospective/INTERFACE-GAPS.md +14 -0
  172. package/src/core/prospective/windows.ts +10 -48
  173. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  174. package/src/core/remember/INTERFACE-GAPS.md +10 -0
  175. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  176. package/src/core/schemas/NOTES.md +118 -1
  177. package/src/core/schemas/index.ts +330 -40
  178. package/src/core/schemas/tunables.ts +23 -0
  179. package/src/core/schemas/types.ts +64 -1
  180. package/src/core/self/CONTRACT.md +3 -0
  181. package/src/core/self/INTERFACE-GAPS.md +10 -0
  182. package/src/core/self/NOTES.md +33 -2
  183. package/src/core/self/calendar.ts +7 -78
  184. package/src/core/self/episodes.ts +52 -12
  185. package/src/core/self/index.ts +40 -12
  186. package/src/core/self/writer.ts +22 -22
  187. package/src/core/sleep/NOTES.md +36 -0
  188. package/src/core/sleep/cycle.ts +38 -3
  189. package/src/core/sleep/fade.ts +76 -0
  190. package/src/core/sleep/index.ts +4 -1
  191. package/src/core/sleep/prune.ts +8 -1
  192. package/src/core/sleep/tunables.ts +5 -0
  193. package/src/core/sleep/types.ts +24 -0
  194. package/src/core/store/CONTRACT.md +36 -7
  195. package/src/core/store/NOTES.md +197 -0
  196. package/src/core/store/errors.ts +22 -0
  197. package/src/core/store/feelings.ts +182 -0
  198. package/src/core/store/index.ts +339 -45
  199. package/src/core/store/operational.ts +240 -22
  200. package/src/core/store/owner-op-seam.ts +13 -3
  201. package/src/core/store/paths.ts +15 -1
  202. package/src/core/store/pre-migration.ts +258 -0
  203. package/src/core/store/prose.ts +8 -1
  204. package/src/core/store/render.ts +3 -0
  205. package/src/core/time.ts +374 -0
  206. package/src/core/types.ts +13 -0
  207. package/src/adapters/dashboard/web/brain.html +0 -463
@@ -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
+ }