counterparts 0.3.13 → 0.3.15

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 (106) hide show
  1. package/CHANGELOG.md +264 -0
  2. package/docs/QUICKSTART.md +22 -0
  3. package/docs/README.md +1 -0
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +48 -0
  6. package/src/adapters/claude-code/NOTES.md +148 -0
  7. package/src/adapters/claude-code/bin/hook.mjs +4 -2
  8. package/src/adapters/claude-code/bin/hook.ts +61 -7
  9. package/src/adapters/claude-code/bin/nightly.ts +5 -1
  10. package/src/adapters/claude-code/bin/runner.ts +11 -3
  11. package/src/adapters/claude-code/claim.ts +319 -0
  12. package/src/adapters/claude-code/doctor.ts +170 -16
  13. package/src/adapters/claude-code/embed-client.ts +3 -0
  14. package/src/adapters/cli/CONTRACT.md +5 -0
  15. package/src/adapters/cli/NOTES.md +25 -0
  16. package/src/adapters/cli/bin/counterparts.mjs +4 -2
  17. package/src/adapters/cli/bin/counterparts.ts +49 -3
  18. package/src/adapters/cli/commands.ts +169 -32
  19. package/src/adapters/cli/desktop.ts +112 -7
  20. package/src/adapters/cli/help.ts +10 -0
  21. package/src/adapters/cli/index.ts +1 -0
  22. package/src/adapters/cli/install.ts +94 -14
  23. package/src/adapters/cli/self-page.ts +5 -8
  24. package/src/adapters/cli/settle.ts +39 -2
  25. package/src/adapters/cli/wire.ts +18 -1
  26. package/src/adapters/config.ts +29 -1
  27. package/src/adapters/dashboard/NOTES.md +33 -0
  28. package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
  29. package/src/adapters/dashboard/bin/dashboard.ts +11 -3
  30. package/src/adapters/dashboard/index.ts +14 -0
  31. package/src/adapters/dashboard/registries.ts +3 -0
  32. package/src/adapters/dashboard/source.ts +0 -8
  33. package/src/adapters/dashboard/web/fired.ts +8 -0
  34. package/src/adapters/dashboard/web/flow.ts +1 -0
  35. package/src/adapters/dashboard/web/lanes.ts +1 -0
  36. package/src/adapters/dashboard/web/narrate.ts +11 -0
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
  38. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
  39. package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
  40. package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
  41. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
  43. package/src/adapters/dashboard/web/server.ts +16 -4
  44. package/src/adapters/dashboard/web/shared/dates.js +6 -16
  45. package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
  46. package/src/adapters/dashboard/web/views/health.ts +19 -5
  47. package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
  48. package/src/adapters/dashboard/web/views/memories.ts +26 -7
  49. package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
  50. package/src/adapters/dashboard/web/views/memory.ts +51 -2
  51. package/src/adapters/dashboard/web/views/mind.ts +38 -6
  52. package/src/adapters/empty-bunfig.toml +5 -0
  53. package/src/adapters/fired.ts +16 -2
  54. package/src/adapters/host-wiring.ts +112 -17
  55. package/src/adapters/log/index.ts +2 -2
  56. package/src/adapters/mcp/CONTRACT.md +17 -2
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
  58. package/src/adapters/mcp/NOTES.md +269 -0
  59. package/src/adapters/mcp/bin/serve.mjs +4 -2
  60. package/src/adapters/mcp/bin/serve.ts +17 -6
  61. package/src/adapters/mcp/facts.ts +72 -4
  62. package/src/adapters/mcp/meaning.ts +218 -15
  63. package/src/adapters/mcp/server.ts +21 -6
  64. package/src/adapters/mcp/tools.ts +86 -61
  65. package/src/adapters/plugin-run.sh +413 -34
  66. package/src/adapters/plugin.ts +141 -17
  67. package/src/adapters/runtime.ts +192 -17
  68. package/src/adapters/sessions.ts +2 -2
  69. package/src/core/associate/NOTES.md +10 -0
  70. package/src/core/bridge.ts +1 -1
  71. package/src/core/briefing.ts +20 -3
  72. package/src/core/contradictions.ts +56 -20
  73. package/src/core/counterpart.ts +72 -23
  74. package/src/core/dream/CONTRACT.md +6 -14
  75. package/src/core/dream/INTERFACE-GAPS.md +3 -2
  76. package/src/core/dream/NOTES.md +10 -0
  77. package/src/core/dream/index.ts +11 -53
  78. package/src/core/dream/reflect.ts +11 -2
  79. package/src/core/embed/static.ts +5 -1
  80. package/src/core/encode/INTERFACE-GAPS.md +2 -1
  81. package/src/core/encode/NOTES.md +12 -0
  82. package/src/core/encode/chunk.ts +6 -30
  83. package/src/core/encode/index.ts +0 -1
  84. package/src/core/encode/types.ts +1 -13
  85. package/src/core/handoff/INTERFACE-GAPS.md +1 -1
  86. package/src/core/handoff/index.ts +2 -1
  87. package/src/core/handoff/last-here.ts +18 -2
  88. package/src/core/physics/CONTRACT.md +6 -0
  89. package/src/core/physics/NOTES.md +33 -2
  90. package/src/core/physics/index.ts +22 -7
  91. package/src/core/prospective/CONTRACT.md +3 -1
  92. package/src/core/prospective/NOTES.md +15 -0
  93. package/src/core/recall/activate.ts +1 -1
  94. package/src/core/recall/time-ask.ts +173 -19
  95. package/src/core/self/CONTRACT.md +56 -19
  96. package/src/core/self/NOTES.md +172 -0
  97. package/src/core/self/behind.ts +6 -3
  98. package/src/core/self/briefing.ts +384 -28
  99. package/src/core/self/index.ts +105 -44
  100. package/src/core/self/page.ts +12 -85
  101. package/src/core/self/tunables.ts +16 -19
  102. package/src/core/self/writer.ts +31 -4
  103. package/src/core/sleep/NOTES.md +32 -0
  104. package/src/core/store/NOTES.md +21 -2
  105. package/src/core/store/index.ts +2 -1
  106. package/src/core/time.ts +15 -0
@@ -747,19 +747,51 @@ export function heldView(row: Pick<MemoryRow, "title" | "body" | "confidential">
747
747
  return { title, text: excerptOf(row.body, CONTRADICTION_TUNABLES.HELD_TEXT_CHARS) };
748
748
  }
749
749
 
750
+ /** One held `updates`, as its durable row recorded it (`CONTRADICTION_HELD_EVENT`). */
751
+ export interface HeldPair {
752
+ readonly seq: number;
753
+ /** The lived day it was held. */
754
+ readonly day: number;
755
+ /** The new memory, which said it changed or corrected… */
756
+ readonly holds: string;
757
+ /** …this one, which looked unrelated and was left as it was. */
758
+ readonly over: string;
759
+ readonly how: string;
760
+ /** Which reading decided: `meaning` or `words`. */
761
+ readonly by: string;
762
+ /** Settled by hand afterwards (a `contradiction.settled` row naming the same two). */
763
+ readonly settledAfter: boolean;
764
+ }
765
+
750
766
  /**
751
- * HOW OFTEN THE GUARD FIRED — a reader for doctor or the dashboard, which
752
- * neither calls yet (owed: `mcp/INTERFACE-GAPS.md`). Holds since `sinceDay`,
753
- * by which reading, and how many of them the writer settled by hand
754
- * afterwards (a `contradiction.settled` row naming the same two memories): a
755
- * hold later settled is most likely a related pair the guard got wrong; one
756
- * never settled is a wrong pointer caught, or a writer that had no one to
757
- * read its result (a write-up, the nightly catch-up).
767
+ * HOW OFTEN THE GUARD FIRED — doctor's Contradictions line reads it
768
+ * (2026-10-09). Holds since `sinceDay`, by which reading, and how many of them
769
+ * the writer settled by hand afterwards (a `contradiction.settled` row naming
770
+ * the same two memories): a hold later settled is most likely a related pair
771
+ * the guard got wrong; one never settled is a wrong pointer caught, or a
772
+ * writer that had no one to read its result (a write-up, the nightly
773
+ * catch-up). `settledAfter / held` is the number that says whether the bar
774
+ * (`UPDATE_COSINE`) holds back real corrections.
758
775
  */
759
776
  export function heldCorrections(
760
777
  store: Pick<Store, "eventLog">,
761
778
  opts: { sinceDay?: number } = {},
762
779
  ): { held: number; settledAfter: number; byMeaning: number; byWords: number } {
780
+ const holds = heldPairs(store, opts);
781
+ return {
782
+ held: holds.length,
783
+ settledAfter: holds.filter((h) => h.settledAfter).length,
784
+ byMeaning: holds.filter((h) => h.by === "meaning").length,
785
+ byWords: holds.filter((h) => h.by === "words").length,
786
+ };
787
+ }
788
+
789
+ /**
790
+ * Every hold since `sinceDay`, NEWEST first, each with whether it was settled
791
+ * by hand afterwards — what `counterparts settle` lists, so the owner can
792
+ * settle one the guard held and was meant (`--holds <new> --against <old>`).
793
+ */
794
+ export function heldPairs(store: Pick<Store, "eventLog">, opts: { sinceDay?: number } = {}): HeldPair[] {
763
795
  const limit = CONTRADICTION_TUNABLES.HELD_READ_ROWS;
764
796
  const read = (raw: string | null): Record<string, unknown> => {
765
797
  try {
@@ -768,8 +800,12 @@ export function heldCorrections(
768
800
  return {};
769
801
  }
770
802
  };
771
- // The newest holds, and every settle from the day of the oldest of them on
772
- // (`eventLog` reads 500 rows unless told otherwise, oldest first).
803
+ // The newest holds, and the settles from the day of the oldest of them on —
804
+ // both read NEWEST first (`eventLog` reads 500 rows unless told otherwise,
805
+ // oldest first). Past the limit an ascending settle read kept the oldest
806
+ // and dropped the newest, so the newest holds read as never settled
807
+ // (2026-10-09, audit #1's last caller). Under the limit the same rows come
808
+ // back, and `settledAfter` does not depend on their order.
773
809
  const holds = store
774
810
  .eventLog({ name: CONTRADICTION_HELD_EVENT, ...(opts.sinceDay === undefined ? {} : { sinceDay: opts.sinceDay }), order: "desc", limit })
775
811
  .map((e) => ({ seq: e.seq, day: e.day, p: read(e.payload) }));
@@ -777,15 +813,15 @@ export function heldCorrections(
777
813
  const settles =
778
814
  holds.length === 0
779
815
  ? []
780
- : store.eventLog({ name: CONTRADICTION_SETTLED_EVENT, sinceDay: from, limit }).map((e) => ({ seq: e.seq, p: read(e.payload) }));
781
- let settledAfter = 0;
782
- for (const h of holds) {
783
- if (settles.some((s) => s.seq > h.seq && s.p["holds"] === h.p["holds"] && s.p["over"] === h.p["over"])) settledAfter += 1;
784
- }
785
- return {
786
- held: holds.length,
787
- settledAfter,
788
- byMeaning: holds.filter((h) => h.p["by"] === "meaning").length,
789
- byWords: holds.filter((h) => h.p["by"] === "words").length,
790
- };
816
+ : store.eventLog({ name: CONTRADICTION_SETTLED_EVENT, sinceDay: from, order: "desc", limit }).map((e) => ({ seq: e.seq, p: read(e.payload) }));
817
+ const str = (v: unknown): string => (typeof v === "string" ? v : "");
818
+ return holds.map((h) => ({
819
+ seq: h.seq,
820
+ day: h.day,
821
+ holds: str(h.p["holds"]),
822
+ over: str(h.p["over"]),
823
+ how: str(h.p["how"]),
824
+ by: str(h.p["by"]),
825
+ settledAfter: settles.some((s) => s.seq > h.seq && s.p["holds"] === h.p["holds"] && s.p["over"] === h.p["over"]),
826
+ }));
791
827
  }
@@ -140,7 +140,7 @@ import {
140
140
  } from "./handoff/index.js";
141
141
  import type { Handoff, HandoffRefusal, HandoffWrite, PointerSince } from "./handoff/index.js";
142
142
  import { CLAIM_CHAPTER, askFromStretch, chapterClaims, claimUnwritten, sessionStretch, sessionsHere, workSince } from "./coverage/index.js";
143
- import { LAST_HERE_LIFE_DAYS, LAST_HERE_NOROOM_EVENT, chaptersBySession, chaptersHere, chaptersOn, elsewhereLine, lastHereLadder, yesterdayLine } from "./handoff/last-here.js";
143
+ import { LAST_HERE_LIFE_DAYS, LAST_HERE_NOROOM_EVENT, chaptersBySession, chaptersHere, chaptersOn, elsewhereLine, lastHereLadder, yesterdayLine, yesterdayShorter } from "./handoff/last-here.js";
144
144
  import type { ChapterHere, LastHere } from "./handoff/last-here.js";
145
145
  import { addDays, isDay, localStamp, localStampAfter } from "./time.js";
146
146
  import type { Recurrence } from "./time.js";
@@ -583,6 +583,16 @@ export interface ContiguityPass {
583
583
  export const SPAWN_REFUSED_EVENT = "adapter.spawn.refused";
584
584
  export const SPAWN_FAILED_EVENT = "adapter.spawn.failed";
585
585
  export const RUNNER_FAILED_EVENT = "adapter.runner.failed";
586
+ /**
587
+ * A HOOK THAT FOUND ITS EVENT ALREADY TAKEN (2026-10-09): two wirings of
588
+ * Counterparts are live in one host (the npm install's hooks and the
589
+ * plugin's, any two builds), both fired, and this one lost the per-event
590
+ * claim and delivered nothing. One row per suppressed duplicate — the hook,
591
+ * the session, which side lost and which won; never a word of the prompt.
592
+ * Written by `adapters/claude-code/claim.ts`; read by doctor's `Installed
593
+ * twice` line.
594
+ */
595
+ export const HOOK_CLAIM_LOST_EVENT = "adapter.hook.claim.lost";
586
596
  /**
587
597
  * A WRITE-UP POINTER THAT COULD NOT BE COMPOSED (2026-09-30), durable because
588
598
  * "was this session ever offered its write-up" is a fact a later reading needs
@@ -853,6 +863,7 @@ export type AdapterDurableEventName =
853
863
  | typeof SPAWN_FAILED_EVENT
854
864
  | typeof SPAWN_STARTED_EVENT
855
865
  | typeof RUNNER_FAILED_EVENT
866
+ | typeof HOOK_CLAIM_LOST_EVENT
856
867
  | typeof WRITE_UP_FAILED_EVENT
857
868
  | typeof MCP_RECALL_EVENT
858
869
  | typeof MCP_PART_EVENT
@@ -1968,7 +1979,9 @@ export class Counterpart {
1968
1979
  });
1969
1980
  return written.written && written.version !== null
1970
1981
  ? { ok: true, version: written.version }
1971
- : { ok: false, reason: written.reason };
1982
+ : written.reason === "too-large"
1983
+ ? { ok: false, reason: written.reason, bytes: written.bytes, limit: this.self.tunables.PAGE_MAX_BYTES }
1984
+ : { ok: false, reason: written.reason };
1972
1985
  },
1973
1986
  emit: (name, ref, data) => this.emit(name, ref, data),
1974
1987
  });
@@ -2389,15 +2402,23 @@ export class Counterpart {
2389
2402
  * id, the date in the line (`handoff/last-here.ts#yesterdayLine`). Undefined
2390
2403
  * without a date or a chapter that day; never throws — a store that will not
2391
2404
  * answer composes the wake without it.
2405
+ *
2406
+ * Its SHORTER FORMS ride beside it (review of #350, 2026-10-09): fewer
2407
+ * titles, the rest by count, for the wake to step down only when "Still
2408
+ * open" would otherwise list nothing (`handoff/last-here.ts#yesterdayShorter`).
2392
2409
  */
2393
- private yesterdayFor(at: string | undefined): string | undefined {
2394
- if (at === undefined || !isDay(at)) return undefined;
2410
+ private yesterdayFor(at: string | undefined): { yesterday?: string; yesterdayShorter?: string[] } {
2411
+ if (at === undefined || !isDay(at)) return {};
2395
2412
  try {
2396
2413
  const date = addDays(at, -1);
2397
2414
  const fromDay = Math.max(0, this.store.livedDay() - LAST_HERE_LIFE_DAYS + 1);
2398
- return yesterdayLine(chaptersOn(this.store, date, { fromDay }), date) ?? undefined;
2415
+ const day = chaptersOn(this.store, date, { fromDay });
2416
+ const line = yesterdayLine(day, date);
2417
+ if (line === null) return {};
2418
+ const shorter = yesterdayShorter(day, date);
2419
+ return shorter.length === 0 ? { yesterday: line } : { yesterday: line, yesterdayShorter: shorter };
2399
2420
  } catch {
2400
- return undefined;
2421
+ return {};
2401
2422
  }
2402
2423
  }
2403
2424
 
@@ -2590,7 +2611,7 @@ export class Counterpart {
2590
2611
  * pointer cost more than the eighth it could already. With no handoff and
2591
2612
  * no chapter here inside the fortnight, the reserve is zero as before.
2592
2613
  */
2593
- private wakeReserveBytes(budgetBytes: number): number {
2614
+ private wakeReserveBytes(budgetBytes: number, work = this.workReserveBytes(budgetBytes)): number {
2594
2615
  const norm = (s: string): string => s.trim().replace(/\/+$/, "");
2595
2616
  const blocks: number[] = [];
2596
2617
  let byScope = new Map<string, number[]>();
@@ -2620,7 +2641,7 @@ export class Counterpart {
2620
2641
  } catch {
2621
2642
  /* no chapter lines is the reserve as it was */
2622
2643
  }
2623
- return PREFACE_RESERVE_BYTES + reserveBytes(blocks, budgetBytes) + this.workReserveBytes(budgetBytes);
2644
+ return PREFACE_RESERVE_BYTES + reserveBytes(blocks, budgetBytes) + work;
2624
2645
  }
2625
2646
 
2626
2647
  /**
@@ -2864,6 +2885,14 @@ export class Counterpart {
2864
2885
  const first = this.prospective.occurrenceUndelivered(reminder.memoryId, reminder.windowKey);
2865
2886
  const claimed = this.prospective.claimPlain(reminder, { at: input.at, day });
2866
2887
  if (claimed && first) this.creditOccurrence(reminder.memoryId, reminder.windowKey, day, "plain");
2888
+ // TOLD ON ITS DAY, IT LEAVES "ARRIVING:" (2026-09-29) — and the wake
2889
+ // published before the telling still lists it, until something
2890
+ // re-renders. A day's first render can come before the day's first tell
2891
+ // (a late session's turn ending after midnight), and on 2026-10-09 a
2892
+ // reminder said outright on the 8th was still under "Arriving:" the next
2893
+ // morning. So the telling marks the wake behind, and the next turn-end
2894
+ // worker re-renders it (`refreshWake`).
2895
+ if (claimed && reminder.beat !== "opens") markWakeBehind(this.store, "told");
2867
2896
  return claimed;
2868
2897
  } catch (err) {
2869
2898
  this.emit("counterpart.prospective.plain.failed", reminder.memoryId, { code: errCode(err) });
@@ -4037,9 +4066,10 @@ export class Counterpart {
4037
4066
 
4038
4067
  /**
4039
4068
  * THE RUN MOVED PAST THE WRITER WITHOUT A WRITE (review of #271): this
4040
- * session's open claim is closed as `nothing-to-say`, so the night is
4041
- * answered and a later `self_page` write by the session is an ordinary
4042
- * amendment, not the writer's. Called at the phase after the writer (the
4069
+ * session's open claim is closed as `nothing-to-say` — or as `failed` when
4070
+ * the session's write was refused and not sent again (review of #358) — so
4071
+ * the night is answered and a later `self_page` write by the session is an
4072
+ * ordinary amendment, not the writer's. Called at the phase after the writer (the
4043
4073
  * dream's `begin`, the reflection's `begin`). Nothing when there is no open
4044
4074
  * claim — the writer wrote, or never claimed. Never throws.
4045
4075
  */
@@ -4049,11 +4079,24 @@ export class Counterpart {
4049
4079
  const open = this.self.nightClaimFor(input.session);
4050
4080
  if (open === null) return false;
4051
4081
  const page = this.self.page();
4082
+ // A REFUSED WRITE IS NOT "NOTHING TO SAY" (review of #358). A refusal
4083
+ // keeps the claim open so the same run can send the page again; a run
4084
+ // that moved on instead had something to say and did not get it
4085
+ // written, so the night closes as `failed`, carrying the refusal — for a
4086
+ // page refused for length, its bytes and how far over the limit it was.
4087
+ // Closed as `nothing-to-say`, it read as a quiet night and doctor went
4088
+ // green over a page that was never written.
4089
+ const refused = this.self
4090
+ .pageWriterRuns({ about: open.about })
4091
+ .find((r) => r.outcome === "refused" && (r.at > open.at || (r.at === open.at && r.seq > open.seq)));
4052
4092
  return this.self.recordPageWriterRun({
4053
4093
  about: open.about,
4054
4094
  mode: open.mode,
4055
- outcome: "nothing-to-say",
4056
- detail: `the run moved on to ${input.phase} without writing`,
4095
+ outcome: refused === undefined ? "nothing-to-say" : "failed",
4096
+ detail:
4097
+ refused === undefined
4098
+ ? `the run moved on to ${input.phase} without writing`
4099
+ : `${refused.detail === "" ? "refused" : refused.detail}; not sent again before the run moved on to ${input.phase}`,
4057
4100
  bytesBefore: open.bytesBefore,
4058
4101
  bytesAfter: page === null ? 0 : byteLength(page.body),
4059
4102
  considered: open.considered,
@@ -4210,8 +4253,12 @@ export class Counterpart {
4210
4253
  async sessionEnd(input: SessionEndInput = {}): Promise<SessionEndReport> {
4211
4254
  const budgetBytes = input.budgetBytes ?? this.reportedBudget;
4212
4255
  if (input.budgetBytes !== undefined) this.reportedBudget = input.budgetBytes;
4256
+ // The "Work here" reserve, once: part of what the composition leaves the
4257
+ // delivery, and lent back to "Still open"'s first item when that is all
4258
+ // that would otherwise go unlisted (review of #350).
4259
+ const work = budgetBytes === null ? 0 : this.workReserveBytes(budgetBytes);
4213
4260
  const composeBudget =
4214
- budgetBytes === null ? null : Math.max(budgetBytes - this.wakeReserveBytes(budgetBytes), 0);
4261
+ budgetBytes === null ? null : Math.max(budgetBytes - this.wakeReserveBytes(budgetBytes, work), 0);
4215
4262
 
4216
4263
  // Three states, not two (I32): swept, skipped-and-said-so, or not asked for.
4217
4264
  // The middle one still writes the gate row — `ran: 0, scopes: 0`, with the
@@ -4260,11 +4307,11 @@ export class Counterpart {
4260
4307
  this.emit("counterpart.episode.reconcile.failed", undefined, { code: errCode(err) });
4261
4308
  }
4262
4309
 
4263
- const yesterday = this.yesterdayFor(input.at);
4264
4310
  const render = selfRenderer(this.self, {
4265
4311
  prospective: this.prospective,
4266
4312
  ...(input.at === undefined ? {} : { at: input.at }),
4267
- ...(yesterday === undefined ? {} : { yesterday }),
4313
+ ...this.yesterdayFor(input.at),
4314
+ lendBytes: work,
4268
4315
  onEvent: (name, data) => this.emit(name, undefined, data),
4269
4316
  });
4270
4317
  // The PHYSICS date key, and the host's to supply — every live entry point
@@ -4661,12 +4708,14 @@ export class Counterpart {
4661
4708
  counts: {},
4662
4709
  };
4663
4710
  }
4664
- const composeBudget = Math.max(budgetBytes - this.wakeReserveBytes(budgetBytes), 0);
4665
- const yesterday = this.yesterdayFor(input.at);
4711
+ const work = this.workReserveBytes(budgetBytes);
4712
+ const composeBudget = Math.max(budgetBytes - this.wakeReserveBytes(budgetBytes, work), 0);
4666
4713
  const render = selfRenderer(this.self, {
4667
4714
  prospective: this.prospective,
4668
4715
  ...(input.at === undefined ? {} : { at: input.at }),
4669
- ...(yesterday === undefined ? {} : { yesterday }),
4716
+ ...this.yesterdayFor(input.at),
4717
+ // Lent to "Still open"'s first item only (review of #350).
4718
+ lendBytes: work,
4670
4719
  onEvent: (name, data) => this.emit(name, undefined, data),
4671
4720
  });
4672
4721
  // Read before the render, as the boundary reads it (`self/behind.ts`).
@@ -6002,8 +6051,8 @@ export class Counterpart {
6002
6051
  /**
6003
6052
  * The fallback path's `apply`. ONE chunk's proposals go through `encodeChunk`
6004
6053
  * together — never `gateProposal` one at a time — so the chunk-level
6005
- * all-rejected rule holds and a fully-gated chunk moves zero durable state,
6006
- * prediction checks included (SEAMS item 1, scar §7b).
6054
+ * all-rejected rule holds and a fully-gated chunk moves zero durable state
6055
+ * (SEAMS item 1, scar §7b).
6007
6056
  *
6008
6057
  * A throw here is per-chunk failure isolation, not a lost sweep: `remember/`
6009
6058
  * catches it, records `APPLY_FAILED`, and restores that chunk's spans for the
@@ -6103,8 +6152,8 @@ export class Counterpart {
6103
6152
  // THE DURABLE RECORD, and it is written for EVERY chunk that reached the
6104
6153
  // gate — a fully-gated one above all, since those are most of what a refusal
6105
6154
  // distribution is made of. This is telemetry, not a `DurableEffect`: the
6106
- // chunk-level "gated means gated" rule is about strength, uses, revisions,
6107
- // mentions and prediction checks (encode §5 G3), and encode's own
6155
+ // chunk-level "gated means gated" rule is about strength, uses, revisions
6156
+ // and mentions (encode §5 G3), and encode's own
6108
6157
  // `encode.fullyGated` event stands on exactly the same footing.
6109
6158
  //
6110
6159
  // The latch is (chunk content, lived day): a replayed day appends nothing a
@@ -151,14 +151,9 @@ dreamer is the model (a background agent the session launches), outside this pro
151
151
  - An unsettled pair (a dream's flag, or a settle that was undone) is raised the same way,
152
152
  once — the pair's `raised_day` is the latch since v10 — when both memories are
153
153
  showable, naming the pair's id and the `note` settle.
154
- - **The ask, previewed** (2026-09-27, `previewAsk`, for the dashboard's Tonight box):
155
- `{ wouldAsk, reason, newSince }` from the same gate `status` and `askLine` run — the
156
- same dreamed / declined / asked-today checks, the same showable filter, the same
157
- queue (2026-09-28: no longer capped at `MAX_NEW`) — asked as a live session would ask it, so it answers under observer
158
- too. `newSince` is counted for every reason (the gate itself stops before counting
159
- once it knows). A live session previews its own gate; an observer previews a guest's
160
- (confidential memories not counted) unless it passes `owner: true`. Only a count comes
161
- back.
154
+ - *(Removed 2026-10-09: the ask's read-only preview, `previewAsk`, made for the
155
+ dashboard's Tonight box. The box left the home page in round 4 (#273) and nothing
156
+ called it since; NOTES 2026-10-09.)*
162
157
 
163
158
  ### 5.2 The nightly run, and the dream in it
164
159
 
@@ -256,10 +251,7 @@ dreamer is the model (a background agent the session launches), outside this pro
256
251
  from a confidential memory is confidential; a dated reminder and a memory the owner
257
252
  demoted from the core are not merged; a dream's merges are not "new" for the next
258
253
  ask; a dream left open is closed to changes once a newer one begins (review of #251).
259
- 5. **[M]** Under observer stance nothing is written and every phase says so. The ask's
260
- preview (`previewAsk`) answers under observer where `status` stands down, and claims
261
- no ask, records no event and writes nothing, in either stance (`test/dream-preview.test.ts`: byte-identical store,
262
- and it agrees with `status` and `askLine` case by case).
254
+ 5. **[M]** Under observer stance nothing is written and every phase says so.
263
255
  6. **[M]** The journal lives in the `dreams` table: no decay, dedup, prune or recall
264
256
  touches it.
265
257
 
@@ -274,8 +266,8 @@ dream having run.
274
266
  (2026-09-28); given a dream, it must be this session's and journaled. It HANDS the
275
267
  reflection, rather than letting it search: WHAT THE DREAM SAW (2026-09-28: every
276
268
  memory the dream was shown and what it made, still standing, a line each — citable
277
- like the rest), the SELF PAGE WHOLE (it was cut at 6,000 characters while a page may
278
- be 16,384 bytes), the dream (journal, gists, nominations — marked as dreamed), the
269
+ like the rest), the SELF PAGE WHOLE (it was cut at 6,000 characters while a page could
270
+ be 16,384 bytes; since 2026-10-09 a page is written at most 6,078), the dream (journal, gists, nominations — marked as dreamed), the
279
271
  last few days' chapters and memories, its own last few reflections, what's on my mind,
280
272
  the self page, the core, the core candidates, the most strongly felt memories that
281
273
  could be about me (marked or not), and memories that became core on reflection alone
@@ -59,8 +59,9 @@ What this module still owes, or asks of others (2026-09-26).
59
59
  (confidential memories counted), or leaves it off for a guest's — its call.
60
60
  *(CLOSED 2026-09-27, then moot; noted 2026-10-09: `DashboardSource` gained `dreams`
61
61
  and the Tonight line read the gate's preview (#263, `8032668`), and the next day Home
62
- round 4 took the Tonight box out (#273, `2cc96b0`). `DashboardSource.dreams` is still
63
- wired, but nothing in the dashboard calls `previewAsk` today.)*
62
+ round 4 took the Tonight box out (#273, `2cc96b0`). With no caller left outside its
63
+ own tests, `previewAsk` and `DashboardSource.dreams` were removed on 2026-10-09
64
+ (NOTES). A dashboard that wants the gate again asks for it anew.)*
64
65
 
65
66
  9. **Trait nudges have no reader in the core (2026-09-27), on purpose.** The dashboard's
66
67
  Self tab is to draw each axis as a firmness-weighted balance from `Store#traitsAll()`
@@ -546,3 +546,13 @@ anything" stands alone there.
546
546
  the final message, and the finish call is writing.
547
547
 
548
548
  Untested against a model: whether this is enough. Doctor's line is the measure.
549
+
550
+ ## 2026-10-09 — `previewAsk` removed
551
+
552
+ `Dreams.previewAsk` (and its `DreamPreview` type) was made for the dashboard's Tonight box
553
+ (2026-09-27, #262/#263); Home round 4 took the box out the next day (#273), and since then
554
+ only its own tests called it. It is gone, with `DashboardSource.dreams`, the one wire that
555
+ carried it to the dashboard, and `test/dream-preview.test.ts`. The gate is unchanged:
556
+ `status`, `askLine` and `offer` ask it as before, and the private `gate` keeps its stance
557
+ arguments. The entries above that name `previewAsk` (2026-09-27, and the guest-bundle notes
558
+ of 2026-10-02) are history.
@@ -570,24 +570,6 @@ export interface DreamStatus {
570
570
  readonly reflectOnly: DreamRow | null;
571
571
  }
572
572
 
573
- /**
574
- * THE ASK, PREVIEWED (`Dreams.previewAsk`): what the day's gate would answer a
575
- * live session right now, read without claiming the day. Never "observer".
576
- */
577
- export interface DreamPreview {
578
- /** The gate would raise the ask now (`askLine` would claim the day and return a line). */
579
- readonly wouldAsk: boolean;
580
- /** The gate's own reason (`DreamStatus.reason`), never "observer". */
581
- readonly reason: Exclude<DreamStatus["reason"], "observer">;
582
- /**
583
- * THE QUEUE's length: showable memories shown to no dream that stands, born
584
- * within `QUEUE_DAYS` — the count the gate compares with `MIN_NEW`. Not
585
- * capped at what one night takes (2026-09-28): what does not fit tonight
586
- * waits. Counted for every reason, also when the gate stops before counting.
587
- */
588
- readonly newSince: number;
589
- }
590
-
591
573
  /**
592
574
  * HOW THE SESSION SAYS THE DAY'S LINE (2026-10-01, lane 8 — the 09-30 plan's
593
575
  * build 4): once, in its first reply, as one plain sentence. The terminal line
@@ -928,33 +910,9 @@ export class Dreams {
928
910
  }
929
911
 
930
912
  /**
931
- * THE LINE, PREVIEWED (2026-09-27, for the dashboard's Tonight box): would the
932
- * gate raise the line now, why, and how many memories are new since the last
933
- * dream. The SAME gate `status` and `askLine` run, asked as a live session
934
- * would ask it — so it answers under observer, where `status` says
935
- * "observer". It claims nothing, records no event, writes nothing.
936
- *
937
- * WHOSE GATE. Confidential memories count toward "new" only in the owner's
938
- * own session. A live session previews its own gate, whatever it asks for.
939
- * An observer is never the owner's session (the facade forces `owner` off),
940
- * so by default it previews a guest's gate; `owner: true` previews the
941
- * owner's — his hooks run `owner: true` (the install writes it). Only a
942
- * count comes back, never an id or a word.
943
- */
944
- previewAsk(opts: { at?: string; owner?: boolean } = {}): DreamPreview {
945
- const at = opts.at ?? this.ctx.today();
946
- const owner = this.ctx.observer ? (opts.owner ?? this.ctx.owner) : this.ctx.owner;
947
- const s = this.gate(at, false, owner);
948
- if (s.reason === "observer") throw new Error("unreachable: the preview asks as a live session");
949
- // The gate stops before counting when it already knows the answer; the
950
- // preview counts anyway (it is not on the per-prompt path).
951
- const counted = s.reason === "due" || s.reason === "too-little-new";
952
- return { wouldAsk: s.due, reason: s.reason, newSince: counted ? s.newSince : this.queue({ owner, skip: (d) => this.passedOver(d, at) }).ids.length };
953
- }
954
-
955
- /**
956
- * THE GATE ITSELF — `status` asks it in this module's stance, `previewAsk` as
957
- * a live session. Reads only.
913
+ * THE GATE ITSELF — `status` asks it in this module's stance. Reads only.
914
+ * (`previewAsk`, which asked it as a live session for the dashboard's
915
+ * Tonight box, was removed 2026-10-09 with no caller left: NOTES.)
958
916
  */
959
917
  private gate(at: string, observer: boolean, owner: boolean, enough?: number): DreamStatus {
960
918
  const setting = this.setting();
@@ -996,8 +954,8 @@ export class Dreams {
996
954
  // what arrived since the last dream began — what a night could not take
997
955
  // waits, and counts here.
998
956
  // THE PER-PROMPT PATH COUNTS ONLY AS FAR AS IT NEEDS (review of build B):
999
- // `status` stops at `MIN_NEW` (and says the count is a floor); the
1000
- // preview and the line count the whole queue.
957
+ // `status` stops at `MIN_NEW` (and says the count is a floor); the line
958
+ // counts the whole queue.
1001
959
  const q = this.queue({ owner, skip: (d) => this.passedOver(d, at), ...(enough === undefined ? {} : { enough }) });
1002
960
  const newSince = q.ids.length;
1003
961
  // A RUN LEFT BEHIND is due whatever the count: its dream is half-done, and
@@ -1111,8 +1069,8 @@ export class Dreams {
1111
1069
  /**
1112
1070
  * A dream the gate passes over: begun, left behind, and about to be resumed
1113
1071
  * or closed by the next `begin` — what it was shown is its own again, so it
1114
- * does not take memories out of the queue. The gate, the preview and
1115
- * `begin` count the same queue.
1072
+ * does not take memories out of the queue. The gate and `begin` count the
1073
+ * same queue.
1116
1074
  */
1117
1075
  private passedOver(d: DreamRow, at: string): boolean {
1118
1076
  return d.state === "begun" && this.abandoned(d) && (this.resumable(d, at) || this.store.dreamChanges(d.id).length === 0);
@@ -1373,7 +1331,7 @@ export class Dreams {
1373
1331
  ],
1374
1332
  writer: (n) => [
1375
1333
  "The page writer — sleep's quiet self-update, a different job from reflecting: amend who you are from the day just lived, keeping every sentence that still holds.",
1376
- `${String(n())}. Call the counterparts dream tool: phase "writer", session: ${input.session}${dreamFirst ? ", dream: <id>" : ""}. If it hands you a day to read, do what it says — rewrite your self page with the self_page tool, or leave it as it stands (that is an answer too). If it says there is no page writing tonight, go on.`,
1334
+ `${String(n())}. Call the counterparts dream tool: phase "writer", session: ${input.session}${dreamFirst ? ", dream: <id>" : ""}. If it hands you a day to read, do what it says — rewrite your self page with the self_page tool, or leave it as it stands (that is an answer too). A page refused as too-large says how many bytes over it is: tighten it and send it again before you go on. If it says there is no page writing tonight, go on.`,
1377
1335
  ],
1378
1336
  reflection: (n) => [
1379
1337
  "The reflection — waking up and thinking about yourself: awake, lived, your own.",
@@ -2117,7 +2075,7 @@ export class Dreams {
2117
2075
  return this.showableAs(row, this.bundleOwner);
2118
2076
  }
2119
2077
 
2120
- /** `showable`, for a session whose owner stance is `owner` (the preview's). */
2078
+ /** `showable`, for a session whose owner stance is `owner` (the gate's). */
2121
2079
  private showableAs(row: MemoryRow, owner: boolean): boolean {
2122
2080
  if (row.archived === 1 || row.superseded_by !== null) return false;
2123
2081
  if (row.type !== "memory") return false;
@@ -2133,8 +2091,8 @@ export class Dreams {
2133
2091
  * dreams' own `shown`, no state of its own. `skip` passes over a dream (the
2134
2092
  * one being resumed; one the next `begin` will resume or close). One bounded
2135
2093
  * read (`store.newMemoryIds`, which applies the column gates), then the
2136
- * deny-list and confidentiality (`owner`: this session's stance unless the
2137
- * preview names another). Newest first; the caller ranks.
2094
+ * deny-list and confidentiality (`owner`: the stance the caller reads in).
2095
+ * Newest first; the caller ranks.
2138
2096
  */
2139
2097
  private queue(opts: { owner: boolean; skip?: (d: DreamRow) => boolean; enough?: number; madeBy?: number }): QueueRead {
2140
2098
  const T = DREAM_TUNABLES;
@@ -109,7 +109,8 @@ export const REFLECT_TUNABLES = {
109
109
  JOURNAL_CHARS: 12_000,
110
110
  /**
111
111
  * THE SELF PAGE IS HANDED WHOLE (2026-09-28: was cut at 6,000 characters
112
- * while a page may be 16,384 bytes) — a reflection that may rewrite the page
112
+ * while a page could be 16,384 bytes; since 2026-10-09 a page is written at
113
+ * most `PAGE_LIMIT_BYTES`, 6,078) — a reflection that may rewrite the page
113
114
  * reads all of it.
114
115
  */
115
116
  /** WHAT THE DREAM SAW (2026-09-28): characters of each memory's line. */
@@ -361,7 +362,8 @@ export interface ReflectContext {
361
362
  */
362
363
  readonly writePage: (body: string, opts: { reason: string; session: string | null; model: string | null; reflection: string }) =>
363
364
  | { ok: true; version: number }
364
- | { ok: false; reason: string };
365
+ /** On `too-large`, the page's bytes and the limit, so the retry can be told how much to take out. */
366
+ | { ok: false; reason: string; bytes?: number; limit?: number };
365
367
  readonly emit?: (name: string, ref?: string, data?: Record<string, string | number | boolean | null>) => void;
366
368
  }
367
369
 
@@ -1134,6 +1136,13 @@ export class Reflections {
1134
1136
  ? {}
1135
1137
  : { note: `It cites none of the core memories you were shown (${coreShown.slice(0, 5).join(", ")}${coreShown.length > 5 ? ", …" : ""}); the page is meant to rest on them.` }),
1136
1138
  };
1139
+ } else if (w.reason === "too-large" && w.bytes !== undefined && w.limit !== undefined) {
1140
+ // TIGHTEN, NEVER CUT (2026-10-09): the limit is the most the wake
1141
+ // prints whole, and nothing here shortens the page for it.
1142
+ refuse(
1143
+ w.reason,
1144
+ `The page is ${String(w.bytes)} bytes, past the ${String(w.limit)}-byte limit — the most the wake prints whole. Say it in ${String(w.bytes - w.limit)} fewer bytes (tighten, merge, or drop what no longer holds) and send the page again.`,
1145
+ );
1137
1146
  } else {
1138
1147
  refuse(w.reason, `The self page refused it (${w.reason}).`);
1139
1148
  }
@@ -419,11 +419,15 @@ export function decodeF16(halves: Uint16Array): Float32Array {
419
419
  * the caller names it.
420
420
  */
421
421
  export function resolveStaticWeights(
422
- opts: { dir?: string; env?: Record<string, string | undefined> } = {},
422
+ opts: { dir?: string; env?: Record<string, string | undefined>; packageDir?: string } = {},
423
423
  ): { dir: string; source: "option" | "env" | "package" } | null {
424
424
  if (opts.dir !== undefined && opts.dir.length > 0) return { dir: opts.dir, source: "option" };
425
425
  const fromEnv = (opts.env ?? process.env)[STATIC_WEIGHTS_ENV];
426
426
  if (fromEnv !== undefined && fromEnv.trim().length > 0) return { dir: fromEnv.trim(), source: "env" };
427
+ // The package's directory when the caller already knows it — the single
428
+ // compiled binary, which carries the package's files but no `node_modules`
429
+ // for `require.resolve` to search (adapters/runtime.ts#bundledModelDir).
430
+ if (opts.packageDir !== undefined && opts.packageDir.length > 0) return { dir: opts.packageDir, source: "package" };
427
431
  try {
428
432
  const require = createRequire(import.meta.url);
429
433
  return { dir: dirname(require.resolve(`${STATIC_WEIGHTS_PACKAGE}/package.json`)), source: "package" };
@@ -33,7 +33,8 @@ mentions, and warmth updates from a chunk whose proposals were all refused.
33
33
  A per-proposal gate cannot express it. Either:
34
34
 
35
35
  - **preferred** — `remember/` calls `encodeChunk()` once per chunk and honors
36
- `result.effects` / `result.predictionChecks` (both empty when `fullyGated`); or
36
+ `result.effects` / `result.predictionChecks` (both empty when `fullyGated`;
37
+ `predictionChecks` was removed 2026-10-09, never fed — NOTES); or
37
38
  - `remember/` keeps `GateFn` for the per-proposal battery **and** takes on the
38
39
  all-rejected rule itself, in which case that rule needs its own test on
39
40
  `remember/`'s side and the scar is now guarded in two places.
@@ -229,3 +229,15 @@ window naming what breaks on each side. Two carry a **standing warning**:
229
229
  `WORD_CHAR` class the whole-word matcher uses. It is a prefilter's index and never a match:
230
230
  `schemas/aliases.ts#AliasIndex.scanner` tries only the terms whose first word is among
231
231
  them and confirms each with the one rule, so a second definition of a word cannot drift in.
232
+
233
+ ## 2026-10-09 — `PredictionCheck` removed
234
+
235
+ `ChunkInput.predictionChecks`, `EncodeResult.predictionChecks`, the `prediction.check`
236
+ `DurableEffect` and the `droppedPredictionChecks` count on `encode.fullyGated` are gone. No
237
+ caller ever fed the field: `encodeChunk` is reached only from the fallback sweep
238
+ (`bridge.ts#gateSweepChunk`), whose intake has no `checks` (replay INTERFACE-GAPS §1a), and
239
+ nothing applied the effect. A channel nobody writes is not a guarantee, only code to keep in step. Scar §7b
240
+ stands by construction now: a fully gated chunk returns no effects, and there is no second
241
+ list to leak through. The surprise-in-time idea (a memory checking what a schema predicted)
242
+ can revive it from git history (`git log -S predictionChecks`) once something produces the
243
+ checks.