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
@@ -0,0 +1,297 @@
1
+ /**
2
+ * OPEN ITEMS A WRITE LOOKS LIKE IT SETTLES (2026-11-07, SO1 step 1b; decided by
3
+ * the roadmap seat with Mike, lightly held). The night can't close most open
4
+ * items: the proof lives in the session that did the work, and that session
5
+ * never knew the item existed (10-30: sessions only close their own items; of
6
+ * 32 items closed by hand on 11-07, the night's rule closed 0). So when a
7
+ * `remember` or a `session_end` entry is stored, its result lists the open
8
+ * items, from ANY folder, whose subject the entry names — and the writing
9
+ * model, which knows what it just did, decides. Nothing is closed here; there
10
+ * is no precision bar, only a short list.
11
+ *
12
+ * **What matches** (the entry read by its HEADLINE, `interference.ts#headline`):
13
+ * - `version`: the same version series, the entry saying a version at or
14
+ * past the item's was DONE (`subjectKeys` / `sameSubject`: "0.3.47
15
+ * published" over "0.3.46 ready to publish");
16
+ * - `settles-when`: the item's `settlesWhen` names a version the entry's
17
+ * done version reaches (the same one included: "0.3.46 published" settles
18
+ * "settles when 0.3.46 published"), or a pull request the entry says was
19
+ * merged — read with every version in it, since it is a trigger stated
20
+ * on purpose;
21
+ * - `pr`: the entry says `#N merged` (a done verb beside the number,
22
+ * `prKeys`), and the item's headline names `#N` — an item in the
23
+ * writer's own project only, since a PR number belongs to one repository.
24
+ *
25
+ * **What is listed:** open items only — flagged `unresolved`, not parked
26
+ * (`self/identity.ts#carriesOpen`), not settled over (`recall/standing.ts#headOf`),
27
+ * never the entry itself or what it updates — at most `SHOWN`, nearest first
28
+ * (fewest patches on, then the newest item). Never a check or a follow-up
29
+ * (`CHECK_ITEM`), a protected row (its close would be refused), nor one whose
30
+ * folder the folder setting has off, paused or observer. Nothing for an entry about the
31
+ * owner, us or me, nor for a plan (`planned`, `proposed`, `asked`): neither is
32
+ * evidence something got done. An item `asked` is listed with a note that only
33
+ * the owner's answer closes it.
34
+ *
35
+ * **The cost:** one read of every open item's head (`Store#openItemHeads`,
36
+ * the `memories_open` index's clause), pure matching, then a parked read and a
37
+ * settled-over walk for the few that matched.
38
+ *
39
+ * **Counted** (no DDL: two event names): each entry that listed any writes
40
+ * `CLOSE_HINT_SHOWN_EVENT` (ref the entry, payload the ids and the ms); a
41
+ * later close of one of those ids through `updates` + `unresolved: false`
42
+ * within `CLOSE_WINDOW_DAYS` lived days writes `CLOSE_HINT_CLOSED_EVENT` (ref
43
+ * the item) — so a CHECK-AFTER read is two `eventCounts` rows: hints shown
44
+ * against closes made.
45
+ */
46
+ import { headline, prKeys, sameSubject, subjectKeys } from "./interference.js";
47
+ import type { SubjectKeys } from "./interference.js";
48
+ import { headOf } from "./recall/standing.js";
49
+ import { carriesOpen } from "./self/identity.js";
50
+ import { projectFolder } from "./self/work.js";
51
+ import type { Store } from "./store/index.js";
52
+ import { SETTLES_WHEN_META_KEY } from "./types.js";
53
+ import { INTERFERENCE_TUNABLES } from "./interference.js";
54
+
55
+ /** Working defaults, held lightly (2026-11-07). Read at use. */
56
+ export const CLOSE_HINT_TUNABLES = {
57
+ /** The switch. Off: no list, nothing counted. */
58
+ ON: true as boolean,
59
+ /** At most this many items listed beside one entry. */
60
+ SHOWN: 3 as number,
61
+ /** A close counts as following a hint when it lands within this many lived days of it. CAL. */
62
+ CLOSE_WINDOW_DAYS: 7 as number,
63
+ };
64
+
65
+ /** Each entry that listed any (ref: the entry). */
66
+ export const CLOSE_HINT_SHOWN_EVENT = "open.close-hint.shown";
67
+ /** A close of an item a hint listed, within the window (ref: the item). */
68
+ export const CLOSE_HINT_CLOSED_EVENT = "open.close-hint.closed";
69
+
70
+ /** Entries about these are never read as settling a work item. */
71
+ const PERSONAL = new Set(["owner", "us", "me"]);
72
+ /** A plan says nothing got done. */
73
+ const PLANS = new Set(["planned", "proposed", "asked"]);
74
+
75
+ export type CloseHintRule = "version" | "settles-when" | "pr";
76
+
77
+ export interface CloseHint {
78
+ readonly id: string;
79
+ readonly title: string;
80
+ /** The folder that wrote it; absent when none was recorded. */
81
+ readonly folder?: string;
82
+ readonly settlesWhen?: string;
83
+ /** True for an item `asked`: the caller says only the owner's answer closes it. */
84
+ readonly asked?: true;
85
+ readonly rule: CloseHintRule;
86
+ /** What matched: `0.3.46→0.3.47`, `#760`. */
87
+ readonly key: string;
88
+ }
89
+
90
+ export interface CloseHintEntry {
91
+ readonly id: string;
92
+ readonly title: string | null;
93
+ readonly body: string;
94
+ /** Its `about` mark, as stored; null when unmarked. */
95
+ readonly about: string | null;
96
+ /** Its `status`, as sent or stored; null when none. */
97
+ readonly status: string | null;
98
+ }
99
+
100
+ export interface CloseHintOptions {
101
+ /** The lived day (`Store#livedDay`). */
102
+ readonly day: number;
103
+ /** `SelfTunables.OPEN_CARRY_DAYS` and `OPEN_CARRY_GLIMPSE_TOUCH`: the parking rule. */
104
+ readonly carryDays: number;
105
+ readonly glimpses: boolean;
106
+ /** Ids never listed: what the write updates, a dump's siblings, what it closed. */
107
+ readonly exclude?: readonly string[];
108
+ /**
109
+ * The writer's project folders (`self/work.ts#projectFolders`, the join
110
+ * Still open reads): a pull-request number belongs to one repository, so the
111
+ * `pr` rule matches only an item written in one of these. Absent: no `pr`
112
+ * matches (fail closed).
113
+ */
114
+ readonly projectFolders?: ReadonlySet<string>;
115
+ /**
116
+ * The folder setting's fence (`dream/slices.ts#memoryClosedTo`): true for
117
+ * an item whose folder is off, paused or observer, whose title must not
118
+ * reach another folder's result. Absent: none closed.
119
+ */
120
+ readonly closed?: (row: OpenItemHead) => boolean;
121
+ }
122
+
123
+ /** One row of `Store#openItemHeads`. */
124
+ export type OpenItemHead = ReturnType<Store["openItemHeads"]>[number];
125
+
126
+ /**
127
+ * A CHECK OR A FOLLOW-UP, NOT A DEBT A DONE SETTLES (review of #783): a
128
+ * CHECK-AFTER read, a dated check, an experiment's check, a re-read. A merge
129
+ * or a release is when such a read comes due, never its answer.
130
+ */
131
+ const CHECK_ITEM = /CHECK-AFTER|\bcheck due\b|\bcheck ~|\bexperiment check\b|\bre-read\b/i;
132
+
133
+ const TITLE_CHARS = 90;
134
+
135
+ function short(s: string): string {
136
+ const flat = s.replace(/\s+/g, " ").trim();
137
+ return flat.length <= TITLE_CHARS ? flat : `${flat.slice(0, TITLE_CHARS - 1).trimEnd()}…`;
138
+ }
139
+
140
+ /** The version rule for a trigger stated on purpose: the entry's done version at or past the one it names. */
141
+ function reaches(named: SubjectKeys, done: SubjectKeys): { key: string; gap: number } | null {
142
+ let best: { key: string; gap: number } | null = null;
143
+ for (const [series, patch] of named.versions) {
144
+ const theirs = done.versions.get(series);
145
+ if (theirs === undefined || theirs < patch) continue;
146
+ if (best === null || theirs - patch < best.gap) best = { key: `${series}.${patch}→${series}.${theirs}`, gap: theirs - patch };
147
+ }
148
+ return best;
149
+ }
150
+
151
+ /**
152
+ * WHETHER A WRITE COULD LIST ANY, from the words as sent, before any store
153
+ * read: its headline says a version or a pull request was done. False for
154
+ * nearly every write, which then costs nothing. Pure.
155
+ */
156
+ export function mayCloseSubject(title: unknown, text: unknown): boolean {
157
+ if (!CLOSE_HINT_TUNABLES.ON || typeof text !== "string") return false;
158
+ const head = headline({ title: typeof title === "string" ? title : null, body: text });
159
+ return subjectKeys(head, "done").versions.size > 0 || prKeys(head, "done").size > 0;
160
+ }
161
+
162
+ /**
163
+ * The open items `entry` looks like it settles, nearest first, at most
164
+ * `SHOWN`. Empty when nothing matches, the switch is off, or the entry is
165
+ * personal or a plan. Reads only; never throws.
166
+ */
167
+ export function closeHints(store: Store, entry: CloseHintEntry, opts: CloseHintOptions): CloseHint[] {
168
+ if (!CLOSE_HINT_TUNABLES.ON || CLOSE_HINT_TUNABLES.SHOWN <= 0) return [];
169
+ if (entry.about !== null && PERSONAL.has(entry.about)) return [];
170
+ if (entry.status !== null && PLANS.has(entry.status)) return [];
171
+ try {
172
+ const head = headline({ title: entry.title, body: entry.body });
173
+ const done = subjectKeys(head, "done");
174
+ const prs = prKeys(head, "done");
175
+ if (done.versions.size === 0 && prs.size === 0) return [];
176
+ const exclude = new Set<string>([entry.id, ...(opts.exclude ?? [])]);
177
+ const found: { hint: CloseHint; gap: number; createdAt: number }[] = [];
178
+ for (const r of store.openItemHeads(INTERFERENCE_TUNABLES.HEADLINE_CHARS + 1)) {
179
+ if (exclude.has(r.id)) continue;
180
+ let meta: Record<string, unknown>;
181
+ try {
182
+ meta = JSON.parse(r.meta) as Record<string, unknown>;
183
+ } catch {
184
+ continue;
185
+ }
186
+ if (meta["unresolved"] !== true) continue;
187
+ const raw = meta[SETTLES_WHEN_META_KEY];
188
+ const settles = typeof raw === "string" && raw.trim() !== "" ? raw.trim() : null;
189
+ const itemHead = headline({ title: r.title, body: r.body });
190
+ if (CHECK_ITEM.test(itemHead) || (settles !== null && CHECK_ITEM.test(settles))) continue;
191
+ const ownProject = r.scope !== null && opts.projectFolders?.has(projectFolder(r.scope)) === true;
192
+ let match: { rule: CloseHintRule; key: string; gap: number } | null = null;
193
+ const take = (m: { rule: CloseHintRule; key: string; gap: number }): void => {
194
+ if (match === null || m.gap < match.gap) match = m;
195
+ };
196
+ if (done.versions.size > 0) {
197
+ const v = sameSubject(subjectKeys(itemHead, "step"), done);
198
+ if (v !== null) take({ rule: "version", key: v.key, gap: v.gap });
199
+ if (settles !== null) {
200
+ const s = reaches(subjectKeys(settles, "any"), done);
201
+ if (s !== null) take({ rule: "settles-when", key: s.key, gap: s.gap });
202
+ }
203
+ }
204
+ if (prs.size > 0 && ownProject) {
205
+ for (const n of prKeys(itemHead, "any")) if (prs.has(n)) take({ rule: "pr", key: `#${String(n)}`, gap: 0 });
206
+ if (settles !== null) for (const n of prKeys(settles, "any")) if (prs.has(n)) take({ rule: "settles-when", key: `#${String(n)}`, gap: 0 });
207
+ }
208
+ if (match === null) continue;
209
+ if (opts.closed?.(r) === true) continue;
210
+ const m = match as { rule: CloseHintRule; key: string; gap: number };
211
+ const folder = r.scope === null ? "" : projectFolder(r.scope);
212
+ found.push({
213
+ hint: {
214
+ id: r.id,
215
+ title: short(itemHead),
216
+ ...(folder === "" ? {} : { folder }),
217
+ ...(settles === null ? {} : { settlesWhen: settles }),
218
+ ...(r.status === "asked" ? { asked: true as const } : {}),
219
+ rule: m.rule,
220
+ key: m.key,
221
+ },
222
+ gap: m.gap,
223
+ createdAt: r.createdAt,
224
+ });
225
+ }
226
+ if (found.length === 0) return [];
227
+ found.sort((a, b) => a.gap - b.gap || b.createdAt - a.createdAt || (a.hint.id < b.hint.id ? 1 : -1));
228
+ // The parked and the settled over, read one at a time, nearest first, only
229
+ // until the list is full (review of #783: a touch read costs ~0.5 ms a row
230
+ // on a real store). An item asked or naming what settles it is never
231
+ // parked (`carriesOpen`), so it needs no touch read at all.
232
+ const out: CloseHint[] = [];
233
+ for (const f of found) {
234
+ if (out.length >= CLOSE_HINT_TUNABLES.SHOWN) break;
235
+ if (f.hint.asked !== true && f.hint.settlesWhen === undefined) {
236
+ const t = store.openThreadTouches({ glimpses: opts.glimpses, at: store.today(), ids: [f.hint.id] })[0];
237
+ if (t !== undefined && !carriesOpen(t, opts.day, opts.carryDays)) continue;
238
+ }
239
+ if (headOf(store, f.hint.id) !== null) continue;
240
+ out.push(f.hint);
241
+ }
242
+ return out;
243
+ } catch {
244
+ return [];
245
+ }
246
+ }
247
+
248
+ /** One row for an entry that listed any (no row for none). Never throws; false when nothing was written. */
249
+ export function noteCloseHintsShown(store: Store, entryId: string, hints: readonly CloseHint[], ms: number): boolean {
250
+ if (hints.length === 0) return false;
251
+ try {
252
+ return (
253
+ store.appendEvent({
254
+ name: CLOSE_HINT_SHOWN_EVENT,
255
+ day: store.livedDay(),
256
+ ref: entryId,
257
+ payload: { ids: hints.map((h) => h.id), rules: hints.map((h) => h.rule), ms: Math.round(ms * 100) / 100 },
258
+ }) > 0
259
+ );
260
+ } catch {
261
+ return false;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * A CLOSE THAT FOLLOWED A HINT: when `target` was listed by a hint within
267
+ * `CLOSE_WINDOW_DAYS` lived days, one row naming the entry that listed it and
268
+ * how many lived days later. One bounded read of the hint rows (indexed by
269
+ * name, from the window's first day). Never throws.
270
+ */
271
+ export function noteCloseHintTaken(store: Store, target: string, successor: string): boolean {
272
+ if (!CLOSE_HINT_TUNABLES.ON) return false;
273
+ try {
274
+ const day = store.livedDay();
275
+ const rows = store.eventLog({ name: CLOSE_HINT_SHOWN_EVENT, sinceDay: day - CLOSE_HINT_TUNABLES.CLOSE_WINDOW_DAYS, order: "desc", limit: 1000 });
276
+ for (const row of rows) {
277
+ let ids: unknown = null;
278
+ try {
279
+ ids = (JSON.parse(row.payload ?? "{}") as Record<string, unknown>)["ids"];
280
+ } catch {
281
+ continue;
282
+ }
283
+ if (!Array.isArray(ids) || !ids.includes(target)) continue;
284
+ return (
285
+ store.appendEvent({
286
+ name: CLOSE_HINT_CLOSED_EVENT,
287
+ day,
288
+ ref: target,
289
+ payload: { entry: row.ref, successor, shownDay: row.day, daysAfter: day - row.day },
290
+ }) > 0
291
+ );
292
+ }
293
+ return false;
294
+ } catch {
295
+ return false;
296
+ }
297
+ }
@@ -20,6 +20,8 @@ import {
20
20
  import type { WakeTrigger } from "./self/index.js";
21
21
  import { runCycle, cyclePartial } from "./sleep/index.js";
22
22
  import { nightTagWork, TUNABLES as SCHEMAS_TUNABLES } from "./schemas/index.js";
23
+ import { interferenceSweep } from "./interference.js";
24
+ import { openCloseSweep } from "./open-close.js";
23
25
  import type { CycleReport, CyclePartial } from "./sleep/index.js";
24
26
  import { boundedIds, isKnownSession } from "./types.js";
25
27
  import type {
@@ -198,6 +200,12 @@ export async function sessionEnd(cp: Counterpart, input: SessionEndInput = {}):
198
200
  // The night's tag work with no model (wave 2 lane B): card names as
199
201
  // tags, stem merges, dead merges let go — behind `TAGS_NIGHT`.
200
202
  tags: (t) => nightTagWork(cp.store, t),
203
+ // A newer routine work event fades the older one (2026-11-07, FD1 step
204
+ // 3), through the one door, counted apart from the prune.
205
+ interfere: (i) => interferenceSweep(cp.store, i),
206
+ // The night closes an open item a later release shows done (2026-11-07,
207
+ // SO1 step 1), and lists what it won't close as "may be done".
208
+ close: (i) => openCloseSweep(cp.store, i),
201
209
  date,
202
210
  ...(composeBudget === null ? {} : { budgetBytes: composeBudget }),
203
211
  onEvent: (e) => cp["relay"]("sleep", e),
@@ -873,6 +881,13 @@ export function recordSleepCycle(
873
881
  pruned: known ? report.pruned.length : null,
874
882
  merged: known ? report.merged.length : null,
875
883
  faded: known ? report.faded.length : null,
884
+ // FADED UNDER A NEWER WORK EVENT (2026-11-07, FD1 step 3), beside
885
+ // `pruned` so a read of the nights tells the two apart: these stay
886
+ // live, faded, and leave later as age prunes.
887
+ interfered: known ? report.interfered.length : null,
888
+ // OPEN ITEMS THE NIGHT CLOSED (2026-11-07, SO1 step 1): the night's
889
+ // close count, beside the reopen rows (`thread.night.reopened`).
890
+ closed: known ? report.closed.length : null,
876
891
  bandUp: known ? report.bandTransitions.filter((t) => t.direction === "up").length : null,
877
892
  bandDown: known
878
893
  ? report.bandTransitions.filter((t) => t.direction === "down").length
@@ -1,6 +1,7 @@
1
1
  /** `Counterpart`'s deposit: the gate's record, the update guard, and carrying facts, reminders and threads onto what is written (bodies moved out of `counterpart.ts`, 2026-10-11; the class keeps a delegate for each). */
2
2
  import { batteryGate } from "./bridge.js";
3
- import { mintProposal, settlesWhenOf, UNRESOLVED_META_KEY } from "./mint.js";
3
+ import { mintProposal, settlesWhenOf, THREAD_REOPENED_BY_META_KEY, UNRESOLVED_META_KEY } from "./mint.js";
4
+ import { nightClosedOf, reopenNightClosed } from "./open-close.js";
4
5
  import type { MintResult } from "./mint.js";
5
6
  import { screenTags } from "./tag-screen.js";
6
7
  import { cueModeOf, recurrenceOf, DATE_FROM_META, DATE_LINEAGE_MAX, DATE_MOVED_TO_META } from "./prospective/index.js";
@@ -24,6 +25,7 @@ import { markWakeBehind } from "./self/index.js";
24
25
  import { ownerNames } from "./sleep/index.js";
25
26
  import { isBeliefRow } from "./recall/index.js";
26
27
  import { headOf } from "./recall/standing.js";
28
+ import { noteCloseHintTaken } from "./close-hint.js";
27
29
  import { statusOf, inheritFrom, occurredOnOf, saidByOf } from "./store/index.js";
28
30
  import type { AboutMark, MemoryRow, Inherited, MemoryStatus } from "./store/index.js";
29
31
  import type {
@@ -723,7 +725,8 @@ export function carrySettles(cp: Counterpart, p: Proposal): string | null {
723
725
  if (target === null) return null;
724
726
  try {
725
727
  const meta = cp.store.readProse(target).meta;
726
- if (meta[UNRESOLVED_META_KEY] === true) return settlesWhenOf(meta);
728
+ // A thread the night closed and this write carries on keeps its trigger too (SO1 step 1).
729
+ if (meta[UNRESOLVED_META_KEY] === true || nightClosedOf(meta) !== null) return settlesWhenOf(meta);
727
730
  // A CHAIN (review of #665): `updates` named an item the thread already
728
731
  // moved on from (a → b, then c updates a). The thread lives where the
729
732
  // chain now ends — the memory that holds over it (`recall/standing.ts#headOf`,
@@ -761,7 +764,22 @@ export function closeThread(cp: Counterpart, p: Proposal, successor: string): {
761
764
  try {
762
765
  const row = cp.store.row(target);
763
766
  if (row === undefined) return null;
764
- if (cp.store.readProse(target).meta[UNRESOLVED_META_KEY] !== true) return null;
767
+ const meta = cp.store.readProse(target).meta;
768
+ if (meta[UNRESOLVED_META_KEY] !== true) {
769
+ // A TOUCH ON AN ITEM THE NIGHT CLOSED (2026-11-07, SO1 step 1): a write
770
+ // that `updates` it and says `unresolved: true` carries the thread on,
771
+ // on this new row, open; that reopening is recorded, and the new row is
772
+ // marked (`threadReopenedBy`) so no night closes the thread again on its own.
773
+ if (p.unresolved === true && nightClosedOf(meta) !== null && row.protected !== 1 && row.archived !== 1) {
774
+ try {
775
+ reopenNightClosed(cp.store, target, { by: "updates", successor, restoreFlag: false });
776
+ cp.store.revise(successor, { meta: { [THREAD_REOPENED_BY_META_KEY]: `night:${target}` }, reason: "thread-reopened" });
777
+ } catch {
778
+ /* the new row is open either way */
779
+ }
780
+ }
781
+ return null;
782
+ }
765
783
  // THE REVISION STEP'S CHECKS, FIRST (review of #313): a flag is state
766
784
  // like any other, so what refuses a revision refuses this — the owner's
767
785
  // protection and an archived row, in `revision.ts`'s own words. Any
@@ -784,6 +802,9 @@ export function closeThread(cp: Counterpart, p: Proposal, successor: string): {
784
802
  } catch (err) {
785
803
  cp["emit"]("counterpart.thread.close.failed", target, { successor, error: errCode(err) });
786
804
  }
805
+ // A close that followed a write's close hint is counted (SO1 step 1b,
806
+ // `close-hint.ts`): hints shown against closes made. Answered, not carried on.
807
+ if (closed && p.unresolved !== true && !cp.observer) noteCloseHintTaken(cp.store, target, successor);
787
808
  cp["emit"]("counterpart.thread.closed", target, { successor, closed, carried: p.unresolved });
788
809
  return { from: target, closed };
789
810
  }
@@ -909,6 +909,9 @@ export const RECALL_DECISION_FIELDS = [
909
909
  "footnotes",
910
910
  "elapsedMs",
911
911
  "lateMs",
912
+ // LT2 part 1 (2026-11-09): ms per step of the pass, absent with
913
+ // `recall.STEP_TIMING` off. Added the way `echoSkipped` was; `tools/parallel`'s hash moves with it.
914
+ "steps",
912
915
  "aborted",
913
916
  // Association build 1 (2026-09-28): what spreading did, and the cut's count.
914
917
  "spread",
@@ -944,6 +947,12 @@ export const RECALL_DECISION_FIELDS = [
944
947
  // subjects named offered, which beliefs were shown, and their bytes; null
945
948
  // when the slot did not run (off, or a quiet turn). Added the way `primed` was.
946
949
  "beliefs",
950
+ // FD1 step 5 (2026-11-07): chapters and frozen copies an ambient turn left
951
+ // out as `LAST_HERE_LIFE_DAYS` or more lived days old (a named skip, like
952
+ // below-reach), and the journal's share of the pool and of the cut's slots.
953
+ // Added the way `echoSkipped` was; `tools/parallel`'s hash moves with it.
954
+ "journalAged",
955
+ "journalCandidates",
947
956
  ] as const;
948
957
 
949
958
  export type SurfaceSetField = (typeof RECALL_DECISION_FIELDS)[number];
@@ -1081,6 +1090,8 @@ export function recallDecisionRecord(
1081
1090
  // past the line it ran: `lateMs` is what the old `latency-abort` counted.
1082
1091
  elapsedMs: d.elapsedMs,
1083
1092
  lateMs: d.lateMs,
1093
+ // WHERE THE TIME WENT (LT2): step name → ms, copied; undefined (not written) while off.
1094
+ steps: d.steps,
1084
1095
  aborted: d.aborted,
1085
1096
  // What spreading did this turn and how many scored candidates the cut left
1086
1097
  // out — counts only (association build 1, 2026-09-28). `spread` is null on
@@ -1110,6 +1121,9 @@ export function recallDecisionRecord(
1110
1121
  primed: d.primed,
1111
1122
  // THE BELIEFS SLOT (lane E): null when it did not run.
1112
1123
  beliefs: d.beliefs,
1124
+ // AGED CHAPTERS AND THE JOURNAL'S SHARE (FD1 step 5): counts only.
1125
+ journalAged: d.journalAged,
1126
+ journalCandidates: d.journalCandidates,
1113
1127
  } satisfies Record<SurfaceSetField, unknown>;
1114
1128
  return surfaceSet;
1115
1129
  }
@@ -602,6 +602,12 @@ export type DepositReason =
602
602
  */
603
603
  export interface PlainReminder extends PlainDue {
604
604
  readonly what: string;
605
+ /**
606
+ * CROSSED (SO1 step 3 fix round): another folder's work reminder that went
607
+ * unsaid past its last day, told once wherever the person is, with its folder
608
+ * named — that folder's name. Its latch is `Prospective.claimCross`, not a beat.
609
+ */
610
+ readonly crossFrom?: string;
605
611
  }
606
612
 
607
613
  export interface DepositResult {