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.
- package/CHANGELOG.md +96 -0
- package/README.md +18 -10
- package/docs/QUICKSTART.md +46 -12
- package/docs/manual.md +2 -1
- package/docs/module-map.md +3 -0
- package/package.json +3 -2
- package/src/adapters/claude-code/NOTES.md +43 -0
- package/src/adapters/claude-code/child.ts +23 -2
- package/src/adapters/claude-code/doctor-growth.ts +269 -0
- package/src/adapters/claude-code/doctor-host.ts +19 -1
- package/src/adapters/claude-code/doctor-recall-steps.ts +84 -0
- package/src/adapters/claude-code/doctor.ts +26 -3
- package/src/adapters/claude-code/hooks.ts +7 -1
- package/src/adapters/cli/INTERFACE-GAPS.md +18 -0
- package/src/adapters/cli/NOTES.md +24 -0
- package/src/adapters/cli/commands-dashboard.ts +9 -1
- package/src/adapters/cli/commands-project.ts +2 -1
- package/src/adapters/cli/commands-readings.ts +19 -8
- package/src/adapters/cli/commands-verify.ts +1 -1
- package/src/adapters/cli/commands.ts +4 -2
- package/src/adapters/cli/export.ts +2 -1
- package/src/adapters/cli/install.ts +14 -6
- package/src/adapters/cli/mechanisms.ts +1 -1
- package/src/adapters/cli/wire.ts +22 -6
- package/src/adapters/dashboard/activity.ts +6 -3
- package/src/adapters/dashboard/registries.ts +11 -0
- package/src/adapters/dashboard/web/flow.ts +3 -0
- package/src/adapters/dashboard/web/lanes.ts +4 -0
- package/src/adapters/dashboard/web/narrate.ts +23 -0
- package/src/adapters/dashboard/web/views/activity.ts +4 -2
- package/src/adapters/dashboard/web/views/flow-view.ts +6 -0
- package/src/adapters/dashboard/web/views/memory.ts +13 -0
- package/src/adapters/dashboard/web/views/shared.ts +2 -1
- package/src/adapters/fired.ts +113 -11
- package/src/adapters/host-wiring.ts +3 -1
- package/src/adapters/lifecycle.ts +36 -9
- package/src/adapters/mcp/CONTRACT.md +22 -1
- package/src/adapters/mcp/server-args.ts +51 -0
- package/src/adapters/mcp/server-session-end.ts +8 -2
- package/src/adapters/mcp/server-words.ts +14 -1
- package/src/adapters/mcp/server.ts +117 -7
- package/src/adapters/mcp/tools.ts +4 -3
- package/src/adapters/plugin.ts +1 -0
- package/src/adapters/presence.ts +74 -0
- package/src/adapters/runtime.ts +258 -8
- package/src/adapters/scopes.ts +3 -2
- package/src/adapters/spawn.ts +3 -0
- package/src/adapters/update-check.ts +1 -1
- package/src/adapters/windows-shims.mjs +102 -0
- package/src/core/close-hint.ts +297 -0
- package/src/core/counterpart-boundary.ts +15 -0
- package/src/core/counterpart-deposit.ts +24 -3
- package/src/core/counterpart-events.ts +14 -0
- package/src/core/counterpart-types.ts +6 -0
- package/src/core/counterpart-wake-shape.ts +88 -19
- package/src/core/counterpart.ts +143 -7
- package/src/core/dream/index.ts +1 -1
- package/src/core/dream/reflect.ts +54 -34
- package/src/core/encode/NOTES.md +55 -0
- package/src/core/encode/secrets.ts +477 -3
- package/src/core/event-rollup.ts +175 -0
- package/src/core/handoff/CONTRACT.md +7 -0
- package/src/core/interference.ts +496 -0
- package/src/core/open-close.ts +583 -0
- package/src/core/prospective/CONTRACT.md +24 -0
- package/src/core/prospective/derive.ts +22 -1
- package/src/core/prospective/index.ts +115 -1
- package/src/core/recall/CONTRACT.md +9 -2
- package/src/core/recall/NOTES.md +99 -0
- package/src/core/recall/activate.ts +83 -6
- package/src/core/recall/index.ts +75 -5
- package/src/core/recall/probe.ts +134 -0
- package/src/core/recall/steps.ts +84 -0
- package/src/core/recall/tunables.ts +11 -0
- package/src/core/reconsolidation.ts +14 -4
- package/src/core/remember/CONTRACT.md +2 -1
- package/src/core/remember/NOTES.md +15 -0
- package/src/core/remember/spans.ts +44 -6
- package/src/core/self/NOTES.md +21 -0
- package/src/core/self/work.ts +9 -5
- package/src/core/sleep/CONTRACT.md +36 -2
- package/src/core/sleep/NOTES.md +35 -0
- package/src/core/sleep/close.ts +77 -0
- package/src/core/sleep/cycle.ts +44 -0
- package/src/core/sleep/index.ts +4 -0
- package/src/core/sleep/interfere.ts +73 -0
- package/src/core/sleep/log.ts +27 -2
- package/src/core/sleep/tunables.ts +19 -0
- package/src/core/sleep/types.ts +20 -0
- package/src/core/store/index.ts +157 -10
- package/src/core/store/operational.ts +22 -0
- package/src/core/store/owner-op-seam.ts +16 -0
- package/src/core/store/reads-history.ts +173 -7
- package/src/core/store/reads-memories.ts +253 -4
- package/src/core/store/shapes.ts +8 -0
|
@@ -57,9 +57,11 @@ import { byteLength } from "./self/identity.js";
|
|
|
57
57
|
import { readSentinel, settledOver } from "./self/index.js";
|
|
58
58
|
import { WAKE_SHAPE_LIMITS as SHAPE } from "./self/tunables.js";
|
|
59
59
|
import type { WakeDelivery, WakeResult } from "./self/index.js";
|
|
60
|
-
import { craftSince, isWorkMemory, projectFolder, threadPlace } from "./self/work.js";
|
|
60
|
+
import { craftSince, isWorkMemory, projectFolder, threadPlace, type WorkRule } from "./self/work.js";
|
|
61
61
|
import { addDays, ageWords, daysBetween, isDay, localDate, localStamp, monthDay, stampDay, startOfLocalDay } from "./time.js";
|
|
62
62
|
import { settlesWhenOf } from "./types.js";
|
|
63
|
+
import { lastNightCloses, OPEN_CLOSE_TUNABLES } from "./open-close.js";
|
|
64
|
+
import { PLAIN_OTHER_NAMED, PLAIN_OTHER_TITLE_CHARS } from "./prospective/index.js";
|
|
63
65
|
import type { Kind } from "./types.js";
|
|
64
66
|
import type { MemoryRow } from "./store/index.js";
|
|
65
67
|
import { TOLD_SOURCE, isTold } from "./told.js";
|
|
@@ -158,8 +160,12 @@ export interface Cue {
|
|
|
158
160
|
readonly mine: boolean;
|
|
159
161
|
/** The other folder it was written in, when not `mine`. */
|
|
160
162
|
readonly folder: string | null;
|
|
163
|
+
/** Personal (me, us, owner, or no folder), whoever reads it: it may be told in any folder (SO1 step 3). */
|
|
164
|
+
readonly personal: boolean;
|
|
161
165
|
}
|
|
162
166
|
|
|
167
|
+
const NO_FOLDERS: ReadonlySet<string> = new Set();
|
|
168
|
+
|
|
163
169
|
/** The folders a reader counts as here, as "Still open" reads them. */
|
|
164
170
|
function readerFolders(cp: Counterpart, here: WakeHere | undefined): Set<string> {
|
|
165
171
|
return new Set(cp["threadReader"](here?.scope, here?.exportsFrom).folders.map(projectFolder).filter((f) => f.length > 0));
|
|
@@ -186,7 +192,8 @@ export function readCues(cp: Counterpart, at: string, here: WakeHere | undefined
|
|
|
186
192
|
const fence = here?.exportsFrom;
|
|
187
193
|
const own = norm(here?.scope ?? "");
|
|
188
194
|
if (happenedAlready(store, h.id, at, { open: (r) => (fence === undefined ? norm(r.origin_scope ?? "") === own : !memoryClosedTo(store, r, fence, own)) }) !== null) continue;
|
|
189
|
-
const
|
|
195
|
+
const facts = { about: row.about ?? null, kind: row.kind as Kind, originScope: row.origin_scope ?? null, journal: false };
|
|
196
|
+
const place = threadPlace(facts, folders, rule);
|
|
190
197
|
let folder: string | null = null;
|
|
191
198
|
if (place === "out") {
|
|
192
199
|
folder = cp["memoryFolder"](row) ?? row.origin_scope ?? null;
|
|
@@ -214,6 +221,8 @@ export function readCues(cp: Counterpart, at: string, here: WakeHere | undefined
|
|
|
214
221
|
plain: h.plainDue === true,
|
|
215
222
|
mine: place !== "out",
|
|
216
223
|
folder: place === "out" ? folder : null,
|
|
224
|
+
// Whoever reads it: what crosses to a reader with no folder crosses to every one.
|
|
225
|
+
personal: threadPlace(facts, NO_FOLDERS, rule) !== "out",
|
|
217
226
|
});
|
|
218
227
|
}
|
|
219
228
|
return out;
|
|
@@ -436,14 +445,24 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
436
445
|
// agent's hand-back with nobody reading, isn't a wake anyone saw. A latch that
|
|
437
446
|
// names no session, or one the registry doesn't hold, doesn't count either.
|
|
438
447
|
// Never on a compaction: that session's model just lost what it was shown. A
|
|
439
|
-
// dated item that isn't plain has no such record and shows as before.
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
448
|
+
// dated item that isn't plain has no such record and shows as before. Only
|
|
449
|
+
// what this reader would show counts (SO1 step 3): another folder's work,
|
|
450
|
+
// told in its own folder, isn't "shown earlier" here, it's in other folders.
|
|
451
|
+
// A telling counts for a folder's work only when it was in one of this
|
|
452
|
+
// reader's folders: told anywhere else (a folderless chat, before SO1 step 3),
|
|
453
|
+
// it wasn't where it can be acted on. A personal one counts wherever it was told.
|
|
454
|
+
const saysHere = (c: Cue): boolean => c.mine;
|
|
455
|
+
const ourFolders = readerFolders(cp, here);
|
|
456
|
+
const seenToday = new Map(sessions.filter((s) => s.headless !== true && localDate(s.startedAt, zone) === at).map((s) => [s.session, projectFolder(s.scope)] as const));
|
|
457
|
+
const byToday = (c: Cue) => (session: string | null): boolean => {
|
|
458
|
+
if (session === null || !seenToday.has(session)) return false;
|
|
459
|
+
return c.personal || ourFolders.has(seenToday.get(session) ?? "");
|
|
460
|
+
};
|
|
461
|
+
const shownEarlier = new Set(here?.source === "compact" ? [] : cues.filter((c) => c.plain && saysHere(c) && safe(() => cp.prospective.plainToldOn(c.id, at, byToday(c)), false)).map((c) => c.id));
|
|
443
462
|
const later = scope.length === 0 ? null : safe(() => sinceHere(cp, scope, since, { handoffSession: newest?.session ?? null, handoffAt: newestAt, reader, lead: lead5, chapters: chaptersHere, skip: cueIds, folders: hereFolders }), null);
|
|
444
463
|
const sinceAged = (later?.items ?? []).map((s) => ({ ...s, age: ageOf(s.chapter ? s.at : Math.min(s.at, factAt(s.id))) }));
|
|
445
464
|
const open = safe(() => cp.self.stillOpen(day, cp["threadReader"](here?.scope, here?.exportsFrom)), { items: [], parked: 0 });
|
|
446
|
-
const folders =
|
|
465
|
+
const folders = ourFolders;
|
|
447
466
|
const rule = { craftTravels: cp.self.tunables.PROJECTS_TRAVEL, craftSince: craftSince(store) };
|
|
448
467
|
const openRows = open.items
|
|
449
468
|
.filter((i) => i.parked !== true)
|
|
@@ -467,6 +486,11 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
467
486
|
// And only with something in "Since, here" to read in its place (review of #734).
|
|
468
487
|
const stepDown = newestAt !== null && now - newestAt >= SHAPE.HANDOFF_STEP_DOWN_MS && sinceSessions > 0 && sinceAged.length > 0;
|
|
469
488
|
const night = safe(() => nightWords(cp, at, here, scope), null);
|
|
489
|
+
// WHAT THE NIGHT CLOSED ITSELF (2026-11-07, SO1 step 1): the newest
|
|
490
|
+
// night's closes, from yesterday's or today's lived day, as one line under
|
|
491
|
+
// "Last night" — only items this folder's Still open would carry (its own,
|
|
492
|
+
// a joined folder's, a personal one), never another folder's work.
|
|
493
|
+
const closedLine = safe(() => nightClosedLine(cp, day, folders, rule), null);
|
|
470
494
|
const installed = here?.installed ?? null;
|
|
471
495
|
const news = safe(() => sinceLastNight(cp, at, here, { ours: new Set(hereFolders), skip: cueIds }), { items: [] as NewsItem[], since: 0, night: false });
|
|
472
496
|
|
|
@@ -606,15 +630,16 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
606
630
|
|
|
607
631
|
const comingSec = (b: number, claim: ReadonlySet<string>): Sec => {
|
|
608
632
|
const live = cues.filter((c) => !claim.has(c.id) || c.plain);
|
|
609
|
-
// Another folder's dated work isn't due here (FS1): it's counted "in other folders", as the `coming up` door lists it.
|
|
610
|
-
|
|
633
|
+
// Another folder's dated work isn't due here (FS1): it's counted "in other folders", as the `coming up` door lists it.
|
|
634
|
+
// A plain reminder too (SO1 step 3, 2026-11-07): another folder's work is said in its own folder, not here; a personal one (me, us, owner) is `mine` everywhere.
|
|
635
|
+
const todayAll = live.filter((c) => c.today && saysHere(c));
|
|
611
636
|
const ranked = [...todayAll].sort(dueOrder);
|
|
612
637
|
const plain = ranked.filter((c) => c.plain && !shownEarlier.has(c.id));
|
|
613
638
|
const folded = live.filter((c) => shownEarlier.has(c.id)).length;
|
|
614
639
|
const rest = ranked.filter((c) => !c.plain);
|
|
615
640
|
const overdue = live.filter((c) => c.past && c.mine).sort((x, y) => String(y.due).localeCompare(String(x.due)));
|
|
616
641
|
const laterAll = live.filter((c) => !c.today && !c.past && c.mine).sort((x, y) => String(x.due ?? UNDATED_LAST).localeCompare(String(y.due ?? UNDATED_LAST)));
|
|
617
|
-
const other = live.filter((c) => !
|
|
642
|
+
const other = live.filter((c) => !saysHere(c));
|
|
618
643
|
const laterCap = spareOn.has("coming") ? SHAPE.LATER_SHOWN_SPARE : SHAPE.LATER_SHOWN;
|
|
619
644
|
const dueLine = (c: Cue): string => `- Due today · ${c.plain ? c.body : c.title}${c.settles === null ? "" : ` · settles when ${flatten(c.settles)}`} [${c.id}]`;
|
|
620
645
|
const overdueLine = (c: Cue): string => `- ${c.due === null ? "Overdue" : `${plural(Math.max(1, daysBetween(c.due, at)), "day")} overdue`} · ${c.title} [${c.id}]`;
|
|
@@ -625,11 +650,17 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
625
650
|
...overdue.slice(0, SHAPE.OVERDUE_SHOWN).map((c) => ({ c, line: overdueLine(c) })),
|
|
626
651
|
...laterAll.slice(0, laterCap).map((c) => ({ c, line: laterLine(c) })),
|
|
627
652
|
];
|
|
628
|
-
|
|
653
|
+
// OTHER FOLDERS' PLAIN REMINDERS DUE TODAY BY NAME (SO1 step 3 fix round): at
|
|
654
|
+
// most two, "folder: title", then "and N more", only when the line still fits.
|
|
655
|
+
const otherPlain = other.filter((c) => c.plain && c.today);
|
|
656
|
+
const among = [here?.scope ?? "", ...otherPlain.flatMap((c) => (c.folder === null ? [] : [c.folder]))];
|
|
657
|
+
const short = (t: string): string => (t.length <= PLAIN_OTHER_TITLE_CHARS ? t : `${t.slice(0, PLAIN_OTHER_TITLE_CHARS - 1).trimEnd()}…`);
|
|
658
|
+
const namedOther = otherPlain.length === 0 ? "" : ` (${[...otherPlain.slice(0, PLAIN_OTHER_NAMED).map((c) => `${c.folder === null ? "elsewhere" : placeWords(c.folder, among)}: ${short(flatten(c.title))}`), ...(otherPlain.length > PLAIN_OTHER_NAMED ? [`and ${String(otherPlain.length - PLAIN_OTHER_NAMED)} more`] : [])].join("; ")})`;
|
|
659
|
+
const render = (shown: readonly { c: Cue; line: string }[], named = false): string[] => {
|
|
629
660
|
const ids = new Set(shown.map((s) => s.c.id));
|
|
630
661
|
const hiddenToday = todayAll.filter((c) => !ids.has(c.id) && !shownEarlier.has(c.id)).length;
|
|
631
662
|
const hereMore = [...overdue, ...laterAll].filter((c) => !ids.has(c.id)).length;
|
|
632
|
-
const more = [hiddenToday > 0 ? `${String(hiddenToday)} more due today` : "", hereMore > 0 ? `${String(hereMore)} more here` : "", other.length > 0 ? `${String(other.length)} in other folders` : ""].filter((x) => x.length > 0).join(", ");
|
|
663
|
+
const more = [hiddenToday > 0 ? `${String(hiddenToday)} more due today` : "", hereMore > 0 ? `${String(hereMore)} more here` : "", other.length > 0 ? `${String(other.length)} in other folders${named ? namedOther : ""}` : ""].filter((x) => x.length > 0).join(", ");
|
|
633
664
|
// The fold is its own clause: "2 due today, shown earlier; 1 more due today; recall …".
|
|
634
665
|
const words = [folded > 0 ? `${String(folded)} due today, shown earlier` : "", more].filter((x) => x.length > 0).join("; ");
|
|
635
666
|
// Nothing to list and nothing behind the door: no section (WF1), not "Nothing dated."
|
|
@@ -642,7 +673,9 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
642
673
|
// later one may still fit: a long plain reminder doesn't hide what's after it.
|
|
643
674
|
const shown: { c: Cue; line: string }[] = [];
|
|
644
675
|
for (const o of order) if (byteLength(blockOf(render([...shown, o]))) <= b) shown.push(o);
|
|
645
|
-
|
|
676
|
+
// The names ride only in room the lines didn't need: never a line for them.
|
|
677
|
+
const withNames = blockOf(render(shown, true));
|
|
678
|
+
const text = namedOther !== "" && byteLength(withNames) <= b ? withNames : blockOf(render(shown));
|
|
646
679
|
if (byteLength(text) > b) return { text: "", ids: [], items: 0 };
|
|
647
680
|
return { text, ids: shown.map((s) => s.c.id), items: shown.length, lined: shown.map((s) => s.c.id) };
|
|
648
681
|
};
|
|
@@ -689,11 +722,23 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
689
722
|
};
|
|
690
723
|
|
|
691
724
|
const nightSec = (b: number): Sec => {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
725
|
+
const closed = closedLine === null ? [] : [closedLine];
|
|
726
|
+
if (night === null) {
|
|
727
|
+
const only = closed.length === 0 ? null : blockOf(closed);
|
|
728
|
+
return only !== null && byteLength(only) <= b ? { text: only, ids: [], items: 0 } : { text: "", ids: [], items: 0 };
|
|
729
|
+
}
|
|
730
|
+
// Widest first: the line, the night's own words, what it closed; then without the own words; then the line alone.
|
|
731
|
+
const forms = [
|
|
732
|
+
...(night.own === null ? [] : [[night.line, night.own, ...closed]]),
|
|
733
|
+
...(closed.length === 0 ? [] : [[night.line, ...closed]]),
|
|
734
|
+
...(night.own === null ? [] : [[night.line, night.own]]),
|
|
735
|
+
[night.line],
|
|
736
|
+
];
|
|
737
|
+
for (const f of forms) {
|
|
738
|
+
const text = blockOf(f);
|
|
739
|
+
if (byteLength(text) <= b) return { text, ids: [], items: 0 };
|
|
740
|
+
}
|
|
741
|
+
return { text: "", ids: [], items: 0 };
|
|
697
742
|
};
|
|
698
743
|
|
|
699
744
|
const fn: Readonly<Record<SectionKey, (b: number, claim: ReadonlySet<string>) => Sec>> = {
|
|
@@ -721,7 +766,7 @@ export function shapedDelivery(cp: Counterpart, delivery: WakeDelivery, here: Wa
|
|
|
721
766
|
const used = (s: Record<SectionKey, Sec>): number => ORDER.reduce((n, k) => n + byteLength(s[k].text), 0);
|
|
722
767
|
const left = room - byteLength(self.text);
|
|
723
768
|
|
|
724
|
-
const plainBytes = cues.filter((c) => c.plain && !shownEarlier.has(c.id)).reduce((n, c) => n + byteLength(`- Due today · ${c.body}${c.settles === null ? "" : ` · settles when ${flatten(c.settles)}`} [${c.id}]\n`), byteLength("Coming up:\n\n"));
|
|
769
|
+
const plainBytes = cues.filter((c) => c.plain && saysHere(c) && !shownEarlier.has(c.id)).reduce((n, c) => n + byteLength(`- Due today · ${c.body}${c.settles === null ? "" : ` · settles when ${flatten(c.settles)}`} [${c.id}]\n`), byteLength("Coming up:\n\n"));
|
|
725
770
|
const summaryBytes = summary === null ? 0 : byteLength(`Yesterday, in day's end's words: ${flatten(summary)}\n\n`);
|
|
726
771
|
const budgets: Budgets = { ...SHAPE.ROOM, coming: Math.max(SHAPE.ROOM.coming, plainBytes + SHAPE.COMING_PAST_PLAIN), yesterday: Math.max(SHAPE.ROOM.yesterday, summaryBytes) };
|
|
727
772
|
let sec = compose(budgets);
|
|
@@ -1007,6 +1052,30 @@ export function readElsewhere(cp: Counterpart, at: string, here: WakeHere | unde
|
|
|
1007
1052
|
];
|
|
1008
1053
|
}
|
|
1009
1054
|
|
|
1055
|
+
/**
|
|
1056
|
+
* "Closed by the night (2): 0.3.46 ready for Mike to publish — 0.3.47
|
|
1057
|
+
* released [mem_…]; … Not done? …" (2026-11-07, SO1 step 1): the newest
|
|
1058
|
+
* night's closes (`open-close.ts#lastNightCloses`) from lived day `day - 1`
|
|
1059
|
+
* on, kept to what this reader's Still open would carry (`threadPlace` not
|
|
1060
|
+
* `out`), at most `OPEN_CLOSE_TUNABLES.MORNING_SHOWN` by title. Null when none.
|
|
1061
|
+
*/
|
|
1062
|
+
function nightClosedLine(cp: Counterpart, day: number, folders: ReadonlySet<string>, rule: WorkRule): string | null {
|
|
1063
|
+
const store = cp.store;
|
|
1064
|
+
const mine = lastNightCloses(store, Math.max(0, day - 1)).filter((x) => {
|
|
1065
|
+
const r = store.row(x.id);
|
|
1066
|
+
return r !== undefined && threadPlace({ about: r.about ?? null, kind: r.kind as Kind, originScope: r.origin_scope ?? null, journal: false }, folders, rule) !== "out";
|
|
1067
|
+
});
|
|
1068
|
+
if (mine.length === 0) return null;
|
|
1069
|
+
const max = OPEN_CLOSE_TUNABLES.MORNING_TITLE_CHARS;
|
|
1070
|
+
const clip = (t: string): string => (t.length > max ? `${t.slice(0, max - 1)}…` : t);
|
|
1071
|
+
const named = mine.slice(0, OPEN_CLOSE_TUNABLES.MORNING_SHOWN).map((x) => {
|
|
1072
|
+
const r = store.row(x.id);
|
|
1073
|
+
return `${clip(flatten(r === undefined ? x.id : titleOfRow(r)))} — ${x.why} [${x.id}]`;
|
|
1074
|
+
});
|
|
1075
|
+
const more = mine.length - named.length;
|
|
1076
|
+
return `Closed by the night (${String(mine.length)}): ${named.join("; ")}${more > 0 ? `; +${String(more)} more` : ""}. One not done? The reflect tool's phase "reopen", reopen: [its id], puts it back.`;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1010
1079
|
/** "Last night", by title and door: the night's own words on what ran, no ids; and the night's own line, when it left one a reader here may read. */
|
|
1011
1080
|
function nightWords(cp: Counterpart, at: string, here: WakeHere | undefined, scope: string): { line: string; own: string | null } | null {
|
|
1012
1081
|
const store = cp.store;
|
package/src/core/counterpart.ts
CHANGED
|
@@ -48,7 +48,12 @@ import type { VectorSource } from "./bridge.js";
|
|
|
48
48
|
import type { MintResult } from "./mint.js";
|
|
49
49
|
import { isObserver } from "./observer.js";
|
|
50
50
|
import type { Stance } from "./observer.js";
|
|
51
|
-
import { Prospective } from "./prospective/index.js";
|
|
51
|
+
import { PLAIN_CROSS_AFTER_LIVED_DAYS, Prospective } from "./prospective/index.js";
|
|
52
|
+
|
|
53
|
+
/** The meta key a day with nothing unsaid to cross is memoised under (`Counterpart#plainCrossing`, round 3 of #780). */
|
|
54
|
+
export const PLAIN_CROSS_NONE_KEY = "prospective.cross.none";
|
|
55
|
+
/** One of my own checks (SO1 step 3's "mine" class): it waits for its folder, never crosses. */
|
|
56
|
+
const MY_CHECK = /CHECK-AFTER|\bCheck due\b|\bCheck ~|\bExperiment check\b/i;
|
|
52
57
|
import type { PlainDue } from "./prospective/index.js";
|
|
53
58
|
import {
|
|
54
59
|
ASKED_KIND,
|
|
@@ -76,6 +81,7 @@ import {
|
|
|
76
81
|
RATED_SAME_TURN_ROWS,
|
|
77
82
|
isBeliefRow,
|
|
78
83
|
beliefLine,
|
|
84
|
+
StepClock,
|
|
79
85
|
} from "./recall/index.js";
|
|
80
86
|
import { DREW_ON_MAX_PER_BOUNDARY, resolveReferences } from "./recall/reference.js";
|
|
81
87
|
import type { ReferenceCandidate } from "./recall/reference.js";
|
|
@@ -109,13 +115,13 @@ import type {
|
|
|
109
115
|
Turn as CapturedTurn,
|
|
110
116
|
UpdatesResolution,
|
|
111
117
|
} from "./remember/index.js";
|
|
112
|
-
import { redactSecrets } from "./encode/index.js";
|
|
118
|
+
import { redactSecrets, scanSecrets } from "./encode/index.js";
|
|
113
119
|
import { TUNABLES as SCHEMAS_TUNABLES } from "./schemas/tunables.js";
|
|
114
120
|
import { similarity as textSimilarity } from "./remember/updates.js";
|
|
115
121
|
import { OWN_PLUMBING_META_KEY } from "./remember/own-plumbing.js";
|
|
116
122
|
import { REFLECT_TUNABLES } from "./dream/reflect.js";
|
|
117
123
|
import type { SchemaSlice as EncodeSchemaSlice } from "./encode/index.js";
|
|
118
|
-
import {
|
|
124
|
+
import { composeTurn } from "./retrieval.js";
|
|
119
125
|
import { applyRevision } from "./revision.js";
|
|
120
126
|
import type { RevisionApplication } from "./revision.js";
|
|
121
127
|
import {
|
|
@@ -185,6 +191,8 @@ import {
|
|
|
185
191
|
craftBornDay,
|
|
186
192
|
CRAFT_SINCE_KEY,
|
|
187
193
|
isDirectoryScope,
|
|
194
|
+
threadPlace,
|
|
195
|
+
folderName,
|
|
188
196
|
} from "./self/index.js";
|
|
189
197
|
import type {
|
|
190
198
|
BriefingResult,
|
|
@@ -237,6 +245,7 @@ import type {
|
|
|
237
245
|
import { TUNABLES as PHYSICS, band as bandOf, fadeOf } from "./physics/index.js";
|
|
238
246
|
import type { UseTier } from "./physics/index.js";
|
|
239
247
|
import type { Kind } from "./types.js";
|
|
248
|
+
import { settlesWhenOf } from "./types.js";
|
|
240
249
|
import { isKnownSession, livedOn } from "./types.js";
|
|
241
250
|
import {
|
|
242
251
|
SELF_BRIEFING_EVENT,
|
|
@@ -671,6 +680,9 @@ export class Counterpart {
|
|
|
671
680
|
day: () => this.store.livedDay(),
|
|
672
681
|
now: this.nowFn,
|
|
673
682
|
onEvent: (e) => this.relay("remember", e),
|
|
683
|
+
// The raw buffer crosses the same secrets scan a memory does (SX1), before
|
|
684
|
+
// anything is hashed or written: a turn at Stop, a note's own line.
|
|
685
|
+
redact: (text) => scanSecrets(text, "raw"),
|
|
674
686
|
});
|
|
675
687
|
|
|
676
688
|
// DREAMING. Every word a dream writes is REDACTED of credentials before it
|
|
@@ -3155,6 +3167,9 @@ export class Counterpart {
|
|
|
3155
3167
|
// `composeTurn` skips its own read when `turn.temporal` is already set, so
|
|
3156
3168
|
// this is the same channel and the same ceiling (§12 G1, G5) — one read of
|
|
3157
3169
|
// `arrivals()`, never two.
|
|
3170
|
+
// WHERE THE TIME WENT (LT2, 2026-11-09): one clock from here through the
|
|
3171
|
+
// record, lapped at each step (`recall/steps.ts`); read by nothing that decides.
|
|
3172
|
+
const clock = turn.clock ?? new StepClock();
|
|
3158
3173
|
const arrived =
|
|
3159
3174
|
opts.at === undefined || turn.temporal !== undefined
|
|
3160
3175
|
? null
|
|
@@ -3167,16 +3182,26 @@ export class Counterpart {
|
|
|
3167
3182
|
}).arrivals.filter((a) => opts.withhold?.has(a.memoryId) !== true);
|
|
3168
3183
|
const cued: RecallTurn =
|
|
3169
3184
|
arrived === null ? turn : { ...turn, temporal: arrived.map((a) => ({ id: a.memoryId, weight: a.cueWeight })) };
|
|
3185
|
+
clock.lap("arrivals");
|
|
3170
3186
|
const echo = turn.echo ?? this.echoOf(turn.sessionId, opts.echoSince, opts.sessionFrom);
|
|
3171
3187
|
const echoed: RecallTurn = echo.size === 0 ? cued : { ...cued, echo };
|
|
3188
|
+
clock.lap("echo");
|
|
3172
3189
|
const placed: RecallTurn = turn.elsewhere !== undefined ? echoed : this.withElsewhere(echoed, opts.scope);
|
|
3173
3190
|
const withCues: RecallTurn = this.withNamedFence(placed, opts.foldersOn, opts.scope);
|
|
3174
|
-
|
|
3191
|
+
clock.lap("place");
|
|
3192
|
+
const meant = this.withSemantic(withCues);
|
|
3193
|
+
clock.lap("embed");
|
|
3194
|
+
const primed = this.withPrime(meant, opts.scope);
|
|
3195
|
+
clock.lap("primeContext");
|
|
3196
|
+
// `retrieval.ts#recallTurn` in two steps, so the binding is timed apart.
|
|
3197
|
+
const composed = composeTurn(primed, {
|
|
3175
3198
|
schemas: this.schemas,
|
|
3176
3199
|
prospective: this.prospective,
|
|
3177
3200
|
associate: this.associate,
|
|
3178
3201
|
...(opts.at === undefined ? {} : { at: opts.at }),
|
|
3179
3202
|
});
|
|
3203
|
+
clock.lap("compose");
|
|
3204
|
+
const result = this.recall.recall({ ...composed, clock });
|
|
3180
3205
|
this.recordDecision(result.decision, opts.at ?? null);
|
|
3181
3206
|
if (arrived !== null && opts.at !== undefined) this.spendArrivals(arrived, result.decision, opts.at);
|
|
3182
3207
|
return result;
|
|
@@ -3456,15 +3481,121 @@ export class Counterpart {
|
|
|
3456
3481
|
return held;
|
|
3457
3482
|
}
|
|
3458
3483
|
|
|
3484
|
+
/**
|
|
3485
|
+
* WHICH OF THESE PLAIN REMINDERS ARE ANOTHER FOLDER'S, NOT THIS READER'S TO BE
|
|
3486
|
+
* TOLD (SO1 step 3, 2026-11-07, with Mike: what reached motelier was plain
|
|
3487
|
+
* things to do from other folders). A reminder written in another folder —
|
|
3488
|
+
* work, or marked world — is said in its own folder (and the folders joined to
|
|
3489
|
+
* it as one project), as Coming up's place reads it (`self/work.ts#threadPlace`,
|
|
3490
|
+
* the reader's folders as Still open's, `threadReader`). Held back like a
|
|
3491
|
+
* closed folder's: not offered, so not claimed, not latched, not spent, and its
|
|
3492
|
+
* own folder's first wake that day still tells it whole. Marked me, us or owner,
|
|
3493
|
+
* or with no folder: told everywhere, as before. A reader with no folder (a
|
|
3494
|
+
* claude.ai chat) is told only the personal ones (the roadmap's call, fix round
|
|
3495
|
+
* of #780): no folder's work is its to be told. A read. Never throws: a row that
|
|
3496
|
+
* won't read is not held.
|
|
3497
|
+
*/
|
|
3498
|
+
plainAway(ids: readonly string[], scope: string | undefined, exportsFrom?: (scope: string) => boolean): ReadonlySet<string> {
|
|
3499
|
+
const away = new Set<string>();
|
|
3500
|
+
try {
|
|
3501
|
+
const folders = new Set(this.threadReader(scope, exportsFrom).folders.map(projectFolder).filter((f) => f.length > 0));
|
|
3502
|
+
const rule = { craftTravels: this.self.tunables.PROJECTS_TRAVEL, craftSince: craftSince(this.store) };
|
|
3503
|
+
for (const id of ids) {
|
|
3504
|
+
try {
|
|
3505
|
+
const row = this.store.row(id);
|
|
3506
|
+
if (row === undefined) continue;
|
|
3507
|
+
if (threadPlace({ about: row.about ?? null, kind: row.kind as Kind, originScope: row.origin_scope ?? null, journal: false }, folders, rule) === "out") away.add(id);
|
|
3508
|
+
} catch {
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
} catch {
|
|
3513
|
+
return away;
|
|
3514
|
+
}
|
|
3515
|
+
return away;
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
/**
|
|
3519
|
+
* THE FALLBACK, SO A REAL DEADLINE CAN'T GO SILENT (SO1 step 3 fix round,
|
|
3520
|
+
* 2026-11-07, the roadmap's call): another folder's work reminder (or one marked
|
|
3521
|
+
* world) that went unsaid through its window, because its folder had no session,
|
|
3522
|
+
* crosses ONCE, `PLAIN_CROSS_AFTER_LIVED_DAYS` lived days past its last day. A
|
|
3523
|
+
* lived day is a calendar day a person had a session: `lived` gives those days, read
|
|
3524
|
+
* once, and only when something is unsaid, from the log's presence rows (round 3: the registry prunes
|
|
3525
|
+
* after a week), and today counts. Not a closed folder's (the caller's
|
|
3526
|
+
* `plainHeldBack` still holds those), not one that already happened, not one
|
|
3527
|
+
* marked done, and not one of my own checks (CHECK-AFTER, "Check due", "Check ~",
|
|
3528
|
+
* "Experiment check" in its title or settles-when: those wait for their folder).
|
|
3529
|
+
* `crossFrom` names its folder. A read; `claimPlainReminder` claims it, once
|
|
3530
|
+
* across every folder.
|
|
3531
|
+
*
|
|
3532
|
+
* MEMOISED PER STORE PER DAY (round 3): a day with nothing unsaid is written
|
|
3533
|
+
* down (`PLAIN_CROSS_NONE_KEY`) and every later ask that day costs one meta
|
|
3534
|
+
* read. What could make one unsaid later the same day — a reminder written
|
|
3535
|
+
* today for a day already past — was written after its day, which never counts.
|
|
3536
|
+
* Never throws.
|
|
3537
|
+
*/
|
|
3538
|
+
plainCrossing(input: { at: string; lived: () => ReadonlySet<string> }): PlainReminder[] {
|
|
3539
|
+
if (this.observer) return [];
|
|
3540
|
+
const out: PlainReminder[] = [];
|
|
3541
|
+
try {
|
|
3542
|
+
if (this.store.getMeta(PLAIN_CROSS_NONE_KEY) === input.at) return out;
|
|
3543
|
+
const unsaid = this.prospective.plainUnsaid({ at: input.at });
|
|
3544
|
+
if (unsaid.length === 0) {
|
|
3545
|
+
try {
|
|
3546
|
+
this.store.setMeta(PLAIN_CROSS_NONE_KEY, input.at);
|
|
3547
|
+
} catch {
|
|
3548
|
+
/* a memo, nothing more */
|
|
3549
|
+
}
|
|
3550
|
+
return out;
|
|
3551
|
+
}
|
|
3552
|
+
const lived = new Set([...input.lived(), input.at]);
|
|
3553
|
+
const livedSince = (day: string): number => [...lived].filter((d) => d > day && d <= input.at).length;
|
|
3554
|
+
const nowhere = new Set<string>();
|
|
3555
|
+
for (const due of unsaid) {
|
|
3556
|
+
const row = this.store.row(due.memoryId);
|
|
3557
|
+
if (row === undefined || row.status === "done") continue;
|
|
3558
|
+
const facts = { about: row.about ?? null, kind: row.kind as Kind, originScope: row.origin_scope ?? null, journal: false };
|
|
3559
|
+
// Only what waits for a folder: a personal one was told wherever a session ran.
|
|
3560
|
+
if (threadPlace(facts, nowhere) !== "out") continue;
|
|
3561
|
+
if (livedSince(due.lastDay) < PLAIN_CROSS_AFTER_LIVED_DAYS) continue;
|
|
3562
|
+
let title = "";
|
|
3563
|
+
let what = "";
|
|
3564
|
+
let settles = "";
|
|
3565
|
+
try {
|
|
3566
|
+
const doc = this.store.readProse(due.memoryId);
|
|
3567
|
+
title = doc.title?.trim() ?? "";
|
|
3568
|
+
const line = doc.body.split("\n").map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
3569
|
+
what = (title.length > 0 ? title : line).replace(/\s+/g, " ").trim();
|
|
3570
|
+
settles = settlesWhenOf(doc.meta) ?? "";
|
|
3571
|
+
} catch {
|
|
3572
|
+
continue;
|
|
3573
|
+
}
|
|
3574
|
+
if (what.length === 0) continue;
|
|
3575
|
+
if (MY_CHECK.test(title) || MY_CHECK.test(settles)) continue;
|
|
3576
|
+
if (happenedAlready(this.store, due.memoryId, input.at, {}) !== null) continue;
|
|
3577
|
+
const folder = this.memoryFolder(row) ?? row.origin_scope ?? "";
|
|
3578
|
+
out.push({ ...due, what, crossFrom: folderName(folder) });
|
|
3579
|
+
}
|
|
3580
|
+
} catch (err) {
|
|
3581
|
+
this.emit("counterpart.prospective.plain.failed", undefined, { code: errCode(err) });
|
|
3582
|
+
}
|
|
3583
|
+
return out;
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3459
3586
|
/**
|
|
3460
3587
|
* Claim one plain beat: TRUE only when this call wrote the latch
|
|
3461
3588
|
* (`Prospective.claimPlain`), so two processes racing for the same beat
|
|
3462
3589
|
* cannot both show it. Show the line only on true. Never throws.
|
|
3463
3590
|
*/
|
|
3464
|
-
claimPlainReminder(reminder: PlainDue, input: { at: string; day?: number; session?: string }): boolean {
|
|
3591
|
+
claimPlainReminder(reminder: PlainDue & { readonly crossFrom?: string }, input: { at: string; day?: number; session?: string }): boolean {
|
|
3465
3592
|
if (this.observer) return false;
|
|
3466
3593
|
try {
|
|
3467
3594
|
const day = input.day ?? this.store.livedDay();
|
|
3595
|
+
// A crossing has its own latch, once across every folder, and is no beat.
|
|
3596
|
+
if (reminder.crossFrom !== undefined) {
|
|
3597
|
+
return this.prospective.claimCross(reminder, { at: input.at, day, ...(input.session === undefined ? {} : { session: input.session }) });
|
|
3598
|
+
}
|
|
3468
3599
|
// Asked BEFORE the claim, which is itself what would make it false.
|
|
3469
3600
|
const first = this.prospective.occurrenceUndelivered(reminder.memoryId, reminder.windowKey);
|
|
3470
3601
|
const claimed = this.prospective.claimPlain(reminder, {
|
|
@@ -4624,7 +4755,7 @@ export class Counterpart {
|
|
|
4624
4755
|
};
|
|
4625
4756
|
let failure: string | null = null;
|
|
4626
4757
|
const linked: string[] = [];
|
|
4627
|
-
const cueOut: { deltas: number; rows: number; dropped: number; stopped?: number } = { deltas: 0, rows: 0, dropped: 0 };
|
|
4758
|
+
const cueOut: { deltas: number; rows: number; dropped: number; stopped?: number; swept?: number } = { deltas: 0, rows: 0, dropped: 0 };
|
|
4628
4759
|
for (const claim of claims) {
|
|
4629
4760
|
out.passes += claim.passes;
|
|
4630
4761
|
out.pairs += claim.deltas.length;
|
|
@@ -4675,7 +4806,11 @@ export class Counterpart {
|
|
|
4675
4806
|
}
|
|
4676
4807
|
// R3S: what the stop-list dropped, only while it holds a word.
|
|
4677
4808
|
if (cueReport?.stopped !== undefined) cueOut.stopped = (cueOut.stopped ?? 0) + cueReport.stopped;
|
|
4678
|
-
if (cueReport !== null && cueReport.reason === "flushed")
|
|
4809
|
+
if (cueReport !== null && cueReport.reason === "flushed") {
|
|
4810
|
+
cueOut.rows += cueReport.rows;
|
|
4811
|
+
// FD1 step 2: the pairs the flush's sweep let go, for doctor's Growth line.
|
|
4812
|
+
if (cueReport.swept > 0) cueOut.swept = (cueOut.swept ?? 0) + cueReport.swept;
|
|
4813
|
+
}
|
|
4679
4814
|
else {
|
|
4680
4815
|
cueOut.dropped += claim.cues.length;
|
|
4681
4816
|
// A busy flush left them buffered; this process ends soon, and the claim goes: drop them, counted.
|
|
@@ -4726,6 +4861,7 @@ export class Counterpart {
|
|
|
4726
4861
|
// CUE LEARNING (R3): word-to-memory deltas carried, pair rows written, deltas lost.
|
|
4727
4862
|
...(cueOut.deltas === 0 ? {} : { cueDeltas: cueOut.deltas, cueRows: cueOut.rows, cueDropped: cueOut.dropped }),
|
|
4728
4863
|
...(cueOut.stopped === undefined ? {} : { cueStopped: cueOut.stopped }),
|
|
4864
|
+
...(cueOut.swept === undefined ? {} : { cueSwept: cueOut.swept }),
|
|
4729
4865
|
...rowIds(linked),
|
|
4730
4866
|
// The APPLYING session (2026-10-11): the boundary whose worker carried
|
|
4731
4867
|
// these claims. A claim may hold lines several sessions credited.
|
package/src/core/dream/index.ts
CHANGED
|
@@ -3745,7 +3745,7 @@ export class Dreams {
|
|
|
3745
3745
|
const id = headOf(this.store, named) ?? named;
|
|
3746
3746
|
if (own.has(id) || own.has(named) || saidNow.has(id) || found.includes(id) || closed.has(id)) continue;
|
|
3747
3747
|
const row = recallableRow(this.store, id, { denied, ambient: false, day });
|
|
3748
|
-
if (row === undefined || row === "
|
|
3748
|
+
if (row === undefined || typeof row === "string") continue;
|
|
3749
3749
|
found.push(id);
|
|
3750
3750
|
}
|
|
3751
3751
|
}
|