counterparts 0.3.44 → 0.3.45

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 (48) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +3 -2
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +15 -4
  5. package/src/adapters/claude-code/NOTES.md +53 -0
  6. package/src/adapters/claude-code/awake.ts +122 -0
  7. package/src/adapters/claude-code/bin/runner.ts +9 -1
  8. package/src/adapters/claude-code/child.ts +14 -4
  9. package/src/adapters/claude-code/doctor-self-page.ts +47 -2
  10. package/src/adapters/claude-code/doctor.ts +6 -1
  11. package/src/adapters/claude-code/hooks.ts +49 -9
  12. package/src/adapters/claude-code/night-catch-up.ts +66 -1
  13. package/src/adapters/claude-code/night-run.ts +97 -19
  14. package/src/adapters/cli/commands-note.ts +6 -5
  15. package/src/adapters/cli/commands.ts +1 -1
  16. package/src/adapters/cli/dream-core.ts +1 -1
  17. package/src/adapters/cli/help.ts +1 -1
  18. package/src/adapters/config.ts +16 -3
  19. package/src/adapters/dashboard/registries.ts +1 -1
  20. package/src/adapters/dashboard/web/narrate.ts +5 -1
  21. package/src/adapters/log/index.ts +4 -1
  22. package/src/adapters/mcp/CONTRACT.md +5 -2
  23. package/src/adapters/mcp/INTERFACE-GAPS.md +5 -0
  24. package/src/adapters/mcp/NOTES.md +2 -1
  25. package/src/adapters/mcp/server-session-end.ts +2 -2
  26. package/src/adapters/mcp/server-words.ts +11 -2
  27. package/src/adapters/mcp/server.ts +25 -15
  28. package/src/adapters/mcp/write-up.ts +43 -3
  29. package/src/adapters/sessions.ts +29 -0
  30. package/src/adapters/snapshots.ts +59 -0
  31. package/src/core/associate/CONTRACT.md +4 -0
  32. package/src/core/associate/NOTES.md +43 -0
  33. package/src/core/associate/index.ts +41 -5
  34. package/src/core/associate/tunables.ts +29 -0
  35. package/src/core/counterpart-deposit.ts +45 -14
  36. package/src/core/counterpart-types.ts +5 -2
  37. package/src/core/counterpart.ts +4 -1
  38. package/src/core/dream/CONTRACT.md +4 -3
  39. package/src/core/dream/index.ts +22 -9
  40. package/src/core/remember/CONTRACT.md +18 -4
  41. package/src/core/remember/NOTES.md +157 -0
  42. package/src/core/remember/index.ts +2 -0
  43. package/src/core/remember/owes.ts +100 -1
  44. package/src/core/remember/owner-strike-seam.ts +7 -1
  45. package/src/core/remember/proposals.ts +75 -27
  46. package/src/core/remember/retention.ts +35 -3
  47. package/src/core/remember/spans.ts +19 -1
  48. package/src/core/types.ts +10 -0
@@ -62,6 +62,8 @@ import type { Counterpart, CounterpartEvent, Seat } from "../../core/counterpart
62
62
  import { calendarDate } from "../../core/self/index.js";
63
63
  import { TUNABLES } from "../config.js";
64
64
  import type { AdapterConfig } from "../config.js";
65
+ import { awakeMeter } from "./awake.js";
66
+ import type { AwakeMeter } from "./awake.js";
65
67
  import { foldersOn, scopesPath } from "../scopes.js";
66
68
  import {
67
69
  NIGHT_RUNNER_PREFIX,
@@ -415,6 +417,37 @@ export function releaseCatchUp(c: Counterpart, plan: CatchUpPlan, opts: { scope:
415
417
  }
416
418
  }
417
419
 
420
+ /**
421
+ * RENEW WHAT A SLEEP WOULD HAVE LET RUN OUT (2026-11-01, NT1): a sleep past
422
+ * `WRITE_UP_CLAIM_MS` would leave the waking child with no claim on what it is
423
+ * writing and a grant the door refuses (`mcp/write-up.ts`), while another session
424
+ * could take the same subject. A process that noticed its sleep is plainly alive,
425
+ * so its claims and its record are as young as now. Only what is still its own: a
426
+ * subject another writer took meanwhile stays theirs. Never throws.
427
+ */
428
+ export function renewCatchUp(c: Counterpart, plan: CatchUpPlan, opts: { scope: string; now: number }): void {
429
+ const dir = c.store.dir;
430
+ const scope = opts.scope.length > 0 ? opts.scope : dir;
431
+ try {
432
+ updateWriteUpProgress(c.store, (map) => {
433
+ let changed = false;
434
+ for (const [key, p] of Object.entries(map)) {
435
+ if (p.claim?.by !== plan.runner) continue;
436
+ map[key] = { ...p, claim: { ...p.claim, at: opts.now } };
437
+ changed = true;
438
+ }
439
+ return changed;
440
+ });
441
+ } catch {
442
+ /* it runs out as it would have */
443
+ }
444
+ try {
445
+ recordSession(dir, { sessionId: plan.runner, scope, phase: "boundary", at: opts.now });
446
+ } catch {
447
+ /* it runs out as it would have */
448
+ }
449
+ }
450
+
418
451
  /**
419
452
  * THE CATCH-UP CHILD'S PROMPT: the runner's id, the sessions in order, and the
420
453
  * one way to write each up. Ids, dates and counts — no words of anyone's; the
@@ -472,6 +505,8 @@ export interface CatchUpReport {
472
505
  readonly busy: number;
473
506
  readonly bytes: number;
474
507
  readonly ms: number;
508
+ /** ...of which the machine slept (2026-11-01, NT1). Absent when it didn't. */
509
+ readonly sleptMs?: number;
475
510
  readonly code: number | null;
476
511
  /** Why the last child failed (2026-10-27, R4): one scrubbed line of what it
477
512
  * said (`child-error.ts`); null when it did not fail, or said nothing, and
@@ -573,6 +608,8 @@ export interface CatchUpInput {
573
608
  readonly onBatch?: (b: { readonly batch: number; readonly plan: CatchUpPlan }) => void;
574
609
  /** The process log (`adapters/log/`), when there is one. */
575
610
  readonly onEvent?: (e: CounterpartEvent) => void;
611
+ /** TESTS ONLY: what tells this run it slept; absent, `awake.ts#awakeMeter`. */
612
+ readonly awake?: (onSlept: (ms: number) => void) => AwakeMeter;
576
613
  }
577
614
 
578
615
  /** One child, started and waited on: what became of it. */
@@ -606,6 +643,29 @@ async function runChild(input: CatchUpInput, plan: CatchUpPlan, prompt: string):
606
643
  * owed (no row: a quiet night is not an event). Never throws.
607
644
  */
608
645
  export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | null> {
646
+ // TIME ASLEEP ISN'T THE RUN'S (2026-11-01, NT1): its hour counts time awake,
647
+ // and what the current batch holds is kept alive across a sleep.
648
+ let holding: CatchUpPlan | null = null;
649
+ const onSlept = (): void => {
650
+ if (holding === null) return;
651
+ const c = input.open();
652
+ try {
653
+ renewCatchUp(c, holding, { scope: input.scope, now: input.now() });
654
+ } finally {
655
+ c.close();
656
+ }
657
+ };
658
+ const meter = input.awake?.(onSlept) ?? awakeMeter({ onSlept });
659
+ try {
660
+ return await catchUpBatches(input, meter, (plan) => {
661
+ holding = plan;
662
+ });
663
+ } finally {
664
+ meter.stop();
665
+ }
666
+ }
667
+
668
+ async function catchUpBatches(input: CatchUpInput, meter: AwakeMeter, hold: (plan: CatchUpPlan | null) => void): Promise<CatchUpReport | null> {
609
669
  const startedAt = input.now();
610
670
  // Read afresh for each plan, and for what is left: a long run sees a folder
611
671
  // turned off in the middle of it from its next batch on.
@@ -634,7 +694,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
634
694
  limit = "parts";
635
695
  break;
636
696
  }
637
- if (batches > 0 && input.now() + TUNABLES.NIGHT_WRITE_UP_MS > deadline) {
697
+ if (batches > 0 && input.now() - meter.asleepMs() + TUNABLES.NIGHT_WRITE_UP_MS > deadline) {
638
698
  limit = "time";
639
699
  break;
640
700
  }
@@ -691,7 +751,9 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
691
751
  } catch {
692
752
  /* never the run's problem */
693
753
  }
754
+ hold(plan);
694
755
  const child = await runChild(input, plan, prompt);
756
+ hold(null);
695
757
  code = child.code;
696
758
  detail = child.detail;
697
759
  signedOut = child.signedOut === true;
@@ -729,6 +791,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
729
791
  }
730
792
  }
731
793
  const endedAt = input.now();
794
+ const slept = meter.asleepMs();
732
795
  const report = (over: Partial<CatchUpReport>): CatchUpReport => ({
733
796
  run: input.run,
734
797
  runner: catchUpRunner(input.run),
@@ -744,6 +807,7 @@ export async function runCatchUp(input: CatchUpInput): Promise<CatchUpReport | n
744
807
  busy,
745
808
  bytes,
746
809
  ms: endedAt - startedAt,
810
+ ...(slept > 0 ? { sleptMs: slept } : {}),
747
811
  code,
748
812
  detail,
749
813
  ...(signedOut ? { signedOut: true as const } : {}),
@@ -784,6 +848,7 @@ function record(input: CatchUpInput, report: CatchUpReport, open?: Counterpart):
784
848
  busy: report.busy,
785
849
  bytes: report.bytes,
786
850
  ms: report.ms,
851
+ ...(report.sleptMs === undefined ? {} : { sleptMs: report.sleptMs }),
787
852
  code: report.code,
788
853
  ...(report.detail === null ? {} : { detail: report.detail }),
789
854
  ...(report.signedOut === true ? { signedOut: true } : {}),
@@ -107,6 +107,8 @@ import { OBSERVER_ENV } from "../stance-env.js";
107
107
 
108
108
  import { NIGHT_DEBUG_DIR, NIGHT_TRANSCRIPT_NAME, TUNABLES, nightDebugDir } from "../config.js";
109
109
  import type { AdapterConfig } from "../config.js";
110
+ import { awakeMeter } from "./awake.js";
111
+ import type { AwakeMeter } from "./awake.js";
110
112
  import { DEFAULT_HOST_COMMAND, KILL_GRACE_MS, PERMISSION_MODE, REAP_GRACE_MS, startChild } from "./child.js";
111
113
  import { runCatchUp } from "./night-catch-up.js";
112
114
  import { foldersOn, readScopes, scopesPath } from "../scopes.js";
@@ -611,6 +613,32 @@ export interface NightRunInput {
611
613
  readonly now?: () => number;
612
614
  /** The process log's (`adapters/log/`), for what the store does not write. */
613
615
  readonly onEvent?: (e: CounterpartEvent) => void;
616
+ /** TESTS ONLY: what tells this run it slept; absent, `awake.ts#awakeMeter`. */
617
+ readonly awake?: (onSlept: (ms: number) => void) => AwakeMeter;
618
+ }
619
+
620
+ /**
621
+ * A SLEEP THE RUN NOTICED (2026-11-01, NT1) goes on its row as soon as it is
622
+ * noticed, so the next prompt reads a run that slept as still under way and no
623
+ * second run starts beside it (`nightRunLost`). Never throws.
624
+ */
625
+ function noteSlept(input: NightRunInput, ms: number): void {
626
+ try {
627
+ const c = input.open();
628
+ try {
629
+ const row = c.dreams.nightRun();
630
+ if (row !== null && row.run === input.run && row.state === "started") c.dreams.recordNightRun({ ...row, sleptMs: (row.sleptMs ?? 0) + ms });
631
+ } finally {
632
+ c.close();
633
+ }
634
+ } catch {
635
+ /* it reads as lost a little sooner; the run still goes on */
636
+ }
637
+ try {
638
+ input.onEvent?.({ at: input.now?.() ?? Date.now(), name: "adapter.night.slept", ref: input.run, data: { ms } });
639
+ } catch {
640
+ /* never the run's problem */
641
+ }
614
642
  }
615
643
 
616
644
  /**
@@ -624,6 +652,18 @@ export interface NightRunInput {
624
652
  * (`transcript.ts#parseToolSpills`). Nothing under `~/.claude` is read.
625
653
  */
626
654
  export async function runNight(input: NightRunInput): Promise<NightRun> {
655
+ const onSlept = (ms: number): void => {
656
+ noteSlept(input, ms);
657
+ };
658
+ const meter = input.awake?.(onSlept) ?? awakeMeter({ onSlept });
659
+ try {
660
+ return await theNight(input, meter);
661
+ } finally {
662
+ meter.stop();
663
+ }
664
+ }
665
+
666
+ async function theNight(input: NightRunInput, meter: AwakeMeter): Promise<NightRun> {
627
667
  const now = input.now ?? ((): number => Date.now());
628
668
  const startedAt = now();
629
669
  let date = input.date ?? "";
@@ -635,9 +675,9 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
635
675
  let writerPrompt = "";
636
676
  // THE MORNING CATCH-UP FIRST (2026-10-01, build 3): owed stretches in any
637
677
  // directory are written up before the page writer reads the day, by a short
638
- // child of their own (`night-catch-up.ts`). Its time is added to the run's
639
- // watchdog on the row, so the gate does not read a run that is still going
640
- // as lost.
678
+ // child of their own (`night-catch-up.ts`). Its time awake is added to the
679
+ // run's watchdog on the row (what it slept is on `sleptMs` with the rest), so
680
+ // the gate does not read a run that is still going as lost.
641
681
  let catchUpMs = 0;
642
682
  // WHICH CHILDREN RAN (2026-10-11), in order, on every row that ends the run.
643
683
  const children: NightChildRun[] = [];
@@ -647,14 +687,18 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
647
687
  // A WEEK OF DEBUG TRANSCRIPTS AT MOST (2026-10-23), pruned whether or not
648
688
  // the switch is on now, so turning it off leaves nothing behind for long.
649
689
  pruneNightTranscripts(input.config.dataDir, input.configPath, localDate(startedAt, input.config.timeZone));
650
- const base = (c: Counterpart | null): Omit<NightRun, "state" | "endedAt" | "reason" | "detail" | "code" | "dream" | "reflection"> => ({
651
- run: input.run,
652
- date: date.length > 0 ? date : (c?.store.today() ?? ""),
653
- kind: input.kind.kind,
654
- session: input.session,
655
- startedAt,
656
- timeoutMs: nightChildrenTimeoutMs(input.config, input.kind.kind) + catchUpMs,
657
- });
690
+ const base = (c: Counterpart | null): Omit<NightRun, "state" | "endedAt" | "reason" | "detail" | "code" | "dream" | "reflection"> => {
691
+ const slept = meter.asleepMs();
692
+ return {
693
+ run: input.run,
694
+ date: date.length > 0 ? date : (c?.store.today() ?? ""),
695
+ kind: input.kind.kind,
696
+ session: input.session,
697
+ startedAt,
698
+ timeoutMs: nightChildrenTimeoutMs(input.config, input.kind.kind) + catchUpMs,
699
+ ...(slept > 0 ? { sleptMs: slept } : {}),
700
+ };
701
+ };
658
702
  const record = (run: NightRun): NightRun => {
659
703
  try {
660
704
  const c = input.open();
@@ -717,7 +761,7 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
717
761
  parts: TUNABLES.NIGHT_WRITE_UP_PARTS,
718
762
  ...(input.onEvent === undefined ? {} : { onEvent: input.onEvent }),
719
763
  });
720
- if (report !== null) catchUpMs = report.ms;
764
+ if (report !== null) catchUpMs = Math.max(0, report.ms - (report.sleptMs ?? 0));
721
765
  // THE CATCH-UP ALONE (2026-10-11): started because write-ups from an
722
766
  // earlier day were owed while the dream was not due. Its dream and its
723
767
  // reflection are skipped, and the row says why — never a failed dream.
@@ -784,12 +828,14 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
784
828
  // a `skipped` row the claim wrote before it is not the writer having run,
785
829
  // and the dream's quick exit is not read as something begun (review of #603).
786
830
  let writerAt: number | null = null;
831
+ let writerMark: number | null = null;
787
832
  let writerAnswer: NightAnswer | null = null;
788
833
  if (split) {
789
834
  const w = await writerFirst(input, seat, writerPrompt, now);
790
835
  if (w !== null) {
791
836
  children.push(w.line);
792
837
  writerAt = w.at;
838
+ writerMark = w.mark;
793
839
  writerAnswer = w.answer;
794
840
  }
795
841
  // A PAGE THE WRITER WAS HELD ON AND NEVER SENT AGAIN IS KEPT NOW, before
@@ -809,6 +855,7 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
809
855
  }
810
856
  }
811
857
  const dreamAt = now();
858
+ const dreamMark = eventMark(input.open);
812
859
  const firstAct: NightChild = input.kind.kind === "night" ? "dream" : "reflection";
813
860
  const ran: NightAnswer[] = [];
814
861
  let one: NightAnswer;
@@ -831,7 +878,7 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
831
878
  // single run did. Not started when the first child could not run at all, or
832
879
  // a reflection already finished today.
833
880
  if (input.kind.kind === "night") {
834
- const next = reflectionAfter(input.open, one, input.session, split ? dreamAt : startedAt);
881
+ const next = reflectionAfter(input.open, one, input.session, split ? { at: dreamAt, mark: dreamMark } : { at: startedAt, mark: null });
835
882
  if ("skipped" in next) children.push({ child: "reflection", code: null, ms: 0, skipped: next.skipped });
836
883
  else {
837
884
  try {
@@ -889,7 +936,7 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
889
936
  // The writer's phase was REACHED: it leaves a row carrying the session.
890
937
  // While split: what the writer's own child did, from when it was asked.
891
938
  const writerSince = split ? writerAt : startedAt;
892
- writerRan = writerSince !== null && c.pageWriterRuns({ limit: 20 }).some((r) => r.at >= writerSince && r.session === input.session);
939
+ writerRan = writerSince !== null && c.pageWriterRuns({ limit: 20 }).some((r) => after(r, { at: writerSince, mark: split ? writerMark : null }) && r.session === input.session);
893
940
  dreamed = dreams.some((d) => d.state === "journaled");
894
941
  const journaled = dreams.find((d) => d.state === "journaled");
895
942
  const reflected = reflections.find((r) => r.state === "reflected");
@@ -1304,8 +1351,9 @@ async function writerFirst(
1304
1351
  seat: Seat<NightAnswer>,
1305
1352
  prompt: string,
1306
1353
  now: () => number,
1307
- ): Promise<{ readonly line: NightChildRun; readonly at: number | null; readonly answer: NightAnswer | null } | null> {
1308
- const line = (l: NightChildRun, at: number | null = null, answer: NightAnswer | null = null) => ({ line: l, at, answer });
1354
+ ): Promise<{ readonly line: NightChildRun; readonly at: number | null; readonly mark: number | null; readonly answer: NightAnswer | null } | null> {
1355
+ let mark: number | null = null;
1356
+ const line = (l: NightChildRun, at: number | null = null, answer: NightAnswer | null = null) => ({ line: l, at, mark, answer });
1309
1357
  // Nothing for it tonight is no child and no line, as the tagging's: a
1310
1358
  // night's row reads as it did before the writer had a child of its own.
1311
1359
  if (input.config.pageWriter?.mode === "off") return null;
@@ -1329,6 +1377,7 @@ async function writerFirst(
1329
1377
  return line({ child: "writer", code: null, ms: 0, skipped: "unread" });
1330
1378
  }
1331
1379
  const at = now();
1380
+ mark = eventMark(input.open);
1332
1381
  try {
1333
1382
  const out = await seat.answer(seatAsk("writer", { prompt, run: input.run, session: input.session, scope: input.scope, limits: { turns: TUNABLES.NIGHT_WRITER_MAX_TURNS, ms: TUNABLES.NIGHT_WRITER_MS } }));
1334
1383
  if (out.refused !== null) return line({ child: "writer", code: null, ms: 0, skipped: out.refused }, at);
@@ -1373,6 +1422,35 @@ async function tagsAfter(open: () => Counterpart, seat: Seat<NightAnswer>, ask:
1373
1422
  }
1374
1423
  }
1375
1424
 
1425
+ /**
1426
+ * WHERE THE EVENT LOG STOOD when a child was asked: a row is that child's only
1427
+ * when it came after this, by sequence (2026-11-01). The clock cannot say: the
1428
+ * writer's `skipped` claim just before a child and a row the child writes at
1429
+ * once can share a millisecond with the moment the child was asked, and the
1430
+ * order of the log is the only thing that tells them apart. Null when the log
1431
+ * will not read (readers then fall back to the millisecond).
1432
+ */
1433
+ function eventMark(open: () => Counterpart): number | null {
1434
+ try {
1435
+ const c = open();
1436
+ try {
1437
+ return c.store.eventLog({ order: "desc", limit: 1 })[0]?.seq ?? 0;
1438
+ } finally {
1439
+ c.close();
1440
+ }
1441
+ } catch {
1442
+ return null;
1443
+ }
1444
+ }
1445
+
1446
+ /** When a reading starts: the moment, and the log's mark when one was taken. */
1447
+ type Since = { readonly at: number; readonly mark: number | null };
1448
+
1449
+ /** Is this writer row from after `since`: by log order when marked, else by the millisecond. */
1450
+ function after(r: { readonly at: number; readonly seq: number }, since: Since): boolean {
1451
+ return since.mark !== null ? r.seq > since.mark : r.at >= since.at;
1452
+ }
1453
+
1376
1454
  /**
1377
1455
  * THE REFLECTION'S CHILD, DECIDED (2026-10-11), after the dream's child
1378
1456
  * ended: its prompt, on tonight's journaled dream or (none journaled — the
@@ -1381,12 +1459,12 @@ async function tagsAfter(open: () => Counterpart, seat: Seat<NightAnswer>, ask:
1381
1459
  * a second `claude` would stop the same way), when a reflection already
1382
1460
  * finished today, or when the store will not open. Never throws.
1383
1461
  */
1384
- function reflectionAfter(open: () => Counterpart, first: NightAnswer, session: string, since: number): { prompt: string; dream: string | null } | { skipped: string } {
1462
+ function reflectionAfter(open: () => Counterpart, first: NightAnswer, session: string, since: Since): { prompt: string; dream: string | null } | { skipped: string } {
1385
1463
  try {
1386
1464
  const c = open();
1387
1465
  try {
1388
- const dreams = c.store.dreams({ sinceAt: since, limit: 5 });
1389
- const began = dreams.length > 0 || c.pageWriterRuns({ limit: 20 }).some((r) => r.at >= since && r.session === session);
1466
+ const dreams = c.store.dreams({ sinceAt: since.at, limit: 5 });
1467
+ const began = dreams.length > 0 || c.pageWriterRuns({ limit: 20 }).some((r) => after(r, since) && r.session === session);
1390
1468
  if (!began && first.code !== 0 && !first.timedOut && first.ms < TUNABLES.NIGHT_QUICK_EXIT_MS) return { skipped: "quick-exit" };
1391
1469
  const today = c.store.today();
1392
1470
  if (c.store.reflections({ limit: 5 }).some((x) => x.state === "reflected" && x.date === today)) return { skipped: "reflected-today" };
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { STORE_EXPORT_EVENT } from "../../core/counterpart.js";
4
4
  import { readChapterLead, readableDate } from "../../core/self/index.js";
5
5
  import { Store, storeExists } from "../../core/store/index.js";
6
+ import { CONSOLE_SESSION } from "../../core/types.js";
6
7
  // The MCP adapter's deliberate-recall dispatcher, imported rather than
7
8
  // re-implemented: a console with its own question path would be a second set of
8
9
  // rules about what recall means. `mcp/deliberate.ts` imports nothing from here,
@@ -107,11 +108,11 @@ export async function noteCommand(
107
108
  // resolved to the default store, the note landed there, and the only line
108
109
  // printed was that something had been remembered.
109
110
  io.out(`Store: ${counterpart.store.dir}`);
110
- const session = "console";
111
+ const session = CONSOLE_SESSION;
111
112
  const scope = filedUnder ?? process.cwd();
112
113
  // Step 1 of 2, and the ORDER is the rule (see the docblock above).
113
114
  const captured = counterpart.captureJot({ session, scope, text });
114
- const ownSpanHash = captured.spans[0]?.hash ?? null;
115
+ const ownSpanHash = captured.spans[0]?.hash ?? captured.heldLine ?? null;
115
116
 
116
117
  const draft: Record<string, unknown> = { content: text };
117
118
  if (typeof parsed.flags["kind"] === "string") draft["kind"] = parsed.flags["kind"];
@@ -326,7 +327,7 @@ export async function recallCommand(
326
327
  const meaning = meaningRecall(
327
328
  {
328
329
  counterpart,
329
- sessionId: "console",
330
+ sessionId: CONSOLE_SESSION,
330
331
  vector: embedded.vector,
331
332
  semantic: embedded.semantic,
332
333
  asker: parsed.flags["voiced"] === true ? "self" : "owner",
@@ -338,7 +339,7 @@ export async function recallCommand(
338
339
  return EXIT.ok;
339
340
  }
340
341
  const facts = factsRecall(
341
- { counterpart, sessionId: "console", vector: embedded.vector, semantic: embedded.semantic },
342
+ { counterpart, sessionId: CONSOLE_SESSION, vector: embedded.vector, semantic: embedded.semantic },
342
343
  question,
343
344
  page,
344
345
  );
@@ -365,7 +366,7 @@ export async function recallCommand(
365
366
  );
366
367
  return EXIT.ok;
367
368
  }
368
- const result = deliberateRecall(counterpart, { handle: idFlag }, { sessionId: "console" });
369
+ const result = deliberateRecall(counterpart, { handle: idFlag }, { sessionId: CONSOLE_SESSION });
369
370
  if (parsed.flags["json"] === true) {
370
371
  io.out(JSON.stringify(result, null, 2));
371
372
  return EXIT.ok;
@@ -966,7 +966,7 @@ const DREAM_FLAG_HELP: Record<string, string> = {
966
966
  "undo-twins":
967
967
  "put back the twin cards the night archived (two live cards with one name, merged once into the elder): every one, or the card named after the flag. Each record is kept, marked undone, and the links the night gave the elder stay. The cost: the name is held twice again, so a new memory naming it links to neither card, and the night will not merge them again",
968
968
  setting:
969
- "auto, ask or off — the nightly run (day's end, dream, reflection). ask (the default): the first session of a day shows you the question in the terminal and waits for you to say \"dream\" (or \"dream on your own\", which turns on auto); auto: the first session of a day starts it by itself, in a separate windowless claude -p in the background, and says so in one line; off: no dreams. `counterparts dream` prints the setting.",
969
+ "auto, ask or off — the nightly run (day's end, dream, reflection). ask (the default): the first session of a day shows you the question in the terminal and waits for you to say \"dream\" (or \"dream on your own\", which turns on auto); auto: the first session you start on a day begins it by itself, in a separate windowless claude -p in the background, and says so in one line; off: no dreams. `counterparts dream` prints the setting.",
970
970
  };
971
971
 
972
972
  /** `night`'s one flag (2026-10-20): `--all` means something else on other pages. */
@@ -40,7 +40,7 @@ function countsLine(counts: Readonly<Record<string, number>>): string {
40
40
  export function dreamingSettingWords(setting: DreamingSetting): string {
41
41
  switch (setting) {
42
42
  case "auto":
43
- return "Once a day, the first session starts the nightly run by itself — day's end, then a dream, then a reflection — in a separate, windowless claude -p in the background, and says so in one line; if it cannot start, the next prompt asks instead and says why. Say 'no dreams' in a session, or counterparts dream --setting off, to turn it off.";
43
+ return "Once a day, the first session you start begins the nightly run by itself — day's end, then a dream, then a reflection — in a separate, windowless claude -p in the background, and says so in one line; if it cannot start, the next prompt asks instead and says why. Say 'no dreams' in a session, or counterparts dream --setting off, to turn it off.";
44
44
  case "ask":
45
45
  return "Once a day, the first session shows you the question in the terminal before it starts the nightly run; say 'dream' to start it, 'dream on your own' to let it start by itself each day, or nothing and it waits. (A memory with no setting reads as this; a new install starts on auto.)";
46
46
  case "off":
@@ -408,7 +408,7 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
408
408
  "nothing durable records — which row would fix that.",
409
409
  ],
410
410
  dream: [
411
- "Once a day the first session starts the nightly run in the background —",
411
+ "Once a day the first session you start runs the night in the background —",
412
412
  "day's end, then a dream, then a reflection — and says so in one",
413
413
  "line (--setting ask makes it ask you first; --setting off, or saying 'no",
414
414
  "dreams' in a session, turns it off). Every change a dream makes is",
@@ -138,6 +138,12 @@ export const TUNABLES = {
138
138
  * row carries it from the start (`night-run.ts#nightRowTimeoutMs`), so a
139
139
  * long catch-up is never read as a lost run. */
140
140
  NIGHT_WRITE_UP_TOTAL_MS: 60 * 60_000,
141
+ /** How often a night's wait looks at the time, ms (2026-11-01, NT1;
142
+ * `claude-code/awake.ts`). Each of these watchdogs counts time awake. */
143
+ NIGHT_AWAKE_TICK_MS: 1_000,
144
+ /** A tick this late, ms, means the machine slept and the time isn't charged.
145
+ * A shorter sleep is charged: a busy machine's stall is never read as sleep. */
146
+ NIGHT_ASLEEP_GAP_MS: 30_000,
141
147
  /** One child's turn ceiling: two calls a part for the most parts a child
142
148
  * takes (2 × 16), and 16 more — room to look a tool up and for the odd
143
149
  * re-sent answer (one in five parts on 2026-10-11). A child that hits it
@@ -318,6 +324,8 @@ export interface AdapterConfig {
318
324
  readonly dir?: string;
319
325
  readonly keep?: number;
320
326
  readonly mirror?: string;
327
+ /** `false`: no daily copy (`adapters/snapshots.ts#SnapshotsConfig.daily`). Hosted's; no install writes it. */
328
+ readonly daily?: boolean;
321
329
  /**
322
330
  * What this file could not read inside the block, phrased for a person —
323
331
  * "snapshots.keep was 0; using 14". Empty is absent. It is a REPORT, not a
@@ -462,7 +470,7 @@ export function loadConfig(raw: unknown): LoadedConfig {
462
470
  socketLifetimeMs?: number;
463
471
  watchdogMs?: number;
464
472
  embedder?: { enabled: boolean; kind?: EmbedderKind };
465
- snapshots?: { dir?: string; keep?: number; mirror?: string; ignored?: string[] };
473
+ snapshots?: { dir?: string; keep?: number; mirror?: string; daily?: boolean; ignored?: string[] };
466
474
  pageWriter?: { mode: PageWriterMode; ignored?: string[] };
467
475
  dreaming?: { model?: string; timeoutMs?: number; maxTurns?: number; ignored?: string[] };
468
476
  retention?: { afterWriteUpDays?: number; maxDays?: number; ignored?: string[] };
@@ -925,7 +933,7 @@ function readSnapshots(raw: unknown): {
925
933
  const ignored = (line: string): void => {
926
934
  raws.push(line);
927
935
  };
928
- const out: { dir?: string; keep?: number; mirror?: string; ignored?: string[] } = {};
936
+ const out: { dir?: string; keep?: number; mirror?: string; daily?: boolean; ignored?: string[] } = {};
929
937
  const done = (): typeof out =>
930
938
  raws.length === 0 ? out : { ...out, ignored: tidy(raws) };
931
939
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
@@ -933,7 +941,7 @@ function readSnapshots(raw: unknown): {
933
941
  return done();
934
942
  }
935
943
  const sn = raw as Record<string, unknown>;
936
- const known = new Set(["dir", "keep", "mirror"]);
944
+ const known = new Set(["dir", "keep", "mirror", "daily"]);
937
945
  for (const key of Object.keys(sn)) {
938
946
  // An unknown sub-key is REPORTED rather than dropped in silence: a typo'd
939
947
  // `"mirrors"` that quietly did nothing is how somebody believes they have a
@@ -972,6 +980,11 @@ function readSnapshots(raw: unknown): {
972
980
  out.keep = keep;
973
981
  }
974
982
  }
983
+ const daily = sn["daily"];
984
+ if (daily !== undefined) {
985
+ if (typeof daily !== "boolean") ignored(`"snapshots.daily" was ${JSON.stringify(daily)}; taking the daily copy`);
986
+ else out.daily = daily;
987
+ }
975
988
  return done();
976
989
  }
977
990
 
@@ -370,7 +370,7 @@ export const DURABLE_EVENTS = {
370
370
  // Raw-transcript retention (2026-09-23, B3). One row per date; `STARTED` goes
371
371
  // in when the pass takes its latch and `LATCH_HELD` when a later worker finds
372
372
  // the latch taken with no row, so a pass that died is never a silence.
373
- "remember.prune": "the week-old raw transcript of sessions that owe nothing was deleted (sessions deleted, kept because they still owe a write-up, kept because they are under a week old or still open, and any that failed — or STARTED / LATCH_HELD for a pass that has not finished)",
373
+ "remember.prune": "the week-old raw transcript of sessions that owe nothing was deleted (sessions deleted, kept because they still owe a write-up, kept because they are under a week old or still open, any that failed, and the old notes with no session let go line by line — or STARTED / LATCH_HELD for a pass that has not finished)",
374
374
  // The vector cache's identity check (2026-09-23, #190). Written only when an
375
375
  // open CHANGED something — never for a match — so a quiet week is no rows.
376
376
  "store.embedder.reconciled": "an open changed which model the stored vectors are filed under (reset to a new table and refilled, a paid model's vectors held until somebody chooses, a hold released, untagged vectors adopted, a decision deferred, or vectors dropped by a rebuild)",
@@ -1123,8 +1123,12 @@ export const NARRATORS = {
1123
1123
  const deleted = n(t, "deleted") ?? 0;
1124
1124
  const owed = n(t, "keptOwed") ?? 0;
1125
1125
  const failed = n(t, "failed") ?? 0;
1126
+ const unbound = n(t, "unboundLines") ?? 0;
1127
+ const notes = `the raw copy of ${String(unbound)} old note${unbound === 1 ? "" : "s"} with no session`;
1126
1128
  const text =
1127
- `The raw transcript of ${String(deleted)} session${deleted === 1 ? "" : "s"} older than a week was let go` +
1129
+ (deleted === 0 && unbound > 0
1130
+ ? `${notes.charAt(0).toUpperCase()}${notes.slice(1)} ${unbound === 1 ? "was" : "were"} let go`
1131
+ : `The raw transcript of ${String(deleted)} session${deleted === 1 ? "" : "s"} older than a week was let go` + (unbound === 0 ? "" : `, and ${notes}`)) +
1128
1132
  (owed === 0 ? "." : `; ${String(owed)} ${owed === 1 ? "is" : "are"} kept until written up.`) +
1129
1133
  (failed === 0 ? "" : ` ${String(failed)} could not be deleted and will be tried again.`);
1130
1134
  return failed === 0 ? calm(text) : amber(text);
@@ -95,7 +95,10 @@ export const LOGGED: { readonly names: ReadonlySet<string>; readonly suffixes: r
95
95
  "adapter.night.writeup",
96
96
  // ...and what its own transcript said about the host's cut (2026-10-09).
97
97
  "adapter.night.spill",
98
- // ...and a run a session nobody watched started (2026-10-01, lane 8).
98
+ // ...and a sleep it noticed (2026-11-01, NT1).
99
+ "adapter.night.slept",
100
+ // ...and a run a session nobody watched started, or a headless session
101
+ // passed on (2026-10-01, lane 8; 2026-11-01, NT1).
99
102
  "adapter.dream.unwatched",
100
103
  "dream.night",
101
104
  "self.page.writer.ran",
@@ -328,7 +328,9 @@ actually wrote (chapter), the written self page or the version a write to it pro
328
328
  `not-asked` (a fetch it was not pointed at, memories before a fetch), `wrong-part`,
329
329
  `part-already-written`, `memories-required` (present and not a list),
330
330
  `nothing-landed` (every entry of a non-empty batch refused; a duplicate counts as
331
- landed), `io-failed` (the fetch could not record the hand-over, so hands nothing),
331
+ landed), `part-not-landed` (a memory of this part threw and the same memories can come
332
+ back: what landed stands and the part stays open; on a last part where one landed its
333
+ claim took the words, so the part closes and says `notLanded`), `io-failed` (the fetch could not record the hand-over, so hands nothing),
332
334
  `claimed` (another writer holds it now), `allowance-spent` (a granted runner past
333
335
  the part its launcher allowed tonight) and `grant-expired` (a nightly runner whose
334
336
  record ended, or is older than `WRITE_UP_CLAIM_MS` because its process was killed).
@@ -775,4 +777,5 @@ Working defaults, held lightly; the revisit (a few days of daily use) checks the
775
777
  when there is one and under the literal `"mcp"` when there is not. Letting it BIND
776
778
  would give an in-the-moment jot the power to claim a day, which is more privilege
777
779
  than the tool needs; leaving it means an unbound server's notes still carry no
778
- session. Neither is obviously right yet.
780
+ session. Neither is obviously right yet. (Their raw copies go line by line on their own
781
+ age since 2026-11-01, `remember/owes.ts#planUnboundLines`.)
@@ -121,6 +121,11 @@ but dedup, so the blast radius is unchanged; the honest fix is also unchanged
121
121
  key (or an explicitly session-free deliberate mode) is what would end the
122
122
  borrowing rather than narrowing it.
123
123
 
124
+ **A second thing did key off it (2026-11-01).** A `remember` with no live session files
125
+ its raw copy under the same id, and retention judged all of those as one session, so a
126
+ new note restarted the clocks for the rest. Retention now judges that id's lines one by
127
+ one (`remember/owes.ts#planUnboundLines`). The id itself is unchanged.
128
+
124
129
  ## 7. `openServer` has no embedder socket — a memory noted through the tool gets no vector — CLOSED 2026-09-23 (#190)
125
130
 
126
131
  **Closed by #190 (roadmap C1), option 1 below.** `OpenServerOptions` carries `embed?:
@@ -618,7 +618,8 @@ anything else: `sqlite3 "$DB" "UPDATE meta SET value = '$V' WHERE key = 'schemaV
618
618
  - **Duplicates count as landed**, and an empty batch is a real answer (owner, 2026-09-23):
619
619
  a batch whose every entry is `duplicate-content` says what the store already holds, and
620
620
  `[]` says nothing in the part was worth keeping. Only a non-empty batch the gate refused
621
- entirely (`nothing-landed`) leaves the part open.
621
+ entirely (`nothing-landed`), or one with an entry whose mint threw (`part-not-landed`,
622
+ 2026-11-01), leaves the part open.
622
623
  - **A write-up's PROPOSALS are the WRITING session's, and B3 reads them that way** (the
623
624
  MEMORY is the ended session's since 2026-10-01: origin, lived date, `secondHand`). They
624
625
  are accepted `session-end` proposals under the live session's id, so if that session
@@ -23,7 +23,7 @@ import {
23
23
  tagsEcho,
24
24
  threadOf,
25
25
  } from "./server-args.js";
26
- import { TITLE_ASKED_NOTE, chatWordsFor } from "./server-words.js";
26
+ import { TITLE_ASKED_NOTE, chatWordsFor, threwDetail } from "./server-words.js";
27
27
  import type { FeelingsRead, ReminderRead, AboutRead, TraitsRead, FactsRead, TagsRead } from "./server-args.js";
28
28
  import type { McpServer } from "./server.js";
29
29
 
@@ -329,7 +329,7 @@ export async function depositEntries(
329
329
  });
330
330
  } catch (err) {
331
331
  // Isolation, not a lost dump: this entry failed, the rest still run.
332
- outcomes.push({ stored: false, reason: "threw", detail: String((err as Error).message ?? err) });
332
+ outcomes.push({ stored: false, reason: "threw", detail: threwDetail(err) });
333
333
  continue;
334
334
  }
335
335
  if (result.deposited) deposited += 1;
@@ -21,7 +21,7 @@ export const SERVER_NAME = "counterparts";
21
21
  * host decides whether to trust what follows. Read from a constant rather than
22
22
  * from disk so the server opens no file to answer its first message.
23
23
  */
24
- export const SERVER_VERSION = "0.3.44";
24
+ export const SERVER_VERSION = "0.3.45";
25
25
 
26
26
  /**
27
27
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -96,6 +96,15 @@ export function schemaUnreadableRefusal(host: string = DEFAULT_HOST): string {
96
96
 
97
97
  export const SCHEMA_UNREADABLE_REFUSAL = schemaUnreadableRefusal(DEFAULT_HOST);
98
98
 
99
+ /**
100
+ * A WRITE THAT THREW (2026-11-01). True however far it got: nothing is claimed
101
+ * unless the memory is on disk, so the same call either lands or says so. It
102
+ * says when to stop too: a full disk throws every time, and nothing here counts.
103
+ */
104
+ export function threwDetail(err: unknown): string {
105
+ return `${String((err as Error).message ?? err)}. The memory may not have been saved: send the same thing again. It lands, or comes back duplicate-content if it already had. If it keeps failing, say so and go on.`;
106
+ }
107
+
99
108
  /** And when the store was merely busy past the wait: a retry, not a reconnect. */
100
109
  export const STORE_BUSY_REFUSAL =
101
110
  "The memory store was busy, so this tool did nothing. Try again in a moment.";
@@ -423,7 +432,7 @@ export const DREAMING_OFF_REFUSAL =
423
432
  export type DreamingSettingWords = Readonly<Record<"auto" | "ask" | "off", string>>;
424
433
 
425
434
  export const CLAUDE_CODE_SETTING_SAID: DreamingSettingWords = {
426
- auto: "Dreaming on its own: once a day, the first session starts the nightly run by itself, in a separate windowless session in the background, and says so in one line. Today's run is still yours to start, if the owner asked for it.",
435
+ auto: "Dreaming on its own: once a day, the first session a person starts begins the nightly run by itself, in a separate windowless session in the background, and says so in one line. Today's run is still yours to start, if the owner asked for it.",
427
436
  ask: "Dreaming asks first: once a day, the first session shows the owner the question in the terminal and waits for their word.",
428
437
  off: "No dreams: nothing starts the nightly run and nothing asks. It can be turned back on with this phase (value ask or auto) when the owner says so.",
429
438
  };