counterparts 0.3.49 → 0.3.52

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 (95) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +18 -10
  3. package/docs/QUICKSTART.md +46 -12
  4. package/docs/manual.md +2 -1
  5. package/docs/module-map.md +3 -0
  6. package/package.json +3 -2
  7. package/src/adapters/claude-code/NOTES.md +43 -0
  8. package/src/adapters/claude-code/child.ts +23 -2
  9. package/src/adapters/claude-code/doctor-growth.ts +269 -0
  10. package/src/adapters/claude-code/doctor-host.ts +19 -1
  11. package/src/adapters/claude-code/doctor-recall-steps.ts +84 -0
  12. package/src/adapters/claude-code/doctor.ts +26 -3
  13. package/src/adapters/claude-code/hooks.ts +7 -1
  14. package/src/adapters/cli/INTERFACE-GAPS.md +18 -0
  15. package/src/adapters/cli/NOTES.md +24 -0
  16. package/src/adapters/cli/commands-dashboard.ts +9 -1
  17. package/src/adapters/cli/commands-project.ts +2 -1
  18. package/src/adapters/cli/commands-readings.ts +19 -8
  19. package/src/adapters/cli/commands-verify.ts +1 -1
  20. package/src/adapters/cli/commands.ts +4 -2
  21. package/src/adapters/cli/export.ts +2 -1
  22. package/src/adapters/cli/install.ts +14 -6
  23. package/src/adapters/cli/mechanisms.ts +1 -1
  24. package/src/adapters/cli/wire.ts +22 -6
  25. package/src/adapters/dashboard/activity.ts +6 -3
  26. package/src/adapters/dashboard/registries.ts +11 -0
  27. package/src/adapters/dashboard/web/flow.ts +3 -0
  28. package/src/adapters/dashboard/web/lanes.ts +4 -0
  29. package/src/adapters/dashboard/web/narrate.ts +23 -0
  30. package/src/adapters/dashboard/web/views/activity.ts +4 -2
  31. package/src/adapters/dashboard/web/views/flow-view.ts +6 -0
  32. package/src/adapters/dashboard/web/views/memory.ts +13 -0
  33. package/src/adapters/dashboard/web/views/shared.ts +2 -1
  34. package/src/adapters/fired.ts +113 -11
  35. package/src/adapters/host-wiring.ts +3 -1
  36. package/src/adapters/lifecycle.ts +36 -9
  37. package/src/adapters/mcp/CONTRACT.md +22 -1
  38. package/src/adapters/mcp/server-args.ts +51 -0
  39. package/src/adapters/mcp/server-session-end.ts +8 -2
  40. package/src/adapters/mcp/server-words.ts +14 -1
  41. package/src/adapters/mcp/server.ts +117 -7
  42. package/src/adapters/mcp/tools.ts +4 -3
  43. package/src/adapters/plugin.ts +1 -0
  44. package/src/adapters/presence.ts +74 -0
  45. package/src/adapters/runtime.ts +258 -8
  46. package/src/adapters/scopes.ts +3 -2
  47. package/src/adapters/spawn.ts +3 -0
  48. package/src/adapters/update-check.ts +1 -1
  49. package/src/adapters/windows-shims.mjs +102 -0
  50. package/src/core/close-hint.ts +297 -0
  51. package/src/core/counterpart-boundary.ts +15 -0
  52. package/src/core/counterpart-deposit.ts +24 -3
  53. package/src/core/counterpart-events.ts +14 -0
  54. package/src/core/counterpart-types.ts +6 -0
  55. package/src/core/counterpart-wake-shape.ts +88 -19
  56. package/src/core/counterpart.ts +143 -7
  57. package/src/core/dream/index.ts +1 -1
  58. package/src/core/dream/reflect.ts +54 -34
  59. package/src/core/encode/NOTES.md +55 -0
  60. package/src/core/encode/secrets.ts +477 -3
  61. package/src/core/event-rollup.ts +175 -0
  62. package/src/core/handoff/CONTRACT.md +7 -0
  63. package/src/core/interference.ts +496 -0
  64. package/src/core/open-close.ts +583 -0
  65. package/src/core/prospective/CONTRACT.md +24 -0
  66. package/src/core/prospective/derive.ts +22 -1
  67. package/src/core/prospective/index.ts +115 -1
  68. package/src/core/recall/CONTRACT.md +9 -2
  69. package/src/core/recall/NOTES.md +99 -0
  70. package/src/core/recall/activate.ts +83 -6
  71. package/src/core/recall/index.ts +75 -5
  72. package/src/core/recall/probe.ts +134 -0
  73. package/src/core/recall/steps.ts +84 -0
  74. package/src/core/recall/tunables.ts +11 -0
  75. package/src/core/reconsolidation.ts +14 -4
  76. package/src/core/remember/CONTRACT.md +2 -1
  77. package/src/core/remember/NOTES.md +15 -0
  78. package/src/core/remember/spans.ts +44 -6
  79. package/src/core/self/NOTES.md +21 -0
  80. package/src/core/self/work.ts +9 -5
  81. package/src/core/sleep/CONTRACT.md +36 -2
  82. package/src/core/sleep/NOTES.md +35 -0
  83. package/src/core/sleep/close.ts +77 -0
  84. package/src/core/sleep/cycle.ts +44 -0
  85. package/src/core/sleep/index.ts +4 -0
  86. package/src/core/sleep/interfere.ts +73 -0
  87. package/src/core/sleep/log.ts +27 -2
  88. package/src/core/sleep/tunables.ts +19 -0
  89. package/src/core/sleep/types.ts +20 -0
  90. package/src/core/store/index.ts +157 -10
  91. package/src/core/store/operational.ts +22 -0
  92. package/src/core/store/owner-op-seam.ts +16 -0
  93. package/src/core/store/reads-history.ts +173 -7
  94. package/src/core/store/reads-memories.ts +253 -4
  95. package/src/core/store/shapes.ts +8 -0
@@ -55,6 +55,8 @@
55
55
  * No body text, no question text, no note text ever reaches an event.
56
56
  */
57
57
  import { MCP_OVERSIZE_EVENT, MCP_PART_EVENT, MCP_RECALL_EVENT, boundedIds } from "../../core/counterpart.js";
58
+ import { closeHints, mayCloseSubject, noteCloseHintsShown } from "../../core/close-hint.js";
59
+ import type { OpenItemHead } from "../../core/close-hint.js";
58
60
  import { CONTRADICTION_TUNABLES, HELD_HINT, NEIGHBOURS_HINT, SLOT_HINT, contentWords } from "../../core/reconsolidation.js";
59
61
  import type { Neighbour } from "../../core/reconsolidation.js";
60
62
  import { localDate, todayIn } from "../../core/time.js";
@@ -129,7 +131,9 @@ import type { AdapterConfig } from "../config.js";
129
131
  import { Lifecycle, plainContextLine } from "../lifecycle.js";
130
132
  import type { SessionInput } from "../lifecycle.js";
131
133
  import { ONE_TAG_LINE, tagLead } from "../store-id.js";
132
- import { NOTHING_CLOSED } from "../../core/dream/slices.js";
134
+ import { NOTHING_CLOSED, memoryClosedTo } from "../../core/dream/slices.js";
135
+ import { projectFolders } from "../../core/self/work.js";
136
+ import { mayBeDoneOf } from "../../core/open-close.js";
133
137
  import { NIGHT_CHILD_ENV, NIGHT_RUN_ENV, WORKER_RUNNER_PATH } from "../spawn.js";
134
138
  import type { Spawner } from "../spawn.js";
135
139
  import {
@@ -273,6 +277,8 @@ import {
273
277
  memoryHomeWords,
274
278
  RECALL_MODE_WORDS,
275
279
  STILL_DATED_HINT,
280
+ MAY_CLOSE_HINT,
281
+ mayCloseAskedNote,
276
282
  ANSWERS_HINT,
277
283
  STILL_DATED_SHOWN,
278
284
  TITLE_ASKED_NOTE,
@@ -297,6 +303,7 @@ import {
297
303
  readAbout,
298
304
  readTraits,
299
305
  readWriteFacts,
306
+ doneDateAsOccurred,
300
307
  readTags,
301
308
  reminderEcho,
302
309
  ownPlumbingEcho,
@@ -1896,8 +1903,15 @@ export class McpServer {
1896
1903
  // THE REMINDER DATE AND HOW IT COMES BACK (2026-09-26) — checked before
1897
1904
  // anything is captured, so an unreadable one is a refusal that says which
1898
1905
  // shapes ARE readable rather than a note that lands without its date.
1899
- const dated = readReminder(args);
1900
- if ("refused" in dated) return this.refuse("remember", dated.refused, { detail: dated.detail });
1906
+ const datedRead = readReminder(args);
1907
+ if ("refused" in datedRead) return this.refuse("remember", datedRead.refused, { detail: datedRead.detail });
1908
+ // v12: when it happened, who said it, what kind — never a refusal: what
1909
+ // cannot be read is dropped and said beside the memory that landed. Read
1910
+ // here, beside the date, since a done with a passed date keeps it as
1911
+ // occurredOn instead (SO1 step 2).
1912
+ const doneAt = doneDateAsOccurred(args, datedRead, readWriteFacts(args, this.today()), this.today());
1913
+ const dated = doneAt.dated;
1914
+ const facts = doneAt.facts;
1901
1915
  // Unbound, the note is filed under the session this server's host is
1902
1916
  // running here, found by its process (2026-10-01, `hostSession`), and
1903
1917
  // under nobody only when that is not exact.
@@ -1937,9 +1951,6 @@ export class McpServer {
1937
1951
  if ("refused" in about) return this.refuse("remember", "about-malformed", { detail: about.refused });
1938
1952
  const traits = readTraits(args["traits"]);
1939
1953
  if ("refused" in traits) return this.refuse("remember", "traits-malformed", { detail: traits.refused });
1940
- // v12: when it happened, who said it, what kind — never a refusal: what
1941
- // cannot be read is dropped and said beside the memory that landed.
1942
- const facts = readWriteFacts(args, this.today());
1943
1954
  // v14, lane B: its tags, loose first the same way.
1944
1955
  const tags = readTags(args);
1945
1956
  let deposit: DepositResult;
@@ -1991,6 +2002,7 @@ export class McpServer {
1991
2002
  ...(neighbours.length === 0 ? {} : { neighbours, neighboursHint: NEIGHBOURS_HINT }),
1992
2003
  ...this.slotOf(deposit),
1993
2004
  ...this.stillDatedNear(deposit, dated, facts.sent.status, [], session),
2005
+ ...this.mayCloseOf(deposit, { title: args["title"], text, status: facts.sent.status }, []),
1994
2006
  ...this.answersReminder(deposit, facts.sent, neighbours),
1995
2007
  ...(settle === null ? {} : { settle }),
1996
2008
  ...(feltNow === null ? {} : { feelingsNow: feltNow }),
@@ -2479,6 +2491,71 @@ export class McpServer {
2479
2491
  return { stillDated: out, stillDatedHint: STILL_DATED_HINT };
2480
2492
  }
2481
2493
 
2494
+ /**
2495
+ * OPEN ITEMS THIS WRITE LOOKS LIKE IT SETTLES (2026-11-07, SO1 step 1b,
2496
+ * `core/close-hint.ts`): from any folder, by the same version series, the
2497
+ * same pull request, or what the item's `settlesWhen` names — at most three,
2498
+ * nearest first, each with its folder, and `MAY_CLOSE_HINT`. The writing
2499
+ * model decides; nothing is closed here. One asked of the owner carries a
2500
+ * note that only their answer closes it. Each entry that listed any is
2501
+ * counted (`noteCloseHintsShown`, with what the read cost). Empty when none.
2502
+ */
2503
+ private mayCloseOf(deposit: DepositResult, sent: { readonly title: unknown; readonly text: unknown; readonly status: unknown }, siblings: readonly string[]): Record<string, unknown> {
2504
+ if (!deposit.deposited || deposit.memoryId === null) return {};
2505
+ const started = performance.now();
2506
+ // Nearly every write names nothing done: no store read at all for it.
2507
+ if (!mayCloseSubject(sent.title, sent.text)) return {};
2508
+ const sentStatus = sent.status;
2509
+ const row = this.counterpart.store.row(deposit.memoryId);
2510
+ if (row === undefined) return {};
2511
+ const exclude = [
2512
+ deposit.mint?.updates,
2513
+ deposit.revision?.targetId,
2514
+ deposit.reminder?.from,
2515
+ ...(deposit.reminder?.alsoClosed ?? []),
2516
+ deposit.thread?.from,
2517
+ ...siblings,
2518
+ ].filter((x): x is string => typeof x === "string");
2519
+ const t = this.counterpart.self.tunables;
2520
+ const on = this.folderOn();
2521
+ const store = this.counterpart.store;
2522
+ const here = (this.scope ?? "").trim();
2523
+ const projects = new Set(here === "" ? [] : projectFolders(store, here, t.PROJECTS_TRAVEL, on));
2524
+ const hints = closeHints(
2525
+ this.counterpart.store,
2526
+ {
2527
+ id: deposit.memoryId,
2528
+ title: row.title,
2529
+ body: row.body,
2530
+ about: row.about ?? null,
2531
+ status: typeof sentStatus === "string" ? sentStatus : (row.status ?? null),
2532
+ },
2533
+ {
2534
+ day: store.livedDay(),
2535
+ carryDays: t.OPEN_CARRY_DAYS,
2536
+ glimpses: t.OPEN_CARRY_GLIMPSE_TOUCH,
2537
+ exclude,
2538
+ projectFolders: projects,
2539
+ // The folder setting (review of #783): an item in a folder that is off,
2540
+ // paused or observer never has its title pushed into another's result.
2541
+ ...(on === undefined ? {} : { closed: (r: OpenItemHead) => memoryClosedTo(store, r, on, this.scope ?? undefined) }),
2542
+ },
2543
+ );
2544
+ if (hints.length === 0) return {};
2545
+ const ms = performance.now() - started;
2546
+ if (!this.counterpart.observer) this.telemetry(() => void noteCloseHintsShown(this.counterpart.store, deposit.memoryId as string, hints, ms));
2547
+ this.markSeen(hints.map((h) => h.id));
2548
+ const asked = hints.some((h) => h.asked === true) ? mayCloseAskedNote(this.counterpart.ownerDisplayName()) : null;
2549
+ const mayClose = hints.map((h) => ({
2550
+ id: h.id,
2551
+ title: h.title,
2552
+ ...(h.folder === undefined ? {} : { folder: h.folder }),
2553
+ ...(h.settlesWhen === undefined ? {} : { settlesWhen: h.settlesWhen }),
2554
+ ...(h.asked === true && asked !== null ? { note: asked } : {}),
2555
+ }));
2556
+ return { mayClose, mayCloseHint: MAY_CLOSE_HINT };
2557
+ }
2558
+
2482
2559
  /**
2483
2560
  * THE SLOT THE DETECTOR PROPOSED for a write (2026-10-11, Group 2): the
2484
2561
  * older memory, by id and title, and the ask — settle it now or let the
@@ -2673,6 +2750,9 @@ export class McpServer {
2673
2750
  // registry scan. Unbound, it is the very session the old
2674
2751
  // `this.session ?? this.hostSession()` found, so the recall is unchanged.
2675
2752
  const key = this.seenKey();
2753
+ // HOW LONG THE ANSWER TOOK (FD1 step 5, 2026-11-07): the recall itself,
2754
+ // on the server's clock, onto `mcp.recall` as `elapsedMs`.
2755
+ const startedAt = this.nowFn();
2676
2756
  const result = deliberateRecall(
2677
2757
  this.counterpart,
2678
2758
  {
@@ -2682,6 +2762,7 @@ export class McpServer {
2682
2762
  },
2683
2763
  { sessionId: this.session ?? key, closed: this.nightClosed() },
2684
2764
  );
2765
+ const elapsedMs = Math.max(0, this.nowFn() - startedAt);
2685
2766
  if (manual !== null && result.reason === "handle-unknown") return this.manualTool(manual);
2686
2767
  const resolved = this.noteHandleResolution(handle, result);
2687
2768
  // THE MEASUREMENT (2026-09-28): did this lookup fetch what a mechanism's
@@ -2710,6 +2791,7 @@ export class McpServer {
2710
2791
  chars: payload["chars"] as number,
2711
2792
  truncated: payload["truncated"] === true,
2712
2793
  droppedForBudget: 0,
2794
+ elapsedMs,
2713
2795
  });
2714
2796
  // Only what was DELIVERED (review of #316): an id left `waiting` was not shown.
2715
2797
  const deliveredIds = ((payload["memories"] as { id?: unknown }[] | undefined) ?? []).map((m) => m.id).filter((x): x is string => typeof x === "string");
@@ -2723,6 +2805,7 @@ export class McpServer {
2723
2805
  expanded: result.path === "handle" ? result.memories.length : 0,
2724
2806
  blockedBy: addressBlocked(result),
2725
2807
  ...(Array.isArray(payload["nights"]) && payload["nights"].length > 0 ? { nights: payload["nights"].length } : {}),
2808
+ elapsedMs,
2726
2809
  },
2727
2810
  askedIds.length,
2728
2811
  question,
@@ -3029,6 +3112,11 @@ export class McpServer {
3029
3112
  const shown = items.slice((at - 1) * STILL_OPEN_PAGE, at * STILL_OPEN_PAGE);
3030
3113
  this.emit("mcp.recall.stillopen", undefined, { total: items.length, page: at, shown: shown.length, parked, routed });
3031
3114
  const touched = (n: number): string => (n === 0 ? "this lived day" : n === 1 ? "1 lived day ago" : `${String(n)} lived days ago`);
3115
+ // MAY BE DONE (2026-11-07, SO1 step 1): what the night saw but would not
3116
+ // close, and what the reflection thought looks done but wasn't sure of —
3117
+ // listed beside the item, never asked (`open-close.ts#mayBeDoneOf`).
3118
+ const maybe = mayBeDoneOf(this.counterpart.store);
3119
+ const maybeShown = shown.filter((i) => maybe.has(i.id)).length;
3032
3120
  // THE PARKED, LISTED AND MARKED (P2, 2026-10-28): after every carried
3033
3121
  // item, the open threads nobody touched in `OPEN_CARRY_DAYS` lived days —
3034
3122
  // in no lane of the wake, not closed. Said once here, `parked: true` on each.
@@ -3055,6 +3143,10 @@ export class McpServer {
3055
3143
  ...(i.date === undefined ? {} : { date: i.date }),
3056
3144
  ...(i.settlesWhen === undefined ? {} : { settlesWhen: i.settlesWhen }),
3057
3145
  ...(i.parked === true ? { parked: true } : {}),
3146
+ ...((): Record<string, unknown> => {
3147
+ const m = maybe.get(i.id);
3148
+ return m === undefined ? {} : { mayBeDone: m.shows === undefined ? m.why : `${m.why} (${m.shows})` };
3149
+ })(),
3058
3150
  })),
3059
3151
  // "COMING UP", BY TITLE (WK1, 2026-10-30): the wake lists what is due
3060
3152
  // today and the oldest overdue and counts the rest, naming this
@@ -3075,6 +3167,9 @@ export class McpServer {
3075
3167
  ? "Nothing is still open."
3076
3168
  : `${carried === 0 ? `Nothing open is carried in the wake's "Still open" now.` : `What "Still open" carries, in the wake's order: what is live first, newest touched first.`}${at < pages ? ` More on page ${String(at + 1)} (page: ${String(at + 1)}).` : ""} Recall an id to read it whole. A lived day is a day the memory was in use.`) +
3077
3169
  parkedNote +
3170
+ (maybeShown === 0
3171
+ ? ""
3172
+ : ` ${maybeShown === 1 ? "One is" : `${String(maybeShown)} are`} marked mayBeDone: the night thought it may be done but wasn't sure enough to close it, and the memory in brackets is why. If it is done, close it (a write that updates it with unresolved: false); nobody is asked. A question to the owner (status asked) closes only on the owner's answer, never on this mark.`) +
3078
3173
  (comingUp.length === 0 || at !== 1
3079
3174
  ? ""
3080
3175
  : ` comingUp: what the wake's "Coming up" lists or counts, the overdue first (overdue: true; the longest past its date first), then by date.`),
@@ -3112,6 +3207,12 @@ export class McpServer {
3112
3207
  let ids: readonly string[];
3113
3208
  let body: Record<string, unknown>;
3114
3209
  let row: RecallRowFields;
3210
+ // HOW LONG THE MODE TOOK (FD1 step 5, 2026-11-07): the mode's own answer,
3211
+ // embedding left out (its round-trip is the embedder's, not the journal's),
3212
+ // so meaning mode's linear cost in episodes can be watched. On `mcp.recall`
3213
+ // as `elapsedMs`; candidate-first selection waits for ~1,000 chapters or a
3214
+ // 200 ms ask (the FD1 step 5 read).
3215
+ const startedAt = this.nowFn();
3115
3216
  if (mode === "facts") {
3116
3217
  const r = factsRecall(ctx, question, { page });
3117
3218
  answer = renderFacts(r);
@@ -3163,6 +3264,7 @@ export class McpServer {
3163
3264
  counts: { ...r.counts },
3164
3265
  };
3165
3266
  }
3267
+ row = { ...row, elapsedMs: Math.max(0, this.nowFn() - startedAt) };
3166
3268
  const payload: Record<string, unknown> = {
3167
3269
  path: "question",
3168
3270
  mode,
@@ -3224,6 +3326,7 @@ export class McpServer {
3224
3326
  chars: shippedChars,
3225
3327
  truncated: false,
3226
3328
  droppedForBudget: 0,
3329
+ elapsedMs: row.elapsedMs ?? 0,
3227
3330
  });
3228
3331
  // On the durable row (review of #663, to calibrate the bar on live use):
3229
3332
  // each dream that came, why, and its meaning score.
@@ -3427,6 +3530,9 @@ export class McpServer {
3427
3530
  ...(row.page === undefined ? {} : { page: row.page }),
3428
3531
  ...(row.time === undefined ? {} : { time: row.time }),
3429
3532
  ...(row.counts === undefined ? {} : { counts: row.counts }),
3533
+ // How long the recall took, ms (FD1 step 5): the mode's answer for a
3534
+ // question, the address read for an id or handle.
3535
+ ...(row.elapsedMs === undefined ? {} : { elapsedMs: row.elapsedMs }),
3430
3536
  considered: row.considered,
3431
3537
  storeSize: row.storeSize,
3432
3538
  chars: payload["chars"] ?? 0,
@@ -3676,7 +3782,11 @@ export class McpServer {
3676
3782
  // The first meeting's marker rides in the wake's head tag (2026-10-20,
3677
3783
  // ONE TAG), as a Claude Code session start carries it.
3678
3784
  const woke = lc.composeWake(input, this.lifecycleOpts.config?.injectionBudgetBytes, () => [lc.onboardingMarker(input)]);
3679
- const plain = lc.plainFor(input);
3785
+ // A wake tool call can be a routine's or a hosted run's with nobody there: an
3786
+ // unsaid folder's reminder crosses (SO1 step 3) only when the host says a person
3787
+ // is (`CLAUDE_CODE_SESSION_ATTENDED`, what the session start's `interactive` reads).
3788
+ const attended = ["1", "true"].includes((this.env["CLAUDE_CODE_SESSION_ATTENDED"] ?? "").trim().toLowerCase());
3789
+ const plain = lc.plainFor(input, { cross: attended && !night });
3680
3790
  const told = lc.claimPlain(input, plain.due);
3681
3791
  const spawn = lc.spawnWorker(input);
3682
3792
  // NO CORE DREAM LINE ON CLAUDE.AI (2026-10-26, OL1b): the ask relayed in a
@@ -232,7 +232,8 @@ function annotate(title: string, hints: { readOnly: boolean; destructive?: boole
232
232
  * object per feeling, spelled on the feelings wheel (`core/feelings-wheel.ts`).
233
233
  * Since emotion part A (2026-09-26) they weigh: the strongest one, or
234
234
  * `emotional` if that is stronger, raises the memory and slows its fading
235
- * (physics §5.10), and a recent one sets the mood recall matches (recall G18).
235
+ * (physics §5.10), and a recent one sets the mood recall matches (recall G18;
236
+ * off since 2026-10-10, both mood weights 0).
236
237
  * Since the wheel v2 (2026-09-30, v11): seven cores, the writer's core is kept
237
238
  * whatever the word, and `strength` and `valence` default from the word.
238
239
  */
@@ -355,7 +356,7 @@ export const CARRIED_BY_TEXT =
355
356
  const FEELINGS_PROPERTY = {
356
357
  type: "array",
357
358
  description:
358
- "Optional: the feelings in this moment, one object each — mixed feelings are several, and yours and the owner's go side by side. The strongest feeling on a memory holds it higher and slows its fading; memories that felt the way someone feels now come to mind more easily.",
359
+ "Optional: the feelings in this moment, one object each — mixed feelings are several, and yours and the owner's go side by side. The strongest feeling on a memory holds it higher and slows its fading.",
359
360
  items: {
360
361
  type: "object",
361
362
  properties: {
@@ -1863,7 +1864,7 @@ const REFLECT: ToolSpec = {
1863
1864
  close: {
1864
1865
  type: "array",
1865
1866
  items: { type: "string" },
1866
- description: "`finish`, optional: ids from the bundle's staleOpen or settlesOpen that look done but you are not sure of — asked in the share, closed only on a yes. `close`: the proposed ids the owner agreed are done.",
1867
+ description: "`finish`, optional: ids from the bundle's staleOpen or settlesOpen that look done but you are not sure of — nothing closes and nobody is asked: they are listed as \"may be done\" under recall \"still open\". `close`: proposed ids the owner says are done.",
1867
1868
  },
1868
1869
  closeNow: {
1869
1870
  type: "array",
@@ -673,6 +673,7 @@ export function ensureFirstRun(input: FirstRunInput): FirstRun {
673
673
  env: env as NodeJS.ProcessEnv,
674
674
  encoding: "utf8",
675
675
  timeout: FIRST_RUN_TIMEOUT_MS,
676
+ windowsHide: true,
676
677
  stdio: ["ignore", "pipe", "pipe"],
677
678
  }),
678
679
  );
@@ -0,0 +1,74 @@
1
+ /**
2
+ * WHEN A PERSON WAS THERE, AND IN WHICH FOLDER (SO1 step 3, round 3 of #780; the
3
+ * roadmap's ruling: one lived-day source). Read from the log's presence rows, the
4
+ * session-start's `adapter.wake.injected`: durable, written by the wake, with its
5
+ * `interactive` flag and the person's calendar `date`, in the store's own clock.
6
+ * Not the session registry, which prunes a record a week after it ends and so
7
+ * could cross a reminder a day late, or show doctor a false amber.
8
+ *
9
+ * Both readers use it: the crossing's lived days (`Lifecycle#plainFor`) and
10
+ * doctor's "should it have crossed" and "was its folder there" (`fired.ts`). One
11
+ * read by event name, bounded by the lived-day clock (a lived day is never longer
12
+ * than a calendar day, so `days` lived days back covers at least `days` calendar
13
+ * days). Reads only; never throws: a log that won't read is no days at all.
14
+ */
15
+ import { WAKE_INJECTED_EVENT } from "../core/counterpart-events.js";
16
+ import type { ReadOnlyStore } from "../core/store/index.js";
17
+ import { addDays, localDate } from "../core/time.js";
18
+
19
+ /** The most rows one read takes: a busy month of session starts is a few hundred. */
20
+ const PRESENCE_ROWS = 5_000;
21
+
22
+ export interface Presence {
23
+ /** Calendar days a person's session started, ascending. */
24
+ readonly lived: ReadonlySet<string>;
25
+ /** Per day, the folders those sessions were in (`projectFolder`-normalized as written), "" when the row named none. */
26
+ readonly folders: ReadonlyMap<string, ReadonlySet<string>>;
27
+ /** Each session's folder, as its wake row named it (absent: the row predates the field). */
28
+ readonly sessionFolder: ReadonlyMap<string, string>;
29
+ /** Sessions a wake row said nobody attends (for good, as doctor has always read them). */
30
+ readonly unattended: ReadonlySet<string>;
31
+ }
32
+
33
+ export function readPresence(store: Pick<ReadOnlyStore, "eventLog" | "livedDay" | "zone">, from: string, to: string): Presence {
34
+ const lived = new Set<string>();
35
+ const folders = new Map<string, Set<string>>();
36
+ const sessionFolder = new Map<string, string>();
37
+ const unattended = new Set<string>();
38
+ try {
39
+ const span = Math.max(1, Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000) + 2);
40
+ const rows = store.eventLog({ name: WAKE_INJECTED_EVENT, sinceDay: Math.max(0, store.livedDay() - span), limit: PRESENCE_ROWS });
41
+ const zone = store.zone();
42
+ const seen: { date: string; session: string | null; folder: string }[] = [];
43
+ for (const row of rows) {
44
+ let p: Record<string, unknown> = {};
45
+ try {
46
+ p = JSON.parse(row.payload ?? "{}") as Record<string, unknown>;
47
+ } catch {
48
+ continue;
49
+ }
50
+ const date = typeof p["date"] === "string" && p["date"].length === 10 ? p["date"] : localDate(row.at, zone);
51
+ const session = typeof p["session"] === "string" && p["session"].length > 0 ? p["session"] : null;
52
+ const folder = typeof p["folder"] === "string" ? p["folder"] : "";
53
+ if (session !== null && p["interactive"] === false) unattended.add(session);
54
+ if (session !== null && folder.length > 0) sessionFolder.set(session, folder);
55
+ if (p["interactive"] === false || date < from || date > to) continue;
56
+ seen.push({ date, session, folder });
57
+ }
58
+ for (const r of seen) {
59
+ if (r.session !== null && unattended.has(r.session)) continue;
60
+ lived.add(r.date);
61
+ let set = folders.get(r.date);
62
+ if (set === undefined) folders.set(r.date, (set = new Set()));
63
+ set.add(r.folder);
64
+ }
65
+ } catch {
66
+ /* no days */
67
+ }
68
+ return { lived, folders, sessionFolder, unattended };
69
+ }
70
+
71
+ /** The window the crossing reads: its lookback and a day either side. */
72
+ export function crossingWindow(at: string, lookbackDays: number): { from: string; to: string } {
73
+ return { from: addDays(at, -(lookbackDays + 1)), to: at };
74
+ }