counterparts 0.3.13 → 0.3.14
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 +160 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/bin/hook.mjs +4 -2
- package/src/adapters/claude-code/bin/hook.ts +11 -4
- package/src/adapters/claude-code/bin/nightly.ts +5 -1
- package/src/adapters/claude-code/bin/runner.ts +11 -3
- package/src/adapters/claude-code/doctor.ts +69 -5
- package/src/adapters/claude-code/embed-client.ts +3 -0
- package/src/adapters/cli/bin/counterparts.mjs +4 -2
- package/src/adapters/cli/bin/counterparts.ts +11 -3
- package/src/adapters/cli/commands.ts +65 -23
- package/src/adapters/cli/index.ts +1 -0
- package/src/adapters/cli/install.ts +22 -9
- package/src/adapters/cli/settle.ts +39 -2
- package/src/adapters/cli/wire.ts +4 -0
- package/src/adapters/config.ts +29 -1
- package/src/adapters/dashboard/NOTES.md +33 -0
- package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
- package/src/adapters/dashboard/bin/dashboard.ts +11 -3
- package/src/adapters/dashboard/index.ts +14 -0
- package/src/adapters/dashboard/source.ts +0 -8
- package/src/adapters/dashboard/web/fired.ts +8 -0
- package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
- package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
- package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
- package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
- package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
- package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
- package/src/adapters/dashboard/web/server.ts +16 -4
- package/src/adapters/dashboard/web/shared/dates.js +6 -16
- package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
- package/src/adapters/dashboard/web/views/health.ts +11 -0
- package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
- package/src/adapters/dashboard/web/views/memories.ts +26 -7
- package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
- package/src/adapters/dashboard/web/views/memory.ts +51 -2
- package/src/adapters/dashboard/web/views/mind.ts +31 -6
- package/src/adapters/empty-bunfig.toml +5 -0
- package/src/adapters/fired.ts +6 -2
- package/src/adapters/host-wiring.ts +4 -3
- package/src/adapters/log/index.ts +2 -2
- package/src/adapters/mcp/CONTRACT.md +16 -2
- package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
- package/src/adapters/mcp/NOTES.md +243 -0
- package/src/adapters/mcp/bin/serve.mjs +4 -2
- package/src/adapters/mcp/bin/serve.ts +11 -4
- package/src/adapters/mcp/facts.ts +72 -4
- package/src/adapters/mcp/meaning.ts +218 -15
- package/src/adapters/mcp/server.ts +1 -1
- package/src/adapters/mcp/tools.ts +81 -57
- package/src/adapters/plugin-run.sh +405 -33
- package/src/adapters/plugin.ts +14 -2
- package/src/adapters/runtime.ts +192 -17
- package/src/adapters/sessions.ts +2 -2
- package/src/core/associate/NOTES.md +10 -0
- package/src/core/bridge.ts +1 -1
- package/src/core/briefing.ts +20 -3
- package/src/core/contradictions.ts +56 -20
- package/src/core/counterpart.ts +39 -17
- package/src/core/dream/CONTRACT.md +4 -12
- package/src/core/dream/INTERFACE-GAPS.md +3 -2
- package/src/core/dream/NOTES.md +10 -0
- package/src/core/dream/index.ts +10 -52
- package/src/core/embed/static.ts +5 -1
- package/src/core/encode/INTERFACE-GAPS.md +2 -1
- package/src/core/encode/NOTES.md +12 -0
- package/src/core/encode/chunk.ts +6 -30
- package/src/core/encode/index.ts +0 -1
- package/src/core/encode/types.ts +1 -13
- package/src/core/handoff/last-here.ts +18 -2
- package/src/core/physics/CONTRACT.md +6 -0
- package/src/core/physics/NOTES.md +33 -2
- package/src/core/physics/index.ts +22 -7
- package/src/core/prospective/CONTRACT.md +3 -1
- package/src/core/prospective/NOTES.md +15 -0
- package/src/core/recall/time-ask.ts +154 -19
- package/src/core/self/CONTRACT.md +23 -3
- package/src/core/self/NOTES.md +64 -0
- package/src/core/self/behind.ts +6 -3
- package/src/core/self/briefing.ts +272 -11
- package/src/core/self/index.ts +50 -4
- package/src/core/sleep/NOTES.md +32 -0
- package/src/core/store/NOTES.md +16 -0
- package/src/core/time.ts +15 -0
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* There is no default in this module to fall back to.
|
|
19
19
|
* - **The trim order is declared and tested** (`TRIM_ORDER`), and trimming eats
|
|
20
20
|
* from the END of a lane, whose ordering is itself policy: *truncation must
|
|
21
|
-
* never be iteration luck* (§1 G3–G4).
|
|
21
|
+
* never be iteration luck* (§1 G3–G4). One declared exception, after the
|
|
22
|
+
* loop: "Still open" keeps its first item before Arriving keeps its second
|
|
23
|
+
* line (`keepFirstOpen`, 2026-10-09).
|
|
22
24
|
* - **The identity SHARE decides how the total is split when lanes compete.**
|
|
23
25
|
* The budget still governs the composed total (§5 G2); the share is not a
|
|
24
26
|
* lane budget but a rule about who wins the contested bytes, and it exists
|
|
@@ -41,6 +43,7 @@
|
|
|
41
43
|
import type { LaneName, Ranked } from "./identity.js";
|
|
42
44
|
import { byteLength } from "./identity.js";
|
|
43
45
|
import type { SelfTunables } from "./tunables.js";
|
|
46
|
+
import { addDays, isDay } from "../time.js";
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
49
|
* Composed order — behavioral-spec §1's, minus the two riders the Rulings drop
|
|
@@ -142,9 +145,41 @@ const MORE_ORDER: readonly LaneName[] = [
|
|
|
142
145
|
|
|
143
146
|
/** `(3 more still open; recall ids: mem_…, mem_…, mem_…)` */
|
|
144
147
|
export function moreLine(lane: LaneName, ids: readonly string[]): string {
|
|
148
|
+
return `(${String(ids.length)} more ${MORE_NOUN[lane]}; ${recallIds(ids)})`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function recallIds(ids: readonly string[]): string {
|
|
145
152
|
const shown = ids.slice(0, MORE_LINE_IDS);
|
|
146
153
|
const which = ids.length > shown.length ? `recall ids (the first ${String(shown.length)})` : "recall ids";
|
|
147
|
-
return
|
|
154
|
+
return `${which}: ${shown.join(", ")}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A LANE WITH NOTHING LISTED SAYS SO IN ONE LINE, NOT A HEADING OVER A COUNT
|
|
159
|
+
* (2026-10-09). The owner's wake that morning read "Still open:" and, under
|
|
160
|
+
* it, "(20 more still open; recall ids …)" with no item between — a heading
|
|
161
|
+
* over nothing reads like a broken page, and "more" than none is not a count.
|
|
162
|
+
* When a lane keeps no element and has something to say about what it left
|
|
163
|
+
* out, the heading and the count are one line: `Still open: 20 — no room to
|
|
164
|
+
* list them in this wake; recall ids (the first 5): mem_…`. Furniture, like
|
|
165
|
+
* the "more" line it replaces; the identity lane keeps its heading, which has
|
|
166
|
+
* the page or the day-0 line under it. The dashboard reads the lane off the
|
|
167
|
+
* line's own heading (`collapsedLane`).
|
|
168
|
+
*/
|
|
169
|
+
export const COLLAPSED_WORDS = "no room to list them in this wake";
|
|
170
|
+
|
|
171
|
+
export function collapsedLine(lane: LaneName, ids: readonly string[]): string {
|
|
172
|
+
return `${laneHeading(lane)} ${String(ids.length)} — ${COLLAPSED_WORDS}; ${recallIds(ids)}`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The lane a collapsed line (`collapsedLine`) speaks for, or null for any other line. */
|
|
176
|
+
export function collapsedLane(line: string): LaneName | null {
|
|
177
|
+
for (const lane of LANE_ORDER) {
|
|
178
|
+
const heading = laneHeading(lane);
|
|
179
|
+
if (!line.startsWith(`${heading} `)) continue;
|
|
180
|
+
if (new RegExp(`^ \\d+ — ${COLLAPSED_WORDS}; recall ids`).test(line.slice(heading.length))) return lane;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
148
183
|
}
|
|
149
184
|
|
|
150
185
|
/**
|
|
@@ -278,6 +313,12 @@ export interface Resolved {
|
|
|
278
313
|
* Only a horizon item that repeats carries one.
|
|
279
314
|
*/
|
|
280
315
|
readonly every?: string;
|
|
316
|
+
/**
|
|
317
|
+
* True when `due` was already BEHIND the day the wake was composed for
|
|
318
|
+
* (`HorizonItem.past`, 2026-10-09) — a one-off in its grace days — so the
|
|
319
|
+
* line says `(was due …)` rather than reading as still to come.
|
|
320
|
+
*/
|
|
321
|
+
readonly duePast?: boolean;
|
|
281
322
|
/**
|
|
282
323
|
* True when the encode date is only an UPPER BOUND — the element was known BY
|
|
283
324
|
* then, not learned then. Set for migrated elements, whose `learned_on` is
|
|
@@ -337,6 +378,24 @@ export interface BriefingRequest {
|
|
|
337
378
|
* the floor would not fit with it. Absent: no line.
|
|
338
379
|
*/
|
|
339
380
|
readonly yesterday?: string;
|
|
381
|
+
/**
|
|
382
|
+
* SHORTER FORMS OF THE SAME LINE, widest first (review of #350,
|
|
383
|
+
* 2026-10-09): fewer titles, the rest by count — composed by the caller,
|
|
384
|
+
* which holds the chapters the count is of. Stepped down only to make room
|
|
385
|
+
* for "Still open"'s first item (`keepFirstOpen`). Ignored without
|
|
386
|
+
* `yesterday`.
|
|
387
|
+
*/
|
|
388
|
+
readonly yesterdayShorter?: readonly string[];
|
|
389
|
+
/**
|
|
390
|
+
* THE ROOM THE DELIVERY HOLDS FOR "WORK HERE" (review of #350, 2026-10-09),
|
|
391
|
+
* in bytes: the caller's reserve for this directory's work lines, which it
|
|
392
|
+
* took out of `budgetBytes` before composing. Lent to "Still open"'s first
|
|
393
|
+
* item and its count only (`keepFirstOpen`), and before Arriving or the
|
|
394
|
+
* Yesterday line give anything up: the work lines are hints, and the
|
|
395
|
+
* delivery shows fewer of them in what is left. Nothing else composes into
|
|
396
|
+
* it. Absent: nothing to lend.
|
|
397
|
+
*/
|
|
398
|
+
readonly lendBytes?: number;
|
|
340
399
|
}
|
|
341
400
|
|
|
342
401
|
export interface TrimEvent {
|
|
@@ -469,6 +528,9 @@ export function flatten(text: string): string {
|
|
|
469
528
|
*/
|
|
470
529
|
export const DATE_SEP = " · ";
|
|
471
530
|
export const DATE_BOUND = "by ";
|
|
531
|
+
/** How an arriving line names its date, ahead of it and once it has passed. */
|
|
532
|
+
export const DUE_WORD = "due";
|
|
533
|
+
export const DUE_PAST_WORD = "was due";
|
|
472
534
|
|
|
473
535
|
export function datePrefix(r: Resolved): string {
|
|
474
536
|
const learned = (r.learnedOn ?? "").trim();
|
|
@@ -481,8 +543,15 @@ export function datePrefix(r: Resolved): string {
|
|
|
481
543
|
// due on the day it was learned, since "every May 14" is news there too.
|
|
482
544
|
const every = (r.every ?? "").trim();
|
|
483
545
|
const often = every === "" ? "" : `, ${every}`;
|
|
484
|
-
|
|
485
|
-
|
|
546
|
+
// PAST ITS DATE, IT SAYS SO (2026-10-09): a one-off stays under
|
|
547
|
+
// "Arriving:" for its grace days (`prospective/` GRACE_DAYS), and
|
|
548
|
+
// "(due 2026-10-08)" read on the 9th reads as still to come.
|
|
549
|
+
const word = r.duePast === true ? DUE_PAST_WORD : DUE_WORD;
|
|
550
|
+
// DUE ON THE DAY IT WAS LEARNED: the one date, stated once — as the DUE
|
|
551
|
+
// date (2026-10-09), so the line still says when, and the delivery can
|
|
552
|
+
// put it in the past tense the morning after (`arrivingTense`).
|
|
553
|
+
if (learned === "" || (due === learned && often === "")) return `${word} ${due}${often}${DATE_SEP}`;
|
|
554
|
+
return `${r.boundedDate === true ? DATE_BOUND : ""}${learned} (${word} ${due}${often})${DATE_SEP}`;
|
|
486
555
|
}
|
|
487
556
|
if (learned === "") return "";
|
|
488
557
|
const happened = (r.happenedOn ?? "").trim();
|
|
@@ -594,6 +663,12 @@ export function compose(
|
|
|
594
663
|
}
|
|
595
664
|
const tail = more[lane];
|
|
596
665
|
if (items.length === 0 && tail === undefined) continue;
|
|
666
|
+
// Nothing listed: the tail is the lane's one collapsed line, heading
|
|
667
|
+
// included (`collapsedLine`), never a heading over a count.
|
|
668
|
+
if (items.length === 0 && tail !== undefined) {
|
|
669
|
+
lines.push("", tail);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
597
672
|
lines.push("", laneHeading(lane));
|
|
598
673
|
for (const item of items) lines.push(elementLine(item, resolve));
|
|
599
674
|
if (tail !== undefined) lines.push(tail);
|
|
@@ -718,6 +793,98 @@ function lostByLane(
|
|
|
718
793
|
return out;
|
|
719
794
|
}
|
|
720
795
|
|
|
796
|
+
/**
|
|
797
|
+
* "STILL OPEN" KEEPS ITS FIRST ITEM, AND ITS COUNT, BEFORE ARRIVING KEEPS ITS
|
|
798
|
+
* SECOND LINE OR THE YESTERDAY LINE ITS TITLES (review of #350, 2026-10-09).
|
|
799
|
+
*
|
|
800
|
+
* The owner's wake on 10-09 read "Still open:" over "(20 more still open; …)"
|
|
801
|
+
* and no item. The self page is furniture the trim cannot pop, the Yesterday
|
|
802
|
+
* line is too, and `TRIM_ORDER` takes "Still open" before "Arriving" — so
|
|
803
|
+
* beside a long page the lane gave up its last item while Arriving kept every
|
|
804
|
+
* line. The page is not what gives way: it is the self the wake is for, and it
|
|
805
|
+
* prints whole under its cap (`Self#pageBlock`). What gives way is, in order
|
|
806
|
+
* — Nearby and craft are already gone by the time this runs, since they trim
|
|
807
|
+
* first —
|
|
808
|
+
*
|
|
809
|
+
* 1. "Work here": the room the delivery holds for this directory's work
|
|
810
|
+
* lines (`lendBytes`), which it then fills with fewer of them;
|
|
811
|
+
* 2. Arriving beyond its first line (each a `TrimEvent`, so its own "N more"
|
|
812
|
+
* line can still say so if there is room);
|
|
813
|
+
* 3. the Yesterday line, down its shorter forms (`yesterdayShorter`: fewer
|
|
814
|
+
* titles, the rest by count — the caller's, which holds the chapters).
|
|
815
|
+
*
|
|
816
|
+
* The target is the lane's first item AND its "N more" line: one item under a
|
|
817
|
+
* heading with no count reads as the only thing open. Only after the trim loop
|
|
818
|
+
* has FIT, only when it left "Still open" with nothing, and all or nothing:
|
|
819
|
+
* when even the last step leaves no room, the render is exactly what the trim
|
|
820
|
+
* loop made, and the lane says so in one line (`collapsedLine`). Returns null
|
|
821
|
+
* then, or when there is nothing to keep.
|
|
822
|
+
*/
|
|
823
|
+
function keepFirstOpen(
|
|
824
|
+
arrived: readonly Ranked[],
|
|
825
|
+
arrivedHorizon: number,
|
|
826
|
+
overflow: readonly string[],
|
|
827
|
+
kept: Kept,
|
|
828
|
+
trimmed: readonly TrimEvent[],
|
|
829
|
+
yesterday: string | undefined,
|
|
830
|
+
req: BriefingRequest,
|
|
831
|
+
resolve: Resolve,
|
|
832
|
+
coreName: string | undefined,
|
|
833
|
+
identity: IdentityBlock,
|
|
834
|
+
): {
|
|
835
|
+
kept: Kept;
|
|
836
|
+
trimmed: TrimEvent[];
|
|
837
|
+
yesterday: string | undefined;
|
|
838
|
+
pinned: Partial<Record<LaneName, string[]>>;
|
|
839
|
+
composed: Composed;
|
|
840
|
+
/** Bytes taken from `lendBytes`: what the composition runs past `budgetBytes`. */
|
|
841
|
+
lent: number;
|
|
842
|
+
} | null {
|
|
843
|
+
const first = arrived[0];
|
|
844
|
+
if (first === undefined || kept.threads.length > 0) return null;
|
|
845
|
+
// Arriving's FIRST line still outranks it, as the trim order says: when the
|
|
846
|
+
// trim already took that, this budget has no room to rearrange.
|
|
847
|
+
if (arrivedHorizon > 0 && kept.horizon.length === 0) return null;
|
|
848
|
+
const k: Kept = {
|
|
849
|
+
identity: [...kept.identity],
|
|
850
|
+
craft: [...kept.craft],
|
|
851
|
+
threads: [first],
|
|
852
|
+
hints: [...kept.hints],
|
|
853
|
+
horizon: [...kept.horizon],
|
|
854
|
+
};
|
|
855
|
+
const t = trimmed.filter((e) => !(e.lane === "threads" && e.id === first.id));
|
|
856
|
+
// The rest of the lane, as `lostByLane` will list it: the trim's (popped
|
|
857
|
+
// from the end, so reversed back), then what the lane's cap left out.
|
|
858
|
+
const rest = [...t.filter((e) => e.lane === "threads").map((e) => e.id).reverse(), ...overflow];
|
|
859
|
+
const pinned: Partial<Record<LaneName, string[]>> = rest.length === 0 ? {} : { threads: rest };
|
|
860
|
+
const lines: Partial<Record<LaneName, string>> = rest.length === 0 ? {} : { threads: moreLine("threads", rest) };
|
|
861
|
+
const shorter =
|
|
862
|
+
yesterday === undefined ? [] : (req.yesterdayShorter ?? []).filter((s) => s.length > 0 && byteLength(s) < byteLength(yesterday));
|
|
863
|
+
const lend = Math.max(0, Math.floor(req.lendBytes ?? 0));
|
|
864
|
+
let limit = req.budgetBytes;
|
|
865
|
+
let y = yesterday;
|
|
866
|
+
let rung = 0;
|
|
867
|
+
for (;;) {
|
|
868
|
+
const c = compose(k, req.day, resolve, coreName, identity, lines, y);
|
|
869
|
+
if (c.bytes <= limit) {
|
|
870
|
+
return { kept: k, trimmed: t, yesterday: y, pinned, composed: c, lent: Math.max(0, c.bytes - req.budgetBytes) };
|
|
871
|
+
}
|
|
872
|
+
if (limit < req.budgetBytes + lend) {
|
|
873
|
+
limit = req.budgetBytes + lend;
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (k.horizon.length > 1) {
|
|
877
|
+
const dropped = k.horizon.pop();
|
|
878
|
+
if (dropped !== undefined) t.push({ lane: "horizon", id: dropped.id, strength: dropped.strength });
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
const next = shorter[rung];
|
|
882
|
+
if (next === undefined) return null;
|
|
883
|
+
y = next;
|
|
884
|
+
rung += 1;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
721
888
|
/**
|
|
722
889
|
* Add each lane's "N more" line, in `MORE_ORDER`, only while the whole
|
|
723
890
|
* composition still fits the budget. A line that does not fit is left out and
|
|
@@ -733,15 +900,26 @@ function withMoreLines(
|
|
|
733
900
|
coreName: string | undefined;
|
|
734
901
|
identity: IdentityBlock;
|
|
735
902
|
yesterday?: string;
|
|
903
|
+
/** Lines already in `composed`, paid for before the others are offered
|
|
904
|
+
* room (`keepFirstOpen`'s count): kept, never re-tried. */
|
|
905
|
+
pinned?: Partial<Record<LaneName, string[]>>;
|
|
736
906
|
},
|
|
737
907
|
): { composed: Composed; more: Partial<Record<LaneName, number>> } {
|
|
738
908
|
let current = composed;
|
|
739
909
|
const lines: Partial<Record<LaneName, string>> = {};
|
|
740
910
|
const more: Partial<Record<LaneName, number>> = {};
|
|
741
|
-
for (const lane of
|
|
742
|
-
const ids = ctx.
|
|
911
|
+
for (const lane of LANE_ORDER) {
|
|
912
|
+
const ids = ctx.pinned?.[lane];
|
|
743
913
|
if (ids === undefined || ids.length === 0) continue;
|
|
744
914
|
lines[lane] = moreLine(lane, ids);
|
|
915
|
+
more[lane] = ids.length;
|
|
916
|
+
}
|
|
917
|
+
for (const lane of MORE_ORDER) {
|
|
918
|
+
const ids = ctx.lost[lane];
|
|
919
|
+
if (ids === undefined || ids.length === 0 || lines[lane] !== undefined) continue;
|
|
920
|
+
// A lane that kept nothing gets the one collapsed line instead: "N more"
|
|
921
|
+
// over no item is neither a list nor a count (2026-10-09).
|
|
922
|
+
lines[lane] = lane !== "identity" && ctx.kept[lane].length === 0 ? collapsedLine(lane, ids) : moreLine(lane, ids);
|
|
745
923
|
const candidate = compose(ctx.kept, ctx.req.day, ctx.resolve, ctx.coreName, ctx.identity, lines, ctx.yesterday);
|
|
746
924
|
if (candidate.bytes > ctx.req.budgetBytes) {
|
|
747
925
|
delete lines[lane];
|
|
@@ -858,13 +1036,31 @@ export function render(
|
|
|
858
1036
|
}
|
|
859
1037
|
}
|
|
860
1038
|
if (fits || cut === null) {
|
|
1039
|
+
// "STILL OPEN" KEEPS ITS FIRST ITEM AND ITS COUNT (review of #350,
|
|
1040
|
+
// 2026-10-09), out of the room held for "Work here", Arriving's later
|
|
1041
|
+
// lines and the Yesterday line's titles, never out of the page — or the
|
|
1042
|
+
// render stays as the trim loop left it (`keepFirstOpen`).
|
|
1043
|
+
const first = fits
|
|
1044
|
+
? keepFirstOpen(lanes.threads, lanes.horizon.length, lanes.overflow?.threads ?? [], kept, trimmed, yesterday, req, resolve, coreName, identity)
|
|
1045
|
+
: null;
|
|
1046
|
+
if (first !== null) {
|
|
1047
|
+
for (const lane of LANE_ORDER) kept[lane] = first.kept[lane];
|
|
1048
|
+
trimmed.splice(0, trimmed.length, ...first.trimmed);
|
|
1049
|
+
}
|
|
1050
|
+
const said = first === null ? yesterday : first.yesterday;
|
|
861
1051
|
// The leftover clause. Only when NOTHING had to be trimmed: a lane that
|
|
862
1052
|
// lost an element wanted the room, and handing it to identity instead
|
|
863
1053
|
// would make the share decide the opposite of what it was set for. When
|
|
864
1054
|
// the other lanes are all present and the budget is still not spent, the
|
|
865
|
-
// held-back identity elements take it back, in rank order, whole.
|
|
1055
|
+
// held-back identity elements take it back, in rank order, whole. Not
|
|
1056
|
+
// beside a kept first item: its count is already in, and the leftover
|
|
1057
|
+
// composes without it.
|
|
866
1058
|
const offered =
|
|
867
|
-
|
|
1059
|
+
first !== null
|
|
1060
|
+
? first.composed
|
|
1061
|
+
: trimmed.length === 0
|
|
1062
|
+
? offerLeftover(kept, held, c, req, resolve, coreName, identity, yesterday)
|
|
1063
|
+
: c;
|
|
868
1064
|
// THE "N MORE" LINES, last: they take only room nothing else wanted.
|
|
869
1065
|
const told = withMoreLines(offered, {
|
|
870
1066
|
kept,
|
|
@@ -873,12 +1069,18 @@ export function render(
|
|
|
873
1069
|
resolve,
|
|
874
1070
|
coreName,
|
|
875
1071
|
identity,
|
|
876
|
-
...(
|
|
1072
|
+
...(said === undefined ? {} : { yesterday: said }),
|
|
1073
|
+
...(first === null ? {} : { pinned: first.pinned }),
|
|
877
1074
|
});
|
|
878
1075
|
const composed = told.composed;
|
|
1076
|
+
// What it was composed to: the caller's budget, and what "Work here"
|
|
1077
|
+
// lent "Still open" (`keepFirstOpen`) — so a reader comparing the bundle
|
|
1078
|
+
// to its ceiling sees one that fits, which it does: the delivery shows
|
|
1079
|
+
// fewer work lines in what is left.
|
|
1080
|
+
const budgetBytes = req.budgetBytes + (first?.lent ?? 0);
|
|
879
1081
|
return {
|
|
880
1082
|
...composed,
|
|
881
|
-
budgetBytes
|
|
1083
|
+
budgetBytes,
|
|
882
1084
|
day: req.day,
|
|
883
1085
|
kept: {
|
|
884
1086
|
identity: kept.identity.map((r) => r.id),
|
|
@@ -889,7 +1091,7 @@ export function render(
|
|
|
889
1091
|
},
|
|
890
1092
|
trimmed,
|
|
891
1093
|
more: told.more,
|
|
892
|
-
pressure: composed.bytes >=
|
|
1094
|
+
pressure: composed.bytes >= budgetBytes * t.BUDGET_PRESSURE,
|
|
893
1095
|
overBudget: !fits,
|
|
894
1096
|
page:
|
|
895
1097
|
identity.page === null
|
|
@@ -1075,6 +1277,65 @@ export function prefaceLine(f: PrefaceFacts): string {
|
|
|
1075
1277
|
);
|
|
1076
1278
|
}
|
|
1077
1279
|
|
|
1280
|
+
/**
|
|
1281
|
+
* THE TENSE ONLY THE DELIVERY KNOWS (2026-10-09).
|
|
1282
|
+
*
|
|
1283
|
+
* The owner's wake on 10-09 carried "Arriving: - … (due 2026-10-08) · …". By
|
|
1284
|
+
* design: a one-off stays in the horizon lane for its grace days, and the wake
|
|
1285
|
+
* is composed at a boundary — the evening one, the day before — and read the
|
|
1286
|
+
* next morning. The DATE was true; the lane's heading made it read as still to
|
|
1287
|
+
* come. A render can put a date it is already past into the past tense
|
|
1288
|
+
* (`Resolved.duePast`), but on the evening of the 8th the 8th is today, and only
|
|
1289
|
+
* the delivery knows the morning is the 9th.
|
|
1290
|
+
*
|
|
1291
|
+
* So, where the preface is composed and with the same date (`WakeDelivery
|
|
1292
|
+
* .date`, the person's day): an Arriving line whose due date is before today
|
|
1293
|
+
* reads `(was due 2026-10-05)`, and `(was due yesterday, 2026-10-08)` the day
|
|
1294
|
+
* after. Only the date prefix of a `- ` line in the Arriving lane is touched —
|
|
1295
|
+
* never a statement, never another lane — and only as far as `room` allows:
|
|
1296
|
+
* "was " on every such line first, then "yesterday, " while room remains, so a
|
|
1297
|
+
* line that would not fit keeps the date it was composed with, which is still
|
|
1298
|
+
* true. The caller passes what the preface reserve has left
|
|
1299
|
+
* (`PREFACE_RESERVE_BYTES`), so the delivered bundle stays inside it.
|
|
1300
|
+
*/
|
|
1301
|
+
export function arrivingTense(text: string, today: string, room: number): string {
|
|
1302
|
+
if (!isDay(today) || room <= 0) return text;
|
|
1303
|
+
const lines = text.split("\n");
|
|
1304
|
+
// The LAST such heading: the lane is last, and a page above it is printed as
|
|
1305
|
+
// written, so a line of the page that happens to read "Arriving:" is not it.
|
|
1306
|
+
const start = lines.lastIndexOf(FRAMING.horizon);
|
|
1307
|
+
if (start < 0) return text;
|
|
1308
|
+
const prior = addDays(today, -1);
|
|
1309
|
+
const shape = /^(- (?:(?:by )?\d{4}-\d{2}-\d{2} \()?)(was )?due (\d{4}-\d{2}-\d{2})(?=[,)]| · )/;
|
|
1310
|
+
const was = `${DUE_PAST_WORD} `;
|
|
1311
|
+
const words = { was: byteLength(was) - byteLength(`${DUE_WORD} `), yesterday: byteLength("yesterday, ") };
|
|
1312
|
+
const past: { i: number; head: string; already: boolean; date: string; rest: string; was: boolean; yesterday: boolean }[] = [];
|
|
1313
|
+
for (let i = start + 1; i < lines.length && lines[i] !== ""; i++) {
|
|
1314
|
+
const line = lines[i] ?? "";
|
|
1315
|
+
const m = shape.exec(line);
|
|
1316
|
+
const date = m?.[3];
|
|
1317
|
+
if (m === null || date === undefined || date >= today) continue;
|
|
1318
|
+
const already = m[2] !== undefined;
|
|
1319
|
+
past.push({ i, head: m[1] ?? "- ", already, date, rest: line.slice(m[0].length), was: already, yesterday: false });
|
|
1320
|
+
}
|
|
1321
|
+
let left = room;
|
|
1322
|
+
for (const p of past) {
|
|
1323
|
+
if (p.was || left < words.was) continue;
|
|
1324
|
+
p.was = true;
|
|
1325
|
+
left -= words.was;
|
|
1326
|
+
}
|
|
1327
|
+
for (const p of past) {
|
|
1328
|
+
if (!p.was || p.date !== prior || left < words.yesterday) continue;
|
|
1329
|
+
p.yesterday = true;
|
|
1330
|
+
left -= words.yesterday;
|
|
1331
|
+
}
|
|
1332
|
+
for (const p of past) {
|
|
1333
|
+
if (!p.was || (p.already && !p.yesterday)) continue;
|
|
1334
|
+
lines[p.i] = `${p.head}${was}${p.yesterday ? "yesterday, " : ""}${p.date}${p.rest}`;
|
|
1335
|
+
}
|
|
1336
|
+
return lines.join("\n");
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1078
1339
|
export interface PrefacedBundle {
|
|
1079
1340
|
readonly text: string;
|
|
1080
1341
|
readonly bytes: number;
|
package/src/core/self/index.ts
CHANGED
|
@@ -74,11 +74,13 @@ import {
|
|
|
74
74
|
TRIM_ORDER,
|
|
75
75
|
WAKE_SYSTEM,
|
|
76
76
|
applyPreface,
|
|
77
|
+
arrivingTense,
|
|
77
78
|
flatten,
|
|
78
79
|
PAGE_FLOOR_RESERVE_BYTES,
|
|
79
80
|
PAGE_MIN_RENDER_BYTES,
|
|
80
81
|
pageDateline,
|
|
81
82
|
pageTooLargeLine,
|
|
83
|
+
PREFACE_RESERVE_BYTES,
|
|
82
84
|
prefaceLine,
|
|
83
85
|
readSentinel,
|
|
84
86
|
render,
|
|
@@ -268,6 +270,13 @@ export interface HorizonItem {
|
|
|
268
270
|
* May 14)`. Absent: a date that happens once.
|
|
269
271
|
*/
|
|
270
272
|
readonly every?: string;
|
|
273
|
+
/**
|
|
274
|
+
* True when `due` is already behind the day the wake is composed for — a
|
|
275
|
+
* one-off in its grace days (2026-10-09). The line then says `(was due …)`.
|
|
276
|
+
* The caller knows that day (`core/briefing.ts#selfRenderer`); absent: not
|
|
277
|
+
* past, as far as the caller said.
|
|
278
|
+
*/
|
|
279
|
+
readonly past?: boolean;
|
|
271
280
|
}
|
|
272
281
|
|
|
273
282
|
export interface BoundaryRequest extends BriefingRequest {
|
|
@@ -591,11 +600,17 @@ export class Self {
|
|
|
591
600
|
const base: Resolve = req.resolve ?? ((id) => this.resolveStatement(id, docs, sources));
|
|
592
601
|
// An arriving occasion's due date, beside its learned one (2026-10-01).
|
|
593
602
|
// A repeating one says how often, beside it (2026-10-09).
|
|
594
|
-
|
|
603
|
+
// One already behind the day the wake is composed for says it WAS due
|
|
604
|
+
// (2026-10-09).
|
|
605
|
+
const dues = new Map<string, { due: string; every?: string; duePast?: boolean }>();
|
|
595
606
|
for (const h of req.horizon ?? []) {
|
|
596
607
|
if (h.due === undefined || h.due.trim() === "") continue;
|
|
597
608
|
const every = h.every?.trim() ?? "";
|
|
598
|
-
dues.set(h.id,
|
|
609
|
+
dues.set(h.id, {
|
|
610
|
+
due: h.due.trim(),
|
|
611
|
+
...(every === "" ? {} : { every }),
|
|
612
|
+
...(h.past === true ? { duePast: true } : {}),
|
|
613
|
+
});
|
|
599
614
|
}
|
|
600
615
|
const resolve: Resolve =
|
|
601
616
|
dues.size === 0
|
|
@@ -635,6 +650,12 @@ export class Self {
|
|
|
635
650
|
// §15 item 3). Turn it off and a filtering composition gets no page and
|
|
636
651
|
// falls back to the identity list `omit` left standing, which is what that
|
|
637
652
|
// composition carried before the page existed.
|
|
653
|
+
//
|
|
654
|
+
// **THE PAGE IS NOT CUT FOR THE LANES BESIDE IT** (review of #350,
|
|
655
|
+
// 2026-10-09): it is the self the wake exists to carry, so a page under
|
|
656
|
+
// its cap prints whole. When "Still open" would list nothing beside it,
|
|
657
|
+
// the room for its first item comes out of the other lanes, in the
|
|
658
|
+
// renderer (`briefing.ts#keepFirstOpen`).
|
|
638
659
|
const block =
|
|
639
660
|
req.omit !== undefined && !this.tunables.PAGE_ON_EGRESS
|
|
640
661
|
? null
|
|
@@ -653,8 +674,16 @@ export class Self {
|
|
|
653
674
|
...(coreName === null ? {} : { coreName }),
|
|
654
675
|
...(page === null ? {} : { page }),
|
|
655
676
|
// The "Yesterday" line (2026-10-01): the owner's wake only — a
|
|
656
|
-
// composition that filters (`omit`) is bound elsewhere.
|
|
677
|
+
// composition that filters (`omit`) is bound elsewhere. Its shorter
|
|
678
|
+
// forms ride beside it (review of #350).
|
|
657
679
|
...(req.yesterday === undefined || req.omit !== undefined ? {} : { yesterday: req.yesterday }),
|
|
680
|
+
...(req.yesterdayShorter === undefined || req.yesterday === undefined || req.omit !== undefined
|
|
681
|
+
? {}
|
|
682
|
+
: { yesterdayShorter: req.yesterdayShorter }),
|
|
683
|
+
// The room held for "Work here", lent to "Still open"'s first item
|
|
684
|
+
// (review of #350): the owner's wake only, which is the one delivered
|
|
685
|
+
// with work lines.
|
|
686
|
+
...(req.lendBytes === undefined || req.omit !== undefined ? {} : { lendBytes: req.lendBytes }),
|
|
658
687
|
},
|
|
659
688
|
resolve,
|
|
660
689
|
this.tunables,
|
|
@@ -1325,6 +1354,10 @@ export class Self {
|
|
|
1325
1354
|
// "no page has been written here yet" — the class of lie PR #71's rule
|
|
1326
1355
|
// forbids, moved from identity to the page (adversarial review MINOR-D).
|
|
1327
1356
|
if (room <= 0) return NO_ROOM;
|
|
1357
|
+
// NOT CUT FOR THE LANES BESIDE IT (review of #350, 2026-10-09): the lines
|
|
1358
|
+
// that compete with the page give way to it, never the other way round —
|
|
1359
|
+
// "Still open" gets its first item out of the other lanes
|
|
1360
|
+
// (`briefing.ts#keepFirstOpen`), not out of the page.
|
|
1328
1361
|
const cap = Math.min(this.tunables.PAGE_WAKE_BYTES, room);
|
|
1329
1362
|
if (cap < PAGE_MIN_RENDER_BYTES && bodyBytes > cap) {
|
|
1330
1363
|
return {
|
|
@@ -1566,7 +1599,20 @@ export class Self {
|
|
|
1566
1599
|
// `storeSize` there cannot mean two things.
|
|
1567
1600
|
liveRows: this.store.countMemories({ archived: false }),
|
|
1568
1601
|
});
|
|
1569
|
-
|
|
1602
|
+
// THE TENSE, at the same moment and from the same date (2026-10-09): an
|
|
1603
|
+
// Arriving line whose date is behind the person's today says it WAS due —
|
|
1604
|
+
// in what the preface's reserve leaves: the line itself, its newline, and
|
|
1605
|
+
// one more digit in each of the two byte counts the splice re-solves.
|
|
1606
|
+
const body =
|
|
1607
|
+
preface === null || delivery?.date === undefined
|
|
1608
|
+
? raw
|
|
1609
|
+
: arrivingTense(raw, delivery.date, PREFACE_RESERVE_BYTES - byteLength(preface) - 1 - 2);
|
|
1610
|
+
// Only through the splice: a bundle `applyPreface` will not rewrite (an
|
|
1611
|
+
// opening line it does not recognise) is delivered exactly as found, and a
|
|
1612
|
+
// tensed body there would carry byte counts that no longer describe it
|
|
1613
|
+
// (review2 of #350).
|
|
1614
|
+
const spliced = preface === null ? null : applyPreface(body, preface);
|
|
1615
|
+
const delivered = preface === null || spliced === null || spliced.applied ? spliced : applyPreface(raw, preface);
|
|
1570
1616
|
this.emit("self.wake", undefined, {
|
|
1571
1617
|
ok: reason === "delivered",
|
|
1572
1618
|
reason,
|
package/src/core/sleep/NOTES.md
CHANGED
|
@@ -921,3 +921,35 @@ fired view as a real refusal beside `protected`) — only on a night the floor w
|
|
|
921
921
|
otherwise have let it go (review of #341), so a repeat above the floor counts under
|
|
922
922
|
`above-floor` alone. The phase adds no criterion of its own;
|
|
923
923
|
why the gate exists is physics NOTES 2026-10-09 and prospective NOTES §16.
|
|
924
|
+
`blocked:protected` is counted on the same terms now (physics NOTES, the follow-up of the
|
|
925
|
+
same day): only on a night the floor would otherwise have let the protected row go. Before,
|
|
926
|
+
the self page alone put one on every cycle. `blocked:in-live-revision-chain` too (review of
|
|
927
|
+
#343): `inLiveRevisionChain` is still asked of every examined row, but physics names it only
|
|
928
|
+
on a night the floor would otherwise have let the row go, so a strong row under challenge
|
|
929
|
+
pressure no longer counts on every night the pressure stands.
|
|
930
|
+
|
|
931
|
+
## 2026-10-09 — dedup and fade: no cursor, measured
|
|
932
|
+
|
|
933
|
+
The 2026-09-28 audit's item 4 asked for a cursor in the four phases without one; prune and
|
|
934
|
+
decay got theirs (above). Dedup and fade were measured on a seeded hermetic store (bun,
|
|
935
|
+
this machine, while a long benchmark ran beside it) and left without one:
|
|
936
|
+
|
|
937
|
+
| store | dedup, one night | fade, one sweep |
|
|
938
|
+
|---|---|---|
|
|
939
|
+
| 3,000 memories, 300 cards | 0.41 s (30 pairs judged; budget 1,000) | 0.04 s (300 cards; budget 5,000) |
|
|
940
|
+
| 20,000 memories, 1,500 cards | 2.9 s (200 pairs) | 0.25 s (1,500 cards) |
|
|
941
|
+
|
|
942
|
+
- **Fade**: its budget never binds on a personal store, so a cursor would visit the same
|
|
943
|
+
cards in the same order. It runs every third lived day.
|
|
944
|
+
- **Dedup**: the time is not the pairs (the budget counts those, and a night judges a few
|
|
945
|
+
hundred at most) but the pass that finds them: every live row read twice (`runDedup`'s
|
|
946
|
+
live set, then `contentHashCandidates`) and every body read once, to group by hash. A
|
|
947
|
+
cursor cannot skip that pass, since a new memory's twin can be any row. (Profiled at
|
|
948
|
+
3,000 rows: about 0.13 s for one pass over the rows, 0.14 s for the bodies, 2 ms
|
|
949
|
+
hashing.)
|
|
950
|
+
- **What would make it cheaper, with the same pairs (not done):** group by
|
|
951
|
+
`memories.content_hash`, which since the floor is `hashText(body)` — equal on all 3,000
|
|
952
|
+
seeded rows — and read each row once. The module header says `content_hash` is
|
|
953
|
+
deliberately not used; that reasoning predates the floor, and a change wants it
|
|
954
|
+
re-ruled and every body write checked to keep the column in step. Or a store `GROUP BY`
|
|
955
|
+
over the column, which reads no row at all.
|
package/src/core/store/NOTES.md
CHANGED
|
@@ -1969,3 +1969,19 @@ store does with it:
|
|
|
1969
1969
|
parsed meta deciding — the same loose-match-then-confirm `planCandidates` uses for
|
|
1970
1970
|
`unresolved`. The partial `event_date` index bounds the scan to dated rows.
|
|
1971
1971
|
`datedMemories` is unchanged.
|
|
1972
|
+
|
|
1973
|
+
## 2026-10-09 — `eventLog`'s ascending default: every caller checked
|
|
1974
|
+
|
|
1975
|
+
The default stays `asc` (a story reads in the order it happened). The 2026-09-28 audit's
|
|
1976
|
+
item 1 was mostly closed by #272; this pass read the rest of the callers that leave `order`
|
|
1977
|
+
unset. Two wanted the newest rows and now ask for them, with `order: "desc"`:
|
|
1978
|
+
`contradictions.ts#heldPairs`' settle read (past `HELD_READ_ROWS` the newest hold read as
|
|
1979
|
+
never settled) and the dashboard's page history (`views/mind.ts#pageHistory`: the newest
|
|
1980
|
+
versions lost their dates past `LOG_LIMIT`; its day strip's `sleep.cycle` read too). Under
|
|
1981
|
+
their limits both return the rows they did, and keep the same row per key (`test/
|
|
1982
|
+
event-reads-newest.test.ts`). Left ascending, on purpose: doctor's `newestRows` ladder
|
|
1983
|
+
(exact or `unknown`), `snapshots.ts`' failed-copy count (a full read is treated as
|
|
1984
|
+
saturated), `fired.ts`' two-read join, the counting reads with ceilings far past any store
|
|
1985
|
+
(`sleep/cycle.ts`' symmetry, the dashboard's `status.ts`, the CLI's merge list, tools), and
|
|
1986
|
+
doctor's `keyHistory`, which asks "ever embedded", where neither end of a capped read is
|
|
1987
|
+
the whole answer.
|
package/src/core/time.ts
CHANGED
|
@@ -208,6 +208,21 @@ export function localStamp(at: number, zone?: string): string {
|
|
|
208
208
|
return `${p.month}-${p.day} ${p.hour}:${p.minute}`;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/**
|
|
212
|
+
* The time of day with the zone's short name: `17:47 MDT` — a 24-hour clock
|
|
213
|
+
* in `zone`, and the name of the clock it is on (`MDT`, or `GMT+14` where the
|
|
214
|
+
* runtime has no abbreviation). For a line whose date is printed beside it in
|
|
215
|
+
* the reader's own style (the dashboard card's "written" row, 2026-10-09,
|
|
216
|
+
* which said "17:47 UTC" until then). Empty for a moment that is not a number.
|
|
217
|
+
*/
|
|
218
|
+
export function localClockZone(at: number, zone?: string): string {
|
|
219
|
+
const z = zone === undefined || !isZoneCached(zone) ? machineZone() : zone;
|
|
220
|
+
const p = partsOf(at, z, "stamp");
|
|
221
|
+
const q = partsOf(at, z, "clock");
|
|
222
|
+
if (p === null) return "";
|
|
223
|
+
return `${p.hour}:${p.minute}${q === null || q.timeZoneName === "" ? "" : ` ${q.timeZoneName}`}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
211
226
|
/**
|
|
212
227
|
* The same stamp, shortened to the clock (`13:02`) when the moment falls on
|
|
213
228
|
* the same date as `after` in `zone` — a time in a run of times that already
|