counterparts 0.3.4 → 0.3.6

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 (156) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/docs/module-map.md +2 -2
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +48 -30
  5. package/src/adapters/claude-code/NOTES.md +38 -0
  6. package/src/adapters/claude-code/doctor.ts +202 -20
  7. package/src/adapters/claude-code/hooks.ts +39 -294
  8. package/src/adapters/claude-code/index.ts +2 -2
  9. package/src/adapters/cli/NOTES.md +12 -0
  10. package/src/adapters/cli/commands.ts +84 -20
  11. package/src/adapters/cli/dream-core.ts +105 -11
  12. package/src/adapters/cli/export.ts +21 -2
  13. package/src/adapters/cli/help.ts +13 -9
  14. package/src/adapters/cli/mechanisms.ts +7 -1
  15. package/src/adapters/cli/self-page.ts +5 -2
  16. package/src/adapters/dashboard/activity.ts +18 -5
  17. package/src/adapters/dashboard/registries.ts +1 -1
  18. package/src/adapters/dashboard/source.ts +8 -0
  19. package/src/adapters/dashboard/stories.ts +3 -1
  20. package/src/adapters/dashboard/web/README.md +131 -54
  21. package/src/adapters/dashboard/web/actions.ts +45 -3
  22. package/src/adapters/dashboard/web/app.html +1 -4
  23. package/src/adapters/dashboard/web/app.js +3 -7
  24. package/src/adapters/dashboard/web/ask-voice.ts +364 -0
  25. package/src/adapters/dashboard/web/lanes.ts +32 -2
  26. package/src/adapters/dashboard/web/mechanisms/association/index.js +1 -0
  27. package/src/adapters/dashboard/web/mechanisms/association/panel.js +1 -3
  28. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +1 -0
  29. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +31 -17
  30. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -0
  31. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +1 -3
  32. package/src/adapters/dashboard/web/mechanisms/dreaming/index.js +3 -2
  33. package/src/adapters/dashboard/web/mechanisms/dreaming/panel.js +20 -0
  34. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +1 -0
  35. package/src/adapters/dashboard/web/mechanisms/emotional/panel.js +24 -0
  36. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +1 -0
  37. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/panel.js +11 -0
  38. package/src/adapters/dashboard/web/mechanisms/index.js +15 -4
  39. package/src/adapters/dashboard/web/mechanisms/interference/index.js +1 -0
  40. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +1 -0
  41. package/src/adapters/dashboard/web/mechanisms/prospective/panel.js +27 -0
  42. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +1 -0
  43. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +1 -3
  44. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +1 -0
  45. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +54 -15
  46. package/src/adapters/dashboard/web/mechanisms/salience/index.js +1 -0
  47. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +16 -5
  48. package/src/adapters/dashboard/web/mechanisms/schema/index.js +1 -0
  49. package/src/adapters/dashboard/web/narrate.ts +78 -9
  50. package/src/adapters/dashboard/web/pages/health/health.css +151 -0
  51. package/src/adapters/dashboard/web/pages/health/index.js +28 -13
  52. package/src/adapters/dashboard/web/pages/health/sections/archive.js +5 -2
  53. package/src/adapters/dashboard/web/pages/health/sections/checks.js +31 -24
  54. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +8 -5
  55. package/src/adapters/dashboard/web/pages/health/sections/mechanisms.js +251 -0
  56. package/src/adapters/dashboard/web/pages/health/sections/wake.js +49 -0
  57. package/src/adapters/dashboard/web/pages/home/brain.js +17 -36
  58. package/src/adapters/dashboard/web/pages/home/go.js +7 -0
  59. package/src/adapters/dashboard/web/pages/home/home.css +54 -123
  60. package/src/adapters/dashboard/web/pages/home/index.js +47 -56
  61. package/src/adapters/dashboard/web/pages/home/sections/brain.js +84 -0
  62. package/src/adapters/dashboard/web/pages/home/sections/feel.js +37 -0
  63. package/src/adapters/dashboard/web/pages/home/sections/hero.js +43 -16
  64. package/src/adapters/dashboard/web/pages/home/sections/map.js +25 -0
  65. package/src/adapters/dashboard/web/pages/home/sections/today.js +41 -0
  66. package/src/adapters/dashboard/web/pages/memories/fold.js +48 -0
  67. package/src/adapters/dashboard/web/pages/memories/index.js +9 -3
  68. package/src/adapters/dashboard/web/pages/memories/memories.css +5 -0
  69. package/src/adapters/dashboard/web/pages/memories/row.js +8 -2
  70. package/src/adapters/dashboard/web/pages/memories/sections/feel.js +33 -14
  71. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +9 -4
  72. package/src/adapters/dashboard/web/pages/memories/sections/search.js +59 -11
  73. package/src/adapters/dashboard/web/pages/self/index.js +15 -11
  74. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +6 -2
  75. package/src/adapters/dashboard/web/pages/self/sections/journal.js +31 -12
  76. package/src/adapters/dashboard/web/pages/self/sections/map.js +273 -0
  77. package/src/adapters/dashboard/web/pages/self/sections/page.js +121 -62
  78. package/src/adapters/dashboard/web/pages/self/sections/settling.js +31 -41
  79. package/src/adapters/dashboard/web/pages/self/sections/traits.js +102 -0
  80. package/src/adapters/dashboard/web/pages/self/sections/wake.js +45 -52
  81. package/src/adapters/dashboard/web/pages/self/self.css +110 -72
  82. package/src/adapters/dashboard/web/pages/self/state.js +4 -0
  83. package/src/adapters/dashboard/web/server.ts +20 -1
  84. package/src/adapters/dashboard/web/shared/absence.js +1 -3
  85. package/src/adapters/dashboard/web/shared/base.css +0 -1
  86. package/src/adapters/dashboard/web/shared/doctor.js +68 -0
  87. package/src/adapters/dashboard/web/shared/layout.css +0 -1
  88. package/src/adapters/dashboard/web/shared/memory-card-words.js +96 -0
  89. package/src/adapters/dashboard/web/shared/memory-modal.js +13 -22
  90. package/src/adapters/dashboard/web/shared/widgets/feed.js +22 -15
  91. package/src/adapters/dashboard/web/shell/pulse.js +1 -16
  92. package/src/adapters/dashboard/web/views/activity.ts +43 -7
  93. package/src/adapters/dashboard/web/views/archive-words.ts +6 -0
  94. package/src/adapters/dashboard/web/views/core-road.ts +56 -0
  95. package/src/adapters/dashboard/web/views/dreams.ts +8 -5
  96. package/src/adapters/dashboard/web/views/flow-view.ts +9 -5
  97. package/src/adapters/dashboard/web/views/health.ts +74 -13
  98. package/src/adapters/dashboard/web/views/mechanism-panel.ts +395 -93
  99. package/src/adapters/dashboard/web/views/mechanisms.ts +106 -5
  100. package/src/adapters/dashboard/web/views/memories.ts +33 -22
  101. package/src/adapters/dashboard/web/views/memory.ts +99 -32
  102. package/src/adapters/dashboard/web/views/mind.ts +590 -53
  103. package/src/adapters/dashboard/web/views/overview.ts +57 -99
  104. package/src/adapters/dashboard/web/views/search.ts +58 -7
  105. package/src/adapters/dashboard/web/views/self-map.ts +124 -0
  106. package/src/adapters/dashboard/web/views/today.ts +181 -0
  107. package/src/adapters/dashboard/web/views/traits.ts +296 -0
  108. package/src/adapters/dashboard/web/views.ts +7 -5
  109. package/src/adapters/fired.ts +32 -11
  110. package/src/adapters/mcp/CONTRACT.md +3 -0
  111. package/src/adapters/mcp/NOTES.md +40 -0
  112. package/src/adapters/mcp/bin/serve.ts +6 -1
  113. package/src/adapters/mcp/index.ts +4 -0
  114. package/src/adapters/mcp/server.ts +471 -21
  115. package/src/adapters/mcp/tools.ts +237 -18
  116. package/src/adapters/mechanism-evidence.ts +26 -3
  117. package/src/adapters/sessions.ts +5 -0
  118. package/src/core/counterpart.ts +210 -2
  119. package/src/core/dream/CONTRACT.md +180 -27
  120. package/src/core/dream/INTERFACE-GAPS.md +25 -0
  121. package/src/core/dream/NOTES.md +265 -0
  122. package/src/core/dream/index.ts +745 -139
  123. package/src/core/dream/mind.ts +110 -0
  124. package/src/core/dream/reflect.ts +1734 -0
  125. package/src/core/dream/tunables.ts +33 -4
  126. package/src/core/physics/CONTRACT.md +23 -1
  127. package/src/core/physics/NOTES.md +48 -0
  128. package/src/core/physics/index.ts +100 -7
  129. package/src/core/remember/owes.ts +4 -1
  130. package/src/core/schemas/index.ts +8 -1
  131. package/src/core/self/CONTRACT.md +41 -19
  132. package/src/core/self/INTERFACE-GAPS.md +4 -0
  133. package/src/core/self/NOTES.md +41 -0
  134. package/src/core/self/index.ts +22 -3
  135. package/src/core/self/journal-file.ts +5 -2
  136. package/src/core/self/page.ts +60 -30
  137. package/src/core/self/writer.ts +114 -19
  138. package/src/core/sleep/CONTRACT.md +2 -1
  139. package/src/core/sleep/NOTES.md +51 -0
  140. package/src/core/sleep/consolidate.ts +146 -25
  141. package/src/core/sleep/index.ts +12 -2
  142. package/src/core/sleep/types.ts +17 -0
  143. package/src/core/store/CONTRACT.md +15 -0
  144. package/src/core/store/NOTES.md +92 -1
  145. package/src/core/store/errors.ts +16 -3
  146. package/src/core/store/feelings.ts +159 -22
  147. package/src/core/store/index.ts +572 -29
  148. package/src/core/store/operational.ts +351 -7
  149. package/src/core/store/owner-op-seam.ts +110 -1
  150. package/src/core/store/traits.ts +179 -0
  151. package/src/core/types.ts +17 -2
  152. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +0 -221
  153. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +0 -31
  154. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +0 -17
  155. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +0 -69
  156. package/src/adapters/dashboard/web/shared/widgets/chapters.js +0 -15
@@ -73,6 +73,7 @@ import {
73
73
  ASK_ROW_COUNTING,
74
74
  decideUpdateNotice,
75
75
  installedBuild,
76
+ isLive,
76
77
  markUpdateNoticeShown,
77
78
  owedWriteUps,
78
79
  progressKey,
@@ -91,15 +92,9 @@ import {
91
92
  } from "../sessions.js";
92
93
  import type { SessionPhase, SessionRecord } from "../sessions.js";
93
94
 
94
- import {
95
- SELF_PAGE_WRITER_EVENT,
96
- SELF_TUNABLES,
97
- calendarDate,
98
- writerInstruction,
99
- writerInstructionOverhead,
100
- } from "../../core/self/index.js";
95
+ import { calendarDate } from "../../core/self/index.js";
101
96
  import { localClock, localDate, readableDate } from "../../core/time.js";
102
- import { capabilities, pageWriterMode } from "./config.js";
97
+ import { capabilities } from "./config.js";
103
98
  import { TUNABLES } from "./config.js";
104
99
  import type { AdapterConfig, CapabilityReport } from "./config.js";
105
100
  import { SESSION_NOTICE_BUDGET_MS, checkoutIsGraded, doctorFindings, noticeMessage, readCheckout } from "./doctor.js";
@@ -328,54 +323,17 @@ export const SCOPE_ASK = [
328
323
  export const SCOPE_ASK_BYTES = Buffer.byteLength(`\n\n${SCOPE_ASK}`, "utf8");
329
324
 
330
325
  /**
331
- * THE NIGHTLY PAGE WRITER'S ASK, in `session` mode (S2, 2026-09-20).
332
- *
333
- * The plan's fallback for "who runs the nightly writer", and the one that needs
334
- * no background process: when nothing has revised the page for the day just
335
- * gone, the first session of the next day is handed that day and asked to do
336
- * the night's work. It rides in `HookResult.ask` — beside the wake, never
337
- * inside it — for the reason the scope question does: the wake's byte count and
338
- * its tail sentinel are load-bearing, and text appended inside the bundle would
339
- * make `bytes`, the sentinel's number and the tail disagree.
340
- *
341
- * **It is not a second pacer.** The scar this package carries about pacers
342
- * (`self/CONTRACT.md` §3, "one ask, one pacer, a conjunction") is about the
343
- * BLOCKED MOMENT at Stop, where two asks on two substance pacers once drew
344
- * about a dozen asks from a 13-turn evening. Nothing here touches that: this
345
- * fires at SessionStart, it consults no substance, and its cadence is the day
346
- * boundary itself — at most `PAGE_WRITER_ASKS_PER_DAY` sessions are handed one
347
- * day, and the first durable row claims it for everyone.
348
- *
349
- * The TEXT is the core's (`self/writer.ts#writerInstruction`), because it
350
- * carries the page and the day and those are memory, not host trivia. What is
351
- * mechanized here is that the moment exists, that it fits inside the reported
352
- * ceiling or is deferred rather than truncated, that one session is asked once,
353
- * and that the ask leaves a durable row (CONTRACT §5 G9).
326
+ * THE PAGE'S TOOL, as a session's model names it. The nightly page writer's
327
+ * SessionStart ask (S2, 2026-09-20 — "the first session of the next day is
328
+ * handed that day") was RETIRED on 2026-09-28: the writer moved into the
329
+ * nightly run (writer, then dream, then reflection, one background agent) and
330
+ * gets its day through the dream tool's `writer` phase — a tool result, with
331
+ * no injection ceiling, so no `no-room` deferral and no contest with the
332
+ * first-launch question for the ask field. Host mode (`page-writer.ts`) is
333
+ * left in place, not the default.
354
334
  */
355
335
  export const PAGE_WRITER_TOOL = "counterparts self_page";
356
336
 
357
- /** The separator `bin/hook.ts#hostDelivery` joins the ask on after the wake. */
358
- export const ASK_SEPARATOR_BYTES = 2;
359
-
360
- /**
361
- * How many recorded deferrals the first-launch question gets before the writer
362
- * takes the ask field instead.
363
- *
364
- * ONE, because the two asks are not symmetrical. The scope question is
365
- * per-SESSION and comes back at the next one at no cost; the writer's night
366
- * happens once, and a night that passes is a day missing from the page for
367
- * good. On a blank store the scope question is exactly what is pending on
368
- * nights 1–3, so an unanswered one starved the writer for as long as nobody
369
- * answered — which on a store where nobody ever does is for ever (S2 review,
370
- * MINOR-5).
371
- *
372
- * It counts DEFERRAL ROWS, which are deduped one per night per reason, so the
373
- * flip is "this night has already lost the field once" — the first session of a
374
- * day raises the scope question, the second gives the writer its night, and the
375
- * third raises the scope question again because the night is claimed by then.
376
- */
377
- export const SCOPE_PATIENCE_DEFERRALS = 1;
378
-
379
337
  /**
380
338
  * THE NEXT-SESSION WRITE-UP'S POINTER (roadmap C2, owner 2026-09-23).
381
339
  *
@@ -766,20 +724,11 @@ export class ClaudeCodeAdapter {
766
724
  // next session in this directory asks instead, and the deferral is an
767
725
  // event rather than a silence.
768
726
  //
769
- // TWO ASKS CAN NOW WANT THIS FIELD, and the first-launch question wins.
770
- // It is asked once in the life of a directory and ends when anybody
771
- // answers; the page writer's comes back tomorrow at no cost. Concatenating
772
- // them would put two unrelated requests in front of a session that has
773
- // just woken, which is the shape §13 G3 is about even though the pacer is
774
- // not. The loser is DEFERRED with a row, never dropped silently.
775
- // ...and after two mornings of losing, the writer goes first. The scope
776
- // question is advisory and returns at the next session; a night that
777
- // passes is a day missing from the page for good (S2 review, MINOR-5).
778
- const scopeFirst = wantsAsk && !this.writerStarvedByScope();
779
- const ask = scopeFirst ? this.deliverScopeAsk(input, sent, budget) : "";
780
- const chosen =
781
- ask.length > 0 ? ask : this.deliverPageWriterAsk(input, sent, budget, false);
782
- if (ask.length > 0) this.deliverPageWriterAsk(input, sent, budget, true);
727
+ // ONE ASK WANTS THIS FIELD NOW: the first-launch question. The nightly
728
+ // page writer's ask used to contend for it (and after two mornings of
729
+ // losing went first); since 2026-09-28 the writer runs inside the
730
+ // nightly run and is handed its day through a tool result instead.
731
+ const chosen = wantsAsk ? this.deliverScopeAsk(input, sent, budget) : "";
783
732
  // THE WRITE-UP POINTER RIDES AFTER WHICHEVER ASK TOOK THE FIELD, never
784
733
  // instead of it (C2): it may coincide with either, it is measured against
785
734
  // the room BOTH of them left, and it is fail-open by construction — a
@@ -856,229 +805,6 @@ export class ClaudeCodeAdapter {
856
805
  return SCOPE_ASK;
857
806
  }
858
807
 
859
- /**
860
- * A NIGHT THAT WAS NOT OFFERED, written down where tomorrow can read it.
861
- *
862
- * A deferral claims nothing — that is what makes it a deferral — so before
863
- * this it left only a ring event, which dies with the hook process. That is
864
- * I32's shape on the newest mechanism in the tree: refused every morning,
865
- * with nothing durable behind it (S2 review, MINOR-5). The row is `skipped`,
866
- * which `pageWriterDue` is explicit about never treating as a claim, and it
867
- * is deduped to ONE per date per reason so a ceiling that is too small every
868
- * session leaves one line rather than forty.
869
- */
870
- private noteWriterDeferred(about: string, reason: string): void {
871
- try {
872
- this.counterpart.recordPageWriterRun({
873
- about,
874
- mode: "session",
875
- outcome: "skipped",
876
- detail: reason,
877
- dedupKey: `${SELF_PAGE_WRITER_EVENT}:deferred:${about}:${reason}`,
878
- });
879
- } catch {
880
- /* a deferral that cannot be recorded is still a deferral (§5 G7) */
881
- }
882
- }
883
-
884
- /**
885
- * HOW MANY MORNINGS THE FIRST-LAUNCH QUESTION HAS TAKEN THE FIELD.
886
- *
887
- * The scope question wins the ask field, and on a blank store it is exactly
888
- * what is pending on nights 1–3 — so the writer was starved for as long as
889
- * nobody answered it, which on a store where nobody ever answers is forever
890
- * (S2 review, MINOR-5). After `SCOPE_PATIENCE_DEFERRALS` deferrals the writer
891
- * goes first instead: the scope question is advisory and comes back next
892
- * session, while a night that passes is a day missing from the page for good.
893
- */
894
- private writerStarvedByScope(): boolean {
895
- try {
896
- const runs = this.counterpart.pageWriterRuns({ limit: 64 });
897
- // ONCE THE WRITER HAS BEEN ASKED, IT IS NOT STARVED, and the field goes
898
- // back to the first-launch question. Without this the priority flipped
899
- // permanently: the writer took both of the night's two asks and the scope
900
- // question — which is the thing a person actually has to answer — stopped
901
- // being raised at all.
902
- if (runs.some((r) => r.outcome === "asked")) return false;
903
- const deferred = runs.filter(
904
- (r) => r.outcome === "skipped" && r.detail === "scope-question",
905
- );
906
- return deferred.length >= SCOPE_PATIENCE_DEFERRALS;
907
- } catch {
908
- return false;
909
- }
910
- }
911
-
912
- /**
913
- * THE NIGHTLY PAGE WRITER'S ASK, in `session` mode — build it, check it fits,
914
- * claim the day, and hand it back. Returns the block, or the empty string.
915
- *
916
- * `standDownOnly` is for the pass where the first-launch question took the
917
- * field: the verdict is still computed and the deferral still leaves a ring
918
- * event, so "why was I not asked" is answerable, but nothing is claimed and
919
- * nothing is recorded — a day that was never offered must stay owed.
920
- *
921
- * **The whole body is fail-open.** A writer that cannot be composed costs the
922
- * ASK and never the wake (§1 G7): every throw below lands in the catch, the
923
- * session gets its bundle, and the ring says which step gave up.
924
- */
925
- private deliverPageWriterAsk(
926
- input: HookInput,
927
- wakeBytes: number,
928
- budget: number | undefined,
929
- standDownOnly: boolean,
930
- ): string {
931
- try {
932
- const mode = pageWriterMode(this.config);
933
- // SESSION MODE ONLY. In `host` mode the night is run by a windowless
934
- // child the worker starts — and that child's own SessionStart hook runs
935
- // this same code, so without this line the writer would be asked to
936
- // write inside the session that was started to do the writing.
937
- if (mode !== "session") return "";
938
- const due = this.counterpart.pageWriterDue({ mode });
939
- if (!due.due) {
940
- // `already-claimed` and `no-previous-day` are the ordinary answers on
941
- // most mornings; emitting a line for each of them at every session
942
- // start is how a ring becomes unreadable. Only the two that mean
943
- // something stood the mechanism down get one.
944
- if (due.reason === "off" || due.reason === "asks-spent") {
945
- this.emit("adapter.page.writer.skipped", { reason: due.reason, about: due.about });
946
- }
947
- return "";
948
- }
949
- if (input.sessionId.length === 0) return "";
950
- // ALREADY ASKED, IN THIS SESSION. `noteSession("start")` has already run
951
- // by the time this is called and it rewrites the record whole — but it
952
- // CARRIES `pageWriterFor` forward, the way it carries `config`, so the
953
- // mark a previous SessionStart in this same session left is still here.
954
- // A compaction re-firing SessionStart must not re-ask.
955
- const record = readSession(this.counterpart.store.dir, input.sessionId);
956
- if (record?.pageWriterFor === due.about) return "";
957
- if (standDownOnly) {
958
- this.emit("adapter.page.writer.deferred", { reason: "scope-question", about: due.about });
959
- this.noteWriterDeferred(due.about, "scope-question");
960
- return "";
961
- }
962
- const framing = { tool: PAGE_WRITER_TOOL, session: input.sessionId };
963
- // SIZE THE DAY TO THE ROOM THE WAKE LEFT, rather than composing what the
964
- // tunable allows and then discovering it does not fit.
965
- //
966
- // The wake already carries the page — which is why the block does not
967
- // repeat it (`self/writer.ts`) — and what is left over varies with the
968
- // day: on a busy one the memories alone are 8 KB against a ceiling a real
969
- // wake has already spent most of. Composing the whole tunable and
970
- // deferring on the total would defer EVERY morning once a store is a few
971
- // days old, and the only trace would be a ring event that dies with this
972
- // process, which is I32's shape exactly.
973
- //
974
- // So the empty block is measured first — it is the same function with no
975
- // memories in it, so the two cannot drift — and the day gets whatever is
976
- // left. A day that could not all fit is delivered SHORT, with `dropped`
977
- // counted on the run's row; only a block whose own furniture will not fit
978
- // is deferred.
979
- //
980
- // **MEASURED AFTER COMPOSING, not predicted before it** (S2 review,
981
- // MINOR-1). The estimate was the empty block, which takes the "nothing was
982
- // written down" branch; the delivered one takes a longer header, a framing
983
- // line and `3 + len` per bullet against a budget charged at 16 + len. The
984
- // difference put the composition up to 20 bytes over the host's reported
985
- // ceiling. So the estimate only SIZES the day, and the real bytes are
986
- // checked afterwards — one extra composition on a path that already
987
- // composes twice, and the ceiling becomes a fact instead of an argument.
988
- const empty = this.counterpart.pageWriterInput({ about: due.about, budgetBytes: 0 });
989
- const overhead = writerInstructionOverhead(empty, framing) + ASK_SEPARATOR_BYTES;
990
- const roomFor = (spent: number): number =>
991
- budget === undefined
992
- ? SELF_TUNABLES.PAGE_WRITER_MEMORY_BYTES
993
- : Math.min(SELF_TUNABLES.PAGE_WRITER_MEMORY_BYTES, budget - wakeBytes - spent);
994
- const defer = (need: number): string => {
995
- // DEFERRED, never truncated and never smuggled past the ceiling — the
996
- // same rule the scope question follows. The day is left unclaimed, so
997
- // the next session in any directory is offered it instead.
998
- this.emit("adapter.page.writer.deferred", {
999
- reason: "no-room",
1000
- about: due.about,
1001
- wakeBytes,
1002
- budget: budget ?? 0,
1003
- need,
1004
- });
1005
- this.noteWriterDeferred(due.about, "no-room");
1006
- return "";
1007
- };
1008
- if (roomFor(overhead) < 0) return defer(overhead);
1009
- let built = this.counterpart.pageWriterInput({
1010
- about: due.about,
1011
- budgetBytes: roomFor(overhead),
1012
- });
1013
- let text = writerInstruction(built, framing);
1014
- let bytes = Buffer.byteLength(`\n\n${text}`, "utf8");
1015
- if (budget !== undefined && wakeBytes + bytes > budget) {
1016
- // One re-composition, against the room the FIRST attempt proved was
1017
- // really left. It cannot loop: the second budget is smaller than what
1018
- // the first composition actually spent on memories, so the second block
1019
- // is strictly shorter.
1020
- const over = wakeBytes + bytes - budget;
1021
- const second = roomFor(overhead + over);
1022
- if (second < 0) return defer(bytes);
1023
- built = this.counterpart.pageWriterInput({ about: due.about, budgetBytes: second });
1024
- text = writerInstruction(built, framing);
1025
- bytes = Buffer.byteLength(`\n\n${text}`, "utf8");
1026
- // Still over after the retry — only reachable when the block's own
1027
- // furniture is the thing that does not fit — and then it is deferred
1028
- // rather than delivered over the ceiling.
1029
- if (wakeBytes + bytes > budget) return defer(bytes);
1030
- }
1031
- // A BLOCK THAT CAN CARRY NONE OF THE DAY IS NOT WORTH A NIGHT'S CLAIM
1032
- // (S2 review, MAJOR-1, the other half). The text is honest about it now —
1033
- // it says "I could not see the day" rather than "the day was empty" — but
1034
- // spending one of two asks on a block whose only content is that sentence
1035
- // is worse than leaving the night owed for a session with more room.
1036
- if (built.memories.length === 0 && built.dropped > 0) return defer(bytes);
1037
- // THE CLAIM, and it is durable rather than a flag on this session: two
1038
- // boundaries, or two machines' worth of hooks against one store, must not
1039
- // both set a night going. It is written BEFORE the text is handed over,
1040
- // so a crash between the two costs one day's revision rather than an
1041
- // unbounded re-ask (the same order `openChapter` commits in).
1042
- const claimed = this.counterpart.recordPageWriterRun({
1043
- about: due.about,
1044
- mode: "session",
1045
- outcome: "asked",
1046
- detail:
1047
- `attempt ${String(due.attempt)}` +
1048
- (built.dropped > 0 ? `; ${String(built.dropped)} of the day did not fit the wake's ceiling` : ""),
1049
- bytesBefore: built.page?.bytes ?? 0,
1050
- considered: built.memories.length,
1051
- omitted: built.omitted,
1052
- });
1053
- const marked = recordSession(this.counterpart.store.dir, {
1054
- sessionId: input.sessionId,
1055
- scope: input.scope,
1056
- phase: "start",
1057
- at: this.nowFn(),
1058
- pageWriterFor: due.about,
1059
- ...(this.configPath === undefined || this.configPath.length === 0
1060
- ? {}
1061
- : { config: this.configPath }),
1062
- });
1063
- this.emit("adapter.page.writer.ask", {
1064
- about: due.about,
1065
- attempt: due.attempt,
1066
- bytes,
1067
- considered: built.memories.length,
1068
- dropped: built.dropped,
1069
- omitted: built.omitted,
1070
- claimed,
1071
- recorded: marked !== null,
1072
- });
1073
- return text;
1074
- } catch (err) {
1075
- this.emit("adapter.page.writer.failed", {
1076
- code: err instanceof Error ? err.name : "UNKNOWN",
1077
- });
1078
- return "";
1079
- }
1080
- }
1081
-
1082
808
  /**
1083
809
  * THE NEXT-SESSION WRITE-UP'S POINTER (C2) — find the session in this project
1084
810
  * that ended owing a write-up and was pointed at least recently (oldest first
@@ -1310,19 +1036,38 @@ export class ClaudeCodeAdapter {
1310
1036
  /**
1311
1037
  * THE DREAM LINES (2026-09-26, `core/dream/`), for the MODEL only, each
1312
1038
  * ending in a newline: a contradiction a dream flagged, raised once awake,
1313
- * and the day's ask — "I haven't dreamed since …" — which the model is to put
1314
- * to the owner at a natural moment. The ask is at most once a CALENDAR day
1315
- * across every session (the store's `dream_asks` latch decides, so of two
1316
- * sessions racing one gets it); a "no" is the dream tool's `decline`. Never in
1039
+ * and the day's line, which follows the owner's dreaming setting
1040
+ * (2026-09-28): `auto` (the default) tells the model to start the nightly
1041
+ * run now — page writer, dream, reflection, one background agent — and to
1042
+ * tell the owner in one line that it is dreaming and how to say "no dreams";
1043
+ * `ask` asks the owner first, as it did from 2026-09-26; `off` says nothing.
1044
+ * The line is at most once a CALENDAR day across every session (the store's
1045
+ * `dream_asks` latch decides, so of two sessions racing one gets it), and
1046
+ * again only for a run that was left behind; a "no" is the dream tool's
1047
+ * `decline`, "no dreams" its `setting`. Never in
1317
1048
  * the host-mode page writer's headless child, never under observer, never
1318
1049
  * without a date. Only what could surface here anyway is counted or raised
1319
1050
  * (the dream module applies recall's gates). Never throws.
1051
+ *
1052
+ * v9 (2026-09-27): a MORNING SHARE the reflecting session never told is
1053
+ * carried here, ONCE, by the next session — only when the session that
1054
+ * reflected has ended (its registry record is ended or quiet), so the two
1055
+ * do not both tell it. Here, on the prompt, rather than in the SessionStart
1056
+ * wake, whose byte ceiling is what stranded the page writer.
1320
1057
  */
1321
1058
  private dreamLines(input: HookInput): string {
1322
1059
  if (this.observer || input.at === undefined || input.pageWriter === true || input.sessionId.length === 0) return "";
1323
1060
  try {
1324
1061
  const dreams = this.counterpart.dreams;
1325
1062
  const lines = [...dreams.raiseLines({ session: input.sessionId })];
1063
+ const pending = this.counterpart.reflections.pendingShare({ session: input.sessionId });
1064
+ if (pending !== null) {
1065
+ const record = pending.session === null ? null : readSession(this.counterpart.store.dir, pending.session);
1066
+ if (record === null || !isLive(record, this.nowFn())) {
1067
+ const carried = this.counterpart.reflections.carryLine({ session: input.sessionId, reflection: pending.id });
1068
+ if (carried !== null) lines.push(carried);
1069
+ }
1070
+ }
1326
1071
  const ask = dreams.askLine({ at: input.at, session: input.sessionId });
1327
1072
  if (ask !== null) lines.push(ask);
1328
1073
  if (lines.length > 0) this.emit("adapter.dream.lines", { asked: ask !== null, raised: lines.length - (ask === null ? 0 : 1) });
@@ -50,11 +50,9 @@ export {
50
50
  BOUNDARY_KIND,
51
51
  ClaudeCodeAdapter,
52
52
  HOOKS,
53
- ASK_SEPARATOR_BYTES,
54
53
  PAGE_WRITER_TOOL,
55
54
  SCOPE_ASK,
56
55
  SCOPE_ASK_BYTES,
57
- SCOPE_PATIENCE_DEFERRALS,
58
56
  SESSION_ENDING,
59
57
  SPAWN_REFUSAL_PREFIX,
60
58
  SPAWN_START_COUNT_KEY,
@@ -169,6 +167,8 @@ export function openAdapter(
169
167
  ...(config.observer === undefined ? {} : { observer: config.observer }),
170
168
  ...(config.owner === undefined ? {} : { owner: config.owner }),
171
169
  ...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
170
+ // Owner ruling D3 on #256: `pageWriter.mode: off` stops the reflection's page write too.
171
+ ...(config.pageWriter?.mode === undefined ? {} : { pageWriterMode: config.pageWriter.mode }),
172
172
  ...(config.identity === undefined
173
173
  ? {}
174
174
  : { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
@@ -1874,3 +1874,15 @@ found a paraphrase only by the words it shared. It now opens its store with the
1874
1874
  the store's own, at open: a store whose box 3 holds another model's vectors withdraws
1875
1875
  the embedder, and the note lands with words only. Missing weights: the note lands with
1876
1876
  words only and prints nothing about it — doctor and the backfill name a missing table.
1877
+
1878
+ ## 2026-09-27 — trait nudges in the export and `fired` (working defaults)
1879
+
1880
+ - **`export --markdown` carries a memory's nudges** as a `## Traits` list after its
1881
+ `## Feelings` (`1. agreeable-candid → candid · 0.6 — carried by: …`). The row is only
1882
+ there when it is not confidential or the owner passed `--include-confidential`, so the
1883
+ section reads with its words.
1884
+ - **`fired` gained one row, `traits`** ("a memory that showed how I acted was given a
1885
+ trait nudge"), a probe over live memories dated by the newest nudge. It is plumbing in
1886
+ `counterparts mechanisms` (no mechanism line of its own: traits feed nothing), so it
1887
+ shows in the plumbing count and in `mechanisms --all`. No doctor line: nothing there
1888
+ fits without forcing it.
@@ -197,7 +197,9 @@ import type { RemovalPlan } from "./removal.js";
197
197
  import { repairDates } from "./repair-dates.js";
198
198
  import type { Confidence } from "./repair-dates.js";
199
199
  import { NO_PAGE_LINES, bodyFrom, pageLines, versionLines, writeLines } from "./self-page.js";
200
- import { coreListLines, dreamListLines, dreamShowLines } from "./dream-core.js";
200
+ import { coreListLines, dreamListLines, dreamShowLines, dreamingSettingWords } from "./dream-core.js";
201
+ import { DREAMING_SETTINGS } from "../../core/dream/index.js";
202
+ import { REFLECTED_FEELING_KEY } from "../../core/sleep/index.js";
201
203
  // The console's shared manners (2026-09-21): is there a person here, ask them,
202
204
  // and say one marked line back.
203
205
  import { ask, confirm, isInteractive, isPromptAborted, paint, typed, ui } from "./ui.js";
@@ -716,8 +718,8 @@ export const COMMAND_FLAGS: Record<Command, readonly string[]> = {
716
718
  // line is a page in shell history, and prose that is injected into every
717
719
  // session does not belong there.
718
720
  "self-page": ["write", "file", "stdin", "reason", "versions", "version", "restore", "clear", "if-version"],
719
- dream: ["list", "show", "undo"],
720
- core: ["list", "demote", "reason"],
721
+ dream: ["list", "show", "undo", "all", "setting"],
722
+ core: ["list", "demote", "reason", "reflected-feeling"],
721
723
  // `--config` because the store it opens is the one the CONFIGURATION names —
722
724
  // that is the whole point of the command over `counterparts-dashboard serve`,
723
725
  // which refuses until you name a store. `--dir` still parses (it is common)
@@ -782,9 +784,9 @@ export const COMMAND_BLURB: Record<Command, string> = {
782
784
  "self-page":
783
785
  "The written page the wake opens with. With no flags it prints the page, its date and its size; --write --file <path> or --write --stdin replaces it whole, keeping every earlier version; --versions lists those and --version <seq> prints one. Reading works under observer; writing refuses there.",
784
786
  dream:
785
- "What each dream did, and its undo. With no flags (or --list), the recent dreams: date, state, title and what changed; --show <id> prints one dream's journal and every change it made; --undo <id> reverses that dream's whole batch (merges come apart, links and gists go, replays and nominations are taken back) and keeps its journal, marked undone. Reading works under observer; --undo refuses there.",
787
+ "What each dream did, and its undo — and what the waking self made of it. With no flags (or --list), the newest 20 dreams (--list --all for every one): date, state, title and what changed, then the recent reflections; --show <id> prints one dream's journal, every change it made and the reflection after it (--show <rfl_…> prints one reflection: its questions, entry, what it rests on and its morning share); --undo <id> reverses that dream's whole batch (merges come apart, links and gists go, replays and nominations are taken back) and keeps its journal, marked undone — a reflection is lived and stays. Reading works under observer; --undo refuses there.",
786
788
  core:
787
- "The core — the memories about me and about us that do not fade. With no flags (or --list), what it holds and which lane carried each one there, what dreams have nominated, and what you sent back; --demote <id> --reason \"...\" sends one back to ordinary fading from today, records why, and keeps the lanes from promoting it again. Reading works under observer; --demote refuses there.",
789
+ "The core — the memories about me, about us and about the owner that do not fade. With no flags (or --list), what it holds and which lane carried each one there, what dreams have nominated, and what you sent back; --demote <id> --reason \"...\" sends one back to ordinary fading from today, records why, and keeps the lanes from promoting it again; --reflected-feeling on|off opens or closes the core to reflection alone. On (the default): a feeling a reflection records later and a reflection citing a memory both count toward the fast lane, and a reflection may re-label what a memory is about either way — each re-label is recorded with its reason, and one into me, us or the owner is told in the next morning share. Off: nothing reaches the core on a reflection alone — the fast lane needs a feeling felt at the time (not one a reflection recorded later) and an ordinary use after a gap (not a reflection citing it), and a reflection may only move what a memory is about toward work or world. Reading works under observer; the two changes refuse there.",
788
790
  dashboard:
789
791
  "Open the dashboard in your browser: the web view of the store your configuration names, served on 127.0.0.1 and nowhere else. Ctrl-C stops it. Looking is read-only — it strengthens nothing and deposits nothing. What you do there on purpose (write a note, remove a memory, back up, …) runs through these same commands, and a removal asks you to type the id back.",
790
792
  version: "The version of Counterparts you have. It opens nothing.",
@@ -808,8 +810,8 @@ const COMMAND_ARGS: Partial<Record<Command, string>> = {
808
810
  connect: " [claude-code]",
809
811
  disconnect: " [claude-code]",
810
812
  help: " [advanced | <command>]",
811
- dream: " [--show <id> | --undo <id>]",
812
- core: " [--demote <id> --reason \"...\"]",
813
+ dream: " [--list [--all] | --show <id> | --undo <id>]",
814
+ core: " [--demote <id> --reason \"...\" | --reflected-feeling on|off]",
813
815
  };
814
816
 
815
817
  /**
@@ -1017,18 +1019,22 @@ const START_FRESH_FLAG_HELP: Record<string, string> = {
1017
1019
  * and it is the one the hooks and the memory tools open. Printing the shared
1018
1020
  * sentence would describe a resolution this command does not use.
1019
1021
  */
1020
- /** `dream`'s own three: `--list` and `--undo` mean something else on other pages. */
1022
+ /** `dream`'s own four: `--list` and `--undo` mean something else on other pages. */
1021
1023
  const DREAM_FLAG_HELP: Record<string, string> = {
1022
1024
  list: "the recent dreams, newest first — the default",
1025
+ all: "with --list: every dream the store holds, not only the newest 20",
1023
1026
  show: "one dream, by id: its journal and every change it made",
1024
1027
  undo: "reverse one dream's whole batch, by id (the id follows the flag); its journal is kept, marked undone",
1028
+ setting:
1029
+ "auto, ask or off — the nightly run (page writer, dream, reflection). auto (the default): the first session of a day starts it in the background and says so in one line; ask: the session asks you first; off: no dreams. `counterparts dream` prints the setting.",
1025
1030
  };
1026
1031
 
1027
- /** `core`'s own three. */
1032
+ /** `core`'s own four. */
1028
1033
  const CORE_FLAG_HELP: Record<string, string> = {
1029
1034
  list: "what the core holds, with lanes, nominations and demotions — the default",
1030
1035
  demote: "send one core memory back to ordinary fading from today, by id; needs --reason",
1031
1036
  reason: "why — recorded with the demotion, and shown by --list",
1037
+ "reflected-feeling": "on or off — can a memory reach the core on reflection alone? On (the default): a feeling a reflection records later and a reflection citing a memory both count toward the fast lane, and a reflection may re-label what a memory is about either way — each re-label is recorded with its reason, and one into me, us or the owner is told in the next morning share. Off: nothing reaches the core on a reflection alone — the fast lane needs a feeling felt at the time (not one a reflection recorded later) and an ordinary use after a gap (not a reflection citing it), and a reflection may only move what a memory is about toward work or world.",
1032
1038
  };
1033
1039
 
1034
1040
  const DASHBOARD_FLAG_HELP: Record<string, string> = {
@@ -1321,6 +1327,12 @@ export function parse(argv: readonly string[]): Parsed {
1321
1327
  // --undo` reuses `start-fresh`'s boolean and takes the id positionally.
1322
1328
  show: { type: "string" },
1323
1329
  demote: { type: "string" },
1330
+ // `core --reflected-feeling on|off` (2026-09-27): a string, so a bare
1331
+ // flag is a refusal rather than a `true` read as a choice.
1332
+ "reflected-feeling": { type: "string" },
1333
+ // `dream --setting auto|ask|off` (2026-09-28): a string, like
1334
+ // `--reflected-feeling`. `counterparts dream` prints the setting.
1335
+ setting: { type: "string" },
1324
1336
  observer: { type: "boolean" },
1325
1337
  help: { type: "boolean" },
1326
1338
  // `scope`'s five. Declared as booleans for the same reason `rebuild` is:
@@ -1916,10 +1928,11 @@ function probeCommand(dir: string, io: Io, namedDir: boolean): number {
1916
1928
  return EXIT.failed;
1917
1929
  }
1918
1930
  try {
1919
- // Explicit ceiling: `eventLog` defaults to 500 oldest-first, which would
1920
- // drop the newest rows — the side of the table the probe exists to read.
1921
- const decisions = store.eventLog({ name: RECALL_DECISION_EVENT, limit: PROBE_ROW_CEILING });
1922
- const credits = store.eventLog({ name: RECALL_CREDIT_EVENT, limit: PROBE_ROW_CEILING });
1931
+ // Explicit ceiling, read NEWEST first and turned back to oldest first: an
1932
+ // ascending read with a limit drops the newest rows — the side of the
1933
+ // table the probe exists to read.
1934
+ const decisions = store.eventLog({ name: RECALL_DECISION_EVENT, order: "desc", limit: PROBE_ROW_CEILING }).reverse();
1935
+ const credits = store.eventLog({ name: RECALL_CREDIT_EVENT, order: "desc", limit: PROBE_ROW_CEILING }).reverse();
1923
1936
  const rows = [...decisions, ...credits].map((r) => ({ name: r.name, day: r.day, payload: r.payload }));
1924
1937
  for (const line of renderProbe(probeOQ4(rows))) io.out(line);
1925
1938
  for (const [name, got] of [
@@ -1927,7 +1940,7 @@ function probeCommand(dir: string, io: Io, namedDir: boolean): number {
1927
1940
  [RECALL_CREDIT_EVENT, credits.length],
1928
1941
  ] as const) {
1929
1942
  if (got >= PROBE_ROW_CEILING) {
1930
- io.err(`warning: ${name} hit the ${PROBE_ROW_CEILING}-row ceiling; the newest rows may be missing from this table`);
1943
+ io.err(`warning: ${name} hit the ${PROBE_ROW_CEILING}-row ceiling; the oldest rows are missing from this table`);
1931
1944
  }
1932
1945
  }
1933
1946
  return EXIT.ok;
@@ -1996,10 +2009,36 @@ function dreamCommand(dir: string, io: Io, parsed: Parsed, observer: boolean, na
1996
2009
  const show = parsed.flags["show"];
1997
2010
  const undo = parsed.flags["undo"] === true;
1998
2011
  const undoId = typeof parsed.flags["undo"] === "string" ? parsed.flags["undo"] : parsed.positional[0];
2012
+ const setting = parsed.flags["setting"];
1999
2013
  if (typeof show === "string" && undo) {
2000
2014
  io.err("refused: --show and --undo are two different things to do. Pass one.");
2001
2015
  return EXIT.usage;
2002
2016
  }
2017
+ if (setting !== undefined) {
2018
+ // THE OWNER'S SETTING (2026-09-28): the same value the dream tool's
2019
+ // `setting` phase writes ("no dreams" in conversation).
2020
+ if (typeof setting !== "string" || !(DREAMING_SETTINGS as readonly string[]).includes(setting)) {
2021
+ io.err("refused: --setting takes auto, ask or off.");
2022
+ return EXIT.usage;
2023
+ }
2024
+ if (observer) {
2025
+ io.err("refused: this console is an observer; it reads and changes nothing. Nothing was changed.");
2026
+ return EXIT.refused;
2027
+ }
2028
+ const counterpart = openCounterpart(dir, observer);
2029
+ try {
2030
+ const out = counterpart.dreams.setSetting(setting, { by: "owner" });
2031
+ if (!out.ok) {
2032
+ io.err(`refused: ${out.reason}. Nothing was changed.`);
2033
+ return EXIT.refused;
2034
+ }
2035
+ io.out(`Dreaming: ${out.setting}${out.before === out.setting ? " (it already was)" : ` (was ${out.before})`}.`);
2036
+ io.out(` ${dreamingSettingWords(out.setting)}`);
2037
+ return EXIT.ok;
2038
+ } finally {
2039
+ counterpart.close();
2040
+ }
2041
+ }
2003
2042
  if (undo) {
2004
2043
  if (undoId === undefined || undoId.length === 0) {
2005
2044
  io.err("refused: --undo needs the dream's id after it (counterparts dream --list shows them).");
@@ -2048,7 +2087,7 @@ function dreamCommand(dir: string, io: Io, parsed: Parsed, observer: boolean, na
2048
2087
  for (const line of lines) io.out(line);
2049
2088
  return EXIT.ok;
2050
2089
  }
2051
- for (const line of dreamListLines(counterpart)) io.out(line);
2090
+ for (const line of dreamListLines(counterpart, parsed.flags["all"] === true ? "all" : undefined)) io.out(line);
2052
2091
  return EXIT.ok;
2053
2092
  } finally {
2054
2093
  counterpart.close();
@@ -2067,6 +2106,30 @@ function coreCommand(dir: string, io: Io, parsed: Parsed, observer: boolean, nam
2067
2106
  }
2068
2107
  const demote = parsed.flags["demote"];
2069
2108
  const reason = parsed.flags["reason"];
2109
+ const reflected = parsed.flags["reflected-feeling"];
2110
+ if (reflected !== undefined) {
2111
+ if (reflected !== "on" && reflected !== "off") {
2112
+ io.err("refused: --reflected-feeling takes on or off.");
2113
+ return EXIT.usage;
2114
+ }
2115
+ if (observer) {
2116
+ io.err("refused: this console is an observer; it reads and changes nothing. Nothing was changed.");
2117
+ return EXIT.refused;
2118
+ }
2119
+ const counterpart = openCounterpart(dir, observer);
2120
+ try {
2121
+ counterpart.store.setMeta(REFLECTED_FEELING_KEY, reflected);
2122
+ io.out(
2123
+ reflected === "on"
2124
+ ? "On: a feeling a reflection records later and a reflection citing a memory both count toward the fast lane, and a reflection may re-label what a memory is about either way — each re-label is recorded with its reason, and one into me, us or the owner is told in the next morning share."
2125
+ : "Off: nothing reaches the core on a reflection alone — the fast lane needs a feeling felt at the time (not one a reflection recorded later) and an ordinary use after a gap (not a reflection citing it), and a reflection may only move what a memory is about toward work or world.",
2126
+ );
2127
+ io.out(" It takes effect at the next consolidation. Nothing already in the core moves.");
2128
+ return EXIT.ok;
2129
+ } finally {
2130
+ counterpart.close();
2131
+ }
2132
+ }
2070
2133
  if (reason !== undefined && typeof demote !== "string") {
2071
2134
  io.err("refused: --reason goes with a --demote. Pass one, or leave it out.");
2072
2135
  return EXIT.usage;
@@ -2384,12 +2447,14 @@ export function firedLines(report: FiredReport, all = false): string[] {
2384
2447
  * become the thing that throws, and it may not guess either. */
2385
2448
  function newestBoundary(store: Store, livedDay: number): string | null {
2386
2449
  try {
2387
- const rows = store.eventLog({
2450
+ // The newest row itself: `rows.at(-1)` of an ascending read with a limit
2451
+ // was the 2,000th-oldest row of the window once it held more.
2452
+ const [last] = store.eventLog({
2388
2453
  name: BOUNDARY_EVENT,
2389
2454
  sinceDay: Math.max(0, livedDay - 30),
2390
- limit: 2000,
2455
+ order: "desc",
2456
+ limit: 1,
2391
2457
  });
2392
- const last = rows[rows.length - 1];
2393
2458
  if (last === undefined) return null;
2394
2459
  const payload = JSON.parse(last.payload ?? "{}") as Record<string, unknown>;
2395
2460
  const date = payload["date"];
@@ -7732,8 +7797,7 @@ function mergedBeliefs(store: Store): MergedBelief[] {
7732
7797
 
7733
7798
  /** The last `memory.merged` record naming this id, in ids and numbers. */
7734
7799
  function mergeRecordOf(store: Store, id: string): { originalId: string | null; day: number | null } {
7735
- const rows = store.eventLog({ name: "memory.merged", ref: id });
7736
- const last = rows[rows.length - 1];
7800
+ const [last] = store.eventLog({ name: "memory.merged", ref: id, order: "desc", limit: 1 });
7737
7801
  if (last === undefined || last.payload === null) return { originalId: null, day: null };
7738
7802
  try {
7739
7803
  const parsed = JSON.parse(last.payload) as Record<string, unknown>;