counterparts 0.3.19 → 0.3.21

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 (108) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/README.md +12 -4
  3. package/docs/module-map.md +6 -0
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +14 -13
  6. package/src/adapters/claude-code/NOTES.md +29 -0
  7. package/src/adapters/claude-code/bin/hook.ts +12 -4
  8. package/src/adapters/claude-code/bin/runner.ts +41 -20
  9. package/src/adapters/claude-code/doctor.ts +123 -30
  10. package/src/adapters/claude-code/hooks.ts +70 -86
  11. package/src/adapters/claude-code/index.ts +0 -3
  12. package/src/adapters/cli/NOTES.md +8 -0
  13. package/src/adapters/cli/commands-delete.ts +273 -0
  14. package/src/adapters/cli/commands-install.ts +29 -10
  15. package/src/adapters/cli/commands-note.ts +1 -1
  16. package/src/adapters/cli/commands-readings.ts +4 -2
  17. package/src/adapters/cli/commands-scope.ts +25 -4
  18. package/src/adapters/cli/commands-self.ts +4 -1
  19. package/src/adapters/cli/commands-start-fresh.ts +1 -1
  20. package/src/adapters/cli/commands.ts +22 -3
  21. package/src/adapters/cli/help.ts +7 -7
  22. package/src/adapters/cli/install.ts +4 -2
  23. package/src/adapters/cli/mechanisms.ts +2 -2
  24. package/src/adapters/cli/removal.ts +1 -1
  25. package/src/adapters/config.ts +112 -30
  26. package/src/adapters/dashboard/CONTRACT.md +14 -0
  27. package/src/adapters/dashboard/NOTES.md +15 -0
  28. package/src/adapters/dashboard/activity.ts +1 -1
  29. package/src/adapters/dashboard/bin/dashboard.ts +3 -3
  30. package/src/adapters/dashboard/browse.ts +1 -1
  31. package/src/adapters/dashboard/identity.ts +1 -1
  32. package/src/adapters/dashboard/registries.ts +14 -14
  33. package/src/adapters/dashboard/resolve.ts +1 -1
  34. package/src/adapters/dashboard/status.ts +5 -2
  35. package/src/adapters/dashboard/web/actions.ts +21 -2
  36. package/src/adapters/dashboard/web/app.html +1 -1
  37. package/src/adapters/dashboard/web/flow.ts +1 -1
  38. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +2 -2
  39. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +1 -1
  40. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -1
  41. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +2 -2
  42. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +3 -3
  43. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +2 -2
  44. package/src/adapters/dashboard/web/narrate.ts +11 -11
  45. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +1 -1
  46. package/src/adapters/dashboard/web/pages/health/sections/checks.js +3 -2
  47. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +5 -5
  48. package/src/adapters/dashboard/web/pages/health/sections/mechanisms.js +1 -1
  49. package/src/adapters/dashboard/web/pages/health/sections/wake.js +2 -2
  50. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +73 -3
  51. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +2 -2
  52. package/src/adapters/dashboard/web/pages/self/sections/journal.js +5 -5
  53. package/src/adapters/dashboard/web/pages/self/sections/page.js +13 -13
  54. package/src/adapters/dashboard/web/pages/self/sections/settling.js +1 -1
  55. package/src/adapters/dashboard/web/pages/self/sections/wake.js +7 -7
  56. package/src/adapters/dashboard/web/server.ts +9 -1
  57. package/src/adapters/dashboard/web/shared/event-modal.js +1 -1
  58. package/src/adapters/dashboard/web/shared/memory-card-words.js +1 -1
  59. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -5
  60. package/src/adapters/dashboard/web/views/activity.ts +1 -1
  61. package/src/adapters/dashboard/web/views/dreams.ts +1 -1
  62. package/src/adapters/dashboard/web/views/health.ts +1 -1
  63. package/src/adapters/dashboard/web/views/mechanisms.ts +6 -6
  64. package/src/adapters/dashboard/web/views/mind.ts +21 -9
  65. package/src/adapters/dashboard/web/views/overview.ts +3 -3
  66. package/src/adapters/expansions.ts +14 -1
  67. package/src/adapters/fired.ts +1 -1
  68. package/src/adapters/lifecycle.ts +25 -4
  69. package/src/adapters/log/index.ts +21 -0
  70. package/src/adapters/mcp/CONTRACT.md +1 -1
  71. package/src/adapters/mcp/server-self-tools.ts +25 -1
  72. package/src/adapters/mcp/server-words.ts +3 -2
  73. package/src/adapters/mcp/server.ts +45 -9
  74. package/src/adapters/mcp/tools.ts +4 -3
  75. package/src/adapters/plugin.ts +44 -8
  76. package/src/adapters/sessions.ts +5 -2
  77. package/src/adapters/snapshots.ts +90 -1
  78. package/src/adapters/store-id.ts +58 -0
  79. package/src/core/counterpart-boundary.ts +9 -0
  80. package/src/core/counterpart.ts +19 -6
  81. package/src/core/dream/CONTRACT.md +8 -0
  82. package/src/core/dream/index.ts +15 -2
  83. package/src/core/handoff/last-here.ts +24 -12
  84. package/src/core/onboarding.ts +231 -62
  85. package/src/core/prospective/CONTRACT.md +4 -1
  86. package/src/core/prospective/index.ts +23 -5
  87. package/src/core/recall/CONTRACT.md +3 -1
  88. package/src/core/recall/INTERFACE-GAPS.md +1 -1
  89. package/src/core/recall/NOTES.md +14 -0
  90. package/src/core/recall/session.ts +40 -1
  91. package/src/core/reconsolidation.ts +1 -1
  92. package/src/core/remember/CONTRACT.md +14 -8
  93. package/src/core/remember/owes.ts +68 -28
  94. package/src/core/remember/owner-strike-seam.ts +6 -3
  95. package/src/core/remember/spans.ts +3 -2
  96. package/src/core/remember/tunables.ts +18 -5
  97. package/src/core/remember/write-up-seam.ts +2 -1
  98. package/src/core/self/CONTRACT.md +25 -9
  99. package/src/core/self/NOTES.md +6 -0
  100. package/src/core/self/briefing-delivery.ts +349 -0
  101. package/src/core/self/briefing-page.ts +315 -0
  102. package/src/core/self/briefing-room.ts +563 -0
  103. package/src/core/self/briefing.ts +304 -1156
  104. package/src/core/self/index.ts +28 -6
  105. package/src/core/store/NOTES.md +6 -5
  106. package/src/core/store/index.ts +39 -0
  107. package/src/core/store/paths.ts +9 -2
  108. package/src/adapters/claude-code/primacy.ts +0 -162
@@ -100,7 +100,7 @@ import {
100
100
  readSnapshotsDir,
101
101
  resolveSnapshotsDir,
102
102
  } from "../snapshots.js";
103
- import { TUNABLES, resolveEmbedder, withEmbedderDefault } from "../config.js";
103
+ import { TUNABLES, resolveEmbedder, retentionClocks, withEmbedderDefault } from "../config.js";
104
104
  import type { EmbedderSource } from "../config.js";
105
105
  import { MODEL_FILE, STATIC_WEIGHTS_ENV, STATIC_WEIGHTS_PACKAGE, resolveStaticWeights } from "../../core/embed/static.js";
106
106
  import { DATABASE_FILE, heldExits, readRollbackHold, rollbackHeld } from "../../core/store/index.js";
@@ -386,6 +386,21 @@ function unreadableClause(keys: readonly string[] | undefined): string {
386
386
  }
387
387
 
388
388
  /** The config file itself: the one the hooks read, and whether it was readable. */
389
+ /**
390
+ * WHICH WAKE CEILING IS IN FORCE (2026-10-12). A configuration with no
391
+ * `injectionBudgetBytes` wakes under Claude Code's default
392
+ * (`config.ts#withBudgetDefault`) — the plugin's first run and scripted
393
+ * installs wrote none before 0.3.20 — and the line says which, so "the file
394
+ * says 9000" and "nothing said, 9000 was used" read differently.
395
+ */
396
+ function ceilingClause(config: AdapterConfig): string {
397
+ const bytes = config.injectionBudgetBytes;
398
+ if (bytes === undefined) return "; no wake ceiling, so no wake is composed";
399
+ return config.injectionBudgetDefaulted === true
400
+ ? `; wake ceiling ${String(bytes)} bytes, Claude Code's default (the file sets no injectionBudgetBytes)`
401
+ : `; wake ceiling ${String(bytes)} bytes`;
402
+ }
403
+
389
404
  function configFindings(input: DoctorInput): Finding[] {
390
405
  const out: Finding[] = [];
391
406
  const reason = input.configReason;
@@ -452,9 +467,15 @@ function configFindings(input: DoctorInput): Finding[] {
452
467
  "config",
453
468
  "green",
454
469
  "Config",
455
- `${input.configPath} — read; dataDir ${input.config.dataDir ?? "(unset: the default store)"}`,
470
+ `${input.configPath} — read; dataDir ${input.config.dataDir ?? "(unset: the default store)"}${ceilingClause(input.config)}`,
456
471
  "",
457
- { path: input.configPath, reason: reason ?? "read-by-caller", dataDir: input.config.dataDir ?? null },
472
+ {
473
+ path: input.configPath,
474
+ reason: reason ?? "read-by-caller",
475
+ dataDir: input.config.dataDir ?? null,
476
+ ceiling: input.config.injectionBudgetBytes ?? null,
477
+ ceilingDefaulted: input.config.injectionBudgetDefaulted === true,
478
+ },
458
479
  ),
459
480
  );
460
481
  // SETTINGS THIS BUILD NO LONGER READS (keyless, 2026-09-24) — a quiet note,
@@ -834,12 +855,12 @@ const KEY_HISTORY_ROWS = 200;
834
855
  * RAW TRANSCRIPTS — how long the captured conversation is kept, and what the
835
856
  * newest retention pass did (remember INTERFACE-GAPS §11; roadmap B3).
836
857
  *
837
- * The first clause is the POLICY, worded so it does not over-promise (PR #189
838
- * review m4, m5): the text lives in the store for a week after a session ends,
839
- * and each daily snapshot holds a copy of whatever was there that day, so the
840
- * last copy is gone only after the snapshots rotate past it too. Both numbers
841
- * are read — the week from `remember/`'s tunable, the snapshots from the
842
- * configuration's `keep` — never retyped.
858
+ * The first clause is the POLICY (Mike, 2026-10-13): the text is deleted a
859
+ * few days after a session is written up and ended, and never kept past the
860
+ * ceiling, owed or not; backups never hold it. Both numbers are read — the
861
+ * configuration's `retention` block, else `remember/`'s defaults, through
862
+ * `config.ts#retentionClocks` — never retyped. A field in that block this
863
+ * could not read is named, amber, the way the Snapshot line names its own.
843
864
  *
844
865
  * The rest is the newest `remember.prune` row, in sessions. Grades:
845
866
  *
@@ -855,11 +876,24 @@ const KEY_HISTORY_ROWS = 200;
855
876
  */
856
877
  function retentionFindings(input: DoctorInput, store: Store): Finding[] {
857
878
  const TITLE = "Raw transcripts";
858
- const days = Math.round(REMEMBER_TUNABLES.RETENTION_MS / 86_400_000);
859
- const keep = keepOf(input.config.snapshots?.keep);
860
- const policy = `${String(days)} days after a session ends (up to ${String(days + keep)} counting the daily snapshots)`;
879
+ const clocks = retentionClocks(input.config);
880
+ const days = clocks.afterWriteUpDays;
881
+ const policy = `deleted ${String(days)} day${days === 1 ? "" : "s"} after a session is written up and ended, never kept more than ${String(clocks.maxDays)} · never in backups`;
861
882
  const run = lastRetentionRun(store);
862
- const base = { retentionDays: days, snapshotKeep: keep };
883
+ const base = { retentionDays: days, maxDays: clocks.maxDays };
884
+ const ignored = input.config.retention?.ignored ?? [];
885
+ if (ignored.length > 0) {
886
+ return [
887
+ finding(
888
+ "retention",
889
+ "amber",
890
+ TITLE,
891
+ `${policy} · the configuration's retention block was partly ignored: ${ignored.join("; ")}`,
892
+ `Fix "retention" in ${tilde(input.configPath)}: whole days, at least 1.`,
893
+ { ...base, ran: run !== null, ignored: ignored.length },
894
+ ),
895
+ ];
896
+ }
863
897
  if (run === null) {
864
898
  return [finding("retention", "green", TITLE, `${policy} · not run yet`, "", { ...base, ran: false })];
865
899
  }
@@ -933,13 +967,13 @@ function clockFindings(input: DoctorInput, store: Store): Finding[] {
933
967
  // the clock, so the comparison is not made and the line says why.
934
968
  if (read.unknown) {
935
969
  const facts =
936
- `lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} ${zoneNote(input)} — ` +
970
+ `day ${livedDay} of use, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} ${zoneNote(input)} — ` +
937
971
  undetermined(BOUNDARY_EVENT);
938
972
  return [finding("clock", "green", "Clock", facts, "", data)];
939
973
  }
940
974
  const facts =
941
- `lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, ` +
942
- `newest boundary ${boundary ?? "(none)"}, today ${input.today} ${zoneNote(input)}`;
975
+ `day ${livedDay} of use, lastActiveDate ${lastActive ?? "(unset)"}, ` +
976
+ `last session end ${boundary ?? "(none)"}, today ${input.today} ${zoneNote(input)}`;
943
977
  if (boundary !== null && (lastActive === null || lastActive < boundary)) {
944
978
  return [
945
979
  finding(
@@ -955,6 +989,28 @@ function clockFindings(input: DoctorInput, store: Store): Finding[] {
955
989
  return [finding("clock", "green", "Clock", facts, "", data)];
956
990
  }
957
991
 
992
+ /**
993
+ * HAS THE WORKER HAD A WHOLE DAY? The first boundary a store reaches (its first
994
+ * session after midnight) starts the first night run, which writes its rows when
995
+ * it FINISHES, minutes later. A doctor run in that window is not a fault: absent
996
+ * rows are evidence of trouble only once a boundary from an earlier day exists.
997
+ * "never" = no boundary yet; "today" = the newest is today's and the run is owed
998
+ * its time; "earlier" = a worker has had its chance.
999
+ */
1000
+ function boundaryAge(store: Store, today: string): "never" | "today" | "earlier" {
1001
+ // ALL boundary rows, not the newest: every active day writes one, so the newest
1002
+ // is today's on any day the store has been used, however long it has lived.
1003
+ const rows = store.eventLog({ name: BOUNDARY_EVENT, limit: 4000 });
1004
+ if (rows.length === 0) return "never";
1005
+ if (rows.length >= 4000) return "earlier"; // certainly lived
1006
+ return rows.some((r) => {
1007
+ const d = rowDate(r);
1008
+ return d !== null && d < today;
1009
+ })
1010
+ ? "earlier"
1011
+ : "today";
1012
+ }
1013
+
958
1014
  /** The newest row of each family the background half leaves behind. */
959
1015
  function rowFindings(input: DoctorInput, store: Store): Finding[] {
960
1016
  const livedDay = store.livedDay();
@@ -968,13 +1024,21 @@ function rowFindings(input: DoctorInput, store: Store): Finding[] {
968
1024
  */
969
1025
  // `unknown` means the store holds MORE than `NEWEST_LIMIT` boundary rows, so
970
1026
  // it has certainly lived — the one thing this flag needs to know.
971
- const boundaries = newestRows(store, BOUNDARY_EVENT, 1, livedDay);
972
- const lived = boundaries.unknown || boundaries.rows.length > 0;
973
- /** The "no row yet" finding: amber once the store has lived, green before. */
1027
+ const age = boundaryAge(store, input.today);
1028
+ /** The "no row yet" finding: amber once a worker has had a whole day, green before. */
974
1029
  const absent = (key: string, title: string, what: string, fix: string): Finding =>
975
- lived
1030
+ age === "earlier"
976
1031
  ? finding(key, "amber", title, what, fix, { rows: 0 })
977
- : finding(key, "green", title, `${what} — and no boundary has been reached here yet`, "", { rows: 0 });
1032
+ : finding(
1033
+ key,
1034
+ "green",
1035
+ title,
1036
+ age === "today"
1037
+ ? `${what} — the first night run starts today and writes this when it finishes`
1038
+ : `${what} — and no session has ended here yet`,
1039
+ "",
1040
+ { rows: 0 },
1041
+ );
978
1042
  /** The "we could not read the newest one" finding: neutral, never a grade. */
979
1043
  const unread = (key: string, title: string, name: string): Finding =>
980
1044
  finding(key, "green", title, undetermined(name), "", { unknown: true });
@@ -1561,8 +1625,7 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1561
1625
  "fired",
1562
1626
  "green",
1563
1627
  "Fired",
1564
- `this store is on lived day ${String(report.livedDay)} — too new to grade; nothing has fired ` +
1565
- `because nothing has happened yet` +
1628
+ `Too new to judge yet: nothing has run because you've only just started` +
1566
1629
  (c.blocked === 0 ? "" : `, though ${String(c.blocked)} was already stopped by something`),
1567
1630
  c.blocked === 0 ? "" : "Run: counterparts mechanisms --all — the blocked rows say by what.",
1568
1631
  data,
@@ -2538,12 +2601,18 @@ export function wakeArrivalFindings(store: Store): Finding[] {
2538
2601
  lastHereNoRoom: room.lastHereNoRoom,
2539
2602
  workNoRoom: room.workNoRoom,
2540
2603
  datedUnlisted: room.datedUnlisted,
2604
+ steppedDown: room.steppedDown,
2605
+ untold: room.untold,
2541
2606
  floor,
2542
2607
  };
2543
2608
  const head =
2544
2609
  expected <= 0
2545
2610
  ? `${window} — no wake checked on arrival (an opt-in check: COUNTERPARTS_WAKE_CHECK=1 in Claude Code's environment)`
2546
2611
  : `${window} — ${String(whole)} of ${String(expected)} ${expected === 1 ? "wake" : "wakes"} arrived whole`;
2612
+ // A LANE LEFT WITHOUT A WORD (2026-10-12) is a bug, not a full wake: red.
2613
+ if (room.red !== null) {
2614
+ return [finding("wake", "red", "Wake", `${head}${rest}`, room.red, data)];
2615
+ }
2547
2616
  if (cut === 0 && room.amber !== null) {
2548
2617
  return [
2549
2618
  finding(
@@ -2582,8 +2651,17 @@ interface WakeRoom {
2582
2651
  readonly lastHereNoRoom: number;
2583
2652
  readonly workNoRoom: number;
2584
2653
  /** Wake renders that left a dated item ("Arriving:") unlisted for want of
2585
- * room (2026-10-10) — amber. */
2654
+ * room (2026-10-10) — amber. Counted, since 2026-10-12, not gone. */
2586
2655
  readonly datedUnlisted: number;
2656
+ /** Wake renders that said some lane by count rather than in full — a
2657
+ * step-down (a lane's cap, the identity share, the trim), never a fault
2658
+ * (2026-10-12). */
2659
+ readonly steppedDown: number;
2660
+ /** Wake renders that left an id unsaid — in no line, not even a count — a
2661
+ * silent drop: red (2026-10-12). */
2662
+ readonly untold: number;
2663
+ /** The red's remedy, or null when nothing here is red. */
2664
+ readonly red: string | null;
2587
2665
  /** The clauses, each led by "; ", or "". */
2588
2666
  readonly clauses: string;
2589
2667
  /** The amber's remedy, or null when nothing here is amber. */
@@ -2615,9 +2693,17 @@ function wakeRoom(store: Store, since: number): WakeRoom {
2615
2693
  // row says "Arriving:" lost an element for want of room
2616
2694
  // (`self/briefing.ts#ROOM_ORDER`) — by its uncapped per-lane count, or, on
2617
2695
  // a row from before that count, by its trimmed list.
2618
- const datedRows = read(SELF_BRIEFING_EVENT).filter((r) => datedUnlisted(payloadOf(r)) > 0);
2696
+ const briefings = read(SELF_BRIEFING_EVENT);
2697
+ const datedRows = briefings.filter((r) => datedUnlisted(payloadOf(r)) > 0);
2619
2698
  const datedUnlistedRenders = datedRows.length;
2620
2699
  const datedNewest = rowDate(datedRows[0]);
2700
+ // STEP-DOWNS AND SILENT DROPS (2026-10-12, `self/briefing.ts#tellLost`): a
2701
+ // lane said by count is the wake doing its job; an id no line names is not.
2702
+ // "Nearby" left uncounted by rank (`quiet`) is a step-down too.
2703
+ const steppedDown = briefings.filter((r) => (num(payloadOf(r), "counted") ?? 0) + (num(payloadOf(r), "quiet") ?? 0) > 0).length;
2704
+ const untoldRows = briefings.filter((r) => (num(payloadOf(r), "untold") ?? 0) > 0);
2705
+ const untold = untoldRows.length;
2706
+ const untoldNewest = rowDate(untoldRows[0]);
2621
2707
  const parts = Object.entries(gaveWay)
2622
2708
  .sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1))
2623
2709
  .map(([part, n]) => `${part} ${String(n)}`);
@@ -2640,7 +2726,10 @@ function wakeRoom(store: Store, since: number): WakeRoom {
2640
2726
  : "") +
2641
2727
  (workNoRoom > 0 ? `; "Work here" lines that did not fit, in ${String(workNoRoom)} ${workNoRoom === 1 ? "directory-day" : "directory-days"}` : "") +
2642
2728
  (datedUnlistedRenders > 0
2643
- ? `; a dated item under "Arriving:" was not listed for want of room in ${String(datedUnlistedRenders)} ${datedUnlistedRenders === 1 ? "render" : "renders"} of the wake${datedNewest === null ? "" : ` (newest ${datedNewest})`}`
2729
+ ? `; a dated item under "Coming up:" was counted, not listed, for want of room in ${String(datedUnlistedRenders)} ${datedUnlistedRenders === 1 ? "render" : "renders"} of the wake${datedNewest === null ? "" : ` (newest ${datedNewest})`}`
2730
+ : "") +
2731
+ (untold > 0
2732
+ ? `; something the wake chose went unsaid — in no line, not even a count — in ${String(untold)} ${untold === 1 ? "render" : "renders"}${untoldNewest === null ? "" : ` (newest ${untoldNewest})`}`
2644
2733
  : "");
2645
2734
  const remedies = [
2646
2735
  ...(datedUnlistedRenders > 0
@@ -2653,8 +2742,12 @@ function wakeRoom(store: Store, since: number): WakeRoom {
2653
2742
  : []),
2654
2743
  ];
2655
2744
  const amber = remedies.length === 0 ? null : remedies.join(" ");
2745
+ const red =
2746
+ untold === 0
2747
+ ? null
2748
+ : "Every lane the wake chose is meant to show whole, shortened, or as a count with its ids, so an id in no line is a bug in Counterparts, or a ceiling too small for the wake's own furniture. Worth reporting with this line; recall still finds the memories.";
2656
2749
  const any = clauses.length > 0;
2657
- return { overBudget, overCap, noticeDropped, gaveWay, handoffNoRoom, lastHereNoRoom, workNoRoom, datedUnlisted: datedUnlistedRenders, clauses, amber, any, floor };
2750
+ return { overBudget, overCap, noticeDropped, gaveWay, handoffNoRoom, lastHereNoRoom, workNoRoom, datedUnlisted: datedUnlistedRenders, steppedDown, untold, red, clauses, amber, any, floor };
2658
2751
  }
2659
2752
 
2660
2753
  /**
@@ -3102,8 +3195,8 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
3102
3195
  // The same rule the row findings use: an absent copy is only evidence once a
3103
3196
  // boundary has been reached. On a fresh install there has been no worker run
3104
3197
  // to take a first one, and an amber there is decoration.
3105
- const boundaries = newestRows(store, BOUNDARY_EVENT, 1, livedDay);
3106
- const lived = boundaries.unknown || boundaries.rows.length > 0;
3198
+ const age = boundaryAge(store, input.today);
3199
+ const lived = age === "earlier";
3107
3200
  const failed = newestRows(store, SNAPSHOT_FAILED_EVENT, 1, livedDay);
3108
3201
  const failedRow = failed.rows[0];
3109
3202
  const why =
@@ -3124,7 +3217,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
3124
3217
  "snapshot",
3125
3218
  "green",
3126
3219
  "Snapshots",
3127
- `no snapshot yet — and no boundary has been reached here yet${strange}${upgrade}${misread}`,
3220
+ `no snapshot yet — ${age === "today" ? "the first night run starts today and takes one when it finishes" : "and no boundary has been reached here yet"}${strange}${upgrade}${misread}`,
3128
3221
  "",
3129
3222
  { ...held, rows: 0 },
3130
3223
  ),
@@ -8,7 +8,7 @@
8
8
  * `Lifecycle` (2026-09-30), which `ClaudeCodeAdapter` extends; this file keeps
9
9
  * what is Claude Code's: its five events, its envelope and the room it
10
10
  * measures, its transcript's delivery check, the Stop ask's words, the
11
- * parallel run's primacy, the notices and the dream line. The rules this file
11
+ * notices and the dream line. The rules this file
12
12
  * mechanizes, each from the CONTRACT (some of them now in the lifecycle's
13
13
  * methods it calls):
14
14
  *
@@ -36,13 +36,8 @@
36
36
  * from PACING but kept in CAPTURE.** `substanceOf` counts one and
37
37
  * `captureSpans` receives the other; the two are computed from the same turns
38
38
  * in the same function, so they cannot drift apart.
39
- * **The parallel run's G3/G5 — exactly one system delivers, and the shadow is
40
- * ENCODE-ONLY.** Behind `parallel.enabled` (absent by default), every
41
- * DELIVERING hook asks `primacy.ts` first and stands down when the answer is
42
- * anything but a clean "engram". A stand-down withholds the wake, the recall
43
- * and both asks; it withholds NOTHING from capture, because the shadow's whole
44
- * job is to encode the same days v1 encodes. Both verdicts are durable
45
- * (parallel-run G4: the mute is evidenced, not asserted).
39
+ * (The parallel run's primacy stand-down — `parallel.enabled` and
40
+ * `primacy.ts` — was removed 2026-10-12; the parallel run ended 2026-09-21.)
46
41
  */
47
42
  import {
48
43
  CHECKOUT_EVENT,
@@ -50,13 +45,12 @@ import {
50
45
  ENVELOPE_OVERCAP_EVENT,
51
46
  INJECTION_OVERBUDGET_EVENT,
52
47
  NOTICE_DROPPED_EVENT,
53
- PRIMACY_DELIVER_EVENT,
54
- PRIMACY_STANDDOWN_EVENT,
55
48
  WAKE_DELIVERED_EVENT,
56
49
  WAKE_INJECTED_EVENT,
57
50
  } from "../../core/counterpart.js";
58
51
  import type { PlainReminder } from "../../core/counterpart.js";
59
52
  import { newNightRunId } from "../../core/dream/index.js";
53
+ import { PRONOUN_RULE, coverFinish, meetingHold } from "../../core/onboarding.js";
60
54
  import type { DreamOffer } from "../../core/dream/index.js";
61
55
  import type { BoundaryKind } from "../../core/remember/index.js";
62
56
  import { homedir } from "node:os";
@@ -84,7 +78,6 @@ import { TUNABLES } from "../config.js";
84
78
  import { TUNABLES as RECALL_TUNABLES } from "../../core/recall/tunables.js";
85
79
  import { SESSION_NOTICE_BUDGET_MS, checkoutIsGraded, doctorFindings, noticeMessage, readCheckout } from "./doctor.js";
86
80
  import type { CheckoutReading } from "./doctor.js";
87
- import { primacy } from "./primacy.js";
88
81
  import { nightRowTimeoutMs, planNightRunner } from "./night-run.js";
89
82
  import { NOTHING_OWED_BEFORE_KEY, catchUpOf, catchUpWords, owedBefore } from "./night-catch-up.js";
90
83
  import type { NightKind } from "./night-run.js";
@@ -295,6 +288,25 @@ export function isInteractive(input: Pick<HookInput, "entrypoint" | "attended">)
295
288
  return input.entrypoint === undefined || !NON_INTERACTIVE_ENTRYPOINTS.has(input.entrypoint);
296
289
  }
297
290
 
291
+ /**
292
+ * IS A PERSON THERE FOR THIS SESSION START? (2026-10-12.) `isInteractive`,
293
+ * and two starts no person makes even when the host says somebody attends:
294
+ * - the headless nightly run's child (`HookInput.nightRun`), named outright
295
+ * rather than left to the host's `sdk-cli` and `ATTENDED=0` (measured on
296
+ * 2.1.296: `claude -p` sets both in its hooks' environment), so the run's
297
+ * own marker holds whatever a later host sets;
298
+ * - a COMPACTION (`source: "compact"`): it fires mid-turn, so it is as
299
+ * watched as the turn that filled the context, which may be a hand-back no
300
+ * person typed, and a subagent's own compaction fires it too (measured
301
+ * 2026-10-10: `SessionStart:compact` inside an Agent-tool subagent, `cli`,
302
+ * handed a full wake). What a person is owed waits one prompt.
303
+ * A plain reminder and the first meeting's line read this (the wake row's
304
+ * `interactive` does not: it says who is in the session, not this start); `startup`, `clear` and `resume` are a person's.
305
+ */
306
+ export function watchedAtStart(input: Pick<HookInput, "entrypoint" | "attended" | "nightRun" | "source">): boolean {
307
+ return isInteractive(input) && input.nightRun !== true && input.source !== "compact";
308
+ }
309
+
298
310
  /** No plain reminders: what a session nobody watches is handed. */
299
311
  const NO_PLAIN: PlainLines = { context: "", notices: [], due: [] };
300
312
 
@@ -502,7 +514,7 @@ export const PAGE_WRITER_TOOL = "counterparts self_page";
502
514
  */
503
515
  export function stopAsk(sessionId: string, chapter: number): string {
504
516
  return [
505
- `${STOP_ASK_OPENER} 1) hand back what caught your attention since you last wrote, one idea each — what you read, what they said, what happened — with the counterparts session_end tool, session: ${sessionId}. \`handoff\` only if work here is unfinished; \`retireHandoff\` any now done; \`updates\` anything dated or open now done.`,
517
+ `${STOP_ASK_OPENER} 1) hand back what caught your attention since you last wrote, one idea each — what you read, what they said, what happened — with the counterparts session_end tool, session: ${sessionId}. \`handoff\` only if work here is unfinished; \`retireHandoff\` any now done; \`updates\` anything dated or open now done. ${PRONOUN_RULE}`,
506
518
  `2) Write chapter ${String(chapter)} with the counterparts chapter tool, session: ${sessionId}.`,
507
519
  ].join("\n");
508
520
  }
@@ -590,22 +602,14 @@ export class ClaudeCodeAdapter extends Lifecycle {
590
602
  // was handed its wake today: `noteSession` keeps the start, but a record
591
603
  // it CREATES (one pruned, or never written) would read as started now.
592
604
  const resumed = this.resumesToday(input);
593
- // BEFORE the delivery verdict, because the registry is not delivery: a
594
- // muted shadow still lives a session, and the tool that writes its dump
595
- // still has to be able to find out that the session is real.
596
605
  this.noteSession("start", input);
597
- // FIRST, before anything is read or composed: is this ours to deliver?
598
- // A stand-down sets no delivery expectation, because there is no render
599
- // for the next hook to check — recording one would put a false negative
600
- // into scar §2.3's telemetry on every muted day.
601
- if (!this.deliveryVerdict("session-start", input)) {
602
- return { ...out, ok: true, reason: "primacy-standdown" };
603
- }
604
606
  const budget = this.config.injectionBudgetBytes;
605
- if (budget === undefined) {
607
+ if (budget === undefined || this.config.injectionBudgetDefaulted === true) {
606
608
  // The tripwire. We inject what exists, and we say that nobody told us
607
- // what this host can carry — an invented ceiling is scar §2.18.
608
- this.emit("adapter.budget.unreported", {});
609
+ // what this host can carry — an invented ceiling is scar §2.18. A
610
+ // configuration with no key wakes under Claude Code's default since
611
+ // 2026-10-12 (`config.ts#withBudgetDefault`), and still trips it.
612
+ this.emit("adapter.budget.unreported", budget === undefined ? {} : { defaulted: budget });
609
613
  }
610
614
  // THE DELIVERY PREFACE is asked for here, at injection, and composed
611
615
  // nowhere else. The stored bundle was rendered at the last boundary and is
@@ -675,7 +679,8 @@ export class ClaudeCodeAdapter extends Lifecycle {
675
679
  // escaped envelope (`ENVELOPE_CHARS`), which cost a full wake its
676
680
  // reminders and both asks. What actually gave way is recorded by the
677
681
  // delivery (`noteGaveWay`) and by each ask's own deferral.
678
- const plain = isInteractive(input) ? this.plainFor(input) : NO_PLAIN;
682
+ const watched = watchedAtStart(input);
683
+ const plain = watched ? this.plainFor(input) : NO_PLAIN;
679
684
  // DESKTOP'S CODE TAB (2026-10-01): one line, right under the clock,
680
685
  // naming this session's id — there the counterparts tools the model sees
681
686
  // are Claude Desktop's server, which serves a call as this session only
@@ -683,8 +688,11 @@ export class ClaudeCodeAdapter extends Lifecycle {
683
688
  const codeTab = codeTabSessionLine(input);
684
689
  // THE FIRST MEETING'S MARKER (2026-10-11), on its own line under the
685
690
  // clock, on every session-start wake: the state word only, for the mod,
686
- // which cannot reach the dashboard before somebody starts it.
687
- const marker = `${this.onboardingMarker(input)}\n`;
691
+ // which cannot reach the dashboard before somebody starts it. The store
692
+ // marker on the line under it (2026-10-12) says which store this session
693
+ // opened, so the mod can tell this store's dashboard from another's.
694
+ const storeLine = this.storeMarker();
695
+ const marker = `${this.onboardingMarker(input)}\n${storeLine.length === 0 ? "" : `${storeLine}\n`}`;
688
696
  const lead = `${woke.text.length === 0 && plain.context.length === 0 && codeTab === null ? "" : `${this.nowLine()}\n`}${marker}${codeTab === null ? "" : `${codeTab}\n`}${plain.context}`;
689
697
  const sent = woke.bytes + Buffer.byteLength(lead, "utf8");
690
698
  const rides =
@@ -721,6 +729,8 @@ export class ClaudeCodeAdapter extends Lifecycle {
721
729
  // reminders. The `fired` report's plain-due check reads it, so a day
722
730
  // only the headless run or `claude -p` came is not a day a reminder
723
731
  // could have been said.
732
+ // Not `watched`: the fired report marks a session unattended for good
733
+ // on any start that says so, and a person's session compacts too.
724
734
  interactive: isInteractive(input) && input.nightRun !== true,
725
735
  // A resume's short wake (2026-10-11): `bytes` is the line, not a bundle.
726
736
  resumed,
@@ -755,7 +765,7 @@ export class ClaudeCodeAdapter extends Lifecycle {
755
765
  // While the meeting is still to happen the scope question waits: the
756
766
  // meeting asks where memory is on, and asking twice is the wall of
757
767
  // questions the meeting replaces.
758
- const meet = isInteractive(input) ? this.deliverMeetLine(input, room) : "";
768
+ const meet = watched ? this.deliverMeetLine(input, room) : "";
759
769
  const meetBytes = meet.length === 0 ? 0 : room.cost(`\n\n${meet}`);
760
770
  const scope = wantsAsk && !this.meetPending() ? this.deliverScopeAsk(input, { ...room, spent: room.spent + meetBytes }) : "";
761
771
  const chosen = [meet, scope].filter((a) => a.length > 0).join("\n\n");
@@ -896,9 +906,9 @@ export class ClaudeCodeAdapter extends Lifecycle {
896
906
  return "";
897
907
  }
898
908
  // The mark is a SECOND write of the same phase rather than a field folded
899
- // into the first: the first write happens before the delivery verdict (a
900
- // muted session still lives one) and the ask is decided after the wake, so
901
- // one write cannot carry both facts without moving the other.
909
+ // into the first: the first write happens before the wake is composed and
910
+ // the ask is decided after it, so one write cannot carry both facts
911
+ // without moving the other.
902
912
  const marked = recordSession(this.counterpart.store.dir, {
903
913
  sessionId: input.sessionId,
904
914
  scope: input.scope,
@@ -927,19 +937,12 @@ export class ClaudeCodeAdapter extends Lifecycle {
927
937
  // Desktop's Code tab, whose tools are Desktop's server (mcp CONTRACT
928
938
  // G21), that turn's calls ran unbound, filed under `claude-desktop:`.
929
939
  // This hook runs before the model makes any call, so the session is live
930
- // again by the time it names its id. Before the delivery verdict, like
931
- // the Stop's: the registry is not delivery. It REFRESHES a record and
940
+ // again by the time it names its id. It REFRESHES a record and
932
941
  // never creates one: a session with no record is the off→on flip
933
942
  // (#92 review, F1), which the Stop alone may make bindable.
934
943
  if (input.sessionId.length > 0 && readSession(this.counterpart.store.dir, input.sessionId) !== null) {
935
944
  this.noteSession("boundary", input);
936
945
  }
937
- // The stand-down precedes the delivery check for the same reason it
938
- // precedes the recall: a muted session rendered nothing, so there is no
939
- // expectation to test and a "not delivered" record would be a lie.
940
- if (!this.deliveryVerdict("user-prompt-submit", input)) {
941
- return { ...out, ok: true, reason: "primacy-standdown" };
942
- }
943
946
  this.checkWakeArrival(input);
944
947
  // A plain reminder whose day began while this session was already open —
945
948
  // the session that runs past midnight — or that SessionStart had no room
@@ -950,8 +953,10 @@ export class ClaudeCodeAdapter extends Lifecycle {
950
953
  const text = input.prompt ?? "";
951
954
  const byHost = isInteractive(input) && startedByHost(text);
952
955
  const plain = isInteractive(input) && !byHost ? this.plainFor(input) : NO_PLAIN;
953
- // Nor handed over there as a quiet cue, which would spend its fire.
954
- const waiting = byHost ? this.plainFor(input).due : plain.due;
956
+ // Nor handed over there as a quiet cue, which would spend its fire; and
957
+ // no quiet cue at all at such a turn (review of #453): each spends a fire
958
+ // of the person's day on a turn nobody reads.
959
+ const waiting = plain.due;
955
960
  const told: { notices?: readonly string[]; plain?: readonly PlainReminder[]; dream?: DreamTold; dreamNote?: { notice: string; context: string } } =
956
961
  plain.due.length === 0 ? {} : { notices: plain.notices, plain: plain.due };
957
962
  // The DREAM lines (2026-09-26): the once-a-day line, and any contradiction
@@ -975,6 +980,7 @@ export class ClaudeCodeAdapter extends Lifecycle {
975
980
  ...(budgetBytes === undefined ? {} : { budgetBytes }),
976
981
  // Said outright this turn, so not ALSO handed over as a quiet cue.
977
982
  ...(waiting.length === 0 ? {} : { withhold: new Set(waiting.map((r) => r.memoryId)) }),
983
+ ...(byHost ? { noCues: true } : {}),
978
984
  });
979
985
  const decision = result.decision;
980
986
  // "SINCE YOU STARTED" (2026-10-11): what changed in other directories
@@ -1455,20 +1461,13 @@ export class ClaudeCodeAdapter extends Lifecycle {
1455
1461
  // it, and a session already running when this shipped never saw a
1456
1462
  // SessionStart write — so this is also where it first becomes bindable.
1457
1463
  this.noteSession("boundary", input);
1458
- // The boundary is UNCONDITIONAL — the shadow encodes the same days v1
1459
- // encodes, and a parallel run that stopped capturing would be comparing
1460
- // nothing (parallel-run G5: encode-only, and honest). What the stand-down
1461
- // withholds is the ASK, which is delivery: an ask from a system the
1462
- // owner is not talking to today is exactly the double-voice G3 forbids.
1463
- const deliver = this.deliveryVerdict("stop", input);
1464
1464
  // THE WAKE'S ARRIVAL, closed here when the first prompt could not
1465
1465
  // (2026-10-08): the host writes the transcript only after that prompt, so
1466
- // the end of the first turn is where every session can be read. Muted
1467
- // sessions are not checked, for the prompt's reason. The check marks a
1466
+ // the end of the first turn is where every session can be read. The check marks a
1468
1467
  // record that exists and never makes one; a session the boundary above
1469
1468
  // just sealed (no record before it) has one with no sentinel, and says
1470
1469
  // `no-wake-expected` — what its second prompt used to say.
1471
- if (deliver) this.checkWakeArrival(input, { final: true });
1470
+ this.checkWakeArrival(input, { final: true });
1472
1471
  // THE AUTHORED FRONT DOOR, first: the experiencer writes its own memories
1473
1472
  // while it still has the pen, and the sweep the worker spawns below is
1474
1473
  // only the fallback for the day nobody got to (contract §4). The ask goes
@@ -1483,7 +1482,7 @@ export class ClaudeCodeAdapter extends Lifecycle {
1483
1482
  // the code did not keep: one evening's Stops billed 13 chunks and minted
1484
1483
  // 61 memories beside 34 the model had authored itself.
1485
1484
  // The headless nightly run is asked nothing (`HookInput.nightRun`).
1486
- const ask = deliver && input.nightRun !== true ? this.askAtStop(input) : null;
1485
+ const ask = input.nightRun !== true ? this.askAtStop(input) : null;
1487
1486
  const spawn = this.spawnWorker(input);
1488
1487
  return { ...claimed, ask, spawn };
1489
1488
  });
@@ -1533,40 +1532,6 @@ export class ClaudeCodeAdapter extends Lifecycle {
1533
1532
 
1534
1533
  // ── internals ──────────────────────────────────────────────────────────────
1535
1534
 
1536
- /**
1537
- * MAY THIS HOOK DELIVER? — the parallel run's G3, at every delivering channel.
1538
- *
1539
- * Without the knob this is `true` and nothing is emitted at all: the flag's
1540
- * absence must be indistinguishable from a build that never had it, or every
1541
- * test and every ordinary session grows a primacy record it cannot explain.
1542
- *
1543
- * With the knob, `primacy()` decides and BOTH verdicts are recorded — the
1544
- * stand-down because an unevidenced mute is indistinguishable from a broken
1545
- * hook (parallel-run G4, scar §2.4), and the delivery because a Phase P day
1546
- * has to be able to show positive evidence that v2 spoke. Each record goes to
1547
- * the ring AND to box 2, because the ring dies with the hook process and the
1548
- * daily count is a claim about the run.
1549
- *
1550
- * `date` rides in the durable payload deliberately: the log's `day` column is
1551
- * the store's LIVED day, which only the heavy cycle advances, so a hook-path
1552
- * row would stamp whatever lived day the store was already on.
1553
- */
1554
- private deliveryVerdict(hook: HookName, input: HookInput): boolean {
1555
- if (this.config.parallel?.enabled !== true) return true;
1556
- const verdict = primacy();
1557
- const name = verdict.deliver ? PRIMACY_DELIVER_EVENT : PRIMACY_STANDDOWN_EVENT;
1558
- const data = {
1559
- hook,
1560
- reason: verdict.reason,
1561
- system: verdict.system,
1562
- date: input.at ?? null,
1563
- session: input.sessionId,
1564
- };
1565
- this.emit(name, data);
1566
- this.counterpart.noteAdapterEvent(name, data);
1567
- return verdict.deliver;
1568
- }
1569
-
1570
1535
  /**
1571
1536
  * Capture and record the boundary — `Lifecycle#captureBoundary`, under this
1572
1537
  * host's event name and boundary kind. ONE function for all three paths, so a
@@ -1589,6 +1554,25 @@ export class ClaudeCodeAdapter extends Lifecycle {
1589
1554
  */
1590
1555
  private askAtStop(input: HookInput): string | null {
1591
1556
  if (input.reFired === true) return null;
1557
+ // THE FIRST MEETING HOLDS THE ASK (2026-10-12, onboarding round 1, A).
1558
+ // Under way in this session: nothing is asked and the pacer is not
1559
+ // consulted, so nothing advances. Just finished here: its finish step
1560
+ // handed over the write-up, so this one Stop is paced (the pacer counts
1561
+ // the write-up as asked) and says nothing.
1562
+ const hold = meetingHold(this.counterpart.store, input.sessionId, this.nowFn());
1563
+ if (hold === "running") {
1564
+ this.emit("adapter.ask.held", { by: "meeting" });
1565
+ return null;
1566
+ }
1567
+ if (hold === "finished") {
1568
+ try {
1569
+ coverFinish(this.counterpart.store);
1570
+ } catch {
1571
+ /* uncovered, the next Stop is paced the same way once more */
1572
+ }
1573
+ this.paceAsk(input, { coveredBy: "meeting" });
1574
+ return null;
1575
+ }
1592
1576
  const chapter = this.paceAsk(input);
1593
1577
  // The ask NAMES this session and its chapter: the id is what the MCP
1594
1578
  // server binds itself with, so an ask that omitted it would be an
@@ -143,9 +143,6 @@ export type {
143
143
  WakeArrival,
144
144
  } from "./transcript.js";
145
145
 
146
- export { AB_DIR_ENV, V2_OVERRIDE, abDir, assignmentHealth, assignmentPath, primacy, readAssignment } from "./primacy.js";
147
- export type { Assignment, AssignmentHealth, AssignmentState, Primacy, PrimacyReason } from "./primacy.js";
148
-
149
146
  import { Counterpart } from "../../core/counterpart.js";
150
147
  import type { CounterpartEvent } from "../../core/counterpart.js";
151
148
  import type { AdapterConfig } from "../config.js";
@@ -1239,6 +1239,14 @@ is treated as no evidence rather than as evidence of absence.
1239
1239
  the owner's plan line ("`--budget` gets a default of 9000") and it is a working default,
1240
1240
  not a new rule — if it fights §2.18 later, the interactive arm is the one place to take
1241
1241
  it back out.
1242
+ **2026-10-12: every Claude Code arm writes it now.** The 0.3.20 release check found the
1243
+ cost of the scripted arm's silence: the plugin's first run is `install --no-connect` with
1244
+ no terminal, so every plugin install got a configuration with no key, and a store that
1245
+ never composed a wake (`briefing.no-budget`): each session woke on the bootstrap line,
1246
+ day after day. `installCommand` now writes 9,000 into any configuration it creates for
1247
+ Claude Code; `installDesktop` alone writes none. A file already written without the key
1248
+ wakes under the same number at load (`config.ts#withBudgetDefault`), and `rebrief` uses
1249
+ it for a config found without the key. The core still has no default.
1242
1250
 
1243
1251
  ### The merge with C and D, and what a real pty found (2026-09-21)
1244
1252